diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:09:23 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:09:23 +0000 |
commit | f73363f1dd94996356cefbf24388f561891acf0b (patch) | |
tree | e3c31248bdb36eaec5fd833490d4278162dba2a0 /source/Plugins/Process/Darwin/NativeProcessDarwin.cpp | |
parent | 160ee69dd7ae18978f4068116777639ea98dc951 (diff) |
Notes
Diffstat (limited to 'source/Plugins/Process/Darwin/NativeProcessDarwin.cpp')
-rw-r--r-- | source/Plugins/Process/Darwin/NativeProcessDarwin.cpp | 163 |
1 files changed, 78 insertions, 85 deletions
diff --git a/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp b/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp index 518f0d2da4f2..3505443abcb0 100644 --- a/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp +++ b/source/Plugins/Process/Darwin/NativeProcessDarwin.cpp @@ -104,8 +104,8 @@ Status NativeProcessProtocol::Launch( return error; } - // Finalize the processing needed to debug the launched process with - // a NativeProcessDarwin instance. + // Finalize the processing needed to debug the launched process with a + // NativeProcessDarwin instance. error = np_darwin_sp->FinalizeLaunch(launch_flavor, mainloop); if (!error.Success()) { if (log) @@ -194,9 +194,9 @@ Status NativeProcessDarwin::FinalizeLaunch(LaunchFlavor launch_flavor, "mach exception port monitor thread: %s", __FUNCTION__, error.AsCString()); - // Terminate the inferior process. There's nothing meaningful we can - // do if we can't receive signals and exceptions. Since we launched - // the process, it's fair game for us to kill it. + // Terminate the inferior process. There's nothing meaningful we can do if + // we can't receive signals and exceptions. Since we launched the process, + // it's fair game for us to kill it. ::ptrace(PT_KILL, m_pid, 0, 0); SetState(eStateExited); @@ -243,9 +243,9 @@ Status NativeProcessDarwin::FinalizeLaunch(LaunchFlavor launch_flavor, } if (TaskPortForProcessID(error) == TASK_NULL) { - // We failed to get the task for our process ID which is bad. - // Kill our process; otherwise, it will be stopped at the entry - // point and get reparented to someone else and never go away. + // We failed to get the task for our process ID which is bad. Kill our + // process; otherwise, it will be stopped at the entry point and get + // reparented to someone else and never go away. if (log) log->Printf("NativeProcessDarwin::%s(): could not get task port " "for process, sending SIGKILL and exiting: %s", @@ -277,9 +277,9 @@ bool NativeProcessDarwin::ProcessUsingBackBoard() const { return false; } -// Called by the exception thread when an exception has been received from -// our process. The exception message is completely filled and the exception -// data has already been copied. +// Called by the exception thread when an exception has been received from our +// process. The exception message is completely filled and the exception data +// has already been copied. void NativeProcessDarwin::ExceptionMessageReceived( const MachException::Message &message) { Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_VERBOSE)); @@ -290,8 +290,8 @@ void NativeProcessDarwin::ExceptionMessageReceived( SuspendTask(); } - // Use a locker to automatically unlock our mutex in case of exceptions - // Add the exception to our internal exception stack + // Use a locker to automatically unlock our mutex in case of exceptions Add + // the exception to our internal exception stack m_exception_messages.push_back(message); if (log) @@ -324,13 +324,12 @@ void *NativeProcessDarwin::DoExceptionThread() { // Ensure we don't get CPU starved. MaybeRaiseThreadPriority(); - // We keep a count of the number of consecutive exceptions received so - // we know to grab all exceptions without a timeout. We do this to get a - // bunch of related exceptions on our exception port so we can process - // then together. When we have multiple threads, we can get an exception - // per thread and they will come in consecutively. The main loop in this - // thread can stop periodically if needed to service things related to this - // process. + // We keep a count of the number of consecutive exceptions received so we + // know to grab all exceptions without a timeout. We do this to get a bunch + // of related exceptions on our exception port so we can process then + // together. When we have multiple threads, we can get an exception per + // thread and they will come in consecutively. The main loop in this thread + // can stop periodically if needed to service things related to this process. // // [did we lose some words here?] // @@ -338,15 +337,15 @@ void *NativeProcessDarwin::DoExceptionThread() { // 0 our exception port. After we get one exception, we then will use the // MACH_RCV_TIMEOUT option with a zero timeout to grab all other current // exceptions for our process. After we have received the last pending - // exception, we will get a timeout which enables us to then notify - // our main thread that we have an exception bundle available. We then wait - // for the main thread to tell this exception thread to start trying to get + // exception, we will get a timeout which enables us to then notify our main + // thread that we have an exception bundle available. We then wait for the + // main thread to tell this exception thread to start trying to get // exceptions messages again and we start again with a mach_msg read with // infinite timeout. // // We choose to park a thread on this, rather than polling, because the - // polling is expensive. On devices, we need to minimize overhead caused - // by the process monitor. + // polling is expensive. On devices, we need to minimize overhead caused by + // the process monitor. uint32_t num_exceptions_received = 0; Status error; task_t task = m_task; @@ -359,8 +358,7 @@ void *NativeProcessDarwin::DoExceptionThread() { CFReleaser<SBSWatchdogAssertionRef> watchdog; if (process->ProcessUsingSpringBoard()) { - // Request a renewal for every 60 seconds if we attached using - // SpringBoard. + // Request a renewal for every 60 seconds if we attached using SpringBoard. watchdog.reset(::SBSWatchdogAssertionCreateForPID(nullptr, pid, 60)); if (log) log->Printf("::SBSWatchdogAssertionCreateForPID(NULL, %4.4x, 60) " @@ -401,18 +399,18 @@ void *NativeProcessDarwin::DoExceptionThread() { } #endif // #ifdef WITH_BKS - // Do we want to use a weak pointer to the NativeProcessDarwin here, in - // which case we can guarantee we don't whack the process monitor if we - // race between this thread and the main one on shutdown? + // Do we want to use a weak pointer to the NativeProcessDarwin here, in which + // case we can guarantee we don't whack the process monitor if we race + // between this thread and the main one on shutdown? while (IsExceptionPortValid()) { ::pthread_testcancel(); MachException::Message exception_message; if (num_exceptions_received > 0) { - // We don't want a timeout here, just receive as many exceptions as - // we can since we already have one. We want to get all currently - // available exceptions for this task at once. + // We don't want a timeout here, just receive as many exceptions as we + // can since we already have one. We want to get all currently available + // exceptions for this task at once. error = exception_message.Receive( GetExceptionPort(), MACH_RCV_MSG | MACH_RCV_INTERRUPT | MACH_RCV_TIMEOUT, 0); @@ -424,8 +422,8 @@ void *NativeProcessDarwin::DoExceptionThread() { MACH_RCV_TIMEOUT, periodic_timeout); } else { - // We don't need to parse all current exceptions or stop - // periodically, just wait for an exception forever. + // We don't need to parse all current exceptions or stop periodically, + // just wait for an exception forever. error = exception_message.Receive(GetExceptionPort(), MACH_RCV_MSG | MACH_RCV_INTERRUPT, 0); } @@ -462,8 +460,8 @@ void *NativeProcessDarwin::DoExceptionThread() { __FUNCTION__); continue; } else { - // The inferior task is no longer valid. Time to exit as - // the process has gone away. + // The inferior task is no longer valid. Time to exit as the process + // has gone away. if (log) log->Printf("NativeProcessDarwin::%s(): the inferior task " "has exited, and so will we...", @@ -476,18 +474,17 @@ void *NativeProcessDarwin::DoExceptionThread() { // We timed out when waiting for exceptions. if (num_exceptions_received > 0) { - // We were receiving all current exceptions with a timeout of - // zero. It is time to go back to our normal looping mode. + // We were receiving all current exceptions with a timeout of zero. + // It is time to go back to our normal looping mode. num_exceptions_received = 0; - // Notify our main thread we have a complete exception message - // bundle available. Get the possibly updated task port back - // from the process in case we exec'ed and our task port - // changed. + // Notify our main thread we have a complete exception message bundle + // available. Get the possibly updated task port back from the + // process in case we exec'ed and our task port changed. task = ExceptionMessageBundleComplete(); - // In case we use a timeout value when getting exceptions, - // make sure our task is still valid. + // In case we use a timeout value when getting exceptions, make sure + // our task is still valid. if (IsTaskValid(task)) { // Task is still ok. if (log) @@ -496,8 +493,8 @@ void *NativeProcessDarwin::DoExceptionThread() { __FUNCTION__); continue; } else { - // The inferior task is no longer valid. Time to exit as - // the process has gone away. + // The inferior task is no longer valid. Time to exit as the + // process has gone away. if (log) log->Printf("NativeProcessDarwin::%s(): the inferior " "task has exited, and so will we...", @@ -534,10 +531,8 @@ void *NativeProcessDarwin::DoExceptionThread() { // TODO: change SBSWatchdogAssertionRelease to SBSWatchdogAssertionCancel // when we // all are up and running on systems that support it. The SBS framework has - // a #define - // that will forward SBSWatchdogAssertionRelease to - // SBSWatchdogAssertionCancel for now - // so it should still build either way. + // a #define that will forward SBSWatchdogAssertionRelease to + // SBSWatchdogAssertionCancel for now so it should still build either way. DNBLogThreadedIf(LOG_TASK, "::SBSWatchdogAssertionRelease(%p)", watchdog.get()); ::SBSWatchdogAssertionRelease(watchdog.get()); @@ -728,8 +723,8 @@ task_t NativeProcessDarwin::ExceptionMessageBundleComplete() { const int signo = m_exception_messages[i].state.SoftSignal(); if (signo == SIGTRAP) { // SIGTRAP could mean that we exec'ed. We need to check the - // dyld all_image_infos.infoArray to see if it is NULL and if - // so, say that we exec'ed. + // dyld all_image_infos.infoArray to see if it is NULL and if so, say + // that we exec'ed. const addr_t aii_addr = GetDYLDAllImageInfosAddress(error); if (aii_addr == LLDB_INVALID_ADDRESS) break; @@ -744,12 +739,12 @@ task_t NativeProcessDarwin::ExceptionMessageBundleComplete() { bytes_read); // #bytes read if (read_error.Success() && (bytes_read == 4)) { if (info_array_count == 0) { - // We got the all infos address, and there are zero - // entries. We think we exec'd. + // We got the all infos address, and there are zero entries. We + // think we exec'd. m_did_exec = true; - // Force the task port to update itself in case the - // task port changed after exec + // Force the task port to update itself in case the task port + // changed after exec const task_t old_task = m_task; const bool force_update = true; const task_t new_task = TaskPortForProcessID(error, force_update); @@ -810,8 +805,7 @@ task_t NativeProcessDarwin::ExceptionMessageBundleComplete() { // 4 - We might need to resume if we stopped only with the // interrupt signal that we never handled. if (m_auto_resume_signo != 0) { - // Only auto_resume if we stopped with _only_ the interrupt - // signal. + // Only auto_resume if we stopped with _only_ the interrupt signal. if (num_task_exceptions == 1) { auto_resume = true; if (log) @@ -831,8 +825,8 @@ task_t NativeProcessDarwin::ExceptionMessageBundleComplete() { } } - // Let all threads recover from stopping and do any clean up based - // on the previous thread state (if any). + // Let all threads recover from stopping and do any clean up based on the + // previous thread state (if any). m_thread_list.ProcessDidStop(*this); // Let each thread know of any exceptions @@ -863,8 +857,8 @@ task_t NativeProcessDarwin::ExceptionMessageBundleComplete() { // TODO - need to hook up event system here. !!!! #if 0 // Wait for the eEventProcessRunningStateChanged event to be reset - // before changing state to stopped to avoid race condition with - // very fast start/stops. + // before changing state to stopped to avoid race condition with very + // fast start/stops. struct timespec timeout; //DNBTimer::OffsetTimeOfDay(&timeout, 0, 250 * 1000); // Wait for 250 ms @@ -889,12 +883,12 @@ Status NativeProcessDarwin::StartWaitpidThread(MainLoop &main_loop) { Status error; Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); - // Strategy: create a thread that sits on waitpid(), waiting for the - // inferior process to die, reaping it in the process. Arrange for - // the thread to have a pipe file descriptor that it can send a byte - // over when the waitpid completes. Have the main loop have a read - // object for the other side of the pipe, and have the callback for - // the read do the process termination message sending. + // Strategy: create a thread that sits on waitpid(), waiting for the inferior + // process to die, reaping it in the process. Arrange for the thread to have + // a pipe file descriptor that it can send a byte over when the waitpid + // completes. Have the main loop have a read object for the other side of + // the pipe, and have the callback for the read do the process termination + // message sending. // Create a single-direction communication channel. const bool child_inherits = false; @@ -1025,8 +1019,8 @@ void *NativeProcessDarwin::DoWaitpidThread() { } } - // We should never exit as long as our child process is alive. If we - // get here, something completely unexpected went wrong and we should exit. + // We should never exit as long as our child process is alive. If we get + // here, something completely unexpected went wrong and we should exit. if (log) log->Printf( "NativeProcessDarwin::%s(): internal error: waitpid thread " @@ -1157,8 +1151,8 @@ task_t NativeProcessDarwin::TaskPortForProcessID(Status &error, ::usleep(usec_interval); } - // We failed to get the task for the inferior process. - // Ensure that it is cleared out. + // We failed to get the task for the inferior process. Ensure that it is + // cleared out. m_task = TASK_NULL; } return m_task; @@ -1196,9 +1190,9 @@ Status NativeProcessDarwin::PrivateResume() { } // bool stepOverBreakInstruction = step; - // Let the thread prepare to resume and see if any threads want us to - // step over a breakpoint instruction (ProcessWillResume will modify - // the value of stepOverBreakInstruction). + // Let the thread prepare to resume and see if any threads want us to step + // over a breakpoint instruction (ProcessWillResume will modify the value of + // stepOverBreakInstruction). m_thread_list.ProcessWillResume(*this, m_thread_actions); // Set our state accordingly @@ -1254,8 +1248,8 @@ Status NativeProcessDarwin::ReplyToAllExceptions() { error = message.Reply(m_pid, m_task, thread_reply_signal); if (error.Fail() && log) { - // We log any error here, but we don't stop the exception - // response handling. + // We log any error here, but we don't stop the exception response + // handling. log->Printf("NativeProcessDarwin::%s(): failed to reply to " "exception: %s", __FUNCTION__, error.AsCString()); @@ -1263,8 +1257,8 @@ Status NativeProcessDarwin::ReplyToAllExceptions() { } } - // Erase all exception message as we should have used and replied - // to them all already. + // Erase all exception message as we should have used and replied to them all + // already. m_exception_messages.clear(); return error; } @@ -1292,8 +1286,8 @@ Status NativeProcessDarwin::ResumeTask() { "0x%4.4x", __FUNCTION__, m_task); - // Get the BasicInfo struct to verify that we're suspended before we try - // to resume the task. + // Get the BasicInfo struct to verify that we're suspended before we try to + // resume the task. struct task_basic_info task_info; error = GetTaskBasicInfo(m_task, &task_info); if (error.Fail()) { @@ -1304,9 +1298,8 @@ Status NativeProcessDarwin::ResumeTask() { return error; } - // task_resume isn't counted like task_suspend calls are, so if the - // task is not suspended, don't try and resume it since it is already - // running + // task_resume isn't counted like task_suspend calls are, so if the task is + // not suspended, don't try and resume it since it is already running if (task_info.suspend_count > 0) { auto mach_err = ::task_resume(m_task); error.SetError(mach_err, eErrorTypeMachKernel); |