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.
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, 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:
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.
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.
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.
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.
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.
Any expression can be evaluated except those that
Inspect... As previously explained variables and structures (both simple and complex) can be inspected during debugging.
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.
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.