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();
});
}
+
+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
-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) {
}
+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() {
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);