Mac 上的核心转储写在哪里?

发布于 2024-08-18 21:06:26 字数 115 浏览 3 评论 0原文

在 Mac OS X 上,如果我向 C 程序发送 SIGQUIT,它会终止,但没有核心转储文件。

您是否必须在 Mac OS X 上手动启用核心转储(如何?),或者它们是否写入其他位置而不是工作目录?

On Mac OS X, if I send SIGQUIT to my C program, it terminates, but there is no core dump file.

Do you have to manually enable core dumps on Mac OS X (how?), or are they written to somewhere else instead of the working directory?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

七七 2024-08-25 21:06:26

看来他们默认是被压制的。运行

$ ulimit -c unlimited

将为当前终端启用核心转储,并将其作为 core.PID 放置在 /cores 中。当您打开新会话时,它将再次设置为默认值。

It seems they are suppressed by default. Running

$ ulimit -c unlimited

Will enable core dumps for the current terminal, and it will be placed in /cores as core.PID. When you open a new session, it will be set to the default value again.

柏林苍穹下 2024-08-25 21:06:26

在 macOS 上,您的故障转储由故障报告器自动处理。

您可以通过执行Console并转到用户诊断报告来查找回溯文件 部分(在“诊断和使用信息”组下),或者您可以在 ~/Library/Logs/DiagnosticReports 中找到它们。

您还可以通过监视system.log 文件来检查转储的生成位置,例如

tail -f /var/log/system.log | grep crash

您可以在/cores 中找到实际的core 转储文件。

另请参阅:

On macOS, your crash dumps are automatically handled by Crash Reporter.

You can find backtrace files by executing Console and going to User Diagnostic Reports section (under 'Diagnostic and Usage Information' group) or you can locate them in ~/Library/Logs/DiagnosticReports.

You can also check where dumps are generated by monitoring system.log file, e.g.

tail -f /var/log/system.log | grep crash

The actual core dump files you can find in /cores.

See also:

◇流星雨 2024-08-25 21:06:26

此外,/cores 目录必须存在,并且运行该程序的用户必须对其具有写入权限。

Additionally, the /cores directory must exist and the user running the program must have write permissions on it.

沦落红尘 2024-08-25 21:06:26

上面的答案,

ulimit -c 无限

有效 - 但请确保在运行转储核心的程序的同一终端中运行它。您需要先运行 ulimit 命令。

The answer above,

ulimit -c unlimited

works -- but be sure to run that in the same terminal from which you will run the program that dumps core. You need to run the ulimit command first.

假装爱人 2024-08-25 21:06:26

默认情况下,mac osx 中的特定目录是隐藏的。您可能想在终端中启用此功能,然后核心转储应该在目录 /cores 中可见。

默认写入 com.apple.finder AppleShowAllFiles TRUE

by default, specific directories in mac osx are hidden. you might want to enable this feature in the terminal and then the core dump should be visible within the directory /cores.

defaults write com.apple.finder AppleShowAllFiles TRUE

野侃 2024-08-25 21:06:26

Apple 论坛上的 Quinn “The Eskimo!” 有一个很好的解释
https://developer.apple.com/forums/thread/694233

我大致遵循那个指南。这是我所做的步骤。

授予对 /cores 目录的所有写入权限

PROMPT> ls -la / | grep cores
drwxr-xr-x    2 root  wheel    64 Dec  8  2021 cores
PROMPT> sudo chmod 1777 /cores
PROMPT> ls -la / | grep cores
drwxrwxrwt    2 root  wheel    64 Dec 21 23:29 cores

设置 core 文件的大小

PROMPT> ulimit -c unlimited

编译并签署程序

PROMPT> cargo build --release -p my-crashing-program
PROMPT> /usr/libexec/PlistBuddy -c "Add :com.apple.security.get-task-allow bool true" tmp.entitlements
PROMPT> codesign -s - -f --entitlements tmp.entitlements my-crashing-program

运行程序

PROMPT> my-crashing-program
thread 'main' panicked at 'boom', my-crashing-program/src/main.rs:74:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
dumping core for pid 80995
zsh: quit       my-crashing-program

现在有一个 core 文件

PROMPT> ls /cores
core.80995

还有 Apple 的 Console 应用程序有一个包含崩溃报告的列表。

There is a great explanation by Quinn “The Eskimo!” on Apple's forums
https://developer.apple.com/forums/thread/694233

I roughly followed that guide. Here are the steps that I did.

Grant write all access to the /cores dir

PROMPT> ls -la / | grep cores
drwxr-xr-x    2 root  wheel    64 Dec  8  2021 cores
PROMPT> sudo chmod 1777 /cores
PROMPT> ls -la / | grep cores
drwxrwxrwt    2 root  wheel    64 Dec 21 23:29 cores

Set size of core file

PROMPT> ulimit -c unlimited

Compile and sign the program

PROMPT> cargo build --release -p my-crashing-program
PROMPT> /usr/libexec/PlistBuddy -c "Add :com.apple.security.get-task-allow bool true" tmp.entitlements
PROMPT> codesign -s - -f --entitlements tmp.entitlements my-crashing-program

Run the program

PROMPT> my-crashing-program
thread 'main' panicked at 'boom', my-crashing-program/src/main.rs:74:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
dumping core for pid 80995
zsh: quit       my-crashing-program

Now there is a core file

PROMPT> ls /cores
core.80995

Also Apple's Console app has a list with Crash Reports.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文