gdb-man.html 12 KB

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