Useful GCC & GDB Notes ====================== By: Alex Mohr This is a short list of useful GCC and GDB suggestions in order to assist you with debugging problems in your code. * Useful gcc Flags -Wall Enables all the warnings that you really do want. -Wstrict-prototypes Warn if a function is declared or defined without specifying the argument types. Circle is strictly prototyped already, so this should help keep your additions compatible and portable. -Wshadow Warns when a local variable shadows another local variable. This has been a great help in solving some logic errors. Example: int i; etcetc; if ( condition ) { int i; i = expression; } [do something with i assuming that i == expression] -Wcast-align From man gcc: Warn whenever a pointer is cast such that the required alignment of the target is increased. For example, warn if a char * is cast to an int * on machines where integers can only be accessed at two- or four-byte boundaries. This option should help those of you on 64 bit machines. * gdb Suggestions If after fixing _all_ the warnings that you receive when compiling, your program still doesn't work, then try using a debugger. With gcc/gdb, you need to compile with the -g flag, and no -O or -s flags. On some systems, you may need to use -ggdb to explicitly specify gdb extentions. On others, you also need to specify -static or -Bstatic so that libraries are directly linked into your code. Start the mud with something like: % gdb program [copyright notice appears] - If you have problems with a specific function and you know more or less where the problem is, try: gdb> break function_name - To start the program running, you can give it arguments right on the command line, such as: gdb> run 4000 [mud starts up] - It'll either keep running, crash with a segmentation fault, or break at the function if you specified one. Assuming one of the latter two, you can try: gdb> backtrace This command will show you the chain of functions that was called to get you where you are, along with all of the arguments given to them. If this is a break point, you can type: gdb> step Step will execute the next line. Just keep stepping along until you get near the problem area. Along the way, you may want to see what some of your variables look like. In that case, use the print command. gdb> print variable_name This, of course, shows you what the value of the specified variable is. I hope this is helpful to some of you at least. If you're serious about coding a mud, please read the man pages and documentation for your compiler and debugger. Really, they do help. Also, treat every warning as an error, except for the 'int i declared but not used' one. Warnings may not be true syntactic errors in some cases, but they indicate trouble spots that may very well have logic errors in them. Alex Mohr Kalgen of Zebesta dzur@u.washington.edu