假設我有以下幾點:利用回調函數來報告堆棧跟蹤
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靜態全局指針,以標識出錯的功能的最佳途徑和然後通過堆棧回溯以通過地址,名稱和偏移來識別每個調用函數?
http://stackoverflow.com/questions/3151779/how-its-better-to-invoke-gdb-from-program-to-print-its-stacktrace/4611112#4611112 – karlphillip 2011-01-06 02:09:19