building.texi 66 KB
Newer Older
Glenn Morris's avatar
Glenn Morris committed
1
@c This is part of the Emacs manual.
Paul Eggert's avatar
Paul Eggert committed
2
@c Copyright (C) 1985-1987, 1993-1995, 1997, 2000-2017 Free Software
3
@c Foundation, Inc.
Glenn Morris's avatar
Glenn Morris committed
4
@c See file emacs.texi for copying conditions.
5
@node Building
Glenn Morris's avatar
Glenn Morris committed
6 7 8 9 10
@chapter Compiling and Testing Programs
@cindex building programs
@cindex program building
@cindex running Lisp functions

11 12 13
  The previous chapter discusses the Emacs commands that are useful
for making changes in programs.  This chapter deals with commands that
assist in the process of compiling and testing programs.
Glenn Morris's avatar
Glenn Morris committed
14 15 16 17 18 19 20 21 22

@menu
* Compilation::         Compiling programs in languages other
                          than Lisp (C, Pascal, etc.).
* Compilation Mode::    The mode for visiting compiler errors.
* Compilation Shell::   Customizing your shell properly
                          for use in the compilation buffer.
* Grep Searching::      Searching with grep.
* Flymake::             Finding syntax errors on the fly.
23
* Debuggers::           Running symbolic debuggers for non-Lisp programs.
Glenn Morris's avatar
Glenn Morris committed
24 25 26
* Executing Lisp::      Various modes for editing Lisp programs,
                          with different facilities for running
                          the Lisp programs.
27 28 29
* Libraries: Lisp Libraries.      How Lisp programs are loaded into Emacs.
* Eval: Lisp Eval.      Executing a single Lisp expression in Emacs.
* Interaction: Lisp Interaction.  Executing Lisp in an Emacs buffer.
30
* External Lisp::       Communicating through Emacs with a separate Lisp.
Glenn Morris's avatar
Glenn Morris committed
31 32 33 34 35 36 37 38 39
@end menu

@node Compilation
@section Running Compilations under Emacs
@cindex inferior process
@cindex make
@cindex compilation errors
@cindex error log

40 41 42
  Emacs can run compilers for languages such as C and Fortran, feeding
the compilation log into an Emacs buffer.  It can also parse the error
messages and show you where the errors occurred.
Glenn Morris's avatar
Glenn Morris committed
43 44 45 46

@table @kbd
@item M-x compile
Run a compiler asynchronously under Emacs, with error messages going to
47
the @file{*compilation*} buffer.
Glenn Morris's avatar
Glenn Morris committed
48 49 50 51 52 53 54 55
@item M-x recompile
Invoke a compiler with the same command as in the last invocation of
@kbd{M-x compile}.
@item M-x kill-compilation
Kill the running compilation subprocess.
@end table

@findex compile
56 57
  To run @code{make} or another compilation command, type @kbd{M-x
compile}.  This reads a shell command line using the minibuffer, and
58 59
then executes the command by running a shell as a subprocess (or
@dfn{inferior process}) of Emacs.  The output is inserted in a buffer
60
named @file{*compilation*}.  The current buffer's default directory is
61 62
used as the working directory for the execution of the command;
normally, therefore, compilation takes place in this directory.
Glenn Morris's avatar
Glenn Morris committed
63 64

@vindex compile-command
65 66 67 68 69 70 71 72 73 74
  The default compilation command is @samp{make -k}, which is usually
correct for programs compiled using the @command{make} utility (the
@samp{-k} flag tells @command{make} to continue compiling as much as
possible after an error).  @xref{Top,, Make, make, GNU Make Manual}.
If you have done @kbd{M-x compile} before, the command that you
specified is automatically stored in the variable
@code{compile-command}; this is used as the default the next time you
type @kbd{M-x compile}.  A file can also specify a file-local value
for @code{compile-command} (@pxref{File Variables}).

75
  Starting a compilation displays the @file{*compilation*} buffer in
76 77
another window but does not select it.  While the compilation is
running, the word @samp{run} is shown in the major mode indicator for
78 79
the @file{*compilation*} buffer, and the word @samp{Compiling} appears
in all mode lines.  You do not have to keep the @file{*compilation*}
80 81
buffer visible while compilation is running; it continues in any case.
When the compilation ends, for whatever reason, the mode line of the
82
@file{*compilation*} buffer changes to say @samp{exit} (followed by
83 84 85 86
the exit code: @samp{[0]} for a normal exit), or @samp{signal} (if a
signal terminated the process).

  If you want to watch the compilation transcript as it appears,
87
switch to the @file{*compilation*} buffer and move point to the end of
88 89 90 91
the buffer.  When point is at the end, new compilation output is
inserted above point, which remains at the end.  Otherwise, point
remains fixed while compilation output is added at the end of the
buffer.
Glenn Morris's avatar
Glenn Morris committed
92

93 94 95 96
  While compilation proceeds, the mode line is updated to show the
number of errors, warnings, and informational messages that have been
seen so far.

Glenn Morris's avatar
Glenn Morris committed
97 98
@cindex compilation buffer, keeping point at end
@vindex compilation-scroll-output
99
  If you change the variable @code{compilation-scroll-output} to a
100
non-@code{nil} value, the @file{*compilation*} buffer scrolls
101 102 103 104
automatically to follow the output.  If the value is
@code{first-error}, scrolling stops when the first error appears,
leaving point at that error.  For any other non-@code{nil} value,
scrolling continues until there is no more output.
Glenn Morris's avatar
Glenn Morris committed
105 106 107

@findex recompile
  To rerun the last compilation with the same command, type @kbd{M-x
108 109
recompile}.  This reuses the compilation command from the last
invocation of @kbd{M-x compile}.  It also reuses the
110
@file{*compilation*} buffer and starts the compilation in its default
Glenn Morris's avatar
Glenn Morris committed
111 112 113 114
directory, which is the directory in which the previous compilation
was started.

@findex kill-compilation
115
@vindex compilation-always-kill
Glenn Morris's avatar
Glenn Morris committed
116
  Starting a new compilation also kills any compilation already
117
running in @file{*compilation*}, as the buffer can only handle one
Glenn Morris's avatar
Glenn Morris committed
118
compilation at any time.  However, @kbd{M-x compile} asks for
119 120 121 122
confirmation before actually killing a compilation that is running; to
always automatically kill the compilation without asking, change the
variable @code{compilation-always-kill} to @code{t}.  You can also
kill a compilation process with the command @kbd{M-x
Glenn Morris's avatar
Glenn Morris committed
123 124
kill-compilation}.

125
  To run two compilations at once, start the first one, then rename
126
the @file{*compilation*} buffer (perhaps using @code{rename-uniquely};
127
@pxref{Misc Buffer}), then switch buffers and start the other
128
compilation.  This will create a new @file{*compilation*} buffer.
Glenn Morris's avatar
Glenn Morris committed
129 130 131 132 133 134 135 136 137 138 139 140 141

@vindex compilation-environment
  You can control the environment passed to the compilation command
with the variable @code{compilation-environment}.  Its value is a list
of environment variable settings; each element should be a string of
the form @code{"@var{envvarname}=@var{value}"}.  These environment
variable settings override the usual ones.

@node Compilation Mode
@section Compilation Mode

@cindex Compilation mode
@cindex mode, Compilation
142
@cindex locus
143
  The @file{*compilation*} buffer uses a major mode called Compilation
144 145 146 147 148 149 150 151 152 153 154
mode.  Compilation mode turns each error message in the buffer into a
hyperlink; you can move point to it and type @key{RET}, or click on it
with the mouse (@pxref{Mouse References}), to visit the @dfn{locus} of
the error message in a separate window.  The locus is the specific
position in a file where that error occurred.

@findex compile-goto-error
@vindex compilation-auto-jump-to-first-error
  If you change the variable
@code{compilation-auto-jump-to-first-error} to a non-@code{nil} value,
Emacs automatically visits the locus of the first error message that
155
appears in the @file{*compilation*} buffer.
156 157

  Compilation mode provides the following additional commands.  These
158
commands can also be used in @file{*grep*} buffers, where the
159 160
hyperlinks are search matches rather than error messages (@pxref{Grep
Searching}).
Glenn Morris's avatar
Glenn Morris committed
161 162 163 164 165

@table @kbd
@item M-g M-n
@itemx M-g n
@itemx C-x `
166
Visit the locus of the next error message or match (@code{next-error}).
Glenn Morris's avatar
Glenn Morris committed
167 168
@item M-g M-p
@itemx M-g p
169 170
Visit the locus of the previous error message or match
(@code{previous-error}).
Glenn Morris's avatar
Glenn Morris committed
171
@item M-n
172 173
Move point to the next error message or match, without visiting its
locus (@code{compilation-next-error}).
Glenn Morris's avatar
Glenn Morris committed
174
@item M-p
175 176
Move point to the previous error message or match, without visiting
its locus (@code{compilation-previous-error}).
Glenn Morris's avatar
Glenn Morris committed
177
@item M-@}
178 179
Move point to the next error message or match occurring in a different
file (@code{compilation-next-file}).
Glenn Morris's avatar
Glenn Morris committed
180
@item M-@{
181 182
Move point to the previous error message or match occurring in a
different file (@code{compilation-previous-file}).
Glenn Morris's avatar
Glenn Morris committed
183 184 185 186 187 188 189 190 191 192
@item C-c C-f
Toggle Next Error Follow minor mode, which makes cursor motion in the
compilation buffer produce automatic source display.
@end table

@kindex M-g M-n
@kindex M-g n
@kindex C-x `
@findex next-error
@vindex next-error-highlight
193 194 195 196 197 198 199
  To visit errors sequentially, type @w{@kbd{C-x `}}
(@code{next-error}), or equivalently @kbd{M-g M-n} or @kbd{M-g n}.
This command can be invoked from any buffer, not just a Compilation
mode buffer.  The first time you invoke it after a compilation, it
visits the locus of the first error message.  Each subsequent
@w{@kbd{C-x `}} visits the next error, in a similar fashion.  If you
visit a specific error with @key{RET} or a mouse click in the
200
@file{*compilation*} buffer, subsequent @w{@kbd{C-x `}} commands
201 202 203 204 205 206 207 208
advance from there.  When @w{@kbd{C-x `}} finds no more error messages
to visit, it signals an error.  @w{@kbd{C-u C-x `}} starts again from
the beginning of the compilation buffer, and visits the first locus.

  @kbd{M-g M-p} or @kbd{M-g p} (@code{previous-error}) iterates
through errors in the opposite direction.

  The @code{next-error} and @code{previous-error} commands don't just
209 210
act on the errors or matches listed in @file{*compilation*} and
@file{*grep*} buffers; they also know how to iterate through error or
211 212 213 214 215 216 217 218 219
match lists produced by other commands, such as @kbd{M-x occur}
(@pxref{Other Repeating Search}).  If you are already in a buffer
containing error messages or matches, those are the ones that are
iterated through; otherwise, Emacs looks for a buffer containing error
messages or matches amongst the windows of the selected frame, then
for one that @code{next-error} or @code{previous-error} previously
iterated through, and finally amongst all other buffers.  If the
buffer chosen for iterating through is not currently displayed in a
window, it will be displayed.
Glenn Morris's avatar
Glenn Morris committed
220 221

@vindex compilation-skip-threshold
222 223 224 225 226 227 228 229 230 231 232 233
  By default, the @code{next-error} and @code{previous-error} commands
skip less important messages.  The variable
@code{compilation-skip-threshold} controls this.  The default value,
1, means to skip anything less important than a warning.  A value of 2
means to skip anything less important than an error, while 0 means not
to skip any messages.

  When Emacs visits the locus of an error message, it momentarily
highlights the relevant source line.  The duration of this highlight
is determined by the variable @code{next-error-highlight}.

@vindex compilation-context-lines
234
  If the @file{*compilation*} buffer is shown in a window with a left
235 236
fringe (@pxref{Fringes}), the locus-visiting commands put an arrow in
the fringe, pointing to the current error message.  If the window has
237 238 239 240 241 242 243
no left fringe, such as on a text terminal, these commands scroll the
window so that the current message is at the top of the window.  If
you change the variable @code{compilation-context-lines} to an integer
value @var{n}, these commands scroll the window so that the current
error message is @var{n} lines from the top, whether or not there is a
fringe; the default value, @code{nil}, gives the behavior described
above.
Glenn Morris's avatar
Glenn Morris committed
244 245 246 247 248

@vindex compilation-error-regexp-alist
@vindex grep-regexp-alist
  To parse messages from the compiler, Compilation mode uses the
variable @code{compilation-error-regexp-alist} which lists various
249 250 251
error message formats and tells Emacs how to extract the locus from
each.  A similar variable, @code{grep-regexp-alist}, tells Emacs how
to parse output from a @code{grep} command (@pxref{Grep Searching}).
Glenn Morris's avatar
Glenn Morris committed
252 253 254 255 256

@findex compilation-next-error
@findex compilation-previous-error
@findex compilation-next-file
@findex compilation-previous-file
257 258 259 260 261 262
  Compilation mode also defines the keys @key{SPC} and @key{DEL} to
scroll by screenfuls; @kbd{M-n} (@code{compilation-next-error}) and
@kbd{M-p} (@code{compilation-previous-error}) to move to the next or
previous error message; and @kbd{M-@{} (@code{compilation-next-file})
and @kbd{M-@}} (@code{compilation-previous-file}) to move to the next
or previous error message for a different source file.
Glenn Morris's avatar
Glenn Morris committed
263 264 265 266 267

@cindex Next Error Follow mode
@findex next-error-follow-minor-mode
  You can type @kbd{C-c C-f} to toggle Next Error Follow mode.  In
this minor mode, ordinary cursor motion in the compilation buffer
268
automatically updates the source buffer, i.e., moving the cursor over
269
an error message causes the locus of that error to be displayed.
Glenn Morris's avatar
Glenn Morris committed
270 271 272

  The features of Compilation mode are also available in a minor mode
called Compilation Minor mode.  This lets you parse error messages in
273 274 275 276 277
any buffer, not just a normal compilation output buffer.  Type
@kbd{M-x compilation-minor-mode} to enable the minor mode.  For
instance, in an Rlogin buffer (@pxref{Remote Host}), Compilation minor
mode automatically accesses remote source files by FTP (@pxref{File
Names}).
Glenn Morris's avatar
Glenn Morris committed
278 279 280 281

@node Compilation Shell
@section Subshells for Compilation

282 283 284 285
  The @kbd{M-x compile} command uses a shell to run the compilation
command, but specifies the option for a noninteractive shell.  This
means, in particular, that the shell should start with no prompt.  If
you find your usual shell prompt making an unsightly appearance in the
286
@file{*compilation*} buffer, it means you have made a mistake in your
287 288 289
shell's init file by setting the prompt unconditionally.  (This init
file may be named @file{.bashrc}, @file{.profile}, @file{.cshrc},
@file{.shrc}, etc., depending on what shell you use.)  The shell init
Glenn Morris's avatar
Glenn Morris committed
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
file should set the prompt only if there already is a prompt.  Here's
how to do it in bash:

@example
if [ "$@{PS1+set@}" = set ]
then PS1=@dots{}
fi
@end example

@noindent
And here's how to do it in csh:

@example
if ($?prompt) set prompt = @dots{}
@end example

306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
  Emacs does not expect a compiler process to launch asynchronous
subprocesses; if it does, and they keep running after the main
compiler process has terminated, Emacs may kill them or their output
may not arrive in Emacs.  To avoid this problem, make the main
compilation process wait for its subprocesses to finish.  In a shell
script, you can do this using @samp{$!} and @samp{wait}, like this:

@example
(sleep 10; echo 2nd)& pid=$!  # @r{Record pid of subprocess}
echo first message
wait $pid                     # @r{Wait for subprocess}
@end example

@noindent
If the background process does not output to the compilation buffer,
so you only need to prevent it from being killed when the main
compilation process terminates, this is sufficient:

@example
nohup @var{command}; sleep 1
@end example
Glenn Morris's avatar
Glenn Morris committed
327 328

@ifnottex
Paul Eggert's avatar
Paul Eggert committed
329
  On MS-DOS, asynchronous subprocesses are
330
not supported, so @kbd{M-x compile} runs the compilation command
331
synchronously (i.e., you must wait until the command finishes before
332
you can do anything else in Emacs).  @xref{MS-DOS}.
Glenn Morris's avatar
Glenn Morris committed
333 334 335 336 337 338
@end ifnottex

@node Grep Searching
@section Searching with Grep under Emacs

  Just as you can run a compiler from Emacs and then visit the lines
339 340
with compilation errors, you can also run @command{grep} and then
visit the lines on which matches were found.  This works by treating
Paul Eggert's avatar
Paul Eggert committed
341
the matches reported by @command{grep} as if they were errors.
342
The output buffer uses Grep mode, which is a variant of Compilation
Glenn Morris's avatar
Glenn Morris committed
343 344 345 346
mode (@pxref{Compilation Mode}).

@table @kbd
@item M-x grep
347
@itemx M-x lgrep
348
Run @command{grep} asynchronously under Emacs, listing matching lines in
349
the buffer named @file{*grep*}.
Glenn Morris's avatar
Glenn Morris committed
350 351 352
@item M-x grep-find
@itemx M-x find-grep
@itemx M-x rgrep
353
Run @command{grep} via @code{find}, and collect output in the
354
@file{*grep*} buffer.
355
@item M-x zrgrep
356
Run @code{zgrep} and collect output in the @file{*grep*} buffer.
Glenn Morris's avatar
Glenn Morris committed
357
@item M-x kill-grep
358
Kill the running @command{grep} subprocess.
Glenn Morris's avatar
Glenn Morris committed
359 360 361
@end table

@findex grep
362 363 364
  To run @command{grep}, type @kbd{M-x grep}, then enter a command line
that specifies how to run @command{grep}.  Use the same arguments you
would give @command{grep} when running it normally: a @command{grep}-style
Glenn Morris's avatar
Glenn Morris committed
365 366
regexp (usually in single-quotes to quote the shell's special
characters) followed by file names, which may use wildcards.  If you
367 368
specify a prefix argument for @kbd{M-x grep}, it finds the identifier
(@pxref{Xref}) in the buffer around point, and puts that into the
369
default @command{grep} command.
Glenn Morris's avatar
Glenn Morris committed
370

371
  Your command need not simply run @command{grep}; you can use any shell
Glenn Morris's avatar
Glenn Morris committed
372
command that produces output in the same format.  For instance, you
373
can chain @command{grep} commands, like this:
Glenn Morris's avatar
Glenn Morris committed
374 375 376 377 378

@example
grep -nH -e foo *.el | grep bar | grep toto
@end example

379
  The output from @command{grep} goes in the @file{*grep*} buffer.  You
Glenn Morris's avatar
Glenn Morris committed
380 381 382 383 384 385 386 387 388
can find the corresponding lines in the original files using @w{@kbd{C-x
`}}, @key{RET}, and so forth, just like compilation errors.

  Some grep programs accept a @samp{--color} option to output special
markers around matches for the purpose of highlighting.  You can make
use of this feature by setting @code{grep-highlight-matches} to
@code{t}.  When displaying a match in the source buffer, the exact
match will be highlighted, instead of the entire source line.

389 390 391 392 393 394 395 396
  The @command{grep} commands will offer to save buffers before
running.  This is controlled by the @code{grep-save-buffers} variable.
The possible values are either @code{nil} (don't save), @code{ask}
(ask before saving), a function which will be used as a predicate (and
is called with the file name as the parameter and should return
non-nil if the buffer is to be saved), and any other non-@code{nil}
value means that all buffers should be saved without asking.

Glenn Morris's avatar
Glenn Morris committed
397 398 399 400 401
@findex grep-find
@findex find-grep
  The command @kbd{M-x grep-find} (also available as @kbd{M-x
find-grep}) is similar to @kbd{M-x grep}, but it supplies a different
initial default for the command---one that runs both @code{find} and
402
@command{grep}, so as to search every file in a directory tree.  See also
Glenn Morris's avatar
Glenn Morris committed
403 404 405 406
the @code{find-grep-dired} command, in @ref{Dired and Find}.

@findex lgrep
@findex rgrep
407
@findex zrgrep
Glenn Morris's avatar
Glenn Morris committed
408
  The commands @kbd{M-x lgrep} (local grep) and @kbd{M-x rgrep}
409
(recursive grep) are more user-friendly versions of @command{grep} and
Glenn Morris's avatar
Glenn Morris committed
410 411
@code{grep-find}, which prompt separately for the regular expression
to match, the files to search, and the base directory for the search.
412 413
Case sensitivity of the search is controlled by the current value of
@code{case-fold-search}.  The command @kbd{M-x zrgrep} is similar to
414 415
@kbd{M-x rgrep}, but it calls @command{zgrep} instead of
@command{grep} to search the contents of gzipped files.
Glenn Morris's avatar
Glenn Morris committed
416

417
  These commands build the shell commands based on the variables
Glenn Morris's avatar
Glenn Morris committed
418
@code{grep-template} (for @code{lgrep}) and @code{grep-find-template}
419 420
(for @code{rgrep}).  The files to search can use aliases defined in
the variable @code{grep-files-aliases}.
Glenn Morris's avatar
Glenn Morris committed
421

422 423 424 425 426
@vindex grep-find-ignored-directories
  Directories listed in the variable
@code{grep-find-ignored-directories} are automatically skipped by
@kbd{M-x rgrep}.  The default value includes the data directories used
by various version control systems.
Glenn Morris's avatar
Glenn Morris committed
427 428 429 430 431 432 433

@node Flymake
@section Finding Syntax Errors On The Fly
@cindex checking syntax

  Flymake mode is a minor mode that performs on-the-fly syntax
checking for many programming and markup languages, including C, C++,
434
Perl, HTML, and @TeX{}/@LaTeX{}.  It is somewhat analogous to Flyspell
Glenn Morris's avatar
Glenn Morris committed
435 436 437 438 439 440 441 442 443
mode, which performs spell checking for ordinary human languages in a
similar fashion (@pxref{Spelling}).  As you edit a file, Flymake mode
runs an appropriate syntax checking tool in the background, using a
temporary copy of the buffer.  It then parses the error and warning
messages, and highlights the erroneous lines in the buffer.  The
syntax checking tool used depends on the language; for example, for
C/C++ files this is usually the C compiler.  Flymake can also use
build tools such as @code{make} for checking complicated projects.

444 445 446 447 448
  To enable Flymake mode, type @kbd{M-x flymake-mode}.  You can jump
to the errors that it finds by using @kbd{M-x flymake-goto-next-error}
and @kbd{M-x flymake-goto-prev-error}.  To display any error messages
associated with the current line, type @kbd{M-x
flymake-display-err-menu-for-current-line}.
Glenn Morris's avatar
Glenn Morris committed
449

450 451 452 453 454 455 456
  For more details about using Flymake,
@ifnottex
see @ref{Top, Flymake, Flymake, flymake, The Flymake Manual}.
@end ifnottex
@iftex
see the Flymake Info manual, which is distributed with Emacs.
@end iftex
Glenn Morris's avatar
Glenn Morris committed
457 458 459 460 461 462 463 464 465 466 467 468 469

@node Debuggers
@section Running Debuggers Under Emacs
@cindex debuggers
@cindex GUD library
@cindex GDB
@cindex DBX
@cindex SDB
@cindex XDB
@cindex Perldb
@cindex JDB
@cindex PDB

Chong Yidong's avatar
Chong Yidong committed
470
The GUD (Grand Unified Debugger) library provides an Emacs interface
471 472 473
to a wide variety of symbolic debuggers.  It can run the GNU Debugger
(GDB), as well as DBX, SDB, XDB, Perl's debugging mode, the Python
debugger PDB, and the Java Debugger JDB.
Glenn Morris's avatar
Glenn Morris committed
474

475 476 477 478 479 480 481
  Emacs provides a special interface to GDB, which uses extra Emacs
windows to display the state of the debugged program.  @xref{GDB
Graphical Interface}.

  Emacs also has a built-in debugger for Emacs Lisp programs.
@xref{Debugging,, The Lisp Debugger, elisp, the Emacs Lisp Reference
Manual}.
482

Glenn Morris's avatar
Glenn Morris committed
483
@menu
484 485 486 487
* Starting GUD::        How to start a debugger subprocess.
* Debugger Operation::  Connection between the debugger and source buffers.
* Commands of GUD::     Key bindings for common commands.
* GUD Customization::   Defining your own commands for GUD.
488
* GDB Graphical Interface::  An enhanced mode that uses GDB features to
Glenn Morris's avatar
Glenn Morris committed
489
                        implement a graphical debugging environment.
Glenn Morris's avatar
Glenn Morris committed
490 491 492
@end menu

@node Starting GUD
493
@subsection Starting GUD
Glenn Morris's avatar
Glenn Morris committed
494

495
  There are several commands for starting a debugger subprocess, each
Chong Yidong's avatar
Chong Yidong committed
496
corresponding to a particular debugger program.
Glenn Morris's avatar
Glenn Morris committed
497 498

@table @kbd
499
@item M-x gdb
500
@findex gdb
501 502 503
Run GDB as a subprocess, and interact with it via an IDE-like Emacs
interface.  @xref{GDB Graphical Interface}, for more information about
this command.
504

505
@item M-x gud-gdb
506
@findex gud-gdb
507 508 509
Run GDB, using a GUD interaction buffer for input and output to the
GDB subprocess (@pxref{Debugger Operation}).  If such a buffer already
exists, switch to it; otherwise, create the buffer and switch to it.
Glenn Morris's avatar
Glenn Morris committed
510

511 512
The other commands in this list do the same, for other debugger
programs.
Glenn Morris's avatar
Glenn Morris committed
513

514
@item M-x perldb
Glenn Morris's avatar
Glenn Morris committed
515
@findex perldb
516
Run the Perl interpreter in debug mode.
Glenn Morris's avatar
Glenn Morris committed
517

518
@item M-x jdb
Glenn Morris's avatar
Glenn Morris committed
519
@findex jdb
520
Run the Java debugger.
Glenn Morris's avatar
Glenn Morris committed
521

522
@item M-x pdb
Glenn Morris's avatar
Glenn Morris committed
523
@findex pdb
524 525 526 527 528 529 530 531 532 533 534 535 536 537
Run the Python debugger.

@item M-x dbx
@findex dbx
Run the DBX debugger.

@item M-x xdb
@findex xdb
@vindex gud-xdb-directories
Run the XDB debugger.

@item M-x sdb
@findex sdb
Run the SDB debugger.
Glenn Morris's avatar
Glenn Morris committed
538 539
@end table

540 541 542 543 544 545 546
  Each of these commands reads a command line to invoke the debugger,
using the minibuffer.  The minibuffer's initial contents contain the
standard executable name and options for the debugger, and sometimes
also a guess for the name of the executable file you want to debug.
Shell wildcards and variables are not allowed in this command line.
Emacs assumes that the first command argument which does not start
with a @samp{-} is the executable file name.
Glenn Morris's avatar
Glenn Morris committed
547

Chong Yidong's avatar
Chong Yidong committed
548
@cindex remote host, debugging on
549 550 551 552 553 554 555
  Tramp provides a facility for remote debugging, whereby both the
debugger and the program being debugged are on the same remote host.
@xref{Running a debugger on a remote host,,, tramp, The Tramp Manual},
for details.  This is separate from GDB's remote debugging feature,
where the program and the debugger run on different machines
(@pxref{Remote Debugging,, Debugging Remote Programs, gdb, The GNU
debugger}).
Glenn Morris's avatar
Glenn Morris committed
556 557

@node Debugger Operation
558
@subsection Debugger Operation
559
@cindex GUD interaction buffer
Glenn Morris's avatar
Glenn Morris committed
560

561 562 563 564 565 566
  The @dfn{GUD interaction buffer} is an Emacs buffer which is used to
send text commands to a debugger subprocess, and record its output.
This is the basic interface for interacting with a debugger, used by
@kbd{M-x gud-gdb} and other commands listed in
@iftex
the preceding section.
567
@end iftex
568 569 570 571 572 573 574 575 576 577 578 579 580 581
@ifnottex
@ref{Starting GUD}.
@end ifnottex
The @kbd{M-x gdb} command extends this interface with additional
specialized buffers for controlling breakpoints, stack frames, and
other aspects of the debugger state (@pxref{GDB Graphical Interface}).

  The GUD interaction buffer uses a variant of Shell mode, so the
Emacs commands defined by Shell mode are available (@pxref{Shell
Mode}).  Completion is available for most debugger commands
(@pxref{Completion}), and you can use the usual Shell mode history
commands to repeat them.
@iftex
See the next section
582
@end iftex
583 584 585 586 587 588 589
@ifnottex
@xref{Commands of GUD},
@end ifnottex
for special commands that can be used in the GUD interaction buffer.

  As you debug a program, Emacs displays the relevant source files by
visiting them in Emacs buffers, with an arrow in the left fringe
590 591 592 593 594 595
indicating the current execution line.  (On a text terminal, the arrow
appears as @samp{=>}, overlaid on the first two text columns.)  Moving
point in such a buffer does not move the arrow.  You are free to edit
these source files, but note that inserting or deleting lines will
throw off the arrow's positioning, as Emacs has no way to figure out
which edited source line corresponds to the line reported by the
596 597 598 599 600 601
debugger subprocess.  To update this information, you typically have
to recompile and restart the program.

@cindex GUD Tooltip mode
@cindex mode, GUD Tooltip
@findex gud-tooltip-mode
Glenn Morris's avatar
Glenn Morris committed
602
@vindex gud-tooltip-echo-area
603
  GUD Tooltip mode is a global minor mode that adds tooltip support to
604
GUD@.  To toggle this mode, type @kbd{M-x gud-tooltip-mode}.  It is
605
disabled by default.  If enabled, you can move the mouse cursor over a
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
variable, a function, or a macro (collectively called
@dfn{identifiers}) to show their values in tooltips
(@pxref{Tooltips}).  Alternatively, mark an identifier or an
expression by dragging the mouse over it, then leave the mouse in the
marked area to have the value of the expression displayed in a
tooltip.  The GUD Tooltip mode takes effect in the GUD interaction
buffer, and in all source buffers with major modes listed in the
variable @code{gud-tooltip-modes}.  If the variable
@code{gud-tooltip-echo-area} is non-@code{nil}, or if you turned off
the tooltip mode, values are shown in the echo area instead of a
tooltip.

  When using GUD Tooltip mode with @kbd{M-x gud-gdb}, displaying an
expression's value in GDB can sometimes expand a macro, potentially
causing side effects in the debugged program.  For that reason, using
tooltips in @code{gud-gdb} is disabled.  If you use the @kbd{M-x gdb}
interface, this problem does not occur, as there is special code to
avoid side-effects; furthermore, you can display macro definitions
associated with an identifier when the program is not executing.
Glenn Morris's avatar
Glenn Morris committed
625 626

@node Commands of GUD
627
@subsection Commands of GUD
Glenn Morris's avatar
Glenn Morris committed
628

629 630
  GUD provides commands for setting and clearing breakpoints,
selecting stack frames, and stepping through the program.
Glenn Morris's avatar
Glenn Morris committed
631 632

@table @kbd
633 634
@item C-x C-a C-b
@kindex C-x C-a C-b
Glenn Morris's avatar
Glenn Morris committed
635 636 637
Set a breakpoint on the source line that point is on.
@end table

638
  @kbd{C-x C-a C-b} (@code{gud-break}), when called in a source
639
buffer, sets a debugger breakpoint on the current source line.  This
640
command is available only after starting GUD@.  If you call it in a
641 642 643
buffer that is not associated with any debugger subprocess, it signals
a error.

Glenn Morris's avatar
Glenn Morris committed
644
@kindex C-x C-a @r{(GUD)}
645 646
  The following commands are available both in the GUD interaction
buffer and globally, but with different key bindings.  The keys
Glenn Morris's avatar
Glenn Morris committed
647
starting with @kbd{C-c} are available only in the GUD interaction
648 649 650
buffer, while those starting with @kbd{C-x C-a} are available
globally.  Some of these commands are also available via the tool bar;
some are not supported by certain debuggers.
Glenn Morris's avatar
Glenn Morris committed
651 652 653 654 655 656

@table @kbd
@item C-c C-l
@kindex C-c C-l @r{(GUD)}
@itemx C-x C-a C-l
@findex gud-refresh
657 658
Display, in another window, the last source line referred to in the
GUD interaction buffer (@code{gud-refresh}).
Glenn Morris's avatar
Glenn Morris committed
659 660 661 662 663

@item C-c C-s
@kindex C-c C-s @r{(GUD)}
@itemx C-x C-a C-s
@findex gud-step
664 665 666
Execute the next single line of code (@code{gud-step}).  If the line
contains a function call, execution stops after entering the called
function.
Glenn Morris's avatar
Glenn Morris committed
667 668 669 670 671

@item C-c C-n
@kindex C-c C-n @r{(GUD)}
@itemx C-x C-a C-n
@findex gud-next
672 673
Execute the next single line of code, stepping across function calls
without stopping inside the functions (@code{gud-next}).
Glenn Morris's avatar
Glenn Morris committed
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

@item C-c C-i
@kindex C-c C-i @r{(GUD)}
@itemx C-x C-a C-i
@findex gud-stepi
Execute a single machine instruction (@code{gud-stepi}).

@item C-c C-p
@kindex C-c C-p @r{(GUD)}
@itemx C-x C-a C-p
@findex gud-print
Evaluate the expression at point (@code{gud-print}).  If Emacs
does not print the exact expression that you want, mark it as a region
first.

@need 3000
@item C-c C-r
@kindex C-c C-r @r{(GUD)}
@itemx C-x C-a C-r
@findex gud-cont
Continue execution without specifying any stopping point.  The program
will run until it hits a breakpoint, terminates, or gets a signal that
the debugger is checking for (@code{gud-cont}).

@need 1000
@item C-c C-d
@kindex C-c C-d @r{(GUD)}
@itemx C-x C-a C-d
@findex gud-remove
Delete the breakpoint(s) on the current source line, if any
(@code{gud-remove}).  If you use this command in the GUD interaction
buffer, it applies to the line where the program last stopped.

@item C-c C-t
@kindex C-c C-t @r{(GUD)}
@itemx C-x C-a C-t
@findex gud-tbreak
Set a temporary breakpoint on the current source line, if any
(@code{gud-tbreak}).  If you use this command in the GUD interaction
buffer, it applies to the line where the program last stopped.

@item C-c <
@kindex C-c < @r{(GUD)}
@itemx C-x C-a <
@findex gud-up
Select the next enclosing stack frame (@code{gud-up}).  This is
equivalent to the GDB command @samp{up}.

@item C-c >
@kindex C-c > @r{(GUD)}
@itemx C-x C-a >
@findex gud-down
Select the next inner stack frame (@code{gud-down}).  This is
equivalent to the GDB command @samp{down}.

@item C-c C-u
@kindex C-c C-u @r{(GUD)}
@itemx C-x C-a C-u
@findex gud-until
Continue execution to the current line (@code{gud-until}).  The
program will run until it hits a breakpoint, terminates, gets a signal
that the debugger is checking for, or reaches the line on which the
cursor currently sits.

@item C-c C-f
@kindex C-c C-f @r{(GUD)}
@itemx C-x C-a C-f
@findex gud-finish
Run the program until the selected stack frame returns or
stops for some other reason (@code{gud-finish}).
@end table

  If you are using GDB, these additional key bindings are available:

@table @kbd
@item C-x C-a C-j
@kindex C-x C-a C-j @r{(GUD)}
@findex gud-jump
Only useful in a source buffer, @code{gud-jump} transfers the
program's execution point to the current line.  In other words, the
next line that the program executes will be the one where you gave the
command.  If the new execution line is in a different function from
the previously one, GDB prompts for confirmation since the results may
be bizarre.  See the GDB manual entry regarding @code{jump} for
details.

@item @key{TAB}
@kindex TAB @r{(GUD)}
@findex gud-gdb-complete-command
With GDB, complete a symbol name (@code{gud-gdb-complete-command}).
This key is available only in the GUD interaction buffer.
@end table

  These commands interpret a numeric argument as a repeat count, when
that makes sense.

  Because @key{TAB} serves as a completion command, you can't use it to
771
enter a tab as input to the program you are debugging with GDB@.
Glenn Morris's avatar
Glenn Morris committed
772 773 774
Instead, type @kbd{C-q @key{TAB}} to enter a tab.

@node GUD Customization
775
@subsection GUD Customization
Glenn Morris's avatar
Glenn Morris committed
776 777 778 779 780 781 782 783

@vindex gdb-mode-hook
@vindex dbx-mode-hook
@vindex sdb-mode-hook
@vindex xdb-mode-hook
@vindex perldb-mode-hook
@vindex pdb-mode-hook
@vindex jdb-mode-hook
784 785 786 787 788
  On startup, GUD runs one of the following hooks:
@code{gdb-mode-hook}, if you are using GDB; @code{dbx-mode-hook}, if
you are using DBX; @code{sdb-mode-hook}, if you are using SDB;
@code{xdb-mode-hook}, if you are using XDB; @code{perldb-mode-hook},
for Perl debugging mode; @code{pdb-mode-hook}, for PDB;
789
@code{jdb-mode-hook}, for JDB@.  @xref{Hooks}.
790 791 792 793 794

  The @code{gud-def} Lisp macro (@pxref{Defining Macros,,, elisp, the
Emacs Lisp Reference Manual}) provides a convenient way to define an
Emacs command that sends a particular command string to the debugger,
and set up a key binding for in the GUD interaction buffer:
Glenn Morris's avatar
Glenn Morris committed
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814

@findex gud-def
@example
(gud-def @var{function} @var{cmdstring} @var{binding} @var{docstring})
@end example

  This defines a command named @var{function} which sends
@var{cmdstring} to the debugger process, and gives it the documentation
string @var{docstring}.  You can then use the command @var{function} in any
buffer.  If @var{binding} is non-@code{nil}, @code{gud-def} also binds
the command to @kbd{C-c @var{binding}} in the GUD buffer's mode and to
@kbd{C-x C-a @var{binding}} generally.

  The command string @var{cmdstring} may contain certain
@samp{%}-sequences that stand for data to be filled in at the time
@var{function} is called:

@table @samp
@item %f
The name of the current source file.  If the current buffer is the GUD
Paul Eggert's avatar
Paul Eggert committed
815
buffer, then the current source file is the file that the program
Glenn Morris's avatar
Glenn Morris committed
816 817 818 819
stopped in.

@item %l
The number of the current source line.  If the current buffer is the GUD
Paul Eggert's avatar
Paul Eggert committed
820
buffer, then the current source line is the line that the program
Glenn Morris's avatar
Glenn Morris committed
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
stopped in.

@item %e
In transient-mark-mode the text in the region, if it is active.
Otherwise the text of the C lvalue or function-call expression at or
adjacent to point.

@item %a
The text of the hexadecimal address at or adjacent to point.

@item %p
The numeric argument of the called function, as a decimal number.  If
the command is used without a numeric argument, @samp{%p} stands for the
empty string.

If you don't use @samp{%p} in the command string, the command you define
ignores any numeric argument.

@item %d
The name of the directory of the current source file.

@item %c
Fully qualified class name derived from the expression surrounding point
(jdb only).
@end table

@node GDB Graphical Interface
@subsection GDB Graphical Interface

850 851 852 853 854
  The command @kbd{M-x gdb} starts GDB in an IDE-like interface, with
specialized buffers for controlling breakpoints, stack frames, and
other aspects of the debugger state.  It also provides additional ways
to control the debugging session with the mouse, such as clicking in
the fringe of a source buffer to set a breakpoint there.
Glenn Morris's avatar
Glenn Morris committed
855 856

@vindex gud-gdb-command-name
857 858 859 860 861 862
  To run GDB using just the GUD interaction buffer interface, without
these additional features, use @kbd{M-x gud-gdb} (@pxref{Starting
GUD}).  You must use this if you want to debug multiple programs
within one Emacs session, as that is currently unsupported by @kbd{M-x
gdb}.

Paul Eggert's avatar
Paul Eggert committed
863
  Internally, @kbd{M-x gdb} informs GDB that its screen size is
864 865
unlimited; for correct operation, you must not change GDB's screen
height and width values during the debugging session.
Glenn Morris's avatar
Glenn Morris committed
866 867

@menu
868
* GDB User Interface Layout::   Control the number of displayed buffers.
Glenn Morris's avatar
Glenn Morris committed
869 870 871
* Source Buffers::              Use the mouse in the fringe/margin to
                                control your program.
* Breakpoints Buffer::          A breakpoint control panel.
872
* Threads Buffer::              Displays your threads.
Glenn Morris's avatar
Glenn Morris committed
873
* Stack Buffer::                Select a frame from the call stack.
874
* Other GDB Buffers::           Other buffers for controlling the GDB state.
Glenn Morris's avatar
Glenn Morris committed
875
* Watch Expressions::           Monitor variable values in the speedbar.
876
* Multithreaded Debugging::     Debugging programs with several threads.
Glenn Morris's avatar
Glenn Morris committed
877 878
@end menu

879
@node GDB User Interface Layout
Glenn Morris's avatar
Glenn Morris committed
880 881 882 883
@subsubsection GDB User Interface Layout
@cindex GDB User Interface layout

@vindex gdb-many-windows
884 885
  If the variable @code{gdb-many-windows} is @code{nil} (the default),
@kbd{M-x gdb} normally displays only the GUD interaction buffer.
Glenn Morris's avatar
Glenn Morris committed
886
However, if the variable @code{gdb-show-main} is also non-@code{nil},
887 888 889
it starts with two windows: one displaying the GUD interaction buffer,
and the other showing the source for the @code{main} function of the
program you are debugging.
Glenn Morris's avatar
Glenn Morris committed
890 891 892 893 894 895 896

  If @code{gdb-many-windows} is non-@code{nil}, then @kbd{M-x gdb}
displays the following frame layout:

@smallexample
@group
+--------------------------------+--------------------------------+
897
|   GUD interaction buffer       |   Locals/Registers buffer      |
Glenn Morris's avatar
Glenn Morris committed
898 899 900
|--------------------------------+--------------------------------+
|   Primary Source buffer        |   I/O buffer for debugged pgm  |
|--------------------------------+--------------------------------+
901
|   Stack buffer                 |   Breakpoints/Threads buffer   |
Glenn Morris's avatar
Glenn Morris committed
902 903 904 905 906 907
+--------------------------------+--------------------------------+
@end group
@end smallexample

@findex gdb-restore-windows
@findex gdb-many-windows
Paul Eggert's avatar
Paul Eggert committed
908 909
  If you ever change the window layout, you can restore the many-windows
layout by typing @kbd{M-x gdb-restore-windows}.  To toggle
910 911
between the many windows layout and a simple layout with just the GUD
interaction buffer and a source file, type @kbd{M-x gdb-many-windows}.
Glenn Morris's avatar
Glenn Morris committed
912 913 914

  You may also specify additional GDB-related buffers to display,
either in the same frame or a different one.  Select the buffers you
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
want by typing @code{M-x gdb-display-@var{buffertype}-buffer} or
@code{M-x gdb-frame-@var{buffertype}-buffer}, where @var{buffertype}
is the relevant buffer type, such as @samp{breakpoints}.  You can do
the same with the menu bar, with the @samp{GDB-Windows} and
@samp{GDB-Frames} sub-menus of the @samp{GUD} menu.

  When you finish debugging, kill the GUD interaction buffer with
@kbd{C-x k}, which will also kill all the buffers associated with the
session.  However you need not do this if, after editing and
re-compiling your source code within Emacs, you wish to continue
debugging.  When you restart execution, GDB automatically finds the
new executable.  Keeping the GUD interaction buffer has the advantage
of keeping the shell history as well as GDB's breakpoints.  You do
need to check that the breakpoints in recently edited source files are
still in the right places.
Glenn Morris's avatar
Glenn Morris committed
930 931 932

@node Source Buffers
@subsubsection Source Buffers
933
@cindex fringes, for debugging
Glenn Morris's avatar
Glenn Morris committed
934

935
@table @asis
936
@item @kbd{mouse-1} (in fringe)
937
Set or clear a breakpoint on that line.
Glenn Morris's avatar
Glenn Morris committed
938

939
@item @kbd{C-mouse-1} (in fringe)
940
Enable or disable a breakpoint on that line.
Glenn Morris's avatar
Glenn Morris committed
941

942
@item @kbd{mouse-3} (in fringe)
943
Continue execution to that line.
Glenn Morris's avatar
Glenn Morris committed
944

945
@item @kbd{C-mouse-3} (in fringe)
946
Jump to that line.
Glenn Morris's avatar
Glenn Morris committed
947 948
@end table

949
  On a graphical display, you can click @kbd{mouse-1} in the fringe of
950 951
a source buffer, to set a breakpoint on that line (@pxref{Fringes}).
A red dot appears in the fringe, where you clicked.  If a breakpoint
952
already exists there, the click removes it.  A @kbd{C-mouse-1} click
953 954 955
enables or disables an existing breakpoint; a breakpoint that is
disabled, but not unset, is indicated by a gray dot.

956
  On a text terminal, or when fringes are disabled, enabled
957 958 959 960 961
breakpoints are indicated with a @samp{B} character in the left margin
of the window.  Disabled breakpoints are indicated with @samp{b}.
(The margin is only displayed if a breakpoint is present.)

  A solid arrow in the left fringe of a source buffer indicates the
962
line of the innermost frame where the debugged program has stopped.  A
963
hollow arrow indicates the current execution line of a higher-level
964
frame.  If you drag the arrow in the fringe with @kbd{mouse-1}, that
965
causes execution to advance to the line where you release the button.
966 967
Alternatively, you can click @kbd{mouse-3} in the fringe to advance to
that line.  You can click @kbd{C-mouse-3} in the fringe to jump to
968 969 970 971
that line without executing the intermediate lines.  This command
allows you to go backwards, which can be useful for running through
code that has already executed, in order to examine its execution in
more detail.
Glenn Morris's avatar
Glenn Morris committed
972 973 974 975

@node Breakpoints Buffer
@subsubsection Breakpoints Buffer

976 977 978 979
  The GDB Breakpoints buffer shows the breakpoints, watchpoints and
catchpoints in the debugger session.  @xref{Breakpoints,,, gdb, The
GNU debugger}.  It provides the following commands, which mostly apply
to the @dfn{current breakpoint} (the breakpoint which point is on):
Glenn Morris's avatar
Glenn Morris committed
980 981 982

@table @kbd
@item @key{SPC}
983
@kindex SPC @r{(GDB Breakpoints buffer)}
Glenn Morris's avatar
Glenn Morris committed
984
@findex gdb-toggle-breakpoint
985 986 987 988
Enable/disable current breakpoint (@code{gdb-toggle-breakpoint}).  On
a graphical display, this changes the color of the dot in the fringe
of the source buffer at that line.  The dot is red when the breakpoint
is enabled, and gray when it is disabled.
Glenn Morris's avatar
Glenn Morris committed
989 990

@item D
991
@kindex D @r{(GDB Breakpoints buffer)}
Glenn Morris's avatar
Glenn Morris committed
992 993 994 995
@findex gdb-delete-breakpoint
Delete the current breakpoint (@code{gdb-delete-breakpoint}).

@item @key{RET}
996
@kindex RET @r{(GDB Breakpoints buffer)}
Glenn Morris's avatar
Glenn Morris committed
997 998 999 1000
@findex gdb-goto-breakpoint
Visit the source line for the current breakpoint
(@code{gdb-goto-breakpoint}).

1001 1002
@item mouse-2
@kindex mouse-2 @r{(GDB Breakpoints buffer)}
Glenn Morris's avatar
Glenn Morris committed
1003 1004 1005
Visit the source line for the breakpoint you click on.
@end table

1006
@vindex gdb-show-threads-by-default
1007 1008
  When @code{gdb-many-windows} is non-@code{nil}, the GDB Breakpoints
buffer shares its window with the GDB Threads buffer.  To switch from
1009
one to the other click with @kbd{mouse-1} on the relevant button in
1010 1011
the header line.  If @code{gdb-show-threads-by-default} is
non-@code{nil}, the GDB Threads buffer is the one shown by default.
1012 1013 1014 1015 1016

@node Threads Buffer
@subsubsection Threads Buffer

@findex gdb-select-thread
1017 1018 1019
  The GDB Threads buffer displays a summary of the threads in the
debugged program.  @xref{Threads, Threads, Debugging programs with
multiple threads, gdb, The GNU debugger}.  To select a thread, move
1020
point there and press @key{RET} (@code{gdb-select-thread}), or click on
1021
it with @kbd{mouse-2}.  This also displays the associated source
1022
buffer, and updates the contents of the other GDB buffers.
1023 1024

  You can customize variables under @code{gdb-buffers} group to select
1025
fields included in GDB Threads buffer.
1026 1027 1028 1029

@table @code
@item gdb-thread-buffer-verbose-names
@vindex gdb-thread-buffer-verbose-names
1030
Show long thread names like @samp{Thread 0x4e2ab70 (LWP 1983)}.
1031 1032 1033

@item gdb-thread-buffer-arguments
@vindex gdb-thread-buffer-arguments
1034
Show arguments of thread top frames.
1035 1036 1037

@item gdb-thread-buffer-locations
@vindex gdb-thread-buffer-locations
1038
Show file information or library names.
1039 1040 1041 1042 1043 1044

@item gdb-thread-buffer-addresses
@vindex gdb-thread-buffer-addresses
Show addresses for thread frames in threads buffer.
@end table

1045 1046
  To view information for several threads simultaneously, use the
following commands from the GDB Threads buffer.
1047 1048 1049 1050 1051

@table @kbd
@item d
@kindex d @r{(GDB threads buffer)}
@findex gdb-display-disassembly-for-thread
1052 1053
Display disassembly buffer for the thread at current line
(@code{gdb-display-disassembly-for-thread}).
1054 1055 1056 1057

@item f
@kindex f @r{(GDB threads buffer)}
@findex gdb-display-stack-for-thread
1058
Display the GDB Stack buffer for the thread at current line
1059 1060 1061 1062 1063
(@code{gdb-display-stack-for-thread}).

@item l
@kindex l @r{(GDB threads buffer)}
@findex gdb-display-locals-for-thread
1064
Display the GDB Locals buffer for the thread at current line
1065 1066 1067 1068 1069
(@code{gdb-display-locals-for-thread}).

@item r
@kindex r @r{(GDB threads buffer)}
@findex gdb-display-registers-for-thread
1070
Display the GDB Registers buffer for the thread at current line
1071 1072 1073
(@code{gdb-display-registers-for-thread}).
@end table

1074 1075 1076
@noindent
Their upper-case counterparts, @kbd{D}, @kbd{F} ,@kbd{L} and @kbd{R},
display the corresponding buffer in a new frame.
1077 1078 1079

  When you create a buffer showing information about some specific
thread, it becomes bound to that thread and keeps showing actual
1080 1081 1082 1083
information while you debug your program.  The mode indicator for each
GDB buffer shows the number of thread it is showing information about.
The thread number is also included in the buffer name of bound
buffers.
1084

1085 1086 1087
  Further commands are available in the GDB Threads buffer which
depend on the mode of GDB that is used for controlling execution of
your program.  @xref{Multithreaded Debugging}.
1088

Glenn Morris's avatar
Glenn Morris committed
1089 1090 1091
@node Stack Buffer
@subsubsection Stack Buffer

1092 1093 1094 1095
  The GDB Stack buffer displays a @dfn{call stack}, with one line for
each of the nested subroutine calls (@dfn{stack frames}) in the
debugger session.  @xref{Backtrace,, Backtraces, gdb, The GNU
debugger}.
Glenn Morris's avatar
Glenn Morris committed
1096 1097

@findex gdb-frames-select
1098
  On graphical displays, the selected stack frame is indicated by an
1099 1100 1101
arrow in the fringe.  On text terminals, or when fringes are disabled,
the selected stack frame is displayed in reverse contrast.  To select
a stack frame, move point in its line and type @key{RET}
1102
(@code{gdb-frames-select}), or click @kbd{mouse-2} on it.  Doing so
1103 1104 1105 1106 1107 1108 1109
also updates the Locals buffer
@ifnottex
(@pxref{Other GDB Buffers}).
@end ifnottex
@iftex
(described in the next section).
@end iftex
Glenn Morris's avatar
Glenn Morris committed
1110

1111
@node Other GDB Buffers
1112
@subsubsection Other GDB Buffers
Glenn Morris's avatar
Glenn Morris committed
1113 1114 1115

@table @asis
@item Locals Buffer
1116 1117
This buffer displays the values of local variables of the current
frame for simple data types (@pxref{Frame Info, Frame Info,
1118
Information on a frame, gdb, The GNU debugger}).  Press @key{RET} or
1119
click @kbd{mouse-2} on the value if you want to edit it.
Glenn Morris's avatar
Glenn Morris committed
1120 1121

Arrays and structures display their type only.  With GDB 6.4 or later,
1122
you can examine the value of the local variable at point by typing
1123 1124
@key{RET}, or with a @kbd{mouse-2} click.  With earlier versions of
GDB, use @key{RET} or @kbd{mouse-2} on the type description
Glenn Morris's avatar
Glenn Morris committed
1125 1126 1127 1128
(@samp{[struct/union]} or @samp{[array]}).  @xref{Watch Expressions}.

@item Registers Buffer
@findex toggle-gdb-all-registers
1129
This buffer displays the values held by the registers
Glenn Morris's avatar
Glenn Morris committed
1130
(@pxref{Registers,,, gdb, The GNU debugger}).  Press @key{RET} or
1131
click @kbd{mouse-2} on a register if you want to edit its value.  With
1132 1133
GDB 6.4 or later, recently changed register values display with
@code{font-lock-warning-face}.
Glenn Morris's avatar
Glenn Morris committed
1134

1135 1136
@item Assembler Buffer
The assembler buffer displays the current frame as machine code.  An
Glenn Morris's avatar
Glenn Morris committed
1137 1138 1139 1140 1141 1142 1143
arrow points to the current instruction, and you can set and remove
breakpoints as in a source buffer.  Breakpoint icons also appear in
the fringe or margin.

@item Memory Buffer
The memory buffer lets you examine sections of program memory
(@pxref{Memory, Memory, Examining memory, gdb, The GNU debugger}).
1144
Click @kbd{mouse-1} on the appropriate part of the header line to
Glenn Morris's avatar
Glenn Morris committed
1145
change the starting address or number of data items that the buffer
1146
displays.  Alternatively, use @kbd{S} or @kbd{N} respectively.  Click
1147
@kbd{mouse-3} on the header line to select the display format or unit
1148
size for these data items.
Glenn Morris's avatar
Glenn Morris committed
1149 1150
@end table

1151
When @code{gdb-many-windows} is non-@code{nil}, the locals buffer
1152
shares its window with the registers buffer, just like breakpoints and
1153
threads buffers.  To switch from one to the other, click with
1154
@kbd{mouse-1} on the relevant button in the header line.
1155

Glenn Morris's avatar
Glenn Morris committed
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167
@node Watch Expressions
@subsubsection Watch Expressions
@cindex Watching expressions in GDB

@findex gud-watch
@kindex C-x C-a C-w @r{(GUD)}
  If you want to see how a variable changes each time your program
stops, move point into the variable name and click on the watch icon
in the tool bar (@code{gud-watch}) or type @kbd{C-x C-a C-w}.  If you
specify a prefix argument, you can enter the variable name in the
minibuffer.

1168 1169 1170 1171 1172 1173 1174 1175 1176
  Each watch expression is displayed in the speedbar
(@pxref{Speedbar}).  Complex data types, such as arrays, structures
and unions are represented in a tree format.  Leaves and simple data
types show the name of the expression and its value and, when the
speedbar frame is selected, display the type as a tooltip.  Higher
levels show the name, type and address value for pointers and just the
name and type otherwise.  Root expressions also display the frame
address as a tooltip to help identify the frame in which they were
defined.
Glenn Morris's avatar
Glenn Morris committed
1177

1178
  To expand or contract a complex data type, click @kbd{mouse-2} or
Glenn Morris's avatar
Glenn Morris committed
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
press @key{SPC} on the tag to the left of the expression.  Emacs asks
for confirmation before expanding the expression if its number of
immediate children exceeds the value of the variable
@code{gdb-max-children}.

@kindex D @r{(GDB speedbar)}
@findex gdb-var-delete
  To delete a complex watch expression, move point to the root
expression in the speedbar and type @kbd{D} (@code{gdb-var-delete}).

@kindex RET @r{(GDB speedbar)}
@findex gdb-edit-value
  To edit a variable with a simple data type, or a simple element of a
complex data type, move point there in the speedbar and type @key{RET}
1193
(@code{gdb-edit-value}).  Or you can click @kbd{mouse-2} on a value to
Glenn Morris's avatar
Glenn Morris committed
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203
edit it.  Either way, this reads the new value using the minibuffer.

@vindex gdb-show-changed-values
  If you set the variable @code{gdb-show-changed-values} to
non-@code{nil} (the default value), Emacs uses
@code{font-lock-warning-face} to highlight values that have recently
changed and @code{shadow} face to make variables which have gone out of
scope less noticeable.  When a variable goes out of scope you can't
edit its value.

1204