For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > July 2006 > Stack dumping with gcc









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Stack dumping with gcc
Valh

2006-07-13, 8:01 am

Hello,

I am trying to use the glibc functions backtrace*() to dump the stack. It
works but only partially - is there any way to have the functions' names?

snd_pcm_writei(hw:0) error: Broken pipe
../p2p [0x804995e]
../p2p [0x8049940]
../p2p [0x804ac07]
../p2p [0x80495be]
/lib/tls/libc.so.6(__libc_start_main+0xd3) [0x3e1e23]
../p2p [0x80493f5]

The code looks like:

void *array[ STACK_DUMP_SZ ];
size_t size;
char **strings;

size = backtrace( array, STACK_DUMP_SZ );
strings = backtrace_symbols( array, size );

if ( strings ) {
int i;
for ( i = 0; i < size; i++ )
fprintf( fp, "%s\n", strings[i] );
free( strings );
}


Regards
a.


John McCallum

2006-07-13, 6:59 pm

Hiya,

Valh wrote:

> I am trying to use the glibc functions backtrace*() to dump the stack. It
> works but only partially - is there any way to have the functions' names?


That'll probably be because be because you didn't link with -rdynamic
(assuming that your platform uses ELF):

> Currently, the function name and offset only be obtained on systems
> that use the ELF binary format for programs and libraries. On other
> systems, only the hexadecimal return address will be present. Also,
> you may need to pass additional flags to the linker to make the
> function names available to the program. (For example, on systems
> using GNU ld, you must pass (-rdynamic.)


Cheers,
--
John McCallum
Emerson Network Power - Embedded Computing, Edinburgh, UK

For email, leave the web and we're not so small.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com