man-pages/man1/gdb.1.html
2021-03-31 01:06:50 +01:00

412 lines
10 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of GDB</TITLE>
</HEAD><BODY>
<H1>GDB</H1>
Section: GNU Development Tools (1)<BR>Updated: 2020-08-04<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
gdb - The GNU Debugger
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
gdb [<B>-help</B>] [<B>-nh</B>] [<B>-nx</B>] [<B>-q</B>]
[<B>-batch</B>] [<B>-cd=</B><I>dir</I>] [<B>-f</B>]
[<B>-b</B>&nbsp;<I>bps</I>]
<BR>&nbsp;&nbsp;&nbsp;&nbsp;[<B>-tty=</B><I>dev</I>]&nbsp;[<B>-s</B>&nbsp;<I>symfile</I>]
[<B>-e</B>&nbsp;<I>prog</I>] [<B>-se</B>&nbsp;<I>prog</I>]
[<B>-c</B>&nbsp;<I>core</I>] [<B>-p</B>&nbsp;<I>procID</I>]
<BR>&nbsp;&nbsp;&nbsp;&nbsp;[<B>-x</B>&nbsp;<I>cmds</I>]&nbsp;[<B>-d</B>&nbsp;<I>dir</I>]
[<I>prog</I>|<I>prog</I> <I>procID</I>|<I>prog</I> <I>core</I>]
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The purpose of a debugger such as <FONT SIZE="-1">GDB</FONT> is to allow you to see what is
going on ``inside'' another program while it executes --- or what another
program was doing at the moment it crashed.
<P>
<FONT SIZE="-1">GDB</FONT> can do four main kinds of things (plus other things in support of
these) to help you catch bugs in the act:
<DL COMPACT>
<DT id="1">&bull;<DD>
Start your program, specifying anything that might affect its behavior.
<DT id="2">&bull;<DD>
Make your program stop on specified conditions.
<DT id="3">&bull;<DD>
Examine what has happened, when your program has stopped.
<DT id="4">&bull;<DD>
Change things in your program, so you can experiment with correcting the
effects of one bug and go on to learn about another.
</DL>
<P>
You can use <FONT SIZE="-1">GDB</FONT> to debug programs written in C, C@t{++}, Fortran and
Modula-2.
<P>
<FONT SIZE="-1">GDB</FONT> is invoked with the shell command <TT>&quot;gdb&quot;</TT>. Once started, it reads
commands from the terminal until you tell it to exit with the <FONT SIZE="-1">GDB</FONT>
command <TT>&quot;quit&quot;</TT>. You can get online help from <FONT SIZE="-1">GDB</FONT> itself
by using the command <TT>&quot;help&quot;</TT>.
<P>
You can run <TT>&quot;gdb&quot;</TT> with no arguments or options; but the most
usual way to start <FONT SIZE="-1">GDB</FONT> is with one argument or two, specifying an
executable program as the argument:
<P>
<PRE>
gdb program
</PRE>
<P>
You can also start with both an executable program and a core file specified:
<P>
<PRE>
gdb program core
</PRE>
<P>
You can, instead, specify a process <FONT SIZE="-1">ID</FONT> as a second argument or use option
<TT>&quot;-p&quot;</TT>, if you want to debug a running process:
<P>
<PRE>
gdb program 1234
gdb -p 1234
</PRE>
<P>
would attach <FONT SIZE="-1">GDB</FONT> to process <TT>1234</TT>. With option <B>-p</B> you
can omit the <I>program</I> filename.
<P>
Here are some of the most frequently needed <FONT SIZE="-1">GDB</FONT> commands:
<DL COMPACT>
<DT id="5"><B>break [</B><I>file</I><B>:]</B><I>function</I><DD>
Set a breakpoint at <I>function</I> (in <I>file</I>).
<DT id="6"><B>run [</B><I>arglist</I><B>]</B><DD>
Start your program (with <I>arglist</I>, if specified).
<DT id="7"><B>bt</B><DD>
Backtrace: display the program stack.
<DT id="8"><B>print</B> <I>expr</I><DD>
Display the value of an expression.
<DT id="9"><B>c</B><DD>
Continue running your program (after stopping, e.g. at a breakpoint).
<DT id="10"><B>next</B><DD>
Execute next program line (after stopping); step <I>over</I> any
function calls in the line.
<DT id="11"><B>edit [</B><I>file</I><B>:]</B><I>function</I><DD>
look at the program line where it is presently stopped.
<DT id="12"><B>list [</B><I>file</I><B>:]</B><I>function</I><DD>
type the text of the program in the vicinity of where it is presently stopped.
<DT id="13"><B>step</B><DD>
Execute next program line (after stopping); step <I>into</I> any
function calls in the line.
<DT id="14"><B>help [</B><I>name</I><B>]</B><DD>
Show information about <FONT SIZE="-1">GDB</FONT> command <I>name</I>, or general information
about using <FONT SIZE="-1">GDB.</FONT>
<DT id="15"><B>quit</B><DD>
Exit from <FONT SIZE="-1">GDB.</FONT>
</DL>
<P>
For full details on <FONT SIZE="-1">GDB,</FONT>
see <I>Using </I><FONT SIZE="-1"><I>GDB: A</I></FONT><I> Guide to the </I><FONT SIZE="-1"><I>GNU</I></FONT><I> Source-Level Debugger</I>,
by Richard M. Stallman and Roland H. Pesch. The same text is available online
as the <TT>&quot;gdb&quot;</TT> entry in the <TT>&quot;info&quot;</TT> program.
<A NAME="lbAE">&nbsp;</A>
<H2>OPTIONS</H2>
Any arguments other than options specify an executable
file and core file (or process <FONT SIZE="-1">ID</FONT>); that is, the first argument
encountered with no
associated option flag is equivalent to a <B>-se</B> option, and the second,
if any, is equivalent to a <B>-c</B> option if it's the name of a file.
Many options have
both long and short forms; both are shown here. The long forms are also
recognized 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 <B>+</B> rather than <B>-</B>, though we illustrate the
more usual convention.)
<P>
All the options and command line arguments you give are processed
in sequential order. The order makes a difference when the <B>-x</B>
option is used.
<DL COMPACT>
<DT id="16"><B>-help</B><DD>
<DT id="17"><B>-h</B><DD>
List all options, with brief explanations.
<DT id="18"><B>-symbols=</B><I>file</I><DD>
<DT id="19"><B>-s</B> <I>file</I><DD>
Read symbol table from file <I>file</I>.
<DT id="20"><B>-write</B><DD>
Enable writing into executable and core files.
<DT id="21"><B>-exec=</B><I>file</I><DD>
<DT id="22"><B>-e</B> <I>file</I><DD>
Use file <I>file</I> as the executable file to execute when
appropriate, and for examining pure data in conjunction with a core
dump.
<DT id="23"><B>-se=</B><I>file</I><DD>
Read symbol table from file <I>file</I> and use it as the executable
file.
<DT id="24"><B>-core=</B><I>file</I><DD>
<DT id="25"><B>-c</B> <I>file</I><DD>
Use file <I>file</I> as a core dump to examine.
<DT id="26"><B>-command=</B><I>file</I><DD>
<DT id="27"><B>-x</B> <I>file</I><DD>
Execute <FONT SIZE="-1">GDB</FONT> commands from file <I>file</I>.
<DT id="28"><B>-ex</B> <I>command</I><DD>
Execute given <FONT SIZE="-1">GDB</FONT> <I>command</I>.
<DT id="29"><B>-directory=</B><I>directory</I><DD>
<DT id="30"><B>-d</B> <I>directory</I><DD>
Add <I>directory</I> to the path to search for source files.
<DT id="31"><B>-nh</B><DD>
Do not execute commands from <I>~/.gdbinit</I>.
<DT id="32"><B>-nx</B><DD>
<DT id="33"><B>-n</B><DD>
Do not execute commands from any <I>.gdbinit</I> initialization files.
<DT id="34"><B>-quiet</B><DD>
<DT id="35"><B>-q</B><DD>
``Quiet''. Do not print the introductory and copyright messages. These
messages are also suppressed in batch mode.
<DT id="36"><B>-batch</B><DD>
Run in batch mode. Exit with status <TT>0</TT> after processing all the command
files specified with <B>-x</B> (and <I>.gdbinit</I>, if not inhibited).
Exit with nonzero status if an error occurs in executing the <FONT SIZE="-1">GDB</FONT>
commands in the command files.
<P>
Batch mode may be useful for running <FONT SIZE="-1">GDB</FONT> as a filter, for example to
download and run a program on another computer; in order to make this
more useful, the message
<P>
<PRE>
Program exited normally.
</PRE>
<P>
(which is ordinarily issued whenever a program running under <FONT SIZE="-1">GDB</FONT> control
terminates) is not issued when running in batch mode.
<DT id="37"><B>-cd=</B><I>directory</I><DD>
Run <FONT SIZE="-1">GDB</FONT> using <I>directory</I> as its working directory,
instead of the current directory.
<DT id="38"><B>-fullname</B><DD>
<DT id="39"><B>-f</B><DD>
Emacs sets this option when it runs <FONT SIZE="-1">GDB</FONT> as a subprocess. It tells
<FONT SIZE="-1">GDB</FONT> 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 the program stops). This recognizable format looks
like two <B>\032</B> 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 <B>\032</B>
characters as a signal to display the source code for the frame.
<DT id="40"><B>-b</B> <I>bps</I><DD>
Set the line speed (baud rate or bits per second) of any serial
interface used by <FONT SIZE="-1">GDB</FONT> for remote debugging.
<DT id="41"><B>-tty=</B><I>device</I><DD>
Run using <I>device</I> for your program's standard input and output.
</DL>
<A NAME="lbAF">&nbsp;</A>
<H2>SEE ALSO</H2>
The full documentation for <FONT SIZE="-1">GDB</FONT> is maintained as a Texinfo manual.
If the <TT>&quot;info&quot;</TT> and <TT>&quot;gdb&quot;</TT> programs and <FONT SIZE="-1">GDB</FONT>'s Texinfo
documentation are properly installed at your site, the command
<P>
<PRE>
info gdb
</PRE>
<P>
should give you access to the complete manual.
<P>
<I>Using </I><FONT SIZE="-1"><I>GDB: A</I></FONT><I> Guide to the </I><FONT SIZE="-1"><I>GNU</I></FONT><I> Source-Level Debugger</I>,
Richard M. Stallman and Roland H. Pesch, July 1991.
<A NAME="lbAG">&nbsp;</A>
<H2>COPYRIGHT</H2>
Copyright (c) 1988-2020 Free Software Foundation, Inc.
<P>
Permission is granted to copy, distribute and/or modify this document
under the terms of the <FONT SIZE="-1">GNU</FONT> Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software'' and ``Free Software Needs
Free Documentation'', with the Front-Cover Texts being ``A <FONT SIZE="-1">GNU</FONT> Manual,''
and with the Back-Cover Texts as in (a) below.
<P>
(a) The <FONT SIZE="-1">FSF</FONT>'s Back-Cover Text is: ``You are free to copy and modify
this <FONT SIZE="-1">GNU</FONT> Manual. Buying copies from <FONT SIZE="-1">GNU</FONT> Press supports the <FONT SIZE="-1">FSF</FONT> in
developing <FONT SIZE="-1">GNU</FONT> and promoting software freedom.''
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="42"><A HREF="#lbAB">NAME</A><DD>
<DT id="43"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="44"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="45"><A HREF="#lbAE">OPTIONS</A><DD>
<DT id="46"><A HREF="#lbAF">SEE ALSO</A><DD>
<DT id="47"><A HREF="#lbAG">COPYRIGHT</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:13 GMT, March 31, 2021
</BODY>
</HTML>