【问题标题】:How can I figure out the program that caused core dump?如何找出导致核心转储的程序?
【发布时间】:2015-10-24 11:52:07
【问题描述】:

我使用的是 Mac OS X 10.10。

我注意到我的硬盘已满,因为每隔几分钟,/cores 中就会出现一个新的核心转储文件:

$ ls -alhtr /cores
total 3551488
-rw-r--r--@  1 saqib  admin   6.0K Apr 24 12:38 .DS_Store
drwxr-xr-x  32 root   admin   1.1K Aug  1 17:00 ../
-r--------   1 saqib  admin   578M Aug  1 22:36 core.35049
-r--------   1 saqib  admin   578M Aug  1 22:37 core.35202
drwxrwxr-t@  6 root   admin   204B Aug  1 22:38 ./
-r--------   1 saqib  admin   578M Aug  1 22:38 core.35438

但我不知道哪些进程正在创建这些核心文件。文件名中的数字应该代表创建它们的进程的 PID。但当然,这些过程现在已经死了。那么如何确定是哪个进程创建了这些内核,以便修复/删除它呢?

编辑 1

在核心文件上执行gdb -c 并没有提供我需要的信息:

$ gdb -c /cores/core.35438
GNU gdb (GDB) 7.8.1
Copyright (C) 2014 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-apple-darwin14.0.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
"/cores/core.35438": no core file handler recognizes format
(gdb)

编辑 2

file 似乎也不起作用:

$ file /cores/core.35049
/cores/core.35049: Mach-O core i386

编辑 3

我使用名为MachOView 的应用程序打开了核心文件。你可以看到它向我展示的屏幕截图。我还是不知道是哪个应用创建了这个核心文件。

【问题讨论】:

  • 没有直接关系,但是你看过CrashReporter吗?它应该默认启用并记录所有崩溃,但您可能希望将其设置为开发人员模式,如 this wiki page 所示
  • 运行一个小循环,每秒将所有进程 ID 存储到一个文件中,然后等待核心到达,使用 Ctrl-C 停止循环,并检查文件中的 processId。 while :; do ps -aef &gt;&gt; /tmp/pids.txt; sleep 1; done

标签: unix osx-yosemite pid coredump


【解决方案1】:

我只需要在 OS X 10.13 上执行此操作,并且在 lldb 中使用 image list 命令对我有用。

lldb -c /cores/core.45943
(lldb) target create "/cores/core.45943"
Core file '/cores/core.45943' (i386) was loaded
(lldb) image list

【讨论】:

  • 这是我从 macOS 上的核心获取信息的唯一方法。
【解决方案2】:

运行控制台实用程序,该实用程序位于 /Applications/Utilities。在诊断和使用信息下查看用户诊断报告和系统诊断报告。每次最近的崩溃都应该有一个条目,包括程序名称、日期、时间和主机名。您可以单击其中的每一个以获取更多信息。

您也可以直接在文件系统中访问诊断报告。用户诊断报告位于 ~/Library/Logs/DiagnosticReports/ 中,系统诊断报告位于 /Library/Logs/DiagnosticReports/ 中。

【讨论】:

  • 我可以 grep 这个控制台文件吗?怎么样?
  • 当然,你可以使用 grep。我已将目录名称添加到答案中。
【解决方案3】:

如果系统安装了gdb,可以使用gdb -c ..命令:

gdb -c core.35049

你会得到如下输出:

GNU gdb (Ubuntu 7.9-1ubuntu1) 7.9
Copyright (C) 2015 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".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
[New LWP 2905]
Core was generated by `./a.out'.
Program terminated with signal SIGSEGV, Segmentation fault.

通过阅读,您将看到核心是由a.out 程序生成的。

更新

使用file,也可以获得类似的信息:

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

【讨论】:

  • 很遗憾,gdb -c 没用。我对原始帖子进行了编辑以说明原因。还有什么想法吗?
  • @SaqibAli,file /cores/core.35438 怎么样?
  • @SaqibAli,对不起,我不知道。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-19
相关资源
最近更新 更多