GCC

GDB

If you successfully compiled a program, and it crashes or it is simply not working correctly, you need to debug it.

Debugging is the process of stepping through each statement of the source code while the program is running. Once you have stepped over a statement that resulted in an unexpected behavior you have located the origin of the error. Then you are ready to analyze the code in question, find out about the cause of the error, and finally fix the problem.

A popular debugger is the gdb. Assuming that you compiled the program with the -g option, you can load the program into the gdb. Then the gdb supports several commands to control and analyze the program behavior:

  • run: start the program
  • start: start the program until it reaches the main function
  • break <function>: stop execution at a particular function
  • cont: continue execution after break point
  • next: proceed with next statement (step over functions)
  • step: proceed with next instruction (step into functions)
  • where: show actual position of program execution and list call stack
  • print <expression>: print variables and expressions
  • watch <expression>: set a continuous watchpoint for an expression
  • quit: exit the debugger


ar and nm | | Makefiles

Options: