Re: Function which prints stack trace of the program
On Nov 9, 11:19 pm, Brendon Costa <bren...@christian.net> wrote:
Getting a stack trace is not simple cross platform. I have written a
class that will get it for, Windows, Linux and Other UNIX'es (Compiled
With GCC)
If you google the information i list below you might find examples.
Otherwise i can post the code for a class I created that does it all
on different platforms. I couldn't find James' source when i looked
briefly.
It's in the Port sub-system, component StackTrace. If the site
is up (my provider is somewhat flakey), it should be accessible
from http://kanze.james.neuf.fr/code-en.html. If you just want
to look at the code, it's in
http://kanze.james.neuf.fr/code/Util/Port/StackTrace/index.html;
you'll have to go into the sub-directories, however, to find the
specific files. The documentation's in
http://kanze.james.neuf.fr/doc/en/Port/html/index.html.
Linux is easiest:
glibc has a function: backtrace() which returns a list of addresses
for the backtrace.
I don't use it, mainly because I had the basics of what was
necessary for PC before I ported to Linux. G++, in general, has
a couple of functions available as extensions which would be
useable.
Note that one of the main uses I make of it is to save the
walkback when allocating memory; this means that the code has to
be reasonably fast (no disk reads, for example), and the format
of the saved information has to be relatively small (I only save
the actual return address).
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34