LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   backtrace your program? (https://www.linuxquestions.org/questions/programming-9/backtrace-your-program-555289/)

lswhbcb 05-19-2007 10:52 PM

backtrace your program?
 
hi all:

i meet a problem . i wanna backtrace my program whiling asserting fail. but the backtrace info from GNU c library do not cantain the function name and the line number in soure file.

void WxcBackTrace()
{
int i;
void * array[25];
int nSize = backtrace(array, 25);
char ** symbols = backtrace_symbols(array, nSize);

for (i = 0; i < nSize; i++)
{
printf("%s \n" , symbols[i]);
}
free(symbols);
}


how can i let the backtrace function to give the detail info like gdb.


(gdb) bt
#0 sprintf_bcd (
pBcdBuff=0xbfe92ee0 "\001\002\003\004\005\006\a\b\t\n\v\f\r\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\ 035\036\037 !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOP`^\\ZXVTRPNLJHFDB@><:86420.,*(&$\" \036\034\032\030\026\024\022\020\016\f\n\b\006\004\002", nBcdLen=30, pStrBuff=0xbfe92de0 "-0", nStrBuffSize=256) at prt_bcd.c:56
#1 0x08048b0e in main () at prt_bcd.c:102

Matir 05-20-2007 11:34 AM

I'd take a look at this documentation: http://www.delorie.com/gnu/docs/glibc/libc_665.html

lswhbcb 05-20-2007 09:02 PM

Thank you , Matir ,I do it as the libc document indication. But it do not contain the function name and code line number info of the function stack. how to print these info in my program ?

Matir 05-20-2007 09:27 PM

Did you use -rdynamic when compiling? Also, the glibc backtrace functionality does not include line numbers, only instruction offsets.

lswhbcb 05-24-2007 09:57 PM

i do not use -rdynamic when compiling. what a pity that the backtrace glibc does not contain the function name and line number inforamtion in tracktrace stack like gdb.

Matir 05-24-2007 10:56 PM

With -rdynamic, you can get function name and instruction offset. Without the dynamic linkage, there is no way to translate an address to a function name without access to the original source.

lswhbcb 05-24-2007 11:35 PM

OK, I get the function name with -rdynamic flag and get the line nuber with macro assert[from "__FILE__" "__LINE__" ], pretty good .


All times are GMT -5. The time now is 03:08 AM.