mib created this revision. mib added a reviewer: JDevlieghere. mib added a project: LLDB. Herald added a subscriber: arphaman. mib requested review of this revision. Herald added a subscriber: lldb-commits.
This patch adds a new method to the Scripted Process Interface to fetch the index to the thread that should be selected in the Scripted Process. This can be very helpful to ensure lldb will stop with the right thread selected by the user in the script. Signed-off-by: Med Ismail Bennani <medismail.benn...@gmail.com> Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D118482 Files: lldb/examples/python/scripted_process/scripted_process.py lldb/include/lldb/Interpreter/ScriptedProcessInterface.h lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py
Index: lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py =================================================================== --- lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py +++ lldb/test/API/functionalities/scripted_process/stack_core_scripted_process.py @@ -57,6 +57,9 @@ return data + def get_selected_thread_index(self): + return 3 + def get_loaded_images(self): # TODO: Iterate over corefile_target modules and build a data structure # from it. Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h +++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.h @@ -44,6 +44,8 @@ StructuredData::DictionarySP GetThreadWithID(lldb::tid_t tid) override; + uint32_t GetSelectedThreadIndex() override; + StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) override; lldb::DataExtractorSP ReadMemoryAtAddress(lldb::addr_t address, size_t size, Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp +++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptedProcessPythonInterface.cpp @@ -113,6 +113,21 @@ return dict; } +uint32_t ScriptedProcessPythonInterface::GetSelectedThreadIndex() { + Status error; + StructuredData::ObjectSP obj = Dispatch("get_selected_thread_index", error); + + if (!CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, error)) + return LLDB_INVALID_INDEX32; + + uint64_t val = obj->GetIntegerValue(LLDB_INVALID_INDEX32); + + if (std::numeric_limits<uint32_t>::max() <= val) + return LLDB_INVALID_INDEX32; + + return static_cast<uint32_t>(val); +} + StructuredData::DictionarySP ScriptedProcessPythonInterface::GetRegistersForThread(lldb::tid_t tid) { // TODO: Implement Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp =================================================================== --- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp +++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp @@ -359,6 +359,11 @@ void ScriptedProcess::RefreshStateAfterStop() { // Let all threads recover from stopping and do any clean up based on the // previous thread state (if any). + uint32_t selected_thread_index = GetInterface().GetSelectedThreadIndex(); + + if (selected_thread_index != LLDB_INVALID_INDEX32 && + selected_thread_index <= m_thread_list.GetSize()) + m_thread_list.SetSelectedThreadByIndexID(selected_thread_index); } bool ScriptedProcess::GetProcessInfo(ProcessInstanceInfo &info) { Index: lldb/include/lldb/Interpreter/ScriptedProcessInterface.h =================================================================== --- lldb/include/lldb/Interpreter/ScriptedProcessInterface.h +++ lldb/include/lldb/Interpreter/ScriptedProcessInterface.h @@ -48,6 +48,8 @@ return nullptr; } + virtual uint32_t GetSelectedThreadIndex() { return LLDB_INVALID_INDEX32; } + virtual StructuredData::DictionarySP GetRegistersForThread(lldb::tid_t tid) { return nullptr; } Index: lldb/examples/python/scripted_process/scripted_process.py =================================================================== --- lldb/examples/python/scripted_process/scripted_process.py +++ lldb/examples/python/scripted_process/scripted_process.py @@ -76,6 +76,15 @@ """ pass + def get_selected_thread_index(self): + """ Get the index of the selected scripted process thread. + + Returns: + Int: The thread index that should be selected by lldb. + (default: 1) + """ + return 1 + @abstractmethod def get_registers_for_thread(self, tid): """ Get the register context dictionary for a certain thread of
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits