From 45148bfe8aece6ca319dcc32351e20bba26b2ea7 Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Tue, 18 Jan 2022 12:52:24 +0100 Subject: [lldb/Plugins] Fix ScriptedThread IndexID reporting When listing all the Scripted Threads of a ScriptedProcess, we can see that all have the thread index set to 1. This is caused by the lldb_private::Thread constructor, which sets the m_index_id member using the provided thread id `tid`. Because the call to the super constructor is done before instantiating the `ScriptedThreadInterface`, lldb can't fetch the thread id from the script instance, so it uses `LLDB_INVALID_THREAD_ID` instead. To mitigate this, this patch takes advantage of the `ScriptedThread::Create` fallible constructor idiom to defer calling the `ScriptedThread` constructor (and the `Thread` super constructor with it), until we can fetch a valid thread id `tid` from the `ScriptedThreadInterface`. rdar://87432065 Differential Revision: https://reviews.llvm.org/D117076 Signed-off-by: Med Ismail Bennani --- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp') diff --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp index e28658e33cda..e71a0fdf8de9 100644 --- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp +++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp @@ -328,12 +328,14 @@ bool ScriptedProcess::DoUpdateThreadList(ThreadList &old_thread_list, return true; } - lldb::ThreadSP thread_sp = - std::make_shared(*this, error, val->GetAsGeneric()); + auto thread_or_error = ScriptedThread::Create(*this, val->GetAsGeneric()); - if (!thread_sp || error.Fail()) - return GetInterface().ErrorWithMessage(LLVM_PRETTY_FUNCTION, - error.AsCString(), error); + if (!thread_or_error) + return GetInterface().ErrorWithMessage( + LLVM_PRETTY_FUNCTION, toString(thread_or_error.takeError()), error); + + ThreadSP thread_sp = thread_or_error.get(); + lldbassert(thread_sp && "Couldn't initialize scripted thread."); RegisterContextSP reg_ctx_sp = thread_sp->GetRegisterContext(); if (!reg_ctx_sp) -- cgit v1.2.3