LLDB  mainline
ThreadMemory.cpp
Go to the documentation of this file.
1 //===-- ThreadMemory.cpp ----------------------------------------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
11 
14 #include "lldb/Target/Process.h"
16 #include "lldb/Target/StopInfo.h"
17 #include "lldb/Target/Unwind.h"
18 
19 #include <memory>
20 
21 using namespace lldb;
22 using namespace lldb_private;
23 
25  const ValueObjectSP &thread_info_valobj_sp)
26  : Thread(process, tid), m_backing_thread_sp(),
27  m_thread_info_valobj_sp(thread_info_valobj_sp), m_name(), m_queue() {}
28 
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(name), m_queue(queue), m_register_data_addr(register_data_addr) {}
34 
36 
37 void ThreadMemory::WillResume(StateType resume_state) {
39  m_backing_thread_sp->WillResume(resume_state);
40 }
41 
44  m_backing_thread_sp->ClearStackFrames();
45  Thread::ClearStackFrames();
46 }
47 
48 RegisterContextSP ThreadMemory::GetRegisterContext() {
49  if (!m_reg_context_sp)
50  m_reg_context_sp = std::make_shared<RegisterContextThreadMemory>(
51  *this, m_register_data_addr);
52  return m_reg_context_sp;
53 }
54 
55 RegisterContextSP
57  RegisterContextSP reg_ctx_sp;
58  uint32_t concrete_frame_idx = 0;
59 
60  if (frame)
61  concrete_frame_idx = frame->GetConcreteFrameIndex();
62 
63  if (concrete_frame_idx == 0) {
64  reg_ctx_sp = GetRegisterContext();
65  } else {
66  Unwind *unwinder = GetUnwinder();
67  if (unwinder != nullptr)
68  reg_ctx_sp = unwinder->CreateRegisterContextForFrame(frame);
69  }
70  return reg_ctx_sp;
71 }
72 
74  if (m_backing_thread_sp) {
75  lldb::StopInfoSP backing_stop_info_sp(
76  m_backing_thread_sp->GetPrivateStopInfo());
77  if (backing_stop_info_sp &&
78  backing_stop_info_sp->IsValidForOperatingSystemThread(*this)) {
79  backing_stop_info_sp->SetThread(shared_from_this());
80  SetStopInfo(backing_stop_info_sp);
81  return true;
82  }
83  } else {
84  ProcessSP process_sp(GetProcess());
85 
86  if (process_sp) {
87  OperatingSystem *os = process_sp->GetOperatingSystem();
88  if (os) {
90  return true;
91  }
92  }
93  }
94  return false;
95 }
96 
99  return m_backing_thread_sp->RefreshStateAfterStop();
100 
101  if (m_reg_context_sp)
102  m_reg_context_sp->InvalidateAllRegisters();
103 }
ThreadMemory(lldb_private::Process &process, lldb::tid_t tid, const lldb::ValueObjectSP &thread_info_valobj_sp)
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
virtual lldb::StopInfoSP CreateThreadStopReason(Thread *thread)=0
lldb::RegisterContextSP m_reg_context_sp
The register context for this thread&#39;s current register state.
Definition: Thread.h:1220
A plug-in interface definition class for halted OS helpers.
lldb::ThreadSP m_backing_thread_sp
Definition: ThreadMemory.h:96
virtual lldb_private::Unwind * GetUnwinder()
Definition: Thread.cpp:2056
lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame)
Definition: Unwind.h:55
void WillResume(lldb::StateType resume_state) override
void SetStopInfo(const lldb::StopInfoSP &stop_info_sp)
Definition: Thread.cpp:477
void ClearStackFrames() override
uint64_t tid_t
Definition: lldb-types.h:86
A plug-in interface definition class for debugging a process.
Definition: Process.h:353
virtual void DestroyThread()
Definition: Thread.cpp:278
lldb::ProcessSP GetProcess() const
Definition: Thread.h:154
uint64_t addr_t
Definition: lldb-types.h:83
lldb::RegisterContextSP GetRegisterContext() override
lldb::RegisterContextSP CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override
Definition: SBAddress.h:15
uint32_t GetConcreteFrameIndex() const
Query this frame to find what frame it is in this Thread&#39;s StackFrameList, not counting inlined frame...
Definition: StackFrame.h:389
This base class provides an interface to stack frames.
Definition: StackFrame.h:40
bool CalculateStopInfo() override
lldb::addr_t m_register_data_addr
Definition: ThreadMemory.h:100
~ThreadMemory() override
void RefreshStateAfterStop() override