diff --git a/lib/_debugger.js b/lib/_debugger.js index c84d2b823e4..f73d13e0f0a 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -415,6 +415,7 @@ function restartQuestion (cb) { }); } + function printScripts () { var text = ''; for (var id in c.scripts) { @@ -428,6 +429,12 @@ function printScripts () { } +function printNotConnected () { + console.log("Program not running. Try 'run'."); + term.prompt(); +} + + function startInterface() { term = readline.createInterface(process.stdout); @@ -485,18 +492,30 @@ function startInterface() { term.prompt(); } else if ('version' == cmd) { + if (!c) { + printNotConnected(); + return; + } c.reqVersion(function (v) { console.log(v); term.prompt(); }); } else if (/info +breakpoints/.test(cmd)) { + if (!c) { + printNotConnected(); + return; + } c.listbreakpoints(function (res) { console.log(res); term.prompt(); }); } else if (/^backtrace/.test(cmd) || /^bt/.test(cmd)) { + if (!c) { + printNotConnected(); + return; + } c.reqBacktrace(function (bt) { if (/full/.test(cmd)) { console.log(bt); @@ -514,25 +533,45 @@ function startInterface() { }); } else if (cmd == 'scripts' || cmd == 'scripts full') { + if (!c) { + printNotConnected(); + return; + } printScripts(); term.prompt(); } else if (/^continue/.test(cmd) || /^c/.test(cmd)) { + if (!c) { + printNotConnected(); + return; + } c.reqContinue(function (res) { // Wait for break point. (disable raw mode?) }); } else if (/^next/.test(cmd) || /^n/.test(cmd)) { + if (!c) { + printNotConnected(); + return; + } c.step('next', 1, function (res) { // Wait for break point. (disable raw mode?) }); } else if (/^step/.test(cmd) || /^s/.test(cmd)) { + if (!c) { + printNotConnected(); + return; + } c.step('in', 1, function (res) { // Wait for break point. (disable raw mode?) }); } else if (/^print/.test(cmd) || /^p/.test(cmd)) { + if (!c) { + printNotConnected(); + return; + } var i = cmd.indexOf(' '); if (i < 0) { console.log("print [expression]");