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