From 7508f121371cf52659db205eeee6290e7d23a4a8 Mon Sep 17 00:00:00 2001 From: meixg Date: Wed, 9 Feb 2022 17:37:01 +0800 Subject: [PATCH 1/3] debugger: add debugger alias for exec(expr) https://github.com/nodejs/node/issues/41794 --- lib/internal/debugger/inspect_repl.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/internal/debugger/inspect_repl.js b/lib/internal/debugger/inspect_repl.js index 401887cbda5c74..36cde95f742511 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 { From 2386987e01ac4558c0eb3393b5ea6e0f032fa468 Mon Sep 17 00:00:00 2001 From: meixg Date: Thu, 10 Feb 2022 14:11:55 +0800 Subject: [PATCH 2/3] test: debugger alias for exec(expr) https://github.com/nodejs/node/issues/41794 --- test/sequential/test-debugger-exec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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(() => { From aea241d5a86f202946f45f5ecfb4479f32504c98 Mon Sep 17 00:00:00 2001 From: meixg Date: Thu, 10 Feb 2022 14:23:59 +0800 Subject: [PATCH 3/3] doc: debugger alias for exec(expr) https://github.com/nodejs/node/issues/41794 --- doc/api/debugger.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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