"Scott A. Herod" wrote:
>
> Hello,
>
> Java's got a nice method for getting the stack trace at runtime.
> I use it often for debugging as an "assert" mechanism. Is there
> something similar that I can do with C++?
>
> Thanks,
>
> Scott
> _______________________________________________
> Web Page: http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
There is if you use -rdynamic and -g. Incidentally, this may cause
normal core dumps to provide less or different info. Here is a basic
sample of a stack frame print function, which is probably specific to
linux:
cerr <<"Begin Stack Frame Dump" <
cerr <<"(if useful symbols are not found, try recompiling "
<<"with -rdynamic during link, and -g without -O#)"
<
trace_size = backtrace( trace, 64 );
messages = backtrace_symbols( trace, trace_size );
for( int i = 0; i
cerr <<"Traced: " < <
}
cerr <<"End Stack Frame Dump" <
}
I've used this at times to debug asyncronous code and figure out what
had been called from where, I actually keep a commented out version in
my game code.