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