Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debugger: add debugger alias for exec(expr) #41907

Merged
merged 3 commits into from Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/api/debugger.md
Expand Up @@ -197,7 +197,8 @@ debug>
* `watchers`: List all watchers and their values (automatically listed on each
breakpoint)
* `repl`: Open debugger's repl for evaluation in debugging script's context
* `exec expr`: Execute an expression in debugging script's context
* `exec expr`, `p expr`: Execute an expression in debugging script's context and
print its value

### Execution control

Expand Down
6 changes: 4 additions & 2 deletions lib/internal/debugger/inspect_repl.js
Expand Up @@ -68,6 +68,7 @@ const SHORTCUTS = {
setBreakpoint: 'sb',
clearBreakpoint: 'cb',
run: 'r',
exec: 'p'
};

const HELP = StringPrototypeTrim(`
Expand All @@ -93,7 +94,8 @@ watch(expr) Start watching the given expression
unwatch(expr) Stop watching an expression
watchers Print all watched expressions and their current values

exec(expr) Evaluate the expression and print the value
exec(expr), p(expr), exec expr, p expr
Evaluate the expression and print the value
repl Enter a debug repl that works like exec

scripts List application scripts that are currently loaded
Expand Down Expand Up @@ -530,7 +532,7 @@ function createRepl(inspector) {
function prepareControlCode(input) {
if (input === '\n') return lastCommand;
// Add parentheses: exec process.title => exec("process.title");
const match = RegExpPrototypeSymbolMatch(/^\s*exec\s+([^\n]*)/, input);
const match = RegExpPrototypeSymbolMatch(/^\s*(?:exec|p)\s+([^\n]*)/, input);
if (match) {
lastCommand = `exec(${JSONStringify(match[1])})`;
} else {
Expand Down
16 changes: 16 additions & 0 deletions test/sequential/test-debugger-exec.js
Expand Up @@ -27,6 +27,14 @@ const assert = require('assert');
'works w/o paren'
);
})
.then(() => cli.command('p [typeof heartbeat, typeof process.exit]'))
.then(() => {
assert.match(
cli.output,
/\[ 'function', 'function' \]/,
'works w/o paren, short'
);
})
.then(() => cli.command('repl'))
.then(() => {
assert.match(
Expand Down Expand Up @@ -54,6 +62,14 @@ const assert = require('assert');
'works w/ paren'
);
})
.then(() => cli.command('p("[typeof heartbeat, typeof process.exit]")'))
.then(() => {
assert.match(
cli.output,
/\[ 'function', 'function' \]/,
'works w/ paren, short'
);
})
.then(() => cli.command('cont'))
.then(() => cli.command('exec [typeof heartbeat, typeof process.exit]'))
.then(() => {
Expand Down