1 //===-- ProcessFreeBSD.cpp ----------------------------------------*- C++
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
17 // Other libraries and framework includes
18 #include "lldb/Core/PluginManager.h"
19 #include "lldb/Core/State.h"
20 #include "lldb/Host/Host.h"
21 #include "lldb/Symbol/ObjectFile.h"
22 #include "lldb/Target/DynamicLoader.h"
23 #include "lldb/Target/Target.h"
25 #include "FreeBSDThread.h"
26 #include "Plugins/Process/Utility/FreeBSDSignals.h"
27 #include "Plugins/Process/Utility/InferiorCallPOSIX.h"
28 #include "ProcessFreeBSD.h"
29 #include "ProcessMonitor.h"
30 #include "ProcessPOSIXLog.h"
32 // Other libraries and framework includes
33 #include "lldb/Breakpoint/BreakpointLocation.h"
34 #include "lldb/Breakpoint/Watchpoint.h"
35 #include "lldb/Core/Module.h"
36 #include "lldb/Core/ModuleSpec.h"
37 #include "lldb/Core/PluginManager.h"
38 #include "lldb/Core/State.h"
39 #include "lldb/Host/FileSpec.h"
40 #include "lldb/Host/Host.h"
41 #include "lldb/Symbol/ObjectFile.h"
42 #include "lldb/Target/DynamicLoader.h"
43 #include "lldb/Target/Platform.h"
44 #include "lldb/Target/Target.h"
46 #include "lldb/Host/posix/Fcntl.h"
49 using namespace lldb_private;
52 UnixSignalsSP &GetFreeBSDSignals() {
53 static UnixSignalsSP s_freebsd_signals_sp(new FreeBSDSignals());
54 return s_freebsd_signals_sp;
58 //------------------------------------------------------------------------------
62 ProcessFreeBSD::CreateInstance(lldb::TargetSP target_sp,
63 lldb::ListenerSP listener_sp,
64 const FileSpec *crash_file_path) {
65 lldb::ProcessSP process_sp;
66 if (crash_file_path == NULL)
68 new ProcessFreeBSD(target_sp, listener_sp, GetFreeBSDSignals()));
72 void ProcessFreeBSD::Initialize() {
73 static std::once_flag g_once_flag;
75 std::call_once(g_once_flag, []() {
76 PluginManager::RegisterPlugin(GetPluginNameStatic(),
77 GetPluginDescriptionStatic(), CreateInstance);
78 ProcessPOSIXLog::Initialize(GetPluginNameStatic());
82 lldb_private::ConstString ProcessFreeBSD::GetPluginNameStatic() {
83 static ConstString g_name("freebsd");
87 const char *ProcessFreeBSD::GetPluginDescriptionStatic() {
88 return "Process plugin for FreeBSD";
91 //------------------------------------------------------------------------------
92 // ProcessInterface protocol.
94 lldb_private::ConstString ProcessFreeBSD::GetPluginName() {
95 return GetPluginNameStatic();
98 uint32_t ProcessFreeBSD::GetPluginVersion() { return 1; }
100 void ProcessFreeBSD::Terminate() {}
102 Error ProcessFreeBSD::DoDetach(bool keep_stopped) {
105 error.SetErrorString("Detaching with keep_stopped true is not currently "
106 "supported on FreeBSD.");
110 error = m_monitor->Detach(GetID());
113 SetPrivateState(eStateDetached);
118 Error ProcessFreeBSD::DoResume() {
119 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
121 SetPrivateState(eStateRunning);
123 std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
124 bool do_step = false;
126 for (tid_collection::const_iterator t_pos = m_run_tids.begin(),
127 t_end = m_run_tids.end();
128 t_pos != t_end; ++t_pos) {
129 m_monitor->ThreadSuspend(*t_pos, false);
131 for (tid_collection::const_iterator t_pos = m_step_tids.begin(),
132 t_end = m_step_tids.end();
133 t_pos != t_end; ++t_pos) {
134 m_monitor->ThreadSuspend(*t_pos, false);
137 for (tid_collection::const_iterator t_pos = m_suspend_tids.begin(),
138 t_end = m_suspend_tids.end();
139 t_pos != t_end; ++t_pos) {
140 m_monitor->ThreadSuspend(*t_pos, true);
141 // XXX Cannot PT_CONTINUE properly with suspended threads.
146 log->Printf("process %" PRIu64 " resuming (%s)", GetID(),
147 do_step ? "step" : "continue");
149 m_monitor->SingleStep(GetID(), m_resume_signo);
151 m_monitor->Resume(GetID(), m_resume_signo);
156 bool ProcessFreeBSD::UpdateThreadList(ThreadList &old_thread_list,
157 ThreadList &new_thread_list) {
158 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
160 log->Printf("ProcessFreeBSD::%s (pid = %" PRIu64 ")", __FUNCTION__,
163 std::vector<lldb::pid_t> tds;
164 if (!GetMonitor().GetCurrentThreadIDs(tds)) {
168 ThreadList old_thread_list_copy(old_thread_list);
169 for (size_t i = 0; i < tds.size(); ++i) {
171 ThreadSP thread_sp(old_thread_list_copy.RemoveThreadByID(tid, false));
173 thread_sp.reset(new FreeBSDThread(*this, tid));
175 log->Printf("ProcessFreeBSD::%s new tid = %" PRIu64, __FUNCTION__, tid);
178 log->Printf("ProcessFreeBSD::%s existing tid = %" PRIu64, __FUNCTION__,
181 new_thread_list.AddThread(thread_sp);
183 for (size_t i = 0; i < old_thread_list_copy.GetSize(false); ++i) {
184 ThreadSP old_thread_sp(old_thread_list_copy.GetThreadAtIndex(i, false));
187 log->Printf("ProcessFreeBSD::%s remove tid", __FUNCTION__);
194 Error ProcessFreeBSD::WillResume() {
196 m_suspend_tids.clear();
199 return Process::WillResume();
202 void ProcessFreeBSD::SendMessage(const ProcessMessage &message) {
203 std::lock_guard<std::recursive_mutex> guard(m_message_mutex);
205 switch (message.GetKind()) {
206 case ProcessMessage::eInvalidMessage:
209 case ProcessMessage::eAttachMessage:
210 SetPrivateState(eStateStopped);
213 case ProcessMessage::eLimboMessage:
214 case ProcessMessage::eExitMessage:
215 SetExitStatus(message.GetExitStatus(), NULL);
218 case ProcessMessage::eSignalMessage:
219 case ProcessMessage::eSignalDeliveredMessage:
220 case ProcessMessage::eBreakpointMessage:
221 case ProcessMessage::eTraceMessage:
222 case ProcessMessage::eWatchpointMessage:
223 case ProcessMessage::eCrashMessage:
224 SetPrivateState(eStateStopped);
227 case ProcessMessage::eNewThreadMessage:
228 llvm_unreachable("eNewThreadMessage unexpected on FreeBSD");
231 case ProcessMessage::eExecMessage:
232 SetPrivateState(eStateStopped);
236 m_message_queue.push(message);
239 //------------------------------------------------------------------------------
240 // Constructors and destructors.
242 ProcessFreeBSD::ProcessFreeBSD(lldb::TargetSP target_sp,
243 lldb::ListenerSP listener_sp,
244 UnixSignalsSP &unix_signals_sp)
245 : Process(target_sp, listener_sp, unix_signals_sp),
246 m_byte_order(endian::InlHostByteOrder()), m_monitor(NULL), m_module(NULL),
247 m_message_mutex(), m_exit_now(false), m_seen_initial_stop(),
249 // FIXME: Putting this code in the ctor and saving the byte order in a
250 // member variable is a hack to avoid const qual issues in GetByteOrder.
251 lldb::ModuleSP module = GetTarget().GetExecutableModule();
252 if (module && module->GetObjectFile())
253 m_byte_order = module->GetObjectFile()->GetByteOrder();
256 ProcessFreeBSD::~ProcessFreeBSD() { delete m_monitor; }
258 //------------------------------------------------------------------------------
260 void ProcessFreeBSD::Finalize() {
264 m_monitor->StopMonitor();
267 bool ProcessFreeBSD::CanDebug(lldb::TargetSP target_sp,
268 bool plugin_specified_by_name) {
269 // For now we are just making sure the file exists for a given module
270 ModuleSP exe_module_sp(target_sp->GetExecutableModule());
271 if (exe_module_sp.get())
272 return exe_module_sp->GetFileSpec().Exists();
273 // If there is no executable module, we return true since we might be
274 // preparing to attach.
278 Error ProcessFreeBSD::DoAttachToProcessWithID(
279 lldb::pid_t pid, const ProcessAttachInfo &attach_info) {
281 assert(m_monitor == NULL);
283 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
284 if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
285 log->Printf("ProcessFreeBSD::%s(pid = %" PRIi64 ")", __FUNCTION__, GetID());
287 m_monitor = new ProcessMonitor(this, pid, error);
289 if (!error.Success())
292 PlatformSP platform_sp(GetTarget().GetPlatform());
293 assert(platform_sp.get());
295 return error; // FIXME: Detatch?
297 // Find out what we can about this process
298 ProcessInstanceInfo process_info;
299 platform_sp->GetProcessInfo(pid, process_info);
301 // Resolve the executable module
302 ModuleSP exe_module_sp;
303 FileSpecList executable_search_paths(
304 Target::GetDefaultExecutableSearchPaths());
305 ModuleSpec exe_module_spec(process_info.GetExecutableFile(),
306 GetTarget().GetArchitecture());
307 error = platform_sp->ResolveExecutable(
308 exe_module_spec, exe_module_sp,
309 executable_search_paths.GetSize() ? &executable_search_paths : NULL);
310 if (!error.Success())
313 // Fix the target architecture if necessary
314 const ArchSpec &module_arch = exe_module_sp->GetArchitecture();
315 if (module_arch.IsValid() &&
316 !GetTarget().GetArchitecture().IsExactMatch(module_arch))
317 GetTarget().SetArchitecture(module_arch);
319 // Initialize the target module list
320 GetTarget().SetExecutableModule(exe_module_sp, true);
322 SetSTDIOFileDescriptor(m_monitor->GetTerminalFD());
329 Error ProcessFreeBSD::WillLaunch(Module *module) {
335 ProcessFreeBSD::GetFileSpec(const lldb_private::FileAction *file_action,
336 const FileSpec &default_file_spec,
337 const FileSpec &dbg_pts_file_spec) {
338 FileSpec file_spec{};
340 if (file_action && file_action->GetAction() == FileAction::eFileActionOpen) {
341 file_spec = file_action->GetFileSpec();
342 // By default the stdio paths passed in will be pseudo-terminal
343 // (/dev/pts). If so, convert to using a different default path
344 // instead to redirect I/O to the debugger console. This should
345 // also handle user overrides to /dev/null or a different file.
346 if (!file_spec || file_spec == dbg_pts_file_spec)
347 file_spec = default_file_spec;
352 Error ProcessFreeBSD::DoLaunch(Module *module, ProcessLaunchInfo &launch_info) {
354 assert(m_monitor == NULL);
356 FileSpec working_dir = launch_info.GetWorkingDirectory();
358 (!working_dir.ResolvePath() ||
359 working_dir.GetFileType() != FileSpec::eFileTypeDirectory)) {
360 error.SetErrorStringWithFormat("No such file or directory: %s",
361 working_dir.GetCString());
365 SetPrivateState(eStateLaunching);
367 const lldb_private::FileAction *file_action;
369 // Default of empty will mean to use existing open file descriptors
370 FileSpec stdin_file_spec{};
371 FileSpec stdout_file_spec{};
372 FileSpec stderr_file_spec{};
374 const FileSpec dbg_pts_file_spec{launch_info.GetPTY().GetSlaveName(NULL, 0),
377 file_action = launch_info.GetFileActionForFD(STDIN_FILENO);
379 GetFileSpec(file_action, stdin_file_spec, dbg_pts_file_spec);
381 file_action = launch_info.GetFileActionForFD(STDOUT_FILENO);
383 GetFileSpec(file_action, stdout_file_spec, dbg_pts_file_spec);
385 file_action = launch_info.GetFileActionForFD(STDERR_FILENO);
387 GetFileSpec(file_action, stderr_file_spec, dbg_pts_file_spec);
389 m_monitor = new ProcessMonitor(
390 this, module, launch_info.GetArguments().GetConstArgumentVector(),
391 launch_info.GetEnvironmentEntries().GetConstArgumentVector(),
392 stdin_file_spec, stdout_file_spec, stderr_file_spec, working_dir,
397 if (!error.Success())
400 int terminal = m_monitor->GetTerminalFD();
402 // The reader thread will close the file descriptor when done, so we pass it a
404 #ifdef F_DUPFD_CLOEXEC
405 int stdio = fcntl(terminal, F_DUPFD_CLOEXEC, 0);
407 error.SetErrorToErrno();
411 // Special case when F_DUPFD_CLOEXEC does not exist (Debian kFreeBSD)
412 int stdio = fcntl(terminal, F_DUPFD, 0);
414 error.SetErrorToErrno();
417 stdio = fcntl(terminal, F_SETFD, FD_CLOEXEC);
419 error.SetErrorToErrno();
423 SetSTDIOFileDescriptor(stdio);
426 SetID(m_monitor->GetPID());
430 void ProcessFreeBSD::DidLaunch() {}
432 addr_t ProcessFreeBSD::GetImageInfoAddress() {
433 Target *target = &GetTarget();
434 ObjectFile *obj_file = target->GetExecutableModule()->GetObjectFile();
435 Address addr = obj_file->GetImageInfoAddress(target);
438 return addr.GetLoadAddress(target);
439 return LLDB_INVALID_ADDRESS;
442 Error ProcessFreeBSD::DoHalt(bool &caused_stop) {
447 } else if (kill(GetID(), SIGSTOP)) {
449 error.SetErrorToErrno();
456 Error ProcessFreeBSD::DoSignal(int signal) {
459 if (kill(GetID(), signal))
460 error.SetErrorToErrno();
465 Error ProcessFreeBSD::DoDestroy() {
471 if (GetID() == LLDB_INVALID_PROCESS_ID) {
472 error.SetErrorString("invalid process id");
475 if (!m_monitor->Kill()) {
476 error.SetErrorToErrno();
480 SetPrivateState(eStateExited);
486 void ProcessFreeBSD::DoDidExec() {
487 Target *target = &GetTarget();
489 PlatformSP platform_sp(target->GetPlatform());
490 assert(platform_sp.get());
492 ProcessInstanceInfo process_info;
493 platform_sp->GetProcessInfo(GetID(), process_info);
494 ModuleSP exe_module_sp;
495 ModuleSpec exe_module_spec(process_info.GetExecutableFile(),
496 target->GetArchitecture());
497 FileSpecList executable_search_paths(
498 Target::GetDefaultExecutableSearchPaths());
499 Error error = platform_sp->ResolveExecutable(
500 exe_module_spec, exe_module_sp,
501 executable_search_paths.GetSize() ? &executable_search_paths : NULL);
502 if (!error.Success())
504 target->SetExecutableModule(exe_module_sp, true);
509 bool ProcessFreeBSD::AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid) {
510 bool added_to_set = false;
511 ThreadStopSet::iterator it = m_seen_initial_stop.find(stop_tid);
512 if (it == m_seen_initial_stop.end()) {
513 m_seen_initial_stop.insert(stop_tid);
519 bool ProcessFreeBSD::WaitingForInitialStop(lldb::tid_t stop_tid) {
520 return (m_seen_initial_stop.find(stop_tid) == m_seen_initial_stop.end());
524 ProcessFreeBSD::CreateNewFreeBSDThread(lldb_private::Process &process,
526 return new FreeBSDThread(process, tid);
529 void ProcessFreeBSD::RefreshStateAfterStop() {
530 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
531 if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
532 log->Printf("ProcessFreeBSD::%s(), message_queue size = %d", __FUNCTION__,
533 (int)m_message_queue.size());
535 std::lock_guard<std::recursive_mutex> guard(m_message_mutex);
537 // This method used to only handle one message. Changing it to loop allows
538 // it to handle the case where we hit a breakpoint while handling a different
540 while (!m_message_queue.empty()) {
541 ProcessMessage &message = m_message_queue.front();
543 // Resolve the thread this message corresponds to and pass it along.
544 lldb::tid_t tid = message.GetTID();
547 "ProcessFreeBSD::%s(), message_queue size = %d, pid = %" PRIi64,
548 __FUNCTION__, (int)m_message_queue.size(), tid);
550 m_thread_list.RefreshStateAfterStop();
552 FreeBSDThread *thread = static_cast<FreeBSDThread *>(
553 GetThreadList().FindThreadByID(tid, false).get());
555 thread->Notify(message);
557 if (message.GetKind() == ProcessMessage::eExitMessage) {
558 // FIXME: We should tell the user about this, but the limbo message is
559 // probably better for that.
561 log->Printf("ProcessFreeBSD::%s() removing thread, tid = %" PRIi64,
564 std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
566 ThreadSP thread_sp = m_thread_list.RemoveThreadByID(tid, false);
568 m_seen_initial_stop.erase(tid);
571 m_message_queue.pop();
575 bool ProcessFreeBSD::IsAlive() {
576 StateType state = GetPrivateState();
577 return state != eStateDetached && state != eStateExited &&
578 state != eStateInvalid && state != eStateUnloaded;
581 size_t ProcessFreeBSD::DoReadMemory(addr_t vm_addr, void *buf, size_t size,
584 return m_monitor->ReadMemory(vm_addr, buf, size, error);
587 size_t ProcessFreeBSD::DoWriteMemory(addr_t vm_addr, const void *buf,
588 size_t size, Error &error) {
590 return m_monitor->WriteMemory(vm_addr, buf, size, error);
593 addr_t ProcessFreeBSD::DoAllocateMemory(size_t size, uint32_t permissions,
595 addr_t allocated_addr = LLDB_INVALID_ADDRESS;
598 if (permissions & lldb::ePermissionsReadable)
599 prot |= eMmapProtRead;
600 if (permissions & lldb::ePermissionsWritable)
601 prot |= eMmapProtWrite;
602 if (permissions & lldb::ePermissionsExecutable)
603 prot |= eMmapProtExec;
605 if (InferiorCallMmap(this, allocated_addr, 0, size, prot,
606 eMmapFlagsAnon | eMmapFlagsPrivate, -1, 0)) {
607 m_addr_to_mmap_size[allocated_addr] = size;
610 allocated_addr = LLDB_INVALID_ADDRESS;
611 error.SetErrorStringWithFormat(
612 "unable to allocate %zu bytes of memory with permissions %s", size,
613 GetPermissionsAsCString(permissions));
616 return allocated_addr;
619 Error ProcessFreeBSD::DoDeallocateMemory(lldb::addr_t addr) {
621 MMapMap::iterator pos = m_addr_to_mmap_size.find(addr);
622 if (pos != m_addr_to_mmap_size.end() &&
623 InferiorCallMunmap(this, addr, pos->second))
624 m_addr_to_mmap_size.erase(pos);
626 error.SetErrorStringWithFormat("unable to deallocate memory at 0x%" PRIx64,
633 ProcessFreeBSD::GetSoftwareBreakpointTrapOpcode(BreakpointSite *bp_site) {
634 static const uint8_t g_aarch64_opcode[] = {0x00, 0x00, 0x20, 0xD4};
635 static const uint8_t g_i386_opcode[] = {0xCC};
637 ArchSpec arch = GetTarget().GetArchitecture();
638 const uint8_t *opcode = NULL;
639 size_t opcode_size = 0;
641 switch (arch.GetMachine()) {
643 assert(false && "CPU type not supported!");
646 case llvm::Triple::arm: {
647 // The ARM reference recommends the use of 0xe7fddefe and 0xdefe
648 // but the linux kernel does otherwise.
649 static const uint8_t g_arm_breakpoint_opcode[] = {0xf0, 0x01, 0xf0, 0xe7};
650 static const uint8_t g_thumb_breakpoint_opcode[] = {0x01, 0xde};
652 lldb::BreakpointLocationSP bp_loc_sp(bp_site->GetOwnerAtIndex(0));
653 AddressClass addr_class = eAddressClassUnknown;
656 addr_class = bp_loc_sp->GetAddress().GetAddressClass();
658 if (addr_class == eAddressClassCodeAlternateISA ||
659 (addr_class == eAddressClassUnknown &&
660 bp_loc_sp->GetAddress().GetOffset() & 1)) {
661 opcode = g_thumb_breakpoint_opcode;
662 opcode_size = sizeof(g_thumb_breakpoint_opcode);
664 opcode = g_arm_breakpoint_opcode;
665 opcode_size = sizeof(g_arm_breakpoint_opcode);
668 case llvm::Triple::aarch64:
669 opcode = g_aarch64_opcode;
670 opcode_size = sizeof(g_aarch64_opcode);
673 case llvm::Triple::x86:
674 case llvm::Triple::x86_64:
675 opcode = g_i386_opcode;
676 opcode_size = sizeof(g_i386_opcode);
680 bp_site->SetTrapOpcode(opcode, opcode_size);
684 Error ProcessFreeBSD::EnableBreakpointSite(BreakpointSite *bp_site) {
685 return EnableSoftwareBreakpoint(bp_site);
688 Error ProcessFreeBSD::DisableBreakpointSite(BreakpointSite *bp_site) {
689 return DisableSoftwareBreakpoint(bp_site);
692 Error ProcessFreeBSD::EnableWatchpoint(Watchpoint *wp, bool notify) {
695 user_id_t watchID = wp->GetID();
696 addr_t addr = wp->GetLoadAddress();
697 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_WATCHPOINTS));
699 log->Printf("ProcessFreeBSD::EnableWatchpoint(watchID = %" PRIu64 ")",
701 if (wp->IsEnabled()) {
703 log->Printf("ProcessFreeBSD::EnableWatchpoint(watchID = %" PRIu64
704 ") addr = 0x%8.8" PRIx64 ": watchpoint already enabled.",
705 watchID, (uint64_t)addr);
709 // Try to find a vacant watchpoint slot in the inferiors' main thread
710 uint32_t wp_hw_index = LLDB_INVALID_INDEX32;
711 std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
712 FreeBSDThread *thread = static_cast<FreeBSDThread *>(
713 m_thread_list.GetThreadAtIndex(0, false).get());
716 wp_hw_index = thread->FindVacantWatchpointIndex();
718 if (wp_hw_index == LLDB_INVALID_INDEX32) {
719 error.SetErrorString("Setting hardware watchpoint failed.");
721 wp->SetHardwareIndex(wp_hw_index);
722 bool wp_enabled = true;
723 uint32_t thread_count = m_thread_list.GetSize(false);
724 for (uint32_t i = 0; i < thread_count; ++i) {
725 thread = static_cast<FreeBSDThread *>(
726 m_thread_list.GetThreadAtIndex(i, false).get());
728 wp_enabled &= thread->EnableHardwareWatchpoint(wp);
733 wp->SetEnabled(true, notify);
736 // Watchpoint enabling failed on at least one
737 // of the threads so roll back all of them
738 DisableWatchpoint(wp, false);
739 error.SetErrorString("Setting hardware watchpoint failed");
743 error.SetErrorString("Watchpoint argument was NULL.");
747 Error ProcessFreeBSD::DisableWatchpoint(Watchpoint *wp, bool notify) {
750 user_id_t watchID = wp->GetID();
751 addr_t addr = wp->GetLoadAddress();
752 Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_WATCHPOINTS));
754 log->Printf("ProcessFreeBSD::DisableWatchpoint(watchID = %" PRIu64 ")",
756 if (!wp->IsEnabled()) {
758 log->Printf("ProcessFreeBSD::DisableWatchpoint(watchID = %" PRIu64
759 ") addr = 0x%8.8" PRIx64 ": watchpoint already disabled.",
760 watchID, (uint64_t)addr);
761 // This is needed (for now) to keep watchpoints disabled correctly
762 wp->SetEnabled(false, notify);
766 if (wp->IsHardware()) {
767 bool wp_disabled = true;
768 std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
769 uint32_t thread_count = m_thread_list.GetSize(false);
770 for (uint32_t i = 0; i < thread_count; ++i) {
771 FreeBSDThread *thread = static_cast<FreeBSDThread *>(
772 m_thread_list.GetThreadAtIndex(i, false).get());
774 wp_disabled &= thread->DisableHardwareWatchpoint(wp);
779 wp->SetHardwareIndex(LLDB_INVALID_INDEX32);
780 wp->SetEnabled(false, notify);
783 error.SetErrorString("Disabling hardware watchpoint failed");
786 error.SetErrorString("Watchpoint argument was NULL.");
790 Error ProcessFreeBSD::GetWatchpointSupportInfo(uint32_t &num) {
792 std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
793 FreeBSDThread *thread = static_cast<FreeBSDThread *>(
794 m_thread_list.GetThreadAtIndex(0, false).get());
796 num = thread->NumSupportedHardwareWatchpoints();
798 error.SetErrorString("Process does not exist.");
802 Error ProcessFreeBSD::GetWatchpointSupportInfo(uint32_t &num, bool &after) {
803 Error error = GetWatchpointSupportInfo(num);
804 // Watchpoints trigger and halt the inferior after
805 // the corresponding instruction has been executed.
810 uint32_t ProcessFreeBSD::UpdateThreadListIfNeeded() {
811 std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
812 // Do not allow recursive updates.
813 return m_thread_list.GetSize(false);
818 ProcessFreeBSD::UpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list)
820 Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
821 if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
822 log->Printf ("ProcessFreeBSD::%s() (pid = %" PRIi64 ")", __FUNCTION__, GetID());
824 bool has_updated = false;
825 // Update the process thread list with this new thread.
826 // FIXME: We should be using tid, not pid.
828 ThreadSP thread_sp (old_thread_list.FindThreadByID (GetID(), false));
830 thread_sp.reset(CreateNewFreeBSDThread(*this, GetID()));
834 if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
835 log->Printf ("ProcessFreeBSD::%s() updated pid = %" PRIi64, __FUNCTION__, GetID());
836 new_thread_list.AddThread(thread_sp);
838 return has_updated; // the list has been updated
842 ByteOrder ProcessFreeBSD::GetByteOrder() const {
843 // FIXME: We should be able to extract this value directly. See comment in
848 size_t ProcessFreeBSD::PutSTDIN(const char *buf, size_t len, Error &error) {
850 if ((status = write(m_monitor->GetTerminalFD(), buf, len)) < 0) {
851 error.SetErrorToErrno();
857 //------------------------------------------------------------------------------
858 // Utility functions.
860 bool ProcessFreeBSD::HasExited() {
861 switch (GetPrivateState()) {
873 bool ProcessFreeBSD::IsStopped() {
874 switch (GetPrivateState()) {
880 case eStateSuspended:
887 bool ProcessFreeBSD::IsAThreadRunning() {
888 bool is_running = false;
889 std::lock_guard<std::recursive_mutex> guard(m_thread_list.GetMutex());
890 uint32_t thread_count = m_thread_list.GetSize(false);
891 for (uint32_t i = 0; i < thread_count; ++i) {
892 FreeBSDThread *thread = static_cast<FreeBSDThread *>(
893 m_thread_list.GetThreadAtIndex(i, false).get());
894 StateType thread_state = thread->GetState();
895 if (thread_state == eStateRunning || thread_state == eStateStepping) {
903 const DataBufferSP ProcessFreeBSD::GetAuxvData() {
904 // If we're the local platform, we can ask the host for auxv data.
905 PlatformSP platform_sp = GetTarget().GetPlatform();
906 if (platform_sp && platform_sp->IsHost())
907 return lldb_private::Host::GetAuxvData(this);
909 // Somewhat unexpected - the process is not running locally or we don't have a
913 "no platform or not the host - how did we get here with ProcessFreeBSD?");
914 return DataBufferSP();