Debugging Technique

Debugging a program that contains debugging information is the main goal of Turbo Debugger. Although this debugger disassembles the program and it is possible to view the disassembled code in the CPU window, such disassemblers as W32Dasm and IDA Pro are considerably more powerful in this respect than Turbo Debugger. The Ice debugger, which works in ring 0, also is more convenient for analyzing executable modules. Turbo Debugger takes its place among various debugging tools because it debugs at the source code level. In this section, I will cover several aspects of debugging techniques.

Generally, the debugging process can be divided into four stages:

  1. Error detectionErrors in programs are detected in the course of program testing and practical use.

  2. Error localizationMost frequently, this stage is the most difficult and labor- intensive . This is the stage, in which debuggers are useful. Professional programmers know that it is sometimes difficult to locate errors in sophisticated algorithms by simply analyzing the source code. Of course, it is possible to output intermediate results; however, for a large program, you might need too many output operations. A good debugger is indispensable in such cases because it allows the variable values to be traced at every step.

  3. Determination of the error causeApart from algorithmic errors, consider the most typical Assembly errors:

    • Error in the order of operands. For example: MOV EAX, EBX instead of MOV EBX, EAX .

    • Stack overflow when using recursive algorithms or a too-deep nesting level of procedure calls.

    • Corruption of the contents of some registers when calling procedures.

    • A stack that is not cleared when exiting a procedure.

    • Incorrect use of conditional jumps , for example, JA instead of JNA .

    • A programmer's error in specifying the last variable values when organizing loops .

    • Incorrect setting of the direction flag.

    • Errors related to incorrectly determining the boundaries of variables and arrays. Such errors often cause the corruption of other variables .

    • Incorrect type casting of operands. For example, the programmer might load MOV AL, BL , then use EAX and forget to reset to zero the most significant bytes of the EAX register.

  4. Error correctionIf the detected error is simple and obvious, it won't be difficult to correct it. By the way, you have probably already guessed that Turbo Debugger doesn't allow you to correct executable modules. However, situations are possible, in which a specific program section (or procedure) produces an erroneous value but you are short of time to properly locate the error because the program section under consideration is too complicated. Sometimes, the incorrect value of the output information occurs only if input parameters take a rare combination of values. In this case, an easy technique can be applied: insert several lines of code that check output information and correct it if needed between the detected program section and the remaining part of the program. This technique is useful when debugging someone else's large program if it is impossible to understand the logic of the algorithm ( especially an erroneous one).



The Assembly Programming Master Book
The Assembly Programming Master Book
ISBN: 8170088178
EAN: 2147483647
Year: 2004
Pages: 140
Authors: Vlad Pirogov

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