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.
This commit is contained in:
mlugg 2025-09-09 08:55:11 +01:00
parent e6adddf80c
commit f798048739
No known key found for this signature in database
GPG key ID: 3F5B7DCCBF4AF02E

View file

@ -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 => {},
};
}