1 //===-- ThreadOpenBSDKernel.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 "ThreadOpenBSDKernel.h" 10 11 #include "lldb/Target/Unwind.h" 12 #include "lldb/Utility/Log.h" 13 14 #include "Plugins/Process/Utility/RegisterContextOpenBSD_i386.h" 15 #include "Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h" 16 #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h" 17 #include "ProcessOpenBSDKernel.h" 18 #include "RegisterContextOpenBSDKernel_arm64.h" 19 #include "RegisterContextOpenBSDKernel_i386.h" 20 #include "RegisterContextOpenBSDKernel_x86_64.h" 21 #include "ThreadOpenBSDKernel.h" 22 23 using namespace lldb; 24 using namespace lldb_private; 25 26 ThreadOpenBSDKernel::ThreadOpenBSDKernel(Process &process, lldb::tid_t tid, 27 lldb::addr_t pcb, 28 std::string thread_name) 29 : Thread(process, tid), m_thread_name(std::move(thread_name)), 30 m_pcb(pcb) {} 31 32 ThreadOpenBSDKernel::~ThreadOpenBSDKernel() {} 33 34 void ThreadOpenBSDKernel::RefreshStateAfterStop() {} 35 36 lldb::RegisterContextSP ThreadOpenBSDKernel::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 43 ThreadOpenBSDKernel::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 ProcessOpenBSDKernel *process = 55 static_cast<ProcessOpenBSDKernel *>(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<RegisterContextOpenBSDKernel_arm64>( 62 *this, std::make_unique<RegisterInfoPOSIX_arm64>(arch, 0), 63 m_pcb); 64 break; 65 case llvm::Triple::x86: 66 m_thread_reg_ctx_sp = std::make_shared<RegisterContextOpenBSDKernel_i386>( 67 *this, new RegisterContextOpenBSD_i386(arch), m_pcb); 68 break; 69 case llvm::Triple::x86_64: 70 m_thread_reg_ctx_sp = 71 std::make_shared<RegisterContextOpenBSDKernel_x86_64>( 72 *this, new RegisterContextOpenBSD_x86_64(arch), m_pcb); 73 break; 74 default: 75 assert(false && "Unsupported architecture passed to ThreadOpenBSDKernel"); 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 86 bool ThreadOpenBSDKernel::CalculateStopInfo() { return false; } 87