From 481329ee7c4ca7f5fdb57ad6f687f229baec461e Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 30 Dec 2010 10:18:25 -0800 Subject: [PATCH] debugger: clean up --- lib/_debugger.js | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/lib/_debugger.js b/lib/_debugger.js index a364910597..c84d2b823e 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -75,22 +75,24 @@ function tryConnect(cb) { } -function trySpawn(cb) { +function killChild() { + if (c) { + c.destroy(); + } + if (child) { child.kill(); child = null; } +} - if (c) { - c.destroy(); - c = null; - } + +function trySpawn(cb) { + killChild(); child = spawn(process.execPath, args, { customFds: [0, 1, 2] }); - console.log("trySpawn"); setTimeout(function () { - console.log("after timeout"); tryConnect(cb); }, 1000); } @@ -445,21 +447,18 @@ function startInterface() { function tryQuit() { if (quitTried) return; quitTried = true; + killChild(); term.close(); - console.log("\ndebug done\n"); - if (c.writable) { - c.reqContinue(function (res) { - process.exit(0); - }); - } else { - process.exit(0); - } + process.exit(0); } term.on('SIGINT', tryQuit); term.on('close', tryQuit); term.on('line', function(cmd) { + // trim whitespace + cmd = cmd.replace(/^\s*/, '').replace(/\s*$/, ''); + if (cmd == 'quit' || cmd == 'q' || cmd == 'exit') { tryQuit(); @@ -471,17 +470,13 @@ function startInterface() { } else { console.log("restarting..."); trySpawn(function () { - c.reqContinue(function (res) { - // Wait for break point. (disable raw mode?) - }); + c.reqContinue(); }); } }); } else { trySpawn(function () { - c.reqContinue(function (res) { - // Wait for break point. (disable raw mode?) - }); + c.reqContinue(); }); }