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...@@ -1258,12 +1258,20 @@ fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugIn
1258 .buffer = mapped_mem[@sizeOf(macho.mach_header_64)..][0..hdr.sizeofcmds],1258 .buffer = mapped_mem[@sizeOf(macho.mach_header_64)..][0..hdr.sizeofcmds],
1259 };1259 };
1260 var unwind_info: ?[]const u8 = null;1260 var unwind_info: ?[]const u8 = null;
1261 var eh_frame: ?[]const u8 = null;
1261 const symtab = while (it.next()) |cmd| switch (cmd.cmd()) {1262 const symtab = while (it.next()) |cmd| switch (cmd.cmd()) {
1262 .SEGMENT_64 => {1263 .SEGMENT_64 => {
1263 for (cmd.getSections()) |sect| {1264 for (cmd.getSections()) |sect| {
1264 if (std.mem.eql(u8, "__TEXT", sect.segName()) and mem.eql(u8, "__unwind_info", sect.sectName())) {1265 if (std.mem.eql(u8, "__TEXT", sect.segName())) {
1265 unwind_info = try chopSlice(mapped_mem, sect.offset, sect.size);1266 if (mem.eql(u8, "__unwind_info", sect.sectName())) {
1266 break;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 }
1267 }1275 }
1268 }1276 }
1269 },1277 },
...@@ -1377,6 +1385,7 @@ fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugIn...@@ -1377,6 +1385,7 @@ fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugIn
1377 .symbols = symbols,1385 .symbols = symbols,
1378 .strings = strings,1386 .strings = strings,
1379 .unwind_info = unwind_info,1387 .unwind_info = unwind_info,
1388 .eh_frame = eh_frame,
1380 };1389 };
1381}1390}
13821391
...@@ -1919,6 +1928,7 @@ pub const ModuleDebugInfo = switch (native_os) {...@@ -1919,6 +1928,7 @@ pub const ModuleDebugInfo = switch (native_os) {
1919 ofiles: OFileTable,1928 ofiles: OFileTable,
1920 // Backed by mapped_memory1929 // Backed by mapped_memory
1921 unwind_info: ?[]const u8,1930 unwind_info: ?[]const u8,
1931 eh_frame: ?[]const u8,
19221932
1923 const OFileTable = std.StringHashMap(OFileInfo);1933 const OFileTable = std.StringHashMap(OFileInfo);
1924 const OFileInfo = struct {1934 const OFileInfo = struct {
...@@ -1982,6 +1992,11 @@ pub const ModuleDebugInfo = switch (native_os) {...@@ -1982,6 +1992,11 @@ pub const ModuleDebugInfo = switch (native_os) {
1982 }1992 }
19831993
1984 var sections: DW.DwarfInfo.SectionArray = DW.DwarfInfo.null_section_array;1994 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
1985 for (segcmd.?.getSections()) |sect| {2000 for (segcmd.?.getSections()) |sect| {
1986 if (!std.mem.eql(u8, "__DWARF", sect.segName())) continue;2001 if (!std.mem.eql(u8, "__DWARF", sect.segName())) continue;
19872002
...@@ -1989,7 +2004,7 @@ pub const ModuleDebugInfo = switch (native_os) {...@@ -1989,7 +2004,7 @@ pub const ModuleDebugInfo = switch (native_os) {
1989 inline for (@typeInfo(DW.DwarfSection).Enum.fields, 0..) |section, i| {2004 inline for (@typeInfo(DW.DwarfSection).Enum.fields, 0..) |section, i| {
1990 if (mem.eql(u8, "__" ++ section.name, sect.sectName())) section_index = i;2005 if (mem.eql(u8, "__" ++ section.name, sect.sectName())) section_index = i;
1991 }2006 }
1992 if (section_index == null) continue;2007 if (section_index == null or sections[section_index.?] != null) continue;
19932008
1994 const section_bytes = try chopSlice(mapped_mem, sect.offset, sect.size);2009 const section_bytes = try chopSlice(mapped_mem, sect.offset, sect.size);
1995 sections[section_index.?] = .{2010 sections[section_index.?] = .{
...@@ -2011,6 +2026,8 @@ pub const ModuleDebugInfo = switch (native_os) {...@@ -2011,6 +2026,8 @@ pub const ModuleDebugInfo = switch (native_os) {
2011 .is_macho = true,2026 .is_macho = true,
2012 };2027 };
20132028
2029 // TODO: Don't actually need to scan unwind info in this case, since __unwind_info points us to the entries
2030
2014 try DW.openDwarfDebugInfo(&di, allocator, mapped_mem);2031 try DW.openDwarfDebugInfo(&di, allocator, mapped_mem);
2015 var info = OFileInfo{2032 var info = OFileInfo{
2016 .di = di,2033 .di = di,