@@ -140,8 +140,10 @@ static bool CallBoardSystemServiceOpenApplication(NSString *bundleIDNSStr,
140
140
cstr = " <Unknown Bundle ID>" ;
141
141
142
142
NSString *description = [options description];
143
- DNBLog (" About to launch process for bundle ID: %s - options:\n %s" , cstr,
144
- [description UTF8String]);
143
+ DNBLog (" [LaunchAttach] START (%d) templated *Board launcher: app lunch "
144
+ " request for "
145
+ " '%s' - options:\n %s" ,
146
+ getpid (), cstr, [description UTF8String]);
145
147
[system_service
146
148
openApplication:bundleIDNSStr
147
149
options:options
@@ -156,33 +158,36 @@ static bool CallBoardSystemServiceOpenApplication(NSString *bundleIDNSStr,
156
158
if (wants_pid) {
157
159
pid_in_block =
158
160
[system_service pidForApplication:bundleIDNSStr];
159
- DNBLog (
160
- " In completion handler, got pid for bundle id, pid: %d." ,
161
- pid_in_block);
162
- DNBLogThreadedIf (
163
- LOG_PROCESS,
164
- " In completion handler, got pid for bundle id, pid: %d." ,
165
- pid_in_block);
166
- } else
167
- DNBLogThreadedIf (LOG_PROCESS,
168
- " In completion handler: success." );
161
+ DNBLog (" [LaunchAttach] In completion handler, got pid for "
162
+ " bundle id "
163
+ " '%s', pid: %d." ,
164
+ cstr, pid_in_block);
165
+ } else {
166
+ DNBLog (" [LaunchAttach] In completion handler, launch was "
167
+ " successful, "
168
+ " debugserver did not ask for the pid" );
169
+ }
169
170
} else {
170
171
const char *error_str =
171
172
[(NSString *)[bks_error localizedDescription] UTF8String];
172
173
if (error_str) {
173
174
open_app_error_string = error_str;
174
- DNBLogError (" In app launch attempt, got error "
175
- " localizedDescription '%s'." , error_str);
175
+ DNBLogError (
176
+ " [LaunchAttach] END (%d) In app launch attempt, got error "
177
+ " localizedDescription '%s'." ,
178
+ getpid (), error_str);
176
179
const char *obj_desc =
177
180
[NSString stringWithFormat:@" %@" , bks_error].UTF8String ;
178
- DNBLogError (" In app launch attempt, got error "
179
- " NSError object description: '%s'." ,
180
- obj_desc);
181
+ DNBLogError (
182
+ " [LaunchAttach] END (%d) In app launch attempt, got error "
183
+ " NSError object description: '%s'." ,
184
+ getpid (), obj_desc);
181
185
}
182
- DNBLogThreadedIf (LOG_PROCESS, " In completion handler for send "
183
- " event, got error \" %s\" (%ld)." ,
186
+ DNBLogThreadedIf (LOG_PROCESS,
187
+ " In completion handler for send "
188
+ " event, got error \" %s\" (%ld)." ,
184
189
error_str ? error_str : " <unknown error>" ,
185
- open_app_error);
190
+ ( long ) open_app_error);
186
191
}
187
192
188
193
[system_service release];
@@ -200,15 +205,23 @@ static bool CallBoardSystemServiceOpenApplication(NSString *bundleIDNSStr,
200
205
201
206
dispatch_release (semaphore);
202
207
208
+ DNBLog (" [LaunchAttach] END (%d) templated *Board launcher finished app lunch "
209
+ " request for "
210
+ " '%s'" ,
211
+ getpid (), cstr);
212
+
203
213
if (!success) {
204
- DNBLogError (" timed out trying to send openApplication to %s." , cstr);
214
+ DNBLogError (" [LaunchAttach] END (%d) timed out trying to send "
215
+ " openApplication to %s." ,
216
+ getpid (), cstr);
205
217
error.SetError (OPEN_APPLICATION_TIMEOUT_ERROR, DNBError::Generic);
206
218
error.SetErrorString (" timed out trying to launch app" );
207
219
} else if (open_app_error != no_error_enum_value) {
208
220
error_function (open_app_error, open_app_error_string, error);
209
- DNBLogError (" unable to launch the application with CFBundleIdentifier '%s' "
210
- " bks_error = %u" ,
211
- cstr, open_app_error);
221
+ DNBLogError (" [LaunchAttach] END (%d) unable to launch the application with "
222
+ " CFBundleIdentifier '%s' "
223
+ " bks_error = %ld" ,
224
+ getpid (), cstr, (long )open_app_error);
212
225
success = false ;
213
226
} else if (wants_pid) {
214
227
*return_pid = pid_in_block;
@@ -1428,7 +1441,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
1428
1441
DNBLogThreadedIf (LOG_PROCESS, " MachProcess::Kill() DoSIGSTOP() state = %s" ,
1429
1442
DNBStateAsString (state));
1430
1443
errno = 0 ;
1431
- DNBLog (" Sending ptrace PT_KILL to terminate inferior process. " );
1444
+ DNBLog (" Sending ptrace PT_KILL to terminate inferior process pid %d. " , m_pid );
1432
1445
::ptrace (PT_KILL, m_pid, 0 , 0 );
1433
1446
DNBError err;
1434
1447
err.SetErrorToErrno ();
@@ -2623,15 +2636,26 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
2623
2636
::snprintf (err_str, err_len, " %s" ,
2624
2637
err_cstr ? err_cstr : " unable to start the exception thread" );
2625
2638
DNBLogThreadedIf (LOG_PROCESS, " error: failed to attach to pid %d" , pid);
2626
- DNBLogError (" MachProcess::AttachForDebug failed to start exception thread: %s" , err_str);
2639
+ DNBLogError (
2640
+ " [LaunchAttach] END (%d) MachProcess::AttachForDebug failed to start "
2641
+ " exception thread attaching to pid %i: %s" ,
2642
+ getpid (), pid, err_str);
2627
2643
m_pid = INVALID_NUB_PROCESS;
2628
2644
return INVALID_NUB_PROCESS;
2629
2645
}
2630
2646
2647
+ DNBLog (" [LaunchAttach] (%d) About to ptrace(PT_ATTACHEXC, %d)..." , getpid (),
2648
+ pid);
2631
2649
errno = 0 ;
2632
- if (::ptrace (PT_ATTACHEXC, pid, 0 , 0 )) {
2633
- err.SetError (errno);
2634
- DNBLogError (" MachProcess::AttachForDebug failed to ptrace(PT_ATTACHEXC): %s" , err.AsString ());
2650
+ int ptrace_result = ::ptrace (PT_ATTACHEXC, pid, 0 , 0 );
2651
+ int ptrace_errno = errno;
2652
+ DNBLog (" [LaunchAttach] (%d) Completed ptrace(PT_ATTACHEXC, %d) == %d" ,
2653
+ getpid (), pid, ptrace_result);
2654
+ if (ptrace_result != 0 ) {
2655
+ err.SetError (ptrace_errno);
2656
+ DNBLogError (" MachProcess::AttachForDebug failed to ptrace(PT_ATTACHEXC) "
2657
+ " pid %i: %s" ,
2658
+ pid, err.AsString ());
2635
2659
} else {
2636
2660
err.Clear ();
2637
2661
}
@@ -2642,19 +2666,27 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
2642
2666
// status
2643
2667
// to stopped.
2644
2668
::usleep (250000 );
2669
+ DNBLog (" [LaunchAttach] (%d) Done napping after ptrace(PT_ATTACHEXC)'ing" ,
2670
+ getpid ());
2645
2671
DNBLogThreadedIf (LOG_PROCESS, " successfully attached to pid %d" , pid);
2646
2672
return m_pid;
2647
2673
} else {
2648
2674
::snprintf (err_str, err_len, " %s" , err.AsString());
2649
- DNBLogError (" MachProcess::AttachForDebug error: failed to attach to pid %d" , pid);
2675
+ DNBLogError (
2676
+ " [LaunchAttach] (%d) MachProcess::AttachForDebug error: failed to "
2677
+ " attach to pid %d" ,
2678
+ getpid (), pid);
2650
2679
2651
2680
struct kinfo_proc kinfo;
2652
2681
int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid};
2653
2682
size_t len = sizeof (struct kinfo_proc );
2654
2683
if (sysctl (mib, sizeof (mib) / sizeof (mib[0 ]), &kinfo, &len, NULL , 0 ) == 0 && len > 0 ) {
2655
2684
if (kinfo.kp_proc .p_flag & P_TRACED) {
2656
2685
::snprintf (err_str, err_len, " %s - process %d is already being debugged" , err.AsString(), pid);
2657
- DNBLogError (" MachProcess::AttachForDebug pid %d is already being debugged" , pid);
2686
+ DNBLogError (
2687
+ " [LaunchAttach] (%d) MachProcess::AttachForDebug pid %d is "
2688
+ " already being debugged" ,
2689
+ getpid (), pid);
2658
2690
}
2659
2691
}
2660
2692
}
@@ -2815,6 +2847,9 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
2815
2847
2816
2848
NSString *bundleIDNSStr = (NSString *)bundleIDCFStr;
2817
2849
2850
+ DNBLog (" [LaunchAttach] START (%d) requesting FBS launch of app with bundle "
2851
+ " ID '%s'" ,
2852
+ getpid (), bundleIDStr.c_str ());
2818
2853
[system_service openApplication:bundleIDNSStr
2819
2854
options:options
2820
2855
clientPort:client_port
@@ -2893,6 +2928,9 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
2893
2928
2894
2929
NSString *bundleIDNSStr = (NSString *)bundleIDCFStr;
2895
2930
2931
+ DNBLog (" [LaunchAttach] START (%d) requesting BKS launch of app with bundle "
2932
+ " ID '%s'" ,
2933
+ getpid (), bundleIDStr.c_str ());
2896
2934
[system_service openApplication:bundleIDNSStr
2897
2935
options:options
2898
2936
clientPort:client_port
@@ -2923,7 +2961,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
2923
2961
std::string empty_str;
2924
2962
SetBKSError (attach_error_code, empty_str, attach_err);
2925
2963
DNBLogError (" unable to launch the application with CFBundleIdentifier "
2926
- " '%s' bks_error = %ld " ,
2964
+ " '%s' bks_error = %d " ,
2927
2965
bundleIDStr.c_str (), attach_error_code);
2928
2966
}
2929
2967
dispatch_release (semaphore);
@@ -2945,6 +2983,10 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
2945
2983
" SBSApplicationLaunchWaitForDebugger )" ,
2946
2984
bundleIDStr.c_str (), stdout_err, stdout_err);
2947
2985
2986
+ DNBLog (" [LaunchAttach] START (%d) requesting SpringBoard launch of app "
2987
+ " with bundle "
2988
+ " ID '%s'" ,
2989
+ getpid (), bundleIDStr.c_str ());
2948
2990
sbs_error = SBSLaunchApplicationForDebugging (
2949
2991
bundleIDCFStr,
2950
2992
(CFURLRef)NULL , // openURL
@@ -3105,7 +3147,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
3105
3147
m_flags |= (eMachProcessFlagsUsingFBS | eMachProcessFlagsBoardCalculated);
3106
3148
if (BoardServiceLaunchForDebug (app_bundle_path.c_str (), argv, envp,
3107
3149
no_stdio, disable_aslr, event_data,
3108
- launch_err) != 0 )
3150
+ unmask_signals, launch_err) != 0 )
3109
3151
return m_pid; // A successful SBLaunchForDebug() returns and assigns a
3110
3152
// non-zero m_pid.
3111
3153
else
@@ -3121,7 +3163,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
3121
3163
m_flags |= (eMachProcessFlagsUsingBKS | eMachProcessFlagsBoardCalculated);
3122
3164
if (BoardServiceLaunchForDebug (app_bundle_path.c_str (), argv, envp,
3123
3165
no_stdio, disable_aslr, event_data,
3124
- launch_err) != 0 )
3166
+ unmask_signals, launch_err) != 0 )
3125
3167
return m_pid; // A successful SBLaunchForDebug() returns and assigns a
3126
3168
// non-zero m_pid.
3127
3169
else
@@ -3148,7 +3190,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
3148
3190
if (app_ext) {
3149
3191
std::string app_bundle_path (path, app_ext + strlen (" .app" ));
3150
3192
if (SBLaunchForDebug (app_bundle_path.c_str (), argv, envp, no_stdio,
3151
- disable_aslr, launch_err) != 0 )
3193
+ disable_aslr, unmask_signals, launch_err) != 0 )
3152
3194
return m_pid; // A successful SBLaunchForDebug() returns and assigns a
3153
3195
// non-zero m_pid.
3154
3196
else
@@ -3200,14 +3242,19 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
3200
3242
3201
3243
SetState (eStateAttaching);
3202
3244
errno = 0 ;
3245
+ DNBLog (" [LaunchAttach] (%d) About to ptrace(PT_ATTACHEXC, %d)..." ,
3246
+ getpid (), m_pid);
3203
3247
int err = ::ptrace (PT_ATTACHEXC, m_pid, 0 , 0 );
3248
+ int ptrace_errno = errno;
3249
+ DNBLog (" [LaunchAttach] (%d) Completed ptrace(PT_ATTACHEXC, %d) == %d" ,
3250
+ getpid (), m_pid, err);
3204
3251
if (err == 0 ) {
3205
3252
m_flags |= eMachProcessFlagsAttached;
3206
3253
DNBLogThreadedIf (LOG_PROCESS, " successfully spawned pid %d" , m_pid);
3207
3254
launch_err.Clear ();
3208
3255
} else {
3209
3256
SetState (eStateExited);
3210
- DNBError ptrace_err (errno , DNBError::POSIX);
3257
+ DNBError ptrace_err (ptrace_errno , DNBError::POSIX);
3211
3258
DNBLogThreadedIf (LOG_PROCESS, " error: failed to attach to spawned pid "
3212
3259
" %d (err = %i, errno = %i (%s))" ,
3213
3260
m_pid, err, ptrace_err.Status (),
@@ -3577,7 +3624,11 @@ static CFStringRef CopyBundleIDForPath(const char *app_bundle_path,
3577
3624
3578
3625
StartSTDIOThread ();
3579
3626
SetState (eStateAttaching);
3627
+ DNBLog (" [LaunchAttach] (%d) About to ptrace(PT_ATTACHEXC, %d)..." , getpid (),
3628
+ m_pid);
3580
3629
int err = ::ptrace (PT_ATTACHEXC, m_pid, 0 , 0 );
3630
+ DNBLog (" [LaunchAttach] (%d) Completed ptrace(PT_ATTACHEXC, %d) == %d" ,
3631
+ getpid (), m_pid, err);
3581
3632
if (err == 0 ) {
3582
3633
m_flags |= eMachProcessFlagsAttached;
3583
3634
DNBLogThreadedIf (LOG_PROCESS, " successfully attached to pid %d" , m_pid);
@@ -3779,22 +3830,30 @@ static CFStringRef CopyBundleIDForPath(const char *app_bundle_path,
3779
3830
if (launch_err.Fail ()) {
3780
3831
if (launch_err.AsString () == NULL )
3781
3832
launch_err.SetErrorString (" unable to start the exception thread" );
3782
- DNBLog (" Could not get inferior's Mach exception port, sending ptrace "
3783
- " PT_KILL and exiting." );
3833
+ DNBLog (" [LaunchAttach] END (%d) Could not get inferior's Mach exception "
3834
+ " port, "
3835
+ " sending ptrace "
3836
+ " PT_KILL to pid %i and exiting." ,
3837
+ getpid (), m_pid);
3784
3838
::ptrace (PT_KILL, m_pid, 0 , 0 );
3785
3839
m_pid = INVALID_NUB_PROCESS;
3786
3840
return INVALID_NUB_PROCESS;
3787
3841
}
3788
3842
3789
3843
StartSTDIOThread ();
3790
3844
SetState (eStateAttaching);
3845
+ DNBLog (" [LaunchAttach] (%d) About to ptrace(PT_ATTACHEXC, %d)..." , getpid (),
3846
+ m_pid);
3791
3847
int err = ::ptrace (PT_ATTACHEXC, m_pid, 0 , 0 );
3848
+ DNBLog (" [LaunchAttach] (%d) Completed ptrace(PT_ATTACHEXC, %d) == %d" ,
3849
+ getpid (), m_pid, err);
3792
3850
if (err == 0 ) {
3793
3851
m_flags |= eMachProcessFlagsAttached;
3794
- DNBLogThreadedIf (LOG_PROCESS, " successfully attached to pid %d" , m_pid);
3852
+ DNBLog ( " [LaunchAttach] successfully attached to pid %d" , m_pid);
3795
3853
} else {
3796
3854
SetState (eStateExited);
3797
- DNBLogThreadedIf (LOG_PROCESS, " error: failed to attach to pid %d" , m_pid);
3855
+ DNBLog (" [LaunchAttach] END (%d) error: failed to attach to pid %d" ,
3856
+ getpid (), m_pid);
3798
3857
}
3799
3858
}
3800
3859
return m_pid;
0 commit comments