In order to use gdb, you must add -g to your compile line. To get into gdb, type: On a mac: lldb a.out On a windows or unix box: gdb a.out Handy commands in gdb: r - run If you would have run the program this way: ./a.out filename.txt 10 Then in gdb, you do this: run filename.txt 10 For segmentation faults, you compile for gdb, run, and it will automatically stop at the rigth place. list - list the program This command prints out several lines from the program. If you know what around what line you want to see, you can put in the line number line 56 Also, if you want it to print out a particular function you can do that, too line main break - set a breakpoint If you know that you are getting an infinite loop somewhere or a seg fault somewhere, it might be a good idea to stop the program before the problem happens so that you can step along and see why it goes wrong. break 56 sets a breakpoint at line 56. That means that once the program reaches that line, it will stop and allow you to control it. up - takes you out of the current function call If you are tracking down a segmentation fault or infinite loop, some time may be spent in some OS call or something (like printf, malloc, new, strcmp, etc). When you stop, it may be in that function, which is not all that help for you, because the line number is in that function, not your code. So, you can keep typing "up" until you recognize the code. That will tell you where, in your code, it stopped. p - print You can print a variable or the return value of a function So, let's say you stop somewhere, and you don't know why something is wrong. You have a variable named i. So, to print i, p i n - next This allows you to advance the program by 1 line. If there is a function call, it will execute the entire function call. s - step This allows you to advance the program by 1 line. If there is a function call, it will step into the function call and advance to the first line of the function call. c - continue If you have stopped at a breakpoint, inspected things, done next and step, and now you want to have it execute at normal speed again, you use continue. quit - quit gdb