The first element stores the length of the stack trace including skipped frames. The remaining elements store the return addresses.
fn captureStackTrace(trace_buf: []usize, ra: usize) void
fn captureStackTrace(trace_buf: []usize, ra: usize) void {
if (trace_buf.len == 0) return;
if (ra == 0) { // No return address provided
@branchHint(.unlikely);
trace_buf[0] = 0;
return;
}
const t = std.debug.captureCurrentStackTrace(.{ .first_address = ra }, trace_buf[1..]);
const skipped = @backingInt(t.skipped) *
@intFromBool(t.return_addresses.len == trace_buf[1..].len);
trace_buf[0] = t.return_addresses.len +| skipped;
}