Coder Social home page Coder Social logo

segv's Introduction

This is copied from How to Dump a Core File on MacOS (Monterey 12.5)

How to Dump a Core File on MacOS (Monterey 12.5)

A core dump (file) records the memory and state of a program at some moment in time, usually when it terminates abnormally. Core dumps can be useful in debugging in certain situations.

On MacOS, the ability to dump a core file must be enabled. The following steps describe how.

1. Ensure /cores Directory is Writable

Core-files are stored in the /cores directory on MacOS. You must have permission to write to it. To ensure this:

% sudo chmod 1777 /cores

2. Set Kernel State to Allow Core-dumps

The kernel state variable kern.coredump must be set in order to dump core-files. This needs to be set only once; it is persistent between reboots. To set it:

% sudo sysctl kern.coredump=1

To check its current value:

% sudo sysctl kern.coredump

3. Code-sign the Executable

For an executable to dump a core-file it must be signed. To do this, create an .entitlements file with the com.apple.security.get-task-allow entitlement set:

/usr/libexec/PlistBuddy -c "Add :com.apple.security.get-task-allow bool true" segv.entitlements

Using this .entitlements file, sign the executable:

codesign -s - -f --entitlements segv.entitlements segv

4. Set ulimit -c unlimited

Before running the executable from which you want a core-dump run the following :

% ulimit -c unlimited

This sets shell resources necessary for a core-dump. This setting is not persistent between shells.

Example Code:

segv.c

int main() {
    int *p = (void*)0;
    *p = 0;
    return 0;
}

makefile

all: segv

segv: segv.c segv.entitlements
        clang -g segv.c -o segv
        codesign -s - -f --entitlements segv.entitlements segv

segv.entitlements:
        /usr/libexec/PlistBuddy -c "Add :com.apple.security.get-task-allow bool true" segv.entitlements

clean:
        rm segv
        rm segv.entitlements
        rm -rf segv.dSYM

segv's People

Contributors

jcouball avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.