<HTML> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!-- Created on March, 27 2008 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: Invocation</TITLE> <META NAME="description" CONTENT="Debugging with GDB: Invocation"> <META NAME="keywords" CONTENT="Debugging with GDB: Invocation"> <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="SEC6"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_2.html#SEC5"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC7"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_4.html#SEC14"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_4.html#SEC14"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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_38.html#SEC764">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H1> 2. Getting In and Out of GDB </H1> <!--docid::SEC6::--> <P> This chapter discusses how to start GDB, and how to get out of it. The essentials are: <UL> <LI> type <SAMP>`gdb'</SAMP> to start GDB. <LI> type <KBD>quit</KBD> or <KBD>Ctrl-d</KBD> to exit. </UL> <P> <BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0> <TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_3.html#SEC7">2.1 Invoking GDB</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">How to start GDB</TD></TR> <TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_3.html#SEC11">2.2 Quitting GDB</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">How to quit GDB</TD></TR> <TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_3.html#SEC12">2.3 Shell Commands</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">How to use shell commands inside GDB</TD></TR> <TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_3.html#SEC13">2.4 Logging Output</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">How to log GDB's output to a file</TD></TR> </TABLE></BLOCKQUOTE> <P> <A NAME="Invoking GDB"></A> <HR SIZE="6"> <A NAME="SEC7"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC6"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC8"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC6"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC6"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC11"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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_38.html#SEC764">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H2> 2.1 Invoking GDB </H2> <!--docid::SEC7::--> <P> Invoke GDB by running the program <CODE>gdb</CODE>. Once started, GDB reads commands from the terminal until you tell it to exit. </P><P> You can also run <CODE>gdb</CODE> with a variety of arguments and options, to specify more of your debugging environment at the outset. </P><P> The command-line options described here are designed to cover a variety of situations; in some environments, some of these options may effectively be unavailable. </P><P> The most usual way to start GDB is with one argument, specifying an executable program: </P><P> <TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>gdb <VAR>program</VAR> </FONT></pre></td></tr></table></P><P> You can also start with both an executable program and a core file specified: </P><P> <TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>gdb <VAR>program</VAR> <VAR>core</VAR> </FONT></pre></td></tr></table></P><P> You can, instead, specify a process ID as a second argument, if you want to debug a running process: </P><P> <TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>gdb <VAR>program</VAR> 1234 </FONT></pre></td></tr></table></P><P> would attach GDB to process <CODE>1234</CODE> (unless you also have a file named <TT>`1234'</TT>; GDB does check for a core file first). </P><P> Taking advantage of the second command-line argument requires a fairly complete operating system; when you use GDB as a remote debugger attached to a bare board, there may not be any notion of "process", and there is often no way to get a core dump. GDB will warn you if it is unable to attach or to read core dumps. </P><P> You can optionally have <CODE>gdb</CODE> pass any arguments after the executable file to the inferior using <CODE>--args</CODE>. This option stops option processing. <TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>gdb --args gcc -O2 -c foo.c </FONT></pre></td></tr></table>This will cause <CODE>gdb</CODE> to debug <CODE>gcc</CODE>, and to set <CODE>gcc</CODE>'s command-line arguments (see section <A HREF="gdb_5.html#SEC21">4.3 Your Program's Arguments</A>) to <SAMP>`-O2 -c foo.c'</SAMP>. </P><P> You can run <CODE>gdb</CODE> without printing the front material, which describes GDB's non-warranty, by specifying <CODE>-silent</CODE>: </P><P> <TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>gdb -silent </FONT></pre></td></tr></table></P><P> You can further control how GDB starts up by using command-line options. GDB itself can remind you of the options available. </P><P> Type </P><P> <TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>gdb -help </FONT></pre></td></tr></table></P><P> to display all available options and briefly describe their use (<SAMP>`gdb -h'</SAMP> is a shorter equivalent). </P><P> All options and command line arguments you give are processed in sequential order. The order makes a difference when the <SAMP>`-x'</SAMP> option is used. </P><P> <BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0> <TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_3.html#SEC8">2.1.1 Choosing Files</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Choosing files</TD></TR> <TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_3.html#SEC9">2.1.2 Choosing Modes</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Choosing modes</TD></TR> <TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_3.html#SEC10">2.1.3 What GDB Does During Startup</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">What GDB does during startup</TD></TR> </TABLE></BLOCKQUOTE> <P> <A NAME="File Options"></A> <HR SIZE="6"> <A NAME="SEC8"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC7"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC9"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC6"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC7"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC11"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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_38.html#SEC764">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H3> 2.1.1 Choosing Files </H3> <!--docid::SEC8::--> <P> When GDB starts, it reads any arguments other than options as specifying an executable file and core file (or process ID). This is the same as if the arguments were specified by the <SAMP>`-se'</SAMP> and <SAMP>`-c'</SAMP> (or <SAMP>`-p'</SAMP>) options respectively. (GDB reads the first argument that does not have an associated option flag as equivalent to the <SAMP>`-se'</SAMP> option followed by that argument; and the second argument that does not have an associated option flag, if any, as equivalent to the <SAMP>`-c'</SAMP>/<SAMP>`-p'</SAMP> option followed by that argument.) If the second argument begins with a decimal digit, GDB will first attempt to attach to it as a process, and if that fails, attempt to open it as a corefile. If you have a corefile whose name begins with a digit, you can prevent GDB from treating it as a pid by prefixing it with <TT>`./'</TT>, e.g. <TT>`./12345'</TT>. </P><P> If GDB has not been configured to included core file support, such as for most embedded targets, then it will complain about a second argument and ignore it. </P><P> Many options have both long and short forms; both are shown in the following list. GDB also recognizes the long forms if you truncate them, so long as enough of the option is present to be unambiguous. (If you prefer, you can flag option arguments with <SAMP>`--'</SAMP> rather than <SAMP>`-'</SAMP>, though we illustrate the more usual convention.) </P><P> <DL COMPACT> <DT><CODE>-symbols <VAR>file</VAR></CODE> <DD><DT><CODE>-s <VAR>file</VAR></CODE> <DD><A NAME="IDX4"></A> <A NAME="IDX5"></A> Read symbol table from file <VAR>file</VAR>. <P> <DT><CODE>-exec <VAR>file</VAR></CODE> <DD><DT><CODE>-e <VAR>file</VAR></CODE> <DD><A NAME="IDX6"></A> <A NAME="IDX7"></A> Use file <VAR>file</VAR> as the executable file to execute when appropriate, and for examining pure data in conjunction with a core dump. <P> <DT><CODE>-se <VAR>file</VAR></CODE> <DD><A NAME="IDX8"></A> Read symbol table from file <VAR>file</VAR> and use it as the executable file. <P> <DT><CODE>-core <VAR>file</VAR></CODE> <DD><DT><CODE>-c <VAR>file</VAR></CODE> <DD><A NAME="IDX9"></A> <A NAME="IDX10"></A> Use file <VAR>file</VAR> as a core dump to examine. <P> <DT><CODE>-pid <VAR>number</VAR></CODE> <DD><DT><CODE>-p <VAR>number</VAR></CODE> <DD><A NAME="IDX11"></A> <A NAME="IDX12"></A> Connect to process ID <VAR>number</VAR>, as with the <CODE>attach</CODE> command. <P> <DT><CODE>-command <VAR>file</VAR></CODE> <DD><DT><CODE>-x <VAR>file</VAR></CODE> <DD><A NAME="IDX13"></A> <A NAME="IDX14"></A> Execute GDB commands from file <VAR>file</VAR>. See section <A HREF="gdb_21.html#SEC232">Command files</A>. <P> <DT><CODE>-eval-command <VAR>command</VAR></CODE> <DD><DT><CODE>-ex <VAR>command</VAR></CODE> <DD><A NAME="IDX15"></A> <A NAME="IDX16"></A> Execute a single GDB command. <P> This option may be used multiple times to call multiple commands. It may also be interleaved with <SAMP>`-command'</SAMP> as required. </P><P> <TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>gdb -ex 'target sim' -ex 'load' \ -x setbreakpoints -ex 'run' a.out </FONT></pre></td></tr></table></P><P> <DT><CODE>-directory <VAR>directory</VAR></CODE> <DD><DT><CODE>-d <VAR>directory</VAR></CODE> <DD><A NAME="IDX17"></A> <A NAME="IDX18"></A> Add <VAR>directory</VAR> to the path to search for source and script files. <P> <DT><CODE>-r</CODE> <DD><DT><CODE>-readnow</CODE> <DD><A NAME="IDX19"></A> <A NAME="IDX20"></A> Read each symbol file's entire symbol table immediately, rather than the default, which is to read it incrementally as it is needed. This makes startup slower, but makes future operations faster. <P> </DL> <P> <A NAME="Mode Options"></A> <HR SIZE="6"> <A NAME="SEC9"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC8"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC10"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC10"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC7"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC11"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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_38.html#SEC764">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H3> 2.1.2 Choosing Modes </H3> <!--docid::SEC9::--> <P> You can run GDB in various alternative modes--for example, in batch mode or quiet mode. </P><P> <DL COMPACT> <DT><CODE>-nx</CODE> <DD><DT><CODE>-n</CODE> <DD><A NAME="IDX21"></A> <A NAME="IDX22"></A> Do not execute commands found in any initialization files. Normally, GDB executes the commands in these files after all the command options and arguments have been processed. See section <A HREF="gdb_21.html#SEC232">Command Files</A>. <P> <DT><CODE>-quiet</CODE> <DD><DT><CODE>-silent</CODE> <DD><DT><CODE>-q</CODE> <DD><A NAME="IDX23"></A> <A NAME="IDX24"></A> <A NAME="IDX25"></A> "Quiet". Do not print the introductory and copyright messages. These messages are also suppressed in batch mode. <P> <DT><CODE>-batch</CODE> <DD><A NAME="IDX26"></A> Run in batch mode. Exit with status <CODE>0</CODE> after processing all the command files specified with <SAMP>`-x'</SAMP> (and all commands from initialization files, if not inhibited with <SAMP>`-n'</SAMP>). Exit with nonzero status if an error occurs in executing the GDB commands in the command files. <P> Batch mode may be useful for running GDB as a filter, for example to download and run a program on another computer; in order to make this more useful, the message </P><P> <TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>Program exited normally. </FONT></pre></td></tr></table></P><P> (which is ordinarily issued whenever a program running under GDB control terminates) is not issued when running in batch mode. </P><P> <DT><CODE>-batch-silent</CODE> <DD><A NAME="IDX27"></A> Run in batch mode exactly like <SAMP>`-batch'</SAMP>, but totally silently. All GDB output to <CODE>stdout</CODE> is prevented (<CODE>stderr</CODE> is unaffected). This is much quieter than <SAMP>`-silent'</SAMP> and would be useless for an interactive session. <P> This is particularly useful when using targets that give <SAMP>`Loading section'</SAMP> messages, for example. </P><P> Note that targets that give their output via GDB, as opposed to writing directly to <CODE>stdout</CODE>, will also be made silent. </P><P> <DT><CODE>-return-child-result</CODE> <DD><A NAME="IDX28"></A> The return code from GDB will be the return code from the child process (the process being debugged), with the following exceptions: <P> <UL> <LI> GDB exits abnormally. E.g., due to an incorrect argument or an internal error. In this case the exit code is the same as it would have been without <SAMP>`-return-child-result'</SAMP>. <LI> The user quits with an explicit value. E.g., <SAMP>`quit 1'</SAMP>. <LI> The child process never runs, or is not allowed to terminate, in which case the exit code will be -1. </UL> <P> This option is useful in conjunction with <SAMP>`-batch'</SAMP> or <SAMP>`-batch-silent'</SAMP>, when GDB is being used as a remote program loader or simulator interface. </P><P> <DT><CODE>-nowindows</CODE> <DD><DT><CODE>-nw</CODE> <DD><A NAME="IDX29"></A> <A NAME="IDX30"></A> "No windows". If GDB comes with a graphical user interface (GUI) built in, then this option tells GDB to only use the command-line interface. If no GUI is available, this option has no effect. <P> <DT><CODE>-windows</CODE> <DD><DT><CODE>-w</CODE> <DD><A NAME="IDX31"></A> <A NAME="IDX32"></A> If GDB includes a GUI, then this option requires it to be used if possible. <P> <DT><CODE>-cd <VAR>directory</VAR></CODE> <DD><A NAME="IDX33"></A> Run GDB using <VAR>directory</VAR> as its working directory, instead of the current directory. <P> <DT><CODE>-fullname</CODE> <DD><DT><CODE>-f</CODE> <DD><A NAME="IDX34"></A> <A NAME="IDX35"></A> GNU Emacs sets this option when it runs GDB as a subprocess. It tells GDB to output the full file name and line number in a standard, recognizable fashion each time a stack frame is displayed (which includes each time your program stops). This recognizable format looks like two <SAMP>`\032'</SAMP> characters, followed by the file name, line number and character position separated by colons, and a newline. The Emacs-to-GDB interface program uses the two <SAMP>`\032'</SAMP> characters as a signal to display the source code for the frame. <P> <DT><CODE>-epoch</CODE> <DD><A NAME="IDX36"></A> The Epoch Emacs-GDB interface sets this option when it runs GDB as a subprocess. It tells GDB to modify its print routines so as to allow Epoch to display values of expressions in a separate window. <P> <DT><CODE>-annotate <VAR>level</VAR></CODE> <DD><A NAME="IDX37"></A> This option sets the <EM>annotation level</EM> inside GDB. Its effect is identical to using <SAMP>`set annotate <VAR>level</VAR>'</SAMP> (see section <A HREF="gdb_26.html#SEC646">25. GDB Annotations</A>). The annotation <VAR>level</VAR> controls how much information GDB prints together with its prompt, values of expressions, source lines, and other types of output. Level 0 is the normal, level 1 is for use when GDB is run as a subprocess of GNU Emacs, level 3 is the maximum annotation suitable for programs that control GDB, and level 2 has been deprecated. <P> The annotation mechanism has largely been superseded by GDB/MI (see section <A HREF="gdb_25.html#SEC242">24. The GDB/MI Interface</A>). </P><P> <DT><CODE>--args</CODE> <DD><A NAME="IDX38"></A> Change interpretation of command line so that arguments following the executable file are passed as command line arguments to the inferior. This option stops option processing. <P> <DT><CODE>-baud <VAR>bps</VAR></CODE> <DD><DT><CODE>-b <VAR>bps</VAR></CODE> <DD><A NAME="IDX39"></A> <A NAME="IDX40"></A> Set the line speed (baud rate or bits per second) of any serial interface used by GDB for remote debugging. <P> <DT><CODE>-l <VAR>timeout</VAR></CODE> <DD><A NAME="IDX41"></A> Set the timeout (in seconds) of any communication used by GDB for remote debugging. <P> <DT><CODE>-tty <VAR>device</VAR></CODE> <DD><DT><CODE>-t <VAR>device</VAR></CODE> <DD><A NAME="IDX42"></A> <A NAME="IDX43"></A> Run using <VAR>device</VAR> for your program's standard input and output. <P> <DT><CODE>-tui</CODE> <DD><A NAME="IDX44"></A> Activate the <EM>Text User Interface</EM> when starting. The Text User Interface manages several text windows on the terminal, showing source, assembly, registers and GDB command outputs (see section <A HREF="gdb_23.html#SEC235">GDB Text User Interface</A>). Alternatively, the Text User Interface can be enabled by invoking the program <SAMP>`gdbtui'</SAMP>. Do not use this option if you run GDB from Emacs (see section <A HREF="gdb_24.html#SEC241">Using GDB under GNU Emacs</A>). <P> <DT><CODE>-interpreter <VAR>interp</VAR></CODE> <DD><A NAME="IDX45"></A> Use the interpreter <VAR>interp</VAR> for interface with the controlling program or device. This option is meant to be set by programs which communicate with GDB using it as a back end. See section <A HREF="gdb_22.html#SEC234">Command Interpreters</A>. <P> <SAMP>`--interpreter=mi'</SAMP> (or <SAMP>`--interpreter=mi2'</SAMP>) causes GDB to use the <EM>GDB/MI interface</EM> (see section <A HREF="gdb_25.html#SEC242">The GDB/MI Interface</A>) included since GDB version 6.0. The previous GDB/MI interface, included in GDB version 5.3 and selected with <SAMP>`--interpreter=mi1'</SAMP>, is deprecated. Earlier GDB/MI interfaces are no longer supported. </P><P> <DT><CODE>-write</CODE> <DD><A NAME="IDX46"></A> Open the executable and core files for both reading and writing. This is equivalent to the <SAMP>`set write on'</SAMP> command inside GDB (see section <A HREF="gdb_15.html#SEC153">14.6 Patching Programs</A>). <P> <DT><CODE>-statistics</CODE> <DD><A NAME="IDX47"></A> This option causes GDB to print statistics about time and memory usage after it completes each command and returns to the prompt. <P> <DT><CODE>-version</CODE> <DD><A NAME="IDX48"></A> This option causes GDB to print its version number and no-warranty blurb, and exit. <P> </DL> <P> <A NAME="Startup"></A> <HR SIZE="6"> <A NAME="SEC10"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC9"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC11"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC6"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC7"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC11"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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_38.html#SEC764">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H3> 2.1.3 What GDB Does During Startup </H3> <!--docid::SEC10::--> <P> Here's the description of what GDB does during session startup: </P><P> <OL> <LI> Sets up the command interpreter as specified by the command line (see section <A HREF="gdb_3.html#SEC9">interpreter</A>). <P> <LI> <A NAME="IDX49"></A> Reads the <EM>init file</EM> (if any) in your home directory<A NAME="DOCF1" HREF="gdb_fot.html#FOOT1">(1)</A> and executes all the commands in that file. <P> <LI> Processes command line options and operands. <P> <LI> Reads and executes the commands from init file (if any) in the current working directory. This is only done if the current directory is different from your home directory. Thus, you can have more than one init file, one generic in your home directory, and another, specific to the program you are debugging, in the directory where you invoke GDB. <P> <LI> Reads command files specified by the <SAMP>`-x'</SAMP> option. See section <A HREF="gdb_21.html#SEC232">20.3 Command Files</A>, for more details about GDB command files. <P> <LI> Reads the command history recorded in the <EM>history file</EM>. See section <A HREF="gdb_20.html#SEC223">19.3 Command History</A>, for more details about the command history and the files where GDB records it. </OL> <P> Init files use the same syntax as <EM>command files</EM> (see section <A HREF="gdb_21.html#SEC232">20.3 Command Files</A>) and are processed by GDB in the same way. 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="IDX50"></A> <A NAME="IDX51"></A> <A NAME="IDX52"></A> The GDB init files are normally called <TT>`.gdbinit'</TT>. The DJGPP port of GDB uses the name <TT>`gdb.ini'</TT>, due to the limitations of file names imposed by DOS filesystems. The Windows ports of GDB use the standard name, but if they find a <TT>`gdb.ini'</TT> file, they warn you about that and suggest to rename the file to the standard name. </P><P> <A NAME="Quitting GDB"></A> <HR SIZE="6"> <A NAME="SEC11"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC10"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC12"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC12"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC6"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_4.html#SEC14"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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_38.html#SEC764">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H2> 2.2 Quitting GDB </H2> <!--docid::SEC11::--> <P> <DL COMPACT> <A NAME="IDX53"></A> <A NAME="IDX54"></A> <DT><CODE>quit [<VAR>expression</VAR>]</CODE> <DD><DT><CODE>q</CODE> <DD>To exit GDB, use the <CODE>quit</CODE> command (abbreviated <CODE>q</CODE>), or type an end-of-file character (usually <KBD>Ctrl-d</KBD>). If you do not supply <VAR>expression</VAR>, GDB will terminate normally; otherwise it will terminate using the result of <VAR>expression</VAR> as the error code. </DL> <P> <A NAME="IDX55"></A> An interrupt (often <KBD>Ctrl-c</KBD>) does not exit from GDB, but rather terminates the action of any GDB command that is in progress and returns to GDB command level. It is safe to type the interrupt character at any time because GDB does not allow it to take effect until a time when it is safe. </P><P> If you have been using GDB to control an attached process or device, you can release it with the <CODE>detach</CODE> command (see section <A HREF="gdb_5.html#SEC25">Debugging an Already-running Process</A>). </P><P> <A NAME="Shell Commands"></A> <HR SIZE="6"> <A NAME="SEC12"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC11"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC13"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC13"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC6"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_4.html#SEC14"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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_38.html#SEC764">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H2> 2.3 Shell Commands </H2> <!--docid::SEC12::--> <P> If you need to execute occasional shell commands during your debugging session, there is no need to leave or suspend GDB; you can just use the <CODE>shell</CODE> command. </P><P> <DL COMPACT> <A NAME="IDX56"></A> <A NAME="IDX57"></A> <DT><CODE>shell <VAR>command string</VAR></CODE> <DD>Invoke a standard shell to execute <VAR>command string</VAR>. If it exists, the environment variable <CODE>SHELL</CODE> determines which shell to run. Otherwise GDB uses the default shell (<TT>`/bin/sh'</TT> on Unix systems, <TT>`COMMAND.COM'</TT> on MS-DOS, etc.). </DL> <P> The utility <CODE>make</CODE> is often needed in development environments. You do not have to use the <CODE>shell</CODE> command for this purpose in GDB: </P><P> <DL COMPACT> <A NAME="IDX58"></A> <A NAME="IDX59"></A> <DT><CODE>make <VAR>make-args</VAR></CODE> <DD>Execute the <CODE>make</CODE> program with the specified arguments. This is equivalent to <SAMP>`shell make <VAR>make-args</VAR>'</SAMP>. </DL> <P> <A NAME="Logging Output"></A> <HR SIZE="6"> <A NAME="SEC13"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC12"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_4.html#SEC14"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC6"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC6"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_4.html#SEC14"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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_38.html#SEC764">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H2> 2.4 Logging Output </H2> <!--docid::SEC13::--> <P> You may want to save the output of GDB commands to a file. There are several commands to control GDB's logging. </P><P> <DL COMPACT> <A NAME="IDX60"></A> <DT><CODE>set logging on</CODE> <DD>Enable logging. <DT><CODE>set logging off</CODE> <DD>Disable logging. <A NAME="IDX61"></A> <DT><CODE>set logging file <VAR>file</VAR></CODE> <DD>Change the name of the current logfile. The default logfile is <TT>`gdb.txt'</TT>. <DT><CODE>set logging overwrite [on|off]</CODE> <DD>By default, GDB will append to the logfile. Set <CODE>overwrite</CODE> if you want <CODE>set logging on</CODE> to overwrite the logfile instead. <DT><CODE>set logging redirect [on|off]</CODE> <DD>By default, GDB output will go to both the terminal and the logfile. Set <CODE>redirect</CODE> if you want output to go only to the log file. <A NAME="IDX62"></A> <DT><CODE>show logging</CODE> <DD>Show the current values of the logging settings. </DL> <P> <A NAME="Commands"></A> <HR SIZE="6"> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC6"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_4.html#SEC14"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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_38.html#SEC764">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 & GNU inquiries & 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>March, 27 2008</I> using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html "><I>texi2html</I></A> </BODY> </HTML>