BRN:Software:Build and Distribution:Userland Debugging: Difference between revisions

From
Jump to navigation Jump to search
No edit summary
 
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Debug Setup =
= Debug Setup =


The remove debugging setup consists of a debugger stub (named gdbserver), which runs on the target machine (mipsel in our case) and is attached to the debuggee process. The debugger resists on a (remove) host machine and is connectet to the stub via a TCP/IP or serial connection. At first we have to build both a debugger stub and a cross-debugger (note that the host debugger which is shipped with the linux distribution could not be used for cross debugging).
The remove debugging setup consists of a debugger stub (named gdbserver), which runs on the target machine (mipsel in our case) and is attached to the debuggee process. The debugger resists on a (remote) host machine and is connectet to the stub via a TCP/IP or serial connection. At first we have to build both a debugger stub and a cross-debugger (note that the host debugger which is shipped with the linux distribution could not be used for cross debugging).


* Build the gdbserver. It must be configured for host and target mipsel.
* Build the
* Build the cross-gdb. Configure it for target mipsel and host i386.

Precompiled binaries could be found in the NFS rootfs and in /usr/local/bin/mipsel-linux-uclibc-gdb on nfs-student.


= Debugging Userland Applications =
= Debugging Userland Applications =

* At first, start the gdbserver on the mips. You can either specify an executable which is load or attach it to a running process. To debug a process with PID 333 for example, simply type

wgt30$ gdbserver :2000 --attach 333

The debugger stub is now attached to the process with given PID and reachable on TCP port 2000.

* Start the cross-debugger on the host system and connect it to the stub, e.g.

(gdb) target remote wgt30:2000

It may be the case that the gdb does not find the images of the linked-in shared libraries, since host and target system may differ. As a result, the debugger is not able to exermine the stack correctly and no (of no usefull) backtrace could be generated. You can solve this problem by specifying a shared object lookup prefix using the following command:

(gdb) set solib-absolute-prefix /openwrtroot/gdb/lib

This '''must''' be done every time you attach to a process.

Now you should be able to use the remote debugger in the same was as a local debugger.

= FAQ =

* Q: I run 'set solib-absolute-prefix /openwrtroot/' and get
<pre>
Reading symbols from /openwrtroot/lib/libgcc_s.so.1...warning: no loadable sections found in added symbol-file /openwrtroot/lib/libgcc_s.so.1
done.
Loaded symbols for /openwrtroot/lib/libgcc_s.so.1
Reading symbols from /openwrtroot/lib/libc.so.0...warning: no loadable sections found in added symbol-file /openwrtroot/lib/libc.so.0
done.
Loaded symbols for /openwrtroot/lib/libc.so.0
Reading symbols from /openwrtroot/lib/ld-uClibc.so.0...warning: no loadable sections found in added symbol-file /openwrtroot/lib/ld-uClibc.so.0
done.
Loaded symbols for /openwrtroot/lib/ld-uClibc.so.0
</pre>
for some libraries.

A: You need to build the libraries without running sstrip, which removes all symbols from the binary to reduce size. See [http://forum.openwrt.org/viewtopic.php?pid=19195]

With the OpenWRT distribution (Kamikaze), you have to replace STRIP in 'rules.mk': E.g. set STRIP to
<pre>
STRIP:=/bin/echo
</pre>

Latest revision as of 10:57, 22 April 2007

Debug Setup

The remove debugging setup consists of a debugger stub (named gdbserver), which runs on the target machine (mipsel in our case) and is attached to the debuggee process. The debugger resists on a (remote) host machine and is connectet to the stub via a TCP/IP or serial connection. At first we have to build both a debugger stub and a cross-debugger (note that the host debugger which is shipped with the linux distribution could not be used for cross debugging).

  • Build the gdbserver. It must be configured for host and target mipsel.
  • Build the cross-gdb. Configure it for target mipsel and host i386.

Precompiled binaries could be found in the NFS rootfs and in /usr/local/bin/mipsel-linux-uclibc-gdb on nfs-student.

Debugging Userland Applications

  • At first, start the gdbserver on the mips. You can either specify an executable which is load or attach it to a running process. To debug a process with PID 333 for example, simply type
wgt30$ gdbserver :2000 --attach 333

The debugger stub is now attached to the process with given PID and reachable on TCP port 2000.

  • Start the cross-debugger on the host system and connect it to the stub, e.g.
(gdb) target remote wgt30:2000

It may be the case that the gdb does not find the images of the linked-in shared libraries, since host and target system may differ. As a result, the debugger is not able to exermine the stack correctly and no (of no usefull) backtrace could be generated. You can solve this problem by specifying a shared object lookup prefix using the following command:

(gdb) set solib-absolute-prefix /openwrtroot/gdb/lib

This must be done every time you attach to a process.

Now you should be able to use the remote debugger in the same was as a local debugger.

FAQ

  • Q: I run 'set solib-absolute-prefix /openwrtroot/' and get
Reading symbols from /openwrtroot/lib/libgcc_s.so.1...warning: no loadable sections found in added symbol-file /openwrtroot/lib/libgcc_s.so.1
done.
Loaded symbols for /openwrtroot/lib/libgcc_s.so.1
Reading symbols from /openwrtroot/lib/libc.so.0...warning: no loadable sections found in added symbol-file /openwrtroot/lib/libc.so.0
done.
Loaded symbols for /openwrtroot/lib/libc.so.0
Reading symbols from /openwrtroot/lib/ld-uClibc.so.0...warning: no loadable sections found in added symbol-file /openwrtroot/lib/ld-uClibc.so.0
done.
Loaded symbols for /openwrtroot/lib/ld-uClibc.so.0

for some libraries.

A: You need to build the libraries without running sstrip, which removes all symbols from the binary to reduce size. See [1]

With the OpenWRT distribution (Kamikaze), you have to replace STRIP in 'rules.mk': E.g. set STRIP to

  STRIP:=/bin/echo