From 445bcce079df20caa7292d721c86ba9065e6b874 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 13 Jul 2026 19:00:51 +0200 Subject: [PATCH] inspector: add --cond to node inspect probe mode On a hot path, the probe can record every hit and require filtering afterwards. This patch adds a per-probe `--cond ` option that allows limiting the hit to only when the expression is truthy at the probe location. V8 evaluates it as the breakpoint's native condition, so the target is not paused when it does not hold, and a condition that throws is treated as false. Since in CDP, a location can only carry one breakpoint per URL pattern, probes sharing a location must share one condition (or none). Conflicting conditions are rejected. Example: ```js // app.js let total = 0; for (let i = 0; i < 10; i++) { total += i; // line 4 } ``` ``` $ out/Release/node inspect --probe app.js:4 --expr 'total' \ --cond 'i % 3 === 0' app.js ``` ``` Hit 1 at file:///path/to/app.js:3:3 total = 0 Hit 2 at file:///path/to/app.js:3:3 total = 3 Hit 3 at file:///path/to/app.js:3:3 total = 15 Hit 4 at file:///path/to/app.js:3:3 total = 36 Completed ``` Signed-off-by: Joyee Cheung PR-URL: https://github.com/nodejs/node/pull/64328 Refs: https://github.com/nodejs/node/issues/63646 Reviewed-By: James M Snell --- doc/api/debugger.md | 60 +++++++++++++++-- lib/internal/debugger/inspect.js | 1 + lib/internal/debugger/inspect_helpers.js | 10 ++- lib/internal/debugger/inspect_probe.js | 65 ++++++++++++++++--- .../test-debugger-probe-cond-invalid.js | 40 ++++++++++++ .../test-debugger-probe-cond-max-hit.js | 47 ++++++++++++++ .../test-debugger-probe-cond-shared.js | 61 +++++++++++++++++ .../test-debugger-probe-cond-throws.js | 37 +++++++++++ test/parallel/test-debugger-probe-cond.js | 44 +++++++++++++ 9 files changed, 348 insertions(+), 17 deletions(-) create mode 100644 test/parallel/test-debugger-probe-cond-invalid.js create mode 100644 test/parallel/test-debugger-probe-cond-max-hit.js create mode 100644 test/parallel/test-debugger-probe-cond-shared.js create mode 100644 test/parallel/test-debugger-probe-cond-throws.js create mode 100644 test/parallel/test-debugger-probe-cond.js diff --git a/doc/api/debugger.md b/doc/api/debugger.md index 8af0dab6d5e..bff91f3def0 100644 --- a/doc/api/debugger.md +++ b/doc/api/debugger.md @@ -236,6 +236,10 @@ debug> added: - v24.16.0 changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/64328 + description: Add per-probe `--cond ` option to only record a hit when the + condition is truthy at the probe location. - version: v24.19.0 pr-url: https://github.com/nodejs/node/pull/63704 description: Add per-probe `--max-hit ` option to limit evaluated hits and finish @@ -268,8 +272,8 @@ printf-style debugging without having to modify the application code and clean up afterwards. It also supports structured JSON output for tool use. ```console -$ node inspect --probe :[:] --expr [--max-hit ] - [--probe :[:] --expr [--max-hit ] ...] +$ node inspect --probe :[:] --expr [--cond ] [--max-hit ] + [--probe :[:] --expr [--cond ] [--max-hit ] ...] [--json] [--preview] [--timeout=] [--port=] [--] [ ...]