arm-linux-gdb+gdbserver环境搭建以及远程调试 及调试core文件

本文详细描述了如何配置环境以正确处理gdb调试产生的coredump文件,并解决了在pc与arm板子间传输core文件时遇到的库加载问题。通过调整核心文件输出配置和设置共享库搜索路径,成功定位并修复了程序崩溃原因。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文主要是描述在调试用gdb 调试coredump文件时出现的问题及解决方法

首先需要对环境进行配置,即配置core文件的输出:
运行命令:ulimit -c unlimited 
该命令用于设置core文件大小不限制
修改/etc/sysctl.conf文件,在文件末尾添加下面一行
kernel.core_pattern=/tmp/core-%e
并修改kernel.core_uses_pid = 1 为
kernel.core_uses_pid = 0 这样core文件的格式就是
core-可执行文件的名字,这里我把进程号去掉了,觉得进程号在此处没多大用处。文件所在目录为/tmp下,也可以自己修改为可执行文件所在目录,这样比较直观。
然后运行命令:sysctl -p /etc/sysctl.conf  或写到/etc/rc.d/rc.local文件里去,每次启动都运行一下

假设将其值改变为:"/home/duanbei/corefile/core-%e-%p-%t", 那么所有的core文件将保存在"/home/duanbei/corefile"目录下,文件名格式为“core-程序名-pid-时间戳”

格式参数列表

[plain] view plaincopyprint?
%p - insert pid into filename 
%u - insert current uid into filename 
%g - insert current gid into filename 
%s - insert signal that caused the coredump into the filename 
%t - insert UNIX time that the coredump occurred into filename 
%h - insert hostname where the coredump happened into filename 
%e - insert coredumping executable name into filename 
%p - insert pid into filename
%u - insert current uid into filename
%g - insert current gid into filename
%s - insert signal that caused the coredump into the filename
%t - insert UNIX time that the coredump occurred into filename
%h - insert hostname where the coredump happened into filename
%e - insert coredumping executable name into filename
注:如果设置了“%p”,而“/proc/sys/kernel/core_uses_pid”值又为1,则不会添加PID后缀,因文件名中已含该信息

到此配置工作完成

$1 = 0x0
 我编写的一个测试用例


#include <stdio.h>
int main(void){
        int man = 0;
        scanf("%d",man);
        return 0;
}
在pc 上面用 arm-hisi-linux-gcc 编译生成 可执行问题ttt
将ttt在arm板子上面运行的到core文件

将core文件传送回pc
在pc上面用命令sudo ./arm-hisi-linux-gdb -c  /home/xiaosw/222/core  /home/xiaosw/tttt

[xiaosw@localhost bin]$ sudo ./arm-hisi-linux-gdb -c  /home/xiaosw/222/core  /home/xiaosw/tttt

This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-hisi-linux"...

Error while mapping shared library sections:
/lib/libc.so.0: No such file or directory.

warning: .dynamic section for "/lib/ld-uClibc.so.0" is not at the expected address (wrong library or version mismatch?)
Symbol file not found for /lib/libc.so.0
Reading symbols from /lib/ld-uClibc.so.0...done.
Loaded symbols for /lib/ld-uClibc.so.0
Core was generated by `./tttt'.
Program terminated with signal 11, Segmentation fault.
#0  0x4003abc4 in ?? ()

显示/lib/libc.so.0库没有, 在/lib下面却是没有这个文件, 但是在我的交叉编译目录下面有,所以我用7楼的办法添加了
set solib-search-path   /opt/hisi-linux/x86-arm/gcc-3.4.3-uClibc-0.9.28/usr/arm-hisi-linux/lib(这个是我的pc机上面的交叉
编译环境的库的目录)


(gdb) set solib-search-path   /opt/hisi-linux/x86-arm/gcc-3.4.3-uClibc-0.9.28/usr/arm-hisi-linux/lib
warning: .dynamic section for "/lib/ld-uClibc.so.0" is not at the expected address (wrong library or version mismatch?)
Reading symbols from /opt/hisi-linux/x86-arm-org/gcc-3.4.3-uClibc-0.9.28/usr/arm-hisi-linux/lib/libc.so.0...done.
Loaded symbols for /opt/hisi-linux/x86-arm-org/gcc-3.4.3-uClibc-0.9.28/usr/arm-hisi-linux/lib/libc.so.0
Reading symbols from /lib/ld-uClibc.so.0...done.
Loaded symbols for /lib/ld-uClibc.so.0

清空以前载入的文件
(gdb) core-file  
No core file now.

载入core文件
(gdb) core-file  /home/xiaosw/222/core
warning: .dynamic section for "/lib/ld-uClibc.so.0" is not at the expected address (wrong library or version mismatch?)
Loaded symbols for /opt/hisi-linux/x86-arm-org/gcc-3.4.3-uClibc-0.9.28/usr/arm-hisi-linux/lib/libc.so.0
Loaded symbols for /lib/ld-uClibc.so.0
Core was generated by `./tttt'.
Program terminated with signal 11, Segmentation fault.
#0  0x4003abc4 in _store_inttype () from /opt/hisi-linux/x86-arm-org/gcc-3.4.3-uClibc-0.9.28/usr/arm-hisi-linux/lib/libc.so.0

(gdb) where
#0  0x4003abc4 in _store_inttype () from /opt/hisi-linux/x86-arm-org/gcc-3.4.3-uClibc-0.9.28/usr/arm-hisi-linux/lib/libc.so.0
#1  0x4003e028 in __psfs_do_numeric () from /opt/hisi-linux/x86-arm-org/gcc-3.4.3-uClibc-0.9.28/usr/arm-hisi-linux/lib/libc.so.0
#2  0x4003d6cc in vfscanf () from /opt/hisi-linux/x86-arm-org/gcc-3.4.3-uClibc-0.9.28/usr/arm-hisi-linux/lib/libc.so.0
#3  0x4003e1c0 in scanf () from /opt/hisi-linux/x86-arm-org/gcc-3.4.3-uClibc-0.9.28/usr/arm-hisi-linux/lib/libc.so.0
#4  0x000084b0 in main () at gdbtest.c:4
(gdb) bt
#0  0x4003abc4 in _store_inttype () from /opt/hisi-linux/x86-arm-org/gcc-3.4.3-uClibc-0.9.28/usr/arm-hisi-linux/lib/libc.so.0
#1  0x4003e028 in __psfs_do_numeric () from /opt/hisi-linux/x86-arm-org/gcc-3.4.3-uClibc-0.9.28/usr/arm-hisi-linux/lib/libc.so.0
#2  0x4003d6cc in vfscanf () from /opt/hisi-linux/x86-arm-org/gcc-3.4.3-uClibc-0.9.28/usr/arm-hisi-linux/lib/libc.so.0
#3  0x4003e1c0 in scanf () from /opt/hisi-linux/x86-arm-org/gcc-3.4.3-uClibc-0.9.28/usr/arm-hisi-linux/lib/libc.so.0
#4  0x000084b0 in main () at gdbtest.c:4
(gdb)








set solib-absolute-prefix path

If this variable is set, path will be used as a prefix for any absoluteshared library paths; many runtime loaders store the absolute paths tothe shared library in the target program's memory. If you use`solib-absolute-prefix' to find shared libraries, they need to be laidout in the same way that they are on the target, with e.g. a `/usr/lib'hierarchy under path. You can set the default value of`solib-absolute-prefix' by using the configure-time `--with-sysroot'option.

如果这一变量被设置,path将被作为任何绝对路径共享库的前缀;许多运行时的载入器存储目标程序内存中共享库的绝对路径。如果你使用“solib-absolute-prefix”查找共享库,它们应该和目标上有一样的路径结构,比如path下的一个“/usr/lib”的层次。

show solib-absolute-prefix

Display the current shared library prefix.

显示当前共享库前缀的配置。

set solib-search-path path

If this variable is set, path is a colon-separated list of directoriesto search for shared libraries. `solib-search-path' is used after`solib-absolute-prefix' fails to locate the library, or if the path tothe library is relative instead of absolute. If you want to use`solib-search-path' instead of `solib-absolute-prefix', be sure to set`solib-absolute-prefix' to a nonexistant directory to prevent GDB fromfinding your host's libraries.

如果这一变量被设置,其中path是冒号分割的用来搜索共享库的目录的列表。“solib-search-path”在“solib-absolute-prefix”定位库失败后使用,或者库的路径是相对的,而不是绝对的。如果你想使用“solib-search-path”代替“solib-absolute-prefix”,确定“solib-absolute-prefix”设置的是不存在的目录,以阻止 GDB 查找宿主机上的库。

show solib-search-path

Display the current shared library search path.

显示当前共享库查找路径的配置。


<think>我们正在讨论CLion是否支持对远程ARM板进行调试以及如何配置。根据引用[1]和引用[2],我们知道CLion可以通过远程开发模式配置ARM开发,并且支持远程调试。具体到调试,引用[2]详细说明了如何配置GDBRemoteDebug,即通过gdbserver远程设备上运行程序,然后CLion通过GDB连接到远程gdbserver进行调试。因此,答案是肯定的,CLion支持对远程ARM板进行调试。配置方法如下:###步骤1:在远程ARM板上安装gdbserver首先,确保远程ARM板上安装了gdbserver。如果没有,可以通过交叉编译或包管理器安装。例如,在基于Debian的系统上:```bashsudoapt-getinstallgdbserver```###步骤2:在远程ARM板上启动gdbserverARM板上运行你的程序,并通过gdbserver监听调试连接。例如,在ARM板上执行:```bashgdbserver:1234./your_program```这里`1234`是端口号,可以自定义。###步骤3:在CLion中配置远程调试1.打开CLion,进入`Run→EditConfigurations`。2.点击`+`,选择`GDBRemoteDebug`。3.配置如下:-`Target`:选择之前配置的远程工具链(参考之前的工具链配置,确保是ARM交叉编译的工具链)。-`'targetremote'args`:填写ARM板的IP地址和端口,例如:`tcp:192.168.1.100:1234`-设置程序路径:在`Pathtoexecutable`中填写本地编译出的可执行文件路径(注意:这个可执行文件必须是用交叉编译器为ARM编译的,并且与远程ARM板上的可执行文件一致)。-设置工作目录:可以设置为远程设备上的程序所在目录(通过部署配置映射的远程路径)。4.在`Symbolfile`中,可以指定本地编译出的可执行文件(用于符号映射)。###步骤4:开始调试在CLion中设置断点,然后选择刚刚配置的调试配置,点击调试按钮。CLion将通过GDB连接到远程gdbserver,开始调试。###注意事项-确保本地CLion项目使用的工具链是交叉编译工具链(针对ARM架构)。-确保本地可执行文件远程ARM板上的可执行文件是相同的(可以通过CLion的部署功能同步)。-如果程序依赖动态库,需要确保远程ARM板上有这些库,或者通过`LD_LIBRARY_PATH`指定。###引用说明以上步骤参考了引用[2]中关于CLion远程调试的方法,以及引用[1]中关于远程ARM开发配置的基础。§§相关问题§§1.如何解决CLion远程调试ARM板时出现的连接超时问题?2.在CLion中如何配置多个远程调试目标?3.如何通过CLion调试运行在ARM板上的后台服务?</think>### CLion 远程调试 ARM 板配置指南 是的,CLion 支持对远程 ARM 板进行调试。以下是完整配置方法: #### 1. **环境准备** - **远程 ARM 板要求**: - 安装 SSH 服务(如 OpenSSH) - 安装 gdbserver:`sudo apt-get install gdbserver`(Debian/Ubuntu) - **本地 CLion 要求**: - 已配置 ARM 交叉编译工具链(参考前文) - 安装 ARMGDB:`sudo apt-get install gdb-multiarch` #### 2. **配置远程调试** 1. **在 ARM 板启动 gdbserver**: ```bash # 在 ARM 板终端执行 gdbserver :1234 ./your_program # 1234 为调试端口 ``` 2. **在 CLion 配置调试器**: - 打开 `Run → Edit Configurations` - 添加 `GDB Remote Debug` 配置 - 关键参数设置: ``` 'target remote' args: tcp://<ARM板IP>:1234 Symbol file: 本地编译的可执行文件路径(交叉编译生成的 ARM 程序) Path mappings: 本地路径 ↔ ARM 板路径(如 /home/user/project) Debugger: gdb-multiarch(或指定的 ARM GDB) ``` #### 3. **调试流程** 1. 在代码中设置断点 2. 选择创建的远程调试配置 3. 点击调试按钮(🐞图标) 4. CLion 将通过 SSH 连接到 gdbserver 并暂停在断点处 ![远程调试示意图](https://example.com/remote-debug.png)*调试界面示例[^2]* #### 4. **调试技巧** - **变量监视**:在调试窗口查看 ARM 板上的实时变量值 - **内存查看**:使用 Memory View 检查 ARM 内存数据 - **寄存器查看**:通过 Debugger → Registers 窗口 - **多线程调试**:支持线程切换和线程级断点 > **注意**:确保本地可执行文件ARM 板上的程序版本一致[^1]。若出现连接问题,检查防火墙设置和 SSH 配置。 #### 5. **高级配置(可选)** - **启动脚本**:在 GDB 配置中添加初始化脚本: ```gdb set sysroot /path/to/arm-sysroot # 指定 ARM 系统库路径 set solib-search-path /path/to/arm-libs ``` - **核心转储调试**:使用 `target remote | gdb-multiarch -c core.file` 分析崩溃现场
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值