gdb server调试步骤

编译gdb/gdbserver

编译arm-linux-gdb

下载gdb-7.12,解压缩进入目录

./configure --target=arm-linux --program-prefix=arm-linux- --prefix=/opt/arm-linux-gdb/

 修改gdb/remote.c

 

//==================================
  如果gdb提示:GDB7.6 Remote 'g' packet reply is too long 
  修改gdb/remote.c文件,屏蔽process_g_packet函数中的下列两行:

  if (buf_len > 2 * rsa->sizeof_g_packet)
     error (_(“Remote ‘g’ packet reply is too long: %s”), rs->buf);

  在其后添加:

  if (buf_len > 2 * rsa->sizeof_g_packet) {
      rsa->sizeof_g_packet = buf_len ;
      for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
      {
         if (rsa->regs[i].pnum == -1)
         continue;

         if (rsa->regs[i].offset >= rsa->sizeof_g_packet)
         rsa->regs[i].in_g_packet = 0;
         else
         rsa->regs[i].in_g_packet = 1;
      }
   }

 
make && make install

 

 

编译gdbserver

进入gdb/gdbserver目录

./configure --target=arm-linux --host=arm-linux

 修改生成的makefile,将CC AR GXX都修改为交叉编译工具链中的工具

make 

 将生成的gdbserver移植到目标机即可

 

目标机:arm

 假设正在运行的程序名字为hello,其进程ID 为6622,目标机IP为192.168.0.11,那么在目标机端开启gdbserver的命令格式:

#命令格式
gdbserver IP:PORT --attach PID

 具体到目标机开启的命令为:

[root@test ~]# gdbserver 192.168.0.11:8888  --attach 6622
Attached; pid = 6622
Listening on port 8888

 

调试机:PC

root@liangwode:# arm-linux-gdb
GNU gdb (GDB) 7.12
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
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-pc-linux-gnu --target=arm-linux".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) target remote 192.168.0.11:8888
Remote debugging using 192.168.0.11:8888
warning: Can not parse XML target description; XML support was disabled at compile time
Reading /home/storm/ftp/hello from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /home/storm/ftp/hello from remote target...
Reading symbols from target:/home/storm/ftp/hello...done.
Reading /lib/libc.so.6 from remote target...
Reading /lib/ld-linux-armhf.so.3 from remote target...
Reading symbols from target:/lib/libc.so.6...done.
Reading symbols from target:/lib/ld-linux-armhf.so.3...done.
0x76f0a8d4 in nanosleep () at ../sysdeps/unix/syscall-template.S:84
84	../sysdeps/unix/syscall-template.S: No such file or directory.

 

转载于:https://www.cnblogs.com/liangwode/p/6242577.html

你可能感兴趣的:(gdb server调试步骤)