Debugging with GDB (September 2007)

Chapter 13: Specifying a Debugging Target 109
13 Specifying a Debugging Target
A target is the execution environment occ upied by your program.
Often, GDB runs in the same host environment as your program; in that case, the
debugging target is specified as a side effect when you use the file or core commands. For
HP-UX specific information, see hundefinedi [HP-UX Targets], page hundefinedi. When
you need more flexibility—for example, running GDB on a physically separate host, or
controlling a standalone system over a se rial port or a realtime system over a TCP/IP
connection you can use the target command to specify one of the target types configured
for GDB (see Section 13.2 [Commands for managing targets], page 109).
13.1 Active targets
There are three classes of targets: processes, core files, and executable files. GDB can
work concurrently on up to three active targets, one in each class. This allows you to (for
example) start a process and inspect its activity without abandoning your work on a core
file.
For example, if you execute gdb a.out’, then the executable file a.out is the only active
target. If you designate a core file as well presumably from a prior run that crashed and
coredumped, then GDB has two active targets and uses them in tandem, looking first in
the corefile target, then in the executable file, to satisfy requests for mem ory addresses.
(Typically, these two classes of target are complementary, since core files contain only
the contents of the program read-write memory, variables, machine status etc. while the
executable files contain only the program text and initialized data.)
When you type run, your executable file becomes an active process target as well. When
a process target is active, all GDB commands requesting memory addresses refer to that
target; addresses in an active core file or executable file target are obscured w hile the process
target is active.
Use the core-file and exec-file commands to select a new core file or executable
target (see Section 12.1 [Commands to specify files], page 103). To specify as a target a
process that is already running, use the attach command (see Section 4.7 [Debugging an
already-running process], page 27).
13.2 Commands for managing targets
target type parameters
Connects the GDB host environment to a target machine or process. A target
is typically a protocol for talking to debugging facilities. You use the argument
type to specify the type or protocol of the target machine.
Further parameters are interpreted by the target protocol, but typically include
things like device names or host names to connect with, process numbers, and
baud rates.
The target command does not repeat if you press
h
RET
i
again after executing
the command.