Skip to content

Commit

Permalink
debugger: add a command to set which lines to check for context
Browse files Browse the repository at this point in the history
  • Loading branch information
Dailyscat committed Feb 24, 2023
1 parent 86362b7 commit 80d330a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/internal/debugger/inspect_repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ out, o Step out, leaving the current function
backtrace, bt Print the current backtrace
list Print the source around the current line where execution
is currently paused
setContextLineNumber Set which lines to check for context
setBreakpoint, sb Set a breakpoint
clearBreakpoint, cb Clear a breakpoint
breakpoints List all known breakpoints
Expand Down Expand Up @@ -381,6 +381,7 @@ function createRepl(inspector) {
let currentBacktrace;
let selectedFrame;
let exitDebugRepl;
let contextLineNumber = 2;

function resetOnStart() {
knownScripts = {};
Expand Down Expand Up @@ -685,6 +686,19 @@ function createRepl(inspector) {
});
}

function setContextLineNumber(delta = 2) {
if (!selectedFrame) {
throw new ERR_DEBUGGER_ERROR('Requires execution to be paused');
}
try {
contextLineNumber = delta;
print(`The contextLine has been changed to ${delta}.`)
} catch (error) {
print("You can't setContextLineNumber source code right now");
throw error;
}
}

function handleBreakpointResolved({ breakpointId, location }) {
const script = knownScripts[location.scriptId];
const scriptUrl = script && script.url;
Expand Down Expand Up @@ -897,7 +911,7 @@ function createRepl(inspector) {

inspector.suspendReplWhile(() =>
PromisePrototypeThen(
SafePromiseAllReturnArrayLike([formatWatchers(true), selectedFrame.list(2)]),
SafePromiseAllReturnArrayLike([formatWatchers(true), selectedFrame.list(contextLineNumber)]),
({ 0: watcherList, 1: context }) => {
const breakContext = watcherList ?
`${watcherList}\n${inspect(context)}` :
Expand Down Expand Up @@ -1159,6 +1173,7 @@ function createRepl(inspector) {
},

list,
setContextLineNumber
});
aliasProperties(context, SHORTCUTS);
}
Expand Down

0 comments on commit 80d330a

Please sign in to comment.