[WK2] [GTK] Allow running the web process with an arbitrary prefix command
authorberto@igalia.com <berto@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Oct 2013 10:36:28 +0000 (10:36 +0000)
committerberto@igalia.com <berto@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Oct 2013 10:36:28 +0000 (10:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=123201

Reviewed by Carlos Garcia Campos.

Launch the web process using WEB_PROCESS_CMD_PREFIX as a
prefix. Useful for debugging the web process with gdb, valgrind,
etc.

* UIProcess/Launcher/ProcessLauncher.h:
* UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp:
(WebKit::ProcessLauncher::launchProcess):
* UIProcess/gtk/WebProcessProxyGtk.cpp:
(WebKit::WebProcessProxy::platformGetLaunchOptions):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@158105 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Launcher/ProcessLauncher.h
Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp
Source/WebKit2/UIProcess/gtk/WebProcessProxyGtk.cpp

index fa74827..351c5db 100644 (file)
@@ -1,3 +1,20 @@
+2013-10-28  Alberto Garcia  <berto@igalia.com>
+
+        [WK2] [GTK] Allow running the web process with an arbitrary prefix command
+        https://bugs.webkit.org/show_bug.cgi?id=123201
+
+        Reviewed by Carlos Garcia Campos.
+
+        Launch the web process using WEB_PROCESS_CMD_PREFIX as a
+        prefix. Useful for debugging the web process with gdb, valgrind,
+        etc.
+
+        * UIProcess/Launcher/ProcessLauncher.h:
+        * UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp:
+        (WebKit::ProcessLauncher::launchProcess):
+        * UIProcess/gtk/WebProcessProxyGtk.cpp:
+        (WebKit::WebProcessProxy::platformGetLaunchOptions):
+
 2013-10-27  Brady Eidson  <beidson@apple.com>
 
         WebIconDatabase can miss private browsing state changes.
index ea51527..c9eb352 100644 (file)
@@ -67,7 +67,7 @@ public:
         bool executableHeap;
         bool useXPC;
 #endif
-#if PLATFORM(EFL)
+#if PLATFORM(EFL) || PLATFORM(GTK)
 #ifndef NDEBUG
         String processCmdPrefix;
 #endif
index dd80056..685a1f6 100644 (file)
@@ -97,11 +97,31 @@ void ProcessLauncher::launchProcess()
 
     realExecutablePath = fileSystemRepresentation(executablePath);
     GOwnPtr<gchar> socket(g_strdup_printf("%d", sockets[0]));
-    char* argv[4];
-    argv[0] = const_cast<char*>(realExecutablePath.data());
-    argv[1] = socket.get();
-    argv[2] = const_cast<char*>(realPluginPath.data());
-    argv[3] = 0;
+
+    unsigned nargs = 4; // size of the argv array for g_spawn_async()
+
+#ifndef NDEBUG
+    Vector<CString> prefixArgs;
+    if (!m_launchOptions.processCmdPrefix.isNull()) {
+        Vector<String> splitArgs;
+        m_launchOptions.processCmdPrefix.split(' ', splitArgs);
+        for (auto it = splitArgs.begin(); it != splitArgs.end(); it++)
+            prefixArgs.append(it->utf8());
+        nargs += prefixArgs.size();
+    }
+#endif
+
+    char** argv = g_newa(char*, nargs);
+    unsigned i = 0;
+#ifndef NDEBUG
+    // If there's a prefix command, put it before the rest of the args.
+    for (auto it = prefixArgs.begin(); it != prefixArgs.end(); it++)
+        argv[i++] = const_cast<char*>(it->data());
+#endif
+    argv[i++] = const_cast<char*>(realExecutablePath.data());
+    argv[i++] = socket.get();
+    argv[i++] = const_cast<char*>(realPluginPath.data());
+    argv[i++] = 0;
 
     GOwnPtr<GError> error;
     if (!g_spawn_async(0, argv, 0, G_SPAWN_LEAVE_DESCRIPTORS_OPEN, childSetupFunction, GINT_TO_POINTER(sockets[1]), &pid, &error.outPtr())) {
index e8b173d..5907d56 100644 (file)
 
 #include "config.h"
 #include "WebProcessProxy.h"
+#include <glib.h>
 
 namespace WebKit {
 
-void WebProcessProxy::platformGetLaunchOptions(ProcessLauncher::LaunchOptions&)
+void WebProcessProxy::platformGetLaunchOptions(ProcessLauncher::LaunchOptions& launchOptions)
 {
+#ifndef NDEBUG
+    const char* webProcessCmdPrefix = g_getenv("WEB_PROCESS_CMD_PREFIX");
+    if (webProcessCmdPrefix && *webProcessCmdPrefix)
+        launchOptions.processCmdPrefix = String::fromUTF8(webProcessCmdPrefix);
+#else
+    UNUSED_PARAM(launchOptions);
+#endif
 }
 
 } // namespace WebKit