Chapter 1
The book covers only GDB, DDD and Eclipse as debugging tools and C and C++ as programming languages. The first chapter defines the Principle of Confirmation as `you as a programmer trying to confirm that what you believe is true, is actually true'. Debuggers can help with this quest for confirmation. Adding trace code (printf and friends) is discouraged: using a debugger is of course much easier and takes far less time. Debuggers also allow you to find the location of a bug and set watchpoints. The authors mention the following debugging principles:- Start small: run your program on easy, simple cases.
- Use a top-down approach: do not step into functions when not necessary.
- Use a debugging tool to determine the location of a segmentation fault.
- Determine the location of an infinite loop by using your debugger's interrupt and backtrace features.
- Use binary search.
- It starts up quickly.
- It can be used in cases where a GUI-debugger cannot be used (ssh remote sessions etc).
- It needs less screen space.
- Debugging a GUI with a GUI can be problematic.
The main debugger operations are:
- Stepping through code: breakpoints, single-stepping (next=next line, step=enter function), resume (continue), temporary breakpoints (tbreak, until, finish).
- Inspecting variables: in GDB this can be done with the print command, in DDD and Eclipse by hovering over a variable with the mouse.
- Setting watchpoints: pausing execution whenever a value of a specified variable changes. A GDB example is watch (i>10).
- Moving up and down the call stack: in GDB you use the frame, up, down and backtrace commands for this.
The chapter ends with an introductory debugging session. Interesting new commands that appear in this session are break and condition. Another interesting GDB-feature that is mentioned is its .gdbinit startup files. Somewhere in the chapter, the authors also mention cgdb as an alternative to GDB.
Stay tuned for Chapter 2!
No comments:
Post a Comment