<rdar://problem/11386214>
authorGreg Clayton <gclayton@apple.com>
Fri, 18 May 2012 02:38:05 +0000 (02:38 +0000)
committerGreg Clayton <gclayton@apple.com>
Fri, 18 May 2012 02:38:05 +0000 (02:38 +0000)
<rdar://problem/11455913>

"target symbol add" should flush the cached frames
"register write" should flush the thread state in case registers modifications change stack

llvm-svn: 157042

lldb/include/lldb/Target/Process.h
lldb/include/lldb/Target/Thread.h
lldb/include/lldb/Target/ThreadList.h
lldb/source/Commands/CommandObjectRegister.cpp
lldb/source/Commands/CommandObjectTarget.cpp
lldb/source/Target/Process.cpp
lldb/source/Target/Thread.cpp
lldb/source/Target/ThreadList.cpp

index e673c44..2ec1f85 100644 (file)
@@ -2269,6 +2269,18 @@ public:
         return m_target;
     }
 
+    //------------------------------------------------------------------
+    /// Flush all data in the process.
+    ///
+    /// Flush the memory caches, all threads, and any other cached data
+    /// in the process.
+    ///
+    /// This function can be called after a world changing event like
+    /// adding a new symbol file, or after the process makes a large
+    /// context switch (from boot ROM to booted into an OS).
+    //------------------------------------------------------------------
+    void
+    Flush ();
 
     //------------------------------------------------------------------
     /// Get accessor for the current process state.
index 94463f1..cdd66c0 100644 (file)
@@ -274,6 +274,9 @@ public:
     Vote
     ShouldReportRun (Event *event_ptr);
     
+    void
+    Flush ();
+
     // Return whether this thread matches the specification in ThreadSpec.  This is a virtual
     // method because at some point we may extend the thread spec with a platform specific
     // dictionary of attributes, which then only the platform specific Thread implementation
index be6a1a2..5acc873 100644 (file)
@@ -60,6 +60,9 @@ public:
     Clear();
 
     void
+    Flush();
+
+    void
     Destroy();
 
     // Note that "idx" is not the same as the "thread_index". It is a zero
index c34e6ee..37ebb78 100644 (file)
@@ -425,6 +425,9 @@ public:
                     {
                         if (reg_ctx->WriteRegister (reg_info, reg_value))
                         {
+                            // Toss all frames and anything else in the thread
+                            // after a register has been written.
+                            exe_ctx.GetThreadRef().Flush();
                             result.SetStatus (eReturnStatusSuccessFinishNoResult);
                             return true;
                         }
index c7b644f..a38f143 100644 (file)
@@ -3585,21 +3585,21 @@ public:
     Execute (Args& args,
              CommandReturnObject &result)
     {
-        Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
+        ExecutionContext exe_ctx (m_interpreter.GetExecutionContext());
+        Target *target = exe_ctx.GetTargetPtr();
         if (target == NULL)
         {
             result.AppendError ("invalid target, create a debug target using the 'target create' command");
             result.SetStatus (eReturnStatusFailed);
-            return false;
         }
         else
         {
+            bool flush = false;
             const size_t argc = args.GetArgumentCount();
             if (argc == 0)
             {
                 result.AppendError ("one or more symbol file paths must be specified");
                 result.SetStatus (eReturnStatusFailed);
-                return false;
             }
             else
             {
@@ -3633,13 +3633,14 @@ public:
                                     ModuleList module_list;
                                     module_list.Append (old_module_sp);
                                     target->ModulesDidLoad (module_list);
+                                    flush = true;
                                 }
                             }
                             else
                             {
                                 result.AppendError ("one or more executable image paths must be specified");
                                 result.SetStatus (eReturnStatusFailed);
-                                return false;
+                                break;
                             }
                             result.SetStatus (eReturnStatusSuccessFinishResult);
                         }
@@ -3661,6 +3662,13 @@ public:
                     }
                 }
             }
+
+            if (flush)
+            {
+                Process *process = exe_ctx.GetProcessPtr();
+                if (process)
+                    process->Flush();
+            }
         }
         return result.Succeeded();
     }
index 3a9b360..4225b80 100644 (file)
@@ -4707,6 +4707,12 @@ Process::ClearPreResumeActions ()
     m_pre_resume_actions.clear();
 }
 
+void
+Process::Flush ()
+{
+    m_thread_list.Flush();
+}
+
 //--------------------------------------------------------------
 // class Process::SettingsController
 //--------------------------------------------------------------
index 5c3c197..4513577 100644 (file)
@@ -1410,6 +1410,14 @@ Thread::GetUnwinder ()
 }
 
 
+void
+Thread::Flush ()
+{
+    ClearStackFrames ();
+    m_reg_context_sp.reset();
+}
+
+
 #pragma mark "Thread::SettingsController"
 //--------------------------------------------------------------
 // class Thread::SettingsController
index e1c3866..3152c15 100644 (file)
@@ -605,4 +605,12 @@ ThreadList::Update (ThreadList &rhs)
     }
 }
 
+void
+ThreadList::Flush ()
+{
+    Mutex::Locker locker(m_threads_mutex);    
+    collection::iterator pos, end = m_threads.end();
+    for (pos = m_threads.begin(); pos != end; ++pos)
+        (*pos)->Flush ();
+}