Bug 1119894 - Add start-debugger-server to Firefox. r=past
authorJ. Ryan Stinnett <jryans@gmail.com>
Mon, 12 Jan 2015 10:17:08 -0600
changeset 249119 7536897c179d5ee387e16e38d786ecbea48c22b0
parent 249118 81877ee96549e0f4378b4d5643925825c9de66c8
child 249120 dd9ba31c3cfc8e477c44ca8eb078afe3004bfff9
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs1119894
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1119894 - Add start-debugger-server to Firefox. r=past
browser/devtools/devtools-clhandler.js
--- a/browser/devtools/devtools-clhandler.js
+++ b/browser/devtools/devtools-clhandler.js
@@ -18,16 +18,28 @@ devtoolsCommandlineHandler.prototype = {
     let consoleFlag = cmdLine.handleFlag("jsconsole", false);
     let debuggerFlag = cmdLine.handleFlag("jsdebugger", false);
     if (consoleFlag) {
       this.handleConsoleFlag(cmdLine);
     }
     if (debuggerFlag) {
       this.handleDebuggerFlag(cmdLine);
     }
+    let debuggerServerFlag;
+    try {
+      debuggerServerFlag =
+        cmdLine.handleFlagWithParam("start-debugger-server", false);
+    } catch(e) {
+      // We get an error if the option is given but not followed by a value.
+      // By catching and trying again, the value is effectively optional.
+      debuggerServerFlag = cmdLine.handleFlag("start-debugger-server", false);
+    }
+    if (debuggerServerFlag) {
+      this.handleDebuggerServerFlag(cmdLine, debuggerServerFlag);
+    }
   },
 
   handleConsoleFlag: function(cmdLine) {
     let window = Services.wm.getMostRecentWindow("devtools:webconsole");
     if (!window) {
       let devtools = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools;
       // Load the browser devtools main module as the loader's main module.
       Cu.import("resource:///modules/devtools/gDevTools.jsm");
@@ -38,40 +50,88 @@ devtoolsCommandlineHandler.prototype = {
       window.focus(); // the Browser Console was already open
     }
 
     if (cmdLine.state == Ci.nsICommandLine.STATE_REMOTE_AUTO) {
       cmdLine.preventDefault = true;
     }
   },
 
-  handleDebuggerFlag: function(cmdLine) {
+  _isRemoteDebuggingEnabled() {
     let remoteDebuggingEnabled = false;
     try {
       remoteDebuggingEnabled = kDebuggerPrefs.every((pref) => Services.prefs.getBoolPref(pref));
     } catch (ex) {
       Cu.reportError(ex);
-      return;
+      return false;
     }
-    if (remoteDebuggingEnabled) {
-      Cu.import("resource:///modules/devtools/ToolboxProcess.jsm");
-      BrowserToolboxProcess.init();
-    } else {
+    if (!remoteDebuggingEnabled) {
       let errorMsg = "Could not run chrome debugger! You need the following prefs " +
                      "to be set to true: " + kDebuggerPrefs.join(", ");
       Cu.reportError(errorMsg);
-      // Dump as well, as we're doing this from a commandline, make sure people don't miss it:
+      // Dump as well, as we're doing this from a commandline, make sure people
+      // don't miss it:
       dump(errorMsg + "\n");
     }
+    return remoteDebuggingEnabled;
+  },
+
+  handleDebuggerFlag: function(cmdLine) {
+    if (!this._isRemoteDebuggingEnabled()) {
+      return;
+    }
+    Cu.import("resource:///modules/devtools/ToolboxProcess.jsm");
+    BrowserToolboxProcess.init();
+
+    if (cmdLine.state == Ci.nsICommandLine.STATE_REMOTE_AUTO) {
+      cmdLine.preventDefault = true;
+    }
+  },
+
+  handleDebuggerServerFlag: function(cmdLine, portOrPath) {
+    if (!this._isRemoteDebuggingEnabled()) {
+      return;
+    }
+    if (portOrPath === true) {
+      // Default to TCP port 6000 if no value given
+      portOrPath = 6000;
+    }
+    let { DevToolsLoader } =
+      Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
+
+    try {
+      // Create a separate loader instance, so that we can be sure to receive
+      // a separate instance of the DebuggingServer from the rest of the
+      // devtools.  This allows us to safely use the tools against even the
+      // actors and DebuggingServer itself, especially since we can mark
+      // serverLoader as invisible to the debugger (unlike the usual loader
+      // settings).
+      let serverLoader = new DevToolsLoader();
+      serverLoader.invisibleToDebugger = true;
+      serverLoader.main("devtools/server/main");
+      let debuggerServer = serverLoader.DebuggerServer;
+      debuggerServer.init();
+      debuggerServer.addBrowserActors();
+
+      let listener = debuggerServer.createListener();
+      listener.portOrPath = portOrPath;
+      listener.open();
+      dump("Started debugger server on " + portOrPath + "\n");
+    } catch(e) {
+      dump("Unable to start debugger server on " + portOrPath + ": " + e);
+    }
 
     if (cmdLine.state == Ci.nsICommandLine.STATE_REMOTE_AUTO) {
       cmdLine.preventDefault = true;
     }
   },
 
   helpInfo : "  --jsconsole        Open the Browser Console.\n" +
-             "  --jsdebugger       Open the Browser Toolbox.\n",
+             "  --jsdebugger       Open the Browser Toolbox.\n" +
+             "  --start-debugger-server [port|path] " +
+             "Start the debugger server on a TCP port or " +
+             "Unix domain socket path.  Defaults to TCP port 6000.\n",
 
   classID: Components.ID("{9e9a9283-0ce9-4e4a-8f1c-ba129a032c32}"),
   QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([devtoolsCommandlineHandler]);