From 2f75d20d87fe68eb2695acd37fc2364c06c4c582 Mon Sep 17 00:00:00 2001 From: kcbanner Date: Thu, 25 May 2023 13:11:21 -0400 Subject: debug: use an explicit context type instead of anytype for dumpStackTraceFromBase, update crash_report to use this for exceptions --- lib/std/debug.zig | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/std/debug.zig') diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 2652ad57a8..a8e8b7bce8 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -133,11 +133,20 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void { } } +pub const StackTraceContext = blk: { + if (native_os == .windows) { + break :blk @typeInfo(@TypeOf(os.windows.CONTEXT.getRegs)).Fn.return_type.?; + } else if (@hasDecl(os.system, "ucontext_t")) { + break :blk *const os.ucontext_t; + } else { + break :blk void; + } +}; + /// Tries to print the stack trace starting from the supplied base pointer to stderr, /// unbuffered, and ignores any error returned. -/// `context` is either *const os.ucontext_t on posix, or the result of CONTEXT.getRegs() on Windows. /// TODO multithreaded awareness -pub fn dumpStackTraceFromBase(context: anytype) void { +pub fn dumpStackTraceFromBase(context: StackTraceContext) void { nosuspend { if (comptime builtin.target.isWasm()) { if (native_os == .wasi) { -- cgit v1.2.3