| ... | @@ -75,7 +75,7 @@ fn loadUnwindInfo(module: *const DarwinModule) DebugInfo.Unwind { | ... | @@ -75,7 +75,7 @@ fn loadUnwindInfo(module: *const DarwinModule) DebugInfo.Unwind { |
| 75 | .eh_frame = eh_frame, | 75 | .eh_frame = eh_frame, |
| 76 | }; | 76 | }; |
| 77 | } | 77 | } |
| 78 | fn loadFullInfo(module: *const DarwinModule, gpa: Allocator) !DebugInfo.Full { | 78 | fn loadMachO(module: *const DarwinModule, gpa: Allocator) !DebugInfo.LoadedMachO { |
| 79 | const mapped_mem = try mapDebugInfoFile(module.name); | 79 | const mapped_mem = try mapDebugInfoFile(module.name); |
| 80 | errdefer posix.munmap(mapped_mem); | 80 | errdefer posix.munmap(mapped_mem); |
| 81 | | 81 | |
| ... | @@ -189,21 +189,21 @@ fn loadFullInfo(module: *const DarwinModule, gpa: Allocator) !DebugInfo.Full { | ... | @@ -189,21 +189,21 @@ fn loadFullInfo(module: *const DarwinModule, gpa: Allocator) !DebugInfo.Full { |
| 189 | }; | 189 | }; |
| 190 | } | 190 | } |
| 191 | pub fn getSymbolAtAddress(module: *const DarwinModule, gpa: Allocator, di: *DebugInfo, address: usize) Error!std.debug.Symbol { | 191 | pub fn getSymbolAtAddress(module: *const DarwinModule, gpa: Allocator, di: *DebugInfo, address: usize) Error!std.debug.Symbol { |
| 192 | if (di.full == null) di.full = module.loadFullInfo(gpa) catch |err| switch (err) { | 192 | if (di.loaded_macho == null) di.loaded_macho = module.loadMachO(gpa) catch |err| switch (err) { |
| 193 | error.InvalidDebugInfo, error.MissingDebugInfo, error.OutOfMemory, error.Unexpected => |e| return e, | 193 | error.InvalidDebugInfo, error.MissingDebugInfo, error.OutOfMemory, error.Unexpected => |e| return e, |
| 194 | else => return error.ReadFailed, | 194 | else => return error.ReadFailed, |
| 195 | }; | 195 | }; |
| 196 | const full = &di.full.?; | 196 | const loaded_macho = &di.loaded_macho.?; |
| 197 | | 197 | |
| 198 | const vaddr = address - module.load_offset; | 198 | const vaddr = address - module.load_offset; |
| 199 | const symbol = MachoSymbol.find(full.symbols, vaddr) orelse return .unknown; | 199 | const symbol = MachoSymbol.find(loaded_macho.symbols, vaddr) orelse return .unknown; |
| 200 | | 200 | |
| 201 | // offset of `address` from start of `symbol` | 201 | // offset of `address` from start of `symbol` |
| 202 | const address_symbol_offset = vaddr - symbol.addr; | 202 | const address_symbol_offset = vaddr - symbol.addr; |
| 203 | | 203 | |
| 204 | // Take the symbol name from the N_FUN STAB entry, we're going to | 204 | // Take the symbol name from the N_FUN STAB entry, we're going to |
| 205 | // use it if we fail to find the DWARF infos | 205 | // use it if we fail to find the DWARF infos |
| 206 | const stab_symbol = mem.sliceTo(full.strings[symbol.strx..], 0); | 206 | const stab_symbol = mem.sliceTo(loaded_macho.strings[symbol.strx..], 0); |
| 207 | | 207 | |
| 208 | // If any information is missing, we can at least return this from now on. | 208 | // If any information is missing, we can at least return this from now on. |
| 209 | const sym_only_result: std.debug.Symbol = .{ | 209 | const sym_only_result: std.debug.Symbol = .{ |
| ... | @@ -213,11 +213,11 @@ pub fn getSymbolAtAddress(module: *const DarwinModule, gpa: Allocator, di: *Debu | ... | @@ -213,11 +213,11 @@ pub fn getSymbolAtAddress(module: *const DarwinModule, gpa: Allocator, di: *Debu |
| 213 | }; | 213 | }; |
| 214 | | 214 | |
| 215 | const o_file: *DebugInfo.OFile = of: { | 215 | const o_file: *DebugInfo.OFile = of: { |
| 216 | const gop = try full.ofiles.getOrPut(gpa, symbol.ofile); | 216 | const gop = try loaded_macho.ofiles.getOrPut(gpa, symbol.ofile); |
| 217 | if (!gop.found_existing) { | 217 | if (!gop.found_existing) { |
| 218 | const o_file_path = mem.sliceTo(full.strings[symbol.ofile..], 0); | 218 | const o_file_path = mem.sliceTo(loaded_macho.strings[symbol.ofile..], 0); |
| 219 | gop.value_ptr.* = DebugInfo.loadOFile(gpa, o_file_path) catch { | 219 | gop.value_ptr.* = DebugInfo.loadOFile(gpa, o_file_path) catch { |
| 220 | _ = full.ofiles.pop().?; | 220 | _ = loaded_macho.ofiles.pop().?; |
| 221 | return sym_only_result; | 221 | return sym_only_result; |
| 222 | }; | 222 | }; |
| 223 | } | 223 | } |
| ... | @@ -581,23 +581,22 @@ fn unwindFrameInner(module: *const DarwinModule, gpa: Allocator, di: *DebugInfo, | ... | @@ -581,23 +581,22 @@ fn unwindFrameInner(module: *const DarwinModule, gpa: Allocator, di: *DebugInfo, |
| 581 | } | 581 | } |
| 582 | pub const DebugInfo = struct { | 582 | pub const DebugInfo = struct { |
| 583 | unwind: ?Unwind, | 583 | unwind: ?Unwind, |
| 584 | // MLUGG TODO: awful field name | 584 | loaded_macho: ?LoadedMachO, |
| 585 | full: ?Full, | | |
| 586 | | 585 | |
| 587 | pub const init: DebugInfo = .{ | 586 | pub const init: DebugInfo = .{ |
| 588 | .unwind = null, | 587 | .unwind = null, |
| 589 | .full = null, | 588 | .loaded_macho = null, |
| 590 | }; | 589 | }; |
| 591 | | 590 | |
| 592 | pub fn deinit(di: *DebugInfo, gpa: Allocator) void { | 591 | pub fn deinit(di: *DebugInfo, gpa: Allocator) void { |
| 593 | if (di.full) |*full| { | 592 | if (di.loaded_macho) |*loaded_macho| { |
| 594 | for (full.ofiles.values()) |*ofile| { | 593 | for (loaded_macho.ofiles.values()) |*ofile| { |
| 595 | ofile.dwarf.deinit(gpa); | 594 | ofile.dwarf.deinit(gpa); |
| 596 | ofile.symbols_by_name.deinit(gpa); | 595 | ofile.symbols_by_name.deinit(gpa); |
| 597 | } | 596 | } |
| 598 | full.ofiles.deinit(gpa); | 597 | loaded_macho.ofiles.deinit(gpa); |
| 599 | gpa.free(full.symbols); | 598 | gpa.free(loaded_macho.symbols); |
| 600 | posix.munmap(full.mapped_memory); | 599 | posix.munmap(loaded_macho.mapped_memory); |
| 601 | } | 600 | } |
| 602 | } | 601 | } |
| 603 | | 602 | |
| ... | @@ -607,7 +606,7 @@ pub const DebugInfo = struct { | ... | @@ -607,7 +606,7 @@ pub const DebugInfo = struct { |
| 607 | eh_frame: ?[]const u8, | 606 | eh_frame: ?[]const u8, |
| 608 | }; | 607 | }; |
| 609 | | 608 | |
| 610 | const Full = struct { | 609 | const LoadedMachO = struct { |
| 611 | mapped_memory: []align(std.heap.page_size_min) const u8, | 610 | mapped_memory: []align(std.heap.page_size_min) const u8, |
| 612 | symbols: []const MachoSymbol, | 611 | symbols: []const MachoSymbol, |
| 613 | strings: [:0]const u8, | 612 | strings: [:0]const u8, |