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

NAME

6       gdb - The GNU Debugger
7

SYNOPSIS

9       gdb    [-help] [-nx] [-q] [-batch] [-cd=dir] [-f] [-b bps] [-tty=dev]
10              [-s symfile] [-e prog] [-se prog] [-c core] [-x cmds] [-d dir]
11              [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       -directory=directory
160
161       -d directory
162               Add directory to the path to search for source files.
163
164       -nx
165
166       -n     Do  not  execute  commands  from  any  `.gdbinit' initialization
167              files.  Normally, the commands in these files are executed after
168              all the command options and arguments have been processed.
169
170
171
172       -quiet
173
174       -q     ``Quiet''.   Do  not  print  the introductory and copyright mes‐
175              sages.  These messages are also suppressed in batch mode.
176
177
178       -batch Run in batch mode.  Exit with status 0 after processing all  the
179              command files specified with `-x' (and `.gdbinit', if not inhib‐
180              ited).  Exit with nonzero status if an error occurs in executing
181              the GDB commands in the command files.
182
183              Batch  mode may be useful for running GDB as a filter, for exam‐
184              ple to download and run a program on another computer; in  order
185              to make this more useful, the message
186
187              Program exited normally.
188
189
190              (which is ordinarily issued whenever a program running under GDB
191              control terminates) is not issued when running in batch mode.
192
193
194       -cd=directory
195               Run GDB using directory as its working  directory,  instead  of
196              the current directory.
197
198
199       -fullname
200
201       -f     Emacs  sets  this  option  when it runs GDB as a subprocess.  It
202              tells GDB to output the full file name  and  line  number  in  a
203              standard,  recognizable  fashion each time a stack frame is dis‐
204              played (which includes each time the program stops).  This  rec‐
205              ognizable  format  looks  like two ` 32' characters, followed by
206              the file name, line number and character position  separated  by
207              colons,  and a newline.  The Emacs-to-GDB interface program uses
208              the two ` 32' characters as a signal to display the source  code
209              for the frame.
210
211
212       -b bps  Set the line speed (baud rate or bits per second) of any serial
213              interface used by GDB for remote debugging.
214
215
216       -tty=device
217               Run using device for your program's standard input and output.
218

SEE ALSO

220       `gdb' entry in info; Using GDB: A Guide to the GNU Source-Level  Debug‐
221       ger, Richard M. Stallman and Roland H. Pesch, July 1991.
222

COPYING

224       Copyright (c) 1991, 2010 Free Software Foundation, Inc.
225
226       Permission  is  granted  to make and distribute verbatim copies of this
227       manual provided the copyright notice and  this  permission  notice  are
228       preserved on all copies.
229
230       Permission  is granted to copy and distribute modified versions of this
231       manual under the conditions for verbatim  copying,  provided  that  the
232       entire  resulting derived work is distributed under the terms of a per‐
233       mission notice identical to this one.
234
235       Permission is granted to copy and distribute translations of this  man‐
236       ual into another language, under the above conditions for modified ver‐
237       sions, except that this permission notice may be included  in  transla‐
238       tions approved by the Free Software Foundation instead of in the origi‐
239       nal English.
240
241
242
243GNU Tools                          22may2002                            gdb(1)
Impressum