ECES 338 Bill's Recitation Notes gdb notes, sample run narrative. Reminder from Recitation 1 notes: To get debug info, you must compile with the "-g" switch. Say that I've got a program HW1.out. I'd debug it as follows: "gdb HW1.out", then I'd set breakpoints in the program by two methods. First, I know that I want to see what happens when it calls the BadThing function, so I'd set a breakpoint there with the command "break BadThing". Now I also want to watch something that I put in half way through the main function, but I don't want to step through the whole thing because I've got a lot of loops before it. So, I use the "l" command to list out the code, I see that I've got a ways to go, so I do "l 100", and it lists the code around the area of line 100, I do "l" again and it picks up where it left off the last time, I eventually find that the code I want to watch is at line 214, so I set the breakpoint with "break 214". Now I'm ready to start, so I use the command "run". The program runs, it stops at line 214, I use "s" to step ahead past the call to function "Func1" and then use "n" to step into the call of "Func2" in the next line. I step through a few more times, and want to see the value of variable "Var1", so I use the command "print Var1". I suspect from this that there's a problem with a string I'm using, so I use "print CharPtr1", and it shows me the value. I suspect that I'm using a different string than the one in the main function which I'd meant to pass, so I use "print &CharPtr1" to get the address, and then "print &(main::OrigString1)" to get the address of the string in the main function. This wasn't the problem, so I want to check something in a structure I made, so I use "print MyStruct1" to see the values it's got. They look ok, but I want to check the value of the next structure, so I use "print *(MyStruct1.Next)", it looks ok, to check the one after that I use "print *(MyStruct1.Next->Next)". I've seen enough, and don't care until my next breakpoint, so I use the command "continue". Before I get to my next breakpoint, I get a message about program halting because it got the signal SIGSEGV, it's gotten a segmentation fault. So I use the command "where" to look at the call stack, I look for the line containing the main function, I see that it's there, but that it's currently in the function "ShadyFunction", I look at that line, and see that it's on line 423 of the source file, so I do "l 423", see where it is, use print calls to check some variables, then use "kill" to kill the process and "quit" to quit gdb. It was pointed out to me that I forgot to include above the possibly most useful command. "help". It gives you explanations for almost anything you'd want. Note that there are more than one command word to get the same functionality, I use "l" instead of "list" and I think that "c" works for "continue" and so on.