Tried allowing $Id: to appear in final output, but it confuses makeinfo
[deliverable/binutils-gdb.git] / gdb / doc / gdb.canned-m4
CommitLineData
9bcc06ef
RP
1_dnl__ Copyright (c) 1988 1989 1990 1991 Free Software Foundation, Inc.
2_dnl__ This file is part of the source for the GDB manual.
3_dnl__ $Id$
4@node Sequences, Emacs, Controlling _GDBN__, Top
5@chapter Canned Sequences of Commands
6
7Aside from breakpoint commands (@pxref{Break Commands}), _GDBN__ provides two
8ways to store sequences of commands for execution as a unit:
9user-defined commands and command files.
10
11@menu
12* Define:: User-Defined Commands
13* Command Files:: Command Files
14* Output:: Commands for Controlled Output
15@end menu
16
17@node Define, Command Files, Sequences, Sequences
18@section User-Defined Commands
19
20@cindex user-defined command
21A @dfn{user-defined command} is a sequence of _GDBN__ commands to which you
22assign a new name as a command. This is done with the @code{define}
23command.
24
25@table @code
26@item define @var{commandname}
27@kindex define
28Define a command named @var{commandname}. If there is already a command
29by that name, you are asked to confirm that you want to redefine it.
30
31The definition of the command is made up of other _GDBN__ command lines,
32which are given following the @code{define} command. The end of these
33commands is marked by a line containing @code{end}.
34
35@item document @var{commandname}
36@kindex document
37Give documentation to the user-defined command @var{commandname}. The
38command @var{commandname} must already be defined. This command reads
39lines of documentation just as @code{define} reads the lines of the
40command definition, ending with @code{end}. After the @code{document}
41command is finished, @code{help} on command @var{commandname} will print
42the documentation you have specified.
43
44You may use the @code{document} command again to change the
45documentation of a command. Redefining the command with @code{define}
46does not change the documentation.
47
48@item help user-defined
49@kindex help user-defined
50List all user-defined commands, with the first line of the documentation
51(if any) for each.
52
53@item info user
54@itemx info user @var{commandname}
55@kindex info user
56Display the _GDBN__ commands used to define @var{commandname} (but not its
57documentation). If no @var{commandname} is given, display the
58definitions for all user-defined commands.
59@end table
60
61User-defined commands do not take arguments. When they are executed, the
62commands of the definition are not printed. An error in any command
63stops execution of the user-defined command.
64
65Commands that would ask for confirmation if used interactively proceed
66without asking when used inside a user-defined command. Many _GDBN__ commands
67that normally print messages to say what they are doing omit the messages
68when used in a user-defined command.
69
70@node Command Files, Output, Define, Sequences
71@section Command Files
72
73@cindex command files
74A command file for _GDBN__ is a file of lines that are _GDBN__ commands. Comments
75(lines starting with @kbd{#}) may also be included. An empty line in a
76command file does nothing; it does not mean to repeat the last command, as
77it would from the terminal.
78
79@cindex init file
80@cindex @file{_GDBINIT__}
81When you start _GDBN__, it automatically executes commands from its
82@dfn{init files}. These are files named @file{_GDBINIT__}. _GDBN__
83reads the init file (if any) in your home directory and then the init
84file (if any) in the current working directory. (The init files are not
85executed if you use the @samp{-nx} option; @pxref{Mode Options}.) You
86can also request the execution of a command file with the @code{source}
87command:
88
89@table @code
90@item source @var{filename}
91@kindex source
92Execute the command file @var{filename}.
93@end table
94
95The lines in a command file are executed sequentially. They are not
96printed as they are executed. An error in any command terminates execution
97of the command file.
98
99Commands that would ask for confirmation if used interactively proceed
100without asking when used in a command file. Many _GDBN__ commands that
101normally print messages to say what they are doing omit the messages
102when called from command files.
103
104@node Output, , Command Files, Sequences
105@section Commands for Controlled Output
106
107During the execution of a command file or a user-defined command, normal
108_GDBN__ output is suppressed; the only output that appears is what is
109explicitly printed by the commands in the definition. This section
110describes three commands useful for generating exactly the output you
111want.
112
113@table @code
114@item echo @var{text}
115@kindex echo
116@c I don't consider backslash-space a standard C escape sequence
117@c because it's not in ANSI.
118Print @var{text}. Nonprinting characters can be included in @var{text}
119using C escape sequences, such as @samp{\n} to print a newline. @b{No
120newline will be printed unless you specify one.} In addition to the
121standard C escape sequences, a backslash followed by a space stands for a
122space. This is useful for outputting a string with spaces at the
123beginning or the end, since leading and trailing spaces are otherwise
124trimmed from all arguments. Thus, to print @samp{@ and foo =@ }, use the
125command @samp{echo \@ and foo = \@ }.
126@c FIXME: verify hard copy actually issues enspaces for '@ '! Will this
127@c confuse texinfo?
128
129A backslash at the end of @var{text} can be used, as in C, to continue
130the command onto subsequent lines. For example,
131
132@example
133echo This is some text\n\
134which is continued\n\
135onto several lines.\n
136@end example
137
138produces the same output as
139
140@example
141echo This is some text\n
142echo which is continued\n
143echo onto several lines.\n
144@end example
145
146@item output @var{expression}
147@kindex output
148Print the value of @var{expression} and nothing but that value: no
149newlines, no @samp{$@var{nn} = }. The value is not entered in the
150value history either. @xref{Expressions} for more information on
151expressions.
152
153@item output/@var{fmt} @var{expression}
154Print the value of @var{expression} in format @var{fmt}. You can use
155the same formats as for @code{print}; @pxref{Output formats}, for more
156information.
157
158@item printf @var{string}, @var{expressions}@dots{}
159@kindex printf
160Print the values of the @var{expressions} under the control of
161@var{string}. The @var{expressions} are separated by commas and may
162be either numbers or pointers. Their values are printed as specified
163by @var{string}, exactly as if the program were to execute
164
165@example
166printf (@var{string}, @var{expressions}@dots{});
167@end example
168
169For example, you can print two values in hex like this:
170
171@example
172printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
173@end example
174
175The only backslash-escape sequences that you can use in the format
176string are the simple ones that consist of backslash followed by a
177letter.
178@end table
This page took 0.029657 seconds and 4 git commands to generate.