Skip to content

Commit 187f080

Browse files
authored
Merge pull request #565 from jasonmolenda/r49953304-bday-branch-pick
Save more descriptive error msg from FBS/BKS, relay it up to lldb.
2 parents a208b31 + c5943e6 commit 187f080

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

lldb/tools/debugserver/source/MacOSX/MachProcess.mm

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static CFStringRef CopyBundleIDForPath(const char *app_bundle_path,
8686
#if defined(WITH_BKS) || defined(WITH_FBS)
8787
#import <Foundation/Foundation.h>
8888
static const int OPEN_APPLICATION_TIMEOUT_ERROR = 111;
89-
typedef void (*SetErrorFunction)(NSInteger, DNBError &);
89+
typedef void (*SetErrorFunction)(NSInteger, std::string, DNBError &);
9090
typedef bool (*CallOpenApplicationFunction)(NSString *bundleIDNSStr,
9191
NSDictionary *options,
9292
DNBError &error, pid_t *return_pid);
@@ -122,6 +122,7 @@ static bool CallBoardSystemServiceOpenApplication(NSString *bundleIDNSStr,
122122
mach_port_t client_port = [system_service createClientPort];
123123
__block dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
124124
__block ErrorFlavor open_app_error = no_error_enum_value;
125+
__block std::string open_app_error_string;
125126
bool wants_pid = (return_pid != NULL);
126127
__block pid_t pid_in_block;
127128

@@ -159,6 +160,9 @@ static bool CallBoardSystemServiceOpenApplication(NSString *bundleIDNSStr,
159160
} else {
160161
const char *error_str =
161162
[(NSString *)[bks_error localizedDescription] UTF8String];
163+
if (error_str) {
164+
open_app_error_string = error_str;
165+
}
162166
DNBLogThreadedIf(LOG_PROCESS, "In completion handler for send "
163167
"event, got error \"%s\"(%ld).",
164168
error_str ? error_str : "<unknown error>",
@@ -190,7 +194,7 @@ static bool CallBoardSystemServiceOpenApplication(NSString *bundleIDNSStr,
190194
error.SetError(OPEN_APPLICATION_TIMEOUT_ERROR, DNBError::Generic);
191195
error.SetErrorString("timed out trying to launch app");
192196
} else if (open_app_error != no_error_enum_value) {
193-
error_function(open_app_error, error);
197+
error_function(open_app_error, open_app_error_string, error);
194198
DNBLogError("unable to launch the application with CFBundleIdentifier '%s' "
195199
"bks_error = %u",
196200
cstr, open_app_error);
@@ -245,19 +249,19 @@ static bool IsBKSProcess(nub_process_t pid) {
245249
return app_state != BKSApplicationStateUnknown;
246250
}
247251

248-
static void SetBKSError(NSInteger error_code, DNBError &error) {
252+
static void SetBKSError(NSInteger error_code,
253+
std::string error_description,
254+
DNBError &error) {
249255
error.SetError(error_code, DNBError::BackBoard);
250256
NSString *err_nsstr = ::BKSOpenApplicationErrorCodeToString(
251257
(BKSOpenApplicationErrorCode)error_code);
252-
const char *err_str = NULL;
253-
if (err_nsstr == NULL)
254-
err_str = "unknown BKS error";
255-
else {
258+
std::string err_str = "unknown BKS error";
259+
if (error_description.empty() == false) {
260+
err_str = error_description;
261+
} else if (err_nsstr != nullptr) {
256262
err_str = [err_nsstr UTF8String];
257-
if (err_str == NULL)
258-
err_str = "unknown BKS error";
259263
}
260-
error.SetErrorString(err_str);
264+
error.SetErrorString(err_str.c_str());
261265
}
262266

263267
static bool BKSAddEventDataToOptions(NSMutableDictionary *options,
@@ -355,19 +359,19 @@ static bool IsFBSProcess(nub_process_t pid) {
355359
}
356360
#endif
357361

358-
static void SetFBSError(NSInteger error_code, DNBError &error) {
362+
static void SetFBSError(NSInteger error_code,
363+
std::string error_description,
364+
DNBError &error) {
359365
error.SetError((DNBError::ValueType)error_code, DNBError::FrontBoard);
360366
NSString *err_nsstr = ::FBSOpenApplicationErrorCodeToString(
361367
(FBSOpenApplicationErrorCode)error_code);
362-
const char *err_str = NULL;
363-
if (err_nsstr == NULL)
364-
err_str = "unknown FBS error";
365-
else {
368+
std::string err_str = "unknown FBS error";
369+
if (error_description.empty() == false) {
370+
err_str = error_description;
371+
} else if (err_nsstr != nullptr) {
366372
err_str = [err_nsstr UTF8String];
367-
if (err_str == NULL)
368-
err_str = "unknown FBS error";
369373
}
370-
error.SetErrorString(err_str);
374+
error.SetErrorString(err_str.c_str());
371375
}
372376

373377
static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
@@ -2754,7 +2758,8 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
27542758
"debugserver timed out waiting for openApplication to complete.");
27552759
attach_err.SetError(OPEN_APPLICATION_TIMEOUT_ERROR, DNBError::Generic);
27562760
} else if (attach_error_code != FBSOpenApplicationErrorCodeNone) {
2757-
SetFBSError(attach_error_code, attach_err);
2761+
std::string empty_str;
2762+
SetFBSError(attach_error_code, empty_str, attach_err);
27582763
DNBLogError("unable to launch the application with CFBundleIdentifier "
27592764
"'%s' bks_error = %ld",
27602765
bundleIDStr.c_str(), (NSInteger)attach_error_code);
@@ -2831,7 +2836,8 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
28312836
"debugserver timed out waiting for openApplication to complete.");
28322837
attach_err.SetError(OPEN_APPLICATION_TIMEOUT_ERROR, DNBError::Generic);
28332838
} else if (attach_error_code != BKSOpenApplicationErrorCodeNone) {
2834-
SetBKSError(attach_error_code, attach_err);
2839+
std::string empty_str;
2840+
SetBKSError(attach_error_code, empty_str, attach_err);
28352841
DNBLogError("unable to launch the application with CFBundleIdentifier "
28362842
"'%s' bks_error = %ld",
28372843
bundleIDStr.c_str(), attach_error_code);

0 commit comments

Comments
 (0)