Use of dbx for C programs on Solaris machines. You should have compiled with "-g -xO0" for best results. This assumes you have the aliases defined in the sample .dbxrc in this package (i.e., download student.dbxrc and cp it to .dbxrc). However, each command is given in full before using the alias form. First we run through some scenarios. A help digest is given at the end. Start from unix with "dbx ". We'll assume "myprog" for the examples. Use "quit" to exit back to unix. CASE 1: Run the program and catch it if it bombs. ------------------------------------------------- Say you would otherwise type "myprog input1". Instead, dbx myprog run input1 Now say it bombs (this might be a failed assertion). You want to see how it got there. where Now look at some source lines around where it bombed. list -w Now look at the value of suspicious variables that might have bombed it. print x, y p line[i] Maybe go up to the caller of this function and do the same things. up lw list 120,170 p z Suppose z points to a struct. Print one field or the whole struct. p z->next p *z Suppose z is a linked list. Print the next three nodes. p *(z->next) p *(z->next->next) p *(z->next->next->next) Many times you have an idea what went wrong by this time and are ready to change the source code and recompile. q If not, go on to Case 2. CASE 2: Set some breakpoints so you can trace after a certain point. -------------------------------------------------------------------- dbx myprog # if you are not already in dbx stop in loadArray run input1 Say dbx stops at the beginning of loadArray (hasn't bombed first) list next n n p x n Use n to execute one line, not stopping inside a function call if the line has some. Use s to step INTO such function calls and trace them in detail. Later you can say "step up" to stop tracing this function and resume tracing at the higher level. s ;# dive into called function n n lw p a n p b step up ;# resume tracing in loadArray where this function returns n n p x You are in a loop at line 50 and you just want to check x each time around, without doing n for each statement. stop at 50 cont p x c p x c Suppose this call looks OK and you want to run until the next call of loadArray. "status" gives you a number for your "stop in loadArray" and for your "stop at 50" (probably 2 and 3 are the numbers). status del 3 c Later, try stopping in a different function, and dont stop at loadArray any more. stop in fixIt status del 2 c This covers the basics. You can do very sophisticated things in dbx, but it might be faster and easier to put in some printf's and recompile. CASE 3: Check for bad pointers, uninitialized variables, etc. -------------------------------------------------------------------- dbx myprog # if you are not already in dbx check -access run input1 Now dbx will stop the program if it detects one of the above memory-access errors, as well as a failed assertion, as well as seg-faults, bus errors, and the like. Bad pointers include array indexes wildly out of range. Even if your program makes it through an easy test file, "check -access" might expose a bug that will show up on a harder test file (like the one the TA makes up for grading, but you didn't think of). HERE IS A DIGEST OF DBX HELP MESSAGES ------------------------------------- The actual messages are often more verbose. Do "help stop", for example. stop at # Stop execution at the line stop in # Stop execution when is called status # Print trace's, when's, and stop's in effect delete ... # Remove trace's, when's, or stop's of given number(s). run # Begin executing the program with the current arguments (from an earlier "run ..."). run # Begin executing the program with new arguments Use ^C to stop executing the program. See also `help rerun', `help runargs' and `help prog'. next # Step one line (step OVER calls). next # Step lines (skip OVER calls) step # Single step one line (step INTO calls). step # Single step lines (step INTO calls) step up # ... and out of the current function cont # Continue execution. Use ^C to stop executing the program and resume tracing it. where # Print a procedure traceback where # Print the top frames in the traceback where -f # Start traceback from frame up # Move up the call stack one level up # Move up the call stack levels down # Move down the call stack one level down # Move down the call stack levels frame # Display the frame number of the current frame list # List N lines list # List line number list , # List lines from to list -w # List N lines around current line print , ... # Print the value of the expression(s) , ... print -p # Call `prettyprint' function print -f # Use as the format for integers, strings, or floating-point expressions (see `help format') EXAMPLES using the alias "p" for "print". x and X request hex. (dbx) p x/10.0 x/10 = 12.3 (dbx) p i i = 31 (dbx) p -fx i i = 1f (dbx) p -f x i ;# space after -f is OK. i = 1f (dbx) p -f %X 1234 4D2 (dbx) p struct1 struct1 = { x = 123 y = 61 } (dbx) p -fx struct1 ;# it even applies to members... struct1 = { x = 7b y = 3d } See `help format' for more formating options and examples.