xref: /freebsd-src/contrib/llvm-project/lldb/source/Plugins/Process/FreeBSDKernel/ThreadFreeBSDKernel.cpp (revision 0eae32dcef82f6f06de6419a0d623d7def0cc8f6)
1*0eae32dcSDimitry Andric //===-- ThreadFreeBSDKernel.cpp -------------------------------------------===//
2*0eae32dcSDimitry Andric //
3*0eae32dcSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0eae32dcSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0eae32dcSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0eae32dcSDimitry Andric //
7*0eae32dcSDimitry Andric //===----------------------------------------------------------------------===//
8*0eae32dcSDimitry Andric 
9*0eae32dcSDimitry Andric #include "ThreadFreeBSDKernel.h"
10*0eae32dcSDimitry Andric 
11*0eae32dcSDimitry Andric #include "lldb/Target/Unwind.h"
12*0eae32dcSDimitry Andric #include "lldb/Utility/Log.h"
13*0eae32dcSDimitry Andric 
14*0eae32dcSDimitry Andric #include "Plugins/Process/Utility/RegisterContextFreeBSD_i386.h"
15*0eae32dcSDimitry Andric #include "Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.h"
16*0eae32dcSDimitry Andric #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h"
17*0eae32dcSDimitry Andric #include "ProcessFreeBSDKernel.h"
18*0eae32dcSDimitry Andric #include "RegisterContextFreeBSDKernel_arm64.h"
19*0eae32dcSDimitry Andric #include "RegisterContextFreeBSDKernel_i386.h"
20*0eae32dcSDimitry Andric #include "RegisterContextFreeBSDKernel_x86_64.h"
21*0eae32dcSDimitry Andric #include "ThreadFreeBSDKernel.h"
22*0eae32dcSDimitry Andric 
23*0eae32dcSDimitry Andric using namespace lldb;
24*0eae32dcSDimitry Andric using namespace lldb_private;
25*0eae32dcSDimitry Andric 
26*0eae32dcSDimitry Andric ThreadFreeBSDKernel::ThreadFreeBSDKernel(Process &process, lldb::tid_t tid,
27*0eae32dcSDimitry Andric                                          lldb::addr_t pcb_addr)
28*0eae32dcSDimitry Andric     : Thread(process, tid), m_pcb_addr(pcb_addr) {}
29*0eae32dcSDimitry Andric 
30*0eae32dcSDimitry Andric ThreadFreeBSDKernel::~ThreadFreeBSDKernel() {}
31*0eae32dcSDimitry Andric 
32*0eae32dcSDimitry Andric void ThreadFreeBSDKernel::RefreshStateAfterStop() {}
33*0eae32dcSDimitry Andric 
34*0eae32dcSDimitry Andric lldb::RegisterContextSP ThreadFreeBSDKernel::GetRegisterContext() {
35*0eae32dcSDimitry Andric   if (!m_reg_context_sp)
36*0eae32dcSDimitry Andric     m_reg_context_sp = CreateRegisterContextForFrame(nullptr);
37*0eae32dcSDimitry Andric   return m_reg_context_sp;
38*0eae32dcSDimitry Andric }
39*0eae32dcSDimitry Andric 
40*0eae32dcSDimitry Andric lldb::RegisterContextSP
41*0eae32dcSDimitry Andric ThreadFreeBSDKernel::CreateRegisterContextForFrame(StackFrame *frame) {
42*0eae32dcSDimitry Andric   RegisterContextSP reg_ctx_sp;
43*0eae32dcSDimitry Andric   uint32_t concrete_frame_idx = 0;
44*0eae32dcSDimitry Andric 
45*0eae32dcSDimitry Andric   if (frame)
46*0eae32dcSDimitry Andric     concrete_frame_idx = frame->GetConcreteFrameIndex();
47*0eae32dcSDimitry Andric 
48*0eae32dcSDimitry Andric   if (concrete_frame_idx == 0) {
49*0eae32dcSDimitry Andric     if (m_thread_reg_ctx_sp)
50*0eae32dcSDimitry Andric       return m_thread_reg_ctx_sp;
51*0eae32dcSDimitry Andric 
52*0eae32dcSDimitry Andric     ProcessFreeBSDKernel *process =
53*0eae32dcSDimitry Andric         static_cast<ProcessFreeBSDKernel *>(GetProcess().get());
54*0eae32dcSDimitry Andric     ArchSpec arch = process->GetTarget().GetArchitecture();
55*0eae32dcSDimitry Andric 
56*0eae32dcSDimitry Andric     switch (arch.GetMachine()) {
57*0eae32dcSDimitry Andric     case llvm::Triple::aarch64:
58*0eae32dcSDimitry Andric       m_thread_reg_ctx_sp =
59*0eae32dcSDimitry Andric           std::make_shared<RegisterContextFreeBSDKernel_arm64>(
60*0eae32dcSDimitry Andric               *this, std::make_unique<RegisterInfoPOSIX_arm64>(arch, 0),
61*0eae32dcSDimitry Andric               m_pcb_addr);
62*0eae32dcSDimitry Andric       break;
63*0eae32dcSDimitry Andric     case llvm::Triple::x86:
64*0eae32dcSDimitry Andric       m_thread_reg_ctx_sp =
65*0eae32dcSDimitry Andric           std::make_shared<RegisterContextFreeBSDKernel_i386>(
66*0eae32dcSDimitry Andric               *this, new RegisterContextFreeBSD_i386(arch), m_pcb_addr);
67*0eae32dcSDimitry Andric       break;
68*0eae32dcSDimitry Andric     case llvm::Triple::x86_64:
69*0eae32dcSDimitry Andric       m_thread_reg_ctx_sp =
70*0eae32dcSDimitry Andric           std::make_shared<RegisterContextFreeBSDKernel_x86_64>(
71*0eae32dcSDimitry Andric               *this, new RegisterContextFreeBSD_x86_64(arch), m_pcb_addr);
72*0eae32dcSDimitry Andric       break;
73*0eae32dcSDimitry Andric     default:
74*0eae32dcSDimitry Andric       assert(false && "Unsupported architecture passed to ThreadFreeBSDKernel");
75*0eae32dcSDimitry Andric       break;
76*0eae32dcSDimitry Andric     }
77*0eae32dcSDimitry Andric 
78*0eae32dcSDimitry Andric     reg_ctx_sp = m_thread_reg_ctx_sp;
79*0eae32dcSDimitry Andric   } else {
80*0eae32dcSDimitry Andric     reg_ctx_sp = GetUnwinder().CreateRegisterContextForFrame(frame);
81*0eae32dcSDimitry Andric   }
82*0eae32dcSDimitry Andric   return reg_ctx_sp;
83*0eae32dcSDimitry Andric }
84*0eae32dcSDimitry Andric 
85*0eae32dcSDimitry Andric bool ThreadFreeBSDKernel::CalculateStopInfo() { return false; }
86