summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Target/Process.h17
-rw-r--r--lldb/include/lldb/Target/ThreadList.h3
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp18
-rw-r--r--lldb/source/Target/Process.cpp40
-rw-r--r--lldb/source/Target/Thread.cpp3
-rw-r--r--lldb/source/Target/ThreadList.cpp23
6 files changed, 98 insertions, 6 deletions
diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h
index 7ccb137c85b..e33e396de35 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -3132,10 +3132,22 @@ public:
{
return m_thread_list;
}
-
-
+
+ // This is obsoleted and will be removed very soon.
uint32_t
GetNextThreadIndexID ();
+
+ uint32_t
+ GetNextThreadIndexID (uint64_t thread_id);
+
+ // Returns true if an index id has been assigned to a thread.
+ bool
+ HasAssignedIndexIDToThread(uint64_t sb_thread_id);
+
+ // Given a thread_id, it will assign a more reasonable index id for display to the user.
+ // If the thread_id has previously been assigned, the same index id will be used.
+ uint32_t
+ AssignIndexIDToThread(uint64_t thread_id);
//------------------------------------------------------------------
// Event Handling
@@ -3464,6 +3476,7 @@ protected:
lldb::thread_t m_private_state_thread; // Thread ID for the thread that watches interal state events
ProcessModID m_mod_id; ///< Tracks the state of the process over stops and other alterations.
uint32_t m_thread_index_id; ///< Each thread is created with a 1 based index that won't get re-used.
+ std::map<uint64_t, uint32_t> m_thread_id_to_index_id_map;
int m_exit_status; ///< The exit status of the process, or -1 if not set.
std::string m_exit_string; ///< A textual description of why a process exited.
ThreadList m_thread_list; ///< The threads for this process.
diff --git a/lldb/include/lldb/Target/ThreadList.h b/lldb/include/lldb/Target/ThreadList.h
index 85c68633de6..345cefd008a 100644
--- a/lldb/include/lldb/Target/ThreadList.h
+++ b/lldb/include/lldb/Target/ThreadList.h
@@ -75,6 +75,9 @@ public:
FindThreadByID (lldb::tid_t tid, bool can_update = true);
lldb::ThreadSP
+ RemoveThreadByID (lldb::tid_t tid, bool can_update = true);
+
+ lldb::ThreadSP
FindThreadByIndexID (uint32_t index_id, bool can_update = true);
lldb::ThreadSP
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index b00c4c95a56..a87b64c8c4d 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -1377,18 +1377,32 @@ ProcessGDBRemote::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new
num_thread_ids = m_thread_ids.size();
}
+ ThreadList old_thread_list_copy(old_thread_list);
if (num_thread_ids > 0)
{
for (size_t i=0; i<num_thread_ids; ++i)
{
tid_t tid = m_thread_ids[i];
- ThreadSP thread_sp (old_thread_list.FindThreadByID (tid, false));
+ ThreadSP thread_sp (old_thread_list_copy.RemoveThreadByID (tid, false));
if (!thread_sp)
thread_sp.reset (new ThreadGDBRemote (*this, tid));
new_thread_list.AddThread(thread_sp);
}
}
-
+
+ // Whatever that is left in old_thread_list_copy are not
+ // present in new_thread_list. Remove non-existent threads from internal id table.
+ size_t old_num_thread_ids = old_thread_list_copy.GetSize(false);
+ for (size_t i=0; i<old_num_thread_ids; i++)
+ {
+ ThreadSP old_thread_sp(old_thread_list_copy.GetThreadAtIndex (i, false));
+ if (old_thread_sp)
+ {
+ lldb::tid_t old_thread_id = old_thread_sp->GetID();
+ m_thread_id_to_index_id_map.erase(old_thread_id);
+ }
+ }
+
return true;
}
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index aac93851596..6ea3f01a6d4 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -937,6 +937,7 @@ Process::Process(Target &target, Listener &listener) :
m_private_state_thread (LLDB_INVALID_HOST_THREAD),
m_mod_id (),
m_thread_index_id (0),
+ m_thread_id_to_index_id_map (),
m_exit_status (-1),
m_exit_string (),
m_thread_list (this),
@@ -1460,12 +1461,51 @@ Process::UpdateThreadListIfNeeded ()
}
}
+// This is obsoleted. Staged removal for Xcode.
uint32_t
Process::GetNextThreadIndexID ()
{
return ++m_thread_index_id;
}
+uint32_t
+Process::GetNextThreadIndexID (uint64_t thread_id)
+{
+ return AssignIndexIDToThread(thread_id);
+}
+
+bool
+Process::HasAssignedIndexIDToThread(uint64_t thread_id)
+{
+ std::map<uint64_t, uint32_t>::iterator iterator = m_thread_id_to_index_id_map.find(thread_id);
+ if (iterator == m_thread_id_to_index_id_map.end())
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+}
+
+uint32_t
+Process::AssignIndexIDToThread(uint64_t thread_id)
+{
+ uint32_t result = 0;
+ std::map<uint64_t, uint32_t>::iterator iterator = m_thread_id_to_index_id_map.find(thread_id);
+ if (iterator == m_thread_id_to_index_id_map.end())
+ {
+ result = ++m_thread_index_id;
+ m_thread_id_to_index_id_map[thread_id] = result;
+ }
+ else
+ {
+ result = iterator->second;
+ }
+
+ return result;
+}
+
StateType
Process::GetState()
{
diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp
index 4750a4dc910..3137cf56413 100644
--- a/lldb/source/Target/Thread.cpp
+++ b/lldb/source/Target/Thread.cpp
@@ -243,7 +243,7 @@ Thread::Thread (Process &process, lldb::tid_t tid) :
Broadcaster(&process.GetTarget().GetDebugger(), Thread::GetStaticBroadcasterClass().AsCString()),
m_process_wp (process.shared_from_this()),
m_actual_stop_info_sp (),
- m_index_id (process.GetNextThreadIndexID ()),
+ m_index_id (process.GetNextThreadIndexID(tid)),
m_reg_context_sp (),
m_state (eStateUnloaded),
m_state_mutex (Mutex::eMutexTypeRecursive),
@@ -258,7 +258,6 @@ Thread::Thread (Process &process, lldb::tid_t tid) :
m_unwinder_ap (),
m_destroy_called (false),
m_thread_stop_reason_stop_id (0)
-
{
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
if (log)
diff --git a/lldb/source/Target/ThreadList.cpp b/lldb/source/Target/ThreadList.cpp
index 9ce772e5a36..99fb7cd070b 100644
--- a/lldb/source/Target/ThreadList.cpp
+++ b/lldb/source/Target/ThreadList.cpp
@@ -128,6 +128,29 @@ ThreadList::FindThreadByID (lldb::tid_t tid, bool can_update)
}
ThreadSP
+ThreadList::RemoveThreadByID (lldb::tid_t tid, bool can_update)
+{
+ Mutex::Locker locker(m_threads_mutex);
+
+ if (can_update)
+ m_process->UpdateThreadListIfNeeded();
+
+ ThreadSP thread_sp;
+ uint32_t idx = 0;
+ const uint32_t num_threads = m_threads.size();
+ for (idx = 0; idx < num_threads; ++idx)
+ {
+ if (m_threads[idx]->GetID() == tid)
+ {
+ thread_sp = m_threads[idx];
+ m_threads.erase(m_threads.begin()+idx);
+ break;
+ }
+ }
+ return thread_sp;
+}
+
+ThreadSP
ThreadList::GetThreadSPForThreadPtr (Thread *thread_ptr)
{
ThreadSP thread_sp;
OpenPOWER on IntegriCloud