ARM上没有生成回溯

时间:2015-05-06 06:12:12

标签: c

我正在研究ARM体系结构,并希望在运行时生成回溯。但它没有按预期工作:

#include <stdio.h>
#include <execinfo.h>
#include <stdlib.h>
#include <signal.h>

#include <sys/syscall.h>

struct ss
{
        int i;
};

static void    dumpstack(int signum, siginfo_t *p_siginfo, void *p_sigcontext)
{
        struct sigaction    *old_sigaction_p;
        void                            *trace[1024];
        int                     trace_size, i;


        printf("Trapped signal %d in process %d thread %ld FAULT at %p ...\n",
        signum, getpid(), syscall(SYS_gettid), p_siginfo->si_addr);

printf("Trapped signal %d in process %d thread %ld FAULT at %p ...\n",
        signum, getpid(), syscall(SYS_gettid), p_siginfo->si_addr);
        printf("Dumping stack for process %d,%ld ...\n", getpid(), pthread_self((
));

        trace_size = backtrace(trace, 1024);

        printf("************************\n");
        printf("[bt] Execution path:\n");
        //backtrace_symbols_fd(trace, trace_size, 1);
        //printf("Trace Size : %d\n", trace_size);

        char** str      = backtrace_symbols(trace, trace_size);
        printf("Trace Size : %d\n", trace_size);
        for (i = 0; i < trace_size; ++i) {
             printf("%d - %s\n", i, str[i]);
         }
        free(str);
        printf("************************\n");

        exit(0);
}

int Signal_Setup(void)
{
        struct sigaction    sigaction_v;

        //common settings for all signals
        sigaction_v.sa_handler          = NULL;
        sigaction_v.sa_restorer                 = NULL;
        sigfillset(&sigaction_v.sa_mask);

        sigaction_v.sa_sigaction        = dumpstack;
        sigaction_v.sa_flags            = SA_SIGINFO;

        int i;
        for(i=1;i<33;i++)
        {
                sigaction(i, &sigaction_v, NULL);
        }
        return 0;
}

int main()void abc(struct ss *s)
{
        printf("%d", s->i);
}

{
        struct ss       *s;
        Signal_Setup();
        printf("Hello world\n");
        abc(s);
        return 0;
}

以上是我的代码段,我正在使用-rdynamic-g标记进行编译。

显示输出为:

Hello world
Trapped signal 11 in process 3401 thread 3401 FAULT at (nil) ...
Dumping stack for process 3401,0 ...
************************
[bt] Execution path:
Trace Size : 0
************************

请告诉我需要做些什么才能获得适当的回溯。

0 个答案:

没有答案