From 4884c4e99b5a18458a5bca56425bf5d66c1f4f92 Mon Sep 17 00:00:00 2001 From: Jeremy <51220084+jeremy-rifkin@users.noreply.github.com> Date: Sun, 19 May 2024 16:36:07 -0500 Subject: [PATCH] Fix frame pointer calculation for symbol frames under libunwind, #123 --- src/unwind/unwind_with_libunwind.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/unwind/unwind_with_libunwind.cpp b/src/unwind/unwind_with_libunwind.cpp index 639df80..fc22a58 100644 --- a/src/unwind/unwind_with_libunwind.cpp +++ b/src/unwind/unwind_with_libunwind.cpp @@ -57,9 +57,16 @@ namespace detail { if(skip) { skip--; } else { - // pc is the instruction after the `call`, adjust back to the previous instruction - // just a cast, signal safe - buffer[i] = to_frame_ptr(pc) - 1; + // thread and signal-safe + if(unw_is_signal_frame(&cursor)) { + // pc is the instruction that caused the signal + // just a cast, thread and signal safe + buffer[i] = to_frame_ptr(pc); + } else { + // pc is the instruction after the `call`, adjust back to the previous instruction + // just a cast, thread and signal safe + buffer[i] = to_frame_ptr(pc) - 1; + } i++; } // thread and signal-safe as long as the cursor is in the local address space, which it is