[Lldb-commits] [lldb] r259738 - Fix a little threading thinko in StartPrivateStateThread - don't pass stack variables

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Wed Feb 3 17:34:34 PST 2016


Author: jingham
Date: Wed Feb  3 19:34:33 2016
New Revision: 259738

URL: http://llvm.org/viewvc/llvm-project?rev=259738&view=rev
Log:
Fix a little threading thinko in StartPrivateStateThread - don't pass stack variables
as args to a pthread_create function...

<rdar://problem/24485206>

Modified:
    lldb/trunk/include/lldb/Target/Process.h
    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=259738&r1=259737&r2=259738&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Wed Feb  3 19:34:33 2016
@@ -3433,12 +3433,15 @@ protected:
     void
     ResumePrivateStateThread ();
 
+private:
     struct PrivateStateThreadArgs
     {
+        PrivateStateThreadArgs(Process *p, bool s) : process(p), is_secondary_thread(s) {};
         Process *process;
         bool is_secondary_thread;
     };
-
+    
+    // arg is a pointer to a new'ed PrivateStateThreadArgs structure.  PrivateStateThread will free it for you.
     static lldb::thread_result_t
     PrivateStateThread (void *arg);
 
@@ -3450,6 +3453,7 @@ protected:
     lldb::thread_result_t
     RunPrivateStateThread (bool is_secondary_thread);
 
+protected:
     void
     HandlePrivateEvent (lldb::EventSP &event_sp);
 

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=259738&r1=259737&r2=259738&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Wed Feb  3 19:34:33 2016
@@ -4065,8 +4065,8 @@ Process::StartPrivateStateThread (bool i
     }
 
     // Create the private state thread, and start it running.
-    PrivateStateThreadArgs args = {this, is_secondary_thread};
-    m_private_state_thread = ThreadLauncher::LaunchThread(thread_name, Process::PrivateStateThread, (void *) &args, NULL, 8 * 1024 * 1024);
+    PrivateStateThreadArgs *args_ptr = new PrivateStateThreadArgs(this, is_secondary_thread);
+    m_private_state_thread = ThreadLauncher::LaunchThread(thread_name, Process::PrivateStateThread, (void *) args_ptr, NULL, 8 * 1024 * 1024);
     if (m_private_state_thread.IsJoinable())
     {
         ResumePrivateStateThread();
@@ -4308,8 +4308,9 @@ Process::HaltPrivate()
 thread_result_t
 Process::PrivateStateThread (void *arg)
 {
-    PrivateStateThreadArgs *real_args = static_cast<PrivateStateThreadArgs *> (arg);
-    thread_result_t result = real_args->process->RunPrivateStateThread(real_args->is_secondary_thread);
+    PrivateStateThreadArgs real_args = *static_cast<PrivateStateThreadArgs *> (arg);
+    free (arg);
+    thread_result_t result = real_args.process->RunPrivateStateThread(real_args.is_secondary_thread);
     return result;
 }
 




More information about the lldb-commits mailing list