| 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 | |
| 22 | using namespace lldb; |
| 23 | using namespace lldb_private; |
| 24 | |
| 25 | ThreadFreeBSDKernel::ThreadFreeBSDKernel(Process &process, lldb::tid_t tid, |
| 26 | lldb::addr_t pcb_addr, |
| 27 | std::string thread_name) |
| 28 | : Thread(process, tid), m_thread_name(std::move(thread_name)), |
| 29 | m_pcb_addr(pcb_addr) {} |
| 30 | |
| 31 | ThreadFreeBSDKernel::~ThreadFreeBSDKernel() {} |
| 32 | |
| 33 | void ThreadFreeBSDKernel::RefreshStateAfterStop() {} |
| 34 | |
| 35 | lldb::RegisterContextSP ThreadFreeBSDKernel::GetRegisterContext() { |
| 36 | if (!m_reg_context_sp) |
| 37 | m_reg_context_sp = CreateRegisterContextForFrame(frame: nullptr); |
| 38 | return m_reg_context_sp; |
| 39 | } |
| 40 | |
| 41 | lldb::RegisterContextSP |
| 42 | ThreadFreeBSDKernel::CreateRegisterContextForFrame(StackFrame *frame) { |
| 43 | RegisterContextSP reg_ctx_sp; |
| 44 | uint32_t concrete_frame_idx = 0; |
| 45 | |
| 46 | if (frame) |
| 47 | concrete_frame_idx = frame->GetConcreteFrameIndex(); |
| 48 | |
| 49 | if (concrete_frame_idx == 0) { |
| 50 | if (m_thread_reg_ctx_sp) |
| 51 | return m_thread_reg_ctx_sp; |
| 52 | |
| 53 | ProcessFreeBSDKernel *process = |
| 54 | static_cast<ProcessFreeBSDKernel *>(GetProcess().get()); |
| 55 | ArchSpec arch = process->GetTarget().GetArchitecture(); |
| 56 | |
| 57 | switch (arch.GetMachine()) { |
| 58 | case llvm::Triple::aarch64: |
| 59 | m_thread_reg_ctx_sp = |
| 60 | std::make_shared<RegisterContextFreeBSDKernel_arm64>( |
| 61 | args&: *this, args: std::make_unique<RegisterInfoPOSIX_arm64>(args&: arch, args: 0), |
| 62 | args&: m_pcb_addr); |
| 63 | break; |
| 64 | case llvm::Triple::x86: |
| 65 | m_thread_reg_ctx_sp = std::make_shared<RegisterContextFreeBSDKernel_i386>( |
| 66 | args&: *this, args: new RegisterContextFreeBSD_i386(arch), args&: m_pcb_addr); |
| 67 | break; |
| 68 | case llvm::Triple::x86_64: |
| 69 | m_thread_reg_ctx_sp = |
| 70 | std::make_shared<RegisterContextFreeBSDKernel_x86_64>( |
| 71 | args&: *this, args: new RegisterContextFreeBSD_x86_64(arch), args&: m_pcb_addr); |
| 72 | break; |
| 73 | default: |
| 74 | assert(false && "Unsupported architecture passed to ThreadFreeBSDKernel" ); |
| 75 | break; |
| 76 | } |
| 77 | |
| 78 | reg_ctx_sp = m_thread_reg_ctx_sp; |
| 79 | } else { |
| 80 | reg_ctx_sp = GetUnwinder().CreateRegisterContextForFrame(frame); |
| 81 | } |
| 82 | return reg_ctx_sp; |
| 83 | } |
| 84 | |
| 85 | bool ThreadFreeBSDKernel::CalculateStopInfo() { return false; } |
| 86 | |