[Lldb-commits] [lldb] r237445 - [NativeProcessLinux] Fix potential race during thread exit

Pavel Labath labath at google.com
Fri May 15 06:31:00 PDT 2015


Author: labath
Date: Fri May 15 08:30:59 2015
New Revision: 237445

URL: http://llvm.org/viewvc/llvm-project?rev=237445&view=rev
Log:
[NativeProcessLinux] Fix potential race during thread exit

Summary:
This is the same issue as we had in D9145 for thread creation. Going through the full
ThreadDidStop/RequestResume cycle can cause a deferred notification to fire, which is not correct
when we are ignoring an event and resuming the thread. In this case it doesn't matter much since
the thread will die after that anyway, but for correctness, we should do the same thing here.
Also treating the SIGTRAP case the same way.

Test Plan: Tests continue to pass.

Reviewers: chaoren, ovyalov

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D9696

Modified:
    lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp?rev=237445&r1=237444&r2=237445&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Fri May 15 08:30:59 2015
@@ -2483,15 +2483,9 @@ NativeProcessLinux::MonitorSIGTRAP(const
     case (SIGTRAP | (PTRACE_EVENT_EXIT << 8)):
     {
         // The inferior process or one of its threads is about to exit.
-        if (! thread_sp)
-            break;
-
-        // This thread is currently stopped.  It's not actually dead yet, just about to be.
-        ThreadDidStop (pid, false);
-        // The actual stop reason does not matter much, as we are going to resume the thread a
-        // few lines down. If we ever want to report this state to the debugger, then we should
-        // invent a new stop reason.
-        std::static_pointer_cast<NativeThreadLinux>(thread_sp)->SetStoppedBySignal(LLDB_INVALID_SIGNAL_NUMBER);
+        // We don't want to do anything with the thread so we just resume it. In case we
+        // want to implement "break on thread exit" functionality, we would need to stop
+        // here.
 
         unsigned long data = 0;
         if (GetEventMessage(pid, &data).Fail())
@@ -2511,14 +2505,7 @@ NativeProcessLinux::MonitorSIGTRAP(const
             SetExitStatus (convert_pid_status_to_exit_type (data), convert_pid_status_to_return_code (data), nullptr, true);
         }
 
-        const int signo = static_cast<int> (data);
-        ResumeThread(pid,
-                [=](lldb::tid_t tid_to_resume, bool supress_signal)
-                {
-                    std::static_pointer_cast<NativeThreadLinux> (thread_sp)->SetRunning ();
-                    return Resume (tid_to_resume, (supress_signal) ? LLDB_INVALID_SIGNAL_NUMBER : signo);
-                },
-                true);
+        Resume(pid, LLDB_INVALID_SIGNAL_NUMBER);
 
         break;
     }
@@ -2556,26 +2543,15 @@ NativeProcessLinux::MonitorSIGTRAP(const
         if (log)
             log->Printf ("NativeProcessLinux::%s() received unknown SIGTRAP system call stop event, pid %" PRIu64 "tid %" PRIu64 ", resuming", __FUNCTION__, GetID (), pid);
 
-        // This thread is currently stopped.
-        ThreadDidStop (pid, false);
-        if (thread_sp)
-            std::static_pointer_cast<NativeThreadLinux> (thread_sp)->SetStoppedBySignal (SIGTRAP);
-
-            
         // Ignore these signals until we know more about them.
-        ResumeThread(pid,
-                [=](lldb::tid_t tid_to_resume, bool supress_signal)
-                {
-                    std::static_pointer_cast<NativeThreadLinux> (thread_sp)->SetRunning ();
-                    return Resume (tid_to_resume, LLDB_INVALID_SIGNAL_NUMBER);
-                },
-                true);
+        Resume(pid, LLDB_INVALID_SIGNAL_NUMBER);
         break;
 
     default:
         assert(false && "Unexpected SIGTRAP code!");
         if (log)
-            log->Printf ("NativeProcessLinux::%s() pid %" PRIu64 "tid %" PRIu64 " received unhandled SIGTRAP code: 0x%" PRIx64, __FUNCTION__, GetID (), pid, static_cast<uint64_t> (SIGTRAP | (PTRACE_EVENT_CLONE << 8)));
+            log->Printf ("NativeProcessLinux::%s() pid %" PRIu64 "tid %" PRIu64 " received unhandled SIGTRAP code: 0x%d",
+                    __FUNCTION__, GetID (), pid, info->si_code);
         break;
         
     }





More information about the lldb-commits mailing list