Commit b421b282 authored by Philip Chimento's avatar Philip Chimento 🚮

Merge branch 'master' into 'master'

Extra help for debugger commands

See merge request !283
parents cebddb1a 64d8ee5a
Pipeline #75590 passed with stages
in 5 minutes and 41 seconds
......@@ -105,7 +105,7 @@ Debugger.Frame.prototype.describeFrame = function() {
else if (this.type == 'global')
return 'toplevel';
else
return this.type + ' code';
return `${this.type} code`;
};
Debugger.Frame.prototype.describePosition = function() {
......@@ -182,6 +182,9 @@ function quitCommand() {
dbg.enabled = false;
quit(0);
}
quitCommand.summary = 'Quit the debugger';
quitCommand.helpText = `USAGE
quit`;
function backtraceCommand() {
if (topFrame === null)
......@@ -189,6 +192,9 @@ function backtraceCommand() {
for (var i = 0, f = topFrame; f; i++, f = f.older)
showFrame(f, i);
}
backtraceCommand.summary = 'Print backtrace of all stack frames';
backtraceCommand.helpText = `USAGE
bt`;
function setCommand(rest) {
var space = rest.indexOf(' ');
......@@ -209,6 +215,14 @@ function setCommand(rest) {
options[name] = value;
}
}
setCommand.summary = 'Sets the value of the given option';
setCommand.helpText = `USAGE
set <option> <value>
PARAMETERS
· option: option name. Allowed options are:
· pretty: set print mode to pretty or brief. Allowed value true or false
· value: option value`;
function splitPrintOptions(s, style) {
const m = /^\/(\w+)/.exec(s);
......@@ -248,15 +262,32 @@ function printCommand(rest) {
var [expr, style] = splitPrintOptions(rest, {pretty: options.pretty});
return doPrint(expr, style);
}
printCommand.summary = 'Prints the given expression';
printCommand.helpText = `USAGE
print[/pretty|p|brief|b] <expr>
PARAMETER
· expr: expression to be printed
· pretty|p: prettify the output
· brief|b: brief output`;
function keysCommand(rest) {
return doPrint(`Object.keys(${rest})`);
}
keysCommand.summary = 'Prints keys of the given object';
keysCommand.helpText = `USAGE
keys <obj>
PARAMETER
· obj: object to get keys of`;
function detachCommand() {
dbg.enabled = false;
return [undefined];
}
detachCommand.summary = 'Detach debugger from the script';
detachCommand.helpText = `USAGE
detach`;
function continueCommand() {
if (focusedFrame === null) {
......@@ -265,6 +296,9 @@ function continueCommand() {
}
return [undefined];
}
continueCommand.summary = 'Continue program execution';
continueCommand.helpText = `USAGE
cont`;
function throwOrReturn(rest, action, defaultCompletion) {
if (focusedFrame !== topFrame) {
......@@ -296,10 +330,22 @@ function throwOrReturn(rest, action, defaultCompletion) {
function throwCommand(rest) {
return throwOrReturn(rest, 'throw', {throw: lastExc});
}
throwCommand.summary = 'Throws the given value';
throwCommand.helpText = `USAGE
throw <expr>
PARAMETER
· expr: expression to throw`;
function returnCommand(rest) {
return throwOrReturn(rest, 'return', {return: undefined});
}
returnCommand.summary = 'Return the given value from the current frame';
returnCommand.helpText = `USAGE
return <expr>
PARAMETER
· expr: expression to return`;
function frameCommand(rest) {
let n, f;
......@@ -330,6 +376,12 @@ function frameCommand(rest) {
print('do what now?');
}
}
frameCommand.summary = 'Jump to specified frame or print current frame (if not specified)';
frameCommand.helpText = `USAGE
frame [frame_num]
PARAMETER
· frame_num: frame to jump to`;
function upCommand() {
if (focusedFrame === null)
......@@ -342,6 +394,9 @@ function upCommand() {
showFrame();
}
}
upCommand.summary = 'Jump to the parent frame';
upCommand.helpText = `USAGE
up`;
function downCommand() {
if (focusedFrame === null)
......@@ -353,6 +408,9 @@ function downCommand() {
showFrame();
}
}
downCommand.summary = 'Jump to the younger frame';
downCommand.helpText = `USAGE
down`;
function printPop(c) {
if (c['return']) {
......@@ -412,7 +470,7 @@ function doStepOrNext(kind) {
}
function stepEntered(newFrame) {
print('entered frame: ' + newFrame.describeFull());
print(`entered frame: ${newFrame.describeFull()}`);
if (!kind.until || newFrame.line == kind.stopLine) {
topFrame = focusedFrame = newFrame;
return repl();
......@@ -471,18 +529,33 @@ function doStepOrNext(kind) {
function stepCommand() {
return doStepOrNext({step: true});
}
stepCommand.summary = 'Step to next command';
stepCommand.helpText = `USAGE
step`;
function nextCommand() {
return doStepOrNext({next: true});
}
nextCommand.summary = 'Jump to next line';
nextCommand.helpText = `USAGE
next`;
function finishCommand() {
return doStepOrNext({finish: true});
}
finishCommand.summary = 'Run until the current frame is finished also prints the returned value';
finishCommand.helpText = `USAGE
finish`;
function untilCommand(line) {
return doStepOrNext({until: true, stopLine: Number(line)});
}
untilCommand.summary = 'Continue until given line';
untilCommand.helpText = `USAGE
until <line_num>
PARAMETER
· line_num: line_num to continue until`;
function findBreakpointOffsets(line, currentScript) {
const offsets = currentScript.getLineOffsets(line);
......@@ -525,7 +598,7 @@ function breakpointCommand(where) {
const possibleOffsets = findBreakpointOffsets(line, focusedFrame.script);
if (possibleOffsets.length === 0) {
print('Unable to break at line ' + where);
print(`Unable to break at line ${where}`);
return;
}
......@@ -538,6 +611,12 @@ function breakpointCommand(where) {
});
});
}
breakpointCommand.summary = 'Set breakpoint at the specified location.';
breakpointCommand.helpText = `USAGE
break <line_num>
PARAMETERS
· line_num: line number to place a breakpoint at.`;
function deleteCommand(breaknum) {
const bp = breakpoints[breaknum];
......@@ -552,6 +631,12 @@ function deleteCommand(breaknum) {
breakpoints[breaknum] = undefined;
print(`${bp} deleted`);
}
deleteCommand.summary = 'Deletes breakpoint';
deleteCommand.helpText = `USAGE
del <breakpoint_num>
PARAMETERS
· breakpoint_num: breakpoint number to be removed.`;
// Build the table of commands.
var commands = {};
......@@ -589,28 +674,74 @@ for (var i = 0; i < commandArray.length; i++) {
currentCmd = commands[cmd.name.replace(/Command$/, '')] = cmd;
}
function helpCommand() {
function _printCommandsList() {
print('Available commands:');
var printcmd = function(group) {
print(' ' + group.join(', '));
var printcmd = function (group) {
var summary = group.find((cmd) => !!cmd.summary);
print(` ${group.map((c) => c.name).join(', ')} -- ${(summary || {}).summary}`);
};
var group = [];
var cmdGroups = _groupCommands();
for (var group of cmdGroups) {
printcmd(group);
}
}
function _groupCommands() {
var groups = [];
for (var cmd of commandArray) {
// Don't print commands for debugging the debugger
if ([commentCommand, evalCommand].includes(cmd) ||
['#', '!'].includes(cmd))
continue;
if (typeof cmd === 'string') {
group.push(cmd);
groups[groups.length - 1]['aliases'].push(cmd);
} else {
groups.push({
summary: cmd.summary,
helpText: cmd.helpText,
aliases: [cmd.name.replace(/Command$/, '')]
});
}
}
return groups;
}
function _printCommand(cmd) {
print(`${cmd.summary}\n\n${cmd.helpText}`);
if (cmd.aliases.length > 1) {
print('\nALIASES');
for (var alias of cmd.aliases) {
print(` · ${alias}`);
}
}
}
function helpCommand(cmd) {
if (!cmd) {
_printCommandsList();
} else {
var cmdGroups = _groupCommands();
var command = cmdGroups.find((c) => c.aliases.includes(cmd));
if (command && command.helpText) {
_printCommand(command);
} else {
// Don't print commands for debugging the debugger
if ([commentCommand, evalCommand].includes(cmd) ||
['comment', 'eval'].includes(group[0]))
continue;
if (group.length)
printcmd(group);
group = [cmd.name.replace(/Command$/, '')];
print(`No help found for ${cmd} command`);
}
}
printcmd(group);
}
helpCommand.summary = 'Show help for the specified command else list all commands';
helpCommand.helpText = `USAGE
help [command]
PARAMETERS
· command: command to show help for`;
// Break cmd into two parts: its first word and everything else. If it begins
// with punctuation, treat that as a separate word. The first word is
......@@ -639,7 +770,7 @@ function runcmd(cmd) {
var first = pieces[0], rest = pieces[1];
if (!commands.hasOwnProperty(first)) {
print("unrecognized command '" + first + "'");
print(`unrecognized command '${first}'`);
return undefined;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment