authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-09-08 11:41:26+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-09-30 13:44:51+01:00
logf1215adedab23535024a28367375a62909de6395
treef818e41fb39702cd1de18976316421d2464eb945
parent253fdfce7064a6ebf70dbb62b465d6564eac0948
signaturelock-open Commit is signed but in an unrecognized format.

SelfInfo.DarwinModule: rename field


1 files changed, 16 insertions(+), 17 deletions(-)

lib/std/debug/SelfInfo/DarwinModule.zig+16-17
......@@ -75,7 +75,7 @@ fn loadUnwindInfo(module: *const DarwinModule) DebugInfo.Unwind {
7575 .eh_frame = eh_frame,
7676 };
7777}
78fn loadFullInfo(module: *const DarwinModule, gpa: Allocator) !DebugInfo.Full {
78fn loadMachO(module: *const DarwinModule, gpa: Allocator) !DebugInfo.LoadedMachO {
7979 const mapped_mem = try mapDebugInfoFile(module.name);
8080 errdefer posix.munmap(mapped_mem);
8181
......@@ -189,21 +189,21 @@ fn loadFullInfo(module: *const DarwinModule, gpa: Allocator) !DebugInfo.Full {
189189 };
190190}
191191pub 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) {
193193 error.InvalidDebugInfo, error.MissingDebugInfo, error.OutOfMemory, error.Unexpected => |e| return e,
194194 else => return error.ReadFailed,
195195 };
196 const full = &di.full.?;
196 const loaded_macho = &di.loaded_macho.?;
197197
198198 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;
200200
201201 // offset of `address` from start of `symbol`
202202 const address_symbol_offset = vaddr - symbol.addr;
203203
204204 // Take the symbol name from the N_FUN STAB entry, we're going to
205205 // 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);
207207
208208 // If any information is missing, we can at least return this from now on.
209209 const sym_only_result: std.debug.Symbol = .{
......@@ -213,11 +213,11 @@ pub fn getSymbolAtAddress(module: *const DarwinModule, gpa: Allocator, di: *Debu
213213 };
214214
215215 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);
217217 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);
219219 gop.value_ptr.* = DebugInfo.loadOFile(gpa, o_file_path) catch {
220 _ = full.ofiles.pop().?;
220 _ = loaded_macho.ofiles.pop().?;
221221 return sym_only_result;
222222 };
223223 }
......@@ -581,23 +581,22 @@ fn unwindFrameInner(module: *const DarwinModule, gpa: Allocator, di: *DebugInfo,
581581}
582582pub const DebugInfo = struct {
583583 unwind: ?Unwind,
584 // MLUGG TODO: awful field name
585 full: ?Full,
584 loaded_macho: ?LoadedMachO,
586585
587586 pub const init: DebugInfo = .{
588587 .unwind = null,
589 .full = null,
588 .loaded_macho = null,
590589 };
591590
592591 pub fn deinit(di: *DebugInfo, gpa: Allocator) void {
593 if (di.full) |*full| {
594 for (full.ofiles.values()) |*ofile| {
592 if (di.loaded_macho) |*loaded_macho| {
593 for (loaded_macho.ofiles.values()) |*ofile| {
595594 ofile.dwarf.deinit(gpa);
596595 ofile.symbols_by_name.deinit(gpa);
597596 }
598 full.ofiles.deinit(gpa);
599 gpa.free(full.symbols);
600 posix.munmap(full.mapped_memory);
597 loaded_macho.ofiles.deinit(gpa);
598 gpa.free(loaded_macho.symbols);
599 posix.munmap(loaded_macho.mapped_memory);
601600 }
602601 }
603602
......@@ -607,7 +606,7 @@ pub const DebugInfo = struct {
607606 eh_frame: ?[]const u8,
608607 };
609608
610 const Full = struct {
609 const LoadedMachO = struct {
611610 mapped_memory: []align(std.heap.page_size_min) const u8,
612611 symbols: []const MachoSymbol,
613612 strings: [:0]const u8,