Skip to content

Commit

Permalink
Merge 3aa49d1 into b3cba2b
Browse files Browse the repository at this point in the history
  • Loading branch information
kattrali committed Oct 17, 2018
2 parents b3cba2b + 3aa49d1 commit a0888c3
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion ndk/src/main/jni/utils/stack_unwinder_libunwind.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
typedef struct {
size_t frame_count;
uintptr_t frame_addresses[BUGSNAG_FRAMES_MAX];
#if defined(__arm__)
void *signal_context;
#endif
siginfo_t *signal_info;
} bsg_libunwind_state;

bsg_libunwind_state *bsg_global_libunwind_state;
Expand All @@ -19,6 +23,36 @@ bool bsg_configure_libunwind(void) {
static _Unwind_Reason_Code
bsg_libunwind_callback(struct _Unwind_Context *context, void *arg) __asyncsafe {
bsg_libunwind_state *state = (bsg_libunwind_state *)arg;

#if defined(__arm__)
if (state->frame_count == 0 && state->signal_context != NULL &&
state->signal_info != NULL && state->signal_info->si_signo != SIGABRT) {
const ucontext_t *signal_ucontext =
(const ucontext_t *)state->signal_context;
const struct sigcontext *signal_mcontext = &(signal_ucontext->uc_mcontext);
// Set the registers and initial frame to the values from the signal
// handler user context
_Unwind_SetGR(context, REG_R0, signal_mcontext->arm_r0);
_Unwind_SetGR(context, REG_R1, signal_mcontext->arm_r1);
_Unwind_SetGR(context, REG_R2, signal_mcontext->arm_r2);
_Unwind_SetGR(context, REG_R3, signal_mcontext->arm_r3);
_Unwind_SetGR(context, REG_R4, signal_mcontext->arm_r4);
_Unwind_SetGR(context, REG_R5, signal_mcontext->arm_r5);
_Unwind_SetGR(context, REG_R6, signal_mcontext->arm_r6);
_Unwind_SetGR(context, REG_R7, signal_mcontext->arm_r7);
_Unwind_SetGR(context, REG_R8, signal_mcontext->arm_r8);
_Unwind_SetGR(context, REG_R9, signal_mcontext->arm_r9);
_Unwind_SetGR(context, REG_R10, signal_mcontext->arm_r10);
_Unwind_SetGR(context, REG_R11, signal_mcontext->arm_fp);
_Unwind_SetGR(context, REG_R12, signal_mcontext->arm_ip);
_Unwind_SetGR(context, REG_R13, signal_mcontext->arm_sp);
_Unwind_SetGR(context, REG_R14, signal_mcontext->arm_lr);
_Unwind_SetGR(context, REG_R15, signal_mcontext->arm_pc);
state->frame_addresses[state->frame_count] = signal_mcontext->arm_pc;
state->frame_count++;
return _URC_NO_REASON;
}
#endif
uintptr_t ip = _Unwind_GetIP(context);

if (state->frame_count >= BUGSNAG_FRAMES_MAX) {
Expand All @@ -34,8 +68,12 @@ bsg_libunwind_callback(struct _Unwind_Context *context, void *arg) __asyncsafe {

ssize_t
bsg_unwind_stack_libunwind(bsg_stackframe stacktrace[BUGSNAG_FRAMES_MAX],
siginfo_t*_info, void *_user_context) {
siginfo_t *info, void *user_context) {
bsg_global_libunwind_state->frame_count = 0;
#if defined(__arm__)
bsg_global_libunwind_state->signal_context = user_context;
#endif
bsg_global_libunwind_state->signal_info = info;
// The return value of _Unwind_Backtrace sits on a throne of lies
_Unwind_Backtrace(bsg_libunwind_callback, bsg_global_libunwind_state);
for (int i = 0; i < bsg_global_libunwind_state->frame_count; ++i) {
Expand Down

0 comments on commit a0888c3

Please sign in to comment.