| ... | ... | @@ -282,44 +282,19 @@ pub const DeclState = struct { |
| 282 | 282 | // DW.AT.array_type delimit children |
| 283 | 283 | try dbg_info_buffer.append(0); |
| 284 | 284 | }, |
| 285 | | .Struct => blk: { |
| 285 | .Struct => { |
| 286 | 286 | // DW.AT.structure_type |
| 287 | 287 | try dbg_info_buffer.append(@intFromEnum(AbbrevKind.struct_type)); |
| 288 | 288 | // DW.AT.byte_size, DW.FORM.udata |
| 289 | 289 | try leb128.writeULEB128(dbg_info_buffer.writer(), ty.abiSize(mod)); |
| 290 | 290 | |
| 291 | | switch (ip.indexToKey(ty.ip_index)) { |
| 292 | | .anon_struct_type => |fields| { |
| 293 | | // DW.AT.name, DW.FORM.string |
| 294 | | try dbg_info_buffer.writer().print("{}\x00", .{ty.fmt(mod)}); |
| 295 | | |
| 296 | | for (fields.types.get(ip), 0..) |field_ty, field_index| { |
| 297 | | // DW.AT.member |
| 298 | | try dbg_info_buffer.append(@intFromEnum(AbbrevKind.struct_member)); |
| 291 | blk: { |
| 292 | switch (ip.indexToKey(ty.ip_index)) { |
| 293 | .anon_struct_type => |fields| { |
| 299 | 294 | // DW.AT.name, DW.FORM.string |
| 300 | | try dbg_info_buffer.writer().print("{d}\x00", .{field_index}); |
| 301 | | // DW.AT.type, DW.FORM.ref4 |
| 302 | | var index = dbg_info_buffer.items.len; |
| 303 | | try dbg_info_buffer.resize(index + 4); |
| 304 | | try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @as(u32, @intCast(index))); |
| 305 | | // DW.AT.data_member_location, DW.FORM.udata |
| 306 | | const field_off = ty.structFieldOffset(field_index, mod); |
| 307 | | try leb128.writeULEB128(dbg_info_buffer.writer(), field_off); |
| 308 | | } |
| 309 | | }, |
| 310 | | .struct_type => |struct_type| { |
| 311 | | // DW.AT.name, DW.FORM.string |
| 312 | | try ty.print(dbg_info_buffer.writer(), mod); |
| 313 | | try dbg_info_buffer.append(0); |
| 314 | | |
| 315 | | if (struct_type.layout == .Packed) { |
| 316 | | log.debug("TODO implement .debug_info for packed structs", .{}); |
| 317 | | break :blk; |
| 318 | | } |
| 295 | try dbg_info_buffer.writer().print("{}\x00", .{ty.fmt(mod)}); |
| 319 | 296 | |
| 320 | | if (struct_type.isTuple(ip)) { |
| 321 | | for (struct_type.field_types.get(ip), struct_type.offsets.get(ip), 0..) |field_ty, field_off, field_index| { |
| 322 | | if (!field_ty.toType().hasRuntimeBits(mod)) continue; |
| 297 | for (fields.types.get(ip), 0..) |field_ty, field_index| { |
| 323 | 298 | // DW.AT.member |
| 324 | 299 | try dbg_info_buffer.append(@intFromEnum(AbbrevKind.struct_member)); |
| 325 | 300 | // DW.AT.name, DW.FORM.string |
| ... | ... | @@ -329,32 +304,59 @@ pub const DeclState = struct { |
| 329 | 304 | try dbg_info_buffer.resize(index + 4); |
| 330 | 305 | try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @as(u32, @intCast(index))); |
| 331 | 306 | // DW.AT.data_member_location, DW.FORM.udata |
| 307 | const field_off = ty.structFieldOffset(field_index, mod); |
| 332 | 308 | try leb128.writeULEB128(dbg_info_buffer.writer(), field_off); |
| 333 | 309 | } |
| 334 | | } else { |
| 335 | | for ( |
| 336 | | struct_type.field_names.get(ip), |
| 337 | | struct_type.field_types.get(ip), |
| 338 | | struct_type.offsets.get(ip), |
| 339 | | ) |field_name_ip, field_ty, field_off| { |
| 340 | | if (!field_ty.toType().hasRuntimeBits(mod)) continue; |
| 341 | | const field_name = ip.stringToSlice(field_name_ip); |
| 342 | | // DW.AT.member |
| 343 | | try dbg_info_buffer.ensureUnusedCapacity(field_name.len + 2); |
| 344 | | dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevKind.struct_member)); |
| 345 | | // DW.AT.name, DW.FORM.string |
| 346 | | dbg_info_buffer.appendSliceAssumeCapacity(field_name); |
| 347 | | dbg_info_buffer.appendAssumeCapacity(0); |
| 348 | | // DW.AT.type, DW.FORM.ref4 |
| 349 | | var index = dbg_info_buffer.items.len; |
| 350 | | try dbg_info_buffer.resize(index + 4); |
| 351 | | try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index)); |
| 352 | | // DW.AT.data_member_location, DW.FORM.udata |
| 353 | | try leb128.writeULEB128(dbg_info_buffer.writer(), field_off); |
| 310 | }, |
| 311 | .struct_type => |struct_type| { |
| 312 | // DW.AT.name, DW.FORM.string |
| 313 | try ty.print(dbg_info_buffer.writer(), mod); |
| 314 | try dbg_info_buffer.append(0); |
| 315 | |
| 316 | if (struct_type.layout == .Packed) { |
| 317 | log.debug("TODO implement .debug_info for packed structs", .{}); |
| 318 | break :blk; |
| 354 | 319 | } |
| 355 | | } |
| 356 | | }, |
| 357 | | else => unreachable, |
| 320 | |
| 321 | if (struct_type.isTuple(ip)) { |
| 322 | for (struct_type.field_types.get(ip), struct_type.offsets.get(ip), 0..) |field_ty, field_off, field_index| { |
| 323 | if (!field_ty.toType().hasRuntimeBits(mod)) continue; |
| 324 | // DW.AT.member |
| 325 | try dbg_info_buffer.append(@intFromEnum(AbbrevKind.struct_member)); |
| 326 | // DW.AT.name, DW.FORM.string |
| 327 | try dbg_info_buffer.writer().print("{d}\x00", .{field_index}); |
| 328 | // DW.AT.type, DW.FORM.ref4 |
| 329 | var index = dbg_info_buffer.items.len; |
| 330 | try dbg_info_buffer.resize(index + 4); |
| 331 | try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @as(u32, @intCast(index))); |
| 332 | // DW.AT.data_member_location, DW.FORM.udata |
| 333 | try leb128.writeULEB128(dbg_info_buffer.writer(), field_off); |
| 334 | } |
| 335 | } else { |
| 336 | for ( |
| 337 | struct_type.field_names.get(ip), |
| 338 | struct_type.field_types.get(ip), |
| 339 | struct_type.offsets.get(ip), |
| 340 | ) |field_name_ip, field_ty, field_off| { |
| 341 | if (!field_ty.toType().hasRuntimeBits(mod)) continue; |
| 342 | const field_name = ip.stringToSlice(field_name_ip); |
| 343 | // DW.AT.member |
| 344 | try dbg_info_buffer.ensureUnusedCapacity(field_name.len + 2); |
| 345 | dbg_info_buffer.appendAssumeCapacity(@intFromEnum(AbbrevKind.struct_member)); |
| 346 | // DW.AT.name, DW.FORM.string |
| 347 | dbg_info_buffer.appendSliceAssumeCapacity(field_name); |
| 348 | dbg_info_buffer.appendAssumeCapacity(0); |
| 349 | // DW.AT.type, DW.FORM.ref4 |
| 350 | var index = dbg_info_buffer.items.len; |
| 351 | try dbg_info_buffer.resize(index + 4); |
| 352 | try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index)); |
| 353 | // DW.AT.data_member_location, DW.FORM.udata |
| 354 | try leb128.writeULEB128(dbg_info_buffer.writer(), field_off); |
| 355 | } |
| 356 | } |
| 357 | }, |
| 358 | else => unreachable, |
| 359 | } |
| 358 | 360 | } |
| 359 | 361 | |
| 360 | 362 | // DW.AT.structure_type delimit children |