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.
This commit is contained in:
committed by
Andrew Kelley
parent
47e004d975
commit
6de8b4bc3d
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user