forked from msysgit/msysgit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgdb.info-1
7347 lines (5749 loc) · 292 KB
/
gdb.info-1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
This is gdb.info, produced by makeinfo version 4.8 from
../.././gdb/doc/gdb.texinfo.
INFO-DIR-SECTION Software development
START-INFO-DIR-ENTRY
* Gdb: (gdb). The GNU debugger.
END-INFO-DIR-ENTRY
This file documents the GNU debugger GDB.
This is the Ninth Edition, of `Debugging with GDB: the GNU
Source-Level Debugger' for GDB Version 6.8.
Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
1998,
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Free Software" and "Free Software Needs Free
Documentation", with the Front-Cover Texts being "A GNU Manual," and
with the Back-Cover Texts as in (a) below.
(a) The FSF's Back-Cover Text is: "You are free to copy and modify
this GNU Manual. Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom."
File: gdb.info, Node: Top, Next: Summary, Prev: (dir), Up: (dir)
Debugging with GDB
******************
This file describes GDB, the GNU symbolic debugger.
This is the Ninth Edition, for GDB Version 6.8.
Copyright (C) 1988-2006 Free Software Foundation, Inc.
This edition of the GDB manual is dedicated to the memory of Fred
Fish. Fred was a long-standing contributor to GDB and to Free software
in general. We will miss him.
* Menu:
* Summary:: Summary of GDB
* Sample Session:: A sample GDB session
* Invocation:: Getting in and out of GDB
* Commands:: GDB commands
* Running:: Running programs under GDB
* Stopping:: Stopping and continuing
* Stack:: Examining the stack
* Source:: Examining source files
* Data:: Examining data
* Macros:: Preprocessor Macros
* Tracepoints:: Debugging remote targets non-intrusively
* Overlays:: Debugging programs that use overlays
* Languages:: Using GDB with different languages
* Symbols:: Examining the symbol table
* Altering:: Altering execution
* GDB Files:: GDB files
* Targets:: Specifying a debugging target
* Remote Debugging:: Debugging remote programs
* Configurations:: Configuration-specific information
* Controlling GDB:: Controlling GDB
* Sequences:: Canned sequences of commands
* Interpreters:: Command Interpreters
* TUI:: GDB Text User Interface
* Emacs:: Using GDB under GNU Emacs
* GDB/MI:: GDB's Machine Interface.
* Annotations:: GDB's annotation interface.
* GDB Bugs:: Reporting bugs in GDB
* Command Line Editing:: Command Line Editing
* Using History Interactively:: Using History Interactively
* Formatting Documentation:: How to format and print GDB documentation
* Installing GDB:: Installing GDB
* Maintenance Commands:: Maintenance Commands
* Remote Protocol:: GDB Remote Serial Protocol
* Agent Expressions:: The GDB Agent Expression Mechanism
* Target Descriptions:: How targets can describe themselves to
GDB
* Copying:: GNU General Public License says
how you can copy and share GDB
* GNU Free Documentation License:: The license for this documentation
* Index:: Index
File: gdb.info, Node: Summary, Next: Sample Session, Prev: Top, Up: Top
Summary of GDB
**************
The purpose of a debugger such as GDB is to allow you to see what is
going on "inside" another program while it executes--or what another
program was doing at the moment it crashed.
GDB can do four main kinds of things (plus other things in support of
these) to help you catch bugs in the act:
* Start your program, specifying anything that might affect its
behavior.
* Make your program stop on specified conditions.
* Examine what has happened, when your program has stopped.
* Change things in your program, so you can experiment with
correcting the effects of one bug and go on to learn about another.
You can use GDB to debug programs written in C and C++. For more
information, see *Note Supported Languages: Supported Languages. For
more information, see *Note C and C++: C.
Support for Modula-2 is partial. For information on Modula-2, see
*Note Modula-2: Modula-2.
Debugging Pascal programs which use sets, subranges, file variables,
or nested functions does not currently work. GDB does not support
entering expressions, printing values, or similar features using Pascal
syntax.
GDB can be used to debug programs written in Fortran, although it
may be necessary to refer to some variables with a trailing underscore.
GDB can be used to debug programs written in Objective-C, using
either the Apple/NeXT or the GNU Objective-C runtime.
* Menu:
* Free Software:: Freely redistributable software
* Contributors:: Contributors to GDB
File: gdb.info, Node: Free Software, Next: Contributors, Up: Summary
Free Software
=============
GDB is "free software", protected by the GNU General Public License
(GPL). The GPL gives you the freedom to copy or adapt a licensed
program--but every person getting a copy also gets with it the freedom
to modify that copy (which means that they must get access to the
source code), and the freedom to distribute further copies. Typical
software companies use copyrights to limit your freedoms; the Free
Software Foundation uses the GPL to preserve these freedoms.
Fundamentally, the General Public License is a license which says
that you have these freedoms and that you cannot take these freedoms
away from anyone else.
Free Software Needs Free Documentation
======================================
The biggest deficiency in the free software community today is not in
the software--it is the lack of good free documentation that we can
include with the free software. Many of our most important programs do
not come with free reference manuals and free introductory texts.
Documentation is an essential part of any software package; when an
important free software package does not come with a free manual and a
free tutorial, that is a major gap. We have many such gaps today.
Consider Perl, for instance. The tutorial manuals that people
normally use are non-free. How did this come about? Because the
authors of those manuals published them with restrictive terms--no
copying, no modification, source files not available--which exclude
them from the free software world.
That wasn't the first time this sort of thing happened, and it was
far from the last. Many times we have heard a GNU user eagerly
describe a manual that he is writing, his intended contribution to the
community, only to learn that he had ruined everything by signing a
publication contract to make it non-free.
Free documentation, like free software, is a matter of freedom, not
price. The problem with the non-free manual is not that publishers
charge a price for printed copies--that in itself is fine. (The Free
Software Foundation sells printed copies of manuals, too.) The problem
is the restrictions on the use of the manual. Free manuals are
available in source code form, and give you permission to copy and
modify. Non-free manuals do not allow this.
The criteria of freedom for a free manual are roughly the same as for
free software. Redistribution (including the normal kinds of
commercial redistribution) must be permitted, so that the manual can
accompany every copy of the program, both on-line and on paper.
Permission for modification of the technical content is crucial too.
When people modify the software, adding or changing features, if they
are conscientious they will change the manual too--so they can provide
accurate and clear documentation for the modified program. A manual
that leaves you no choice but to write a new manual to document a
changed version of the program is not really available to our community.
Some kinds of limits on the way modification is handled are
acceptable. For example, requirements to preserve the original
author's copyright notice, the distribution terms, or the list of
authors, are ok. It is also no problem to require modified versions to
include notice that they were modified. Even entire sections that may
not be deleted or changed are acceptable, as long as they deal with
nontechnical topics (like this one). These kinds of restrictions are
acceptable because they don't obstruct the community's normal use of
the manual.
However, it must be possible to modify all the _technical_ content
of the manual, and then distribute the result in all the usual media,
through all the usual channels. Otherwise, the restrictions obstruct
the use of the manual, it is not free, and we need another manual to
replace it.
Please spread the word about this issue. Our community continues to
lose manuals to proprietary publishing. If we spread the word that
free software needs free reference manuals and free tutorials, perhaps
the next person who wants to contribute by writing documentation will
realize, before it is too late, that only free manuals contribute to
the free software community.
If you are writing documentation, please insist on publishing it
under the GNU Free Documentation License or another free documentation
license. Remember that this decision requires your approval--you don't
have to let the publisher decide. Some commercial publishers will use
a free license if you insist, but they will not propose the option; it
is up to you to raise the issue and say firmly that this is what you
want. If the publisher you are dealing with refuses, please try other
publishers. If you're not sure whether a proposed license is free,
write to <[email protected]>.
You can encourage commercial publishers to sell more free, copylefted
manuals and tutorials by buying them, and particularly by buying copies
from the publishers that paid for their writing or for major
improvements. Meanwhile, try to avoid buying non-free documentation at
all. Check the distribution terms of a manual before you buy it, and
insist that whoever seeks your business must respect your freedom.
Check the history of the book, and try to reward the publishers that
have paid or pay the authors to work on it.
The Free Software Foundation maintains a list of free documentation
published by other publishers, at
`http://www.fsf.org/doc/other-free-books.html'.
File: gdb.info, Node: Contributors, Prev: Free Software, Up: Summary
Contributors to GDB
===================
Richard Stallman was the original author of GDB, and of many other GNU
programs. Many others have contributed to its development. This
section attempts to credit major contributors. One of the virtues of
free software is that everyone is free to contribute to it; with
regret, we cannot actually acknowledge everyone here. The file
`ChangeLog' in the GDB distribution approximates a blow-by-blow account.
Changes much prior to version 2.0 are lost in the mists of time.
_Plea:_ Additions to this section are particularly welcome. If you
or your friends (or enemies, to be evenhanded) have been unfairly
omitted from this list, we would like to add your names!
So that they may not regard their many labors as thankless, we
particularly thank those who shepherded GDB through major releases:
Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0); Jim
Blandy (release 4.18); Jason Molenda (release 4.17); Stan Shebs
(release 4.14); Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10,
and 4.9); Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5,
and 4.4); John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9); Jim
Kingdon (releases 3.5, 3.4, and 3.3); and Randy Smith (releases 3.2,
3.1, and 3.0).
Richard Stallman, assisted at various times by Peter TerMaat, Chris
Hanson, and Richard Mlynarik, handled releases through 2.8.
Michael Tiemann is the author of most of the GNU C++ support in GDB,
with significant additional contributions from Per Bothner and Daniel
Berlin. James Clark wrote the GNU C++ demangler. Early work on C++
was by Peter TerMaat (who also did much general update work leading to
release 3.0).
GDB uses the BFD subroutine library to examine multiple object-file
formats; BFD was a joint project of David V. Henkel-Wallace, Rich
Pixley, Steve Chamberlain, and John Gilmore.
David Johnson wrote the original COFF support; Pace Willison did the
original support for encapsulated COFF.
Brent Benson of Harris Computer Systems contributed DWARF 2 support.
Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
support. Jean-Daniel Fekete contributed Sun 386i support. Chris
Hanson improved the HP9000 support. Noboyuki Hikichi and Tomoyuki
Hasei contributed Sony/News OS 3 support. David Johnson contributed
Encore Umax support. Jyrki Kuoppala contributed Altos 3068 support.
Jeff Law contributed HP PA and SOM support. Keith Packard contributed
NS32K support. Doug Rabson contributed Acorn Risc Machine support.
Bob Rusk contributed Harris Nighthawk CX-UX support. Chris Smith
contributed Convex support (and Fortran debugging). Jonathan Stone
contributed Pyramid support. Michael Tiemann contributed SPARC support.
Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
Pace Willison contributed Intel 386 support. Jay Vosburgh contributed
Symmetry support. Marko Mlinar contributed OpenRISC 1000 support.
Andreas Schwab contributed M68K GNU/Linux support.
Rich Schaefer and Peter Schauer helped with support of SunOS shared
libraries.
Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about
several machine instruction sets.
Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped
develop remote debugging. Intel Corporation, Wind River Systems, AMD,
and ARM contributed remote debugging modules for the i960, VxWorks,
A29K UDI, and RDI targets, respectively.
Brian Fox is the author of the readline libraries providing
command-line editing and command history.
Andrew Beers of SUNY Buffalo wrote the language-switching code, the
Modula-2 support, and contributed the Languages chapter of this manual.
Fred Fish wrote most of the support for Unix System Vr4. He also
enhanced the command-completion support to cover C++ overloaded symbols.
Hitachi America (now Renesas America), Ltd. sponsored the support for
H8/300, H8/500, and Super-H processors.
NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx
processors.
Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and
M32R/D processors.
Toshiba sponsored the support for the TX39 Mips processor.
Matsushita sponsored the support for the MN10200 and MN10300
processors.
Fujitsu sponsored the support for SPARClite and FR30 processors.
Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
watchpoints.
Michael Snyder added support for tracepoints.
Stu Grossman wrote gdbserver.
Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made nearly
innumerable bug fixes and cleanups throughout GDB.
The following people at the Hewlett-Packard Company contributed
support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
(narrow mode), HP's implementation of kernel threads, HP's aC++
compiler, and the Text User Interface (nee Terminal User Interface):
Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
provided HP-specific information in this manual.
DJ Delorie ported GDB to MS-DOS, for the DJGPP project. Robert
Hoehne made significant contributions to the DJGPP port.
Cygnus Solutions has sponsored GDB maintenance and much of its
development since 1991. Cygnus engineers who have worked on GDB
fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
Zuhn have made contributions both large and small.
Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
Cygnus Solutions, implemented the original GDB/MI interface.
Jim Blandy added support for preprocessor macros, while working for
Red Hat.
Andrew Cagney designed GDB's architecture vector. Many people
including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick Duffek,
Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei Sakamoto,
Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason Thorpe, Corinna
Vinschen, Ulrich Weigand, and Elena Zannoni, helped with the migration
of old architectures to this new framework.
Andrew Cagney completely re-designed and re-implemented GDB's
unwinder framework, this consisting of a fresh new design featuring
frame IDs, independent frame sniffers, and the sentinel frame. Mark
Kettenis implemented the DWARF 2 unwinder, Jeff Johnston the libunwind
unwinder, and Andrew Cagney the dummy, sentinel, tramp, and trad
unwinders. The architecture-specific changes, each involving a
complete rewrite of the architecture's frame code, were carried out by
Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
Weigand.
Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
Tensilica, Inc. contributed support for Xtensa processors. Others who
have worked on the Xtensa port of GDB in the past include Steve Tjiang,
John Newlin, and Scott Foehner.
File: gdb.info, Node: Sample Session, Next: Invocation, Prev: Summary, Up: Top
1 A Sample GDB Session
**********************
You can use this manual at your leisure to read all about GDB.
However, a handful of commands are enough to get started using the
debugger. This chapter illustrates those commands.
One of the preliminary versions of GNU `m4' (a generic macro
processor) exhibits the following bug: sometimes, when we change its
quote strings from the default, the commands used to capture one macro
definition within another stop working. In the following short `m4'
session, we define a macro `foo' which expands to `0000'; we then use
the `m4' built-in `defn' to define `bar' as the same thing. However,
when we change the open quote string to `<QUOTE>' and the close quote
string to `<UNQUOTE>', the same procedure fails to define a new synonym
`baz':
$ cd gnu/m4
$ ./m4
define(foo,0000)
foo
0000
define(bar,defn(`foo'))
bar
0000
changequote(<QUOTE>,<UNQUOTE>)
define(baz,defn(<QUOTE>foo<UNQUOTE>))
baz
Ctrl-d
m4: End of input: 0: fatal error: EOF in string
Let us use GDB to try to see what is going on.
$ gdb m4
GDB is free software and you are welcome to distribute copies
of it under certain conditions; type "show copying" to see
the conditions.
There is absolutely no warranty for GDB; type "show warranty"
for details.
GDB 6.8, Copyright 1999 Free Software Foundation, Inc...
(gdb)
GDB reads only enough symbol data to know where to find the rest when
needed; as a result, the first prompt comes up very quickly. We now
tell GDB to use a narrower display width than usual, so that examples
fit in this manual.
(gdb) set width 70
We need to see how the `m4' built-in `changequote' works. Having
looked at the source, we know the relevant subroutine is
`m4_changequote', so we set a breakpoint there with the GDB `break'
command.
(gdb) break m4_changequote
Breakpoint 1 at 0x62f4: file builtin.c, line 879.
Using the `run' command, we start `m4' running under GDB control; as
long as control does not reach the `m4_changequote' subroutine, the
program runs as usual:
(gdb) run
Starting program: /work/Editorial/gdb/gnu/m4/m4
define(foo,0000)
foo
0000
To trigger the breakpoint, we call `changequote'. GDB suspends
execution of `m4', displaying information about the context where it
stops.
changequote(<QUOTE>,<UNQUOTE>)
Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
at builtin.c:879
879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
Now we use the command `n' (`next') to advance execution to the next
line of the current function.
(gdb) n
882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
: nil,
`set_quotes' looks like a promising subroutine. We can go into it by
using the command `s' (`step') instead of `next'. `step' goes to the
next line to be executed in _any_ subroutine, so it steps into
`set_quotes'.
(gdb) s
set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
at input.c:530
530 if (lquote != def_lquote)
The display that shows the subroutine where `m4' is now suspended (and
its arguments) is called a stack frame display. It shows a summary of
the stack. We can use the `backtrace' command (which can also be
spelled `bt'), to see where we are in the stack as a whole: the
`backtrace' command displays a stack frame for each active subroutine.
(gdb) bt
#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
at input.c:530
#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
at builtin.c:882
#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
at macro.c:71
#4 0x79dc in expand_input () at macro.c:40
#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
We step through a few more lines to see what happens. The first two
times, we can use `s'; the next two times we use `n' to avoid falling
into the `xstrdup' subroutine.
(gdb) s
0x3b5c 532 if (rquote != def_rquote)
(gdb) s
0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
def_lquote : xstrdup(lq);
(gdb) n
536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
: xstrdup(rq);
(gdb) n
538 len_lquote = strlen(rquote);
The last line displayed looks a little odd; we can examine the variables
`lquote' and `rquote' to see if they are in fact the new left and right
quotes we specified. We use the command `p' (`print') to see their
values.
(gdb) p lquote
$1 = 0x35d40 "<QUOTE>"
(gdb) p rquote
$2 = 0x35d50 "<UNQUOTE>"
`lquote' and `rquote' are indeed the new left and right quotes. To
look at some context, we can display ten lines of source surrounding
the current line with the `l' (`list') command.
(gdb) l
533 xfree(rquote);
534
535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
: xstrdup (lq);
536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
: xstrdup (rq);
537
538 len_lquote = strlen(rquote);
539 len_rquote = strlen(lquote);
540 }
541
542 void
Let us step past the two lines that set `len_lquote' and `len_rquote',
and then examine the values of those variables.
(gdb) n
539 len_rquote = strlen(lquote);
(gdb) n
540 }
(gdb) p len_lquote
$3 = 9
(gdb) p len_rquote
$4 = 7
That certainly looks wrong, assuming `len_lquote' and `len_rquote' are
meant to be the lengths of `lquote' and `rquote' respectively. We can
set them to better values using the `p' command, since it can print the
value of any expression--and that expression can include subroutine
calls and assignments.
(gdb) p len_lquote=strlen(lquote)
$5 = 7
(gdb) p len_rquote=strlen(rquote)
$6 = 9
Is that enough to fix the problem of using the new quotes with the `m4'
built-in `defn'? We can allow `m4' to continue executing with the `c'
(`continue') command, and then try the example that caused trouble
initially:
(gdb) c
Continuing.
define(baz,defn(<QUOTE>foo<UNQUOTE>))
baz
0000
Success! The new quotes now work just as well as the default ones. The
problem seems to have been just the two typos defining the wrong
lengths. We allow `m4' exit by giving it an EOF as input:
Ctrl-d
Program exited normally.
The message `Program exited normally.' is from GDB; it indicates `m4'
has finished executing. We can end our GDB session with the GDB `quit'
command.
(gdb) quit
File: gdb.info, Node: Invocation, Next: Commands, Prev: Sample Session, Up: Top
2 Getting In and Out of GDB
***************************
This chapter discusses how to start GDB, and how to get out of it. The
essentials are:
* type `gdb' to start GDB.
* type `quit' or `Ctrl-d' to exit.
* Menu:
* Invoking GDB:: How to start GDB
* Quitting GDB:: How to quit GDB
* Shell Commands:: How to use shell commands inside GDB
* Logging Output:: How to log GDB's output to a file
File: gdb.info, Node: Invoking GDB, Next: Quitting GDB, Up: Invocation
2.1 Invoking GDB
================
Invoke GDB by running the program `gdb'. Once started, GDB reads
commands from the terminal until you tell it to exit.
You can also run `gdb' with a variety of arguments and options, to
specify more of your debugging environment at the outset.
The command-line options described here are designed to cover a
variety of situations; in some environments, some of these options may
effectively be unavailable.
The most usual way to start GDB is with one argument, specifying an
executable program:
gdb PROGRAM
You can also start with both an executable program and a core file
specified:
gdb PROGRAM CORE
You can, instead, specify a process ID as a second argument, if you
want to debug a running process:
gdb PROGRAM 1234
would attach GDB to process `1234' (unless you also have a file named
`1234'; GDB does check for a core file first).
Taking advantage of the second command-line argument requires a
fairly complete operating system; when you use GDB as a remote debugger
attached to a bare board, there may not be any notion of "process", and
there is often no way to get a core dump. GDB will warn you if it is
unable to attach or to read core dumps.
You can optionally have `gdb' pass any arguments after the
executable file to the inferior using `--args'. This option stops
option processing.
gdb --args gcc -O2 -c foo.c
This will cause `gdb' to debug `gcc', and to set `gcc''s
command-line arguments (*note Arguments::) to `-O2 -c foo.c'.
You can run `gdb' without printing the front material, which
describes GDB's non-warranty, by specifying `-silent':
gdb -silent
You can further control how GDB starts up by using command-line
options. GDB itself can remind you of the options available.
Type
gdb -help
to display all available options and briefly describe their use (`gdb
-h' is a shorter equivalent).
All options and command line arguments you give are processed in
sequential order. The order makes a difference when the `-x' option is
used.
* Menu:
* File Options:: Choosing files
* Mode Options:: Choosing modes
* Startup:: What GDB does during startup
File: gdb.info, Node: File Options, Next: Mode Options, Up: Invoking GDB
2.1.1 Choosing Files
--------------------
When GDB starts, it reads any arguments other than options as
specifying an executable file and core file (or process ID). This is
the same as if the arguments were specified by the `-se' and `-c' (or
`-p') options respectively. (GDB reads the first argument that does
not have an associated option flag as equivalent to the `-se' option
followed by that argument; and the second argument that does not have
an associated option flag, if any, as equivalent to the `-c'/`-p'
option followed by that argument.) If the second argument begins with
a decimal digit, GDB will first attempt to attach to it as a process,
and if that fails, attempt to open it as a corefile. If you have a
corefile whose name begins with a digit, you can prevent GDB from
treating it as a pid by prefixing it with `./', e.g. `./12345'.
If GDB has not been configured to included core file support, such
as for most embedded targets, then it will complain about a second
argument and ignore it.
Many options have both long and short forms; both are shown in the
following list. GDB also recognizes the long forms if you truncate
them, so long as enough of the option is present to be unambiguous.
(If you prefer, you can flag option arguments with `--' rather than
`-', though we illustrate the more usual convention.)
`-symbols FILE'
`-s FILE'
Read symbol table from file FILE.
`-exec FILE'
`-e FILE'
Use file FILE as the executable file to execute when appropriate,
and for examining pure data in conjunction with a core dump.
`-se FILE'
Read symbol table from file FILE and use it as the executable file.
`-core FILE'
`-c FILE'
Use file FILE as a core dump to examine.
`-pid NUMBER'
`-p NUMBER'
Connect to process ID NUMBER, as with the `attach' command.
`-command FILE'
`-x FILE'
Execute GDB commands from file FILE. *Note Command files: Command
Files.
`-eval-command COMMAND'
`-ex COMMAND'
Execute a single GDB command.
This option may be used multiple times to call multiple commands.
It may also be interleaved with `-command' as required.
gdb -ex 'target sim' -ex 'load' \
-x setbreakpoints -ex 'run' a.out
`-directory DIRECTORY'
`-d DIRECTORY'
Add DIRECTORY to the path to search for source and script files.
`-r'
`-readnow'
Read each symbol file's entire symbol table immediately, rather
than the default, which is to read it incrementally as it is
needed. This makes startup slower, but makes future operations
faster.
File: gdb.info, Node: Mode Options, Next: Startup, Prev: File Options, Up: Invoking GDB
2.1.2 Choosing Modes
--------------------
You can run GDB in various alternative modes--for example, in batch
mode or quiet mode.
`-nx'
`-n'
Do not execute commands found in any initialization files.
Normally, GDB executes the commands in these files after all the
command options and arguments have been processed. *Note Command
Files: Command Files.
`-quiet'
`-silent'
`-q'
"Quiet". Do not print the introductory and copyright messages.
These messages are also suppressed in batch mode.
`-batch'
Run in batch mode. Exit with status `0' after processing all the
command files specified with `-x' (and all commands from
initialization files, if not inhibited with `-n'). Exit with
nonzero status if an error occurs in executing the GDB commands in
the command files.
Batch mode may be useful for running GDB as a filter, for example
to download and run a program on another computer; in order to
make this more useful, the message
Program exited normally.
(which is ordinarily issued whenever a program running under GDB
control terminates) is not issued when running in batch mode.
`-batch-silent'
Run in batch mode exactly like `-batch', but totally silently. All
GDB output to `stdout' is prevented (`stderr' is unaffected).
This is much quieter than `-silent' and would be useless for an
interactive session.
This is particularly useful when using targets that give `Loading
section' messages, for example.
Note that targets that give their output via GDB, as opposed to
writing directly to `stdout', will also be made silent.
`-return-child-result'
The return code from GDB will be the return code from the child
process (the process being debugged), with the following
exceptions:
* GDB exits abnormally. E.g., due to an incorrect argument or
an internal error. In this case the exit code is the same as
it would have been without `-return-child-result'.
* The user quits with an explicit value. E.g., `quit 1'.
* The child process never runs, or is not allowed to terminate,
in which case the exit code will be -1.
This option is useful in conjunction with `-batch' or
`-batch-silent', when GDB is being used as a remote program loader
or simulator interface.
`-nowindows'
`-nw'
"No windows". If GDB comes with a graphical user interface (GUI)
built in, then this option tells GDB to only use the command-line
interface. If no GUI is available, this option has no effect.
`-windows'
`-w'
If GDB includes a GUI, then this option requires it to be used if
possible.
`-cd DIRECTORY'
Run GDB using DIRECTORY as its working directory, instead of the
current directory.
`-fullname'
`-f'
GNU Emacs sets this option when it runs GDB as a subprocess. It
tells GDB to output the full file name and line number in a
standard, recognizable fashion each time a stack frame is
displayed (which includes each time your program stops). This
recognizable format looks like two `\032' characters, followed by
the file name, line number and character position separated by
colons, and a newline. The Emacs-to-GDB interface program uses
the two `\032' characters as a signal to display the source code
for the frame.
`-epoch'
The Epoch Emacs-GDB interface sets this option when it runs GDB as
a subprocess. It tells GDB to modify its print routines so as to
allow Epoch to display values of expressions in a separate window.
`-annotate LEVEL'
This option sets the "annotation level" inside GDB. Its effect is
identical to using `set annotate LEVEL' (*note Annotations::).
The annotation LEVEL controls how much information GDB prints
together with its prompt, values of expressions, source lines, and
other types of output. Level 0 is the normal, level 1 is for use
when GDB is run as a subprocess of GNU Emacs, level 3 is the
maximum annotation suitable for programs that control GDB, and
level 2 has been deprecated.
The annotation mechanism has largely been superseded by GDB/MI
(*note GDB/MI::).
`--args'
Change interpretation of command line so that arguments following
the executable file are passed as command line arguments to the
inferior. This option stops option processing.
`-baud BPS'
`-b BPS'
Set the line speed (baud rate or bits per second) of any serial
interface used by GDB for remote debugging.
`-l TIMEOUT'
Set the timeout (in seconds) of any communication used by GDB for
remote debugging.
`-tty DEVICE'
`-t DEVICE'
Run using DEVICE for your program's standard input and output.
`-tui'
Activate the "Text User Interface" when starting. The Text User
Interface manages several text windows on the terminal, showing
source, assembly, registers and GDB command outputs (*note GDB
Text User Interface: TUI.). Alternatively, the Text User
Interface can be enabled by invoking the program `gdbtui'. Do not
use this option if you run GDB from Emacs (*note Using GDB under
GNU Emacs: Emacs.).
`-interpreter INTERP'
Use the interpreter INTERP for interface with the controlling
program or device. This option is meant to be set by programs
which communicate with GDB using it as a back end. *Note Command
Interpreters: Interpreters.
`--interpreter=mi' (or `--interpreter=mi2') causes GDB to use the
"GDB/MI interface" (*note The GDB/MI Interface: GDB/MI.) included
since GDB version 6.0. The previous GDB/MI interface, included in
GDB version 5.3 and selected with `--interpreter=mi1', is
deprecated. Earlier GDB/MI interfaces are no longer supported.
`-write'
Open the executable and core files for both reading and writing.
This is equivalent to the `set write on' command inside GDB (*note
Patching::).
`-statistics'
This option causes GDB to print statistics about time and memory
usage after it completes each command and returns to the prompt.
`-version'
This option causes GDB to print its version number and no-warranty
blurb, and exit.
File: gdb.info, Node: Startup, Prev: Mode Options, Up: Invoking GDB
2.1.3 What GDB Does During Startup
----------------------------------
Here's the description of what GDB does during session startup:
1. Sets up the command interpreter as specified by the command line
(*note interpreter: Mode Options.).
2. Reads the "init file" (if any) in your home directory(1) and
executes all the commands in that file.
3. Processes command line options and operands.
4. Reads and executes the commands from init file (if any) in the
current working directory. This is only done if the current
directory is different from your home directory. Thus, you can
have more than one init file, one generic in your home directory,
and another, specific to the program you are debugging, in the
directory where you invoke GDB.
5. Reads command files specified by the `-x' option. *Note Command
Files::, for more details about GDB command files.
6. Reads the command history recorded in the "history file". *Note
Command History::, for more details about the command history and
the files where GDB records it.
Init files use the same syntax as "command files" (*note Command
Files::) and are processed by GDB in the same way. The init file in
your home directory can set options (such as `set complaints') that
affect subsequent processing of command line options and operands.
Init files are not executed if you use the `-nx' option (*note Choosing
Modes: Mode Options.).
The GDB init files are normally called `.gdbinit'. The DJGPP port
of GDB uses the name `gdb.ini', due to the limitations of file names
imposed by DOS filesystems. The Windows ports of GDB use the standard
name, but if they find a `gdb.ini' file, they warn you about that and
suggest to rename the file to the standard name.