Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3119 from trufflesuite/step-intover
Browse files Browse the repository at this point in the history
Bug fixes: Fix step into; fix help display; make i & u repeatable
  • Loading branch information
haltman-at authored Jun 23, 2020
2 parents 142b632 + a68f34c commit a15b7ce
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 30 deletions.
4 changes: 1 addition & 3 deletions packages/core/lib/debug/interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,12 +597,10 @@ class DebugInterpreter {
//nothing to print
break;
default:
this.printer.printHelp();
this.printer.printHelp(this.lastCommand);
}

if (
cmd !== "i" &&
cmd !== "u" &&
cmd !== "b" &&
cmd !== "B" &&
cmd !== "v" &&
Expand Down
4 changes: 2 additions & 2 deletions packages/core/lib/debug/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ class DebugPrinter {
}
}

printHelp() {
printHelp(lastCommand) {
this.config.logger.log("");
this.config.logger.log(DebugUtils.formatHelp());
this.config.logger.log(DebugUtils.formatHelp(lastCommand));
}

printFile() {
Expand Down
32 changes: 26 additions & 6 deletions packages/debug-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ const commandReference = {
"s": "print stacktrace"
};

const shortCommandReference = {
"o": "step over",
"i": "step into",
"u": "step out",
"n": "step next",
";": "step instruction",
"p": "print state",
"l": "print context",
"h": "print help",
"v": "print variables",
":": "evaluate",
"+": "add watch",
"-": "remove watch",
"?": "list watches & breakpoints",
"b": "add breakpoint",
"B": "remove breakpoint",
"c": "continue",
"q": "quit",
"r": "reset",
"t": "load",
"T": "unload",
"s": "stacktrace"
};

const truffleColors = {
mint: chalk.hex("#3FE0C5"),
orange: chalk.hex("#E4A663"),
Expand Down Expand Up @@ -179,16 +203,12 @@ var DebugUtils = {
return lines.join(OS.EOL);
},

formatHelp: function(lastCommand) {
if (!lastCommand) {
lastCommand = "n";
}

formatHelp: function(lastCommand = "n") {
var prefix = [
"Commands:",
truffleColors.mint("(enter)") +
" last command entered (" +
commandReference[lastCommand] +
shortCommandReference[lastCommand] +
")"
];

Expand Down
31 changes: 12 additions & 19 deletions packages/debugger/lib/controller/sagas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,42 +109,35 @@ function* stepNext() {
* step.
*/
function* stepInto() {
if (yield select(controller.current.willJump)) {
yield* stepNext();
return;
}

if (yield select(controller.current.location.isMultiline)) {
yield* stepOver();
return;
}

const startingDepth = yield select(controller.current.functionDepth);
const startingLocation = yield select(controller.current.location);
var currentDepth;
var currentLocation;
var finished;
debug("startingDepth: %d", startingDepth);
debug("starting source range: %O", (startingLocation || {}).sourceRange);
let currentDepth;
let currentLocation;
let finished;

do {
yield* stepNext();

currentDepth = yield select(controller.current.functionDepth);
currentLocation = yield select(controller.current.location);
finished = yield select(controller.current.trace.finished);
debug("currentDepth: %d", currentDepth);
debug("current source range: %O", (currentLocation || {}).sourceRange);
debug("finished: %o", finished);
} while (
//we aren't finished,
!finished &&
// the function stack has not increased,
currentDepth <= startingDepth &&
// we haven't changed files,
currentLocation.source.id === startingLocation.source.id &&
currentLocation.source.compilationId ===
startingLocation.source.compilationId &&
// the current source range begins on or after the starting range,
currentLocation.sourceRange.start >= startingLocation.sourceRange.start &&
// and the current range ends on or before the starting range ends
currentLocation.sourceRange.start + currentLocation.sourceRange.length <=
startingLocation.sourceRange.start + startingLocation.sourceRange.length
currentLocation.source.id === startingLocation.source.id &&
//and we haven't changed lines
currentLocation.sourceRange.lines.start.line ===
startingLocation.sourceRange.lines.start.line
);
}

Expand Down

0 comments on commit a15b7ce

Please sign in to comment.