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