Skip to content

Commit 7036af3

Browse files
authored
configure.js: Add llnode command
Add an llnode command script that invokes lldb and pre-loads the plugin for ease of use. PR-URL: #108 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
1 parent ea763e3 commit 7036af3

4 files changed

Lines changed: 102 additions & 16 deletions

File tree

README.md

Lines changed: 68 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,45 @@
22

33
[![Build Status](https://secure.travis-ci.org/nodejs/llnode.png)](http://travis-ci.org/nodejs/llnode)
44

5-
Node.js v4.x-v6.x C++ plugin for [LLDB](http://lldb.llvm.org) - a next generation, high-performance debugger.
5+
Node.js v4.x-v8.x C++ plugin for the [LLDB](http://lldb.llvm.org) debugger.
6+
7+
The llnode plugin adds the ability to inspect JavaScript stack frames, objects,
8+
source code and more to the standard C/C++ debugging facilities when working
9+
with Node.js processes or core dumps in LLDB.
10+
11+
### Quick start
12+
13+
Start an lldb session with the llnode plugin pre-loaded:
14+
15+
```bash
16+
npm install -g llnode
17+
llnode node -c core
18+
```
19+
20+
- For more details on starting llnode see the [Usage](#usage) section.
21+
- To get started with the llnode commands see the [Commands](#commands) section.
622

723
## Demo
824

925
https://asciinema.org/a/29589
1026

1127
## Install Instructions
1228

13-
### Install with npm
29+
To use llnode you need to have the LLDB debugger installed.
30+
31+
- On OS X lldb is installed as part of Xcode. You will need Xcode both to build and run llnode.
32+
- On Linux install the lldb package using your distributions package manager.
33+
34+
### Global install with npm
1435

1536
```bash
16-
npm install llnode
37+
npm install -g llnode
1738
```
1839

1940
To use a particular build of lldb, use the `--lldb_exe` option:
2041

2142
```bash
22-
npm install --lldb_exe=`which lldb-3.9` llnode
43+
npm install --lldb_exe=`which lldb-3.9` -g llnode
2344
```
2445

2546
### Install with Homebrew (OS X)
@@ -75,11 +96,29 @@ make -C out/ -j9
7596
sudo make install-linux
7697
```
7798

78-
## Usage
99+
## Loading the lldb plugin library.
100+
101+
The simplest method is:
102+
```bash
103+
npm install -g llnode
104+
llnode
105+
```
106+
107+
If you do a global install (npm install -g llnode) you can use the `llnode`
108+
shortcut script. This starts `lldb` and automatically issues the `plugin load` command.
109+
All parameters to the llnode script are passed directly to lldb. If you do not do a
110+
local install the shortcut will be in `node_modules/.bin/llnode`
111+
112+
If you run either `make install-linux` or `make install-osx` the plugin will installed
113+
in the LLDB system plugin directory, in which case LLDB will load the plugin
114+
automatically on start-up. Using this may require additional permissions to be able to
115+
copy the plugin libary to the system plugin directory.
79116

80-
The llnode plugin can be loaded into LLDB using the `plugin load` command.
81-
Alternatively it can be installed in the LLDB system plugin directory, in
82-
which case LLDB will load the plugin automatically on start-up.
117+
The llnode plugin can also be manually loaded into LLDB using the
118+
`plugin load` command within lldb.
119+
120+
It does not matter whether the `plugin load` command is issued before or after
121+
loading a core dump or attaching to a process.
83122

84123
### OS X
85124

@@ -106,22 +145,35 @@ To install the plugin in the LLDB system plugin directory, use the
106145
npm copy `node_modules/llnode/llnode.so` to
107146
`/usr/lib/lldb/plugins`.
108147

148+
# Usage
149+
109150
To use llnode with a core dump the core dump needs to be loaded into lldb
110151
along with the exact executable that created the core dump. The executable
111-
contains information that lldb and llnode need to make sense of the data in
112-
the core dump.
152+
contains information that lldb and the llnode plugin need to make sense of
153+
the data in the core dump.
113154

114-
To load the core dump when starting lldb use:
155+
To load a core dump when starting llnode use:
115156
```
116-
lldb /path/to/bin/node -c /path/to/core
157+
llnode /path/to/bin/node -c /path/to/core
117158
```
118159
or to load the core dump after starting lldb:
119160
```
120-
(lldb) target create /path/to/bin/node -c /path/to/core
161+
(llnode) target create /path/to/bin/node -c /path/to/core
121162
```
122163

123-
It does not matter whether the `plugin load` command is issued before or after
124-
loading a core dump.
164+
To use llnode against a live process:
165+
```
166+
llnode -- /path/to/bin/node script.js
167+
(llnode) run
168+
```
169+
This is ideal for debugging an npm package with native code.
170+
To debug a Node.js crash on uncaught exception:
171+
```
172+
llnode -- /path/to/bin/node --abort_on_uncaught_exception script.js
173+
(llnode) run
174+
```
175+
lldb will stop your process when it crashes. To see where it stopped use the
176+
v8 bt command. See the [Commands](#commands) section below for more commands.
125177

126178
### Commands
127179

@@ -152,6 +204,7 @@ The following subcommands are supported:
152204
* -v, --value expr - all properties that refer to the specified JavaScript object (default)
153205
* -n, --name name - all properties with the specified name
154206
* -s, --string string - all properties that refer to the specified JavaScript string value
207+
* --array-length num - print maximum of `num` elements in array
155208
156209
inspect -- Print detailed description and contents of the JavaScript value.
157210

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"directories": {
77
"test": "test"
88
},
9+
"bin" : { "llnode" : "scripts/llnode.sh"},
910
"//": "(Blame C++)",
1011
"scripts": {
1112
"preinstall": "node scripts/configure.js",

scripts/configure.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ fs.mkdirSync('tools');
107107
console.log(`Linking tools/gyp to ${gypDir}/gyp`);
108108
fs.symlinkSync(`${gypDir}/gyp`, 'tools/gyp');
109109

110+
fs.writeFileSync(`${buildDir}/scripts/llnode.sh`, scriptText(lldbExe));
111+
110112
// Exit with success.
111113
process.exit(0);
112114

@@ -140,7 +142,7 @@ function getDarwinRelease() {
140142
}
141143

142144
// Find the 'best' lldb to use. Either:
143-
// - the one specified by the user using npm --llnode_exe=... install llnode
145+
// - the one specified by the user using npm --lldb_exe=... install llnode
144146
// - the default lldb executable
145147
// - the higest known lldb version
146148
function getLldbExecutable() {
@@ -215,3 +217,28 @@ function getLinuxHeadersDir(version) {
215217
}
216218
return undefined;
217219
}
220+
221+
function scriptText(lldbExe) {
222+
223+
let lib = 'llnode.so';
224+
if (osName === 'Darwin') {
225+
lib = 'llnode.dylib';
226+
}
227+
228+
return `#!/bin/sh
229+
230+
LLNODE_SCRIPT=\`node -p "path.resolve('$0')"\`
231+
232+
SCRIPT_PATH=\`dirname $LLNODE_SCRIPT\`
233+
if [ \`basename $SCRIPT_PATH\` = ".bin" ]; then
234+
# llnode installed locally in node_modules/.bin
235+
LLNODE_PLUGIN="$SCRIPT_PATH/../llnode/${lib}"
236+
else
237+
# llnode installed globally in lib/node_modules
238+
LLNODE_PLUGIN="$SCRIPT_PATH/../lib/node_modules/llnode/${lib}"
239+
fi
240+
241+
${lldbExe} --one-line "plugin load $LLNODE_PLUGIN" --one-line "settings set prompt '(llnode) '" $@
242+
`;
243+
244+
}

scripts/llnode.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
echo "Place holder script for llnode"
4+
5+
exit 1;

0 commit comments

Comments
 (0)