LLDB  mainline
ThreadMachCore.cpp
Go to the documentation of this file.
1 //===-- ThreadMachCore.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 
9 #include "ThreadMachCore.h"
10 
12 #include "lldb/Symbol/ObjectFile.h"
13 #include "lldb/Target/Process.h"
15 #include "lldb/Target/StopInfo.h"
16 #include "lldb/Target/Target.h"
17 #include "lldb/Target/Unwind.h"
18 #include "lldb/Utility/ArchSpec.h"
20 #include "lldb/Utility/State.h"
22 
23 #include "ProcessMachCore.h"
24 //#include "RegisterContextKDP_arm.h"
25 //#include "RegisterContextKDP_i386.h"
26 //#include "RegisterContextKDP_x86_64.h"
27 
28 using namespace lldb;
29 using namespace lldb_private;
30 
31 // Thread Registers
32 
34  : Thread(process, tid), m_thread_name(), m_dispatch_queue_name(),
35  m_thread_dispatch_qaddr(LLDB_INVALID_ADDRESS), m_thread_reg_ctx_sp() {}
36 
38 
39 const char *ThreadMachCore::GetName() {
40  if (m_thread_name.empty())
41  return nullptr;
42  return m_thread_name.c_str();
43 }
44 
46  // Invalidate all registers in our register context. We don't set "force" to
47  // true because the stop reply packet might have had some register values
48  // that were expedited and these will already be copied into the register
49  // context by the time this function gets called. The KDPRegisterContext
50  // class has been made smart enough to detect when it needs to invalidate
51  // which registers are valid by putting hooks in the register read and
52  // register supply functions where they check the process stop ID and do the
53  // right thing.
54  const bool force = false;
55  GetRegisterContext()->InvalidateIfNeeded(force);
56 }
57 
58 bool ThreadMachCore::ThreadIDIsValid(lldb::tid_t thread) { return thread != 0; }
59 
60 lldb::RegisterContextSP ThreadMachCore::GetRegisterContext() {
61  if (!m_reg_context_sp)
63  return m_reg_context_sp;
64 }
65 
66 lldb::RegisterContextSP
68  lldb::RegisterContextSP reg_ctx_sp;
69  uint32_t concrete_frame_idx = 0;
70 
71  if (frame)
72  concrete_frame_idx = frame->GetConcreteFrameIndex();
73 
74  if (concrete_frame_idx == 0) {
75  if (!m_thread_reg_ctx_sp) {
76  ProcessSP process_sp(GetProcess());
77 
78  ObjectFile *core_objfile =
79  static_cast<ProcessMachCore *>(process_sp.get())->GetCoreObjectFile();
80  if (core_objfile)
82  core_objfile->GetThreadContextAtIndex(GetID(), *this);
83  }
84  reg_ctx_sp = m_thread_reg_ctx_sp;
85  } else {
86  reg_ctx_sp = GetUnwinder().CreateRegisterContextForFrame(frame);
87  }
88  return reg_ctx_sp;
89 }
90 
92  ProcessSP process_sp(GetProcess());
93  if (process_sp) {
94  SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, SIGSTOP));
95  return true;
96  }
97  return false;
98 }
A class that represents a running process on the host machine.
bool CalculateStopInfo() override
static bool ThreadIDIsValid(lldb::tid_t thread)
ThreadMachCore(lldb_private::Process &process, lldb::tid_t tid)
lldb::RegisterContextSP m_thread_reg_ctx_sp
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47
virtual Unwind & GetUnwinder()
Definition: Thread.cpp:1860
A plug-in interface definition class for object file parsers.
Definition: ObjectFile.h:58
lldb::RegisterContextSP m_reg_context_sp
The register context for this thread&#39;s current register state.
Definition: Thread.h:1229
#define SIGSTOP
std::string m_thread_name
lldb::RegisterContextSP CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override
lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame)
Definition: Unwind.h:56
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
void SetStopInfo(const lldb::StopInfoSP &stop_info_sp)
Definition: Thread.cpp:440
lldb::RegisterContextSP GetRegisterContext() override
uint64_t tid_t
Definition: lldb-types.h:86
A plug-in interface definition class for debugging a process.
Definition: Process.h:362
virtual void DestroyThread()
Definition: Thread.cpp:254
lldb::ProcessSP GetProcess() const
Definition: Thread.h:153
virtual lldb::RegisterContextSP GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread)
Definition: ObjectFile.h:512
~ThreadMachCore() override
Definition: SBAddress.h:15
void RefreshStateAfterStop() override
const char * GetName() override
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