LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-19-2007, 11:52 PM   #1
lswhbcb
LQ Newbie
 
Registered: Apr 2007
Posts: 11

Rep: Reputation: 0
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
 
Old 05-20-2007, 12:34 PM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
I'd take a look at this documentation: http://www.delorie.com/gnu/docs/glibc/libc_665.html
 
Old 05-20-2007, 10:02 PM   #3
lswhbcb
LQ Newbie
 
Registered: Apr 2007
Posts: 11

Original Poster
Rep: Reputation: 0
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 ?
 
Old 05-20-2007, 10:27 PM   #4
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Did you use -rdynamic when compiling? Also, the glibc backtrace functionality does not include line numbers, only instruction offsets.
 
Old 05-24-2007, 10:57 PM   #5
lswhbcb
LQ Newbie
 
Registered: Apr 2007
Posts: 11

Original Poster
Rep: Reputation: 0
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.
 
Old 05-24-2007, 11:56 PM   #6
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
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.
 
Old 05-25-2007, 12:35 AM   #7
lswhbcb
LQ Newbie
 
Registered: Apr 2007
Posts: 11

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting stack backtrace for all instantiated threads bcreane Programming 2 05-02-2006 11:58 AM
Alsa backtrace? hosler Slackware 9 02-07-2006 01:23 AM
how to make a good backtrace in C/C++? Thinking Programming 1 12-06-2005 08:16 AM
kde crash backtrace help MRDucks Mandriva 1 11-14-2005 02:10 PM
How to interpret backtrace (gdb) jnusa Programming 1 12-06-2004 10:16 AM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration