[Lldb-commits] [lldb] r192301 - Allow Process::WaitForProcessToStop to return immediately if process is already in the stopped state

Daniel Malea daniel.malea at gmail.com
Wed Oct 9 09:56:28 PDT 2013


Author: dmalea
Date: Wed Oct  9 11:56:28 2013
New Revision: 192301

URL: http://llvm.org/viewvc/llvm-project?rev=192301&view=rev
Log:
Allow Process::WaitForProcessToStop to return immediately if process is already in the stopped state
- By default, the above function will wait for at least one event
- Set wait_always=false to make the function return immediately if the process is already stopped


Modified:
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/source/Commands/CommandObjectProcess.cpp
    lldb/trunk/source/Target/Process.cpp

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=192301&r1=192300&r2=192301&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Wed Oct  9 11:56:28 2013
@@ -3316,8 +3316,11 @@ public:
     lldb::StateType
     GetNextEvent (lldb::EventSP &event_sp);
 
+    // Returns the process state when it is stopped. If specified, event_sp_ptr
+    // is set to the event which triggered the stop. If wait_always = false,
+    // and the process is already stopped, this function returns immediately.
     lldb::StateType
-    WaitForProcessToStop (const TimeValue *timeout, lldb::EventSP *event_sp_ptr = NULL);
+    WaitForProcessToStop (const TimeValue *timeout, lldb::EventSP *event_sp_ptr = NULL, bool wait_always = true);
 
     lldb::StateType
     WaitForStateChangedEvents (const TimeValue *timeout, lldb::EventSP &event_sp);

Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=192301&r1=192300&r2=192301&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Wed Oct  9 11:56:28 2013
@@ -302,7 +302,7 @@ protected:
             if (m_options.launch_info.GetFlags().Test(eLaunchFlagStopAtEntry) == false)
             {
                 result.SetStatus (eReturnStatusSuccessContinuingNoResult);
-                StateType state = process->WaitForProcessToStop (NULL);
+                StateType state = process->WaitForProcessToStop (NULL, NULL, false);
 
                 if (state == eStateStopped)
                 {

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=192301&r1=192300&r2=192301&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Wed Oct  9 11:56:28 2013
@@ -1230,7 +1230,7 @@ Process::GetNextEvent (EventSP &event_sp
 
 
 StateType
-Process::WaitForProcessToStop (const TimeValue *timeout, lldb::EventSP *event_sp_ptr)
+Process::WaitForProcessToStop (const TimeValue *timeout, lldb::EventSP *event_sp_ptr, bool wait_always)
 {
     // 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 check the restarted flag
@@ -1243,6 +1243,19 @@ Process::WaitForProcessToStop (const Tim
     if (state == eStateDetached || state == eStateExited)
         return state;
 
+    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
+    if (log)
+        log->Printf ("Process::%s (timeout = %p)", __FUNCTION__, timeout);
+
+    if (!wait_always &&
+        StateIsStoppedState(state, true) &&
+        StateIsStoppedState(GetPrivateState(), true)) {
+        if (log)
+            log->Printf("Process::%s returning without waiting for events; process private and public states are already 'stopped'.",
+                        __FUNCTION__);
+        return state;
+    }
+
     while (state != eStateInvalid)
     {
         EventSP event_sp;





More information about the lldb-commits mailing list