9.8 Generate a variable snapshot


9.8 Generate a variable snapshot

9.8.1 Basic tactic

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

9.8.2 Purpose

Determine the values of a set of variables.

9.8.3 Questions answered

  • Were any of these variables modified since the last time the dump was made?

  • Do all of these variables have reasonable values?

9.8.4 Potential problems

  • You can generate a lot of data if the statement is executed frequently.

  • If the problem is caused by stack or heap corruption, running under an interpreter or high-level debugger may cause the symptom to change or disappear. This happens because the values on the stack and heap will be different.

9.8.5 Refined tactics

Dump only selected elements of arrays, such as the first and last element of each row or column, or the diagonal elements.

9.8.6 Related tactics

  • Call a function that dumps a specific number of words starting at a base address. Call it with the address of the last local variable declared in the function. Print each word in several formats (character, numeric).

  • For languages that keep most of their data in global variables, dump the entire global area.

9.8.7 Choosing tactics

Use the basic tactic when one of the following conditions is true:

  • No high-level debugger is available.

  • It isn’t feasible to run the application interactively.

9.8.8 Language specifics

  • C++: Dump the data members of the object currently referenced by this, and recursively dump all data members of objects pointed to or referenced by that object.

  • Java: Dump the data members of the object currently referenced by this, and recursively dump all data members of objects referenced by that object. Use reflection to implement this facility.

  • C: There is no way to get the names or addresses of all global variables without explicitly listing them.

  • Fortran: Dump the contents of blank COMMON, or of all COMMON blocks.




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