authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-15 01:17:44-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-20 22:58:16-04:00
log5e399d97d7b8ed3fc4c5b3664acfa7c79e72136c
tree9d270616838408eeaada3296543195cb51466640
parentba813d00f57542483cac108223c7b2c4353c14e0

use eh_frame from the mapped binary if available


1 files changed, 21 insertions(+), 4 deletions(-)

lib/std/debug.zig+21-4
......@@ -1258,12 +1258,20 @@ fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugIn
12581258 .buffer = mapped_mem[@sizeOf(macho.mach_header_64)..][0..hdr.sizeofcmds],
12591259 };
12601260 var unwind_info: ?[]const u8 = null;
1261 var eh_frame: ?[]const u8 = null;
12611262 const symtab = while (it.next()) |cmd| switch (cmd.cmd()) {
12621263 .SEGMENT_64 => {
12631264 for (cmd.getSections()) |sect| {
1264 if (std.mem.eql(u8, "__TEXT", sect.segName()) and mem.eql(u8, "__unwind_info", sect.sectName())) {
1265 unwind_info = try chopSlice(mapped_mem, sect.offset, sect.size);
1266 break;
1265 if (std.mem.eql(u8, "__TEXT", sect.segName())) {
1266 if (mem.eql(u8, "__unwind_info", sect.sectName())) {
1267 unwind_info = try chopSlice(mapped_mem, sect.offset, sect.size);
1268 continue;
1269 }
1270
1271 if (mem.eql(u8, "__eh_frame", sect.sectName())) {
1272 eh_frame = try chopSlice(mapped_mem, sect.offset, sect.size);
1273 continue;
1274 }
12671275 }
12681276 }
12691277 },
......@@ -1377,6 +1385,7 @@ fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugIn
13771385 .symbols = symbols,
13781386 .strings = strings,
13791387 .unwind_info = unwind_info,
1388 .eh_frame = eh_frame,
13801389 };
13811390}
13821391
......@@ -1919,6 +1928,7 @@ pub const ModuleDebugInfo = switch (native_os) {
19191928 ofiles: OFileTable,
19201929 // Backed by mapped_memory
19211930 unwind_info: ?[]const u8,
1931 eh_frame: ?[]const u8,
19221932
19231933 const OFileTable = std.StringHashMap(OFileInfo);
19241934 const OFileInfo = struct {
......@@ -1982,6 +1992,11 @@ pub const ModuleDebugInfo = switch (native_os) {
19821992 }
19831993
19841994 var sections: DW.DwarfInfo.SectionArray = DW.DwarfInfo.null_section_array;
1995 if (self.eh_frame) |eh_frame| sections[@intFromEnum(DW.DwarfSection.eh_frame)] = .{
1996 .data = eh_frame,
1997 .owned = false,
1998 };
1999
19852000 for (segcmd.?.getSections()) |sect| {
19862001 if (!std.mem.eql(u8, "__DWARF", sect.segName())) continue;
19872002
......@@ -1989,7 +2004,7 @@ pub const ModuleDebugInfo = switch (native_os) {
19892004 inline for (@typeInfo(DW.DwarfSection).Enum.fields, 0..) |section, i| {
19902005 if (mem.eql(u8, "__" ++ section.name, sect.sectName())) section_index = i;
19912006 }
1992 if (section_index == null) continue;
2007 if (section_index == null or sections[section_index.?] != null) continue;
19932008
19942009 const section_bytes = try chopSlice(mapped_mem, sect.offset, sect.size);
19952010 sections[section_index.?] = .{
......@@ -2011,6 +2026,8 @@ pub const ModuleDebugInfo = switch (native_os) {
20112026 .is_macho = true,
20122027 };
20132028
2029 // TODO: Don't actually need to scan unwind info in this case, since __unwind_info points us to the entries
2030
20142031 try DW.openDwarfDebugInfo(&di, allocator, mapped_mem);
20152032 var info = OFileInfo{
20162033 .di = di,