1 //===-- ThreadFreeBSDKernel.cpp -------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "ThreadFreeBSDKernel.h"
11 #include "lldb/Target/Unwind.h"
12 #include "lldb/Utility/Log.h"
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"
24 using namespace lldb_private
;
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
) {}
32 ThreadFreeBSDKernel::~ThreadFreeBSDKernel() {}
34 void ThreadFreeBSDKernel::RefreshStateAfterStop() {}
36 lldb::RegisterContextSP
ThreadFreeBSDKernel::GetRegisterContext() {
37 if (!m_reg_context_sp
)
38 m_reg_context_sp
= CreateRegisterContextForFrame(nullptr);
39 return m_reg_context_sp
;
42 lldb::RegisterContextSP
43 ThreadFreeBSDKernel::CreateRegisterContextForFrame(StackFrame
*frame
) {
44 RegisterContextSP reg_ctx_sp
;
45 uint32_t concrete_frame_idx
= 0;
48 concrete_frame_idx
= frame
->GetConcreteFrameIndex();
50 if (concrete_frame_idx
== 0) {
51 if (m_thread_reg_ctx_sp
)
52 return m_thread_reg_ctx_sp
;
54 ProcessFreeBSDKernel
*process
=
55 static_cast<ProcessFreeBSDKernel
*>(GetProcess().get());
56 ArchSpec arch
= process
->GetTarget().GetArchitecture();
58 switch (arch
.GetMachine()) {
59 case llvm::Triple::aarch64
:
61 std::make_shared
<RegisterContextFreeBSDKernel_arm64
>(
62 *this, std::make_unique
<RegisterInfoPOSIX_arm64
>(arch
, 0),
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
);
69 case llvm::Triple::x86_64
:
71 std::make_shared
<RegisterContextFreeBSDKernel_x86_64
>(
72 *this, new RegisterContextFreeBSD_x86_64(arch
), m_pcb_addr
);
75 assert(false && "Unsupported architecture passed to ThreadFreeBSDKernel");
79 reg_ctx_sp
= m_thread_reg_ctx_sp
;
81 reg_ctx_sp
= GetUnwinder().CreateRegisterContextForFrame(frame
);
86 bool ThreadFreeBSDKernel::CalculateStopInfo() { return false; }