1 //===-- NativeThreadNetBSD.cpp -------------------------------- -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "NativeThreadNetBSD.h"
11 #include "NativeRegisterContextNetBSD.h"
13 #include "NativeProcessNetBSD.h"
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 #include "lldb/Utility/LLDBAssert.h"
24 using namespace lldb_private;
25 using namespace lldb_private::process_netbsd;
27 NativeThreadNetBSD::NativeThreadNetBSD(NativeProcessNetBSD &process,
29 : NativeThreadProtocol(process, tid), m_state(StateType::eStateInvalid),
30 m_stop_info(), m_reg_context_up(
31 NativeRegisterContextNetBSD::CreateHostNativeRegisterContextNetBSD(process.GetArchitecture(), *this)
32 ), m_stop_description() {}
34 void NativeThreadNetBSD::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);
41 m_stop_info.reason = StopReason::eStopReasonSignal;
42 m_stop_info.details.signal.signo = signo;
44 m_stop_description.clear();
51 const auto reason = GetCrashReason(*info);
52 m_stop_description = GetCrashReasonString(reason, *info);
58 void NativeThreadNetBSD::SetStoppedByBreakpoint() {
60 m_stop_info.reason = StopReason::eStopReasonBreakpoint;
61 m_stop_info.details.signal.signo = SIGTRAP;
64 void NativeThreadNetBSD::SetStoppedByTrace() {
66 m_stop_info.reason = StopReason::eStopReasonTrace;
67 m_stop_info.details.signal.signo = SIGTRAP;
70 void NativeThreadNetBSD::SetStoppedByExec() {
72 m_stop_info.reason = StopReason::eStopReasonExec;
73 m_stop_info.details.signal.signo = SIGTRAP;
76 void NativeThreadNetBSD::SetStoppedByWatchpoint(uint32_t wp_index) {
79 lldbassert(wp_index != LLDB_INVALID_INDEX32 && "wp_index cannot be invalid");
81 std::ostringstream ostr;
82 ostr << GetRegisterContext().GetWatchpointAddress(wp_index) << " ";
85 ostr << " " << GetRegisterContext().GetWatchpointHitAddress(wp_index);
87 m_stop_description = ostr.str();
89 m_stop_info.reason = StopReason::eStopReasonWatchpoint;
90 m_stop_info.details.signal.signo = SIGTRAP;
93 void NativeThreadNetBSD::SetStopped() {
94 const StateType new_state = StateType::eStateStopped;
96 m_stop_description.clear();
99 void NativeThreadNetBSD::SetRunning() {
100 m_state = StateType::eStateRunning;
101 m_stop_info.reason = StopReason::eStopReasonNone;
104 void NativeThreadNetBSD::SetStepping() {
105 m_state = StateType::eStateStepping;
106 m_stop_info.reason = StopReason::eStopReasonNone;
109 std::string NativeThreadNetBSD::GetName() { return std::string(""); }
111 lldb::StateType NativeThreadNetBSD::GetState() { return m_state; }
113 bool NativeThreadNetBSD::GetStopReason(ThreadStopInfo &stop_info,
114 std::string &description) {
115 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
123 case eStateSuspended:
125 stop_info = m_stop_info;
126 description = m_stop_description;
131 case eStateConnected:
132 case eStateAttaching:
133 case eStateLaunching:
137 LLDB_LOG(log, "tid = {0} in state {1} cannot answer stop reason", GetID(),
138 StateAsCString(m_state));
141 llvm_unreachable("unhandled StateType!");
144 NativeRegisterContext& NativeThreadNetBSD::GetRegisterContext() {
145 assert(m_reg_context_up);
146 return *m_reg_context_up;
149 Status NativeThreadNetBSD::SetWatchpoint(lldb::addr_t addr, size_t size,
150 uint32_t watch_flags, bool hardware) {
152 return Status("not implemented");
153 if (m_state == eStateLaunching)
155 Status error = RemoveWatchpoint(addr);
158 uint32_t wp_index = GetRegisterContext().SetHardwareWatchpoint(addr, size, watch_flags);
159 if (wp_index == LLDB_INVALID_INDEX32)
160 return Status("Setting hardware watchpoint failed.");
161 m_watchpoint_index_map.insert({addr, wp_index});
165 Status NativeThreadNetBSD::RemoveWatchpoint(lldb::addr_t addr) {
166 auto wp = m_watchpoint_index_map.find(addr);
167 if (wp == m_watchpoint_index_map.end())
169 uint32_t wp_index = wp->second;
170 m_watchpoint_index_map.erase(wp);
171 if (GetRegisterContext().ClearHardwareWatchpoint(wp_index))
173 return Status("Clearing hardware watchpoint failed.");
176 Status NativeThreadNetBSD::SetHardwareBreakpoint(lldb::addr_t addr,
178 if (m_state == eStateLaunching)
181 Status error = RemoveHardwareBreakpoint(addr);
185 uint32_t bp_index = GetRegisterContext().SetHardwareBreakpoint(addr, size);
187 if (bp_index == LLDB_INVALID_INDEX32)
188 return Status("Setting hardware breakpoint failed.");
190 m_hw_break_index_map.insert({addr, bp_index});
194 Status NativeThreadNetBSD::RemoveHardwareBreakpoint(lldb::addr_t addr) {
195 auto bp = m_hw_break_index_map.find(addr);
196 if (bp == m_hw_break_index_map.end())
199 uint32_t bp_index = bp->second;
200 if (GetRegisterContext().ClearHardwareBreakpoint(bp_index)) {
201 m_hw_break_index_map.erase(bp);
205 return Status("Clearing hardware breakpoint failed.");