Displaying the function stack trace

Displaying the function stack trace

Post by Guenther Sohle » Thu, 26 Jun 2003 14:00:39



I have written a program, which is very complicated
and so it happens quite often, that it has to exit itself,
because its handling an invalid index of an array.
(It never crashes, it always nicely exits).
Nevertheless - in that case, It would be very nice
if my program could display the function hierarchy,
how my program reached that exit.
I have already seen programs doing that, before they crashed.
How can I do this on a unix/linux system ?
Are there special functions to read the symbols contained within the ELF
File ?

rds

 
 
 

Displaying the function stack trace

Post by Bjorn Rees » Fri, 27 Jun 2003 01:56:52



> Nevertheless - in that case, It would be very nice
> if my program could display the function hierarchy,
> how my program reached that exit.

Use abort() instead of exit(). This will leave a core file that
you can use for post-mortem debugging.

 
 
 

Displaying the function stack trace

Post by Shaun Clowe » Fri, 27 Jun 2003 07:08:57



Quote:

> Nevertheless - in that case, It would be very nice
> if my program could display the function hierarchy,
> how my program reached that exit.

There are actually a few requirements to achieve your goal:

- Perform a backtrace, that is, trace the calling execution path
- Determine which files are where in memory
- Use the file symbol information to convert to the addresses in the
execution path into symbol names

You can do this manually (which is interesting work, but kind of a pain) or
use the glibc support functions (since you mention you're on linux). Take a
look at
http://elvin.dstc.com/ListArchive/elvin-dev/archive/2001/10/msg00077.....

Cheers,
Shaun

 
 
 

Displaying the function stack trace

Post by ndevi.. » Sat, 28 Jun 2003 19:10:51


[...]

Quote:> Nevertheless - in that case, It would be very nice
> if my program could display the function hierarchy,
> how my program reached that exit.

You may want to have a look at etrace:
http://ndevilla.free.fr/etrace/index.html

This tiny module allows you to trace your function
calls and print the stack as the program is running.
It only works with gcc, but on most Unixes though.

Hope it helps
--
Nicolas

 
 
 

1. stack trace within a function

I am developing code using a SPARC processor running Solaris2.3.  For the stuff I am writing it would be really useful to be able to see where I am.  What I would like to be able to do is get a stack trace of the function calls from main that got me there.  Something like the 'info stack' in gdb or 'where' in dbx, but for the current process, not a child process.  I am not really interested in other debug information like argument names and source line numbers (but wouldn't mind if they where no extra hass
le), I just want the function names.

I had a bit of a look at the source code for gdb but got completely lost.

Is there an easy way of doing this?  If so, where do I start?

thankyou for your help
James Woods

2. I want more colors under X

3. stack trace function

4. connecting to the internet with @home (lan setup)

5. t: Displaying stack trace without using sdb

6. Do people really use WINE?

7. Problems calling a gdb stack trace from inside the program thats being traced.

8. squid hierarchical cache problem

9. Stack trace in C/C++

10. stack trace

11. Stack trace wanted

12. Stack trace - Multi threaded

13. Stack Trace dump in do_IRQ