debugger: Disable/Enable raw mode for child
authorRyan Dahl <ry@tinyclouds.org>
Thu, 30 Dec 2010 23:46:47 +0000 (15:46 -0800)
committerRyan Dahl <ry@tinyclouds.org>
Thu, 30 Dec 2010 23:46:47 +0000 (15:46 -0800)
benchmark/http_simple.js
lib/_debugger.js
lib/readline.js

index 8d66190..6d6b0d3 100644 (file)
@@ -43,6 +43,7 @@ var server = http.createServer(function (req, res) {
 
   if (command == "bytes") {
     var n = parseInt(arg, 10)
+    debugger;
     if (n <= 0)
       throw "bytes called with n <= 0"
     if (stored[n] === undefined) {
index a9818be..4f95293 100644 (file)
@@ -310,6 +310,7 @@ function SourceUnderline(sourceText, position) {
   return sourceText + '\n' + underline;
 }
 
+
 function SourceInfo(body) {
   var result = '';
 
@@ -340,8 +341,8 @@ function Interface() {
     self.killChild();
   });
 
-  var stdin = process.openStdin();
-  stdin.addListener('data', function(chunk) {
+  this.stdin = process.openStdin();
+  this.stdin.addListener('data', function(chunk) {
     term.write(chunk);
   });
 
@@ -350,12 +351,14 @@ function Interface() {
 
   this.quitTried = false;
 
+  process.on('SIGINT', function () {
+    self.handleSIGINT();
+  });
 
   term.on('SIGINT', function () {
-    self.tryQuit();
+    self.handleSIGINT();
   });
 
-
   term.on('close', function () {
     self.tryQuit();
   });
@@ -374,6 +377,15 @@ function Interface() {
 }
 
 
+Interface.prototype.handleSIGINT = function() {
+  if (this.paused) {
+    this.child.kill('SIGINT');
+  } else {
+    this.tryQuit();
+  }
+};
+
+
 Interface.prototype.tryQuit = function() {
   if (this.quitTried) return;
   this.quitTried = true;
@@ -383,6 +395,23 @@ Interface.prototype.tryQuit = function() {
 };
 
 
+Interface.prototype.pause = function() {
+  this.paused = true;
+  this.stdin.pause();
+  this.term.pause();
+};
+
+
+Interface.prototype.resume = function() {
+  if (!this.paused) return false
+  this.paused = false;
+  this.stdin.resume();
+  this.term.resume();
+  this.term.prompt();
+  return true;
+};
+
+
 Interface.prototype.handleBreak = function(r) {
   var result = '';
   if (r.breakpoints) {
@@ -413,7 +442,7 @@ Interface.prototype.handleBreak = function(r) {
 
   console.log(result);
 
-  this.term.prompt();
+  if(!this.resume()) this.term.prompt();
 };
 
 
@@ -504,7 +533,11 @@ Interface.prototype.handleCommand = function(cmd) {
       self.printNotConnected();
       return;
     }
-    client.reqContinue();
+
+    self.pause();
+    client.reqContinue(function () {
+      self.resume();
+    });
 
   } else if (/^k(ill)?/.test(cmd)) {
     if (!client) {
@@ -611,15 +644,21 @@ Interface.prototype.killChild = function() {
     this.client.destroy();
     this.client = null;
   }
+
+  this.resume();
 };
 
 
 Interface.prototype.trySpawn = function(cb) {
+  var self = this;
+
   this.killChild();
 
   this.child = spawn(process.execPath, args, { customFds: [0, 1, 2] });
 
-  var self = this;
+
+  this.pause();
+
   setTimeout(function () {
     process.stdout.write("connecting...");
     var client = self.client = new Client();
@@ -630,15 +669,16 @@ Interface.prototype.trySpawn = function(cb) {
 
       // since we did debug-brk, we're hitting a break point immediately
       // continue before anything else.
-      client.reqContinue();
-
-      if (cb) cb();
+      client.reqContinue(function () {
+        if (cb) cb();
+      });
     });
 
     client.on('close', function () {
       console.log("\nprogram terminated");
       self.client = null;
       self.killChild();
+      self.term.prompt();
     });
 
     client.on('unhandledResponse', function (res) {
index 4a0565a..474e227 100644 (file)
@@ -154,6 +154,20 @@ Interface.prototype.close = function(d) {
 };
 
 
+Interface.prototype.pause = function() {
+  if (this.enabled) {
+    tty.setRawMode(false);
+  }
+};
+
+
+Interface.prototype.resume = function() {
+  if (this.enabled) {
+    tty.setRawMode(true);
+  }
+};
+
+
 Interface.prototype.write = function(d) {
   if (this._closed) return;
   return this.enabled ? this._ttyWrite(d) : this._normalWrite(d);