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 |
I'd take a look at this documentation: http://www.delorie.com/gnu/docs/glibc/libc_665.html
|
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 ?
|
Did you use -rdynamic when compiling? Also, the glibc backtrace functionality does not include line numbers, only instruction offsets.
|
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.
|
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.
|
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. |