c - 使用回调函数报告堆栈回溯

标签 c x86 stack-trace

假设我有以下内容:

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 静态全局指针来识别发生错误的函数然后通过堆栈回溯以通过地址、名称和偏移量来识别每个调用函数的最佳方法是什么?

最佳答案

关于c - 使用回调函数报告堆栈回溯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2933697/

相关文章:

指针与整数比较错误

linux - ptrace 能否判断 x86 系统调用使用的是 64 位还是 32 位 ABI?

java - 为什么我在创建自己的异常时得到一个空的堆栈跟踪?

自动确定调用者的类名的 Java 记录器

c++ - 这个堆栈跟踪可能意味着什么?

c++ - 如何让 rdoc 从我的 c 扩展中正确读取方法参数?

c - C 中的递归不返回字符串值

assembly - x64 指令编码和 ModRM 字节

linux - 读写文件汇编

javascript - 从 LWIP 服务器响应中检索 16 位整数