It seems like I can not generate core dumps in Mac OS X 10.6.8.
$ ulimit -c unlimited
$ ./a.out
Hello world!
Segmentation fault
$ find ~/ -type f -name core
# ls -la /cores/
total 0
drwxrwxr-t@ 2 root admin 68 24 jui 2010 .
drwxrwxr-t 31 root admin 1122 17 oct 15:52 ..
My current directory, my HOME and /cores/ remain empty…
A core dump is a file that gets automatically generated by the Linux kernel after a program crashes. This file contains the memory, register values, and the call stack of an application at the point of crashing.
Core dumps are located in the /cores/ directory for all versions. MacOS 10.4 and Higher: Core dumps are disabled by default. To enable core dumps on a MacOS machine of version 10.4 and higher create the file, /etc/launchd.
By default, crashes are reported into .crash
files which can be found in /Library/Logs/DiagnosticReports
(system-wide) and ~/Library/Logs/DiagnosticReports
(user). These files can be opened by using Console app, in User or System Reports. The .crash
files are in plain text format and should include relevant information about the crash.
In order to activate the full core dumps, make sure that /cores
directory has write permissions for the current user (test by: touch /cores/test && rm /cores/test
). In addition, make sure that you don't have any limits on core file sizes by:
ulimit -c unlimited
The name of the core dump file is in format: core
.PID
.
If the directory is hidden, you can show the hidden files by:
defaults write com.apple.finder AppleShowAllFiles TRUE
You can test that by the following commands:
sleep 100 &
killall -SIGSEGV sleep
which should say extra (core dumped)
, after Segmentation fault message.
The core dump files should be found by default in /cores
directory.
Example by commands:
$ ulimit -c unlimited
$ sleep 100 &
$ killall -SIGSEGV sleep # Then press Enter few times till below message is shown
[1]+ Segmentation fault: 11 (core dumped) sleep 100
$ ls /cores
core.13652
$ lldb -c /cores/core.*
(lldb) target create --core "/cores/core.13652"
Core file '/cores/core.13652' (x86_64) was loaded.
(lldb) bt
* thread #1, stop reason = signal SIGSTOP
* frame #0: 0x00007fffa7d13fde libsystem_kernel.dylib`__semwait_signal + 10
frame #1: 0x00007fffa7c9ab92 libsystem_c.dylib`nanosleep + 199
frame #2: 0x000000010c090002 sleep`rpl_nanosleep + 128
See also: Technical Note TN2118 - Kernel Core Dumps.
You can generate core dump files on Mac Os X like this:
Create the file : /etc/launchd.conf
, then :
echo "limit core unlimited" | sudo tee -a /etc/launchd.conf
Restart your Mac.
And that's it, the core dump files are generated in the /cores
directory. Be careful the core dump files are large files so when you finishing troubleshooting your code, remove them.
Apple list a number of ways to generate core dump files in their TN2124 or Mac OS X Debugging Magic.
Here's a couple of extracts:
Prior to Mac OS X 10.4, you would enable core dumps on a system-wide basis by changing the line "COREDUMPS=-NO-" in /etc/hostconfig to "COREDUMPS=-YES-" and then restarting
And
# BSH
$ ulimit -c unlimited
# CSH
% limit coredumpsize unlimited
You can even do it programatically:
#include <sys/resource.h>
static bool EnableCoreDumps(void)
{
struct rlimit limit;
limit.rlim_cur = RLIM_INFINITY;
limit.rlim_max = RLIM_INFINITY;
return setrlimit(RLIMIT_CORE, &limit) == 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With