f78
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.
-
Using the Open
menu item in the File drop-down menu from
the Source Window .
-
Using the following initialization
procedure, entering commands at the (gdb) prompt in the Console
window.
Open the Console
window, either from the View menu, or
with the Console button (see Console
button).
With the Console
window active, determine if the target file is in the same directory as
GDBTk. If not, change to the target directory, using the cd command.
In
our example procedures, the syntax uses the forward slash as the path delimiter
on all platforms. Windows, though, requires using two forward slashes after
the drive designation.
If the source
files are not in the same directory as the executable file, use the GDB
dir command to add a path to them, using the same syntax as in
Step 2 of initializing a target file. This was not needed in our example.
Use the command, file
example, to specify the target executable file.
See
Console
window with initial commands for the results of these procedures.
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.
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.
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.
Note:
A second single click on
a breakpont will remove the breakpoint.
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.
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