s

Debug Openwrt Package


1 prepare gdbserver

1.1 add gdb support in toolchain

$ make menuconfig

[*] Advanced configuration options (for developers)  --->
  [*]   Toolchain Options  --->
    [*]   Build gdb
                

1.2 add gdbserver support

$ make menuconfig

Development  --->
  <M> gdbserver
                

1.3 compile and install gdbserver

make package/devel/gdb/{clean,prepare,compile,install} V=s
                

Then scp the package below to /tmp directory on board.

bin/ipq806x/packages/base/gdbserver_7.8-2_ipq806x.ipk
                

install the gdbserver:

root@xx# opkg install /tmp/gdbserver_7.8-2_ipq806x.ipk
                

2 prepare package with debug info

In order to debug a program effectively, you need to generate debugging information when you compile it. This debugging information is stored in the object file; it describes the data type of each variable or function and the correspondence between source line numbers and addresses in the executable code.

To request debugging information, sepecify the '-g' option when you run the compiler.

2.1 add debug flag in package/Makefile

add `TARGET_CFLAGS += -g3' in package/Makefile

TARGET_CFLAGS += -g3

define Build/Compile
    $(MAKE) -C $(PKG_BUILD_DIR)/ \
    CC="$(TARGET_CC)" \
    CFLAGS="$(TARGET_CFLAGS)"
endef
                

2.2 compile package

make package/hello/{clean,prepare,compile,install} V=s
                

then scp to the board.

3 start gdbserver on target

the target ip is 192.168.1.20

# gdbserver :9000 /bin/hello
              

4 start gdb on host

There are two methods for debug in host:

4.1 method one

./scripts/remote-gdb 192.168.1.20:9000 ./build_dir/target-*/hello/hello
                

4.2 method2 two

$ ./staging_dir/toolchain-arm_cortex-a7_gcc-5.2.0_uClibc-1.0.14_eabi/bin/arm-openwrt-linux-gdb
(gdb) file <openwrtdir>/build_dir/<targetarch>/<path>/<executable>
(gdb) target remote ip:9000
                

5 quit openwrt gdbserver

There are two methods to quit openwrt gdbserver

5.1 monitor exit

Give command

(gdb) monitor exit
                

from your host gdb before terminating the client. If you have already terminated it, just attach with another one.

5.2 kill process

Login the target by using ssh, and kill the gdbserver process.