Tuesday, July 5, 2016

GDB example

GNU Debugger
Please look upstream for multilingual instructions and manuals, like e.g. here: http://sourceware.org/gdb/current/onlinedocs/gdb/

Compiling Tools
in menuconfig enable gdb
Advanced configuration options (for developers) → Toolchain Options → Build gdb
and gdbserver
Development → gdbserver

Add debugging to a package
Add CFLAGS to the package Makefile and recompile it.
TARGET_CFLAGS += -ggdb3
backports/Makefile
- MAKE_OPTS:
- EXTRA_CFLAGS=" -ggdb3" /* DOES NOT WORK */

Alternatively recompile the package with CONFIG_DEBUG set
make package/busybox/{clean,compile} V=99 CONFIG_DEBUG=y
make package/backports/{clean,compile} V=99 CONFIG_DEBUG=y
make package/mac80211/{clean,compile} package/index CONFIG_DEBUG=y

Or you can enable debug info in menuconfig
Global build settings > Compile packages with debugging info

Remove Strip option (-s) from LD Flags
/linux/Makefile
KBUILD_LDFLAGS_MODULE = -T $(srctree)/scripts/module-common.lds $(if $(CONFIG_PROFILING),,-s)

/build_dir/target-arm_cortex-a7_uClibc-0.9.33.2_eabi/linux/linux-3.14/Makefile
/* This Makefile is not a copy of src/linux/Makefile */

Starting GNU Debugger
Start gdbserver on target (router)
gdbserver :9000 /bin/ping example.org

Start gdb on host (in compiling tree)
./scripts/remote-gdb 192.168.1.1:9000 ./build_dir/target-*/busybox-*/busybox
now you have a gdb shell. Set breakpoints, start program, backtrace etc.

(gdb) b source-file.c:123
(gdb) c
(gdb) bt

/build_dir/toolchain-arm_cortex-a7_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/binutils-2.22/binutils$

:~/build_dir/toolchain-arm_cortex-a7_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/binutils-2.22/binutils$ objdump -S ~/build_dir/target-arm_cortex-a7_uClibc-0.9.33.2_eabi/linux/backports/net/mac80211/mac80211.o 2>&1 | tee ~/works/temp/mac80211.txt

objdump -d shows instructions
objdump –S net/mac80211/rx.o
http://wiki.openwrt.org/doc/devel/gdb


~/works/staging_dir/toolchain-arm_cortex-a7_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin$ arm-openwrt-linux-gdb ~/build_dir/target-arm_cortex-a7_uClibc-0.9.33.2_eabi/linux/backports/net/mac80211/mac80211.ko
$ pwd
/staging_dir/toolchain-arm_v7-a_gcc-4.6-linaro_uClibc-0.9.33.2_eabi/bin

$ ./arm-openwrt-linux-gdb ~/build_dir/linux/backports/net/mac80211/mac80211.ko
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=x86_64-unknown-linux-gnu --target=arm-openwrt-linux-uclibcgnueabi".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /build_dir/linux/backports/net/mac80211/mac80211.ko...done.
(gdb) disas /m ieee80211_sta_ps_transition

(gdb) l *ieee80211_sta_ps_transition
0x1cab8 is in ieee80211_sta_ps_transition (/build_dir/linux/backports/net/mac80211/rx.c:1264).
1259            clear_sta_flag(sta, WLAN_STA_PS_STA);
1260            ieee80211_sta_ps_deliver_wakeup(sta);
1261    }
1262
1263    int ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool start)
1264    {
1265            struct sta_info *sta_inf = container_of(sta, struct sta_info, sta);
1266            bool in_ps;
1267
1268            WARN_ON(!(sta_inf->local->hw.flags & IEEE80211_HW_AP_LINK_PS));

========================================================================
** gdb
http://wiki.openwrt.org/doc/devel/gdb
========================================================================

No comments:

Post a Comment