diff options
| author | William Sengir <william@sengir.com> | 2022-03-15 02:07:46 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-03-15 16:53:45 -0400 |
| commit | 6de8b4bc3d105c15cd473c5bf100db4c9328dd54 (patch) | |
| tree | 6f15f1b038b04aaf50ed03d7663c7e54d255a9b4 /src/link/MachO/Object.zig | |
| parent | 47e004d975669fea1297224e33a868742178c4b4 (diff) | |
| download | zig-6de8b4bc3d105c15cd473c5bf100db4c9328dd54.tar.gz zig-6de8b4bc3d105c15cd473c5bf100db4c9328dd54.zip | |
std.dwarf: implement basic DWARF 5 parsing
DWARF 5 moves around some fields and adds a few new ones that can't be
parsed or ignored by our current DWARF 4 parser. This isn't a complete
implementation of DWARF 5, but this is enough to make stack traces
mostly work. Line numbers from C++ don't show up, but I know the info
is there. I think the answer is to iterate through .debug_line_str in
getLineNumberInfo, but I didn't want to fall into an even deeper rabbit
hole tonight.
Diffstat (limited to 'src/link/MachO/Object.zig')
| -rw-r--r-- | src/link/MachO/Object.zig | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig index 70cdda6c2f..6620c99b49 100644 --- a/src/link/MachO/Object.zig +++ b/src/link/MachO/Object.zig @@ -38,6 +38,7 @@ dwarf_debug_info_index: ?u16 = null, dwarf_debug_abbrev_index: ?u16 = null, dwarf_debug_str_index: ?u16 = null, dwarf_debug_line_index: ?u16 = null, +dwarf_debug_line_str_index: ?u16 = null, dwarf_debug_ranges_index: ?u16 = null, symtab: std.ArrayListUnmanaged(macho.nlist_64) = .{}, @@ -68,6 +69,7 @@ const DebugInfo = struct { debug_abbrev: []u8, debug_str: []u8, debug_line: []u8, + debug_line_str: []u8, debug_ranges: []u8, pub fn parseFromObject(allocator: Allocator, object: *const Object) !?DebugInfo { @@ -87,6 +89,12 @@ const DebugInfo = struct { const index = object.dwarf_debug_line_index orelse return null; break :blk try object.readSection(allocator, index); }; + var debug_line_str = blk: { + if (object.dwarf_debug_line_str_index) |ind| { + break :blk try object.readSection(allocator, ind); + } + break :blk try allocator.alloc(u8, 0); + }; var debug_ranges = blk: { if (object.dwarf_debug_ranges_index) |ind| { break :blk try object.readSection(allocator, ind); @@ -100,6 +108,7 @@ const DebugInfo = struct { .debug_abbrev = debug_abbrev, .debug_str = debug_str, .debug_line = debug_line, + .debug_line_str = debug_line_str, .debug_ranges = debug_ranges, }; try dwarf.openDwarfDebugInfo(&inner, allocator); @@ -110,6 +119,7 @@ const DebugInfo = struct { .debug_abbrev = debug_abbrev, .debug_str = debug_str, .debug_line = debug_line, + .debug_line_str = debug_line_str, .debug_ranges = debug_ranges, }; } @@ -119,6 +129,7 @@ const DebugInfo = struct { allocator.free(self.debug_abbrev); allocator.free(self.debug_str); allocator.free(self.debug_line); + allocator.free(self.debug_line_str); allocator.free(self.debug_ranges); self.inner.abbrev_table_list.deinit(); self.inner.compile_unit_list.deinit(); @@ -285,6 +296,8 @@ pub fn readLoadCommands(self: *Object, allocator: Allocator, reader: anytype) !v self.dwarf_debug_str_index = index; } else if (mem.eql(u8, sectname, "__debug_line")) { self.dwarf_debug_line_index = index; + } else if (mem.eql(u8, sectname, "__debug_line_str")) { + self.dwarf_debug_line_str_index = index; } else if (mem.eql(u8, sectname, "__debug_ranges")) { self.dwarf_debug_ranges_index = index; } |
