| <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>3.7. Using GDB Server for Debugging</title><link rel="stylesheet" href="cs.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.74.0"><link rel="home" href="index.html" title="Sourcery G++ Lite"><link rel="up" href="chap-target.html" title="Chapter 3. Sourcery G++ Lite for ARM GNU/Linux"><link rel="prev" href="included-libraries.html" title="3.6. Using Sourcery G++ Lite on GNU/Linux Targets"><link rel="next" href="sec-backtrace.html" title="3.8. GLIBC Backtrace Support"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3.7. Using GDB Server for Debugging</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="included-libraries.html">Prev</a> </td><th width="60%" align="center">Chapter 3. Sourcery G++ Lite for ARM GNU/Linux</th><td width="20%" align="right"> <a accesskey="n" href="sec-backtrace.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="linux-gdbserver"></a>3.7. Using GDB Server for Debugging</h2></div></div></div><p> |
| The GDB server utility provided with Sourcery G++ Lite can be used to debug |
| a GNU/Linux application. While Sourcery G++ runs on your host system, |
| <code class="command">gdbserver</code> and the target application |
| run on your target system. Even though Sourcery G++ and your application |
| run on different systems, the debugging experience when using |
| <code class="command">gdbserver</code> is very similar to debugging a native application. |
| </p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sec-running-gdbserver"></a>3.7.1. Running GDB Server</h3></div></div></div><p> |
| The GDB server executables are included in the sysroot in ABI-specific |
| subdirectories of |
| <code class="filename"><em class="replaceable"><code>sysroot</code></em>/usr</code>. Use the |
| executable from the sysroot and library subdirectory |
| that match your program. |
| See <a class="xref" href="sec-multilibs.html" title="3.2. Library Configurations">Section 3.2, “Library Configurations”</a> for details. |
| </p><p> |
| You must copy the sysroot to your target system as described |
| in <a class="xref" href="included-libraries.html#sec-installing-sysroot" title="3.6.1. Installing the Sysroot">Section 3.6.1, “Installing the Sysroot”</a>. |
| You must also copy the executable you want to debug to your target system. |
| </p><p> |
| If you have installed the sysroot in the root directory of the filesystem |
| on the target, you can invoke <code class="command">gdbserver</code> as: |
| |
| </p><pre class="screen">> gdbserver :10000 <em class="replaceable"><code>program arg1 arg2 ...</code></em></pre><p> |
| |
| where <em class="replaceable"><code>program</code></em> is the path to the program you |
| want to debug and <em class="replaceable"><code>arg1 arg2 ...</code></em> are the arguments |
| you want to pass to it. The <code class="literal">:10000</code> argument indicates |
| that <code class="command">gdbserver</code> should listen for connections from GDB |
| on port 10000. |
| |
| You can use a different port, if you prefer. |
| </p><p> |
| If you have installed the sysroot in an alternate directory, invoking |
| <code class="command">gdbserver</code> becomes more complicated. You must build |
| your application using the link-time options to specify the location of |
| the sysroot, as described in <a class="xref" href="included-libraries.html#sec-linker-sysroot" title="3.6.2. Using Linker Options to Specify the Sysroot Location">Section 3.6.2, “Using Linker Options to Specify the Sysroot Location”</a>. You |
| must also invoke <code class="command">gdbserver</code> itself using the dynamic |
| linker provided in the Sourcery G++ sysroot, as described in |
| <a class="xref" href="included-libraries.html#sec-runtime-sysroot" title="3.6.3. Specifying the Sysroot Location at Runtime">Section 3.6.3, “Specifying the Sysroot Location at Runtime”</a>. In other words, the command to |
| invoke <code class="command">gdbserver</code> in this case would be similar to: |
| |
| </p><pre class="screen">> <em class="replaceable"><code>sysroot</code></em>/lib/ld-linux.so.3 \ |
| --library-path <em class="replaceable"><code>sysroot</code></em>/lib:<em class="replaceable"><code>sysroot</code></em>/usr/lib \ |
| <em class="replaceable"><code>sysroot</code></em>/usr/lib/bin/gdbserver :10000 <em class="replaceable"><code>program arg1 arg2 ...</code></em></pre><p> |
| </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id278437"></a>3.7.2. Connecting to GDB Server from the Debugger</h3></div></div></div><p> |
| You can connect to GDB server by using the following command from |
| within GDB: |
| |
| </p><pre class="screen">(gdb) target remote <em class="replaceable"><code>target</code></em>:10000</pre><p> |
| |
| where <em class="replaceable"><code>target</code></em> is the host name or IP address |
| of your target system. |
| </p><p> |
| When your program exits, <code class="command">gdbserver</code> exits too. |
| If you want to debug the program again, you must restart |
| <code class="command">gdbserver</code> on the target. |
| Then, in GDB, reissue the <code class="literal">target</code> command shown above. |
| </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sec-gdb-sysroot"></a>3.7.3. Setting the Sysroot in the Debugger</h3></div></div></div><p> |
| In order to debug shared libraries, GDB needs to map |
| the pathnames of shared libraries on the target to the pathnames of |
| equivalent files on the host system. Debugging of multi-threaded |
| applications also depends on correctly locating copies of the |
| libraries provided in the sysroot on the host system. |
| </p><p> |
| In some situations, the target pathnames are valid on the host system. |
| |
| Otherwise, you must tell GDB how to map target pathnames onto the |
| equivalent host pathnames. |
| </p><p> |
| In the general case, there are two GDB commands required to set up the |
| mapping: |
| |
| </p><pre class="screen">(gdb) set sysroot-on-target <em class="replaceable"><code>target-pathname</code></em> |
| (gdb) set sysroot <em class="replaceable"><code>host-pathname</code></em></pre><p> |
| |
| This causes GDB to replace all instances of the |
| <em class="replaceable"><code>target-pathname</code></em> prefix in shared library |
| pathnames reported by the target with |
| <em class="replaceable"><code>host-pathname</code></em> to get the location of the |
| equivalent library on the host. |
| </p><p> |
| If you have installed the sysroot in the root filesystem on the target, |
| you can omit the <code class="command">set sysroot-on-target</code> command, and |
| use only <code class="command">set sysroot</code> to specify the location on the |
| host system. |
| </p><p> |
| Refer to <a class="xref" href="included-libraries.html#sec-installing-sysroot" title="3.6.1. Installing the Sysroot">Section 3.6.1, “Installing the Sysroot”</a> for more information |
| about installing the sysroot on the target. |
| Note that if you have installed a stripped copy of the provided libraries |
| on the target, you should give GDB the location of an unstripped |
| copy on the host. |
| </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="included-libraries.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="chap-target.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sec-backtrace.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3.6. Using Sourcery G++ Lite on GNU/Linux Targets </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 3.8. GLIBC Backtrace Support</td></tr></table></div></body></html> |