| ... | @@ -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 | } |
| 1382 | | 1391 | |
| ... | @@ -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_memory | 1929 | // Backed by mapped_memory |
| 1921 | unwind_info: ?[]const u8, | 1930 | unwind_info: ?[]const u8, |
| | 1931 | eh_frame: ?[]const u8, |
| 1922 | | 1932 | |
| 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 | } |
| 1983 | | 1993 | |
| 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; |
| 1987 | | 2002 | |
| ... | @@ -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; |
| 1993 | | 2008 | |
| 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 | }; |
| 2013 | | 2028 | |
| | 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, |