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

本文主要是描述在调试用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.

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值