debug: fixup last_error being printed too many times

This commit is contained in:
kcbanner 2023-07-10 20:18:58 -04:00
parent 891fa3b8b5
commit e5aa2bb224
2 changed files with 15 additions and 9 deletions

View File

@ -493,6 +493,7 @@ pub const StackIterator = struct {
debug_info: *DebugInfo,
dwarf_context: DW.UnwindContext,
last_error: ?UnwindError = null,
failed: bool = false,
} else void = if (have_ucontext) null else {},
pub fn init(first_address: ?usize, fp: ?usize) StackIterator {
@ -530,6 +531,7 @@ pub const StackIterator = struct {
if (!have_ucontext) return null;
if (self.unwind_state) |*unwind_state| {
if (unwind_state.last_error) |err| {
unwind_state.last_error = null;
return .{
.err = err,
.address = unwind_state.dwarf_context.pc,
@ -648,15 +650,20 @@ pub const StackIterator = struct {
fn next_internal(self: *StackIterator) ?usize {
if (have_ucontext) {
if (self.unwind_state) |*unwind_state| {
if (unwind_state.dwarf_context.pc == 0) return null;
if (unwind_state.last_error == null) {
if (self.next_unwind()) |return_address| {
return return_address;
} else |err| {
unwind_state.last_error = err;
if (!unwind_state.failed) {
if (unwind_state.dwarf_context.pc == 0) return null;
if (unwind_state.last_error == null) {
if (self.next_unwind()) |return_address| {
return return_address;
} else |err| {
unwind_state.last_error = err;
unwind_state.failed = true;
// Fall back to fp-based unwinding on the first failure
self.fp = unwind_state.dwarf_context.getFp() catch 0;
// Fall back to fp-based unwinding on the first failure.
// We can't attempt it for other modules later in the
// stack because the full register state won't be unwound.
self.fp = unwind_state.dwarf_context.getFp() catch 0;
}
}
}
}

View File

@ -1023,7 +1023,6 @@ pub fn Builder(comptime options: ExpressionOptions) type {
try leb.writeULEB128(writer, value_bytes.len);
try writer.writeAll(value_bytes);
}
};
}