You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

319 line
12KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Free Software" and "Free Software Needs
  8. Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
  9. and with the Back-Cover Texts as in (a) below.
  10. (a) The FSF's Back-Cover Text is: "You are free to copy and modify
  11. this GNU Manual. Buying copies from GNU Press supports the FSF in
  12. developing GNU and promoting software freedom." -->
  13. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  16. <title>gdb man (Debugging with GDB)</title>
  17. <meta name="description" content="gdb man (Debugging with GDB)">
  18. <meta name="keywords" content="gdb man (Debugging with GDB)">
  19. <meta name="resource-type" content="document">
  20. <meta name="distribution" content="global">
  21. <meta name="Generator" content="makeinfo">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="Man-Pages.html#Man-Pages" rel="up" title="Man Pages">
  26. <link href="gdbserver-man.html#gdbserver-man" rel="next" title="gdbserver man">
  27. <link href="Man-Pages.html#Man-Pages" rel="prev" title="Man Pages">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.indentedblock {margin-right: 0em}
  32. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. div.smalldisplay {margin-left: 3.2em}
  38. div.smallexample {margin-left: 3.2em}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style: oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nolinebreak {white-space: nowrap}
  50. span.roman {font-family: initial; font-weight: normal}
  51. span.sansserif {font-family: sans-serif; font-weight: normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en">
  57. <a name="gdb-man"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="gdbserver-man.html#gdbserver-man" accesskey="n" rel="next">gdbserver man</a>, Up: <a href="Man-Pages.html#Man-Pages" accesskey="u" rel="up">Man Pages</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  61. </div>
  62. <hr>
  63. <h4 class="node-heading">gdb man</h4>
  64. <a name="gdb-man-1"></a>
  65. <h3 class="heading">gdb man</h3>
  66. <p>gdb [<samp>-help</samp>] [<samp>-nh</samp>] [<samp>-nx</samp>] [<samp>-q</samp>]
  67. [<samp>-batch</samp>] [<samp>-cd=</samp><var>dir</var>] [<samp>-f</samp>]
  68. [<samp>-b</samp>&nbsp;<!-- /@w --><var>bps</var>]
  69. [<samp>-tty=</samp><var>dev</var>] [<samp>-s</samp> <var>symfile</var>]
  70. [<samp>-e</samp>&nbsp;<!-- /@w --><var>prog</var>] [<samp>-se</samp>&nbsp;<!-- /@w --><var>prog</var>]
  71. [<samp>-c</samp>&nbsp;<!-- /@w --><var>core</var>] [<samp>-p</samp>&nbsp;<!-- /@w --><var>procID</var>]
  72. [<samp>-x</samp>&nbsp;<!-- /@w --><var>cmds</var>] [<samp>-d</samp>&nbsp;<!-- /@w --><var>dir</var>]
  73. [<var>prog</var>|<var>prog</var> <var>procID</var>|<var>prog</var> <var>core</var>]
  74. </p>
  75. <p>The purpose of a debugger such as <small>GDB</small> is to allow you to see what is
  76. going on &ldquo;inside&rdquo; another program while it executes &ndash; or what another
  77. program was doing at the moment it crashed.
  78. </p>
  79. <p><small>GDB</small> can do four main kinds of things (plus other things in support of
  80. these) to help you catch bugs in the act:
  81. </p>
  82. <ul>
  83. <li> Start your program, specifying anything that might affect its behavior.
  84. </li><li> Make your program stop on specified conditions.
  85. </li><li> Examine what has happened, when your program has stopped.
  86. </li><li> Change things in your program, so you can experiment with correcting the
  87. effects of one bug and go on to learn about another.
  88. </li></ul>
  89. <p>You can use <small>GDB</small> to debug programs written in C, C<tt>++</tt>, Fortran and
  90. Modula-2.
  91. </p>
  92. <p><small>GDB</small> is invoked with the shell command <code>gdb</code>. Once started, it reads
  93. commands from the terminal until you tell it to exit with the <small>GDB</small>
  94. command <code>quit</code>. You can get online help from <small>GDB</small> itself
  95. by using the command <code>help</code>.
  96. </p>
  97. <p>You can run <code>gdb</code> with no arguments or options; but the most
  98. usual way to start <small>GDB</small> is with one argument or two, specifying an
  99. executable program as the argument:
  100. </p>
  101. <div class="smallexample">
  102. <pre class="smallexample">gdb program
  103. </pre></div>
  104. <p>You can also start with both an executable program and a core file specified:
  105. </p>
  106. <div class="smallexample">
  107. <pre class="smallexample">gdb program core
  108. </pre></div>
  109. <p>You can, instead, specify a process ID as a second argument or use option
  110. <code>-p</code>, if you want to debug a running process:
  111. </p>
  112. <div class="smallexample">
  113. <pre class="smallexample">gdb program 1234
  114. gdb -p 1234
  115. </pre></div>
  116. <p>would attach <small>GDB</small> to process <code>1234</code>. With option <samp>-p</samp> you
  117. can omit the <var>program</var> filename.
  118. </p>
  119. <p>Here are some of the most frequently needed <small>GDB</small> commands:
  120. </p>
  121. <dl compact="compact">
  122. <dt><code>break [<var>file</var>:]<var>function</var></code></dt>
  123. <dd><p>Set a breakpoint at <var>function</var> (in <var>file</var>).
  124. </p>
  125. </dd>
  126. <dt><code>run [<var>arglist</var>]</code></dt>
  127. <dd><p>Start your program (with <var>arglist</var>, if specified).
  128. </p>
  129. </dd>
  130. <dt><code>bt</code></dt>
  131. <dd><p>Backtrace: display the program stack.
  132. </p>
  133. </dd>
  134. <dt><code>print <var>expr</var></code></dt>
  135. <dd><p>Display the value of an expression.
  136. </p>
  137. </dd>
  138. <dt><code>c</code></dt>
  139. <dd><p>Continue running your program (after stopping, e.g. at a breakpoint).
  140. </p>
  141. </dd>
  142. <dt><code>next</code></dt>
  143. <dd><p>Execute next program line (after stopping); step <em>over</em> any
  144. function calls in the line.
  145. </p>
  146. </dd>
  147. <dt><code>edit [<var>file</var>:]<var>function</var></code></dt>
  148. <dd><p>look at the program line where it is presently stopped.
  149. </p>
  150. </dd>
  151. <dt><code>list [<var>file</var>:]<var>function</var></code></dt>
  152. <dd><p>type the text of the program in the vicinity of where it is presently stopped.
  153. </p>
  154. </dd>
  155. <dt><code>step</code></dt>
  156. <dd><p>Execute next program line (after stopping); step <em>into</em> any
  157. function calls in the line.
  158. </p>
  159. </dd>
  160. <dt><code>help [<var>name</var>]</code></dt>
  161. <dd><p>Show information about <small>GDB</small> command <var>name</var>, or general information
  162. about using <small>GDB</small>.
  163. </p>
  164. </dd>
  165. <dt><code>quit</code></dt>
  166. <dd><p>Exit from <small>GDB</small>.
  167. </p></dd>
  168. </dl>
  169. <p>Any arguments other than options specify an executable
  170. file and core file (or process ID); that is, the first argument
  171. encountered with no
  172. associated option flag is equivalent to a <samp>-se</samp> option, and the second,
  173. if any, is equivalent to a <samp>-c</samp> option if it&rsquo;s the name of a file.
  174. Many options have
  175. both long and short forms; both are shown here. The long forms are also
  176. recognized if you truncate them, so long as enough of the option is
  177. present to be unambiguous. (If you prefer, you can flag option
  178. arguments with <samp>+</samp> rather than <samp>-</samp>, though we illustrate the
  179. more usual convention.)
  180. </p>
  181. <p>All the options and command line arguments you give are processed
  182. in sequential order. The order makes a difference when the <samp>-x</samp>
  183. option is used.
  184. </p>
  185. <dl compact="compact">
  186. <dt><code>-help</code></dt>
  187. <dt><code>-h</code></dt>
  188. <dd><p>List all options, with brief explanations.
  189. </p>
  190. </dd>
  191. <dt><code>-symbols=<var>file</var></code></dt>
  192. <dt><code>-s <var>file</var></code></dt>
  193. <dd><p>Read symbol table from file <var>file</var>.
  194. </p>
  195. </dd>
  196. <dt><code>-write</code></dt>
  197. <dd><p>Enable writing into executable and core files.
  198. </p>
  199. </dd>
  200. <dt><code>-exec=<var>file</var></code></dt>
  201. <dt><code>-e <var>file</var></code></dt>
  202. <dd><p>Use file <var>file</var> as the executable file to execute when
  203. appropriate, and for examining pure data in conjunction with a core
  204. dump.
  205. </p>
  206. </dd>
  207. <dt><code>-se=<var>file</var></code></dt>
  208. <dd><p>Read symbol table from file <var>file</var> and use it as the executable
  209. file.
  210. </p>
  211. </dd>
  212. <dt><code>-core=<var>file</var></code></dt>
  213. <dt><code>-c <var>file</var></code></dt>
  214. <dd><p>Use file <var>file</var> as a core dump to examine.
  215. </p>
  216. </dd>
  217. <dt><code>-command=<var>file</var></code></dt>
  218. <dt><code>-x <var>file</var></code></dt>
  219. <dd><p>Execute <small>GDB</small> commands from file <var>file</var>.
  220. </p>
  221. </dd>
  222. <dt><code>-ex <var>command</var></code></dt>
  223. <dd><p>Execute given <small>GDB</small> <var>command</var>.
  224. </p>
  225. </dd>
  226. <dt><code>-directory=<var>directory</var></code></dt>
  227. <dt><code>-d <var>directory</var></code></dt>
  228. <dd><p>Add <var>directory</var> to the path to search for source files.
  229. </p>
  230. </dd>
  231. <dt><code>-nh</code></dt>
  232. <dd><p>Do not execute commands from <samp>~/.gdbinit</samp>.
  233. </p>
  234. </dd>
  235. <dt><code>-nx</code></dt>
  236. <dt><code>-n</code></dt>
  237. <dd><p>Do not execute commands from any <samp>.gdbinit</samp> initialization files.
  238. </p>
  239. </dd>
  240. <dt><code>-quiet</code></dt>
  241. <dt><code>-q</code></dt>
  242. <dd><p>&ldquo;Quiet&rdquo;. Do not print the introductory and copyright messages. These
  243. messages are also suppressed in batch mode.
  244. </p>
  245. </dd>
  246. <dt><code>-batch</code></dt>
  247. <dd><p>Run in batch mode. Exit with status <code>0</code> after processing all the command
  248. files specified with <samp>-x</samp> (and <samp>.gdbinit</samp>, if not inhibited).
  249. Exit with nonzero status if an error occurs in executing the <small>GDB</small>
  250. commands in the command files.
  251. </p>
  252. <p>Batch mode may be useful for running <small>GDB</small> as a filter, for example to
  253. download and run a program on another computer; in order to make this
  254. more useful, the message
  255. </p>
  256. <div class="smallexample">
  257. <pre class="smallexample">Program exited normally.
  258. </pre></div>
  259. <p>(which is ordinarily issued whenever a program running under <small>GDB</small> control
  260. terminates) is not issued when running in batch mode.
  261. </p>
  262. </dd>
  263. <dt><code>-cd=<var>directory</var></code></dt>
  264. <dd><p>Run <small>GDB</small> using <var>directory</var> as its working directory,
  265. instead of the current directory.
  266. </p>
  267. </dd>
  268. <dt><code>-fullname</code></dt>
  269. <dt><code>-f</code></dt>
  270. <dd><p>Emacs sets this option when it runs <small>GDB</small> as a subprocess. It tells
  271. <small>GDB</small> to output the full file name and line number in a standard,
  272. recognizable fashion each time a stack frame is displayed (which
  273. includes each time the program stops). This recognizable format looks
  274. like two &lsquo;<samp>\032</samp>&rsquo; characters, followed by the file name, line number
  275. and character position separated by colons, and a newline. The
  276. Emacs-to-<small>GDB</small> interface program uses the two &lsquo;<samp>\032</samp>&rsquo;
  277. characters as a signal to display the source code for the frame.
  278. </p>
  279. </dd>
  280. <dt><code>-b <var>bps</var></code></dt>
  281. <dd><p>Set the line speed (baud rate or bits per second) of any serial
  282. interface used by <small>GDB</small> for remote debugging.
  283. </p>
  284. </dd>
  285. <dt><code>-tty=<var>device</var></code></dt>
  286. <dd><p>Run using <var>device</var> for your program&rsquo;s standard input and output.
  287. </p></dd>
  288. </dl>
  289. <hr>
  290. <div class="header">
  291. <p>
  292. Next: <a href="gdbserver-man.html#gdbserver-man" accesskey="n" rel="next">gdbserver man</a>, Up: <a href="Man-Pages.html#Man-Pages" accesskey="u" rel="up">Man Pages</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  293. </div>
  294. </body>
  295. </html>