412 lines
10 KiB
HTML
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"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
gdb - The GNU Debugger
|
|
<A NAME="lbAC"> </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> <I>bps</I>]
|
|
<BR> [<B>-tty=</B><I>dev</I>] [<B>-s</B> <I>symfile</I>]
|
|
[<B>-e</B> <I>prog</I>] [<B>-se</B> <I>prog</I>]
|
|
[<B>-c</B> <I>core</I>] [<B>-p</B> <I>procID</I>]
|
|
<BR> [<B>-x</B> <I>cmds</I>] [<B>-d</B> <I>dir</I>]
|
|
[<I>prog</I>|<I>prog</I> <I>procID</I>|<I>prog</I> <I>core</I>]
|
|
<A NAME="lbAD"> </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">•<DD>
|
|
Start your program, specifying anything that might affect its behavior.
|
|
<DT id="2">•<DD>
|
|
Make your program stop on specified conditions.
|
|
<DT id="3">•<DD>
|
|
Examine what has happened, when your program has stopped.
|
|
<DT id="4">•<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>"gdb"</TT>. Once started, it reads
|
|
commands from the terminal until you tell it to exit with the <FONT SIZE="-1">GDB</FONT>
|
|
command <TT>"quit"</TT>. You can get online help from <FONT SIZE="-1">GDB</FONT> itself
|
|
by using the command <TT>"help"</TT>.
|
|
<P>
|
|
|
|
You can run <TT>"gdb"</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>"-p"</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>"gdb"</TT> entry in the <TT>"info"</TT> program.
|
|
<A NAME="lbAE"> </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"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
|
|
|
|
The full documentation for <FONT SIZE="-1">GDB</FONT> is maintained as a Texinfo manual.
|
|
If the <TT>"info"</TT> and <TT>"gdb"</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"> </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"> </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>
|