Usage:
armgdb is running on
x86 as a client.
gdbserver is running on
arm-device as a server.
Ex.
===================
== On the device ==
===================
#./gdbserver 127.0.0.1:1234 server &
Then gdbserver will listen on port 1234 on the device
================================
== On the x86 (vmware fedora) ==
================================
#cd
#./armgdb server
Then the gdb prompt will appear and waiting your command...
Some settings need to be set first
(gdb) set solib-search-path /project/target/fs-cpio/lib <== path to your
rootfs lib directory
Then let's connect to the device port 1234
(gdb) target remote :1234
[Optional : (gdb) break ]
(gdb) run
Book : GNU - Debugging with gdb
用 gdb 對特定記憶體區域寫入設斷點
加快編譯的一些取巧方式
GDB 7.9 可以動態編譯插入程式片段進入正在跑的程式中
沒試過 ... 歡迎不怕辛苦的嘗試看看
一些連結,主要是針對 ARM 架構如何去做 stack unwinding , 我目前是土法煉鋼在 SIGSEGV handler 內把該 thread 的
stack 直接 fopen 寫到一個檔案,因為 core dump 不完整磁碟空間不足,所以只好針對性的 dump stack.
·
Memory Debugging
use address sanitizer, Linaro ported it to ARM on 2013/07
·
Backtrace on SEGFAULT
·
socketpair(2): create two already connected unix domain sockets
·
libunwind from Wiki:Call Stack
以下是我的一些
googling ,我後來有加程式碼來
dump stack 以及用
addr2line 來亂槍打鳥尋找可能的
backtrace .
1.
man 5 core, from
linux 2.6.19 it supports piping core dump to another process
Ref : Piping core dumps to a program
Ref : Piping core dumps to a program
2.
GDB Document
3.
Get EIP in SIGSEGV
action handler
Need to add -rdynamic
Ref toolchain /sys/ucontext.h for the third argument of signal action handelr.
Need to add -rdynamic
Ref toolchain /sys/ucontext.h for the third argument of signal action handelr.
4.
libbacktrace
A library could be linked to your program can called to analysis DWARF stylf executable.
A library could be linked to your program can called to analysis DWARF stylf executable.
Create a global array to
record every pthread’s first variable pointer (As stack bottom),
ex:
oprofile
perf Profiler
Examine cache miss and branch
prediction miss events for performance tuning
Perf tutorial, examples
On older kernels, use oProfile as a perf replacement
Good branch prediction miss example: Stackoverflow: Why is processing a sorted array faster than an unsorted array?
https://wiki.linaro.org/KenWerner/Sandbox/perf: perf and Cortex A9
Perf tutorial, examples
On older kernels, use oProfile as a perf replacement
Good branch prediction miss example: Stackoverflow: Why is processing a sorted array faster than an unsorted array?
https://wiki.linaro.org/KenWerner/Sandbox/perf: perf and Cortex A9
Performance Monitor
Unit
ARMv7 common PMU events are in
the ARMv7 AR
一些關鍵字。
oprofile
strack
valgrind
kprobes
backtrace
vfs_cache_pressure
kswapd
watchpoint
sigsegv
netconsole
oops
syslogs
ptrace
systemtap
meminfo
proc
oom
killer
slab
oprofile
vprobe
xen
nmi
objdump
scheduler
stack
overflow
semaphore
deadlock
buffer
overrun
kernel
mode
race
condition
interrupt
gdb: running on PC
gdbserver: running on the
device
If you have problem to run them, you may
uncompress the gdb.tar.bz2 to re-build again.
(cat config.log or config.status to search
for pattern like “./configure …..”, then
copy-paste on to re-build again)
Device:
iptables -P INPUT ACCEPT
./gdbserver --attach 0.0.0.0:3000 &
PC:
./gdb
(gdb) set solib-search-path
(gdb) target remote 172.16.3.92:3000
Remote debugging using 172.16.3.92:3000
[New Thread 237]
…
(gdb) bt
#0 0x401cb218 in select () from
/usr/src/trunk/target/fs-cpio/lib/libc.so.0
#1 0x0000b6c0 in event_loop (single=
During symbol reading, incomplete CFI data; unspecified registers
(e.g., r0) at 0xb278.
0) at event.c:481
#2 0x00020300 in main (argc=1, argv=0xbed11eb4) at
server.c:287
(gdb) n
Single stepping until exit from function select,
which has no line number information.
ham_loop (single=0) at event.c:482
482
if (debug_event ())
(gdb) n
484
pthread_mutex_lock (&time_event_mutex);
(gdb) p time_event_list
$1 = (struct event *) 0xbfba8
(gdb) cont
Continuing.
Program received signal SIGINT, Interrupt.
0x401cb218 in select () from /usr/src/trunk/target/fs-cpio/lib/libc.so.0
(gdb) cont
Continuing.
Device 上:
ulimit –c unlimited
重啟 server , 重要!
等待 server 掛掉
cd /usr/sbin
tftp -p 1.2.3.4 -l core.數字
PC上
/tmp/gdb-6.8/gdb/gdb
/tmp/server_0912010954
#必須是沒有被 strip 的版本, 可以修改 Makefile 在 arm-linux-strip 之前插入 cp server /tmp/server_`date + %y%m%d%H%M` 來時常保留備份
#進入 gdb 後
(gdb) set
solib-search-path /home/project/lib/
(gdb) core
/tftpboot/core.數字
#可以看出一點眉目
(gdb) bt
#通常這邊可以看出問題
(gdb) up 或是 down
(gdb) print <變數>
#變數通常是 function 傳進來的變數.
A patch to vim7.2 to let vim support gdb .
我是新增 ~/.armgdb 內容:
set solib-search-path ~/TPL/target/tplfs-cpio/lib/
handle SIG33 nostop noprint pass
handle SIG32 nostop noprint pass
handle SIGTRAP nostop
handle SIGINT nostop noprint pass
handle SIGTERM nostop noprint pass
#target remote 172.16.15.77:1234
然後執行 gdb
gdb -x ~/.armgdb
gdb -x ~/.armgdb