authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-06 18:58:03+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-07 16:47:57+02:00
logfdd109420d1c3d23a7a5a1036634b033b25cac04
tree381d475d3c92c25c19261c9bb96aea1a56692370
parent0b33891f4c5a1de378ff6035380b84abbebfa6e2
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.debug: add noinline to functions that capture the current stack trace

Fixes stack traces missing a frame depending on inlining decisions. ref https://github.com/ziglang/zig/issues/25418

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

lib/std/debug.zig+2-2
......@@ -623,7 +623,7 @@ pub const StackUnwindOptions = struct {
623623/// the given buffer, so `addr_buf` must have a lifetime at least equal to the `StackTrace`.
624624///
625625/// See `writeCurrentStackTrace` to immediately print the trace instead of capturing it.
626pub fn captureCurrentStackTrace(options: StackUnwindOptions, addr_buf: []usize) std.builtin.StackTrace {
626pub noinline fn captureCurrentStackTrace(options: StackUnwindOptions, addr_buf: []usize) std.builtin.StackTrace {
627627 const empty_trace: std.builtin.StackTrace = .{ .index = 0, .instruction_addresses = &.{} };
628628 if (!std.options.allow_stack_tracing) return empty_trace;
629629 var it = StackIterator.init(options.context) catch return empty_trace;
......@@ -661,7 +661,7 @@ pub fn captureCurrentStackTrace(options: StackUnwindOptions, addr_buf: []usize)
661661/// Write the current stack trace to `writer`, annotated with source locations.
662662///
663663/// See `captureCurrentStackTrace` to capture the trace addresses into a buffer instead of printing.
664pub fn writeCurrentStackTrace(options: StackUnwindOptions, writer: *Writer, tty_config: tty.Config) Writer.Error!void {
664pub noinline fn writeCurrentStackTrace(options: StackUnwindOptions, writer: *Writer, tty_config: tty.Config) Writer.Error!void {
665665 if (!std.options.allow_stack_tracing) {
666666 tty_config.setColor(writer, .dim) catch {};
667667 try writer.print("Cannot print stack trace: stack tracing is disabled\n", .{});