| ... | ... | @@ -983,10 +983,9 @@ pub const abbrev_subprogram_retvoid = 3; |
| 983 | 983 | pub const abbrev_base_type = 4; |
| 984 | 984 | pub const abbrev_ptr_type = 5; |
| 985 | 985 | pub const abbrev_struct_type = 6; |
| 986 | | pub const abbrev_anon_struct_type = 7; |
| 987 | | pub const abbrev_struct_member = 8; |
| 988 | | pub const abbrev_pad1 = 9; |
| 989 | | pub const abbrev_parameter = 10; |
| 986 | pub const abbrev_struct_member = 7; |
| 987 | pub const abbrev_pad1 = 8; |
| 988 | pub const abbrev_parameter = 9; |
| 990 | 989 | |
| 991 | 990 | pub fn flush(self: *Elf, comp: *Compilation) !void { |
| 992 | 991 | if (self.base.options.emit == null) { |
| ... | ... | @@ -1127,13 +1126,6 @@ pub fn flushModule(self: *Elf, comp: *Compilation) !void { |
| 1127 | 1126 | DW.FORM.string, |
| 1128 | 1127 | 0, |
| 1129 | 1128 | 0, // table sentinel |
| 1130 | | abbrev_anon_struct_type, |
| 1131 | | DW.TAG.structure_type, |
| 1132 | | DW.CHILDREN.yes, // header |
| 1133 | | DW.AT.byte_size, |
| 1134 | | DW.FORM.sdata, |
| 1135 | | 0, |
| 1136 | | 0, // table sentinel |
| 1137 | 1129 | abbrev_struct_member, |
| 1138 | 1130 | DW.TAG.member, |
| 1139 | 1131 | DW.CHILDREN.no, // header |
| ... | ... | @@ -3186,6 +3178,7 @@ fn addDbgInfoType( |
| 3186 | 3178 | dbg_info_buffer: *std.ArrayList(u8), |
| 3187 | 3179 | dbg_info_type_relocs: *File.DbgInfoTypeRelocsTable, |
| 3188 | 3180 | ) error{OutOfMemory}!void { |
| 3181 | const target = self.base.options.target; |
| 3189 | 3182 | var relocs = std.ArrayList(struct { ty: Type, reloc: u32 }).init(arena); |
| 3190 | 3183 | |
| 3191 | 3184 | switch (ty.zigTypeTag()) { |
| ... | ... | @@ -3202,7 +3195,7 @@ fn addDbgInfoType( |
| 3202 | 3195 | }); |
| 3203 | 3196 | }, |
| 3204 | 3197 | .Int => { |
| 3205 | | const info = ty.intInfo(self.base.options.target); |
| 3198 | const info = ty.intInfo(target); |
| 3206 | 3199 | try dbg_info_buffer.ensureUnusedCapacity(12); |
| 3207 | 3200 | dbg_info_buffer.appendAssumeCapacity(abbrev_base_type); |
| 3208 | 3201 | // DW.AT.encoding, DW.FORM.data1 |
| ... | ... | @@ -3211,7 +3204,7 @@ fn addDbgInfoType( |
| 3211 | 3204 | .unsigned => DW.ATE.unsigned, |
| 3212 | 3205 | }); |
| 3213 | 3206 | // DW.AT.byte_size, DW.FORM.data1 |
| 3214 | | dbg_info_buffer.appendAssumeCapacity(@intCast(u8, ty.abiSize(self.base.options.target))); |
| 3207 | dbg_info_buffer.appendAssumeCapacity(@intCast(u8, ty.abiSize(target))); |
| 3215 | 3208 | // DW.AT.name, DW.FORM.string |
| 3216 | 3209 | try dbg_info_buffer.writer().print("{}\x00", .{ty}); |
| 3217 | 3210 | }, |
| ... | ... | @@ -3222,23 +3215,61 @@ fn addDbgInfoType( |
| 3222 | 3215 | // DW.AT.encoding, DW.FORM.data1 |
| 3223 | 3216 | dbg_info_buffer.appendAssumeCapacity(DW.ATE.address); |
| 3224 | 3217 | // DW.AT.byte_size, DW.FORM.data1 |
| 3225 | | dbg_info_buffer.appendAssumeCapacity(@intCast(u8, ty.abiSize(self.base.options.target))); |
| 3218 | dbg_info_buffer.appendAssumeCapacity(@intCast(u8, ty.abiSize(target))); |
| 3226 | 3219 | // DW.AT.name, DW.FORM.string |
| 3227 | 3220 | try dbg_info_buffer.writer().print("{}\x00", .{ty}); |
| 3228 | 3221 | } else { |
| 3229 | | log.debug("TODO implement .debug_info for type '{}'", .{ty}); |
| 3230 | | try dbg_info_buffer.append(abbrev_pad1); |
| 3222 | // Non-pointer optionals are structs: struct { .maybe = *, .val = * } |
| 3223 | var buf = try arena.create(Type.Payload.ElemType); |
| 3224 | const payload_ty = ty.optionalChild(buf); |
| 3225 | // DW.AT.structure_type |
| 3226 | try dbg_info_buffer.append(abbrev_struct_type); |
| 3227 | // DW.AT.byte_size, DW.FORM.sdata |
| 3228 | const abi_size = ty.abiSize(target); |
| 3229 | try leb128.writeULEB128(dbg_info_buffer.writer(), abi_size); |
| 3230 | // DW.AT.name, DW.FORM.string |
| 3231 | try dbg_info_buffer.writer().print("{}\x00", .{ty}); |
| 3232 | // DW.AT.member |
| 3233 | try dbg_info_buffer.ensureUnusedCapacity(7); |
| 3234 | dbg_info_buffer.appendAssumeCapacity(abbrev_struct_member); |
| 3235 | // DW.AT.name, DW.FORM.string |
| 3236 | dbg_info_buffer.appendSliceAssumeCapacity("maybe"); |
| 3237 | dbg_info_buffer.appendAssumeCapacity(0); |
| 3238 | // DW.AT.type, DW.FORM.ref4 |
| 3239 | var index = dbg_info_buffer.items.len; |
| 3240 | try dbg_info_buffer.resize(index + 4); |
| 3241 | try relocs.append(.{ .ty = Type.bool, .reloc = @intCast(u32, index) }); |
| 3242 | // DW.AT.data_member_location, DW.FORM.sdata |
| 3243 | try dbg_info_buffer.ensureUnusedCapacity(6); |
| 3244 | dbg_info_buffer.appendAssumeCapacity(0); |
| 3245 | // DW.AT.member |
| 3246 | dbg_info_buffer.appendAssumeCapacity(abbrev_struct_member); |
| 3247 | // DW.AT.name, DW.FORM.string |
| 3248 | dbg_info_buffer.appendSliceAssumeCapacity("val"); |
| 3249 | dbg_info_buffer.appendAssumeCapacity(0); |
| 3250 | // DW.AT.type, DW.FORM.ref4 |
| 3251 | index = dbg_info_buffer.items.len; |
| 3252 | try dbg_info_buffer.resize(index + 4); |
| 3253 | try relocs.append(.{ .ty = payload_ty, .reloc = @intCast(u32, index) }); |
| 3254 | // DW.AT.data_member_location, DW.FORM.sdata |
| 3255 | const offset = abi_size - payload_ty.abiSize(target); |
| 3256 | try leb128.writeULEB128(dbg_info_buffer.writer(), offset); |
| 3257 | // DW.AT.structure_type delimit children |
| 3258 | try dbg_info_buffer.append(0); |
| 3231 | 3259 | } |
| 3232 | 3260 | }, |
| 3233 | 3261 | .Pointer => { |
| 3234 | 3262 | if (ty.isSlice()) { |
| 3235 | | // Slices are anonymous structs: struct { .ptr = *, .len = N } |
| 3236 | | try dbg_info_buffer.ensureUnusedCapacity(23); |
| 3263 | // Slices are structs: struct { .ptr = *, .len = N } |
| 3237 | 3264 | // DW.AT.structure_type |
| 3238 | | dbg_info_buffer.appendAssumeCapacity(abbrev_anon_struct_type); |
| 3265 | try dbg_info_buffer.ensureUnusedCapacity(2); |
| 3266 | dbg_info_buffer.appendAssumeCapacity(abbrev_struct_type); |
| 3239 | 3267 | // DW.AT.byte_size, DW.FORM.sdata |
| 3240 | | dbg_info_buffer.appendAssumeCapacity(16); |
| 3268 | dbg_info_buffer.appendAssumeCapacity(@sizeOf(usize) * 2); |
| 3269 | // DW.AT.name, DW.FORM.string |
| 3270 | try dbg_info_buffer.writer().print("{}\x00", .{ty}); |
| 3241 | 3271 | // DW.AT.member |
| 3272 | try dbg_info_buffer.ensureUnusedCapacity(5); |
| 3242 | 3273 | dbg_info_buffer.appendAssumeCapacity(abbrev_struct_member); |
| 3243 | 3274 | // DW.AT.name, DW.FORM.string |
| 3244 | 3275 | dbg_info_buffer.appendSliceAssumeCapacity("ptr"); |
| ... | ... | @@ -3250,6 +3281,7 @@ fn addDbgInfoType( |
| 3250 | 3281 | const ptr_ty = ty.slicePtrFieldType(buf); |
| 3251 | 3282 | try relocs.append(.{ .ty = ptr_ty, .reloc = @intCast(u32, index) }); |
| 3252 | 3283 | // DW.AT.data_member_location, DW.FORM.sdata |
| 3284 | try dbg_info_buffer.ensureUnusedCapacity(6); |
| 3253 | 3285 | dbg_info_buffer.appendAssumeCapacity(0); |
| 3254 | 3286 | // DW.AT.member |
| 3255 | 3287 | dbg_info_buffer.appendAssumeCapacity(abbrev_struct_member); |
| ... | ... | @@ -3261,7 +3293,8 @@ fn addDbgInfoType( |
| 3261 | 3293 | try dbg_info_buffer.resize(index + 4); |
| 3262 | 3294 | try relocs.append(.{ .ty = Type.initTag(.usize), .reloc = @intCast(u32, index) }); |
| 3263 | 3295 | // DW.AT.data_member_location, DW.FORM.sdata |
| 3264 | | dbg_info_buffer.appendAssumeCapacity(8); |
| 3296 | try dbg_info_buffer.ensureUnusedCapacity(2); |
| 3297 | dbg_info_buffer.appendAssumeCapacity(@sizeOf(usize)); |
| 3265 | 3298 | // DW.AT.structure_type delimit children |
| 3266 | 3299 | dbg_info_buffer.appendAssumeCapacity(0); |
| 3267 | 3300 | } else { |
| ... | ... | @@ -3278,7 +3311,7 @@ fn addDbgInfoType( |
| 3278 | 3311 | // DW.AT.structure_type |
| 3279 | 3312 | try dbg_info_buffer.append(abbrev_struct_type); |
| 3280 | 3313 | // DW.AT.byte_size, DW.FORM.sdata |
| 3281 | | const abi_size = ty.abiSize(self.base.options.target); |
| 3314 | const abi_size = ty.abiSize(target); |
| 3282 | 3315 | try leb128.writeULEB128(dbg_info_buffer.writer(), abi_size); |
| 3283 | 3316 | // DW.AT.name, DW.FORM.string |
| 3284 | 3317 | const struct_name = try ty.nameAlloc(arena); |
| ... | ... | @@ -3306,7 +3339,7 @@ fn addDbgInfoType( |
| 3306 | 3339 | try dbg_info_buffer.resize(index + 4); |
| 3307 | 3340 | try relocs.append(.{ .ty = field.ty, .reloc = @intCast(u32, index) }); |
| 3308 | 3341 | // DW.AT.data_member_location, DW.FORM.sdata |
| 3309 | | const field_off = ty.structFieldOffset(field_index, self.base.options.target); |
| 3342 | const field_off = ty.structFieldOffset(field_index, target); |
| 3310 | 3343 | try leb128.writeULEB128(dbg_info_buffer.writer(), field_off); |
| 3311 | 3344 | } |
| 3312 | 3345 | |