Skip to content

Commit 775dd6c

Browse files
committed
doc, test: doc API design, add tests
PR-URL: #206 Refs: #14 Reviewed-By: Matheus Marchini <[email protected]>
1 parent c00c41e commit 775dd6c

13 files changed

+333
-65
lines changed

.travis.yml

+20-1
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,35 @@ matrix:
77
before_install:
88
- sudo apt-get -qq update
99
- sudo apt-get install lldb-3.9 liblldb-3.9-dev -y
10+
install: npm install --llnode_build_addon=true
11+
script: TEST_LLDB_BINARY=`which lldb-3.9` npm run test-all
1012
node_js: "6"
1113
- sudo: required
1214
dist: trusty
1315
before_install:
1416
- sudo apt-get -qq update
1517
- sudo apt-get install lldb-3.9 liblldb-3.9-dev -y
18+
install: npm install --llnode_build_addon=true
19+
script: TEST_LLDB_BINARY=`which lldb-3.9` npm run test-all
1620
node_js: "8"
1721
- sudo: required
1822
dist: trusty
1923
before_install:
2024
- sudo apt-get -qq update
2125
- sudo apt-get install lldb-3.9 liblldb-3.9-dev -y
26+
install: npm install --llnode_build_addon=true
27+
script: TEST_LLDB_BINARY=`which lldb-3.9` npm run test-all
2228
node_js: "9"
2329
- sudo: required
2430
dist: trusty
2531
before_install:
2632
- sudo apt-get -qq update
2733
- sudo apt-get install lldb-3.9 liblldb-3.9-dev -y
34+
install: npm install --llnode_build_addon=true
35+
script: TEST_LLDB_BINARY=`which lldb-3.9` npm run test-all
2836
node_js: "10"
2937
# Test Node.js master nightly build
38+
# Addon is not tested due to lack of node-addon-api
3039
- node_js: "node"
3140
sudo: required
3241
dist: trusty
@@ -35,10 +44,12 @@ matrix:
3544
- sudo apt-get install lldb-3.9 liblldb-3.9-dev -y
3645
install:
3746
- npm install --nodedir=$(dirname $(dirname $(which node)))/include/node
47+
script: TEST_LLDB_BINARY=`which lldb-3.9` npm run test-plugin
3848
env:
3949
- NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly
4050
- NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly
4151
# Test Node.js v8-canary nightly build
52+
# Addon is not tested due to lack of node-addon-api
4253
- node_js: "node"
4354
sudo: required
4455
dist: trusty
@@ -47,21 +58,30 @@ matrix:
4758
- sudo apt-get install lldb-3.9 liblldb-3.9-dev -y
4859
install:
4960
- npm install --nodedir=$(dirname $(dirname $(which node)))/include/node
61+
script: TEST_LLDB_BINARY=`which lldb-3.9` npm run test-plugin
5062
env:
5163
- NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/v8-canary
5264
- NODEJS_ORG_MIRROR=https://nodejs.org/download/v8-canary
5365
# Test on OS X
5466
- os: osx
5567
osx_image: xcode9.3
68+
install: npm install --llnode_build_addon=true
69+
script: npm run test-all
5670
node_js: "6"
5771
- os: osx
5872
osx_image: xcode9.3
73+
install: npm install --llnode_build_addon=true
74+
script: npm run test-all
5975
node_js: "8"
6076
- os: osx
6177
osx_image: xcode9.3
78+
install: npm install --llnode_build_addon=true
79+
script: npm run test-all
6280
node_js: "9"
6381
- os: osx
6482
osx_image: xcode9.3
83+
install: npm install --llnode_build_addon=true
84+
script: npm run test-all
6585
node_js: "10"
6686
allow_failures:
6787
# Allow the nightly installs to fail
@@ -80,4 +100,3 @@ matrix:
80100
branches:
81101
only:
82102
- master
83-
script: make _travis

JSAPI.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Draft of the JavaScript API
2+
3+
This is currently a work in progress, expect the API to change significantly.
4+
Specifically, the APIs returning strings as results of inspection should return
5+
structured data instead for ease of use.
6+
7+
```js
8+
class LLNode {
9+
/**
10+
* @param {string} dump path to the coredump
11+
* @param {string} executable path to the node executable
12+
* @returns {LLNode} an LLNode instance
13+
*/
14+
static fromCoredump(dump, executable) {}
15+
16+
/**
17+
* @returns {string} SBProcess information
18+
*/
19+
getProcessInfo() {}
20+
21+
/**
22+
* @typedef {object} Frame
23+
* @property {string} function
24+
*
25+
* @typedef {object} Thread
26+
* @property {number} threadId
27+
* @property {number} frameCount
28+
* @property {Frame[]} frames
29+
*
30+
* @typedef {object} Process
31+
* @property {number} pid
32+
* @property {string} state
33+
* @property {number} threadCount
34+
* @property {Thread[]} threads
35+
*
36+
* @returns {Process} Process data
37+
*/
38+
getProcessObject() {}
39+
40+
/**
41+
* @typedef {object} HeapInstance
42+
* @property {string} address
43+
* @property {string} value
44+
*
45+
* @typedef {object} HeapType
46+
* @property {string} typeName
47+
* @property {string} instanceCount
48+
* @property {string} totalSize
49+
* @property {LLNode} llnode
50+
* @property {Iterator<HeapInstance>} instances
51+
*
52+
* @returns {HeapType[]}
53+
*/
54+
getHeapTypes() {}
55+
56+
/**
57+
* TODO: rematerialize object
58+
* @returns {HeapInstance}
59+
*/
60+
getObjectAtAddress(address) {}
61+
}
62+
```

Makefile

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
TEST_LLDB_BINARY ?= $(shell which lldb-3.9)
2-
31
.PHONY: all
4-
all:
5-
@echo "Please take a look at README.md"
2+
all: configure-with-addon
3+
node-gyp rebuild
4+
node scripts/cleanup.js
65

76
.PHONY: install-osx
87
install-osx: plugin
@@ -32,20 +31,19 @@ format:
3231
configure:
3332
node scripts/configure.js
3433

34+
.PHONY: configure-with-addon
35+
configure-with-addon:
36+
LLNODE_BUILD_ADDON=true node scripts/configure.js
37+
3538
.PHONY: plugin
3639
plugin: configure
3740
node-gyp rebuild
3841
node scripts/cleanup.js
3942

4043
.PHONY: addon
41-
addon: configure
44+
addon: configure-with-addon
4245
node-gyp rebuild
4346

44-
.PHONY: _travis
45-
_travis:
46-
TEST_LLDB_BINARY="$(TEST_LLDB_BINARY)" \
47-
npm test
48-
4947
.PHONY: clean
5048
clean:
5149
$(RM) -r build

README.md

+19-6
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,28 @@ The easiest way to build the plugin:
259259
# Clone this repo
260260
git clone https://github.com/nodejs/llnode.git && cd llnode
261261
262-
# Configure and build the plugin
262+
# Configure and build the plugin with npm
263263
npm install
264-
# Or run
264+
# To configure and build the plugin without npm
265+
node scripts/configure.js && node scripts/install.js && node scripts/cleanup.js
266+
# Or use make
265267
make plugin
268+
269+
# To configure and build both the plugin and the addon
270+
npm install --llnode_build_addon=true
271+
# Without npm
272+
LLNODE_BUILD_ADDON=true node scripts/configure.js && node scripts/install.js && node scripts/cleanup.js
273+
# Or use make
274+
make addon # Builds the addon
275+
make # Builds both the addon and the plugin
266276
```
267277
268278
To configure the build yourself:
269279
270280
```bash
271281
# Detect available lldb installation and download headers if necessary
272282
node scripts/configure.js
283+
# To build the addon, set the environment variable LLNODE_BUILD_ADDON=true
273284
274285
# To configure with the detected lldb installation
275286
node-gyp configure
@@ -280,7 +291,7 @@ node-gyp configure -- -Dlldb_include_dir=/usr/local/Cellar/llvm/5.0.0/include
280291
# contains `liblldb.so` or `liblldb.dylib`
281292
node-gyp configure -- -Dlldb_lib_dir=/usr/lib/llvm-3.9/lib
282293
283-
# Build the plugin
294+
# Build the plugin (and the addon if LLNODE_BUILD_ADDON=true)
284295
node-gyp build
285296
286297
# Move the built plugin to the project directory
@@ -292,14 +303,16 @@ node scripts/cleanup.js
292303
To run the tests, if `lldb` is an executable on the `PATH`:
293304
294305
```bash
295-
npm run test
306+
npm run test-all # Run both addon and plugin tests
307+
npm run test-plugin # Run plugin tests
308+
npm run test-addon # Run addon tests
296309
```
297310
298311
If the LLDB executable is named differently, point `TEST_LLDB_BINARY`
299-
to it:
312+
to it before running the tests:
300313
301314
```bash
302-
TEST_LLDB_BINARY=`which lldb-4.0` npm run test
315+
TEST_LLDB_BINARY=`which lldb-4.0` npm run test-all
303316
```
304317
305318
### Useful Environment Variables

binding.gyp

+46-39
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
# gyp does not appear to let you test for undefined variables, so define
99
# lldb_lib_dir as empty so we can test it later.
1010
"lldb_lib_dir%": "",
11-
"lldb_lib_so%": ""
11+
"lldb_lib_so%": "",
12+
"build_addon": "false",
1213
},
1314

1415
"target_defaults": {
@@ -85,47 +86,53 @@
8586
],
8687
}]
8788
]
88-
}, {
89-
"target_name": "addon",
90-
"type": "loadable_module",
91-
"include_dirs": [
92-
"<!@(node -p \"require('node-addon-api').include\")"
93-
],
94-
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
95-
"sources": [
96-
"src/addon.cc",
97-
"src/llnode_module.cc",
98-
"src/llnode_api.cc",
99-
"src/constants.cc",
100-
"src/error.cc",
101-
"src/llv8.cc",
102-
"src/llv8-constants.cc",
103-
"src/llscan.cc",
104-
"src/node-constants.cc",
105-
],
106-
"cflags!": [ "-fno-exceptions" ],
107-
"cflags_cc!": [ "-fno-exceptions" ],
108-
"conditions": [
109-
[ "OS=='linux' or OS=='freebsd'", {
89+
}],
90+
91+
"conditions": [
92+
[ "build_addon == 'true'", {
93+
"targets": [{
94+
"target_name": "addon",
95+
"type": "loadable_module",
96+
"include_dirs": [
97+
"<!@(node -p \"require('node-addon-api').include\")"
98+
],
99+
"defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
100+
"sources": [
101+
"src/addon.cc",
102+
"src/llnode_module.cc",
103+
"src/llnode_api.cc",
104+
"src/constants.cc",
105+
"src/error.cc",
106+
"src/llv8.cc",
107+
"src/llv8-constants.cc",
108+
"src/llscan.cc",
109+
"src/node-constants.cc",
110+
],
111+
"cflags!": [ "-fno-exceptions" ],
112+
"cflags_cc!": [ "-fno-exceptions" ],
110113
"conditions": [
111-
# If we could not locate the lib dir, then we will have to search
112-
# from the global search paths during linking and at runtime
113-
[ "lldb_lib_dir != ''", {
114-
"ldflags": [
115-
"-L<(lldb_lib_dir)",
116-
"-Wl,-rpath,<(lldb_lib_dir)"
114+
[ "OS=='linux' or OS=='freebsd'", {
115+
"conditions": [
116+
# If we could not locate the lib dir, then we will have to search
117+
# from the global search paths during linking and at runtime
118+
[ "lldb_lib_dir != ''", {
119+
"ldflags": [
120+
"-L<(lldb_lib_dir)",
121+
"-Wl,-rpath,<(lldb_lib_dir)"
122+
]
123+
}],
124+
# If we cannot find a non-versioned library liblldb(-x.y).so,
125+
# then we will have to link to the versioned library
126+
# liblldb(-x.y).so.z loaded by the detected lldb executable
127+
[ "lldb_lib_so != ''", {
128+
"libraries": ["<(lldb_lib_so)"]
129+
}, {
130+
"libraries": ["-l<(lldb_lib)"]
131+
}]
117132
]
118-
}],
119-
# If we cannot find a non-versioned library liblldb(-x.y).so,
120-
# then we will have to link to the versioned library
121-
# liblldb(-x.y).so.z loaded by the detected lldb executable
122-
[ "lldb_lib_so != ''", {
123-
"libraries": ["<(lldb_lib_so)"]
124-
}, {
125-
"libraries": ["-l<(lldb_lib)"]
126133
}]
127134
]
128135
}]
129-
]
130-
}]
136+
}]
137+
]
131138
}

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
"preinstall": "node scripts/configure.js",
1414
"install": "node scripts/install.js",
1515
"postinstall": "node scripts/cleanup.js",
16-
"test": "tape test/*-test.js"
16+
"test-plugin": "tape test/plugin/*-test.js",
17+
"test-addon": "tape test/addon/*-test.js",
18+
"test-all": "npm run test-addon && npm run test-plugin",
19+
"test": "npm run test-plugin"
1720
},
1821
"repository": {
1922
"type": "git",

scripts/configure.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,27 @@ function main() {
99
const buildDir = process.cwd();
1010
console.log('Build dir is: ' + buildDir);
1111
const osName = os.type();
12-
const result = configureInstallation(osName, buildDir);
13-
writeConfig(result.config);
14-
writeLlnodeScript(buildDir, result.executable, osName);
12+
const { config, executable } = configureInstallation(osName, buildDir);
13+
configureBuildOptions(config);
14+
writeConfig(config);
15+
writeLlnodeScript(buildDir, executable, osName);
1516
// Exit with success.
1617
process.exit(0);
1718
}
1819

1920
main();
2021

22+
// Do not build addon by default until it's less experimental
23+
function configureBuildOptions(config) {
24+
const build_addon = (process.env.npm_config_llnode_build_addon ||
25+
process.env.LLNODE_BUILD_ADDON);
26+
if (build_addon) {
27+
config.variables.build_addon = build_addon;
28+
} else {
29+
config.variables.build_addon = 'false';
30+
}
31+
}
32+
2133
/**
2234
* Get and configure the lldb installation. The returned prefix
2335
* should be linked to ./lldb

0 commit comments

Comments
 (0)