authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-10 20:18:58-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-20 22:58:15-04:00
loge5aa2bb2246e79f47c39c281d51cc9b5a6d89d04
treec10fc0d0700ac00378a1b79ecb912e6ed79f49e1
parent891fa3b8b54428ad8065de8660869cd38876e429

debug: fixup last_error being printed too many times


2 files changed, 16 insertions(+), 10 deletions(-)

lib/std/debug.zig+16-9
......@@ -493,6 +493,7 @@ pub const StackIterator = struct {
493493 debug_info: *DebugInfo,
494494 dwarf_context: DW.UnwindContext,
495495 last_error: ?UnwindError = null,
496 failed: bool = false,
496497 } else void = if (have_ucontext) null else {},
497498
498499 pub fn init(first_address: ?usize, fp: ?usize) StackIterator {
......@@ -530,6 +531,7 @@ pub const StackIterator = struct {
530531 if (!have_ucontext) return null;
531532 if (self.unwind_state) |*unwind_state| {
532533 if (unwind_state.last_error) |err| {
534 unwind_state.last_error = null;
533535 return .{
534536 .err = err,
535537 .address = unwind_state.dwarf_context.pc,
......@@ -648,15 +650,20 @@ pub const StackIterator = struct {
648650 fn next_internal(self: *StackIterator) ?usize {
649651 if (have_ucontext) {
650652 if (self.unwind_state) |*unwind_state| {
651 if (unwind_state.dwarf_context.pc == 0) return null;
652 if (unwind_state.last_error == null) {
653 if (self.next_unwind()) |return_address| {
654 return return_address;
655 } else |err| {
656 unwind_state.last_error = err;
657
658 // Fall back to fp-based unwinding on the first failure
659 self.fp = unwind_state.dwarf_context.getFp() catch 0;
653 if (!unwind_state.failed) {
654 if (unwind_state.dwarf_context.pc == 0) return null;
655 if (unwind_state.last_error == null) {
656 if (self.next_unwind()) |return_address| {
657 return return_address;
658 } else |err| {
659 unwind_state.last_error = err;
660 unwind_state.failed = true;
661
662 // Fall back to fp-based unwinding on the first failure.
663 // We can't attempt it for other modules later in the
664 // stack because the full register state won't be unwound.
665 self.fp = unwind_state.dwarf_context.getFp() catch 0;
666 }
660667 }
661668 }
662669 }
lib/std/dwarf/expressions.zig-1
......@@ -1023,7 +1023,6 @@ pub fn Builder(comptime options: ExpressionOptions) type {
10231023 try leb.writeULEB128(writer, value_bytes.len);
10241024 try writer.writeAll(value_bytes);
10251025 }
1026
10271026 };
10281027}
10291028