UMD Computer Science Department
Turbo Debugger for Windows

Introduction

This document serves as a tutorial and reference for using Turbo Debugger for Windows (TDW). It is divided in two parts: the first part is a tutorial that introduces you to the basic features of TDW and debugging techniques needed to debug a program; the second part is a reference to the different debugging commands available in TDW. The document assumes you have a basic knowledge of using Turbo C for Windows and programming in the C language.

Tutorial

In this tutorial you will learn to the following debugging concepts:

The tutorial uses a demo C program, called TDDEMO1.C to introduce you to TDW. As you read through this tutorial, you are advised to apply the techniques presented to the demo program. This will enable you to gain a better understanding of the debugger and the debugging process in general.

The Demo program (TDDEMO1)

The demo program, by itself, is not meant to be particularly useful; some of its code and data structures exist solely to show TDW's capabilities. The program implements a primitive calculator that performs the basic arithmetic operations of addition, subtraction, multiplication and division on integers. The program prompts the user for two integer numbers. It then performs the arithmetic operations on the numbers and prints out the result.

The C file for the demo program can be downloaded by clicking here and choosing the Save File... option:
TDDEMO1.C.

Setting Breakpoints

To control where your program stops running you will have to set breakpoints. The simplest way to set a breakpoint is with Debug-Toggle-Breakpoint or F5 key. Move the cursor to line 28, scanf("%d %d", &A, &B);, and press F5. Turbo debugger highlights the line, indicating there is a breakpoint set on it. Now select Debug-Run or press Ctrl-F9 to execute your program without interruption. The program stops at line 28. What has happened is, the debugger has executed the intervening statements, from printf("Enter two integer numbers, A & B: "); to scanf("%d %d",&A, &B); . Press F5 again to remove the breakpoint.

Running and stopping the program

To run the program, choose Debug-Step over or press F8. This allows execution one line at a time, until the first breakpoint, in the program . This brings up a window, titled "TDDEMO1.EXE". The window displays the line Enter two integer numbers, A & B. This window is the program input/output window, through which you interact with the program.

The scanf("%d %d",&A,&B) statement is now high-lighted. Pressing F8, brings the program input/output screen to the foreground, with the cursor blinking after the words Enter two integer numbers, A & B. That is because the scanf statement is waiting for you to enter two numbers. Type two integers and press ENTER. This will cause the next line to be highlighted. This process of executing one program statement at a time is called Single stepping.

Tracing in procedures and functions

When debugging a program, it sometimes becomes necessary to check the inner workings of a function to ensure its correctness. Select Debug-Trace Into or press F7 when the program has stopped at a statement containing the function call. TDW traces into the function, if it is accessible to the debugger and highlights the first statement in the function. Set a breakpoint at the line sum = Add(A, B); In our program, the execution will now stop at this statement when resumed. This statement contains a call to the function Add. Press F7 to trace into function Add. The first statement return A + B; in the function is now highlighted. Press F8 to resume execution. The function now returns control to the calling routine. The statement diff = Subtract(A,B); , following the statement sum = Add(A,B); is now highlighted.

Examining program variables

The Watches window can be opened by selecting the View-Options and it shows the value of variables you specify. For example, to watch the value of the variable sum, move the cursor to the variable name on line 30. Then choose Debug-Add watch or press Ctrl F5. The variable sum now appears in the Watches window along with its type and value. As you execute the program, Turbo debugger updates this value to reflect the variable's current value.

Examining simple C data objects

Once you have stopped your program, there are a number of ways of looking at data using the Inspect command. This very powerful facility lets you examine data structures in the same way that you visualize them when you write a program. The Debug-Inspect... command lets you examine any variable you specify. Suppose you want to look at the value of the variable prod Move the cursor below the variable and choose Debug-Inspect... An Inspector window pops up. The first line tells you the variable name and type of data stored in it; the second line shows its value and the address in memory.

Examining compound C data objects

A compound data object such as an array or structure, contains multiple components. The variable pairs is a compound object. It is an array of records. To examine its content, invoke the Inspector window as described above. The Inspector window shows the values of the 20 elements of pairs. Use the arrow keys to scroll through the 20 elements. The title of the window shows the name of the data you are inspecting. A new Inspector window appears, showing the contents of that element in the array. The Inspector window shows the contents of a record of type integerpair. If one of these were in turn a compound data object, you could issue an Inspect command and dig down further into the data structure.

Changing C data values

So far, you have learned how to look at data in the program. Here you will learn to change the value of data items. Use the arrow keys to go to line 33 in the source file. Place the cursor at the variable A and choose Debug-Evaluate/Modify. The window now shows the value of variable A. you can enter any C expression that evaluates to a number. Type A+10 and press ENTER. The new value evaluated can be seen in the middle Result pane. Now, in the bottom pane with title New Value, enter a new value and press ENTER. Variable A takes the new value.

Reference

This section is a reference to using the different commands in TDW. The commands are categorized into two groups namely, "Controlling program execution" and "Examining and modifying data," according to their functionality.

Controlling program execution

When you debug a program in TDW, you execute portions of it and check at stopping points to see if it is behaving correctly. TDW provides you with a number of ways to control your program's execution.
You can The Debug menu and the Speedup menu contain all the commands that are needed to control the execution of a program.

The Debug menu

The Debug menu has a number of options for executing different parts of your program. Since these options are used frequently, most are available on function keys. Following is the description of some of these options. The letters in the brackets stand for function keys with which the command can be invoked.

Run [Ctrl-F9] The Run menu Runs your program without stopping. Control returns to TDW when one of the following events occurs:

Trace Into [F7] Executes a single source line. If the current line contains a function call, then the debugger traces into the function if it is accessible to the TDW.

Step Over [F8] Executes a single source line, skipping over any function calls. TDW treats any function call in a line as part of the line. You do not end up at the start of one of the functions or procedures. Instead, you end up at the next line in the current routine or at the previous routine that called the current one.

Toggle BreakPoint [F5] When the cursor is on a source line, then a breakpoint is set at that line when this option is chosen. If it is already a breakpoint then the breakpoint is removed.

Find execution point Finds the point in the program where execution is to resume. This can be of use when debugging a large program.

Add breakpoint New breakpoints can be added during debugging and this option brings up a window. Options to set a conditional breakpoint under a specific condition are available in this window.

Pause program The program can be paused at any point in the debugging process with this option.

Terminate program [Ctrl-F2] If you are debugging a program that requires as much memory as possible to complie, then choose this option after the debugging session.

Add watch [Ctrl-F5] You could add a new watch variable during the debugging session. The display type of the variable, the radix etc. can be selected.

Evaluate/Modify Any expression can be evaluated except those that

Inspect... As previously explained variables and structures (both simple and complex) can be inspected during debugging.

Speedup Menu

This is a small menu that comes up when the right mouse button is clicked or when Alt-F10 is pressed.

Browse symbol You can choose to browse any variable or structure in your program. If the structure has more than one elements then you could further inspect any of them.

View

Message window Any messages that may appear during linking and running of the program shows up in this window.

Globals This window shows all the global variables and functions that have been defined in the program.

Watch This window shows all the variables and structures that are being watched in the debugging session. The values of the variables during the different stages of execution are shown.

Call Stack This window shows the contents of this program stack. The different function calls in the program can be seen as being the stack contents when the TDDEMO1.C program is exected.

Register This window displays the contents of the data, pointer, index, segment, and instruction pointer registers, as well as the settings of the status word or flags.

Event log This window displays the results of breakpoints, Windows messages, and output messages generated while using the debugger.