1gdb(1)                             GNU Tools                            gdb(1)
2
3
4

NAME

6       gdb - The GNU Debugger
7

SYNOPSIS

9       gdb    [-help] [-nh] [-nx] [-q] [-batch] [-cd=dir] [-f] [-b bps]
10              [-tty=dev] [-s symfile] [-e prog] [-se prog] [-c core] [-x file]
11              [-ex cmd] [-d dir] [prog[core|procID]]
12

DESCRIPTION

14       The  purpose  of  a debugger such as GDB is to allow you to see what is
15       going on ``inside'' another program while it executes—or  what  another
16       program was doing at the moment it crashed.
17
18       GDB  can  do four main kinds of things (plus other things in support of
19       these) to help you catch bugs in the act:
20
21
22          ·   Start your program, specifying anything that  might  affect  its
23              behavior.
24
25
26          ·   Make your program stop on specified conditions.
27
28
29          ·   Examine what has happened, when your program has stopped.
30
31
32          ·   Change  things  in your program, so you can experiment with cor‐
33              recting the effects of one bug and go on to learn about another.
34
35       You can use GDB to debug programs written  in  C,  C++,  and  Modula-2.
36       Fortran support will be added when a GNU Fortran compiler is ready.
37
38       GDB is invoked with the shell command gdb.  Once started, it reads com‐
39       mands from the terminal until you tell it to exit with the GDB  command
40       quit.   You  can  get  online help from gdb itself by using the command
41       help.
42
43       You can run gdb with no arguments or options; but the most usual way to
44       start GDB is with one argument or two, specifying an executable program
45       as the argument:
46
47       gdb program
48
49
50       You can also start with both an executable  program  and  a  core  file
51       specified:
52
53       gdb program core
54
55
56       You  can,  instead,  specify  a process ID as a second argument, if you
57       want to debug a running process:
58
59       gdb program 1234
60
61
62       would attach GDB to process 1234 (unless you also  have  a  file  named
63       `1234'; GDB does check for a core file first).
64
65       Here are some of the most frequently needed GDB commands:
66
67       break [file:]function
68               Set a breakpoint at function (in file).
69
70       run [arglist]
71              Start your program (with arglist, if specified).
72
73       bt     Backtrace: display the program stack.
74
75       print expr
76               Display the value of an expression.
77
78       c      Continue  running your program (after stopping, e.g. at a break‐
79              point).
80
81       next   Execute next program line (after stopping); step over any  func‐
82              tion calls in the line.
83
84       edit [file:]function
85              look at the program line where it is presently stopped.
86
87       list [file:]function
88              type  the  text  of  the  program in the vicinity of where it is
89              presently stopped.
90
91       step   Execute next program line (after stopping); step into any  func‐
92              tion calls in the line.
93
94       help [name]
95              Show  information about GDB command name, or general information
96              about using GDB.
97
98       quit   Exit from GDB.
99
100       For full details on GDB, see Using GDB: A Guide to the GNU Source-Level
101       Debugger, by Richard M. Stallman and Roland H. Pesch.  The same text is
102       available online as the gdb entry in the info program.
103

OPTIONS

105       Any arguments other than options specify an executable  file  and  core
106       file  (or  process ID); that is, the first argument encountered with no
107       associated option flag is equivalent to a `-se' option, and the second,
108       if  any,  is  equivalent  to  a `-c' option if it's the name of a file.
109       Many options have both long and short forms; both are shown here.   The
110       long  forms are also recognized if you truncate them, so long as enough
111       of the option is present to be unambiguous.  (If you  prefer,  you  can
112       flag  option  arguments  with `+' rather than `-', though we illustrate
113       the more usual convention.)
114
115       All the options and command line arguments you give  are  processed  in
116       sequential order.  The order makes a difference when the `-x' option is
117       used.
118
119
120       -help
121
122       -h     List all options, with brief explanations.
123
124
125       -symbols=file
126
127       -s file
128               Read symbol table from file file.
129
130
131       -write Enable writing into executable and core files.
132
133
134       -exec=file
135
136       -e file
137               Use file file as the executable file to execute when  appropri‐
138              ate,  and  for  examining  pure  data in conjunction with a core
139              dump.
140
141
142       -se=file
143               Read symbol table from file file and use it as  the  executable
144              file.
145
146
147       -core=file
148
149       -c file
150               Use file file as a core dump to examine.
151
152
153       -command=file
154
155       -x file
156               Execute GDB commands from file file.
157
158
159       -ex command
160               Execute given GDB command.
161
162
163       -directory=directory
164
165       -d directory
166               Add directory to the path to search for source files.
167
168       -nh    Do not execute commands from ~/.gdbinit.
169
170
171       -nx
172
173       -n     Do  not  execute  commands  from  any  `.gdbinit' initialization
174              files.
175
176
177
178       -quiet
179
180       -q     ``Quiet''.  Do not print the  introductory  and  copyright  mes‐
181              sages.  These messages are also suppressed in batch mode.
182
183
184       -batch Run  in batch mode.  Exit with status 0 after processing all the
185              command files specified with `-x' (and `.gdbinit', if not inhib‐
186              ited).  Exit with nonzero status if an error occurs in executing
187              the GDB commands in the command files.
188
189              Batch mode may be useful for running GDB as a filter, for  exam‐
190              ple  to download and run a program on another computer; in order
191              to make this more useful, the message
192
193              Program exited normally.
194
195
196              (which is ordinarily issued whenever a program running under GDB
197              control terminates) is not issued when running in batch mode.
198
199
200       -cd=directory
201                Run  GDB  using directory as its working directory, instead of
202              the current directory.
203
204
205       -fullname
206
207       -f     Emacs sets this option when it runs GDB  as  a  subprocess.   It
208              tells  GDB  to  output  the  full file name and line number in a
209              standard, recognizable fashion each time a stack frame  is  dis‐
210              played  (which includes each time the program stops).  This rec‐
211              ognizable format looks like two ` 32'  characters,  followed  by
212              the  file  name, line number and character position separated by
213              colons, and a newline.  The Emacs-to-GDB interface program  uses
214              the  two ` 32' characters as a signal to display the source code
215              for the frame.
216
217
218       -b bps  Set the line speed (baud rate or bits per second) of any serial
219              interface used by GDB for remote debugging.
220
221
222       -tty=device
223               Run using device for your program's standard input and output.
224

SEE ALSO

226       The  full  documentation for gdb is maintained as a Texinfo manual.  If
227       the info and gdb programs and GDB's Texinfo documentation are  properly
228       installed at your site, the command
229
230              info gdb
231
232       should give you access to the complete manual.
233
234       Using  GDB: A Guide to the GNU Source-Level Debugger, Richard M. Stall‐
235       man and Roland H. Pesch, July 1991.
236

COPYING

238       Copyright (c) 1991, 2010 Free Software Foundation, Inc.
239
240       Permission is granted to make and distribute verbatim  copies  of  this
241       manual  provided  the  copyright  notice and this permission notice are
242       preserved on all copies.
243
244       Permission is granted to copy and distribute modified versions of  this
245       manual  under  the  conditions  for verbatim copying, provided that the
246       entire resulting derived work is distributed under the terms of a  per‐
247       mission notice identical to this one.
248
249       Permission  is granted to copy and distribute translations of this man‐
250       ual into another language, under the above conditions for modified ver‐
251       sions,  except  that this permission notice may be included in transla‐
252       tions approved by the Free Software Foundation instead of in the origi‐
253       nal English.
254
255
256
257GNU Tools                          22may2002                            gdb(1)
Impressum