Chapter 23: Introduction to Turbo Debugger

Overview

Borland Turbo Debugger is a powerful tool for debugging programs. It was developed in the time of MS-DOS and mainly is oriented toward Borland's implementations of most programming languages. The most important point is that this debugger allows program debugging both at the level of disassembled microprocessor commands and at the symbolic level (i.e., using the source code of the program being debugged ). In the latter case, for successful debugging it is necessary to include the debug information in the executable module at compile time.

For example, consider the program from Listing 17.1 in Chapter 17. This program displays the window containing the list of available disks and drives (both local and network, if there are any). To include the debug information in this module, add the /zi command-line option when assembling the program with TASM32. At build time, add the -v option to the TLINK32.EXE command-line options. In this case, all information required for symbolic debugging will be saved in the executable module.

It is important to bear in mind that more than the executable module and the debug information that it contains are required for symbolic debugging. In addition to this, you'll need the program's source code. The executable module stores the information that allows you to compare machine codes and the source code of the program. Fig. 23.1 shows the debugger window with the loaded debug information of the DRIV.ASM program (see Listing 17.1 in Chapter 17). The debugger allows you to execute the program step by step (more details on the modes of program execution are provided later in this chapter), simultaneously viewing the source code of the program being debugged and its disassembled listing. By walking through the program, you'll be able to view the results of executing each step.

Fig. 23.1 shows the three most frequently used debugger windows : the window containing the source code, the Central Processing Unit (CPU) window that displays the disassembled text, and even the current information about registers and flags, which is especially important when debugging GUI applications.

image from book
Figure 23.1: Turbo Debugger windows

Consider the debugger commands and its functional capabilities:

  • Starting the application being debuggedThis can be achieved by pressing <F9> or selecting the RUN command from the RUN menu. The program executes until it accomplishes its tasks , provided that the breakpoint on a specific line of code is not set in the CPU window. To set a breakpoint, press <F2>. By opening the Watch window (View Watches), you'll be able to specify the settings to track the changes of the variables , which are of interest to you. In this case, the breakpoints will also prove to be useful.

  • Executing the program up to the line where the cursor is positionedTo execute a command, press <F4> or select the appropriate menu item. The meaning of this command is that if you are interested in some program fragment, you can execute the program up to a specific line and review the result. This is similar to breakpoints but is more responsive . Furthermore, by pressing <Alt>+<F9>, you can execute the program up to a specific address.

  • Executing an individual commandThis is achieved by pressing <F7>. If the cursor is in the source code window, then the operator of a specific programming language will be executed. If the cursor is in the CPU window, then the appropriate CPU instruction will be executed.

  • Executing a command by walking through the procedureThis command is executed when the user presses <F8>. It differs from the previous command in that it doesn't enter the procedure but that all instructions in the procedure are executed automatically (within a single step).

  • Executing the procedureIf the cursor is positioned on the command for calling a procedure, then it is possible to execute that procedure by pressing <Alt>+<F8>.

  • Delaying the executionIt is also possible to instruct the debugger to execute the program with a certain delay after each command. This is achieved by choosing the Animate command from the Run menu.

When executing any of the previously listed commands, it is also possible to specify command-line options. This can be achieved by choosing the Run Arguments commands.

Now, consider the most important windows of this debugger, some of which I have already mentioned. To display a specific debugger window, choose an appropriate command from the View menu.

To display the program text, choose the Module command of the View menu. The program must be translated with the options ensuring that the debug information is saved in the executable module. Unfortunately, this is only true for the modules compiled using Borland products: C++, Delphi, and Turbo Assembler. Debugging information of other developers cannot be recognized by Turbo Debugger. Later in this chapter, I provide an example illustrating the debugging of a program written in Borland C++.

If Turbo Debugger doesn't recognize the debug information in the executable module, you will have to use the CPU window in the course of debugging. This window is divided into five parts (these are shown in Fig. 23.2):

image from book
Figure 23.2: Turbo Debugger CPU window
  • Microprocessor instructions

  • Data segment

  • Stack segment

  • Registers state

  • Main flags

Other windows of Turbo Debugger are as follows :

  • Window for watching variablesThis window is opened by selecting View Watches. By clicking the right mouse button, you can add to this window variables whose values you want to watch. When the program is executed step by step or with breakpoints, it is possible to control the values of variables at each step.

  • Stack windowThis window shows the state of the stack. The first called function will be at the bottom of the stack.

  • Breakpoints windowThis window contains information about all breakpoints set within the program. It is possible to add new breakpoints.

  • Log windowThis window stores information about all events that take place in the debugger.

  • Variables windowThis window displays variables available in the current context.

  • Files windowIn this window, you can view the binary file and correct it when necessary.

  • Memory display windowThis window allows you to view the memory contents line by line.

  • Coprocessor windowThis window displays the current coprocessor state.

  • Execution history windowThis window displays the history of program execution.

  • Hierarchy windowThis window displays the hierarchical tree of all objects and all class types used in the current module. An example window displaying the hierarchy of object classes is shown in Fig. 23.3.

    image from book
    Figure 23.3: Turbo Debugger window displaying class hierarchy

  • Threads windowThis window displays information about all threads running in the process being debugged.

  • Messages windowUsing this window, it is possible to trace all messages received by the current window. Fig. 23.4 provides an example of using the messages window. Here, it is possible to select the class of messages to be traced or to specify individual messages for tracing. In addition to tracing, it is possible to specify another reactioninterrupt execution (i.e., to set the breakpoint to the specific message).

    image from book
    Figure 23.4: Contents of the Messages window

  • Clipboard buffer windowUsing this window, it is possible to trace the contents of the clipboard when executing a program.



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