OpenWrt Forum Archive

Topic: Not able to use gdb for debugging openwrt packages.

The content of this topic has been archived on 29 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi ,

I am new in open-wrt environment. I am trying to setup open-wrt gdb , for debugging the openwrt packages.
I am Not able to use gdb for debugging openwrt packages. Please help me in this regard.

I had installed openwrt compiled gdb version and  the binary of my sample program which is "not stripped" on my router .
Now trying to debug the binary using Ubuntu:
I am following below step:

i)Ubuntu and router  are connected statistically using LAN cable.
ii) running below command on router:
     
root@OpenWrt:/usr# gdbserver :2000 helloworld
Process helloworld created; pid = 10938
Listening on port 2000

Remote debugging from host 10.63.84.60



ii)running below on Ubuntu:

root@LMint:/home/siballa/openwrt/openwrt/puneeth_qsdk/qsdk/staging_dir/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin# ./mips-openwrt-linux-uclibc-gdb
GNU gdb (Linaro GDB) 7.2-2011.03-0
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-linux-gnu --target=mips-openwrt-linux-uclibc".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>.
(gdb) target remote 10.63.84.67:2000
Remote debugging using 10.63.84.67:2000
warning: Can not parse XML target description; XML support was disabled at compile time
0x77beef60 in ?? ()
(gdb) b main
No symbol table is loaded.  Use the "file" command.
Make breakpoint pending on future shared library load? (y or [n]) n
(gdb) run
The "remote" target does not support "run".  Try "help target" or "continue".
(gdb)


I am getting error "No symbol table is loaded.  Use the "file" command." while setting breakpoint.

I had tried compiling  helloworld program with below option , in order to include symbol table:

1.in menuconfig enable gdb
---------------------------------

Advanced configuration options (for developers) → Toolchain Options → Build gdb
and gdbserver
Development → gdbserver

2.Add debugging to a package
--------------------------------

Add CFLAGS to the package Makefile and recompile it.
TARGET_CFLAGS += -ggdb3

           OR

Alternatively recompile the package with CONFIG_DEBUG set

make package/busybox/{clean,compile} V=99 CONFIG_DEBUG=y

OR

enable debug info in menuconfig

Global build settings > Compile packages with debugging info

You need to provide a path to the non-stripped binary in the buildhost that is running gdb. I think that you could also give that parameter via gdb console, but I have always provided it at launch (using the remote-gdb script).

I have used remote gdb from the buildhost to debug "collectd" program with:

./scripts/remote-gdb 192.168.1.2:9000 staging_dir/target-mips_34kc_musl-1.1.10/root-ar71xx/usr/sbin/collectd

Ps.
if you set the system to produce also core files, you can also debug crashed programs.

Enable core file creation at crash:
ulimit -c unlimited

Post-mortem debug of the core file:
./build_dir/toolchain-mips_34kc_gcc-4.8-linaro_musl-1.1.10/gdb-7.8/gdb/gdb ./staging_dir/target-mips_34kc_musl-1.1.10/root-ar71xx/usr/sbin/collectd ./collectd.3328.11.1439752039.core

Hi Thanks hnyman.

In my above mentioned steps also I had non-stripped binary.

For confirmation I tried again .
I tried below step:

compiled my helloworld sample program with :
1.in menuconfig enable gdb
---------------------------------

Advanced configuration options (for developers) → Toolchain Options → Build gdb
and gdbserver
Development → gdbserver

2.Add debugging to a package
--------------------------------
make package/busybox/{clean,compile} V=99 CONFIG_DEBUG=y

3.transferred non-stripped binary on target.
---------------------------------------------------

root@LMint:/home/siballa/openwrt/openwrt/puneeth_qsdk/qsdk/build_dir/target-mips_r2_uClibc-0.9.33.2/helloworld# file helloworld
helloworld: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs), with unknown capability 0x41000000 = 0xf676e75, with unknown capability 0x10000 = 0x70403, not stripped

4.now in target running:
------------------------------

gdbserver :2000 helloworld

5. on host running:
----------------------

./scripts/remote-gdb 10.63.84.67:2000 staging_dir/target-mips_r2_uClibc-0.9.33.2/root-ar71xx/usr/bin/helloworld

Here , in path staging_dir/target-mips_r2_uClibc-0.9.33.2/root-ar71xx/usr/sbin/ (as suggested in above reply) I don't find the binary of my sample helloworld program. helloworld binary is present in path "staging_dir/target-mips_r2_uClibc-0.9.33.2/root-ar71xx/usr/bin/helloworld "
Hence using this path while running gdb from host.

But now also breakpoint is not setting properly . Its referring some other binary , not my helloworld binary.

root@LMint:/home/siballa/openwrt/openwrt/puneeth_qsdk/qsdk# ./scripts/remote-gdb 10.63.84.67:2000 staging_dir/target-mips_r2_uClibc-0.9.33.2/root-ar71xx/usr/bin/helloworld
Using target mips_r2 (uClibc-0.9.33.2)
GNU gdb (Linaro GDB) 7.2-2011.03-0
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-linux-gnu --target=mips-openwrt-linux-uclibc".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/siballa/openwrt/openwrt/puneeth_qsdk/qsdk/staging_dir/target-mips_r2_uClibc-0.9.33.2/root-ar71xx/usr/bin/helloworld...done.
warning: Can not parse XML target description; XML support was disabled at compile time
0x77c24f60 in _start () from /home/siballa/openwrt/openwrt/puneeth_qsdk/qsdk/scripts/../staging_dir/target-mips_r2_uClibc-0.9.33.2/root-ar71xx/lib/ld-uClibc.so.0
(gdb) b main
Breakpoint 1 at 0x400660
(gdb) n
Single stepping until exit from function _start,
which has no line number information.
__start () at libc/sysdeps/linux/mips/crt1.S:91
91        PTR_LA $28, _gp             /* Setup GP correctly if we're non-PIC.  */
(gdb)


As I understood here it is referring to "ld-uClibc.so.0 "  binary.

Please help me in this regard.

(Last edited by poonam163 on 22 Oct 2015, 09:51)

Hi All,

Please someone help me in proceeding further. I am stucked at this point.

(Last edited by poonam163 on 25 Oct 2015, 16:23)

The discussion might have continued from here.