| author | |
| committer | |
| log | bfe8a4d9f6f51ede95e827e9f90b4591081c55f9 |
| tree | aad5e99e972b3cb4fe3b92aaf355ea86037de334 |
| parent | 92568a0097a6aeb0cd59f1f3dae43d0ecd7a18d0 |
| parent | aeaffd42f6d1c8fc92fa7669a579a8e6c46eb641 |
| signature |
x86: fix generating debug info for variables3 files changed, 63 insertions(+), 14 deletions(-)
src/arch/x86_64/CodeGen.zig+47-1| ... | ... | @@ -4370,6 +4370,7 @@ fn genVarDbgInfo( |
| 4370 | 4370 | .dwarf => |dw| { |
| 4371 | 4371 | const dbg_info = &dw.dbg_info; |
| 4372 | 4372 | try dbg_info.append(@enumToInt(link.File.Dwarf.AbbrevKind.variable)); |
| 4373 | const endian = self.target.cpu.arch.endian(); | |
| 4373 | 4374 | |
| 4374 | 4375 | switch (mcv) { |
| 4375 | 4376 | .register => |reg| { |
| ... | ... | @@ -4390,7 +4391,6 @@ fn genVarDbgInfo( |
| 4390 | 4391 | dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2); |
| 4391 | 4392 | }, |
| 4392 | 4393 | .memory, .got_load, .direct_load => { |
| 4393 | const endian = self.target.cpu.arch.endian(); | |
| 4394 | 4394 | const ptr_width = @intCast(u8, @divExact(self.target.cpu.arch.ptrBitWidth(), 8)); |
| 4395 | 4395 | const is_ptr = switch (tag) { |
| 4396 | 4396 | .dbg_var_ptr => true, |
| ... | ... | @@ -4425,7 +4425,53 @@ fn genVarDbgInfo( |
| 4425 | 4425 | else => {}, |
| 4426 | 4426 | } |
| 4427 | 4427 | }, |
| 4428 | .immediate => |x| { | |
| 4429 | const signedness: std.builtin.Signedness = blk: { | |
| 4430 | if (ty.zigTypeTag() != .Int) break :blk .unsigned; | |
| 4431 | break :blk ty.intInfo(self.target.*).signedness; | |
| 4432 | }; | |
| 4433 | try dbg_info.ensureUnusedCapacity(2); | |
| 4434 | const fixup = dbg_info.items.len; | |
| 4435 | dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc | |
| 4436 | 1, | |
| 4437 | switch (signedness) { | |
| 4438 | .signed => DW.OP.consts, | |
| 4439 | .unsigned => DW.OP.constu, | |
| 4440 | }, | |
| 4441 | }); | |
| 4442 | switch (signedness) { | |
| 4443 | .signed => try leb128.writeILEB128(dbg_info.writer(), @bitCast(i64, x)), | |
| 4444 | .unsigned => try leb128.writeULEB128(dbg_info.writer(), x), | |
| 4445 | } | |
| 4446 | try dbg_info.append(DW.OP.stack_value); | |
| 4447 | dbg_info.items[fixup] += @intCast(u8, dbg_info.items.len - fixup - 2); | |
| 4448 | }, | |
| 4449 | .undef => { | |
| 4450 | // DW.AT.location, DW.FORM.exprloc | |
| 4451 | // uleb128(exprloc_len) | |
| 4452 | // DW.OP.implicit_value uleb128(len_of_bytes) bytes | |
| 4453 | const abi_size = @intCast(u32, ty.abiSize(self.target.*)); | |
| 4454 | var implicit_value_len = std.ArrayList(u8).init(self.gpa); | |
| 4455 | defer implicit_value_len.deinit(); | |
| 4456 | try leb128.writeULEB128(implicit_value_len.writer(), abi_size); | |
| 4457 | const total_exprloc_len = 1 + implicit_value_len.items.len + abi_size; | |
| 4458 | try leb128.writeULEB128(dbg_info.writer(), total_exprloc_len); | |
| 4459 | try dbg_info.ensureUnusedCapacity(total_exprloc_len); | |
| 4460 | dbg_info.appendAssumeCapacity(DW.OP.implicit_value); | |
| 4461 | dbg_info.appendSliceAssumeCapacity(implicit_value_len.items); | |
| 4462 | dbg_info.appendNTimesAssumeCapacity(0xaa, abi_size); | |
| 4463 | }, | |
| 4464 | .none => { | |
| 4465 | try dbg_info.ensureUnusedCapacity(3); | |
| 4466 | dbg_info.appendSliceAssumeCapacity(&[3]u8{ // DW.AT.location, DW.FORM.exprloc | |
| 4467 | 2, DW.OP.lit0, DW.OP.stack_value, | |
| 4468 | }); | |
| 4469 | }, | |
| 4428 | 4470 | else => { |
| 4471 | try dbg_info.ensureUnusedCapacity(2); | |
| 4472 | dbg_info.appendSliceAssumeCapacity(&[2]u8{ // DW.AT.location, DW.FORM.exprloc | |
| 4473 | 1, DW.OP.nop, | |
| 4474 | }); | |
| 4429 | 4475 | log.debug("TODO generate debug info for {}", .{mcv}); |
| 4430 | 4476 | }, |
| 4431 | 4477 | } |
src/link/Dwarf.zig+8-5| ... | ... | @@ -102,7 +102,7 @@ pub const DeclState = struct { |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | pub fn addExprlocReloc(self: *DeclState, target: u32, offset: u32, is_ptr: bool) !void { |
| 105 | log.debug("{x}: target sym @{d}, via GOT {}", .{ offset, target, is_ptr }); | |
| 105 | log.debug("{x}: target sym %{d}, via GOT {}", .{ offset, target, is_ptr }); | |
| 106 | 106 | try self.exprloc_relocs.append(self.gpa, .{ |
| 107 | 107 | .@"type" = if (is_ptr) .got_load else .direct_load, |
| 108 | 108 | .target = target, |
| ... | ... | @@ -135,7 +135,7 @@ pub const DeclState = struct { |
| 135 | 135 | .@"type" = ty, |
| 136 | 136 | .offset = undefined, |
| 137 | 137 | }); |
| 138 | log.debug("@{d}: {}", .{ sym_index, ty.fmtDebug() }); | |
| 138 | log.debug("%{d}: {}", .{ sym_index, ty.fmtDebug() }); | |
| 139 | 139 | try self.abbrev_resolver.putNoClobberContext(self.gpa, ty, sym_index, .{ |
| 140 | 140 | .mod = self.mod, |
| 141 | 141 | }); |
| ... | ... | @@ -143,7 +143,7 @@ pub const DeclState = struct { |
| 143 | 143 | .mod = self.mod, |
| 144 | 144 | }).?; |
| 145 | 145 | }; |
| 146 | log.debug("{x}: @{d} + 0", .{ offset, resolv }); | |
| 146 | log.debug("{x}: %{d} + 0", .{ offset, resolv }); | |
| 147 | 147 | try self.abbrev_relocs.append(self.gpa, .{ |
| 148 | 148 | .target = resolv, |
| 149 | 149 | .atom = atom, |
| ... | ... | @@ -1056,6 +1056,7 @@ pub fn commitDeclState( |
| 1056 | 1056 | break :blk false; |
| 1057 | 1057 | }; |
| 1058 | 1058 | if (deferred) { |
| 1059 | log.debug("resolving %{d} deferred until flush", .{target}); | |
| 1059 | 1060 | try self.global_abbrev_relocs.append(gpa, .{ |
| 1060 | 1061 | .target = null, |
| 1061 | 1062 | .offset = reloc.offset, |
| ... | ... | @@ -1063,10 +1064,12 @@ pub fn commitDeclState( |
| 1063 | 1064 | .addend = reloc.addend, |
| 1064 | 1065 | }); |
| 1065 | 1066 | } else { |
| 1067 | const value = symbol.atom.off + symbol.offset + reloc.addend; | |
| 1068 | log.debug("{x}: [() => {x}] (%{d}, '{}')", .{ reloc.offset, value, target, ty.fmtDebug() }); | |
| 1066 | 1069 | mem.writeInt( |
| 1067 | 1070 | u32, |
| 1068 | 1071 | dbg_info_buffer.items[reloc.offset..][0..@sizeOf(u32)], |
| 1069 | symbol.atom.off + symbol.offset + reloc.addend, | |
| 1072 | value, | |
| 1070 | 1073 | target_endian, |
| 1071 | 1074 | ); |
| 1072 | 1075 | } |
| ... | ... | @@ -1259,7 +1262,7 @@ fn writeDeclDebugInfo(self: *Dwarf, file: *File, atom: *Atom, dbg_info_buf: []co |
| 1259 | 1262 | debug_info_sect.addr = dwarf_segment.vmaddr + new_offset - dwarf_segment.fileoff; |
| 1260 | 1263 | } |
| 1261 | 1264 | debug_info_sect.size = needed_size; |
| 1262 | d_sym.debug_line_header_dirty = true; | |
| 1265 | d_sym.debug_info_header_dirty = true; | |
| 1263 | 1266 | } |
| 1264 | 1267 | const file_pos = debug_info_sect.offset + atom.off; |
| 1265 | 1268 | try pwriteDbgInfoNops( |
src/link/MachO/DebugSymbols.zig+8-8| ... | ... | @@ -63,17 +63,16 @@ pub const Reloc = struct { |
| 63 | 63 | pub fn populateMissingMetadata(self: *DebugSymbols, allocator: Allocator) !void { |
| 64 | 64 | if (self.linkedit_segment_cmd_index == null) { |
| 65 | 65 | self.linkedit_segment_cmd_index = @intCast(u8, self.segments.items.len); |
| 66 | log.debug("found __LINKEDIT segment free space 0x{x} to 0x{x}", .{ | |
| 67 | self.base.page_size, | |
| 68 | self.base.page_size * 2, | |
| 69 | }); | |
| 66 | const fileoff = @intCast(u64, self.base.page_size); | |
| 67 | const needed_size = @intCast(u64, self.base.page_size) * 2; | |
| 68 | log.debug("found __LINKEDIT segment free space 0x{x} to 0x{x}", .{ fileoff, needed_size }); | |
| 70 | 69 | // TODO this needs reworking |
| 71 | 70 | try self.segments.append(allocator, .{ |
| 72 | 71 | .segname = makeStaticString("__LINKEDIT"), |
| 73 | .vmaddr = self.base.page_size, | |
| 74 | .vmsize = self.base.page_size, | |
| 75 | .fileoff = self.base.page_size, | |
| 76 | .filesize = self.base.page_size, | |
| 72 | .vmaddr = fileoff, | |
| 73 | .vmsize = needed_size, | |
| 74 | .fileoff = fileoff, | |
| 75 | .filesize = needed_size, | |
| 77 | 76 | .maxprot = macho.PROT.READ, |
| 78 | 77 | .initprot = macho.PROT.READ, |
| 79 | 78 | .cmdsize = @sizeOf(macho.segment_command_64), |
| ... | ... | @@ -284,6 +283,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: Allocator, options: link.Opti |
| 284 | 283 | const lc_writer = lc_buffer.writer(); |
| 285 | 284 | var ncmds: u32 = 0; |
| 286 | 285 | |
| 286 | self.updateDwarfSegment(); | |
| 287 | 287 | try self.writeLinkeditSegmentData(&ncmds, lc_writer); |
| 288 | 288 | self.updateDwarfSegment(); |
| 289 | 289 |