Index: [thread] [date] [subject] [author]
  From: Erik Thiele <erikyyy@studbox.uni-stuttgart.de>
  To  : ggi-develop@eskimo.com
  Date: Thu, 15 Jul 1999 07:32:57 +0200

Re: a better backtrace() implementation

On Thu, Jul 15, 1999 at 01:13:55AM +0200, Julian v. Bock wrote:
> 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 );
better do
if (lsize <0) exit (1);
because lsize cannot ever get 100 according to the manpage.

> 	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
> 
--
EMAIL: erikyyy@studbox.uni-stuttgart.de                  \\\\
       thieleek@tick.informatik.uni-stuttgart.de         o `QQ'_
IRC:   erikyyy                                            /   __8
WWW:   http://wwwcip.rus.uni-stuttgart.de/~inf24628/      '  `
       http://tick.informatik.uni-stuttgart.de/~thieleek/

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