Enable core dumps on Mac OS X Monterey M1 Pro

I use my Macs to develop MySQL software, it is extremely useful to analyse some crashes that happen when I develop new software. It has worked to enable this is in all my previous Macs. But I haven't found any way to enable it on the new Mac.

I tried ulimit -c unlimited, I tried to set sudo chmod a+rwx /cores I tried creating /etc/launchd.conf

But still no crash files appeared.

Any ideas are welcome.

Replies

launchd.conf hasn’t worked for a while now.

The best way to enable core dumps is at the point that you launch the program. How are you launching the programs that you want to dump core?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • I run a cluster locally using a tool called MTR that starts multiple processes. In the code I ensure that I stop using a call to abort() when I want to have a core file.

    In another Mac I have it working where core files are produced, even get a CrashReporter to pop up a window at the crash. Recall that I had to set some setting somewhere, but can't remember where it was, and haven't been able to find it using Google. The other Mac runs Mac OS X 11, this one runs Mac OS X Monterey.

    Right now for example I get a crash in pthread_cond_signal with Bus error. Printing the pointer before the call goes well and the pointer is aligned correctly. So this type of error is very hard to debug with core dumps.

Add a Comment

I found out that /cores directory was mounted as read-only file system. I used DiskUtility to fix that such that /cores was writeable. Unfortunately still no core files. I tested with a very simple program that called abort() immediately after starting the main function.

I have set ulimit -c unlimited and tested with launctl to set core limit there unlimited as well.

Still no success. This is extremely disturbing since it means that I cannot debug my application. It is impossible to figure out why a call to pthread_cond_signal fails with Bus error without having access to a core file.

Same issue. I tried also following recommendations from this thread to no effect: https://developer.apple.com/forums/thread/53023

By an amazing coincidence another developer opened a DTS tech support incident about this very issue last week, so I had a chance to dig into it. I have a theory as to what’s going on, but I’d like you to run a test before I go into the details. Specifically:

  1. On your macOS 12.0.1 machine, open a Terminal window.

  2. Configure the core limit:

    % ulimit -c unlimited
    
  3. Make a copy of your the command-line tool that’s failing to generate core.

    % cp /path/to/CrashSelf .
    
  4. Create a dummy .entitlements with the com.apple.security.get-task-allow entitlement set:

    % /usr/libexec/PlistBuddy -c "Add :com.apple.security.get-task-allow bool true" tmp.entitlements
    File Doesn't Exist, Will Create: tmp.entitlements
    
  5. Re-signed the tool with those entitlements:

    % codesign -s - -f --entitlements tmp.entitlements CrashSelf 
    CrashSelf: replacing existing signature
    
  6. Run that copy:

    % ./CrashSelf
    zsh: segmentation fault (core dumped)  ./CrashSelf
    
  7. Check for a core:

    % ls -al /cores                                                                              
    total 7301064
    drwxrwxr-t   3 root   admin          96 Nov 22 10:01 .
    drwxr-xr-x  20 root   wheel         640 Oct 17 20:30 ..
    -r--------   1 quinn  admin  3721371648 Nov 22 10:01 core.1783
    

Does that work?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • I tried those steps without success. I created a very simple crashing file as tmp.c and everything worked except that no cores were generated. I also tried setting it on my development binary that I want the core files for. Same result. I did manage to verify that the get-task-allow entitlement was set on the binaries. I was also able to attach a debugger to the process, but that didn't really give any extra information since I am still missing the core file.

    However after performing the following operation it worked :) sudo chmod 1777 /cores I had to verify that I could create files in the cores directory.

    And now I also got a core file of the program and the crash that I was looking for.

    While at it, on my previous Mac's I get a popup window after a crash. But I have forgotten how to enable this feature. Essentially get a popup window that shows the same information as found in the Console.

    Thx for the assistance!

  • ulimit -c unlimited, plus, codesigning with the entitlements shown worked for me on Monterey 12.4, for binary I created with gcc. I just added steps 4 and 5 to the target that builds the binary in my Makefile. Then and only then does the app coredump to /cores.

  • after finish 4 and 5 with ulimit -c unlimited, my program generate core dump successfully in macOS monterey12.5. But why steps 4 and 5 works?

However after performing the following operation it worked :)

sudo chmod 1777 /cores

The default permissions for /cores is:

% ls -ld /cores
drwxrwxr-t  2 root  admin  64 Oct 17 20:30 /cores

So, you shouldn’t need this unless you’re running as a non-admin user (this is a valid life choice, but rare for folks doing development work, which is why I didn’t consider it; sorry).

While at it, on my previous Mac's I get a popup window after a crash.

The Apple crash reporter does not, by default, display an alert when a non-GUI program crashes. You can tweak this default using the CrashReporterPrefs app, part of the Additional Tools for Xcode 13 (in Xcode, choose Xcode > Open Developer Tool > More Developer Tools).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • Thx, got it working with CrashReportPrefs as well. It is still a bit tricky to get the core files, but I gather I will soon understand the exact requirements on the order of doing things. So getting closer to a proper development environment.

    Regarding admin users I am developing a tree based on MySQL, in MySQL one is assumed to not run from root and rather from a normal user account, so have always been developing also from a normal user account.

    Thx for the great assistance.

  • Seems like you have to call codesign .... each time you recompile the binary to get core files.

    So in my case using it on a binary called I can do the following command after recompile:

    codesign -s - -f --entitlements ndbmtd.entitlements ndbmtd

Add a Comment

Seems like you have to call codesign … each time you recompile the binary to get core files.

Right. The entitlement is part of the code signature, so every new executable needs a new signature with that entitlement.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

The ulimit -c unlimited can also be done by the app via getrlimit and setrlimit. e.g.

#include <unistd.h>
#include <signal.h>
#include <sys/resource.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
  pid_t pid = getpid();
  struct rlimit l;
  int ret = getrlimit(RLIMIT_CORE, &l);

  printf("getrlimit returned %d\n", ret);
  printf("rlim_cur = %llu\n", l.rlim_cur);
  printf("rlim_max = %llu\n", l.rlim_max);
  l.rlim_cur = l.rlim_max;
  printf("setrlimit returned %d\n", setrlimit(RLIMIT_CORE, &l));
  printf("Time to kill myself\n");
  kill(pid, SIGBUS);
}

can also be done by the app

Yep. Indeed, this is super useful if have a GUI app that’s crashing for a user in a way that you can’t reproduce:

  1. Send them custom build of the app with this code.

  2. Have them run it and reproduce the problem.

  3. Then send you the core file.

  4. Which you can debug.

Core dumps are cool!

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

ls -ld /cores drwxrwxrwt 2 root admin 64 Oct 17 2021 /cores/ # it's been there a long time ls -lR /cores total 0

c /usr/bin/lprm .

/usr/libexec/PlistBuddy -c "Add :com.apple.security.get-task-allow bool true" tmp.entitlements File Doesn't Exist, Will Create: tmp.entitlements

codesign -s - -f --entitlements tmp.entitlements lprm

lprm: replacing existing signature

./lprm -P

zsh: killed ./lprm -P

or

sudo /home/user/lprm -P

zsh: killed

bash generates nearly the same unhelpful respose Killed: 9

https://nasa.github.io/trick/howto_guides/How-to-dump-core-file-on-MacOS.html I follow this article and it worked.