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.

314 lines
13KB

  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>gdbserver man (Debugging with GDB)</title>
  17. <meta name="description" content="gdbserver man (Debugging with GDB)">
  18. <meta name="keywords" content="gdbserver 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="gcore-man.html#gcore-man" rel="next" title="gcore man">
  27. <link href="gdb-man.html#gdb-man" rel="prev" title="gdb man">
  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="gdbserver-man"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="gcore-man.html#gcore-man" accesskey="n" rel="next">gcore man</a>, Previous: <a href="gdb-man.html#gdb-man" accesskey="p" rel="prev">gdb 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">gdbserver man</h4>
  64. <a name="gdbserver-man-1"></a>
  65. <h3 class="heading">gdbserver man</h3>
  66. <div class="format">
  67. <pre class="format">gdbserver <var>comm</var> <var>prog</var> [<var>args</var>&hellip;]
  68. gdbserver &ndash;attach <var>comm</var> <var>pid</var>
  69. gdbserver &ndash;multi <var>comm</var>
  70. </pre></div>
  71. <p><code>gdbserver</code> is a program that allows you to run <small>GDB</small> on a different machine
  72. than the one which is running the program being debugged.
  73. </p>
  74. <a name="Usage-_0028server-_0028target_0029-side_0029"></a>
  75. <h4 class="subheading">Usage (server (target) side)</h4>
  76. <p>First, you need to have a copy of the program you want to debug put onto
  77. the target system. The program can be stripped to save space if needed, as
  78. <code>gdbserver</code> doesn&rsquo;t care about symbols. All symbol handling is taken care of by
  79. the <small>GDB</small> running on the host system.
  80. </p>
  81. <p>To use the server, you log on to the target system, and run the <code>gdbserver</code>
  82. program. You must tell it (a) how to communicate with <small>GDB</small>, (b) the name of
  83. your program, and (c) its arguments. The general syntax is:
  84. </p>
  85. <div class="smallexample">
  86. <pre class="smallexample">target&gt; gdbserver <var>comm</var> <var>program</var> [<var>args</var> ...]
  87. </pre></div>
  88. <p>For example, using a serial port, you might say:
  89. </p>
  90. <div class="smallexample">
  91. <pre class="smallexample">target&gt; gdbserver <samp>/dev/com1</samp> emacs foo.txt
  92. </pre></div>
  93. <p>This tells <code>gdbserver</code> to debug emacs with an argument of foo.txt, and
  94. to communicate with <small>GDB</small> via <samp>/dev/com1</samp>. <code>gdbserver</code> now
  95. waits patiently for the host <small>GDB</small> to communicate with it.
  96. </p>
  97. <p>To use a TCP connection, you could say:
  98. </p>
  99. <div class="smallexample">
  100. <pre class="smallexample">target&gt; gdbserver host:2345 emacs foo.txt
  101. </pre></div>
  102. <p>This says pretty much the same thing as the last example, except that we are
  103. going to communicate with the <code>host</code> <small>GDB</small> via TCP. The <code>host:2345</code> argument means
  104. that we are expecting to see a TCP connection from <code>host</code> to local TCP port
  105. 2345. (Currently, the <code>host</code> part is ignored.) You can choose any number you
  106. want for the port number as long as it does not conflict with any existing TCP
  107. ports on the target system. This same port number must be used in the host
  108. <small>GDB</small>s <code>target remote</code> command, which will be described shortly. Note that if
  109. you chose a port number that conflicts with another service, <code>gdbserver</code> will
  110. print an error message and exit.
  111. </p>
  112. <p><code>gdbserver</code> can also attach to running programs.
  113. This is accomplished via the <samp>--attach</samp> argument. The syntax is:
  114. </p>
  115. <div class="smallexample">
  116. <pre class="smallexample">target&gt; gdbserver --attach <var>comm</var> <var>pid</var>
  117. </pre></div>
  118. <p><var>pid</var> is the process ID of a currently running process. It isn&rsquo;t
  119. necessary to point <code>gdbserver</code> at a binary for the running process.
  120. </p>
  121. <p>To start <code>gdbserver</code> without supplying an initial command to run
  122. or process ID to attach, use the <samp>--multi</samp> command line option.
  123. In such case you should connect using <kbd>target extended-remote</kbd> to start
  124. the program you want to debug.
  125. </p>
  126. <div class="smallexample">
  127. <pre class="smallexample">target&gt; gdbserver --multi <var>comm</var>
  128. </pre></div>
  129. <a name="Usage-_0028host-side_0029"></a>
  130. <h4 class="subheading">Usage (host side)</h4>
  131. <p>You need an unstripped copy of the target program on your host system, since
  132. <small>GDB</small> needs to examine its symbol tables and such. Start up <small>GDB</small> as you normally
  133. would, with the target program as the first argument. (You may need to use the
  134. <samp>--baud</samp> option if the serial line is running at anything except 9600 baud.)
  135. That is <code>gdb TARGET-PROG</code>, or <code>gdb --baud BAUD TARGET-PROG</code>. After that, the only
  136. new command you need to know about is <code>target remote</code>
  137. (or <code>target extended-remote</code>). Its argument is either
  138. a device name (usually a serial device, like <samp>/dev/ttyb</samp>), or a <code>HOST:PORT</code>
  139. descriptor. For example:
  140. </p>
  141. <div class="smallexample">
  142. <pre class="smallexample">(gdb) target remote <samp>/dev/ttyb</samp>
  143. </pre></div>
  144. <p>communicates with the server via serial line <samp>/dev/ttyb</samp>, and:
  145. </p>
  146. <div class="smallexample">
  147. <pre class="smallexample">(gdb) target remote the-target:2345
  148. </pre></div>
  149. <p>communicates via a TCP connection to port 2345 on host &lsquo;the-target&rsquo;, where
  150. you previously started up <code>gdbserver</code> with the same port number. Note that for
  151. TCP connections, you must start up <code>gdbserver</code> prior to using the &lsquo;target remote&rsquo;
  152. command, otherwise you may get an error that looks something like
  153. &lsquo;Connection refused&rsquo;.
  154. </p>
  155. <p><code>gdbserver</code> can also debug multiple inferiors at once,
  156. described in
  157. <a href="Inferiors-Connections-and-Programs.html#Inferiors-Connections-and-Programs">Inferiors Connections and Programs</a>.
  158. In such case use the <code>extended-remote</code> <small>GDB</small> command variant:
  159. </p>
  160. <div class="smallexample">
  161. <pre class="smallexample">(gdb) target extended-remote the-target:2345
  162. </pre></div>
  163. <p>The <code>gdbserver</code> option <samp>--multi</samp> may or may not be used in such
  164. case.
  165. </p>
  166. <p>There are three different modes for invoking <code>gdbserver</code>:
  167. </p>
  168. <ul>
  169. <li> Debug a specific program specified by its program name:
  170. <div class="smallexample">
  171. <pre class="smallexample">gdbserver <var>comm</var> <var>prog</var> [<var>args</var>&hellip;]
  172. </pre></div>
  173. <p>The <var>comm</var> parameter specifies how should the server communicate
  174. with <small>GDB</small>; it is either a device name (to use a serial line),
  175. a TCP port number (<code>:1234</code>), or <code>-</code> or <code>stdio</code> to use
  176. stdin/stdout of <code>gdbserver</code>. Specify the name of the program to
  177. debug in <var>prog</var>. Any remaining arguments will be passed to the
  178. program verbatim. When the program exits, <small>GDB</small> will close the
  179. connection, and <code>gdbserver</code> will exit.
  180. </p>
  181. </li><li> Debug a specific program by specifying the process ID of a running
  182. program:
  183. <div class="smallexample">
  184. <pre class="smallexample">gdbserver --attach <var>comm</var> <var>pid</var>
  185. </pre></div>
  186. <p>The <var>comm</var> parameter is as described above. Supply the process ID
  187. of a running program in <var>pid</var>; <small>GDB</small> will do everything
  188. else. Like with the previous mode, when the process <var>pid</var> exits,
  189. <small>GDB</small> will close the connection, and <code>gdbserver</code> will exit.
  190. </p>
  191. </li><li> Multi-process mode &ndash; debug more than one program/process:
  192. <div class="smallexample">
  193. <pre class="smallexample">gdbserver --multi <var>comm</var>
  194. </pre></div>
  195. <p>In this mode, <small>GDB</small> can instruct <code>gdbserver</code> which
  196. command(s) to run. Unlike the other 2 modes, <small>GDB</small> will not
  197. close the connection when a process being debugged exits, so you can
  198. debug several processes in the same session.
  199. </p></li></ul>
  200. <p>In each of the modes you may specify these options:
  201. </p>
  202. <dl compact="compact">
  203. <dt><code>--help</code></dt>
  204. <dd><p>List all options, with brief explanations.
  205. </p>
  206. </dd>
  207. <dt><code>--version</code></dt>
  208. <dd><p>This option causes <code>gdbserver</code> to print its version number and exit.
  209. </p>
  210. </dd>
  211. <dt><code>--attach</code></dt>
  212. <dd><p><code>gdbserver</code> will attach to a running program. The syntax is:
  213. </p>
  214. <div class="smallexample">
  215. <pre class="smallexample">target&gt; gdbserver --attach <var>comm</var> <var>pid</var>
  216. </pre></div>
  217. <p><var>pid</var> is the process ID of a currently running process. It isn&rsquo;t
  218. necessary to point <code>gdbserver</code> at a binary for the running process.
  219. </p>
  220. </dd>
  221. <dt><code>--multi</code></dt>
  222. <dd><p>To start <code>gdbserver</code> without supplying an initial command to run
  223. or process ID to attach, use this command line option.
  224. Then you can connect using <kbd>target extended-remote</kbd> and start
  225. the program you want to debug. The syntax is:
  226. </p>
  227. <div class="smallexample">
  228. <pre class="smallexample">target&gt; gdbserver --multi <var>comm</var>
  229. </pre></div>
  230. </dd>
  231. <dt><code>--debug</code></dt>
  232. <dd><p>Instruct <code>gdbserver</code> to display extra status information about the debugging
  233. process.
  234. This option is intended for <code>gdbserver</code> development and for bug reports to
  235. the developers.
  236. </p>
  237. </dd>
  238. <dt><code>--remote-debug</code></dt>
  239. <dd><p>Instruct <code>gdbserver</code> to display remote protocol debug output.
  240. This option is intended for <code>gdbserver</code> development and for bug reports to
  241. the developers.
  242. </p>
  243. </dd>
  244. <dt><code>--debug-file=<var>filename</var></code></dt>
  245. <dd><p>Instruct <code>gdbserver</code> to send any debug output to the given <var>filename</var>.
  246. This option is intended for <code>gdbserver</code> development and for bug reports to
  247. the developers.
  248. </p>
  249. </dd>
  250. <dt><code>--debug-format=option1<span class="roman">[</span>,option2,...<span class="roman">]</span></code></dt>
  251. <dd><p>Instruct <code>gdbserver</code> to include extra information in each line
  252. of debugging output.
  253. See <a href="Server.html#Other-Command_002dLine-Arguments-for-gdbserver">Other Command-Line Arguments for gdbserver</a>.
  254. </p>
  255. </dd>
  256. <dt><code>--wrapper</code></dt>
  257. <dd><p>Specify a wrapper to launch programs
  258. for debugging. The option should be followed by the name of the
  259. wrapper, then any command-line arguments to pass to the wrapper, then
  260. <kbd>--</kbd> indicating the end of the wrapper arguments.
  261. </p>
  262. </dd>
  263. <dt><code>--once</code></dt>
  264. <dd><p>By default, <code>gdbserver</code> keeps the listening TCP port open, so that
  265. additional connections are possible. However, if you start <code>gdbserver</code>
  266. with the <samp>--once</samp> option, it will stop listening for any further
  267. connection attempts after connecting to the first <small>GDB</small> session.
  268. </p>
  269. </dd>
  270. </dl>
  271. <hr>
  272. <div class="header">
  273. <p>
  274. Next: <a href="gcore-man.html#gcore-man" accesskey="n" rel="next">gcore man</a>, Previous: <a href="gdb-man.html#gdb-man" accesskey="p" rel="prev">gdb 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>
  275. </div>
  276. </body>
  277. </html>