Skip to content

Instantly share code, notes, and snippets.

@erabhimanyu
Last active March 1, 2021 06:42
Show Gist options
  • Select an option

  • Save erabhimanyu/8bb3b9909f3d2acdbe8ae019edb126ba to your computer and use it in GitHub Desktop.

Select an option

Save erabhimanyu/8bb3b9909f3d2acdbe8ae019edb126ba to your computer and use it in GitHub Desktop.

Node postmortem debugging (OSX)

1. Taking core dump

To get core dump of running node process:

  • Take PID of that process:

    pgrep -lf node
  • Run lldb debugger with attached process:

    lldb -p <PID>
  • Take a dump of process data:

    (lldb) process save-core <FILE_NAME>

Alternative: If you have signed (on OSX only) gdb with gcore you can run simply gcore <PID>

2. Extend lldb with v8 debugger support

  • Fetch the repository with lldb extension. (It will be used later).

    git clone git@github.com:nodejs/llnode.git
  • Install llnode

    brew install llnode
  • Install python with pip if you don't have it already.

    brew install python
  • Install python six module

    pip install six
  • Link llnode with lldb

    mkdir -p ~/Library/Application\ Support/LLDB/PlugIns
    ln -sf /usr/local/opt/llnode/llnode.dylib ~/Library/Application\ Support/LLDB/PlugIns/

3. Debug

In order to have full functionallity we need to have generated memory ranges file for each core dump that we want to investigate.

  • To do so we need to run from previously fetched llnode repo(this is not needed for lldb version 3.9 - nodejs/llnode#91):

    ./scripts/otool2segments.py <GENERATED_CORE_DUMP> > <RANGES_FILE>
  • Then just export that file in environment variable (this is not needed for lldb version 3.9).

    export LLNODE_RANGESFILE=<RANGES_FILE>
  • Run lldb with our node dump - we need to use the exact node binary as the dump was created

    lldb node -c <GENERATED_CORE_DUMP>
  • Check if everything works:

    (lldb) help v8

Some docs for v8 commands are available here: https://developer.ibm.com/node/2016/09/27/advances-in-core-dump-debugging-for-node-js/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment