authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-09-09 08:55:11+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-09-30 13:44:52+01:00
logf7980487395b660d5c568ba57891ab371a27102d
tree29838a7aa6289aa000772a9f025b99fb17900fe7
parente6adddf80c5c24ed89e6dc9e5bbaa3b88dd5ed69
signaturelock-open Commit is signed but in an unrecognized format.

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.

1 files changed, 9 insertions(+), 1 deletions(-)

lib/std/debug.zig+9-1
......@@ -732,7 +732,15 @@ pub fn dumpCurrentStackTrace(options: StackUnwindOptions) void {
732732 const tty_config = tty.detectConfig(.stderr());
733733 const stderr = lockStderrWriter(&.{});
734734 defer unlockStderrWriter();
735 writeCurrentStackTrace(options, stderr, tty_config) catch |err| switch (err) {
735 writeCurrentStackTrace(.{
736 .first_address = a: {
737 if (options.first_address) |a| break :a a;
738 if (options.context != null) break :a null;
739 break :a @returnAddress(); // don't include this frame in the trace
740 },
741 .context = options.context,
742 .allow_unsafe_unwind = options.allow_unsafe_unwind,
743 }, stderr, tty_config) catch |err| switch (err) {
736744 error.WriteFailed => {},
737745 };
738746}