LLDB  mainline
NativeProcessFreeBSD.cpp
Go to the documentation of this file.
1 //===-- NativeProcessFreeBSD.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 "NativeProcessFreeBSD.h"
10 
11 // clang-format off
12 #include <sys/types.h>
13 #include <sys/ptrace.h>
14 #include <sys/sysctl.h>
15 #include <sys/user.h>
16 #include <sys/wait.h>
17 #include <machine/elf.h>
18 // clang-format on
19 
21 #include "lldb/Host/HostProcess.h"
23 #include "lldb/Target/Process.h"
24 #include "lldb/Utility/State.h"
25 #include "llvm/Support/Errno.h"
26 
27 using namespace lldb;
28 using namespace lldb_private;
29 using namespace lldb_private::process_freebsd;
30 using namespace llvm;
31 
32 // Simple helper function to ensure flags are enabled on the given file
33 // descriptor.
34 static Status EnsureFDFlags(int fd, int flags) {
35  Status error;
36 
37  int status = fcntl(fd, F_GETFL);
38  if (status == -1) {
39  error.SetErrorToErrno();
40  return error;
41  }
42 
43  if (fcntl(fd, F_SETFL, status | flags) == -1) {
44  error.SetErrorToErrno();
45  return error;
46  }
47 
48  return error;
49 }
50 
51 // Public Static Methods
52 
53 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
54 NativeProcessFreeBSD::Factory::Launch(ProcessLaunchInfo &launch_info,
55  NativeDelegate &native_delegate,
56  MainLoop &mainloop) const {
57  Log *log = GetLog(POSIXLog::Process);
58 
59  Status status;
61  .LaunchProcess(launch_info, status)
62  .GetProcessId();
63  LLDB_LOG(log, "pid = {0:x}", pid);
64  if (status.Fail()) {
65  LLDB_LOG(log, "failed to launch process: {0}", status);
66  return status.ToError();
67  }
68 
69  // Wait for the child process to trap on its call to execve.
70  int wstatus;
71  ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
72  assert(wpid == pid);
73  (void)wpid;
74  if (!WIFSTOPPED(wstatus)) {
75  LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
76  WaitStatus::Decode(wstatus));
77  return llvm::make_error<StringError>("Could not sync with inferior process",
78  llvm::inconvertibleErrorCode());
79  }
80  LLDB_LOG(log, "inferior started, now in stopped state");
81 
83  if (!Host::GetProcessInfo(pid, Info)) {
84  return llvm::make_error<StringError>("Cannot get process architecture",
85  llvm::inconvertibleErrorCode());
86  }
87 
88  // Set the architecture to the exe architecture.
89  LLDB_LOG(log, "pid = {0:x}, detected architecture {1}", pid,
90  Info.GetArchitecture().GetArchitectureName());
91 
92  std::unique_ptr<NativeProcessFreeBSD> process_up(new NativeProcessFreeBSD(
93  pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), native_delegate,
94  Info.GetArchitecture(), mainloop));
95 
96  status = process_up->SetupTrace();
97  if (status.Fail())
98  return status.ToError();
99 
100  for (const auto &thread : process_up->m_threads)
101  static_cast<NativeThreadFreeBSD &>(*thread).SetStoppedBySignal(SIGSTOP);
102  process_up->SetState(StateType::eStateStopped, false);
103 
104  return std::move(process_up);
105 }
106 
107 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
108 NativeProcessFreeBSD::Factory::Attach(
110  MainLoop &mainloop) const {
111  Log *log = GetLog(POSIXLog::Process);
112  LLDB_LOG(log, "pid = {0:x}", pid);
113 
114  // Retrieve the architecture for the running process.
115  ProcessInstanceInfo Info;
116  if (!Host::GetProcessInfo(pid, Info)) {
117  return llvm::make_error<StringError>("Cannot get process architecture",
118  llvm::inconvertibleErrorCode());
119  }
120 
121  std::unique_ptr<NativeProcessFreeBSD> process_up(new NativeProcessFreeBSD(
122  pid, -1, native_delegate, Info.GetArchitecture(), mainloop));
123 
124  Status status = process_up->Attach();
125  if (!status.Success())
126  return status.ToError();
127 
128  return std::move(process_up);
129 }
130 
132 NativeProcessFreeBSD::Factory::GetSupportedExtensions() const {
133  return
134 #if defined(PT_COREDUMP)
135  Extension::savecore |
136 #endif
137  Extension::multiprocess | Extension::fork | Extension::vfork |
138  Extension::pass_signals | Extension::auxv | Extension::libraries_svr4 |
139  Extension::siginfo_read;
140 }
141 
142 // Public Instance Methods
143 
144 NativeProcessFreeBSD::NativeProcessFreeBSD(::pid_t pid, int terminal_fd,
145  NativeDelegate &delegate,
146  const ArchSpec &arch,
147  MainLoop &mainloop)
148  : NativeProcessELF(pid, terminal_fd, delegate), m_arch(arch),
149  m_main_loop(mainloop) {
150  if (m_terminal_fd != -1) {
152  assert(status.Success());
153  }
154 
155  Status status;
156  m_sigchld_handle = mainloop.RegisterSignal(
157  SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
158  assert(m_sigchld_handle && status.Success());
159 }
160 
161 // Handles all waitpid events from the inferior process.
163  switch (signal) {
164  case SIGTRAP:
165  return MonitorSIGTRAP(pid);
166  case SIGSTOP:
167  return MonitorSIGSTOP(pid);
168  default:
169  return MonitorSignal(pid, signal);
170  }
171 }
172 
174  Log *log = GetLog(POSIXLog::Process);
175 
176  LLDB_LOG(log, "got exit signal({0}) , pid = {1}", status, pid);
177 
178  /* Stop Tracking All Threads attached to Process */
179  m_threads.clear();
180 
181  SetExitStatus(status, true);
182 
183  // Notify delegate that our process has exited.
185 }
186 
188  /* Stop all Threads attached to Process */
189  for (const auto &thread : m_threads) {
190  static_cast<NativeThreadFreeBSD &>(*thread).SetStoppedBySignal(SIGSTOP,
191  nullptr);
192  }
194 }
195 
197  Log *log = GetLog(POSIXLog::Process);
198  struct ptrace_lwpinfo info;
199 
200  const auto siginfo_err = PtraceWrapper(PT_LWPINFO, pid, &info, sizeof(info));
201  if (siginfo_err.Fail()) {
202  LLDB_LOG(log, "PT_LWPINFO failed {0}", siginfo_err);
203  return;
204  }
205  assert(info.pl_event == PL_EVENT_SIGNAL);
206 
207  LLDB_LOG(log, "got SIGTRAP, pid = {0}, lwpid = {1}, flags = {2:x}", pid,
208  info.pl_lwpid, info.pl_flags);
209  NativeThreadFreeBSD *thread = nullptr;
210 
211  if (info.pl_flags & (PL_FLAG_BORN | PL_FLAG_EXITED)) {
212  if (info.pl_flags & PL_FLAG_BORN) {
213  LLDB_LOG(log, "monitoring new thread, tid = {0}", info.pl_lwpid);
214  NativeThreadFreeBSD &t = AddThread(info.pl_lwpid);
215 
216  // Technically, the FreeBSD kernel copies the debug registers to new
217  // threads. However, there is a non-negligible delay between acquiring
218  // the DR values and reporting the new thread during which the user may
219  // establish a new watchpoint. In order to ensure that watchpoints
220  // established during this period are propagated to new threads,
221  // explicitly copy the DR value at the time the new thread is reported.
222  //
223  // See also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=250954
224 
226  static_cast<NativeThreadFreeBSD &>(*GetCurrentThread()));
227  if (error) {
228  LLDB_LOG_ERROR(log, std::move(error),
229  "failed to copy watchpoints to new thread {1}: {0}",
230  info.pl_lwpid);
232  return;
233  }
234  } else /*if (info.pl_flags & PL_FLAG_EXITED)*/ {
235  LLDB_LOG(log, "thread exited, tid = {0}", info.pl_lwpid);
236  RemoveThread(info.pl_lwpid);
237  }
238 
239  Status error =
240  PtraceWrapper(PT_CONTINUE, pid, reinterpret_cast<void *>(1), 0);
241  if (error.Fail())
243  return;
244  }
245 
246  if (info.pl_flags & PL_FLAG_EXEC) {
248  if (error.Fail()) {
250  return;
251  }
252 
253  // Let our delegate know we have just exec'd.
254  NotifyDidExec();
255 
256  for (const auto &thread : m_threads)
257  static_cast<NativeThreadFreeBSD &>(*thread).SetStoppedByExec();
258  SetCurrentThreadID(m_threads.front()->GetID());
260  return;
261  }
262 
263  if (info.pl_lwpid > 0) {
264  for (const auto &t : m_threads) {
265  if (t->GetID() == static_cast<lldb::tid_t>(info.pl_lwpid))
266  thread = static_cast<NativeThreadFreeBSD *>(t.get());
267  static_cast<NativeThreadFreeBSD *>(t.get())->SetStoppedWithNoReason();
268  }
269  if (!thread)
270  LLDB_LOG(log, "thread not found in m_threads, pid = {0}, LWP = {1}", pid,
271  info.pl_lwpid);
272  }
273 
274  if (info.pl_flags & PL_FLAG_FORKED) {
275  assert(thread);
276  MonitorClone(info.pl_child_pid, info.pl_flags & PL_FLAG_VFORKED, *thread);
277  return;
278  }
279 
280  if (info.pl_flags & PL_FLAG_VFORK_DONE) {
281  assert(thread);
283  thread->SetStoppedByVForkDone();
285  } else {
286  Status error =
287  PtraceWrapper(PT_CONTINUE, pid, reinterpret_cast<void *>(1), 0);
288  if (error.Fail())
290  }
291  return;
292  }
293 
294  if (info.pl_flags & PL_FLAG_SI) {
295  assert(info.pl_siginfo.si_signo == SIGTRAP);
296  LLDB_LOG(log, "SIGTRAP siginfo: si_code = {0}, pid = {1}",
297  info.pl_siginfo.si_code, info.pl_siginfo.si_pid);
298 
299  switch (info.pl_siginfo.si_code) {
300  case TRAP_BRKPT:
301  LLDB_LOG(log, "SIGTRAP/TRAP_BRKPT: si_addr: {0}",
302  info.pl_siginfo.si_addr);
303 
304  if (thread) {
305  auto thread_info =
307  if (thread_info != m_threads_stepping_with_breakpoint.end()) {
308  thread->SetStoppedByTrace();
309  Status brkpt_error = RemoveBreakpoint(thread_info->second);
310  if (brkpt_error.Fail())
311  LLDB_LOG(log, "pid = {0} remove stepping breakpoint: {1}",
312  thread_info->first, brkpt_error);
313  m_threads_stepping_with_breakpoint.erase(thread_info);
314  } else
315  thread->SetStoppedByBreakpoint();
316  FixupBreakpointPCAsNeeded(*thread);
317  SetCurrentThreadID(thread->GetID());
318  }
320  return;
321  case TRAP_TRACE:
322  LLDB_LOG(log, "SIGTRAP/TRAP_TRACE: si_addr: {0}",
323  info.pl_siginfo.si_addr);
324 
325  if (thread) {
326  auto &regctx = static_cast<NativeRegisterContextFreeBSD &>(
327  thread->GetRegisterContext());
328  uint32_t wp_index = LLDB_INVALID_INDEX32;
329  Status error = regctx.GetWatchpointHitIndex(
330  wp_index, reinterpret_cast<uintptr_t>(info.pl_siginfo.si_addr));
331  if (error.Fail())
332  LLDB_LOG(log,
333  "received error while checking for watchpoint hits, pid = "
334  "{0}, LWP = {1}, error = {2}",
335  pid, info.pl_lwpid, error);
336  if (wp_index != LLDB_INVALID_INDEX32) {
337  regctx.ClearWatchpointHit(wp_index);
338  thread->SetStoppedByWatchpoint(wp_index);
339  SetCurrentThreadID(thread->GetID());
341  break;
342  }
343 
344  thread->SetStoppedByTrace();
345  SetCurrentThreadID(thread->GetID());
346  }
347 
349  return;
350  }
351  }
352 
353  // Either user-generated SIGTRAP or an unknown event that would
354  // otherwise leave the debugger hanging.
355  LLDB_LOG(log, "unknown SIGTRAP, passing to generic handler");
356  MonitorSignal(pid, SIGTRAP);
357 }
358 
360  Log *log = GetLog(POSIXLog::Process);
361  struct ptrace_lwpinfo info;
362 
363  const auto siginfo_err = PtraceWrapper(PT_LWPINFO, pid, &info, sizeof(info));
364  if (siginfo_err.Fail()) {
365  LLDB_LOG(log, "PT_LWPINFO failed {0}", siginfo_err);
366  return;
367  }
368  assert(info.pl_event == PL_EVENT_SIGNAL);
369  // TODO: do we need to handle !PL_FLAG_SI?
370  assert(info.pl_flags & PL_FLAG_SI);
371  assert(info.pl_siginfo.si_signo == signal);
372 
373  for (const auto &abs_thread : m_threads) {
374  NativeThreadFreeBSD &thread =
375  static_cast<NativeThreadFreeBSD &>(*abs_thread);
376  assert(info.pl_lwpid >= 0);
377  if (info.pl_lwpid == 0 ||
378  static_cast<lldb::tid_t>(info.pl_lwpid) == thread.GetID()) {
379  thread.SetStoppedBySignal(info.pl_siginfo.si_signo, &info.pl_siginfo);
380  SetCurrentThreadID(thread.GetID());
381  } else
382  thread.SetStoppedWithNoReason();
383  }
385 }
386 
388  int data, int *result) {
389  Log *log = GetLog(POSIXLog::Ptrace);
390  Status error;
391  int ret;
392 
393  errno = 0;
394  ret =
395  ptrace(req, static_cast<::pid_t>(pid), static_cast<caddr_t>(addr), data);
396 
397  if (ret == -1)
398  error.SetErrorToErrno();
399 
400  if (result)
401  *result = ret;
402 
403  LLDB_LOG(log, "ptrace({0}, {1}, {2}, {3})={4:x}", req, pid, addr, data, ret);
404 
405  if (error.Fail())
406  LLDB_LOG(log, "ptrace() failed: {0}", error);
407 
408  return error;
409 }
410 
411 llvm::Expected<llvm::ArrayRef<uint8_t>>
413  static const uint8_t g_arm_opcode[] = {0xfe, 0xde, 0xff, 0xe7};
414  static const uint8_t g_thumb_opcode[] = {0x01, 0xde};
415 
416  switch (GetArchitecture().GetMachine()) {
417  case llvm::Triple::arm:
418  switch (size_hint) {
419  case 2:
420  return llvm::makeArrayRef(g_thumb_opcode);
421  case 4:
422  return llvm::makeArrayRef(g_arm_opcode);
423  default:
424  return llvm::createStringError(llvm::inconvertibleErrorCode(),
425  "Unrecognised trap opcode size hint!");
426  }
427  default:
429  }
430 }
431 
433  Log *log = GetLog(POSIXLog::Process);
434  LLDB_LOG(log, "pid {0}", GetID());
435 
436  Status ret;
437 
438  int signal = 0;
439  for (const auto &abs_thread : m_threads) {
440  assert(abs_thread && "thread list should not contain NULL threads");
441  NativeThreadFreeBSD &thread =
442  static_cast<NativeThreadFreeBSD &>(*abs_thread);
443 
444  const ResumeAction *action =
445  resume_actions.GetActionForThread(thread.GetID(), true);
446  // we need to explicit issue suspend requests, so it is simpler to map it
447  // into proper action
448  ResumeAction suspend_action{thread.GetID(), eStateSuspended,
450 
451  if (action == nullptr) {
452  LLDB_LOG(log, "no action specified for pid {0} tid {1}", GetID(),
453  thread.GetID());
454  action = &suspend_action;
455  }
456 
457  LLDB_LOG(
458  log,
459  "processing resume action state {0} signal {1} for pid {2} tid {3}",
460  action->state, action->signal, GetID(), thread.GetID());
461 
462  switch (action->state) {
463  case eStateRunning:
464  ret = thread.Resume();
465  break;
466  case eStateStepping:
467  ret = thread.SingleStep();
468  break;
469  case eStateSuspended:
470  case eStateStopped:
471  if (action->signal != LLDB_INVALID_SIGNAL_NUMBER)
472  return Status("Passing signal to suspended thread unsupported");
473 
474  ret = thread.Suspend();
475  break;
476 
477  default:
478  return Status(
479  "NativeProcessFreeBSD::%s (): unexpected state %s specified "
480  "for pid %" PRIu64 ", tid %" PRIu64,
481  __FUNCTION__, StateAsCString(action->state), GetID(), thread.GetID());
482  }
483 
484  if (!ret.Success())
485  return ret;
486  if (action->signal != LLDB_INVALID_SIGNAL_NUMBER)
487  signal = action->signal;
488  }
489 
490  ret =
491  PtraceWrapper(PT_CONTINUE, GetID(), reinterpret_cast<void *>(1), signal);
492  if (ret.Success())
493  SetState(eStateRunning, true);
494  return ret;
495 }
496 
498  Status error;
499 
500  // Do not try to stop a process that's already stopped, this may cause
501  // the SIGSTOP to get queued and stop the process again once resumed.
502  if (StateIsStoppedState(m_state, false))
503  return error;
504  if (kill(GetID(), SIGSTOP) != 0)
505  error.SetErrorToErrno();
506  return error;
507 }
508 
510  Status error;
511 
512  // Stop monitoring the inferior.
513  m_sigchld_handle.reset();
514 
515  // Tell ptrace to detach from the process.
517  return error;
518 
519  return PtraceWrapper(PT_DETACH, GetID());
520 }
521 
523  Status error;
524 
525  if (kill(GetID(), signo))
526  error.SetErrorToErrno();
527 
528  return error;
529 }
530 
532 
534  Log *log = GetLog(POSIXLog::Process);
535  LLDB_LOG(log, "pid {0}", GetID());
536 
537  Status error;
538 
539  switch (m_state) {
545  // Nothing to do - the process is already dead.
546  LLDB_LOG(log, "ignored for PID {0} due to current state: {1}", GetID(),
548  return error;
549 
557  // We can try to kill a process in these states.
558  break;
559  }
560 
561  return PtraceWrapper(PT_KILL, m_pid);
562 }
563 
565  MemoryRegionInfo &range_info) {
566 
568  // We're done.
569  return Status("unsupported");
570  }
571 
573  if (error.Fail()) {
574  return error;
575  }
576 
577  lldb::addr_t prev_base_address = 0;
578  // FIXME start by finding the last region that is <= target address using
579  // binary search. Data is sorted.
580  // There can be a ton of regions on pthreads apps with lots of threads.
581  for (auto it = m_mem_region_cache.begin(); it != m_mem_region_cache.end();
582  ++it) {
583  MemoryRegionInfo &proc_entry_info = it->first;
584  // Sanity check assumption that memory map entries are ascending.
585  assert((proc_entry_info.GetRange().GetRangeBase() >= prev_base_address) &&
586  "descending memory map entries detected, unexpected");
587  prev_base_address = proc_entry_info.GetRange().GetRangeBase();
588  UNUSED_IF_ASSERT_DISABLED(prev_base_address);
589  // If the target address comes before this entry, indicate distance to next
590  // region.
591  if (load_addr < proc_entry_info.GetRange().GetRangeBase()) {
592  range_info.GetRange().SetRangeBase(load_addr);
593  range_info.GetRange().SetByteSize(
594  proc_entry_info.GetRange().GetRangeBase() - load_addr);
595  range_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
596  range_info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
597  range_info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
598  range_info.SetMapped(MemoryRegionInfo::OptionalBool::eNo);
599  return error;
600  } else if (proc_entry_info.GetRange().Contains(load_addr)) {
601  // The target address is within the memory region we're processing here.
602  range_info = proc_entry_info;
603  return error;
604  }
605  // The target memory address comes somewhere after the region we just
606  // parsed.
607  }
608  // If we made it here, we didn't find an entry that contained the given
609  // address. Return the load_addr as start and the amount of bytes betwwen
610  // load address and the end of the memory as size.
611  range_info.GetRange().SetRangeBase(load_addr);
613  range_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
614  range_info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
615  range_info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
616  range_info.SetMapped(MemoryRegionInfo::OptionalBool::eNo);
617  return error;
618 }
619 
621  Log *log = GetLog(POSIXLog::Process);
622  // If our cache is empty, pull the latest. There should always be at least
623  // one memory region if memory region handling is supported.
624  if (!m_mem_region_cache.empty()) {
625  LLDB_LOG(log, "reusing {0} cached memory region entries",
626  m_mem_region_cache.size());
627  return Status();
628  }
629 
630  int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_VMMAP, static_cast<int>(m_pid)};
631  int ret;
632  size_t len;
633 
634  ret = ::sysctl(mib, 4, nullptr, &len, nullptr, 0);
635  if (ret != 0) {
637  return Status("sysctl() for KERN_PROC_VMMAP failed");
638  }
639 
640  std::unique_ptr<WritableMemoryBuffer> buf =
641  llvm::WritableMemoryBuffer::getNewMemBuffer(len);
642  ret = ::sysctl(mib, 4, buf->getBufferStart(), &len, nullptr, 0);
643  if (ret != 0) {
645  return Status("sysctl() for KERN_PROC_VMMAP failed");
646  }
647 
648  char *bp = buf->getBufferStart();
649  char *end = bp + len;
650  while (bp < end) {
651  auto *kv = reinterpret_cast<struct kinfo_vmentry *>(bp);
652  if (kv->kve_structsize == 0)
653  break;
654  bp += kv->kve_structsize;
655 
656  MemoryRegionInfo info;
657  info.Clear();
658  info.GetRange().SetRangeBase(kv->kve_start);
659  info.GetRange().SetRangeEnd(kv->kve_end);
660  info.SetMapped(MemoryRegionInfo::OptionalBool::eYes);
661 
662  if (kv->kve_protection & VM_PROT_READ)
663  info.SetReadable(MemoryRegionInfo::OptionalBool::eYes);
664  else
665  info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
666 
667  if (kv->kve_protection & VM_PROT_WRITE)
668  info.SetWritable(MemoryRegionInfo::OptionalBool::eYes);
669  else
670  info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
671 
672  if (kv->kve_protection & VM_PROT_EXECUTE)
673  info.SetExecutable(MemoryRegionInfo::OptionalBool::eYes);
674  else
675  info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
676 
677  if (kv->kve_path[0])
678  info.SetName(kv->kve_path);
679 
680  m_mem_region_cache.emplace_back(info,
681  FileSpec(info.GetName().GetCString()));
682  }
683 
684  if (m_mem_region_cache.empty()) {
685  // No entries after attempting to read them. This shouldn't happen. Assume
686  // we don't support map entries.
687  LLDB_LOG(log, "failed to find any vmmap entries, assuming no support "
688  "for memory region metadata retrieval");
690  return Status("not supported");
691  }
692  LLDB_LOG(log, "read {0} memory region entries from process {1}",
693  m_mem_region_cache.size(), GetID());
694  // We support memory retrieval, remember that.
696 
697  return Status();
698 }
699 
701 
703  bool hardware) {
704  if (hardware)
705  return SetHardwareBreakpoint(addr, size);
706  return SetSoftwareBreakpoint(addr, size);
707 }
708 
710  FileSpec &file_spec) {
712  if (error.Fail())
713  return error;
714 
715  FileSpec module_file_spec(module_path);
716  FileSystem::Instance().Resolve(module_file_spec);
717 
718  file_spec.Clear();
719  for (const auto &it : m_mem_region_cache) {
720  if (it.second.GetFilename() == module_file_spec.GetFilename()) {
721  file_spec = it.second;
722  return Status();
723  }
724  }
725  return Status("Module file (%s) not found in process' memory map!",
726  module_file_spec.GetFilename().AsCString());
727 }
728 
729 Status
730 NativeProcessFreeBSD::GetFileLoadAddress(const llvm::StringRef &file_name,
731  lldb::addr_t &load_addr) {
732  load_addr = LLDB_INVALID_ADDRESS;
734  if (error.Fail())
735  return error;
736 
737  FileSpec file(file_name);
738  for (const auto &it : m_mem_region_cache) {
739  if (it.second == file) {
740  load_addr = it.first.GetRange().GetRangeBase();
741  return Status();
742  }
743  }
744  return Status("No load address found for file %s.", file_name.str().c_str());
745 }
746 
748  Log *log = GetLog(POSIXLog::Process);
749  int status;
750  ::pid_t wait_pid =
751  llvm::sys::RetryAfterSignal(-1, waitpid, GetID(), &status, WNOHANG);
752 
753  if (wait_pid == 0)
754  return;
755 
756  if (wait_pid == -1) {
757  Status error(errno, eErrorTypePOSIX);
758  LLDB_LOG(log, "waitpid ({0}, &status, _) failed: {1}", GetID(), error);
759  return;
760  }
761 
762  WaitStatus wait_status = WaitStatus::Decode(status);
763  bool exited = wait_status.type == WaitStatus::Exit ||
764  (wait_status.type == WaitStatus::Signal &&
765  wait_pid == static_cast<::pid_t>(GetID()));
766 
767  LLDB_LOG(log,
768  "waitpid ({0}, &status, _) => pid = {1}, status = {2}, exited = {3}",
769  GetID(), wait_pid, status, exited);
770 
771  if (exited)
772  MonitorExited(wait_pid, wait_status);
773  else {
774  assert(wait_status.type == WaitStatus::Stop);
775  MonitorCallback(wait_pid, wait_status.status);
776  }
777 }
778 
780  for (const auto &thread : m_threads) {
781  assert(thread && "thread list should not contain NULL threads");
782  if (thread->GetID() == thread_id) {
783  // We have this thread.
784  return true;
785  }
786  }
787 
788  // We don't have this thread.
789  return false;
790 }
791 
793  Log *log = GetLog(POSIXLog::Thread);
794  LLDB_LOG(log, "pid {0} adding thread with tid {1}", GetID(), thread_id);
795 
796  assert(thread_id > 0);
797  assert(!HasThreadNoLock(thread_id) &&
798  "attempted to add a thread by id that already exists");
799 
800  // If this is the first thread, save it as the current thread
801  if (m_threads.empty())
802  SetCurrentThreadID(thread_id);
803 
804  m_threads.push_back(std::make_unique<NativeThreadFreeBSD>(*this, thread_id));
805  return static_cast<NativeThreadFreeBSD &>(*m_threads.back());
806 }
807 
809  Log *log = GetLog(POSIXLog::Thread);
810  LLDB_LOG(log, "pid {0} removing thread with tid {1}", GetID(), thread_id);
811 
812  assert(thread_id > 0);
813  assert(HasThreadNoLock(thread_id) &&
814  "attempted to remove a thread that does not exist");
815 
816  for (auto it = m_threads.begin(); it != m_threads.end(); ++it) {
817  if ((*it)->GetID() == thread_id) {
818  m_threads.erase(it);
819  break;
820  }
821  }
822 
823  if (GetCurrentThreadID() == thread_id)
824  SetCurrentThreadID(m_threads.front()->GetID());
825 }
826 
828  // Attach to the requested process.
829  // An attach will cause the thread to stop with a SIGSTOP.
830  Status status = PtraceWrapper(PT_ATTACH, m_pid);
831  if (status.Fail())
832  return status;
833 
834  int wstatus;
835  // Need to use WALLSIG otherwise we receive an error with errno=ECHLD At this
836  // point we should have a thread stopped if waitpid succeeds.
837  if ((wstatus = llvm::sys::RetryAfterSignal(-1, waitpid, m_pid, nullptr, 0)) <
838  0)
839  return Status(errno, eErrorTypePOSIX);
840 
841  // Initialize threads and tracing status
842  // NB: this needs to be called before we set thread state
843  status = SetupTrace();
844  if (status.Fail())
845  return status;
846 
847  for (const auto &thread : m_threads)
848  static_cast<NativeThreadFreeBSD &>(*thread).SetStoppedBySignal(SIGSTOP);
849 
850  // Let our process instance know the thread has stopped.
851  SetCurrentThreadID(m_threads.front()->GetID());
853  return Status();
854 }
855 
857  size_t size, size_t &bytes_read) {
858  unsigned char *dst = static_cast<unsigned char *>(buf);
859  struct ptrace_io_desc io;
860 
861  Log *log = GetLog(POSIXLog::Memory);
862  LLDB_LOG(log, "addr = {0}, buf = {1}, size = {2}", addr, buf, size);
863 
864  bytes_read = 0;
865  io.piod_op = PIOD_READ_D;
866  io.piod_len = size;
867 
868  do {
869  io.piod_offs = (void *)(addr + bytes_read);
870  io.piod_addr = dst + bytes_read;
871 
873  if (error.Fail() || io.piod_len == 0)
874  return error;
875 
876  bytes_read += io.piod_len;
877  io.piod_len = size - bytes_read;
878  } while (bytes_read < size);
879 
880  return Status();
881 }
882 
884  size_t size, size_t &bytes_written) {
885  const unsigned char *src = static_cast<const unsigned char *>(buf);
886  Status error;
887  struct ptrace_io_desc io;
888 
889  Log *log = GetLog(POSIXLog::Memory);
890  LLDB_LOG(log, "addr = {0}, buf = {1}, size = {2}", addr, buf, size);
891 
892  bytes_written = 0;
893  io.piod_op = PIOD_WRITE_D;
894  io.piod_len = size;
895 
896  do {
897  io.piod_addr =
898  const_cast<void *>(static_cast<const void *>(src + bytes_written));
899  io.piod_offs = (void *)(addr + bytes_written);
900 
902  if (error.Fail() || io.piod_len == 0)
903  return error;
904 
905  bytes_written += io.piod_len;
906  io.piod_len = size - bytes_written;
907  } while (bytes_written < size);
908 
909  return error;
910 }
911 
912 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
914  int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_AUXV, static_cast<int>(GetID())};
915  size_t auxv_size = AT_COUNT * sizeof(Elf_Auxinfo);
916  std::unique_ptr<WritableMemoryBuffer> buf =
917  llvm::WritableMemoryBuffer::getNewMemBuffer(auxv_size);
918 
919  if (::sysctl(mib, 4, buf->getBufferStart(), &auxv_size, nullptr, 0) != 0)
920  return std::error_code(errno, std::generic_category());
921 
922  return buf;
923 }
924 
926  // Enable event reporting
927  int events;
928  Status status =
929  PtraceWrapper(PT_GET_EVENT_MASK, GetID(), &events, sizeof(events));
930  if (status.Fail())
931  return status;
932  events |= PTRACE_LWP | PTRACE_FORK | PTRACE_VFORK;
933  status = PtraceWrapper(PT_SET_EVENT_MASK, GetID(), &events, sizeof(events));
934  if (status.Fail())
935  return status;
936 
937  return ReinitializeThreads();
938 }
939 
941  // Clear old threads
942  m_threads.clear();
943 
944  int num_lwps;
945  Status error = PtraceWrapper(PT_GETNUMLWPS, GetID(), nullptr, 0, &num_lwps);
946  if (error.Fail())
947  return error;
948 
949  std::vector<lwpid_t> lwp_ids;
950  lwp_ids.resize(num_lwps);
951  error = PtraceWrapper(PT_GETLWPLIST, GetID(), lwp_ids.data(),
952  lwp_ids.size() * sizeof(lwpid_t), &num_lwps);
953  if (error.Fail())
954  return error;
955 
956  // Reinitialize from scratch threads and register them in process
957  for (lwpid_t lwp : lwp_ids)
958  AddThread(lwp);
959 
960  return error;
961 }
962 
964  return !m_arch.IsMIPS();
965 }
966 
967 void NativeProcessFreeBSD::MonitorClone(::pid_t child_pid, bool is_vfork,
968  NativeThreadFreeBSD &parent_thread) {
969  Log *log = GetLog(POSIXLog::Process);
970  LLDB_LOG(log, "fork, child_pid={0}", child_pid);
971 
972  int status;
973  ::pid_t wait_pid =
974  llvm::sys::RetryAfterSignal(-1, ::waitpid, child_pid, &status, 0);
975  if (wait_pid != child_pid) {
976  LLDB_LOG(log,
977  "waiting for pid {0} failed. Assuming the pid has "
978  "disappeared in the meantime",
979  child_pid);
980  return;
981  }
982  if (WIFEXITED(status)) {
983  LLDB_LOG(log,
984  "waiting for pid {0} returned an 'exited' event. Not "
985  "tracking it.",
986  child_pid);
987  return;
988  }
989 
990  struct ptrace_lwpinfo info;
991  const auto siginfo_err = PtraceWrapper(PT_LWPINFO, child_pid, &info, sizeof(info));
992  if (siginfo_err.Fail()) {
993  LLDB_LOG(log, "PT_LWPINFO failed {0}", siginfo_err);
994  return;
995  }
996  assert(info.pl_event == PL_EVENT_SIGNAL);
997  lldb::tid_t child_tid = info.pl_lwpid;
998 
999  std::unique_ptr<NativeProcessFreeBSD> child_process{
1000  new NativeProcessFreeBSD(static_cast<::pid_t>(child_pid), m_terminal_fd,
1002  if (!is_vfork)
1003  child_process->m_software_breakpoints = m_software_breakpoints;
1004 
1005  Extension expected_ext = is_vfork ? Extension::vfork : Extension::fork;
1006  if ((m_enabled_extensions & expected_ext) == expected_ext) {
1007  child_process->SetupTrace();
1008  for (const auto &thread : child_process->m_threads)
1009  static_cast<NativeThreadFreeBSD &>(*thread).SetStoppedBySignal(SIGSTOP);
1010  child_process->SetState(StateType::eStateStopped, false);
1011 
1012  m_delegate.NewSubprocess(this, std::move(child_process));
1013  if (is_vfork)
1014  parent_thread.SetStoppedByVFork(child_pid, child_tid);
1015  else
1016  parent_thread.SetStoppedByFork(child_pid, child_tid);
1018  } else {
1019  child_process->Detach();
1020  Status pt_error =
1021  PtraceWrapper(PT_CONTINUE, GetID(), reinterpret_cast<void *>(1), 0);
1022  if (pt_error.Fail()) {
1023  LLDB_LOG_ERROR(log, pt_error.ToError(),
1024  "unable to resume parent process {1}: {0}", GetID());
1026  }
1027  }
1028 }
1029 
1030 llvm::Expected<std::string>
1031 NativeProcessFreeBSD::SaveCore(llvm::StringRef path_hint) {
1032 #if defined(PT_COREDUMP)
1033  using namespace llvm::sys::fs;
1034 
1035  llvm::SmallString<128> path{path_hint};
1036  Status error;
1037  struct ptrace_coredump pc = {};
1038 
1039  // Try with the suggested path first. If there is no suggested path or it
1040  // failed to open, use a temporary file.
1041  if (path.empty() ||
1042  openFile(path, pc.pc_fd, CD_CreateNew, FA_Write, OF_None)) {
1043  if (std::error_code errc =
1044  createTemporaryFile("lldb", "core", pc.pc_fd, path))
1045  return llvm::createStringError(errc, "Unable to create a temporary file");
1046  }
1047  error = PtraceWrapper(PT_COREDUMP, GetID(), &pc, sizeof(pc));
1048 
1049  std::error_code close_err = closeFile(pc.pc_fd);
1050  if (error.Fail())
1051  return error.ToError();
1052  if (close_err)
1053  return llvm::createStringError(
1054  close_err, "Unable to close the core dump after writing");
1055  return path.str().str();
1056 #else // !defined(PT_COREDUMP)
1057  return llvm::createStringError(
1058  llvm::inconvertibleErrorCode(),
1059  "PT_COREDUMP not supported in the FreeBSD version used to build LLDB");
1060 #endif
1061 }
lldb_private::WaitStatus::type
Type type
Definition: Host.h:45
lldb_private::NativeProcessProtocol::SetSoftwareBreakpoint
Status SetSoftwareBreakpoint(lldb::addr_t addr, uint32_t size_hint)
Definition: NativeProcessProtocol.cpp:339
lldb_private::process_freebsd::NativeThreadFreeBSD::SingleStep
Status SingleStep()
Definition: NativeThreadFreeBSD.cpp:59
lldb_private::ProcessLauncherPosixFork
Definition: ProcessLauncherPosixFork.h:16
lldb_private::ProcessInstanceInfo
Definition: ProcessInfo.h:106
lldb_private::Range::GetRangeBase
BaseType GetRangeBase() const
Definition: RangeMap.h:46
llvm
Definition: Debugger.h:50
lldb_private::process_freebsd::NativeProcessFreeBSD::Detach
Status Detach() override
Definition: NativeProcessFreeBSD.cpp:509
lldb_private::NativeProcessProtocol::NativeDelegate
Definition: NativeProcessProtocol.h:236
lldb_private::process_freebsd::NativeThreadFreeBSD::CopyWatchpointsFrom
llvm::Error CopyWatchpointsFrom(NativeThreadFreeBSD &source)
Definition: NativeThreadFreeBSD.cpp:310
lldb_private::ArchSpec
Definition: ArchSpec.h:32
lldb_private::ArchSpec::IsMIPS
bool IsMIPS() const
if MIPS architecture return true.
Definition: ArchSpec.cpp:554
UNUSED_IF_ASSERT_DISABLED
#define UNUSED_IF_ASSERT_DISABLED(x)
Definition: lldb-defines.h:126
lldb_private::NativeProcessProtocol::GetCurrentThread
NativeThreadProtocol * GetCurrentThread()
Definition: NativeProcessProtocol.h:220
lldb_private::process_freebsd::NativeProcessFreeBSD::Resume
Status Resume(const ResumeActionList &resume_actions) override
Definition: NativeProcessFreeBSD.cpp:432
LLDB_INVALID_PROCESS_ID
#define LLDB_INVALID_PROCESS_ID
Definition: lldb-defines.h:81
O_NONBLOCK
#define O_NONBLOCK
Definition: windows/PosixApi.h:29
lldb_private::NativeProcessProtocol::SetHardwareBreakpoint
virtual Status SetHardwareBreakpoint(lldb::addr_t addr, size_t size)
Definition: NativeProcessProtocol.cpp:235
lldb_private::process_freebsd::NativeProcessFreeBSD::Signal
Status Signal(int signo) override
Sends a process a UNIX signal signal.
Definition: NativeProcessFreeBSD.cpp:522
lldb_private::process_freebsd::NativeProcessFreeBSD::SetBreakpoint
Status SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware) override
Definition: NativeProcessFreeBSD.cpp:702
lldb_private::process_freebsd::NativeProcessFreeBSD
Definition: NativeProcessFreeBSD.h:30
lldb_private::MemoryRegionInfo::SetName
void SetName(const char *name)
Definition: MemoryRegionInfo.h:68
lldb::eStateAttaching
@ eStateAttaching
Process is currently trying to attach.
Definition: lldb-enumerations.h:79
lldb_private::NativeProcessProtocol::SetState
void SetState(lldb::StateType state, bool notify_delegates=true)
Definition: NativeProcessProtocol.cpp:729
lldb_private::process_freebsd::NativeProcessFreeBSD::m_supports_mem_region
LazyBool m_supports_mem_region
Definition: NativeProcessFreeBSD.h:104
HostProcess.h
lldb_private::eLazyBoolYes
@ eLazyBoolYes
Definition: lldb-private-enumerations.h:115
lldb_private::MemoryRegionInfo::Clear
void Clear()
Definition: MemoryRegionInfo.h:40
lldb_private::NativeProcessProtocol::GetCurrentThreadID
lldb::tid_t GetCurrentThreadID() const
Definition: NativeProcessProtocol.h:218
lldb_private::process_freebsd::NativeThreadFreeBSD::SetStoppedByFork
void SetStoppedByFork(lldb::pid_t child_pid, lldb::tid_t child_tid)
Definition: NativeThreadFreeBSD.cpp:133
lldb_private::process_freebsd::NativeProcessFreeBSD::Halt
Status Halt() override
Definition: NativeProcessFreeBSD.cpp:497
lldb_private::WaitStatus::Decode
static WaitStatus Decode(int wstatus)
lldb_private::process_freebsd::NativeThreadFreeBSD::SetStoppedByTrace
void SetStoppedByTrace()
Definition: NativeThreadFreeBSD.cpp:106
lldb_private::process_freebsd::NativeThreadFreeBSD::SetStoppedByVForkDone
void SetStoppedByVForkDone()
Definition: NativeThreadFreeBSD.cpp:153
lldb_private::StateAsCString
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition: State.cpp:14
lldb_private::NativeProcessProtocol::m_software_breakpoints
std::unordered_map< lldb::addr_t, SoftwareBreakpoint > m_software_breakpoints
Definition: NativeProcessProtocol.h:415
lldb_private::NativeProcessProtocol::SetExitStatus
virtual bool SetExitStatus(WaitStatus status, bool bNotifyStateChange)
Definition: NativeProcessProtocol.cpp:76
lldb_private::ResumeAction
Definition: Debug.h:19
lldb_private::ConstString::AsCString
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:192
lldb_private::process_freebsd::NativeProcessFreeBSD::SaveCore
llvm::Expected< std::string > SaveCore(llvm::StringRef path_hint) override
Write a core dump (without crashing the program).
Definition: NativeProcessFreeBSD.cpp:1031
lldb_private::FileSpec::GetFilename
const ConstString & GetFilename() const
Filename string const get accessor.
Definition: FileSpec.h:239
lldb_private::MemoryRegionInfo
Definition: MemoryRegionInfo.h:21
lldb_private::NativeProcessProtocol::m_pid
lldb::pid_t m_pid
Definition: NativeProcessProtocol.h:416
lldb_private::process_freebsd::NativeProcessFreeBSD::PopulateMemoryRegionCache
Status PopulateMemoryRegionCache()
Definition: NativeProcessFreeBSD.cpp:620
lldb_private::POSIXLog::Ptrace
@ Ptrace
lldb_private::ResumeAction::signal
int signal
Definition: Debug.h:25
lldb_private::process_freebsd::NativeProcessFreeBSD::NativeProcessFreeBSD
NativeProcessFreeBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate, const ArchSpec &arch, MainLoop &mainloop)
Definition: NativeProcessFreeBSD.cpp:144
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
pc
@ pc
Definition: CompactUnwindInfo.cpp:1251
lldb_private::MemoryRegionInfo::SetReadable
void SetReadable(OptionalBool val)
Definition: MemoryRegionInfo.h:58
lldb_private::NativeProcessProtocol::m_terminal_fd
int m_terminal_fd
Definition: NativeProcessProtocol.h:430
SIGSTOP
#define SIGSTOP
Definition: windows/PosixApi.h:32
lldb_private::process_freebsd::NativeThreadFreeBSD
Definition: NativeThreadFreeBSD.h:25
lldb_private::process_freebsd::NativeProcessFreeBSD::MonitorClone
void MonitorClone(::pid_t child_pid, bool is_vfork, NativeThreadFreeBSD &parent_thread)
Definition: NativeProcessFreeBSD.cpp:967
lldb_private::process_freebsd::NativeProcessFreeBSD::ReinitializeThreads
Status ReinitializeThreads()
Definition: NativeProcessFreeBSD.cpp:940
lldb_private::process_freebsd::NativeProcessFreeBSD::RemoveThread
void RemoveThread(lldb::tid_t thread_id)
Definition: NativeProcessFreeBSD.cpp:808
lldb_private::process_freebsd::NativeProcessFreeBSD::m_sigchld_handle
MainLoop::SignalHandleUP m_sigchld_handle
Definition: NativeProcessFreeBSD.h:101
lldb::eErrorTypePOSIX
@ eErrorTypePOSIX
POSIX error codes.
Definition: lldb-enumerations.h:311
lldb::eStateExited
@ eStateExited
Process has exited and can't be examined.
Definition: lldb-enumerations.h:91
lldb_private::NativeProcessProtocol::m_delegate
NativeDelegate & m_delegate
Definition: NativeProcessProtocol.h:427
Process.h
lldb_private::WaitStatus
Definition: Host.h:35
lldb_private::MainLoopBase
Definition: MainLoopBase.h:36
lldb_private::ResumeActionList::GetActionForThread
const ResumeAction * GetActionForThread(lldb::tid_t tid, bool default_ok) const
Definition: Debug.h:74
lldb::eStateStopped
@ eStateStopped
Process or thread is stopped and can be examined.
Definition: lldb-enumerations.h:85
lldb_private::NativeProcessProtocol::SetCurrentThreadID
void SetCurrentThreadID(lldb::tid_t tid)
Definition: NativeProcessProtocol.h:216
lldb_private::NativeProcessProtocol::GetSoftwareBreakpointTrapOpcode
virtual llvm::Expected< llvm::ArrayRef< uint8_t > > GetSoftwareBreakpointTrapOpcode(size_t size_hint)
Definition: NativeProcessProtocol.cpp:500
lldb_private::process_freebsd::NativeThreadFreeBSD::SetStoppedByExec
void SetStoppedByExec()
Definition: NativeThreadFreeBSD.cpp:112
lldb_private::process_freebsd::NativeProcessFreeBSD::MonitorSignal
void MonitorSignal(lldb::pid_t pid, int signal)
Definition: NativeProcessFreeBSD.cpp:359
lldb_private::FileSpec
Definition: FileSpec.h:55
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::Range::SetRangeEnd
void SetRangeEnd(BaseType end)
Definition: RangeMap.h:80
LLDB_INVALID_SIGNAL_NUMBER
#define LLDB_INVALID_SIGNAL_NUMBER
Definition: lldb-defines.h:84
lldb_private::Status::Success
bool Success() const
Test for success condition.
Definition: Status.cpp:287
lldb::eStateCrashed
@ eStateCrashed
Process or thread has crashed and can be examined.
Definition: lldb-enumerations.h:89
lldb_private::process_freebsd::NativeProcessFreeBSD::GetLoadedModuleFileSpec
Status GetLoadedModuleFileSpec(const char *module_path, FileSpec &file_spec) override
Definition: NativeProcessFreeBSD.cpp:709
lldb_private::StateIsStoppedState
bool StateIsStoppedState(lldb::StateType state, bool must_exist)
Check if a state represents a state where the process or thread is stopped.
Definition: State.cpp:89
lldb_private::process_freebsd::NativeProcessFreeBSD::PtraceWrapper
static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr=nullptr, int data=0, int *result=nullptr)
Definition: NativeProcessFreeBSD.cpp:387
NativeProcessFreeBSD.h
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
lldb_private::process_freebsd
Definition: NativeProcessFreeBSD.h:22
lldb_private::ResumeAction::state
lldb::StateType state
Definition: Debug.h:23
lldb_private::process_freebsd::NativeThreadFreeBSD::Suspend
Status Suspend()
Definition: NativeThreadFreeBSD.cpp:69
lldb_private::process_freebsd::NativeProcessFreeBSD::MonitorSIGSTOP
void MonitorSIGSTOP(lldb::pid_t pid)
Definition: NativeProcessFreeBSD.cpp:187
lldb_private::MemoryRegionInfo::SetExecutable
void SetExecutable(OptionalBool val)
Definition: MemoryRegionInfo.h:62
lldb::eStateConnected
@ eStateConnected
Process is connected to remote debug services, but not launched or attached to anything yet.
Definition: lldb-enumerations.h:77
lldb_private::Status::Fail
bool Fail() const
Test for error condition.
Definition: Status.cpp:181
lldb_private::NativeProcessProtocol::m_enabled_extensions
Extension m_enabled_extensions
Definition: NativeProcessProtocol.h:438
SIGTRAP
#define SIGTRAP
Definition: windows/PosixApi.h:30
lldb::eStateLaunching
@ eStateLaunching
Process is in the process of launching.
Definition: lldb-enumerations.h:80
lldb_private::process_freebsd::NativeProcessFreeBSD::WriteMemory
Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) override
Definition: NativeProcessFreeBSD.cpp:883
lldb_private::WaitStatus::status
uint8_t status
Definition: Host.h:46
lldb_private::NativeProcessProtocol::GetID
lldb::pid_t GetID() const
Definition: NativeProcessProtocol.h:183
lldb_private::NativeProcessELF::NotifyDidExec
void NotifyDidExec() override
Notify the delegate that an exec occurred.
Definition: NativeProcessELF.cpp:183
lldb_private::ProcessLauncherPosixFork::LaunchProcess
HostProcess LaunchProcess(const ProcessLaunchInfo &launch_info, Status &error) override
Definition: ProcessLauncherPosixFork.cpp:258
lldb_private::POSIXLog::Memory
@ Memory
lldb_private::process_freebsd::NativeProcessFreeBSD::ReadMemory
Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override
Definition: NativeProcessFreeBSD.cpp:856
lldb_private::NativeProcessProtocol::m_state
lldb::StateType m_state
Definition: NativeProcessProtocol.h:422
lldb_private::process_freebsd::NativeProcessFreeBSD::MonitorCallback
void MonitorCallback(lldb::pid_t pid, int signal)
Definition: NativeProcessFreeBSD.cpp:162
ProcessPOSIXLog.h
lldb_private::NativeProcessProtocol::NativeDelegate::NewSubprocess
virtual void NewSubprocess(NativeProcessProtocol *parent_process, std::unique_ptr< NativeProcessProtocol > child_process)=0
lldb::eStateDetached
@ eStateDetached
Process has been detached and can't be examined.
Definition: lldb-enumerations.h:90
lldb_private::MemoryRegionInfo::GetName
ConstString GetName() const
Definition: MemoryRegionInfo.h:54
lldb_private::NativeProcessProtocol::Extension::vfork
@ vfork
lldb_private::process_freebsd::NativeProcessFreeBSD::Attach
Status Attach()
Definition: NativeProcessFreeBSD.cpp:827
lldb_private::FileSystem::Resolve
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
Definition: common/FileSystem.cpp:235
lldb_private::HostProcess::GetProcessId
lldb::pid_t GetProcessId() const
Definition: HostProcess.cpp:25
lldb_private::process_freebsd::NativeThreadFreeBSD::SetStoppedWithNoReason
void SetStoppedWithNoReason()
Definition: NativeThreadFreeBSD.cpp:160
lldb::eStateUnloaded
@ eStateUnloaded
Process is object is valid, but not currently loaded.
Definition: lldb-enumerations.h:76
lldb_private::process_freebsd::NativeProcessFreeBSD::m_main_loop
MainLoop & m_main_loop
Definition: NativeProcessFreeBSD.h:103
lldb_private::NativeProcessProtocol::m_threads
std::vector< std::unique_ptr< NativeThreadProtocol > > m_threads
Definition: NativeProcessProtocol.h:418
lldb_private::NativeProcessProtocol::Extension::fork
@ fork
lldb_private::NativeProcessProtocol::RemoveBreakpoint
virtual Status RemoveBreakpoint(lldb::addr_t addr, bool hardware=false)
Definition: NativeProcessProtocol.cpp:636
lldb_private::ProcessLaunchInfo::GetPTY
PseudoTerminal & GetPTY()
Definition: ProcessLaunchInfo.h:122
lldb_private::MainLoopPosix::RegisterSignal
SignalHandleUP RegisterSignal(int signo, const Callback &callback, Status &error)
Definition: MainLoopPosix.cpp:276
lldb_private::MainLoopPosix
Definition: MainLoopPosix.h:27
lldb_private::MemoryRegionInfo::SetWritable
void SetWritable(OptionalBool val)
Definition: MemoryRegionInfo.h:60
lldb_private::process_freebsd::NativeThreadFreeBSD::Resume
Status Resume()
Definition: NativeThreadFreeBSD.cpp:44
EnsureFDFlags
static Status EnsureFDFlags(int fd, int flags)
Definition: NativeProcessFreeBSD.cpp:34
lldb_private::NativeProcessProtocol::Extension
Extension
Extension flag constants, returned by Factory::GetSupportedExtensions() and passed to SetEnabledExten...
Definition: NativeProcessProtocol.h:260
lldb_private::FileSpec::Clear
void Clear()
Clears the object state.
Definition: FileSpec.cpp:257
lldb_private::NativeProcessSoftwareSingleStep::m_threads_stepping_with_breakpoint
std::map< lldb::tid_t, lldb::addr_t > m_threads_stepping_with_breakpoint
Definition: NativeProcessSoftwareSingleStep.h:26
lldb_private::process_freebsd::NativeProcessFreeBSD::GetArchitecture
const ArchSpec & GetArchitecture() const override
Definition: NativeProcessFreeBSD.h:70
lldb::eStateStepping
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
Definition: lldb-enumerations.h:87
lldb::eStateSuspended
@ eStateSuspended
Process or thread is in a suspended state as far as the debugger is concerned while other processes o...
Definition: lldb-enumerations.h:92
lldb_private::NativeProcessProtocol::FixupBreakpointPCAsNeeded
void FixupBreakpointPCAsNeeded(NativeThreadProtocol &thread)
Definition: NativeProcessProtocol.cpp:586
lldb_private::process_freebsd::NativeThreadFreeBSD::SetStoppedByBreakpoint
void SetStoppedByBreakpoint()
Definition: NativeThreadFreeBSD.cpp:100
lldb_private::Status
Definition: Status.h:44
lldb_private::PseudoTerminal::ReleasePrimaryFileDescriptor
int ReleasePrimaryFileDescriptor()
Release the primary file descriptor.
Definition: PseudoTerminal.cpp:202
uint32_t
lldb_private::eLazyBoolNo
@ eLazyBoolNo
Definition: lldb-private-enumerations.h:115
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb_private::NativeThreadProtocol::GetID
lldb::tid_t GetID() const
Definition: NativeThreadProtocol.h:39
lldb_private::MemoryRegionInfo::SetMapped
void SetMapped(OptionalBool val)
Definition: MemoryRegionInfo.h:66
lldb_private::process_freebsd::NativeProcessFreeBSD::GetFileLoadAddress
Status GetFileLoadAddress(const llvm::StringRef &file_name, lldb::addr_t &load_addr) override
Definition: NativeProcessFreeBSD.cpp:730
lldb_private::Range::SetRangeBase
void SetRangeBase(BaseType b)
Definition: RangeMap.h:48
lldb_private::process_freebsd::NativeProcessFreeBSD::GetMemoryRegionInfo
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info) override
Definition: NativeProcessFreeBSD.cpp:564
lldb_private::Range::SetByteSize
void SetByteSize(SizeType s)
Definition: RangeMap.h:89
lldb_private::process_freebsd::NativeProcessFreeBSD::Kill
Status Kill() override
Definition: NativeProcessFreeBSD.cpp:533
lldb_private::process_freebsd::NativeProcessFreeBSD::GetAuxvData
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > GetAuxvData() const override
Definition: NativeProcessFreeBSD.cpp:913
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
lldb_private::ConstString::GetCString
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:215
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:337
lldb_private::process_freebsd::NativeProcessFreeBSD::MonitorSIGTRAP
void MonitorSIGTRAP(lldb::pid_t pid)
Definition: NativeProcessFreeBSD.cpp:196
lldb_private::process_freebsd::NativeProcessFreeBSD::Interrupt
Status Interrupt() override
Tells a process to interrupt all operations as if by a Ctrl-C.
Definition: NativeProcessFreeBSD.cpp:531
lldb_private::process_freebsd::NativeRegisterContextFreeBSD
Definition: NativeRegisterContextFreeBSD.h:21
lldb_private::MemoryRegionInfo::GetRange
RangeType & GetRange()
Definition: MemoryRegionInfo.h:38
lldb_private::FileSystem::Instance
static FileSystem & Instance()
Definition: common/FileSystem.cpp:46
lldb_private::WaitStatus::Signal
@ Signal
Definition: Host.h:39
lldb_private::POSIXLog::Thread
@ Thread
lldb_private::ResumeActionList
Definition: Debug.h:33
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::NativeProcessELF
Definition: NativeProcessELF.h:21
lldb_private::process_freebsd::NativeProcessFreeBSD::AddThread
NativeThreadFreeBSD & AddThread(lldb::tid_t thread_id)
Definition: NativeProcessFreeBSD.cpp:792
fork
pid_t fork(void)
Definition: windows/PosixApi.h:96
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:34
lldb_private::process_freebsd::NativeThreadFreeBSD::GetRegisterContext
NativeRegisterContextFreeBSD & GetRegisterContext() override
Definition: NativeThreadFreeBSD.cpp:247
lldb_private::process_freebsd::NativeProcessFreeBSD::SetupTrace
Status SetupTrace()
Definition: NativeProcessFreeBSD.cpp:925
lldb_private::POSIXLog::Process
@ Process
lldb_private::process_freebsd::NativeThreadFreeBSD::SetStoppedByWatchpoint
void SetStoppedByWatchpoint(uint32_t wp_index)
Definition: NativeThreadFreeBSD.cpp:118
lldb_private::process_freebsd::NativeProcessFreeBSD::UpdateThreads
size_t UpdateThreads() override
Definition: NativeProcessFreeBSD.cpp:700
lldb::eStateInvalid
@ eStateInvalid
Definition: lldb-enumerations.h:75
lldb_private::process_freebsd::NativeProcessFreeBSD::SupportHardwareSingleStepping
bool SupportHardwareSingleStepping() const
Definition: NativeProcessFreeBSD.cpp:963
lldb_private::Status::ToError
llvm::Error ToError() const
Definition: Status.cpp:89
lldb_private::process_freebsd::NativeProcessFreeBSD::MonitorExited
void MonitorExited(lldb::pid_t pid, WaitStatus status)
Definition: NativeProcessFreeBSD.cpp:173
State.h
LLDB_INVALID_INDEX32
#define LLDB_INVALID_INDEX32
Definition: lldb-defines.h:75
lldb_private::Log
Definition: Log.h:115
lldb_private::process_freebsd::NativeProcessFreeBSD::m_mem_region_cache
std::vector< std::pair< MemoryRegionInfo, FileSpec > > m_mem_region_cache
Definition: NativeProcessFreeBSD.h:105
lldb_private::process_freebsd::NativeProcessFreeBSD::SigchldHandler
void SigchldHandler()
Definition: NativeProcessFreeBSD.cpp:747
lldb_private::process_freebsd::NativeThreadFreeBSD::SetStoppedBySignal
void SetStoppedBySignal(uint32_t signo, const siginfo_t *info=nullptr)
Definition: NativeThreadFreeBSD.cpp:76
lldb_private::GetLog
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:309
lldb_private::Range::Contains
bool Contains(BaseType r) const
Definition: RangeMap.h:93
lldb
Definition: SBAddress.h:15
lldb_private::process_freebsd::NativeThreadFreeBSD::SetStoppedByVFork
void SetStoppedByVFork(lldb::pid_t child_pid, lldb::tid_t child_tid)
Definition: NativeThreadFreeBSD.cpp:143
lldb::eStateRunning
@ eStateRunning
Process or thread is running and can't be examined.
Definition: lldb-enumerations.h:86
LLDB_LOG_ERROR
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:360
lldb_private::WaitStatus::Exit
@ Exit
Definition: Host.h:37
lldb_private::process_freebsd::NativeProcessFreeBSD::m_arch
ArchSpec m_arch
Definition: NativeProcessFreeBSD.h:102
lldb_private::process_freebsd::NativeProcessFreeBSD::GetSoftwareBreakpointTrapOpcode
llvm::Expected< llvm::ArrayRef< uint8_t > > GetSoftwareBreakpointTrapOpcode(size_t size_hint) override
Definition: NativeProcessFreeBSD.cpp:412
lldb_private::WaitStatus::Stop
@ Stop
Definition: Host.h:41
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86
ProcessLauncherPosixFork.h
lldb_private::process_freebsd::NativeProcessFreeBSD::HasThreadNoLock
bool HasThreadNoLock(lldb::tid_t thread_id)
Definition: NativeProcessFreeBSD.cpp:779