From e28a93deffabecaabdff6d4c9c2d06f151cf675a Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Fri, 17 Nov 2017 01:22:34 +0000 Subject: [PATCH] Recognize another magic token sent in the LaunchInfo's EventData. llvm-svn: 318496 --- .../tools/debugserver/source/MacOSX/MachProcess.mm | 100 +++++++++++++++------ 1 file changed, 71 insertions(+), 29 deletions(-) diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm index a93f724..04df4ba 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm +++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm @@ -45,6 +45,26 @@ #include "CFBundle.h" #include "CFString.h" +static void SplitEventData(const char *data, std::vector &elements) +{ + elements.clear(); + if (!data) + return; + + const char *start = data; + + while (*start != '\0') { + const char *token = strchr(start, ':'); + if (!token) { + elements.push_back(std::string(start)); + return; + } + if (token != start) + elements.push_back(std::string(start, token - start)); + start = ++token; + } +} + #ifdef WITH_SPRINGBOARD #include @@ -112,7 +132,9 @@ static bool CallBoardSystemServiceOpenApplication(NSString *bundleIDNSStr, if (!cstr) cstr = ""; - DNBLog("About to launch process for bundle ID: %s", cstr); + NSString *description = [options description]; + DNBLog("About to launch process for bundle ID: %s - options:\n%s", cstr, + [description UTF8String]); [system_service openApplication:bundleIDNSStr options:options @@ -222,21 +244,31 @@ static void SetBKSError(NSInteger error_code, DNBError &error) { static bool BKSAddEventDataToOptions(NSMutableDictionary *options, const char *event_data, DNBError &option_error) { - if (strcmp(event_data, "BackgroundContentFetching") == 0) { - DNBLog("Setting ActivateForEvent key in options dictionary."); - NSDictionary *event_details = [NSDictionary dictionary]; - NSDictionary *event_dictionary = [NSDictionary - dictionaryWithObject:event_details - forKey: - BKSActivateForEventOptionTypeBackgroundContentFetching]; - [options setObject:event_dictionary - forKey:BKSOpenApplicationOptionKeyActivateForEvent]; - return true; - } else { - DNBLogError("Unrecognized event type: %s. Ignoring.", event_data); - option_error.SetErrorString("Unrecognized event data."); - return false; + std::vector values; + SplitEventData(event_data, values); + bool found_one = false; + for (std::string value : values) + { + if (value.compare("BackgroundContentFetching") == 0) { + DNBLog("Setting ActivateForEvent key in options dictionary."); + NSDictionary *event_details = [NSDictionary dictionary]; + NSDictionary *event_dictionary = [NSDictionary + dictionaryWithObject:event_details + forKey: + BKSActivateForEventOptionTypeBackgroundContentFetching]; + [options setObject:event_dictionary + forKey:BKSOpenApplicationOptionKeyActivateForEvent]; + found_one = true; + } else if (value.compare("ActivateSuspended") == 0) { + DNBLog("Setting ActivateSuspended key in options dictionary."); + [options setObject:@YES forKey: BKSOpenApplicationOptionKeyActivateSuspended]; + found_one = true; + } else { + DNBLogError("Unrecognized event type: %s. Ignoring.", value.c_str()); + option_error.SetErrorString("Unrecognized event data"); + } } + return found_one; } static NSMutableDictionary *BKSCreateOptionsDictionary( @@ -322,21 +354,31 @@ static void SetFBSError(NSInteger error_code, DNBError &error) { static bool FBSAddEventDataToOptions(NSMutableDictionary *options, const char *event_data, DNBError &option_error) { - if (strcmp(event_data, "BackgroundContentFetching") == 0) { - DNBLog("Setting ActivateForEvent key in options dictionary."); - NSDictionary *event_details = [NSDictionary dictionary]; - NSDictionary *event_dictionary = [NSDictionary - dictionaryWithObject:event_details - forKey: - FBSActivateForEventOptionTypeBackgroundContentFetching]; - [options setObject:event_dictionary - forKey:FBSOpenApplicationOptionKeyActivateForEvent]; - return true; - } else { - DNBLogError("Unrecognized event type: %s. Ignoring.", event_data); - option_error.SetErrorString("Unrecognized event data."); - return false; + std::vector values; + SplitEventData(event_data, values); + bool found_one = false; + for (std::string value : values) + { + if (value.compare("BackgroundContentFetching") == 0) { + DNBLog("Setting ActivateForEvent key in options dictionary."); + NSDictionary *event_details = [NSDictionary dictionary]; + NSDictionary *event_dictionary = [NSDictionary + dictionaryWithObject:event_details + forKey: + FBSActivateForEventOptionTypeBackgroundContentFetching]; + [options setObject:event_dictionary + forKey:FBSOpenApplicationOptionKeyActivateForEvent]; + found_one = true; + } else if (value.compare("ActivateSuspended") == 0) { + DNBLog("Setting ActivateSuspended key in options dictionary."); + [options setObject:@YES forKey: FBSOpenApplicationOptionKeyActivateSuspended]; + found_one = true; + } else { + DNBLogError("Unrecognized event type: %s. Ignoring.", value.c_str()); + option_error.SetErrorString("Unrecognized event data."); + } } + return found_one; } static NSMutableDictionary * -- 2.7.4