diff --git a/lib/_debugger.js b/lib/_debugger.js index 12f67a7518..c401066efa 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -16,19 +16,9 @@ exports.start = function () { var child; var c; var term; +var args = process.argv.slice(2); +args.unshift('--debug-brk'); -function trySpawn(cb) { - var args = process.argv.slice(2); - args.unshift('--debug-brk'); - - console.log(args); - - child = spawn(process.execPath, args, { customFds: [0, 1, 2] }); - - setTimeout(function () { - tryConnect(cb); - }, 100); -} function tryConnect(cb) { c = new Client(); @@ -84,6 +74,27 @@ function tryConnect(cb) { }); } + +function trySpawn(cb) { + if (child) { + child.kill(); + child = null; + } + + if (c) { + c.destroy(); + c = null; + } + + child = spawn(process.execPath, args, { customFds: [0, 1, 2] }); + + console.log("trySpawn"); + setTimeout(function () { + console.log("after timeout"); + tryConnect(cb); + }, 1000); +} + // // Parser/Serializer for V8 debugger protocol // http://code.google.com/p/v8/wiki/DebuggerProtocol @@ -305,7 +316,7 @@ Client.prototype.step = function(action, count, cb) { -var helpMessage = "Commands: print, step, next, continue, scripts, backtrace, version, quit"; +var helpMessage = "Commands: run, print, step, next, continue, scripts, backtrace, version, quit"; function SourceUnderline(source_text, position) { if (!source_text) { @@ -348,6 +359,23 @@ function SourceInfo(body) { } +var restartQuestionPrompt = "The program being debugged has " + + "been started already.\n" + + "Start it from the beginning? (y or n): "; + +function restartQuestion (cb) { + term.question(restartQuestionPrompt, function (answer) { + if (/^y(es)?$/i.test(answer)) { + cb(true); + } else if (/^n(o)?$/i.test(answer)) { + cb(false); + } else { + console.log("Please answer y or n."); + restartQuestion(cb); + } + }); +} + function startInterface() { @@ -387,11 +415,26 @@ function startInterface() { tryQuit(); } else if (/^r(un)?/.test(cmd)) { - trySpawn(function () { - c.reqContinue(function (res) { - // Wait for break point. (disable raw mode?) + if (child) { + restartQuestion(function (yes) { + if (!yes) { + term.prompt(); + } else { + console.log("restarting..."); + trySpawn(function () { + c.reqContinue(function (res) { + // Wait for break point. (disable raw mode?) + }); + }); + } }); - }); + } else { + trySpawn(function () { + c.reqContinue(function (res) { + // Wait for break point. (disable raw mode?) + }); + }); + } } else if (/^help/.test(cmd)) { console.log(helpMessage);