GDB远程调试程序 & 生成core文件便于调试

# GDB远程调试程序

**该文件是用于远程调试gdb,文件夹中的gdbserver和arm-linux-gdb的版本已经保持一致均为6.4**

1. target:`./gdbserver6.4 192.168.100.101:8888 ./test_scale` 
2. host:  1. `arm-linux-gdb app/app.arm.elf` 或 2.`arm-linux-gdb ./app/app.arm.elf -ex 'target remote 192.168.100.253:8888'`
3. 选2.2则忽略此步 host: `target remote 192.168.100.254:8888`
 
## 生成core文件便于调试
```c
#include <sys/resource.h>

#define  EnableCoreDumps()\
{\
    struct rlimit   limit;\
    limit.rlim_cur = RLIM_INFINITY;\
    limit.rlim_max = RLIM_INFINITY;\
    setrlimit(RLIMIT_CORE, &limit);\
}
...
int main()
{
    EnableCoreDumps();
    mkdir("./cores",0775);//mkdir -p ../cores
    system("busybox sysctl -w kernel.core_pattern=./cores/core.%e-%p-%t");//在./cores目录中生成 core.test....
    
    return 0;
}
```
1. 在程序遇到段错误的时候就会生成core文件,用7.9版本的嵌入式`arm-linux-gdb-7.9`调试查看堆栈信息。`arm-linux-gdb-7.9 ./test_scale  -c ./core.test_scale-546-1464108418`。
2. 使用`bt,f num,thread apply all bt`查看各个线程堆栈信息。

## 条件

假设host主机(PC)的ip是`192.168.100.105`target(开发板)的ip是`192.168.100.253`


## 总结

1. host和target的gdb,gdbserver版本不一致会导致他们之间的RPC接口不一致,会导致远程调试失败。
2. 6.4的arm-linux-gdb不能查看core文件,这是gdb的bug,官网可以得知。若要单独查看core文件需编译gdb-7.9。

猜你喜欢

转载自blog.csdn.net/ggggyj/article/details/83338883
今日推荐