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.

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 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"

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"

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.

Enable core dumps on Mac OS X Monterey M1 Pro
 
 
Q