toolchain/share/doc/gdb/gdb-man.html

222 lines
12 KiB
HTML
Raw Permalink Normal View History

2024-01-10 05:24:32 +00:00
<html lang="en">
<head>
<title>gdb man - Debugging with GDB</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Debugging with GDB">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Man-Pages.html#Man-Pages" title="Man Pages">
<link rel="next" href="gdbserver-man.html#gdbserver-man" title="gdbserver man">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 1988-2019 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU 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 GNU Manual,''
and with the Back-Cover Texts as in (a) below.
(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
this GNU Manual. Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom.''
-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="gdb-man"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="gdbserver-man.html#gdbserver-man">gdbserver man</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Man-Pages.html#Man-Pages">Man Pages</a>
<hr>
</div>
<h3 class="heading">gdb man</h3>
<!-- man title gdb The GNU Debugger -->
<!-- man begin SYNOPSIS gdb -->
<p>gdb [<samp><span class="option">-help</span></samp>] [<samp><span class="option">-nh</span></samp>] [<samp><span class="option">-nx</span></samp>] [<samp><span class="option">-q</span></samp>]
[<samp><span class="option">-batch</span></samp>] [<samp><span class="option">-cd=</span></samp><var>dir</var>] [<samp><span class="option">-f</span></samp>]
[<samp><span class="option">-b</span></samp>&nbsp;<!-- /@w --><var>bps</var>]
[<samp><span class="option">-tty=</span></samp><var>dev</var>] [<samp><span class="option">-s</span></samp> <var>symfile</var>]
[<samp><span class="option">-e</span></samp>&nbsp;<!-- /@w --><var>prog</var>] [<samp><span class="option">-se</span></samp>&nbsp;<!-- /@w --><var>prog</var>]
[<samp><span class="option">-c</span></samp>&nbsp;<!-- /@w --><var>core</var>] [<samp><span class="option">-p</span></samp>&nbsp;<!-- /@w --><var>procID</var>]
[<samp><span class="option">-x</span></samp>&nbsp;<!-- /@w --><var>cmds</var>] [<samp><span class="option">-d</span></samp>&nbsp;<!-- /@w --><var>dir</var>]
[<var>prog</var>|<var>prog</var> <var>procID</var>|<var>prog</var> <var>core</var>]
<!-- man end -->
<!-- man begin DESCRIPTION gdb -->
<p>The purpose of a debugger such as <span class="sc">gdb</span> is to allow you to see what is
going on &ldquo;inside&rdquo; another program while it executes &ndash; or what another
program was doing at the moment it crashed.
<p><span class="sc">gdb</span> can do four main kinds of things (plus other things in support of
these) to help you catch bugs in the act:
<ul>
<li>Start your program, specifying anything that might affect its behavior.
<li>Make your program stop on specified conditions.
<li>Examine what has happened, when your program has stopped.
<li>Change things in your program, so you can experiment with correcting the
effects of one bug and go on to learn about another.
</ul>
<p>You can use <span class="sc">gdb</span> to debug programs written in C, C<tt>++</tt>, Fortran and
Modula-2.
<p><span class="sc">gdb</span> is invoked with the shell command <code>gdb</code>. Once started, it reads
commands from the terminal until you tell it to exit with the <span class="sc">gdb</span>
command <code>quit</code>. You can get online help from <span class="sc">gdb</span> itself
by using the command <code>help</code>.
<p>You can run <code>gdb</code> with no arguments or options; but the most
usual way to start <span class="sc">gdb</span> is with one argument or two, specifying an
executable program as the argument:
<pre class="smallexample"> gdb program
</pre>
<p>You can also start with both an executable program and a core file specified:
<pre class="smallexample"> gdb program core
</pre>
<p>You can, instead, specify a process ID as a second argument, if you want
to debug a running process:
<pre class="smallexample"> gdb program 1234
gdb -p 1234
</pre>
<p class="noindent">would attach <span class="sc">gdb</span> to process <code>1234</code> (unless you also have a file
named <samp><span class="file">1234</span></samp>; <span class="sc">gdb</span> does check for a core file first).
With option <samp><span class="option">-p</span></samp> you can omit the <var>program</var> filename.
<p>Here are some of the most frequently needed <span class="sc">gdb</span> commands:
<!-- pod2man highlights the right hand side of the @item lines. -->
<dl>
<dt><samp><span class="env">break [</span><var>file</var><span class="env">:]</span><var>function</var></samp><dd>Set a breakpoint at <var>function</var> (in <var>file</var>).
<br><dt><samp><span class="env">run [</span><var>arglist</var><span class="env">]</span></samp><dd>Start your program (with <var>arglist</var>, if specified).
<br><dt><samp><span class="env">bt</span></samp><dd>Backtrace: display the program stack.
<br><dt><samp><span class="env">print </span><var>expr</var></samp><dd>Display the value of an expression.
<br><dt><samp><span class="env">c</span></samp><dd>Continue running your program (after stopping, e.g. at a breakpoint).
<br><dt><samp><span class="env">next</span></samp><dd>Execute next program line (after stopping); step <em>over</em> any
function calls in the line.
<br><dt><samp><span class="env">edit [</span><var>file</var><span class="env">:]</span><var>function</var></samp><dd>look at the program line where it is presently stopped.
<br><dt><samp><span class="env">list [</span><var>file</var><span class="env">:]</span><var>function</var></samp><dd>type the text of the program in the vicinity of where it is presently stopped.
<br><dt><samp><span class="env">step</span></samp><dd>Execute next program line (after stopping); step <em>into</em> any
function calls in the line.
<br><dt><samp><span class="env">help [</span><var>name</var><span class="env">]</span></samp><dd>Show information about <span class="sc">gdb</span> command <var>name</var>, or general information
about using <span class="sc">gdb</span>.
<br><dt><samp><span class="env">quit</span></samp><dd>Exit from <span class="sc">gdb</span>.
</dl>
<!-- man end -->
<!-- man begin OPTIONS gdb -->
<p>Any arguments other than options specify an executable
file and core file (or process ID); that is, the first argument
encountered with no
associated option flag is equivalent to a <samp><span class="option">-se</span></samp> option, and the second,
if any, is equivalent to a <samp><span class="option">-c</span></samp> 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 <samp><span class="option">+</span></samp> rather than <samp><span class="option">-</span></samp>, 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 <samp><span class="option">-x</span></samp>
option is used.
<dl>
<dt><samp><span class="env">-help</span></samp><dt><samp><span class="env">-h</span></samp><dd>List all options, with brief explanations.
<br><dt><samp><span class="env">-symbols=</span><var>file</var></samp><dt><samp><span class="env">-s </span><var>file</var></samp><dd>Read symbol table from file <var>file</var>.
<br><dt><samp><span class="env">-write</span></samp><dd>Enable writing into executable and core files.
<br><dt><samp><span class="env">-exec=</span><var>file</var></samp><dt><samp><span class="env">-e </span><var>file</var></samp><dd>Use file <var>file</var> as the executable file to execute when
appropriate, and for examining pure data in conjunction with a core
dump.
<br><dt><samp><span class="env">-se=</span><var>file</var></samp><dd>Read symbol table from file <var>file</var> and use it as the executable
file.
<br><dt><samp><span class="env">-core=</span><var>file</var></samp><dt><samp><span class="env">-c </span><var>file</var></samp><dd>Use file <var>file</var> as a core dump to examine.
<br><dt><samp><span class="env">-command=</span><var>file</var></samp><dt><samp><span class="env">-x </span><var>file</var></samp><dd>Execute <span class="sc">gdb</span> commands from file <var>file</var>.
<br><dt><samp><span class="env">-ex </span><var>command</var></samp><dd>Execute given <span class="sc">gdb</span> <var>command</var>.
<br><dt><samp><span class="env">-directory=</span><var>directory</var></samp><dt><samp><span class="env">-d </span><var>directory</var></samp><dd>Add <var>directory</var> to the path to search for source files.
<br><dt><samp><span class="env">-nh</span></samp><dd>Do not execute commands from <samp><span class="file">~/.gdbinit</span></samp>.
<br><dt><samp><span class="env">-nx</span></samp><dt><samp><span class="env">-n</span></samp><dd>Do not execute commands from any <samp><span class="file">.gdbinit</span></samp> initialization files.
<br><dt><samp><span class="env">-quiet</span></samp><dt><samp><span class="env">-q</span></samp><dd>&ldquo;Quiet&rdquo;. Do not print the introductory and copyright messages. These
messages are also suppressed in batch mode.
<br><dt><samp><span class="env">-batch</span></samp><dd>Run in batch mode. Exit with status <code>0</code> after processing all the command
files specified with <samp><span class="option">-x</span></samp> (and <samp><span class="file">.gdbinit</span></samp>, if not inhibited).
Exit with nonzero status if an error occurs in executing the <span class="sc">gdb</span>
commands in the command files.
<p>Batch mode may be useful for running <span class="sc">gdb</span> as a filter, for example to
download and run a program on another computer; in order to make this
more useful, the message
<pre class="smallexample"> Program exited normally.
</pre>
<p class="noindent">(which is ordinarily issued whenever a program running under <span class="sc">gdb</span> control
terminates) is not issued when running in batch mode.
<br><dt><samp><span class="env">-cd=</span><var>directory</var></samp><dd>Run <span class="sc">gdb</span> using <var>directory</var> as its working directory,
instead of the current directory.
<br><dt><samp><span class="env">-fullname</span></samp><dt><samp><span class="env">-f</span></samp><dd>Emacs sets this option when it runs <span class="sc">gdb</span> as a subprocess. It tells
<span class="sc">gdb</span> 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 &lsquo;<samp><span class="samp">\032</span></samp>&rsquo; characters, followed by the file name, line number
and character position separated by colons, and a newline. The
Emacs-to-<span class="sc">gdb</span> interface program uses the two &lsquo;<samp><span class="samp">\032</span></samp>&rsquo;
characters as a signal to display the source code for the frame.
<br><dt><samp><span class="env">-b </span><var>bps</var></samp><dd>Set the line speed (baud rate or bits per second) of any serial
interface used by <span class="sc">gdb</span> for remote debugging.
<br><dt><samp><span class="env">-tty=</span><var>device</var></samp><dd>Run using <var>device</var> for your program's standard input and output.
</dl>
<!-- man end -->
<!-- man begin SEEALSO gdb -->
<!-- man end -->
</body></html>