From 6cdaa6323059efe69e6ea55bd87b820a80c97948 Mon Sep 17 00:00:00 2001 From: nightwing Date: Thu, 1 Feb 2018 19:58:16 +0400 Subject: [PATCH] fix php debugger --- .../lib/DbgpSession.js | 3 -- plugins/c9.ide.run.debug.xdebug/netproxy.js | 35 ++++++++++++------- plugins/c9.ide.run.debug.xdebug/xdebug.js | 16 ++++++--- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/plugins/c9.ide.run.debug.xdebug/lib/DbgpSession.js b/plugins/c9.ide.run.debug.xdebug/lib/DbgpSession.js index 441c1fee..68c6f3a7 100644 --- a/plugins/c9.ide.run.debug.xdebug/lib/DbgpSession.js +++ b/plugins/c9.ide.run.debug.xdebug/lib/DbgpSession.js @@ -112,9 +112,6 @@ DbgpSession.prototype.end = function() { }; DbgpSession.prototype._handleInit = function(init) { - if (this.initialized) - throw new Error("Cannot initialize debugger session more than once"); - this.protocolVersion = init["@protocol_version"]; this.appId = init["@appid"]; diff --git a/plugins/c9.ide.run.debug.xdebug/netproxy.js b/plugins/c9.ide.run.debug.xdebug/netproxy.js index 143d7cc2..d47a970e 100644 --- a/plugins/c9.ide.run.debug.xdebug/netproxy.js +++ b/plugins/c9.ide.run.debug.xdebug/netproxy.js @@ -1,8 +1,11 @@ var net = require("net"); +var fs = require("fs"); var debug = function() {}; -// var debug = require("debug")("netproxy"); - +// var debug = console.error.bind(console); +var socketPath = process.env.HOME + "/.c9/xdebug.sock"; +if (process.platform == "win32") + socketPath = "\\\\.\\pipe\\" + socketPath.replace(/\//g, "\\"); var host = "{HOST}" || "127.0.0.1"; var port = parseInt("{PORT}", 10) || 9000; @@ -22,7 +25,7 @@ function send() { } -// --- +/*** --- ***/ var browserServer = net.createServer(function(client) { debug("browserClient::connect"); @@ -36,8 +39,6 @@ var browserServer = net.createServer(function(client) { browserClient.on("end", function() { debug("browserClient::end"); process.exit(0); - // if (debugClient) - // debugClient.end(); browserClient = null; }); @@ -58,8 +59,17 @@ var browserServer = net.createServer(function(client) { } }); -browserServer.listen(port + 1, host, function() { - debug("netproxy listening for browser on port " + (port + 1)); + +if (process.platform !== "win32") { + try { + fs.unlinkSync(socketPath); + } catch (e) { + if (e.code != "ENOENT") + console.log(e); + } +} +browserServer.listen(socketPath, function() { + debug("netproxy listening for " + socketPath); start(); }); @@ -67,8 +77,12 @@ browserServer.on("error", function(err) { console.log(err); process.exit(0); }); +browserServer.on("close", function(err) { + console.log(err); + process.exit(0); +}); -// --- +/*** --- ***/ var debugServer = net.createServer(function(client) { debug("debugClient::connect"); @@ -84,9 +98,6 @@ var debugServer = net.createServer(function(client) { debugClient.on("end", function() { debug("debugClient::end"); process.exit(0); - // debugClient = null; - // if (browserClient) - // browserClient.end(); }); debugClient.on("data", function(data) { @@ -116,7 +127,7 @@ debugServer.on("error", function(err) { process.exit(0); }); -// -- +/*** --- ***/ var I = 0; function start() { diff --git a/plugins/c9.ide.run.debug.xdebug/xdebug.js b/plugins/c9.ide.run.debug.xdebug/xdebug.js index 5dc686fb..b5ec6ec2 100644 --- a/plugins/c9.ide.run.debug.xdebug/xdebug.js +++ b/plugins/c9.ide.run.debug.xdebug/xdebug.js @@ -452,11 +452,17 @@ define(function(require, exports, module) { } function getProxySource(process) { - return PROXY - .replace(/\/\/.*/g, "") - .replace(/[\n\r]/g, "") - .replace(/\{HOST\}/, process.runner.debughost || "") - .replace(/\{PORT\}/, process.runner.debugport); + var socketPath = c9.home + "/.c9/xdebug.sock"; + if (c9.platform == "win32") + socketPath = "\\\\.\\pipe\\" + socketPath.replace(/\//g, "\\"); + return { + source: PROXY + .replace(/^\s*\/\/.*/gm, "") + .replace(/[\n\r]/g, "") + .replace(/\{HOST\}/, process.runner.debughost || "") + .replace(/\{PORT\}/, process.runner.debugport), + port: socketPath + }; } function setBreakpoints(breakpoints, callback) {