Index: [thread] [date] [subject] [author]
  From: Julian v. Bock <JimProfit@t-online.de>
  To  : ggi-develop@eskimo.com
  Date: Thu, 15 Jul 1999 01:13:55 +0200

a better backtrace() implementation

Hi!

I have improved the backtrace() implementation. It doesn't need the program
name anymore. Maybe it's helpful.

void
backtrace()
{
	char	bt[200];
	char	command[100];
	char	prgname[100];
	char	elink[100];
	int	pid = getpid();
	
	sprintf( elink, "/proc/%i/exe", pid );
	int lsize = readlink( elink, prgname, 99 );
	if ( lsize >= 100 ) exit( 1 );
	prgname[lsize] = 0;
	sprintf( command, "echo backtrace | gdb %s %i 2>/dev/null", prgname, pid );
	
	FILE*	gdb = popen( command, "r" );
	
	do
	{
		fgets( bt, 200, gdb );
	} while ( strncmp( bt, "#9", 2 ) );
	
	do
	{
		printf( "%s", bt );
		fgets( bt, 200, gdb );
	} while ( !*bt == '#' );
		
	pclose( gdb );
}

happy coding...

Julian

Index: [thread] [date] [subject] [author]