9.19 Change storage class


9.19 Change storage class

9.19.1 Basic tactic

Change local variable references to be global variables.

9.19.2 Purpose

Determine whether stack corruption is causing the problem.

9.19.3 Questions answered

  • Which stack variables were having their values overwritten?

  • Was the stack frame itself being overwritten?

9.19.4 Potential problems

This approach won’t work with algorithms that really need a stack.

9.19.5 Refined tactics

Put preprocessor conditional compile directives around all stack variable declarations so you can switch between locals and globals.

9.19.6 Related tactics

  • Change local variable references to be heap variables pointed to by global variables.

  • Change heap variables to be located on the stack with the use of alloca (nonportable).

  • Put arrays of pad values between each true variable on the stack.

9.19.7 Choosing tactics

Use the basic or refined tactic when both of the following are true:

  • Symptoms change radically between runs.

  • Local variables are being overwritten, but their address isn’t being taken.

9.19.8 Language specifics

  • C++: This tactic can be useful for C++.

  • Java: Java guarantees heap integrity, so this tactic is unnecessary.

  • C: This tactic can be useful for C.

  • Fortran: This tactic is awkward to implement in Fortran.




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