summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp')
-rw-r--r--lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp130
1 files changed, 16 insertions, 114 deletions
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index 205faf0f8f5..0de12da2296 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -2260,62 +2260,25 @@ NativeProcessLinux::MonitorSIGTRAP(const siginfo_t *info, lldb::pid_t pid)
case (SIGTRAP | (PTRACE_EVENT_CLONE << 8)):
{
- lldb::tid_t tid = LLDB_INVALID_THREAD_ID;
+ // This is the notification on the parent thread which informs us of new thread
+ // creation. We are not interested in these events at this point (an interesting use
+ // case would be to stop the process upon thread creation), so we just resume the thread.
+ // We will pickup the new thread when we get its SIGSTOP notification.
- // The main thread is stopped here.
- if (thread_sp)
- std::static_pointer_cast<NativeThreadLinux> (thread_sp)->SetStoppedBySignal (SIGTRAP);
- NotifyThreadStop (pid);
-
- unsigned long event_message = 0;
- if (GetEventMessage (pid, &event_message).Success())
+ if (log)
{
- tid = static_cast<lldb::tid_t> (event_message);
- if (log)
+ unsigned long event_message = 0;
+ if (GetEventMessage (pid, &event_message).Success())
+ {
+ lldb::tid_t tid = static_cast<lldb::tid_t> (event_message);
log->Printf ("NativeProcessLinux::%s() pid %" PRIu64 " received thread creation event for tid %" PRIu64, __FUNCTION__, pid, tid);
- // If we don't track the thread yet: create it, mark as stopped.
- // If we do track it, this is the wait we needed. Now resume the new thread.
- // In all cases, resume the current (i.e. main process) thread.
- bool created_now = false;
- NativeThreadProtocolSP new_thread_sp = GetOrCreateThread (tid, created_now);
- assert (new_thread_sp.get() && "failed to get or create the tracking data for newly created inferior thread");
-
- // If the thread was already tracked, it means the created thread already received its SI_USER notification of creation.
- if (!created_now)
- {
- // We can now resume the newly created thread since it is fully created.
- NotifyThreadCreateStopped (tid);
- m_coordinator_up->RequestThreadResume (tid,
- [=](lldb::tid_t tid_to_resume, bool supress_signal)
- {
- std::static_pointer_cast<NativeThreadLinux> (new_thread_sp)->SetRunning ();
- return Resume (tid_to_resume, LLDB_INVALID_SIGNAL_NUMBER);
- },
- CoordinatorErrorHandler);
}
else
- {
- // Mark the thread as currently launching. Need to wait for SIGTRAP clone on the main thread before
- // this thread is ready to go.
- std::static_pointer_cast<NativeThreadLinux> (new_thread_sp)->SetLaunching ();
- }
- }
- else
- {
- if (log)
log->Printf ("NativeProcessLinux::%s() pid %" PRIu64 " received thread creation event but GetEventMessage failed so we don't know the new tid", __FUNCTION__, pid);
}
- // In all cases, we can resume the main thread here.
- m_coordinator_up->RequestThreadResume (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);
- },
- CoordinatorErrorHandler);
-
+ Resume (pid, LLDB_INVALID_SIGNAL_NUMBER);
break;
}
@@ -2640,31 +2603,12 @@ NativeProcessLinux::MonitorSignal(const siginfo_t *info, lldb::pid_t pid, bool e
log->Printf ("NativeProcessLinux::%s() pid = %" PRIu64 " tid %" PRIu64 ": new thread notification",
__FUNCTION__, GetID (), pid);
- // Did we already create the thread?
- bool created_now = false;
- thread_sp = GetOrCreateThread (pid, created_now);
- assert (thread_sp.get() && "failed to get or create the tracking data for newly created inferior thread");
-
- // If the thread was already tracked, it means the main thread already received its SIGTRAP for the create.
- if (!created_now)
- {
- // We can now resume the newly created thread since it is fully created.
- NotifyThreadCreateStopped (pid);
- m_coordinator_up->RequestThreadResume (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);
- },
- CoordinatorErrorHandler);
- }
- else
- {
- // Mark the thread as currently launching. Need to wait for SIGTRAP clone on the main thread before
- // this thread is ready to go.
- std::static_pointer_cast<NativeThreadLinux> (thread_sp)->SetLaunching ();
- }
-
+ thread_sp = AddThread(pid);
+ assert (thread_sp.get() && "failed to create the tracking data for newly created inferior thread");
+ // We can now resume the newly created thread.
+ std::static_pointer_cast<NativeThreadLinux> (thread_sp)->SetRunning ();
+ Resume (pid, LLDB_INVALID_SIGNAL_NUMBER);
+ m_coordinator_up->NotifyThreadCreate (pid, false, CoordinatorErrorHandler);
// Done handling.
return;
}
@@ -4109,48 +4053,6 @@ NativeProcessLinux::AddThread (lldb::tid_t thread_id)
return thread_sp;
}
-NativeThreadProtocolSP
-NativeProcessLinux::GetOrCreateThread (lldb::tid_t thread_id, bool &created)
-{
- Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
-
- Mutex::Locker locker (m_threads_mutex);
- if (log)
- {
- log->Printf ("NativeProcessLinux::%s pid %" PRIu64 " get/create thread with tid %" PRIu64,
- __FUNCTION__,
- GetID (),
- thread_id);
- }
-
- // Retrieve the thread if it is already getting tracked.
- NativeThreadProtocolSP thread_sp = MaybeGetThreadNoLock (thread_id);
- if (thread_sp)
- {
- if (log)
- log->Printf ("NativeProcessLinux::%s pid %" PRIu64 " tid %" PRIu64 ": thread already tracked, returning",
- __FUNCTION__,
- GetID (),
- thread_id);
- created = false;
- return thread_sp;
-
- }
-
- // Create the thread metadata since it isn't being tracked.
- if (log)
- log->Printf ("NativeProcessLinux::%s pid %" PRIu64 " tid %" PRIu64 ": thread didn't exist, tracking now",
- __FUNCTION__,
- GetID (),
- thread_id);
-
- thread_sp.reset (new NativeThreadLinux (this, thread_id));
- m_threads.push_back (thread_sp);
- created = true;
-
- return thread_sp;
-}
-
Error
NativeProcessLinux::FixupBreakpointPCAsNeeded (NativeThreadProtocolSP &thread_sp)
{
OpenPOWER on IntegriCloud