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