Skip to content

Commit 1ce71c8

Browse files
committed
std.debug: implement support for DWARFv5
1 parent c84e5ee commit 1ce71c8

File tree

5 files changed

+415
-160
lines changed

5 files changed

+415
-160
lines changed

lib/std/debug.zig

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,11 @@ pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugIn
923923
var opt_debug_line: ?[]const u8 = null;
924924
var opt_debug_line_str: ?[]const u8 = null;
925925
var opt_debug_ranges: ?[]const u8 = null;
926+
var opt_debug_loclists: ?[]const u8 = null;
927+
var opt_debug_rnglists: ?[]const u8 = null;
928+
var opt_debug_addr: ?[]const u8 = null;
929+
var opt_debug_names: ?[]const u8 = null;
930+
var opt_debug_frame: ?[]const u8 = null;
926931

927932
for (shdrs) |*shdr| {
928933
if (shdr.sh_type == elf.SHT_NULL) continue;
@@ -942,6 +947,16 @@ pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugIn
942947
opt_debug_line_str = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
943948
} else if (mem.eql(u8, name, ".debug_ranges")) {
944949
opt_debug_ranges = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
950+
} else if (mem.eql(u8, name, ".debug_loclists")) {
951+
opt_debug_loclists = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
952+
} else if (mem.eql(u8, name, ".debug_rnglists")) {
953+
opt_debug_rnglists = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
954+
} else if (mem.eql(u8, name, ".debug_addr")) {
955+
opt_debug_addr = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
956+
} else if (mem.eql(u8, name, ".debug_names")) {
957+
opt_debug_names = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
958+
} else if (mem.eql(u8, name, ".debug_frame")) {
959+
opt_debug_frame = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
945960
}
946961
}
947962

@@ -954,6 +969,11 @@ pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugIn
954969
.debug_line = opt_debug_line orelse return error.MissingDebugInfo,
955970
.debug_line_str = opt_debug_line_str,
956971
.debug_ranges = opt_debug_ranges,
972+
.debug_loclists = opt_debug_loclists,
973+
.debug_rnglists = opt_debug_rnglists,
974+
.debug_addr = opt_debug_addr,
975+
.debug_names = opt_debug_names,
976+
.debug_frame = opt_debug_frame,
957977
};
958978

959979
try DW.openDwarfDebugInfo(&di, allocator);
@@ -1494,6 +1514,11 @@ pub const ModuleDebugInfo = switch (native_os) {
14941514
var opt_debug_str: ?macho.section_64 = null;
14951515
var opt_debug_line_str: ?macho.section_64 = null;
14961516
var opt_debug_ranges: ?macho.section_64 = null;
1517+
var opt_debug_loclists: ?macho.section_64 = null;
1518+
var opt_debug_rnglists: ?macho.section_64 = null;
1519+
var opt_debug_addr: ?macho.section_64 = null;
1520+
var opt_debug_names: ?macho.section_64 = null;
1521+
var opt_debug_frame: ?macho.section_64 = null;
14971522

14981523
for (segcmd.?.getSections()) |sect| {
14991524
const name = sect.sectName();
@@ -1509,6 +1534,16 @@ pub const ModuleDebugInfo = switch (native_os) {
15091534
opt_debug_line_str = sect;
15101535
} else if (mem.eql(u8, name, "__debug_ranges")) {
15111536
opt_debug_ranges = sect;
1537+
} else if (mem.eql(u8, name, "__debug_loclists")) {
1538+
opt_debug_loclists = sect;
1539+
} else if (mem.eql(u8, name, "__debug_rnglists")) {
1540+
opt_debug_rnglists = sect;
1541+
} else if (mem.eql(u8, name, "__debug_addr")) {
1542+
opt_debug_addr = sect;
1543+
} else if (mem.eql(u8, name, "__debug_names")) {
1544+
opt_debug_names = sect;
1545+
} else if (mem.eql(u8, name, "__debug_frame")) {
1546+
opt_debug_frame = sect;
15121547
}
15131548
}
15141549

@@ -1536,6 +1571,11 @@ pub const ModuleDebugInfo = switch (native_os) {
15361571
try chopSlice(mapped_mem, debug_ranges.offset, debug_ranges.size)
15371572
else
15381573
null,
1574+
.debug_loclists = opt_debug_loclists,
1575+
.debug_rnglists = opt_debug_rnglists,
1576+
.debug_addr = opt_debug_addr,
1577+
.debug_names = opt_debug_names,
1578+
.debug_frame = opt_debug_frame,
15391579
};
15401580

15411581
try DW.openDwarfDebugInfo(&di, allocator);
@@ -1590,7 +1630,7 @@ pub const ModuleDebugInfo = switch (native_os) {
15901630
.compile_unit_name = compile_unit.die.getAttrString(
15911631
o_file_di,
15921632
DW.AT.name,
1593-
compile_unit.is_64,
1633+
self.di.debug_str,
15941634
) catch |err| switch (err) {
15951635
error.MissingDebugInfo, error.InvalidDebugInfo => "???",
15961636
},
@@ -1712,7 +1752,7 @@ fn getSymbolFromDwarf(allocator: mem.Allocator, address: u64, di: *DW.DwarfInfo)
17121752
if (nosuspend di.findCompileUnit(address)) |compile_unit| {
17131753
return SymbolInfo{
17141754
.symbol_name = nosuspend di.getSymbolName(address) orelse "???",
1715-
.compile_unit_name = compile_unit.die.getAttrString(di, DW.AT.name, compile_unit.is_64) catch |err| switch (err) {
1755+
.compile_unit_name = compile_unit.die.getAttrString(di, DW.AT.name, di.debug_str) catch |err| switch (err) {
17161756
error.MissingDebugInfo, error.InvalidDebugInfo => "???",
17171757
},
17181758
.line_info = nosuspend di.getLineNumberInfo(allocator, compile_unit.*, address) catch |err| switch (err) {

0 commit comments

Comments
 (0)