Linux 程序崩溃后的源码定位

28 篇文章 1 订阅
Linux 程序崩溃后的源码定位: 以centos为例
1. 在系统中运行下列命令:
#ulimit -c unlimited
#echo "1" > /proc/sys/kernel/core_uses_pid
#echo "core-%e-%p-%t" > /proc/sys/kernel/core_pattern  


关于这些命令:


先设置崩溃后转储文件大小:ulimit -c 1024(kbytes单位)或者ulimit -c unlimited
查看 ulimit -c 
查看崩溃文件输出位置:more  /proc/sys/kernel/core-pattern
设置崩溃文件输出位置:
                 echo "1" > /proc/sys/kernel/core-user-pid使core文件名加上pid号 或
                 echo "/root/corefile/core-%e-%p-%t" > /proc/sys/kernel/core-pattern控制core文件保存位置和文件名格式。
                    如果你想把崩溃后的文件输出到当前目录 下 echo "core-%e-%p-%t" > /proc/sys/kernel/core-pattern
                    以下是参数列表:
                        %p - insert pid into filename 添加pid
                        %u - insert current uid into filename 添加当前uid
                        %g - insert current gid into filename 添加当前gid
                        %s - insert signal that caused the coredump into the filename 添加导致产生core的信号
                        %t - insert UNIX time that the coredump occurred into filename 添加core文件生成时的unix时间
                        %h - insert hostname where the coredump happened into filename 添加主机名
                        %e - insert coredumping executable name into filename 添加命令名
    






2. 在你的工程编译时加 -g,假如编译的可执行文件为xx.bin


3. #objcopy --only-keep-debug xx.bin xx.bin.dbg
   此时会生成一个调试用的信息文件xx.bin.dbg,当然也可以#objcopy  xx.bin xx.bin.dbg 这样崩溃后得到的信息更全面,不过这个文件会大一点.


4. #strip xx.bin
   用来减小可执行文件的体积


5. 在程序跑挂后,会在当前目录生成core文件


6. gdb -c core文件 xx.bin 


7. 进入gdb后,执行file xx.bin.dbg


6. bt 或者 where 就能看到你的程序挂到哪里, 如果你的在第3步 没有加  --only-keep-debug  这个参数,你就可以看到当时参数的值.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值