Changeset 104115 in webkit


Ignore:
Timestamp:
Jan 4, 2012 8:19:28 PM (12 years ago)
Author:
mitz@apple.com
Message:

Source/WebKit2: Allow WebProcess to launch a client process and become its first WebProcess.

This is the WebKit2 part of fixing <http://webkit.org/b/75444> Debugging WebProcess requires running a UI process first and waiting to attach

Reviewed by Anders Carlsson.

  • PluginProcess/mac/PluginProcessMainMac.mm:

(WebKit::PluginProcessMain): Added a newline to stderr output.

  • UIProcess/Launcher/mac/EnvironmentVariables.cpp:

(WebKit::EnvironmentVariables::preexistingProcessServiceNameKey): Added. Returns the name
of the environment variable that optionally tells a UI processs to look for a preexisting
web process instead of launching a new one.
(WebKit::EnvironmentVariables::preexistingProcessTypeKey): Added. Returns the name of the
environment variable that tells a UI process the type of the preexisting web process
indicated by the other variable.

  • UIProcess/Launcher/mac/EnvironmentVariables.h:
  • UIProcess/Launcher/mac/ProcessLauncherMac.mm:

(WebKit::ProcessLauncher::launchProcess): Changed to look for a preexisting web process if
the aforementioned environment variables are set and the preexisting process has not been
used yet.

  • WebProcess/mac/WebProcessMainMac.mm:

(WebKit::WebProcessMain): Changed to look for the -client-executable command-line option,
and if present, launch the specified executable, setting variables in its environment that
tell it to use this preexisting web process, then wait for it to send a send right to its
listening port.

Tools: Add a --target-web-process option to the debug-* scripts. When specified, the scripts will
start WebProcess under gdb and WebProcess will then run the client executable.

This is the Tools part of fixing <http://webkit.org/b/75444> Debugging WebProcess requires running a UI process first and waiting to attach

Reviewed by Anders Carlsson.

  • Scripts/webkitdirs.pm:

(shouldTargetWebProcess): Added.
(determineShouldTargetWebProcess): Added. Checks for --target-web-process.
(execMacWebKitAppForDebugging): Changed to target gdb at WebProcess and pass the path to the
app using the -client-executable option if targeting the web process.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r104049 r104115  
     12012-01-04  Dan Bernstein  <mitz@apple.com>
     2
     3        Allow WebProcess to launch a client process and become its first WebProcess.
     4
     5        This is the WebKit2 part of fixing <http://webkit.org/b/75444> Debugging WebProcess requires running a UI process first and waiting to attach
     6
     7        Reviewed by Anders Carlsson.
     8
     9        * PluginProcess/mac/PluginProcessMainMac.mm:
     10        (WebKit::PluginProcessMain): Added a newline to stderr output.
     11        * UIProcess/Launcher/mac/EnvironmentVariables.cpp:
     12        (WebKit::EnvironmentVariables::preexistingProcessServiceNameKey): Added. Returns the name
     13        of the environment variable that optionally tells a UI processs to look for a preexisting
     14        web process instead of launching a new one.
     15        (WebKit::EnvironmentVariables::preexistingProcessTypeKey): Added. Returns the name of the
     16        environment variable that tells a UI process the type of the preexisting web process
     17        indicated by the other variable.
     18        * UIProcess/Launcher/mac/EnvironmentVariables.h:
     19        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
     20        (WebKit::ProcessLauncher::launchProcess): Changed to look for a preexisting web process if
     21        the aforementioned environment variables are set and the preexisting process has not been
     22        used yet.
     23        * WebProcess/mac/WebProcessMainMac.mm:
     24        (WebKit::WebProcessMain): Changed to look for the -client-executable command-line option,
     25        and if present, launch the specified executable, setting variables in its environment that
     26        tell it to use this preexisting web process, then wait for it to send a send right to its
     27        listening port.
     28
    1292012-01-04  Alexey Proskuryakov  <ap@apple.com>
    230
  • trunk/Source/WebKit2/PluginProcess/mac/PluginProcessMainMac.mm

    r103908 r104115  
    7777    kern_return_t kr = bootstrap_look_up(bootstrap_port, serviceName.utf8().data(), &serverPort);
    7878    if (kr) {
    79         fprintf(stderr, "bootstrap_look_up result: %s (%x)", mach_error_string(kr), kr);
     79        fprintf(stderr, "bootstrap_look_up result: %s (%x)\n", mach_error_string(kr), kr);
    8080        return EXIT_FAILURE;
    8181    }
  • trunk/Source/WebKit2/UIProcess/Launcher/mac/EnvironmentVariables.cpp

    r95901 r104115  
    137137}
    138138
     139#if !defined(BUILDING_ON_SNOW_LEOPARD)
     140
     141const char* EnvironmentVariables::preexistingProcessServiceNameKey()
     142{
     143    return "WEBKIT_PREEXISTING_PROCESS_SERVICE_NAME";
     144}
     145
     146const char* EnvironmentVariables::preexistingProcessTypeKey()
     147{
     148    return "WEBKIT_PREEXISTING_PROCESS_TYPE";
     149}
     150
     151#endif // !defined(BUILDING_ON_SNOW_LEOPARD)
     152
    139153} // namespace WebKit
  • trunk/Source/WebKit2/UIProcess/Launcher/mac/EnvironmentVariables.h

    r95901 r104115  
    4747    char** environmentPointer() const { return m_environmentPointer; }
    4848
     49#if !defined(BUILDING_ON_SNOW_LEOPARD)
     50    static const char* preexistingProcessServiceNameKey();
     51    static const char* preexistingProcessTypeKey();
     52#endif
     53
    4954private:
    5055    const char* valueIfVariableHasName(const char* environmentVariable, const char* name) const;
  • trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm

    r103132 r104115  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010, 2011, 2012 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    7878    mach_port_insert_right(mach_task_self(), listeningPort, listeningPort, MACH_MSG_TYPE_MAKE_SEND);
    7979
    80     NSBundle *webKit2Bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebKit2"];
    81     NSString *frameworksPath = [[webKit2Bundle bundlePath] stringByDeletingLastPathComponent];
    82     const char* frameworkExecutablePath = [[webKit2Bundle executablePath] fileSystemRepresentation];
    83 
    84     NSString *processPath;
    85     if (m_launchOptions.processType == ProcessLauncher::PluginProcess)
    86         processPath = [webKit2Bundle pathForAuxiliaryExecutable:@"PluginProcess.app"];
    87     else
    88         processPath = [webKit2Bundle pathForAuxiliaryExecutable:@"WebProcess.app"];
    89 
    90     NSString *processAppExecutablePath = [[NSBundle bundleWithPath:processPath] executablePath];
    91 
    92     RetainPtr<CFStringRef> cfLocalization(AdoptCF, WKCopyCFLocalizationPreferredName(NULL));
    93     CString localization = String(cfLocalization.get()).utf8();
    94    
    95     // Make a unique, per pid, per process launcher web process service name.
    96     CString serviceName = String::format("com.apple.WebKit.WebProcess-%d-%p", getpid(), this).utf8();
    97 
    98     const char* args[] = { [processAppExecutablePath fileSystemRepresentation], frameworkExecutablePath, "-type", processTypeAsString(m_launchOptions.processType), "-servicename", serviceName.data(), "-localization", localization.data(), 0 };
    99 
    100     // Register ourselves.
    101     kern_return_t kr = bootstrap_register2(bootstrap_port, const_cast<char*>(serviceName.data()), listeningPort, 0);
    102     ASSERT_UNUSED(kr, kr == KERN_SUCCESS);
    103 
    104     posix_spawnattr_t attr;
    105     posix_spawnattr_init(&attr);
    106 
    107     short flags = 0;
    108 
    109     // We want our process to receive all signals.
    110     sigset_t signalMaskSet;
    111     sigemptyset(&signalMaskSet);
    112 
    113     posix_spawnattr_setsigmask(&attr, &signalMaskSet);
    114     flags |= POSIX_SPAWN_SETSIGMASK;
    115 
    116     // Determine the architecture to use.
    117     cpu_type_t architecture = m_launchOptions.architecture;
    118     if (architecture == LaunchOptions::MatchCurrentArchitecture)
    119         architecture = _NSGetMachExecuteHeader()->cputype;
    120 
    121     cpu_type_t cpuTypes[] = { architecture };
    122     size_t outCount = 0;
    123     posix_spawnattr_setbinpref_np(&attr, 1, cpuTypes, &outCount);
    124 
    125     // Start suspended so we can set up the termination notification handler.
    126     flags |= POSIX_SPAWN_START_SUSPENDED;
     80    pid_t processIdentifier = 0;
     81
     82    EnvironmentVariables environmentVariables;
     83#if !defined(BUILDING_ON_SNOW_LEOPARD)
     84    static const char* preexistingProcessServiceName = environmentVariables.get(EnvironmentVariables::preexistingProcessServiceNameKey());
     85    ProcessType preexistingProcessType;
     86    if (preexistingProcessServiceName)
     87        getProcessTypeFromString(environmentVariables.get(EnvironmentVariables::preexistingProcessTypeKey()), preexistingProcessType);
     88
     89    bool usePreexistingProcess = preexistingProcessServiceName && preexistingProcessType == m_launchOptions.processType;
     90
     91    if (usePreexistingProcess) {
     92        mach_port_t lookupPort;
     93        bootstrap_look_up(bootstrap_port, preexistingProcessServiceName, &lookupPort);
     94
     95        mach_msg_header_t header;
     96        header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND);
     97        header.msgh_id = 0;
     98        header.msgh_local_port = listeningPort;
     99        header.msgh_remote_port = lookupPort;
     100        header.msgh_size = sizeof(header);
     101        kern_return_t kr = mach_msg(&header, MACH_SEND_MSG, sizeof(header), 0, MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
     102
     103        if (kr) {
     104            LOG_ERROR("Failed to pick up preexisting process at %s (%x). Launching a new process of type %s instead.", preexistingProcessServiceName, kr, processTypeAsString(m_launchOptions.processType));
     105            usePreexistingProcess = false;
     106        }
     107
     108        mach_port_deallocate(mach_task_self(), lookupPort);
     109
     110        preexistingProcessServiceName = 0;
     111    }
     112
     113    if (!usePreexistingProcess) {
     114#endif
     115        NSBundle *webKit2Bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebKit2"];
     116        NSString *frameworksPath = [[webKit2Bundle bundlePath] stringByDeletingLastPathComponent];
     117        const char* frameworkExecutablePath = [[webKit2Bundle executablePath] fileSystemRepresentation];
     118
     119        NSString *processPath;
     120        if (m_launchOptions.processType == ProcessLauncher::PluginProcess)
     121            processPath = [webKit2Bundle pathForAuxiliaryExecutable:@"PluginProcess.app"];
     122        else
     123            processPath = [webKit2Bundle pathForAuxiliaryExecutable:@"WebProcess.app"];
     124
     125        NSString *processAppExecutablePath = [[NSBundle bundleWithPath:processPath] executablePath];
     126
     127        RetainPtr<CFStringRef> cfLocalization(AdoptCF, WKCopyCFLocalizationPreferredName(NULL));
     128        CString localization = String(cfLocalization.get()).utf8();
     129       
     130        // Make a unique, per pid, per process launcher web process service name.
     131        CString serviceName = String::format("com.apple.WebKit.WebProcess-%d-%p", getpid(), this).utf8();
     132
     133        const char* args[] = { [processAppExecutablePath fileSystemRepresentation], frameworkExecutablePath, "-type", processTypeAsString(m_launchOptions.processType), "-servicename", serviceName.data(), "-localization", localization.data(), 0 };
     134
     135        // Register ourselves.
     136        kern_return_t kr = bootstrap_register2(bootstrap_port, const_cast<char*>(serviceName.data()), listeningPort, 0);
     137        ASSERT_UNUSED(kr, kr == KERN_SUCCESS);
     138
     139        posix_spawnattr_t attr;
     140        posix_spawnattr_init(&attr);
     141
     142        short flags = 0;
     143
     144        // We want our process to receive all signals.
     145        sigset_t signalMaskSet;
     146        sigemptyset(&signalMaskSet);
     147
     148        posix_spawnattr_setsigmask(&attr, &signalMaskSet);
     149        flags |= POSIX_SPAWN_SETSIGMASK;
     150
     151        // Determine the architecture to use.
     152        cpu_type_t architecture = m_launchOptions.architecture;
     153        if (architecture == LaunchOptions::MatchCurrentArchitecture)
     154            architecture = _NSGetMachExecuteHeader()->cputype;
     155
     156        cpu_type_t cpuTypes[] = { architecture };
     157        size_t outCount = 0;
     158        posix_spawnattr_setbinpref_np(&attr, 1, cpuTypes, &outCount);
     159
     160        // Start suspended so we can set up the termination notification handler.
     161        flags |= POSIX_SPAWN_START_SUSPENDED;
    127162
    128163#ifndef BUILDING_ON_SNOW_LEOPARD
    129     static const int allowExecutableHeapFlag = 0x2000;
    130     if (m_launchOptions.executableHeap)
    131         flags |= allowExecutableHeapFlag;
    132 #endif
    133 
    134     posix_spawnattr_setflags(&attr, flags);
    135 
    136     pid_t processIdentifier;
    137 
    138     EnvironmentVariables environmentVariables;
     164        static const int allowExecutableHeapFlag = 0x2000;
     165        if (m_launchOptions.executableHeap)
     166            flags |= allowExecutableHeapFlag;
     167#endif
     168
     169        posix_spawnattr_setflags(&attr, flags);
    139170
    140171#ifndef BUILDING_ON_SNOW_LEOPARD
    141     DynamicLinkerEnvironmentExtractor environmentExtractor([[NSBundle mainBundle] executablePath], architecture);
    142     environmentExtractor.getExtractedEnvironmentVariables(environmentVariables);
    143 #endif
    144 
    145     // To make engineering builds work, if the path is outside of /System set up
    146     // DYLD_FRAMEWORK_PATH to pick up other frameworks, but don't do it for the
    147     // production configuration because it involves extra file system access.
    148     if (![frameworksPath hasPrefix:@"/System/"])
    149         environmentVariables.appendValue("DYLD_FRAMEWORK_PATH", [frameworksPath fileSystemRepresentation], ':');
    150 
    151     NSString *processShimPathNSString = nil;
    152     if (m_launchOptions.processType == ProcessLauncher::PluginProcess)
    153         processShimPathNSString = [[processAppExecutablePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"PluginProcessShim.dylib"];
    154     else if (m_launchOptions.processType == ProcessLauncher::WebProcess)
    155         processShimPathNSString = [[processAppExecutablePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"WebProcessShim.dylib"];
    156 
    157     // Make sure that the shim library file exists and insert it.
    158     if (processShimPathNSString) {
    159         const char* processShimPath = [processShimPathNSString fileSystemRepresentation];
    160         struct stat statBuf;
    161         if (stat(processShimPath, &statBuf) == 0 && (statBuf.st_mode & S_IFMT) == S_IFREG)
    162             environmentVariables.appendValue("DYLD_INSERT_LIBRARIES", processShimPath, ':');
     172        DynamicLinkerEnvironmentExtractor environmentExtractor([[NSBundle mainBundle] executablePath], architecture);
     173        environmentExtractor.getExtractedEnvironmentVariables(environmentVariables);
     174#endif
     175
     176        // To make engineering builds work, if the path is outside of /System set up
     177        // DYLD_FRAMEWORK_PATH to pick up other frameworks, but don't do it for the
     178        // production configuration because it involves extra file system access.
     179        if (![frameworksPath hasPrefix:@"/System/"])
     180            environmentVariables.appendValue("DYLD_FRAMEWORK_PATH", [frameworksPath fileSystemRepresentation], ':');
     181
     182        NSString *processShimPathNSString = nil;
     183        if (m_launchOptions.processType == ProcessLauncher::PluginProcess)
     184            processShimPathNSString = [[processAppExecutablePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"PluginProcessShim.dylib"];
     185        else if (m_launchOptions.processType == ProcessLauncher::WebProcess)
     186            processShimPathNSString = [[processAppExecutablePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"WebProcessShim.dylib"];
     187
     188        // Make sure that the shim library file exists and insert it.
     189        if (processShimPathNSString) {
     190            const char* processShimPath = [processShimPathNSString fileSystemRepresentation];
     191            struct stat statBuf;
     192            if (stat(processShimPath, &statBuf) == 0 && (statBuf.st_mode & S_IFMT) == S_IFREG)
     193                environmentVariables.appendValue("DYLD_INSERT_LIBRARIES", processShimPath, ':');
     194        }
     195       
     196        int result = posix_spawn(&processIdentifier, args[0], 0, &attr, const_cast<char**>(args), environmentVariables.environmentPointer());
     197
     198        posix_spawnattr_destroy(&attr);
     199
     200        if (!result) {
     201            // Set up the termination notification handler and then ask the child process to continue.
     202            setUpTerminationNotificationHandler(processIdentifier);
     203            kill(processIdentifier, SIGCONT);
     204        } else {
     205            // We failed to launch. Release the send right.
     206            mach_port_deallocate(mach_task_self(), listeningPort);
     207
     208            // And the receive right.
     209            mach_port_mod_refs(mach_task_self(), listeningPort, MACH_PORT_RIGHT_RECEIVE, -1);
     210           
     211            listeningPort = MACH_PORT_NULL;
     212            processIdentifier = 0;
     213        }
     214#if !defined(BUILDING_ON_SNOW_LEOPARD)
    163215    }
    164    
    165     int result = posix_spawn(&processIdentifier, args[0], 0, &attr, const_cast<char**>(args), environmentVariables.environmentPointer());
    166 
    167     posix_spawnattr_destroy(&attr);
    168 
    169     if (!result) {
    170         // Set up the termination notification handler and then ask the child process to continue.
    171         setUpTerminationNotificationHandler(processIdentifier);
    172         kill(processIdentifier, SIGCONT);
    173     } else {
    174         // We failed to launch. Release the send right.
    175         mach_port_deallocate(mach_task_self(), listeningPort);
    176 
    177         // And the receive right.
    178         mach_port_mod_refs(mach_task_self(), listeningPort, MACH_PORT_RIGHT_RECEIVE, -1);
    179        
    180         listeningPort = MACH_PORT_NULL;
    181         processIdentifier = 0;
    182     }
    183    
     216#endif
     217
    184218    // We've finished launching the process, message back to the main run loop.
    185219    RunLoop::main()->dispatch(bind(&ProcessLauncher::didFinishLaunchingProcess, this, processIdentifier, listeningPort));
  • trunk/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm

    r103908 r104115  
    11/*
    2  * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010, 2011, 2012 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929#import "CommandLine.h"
    3030#import "EnvironmentUtilities.h"
     31#import "EnvironmentVariables.h"
    3132#import "RunLoop.h"
    3233#import "WebProcess.h"
     
    3940#import <servers/bootstrap.h>
    4041#import <signal.h>
     42#import <spawn.h>
    4143#import <stdio.h>
    4244#import <sysexits.h>
     
    4648#import <wtf/text/CString.h>
    4749#import <wtf/text/StringBuilder.h>
     50
     51#if !defined(BUILDING_ON_SNOW_LEOPARD)
     52extern "C" kern_return_t bootstrap_register2(mach_port_t, name_t, mach_port_t, uint64_t);
     53#endif
    4854
    4955@interface NSApplication (WebNSApplicationDetails)
     
    5965int WebProcessMain(const CommandLine& commandLine)
    6066{
    61 #ifdef BUILDING_ON_SNOW_LEOPARD
    6267    // Remove the WebProcess shim from the DYLD_INSERT_LIBRARIES environment variable so any processes spawned by
    6368    // the WebProcess don't try to insert the shim and crash.
    6469    EnvironmentUtilities::stripValuesEndingWithString("DYLD_INSERT_LIBRARIES", "/WebProcessShim.dylib");
    65 #endif
    6670
    6771    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    6872
    6973    String serviceName = commandLine["servicename"];
    70     if (serviceName.isEmpty())
     74    String clientExecutable;
     75#if !defined(BUILDING_ON_SNOW_LEOPARD)
     76    clientExecutable = commandLine["client-executable"];
     77#endif
     78
     79    if (serviceName.isEmpty() && clientExecutable.isEmpty())
    7180        return EXIT_FAILURE;
    7281
    7382    // Get the server port.
    7483    mach_port_t serverPort;
    75     kern_return_t kr = bootstrap_look_up(bootstrap_port, serviceName.utf8().data(), &serverPort);
    76     if (kr) {
    77         fprintf(stderr, "bootstrap_look_up result: %s (%x)", mach_error_string(kr), kr);
    78         return 2;
     84    if (clientExecutable.isEmpty()) {
     85        kern_return_t kr = bootstrap_look_up(bootstrap_port, serviceName.utf8().data(), &serverPort);
     86        if (kr) {
     87            fprintf(stderr, "bootstrap_look_up result: %s (%x)\n", mach_error_string(kr), kr);
     88            return 2;
     89        }
    7990    }
     91#if !defined(BUILDING_ON_SNOW_LEOPARD)
     92    else {
     93        mach_port_name_t publishedService;
     94        mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &publishedService);
     95        mach_port_insert_right(mach_task_self(), publishedService, publishedService, MACH_MSG_TYPE_MAKE_SEND);
     96        // Make it possible to look up.
     97        serviceName = String::format("com.apple.WebKit.WebProcess-%d", getpid());
     98        if (kern_return_t kr = bootstrap_register2(bootstrap_port, const_cast<char*>(serviceName.utf8().data()), publishedService, 0)) {
     99            fprintf(stderr, "Failed to register service name \"%s\". %s (%x)\n", serviceName.utf8().data(), mach_error_string(kr), kr);
     100            return EXIT_FAILURE;
     101        }
     102
     103        CString command = clientExecutable.utf8();
     104        const char* args[] = { command.data(), 0 };
     105
     106        EnvironmentVariables environmentVariables;
     107        environmentVariables.set(EnvironmentVariables::preexistingProcessServiceNameKey(), serviceName.utf8().data());
     108        environmentVariables.set(EnvironmentVariables::preexistingProcessTypeKey(), commandLine["type"].utf8().data());
     109
     110        posix_spawn_file_actions_t fileActions;
     111        posix_spawn_file_actions_init(&fileActions);
     112        posix_spawn_file_actions_addinherit_np(&fileActions, STDIN_FILENO);
     113        posix_spawn_file_actions_addinherit_np(&fileActions, STDOUT_FILENO);
     114        posix_spawn_file_actions_addinherit_np(&fileActions, STDERR_FILENO);
     115
     116        posix_spawnattr_t attributes;
     117        posix_spawnattr_init(&attributes);
     118        posix_spawnattr_setflags(&attributes, POSIX_SPAWN_CLOEXEC_DEFAULT | POSIX_SPAWN_SETPGROUP);
     119
     120        int spawnResult = posix_spawn(0, command.data(), &fileActions, &attributes, const_cast<char**>(args), environmentVariables.environmentPointer());
     121        if (spawnResult)
     122            return 2;
     123
     124        mach_msg_empty_rcv_t message;
     125        if (kern_return_t kr = mach_msg(&message.header, MACH_RCV_MSG, 0, sizeof(message), publishedService, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL)) {
     126            fprintf(stderr, "Failed to receive port from the UI process. %s (%x)\n", mach_error_string(kr), kr);
     127            return EXIT_FAILURE;
     128        }
     129
     130        mach_port_mod_refs(mach_task_self(), publishedService, MACH_PORT_RIGHT_RECEIVE, -1);
     131        serverPort = message.header.msgh_remote_port;
     132        mach_port_type_t portType;
     133        kern_return_t kr = mach_port_type(mach_task_self(), serverPort, &portType);
     134        if (kr || !(portType & MACH_PORT_TYPE_SEND)) {
     135            fprintf(stderr, "Failed to obtain send right for port received from the UI process.\n");
     136            return EXIT_FAILURE;
     137        }
     138    }
     139#endif // !defined(BUILDING_ON_SNOW_LEOPARD)
    80140
    81141    String localization = commandLine["localization"];
  • trunk/Tools/ChangeLog

    r104067 r104115  
     12012-01-04  Dan Bernstein  <mitz@apple.com>
     2
     3        Add a --target-web-process option to the debug-* scripts. When specified, the scripts will
     4        start WebProcess under gdb and WebProcess will then run the client executable.
     5
     6        This is the Tools part of fixing <http://webkit.org/b/75444> Debugging WebProcess requires running a UI process first and waiting to attach
     7
     8        Reviewed by Anders Carlsson.
     9
     10        * Scripts/webkitdirs.pm:
     11        (shouldTargetWebProcess): Added.
     12        (determineShouldTargetWebProcess): Added. Checks for --target-web-process.
     13        (execMacWebKitAppForDebugging): Changed to target gdb at WebProcess and pass the path to the
     14        app using the -client-executable option if targeting the web process.
     15
    1162012-01-04  Viatcheslav Ostapenko  <ostapenko.viatcheslav@nokia.com>
    217
  • trunk/Tools/Scripts/webkitdirs.pm

    r103834 r104115  
    1 # Copyright (C) 2005, 2006, 2007, 2010 Apple Inc. All rights reserved.
     1# Copyright (C) 2005, 2006, 2007, 2010, 2012 Apple Inc. All rights reserved.
    22# Copyright (C) 2009 Google Inc. All rights reserved.
    33# Copyright (C) 2011 Research In Motion Limited. All rights reserved.
     
    9999my $isInspectorFrontend;
    100100my $isWK2;
     101my $shouldTargetWebProcess;
    101102my $xcodeVersion;
    102103
     
    13051306{
    13061307    return $ENV{'OS'} eq 'Windows_NT';
     1308}
     1309
     1310sub shouldTargetWebProcess
     1311{
     1312    determineShouldTargetWebProcess();
     1313    return $shouldTargetWebProcess;
     1314}
     1315
     1316sub determineShouldTargetWebProcess
     1317{
     1318    return if defined($shouldTargetWebProcess);
     1319    $shouldTargetWebProcess = checkForArgumentAndRemoveFromARGV("--target-web-process");
    13071320}
    13081321
     
    23302343
    23312344    my $productDir = productDir();
    2332     print "Starting @{[basename($appPath)]} under gdb with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
    23332345    $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
    23342346    $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
    23352347    my @architectureFlags = ("-arch", architecture());
    2336     exec { $gdbPath } $gdbPath, @architectureFlags, "--args", $appPath, argumentsForRunAndDebugMacWebKitApp() or die;
     2348    if (!shouldTargetWebProcess()) {
     2349        print "Starting @{[basename($appPath)]} under gdb with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
     2350        exec { $gdbPath } $gdbPath, @architectureFlags, "--args", $appPath, argumentsForRunAndDebugMacWebKitApp() or die;
     2351    } else {
     2352        my $webProcessShimPath = File::Spec->catfile($productDir, "WebProcessShim.dylib");
     2353        my $webProcessPath = File::Spec->catdir($productDir, "WebProcess.app");
     2354        my $webKit2ExecutablePath = File::Spec->catfile($productDir, "WebKit2.framework", "WebKit2");
     2355        $ENV{DYLD_INSERT_LIBRARIES} = $webProcessShimPath;
     2356
     2357        print "Starting WebProcess under gdb with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
     2358        exec { $gdbPath } $gdbPath, @architectureFlags, "--args", $webProcessPath, $webKit2ExecutablePath, "-type", "webprocess", "-client-executable", $appPath or die;
     2359    }
    23372360}
    23382361
Note: See TracChangeset for help on using the changeset viewer.