在 Ubuntu 上生成核心文件

在 Ubuntu 上生成核心文件

最近我一直在尝试在 Ubuntu 上启用核心转储。我编写了一个简单的程序,但它会崩溃(它会将一些数据写入数组之外)。

起初,没有生成核心转储。这是因为 ulimit 设置为零,所以我运行命令:ulimit -c unlimited。这没有帮助,因为大多数核心转储都落到了apport。我还通过另一个简单命令禁用了此功能:echo "core" > /proc/sys/kernel/core_pattern

结果,核心生成了,但仍然无法被读取gdb。以下是的输出gdb

root@melon:/home/melon/test# gdb ./a.out ./core.3506 
GNU gdb (GDB) 7.5-ubuntu
Copyright (C) 2012 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-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/melon/test/a.out...done.
[New LWP 3506]

warning: Can't read pathname for load map: Input/output error.
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0  0x00007fa2dc0f976d in ?? ()
(gdb) bt
#0  0x00007fa2dc0f976d in ?? ()
#1  0x0000000000000000 in ?? ()

以下是命令的输出file

core.3506: ELF 64-bit LSB core file x86-64, version 1 (SYSV), SVR4-style, from './a.out'

开头是ulimit -a

core file size          (blocks, -c) unlimited

并回应更重要的/proc/sys/kernel输出:

cat /proc/sys/kernel/core_pattern 
core

cat /proc/sys/kernel/core_uses_pid 
1

cat /proc/sys/kernel/core_pipe_limit 
0

我的问题是我做错了什么?如何生成一个将被读取的核心文件gdb

答案1

看起来你的 elf 缺少调试符号。也许它只是用

g++ -g -rdynamic -o main main.cpp

相关内容