[lug] good assert library

D. Stimits stimits at attbi.com
Sun Sep 15 21:46:56 MDT 2002


Chan Kar Heng wrote:
> hi!
> 
> would anyone know of a good assert library??
> 
> i'm particularly looking for one that dumps the function call stack...
> ansi assert merely reports the function that broke down.. but not
> the caller.. :(
> 
> thanks in advance
> 
> rgds,
> 
> kh
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
> 

I use this in some of my testing code (don't forget the -rdynamic):

#include <execinfo.h>
#include <iostream>

#ifdef _EXECINFO_H
void show_stackframe()
{
	void* trace[ 64 ];
	char** messages = NULL;
	int trace_size = 0;
	
	cerr << "Begin Stack Frame Dump" << endl;
	cerr << "(if useful symbols are not found, try recompiling "
		<< "with -rdynamic during link, and -g without -O#)"
		<< endl;
	trace_size = backtrace( trace, 64 );
	messages = backtrace_symbols( trace, trace_size );
	for( int i = 0; i < trace_size; ++i ) {
		cerr << "Traced: " << messages[i] << endl;
	}
	cerr << "End Stack Frame Dump" << endl;
}
#endif 
// _EXECINFO_H



D. Stimits, stimits AT attbi.com




More information about the LUG mailing list