Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Server.html 24KB

3 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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>Server (Debugging with GDB)</title>
  17. <meta name="description" content="Server (Debugging with GDB)">
  18. <meta name="keywords" content="Server (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="Remote-Debugging.html#Remote-Debugging" rel="up" title="Remote Debugging">
  26. <link href="Remote-Configuration.html#Remote-Configuration" rel="next" title="Remote Configuration">
  27. <link href="File-Transfer.html#File-Transfer" rel="prev" title="File Transfer">
  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="Server"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Remote-Configuration.html#Remote-Configuration" accesskey="n" rel="next">Remote Configuration</a>, Previous: <a href="File-Transfer.html#File-Transfer" accesskey="p" rel="prev">File Transfer</a>, Up: <a href="Remote-Debugging.html#Remote-Debugging" accesskey="u" rel="up">Remote Debugging</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. <a name="Using-the-gdbserver-Program"></a>
  64. <h3 class="section">20.3 Using the <code>gdbserver</code> Program</h3>
  65. <a name="index-gdbserver"></a>
  66. <a name="index-remote-connection-without-stubs"></a>
  67. <p><code>gdbserver</code> is a control program for Unix-like systems, which
  68. allows you to connect your program with a remote <small>GDB</small> via
  69. <code>target remote</code> or <code>target extended-remote</code>&mdash;but without
  70. linking in the usual debugging stub.
  71. </p>
  72. <p><code>gdbserver</code> is not a complete replacement for the debugging stubs,
  73. because it requires essentially the same operating-system facilities
  74. that <small>GDB</small> itself does. In fact, a system that can run
  75. <code>gdbserver</code> to connect to a remote <small>GDB</small> could also run
  76. <small>GDB</small> locally! <code>gdbserver</code> is sometimes useful nevertheless,
  77. because it is a much smaller program than <small>GDB</small> itself. It is
  78. also easier to port than all of <small>GDB</small>, so you may be able to get
  79. started more quickly on a new system by using <code>gdbserver</code>.
  80. Finally, if you develop code for real-time systems, you may find that
  81. the tradeoffs involved in real-time operation make it more convenient to
  82. do as much development work as possible on another system, for example
  83. by cross-compiling. You can use <code>gdbserver</code> to make a similar
  84. choice for debugging.
  85. </p>
  86. <p><small>GDB</small> and <code>gdbserver</code> communicate via either a serial line
  87. or a TCP connection, using the standard <small>GDB</small> remote serial
  88. protocol.
  89. </p>
  90. <blockquote>
  91. <p><em>Warning:</em> <code>gdbserver</code> does not have any built-in security.
  92. Do not run <code>gdbserver</code> connected to any public network; a
  93. <small>GDB</small> connection to <code>gdbserver</code> provides access to the
  94. target system with the same privileges as the user running
  95. <code>gdbserver</code>.
  96. </p></blockquote>
  97. <a name="Running-gdbserver"></a><a name="Running-gdbserver-1"></a>
  98. <h4 class="subsection">20.3.1 Running <code>gdbserver</code></h4>
  99. <a name="index-arguments_002c-to-gdbserver"></a>
  100. <a name="index-gdbserver_002c-command_002dline-arguments"></a>
  101. <p>Run <code>gdbserver</code> on the target system. You need a copy of the
  102. program you want to debug, including any libraries it requires.
  103. <code>gdbserver</code> does not need your program&rsquo;s symbol table, so you can
  104. strip the program if necessary to save space. <small>GDB</small> on the host
  105. system does all the symbol handling.
  106. </p>
  107. <p>To use the server, you must tell it how to communicate with <small>GDB</small>;
  108. the name of your program; and the arguments for your program. The usual
  109. syntax is:
  110. </p>
  111. <div class="smallexample">
  112. <pre class="smallexample">target&gt; gdbserver <var>comm</var> <var>program</var> [ <var>args</var> &hellip; ]
  113. </pre></div>
  114. <p><var>comm</var> is either a device name (to use a serial line), or a TCP
  115. hostname and portnumber, or <code>-</code> or <code>stdio</code> to use
  116. stdin/stdout of <code>gdbserver</code>.
  117. For example, to debug Emacs with the argument
  118. &lsquo;<samp>foo.txt</samp>&rsquo; and communicate with <small>GDB</small> over the serial port
  119. <samp>/dev/com1</samp>:
  120. </p>
  121. <div class="smallexample">
  122. <pre class="smallexample">target&gt; gdbserver /dev/com1 emacs foo.txt
  123. </pre></div>
  124. <p><code>gdbserver</code> waits passively for the host <small>GDB</small> to communicate
  125. with it.
  126. </p>
  127. <p>To use a TCP connection instead of a serial line:
  128. </p>
  129. <div class="smallexample">
  130. <pre class="smallexample">target&gt; gdbserver host:2345 emacs foo.txt
  131. </pre></div>
  132. <p>The only difference from the previous example is the first argument,
  133. specifying that you are communicating with the host <small>GDB</small> via
  134. TCP. The &lsquo;<samp>host:2345</samp>&rsquo; argument means that <code>gdbserver</code> is to
  135. expect a TCP connection from machine &lsquo;<samp>host</samp>&rsquo; to local TCP port 2345.
  136. (Currently, the &lsquo;<samp>host</samp>&rsquo; part is ignored.) You can choose any number
  137. you want for the port number as long as it does not conflict with any
  138. TCP ports already in use on the target system (for example, <code>23</code> is
  139. reserved for <code>telnet</code>).<a name="DOCF16" href="#FOOT16"><sup>16</sup></a> You must use the same port number with the host <small>GDB</small>
  140. <code>target remote</code> command.
  141. </p>
  142. <p>The <code>stdio</code> connection is useful when starting <code>gdbserver</code>
  143. with ssh:
  144. </p>
  145. <div class="smallexample">
  146. <pre class="smallexample">(gdb) target remote | ssh -T hostname gdbserver - hello
  147. </pre></div>
  148. <p>The &lsquo;<samp>-T</samp>&rsquo; option to ssh is provided because we don&rsquo;t need a remote pty,
  149. and we don&rsquo;t want escape-character handling. Ssh does this by default when
  150. a command is provided, the flag is provided to make it explicit.
  151. You could elide it if you want to.
  152. </p>
  153. <p>Programs started with stdio-connected gdbserver have <samp>/dev/null</samp> for
  154. <code>stdin</code>, and <code>stdout</code>,<code>stderr</code> are sent back to gdb for
  155. display through a pipe connected to gdbserver.
  156. Both <code>stdout</code> and <code>stderr</code> use the same pipe.
  157. </p>
  158. <a name="Attaching-to-a-program"></a><a name="Attaching-to-a-Running-Program"></a>
  159. <h4 class="subsubsection">20.3.1.1 Attaching to a Running Program</h4>
  160. <a name="index-attach-to-a-program_002c-gdbserver"></a>
  161. <a name="index-_002d_002dattach_002c-gdbserver-option"></a>
  162. <p>On some targets, <code>gdbserver</code> can also attach to running programs.
  163. This is accomplished via the <code>--attach</code> argument. The syntax is:
  164. </p>
  165. <div class="smallexample">
  166. <pre class="smallexample">target&gt; gdbserver --attach <var>comm</var> <var>pid</var>
  167. </pre></div>
  168. <p><var>pid</var> is the process ID of a currently running process. It isn&rsquo;t
  169. necessary to point <code>gdbserver</code> at a binary for the running process.
  170. </p>
  171. <p>In <code>target extended-remote</code> mode, you can also attach using the
  172. <small>GDB</small> attach command
  173. (see <a href="Connecting.html#Attaching-in-Types-of-Remote-Connections">Attaching in Types of Remote Connections</a>).
  174. </p>
  175. <a name="index-pidof"></a>
  176. <p>You can debug processes by name instead of process ID if your target has the
  177. <code>pidof</code> utility:
  178. </p>
  179. <div class="smallexample">
  180. <pre class="smallexample">target&gt; gdbserver --attach <var>comm</var> `pidof <var>program</var>`
  181. </pre></div>
  182. <p>In case more than one copy of <var>program</var> is running, or <var>program</var>
  183. has multiple threads, most versions of <code>pidof</code> support the
  184. <code>-s</code> option to only return the first process ID.
  185. </p>
  186. <a name="TCP-port-allocation-lifecycle-of-gdbserver"></a>
  187. <h4 class="subsubsection">20.3.1.2 TCP port allocation lifecycle of <code>gdbserver</code></h4>
  188. <p>This section applies only when <code>gdbserver</code> is run to listen on a TCP
  189. port.
  190. </p>
  191. <p><code>gdbserver</code> normally terminates after all of its debugged processes have
  192. terminated in <kbd>target remote</kbd> mode. On the other hand, for <kbd>target
  193. extended-remote</kbd>, <code>gdbserver</code> stays running even with no processes left.
  194. <small>GDB</small> normally terminates the spawned debugged process on its exit,
  195. which normally also terminates <code>gdbserver</code> in the <kbd>target remote</kbd>
  196. mode. Therefore, when the connection drops unexpectedly, and <small>GDB</small>
  197. cannot ask <code>gdbserver</code> to kill its debugged processes, <code>gdbserver</code>
  198. stays running even in the <kbd>target remote</kbd> mode.
  199. </p>
  200. <p>When <code>gdbserver</code> stays running, <small>GDB</small> can connect to it again later.
  201. Such reconnecting is useful for features like <a href="Starting-and-Stopping-Trace-Experiments.html#disconnected-tracing">disconnected tracing</a>. For
  202. completeness, at most one <small>GDB</small> can be connected at a time.
  203. </p>
  204. <a name="index-_002d_002donce_002c-gdbserver-option"></a>
  205. <p>By default, <code>gdbserver</code> keeps the listening TCP port open, so that
  206. subsequent connections are possible. However, if you start <code>gdbserver</code>
  207. with the <samp>--once</samp> option, it will stop listening for any further
  208. connection attempts after connecting to the first <small>GDB</small> session. This
  209. means no further connections to <code>gdbserver</code> will be possible after the
  210. first one. It also means <code>gdbserver</code> will terminate after the first
  211. connection with remote <small>GDB</small> has closed, even for unexpectedly closed
  212. connections and even in the <kbd>target extended-remote</kbd> mode. The
  213. <samp>--once</samp> option allows reusing the same port number for connecting to
  214. multiple instances of <code>gdbserver</code> running on the same host, since each
  215. instance closes its port after the first connection.
  216. </p>
  217. <a name="Other-Command_002dLine-Arguments-for-gdbserver"></a><a name="Other-Command_002dLine-Arguments-for-gdbserver-1"></a>
  218. <h4 class="subsubsection">20.3.1.3 Other Command-Line Arguments for <code>gdbserver</code></h4>
  219. <p>You can use the <samp>--multi</samp> option to start <code>gdbserver</code> without
  220. specifying a program to debug or a process to attach to. Then you can
  221. attach in <code>target extended-remote</code> mode and run or attach to a
  222. program. For more information,
  223. see <a href="Connecting.html#g_t_002d_002dmulti-Option-in-Types-of-Remote-Connnections">--multi Option in Types of Remote Connnections</a>.
  224. </p>
  225. <a name="index-_002d_002ddebug_002c-gdbserver-option"></a>
  226. <p>The <samp>--debug</samp> option tells <code>gdbserver</code> to display extra
  227. status information about the debugging process.
  228. <a name="index-_002d_002dremote_002ddebug_002c-gdbserver-option"></a>
  229. The <samp>--remote-debug</samp> option tells <code>gdbserver</code> to display
  230. remote protocol debug output.
  231. <a name="index-_002d_002ddebug_002dfile_002c-gdbserver-option"></a>
  232. <a name="index-gdbserver_002c-send-all-debug-output-to-a-single-file"></a>
  233. The <samp>--debug-file=<var>filename</var></samp> option tells <code>gdbserver</code> to
  234. write any debug output to the given <var>filename</var>. These options are intended
  235. for <code>gdbserver</code> development and for bug reports to the developers.
  236. </p>
  237. <a name="index-_002d_002ddebug_002dformat_002c-gdbserver-option"></a>
  238. <p>The <samp>--debug-format=option1[,option2,...]</samp> option tells
  239. <code>gdbserver</code> to include additional information in each output.
  240. Possible options are:
  241. </p>
  242. <dl compact="compact">
  243. <dt><code>none</code></dt>
  244. <dd><p>Turn off all extra information in debugging output.
  245. </p></dd>
  246. <dt><code>all</code></dt>
  247. <dd><p>Turn on all extra information in debugging output.
  248. </p></dd>
  249. <dt><code>timestamps</code></dt>
  250. <dd><p>Include a timestamp in each line of debugging output.
  251. </p></dd>
  252. </dl>
  253. <p>Options are processed in order. Thus, for example, if <samp>none</samp>
  254. appears last then no additional information is added to debugging output.
  255. </p>
  256. <a name="index-_002d_002dwrapper_002c-gdbserver-option"></a>
  257. <p>The <samp>--wrapper</samp> option specifies 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. <p><code>gdbserver</code> runs the specified wrapper program with a combined
  263. command line including the wrapper arguments, then the name of the
  264. program to debug, then any arguments to the program. The wrapper
  265. runs until it executes your program, and then <small>GDB</small> gains control.
  266. </p>
  267. <p>You can use any program that eventually calls <code>execve</code> with
  268. its arguments as a wrapper. Several standard Unix utilities do
  269. this, e.g. <code>env</code> and <code>nohup</code>. Any Unix shell script ending
  270. with <code>exec &quot;$@&quot;</code> will also work.
  271. </p>
  272. <p>For example, you can use <code>env</code> to pass an environment variable to
  273. the debugged program, without setting the variable in <code>gdbserver</code>&rsquo;s
  274. environment:
  275. </p>
  276. <div class="smallexample">
  277. <pre class="smallexample">$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
  278. </pre></div>
  279. <a name="index-_002d_002dselftest"></a>
  280. <p>The <samp>--selftest</samp> option runs the self tests in <code>gdbserver</code>:
  281. </p>
  282. <div class="smallexample">
  283. <pre class="smallexample">$ gdbserver --selftest
  284. Ran 2 unit tests, 0 failed
  285. </pre></div>
  286. <p>These tests are disabled in release.
  287. </p><a name="Connecting-to-gdbserver"></a>
  288. <h4 class="subsection">20.3.2 Connecting to <code>gdbserver</code></h4>
  289. <p>The basic procedure for connecting to the remote target is:
  290. </p><ul>
  291. <li> Run <small>GDB</small> on the host system.
  292. </li><li> Make sure you have the necessary symbol files
  293. (see <a href="Connecting.html#Host-and-target-files">Host and target files</a>).
  294. Load symbols for your application using the <code>file</code> command before you
  295. connect. Use <code>set sysroot</code> to locate target libraries (unless your
  296. <small>GDB</small> was compiled with the correct sysroot using
  297. <code>--with-sysroot</code>).
  298. </li><li> Connect to your target (see <a href="Connecting.html#Connecting">Connecting to a Remote Target</a>).
  299. For TCP connections, you must start up <code>gdbserver</code> prior to using
  300. the <code>target</code> command. Otherwise you may get an error whose
  301. text depends on the host system, but which usually looks something like
  302. &lsquo;<samp>Connection refused</samp>&rsquo;. Don&rsquo;t use the <code>load</code>
  303. command in <small>GDB</small> when using <code>target remote</code> mode, since the
  304. program is already on the target.
  305. </li></ul>
  306. <a name="Monitor-Commands-for-gdbserver"></a><a name="Monitor-Commands-for-gdbserver-1"></a>
  307. <h4 class="subsection">20.3.3 Monitor Commands for <code>gdbserver</code></h4>
  308. <a name="index-monitor-commands_002c-for-gdbserver"></a>
  309. <p>During a <small>GDB</small> session using <code>gdbserver</code>, you can use the
  310. <code>monitor</code> command to send special requests to <code>gdbserver</code>.
  311. Here are the available commands.
  312. </p>
  313. <dl compact="compact">
  314. <dt><code>monitor help</code></dt>
  315. <dd><p>List the available monitor commands.
  316. </p>
  317. </dd>
  318. <dt><code>monitor set debug 0</code></dt>
  319. <dt><code>monitor set debug 1</code></dt>
  320. <dd><p>Disable or enable general debugging messages.
  321. </p>
  322. </dd>
  323. <dt><code>monitor set remote-debug 0</code></dt>
  324. <dt><code>monitor set remote-debug 1</code></dt>
  325. <dd><p>Disable or enable specific debugging messages associated with the remote
  326. protocol (see <a href="Remote-Protocol.html#Remote-Protocol">Remote Protocol</a>).
  327. </p>
  328. </dd>
  329. <dt><code>monitor set debug-file filename</code></dt>
  330. <dt><code>monitor set debug-file</code></dt>
  331. <dd><p>Send any debug output to the given file, or to stderr.
  332. </p>
  333. </dd>
  334. <dt><code>monitor set debug-format option1<span class="roman">[</span>,option2,...<span class="roman">]</span></code></dt>
  335. <dd><p>Specify additional text to add to debugging messages.
  336. Possible options are:
  337. </p>
  338. <dl compact="compact">
  339. <dt><code>none</code></dt>
  340. <dd><p>Turn off all extra information in debugging output.
  341. </p></dd>
  342. <dt><code>all</code></dt>
  343. <dd><p>Turn on all extra information in debugging output.
  344. </p></dd>
  345. <dt><code>timestamps</code></dt>
  346. <dd><p>Include a timestamp in each line of debugging output.
  347. </p></dd>
  348. </dl>
  349. <p>Options are processed in order. Thus, for example, if <samp>none</samp>
  350. appears last then no additional information is added to debugging output.
  351. </p>
  352. </dd>
  353. <dt><code>monitor set libthread-db-search-path [PATH]</code></dt>
  354. <dd><a name="index-gdbserver_002c-search-path-for-libthread_005fdb"></a>
  355. <p>When this command is issued, <var>path</var> is a colon-separated list of
  356. directories to search for <code>libthread_db</code> (see <a href="Threads.html#Threads">set
  357. libthread-db-search-path</a>). If you omit <var>path</var>,
  358. &lsquo;<samp>libthread-db-search-path</samp>&rsquo; will be reset to its default value.
  359. </p>
  360. <p>The special entry &lsquo;<samp>$pdir</samp>&rsquo; for &lsquo;<samp>libthread-db-search-path</samp>&rsquo; is
  361. not supported in <code>gdbserver</code>.
  362. </p>
  363. </dd>
  364. <dt><code>monitor exit</code></dt>
  365. <dd><p>Tell gdbserver to exit immediately. This command should be followed by
  366. <code>disconnect</code> to close the debugging session. <code>gdbserver</code> will
  367. detach from any attached processes and kill any processes it created.
  368. Use <code>monitor exit</code> to terminate <code>gdbserver</code> at the end
  369. of a multi-process mode debug session.
  370. </p>
  371. </dd>
  372. </dl>
  373. <a name="Tracepoints-support-in-gdbserver"></a>
  374. <h4 class="subsection">20.3.4 Tracepoints support in <code>gdbserver</code></h4>
  375. <a name="index-tracepoints-support-in-gdbserver"></a>
  376. <p>On some targets, <code>gdbserver</code> supports tracepoints, fast
  377. tracepoints and static tracepoints.
  378. </p>
  379. <p>For fast or static tracepoints to work, a special library called the
  380. <em>in-process agent</em> (IPA), must be loaded in the inferior process.
  381. This library is built and distributed as an integral part of
  382. <code>gdbserver</code>. In addition, support for static tracepoints
  383. requires building the in-process agent library with static tracepoints
  384. support. At present, the UST (LTTng Userspace Tracer,
  385. <a href="http://lttng.org/ust">http://lttng.org/ust</a>) tracing engine is supported. This support
  386. is automatically available if UST development headers are found in the
  387. standard include path when <code>gdbserver</code> is built, or if
  388. <code>gdbserver</code> was explicitly configured using <samp>--with-ust</samp>
  389. to point at such headers. You can explicitly disable the support
  390. using <samp>--with-ust=no</samp>.
  391. </p>
  392. <p>There are several ways to load the in-process agent in your program:
  393. </p>
  394. <dl compact="compact">
  395. <dt><code>Specifying it as dependency at link time</code></dt>
  396. <dd>
  397. <p>You can link your program dynamically with the in-process agent
  398. library. On most systems, this is accomplished by adding
  399. <code>-linproctrace</code> to the link command.
  400. </p>
  401. </dd>
  402. <dt><code>Using the system's preloading mechanisms</code></dt>
  403. <dd>
  404. <p>You can force loading the in-process agent at startup time by using
  405. your system&rsquo;s support for preloading shared libraries. Many Unixes
  406. support the concept of preloading user defined libraries. In most
  407. cases, you do that by specifying <code>LD_PRELOAD=libinproctrace.so</code>
  408. in the environment. See also the description of <code>gdbserver</code>&rsquo;s
  409. <samp>--wrapper</samp> command line option.
  410. </p>
  411. </dd>
  412. <dt><code>Using <small>GDB</small> to force loading the agent at run time</code></dt>
  413. <dd>
  414. <p>On some systems, you can force the inferior to load a shared library,
  415. by calling a dynamic loader function in the inferior that takes care
  416. of dynamically looking up and loading a shared library. On most Unix
  417. systems, the function is <code>dlopen</code>. You&rsquo;ll use the <code>call</code>
  418. command for that. For example:
  419. </p>
  420. <div class="smallexample">
  421. <pre class="smallexample">(gdb) call dlopen (&quot;libinproctrace.so&quot;, ...)
  422. </pre></div>
  423. <p>Note that on most Unix systems, for the <code>dlopen</code> function to be
  424. available, the program needs to be linked with <code>-ldl</code>.
  425. </p></dd>
  426. </dl>
  427. <p>On systems that have a userspace dynamic loader, like most Unix
  428. systems, when you connect to <code>gdbserver</code> using <code>target
  429. remote</code>, you&rsquo;ll find that the program is stopped at the dynamic
  430. loader&rsquo;s entry point, and no shared library has been loaded in the
  431. program&rsquo;s address space yet, including the in-process agent. In that
  432. case, before being able to use any of the fast or static tracepoints
  433. features, you need to let the loader run and load the shared
  434. libraries. The simplest way to do that is to run the program to the
  435. main procedure. E.g., if debugging a C or C<tt>++</tt> program, start
  436. <code>gdbserver</code> like so:
  437. </p>
  438. <div class="smallexample">
  439. <pre class="smallexample">$ gdbserver :9999 myprogram
  440. </pre></div>
  441. <p>Start GDB and connect to <code>gdbserver</code> like so, and run to main:
  442. </p>
  443. <div class="smallexample">
  444. <pre class="smallexample">$ gdb myprogram
  445. (gdb) target remote myhost:9999
  446. 0x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
  447. (gdb) b main
  448. (gdb) continue
  449. </pre></div>
  450. <p>The in-process tracing agent library should now be loaded into the
  451. process; you can confirm it with the <code>info sharedlibrary</code>
  452. command, which will list <samp>libinproctrace.so</samp> as loaded in the
  453. process. You are now ready to install fast tracepoints, list static
  454. tracepoint markers, probe static tracepoints markers, and start
  455. tracing.
  456. </p>
  457. <div class="footnote">
  458. <hr>
  459. <h4 class="footnotes-heading">Footnotes</h4>
  460. <h3><a name="FOOT16" href="#DOCF16">(16)</a></h3>
  461. <p>If you choose a port number that
  462. conflicts with another service, <code>gdbserver</code> prints an error message
  463. and exits.</p>
  464. </div>
  465. <hr>
  466. <div class="header">
  467. <p>
  468. Next: <a href="Remote-Configuration.html#Remote-Configuration" accesskey="n" rel="next">Remote Configuration</a>, Previous: <a href="File-Transfer.html#File-Transfer" accesskey="p" rel="prev">File Transfer</a>, Up: <a href="Remote-Debugging.html#Remote-Debugging" accesskey="u" rel="up">Remote Debugging</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>
  469. </div>
  470. </body>
  471. </html>