1.用到命令有:
gdbserver 192.168.0.157:1234 fun
arm-linux-gdb fun
target remote 192.168.0.157:1234
attach debuf:
gdbserver 192.168.0.157:1234 fun --attach pid
break;
backtrace
frame
x/n addr
info locals
info registers $esp
stepi
nexti
step
next
run
continue
thread apply threadid1,2 command(continue)
讓線程1,2執行後面命令
條件斷點:
break [where] if [condition]
動態設置變量地址:
set $i=0
x\i 反彙編
directory 源碼目錄
在斷點處執行一系列命令
1.break main
2.info breadinfos
1 main
3.command 1
>print a
>print b
>end
多線程中調試線程
info thread 查看線程ID
thread id切換到指定線程
set scheduler-locking on 只調試當前線程
break file.c:13 thread id, 給線程下斷點
2.bug:
當程序執行函數時,局部變量隨機被改變,緩衝區溢出;
fun()
{
int i=0;
int j=0;
char buff[2];
buff[2]=9;
buff[3]=10;
}
3,附加調試
target:
gdbserver --attach xx.xx.xx.xx:1234 pid
host:
(gdb) set solib-absolute-prefix /usr/local/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/
(gdb) target remote xx.xx.xx.xx:1234
Remote debugging using xx.xx.xx.xx:1234
Reading symbols from /usr/local/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/lib/libpthread.so.0...done.
Loaded symbols for /usr/local/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/lib/libpthread.so.0
Reading symbols from /usr/local/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/lib/libgcc_s.so.1...done.
Loaded symbols for /usr/local/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/lib/libgcc_s.so.1
Reading symbols from /usr/local/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/lib/libc.so.6...done.
Loaded symbols for /usr/local/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/lib/libc.so.6
Reading symbols from /usr/local/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/lib/ld-linux.so.3...done.
Loaded symbols for /usr/local/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/lib/ld-linux.so.3
0x401c6ea4 in nanosleep () from /usr/local/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/lib/libc.so.6
(gdb) info threads
[New Thread 8103]
[New Thread 8102]
3 Thread 8102 0x4012480c in __lll_lock_wait ()
from /usr/local/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/lib/libpthread.so.0
2 Thread 8103 0x4012480c in __lll_lock_wait ()
from /usr/local/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/lib/libpthread.so.0
* 1 Thread 8101 0x401c6ea4 in nanosleep ()
from /usr/local/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc/lib/libc.so.6
target and host 可執行程序必須一樣,最好代碼也一樣,在發佈產品時,內部處理髮布附件外,還要備份固件對應源代碼,以便動態調試。
4.strace
a.過濾不需要的信息
strace -F -etrace=\!gettimeofday,nanosleep,open -p 868