1 //===-- NativeThreadNetBSD.cpp -------------------------------- -*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "NativeThreadNetBSD.h" 11 #include "NativeRegisterContextNetBSD.h" 12 13 #include "NativeProcessNetBSD.h" 14 15 #include "Plugins/Process/POSIX/CrashReason.h" 16 #include "Plugins/Process/POSIX/ProcessPOSIXLog.h" 17 #include "lldb/Core/RegisterValue.h" 18 #include "lldb/Core/State.h" 19 20 using namespace lldb; 21 using namespace lldb_private; 22 using namespace lldb_private::process_netbsd; 23 24 NativeThreadNetBSD::NativeThreadNetBSD(NativeProcessNetBSD *process, 25 lldb::tid_t tid) 26 : NativeThreadProtocol(process, tid), m_state(StateType::eStateInvalid), 27 m_stop_info(), m_reg_context_sp(), m_stop_description() {} 28 29 void NativeThreadNetBSD::SetStoppedBySignal(uint32_t signo, 30 const siginfo_t *info) { 31 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD)); 32 LLDB_LOG(log, "tid = {0} in called with signal {1}", GetID(), signo); 33 34 SetStopped(); 35 36 m_stop_info.reason = StopReason::eStopReasonSignal; 37 m_stop_info.details.signal.signo = signo; 38 39 m_stop_description.clear(); 40 if (info) { 41 switch (signo) { 42 case SIGSEGV: 43 case SIGBUS: 44 case SIGFPE: 45 case SIGILL: 46 const auto reason = GetCrashReason(*info); 47 m_stop_description = GetCrashReasonString(reason, *info); 48 break; 49 } 50 } 51 } 52 53 void NativeThreadNetBSD::SetStoppedByBreakpoint() { 54 SetStopped(); 55 m_stop_info.reason = StopReason::eStopReasonBreakpoint; 56 m_stop_info.details.signal.signo = SIGTRAP; 57 } 58 59 void NativeThreadNetBSD::SetStopped() { 60 const StateType new_state = StateType::eStateStopped; 61 m_state = new_state; 62 m_stop_description.clear(); 63 } 64 65 void NativeThreadNetBSD::SetRunning() { 66 m_state = StateType::eStateRunning; 67 m_stop_info.reason = StopReason::eStopReasonNone; 68 } 69 70 std::string NativeThreadNetBSD::GetName() { return std::string(""); } 71 72 lldb::StateType NativeThreadNetBSD::GetState() { return m_state; } 73 74 bool NativeThreadNetBSD::GetStopReason(ThreadStopInfo &stop_info, 75 std::string &description) { 76 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD)); 77 78 description.clear(); 79 80 switch (m_state) { 81 case eStateStopped: 82 case eStateCrashed: 83 case eStateExited: 84 case eStateSuspended: 85 case eStateUnloaded: 86 stop_info = m_stop_info; 87 description = m_stop_description; 88 89 return true; 90 91 case eStateInvalid: 92 case eStateConnected: 93 case eStateAttaching: 94 case eStateLaunching: 95 case eStateRunning: 96 case eStateStepping: 97 case eStateDetached: 98 LLDB_LOG(log, "tid = {0} in state {1} cannot answer stop reason", GetID(), 99 StateAsCString(m_state)); 100 return false; 101 } 102 llvm_unreachable("unhandled StateType!"); 103 } 104 105 NativeRegisterContextSP NativeThreadNetBSD::GetRegisterContext() { 106 // Return the register context if we already created it. 107 if (m_reg_context_sp) 108 return m_reg_context_sp; 109 110 NativeProcessProtocolSP m_process_sp = m_process_wp.lock(); 111 if (!m_process_sp) 112 return NativeRegisterContextSP(); 113 114 ArchSpec target_arch; 115 if (!m_process_sp->GetArchitecture(target_arch)) 116 return NativeRegisterContextSP(); 117 118 const uint32_t concrete_frame_idx = 0; 119 m_reg_context_sp.reset( 120 NativeRegisterContextNetBSD::CreateHostNativeRegisterContextNetBSD( 121 target_arch, *this, concrete_frame_idx)); 122 123 return m_reg_context_sp; 124 } 125 126 Error NativeThreadNetBSD::SetWatchpoint(lldb::addr_t addr, size_t size, 127 uint32_t watch_flags, bool hardware) { 128 return Error("Unimplemented"); 129 } 130 131 Error NativeThreadNetBSD::RemoveWatchpoint(lldb::addr_t addr) { 132 return Error("Unimplemented"); 133 } 134 135 Error NativeThreadNetBSD::SetHardwareBreakpoint(lldb::addr_t addr, 136 size_t size) { 137 return Error("Unimplemented"); 138 } 139 140 Error NativeThreadNetBSD::RemoveHardwareBreakpoint(lldb::addr_t addr) { 141 return Error("Unimplemented"); 142 } 143