/* Returns a pointer to the text output of a forked GDB process. showing what steps occurred just prior to the calling of this. You can place a call to backtrace to record why a problem is occurring by seeing what happened before it. Example usages: Stock: bug( "%s", backtrace()); or append_to_file( SYSTEM_DIR "backtrace.log", backtrace()); Global Board System: make_note("Bugs", sysdata.mud_name, "imms", "Backtrace Report", 30, FALSE, backtrace() ); Use calls to backtrace sparingly on main ports. They WILL cause lag while gdb loads and runs, and pause the entire game while running the trace. */ char *backtrace() { static char buf[5000]; char arg[MAX_INPUT_LENGTH]; FILE *fp; sprintf( arg, "gdb -se ../src/smaug -c %d -q -x ~/gdb.dat", (int) getpid() ); fp = popen( arg, "r" ); fgetf( buf, 5000, fp ); pclose( fp ); return buf; } char *fgetf( char *s, int n, register FILE *iop ) { register int c; register char *cs; c = '\0'; cs = s; while( --n > 0 && (c = getc(iop)) != EOF) if ((*cs++ = c) == '\0') break; *cs = '\0'; return((c == EOF && cs == s) ? NULL : s); } /* Create a file named gdb.dat, place it in your root directory ( you can type echo ~ to find your root if you don't know) with the rest of this comment as the contents: echo \nFinal Point:\n\n frame 7 echo \nSteps leading up to this point:\n\n bt quit y */