remove extra call stack frames from panic
See #684
@andrewrk (or anyone else): Could an example be added of the current behavior that needs to be changed? Is this referring to the frame entry with all the ??? in it, in https://github.com/ziglang/zig/pull/684#issue-162561892 ? (If so, then I've never before observed this, so it seems this remnant of #684 has been fixed already in the meantime.)
I'd say the idea is to stop the stack traces at the call that's made in user code, not continue deeper into zig internal implementation details. For example:
const std = @import("std");
pub fn main() void {
std.debug.panic("not implemented", .{});
}
Instead of current
thread 16502146 panic: not implemented
/opt/homebrew/Cellar/zig/0.11.0/lib/zig/std/debug.zig:374:22: 0x1024665c7 in panicExtra__anon_3679 (x)
std.builtin.panic(msg, trace, ret_addr);
^
/opt/homebrew/Cellar/zig/0.11.0/lib/zig/std/debug.zig:349:15: 0x102465327 in panic__anon_2692 (x)
panicExtra(null, null, format, args);
^
/private/tmp/x.zig:4:20: 0x102464b9b in main (x)
std.debug.panic("not implemented", .{});
^
/opt/homebrew/Cellar/zig/0.11.0/lib/zig/std/start.zig:564:22: 0x102464987 in main (x)
root.main();
^
???:?:?: 0x1027bd08b in ??? (???)
???:?:?: 0xfd43ffffffffffff in ??? (???)
the frames should stop at the panic call going down, and basically not bother with startup frames either since they aren't helpful either, at least not in this case, so:
thread 16502146 panic: not implemented
/private/tmp/x.zig:4:20: 0x102464b9b in main (x)
std.debug.panic("not implemented", .{});
^
then the person should replace their call with @panic + std.fmt.[alloc|buf]Print
Ah, didn't even realize it exists. Yes, it does print nicer backtrace, however, the docs are describing @panic as something you'd use only in special scenarios rather than by default.
Generally it is better to use
@import("std").debug.panic. However,@paniccan be useful for 2 scenarios:
- From library code, calling the programmer's panic function if they exposed one in the root source file.
- When mixing C and Zig code, calling the canonical panic implementation across multiple .o files.
the panic continuing deeper into the stdlib code was just fixed by #19622. not sure what exactly andrew was referring to with this issue but it still does show stuff from start.zig, it would definitely be nice if it didnt