使用回调函数来报告堆栈跟踪 [英] use callback function to report stack backtrace

查看:93
本文介绍了使用回调函数来报告堆栈跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下几点:

typedef struct {
   char *name;
   char binding;
   int address;
} Fn_Symbol               //definition of function symbol

static Fn_Symbol *fnSymbols; //array of function symbols in a file
statc int total;  //number of symbol functions in the array and file

static void PrintBacktrace(int sigum, siginfo_t * siginfo, void *context)
{
   printf("\nSignal received %d (%s)\n", signum, strsignal(signum));
   const int eip_index = 14; 
   void *eip = (void *)((struct ucontext *)context)->uc_mcontext.gregs[eip_index];
   printf("Error at [%p]  %s (+0x%x), eip, fnName, offset from start); //?????
   exit(0);
}

我有这到目前为止,但什么是使用fnSymbols静态全局指针通过堆栈来标识错误发生的函数,然后回溯追踪识别由地址,名称为每个调用函数,和偏移的最佳方式?

I have this so far, but what is the best way using the fnSymbols static global pointer to identify the function where the error occured and then back trace through the stack to identify each calling function by address, name, and offset?

推荐答案

的http:// Linux操作系统。 die.net/man/3/backtrace_symbols

这篇关于使用回调函数来报告堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆