1 //===-- FreeBSDThread.cpp -------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include <errno.h>
10 #include <pthread.h>
11 #include <pthread_np.h>
12 #include <stdlib.h>
13 #include <sys/sysctl.h>
14 #include <sys/types.h>
15 #include <sys/user.h>
16
17 #include "FreeBSDThread.h"
18 #include "POSIXStopInfo.h"
19 #include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
20 #include "Plugins/Process/Utility/RegisterContextFreeBSD_i386.h"
21 #include "Plugins/Process/Utility/RegisterContextFreeBSD_mips64.h"
22 #include "Plugins/Process/Utility/RegisterContextFreeBSD_powerpc.h"
23 #include "Plugins/Process/Utility/RegisterContextFreeBSD_x86_64.h"
24 #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm.h"
25 #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h"
26 #include "ProcessFreeBSD.h"
27 #include "ProcessMonitor.h"
28 #include "RegisterContextPOSIXProcessMonitor_arm.h"
29 #include "RegisterContextPOSIXProcessMonitor_arm64.h"
30 #include "RegisterContextPOSIXProcessMonitor_mips64.h"
31 #include "RegisterContextPOSIXProcessMonitor_powerpc.h"
32 #include "RegisterContextPOSIXProcessMonitor_x86.h"
33 #include "lldb/Breakpoint/BreakpointLocation.h"
34 #include "lldb/Breakpoint/Watchpoint.h"
35 #include "lldb/Core/Debugger.h"
36 #include "lldb/Host/Host.h"
37 #include "lldb/Host/HostInfo.h"
38 #include "lldb/Host/HostNativeThread.h"
39 #include "lldb/Target/Process.h"
40 #include "lldb/Target/StopInfo.h"
41 #include "lldb/Target/Target.h"
42 #include "lldb/Target/ThreadSpec.h"
43 #include "lldb/Target/UnixSignals.h"
44 #include "lldb/Target/Unwind.h"
45 #include "lldb/Utility/State.h"
46 #include "llvm/ADT/SmallString.h"
47
48 using namespace lldb;
49 using namespace lldb_private;
50
FreeBSDThread(Process & process,lldb::tid_t tid)51 FreeBSDThread::FreeBSDThread(Process &process, lldb::tid_t tid)
52 : Thread(process, tid), m_frame_up(), m_breakpoint(),
53 m_thread_name_valid(false), m_thread_name(), m_posix_thread(nullptr) {
54 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
55 LLDB_LOGV(log, "tid = {0}", tid);
56
57 // Set the current watchpoints for this thread.
58 Target &target = GetProcess()->GetTarget();
59 const WatchpointList &wp_list = target.GetWatchpointList();
60 size_t wp_size = wp_list.GetSize();
61
62 for (uint32_t wp_idx = 0; wp_idx < wp_size; wp_idx++) {
63 lldb::WatchpointSP wp = wp_list.GetByIndex(wp_idx);
64 if (wp.get() && wp->IsEnabled()) {
65 // This watchpoint as been enabled; obviously this "new" thread has been
66 // created since that watchpoint was enabled. Since the
67 // POSIXBreakpointProtocol has yet to be initialized, its
68 // m_watchpoints_initialized member will be FALSE. Attempting to read
69 // the debug status register to determine if a watchpoint has been hit
70 // would result in the zeroing of that register. Since the active debug
71 // registers would have been cloned when this thread was created, simply
72 // force the m_watchpoints_initized member to TRUE and avoid resetting
73 // dr6 and dr7.
74 GetPOSIXBreakpointProtocol()->ForceWatchpointsInitialized();
75 }
76 }
77 }
78
~FreeBSDThread()79 FreeBSDThread::~FreeBSDThread() { DestroyThread(); }
80
GetMonitor()81 ProcessMonitor &FreeBSDThread::GetMonitor() {
82 ProcessSP base = GetProcess();
83 ProcessFreeBSD &process = static_cast<ProcessFreeBSD &>(*base);
84 return process.GetMonitor();
85 }
86
RefreshStateAfterStop()87 void FreeBSDThread::RefreshStateAfterStop() {
88 // Invalidate all registers in our register context. We don't set "force" to
89 // true because the stop reply packet might have had some register values
90 // that were expedited and these will already be copied into the register
91 // context by the time this function gets called. The KDPRegisterContext
92 // class has been made smart enough to detect when it needs to invalidate
93 // which registers are valid by putting hooks in the register read and
94 // register supply functions where they check the process stop ID and do the
95 // right thing. if (StateIsStoppedState(GetState())
96 {
97 const bool force = false;
98 GetRegisterContext()->InvalidateIfNeeded(force);
99 }
100 }
101
GetInfo()102 const char *FreeBSDThread::GetInfo() { return nullptr; }
103
SetName(const char * name)104 void FreeBSDThread::SetName(const char *name) {
105 m_thread_name_valid = (name && name[0]);
106 if (m_thread_name_valid)
107 m_thread_name.assign(name);
108 else
109 m_thread_name.clear();
110 }
111
GetName()112 const char *FreeBSDThread::GetName() {
113 if (!m_thread_name_valid) {
114 m_thread_name.clear();
115 int pid = GetProcess()->GetID();
116
117 struct kinfo_proc *kp = nullptr, *nkp;
118 size_t len = 0;
119 int error;
120 int ctl[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD,
121 pid};
122
123 while (1) {
124 error = sysctl(ctl, 4, kp, &len, nullptr, 0);
125 if (kp == nullptr || (error != 0 && errno == ENOMEM)) {
126 // Add extra space in case threads are added before next call.
127 len += sizeof(*kp) + len / 10;
128 nkp = (struct kinfo_proc *)realloc(kp, len);
129 if (nkp == nullptr) {
130 free(kp);
131 return nullptr;
132 }
133 kp = nkp;
134 continue;
135 }
136 if (error != 0)
137 len = 0;
138 break;
139 }
140
141 for (size_t i = 0; i < len / sizeof(*kp); i++) {
142 if (kp[i].ki_tid == (lwpid_t)GetID()) {
143 m_thread_name.append(kp[i].ki_tdname,
144 kp[i].ki_tdname + strlen(kp[i].ki_tdname));
145 break;
146 }
147 }
148 free(kp);
149 m_thread_name_valid = true;
150 }
151
152 if (m_thread_name.empty())
153 return nullptr;
154 return m_thread_name.c_str();
155 }
156
GetRegisterContext()157 lldb::RegisterContextSP FreeBSDThread::GetRegisterContext() {
158 if (!m_reg_context_sp) {
159 m_posix_thread = nullptr;
160
161 RegisterInfoInterface *reg_interface = nullptr;
162 const ArchSpec &target_arch = GetProcess()->GetTarget().GetArchitecture();
163
164 assert(target_arch.GetTriple().getOS() == llvm::Triple::FreeBSD);
165 switch (target_arch.GetMachine()) {
166 case llvm::Triple::aarch64:
167 case llvm::Triple::arm:
168 break;
169 case llvm::Triple::ppc:
170 #ifndef __powerpc64__
171 reg_interface = new RegisterContextFreeBSD_powerpc32(target_arch);
172 break;
173 #endif
174 case llvm::Triple::ppc64:
175 reg_interface = new RegisterContextFreeBSD_powerpc64(target_arch);
176 break;
177 case llvm::Triple::mips64:
178 reg_interface = new RegisterContextFreeBSD_mips64(target_arch);
179 break;
180 case llvm::Triple::x86:
181 reg_interface = new RegisterContextFreeBSD_i386(target_arch);
182 break;
183 case llvm::Triple::x86_64:
184 reg_interface = new RegisterContextFreeBSD_x86_64(target_arch);
185 break;
186 default:
187 llvm_unreachable("CPU not supported");
188 }
189
190 switch (target_arch.GetMachine()) {
191 case llvm::Triple::aarch64: {
192 RegisterContextPOSIXProcessMonitor_arm64 *reg_ctx =
193 new RegisterContextPOSIXProcessMonitor_arm64(
194 *this, std::make_unique<RegisterInfoPOSIX_arm64>(target_arch));
195 m_posix_thread = reg_ctx;
196 m_reg_context_sp.reset(reg_ctx);
197 break;
198 }
199 case llvm::Triple::arm: {
200 RegisterContextPOSIXProcessMonitor_arm *reg_ctx =
201 new RegisterContextPOSIXProcessMonitor_arm(
202 *this, std::make_unique<RegisterInfoPOSIX_arm>(target_arch));
203 m_posix_thread = reg_ctx;
204 m_reg_context_sp.reset(reg_ctx);
205 break;
206 }
207 case llvm::Triple::mips64: {
208 RegisterContextPOSIXProcessMonitor_mips64 *reg_ctx =
209 new RegisterContextPOSIXProcessMonitor_mips64(*this, 0,
210 reg_interface);
211 m_posix_thread = reg_ctx;
212 m_reg_context_sp.reset(reg_ctx);
213 break;
214 }
215 case llvm::Triple::ppc:
216 case llvm::Triple::ppc64: {
217 RegisterContextPOSIXProcessMonitor_powerpc *reg_ctx =
218 new RegisterContextPOSIXProcessMonitor_powerpc(*this, 0,
219 reg_interface);
220 m_posix_thread = reg_ctx;
221 m_reg_context_sp.reset(reg_ctx);
222 break;
223 }
224 case llvm::Triple::x86:
225 case llvm::Triple::x86_64: {
226 RegisterContextPOSIXProcessMonitor_x86_64 *reg_ctx =
227 new RegisterContextPOSIXProcessMonitor_x86_64(*this, 0,
228 reg_interface);
229 m_posix_thread = reg_ctx;
230 m_reg_context_sp.reset(reg_ctx);
231 break;
232 }
233 default:
234 break;
235 }
236 }
237 return m_reg_context_sp;
238 }
239
240 lldb::RegisterContextSP
CreateRegisterContextForFrame(lldb_private::StackFrame * frame)241 FreeBSDThread::CreateRegisterContextForFrame(lldb_private::StackFrame *frame) {
242 lldb::RegisterContextSP reg_ctx_sp;
243 uint32_t concrete_frame_idx = 0;
244
245 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
246 LLDB_LOGV(log, "called");
247
248 if (frame)
249 concrete_frame_idx = frame->GetConcreteFrameIndex();
250
251 if (concrete_frame_idx == 0)
252 reg_ctx_sp = GetRegisterContext();
253 else {
254 reg_ctx_sp = GetUnwinder().CreateRegisterContextForFrame(frame);
255 }
256
257 return reg_ctx_sp;
258 }
259
GetThreadPointer()260 lldb::addr_t FreeBSDThread::GetThreadPointer() {
261 ProcessMonitor &monitor = GetMonitor();
262 addr_t addr;
263 if (monitor.ReadThreadPointer(GetID(), addr))
264 return addr;
265 else
266 return LLDB_INVALID_ADDRESS;
267 }
268
CalculateStopInfo()269 bool FreeBSDThread::CalculateStopInfo() {
270 SetStopInfo(m_stop_info_sp);
271 return true;
272 }
273
DidStop()274 void FreeBSDThread::DidStop() {
275 // Don't set the thread state to stopped unless we really stopped.
276 }
277
WillResume(lldb::StateType resume_state)278 void FreeBSDThread::WillResume(lldb::StateType resume_state) {
279 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
280 LLDB_LOGF(log, "tid %lu resume_state = %s", GetID(),
281 lldb_private::StateAsCString(resume_state));
282 ProcessSP process_sp(GetProcess());
283 ProcessFreeBSD *process = static_cast<ProcessFreeBSD *>(process_sp.get());
284 int signo = GetResumeSignal();
285 bool signo_valid = process->GetUnixSignals()->SignalIsValid(signo);
286
287 switch (resume_state) {
288 case eStateSuspended:
289 case eStateStopped:
290 process->m_suspend_tids.push_back(GetID());
291 break;
292 case eStateRunning:
293 process->m_run_tids.push_back(GetID());
294 if (signo_valid)
295 process->m_resume_signo = signo;
296 break;
297 case eStateStepping:
298 process->m_step_tids.push_back(GetID());
299 if (signo_valid)
300 process->m_resume_signo = signo;
301 break;
302 default:
303 break;
304 }
305 }
306
Resume()307 bool FreeBSDThread::Resume() {
308 lldb::StateType resume_state = GetResumeState();
309 ProcessMonitor &monitor = GetMonitor();
310 bool status;
311
312 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
313 LLDB_LOGF(log, "FreeBSDThread::%s (), resume_state = %s", __FUNCTION__,
314 StateAsCString(resume_state));
315
316 switch (resume_state) {
317 default:
318 assert(false && "Unexpected state for resume!");
319 status = false;
320 break;
321
322 case lldb::eStateRunning:
323 SetState(resume_state);
324 status = monitor.Resume(GetID(), GetResumeSignal());
325 break;
326
327 case lldb::eStateStepping:
328 SetState(resume_state);
329 status = monitor.SingleStep(GetID(), GetResumeSignal());
330 break;
331 case lldb::eStateStopped:
332 case lldb::eStateSuspended:
333 status = true;
334 break;
335 }
336
337 return status;
338 }
339
Notify(const ProcessMessage & message)340 void FreeBSDThread::Notify(const ProcessMessage &message) {
341 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
342 LLDB_LOGF(log, "FreeBSDThread::%s () message kind = '%s' for tid %" PRIu64,
343 __FUNCTION__, message.PrintKind(), GetID());
344
345 switch (message.GetKind()) {
346 default:
347 assert(false && "Unexpected message kind!");
348 break;
349
350 case ProcessMessage::eExitMessage:
351 // Nothing to be done.
352 break;
353
354 case ProcessMessage::eLimboMessage:
355 LimboNotify(message);
356 break;
357
358 case ProcessMessage::eCrashMessage:
359 case ProcessMessage::eSignalMessage:
360 SignalNotify(message);
361 break;
362
363 case ProcessMessage::eSignalDeliveredMessage:
364 SignalDeliveredNotify(message);
365 break;
366
367 case ProcessMessage::eTraceMessage:
368 TraceNotify(message);
369 break;
370
371 case ProcessMessage::eBreakpointMessage:
372 BreakNotify(message);
373 break;
374
375 case ProcessMessage::eWatchpointMessage:
376 WatchNotify(message);
377 break;
378
379 case ProcessMessage::eExecMessage:
380 ExecNotify(message);
381 break;
382 }
383 }
384
EnableHardwareWatchpoint(Watchpoint * wp)385 bool FreeBSDThread::EnableHardwareWatchpoint(Watchpoint *wp) {
386 bool wp_set = false;
387 if (wp) {
388 addr_t wp_addr = wp->GetLoadAddress();
389 size_t wp_size = wp->GetByteSize();
390 bool wp_read = wp->WatchpointRead();
391 bool wp_write = wp->WatchpointWrite();
392 uint32_t wp_hw_index = wp->GetHardwareIndex();
393 POSIXBreakpointProtocol *reg_ctx = GetPOSIXBreakpointProtocol();
394 if (reg_ctx)
395 wp_set = reg_ctx->SetHardwareWatchpointWithIndex(
396 wp_addr, wp_size, wp_read, wp_write, wp_hw_index);
397 }
398 return wp_set;
399 }
400
DisableHardwareWatchpoint(Watchpoint * wp)401 bool FreeBSDThread::DisableHardwareWatchpoint(Watchpoint *wp) {
402 bool result = false;
403 if (wp) {
404 lldb::RegisterContextSP reg_ctx_sp = GetRegisterContext();
405 if (reg_ctx_sp.get())
406 result = reg_ctx_sp->ClearHardwareWatchpoint(wp->GetHardwareIndex());
407 }
408 return result;
409 }
410
NumSupportedHardwareWatchpoints()411 uint32_t FreeBSDThread::NumSupportedHardwareWatchpoints() {
412 lldb::RegisterContextSP reg_ctx_sp = GetRegisterContext();
413 if (reg_ctx_sp.get())
414 return reg_ctx_sp->NumSupportedHardwareWatchpoints();
415 return 0;
416 }
417
FindVacantWatchpointIndex()418 uint32_t FreeBSDThread::FindVacantWatchpointIndex() {
419 uint32_t hw_index = LLDB_INVALID_INDEX32;
420 uint32_t num_hw_wps = NumSupportedHardwareWatchpoints();
421 uint32_t wp_idx;
422 POSIXBreakpointProtocol *reg_ctx = GetPOSIXBreakpointProtocol();
423 if (reg_ctx) {
424 for (wp_idx = 0; wp_idx < num_hw_wps; wp_idx++) {
425 if (reg_ctx->IsWatchpointVacant(wp_idx)) {
426 hw_index = wp_idx;
427 break;
428 }
429 }
430 }
431 return hw_index;
432 }
433
BreakNotify(const ProcessMessage & message)434 void FreeBSDThread::BreakNotify(const ProcessMessage &message) {
435 bool status;
436 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
437
438 assert(GetRegisterContext());
439 status = GetPOSIXBreakpointProtocol()->UpdateAfterBreakpoint();
440 assert(status && "Breakpoint update failed!");
441
442 // With our register state restored, resolve the breakpoint object
443 // corresponding to our current PC.
444 assert(GetRegisterContext());
445 lldb::addr_t pc = GetRegisterContext()->GetPC();
446 LLDB_LOGF(log, "FreeBSDThread::%s () PC=0x%8.8" PRIx64, __FUNCTION__, pc);
447 lldb::BreakpointSiteSP bp_site(
448 GetProcess()->GetBreakpointSiteList().FindByAddress(pc));
449
450 // If the breakpoint is for this thread, then we'll report the hit, but if it
451 // is for another thread, we create a stop reason with should_stop=false. If
452 // there is no breakpoint location, then report an invalid stop reason. We
453 // don't need to worry about stepping over the breakpoint here, that will be
454 // taken care of when the thread resumes and notices that there's a
455 // breakpoint under the pc.
456 if (bp_site) {
457 lldb::break_id_t bp_id = bp_site->GetID();
458 // If we have an operating system plug-in, we might have set a thread
459 // specific breakpoint using the operating system thread ID, so we can't
460 // make any assumptions about the thread ID so we must always report the
461 // breakpoint regardless of the thread.
462 if (bp_site->ValidForThisThread(this) ||
463 GetProcess()->GetOperatingSystem() != nullptr)
464 SetStopInfo(StopInfo::CreateStopReasonWithBreakpointSiteID(*this, bp_id));
465 else {
466 const bool should_stop = false;
467 SetStopInfo(StopInfo::CreateStopReasonWithBreakpointSiteID(*this, bp_id,
468 should_stop));
469 }
470 } else
471 SetStopInfo(StopInfoSP());
472 }
473
WatchNotify(const ProcessMessage & message)474 void FreeBSDThread::WatchNotify(const ProcessMessage &message) {
475 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
476
477 lldb::addr_t halt_addr = message.GetHWAddress();
478 LLDB_LOGF(log,
479 "FreeBSDThread::%s () Hardware Watchpoint Address = 0x%8.8" PRIx64,
480 __FUNCTION__, halt_addr);
481
482 POSIXBreakpointProtocol *reg_ctx = GetPOSIXBreakpointProtocol();
483 if (reg_ctx) {
484 uint32_t num_hw_wps = reg_ctx->NumSupportedHardwareWatchpoints();
485 uint32_t wp_idx;
486 for (wp_idx = 0; wp_idx < num_hw_wps; wp_idx++) {
487 if (reg_ctx->IsWatchpointHit(wp_idx)) {
488 // Clear the watchpoint hit here
489 reg_ctx->ClearWatchpointHits();
490 break;
491 }
492 }
493
494 if (wp_idx == num_hw_wps)
495 return;
496
497 Target &target = GetProcess()->GetTarget();
498 lldb::addr_t wp_monitor_addr = reg_ctx->GetWatchpointAddress(wp_idx);
499 const WatchpointList &wp_list = target.GetWatchpointList();
500 lldb::WatchpointSP wp_sp = wp_list.FindByAddress(wp_monitor_addr);
501
502 assert(wp_sp.get() && "No watchpoint found");
503 SetStopInfo(
504 StopInfo::CreateStopReasonWithWatchpointID(*this, wp_sp->GetID()));
505 }
506 }
507
TraceNotify(const ProcessMessage & message)508 void FreeBSDThread::TraceNotify(const ProcessMessage &message) {
509 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
510
511 // Try to resolve the breakpoint object corresponding to the current PC.
512 assert(GetRegisterContext());
513 lldb::addr_t pc = GetRegisterContext()->GetPC();
514 LLDB_LOGF(log, "FreeBSDThread::%s () PC=0x%8.8" PRIx64, __FUNCTION__, pc);
515 lldb::BreakpointSiteSP bp_site(
516 GetProcess()->GetBreakpointSiteList().FindByAddress(pc));
517
518 // If the current pc is a breakpoint site then set the StopInfo to
519 // Breakpoint. Otherwise, set the StopInfo to Watchpoint or Trace. If we have
520 // an operating system plug-in, we might have set a thread specific
521 // breakpoint using the operating system thread ID, so we can't make any
522 // assumptions about the thread ID so we must always report the breakpoint
523 // regardless of the thread.
524 if (bp_site && (bp_site->ValidForThisThread(this) ||
525 GetProcess()->GetOperatingSystem() != nullptr))
526 SetStopInfo(StopInfo::CreateStopReasonWithBreakpointSiteID(
527 *this, bp_site->GetID()));
528 else {
529 POSIXBreakpointProtocol *reg_ctx = GetPOSIXBreakpointProtocol();
530 if (reg_ctx) {
531 uint32_t num_hw_wps = reg_ctx->NumSupportedHardwareWatchpoints();
532 uint32_t wp_idx;
533 for (wp_idx = 0; wp_idx < num_hw_wps; wp_idx++) {
534 if (reg_ctx->IsWatchpointHit(wp_idx)) {
535 WatchNotify(message);
536 return;
537 }
538 }
539 }
540 SetStopInfo(StopInfo::CreateStopReasonToTrace(*this));
541 }
542 }
543
LimboNotify(const ProcessMessage & message)544 void FreeBSDThread::LimboNotify(const ProcessMessage &message) {
545 SetStopInfo(lldb::StopInfoSP(new POSIXLimboStopInfo(*this)));
546 }
547
SignalNotify(const ProcessMessage & message)548 void FreeBSDThread::SignalNotify(const ProcessMessage &message) {
549 int signo = message.GetSignal();
550 if (message.GetKind() == ProcessMessage::eCrashMessage) {
551 std::string stop_description = GetCrashReasonString(
552 message.GetCrashReason(), message.GetFaultAddress());
553 SetStopInfo(StopInfo::CreateStopReasonWithSignal(
554 *this, signo, stop_description.c_str()));
555 } else {
556 SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, signo));
557 }
558 }
559
SignalDeliveredNotify(const ProcessMessage & message)560 void FreeBSDThread::SignalDeliveredNotify(const ProcessMessage &message) {
561 int signo = message.GetSignal();
562 SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, signo));
563 }
564
GetRegisterIndexFromOffset(unsigned offset)565 unsigned FreeBSDThread::GetRegisterIndexFromOffset(unsigned offset) {
566 unsigned reg = LLDB_INVALID_REGNUM;
567 ArchSpec arch = HostInfo::GetArchitecture();
568
569 switch (arch.GetMachine()) {
570 default:
571 llvm_unreachable("CPU type not supported!");
572 break;
573
574 case llvm::Triple::aarch64:
575 case llvm::Triple::arm:
576 case llvm::Triple::mips64:
577 case llvm::Triple::ppc:
578 case llvm::Triple::ppc64:
579 case llvm::Triple::x86:
580 case llvm::Triple::x86_64: {
581 POSIXBreakpointProtocol *reg_ctx = GetPOSIXBreakpointProtocol();
582 reg = reg_ctx->GetRegisterIndexFromOffset(offset);
583 } break;
584 }
585 return reg;
586 }
587
ExecNotify(const ProcessMessage & message)588 void FreeBSDThread::ExecNotify(const ProcessMessage &message) {
589 SetStopInfo(StopInfo::CreateStopReasonWithExec(*this));
590 }
591
GetRegisterName(unsigned reg)592 const char *FreeBSDThread::GetRegisterName(unsigned reg) {
593 const char *name = nullptr;
594 ArchSpec arch = HostInfo::GetArchitecture();
595
596 switch (arch.GetMachine()) {
597 default:
598 assert(false && "CPU type not supported!");
599 break;
600
601 case llvm::Triple::aarch64:
602 case llvm::Triple::arm:
603 case llvm::Triple::mips64:
604 case llvm::Triple::ppc:
605 case llvm::Triple::ppc64:
606 case llvm::Triple::x86:
607 case llvm::Triple::x86_64:
608 name = GetRegisterContext()->GetRegisterName(reg);
609 break;
610 }
611 return name;
612 }
613
GetRegisterNameFromOffset(unsigned offset)614 const char *FreeBSDThread::GetRegisterNameFromOffset(unsigned offset) {
615 return GetRegisterName(GetRegisterIndexFromOffset(offset));
616 }
617