@@ -140,8 +140,10 @@ static bool CallBoardSystemServiceOpenApplication(NSString *bundleIDNSStr,
140140 cstr = " <Unknown Bundle ID>" ;
141141
142142 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]);
145147 [system_service
146148 openApplication:bundleIDNSStr
147149 options:options
@@ -156,33 +158,36 @@ static bool CallBoardSystemServiceOpenApplication(NSString *bundleIDNSStr,
156158 if (wants_pid) {
157159 pid_in_block =
158160 [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+ }
169170 } else {
170171 const char *error_str =
171172 [(NSString *)[bks_error localizedDescription] UTF8String];
172173 if (error_str) {
173174 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);
176179 const char *obj_desc =
177180 [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);
181185 }
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)." ,
184189 error_str ? error_str : " <unknown error>" ,
185- open_app_error);
190+ ( long ) open_app_error);
186191 }
187192
188193 [system_service release];
@@ -200,15 +205,23 @@ static bool CallBoardSystemServiceOpenApplication(NSString *bundleIDNSStr,
200205
201206 dispatch_release (semaphore);
202207
208+ DNBLog (" [LaunchAttach] END (%d) templated *Board launcher finished app lunch "
209+ " request for "
210+ " '%s'" ,
211+ getpid (), cstr);
212+
203213 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);
205217 error.SetError (OPEN_APPLICATION_TIMEOUT_ERROR, DNBError::Generic);
206218 error.SetErrorString (" timed out trying to launch app" );
207219 } else if (open_app_error != no_error_enum_value) {
208220 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);
212225 success = false ;
213226 } else if (wants_pid) {
214227 *return_pid = pid_in_block;
@@ -1428,7 +1441,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
14281441 DNBLogThreadedIf (LOG_PROCESS, " MachProcess::Kill() DoSIGSTOP() state = %s" ,
14291442 DNBStateAsString (state));
14301443 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 );
14321445 ::ptrace (PT_KILL, m_pid, 0 , 0 );
14331446 DNBError err;
14341447 err.SetErrorToErrno ();
@@ -2623,15 +2636,26 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
26232636 ::snprintf (err_str, err_len, " %s" ,
26242637 err_cstr ? err_cstr : " unable to start the exception thread" );
26252638 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);
26272643 m_pid = INVALID_NUB_PROCESS;
26282644 return INVALID_NUB_PROCESS;
26292645 }
26302646
2647+ DNBLog (" [LaunchAttach] (%d) About to ptrace(PT_ATTACHEXC, %d)..." , getpid (),
2648+ pid);
26312649 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 ());
26352659 } else {
26362660 err.Clear ();
26372661 }
@@ -2642,19 +2666,27 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
26422666 // status
26432667 // to stopped.
26442668 ::usleep (250000 );
2669+ DNBLog (" [LaunchAttach] (%d) Done napping after ptrace(PT_ATTACHEXC)'ing" ,
2670+ getpid ());
26452671 DNBLogThreadedIf (LOG_PROCESS, " successfully attached to pid %d" , pid);
26462672 return m_pid;
26472673 } else {
26482674 ::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);
26502679
26512680 struct kinfo_proc kinfo;
26522681 int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid};
26532682 size_t len = sizeof (struct kinfo_proc );
26542683 if (sysctl (mib, sizeof (mib) / sizeof (mib[0 ]), &kinfo, &len, NULL , 0 ) == 0 && len > 0 ) {
26552684 if (kinfo.kp_proc .p_flag & P_TRACED) {
26562685 ::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);
26582690 }
26592691 }
26602692 }
@@ -2815,6 +2847,9 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
28152847
28162848 NSString *bundleIDNSStr = (NSString *)bundleIDCFStr;
28172849
2850+ DNBLog (" [LaunchAttach] START (%d) requesting FBS launch of app with bundle "
2851+ " ID '%s'" ,
2852+ getpid (), bundleIDStr.c_str ());
28182853 [system_service openApplication:bundleIDNSStr
28192854 options:options
28202855 clientPort:client_port
@@ -2893,6 +2928,9 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
28932928
28942929 NSString *bundleIDNSStr = (NSString *)bundleIDCFStr;
28952930
2931+ DNBLog (" [LaunchAttach] START (%d) requesting BKS launch of app with bundle "
2932+ " ID '%s'" ,
2933+ getpid (), bundleIDStr.c_str ());
28962934 [system_service openApplication:bundleIDNSStr
28972935 options:options
28982936 clientPort:client_port
@@ -2923,7 +2961,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
29232961 std::string empty_str;
29242962 SetBKSError (attach_error_code, empty_str, attach_err);
29252963 DNBLogError (" unable to launch the application with CFBundleIdentifier "
2926- " '%s' bks_error = %ld " ,
2964+ " '%s' bks_error = %d " ,
29272965 bundleIDStr.c_str (), attach_error_code);
29282966 }
29292967 dispatch_release (semaphore);
@@ -2945,6 +2983,10 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
29452983 " SBSApplicationLaunchWaitForDebugger )" ,
29462984 bundleIDStr.c_str (), stdout_err, stdout_err);
29472985
2986+ DNBLog (" [LaunchAttach] START (%d) requesting SpringBoard launch of app "
2987+ " with bundle "
2988+ " ID '%s'" ,
2989+ getpid (), bundleIDStr.c_str ());
29482990 sbs_error = SBSLaunchApplicationForDebugging (
29492991 bundleIDCFStr,
29502992 (CFURLRef)NULL , // openURL
@@ -3105,7 +3147,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
31053147 m_flags |= (eMachProcessFlagsUsingFBS | eMachProcessFlagsBoardCalculated);
31063148 if (BoardServiceLaunchForDebug (app_bundle_path.c_str (), argv, envp,
31073149 no_stdio, disable_aslr, event_data,
3108- launch_err) != 0 )
3150+ unmask_signals, launch_err) != 0 )
31093151 return m_pid; // A successful SBLaunchForDebug() returns and assigns a
31103152 // non-zero m_pid.
31113153 else
@@ -3121,7 +3163,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
31213163 m_flags |= (eMachProcessFlagsUsingBKS | eMachProcessFlagsBoardCalculated);
31223164 if (BoardServiceLaunchForDebug (app_bundle_path.c_str (), argv, envp,
31233165 no_stdio, disable_aslr, event_data,
3124- launch_err) != 0 )
3166+ unmask_signals, launch_err) != 0 )
31253167 return m_pid; // A successful SBLaunchForDebug() returns and assigns a
31263168 // non-zero m_pid.
31273169 else
@@ -3148,7 +3190,7 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
31483190 if (app_ext) {
31493191 std::string app_bundle_path (path, app_ext + strlen (" .app" ));
31503192 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 )
31523194 return m_pid; // A successful SBLaunchForDebug() returns and assigns a
31533195 // non-zero m_pid.
31543196 else
@@ -3200,14 +3242,19 @@ static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
32003242
32013243 SetState (eStateAttaching);
32023244 errno = 0 ;
3245+ DNBLog (" [LaunchAttach] (%d) About to ptrace(PT_ATTACHEXC, %d)..." ,
3246+ getpid (), m_pid);
32033247 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);
32043251 if (err == 0 ) {
32053252 m_flags |= eMachProcessFlagsAttached;
32063253 DNBLogThreadedIf (LOG_PROCESS, " successfully spawned pid %d" , m_pid);
32073254 launch_err.Clear ();
32083255 } else {
32093256 SetState (eStateExited);
3210- DNBError ptrace_err (errno , DNBError::POSIX);
3257+ DNBError ptrace_err (ptrace_errno , DNBError::POSIX);
32113258 DNBLogThreadedIf (LOG_PROCESS, " error: failed to attach to spawned pid "
32123259 " %d (err = %i, errno = %i (%s))" ,
32133260 m_pid, err, ptrace_err.Status (),
@@ -3577,7 +3624,11 @@ static CFStringRef CopyBundleIDForPath(const char *app_bundle_path,
35773624
35783625 StartSTDIOThread ();
35793626 SetState (eStateAttaching);
3627+ DNBLog (" [LaunchAttach] (%d) About to ptrace(PT_ATTACHEXC, %d)..." , getpid (),
3628+ m_pid);
35803629 int err = ::ptrace (PT_ATTACHEXC, m_pid, 0 , 0 );
3630+ DNBLog (" [LaunchAttach] (%d) Completed ptrace(PT_ATTACHEXC, %d) == %d" ,
3631+ getpid (), m_pid, err);
35813632 if (err == 0 ) {
35823633 m_flags |= eMachProcessFlagsAttached;
35833634 DNBLogThreadedIf (LOG_PROCESS, " successfully attached to pid %d" , m_pid);
@@ -3779,22 +3830,30 @@ static CFStringRef CopyBundleIDForPath(const char *app_bundle_path,
37793830 if (launch_err.Fail ()) {
37803831 if (launch_err.AsString () == NULL )
37813832 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);
37843838 ::ptrace (PT_KILL, m_pid, 0 , 0 );
37853839 m_pid = INVALID_NUB_PROCESS;
37863840 return INVALID_NUB_PROCESS;
37873841 }
37883842
37893843 StartSTDIOThread ();
37903844 SetState (eStateAttaching);
3845+ DNBLog (" [LaunchAttach] (%d) About to ptrace(PT_ATTACHEXC, %d)..." , getpid (),
3846+ m_pid);
37913847 int err = ::ptrace (PT_ATTACHEXC, m_pid, 0 , 0 );
3848+ DNBLog (" [LaunchAttach] (%d) Completed ptrace(PT_ATTACHEXC, %d) == %d" ,
3849+ getpid (), m_pid, err);
37923850 if (err == 0 ) {
37933851 m_flags |= eMachProcessFlagsAttached;
3794- DNBLogThreadedIf (LOG_PROCESS, " successfully attached to pid %d" , m_pid);
3852+ DNBLog ( " [LaunchAttach] successfully attached to pid %d" , m_pid);
37953853 } else {
37963854 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);
37983857 }
37993858 }
38003859 return m_pid;
0 commit comments