LLDB  mainline
ThreadFreeBSDKernel.cpp
Go to the documentation of this file.
1 //===-- ThreadFreeBSDKernel.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 "ThreadFreeBSDKernel.h"
10 
11 #include "lldb/Target/Unwind.h"
12 #include "lldb/Utility/Log.h"
13 
17 #include "ProcessFreeBSDKernel.h"
21 #include "ThreadFreeBSDKernel.h"
22 
23 using namespace lldb;
24 using namespace lldb_private;
25 
27  lldb::addr_t pcb_addr,
28  std::string thread_name)
29  : Thread(process, tid), m_thread_name(std::move(thread_name)),
30  m_pcb_addr(pcb_addr) {}
31 
33 
35 
36 lldb::RegisterContextSP ThreadFreeBSDKernel::GetRegisterContext() {
37  if (!m_reg_context_sp)
39  return m_reg_context_sp;
40 }
41 
42 lldb::RegisterContextSP
44  RegisterContextSP reg_ctx_sp;
45  uint32_t concrete_frame_idx = 0;
46 
47  if (frame)
48  concrete_frame_idx = frame->GetConcreteFrameIndex();
49 
50  if (concrete_frame_idx == 0) {
52  return m_thread_reg_ctx_sp;
53 
54  ProcessFreeBSDKernel *process =
55  static_cast<ProcessFreeBSDKernel *>(GetProcess().get());
56  ArchSpec arch = process->GetTarget().GetArchitecture();
57 
58  switch (arch.GetMachine()) {
59  case llvm::Triple::aarch64:
61  std::make_shared<RegisterContextFreeBSDKernel_arm64>(
62  *this, std::make_unique<RegisterInfoPOSIX_arm64>(arch, 0),
63  m_pcb_addr);
64  break;
65  case llvm::Triple::x86:
66  m_thread_reg_ctx_sp = std::make_shared<RegisterContextFreeBSDKernel_i386>(
67  *this, new RegisterContextFreeBSD_i386(arch), m_pcb_addr);
68  break;
69  case llvm::Triple::x86_64:
71  std::make_shared<RegisterContextFreeBSDKernel_x86_64>(
72  *this, new RegisterContextFreeBSD_x86_64(arch), m_pcb_addr);
73  break;
74  default:
75  assert(false && "Unsupported architecture passed to ThreadFreeBSDKernel");
76  break;
77  }
78 
79  reg_ctx_sp = m_thread_reg_ctx_sp;
80  } else {
81  reg_ctx_sp = GetUnwinder().CreateRegisterContextForFrame(frame);
82  }
83  return reg_ctx_sp;
84 }
85 
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::ArchSpec::GetMachine
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:668
ProcessFreeBSDKernel.h
lldb_private::Thread::GetUnwinder
virtual Unwind & GetUnwinder()
Definition: Thread.cpp:1855
Unwind.h
lldb_private::Process
Definition: Process.h:338
lldb_private::Process::GetTarget
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1206
ThreadFreeBSDKernel::~ThreadFreeBSDKernel
~ThreadFreeBSDKernel() override
Definition: ThreadFreeBSDKernel.cpp:32
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
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
RegisterContextFreeBSDKernel_x86_64.h
lldb_private::Thread::GetProcess
lldb::ProcessSP GetProcess() const
Definition: Thread.h:153
Log.h
lldb_private::Thread
Definition: Thread.h:61
ThreadFreeBSDKernel.h
RegisterContextFreeBSDKernel_arm64.h
ThreadFreeBSDKernel::m_thread_reg_ctx_sp
lldb::RegisterContextSP m_thread_reg_ctx_sp
Definition: ThreadFreeBSDKernel.h:46
RegisterInfoPOSIX_arm64.h
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
ThreadFreeBSDKernel::CreateRegisterContextForFrame
lldb::RegisterContextSP CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override
Definition: ThreadFreeBSDKernel.cpp:43
lldb_private::Unwind::CreateRegisterContextForFrame
lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame)
Definition: Unwind.h:56
RegisterContextFreeBSD_x86_64.h
lldb_private::Target::GetArchitecture
const ArchSpec & GetArchitecture() const
Definition: Target.h:989
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:1259
uint32_t
RegisterContextFreeBSD_i386.h
ThreadFreeBSDKernel::RefreshStateAfterStop
void RefreshStateAfterStop() override
Definition: ThreadFreeBSDKernel.cpp:34
ThreadFreeBSDKernel::GetRegisterContext
lldb::RegisterContextSP GetRegisterContext() override
Definition: ThreadFreeBSDKernel.cpp:36
ThreadFreeBSDKernel::CalculateStopInfo
bool CalculateStopInfo() override
Definition: ThreadFreeBSDKernel.cpp:86
RegisterContextFreeBSDKernel_i386.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
RegisterContextFreeBSD_i386
Definition: RegisterContextFreeBSD_i386.h:14
ProcessFreeBSDKernel
Definition: ProcessFreeBSDKernel.h:14
ThreadFreeBSDKernel::ThreadFreeBSDKernel
ThreadFreeBSDKernel(lldb_private::Process &process, lldb::tid_t tid, lldb::addr_t pcb_addr, std::string thread_name)
Definition: ThreadFreeBSDKernel.cpp:26
lldb_private::StackFrame
Definition: StackFrame.h:40
lldb
Definition: SBAddress.h:15
ThreadFreeBSDKernel::m_pcb_addr
lldb::addr_t m_pcb_addr
Definition: ThreadFreeBSDKernel.h:47
RegisterContextFreeBSD_x86_64
Definition: RegisterContextFreeBSD_x86_64.h:14
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86