嵌入式linuxGDB和GDBServer


linux应用调试技术之GDB和GDBServer

调试原理

  GDB调试是应用程序在开发板上运行,然后在PC机上对开发板上得应用程序进行调试,PC机运行GDB,开发板上运行GDBServer。

安装GDB和GDBServer(gdb-7.4.tar.bz2 )

下载: http://ftp.gnu.org/gnu/gdb/

解压:tar xvf gdb-7.4.tar.bz2

配置:

cd gdb-7.4/
./configure --target=arm-linux

编译:make

安装:

mkdir tmp 
make install prefix=$PWD/tmp

拷贝:cp tmp/bin/arm-linux-gdb /bin/

查看版本 /bin/arm-linux-gdb -v (使用绝对路径使用gdb)

GDBServer

cd gdb/gdbserver/
./configure --target=arm-linux --host=arm-linux
make CC=arm-linux-gcc

编译GDBServer的时候会出现以下错误

linux-arm-low.c: In function `arm_stopped_by_watchpoint':
linux-arm-low.c:642: error: `PTRACE_GETSIGINFO' undeclared (first use in this function)
linux-arm-low.c:642: error: (Each undeclared identifier is reported only once
linux-arm-low.c:642: error: for each function it appears in.)

该错误是因为找不到PTRACE_GETSIGINFO宏,导致编译错误。我们到交叉编译链去搜索一下,我们交叉编译地址为 /work/tools/gcc-3.4.5-glibc-2.3.6

# cd  /work/tools/gcc-3.4.5-glibc-2.3.6
# grep "PTRACE_GETSIGINFO" * -nR
arm-linux/sys-include/linux/ptrace.h:27:#define PTRACE_GETSIGINFO    0x4202
arm-linux/include/linux/ptrace.h:27:#define PTRACE_GETSIGINFO    0x4202
distributed/arm-linux/sys-include/linux/ptrace.h:27:#define PTRACE_GETSIGINFO    0x4202
distributed/arm-linux/include/linux/ptrace.h:27:#define PTRACE_GETSIGINFO    0x4202

可以看到,在交叉编译链里面,定义了PTRACE_GETSIGINFO宏为0x4202,头文件为include中。有两种解决办法,可任选其一:

  ① 在linux-arm-low.c中直接添加宏 #define PTRACE_GETSIGINFO 0x4202
  ② 在linux-arm-low.c中将#include 更改为 #include
  再次编译,编译通过

将gdbserver拷贝到开发板的bin目录下

#cp gdbserver /usr/bin

调试DEBUG

主机采用vscode+cmake环境编译功能,launch.json里添加 目标板的IP地址 192.168.100.151,端口号和目标板的一致就行,这里是2346,交叉编译器记得选gdb

"miDebuggerServerAddress": "192.168.100.151:2346",
"miDebuggerPath": "/home/vmuser/nwjzq/tuopoTTU/arm-2014.05/bin/arm-none-linux-gnueabi-gdb",

目标板通过挂载主机程序方式仿真调试

    mount -t nfs -o nolock 192.168.100.150://home/vmuser/nwjzq/nwjzq /root/app
gdbserver :1234 /root/app/tapp
Process ./tapp created; pid = 751
Listening on port 2346

vscode菜单点运行,则进入仿真调试状态。

相关