Chapter 9: Debugging Tactics


Experiments are like cross-questioning a witness who will tell the truth but not the whole truth.

—Alan Gregg

9.1 Preview

This chapter describes in detail basic and refined debugging tactics that every programmer should be able to use, given that they’re supported in his or her development environment. It develops a standard methodology for defining tactics according to a list of questions. Each tactic is described using this methodology and is concluded by an example of finding an actual bug using it.

The following debugging tactics are described as follows:

  • Read the source code looking for problems.

  • Write and execute a unit test for a procedure.

  • Insert a statement in the source to print the value of a variable.

  • Insert a statement in the source to print a message when a code block is executed, listing the procedure name and some locality identifier.

  • Insert statements in the source to print the values of arguments on entry to a procedure.

  • Run the application under an interpreter or high-level debugger and generate a trace of all statements executed.

  • Run the application under an interpreter or high-level debugger and generate a snapshot of all variable values each time a statement in a specified procedure is executed.

  • Generate a memory map when the application is compiled and a memory dump when it completes execution.

  • Generate a memory map when the application is compiled and a memory dump when it completes execution.

  • Insert assertions into the program source that make the assumptions of the code explicit.

  • Insert calls to procedures that check the validity of user data structures.

  • Insert calls to procedures that display user data structures.

  • Use compiler options to generate runtime subscript checking.

  • Use compiler options to generate runtime checking of stack integrity.

  • Use a memory allocator that performs runtime checking of heap integrity.

  • Use compiler options to initialize statically with unusual or invalid values those global variables that aren’t explicitly initialized.

  • Use compiler options to initialize dynamically with unusual or invalid values those local (stack) variables that aren’t explicitly initialized.

  • Change local variable references to be global variables.

  • Compile your source code with a compiler from a different vendor.

  • Compile your source code to assembly code.

  • Compile and run the application on a computer system with a different operating system or hardware architecture.




Debugging by Thinking. A Multidisciplinary Approach
Debugging by Thinking: A Multidisciplinary Approach (HP Technologies)
ISBN: 1555583075
EAN: 2147483647
Year: 2002
Pages: 172

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net