authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-09-02 13:13:16+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-09-30 13:44:49+01:00
log55ae6747e2ad85f9f92919cab174efadc40ea002
tree0d38a3fd0cc0dd83637499e340657455aad67bbf
parent3f6a90766c7ababdaaca629cc5165c5ff5b5dcd7
signaturelock-open Commit is signed but in an unrecognized format.

names


1 files changed, 11 insertions(+), 12 deletions(-)

lib/std/debug/SelfInfo.zig+11-12
...@@ -28,9 +28,10 @@ const SelfInfo = @This();...@@ -28,9 +28,10 @@ const SelfInfo = @This();
2828
29modules: std.AutoHashMapUnmanaged(usize, struct {29modules: std.AutoHashMapUnmanaged(usize, struct {
30 di: Module.DebugInfo,30 di: Module.DebugInfo,
31 loaded_debug: bool,31 // MLUGG TODO: okay actually these should definitely go on the impl so it can share state. e.g. loading unwind info might require lodaing debug info in some cases
32 loaded_locations: bool,
32 loaded_unwind: bool,33 loaded_unwind: bool,
33 const init: @This() = .{ .di = .init, .loaded_debug = false, .loaded_unwind = false };34 const init: @This() = .{ .di = .init, .loaded_locations = false, .loaded_unwind = false };
34}),35}),
35lookup_cache: Module.LookupCache,36lookup_cache: Module.LookupCache,
3637
...@@ -88,11 +89,9 @@ pub fn getSymbolAtAddress(self: *SelfInfo, gpa: Allocator, address: usize) !std....@@ -88,11 +89,9 @@ pub fn getSymbolAtAddress(self: *SelfInfo, gpa: Allocator, address: usize) !std.
88 const module: Module = try .lookup(&self.lookup_cache, gpa, address);89 const module: Module = try .lookup(&self.lookup_cache, gpa, address);
89 const gop = try self.modules.getOrPut(gpa, module.key());90 const gop = try self.modules.getOrPut(gpa, module.key());
90 if (!gop.found_existing) gop.value_ptr.* = .init;91 if (!gop.found_existing) gop.value_ptr.* = .init;
91 if (!gop.value_ptr.loaded_debug) {92 if (!gop.value_ptr.loaded_locations) {
92 // MLUGG TODO: this overloads the name 'debug info' with including vs excluding unwind info93 try module.loadLocationInfo(gpa, &gop.value_ptr.di);
93 // figure out a better name for one or the other (i think the inner one is maybe 'symbol info' or something idk)94 gop.value_ptr.loaded_locations = true;
94 try module.loadDebugInfo(gpa, &gop.value_ptr.di);
95 gop.value_ptr.loaded_debug = true;
96 }95 }
97 return module.getSymbolAtAddress(gpa, &gop.value_ptr.di, address);96 return module.getSymbolAtAddress(gpa, &gop.value_ptr.di, address);
98}97}
...@@ -168,8 +167,8 @@ const Module = switch (native_os) {...@@ -168,8 +167,8 @@ const Module = switch (native_os) {
168 }167 }
169 return error.MissingDebugInfo;168 return error.MissingDebugInfo;
170 }169 }
171 fn loadDebugInfo(module: *const Module, gpa: Allocator, di: *Module.DebugInfo) !void {170 fn loadLocationInfo(module: *const Module, gpa: Allocator, di: *Module.DebugInfo) !void {
172 return loadMachODebugInfo(gpa, module, di);171 try loadMachODebugInfo(gpa, module, di); // MLUGG TODO inline
173 }172 }
174 fn loadUnwindInfo(module: *const Module, gpa: Allocator, di: *Module.DebugInfo) !void {173 fn loadUnwindInfo(module: *const Module, gpa: Allocator, di: *Module.DebugInfo) !void {
175 // MLUGG TODO HACKHACK174 // MLUGG TODO HACKHACK
...@@ -381,7 +380,7 @@ const Module = switch (native_os) {...@@ -381,7 +380,7 @@ const Module = switch (native_os) {
381 _ = address;380 _ = address;
382 unreachable;381 unreachable;
383 }382 }
384 fn loadDebugInfo(module: *const Module, gpa: Allocator, di: *DebugInfo) !void {383 fn loadLocationInfo(module: *const Module, gpa: Allocator, di: *DebugInfo) !void {
385 _ = module;384 _ = module;
386 _ = gpa;385 _ = gpa;
387 _ = di;386 _ = di;
...@@ -479,7 +478,7 @@ const Module = switch (native_os) {...@@ -479,7 +478,7 @@ const Module = switch (native_os) {
479 };478 };
480 return error.MissingDebugInfo;479 return error.MissingDebugInfo;
481 }480 }
482 fn loadDebugInfo(module: *const Module, gpa: Allocator, di: *Module.DebugInfo) !void {481 fn loadLocationInfo(module: *const Module, gpa: Allocator, di: *Module.DebugInfo) !void {
483 const filename: ?[]const u8 = if (module.name.len > 0) module.name else null;482 const filename: ?[]const u8 = if (module.name.len > 0) module.name else null;
484 const mapped_mem = mapFileOrSelfExe(filename) catch |err| switch (err) {483 const mapped_mem = mapFileOrSelfExe(filename) catch |err| switch (err) {
485 error.FileNotFound => return error.MissingDebugInfo,484 error.FileNotFound => return error.MissingDebugInfo,
...@@ -550,7 +549,7 @@ const Module = switch (native_os) {...@@ -550,7 +549,7 @@ const Module = switch (native_os) {
550 }549 }
551 return null;550 return null;
552 }551 }
553 fn loadDebugInfo(module: *const Module, gpa: Allocator, di: *DebugInfo) !void {552 fn loadLocationInfo(module: *const Module, gpa: Allocator, di: *DebugInfo) !void {
554 const mapped_ptr: [*]const u8 = @ptrFromInt(module.base_address);553 const mapped_ptr: [*]const u8 = @ptrFromInt(module.base_address);
555 const mapped = mapped_ptr[0..module.size];554 const mapped = mapped_ptr[0..module.size];
556 var coff_obj = coff.Coff.init(mapped, true) catch return error.InvalidDebugInfo;555 var coff_obj = coff.Coff.init(mapped, true) catch return error.InvalidDebugInfo;