Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node debug does not repeat last command when hitting enter at prompt #6010

Closed
lrowe opened this issue Apr 2, 2016 · 1 comment
Closed

node debug does not repeat last command when hitting enter at prompt #6010

lrowe opened this issue Apr 2, 2016 · 1 comment

Comments

@lrowe
Copy link

lrowe commented Apr 2, 2016

When stepping through code with a command line debugger, it's really helpful to repeat the last command by hitting enter.

Steps to reproduce:

$ node debug script.js 
< Debugger listening on port 5858
connecting to 127.0.0.1:5858 ... ok
break in script.js:1
> 1 var a = 1;
  2 var b = 2;
  3 console.log(a);
debug> next
break in script.js:2
  1 var a = 1;
> 2 var b = 2;
  3 console.log(a);
  4 console.log(b);
debug> 
debug> 

The _debugger module seems to implement this in commandEval:

// Used for debugger's commands evaluation and execution
Interface.prototype.controlEval = function(code, context, filename, callback) {
  try {
    // Repeat last command if empty line are going to be evaluated
    if (this.repl.rli.history && this.repl.rli.history.length > 0) {
      if (code === '\n') {
        code = this.repl.rli.history[0] + '\n';
      }
    }

https://github.com/nodejs/node/blob/v5.9.1/lib/_debugger.js#L943-L951

Unfortunately it seems that the repl's self.eval is no longer called for empty commands:

    if (!skipCatchall && (cmd || (!cmd && self.bufferedCommand))) {
      var evalCmd = self.bufferedCommand + cmd;
      if (/^\s*\{/.test(evalCmd) && /\}\s*$/.test(evalCmd)) {
        // It's confusing for `{ a : 1 }` to be interpreted as a block
        // statement rather than an object literal.  So, we first try
        // to wrap it in parentheses, so that it will be interpreted as
        // an expression.
        evalCmd = '(' + evalCmd + ')\n';
      } else {
        // otherwise we just append a \n so that it will be either
        // terminated, or continued onto the next expression if it's an
        // unexpected end of input.
        evalCmd = evalCmd + '\n';
      }

      debug('eval %j', evalCmd);
      self.eval(evalCmd, self.context, 'repl', finish);
    } else {
      finish(null);
    }

https://github.com/nodejs/node/blob/v5.9.1/lib/repl.js#L413-L432

  • Version: 5.9.1
  • Platform: Darwin MachineName.local 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64
  • Subsystem: _debugger
lrowe added a commit to lrowe/node that referenced this issue Apr 4, 2016
Tweak the better empty line handling introduced in nodejs#2163 so that empty
lines are still passed to the eval function. This is required for the
debugger to repeat the last command on an empty line.

Fixes: nodejs#6010
@Trott
Copy link
Member

Trott commented May 26, 2016

I believe this was fixed in 1df84f4. It seems to be working in Node.js 6.2.0. Closing. Please re-open if I'm mistaken.

@Trott Trott closed this as completed May 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants