Breakpoints and Usage

You probably know you can type `break function_name` (this places a break at the START of the function). Not so useful for concurrency when you might be switching in and out of functions all the time. More useful is `break filename.c:XX`, where XX is line number.

(gdb) break producerconsumer.c:28
Breakpoint 5 at 0x80002bf8: file ../../asst1/producerconsumer.c, line 28.
(gdb) break producerconsumer.c:56
Breakpoint 6 at 0x80002dfc: file ../../asst1/producerconsumer.c, line 56.

Also check out backtrace (bt) and list (l)

You probably haven't missed step (s), next (n)

Commands Summary

  • `info gdb` //Manual
  • `info locals` //Vars in local scope
  • `info variables` //Vars declared outside current scope
  • `info functions` //Names and datatypes of all defined functions
  • `info b` //List all breakpoints
  • `break funcName` //Set breakpoint at function funcName (short: b funcName)
  • `break file::line` //Set breakpoint at line in file
  • `layout next` //Cycle through the layouts of gdb
  • `p var` //Print the value of variable var
  • `p var = value` //Force set value to a var
  • `run` //Start the program
  • `start` //Synonymous to (b main && run). Puts temporary b at main
  • `next` //Execute the current line in source (short: n)
  • `step` //Step into function call at current line (short: s)
  • `finish` //Finish the execution of current function (short: fin)
  • `continue` //Resume execution (After a breakpoint) (short: c)
  • `refresh` //Repaint the interface (To fix corrupted interface)
  • `shell cmd` //Run shell command cmd from gdb prompt
  • `python gdb.execute(cmd)` //Run a gdb command cmd from python prompt
  • `set print pretty on` /Enable pretty printing (Put in ~.gdbinit)
  • `$ gdb -c core.num` //Examine the dumped core file from a SIGSEGV(shell command)
  • `bt` //Print backtrace
  • `break _exit` //Breakpoint at exit of program
  • `whatis expr` //Print datatype of expr
  • `ptype expr` //Detailed print of datatype of expr
  • `watch var` //Stop when var is modified
  • `watch -l foo` //Watch foo loaction
  • `rwatch foo` //Stop when foo is read
  • `watch foo if foo>10` //Watch foo conditionally
  • `delete` //Delete all breakpoints
  • `delete breakpoint_no` //Delete breakpoint breakpoint_no
  • `command breakpoint_no` //Run user listed commands when breakpoint is hit (End list of commands with 'end')
  • `file executable` //Load the executable for debugging from inside gdb
  • `quit` //Quit (short: q)