debugger: add edit-free runtime expression probes to node inspect#62713
debugger: add edit-free runtime expression probes to node inspect#62713joyeecheung wants to merge 1 commit intonodejs:mainfrom
node inspect#62713Conversation
|
cc @nodejs/inspector @nodejs/diagnostics |
3608c5d to
b0ec4b2
Compare
Add a non-interactive probe mode to `node inspect` for inspecting
runtime values in a run-to-completion application. This allows
users to perform printf-style debugging without having to modify
the application code and clean up afterwards, it also supports
structured output to be consumed by tools.
Probe mode launches the application, sets one or more source
breakpoints, evaluates one expression at each hit, and prints a
single text or JSON report when execution ends.
Interface:
node inspect [--json] [--preview] [--timeout=<ms>] [--port=<port>]
--probe <file>:<line>[:<col>] --expr <expr> ...
[--] <script> [args...]
Example:
```js
// cli.js
let maxRSS = 0;
for (let i = 0; i < 2; i++) {
const { rss } = process.memoryUsage();
maxRSS = Math.max(maxRSS, rss);
}
```
```
$ node inspect --probe cli.js:5 --expr 'rss' cli.js
Hit 1 at cli.js:5
rss = 54935552
Hit 2 at cli.js:5
rss = 55083008
Completed
```
(Prettified JSON to fit in commit message restrictions).
```js
$ node inspect --json --probe cli.js:5 --expr 'rss' cli.js
{"v":1,"probes":[{"expr":"rss","target":["cli.js",5]}],
"results":[
{"probe":0,"event":"hit","hit":1,
"result":{"type":"number","value":55443456,
"description":"55443456"}},
{"probe":0,"event":"hit","hit":2,
"result":{"type":"number","value":55574528,
"description":"55574528"}},
{"event":"completed"}]}
```
Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62713 +/- ##
==========================================
- Coverage 89.81% 89.73% -0.08%
==========================================
Files 699 699
Lines 216379 217210 +831
Branches 41366 41557 +191
==========================================
+ Hits 194340 194922 +582
- Misses 14139 14368 +229
- Partials 7900 7920 +20
🚀 New features to boost your workflow:
|
| '--json', | ||
| '--preview', | ||
| '--timeout=1', | ||
| '--expr', |
There was a problem hiding this comment.
I'm not sure what this tests in relation to the probes. Shouldn't it fail because --expr is passed without any probe location? The test below appears to only test the exec command and not involve the value expression..?
| // Parse from right to left to allow Windows paths with drive letters. | ||
| // Accepts file:line or file:line:column formats. | ||
| function parseProbeLocation(text) { | ||
| const lastColon = StringPrototypeLastIndexOf(text, ':'); |
There was a problem hiding this comment.
It feels like using a single regex for the entire text would be easier to read here. But I don't have super strong opitions.
| } | ||
|
|
||
| function formatProbeTuple(tuple) { | ||
| return ArrayPrototypeJoin(ArrayPrototypeMap(tuple, (part) => `${part}`), ':'); |
There was a problem hiding this comment.
Does the map really do anything here? I assume all elements are primitives that would be converted to strings by join already?
|
|
||
| function formatPendingProbeLocations(probes, pending) { | ||
| const seen = new SafeSet(); | ||
| const names = []; |
There was a problem hiding this comment.
Isn't this redundant with seen? Should we just Array.from(seen) at the end?
| } | ||
| } | ||
|
|
||
| async function runScript(script, scriptArgs, inspectHost, inspectPort, |
There was a problem hiding this comment.
Since this only has one call site, should we just update that call to match the launchChildProcess signature instead of having this wrapper function?
|
This is really cool! Have we considered to use new line delimited JSON instead of a big JSON array as the primary output format? |
Add a non-interactive probe mode to
node inspectfor inspecting runtime values in a run-to-completion application. This allows users to perform printf-style debugging without having to modify the application code and clean up afterwards, it also supports structured output to be consumed by tools.This is proposed to be experimental first, so that we can iterate on the interface. There are a few features that would be nice to have but better left for follow-ups to avoid bloating the diff:
In this patch, probe mode launches the application, sets one or more source breakpoints, evaluates one expression at each hit, and prints a single text or JSON report containing all the evaluated values when execution ends.
Interface:
For example, to inspect a string in an application without modifying the source:
(Prettified JSON to fit in commit message restrictions).