Skip to content

Commit

Permalink
repl: 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 7953c79
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/internal/debugger/inspect_repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const SHORTCUTS = {
step: 's',
out: 'o',
backtrace: 'bt',
setContextLineNumber: 'scln',
setBreakpoint: 'sb',
clearBreakpoint: 'cb',
run: 'r',
Expand All @@ -81,7 +82,8 @@ 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, scln
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 +383,7 @@ function createRepl(inspector) {
let currentBacktrace;
let selectedFrame;
let exitDebugRepl;
let contextLineNumber = 2;

function resetOnStart() {
knownScripts = {};
Expand Down Expand Up @@ -685,6 +688,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 +913,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 +1175,7 @@ function createRepl(inspector) {
},

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

0 comments on commit 7953c79

Please sign in to comment.