mirror of https://github.com/nodejs/node.git
debugger: add 'kill' command
parent
a3c4e17c2a
commit
866201bd74
|
@ -278,7 +278,8 @@ Client.prototype.step = function(action, count, cb) {
|
|||
|
||||
|
||||
|
||||
var helpMessage = "Commands: run, print, step, next, continue, scripts, backtrace, version, quit";
|
||||
var helpMessage = "Commands: run, kill, print, step, next, " +
|
||||
"continue, scripts, backtrace, version, quit";
|
||||
|
||||
function SourceUnderline(sourceText, position) {
|
||||
if (!sourceText) return;
|
||||
|
@ -420,10 +421,15 @@ Interface.prototype.handleCommand = function(cmd) {
|
|||
if (self.child) {
|
||||
self.restartQuestion(function (yes) {
|
||||
if (!yes) {
|
||||
self._lastCommand = null;
|
||||
term.prompt();
|
||||
} else {
|
||||
console.log("restarting...");
|
||||
self.trySpawn();
|
||||
self.killChild();
|
||||
// XXX need to wait a little bit for the restart to work?
|
||||
setTimeout(function () {
|
||||
self.trySpawn();
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -488,9 +494,22 @@ Interface.prototype.handleCommand = function(cmd) {
|
|||
self.printNotConnected();
|
||||
return;
|
||||
}
|
||||
client.reqContinue(function (res) {
|
||||
// Wait for break point. (disable raw mode?)
|
||||
});
|
||||
client.reqContinue();
|
||||
|
||||
} else if (/^k(ill)?/.test(cmd)) {
|
||||
// kill
|
||||
if (self.child) {
|
||||
self.killQuestion(function (yes) {
|
||||
if (yes) {
|
||||
self.killChild();
|
||||
} else {
|
||||
self._lastCommand = null;
|
||||
}
|
||||
self.term.prompt();
|
||||
});
|
||||
} else {
|
||||
self.term.prompt();
|
||||
}
|
||||
|
||||
} else if (/^next/.test(cmd) || /^n/.test(cmd)) {
|
||||
if (!client) {
|
||||
|
@ -541,13 +560,10 @@ Interface.prototype.handleCommand = function(cmd) {
|
|||
};
|
||||
|
||||
|
||||
var restartQuestionPrompt = "The program being debugged has " +
|
||||
"been started already.\n" +
|
||||
"Start it from the beginning? (y or n): ";
|
||||
|
||||
Interface.prototype.restartQuestion = function(cb) {
|
||||
Interface.prototype.yesNoQuestion = function(prompt, cb) {
|
||||
var self = this;
|
||||
this.term.question(restartQuestionPrompt, function (answer) {
|
||||
this.term.question(prompt, function (answer) {
|
||||
if (/^y(es)?$/i.test(answer)) {
|
||||
cb(true);
|
||||
} else if (/^n(o)?$/i.test(answer)) {
|
||||
|
@ -560,16 +576,27 @@ Interface.prototype.restartQuestion = function(cb) {
|
|||
};
|
||||
|
||||
|
||||
Interface.prototype.killChild = function() {
|
||||
if (this.client) {
|
||||
this.client.destroy();
|
||||
this.client = null;
|
||||
}
|
||||
Interface.prototype.restartQuestion = function(cb) {
|
||||
this.yesNoQuestion("The program being debugged has been started already.\n" +
|
||||
"Start it from the beginning? (y or n) ", cb);
|
||||
};
|
||||
|
||||
|
||||
Interface.prototype.killQuestion = function(cb) {
|
||||
this.yesNoQuestion("Kill the program being debugged? (y or n) ", cb);
|
||||
};
|
||||
|
||||
|
||||
Interface.prototype.killChild = function() {
|
||||
if (this.child) {
|
||||
this.child.kill();
|
||||
this.child = null;
|
||||
}
|
||||
|
||||
if (this.client) {
|
||||
this.client.destroy();
|
||||
this.client = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -598,7 +625,6 @@ Interface.prototype.trySpawn = function(cb) {
|
|||
console.log("\nprogram terminated");
|
||||
self.client = null;
|
||||
self.killChild();
|
||||
self.term.prompt();
|
||||
});
|
||||
|
||||
client.on('unhandledResponse', function (res) {
|
||||
|
|
Loading…
Reference in New Issue