9.13 Display data structures


9.13 Display data structures

9.13.1 Basic tactic

  • Insert calls to procedures that display user data structures.

  • Print the name of an enumeration value, not the integer.

  • Print bit data in hexadecimal or binary form, not integer.

  • Print the names of all flags turned on in flag words, rather than just the value of the word.

  • Rather than print the values of pointers and references, do the following:

    • Place the pointer/pointee or reference/referent adjacently.

    • Draw relationships with arrows.

    • Use indentation to show hierarchy.

  • Print data in unions with the proper format, based on a variant record tag.

  • Suppress default or zero data as appropriate.

  • Provide self-identifying data.

  • Provide multiple views for the same data—implement both a sketch and a full detail view.

9.13.2 Purpose

  • Determine whether a data structure ever had an incorrect value.

  • Find the earliest point in the execution of the program when the data structure contained an incorrect value.

  • Find the first location in the program source where a data structure contained an incorrect value.

9.13.3 Questions answered

  • What are the contents of major data structures as they’re built and used?

9.13.4 Potential problems

  • If these procedures are called frequently or display very large structures, the display can use up a lot of file space.

  • If the problem is caused by stack or heap corruption, the presence of a call to a data-structure display procedure may cause the symptom to disappear. This happens because the display procedure will shift things on the stack and may allocate memory on the heap.

  • If the problem is caused by optimizations performed by the compiler, the presence of a call to the display procedure may cause the optimizer not to perform the offending optimization or to perform it differently.

9.13.5 Refined tactics

Test values in other data structures, and only print the values when exceptional conditions occur.

9.13.6 Related tactics

  • Use a high-level debugger or interpreter to do the following:

    • Set a breakpoint at a place where you know that the data structure is completely built.

    • Add a command list to the breakpoint that calls the data-structure display procedure and continues execution.

  • Use a high-level debugger or interpreter to do the following:

    • Set a watch point to a variable that will contain a pointer or reference to the data structure.

    • Add a command list to the watch point that calls the data-structure display procedure and continues execution.

9.13.7 Choosing tactics

Use either the basic or refined tactics when your data structures are complicated hierarchical structures.




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