Android _Unwind_Backtrace inside sigaction

前端 未结 3 1589
栀梦
栀梦 2021-02-15 11:53

I am trying to catch signals such as SIGSEGV in my Android NDK app for debugging purpose. For that, I have set up a sigaction that is called.

I am now trying to get the

3条回答
  •  渐次进展
    2021-02-15 12:22

    In my practice standard _Unwind_Backtrace failed to switch to pre-signal stack.

    I've managed to get some before-signal stacks by calling internal libgcc __gnu_Unwind_Backtrace - it has an extra agrument being "current registry values" - so it operates on given stack, not on current stack.

    //definitions copied from arm-specific libgcc 4.8 sources.
    struct core_regs
    {
      _uw r[16];
    };
    
    typedef struct
    {
      _uw demand_save_flags;
      struct core_regs core;
    } phase2_vrs;
    
    extern "C"
    _Unwind_Reason_Code
    __gnu_Unwind_Backtrace(_Unwind_Trace_Fn trace, void * trace_argument,
                   phase2_vrs * entry_vrs);
    
    // Getting backtrace with those definitions
    //istead of _Unwind_Backtrace(tracer, &state);
    if (const ucontext_t* signal_context = last_sigaction_parameter)
    {
          phase2_vrs pre_signal_state = {};
          pre_signal_state.core = *reinterpret_cast(&(signal_context->uc_mcontext.arm_r0));
          __gnu_Unwind_Backtrace(tracer, &state, &pre_signal_state);
    }
    

提交回复
热议问题