Files
2024-02-19 00:25:23 -05:00

528 lines
21 KiB
HTML

<HTML>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Created on November, 11 2002 by texi2html 1.64 -->
<!--
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
Karl Berry <karl@freefriends.org>
Olaf Bachmann <obachman@mathematik.uni-kl.de>
and many others.
Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
-->
<HEAD>
<TITLE>Debugging with GDB: Sequences</TITLE>
<META NAME="description" CONTENT="Debugging with GDB: Sequences">
<META NAME="keywords" CONTENT="Debugging with GDB: Sequences">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="texi2html 1.64">
</HEAD>
<BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<A NAME="SEC192"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_20.html#SEC191"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC193"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_4.html#SEC12"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_22.html#SEC197"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_35.html#SEC643">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<H1> 20. Canned Sequences of Commands </H1>
<!--docid::SEC192::-->
<P>
Aside from breakpoint commands (see section <A HREF="gdb_6.html#SEC35">Breakpoint command lists</A>), GDB provides two ways to store sequences of
commands for execution as a unit: user-defined commands and command
files.
</P><P>
<BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0>
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_21.html#SEC193">20.1 User-defined commands</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_21.html#SEC194">20.2 User-defined command hooks</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_21.html#SEC195">20.3 Command files</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_21.html#SEC196">20.4 Commands for controlled output</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
</TABLE></BLOCKQUOTE>
<P>
<A NAME="Define"></A>
<HR SIZE="6">
<A NAME="SEC193"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC192"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC194"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC192"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC192"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_22.html#SEC197"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_35.html#SEC643">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<H2> 20.1 User-defined commands </H2>
<!--docid::SEC193::-->
<P>
<A NAME="IDX858"></A>
A <EM>user-defined command</EM> is a sequence of GDB commands to
which you assign a new name as a command. This is done with the
<CODE>define</CODE> command. User commands may accept up to 10 arguments
separated by whitespace. Arguments are accessed within the user command
via <VAR>$arg0<small>...</small>$arg9</VAR>. A trivial example:
</P><P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>define adder
print $arg0 + $arg1 + $arg2
</FONT></pre></td></tr></table></P><P>
To execute the command use:
</P><P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>adder 1 2 3
</FONT></pre></td></tr></table></P><P>
This defines the command <CODE>adder</CODE>, which prints the sum of
its three arguments. Note the arguments are text substitutions, so they may
reference variables, use complex expressions, or even perform inferior
functions calls.
</P><P>
<DL COMPACT>
<A NAME="IDX859"></A>
<DT><CODE>define <VAR>commandname</VAR></CODE>
<DD>Define a command named <VAR>commandname</VAR>. If there is already a command
by that name, you are asked to confirm that you want to redefine it.
<P>
The definition of the command is made up of other GDB command lines,
which are given following the <CODE>define</CODE> command. The end of these
commands is marked by a line containing <CODE>end</CODE>.
</P><P>
<A NAME="IDX860"></A>
<A NAME="IDX861"></A>
<DT><CODE>if</CODE>
<DD>Takes a single argument, which is an expression to evaluate.
It is followed by a series of commands that are executed
only if the expression is true (nonzero).
There can then optionally be a line <CODE>else</CODE>, followed
by a series of commands that are only executed if the expression
was false. The end of the list is marked by a line containing <CODE>end</CODE>.
<P>
<A NAME="IDX862"></A>
<DT><CODE>while</CODE>
<DD>The syntax is similar to <CODE>if</CODE>: the command takes a single argument,
which is an expression to evaluate, and must be followed by the commands to
execute, one per line, terminated by an <CODE>end</CODE>.
The commands are executed repeatedly as long as the expression
evaluates to true.
<P>
<A NAME="IDX863"></A>
<DT><CODE>document <VAR>commandname</VAR></CODE>
<DD>Document the user-defined command <VAR>commandname</VAR>, so that it can be
accessed by <CODE>help</CODE>. The command <VAR>commandname</VAR> must already be
defined. This command reads lines of documentation just as <CODE>define</CODE>
reads the lines of the command definition, ending with <CODE>end</CODE>.
After the <CODE>document</CODE> command is finished, <CODE>help</CODE> on command
<VAR>commandname</VAR> displays the documentation you have written.
<P>
You may use the <CODE>document</CODE> command again to change the
documentation of a command. Redefining the command with <CODE>define</CODE>
does not change the documentation.
</P><P>
<A NAME="IDX864"></A>
<DT><CODE>help user-defined</CODE>
<DD>List all user-defined commands, with the first line of the documentation
(if any) for each.
<P>
<A NAME="IDX865"></A>
<DT><CODE>show user</CODE>
<DD><DT><CODE>show user <VAR>commandname</VAR></CODE>
<DD>Display the GDB commands used to define <VAR>commandname</VAR> (but
not its documentation). If no <VAR>commandname</VAR> is given, display the
definitions for all user-defined commands.
<P>
<A NAME="IDX866"></A>
<A NAME="IDX867"></A>
<DT><CODE>show max-user-call-depth</CODE>
<DD><DT><CODE>set max-user-call-depth</CODE>
<DD>The value of <CODE>max-user-call-depth</CODE> controls how many recursion
levels are allowed in user-defined commands before GDB suspects an
infinite recursion and aborts the command.
<P>
</DL>
<P>
When user-defined commands are executed, the
commands of the definition are not printed. An error in any command
stops execution of the user-defined command.
</P><P>
If used interactively, commands that would ask for confirmation proceed
without asking when used inside a user-defined command. Many GDB
commands that normally print messages to say what they are doing omit the
messages when used in a user-defined command.
</P><P>
<A NAME="Hooks"></A>
<HR SIZE="6">
<A NAME="SEC194"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC193"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC195"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC195"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC192"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_22.html#SEC197"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_35.html#SEC643">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<H2> 20.2 User-defined command hooks </H2>
<!--docid::SEC194::-->
<P>
<A NAME="IDX868"></A>
<A NAME="IDX869"></A>
You may define <EM>hooks</EM>, which are a special kind of user-defined
command. Whenever you run the command <SAMP>`foo'</SAMP>, if the user-defined
command <SAMP>`hook-foo'</SAMP> exists, it is executed (with no arguments)
before that command.
</P><P>
<A NAME="IDX870"></A>
<A NAME="IDX871"></A>
<A NAME="IDX872"></A>
A hook may also be defined which is run after the command you executed.
Whenever you run the command <SAMP>`foo'</SAMP>, if the user-defined command
<SAMP>`hookpost-foo'</SAMP> exists, it is executed (with no arguments) after
that command. Post-execution hooks may exist simultaneously with
pre-execution hooks, for the same command.
</P><P>
It is valid for a hook to call the command which it hooks. If this
occurs, the hook is not re-executed, thereby avoiding infinte recursion.
</P><P>
<A NAME="IDX873"></A>
In addition, a pseudo-command, <SAMP>`stop'</SAMP> exists. Defining
(<SAMP>`hook-stop'</SAMP>) makes the associated commands execute every time
execution stops in your program: before breakpoint commands are run,
displays are printed, or the stack frame is printed.
</P><P>
For example, to ignore <CODE>SIGALRM</CODE> signals while
single-stepping, but treat them normally during normal execution,
you could define:
</P><P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>define hook-stop
handle SIGALRM nopass
end
define hook-run
handle SIGALRM pass
end
define hook-continue
handle SIGLARM pass
end
</FONT></pre></td></tr></table></P><P>
As a further example, to hook at the begining and end of the <CODE>echo</CODE>
command, and to add extra text to the beginning and end of the message,
you could define:
</P><P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>define hook-echo
echo &#60;&#60;&#60;---
end
define hookpost-echo
echo ---&#62;&#62;&#62;\n
end
(gdb) echo Hello World
&#60;&#60;&#60;---Hello World---&#62;&#62;&#62;
(gdb)
</FONT></pre></td></tr></table></P><P>
You can define a hook for any single-word command in GDB, but
not for command aliases; you should define a hook for the basic command
name, e.g. <CODE>backtrace</CODE> rather than <CODE>bt</CODE>.
If an error occurs during the execution of your hook, execution of
GDB commands stops and GDB issues a prompt
(before the command that you actually typed had a chance to run).
</P><P>
If you try to define a hook which does not match any known command, you
get a warning from the <CODE>define</CODE> command.
</P><P>
<A NAME="Command Files"></A>
<HR SIZE="6">
<A NAME="SEC195"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC194"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC196"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC196"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC192"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_22.html#SEC197"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_35.html#SEC643">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<H2> 20.3 Command files </H2>
<!--docid::SEC195::-->
<P>
<A NAME="IDX874"></A>
A command file for GDB is a file of lines that are GDB
commands. Comments (lines starting with <KBD>#</KBD>) may also be included.
An empty line in a command file does nothing; it does not mean to repeat
the last command, as it would from the terminal.
</P><P>
<A NAME="IDX875"></A>
<A NAME="IDX876"></A>
<A NAME="IDX877"></A>
When you start GDB, it automatically executes commands from its
<EM>init files</EM>, normally called <TT>`.gdbinit'</TT><A NAME="DOCF6" HREF="gdb_fot.html#FOOT6">(6)</A>.
During startup, GDB does the following:
</P><P>
<OL>
<LI>
Reads the init file (if any) in your home directory<A NAME="DOCF7" HREF="gdb_fot.html#FOOT7">(7)</A>.
<P>
<LI>
Processes command line options and operands.
<P>
<LI>
Reads the init file (if any) in the current working directory.
<P>
<LI>
Reads command files specified by the <SAMP>`-x'</SAMP> option.
</OL>
<P>
The init file in your home directory can set options (such as <SAMP>`set
complaints'</SAMP>) that affect subsequent processing of command line options
and operands. Init files are not executed if you use the <SAMP>`-nx'</SAMP>
option (see section <A HREF="gdb_3.html#SEC9">Choosing modes</A>).
</P><P>
<A NAME="IDX878"></A>
On some configurations of GDB, the init file is known by a
different name (these are typically environments where a specialized
form of GDB may need to coexist with other forms, hence a
different name for the specialized version's init file). These are the
environments with special init file names:
</P><P>
<A NAME="IDX879"></A>
<UL>
<LI>
VxWorks (Wind River Systems real-time OS): <TT>`.vxgdbinit'</TT>
<P>
<A NAME="IDX880"></A>
<LI>
OS68K (Enea Data Systems real-time OS): <TT>`.os68gdbinit'</TT>
<P>
<A NAME="IDX881"></A>
<LI>
ES-1800 (Ericsson Telecom AB M68000 emulator): <TT>`.esgdbinit'</TT>
</UL>
<P>
You can also request the execution of a command file with the
<CODE>source</CODE> command:
</P><P>
<DL COMPACT>
<A NAME="IDX882"></A>
<DT><CODE>source <VAR>filename</VAR></CODE>
<DD>Execute the command file <VAR>filename</VAR>.
</DL>
<P>
The lines in a command file are executed sequentially. They are not
printed as they are executed. An error in any command terminates
execution of the command file and control is returned to the console.
</P><P>
Commands that would ask for confirmation if used interactively proceed
without asking when used in a command file. Many GDB commands that
normally print messages to say what they are doing omit the messages
when called from command files.
</P><P>
GDB also accepts command input from standard input. In this
mode, normal output goes to standard output and error output goes to
standard error. Errors in a command file supplied on standard input do
not terminate execution of the command file -- execution continues with
the next command.
</P><P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>gdb &#60; cmds &#62; log 2&#62;&#38;1
</FONT></pre></td></tr></table></P><P>
(The syntax above will vary depending on the shell used.) This example
will execute commands from the file <TT>`cmds'</TT>. All output and errors
would be directed to <TT>`log'</TT>.
</P><P>
<A NAME="Output"></A>
<HR SIZE="6">
<A NAME="SEC196"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC195"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_22.html#SEC197"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC192"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC192"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_22.html#SEC197"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_35.html#SEC643">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<H2> 20.4 Commands for controlled output </H2>
<!--docid::SEC196::-->
<P>
During the execution of a command file or a user-defined command, normal
GDB output is suppressed; the only output that appears is what is
explicitly printed by the commands in the definition. This section
describes three commands useful for generating exactly the output you
want.
</P><P>
<DL COMPACT>
<A NAME="IDX883"></A>
<DT><CODE>echo <VAR>text</VAR></CODE>
<DD>Print <VAR>text</VAR>. Nonprinting characters can be included in
<VAR>text</VAR> using C escape sequences, such as <SAMP>`\n'</SAMP> to print a
newline. <STRONG>No newline is printed unless you specify one.</STRONG>
In addition to the standard C escape sequences, a backslash followed
by a space stands for a space. This is useful for displaying a
string with spaces at the beginning or the end, since leading and
trailing spaces are otherwise trimmed from all arguments.
To print <SAMP>` and foo = '</SAMP>, use the command
<SAMP>`echo \ and foo = \ '</SAMP>.
<P>
A backslash at the end of <VAR>text</VAR> can be used, as in C, to continue
the command onto subsequent lines. For example,
</P><P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>echo This is some text\n\
which is continued\n\
onto several lines.\n
</FONT></pre></td></tr></table></P><P>
produces the same output as
</P><P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>echo This is some text\n
echo which is continued\n
echo onto several lines.\n
</FONT></pre></td></tr></table></P><P>
<A NAME="IDX884"></A>
<DT><CODE>output <VAR>expression</VAR></CODE>
<DD>Print the value of <VAR>expression</VAR> and nothing but that value: no
newlines, no <SAMP>`$<VAR>nn</VAR> = '</SAMP>. The value is not entered in the
value history either. See section <A HREF="gdb_9.html#SEC54">Expressions</A>, for more information
on expressions.
<P>
<DT><CODE>output/<VAR>fmt</VAR> <VAR>expression</VAR></CODE>
<DD>Print the value of <VAR>expression</VAR> in format <VAR>fmt</VAR>. You can use
the same formats as for <CODE>print</CODE>. See section <A HREF="gdb_9.html#SEC57">Output formats</A>, for more information.
<P>
<A NAME="IDX885"></A>
<DT><CODE>printf <VAR>string</VAR>, <VAR>expressions</VAR><small>...</small></CODE>
<DD>Print the values of the <VAR>expressions</VAR> under the control of
<VAR>string</VAR>. The <VAR>expressions</VAR> are separated by commas and may be
either numbers or pointers. Their values are printed as specified by
<VAR>string</VAR>, exactly as if your program were to execute the C
subroutine
<P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>printf (<VAR>string</VAR>, <VAR>expressions</VAR><small>...</small>);
</FONT></pre></td></tr></table></P><P>
For example, you can print two values in hex like this:
</P><P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
</FONT></pre></td></tr></table></P><P>
The only backslash-escape sequences that you can use in the format
string are the simple ones that consist of backslash followed by a
letter.
</DL>
<P>
<A NAME="TUI"></A>
<HR SIZE="6">
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_21.html#SEC192"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_22.html#SEC197"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_35.html#SEC643">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<BR>
<FONT SIZE="-1">
<address>
<p>Please send FSF &amp; GNU inquiries &amp; questions to <a
href="mailto:gnu@gnu.org">gnu@gnu.org</a>. There are also <a
href="http://www.gnu.org/home.html#ContactInfo">other ways to
contact</a> the FSF.</p>
<p>These pages are maintained by <a
href="http://www.gnu.org/software/gdb/">the GDB developers</a>.</p>
<p>Copyright Free Software Foundation, Inc., 59 Temple Place - Suite
330, Boston, MA 02111, USA.</p>
<p>Verbatim copying and distribution of this entire article is
permitted in any medium, provided this notice is preserved.</p>
</address>
This document was generated
by <I>GDB Administrator</I> on <I>November, 11 2002</I>
using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
"><I>texi2html</I></A>
</BODY>
</HTML>