I assume that you have an access to ssh and node server process is up and running.
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>
It won't kill your service, so you can dump it while is running
Alternative: If you have signed (on OSX only)
gdb
withgcore
you can run simplygcore <PID>
-
Fetch the repository with lldb extension. (It will be used later).
git clone [email protected]:nodejs/llnode.git
-
Install
llnode
brew install llnode
-
Install
python
withpip
if you don't have it already.brew install python
-
Install python
six
modulepip install six
-
Link
llnode
withlldb
mkdir -p ~/Library/Application\ Support/LLDB/PlugIns ln -sf /usr/local/opt/llnode/llnode.dylib ~/Library/Application\ Support/LLDB/PlugIns/
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:
./scripts/otool2segments.py <GENERATED_CORE_DUMP> > <RANGES_FILE>
-
Then just export that file in environment variable.
export LLNODE_RANGESFILE=<RANGES_FILE>
-
Run
lldb
with our node dump. (Please notice thatnode
binary should be the same as your generated coredump)lldb node -c <GENERATED_CORE_DUMP>
Alternative: You can also lunch it with single command:
env LLNODE_RANGESFILE=<RANGES_FILE> 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/