Make ThreadList::GetSelectedThread() select and return the 0th thread if there's no
currently selected thread. And update the call sites accordingly.
llvm-svn: 138577
diff --git a/lldb/include/lldb/Target/ThreadList.h b/lldb/include/lldb/Target/ThreadList.h
index fbc0505..4740f23 100644
--- a/lldb/include/lldb/Target/ThreadList.h
+++ b/lldb/include/lldb/Target/ThreadList.h
@@ -45,6 +45,8 @@
void
AddThread (lldb::ThreadSP &thread_sp);
+ // Return the selected thread if there is one. Otherwise, return the thread
+ // selected at index 0.
lldb::ThreadSP
GetSelectedThread ();
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 875466c..c361dfc 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -346,8 +346,6 @@
if (exe_ctx.process && exe_ctx.process->IsRunning() == false)
{
exe_ctx.thread = exe_ctx.process->GetThreadList().GetSelectedThread().get();
- if (exe_ctx.thread == NULL)
- exe_ctx.thread = exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
if (exe_ctx.thread)
{
exe_ctx.frame = exe_ctx.thread->GetSelectedFrame().get();
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index f403d04..4202472 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -2230,13 +2230,6 @@
if (m_exe_ctx.process && m_exe_ctx.process->IsAlive() && !m_exe_ctx.process->IsRunning())
{
m_exe_ctx.thread = m_exe_ctx.process->GetThreadList().GetSelectedThread().get();
- if (m_exe_ctx.thread == NULL)
- {
- m_exe_ctx.thread = m_exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
- // If we didn't have a selected thread, select one here.
- if (m_exe_ctx.thread != NULL)
- m_exe_ctx.process->GetThreadList().SetSelectedThreadByID(m_exe_ctx.thread->GetID());
- }
if (m_exe_ctx.thread)
{
m_exe_ctx.frame = m_exe_ctx.thread->GetSelectedFrame().get();
diff --git a/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp b/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
index 6bb9f70..2354d91 100644
--- a/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
+++ b/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
@@ -26,8 +26,6 @@
unsigned flags, addr_t fd, addr_t offset) {
Thread *thread = process->GetThreadList().GetSelectedThread().get();
if (thread == NULL)
- thread = process->GetThreadList().GetThreadAtIndex(0).get();
- if (thread == NULL)
return false;
const bool append = true;
@@ -129,7 +127,7 @@
addr_t length) {
Thread *thread = process->GetThreadList().GetSelectedThread().get();
if (thread == NULL)
- thread = process->GetThreadList().GetThreadAtIndex(0).get();
+ return false;
const bool append = true;
const bool include_symbols = true;
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 3119c32..8f57d1c 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -1138,8 +1138,6 @@
if (error.Success())
{
ThreadSP thread_sp(GetThreadList ().GetSelectedThread());
- if (thread_sp == NULL)
- thread_sp = GetThreadList ().GetThreadAtIndex(0, true);
if (thread_sp)
{
@@ -1205,8 +1203,6 @@
if (error.Success())
{
ThreadSP thread_sp(GetThreadList ().GetSelectedThread());
- if (thread_sp == NULL)
- thread_sp = GetThreadList ().GetThreadAtIndex(0, true);
if (thread_sp)
{
diff --git a/lldb/source/Target/ThreadList.cpp b/lldb/source/Target/ThreadList.cpp
index ac0797d..2b5a10d 100644
--- a/lldb/source/Target/ThreadList.cpp
+++ b/lldb/source/Target/ThreadList.cpp
@@ -545,6 +545,8 @@
ThreadList::GetSelectedThread ()
{
Mutex::Locker locker(m_threads_mutex);
+ if (m_selected_tid == LLDB_INVALID_THREAD_ID)
+ SetSelectedThreadByID(m_threads[0]->GetID());
return FindThreadByID(m_selected_tid);
}