gdbserver-man.html 14 KB

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