]> code.delx.au - gnu-emacs/blobdiff - man/building.texi
(Optional Mode Line): Document `size-indication-mode'.
[gnu-emacs] / man / building.texi
index 239a5b5a43c060addd352615ad56478d3e02777d..d28917ada2242b22b4d971e809ff9c1793ef12dd 100644 (file)
@@ -1,7 +1,7 @@
 @c This is part of the Emacs manual.
-@c Copyright (C) 1985, 86, 87, 93, 94, 95, 97, 2000 Free Software Foundation, Inc.
+@c Copyright (C) 1985,86,87,93,94,95,97,2000,2001 Free Software Foundation, Inc.
 @c See file emacs.texi for copying conditions.
-@node Building, Abbrevs, Programs, Top
+@node Building, Maintaining, Programs, Top
 @chapter Compiling and Testing Programs
 @cindex building programs
 @cindex program building
@@ -18,14 +18,14 @@ in the larger process of developing and maintaining programs.
 * Compilation Mode::    The mode for visiting compiler errors.
 * Compilation Shell::   Customizing your shell properly
                           for use in the compilation buffer.
-* Debuggers::          Running symbolic debuggers for non-Lisp programs. 
-* Executing Lisp::      Various modes for editing Lisp programs, 
+* Debuggers::          Running symbolic debuggers for non-Lisp programs.
+* Executing Lisp::      Various modes for editing Lisp programs,
                           with different facilities for running
-                          the Lisp programs. 
+                          the Lisp programs.
 * Libraries: Lisp Libraries.      Creating Lisp programs to run in Emacs.
 * Interaction: Lisp Interaction.  Executing Lisp in an Emacs buffer.
 * Eval: Lisp Eval.      Executing a single Lisp expression in Emacs.
-* External Lisp::         Communicating through Emacs with a separate Lisp. 
+* External Lisp::         Communicating through Emacs with a separate Lisp.
 @end menu
 
 @node Compilation
@@ -42,8 +42,11 @@ compilation errors occurred.
 
 @table @kbd
 @item M-x compile
-Run a compiler asynchronously under Emacs, with error messages to
-@samp{*compilation*} buffer.
+Run a compiler asynchronously under Emacs, with error messages going to
+the @samp{*compilation*} buffer.
+@item M-x recompile
+Invoke a compiler with the same command as in the last invocation of
+@kbd{M-x compile}.
 @item M-x grep
 Run @code{grep} asynchronously under Emacs, with matching lines
 listed in the buffer named @samp{*grep*}.
@@ -65,11 +68,13 @@ command; normally, therefore, the compilation happens in this
 directory.
 
 @vindex compile-command
-  When the shell command line is read, the minibuffer appears containing
-a default command line, which is the command you used the last time you
-did @kbd{M-x compile}.  If you type just @key{RET}, the same command
-line is used again.  For the first @kbd{M-x compile}, the default is
-@samp{make -k}.  The default compilation command comes from the variable
+  When the shell command line is read, the minibuffer appears
+containing a default command line, which is the command you used the
+last time you did @kbd{M-x compile}.  If you type just @key{RET}, the
+same command line is used again.  For the first @kbd{M-x compile}, the
+default is @samp{make -k}, which is correct most of the time for
+nontrivial programs.  (@xref{Top,, Make, make, GNU Make Manual}.)
+The default compilation command comes from the variable
 @code{compile-command}; if the appropriate compilation command for a
 file is something other than @samp{make -k}, it can be useful for the
 file to specify a local value for @code{compile-command} (@pxref{File
@@ -97,13 +102,31 @@ non-@code{nil} value, then the compilation buffer always scrolls to
 follow output as it comes in.
 
 @findex kill-compilation
-  To kill the compilation process, do @kbd{M-x kill-compilation}.  When
-the compiler process terminates, the mode line of the
-@samp{*compilation*} buffer changes to say @samp{signal} instead of
-@samp{run}.  Starting a new compilation also kills any running
-compilation, as only one can exist at any time.  However, @kbd{M-x
-compile} asks for confirmation before actually killing a compilation
-that is running.
+  When the compiler process terminates, for whatever reason, the mode
+line of the @samp{*compilation*} buffer changes to say @samp{signal}
+instead of @samp{run}.  Starting a new compilation also kills any
+running compilation, as only one can exist at any time.  However,
+@kbd{M-x compile} asks for confirmation before actually killing a
+compilation that is running.  You can also kill the compilation
+process with @kbd{M-x kill-compilation}.
+
+@findex recompile
+  To rerun the last compilation with the same command, type @kbd{M-x
+recompile}.  This automatically reuses the compilation command from the
+last invocation of @kbd{M-x compile}.
+
+  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 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
 
 @node Grep Searching
 @section Searching with Grep under Emacs
@@ -161,9 +184,10 @@ Visit the locus of the error message that you click on.
 @kindex C-x `
 @findex next-error
   You can visit the source for any particular error message by moving
-point in @samp{*compilation*} to that error message and typing @key{RET}
-(@code{compile-goto-error}).  Or click @kbd{Mouse-2} on the error message;
-you need not switch to the @samp{*compilation*} buffer first.
+point in the @samp{*compilation*} buffer to that error message and
+typing @key{RET} (@code{compile-goto-error}).  Alternatively, you can
+click @kbd{Mouse-2} on the error message; you need not switch to the
+@samp{*compilation*} buffer first.
 
   To parse the compiler error messages sequentially, type @kbd{C-x `}
 (@code{next-error}).  The character following the @kbd{C-x} is the
@@ -183,6 +207,16 @@ an Emacs error.
   @kbd{C-u C-x `} starts scanning from the beginning of the compilation
 buffer.  This is one way to process the same set of errors again.
 
+@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
+formats of error messages and tells Emacs how to extract the source file
+and the line number from the text of a message.  If your compiler isn't
+supported, you can tailor Compilation mode to it by adding elements to
+that list.  A similar variable @code{grep-regexp-alist} tells Emacs how
+to parse output of a @code{grep} command.
+
   Compilation mode also redefines the keys @key{SPC} and @key{DEL} to
 scroll by screenfuls, and @kbd{M-n} and @kbd{M-p} to move to the next or
 previous error message.  You can also use @kbd{M-@{} and @kbd{M-@}} to
@@ -254,6 +288,8 @@ various symbolic debuggers from within Emacs.  We recommend the debugger
 GDB, which is free software, but you can also run DBX, SDB or XDB if you
 have them.  GUD can also serve as an interface to the Perl's debugging
 mode, the Python debugger PDB, and to JDB, the Java Debugger.
+@xref{Debugging,, The Lisp Debugger, elisp, the Emacs Lisp Reference Manual},
+for information on debugging Emacs Lisp programs.
 
 @menu
 * Starting GUD::       How to start a debugger subprocess.
@@ -261,6 +297,9 @@ mode, the Python debugger PDB, and to JDB, the Java Debugger.
 * Commands of GUD::    Key bindings for common commands.
 * GUD Customization::  Defining your own commands for GUD.
 * GUD Tooltips::        Showing variable values by pointing with the mouse.
+* GDB Graphical Interface::  An enhanced mode that uses GDB features to
+                        implement a graphical debugging environment through
+                        Emacs.
 @end menu
 
 @node Starting GUD
@@ -272,9 +311,13 @@ to a particular debugger program.
 @table @kbd
 @item M-x gdb @key{RET} @var{file} @key{RET}
 @findex gdb
-Run GDB as a subprocess of Emacs.  This command creates a buffer for
-input and output to GDB, and switches to it.  If a GDB buffer already
-exists, it just switches to that buffer.
+Run GDB as a subprocess of Emacs.  This command creates a buffer
+for input and output to GDB, and switches to it.  If a GDB buffer
+already exists, it just switches to that buffer.
+
+@item M-x gdba @key{RET} @var{file} @key{RET}
+Run GDB as a subprocess of Emacs, providing a graphical interface
+to GDB features through Emacs.  @xref{GDB Graphical Interface}.
 
 @item M-x dbx @key{RET} @var{file} @key{RET}
 @findex dbx
@@ -324,16 +367,17 @@ allowed.  GUD assumes that the first argument not starting with a
 @node Debugger Operation
 @subsection Debugger Operation
 
+@cindex fringes, and current execution line in GUD
   When you run a debugger with GUD, the debugger uses an Emacs buffer
 for its ordinary input and output.  This is called the GUD buffer.  The
 debugger displays the source files of the program by visiting them in
 Emacs buffers.  An arrow (@samp{=>}) in one of these buffers indicates
-the current execution line.@footnote{Under a window system the arrow is
-displayed in the marginal area of the Emacs window.}  Moving point in
-this buffer does not move the arrow.
+the current execution line.@footnote{Under a window system, the arrow
+appears in the left fringe of the Emacs window.}  Moving point in this
+buffer does not move the arrow.
 
   You can start editing these source files at any time in the buffers
-that were made to display them.  The arrow is not part of the file's
+that display them.  The arrow is not part of the file's
 text; it appears only on the screen.  If you do modify a source file,
 keep in mind that inserting or deleting lines will throw off the arrow's
 positioning; GUD has no way of figuring out which line corresponded
@@ -356,9 +400,9 @@ selecting stack frames, and for stepping through the program.  These
 commands are available both in the GUD buffer and globally, but with
 different key bindings.
 
-  The breakpoint commands are usually used in source file buffers,
-because that is the way to specify where to set or clear the breakpoint.
-Here's the global command to set a breakpoint:
+  The breakpoint commands are normally used in source file buffers,
+because that is the easiest way to specify where to set or clear the
+breakpoint.  Here's the global command to set a breakpoint:
 
 @table @kbd
 @item C-x @key{SPC}
@@ -450,6 +494,21 @@ equivalent to the @samp{down} command.
   If you are using GDB, these additional key bindings are available:
 
 @table @kbd
+@item C-c C-r
+@kindex C-c C-r @r{(GUD)}
+@itemx C-x C-a C-r
+@findex gud-run
+Start execution of the program (@code{gud-run}).
+
+@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. 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
+(@code{gud-until}).
+
 @item @key{TAB}
 @kindex TAB @r{(GUD)}
 @findex gud-gdb-complete-command
@@ -463,6 +522,17 @@ GDB versions 4.13 and later.
 @findex gud-finish
 Run the program until the selected stack frame returns (or until it
 stops for some other reason).
+
+@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.
 @end table
 
   These commands interpret a numeric argument as a repeat count, when
@@ -486,7 +556,7 @@ Instead, type @kbd{C-q @key{TAB}} to enter a tab.
 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{jdb-mode-hook}, for PDB; @code{jdb-mode-hook}, for JDB.  You can
+@code{pdb-mode-hook}, for PDB; @code{jdb-mode-hook}, for JDB.  You can
 use these hooks to define custom key bindings for the debugger
 interaction buffer.  @xref{Hooks}.
 
@@ -501,7 +571,7 @@ debugger interaction buffer:
 
   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 use the command thus defined in any
+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.
@@ -548,6 +618,188 @@ variable values can be displayed in tooltips by pointing at them with
 the mouse in the GUD buffer or in source buffers with major modes in the
 customizable list @code{tooltip-gud-modes}.
 
+@node GDB Graphical Interface
+@subsection GDB Graphical Interface
+
+@findex gdba
+The command @code{gdba} starts GDB using a graphical interface where
+you view and control the program's data using Emacs windows.  You can
+still interact with GDB through the GUD buffer, but the point of this
+mode is that you can do it through menus and clicks, without needing
+to know GDB commands.
+
+@menu
+* Breakpoints Buffer::   A breakpoint control panel.
+* Stack Buffer::         Select a frame from the call stack. 
+* Data Display::         Display and update expressions in their own buffer.
+* Display Buffer::       Control the displayed expressions.
+* Other Buffers::        Input/output, locals, registers and assembler buffers.
+* Layout::               Control the number of displayed buffers.
+@end menu
+
+@node Breakpoints Buffer
+@subsubsection Breakpoints Buffer
+
+The breakpoints buffer shows the existing breakpoints and watchpoints 
+(@pxref{Breakpoints,,, gdb, The GNU debugger}).  It has three special
+commands:
+
+@table @kbd
+@item @key{SPC} 
+@kindex SPC @r{(GDB breakpoints buffer)}
+@findex gdb-toggle-breakpoint
+Enable/disable the breakpoint at the current line
+(@code{gdb-toggle-breakpoint}).  On a graphical display, this changes
+the color of a bullet in the margin of the source buffer at the
+relevant line.  This is red when the breakpoint is enabled and grey
+when it is disabled.  Text-only terminals correspondingly display
+a @samp{B} or @samp{b}.
+
+@item @kbd{d}
+@kindex d @r{(GDB breakpoints buffer)}
+@findex gdb-delete-breakpoint
+Delete the breakpoint at the current line (@code{gdb-delete-breakpoint}).
+
+@item @key{RET}
+@kindex RET @r{(GDB breakpoints buffer)}
+@findex gdb-goto-breakpoint
+Display the file in the source buffer at the breakpoint specified at
+the current line (@code{gdb-goto-breakpoint}).  Alternatively, click @kbd{Mouse-2} on the breakpoint that you wish to visit.
+@end table
+
+@node Stack Buffer
+@subsubsection Stack Buffer
+
+The stack buffer displays a @dfn{call stack}, with one line for each
+of the nested subroutine calls (@dfn{stack frames}) now active in the
+program.  @xref{Backtrace,,info stack, gdb, The GNU debugger}.
+
+Move point to any frame in the stack and type @key{RET} to make it
+become the current frame (@code{gdb-frames-select}) and display the
+associated source in the source buffer.  Alternatively, click
+@kbd{Mouse-2} to make the selected frame become the current one.  If the
+locals buffer is displayed then its contents update to display the
+variables that are local to the new frame.
+
+@node Data Display
+@subsubsection Data Display
+@cindex displaying expressions in GDB
+
+If you want to see how a variable changes each time your program stops
+then place the cursor over the variable name and click on the display
+icon in the toolbar (@code{gud-display}).
+
+Each displayed expression has its own frame on a graphical display and
+its own buffer on a text-only terminal.  Arrays and structures have
+their own display formats.  To display an array as a slice, at the top
+of the display window, click @kbd{Mouse-2} on the array index that you
+want to restrict and you will be prompted in the mini-buffer for a
+start and a stop value. Click @kbd{Mouse-2} on a pointer to
+dereference it in the same frame/buffer.  Click @kbd{S-Mouse-2} there
+to do the same thing but in a new frame/buffer.  There are two special
+commands for these buffers:
+
+@table @kbd
+@item @kbd{v}
+@kindex v @r{(GDB data buffer)}
+@findex gdb-array-visualise
+Visualise an array using the graph program from plotutils if this is
+installed. This only works for one dimensional arrays
+(@code{gdb-array-visualise}).
+
+@item @kbd{q}
+@kindex q @r{(GDB data buffer)}
+@findex gdb-delete-expression
+Delete the displayed expression and the associated frame
+(@code{gdb-delete-expression}).
+@end table
+
+@node Display Buffer
+@subsubsection Display Buffer
+
+The display buffer shows the list of displayed expressions
+(@pxref{Auto Display,,, gdb, The GNU debugger}).  As with the
+breakpoints, you can enable/disable or delete the displayed
+expressions:
+
+@table @kbd
+@item @key{SPC}
+@kindex SPC @r{(GDB display buffer)}
+@findex gdb-toggle-display
+Enable/disable the display at the current line
+(@code{gdb-toggle-display}).
+
+@item @kbd{d}
+@kindex d @r{(GDB display buffer)}
+@findex gdb-delete-display
+Delete the display at the current line (@code{gdb-delete-display}).
+@end table
+
+@node Other Buffers
+@subsubsection Other Buffers
+
+@table @asis
+@item Input/Output Buffer
+The executable program that is being debugged takes its input and
+displays its output here.  Some of the commands from shell mode are
+available here.  @xref{Shell Mode}.
+
+@item Locals Buffer
+The locals buffer displays the values of local variables of the
+current frame for simple data types (@pxref{Frame Info,,, gdb, The GNU
+debugger}).
+
+Arrays and structures display their type only.  You must display them
+separately to examine their values.  @ref{Data Display}.
+
+@item Registers Buffer
+The registers buffer displays the values held by the registers
+(@pxref{Registers,,, gdb, The GNU debugger}).
+
+@item Assembler Buffer
+The assembler buffer displays the current frame as machine code.  An
+overlay arrow points to the current instruction and you can set and
+remove breakpoints as with the source buffer.  Breakpoints also
+appear in the margin.
+@end table
+
+@node Layout
+@subsubsection Layout
+@cindex GDB User Interface layout
+You may choose to display the additional buffers described previously
+either in the same frame or a different one.  Select GDB-windows or
+GDB-Frames from the menu-bar under the heading GUD.  If the menu-bar
+is unavailable, type @code{M-x
+gdb-display-@var{buffertype}-buffer} or @code{M-x
+gdb-frame-@var{buffertype}-buffer} respectively, where @var{buffertype}
+is the relevant buffer type e.g breakpoints.
+
+@findex gdb-many-windows
+@vindex gdb-many-windows
+If @code{gdb-many-windows} is @code{nil} (the default value), then GDB starts
+with just two windows: the GUD and the source buffer.  If it is @code{t}, then
+six windows with the following layout will appear:
+
+@multitable @columnfractions .5 .5
+@item GUD buffer (I/O of GDB)
+@tab Locals buffer
+@item
+@tab
+@item Source buffer
+@tab Input/Output (of debuggee) buffer
+@item
+@tab
+@item Stack buffer
+@tab Breakpoints buffer
+@end multitable
+
+To toggle this layout, do @kbd{M-x gdb-many-windows}.
+
+@findex gdb-restore-windows
+If you change the window layout, for example, while editing and
+re-compiling your program, then you can restore it with
+@code{gdb-restore-windows}.
+
 @node Executing Lisp
 @section Executing Lisp Expressions
 
@@ -613,7 +865,7 @@ the result of compiling @file{@var{lib}.el}; it is better to load the
 compiled file, since it will load and run faster.
 
   If @code{load-library} finds that @file{@var{lib}.el} is newer than
-@file{@var{lib}.elc} file, it prints a warning, because it's likely that
+@file{@var{lib}.elc} file, it issues a warning, because it's likely that
 somebody made changes to the @file{.el} file and forgot to recompile
 it.
 
@@ -693,7 +945,14 @@ Evaluate all the Lisp expressions in the region.
 Evaluate all the Lisp expressions in the buffer.
 @end table
 
+@ifinfo
+@c This uses ``colon'' instead of a literal `:' because Info cannot
+@c cope with a `:' in a menu
+@kindex M-@key{colon}
+@end ifinfo
+@ifnotinfo
 @kindex M-:
+@end ifnotinfo
 @findex eval-expression
   @kbd{M-:} (@code{eval-expression}) is the most basic command for evaluating
 a Lisp expression interactively.  It reads the expression using the
@@ -736,7 +995,7 @@ is @code{eval-region}.  @kbd{M-x eval-region} parses the text of the
 region as one or more Lisp expressions, evaluating them one by one.
 @kbd{M-x eval-current-buffer} is similar but evaluates the entire
 buffer.  This is a reasonable way to install the contents of a file of
-Lisp code that you are just ready to test.  Later, as you find bugs and
+Lisp code that you are ready to test.  Later, as you find bugs and
 change individual functions, use @kbd{C-M-x} on each function that you
 change.  This keeps the Lisp world in step with the source file.
 
@@ -829,3 +1088,7 @@ programs to be run in Emacs): in both modes it has the effect of installing
 the function definition that point is in, but the way of doing so is
 different according to where the relevant Lisp environment is found.
 @xref{Executing Lisp}.
+
+@ignore
+   arch-tag: 9c3c2f71-b332-4144-8500-3ff9945a50ed
+@end ignore