From e6019a4cc079405d5d7b3a90483579de23677297 Mon Sep 17 00:00:00 2001 From: Xuguang Mei Date: Fri, 18 Feb 2022 03:23:20 +0800 Subject: [PATCH] debugger: add debugger alias for exec(expr) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/nodejs/node/issues/41794 PR-URL: https://github.com/nodejs/node/pull/41907 Reviewed-By: Jan Krems Reviewed-By: Michaƫl Zasso --- doc/api/debugger.md | 3 ++- lib/internal/debugger/inspect_repl.js | 6 ++++-- test/sequential/test-debugger-exec.js | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/doc/api/debugger.md b/doc/api/debugger.md index 2bfb08771dffe4..8c91a10ddd8b36 100644 --- a/doc/api/debugger.md +++ b/doc/api/debugger.md @@ -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 diff --git a/lib/internal/debugger/inspect_repl.js b/lib/internal/debugger/inspect_repl.js index 732b6a0f23265a..a32099a1dbf88e 100644 --- a/lib/internal/debugger/inspect_repl.js +++ b/lib/internal/debugger/inspect_repl.js @@ -68,6 +68,7 @@ const SHORTCUTS = { setBreakpoint: 'sb', clearBreakpoint: 'cb', run: 'r', + exec: 'p' }; const HELP = StringPrototypeTrim(` @@ -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 @@ -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 { diff --git a/test/sequential/test-debugger-exec.js b/test/sequential/test-debugger-exec.js index 68a9b37d09d6aa..4057dd03785e7c 100644 --- a/test/sequential/test-debugger-exec.js +++ b/test/sequential/test-debugger-exec.js @@ -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( @@ -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(() => {