Unable to print function names in stacktrace

H

Hitesh Patel

hi friends,

I am using backtrace() and backtrace_symbols() functions from execinfo.h.

when I print backtrace I get only hex address of every function call. I know
that to get functions names, binary format of executable file must be ELF.

I set -rdynamic option during compilation but I don't get functions names.
is there any other otion we have to set?

pls help me.

my code is as follows

void *btArray[128];
int btSize;
char** btSymbols;

cout << endl << "########## Backtrace ##########" << endl;
btSize = backtrace(btArray, sizeof(btArray) / sizeof(void *));
cout << "Number of elements in backtrace: " << btSize << endl;

if (btSize > 0) {

btSymbols = backtrace_symbols(btArray, btSize);
if (btSymbols) {
for (int i = btSize - 1; i >= 0; --i) {
cout << btSymbols << endl;
}
}
}

I am using
gcc -v
Using built-in specs.
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.2.2 [FreeBSD] 20030205 (release)

Thanks in advance.
 
V

Victor Bazarov

Hitesh Patel said:
I am using backtrace() and backtrace_symbols() functions from execinfo.h.
[...]

Neither 'backtrace' nor 'backtrace_symbols' is a standard function.
Perhaps you should ask in a newsgroup where they would be on topic,
like gnu.gcc.help or the newsgroup for FreeBDS.
 
H

Hitesh Patel

Victor Bazarov said:
Hitesh Patel said:
I am using backtrace() and backtrace_symbols() functions from execinfo.h.
[...]

Neither 'backtrace' nor 'backtrace_symbols' is a standard function.
Perhaps you should ask in a newsgroup where they would be on topic,
like gnu.gcc.help or the newsgroup for FreeBDS.

I found one utility named addr2line in freeBSD. which gives function name,
file name and line number if code is compiled in debug mode. otherwise only
give function name.

Hitesh Patel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top