use callback function to report stack backtrace

Posted by user353394 on Stack Overflow See other posts from Stack Overflow or by user353394
Published on 2010-05-29T03:44:42Z Indexed on 2010/05/29 3:52 UTC
Read the original article Hit count: 261

Filed under:
|
|

Assume I have the following:

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);
}

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?

© Stack Overflow or respective owner

Related posts about c

    Related posts about x86