选择探头位置


🌐 Selecting the probe location

当执行到探测位置时,这些表达式会在探测位置的词法作用域中进行求值。避免在由 letconst 声明的变量的声明位置进行探测,因为这会导致 ReferenceError,这是由于在变量的暂时性死区(TDZ)中访问该变量所引起的。

🌐 The expressions are evaluated in the lexical scope of the probe location when execution reaches it. Avoid probing a variable declared by let or const at its declaration site, as this leads to a ReferenceError caused by accessing the variable in its temporal dead zone (TDZ).

// app.js
const x = 42;        // line 2
console.log(x);      // line 3 
$ node inspect --probe app.js:1 --expr 'x' app.js
Hit 1 at app.js:1
  [error] x = ReferenceError: Cannot access 'x' from debugger
  ...
Completed 

相反,在变量已经被初始化的位置进行探测:

🌐 Instead, probe at a location where the variable is already initialized:

$ node inspect --probe app.js:3 --expr 'x' app.js
Hit 1 at app.js:3
  x = 42
Completed 

探针路径会通过基本名称与已加载的脚本 URL 进行匹配,类似于本地调试器通常匹配断点的方式。给定:

🌐 Probe paths are matched against loaded script URLs by basename, similar to how native debuggers typically match breakpoints. Given:

project/
  - src/utils.js
  - lib/utils.js 

--probe utils.js:10 绑定到 两个 文件,并为每个匹配生成一次命中。 为了解析歧义,请指定一个只匹配目标文件的完整路径:

$ node inspect --probe src/utils.js:10 --expr 'x' main.js   # matches only src/utils.js