LLDB  mainline
ProcessKDP.cpp
Go to the documentation of this file.
1 //===-- ProcessKDP.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 <cerrno>
10 #include <cstdlib>
11 
12 #include <memory>
13 #include <mutex>
14 
15 #include "lldb/Core/Debugger.h"
16 #include "lldb/Core/Module.h"
17 #include "lldb/Core/ModuleSpec.h"
20 #include "lldb/Host/Host.h"
31 #include "lldb/Symbol/ObjectFile.h"
33 #include "lldb/Target/Target.h"
34 #include "lldb/Target/Thread.h"
35 #include "lldb/Utility/Log.h"
36 #include "lldb/Utility/State.h"
38 #include "lldb/Utility/UUID.h"
39 
40 #include "llvm/Support/Threading.h"
41 
42 #define USEC_PER_SEC 1000000
43 
46 #include "ProcessKDP.h"
47 #include "ProcessKDPLog.h"
48 #include "ThreadKDP.h"
49 
50 using namespace lldb;
51 using namespace lldb_private;
52 
53 LLDB_PLUGIN_DEFINE_ADV(ProcessKDP, ProcessMacOSXKernel)
54 
55 namespace {
56 
57 #define LLDB_PROPERTIES_processkdp
58 #include "ProcessKDPProperties.inc"
59 
60 enum {
61 #define LLDB_PROPERTIES_processkdp
62 #include "ProcessKDPPropertiesEnum.inc"
63 };
64 
65 class PluginProperties : public Properties {
66 public:
67  static ConstString GetSettingName() {
69  }
70 
71  PluginProperties() : Properties() {
72  m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
73  m_collection_sp->Initialize(g_processkdp_properties);
74  }
75 
76  virtual ~PluginProperties() = default;
77 
78  uint64_t GetPacketTimeout() {
79  const uint32_t idx = ePropertyKDPPacketTimeout;
80  return m_collection_sp->GetPropertyAtIndexAsUInt64(
81  NULL, idx, g_processkdp_properties[idx].default_uint_value);
82  }
83 };
84 
85 static PluginProperties &GetGlobalPluginProperties() {
86  static PluginProperties g_settings;
87  return g_settings;
88 }
89 
90 } // anonymous namespace end
91 
92 static const lldb::tid_t g_kernel_tid = 1;
93 
95  return "KDP Remote protocol based debugging plug-in for darwin kernel "
96  "debugging.";
97 }
98 
100  PluginManager::UnregisterPlugin(ProcessKDP::CreateInstance);
101 }
102 
103 lldb::ProcessSP ProcessKDP::CreateInstance(TargetSP target_sp,
104  ListenerSP listener_sp,
105  const FileSpec *crash_file_path,
106  bool can_connect) {
107  lldb::ProcessSP process_sp;
108  if (crash_file_path == NULL)
109  process_sp = std::make_shared<ProcessKDP>(target_sp, listener_sp);
110  return process_sp;
111 }
112 
113 bool ProcessKDP::CanDebug(TargetSP target_sp, bool plugin_specified_by_name) {
114  if (plugin_specified_by_name)
115  return true;
116 
117  // For now we are just making sure the file exists for a given module
118  Module *exe_module = target_sp->GetExecutableModulePointer();
119  if (exe_module) {
120  const llvm::Triple &triple_ref = target_sp->GetArchitecture().GetTriple();
121  switch (triple_ref.getOS()) {
122  case llvm::Triple::Darwin: // Should use "macosx" for desktop and "ios" for
123  // iOS, but accept darwin just in case
124  case llvm::Triple::MacOSX: // For desktop targets
125  case llvm::Triple::IOS: // For arm targets
126  case llvm::Triple::TvOS:
127  case llvm::Triple::WatchOS:
128  if (triple_ref.getVendor() == llvm::Triple::Apple) {
129  ObjectFile *exe_objfile = exe_module->GetObjectFile();
130  if (exe_objfile->GetType() == ObjectFile::eTypeExecutable &&
131  exe_objfile->GetStrata() == ObjectFile::eStrataKernel)
132  return true;
133  }
134  break;
135 
136  default:
137  break;
138  }
139  }
140  return false;
141 }
142 
143 // ProcessKDP constructor
144 ProcessKDP::ProcessKDP(TargetSP target_sp, ListenerSP listener_sp)
145  : Process(target_sp, listener_sp),
146  m_comm("lldb.process.kdp-remote.communication"),
147  m_async_broadcaster(NULL, "lldb.process.kdp-remote.async-broadcaster"),
148  m_kernel_load_addr(LLDB_INVALID_ADDRESS), m_command_sp(),
149  m_kernel_thread_wp() {
151  "async thread should exit");
153  "async thread continue");
154  const uint64_t timeout_seconds =
155  GetGlobalPluginProperties().GetPacketTimeout();
156  if (timeout_seconds > 0)
157  m_comm.SetPacketTimeout(std::chrono::seconds(timeout_seconds));
158 }
159 
160 // Destructor
162  Clear();
163  // We need to call finalize on the process before destroying ourselves to
164  // make sure all of the broadcaster cleanup goes as planned. If we destruct
165  // this class, then Process::~Process() might have problems trying to fully
166  // destroy the broadcaster.
167  Finalize();
168 }
169 
171  Status error;
172  error.SetErrorString("launching not supported in kdp-remote plug-in");
173  return error;
174 }
175 
177  Status error;
178  error.SetErrorString(
179  "attaching to a by process ID not supported in kdp-remote plug-in");
180  return error;
181 }
182 
184  bool wait_for_launch) {
185  Status error;
186  error.SetErrorString(
187  "attaching to a by process name not supported in kdp-remote plug-in");
188  return error;
189 }
190 
192  uint32_t cpu = m_comm.GetCPUType();
193  if (cpu) {
194  uint32_t sub = m_comm.GetCPUSubtype();
195  arch.SetArchitecture(eArchTypeMachO, cpu, sub);
196  // Leave architecture vendor as unspecified unknown
197  arch.GetTriple().setVendor(llvm::Triple::UnknownVendor);
198  arch.GetTriple().setVendorName(llvm::StringRef());
199  return true;
200  }
201  arch.Clear();
202  return false;
203 }
204 
205 Status ProcessKDP::DoConnectRemote(llvm::StringRef remote_url) {
206  Status error;
207 
208  // Don't let any JIT happen when doing KDP as we can't allocate memory and we
209  // don't want to be mucking with threads that might already be handling
210  // exceptions
211  SetCanJIT(false);
212 
213  if (remote_url.empty()) {
214  error.SetErrorStringWithFormat("empty connection URL");
215  return error;
216  }
217 
218  std::unique_ptr<ConnectionFileDescriptor> conn_up(
220  if (conn_up) {
221  // Only try once for now.
222  // TODO: check if we should be retrying?
223  const uint32_t max_retry_count = 1;
224  for (uint32_t retry_count = 0; retry_count < max_retry_count;
225  ++retry_count) {
226  if (conn_up->Connect(remote_url, &error) == eConnectionStatusSuccess)
227  break;
228  usleep(100000);
229  }
230  }
231 
232  if (conn_up->IsConnected()) {
233  const TCPSocket &socket =
234  static_cast<const TCPSocket &>(*conn_up->GetReadObject());
235  const uint16_t reply_port = socket.GetLocalPortNumber();
236 
237  if (reply_port != 0) {
238  m_comm.SetConnection(std::move(conn_up));
239 
240  if (m_comm.SendRequestReattach(reply_port)) {
241  if (m_comm.SendRequestConnect(reply_port, reply_port,
242  "Greetings from LLDB...")) {
243  m_comm.GetVersion();
244 
245  Target &target = GetTarget();
246  ArchSpec kernel_arch;
247  // The host architecture
248  GetHostArchitecture(kernel_arch);
249  ArchSpec target_arch = target.GetArchitecture();
250  // Merge in any unspecified stuff into the target architecture in
251  // case the target arch isn't set at all or incompletely.
252  target_arch.MergeFrom(kernel_arch);
253  target.SetArchitecture(target_arch);
254 
255  /* Get the kernel's UUID and load address via KDP_KERNELVERSION
256  * packet. */
257  /* An EFI kdp session has neither UUID nor load address. */
258 
259  UUID kernel_uuid = m_comm.GetUUID();
260  addr_t kernel_load_addr = m_comm.GetLoadAddress();
261 
262  if (m_comm.RemoteIsEFI()) {
263  // Select an invalid plugin name for the dynamic loader so one
264  // doesn't get used since EFI does its own manual loading via
265  // python scripting
266  m_dyld_plugin_name = "none";
267 
268  if (kernel_uuid.IsValid()) {
269  // If EFI passed in a UUID= try to lookup UUID The slide will not
270  // be provided. But the UUID lookup will be used to launch EFI
271  // debug scripts from the dSYM, that can load all of the symbols.
272  ModuleSpec module_spec;
273  module_spec.GetUUID() = kernel_uuid;
274  module_spec.GetArchitecture() = target.GetArchitecture();
275 
276  // Lookup UUID locally, before attempting dsymForUUID like action
277  FileSpecList search_paths =
278  Target::GetDefaultDebugFileSearchPaths();
279  module_spec.GetSymbolFileSpec() =
280  Symbols::LocateExecutableSymbolFile(module_spec,
281  search_paths);
282  if (module_spec.GetSymbolFileSpec()) {
283  ModuleSpec executable_module_spec =
284  Symbols::LocateExecutableObjectFile(module_spec);
285  if (FileSystem::Instance().Exists(
286  executable_module_spec.GetFileSpec())) {
287  module_spec.GetFileSpec() =
288  executable_module_spec.GetFileSpec();
289  }
290  }
291  if (!module_spec.GetSymbolFileSpec() ||
292  !module_spec.GetSymbolFileSpec())
293  Symbols::DownloadObjectAndSymbolFile(module_spec, true);
294 
295  if (FileSystem::Instance().Exists(module_spec.GetFileSpec())) {
296  ModuleSP module_sp(new Module(module_spec));
297  if (module_sp.get() && module_sp->GetObjectFile()) {
298  // Get the current target executable
299  ModuleSP exe_module_sp(target.GetExecutableModule());
300 
301  // Make sure you don't already have the right module loaded
302  // and they will be uniqued
303  if (exe_module_sp.get() != module_sp.get())
304  target.SetExecutableModule(module_sp, eLoadDependentsNo);
305  }
306  }
307  }
308  } else if (m_comm.RemoteIsDarwinKernel()) {
311  if (kernel_load_addr != LLDB_INVALID_ADDRESS) {
312  m_kernel_load_addr = kernel_load_addr;
313  }
314  }
315 
316  // Set the thread ID
318  SetID(1);
319  GetThreadList();
321  StreamSP async_strm_sp(target.GetDebugger().GetAsyncOutputStream());
322  if (async_strm_sp) {
323  const char *cstr;
324  if ((cstr = m_comm.GetKernelVersion()) != NULL) {
325  async_strm_sp->Printf("Version: %s\n", cstr);
326  async_strm_sp->Flush();
327  }
328  // if ((cstr = m_comm.GetImagePath ()) != NULL)
329  // {
330  // async_strm_sp->Printf ("Image Path:
331  // %s\n", cstr);
332  // async_strm_sp->Flush();
333  // }
334  }
335  } else {
336  error.SetErrorString("KDP_REATTACH failed");
337  }
338  } else {
339  error.SetErrorString("KDP_REATTACH failed");
340  }
341  } else {
342  error.SetErrorString("invalid reply port from UDP connection");
343  }
344  } else {
345  if (error.Success())
346  error.SetErrorStringWithFormat("failed to connect to '%s'",
347  remote_url.str().c_str());
348  }
349  if (error.Fail())
350  m_comm.Disconnect();
351 
352  return error;
353 }
354 
355 // Process Control
357  ProcessLaunchInfo &launch_info) {
358  Status error;
359  error.SetErrorString("launching not supported in kdp-remote plug-in");
360  return error;
361 }
362 
363 Status
365  const ProcessAttachInfo &attach_info) {
366  Status error;
367  error.SetErrorString(
368  "attach to process by ID is not supported in kdp remote debugging");
369  return error;
370 }
371 
372 Status
373 ProcessKDP::DoAttachToProcessWithName(const char *process_name,
374  const ProcessAttachInfo &attach_info) {
375  Status error;
376  error.SetErrorString(
377  "attach to process by name is not supported in kdp remote debugging");
378  return error;
379 }
380 
381 void ProcessKDP::DidAttach(ArchSpec &process_arch) {
382  Process::DidAttach(process_arch);
383 
385  LLDB_LOGF(log, "ProcessKDP::DidAttach()");
386  if (GetID() != LLDB_INVALID_PROCESS_ID) {
387  GetHostArchitecture(process_arch);
388  }
389 }
390 
392 
394  if (m_dyld_up.get() == NULL)
395  m_dyld_up.reset(DynamicLoader::FindPlugin(this, m_dyld_plugin_name));
396  return m_dyld_up.get();
397 }
398 
400 
402  Status error;
404  // Only start the async thread if we try to do any process control
405  if (!m_async_thread.IsJoinable())
407 
408  bool resume = false;
409 
410  // With KDP there is only one thread we can tell what to do
411  ThreadSP kernel_thread_sp(m_thread_list.FindThreadByProtocolID(g_kernel_tid));
412 
413  if (kernel_thread_sp) {
414  const StateType thread_resume_state =
415  kernel_thread_sp->GetTemporaryResumeState();
416 
417  LLDB_LOGF(log, "ProcessKDP::DoResume() thread_resume_state = %s",
418  StateAsCString(thread_resume_state));
419  switch (thread_resume_state) {
420  case eStateSuspended:
421  // Nothing to do here when a thread will stay suspended we just leave the
422  // CPU mask bit set to zero for the thread
423  LLDB_LOGF(log, "ProcessKDP::DoResume() = suspended???");
424  break;
425 
426  case eStateStepping: {
427  lldb::RegisterContextSP reg_ctx_sp(
428  kernel_thread_sp->GetRegisterContext());
429 
430  if (reg_ctx_sp) {
431  LLDB_LOGF(
432  log,
433  "ProcessKDP::DoResume () reg_ctx_sp->HardwareSingleStep (true);");
434  reg_ctx_sp->HardwareSingleStep(true);
435  resume = true;
436  } else {
437  error.SetErrorStringWithFormat(
438  "KDP thread 0x%llx has no register context",
439  kernel_thread_sp->GetID());
440  }
441  } break;
442 
443  case eStateRunning: {
444  lldb::RegisterContextSP reg_ctx_sp(
445  kernel_thread_sp->GetRegisterContext());
446 
447  if (reg_ctx_sp) {
448  LLDB_LOGF(log, "ProcessKDP::DoResume () reg_ctx_sp->HardwareSingleStep "
449  "(false);");
450  reg_ctx_sp->HardwareSingleStep(false);
451  resume = true;
452  } else {
453  error.SetErrorStringWithFormat(
454  "KDP thread 0x%llx has no register context",
455  kernel_thread_sp->GetID());
456  }
457  } break;
458 
459  default:
460  // The only valid thread resume states are listed above
461  llvm_unreachable("invalid thread resume state");
462  }
463  }
464 
465  if (resume) {
466  LLDB_LOGF(log, "ProcessKDP::DoResume () sending resume");
467 
468  if (m_comm.SendRequestResume()) {
471  } else
472  error.SetErrorString("KDP resume failed");
473  } else {
474  error.SetErrorString("kernel thread is suspended");
475  }
476 
477  return error;
478 }
479 
480 lldb::ThreadSP ProcessKDP::GetKernelThread() {
481  // KDP only tells us about one thread/core. Any other threads will usually
482  // be the ones that are read from memory by the OS plug-ins.
483 
484  ThreadSP thread_sp(m_kernel_thread_wp.lock());
485  if (!thread_sp) {
486  thread_sp = std::make_shared<ThreadKDP>(*this, g_kernel_tid);
487  m_kernel_thread_wp = thread_sp;
488  }
489  return thread_sp;
490 }
491 
493  ThreadList &new_thread_list) {
494  // locker will keep a mutex locked until it goes out of scope
496  LLDB_LOGV(log, "pid = {0}", GetID());
497 
498  // Even though there is a CPU mask, it doesn't mean we can see each CPU
499  // individually, there is really only one. Lets call this thread 1.
500  ThreadSP thread_sp(
501  old_thread_list.FindThreadByProtocolID(g_kernel_tid, false));
502  if (!thread_sp)
503  thread_sp = GetKernelThread();
504  new_thread_list.AddThread(thread_sp);
505 
506  return new_thread_list.GetSize(false) > 0;
507 }
508 
510  // Let all threads recover from stopping and do any clean up based on the
511  // previous thread state (if any).
513 }
514 
515 Status ProcessKDP::DoHalt(bool &caused_stop) {
516  Status error;
517 
518  if (m_comm.IsRunning()) {
519  if (m_destroy_in_process) {
520  // If we are attempting to destroy, we need to not return an error to Halt
521  // or DoDestroy won't get called. We are also currently running, so send
522  // a process stopped event
524  } else {
525  error.SetErrorString("KDP cannot interrupt a running kernel");
526  }
527  }
528  return error;
529 }
530 
531 Status ProcessKDP::DoDetach(bool keep_stopped) {
532  Status error;
534  LLDB_LOGF(log, "ProcessKDP::DoDetach(keep_stopped = %i)", keep_stopped);
535 
536  if (m_comm.IsRunning()) {
537  // We are running and we can't interrupt a running kernel, so we need to
538  // just close the connection to the kernel and hope for the best
539  } else {
540  // If we are going to keep the target stopped, then don't send the
541  // disconnect message.
542  if (!keep_stopped && m_comm.IsConnected()) {
543  const bool success = m_comm.SendRequestDisconnect();
544  if (log) {
545  if (success)
546  log->PutCString(
547  "ProcessKDP::DoDetach() detach packet sent successfully");
548  else
549  log->PutCString(
550  "ProcessKDP::DoDetach() connection channel shutdown failed");
551  }
552  m_comm.Disconnect();
553  }
554  }
555  StopAsyncThread();
556  m_comm.Clear();
557 
560 
561  // KillDebugserverProcess ();
562  return error;
563 }
564 
566  // For KDP there really is no difference between destroy and detach
567  bool keep_stopped = false;
568  return DoDetach(keep_stopped);
569 }
570 
571 // Process Queries
572 
574  return m_comm.IsConnected() && Process::IsAlive();
575 }
576 
577 // Process Memory
578 size_t ProcessKDP::DoReadMemory(addr_t addr, void *buf, size_t size,
579  Status &error) {
580  uint8_t *data_buffer = (uint8_t *)buf;
581  if (m_comm.IsConnected()) {
582  const size_t max_read_size = 512;
583  size_t total_bytes_read = 0;
584 
585  // Read the requested amount of memory in 512 byte chunks
586  while (total_bytes_read < size) {
587  size_t bytes_to_read_this_request = size - total_bytes_read;
588  if (bytes_to_read_this_request > max_read_size) {
589  bytes_to_read_this_request = max_read_size;
590  }
591  size_t bytes_read = m_comm.SendRequestReadMemory(
592  addr + total_bytes_read, data_buffer + total_bytes_read,
593  bytes_to_read_this_request, error);
594  total_bytes_read += bytes_read;
595  if (error.Fail() || bytes_read == 0) {
596  return total_bytes_read;
597  }
598  }
599 
600  return total_bytes_read;
601  }
602  error.SetErrorString("not connected");
603  return 0;
604 }
605 
606 size_t ProcessKDP::DoWriteMemory(addr_t addr, const void *buf, size_t size,
607  Status &error) {
608  if (m_comm.IsConnected())
609  return m_comm.SendRequestWriteMemory(addr, buf, size, error);
610  error.SetErrorString("not connected");
611  return 0;
612 }
613 
615  Status &error) {
616  error.SetErrorString(
617  "memory allocation not supported in kdp remote debugging");
618  return LLDB_INVALID_ADDRESS;
619 }
620 
622  Status error;
623  error.SetErrorString(
624  "memory deallocation not supported in kdp remote debugging");
625  return error;
626 }
627 
629  if (bp_site->HardwareRequired())
630  return Status("Hardware breakpoints are not supported.");
631 
633  Status error;
634  if (!bp_site->IsEnabled()) {
635  if (m_comm.SendRequestBreakpoint(true, bp_site->GetLoadAddress())) {
636  bp_site->SetEnabled(true);
637  bp_site->SetType(BreakpointSite::eExternal);
638  } else {
639  error.SetErrorString("KDP set breakpoint failed");
640  }
641  }
642  return error;
643  }
644  return EnableSoftwareBreakpoint(bp_site);
645 }
646 
649  Status error;
650  if (bp_site->IsEnabled()) {
651  BreakpointSite::Type bp_type = bp_site->GetType();
652  if (bp_type == BreakpointSite::eExternal) {
654  // We are trying to destroy our connection and we are running
655  bp_site->SetEnabled(false);
656  } else {
657  if (m_comm.SendRequestBreakpoint(false, bp_site->GetLoadAddress()))
658  bp_site->SetEnabled(false);
659  else
660  error.SetErrorString("KDP remove breakpoint failed");
661  }
662  } else {
663  error = DisableSoftwareBreakpoint(bp_site);
664  }
665  }
666  return error;
667  }
668  return DisableSoftwareBreakpoint(bp_site);
669 }
670 
672  Status error;
673  error.SetErrorString(
674  "watchpoints are not supported in kdp remote debugging");
675  return error;
676 }
677 
679  Status error;
680  error.SetErrorString(
681  "watchpoints are not supported in kdp remote debugging");
682  return error;
683 }
684 
686 
688  Status error;
689  error.SetErrorString(
690  "sending signals is not supported in kdp remote debugging");
691  return error;
692 }
693 
695  static llvm::once_flag g_once_flag;
696 
697  llvm::call_once(g_once_flag, []() {
698  PluginManager::RegisterPlugin(GetPluginNameStatic(),
701 
702  ProcessKDPLog::Initialize();
703  });
704 }
705 
707  if (!PluginManager::GetSettingForProcessPlugin(
708  debugger, PluginProperties::GetSettingName())) {
709  const bool is_global_setting = true;
710  PluginManager::CreateSettingForProcessPlugin(
711  debugger, GetGlobalPluginProperties().GetValueProperties(),
712  ConstString("Properties for the kdp-remote process plug-in."),
713  is_global_setting);
714  }
715 }
716 
719 
720  LLDB_LOGF(log, "ProcessKDP::StartAsyncThread ()");
721 
723  return true;
724 
725  llvm::Expected<HostThread> async_thread = ThreadLauncher::LaunchThread(
726  "<lldb.process.kdp-remote.async>", ProcessKDP::AsyncThread, this);
727  if (!async_thread) {
729  "failed to launch host thread: {}",
730  llvm::toString(async_thread.takeError()));
731  return false;
732  }
733  m_async_thread = *async_thread;
734  return m_async_thread.IsJoinable();
735 }
736 
739 
740  LLDB_LOGF(log, "ProcessKDP::StopAsyncThread ()");
741 
743 
744  // Stop the stdio thread
746  m_async_thread.Join(nullptr);
747 }
748 
749 void *ProcessKDP::AsyncThread(void *arg) {
750  ProcessKDP *process = (ProcessKDP *)arg;
751 
752  const lldb::pid_t pid = process->GetID();
753 
755  LLDB_LOGF(log,
756  "ProcessKDP::AsyncThread (arg = %p, pid = %" PRIu64
757  ") thread starting...",
758  arg, pid);
759 
760  ListenerSP listener_sp(Listener::MakeListener("ProcessKDP::AsyncThread"));
761  EventSP event_sp;
762  const uint32_t desired_event_mask =
764 
765  if (listener_sp->StartListeningForEvents(&process->m_async_broadcaster,
766  desired_event_mask) ==
767  desired_event_mask) {
768  bool done = false;
769  while (!done) {
770  LLDB_LOGF(log,
771  "ProcessKDP::AsyncThread (pid = %" PRIu64
772  ") listener.WaitForEvent (NULL, event_sp)...",
773  pid);
774  if (listener_sp->GetEvent(event_sp, llvm::None)) {
775  uint32_t event_type = event_sp->GetType();
776  LLDB_LOGF(log,
777  "ProcessKDP::AsyncThread (pid = %" PRIu64
778  ") Got an event of type: %d...",
779  pid, event_type);
780 
781  // When we are running, poll for 1 second to try and get an exception
782  // to indicate the process has stopped. If we don't get one, check to
783  // make sure no one asked us to exit
784  bool is_running = false;
785  DataExtractor exc_reply_packet;
786  do {
787  switch (event_type) {
789  is_running = true;
791  exc_reply_packet, 1 * USEC_PER_SEC)) {
792  ThreadSP thread_sp(process->GetKernelThread());
793  if (thread_sp) {
794  lldb::RegisterContextSP reg_ctx_sp(
795  thread_sp->GetRegisterContext());
796  if (reg_ctx_sp)
797  reg_ctx_sp->InvalidateAllRegisters();
798  static_cast<ThreadKDP *>(thread_sp.get())
799  ->SetStopInfoFrom_KDP_EXCEPTION(exc_reply_packet);
800  }
801 
802  // TODO: parse the stop reply packet
803  is_running = false;
804  process->SetPrivateState(eStateStopped);
805  } else {
806  // Check to see if we are supposed to exit. There is no way to
807  // interrupt a running kernel, so all we can do is wait for an
808  // exception or detach...
809  if (listener_sp->GetEvent(event_sp,
810  std::chrono::microseconds(0))) {
811  // We got an event, go through the loop again
812  event_type = event_sp->GetType();
813  }
814  }
815  } break;
816 
818  LLDB_LOGF(log,
819  "ProcessKDP::AsyncThread (pid = %" PRIu64
820  ") got eBroadcastBitAsyncThreadShouldExit...",
821  pid);
822  done = true;
823  is_running = false;
824  break;
825 
826  default:
827  LLDB_LOGF(log,
828  "ProcessKDP::AsyncThread (pid = %" PRIu64
829  ") got unknown event 0x%8.8x",
830  pid, event_type);
831  done = true;
832  is_running = false;
833  break;
834  }
835  } while (is_running);
836  } else {
837  LLDB_LOGF(log,
838  "ProcessKDP::AsyncThread (pid = %" PRIu64
839  ") listener.WaitForEvent (NULL, event_sp) => false",
840  pid);
841  done = true;
842  }
843  }
844  }
845 
846  LLDB_LOGF(log,
847  "ProcessKDP::AsyncThread (arg = %p, pid = %" PRIu64
848  ") thread exiting...",
849  arg, pid);
850 
851  process->m_async_thread.Reset();
852  return NULL;
853 }
854 
856 private:
860 
861  Options *GetOptions() override { return &m_option_group; }
862 
863 public:
865  : CommandObjectParsed(interpreter, "process plugin packet send",
866  "Send a custom packet through the KDP protocol by "
867  "specifying the command byte and the packet "
868  "payload data. A packet will be sent with a "
869  "correct header and payload, and the raw result "
870  "bytes will be displayed as a string value. ",
871  NULL),
872  m_option_group(),
873  m_command_byte(LLDB_OPT_SET_1, true, "command", 'c', 0, eArgTypeNone,
874  "Specify the command byte to use when sending the KDP "
875  "request packet.",
876  0),
877  m_packet_data(LLDB_OPT_SET_1, false, "payload", 'p', 0, eArgTypeNone,
878  "Specify packet payload bytes as a hex ASCII string with "
879  "no spaces or hex prefixes.",
880  NULL) {
884  }
885 
887 
888  bool DoExecute(Args &command, CommandReturnObject &result) override {
889  const size_t argc = command.GetArgumentCount();
890  if (argc == 0) {
892  result.AppendError(
893  "the --command option must be set to a valid command byte");
894  } else {
895  const uint64_t command_byte =
897  if (command_byte > 0 && command_byte <= UINT8_MAX) {
898  ProcessKDP *process =
900  if (process) {
901  const StateType state = process->GetState();
902 
903  if (StateIsStoppedState(state, true)) {
904  std::vector<uint8_t> payload_bytes;
905  const char *ascii_hex_bytes_cstr =
907  if (ascii_hex_bytes_cstr && ascii_hex_bytes_cstr[0]) {
908  StringExtractor extractor(ascii_hex_bytes_cstr);
909  const size_t ascii_hex_bytes_cstr_len =
910  extractor.GetStringRef().size();
911  if (ascii_hex_bytes_cstr_len & 1) {
912  result.AppendErrorWithFormat("payload data must contain an "
913  "even number of ASCII hex "
914  "characters: '%s'",
915  ascii_hex_bytes_cstr);
916  return false;
917  }
918  payload_bytes.resize(ascii_hex_bytes_cstr_len / 2);
919  if (extractor.GetHexBytes(payload_bytes, '\xdd') !=
920  payload_bytes.size()) {
921  result.AppendErrorWithFormat("payload data must only contain "
922  "ASCII hex characters (no "
923  "spaces or hex prefixes): '%s'",
924  ascii_hex_bytes_cstr);
925  return false;
926  }
927  }
928  Status error;
929  DataExtractor reply;
930  process->GetCommunication().SendRawRequest(
931  command_byte,
932  payload_bytes.empty() ? NULL : payload_bytes.data(),
933  payload_bytes.size(), reply, error);
934 
935  if (error.Success()) {
936  // Copy the binary bytes into a hex ASCII string for the result
937  StreamString packet;
938  packet.PutBytesAsRawHex8(
939  reply.GetDataStart(), reply.GetByteSize(),
941  result.AppendMessage(packet.GetString());
943  return true;
944  } else {
945  const char *error_cstr = error.AsCString();
946  if (error_cstr && error_cstr[0])
947  result.AppendError(error_cstr);
948  else
949  result.AppendErrorWithFormat("unknown error 0x%8.8x",
950  error.GetError());
951  return false;
952  }
953  } else {
954  result.AppendErrorWithFormat("process must be stopped in order "
955  "to send KDP packets, state is %s",
956  StateAsCString(state));
957  }
958  } else {
959  result.AppendError("invalid process");
960  }
961  } else {
962  result.AppendErrorWithFormat("invalid command byte 0x%" PRIx64
963  ", valid values are 1 - 255",
964  command_byte);
965  }
966  }
967  } else {
968  result.AppendErrorWithFormat("'%s' takes no arguments, only options.",
969  m_cmd_name.c_str());
970  }
971  return false;
972  }
973 };
974 
976 private:
977 public:
979  : CommandObjectMultiword(interpreter, "process plugin packet",
980  "Commands that deal with KDP remote packets.",
981  NULL) {
983  "send",
984  CommandObjectSP(new CommandObjectProcessKDPPacketSend(interpreter)));
985  }
986 
987  ~CommandObjectProcessKDPPacket() = default;
988 };
989 
991 public:
994  interpreter, "process plugin",
995  "Commands for operating on a ProcessKDP process.",
996  "process plugin <subcommand> [<subcommand-options>]") {
997  LoadSubCommand("packet", CommandObjectSP(new CommandObjectProcessKDPPacket(
998  interpreter)));
999  }
1000 
1002 };
1003 
1005  if (!m_command_sp)
1006  m_command_sp = std::make_shared<CommandObjectMultiwordProcessKDP>(
1007  GetTarget().GetDebugger().GetCommandInterpreter());
1008  return m_command_sp.get();
1009 }
lldb_private::toString
const char * toString(AppleArm64ExceptionClass EC)
Definition: AppleArm64ExceptionClass.h:38
ProcessKDP::CanDebug
bool CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override
Check if a plug-in instance can debug the file in module.
Definition: ProcessKDP.cpp:113
ProcessKDP::m_comm
CommunicationKDP m_comm
Broadcaster event bits definitions.
Definition: ProcessKDP.h:170
lldb_private::CommandObjectParsed
Definition: CommandObject.h:394
lldb_private::UUID
Definition: UUID.h:23
lldb_private::StoppointSite::GetLoadAddress
virtual lldb::addr_t GetLoadAddress() const
Definition: StoppointSite.h:27
lldb_private::Module::GetObjectFile
virtual ObjectFile * GetObjectFile()
Get the object file representation for the current architecture.
Definition: Module.cpp:1237
lldb_private::Properties::GetValueProperties
virtual lldb::OptionValuePropertiesSP GetValueProperties() const
Definition: UserSettingsController.h:42
lldb_private::ArchSpec
Definition: ArchSpec.h:33
CommandObjectProcessKDPPacketSend
Definition: ProcessKDP.cpp:855
CommandObjectMultiwordProcessKDP::~CommandObjectMultiwordProcessKDP
~CommandObjectMultiwordProcessKDP()=default
lldb_private::BreakpointSite::Type
Type
Definition: BreakpointSite.h:38
lldb_private::Process::m_thread_list
ThreadList m_thread_list
The threads for this process as the user will see them.
Definition: Process.h:2864
lldb_private::OptionValue::OptionWasSet
bool OptionWasSet() const
Definition: OptionValue.h:303
lldb_private::OptionGroupUInt64::GetOptionValue
OptionValueUInt64 & GetOptionValue()
Definition: OptionGroupUInt64.h:37
KDP_LOG_PROCESS
#define KDP_LOG_PROCESS
Definition: ProcessKDPLog.h:14
CommunicationKDP::GetCPUSubtype
uint32_t GetCPUSubtype()
Definition: CommunicationKDP.cpp:428
LLDB_INVALID_PROCESS_ID
#define LLDB_INVALID_PROCESS_ID
Definition: lldb-defines.h:93
ModuleSpec.h
CommandObjectProcessKDPPacketSend::m_option_group
OptionGroupOptions m_option_group
Definition: ProcessKDP.cpp:857
lldb_private::ExecutionContext::GetProcessPtr
Process * GetProcessPtr() const
Returns a pointer to the process object.
Definition: ExecutionContext.cpp:208
UUID.h
Host.h
StringExtractor::GetStringRef
llvm::StringRef GetStringRef() const
Definition: StringExtractor.h:48
ProcessKDP::DidAttach
void DidAttach(lldb_private::ArchSpec &process_arch) override
Called after attaching a process.
Definition: ProcessKDP.cpp:381
ProcessKDP::GetImageInfoAddress
lldb::addr_t GetImageInfoAddress() override
Get the image information address for the current process.
Definition: ProcessKDP.cpp:391
CommandObjectProcessKDPPacketSend::DoExecute
bool DoExecute(Args &command, CommandReturnObject &result) override
Definition: ProcessKDP.cpp:888
ProcessKDP::DoResume
lldb_private::Status DoResume() override
Resumes all of a process's threads as configured using the Thread run control functions.
Definition: ProcessKDP.cpp:401
ProcessKDP
Definition: ProcessKDP.h:30
CommunicationKDP::LocalBreakpointsAreSupported
bool LocalBreakpointsAreSupported()
Definition: CommunicationKDP.h:149
ProcessKDP::WillResume
lldb_private::Status WillResume() override
Called before resuming to a process.
Definition: ProcessKDP.cpp:399
lldb_private::Process::EnableSoftwareBreakpoint
virtual Status EnableSoftwareBreakpoint(BreakpointSite *bp_site)
Definition: Process.cpp:1755
USEC_PER_SEC
#define USEC_PER_SEC
Definition: ProcessKDP.cpp:42
lldb_private::UUID::IsValid
bool IsValid() const
Definition: UUID.h:79
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
CommunicationKDP::RemoteIsDarwinKernel
bool RemoteIsDarwinKernel()
Definition: CommunicationKDP.cpp:461
ProcessKDP::GetPluginCommandObject
lldb_private::CommandObject * GetPluginCommandObject() override
Return a multi-word command object that can be used to expose plug-in specific commands.
Definition: ProcessKDP.cpp:1004
lldb_private::Process
Definition: Process.h:341
lldb_private::ArchSpec::MergeFrom
void MergeFrom(const ArchSpec &other)
Merges fields from another ArchSpec into this ArchSpec.
Definition: ArchSpec.cpp:801
lldb_private::Target::GetExecutableModule
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Definition: Target.cpp:1345
lldb_private::Broadcaster::SetEventName
void SetEventName(uint32_t event_mask, const char *name)
Set the name for an event bit.
Definition: Broadcaster.h:337
lldb_private::OptionGroupOptions
Definition: Options.h:255
ProcessKDP.h
Module.h
ProcessKDP::m_async_broadcaster
lldb_private::Broadcaster m_async_broadcaster
Definition: ProcessKDP.h:171
lldb_private::Process::GetThreadList
ThreadList & GetThreadList()
Definition: Process.h:2078
lldb_private::Process::GetTarget
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1209
lldb_private::StateAsCString
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition: State.cpp:14
ThreadKDP.h
ProcessKDP::DoAttachToProcessWithID
lldb_private::Status DoAttachToProcessWithID(lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info) override
Attach to an existing process using a process ID.
Definition: ProcessKDP.cpp:364
lldb_private::BreakpointSite::GetType
BreakpointSite::Type GetType() const
Definition: BreakpointSite.h:192
ProcessKDP::DisableBreakpointSite
lldb_private::Status DisableBreakpointSite(lldb_private::BreakpointSite *bp_site) override
Definition: ProcessKDP.cpp:647
lldb_private::ThreadList::RefreshStateAfterStop
void RefreshStateAfterStop()
Definition: ThreadList.cpp:458
ProcessKDP::DoDestroy
lldb_private::Status DoDestroy() override
Definition: ProcessKDP.cpp:565
lldb_private::Module
Definition: Module.h:85
LocateSymbolFile.h
lldb_private::OptionValue::GetUInt64Value
uint64_t GetUInt64Value(uint64_t fail_value, bool *success_ptr)
Definition: OptionValue.cpp:20
DynamicLoaderStatic.h
CommandObjectProcessKDPPacketSend::GetOptions
Options * GetOptions() override
Definition: ProcessKDP.cpp:861
ProcessKDP::~ProcessKDP
~ProcessKDP() override
Definition: ProcessKDP.cpp:161
lldb_private::Process::SetID
void SetID(lldb::pid_t new_pid)
Sets the stored pid.
Definition: Process.h:546
lldb_private::Args
Definition: Args.h:33
lldb_private::ArchSpec::GetTriple
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:444
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
CommunicationKDP::RemoteIsEFI
bool RemoteIsEFI()
Definition: CommunicationKDP.cpp:455
CommunicationKDP::GetUUID
lldb_private::UUID GetUUID()
Definition: CommunicationKDP.cpp:434
lldb_private::Process::SetPrivateState
void SetPrivateState(lldb::StateType state)
Definition: Process.cpp:1415
StringExtractor
Definition: StringExtractor.h:19
lldb_private::Target::GetDebugger
Debugger & GetDebugger()
Definition: Target.h:1000
CommandReturnObject.h
ThreadLauncher.h
Debugger.h
lldb_private::Target
Definition: Target.h:451
LLDB_LOGV
#define LLDB_LOGV(log,...)
Definition: Log.h:256
LLDB_PLUGIN_DEFINE_ADV
LLDB_PLUGIN_DEFINE_ADV(ObjectContainerUniversalMachO, ObjectContainerMachOArchive) void ObjectContainerUniversalMachO
Definition: ObjectContainerUniversalMachO.cpp:23
lldb_private::StreamString::GetString
llvm::StringRef GetString() const
Definition: StreamString.cpp:51
lldb_private::ModuleSpec::GetSymbolFileSpec
FileSpec & GetSymbolFileSpec()
Definition: ModuleSpec.h:82
lldb_private::Process::GetState
lldb::StateType GetState()
Get accessor for the current process state.
Definition: Process.cpp:1294
ProcessKDP::DoUpdateThreadList
bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list, lldb_private::ThreadList &new_thread_list) override
Update the thread list following process plug-in's specific logic.
Definition: ProcessKDP.cpp:492
lldb_private::eArchTypeMachO
@ eArchTypeMachO
Definition: lldb-private-enumerations.h:63
ProcessKDP::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: ProcessKDP.h:44
CommunicationKDP::SendRequestReadMemory
uint32_t SendRequestReadMemory(lldb::addr_t addr, void *dst, uint32_t dst_size, lldb_private::Status &error)
Definition: CommunicationKDP.cpp:546
lldb::eStateStopped
@ eStateStopped
Process or thread is stopped and can be examined.
Definition: lldb-enumerations.h:84
Target.h
lldb_private::Communication::SetConnection
void SetConnection(std::unique_ptr< Connection > connection)
Sets the connection that it to be used by this class.
Definition: Communication.cpp:423
lldb_private::ModuleSpec::GetUUID
UUID & GetUUID()
Definition: ModuleSpec.h:104
lldb_private::Properties
Definition: UserSettingsController.h:33
CommunicationKDP::SendRequestResume
bool SendRequestResume()
Definition: CommunicationKDP.cpp:1238
CommandObjectMultiwordProcessKDP
Definition: ProcessKDP.cpp:990
LIBLLDB_LOG_HOST
#define LIBLLDB_LOG_HOST
Definition: Logging.h:28
CommunicationKDP::GetVersion
uint32_t GetVersion()
Definition: CommunicationKDP.cpp:388
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::ThreadList::Clear
void Clear()
Definition: ThreadList.cpp:443
lldb_private::CommandObjectMultiword
Definition: CommandObjectMultiword.h:19
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
CommandObjectProcessKDPPacketSend::m_packet_data
OptionGroupString m_packet_data
Definition: ProcessKDP.cpp:859
ProcessKDP::GetHostArchitecture
bool GetHostArchitecture(lldb_private::ArchSpec &arch)
Definition: ProcessKDP.cpp:191
lldb_private::Options
Definition: Options.h:57
lldb_private::BreakpointSite
Definition: BreakpointSite.h:35
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::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
lldb_private::DataExtractor
Definition: DataExtractor.h:48
Log.h
CommandObjectMultiwordProcessKDP::CommandObjectMultiwordProcessKDP
CommandObjectMultiwordProcessKDP(CommandInterpreter &interpreter)
Definition: ProcessKDP.cpp:992
lldb_private::eLoadDependentsNo
@ eLoadDependentsNo
Definition: Target.h:64
lldb_private::Process::DisableSoftwareBreakpoint
virtual Status DisableSoftwareBreakpoint(BreakpointSite *bp_site)
Definition: Process.cpp:1831
lldb_private::CommandObjectMultiword::LoadSubCommand
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
Definition: CommandObjectMultiword.cpp:80
LLDB_OPT_SET_1
#define LLDB_OPT_SET_1
Definition: lldb-defines.h:113
lldb_private::CommandReturnObject::SetStatus
void SetStatus(lldb::ReturnStatus status)
Definition: CommandReturnObject.cpp:121
lldb_private::Watchpoint
Definition: Watchpoint.h:24
CommunicationKDP::SendRequestDisconnect
bool SendRequestDisconnect()
Definition: CommunicationKDP.cpp:532
lldb_private::Debugger::GetAsyncOutputStream
lldb::StreamSP GetAsyncOutputStream()
Definition: Debugger.cpp:1150
lldb_private::StoppointSite::HardwareRequired
bool HardwareRequired() const
Definition: StoppointSite.h:37
lldb_private::Process::m_dyld_up
lldb::DynamicLoaderUP m_dyld_up
Definition: Process.h:2888
lldb_private::BreakpointSite::SetEnabled
void SetEnabled(bool enabled)
Sets whether the current breakpoint site is enabled or not.
Definition: BreakpointSite.cpp:123
lldb_private::Communication::Clear
void Clear()
Definition: Communication.cpp:72
OptionGroupUInt64.h
ProcessKDP::DoReadMemory
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Status &error) override
Actually do the reading of memory from a process.
Definition: ProcessKDP.cpp:578
lldb_private::Process::Finalize
virtual void Finalize()
This object is about to be destroyed, do any necessary cleanup.
Definition: Process.cpp:510
ProcessKDP::m_kernel_load_addr
lldb::addr_t m_kernel_load_addr
Definition: ProcessKDP.h:174
LLDB_OPT_SET_ALL
#define LLDB_OPT_SET_ALL
Definition: lldb-defines.h:112
lldb_private::DataExtractor::GetDataStart
const uint8_t * GetDataStart() const
Get the data start pointer.
Definition: DataExtractor.h:422
lldb_private::ThreadList
Definition: ThreadList.h:26
lldb_private::ConstString
Definition: ConstString.h:40
DynamicLoaderDarwinKernel.h
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::Process::UpdateThreadListIfNeeded
void UpdateThreadListIfNeeded()
Definition: Process.cpp:1138
ProcessKDPLog.h
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
lldb_private::OptionGroupOptions::Finalize
void Finalize()
Definition: Options.cpp:839
CommandObjectProcessKDPPacket
Definition: ProcessKDP.cpp:975
ProcessKDP::Terminate
static void Terminate()
Definition: ProcessKDP.cpp:99
lldb_private::CommandInterpreter
Definition: CommandInterpreter.h:214
lldb_private::DynamicLoader
Definition: DynamicLoader.h:52
lldb::eStateDetached
@ eStateDetached
Process has been detached and can't be examined.
Definition: lldb-enumerations.h:89
CommandObjectMultiword.h
ConnectionFileDescriptor.h
ProcessKDP::m_async_thread
lldb_private::HostThread m_async_thread
Definition: ProcessKDP.h:172
lldb_private::HostThread::Reset
void Reset()
Definition: HostThread.cpp:26
lldb_private::Target::SetArchitecture
bool SetArchitecture(const ArchSpec &arch_spec, bool set_platform=false)
Set the architecture for this target.
Definition: Target.cpp:1460
lldb_private::Debugger
Definition: Debugger.h:70
ProcessKDP::WillLaunch
lldb_private::Status WillLaunch(lldb_private::Module *module) override
Called before launching to a process.
Definition: ProcessKDP.cpp:170
lldb_private::CommandObject::m_interpreter
CommandInterpreter & m_interpreter
Definition: CommandObject.h:373
lldb_private::ThreadList::FindThreadByProtocolID
lldb::ThreadSP FindThreadByProtocolID(lldb::tid_t tid, bool can_update=true)
Definition: ThreadList.cpp:120
lldb_private::OptionValueString::GetCurrentValue
const char * GetCurrentValue() const
Definition: OptionValueString.h:92
Thread.h
CommandObjectProcessKDPPacket::CommandObjectProcessKDPPacket
CommandObjectProcessKDPPacket(CommandInterpreter &interpreter)
Definition: ProcessKDP.cpp:978
g_kernel_tid
static const lldb::tid_t g_kernel_tid
Definition: ProcessKDP.cpp:92
lldb_private::OptionGroupString
Definition: OptionGroupString.h:18
lldb_private::OptionGroupUInt64
Definition: OptionGroupUInt64.h:19
ThreadKDP
Definition: ThreadKDP.h:19
ProcessKDP::DoLaunch
lldb_private::Status DoLaunch(lldb_private::Module *exe_module, lldb_private::ProcessLaunchInfo &launch_info) override
Launch a new process.
Definition: ProcessKDP.cpp:356
ProcessKDP::DebuggerInitialize
static void DebuggerInitialize(lldb_private::Debugger &debugger)
Definition: ProcessKDP.cpp:706
OptionValueProperties.h
lldb_private::Process::ResumePrivateStateThread
void ResumePrivateStateThread()
Definition: Process.cpp:3520
ProcessKDP::DoDeallocateMemory
lldb_private::Status DoDeallocateMemory(lldb::addr_t ptr) override
Actually deallocate memory in the process.
Definition: ProcessKDP.cpp:621
lldb_private::ProcessAttachInfo
Definition: Process.h:113
ObjectFile.h
CommandObjectProcessKDPPacketSend::~CommandObjectProcessKDPPacketSend
~CommandObjectProcessKDPPacketSend()=default
OptionGroupString.h
lldb_private::Target::SetExecutableModule
void SetExecutableModule(lldb::ModuleSP &module_sp, LoadDependentFiles load_dependent_files=eLoadDependentsDefault)
Set the main executable module.
Definition: Target.cpp:1394
CommunicationKDP::SendRawRequest
bool SendRawRequest(uint8_t command_byte, const void *src, uint32_t src_len, lldb_private::DataExtractor &reply, lldb_private::Status &error)
Definition: CommunicationKDP.cpp:617
lldb_private::CommandObject
Definition: CommandObject.h:67
ProcessKDP::DoAllocateMemory
lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions, lldb_private::Status &error) override
Actually allocate memory in the process.
Definition: ProcessKDP.cpp:614
CommunicationKDP::SendRequestBreakpoint
bool SendRequestBreakpoint(bool set, lldb::addr_t addr)
Definition: CommunicationKDP.cpp:1250
CommandObjectProcessKDPPacketSend::CommandObjectProcessKDPPacketSend
CommandObjectProcessKDPPacketSend(CommandInterpreter &interpreter)
Definition: ProcessKDP.cpp:864
CommunicationKDP::GetCPUType
uint32_t GetCPUType()
Definition: CommunicationKDP.cpp:422
lldb::eStateStepping
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
Definition: lldb-enumerations.h:86
ProcessKDP::eBroadcastBitAsyncContinue
@ eBroadcastBitAsyncContinue
Definition: ProcessKDP.h:163
lldb_private::ArchSpec::SetArchitecture
bool SetArchitecture(ArchitectureType arch_type, uint32_t cpu, uint32_t sub, uint32_t os=0)
Change the architecture object type, CPU type and OS type.
Definition: ArchSpec.cpp:843
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::Broadcaster::BroadcastEvent
void BroadcastEvent(lldb::EventSP &event_sp)
Broadcast an event which has no associated data.
Definition: Broadcaster.h:262
lldb_private::ModuleSpec::GetFileSpec
FileSpec & GetFileSpec()
Definition: ModuleSpec.h:58
lldb_private::Communication::Disconnect
lldb::ConnectionStatus Disconnect(Status *error_ptr=nullptr)
Disconnect the communications connection if one is currently connected.
Definition: Communication.cpp:92
lldb_private::ModuleSpec
Definition: ModuleSpec.h:26
lldb_private::Target::GetArchitecture
const ArchSpec & GetArchitecture() const
Definition: Target.h:967
lldb_private::HostThread::Join
Status Join(lldb::thread_result_t *result)
Definition: HostThread.cpp:20
lldb_private::Stream::PutBytesAsRawHex8
size_t PutBytesAsRawHex8(const void *src, size_t src_len, lldb::ByteOrder src_byte_order=lldb::eByteOrderInvalid, lldb::ByteOrder dst_byte_order=lldb::eByteOrderInvalid)
Definition: Stream.cpp:356
lldb_private::Status
Definition: Status.h:44
ProcessKDP::DoAttachToProcessWithName
lldb_private::Status DoAttachToProcessWithName(const char *process_name, const lldb_private::ProcessAttachInfo &attach_info) override
Attach to an existing process using a partial process name.
Definition: ProcessKDP.cpp:373
ProcessKDP::DoHalt
lldb_private::Status DoHalt(bool &caused_stop) override
Halts a running process.
Definition: ProcessKDP.cpp:515
lldb_private::CommandReturnObject
Definition: CommandReturnObject.h:25
CommunicationKDP::SendRequestConnect
bool SendRequestConnect(uint16_t reply_port, uint16_t exc_port, const char *greeting)
Definition: CommunicationKDP.cpp:334
ProcessKDP::GetDynamicLoader
lldb_private::DynamicLoader * GetDynamicLoader() override
Get the dynamic loader plug-in for this process.
Definition: ProcessKDP.cpp:393
uint32_t
CommandObjectProcessKDPPacketSend::m_command_byte
OptionGroupUInt64 m_command_byte
Definition: ProcessKDP.cpp:858
ProcessKDP::DoDetach
lldb_private::Status DoDetach(bool keep_stopped) override
Detaches from a running or stopped process.
Definition: ProcessKDP.cpp:531
lldb_private::CommandObject::m_cmd_name
std::string m_cmd_name
Definition: CommandObject.h:376
CommandObject.h
lldb::eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishResult
Definition: lldb-enumerations.h:261
ProcessKDP::m_kernel_thread_wp
lldb::ThreadWP m_kernel_thread_wp
Definition: ProcessKDP.h:176
ProcessKDP::RefreshStateAfterStop
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
Definition: ProcessKDP.cpp:509
ProcessKDP::CreateInstance
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const lldb_private::FileSpec *crash_file_path, bool can_connect)
Definition: ProcessKDP.cpp:103
lldb::eArgTypeNone
@ eArgTypeNone
Definition: lldb-enumerations.h:595
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb_private::ObjectFile::GetStrata
Strata GetStrata()
Definition: ObjectFile.h:636
lldb_private::endian::InlHostByteOrder
lldb::ByteOrder InlHostByteOrder()
Definition: Endian.h:25
StringExtractor.h
ProcessKDP::DoConnectRemote
lldb_private::Status DoConnectRemote(llvm::StringRef remote_url) override
Attach to a remote system via a URL.
Definition: ProcessKDP.cpp:205
ProcessKDP::DisableWatchpoint
lldb_private::Status DisableWatchpoint(lldb_private::Watchpoint *wp, bool notify=true) override
Definition: ProcessKDP.cpp:678
ProcessKDP::GetKernelThread
lldb::ThreadSP GetKernelThread()
Definition: ProcessKDP.cpp:480
lldb_private::ThreadList::GetSize
uint32_t GetSize(bool can_update=true)
Definition: ThreadList.cpp:82
CommunicationKDP::IsRunning
bool IsRunning() const
Definition: CommunicationKDP.h:95
ProcessKDP::Clear
void Clear()
Definition: ProcessKDP.cpp:685
ProcessKDP::IsAlive
bool IsAlive() override
Check if a process is still alive.
Definition: ProcessKDP.cpp:573
lldb_private::Communication::IsConnected
bool IsConnected() const
Check if the connection is valid.
Definition: Communication.cpp:116
lldb_private::BreakpointSite::IsEnabled
bool IsEnabled() const
Tells whether the current breakpoint site is enabled or not.
Definition: BreakpointSite.cpp:121
uint16_t
DynamicLoaderDarwinKernel::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: DynamicLoaderDarwinKernel.h:36
PluginManager.h
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
lldb_private::ModuleSpec::GetArchitecture
ArchSpec & GetArchitecture()
Definition: ModuleSpec.h:94
TCPSocket.h
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:242
lldb_private::Process::GetID
lldb::pid_t GetID() const
Returns the pid of the process or LLDB_INVALID_PROCESS_ID if there is no known pid.
Definition: Process.h:541
ProcessKDP::ProcessKDP
ProcessKDP(lldb::TargetSP target_sp, lldb::ListenerSP listener)
KDP_LOG_THREAD
#define KDP_LOG_THREAD
Definition: ProcessKDPLog.h:15
ProcessKDP::EnableWatchpoint
lldb_private::Status EnableWatchpoint(lldb_private::Watchpoint *wp, bool notify=true) override
Definition: ProcessKDP.cpp:671
ProcessKDP::WillAttachToProcessWithID
lldb_private::Status WillAttachToProcessWithID(lldb::pid_t pid) override
Called before attaching to a process.
Definition: ProcessKDP.cpp:176
lldb_private::CommandReturnObject::AppendErrorWithFormat
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
Definition: CommandReturnObject.cpp:46
ProcessKDP::Initialize
static void Initialize()
Definition: ProcessKDP.cpp:694
lldb::eConnectionStatusSuccess
@ eConnectionStatusSuccess
Success.
Definition: lldb-enumerations.h:296
ProcessKDP::m_dyld_plugin_name
llvm::StringRef m_dyld_plugin_name
Definition: ProcessKDP.h:173
StringExtractor::GetHexBytes
size_t GetHexBytes(llvm::MutableArrayRef< uint8_t > dest, uint8_t fail_fill_value)
Definition: StringExtractor.cpp:266
ProcessKDP::WillAttachToProcessWithName
lldb_private::Status WillAttachToProcessWithName(const char *process_name, bool wait_for_launch) override
Called before attaching to a process.
Definition: ProcessKDP.cpp:183
lldb_private::OptionGroupOptions::Append
void Append(OptionGroup *group)
Append options from a OptionGroup class.
Definition: Options.cpp:810
lldb_private::TCPSocket
Definition: TCPSocket.h:17
lldb_private::HostThread::IsJoinable
bool IsJoinable() const
Definition: HostThread.cpp:30
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::Process::m_destroy_in_process
bool m_destroy_in_process
Definition: Process.h:2945
ProcessKDP::EnableBreakpointSite
lldb_private::Status EnableBreakpointSite(lldb_private::BreakpointSite *bp_site) override
Definition: ProcessKDP.cpp:628
CommunicationKDP::WaitForPacketWithTimeoutMicroSeconds
size_t WaitForPacketWithTimeoutMicroSeconds(lldb_private::DataExtractor &response, uint32_t usec)
Definition: CommunicationKDP.cpp:170
ProcessKDP::DoSignal
lldb_private::Status DoSignal(int signal) override
Sends a process a UNIX signal signal.
Definition: ProcessKDP.cpp:687
CommandInterpreter.h
lldb_private::CommandInterpreter::GetExecutionContext
ExecutionContext GetExecutionContext() const
CommunicationKDP::SetPacketTimeout
std::chrono::seconds SetPacketTimeout(std::chrono::seconds packet_timeout)
Definition: CommunicationKDP.h:103
State.h
lldb_private::ThreadCollection::AddThread
void AddThread(const lldb::ThreadSP &thread_sp)
Definition: ThreadCollection.cpp:24
CommandObjectProcessKDPPacket::~CommandObjectProcessKDPPacket
~CommandObjectProcessKDPPacket()=default
lldb::StateType
StateType
Process and Thread States.
Definition: lldb-enumerations.h:73
lldb_private::Log
Definition: Log.h:49
CommunicationKDP::SendRequestReattach
bool SendRequestReattach(uint16_t reply_port)
Definition: CommunicationKDP.cpp:366
lldb_private::Module::GetArchitecture
const ArchSpec & GetArchitecture() const
Get const accessor for the module architecture.
Definition: Module.cpp:1065
lldb_private::Process::SetCanJIT
void SetCanJIT(bool can_jit)
Sets whether executing JIT-compiled code in this process is possible.
Definition: Process.cpp:2319
ProcessKDP::StartAsyncThread
bool StartAsyncThread()
Definition: ProcessKDP.cpp:717
CommunicationKDP::SendRequestWriteMemory
uint32_t SendRequestWriteMemory(lldb::addr_t addr, const void *src, uint32_t src_len, lldb_private::Status &error)
Definition: CommunicationKDP.cpp:584
lldb_private::ArchSpec::Clear
void Clear()
Clears the object state.
Definition: ArchSpec.cpp:527
lldb_private::BreakpointSite::SetType
void SetType(BreakpointSite::Type type)
Definition: BreakpointSite.h:194
lldb_private::CommandReturnObject::AppendError
void void AppendError(llvm::StringRef in_string)
Definition: CommandReturnObject.cpp:100
lldb_private::TCPSocket::GetLocalPortNumber
uint16_t GetLocalPortNumber() const
Definition: TCPSocket.cpp:80
CommunicationKDP::GetKernelVersion
const char * GetKernelVersion()
Definition: CommunicationKDP.cpp:510
lldb_private::DataExtractor::GetByteSize
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
Definition: DataExtractor.h:270
lldb_private::Args::GetArgumentCount
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
Definition: Args.h:118
lldb_private::ConnectionFileDescriptor
Definition: ConnectionFileDescriptorPosix.h:29
lldb
Definition: SBAddress.h:15
ProcessKDP::eBroadcastBitAsyncThreadShouldExit
@ eBroadcastBitAsyncThreadShouldExit
Definition: ProcessKDP.h:164
ProcessKDP::GetPluginDescriptionStatic
static llvm::StringRef GetPluginDescriptionStatic()
Definition: ProcessKDP.cpp:94
lldb::eStateRunning
@ eStateRunning
Process or thread is running and can't be examined.
Definition: lldb-enumerations.h:85
CommunicationKDP::GetLoadAddress
lldb::addr_t GetLoadAddress()
Definition: CommunicationKDP.cpp:467
RegisterContext.h
ProcessKDP::AsyncThread
static void * AsyncThread(void *arg)
Definition: ProcessKDP.cpp:749
ProcessKDP::DoWriteMemory
size_t DoWriteMemory(lldb::addr_t addr, const void *buf, size_t size, lldb_private::Status &error) override
Actually do the writing of memory to a process.
Definition: ProcessKDP.cpp:606
lldb_private::CommandReturnObject::AppendMessage
void AppendMessage(llvm::StringRef in_string)
Definition: CommandReturnObject.cpp:88
lldb_private::ObjectFile
Definition: ObjectFile.h:59
ProcessKDP::m_command_sp
lldb::CommandObjectSP m_command_sp
Definition: ProcessKDP.h:175
ProcessKDP::StopAsyncThread
void StopAsyncThread()
Definition: ProcessKDP.cpp:737
ProcessKDP::GetCommunication
CommunicationKDP & GetCommunication()
Definition: ProcessKDP.h:134
lldb_private::ObjectFile::GetType
Type GetType()
Definition: ObjectFile.h:630
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86
lldb_private::OptionGroupString::GetOptionValue
OptionValueString & GetOptionValue()
Definition: OptionGroupString.h:36
lldb_private::Log::PutCString
void PutCString(const char *cstr)
Definition: Log.cpp:118