1 |
578 |
markom |
This is ./gdb.info, produced by makeinfo version 4.0 from gdb.texinfo.
|
2 |
|
|
|
3 |
|
|
INFO-DIR-SECTION Programming & development tools.
|
4 |
|
|
START-INFO-DIR-ENTRY
|
5 |
|
|
* Gdb: (gdb). The GNU debugger.
|
6 |
|
|
END-INFO-DIR-ENTRY
|
7 |
|
|
|
8 |
|
|
This file documents the GNU debugger GDB.
|
9 |
|
|
|
10 |
|
|
This is the Ninth Edition, April 2001, of `Debugging with GDB: the
|
11 |
|
|
GNU Source-Level Debugger' for GDB Version 20010707.
|
12 |
|
|
|
13 |
|
|
Copyright (C)
|
14 |
|
|
1988,1989,1990,1991,1992,1993,1994,1995,1996,1998,1999,2000,2001
|
15 |
|
|
Free Software Foundation, Inc.
|
16 |
|
|
|
17 |
|
|
Permission is granted to copy, distribute and/or modify this document
|
18 |
|
|
under the terms of the GNU Free Documentation License, Version 1.1 or
|
19 |
|
|
any later version published by the Free Software Foundation; with the
|
20 |
|
|
Invariant Sections being "A Sample GDB Session" and "Free Software",
|
21 |
|
|
with the Front-Cover texts being "A GNU Manual," and with the
|
22 |
|
|
Back-Cover Texts as in (a) below.
|
23 |
|
|
|
24 |
|
|
(a) The FSF's Back-Cover Text is: "You have freedom to copy and
|
25 |
|
|
modify this GNU Manual, like GNU software. Copies published by the Free
|
26 |
|
|
Software Foundation raise funds for GNU development."
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
File: gdb.info, Node: Files, Next: Symbol Errors, Up: GDB Files
|
30 |
|
|
|
31 |
|
|
Commands to specify files
|
32 |
|
|
=========================
|
33 |
|
|
|
34 |
|
|
You may want to specify executable and core dump file names. The
|
35 |
|
|
usual way to do this is at start-up time, using the arguments to GDB's
|
36 |
|
|
start-up commands (*note Getting In and Out of GDB: Invocation.).
|
37 |
|
|
|
38 |
|
|
Occasionally it is necessary to change to a different file during a
|
39 |
|
|
GDB session. Or you may run GDB and forget to specify a file you want
|
40 |
|
|
to use. In these situations the GDB commands to specify new files are
|
41 |
|
|
useful.
|
42 |
|
|
|
43 |
|
|
`file FILENAME'
|
44 |
|
|
Use FILENAME as the program to be debugged. It is read for its
|
45 |
|
|
symbols and for the contents of pure memory. It is also the
|
46 |
|
|
program executed when you use the `run' command. If you do not
|
47 |
|
|
specify a directory and the file is not found in the GDB working
|
48 |
|
|
directory, GDB uses the environment variable `PATH' as a list of
|
49 |
|
|
directories to search, just as the shell does when looking for a
|
50 |
|
|
program to run. You can change the value of this variable, for
|
51 |
|
|
both GDB and your program, using the `path' command.
|
52 |
|
|
|
53 |
|
|
On systems with memory-mapped files, an auxiliary file named
|
54 |
|
|
`FILENAME.syms' may hold symbol table information for FILENAME.
|
55 |
|
|
If so, GDB maps in the symbol table from `FILENAME.syms', starting
|
56 |
|
|
up more quickly. See the descriptions of the file options
|
57 |
|
|
`-mapped' and `-readnow' (available on the command line, and with
|
58 |
|
|
the commands `file', `symbol-file', or `add-symbol-file',
|
59 |
|
|
described below), for more information.
|
60 |
|
|
|
61 |
|
|
`file'
|
62 |
|
|
`file' with no argument makes GDB discard any information it has
|
63 |
|
|
on both executable file and the symbol table.
|
64 |
|
|
|
65 |
|
|
`exec-file [ FILENAME ]'
|
66 |
|
|
Specify that the program to be run (but not the symbol table) is
|
67 |
|
|
found in FILENAME. GDB searches the environment variable `PATH'
|
68 |
|
|
if necessary to locate your program. Omitting FILENAME means to
|
69 |
|
|
discard information on the executable file.
|
70 |
|
|
|
71 |
|
|
`symbol-file [ FILENAME ]'
|
72 |
|
|
Read symbol table information from file FILENAME. `PATH' is
|
73 |
|
|
searched when necessary. Use the `file' command to get both symbol
|
74 |
|
|
table and program to run from the same file.
|
75 |
|
|
|
76 |
|
|
`symbol-file' with no argument clears out GDB information on your
|
77 |
|
|
program's symbol table.
|
78 |
|
|
|
79 |
|
|
The `symbol-file' command causes GDB to forget the contents of its
|
80 |
|
|
convenience variables, the value history, and all breakpoints and
|
81 |
|
|
auto-display expressions. This is because they may contain
|
82 |
|
|
pointers to the internal data recording symbols and data types,
|
83 |
|
|
which are part of the old symbol table data being discarded inside
|
84 |
|
|
GDB.
|
85 |
|
|
|
86 |
|
|
`symbol-file' does not repeat if you press again after
|
87 |
|
|
executing it once.
|
88 |
|
|
|
89 |
|
|
When GDB is configured for a particular environment, it
|
90 |
|
|
understands debugging information in whatever format is the
|
91 |
|
|
standard generated for that environment; you may use either a GNU
|
92 |
|
|
compiler, or other compilers that adhere to the local conventions.
|
93 |
|
|
Best results are usually obtained from GNU compilers; for example,
|
94 |
|
|
using `gcc' you can generate debugging information for optimized
|
95 |
|
|
code.
|
96 |
|
|
|
97 |
|
|
For most kinds of object files, with the exception of old SVR3
|
98 |
|
|
systems using COFF, the `symbol-file' command does not normally
|
99 |
|
|
read the symbol table in full right away. Instead, it scans the
|
100 |
|
|
symbol table quickly to find which source files and which symbols
|
101 |
|
|
are present. The details are read later, one source file at a
|
102 |
|
|
time, as they are needed.
|
103 |
|
|
|
104 |
|
|
The purpose of this two-stage reading strategy is to make GDB
|
105 |
|
|
start up faster. For the most part, it is invisible except for
|
106 |
|
|
occasional pauses while the symbol table details for a particular
|
107 |
|
|
source file are being read. (The `set verbose' command can turn
|
108 |
|
|
these pauses into messages if desired. *Note Optional warnings
|
109 |
|
|
and messages: Messages/Warnings.)
|
110 |
|
|
|
111 |
|
|
We have not implemented the two-stage strategy for COFF yet. When
|
112 |
|
|
the symbol table is stored in COFF format, `symbol-file' reads the
|
113 |
|
|
symbol table data in full right away. Note that "stabs-in-COFF"
|
114 |
|
|
still does the two-stage strategy, since the debug info is actually
|
115 |
|
|
in stabs format.
|
116 |
|
|
|
117 |
|
|
`symbol-file FILENAME [ -readnow ] [ -mapped ]'
|
118 |
|
|
`file FILENAME [ -readnow ] [ -mapped ]'
|
119 |
|
|
You can override the GDB two-stage strategy for reading symbol
|
120 |
|
|
tables by using the `-readnow' option with any of the commands that
|
121 |
|
|
load symbol table information, if you want to be sure GDB has the
|
122 |
|
|
entire symbol table available.
|
123 |
|
|
|
124 |
|
|
If memory-mapped files are available on your system through the
|
125 |
|
|
`mmap' system call, you can use another option, `-mapped', to
|
126 |
|
|
cause GDB to write the symbols for your program into a reusable
|
127 |
|
|
file. Future GDB debugging sessions map in symbol information
|
128 |
|
|
from this auxiliary symbol file (if the program has not changed),
|
129 |
|
|
rather than spending time reading the symbol table from the
|
130 |
|
|
executable program. Using the `-mapped' option has the same
|
131 |
|
|
effect as starting GDB with the `-mapped' command-line option.
|
132 |
|
|
|
133 |
|
|
You can use both options together, to make sure the auxiliary
|
134 |
|
|
symbol file has all the symbol information for your program.
|
135 |
|
|
|
136 |
|
|
The auxiliary symbol file for a program called MYPROG is called
|
137 |
|
|
`MYPROG.syms'. Once this file exists (so long as it is newer than
|
138 |
|
|
the corresponding executable), GDB always attempts to use it when
|
139 |
|
|
you debug MYPROG; no special options or commands are needed.
|
140 |
|
|
|
141 |
|
|
The `.syms' file is specific to the host machine where you run
|
142 |
|
|
GDB. It holds an exact image of the internal GDB symbol table.
|
143 |
|
|
It cannot be shared across multiple host platforms.
|
144 |
|
|
|
145 |
|
|
`core-file [ FILENAME ]'
|
146 |
|
|
Specify the whereabouts of a core dump file to be used as the
|
147 |
|
|
"contents of memory". Traditionally, core files contain only some
|
148 |
|
|
parts of the address space of the process that generated them; GDB
|
149 |
|
|
can access the executable file itself for other parts.
|
150 |
|
|
|
151 |
|
|
`core-file' with no argument specifies that no core file is to be
|
152 |
|
|
used.
|
153 |
|
|
|
154 |
|
|
Note that the core file is ignored when your program is actually
|
155 |
|
|
running under GDB. So, if you have been running your program and
|
156 |
|
|
you wish to debug a core file instead, you must kill the
|
157 |
|
|
subprocess in which the program is running. To do this, use the
|
158 |
|
|
`kill' command (*note Killing the child process: Kill Process.).
|
159 |
|
|
|
160 |
|
|
`add-symbol-file FILENAME ADDRESS'
|
161 |
|
|
`add-symbol-file FILENAME ADDRESS [ -readnow ] [ -mapped ]'
|
162 |
|
|
`add-symbol-file FILENAME -sSECTION ADDRESS'
|
163 |
|
|
The `add-symbol-file' command reads additional symbol table
|
164 |
|
|
information from the file FILENAME. You would use this command
|
165 |
|
|
when FILENAME has been dynamically loaded (by some other means)
|
166 |
|
|
into the program that is running. ADDRESS should be the memory
|
167 |
|
|
address at which the file has been loaded; GDB cannot figure this
|
168 |
|
|
out for itself. You can additionally specify an arbitrary number
|
169 |
|
|
of `-sSECTION ADDRESS' pairs, to give an explicit section name and
|
170 |
|
|
base address for that section. You can specify any ADDRESS as an
|
171 |
|
|
expression.
|
172 |
|
|
|
173 |
|
|
The symbol table of the file FILENAME is added to the symbol table
|
174 |
|
|
originally read with the `symbol-file' command. You can use the
|
175 |
|
|
`add-symbol-file' command any number of times; the new symbol data
|
176 |
|
|
thus read keeps adding to the old. To discard all old symbol data
|
177 |
|
|
instead, use the `symbol-file' command without any arguments.
|
178 |
|
|
|
179 |
|
|
`add-symbol-file' does not repeat if you press after using
|
180 |
|
|
it.
|
181 |
|
|
|
182 |
|
|
You can use the `-mapped' and `-readnow' options just as with the
|
183 |
|
|
`symbol-file' command, to change how GDB manages the symbol table
|
184 |
|
|
information for FILENAME.
|
185 |
|
|
|
186 |
|
|
`add-shared-symbol-file'
|
187 |
|
|
The `add-shared-symbol-file' command can be used only under
|
188 |
|
|
Harris' CXUX operating system for the Motorola 88k. GDB
|
189 |
|
|
automatically looks for shared libraries, however if GDB does not
|
190 |
|
|
find yours, you can run `add-shared-symbol-file'. It takes no
|
191 |
|
|
arguments.
|
192 |
|
|
|
193 |
|
|
`section'
|
194 |
|
|
The `section' command changes the base address of section SECTION
|
195 |
|
|
of the exec file to ADDR. This can be used if the exec file does
|
196 |
|
|
not contain section addresses, (such as in the a.out format), or
|
197 |
|
|
when the addresses specified in the file itself are wrong. Each
|
198 |
|
|
section must be changed separately. The `info files' command,
|
199 |
|
|
described below, lists all the sections and their addresses.
|
200 |
|
|
|
201 |
|
|
`info files'
|
202 |
|
|
`info target'
|
203 |
|
|
`info files' and `info target' are synonymous; both print the
|
204 |
|
|
current target (*note Specifying a Debugging Target: Targets.),
|
205 |
|
|
including the names of the executable and core dump files
|
206 |
|
|
currently in use by GDB, and the files from which symbols were
|
207 |
|
|
loaded. The command `help target' lists all possible targets
|
208 |
|
|
rather than current ones.
|
209 |
|
|
|
210 |
|
|
All file-specifying commands allow both absolute and relative file
|
211 |
|
|
names as arguments. GDB always converts the file name to an absolute
|
212 |
|
|
file name and remembers it that way.
|
213 |
|
|
|
214 |
|
|
GDB supports HP-UX, SunOS, SVr4, Irix 5, and IBM RS/6000 shared
|
215 |
|
|
libraries.
|
216 |
|
|
|
217 |
|
|
GDB automatically loads symbol definitions from shared libraries
|
218 |
|
|
when you use the `run' command, or when you examine a core file.
|
219 |
|
|
(Before you issue the `run' command, GDB does not understand references
|
220 |
|
|
to a function in a shared library, however--unless you are debugging a
|
221 |
|
|
core file).
|
222 |
|
|
|
223 |
|
|
On HP-UX, if the program loads a library explicitly, GDB
|
224 |
|
|
automatically loads the symbols at the time of the `shl_load' call.
|
225 |
|
|
|
226 |
|
|
`info share'
|
227 |
|
|
`info sharedlibrary'
|
228 |
|
|
Print the names of the shared libraries which are currently loaded.
|
229 |
|
|
|
230 |
|
|
`sharedlibrary REGEX'
|
231 |
|
|
`share REGEX'
|
232 |
|
|
Load shared object library symbols for files matching a Unix
|
233 |
|
|
regular expression. As with files loaded automatically, it only
|
234 |
|
|
loads shared libraries required by your program for a core file or
|
235 |
|
|
after typing `run'. If REGEX is omitted all shared libraries
|
236 |
|
|
required by your program are loaded.
|
237 |
|
|
|
238 |
|
|
On HP-UX systems, GDB detects the loading of a shared library and
|
239 |
|
|
automatically reads in symbols from the newly loaded library, up to a
|
240 |
|
|
threshold that is initially set but that you can modify if you wish.
|
241 |
|
|
|
242 |
|
|
Beyond that threshold, symbols from shared libraries must be
|
243 |
|
|
explicitly loaded. To load these symbols, use the command
|
244 |
|
|
`sharedlibrary FILENAME'. The base address of the shared library is
|
245 |
|
|
determined automatically by GDB and need not be specified.
|
246 |
|
|
|
247 |
|
|
To display or set the threshold, use the commands:
|
248 |
|
|
|
249 |
|
|
`set auto-solib-add THRESHOLD'
|
250 |
|
|
Set the autoloading size threshold, in megabytes. If THRESHOLD is
|
251 |
|
|
nonzero, symbols from all shared object libraries will be loaded
|
252 |
|
|
automatically when the inferior begins execution or when the
|
253 |
|
|
dynamic linker informs GDB that a new library has been loaded,
|
254 |
|
|
until the symbol table of the program and libraries exceeds this
|
255 |
|
|
threshold. Otherwise, symbols must be loaded manually, using the
|
256 |
|
|
`sharedlibrary' command. The default threshold is 100 megabytes.
|
257 |
|
|
|
258 |
|
|
`show auto-solib-add'
|
259 |
|
|
Display the current autoloading size threshold, in megabytes.
|
260 |
|
|
|
261 |
|
|
|
262 |
|
|
File: gdb.info, Node: Symbol Errors, Prev: Files, Up: GDB Files
|
263 |
|
|
|
264 |
|
|
Errors reading symbol files
|
265 |
|
|
===========================
|
266 |
|
|
|
267 |
|
|
While reading a symbol file, GDB occasionally encounters problems,
|
268 |
|
|
such as symbol types it does not recognize, or known bugs in compiler
|
269 |
|
|
output. By default, GDB does not notify you of such problems, since
|
270 |
|
|
they are relatively common and primarily of interest to people
|
271 |
|
|
debugging compilers. If you are interested in seeing information about
|
272 |
|
|
ill-constructed symbol tables, you can either ask GDB to print only one
|
273 |
|
|
message about each such type of problem, no matter how many times the
|
274 |
|
|
problem occurs; or you can ask GDB to print more messages, to see how
|
275 |
|
|
many times the problems occur, with the `set complaints' command (*note
|
276 |
|
|
Optional warnings and messages: Messages/Warnings.).
|
277 |
|
|
|
278 |
|
|
The messages currently printed, and their meanings, include:
|
279 |
|
|
|
280 |
|
|
`inner block not inside outer block in SYMBOL'
|
281 |
|
|
The symbol information shows where symbol scopes begin and end
|
282 |
|
|
(such as at the start of a function or a block of statements).
|
283 |
|
|
This error indicates that an inner scope block is not fully
|
284 |
|
|
contained in its outer scope blocks.
|
285 |
|
|
|
286 |
|
|
GDB circumvents the problem by treating the inner block as if it
|
287 |
|
|
had the same scope as the outer block. In the error message,
|
288 |
|
|
SYMBOL may be shown as "`(don't know)'" if the outer block is not a
|
289 |
|
|
function.
|
290 |
|
|
|
291 |
|
|
`block at ADDRESS out of order'
|
292 |
|
|
The symbol information for symbol scope blocks should occur in
|
293 |
|
|
order of increasing addresses. This error indicates that it does
|
294 |
|
|
not do so.
|
295 |
|
|
|
296 |
|
|
GDB does not circumvent this problem, and has trouble locating
|
297 |
|
|
symbols in the source file whose symbols it is reading. (You can
|
298 |
|
|
often determine what source file is affected by specifying `set
|
299 |
|
|
verbose on'. *Note Optional warnings and messages:
|
300 |
|
|
Messages/Warnings.)
|
301 |
|
|
|
302 |
|
|
`bad block start address patched'
|
303 |
|
|
The symbol information for a symbol scope block has a start address
|
304 |
|
|
smaller than the address of the preceding source line. This is
|
305 |
|
|
known to occur in the SunOS 4.1.1 (and earlier) C compiler.
|
306 |
|
|
|
307 |
|
|
GDB circumvents the problem by treating the symbol scope block as
|
308 |
|
|
starting on the previous source line.
|
309 |
|
|
|
310 |
|
|
`bad string table offset in symbol N'
|
311 |
|
|
Symbol number N contains a pointer into the string table which is
|
312 |
|
|
larger than the size of the string table.
|
313 |
|
|
|
314 |
|
|
GDB circumvents the problem by considering the symbol to have the
|
315 |
|
|
name `foo', which may cause other problems if many symbols end up
|
316 |
|
|
with this name.
|
317 |
|
|
|
318 |
|
|
`unknown symbol type `0xNN''
|
319 |
|
|
The symbol information contains new data types that GDB does not
|
320 |
|
|
yet know how to read. `0xNN' is the symbol type of the
|
321 |
|
|
uncomprehended information, in hexadecimal.
|
322 |
|
|
|
323 |
|
|
GDB circumvents the error by ignoring this symbol information.
|
324 |
|
|
This usually allows you to debug your program, though certain
|
325 |
|
|
symbols are not accessible. If you encounter such a problem and
|
326 |
|
|
feel like debugging it, you can debug `gdb' with itself, breakpoint
|
327 |
|
|
on `complain', then go up to the function `read_dbx_symtab' and
|
328 |
|
|
examine `*bufp' to see the symbol.
|
329 |
|
|
|
330 |
|
|
`stub type has NULL name'
|
331 |
|
|
GDB could not find the full definition for a struct or class.
|
332 |
|
|
|
333 |
|
|
`const/volatile indicator missing (ok if using g++ v1.x), got...'
|
334 |
|
|
The symbol information for a C++ member function is missing some
|
335 |
|
|
information that recent versions of the compiler should have
|
336 |
|
|
output for it.
|
337 |
|
|
|
338 |
|
|
`info mismatch between compiler and debugger'
|
339 |
|
|
GDB could not parse a type specification output by the compiler.
|
340 |
|
|
|
341 |
|
|
|
342 |
|
|
File: gdb.info, Node: Targets, Next: Configurations, Prev: GDB Files, Up: Top
|
343 |
|
|
|
344 |
|
|
Specifying a Debugging Target
|
345 |
|
|
*****************************
|
346 |
|
|
|
347 |
|
|
A "target" is the execution environment occupied by your program.
|
348 |
|
|
|
349 |
|
|
Often, GDB runs in the same host environment as your program; in
|
350 |
|
|
that case, the debugging target is specified as a side effect when you
|
351 |
|
|
use the `file' or `core' commands. When you need more flexibility--for
|
352 |
|
|
example, running GDB on a physically separate host, or controlling a
|
353 |
|
|
standalone system over a serial port or a realtime system over a TCP/IP
|
354 |
|
|
connection--you can use the `target' command to specify one of the
|
355 |
|
|
target types configured for GDB (*note Commands for managing targets:
|
356 |
|
|
Target Commands.).
|
357 |
|
|
|
358 |
|
|
* Menu:
|
359 |
|
|
|
360 |
|
|
* Active Targets:: Active targets
|
361 |
|
|
* Target Commands:: Commands for managing targets
|
362 |
|
|
* Byte Order:: Choosing target byte order
|
363 |
|
|
* Remote:: Remote debugging
|
364 |
|
|
* KOD:: Kernel Object Display
|
365 |
|
|
|
366 |
|
|
|
367 |
|
|
File: gdb.info, Node: Active Targets, Next: Target Commands, Up: Targets
|
368 |
|
|
|
369 |
|
|
Active targets
|
370 |
|
|
==============
|
371 |
|
|
|
372 |
|
|
There are three classes of targets: processes, core files, and
|
373 |
|
|
executable files. GDB can work concurrently on up to three active
|
374 |
|
|
targets, one in each class. This allows you to (for example) start a
|
375 |
|
|
process and inspect its activity without abandoning your work on a core
|
376 |
|
|
file.
|
377 |
|
|
|
378 |
|
|
For example, if you execute `gdb a.out', then the executable file
|
379 |
|
|
`a.out' is the only active target. If you designate a core file as
|
380 |
|
|
well--presumably from a prior run that crashed and coredumped--then GDB
|
381 |
|
|
has two active targets and uses them in tandem, looking first in the
|
382 |
|
|
corefile target, then in the executable file, to satisfy requests for
|
383 |
|
|
memory addresses. (Typically, these two classes of target are
|
384 |
|
|
complementary, since core files contain only a program's read-write
|
385 |
|
|
memory--variables and so on--plus machine status, while executable
|
386 |
|
|
files contain only the program text and initialized data.)
|
387 |
|
|
|
388 |
|
|
When you type `run', your executable file becomes an active process
|
389 |
|
|
target as well. When a process target is active, all GDB commands
|
390 |
|
|
requesting memory addresses refer to that target; addresses in an
|
391 |
|
|
active core file or executable file target are obscured while the
|
392 |
|
|
process target is active.
|
393 |
|
|
|
394 |
|
|
Use the `core-file' and `exec-file' commands to select a new core
|
395 |
|
|
file or executable target (*note Commands to specify files: Files.).
|
396 |
|
|
To specify as a target a process that is already running, use the
|
397 |
|
|
`attach' command (*note Debugging an already-running process: Attach.).
|
398 |
|
|
|
399 |
|
|
|
400 |
|
|
File: gdb.info, Node: Target Commands, Next: Byte Order, Prev: Active Targets, Up: Targets
|
401 |
|
|
|
402 |
|
|
Commands for managing targets
|
403 |
|
|
=============================
|
404 |
|
|
|
405 |
|
|
`target TYPE PARAMETERS'
|
406 |
|
|
Connects the GDB host environment to a target machine or process.
|
407 |
|
|
A target is typically a protocol for talking to debugging
|
408 |
|
|
facilities. You use the argument TYPE to specify the type or
|
409 |
|
|
protocol of the target machine.
|
410 |
|
|
|
411 |
|
|
Further PARAMETERS are interpreted by the target protocol, but
|
412 |
|
|
typically include things like device names or host names to connect
|
413 |
|
|
with, process numbers, and baud rates.
|
414 |
|
|
|
415 |
|
|
The `target' command does not repeat if you press again
|
416 |
|
|
after executing the command.
|
417 |
|
|
|
418 |
|
|
`help target'
|
419 |
|
|
Displays the names of all targets available. To display targets
|
420 |
|
|
currently selected, use either `info target' or `info files'
|
421 |
|
|
(*note Commands to specify files: Files.).
|
422 |
|
|
|
423 |
|
|
`help target NAME'
|
424 |
|
|
Describe a particular target, including any parameters necessary to
|
425 |
|
|
select it.
|
426 |
|
|
|
427 |
|
|
`set gnutarget ARGS'
|
428 |
|
|
GDB uses its own library BFD to read your files. GDB knows
|
429 |
|
|
whether it is reading an "executable", a "core", or a ".o" file;
|
430 |
|
|
however, you can specify the file format with the `set gnutarget'
|
431 |
|
|
command. Unlike most `target' commands, with `gnutarget' the
|
432 |
|
|
`target' refers to a program, not a machine.
|
433 |
|
|
|
434 |
|
|
_Warning:_ To specify a file format with `set gnutarget', you
|
435 |
|
|
must know the actual BFD name.
|
436 |
|
|
|
437 |
|
|
*Note Commands to specify files: Files.
|
438 |
|
|
|
439 |
|
|
`show gnutarget'
|
440 |
|
|
Use the `show gnutarget' command to display what file format
|
441 |
|
|
`gnutarget' is set to read. If you have not set `gnutarget', GDB
|
442 |
|
|
will determine the file format for each file automatically, and
|
443 |
|
|
`show gnutarget' displays `The current BDF target is "auto"'.
|
444 |
|
|
|
445 |
|
|
Here are some common targets (available, or not, depending on the GDB
|
446 |
|
|
configuration):
|
447 |
|
|
|
448 |
|
|
`target exec PROGRAM'
|
449 |
|
|
An executable file. `target exec PROGRAM' is the same as
|
450 |
|
|
`exec-file PROGRAM'.
|
451 |
|
|
|
452 |
|
|
`target core FILENAME'
|
453 |
|
|
A core dump file. `target core FILENAME' is the same as
|
454 |
|
|
`core-file FILENAME'.
|
455 |
|
|
|
456 |
|
|
`target remote DEV'
|
457 |
|
|
Remote serial target in GDB-specific protocol. The argument DEV
|
458 |
|
|
specifies what serial device to use for the connection (e.g.
|
459 |
|
|
`/dev/ttya'). *Note Remote debugging: Remote. `target remote'
|
460 |
|
|
supports the `load' command. This is only useful if you have some
|
461 |
|
|
other way of getting the stub to the target system, and you can put
|
462 |
|
|
it somewhere in memory where it won't get clobbered by the
|
463 |
|
|
download.
|
464 |
|
|
|
465 |
|
|
`target sim'
|
466 |
|
|
Builtin CPU simulator. GDB includes simulators for most
|
467 |
|
|
architectures. In general,
|
468 |
|
|
target sim
|
469 |
|
|
load
|
470 |
|
|
run
|
471 |
|
|
|
472 |
|
|
works; however, you cannot assume that a specific memory map,
|
473 |
|
|
device drivers, or even basic I/O is available, although some
|
474 |
|
|
simulators do provide these. For info about any
|
475 |
|
|
processor-specific simulator details, see the appropriate section
|
476 |
|
|
in *Note Embedded Processors: Embedded Processors.
|
477 |
|
|
|
478 |
|
|
Some configurations may include these targets as well:
|
479 |
|
|
|
480 |
|
|
`target nrom DEV'
|
481 |
|
|
NetROM ROM emulator. This target only supports downloading.
|
482 |
|
|
|
483 |
|
|
Different targets are available on different configurations of GDB;
|
484 |
|
|
your configuration may have more or fewer targets.
|
485 |
|
|
|
486 |
|
|
Many remote targets require you to download the executable's code
|
487 |
|
|
once you've successfully established a connection.
|
488 |
|
|
|
489 |
|
|
`load FILENAME'
|
490 |
|
|
Depending on what remote debugging facilities are configured into
|
491 |
|
|
GDB, the `load' command may be available. Where it exists, it is
|
492 |
|
|
meant to make FILENAME (an executable) available for debugging on
|
493 |
|
|
the remote system--by downloading, or dynamic linking, for example.
|
494 |
|
|
`load' also records the FILENAME symbol table in GDB, like the
|
495 |
|
|
`add-symbol-file' command.
|
496 |
|
|
|
497 |
|
|
If your GDB does not have a `load' command, attempting to execute
|
498 |
|
|
it gets the error message "`You can't do that when your target is
|
499 |
|
|
...'"
|
500 |
|
|
|
501 |
|
|
The file is loaded at whatever address is specified in the
|
502 |
|
|
executable. For some object file formats, you can specify the
|
503 |
|
|
load address when you link the program; for other formats, like
|
504 |
|
|
a.out, the object file format specifies a fixed address.
|
505 |
|
|
|
506 |
|
|
`load' does not repeat if you press again after using it.
|
507 |
|
|
|
508 |
|
|
|
509 |
|
|
File: gdb.info, Node: Byte Order, Next: Remote, Prev: Target Commands, Up: Targets
|
510 |
|
|
|
511 |
|
|
Choosing target byte order
|
512 |
|
|
==========================
|
513 |
|
|
|
514 |
|
|
Some types of processors, such as the MIPS, PowerPC, and Hitachi SH,
|
515 |
|
|
offer the ability to run either big-endian or little-endian byte
|
516 |
|
|
orders. Usually the executable or symbol will include a bit to
|
517 |
|
|
designate the endian-ness, and you will not need to worry about which
|
518 |
|
|
to use. However, you may still find it useful to adjust GDB's idea of
|
519 |
|
|
processor endian-ness manually.
|
520 |
|
|
|
521 |
|
|
`set endian big'
|
522 |
|
|
Instruct GDB to assume the target is big-endian.
|
523 |
|
|
|
524 |
|
|
`set endian little'
|
525 |
|
|
Instruct GDB to assume the target is little-endian.
|
526 |
|
|
|
527 |
|
|
`set endian auto'
|
528 |
|
|
Instruct GDB to use the byte order associated with the executable.
|
529 |
|
|
|
530 |
|
|
`show endian'
|
531 |
|
|
Display GDB's current idea of the target byte order.
|
532 |
|
|
|
533 |
|
|
Note that these commands merely adjust interpretation of symbolic
|
534 |
|
|
data on the host, and that they have absolutely no effect on the target
|
535 |
|
|
system.
|
536 |
|
|
|
537 |
|
|
|
538 |
|
|
File: gdb.info, Node: Remote, Next: KOD, Prev: Byte Order, Up: Targets
|
539 |
|
|
|
540 |
|
|
Remote debugging
|
541 |
|
|
================
|
542 |
|
|
|
543 |
|
|
If you are trying to debug a program running on a machine that
|
544 |
|
|
cannot run GDB in the usual way, it is often useful to use remote
|
545 |
|
|
debugging. For example, you might use remote debugging on an operating
|
546 |
|
|
system kernel, or on a small system which does not have a general
|
547 |
|
|
purpose operating system powerful enough to run a full-featured
|
548 |
|
|
debugger.
|
549 |
|
|
|
550 |
|
|
Some configurations of GDB have special serial or TCP/IP interfaces
|
551 |
|
|
to make this work with particular debugging targets. In addition, GDB
|
552 |
|
|
comes with a generic serial protocol (specific to GDB, but not specific
|
553 |
|
|
to any particular target system) which you can use if you write the
|
554 |
|
|
remote stubs--the code that runs on the remote system to communicate
|
555 |
|
|
with GDB.
|
556 |
|
|
|
557 |
|
|
Other remote targets may be available in your configuration of GDB;
|
558 |
|
|
use `help target' to list them.
|
559 |
|
|
|
560 |
|
|
* Menu:
|
561 |
|
|
|
562 |
|
|
* Remote Serial:: GDB remote serial protocol
|
563 |
|
|
|
564 |
|
|
|
565 |
|
|
File: gdb.info, Node: Remote Serial, Up: Remote
|
566 |
|
|
|
567 |
|
|
The GDB remote serial protocol
|
568 |
|
|
------------------------------
|
569 |
|
|
|
570 |
|
|
To debug a program running on another machine (the debugging
|
571 |
|
|
"target" machine), you must first arrange for all the usual
|
572 |
|
|
prerequisites for the program to run by itself. For example, for a C
|
573 |
|
|
program, you need:
|
574 |
|
|
|
575 |
|
|
1. A startup routine to set up the C runtime environment; these
|
576 |
|
|
usually have a name like `crt0'. The startup routine may be
|
577 |
|
|
supplied by your hardware supplier, or you may have to write your
|
578 |
|
|
own.
|
579 |
|
|
|
580 |
|
|
2. A C subroutine library to support your program's subroutine calls,
|
581 |
|
|
notably managing input and output.
|
582 |
|
|
|
583 |
|
|
3. A way of getting your program to the other machine--for example, a
|
584 |
|
|
download program. These are often supplied by the hardware
|
585 |
|
|
manufacturer, but you may have to write your own from hardware
|
586 |
|
|
documentation.
|
587 |
|
|
|
588 |
|
|
The next step is to arrange for your program to use a serial port to
|
589 |
|
|
communicate with the machine where GDB is running (the "host" machine).
|
590 |
|
|
In general terms, the scheme looks like this:
|
591 |
|
|
|
592 |
|
|
_On the host,_
|
593 |
|
|
GDB already understands how to use this protocol; when everything
|
594 |
|
|
else is set up, you can simply use the `target remote' command
|
595 |
|
|
(*note Specifying a Debugging Target: Targets.).
|
596 |
|
|
|
597 |
|
|
_On the target,_
|
598 |
|
|
you must link with your program a few special-purpose subroutines
|
599 |
|
|
that implement the GDB remote serial protocol. The file
|
600 |
|
|
containing these subroutines is called a "debugging stub".
|
601 |
|
|
|
602 |
|
|
On certain remote targets, you can use an auxiliary program
|
603 |
|
|
`gdbserver' instead of linking a stub into your program. *Note
|
604 |
|
|
Using the `gdbserver' program: Server, for details.
|
605 |
|
|
|
606 |
|
|
The debugging stub is specific to the architecture of the remote
|
607 |
|
|
machine; for example, use `sparc-stub.c' to debug programs on SPARC
|
608 |
|
|
boards.
|
609 |
|
|
|
610 |
|
|
These working remote stubs are distributed with GDB:
|
611 |
|
|
|
612 |
|
|
`i386-stub.c'
|
613 |
|
|
For Intel 386 and compatible architectures.
|
614 |
|
|
|
615 |
|
|
`m68k-stub.c'
|
616 |
|
|
For Motorola 680x0 architectures.
|
617 |
|
|
|
618 |
|
|
`sh-stub.c'
|
619 |
|
|
For Hitachi SH architectures.
|
620 |
|
|
|
621 |
|
|
`sparc-stub.c'
|
622 |
|
|
For SPARC architectures.
|
623 |
|
|
|
624 |
|
|
`sparcl-stub.c'
|
625 |
|
|
For Fujitsu SPARCLITE architectures.
|
626 |
|
|
|
627 |
|
|
The `README' file in the GDB distribution may list other recently
|
628 |
|
|
added stubs.
|
629 |
|
|
|
630 |
|
|
* Menu:
|
631 |
|
|
|
632 |
|
|
* Stub Contents:: What the stub can do for you
|
633 |
|
|
* Bootstrapping:: What you must do for the stub
|
634 |
|
|
* Debug Session:: Putting it all together
|
635 |
|
|
* Protocol:: Definition of the communication protocol
|
636 |
|
|
* Server:: Using the `gdbserver' program
|
637 |
|
|
* NetWare:: Using the `gdbserve.nlm' program
|
638 |
|
|
|
639 |
|
|
|
640 |
|
|
File: gdb.info, Node: Stub Contents, Next: Bootstrapping, Up: Remote Serial
|
641 |
|
|
|
642 |
|
|
What the stub can do for you
|
643 |
|
|
............................
|
644 |
|
|
|
645 |
|
|
The debugging stub for your architecture supplies these three
|
646 |
|
|
subroutines:
|
647 |
|
|
|
648 |
|
|
`set_debug_traps'
|
649 |
|
|
This routine arranges for `handle_exception' to run when your
|
650 |
|
|
program stops. You must call this subroutine explicitly near the
|
651 |
|
|
beginning of your program.
|
652 |
|
|
|
653 |
|
|
`handle_exception'
|
654 |
|
|
This is the central workhorse, but your program never calls it
|
655 |
|
|
explicitly--the setup code arranges for `handle_exception' to run
|
656 |
|
|
when a trap is triggered.
|
657 |
|
|
|
658 |
|
|
`handle_exception' takes control when your program stops during
|
659 |
|
|
execution (for example, on a breakpoint), and mediates
|
660 |
|
|
communications with GDB on the host machine. This is where the
|
661 |
|
|
communications protocol is implemented; `handle_exception' acts as
|
662 |
|
|
the GDB representative on the target machine. It begins by
|
663 |
|
|
sending summary information on the state of your program, then
|
664 |
|
|
continues to execute, retrieving and transmitting any information
|
665 |
|
|
GDB needs, until you execute a GDB command that makes your program
|
666 |
|
|
resume; at that point, `handle_exception' returns control to your
|
667 |
|
|
own code on the target machine.
|
668 |
|
|
|
669 |
|
|
`breakpoint'
|
670 |
|
|
Use this auxiliary subroutine to make your program contain a
|
671 |
|
|
breakpoint. Depending on the particular situation, this may be
|
672 |
|
|
the only way for GDB to get control. For instance, if your target
|
673 |
|
|
machine has some sort of interrupt button, you won't need to call
|
674 |
|
|
this; pressing the interrupt button transfers control to
|
675 |
|
|
`handle_exception'--in effect, to GDB. On some machines, simply
|
676 |
|
|
receiving characters on the serial port may also trigger a trap;
|
677 |
|
|
again, in that situation, you don't need to call `breakpoint' from
|
678 |
|
|
your own program--simply running `target remote' from the host GDB
|
679 |
|
|
session gets control.
|
680 |
|
|
|
681 |
|
|
Call `breakpoint' if none of these is true, or if you simply want
|
682 |
|
|
to make certain your program stops at a predetermined point for the
|
683 |
|
|
start of your debugging session.
|
684 |
|
|
|
685 |
|
|
|
686 |
|
|
File: gdb.info, Node: Bootstrapping, Next: Debug Session, Prev: Stub Contents, Up: Remote Serial
|
687 |
|
|
|
688 |
|
|
What you must do for the stub
|
689 |
|
|
.............................
|
690 |
|
|
|
691 |
|
|
The debugging stubs that come with GDB are set up for a particular
|
692 |
|
|
chip architecture, but they have no information about the rest of your
|
693 |
|
|
debugging target machine.
|
694 |
|
|
|
695 |
|
|
First of all you need to tell the stub how to communicate with the
|
696 |
|
|
serial port.
|
697 |
|
|
|
698 |
|
|
`int getDebugChar()'
|
699 |
|
|
Write this subroutine to read a single character from the serial
|
700 |
|
|
port. It may be identical to `getchar' for your target system; a
|
701 |
|
|
different name is used to allow you to distinguish the two if you
|
702 |
|
|
wish.
|
703 |
|
|
|
704 |
|
|
`void putDebugChar(int)'
|
705 |
|
|
Write this subroutine to write a single character to the serial
|
706 |
|
|
port. It may be identical to `putchar' for your target system; a
|
707 |
|
|
different name is used to allow you to distinguish the two if you
|
708 |
|
|
wish.
|
709 |
|
|
|
710 |
|
|
If you want GDB to be able to stop your program while it is running,
|
711 |
|
|
you need to use an interrupt-driven serial driver, and arrange for it
|
712 |
|
|
to stop when it receives a `^C' (`\003', the control-C character).
|
713 |
|
|
That is the character which GDB uses to tell the remote system to stop.
|
714 |
|
|
|
715 |
|
|
Getting the debugging target to return the proper status to GDB
|
716 |
|
|
probably requires changes to the standard stub; one quick and dirty way
|
717 |
|
|
is to just execute a breakpoint instruction (the "dirty" part is that
|
718 |
|
|
GDB reports a `SIGTRAP' instead of a `SIGINT').
|
719 |
|
|
|
720 |
|
|
Other routines you need to supply are:
|
721 |
|
|
|
722 |
|
|
`void exceptionHandler (int EXCEPTION_NUMBER, void *EXCEPTION_ADDRESS)'
|
723 |
|
|
Write this function to install EXCEPTION_ADDRESS in the exception
|
724 |
|
|
handling tables. You need to do this because the stub does not
|
725 |
|
|
have any way of knowing what the exception handling tables on your
|
726 |
|
|
target system are like (for example, the processor's table might
|
727 |
|
|
be in ROM, containing entries which point to a table in RAM).
|
728 |
|
|
EXCEPTION_NUMBER is the exception number which should be changed;
|
729 |
|
|
its meaning is architecture-dependent (for example, different
|
730 |
|
|
numbers might represent divide by zero, misaligned access, etc).
|
731 |
|
|
When this exception occurs, control should be transferred directly
|
732 |
|
|
to EXCEPTION_ADDRESS, and the processor state (stack, registers,
|
733 |
|
|
and so on) should be just as it is when a processor exception
|
734 |
|
|
occurs. So if you want to use a jump instruction to reach
|
735 |
|
|
EXCEPTION_ADDRESS, it should be a simple jump, not a jump to
|
736 |
|
|
subroutine.
|
737 |
|
|
|
738 |
|
|
For the 386, EXCEPTION_ADDRESS should be installed as an interrupt
|
739 |
|
|
gate so that interrupts are masked while the handler runs. The
|
740 |
|
|
gate should be at privilege level 0 (the most privileged level).
|
741 |
|
|
The SPARC and 68k stubs are able to mask interrupts themselves
|
742 |
|
|
without help from `exceptionHandler'.
|
743 |
|
|
|
744 |
|
|
`void flush_i_cache()'
|
745 |
|
|
On SPARC and SPARCLITE only, write this subroutine to flush the
|
746 |
|
|
instruction cache, if any, on your target machine. If there is no
|
747 |
|
|
instruction cache, this subroutine may be a no-op.
|
748 |
|
|
|
749 |
|
|
On target machines that have instruction caches, GDB requires this
|
750 |
|
|
function to make certain that the state of your program is stable.
|
751 |
|
|
|
752 |
|
|
You must also make sure this library routine is available:
|
753 |
|
|
|
754 |
|
|
`void *memset(void *, int, int)'
|
755 |
|
|
This is the standard library function `memset' that sets an area of
|
756 |
|
|
memory to a known value. If you have one of the free versions of
|
757 |
|
|
`libc.a', `memset' can be found there; otherwise, you must either
|
758 |
|
|
obtain it from your hardware manufacturer, or write your own.
|
759 |
|
|
|
760 |
|
|
If you do not use the GNU C compiler, you may need other standard
|
761 |
|
|
library subroutines as well; this varies from one stub to another, but
|
762 |
|
|
in general the stubs are likely to use any of the common library
|
763 |
|
|
subroutines which `gcc' generates as inline code.
|
764 |
|
|
|
765 |
|
|
|
766 |
|
|
File: gdb.info, Node: Debug Session, Next: Protocol, Prev: Bootstrapping, Up: Remote Serial
|
767 |
|
|
|
768 |
|
|
Putting it all together
|
769 |
|
|
.......................
|
770 |
|
|
|
771 |
|
|
In summary, when your program is ready to debug, you must follow
|
772 |
|
|
these steps.
|
773 |
|
|
|
774 |
|
|
1. Make sure you have defined the supporting low-level routines
|
775 |
|
|
(*note What you must do for the stub: Bootstrapping.):
|
776 |
|
|
`getDebugChar', `putDebugChar',
|
777 |
|
|
`flush_i_cache', `memset', `exceptionHandler'.
|
778 |
|
|
|
779 |
|
|
2. Insert these lines near the top of your program:
|
780 |
|
|
|
781 |
|
|
set_debug_traps();
|
782 |
|
|
breakpoint();
|
783 |
|
|
|
784 |
|
|
3. For the 680x0 stub only, you need to provide a variable called
|
785 |
|
|
`exceptionHook'. Normally you just use:
|
786 |
|
|
|
787 |
|
|
void (*exceptionHook)() = 0;
|
788 |
|
|
|
789 |
|
|
but if before calling `set_debug_traps', you set it to point to a
|
790 |
|
|
function in your program, that function is called when `GDB'
|
791 |
|
|
continues after stopping on a trap (for example, bus error). The
|
792 |
|
|
function indicated by `exceptionHook' is called with one
|
793 |
|
|
parameter: an `int' which is the exception number.
|
794 |
|
|
|
795 |
|
|
4. Compile and link together: your program, the GDB debugging stub for
|
796 |
|
|
your target architecture, and the supporting subroutines.
|
797 |
|
|
|
798 |
|
|
5. Make sure you have a serial connection between your target machine
|
799 |
|
|
and the GDB host, and identify the serial port on the host.
|
800 |
|
|
|
801 |
|
|
6. Download your program to your target machine (or get it there by
|
802 |
|
|
whatever means the manufacturer provides), and start it.
|
803 |
|
|
|
804 |
|
|
7. To start remote debugging, run GDB on the host machine, and specify
|
805 |
|
|
as an executable file the program that is running in the remote
|
806 |
|
|
machine. This tells GDB how to find your program's symbols and
|
807 |
|
|
the contents of its pure text.
|
808 |
|
|
|
809 |
|
|
8. Establish communication using the `target remote' command. Its
|
810 |
|
|
argument specifies how to communicate with the target
|
811 |
|
|
machine--either via a devicename attached to a direct serial line,
|
812 |
|
|
or a TCP port (usually to a terminal server which in turn has a
|
813 |
|
|
serial line to the target). For example, to use a serial line
|
814 |
|
|
connected to the device named `/dev/ttyb':
|
815 |
|
|
|
816 |
|
|
target remote /dev/ttyb
|
817 |
|
|
|
818 |
|
|
To use a TCP connection, use an argument of the form `HOST:port'.
|
819 |
|
|
For example, to connect to port 2828 on a terminal server named
|
820 |
|
|
`manyfarms':
|
821 |
|
|
|
822 |
|
|
target remote manyfarms:2828
|
823 |
|
|
|
824 |
|
|
Now you can use all the usual commands to examine and change data
|
825 |
|
|
and to step and continue the remote program.
|
826 |
|
|
|
827 |
|
|
To resume the remote program and stop debugging it, use the `detach'
|
828 |
|
|
command.
|
829 |
|
|
|
830 |
|
|
Whenever GDB is waiting for the remote program, if you type the
|
831 |
|
|
interrupt character (often ), GDB attempts to stop the program.
|
832 |
|
|
This may or may not succeed, depending in part on the hardware and the
|
833 |
|
|
serial drivers the remote system uses. If you type the interrupt
|
834 |
|
|
character once again, GDB displays this prompt:
|
835 |
|
|
|
836 |
|
|
Interrupted while waiting for the program.
|
837 |
|
|
Give up (and stop debugging it)? (y or n)
|
838 |
|
|
|
839 |
|
|
If you type `y', GDB abandons the remote debugging session. (If you
|
840 |
|
|
decide you want to try again later, you can use `target remote' again
|
841 |
|
|
to connect once more.) If you type `n', GDB goes back to waiting.
|
842 |
|
|
|