LLDB  mainline
NativeProcessLinux.cpp
Go to the documentation of this file.
1 //===-- NativeProcessLinux.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 "NativeProcessLinux.h"
10 
11 #include <cerrno>
12 #include <cstdint>
13 #include <cstring>
14 #include <unistd.h>
15 
16 #include <fstream>
17 #include <mutex>
18 #include <sstream>
19 #include <string>
20 #include <unordered_map>
21 
22 #include "NativeThreadLinux.h"
25 #include "Procfs.h"
26 #include "lldb/Core/ModuleSpec.h"
27 #include "lldb/Host/Host.h"
28 #include "lldb/Host/HostProcess.h"
33 #include "lldb/Host/linux/Host.h"
34 #include "lldb/Host/linux/Ptrace.h"
35 #include "lldb/Host/linux/Uio.h"
37 #include "lldb/Symbol/ObjectFile.h"
38 #include "lldb/Target/Process.h"
39 #include "lldb/Target/Target.h"
41 #include "lldb/Utility/State.h"
42 #include "lldb/Utility/Status.h"
44 #include "llvm/ADT/ScopeExit.h"
45 #include "llvm/Support/Errno.h"
46 #include "llvm/Support/FileSystem.h"
47 #include "llvm/Support/Threading.h"
48 
49 #include <linux/unistd.h>
50 #include <sys/socket.h>
51 #include <sys/syscall.h>
52 #include <sys/types.h>
53 #include <sys/user.h>
54 #include <sys/wait.h>
55 
56 #ifdef __aarch64__
57 #include <asm/hwcap.h>
58 #include <sys/auxv.h>
59 #endif
60 
61 // Support hardware breakpoints in case it has not been defined
62 #ifndef TRAP_HWBKPT
63 #define TRAP_HWBKPT 4
64 #endif
65 
66 #ifndef HWCAP2_MTE
67 #define HWCAP2_MTE (1 << 18)
68 #endif
69 
70 using namespace lldb;
71 using namespace lldb_private;
72 using namespace lldb_private::process_linux;
73 using namespace llvm;
74 
75 // Private bits we only need internally.
76 
77 static bool ProcessVmReadvSupported() {
78  static bool is_supported;
79  static llvm::once_flag flag;
80 
81  llvm::call_once(flag, [] {
83 
84  uint32_t source = 0x47424742;
85  uint32_t dest = 0;
86 
87  struct iovec local, remote;
88  remote.iov_base = &source;
89  local.iov_base = &dest;
90  remote.iov_len = local.iov_len = sizeof source;
91 
92  // We shall try if cross-process-memory reads work by attempting to read a
93  // value from our own process.
94  ssize_t res = process_vm_readv(getpid(), &local, 1, &remote, 1, 0);
95  is_supported = (res == sizeof(source) && source == dest);
96  if (is_supported)
97  LLDB_LOG(log,
98  "Detected kernel support for process_vm_readv syscall. "
99  "Fast memory reads enabled.");
100  else
101  LLDB_LOG(log,
102  "syscall process_vm_readv failed (error: {0}). Fast memory "
103  "reads disabled.",
104  llvm::sys::StrError());
105  });
106 
107  return is_supported;
108 }
109 
110 static void MaybeLogLaunchInfo(const ProcessLaunchInfo &info) {
112  if (!log)
113  return;
114 
115  if (const FileAction *action = info.GetFileActionForFD(STDIN_FILENO))
116  LLDB_LOG(log, "setting STDIN to '{0}'", action->GetFileSpec());
117  else
118  LLDB_LOG(log, "leaving STDIN as is");
119 
120  if (const FileAction *action = info.GetFileActionForFD(STDOUT_FILENO))
121  LLDB_LOG(log, "setting STDOUT to '{0}'", action->GetFileSpec());
122  else
123  LLDB_LOG(log, "leaving STDOUT as is");
124 
125  if (const FileAction *action = info.GetFileActionForFD(STDERR_FILENO))
126  LLDB_LOG(log, "setting STDERR to '{0}'", action->GetFileSpec());
127  else
128  LLDB_LOG(log, "leaving STDERR as is");
129 
130  int i = 0;
131  for (const char **args = info.GetArguments().GetConstArgumentVector(); *args;
132  ++args, ++i)
133  LLDB_LOG(log, "arg {0}: '{1}'", i, *args);
134 }
135 
136 static void DisplayBytes(StreamString &s, void *bytes, uint32_t count) {
137  uint8_t *ptr = (uint8_t *)bytes;
138  const uint32_t loop_count = std::min<uint32_t>(DEBUG_PTRACE_MAXBYTES, count);
139  for (uint32_t i = 0; i < loop_count; i++) {
140  s.Printf("[%x]", *ptr);
141  ptr++;
142  }
143 }
144 
145 static void PtraceDisplayBytes(int &req, void *data, size_t data_size) {
147  if (!log)
148  return;
149  StreamString buf;
150 
151  switch (req) {
152  case PTRACE_POKETEXT: {
153  DisplayBytes(buf, &data, 8);
154  LLDB_LOGV(log, "PTRACE_POKETEXT {0}", buf.GetData());
155  break;
156  }
157  case PTRACE_POKEDATA: {
158  DisplayBytes(buf, &data, 8);
159  LLDB_LOGV(log, "PTRACE_POKEDATA {0}", buf.GetData());
160  break;
161  }
162  case PTRACE_POKEUSER: {
163  DisplayBytes(buf, &data, 8);
164  LLDB_LOGV(log, "PTRACE_POKEUSER {0}", buf.GetData());
165  break;
166  }
167  case PTRACE_SETREGS: {
168  DisplayBytes(buf, data, data_size);
169  LLDB_LOGV(log, "PTRACE_SETREGS {0}", buf.GetData());
170  break;
171  }
172  case PTRACE_SETFPREGS: {
173  DisplayBytes(buf, data, data_size);
174  LLDB_LOGV(log, "PTRACE_SETFPREGS {0}", buf.GetData());
175  break;
176  }
177  case PTRACE_SETSIGINFO: {
178  DisplayBytes(buf, data, sizeof(siginfo_t));
179  LLDB_LOGV(log, "PTRACE_SETSIGINFO {0}", buf.GetData());
180  break;
181  }
182  case PTRACE_SETREGSET: {
183  // Extract iov_base from data, which is a pointer to the struct iovec
184  DisplayBytes(buf, *(void **)data, data_size);
185  LLDB_LOGV(log, "PTRACE_SETREGSET {0}", buf.GetData());
186  break;
187  }
188  default: {}
189  }
190 }
191 
192 static constexpr unsigned k_ptrace_word_size = sizeof(void *);
193 static_assert(sizeof(long) >= k_ptrace_word_size,
194  "Size of long must be larger than ptrace word size");
195 
196 // Simple helper function to ensure flags are enabled on the given file
197 // descriptor.
198 static Status EnsureFDFlags(int fd, int flags) {
199  Status error;
200 
201  int status = fcntl(fd, F_GETFL);
202  if (status == -1) {
203  error.SetErrorToErrno();
204  return error;
205  }
206 
207  if (fcntl(fd, F_SETFL, status | flags) == -1) {
208  error.SetErrorToErrno();
209  return error;
210  }
211 
212  return error;
213 }
214 
215 // Public Static Methods
216 
217 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
218 NativeProcessLinux::Factory::Launch(ProcessLaunchInfo &launch_info,
219  NativeDelegate &native_delegate,
220  MainLoop &mainloop) const {
222 
223  MaybeLogLaunchInfo(launch_info);
224 
225  Status status;
227  .LaunchProcess(launch_info, status)
228  .GetProcessId();
229  LLDB_LOG(log, "pid = {0:x}", pid);
230  if (status.Fail()) {
231  LLDB_LOG(log, "failed to launch process: {0}", status);
232  return status.ToError();
233  }
234 
235  // Wait for the child process to trap on its call to execve.
236  int wstatus;
237  ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
238  assert(wpid == pid);
239  (void)wpid;
240  if (!WIFSTOPPED(wstatus)) {
241  LLDB_LOG(log, "Could not sync with inferior process: wstatus={1}",
242  WaitStatus::Decode(wstatus));
243  return llvm::make_error<StringError>("Could not sync with inferior process",
244  llvm::inconvertibleErrorCode());
245  }
246  LLDB_LOG(log, "inferior started, now in stopped state");
247 
248  ProcessInstanceInfo Info;
249  if (!Host::GetProcessInfo(pid, Info)) {
250  return llvm::make_error<StringError>("Cannot get process architecture",
251  llvm::inconvertibleErrorCode());
252  }
253 
254  // Set the architecture to the exe architecture.
255  LLDB_LOG(log, "pid = {0:x}, detected architecture {1}", pid,
256  Info.GetArchitecture().GetArchitectureName());
257 
258  status = SetDefaultPtraceOpts(pid);
259  if (status.Fail()) {
260  LLDB_LOG(log, "failed to set default ptrace options: {0}", status);
261  return status.ToError();
262  }
263 
264  return std::unique_ptr<NativeProcessLinux>(new NativeProcessLinux(
265  pid, launch_info.GetPTY().ReleasePrimaryFileDescriptor(), native_delegate,
266  Info.GetArchitecture(), mainloop, {pid}));
267 }
268 
269 llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
270 NativeProcessLinux::Factory::Attach(
272  MainLoop &mainloop) const {
274  LLDB_LOG(log, "pid = {0:x}", pid);
275 
276  // Retrieve the architecture for the running process.
277  ProcessInstanceInfo Info;
278  if (!Host::GetProcessInfo(pid, Info)) {
279  return llvm::make_error<StringError>("Cannot get process architecture",
280  llvm::inconvertibleErrorCode());
281  }
282 
283  auto tids_or = NativeProcessLinux::Attach(pid);
284  if (!tids_or)
285  return tids_or.takeError();
286 
287  return std::unique_ptr<NativeProcessLinux>(new NativeProcessLinux(
288  pid, -1, native_delegate, Info.GetArchitecture(), mainloop, *tids_or));
289 }
290 
292 NativeProcessLinux::Factory::GetSupportedExtensions() const {
294  Extension::multiprocess | Extension::fork | Extension::vfork |
295  Extension::pass_signals | Extension::auxv | Extension::libraries_svr4 |
296  Extension::siginfo_read;
297 
298 #ifdef __aarch64__
299  // At this point we do not have a process so read auxv directly.
300  if ((getauxval(AT_HWCAP2) & HWCAP2_MTE))
301  supported |= Extension::memory_tagging;
302 #endif
303 
304  return supported;
305 }
306 
307 // Public Instance Methods
308 
309 NativeProcessLinux::NativeProcessLinux(::pid_t pid, int terminal_fd,
310  NativeDelegate &delegate,
311  const ArchSpec &arch, MainLoop &mainloop,
312  llvm::ArrayRef<::pid_t> tids)
313  : NativeProcessELF(pid, terminal_fd, delegate), m_arch(arch),
314  m_main_loop(mainloop), m_intel_pt_manager(pid) {
315  if (m_terminal_fd != -1) {
317  assert(status.Success());
318  }
319 
320  Status status;
321  m_sigchld_handle = mainloop.RegisterSignal(
322  SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
323  assert(m_sigchld_handle && status.Success());
324 
325  for (const auto &tid : tids) {
326  NativeThreadLinux &thread = AddThread(tid, /*resume*/ false);
327  ThreadWasCreated(thread);
328  }
329 
330  // Let our process instance know the thread has stopped.
331  SetCurrentThreadID(tids[0]);
333 
334  // Proccess any signals we received before installing our handler
335  SigchldHandler();
336 }
337 
338 llvm::Expected<std::vector<::pid_t>> NativeProcessLinux::Attach(::pid_t pid) {
340 
341  Status status;
342  // Use a map to keep track of the threads which we have attached/need to
343  // attach.
344  Host::TidMap tids_to_attach;
345  while (Host::FindProcessThreads(pid, tids_to_attach)) {
346  for (Host::TidMap::iterator it = tids_to_attach.begin();
347  it != tids_to_attach.end();) {
348  if (it->second == false) {
349  lldb::tid_t tid = it->first;
350 
351  // Attach to the requested process.
352  // An attach will cause the thread to stop with a SIGSTOP.
353  if ((status = PtraceWrapper(PTRACE_ATTACH, tid)).Fail()) {
354  // No such thread. The thread may have exited. More error handling
355  // may be needed.
356  if (status.GetError() == ESRCH) {
357  it = tids_to_attach.erase(it);
358  continue;
359  }
360  return status.ToError();
361  }
362 
363  int wpid =
364  llvm::sys::RetryAfterSignal(-1, ::waitpid, tid, nullptr, __WALL);
365  // Need to use __WALL otherwise we receive an error with errno=ECHLD At
366  // this point we should have a thread stopped if waitpid succeeds.
367  if (wpid < 0) {
368  // No such thread. The thread may have exited. More error handling
369  // may be needed.
370  if (errno == ESRCH) {
371  it = tids_to_attach.erase(it);
372  continue;
373  }
374  return llvm::errorCodeToError(
375  std::error_code(errno, std::generic_category()));
376  }
377 
378  if ((status = SetDefaultPtraceOpts(tid)).Fail())
379  return status.ToError();
380 
381  LLDB_LOG(log, "adding tid = {0}", tid);
382  it->second = true;
383  }
384 
385  // move the loop forward
386  ++it;
387  }
388  }
389 
390  size_t tid_count = tids_to_attach.size();
391  if (tid_count == 0)
392  return llvm::make_error<StringError>("No such process",
393  llvm::inconvertibleErrorCode());
394 
395  std::vector<::pid_t> tids;
396  tids.reserve(tid_count);
397  for (const auto &p : tids_to_attach)
398  tids.push_back(p.first);
399  return std::move(tids);
400 }
401 
403  long ptrace_opts = 0;
404 
405  // Have the child raise an event on exit. This is used to keep the child in
406  // limbo until it is destroyed.
407  ptrace_opts |= PTRACE_O_TRACEEXIT;
408 
409  // Have the tracer trace threads which spawn in the inferior process.
410  ptrace_opts |= PTRACE_O_TRACECLONE;
411 
412  // Have the tracer notify us before execve returns (needed to disable legacy
413  // SIGTRAP generation)
414  ptrace_opts |= PTRACE_O_TRACEEXEC;
415 
416  // Have the tracer trace forked children.
417  ptrace_opts |= PTRACE_O_TRACEFORK;
418 
419  // Have the tracer trace vforks.
420  ptrace_opts |= PTRACE_O_TRACEVFORK;
421 
422  // Have the tracer trace vfork-done in order to restore breakpoints after
423  // the child finishes sharing memory.
424  ptrace_opts |= PTRACE_O_TRACEVFORKDONE;
425 
426  return PtraceWrapper(PTRACE_SETOPTIONS, pid, nullptr, (void *)ptrace_opts);
427 }
428 
429 // Handles all waitpid events from the inferior process.
431  WaitStatus status) {
433 
434  // Certain activities differ based on whether the pid is the tid of the main
435  // thread.
436  const bool is_main_thread = (thread.GetID() == GetID());
437 
438  // Handle when the thread exits.
439  if (status.type == WaitStatus::Exit || status.type == WaitStatus::Signal) {
440  LLDB_LOG(log,
441  "got exit status({0}) , tid = {1} ({2} main thread), process "
442  "state = {3}",
443  status, thread.GetID(), is_main_thread ? "is" : "is not",
444  GetState());
445 
446  // This is a thread that exited. Ensure we're not tracking it anymore.
447  StopTrackingThread(thread);
448 
449  if (is_main_thread) {
450  // The main thread exited. We're done monitoring. Report to delegate.
451  SetExitStatus(status, true);
452 
453  // Notify delegate that our process has exited.
455  }
456  return;
457  }
458 
459  siginfo_t info;
460  const auto info_err = GetSignalInfo(thread.GetID(), &info);
461 
462  // Get details on the signal raised.
463  if (info_err.Success()) {
464  // We have retrieved the signal info. Dispatch appropriately.
465  if (info.si_signo == SIGTRAP)
466  MonitorSIGTRAP(info, thread);
467  else
468  MonitorSignal(info, thread);
469  } else {
470  if (info_err.GetError() == EINVAL) {
471  // This is a group stop reception for this tid. We can reach here if we
472  // reinject SIGSTOP, SIGSTP, SIGTTIN or SIGTTOU into the tracee,
473  // triggering the group-stop mechanism. Normally receiving these would
474  // stop the process, pending a SIGCONT. Simulating this state in a
475  // debugger is hard and is generally not needed (one use case is
476  // debugging background task being managed by a shell). For general use,
477  // it is sufficient to stop the process in a signal-delivery stop which
478  // happens before the group stop. This done by MonitorSignal and works
479  // correctly for all signals.
480  LLDB_LOG(log,
481  "received a group stop for pid {0} tid {1}. Transparent "
482  "handling of group stops not supported, resuming the "
483  "thread.",
484  GetID(), thread.GetID());
486  } else {
487  // ptrace(GETSIGINFO) failed (but not due to group-stop).
488 
489  // A return value of ESRCH means the thread/process has died in the mean
490  // time. This can (e.g.) happen when another thread does an exit_group(2)
491  // or the entire process get SIGKILLed.
492  // We can't do anything with this thread anymore, but we keep it around
493  // until we get the WIFEXITED event.
494 
495  LLDB_LOG(log,
496  "GetSignalInfo({0}) failed: {1}, status = {2}, main_thread = "
497  "{3}. Expecting WIFEXITED soon.",
498  thread.GetID(), info_err, status, is_main_thread);
499  }
500  }
501 }
502 
505 
506  // The PID is not tracked yet, let's wait for it to appear.
507  int status = -1;
508  LLDB_LOG(log,
509  "received clone event for pid {0}. pid not tracked yet, "
510  "waiting for it to appear...",
511  pid);
512  ::pid_t wait_pid =
513  llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &status, __WALL);
514 
515  // It's theoretically possible to get other events if the entire process was
516  // SIGKILLed before we got a chance to check this. In that case, we'll just
517  // clean everything up when we get the process exit event.
518 
519  LLDB_LOG(log,
520  "waitpid({0}, &status, __WALL) => {1} (errno: {2}, status = {3})",
521  pid, wait_pid, errno, WaitStatus::Decode(status));
522 }
523 
524 void NativeProcessLinux::MonitorSIGTRAP(const siginfo_t &info,
525  NativeThreadLinux &thread) {
527  const bool is_main_thread = (thread.GetID() == GetID());
528 
529  assert(info.si_signo == SIGTRAP && "Unexpected child signal!");
530 
531  switch (info.si_code) {
532  case (SIGTRAP | (PTRACE_EVENT_FORK << 8)):
533  case (SIGTRAP | (PTRACE_EVENT_VFORK << 8)):
534  case (SIGTRAP | (PTRACE_EVENT_CLONE << 8)): {
535  // This can either mean a new thread or a new process spawned via
536  // clone(2) without SIGCHLD or CLONE_VFORK flag. Note that clone(2)
537  // can also cause PTRACE_EVENT_FORK and PTRACE_EVENT_VFORK if one
538  // of these flags are passed.
539 
540  unsigned long event_message = 0;
541  if (GetEventMessage(thread.GetID(), &event_message).Fail()) {
542  LLDB_LOG(log,
543  "pid {0} received clone() event but GetEventMessage failed "
544  "so we don't know the new pid/tid",
545  thread.GetID());
547  } else {
548  MonitorClone(thread, event_message, info.si_code >> 8);
549  }
550 
551  break;
552  }
553 
554  case (SIGTRAP | (PTRACE_EVENT_EXEC << 8)): {
555  LLDB_LOG(log, "received exec event, code = {0}", info.si_code ^ SIGTRAP);
556 
557  // Exec clears any pending notifications.
559 
560  // Remove all but the main thread here. Linux fork creates a new process
561  // which only copies the main thread.
562  LLDB_LOG(log, "exec received, stop tracking all but main thread");
563 
564  llvm::erase_if(m_threads, [&](std::unique_ptr<NativeThreadProtocol> &t) {
565  return t->GetID() != GetID();
566  });
567  assert(m_threads.size() == 1);
568  auto *main_thread = static_cast<NativeThreadLinux *>(m_threads[0].get());
569 
570  SetCurrentThreadID(main_thread->GetID());
571  main_thread->SetStoppedByExec();
572 
573  // Tell coordinator about about the "new" (since exec) stopped main thread.
574  ThreadWasCreated(*main_thread);
575 
576  // Let our delegate know we have just exec'd.
577  NotifyDidExec();
578 
579  // Let the process know we're stopped.
580  StopRunningThreads(main_thread->GetID());
581 
582  break;
583  }
584 
585  case (SIGTRAP | (PTRACE_EVENT_EXIT << 8)): {
586  // The inferior process or one of its threads is about to exit. We don't
587  // want to do anything with the thread so we just resume it. In case we
588  // want to implement "break on thread exit" functionality, we would need to
589  // stop here.
590 
591  unsigned long data = 0;
592  if (GetEventMessage(thread.GetID(), &data).Fail())
593  data = -1;
594 
595  LLDB_LOG(log,
596  "received PTRACE_EVENT_EXIT, data = {0:x}, WIFEXITED={1}, "
597  "WIFSIGNALED={2}, pid = {3}, main_thread = {4}",
598  data, WIFEXITED(data), WIFSIGNALED(data), thread.GetID(),
599  is_main_thread);
600 
601 
602  StateType state = thread.GetState();
603  if (!StateIsRunningState(state)) {
604  // Due to a kernel bug, we may sometimes get this stop after the inferior
605  // gets a SIGKILL. This confuses our state tracking logic in
606  // ResumeThread(), since normally, we should not be receiving any ptrace
607  // events while the inferior is stopped. This makes sure that the
608  // inferior is resumed and exits normally.
609  state = eStateRunning;
610  }
612 
613  break;
614  }
615 
616  case (SIGTRAP | (PTRACE_EVENT_VFORK_DONE << 8)): {
618  thread.SetStoppedByVForkDone();
619  StopRunningThreads(thread.GetID());
620  }
621  else
623  break;
624  }
625 
626  case 0:
627  case TRAP_TRACE: // We receive this on single stepping.
628  case TRAP_HWBKPT: // We receive this on watchpoint hit
629  {
630  // If a watchpoint was hit, report it
631  uint32_t wp_index;
633  wp_index, (uintptr_t)info.si_addr);
634  if (error.Fail())
635  LLDB_LOG(log,
636  "received error while checking for watchpoint hits, pid = "
637  "{0}, error = {1}",
638  thread.GetID(), error);
639  if (wp_index != LLDB_INVALID_INDEX32) {
640  MonitorWatchpoint(thread, wp_index);
641  break;
642  }
643 
644  // If a breakpoint was hit, report it
645  uint32_t bp_index;
647  bp_index, (uintptr_t)info.si_addr);
648  if (error.Fail())
649  LLDB_LOG(log, "received error while checking for hardware "
650  "breakpoint hits, pid = {0}, error = {1}",
651  thread.GetID(), error);
652  if (bp_index != LLDB_INVALID_INDEX32) {
653  MonitorBreakpoint(thread);
654  break;
655  }
656 
657  // Otherwise, report step over
658  MonitorTrace(thread);
659  break;
660  }
661 
662  case SI_KERNEL:
663 #if defined __mips__
664  // For mips there is no special signal for watchpoint So we check for
665  // watchpoint in kernel trap
666  {
667  // If a watchpoint was hit, report it
668  uint32_t wp_index;
670  wp_index, LLDB_INVALID_ADDRESS);
671  if (error.Fail())
672  LLDB_LOG(log,
673  "received error while checking for watchpoint hits, pid = "
674  "{0}, error = {1}",
675  thread.GetID(), error);
676  if (wp_index != LLDB_INVALID_INDEX32) {
677  MonitorWatchpoint(thread, wp_index);
678  break;
679  }
680  }
681 // NO BREAK
682 #endif
683  case TRAP_BRKPT:
684  MonitorBreakpoint(thread);
685  break;
686 
687  case SIGTRAP:
688  case (SIGTRAP | 0x80):
689  LLDB_LOG(
690  log,
691  "received unknown SIGTRAP stop event ({0}, pid {1} tid {2}, resuming",
692  info.si_code, GetID(), thread.GetID());
693 
694  // Ignore these signals until we know more about them.
696  break;
697 
698  default:
699  LLDB_LOG(log, "received unknown SIGTRAP stop event ({0}, pid {1} tid {2}",
700  info.si_code, GetID(), thread.GetID());
701  MonitorSignal(info, thread);
702  break;
703  }
704 }
705 
708  LLDB_LOG(log, "received trace event, pid = {0}", thread.GetID());
709 
710  // This thread is currently stopped.
711  thread.SetStoppedByTrace();
712 
713  StopRunningThreads(thread.GetID());
714 }
715 
717  Log *log(
719  LLDB_LOG(log, "received breakpoint event, pid = {0}", thread.GetID());
720 
721  // Mark the thread as stopped at breakpoint.
722  thread.SetStoppedByBreakpoint();
724 
725  if (m_threads_stepping_with_breakpoint.find(thread.GetID()) !=
727  thread.SetStoppedByTrace();
728 
729  StopRunningThreads(thread.GetID());
730 }
731 
733  uint32_t wp_index) {
734  Log *log(
736  LLDB_LOG(log, "received watchpoint event, pid = {0}, wp_index = {1}",
737  thread.GetID(), wp_index);
738 
739  // Mark the thread as stopped at watchpoint. The address is at
740  // (lldb::addr_t)info->si_addr if we need it.
741  thread.SetStoppedByWatchpoint(wp_index);
742 
743  // We need to tell all other running threads before we notify the delegate
744  // about this stop.
745  StopRunningThreads(thread.GetID());
746 }
747 
748 void NativeProcessLinux::MonitorSignal(const siginfo_t &info,
749  NativeThreadLinux &thread) {
750  const int signo = info.si_signo;
751  const bool is_from_llgs = info.si_pid == getpid();
752 
754 
755  // POSIX says that process behaviour is undefined after it ignores a SIGFPE,
756  // SIGILL, SIGSEGV, or SIGBUS *unless* that signal was generated by a kill(2)
757  // or raise(3). Similarly for tgkill(2) on Linux.
758  //
759  // IOW, user generated signals never generate what we consider to be a
760  // "crash".
761  //
762  // Similarly, ACK signals generated by this monitor.
763 
764  // Handle the signal.
765  LLDB_LOG(log,
766  "received signal {0} ({1}) with code {2}, (siginfo pid = {3}, "
767  "waitpid pid = {4})",
768  Host::GetSignalAsCString(signo), signo, info.si_code,
769  thread.GetID());
770 
771  // Check for thread stop notification.
772  if (is_from_llgs && (info.si_code == SI_TKILL) && (signo == SIGSTOP)) {
773  // This is a tgkill()-based stop.
774  LLDB_LOG(log, "pid {0} tid {1}, thread stopped", GetID(), thread.GetID());
775 
776  // Check that we're not already marked with a stop reason. Note this thread
777  // really shouldn't already be marked as stopped - if we were, that would
778  // imply that the kernel signaled us with the thread stopping which we
779  // handled and marked as stopped, and that, without an intervening resume,
780  // we received another stop. It is more likely that we are missing the
781  // marking of a run state somewhere if we find that the thread was marked
782  // as stopped.
783  const StateType thread_state = thread.GetState();
784  if (!StateIsStoppedState(thread_state, false)) {
785  // An inferior thread has stopped because of a SIGSTOP we have sent it.
786  // Generally, these are not important stops and we don't want to report
787  // them as they are just used to stop other threads when one thread (the
788  // one with the *real* stop reason) hits a breakpoint (watchpoint,
789  // etc...). However, in the case of an asynchronous Interrupt(), this
790  // *is* the real stop reason, so we leave the signal intact if this is
791  // the thread that was chosen as the triggering thread.
793  if (m_pending_notification_tid == thread.GetID())
794  thread.SetStoppedBySignal(SIGSTOP, &info);
795  else
796  thread.SetStoppedWithNoReason();
797 
798  SetCurrentThreadID(thread.GetID());
800  } else {
801  // We can end up here if stop was initiated by LLGS but by this time a
802  // thread stop has occurred - maybe initiated by another event.
803  Status error = ResumeThread(thread, thread.GetState(), 0);
804  if (error.Fail())
805  LLDB_LOG(log, "failed to resume thread {0}: {1}", thread.GetID(),
806  error);
807  }
808  } else {
809  LLDB_LOG(log,
810  "pid {0} tid {1}, thread was already marked as a stopped "
811  "state (state={2}), leaving stop signal as is",
812  GetID(), thread.GetID(), thread_state);
814  }
815 
816  // Done handling.
817  return;
818  }
819 
820  // Check if debugger should stop at this signal or just ignore it and resume
821  // the inferior.
822  if (m_signals_to_ignore.contains(signo)) {
823  ResumeThread(thread, thread.GetState(), signo);
824  return;
825  }
826 
827  // This thread is stopped.
828  LLDB_LOG(log, "received signal {0}", Host::GetSignalAsCString(signo));
829  thread.SetStoppedBySignal(signo, &info);
830 
831  // Send a stop to the debugger after we get all other threads to stop.
832  StopRunningThreads(thread.GetID());
833 }
834 
836  lldb::pid_t child_pid, int event) {
838  LLDB_LOG(log, "parent_tid={0}, child_pid={1}, event={2}", parent.GetID(),
839  child_pid, event);
840 
841  WaitForCloneNotification(child_pid);
842 
843  switch (event) {
844  case PTRACE_EVENT_CLONE: {
845  // PTRACE_EVENT_CLONE can either mean a new thread or a new process.
846  // Try to grab the new process' PGID to figure out which one it is.
847  // If PGID is the same as the PID, then it's a new process. Otherwise,
848  // it's a thread.
849  auto tgid_ret = getPIDForTID(child_pid);
850  if (tgid_ret != child_pid) {
851  // A new thread should have PGID matching our process' PID.
852  assert(!tgid_ret || tgid_ret.getValue() == GetID());
853 
854  NativeThreadLinux &child_thread = AddThread(child_pid, /*resume*/ true);
855  ThreadWasCreated(child_thread);
856 
857  // Resume the parent.
859  break;
860  }
861  }
862  LLVM_FALLTHROUGH;
863  case PTRACE_EVENT_FORK:
864  case PTRACE_EVENT_VFORK: {
865  bool is_vfork = event == PTRACE_EVENT_VFORK;
866  std::unique_ptr<NativeProcessLinux> child_process{new NativeProcessLinux(
867  static_cast<::pid_t>(child_pid), m_terminal_fd, m_delegate, m_arch,
868  m_main_loop, {static_cast<::pid_t>(child_pid)})};
869  if (!is_vfork)
870  child_process->m_software_breakpoints = m_software_breakpoints;
871 
872  Extension expected_ext = is_vfork ? Extension::vfork : Extension::fork;
873  if (bool(m_enabled_extensions & expected_ext)) {
874  m_delegate.NewSubprocess(this, std::move(child_process));
875  // NB: non-vfork clone() is reported as fork
876  parent.SetStoppedByFork(is_vfork, child_pid);
877  StopRunningThreads(parent.GetID());
878  } else {
879  child_process->Detach();
881  }
882  break;
883  }
884  default:
885  llvm_unreachable("unknown clone_info.event");
886  }
887 
888  return true;
889 }
890 
892  if (m_arch.GetMachine() == llvm::Triple::arm || m_arch.IsMIPS())
893  return false;
894  return true;
895 }
896 
899  LLDB_LOG(log, "pid {0}", GetID());
900 
901  bool software_single_step = !SupportHardwareSingleStepping();
902 
903  if (software_single_step) {
904  for (const auto &thread : m_threads) {
905  assert(thread && "thread list should not contain NULL threads");
906 
907  const ResumeAction *const action =
908  resume_actions.GetActionForThread(thread->GetID(), true);
909  if (action == nullptr)
910  continue;
911 
912  if (action->state == eStateStepping) {
914  static_cast<NativeThreadLinux &>(*thread));
915  if (error.Fail())
916  return error;
917  }
918  }
919  }
920 
921  for (const auto &thread : m_threads) {
922  assert(thread && "thread list should not contain NULL threads");
923 
924  const ResumeAction *const action =
925  resume_actions.GetActionForThread(thread->GetID(), true);
926 
927  if (action == nullptr) {
928  LLDB_LOG(log, "no action specified for pid {0} tid {1}", GetID(),
929  thread->GetID());
930  continue;
931  }
932 
933  LLDB_LOG(log, "processing resume action state {0} for pid {1} tid {2}",
934  action->state, GetID(), thread->GetID());
935 
936  switch (action->state) {
937  case eStateRunning:
938  case eStateStepping: {
939  // Run the thread, possibly feeding it the signal.
940  const int signo = action->signal;
941  ResumeThread(static_cast<NativeThreadLinux &>(*thread), action->state,
942  signo);
943  break;
944  }
945 
946  case eStateSuspended:
947  case eStateStopped:
948  llvm_unreachable("Unexpected state");
949 
950  default:
951  return Status("NativeProcessLinux::%s (): unexpected state %s specified "
952  "for pid %" PRIu64 ", tid %" PRIu64,
953  __FUNCTION__, StateAsCString(action->state), GetID(),
954  thread->GetID());
955  }
956  }
957 
958  return Status();
959 }
960 
962  Status error;
963 
964  if (kill(GetID(), SIGSTOP) != 0)
965  error.SetErrorToErrno();
966 
967  return error;
968 }
969 
971  Status error;
972 
973  // Stop monitoring the inferior.
974  m_sigchld_handle.reset();
975 
976  // Tell ptrace to detach from the process.
978  return error;
979 
980  for (const auto &thread : m_threads) {
981  Status e = Detach(thread->GetID());
982  if (e.Fail())
983  error =
984  e; // Save the error, but still attempt to detach from other threads.
985  }
986 
988 
989  return error;
990 }
991 
993  Status error;
994 
996  LLDB_LOG(log, "sending signal {0} ({1}) to pid {1}", signo,
997  Host::GetSignalAsCString(signo), GetID());
998 
999  if (kill(GetID(), signo))
1000  error.SetErrorToErrno();
1001 
1002  return error;
1003 }
1004 
1006  // Pick a running thread (or if none, a not-dead stopped thread) as the
1007  // chosen thread that will be the stop-reason thread.
1009 
1010  NativeThreadProtocol *running_thread = nullptr;
1011  NativeThreadProtocol *stopped_thread = nullptr;
1012 
1013  LLDB_LOG(log, "selecting running thread for interrupt target");
1014  for (const auto &thread : m_threads) {
1015  // If we have a running or stepping thread, we'll call that the target of
1016  // the interrupt.
1017  const auto thread_state = thread->GetState();
1018  if (thread_state == eStateRunning || thread_state == eStateStepping) {
1019  running_thread = thread.get();
1020  break;
1021  } else if (!stopped_thread && StateIsStoppedState(thread_state, true)) {
1022  // Remember the first non-dead stopped thread. We'll use that as a
1023  // backup if there are no running threads.
1024  stopped_thread = thread.get();
1025  }
1026  }
1027 
1028  if (!running_thread && !stopped_thread) {
1029  Status error("found no running/stepping or live stopped threads as target "
1030  "for interrupt");
1031  LLDB_LOG(log, "skipping due to error: {0}", error);
1032 
1033  return error;
1034  }
1035 
1036  NativeThreadProtocol *deferred_signal_thread =
1037  running_thread ? running_thread : stopped_thread;
1038 
1039  LLDB_LOG(log, "pid {0} {1} tid {2} chosen for interrupt target", GetID(),
1040  running_thread ? "running" : "stopped",
1041  deferred_signal_thread->GetID());
1042 
1043  StopRunningThreads(deferred_signal_thread->GetID());
1044 
1045  return Status();
1046 }
1047 
1050  LLDB_LOG(log, "pid {0}", GetID());
1051 
1052  Status error;
1053 
1054  switch (m_state) {
1060  // Nothing to do - the process is already dead.
1061  LLDB_LOG(log, "ignored for PID {0} due to current state: {1}", GetID(),
1062  m_state);
1063  return error;
1064 
1072  // We can try to kill a process in these states.
1073  break;
1074  }
1075 
1076  if (kill(GetID(), SIGKILL) != 0) {
1077  error.SetErrorToErrno();
1078  return error;
1079  }
1080 
1081  return error;
1082 }
1083 
1085  MemoryRegionInfo &range_info) {
1086  // FIXME review that the final memory region returned extends to the end of
1087  // the virtual address space,
1088  // with no perms if it is not mapped.
1089 
1090  // Use an approach that reads memory regions from /proc/{pid}/maps. Assume
1091  // proc maps entries are in ascending order.
1092  // FIXME assert if we find differently.
1093 
1095  // We're done.
1096  return Status("unsupported");
1097  }
1098 
1100  if (error.Fail()) {
1101  return error;
1102  }
1103 
1104  lldb::addr_t prev_base_address = 0;
1105 
1106  // FIXME start by finding the last region that is <= target address using
1107  // binary search. Data is sorted.
1108  // There can be a ton of regions on pthreads apps with lots of threads.
1109  for (auto it = m_mem_region_cache.begin(); it != m_mem_region_cache.end();
1110  ++it) {
1111  MemoryRegionInfo &proc_entry_info = it->first;
1112 
1113  // Sanity check assumption that /proc/{pid}/maps entries are ascending.
1114  assert((proc_entry_info.GetRange().GetRangeBase() >= prev_base_address) &&
1115  "descending /proc/pid/maps entries detected, unexpected");
1116  prev_base_address = proc_entry_info.GetRange().GetRangeBase();
1117  UNUSED_IF_ASSERT_DISABLED(prev_base_address);
1118 
1119  // If the target address comes before this entry, indicate distance to next
1120  // region.
1121  if (load_addr < proc_entry_info.GetRange().GetRangeBase()) {
1122  range_info.GetRange().SetRangeBase(load_addr);
1123  range_info.GetRange().SetByteSize(
1124  proc_entry_info.GetRange().GetRangeBase() - load_addr);
1125  range_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
1126  range_info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
1127  range_info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
1128  range_info.SetMapped(MemoryRegionInfo::OptionalBool::eNo);
1129 
1130  return error;
1131  } else if (proc_entry_info.GetRange().Contains(load_addr)) {
1132  // The target address is within the memory region we're processing here.
1133  range_info = proc_entry_info;
1134  return error;
1135  }
1136 
1137  // The target memory address comes somewhere after the region we just
1138  // parsed.
1139  }
1140 
1141  // If we made it here, we didn't find an entry that contained the given
1142  // address. Return the load_addr as start and the amount of bytes betwwen
1143  // load address and the end of the memory as size.
1144  range_info.GetRange().SetRangeBase(load_addr);
1146  range_info.SetReadable(MemoryRegionInfo::OptionalBool::eNo);
1147  range_info.SetWritable(MemoryRegionInfo::OptionalBool::eNo);
1148  range_info.SetExecutable(MemoryRegionInfo::OptionalBool::eNo);
1149  range_info.SetMapped(MemoryRegionInfo::OptionalBool::eNo);
1150  return error;
1151 }
1152 
1155 
1156  // If our cache is empty, pull the latest. There should always be at least
1157  // one memory region if memory region handling is supported.
1158  if (!m_mem_region_cache.empty()) {
1159  LLDB_LOG(log, "reusing {0} cached memory region entries",
1160  m_mem_region_cache.size());
1161  return Status();
1162  }
1163 
1164  Status Result;
1165  LinuxMapCallback callback = [&](llvm::Expected<MemoryRegionInfo> Info) {
1166  if (Info) {
1167  FileSpec file_spec(Info->GetName().GetCString());
1168  FileSystem::Instance().Resolve(file_spec);
1169  m_mem_region_cache.emplace_back(*Info, file_spec);
1170  return true;
1171  }
1172 
1173  Result = Info.takeError();
1175  LLDB_LOG(log, "failed to parse proc maps: {0}", Result);
1176  return false;
1177  };
1178 
1179  // Linux kernel since 2.6.14 has /proc/{pid}/smaps
1180  // if CONFIG_PROC_PAGE_MONITOR is enabled
1181  auto BufferOrError = getProcFile(GetID(), "smaps");
1182  if (BufferOrError)
1183  ParseLinuxSMapRegions(BufferOrError.get()->getBuffer(), callback);
1184  else {
1185  BufferOrError = getProcFile(GetID(), "maps");
1186  if (!BufferOrError) {
1188  return BufferOrError.getError();
1189  }
1190 
1191  ParseLinuxMapRegions(BufferOrError.get()->getBuffer(), callback);
1192  }
1193 
1194  if (Result.Fail())
1195  return Result;
1196 
1197  if (m_mem_region_cache.empty()) {
1198  // No entries after attempting to read them. This shouldn't happen if
1199  // /proc/{pid}/maps is supported. Assume we don't support map entries via
1200  // procfs.
1202  LLDB_LOG(log,
1203  "failed to find any procfs maps entries, assuming no support "
1204  "for memory region metadata retrieval");
1205  return Status("not supported");
1206  }
1207 
1208  LLDB_LOG(log, "read {0} memory region entries from /proc/{1}/maps",
1209  m_mem_region_cache.size(), GetID());
1210 
1211  // We support memory retrieval, remember that.
1213  return Status();
1214 }
1215 
1218  LLDB_LOG(log, "newBumpId={0}", newBumpId);
1219  LLDB_LOG(log, "clearing {0} entries from memory region cache",
1220  m_mem_region_cache.size());
1221  m_mem_region_cache.clear();
1222 }
1223 
1224 llvm::Expected<uint64_t>
1225 NativeProcessLinux::Syscall(llvm::ArrayRef<uint64_t> args) {
1227  auto region_it = llvm::find_if(m_mem_region_cache, [](const auto &pair) {
1228  return pair.first.GetExecutable() == MemoryRegionInfo::eYes;
1229  });
1230  if (region_it == m_mem_region_cache.end())
1231  return llvm::createStringError(llvm::inconvertibleErrorCode(),
1232  "No executable memory region found!");
1233 
1234  addr_t exe_addr = region_it->first.GetRange().GetRangeBase();
1235 
1236  NativeThreadLinux &thread = *GetThreadByID(GetID());
1237  assert(thread.GetState() == eStateStopped);
1238  NativeRegisterContextLinux &reg_ctx = thread.GetRegisterContext();
1239 
1241  *reg_ctx.GetSyscallData();
1242 
1243  DataBufferSP registers_sp;
1244  if (llvm::Error Err = reg_ctx.ReadAllRegisterValues(registers_sp).ToError())
1245  return std::move(Err);
1246  auto restore_regs = llvm::make_scope_exit(
1247  [&] { reg_ctx.WriteAllRegisterValues(registers_sp); });
1248 
1249  llvm::SmallVector<uint8_t, 8> memory(syscall_data.Insn.size());
1250  size_t bytes_read;
1251  if (llvm::Error Err =
1252  ReadMemory(exe_addr, memory.data(), memory.size(), bytes_read)
1253  .ToError()) {
1254  return std::move(Err);
1255  }
1256 
1257  auto restore_mem = llvm::make_scope_exit(
1258  [&] { WriteMemory(exe_addr, memory.data(), memory.size(), bytes_read); });
1259 
1260  if (llvm::Error Err = reg_ctx.SetPC(exe_addr).ToError())
1261  return std::move(Err);
1262 
1263  for (const auto &zip : llvm::zip_first(args, syscall_data.Args)) {
1264  if (llvm::Error Err =
1265  reg_ctx
1266  .WriteRegisterFromUnsigned(std::get<1>(zip), std::get<0>(zip))
1267  .ToError()) {
1268  return std::move(Err);
1269  }
1270  }
1271  if (llvm::Error Err = WriteMemory(exe_addr, syscall_data.Insn.data(),
1272  syscall_data.Insn.size(), bytes_read)
1273  .ToError())
1274  return std::move(Err);
1275 
1276  m_mem_region_cache.clear();
1277 
1278  // With software single stepping the syscall insn buffer must also include a
1279  // trap instruction to stop the process.
1280  int req = SupportHardwareSingleStepping() ? PTRACE_SINGLESTEP : PTRACE_CONT;
1281  if (llvm::Error Err =
1282  PtraceWrapper(req, thread.GetID(), nullptr, nullptr).ToError())
1283  return std::move(Err);
1284 
1285  int status;
1286  ::pid_t wait_pid = llvm::sys::RetryAfterSignal(-1, ::waitpid, thread.GetID(),
1287  &status, __WALL);
1288  if (wait_pid == -1) {
1289  return llvm::errorCodeToError(
1290  std::error_code(errno, std::generic_category()));
1291  }
1292  assert((unsigned)wait_pid == thread.GetID());
1293 
1294  uint64_t result = reg_ctx.ReadRegisterAsUnsigned(syscall_data.Result, -ESRCH);
1295 
1296  // Values larger than this are actually negative errno numbers.
1297  uint64_t errno_threshold =
1298  (uint64_t(-1) >> (64 - 8 * m_arch.GetAddressByteSize())) - 0x1000;
1299  if (result > errno_threshold) {
1300  return llvm::errorCodeToError(
1301  std::error_code(-result & 0xfff, std::generic_category()));
1302  }
1303 
1304  return result;
1305 }
1306 
1307 llvm::Expected<addr_t>
1309 
1310  llvm::Optional<NativeRegisterContextLinux::MmapData> mmap_data =
1312  if (!mmap_data)
1313  return llvm::make_error<UnimplementedError>();
1314 
1315  unsigned prot = PROT_NONE;
1316  assert((permissions & (ePermissionsReadable | ePermissionsWritable |
1317  ePermissionsExecutable)) == permissions &&
1318  "Unknown permission!");
1319  if (permissions & ePermissionsReadable)
1320  prot |= PROT_READ;
1321  if (permissions & ePermissionsWritable)
1322  prot |= PROT_WRITE;
1323  if (permissions & ePermissionsExecutable)
1324  prot |= PROT_EXEC;
1325 
1326  llvm::Expected<uint64_t> Result =
1327  Syscall({mmap_data->SysMmap, 0, size, prot, MAP_ANONYMOUS | MAP_PRIVATE,
1328  uint64_t(-1), 0});
1329  if (Result)
1330  m_allocated_memory.try_emplace(*Result, size);
1331  return Result;
1332 }
1333 
1335  llvm::Optional<NativeRegisterContextLinux::MmapData> mmap_data =
1337  if (!mmap_data)
1338  return llvm::make_error<UnimplementedError>();
1339 
1340  auto it = m_allocated_memory.find(addr);
1341  if (it == m_allocated_memory.end())
1342  return llvm::createStringError(llvm::errc::invalid_argument,
1343  "Memory not allocated by the debugger.");
1344 
1345  llvm::Expected<uint64_t> Result =
1346  Syscall({mmap_data->SysMunmap, addr, it->second});
1347  if (!Result)
1348  return Result.takeError();
1349 
1350  m_allocated_memory.erase(it);
1351  return llvm::Error::success();
1352 }
1353 
1355  size_t len,
1356  std::vector<uint8_t> &tags) {
1357  llvm::Expected<NativeRegisterContextLinux::MemoryTaggingDetails> details =
1359  if (!details)
1360  return Status(details.takeError());
1361 
1362  // Ignore 0 length read
1363  if (!len)
1364  return Status();
1365 
1366  // lldb will align the range it requests but it is not required to by
1367  // the protocol so we'll do it again just in case.
1368  // Remove tag bits too. Ptrace calls may work regardless but that
1369  // is not a guarantee.
1370  MemoryTagManager::TagRange range(details->manager->RemoveTagBits(addr), len);
1371  range = details->manager->ExpandToGranule(range);
1372 
1373  // Allocate enough space for all tags to be read
1374  size_t num_tags = range.GetByteSize() / details->manager->GetGranuleSize();
1375  tags.resize(num_tags * details->manager->GetTagSizeInBytes());
1376 
1377  struct iovec tags_iovec;
1378  uint8_t *dest = tags.data();
1379  lldb::addr_t read_addr = range.GetRangeBase();
1380 
1381  // This call can return partial data so loop until we error or
1382  // get all tags back.
1383  while (num_tags) {
1384  tags_iovec.iov_base = dest;
1385  tags_iovec.iov_len = num_tags;
1386 
1388  details->ptrace_read_req, GetID(), reinterpret_cast<void *>(read_addr),
1389  static_cast<void *>(&tags_iovec), 0, nullptr);
1390 
1391  if (error.Fail()) {
1392  // Discard partial reads
1393  tags.resize(0);
1394  return error;
1395  }
1396 
1397  size_t tags_read = tags_iovec.iov_len;
1398  assert(tags_read && (tags_read <= num_tags));
1399 
1400  dest += tags_read * details->manager->GetTagSizeInBytes();
1401  read_addr += details->manager->GetGranuleSize() * tags_read;
1402  num_tags -= tags_read;
1403  }
1404 
1405  return Status();
1406 }
1407 
1409  size_t len,
1410  const std::vector<uint8_t> &tags) {
1411  llvm::Expected<NativeRegisterContextLinux::MemoryTaggingDetails> details =
1413  if (!details)
1414  return Status(details.takeError());
1415 
1416  // Ignore 0 length write
1417  if (!len)
1418  return Status();
1419 
1420  // lldb will align the range it requests but it is not required to by
1421  // the protocol so we'll do it again just in case.
1422  // Remove tag bits too. Ptrace calls may work regardless but that
1423  // is not a guarantee.
1424  MemoryTagManager::TagRange range(details->manager->RemoveTagBits(addr), len);
1425  range = details->manager->ExpandToGranule(range);
1426 
1427  // Not checking number of tags here, we may repeat them below
1428  llvm::Expected<std::vector<lldb::addr_t>> unpacked_tags_or_err =
1429  details->manager->UnpackTagsData(tags);
1430  if (!unpacked_tags_or_err)
1431  return Status(unpacked_tags_or_err.takeError());
1432 
1433  llvm::Expected<std::vector<lldb::addr_t>> repeated_tags_or_err =
1434  details->manager->RepeatTagsForRange(*unpacked_tags_or_err, range);
1435  if (!repeated_tags_or_err)
1436  return Status(repeated_tags_or_err.takeError());
1437 
1438  // Repack them for ptrace to use
1439  llvm::Expected<std::vector<uint8_t>> final_tag_data =
1440  details->manager->PackTags(*repeated_tags_or_err);
1441  if (!final_tag_data)
1442  return Status(final_tag_data.takeError());
1443 
1444  struct iovec tags_vec;
1445  uint8_t *src = final_tag_data->data();
1446  lldb::addr_t write_addr = range.GetRangeBase();
1447  // unpacked tags size because the number of bytes per tag might not be 1
1448  size_t num_tags = repeated_tags_or_err->size();
1449 
1450  // This call can partially write tags, so we loop until we
1451  // error or all tags have been written.
1452  while (num_tags > 0) {
1453  tags_vec.iov_base = src;
1454  tags_vec.iov_len = num_tags;
1455 
1457  details->ptrace_write_req, GetID(),
1458  reinterpret_cast<void *>(write_addr), static_cast<void *>(&tags_vec), 0,
1459  nullptr);
1460 
1461  if (error.Fail()) {
1462  // Don't attempt to restore the original values in the case of a partial
1463  // write
1464  return error;
1465  }
1466 
1467  size_t tags_written = tags_vec.iov_len;
1468  assert(tags_written && (tags_written <= num_tags));
1469 
1470  src += tags_written * details->manager->GetTagSizeInBytes();
1471  write_addr += details->manager->GetGranuleSize() * tags_written;
1472  num_tags -= tags_written;
1473  }
1474 
1475  return Status();
1476 }
1477 
1479  // The NativeProcessLinux monitoring threads are always up to date with
1480  // respect to thread state and they keep the thread list populated properly.
1481  // All this method needs to do is return the thread count.
1482  return m_threads.size();
1483 }
1484 
1486  bool hardware) {
1487  if (hardware)
1488  return SetHardwareBreakpoint(addr, size);
1489  else
1490  return SetSoftwareBreakpoint(addr, size);
1491 }
1492 
1494  if (hardware)
1495  return RemoveHardwareBreakpoint(addr);
1496  else
1498 }
1499 
1500 llvm::Expected<llvm::ArrayRef<uint8_t>>
1502  // The ARM reference recommends the use of 0xe7fddefe and 0xdefe but the
1503  // linux kernel does otherwise.
1504  static const uint8_t g_arm_opcode[] = {0xf0, 0x01, 0xf0, 0xe7};
1505  static const uint8_t g_thumb_opcode[] = {0x01, 0xde};
1506 
1507  switch (GetArchitecture().GetMachine()) {
1508  case llvm::Triple::arm:
1509  switch (size_hint) {
1510  case 2:
1511  return llvm::makeArrayRef(g_thumb_opcode);
1512  case 4:
1513  return llvm::makeArrayRef(g_arm_opcode);
1514  default:
1515  return llvm::createStringError(llvm::inconvertibleErrorCode(),
1516  "Unrecognised trap opcode size hint!");
1517  }
1518  default:
1520  }
1521 }
1522 
1524  size_t &bytes_read) {
1525  if (ProcessVmReadvSupported()) {
1526  // The process_vm_readv path is about 50 times faster than ptrace api. We
1527  // want to use this syscall if it is supported.
1528 
1529  const ::pid_t pid = GetID();
1530 
1531  struct iovec local_iov, remote_iov;
1532  local_iov.iov_base = buf;
1533  local_iov.iov_len = size;
1534  remote_iov.iov_base = reinterpret_cast<void *>(addr);
1535  remote_iov.iov_len = size;
1536 
1537  bytes_read = process_vm_readv(pid, &local_iov, 1, &remote_iov, 1, 0);
1538  const bool success = bytes_read == size;
1539 
1541  LLDB_LOG(log,
1542  "using process_vm_readv to read {0} bytes from inferior "
1543  "address {1:x}: {2}",
1544  size, addr, success ? "Success" : llvm::sys::StrError(errno));
1545 
1546  if (success)
1547  return Status();
1548  // else the call failed for some reason, let's retry the read using ptrace
1549  // api.
1550  }
1551 
1552  unsigned char *dst = static_cast<unsigned char *>(buf);
1553  size_t remainder;
1554  long data;
1555 
1557  LLDB_LOG(log, "addr = {0}, buf = {1}, size = {2}", addr, buf, size);
1558 
1559  for (bytes_read = 0; bytes_read < size; bytes_read += remainder) {
1561  PTRACE_PEEKDATA, GetID(), (void *)addr, nullptr, 0, &data);
1562  if (error.Fail())
1563  return error;
1564 
1565  remainder = size - bytes_read;
1566  remainder = remainder > k_ptrace_word_size ? k_ptrace_word_size : remainder;
1567 
1568  // Copy the data into our buffer
1569  memcpy(dst, &data, remainder);
1570 
1571  LLDB_LOG(log, "[{0:x}]:{1:x}", addr, data);
1572  addr += k_ptrace_word_size;
1573  dst += k_ptrace_word_size;
1574  }
1575  return Status();
1576 }
1577 
1579  size_t size, size_t &bytes_written) {
1580  const unsigned char *src = static_cast<const unsigned char *>(buf);
1581  size_t remainder;
1582  Status error;
1583 
1585  LLDB_LOG(log, "addr = {0}, buf = {1}, size = {2}", addr, buf, size);
1586 
1587  for (bytes_written = 0; bytes_written < size; bytes_written += remainder) {
1588  remainder = size - bytes_written;
1589  remainder = remainder > k_ptrace_word_size ? k_ptrace_word_size : remainder;
1590 
1591  if (remainder == k_ptrace_word_size) {
1592  unsigned long data = 0;
1593  memcpy(&data, src, k_ptrace_word_size);
1594 
1595  LLDB_LOG(log, "[{0:x}]:{1:x}", addr, data);
1596  error = NativeProcessLinux::PtraceWrapper(PTRACE_POKEDATA, GetID(),
1597  (void *)addr, (void *)data);
1598  if (error.Fail())
1599  return error;
1600  } else {
1601  unsigned char buff[8];
1602  size_t bytes_read;
1603  error = ReadMemory(addr, buff, k_ptrace_word_size, bytes_read);
1604  if (error.Fail())
1605  return error;
1606 
1607  memcpy(buff, src, remainder);
1608 
1609  size_t bytes_written_rec;
1610  error = WriteMemory(addr, buff, k_ptrace_word_size, bytes_written_rec);
1611  if (error.Fail())
1612  return error;
1613 
1614  LLDB_LOG(log, "[{0:x}]:{1:x} ({2:x})", addr, *(const unsigned long *)src,
1615  *(unsigned long *)buff);
1616  }
1617 
1618  addr += k_ptrace_word_size;
1619  src += k_ptrace_word_size;
1620  }
1621  return error;
1622 }
1623 
1625  return PtraceWrapper(PTRACE_GETSIGINFO, tid, nullptr, siginfo);
1626 }
1627 
1629  unsigned long *message) {
1630  return PtraceWrapper(PTRACE_GETEVENTMSG, tid, nullptr, message);
1631 }
1632 
1634  if (tid == LLDB_INVALID_THREAD_ID)
1635  return Status();
1636 
1637  return PtraceWrapper(PTRACE_DETACH, tid);
1638 }
1639 
1641  for (const auto &thread : m_threads) {
1642  assert(thread && "thread list should not contain NULL threads");
1643  if (thread->GetID() == thread_id) {
1644  // We have this thread.
1645  return true;
1646  }
1647  }
1648 
1649  // We don't have this thread.
1650  return false;
1651 }
1652 
1655  lldb::tid_t thread_id = thread.GetID();
1656  LLDB_LOG(log, "tid: {0}", thread_id);
1657 
1658  auto it = llvm::find_if(m_threads, [&](const auto &thread_up) {
1659  return thread_up.get() == &thread;
1660  });
1661  assert(it != m_threads.end());
1662  m_threads.erase(it);
1663 
1664  NotifyTracersOfThreadDestroyed(thread_id);
1666 }
1667 
1671  if (error.Fail())
1672  LLDB_LOG(log, "Failed to trace a new thread with intel-pt, tid = {0}. {1}",
1673  tid, error.AsCString());
1674  return error;
1675 }
1676 
1680  if (error.Fail())
1681  LLDB_LOG(log,
1682  "Failed to stop a destroyed thread with intel-pt, tid = {0}. {1}",
1683  tid, error.AsCString());
1684  return error;
1685 }
1686 
1688  bool resume) {
1690  LLDB_LOG(log, "pid {0} adding thread with tid {1}", GetID(), thread_id);
1691 
1692  assert(!HasThreadNoLock(thread_id) &&
1693  "attempted to add a thread by id that already exists");
1694 
1695  // If this is the first thread, save it as the current thread
1696  if (m_threads.empty())
1697  SetCurrentThreadID(thread_id);
1698 
1699  m_threads.push_back(std::make_unique<NativeThreadLinux>(*this, thread_id));
1700  NativeThreadLinux &thread =
1701  static_cast<NativeThreadLinux &>(*m_threads.back());
1702 
1703  Status tracing_error = NotifyTracersOfNewThread(thread.GetID());
1704  if (tracing_error.Fail()) {
1705  thread.SetStoppedByProcessorTrace(tracing_error.AsCString());
1706  StopRunningThreads(thread.GetID());
1707  } else if (resume)
1709  else
1710  thread.SetStoppedBySignal(SIGSTOP);
1711 
1712  return thread;
1713 }
1714 
1716  FileSpec &file_spec) {
1718  if (error.Fail())
1719  return error;
1720 
1721  FileSpec module_file_spec(module_path);
1722  FileSystem::Instance().Resolve(module_file_spec);
1723 
1724  file_spec.Clear();
1725  for (const auto &it : m_mem_region_cache) {
1726  if (it.second.GetFilename() == module_file_spec.GetFilename()) {
1727  file_spec = it.second;
1728  return Status();
1729  }
1730  }
1731  return Status("Module file (%s) not found in /proc/%" PRIu64 "/maps file!",
1732  module_file_spec.GetFilename().AsCString(), GetID());
1733 }
1734 
1735 Status NativeProcessLinux::GetFileLoadAddress(const llvm::StringRef &file_name,
1736  lldb::addr_t &load_addr) {
1737  load_addr = LLDB_INVALID_ADDRESS;
1739  if (error.Fail())
1740  return error;
1741 
1742  FileSpec file(file_name);
1743  for (const auto &it : m_mem_region_cache) {
1744  if (it.second == file) {
1745  load_addr = it.first.GetRange().GetRangeBase();
1746  return Status();
1747  }
1748  }
1749  return Status("No load address found for specified file.");
1750 }
1751 
1753  return static_cast<NativeThreadLinux *>(
1755 }
1756 
1758  return static_cast<NativeThreadLinux *>(
1760 }
1761 
1763  lldb::StateType state, int signo) {
1765  LLDB_LOG(log, "tid: {0}", thread.GetID());
1766 
1767  // Before we do the resume below, first check if we have a pending stop
1768  // notification that is currently waiting for all threads to stop. This is
1769  // potentially a buggy situation since we're ostensibly waiting for threads
1770  // to stop before we send out the pending notification, and here we are
1771  // resuming one before we send out the pending stop notification.
1773  LLDB_LOG(log,
1774  "about to resume tid {0} per explicit request but we have a "
1775  "pending stop notification (tid {1}) that is actively "
1776  "waiting for this thread to stop. Valid sequence of events?",
1777  thread.GetID(), m_pending_notification_tid);
1778  }
1779 
1780  // Request a resume. We expect this to be synchronous and the system to
1781  // reflect it is running after this completes.
1782  switch (state) {
1783  case eStateRunning: {
1784  const auto resume_result = thread.Resume(signo);
1785  if (resume_result.Success())
1786  SetState(eStateRunning, true);
1787  return resume_result;
1788  }
1789  case eStateStepping: {
1790  const auto step_result = thread.SingleStep(signo);
1791  if (step_result.Success())
1792  SetState(eStateRunning, true);
1793  return step_result;
1794  }
1795  default:
1796  LLDB_LOG(log, "Unhandled state {0}.", state);
1797  llvm_unreachable("Unhandled state for resume");
1798  }
1799 }
1800 
1801 //===----------------------------------------------------------------------===//
1802 
1805  LLDB_LOG(log, "about to process event: (triggering_tid: {0})",
1806  triggering_tid);
1807 
1808  m_pending_notification_tid = triggering_tid;
1809 
1810  // Request a stop for all the thread stops that need to be stopped and are
1811  // not already known to be stopped.
1812  for (const auto &thread : m_threads) {
1813  if (StateIsRunningState(thread->GetState()))
1814  static_cast<NativeThreadLinux *>(thread.get())->RequestStop();
1815  }
1816 
1818  LLDB_LOG(log, "event processing done");
1819 }
1820 
1823  return; // No pending notification. Nothing to do.
1824 
1825  for (const auto &thread_sp : m_threads) {
1826  if (StateIsRunningState(thread_sp->GetState()))
1827  return; // Some threads are still running. Don't signal yet.
1828  }
1829 
1830  // We have a pending notification and all threads have stopped.
1831  Log *log(
1833 
1834  // Clear any temporary breakpoints we used to implement software single
1835  // stepping.
1836  for (const auto &thread_info : m_threads_stepping_with_breakpoint) {
1837  Status error = RemoveBreakpoint(thread_info.second);
1838  if (error.Fail())
1839  LLDB_LOG(log, "pid = {0} remove stepping breakpoint: {1}",
1840  thread_info.first, error);
1841  }
1843 
1844  // Notify the delegate about the stop
1848 }
1849 
1852  LLDB_LOG(log, "tid: {0}", thread.GetID());
1853 
1855  StateIsRunningState(thread.GetState())) {
1856  // We will need to wait for this new thread to stop as well before firing
1857  // the notification.
1858  thread.RequestStop();
1859  }
1860 }
1861 
1864 
1865  // Threads can appear or disappear as a result of event processing, so gather
1866  // the events upfront.
1867  llvm::DenseMap<lldb::tid_t, WaitStatus> tid_events;
1868  for (const auto &thread_up : m_threads) {
1869  int status = -1;
1870  ::pid_t wait_pid =
1871  llvm::sys::RetryAfterSignal(-1, ::waitpid, thread_up->GetID(), &status,
1872  __WALL | __WNOTHREAD | WNOHANG);
1873 
1874  if (wait_pid == 0)
1875  continue; // Nothing to do for this thread.
1876 
1877  if (wait_pid == -1) {
1878  Status error(errno, eErrorTypePOSIX);
1879  LLDB_LOG(log, "waitpid({0}, &status, _) failed: {1}", thread_up->GetID(),
1880  error);
1881  continue;
1882  }
1883 
1884  assert(wait_pid == static_cast<::pid_t>(thread_up->GetID()));
1885 
1886  WaitStatus wait_status = WaitStatus::Decode(status);
1887 
1888  LLDB_LOG(log, "waitpid({0}) got status = {1}", thread_up->GetID(),
1889  wait_status);
1890  tid_events.try_emplace(thread_up->GetID(), wait_status);
1891  }
1892 
1893  for (auto &KV : tid_events) {
1894  LLDB_LOG(log, "processing {0}({1}) ...", KV.first, KV.second);
1895  NativeThreadLinux *thread = GetThreadByID(KV.first);
1896  if (thread) {
1897  MonitorCallback(*thread, KV.second);
1898  } else {
1899  // This can happen if one of the events is an main thread exit.
1900  LLDB_LOG(log, "... but the thread has disappeared");
1901  }
1902  }
1903 }
1904 
1905 // Wrapper for ptrace to catch errors and log calls. Note that ptrace sets
1906 // errno on error because -1 can be a valid result (i.e. for PTRACE_PEEK*)
1908  void *data, size_t data_size,
1909  long *result) {
1910  Status error;
1911  long int ret;
1912 
1914 
1915  PtraceDisplayBytes(req, data, data_size);
1916 
1917  errno = 0;
1918  if (req == PTRACE_GETREGSET || req == PTRACE_SETREGSET)
1919  ret = ptrace(static_cast<__ptrace_request>(req), static_cast<::pid_t>(pid),
1920  *(unsigned int *)addr, data);
1921  else
1922  ret = ptrace(static_cast<__ptrace_request>(req), static_cast<::pid_t>(pid),
1923  addr, data);
1924 
1925  if (ret == -1)
1926  error.SetErrorToErrno();
1927 
1928  if (result)
1929  *result = ret;
1930 
1931  LLDB_LOG(log, "ptrace({0}, {1}, {2}, {3}, {4})={5:x}", req, pid, addr, data,
1932  data_size, ret);
1933 
1934  PtraceDisplayBytes(req, data, data_size);
1935 
1936  if (error.Fail())
1937  LLDB_LOG(log, "ptrace() failed: {0}", error);
1938 
1939  return error;
1940 }
1941 
1942 llvm::Expected<TraceSupportedResponse> NativeProcessLinux::TraceSupported() {
1944  return TraceSupportedResponse{"intel-pt", "Intel Processor Trace"};
1946 }
1947 
1948 Error NativeProcessLinux::TraceStart(StringRef json_request, StringRef type) {
1949  if (type == "intel-pt") {
1950  if (Expected<TraceIntelPTStartRequest> request =
1951  json::parse<TraceIntelPTStartRequest>(json_request,
1952  "TraceIntelPTStartRequest")) {
1953  std::vector<lldb::tid_t> process_threads;
1954  for (auto &thread : m_threads)
1955  process_threads.push_back(thread->GetID());
1956  return m_intel_pt_manager.TraceStart(*request, process_threads);
1957  } else
1958  return request.takeError();
1959  }
1960 
1961  return NativeProcessProtocol::TraceStart(json_request, type);
1962 }
1963 
1965  if (request.type == "intel-pt")
1966  return m_intel_pt_manager.TraceStop(request);
1967  return NativeProcessProtocol::TraceStop(request);
1968 }
1969 
1970 Expected<json::Value> NativeProcessLinux::TraceGetState(StringRef type) {
1971  if (type == "intel-pt")
1972  return m_intel_pt_manager.GetState();
1974 }
1975 
1976 Expected<std::vector<uint8_t>> NativeProcessLinux::TraceGetBinaryData(
1977  const TraceGetBinaryDataRequest &request) {
1978  if (request.type == "intel-pt")
1979  return m_intel_pt_manager.GetBinaryData(request);
1981 }
lldb_private::WaitStatus::type
Type type
Definition: Host.h:44
lldb_private::NativeProcessProtocol::SetSoftwareBreakpoint
Status SetSoftwareBreakpoint(lldb::addr_t addr, uint32_t size_hint)
Definition: NativeProcessProtocol.cpp:326
lldb_private::ProcessInfo::GetArguments
Args & GetArguments()
Definition: ProcessInfo.h:75
lldb_private::ProcessLauncherPosixFork
Definition: ProcessLauncherPosixFork.h:16
lldb_private::ProcessInstanceInfo
Definition: ProcessInfo.h:108
lldb_private::process_linux::NativeProcessLinux::MonitorCallback
void MonitorCallback(NativeThreadLinux &thread, WaitStatus status)
Definition: NativeProcessLinux.cpp:430
DEBUG_PTRACE_MAXBYTES
#define DEBUG_PTRACE_MAXBYTES
Definition: Ptrace.h:20
POSIX_LOG_THREAD
#define POSIX_LOG_THREAD
Definition: ProcessPOSIXLog.h:17
lldb_private::Range::GetRangeBase
BaseType GetRangeBase() const
Definition: RangeMap.h:46
PTRACE_GETREGSET
#define PTRACE_GETREGSET
Definition: Ptrace.h:36
PTRACE_SETREGS
#define PTRACE_SETREGS
Definition: Ptrace.h:27
llvm
Definition: Debugger.h:49
lldb_private::NativeProcessProtocol::NativeDelegate
Definition: NativeProcessProtocol.h:221
lldb_private::process_linux::NativeThreadLinux::SetStoppedByVForkDone
void SetStoppedByVForkDone()
Definition: NativeThreadLinux.cpp:465
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::ArchSpec::IsMIPS
bool IsMIPS() const
if MIPS architecture return true.
Definition: ArchSpec.cpp:545
lldb_private::NativeRegisterContext::GetWatchpointHitIndex
virtual Status GetWatchpointHitIndex(uint32_t &wp_index, lldb::addr_t trap_addr)
Definition: NativeRegisterContext.cpp:294
UNUSED_IF_ASSERT_DISABLED
#define UNUSED_IF_ASSERT_DISABLED(x)
Definition: lldb-defines.h:125
lldb_private::NativeProcessProtocol::GetCurrentThread
NativeThreadProtocol * GetCurrentThread()
Definition: NativeProcessProtocol.h:209
lldb_private::TraceGetBinaryDataRequest
jLLDBTraceGetBinaryData gdb-remote packet
Definition: TraceGDBRemotePackets.h:132
lldb_private::process_linux::NativeProcessLinux::PtraceWrapper
static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr=nullptr, void *data=nullptr, size_t data_size=0, long *result=nullptr)
}
Definition: NativeProcessLinux.cpp:1907
lldb_private::NativeProcessProtocol::TraceStart
virtual llvm::Error TraceStart(llvm::StringRef json_params, llvm::StringRef type)
Start tracing a process or its threads.
Definition: NativeProcessProtocol.h:329
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::ArchSpec::GetMachine
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:667
lldb_private::NativeProcessProtocol::SetHardwareBreakpoint
virtual Status SetHardwareBreakpoint(lldb::addr_t addr, size_t size)
Definition: NativeProcessProtocol.cpp:234
ModuleSpec.h
lldb_private::NativeThreadProtocol
Definition: NativeThreadProtocol.h:24
lldb_private::process_linux::NativeProcessLinux::MonitorSIGTRAP
void MonitorSIGTRAP(const siginfo_t &info, NativeThreadLinux &thread)
Definition: NativeProcessLinux.cpp:524
lldb_private::process_linux::NativeProcessLinux::GetThreadByID
NativeThreadLinux * GetThreadByID(lldb::tid_t id)
Definition: NativeProcessLinux.cpp:1752
lldb_private::process_linux::NativeProcessLinux::m_pending_notification_tid
lldb::tid_t m_pending_notification_tid
Definition: NativeProcessLinux.h:156
lldb_private::process_linux::NativeThreadLinux::Resume
Status Resume(uint32_t signo)
Resumes the thread.
Definition: NativeThreadLinux.cpp:210
lldb_private::process_linux::NativeRegisterContextLinux
Definition: NativeRegisterContextLinux.h:22
lldb_private::process_linux::NativeThreadLinux::SetStoppedByProcessorTrace
void SetStoppedByProcessorTrace(llvm::StringRef description)
Definition: NativeThreadLinux.cpp:478
Host.h
lldb_private::TraceSupportedResponse
jLLDBTraceSupported gdb-remote packet
Definition: TraceGDBRemotePackets.h:22
lldb_private::Host::GetSignalAsCString
static const char * GetSignalAsCString(int signo)
Definition: common/Host.cpp:322
lldb_private::process_linux::NativeProcessLinux::GetSignalInfo
Status GetSignalInfo(lldb::tid_t tid, void *siginfo) const
Writes a siginfo_t structure corresponding to the given thread ID to the memory region pointed to by ...
Definition: NativeProcessLinux.cpp:1624
lldb::eStateAttaching
@ eStateAttaching
Process is currently trying to attach.
Definition: lldb-enumerations.h:78
lldb_private::NativeProcessProtocol::SetState
void SetState(lldb::StateType state, bool notify_delegates=true)
Definition: NativeProcessProtocol.cpp:698
lldb_private::process_linux::NativeProcessLinux::DoStopIDBumped
void DoStopIDBumped(uint32_t newBumpId) override
Definition: NativeProcessLinux.cpp:1216
ProcessLaunchInfo.h
HostProcess.h
lldb_private::process_linux::NativeProcessLinux::GetEventMessage
Status GetEventMessage(lldb::tid_t tid, unsigned long *message)
Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG) corresponding to the given thread ID...
Definition: NativeProcessLinux.cpp:1628
lldb_private::eLazyBoolYes
@ eLazyBoolYes
Definition: lldb-private-enumerations.h:115
lldb_private::process_linux::IntelPTManager::TraceStop
llvm::Error TraceStop(const TraceStopRequest &request)
Implementation of the jLLDBTraceStop packet.
Definition: IntelPTManager.cpp:575
lldb_private::WaitStatus::Decode
static WaitStatus Decode(int wstatus)
lldb_private::ParseLinuxMapRegions
void ParseLinuxMapRegions(llvm::StringRef linux_map, LinuxMapCallback const &callback)
Definition: LinuxProcMaps.cpp:114
lldb_private::NativeProcessProtocol::GetThreadByID
NativeThreadProtocol * GetThreadByID(lldb::tid_t tid)
Definition: NativeProcessProtocol.cpp:114
lldb_private::StateAsCString
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition: State.cpp:14
lldb_private::process_linux::NativeProcessLinux::NativeProcessLinux
NativeProcessLinux(::pid_t pid, int terminal_fd, NativeDelegate &delegate, const ArchSpec &arch, MainLoop &mainloop, llvm::ArrayRef<::pid_t > tids)
Definition: NativeProcessLinux.cpp:309
lldb_private::process_linux::NativeProcessLinux::MonitorTrace
void MonitorTrace(NativeThreadLinux &thread)
Definition: NativeProcessLinux.cpp:706
lldb_private::NativeProcessProtocol::m_software_breakpoints
std::unordered_map< lldb::addr_t, SoftwareBreakpoint > m_software_breakpoints
Definition: NativeProcessProtocol.h:394
lldb_private::ProcessLaunchInfo::GetFileActionForFD
const FileAction * GetFileActionForFD(int fd) const
Definition: ProcessLaunchInfo.cpp:116
lldb_private::NativeProcessProtocol::SetExitStatus
virtual bool SetExitStatus(WaitStatus status, bool bNotifyStateChange)
Definition: NativeProcessProtocol.cpp:75
LIBLLDB_LOG_WATCHPOINTS
#define LIBLLDB_LOG_WATCHPOINTS
Definition: Logging.h:20
PROT_WRITE
#define PROT_WRITE
Definition: InferiorCallPOSIX.cpp:30
lldb_private::StateIsRunningState
bool StateIsRunningState(lldb::StateType state)
Check if a state represents a state where the process or thread is running.
Definition: State.cpp:68
lldb_private::process_linux::NativeThreadLinux
Definition: NativeThreadLinux.h:29
lldb_private::ResumeAction
Definition: Debug.h:19
lldb_private::process_linux::IntelPTManager::TraceStart
llvm::Error TraceStart(const TraceIntelPTStartRequest &request, const std::vector< lldb::tid_t > &process_threads)
Implementation of the jLLDBTraceStart packet.
Definition: IntelPTManager.cpp:588
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:193
lldb_private::process_linux::NativeProcessLinux::MonitorClone
bool MonitorClone(NativeThreadLinux &parent, lldb::pid_t child_pid, int event)
Definition: NativeProcessLinux.cpp:835
lldb_private::MemoryRegionInfo
Definition: MemoryRegionInfo.h:21
MaybeLogLaunchInfo
static void MaybeLogLaunchInfo(const ProcessLaunchInfo &info)
Definition: NativeProcessLinux.cpp:110
POSIX_LOG_PROCESS
#define POSIX_LOG_PROCESS
Definition: ProcessPOSIXLog.h:16
lldb_private::process_linux::IntelPTManager::OnThreadDestroyed
llvm::Error OnThreadDestroyed(lldb::tid_t tid)
Stops tracing a tracing upon a destroy event.
Definition: IntelPTManager.cpp:618
lldb_private::process_linux::NativeProcessLinux::PopulateMemoryRegionCache
Status PopulateMemoryRegionCache()
Definition: NativeProcessLinux.cpp:1153
lldb_private::ResumeAction::signal
int signal
Definition: Debug.h:25
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::MemoryRegionInfo::SetReadable
void SetReadable(OptionalBool val)
Definition: MemoryRegionInfo.h:54
lldb_private::NativeProcessProtocol::m_terminal_fd
int m_terminal_fd
Definition: NativeProcessProtocol.h:409
NativeThreadLinux.h
SIGSTOP
#define SIGSTOP
Definition: windows/PosixApi.h:32
ThreadLauncher.h
LLDB_LOGV
#define LLDB_LOGV(log,...)
Definition: Log.h:254
lldb_private::process_linux::NativeProcessLinux::Resume
Status Resume(const ResumeActionList &resume_actions) override
Definition: NativeProcessLinux.cpp:897
lldb_private::FileAction
Definition: FileAction.h:17
PTRACE_SETFPREGS
#define PTRACE_SETFPREGS
Definition: Ptrace.h:33
lldb_private::LinuxMapCallback
std::function< bool(llvm::Expected< MemoryRegionInfo >)> LinuxMapCallback
Definition: LinuxProcMaps.h:18
Procfs.h
Uio.h
lldb_private::process_linux::NativeProcessLinux::ThreadWasCreated
void ThreadWasCreated(NativeThreadLinux &thread)
Definition: NativeProcessLinux.cpp:1850
lldb_private::process_linux::NativeProcessLinux::UpdateThreads
size_t UpdateThreads() override
Definition: NativeProcessLinux.cpp:1478
lldb::eErrorTypePOSIX
@ eErrorTypePOSIX
POSIX error codes.
Definition: lldb-enumerations.h:310
lldb::eStateExited
@ eStateExited
Process has exited and can't be examined.
Definition: lldb-enumerations.h:90
lldb_private::NativeProcessProtocol::m_delegate
NativeDelegate & m_delegate
Definition: NativeProcessProtocol.h:406
lldb_private::NativeRegisterContext::SetPC
Status SetPC(lldb::addr_t pc)
Definition: NativeRegisterContext.cpp:147
Process.h
lldb_private::ParseLinuxSMapRegions
void ParseLinuxSMapRegions(llvm::StringRef linux_smap, LinuxMapCallback const &callback)
Definition: LinuxProcMaps.cpp:125
lldb_private::WaitStatus
Definition: Host.h:34
lldb_private::NativeRegisterContext::ReadRegisterAsUnsigned
lldb::addr_t ReadRegisterAsUnsigned(uint32_t reg, lldb::addr_t fail_value)
Definition: NativeRegisterContext.cpp:190
lldb_private::process_linux::NativeProcessLinux::WriteMemory
Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) override
Definition: NativeProcessLinux.cpp:1578
lldb_private::MainLoopBase
Definition: MainLoopBase.h:31
lldb_private::MainLoop::RegisterSignal
SignalHandleUP RegisterSignal(int signo, const Callback &callback, Status &error)
Definition: MainLoop.cpp:300
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:84
lldb_private::process_linux::NativeProcessLinux::HasThreadNoLock
bool HasThreadNoLock(lldb::tid_t thread_id)
Definition: NativeProcessLinux.cpp:1640
Target.h
lldb_private::process_linux::NativeProcessLinux::MonitorBreakpoint
void MonitorBreakpoint(NativeThreadLinux &thread)
Definition: NativeProcessLinux.cpp:716
lldb_private::NativeProcessProtocol::SetCurrentThreadID
void SetCurrentThreadID(lldb::tid_t tid)
Definition: NativeProcessProtocol.h:205
lldb_private::NativeProcessProtocol::GetSoftwareBreakpointTrapOpcode
virtual llvm::Expected< llvm::ArrayRef< uint8_t > > GetSoftwareBreakpointTrapOpcode(size_t size_hint)
Definition: NativeProcessProtocol.cpp:487
lldb_private::process_linux::NativeProcessLinux::MonitorSignal
void MonitorSignal(const siginfo_t &info, NativeThreadLinux &thread)
Definition: NativeProcessLinux.cpp:748
lldb_private::process_linux::NativeProcessLinux::TraceSupported
llvm::Expected< TraceSupportedResponse > TraceSupported() override
Get the processor tracing type supported for this process.
Definition: NativeProcessLinux.cpp:1942
lldb_private::NativeProcessProtocol::TraceGetBinaryData
virtual llvm::Expected< std::vector< uint8_t > > TraceGetBinaryData(const TraceGetBinaryDataRequest &request)
Get binary data given a trace technology and a data identifier.
Definition: NativeProcessProtocol.h:353
lldb_private::process_linux::NativeProcessLinux::SetBreakpoint
Status SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware) override
Definition: NativeProcessLinux.cpp:1485
lldb_private::FileSpec
Definition: FileSpec.h:56
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::Range::SetRangeEnd
void SetRangeEnd(BaseType end)
Definition: RangeMap.h:64
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:288
lldb_private::NativeProcessProtocol::NotifyDidExec
void NotifyDidExec()
Notify the delegate that an exec occurred.
Definition: NativeProcessProtocol.cpp:319
lldb_private::process_linux::NativeProcessLinux::WaitForCloneNotification
void WaitForCloneNotification(::pid_t pid)
Definition: NativeProcessLinux.cpp:503
lldb_private::process_linux::IntelPTManager::IsSupported
static bool IsSupported()
Definition: IntelPTManager.cpp:673
lldb::eStateCrashed
@ eStateCrashed
Process or thread has crashed and can be examined.
Definition: lldb-enumerations.h:88
lldb_private::process_linux::NativeProcessLinux::GetSoftwareBreakpointTrapOpcode
llvm::Expected< llvm::ArrayRef< uint8_t > > GetSoftwareBreakpointTrapOpcode(size_t size_hint) override
Definition: NativeProcessLinux.cpp:1501
PROT_NONE
#define PROT_NONE
Definition: InferiorCallPOSIX.cpp:28
lldb_private::process_linux::NativeThreadLinux::SetStoppedByFork
void SetStoppedByFork(bool is_vfork, lldb::pid_t child_pid)
Definition: NativeThreadLinux.cpp:456
lldb_private::process_linux::NativeProcessLinux::AddThread
NativeThreadLinux & AddThread(lldb::tid_t thread_id, bool resume)
Create a new thread.
Definition: NativeProcessLinux.cpp:1687
LLDBAssert.h
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_linux::NativeProcessLinux::SupportHardwareSingleStepping
bool SupportHardwareSingleStepping() const
Definition: NativeProcessLinux.cpp:891
SIGKILL
#define SIGKILL
Definition: windows/PosixApi.h:31
PTRACE_SETREGSET
#define PTRACE_SETREGSET
Definition: Ptrace.h:39
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
MAP_PRIVATE
#define MAP_PRIVATE
Definition: PlatformFreeBSD.cpp:35
lldb_private::process_linux
Definition: IntelPTManager.h:24
lldb_private::ResumeAction::state
lldb::StateType state
Definition: Debug.h:23
lldb_private::process_linux::NativeProcessLinux::NotifyTracersOfThreadDestroyed
Status NotifyTracersOfThreadDestroyed(lldb::tid_t tid)
Stop tracing threads upon a destroy event.
Definition: NativeProcessLinux.cpp:1677
lldb_private::Status::GetError
ValueType GetError() const
Access the error value.
Definition: Status.cpp:175
lldb_private::process_linux::NativeProcessLinux::TraceGetBinaryData
llvm::Expected< std::vector< uint8_t > > TraceGetBinaryData(const TraceGetBinaryDataRequest &request) override
Get binary data given a trace technology and a data identifier.
Definition: NativeProcessLinux.cpp:1976
TRAP_HWBKPT
#define TRAP_HWBKPT
Definition: NativeProcessLinux.cpp:63
lldb_private::MemoryRegionInfo::SetExecutable
void SetExecutable(OptionalBool val)
Definition: MemoryRegionInfo.h:58
lldb::eStateConnected
@ eStateConnected
Process is connected to remote debug services, but not launched or attached to anything yet.
Definition: lldb-enumerations.h:76
lldb_private::process_linux::NativeProcessLinux::GetFileLoadAddress
Status GetFileLoadAddress(const llvm::StringRef &file_name, lldb::addr_t &load_addr) override
Definition: NativeProcessLinux.cpp:1735
lldb_private::Status::Fail
bool Fail() const
Test for error condition.
Definition: Status.cpp:182
lldb_private::process_linux::NativeRegisterContextLinux::GetMmapData
virtual llvm::Optional< MmapData > GetMmapData()
Return the architecture-specific data needed to make mmap syscalls, if they are supported.
Definition: NativeRegisterContextLinux.h:60
lldb_private::NativeProcessProtocol::m_enabled_extensions
Extension m_enabled_extensions
Definition: NativeProcessProtocol.h:417
lldb_private::StreamString::GetData
const char * GetData() const
Definition: StreamString.h:43
SIGTRAP
#define SIGTRAP
Definition: windows/PosixApi.h:30
lldb::eStateLaunching
@ eStateLaunching
Process is in the process of launching.
Definition: lldb-enumerations.h:79
lldb_private::process_linux::NativeProcessLinux::NotifyTracersOfNewThread
Status NotifyTracersOfNewThread(lldb::tid_t tid)
Start tracing a new thread if process tracing is enabled.
Definition: NativeProcessLinux.cpp:1668
lldb_private::MemoryRegionInfo::eYes
@ eYes
Definition: MemoryRegionInfo.h:25
lldb_private::NativeProcessProtocol::GetID
lldb::pid_t GetID() const
Definition: NativeProcessProtocol.h:172
lldb_private::ProcessLauncherPosixFork::LaunchProcess
HostProcess LaunchProcess(const ProcessLaunchInfo &launch_info, Status &error) override
Definition: ProcessLauncherPosixFork.cpp:258
lldb_private::process_linux::NativeThreadLinux::SingleStep
Status SingleStep(uint32_t signo)
Single steps the thread.
Definition: NativeThreadLinux.cpp:252
lldb_private::NativeProcessProtocol::m_signals_to_ignore
llvm::DenseSet< int > m_signals_to_ignore
Definition: NativeProcessProtocol.h:414
lldb_private::process_linux::IntelPTManager::GetState
llvm::Expected< llvm::json::Value > GetState() const
Implementation of the jLLDBTraceGetState packet.
Definition: IntelPTManager.cpp:626
lldb_private::StreamString
Definition: StreamString.h:23
process_vm_readv
ssize_t process_vm_readv(::pid_t pid, const struct iovec *local_iov, unsigned long liovcnt, const struct iovec *remote_iov, unsigned long riovcnt, unsigned long flags)
Definition: linux/LibcGlue.cpp:18
lldb_private::process_linux::NativeProcessLinux::StopTrackingThread
void StopTrackingThread(NativeThreadLinux &thread)
Definition: NativeProcessLinux.cpp:1653
lldb_private::process_linux::NativeProcessLinux::ResumeThread
Status ResumeThread(NativeThreadLinux &thread, lldb::StateType state, int signo)
Definition: NativeProcessLinux.cpp:1762
lldb_private::process_linux::NativeProcessLinux
Definition: NativeProcessLinux.h:40
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
lldb_private::NativeProcessProtocol::m_state
lldb::StateType m_state
Definition: NativeProcessProtocol.h:401
ProcessPOSIXLog.h
lldb_private::NativeProcessProtocol::NativeDelegate::NewSubprocess
virtual void NewSubprocess(NativeProcessProtocol *parent_process, std::unique_ptr< NativeProcessProtocol > child_process)=0
lldb_private::process_linux::NativeThreadLinux::GetState
lldb::StateType GetState() override
Definition: NativeThreadLinux.cpp:109
lldb_private::Range< lldb::addr_t, lldb::addr_t >
DisplayBytes
static void DisplayBytes(StreamString &s, void *bytes, uint32_t count)
Definition: NativeProcessLinux.cpp:136
lldb_private::process_linux::NativeProcessLinux::GetLoadedModuleFileSpec
Status GetLoadedModuleFileSpec(const char *module_path, FileSpec &file_spec) override
Definition: NativeProcessLinux.cpp:1715
lldb::eStateDetached
@ eStateDetached
Process has been detached and can't be examined.
Definition: lldb-enumerations.h:89
lldb_private::process_linux::NativeProcessLinux::TraceStart
llvm::Error TraceStart(llvm::StringRef json_request, llvm::StringRef type) override
Tracing These methods implement the jLLDBTrace packets.
Definition: NativeProcessLinux.cpp:1948
lldb_private::process_linux::NativeThreadLinux::SetStoppedByTrace
void SetStoppedByTrace()
Definition: NativeThreadLinux.cpp:449
lldb_private::NativeProcessProtocol::Extension::vfork
@ vfork
PROT_READ
#define PROT_READ
Definition: InferiorCallPOSIX.cpp:29
lldb_private::NativeRegisterContext::ReadAllRegisterValues
virtual Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp)=0
lldb_private::getProcFile
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getProcFile(::pid_t pid, ::pid_t tid, const llvm::Twine &file)
Definition: Support.cpp:14
lldb_private::FileSystem::Resolve
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
Definition: common/FileSystem.cpp:255
lldb_private::process_linux::NativeThreadLinux::RequestStop
Status RequestStop()
Definition: NativeThreadLinux.cpp:495
lldb_private::HostProcess::GetProcessId
lldb::pid_t GetProcessId() const
Definition: HostProcess.cpp:29
k_ptrace_word_size
static constexpr unsigned k_ptrace_word_size
Definition: NativeProcessLinux.cpp:192
lldb_private::process_linux::NativeProcessLinux::TraceGetState
llvm::Expected< llvm::json::Value > TraceGetState(llvm::StringRef type) override
Get the current tracing state of the process and its threads.
Definition: NativeProcessLinux.cpp:1970
PROT_EXEC
#define PROT_EXEC
Definition: InferiorCallPOSIX.cpp:31
lldb_private::process_linux::NativeProcessLinux::m_sigchld_handle
MainLoop::SignalHandleUP m_sigchld_handle
Definition: NativeProcessLinux.h:149
lldb::eStateUnloaded
@ eStateUnloaded
Process is object is valid, but not currently loaded.
Definition: lldb-enumerations.h:75
lldb_private::process_linux::NativeProcessLinux::Kill
Status Kill() override
Definition: NativeProcessLinux.cpp:1048
lldb_private::process_linux::NativeThreadLinux::SetStoppedByBreakpoint
void SetStoppedByBreakpoint()
Definition: NativeThreadLinux.cpp:403
lldb_private::NativeProcessProtocol::m_threads
std::vector< std::unique_ptr< NativeThreadProtocol > > m_threads
Definition: NativeProcessProtocol.h:397
lldb_private::process_linux::NativeProcessLinux::WriteMemoryTags
Status WriteMemoryTags(int32_t type, lldb::addr_t addr, size_t len, const std::vector< uint8_t > &tags) override
Definition: NativeProcessLinux.cpp:1408
lldb_private::NativeProcessProtocol::Extension::fork
@ fork
lldb_private::NativeProcessProtocol::RemoveBreakpoint
virtual Status RemoveBreakpoint(lldb::addr_t addr, bool hardware=false)
Definition: NativeProcessProtocol.cpp:605
lldb_private::process_linux::NativeProcessLinux::SigchldHandler
void SigchldHandler()
Definition: NativeProcessLinux.cpp:1862
lldb_private::process_linux::NativeProcessLinux::Interrupt
Status Interrupt() override
Tells a process to interrupt all operations as if by a Ctrl-C.
Definition: NativeProcessLinux.cpp:1005
lldb_private::ProcessLaunchInfo::GetPTY
PseudoTerminal & GetPTY()
Definition: ProcessLaunchInfo.h:125
lldb_private::ArchSpec::GetAddressByteSize
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition: ArchSpec.cpp:683
ObjectFile.h
lldb_private::MemoryRegionInfo::SetWritable
void SetWritable(OptionalBool val)
Definition: MemoryRegionInfo.h:56
lldb_private::NativeProcessProtocol::Extension
Extension
Extension flag constants, returned by Factory::GetSupportedExtensions() and passed to SetEnabledExten...
Definition: NativeProcessProtocol.h:245
lldb_private::process_linux::NativeThreadLinux::SetStoppedBySignal
void SetStoppedBySignal(uint32_t signo, const siginfo_t *info=nullptr)
Definition: NativeThreadLinux.cpp:278
lldb_private::FileSpec::Clear
void Clear()
Clears the object state.
Definition: FileSpec.cpp:259
__ptrace_request
int __ptrace_request
Definition: Ptrace.h:17
lldb_private::process_linux::NativeProcessLinux::Attach
static llvm::Expected< std::vector<::pid_t > > Attach(::pid_t pid)
Definition: NativeProcessLinux.cpp:338
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_linux::NativeProcessLinux::Detach
Status Detach() override
Definition: NativeProcessLinux.cpp:970
lldb::eStateStepping
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
Definition: lldb-enumerations.h:86
lldb_private::process_linux::NativeProcessLinux::MonitorWatchpoint
void MonitorWatchpoint(NativeThreadLinux &thread, uint32_t wp_index)
Definition: NativeProcessLinux.cpp:732
lldb_private::TraceStopRequest
jLLDBTraceStop gdb-remote packet
Definition: TraceGDBRemotePackets.h:62
HWCAP2_MTE
#define HWCAP2_MTE
Definition: NativeProcessLinux.cpp:67
lldb_private::process_linux::NativeRegisterContextLinux::GetSyscallData
virtual llvm::Optional< SyscallData > GetSyscallData()
Return architecture-specific data needed to make inferior syscalls, if they are supported.
Definition: NativeRegisterContextLinux.h:50
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:91
lldb_private::NativeProcessProtocol::FixupBreakpointPCAsNeeded
void FixupBreakpointPCAsNeeded(NativeThreadProtocol &thread)
Definition: NativeProcessProtocol.cpp:555
lldb_private::process_linux::IntelPTManager::Clear
void Clear()
Dispose of all traces.
Definition: IntelPTManager.cpp:686
lldb_private::process_linux::NativeProcessLinux::m_supports_mem_region
LazyBool m_supports_mem_region
Definition: NativeProcessLinux.h:153
lldb_private::Status
Definition: Status.h:44
POSIX_LOG_MEMORY
#define POSIX_LOG_MEMORY
Definition: ProcessPOSIXLog.h:18
lldb_private::PseudoTerminal::ReleasePrimaryFileDescriptor
int ReleasePrimaryFileDescriptor()
Release the primary file descriptor.
Definition: PseudoTerminal.cpp:184
lldb_private::process_linux::NativeProcessLinux::GetCurrentThread
NativeThreadLinux * GetCurrentThread()
Definition: NativeProcessLinux.cpp:1757
lldb_private::process_linux::NativeThreadLinux::SetStoppedByWatchpoint
void SetStoppedByWatchpoint(uint32_t wp_index)
Definition: NativeThreadLinux.cpp:411
message
message(FATAL_ERROR "invalid libipt include path provided") endif() include_directories($
Definition: Plugins/Trace/intel-pt/CMakeLists.txt:6
uint32_t
lldb_private::process_linux::NativeProcessLinux::Signal
Status Signal(int signo) override
Sends a process a UNIX signal signal.
Definition: NativeProcessLinux.cpp:992
lldb_private::eLazyBoolNo
@ eLazyBoolNo
Definition: lldb-private-enumerations.h:115
LIBLLDB_LOG_BREAKPOINTS
#define LIBLLDB_LOG_BREAKPOINTS
Definition: Logging.h:19
lldb_private::NativeProcessProtocol::TraceStop
virtual llvm::Error TraceStop(const TraceStopRequest &request)
Stop tracing a live process or its threads.
Definition: NativeProcessProtocol.h:337
lldb_private::process_linux::NativeProcessLinux::m_main_loop
MainLoop & m_main_loop
Definition: NativeProcessLinux.h:151
lldb_private::Args::GetConstArgumentVector
const char ** GetConstArgumentVector() const
Gets the argument vector.
Definition: Args.cpp:275
lldb_private::MainLoop
Definition: MainLoop.h:38
lldb_private::process_linux::NativeProcessLinux::AllocateMemory
llvm::Expected< lldb::addr_t > AllocateMemory(size_t size, uint32_t permissions) override
Definition: NativeProcessLinux.cpp:1308
lldb_private::NativeProcessProtocol::RemoveHardwareBreakpoint
virtual Status RemoveHardwareBreakpoint(lldb::addr_t addr)
Definition: NativeProcessProtocol.cpp:291
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
Host.h
lldb_private::process_linux::NativeRegisterContextLinux::GetMemoryTaggingDetails
virtual llvm::Expected< MemoryTaggingDetails > GetMemoryTaggingDetails(int32_t type)
Return architecture specific data needed to use memory tags, if they are supported.
Definition: NativeRegisterContextLinux.h:72
StringExtractor.h
lldb_private::NativeThreadProtocol::GetID
lldb::tid_t GetID() const
Definition: NativeThreadProtocol.h:39
lldb_private::MemoryRegionInfo::SetMapped
void SetMapped(OptionalBool val)
Definition: MemoryRegionInfo.h:60
lldb_private::NativeProcessProtocol::GetState
lldb::StateType GetState() const
Definition: NativeProcessProtocol.cpp:693
lldb_private::Range::SetRangeBase
void SetRangeBase(BaseType b)
Definition: RangeMap.h:48
lldb_private::Range::GetByteSize
SizeType GetByteSize() const
Definition: RangeMap.h:71
lldb_private::process_linux::NativeProcessLinux::StopRunningThreads
void StopRunningThreads(lldb::tid_t triggering_tid)
Definition: NativeProcessLinux.cpp:1803
lldb_private::NativeProcessProtocol::TraceGetState
virtual llvm::Expected< llvm::json::Value > TraceGetState(llvm::StringRef type)
Get the current tracing state of the process and its threads.
Definition: NativeProcessProtocol.h:345
lldb_private::Range::SetByteSize
void SetByteSize(SizeType s)
Definition: RangeMap.h:73
lldb_private::NativeRegisterContext::GetHardwareBreakHitIndex
virtual Status GetHardwareBreakHitIndex(uint32_t &bp_index, lldb::addr_t trap_addr)
Definition: NativeRegisterContext.cpp:263
PseudoTerminal.h
lldb_private::process_linux::IntelPTManager::GetBinaryData
llvm::Expected< std::vector< uint8_t > > GetBinaryData(const TraceGetBinaryDataRequest &request) const
Implementation of the jLLDBTraceGetBinaryData packet.
Definition: IntelPTManager.cpp:656
PtraceDisplayBytes
static void PtraceDisplayBytes(int &req, void *data, size_t data_size)
Definition: NativeProcessLinux.cpp:145
Ptrace.h
lldb_private::process_linux::NativeThreadLinux::SetStoppedWithNoReason
void SetStoppedWithNoReason()
Definition: NativeThreadLinux.cpp:471
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
POSIX_LOG_PTRACE
#define POSIX_LOG_PTRACE
Definition: ProcessPOSIXLog.h:19
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:240
lldb_private::TraceGetBinaryDataRequest::type
std::string type
Tracing technology name, e.g. intel-pt, arm-coresight.
Definition: TraceGDBRemotePackets.h:134
lldb_private::process_linux::NativeProcessLinux::m_arch
ArchSpec m_arch
Definition: NativeProcessLinux.h:150
lldb_private::process_linux::NativeProcessLinux::SignalIfAllThreadsStopped
void SignalIfAllThreadsStopped()
Definition: NativeProcessLinux.cpp:1821
lldb_private::NativeProcessSoftwareSingleStep::SetupSoftwareSingleStepping
Status SetupSoftwareSingleStepping(NativeThreadProtocol &thread)
Definition: NativeProcessSoftwareSingleStep.cpp:97
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private::process_linux::NativeProcessLinux::m_intel_pt_manager
IntelPTManager m_intel_pt_manager
Manages Intel PT process and thread traces.
Definition: NativeProcessLinux.h:244
lldb_private::MemoryRegionInfo::GetRange
RangeType & GetRange()
Definition: MemoryRegionInfo.h:36
lldb_private::FileSystem::Instance
static FileSystem & Instance()
Definition: common/FileSystem.cpp:45
lldb_private::WaitStatus::Signal
@ Signal
Definition: Host.h:38
Status.h
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
fork
pid_t fork(void)
Definition: windows/PosixApi.h:121
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:29
NativeProcessLinux.h
lldb::eStateInvalid
@ eStateInvalid
Definition: lldb-enumerations.h:74
lldb_private::process_linux::NativeProcessLinux::TraceStop
llvm::Error TraceStop(const TraceStopRequest &request) override
Stop tracing a live process or its threads.
Definition: NativeProcessLinux.cpp:1964
lldb_private::Status::ToError
llvm::Error ToError() const
Definition: Status.cpp:90
lldb_private::process_linux::NativeProcessLinux::Halt
Status Halt() override
Definition: NativeProcessLinux.cpp:961
ProcessVmReadvSupported
static bool ProcessVmReadvSupported()
Definition: NativeProcessLinux.cpp:77
lldb_private::NativeProcessProtocol::TraceSupported
virtual llvm::Expected< TraceSupportedResponse > TraceSupported()
Get the processor tracing type supported for this process.
Definition: NativeProcessProtocol.h:361
lldb_private::process_linux::NativeProcessLinux::m_mem_region_cache
std::vector< std::pair< MemoryRegionInfo, FileSpec > > m_mem_region_cache
Definition: NativeProcessLinux.h:154
lldb_private::process_linux::NativeThreadLinux::GetRegisterContext
NativeRegisterContextLinux & GetRegisterContext() override
Definition: NativeThreadLinux.h:43
State.h
lldb_private::process_linux::NativeProcessLinux::RemoveBreakpoint
Status RemoveBreakpoint(lldb::addr_t addr, bool hardware=false) override
Definition: NativeProcessLinux.cpp:1493
LinuxProcMaps.h
LLDB_INVALID_INDEX32
#define LLDB_INVALID_INDEX32
Definition: lldb-defines.h:75
LLDB_INVALID_THREAD_ID
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:82
lldb::StateType
StateType
Process and Thread States.
Definition: lldb-enumerations.h:73
lldb_private::process_linux::NativeRegisterContextLinux::SyscallData::Result
uint32_t Result
Register containing the syscall result.
Definition: NativeRegisterContextLinux.h:46
lldb_private::process_linux::NativeProcessLinux::Syscall
llvm::Expected< uint64_t > Syscall(llvm::ArrayRef< uint64_t > args)
Definition: NativeProcessLinux.cpp:1225
lldb_private::Log
Definition: Log.h:49
lldb_private::getPIDForTID
llvm::Optional< lldb::pid_t > getPIDForTID(lldb::pid_t tid)
Definition: linux/Host.cpp:318
lldb_private::process_linux::NativeRegisterContextLinux::SyscallData
Definition: NativeRegisterContextLinux.h:36
lldb_private::process_linux::NativeProcessLinux::ReadMemory
Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override
Definition: NativeProcessLinux.cpp:1523
lldb_private::Host::FindProcessThreads
static bool FindProcessThreads(const lldb::pid_t pid, TidMap &tids_to_attach)
Definition: common/Host.cpp:439
lldb_private::ProcessPOSIXLog::GetLogIfAllCategoriesSet
static Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: ProcessPOSIXLog.h:33
lldb_private::GetLogIfAnyCategoriesSet
Log * GetLogIfAnyCategoriesSet(uint32_t mask)
Definition: Logging.cpp:62
lldb_private::process_linux::NativeProcessLinux::DeallocateMemory
llvm::Error DeallocateMemory(lldb::addr_t addr) override
Definition: NativeProcessLinux.cpp:1334
lldb_private::process_linux::IntelPTManager::OnThreadCreated
llvm::Error OnThreadCreated(lldb::tid_t tid)
If "process tracing" is enabled, then trace the given thread.
Definition: IntelPTManager.cpp:612
lldb_private::process_linux::NativeProcessLinux::m_allocated_memory
llvm::DenseMap< lldb::addr_t, lldb::addr_t > m_allocated_memory
Inferior memory (allocated by us) and its size.
Definition: NativeProcessLinux.h:159
lldb_private::process_linux::NativeRegisterContextLinux::SyscallData::Insn
llvm::ArrayRef< uint8_t > Insn
The syscall instruction.
Definition: NativeRegisterContextLinux.h:40
lldb_private::TraceStopRequest::type
std::string type
Tracing technology name, e.g. intel-pt, arm-coresight.
Definition: TraceGDBRemotePackets.h:72
lldb_private::Range::Contains
bool Contains(BaseType r) const
Definition: RangeMap.h:77
lldb_private::NativeRegisterContext::WriteAllRegisterValues
virtual Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp)=0
lldb
Definition: SBAddress.h:15
LIBLLDB_LOG_PROCESS
#define LIBLLDB_LOG_PROCESS
Definition: Logging.h:15
lldb::eStateRunning
@ eStateRunning
Process or thread is running and can't be examined.
Definition: lldb-enumerations.h:85
lldb_private::WaitStatus::Exit
@ Exit
Definition: Host.h:36
NativeRegisterContext.h
lldb_private::FileSpec::GetFilename
ConstString & GetFilename()
Filename string get accessor.
Definition: FileSpec.cpp:339
lldb_private::Host::TidMap
std::map< lldb::pid_t, bool > TidMap
Definition: Host.h:180
lldb_private::process_linux::NativeProcessLinux::SetDefaultPtraceOpts
static Status SetDefaultPtraceOpts(const lldb::pid_t)
Definition: NativeProcessLinux.cpp:402
EnsureFDFlags
static Status EnsureFDFlags(int fd, int flags)
Definition: NativeProcessLinux.cpp:198
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86
lldb_private::process_linux::NativeProcessLinux::GetArchitecture
const ArchSpec & GetArchitecture() const override
Definition: NativeProcessLinux.h:91
lldb_private::Status::AsCString
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:131
lldb_private::process_linux::NativeRegisterContextLinux::SyscallData::Args
llvm::ArrayRef< uint32_t > Args
Registers used for syscall arguments.
Definition: NativeRegisterContextLinux.h:44
ProcessLauncherPosixFork.h
lldb_private::process_linux::NativeProcessLinux::ReadMemoryTags
Status ReadMemoryTags(int32_t type, lldb::addr_t addr, size_t len, std::vector< uint8_t > &tags) override
Definition: NativeProcessLinux.cpp:1354
lldb_private::process_linux::NativeProcessLinux::GetMemoryRegionInfo
Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info) override
Definition: NativeProcessLinux.cpp:1084