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