From 253fdfce7064a6ebf70dbb62b465d6564eac0948 Mon Sep 17 00:00:00 2001 From: mlugg Date: Mon, 8 Sep 2025 11:38:25 +0100 Subject: SelfInfo: be honest about how general unwinding is ...in that it isn't: it's currently very specialized to DWARF unwinding. Also, make a type unmanaged. --- lib/std/debug/SelfInfo/DarwinModule.zig | 15 ++++++++------- lib/std/debug/SelfInfo/ElfModule.zig | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'lib/std/debug/SelfInfo') diff --git a/lib/std/debug/SelfInfo/DarwinModule.zig b/lib/std/debug/SelfInfo/DarwinModule.zig index 4f94798c63..ce15aed95c 100644 --- a/lib/std/debug/SelfInfo/DarwinModule.zig +++ b/lib/std/debug/SelfInfo/DarwinModule.zig @@ -255,7 +255,7 @@ pub const supports_unwinding: bool = true; /// Unwind a frame using MachO compact unwind info (from __unwind_info). /// If the compact encoding can't encode a way to unwind a frame, it will /// defer unwinding to DWARF, in which case `.eh_frame` will be used if available. -pub fn unwindFrame(module: *const DarwinModule, gpa: Allocator, di: *DebugInfo, context: *UnwindContext) Error!usize { +pub fn unwindFrame(module: *const DarwinModule, gpa: Allocator, di: *DebugInfo, context: *DwarfUnwindContext) Error!usize { return unwindFrameInner(module, gpa, di, context) catch |err| switch (err) { error.InvalidDebugInfo, error.MissingDebugInfo, @@ -274,8 +274,7 @@ pub fn unwindFrame(module: *const DarwinModule, gpa: Allocator, di: *DebugInfo, => return error.InvalidDebugInfo, }; } -fn unwindFrameInner(module: *const DarwinModule, gpa: Allocator, di: *DebugInfo, context: *UnwindContext) !usize { - _ = gpa; +fn unwindFrameInner(module: *const DarwinModule, gpa: Allocator, di: *DebugInfo, context: *DwarfUnwindContext) !usize { if (di.unwind == null) di.unwind = module.loadUnwindInfo(); const unwind = &di.unwind.?; @@ -505,7 +504,8 @@ fn unwindFrameInner(module: *const DarwinModule, gpa: Allocator, di: *DebugInfo, .DWARF => { const eh_frame = unwind.eh_frame orelse return error.MissingDebugInfo; const eh_frame_vaddr = @intFromPtr(eh_frame.ptr) - module.load_offset; - return context.unwindFrameDwarf( + return context.unwindFrame( + gpa, &.initSection(.eh_frame, eh_frame_vaddr, eh_frame), module.load_offset, @intCast(encoding.value.x86_64.dwarf), @@ -524,7 +524,8 @@ fn unwindFrameInner(module: *const DarwinModule, gpa: Allocator, di: *DebugInfo, .DWARF => { const eh_frame = unwind.eh_frame orelse return error.MissingDebugInfo; const eh_frame_vaddr = @intFromPtr(eh_frame.ptr) - module.load_offset; - return context.unwindFrameDwarf( + return context.unwindFrame( + gpa, &.initSection(.eh_frame, eh_frame_vaddr, eh_frame), module.load_offset, @intCast(encoding.value.x86_64.dwarf), @@ -574,7 +575,7 @@ fn unwindFrameInner(module: *const DarwinModule, gpa: Allocator, di: *DebugInfo, else => comptime unreachable, // unimplemented }; - context.pc = UnwindContext.stripInstructionPtrAuthCode(new_ip); + context.pc = DwarfUnwindContext.stripInstructionPtrAuthCode(new_ip); if (context.pc > 0) context.pc -= 1; return new_ip; } @@ -819,7 +820,7 @@ const macho = std.macho; const mem = std.mem; const posix = std.posix; const testing = std.testing; -const UnwindContext = std.debug.SelfInfo.UnwindContext; +const DwarfUnwindContext = std.debug.SelfInfo.DwarfUnwindContext; const Error = std.debug.SelfInfo.Error; const regBytes = Dwarf.abi.regBytes; const regValueNative = Dwarf.abi.regValueNative; diff --git a/lib/std/debug/SelfInfo/ElfModule.zig b/lib/std/debug/SelfInfo/ElfModule.zig index b58125031e..ff37e283b9 100644 --- a/lib/std/debug/SelfInfo/ElfModule.zig +++ b/lib/std/debug/SelfInfo/ElfModule.zig @@ -193,12 +193,12 @@ fn loadUnwindInfo(module: *const ElfModule, gpa: Allocator, di: *DebugInfo) Erro else => unreachable, } } -pub fn unwindFrame(module: *const ElfModule, gpa: Allocator, di: *DebugInfo, context: *UnwindContext) Error!usize { +pub fn unwindFrame(module: *const ElfModule, gpa: Allocator, di: *DebugInfo, context: *DwarfUnwindContext) Error!usize { if (di.unwind[0] == null) try module.loadUnwindInfo(gpa, di); std.debug.assert(di.unwind[0] != null); for (&di.unwind) |*opt_unwind| { const unwind = &(opt_unwind.* orelse break); - return context.unwindFrameDwarf(unwind, module.load_offset, null) catch |err| switch (err) { + return context.unwindFrame(gpa, unwind, module.load_offset, null) catch |err| switch (err) { error.MissingDebugInfo => continue, // try the next one else => |e| return e, }; @@ -233,7 +233,7 @@ const Allocator = std.mem.Allocator; const Dwarf = std.debug.Dwarf; const elf = std.elf; const mem = std.mem; -const UnwindContext = std.debug.SelfInfo.UnwindContext; +const DwarfUnwindContext = std.debug.SelfInfo.DwarfUnwindContext; const Error = std.debug.SelfInfo.Error; const builtin = @import("builtin"); -- cgit v1.2.3