Go to the first, previous, next, last section, table of contents.
A target is the execution environment occupied by your program.
Often, 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. When you need more
flexibility--for example, running on a physically separate
host, or controlling a standalone system over a serial 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 (see section Commands for managing targets).
There are three classes of targets: processes, core files, and executable files. 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
has two active targets and uses them in tandem, looking
first in the corefile target, then in the executable file, to satisfy
requests for memory addresses. (Typically, these two classes of target
are complementary, since core files contain only a program's
read-write memory--variables and so on--plus machine status, while
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 commands
requesting memory addresses refer to that target; addresses in an
active core file or
executable file target are obscured while the process
target is active.
Use the core-file and exec-file commands to select a
new core file or executable target (see section Commands to specify files). To specify as a target a process that is already running, use
the attach command (see section Debugging an already-running process).
target type parameters
target command does not repeat if you press RET again
after executing the command.
help target
info target or info files
(see section Commands to specify files).
help target name
set gnutarget args
set gnutarget command. Unlike most target commands,
with gnutarget the target refers to a program, not a machine.
Warning: To specify a file format with set gnutarget,
you must know the actual BFD name.
See section Commands to specify files.
show gnutarget
show gnutarget command to display what file format
gnutarget is set to read. If you have not set gnutarget,
will determine the file format for each file automatically,
and show gnutarget displays `The current BDF target is "auto"'.
Here are some common targets (available, or not, depending on the GDB configuration):
target exec program
target core filename
target remote dev
target remote
now supports the load command. This is only useful if you have
some other way of getting the stub to the target system, and you can put
it somewhere in memory where it won't get clobbered by the download.
target sim
The following targets are all CPU-specific, and only available for specific configurations.
target abug dev
target adapt dev
target amd-eb dev speed PROG
target remote;
speed allows you to specify the linespeed; and PROG is the
name of the program to be debugged, as it appears to DOS on the PC.
@xref{EB29K Remote, ,The EBMON protocol for AMD29K}.
target array dev
target bug dev
target cpu32bug dev
target dbug dev
target ddb dev
target dink32 dev
target e7000 dev
target es1800 dev
target est dev
target hms dev
device and speed to control the serial
line and the communications speed used.
@xref{Hitachi Remote,, and Hitachi Microprocessors}.
target lsi dev
target m32r dev
target mips dev
target mon960 dev
target nindy devicename
target nrom dev
target op50n dev
target pmon dev
target ppcbug dev
target ppcbug1 dev
target r3900 dev
target rdi dev
target rdp dev
target rom68k dev
target rombug dev
target sds dev
target sparclite dev
target sh3 dev
target sh3e dev
target st2000 dev speed
target udi keyword
target vxworks machinename
target w89k dev
Many remote targets require you to download the executable's code once you've successfully established a connection.
load filename
load does not repeat if you press RET again after using it.
i386-stub.c
m68k-stub.c
sh-stub.c
sparc-stub.c
sparcl-stub.c
The debugging stub for your architecture supplies these three subroutines:
set_debug_traps
handle_exception to run when your
program stops. You must call this subroutine explicitly near the
beginning of your program.
handle_exception
handle_exception to
run when a trap is triggered.
handle_exception takes control when your program stops during
execution (for example, on a breakpoint), and mediates communications
with on the host machine. This is where the communications
protocol is implemented; handle_exception acts as the
representative on the target machine; it begins by sending summary
information on the state of your program, then continues to execute,
retrieving and transmitting any information needs, until you
execute a command that makes your program resume; at that point,
handle_exception returns control to your own code on the target
machine.
breakpoint
handle_exception---in effect, to . On some machines,
simply receiving characters on the serial port may also trigger a trap;
again, in that situation, you don't need to call breakpoint from
your own program--simply running `target remote' from the host
session gets control.
Call breakpoint if none of these is true, or if you simply want
to make certain your program stops at a predetermined point for the
start of your debugging session.
The debugging stubs that come with are set up for a particular chip architecture, but they have no information about the rest of your debugging target machine.
First of all you need to tell the stub how to communicate with the serial port.
int getDebugChar()
getchar for your target system; a
different name is used to allow you to distinguish the two if you wish.
void putDebugChar(int)
putchar for your target system; a
different name is used to allow you to distinguish the two if you wish.
If you want to be able to stop your program while it is
running, you need to use an interrupt-driven serial driver, and arrange
for it to stop when it receives a ^C (`\003', the control-C
character). That is the character which uses to tell the
remote system to stop.
Getting the debugging target to return the proper status to
probably requires changes to the standard stub; one quick and dirty way
is to just execute a breakpoint instruction (the "dirty" part is that
reports a SIGTRAP instead of a SIGINT).
Other routines you need to supply are:
void exceptionHandler (int exception_number, void *exception_address)
exceptionHandler.
void flush_i_cache()
You must also make sure this library routine is available:
void *memset(void *, int, int)
memset that sets an area of
memory to a known value. If you have one of the free versions of
libc.a, memset can be found there; otherwise, you must
either obtain it from your hardware manufacturer, or write your own.
If you do not use the GNU C compiler, you may need other standard
library subroutines as well; this varies from one stub to another,
but in general the stubs are likely to use any of the common library
subroutines which gcc generates as inline code.
In summary, when your program is ready to debug, you must follow these steps.
getDebugChar,putDebugChar,flush_i_cache,memset,exceptionHandler.
set_debug_traps(); breakpoint();
exceptionHook. Normally you just use:
void (*exceptionHook)() = 0;but if before calling
set_debug_traps, you set it to point to a
function in your program, that function is called when
continues after stopping on a trap (for example, bus
error). The function indicated by exceptionHook is called with
one parameter: an int which is the exception number.
target remote command.
Its argument specifies how to communicate with the target
machine--either via a devicename attached to a direct serial line, or a
TCP port (usually to a terminal server which in turn has a serial line
to the target). For example, to use a serial line connected to the
device named `/dev/ttyb':
target remote /dev/ttybTo use a TCP connection, use an argument of the form
host:port. For example, to connect to port 2828 on a
terminal server named manyfarms:
target remote manyfarms:2828
Now you can use all the usual commands to examine and change data and to step and continue the remote program.
To resume the remote program and stop debugging it, use the detach
command.
Whenever is waiting for the remote program, if you type the interrupt character (often C-C), attempts to stop the program. This may or may not succeed, depending in part on the hardware and the serial drivers the remote system uses. If you type the interrupt character once again, displays this prompt:
Interrupted while waiting for the program. Give up (and stop debugging it)? (y or n)
If you type y, abandons the remote debugging session. (If you decide you want to try again later, you can use `target remote' again to connect once more.) If you type n, goes back to waiting.
The stub files provided with implement the target side of the communication protocol, and the side is implemented in the source file `remote.c'. Normally, you can simply allow these subroutines to communicate, and ignore the details. (If you're implementing your own stub file, you can still ignore the details: start with one of the existing stub files. `sparc-stub.c' is the best organized, and therefore the easiest to read.)
However, there may be occasions when you need to know something about the protocol--for example, if there is only one serial port to your target machine, you might want your program to do something special if it recognizes a packet meant for .
All commands and responses (other than acknowledgements, which are single characters) are sent as a packet which includes a checksum. A packet is introduced with the character `$', and ends with the character `#' followed by a two-digit checksum:
$packet info#checksum
checksum is computed as the modulo 256 sum of the packet info characters.
When either the host or the target machine receives a packet, the first response expected is an acknowledgement: a single character, either `+' (to indicate the package was received correctly) or `-' (to request retransmission).
The host () sends commands, and the target (the debugging stub incorporated in your program) sends data in response. The target also sends data when your program stops.
Command packets are distinguished by their first character, which identifies the kind of command.
These are some of the commands currently supported (for a complete list of commands, look in `gdb/remote.c.'):
g
G
maddr,count
Maddr,count:...
c
caddr
s
saddr
k
?
T
If you have trouble with the serial connection, you can use the command
set remotedebug. This makes report on all packets sent
back and forth across the serial line to the remote machine. The
packet-debugging information is printed on the standard output
stream. set remotedebug off turns it off, and show
remotedebug shows you its current state.
You can use the E7000 in-circuit emulator to develop code for either the Hitachi SH or the H8/300H. Use one of these forms of the `target e7000' command to connect to your E7000:
target e7000 port speed
target e7000 hostname
telnet to connect.
Some commands are available only on the H8/300 or the H8/500 configurations:
set machine h8300
set machine h8300h
set memory mod
show memory
small,
big, medium, and compact.
target sim args
After specifying this target, you can debug programs for the simulated
CPU in the same style as programs for your host computer; use the
file command to load a new program image, the run command
to run your program, and so on.
As well as making available all the usual machine registers (see
info reg), the Z8000 simulator provides three additional items
of information as specially named registers:
cycles
insts
time
You can refer to these values in expressions with the usual conventions; for example, `b fputc if $cycles>5000' sets a conditional breakpoint that suspends only after at least 5000 simulated clock ticks.
Go to the first, previous, next, last section, table of contents.