aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug.zig
diff options
context:
space:
mode:
authorWilliam Sengir <william@sengir.com>2022-03-15 02:07:46 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-03-15 16:53:45 -0400
commit6de8b4bc3d105c15cd473c5bf100db4c9328dd54 (patch)
tree6f15f1b038b04aaf50ed03d7663c7e54d255a9b4 /lib/std/debug.zig
parent47e004d975669fea1297224e33a868742178c4b4 (diff)
downloadzig-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 'lib/std/debug.zig')
-rw-r--r--lib/std/debug.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 3d06c16d57..9b02d418c5 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -797,6 +797,7 @@ fn readCoffDebugInfo(allocator: mem.Allocator, coff_file: File) !ModuleDebugInfo
const debug_abbrev_data = di.coff.getSectionData(".debug_abbrev", allocator) catch null;
const debug_str_data = di.coff.getSectionData(".debug_str", allocator) catch null;
const debug_line_data = di.coff.getSectionData(".debug_line", allocator) catch null;
+ const debug_line_str_data = di.coff.getSectionData(".debug_line_str", allocator) catch null;
const debug_ranges_data = di.coff.getSectionData(".debug_ranges", allocator) catch null;
var dwarf = DW.DwarfInfo{
@@ -805,6 +806,7 @@ fn readCoffDebugInfo(allocator: mem.Allocator, coff_file: File) !ModuleDebugInfo
.debug_abbrev = debug_abbrev_data orelse return error.MissingDebugInfo,
.debug_str = debug_str_data orelse return error.MissingDebugInfo,
.debug_line = debug_line_data orelse return error.MissingDebugInfo,
+ .debug_line_str = debug_line_str_data,
.debug_ranges = debug_ranges_data,
};
try DW.openDwarfDebugInfo(&dwarf, allocator);
@@ -871,6 +873,7 @@ pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugIn
var opt_debug_abbrev: ?[]const u8 = null;
var opt_debug_str: ?[]const u8 = null;
var opt_debug_line: ?[]const u8 = null;
+ var opt_debug_line_str: ?[]const u8 = null;
var opt_debug_ranges: ?[]const u8 = null;
for (shdrs) |*shdr| {
@@ -885,6 +888,8 @@ pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugIn
opt_debug_str = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
} else if (mem.eql(u8, name, ".debug_line")) {
opt_debug_line = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
+ } else if (mem.eql(u8, name, ".debug_line_str")) {
+ opt_debug_line_str = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
} else if (mem.eql(u8, name, ".debug_ranges")) {
opt_debug_ranges = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
}
@@ -896,6 +901,7 @@ pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugIn
.debug_abbrev = opt_debug_abbrev orelse return error.MissingDebugInfo,
.debug_str = opt_debug_str orelse return error.MissingDebugInfo,
.debug_line = opt_debug_line orelse return error.MissingDebugInfo,
+ .debug_line_str = opt_debug_line_str,
.debug_ranges = opt_debug_ranges,
};
@@ -1434,6 +1440,7 @@ pub const ModuleDebugInfo = switch (native_os) {
var opt_debug_info: ?*const macho.section_64 = null;
var opt_debug_abbrev: ?*const macho.section_64 = null;
var opt_debug_str: ?*const macho.section_64 = null;
+ var opt_debug_line_str: ?*const macho.section_64 = null;
var opt_debug_ranges: ?*const macho.section_64 = null;
const sections = @ptrCast(
@@ -1456,6 +1463,8 @@ pub const ModuleDebugInfo = switch (native_os) {
opt_debug_abbrev = sect;
} else if (mem.eql(u8, name, "__debug_str")) {
opt_debug_str = sect;
+ } else if (mem.eql(u8, name, "__debug_line_str")) {
+ opt_debug_line_str = sect;
} else if (mem.eql(u8, name, "__debug_ranges")) {
opt_debug_ranges = sect;
}
@@ -1476,6 +1485,10 @@ pub const ModuleDebugInfo = switch (native_os) {
.debug_abbrev = try chopSlice(mapped_mem, debug_abbrev.offset, debug_abbrev.size),
.debug_str = try chopSlice(mapped_mem, debug_str.offset, debug_str.size),
.debug_line = try chopSlice(mapped_mem, debug_line.offset, debug_line.size),
+ .debug_line_str = if (opt_debug_line_str) |debug_line_str|
+ try chopSlice(mapped_mem, debug_line_str.offset, debug_line_str.size)
+ else
+ null,
.debug_ranges = if (opt_debug_ranges) |debug_ranges|
try chopSlice(mapped_mem, debug_ranges.offset, debug_ranges.size)
else