From f7980487395b660d5c568ba57891ab371a27102d Mon Sep 17 00:00:00 2001 From: mlugg Date: Tue, 9 Sep 2025 08:55:11 +0100 Subject: [PATCH] std.debug: don't include dumpCurrentStackTrace frame If it's not given, we should set `first_address` to the return address of `dumpCurrentStackTrace` to avoid the call to `writeCurrentStackTrace` appearing in the trace. However, we must only do that if no `context` is given; if there's a context then we're starting the stack unwind elsewhere. --- lib/std/debug.zig | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 87af0eefb9..2b6028ca82 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -732,7 +732,15 @@ pub fn dumpCurrentStackTrace(options: StackUnwindOptions) void { const tty_config = tty.detectConfig(.stderr()); const stderr = lockStderrWriter(&.{}); defer unlockStderrWriter(); - writeCurrentStackTrace(options, stderr, tty_config) catch |err| switch (err) { + writeCurrentStackTrace(.{ + .first_address = a: { + if (options.first_address) |a| break :a a; + if (options.context != null) break :a null; + break :a @returnAddress(); // don't include this frame in the trace + }, + .context = options.context, + .allow_unsafe_unwind = options.allow_unsafe_unwind, + }, stderr, tty_config) catch |err| switch (err) { error.WriteFailed => {}, }; }