f78  
Contents|Previous

Procedures



 The following documentation contains an example debugging session with step by step procedures for using GDBTk.

Initializing a target executable file

Initializing a target executable file with GDBTk means opening a specific executable file.
There are two ways to open an executable file in GDBTk.
See Console window with initial commands for the results of these procedures.

Console window with initial commands

    Figure 70: Console window with initial commands

Selecting a source file

To select a source file and specify a function within that file, use the following procedure. 
1.
Select the foo.c source file in the file drop-down combo box, at the bottom of the Source Window.
Source file and function selection represents the lower left corner of the Source Window, showing the Source Window's File menu drop-down combo box on the left and the function drop-down combo box on the right of the window. See also Below the horizontal scroll bar.
Figure 71: Source file and function selection
2.
Select the function, foo, in the function drop-down combo box, at the bottom of the Source Window.
3.
Now the foo.c source file is displayed in the Source Window with a colored bar, indicating the current position, as shown in Source Window with foo.c source file, on the first executable line (line 6) in the foo function. Once again, the colored bar is violet, indicating graphically that the program is not running.
Figure 72: Source Window with foo.c source file

Setting breakpoints and viewing local variables

A breakpoint can be set at any executable line. Executable lines are marked by a minus sign in the left margin of the Source Window. When the cursor is in the left column and it is over an executable line, it changes into a circle. When the cursor is in this state, a breakpoint can be set.
The following exercise steps you through setting four breakpoints in a function, as well as running the program and viewing the changing values in the local variables.
1.
With the Source Window active, having opened the foo.c source file, place the cursor over the minus sign on line 6.
2.
When the minus sign changes into a circle, click the left mouse button; this sets the breakpoint, signified as a red square.
3.
Repeat the process to set breakpoints at lines 8, 9 and 10. See Results of setting breakpoints at lines 6, 7, 8, and 9.
4.
Open the Breakpoints window, by clicking the Breakpoints button on the tool bar (see Breakpoints button and Breakpoints window).
5.
Click the check box for line 6. The red checkmark disappears and the red square in the Source Window changes to black. This color change indicates that the breakpoint has been disabled. Re-enable the breakpoint at line 6 by clicking the check box.
6.
Click the Run button on the tool bar to start the executable (see Run button). The program runs until it hits the first breakpoint on line 6. The color bar on line 6 is green, indicating that the program is running (see Results of setting breakpoints at lines 6, 7, 8, and 9 and Breakpoints window).
Figure 73: Results of setting breakpoints at lines 6, 7, 8, and 9 
Figure 74: Breakpoints window
7.
Open the Local Variables window, by clicking the Local Variables button in the tool bar (see Local Variables button and See Local Variables window). The window displays the initial values of the variables.
8.
Click the Continue button in the tool bar (see Continue button), to move to the next breakpoint. The variables that have changed value turn blue in the Local Variables window (see Local Variables window after setting breakpoints).
Figure 75: Local Variables window after setting breakpoints
9.
Click the Continue button two more times, to step through the next two breakpoints and notice the changing values of the local variables.
0