1 //===-- NativeThreadOpenBSD.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 "NativeThreadOpenBSD.h"
11 #include "NativeRegisterContextOpenBSD.h"
12
13 #include "NativeProcessOpenBSD.h"
14
15 #include "Plugins/Process/POSIX/CrashReason.h"
16 #include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
17 #include "lldb/Utility/LLDBAssert.h"
18 #include "lldb/Utility/RegisterValue.h"
19 #include "lldb/Utility/State.h"
20
21 #include <sstream>
22
23 using namespace lldb;
24 using namespace lldb_private;
25 using namespace lldb_private::process_openbsd;
26
NativeThreadOpenBSD(NativeProcessOpenBSD & process,lldb::tid_t tid)27 NativeThreadOpenBSD::NativeThreadOpenBSD(NativeProcessOpenBSD &process,
28 lldb::tid_t tid)
29 : NativeThreadProtocol(process, tid), m_state(StateType::eStateInvalid),
30 m_stop_info(), m_stop_description() {
31 m_reg_context_up = NativeRegisterContextOpenBSD::CreateHostNativeRegisterContextOpenBSD(process.GetArchitecture(), *this);
32 if (!m_reg_context_up)
33 llvm_unreachable("This architecture does not support debugging running processes.");
34 }
35
SetStoppedBySignal(uint32_t signo,const siginfo_t * info)36 void NativeThreadOpenBSD::SetStoppedBySignal(uint32_t signo,
37 const siginfo_t *info) {
38 Log *log = GetLog(POSIXLog::Thread);
39 LLDB_LOG(log, "tid = {0} in called with signal {1}", GetID(), signo);
40
41 SetStopped();
42
43 m_stop_info.reason = StopReason::eStopReasonSignal;
44 m_stop_info.signo = signo;
45
46 m_stop_description.clear();
47 if (info) {
48 switch (signo) {
49 case SIGSEGV:
50 case SIGBUS:
51 case SIGFPE:
52 case SIGILL:
53 const auto reason = GetCrashReason(*info);
54 m_stop_description = GetCrashReasonString(reason, *info);
55 break;
56 }
57 }
58 }
59
SetStoppedByBreakpoint()60 void NativeThreadOpenBSD::SetStoppedByBreakpoint() {
61 SetStopped();
62 m_stop_info.reason = StopReason::eStopReasonBreakpoint;
63 m_stop_info.signo = SIGTRAP;
64 }
65
SetStoppedByTrace()66 void NativeThreadOpenBSD::SetStoppedByTrace() {
67 SetStopped();
68 m_stop_info.reason = StopReason::eStopReasonTrace;
69 m_stop_info.signo = SIGTRAP;
70 }
71
SetStoppedByExec()72 void NativeThreadOpenBSD::SetStoppedByExec() {
73 SetStopped();
74 m_stop_info.reason = StopReason::eStopReasonExec;
75 m_stop_info.signo = SIGTRAP;
76 }
77
SetStopped()78 void NativeThreadOpenBSD::SetStopped() {
79 const StateType new_state = StateType::eStateStopped;
80 m_state = new_state;
81 m_stop_description.clear();
82 }
83
SetRunning()84 void NativeThreadOpenBSD::SetRunning() {
85 m_state = StateType::eStateRunning;
86 m_stop_info.reason = StopReason::eStopReasonNone;
87 }
88
SetStepping()89 void NativeThreadOpenBSD::SetStepping() {
90 m_state = StateType::eStateStepping;
91 m_stop_info.reason = StopReason::eStopReasonNone;
92 }
93
GetName()94 std::string NativeThreadOpenBSD::GetName() { return std::string(""); }
95
GetState()96 lldb::StateType NativeThreadOpenBSD::GetState() { return m_state; }
97
GetStopReason(ThreadStopInfo & stop_info,std::string & description)98 bool NativeThreadOpenBSD::GetStopReason(ThreadStopInfo &stop_info,
99 std::string &description) {
100 Log *log = GetLog(POSIXLog::Thread);
101
102 description.clear();
103
104 switch (m_state) {
105 case eStateStopped:
106 case eStateCrashed:
107 case eStateExited:
108 case eStateSuspended:
109 case eStateUnloaded:
110 stop_info = m_stop_info;
111 description = m_stop_description;
112
113 return true;
114
115 case eStateInvalid:
116 case eStateConnected:
117 case eStateAttaching:
118 case eStateLaunching:
119 case eStateRunning:
120 case eStateStepping:
121 case eStateDetached:
122 LLDB_LOG(log, "tid = {0} in state {1} cannot answer stop reason", GetID(),
123 StateAsCString(m_state));
124 return false;
125 }
126 llvm_unreachable("unhandled StateType!");
127 }
128
GetRegisterContext()129 NativeRegisterContext& NativeThreadOpenBSD::GetRegisterContext() {
130 assert(m_reg_context_up);
131 return *m_reg_context_up;
132 }
133
SetWatchpoint(lldb::addr_t addr,size_t size,uint32_t watch_flags,bool hardware)134 Status NativeThreadOpenBSD::SetWatchpoint(lldb::addr_t addr, size_t size,
135 uint32_t watch_flags, bool hardware) {
136 if (hardware)
137 return Status("Not Aailable");
138 return Status("Software watchpoints not implemented");
139 }
140
RemoveWatchpoint(lldb::addr_t addr)141 Status NativeThreadOpenBSD::RemoveWatchpoint(lldb::addr_t addr) {
142 return Status("Software watchpoints not implemented");
143 }
144
SetHardwareBreakpoint(lldb::addr_t addr,size_t size)145 Status NativeThreadOpenBSD::SetHardwareBreakpoint(lldb::addr_t addr,
146 size_t size) {
147 return Status("Not Available");
148 }
149
RemoveHardwareBreakpoint(lldb::addr_t addr)150 Status NativeThreadOpenBSD::RemoveHardwareBreakpoint(lldb::addr_t addr) {
151 return Status("Not Available");
152 }
153