mib updated this revision to Diff 381091. mib added a comment. Address @shafik comment.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D112167/new/ https://reviews.llvm.org/D112167 Files: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp lldb/source/Plugins/Process/scripted/ScriptedProcess.h lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
Index: lldb/source/Plugins/Process/scripted/ScriptedThread.cpp =================================================================== --- lldb/source/Plugins/Process/scripted/ScriptedThread.cpp +++ lldb/source/Plugins/Process/scripted/ScriptedThread.cpp @@ -64,32 +64,6 @@ m_script_object_sp = object_sp; SetID(scripted_thread_interface->GetThreadID()); - - llvm::Optional<std::string> reg_data = - scripted_thread_interface->GetRegisterContext(); - if (!reg_data) { - error.SetErrorString("Failed to get scripted thread registers data."); - return; - } - - DataBufferSP data_sp( - std::make_shared<DataBufferHeap>(reg_data->c_str(), reg_data->size())); - - if (!data_sp->GetByteSize()) { - error.SetErrorString("Failed to copy raw registers data."); - return; - } - - std::shared_ptr<RegisterContextMemory> reg_ctx_memory = - std::make_shared<RegisterContextMemory>( - *this, 0, *GetDynamicRegisterInfo(), LLDB_INVALID_ADDRESS); - if (!reg_ctx_memory) { - error.SetErrorString("Failed to create a register context."); - return; - } - - reg_ctx_memory->SetAllRegisterData(data_sp); - m_reg_context_sp = reg_ctx_memory; } ScriptedThread::~ScriptedThread() { DestroyThread(); } @@ -115,11 +89,8 @@ void ScriptedThread::ClearStackFrames() { Thread::ClearStackFrames(); } RegisterContextSP ScriptedThread::GetRegisterContext() { - if (!m_reg_context_sp) { - m_reg_context_sp = std::make_shared<RegisterContextThreadMemory>( - *this, LLDB_INVALID_ADDRESS); - GetInterface()->GetRegisterContext(); - } + if (!m_reg_context_sp) + m_reg_context_sp = CreateRegisterContextForFrame(nullptr); return m_reg_context_sp; } @@ -127,9 +98,38 @@ ScriptedThread::CreateRegisterContextForFrame(StackFrame *frame) { uint32_t concrete_frame_idx = frame ? frame->GetConcreteFrameIndex() : 0; - if (concrete_frame_idx == 0) - return GetRegisterContext(); - return GetUnwinder().CreateRegisterContextForFrame(frame); + if (concrete_frame_idx) + return GetUnwinder().CreateRegisterContextForFrame(frame); + + lldb::RegisterContextSP reg_ctx_sp; + Status error; + + llvm::Optional<std::string> reg_data = GetInterface()->GetRegisterContext(); + if (!reg_data) { + error.SetErrorString("Failed to get scripted thread registers data."); + return nullptr; + } + + DataBufferSP data_sp( + std::make_shared<DataBufferHeap>(reg_data->c_str(), reg_data->size())); + + if (!data_sp->GetByteSize()) { + error.SetErrorString("Failed to copy raw registers data."); + return nullptr; + } + + std::shared_ptr<RegisterContextMemory> reg_ctx_memory = + std::make_shared<RegisterContextMemory>( + *this, 0, *GetDynamicRegisterInfo(), LLDB_INVALID_ADDRESS); + if (!reg_ctx_memory) { + error.SetErrorString("Failed to create a register context."); + return nullptr; + } + + reg_ctx_memory->SetAllRegisterData(data_sp); + m_reg_context_sp = reg_ctx_memory; + + return m_reg_context_sp; } bool ScriptedThread::CalculateStopInfo() { @@ -183,9 +183,7 @@ } void ScriptedThread::RefreshStateAfterStop() { - // TODO: Implement - if (m_reg_context_sp) - m_reg_context_sp->InvalidateAllRegisters(); + GetRegisterContext()->InvalidateIfNeeded(/*force=*/false); } lldb::ScriptedThreadInterfaceSP ScriptedThread::GetInterface() const { Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.h =================================================================== --- lldb/source/Plugins/Process/scripted/ScriptedProcess.h +++ lldb/source/Plugins/Process/scripted/ScriptedProcess.h @@ -78,7 +78,7 @@ Status DoDestroy() override; - void RefreshStateAfterStop() override{}; + void RefreshStateAfterStop() override; bool IsAlive() override; Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp =================================================================== --- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp +++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp @@ -20,7 +20,6 @@ #include "lldb/Interpreter/ScriptInterpreter.h" #include "lldb/Target/MemoryRegionInfo.h" #include "lldb/Target/RegisterContext.h" - #include "lldb/Utility/State.h" #include <mutex> @@ -296,6 +295,7 @@ // actually new threads will get added to new_thread_list. CheckInterpreterAndScriptObject(); + m_thread_plans.ClearThreadCache(); Status error; ScriptLanguage language = m_interpreter->GetLanguage(); @@ -321,6 +321,12 @@ return new_thread_list.GetSize(false) > 0; } +void ScriptedProcess::RefreshStateAfterStop() { + // Let all threads recover from stopping and do any clean up based on the + // previous thread state (if any). + m_thread_list.RefreshStateAfterStop(); +} + bool ScriptedProcess::GetProcessInfo(ProcessInstanceInfo &info) { info.Clear(); info.SetProcessID(GetID());
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits