OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gdb-7.2/] [gdb-7.2-or32-1.0rc1/] [gdb/] [doc/] [gdb.info-2] - Blame information for rev 341

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 330 jeremybenn
This is gdb.info, produced by makeinfo version 4.8 from ./gdb.texinfo.
2
 
3
INFO-DIR-SECTION Software development
4
START-INFO-DIR-ENTRY
5
* Gdb: (gdb).                     The GNU debugger.
6
END-INFO-DIR-ENTRY
7
 
8
   Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
9
1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
10
2010 Free Software Foundation, Inc.
11
 
12
   Permission is granted to copy, distribute and/or modify this document
13
under the terms of the GNU Free Documentation License, Version 1.3 or
14
any later version published by the Free Software Foundation; with the
15
Invariant Sections being "Free Software" and "Free Software Needs Free
16
Documentation", with the Front-Cover Texts being "A GNU Manual," and
17
with the Back-Cover Texts as in (a) below.
18
 
19
   (a) The FSF's Back-Cover Text is: "You are free to copy and modify
20
this GNU Manual.  Buying copies from GNU Press supports the FSF in
21
developing GNU and promoting software freedom."
22
 
23
   This file documents the GNU debugger GDB.
24
 
25
   This is the Ninth Edition, of `Debugging with GDB: the GNU
26
Source-Level Debugger' for GDB (GDB) Version 7.2.
27
 
28
   Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
29
1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
30
2010 Free Software Foundation, Inc.
31
 
32
   Permission is granted to copy, distribute and/or modify this document
33
under the terms of the GNU Free Documentation License, Version 1.3 or
34
any later version published by the Free Software Foundation; with the
35
Invariant Sections being "Free Software" and "Free Software Needs Free
36
Documentation", with the Front-Cover Texts being "A GNU Manual," and
37
with the Back-Cover Texts as in (a) below.
38
 
39
   (a) The FSF's Back-Cover Text is: "You are free to copy and modify
40
this GNU Manual.  Buying copies from GNU Press supports the FSF in
41
developing GNU and promoting software freedom."
42
 
43

44
File: gdb.info,  Node: Registers,  Next: Floating Point Hardware,  Prev: Convenience Vars,  Up: Data
45
 
46
10.12 Registers
47
===============
48
 
49
You can refer to machine register contents, in expressions, as variables
50
with names starting with `$'.  The names of registers are different for
51
each machine; use `info registers' to see the names used on your
52
machine.
53
 
54
`info registers'
55
     Print the names and values of all registers except floating-point
56
     and vector registers (in the selected stack frame).
57
 
58
`info all-registers'
59
     Print the names and values of all registers, including
60
     floating-point and vector registers (in the selected stack frame).
61
 
62
`info registers REGNAME ...'
63
     Print the "relativized" value of each specified register REGNAME.
64
     As discussed in detail below, register values are normally
65
     relative to the selected stack frame.  REGNAME may be any register
66
     name valid on the machine you are using, with or without the
67
     initial `$'.
68
 
69
   GDB has four "standard" register names that are available (in
70
expressions) on most machines--whenever they do not conflict with an
71
architecture's canonical mnemonics for registers.  The register names
72
`$pc' and `$sp' are used for the program counter register and the stack
73
pointer.  `$fp' is used for a register that contains a pointer to the
74
current stack frame, and `$ps' is used for a register that contains the
75
processor status.  For example, you could print the program counter in
76
hex with
77
 
78
     p/x $pc
79
 
80
or print the instruction to be executed next with
81
 
82
     x/i $pc
83
 
84
or add four to the stack pointer(1) with
85
 
86
     set $sp += 4
87
 
88
   Whenever possible, these four standard register names are available
89
on your machine even though the machine has different canonical
90
mnemonics, so long as there is no conflict.  The `info registers'
91
command shows the canonical names.  For example, on the SPARC, `info
92
registers' displays the processor status register as `$psr' but you can
93
also refer to it as `$ps'; and on x86-based machines `$ps' is an alias
94
for the EFLAGS register.
95
 
96
   GDB always considers the contents of an ordinary register as an
97
integer when the register is examined in this way.  Some machines have
98
special registers which can hold nothing but floating point; these
99
registers are considered to have floating point values.  There is no way
100
to refer to the contents of an ordinary register as floating point value
101
(although you can _print_ it as a floating point value with `print/f
102
$REGNAME').
103
 
104
   Some registers have distinct "raw" and "virtual" data formats.  This
105
means that the data format in which the register contents are saved by
106
the operating system is not the same one that your program normally
107
sees.  For example, the registers of the 68881 floating point
108
coprocessor are always saved in "extended" (raw) format, but all C
109
programs expect to work with "double" (virtual) format.  In such cases,
110
GDB normally works with the virtual format only (the format that makes
111
sense for your program), but the `info registers' command prints the
112
data in both formats.
113
 
114
   Some machines have special registers whose contents can be
115
interpreted in several different ways.  For example, modern x86-based
116
machines have SSE and MMX registers that can hold several values packed
117
together in several different formats.  GDB refers to such registers in
118
`struct' notation:
119
 
120
     (gdb) print $xmm1
121
     $1 = {
122
       v4_float = {0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044},
123
       v2_double = {9.92129282474342e-303, 2.7585945287983262e-313},
124
       v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
125
       v8_int16 = {0, 0, 14072, 315, 11, 0, 13, 0},
126
       v4_int32 = {0, 20657912, 11, 13},
127
       v2_int64 = {88725056443645952, 55834574859},
128
       uint128 = 0x0000000d0000000b013b36f800000000
129
     }
130
 
131
To set values of such registers, you need to tell GDB which view of the
132
register you wish to change, as if you were assigning value to a
133
`struct' member:
134
 
135
      (gdb) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
136
 
137
   Normally, register values are relative to the selected stack frame
138
(*note Selecting a Frame: Selection.).  This means that you get the
139
value that the register would contain if all stack frames farther in
140
were exited and their saved registers restored.  In order to see the
141
true contents of hardware registers, you must select the innermost
142
frame (with `frame 0').
143
 
144
   However, GDB must deduce where registers are saved, from the machine
145
code generated by your compiler.  If some registers are not saved, or if
146
GDB is unable to locate the saved registers, the selected stack frame
147
makes no difference.
148
 
149
   ---------- Footnotes ----------
150
 
151
   (1) This is a way of removing one word from the stack, on machines
152
where stacks grow downward in memory (most machines, nowadays).  This
153
assumes that the innermost stack frame is selected; setting `$sp' is
154
not allowed when other stack frames are selected.  To pop entire frames
155
off the stack, regardless of machine architecture, use `return'; see
156
*Note Returning from a Function: Returning.
157
 
158

159
File: gdb.info,  Node: Floating Point Hardware,  Next: Vector Unit,  Prev: Registers,  Up: Data
160
 
161
10.13 Floating Point Hardware
162
=============================
163
 
164
Depending on the configuration, GDB may be able to give you more
165
information about the status of the floating point hardware.
166
 
167
`info float'
168
     Display hardware-dependent information about the floating point
169
     unit.  The exact contents and layout vary depending on the
170
     floating point chip.  Currently, `info float' is supported on the
171
     ARM and x86 machines.
172
 
173

174
File: gdb.info,  Node: Vector Unit,  Next: OS Information,  Prev: Floating Point Hardware,  Up: Data
175
 
176
10.14 Vector Unit
177
=================
178
 
179
Depending on the configuration, GDB may be able to give you more
180
information about the status of the vector unit.
181
 
182
`info vector'
183
     Display information about the vector unit.  The exact contents and
184
     layout vary depending on the hardware.
185
 
186

187
File: gdb.info,  Node: OS Information,  Next: Memory Region Attributes,  Prev: Vector Unit,  Up: Data
188
 
189
10.15 Operating System Auxiliary Information
190
============================================
191
 
192
GDB provides interfaces to useful OS facilities that can help you debug
193
your program.
194
 
195
   When GDB runs on a "Posix system" (such as GNU or Unix machines), it
196
interfaces with the inferior via the `ptrace' system call.  The
197
operating system creates a special sata structure, called `struct
198
user', for this interface.  You can use the command `info udot' to
199
display the contents of this data structure.
200
 
201
`info udot'
202
     Display the contents of the `struct user' maintained by the OS
203
     kernel for the program being debugged.  GDB displays the contents
204
     of `struct user' as a list of hex numbers, similar to the
205
     `examine' command.
206
 
207
   Some operating systems supply an "auxiliary vector" to programs at
208
startup.  This is akin to the arguments and environment that you
209
specify for a program, but contains a system-dependent variety of
210
binary values that tell system libraries important details about the
211
hardware, operating system, and process.  Each value's purpose is
212
identified by an integer tag; the meanings are well-known but
213
system-specific.  Depending on the configuration and operating system
214
facilities, GDB may be able to show you this information.  For remote
215
targets, this functionality may further depend on the remote stub's
216
support of the `qXfer:auxv:read' packet, see *Note qXfer auxiliary
217
vector read::.
218
 
219
`info auxv'
220
     Display the auxiliary vector of the inferior, which can be either a
221
     live process or a core dump file.  GDB prints each tag value
222
     numerically, and also shows names and text descriptions for
223
     recognized tags.  Some values in the vector are numbers, some bit
224
     masks, and some pointers to strings or other data.  GDB displays
225
     each value in the most appropriate form for a recognized tag, and
226
     in hexadecimal for an unrecognized tag.
227
 
228
   On some targets, GDB can access operating-system-specific information
229
and display it to user, without interpretation.  For remote targets,
230
this functionality depends on the remote stub's support of the
231
`qXfer:osdata:read' packet, see *Note qXfer osdata read::.
232
 
233
`info os'
234
     List the types of OS information available for the target.  If the
235
     target does not return a list of possible types, this command will
236
     report an error.
237
 
238
`info os processes'
239
     Display the list of processes on the target.  For each process,
240
     GDB prints the process identifier, the name of the user, and the
241
     command corresponding to the process.
242
 
243

244
File: gdb.info,  Node: Memory Region Attributes,  Next: Dump/Restore Files,  Prev: OS Information,  Up: Data
245
 
246
10.16 Memory Region Attributes
247
==============================
248
 
249
"Memory region attributes" allow you to describe special handling
250
required by regions of your target's memory.  GDB uses attributes to
251
determine whether to allow certain types of memory accesses; whether to
252
use specific width accesses; and whether to cache target memory.  By
253
default the description of memory regions is fetched from the target
254
(if the current target supports this), but the user can override the
255
fetched regions.
256
 
257
   Defined memory regions can be individually enabled and disabled.
258
When a memory region is disabled, GDB uses the default attributes when
259
accessing memory in that region.  Similarly, if no memory regions have
260
been defined, GDB uses the default attributes when accessing all memory.
261
 
262
   When a memory region is defined, it is given a number to identify it;
263
to enable, disable, or remove a memory region, you specify that number.
264
 
265
`mem LOWER UPPER ATTRIBUTES...'
266
     Define a memory region bounded by LOWER and UPPER with attributes
267
     ATTRIBUTES..., and add it to the list of regions monitored by GDB.
268
     Note that UPPER == 0 is a special case: it is treated as the
269
     target's maximum memory address.  (0xffff on 16 bit targets,
270
     0xffffffff on 32 bit targets, etc.)
271
 
272
`mem auto'
273
     Discard any user changes to the memory regions and use
274
     target-supplied regions, if available, or no regions if the target
275
     does not support.
276
 
277
`delete mem NUMS...'
278
     Remove memory regions NUMS... from the list of regions monitored
279
     by GDB.
280
 
281
`disable mem NUMS...'
282
     Disable monitoring of memory regions NUMS....  A disabled memory
283
     region is not forgotten.  It may be enabled again later.
284
 
285
`enable mem NUMS...'
286
     Enable monitoring of memory regions NUMS....
287
 
288
`info mem'
289
     Print a table of all defined memory regions, with the following
290
     columns for each region:
291
 
292
    _Memory Region Number_
293
 
294
    _Enabled or Disabled._
295
          Enabled memory regions are marked with `y'.  Disabled memory
296
          regions are marked with `n'.
297
 
298
    _Lo Address_
299
          The address defining the inclusive lower bound of the memory
300
          region.
301
 
302
    _Hi Address_
303
          The address defining the exclusive upper bound of the memory
304
          region.
305
 
306
    _Attributes_
307
          The list of attributes set for this memory region.
308
 
309
10.16.1 Attributes
310
------------------
311
 
312
10.16.1.1 Memory Access Mode
313
............................
314
 
315
The access mode attributes set whether GDB may make read or write
316
accesses to a memory region.
317
 
318
   While these attributes prevent GDB from performing invalid memory
319
accesses, they do nothing to prevent the target system, I/O DMA, etc.
320
from accessing memory.
321
 
322
`ro'
323
     Memory is read only.
324
 
325
`wo'
326
     Memory is write only.
327
 
328
`rw'
329
     Memory is read/write.  This is the default.
330
 
331
10.16.1.2 Memory Access Size
332
............................
333
 
334
The access size attribute tells GDB to use specific sized accesses in
335
the memory region.  Often memory mapped device registers require
336
specific sized accesses.  If no access size attribute is specified, GDB
337
may use accesses of any size.
338
 
339
`8'
340
     Use 8 bit memory accesses.
341
 
342
`16'
343
     Use 16 bit memory accesses.
344
 
345
`32'
346
     Use 32 bit memory accesses.
347
 
348
`64'
349
     Use 64 bit memory accesses.
350
 
351
10.16.1.3 Data Cache
352
....................
353
 
354
The data cache attributes set whether GDB will cache target memory.
355
While this generally improves performance by reducing debug protocol
356
overhead, it can lead to incorrect results because GDB does not know
357
about volatile variables or memory mapped device registers.
358
 
359
`cache'
360
     Enable GDB to cache target memory.
361
 
362
`nocache'
363
     Disable GDB from caching target memory.  This is the default.
364
 
365
10.16.2 Memory Access Checking
366
------------------------------
367
 
368
GDB can be instructed to refuse accesses to memory that is not
369
explicitly described.  This can be useful if accessing such regions has
370
undesired effects for a specific target, or to provide better error
371
checking.  The following commands control this behaviour.
372
 
373
`set mem inaccessible-by-default [on|off]'
374
     If `on' is specified, make  GDB treat memory not explicitly
375
     described by the memory ranges as non-existent and refuse accesses
376
     to such memory.  The checks are only performed if there's at least
377
     one memory range defined.  If `off' is specified, make GDB treat
378
     the memory not explicitly described by the memory ranges as RAM.
379
     The default value is `on'.
380
 
381
`show mem inaccessible-by-default'
382
     Show the current handling of accesses to unknown memory.
383
 
384

385
File: gdb.info,  Node: Dump/Restore Files,  Next: Core File Generation,  Prev: Memory Region Attributes,  Up: Data
386
 
387
10.17 Copy Between Memory and a File
388
====================================
389
 
390
You can use the commands `dump', `append', and `restore' to copy data
391
between target memory and a file.  The `dump' and `append' commands
392
write data to a file, and the `restore' command reads data from a file
393
back into the inferior's memory.  Files may be in binary, Motorola
394
S-record, Intel hex, or Tektronix Hex format; however, GDB can only
395
append to binary files.
396
 
397
`dump [FORMAT] memory FILENAME START_ADDR END_ADDR'
398
`dump [FORMAT] value FILENAME EXPR'
399
     Dump the contents of memory from START_ADDR to END_ADDR, or the
400
     value of EXPR, to FILENAME in the given format.
401
 
402
     The FORMAT parameter may be any one of:
403
    `binary'
404
          Raw binary form.
405
 
406
    `ihex'
407
          Intel hex format.
408
 
409
    `srec'
410
          Motorola S-record format.
411
 
412
    `tekhex'
413
          Tektronix Hex format.
414
 
415
     GDB uses the same definitions of these formats as the GNU binary
416
     utilities, like `objdump' and `objcopy'.  If FORMAT is omitted,
417
     GDB dumps the data in raw binary form.
418
 
419
`append [binary] memory FILENAME START_ADDR END_ADDR'
420
`append [binary] value FILENAME EXPR'
421
     Append the contents of memory from START_ADDR to END_ADDR, or the
422
     value of EXPR, to the file FILENAME, in raw binary form.  (GDB can
423
     only append data to files in raw binary form.)
424
 
425
`restore FILENAME [binary] BIAS START END'
426
     Restore the contents of file FILENAME into memory.  The `restore'
427
     command can automatically recognize any known BFD file format,
428
     except for raw binary.  To restore a raw binary file you must
429
     specify the optional keyword `binary' after the filename.
430
 
431
     If BIAS is non-zero, its value will be added to the addresses
432
     contained in the file.  Binary files always start at address zero,
433
     so they will be restored at address BIAS.  Other bfd files have a
434
     built-in location; they will be restored at offset BIAS from that
435
     location.
436
 
437
     If START and/or END are non-zero, then only data between file
438
     offset START and file offset END will be restored.  These offsets
439
     are relative to the addresses in the file, before the BIAS
440
     argument is applied.
441
 
442
 
443

444
File: gdb.info,  Node: Core File Generation,  Next: Character Sets,  Prev: Dump/Restore Files,  Up: Data
445
 
446
10.18 How to Produce a Core File from Your Program
447
==================================================
448
 
449
A "core file" or "core dump" is a file that records the memory image of
450
a running process and its process status (register values etc.).  Its
451
primary use is post-mortem debugging of a program that crashed while it
452
ran outside a debugger.  A program that crashes automatically produces
453
a core file, unless this feature is disabled by the user.  *Note
454
Files::, for information on invoking GDB in the post-mortem debugging
455
mode.
456
 
457
   Occasionally, you may wish to produce a core file of the program you
458
are debugging in order to preserve a snapshot of its state.  GDB has a
459
special command for that.
460
 
461
`generate-core-file [FILE]'
462
`gcore [FILE]'
463
     Produce a core dump of the inferior process.  The optional argument
464
     FILE specifies the file name where to put the core dump.  If not
465
     specified, the file name defaults to `core.PID', where PID is the
466
     inferior process ID.
467
 
468
     Note that this command is implemented only for some systems (as of
469
     this writing, GNU/Linux, FreeBSD, Solaris, Unixware, and S390).
470
 
471

472
File: gdb.info,  Node: Character Sets,  Next: Caching Remote Data,  Prev: Core File Generation,  Up: Data
473
 
474
10.19 Character Sets
475
====================
476
 
477
If the program you are debugging uses a different character set to
478
represent characters and strings than the one GDB uses itself, GDB can
479
automatically translate between the character sets for you.  The
480
character set GDB uses we call the "host character set"; the one the
481
inferior program uses we call the "target character set".
482
 
483
   For example, if you are running GDB on a GNU/Linux system, which
484
uses the ISO Latin 1 character set, but you are using GDB's remote
485
protocol (*note Remote Debugging::) to debug a program running on an
486
IBM mainframe, which uses the EBCDIC character set, then the host
487
character set is Latin-1, and the target character set is EBCDIC.  If
488
you give GDB the command `set target-charset EBCDIC-US', then GDB
489
translates between EBCDIC and Latin 1 as you print character or string
490
values, or use character and string literals in expressions.
491
 
492
   GDB has no way to automatically recognize which character set the
493
inferior program uses; you must tell it, using the `set target-charset'
494
command, described below.
495
 
496
   Here are the commands for controlling GDB's character set support:
497
 
498
`set target-charset CHARSET'
499
     Set the current target character set to CHARSET.  To display the
500
     list of supported target character sets, type
501
     `set target-charset '.
502
 
503
`set host-charset CHARSET'
504
     Set the current host character set to CHARSET.
505
 
506
     By default, GDB uses a host character set appropriate to the
507
     system it is running on; you can override that default using the
508
     `set host-charset' command.  On some systems, GDB cannot
509
     automatically determine the appropriate host character set.  In
510
     this case, GDB uses `UTF-8'.
511
 
512
     GDB can only use certain character sets as its host character set.
513
     If you type `set target-charset ', GDB will list the
514
     host character sets it supports.
515
 
516
`set charset CHARSET'
517
     Set the current host and target character sets to CHARSET.  As
518
     above, if you type `set charset ', GDB will list the
519
     names of the character sets that can be used for both host and
520
     target.
521
 
522
`show charset'
523
     Show the names of the current host and target character sets.
524
 
525
`show host-charset'
526
     Show the name of the current host character set.
527
 
528
`show target-charset'
529
     Show the name of the current target character set.
530
 
531
`set target-wide-charset CHARSET'
532
     Set the current target's wide character set to CHARSET.  This is
533
     the character set used by the target's `wchar_t' type.  To display
534
     the list of supported wide character sets, type
535
     `set target-wide-charset '.
536
 
537
`show target-wide-charset'
538
     Show the name of the current target's wide character set.
539
 
540
   Here is an example of GDB's character set support in action.  Assume
541
that the following source code has been placed in the file
542
`charset-test.c':
543
 
544
     #include 
545
 
546
     char ascii_hello[]
547
       = {72, 101, 108, 108, 111, 44, 32, 119,
548
          111, 114, 108, 100, 33, 10, 0};
549
     char ibm1047_hello[]
550
       = {200, 133, 147, 147, 150, 107, 64, 166,
551
          150, 153, 147, 132, 90, 37, 0};
552
 
553
     main ()
554
     {
555
       printf ("Hello, world!\n");
556
     }
557
 
558
   In this program, `ascii_hello' and `ibm1047_hello' are arrays
559
containing the string `Hello, world!' followed by a newline, encoded in
560
the ASCII and IBM1047 character sets.
561
 
562
   We compile the program, and invoke the debugger on it:
563
 
564
     $ gcc -g charset-test.c -o charset-test
565
     $ gdb -nw charset-test
566
     GNU gdb 2001-12-19-cvs
567
     Copyright 2001 Free Software Foundation, Inc.
568
     ...
569
     (gdb)
570
 
571
   We can use the `show charset' command to see what character sets GDB
572
is currently using to interpret and display characters and strings:
573
 
574
     (gdb) show charset
575
     The current host and target character set is `ISO-8859-1'.
576
     (gdb)
577
 
578
   For the sake of printing this manual, let's use ASCII as our initial
579
character set:
580
     (gdb) set charset ASCII
581
     (gdb) show charset
582
     The current host and target character set is `ASCII'.
583
     (gdb)
584
 
585
   Let's assume that ASCII is indeed the correct character set for our
586
host system -- in other words, let's assume that if GDB prints
587
characters using the ASCII character set, our terminal will display
588
them properly.  Since our current target character set is also ASCII,
589
the contents of `ascii_hello' print legibly:
590
 
591
     (gdb) print ascii_hello
592
     $1 = 0x401698 "Hello, world!\n"
593
     (gdb) print ascii_hello[0]
594
     $2 = 72 'H'
595
     (gdb)
596
 
597
   GDB uses the target character set for character and string literals
598
you use in expressions:
599
 
600
     (gdb) print '+'
601
     $3 = 43 '+'
602
     (gdb)
603
 
604
   The ASCII character set uses the number 43 to encode the `+'
605
character.
606
 
607
   GDB relies on the user to tell it which character set the target
608
program uses.  If we print `ibm1047_hello' while our target character
609
set is still ASCII, we get jibberish:
610
 
611
     (gdb) print ibm1047_hello
612
     $4 = 0x4016a8 "\310\205\223\223\226k@\246\226\231\223\204Z%"
613
     (gdb) print ibm1047_hello[0]
614
     $5 = 200 '\310'
615
     (gdb)
616
 
617
   If we invoke the `set target-charset' followed by , GDB
618
tells us the character sets it supports:
619
 
620
     (gdb) set target-charset
621
     ASCII       EBCDIC-US   IBM1047     ISO-8859-1
622
     (gdb) set target-charset
623
 
624
   We can select IBM1047 as our target character set, and examine the
625
program's strings again.  Now the ASCII string is wrong, but GDB
626
translates the contents of `ibm1047_hello' from the target character
627
set, IBM1047, to the host character set, ASCII, and they display
628
correctly:
629
 
630
     (gdb) set target-charset IBM1047
631
     (gdb) show charset
632
     The current host character set is `ASCII'.
633
     The current target character set is `IBM1047'.
634
     (gdb) print ascii_hello
635
     $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
636
     (gdb) print ascii_hello[0]
637
     $7 = 72 '\110'
638
     (gdb) print ibm1047_hello
639
     $8 = 0x4016a8 "Hello, world!\n"
640
     (gdb) print ibm1047_hello[0]
641
     $9 = 200 'H'
642
     (gdb)
643
 
644
   As above, GDB uses the target character set for character and string
645
literals you use in expressions:
646
 
647
     (gdb) print '+'
648
     $10 = 78 '+'
649
     (gdb)
650
 
651
   The IBM1047 character set uses the number 78 to encode the `+'
652
character.
653
 
654

655
File: gdb.info,  Node: Caching Remote Data,  Next: Searching Memory,  Prev: Character Sets,  Up: Data
656
 
657
10.20 Caching Data of Remote Targets
658
====================================
659
 
660
GDB caches data exchanged between the debugger and a remote target
661
(*note Remote Debugging::).  Such caching generally improves
662
performance, because it reduces the overhead of the remote protocol by
663
bundling memory reads and writes into large chunks.  Unfortunately,
664
simply caching everything would lead to incorrect results, since GDB
665
does not necessarily know anything about volatile values, memory-mapped
666
I/O addresses, etc.  Furthermore, in non-stop mode (*note Non-Stop
667
Mode::) memory can be changed _while_ a gdb command is executing.
668
Therefore, by default, GDB only caches data known to be on the stack(1).
669
Other regions of memory can be explicitly marked as cacheable; see
670
*note Memory Region Attributes::.
671
 
672
`set remotecache on'
673
`set remotecache off'
674
     This option no longer does anything; it exists for compatibility
675
     with old scripts.
676
 
677
`show remotecache'
678
     Show the current state of the obsolete remotecache flag.
679
 
680
`set stack-cache on'
681
`set stack-cache off'
682
     Enable or disable caching of stack accesses.  When `ON', use
683
     caching.  By default, this option is `ON'.
684
 
685
`show stack-cache'
686
     Show the current state of data caching for memory accesses.
687
 
688
`info dcache [line]'
689
     Print the information about the data cache performance.  The
690
     information displayed includes the dcache width and depth, and for
691
     each cache line, its number, address, and how many times it was
692
     referenced.  This command is useful for debugging the data cache
693
     operation.
694
 
695
     If a line number is specified, the contents of that line will be
696
     printed in hex.
697
 
698
   ---------- Footnotes ----------
699
 
700
   (1) In non-stop mode, it is moderately rare for a running thread to
701
modify the stack of a stopped thread in a way that would interfere with
702
a backtrace, and caching of stack reads provides a significant speed up
703
of remote backtraces.
704
 
705

706
File: gdb.info,  Node: Searching Memory,  Prev: Caching Remote Data,  Up: Data
707
 
708
10.21 Search Memory
709
===================
710
 
711
Memory can be searched for a particular sequence of bytes with the
712
`find' command.
713
 
714
`find [/SN] START_ADDR, +LEN, VAL1 [, VAL2, ...]'
715
`find [/SN] START_ADDR, END_ADDR, VAL1 [, VAL2, ...]'
716
     Search memory for the sequence of bytes specified by VAL1, VAL2,
717
     etc.  The search begins at address START_ADDR and continues for
718
     either LEN bytes or through to END_ADDR inclusive.
719
 
720
   S and N are optional parameters.  They may be specified in either
721
order, apart or together.
722
 
723
S, search query size
724
     The size of each search query value.
725
 
726
    `b'
727
          bytes
728
 
729
    `h'
730
          halfwords (two bytes)
731
 
732
    `w'
733
          words (four bytes)
734
 
735
    `g'
736
          giant words (eight bytes)
737
 
738
     All values are interpreted in the current language.  This means,
739
     for example, that if the current source language is C/C++ then
740
     searching for the string "hello" includes the trailing '\0'.
741
 
742
     If the value size is not specified, it is taken from the value's
743
     type in the current language.  This is useful when one wants to
744
     specify the search pattern as a mixture of types.  Note that this
745
     means, for example, that in the case of C-like languages a search
746
     for an untyped 0x42 will search for `(int) 0x42' which is
747
     typically four bytes.
748
 
749
N, maximum number of finds
750
     The maximum number of matches to print.  The default is to print
751
     all finds.
752
 
753
   You can use strings as search values.  Quote them with double-quotes
754
(`"').  The string value is copied into the search pattern byte by
755
byte, regardless of the endianness of the target and the size
756
specification.
757
 
758
   The address of each match found is printed as well as a count of the
759
number of matches found.
760
 
761
   The address of the last value found is stored in convenience variable
762
`$_'.  A count of the number of matches is stored in `$numfound'.
763
 
764
   For example, if stopped at the `printf' in this function:
765
 
766
     void
767
     hello ()
768
     {
769
       static char hello[] = "hello-hello";
770
       static struct { char c; short s; int i; }
771
         __attribute__ ((packed)) mixed
772
         = { 'c', 0x1234, 0x87654321 };
773
       printf ("%s\n", hello);
774
     }
775
 
776
you get during debugging:
777
 
778
     (gdb) find &hello[0], +sizeof(hello), "hello"
779
     0x804956d 
780
     1 pattern found
781
     (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
782
     0x8049567 
783
     0x804956d 
784
     2 patterns found
785
     (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
786
     0x8049567 
787
     1 pattern found
788
     (gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
789
     0x8049560 
790
     1 pattern found
791
     (gdb) print $numfound
792
     $1 = 1
793
     (gdb) print $_
794
     $2 = (void *) 0x8049560
795
 
796

797
File: gdb.info,  Node: Optimized Code,  Next: Macros,  Prev: Data,  Up: Top
798
 
799
11 Debugging Optimized Code
800
***************************
801
 
802
Almost all compilers support optimization.  With optimization disabled,
803
the compiler generates assembly code that corresponds directly to your
804
source code, in a simplistic way.  As the compiler applies more
805
powerful optimizations, the generated assembly code diverges from your
806
original source code.  With help from debugging information generated
807
by the compiler, GDB can map from the running program back to
808
constructs from your original source.
809
 
810
   GDB is more accurate with optimization disabled.  If you can
811
recompile without optimization, it is easier to follow the progress of
812
your program during debugging.  But, there are many cases where you may
813
need to debug an optimized version.
814
 
815
   When you debug a program compiled with `-g -O', remember that the
816
optimizer has rearranged your code; the debugger shows you what is
817
really there.  Do not be too surprised when the execution path does not
818
exactly match your source file!  An extreme example: if you define a
819
variable, but never use it, GDB never sees that variable--because the
820
compiler optimizes it out of existence.
821
 
822
   Some things do not work as well with `-g -O' as with just `-g',
823
particularly on machines with instruction scheduling.  If in doubt,
824
recompile with `-g' alone, and if this fixes the problem, please report
825
it to us as a bug (including a test case!).  *Note Variables::, for
826
more information about debugging optimized code.
827
 
828
* Menu:
829
 
830
* Inline Functions::            How GDB presents inlining
831
 
832

833
File: gdb.info,  Node: Inline Functions,  Up: Optimized Code
834
 
835
11.1 Inline Functions
836
=====================
837
 
838
"Inlining" is an optimization that inserts a copy of the function body
839
directly at each call site, instead of jumping to a shared routine.
840
GDB displays inlined functions just like non-inlined functions.  They
841
appear in backtraces.  You can view their arguments and local
842
variables, step into them with `step', skip them with `next', and
843
escape from them with `finish'.  You can check whether a function was
844
inlined by using the `info frame' command.
845
 
846
   For GDB to support inlined functions, the compiler must record
847
information about inlining in the debug information -- GCC using the
848
DWARF 2 format does this, and several other compilers do also.  GDB
849
only supports inlined functions when using DWARF 2.  Versions of GCC
850
before 4.1 do not emit two required attributes (`DW_AT_call_file' and
851
`DW_AT_call_line'); GDB does not display inlined function calls with
852
earlier versions of GCC.  It instead displays the arguments and local
853
variables of inlined functions as local variables in the caller.
854
 
855
   The body of an inlined function is directly included at its call
856
site; unlike a non-inlined function, there are no instructions devoted
857
to the call.  GDB still pretends that the call site and the start of
858
the inlined function are different instructions.  Stepping to the call
859
site shows the call site, and then stepping again shows the first line
860
of the inlined function, even though no additional instructions are
861
executed.
862
 
863
   This makes source-level debugging much clearer; you can see both the
864
context of the call and then the effect of the call.  Only stepping by
865
a single instruction using `stepi' or `nexti' does not do this; single
866
instruction steps always show the inlined body.
867
 
868
   There are some ways that GDB does not pretend that inlined function
869
calls are the same as normal calls:
870
 
871
   * You cannot set breakpoints on inlined functions.  GDB either
872
     reports that there is no symbol with that name, or else sets the
873
     breakpoint only on non-inlined copies of the function.  This
874
     limitation will be removed in a future version of GDB; until then,
875
     set a breakpoint by line number on the first line of the inlined
876
     function instead.
877
 
878
   * Setting breakpoints at the call site of an inlined function may not
879
     work, because the call site does not contain any code.  GDB may
880
     incorrectly move the breakpoint to the next line of the enclosing
881
     function, after the call.  This limitation will be removed in a
882
     future version of GDB; until then, set a breakpoint on an earlier
883
     line or inside the inlined function instead.
884
 
885
   * GDB cannot locate the return value of inlined calls after using
886
     the `finish' command.  This is a limitation of compiler-generated
887
     debugging information; after `finish', you can step to the next
888
     line and print a variable where your program stored the return
889
     value.
890
 
891
 
892

893
File: gdb.info,  Node: Macros,  Next: Tracepoints,  Prev: Optimized Code,  Up: Top
894
 
895
12 C Preprocessor Macros
896
************************
897
 
898
Some languages, such as C and C++, provide a way to define and invoke
899
"preprocessor macros" which expand into strings of tokens.  GDB can
900
evaluate expressions containing macro invocations, show the result of
901
macro expansion, and show a macro's definition, including where it was
902
defined.
903
 
904
   You may need to compile your program specially to provide GDB with
905
information about preprocessor macros.  Most compilers do not include
906
macros in their debugging information, even when you compile with the
907
`-g' flag.  *Note Compilation::.
908
 
909
   A program may define a macro at one point, remove that definition
910
later, and then provide a different definition after that.  Thus, at
911
different points in the program, a macro may have different
912
definitions, or have no definition at all.  If there is a current stack
913
frame, GDB uses the macros in scope at that frame's source code line.
914
Otherwise, GDB uses the macros in scope at the current listing location;
915
see *Note List::.
916
 
917
   Whenever GDB evaluates an expression, it always expands any macro
918
invocations present in the expression.  GDB also provides the following
919
commands for working with macros explicitly.
920
 
921
`macro expand EXPRESSION'
922
`macro exp EXPRESSION'
923
     Show the results of expanding all preprocessor macro invocations in
924
     EXPRESSION.  Since GDB simply expands macros, but does not parse
925
     the result, EXPRESSION need not be a valid expression; it can be
926
     any string of tokens.
927
 
928
`macro expand-once EXPRESSION'
929
`macro exp1 EXPRESSION'
930
     (This command is not yet implemented.)  Show the results of
931
     expanding those preprocessor macro invocations that appear
932
     explicitly in EXPRESSION.  Macro invocations appearing in that
933
     expansion are left unchanged.  This command allows you to see the
934
     effect of a particular macro more clearly, without being confused
935
     by further expansions.  Since GDB simply expands macros, but does
936
     not parse the result, EXPRESSION need not be a valid expression; it
937
     can be any string of tokens.
938
 
939
`info macro MACRO'
940
     Show the definition of the macro named MACRO, and describe the
941
     source location or compiler command-line where that definition was
942
     established.
943
 
944
`macro define MACRO REPLACEMENT-LIST'
945
`macro define MACRO(ARGLIST) REPLACEMENT-LIST'
946
     Introduce a definition for a preprocessor macro named MACRO,
947
     invocations of which are replaced by the tokens given in
948
     REPLACEMENT-LIST.  The first form of this command defines an
949
     "object-like" macro, which takes no arguments; the second form
950
     defines a "function-like" macro, which takes the arguments given in
951
     ARGLIST.
952
 
953
     A definition introduced by this command is in scope in every
954
     expression evaluated in GDB, until it is removed with the `macro
955
     undef' command, described below.  The definition overrides all
956
     definitions for MACRO present in the program being debugged, as
957
     well as any previous user-supplied definition.
958
 
959
`macro undef MACRO'
960
     Remove any user-supplied definition for the macro named MACRO.
961
     This command only affects definitions provided with the `macro
962
     define' command, described above; it cannot remove definitions
963
     present in the program being debugged.
964
 
965
`macro list'
966
     List all the macros defined using the `macro define' command.
967
 
968
   Here is a transcript showing the above commands in action.  First, we
969
show our source files:
970
 
971
     $ cat sample.c
972
     #include 
973
     #include "sample.h"
974
 
975
     #define M 42
976
     #define ADD(x) (M + x)
977
 
978
     main ()
979
     {
980
     #define N 28
981
       printf ("Hello, world!\n");
982
     #undef N
983
       printf ("We're so creative.\n");
984
     #define N 1729
985
       printf ("Goodbye, world!\n");
986
     }
987
     $ cat sample.h
988
     #define Q <
989
     $
990
 
991
   Now, we compile the program using the GNU C compiler, GCC.  We pass
992
the `-gdwarf-2' and `-g3' flags to ensure the compiler includes
993
information about preprocessor macros in the debugging information.
994
 
995
     $ gcc -gdwarf-2 -g3 sample.c -o sample
996
     $
997
 
998
   Now, we start GDB on our sample program:
999
 
1000
     $ gdb -nw sample
1001
     GNU gdb 2002-05-06-cvs
1002
     Copyright 2002 Free Software Foundation, Inc.
1003
     GDB is free software, ...
1004
     (gdb)
1005
 
1006
   We can expand macros and examine their definitions, even when the
1007
program is not running.  GDB uses the current listing position to
1008
decide which macro definitions are in scope:
1009
 
1010
     (gdb) list main
1011
     3
1012
     4       #define M 42
1013
     5       #define ADD(x) (M + x)
1014
     6
1015
     7       main ()
1016
     8       {
1017
     9       #define N 28
1018
     10        printf ("Hello, world!\n");
1019
     11      #undef N
1020
     12        printf ("We're so creative.\n");
1021
     (gdb) info macro ADD
1022
     Defined at /home/jimb/gdb/macros/play/sample.c:5
1023
     #define ADD(x) (M + x)
1024
     (gdb) info macro Q
1025
     Defined at /home/jimb/gdb/macros/play/sample.h:1
1026
       included at /home/jimb/gdb/macros/play/sample.c:2
1027
     #define Q <
1028
     (gdb) macro expand ADD(1)
1029
     expands to: (42 + 1)
1030
     (gdb) macro expand-once ADD(1)
1031
     expands to: once (M + 1)
1032
     (gdb)
1033
 
1034
   In the example above, note that `macro expand-once' expands only the
1035
macro invocation explicit in the original text -- the invocation of
1036
`ADD' -- but does not expand the invocation of the macro `M', which was
1037
introduced by `ADD'.
1038
 
1039
   Once the program is running, GDB uses the macro definitions in force
1040
at the source line of the current stack frame:
1041
 
1042
     (gdb) break main
1043
     Breakpoint 1 at 0x8048370: file sample.c, line 10.
1044
     (gdb) run
1045
     Starting program: /home/jimb/gdb/macros/play/sample
1046
 
1047
     Breakpoint 1, main () at sample.c:10
1048
     10        printf ("Hello, world!\n");
1049
     (gdb)
1050
 
1051
   At line 10, the definition of the macro `N' at line 9 is in force:
1052
 
1053
     (gdb) info macro N
1054
     Defined at /home/jimb/gdb/macros/play/sample.c:9
1055
     #define N 28
1056
     (gdb) macro expand N Q M
1057
     expands to: 28 < 42
1058
     (gdb) print N Q M
1059
     $1 = 1
1060
     (gdb)
1061
 
1062
   As we step over directives that remove `N''s definition, and then
1063
give it a new definition, GDB finds the definition (or lack thereof) in
1064
force at each point:
1065
 
1066
     (gdb) next
1067
     Hello, world!
1068
     12        printf ("We're so creative.\n");
1069
     (gdb) info macro N
1070
     The symbol `N' has no definition as a C/C++ preprocessor macro
1071
     at /home/jimb/gdb/macros/play/sample.c:12
1072
     (gdb) next
1073
     We're so creative.
1074
     14        printf ("Goodbye, world!\n");
1075
     (gdb) info macro N
1076
     Defined at /home/jimb/gdb/macros/play/sample.c:13
1077
     #define N 1729
1078
     (gdb) macro expand N Q M
1079
     expands to: 1729 < 42
1080
     (gdb) print N Q M
1081
     $2 = 0
1082
     (gdb)
1083
 
1084
   In addition to source files, macros can be defined on the
1085
compilation command line using the `-DNAME=VALUE' syntax.  For macros
1086
defined in such a way, GDB displays the location of their definition as
1087
line zero of the source file submitted to the compiler.
1088
 
1089
     (gdb) info macro __STDC__
1090
     Defined at /home/jimb/gdb/macros/play/sample.c:0
1091
     -D__STDC__=1
1092
     (gdb)
1093
 
1094

1095
File: gdb.info,  Node: Tracepoints,  Next: Overlays,  Prev: Macros,  Up: Top
1096
 
1097
13 Tracepoints
1098
**************
1099
 
1100
In some applications, it is not feasible for the debugger to interrupt
1101
the program's execution long enough for the developer to learn anything
1102
helpful about its behavior.  If the program's correctness depends on
1103
its real-time behavior, delays introduced by a debugger might cause the
1104
program to change its behavior drastically, or perhaps fail, even when
1105
the code itself is correct.  It is useful to be able to observe the
1106
program's behavior without interrupting it.
1107
 
1108
   Using GDB's `trace' and `collect' commands, you can specify
1109
locations in the program, called "tracepoints", and arbitrary
1110
expressions to evaluate when those tracepoints are reached.  Later,
1111
using the `tfind' command, you can examine the values those expressions
1112
had when the program hit the tracepoints.  The expressions may also
1113
denote objects in memory--structures or arrays, for example--whose
1114
values GDB should record; while visiting a particular tracepoint, you
1115
may inspect those objects as if they were in memory at that moment.
1116
However, because GDB records these values without interacting with you,
1117
it can do so quickly and unobtrusively, hopefully not disturbing the
1118
program's behavior.
1119
 
1120
   The tracepoint facility is currently available only for remote
1121
targets.  *Note Targets::.  In addition, your remote target must know
1122
how to collect trace data.  This functionality is implemented in the
1123
remote stub; however, none of the stubs distributed with GDB support
1124
tracepoints as of this writing.  The format of the remote packets used
1125
to implement tracepoints are described in *Note Tracepoint Packets::.
1126
 
1127
   It is also possible to get trace data from a file, in a manner
1128
reminiscent of corefiles; you specify the filename, and use `tfind' to
1129
search through the file.  *Note Trace Files::, for more details.
1130
 
1131
   This chapter describes the tracepoint commands and features.
1132
 
1133
* Menu:
1134
 
1135
* Set Tracepoints::
1136
* Analyze Collected Data::
1137
* Tracepoint Variables::
1138
* Trace Files::
1139
 
1140

1141
File: gdb.info,  Node: Set Tracepoints,  Next: Analyze Collected Data,  Up: Tracepoints
1142
 
1143
13.1 Commands to Set Tracepoints
1144
================================
1145
 
1146
Before running such a "trace experiment", an arbitrary number of
1147
tracepoints can be set.  A tracepoint is actually a special type of
1148
breakpoint (*note Set Breaks::), so you can manipulate it using
1149
standard breakpoint commands.  For instance, as with breakpoints,
1150
tracepoint numbers are successive integers starting from one, and many
1151
of the commands associated with tracepoints take the tracepoint number
1152
as their argument, to identify which tracepoint to work on.
1153
 
1154
   For each tracepoint, you can specify, in advance, some arbitrary set
1155
of data that you want the target to collect in the trace buffer when it
1156
hits that tracepoint.  The collected data can include registers, local
1157
variables, or global data.  Later, you can use GDB commands to examine
1158
the values these data had at the time the tracepoint was hit.
1159
 
1160
   Tracepoints do not support every breakpoint feature.  Ignore counts
1161
on tracepoints have no effect, and tracepoints cannot run GDB commands
1162
when they are hit.  Tracepoints may not be thread-specific either.
1163
 
1164
   Some targets may support "fast tracepoints", which are inserted in a
1165
different way (such as with a jump instead of a trap), that is faster
1166
but possibly restricted in where they may be installed.
1167
 
1168
   Regular and fast tracepoints are dynamic tracing facilities, meaning
1169
that they can be used to insert tracepoints at (almost) any location in
1170
the target.  Some targets may also support controlling "static
1171
tracepoints" from GDB.  With static tracing, a set of instrumentation
1172
points, also known as "markers", are embedded in the target program,
1173
and can be activated or deactivated by name or address.  These are
1174
usually placed at locations which facilitate investigating what the
1175
target is actually doing.  GDB's support for static tracing includes
1176
being able to list instrumentation points, and attach them with GDB
1177
defined high level tracepoints that expose the whole range of
1178
convenience of GDB's tracepoints support.  Namelly, support for
1179
collecting registers values and values of global or local (to the
1180
instrumentation point) variables; tracepoint conditions and trace state
1181
variables.  The act of installing a GDB static tracepoint on an
1182
instrumentation point, or marker, is referred to as "probing" a static
1183
tracepoint marker.
1184
 
1185
   `gdbserver' supports tracepoints on some target systems.  *Note
1186
Tracepoints support in `gdbserver': Server.
1187
 
1188
   This section describes commands to set tracepoints and associated
1189
conditions and actions.
1190
 
1191
* Menu:
1192
 
1193
* Create and Delete Tracepoints::
1194
* Enable and Disable Tracepoints::
1195
* Tracepoint Passcounts::
1196
* Tracepoint Conditions::
1197
* Trace State Variables::
1198
* Tracepoint Actions::
1199
* Listing Tracepoints::
1200
* Listing Static Tracepoint Markers::
1201
* Starting and Stopping Trace Experiments::
1202
* Tracepoint Restrictions::
1203
 
1204

1205
File: gdb.info,  Node: Create and Delete Tracepoints,  Next: Enable and Disable Tracepoints,  Up: Set Tracepoints
1206
 
1207
13.1.1 Create and Delete Tracepoints
1208
------------------------------------
1209
 
1210
`trace LOCATION'
1211
     The `trace' command is very similar to the `break' command.  Its
1212
     argument LOCATION can be a source line, a function name, or an
1213
     address in the target program.  *Note Specify Location::.  The
1214
     `trace' command defines a tracepoint, which is a point in the
1215
     target program where the debugger will briefly stop, collect some
1216
     data, and then allow the program to continue.  Setting a
1217
     tracepoint or changing its actions doesn't take effect until the
1218
     next `tstart' command, and once a trace experiment is running,
1219
     further changes will not have any effect until the next trace
1220
     experiment starts.
1221
 
1222
     Here are some examples of using the `trace' command:
1223
 
1224
          (gdb) trace foo.c:121    // a source file and line number
1225
 
1226
          (gdb) trace +2           // 2 lines forward
1227
 
1228
          (gdb) trace my_function  // first source line of function
1229
 
1230
          (gdb) trace *my_function // EXACT start address of function
1231
 
1232
          (gdb) trace *0x2117c4    // an address
1233
 
1234
     You can abbreviate `trace' as `tr'.
1235
 
1236
`trace LOCATION if COND'
1237
     Set a tracepoint with condition COND; evaluate the expression COND
1238
     each time the tracepoint is reached, and collect data only if the
1239
     value is nonzero--that is, if COND evaluates as true.  *Note
1240
     Tracepoint Conditions: Tracepoint Conditions, for more information
1241
     on tracepoint conditions.
1242
 
1243
`ftrace LOCATION [ if COND ]'
1244
     The `ftrace' command sets a fast tracepoint.  For targets that
1245
     support them, fast tracepoints will use a more efficient but
1246
     possibly less general technique to trigger data collection, such
1247
     as a jump instruction instead of a trap, or some sort of hardware
1248
     support.  It may not be possible to create a fast tracepoint at
1249
     the desired location, in which case the command will exit with an
1250
     explanatory message.
1251
 
1252
     GDB handles arguments to `ftrace' exactly as for `trace'.
1253
 
1254
`strace LOCATION [ if COND ]'
1255
     The `strace' command sets a static tracepoint.  For targets that
1256
     support it, setting a static tracepoint probes a static
1257
     instrumentation point, or marker, found at LOCATION.  It may not
1258
     be possible to set a static tracepoint at the desired location, in
1259
     which case the command will exit with an explanatory message.
1260
 
1261
     GDB handles arguments to `strace' exactly as for `trace', with the
1262
     addition that the user can also specify `-m MARKER' as LOCATION.
1263
     This probes the marker identified by the MARKER string identifier.
1264
     This identifier depends on the static tracepoint backend library
1265
     your program is using.  You can find all the marker identifiers in
1266
     the `ID' field of the `info static-tracepoint-markers' command
1267
     output.  *Note Listing Static Tracepoint Markers: Listing Static
1268
     Tracepoint Markers.  For example, in the following small program
1269
     using the UST tracing engine:
1270
 
1271
          main ()
1272
          {
1273
            trace_mark(ust, bar33, "str %s", "FOOBAZ");
1274
          }
1275
 
1276
     the marker id is composed of joining the first two arguments to the
1277
     `trace_mark' call with a slash, which translates to:
1278
 
1279
          (gdb) info static-tracepoint-markers
1280
          Cnt Enb ID         Address            What
1281
          1   n   ust/bar33  0x0000000000400ddc in main at stexample.c:22
1282
                   Data: "str %s"
1283
          [etc...]
1284
 
1285
     so you may probe the marker above with:
1286
 
1287
          (gdb) strace -m ust/bar33
1288
 
1289
     Static tracepoints accept an extra collect action -- `collect
1290
     $_sdata'.  This collects arbitrary user data passed in the probe
1291
     point call to the tracing library.  In the UST example above,
1292
     you'll see that the third argument to `trace_mark' is a
1293
     printf-like format string.  The user data is then the result of
1294
     running that formating string against the following arguments.
1295
     Note that `info static-tracepoint-markers' command output lists
1296
     that format string in the `Data:' field.
1297
 
1298
     You can inspect this data when analyzing the trace buffer, by
1299
     printing the $_sdata variable like any other variable available to
1300
     GDB.  *Note Tracepoint Action Lists: Tracepoint Actions.
1301
 
1302
     The convenience variable `$tpnum' records the tracepoint number of
1303
     the most recently set tracepoint.
1304
 
1305
`delete tracepoint [NUM]'
1306
     Permanently delete one or more tracepoints.  With no argument, the
1307
     default is to delete all tracepoints.  Note that the regular
1308
     `delete' command can remove tracepoints also.
1309
 
1310
     Examples:
1311
 
1312
          (gdb) delete trace 1 2 3 // remove three tracepoints
1313
 
1314
          (gdb) delete trace       // remove all tracepoints
1315
 
1316
     You can abbreviate this command as `del tr'.
1317
 
1318

1319
File: gdb.info,  Node: Enable and Disable Tracepoints,  Next: Tracepoint Passcounts,  Prev: Create and Delete Tracepoints,  Up: Set Tracepoints
1320
 
1321
13.1.2 Enable and Disable Tracepoints
1322
-------------------------------------
1323
 
1324
These commands are deprecated; they are equivalent to plain `disable'
1325
and `enable'.
1326
 
1327
`disable tracepoint [NUM]'
1328
     Disable tracepoint NUM, or all tracepoints if no argument NUM is
1329
     given.  A disabled tracepoint will have no effect during the next
1330
     trace experiment, but it is not forgotten.  You can re-enable a
1331
     disabled tracepoint using the `enable tracepoint' command.
1332
 
1333
`enable tracepoint [NUM]'
1334
     Enable tracepoint NUM, or all tracepoints.  The enabled
1335
     tracepoints will become effective the next time a trace experiment
1336
     is run.
1337
 
1338

1339
File: gdb.info,  Node: Tracepoint Passcounts,  Next: Tracepoint Conditions,  Prev: Enable and Disable Tracepoints,  Up: Set Tracepoints
1340
 
1341
13.1.3 Tracepoint Passcounts
1342
----------------------------
1343
 
1344
`passcount [N [NUM]]'
1345
     Set the "passcount" of a tracepoint.  The passcount is a way to
1346
     automatically stop a trace experiment.  If a tracepoint's
1347
     passcount is N, then the trace experiment will be automatically
1348
     stopped on the N'th time that tracepoint is hit.  If the
1349
     tracepoint number NUM is not specified, the `passcount' command
1350
     sets the passcount of the most recently defined tracepoint.  If no
1351
     passcount is given, the trace experiment will run until stopped
1352
     explicitly by the user.
1353
 
1354
     Examples:
1355
 
1356
          (gdb) passcount 5 2 // Stop on the 5th execution of
1357
                                        `// tracepoint 2'
1358
 
1359
          (gdb) passcount 12  // Stop on the 12th execution of the
1360
                                        `// most recently defined tracepoint.'
1361
          (gdb) trace foo
1362
          (gdb) pass 3
1363
          (gdb) trace bar
1364
          (gdb) pass 2
1365
          (gdb) trace baz
1366
          (gdb) pass 1        // Stop tracing when foo has been
1367
                                         `// executed 3 times OR when bar has'
1368
                                         `// been executed 2 times'
1369
                                         `// OR when baz has been executed 1 time.'
1370
 
1371
 
1372

1373
File: gdb.info,  Node: Tracepoint Conditions,  Next: Trace State Variables,  Prev: Tracepoint Passcounts,  Up: Set Tracepoints
1374
 
1375
13.1.4 Tracepoint Conditions
1376
----------------------------
1377
 
1378
The simplest sort of tracepoint collects data every time your program
1379
reaches a specified place.  You can also specify a "condition" for a
1380
tracepoint.  A condition is just a Boolean expression in your
1381
programming language (*note Expressions: Expressions.).  A tracepoint
1382
with a condition evaluates the expression each time your program
1383
reaches it, and data collection happens only if the condition is true.
1384
 
1385
   Tracepoint conditions can be specified when a tracepoint is set, by
1386
using `if' in the arguments to the `trace' command.  *Note Setting
1387
Tracepoints: Create and Delete Tracepoints.  They can also be set or
1388
changed at any time with the `condition' command, just as with
1389
breakpoints.
1390
 
1391
   Unlike breakpoint conditions, GDB does not actually evaluate the
1392
conditional expression itself.  Instead, GDB encodes the expression
1393
into an agent expression (*note Agent Expressions:: suitable for
1394
execution on the target, independently of GDB.  Global variables become
1395
raw memory locations, locals become stack accesses, and so forth.
1396
 
1397
   For instance, suppose you have a function that is usually called
1398
frequently, but should not be called after an error has occurred.  You
1399
could use the following tracepoint command to collect data about calls
1400
of that function that happen while the error code is propagating
1401
through the program; an unconditional tracepoint could end up
1402
collecting thousands of useless trace frames that you would have to
1403
search through.
1404
 
1405
     (gdb) trace normal_operation if errcode > 0
1406
 
1407

1408
File: gdb.info,  Node: Trace State Variables,  Next: Tracepoint Actions,  Prev: Tracepoint Conditions,  Up: Set Tracepoints
1409
 
1410
13.1.5 Trace State Variables
1411
----------------------------
1412
 
1413
A "trace state variable" is a special type of variable that is created
1414
and managed by target-side code.  The syntax is the same as that for
1415
GDB's convenience variables (a string prefixed with "$"), but they are
1416
stored on the target.  They must be created explicitly, using a
1417
`tvariable' command.  They are always 64-bit signed integers.
1418
 
1419
   Trace state variables are remembered by GDB, and downloaded to the
1420
target along with tracepoint information when the trace experiment
1421
starts.  There are no intrinsic limits on the number of trace state
1422
variables, beyond memory limitations of the target.
1423
 
1424
   Although trace state variables are managed by the target, you can use
1425
them in print commands and expressions as if they were convenience
1426
variables; GDB will get the current value from the target while the
1427
trace experiment is running.  Trace state variables share the same
1428
namespace as other "$" variables, which means that you cannot have
1429
trace state variables with names like `$23' or `$pc', nor can you have
1430
a trace state variable and a convenience variable with the same name.
1431
 
1432
`tvariable $NAME [ = EXPRESSION ]'
1433
     The `tvariable' command creates a new trace state variable named
1434
     `$NAME', and optionally gives it an initial value of EXPRESSION.
1435
     EXPRESSION is evaluated when this command is entered; the result
1436
     will be converted to an integer if possible, otherwise GDB will
1437
     report an error. A subsequent `tvariable' command specifying the
1438
     same name does not create a variable, but instead assigns the
1439
     supplied initial value to the existing variable of that name,
1440
     overwriting any previous initial value. The default initial value
1441
     is 0.
1442
 
1443
`info tvariables'
1444
     List all the trace state variables along with their initial values.
1445
     Their current values may also be displayed, if the trace
1446
     experiment is currently running.
1447
 
1448
`delete tvariable [ $NAME ... ]'
1449
     Delete the given trace state variables, or all of them if no
1450
     arguments are specified.
1451
 
1452
 
1453

1454
File: gdb.info,  Node: Tracepoint Actions,  Next: Listing Tracepoints,  Prev: Trace State Variables,  Up: Set Tracepoints
1455
 
1456
13.1.6 Tracepoint Action Lists
1457
------------------------------
1458
 
1459
`actions [NUM]'
1460
     This command will prompt for a list of actions to be taken when the
1461
     tracepoint is hit.  If the tracepoint number NUM is not specified,
1462
     this command sets the actions for the one that was most recently
1463
     defined (so that you can define a tracepoint and then say
1464
     `actions' without bothering about its number).  You specify the
1465
     actions themselves on the following lines, one action at a time,
1466
     and terminate the actions list with a line containing just `end'.
1467
     So far, the only defined actions are `collect', `teval', and
1468
     `while-stepping'.
1469
 
1470
     `actions' is actually equivalent to `commands' (*note Breakpoint
1471
     Command Lists: Break Commands.), except that only the defined
1472
     actions are allowed; any other GDB command is rejected.
1473
 
1474
     To remove all actions from a tracepoint, type `actions NUM' and
1475
     follow it immediately with `end'.
1476
 
1477
          (gdb) collect DATA // collect some data
1478
 
1479
          (gdb) while-stepping 5 // single-step 5 times, collect data
1480
 
1481
          (gdb) end              // signals the end of actions.
1482
 
1483
     In the following example, the action list begins with `collect'
1484
     commands indicating the things to be collected when the tracepoint
1485
     is hit.  Then, in order to single-step and collect additional data
1486
     following the tracepoint, a `while-stepping' command is used,
1487
     followed by the list of things to be collected after each step in a
1488
     sequence of single steps.  The `while-stepping' command is
1489
     terminated by its own separate `end' command.  Lastly, the action
1490
     list is terminated by an `end' command.
1491
 
1492
          (gdb) trace foo
1493
          (gdb) actions
1494
          Enter actions for tracepoint 1, one per line:
1495
          > collect bar,baz
1496
          > collect $regs
1497
          > while-stepping 12
1498
            > collect $pc, arr[i]
1499
            > end
1500
          end
1501
 
1502
`collect EXPR1, EXPR2, ...'
1503
     Collect values of the given expressions when the tracepoint is hit.
1504
     This command accepts a comma-separated list of any valid
1505
     expressions.  In addition to global, static, or local variables,
1506
     the following special arguments are supported:
1507
 
1508
    `$regs'
1509
          Collect all registers.
1510
 
1511
    `$args'
1512
          Collect all function arguments.
1513
 
1514
    `$locals'
1515
          Collect all local variables.
1516
 
1517
    `$_sdata'
1518
          Collect static tracepoint marker specific data.  Only
1519
          available for static tracepoints.  *Note Tracepoint Action
1520
          Lists: Tracepoint Actions.  On the UST static tracepoints
1521
          library backend, an instrumentation point resembles a
1522
          `printf' function call.  The tracing library is able to
1523
          collect user specified data formatted to a character string
1524
          using the format provided by the programmer that instrumented
1525
          the program.  Other backends have similar mechanisms.  Here's
1526
          an example of a UST marker call:
1527
 
1528
                const char master_name[] = "$your_name";
1529
                trace_mark(channel1, marker1, "hello %s", master_name)
1530
 
1531
          In this case, collecting `$_sdata' collects the string `hello
1532
          $yourname'.  When analyzing the trace buffer, you can inspect
1533
          `$_sdata' like any other variable available to GDB.
1534
 
1535
     You can give several consecutive `collect' commands, each one with
1536
     a single argument, or one `collect' command with several arguments
1537
     separated by commas; the effect is the same.
1538
 
1539
     The command `info scope' (*note info scope: Symbols.) is
1540
     particularly useful for figuring out what data to collect.
1541
 
1542
`teval EXPR1, EXPR2, ...'
1543
     Evaluate the given expressions when the tracepoint is hit.  This
1544
     command accepts a comma-separated list of expressions.  The results
1545
     are discarded, so this is mainly useful for assigning values to
1546
     trace state variables (*note Trace State Variables::) without
1547
     adding those values to the trace buffer, as would be the case if
1548
     the `collect' action were used.
1549
 
1550
`while-stepping N'
1551
     Perform N single-step instruction traces after the tracepoint,
1552
     collecting new data after each step.  The `while-stepping' command
1553
     is followed by the list of what to collect while stepping
1554
     (followed by its own `end' command):
1555
 
1556
          > while-stepping 12
1557
            > collect $regs, myglobal
1558
            > end
1559
          >
1560
 
1561
     Note that `$pc' is not automatically collected by
1562
     `while-stepping'; you need to explicitly collect that register if
1563
     you need it.  You may abbreviate `while-stepping' as `ws' or
1564
     `stepping'.
1565
 
1566
`set default-collect EXPR1, EXPR2, ...'
1567
     This variable is a list of expressions to collect at each
1568
     tracepoint hit.  It is effectively an additional `collect' action
1569
     prepended to every tracepoint action list.  The expressions are
1570
     parsed individually for each tracepoint, so for instance a
1571
     variable named `xyz' may be interpreted as a global for one
1572
     tracepoint, and a local for another, as appropriate to the
1573
     tracepoint's location.
1574
 
1575
`show default-collect'
1576
     Show the list of expressions that are collected by default at each
1577
     tracepoint hit.
1578
 
1579
 
1580

1581
File: gdb.info,  Node: Listing Tracepoints,  Next: Listing Static Tracepoint Markers,  Prev: Tracepoint Actions,  Up: Set Tracepoints
1582
 
1583
13.1.7 Listing Tracepoints
1584
--------------------------
1585
 
1586
`info tracepoints [NUM]'
1587
     Display information about the tracepoint NUM.  If you don't
1588
     specify a tracepoint number, displays information about all the
1589
     tracepoints defined so far.  The format is similar to that used for
1590
     `info breakpoints'; in fact, `info tracepoints' is the same
1591
     command, simply restricting itself to tracepoints.
1592
 
1593
     A tracepoint's listing may include additional information specific
1594
     to tracing:
1595
 
1596
        * its passcount as given by the `passcount N' command
1597
 
1598
          (gdb) info trace
1599
          Num     Type           Disp Enb Address    What
1600
          1       tracepoint     keep y   0x0804ab57 in foo() at main.cxx:7
1601
                  while-stepping 20
1602
                    collect globfoo, $regs
1603
                  end
1604
                  collect globfoo2
1605
                  end
1606
                  pass count 1200
1607
          (gdb)
1608
 
1609
     This command can be abbreviated `info tp'.
1610
 
1611

1612
File: gdb.info,  Node: Listing Static Tracepoint Markers,  Next: Starting and Stopping Trace Experiments,  Prev: Listing Tracepoints,  Up: Set Tracepoints
1613
 
1614
13.1.8 Listing Static Tracepoint Markers
1615
----------------------------------------
1616
 
1617
`info static-tracepoint-markers'
1618
     Display information about all static tracepoint markers defined in
1619
     the program.
1620
 
1621
     For each marker, the following columns are printed:
1622
 
1623
    _Count_
1624
          An incrementing counter, output to help readability.  This is
1625
          not a stable identifier.
1626
 
1627
    _ID_
1628
          The marker ID, as reported by the target.
1629
 
1630
    _Enabled or Disabled_
1631
          Probed markers are tagged with `y'.  `n' identifies marks
1632
          that are not enabled.
1633
 
1634
    _Address_
1635
          Where the marker is in your program, as a memory address.
1636
 
1637
    _What_
1638
          Where the marker is in the source for your program, as a file
1639
          and line number.  If the debug information included in the
1640
          program does not allow GDB to locate the source of the
1641
          marker, this column will be left blank.
1642
 
1643
     In addition, the following information may be printed for each
1644
     marker:
1645
 
1646
    _Data_
1647
          User data passed to the tracing library by the marker call.
1648
          In the UST backend, this is the format string passed as
1649
          argument to the marker call.
1650
 
1651
    _Static tracepoints probing the marker_
1652
          The list of static tracepoints attached to the marker.
1653
 
1654
          (gdb) info static-tracepoint-markers
1655
          Cnt ID         Enb Address            What
1656
          1   ust/bar2   y   0x0000000000400e1a in main at stexample.c:25
1657
               Data: number1 %d number2 %d
1658
               Probed by static tracepoints: #2
1659
          2   ust/bar33  n   0x0000000000400c87 in main at stexample.c:24
1660
               Data: str %s
1661
          (gdb)
1662
 
1663

1664
File: gdb.info,  Node: Starting and Stopping Trace Experiments,  Next: Tracepoint Restrictions,  Prev: Listing Static Tracepoint Markers,  Up: Set Tracepoints
1665
 
1666
13.1.9 Starting and Stopping Trace Experiments
1667
----------------------------------------------
1668
 
1669
`tstart'
1670
     This command takes no arguments.  It starts the trace experiment,
1671
     and begins collecting data.  This has the side effect of
1672
     discarding all the data collected in the trace buffer during the
1673
     previous trace experiment.
1674
 
1675
`tstop'
1676
     This command takes no arguments.  It ends the trace experiment, and
1677
     stops collecting data.
1678
 
1679
     *Note*: a trace experiment and data collection may stop
1680
     automatically if any tracepoint's passcount is reached (*note
1681
     Tracepoint Passcounts::), or if the trace buffer becomes full.
1682
 
1683
`tstatus'
1684
     This command displays the status of the current trace data
1685
     collection.
1686
 
1687
   Here is an example of the commands we described so far:
1688
 
1689
     (gdb) trace gdb_c_test
1690
     (gdb) actions
1691
     Enter actions for tracepoint #1, one per line.
1692
     > collect $regs,$locals,$args
1693
     > while-stepping 11
1694
       > collect $regs
1695
       > end
1696
     > end
1697
     (gdb) tstart
1698
        [time passes ...]
1699
     (gdb) tstop
1700
 
1701
   You can choose to continue running the trace experiment even if GDB
1702
disconnects from the target, voluntarily or involuntarily.  For
1703
commands such as `detach', the debugger will ask what you want to do
1704
with the trace.  But for unexpected terminations (GDB crash, network
1705
outage), it would be unfortunate to lose hard-won trace data, so the
1706
variable `disconnected-tracing' lets you decide whether the trace should
1707
continue running without GDB.
1708
 
1709
`set disconnected-tracing on'
1710
`set disconnected-tracing off'
1711
     Choose whether a tracing run should continue to run if GDB has
1712
     disconnected from the target.  Note that `detach' or `quit' will
1713
     ask you directly what to do about a running trace no matter what
1714
     this variable's setting, so the variable is mainly useful for
1715
     handling unexpected situations, such as loss of the network.
1716
 
1717
`show disconnected-tracing'
1718
     Show the current choice for disconnected tracing.
1719
 
1720
 
1721
   When you reconnect to the target, the trace experiment may or may not
1722
still be running; it might have filled the trace buffer in the
1723
meantime, or stopped for one of the other reasons.  If it is running,
1724
it will continue after reconnection.
1725
 
1726
   Upon reconnection, the target will upload information about the
1727
tracepoints in effect.  GDB will then compare that information to the
1728
set of tracepoints currently defined, and attempt to match them up,
1729
allowing for the possibility that the numbers may have changed due to
1730
creation and deletion in the meantime.  If one of the target's
1731
tracepoints does not match any in GDB, the debugger will create a new
1732
tracepoint, so that you have a number with which to specify that
1733
tracepoint.  This matching-up process is necessarily heuristic, and it
1734
may result in useless tracepoints being created; you may simply delete
1735
them if they are of no use.
1736
 
1737
   If your target agent supports a "circular trace buffer", then you
1738
can run a trace experiment indefinitely without filling the trace
1739
buffer; when space runs out, the agent deletes already-collected trace
1740
frames, oldest first, until there is enough room to continue
1741
collecting.  This is especially useful if your tracepoints are being
1742
hit too often, and your trace gets terminated prematurely because the
1743
buffer is full.  To ask for a circular trace buffer, simply set
1744
`circular_trace_buffer' to on.  You can set this at any time, including
1745
during tracing; if the agent can do it, it will change buffer handling
1746
on the fly, otherwise it will not take effect until the next run.
1747
 
1748
`set circular-trace-buffer on'
1749
`set circular-trace-buffer off'
1750
     Choose whether a tracing run should use a linear or circular buffer
1751
     for trace data.  A linear buffer will not lose any trace data, but
1752
     may fill up prematurely, while a circular buffer will discard old
1753
     trace data, but it will have always room for the latest tracepoint
1754
     hits.
1755
 
1756
`show circular-trace-buffer'
1757
     Show the current choice for the trace buffer.  Note that this may
1758
     not match the agent's current buffer handling, nor is it
1759
     guaranteed to match the setting that might have been in effect
1760
     during a past run, for instance if you are looking at frames from
1761
     a trace file.
1762
 
1763
 
1764

1765
File: gdb.info,  Node: Tracepoint Restrictions,  Prev: Starting and Stopping Trace Experiments,  Up: Set Tracepoints
1766
 
1767
13.1.10 Tracepoint Restrictions
1768
-------------------------------
1769
 
1770
There are a number of restrictions on the use of tracepoints.  As
1771
described above, tracepoint data gathering occurs on the target without
1772
interaction from GDB.  Thus the full capabilities of the debugger are
1773
not available during data gathering, and then at data examination time,
1774
you will be limited by only having what was collected.  The following
1775
items describe some common problems, but it is not exhaustive, and you
1776
may run into additional difficulties not mentioned here.
1777
 
1778
   * Tracepoint expressions are intended to gather objects (lvalues).
1779
     Thus the full flexibility of GDB's expression evaluator is not
1780
     available.  You cannot call functions, cast objects to aggregate
1781
     types, access convenience variables or modify values (except by
1782
     assignment to trace state variables).  Some language features may
1783
     implicitly call functions (for instance Objective-C fields with
1784
     accessors), and therefore cannot be collected either.
1785
 
1786
   * Collection of local variables, either individually or in bulk with
1787
     `$locals' or `$args', during `while-stepping' may behave
1788
     erratically.  The stepping action may enter a new scope (for
1789
     instance by stepping into a function), or the location of the
1790
     variable may change (for instance it is loaded into a register).
1791
     The tracepoint data recorded uses the location information for the
1792
     variables that is correct for the tracepoint location.  When the
1793
     tracepoint is created, it is not possible, in general, to determine
1794
     where the steps of a `while-stepping' sequence will advance the
1795
     program--particularly if a conditional branch is stepped.
1796
 
1797
   * Collection of an incompletely-initialized or partially-destroyed
1798
     object may result in something that GDB cannot display, or displays
1799
     in a misleading way.
1800
 
1801
   * When GDB displays a pointer to character it automatically
1802
     dereferences the pointer to also display characters of the string
1803
     being pointed to.  However, collecting the pointer during tracing
1804
     does not automatically collect the string.  You need to explicitly
1805
     dereference the pointer and provide size information if you want to
1806
     collect not only the pointer, but the memory pointed to.  For
1807
     example, `*ptr@50' can be used to collect the 50 element array
1808
     pointed to by `ptr'.
1809
 
1810
   * It is not possible to collect a complete stack backtrace at a
1811
     tracepoint.  Instead, you may collect the registers and a few
1812
     hundred bytes from the stack pointer with something like
1813
     `*$esp@300' (adjust to use the name of the actual stack pointer
1814
     register on your target architecture, and the amount of stack you
1815
     wish to capture).  Then the `backtrace' command will show a
1816
     partial backtrace when using a trace frame.  The number of stack
1817
     frames that can be examined depends on the sizes of the frames in
1818
     the collected stack.  Note that if you ask for a block so large
1819
     that it goes past the bottom of the stack, the target agent may
1820
     report an error trying to read from an invalid address.
1821
 
1822
   * If you do not collect registers at a tracepoint, GDB can infer
1823
     that the value of `$pc' must be the same as the address of the
1824
     tracepoint and use that when you are looking at a trace frame for
1825
     that tracepoint.  However, this cannot work if the tracepoint has
1826
     multiple locations (for instance if it was set in a function that
1827
     was inlined), or if it has a `while-stepping' loop.  In those cases
1828
     GDB will warn you that it can't infer `$pc', and default it to
1829
     zero.
1830
 
1831
 
1832

1833
File: gdb.info,  Node: Analyze Collected Data,  Next: Tracepoint Variables,  Prev: Set Tracepoints,  Up: Tracepoints
1834
 
1835
13.2 Using the Collected Data
1836
=============================
1837
 
1838
After the tracepoint experiment ends, you use GDB commands for
1839
examining the trace data.  The basic idea is that each tracepoint
1840
collects a trace "snapshot" every time it is hit and another snapshot
1841
every time it single-steps.  All these snapshots are consecutively
1842
numbered from zero and go into a buffer, and you can examine them
1843
later.  The way you examine them is to "focus" on a specific trace
1844
snapshot.  When the remote stub is focused on a trace snapshot, it will
1845
respond to all GDB requests for memory and registers by reading from
1846
the buffer which belongs to that snapshot, rather than from _real_
1847
memory or registers of the program being debugged.  This means that
1848
*all* GDB commands (`print', `info registers', `backtrace', etc.) will
1849
behave as if we were currently debugging the program state as it was
1850
when the tracepoint occurred.  Any requests for data that are not in
1851
the buffer will fail.
1852
 
1853
* Menu:
1854
 
1855
* tfind::                       How to select a trace snapshot
1856
* tdump::                       How to display all data for a snapshot
1857
* save tracepoints::            How to save tracepoints for a future run
1858
 
1859

1860
File: gdb.info,  Node: tfind,  Next: tdump,  Up: Analyze Collected Data
1861
 
1862
13.2.1 `tfind N'
1863
----------------
1864
 
1865
The basic command for selecting a trace snapshot from the buffer is
1866
`tfind N', which finds trace snapshot number N, counting from zero.  If
1867
no argument N is given, the next snapshot is selected.
1868
 
1869
   Here are the various forms of using the `tfind' command.
1870
 
1871
`tfind start'
1872
     Find the first snapshot in the buffer.  This is a synonym for
1873
     `tfind 0' (since 0 is the number of the first snapshot).
1874
 
1875
`tfind none'
1876
     Stop debugging trace snapshots, resume _live_ debugging.
1877
 
1878
`tfind end'
1879
     Same as `tfind none'.
1880
 
1881
`tfind'
1882
     No argument means find the next trace snapshot.
1883
 
1884
`tfind -'
1885
     Find the previous trace snapshot before the current one.  This
1886
     permits retracing earlier steps.
1887
 
1888
`tfind tracepoint NUM'
1889
     Find the next snapshot associated with tracepoint NUM.  Search
1890
     proceeds forward from the last examined trace snapshot.  If no
1891
     argument NUM is given, it means find the next snapshot collected
1892
     for the same tracepoint as the current snapshot.
1893
 
1894
`tfind pc ADDR'
1895
     Find the next snapshot associated with the value ADDR of the
1896
     program counter.  Search proceeds forward from the last examined
1897
     trace snapshot.  If no argument ADDR is given, it means find the
1898
     next snapshot with the same value of PC as the current snapshot.
1899
 
1900
`tfind outside ADDR1, ADDR2'
1901
     Find the next snapshot whose PC is outside the given range of
1902
     addresses (exclusive).
1903
 
1904
`tfind range ADDR1, ADDR2'
1905
     Find the next snapshot whose PC is between ADDR1 and ADDR2
1906
     (inclusive).
1907
 
1908
`tfind line [FILE:]N'
1909
     Find the next snapshot associated with the source line N.  If the
1910
     optional argument FILE is given, refer to line N in that source
1911
     file.  Search proceeds forward from the last examined trace
1912
     snapshot.  If no argument N is given, it means find the next line
1913
     other than the one currently being examined; thus saying `tfind
1914
     line' repeatedly can appear to have the same effect as stepping
1915
     from line to line in a _live_ debugging session.
1916
 
1917
   The default arguments for the `tfind' commands are specifically
1918
designed to make it easy to scan through the trace buffer.  For
1919
instance, `tfind' with no argument selects the next trace snapshot, and
1920
`tfind -' with no argument selects the previous trace snapshot.  So, by
1921
giving one `tfind' command, and then simply hitting  repeatedly
1922
you can examine all the trace snapshots in order.  Or, by saying `tfind
1923
-' and then hitting  repeatedly you can examine the snapshots in
1924
reverse order.  The `tfind line' command with no argument selects the
1925
snapshot for the next source line executed.  The `tfind pc' command with
1926
no argument selects the next snapshot with the same program counter
1927
(PC) as the current frame.  The `tfind tracepoint' command with no
1928
argument selects the next trace snapshot collected by the same
1929
tracepoint as the current one.
1930
 
1931
   In addition to letting you scan through the trace buffer manually,
1932
these commands make it easy to construct GDB scripts that scan through
1933
the trace buffer and print out whatever collected data you are
1934
interested in.  Thus, if we want to examine the PC, FP, and SP
1935
registers from each trace frame in the buffer, we can say this:
1936
 
1937
     (gdb) tfind start
1938
     (gdb) while ($trace_frame != -1)
1939
     > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
1940
               $trace_frame, $pc, $sp, $fp
1941
     > tfind
1942
     > end
1943
 
1944
     Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
1945
     Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
1946
     Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
1947
     Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
1948
     Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
1949
     Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
1950
     Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
1951
     Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
1952
     Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
1953
     Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
1954
     Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
1955
 
1956
   Or, if we want to examine the variable `X' at each source line in
1957
the buffer:
1958
 
1959
     (gdb) tfind start
1960
     (gdb) while ($trace_frame != -1)
1961
     > printf "Frame %d, X == %d\n", $trace_frame, X
1962
     > tfind line
1963
     > end
1964
 
1965
     Frame 0, X = 1
1966
     Frame 7, X = 2
1967
     Frame 13, X = 255
1968
 
1969

1970
File: gdb.info,  Node: tdump,  Next: save tracepoints,  Prev: tfind,  Up: Analyze Collected Data
1971
 
1972
13.2.2 `tdump'
1973
--------------
1974
 
1975
This command takes no arguments.  It prints all the data collected at
1976
the current trace snapshot.
1977
 
1978
     (gdb) trace 444
1979
     (gdb) actions
1980
     Enter actions for tracepoint #2, one per line:
1981
     > collect $regs, $locals, $args, gdb_long_test
1982
     > end
1983
 
1984
     (gdb) tstart
1985
 
1986
     (gdb) tfind line 444
1987
     #0  gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
1988
     at gdb_test.c:444
1989
     444        printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
1990
 
1991
     (gdb) tdump
1992
     Data collected at tracepoint 2, trace frame 1:
1993
     d0             0xc4aa0085       -995491707
1994
     d1             0x18     24
1995
     d2             0x80     128
1996
     d3             0x33     51
1997
     d4             0x71aea3d        119204413
1998
     d5             0x22     34
1999
     d6             0xe0     224
2000
     d7             0x380035 3670069
2001
     a0             0x19e24a 1696330
2002
     a1             0x3000668        50333288
2003
     a2             0x100    256
2004
     a3             0x322000 3284992
2005
     a4             0x3000698        50333336
2006
     a5             0x1ad3cc 1758156
2007
     fp             0x30bf3c 0x30bf3c
2008
     sp             0x30bf34 0x30bf34
2009
     ps             0x0      0
2010
     pc             0x20b2c8 0x20b2c8
2011
     fpcontrol      0x0      0
2012
     fpstatus       0x0      0
2013
     fpiaddr        0x0      0
2014
     p = 0x20e5b4 "gdb-test"
2015
     p1 = (void *) 0x11
2016
     p2 = (void *) 0x22
2017
     p3 = (void *) 0x33
2018
     p4 = (void *) 0x44
2019
     p5 = (void *) 0x55
2020
     p6 = (void *) 0x66
2021
     gdb_long_test = 17 '\021'
2022
 
2023
     (gdb)
2024
 
2025
   `tdump' works by scanning the tracepoint's current collection
2026
actions and printing the value of each expression listed.  So `tdump'
2027
can fail, if after a run, you change the tracepoint's actions to
2028
mention variables that were not collected during the run.
2029
 
2030
   Also, for tracepoints with `while-stepping' loops, `tdump' uses the
2031
collected value of `$pc' to distinguish between trace frames that were
2032
collected at the tracepoint hit, and frames that were collected while
2033
stepping.  This allows it to correctly choose whether to display the
2034
basic list of collections, or the collections from the body of the
2035
while-stepping loop.  However, if `$pc' was not collected, then `tdump'
2036
will always attempt to dump using the basic collection list, and may
2037
fail if a while-stepping frame does not include all the same data that
2038
is collected at the tracepoint hit.
2039
 
2040

2041
File: gdb.info,  Node: save tracepoints,  Prev: tdump,  Up: Analyze Collected Data
2042
 
2043
13.2.3 `save tracepoints FILENAME'
2044
----------------------------------
2045
 
2046
This command saves all current tracepoint definitions together with
2047
their actions and passcounts, into a file `FILENAME' suitable for use
2048
in a later debugging session.  To read the saved tracepoint
2049
definitions, use the `source' command (*note Command Files::).  The
2050
`save-tracepoints' command is a deprecated alias for `save tracepoints'
2051
 
2052

2053
File: gdb.info,  Node: Tracepoint Variables,  Next: Trace Files,  Prev: Analyze Collected Data,  Up: Tracepoints
2054
 
2055
13.3 Convenience Variables for Tracepoints
2056
==========================================
2057
 
2058
`(int) $trace_frame'
2059
     The current trace snapshot (a.k.a. "frame") number, or -1 if no
2060
     snapshot is selected.
2061
 
2062
`(int) $tracepoint'
2063
     The tracepoint for the current trace snapshot.
2064
 
2065
`(int) $trace_line'
2066
     The line number for the current trace snapshot.
2067
 
2068
`(char []) $trace_file'
2069
     The source file for the current trace snapshot.
2070
 
2071
`(char []) $trace_func'
2072
     The name of the function containing `$tracepoint'.
2073
 
2074
   Note: `$trace_file' is not suitable for use in `printf', use
2075
`output' instead.
2076
 
2077
   Here's a simple example of using these convenience variables for
2078
stepping through all the trace snapshots and printing some of their
2079
data.  Note that these are not the same as trace state variables, which
2080
are managed by the target.
2081
 
2082
     (gdb) tfind start
2083
 
2084
     (gdb) while $trace_frame != -1
2085
     > output $trace_file
2086
     > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
2087
     > tfind
2088
     > end
2089
 
2090

2091
File: gdb.info,  Node: Trace Files,  Prev: Tracepoint Variables,  Up: Tracepoints
2092
 
2093
13.4 Using Trace Files
2094
======================
2095
 
2096
In some situations, the target running a trace experiment may no longer
2097
be available; perhaps it crashed, or the hardware was needed for a
2098
different activity.  To handle these cases, you can arrange to dump the
2099
trace data into a file, and later use that file as a source of trace
2100
data, via the `target tfile' command.
2101
 
2102
`tsave [ -r ] FILENAME'
2103
     Save the trace data to FILENAME.  By default, this command assumes
2104
     that FILENAME refers to the host filesystem, so if necessary GDB
2105
     will copy raw trace data up from the target and then save it.  If
2106
     the target supports it, you can also supply the optional argument
2107
     `-r' ("remote") to direct the target to save the data directly
2108
     into FILENAME in its own filesystem, which may be more efficient
2109
     if the trace buffer is very large.  (Note, however, that `target
2110
     tfile' can only read from files accessible to the host.)
2111
 
2112
`target tfile FILENAME'
2113
     Use the file named FILENAME as a source of trace data.  Commands
2114
     that examine data work as they do with a live target, but it is not
2115
     possible to run any new trace experiments.  `tstatus' will report
2116
     the state of the trace run at the moment the data was saved, as
2117
     well as the current trace frame you are examining.  FILENAME must
2118
     be on a filesystem accessible to the host.
2119
 
2120
 
2121

2122
File: gdb.info,  Node: Overlays,  Next: Languages,  Prev: Tracepoints,  Up: Top
2123
 
2124
14 Debugging Programs That Use Overlays
2125
***************************************
2126
 
2127
If your program is too large to fit completely in your target system's
2128
memory, you can sometimes use "overlays" to work around this problem.
2129
GDB provides some support for debugging programs that use overlays.
2130
 
2131
* Menu:
2132
 
2133
* How Overlays Work::              A general explanation of overlays.
2134
* Overlay Commands::               Managing overlays in GDB.
2135
* Automatic Overlay Debugging::    GDB can find out which overlays are
2136
                                   mapped by asking the inferior.
2137
* Overlay Sample Program::         A sample program using overlays.
2138
 
2139

2140
File: gdb.info,  Node: How Overlays Work,  Next: Overlay Commands,  Up: Overlays
2141
 
2142
14.1 How Overlays Work
2143
======================
2144
 
2145
Suppose you have a computer whose instruction address space is only 64
2146
kilobytes long, but which has much more memory which can be accessed by
2147
other means: special instructions, segment registers, or memory
2148
management hardware, for example.  Suppose further that you want to
2149
adapt a program which is larger than 64 kilobytes to run on this system.
2150
 
2151
   One solution is to identify modules of your program which are
2152
relatively independent, and need not call each other directly; call
2153
these modules "overlays".  Separate the overlays from the main program,
2154
and place their machine code in the larger memory.  Place your main
2155
program in instruction memory, but leave at least enough space there to
2156
hold the largest overlay as well.
2157
 
2158
   Now, to call a function located in an overlay, you must first copy
2159
that overlay's machine code from the large memory into the space set
2160
aside for it in the instruction memory, and then jump to its entry point
2161
there.
2162
 
2163
         Data             Instruction            Larger
2164
     Address Space       Address Space        Address Space
2165
     +-----------+       +-----------+        +-----------+
2166
     |           |       |           |        |           |
2167
     +-----------+       +-----------+        +-----------+<-- overlay 1
2168
     | program   |       |   main    |   .----| overlay 1 | load address
2169
     | variables |       |  program  |   |    +-----------+
2170
     | and heap  |       |           |   |    |           |
2171
     +-----------+       |           |   |    +-----------+<-- overlay 2
2172
     |           |       +-----------+   |    |           | load address
2173
     +-----------+       |           |   |  .-| overlay 2 |
2174
                         |           |   |  | |           |
2175
              mapped --->+-----------+   |  | +-----------+
2176
              address    |           |   |  | |           |
2177
                         |  overlay  | <-'  | |           |
2178
                         |   area    |  <---' +-----------+<-- overlay 3
2179
                         |           | <---.  |           | load address
2180
                         +-----------+     `--| overlay 3 |
2181
                         |           |        |           |
2182
                         +-----------+        |           |
2183
                                              +-----------+
2184
                                              |           |
2185
                                              +-----------+
2186
 
2187
                         A code overlay
2188
 
2189
   The diagram (*note A code overlay::) shows a system with separate
2190
data and instruction address spaces.  To map an overlay, the program
2191
copies its code from the larger address space to the instruction
2192
address space.  Since the overlays shown here all use the same mapped
2193
address, only one may be mapped at a time.  For a system with a single
2194
address space for data and instructions, the diagram would be similar,
2195
except that the program variables and heap would share an address space
2196
with the main program and the overlay area.
2197
 
2198
   An overlay loaded into instruction memory and ready for use is
2199
called a "mapped" overlay; its "mapped address" is its address in the
2200
instruction memory.  An overlay not present (or only partially present)
2201
in instruction memory is called "unmapped"; its "load address" is its
2202
address in the larger memory.  The mapped address is also called the
2203
"virtual memory address", or "VMA"; the load address is also called the
2204
"load memory address", or "LMA".
2205
 
2206
   Unfortunately, overlays are not a completely transparent way to
2207
adapt a program to limited instruction memory.  They introduce a new
2208
set of global constraints you must keep in mind as you design your
2209
program:
2210
 
2211
   * Before calling or returning to a function in an overlay, your
2212
     program must make sure that overlay is actually mapped.
2213
     Otherwise, the call or return will transfer control to the right
2214
     address, but in the wrong overlay, and your program will probably
2215
     crash.
2216
 
2217
   * If the process of mapping an overlay is expensive on your system,
2218
     you will need to choose your overlays carefully to minimize their
2219
     effect on your program's performance.
2220
 
2221
   * The executable file you load onto your system must contain each
2222
     overlay's instructions, appearing at the overlay's load address,
2223
     not its mapped address.  However, each overlay's instructions must
2224
     be relocated and its symbols defined as if the overlay were at its
2225
     mapped address.  You can use GNU linker scripts to specify
2226
     different load and relocation addresses for pieces of your
2227
     program; see *Note Overlay Description: (ld.info)Overlay
2228
     Description.
2229
 
2230
   * The procedure for loading executable files onto your system must
2231
     be able to load their contents into the larger address space as
2232
     well as the instruction and data spaces.
2233
 
2234
 
2235
   The overlay system described above is rather simple, and could be
2236
improved in many ways:
2237
 
2238
   * If your system has suitable bank switch registers or memory
2239
     management hardware, you could use those facilities to make an
2240
     overlay's load area contents simply appear at their mapped address
2241
     in instruction space.  This would probably be faster than copying
2242
     the overlay to its mapped area in the usual way.
2243
 
2244
   * If your overlays are small enough, you could set aside more than
2245
     one overlay area, and have more than one overlay mapped at a time.
2246
 
2247
   * You can use overlays to manage data, as well as instructions.  In
2248
     general, data overlays are even less transparent to your design
2249
     than code overlays: whereas code overlays only require care when
2250
     you call or return to functions, data overlays require care every
2251
     time you access the data.  Also, if you change the contents of a
2252
     data overlay, you must copy its contents back out to its load
2253
     address before you can copy a different data overlay into the same
2254
     mapped area.
2255
 
2256
 
2257

2258
File: gdb.info,  Node: Overlay Commands,  Next: Automatic Overlay Debugging,  Prev: How Overlays Work,  Up: Overlays
2259
 
2260
14.2 Overlay Commands
2261
=====================
2262
 
2263
To use GDB's overlay support, each overlay in your program must
2264
correspond to a separate section of the executable file.  The section's
2265
virtual memory address and load memory address must be the overlay's
2266
mapped and load addresses.  Identifying overlays with sections allows
2267
GDB to determine the appropriate address of a function or variable,
2268
depending on whether the overlay is mapped or not.
2269
 
2270
   GDB's overlay commands all start with the word `overlay'; you can
2271
abbreviate this as `ov' or `ovly'.  The commands are:
2272
 
2273
`overlay off'
2274
     Disable GDB's overlay support.  When overlay support is disabled,
2275
     GDB assumes that all functions and variables are always present at
2276
     their mapped addresses.  By default, GDB's overlay support is
2277
     disabled.
2278
 
2279
`overlay manual'
2280
     Enable "manual" overlay debugging.  In this mode, GDB relies on
2281
     you to tell it which overlays are mapped, and which are not, using
2282
     the `overlay map-overlay' and `overlay unmap-overlay' commands
2283
     described below.
2284
 
2285
`overlay map-overlay OVERLAY'
2286
`overlay map OVERLAY'
2287
     Tell GDB that OVERLAY is now mapped; OVERLAY must be the name of
2288
     the object file section containing the overlay.  When an overlay
2289
     is mapped, GDB assumes it can find the overlay's functions and
2290
     variables at their mapped addresses.  GDB assumes that any other
2291
     overlays whose mapped ranges overlap that of OVERLAY are now
2292
     unmapped.
2293
 
2294
`overlay unmap-overlay OVERLAY'
2295
`overlay unmap OVERLAY'
2296
     Tell GDB that OVERLAY is no longer mapped; OVERLAY must be the
2297
     name of the object file section containing the overlay.  When an
2298
     overlay is unmapped, GDB assumes it can find the overlay's
2299
     functions and variables at their load addresses.
2300
 
2301
`overlay auto'
2302
     Enable "automatic" overlay debugging.  In this mode, GDB consults
2303
     a data structure the overlay manager maintains in the inferior to
2304
     see which overlays are mapped.  For details, see *Note Automatic
2305
     Overlay Debugging::.
2306
 
2307
`overlay load-target'
2308
`overlay load'
2309
     Re-read the overlay table from the inferior.  Normally, GDB
2310
     re-reads the table GDB automatically each time the inferior stops,
2311
     so this command should only be necessary if you have changed the
2312
     overlay mapping yourself using GDB.  This command is only useful
2313
     when using automatic overlay debugging.
2314
 
2315
`overlay list-overlays'
2316
`overlay list'
2317
     Display a list of the overlays currently mapped, along with their
2318
     mapped addresses, load addresses, and sizes.
2319
 
2320
 
2321
   Normally, when GDB prints a code address, it includes the name of
2322
the function the address falls in:
2323
 
2324
     (gdb) print main
2325
     $3 = {int ()} 0x11a0 
2326
   When overlay debugging is enabled, GDB recognizes code in unmapped
2327
overlays, and prints the names of unmapped functions with asterisks
2328
around them.  For example, if `foo' is a function in an unmapped
2329
overlay, GDB prints it this way:
2330
 
2331
     (gdb) overlay list
2332
     No sections are mapped.
2333
     (gdb) print foo
2334
     $5 = {int (int)} 0x100000 <*foo*>
2335
   When `foo''s overlay is mapped, GDB prints the function's name
2336
normally:
2337
 
2338
     (gdb) overlay list
2339
     Section .ov.foo.text, loaded at 0x100000 - 0x100034,
2340
             mapped at 0x1016 - 0x104a
2341
     (gdb) print foo
2342
     $6 = {int (int)} 0x1016 
2343
 
2344
   When overlay debugging is enabled, GDB can find the correct address
2345
for functions and variables in an overlay, whether or not the overlay
2346
is mapped.  This allows most GDB commands, like `break' and
2347
`disassemble', to work normally, even on unmapped code.  However, GDB's
2348
breakpoint support has some limitations:
2349
 
2350
   * You can set breakpoints in functions in unmapped overlays, as long
2351
     as GDB can write to the overlay at its load address.
2352
 
2353
   * GDB can not set hardware or simulator-based breakpoints in
2354
     unmapped overlays.  However, if you set a breakpoint at the end of
2355
     your overlay manager (and tell GDB which overlays are now mapped,
2356
     if you are using manual overlay management), GDB will re-set its
2357
     breakpoints properly.
2358
 
2359

2360
File: gdb.info,  Node: Automatic Overlay Debugging,  Next: Overlay Sample Program,  Prev: Overlay Commands,  Up: Overlays
2361
 
2362
14.3 Automatic Overlay Debugging
2363
================================
2364
 
2365
GDB can automatically track which overlays are mapped and which are
2366
not, given some simple co-operation from the overlay manager in the
2367
inferior.  If you enable automatic overlay debugging with the `overlay
2368
auto' command (*note Overlay Commands::), GDB looks in the inferior's
2369
memory for certain variables describing the current state of the
2370
overlays.
2371
 
2372
   Here are the variables your overlay manager must define to support
2373
GDB's automatic overlay debugging:
2374
 
2375
`_ovly_table':
2376
     This variable must be an array of the following structures:
2377
 
2378
          struct
2379
          {
2380
            /* The overlay's mapped address.  */
2381
            unsigned long vma;
2382
 
2383
            /* The size of the overlay, in bytes.  */
2384
            unsigned long size;
2385
 
2386
            /* The overlay's load address.  */
2387
            unsigned long lma;
2388
 
2389
            /* Non-zero if the overlay is currently mapped;
2390
               zero otherwise.  */
2391
            unsigned long mapped;
2392
          }
2393
 
2394
`_novlys':
2395
     This variable must be a four-byte signed integer, holding the total
2396
     number of elements in `_ovly_table'.
2397
 
2398
 
2399
   To decide whether a particular overlay is mapped or not, GDB looks
2400
for an entry in `_ovly_table' whose `vma' and `lma' members equal the
2401
VMA and LMA of the overlay's section in the executable file.  When GDB
2402
finds a matching entry, it consults the entry's `mapped' member to
2403
determine whether the overlay is currently mapped.
2404
 
2405
   In addition, your overlay manager may define a function called
2406
`_ovly_debug_event'.  If this function is defined, GDB will silently
2407
set a breakpoint there.  If the overlay manager then calls this
2408
function whenever it has changed the overlay table, this will enable
2409
GDB to accurately keep track of which overlays are in program memory,
2410
and update any breakpoints that may be set in overlays.  This will
2411
allow breakpoints to work even if the overlays are kept in ROM or other
2412
non-writable memory while they are not being executed.
2413
 
2414

2415
File: gdb.info,  Node: Overlay Sample Program,  Prev: Automatic Overlay Debugging,  Up: Overlays
2416
 
2417
14.4 Overlay Sample Program
2418
===========================
2419
 
2420
When linking a program which uses overlays, you must place the overlays
2421
at their load addresses, while relocating them to run at their mapped
2422
addresses.  To do this, you must write a linker script (*note Overlay
2423
Description: (ld.info)Overlay Description.).  Unfortunately, since
2424
linker scripts are specific to a particular host system, target
2425
architecture, and target memory layout, this manual cannot provide
2426
portable sample code demonstrating GDB's overlay support.
2427
 
2428
   However, the GDB source distribution does contain an overlaid
2429
program, with linker scripts for a few systems, as part of its test
2430
suite.  The program consists of the following files from
2431
`gdb/testsuite/gdb.base':
2432
 
2433
`overlays.c'
2434
     The main program file.
2435
 
2436
`ovlymgr.c'
2437
     A simple overlay manager, used by `overlays.c'.
2438
 
2439
`foo.c'
2440
`bar.c'
2441
`baz.c'
2442
`grbx.c'
2443
     Overlay modules, loaded and used by `overlays.c'.
2444
 
2445
`d10v.ld'
2446
`m32r.ld'
2447
     Linker scripts for linking the test program on the `d10v-elf' and
2448
     `m32r-elf' targets.
2449
 
2450
   You can build the test program using the `d10v-elf' GCC
2451
cross-compiler like this:
2452
 
2453
     $ d10v-elf-gcc -g -c overlays.c
2454
     $ d10v-elf-gcc -g -c ovlymgr.c
2455
     $ d10v-elf-gcc -g -c foo.c
2456
     $ d10v-elf-gcc -g -c bar.c
2457
     $ d10v-elf-gcc -g -c baz.c
2458
     $ d10v-elf-gcc -g -c grbx.c
2459
     $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
2460
                       baz.o grbx.o -Wl,-Td10v.ld -o overlays
2461
 
2462
   The build process is identical for any other architecture, except
2463
that you must substitute the appropriate compiler and linker script for
2464
the target system for `d10v-elf-gcc' and `d10v.ld'.
2465
 
2466

2467
File: gdb.info,  Node: Languages,  Next: Symbols,  Prev: Overlays,  Up: Top
2468
 
2469
15 Using GDB with Different Languages
2470
*************************************
2471
 
2472
Although programming languages generally have common aspects, they are
2473
rarely expressed in the same manner.  For instance, in ANSI C,
2474
dereferencing a pointer `p' is accomplished by `*p', but in Modula-2,
2475
it is accomplished by `p^'.  Values can also be represented (and
2476
displayed) differently.  Hex numbers in C appear as `0x1ae', while in
2477
Modula-2 they appear as `1AEH'.
2478
 
2479
   Language-specific information is built into GDB for some languages,
2480
allowing you to express operations like the above in your program's
2481
native language, and allowing GDB to output values in a manner
2482
consistent with the syntax of your program's native language.  The
2483
language you use to build expressions is called the "working language".
2484
 
2485
* Menu:
2486
 
2487
* Setting::                     Switching between source languages
2488
* Show::                        Displaying the language
2489
* Checks::                      Type and range checks
2490
* Supported Languages::         Supported languages
2491
* Unsupported Languages::       Unsupported languages
2492
 
2493

2494
File: gdb.info,  Node: Setting,  Next: Show,  Up: Languages
2495
 
2496
15.1 Switching Between Source Languages
2497
=======================================
2498
 
2499
There are two ways to control the working language--either have GDB set
2500
it automatically, or select it manually yourself.  You can use the `set
2501
language' command for either purpose.  On startup, GDB defaults to
2502
setting the language automatically.  The working language is used to
2503
determine how expressions you type are interpreted, how values are
2504
printed, etc.
2505
 
2506
   In addition to the working language, every source file that GDB
2507
knows about has its own working language.  For some object file
2508
formats, the compiler might indicate which language a particular source
2509
file is in.  However, most of the time GDB infers the language from the
2510
name of the file.  The language of a source file controls whether C++
2511
names are demangled--this way `backtrace' can show each frame
2512
appropriately for its own language.  There is no way to set the
2513
language of a source file from within GDB, but you can set the language
2514
associated with a filename extension.  *Note Displaying the Language:
2515
Show.
2516
 
2517
   This is most commonly a problem when you use a program, such as
2518
`cfront' or `f2c', that generates C but is written in another language.
2519
In that case, make the program use `#line' directives in its C output;
2520
that way GDB will know the correct language of the source code of the
2521
original program, and will display that source code, not the generated
2522
C code.
2523
 
2524
* Menu:
2525
 
2526
* Filenames::                   Filename extensions and languages.
2527
* Manually::                    Setting the working language manually
2528
* Automatically::               Having GDB infer the source language
2529
 
2530

2531
File: gdb.info,  Node: Filenames,  Next: Manually,  Up: Setting
2532
 
2533
15.1.1 List of Filename Extensions and Languages
2534
------------------------------------------------
2535
 
2536
If a source file name ends in one of the following extensions, then GDB
2537
infers that its language is the one indicated.
2538
 
2539
`.ada'
2540
`.ads'
2541
`.adb'
2542
`.a'
2543
     Ada source file.
2544
 
2545
`.c'
2546
     C source file
2547
 
2548
`.C'
2549
`.cc'
2550
`.cp'
2551
`.cpp'
2552
`.cxx'
2553
`.c++'
2554
     C++ source file
2555
 
2556
`.d'
2557
     D source file
2558
 
2559
`.m'
2560
     Objective-C source file
2561
 
2562
`.f'
2563
`.F'
2564
     Fortran source file
2565
 
2566
`.mod'
2567
     Modula-2 source file
2568
 
2569
`.s'
2570
`.S'
2571
     Assembler source file.  This actually behaves almost like C, but
2572
     GDB does not skip over function prologues when stepping.
2573
 
2574
   In addition, you may set the language associated with a filename
2575
extension.  *Note Displaying the Language: Show.
2576
 
2577

2578
File: gdb.info,  Node: Manually,  Next: Automatically,  Prev: Filenames,  Up: Setting
2579
 
2580
15.1.2 Setting the Working Language
2581
-----------------------------------
2582
 
2583
If you allow GDB to set the language automatically, expressions are
2584
interpreted the same way in your debugging session and your program.
2585
 
2586
   If you wish, you may set the language manually.  To do this, issue
2587
the command `set language LANG', where LANG is the name of a language,
2588
such as `c' or `modula-2'.  For a list of the supported languages, type
2589
`set language'.
2590
 
2591
   Setting the language manually prevents GDB from updating the working
2592
language automatically.  This can lead to confusion if you try to debug
2593
a program when the working language is not the same as the source
2594
language, when an expression is acceptable to both languages--but means
2595
different things.  For instance, if the current source file were
2596
written in C, and GDB was parsing Modula-2, a command such as:
2597
 
2598
     print a = b + c
2599
 
2600
might not have the effect you intended.  In C, this means to add `b'
2601
and `c' and place the result in `a'.  The result printed would be the
2602
value of `a'.  In Modula-2, this means to compare `a' to the result of
2603
`b+c', yielding a `BOOLEAN' value.
2604
 
2605

2606
File: gdb.info,  Node: Automatically,  Prev: Manually,  Up: Setting
2607
 
2608
15.1.3 Having GDB Infer the Source Language
2609
-------------------------------------------
2610
 
2611
To have GDB set the working language automatically, use `set language
2612
local' or `set language auto'.  GDB then infers the working language.
2613
That is, when your program stops in a frame (usually by encountering a
2614
breakpoint), GDB sets the working language to the language recorded for
2615
the function in that frame.  If the language for a frame is unknown
2616
(that is, if the function or block corresponding to the frame was
2617
defined in a source file that does not have a recognized extension),
2618
the current working language is not changed, and GDB issues a warning.
2619
 
2620
   This may not seem necessary for most programs, which are written
2621
entirely in one source language.  However, program modules and libraries
2622
written in one source language can be used by a main program written in
2623
a different source language.  Using `set language auto' in this case
2624
frees you from having to set the working language manually.
2625
 
2626

2627
File: gdb.info,  Node: Show,  Next: Checks,  Prev: Setting,  Up: Languages
2628
 
2629
15.2 Displaying the Language
2630
============================
2631
 
2632
The following commands help you find out which language is the working
2633
language, and also what language source files were written in.
2634
 
2635
`show language'
2636
     Display the current working language.  This is the language you
2637
     can use with commands such as `print' to build and compute
2638
     expressions that may involve variables in your program.
2639
 
2640
`info frame'
2641
     Display the source language for this frame.  This language becomes
2642
     the working language if you use an identifier from this frame.
2643
     *Note Information about a Frame: Frame Info, to identify the other
2644
     information listed here.
2645
 
2646
`info source'
2647
     Display the source language of this source file.  *Note Examining
2648
     the Symbol Table: Symbols, to identify the other information
2649
     listed here.
2650
 
2651
   In unusual circumstances, you may have source files with extensions
2652
not in the standard list.  You can then set the extension associated
2653
with a language explicitly:
2654
 
2655
`set extension-language EXT LANGUAGE'
2656
     Tell GDB that source files with extension EXT are to be assumed as
2657
     written in the source language LANGUAGE.
2658
 
2659
`info extensions'
2660
     List all the filename extensions and the associated languages.
2661
 
2662

2663
File: gdb.info,  Node: Checks,  Next: Supported Languages,  Prev: Show,  Up: Languages
2664
 
2665
15.3 Type and Range Checking
2666
============================
2667
 
2668
     _Warning:_ In this release, the GDB commands for type and range
2669
     checking are included, but they do not yet have any effect.  This
2670
     section documents the intended facilities.
2671
 
2672
   Some languages are designed to guard you against making seemingly
2673
common errors through a series of compile- and run-time checks.  These
2674
include checking the type of arguments to functions and operators, and
2675
making sure mathematical overflows are caught at run time.  Checks such
2676
as these help to ensure a program's correctness once it has been
2677
compiled by eliminating type mismatches, and providing active checks
2678
for range errors when your program is running.
2679
 
2680
   GDB can check for conditions like the above if you wish.  Although
2681
GDB does not check the statements in your program, it can check
2682
expressions entered directly into GDB for evaluation via the `print'
2683
command, for example.  As with the working language, GDB can also
2684
decide whether or not to check automatically based on your program's
2685
source language.  *Note Supported Languages: Supported Languages, for
2686
the default settings of supported languages.
2687
 
2688
* Menu:
2689
 
2690
* Type Checking::               An overview of type checking
2691
* Range Checking::              An overview of range checking
2692
 
2693

2694
File: gdb.info,  Node: Type Checking,  Next: Range Checking,  Up: Checks
2695
 
2696
15.3.1 An Overview of Type Checking
2697
-----------------------------------
2698
 
2699
Some languages, such as Modula-2, are strongly typed, meaning that the
2700
arguments to operators and functions have to be of the correct type,
2701
otherwise an error occurs.  These checks prevent type mismatch errors
2702
from ever causing any run-time problems.  For example,
2703
 
2704
     1 + 2 => 3
2705
but
2706
     error--> 1 + 2.3
2707
 
2708
   The second example fails because the `CARDINAL' 1 is not
2709
type-compatible with the `REAL' 2.3.
2710
 
2711
   For the expressions you use in GDB commands, you can tell the GDB
2712
type checker to skip checking; to treat any mismatches as errors and
2713
abandon the expression; or to only issue warnings when type mismatches
2714
occur, but evaluate the expression anyway.  When you choose the last of
2715
these, GDB evaluates expressions like the second example above, but
2716
also issues a warning.
2717
 
2718
   Even if you turn type checking off, there may be other reasons
2719
related to type that prevent GDB from evaluating an expression.  For
2720
instance, GDB does not know how to add an `int' and a `struct foo'.
2721
These particular type errors have nothing to do with the language in
2722
use, and usually arise from expressions, such as the one described
2723
above, which make little sense to evaluate anyway.
2724
 
2725
   Each language defines to what degree it is strict about type.  For
2726
instance, both Modula-2 and C require the arguments to arithmetical
2727
operators to be numbers.  In C, enumerated types and pointers can be
2728
represented as numbers, so that they are valid arguments to mathematical
2729
operators.  *Note Supported Languages: Supported Languages, for further
2730
details on specific languages.
2731
 
2732
   GDB provides some additional commands for controlling the type
2733
checker:
2734
 
2735
`set check type auto'
2736
     Set type checking on or off based on the current working language.
2737
     *Note Supported Languages: Supported Languages, for the default
2738
     settings for each language.
2739
 
2740
`set check type on'
2741
`set check type off'
2742
     Set type checking on or off, overriding the default setting for the
2743
     current working language.  Issue a warning if the setting does not
2744
     match the language default.  If any type mismatches occur in
2745
     evaluating an expression while type checking is on, GDB prints a
2746
     message and aborts evaluation of the expression.
2747
 
2748
`set check type warn'
2749
     Cause the type checker to issue warnings, but to always attempt to
2750
     evaluate the expression.  Evaluating the expression may still be
2751
     impossible for other reasons.  For example, GDB cannot add numbers
2752
     and structures.
2753
 
2754
`show type'
2755
     Show the current setting of the type checker, and whether or not
2756
     GDB is setting it automatically.
2757
 
2758

2759
File: gdb.info,  Node: Range Checking,  Prev: Type Checking,  Up: Checks
2760
 
2761
15.3.2 An Overview of Range Checking
2762
------------------------------------
2763
 
2764
In some languages (such as Modula-2), it is an error to exceed the
2765
bounds of a type; this is enforced with run-time checks.  Such range
2766
checking is meant to ensure program correctness by making sure
2767
computations do not overflow, or indices on an array element access do
2768
not exceed the bounds of the array.
2769
 
2770
   For expressions you use in GDB commands, you can tell GDB to treat
2771
range errors in one of three ways: ignore them, always treat them as
2772
errors and abandon the expression, or issue warnings but evaluate the
2773
expression anyway.
2774
 
2775
   A range error can result from numerical overflow, from exceeding an
2776
array index bound, or when you type a constant that is not a member of
2777
any type.  Some languages, however, do not treat overflows as an error.
2778
In many implementations of C, mathematical overflow causes the result
2779
to "wrap around" to lower values--for example, if M is the largest
2780
integer value, and S is the smallest, then
2781
 
2782
     M + 1 => S
2783
 
2784
   This, too, is specific to individual languages, and in some cases
2785
specific to individual compilers or machines.  *Note Supported
2786
Languages: Supported Languages, for further details on specific
2787
languages.
2788
 
2789
   GDB provides some additional commands for controlling the range
2790
checker:
2791
 
2792
`set check range auto'
2793
     Set range checking on or off based on the current working language.
2794
     *Note Supported Languages: Supported Languages, for the default
2795
     settings for each language.
2796
 
2797
`set check range on'
2798
`set check range off'
2799
     Set range checking on or off, overriding the default setting for
2800
     the current working language.  A warning is issued if the setting
2801
     does not match the language default.  If a range error occurs and
2802
     range checking is on, then a message is printed and evaluation of
2803
     the expression is aborted.
2804
 
2805
`set check range warn'
2806
     Output messages when the GDB range checker detects a range error,
2807
     but attempt to evaluate the expression anyway.  Evaluating the
2808
     expression may still be impossible for other reasons, such as
2809
     accessing memory that the process does not own (a typical example
2810
     from many Unix systems).
2811
 
2812
`show range'
2813
     Show the current setting of the range checker, and whether or not
2814
     it is being set automatically by GDB.
2815
 
2816

2817
File: gdb.info,  Node: Supported Languages,  Next: Unsupported Languages,  Prev: Checks,  Up: Languages
2818
 
2819
15.4 Supported Languages
2820
========================
2821
 
2822
GDB supports C, C++, D, Objective-C, Fortran, Java, Pascal, assembly,
2823
Modula-2, and Ada.  Some GDB features may be used in expressions
2824
regardless of the language you use: the GDB `@' and `::' operators, and
2825
the `{type}addr' construct (*note Expressions: Expressions.) can be
2826
used with the constructs of any supported language.
2827
 
2828
   The following sections detail to what degree each source language is
2829
supported by GDB.  These sections are not meant to be language
2830
tutorials or references, but serve only as a reference guide to what the
2831
GDB expression parser accepts, and what input and output formats should
2832
look like for different languages.  There are many good books written
2833
on each of these languages; please look to these for a language
2834
reference or tutorial.
2835
 
2836
* Menu:
2837
 
2838
* C::                           C and C++
2839
* D::                           D
2840
* Objective-C::                 Objective-C
2841
* Fortran::                     Fortran
2842
* Pascal::                      Pascal
2843
* Modula-2::                    Modula-2
2844
* Ada::                         Ada
2845
 
2846

2847
File: gdb.info,  Node: C,  Next: D,  Up: Supported Languages
2848
 
2849
15.4.1 C and C++
2850
----------------
2851
 
2852
Since C and C++ are so closely related, many features of GDB apply to
2853
both languages.  Whenever this is the case, we discuss those languages
2854
together.
2855
 
2856
   The C++ debugging facilities are jointly implemented by the C++
2857
compiler and GDB.  Therefore, to debug your C++ code effectively, you
2858
must compile your C++ programs with a supported C++ compiler, such as
2859
GNU `g++', or the HP ANSI C++ compiler (`aCC').
2860
 
2861
   For best results when using GNU C++, use the DWARF 2 debugging
2862
format; if it doesn't work on your system, try the stabs+ debugging
2863
format.  You can select those formats explicitly with the `g++'
2864
command-line options `-gdwarf-2' and `-gstabs+'.  *Note Options for
2865
Debugging Your Program or GCC: (gcc.info)Debugging Options.
2866
 
2867
* Menu:
2868
 
2869
* C Operators::                 C and C++ operators
2870
* C Constants::                 C and C++ constants
2871
* C Plus Plus Expressions::     C++ expressions
2872
* C Defaults::                  Default settings for C and C++
2873
* C Checks::                    C and C++ type and range checks
2874
* Debugging C::                 GDB and C
2875
* Debugging C Plus Plus::       GDB features for C++
2876
* Decimal Floating Point::      Numbers in Decimal Floating Point format
2877
 
2878

2879
File: gdb.info,  Node: C Operators,  Next: C Constants,  Up: C
2880
 
2881
15.4.1.1 C and C++ Operators
2882
............................
2883
 
2884
Operators must be defined on values of specific types.  For instance,
2885
`+' is defined on numbers, but not on structures.  Operators are often
2886
defined on groups of types.
2887
 
2888
   For the purposes of C and C++, the following definitions hold:
2889
 
2890
   * _Integral types_ include `int' with any of its storage-class
2891
     specifiers; `char'; `enum'; and, for C++, `bool'.
2892
 
2893
   * _Floating-point types_ include `float', `double', and `long
2894
     double' (if supported by the target platform).
2895
 
2896
   * _Pointer types_ include all types defined as `(TYPE *)'.
2897
 
2898
   * _Scalar types_ include all of the above.
2899
 
2900
 
2901
The following operators are supported.  They are listed here in order
2902
of increasing precedence:
2903
 
2904
`,'
2905
     The comma or sequencing operator.  Expressions in a
2906
     comma-separated list are evaluated from left to right, with the
2907
     result of the entire expression being the last expression
2908
     evaluated.
2909
 
2910
`='
2911
     Assignment.  The value of an assignment expression is the value
2912
     assigned.  Defined on scalar types.
2913
 
2914
`OP='
2915
     Used in an expression of the form `A OP= B', and translated to
2916
     `A = A OP B'.  `OP=' and `=' have the same precedence.  OP is any
2917
     one of the operators `|', `^', `&', `<<', `>>', `+', `-', `*',
2918
     `/', `%'.
2919
 
2920
`?:'
2921
     The ternary operator.  `A ? B : C' can be thought of as:  if A
2922
     then B else C.  A should be of an integral type.
2923
 
2924
`||'
2925
     Logical OR.  Defined on integral types.
2926
 
2927
`&&'
2928
     Logical AND.  Defined on integral types.
2929
 
2930
`|'
2931
     Bitwise OR.  Defined on integral types.
2932
 
2933
`^'
2934
     Bitwise exclusive-OR.  Defined on integral types.
2935
 
2936
`&'
2937
     Bitwise AND.  Defined on integral types.
2938
 
2939
`==, !='
2940
     Equality and inequality.  Defined on scalar types.  The value of
2941
     these expressions is 0 for false and non-zero for true.
2942
 
2943
`<, >, <=, >='
2944
     Less than, greater than, less than or equal, greater than or equal.
2945
     Defined on scalar types.  The value of these expressions is 0 for
2946
     false and non-zero for true.
2947
 
2948
`<<, >>'
2949
     left shift, and right shift.  Defined on integral types.
2950
 
2951
`@'
2952
     The GDB "artificial array" operator (*note Expressions:
2953
     Expressions.).
2954
 
2955
`+, -'
2956
     Addition and subtraction.  Defined on integral types,
2957
     floating-point types and pointer types.
2958
 
2959
`*, /, %'
2960
     Multiplication, division, and modulus.  Multiplication and
2961
     division are defined on integral and floating-point types.
2962
     Modulus is defined on integral types.
2963
 
2964
`++, --'
2965
     Increment and decrement.  When appearing before a variable, the
2966
     operation is performed before the variable is used in an
2967
     expression; when appearing after it, the variable's value is used
2968
     before the operation takes place.
2969
 
2970
`*'
2971
     Pointer dereferencing.  Defined on pointer types.  Same precedence
2972
     as `++'.
2973
 
2974
`&'
2975
     Address operator.  Defined on variables.  Same precedence as `++'.
2976
 
2977
     For debugging C++, GDB implements a use of `&' beyond what is
2978
     allowed in the C++ language itself: you can use `&(&REF)' to
2979
     examine the address where a C++ reference variable (declared with
2980
     `&REF') is stored.
2981
 
2982
`-'
2983
     Negative.  Defined on integral and floating-point types.  Same
2984
     precedence as `++'.
2985
 
2986
`!'
2987
     Logical negation.  Defined on integral types.  Same precedence as
2988
     `++'.
2989
 
2990
`~'
2991
     Bitwise complement operator.  Defined on integral types.  Same
2992
     precedence as `++'.
2993
 
2994
`., ->'
2995
     Structure member, and pointer-to-structure member.  For
2996
     convenience, GDB regards the two as equivalent, choosing whether
2997
     to dereference a pointer based on the stored type information.
2998
     Defined on `struct' and `union' data.
2999
 
3000
`.*, ->*'
3001
     Dereferences of pointers to members.
3002
 
3003
`[]'
3004
     Array indexing.  `A[I]' is defined as `*(A+I)'.  Same precedence
3005
     as `->'.
3006
 
3007
`()'
3008
     Function parameter list.  Same precedence as `->'.
3009
 
3010
`::'
3011
     C++ scope resolution operator.  Defined on `struct', `union', and
3012
     `class' types.
3013
 
3014
`::'
3015
     Doubled colons also represent the GDB scope operator (*note
3016
     Expressions: Expressions.).  Same precedence as `::', above.
3017
 
3018
   If an operator is redefined in the user code, GDB usually attempts
3019
to invoke the redefined version instead of using the operator's
3020
predefined meaning.
3021
 
3022

3023
File: gdb.info,  Node: C Constants,  Next: C Plus Plus Expressions,  Prev: C Operators,  Up: C
3024
 
3025
15.4.1.2 C and C++ Constants
3026
............................
3027
 
3028
GDB allows you to express the constants of C and C++ in the following
3029
ways:
3030
 
3031
   * Integer constants are a sequence of digits.  Octal constants are
3032
     specified by a leading `0' (i.e. zero), and hexadecimal constants
3033
     by a leading `0x' or `0X'.  Constants may also end with a letter
3034
     `l', specifying that the constant should be treated as a `long'
3035
     value.
3036
 
3037
   * Floating point constants are a sequence of digits, followed by a
3038
     decimal point, followed by a sequence of digits, and optionally
3039
     followed by an exponent.  An exponent is of the form:
3040
     `e[[+]|-]NNN', where NNN is another sequence of digits.  The `+'
3041
     is optional for positive exponents.  A floating-point constant may
3042
     also end with a letter `f' or `F', specifying that the constant
3043
     should be treated as being of the `float' (as opposed to the
3044
     default `double') type; or with a letter `l' or `L', which
3045
     specifies a `long double' constant.
3046
 
3047
   * Enumerated constants consist of enumerated identifiers, or their
3048
     integral equivalents.
3049
 
3050
   * Character constants are a single character surrounded by single
3051
     quotes (`''), or a number--the ordinal value of the corresponding
3052
     character (usually its ASCII value).  Within quotes, the single
3053
     character may be represented by a letter or by "escape sequences",
3054
     which are of the form `\NNN', where NNN is the octal representation
3055
     of the character's ordinal value; or of the form `\X', where `X'
3056
     is a predefined special character--for example, `\n' for newline.
3057
 
3058
   * String constants are a sequence of character constants surrounded
3059
     by double quotes (`"').  Any valid character constant (as described
3060
     above) may appear.  Double quotes within the string must be
3061
     preceded by a backslash, so for instance `"a\"b'c"' is a string of
3062
     five characters.
3063
 
3064
   * Pointer constants are an integral value.  You can also write
3065
     pointers to constants using the C operator `&'.
3066
 
3067
   * Array constants are comma-separated lists surrounded by braces `{'
3068
     and `}'; for example, `{1,2,3}' is a three-element array of
3069
     integers, `{{1,2}, {3,4}, {5,6}}' is a three-by-two array, and
3070
     `{&"hi", &"there", &"fred"}' is a three-element array of pointers.
3071
 
3072

3073
File: gdb.info,  Node: C Plus Plus Expressions,  Next: C Defaults,  Prev: C Constants,  Up: C
3074
 
3075
15.4.1.3 C++ Expressions
3076
........................
3077
 
3078
GDB expression handling can interpret most C++ expressions.
3079
 
3080
     _Warning:_ GDB can only debug C++ code if you use the proper
3081
     compiler and the proper debug format.  Currently, GDB works best
3082
     when debugging C++ code that is compiled with GCC 2.95.3 or with
3083
     GCC 3.1 or newer, using the options `-gdwarf-2' or `-gstabs+'.
3084
     DWARF 2 is preferred over stabs+.  Most configurations of GCC emit
3085
     either DWARF 2 or stabs+ as their default debug format, so you
3086
     usually don't need to specify a debug format explicitly.  Other
3087
     compilers and/or debug formats are likely to work badly or not at
3088
     all when using GDB to debug C++ code.
3089
 
3090
  1. Member function calls are allowed; you can use expressions like
3091
 
3092
          count = aml->GetOriginal(x, y)
3093
 
3094
  2. While a member function is active (in the selected stack frame),
3095
     your expressions have the same namespace available as the member
3096
     function; that is, GDB allows implicit references to the class
3097
     instance pointer `this' following the same rules as C++.
3098
 
3099
  3. You can call overloaded functions; GDB resolves the function call
3100
     to the right definition, with some restrictions.  GDB does not
3101
     perform overload resolution involving user-defined type
3102
     conversions, calls to constructors, or instantiations of templates
3103
     that do not exist in the program.  It also cannot handle ellipsis
3104
     argument lists or default arguments.
3105
 
3106
     It does perform integral conversions and promotions, floating-point
3107
     promotions, arithmetic conversions, pointer conversions,
3108
     conversions of class objects to base classes, and standard
3109
     conversions such as those of functions or arrays to pointers; it
3110
     requires an exact match on the number of function arguments.
3111
 
3112
     Overload resolution is always performed, unless you have specified
3113
     `set overload-resolution off'.  *Note GDB Features for C++:
3114
     Debugging C Plus Plus.
3115
 
3116
     You must specify `set overload-resolution off' in order to use an
3117
     explicit function signature to call an overloaded function, as in
3118
          p 'foo(char,int)'('x', 13)
3119
 
3120
     The GDB command-completion facility can simplify this; see *Note
3121
     Command Completion: Completion.
3122
 
3123
  4. GDB understands variables declared as C++ references; you can use
3124
     them in expressions just as you do in C++ source--they are
3125
     automatically dereferenced.
3126
 
3127
     In the parameter list shown when GDB displays a frame, the values
3128
     of reference variables are not displayed (unlike other variables);
3129
     this avoids clutter, since references are often used for large
3130
     structures.  The _address_ of a reference variable is always
3131
     shown, unless you have specified `set print address off'.
3132
 
3133
  5. GDB supports the C++ name resolution operator `::'--your
3134
     expressions can use it just as expressions in your program do.
3135
     Since one scope may be defined in another, you can use `::'
3136
     repeatedly if necessary, for example in an expression like
3137
     `SCOPE1::SCOPE2::NAME'.  GDB also allows resolving name scope by
3138
     reference to source files, in both C and C++ debugging (*note
3139
     Program Variables: Variables.).
3140
 
3141
   In addition, when used with HP's C++ compiler, GDB supports calling
3142
virtual functions correctly, printing out virtual bases of objects,
3143
calling functions in a base subobject, casting objects, and invoking
3144
user-defined operators.
3145
 
3146

3147
File: gdb.info,  Node: C Defaults,  Next: C Checks,  Prev: C Plus Plus Expressions,  Up: C
3148
 
3149
15.4.1.4 C and C++ Defaults
3150
...........................
3151
 
3152
If you allow GDB to set type and range checking automatically, they
3153
both default to `off' whenever the working language changes to C or
3154
C++.  This happens regardless of whether you or GDB selects the working
3155
language.
3156
 
3157
   If you allow GDB to set the language automatically, it recognizes
3158
source files whose names end with `.c', `.C', or `.cc', etc, and when
3159
GDB enters code compiled from one of these files, it sets the working
3160
language to C or C++.  *Note Having GDB Infer the Source Language:
3161
Automatically, for further details.
3162
 
3163

3164
File: gdb.info,  Node: C Checks,  Next: Debugging C,  Prev: C Defaults,  Up: C
3165
 
3166
15.4.1.5 C and C++ Type and Range Checks
3167
........................................
3168
 
3169
By default, when GDB parses C or C++ expressions, type checking is not
3170
used.  However, if you turn type checking on, GDB considers two
3171
variables type equivalent if:
3172
 
3173
   * The two variables are structured and have the same structure,
3174
     union, or enumerated tag.
3175
 
3176
   * The two variables have the same type name, or types that have been
3177
     declared equivalent through `typedef'.
3178
 
3179
 
3180
   Range checking, if turned on, is done on mathematical operations.
3181
Array indices are not checked, since they are often used to index a
3182
pointer that is not itself an array.
3183
 
3184

3185
File: gdb.info,  Node: Debugging C,  Next: Debugging C Plus Plus,  Prev: C Checks,  Up: C
3186
 
3187
15.4.1.6 GDB and C
3188
..................
3189
 
3190
The `set print union' and `show print union' commands apply to the
3191
`union' type.  When set to `on', any `union' that is inside a `struct'
3192
or `class' is also printed.  Otherwise, it appears as `{...}'.
3193
 
3194
   The `@' operator aids in the debugging of dynamic arrays, formed
3195
with pointers and a memory allocation function.  *Note Expressions:
3196
Expressions.
3197
 
3198

3199
File: gdb.info,  Node: Debugging C Plus Plus,  Next: Decimal Floating Point,  Prev: Debugging C,  Up: C
3200
 
3201
15.4.1.7 GDB Features for C++
3202
.............................
3203
 
3204
Some GDB commands are particularly useful with C++, and some are
3205
designed specifically for use with C++.  Here is a summary:
3206
 
3207
`breakpoint menus'
3208
     When you want a breakpoint in a function whose name is overloaded,
3209
     GDB has the capability to display a menu of possible breakpoint
3210
     locations to help you specify which function definition you want.
3211
     *Note Ambiguous Expressions: Ambiguous Expressions.
3212
 
3213
`rbreak REGEX'
3214
     Setting breakpoints using regular expressions is helpful for
3215
     setting breakpoints on overloaded functions that are not members
3216
     of any special classes.  *Note Setting Breakpoints: Set Breaks.
3217
 
3218
`catch throw'
3219
`catch catch'
3220
     Debug C++ exception handling using these commands.  *Note Setting
3221
     Catchpoints: Set Catchpoints.
3222
 
3223
`ptype TYPENAME'
3224
     Print inheritance relationships as well as other information for
3225
     type TYPENAME.  *Note Examining the Symbol Table: Symbols.
3226
 
3227
`set print demangle'
3228
`show print demangle'
3229
`set print asm-demangle'
3230
`show print asm-demangle'
3231
     Control whether C++ symbols display in their source form, both when
3232
     displaying code as C++ source and when displaying disassemblies.
3233
     *Note Print Settings: Print Settings.
3234
 
3235
`set print object'
3236
`show print object'
3237
     Choose whether to print derived (actual) or declared types of
3238
     objects.  *Note Print Settings: Print Settings.
3239
 
3240
`set print vtbl'
3241
`show print vtbl'
3242
     Control the format for printing virtual function tables.  *Note
3243
     Print Settings: Print Settings.  (The `vtbl' commands do not work
3244
     on programs compiled with the HP ANSI C++ compiler (`aCC').)
3245
 
3246
`set overload-resolution on'
3247
     Enable overload resolution for C++ expression evaluation.  The
3248
     default is on.  For overloaded functions, GDB evaluates the
3249
     arguments and searches for a function whose signature matches the
3250
     argument types, using the standard C++ conversion rules (see *Note
3251
     C++ Expressions: C Plus Plus Expressions, for details).  If it
3252
     cannot find a match, it emits a message.
3253
 
3254
`set overload-resolution off'
3255
     Disable overload resolution for C++ expression evaluation.  For
3256
     overloaded functions that are not class member functions, GDB
3257
     chooses the first function of the specified name that it finds in
3258
     the symbol table, whether or not its arguments are of the correct
3259
     type.  For overloaded functions that are class member functions,
3260
     GDB searches for a function whose signature _exactly_ matches the
3261
     argument types.
3262
 
3263
`show overload-resolution'
3264
     Show the current setting of overload resolution.
3265
 
3266
`Overloaded symbol names'
3267
     You can specify a particular definition of an overloaded symbol,
3268
     using the same notation that is used to declare such symbols in
3269
     C++: type `SYMBOL(TYPES)' rather than just SYMBOL.  You can also
3270
     use the GDB command-line word completion facilities to list the
3271
     available choices, or to finish the type list for you.  *Note
3272
     Command Completion: Completion, for details on how to do this.
3273
 
3274

3275
File: gdb.info,  Node: Decimal Floating Point,  Prev: Debugging C Plus Plus,  Up: C
3276
 
3277
15.4.1.8 Decimal Floating Point format
3278
......................................
3279
 
3280
GDB can examine, set and perform computations with numbers in decimal
3281
floating point format, which in the C language correspond to the
3282
`_Decimal32', `_Decimal64' and `_Decimal128' types as specified by the
3283
extension to support decimal floating-point arithmetic.
3284
 
3285
   There are two encodings in use, depending on the architecture: BID
3286
(Binary Integer Decimal) for x86 and x86-64, and DPD (Densely Packed
3287
Decimal) for PowerPC.  GDB will use the appropriate encoding for the
3288
configured target.
3289
 
3290
   Because of a limitation in `libdecnumber', the library used by GDB
3291
to manipulate decimal floating point numbers, it is not possible to
3292
convert (using a cast, for example) integers wider than 32-bit to
3293
decimal float.
3294
 
3295
   In addition, in order to imitate GDB's behaviour with binary floating
3296
point computations, error checking in decimal float operations ignores
3297
underflow, overflow and divide by zero exceptions.
3298
 
3299
   In the PowerPC architecture, GDB provides a set of pseudo-registers
3300
to inspect `_Decimal128' values stored in floating point registers.
3301
See *Note PowerPC: PowerPC. for more details.
3302
 
3303

3304
File: gdb.info,  Node: D,  Next: Objective-C,  Prev: C,  Up: Supported Languages
3305
 
3306
15.4.2 D
3307
--------
3308
 
3309
GDB can be used to debug programs written in D and compiled with GDC,
3310
LDC or DMD compilers. Currently GDB supports only one D specific
3311
feature -- dynamic arrays.
3312
 
3313

3314
File: gdb.info,  Node: Objective-C,  Next: Fortran,  Prev: D,  Up: Supported Languages
3315
 
3316
15.4.3 Objective-C
3317
------------------
3318
 
3319
This section provides information about some commands and command
3320
options that are useful for debugging Objective-C code.  See also *Note
3321
info classes: Symbols, and *Note info selectors: Symbols, for a few
3322
more commands specific to Objective-C support.
3323
 
3324
* Menu:
3325
 
3326
* Method Names in Commands::
3327
* The Print Command with Objective-C::
3328
 
3329

3330
File: gdb.info,  Node: Method Names in Commands,  Next: The Print Command with Objective-C,  Up: Objective-C
3331
 
3332
15.4.3.1 Method Names in Commands
3333
.................................
3334
 
3335
The following commands have been extended to accept Objective-C method
3336
names as line specifications:
3337
 
3338
   * `clear'
3339
 
3340
   * `break'
3341
 
3342
   * `info line'
3343
 
3344
   * `jump'
3345
 
3346
   * `list'
3347
 
3348
   A fully qualified Objective-C method name is specified as
3349
 
3350
     -[CLASS METHODNAME]
3351
 
3352
   where the minus sign is used to indicate an instance method and a
3353
plus sign (not shown) is used to indicate a class method.  The class
3354
name CLASS and method name METHODNAME are enclosed in brackets, similar
3355
to the way messages are specified in Objective-C source code.  For
3356
example, to set a breakpoint at the `create' instance method of class
3357
`Fruit' in the program currently being debugged, enter:
3358
 
3359
     break -[Fruit create]
3360
 
3361
   To list ten program lines around the `initialize' class method,
3362
enter:
3363
 
3364
     list +[NSText initialize]
3365
 
3366
   In the current version of GDB, the plus or minus sign is required.
3367
In future versions of GDB, the plus or minus sign will be optional, but
3368
you can use it to narrow the search.  It is also possible to specify
3369
just a method name:
3370
 
3371
     break create
3372
 
3373
   You must specify the complete method name, including any colons.  If
3374
your program's source files contain more than one `create' method,
3375
you'll be presented with a numbered list of classes that implement that
3376
method.  Indicate your choice by number, or type `0' to exit if none
3377
apply.
3378
 
3379
   As another example, to clear a breakpoint established at the
3380
`makeKeyAndOrderFront:' method of the `NSWindow' class, enter:
3381
 
3382
     clear -[NSWindow makeKeyAndOrderFront:]
3383
 
3384

3385
File: gdb.info,  Node: The Print Command with Objective-C,  Prev: Method Names in Commands,  Up: Objective-C
3386
 
3387
15.4.3.2 The Print Command With Objective-C
3388
...........................................
3389
 
3390
The print command has also been extended to accept methods.  For
3391
example:
3392
 
3393
     print -[OBJECT hash]
3394
 
3395
will tell GDB to send the `hash' message to OBJECT and print the
3396
result.  Also, an additional command has been added, `print-object' or
3397
`po' for short, which is meant to print the description of an object.
3398
However, this command may only work with certain Objective-C libraries
3399
that have a particular hook function, `_NSPrintForDebugger', defined.
3400
 
3401

3402
File: gdb.info,  Node: Fortran,  Next: Pascal,  Prev: Objective-C,  Up: Supported Languages
3403
 
3404
15.4.4 Fortran
3405
--------------
3406
 
3407
GDB can be used to debug programs written in Fortran, but it currently
3408
supports only the features of Fortran 77 language.
3409
 
3410
   Some Fortran compilers (GNU Fortran 77 and Fortran 95 compilers
3411
among them) append an underscore to the names of variables and
3412
functions.  When you debug programs compiled by those compilers, you
3413
will need to refer to variables and functions with a trailing
3414
underscore.
3415
 
3416
* Menu:
3417
 
3418
* Fortran Operators::           Fortran operators and expressions
3419
* Fortran Defaults::            Default settings for Fortran
3420
* Special Fortran Commands::    Special GDB commands for Fortran
3421
 
3422

3423
File: gdb.info,  Node: Fortran Operators,  Next: Fortran Defaults,  Up: Fortran
3424
 
3425
15.4.4.1 Fortran Operators and Expressions
3426
..........................................
3427
 
3428
Operators must be defined on values of specific types.  For instance,
3429
`+' is defined on numbers, but not on characters or other non-
3430
arithmetic types.  Operators are often defined on groups of types.
3431
 
3432
`**'
3433
     The exponentiation operator.  It raises the first operand to the
3434
     power of the second one.
3435
 
3436
`:'
3437
     The range operator.  Normally used in the form of array(low:high)
3438
     to represent a section of array.
3439
 
3440
`%'
3441
     The access component operator.  Normally used to access elements
3442
     in derived types.  Also suitable for unions.  As unions aren't
3443
     part of regular Fortran, this can only happen when accessing a
3444
     register that uses a gdbarch-defined union type.
3445
 
3446

3447
File: gdb.info,  Node: Fortran Defaults,  Next: Special Fortran Commands,  Prev: Fortran Operators,  Up: Fortran
3448
 
3449
15.4.4.2 Fortran Defaults
3450
.........................
3451
 
3452
Fortran symbols are usually case-insensitive, so GDB by default uses
3453
case-insensitive matches for Fortran symbols.  You can change that with
3454
the `set case-insensitive' command, see *Note Symbols::, for the
3455
details.
3456
 
3457

3458
File: gdb.info,  Node: Special Fortran Commands,  Prev: Fortran Defaults,  Up: Fortran
3459
 
3460
15.4.4.3 Special Fortran Commands
3461
.................................
3462
 
3463
GDB has some commands to support Fortran-specific features, such as
3464
displaying common blocks.
3465
 
3466
`info common [COMMON-NAME]'
3467
     This command prints the values contained in the Fortran `COMMON'
3468
     block whose name is COMMON-NAME.  With no argument, the names of
3469
     all `COMMON' blocks visible at the current program location are
3470
     printed.
3471
 
3472

3473
File: gdb.info,  Node: Pascal,  Next: Modula-2,  Prev: Fortran,  Up: Supported Languages
3474
 
3475
15.4.5 Pascal
3476
-------------
3477
 
3478
Debugging Pascal programs which use sets, subranges, file variables, or
3479
nested functions does not currently work.  GDB does not support
3480
entering expressions, printing values, or similar features using Pascal
3481
syntax.
3482
 
3483
   The Pascal-specific command `set print pascal_static-members'
3484
controls whether static members of Pascal objects are displayed.  *Note
3485
pascal_static-members: Print Settings.
3486
 
3487

3488
File: gdb.info,  Node: Modula-2,  Next: Ada,  Prev: Pascal,  Up: Supported Languages
3489
 
3490
15.4.6 Modula-2
3491
---------------
3492
 
3493
The extensions made to GDB to support Modula-2 only support output from
3494
the GNU Modula-2 compiler (which is currently being developed).  Other
3495
Modula-2 compilers are not currently supported, and attempting to debug
3496
executables produced by them is most likely to give an error as GDB
3497
reads in the executable's symbol table.
3498
 
3499
* Menu:
3500
 
3501
* M2 Operators::                Built-in operators
3502
* Built-In Func/Proc::          Built-in functions and procedures
3503
* M2 Constants::                Modula-2 constants
3504
* M2 Types::                    Modula-2 types
3505
* M2 Defaults::                 Default settings for Modula-2
3506
* Deviations::                  Deviations from standard Modula-2
3507
* M2 Checks::                   Modula-2 type and range checks
3508
* M2 Scope::                    The scope operators `::' and `.'
3509
* GDB/M2::                      GDB and Modula-2
3510
 
3511

3512
File: gdb.info,  Node: M2 Operators,  Next: Built-In Func/Proc,  Up: Modula-2
3513
 
3514
15.4.6.1 Operators
3515
..................
3516
 
3517
Operators must be defined on values of specific types.  For instance,
3518
`+' is defined on numbers, but not on structures.  Operators are often
3519
defined on groups of types.  For the purposes of Modula-2, the
3520
following definitions hold:
3521
 
3522
   * _Integral types_ consist of `INTEGER', `CARDINAL', and their
3523
     subranges.
3524
 
3525
   * _Character types_ consist of `CHAR' and its subranges.
3526
 
3527
   * _Floating-point types_ consist of `REAL'.
3528
 
3529
   * _Pointer types_ consist of anything declared as `POINTER TO TYPE'.
3530
 
3531
   * _Scalar types_ consist of all of the above.
3532
 
3533
   * _Set types_ consist of `SET' and `BITSET' types.
3534
 
3535
   * _Boolean types_ consist of `BOOLEAN'.
3536
 
3537
The following operators are supported, and appear in order of
3538
increasing precedence:
3539
 
3540
`,'
3541
     Function argument or array index separator.
3542
 
3543
`:='
3544
     Assignment.  The value of VAR `:=' VALUE is VALUE.
3545
 
3546
`<, >'
3547
     Less than, greater than on integral, floating-point, or enumerated
3548
     types.
3549
 
3550
`<=, >='
3551
     Less than or equal to, greater than or equal to on integral,
3552
     floating-point and enumerated types, or set inclusion on set
3553
     types.  Same precedence as `<'.
3554
 
3555
`=, <>, #'
3556
     Equality and two ways of expressing inequality, valid on scalar
3557
     types.  Same precedence as `<'.  In GDB scripts, only `<>' is
3558
     available for inequality, since `#' conflicts with the script
3559
     comment character.
3560
 
3561
`IN'
3562
     Set membership.  Defined on set types and the types of their
3563
     members.  Same precedence as `<'.
3564
 
3565
`OR'
3566
     Boolean disjunction.  Defined on boolean types.
3567
 
3568
`AND, &'
3569
     Boolean conjunction.  Defined on boolean types.
3570
 
3571
`@'
3572
     The GDB "artificial array" operator (*note Expressions:
3573
     Expressions.).
3574
 
3575
`+, -'
3576
     Addition and subtraction on integral and floating-point types, or
3577
     union and difference on set types.
3578
 
3579
`*'
3580
     Multiplication on integral and floating-point types, or set
3581
     intersection on set types.
3582
 
3583
`/'
3584
     Division on floating-point types, or symmetric set difference on
3585
     set types.  Same precedence as `*'.
3586
 
3587
`DIV, MOD'
3588
     Integer division and remainder.  Defined on integral types.  Same
3589
     precedence as `*'.
3590
 
3591
`-'
3592
     Negative.  Defined on `INTEGER' and `REAL' data.
3593
 
3594
`^'
3595
     Pointer dereferencing.  Defined on pointer types.
3596
 
3597
`NOT'
3598
     Boolean negation.  Defined on boolean types.  Same precedence as
3599
     `^'.
3600
 
3601
`.'
3602
     `RECORD' field selector.  Defined on `RECORD' data.  Same
3603
     precedence as `^'.
3604
 
3605
`[]'
3606
     Array indexing.  Defined on `ARRAY' data.  Same precedence as `^'.
3607
 
3608
`()'
3609
     Procedure argument list.  Defined on `PROCEDURE' objects.  Same
3610
     precedence as `^'.
3611
 
3612
`::, .'
3613
     GDB and Modula-2 scope operators.
3614
 
3615
     _Warning:_ Set expressions and their operations are not yet
3616
     supported, so GDB treats the use of the operator `IN', or the use
3617
     of operators `+', `-', `*', `/', `=', , `<>', `#', `<=', and `>='
3618
     on sets as an error.
3619
 
3620

3621
File: gdb.info,  Node: Built-In Func/Proc,  Next: M2 Constants,  Prev: M2 Operators,  Up: Modula-2
3622
 
3623
15.4.6.2 Built-in Functions and Procedures
3624
..........................................
3625
 
3626
Modula-2 also makes available several built-in procedures and functions.
3627
In describing these, the following metavariables are used:
3628
 
3629
A
3630
     represents an `ARRAY' variable.
3631
 
3632
C
3633
     represents a `CHAR' constant or variable.
3634
 
3635
I
3636
     represents a variable or constant of integral type.
3637
 
3638
M
3639
     represents an identifier that belongs to a set.  Generally used in
3640
     the same function with the metavariable S.  The type of S should
3641
     be `SET OF MTYPE' (where MTYPE is the type of M).
3642
 
3643
N
3644
     represents a variable or constant of integral or floating-point
3645
     type.
3646
 
3647
R
3648
     represents a variable or constant of floating-point type.
3649
 
3650
T
3651
     represents a type.
3652
 
3653
V
3654
     represents a variable.
3655
 
3656
X
3657
     represents a variable or constant of one of many types.  See the
3658
     explanation of the function for details.
3659
 
3660
   All Modula-2 built-in procedures also return a result, described
3661
below.
3662
 
3663
`ABS(N)'
3664
     Returns the absolute value of N.
3665
 
3666
`CAP(C)'
3667
     If C is a lower case letter, it returns its upper case equivalent,
3668
     otherwise it returns its argument.
3669
 
3670
`CHR(I)'
3671
     Returns the character whose ordinal value is I.
3672
 
3673
`DEC(V)'
3674
     Decrements the value in the variable V by one.  Returns the new
3675
     value.
3676
 
3677
`DEC(V,I)'
3678
     Decrements the value in the variable V by I.  Returns the new
3679
     value.
3680
 
3681
`EXCL(M,S)'
3682
     Removes the element M from the set S.  Returns the new set.
3683
 
3684
`FLOAT(I)'
3685
     Returns the floating point equivalent of the integer I.
3686
 
3687
`HIGH(A)'
3688
     Returns the index of the last member of A.
3689
 
3690
`INC(V)'
3691
     Increments the value in the variable V by one.  Returns the new
3692
     value.
3693
 
3694
`INC(V,I)'
3695
     Increments the value in the variable V by I.  Returns the new
3696
     value.
3697
 
3698
`INCL(M,S)'
3699
     Adds the element M to the set S if it is not already there.
3700
     Returns the new set.
3701
 
3702
`MAX(T)'
3703
     Returns the maximum value of the type T.
3704
 
3705
`MIN(T)'
3706
     Returns the minimum value of the type T.
3707
 
3708
`ODD(I)'
3709
     Returns boolean TRUE if I is an odd number.
3710
 
3711
`ORD(X)'
3712
     Returns the ordinal value of its argument.  For example, the
3713
     ordinal value of a character is its ASCII value (on machines
3714
     supporting the ASCII character set).  X must be of an ordered
3715
     type, which include integral, character and enumerated types.
3716
 
3717
`SIZE(X)'
3718
     Returns the size of its argument.  X can be a variable or a type.
3719
 
3720
`TRUNC(R)'
3721
     Returns the integral part of R.
3722
 
3723
`TSIZE(X)'
3724
     Returns the size of its argument.  X can be a variable or a type.
3725
 
3726
`VAL(T,I)'
3727
     Returns the member of the type T whose ordinal value is I.
3728
 
3729
     _Warning:_  Sets and their operations are not yet supported, so
3730
     GDB treats the use of procedures `INCL' and `EXCL' as an error.
3731
 
3732

3733
File: gdb.info,  Node: M2 Constants,  Next: M2 Types,  Prev: Built-In Func/Proc,  Up: Modula-2
3734
 
3735
15.4.6.3 Constants
3736
..................
3737
 
3738
GDB allows you to express the constants of Modula-2 in the following
3739
ways:
3740
 
3741
   * Integer constants are simply a sequence of digits.  When used in an
3742
     expression, a constant is interpreted to be type-compatible with
3743
     the rest of the expression.  Hexadecimal integers are specified by
3744
     a trailing `H', and octal integers by a trailing `B'.
3745
 
3746
   * Floating point constants appear as a sequence of digits, followed
3747
     by a decimal point and another sequence of digits.  An optional
3748
     exponent can then be specified, in the form `E[+|-]NNN', where
3749
     `[+|-]NNN' is the desired exponent.  All of the digits of the
3750
     floating point constant must be valid decimal (base 10) digits.
3751
 
3752
   * Character constants consist of a single character enclosed by a
3753
     pair of like quotes, either single (`'') or double (`"').  They may
3754
     also be expressed by their ordinal value (their ASCII value,
3755
     usually) followed by a `C'.
3756
 
3757
   * String constants consist of a sequence of characters enclosed by a
3758
     pair of like quotes, either single (`'') or double (`"').  Escape
3759
     sequences in the style of C are also allowed.  *Note C and C++
3760
     Constants: C Constants, for a brief explanation of escape
3761
     sequences.
3762
 
3763
   * Enumerated constants consist of an enumerated identifier.
3764
 
3765
   * Boolean constants consist of the identifiers `TRUE' and `FALSE'.
3766
 
3767
   * Pointer constants consist of integral values only.
3768
 
3769
   * Set constants are not yet supported.
3770
 
3771

3772
File: gdb.info,  Node: M2 Types,  Next: M2 Defaults,  Prev: M2 Constants,  Up: Modula-2
3773
 
3774
15.4.6.4 Modula-2 Types
3775
.......................
3776
 
3777
Currently GDB can print the following data types in Modula-2 syntax:
3778
array types, record types, set types, pointer types, procedure types,
3779
enumerated types, subrange types and base types.  You can also print
3780
the contents of variables declared using these type.  This section
3781
gives a number of simple source code examples together with sample GDB
3782
sessions.
3783
 
3784
   The first example contains the following section of code:
3785
 
3786
     VAR
3787
        s: SET OF CHAR ;
3788
        r: [20..40] ;
3789
 
3790
and you can request GDB to interrogate the type and value of `r' and
3791
`s'.
3792
 
3793
     (gdb) print s
3794
     {'A'..'C', 'Z'}
3795
     (gdb) ptype s
3796
     SET OF CHAR
3797
     (gdb) print r
3798
     21
3799
     (gdb) ptype r
3800
     [20..40]
3801
 
3802
Likewise if your source code declares `s' as:
3803
 
3804
     VAR
3805
        s: SET ['A'..'Z'] ;
3806
 
3807
then you may query the type of `s' by:
3808
 
3809
     (gdb) ptype s
3810
     type = SET ['A'..'Z']
3811
 
3812
Note that at present you cannot interactively manipulate set
3813
expressions using the debugger.
3814
 
3815
   The following example shows how you might declare an array in
3816
Modula-2 and how you can interact with GDB to print its type and
3817
contents:
3818
 
3819
     VAR
3820
        s: ARRAY [-10..10] OF CHAR ;
3821
 
3822
     (gdb) ptype s
3823
     ARRAY [-10..10] OF CHAR
3824
 
3825
   Note that the array handling is not yet complete and although the
3826
type is printed correctly, expression handling still assumes that all
3827
arrays have a lower bound of zero and not `-10' as in the example above.
3828
 
3829
   Here are some more type related Modula-2 examples:
3830
 
3831
     TYPE
3832
        colour = (blue, red, yellow, green) ;
3833
        t = [blue..yellow] ;
3834
     VAR
3835
        s: t ;
3836
     BEGIN
3837
        s := blue ;
3838
 
3839
The GDB interaction shows how you can query the data type and value of
3840
a variable.
3841
 
3842
     (gdb) print s
3843
     $1 = blue
3844
     (gdb) ptype t
3845
     type = [blue..yellow]
3846
 
3847
In this example a Modula-2 array is declared and its contents
3848
displayed.  Observe that the contents are written in the same way as
3849
their `C' counterparts.
3850
 
3851
     VAR
3852
        s: ARRAY [1..5] OF CARDINAL ;
3853
     BEGIN
3854
        s[1] := 1 ;
3855
 
3856
     (gdb) print s
3857
     $1 = {1, 0, 0, 0, 0}
3858
     (gdb) ptype s
3859
     type = ARRAY [1..5] OF CARDINAL
3860
 
3861
   The Modula-2 language interface to GDB also understands pointer
3862
types as shown in this example:
3863
 
3864
     VAR
3865
        s: POINTER TO ARRAY [1..5] OF CARDINAL ;
3866
     BEGIN
3867
        NEW(s) ;
3868
        s^[1] := 1 ;
3869
 
3870
and you can request that GDB describes the type of `s'.
3871
 
3872
     (gdb) ptype s
3873
     type = POINTER TO ARRAY [1..5] OF CARDINAL
3874
 
3875
   GDB handles compound types as we can see in this example.  Here we
3876
combine array types, record types, pointer types and subrange types:
3877
 
3878
     TYPE
3879
        foo = RECORD
3880
                 f1: CARDINAL ;
3881
                 f2: CHAR ;
3882
                 f3: myarray ;
3883
              END ;
3884
 
3885
        myarray = ARRAY myrange OF CARDINAL ;
3886
        myrange = [-2..2] ;
3887
     VAR
3888
        s: POINTER TO ARRAY myrange OF foo ;
3889
 
3890
and you can ask GDB to describe the type of `s' as shown below.
3891
 
3892
     (gdb) ptype s
3893
     type = POINTER TO ARRAY [-2..2] OF foo = RECORD
3894
         f1 : CARDINAL;
3895
         f2 : CHAR;
3896
         f3 : ARRAY [-2..2] OF CARDINAL;
3897
     END
3898
 
3899

3900
File: gdb.info,  Node: M2 Defaults,  Next: Deviations,  Prev: M2 Types,  Up: Modula-2
3901
 
3902
15.4.6.5 Modula-2 Defaults
3903
..........................
3904
 
3905
If type and range checking are set automatically by GDB, they both
3906
default to `on' whenever the working language changes to Modula-2.
3907
This happens regardless of whether you or GDB selected the working
3908
language.
3909
 
3910
   If you allow GDB to set the language automatically, then entering
3911
code compiled from a file whose name ends with `.mod' sets the working
3912
language to Modula-2.  *Note Having GDB Infer the Source Language:
3913
Automatically, for further details.
3914
 
3915

3916
File: gdb.info,  Node: Deviations,  Next: M2 Checks,  Prev: M2 Defaults,  Up: Modula-2
3917
 
3918
15.4.6.6 Deviations from Standard Modula-2
3919
..........................................
3920
 
3921
A few changes have been made to make Modula-2 programs easier to debug.
3922
This is done primarily via loosening its type strictness:
3923
 
3924
   * Unlike in standard Modula-2, pointer constants can be formed by
3925
     integers.  This allows you to modify pointer variables during
3926
     debugging.  (In standard Modula-2, the actual address contained in
3927
     a pointer variable is hidden from you; it can only be modified
3928
     through direct assignment to another pointer variable or
3929
     expression that returned a pointer.)
3930
 
3931
   * C escape sequences can be used in strings and characters to
3932
     represent non-printable characters.  GDB prints out strings with
3933
     these escape sequences embedded.  Single non-printable characters
3934
     are printed using the `CHR(NNN)' format.
3935
 
3936
   * The assignment operator (`:=') returns the value of its right-hand
3937
     argument.
3938
 
3939
   * All built-in procedures both modify _and_ return their argument.
3940
 
3941

3942
File: gdb.info,  Node: M2 Checks,  Next: M2 Scope,  Prev: Deviations,  Up: Modula-2
3943
 
3944
15.4.6.7 Modula-2 Type and Range Checks
3945
.......................................
3946
 
3947
     _Warning:_ in this release, GDB does not yet perform type or range
3948
     checking.
3949
 
3950
   GDB considers two Modula-2 variables type equivalent if:
3951
 
3952
   * They are of types that have been declared equivalent via a `TYPE
3953
     T1 = T2' statement
3954
 
3955
   * They have been declared on the same line.  (Note:  This is true of
3956
     the GNU Modula-2 compiler, but it may not be true of other
3957
     compilers.)
3958
 
3959
   As long as type checking is enabled, any attempt to combine variables
3960
whose types are not equivalent is an error.
3961
 
3962
   Range checking is done on all mathematical operations, assignment,
3963
array index bounds, and all built-in functions and procedures.
3964
 
3965

3966
File: gdb.info,  Node: M2 Scope,  Next: GDB/M2,  Prev: M2 Checks,  Up: Modula-2
3967
 
3968
15.4.6.8 The Scope Operators `::' and `.'
3969
.........................................
3970
 
3971
There are a few subtle differences between the Modula-2 scope operator
3972
(`.') and the GDB scope operator (`::').  The two have similar syntax:
3973
 
3974
 
3975
     MODULE . ID
3976
     SCOPE :: ID
3977
 
3978
where SCOPE is the name of a module or a procedure, MODULE the name of
3979
a module, and ID is any declared identifier within your program, except
3980
another module.
3981
 
3982
   Using the `::' operator makes GDB search the scope specified by
3983
SCOPE for the identifier ID.  If it is not found in the specified
3984
scope, then GDB searches all scopes enclosing the one specified by
3985
SCOPE.
3986
 
3987
   Using the `.' operator makes GDB search the current scope for the
3988
identifier specified by ID that was imported from the definition module
3989
specified by MODULE.  With this operator, it is an error if the
3990
identifier ID was not imported from definition module MODULE, or if ID
3991
is not an identifier in MODULE.
3992
 
3993

3994
File: gdb.info,  Node: GDB/M2,  Prev: M2 Scope,  Up: Modula-2
3995
 
3996
15.4.6.9 GDB and Modula-2
3997
.........................
3998
 
3999
Some GDB commands have little use when debugging Modula-2 programs.
4000
Five subcommands of `set print' and `show print' apply specifically to
4001
C and C++: `vtbl', `demangle', `asm-demangle', `object', and `union'.
4002
The first four apply to C++, and the last to the C `union' type, which
4003
has no direct analogue in Modula-2.
4004
 
4005
   The `@' operator (*note Expressions: Expressions.), while available
4006
with any language, is not useful with Modula-2.  Its intent is to aid
4007
the debugging of "dynamic arrays", which cannot be created in Modula-2
4008
as they can in C or C++.  However, because an address can be specified
4009
by an integral constant, the construct `{TYPE}ADREXP' is still useful.
4010
 
4011
   In GDB scripts, the Modula-2 inequality operator `#' is interpreted
4012
as the beginning of a comment.  Use `<>' instead.
4013
 
4014

4015
File: gdb.info,  Node: Ada,  Prev: Modula-2,  Up: Supported Languages
4016
 
4017
15.4.7 Ada
4018
----------
4019
 
4020
The extensions made to GDB for Ada only support output from the GNU Ada
4021
(GNAT) compiler.  Other Ada compilers are not currently supported, and
4022
attempting to debug executables produced by them is most likely to be
4023
difficult.
4024
 
4025
* Menu:
4026
 
4027
* Ada Mode Intro::              General remarks on the Ada syntax
4028
                                   and semantics supported by Ada mode
4029
                                   in GDB.
4030
* Omissions from Ada::          Restrictions on the Ada expression syntax.
4031
* Additions to Ada::            Extensions of the Ada expression syntax.
4032
* Stopping Before Main Program:: Debugging the program during elaboration.
4033
* Ada Tasks::                   Listing and setting breakpoints in tasks.
4034
* Ada Tasks and Core Files::    Tasking Support when Debugging Core Files
4035
* Ada Glitches::                Known peculiarities of Ada mode.
4036
 
4037

4038
File: gdb.info,  Node: Ada Mode Intro,  Next: Omissions from Ada,  Up: Ada
4039
 
4040
15.4.7.1 Introduction
4041
.....................
4042
 
4043
The Ada mode of GDB supports a fairly large subset of Ada expression
4044
syntax, with some extensions.  The philosophy behind the design of this
4045
subset is
4046
 
4047
   * That GDB should provide basic literals and access to operations for
4048
     arithmetic, dereferencing, field selection, indexing, and
4049
     subprogram calls, leaving more sophisticated computations to
4050
     subprograms written into the program (which therefore may be
4051
     called from GDB).
4052
 
4053
   * That type safety and strict adherence to Ada language restrictions
4054
     are not particularly important to the GDB user.
4055
 
4056
   * That brevity is important to the GDB user.
4057
 
4058
   Thus, for brevity, the debugger acts as if all names declared in
4059
user-written packages are directly visible, even if they are not visible
4060
according to Ada rules, thus making it unnecessary to fully qualify most
4061
names with their packages, regardless of context.  Where this causes
4062
ambiguity, GDB asks the user's intent.
4063
 
4064
   The debugger will start in Ada mode if it detects an Ada main
4065
program.  As for other languages, it will enter Ada mode when stopped
4066
in a program that was translated from an Ada source file.
4067
 
4068
   While in Ada mode, you may use `-' for comments.  This is useful
4069
mostly for documenting command files.  The standard GDB comment (`#')
4070
still works at the beginning of a line in Ada mode, but not in the
4071
middle (to allow based literals).
4072
 
4073
   The debugger supports limited overloading.  Given a subprogram call
4074
in which the function symbol has multiple definitions, it will use the
4075
number of actual parameters and some information about their types to
4076
attempt to narrow the set of definitions.  It also makes very limited
4077
use of context, preferring procedures to functions in the context of
4078
the `call' command, and functions to procedures elsewhere.
4079
 
4080

4081
File: gdb.info,  Node: Omissions from Ada,  Next: Additions to Ada,  Prev: Ada Mode Intro,  Up: Ada
4082
 
4083
15.4.7.2 Omissions from Ada
4084
...........................
4085
 
4086
Here are the notable omissions from the subset:
4087
 
4088
   * Only a subset of the attributes are supported:
4089
 
4090
        - 'First, 'Last, and 'Length  on array objects (not on types
4091
          and subtypes).
4092
 
4093
        - 'Min and 'Max.
4094
 
4095
        - 'Pos and 'Val.
4096
 
4097
        - 'Tag.
4098
 
4099
        - 'Range on array objects (not subtypes), but only as the right
4100
          operand of the membership (`in') operator.
4101
 
4102
        - 'Access, 'Unchecked_Access, and 'Unrestricted_Access (a GNAT
4103
          extension).
4104
 
4105
        - 'Address.
4106
 
4107
   * The names in `Characters.Latin_1' are not available and
4108
     concatenation is not implemented.  Thus, escape characters in
4109
     strings are not currently available.
4110
 
4111
   * Equality tests (`=' and `/=') on arrays test for bitwise equality
4112
     of representations.  They will generally work correctly for
4113
     strings and arrays whose elements have integer or enumeration
4114
     types.  They may not work correctly for arrays whose element types
4115
     have user-defined equality, for arrays of real values (in
4116
     particular, IEEE-conformant floating point, because of negative
4117
     zeroes and NaNs), and for arrays whose elements contain unused
4118
     bits with indeterminate values.
4119
 
4120
   * The other component-by-component array operations (`and', `or',
4121
     `xor', `not', and relational tests other than equality) are not
4122
     implemented.
4123
 
4124
   * There is limited support for array and record aggregates.  They are
4125
     permitted only on the right sides of assignments, as in these
4126
     examples:
4127
 
4128
          (gdb) set An_Array := (1, 2, 3, 4, 5, 6)
4129
          (gdb) set An_Array := (1, others => 0)
4130
          (gdb) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
4131
          (gdb) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
4132
          (gdb) set A_Record := (1, "Peter", True);
4133
          (gdb) set A_Record := (Name => "Peter", Id => 1, Alive => True)
4134
 
4135
     Changing a discriminant's value by assigning an aggregate has an
4136
     undefined effect if that discriminant is used within the record.
4137
     However, you can first modify discriminants by directly assigning
4138
     to them (which normally would not be allowed in Ada), and then
4139
     performing an aggregate assignment.  For example, given a variable
4140
     `A_Rec' declared to have a type such as:
4141
 
4142
          type Rec (Len : Small_Integer := 0) is record
4143
              Id : Integer;
4144
              Vals : IntArray (1 .. Len);
4145
          end record;
4146
 
4147
     you can assign a value with a different size of `Vals' with two
4148
     assignments:
4149
 
4150
          (gdb) set A_Rec.Len := 4
4151
          (gdb) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
4152
 
4153
     As this example also illustrates, GDB is very loose about the usual
4154
     rules concerning aggregates.  You may leave out some of the
4155
     components of an array or record aggregate (such as the `Len'
4156
     component in the assignment to `A_Rec' above); they will retain
4157
     their original values upon assignment.  You may freely use dynamic
4158
     values as indices in component associations.  You may even use
4159
     overlapping or redundant component associations, although which
4160
     component values are assigned in such cases is not defined.
4161
 
4162
   * Calls to dispatching subprograms are not implemented.
4163
 
4164
   * The overloading algorithm is much more limited (i.e., less
4165
     selective) than that of real Ada.  It makes only limited use of
4166
     the context in which a subexpression appears to resolve its
4167
     meaning, and it is much looser in its rules for allowing type
4168
     matches.  As a result, some function calls will be ambiguous, and
4169
     the user will be asked to choose the proper resolution.
4170
 
4171
   * The `new' operator is not implemented.
4172
 
4173
   * Entry calls are not implemented.
4174
 
4175
   * Aside from printing, arithmetic operations on the native VAX
4176
     floating-point formats are not supported.
4177
 
4178
   * It is not possible to slice a packed array.
4179
 
4180
   * The names `True' and `False', when not part of a qualified name,
4181
     are interpreted as if implicitly prefixed by `Standard',
4182
     regardless of context.  Should your program redefine these names
4183
     in a package or procedure (at best a dubious practice), you will
4184
     have to use fully qualified names to access their new definitions.
4185
 
4186

4187
File: gdb.info,  Node: Additions to Ada,  Next: Stopping Before Main Program,  Prev: Omissions from Ada,  Up: Ada
4188
 
4189
15.4.7.3 Additions to Ada
4190
.........................
4191
 
4192
As it does for other languages, GDB makes certain generic extensions to
4193
Ada (*note Expressions::):
4194
 
4195
   * If the expression E is a variable residing in memory (typically a
4196
     local variable or array element) and N is a positive integer, then
4197
     `E@N' displays the values of E and the N-1 adjacent variables
4198
     following it in memory as an array.  In Ada, this operator is
4199
     generally not necessary, since its prime use is in displaying
4200
     parts of an array, and slicing will usually do this in Ada.
4201
     However, there are occasional uses when debugging programs in
4202
     which certain debugging information has been optimized away.
4203
 
4204
   * `B::VAR' means "the variable named VAR that appears in function or
4205
     file B."  When B is a file name, you must typically surround it in
4206
     single quotes.
4207
 
4208
   * The expression `{TYPE} ADDR' means "the variable of type TYPE that
4209
     appears at address ADDR."
4210
 
4211
   * A name starting with `$' is a convenience variable (*note
4212
     Convenience Vars::) or a machine register (*note Registers::).
4213
 
4214
   In addition, GDB provides a few other shortcuts and outright
4215
additions specific to Ada:
4216
 
4217
   * The assignment statement is allowed as an expression, returning
4218
     its right-hand operand as its value.  Thus, you may enter
4219
 
4220
          (gdb) set x := y + 3
4221
          (gdb) print A(tmp := y + 1)
4222
 
4223
   * The semicolon is allowed as an "operator,"  returning as its value
4224
     the value of its right-hand operand.  This allows, for example,
4225
     complex conditional breaks:
4226
 
4227
          (gdb) break f
4228
          (gdb) condition 1 (report(i); k += 1; A(k) > 100)
4229
 
4230
   * Rather than use catenation and symbolic character names to
4231
     introduce special characters into strings, one may instead use a
4232
     special bracket notation, which is also used to print strings.  A
4233
     sequence of characters of the form `["XX"]' within a string or
4234
     character literal denotes the (single) character whose numeric
4235
     encoding is XX in hexadecimal.  The sequence of characters `["""]'
4236
     also denotes a single quotation mark in strings.   For example,
4237
             "One line.["0a"]Next line.["0a"]"
4238
     contains an ASCII newline character (`Ada.Characters.Latin_1.LF')
4239
     after each period.
4240
 
4241
   * The subtype used as a prefix for the attributes 'Pos, 'Min, and
4242
     'Max is optional (and is ignored in any case).  For example, it is
4243
     valid to write
4244
 
4245
          (gdb) print 'max(x, y)
4246
 
4247
   * When printing arrays, GDB uses positional notation when the array
4248
     has a lower bound of 1, and uses a modified named notation
4249
     otherwise.  For example, a one-dimensional array of three integers
4250
     with a lower bound of 3 might print as
4251
 
4252
          (3 => 10, 17, 1)
4253
 
4254
     That is, in contrast to valid Ada, only the first component has a
4255
     `=>' clause.
4256
 
4257
   * You may abbreviate attributes in expressions with any unique,
4258
     multi-character subsequence of their names (an exact match gets
4259
     preference).  For example, you may use a'len, a'gth, or a'lh in
4260
     place of  a'length.
4261
 
4262
   * Since Ada is case-insensitive, the debugger normally maps
4263
     identifiers you type to lower case.  The GNAT compiler uses
4264
     upper-case characters for some of its internal identifiers, which
4265
     are normally of no interest to users.  For the rare occasions when
4266
     you actually have to look at them, enclose them in angle brackets
4267
     to avoid the lower-case mapping.  For example,
4268
          (gdb) print [0]
4269
 
4270
   * Printing an object of class-wide type or dereferencing an
4271
     access-to-class-wide value will display all the components of the
4272
     object's specific type (as indicated by its run-time tag).
4273
     Likewise, component selection on such a value will operate on the
4274
     specific type of the object.
4275
 
4276
 
4277

4278
File: gdb.info,  Node: Stopping Before Main Program,  Next: Ada Tasks,  Prev: Additions to Ada,  Up: Ada
4279
 
4280
15.4.7.4 Stopping at the Very Beginning
4281
.......................................
4282
 
4283
It is sometimes necessary to debug the program during elaboration, and
4284
before reaching the main procedure.  As defined in the Ada Reference
4285
Manual, the elaboration code is invoked from a procedure called
4286
`adainit'.  To run your program up to the beginning of elaboration,
4287
simply use the following two commands: `tbreak adainit' and `run'.
4288
 
4289

4290
File: gdb.info,  Node: Ada Tasks,  Next: Ada Tasks and Core Files,  Prev: Stopping Before Main Program,  Up: Ada
4291
 
4292
15.4.7.5 Extensions for Ada Tasks
4293
.................................
4294
 
4295
Support for Ada tasks is analogous to that for threads (*note
4296
Threads::).  GDB provides the following task-related commands:
4297
 
4298
`info tasks'
4299
     This command shows a list of current Ada tasks, as in the
4300
     following example:
4301
 
4302
          (gdb) info tasks
4303
            ID       TID P-ID Pri State                 Name
4304
             1   8088000   0   15 Child Activation Wait main_task
4305
             2   80a4000   1   15 Accept Statement      b
4306
             3   809a800   1   15 Child Activation Wait a
4307
          *  4   80ae800   3   15 Runnable              c
4308
 
4309
     In this listing, the asterisk before the last task indicates it to
4310
     be the task currently being inspected.
4311
 
4312
    ID
4313
          Represents GDB's internal task number.
4314
 
4315
    TID
4316
          The Ada task ID.
4317
 
4318
    P-ID
4319
          The parent's task ID (GDB's internal task number).
4320
 
4321
    Pri
4322
          The base priority of the task.
4323
 
4324
    State
4325
          Current state of the task.
4326
 
4327
         `Unactivated'
4328
               The task has been created but has not been activated.
4329
               It cannot be executing.
4330
 
4331
         `Runnable'
4332
               The task is not blocked for any reason known to Ada.
4333
               (It may be waiting for a mutex, though.) It is
4334
               conceptually "executing" in normal mode.
4335
 
4336
         `Terminated'
4337
               The task is terminated, in the sense of ARM 9.3 (5).
4338
               Any dependents that were waiting on terminate
4339
               alternatives have been awakened and have terminated
4340
               themselves.
4341
 
4342
         `Child Activation Wait'
4343
               The task is waiting for created tasks to complete
4344
               activation.
4345
 
4346
         `Accept Statement'
4347
               The task is waiting on an accept or selective wait
4348
               statement.
4349
 
4350
         `Waiting on entry call'
4351
               The task is waiting on an entry call.
4352
 
4353
         `Async Select Wait'
4354
               The task is waiting to start the abortable part of an
4355
               asynchronous select statement.
4356
 
4357
         `Delay Sleep'
4358
               The task is waiting on a select statement with only a
4359
               delay alternative open.
4360
 
4361
         `Child Termination Wait'
4362
               The task is sleeping having completed a master within
4363
               itself, and is waiting for the tasks dependent on that
4364
               master to become terminated or waiting on a terminate
4365
               Phase.
4366
 
4367
         `Wait Child in Term Alt'
4368
               The task is sleeping waiting for tasks on terminate
4369
               alternatives to finish terminating.
4370
 
4371
         `Accepting RV with TASKNO'
4372
               The task is accepting a rendez-vous with the task TASKNO.
4373
 
4374
    Name
4375
          Name of the task in the program.
4376
 
4377
 
4378
`info task TASKNO'
4379
     This command shows detailled informations on the specified task,
4380
     as in the following example:
4381
          (gdb) info tasks
4382
            ID       TID P-ID Pri State                  Name
4383
             1   8077880    0  15 Child Activation Wait  main_task
4384
          *  2   807c468    1  15 Runnable               task_1
4385
          (gdb) info task 2
4386
          Ada Task: 0x807c468
4387
          Name: task_1
4388
          Thread: 0x807f378
4389
          Parent: 1 (main_task)
4390
          Base Priority: 15
4391
          State: Runnable
4392
 
4393
`task'
4394
     This command prints the ID of the current task.
4395
 
4396
          (gdb) info tasks
4397
            ID       TID P-ID Pri State                  Name
4398
             1   8077870    0  15 Child Activation Wait  main_task
4399
          *  2   807c458    1  15 Runnable               t
4400
          (gdb) task
4401
          [Current task is 2]
4402
 
4403
`task TASKNO'
4404
     This command is like the `thread THREADNO' command (*note
4405
     Threads::).  It switches the context of debugging from the current
4406
     task to the given task.
4407
 
4408
          (gdb) info tasks
4409
            ID       TID P-ID Pri State                  Name
4410
             1   8077870    0  15 Child Activation Wait  main_task
4411
          *  2   807c458    1  15 Runnable               t
4412
          (gdb) task 1
4413
          [Switching to task 1]
4414
          #0  0x8067726 in pthread_cond_wait ()
4415
          (gdb) bt
4416
          #0  0x8067726 in pthread_cond_wait ()
4417
          #1  0x8056714 in system.os_interface.pthread_cond_wait ()
4418
          #2  0x805cb63 in system.task_primitives.operations.sleep ()
4419
          #3  0x806153e in system.tasking.stages.activate_tasks ()
4420
          #4  0x804aacc in un () at un.adb:5
4421
 
4422
`break LINESPEC task TASKNO'
4423
`break LINESPEC task TASKNO if ...'
4424
     These commands are like the `break ... thread ...' command (*note
4425
     Thread Stops::).  LINESPEC specifies source lines, as described in
4426
     *Note Specify Location::.
4427
 
4428
     Use the qualifier `task TASKNO' with a breakpoint command to
4429
     specify that you only want GDB to stop the program when a
4430
     particular Ada task reaches this breakpoint.  TASKNO is one of the
4431
     numeric task identifiers assigned by GDB, shown in the first
4432
     column of the `info tasks' display.
4433
 
4434
     If you do not specify `task TASKNO' when you set a breakpoint, the
4435
     breakpoint applies to _all_ tasks of your program.
4436
 
4437
     You can use the `task' qualifier on conditional breakpoints as
4438
     well; in this case, place `task TASKNO' before the breakpoint
4439
     condition (before the `if').
4440
 
4441
     For example,
4442
 
4443
          (gdb) info tasks
4444
            ID       TID P-ID Pri State                 Name
4445
             1 140022020   0   15 Child Activation Wait main_task
4446
             2 140045060   1   15 Accept/Select Wait    t2
4447
             3 140044840   1   15 Runnable              t1
4448
          *  4 140056040   1   15 Runnable              t3
4449
          (gdb) b 15 task 2
4450
          Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
4451
          (gdb) cont
4452
          Continuing.
4453
          task # 1 running
4454
          task # 2 running
4455
 
4456
          Breakpoint 5, test_task_debug () at test_task_debug.adb:15
4457
          15               flush;
4458
          (gdb) info tasks
4459
            ID       TID P-ID Pri State                 Name
4460
             1 140022020   0   15 Child Activation Wait main_task
4461
          *  2 140045060   1   15 Runnable              t2
4462
             3 140044840   1   15 Runnable              t1
4463
             4 140056040   1   15 Delay Sleep           t3
4464
 
4465

4466
File: gdb.info,  Node: Ada Tasks and Core Files,  Next: Ada Glitches,  Prev: Ada Tasks,  Up: Ada
4467
 
4468
15.4.7.6 Tasking Support when Debugging Core Files
4469
..................................................
4470
 
4471
When inspecting a core file, as opposed to debugging a live program,
4472
tasking support may be limited or even unavailable, depending on the
4473
platform being used.  For instance, on x86-linux, the list of tasks is
4474
available, but task switching is not supported.  On Tru64, however,
4475
task switching will work as usual.
4476
 
4477
   On certain platforms, including Tru64, the debugger needs to perform
4478
some memory writes in order to provide Ada tasking support.  When
4479
inspecting a core file, this means that the core file must be opened
4480
with read-write privileges, using the command `"set write on"' (*note
4481
Patching::).  Under these circumstances, you should make a backup copy
4482
of the core file before inspecting it with GDB.
4483
 
4484

4485
File: gdb.info,  Node: Ada Glitches,  Prev: Ada Tasks and Core Files,  Up: Ada
4486
 
4487
15.4.7.7 Known Peculiarities of Ada Mode
4488
........................................
4489
 
4490
Besides the omissions listed previously (*note Omissions from Ada::),
4491
we know of several problems with and limitations of Ada mode in GDB,
4492
some of which will be fixed with planned future releases of the debugger
4493
and the GNU Ada compiler.
4494
 
4495
   * Currently, the debugger has insufficient information to determine
4496
     whether certain pointers represent pointers to objects or the
4497
     objects themselves.  Thus, the user may have to tack an extra
4498
     `.all' after an expression to get it printed properly.
4499
 
4500
   * Static constants that the compiler chooses not to materialize as
4501
     objects in storage are invisible to the debugger.
4502
 
4503
   * Named parameter associations in function argument lists are
4504
     ignored (the argument lists are treated as positional).
4505
 
4506
   * Many useful library packages are currently invisible to the
4507
     debugger.
4508
 
4509
   * Fixed-point arithmetic, conversions, input, and output is carried
4510
     out using floating-point arithmetic, and may give results that
4511
     only approximate those on the host machine.
4512
 
4513
   * The GNAT compiler never generates the prefix `Standard' for any of
4514
     the standard symbols defined by the Ada language.  GDB knows about
4515
     this: it will strip the prefix from names when you use it, and
4516
     will never look for a name you have so qualified among local
4517
     symbols, nor match against symbols in other packages or
4518
     subprograms.  If you have defined entities anywhere in your
4519
     program other than parameters and local variables whose simple
4520
     names match names in `Standard', GNAT's lack of qualification here
4521
     can cause confusion.  When this happens, you can usually resolve
4522
     the confusion by qualifying the problematic names with package
4523
     `Standard' explicitly.
4524
 
4525
   Older versions of the compiler sometimes generate erroneous debugging
4526
information, resulting in the debugger incorrectly printing the value
4527
of affected entities.  In some cases, the debugger is able to work
4528
around an issue automatically. In other cases, the debugger is able to
4529
work around the issue, but the work-around has to be specifically
4530
enabled.
4531
 
4532
`set ada trust-PAD-over-XVS on'
4533
     Configure GDB to strictly follow the GNAT encoding when computing
4534
     the value of Ada entities, particularly when `PAD' and `PAD___XVS'
4535
     types are involved (see `ada/exp_dbug.ads' in the GCC sources for
4536
     a complete description of the encoding used by the GNAT compiler).
4537
     This is the default.
4538
 
4539
`set ada trust-PAD-over-XVS off'
4540
     This is related to the encoding using by the GNAT compiler.  If
4541
     GDB sometimes prints the wrong value for certain entities,
4542
     changing `ada trust-PAD-over-XVS' to `off' activates a work-around
4543
     which may fix the issue.  It is always safe to set `ada
4544
     trust-PAD-over-XVS' to `off', but this incurs a slight performance
4545
     penalty, so it is recommended to leave this setting to `on' unless
4546
     necessary.
4547
 
4548
 
4549

4550
File: gdb.info,  Node: Unsupported Languages,  Prev: Supported Languages,  Up: Languages
4551
 
4552
15.5 Unsupported Languages
4553
==========================
4554
 
4555
In addition to the other fully-supported programming languages, GDB
4556
also provides a pseudo-language, called `minimal'.  It does not
4557
represent a real programming language, but provides a set of
4558
capabilities close to what the C or assembly languages provide.  This
4559
should allow most simple operations to be performed while debugging an
4560
application that uses a language currently not supported by GDB.
4561
 
4562
   If the language is set to `auto', GDB will automatically select this
4563
language if the current frame corresponds to an unsupported language.
4564
 
4565

4566
File: gdb.info,  Node: Symbols,  Next: Altering,  Prev: Languages,  Up: Top
4567
 
4568
16 Examining the Symbol Table
4569
*****************************
4570
 
4571
The commands described in this chapter allow you to inquire about the
4572
symbols (names of variables, functions and types) defined in your
4573
program.  This information is inherent in the text of your program and
4574
does not change as your program executes.  GDB finds it in your
4575
program's symbol table, in the file indicated when you started GDB
4576
(*note Choosing Files: File Options.), or by one of the file-management
4577
commands (*note Commands to Specify Files: Files.).
4578
 
4579
   Occasionally, you may need to refer to symbols that contain unusual
4580
characters, which GDB ordinarily treats as word delimiters.  The most
4581
frequent case is in referring to static variables in other source files
4582
(*note Program Variables: Variables.).  File names are recorded in
4583
object files as debugging symbols, but GDB would ordinarily parse a
4584
typical file name, like `foo.c', as the three words `foo' `.' `c'.  To
4585
allow GDB to recognize `foo.c' as a single symbol, enclose it in single
4586
quotes; for example,
4587
 
4588
     p 'foo.c'::x
4589
 
4590
looks up the value of `x' in the scope of the file `foo.c'.
4591
 
4592
`set case-sensitive on'
4593
`set case-sensitive off'
4594
`set case-sensitive auto'
4595
     Normally, when GDB looks up symbols, it matches their names with
4596
     case sensitivity determined by the current source language.
4597
     Occasionally, you may wish to control that.  The command `set
4598
     case-sensitive' lets you do that by specifying `on' for
4599
     case-sensitive matches or `off' for case-insensitive ones.  If you
4600
     specify `auto', case sensitivity is reset to the default suitable
4601
     for the source language.  The default is case-sensitive matches
4602
     for all languages except for Fortran, for which the default is
4603
     case-insensitive matches.
4604
 
4605
`show case-sensitive'
4606
     This command shows the current setting of case sensitivity for
4607
     symbols lookups.
4608
 
4609
`info address SYMBOL'
4610
     Describe where the data for SYMBOL is stored.  For a register
4611
     variable, this says which register it is kept in.  For a
4612
     non-register local variable, this prints the stack-frame offset at
4613
     which the variable is always stored.
4614
 
4615
     Note the contrast with `print &SYMBOL', which does not work at all
4616
     for a register variable, and for a stack local variable prints the
4617
     exact address of the current instantiation of the variable.
4618
 
4619
`info symbol ADDR'
4620
     Print the name of a symbol which is stored at the address ADDR.
4621
     If no symbol is stored exactly at ADDR, GDB prints the nearest
4622
     symbol and an offset from it:
4623
 
4624
          (gdb) info symbol 0x54320
4625
          _initialize_vx + 396 in section .text
4626
 
4627
     This is the opposite of the `info address' command.  You can use
4628
     it to find out the name of a variable or a function given its
4629
     address.
4630
 
4631
     For dynamically linked executables, the name of executable or
4632
     shared library containing the symbol is also printed:
4633
 
4634
          (gdb) info symbol 0x400225
4635
          _start + 5 in section .text of /tmp/a.out
4636
          (gdb) info symbol 0x2aaaac2811cf
4637
          __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
4638
 
4639
`whatis [ARG]'
4640
     Print the data type of ARG, which can be either an expression or a
4641
     data type.  With no argument, print the data type of `$', the last
4642
     value in the value history.  If ARG is an expression, it is not
4643
     actually evaluated, and any side-effecting operations (such as
4644
     assignments or function calls) inside it do not take place.  If
4645
     ARG is a type name, it may be the name of a type or typedef, or
4646
     for C code it may have the form `class CLASS-NAME', `struct
4647
     STRUCT-TAG', `union UNION-TAG' or `enum ENUM-TAG'.  *Note
4648
     Expressions: Expressions.
4649
 
4650
`ptype [ARG]'
4651
     `ptype' accepts the same arguments as `whatis', but prints a
4652
     detailed description of the type, instead of just the name of the
4653
     type.  *Note Expressions: Expressions.
4654
 
4655
     For example, for this variable declaration:
4656
 
4657
          struct complex {double real; double imag;} v;
4658
 
4659
     the two commands give this output:
4660
 
4661
          (gdb) whatis v
4662
          type = struct complex
4663
          (gdb) ptype v
4664
          type = struct complex {
4665
              double real;
4666
              double imag;
4667
          }
4668
 
4669
     As with `whatis', using `ptype' without an argument refers to the
4670
     type of `$', the last value in the value history.
4671
 
4672
     Sometimes, programs use opaque data types or incomplete
4673
     specifications of complex data structure.  If the debug
4674
     information included in the program does not allow GDB to display
4675
     a full declaration of the data type, it will say `
4676
     type>'.  For example, given these declarations:
4677
 
4678
              struct foo;
4679
              struct foo *fooptr;
4680
 
4681
     but no definition for `struct foo' itself, GDB will say:
4682
 
4683
            (gdb) ptype foo
4684
            $1 = 
4685
 
4686
     "Incomplete type" is C terminology for data types that are not
4687
     completely specified.
4688
 
4689
`info types REGEXP'
4690
`info types'
4691
     Print a brief description of all types whose names match the
4692
     regular expression REGEXP (or all types in your program, if you
4693
     supply no argument).  Each complete typename is matched as though
4694
     it were a complete line; thus, `i type value' gives information on
4695
     all types in your program whose names include the string `value',
4696
     but `i type ^value$' gives information only on types whose complete
4697
     name is `value'.
4698
 
4699
     This command differs from `ptype' in two ways: first, like
4700
     `whatis', it does not print a detailed description; second, it
4701
     lists all source files where a type is defined.
4702
 
4703
`info scope LOCATION'
4704
     List all the variables local to a particular scope.  This command
4705
     accepts a LOCATION argument--a function name, a source line, or an
4706
     address preceded by a `*', and prints all the variables local to
4707
     the scope defined by that location.  (*Note Specify Location::, for
4708
     details about supported forms of LOCATION.)  For example:
4709
 
4710
          (gdb) info scope command_line_handler
4711
          Scope for command_line_handler:
4712
          Symbol rl is an argument at stack/frame offset 8, length 4.
4713
          Symbol linebuffer is in static storage at address 0x150a18, length 4.
4714
          Symbol linelength is in static storage at address 0x150a1c, length 4.
4715
          Symbol p is a local variable in register $esi, length 4.
4716
          Symbol p1 is a local variable in register $ebx, length 4.
4717
          Symbol nline is a local variable in register $edx, length 4.
4718
          Symbol repeat is a local variable at frame offset -8, length 4.
4719
 
4720
     This command is especially useful for determining what data to
4721
     collect during a "trace experiment", see *Note collect: Tracepoint
4722
     Actions.
4723
 
4724
`info source'
4725
     Show information about the current source file--that is, the
4726
     source file for the function containing the current point of
4727
     execution:
4728
        * the name of the source file, and the directory containing it,
4729
 
4730
        * the directory it was compiled in,
4731
 
4732
        * its length, in lines,
4733
 
4734
        * which programming language it is written in,
4735
 
4736
        * whether the executable includes debugging information for
4737
          that file, and if so, what format the information is in
4738
          (e.g., STABS, Dwarf 2, etc.), and
4739
 
4740
        * whether the debugging information includes information about
4741
          preprocessor macros.
4742
 
4743
`info sources'
4744
     Print the names of all source files in your program for which
4745
     there is debugging information, organized into two lists: files
4746
     whose symbols have already been read, and files whose symbols will
4747
     be read when needed.
4748
 
4749
`info functions'
4750
     Print the names and data types of all defined functions.
4751
 
4752
`info functions REGEXP'
4753
     Print the names and data types of all defined functions whose
4754
     names contain a match for regular expression REGEXP.  Thus, `info
4755
     fun step' finds all functions whose names include `step'; `info
4756
     fun ^step' finds those whose names start with `step'.  If a
4757
     function name contains characters that conflict with the regular
4758
     expression language (e.g.  `operator*()'), they may be quoted with
4759
     a backslash.
4760
 
4761
`info variables'
4762
     Print the names and data types of all variables that are defined
4763
     outside of functions (i.e. excluding local variables).
4764
 
4765
`info variables REGEXP'
4766
     Print the names and data types of all variables (except for local
4767
     variables) whose names contain a match for regular expression
4768
     REGEXP.
4769
 
4770
`info classes'
4771
`info classes REGEXP'
4772
     Display all Objective-C classes in your program, or (with the
4773
     REGEXP argument) all those matching a particular regular
4774
     expression.
4775
 
4776
`info selectors'
4777
`info selectors REGEXP'
4778
     Display all Objective-C selectors in your program, or (with the
4779
     REGEXP argument) all those matching a particular regular
4780
     expression.
4781
 
4782
     Some systems allow individual object files that make up your
4783
     program to be replaced without stopping and restarting your
4784
     program.  For example, in VxWorks you can simply recompile a
4785
     defective object file and keep on running.  If you are running on
4786
     one of these systems, you can allow GDB to reload the symbols for
4787
     automatically relinked modules:
4788
 
4789
    `set symbol-reloading on'
4790
          Replace symbol definitions for the corresponding source file
4791
          when an object file with a particular name is seen again.
4792
 
4793
    `set symbol-reloading off'
4794
          Do not replace symbol definitions when encountering object
4795
          files of the same name more than once.  This is the default
4796
          state; if you are not running on a system that permits
4797
          automatic relinking of modules, you should leave
4798
          `symbol-reloading' off, since otherwise GDB may discard
4799
          symbols when linking large programs, that may contain several
4800
          modules (from different directories or libraries) with the
4801
          same name.
4802
 
4803
    `show symbol-reloading'
4804
          Show the current `on' or `off' setting.
4805
 
4806
`set opaque-type-resolution on'
4807
     Tell GDB to resolve opaque types.  An opaque type is a type
4808
     declared as a pointer to a `struct', `class', or `union'--for
4809
     example, `struct MyType *'--that is used in one source file
4810
     although the full declaration of `struct MyType' is in another
4811
     source file.  The default is on.
4812
 
4813
     A change in the setting of this subcommand will not take effect
4814
     until the next time symbols for a file are loaded.
4815
 
4816
`set opaque-type-resolution off'
4817
     Tell GDB not to resolve opaque types.  In this case, the type is
4818
     printed as follows:
4819
          {}
4820
 
4821
`show opaque-type-resolution'
4822
     Show whether opaque types are resolved or not.
4823
 
4824
`maint print symbols FILENAME'
4825
`maint print psymbols FILENAME'
4826
`maint print msymbols FILENAME'
4827
     Write a dump of debugging symbol data into the file FILENAME.
4828
     These commands are used to debug the GDB symbol-reading code.  Only
4829
     symbols with debugging data are included.  If you use `maint print
4830
     symbols', GDB includes all the symbols for which it has already
4831
     collected full details: that is, FILENAME reflects symbols for
4832
     only those files whose symbols GDB has read.  You can use the
4833
     command `info sources' to find out which files these are.  If you
4834
     use `maint print psymbols' instead, the dump shows information
4835
     about symbols that GDB only knows partially--that is, symbols
4836
     defined in files that GDB has skimmed, but not yet read
4837
     completely.  Finally, `maint print msymbols' dumps just the
4838
     minimal symbol information required for each object file from
4839
     which GDB has read some symbols.  *Note Commands to Specify Files:
4840
     Files, for a discussion of how GDB reads symbols (in the
4841
     description of `symbol-file').
4842
 
4843
`maint info symtabs [ REGEXP ]'
4844
`maint info psymtabs [ REGEXP ]'
4845
     List the `struct symtab' or `struct partial_symtab' structures
4846
     whose names match REGEXP.  If REGEXP is not given, list them all.
4847
     The output includes expressions which you can copy into a GDB
4848
     debugging this one to examine a particular structure in more
4849
     detail.  For example:
4850
 
4851
          (gdb) maint info psymtabs dwarf2read
4852
          { objfile /home/gnu/build/gdb/gdb
4853
            ((struct objfile *) 0x82e69d0)
4854
            { psymtab /home/gnu/src/gdb/dwarf2read.c
4855
              ((struct partial_symtab *) 0x8474b10)
4856
              readin no
4857
              fullname (null)
4858
              text addresses 0x814d3c8 -- 0x8158074
4859
              globals (* (struct partial_symbol **) 0x8507a08 @ 9)
4860
              statics (* (struct partial_symbol **) 0x40e95b78 @ 2882)
4861
              dependencies (none)
4862
            }
4863
          }
4864
          (gdb) maint info symtabs
4865
          (gdb)
4866
     We see that there is one partial symbol table whose filename
4867
     contains the string `dwarf2read', belonging to the `gdb'
4868
     executable; and we see that GDB has not read in any symtabs yet at
4869
     all.  If we set a breakpoint on a function, that will cause GDB to
4870
     read the symtab for the compilation unit containing that function:
4871
 
4872
          (gdb) break dwarf2_psymtab_to_symtab
4873
          Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
4874
          line 1574.
4875
          (gdb) maint info symtabs
4876
          { objfile /home/gnu/build/gdb/gdb
4877
            ((struct objfile *) 0x82e69d0)
4878
            { symtab /home/gnu/src/gdb/dwarf2read.c
4879
              ((struct symtab *) 0x86c1f38)
4880
              dirname (null)
4881
              fullname (null)
4882
              blockvector ((struct blockvector *) 0x86c1bd0) (primary)
4883
              linetable ((struct linetable *) 0x8370fa0)
4884
              debugformat DWARF 2
4885
            }
4886
          }
4887
          (gdb)
4888
 
4889

4890
File: gdb.info,  Node: Altering,  Next: GDB Files,  Prev: Symbols,  Up: Top
4891
 
4892
17 Altering Execution
4893
*********************
4894
 
4895
Once you think you have found an error in your program, you might want
4896
to find out for certain whether correcting the apparent error would
4897
lead to correct results in the rest of the run.  You can find the
4898
answer by experiment, using the GDB features for altering execution of
4899
the program.
4900
 
4901
   For example, you can store new values into variables or memory
4902
locations, give your program a signal, restart it at a different
4903
address, or even return prematurely from a function.
4904
 
4905
* Menu:
4906
 
4907
* Assignment::                  Assignment to variables
4908
* Jumping::                     Continuing at a different address
4909
* Signaling::                   Giving your program a signal
4910
* Returning::                   Returning from a function
4911
* Calling::                     Calling your program's functions
4912
* Patching::                    Patching your program
4913
 
4914

4915
File: gdb.info,  Node: Assignment,  Next: Jumping,  Up: Altering
4916
 
4917
17.1 Assignment to Variables
4918
============================
4919
 
4920
To alter the value of a variable, evaluate an assignment expression.
4921
*Note Expressions: Expressions.  For example,
4922
 
4923
     print x=4
4924
 
4925
stores the value 4 into the variable `x', and then prints the value of
4926
the assignment expression (which is 4).  *Note Using GDB with Different
4927
Languages: Languages, for more information on operators in supported
4928
languages.
4929
 
4930
   If you are not interested in seeing the value of the assignment, use
4931
the `set' command instead of the `print' command.  `set' is really the
4932
same as `print' except that the expression's value is not printed and
4933
is not put in the value history (*note Value History: Value History.).
4934
The expression is evaluated only for its effects.
4935
 
4936
   If the beginning of the argument string of the `set' command appears
4937
identical to a `set' subcommand, use the `set variable' command instead
4938
of just `set'.  This command is identical to `set' except for its lack
4939
of subcommands.  For example, if your program has a variable `width',
4940
you get an error if you try to set a new value with just `set
4941
width=13', because GDB has the command `set width':
4942
 
4943
     (gdb) whatis width
4944
     type = double
4945
     (gdb) p width
4946
     $4 = 13
4947
     (gdb) set width=47
4948
     Invalid syntax in expression.
4949
 
4950
The invalid expression, of course, is `=47'.  In order to actually set
4951
the program's variable `width', use
4952
 
4953
     (gdb) set var width=47
4954
 
4955
   Because the `set' command has many subcommands that can conflict
4956
with the names of program variables, it is a good idea to use the `set
4957
variable' command instead of just `set'.  For example, if your program
4958
has a variable `g', you run into problems if you try to set a new value
4959
with just `set g=4', because GDB has the command `set gnutarget',
4960
abbreviated `set g':
4961
 
4962
     (gdb) whatis g
4963
     type = double
4964
     (gdb) p g
4965
     $1 = 1
4966
     (gdb) set g=4
4967
     (gdb) p g
4968
     $2 = 1
4969
     (gdb) r
4970
     The program being debugged has been started already.
4971
     Start it from the beginning? (y or n) y
4972
     Starting program: /home/smith/cc_progs/a.out
4973
     "/home/smith/cc_progs/a.out": can't open to read symbols:
4974
                                      Invalid bfd target.
4975
     (gdb) show g
4976
     The current BFD target is "=4".
4977
 
4978
The program variable `g' did not change, and you silently set the
4979
`gnutarget' to an invalid value.  In order to set the variable `g', use
4980
 
4981
     (gdb) set var g=4
4982
 
4983
   GDB allows more implicit conversions in assignments than C; you can
4984
freely store an integer value into a pointer variable or vice versa,
4985
and you can convert any structure to any other structure that is the
4986
same length or shorter.
4987
 
4988
   To store values into arbitrary places in memory, use the `{...}'
4989
construct to generate a value of specified type at a specified address
4990
(*note Expressions: Expressions.).  For example, `{int}0x83040' refers
4991
to memory location `0x83040' as an integer (which implies a certain size
4992
and representation in memory), and
4993
 
4994
     set {int}0x83040 = 4
4995
 
4996
stores the value 4 into that memory location.
4997
 
4998

4999
File: gdb.info,  Node: Jumping,  Next: Signaling,  Prev: Assignment,  Up: Altering
5000
 
5001
17.2 Continuing at a Different Address
5002
======================================
5003
 
5004
Ordinarily, when you continue your program, you do so at the place where
5005
it stopped, with the `continue' command.  You can instead continue at
5006
an address of your own choosing, with the following commands:
5007
 
5008
`jump LINESPEC'
5009
`jump LOCATION'
5010
     Resume execution at line LINESPEC or at address given by LOCATION.
5011
     Execution stops again immediately if there is a breakpoint there.
5012
     *Note Specify Location::, for a description of the different
5013
     forms of LINESPEC and LOCATION.  It is common practice to use the
5014
     `tbreak' command in conjunction with `jump'.  *Note Setting
5015
     Breakpoints: Set Breaks.
5016
 
5017
     The `jump' command does not change the current stack frame, or the
5018
     stack pointer, or the contents of any memory location or any
5019
     register other than the program counter.  If line LINESPEC is in a
5020
     different function from the one currently executing, the results
5021
     may be bizarre if the two functions expect different patterns of
5022
     arguments or of local variables.  For this reason, the `jump'
5023
     command requests confirmation if the specified line is not in the
5024
     function currently executing.  However, even bizarre results are
5025
     predictable if you are well acquainted with the machine-language
5026
     code of your program.
5027
 
5028
   On many systems, you can get much the same effect as the `jump'
5029
command by storing a new value into the register `$pc'.  The difference
5030
is that this does not start your program running; it only changes the
5031
address of where it _will_ run when you continue.  For example,
5032
 
5033
     set $pc = 0x485
5034
 
5035
makes the next `continue' command or stepping command execute at
5036
address `0x485', rather than at the address where your program stopped.
5037
*Note Continuing and Stepping: Continuing and Stepping.
5038
 
5039
   The most common occasion to use the `jump' command is to back
5040
up--perhaps with more breakpoints set--over a portion of a program that
5041
has already executed, in order to examine its execution in more detail.
5042
 
5043

5044
File: gdb.info,  Node: Signaling,  Next: Returning,  Prev: Jumping,  Up: Altering
5045
 
5046
17.3 Giving your Program a Signal
5047
=================================
5048
 
5049
`signal SIGNAL'
5050
     Resume execution where your program stopped, but immediately give
5051
     it the signal SIGNAL.  SIGNAL can be the name or the number of a
5052
     signal.  For example, on many systems `signal 2' and `signal
5053
     SIGINT' are both ways of sending an interrupt signal.
5054
 
5055
     Alternatively, if SIGNAL is zero, continue execution without
5056
     giving a signal.  This is useful when your program stopped on
5057
     account of a signal and would ordinary see the signal when resumed
5058
     with the `continue' command; `signal 0' causes it to resume
5059
     without a signal.
5060
 
5061
     `signal' does not repeat when you press  a second time after
5062
     executing the command.
5063
 
5064
   Invoking the `signal' command is not the same as invoking the `kill'
5065
utility from the shell.  Sending a signal with `kill' causes GDB to
5066
decide what to do with the signal depending on the signal handling
5067
tables (*note Signals::).  The `signal' command passes the signal
5068
directly to your program.
5069
 
5070

5071
File: gdb.info,  Node: Returning,  Next: Calling,  Prev: Signaling,  Up: Altering
5072
 
5073
17.4 Returning from a Function
5074
==============================
5075
 
5076
`return'
5077
`return EXPRESSION'
5078
     You can cancel execution of a function call with the `return'
5079
     command.  If you give an EXPRESSION argument, its value is used as
5080
     the function's return value.
5081
 
5082
   When you use `return', GDB discards the selected stack frame (and
5083
all frames within it).  You can think of this as making the discarded
5084
frame return prematurely.  If you wish to specify a value to be
5085
returned, give that value as the argument to `return'.
5086
 
5087
   This pops the selected stack frame (*note Selecting a Frame:
5088
Selection.), and any other frames inside of it, leaving its caller as
5089
the innermost remaining frame.  That frame becomes selected.  The
5090
specified value is stored in the registers used for returning values of
5091
functions.
5092
 
5093
   The `return' command does not resume execution; it leaves the
5094
program stopped in the state that would exist if the function had just
5095
returned.  In contrast, the `finish' command (*note Continuing and
5096
Stepping: Continuing and Stepping.) resumes execution until the
5097
selected stack frame returns naturally.
5098
 
5099
   GDB needs to know how the EXPRESSION argument should be set for the
5100
inferior.  The concrete registers assignment depends on the OS ABI and
5101
the type being returned by the selected stack frame.  For example it is
5102
common for OS ABI to return floating point values in FPU registers
5103
while integer values in CPU registers.  Still some ABIs return even
5104
floating point values in CPU registers.  Larger integer widths (such as
5105
`long long int') also have specific placement rules.  GDB already knows
5106
the OS ABI from its current target so it needs to find out also the
5107
type being returned to make the assignment into the right register(s).
5108
 
5109
   Normally, the selected stack frame has debug info.  GDB will always
5110
use the debug info instead of the implicit type of EXPRESSION when the
5111
debug info is available.  For example, if you type `return -1', and the
5112
function in the current stack frame is declared to return a `long long
5113
int', GDB transparently converts the implicit `int' value of -1 into a
5114
`long long int':
5115
 
5116
     Breakpoint 1, func () at gdb.base/return-nodebug.c:29
5117
     29        return 31;
5118
     (gdb) return -1
5119
     Make func return now? (y or n) y
5120
     #0  0x004004f6 in main () at gdb.base/return-nodebug.c:43
5121
     43        printf ("result=%lld\n", func ());
5122
     (gdb)
5123
 
5124
   However, if the selected stack frame does not have a debug info,
5125
e.g., if the function was compiled without debug info, GDB has to find
5126
out the type to return from user.  Specifying a different type by
5127
mistake may set the value in different inferior registers than the
5128
caller code expects.  For example, typing `return -1' with its implicit
5129
type `int' would set only a part of a `long long int' result for a
5130
debug info less function (on 32-bit architectures).  Therefore the user
5131
is required to specify the return type by an appropriate cast
5132
explicitly:
5133
 
5134
     Breakpoint 2, 0x0040050b in func ()
5135
     (gdb) return -1
5136
     Return value type not available for selected stack frame.
5137
     Please use an explicit cast of the value to return.
5138
     (gdb) return (long long int) -1
5139
     Make selected stack frame return now? (y or n) y
5140
     #0  0x00400526 in main ()
5141
     (gdb)
5142
 
5143

5144
File: gdb.info,  Node: Calling,  Next: Patching,  Prev: Returning,  Up: Altering
5145
 
5146
17.5 Calling Program Functions
5147
==============================
5148
 
5149
`print EXPR'
5150
     Evaluate the expression EXPR and display the resulting value.
5151
     EXPR may include calls to functions in the program being debugged.
5152
 
5153
`call EXPR'
5154
     Evaluate the expression EXPR without displaying `void' returned
5155
     values.
5156
 
5157
     You can use this variant of the `print' command if you want to
5158
     execute a function from your program that does not return anything
5159
     (a.k.a. "a void function"), but without cluttering the output with
5160
     `void' returned values that GDB will otherwise print.  If the
5161
     result is not void, it is printed and saved in the value history.
5162
 
5163
   It is possible for the function you call via the `print' or `call'
5164
command to generate a signal (e.g., if there's a bug in the function,
5165
or if you passed it incorrect arguments).  What happens in that case is
5166
controlled by the `set unwindonsignal' command.
5167
 
5168
   Similarly, with a C++ program it is possible for the function you
5169
call via the `print' or `call' command to generate an exception that is
5170
not handled due to the constraints of the dummy frame.  In this case,
5171
any exception that is raised in the frame, but has an out-of-frame
5172
exception handler will not be found.  GDB builds a dummy-frame for the
5173
inferior function call, and the unwinder cannot seek for exception
5174
handlers outside of this dummy-frame.  What happens in that case is
5175
controlled by the `set unwind-on-terminating-exception' command.
5176
 
5177
`set unwindonsignal'
5178
     Set unwinding of the stack if a signal is received while in a
5179
     function that GDB called in the program being debugged.  If set to
5180
     on, GDB unwinds the stack it created for the call and restores the
5181
     context to what it was before the call.  If set to off (the
5182
     default), GDB stops in the frame where the signal was received.
5183
 
5184
`show unwindonsignal'
5185
     Show the current setting of stack unwinding in the functions
5186
     called by GDB.
5187
 
5188
`set unwind-on-terminating-exception'
5189
     Set unwinding of the stack if a C++ exception is raised, but left
5190
     unhandled while in a function that GDB called in the program being
5191
     debugged.  If set to on (the default), GDB unwinds the stack it
5192
     created for the call and restores the context to what it was before
5193
     the call.  If set to off, GDB the exception is delivered to the
5194
     default C++ exception handler and the inferior terminated.
5195
 
5196
`show unwind-on-terminating-exception'
5197
     Show the current setting of stack unwinding in the functions
5198
     called by GDB.
5199
 
5200
 
5201
   Sometimes, a function you wish to call is actually a "weak alias"
5202
for another function.  In such case, GDB might not pick up the type
5203
information, including the types of the function arguments, which
5204
causes GDB to call the inferior function incorrectly.  As a result, the
5205
called function will function erroneously and may even crash.  A
5206
solution to that is to use the name of the aliased function instead.
5207
 
5208

5209
File: gdb.info,  Node: Patching,  Prev: Calling,  Up: Altering
5210
 
5211
17.6 Patching Programs
5212
======================
5213
 
5214
By default, GDB opens the file containing your program's executable
5215
code (or the corefile) read-only.  This prevents accidental alterations
5216
to machine code; but it also prevents you from intentionally patching
5217
your program's binary.
5218
 
5219
   If you'd like to be able to patch the binary, you can specify that
5220
explicitly with the `set write' command.  For example, you might want
5221
to turn on internal debugging flags, or even to make emergency repairs.
5222
 
5223
`set write on'
5224
`set write off'
5225
     If you specify `set write on', GDB opens executable and core files
5226
     for both reading and writing; if you specify `set write off' (the
5227
     default), GDB opens them read-only.
5228
 
5229
     If you have already loaded a file, you must load it again (using
5230
     the `exec-file' or `core-file' command) after changing `set
5231
     write', for your new setting to take effect.
5232
 
5233
`show write'
5234
     Display whether executable files and core files are opened for
5235
     writing as well as reading.
5236
 
5237

5238
File: gdb.info,  Node: GDB Files,  Next: Targets,  Prev: Altering,  Up: Top
5239
 
5240
18 GDB Files
5241
************
5242
 
5243
GDB needs to know the file name of the program to be debugged, both in
5244
order to read its symbol table and in order to start your program.  To
5245
debug a core dump of a previous run, you must also tell GDB the name of
5246
the core dump file.
5247
 
5248
* Menu:
5249
 
5250
* Files::                       Commands to specify files
5251
* Separate Debug Files::        Debugging information in separate files
5252
* Symbol Errors::               Errors reading symbol files
5253
* Data Files::                  GDB data files
5254
 
5255

5256
File: gdb.info,  Node: Files,  Next: Separate Debug Files,  Up: GDB Files
5257
 
5258
18.1 Commands to Specify Files
5259
==============================
5260
 
5261
You may want to specify executable and core dump file names.  The usual
5262
way to do this is at start-up time, using the arguments to GDB's
5263
start-up commands (*note Getting In and Out of GDB: Invocation.).
5264
 
5265
   Occasionally it is necessary to change to a different file during a
5266
GDB session.  Or you may run GDB and forget to specify a file you want
5267
to use.  Or you are debugging a remote target via `gdbserver' (*note
5268
file: Server.).  In these situations the GDB commands to specify new
5269
files are useful.
5270
 
5271
`file FILENAME'
5272
     Use FILENAME as the program to be debugged.  It is read for its
5273
     symbols and for the contents of pure memory.  It is also the
5274
     program executed when you use the `run' command.  If you do not
5275
     specify a directory and the file is not found in the GDB working
5276
     directory, GDB uses the environment variable `PATH' as a list of
5277
     directories to search, just as the shell does when looking for a
5278
     program to run.  You can change the value of this variable, for
5279
     both GDB and your program, using the `path' command.
5280
 
5281
     You can load unlinked object `.o' files into GDB using the `file'
5282
     command.  You will not be able to "run" an object file, but you
5283
     can disassemble functions and inspect variables.  Also, if the
5284
     underlying BFD functionality supports it, you could use `gdb
5285
     -write' to patch object files using this technique.  Note that GDB
5286
     can neither interpret nor modify relocations in this case, so
5287
     branches and some initialized variables will appear to go to the
5288
     wrong place.  But this feature is still handy from time to time.
5289
 
5290
`file'
5291
     `file' with no argument makes GDB discard any information it has
5292
     on both executable file and the symbol table.
5293
 
5294
`exec-file [ FILENAME ]'
5295
     Specify that the program to be run (but not the symbol table) is
5296
     found in FILENAME.  GDB searches the environment variable `PATH'
5297
     if necessary to locate your program.  Omitting FILENAME means to
5298
     discard information on the executable file.
5299
 
5300
`symbol-file [ FILENAME ]'
5301
     Read symbol table information from file FILENAME.  `PATH' is
5302
     searched when necessary.  Use the `file' command to get both symbol
5303
     table and program to run from the same file.
5304
 
5305
     `symbol-file' with no argument clears out GDB information on your
5306
     program's symbol table.
5307
 
5308
     The `symbol-file' command causes GDB to forget the contents of
5309
     some breakpoints and auto-display expressions.  This is because
5310
     they may contain pointers to the internal data recording symbols
5311
     and data types, which are part of the old symbol table data being
5312
     discarded inside GDB.
5313
 
5314
     `symbol-file' does not repeat if you press  again after
5315
     executing it once.
5316
 
5317
     When GDB is configured for a particular environment, it
5318
     understands debugging information in whatever format is the
5319
     standard generated for that environment; you may use either a GNU
5320
     compiler, or other compilers that adhere to the local conventions.
5321
     Best results are usually obtained from GNU compilers; for example,
5322
     using `GCC' you can generate debugging information for optimized
5323
     code.
5324
 
5325
     For most kinds of object files, with the exception of old SVR3
5326
     systems using COFF, the `symbol-file' command does not normally
5327
     read the symbol table in full right away.  Instead, it scans the
5328
     symbol table quickly to find which source files and which symbols
5329
     are present.  The details are read later, one source file at a
5330
     time, as they are needed.
5331
 
5332
     The purpose of this two-stage reading strategy is to make GDB
5333
     start up faster.  For the most part, it is invisible except for
5334
     occasional pauses while the symbol table details for a particular
5335
     source file are being read.  (The `set verbose' command can turn
5336
     these pauses into messages if desired.  *Note Optional Warnings
5337
     and Messages: Messages/Warnings.)
5338
 
5339
     We have not implemented the two-stage strategy for COFF yet.  When
5340
     the symbol table is stored in COFF format, `symbol-file' reads the
5341
     symbol table data in full right away.  Note that "stabs-in-COFF"
5342
     still does the two-stage strategy, since the debug info is actually
5343
     in stabs format.
5344
 
5345
`symbol-file [ -readnow ] FILENAME'
5346
`file [ -readnow ] FILENAME'
5347
     You can override the GDB two-stage strategy for reading symbol
5348
     tables by using the `-readnow' option with any of the commands that
5349
     load symbol table information, if you want to be sure GDB has the
5350
     entire symbol table available.
5351
 
5352
`core-file [FILENAME]'
5353
`core'
5354
     Specify the whereabouts of a core dump file to be used as the
5355
     "contents of memory".  Traditionally, core files contain only some
5356
     parts of the address space of the process that generated them; GDB
5357
     can access the executable file itself for other parts.
5358
 
5359
     `core-file' with no argument specifies that no core file is to be
5360
     used.
5361
 
5362
     Note that the core file is ignored when your program is actually
5363
     running under GDB.  So, if you have been running your program and
5364
     you wish to debug a core file instead, you must kill the
5365
     subprocess in which the program is running.  To do this, use the
5366
     `kill' command (*note Killing the Child Process: Kill Process.).
5367
 
5368
`add-symbol-file FILENAME ADDRESS'
5369
`add-symbol-file FILENAME ADDRESS [ -readnow ]'
5370
`add-symbol-file FILENAME -sSECTION ADDRESS ...'
5371
     The `add-symbol-file' command reads additional symbol table
5372
     information from the file FILENAME.  You would use this command
5373
     when FILENAME has been dynamically loaded (by some other means)
5374
     into the program that is running.  ADDRESS should be the memory
5375
     address at which the file has been loaded; GDB cannot figure this
5376
     out for itself.  You can additionally specify an arbitrary number
5377
     of `-sSECTION ADDRESS' pairs, to give an explicit section name and
5378
     base address for that section.  You can specify any ADDRESS as an
5379
     expression.
5380
 
5381
     The symbol table of the file FILENAME is added to the symbol table
5382
     originally read with the `symbol-file' command.  You can use the
5383
     `add-symbol-file' command any number of times; the new symbol data
5384
     thus read keeps adding to the old.  To discard all old symbol data
5385
     instead, use the `symbol-file' command without any arguments.
5386
 
5387
     Although FILENAME is typically a shared library file, an
5388
     executable file, or some other object file which has been fully
5389
     relocated for loading into a process, you can also load symbolic
5390
     information from relocatable `.o' files, as long as:
5391
 
5392
        * the file's symbolic information refers only to linker symbols
5393
          defined in that file, not to symbols defined by other object
5394
          files,
5395
 
5396
        * every section the file's symbolic information refers to has
5397
          actually been loaded into the inferior, as it appears in the
5398
          file, and
5399
 
5400
        * you can determine the address at which every section was
5401
          loaded, and provide these to the `add-symbol-file' command.
5402
 
5403
     Some embedded operating systems, like Sun Chorus and VxWorks, can
5404
     load relocatable files into an already running program; such
5405
     systems typically make the requirements above easy to meet.
5406
     However, it's important to recognize that many native systems use
5407
     complex link procedures (`.linkonce' section factoring and C++
5408
     constructor table assembly, for example) that make the
5409
     requirements difficult to meet.  In general, one cannot assume
5410
     that using `add-symbol-file' to read a relocatable object file's
5411
     symbolic information will have the same effect as linking the
5412
     relocatable object file into the program in the normal way.
5413
 
5414
     `add-symbol-file' does not repeat if you press  after using
5415
     it.
5416
 
5417
`add-symbol-file-from-memory ADDRESS'
5418
     Load symbols from the given ADDRESS in a dynamically loaded object
5419
     file whose image is mapped directly into the inferior's memory.
5420
     For example, the Linux kernel maps a `syscall DSO' into each
5421
     process's address space; this DSO provides kernel-specific code for
5422
     some system calls.  The argument can be any expression whose
5423
     evaluation yields the address of the file's shared object file
5424
     header.  For this command to work, you must have used
5425
     `symbol-file' or `exec-file' commands in advance.
5426
 
5427
`add-shared-symbol-files LIBRARY-FILE'
5428
`assf LIBRARY-FILE'
5429
     The `add-shared-symbol-files' command can currently be used only
5430
     in the Cygwin build of GDB on MS-Windows OS, where it is an alias
5431
     for the `dll-symbols' command (*note Cygwin Native::).  GDB
5432
     automatically looks for shared libraries, however if GDB does not
5433
     find yours, you can invoke `add-shared-symbol-files'.  It takes
5434
     one argument: the shared library's file name.  `assf' is a
5435
     shorthand alias for `add-shared-symbol-files'.
5436
 
5437
`section SECTION ADDR'
5438
     The `section' command changes the base address of the named
5439
     SECTION of the exec file to ADDR.  This can be used if the exec
5440
     file does not contain section addresses, (such as in the `a.out'
5441
     format), or when the addresses specified in the file itself are
5442
     wrong.  Each section must be changed separately.  The `info files'
5443
     command, described below, lists all the sections and their
5444
     addresses.
5445
 
5446
`info files'
5447
`info target'
5448
     `info files' and `info target' are synonymous; both print the
5449
     current target (*note Specifying a Debugging Target: Targets.),
5450
     including the names of the executable and core dump files
5451
     currently in use by GDB, and the files from which symbols were
5452
     loaded.  The command `help target' lists all possible targets
5453
     rather than current ones.
5454
 
5455
`maint info sections'
5456
     Another command that can give you extra information about program
5457
     sections is `maint info sections'.  In addition to the section
5458
     information displayed by `info files', this command displays the
5459
     flags and file offset of each section in the executable and core
5460
     dump files.  In addition, `maint info sections' provides the
5461
     following command options (which may be arbitrarily combined):
5462
 
5463
    `ALLOBJ'
5464
          Display sections for all loaded object files, including
5465
          shared libraries.
5466
 
5467
    `SECTIONS'
5468
          Display info only for named SECTIONS.
5469
 
5470
    `SECTION-FLAGS'
5471
          Display info only for sections for which SECTION-FLAGS are
5472
          true.  The section flags that GDB currently knows about are:
5473
         `ALLOC'
5474
               Section will have space allocated in the process when
5475
               loaded.  Set for all sections except those containing
5476
               debug information.
5477
 
5478
         `LOAD'
5479
               Section will be loaded from the file into the child
5480
               process memory.  Set for pre-initialized code and data,
5481
               clear for `.bss' sections.
5482
 
5483
         `RELOC'
5484
               Section needs to be relocated before loading.
5485
 
5486
         `READONLY'
5487
               Section cannot be modified by the child process.
5488
 
5489
         `CODE'
5490
               Section contains executable code only.
5491
 
5492
         `DATA'
5493
               Section contains data only (no executable code).
5494
 
5495
         `ROM'
5496
               Section will reside in ROM.
5497
 
5498
         `CONSTRUCTOR'
5499
               Section contains data for constructor/destructor lists.
5500
 
5501
         `HAS_CONTENTS'
5502
               Section is not empty.
5503
 
5504
         `NEVER_LOAD'
5505
               An instruction to the linker to not output the section.
5506
 
5507
         `COFF_SHARED_LIBRARY'
5508
               A notification to the linker that the section contains
5509
               COFF shared library information.
5510
 
5511
         `IS_COMMON'
5512
               Section contains common symbols.
5513
 
5514
`set trust-readonly-sections on'
5515
     Tell GDB that readonly sections in your object file really are
5516
     read-only (i.e. that their contents will not change).  In that
5517
     case, GDB can fetch values from these sections out of the object
5518
     file, rather than from the target program.  For some targets
5519
     (notably embedded ones), this can be a significant enhancement to
5520
     debugging performance.
5521
 
5522
     The default is off.
5523
 
5524
`set trust-readonly-sections off'
5525
     Tell GDB not to trust readonly sections.  This means that the
5526
     contents of the section might change while the program is running,
5527
     and must therefore be fetched from the target when needed.
5528
 
5529
`show trust-readonly-sections'
5530
     Show the current setting of trusting readonly sections.
5531
 
5532
   All file-specifying commands allow both absolute and relative file
5533
names as arguments.  GDB always converts the file name to an absolute
5534
file name and remembers it that way.
5535
 
5536
   GDB supports GNU/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix, and
5537
IBM RS/6000 AIX shared libraries.
5538
 
5539
   On MS-Windows GDB must be linked with the Expat library to support
5540
shared libraries.  *Note Expat::.
5541
 
5542
   GDB automatically loads symbol definitions from shared libraries
5543
when you use the `run' command, or when you examine a core file.
5544
(Before you issue the `run' command, GDB does not understand references
5545
to a function in a shared library, however--unless you are debugging a
5546
core file).
5547
 
5548
   On HP-UX, if the program loads a library explicitly, GDB
5549
automatically loads the symbols at the time of the `shl_load' call.
5550
 
5551
   There are times, however, when you may wish to not automatically load
5552
symbol definitions from shared libraries, such as when they are
5553
particularly large or there are many of them.
5554
 
5555
   To control the automatic loading of shared library symbols, use the
5556
commands:
5557
 
5558
`set auto-solib-add MODE'
5559
     If MODE is `on', symbols from all shared object libraries will be
5560
     loaded automatically when the inferior begins execution, you
5561
     attach to an independently started inferior, or when the dynamic
5562
     linker informs GDB that a new library has been loaded.  If MODE is
5563
     `off', symbols must be loaded manually, using the `sharedlibrary'
5564
     command.  The default value is `on'.
5565
 
5566
     If your program uses lots of shared libraries with debug info that
5567
     takes large amounts of memory, you can decrease the GDB memory
5568
     footprint by preventing it from automatically loading the symbols
5569
     from shared libraries.  To that end, type `set auto-solib-add off'
5570
     before running the inferior, then load each library whose debug
5571
     symbols you do need with `sharedlibrary REGEXP', where REGEXP is a
5572
     regular expression that matches the libraries whose symbols you
5573
     want to be loaded.
5574
 
5575
`show auto-solib-add'
5576
     Display the current autoloading mode.
5577
 
5578
   To explicitly load shared library symbols, use the `sharedlibrary'
5579
command:
5580
 
5581
`info share REGEX'
5582
`info sharedlibrary REGEX'
5583
     Print the names of the shared libraries which are currently loaded
5584
     that match REGEX.  If REGEX is omitted then print all shared
5585
     libraries that are loaded.
5586
 
5587
`sharedlibrary REGEX'
5588
`share REGEX'
5589
     Load shared object library symbols for files matching a Unix
5590
     regular expression.  As with files loaded automatically, it only
5591
     loads shared libraries required by your program for a core file or
5592
     after typing `run'.  If REGEX is omitted all shared libraries
5593
     required by your program are loaded.
5594
 
5595
`nosharedlibrary'
5596
     Unload all shared object library symbols.  This discards all
5597
     symbols that have been loaded from all shared libraries.  Symbols
5598
     from shared libraries that were loaded by explicit user requests
5599
     are not discarded.
5600
 
5601
   Sometimes you may wish that GDB stops and gives you control when any
5602
of shared library events happen.  Use the `set stop-on-solib-events'
5603
command for this:
5604
 
5605
`set stop-on-solib-events'
5606
     This command controls whether GDB should give you control when the
5607
     dynamic linker notifies it about some shared library event.  The
5608
     most common event of interest is loading or unloading of a new
5609
     shared library.
5610
 
5611
`show stop-on-solib-events'
5612
     Show whether GDB stops and gives you control when shared library
5613
     events happen.
5614
 
5615
   Shared libraries are also supported in many cross or remote debugging
5616
configurations.  GDB needs to have access to the target's libraries;
5617
this can be accomplished either by providing copies of the libraries on
5618
the host system, or by asking GDB to automatically retrieve the
5619
libraries from the target.  If copies of the target libraries are
5620
provided, they need to be the same as the target libraries, although the
5621
copies on the target can be stripped as long as the copies on the host
5622
are not.
5623
 
5624
   For remote debugging, you need to tell GDB where the target
5625
libraries are, so that it can load the correct copies--otherwise, it
5626
may try to load the host's libraries.  GDB has two variables to specify
5627
the search directories for target libraries.
5628
 
5629
`set sysroot PATH'
5630
     Use PATH as the system root for the program being debugged.  Any
5631
     absolute shared library paths will be prefixed with PATH; many
5632
     runtime loaders store the absolute paths to the shared library in
5633
     the target program's memory.  If you use `set sysroot' to find
5634
     shared libraries, they need to be laid out in the same way that
5635
     they are on the target, with e.g. a `/lib' and `/usr/lib' hierarchy
5636
     under PATH.
5637
 
5638
     If PATH starts with the sequence `remote:', GDB will retrieve the
5639
     target libraries from the remote system.  This is only supported
5640
     when using a remote target that supports the `remote get' command
5641
     (*note Sending files to a remote system: File Transfer.).  The
5642
     part of PATH following the initial `remote:' (if present) is used
5643
     as system root prefix on the remote file system.  (1)
5644
 
5645
     For targets with an MS-DOS based filesystem, such as MS-Windows and
5646
     SymbianOS, GDB tries prefixing a few variants of the target
5647
     absolute file name with PATH.  But first, on Unix hosts, GDB
5648
     converts all backslash directory separators into forward slashes,
5649
     because the backslash is not a directory separator on Unix:
5650
 
5651
            c:\foo\bar.dll => c:/foo/bar.dll
5652
 
5653
     Then, GDB attempts prefixing the target file name with PATH, and
5654
     looks for the resulting file name in the host file system:
5655
 
5656
            c:/foo/bar.dll => /path/to/sysroot/c:/foo/bar.dll
5657
 
5658
     If that does not find the shared library, GDB tries removing the
5659
     `:' character from the drive spec, both for convenience, and, for
5660
     the case of the host file system not supporting file names with
5661
     colons:
5662
 
5663
            c:/foo/bar.dll => /path/to/sysroot/c/foo/bar.dll
5664
 
5665
     This makes it possible to have a system root that mirrors a target
5666
     with more than one drive.  E.g., you may want to setup your local
5667
     copies of the target system shared libraries like so (note `c' vs
5668
     `z'):
5669
 
5670
           `/path/to/sysroot/c/sys/bin/foo.dll'
5671
           `/path/to/sysroot/c/sys/bin/bar.dll'
5672
           `/path/to/sysroot/z/sys/bin/bar.dll'
5673
 
5674
     and point the system root at `/path/to/sysroot', so that GDB can
5675
     find the correct copies of both `c:\sys\bin\foo.dll', and
5676
     `z:\sys\bin\bar.dll'.
5677
 
5678
     If that still does not find the shared library, GDB tries removing
5679
     the whole drive spec from the target file name:
5680
 
5681
            c:/foo/bar.dll => /path/to/sysroot/foo/bar.dll
5682
 
5683
     This last lookup makes it possible to not care about the drive
5684
     name, if you don't want or need to.
5685
 
5686
     The `set solib-absolute-prefix' command is an alias for `set
5687
     sysroot'.
5688
 
5689
     You can set the default system root by using the configure-time
5690
     `--with-sysroot' option.  If the system root is inside GDB's
5691
     configured binary prefix (set with `--prefix' or `--exec-prefix'),
5692
     then the default system root will be updated automatically if the
5693
     installed GDB is moved to a new location.
5694
 
5695
`show sysroot'
5696
     Display the current shared library prefix.
5697
 
5698
`set solib-search-path PATH'
5699
     If this variable is set, PATH is a colon-separated list of
5700
     directories to search for shared libraries.  `solib-search-path'
5701
     is used after `sysroot' fails to locate the library, or if the
5702
     path to the library is relative instead of absolute.  If you want
5703
     to use `solib-search-path' instead of `sysroot', be sure to set
5704
     `sysroot' to a nonexistent directory to prevent GDB from finding
5705
     your host's libraries.  `sysroot' is preferred; setting it to a
5706
     nonexistent directory may interfere with automatic loading of
5707
     shared library symbols.
5708
 
5709
`show solib-search-path'
5710
     Display the current shared library search path.
5711
 
5712
`set target-file-system-kind KIND'
5713
     Set assumed file system kind for target reported file names.
5714
 
5715
     Shared library file names as reported by the target system may not
5716
     make sense as is on the system GDB is running on.  For example,
5717
     when remote debugging a target that has MS-DOS based file system
5718
     semantics, from a Unix host, the target may be reporting to GDB a
5719
     list of loaded shared libraries with file names such as
5720
     `c:\Windows\kernel32.dll'.  On Unix hosts, there's no concept of
5721
     drive letters, so the `c:\' prefix is not normally understood as
5722
     indicating an absolute file name, and neither is the backslash
5723
     normally considered a directory separator character.  In that case,
5724
     the native file system would interpret this whole absolute file
5725
     name as a relative file name with no directory components.  This
5726
     would make it impossible to point GDB at a copy of the remote
5727
     target's shared libraries on the host using `set sysroot', and
5728
     impractical with `set solib-search-path'.  Setting
5729
     `target-file-system-kind' to `dos-based' tells GDB to interpret
5730
     such file names similarly to how the target would, and to map them
5731
     to file names valid on GDB's native file system semantics.  The
5732
     value of KIND can be `"auto"', in addition to one of the supported
5733
     file system kinds.  In that case, GDB tries to determine the
5734
     appropriate file system variant based on the current target's
5735
     operating system (*note Configuring the Current ABI: ABI.).  The
5736
     supported file system settings are:
5737
 
5738
    `unix'
5739
          Instruct GDB to assume the target file system is of Unix
5740
          kind.  Only file names starting the forward slash (`/')
5741
          character are considered absolute, and the directory
5742
          separator character is also the forward slash.
5743
 
5744
    `dos-based'
5745
          Instruct GDB to assume the target file system is DOS based.
5746
          File names starting with either a forward slash, or a drive
5747
          letter followed by a colon (e.g., `c:'), are considered
5748
          absolute, and both the slash (`/') and the backslash (`\\')
5749
          characters are considered directory separators.
5750
 
5751
    `auto'
5752
          Instruct GDB to use the file system kind associated with the
5753
          target operating system (*note Configuring the Current ABI:
5754
          ABI.).  This is the default.
5755
 
5756
   ---------- Footnotes ----------
5757
 
5758
   (1) If you want to specify a local system root using a directory
5759
that happens to be named `remote:', you need to use some equivalent
5760
variant of the name like `./remote:'.
5761
 
5762

5763
File: gdb.info,  Node: Separate Debug Files,  Next: Symbol Errors,  Prev: Files,  Up: GDB Files
5764
 
5765
18.2 Debugging Information in Separate Files
5766
============================================
5767
 
5768
GDB allows you to put a program's debugging information in a file
5769
separate from the executable itself, in a way that allows GDB to find
5770
and load the debugging information automatically.  Since debugging
5771
information can be very large--sometimes larger than the executable
5772
code itself--some systems distribute debugging information for their
5773
executables in separate files, which users can install only when they
5774
need to debug a problem.
5775
 
5776
   GDB supports two ways of specifying the separate debug info file:
5777
 
5778
   * The executable contains a "debug link" that specifies the name of
5779
     the separate debug info file.  The separate debug file's name is
5780
     usually `EXECUTABLE.debug', where EXECUTABLE is the name of the
5781
     corresponding executable file without leading directories (e.g.,
5782
     `ls.debug' for `/usr/bin/ls').  In addition, the debug link
5783
     specifies a 32-bit "Cyclic Redundancy Check" (CRC) checksum for
5784
     the debug file, which GDB uses to validate that the executable and
5785
     the debug file came from the same build.
5786
 
5787
   * The executable contains a "build ID", a unique bit string that is
5788
     also present in the corresponding debug info file.  (This is
5789
     supported only on some operating systems, notably those which use
5790
     the ELF format for binary files and the GNU Binutils.)  For more
5791
     details about this feature, see the description of the `--build-id'
5792
     command-line option in *Note Command Line Options:
5793
     (ld.info)Options.  The debug info file's name is not specified
5794
     explicitly by the build ID, but can be computed from the build ID,
5795
     see below.
5796
 
5797
   Depending on the way the debug info file is specified, GDB uses two
5798
different methods of looking for the debug file:
5799
 
5800
   * For the "debug link" method, GDB looks up the named file in the
5801
     directory of the executable file, then in a subdirectory of that
5802
     directory named `.debug', and finally under the global debug
5803
     directory, in a subdirectory whose name is identical to the leading
5804
     directories of the executable's absolute file name.
5805
 
5806
   * For the "build ID" method, GDB looks in the `.build-id'
5807
     subdirectory of the global debug directory for a file named
5808
     `NN/NNNNNNNN.debug', where NN are the first 2 hex characters of
5809
     the build ID bit string, and NNNNNNNN are the rest of the bit
5810
     string.  (Real build ID strings are 32 or more hex characters, not
5811
     10.)
5812
 
5813
   So, for example, suppose you ask GDB to debug `/usr/bin/ls', which
5814
has a debug link that specifies the file `ls.debug', and a build ID
5815
whose value in hex is `abcdef1234'.  If the global debug directory is
5816
`/usr/lib/debug', then GDB will look for the following debug
5817
information files, in the indicated order:
5818
 
5819
   - `/usr/lib/debug/.build-id/ab/cdef1234.debug'
5820
 
5821
   - `/usr/bin/ls.debug'
5822
 
5823
   - `/usr/bin/.debug/ls.debug'
5824
 
5825
   - `/usr/lib/debug/usr/bin/ls.debug'.
5826
 
5827
   You can set the global debugging info directory's name, and view the
5828
name GDB is currently using.
5829
 
5830
`set debug-file-directory DIRECTORIES'
5831
     Set the directories which GDB searches for separate debugging
5832
     information files to DIRECTORY.  Multiple directory components can
5833
     be set concatenating them by a directory separator.
5834
 
5835
`show debug-file-directory'
5836
     Show the directories GDB searches for separate debugging
5837
     information files.
5838
 
5839
 
5840
   A debug link is a special section of the executable file named
5841
`.gnu_debuglink'.  The section must contain:
5842
 
5843
   * A filename, with any leading directory components removed,
5844
     followed by a zero byte,
5845
 
5846
   * zero to three bytes of padding, as needed to reach the next
5847
     four-byte boundary within the section, and
5848
 
5849
   * a four-byte CRC checksum, stored in the same endianness used for
5850
     the executable file itself.  The checksum is computed on the
5851
     debugging information file's full contents by the function given
5852
     below, passing zero as the CRC argument.
5853
 
5854
   Any executable file format can carry a debug link, as long as it can
5855
contain a section named `.gnu_debuglink' with the contents described
5856
above.
5857
 
5858
   The build ID is a special section in the executable file (and in
5859
other ELF binary files that GDB may consider).  This section is often
5860
named `.note.gnu.build-id', but that name is not mandatory.  It
5861
contains unique identification for the built files--the ID remains the
5862
same across multiple builds of the same build tree.  The default
5863
algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
5864
content for the build ID string.  The same section with an identical
5865
value is present in the original built binary with symbols, in its
5866
stripped variant, and in the separate debugging information file.
5867
 
5868
   The debugging information file itself should be an ordinary
5869
executable, containing a full set of linker symbols, sections, and
5870
debugging information.  The sections of the debugging information file
5871
should have the same names, addresses, and sizes as the original file,
5872
but they need not contain any data--much like a `.bss' section in an
5873
ordinary executable.
5874
 
5875
   The GNU binary utilities (Binutils) package includes the `objcopy'
5876
utility that can produce the separated executable / debugging
5877
information file pairs using the following commands:
5878
 
5879
     objcopy --only-keep-debug foo foo.debug
5880
     strip -g foo
5881
 
5882
These commands remove the debugging information from the executable
5883
file `foo' and place it in the file `foo.debug'.  You can use the
5884
first, second or both methods to link the two files:
5885
 
5886
   * The debug link method needs the following additional command to
5887
     also leave behind a debug link in `foo':
5888
 
5889
          objcopy --add-gnu-debuglink=foo.debug foo
5890
 
5891
     Ulrich Drepper's `elfutils' package, starting with version 0.53,
5892
     contains a version of the `strip' command such that the command
5893
     `strip foo -f foo.debug' has the same functionality as the two
5894
     `objcopy' commands and the `ln -s' command above, together.
5895
 
5896
   * Build ID gets embedded into the main executable using `ld
5897
     --build-id' or the GCC counterpart `gcc -Wl,--build-id'.  Build ID
5898
     support plus compatibility fixes for debug files separation are
5899
     present in GNU binary utilities (Binutils) package since version
5900
     2.18.
5901
 
5902
The CRC used in `.gnu_debuglink' is the CRC-32 defined in IEEE 802.3
5903
using the polynomial:
5904
 
5905
      x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11
5906
      + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
5907
 
5908
   The function is computed byte at a time, taking the least
5909
significant bit of each byte first.  The initial pattern `0xffffffff'
5910
is used, to ensure leading zeros affect the CRC and the final result is
5911
inverted to ensure trailing zeros also affect the CRC.
5912
 
5913
   _Note:_ This is the same CRC polynomial as used in handling the
5914
"Remote Serial Protocol" `qCRC' packet (*note GDB Remote Serial
5915
Protocol: Remote Protocol.).  However in the case of the Remote Serial
5916
Protocol, the CRC is computed _most_ significant bit first, and the
5917
result is not inverted, so trailing zeros have no effect on the CRC
5918
value.
5919
 
5920
   To complete the description, we show below the code of the function
5921
which produces the CRC used in `.gnu_debuglink'.  Inverting the
5922
initially supplied `crc' argument means that an initial call to this
5923
function passing in zero will start computing the CRC using
5924
`0xffffffff'.
5925
 
5926
     unsigned long
5927
     gnu_debuglink_crc32 (unsigned long crc,
5928
                          unsigned char *buf, size_t len)
5929
     {
5930
       static const unsigned long crc32_table[256] =
5931
         {
5932
           0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
5933
           0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
5934
           0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
5935
           0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
5936
           0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
5937
           0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
5938
           0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
5939
           0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
5940
           0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
5941
           0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
5942
           0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
5943
           0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
5944
           0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
5945
           0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
5946
           0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
5947
           0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
5948
           0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
5949
           0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
5950
           0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
5951
           0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
5952
           0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
5953
           0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
5954
           0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
5955
           0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
5956
           0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
5957
           0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
5958
           0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
5959
           0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
5960
           0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
5961
           0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
5962
           0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
5963
           0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
5964
           0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
5965
           0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
5966
           0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
5967
           0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
5968
           0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
5969
           0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
5970
           0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
5971
           0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
5972
           0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
5973
           0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
5974
           0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
5975
           0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
5976
           0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
5977
           0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
5978
           0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
5979
           0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
5980
           0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
5981
           0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
5982
           0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
5983
           0x2d02ef8d
5984
         };
5985
       unsigned char *end;
5986
 
5987
       crc = ~crc & 0xffffffff;
5988
       for (end = buf + len; buf < end; ++buf)
5989
         crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
5990
       return ~crc & 0xffffffff;
5991
     }
5992
 
5993
This computation does not apply to the "build ID" method.
5994
 
5995

5996
File: gdb.info,  Node: Symbol Errors,  Next: Data Files,  Prev: Separate Debug Files,  Up: GDB Files
5997
 
5998
18.3 Errors Reading Symbol Files
5999
================================
6000
 
6001
While reading a symbol file, GDB occasionally encounters problems, such
6002
as symbol types it does not recognize, or known bugs in compiler
6003
output.  By default, GDB does not notify you of such problems, since
6004
they are relatively common and primarily of interest to people
6005
debugging compilers.  If you are interested in seeing information about
6006
ill-constructed symbol tables, you can either ask GDB to print only one
6007
message about each such type of problem, no matter how many times the
6008
problem occurs; or you can ask GDB to print more messages, to see how
6009
many times the problems occur, with the `set complaints' command (*note
6010
Optional Warnings and Messages: Messages/Warnings.).
6011
 
6012
   The messages currently printed, and their meanings, include:
6013
 
6014
`inner block not inside outer block in SYMBOL'
6015
     The symbol information shows where symbol scopes begin and end
6016
     (such as at the start of a function or a block of statements).
6017
     This error indicates that an inner scope block is not fully
6018
     contained in its outer scope blocks.
6019
 
6020
     GDB circumvents the problem by treating the inner block as if it
6021
     had the same scope as the outer block.  In the error message,
6022
     SYMBOL may be shown as "`(don't know)'" if the outer block is not a
6023
     function.
6024
 
6025
`block at ADDRESS out of order'
6026
     The symbol information for symbol scope blocks should occur in
6027
     order of increasing addresses.  This error indicates that it does
6028
     not do so.
6029
 
6030
     GDB does not circumvent this problem, and has trouble locating
6031
     symbols in the source file whose symbols it is reading.  (You can
6032
     often determine what source file is affected by specifying `set
6033
     verbose on'.  *Note Optional Warnings and Messages:
6034
     Messages/Warnings.)
6035
 
6036
`bad block start address patched'
6037
     The symbol information for a symbol scope block has a start address
6038
     smaller than the address of the preceding source line.  This is
6039
     known to occur in the SunOS 4.1.1 (and earlier) C compiler.
6040
 
6041
     GDB circumvents the problem by treating the symbol scope block as
6042
     starting on the previous source line.
6043
 
6044
`bad string table offset in symbol N'
6045
     Symbol number N contains a pointer into the string table which is
6046
     larger than the size of the string table.
6047
 
6048
     GDB circumvents the problem by considering the symbol to have the
6049
     name `foo', which may cause other problems if many symbols end up
6050
     with this name.
6051
 
6052
`unknown symbol type `0xNN''
6053
     The symbol information contains new data types that GDB does not
6054
     yet know how to read.  `0xNN' is the symbol type of the
6055
     uncomprehended information, in hexadecimal.
6056
 
6057
     GDB circumvents the error by ignoring this symbol information.
6058
     This usually allows you to debug your program, though certain
6059
     symbols are not accessible.  If you encounter such a problem and
6060
     feel like debugging it, you can debug `gdb' with itself, breakpoint
6061
     on `complain', then go up to the function `read_dbx_symtab' and
6062
     examine `*bufp' to see the symbol.
6063
 
6064
`stub type has NULL name'
6065
     GDB could not find the full definition for a struct or class.
6066
 
6067
`const/volatile indicator missing (ok if using g++ v1.x), got...'
6068
     The symbol information for a C++ member function is missing some
6069
     information that recent versions of the compiler should have
6070
     output for it.
6071
 
6072
`info mismatch between compiler and debugger'
6073
     GDB could not parse a type specification output by the compiler.
6074
 
6075
 
6076

6077
File: gdb.info,  Node: Data Files,  Prev: Symbol Errors,  Up: GDB Files
6078
 
6079
18.4 GDB Data Files
6080
===================
6081
 
6082
GDB will sometimes read an auxiliary data file.  These files are kept
6083
in a directory known as the "data directory".
6084
 
6085
   You can set the data directory's name, and view the name GDB is
6086
currently using.
6087
 
6088
`set data-directory DIRECTORY'
6089
     Set the directory which GDB searches for auxiliary data files to
6090
     DIRECTORY.
6091
 
6092
`show data-directory'
6093
     Show the directory GDB searches for auxiliary data files.
6094
 
6095
   You can set the default data directory by using the configure-time
6096
`--with-gdb-datadir' option.  If the data directory is inside GDB's
6097
configured binary prefix (set with `--prefix' or `--exec-prefix'), then
6098
the default data directory will be updated automatically if the
6099
installed GDB is moved to a new location.
6100
 
6101

6102
File: gdb.info,  Node: Targets,  Next: Remote Debugging,  Prev: GDB Files,  Up: Top
6103
 
6104
19 Specifying a Debugging Target
6105
********************************
6106
 
6107
A "target" is the execution environment occupied by your program.
6108
 
6109
   Often, GDB runs in the same host environment as your program; in
6110
that case, the debugging target is specified as a side effect when you
6111
use the `file' or `core' commands.  When you need more flexibility--for
6112
example, running GDB on a physically separate host, or controlling a
6113
standalone system over a serial port or a realtime system over a TCP/IP
6114
connection--you can use the `target' command to specify one of the
6115
target types configured for GDB (*note Commands for Managing Targets:
6116
Target Commands.).
6117
 
6118
   It is possible to build GDB for several different "target
6119
architectures".  When GDB is built like that, you can choose one of the
6120
available architectures with the `set architecture' command.
6121
 
6122
`set architecture ARCH'
6123
     This command sets the current target architecture to ARCH.  The
6124
     value of ARCH can be `"auto"', in addition to one of the supported
6125
     architectures.
6126
 
6127
`show architecture'
6128
     Show the current target architecture.
6129
 
6130
`set processor'
6131
`processor'
6132
     These are alias commands for, respectively, `set architecture' and
6133
     `show architecture'.
6134
 
6135
* Menu:
6136
 
6137
* Active Targets::              Active targets
6138
* Target Commands::             Commands for managing targets
6139
* Byte Order::                  Choosing target byte order
6140
 
6141

6142
File: gdb.info,  Node: Active Targets,  Next: Target Commands,  Up: Targets
6143
 
6144
19.1 Active Targets
6145
===================
6146
 
6147
There are three classes of targets: processes, core files, and
6148
executable files.  GDB can work concurrently on up to three active
6149
targets, one in each class.  This allows you to (for example) start a
6150
process and inspect its activity without abandoning your work on a core
6151
file.
6152
 
6153
   For example, if you execute `gdb a.out', then the executable file
6154
`a.out' is the only active target.  If you designate a core file as
6155
well--presumably from a prior run that crashed and coredumped--then GDB
6156
has two active targets and uses them in tandem, looking first in the
6157
corefile target, then in the executable file, to satisfy requests for
6158
memory addresses.  (Typically, these two classes of target are
6159
complementary, since core files contain only a program's read-write
6160
memory--variables and so on--plus machine status, while executable
6161
files contain only the program text and initialized data.)
6162
 
6163
   When you type `run', your executable file becomes an active process
6164
target as well.  When a process target is active, all GDB commands
6165
requesting memory addresses refer to that target; addresses in an
6166
active core file or executable file target are obscured while the
6167
process target is active.
6168
 
6169
   Use the `core-file' and `exec-file' commands to select a new core
6170
file or executable target (*note Commands to Specify Files: Files.).
6171
To specify as a target a process that is already running, use the
6172
`attach' command (*note Debugging an Already-running Process: Attach.).
6173
 
6174

6175
File: gdb.info,  Node: Target Commands,  Next: Byte Order,  Prev: Active Targets,  Up: Targets
6176
 
6177
19.2 Commands for Managing Targets
6178
==================================
6179
 
6180
`target TYPE PARAMETERS'
6181
     Connects the GDB host environment to a target machine or process.
6182
     A target is typically a protocol for talking to debugging
6183
     facilities.  You use the argument TYPE to specify the type or
6184
     protocol of the target machine.
6185
 
6186
     Further PARAMETERS are interpreted by the target protocol, but
6187
     typically include things like device names or host names to connect
6188
     with, process numbers, and baud rates.
6189
 
6190
     The `target' command does not repeat if you press  again
6191
     after executing the command.
6192
 
6193
`help target'
6194
     Displays the names of all targets available.  To display targets
6195
     currently selected, use either `info target' or `info files'
6196
     (*note Commands to Specify Files: Files.).
6197
 
6198
`help target NAME'
6199
     Describe a particular target, including any parameters necessary to
6200
     select it.
6201
 
6202
`set gnutarget ARGS'
6203
     GDB uses its own library BFD to read your files.  GDB knows
6204
     whether it is reading an "executable", a "core", or a ".o" file;
6205
     however, you can specify the file format with the `set gnutarget'
6206
     command.  Unlike most `target' commands, with `gnutarget' the
6207
     `target' refers to a program, not a machine.
6208
 
6209
          _Warning:_ To specify a file format with `set gnutarget', you
6210
          must know the actual BFD name.
6211
 
6212
     *Note Commands to Specify Files: Files.
6213
 
6214
`show gnutarget'
6215
     Use the `show gnutarget' command to display what file format
6216
     `gnutarget' is set to read.  If you have not set `gnutarget', GDB
6217
     will determine the file format for each file automatically, and
6218
     `show gnutarget' displays `The current BDF target is "auto"'.
6219
 
6220
   Here are some common targets (available, or not, depending on the GDB
6221
configuration):
6222
 
6223
`target exec PROGRAM'
6224
     An executable file.  `target exec PROGRAM' is the same as
6225
     `exec-file PROGRAM'.
6226
 
6227
`target core FILENAME'
6228
     A core dump file.  `target core FILENAME' is the same as
6229
     `core-file FILENAME'.
6230
 
6231
`target remote MEDIUM'
6232
     A remote system connected to GDB via a serial line or network
6233
     connection.  This command tells GDB to use its own remote protocol
6234
     over MEDIUM for debugging.  *Note Remote Debugging::.
6235
 
6236
     For example, if you have a board connected to `/dev/ttya' on the
6237
     machine running GDB, you could say:
6238
 
6239
          target remote /dev/ttya
6240
 
6241
     `target remote' supports the `load' command.  This is only useful
6242
     if you have some other way of getting the stub to the target
6243
     system, and you can put it somewhere in memory where it won't get
6244
     clobbered by the download.
6245
 
6246
`target sim [SIMARGS] ...'
6247
     Builtin CPU simulator.  GDB includes simulators for most
6248
     architectures.  In general,
6249
                  target sim
6250
                  load
6251
                  run
6252
     works; however, you cannot assume that a specific memory map,
6253
     device drivers, or even basic I/O is available, although some
6254
     simulators do provide these.  For info about any
6255
     processor-specific simulator details, see the appropriate section
6256
     in *Note Embedded Processors: Embedded Processors.
6257
 
6258
 
6259
   Some configurations may include these targets as well:
6260
 
6261
`target nrom DEV'
6262
     NetROM ROM emulator.  This target only supports downloading.
6263
 
6264
 
6265
   Different targets are available on different configurations of GDB;
6266
your configuration may have more or fewer targets.
6267
 
6268
   Many remote targets require you to download the executable's code
6269
once you've successfully established a connection.  You may wish to
6270
control various aspects of this process.
6271
 
6272
`set hash'
6273
     This command controls whether a hash mark `#' is displayed while
6274
     downloading a file to the remote monitor.  If on, a hash mark is
6275
     displayed after each S-record is successfully downloaded to the
6276
     monitor.
6277
 
6278
`show hash'
6279
     Show the current status of displaying the hash mark.
6280
 
6281
`set debug monitor'
6282
     Enable or disable display of communications messages between GDB
6283
     and the remote monitor.
6284
 
6285
`show debug monitor'
6286
     Show the current status of displaying communications between GDB
6287
     and the remote monitor.
6288
 
6289
`load FILENAME'
6290
     Depending on what remote debugging facilities are configured into
6291
     GDB, the `load' command may be available.  Where it exists, it is
6292
     meant to make FILENAME (an executable) available for debugging on
6293
     the remote system--by downloading, or dynamic linking, for example.
6294
     `load' also records the FILENAME symbol table in GDB, like the
6295
     `add-symbol-file' command.
6296
 
6297
     If your GDB does not have a `load' command, attempting to execute
6298
     it gets the error message "`You can't do that when your target is
6299
     ...'"
6300
 
6301
     The file is loaded at whatever address is specified in the
6302
     executable.  For some object file formats, you can specify the
6303
     load address when you link the program; for other formats, like
6304
     a.out, the object file format specifies a fixed address.
6305
 
6306
     Depending on the remote side capabilities, GDB may be able to load
6307
     programs into flash memory.
6308
 
6309
     `load' does not repeat if you press  again after using it.
6310
 
6311

6312
File: gdb.info,  Node: Byte Order,  Prev: Target Commands,  Up: Targets
6313
 
6314
19.3 Choosing Target Byte Order
6315
===============================
6316
 
6317
Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
6318
offer the ability to run either big-endian or little-endian byte
6319
orders.  Usually the executable or symbol will include a bit to
6320
designate the endian-ness, and you will not need to worry about which
6321
to use.  However, you may still find it useful to adjust GDB's idea of
6322
processor endian-ness manually.
6323
 
6324
`set endian big'
6325
     Instruct GDB to assume the target is big-endian.
6326
 
6327
`set endian little'
6328
     Instruct GDB to assume the target is little-endian.
6329
 
6330
`set endian auto'
6331
     Instruct GDB to use the byte order associated with the executable.
6332
 
6333
`show endian'
6334
     Display GDB's current idea of the target byte order.
6335
 
6336
 
6337
   Note that these commands merely adjust interpretation of symbolic
6338
data on the host, and that they have absolutely no effect on the target
6339
system.
6340
 
6341

6342
File: gdb.info,  Node: Remote Debugging,  Next: Configurations,  Prev: Targets,  Up: Top
6343
 
6344
20 Debugging Remote Programs
6345
****************************
6346
 
6347
If you are trying to debug a program running on a machine that cannot
6348
run GDB in the usual way, it is often useful to use remote debugging.
6349
For example, you might use remote debugging on an operating system
6350
kernel, or on a small system which does not have a general purpose
6351
operating system powerful enough to run a full-featured debugger.
6352
 
6353
   Some configurations of GDB have special serial or TCP/IP interfaces
6354
to make this work with particular debugging targets.  In addition, GDB
6355
comes with a generic serial protocol (specific to GDB, but not specific
6356
to any particular target system) which you can use if you write the
6357
remote stubs--the code that runs on the remote system to communicate
6358
with GDB.
6359
 
6360
   Other remote targets may be available in your configuration of GDB;
6361
use `help target' to list them.
6362
 
6363
* Menu:
6364
 
6365
* Connecting::                  Connecting to a remote target
6366
* File Transfer::               Sending files to a remote system
6367
* Server::                      Using the gdbserver program
6368
* Remote Configuration::        Remote configuration
6369
* Remote Stub::                 Implementing a remote stub
6370
 
6371

6372
File: gdb.info,  Node: Connecting,  Next: File Transfer,  Up: Remote Debugging
6373
 
6374
20.1 Connecting to a Remote Target
6375
==================================
6376
 
6377
On the GDB host machine, you will need an unstripped copy of your
6378
program, since GDB needs symbol and debugging information.  Start up
6379
GDB as usual, using the name of the local copy of your program as the
6380
first argument.
6381
 
6382
   GDB can communicate with the target over a serial line, or over an
6383
IP network using TCP or UDP.  In each case, GDB uses the same protocol
6384
for debugging your program; only the medium carrying the debugging
6385
packets varies.  The `target remote' command establishes a connection
6386
to the target.  Its arguments indicate which medium to use:
6387
 
6388
`target remote SERIAL-DEVICE'
6389
     Use SERIAL-DEVICE to communicate with the target.  For example, to
6390
     use a serial line connected to the device named `/dev/ttyb':
6391
 
6392
          target remote /dev/ttyb
6393
 
6394
     If you're using a serial line, you may want to give GDB the
6395
     `--baud' option, or use the `set remotebaud' command (*note set
6396
     remotebaud: Remote Configuration.) before the `target' command.
6397
 
6398
`target remote `HOST:PORT''
6399
`target remote `tcp:HOST:PORT''
6400
     Debug using a TCP connection to PORT on HOST.  The HOST may be
6401
     either a host name or a numeric IP address; PORT must be a decimal
6402
     number.  The HOST could be the target machine itself, if it is
6403
     directly connected to the net, or it might be a terminal server
6404
     which in turn has a serial line to the target.
6405
 
6406
     For example, to connect to port 2828 on a terminal server named
6407
     `manyfarms':
6408
 
6409
          target remote manyfarms:2828
6410
 
6411
     If your remote target is actually running on the same machine as
6412
     your debugger session (e.g. a simulator for your target running on
6413
     the same host), you can omit the hostname.  For example, to
6414
     connect to port 1234 on your local machine:
6415
 
6416
          target remote :1234
6417
     Note that the colon is still required here.
6418
 
6419
`target remote `udp:HOST:PORT''
6420
     Debug using UDP packets to PORT on HOST.  For example, to connect
6421
     to UDP port 2828 on a terminal server named `manyfarms':
6422
 
6423
          target remote udp:manyfarms:2828
6424
 
6425
     When using a UDP connection for remote debugging, you should keep
6426
     in mind that the `U' stands for "Unreliable".  UDP can silently
6427
     drop packets on busy or unreliable networks, which will cause
6428
     havoc with your debugging session.
6429
 
6430
`target remote | COMMAND'
6431
     Run COMMAND in the background and communicate with it using a
6432
     pipe.  The COMMAND is a shell command, to be parsed and expanded
6433
     by the system's command shell, `/bin/sh'; it should expect remote
6434
     protocol packets on its standard input, and send replies on its
6435
     standard output.  You could use this to run a stand-alone simulator
6436
     that speaks the remote debugging protocol, to make net connections
6437
     using programs like `ssh', or for other similar tricks.
6438
 
6439
     If COMMAND closes its standard output (perhaps by exiting), GDB
6440
     will try to send it a `SIGTERM' signal.  (If the program has
6441
     already exited, this will have no effect.)
6442
 
6443
 
6444
   Once the connection has been established, you can use all the usual
6445
commands to examine and change data.  The remote program is already
6446
running; you can use `step' and `continue', and you do not need to use
6447
`run'.
6448
 
6449
   Whenever GDB is waiting for the remote program, if you type the
6450
interrupt character (often `Ctrl-c'), GDB attempts to stop the program.
6451
This may or may not succeed, depending in part on the hardware and the
6452
serial drivers the remote system uses.  If you type the interrupt
6453
character once again, GDB displays this prompt:
6454
 
6455
     Interrupted while waiting for the program.
6456
     Give up (and stop debugging it)?  (y or n)
6457
 
6458
   If you type `y', GDB abandons the remote debugging session.  (If you
6459
decide you want to try again later, you can use `target remote' again
6460
to connect once more.)  If you type `n', GDB goes back to waiting.
6461
 
6462
`detach'
6463
     When you have finished debugging the remote program, you can use
6464
     the `detach' command to release it from GDB control.  Detaching
6465
     from the target normally resumes its execution, but the results
6466
     will depend on your particular remote stub.  After the `detach'
6467
     command, GDB is free to connect to another target.
6468
 
6469
`disconnect'
6470
     The `disconnect' command behaves like `detach', except that the
6471
     target is generally not resumed.  It will wait for GDB (this
6472
     instance or another one) to connect and continue debugging.  After
6473
     the `disconnect' command, GDB is again free to connect to another
6474
     target.
6475
 
6476
`monitor CMD'
6477
     This command allows you to send arbitrary commands directly to the
6478
     remote monitor.  Since GDB doesn't care about the commands it
6479
     sends like this, this command is the way to extend GDB--you can
6480
     add new commands that only the external monitor will understand
6481
     and implement.
6482
 
6483

6484
File: gdb.info,  Node: File Transfer,  Next: Server,  Prev: Connecting,  Up: Remote Debugging
6485
 
6486
20.2 Sending files to a remote system
6487
=====================================
6488
 
6489
Some remote targets offer the ability to transfer files over the same
6490
connection used to communicate with GDB.  This is convenient for
6491
targets accessible through other means, e.g. GNU/Linux systems running
6492
`gdbserver' over a network interface.  For other targets, e.g. embedded
6493
devices with only a single serial port, this may be the only way to
6494
upload or download files.
6495
 
6496
   Not all remote targets support these commands.
6497
 
6498
`remote put HOSTFILE TARGETFILE'
6499
     Copy file HOSTFILE from the host system (the machine running GDB)
6500
     to TARGETFILE on the target system.
6501
 
6502
`remote get TARGETFILE HOSTFILE'
6503
     Copy file TARGETFILE from the target system to HOSTFILE on the
6504
     host system.
6505
 
6506
`remote delete TARGETFILE'
6507
     Delete TARGETFILE from the target system.
6508
 
6509
 
6510

6511
File: gdb.info,  Node: Server,  Next: Remote Configuration,  Prev: File Transfer,  Up: Remote Debugging
6512
 
6513
20.3 Using the `gdbserver' Program
6514
==================================
6515
 
6516
`gdbserver' is a control program for Unix-like systems, which allows
6517
you to connect your program with a remote GDB via `target remote'--but
6518
without linking in the usual debugging stub.
6519
 
6520
   `gdbserver' is not a complete replacement for the debugging stubs,
6521
because it requires essentially the same operating-system facilities
6522
that GDB itself does.  In fact, a system that can run `gdbserver' to
6523
connect to a remote GDB could also run GDB locally!  `gdbserver' is
6524
sometimes useful nevertheless, because it is a much smaller program
6525
than GDB itself.  It is also easier to port than all of GDB, so you may
6526
be able to get started more quickly on a new system by using
6527
`gdbserver'.  Finally, if you develop code for real-time systems, you
6528
may find that the tradeoffs involved in real-time operation make it
6529
more convenient to do as much development work as possible on another
6530
system, for example by cross-compiling.  You can use `gdbserver' to
6531
make a similar choice for debugging.
6532
 
6533
   GDB and `gdbserver' communicate via either a serial line or a TCP
6534
connection, using the standard GDB remote serial protocol.
6535
 
6536
     _Warning:_ `gdbserver' does not have any built-in security.  Do
6537
     not run `gdbserver' connected to any public network; a GDB
6538
     connection to `gdbserver' provides access to the target system
6539
     with the same privileges as the user running `gdbserver'.
6540
 
6541
20.3.1 Running `gdbserver'
6542
--------------------------
6543
 
6544
Run `gdbserver' on the target system.  You need a copy of the program
6545
you want to debug, including any libraries it requires.  `gdbserver'
6546
does not need your program's symbol table, so you can strip the program
6547
if necessary to save space.  GDB on the host system does all the symbol
6548
handling.
6549
 
6550
   To use the server, you must tell it how to communicate with GDB; the
6551
name of your program; and the arguments for your program.  The usual
6552
syntax is:
6553
 
6554
     target> gdbserver COMM PROGRAM [ ARGS ... ]
6555
 
6556
   COMM is either a device name (to use a serial line) or a TCP
6557
hostname and portnumber.  For example, to debug Emacs with the argument
6558
`foo.txt' and communicate with GDB over the serial port `/dev/com1':
6559
 
6560
     target> gdbserver /dev/com1 emacs foo.txt
6561
 
6562
   `gdbserver' waits passively for the host GDB to communicate with it.
6563
 
6564
   To use a TCP connection instead of a serial line:
6565
 
6566
     target> gdbserver host:2345 emacs foo.txt
6567
 
6568
   The only difference from the previous example is the first argument,
6569
specifying that you are communicating with the host GDB via TCP.  The
6570
`host:2345' argument means that `gdbserver' is to expect a TCP
6571
connection from machine `host' to local TCP port 2345.  (Currently, the
6572
`host' part is ignored.)  You can choose any number you want for the
6573
port number as long as it does not conflict with any TCP ports already
6574
in use on the target system (for example, `23' is reserved for
6575
`telnet').(1)  You must use the same port number with the host GDB
6576
`target remote' command.
6577
 
6578
20.3.1.1 Attaching to a Running Program
6579
.......................................
6580
 
6581
On some targets, `gdbserver' can also attach to running programs.  This
6582
is accomplished via the `--attach' argument.  The syntax is:
6583
 
6584
     target> gdbserver --attach COMM PID
6585
 
6586
   PID is the process ID of a currently running process.  It isn't
6587
necessary to point `gdbserver' at a binary for the running process.
6588
 
6589
   You can debug processes by name instead of process ID if your target
6590
has the `pidof' utility:
6591
 
6592
     target> gdbserver --attach COMM `pidof PROGRAM`
6593
 
6594
   In case more than one copy of PROGRAM is running, or PROGRAM has
6595
multiple threads, most versions of `pidof' support the `-s' option to
6596
only return the first process ID.
6597
 
6598
20.3.1.2 Multi-Process Mode for `gdbserver'
6599
...........................................
6600
 
6601
When you connect to `gdbserver' using `target remote', `gdbserver'
6602
debugs the specified program only once.  When the program exits, or you
6603
detach from it, GDB closes the connection and `gdbserver' exits.
6604
 
6605
   If you connect using `target extended-remote', `gdbserver' enters
6606
multi-process mode.  When the debugged program exits, or you detach
6607
from it, GDB stays connected to `gdbserver' even though no program is
6608
running.  The `run' and `attach' commands instruct `gdbserver' to run
6609
or attach to a new program.  The `run' command uses `set remote
6610
exec-file' (*note set remote exec-file::) to select the program to run.
6611
Command line arguments are supported, except for wildcard expansion
6612
and I/O redirection (*note Arguments::).
6613
 
6614
   To start `gdbserver' without supplying an initial command to run or
6615
process ID to attach, use the `--multi' command line option.  Then you
6616
can connect using `target extended-remote' and start the program you
6617
want to debug.
6618
 
6619
   `gdbserver' does not automatically exit in multi-process mode.  You
6620
can terminate it by using `monitor exit' (*note Monitor Commands for
6621
gdbserver::).
6622
 
6623
20.3.1.3 Other Command-Line Arguments for `gdbserver'
6624
.....................................................
6625
 
6626
The `--debug' option tells `gdbserver' to display extra status
6627
information about the debugging process.  The `--remote-debug' option
6628
tells `gdbserver' to display remote protocol debug output.  These
6629
options are intended for `gdbserver' development and for bug reports to
6630
the developers.
6631
 
6632
   The `--wrapper' option specifies a wrapper to launch programs for
6633
debugging.  The option should be followed by the name of the wrapper,
6634
then any command-line arguments to pass to the wrapper, then `--'
6635
indicating the end of the wrapper arguments.
6636
 
6637
   `gdbserver' runs the specified wrapper program with a combined
6638
command line including the wrapper arguments, then the name of the
6639
program to debug, then any arguments to the program.  The wrapper runs
6640
until it executes your program, and then GDB gains control.
6641
 
6642
   You can use any program that eventually calls `execve' with its
6643
arguments as a wrapper.  Several standard Unix utilities do this, e.g.
6644
`env' and `nohup'.  Any Unix shell script ending with `exec "$@"' will
6645
also work.
6646
 
6647
   For example, you can use `env' to pass an environment variable to
6648
the debugged program, without setting the variable in `gdbserver''s
6649
environment:
6650
 
6651
     $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
6652
 
6653
20.3.2 Connecting to `gdbserver'
6654
--------------------------------
6655
 
6656
Run GDB on the host system.
6657
 
6658
   First make sure you have the necessary symbol files.  Load symbols
6659
for your application using the `file' command before you connect.  Use
6660
`set sysroot' to locate target libraries (unless your GDB was compiled
6661
with the correct sysroot using `--with-sysroot').
6662
 
6663
   The symbol file and target libraries must exactly match the
6664
executable and libraries on the target, with one exception: the files
6665
on the host system should not be stripped, even if the files on the
6666
target system are.  Mismatched or missing files will lead to confusing
6667
results during debugging.  On GNU/Linux targets, mismatched or missing
6668
files may also prevent `gdbserver' from debugging multi-threaded
6669
programs.
6670
 
6671
   Connect to your target (*note Connecting to a Remote Target:
6672
Connecting.).  For TCP connections, you must start up `gdbserver' prior
6673
to using the `target remote' command.  Otherwise you may get an error
6674
whose text depends on the host system, but which usually looks
6675
something like `Connection refused'.  Don't use the `load' command in
6676
GDB when using `gdbserver', since the program is already on the target.
6677
 
6678
20.3.3 Monitor Commands for `gdbserver'
6679
---------------------------------------
6680
 
6681
During a GDB session using `gdbserver', you can use the `monitor'
6682
command to send special requests to `gdbserver'.  Here are the
6683
available commands.
6684
 
6685
`monitor help'
6686
     List the available monitor commands.
6687
 
6688
`monitor set debug 0'
6689
`monitor set debug 1'
6690
     Disable or enable general debugging messages.
6691
 
6692
`monitor set remote-debug 0'
6693
`monitor set remote-debug 1'
6694
     Disable or enable specific debugging messages associated with the
6695
     remote protocol (*note Remote Protocol::).
6696
 
6697
`monitor set libthread-db-search-path [PATH]'
6698
     When this command is issued, PATH is a colon-separated list of
6699
     directories to search for `libthread_db' (*note set
6700
     libthread-db-search-path: Threads.).  If you omit PATH,
6701
     `libthread-db-search-path' will be reset to an empty list.
6702
 
6703
`monitor exit'
6704
     Tell gdbserver to exit immediately.  This command should be
6705
     followed by `disconnect' to close the debugging session.
6706
     `gdbserver' will detach from any attached processes and kill any
6707
     processes it created.  Use `monitor exit' to terminate `gdbserver'
6708
     at the end of a multi-process mode debug session.
6709
 
6710
 
6711
20.3.4 Tracepoints support in `gdbserver'
6712
-----------------------------------------
6713
 
6714
On some targets, `gdbserver' supports tracepoints, fast tracepoints and
6715
static tracepoints.
6716
 
6717
   For fast or static tracepoints to work, a special library called the
6718
"in-process agent" (IPA), must be loaded in the inferior process.  This
6719
library is built and distributed as an integral part of `gdbserver'.
6720
In addition, support for static tracepoints requires building the
6721
in-process agent library with static tracepoints support.  At present,
6722
the UST (LTTng Userspace Tracer, `http://lttng.org/ust') tracing engine
6723
is supported.  This support is automatically available if UST
6724
development headers are found in the standard include path when
6725
`gdbserver' is built, or if `gdbserver' was explicitly configured using
6726
`--with-ust' to point at such headers.  You can explicitly disable the
6727
support using `--with-ust=no'.
6728
 
6729
   There are several ways to load the in-process agent in your program:
6730
 
6731
`Specifying it as dependency at link time'
6732
     You can link your program dynamically with the in-process agent
6733
     library.  On most systems, this is accomplished by adding
6734
     `-linproctrace' to the link command.
6735
 
6736
`Using the system's preloading mechanisms'
6737
     You can force loading the in-process agent at startup time by using
6738
     your system's support for preloading shared libraries.  Many Unixes
6739
     support the concept of preloading user defined libraries.  In most
6740
     cases, you do that by specifying `LD_PRELOAD=libinproctrace.so' in
6741
     the environment.  See also the description of `gdbserver''s
6742
     `--wrapper' command line option.
6743
 
6744
`Using GDB to force loading the agent at run time'
6745
     On some systems, you can force the inferior to load a shared
6746
     library, by calling a dynamic loader function in the inferior that
6747
     takes care of dynamically looking up and loading a shared library.
6748
     On most Unix systems, the function is `dlopen'.  You'll use the
6749
     `call' command for that.  For example:
6750
 
6751
          (gdb) call dlopen ("libinproctrace.so", ...)
6752
 
6753
     Note that on most Unix systems, for the `dlopen' function to be
6754
     available, the program needs to be linked with `-ldl'.
6755
 
6756
   On systems that have a userspace dynamic loader, like most Unix
6757
systems, when you connect to `gdbserver' using `target remote', you'll
6758
find that the program is stopped at the dynamic loader's entry point,
6759
and no shared library has been loaded in the program's address space
6760
yet, including the in-process agent.  In that case, before being able
6761
to use any of the fast or static tracepoints features, you need to let
6762
the loader run and load the shared libraries.  The simplest way to do
6763
that is to run the program to the main procedure.  E.g., if debugging a
6764
C or C++ program, start `gdbserver' like so:
6765
 
6766
     $ gdbserver :9999 myprogram
6767
 
6768
   Start GDB and connect to `gdbserver' like so, and run to main:
6769
 
6770
     $ gdb myprogram
6771
     (gdb) target remote myhost:9999
6772
     0x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
6773
     (gdb) b main
6774
     (gdb) continue
6775
 
6776
   The in-process tracing agent library should now be loaded into the
6777
process; you can confirm it with the `info sharedlibrary' command,
6778
which will list `libinproctrace.so' as loaded in the process.  You are
6779
now ready to install fast tracepoints, list static tracepoint markers,
6780
probe static tracepoints markers, and start tracing.
6781
 
6782
   ---------- Footnotes ----------
6783
 
6784
   (1) If you choose a port number that conflicts with another service,
6785
`gdbserver' prints an error message and exits.
6786
 
6787

6788
File: gdb.info,  Node: Remote Configuration,  Next: Remote Stub,  Prev: Server,  Up: Remote Debugging
6789
 
6790
20.4 Remote Configuration
6791
=========================
6792
 
6793
This section documents the configuration options available when
6794
debugging remote programs.  For the options related to the File I/O
6795
extensions of the remote protocol, see *Note system-call-allowed:
6796
system.
6797
 
6798
`set remoteaddresssize BITS'
6799
     Set the maximum size of address in a memory packet to the specified
6800
     number of bits.  GDB will mask off the address bits above that
6801
     number, when it passes addresses to the remote target.  The
6802
     default value is the number of bits in the target's address.
6803
 
6804
`show remoteaddresssize'
6805
     Show the current value of remote address size in bits.
6806
 
6807
`set remotebaud N'
6808
     Set the baud rate for the remote serial I/O to N baud.  The value
6809
     is used to set the speed of the serial port used for debugging
6810
     remote targets.
6811
 
6812
`show remotebaud'
6813
     Show the current speed of the remote connection.
6814
 
6815
`set remotebreak'
6816
     If set to on, GDB sends a `BREAK' signal to the remote when you
6817
     type `Ctrl-c' to interrupt the program running on the remote.  If
6818
     set to off, GDB sends the `Ctrl-C' character instead.  The default
6819
     is off, since most remote systems expect to see `Ctrl-C' as the
6820
     interrupt signal.
6821
 
6822
`show remotebreak'
6823
     Show whether GDB sends `BREAK' or `Ctrl-C' to interrupt the remote
6824
     program.
6825
 
6826
`set remoteflow on'
6827
`set remoteflow off'
6828
     Enable or disable hardware flow control (`RTS'/`CTS') on the
6829
     serial port used to communicate to the remote target.
6830
 
6831
`show remoteflow'
6832
     Show the current setting of hardware flow control.
6833
 
6834
`set remotelogbase BASE'
6835
     Set the base (a.k.a. radix) of logging serial protocol
6836
     communications to BASE.  Supported values of BASE are: `ascii',
6837
     `octal', and `hex'.  The default is `ascii'.
6838
 
6839
`show remotelogbase'
6840
     Show the current setting of the radix for logging remote serial
6841
     protocol.
6842
 
6843
`set remotelogfile FILE'
6844
     Record remote serial communications on the named FILE.  The
6845
     default is not to record at all.
6846
 
6847
`show remotelogfile.'
6848
     Show the current setting  of the file name on which to record the
6849
     serial communications.
6850
 
6851
`set remotetimeout NUM'
6852
     Set the timeout limit to wait for the remote target to respond to
6853
     NUM seconds.  The default is 2 seconds.
6854
 
6855
`show remotetimeout'
6856
     Show the current number of seconds to wait for the remote target
6857
     responses.
6858
 
6859
`set remote hardware-watchpoint-limit LIMIT'
6860
`set remote hardware-breakpoint-limit LIMIT'
6861
     Restrict GDB to using LIMIT remote hardware breakpoint or
6862
     watchpoints.  A limit of -1, the default, is treated as unlimited.
6863
 
6864
`set remote exec-file FILENAME'
6865
`show remote exec-file'
6866
     Select the file used for `run' with `target extended-remote'.
6867
     This should be set to a filename valid on the target system.  If
6868
     it is not set, the target will use a default filename (e.g. the
6869
     last program run).
6870
 
6871
`set remote interrupt-sequence'
6872
     Allow the user to select one of `Ctrl-C', a `BREAK' or `BREAK-g'
6873
     as the sequence to the remote target in order to interrupt the
6874
     execution.  `Ctrl-C' is a default.  Some system prefers `BREAK'
6875
     which is high level of serial line for some certain time.  Linux
6876
     kernel prefers `BREAK-g', a.k.a Magic SysRq g.  It is `BREAK'
6877
     signal followed by character `g'.
6878
 
6879
`show interrupt-sequence'
6880
     Show which of `Ctrl-C', `BREAK' or `BREAK-g' is sent by GDB to
6881
     interrupt the remote program.  `BREAK-g' is BREAK signal followed
6882
     by `g' and also known as Magic SysRq g.
6883
 
6884
`set remote interrupt-on-connect'
6885
     Specify whether interrupt-sequence is sent to remote target when
6886
     GDB connects to it.  This is mostly needed when you debug Linux
6887
     kernel.  Linux kernel expects `BREAK' followed by `g' which is
6888
     known as Magic SysRq g in order to connect GDB.
6889
 
6890
`show interrupt-on-connect'
6891
     Show whether interrupt-sequence is sent to remote target when GDB
6892
     connects to it.
6893
 
6894
`set tcp auto-retry on'
6895
     Enable auto-retry for remote TCP connections.  This is useful if
6896
     the remote debugging agent is launched in parallel with GDB; there
6897
     is a race condition because the agent may not become ready to
6898
     accept the connection before GDB attempts to connect.  When
6899
     auto-retry is enabled, if the initial attempt to connect fails,
6900
     GDB reattempts to establish the connection using the timeout
6901
     specified by `set tcp connect-timeout'.
6902
 
6903
`set tcp auto-retry off'
6904
     Do not auto-retry failed TCP connections.
6905
 
6906
`show tcp auto-retry'
6907
     Show the current auto-retry setting.
6908
 
6909
`set tcp connect-timeout SECONDS'
6910
     Set the timeout for establishing a TCP connection to the remote
6911
     target to SECONDS.  The timeout affects both polling to retry
6912
     failed connections (enabled by `set tcp auto-retry on') and
6913
     waiting for connections that are merely slow to complete, and
6914
     represents an approximate cumulative value.
6915
 
6916
`show tcp connect-timeout'
6917
     Show the current connection timeout setting.
6918
 
6919
   The GDB remote protocol autodetects the packets supported by your
6920
debugging stub.  If you need to override the autodetection, you can use
6921
these commands to enable or disable individual packets.  Each packet
6922
can be set to `on' (the remote target supports this packet), `off' (the
6923
remote target does not support this packet), or `auto' (detect remote
6924
target support for this packet).  They all default to `auto'.  For more
6925
information about each packet, see *Note Remote Protocol::.
6926
 
6927
   During normal use, you should not have to use any of these commands.
6928
If you do, that may be a bug in your remote debugging stub, or a bug in
6929
GDB.  You may want to report the problem to the GDB developers.
6930
 
6931
   For each packet NAME, the command to enable or disable the packet is
6932
`set remote NAME-packet'.  The available settings are:
6933
 
6934
Command Name         Remote Packet           Related Features
6935
`fetch-register'     `p'                     `info registers'
6936
`set-register'       `P'                     `set'
6937
`binary-download'    `X'                     `load', `set'
6938
`read-aux-vector'    `qXfer:auxv:read'       `info auxv'
6939
`symbol-lookup'      `qSymbol'               Detecting
6940
                                             multiple threads
6941
`attach'             `vAttach'               `attach'
6942
`verbose-resume'     `vCont'                 Stepping or
6943
                                             resuming multiple
6944
                                             threads
6945
`run'                `vRun'                  `run'
6946
`software-breakpoint'`Z0'                    `break'
6947
`hardware-breakpoint'`Z1'                    `hbreak'
6948
`write-watchpoint'   `Z2'                    `watch'
6949
`read-watchpoint'    `Z3'                    `rwatch'
6950
`access-watchpoint'  `Z4'                    `awatch'
6951
`target-features'    `qXfer:features:read'   `set architecture'
6952
`library-info'       `qXfer:libraries:read'  `info
6953
                                             sharedlibrary'
6954
`memory-map'         `qXfer:memory-map:read' `info mem'
6955
`read-sdata-object'  `qXfer:sdata:read'      `print $_sdata'
6956
`read-spu-object'    `qXfer:spu:read'        `info spu'
6957
`write-spu-object'   `qXfer:spu:write'       `info spu'
6958
`read-siginfo-object'`qXfer:siginfo:read'    `print $_siginfo'
6959
`write-siginfo-object'`qXfer:siginfo:write'   `set $_siginfo'
6960
`threads'            `qXfer:threads:read'    `info threads'
6961
`get-thread-local-   `qGetTLSAddr'           Displaying
6962
storage-address'                             `__thread'
6963
                                             variables
6964
`get-thread-information-block-address'`qGetTIBAddr'           Display
6965
                                             MS-Windows Thread
6966
                                             Information Block.
6967
`search-memory'      `qSearch:memory'        `find'
6968
`supported-packets'  `qSupported'            Remote
6969
                                             communications
6970
                                             parameters
6971
`pass-signals'       `QPassSignals'          `handle SIGNAL'
6972
`hostio-close-packet'`vFile:close'           `remote get',
6973
                                             `remote put'
6974
`hostio-open-packet' `vFile:open'            `remote get',
6975
                                             `remote put'
6976
`hostio-pread-packet'`vFile:pread'           `remote get',
6977
                                             `remote put'
6978
`hostio-pwrite-packet'`vFile:pwrite'          `remote get',
6979
                                             `remote put'
6980
`hostio-unlink-packet'`vFile:unlink'          `remote delete'
6981
`noack-packet'       `QStartNoAckMode'       Packet
6982
                                             acknowledgment
6983
`osdata'             `qXfer:osdata:read'     `info os'
6984
`query-attached'     `qAttached'             Querying remote
6985
                                             process attach
6986
                                             state.
6987
 
6988

6989
File: gdb.info,  Node: Remote Stub,  Prev: Remote Configuration,  Up: Remote Debugging
6990
 
6991
20.5 Implementing a Remote Stub
6992
===============================
6993
 
6994
The stub files provided with GDB implement the target side of the
6995
communication protocol, and the GDB side is implemented in the GDB
6996
source file `remote.c'.  Normally, you can simply allow these
6997
subroutines to communicate, and ignore the details.  (If you're
6998
implementing your own stub file, you can still ignore the details: start
6999
with one of the existing stub files.  `sparc-stub.c' is the best
7000
organized, and therefore the easiest to read.)
7001
 
7002
   To debug a program running on another machine (the debugging
7003
"target" machine), you must first arrange for all the usual
7004
prerequisites for the program to run by itself.  For example, for a C
7005
program, you need:
7006
 
7007
  1. A startup routine to set up the C runtime environment; these
7008
     usually have a name like `crt0'.  The startup routine may be
7009
     supplied by your hardware supplier, or you may have to write your
7010
     own.
7011
 
7012
  2. A C subroutine library to support your program's subroutine calls,
7013
     notably managing input and output.
7014
 
7015
  3. A way of getting your program to the other machine--for example, a
7016
     download program.  These are often supplied by the hardware
7017
     manufacturer, but you may have to write your own from hardware
7018
     documentation.
7019
 
7020
   The next step is to arrange for your program to use a serial port to
7021
communicate with the machine where GDB is running (the "host" machine).
7022
In general terms, the scheme looks like this:
7023
 
7024
_On the host,_
7025
     GDB already understands how to use this protocol; when everything
7026
     else is set up, you can simply use the `target remote' command
7027
     (*note Specifying a Debugging Target: Targets.).
7028
 
7029
_On the target,_
7030
     you must link with your program a few special-purpose subroutines
7031
     that implement the GDB remote serial protocol.  The file
7032
     containing these subroutines is called  a "debugging stub".
7033
 
7034
     On certain remote targets, you can use an auxiliary program
7035
     `gdbserver' instead of linking a stub into your program.  *Note
7036
     Using the `gdbserver' Program: Server, for details.
7037
 
7038
   The debugging stub is specific to the architecture of the remote
7039
machine; for example, use `sparc-stub.c' to debug programs on SPARC
7040
boards.
7041
 
7042
   These working remote stubs are distributed with GDB:
7043
 
7044
`i386-stub.c'
7045
     For Intel 386 and compatible architectures.
7046
 
7047
`m68k-stub.c'
7048
     For Motorola 680x0 architectures.
7049
 
7050
`sh-stub.c'
7051
     For Renesas SH architectures.
7052
 
7053
`sparc-stub.c'
7054
     For SPARC architectures.
7055
 
7056
`sparcl-stub.c'
7057
     For Fujitsu SPARCLITE architectures.
7058
 
7059
 
7060
   The `README' file in the GDB distribution may list other recently
7061
added stubs.
7062
 
7063
* Menu:
7064
 
7065
* Stub Contents::       What the stub can do for you
7066
* Bootstrapping::       What you must do for the stub
7067
* Debug Session::       Putting it all together
7068
 
7069

7070
File: gdb.info,  Node: Stub Contents,  Next: Bootstrapping,  Up: Remote Stub
7071
 
7072
20.5.1 What the Stub Can Do for You
7073
-----------------------------------
7074
 
7075
The debugging stub for your architecture supplies these three
7076
subroutines:
7077
 
7078
`set_debug_traps'
7079
     This routine arranges for `handle_exception' to run when your
7080
     program stops.  You must call this subroutine explicitly near the
7081
     beginning of your program.
7082
 
7083
`handle_exception'
7084
     This is the central workhorse, but your program never calls it
7085
     explicitly--the setup code arranges for `handle_exception' to run
7086
     when a trap is triggered.
7087
 
7088
     `handle_exception' takes control when your program stops during
7089
     execution (for example, on a breakpoint), and mediates
7090
     communications with GDB on the host machine.  This is where the
7091
     communications protocol is implemented; `handle_exception' acts as
7092
     the GDB representative on the target machine.  It begins by
7093
     sending summary information on the state of your program, then
7094
     continues to execute, retrieving and transmitting any information
7095
     GDB needs, until you execute a GDB command that makes your program
7096
     resume; at that point, `handle_exception' returns control to your
7097
     own code on the target machine.
7098
 
7099
`breakpoint'
7100
     Use this auxiliary subroutine to make your program contain a
7101
     breakpoint.  Depending on the particular situation, this may be
7102
     the only way for GDB to get control.  For instance, if your target
7103
     machine has some sort of interrupt button, you won't need to call
7104
     this; pressing the interrupt button transfers control to
7105
     `handle_exception'--in effect, to GDB.  On some machines, simply
7106
     receiving characters on the serial port may also trigger a trap;
7107
     again, in that situation, you don't need to call `breakpoint' from
7108
     your own program--simply running `target remote' from the host GDB
7109
     session gets control.
7110
 
7111
     Call `breakpoint' if none of these is true, or if you simply want
7112
     to make certain your program stops at a predetermined point for the
7113
     start of your debugging session.
7114
 
7115

7116
File: gdb.info,  Node: Bootstrapping,  Next: Debug Session,  Prev: Stub Contents,  Up: Remote Stub
7117
 
7118
20.5.2 What You Must Do for the Stub
7119
------------------------------------
7120
 
7121
The debugging stubs that come with GDB are set up for a particular chip
7122
architecture, but they have no information about the rest of your
7123
debugging target machine.
7124
 
7125
   First of all you need to tell the stub how to communicate with the
7126
serial port.
7127
 
7128
`int getDebugChar()'
7129
     Write this subroutine to read a single character from the serial
7130
     port.  It may be identical to `getchar' for your target system; a
7131
     different name is used to allow you to distinguish the two if you
7132
     wish.
7133
 
7134
`void putDebugChar(int)'
7135
     Write this subroutine to write a single character to the serial
7136
     port.  It may be identical to `putchar' for your target system; a
7137
     different name is used to allow you to distinguish the two if you
7138
     wish.
7139
 
7140
   If you want GDB to be able to stop your program while it is running,
7141
you need to use an interrupt-driven serial driver, and arrange for it
7142
to stop when it receives a `^C' (`\003', the control-C character).
7143
That is the character which GDB uses to tell the remote system to stop.
7144
 
7145
   Getting the debugging target to return the proper status to GDB
7146
probably requires changes to the standard stub; one quick and dirty way
7147
is to just execute a breakpoint instruction (the "dirty" part is that
7148
GDB reports a `SIGTRAP' instead of a `SIGINT').
7149
 
7150
   Other routines you need to supply are:
7151
 
7152
`void exceptionHandler (int EXCEPTION_NUMBER, void *EXCEPTION_ADDRESS)'
7153
     Write this function to install EXCEPTION_ADDRESS in the exception
7154
     handling tables.  You need to do this because the stub does not
7155
     have any way of knowing what the exception handling tables on your
7156
     target system are like (for example, the processor's table might
7157
     be in ROM, containing entries which point to a table in RAM).
7158
     EXCEPTION_NUMBER is the exception number which should be changed;
7159
     its meaning is architecture-dependent (for example, different
7160
     numbers might represent divide by zero, misaligned access, etc).
7161
     When this exception occurs, control should be transferred directly
7162
     to EXCEPTION_ADDRESS, and the processor state (stack, registers,
7163
     and so on) should be just as it is when a processor exception
7164
     occurs.  So if you want to use a jump instruction to reach
7165
     EXCEPTION_ADDRESS, it should be a simple jump, not a jump to
7166
     subroutine.
7167
 
7168
     For the 386, EXCEPTION_ADDRESS should be installed as an interrupt
7169
     gate so that interrupts are masked while the handler runs.  The
7170
     gate should be at privilege level 0 (the most privileged level).
7171
     The SPARC and 68k stubs are able to mask interrupts themselves
7172
     without help from `exceptionHandler'.
7173
 
7174
`void flush_i_cache()'
7175
     On SPARC and SPARCLITE only, write this subroutine to flush the
7176
     instruction cache, if any, on your target machine.  If there is no
7177
     instruction cache, this subroutine may be a no-op.
7178
 
7179
     On target machines that have instruction caches, GDB requires this
7180
     function to make certain that the state of your program is stable.
7181
 
7182
You must also make sure this library routine is available:
7183
 
7184
`void *memset(void *, int, int)'
7185
     This is the standard library function `memset' that sets an area of
7186
     memory to a known value.  If you have one of the free versions of
7187
     `libc.a', `memset' can be found there; otherwise, you must either
7188
     obtain it from your hardware manufacturer, or write your own.
7189
 
7190
   If you do not use the GNU C compiler, you may need other standard
7191
library subroutines as well; this varies from one stub to another, but
7192
in general the stubs are likely to use any of the common library
7193
subroutines which `GCC' generates as inline code.
7194
 
7195

7196
File: gdb.info,  Node: Debug Session,  Prev: Bootstrapping,  Up: Remote Stub
7197
 
7198
20.5.3 Putting it All Together
7199
------------------------------
7200
 
7201
In summary, when your program is ready to debug, you must follow these
7202
steps.
7203
 
7204
  1. Make sure you have defined the supporting low-level routines
7205
     (*note What You Must Do for the Stub: Bootstrapping.):
7206
          `getDebugChar', `putDebugChar',
7207
          `flush_i_cache', `memset', `exceptionHandler'.
7208
 
7209
  2. Insert these lines near the top of your program:
7210
 
7211
          set_debug_traps();
7212
          breakpoint();
7213
 
7214
  3. For the 680x0 stub only, you need to provide a variable called
7215
     `exceptionHook'.  Normally you just use:
7216
 
7217
          void (*exceptionHook)() = 0;
7218
 
7219
     but if before calling `set_debug_traps', you set it to point to a
7220
     function in your program, that function is called when `GDB'
7221
     continues after stopping on a trap (for example, bus error).  The
7222
     function indicated by `exceptionHook' is called with one
7223
     parameter: an `int' which is the exception number.
7224
 
7225
  4. Compile and link together: your program, the GDB debugging stub for
7226
     your target architecture, and the supporting subroutines.
7227
 
7228
  5. Make sure you have a serial connection between your target machine
7229
     and the GDB host, and identify the serial port on the host.
7230
 
7231
  6. Download your program to your target machine (or get it there by
7232
     whatever means the manufacturer provides), and start it.
7233
 
7234
  7. Start GDB on the host, and connect to the target (*note Connecting
7235
     to a Remote Target: Connecting.).
7236
 
7237
 
7238

7239
File: gdb.info,  Node: Configurations,  Next: Controlling GDB,  Prev: Remote Debugging,  Up: Top
7240
 
7241
21 Configuration-Specific Information
7242
*************************************
7243
 
7244
While nearly all GDB commands are available for all native and cross
7245
versions of the debugger, there are some exceptions.  This chapter
7246
describes things that are only available in certain configurations.
7247
 
7248
   There are three major categories of configurations: native
7249
configurations, where the host and target are the same, embedded
7250
operating system configurations, which are usually the same for several
7251
different processor architectures, and bare embedded processors, which
7252
are quite different from each other.
7253
 
7254
* Menu:
7255
 
7256
* Native::
7257
* Embedded OS::
7258
* Embedded Processors::
7259
* Architectures::
7260
 
7261

7262
File: gdb.info,  Node: Native,  Next: Embedded OS,  Up: Configurations
7263
 
7264
21.1 Native
7265
===========
7266
 
7267
This section describes details specific to particular native
7268
configurations.
7269
 
7270
* Menu:
7271
 
7272
* HP-UX::                       HP-UX
7273
* BSD libkvm Interface::        Debugging BSD kernel memory images
7274
* SVR4 Process Information::    SVR4 process information
7275
* DJGPP Native::                Features specific to the DJGPP port
7276
* Cygwin Native::               Features specific to the Cygwin port
7277
* Hurd Native::                 Features specific to GNU Hurd
7278
* Neutrino::                    Features specific to QNX Neutrino
7279
* Darwin::                      Features specific to Darwin
7280
 
7281

7282
File: gdb.info,  Node: HP-UX,  Next: BSD libkvm Interface,  Up: Native
7283
 
7284
21.1.1 HP-UX
7285
------------
7286
 
7287
On HP-UX systems, if you refer to a function or variable name that
7288
begins with a dollar sign, GDB searches for a user or system name
7289
first, before it searches for a convenience variable.
7290
 
7291

7292
File: gdb.info,  Node: BSD libkvm Interface,  Next: SVR4 Process Information,  Prev: HP-UX,  Up: Native
7293
 
7294
21.1.2 BSD libkvm Interface
7295
---------------------------
7296
 
7297
BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
7298
interface that provides a uniform interface for accessing kernel virtual
7299
memory images, including live systems and crash dumps.  GDB uses this
7300
interface to allow you to debug live kernels and kernel crash dumps on
7301
many native BSD configurations.  This is implemented as a special `kvm'
7302
debugging target.  For debugging a live system, load the currently
7303
running kernel into GDB and connect to the `kvm' target:
7304
 
7305
     (gdb) target kvm
7306
 
7307
   For debugging crash dumps, provide the file name of the crash dump
7308
as an argument:
7309
 
7310
     (gdb) target kvm /var/crash/bsd.0
7311
 
7312
   Once connected to the `kvm' target, the following commands are
7313
available:
7314
 
7315
`kvm pcb'
7316
     Set current context from the "Process Control Block" (PCB) address.
7317
 
7318
`kvm proc'
7319
     Set current context from proc address.  This command isn't
7320
     available on modern FreeBSD systems.
7321
 
7322

7323
File: gdb.info,  Node: SVR4 Process Information,  Next: DJGPP Native,  Prev: BSD libkvm Interface,  Up: Native
7324
 
7325
21.1.3 SVR4 Process Information
7326
-------------------------------
7327
 
7328
Many versions of SVR4 and compatible systems provide a facility called
7329
`/proc' that can be used to examine the image of a running process
7330
using file-system subroutines.  If GDB is configured for an operating
7331
system with this facility, the command `info proc' is available to
7332
report information about the process running your program, or about any
7333
process running on your system.  `info proc' works only on SVR4 systems
7334
that include the `procfs' code.  This includes, as of this writing,
7335
GNU/Linux, OSF/1 (Digital Unix), Solaris, Irix, and Unixware, but not
7336
HP-UX, for example.
7337
 
7338
`info proc'
7339
`info proc PROCESS-ID'
7340
     Summarize available information about any running process.  If a
7341
     process ID is specified by PROCESS-ID, display information about
7342
     that process; otherwise display information about the program being
7343
     debugged.  The summary includes the debugged process ID, the
7344
     command line used to invoke it, its current working directory, and
7345
     its executable file's absolute file name.
7346
 
7347
     On some systems, PROCESS-ID can be of the form `[PID]/TID' which
7348
     specifies a certain thread ID within a process.  If the optional
7349
     PID part is missing, it means a thread from the process being
7350
     debugged (the leading `/' still needs to be present, or else GDB
7351
     will interpret the number as a process ID rather than a thread ID).
7352
 
7353
`info proc mappings'
7354
     Report the memory address space ranges accessible in the program,
7355
     with information on whether the process has read, write, or
7356
     execute access rights to each range.  On GNU/Linux systems, each
7357
     memory range includes the object file which is mapped to that
7358
     range, instead of the memory access rights to that range.
7359
 
7360
`info proc stat'
7361
`info proc status'
7362
     These subcommands are specific to GNU/Linux systems.  They show
7363
     the process-related information, including the user ID and group
7364
     ID; how many threads are there in the process; its virtual memory
7365
     usage; the signals that are pending, blocked, and ignored; its
7366
     TTY; its consumption of system and user time; its stack size; its
7367
     `nice' value; etc.  For more information, see the `proc' man page
7368
     (type `man 5 proc' from your shell prompt).
7369
 
7370
`info proc all'
7371
     Show all the information about the process described under all of
7372
     the above `info proc' subcommands.
7373
 
7374
`set procfs-trace'
7375
     This command enables and disables tracing of `procfs' API calls.
7376
 
7377
`show procfs-trace'
7378
     Show the current state of `procfs' API call tracing.
7379
 
7380
`set procfs-file FILE'
7381
     Tell GDB to write `procfs' API trace to the named FILE.  GDB
7382
     appends the trace info to the previous contents of the file.  The
7383
     default is to display the trace on the standard output.
7384
 
7385
`show procfs-file'
7386
     Show the file to which `procfs' API trace is written.
7387
 
7388
`proc-trace-entry'
7389
`proc-trace-exit'
7390
`proc-untrace-entry'
7391
`proc-untrace-exit'
7392
     These commands enable and disable tracing of entries into and exits
7393
     from the `syscall' interface.
7394
 
7395
`info pidlist'
7396
     For QNX Neutrino only, this command displays the list of all the
7397
     processes and all the threads within each process.
7398
 
7399
`info meminfo'
7400
     For QNX Neutrino only, this command displays the list of all
7401
     mapinfos.
7402
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.