diff options
| author | Pavel Labath <labath@google.com> | 2016-11-30 11:56:32 +0000 |
|---|---|---|
| committer | Pavel Labath <labath@google.com> | 2016-11-30 11:56:32 +0000 |
| commit | e3e21cfc0c98fe1089555e0b7b32b8978b789323 (patch) | |
| tree | f0d998440810408aa5f52d297aacd4f5672b4ee0 /lldb/source/Target/Process.cpp | |
| parent | b099d16516f571721b470940ab602db26a35f28d (diff) | |
| download | bcm5719-llvm-e3e21cfc0c98fe1089555e0b7b32b8978b789323.tar.gz bcm5719-llvm-e3e21cfc0c98fe1089555e0b7b32b8978b789323.zip | |
Convert most of the Process class to Timeout<>
This changes most of the class to use the new Timeout class. The one function
left is RunThreadPlan, which I left for a separate change as the function is
massive. A couple of things to call out:
- I've renamed the affected functions to match the listener interface names. This
should also help catch any places I did not convert at compile time.
- I've deleted the WaitForState function as it was unused.
llvm-svn: 288241
Diffstat (limited to 'lldb/source/Target/Process.cpp')
| -rw-r--r-- | lldb/source/Target/Process.cpp | 121 |
1 files changed, 51 insertions, 70 deletions
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index ad0c1343708..9dc32d8e264 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -67,6 +67,7 @@ using namespace lldb; using namespace lldb_private; +using namespace std::chrono; // A temporary function to convert between old representations of timeouts (0 // means infinite wait) and new Timeout class (0 means "poll"). @@ -971,11 +972,10 @@ void Process::SyncIOHandler(uint32_t iohandler_id, uint64_t timeout_msec) { __FUNCTION__, iohandler_id, new_iohandler_id); } -StateType -Process::WaitForProcessToStop(const std::chrono::microseconds &timeout, - EventSP *event_sp_ptr, bool wait_always, - ListenerSP hijack_listener_sp, Stream *stream, - bool use_run_lock) { +StateType Process::WaitForProcessToStop(const Timeout<std::micro> &timeout, + EventSP *event_sp_ptr, bool wait_always, + ListenerSP hijack_listener_sp, + Stream *stream, bool use_run_lock) { // We can't just wait for a "stopped" event, because the stopped event may // have restarted the target. // We have to actually check each event, and in the case of a stopped event @@ -991,8 +991,9 @@ Process::WaitForProcessToStop(const std::chrono::microseconds &timeout, Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); if (log) - log->Printf("Process::%s (timeout = %llu)", __FUNCTION__, - static_cast<unsigned long long>(timeout.count())); + log->Printf( + "Process::%s (timeout = %llu)", __FUNCTION__, + static_cast<unsigned long long>(timeout ? timeout->count() : -1)); if (!wait_always && StateIsStoppedState(state, true) && StateIsStoppedState(GetPrivateState(), true)) { @@ -1009,7 +1010,7 @@ Process::WaitForProcessToStop(const std::chrono::microseconds &timeout, while (state != eStateInvalid) { EventSP event_sp; - state = WaitForStateChangedEvents(timeout, event_sp, hijack_listener_sp); + state = GetStateChangedEvents(event_sp, timeout, hijack_listener_sp); if (event_sp_ptr && event_sp) *event_sp_ptr = event_sp; @@ -1254,27 +1255,6 @@ bool Process::HandleProcessStateChangedEvent(const EventSP &event_sp, return true; } -StateType Process::WaitForState(const std::chrono::microseconds &timeout, - const StateType *match_states, - const uint32_t num_match_states) { - EventSP event_sp; - StateType state = GetState(); - while (state != eStateInvalid) { - // If we are exited or detached, we won't ever get back to any - // other valid state... - if (state == eStateDetached || state == eStateExited) - return state; - - state = WaitForStateChangedEvents(timeout, event_sp, nullptr); - - for (uint32_t i = 0; i < num_match_states; ++i) { - if (match_states[i] == state) - return state; - } - } - return state; -} - bool Process::HijackProcessEvents(ListenerSP listener_sp) { if (listener_sp) { return HijackBroadcaster(listener_sp, eBroadcastBitStateChanged | @@ -1285,15 +1265,15 @@ bool Process::HijackProcessEvents(ListenerSP listener_sp) { void Process::RestoreProcessEvents() { RestoreBroadcaster(); } -StateType -Process::WaitForStateChangedEvents(const std::chrono::microseconds &timeout, - EventSP &event_sp, - ListenerSP hijack_listener_sp) { +StateType Process::GetStateChangedEvents(EventSP &event_sp, + const Timeout<std::micro> &timeout, + ListenerSP hijack_listener_sp) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); if (log) - log->Printf("Process::%s (timeout = %llu, event_sp)...", __FUNCTION__, - static_cast<unsigned long long>(timeout.count())); + log->Printf( + "Process::%s (timeout = %llu, event_sp)...", __FUNCTION__, + static_cast<unsigned long long>(timeout ? timeout->count() : -1)); ListenerSP listener_sp = hijack_listener_sp; if (!listener_sp) @@ -1302,7 +1282,7 @@ Process::WaitForStateChangedEvents(const std::chrono::microseconds &timeout, StateType state = eStateInvalid; if (listener_sp->GetEventForBroadcasterWithType( this, eBroadcastBitStateChanged | eBroadcastBitInterrupt, event_sp, - ConvertTimeout(timeout))) { + timeout)) { if (event_sp && event_sp->GetType() == eBroadcastBitStateChanged) state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); else if (log) @@ -1310,9 +1290,10 @@ Process::WaitForStateChangedEvents(const std::chrono::microseconds &timeout, } if (log) - log->Printf("Process::%s (timeout = %llu, event_sp) => %s", __FUNCTION__, - static_cast<unsigned long long>(timeout.count()), - StateAsCString(state)); + log->Printf( + "Process::%s (timeout = %llu, event_sp) => %s", __FUNCTION__, + static_cast<unsigned long long>(timeout ? timeout->count() : -1), + StateAsCString(state)); return state; } @@ -1337,19 +1318,21 @@ Event *Process::PeekAtStateChangedEvents() { return event_ptr; } -StateType Process::WaitForStateChangedEventsPrivate( - const std::chrono::microseconds &timeout, EventSP &event_sp) { +StateType +Process::GetStateChangedEventsPrivate(EventSP &event_sp, + const Timeout<std::micro> &timeout) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); if (log) - log->Printf("Process::%s (timeout = %llu, event_sp)...", __FUNCTION__, - static_cast<unsigned long long>(timeout.count())); + log->Printf( + "Process::%s (timeout = %llu, event_sp)...", __FUNCTION__, + static_cast<unsigned long long>(timeout ? timeout->count() : -1)); StateType state = eStateInvalid; if (m_private_state_listener_sp->GetEventForBroadcasterWithType( &m_private_state_broadcaster, eBroadcastBitStateChanged | eBroadcastBitInterrupt, event_sp, - ConvertTimeout(timeout))) + timeout)) if (event_sp && event_sp->GetType() == eBroadcastBitStateChanged) state = Process::ProcessEventData::GetStateFromEvent(event_sp.get()); @@ -1357,27 +1340,28 @@ StateType Process::WaitForStateChangedEventsPrivate( // to the command-line, and that could disable the log, which would render the // log we got above invalid. if (log) - log->Printf("Process::%s (timeout = %llu, event_sp) => %s", __FUNCTION__, - static_cast<unsigned long long>(timeout.count()), - state == eStateInvalid ? "TIMEOUT" : StateAsCString(state)); + log->Printf( + "Process::%s (timeout = %llu, event_sp) => %s", __FUNCTION__, + static_cast<unsigned long long>(timeout ? timeout->count() : -1), + state == eStateInvalid ? "TIMEOUT" : StateAsCString(state)); return state; } -bool Process::WaitForEventsPrivate(const std::chrono::microseconds &timeout, - EventSP &event_sp, bool control_only) { +bool Process::GetEventsPrivate(EventSP &event_sp, + const Timeout<std::micro> &timeout, + bool control_only) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); if (log) - log->Printf("Process::%s (timeout = %llu, event_sp)...", __FUNCTION__, - static_cast<unsigned long long>(timeout.count())); + log->Printf( + "Process::%s (timeout = %llu, event_sp)...", __FUNCTION__, + static_cast<unsigned long long>(timeout ? timeout->count() : -1)); if (control_only) return m_private_state_listener_sp->GetEventForBroadcaster( - &m_private_state_control_broadcaster, event_sp, - ConvertTimeout(timeout)); + &m_private_state_control_broadcaster, event_sp, timeout); else - return m_private_state_listener_sp->GetEvent(event_sp, - ConvertTimeout(timeout)); + return m_private_state_listener_sp->GetEvent(event_sp, timeout); } bool Process::IsRunning() const { @@ -1688,8 +1672,8 @@ Error Process::ResumeSynchronous(Stream *stream) { Error error = PrivateResume(); if (error.Success()) { - StateType state = WaitForProcessToStop(std::chrono::microseconds(0), NULL, - true, listener_sp, stream); + StateType state = + WaitForProcessToStop(llvm::None, NULL, true, listener_sp, stream); const bool must_be_alive = false; // eStateExited is ok, so this must be false if (!StateIsStoppedState(state, must_be_alive)) @@ -2718,14 +2702,14 @@ Error Process::DisableWatchpoint(Watchpoint *watchpoint, bool notify) { } StateType -Process::WaitForProcessStopPrivate(const std::chrono::microseconds &timeout, - EventSP &event_sp) { +Process::WaitForProcessStopPrivate(EventSP &event_sp, + const Timeout<std::micro> &timeout) { StateType state; // Now wait for the process to launch and return control to us, and then // call DidLaunch: while (true) { event_sp.reset(); - state = WaitForStateChangedEventsPrivate(timeout, event_sp); + state = GetStateChangedEventsPrivate(event_sp, timeout); if (StateIsStoppedState(state, false)) break; @@ -2801,8 +2785,7 @@ Error Process::Launch(ProcessLaunchInfo &launch_info) { } } else { EventSP event_sp; - StateType state = - WaitForProcessStopPrivate(std::chrono::seconds(10), event_sp); + StateType state = WaitForProcessStopPrivate(event_sp, seconds(10)); if (state == eStateInvalid || !event_sp) { // We were able to launch the process, but we failed to @@ -3271,8 +3254,7 @@ Error Process::ConnectRemote(Stream *strm, llvm::StringRef remote_url) { if (error.Success()) { if (GetID() != LLDB_INVALID_PROCESS_ID) { EventSP event_sp; - StateType state = - WaitForProcessStopPrivate(std::chrono::microseconds(0), event_sp); + StateType state = WaitForProcessStopPrivate(event_sp, llvm::None); if (state == eStateStopped || state == eStateCrashed) { // If we attached and actually have a process on the other end, then @@ -3374,9 +3356,8 @@ Error Process::Halt(bool clear_thread_plans, bool use_run_lock) { } // Wait for 10 second for the process to stop. - StateType state = - WaitForProcessToStop(std::chrono::seconds(10), &event_sp, true, - halt_listener_sp, nullptr, use_run_lock); + StateType state = WaitForProcessToStop( + seconds(10), &event_sp, true, halt_listener_sp, nullptr, use_run_lock); RestoreProcessEvents(); if (state == eStateInvalid || !event_sp) { @@ -3408,8 +3389,8 @@ Error Process::StopForDestroyOrDetach(lldb::EventSP &exit_event_sp) { SendAsyncInterrupt(); // Consume the interrupt event. - StateType state = WaitForProcessToStop(std::chrono::seconds(10), - &exit_event_sp, true, listener_sp); + StateType state = + WaitForProcessToStop(seconds(10), &exit_event_sp, true, listener_sp); RestoreProcessEvents(); @@ -4038,7 +4019,7 @@ thread_result_t Process::RunPrivateStateThread(bool is_secondary_thread) { bool interrupt_requested = false; while (!exit_now) { EventSP event_sp; - WaitForEventsPrivate(std::chrono::microseconds(0), event_sp, control_only); + GetEventsPrivate(event_sp, llvm::None, control_only); if (event_sp->BroadcasterIs(&m_private_state_control_broadcaster)) { if (log) log->Printf("Process::%s (arg = %p, pid = %" PRIu64 |

