This is the mail archive of the egcs@egcs.cygnus.com mailing list for the EGCS project. See the EGCS home page for more information.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
On Thu, 25 Mar 1999, Jeffrey A Law wrote: > > In message <E10QOsn-0004a6-00@roboto.devolution.com>you write: > > Is there any way to generate a stack trace from within a running program? > > i.e. save a backtrace in memory and periodically flush it to disk? > > (On ix86 Linux) > It's certainly possible, but there's no simple function lying around to > do it. > > One approach would be to use the dwarf2 unwind tables to walk up the stack. > The other would be to duplicate the frame chain building found in gdb. > > jeff > Why not use the kernel programmer's idea and overload malloc with a macro to track which line/file each block of memory is allocated from? This is obviously unacceptable for release code, but can be invaluable for debug and developement code. Here's some other idea, why not have your program accept a signal and mark a flag, that way at the next call to malloc (which you've overriden with a macro) will spew out the statistics of your memory allocation? This doesn't take long to implement and can be very useful. Depending on how much you track from your macro you can even keep track of the order of allocations... I know you are using c++, but i'm sure there is a way to overload 'new' in C++ to achieve this. Alfred Perlstein - Admin, coder, and admirer of all things BSD. -- There are operating systems, and then there's FreeBSD. -- http://www.freebsd.org/ 4.0-current