Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-12-30 12:34:54 +0300
committerRyan Dahl <ry@tinyclouds.org>2010-12-30 12:35:20 +0300
commitbb400d5697dd41d50bb7307d8b3478fa8ae1092f (patch)
tree0a1ac491732c0ecca4f0a3dbea245f4830f2ccf5 /lib
parente33d0de129533465276158980e53c0979096b8be (diff)
debugger: Work towards interactive restart
Diffstat (limited to 'lib')
-rw-r--r--lib/_debugger.js77
1 files changed, 60 insertions, 17 deletions
diff --git a/lib/_debugger.js b/lib/_debugger.js
index 12f67a75188..c401066efa5 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);