Commit f798048739

mlugg <mlugg@mlugg.co.uk>
2025-09-09 09:55:11
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 parent e6adddf
Changed files (1)
lib
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 => {},
     };
 }