1 //===-- ProcessFreeBSD.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 //===----------------------------------------------------------------------===//
16 // Other libraries and framework includes
17 #include "lldb/Core/PluginManager.h"
18 #include "lldb/Core/State.h"
19 #include "lldb/Host/Host.h"
20 #include "lldb/Symbol/ObjectFile.h"
21 #include "lldb/Target/DynamicLoader.h"
22 #include "lldb/Target/Target.h"
24 #include "ProcessFreeBSD.h"
25 #include "ProcessPOSIXLog.h"
26 #include "Plugins/Process/Utility/InferiorCallPOSIX.h"
27 #include "Plugins/Process/Utility/FreeBSDSignals.h"
28 #include "ProcessMonitor.h"
29 #include "FreeBSDThread.h"
31 // Other libraries and framework includes
32 #include "lldb/Breakpoint/BreakpointLocation.h"
33 #include "lldb/Breakpoint/Watchpoint.h"
34 #include "lldb/Core/Module.h"
35 #include "lldb/Core/ModuleSpec.h"
36 #include "lldb/Core/PluginManager.h"
37 #include "lldb/Core/State.h"
38 #include "lldb/Host/FileSpec.h"
39 #include "lldb/Host/Host.h"
40 #include "lldb/Symbol/ObjectFile.h"
41 #include "lldb/Target/DynamicLoader.h"
42 #include "lldb/Target/Platform.h"
43 #include "lldb/Target/Target.h"
45 #include "lldb/Host/posix/Fcntl.h"
49 using namespace lldb_private;
56 static UnixSignalsSP s_freebsd_signals_sp (new FreeBSDSignals ());
57 return s_freebsd_signals_sp;
61 //------------------------------------------------------------------------------
65 ProcessFreeBSD::CreateInstance(lldb::TargetSP target_sp,
67 const FileSpec *crash_file_path)
69 lldb::ProcessSP process_sp;
70 if (crash_file_path == NULL)
71 process_sp.reset(new ProcessFreeBSD (target_sp, listener, GetFreeBSDSignals()));
76 ProcessFreeBSD::Initialize()
78 static std::once_flag g_once_flag;
80 std::call_once(g_once_flag, []() {
81 PluginManager::RegisterPlugin(GetPluginNameStatic(),
82 GetPluginDescriptionStatic(),
84 ProcessPOSIXLog::Initialize(GetPluginNameStatic());
88 lldb_private::ConstString
89 ProcessFreeBSD::GetPluginNameStatic()
91 static ConstString g_name("freebsd");
96 ProcessFreeBSD::GetPluginDescriptionStatic()
98 return "Process plugin for FreeBSD";
101 //------------------------------------------------------------------------------
102 // ProcessInterface protocol.
104 lldb_private::ConstString
105 ProcessFreeBSD::GetPluginName()
107 return GetPluginNameStatic();
111 ProcessFreeBSD::GetPluginVersion()
117 ProcessFreeBSD::Terminate()
122 ProcessFreeBSD::DoDetach(bool keep_stopped)
127 error.SetErrorString("Detaching with keep_stopped true is not currently supported on FreeBSD.");
131 error = m_monitor->Detach(GetID());
134 SetPrivateState(eStateDetached);
140 ProcessFreeBSD::DoResume()
142 Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
144 SetPrivateState(eStateRunning);
146 Mutex::Locker lock(m_thread_list.GetMutex());
147 bool do_step = false;
149 for (tid_collection::const_iterator t_pos = m_run_tids.begin(), t_end = m_run_tids.end(); t_pos != t_end; ++t_pos)
151 m_monitor->ThreadSuspend(*t_pos, false);
153 for (tid_collection::const_iterator t_pos = m_step_tids.begin(), t_end = m_step_tids.end(); t_pos != t_end; ++t_pos)
155 m_monitor->ThreadSuspend(*t_pos, false);
158 for (tid_collection::const_iterator t_pos = m_suspend_tids.begin(), t_end = m_suspend_tids.end(); t_pos != t_end; ++t_pos)
160 m_monitor->ThreadSuspend(*t_pos, true);
161 // XXX Cannot PT_CONTINUE properly with suspended threads.
166 log->Printf("process %" PRIu64 " resuming (%s)", GetID(), do_step ? "step" : "continue");
168 m_monitor->SingleStep(GetID(), m_resume_signo);
170 m_monitor->Resume(GetID(), m_resume_signo);
176 ProcessFreeBSD::UpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list)
178 Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
180 log->Printf("ProcessFreeBSD::%s (pid = %" PRIu64 ")", __FUNCTION__, GetID());
182 std::vector<lldb::pid_t> tds;
183 if (!GetMonitor().GetCurrentThreadIDs(tds))
188 ThreadList old_thread_list_copy(old_thread_list);
189 for (size_t i = 0; i < tds.size(); ++i)
192 ThreadSP thread_sp (old_thread_list_copy.RemoveThreadByID(tid, false));
195 thread_sp.reset(new FreeBSDThread(*this, tid));
197 log->Printf("ProcessFreeBSD::%s new tid = %" PRIu64, __FUNCTION__, tid);
202 log->Printf("ProcessFreeBSD::%s existing tid = %" PRIu64, __FUNCTION__, tid);
204 new_thread_list.AddThread(thread_sp);
206 for (size_t i = 0; i < old_thread_list_copy.GetSize(false); ++i)
208 ThreadSP old_thread_sp(old_thread_list_copy.GetThreadAtIndex(i, false));
212 log->Printf("ProcessFreeBSD::%s remove tid", __FUNCTION__);
220 ProcessFreeBSD::WillResume()
223 m_suspend_tids.clear();
226 return Process::WillResume();
230 ProcessFreeBSD::SendMessage(const ProcessMessage &message)
232 Mutex::Locker lock(m_message_mutex);
234 switch (message.GetKind())
236 case ProcessMessage::eInvalidMessage:
239 case ProcessMessage::eAttachMessage:
240 SetPrivateState(eStateStopped);
243 case ProcessMessage::eLimboMessage:
244 case ProcessMessage::eExitMessage:
245 SetExitStatus(message.GetExitStatus(), NULL);
248 case ProcessMessage::eSignalMessage:
249 case ProcessMessage::eSignalDeliveredMessage:
250 case ProcessMessage::eBreakpointMessage:
251 case ProcessMessage::eTraceMessage:
252 case ProcessMessage::eWatchpointMessage:
253 case ProcessMessage::eCrashMessage:
254 SetPrivateState(eStateStopped);
257 case ProcessMessage::eNewThreadMessage:
258 llvm_unreachable("eNewThreadMessage unexpected on FreeBSD");
261 case ProcessMessage::eExecMessage:
262 SetPrivateState(eStateStopped);
266 m_message_queue.push(message);
269 //------------------------------------------------------------------------------
270 // Constructors and destructors.
272 ProcessFreeBSD::ProcessFreeBSD(lldb::TargetSP target_sp, Listener &listener, UnixSignalsSP &unix_signals_sp)
273 : Process(target_sp, listener, unix_signals_sp),
274 m_byte_order(endian::InlHostByteOrder()),
277 m_message_mutex (Mutex::eMutexTypeRecursive),
279 m_seen_initial_stop(),
282 // FIXME: Putting this code in the ctor and saving the byte order in a
283 // member variable is a hack to avoid const qual issues in GetByteOrder.
284 lldb::ModuleSP module = GetTarget().GetExecutableModule();
285 if (module && module->GetObjectFile())
286 m_byte_order = module->GetObjectFile()->GetByteOrder();
289 ProcessFreeBSD::~ProcessFreeBSD()
294 //------------------------------------------------------------------------------
297 ProcessFreeBSD::Finalize()
302 m_monitor->StopMonitor();
306 ProcessFreeBSD::CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name)
308 // For now we are just making sure the file exists for a given module
309 ModuleSP exe_module_sp(target_sp->GetExecutableModule());
310 if (exe_module_sp.get())
311 return exe_module_sp->GetFileSpec().Exists();
312 // If there is no executable module, we return true since we might be preparing to attach.
317 ProcessFreeBSD::DoAttachToProcessWithID (lldb::pid_t pid, const ProcessAttachInfo &attach_info)
320 assert(m_monitor == NULL);
322 Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
323 if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
324 log->Printf ("ProcessFreeBSD::%s(pid = %" PRIi64 ")", __FUNCTION__, GetID());
326 m_monitor = new ProcessMonitor(this, pid, error);
328 if (!error.Success())
331 PlatformSP platform_sp (GetTarget().GetPlatform ());
332 assert (platform_sp.get());
334 return error; // FIXME: Detatch?
336 // Find out what we can about this process
337 ProcessInstanceInfo process_info;
338 platform_sp->GetProcessInfo (pid, process_info);
340 // Resolve the executable module
341 ModuleSP exe_module_sp;
342 FileSpecList executable_search_paths (Target::GetDefaultExecutableSearchPaths());
343 ModuleSpec exe_module_spec(process_info.GetExecutableFile(), GetTarget().GetArchitecture());
344 error = platform_sp->ResolveExecutable(exe_module_spec,
346 executable_search_paths.GetSize() ? &executable_search_paths : NULL);
347 if (!error.Success())
350 // Fix the target architecture if necessary
351 const ArchSpec &module_arch = exe_module_sp->GetArchitecture();
352 if (module_arch.IsValid() && !GetTarget().GetArchitecture().IsExactMatch(module_arch))
353 GetTarget().SetArchitecture(module_arch);
355 // Initialize the target module list
356 GetTarget().SetExecutableModule (exe_module_sp, true);
358 SetSTDIOFileDescriptor(m_monitor->GetTerminalFD());
366 ProcessFreeBSD::WillLaunch(Module* module)
373 ProcessFreeBSD::GetFileSpec(const lldb_private::FileAction *file_action,
374 const FileSpec &default_file_spec,
375 const FileSpec &dbg_pts_file_spec)
377 FileSpec file_spec{};
379 if (file_action && file_action->GetAction() == FileAction::eFileActionOpen)
381 file_spec = file_action->GetFileSpec();
382 // By default the stdio paths passed in will be pseudo-terminal
383 // (/dev/pts). If so, convert to using a different default path
384 // instead to redirect I/O to the debugger console. This should
385 // also handle user overrides to /dev/null or a different file.
386 if (!file_spec || file_spec == dbg_pts_file_spec)
387 file_spec = default_file_spec;
393 ProcessFreeBSD::DoLaunch (Module *module,
394 ProcessLaunchInfo &launch_info)
397 assert(m_monitor == NULL);
399 FileSpec working_dir = launch_info.GetWorkingDirectory();
401 (!working_dir.ResolvePath() ||
402 working_dir.GetFileType() != FileSpec::eFileTypeDirectory))
404 error.SetErrorStringWithFormat("No such file or directory: %s",
405 working_dir.GetCString());
409 SetPrivateState(eStateLaunching);
411 const lldb_private::FileAction *file_action;
413 // Default of empty will mean to use existing open file descriptors
414 FileSpec stdin_file_spec{};
415 FileSpec stdout_file_spec{};
416 FileSpec stderr_file_spec{};
418 const FileSpec dbg_pts_file_spec{launch_info.GetPTY().GetSlaveName(NULL,0), false};
420 file_action = launch_info.GetFileActionForFD (STDIN_FILENO);
421 stdin_file_spec = GetFileSpec(file_action, stdin_file_spec, dbg_pts_file_spec);
423 file_action = launch_info.GetFileActionForFD (STDOUT_FILENO);
424 stdout_file_spec = GetFileSpec(file_action, stdout_file_spec, dbg_pts_file_spec);
426 file_action = launch_info.GetFileActionForFD (STDERR_FILENO);
427 stderr_file_spec = GetFileSpec(file_action, stderr_file_spec, dbg_pts_file_spec);
429 m_monitor = new ProcessMonitor(this,
431 launch_info.GetArguments().GetConstArgumentVector(),
432 launch_info.GetEnvironmentEntries().GetConstArgumentVector(),
442 if (!error.Success())
445 int terminal = m_monitor->GetTerminalFD();
447 // The reader thread will close the file descriptor when done, so we pass it a copy.
448 #ifdef F_DUPFD_CLOEXEC
449 int stdio = fcntl(terminal, F_DUPFD_CLOEXEC, 0);
451 error.SetErrorToErrno();
455 // Special case when F_DUPFD_CLOEXEC does not exist (Debian kFreeBSD)
456 int stdio = fcntl(terminal, F_DUPFD, 0);
458 error.SetErrorToErrno();
461 stdio = fcntl(terminal, F_SETFD, FD_CLOEXEC);
463 error.SetErrorToErrno();
467 SetSTDIOFileDescriptor(stdio);
470 SetID(m_monitor->GetPID());
475 ProcessFreeBSD::DidLaunch()
480 ProcessFreeBSD::GetImageInfoAddress()
482 Target *target = &GetTarget();
483 ObjectFile *obj_file = target->GetExecutableModule()->GetObjectFile();
484 Address addr = obj_file->GetImageInfoAddress(target);
487 return addr.GetLoadAddress(target);
488 return LLDB_INVALID_ADDRESS;
492 ProcessFreeBSD::DoHalt(bool &caused_stop)
500 else if (kill(GetID(), SIGSTOP))
503 error.SetErrorToErrno();
513 ProcessFreeBSD::DoSignal(int signal)
517 if (kill(GetID(), signal))
518 error.SetErrorToErrno();
524 ProcessFreeBSD::DoDestroy()
532 if (GetID() == LLDB_INVALID_PROCESS_ID)
534 error.SetErrorString("invalid process id");
537 if (!m_monitor->Kill())
539 error.SetErrorToErrno();
543 SetPrivateState(eStateExited);
550 ProcessFreeBSD::DoDidExec()
552 Target *target = &GetTarget();
555 PlatformSP platform_sp (target->GetPlatform());
556 assert (platform_sp.get());
559 ProcessInstanceInfo process_info;
560 platform_sp->GetProcessInfo(GetID(), process_info);
561 ModuleSP exe_module_sp;
562 ModuleSpec exe_module_spec(process_info.GetExecutableFile(), target->GetArchitecture());
563 FileSpecList executable_search_paths (Target::GetDefaultExecutableSearchPaths());
564 Error error = platform_sp->ResolveExecutable(exe_module_spec,
566 executable_search_paths.GetSize() ? &executable_search_paths : NULL);
567 if (!error.Success())
569 target->SetExecutableModule(exe_module_sp, true);
575 ProcessFreeBSD::AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid)
577 bool added_to_set = false;
578 ThreadStopSet::iterator it = m_seen_initial_stop.find(stop_tid);
579 if (it == m_seen_initial_stop.end())
581 m_seen_initial_stop.insert(stop_tid);
588 ProcessFreeBSD::WaitingForInitialStop(lldb::tid_t stop_tid)
590 return (m_seen_initial_stop.find(stop_tid) == m_seen_initial_stop.end());
594 ProcessFreeBSD::CreateNewFreeBSDThread(lldb_private::Process &process, lldb::tid_t tid)
596 return new FreeBSDThread(process, tid);
600 ProcessFreeBSD::RefreshStateAfterStop()
602 Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
603 if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
604 log->Printf ("ProcessFreeBSD::%s(), message_queue size = %d", __FUNCTION__, (int)m_message_queue.size());
606 Mutex::Locker lock(m_message_mutex);
608 // This method used to only handle one message. Changing it to loop allows
609 // it to handle the case where we hit a breakpoint while handling a different
611 while (!m_message_queue.empty())
613 ProcessMessage &message = m_message_queue.front();
615 // Resolve the thread this message corresponds to and pass it along.
616 lldb::tid_t tid = message.GetTID();
618 log->Printf ("ProcessFreeBSD::%s(), message_queue size = %d, pid = %" PRIi64, __FUNCTION__, (int)m_message_queue.size(), tid);
620 m_thread_list.RefreshStateAfterStop();
622 FreeBSDThread *thread = static_cast<FreeBSDThread*>(
623 GetThreadList().FindThreadByID(tid, false).get());
625 thread->Notify(message);
627 if (message.GetKind() == ProcessMessage::eExitMessage)
629 // FIXME: We should tell the user about this, but the limbo message is probably better for that.
631 log->Printf ("ProcessFreeBSD::%s() removing thread, tid = %" PRIi64, __FUNCTION__, tid);
633 Mutex::Locker lock(m_thread_list.GetMutex());
635 ThreadSP thread_sp = m_thread_list.RemoveThreadByID(tid, false);
637 m_seen_initial_stop.erase(tid);
640 m_message_queue.pop();
645 ProcessFreeBSD::IsAlive()
647 StateType state = GetPrivateState();
648 return state != eStateDetached
649 && state != eStateExited
650 && state != eStateInvalid
651 && state != eStateUnloaded;
655 ProcessFreeBSD::DoReadMemory(addr_t vm_addr,
656 void *buf, size_t size, Error &error)
659 return m_monitor->ReadMemory(vm_addr, buf, size, error);
663 ProcessFreeBSD::DoWriteMemory(addr_t vm_addr, const void *buf, size_t size,
667 return m_monitor->WriteMemory(vm_addr, buf, size, error);
671 ProcessFreeBSD::DoAllocateMemory(size_t size, uint32_t permissions,
674 addr_t allocated_addr = LLDB_INVALID_ADDRESS;
677 if (permissions & lldb::ePermissionsReadable)
678 prot |= eMmapProtRead;
679 if (permissions & lldb::ePermissionsWritable)
680 prot |= eMmapProtWrite;
681 if (permissions & lldb::ePermissionsExecutable)
682 prot |= eMmapProtExec;
684 if (InferiorCallMmap(this, allocated_addr, 0, size, prot,
685 eMmapFlagsAnon | eMmapFlagsPrivate, -1, 0)) {
686 m_addr_to_mmap_size[allocated_addr] = size;
689 allocated_addr = LLDB_INVALID_ADDRESS;
690 error.SetErrorStringWithFormat("unable to allocate %zu bytes of memory with permissions %s", size, GetPermissionsAsCString (permissions));
693 return allocated_addr;
697 ProcessFreeBSD::DoDeallocateMemory(lldb::addr_t addr)
700 MMapMap::iterator pos = m_addr_to_mmap_size.find(addr);
701 if (pos != m_addr_to_mmap_size.end() &&
702 InferiorCallMunmap(this, addr, pos->second))
703 m_addr_to_mmap_size.erase (pos);
705 error.SetErrorStringWithFormat("unable to deallocate memory at 0x%" PRIx64, addr);
711 ProcessFreeBSD::GetSoftwareBreakpointTrapOpcode(BreakpointSite* bp_site)
713 static const uint8_t g_aarch64_opcode[] = { 0x00, 0x00, 0x20, 0xD4 };
714 static const uint8_t g_i386_opcode[] = { 0xCC };
716 ArchSpec arch = GetTarget().GetArchitecture();
717 const uint8_t *opcode = NULL;
718 size_t opcode_size = 0;
720 switch (arch.GetMachine())
723 assert(false && "CPU type not supported!");
726 case llvm::Triple::arm:
728 // The ARM reference recommends the use of 0xe7fddefe and 0xdefe
729 // but the linux kernel does otherwise.
730 static const uint8_t g_arm_breakpoint_opcode[] = { 0xf0, 0x01, 0xf0, 0xe7 };
731 static const uint8_t g_thumb_breakpoint_opcode[] = { 0x01, 0xde };
733 lldb::BreakpointLocationSP bp_loc_sp (bp_site->GetOwnerAtIndex (0));
734 AddressClass addr_class = eAddressClassUnknown;
737 addr_class = bp_loc_sp->GetAddress ().GetAddressClass ();
739 if (addr_class == eAddressClassCodeAlternateISA
740 || (addr_class == eAddressClassUnknown
741 && bp_loc_sp->GetAddress().GetOffset() & 1))
743 opcode = g_thumb_breakpoint_opcode;
744 opcode_size = sizeof(g_thumb_breakpoint_opcode);
748 opcode = g_arm_breakpoint_opcode;
749 opcode_size = sizeof(g_arm_breakpoint_opcode);
753 case llvm::Triple::aarch64:
754 opcode = g_aarch64_opcode;
755 opcode_size = sizeof(g_aarch64_opcode);
758 case llvm::Triple::x86:
759 case llvm::Triple::x86_64:
760 opcode = g_i386_opcode;
761 opcode_size = sizeof(g_i386_opcode);
765 bp_site->SetTrapOpcode(opcode, opcode_size);
770 ProcessFreeBSD::EnableBreakpointSite(BreakpointSite *bp_site)
772 return EnableSoftwareBreakpoint(bp_site);
776 ProcessFreeBSD::DisableBreakpointSite(BreakpointSite *bp_site)
778 return DisableSoftwareBreakpoint(bp_site);
782 ProcessFreeBSD::EnableWatchpoint(Watchpoint *wp, bool notify)
787 user_id_t watchID = wp->GetID();
788 addr_t addr = wp->GetLoadAddress();
789 Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_WATCHPOINTS));
791 log->Printf ("ProcessFreeBSD::EnableWatchpoint(watchID = %" PRIu64 ")",
796 log->Printf("ProcessFreeBSD::EnableWatchpoint(watchID = %" PRIu64
797 ") addr = 0x%8.8" PRIx64 ": watchpoint already enabled.",
798 watchID, (uint64_t)addr);
802 // Try to find a vacant watchpoint slot in the inferiors' main thread
803 uint32_t wp_hw_index = LLDB_INVALID_INDEX32;
804 Mutex::Locker lock(m_thread_list.GetMutex());
805 FreeBSDThread *thread = static_cast<FreeBSDThread*>(
806 m_thread_list.GetThreadAtIndex(0, false).get());
809 wp_hw_index = thread->FindVacantWatchpointIndex();
811 if (wp_hw_index == LLDB_INVALID_INDEX32)
813 error.SetErrorString("Setting hardware watchpoint failed.");
817 wp->SetHardwareIndex(wp_hw_index);
818 bool wp_enabled = true;
819 uint32_t thread_count = m_thread_list.GetSize(false);
820 for (uint32_t i = 0; i < thread_count; ++i)
822 thread = static_cast<FreeBSDThread*>(
823 m_thread_list.GetThreadAtIndex(i, false).get());
825 wp_enabled &= thread->EnableHardwareWatchpoint(wp);
831 wp->SetEnabled(true, notify);
836 // Watchpoint enabling failed on at least one
837 // of the threads so roll back all of them
838 DisableWatchpoint(wp, false);
839 error.SetErrorString("Setting hardware watchpoint failed");
844 error.SetErrorString("Watchpoint argument was NULL.");
849 ProcessFreeBSD::DisableWatchpoint(Watchpoint *wp, bool notify)
854 user_id_t watchID = wp->GetID();
855 addr_t addr = wp->GetLoadAddress();
856 Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_WATCHPOINTS));
858 log->Printf("ProcessFreeBSD::DisableWatchpoint(watchID = %" PRIu64 ")",
860 if (!wp->IsEnabled())
863 log->Printf("ProcessFreeBSD::DisableWatchpoint(watchID = %" PRIu64
864 ") addr = 0x%8.8" PRIx64 ": watchpoint already disabled.",
865 watchID, (uint64_t)addr);
866 // This is needed (for now) to keep watchpoints disabled correctly
867 wp->SetEnabled(false, notify);
871 if (wp->IsHardware())
873 bool wp_disabled = true;
874 Mutex::Locker lock(m_thread_list.GetMutex());
875 uint32_t thread_count = m_thread_list.GetSize(false);
876 for (uint32_t i = 0; i < thread_count; ++i)
878 FreeBSDThread *thread = static_cast<FreeBSDThread*>(
879 m_thread_list.GetThreadAtIndex(i, false).get());
881 wp_disabled &= thread->DisableHardwareWatchpoint(wp);
887 wp->SetHardwareIndex(LLDB_INVALID_INDEX32);
888 wp->SetEnabled(false, notify);
892 error.SetErrorString("Disabling hardware watchpoint failed");
896 error.SetErrorString("Watchpoint argument was NULL.");
901 ProcessFreeBSD::GetWatchpointSupportInfo(uint32_t &num)
904 Mutex::Locker lock(m_thread_list.GetMutex());
905 FreeBSDThread *thread = static_cast<FreeBSDThread*>(
906 m_thread_list.GetThreadAtIndex(0, false).get());
908 num = thread->NumSupportedHardwareWatchpoints();
910 error.SetErrorString("Process does not exist.");
915 ProcessFreeBSD::GetWatchpointSupportInfo(uint32_t &num, bool &after)
917 Error error = GetWatchpointSupportInfo(num);
918 // Watchpoints trigger and halt the inferior after
919 // the corresponding instruction has been executed.
925 ProcessFreeBSD::UpdateThreadListIfNeeded()
927 Mutex::Locker lock(m_thread_list.GetMutex());
928 // Do not allow recursive updates.
929 return m_thread_list.GetSize(false);
934 ProcessFreeBSD::UpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list)
936 Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
937 if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
938 log->Printf ("ProcessFreeBSD::%s() (pid = %" PRIi64 ")", __FUNCTION__, GetID());
940 bool has_updated = false;
941 // Update the process thread list with this new thread.
942 // FIXME: We should be using tid, not pid.
944 ThreadSP thread_sp (old_thread_list.FindThreadByID (GetID(), false));
946 thread_sp.reset(CreateNewFreeBSDThread(*this, GetID()));
950 if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
951 log->Printf ("ProcessFreeBSD::%s() updated pid = %" PRIi64, __FUNCTION__, GetID());
952 new_thread_list.AddThread(thread_sp);
954 return has_updated; // the list has been updated
959 ProcessFreeBSD::GetByteOrder() const
961 // FIXME: We should be able to extract this value directly. See comment in
967 ProcessFreeBSD::PutSTDIN(const char *buf, size_t len, Error &error)
970 if ((status = write(m_monitor->GetTerminalFD(), buf, len)) < 0)
972 error.SetErrorToErrno();
978 //------------------------------------------------------------------------------
979 // Utility functions.
982 ProcessFreeBSD::HasExited()
984 switch (GetPrivateState())
998 ProcessFreeBSD::IsStopped()
1000 switch (GetPrivateState())
1007 case eStateSuspended:
1015 ProcessFreeBSD::IsAThreadRunning()
1017 bool is_running = false;
1018 Mutex::Locker lock(m_thread_list.GetMutex());
1019 uint32_t thread_count = m_thread_list.GetSize(false);
1020 for (uint32_t i = 0; i < thread_count; ++i)
1022 FreeBSDThread *thread = static_cast<FreeBSDThread*>(
1023 m_thread_list.GetThreadAtIndex(i, false).get());
1024 StateType thread_state = thread->GetState();
1025 if (thread_state == eStateRunning || thread_state == eStateStepping)
1035 ProcessFreeBSD::GetAuxvData ()
1037 // If we're the local platform, we can ask the host for auxv data.
1038 PlatformSP platform_sp = GetTarget().GetPlatform ();
1039 if (platform_sp && platform_sp->IsHost ())
1040 return lldb_private::Host::GetAuxvData(this);
1042 // Somewhat unexpected - the process is not running locally or we don't have a platform.
1043 assert (false && "no platform or not the host - how did we get here with ProcessFreeBSD?");
1044 return DataBufferSP ();