// ******************************************************************************** // // **Creator: Dazzle Licence: Diku Merc Rom Terms ** // // **Difficulty: 5 Snippet: Mud Backtrace ** // // ******************************************************************************** // // ** Contact Information ** // // **Yahoo: ldevil.geo Msn: ldevil@hotmail.com ** // // **Aim: pocketweasle Email: sandstorm@arthmoor.com ** // // **Webpage: http://sandstorm.arthmoor.com ** // // ******************************************************************************** // // **Terms of Usage: ** // // **Follow the Diku, Merc, Rom Licences, also, if you have a snippet helpfile ** // // **Put my name in there, if not, leave my name in the source. ** // // **Also, this code is given AS-IS, straight from my mud, so there will be some ** // // **Effort required to make this work in your mud. ** // // **Install at your own risk, if you have any comments or questions on this ** // // **Visit the website mentioned above, and enter the forum, post and bugs or ** // // **suggestions there. ** // // ******************************************************************************** // Set this up in your mud-base, i put it in DB.c, and here is what it does. You can set this up to grab a backtrace from your mud, so if you are using my crash signal catcher, you'd simply put log_string(MudBackTrace()); at the top of it, and it would grab all of the backtrace information, now, there are 2 types of backtracing available. in your Makefile, with the rest of your -DWHATEVER style of flags, if you want to put hardgdbing on, put -DHARDGDB HardGDB will stall your process while it backtraces the system, this shouldn't smash the stack. when it is done, your mud will resume as usual. If you do not wish to have hardgdb on, you will get a simple internal backtrace done by the system, it will not lockup your mud for any duration of time, however, the function-names and information on the backtrace will be garbled, but you will get enough information to know roughly what information may have triggered your backtrace. On a side note, I did not code either of these functions, they were designed by 2 seperate smaug releases, the bottom one is by Samson, the top one is by someone else I do not have their name or email address, all i know is that it was originaly designed for smaug. However, I did enhance them where I could. #include <execinfo.h> // *Required for backtrace* // #ifdef HARDGDB // * If you don't have this, you do now * // 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); } char *MudBackTrace( void ) { static char buf[5000]; char arg[SBUF]; FILE *fp; buf[0] = '\0' // *change the rom to whatever your name is, and ensure that the directory is correct* // snprintf( arg, SBUF, "gdb -se ../src/rom -c %d -q -x ~/Rom24/src/gdb.dat", ( int )getpid( ) ); fp = popen( arg, "r" ); fgetf( buf, 5000, fp ); pclose( fp ); return buf; } #else char *MudBackTrace( void ) { static char mybugbuf[LBUF]; void *array[30]; size_t size, i; char **bstrings; size = backtrace( array, 30 ); bstrings = backtrace_symbols( array, size ); sprintf( mybugbuf, "Obtained %d stack frames.\n", size ); for( i = 0; i < size; i++ ) { mudstrlcat( mybugbuf, bstrings[i], LBUF ); mudstrlcat( mybugbuf, "\n", LBUF ); } // free(bstrings); return ( mybugbuf ); } #endif The following is named gdb.dat, this is a required file for debugging. echo \nFinal Point:\n\n frame 7 echo \nSteps leading up to this point:\n\n bt quit y Copy that to the gdb.dat file, and put it in your src directory.