Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Plugins / Process / Utility / ThreadMemory.cpp
blob89ecc757a68f56f87714d6625da30523491c5b6d
1 //===-- ThreadMemory.cpp --------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "Plugins/Process/Utility/ThreadMemory.h"
11 #include "Plugins/Process/Utility/RegisterContextThreadMemory.h"
12 #include "lldb/Target/OperatingSystem.h"
13 #include "lldb/Target/Process.h"
14 #include "lldb/Target/RegisterContext.h"
15 #include "lldb/Target/StopInfo.h"
16 #include "lldb/Target/Unwind.h"
18 #include <memory>
20 using namespace lldb;
21 using namespace lldb_private;
23 ThreadMemory::ThreadMemory(Process &process, tid_t tid,
24 const ValueObjectSP &thread_info_valobj_sp)
25 : Thread(process, tid), m_backing_thread_sp(),
26 m_thread_info_valobj_sp(thread_info_valobj_sp), m_name(), m_queue(),
27 m_register_data_addr(LLDB_INVALID_ADDRESS) {}
29 ThreadMemory::ThreadMemory(Process &process, lldb::tid_t tid,
30 llvm::StringRef name, llvm::StringRef queue,
31 lldb::addr_t register_data_addr)
32 : Thread(process, tid), m_backing_thread_sp(), m_thread_info_valobj_sp(),
33 m_name(std::string(name)), m_queue(std::string(queue)),
34 m_register_data_addr(register_data_addr) {}
36 ThreadMemory::~ThreadMemory() { DestroyThread(); }
38 void ThreadMemory::WillResume(StateType resume_state) {
39 if (m_backing_thread_sp)
40 m_backing_thread_sp->WillResume(resume_state);
43 void ThreadMemory::ClearStackFrames() {
44 if (m_backing_thread_sp)
45 m_backing_thread_sp->ClearStackFrames();
46 Thread::ClearStackFrames();
49 RegisterContextSP ThreadMemory::GetRegisterContext() {
50 if (!m_reg_context_sp)
51 m_reg_context_sp = std::make_shared<RegisterContextThreadMemory>(
52 *this, m_register_data_addr);
53 return m_reg_context_sp;
56 RegisterContextSP
57 ThreadMemory::CreateRegisterContextForFrame(StackFrame *frame) {
58 uint32_t concrete_frame_idx = 0;
60 if (frame)
61 concrete_frame_idx = frame->GetConcreteFrameIndex();
63 if (concrete_frame_idx == 0)
64 return GetRegisterContext();
65 return GetUnwinder().CreateRegisterContextForFrame(frame);
68 bool ThreadMemory::CalculateStopInfo() {
69 if (m_backing_thread_sp) {
70 lldb::StopInfoSP backing_stop_info_sp(
71 m_backing_thread_sp->GetPrivateStopInfo());
72 if (backing_stop_info_sp &&
73 backing_stop_info_sp->IsValidForOperatingSystemThread(*this)) {
74 backing_stop_info_sp->SetThread(shared_from_this());
75 SetStopInfo(backing_stop_info_sp);
76 return true;
78 } else {
79 ProcessSP process_sp(GetProcess());
81 if (process_sp) {
82 OperatingSystem *os = process_sp->GetOperatingSystem();
83 if (os) {
84 SetStopInfo(os->CreateThreadStopReason(this));
85 return true;
89 return false;
92 void ThreadMemory::RefreshStateAfterStop() {
93 if (m_backing_thread_sp)
94 return m_backing_thread_sp->RefreshStateAfterStop();
96 if (m_reg_context_sp)
97 m_reg_context_sp->InvalidateAllRegisters();