diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2025-09-02 18:47:31 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2025-09-30 13:44:50 +0100 |
| commit | 665f13b0cde4b9c2e69b139a87d272a67a9489e1 (patch) | |
| tree | 88598b5eb7d17a86ea15a93ca15dbab5be6594d2 /lib/std/debug/SelfInfo.zig | |
| parent | ba3f38959a31ace9af1816f16cda6c0717518b7f (diff) | |
| download | zig-665f13b0cde4b9c2e69b139a87d272a67a9489e1.tar.gz zig-665f13b0cde4b9c2e69b139a87d272a67a9489e1.zip | |
SelfInfo deinit magic
Diffstat (limited to 'lib/std/debug/SelfInfo.zig')
| -rw-r--r-- | lib/std/debug/SelfInfo.zig | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/lib/std/debug/SelfInfo.zig b/lib/std/debug/SelfInfo.zig index 32382ac1e1..9ca1b32f4e 100644 --- a/lib/std/debug/SelfInfo.zig +++ b/lib/std/debug/SelfInfo.zig @@ -18,7 +18,7 @@ const regValueNative = Dwarf.abi.regValueNative; const SelfInfo = @This(); -modules: std.AutoHashMapUnmanaged(usize, Module.DebugInfo), +modules: std.AutoArrayHashMapUnmanaged(usize, Module.DebugInfo), lookup_cache: Module.LookupCache, /// Indicates whether the `SelfInfo` implementation has support for this target. @@ -68,18 +68,18 @@ comptime { pub const init: SelfInfo = .{ .modules = .empty, - .lookup_cache = .init, + .lookup_cache = if (Module.LookupCache != void) .init, }; -pub fn deinit(self: *SelfInfo) void { - // MLUGG TODO: that's amusing, this function is straight-up unused. i... wonder if it even should be used anywhere? perhaps not... so perhaps it should not even exist...???? - var it = self.modules.iterator(); - while (it.next()) |entry| { - const mdi = entry.value_ptr.*; - mdi.deinit(self.allocator); - self.allocator.destroy(mdi); - } - self.modules.deinit(self.allocator); +pub fn deinit(self: *SelfInfo, gpa: Allocator) void { + for (self.modules.values()) |*di| di.deinit(gpa); + self.modules.deinit(gpa); + if (Module.LookupCache != void) self.lookup_cache.deinit(gpa); +} +comptime { + // `std.debug` does not currently utilize `deinit`, as it keeps hold of debug info for the + // whole lifetime of the program. Let's try to avoid it bitrotting. + _ = &deinit; } pub fn unwindFrame(self: *SelfInfo, gpa: Allocator, context: *UnwindContext) !usize { @@ -110,11 +110,12 @@ pub fn getModuleNameForAddress(self: *SelfInfo, gpa: Allocator, address: usize) /// This type contains the target-specific implementation. It must expose the following declarations: /// -/// * `LookupCache: type` -/// * `LookupCache.init: LookupCache` +/// * `LookupCache: type`, with the following declarations unless `LookupCache == void`: +/// * `init: LookupCache` +/// * `deinit: fn (*LookupCache, Allocator) void` /// * `lookup: fn (*LookupCache, Allocator, address: usize) !Module` /// * `key: fn (*const Module) usize` -/// * `DebugInfo: type` +/// * `DebugInfo: type`, with the following declarations: /// * `DebugInfo.init: DebugInfo` /// * `getSymbolAtAddress: fn (*const Module, Allocator, *DebugInfo, address: usize) !std.debug.Symbol` /// |
