Kamil Rytarowski | 1a3d19d | 2017-03-21 17:30:47 +0000 | [diff] [blame] | 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 | |
Kamil Rytarowski | f07a999 | 2017-03-28 22:43:17 +0000 | [diff] [blame] | 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 | |
Kamil Rytarowski | 1a3d19d | 2017-03-21 17:30:47 +0000 | [diff] [blame] | 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) |
Kamil Rytarowski | f07a999 | 2017-03-28 22:43:17 +0000 | [diff] [blame] | 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 | |
Kamil Rytarowski | 3eef2b5 | 2017-03-30 20:25:29 +0000 | [diff] [blame^] | 59 | void NativeThreadNetBSD::SetStoppedByTrace() { |
| 60 | SetStopped(); |
| 61 | m_stop_info.reason = StopReason::eStopReasonTrace; |
| 62 | m_stop_info.details.signal.signo = SIGTRAP; |
| 63 | } |
| 64 | |
| 65 | void NativeThreadNetBSD::SetStoppedByExec() { |
| 66 | SetStopped(); |
| 67 | m_stop_info.reason = StopReason::eStopReasonExec; |
| 68 | m_stop_info.details.signal.signo = SIGTRAP; |
| 69 | } |
| 70 | |
Kamil Rytarowski | f07a999 | 2017-03-28 22:43:17 +0000 | [diff] [blame] | 71 | void NativeThreadNetBSD::SetStopped() { |
| 72 | const StateType new_state = StateType::eStateStopped; |
| 73 | m_state = new_state; |
| 74 | m_stop_description.clear(); |
| 75 | } |
| 76 | |
| 77 | void NativeThreadNetBSD::SetRunning() { |
| 78 | m_state = StateType::eStateRunning; |
| 79 | m_stop_info.reason = StopReason::eStopReasonNone; |
| 80 | } |
| 81 | |
Kamil Rytarowski | 3eef2b5 | 2017-03-30 20:25:29 +0000 | [diff] [blame^] | 82 | void NativeThreadNetBSD::SetStepping() { |
| 83 | m_state = StateType::eStateStepping; |
| 84 | m_stop_info.reason = StopReason::eStopReasonNone; |
| 85 | } |
| 86 | |
Kamil Rytarowski | f07a999 | 2017-03-28 22:43:17 +0000 | [diff] [blame] | 87 | std::string NativeThreadNetBSD::GetName() { return std::string(""); } |
| 88 | |
| 89 | lldb::StateType NativeThreadNetBSD::GetState() { return m_state; } |
| 90 | |
| 91 | bool NativeThreadNetBSD::GetStopReason(ThreadStopInfo &stop_info, |
| 92 | std::string &description) { |
| 93 | Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD)); |
| 94 | |
| 95 | description.clear(); |
| 96 | |
| 97 | switch (m_state) { |
| 98 | case eStateStopped: |
| 99 | case eStateCrashed: |
| 100 | case eStateExited: |
| 101 | case eStateSuspended: |
| 102 | case eStateUnloaded: |
| 103 | stop_info = m_stop_info; |
| 104 | description = m_stop_description; |
| 105 | |
| 106 | return true; |
| 107 | |
| 108 | case eStateInvalid: |
| 109 | case eStateConnected: |
| 110 | case eStateAttaching: |
| 111 | case eStateLaunching: |
| 112 | case eStateRunning: |
| 113 | case eStateStepping: |
| 114 | case eStateDetached: |
| 115 | LLDB_LOG(log, "tid = {0} in state {1} cannot answer stop reason", GetID(), |
| 116 | StateAsCString(m_state)); |
| 117 | return false; |
| 118 | } |
| 119 | llvm_unreachable("unhandled StateType!"); |
| 120 | } |
| 121 | |
| 122 | NativeRegisterContextSP NativeThreadNetBSD::GetRegisterContext() { |
| 123 | // Return the register context if we already created it. |
| 124 | if (m_reg_context_sp) |
| 125 | return m_reg_context_sp; |
| 126 | |
| 127 | NativeProcessProtocolSP m_process_sp = m_process_wp.lock(); |
| 128 | if (!m_process_sp) |
| 129 | return NativeRegisterContextSP(); |
| 130 | |
| 131 | ArchSpec target_arch; |
| 132 | if (!m_process_sp->GetArchitecture(target_arch)) |
| 133 | return NativeRegisterContextSP(); |
| 134 | |
| 135 | const uint32_t concrete_frame_idx = 0; |
| 136 | m_reg_context_sp.reset( |
| 137 | NativeRegisterContextNetBSD::CreateHostNativeRegisterContextNetBSD( |
| 138 | target_arch, *this, concrete_frame_idx)); |
| 139 | |
| 140 | return m_reg_context_sp; |
| 141 | } |
| 142 | |
| 143 | Error NativeThreadNetBSD::SetWatchpoint(lldb::addr_t addr, size_t size, |
| 144 | uint32_t watch_flags, bool hardware) { |
| 145 | return Error("Unimplemented"); |
| 146 | } |
| 147 | |
| 148 | Error NativeThreadNetBSD::RemoveWatchpoint(lldb::addr_t addr) { |
| 149 | return Error("Unimplemented"); |
| 150 | } |
| 151 | |
| 152 | Error NativeThreadNetBSD::SetHardwareBreakpoint(lldb::addr_t addr, |
| 153 | size_t size) { |
| 154 | return Error("Unimplemented"); |
| 155 | } |
| 156 | |
| 157 | Error NativeThreadNetBSD::RemoveHardwareBreakpoint(lldb::addr_t addr) { |
| 158 | return Error("Unimplemented"); |
| 159 | } |