• Keine Ergebnisse gefunden

Examining program source files

Im Dokument . Turbo Debugger " (Seite 124-128)

Figure 8.1 The Module window

The Module window is the most frequently used window in Turbo

Debugger. You can use this window to examine the executable source code of any module that was compiled and linked with debug information.

When you open the Module window, the title bar displays the name of the currently loaded module, the name of the current source file, and the line number that the cursor is on. .

In the Module window, executable lines of code are marked with a bullet (.) in the left column of the window. You can set breakpoints or step to any of these lines of code. An arrow (~) in the first column of the wiildow indicates the location of the instruction pointer. This always points to the next statement to be executed.

Chapter 8, Examining disk files 115

Loading source files

The Module windows SpeedMenu

As you step through your program, the Module window automatically displays the source code relating to the current location of the instruction pointer. By navigating to different source-code locations, you can set breakpoints and watches, and inspect the values of different program variables.

If the abbreviation opt appears after the file name in the title bar, the program has been optimized by the c01!1piler. If you compiled your

program with optimizations, you might have trouble finding variables that have been optimized away. In addition, compiler optimizations can place variables in registers, meaning that they cannot be linked to memory addresses. Because of this, it is recommended that you do not optimize your program while you are in the debugging stage.

If the word modified appears after the file name in the title bar, the file has been changed since it was last compiled. In this case, the line numbers in the source file might not correspond to the line numbers in the executable's debug information. If these line numbers don't match, the debugger will not be able to show the correct program locations when you step through your code. To correct this problem, recompile your program with symbol debug information.

When you load a program into Turbo Debugger, the file containing the entry point to the program automatically loads into the Module view.

If you want to change the source file that's currently displayed in the Module window, choose one of the following two commands from the Module window's SpeedMenu:

• The File command lets you change to another source file contained in the current program module .

• The Module command lets you change the currently loaded program

module. .

The Module window's SpeedMenu provides commands that let you navigate through the displayed file, inspect and watch data items, and load new source code files. The SpeedMenu in TD32 also has the Thread and Edit commands:

Inspect

The Inspect command opens an Inspector window that shows the details of the program variable at the current cursor position. If the cursor isn't on a variable, you're prompted to enter an expression to inspect.

You can also use the arrow keys or your mouse to quickly select an expression or string of text in the Module window. To use the keyboard, press Ins, and use the left or right arrow keys to mark your selection. To use the mouse, click and drag the mouse pointer over the section of text you want to select. After selecting an expression, press Ctrl+1 to activate the Inspector window.

Watch adds the variable at the current cursor position to the Watches window. Putting a variable in the Watches window lets you monitor the value of that variable as your program executes.

If you have selected an expression in the Module window, press Ctrl+W to add the expression to the Watches window.

The Thread command, found only in TD32, opens the Pick a Thread dialog box, from which you can pick a specific program thread to monitor. For more information on threads, see page 148.

The Module command lets you load a different module into the debugger by picking the module you want from the Load Module Source or DLL Symbols dialog box.

The Load Module Source or DLL Symbols dialog box is fully described on page 144.

File lets you examine another source file that's compiled into the module you're currently viewing. This command opens the Pick a Source File dialog box, which lists the source files that contain executable code. When

Chapter 8, Examining disk files 117

Previous

Line

Search

Next

Origin

you choose the source file you want to examine, that file replaces the current file in the Module window.

To view different files simultaneously, use the View I Another I Module command to open multiple Module windows.

Files that are included in your program with the #include directive are also program source files. If an include file contains executable lines of code, you can use the File command to load the file into the Module window.

However, if the include file doesn't contain executable code (such as many C header files), you must use the File window to examine the file.

The Previous command returns you to the source location you were viewing before you changed your position. For example, if you use the Goto command to view the source code at a different address, the Previous commal)d returns you to your original position.

Line positions you at a new line number in the file. The Enter New Line Number dialog box prompts you for a decimal line number. If you enter a line number after the last line in the file, you will be positioned at the end of the file.

The Search command searches for a character string, starting at the current cursor position. When you choose this command, the Enter Search String dialog box prompts you for a search string. If the cursor is positioned over something that looks like a variable name, the dialog box opens initialized to that name.

If you mark a block in the file using Ins and the arrow keys, that block will be used to initialize the Search String dialog box.

You can also search using simple wildcards: a question mark (?) indicates a match on any single character and an asterisk (*) matches zero or more characters.

The search does not wrap around from the end of the file to the beginning.

To search the entire file, first go to the beginning of the file by pressing Ctrl+PgUp.

Next searches for the next instance of the character string you specified with the Search command.

The Origin command positions the cursor at the module and line number

Goto

Edit

Exceptions

viewing is not the module that contains the instruction pointer, the Module window will change to show that module.

This command is useful when you have been examining various places in your code, and you want to return to the location of the instruction pointer.

Goto opens the Enter Address to Position To dialog box, which enables you to view any address location within your program. Enter the address you want to examine as either a procedure name or a hexadecimal address. If the address you enter doesn't have a corresponding source line, the CPU window opens. See "Types of expressions" on page 106 for a description of entering addresses.

. . You can also invoke this command by typing into the Module window.

This brings up the Enter Address to Position To dialog box, exactly as if you had chosen the Goto command.

When you're debugging a Windows 32s program with TD32, you can invoke the editor of your choice using the Edit command. This comp1.and is useful if you've found the program bug, and you want to fix the source code before leaving Turbo Debugger.

Before you can use this command, you must configure TD32 so it knows where to find your editor:

1. Load the TDINST32.EXE installation program.

2. Choose Options I Directories to access the Directories dialog box.

3. Enter the absolute path and name of your editor into the Editor Program Name input field.

4. Save the settings.

If you haye implemented C or C++ exception handling in your program, . the Exception command becomes active. For complete details on this

command, see page 163.

Im Dokument . Turbo Debugger " (Seite 124-128)