Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stage2: Pop error trace frames for handled errors (#1923) #12837

Merged
merged 12 commits into from
Oct 22, 2022
Merged
6 changes: 4 additions & 2 deletions lib/std/builtin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,10 @@ pub noinline fn returnError(st: *StackTrace) void {
}

pub inline fn addErrRetTraceAddr(st: *StackTrace, addr: usize) void {
st.instruction_addresses[st.index & (st.instruction_addresses.len - 1)] = addr;
st.index +%= 1;
if (st.index < st.instruction_addresses.len)
st.instruction_addresses[st.index] = addr;

st.index += 1;
}

const std = @import("std.zig");
Expand Down
8 changes: 8 additions & 0 deletions lib/std/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,14 @@ pub fn writeStackTrace(
const return_address = stack_trace.instruction_addresses[frame_index];
try printSourceAtAddress(debug_info, out_stream, return_address - 1, tty_config);
}

if (stack_trace.index > stack_trace.instruction_addresses.len) {
const dropped_frames = stack_trace.index - stack_trace.instruction_addresses.len;

tty_config.setColor(out_stream, .Bold);
try out_stream.print("({d} additional stack frames skipped...)\n", .{dropped_frames});
tty_config.setColor(out_stream, .Reset);
}
}

pub const StackIterator = struct {
Expand Down
5 changes: 5 additions & 0 deletions src/Air.zig
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,10 @@ pub const Inst = struct {
/// Uses the `ty_op` field.
addrspace_cast,

/// Saves the error return trace index, if any. Otherwise, returns 0.
/// Uses the `ty_pl` field.
save_err_return_trace_index,

pub fn fromCmpOp(op: std.math.CompareOperator, optimized: bool) Tag {
switch (op) {
.lt => return if (optimized) .cmp_lt_optimized else .cmp_lt,
Expand Down Expand Up @@ -1179,6 +1183,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
.slice_len,
.ret_addr,
.frame_addr,
.save_err_return_trace_index,
=> return Type.usize,

.wasm_memory_grow => return Type.i32,
Expand Down
Loading