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
14 #include "Plugins/Process/Utility/RegisterContextFreeBSD_i386.h"
15 #include "Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.h"
16 #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h"
17 #include "ProcessFreeBSDKernel.h"
18 #include "RegisterContextFreeBSDKernel_arm64.h"
19 #include "RegisterContextFreeBSDKernel_i386.h"
20 #include "RegisterContextFreeBSDKernel_x86_64.h"
21 #include "ThreadFreeBSDKernel.h"
22
23 using namespace lldb;
24 using namespace lldb_private;
25
ThreadFreeBSDKernel(Process & process,lldb::tid_t tid,lldb::addr_t pcb_addr,std::string thread_name)26 ThreadFreeBSDKernel::ThreadFreeBSDKernel(Process &process, lldb::tid_t tid,
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
~ThreadFreeBSDKernel()32 ThreadFreeBSDKernel::~ThreadFreeBSDKernel() {}
33
RefreshStateAfterStop()34 void ThreadFreeBSDKernel::RefreshStateAfterStop() {}
35
GetRegisterContext()36 lldb::RegisterContextSP ThreadFreeBSDKernel::GetRegisterContext() {
37 if (!m_reg_context_sp)
38 m_reg_context_sp = CreateRegisterContextForFrame(nullptr);
39 return m_reg_context_sp;
40 }
41
42 lldb::RegisterContextSP
CreateRegisterContextForFrame(StackFrame * frame)43 ThreadFreeBSDKernel::CreateRegisterContextForFrame(StackFrame *frame) {
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) {
51 if (m_thread_reg_ctx_sp)
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:
60 m_thread_reg_ctx_sp =
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:
70 m_thread_reg_ctx_sp =
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
CalculateStopInfo()86 bool ThreadFreeBSDKernel::CalculateStopInfo() { return false; }
87