aboutsummaryrefslogtreecommitdiff
path: root/lib/std/builtin.zig
diff options
context:
space:
mode:
authorCody Tapscott <topolarity@tapscott.me>2022-09-25 20:18:15 -0700
committerCody Tapscott <topolarity@tapscott.me>2022-10-21 12:40:33 -0700
commita4523a2d4a0fb2b5c660a11aa37718080eebe9d0 (patch)
tree2d03ffade98f1d46db5af94eae7be40c998b93e7 /lib/std/builtin.zig
parentd060cbbec75ac7b0204c706e4dfdfb38f1b24dfd (diff)
downloadzig-a4523a2d4a0fb2b5c660a11aa37718080eebe9d0.tar.gz
zig-a4523a2d4a0fb2b5c660a11aa37718080eebe9d0.zip
builtin.zig: Do not overwrite error frames when trace full
Previously, we'd overwrite the errors in a circular buffer. Now that error return traces are intended to follow a stack discipline, we no longer have to support the index rolling over. By treating the trace like a saturating stack, any pop/restore code still behaves correctly past-the-end of the trace. As a bonus, this adds a small blurb to let the user know when the trace saturated and x number of frames were dropped.
Diffstat (limited to 'lib/std/builtin.zig')
-rw-r--r--lib/std/builtin.zig6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig
index c772d8e6f9..430a29c9d7 100644
--- a/lib/std/builtin.zig
+++ b/lib/std/builtin.zig
@@ -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");