在程序运行过程中使用gdb产生core文件

方法1、
(1)先获取进程的PID
ps -aux | grep test

# ps -aux | grep test
root      6906 85.7  0.0   4212   356 pts/0    R+   00:56   3:57 ./test
root      6978  0.0  0.0 112708   980 pts/1    R+   01:01   0:00 grep --color=auto test

(2)直接使用gcore产生coredump文件

# gcore 6906
func_1 () at test.c:6
6	    while (1);
Saved corefile core.6906
# ls
123  core.6819  core.6906  test  test.c
[root@localhost ~/test/test_2]

方法2、
(1)获取进程PID号;
(2)使用gdb工具attach到进程上;
(3)使用gcore + coredump文件名,生成coredump文件;
(4)使用detach脱离进程;
(5)使用quit退出gdb。

# gdb 
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-114.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) attach 6906
Attaching to process 6906
Reading symbols from /root/test/test_2/test...done.
Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
func_1 () at test.c:6
6	    while (1);
Missing separate debuginfos, use: debuginfo-install glibc-2.17-260.el7.x86_64
(gdb) gcore test_coredump
Saved corefile test_coredump
(gdb) detach
Detaching from program: /root/test/test_2/test, process 6906
(gdb) quit
[root@localhost ~/test/test_2]

方法3、
先fork创建一个子进程,子进程拥有和父进程一样的内存空间了,然后在子进程触发abort信号,让子进程进行core
dump。

https://www.cnblogs.com/youxin/p/8833877.html
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值