相关疑难解决方法(0)

如何展开堆栈以获取指定堆栈指针(SP)的回溯?

我正在为Android(仅限ARM)编写这个,但我相信通用Linux的原理也是如此.

我正在尝试从信号处理程序中捕获堆栈跟踪,以便我可以在应用程序崩溃时记录它.这就是我想出来的用法<unwind.h>.
初始化:

struct sigaction signalhandlerDescriptor;
memset(&signalhandlerDescriptor, 0, sizeof(signalhandlerDescriptor));
signalhandlerDescriptor.sa_flags = SA_SIGINFO;
signalhandlerDescriptor._u._sa_sigaction = signalHandler;
sigaction(SIGSEGV, &signalhandlerDescriptor, 0);
Run Code Online (Sandbox Code Playgroud)

代码本身:

struct BacktraceState
{
    void** current;
    void** end;
    void* pc;
};

inline _Unwind_Reason_Code unwindCallback(struct _Unwind_Context* context, void* arg)
{
    BacktraceState* state = static_cast<BacktraceState*>(arg);
    state->pc = (void*)_Unwind_GetIP(context);
    if (state->pc)
    {
        if (state->current == state->end)
            return _URC_END_OF_STACK;
        else
            *state->current++ = reinterpret_cast<void*>(state->pc);
    }
    return _URC_NO_REASON;
}

inline size_t captureBacktrace(void** addrs, size_t max, unsigned long pc)
{
    BacktraceState state = {addrs, addrs + max, …
Run Code Online (Sandbox Code Playgroud)

c++ linux arm backtrace android-ndk

29
推荐指数
2
解决办法
4459
查看次数

ARM:链接寄存器和帧指针

我试图理解链接寄存器和帧指针在ARM中是如何工作的.我去过几个网站,我想确认一下我的理解.

假设我有以下代码:

int foo(void)
{
    // ..
    bar();
    // (A)
    // ..
}

int bar(void)
{
    // (B)
    int b1;
    // ..
    // (C)
    baz();
    // (D)
}

int baz(void)
{
    // (E)
    int a;
    int b;
    // (F)
}
Run Code Online (Sandbox Code Playgroud)

我叫foo().将链接寄存器包含在点(A)的地址码和帧指针包含在代码点(B)的地址?在声明了所有本地人之后,堆栈指针可以是bar()内的任何位置吗?

[编辑]添加了另一个函数调用baz()

c arm

28
推荐指数
1
解决办法
5万
查看次数

标签 统计

arm ×2

android-ndk ×1

backtrace ×1

c ×1

c++ ×1

linux ×1