Stop fp unwinding if the pc is 0.
The android_unsafe_frame_pointer_chase keeps going even when a
frame is 0. Modify the unwind to stop when this case is found.
I found this while running the GwpAsanCrasherTest.run_gwp_asan_test
from debuggerd_test and printing the tombstone created. The
deallocated by and allocated by stack traces always ended in 0 frame.
After fixing this, the last 0 frame is no longer present.
Test: Ran the debuggerd test and printed the tombstone on a raven
Test: verifying that the last frame is non-zero.
Test: Ran the bionic unit tests.
Change-Id: I8d64679277abcf5f237e6759051db11ffaa34c2f
diff --git a/libc/bionic/android_unsafe_frame_pointer_chase.cpp b/libc/bionic/android_unsafe_frame_pointer_chase.cpp
index 58b7cd8..7d5cd6c 100644
--- a/libc/bionic/android_unsafe_frame_pointer_chase.cpp
+++ b/libc/bionic/android_unsafe_frame_pointer_chase.cpp
@@ -82,7 +82,11 @@
auto* frame = reinterpret_cast<frame_record*>(begin);
#endif
if (num_frames < num_entries) {
- buf[num_frames] = __bionic_clear_pac_bits(frame->return_addr);
+ uintptr_t addr = __bionic_clear_pac_bits(frame->return_addr);
+ if (addr == 0) {
+ break;
+ }
+ buf[num_frames] = addr;
}
++num_frames;
if (frame->next_frame < begin + sizeof(frame_record) || frame->next_frame >= end ||