LLDB  mainline
ThreadMemory.cpp
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
8 
10 
13 #include "lldb/Target/Process.h"
15 #include "lldb/Target/StopInfo.h"
16 #include "lldb/Target/Unwind.h"
17 
18 #include <memory>
19 
20 using namespace lldb;
21 using namespace lldb_private;
22 
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 
29  llvm::StringRef name, llvm::StringRef queue,
30  lldb::addr_t register_data_addr)
31  : Thread(process, tid), m_backing_thread_sp(), m_thread_info_valobj_sp(),
32  m_name(std::string(name)), m_queue(std::string(queue)),
33  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  uint32_t concrete_frame_idx = 0;
58 
59  if (frame)
60  concrete_frame_idx = frame->GetConcreteFrameIndex();
61 
62  if (concrete_frame_idx == 0)
63  return GetRegisterContext();
65 }
66 
68  if (m_backing_thread_sp) {
69  lldb::StopInfoSP backing_stop_info_sp(
70  m_backing_thread_sp->GetPrivateStopInfo());
71  if (backing_stop_info_sp &&
72  backing_stop_info_sp->IsValidForOperatingSystemThread(*this)) {
73  backing_stop_info_sp->SetThread(shared_from_this());
74  SetStopInfo(backing_stop_info_sp);
75  return true;
76  }
77  } else {
78  ProcessSP process_sp(GetProcess());
79 
80  if (process_sp) {
81  OperatingSystem *os = process_sp->GetOperatingSystem();
82  if (os) {
84  return true;
85  }
86  }
87  }
88  return false;
89 }
90 
93  return m_backing_thread_sp->RefreshStateAfterStop();
94 
95  if (m_reg_context_sp)
96  m_reg_context_sp->InvalidateAllRegisters();
97 }
ThreadMemory.h
ThreadMemory::ThreadMemory
ThreadMemory(lldb_private::Process &process, lldb::tid_t tid, const lldb::ValueObjectSP &thread_info_valobj_sp)
lldb_private::Thread::GetUnwinder
virtual Unwind & GetUnwinder()
Definition: Thread.cpp:1861
Unwind.h
lldb_private::OperatingSystem::CreateThreadStopReason
virtual lldb::StopInfoSP CreateThreadStopReason(Thread *thread)=0
lldb_private::Process
Definition: Process.h:341
ThreadMemory::CalculateStopInfo
bool CalculateStopInfo() override
Definition: ThreadMemory.cpp:67
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
ThreadMemory::WillResume
void WillResume(lldb::StateType resume_state) override
Definition: ThreadMemory.cpp:37
Process.h
lldb_private::StackFrame::GetConcreteFrameIndex
uint32_t GetConcreteFrameIndex() const
Query this frame to find what frame it is in this Thread's StackFrameList, not counting inlined frame...
Definition: StackFrame.h:407
lldb_private::Thread::GetProcess
lldb::ProcessSP GetProcess() const
Definition: Thread.h:152
lldb_private::Thread::DestroyThread
virtual void DestroyThread()
Definition: Thread.cpp:247
lldb_private::Thread
Definition: Thread.h:60
OperatingSystem.h
ThreadMemory::RefreshStateAfterStop
void RefreshStateAfterStop() override
Definition: ThreadMemory.cpp:91
lldb_private::Thread::SetStopInfo
void SetStopInfo(const lldb::StopInfoSP &stop_info_sp)
Definition: Thread.cpp:433
lldb_private::OperatingSystem
Definition: OperatingSystem.h:27
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::Unwind::CreateRegisterContextForFrame
lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame)
Definition: Unwind.h:56
ThreadMemory::m_backing_thread_sp
lldb::ThreadSP m_backing_thread_sp
Definition: ThreadMemory.h:96
ThreadMemory::CreateRegisterContextForFrame
lldb::RegisterContextSP CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override
Definition: ThreadMemory.cpp:56
lldb_private::Thread::m_reg_context_sp
lldb::RegisterContextSP m_reg_context_sp
The register context for this thread's current register state.
Definition: Thread.h:1247
uint32_t
ThreadMemory::GetRegisterContext
lldb::RegisterContextSP GetRegisterContext() override
Definition: ThreadMemory.cpp:48
StopInfo.h
ThreadMemory::m_register_data_addr
lldb::addr_t m_register_data_addr
Definition: ThreadMemory.h:100
RegisterContextThreadMemory.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::StateType
StateType
Process and Thread States.
Definition: lldb-enumerations.h:73
ThreadMemory::ClearStackFrames
void ClearStackFrames() override
Definition: ThreadMemory.cpp:42
lldb_private::StackFrame
Definition: StackFrame.h:40
lldb
Definition: SBAddress.h:15
RegisterContext.h
ThreadMemory::~ThreadMemory
~ThreadMemory() override
Definition: ThreadMemory.cpp:35
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86