Lecture notes Friday 4/9/99
Debugging
Avoiding bugs & debugging
in emacs: use TAB key, if indentation is "wrong" you have a bug in previous line
    try it out with bug3.c from the class directory
in C code: put printf statements in your code (diagnostic output)
while compiling: use "-Wall" option in compile command
Debugger gdb
copy bug1.c & bug2.c, e.g. "cp ~jmache/cs1/bug* ."
compile with -g, e.g. "gcc -g bug1.c -o bug1"
if you run this, it will crash (remember to "rm core")
start the debugger, e.g. "gdb bug1"
"run": run executable
"where": tells you where program stopped or crashed
"quit": leave the debugger
compile bug2.c
start the debugger, e.g. "gdb bug2"
"list": to look at C code
"break 6": set breakpoint at beginning of line 6
emergency break is "C-c"
"run": run executable
"watch i": stop and display i whenever its value changes
"cont": continue
"help": find out more about topics or commands, like:
"display i": show value of i whenever you stop
"delete"
copy bug5.c & rec.c from the class directory
compile with -g, e.g. "gcc -g bug5.c -o bug5"
if you run it, it will give wrong output and sentinel does not work
start the debugger, e.g. "gdb bug5"
"list 5", "list 15": to look at C code around line 5 or 15
"break 14": set breakpoint at beginning of line 14
"run": run executable until breakpoint
"display gallons": show value of gallons whenever you stop
"cont": continue until breakpoint
"next": execute one more line (skipping function calls)
"help": find out more about topics or commands
"quit": leave the debugger
Recursion
compile rec.c, e.g. "gcc -g rec.c -o rec"
for exemination purpose, we'll use the debugger, "gdb rec"
"list 1,25": to look at C code from line 1 to line 25
"break 23": set breakpoint at beginning of line 23
"run": run executable
"display local": show value of local whenever you stop
"info stack": show call stack
"cont": continue
if you do the last two repeatedly you can see how recursion works
"quit": leave the debugger