This is interesting last night I wrote a list for myself and now you've asked this question
So it's destined that it has to be shared with you Here's a list of useful commands I think you will probably need to use:
(Don't forget to compile in a way that is proper for GDB (compilation should include symbols GDB needs), it could be done with simply the -g flag, e.g gcc -g prog.c -o prog)
Code:
gdb ./prog (notice executable file is used)
break main (or b main) (add a break point to the main function)
run (run the program)
next (or n) (run the next line)
<enter> (repeats last command, whatever it's been)
list (or l) (see where you are in the source code)
print <var_name> (or p <var_name>)
break prog.c:<line_number> (notice source file is used. e.g.: b prog.c:142)
continue (run until next breakpoint)
until <line_number>
step ("next" runs "lines" so skips going into function calls, but that's not always our intended behavior, using "step" you can step inside your function calls)
print *<array_name>@<array_length> (e.g.: p *myArr@10)
r (re-run the debugging from beginning)
quit (or q)
kill (kill the program being debugged without quitting gdb)
make (running make from inside gdb, IT'S POSSIBLE!)
print x = 1 (adds this to the source code of your program!! So if you "make" it'll be changed as you need without leaving the GDB!)
info locals (very helpful command shows information of all variables in the current local scope)
disable (remove debugging symbols from the executable, usually done when you're finished debugging and everything's fine)
Hope that helps.