LLDB  mainline
GDBRemoteCommunicationServerLLGS.cpp
Go to the documentation of this file.
1 //===-- GDBRemoteCommunicationServerLLGS.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 
11 #include "lldb/Host/Config.h"
12 
13 
14 #include <chrono>
15 #include <cstring>
16 #include <limits>
17 #include <thread>
18 
21 #include "lldb/Host/Debug.h"
22 #include "lldb/Host/File.h"
23 #include "lldb/Host/FileAction.h"
24 #include "lldb/Host/FileSystem.h"
25 #include "lldb/Host/Host.h"
26 #include "lldb/Host/HostInfo.h"
27 #include "lldb/Host/PosixApi.h"
28 #include "lldb/Host/Socket.h"
33 #include "lldb/Utility/Args.h"
35 #include "lldb/Utility/Endian.h"
36 #include "lldb/Utility/GDBRemote.h"
38 #include "lldb/Utility/Log.h"
40 #include "lldb/Utility/State.h"
43 #include "lldb/Utility/UriParser.h"
44 #include "llvm/ADT/Triple.h"
45 #include "llvm/Support/JSON.h"
46 #include "llvm/Support/ScopedPrinter.h"
47 
48 #include "ProcessGDBRemote.h"
49 #include "ProcessGDBRemoteLog.h"
51 
52 using namespace lldb;
53 using namespace lldb_private;
54 using namespace lldb_private::process_gdb_remote;
55 using namespace llvm;
56 
57 // GDBRemote Errors
58 
59 namespace {
60 enum GDBRemoteServerError {
61  // Set to the first unused error number in literal form below
62  eErrorFirst = 29,
63  eErrorNoProcess = eErrorFirst,
64  eErrorResume,
65  eErrorExitStatus
66 };
67 }
68 
69 // GDBRemoteCommunicationServerLLGS constructor
70 GDBRemoteCommunicationServerLLGS::GDBRemoteCommunicationServerLLGS(
71  MainLoop &mainloop, const NativeProcessProtocol::Factory &process_factory)
72  : GDBRemoteCommunicationServerCommon("gdb-remote.server",
73  "gdb-remote.server.rx_packet"),
74  m_mainloop(mainloop), m_process_factory(process_factory),
75  m_current_process(nullptr), m_continue_process(nullptr),
76  m_stdio_communication("process.stdio") {
78 }
79 
199 
215 
218 
222 
226 
228  [this](StringExtractorGDBRemote packet, Status &error,
229  bool &interrupt, bool &quit) {
230  quit = true;
231  return this->Handle_k(packet);
232  });
233 
237 }
238 
240  m_process_launch_info = info;
241 }
242 
245 
247  return Status("%s: no process command line specified to launch",
248  __FUNCTION__);
249 
250  const bool should_forward_stdio =
251  m_process_launch_info.GetFileActionForFD(STDIN_FILENO) == nullptr ||
252  m_process_launch_info.GetFileActionForFD(STDOUT_FILENO) == nullptr ||
253  m_process_launch_info.GetFileActionForFD(STDERR_FILENO) == nullptr;
255  m_process_launch_info.GetFlags().Set(eLaunchFlagDebug);
256 
257  if (should_forward_stdio) {
258  // Temporarily relax the following for Windows until we can take advantage
259  // of the recently added pty support. This doesn't really affect the use of
260  // lldb-server on Windows.
261 #if !defined(_WIN32)
263  return Status(std::move(Err));
264 #endif
265  }
266 
267  {
268  std::lock_guard<std::recursive_mutex> guard(m_debugged_process_mutex);
269  assert(m_debugged_processes.empty() && "lldb-server creating debugged "
270  "process but one already exists");
271  auto process_or =
273  if (!process_or)
274  return Status(process_or.takeError());
275  m_continue_process = m_current_process = process_or->get();
276  m_debugged_processes[m_current_process->GetID()] = std::move(*process_or);
277  }
278 
280 
281  // Handle mirroring of inferior stdout/stderr over the gdb-remote protocol as
282  // needed. llgs local-process debugging may specify PTY paths, which will
283  // make these file actions non-null process launch -i/e/o will also make
284  // these file actions non-null nullptr means that the traffic is expected to
285  // flow over gdb-remote protocol
286  if (should_forward_stdio) {
287  // nullptr means it's not redirected to file or pty (in case of LLGS local)
288  // at least one of stdio will be transferred pty<->gdb-remote we need to
289  // give the pty primary handle to this object to read and/or write
290  LLDB_LOG(log,
291  "pid = {0}: setting up stdout/stderr redirection via $O "
292  "gdb-remote commands",
294 
295  // Setup stdout/stderr mapping from inferior to $O
296  auto terminal_fd = m_current_process->GetTerminalFileDescriptor();
297  if (terminal_fd >= 0) {
298  LLDB_LOGF(log,
299  "ProcessGDBRemoteCommunicationServerLLGS::%s setting "
300  "inferior STDIO fd to %d",
301  __FUNCTION__, terminal_fd);
302  Status status = SetSTDIOFileDescriptor(terminal_fd);
303  if (status.Fail())
304  return status;
305  } else {
306  LLDB_LOGF(log,
307  "ProcessGDBRemoteCommunicationServerLLGS::%s ignoring "
308  "inferior STDIO since terminal fd reported as %d",
309  __FUNCTION__, terminal_fd);
310  }
311  } else {
312  LLDB_LOG(log,
313  "pid = {0} skipping stdout/stderr redirection via $O: inferior "
314  "will communicate over client-provided file descriptors",
316  }
317 
318  printf("Launched '%s' as process %" PRIu64 "...\n",
321 
322  return Status();
323 }
324 
327  LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64,
328  __FUNCTION__, pid);
329 
330  // Before we try to attach, make sure we aren't already monitoring something
331  // else.
332  if (!m_debugged_processes.empty())
333  return Status("cannot attach to process %" PRIu64
334  " when another process with pid %" PRIu64
335  " is being debugged.",
336  pid, m_current_process->GetID());
337 
338  // Try to attach.
339  auto process_or = m_process_factory.Attach(pid, *this, m_mainloop);
340  if (!process_or) {
341  Status status(process_or.takeError());
342  llvm::errs() << llvm::formatv("failed to attach to process {0}: {1}\n", pid,
343  status);
344  return status;
345  }
346  m_continue_process = m_current_process = process_or->get();
347  m_debugged_processes[m_current_process->GetID()] = std::move(*process_or);
349 
350  // Setup stdout/stderr mapping from inferior.
351  auto terminal_fd = m_current_process->GetTerminalFileDescriptor();
352  if (terminal_fd >= 0) {
353  LLDB_LOGF(log,
354  "ProcessGDBRemoteCommunicationServerLLGS::%s setting "
355  "inferior STDIO fd to %d",
356  __FUNCTION__, terminal_fd);
357  Status status = SetSTDIOFileDescriptor(terminal_fd);
358  if (status.Fail())
359  return status;
360  } else {
361  LLDB_LOGF(log,
362  "ProcessGDBRemoteCommunicationServerLLGS::%s ignoring "
363  "inferior STDIO since terminal fd reported as %d",
364  __FUNCTION__, terminal_fd);
365  }
366 
367  printf("Attached to process %" PRIu64 "...\n", pid);
368  return Status();
369 }
370 
372  llvm::StringRef process_name, bool include_existing) {
374 
375  std::chrono::milliseconds polling_interval = std::chrono::milliseconds(1);
376 
377  // Create the matcher used to search the process list.
378  ProcessInstanceInfoList exclusion_list;
379  ProcessInstanceInfoMatch match_info;
381  process_name, llvm::sys::path::Style::native);
383 
384  if (include_existing) {
385  LLDB_LOG(log, "including existing processes in search");
386  } else {
387  // Create the excluded process list before polling begins.
388  Host::FindProcesses(match_info, exclusion_list);
389  LLDB_LOG(log, "placed '{0}' processes in the exclusion list.",
390  exclusion_list.size());
391  }
392 
393  LLDB_LOG(log, "waiting for '{0}' to appear", process_name);
394 
395  auto is_in_exclusion_list =
396  [&exclusion_list](const ProcessInstanceInfo &info) {
397  for (auto &excluded : exclusion_list) {
398  if (excluded.GetProcessID() == info.GetProcessID())
399  return true;
400  }
401  return false;
402  };
403 
404  ProcessInstanceInfoList loop_process_list;
405  while (true) {
406  loop_process_list.clear();
407  if (Host::FindProcesses(match_info, loop_process_list)) {
408  // Remove all the elements that are in the exclusion list.
409  llvm::erase_if(loop_process_list, is_in_exclusion_list);
410 
411  // One match! We found the desired process.
412  if (loop_process_list.size() == 1) {
413  auto matching_process_pid = loop_process_list[0].GetProcessID();
414  LLDB_LOG(log, "found pid {0}", matching_process_pid);
415  return AttachToProcess(matching_process_pid);
416  }
417 
418  // Multiple matches! Return an error reporting the PIDs we found.
419  if (loop_process_list.size() > 1) {
420  StreamString error_stream;
421  error_stream.Format(
422  "Multiple executables with name: '{0}' found. Pids: ",
423  process_name);
424  for (size_t i = 0; i < loop_process_list.size() - 1; ++i) {
425  error_stream.Format("{0}, ", loop_process_list[i].GetProcessID());
426  }
427  error_stream.Format("{0}.", loop_process_list.back().GetProcessID());
428 
429  Status error;
430  error.SetErrorString(error_stream.GetString());
431  return error;
432  }
433  }
434  // No matches, we have not found the process. Sleep until next poll.
435  LLDB_LOG(log, "sleep {0} seconds", polling_interval);
436  std::this_thread::sleep_for(polling_interval);
437  }
438 }
439 
441  NativeProcessProtocol *process) {
442  assert(process && "process cannot be NULL");
444  if (log) {
445  LLDB_LOGF(log,
446  "GDBRemoteCommunicationServerLLGS::%s called with "
447  "NativeProcessProtocol pid %" PRIu64 ", current state: %s",
448  __FUNCTION__, process->GetID(),
449  StateAsCString(process->GetState()));
450  }
451 }
452 
455  NativeProcessProtocol *process) {
456  assert(process && "process cannot be NULL");
458 
459  // send W notification
460  auto wait_status = process->GetExitStatus();
461  if (!wait_status) {
462  LLDB_LOG(log, "pid = {0}, failed to retrieve process exit status",
463  process->GetID());
464 
465  StreamGDBRemote response;
466  response.PutChar('E');
467  response.PutHex8(GDBRemoteServerError::eErrorExitStatus);
468  return SendPacketNoLock(response.GetString());
469  }
470 
471  LLDB_LOG(log, "pid = {0}, returning exit type {1}", process->GetID(),
472  *wait_status);
473 
474  StreamGDBRemote response;
475  response.Format("{0:g}", *wait_status);
476  return SendPacketNoLock(response.GetString());
477 }
478 
479 static void AppendHexValue(StreamString &response, const uint8_t *buf,
480  uint32_t buf_size, bool swap) {
481  int64_t i;
482  if (swap) {
483  for (i = buf_size - 1; i >= 0; i--)
484  response.PutHex8(buf[i]);
485  } else {
486  for (i = 0; i < buf_size; i++)
487  response.PutHex8(buf[i]);
488  }
489 }
490 
491 static llvm::StringRef GetEncodingNameOrEmpty(const RegisterInfo &reg_info) {
492  switch (reg_info.encoding) {
493  case eEncodingUint:
494  return "uint";
495  case eEncodingSint:
496  return "sint";
497  case eEncodingIEEE754:
498  return "ieee754";
499  case eEncodingVector:
500  return "vector";
501  default:
502  return "";
503  }
504 }
505 
506 static llvm::StringRef GetFormatNameOrEmpty(const RegisterInfo &reg_info) {
507  switch (reg_info.format) {
508  case eFormatBinary:
509  return "binary";
510  case eFormatDecimal:
511  return "decimal";
512  case eFormatHex:
513  return "hex";
514  case eFormatFloat:
515  return "float";
517  return "vector-sint8";
519  return "vector-uint8";
521  return "vector-sint16";
523  return "vector-uint16";
525  return "vector-sint32";
527  return "vector-uint32";
529  return "vector-float32";
531  return "vector-uint64";
533  return "vector-uint128";
534  default:
535  return "";
536  };
537 }
538 
539 static llvm::StringRef GetKindGenericOrEmpty(const RegisterInfo &reg_info) {
540  switch (reg_info.kinds[RegisterKind::eRegisterKindGeneric]) {
542  return "pc";
544  return "sp";
546  return "fp";
548  return "ra";
550  return "flags";
552  return "arg1";
554  return "arg2";
556  return "arg3";
558  return "arg4";
560  return "arg5";
562  return "arg6";
564  return "arg7";
566  return "arg8";
567  default:
568  return "";
569  }
570 }
571 
572 static void CollectRegNums(const uint32_t *reg_num, StreamString &response,
573  bool usehex) {
574  for (int i = 0; *reg_num != LLDB_INVALID_REGNUM; ++reg_num, ++i) {
575  if (i > 0)
576  response.PutChar(',');
577  if (usehex)
578  response.Printf("%" PRIx32, *reg_num);
579  else
580  response.Printf("%" PRIu32, *reg_num);
581  }
582 }
583 
585  StreamString &response, NativeRegisterContext &reg_ctx,
586  const RegisterInfo &reg_info, const RegisterValue *reg_value_p,
587  lldb::ByteOrder byte_order) {
588  RegisterValue reg_value;
589  if (!reg_value_p) {
590  Status error = reg_ctx.ReadRegister(&reg_info, reg_value);
591  if (error.Success())
592  reg_value_p = &reg_value;
593  // else log.
594  }
595 
596  if (reg_value_p) {
597  AppendHexValue(response, (const uint8_t *)reg_value_p->GetBytes(),
598  reg_value_p->GetByteSize(),
599  byte_order == lldb::eByteOrderLittle);
600  } else {
601  // Zero-out any unreadable values.
602  if (reg_info.byte_size > 0) {
603  std::basic_string<uint8_t> zeros(reg_info.byte_size, '\0');
604  AppendHexValue(response, zeros.data(), zeros.size(), false);
605  }
606  }
607 }
608 
609 static llvm::Optional<json::Object>
612 
613  NativeRegisterContext& reg_ctx = thread.GetRegisterContext();
614 
615  json::Object register_object;
616 
617 #ifdef LLDB_JTHREADSINFO_FULL_REGISTER_SET
618  const auto expedited_regs =
620 #else
621  const auto expedited_regs =
623 #endif
624  if (expedited_regs.empty())
625  return llvm::None;
626 
627  for (auto &reg_num : expedited_regs) {
628  const RegisterInfo *const reg_info_p =
629  reg_ctx.GetRegisterInfoAtIndex(reg_num);
630  if (reg_info_p == nullptr) {
631  LLDB_LOGF(log,
632  "%s failed to get register info for register index %" PRIu32,
633  __FUNCTION__, reg_num);
634  continue;
635  }
636 
637  if (reg_info_p->value_regs != nullptr)
638  continue; // Only expedite registers that are not contained in other
639  // registers.
640 
641  RegisterValue reg_value;
642  Status error = reg_ctx.ReadRegister(reg_info_p, reg_value);
643  if (error.Fail()) {
644  LLDB_LOGF(log, "%s failed to read register '%s' index %" PRIu32 ": %s",
645  __FUNCTION__,
646  reg_info_p->name ? reg_info_p->name : "<unnamed-register>",
647  reg_num, error.AsCString());
648  continue;
649  }
650 
651  StreamString stream;
652  WriteRegisterValueInHexFixedWidth(stream, reg_ctx, *reg_info_p,
653  &reg_value, lldb::eByteOrderBig);
654 
655  register_object.try_emplace(llvm::to_string(reg_num),
656  stream.GetString().str());
657  }
658 
659  return register_object;
660 }
661 
662 static const char *GetStopReasonString(StopReason stop_reason) {
663  switch (stop_reason) {
664  case eStopReasonTrace:
665  return "trace";
667  return "breakpoint";
669  return "watchpoint";
670  case eStopReasonSignal:
671  return "signal";
673  return "exception";
674  case eStopReasonExec:
675  return "exec";
677  return "processor trace";
678  case eStopReasonFork:
679  return "fork";
680  case eStopReasonVFork:
681  return "vfork";
683  return "vforkdone";
685  case eStopReasonInvalid:
688  case eStopReasonNone:
689  break; // ignored
690  }
691  return nullptr;
692 }
693 
694 static llvm::Expected<json::Array>
695 GetJSONThreadsInfo(NativeProcessProtocol &process, bool abridged) {
697 
698  json::Array threads_array;
699 
700  // Ensure we can get info on the given thread.
701  uint32_t thread_idx = 0;
702  for (NativeThreadProtocol *thread;
703  (thread = process.GetThreadAtIndex(thread_idx)) != nullptr;
704  ++thread_idx) {
705 
706  lldb::tid_t tid = thread->GetID();
707 
708  // Grab the reason this thread stopped.
709  struct ThreadStopInfo tid_stop_info;
710  std::string description;
711  if (!thread->GetStopReason(tid_stop_info, description))
712  return llvm::make_error<llvm::StringError>(
713  "failed to get stop reason", llvm::inconvertibleErrorCode());
714 
715  const int signum = tid_stop_info.details.signal.signo;
716  if (log) {
717  LLDB_LOGF(log,
718  "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
719  " tid %" PRIu64
720  " got signal signo = %d, reason = %d, exc_type = %" PRIu64,
721  __FUNCTION__, process.GetID(), tid, signum,
722  tid_stop_info.reason, tid_stop_info.details.exception.type);
723  }
724 
725  json::Object thread_obj;
726 
727  if (!abridged) {
728  if (llvm::Optional<json::Object> registers = GetRegistersAsJSON(*thread))
729  thread_obj.try_emplace("registers", std::move(*registers));
730  }
731 
732  thread_obj.try_emplace("tid", static_cast<int64_t>(tid));
733 
734  if (signum != 0)
735  thread_obj.try_emplace("signal", signum);
736 
737  const std::string thread_name = thread->GetName();
738  if (!thread_name.empty())
739  thread_obj.try_emplace("name", thread_name);
740 
741  const char *stop_reason = GetStopReasonString(tid_stop_info.reason);
742  if (stop_reason)
743  thread_obj.try_emplace("reason", stop_reason);
744 
745  if (!description.empty())
746  thread_obj.try_emplace("description", description);
747 
748  if ((tid_stop_info.reason == eStopReasonException) &&
749  tid_stop_info.details.exception.type) {
750  thread_obj.try_emplace(
751  "metype", static_cast<int64_t>(tid_stop_info.details.exception.type));
752 
753  json::Array medata_array;
754  for (uint32_t i = 0; i < tid_stop_info.details.exception.data_count;
755  ++i) {
756  medata_array.push_back(
757  static_cast<int64_t>(tid_stop_info.details.exception.data[i]));
758  }
759  thread_obj.try_emplace("medata", std::move(medata_array));
760  }
761  threads_array.push_back(std::move(thread_obj));
762  }
763  return threads_array;
764 }
765 
768  lldb::tid_t tid) {
770 
771  // Ensure we have a debugged process.
772  if (!m_current_process ||
774  return SendErrorResponse(50);
775 
776  LLDB_LOG(log, "preparing packet for pid {0} tid {1}",
777  m_current_process->GetID(), tid);
778 
779  // Ensure we can get info on the given thread.
781  if (!thread)
782  return SendErrorResponse(51);
783 
784  // Grab the reason this thread stopped.
785  struct ThreadStopInfo tid_stop_info;
786  std::string description;
787  if (!thread->GetStopReason(tid_stop_info, description))
788  return SendErrorResponse(52);
789 
790  // FIXME implement register handling for exec'd inferiors.
791  // if (tid_stop_info.reason == eStopReasonExec) {
792  // const bool force = true;
793  // InitializeRegisters(force);
794  // }
795 
796  StreamString response;
797  // Output the T packet with the thread
798  response.PutChar('T');
799  int signum = tid_stop_info.details.signal.signo;
800  LLDB_LOG(
801  log,
802  "pid {0}, tid {1}, got signal signo = {2}, reason = {3}, exc_type = {4}",
803  m_current_process->GetID(), tid, signum, int(tid_stop_info.reason),
804  tid_stop_info.details.exception.type);
805 
806  // Print the signal number.
807  response.PutHex8(signum & 0xff);
808 
809  // Include the tid.
810  response.Printf("thread:%" PRIx64 ";", tid);
811 
812  // Include the thread name if there is one.
813  const std::string thread_name = thread->GetName();
814  if (!thread_name.empty()) {
815  size_t thread_name_len = thread_name.length();
816 
817  if (::strcspn(thread_name.c_str(), "$#+-;:") == thread_name_len) {
818  response.PutCString("name:");
819  response.PutCString(thread_name);
820  } else {
821  // The thread name contains special chars, send as hex bytes.
822  response.PutCString("hexname:");
823  response.PutStringAsRawHex8(thread_name);
824  }
825  response.PutChar(';');
826  }
827 
828  // If a 'QListThreadsInStopReply' was sent to enable this feature, we will
829  // send all thread IDs back in the "threads" key whose value is a list of hex
830  // thread IDs separated by commas:
831  // "threads:10a,10b,10c;"
832  // This will save the debugger from having to send a pair of qfThreadInfo and
833  // qsThreadInfo packets, but it also might take a lot of room in the stop
834  // reply packet, so it must be enabled only on systems where there are no
835  // limits on packet lengths.
837  response.PutCString("threads:");
838 
839  uint32_t thread_index = 0;
840  NativeThreadProtocol *listed_thread;
841  for (listed_thread = m_current_process->GetThreadAtIndex(thread_index);
842  listed_thread; ++thread_index,
843  listed_thread = m_current_process->GetThreadAtIndex(thread_index)) {
844  if (thread_index > 0)
845  response.PutChar(',');
846  response.Printf("%" PRIx64, listed_thread->GetID());
847  }
848  response.PutChar(';');
849 
850  // Include JSON info that describes the stop reason for any threads that
851  // actually have stop reasons. We use the new "jstopinfo" key whose values
852  // is hex ascii JSON that contains the thread IDs thread stop info only for
853  // threads that have stop reasons. Only send this if we have more than one
854  // thread otherwise this packet has all the info it needs.
855  if (thread_index > 1) {
856  const bool threads_with_valid_stop_info_only = true;
857  llvm::Expected<json::Array> threads_info = GetJSONThreadsInfo(
858  *m_current_process, threads_with_valid_stop_info_only);
859  if (threads_info) {
860  response.PutCString("jstopinfo:");
861  StreamString unescaped_response;
862  unescaped_response.AsRawOstream() << std::move(*threads_info);
863  response.PutStringAsRawHex8(unescaped_response.GetData());
864  response.PutChar(';');
865  } else {
866  LLDB_LOG_ERROR(log, threads_info.takeError(),
867  "failed to prepare a jstopinfo field for pid {1}: {0}",
869  }
870  }
871 
872  uint32_t i = 0;
873  response.PutCString("thread-pcs");
874  char delimiter = ':';
875  for (NativeThreadProtocol *thread;
876  (thread = m_current_process->GetThreadAtIndex(i)) != nullptr; ++i) {
877  NativeRegisterContext& reg_ctx = thread->GetRegisterContext();
878 
879  uint32_t reg_to_read = reg_ctx.ConvertRegisterKindToRegisterNumber(
881  const RegisterInfo *const reg_info_p =
882  reg_ctx.GetRegisterInfoAtIndex(reg_to_read);
883 
884  RegisterValue reg_value;
885  Status error = reg_ctx.ReadRegister(reg_info_p, reg_value);
886  if (error.Fail()) {
887  LLDB_LOGF(log, "%s failed to read register '%s' index %" PRIu32 ": %s",
888  __FUNCTION__,
889  reg_info_p->name ? reg_info_p->name : "<unnamed-register>",
890  reg_to_read, error.AsCString());
891  continue;
892  }
893 
894  response.PutChar(delimiter);
895  delimiter = ',';
896  WriteRegisterValueInHexFixedWidth(response, reg_ctx, *reg_info_p,
897  &reg_value, endian::InlHostByteOrder());
898  }
899 
900  response.PutChar(';');
901  }
902 
903  //
904  // Expedite registers.
905  //
906 
907  // Grab the register context.
908  NativeRegisterContext& reg_ctx = thread->GetRegisterContext();
909  const auto expedited_regs =
911 
912  for (auto &reg_num : expedited_regs) {
913  const RegisterInfo *const reg_info_p =
914  reg_ctx.GetRegisterInfoAtIndex(reg_num);
915  // Only expediate registers that are not contained in other registers.
916  if (reg_info_p != nullptr && reg_info_p->value_regs == nullptr) {
917  RegisterValue reg_value;
918  Status error = reg_ctx.ReadRegister(reg_info_p, reg_value);
919  if (error.Success()) {
920  response.Printf("%.02x:", reg_num);
921  WriteRegisterValueInHexFixedWidth(response, reg_ctx, *reg_info_p,
922  &reg_value, lldb::eByteOrderBig);
923  response.PutChar(';');
924  } else {
925  LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s failed to read "
926  "register '%s' index %" PRIu32 ": %s",
927  __FUNCTION__,
928  reg_info_p->name ? reg_info_p->name : "<unnamed-register>",
929  reg_num, error.AsCString());
930  }
931  }
932  }
933 
934  const char *reason_str = GetStopReasonString(tid_stop_info.reason);
935  if (reason_str != nullptr) {
936  response.Printf("reason:%s;", reason_str);
937  }
938 
939  if (!description.empty()) {
940  // Description may contains special chars, send as hex bytes.
941  response.PutCString("description:");
942  response.PutStringAsRawHex8(description);
943  response.PutChar(';');
944  } else if ((tid_stop_info.reason == eStopReasonException) &&
945  tid_stop_info.details.exception.type) {
946  response.PutCString("metype:");
947  response.PutHex64(tid_stop_info.details.exception.type);
948  response.PutCString(";mecount:");
949  response.PutHex32(tid_stop_info.details.exception.data_count);
950  response.PutChar(';');
951 
952  for (uint32_t i = 0; i < tid_stop_info.details.exception.data_count; ++i) {
953  response.PutCString("medata:");
954  response.PutHex64(tid_stop_info.details.exception.data[i]);
955  response.PutChar(';');
956  }
957  }
958 
959  // Include child process PID/TID for forks.
960  if (tid_stop_info.reason == eStopReasonFork ||
961  tid_stop_info.reason == eStopReasonVFork) {
962  assert(bool(m_extensions_supported &
964  if (tid_stop_info.reason == eStopReasonFork)
965  assert(bool(m_extensions_supported &
967  if (tid_stop_info.reason == eStopReasonVFork)
968  assert(bool(m_extensions_supported &
970  response.Printf("%s:p%" PRIx64 ".%" PRIx64 ";", reason_str,
971  tid_stop_info.details.fork.child_pid,
972  tid_stop_info.details.fork.child_tid);
973  }
974 
975  return SendPacketNoLock(response.GetString());
976 }
977 
979  NativeProcessProtocol *process) {
980  assert(process && "process cannot be NULL");
981 
983  LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
984 
986  if (result != PacketResult::Success) {
987  LLDB_LOGF(log,
988  "GDBRemoteCommunicationServerLLGS::%s failed to send stop "
989  "notification for PID %" PRIu64 ", state: eStateExited",
990  __FUNCTION__, process->GetID());
991  }
992 
993  // Close the pipe to the inferior terminal i/o if we launched it and set one
994  // up.
996 
997  // We are ready to exit the debug monitor.
998  m_exit_now = true;
1000 }
1001 
1003  NativeProcessProtocol *process) {
1004  assert(process && "process cannot be NULL");
1005 
1007  LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
1008 
1009  // Send the stop reason unless this is the stop after the launch or attach.
1010  switch (m_inferior_prev_state) {
1011  case eStateLaunching:
1012  case eStateAttaching:
1013  // Don't send anything per debugserver behavior.
1014  break;
1015  default:
1016  // In all other cases, send the stop reason.
1018  if (result != PacketResult::Success) {
1019  LLDB_LOGF(log,
1020  "GDBRemoteCommunicationServerLLGS::%s failed to send stop "
1021  "notification for PID %" PRIu64 ", state: eStateExited",
1022  __FUNCTION__, process->GetID());
1023  }
1024  break;
1025  }
1026 }
1027 
1029  NativeProcessProtocol *process, lldb::StateType state) {
1030  assert(process && "process cannot be NULL");
1032  if (log) {
1033  LLDB_LOGF(log,
1034  "GDBRemoteCommunicationServerLLGS::%s called with "
1035  "NativeProcessProtocol pid %" PRIu64 ", state: %s",
1036  __FUNCTION__, process->GetID(), StateAsCString(state));
1037  }
1038 
1039  switch (state) {
1042  break;
1043 
1045  // Make sure we get all of the pending stdout/stderr from the inferior and
1046  // send it to the lldb host before we send the state change notification
1048  // Then stop the forwarding, so that any late output (see llvm.org/pr25652)
1049  // does not interfere with our protocol.
1051  HandleInferiorState_Stopped(process);
1052  break;
1053 
1055  // Same as above
1058  HandleInferiorState_Exited(process);
1059  break;
1060 
1061  default:
1062  if (log) {
1063  LLDB_LOGF(log,
1064  "GDBRemoteCommunicationServerLLGS::%s didn't handle state "
1065  "change for pid %" PRIu64 ", new state: %s",
1066  __FUNCTION__, process->GetID(), StateAsCString(state));
1067  }
1068  break;
1069  }
1070 
1071  // Remember the previous state reported to us.
1072  m_inferior_prev_state = state;
1073 }
1074 
1077 }
1078 
1080  NativeProcessProtocol *parent_process,
1081  std::unique_ptr<NativeProcessProtocol> child_process) {
1082  lldb::pid_t child_pid = child_process->GetID();
1083  assert(child_pid != LLDB_INVALID_PROCESS_ID);
1084  assert(m_debugged_processes.find(child_pid) == m_debugged_processes.end());
1085  m_debugged_processes[child_pid] = std::move(child_process);
1086 }
1087 
1090 
1091  bool interrupt = false;
1092  bool done = false;
1093  Status error;
1094  while (true) {
1095  const PacketResult result = GetPacketAndSendResponse(
1096  std::chrono::microseconds(0), error, interrupt, done);
1097  if (result == PacketResult::ErrorReplyTimeout)
1098  break; // No more packets in the queue
1099 
1100  if ((result != PacketResult::Success)) {
1101  LLDB_LOGF(log,
1102  "GDBRemoteCommunicationServerLLGS::%s processing a packet "
1103  "failed: %s",
1104  __FUNCTION__, error.AsCString());
1106  break;
1107  }
1108  }
1109 }
1110 
1112  std::unique_ptr<Connection> connection) {
1113  IOObjectSP read_object_sp = connection->GetReadObject();
1114  GDBRemoteCommunicationServer::SetConnection(std::move(connection));
1115 
1116  Status error;
1118  read_object_sp, [this](MainLoopBase &) { DataAvailableCallback(); },
1119  error);
1120  return error;
1121 }
1122 
1125  uint32_t len) {
1126  if ((buffer == nullptr) || (len == 0)) {
1127  // Nothing to send.
1128  return PacketResult::Success;
1129  }
1130 
1131  StreamString response;
1132  response.PutChar('O');
1133  response.PutBytesAsRawHex8(buffer, len);
1134 
1135  return SendPacketNoLock(response.GetString());
1136 }
1137 
1139  Status error;
1140 
1141  // Set up the reading/handling of process I/O
1142  std::unique_ptr<ConnectionFileDescriptor> conn_up(
1143  new ConnectionFileDescriptor(fd, true));
1144  if (!conn_up) {
1145  error.SetErrorString("failed to create ConnectionFileDescriptor");
1146  return error;
1147  }
1148 
1150  m_stdio_communication.SetConnection(std::move(conn_up));
1152  error.SetErrorString(
1153  "failed to set connection for inferior I/O communication");
1154  return error;
1155  }
1156 
1157  return Status();
1158 }
1159 
1161  // Don't forward if not connected (e.g. when attaching).
1163  return;
1164 
1165  Status error;
1169  [this](MainLoopBase &) { SendProcessOutput(); }, error);
1170 
1171  if (!m_stdio_handle_up) {
1172  // Not much we can do about the failure. Log it and continue without
1173  // forwarding.
1175  LLDB_LOGF(log,
1176  "GDBRemoteCommunicationServerLLGS::%s Failed to set up stdio "
1177  "forwarding: %s",
1178  __FUNCTION__, error.AsCString());
1179  }
1180 }
1181 
1183  m_stdio_handle_up.reset();
1184 }
1185 
1187  char buffer[1024];
1188  ConnectionStatus status;
1189  Status error;
1190  while (true) {
1191  size_t bytes_read = m_stdio_communication.Read(
1192  buffer, sizeof buffer, std::chrono::microseconds(0), status, &error);
1193  switch (status) {
1195  SendONotification(buffer, bytes_read);
1196  break;
1202  LLDB_LOGF(log,
1203  "GDBRemoteCommunicationServerLLGS::%s Stopping stdio "
1204  "forwarding as communication returned status %d (error: "
1205  "%s)",
1206  __FUNCTION__, status, error.AsCString());
1207  m_stdio_handle_up.reset();
1208  return;
1209 
1212  return;
1213  }
1214  }
1215 }
1216 
1219  StringExtractorGDBRemote &packet) {
1220 
1221  // Fail if we don't have a current process.
1222  if (!m_current_process ||
1224  return SendErrorResponse(Status("Process not running."));
1225 
1227 }
1228 
1231  StringExtractorGDBRemote &packet) {
1232  // Fail if we don't have a current process.
1233  if (!m_current_process ||
1235  return SendErrorResponse(Status("Process not running."));
1236 
1237  packet.ConsumeFront("jLLDBTraceStop:");
1238  Expected<TraceStopRequest> stop_request =
1239  json::parse<TraceStopRequest>(packet.Peek(), "TraceStopRequest");
1240  if (!stop_request)
1241  return SendErrorResponse(stop_request.takeError());
1242 
1243  if (Error err = m_current_process->TraceStop(*stop_request))
1244  return SendErrorResponse(std::move(err));
1245 
1246  return SendOKResponse();
1247 }
1248 
1251  StringExtractorGDBRemote &packet) {
1252 
1253  // Fail if we don't have a current process.
1254  if (!m_current_process ||
1256  return SendErrorResponse(Status("Process not running."));
1257 
1258  packet.ConsumeFront("jLLDBTraceStart:");
1259  Expected<TraceStartRequest> request =
1260  json::parse<TraceStartRequest>(packet.Peek(), "TraceStartRequest");
1261  if (!request)
1262  return SendErrorResponse(request.takeError());
1263 
1264  if (Error err = m_current_process->TraceStart(packet.Peek(), request->type))
1265  return SendErrorResponse(std::move(err));
1266 
1267  return SendOKResponse();
1268 }
1269 
1272  StringExtractorGDBRemote &packet) {
1273 
1274  // Fail if we don't have a current process.
1275  if (!m_current_process ||
1277  return SendErrorResponse(Status("Process not running."));
1278 
1279  packet.ConsumeFront("jLLDBTraceGetState:");
1280  Expected<TraceGetStateRequest> request =
1281  json::parse<TraceGetStateRequest>(packet.Peek(), "TraceGetStateRequest");
1282  if (!request)
1283  return SendErrorResponse(request.takeError());
1284 
1285  return SendJSONResponse(m_current_process->TraceGetState(request->type));
1286 }
1287 
1290  StringExtractorGDBRemote &packet) {
1291 
1292  // Fail if we don't have a current process.
1293  if (!m_current_process ||
1295  return SendErrorResponse(Status("Process not running."));
1296 
1297  packet.ConsumeFront("jLLDBTraceGetBinaryData:");
1298  llvm::Expected<TraceGetBinaryDataRequest> request =
1299  llvm::json::parse<TraceGetBinaryDataRequest>(packet.Peek(),
1300  "TraceGetBinaryDataRequest");
1301  if (!request)
1302  return SendErrorResponse(Status(request.takeError()));
1303 
1304  if (Expected<std::vector<uint8_t>> bytes =
1306  StreamGDBRemote response;
1307  response.PutEscapedBytes(bytes->data(), bytes->size());
1308  return SendPacketNoLock(response.GetString());
1309  } else
1310  return SendErrorResponse(bytes.takeError());
1311 }
1312 
1315  StringExtractorGDBRemote &packet) {
1316  // Fail if we don't have a current process.
1317  if (!m_current_process ||
1319  return SendErrorResponse(68);
1320 
1322 
1323  if (pid == LLDB_INVALID_PROCESS_ID)
1324  return SendErrorResponse(1);
1325 
1326  ProcessInstanceInfo proc_info;
1327  if (!Host::GetProcessInfo(pid, proc_info))
1328  return SendErrorResponse(1);
1329 
1330  StreamString response;
1331  CreateProcessInfoResponse_DebugServerStyle(proc_info, response);
1332  return SendPacketNoLock(response.GetString());
1333 }
1334 
1337  // Fail if we don't have a current process.
1338  if (!m_current_process ||
1340  return SendErrorResponse(68);
1341 
1342  // Make sure we set the current thread so g and p packets return the data the
1343  // gdb will expect.
1345  SetCurrentThreadID(tid);
1346 
1348  if (!thread)
1349  return SendErrorResponse(69);
1350 
1351  StreamString response;
1352  response.Printf("QC%" PRIx64, thread->GetID());
1353 
1354  return SendPacketNoLock(response.GetString());
1355 }
1356 
1360 
1362 
1363  if (!m_current_process) {
1364  LLDB_LOG(log, "No debugged process found.");
1365  return PacketResult::Success;
1366  }
1367 
1369  if (error.Fail())
1370  LLDB_LOG(log, "Failed to kill debugged process {0}: {1}",
1372 
1373  // No OK response for kill packet.
1374  // return SendOKResponse ();
1375  return PacketResult::Success;
1376 }
1377 
1380  StringExtractorGDBRemote &packet) {
1381  packet.SetFilePos(::strlen("QSetDisableASLR:"));
1382  if (packet.GetU32(0))
1383  m_process_launch_info.GetFlags().Set(eLaunchFlagDisableASLR);
1384  else
1385  m_process_launch_info.GetFlags().Clear(eLaunchFlagDisableASLR);
1386  return SendOKResponse();
1387 }
1388 
1391  StringExtractorGDBRemote &packet) {
1392  packet.SetFilePos(::strlen("QSetWorkingDir:"));
1393  std::string path;
1394  packet.GetHexByteString(path);
1396  return SendOKResponse();
1397 }
1398 
1401  StringExtractorGDBRemote &packet) {
1403  if (working_dir) {
1404  StreamString response;
1405  response.PutStringAsRawHex8(working_dir.GetCString());
1406  return SendPacketNoLock(response.GetString());
1407  }
1408 
1409  return SendErrorResponse(14);
1410 }
1411 
1414  StringExtractorGDBRemote &packet) {
1416  return SendOKResponse();
1417 }
1418 
1421  StringExtractorGDBRemote &packet) {
1423  return SendOKResponse();
1424 }
1425 
1429  LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
1430 
1431  // Ensure we have a native process.
1432  if (!m_continue_process) {
1433  LLDB_LOGF(log,
1434  "GDBRemoteCommunicationServerLLGS::%s no debugged process "
1435  "shared pointer",
1436  __FUNCTION__);
1437  return SendErrorResponse(0x36);
1438  }
1439 
1440  // Pull out the signal number.
1441  packet.SetFilePos(::strlen("C"));
1442  if (packet.GetBytesLeft() < 1) {
1443  // Shouldn't be using a C without a signal.
1444  return SendIllFormedResponse(packet, "C packet specified without signal.");
1445  }
1446  const uint32_t signo =
1447  packet.GetHexMaxU32(false, std::numeric_limits<uint32_t>::max());
1448  if (signo == std::numeric_limits<uint32_t>::max())
1449  return SendIllFormedResponse(packet, "failed to parse signal number");
1450 
1451  // Handle optional continue address.
1452  if (packet.GetBytesLeft() > 0) {
1453  // FIXME add continue at address support for $C{signo}[;{continue-address}].
1454  if (*packet.Peek() == ';')
1455  return SendUnimplementedResponse(packet.GetStringRef().data());
1456  else
1457  return SendIllFormedResponse(
1458  packet, "unexpected content after $C{signal-number}");
1459  }
1460 
1463  Status error;
1464 
1465  // We have two branches: what to do if a continue thread is specified (in
1466  // which case we target sending the signal to that thread), or when we don't
1467  // have a continue thread set (in which case we send a signal to the
1468  // process).
1469 
1470  // TODO discuss with Greg Clayton, make sure this makes sense.
1471 
1472  lldb::tid_t signal_tid = GetContinueThreadID();
1473  if (signal_tid != LLDB_INVALID_THREAD_ID) {
1474  // The resume action for the continue thread (or all threads if a continue
1475  // thread is not set).
1477  static_cast<int>(signo)};
1478 
1479  // Add the action for the continue thread (or all threads when the continue
1480  // thread isn't present).
1481  resume_actions.Append(action);
1482  } else {
1483  // Send the signal to the process since we weren't targeting a specific
1484  // continue thread with the signal.
1485  error = m_continue_process->Signal(signo);
1486  if (error.Fail()) {
1487  LLDB_LOG(log, "failed to send signal for process {0}: {1}",
1489 
1490  return SendErrorResponse(0x52);
1491  }
1492  }
1493 
1494  // Resume the threads.
1495  error = m_continue_process->Resume(resume_actions);
1496  if (error.Fail()) {
1497  LLDB_LOG(log, "failed to resume threads for process {0}: {1}",
1499 
1500  return SendErrorResponse(0x38);
1501  }
1502 
1503  // Don't send an "OK" packet; response is the stopped/exited message.
1504  return PacketResult::Success;
1505 }
1506 
1510  LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
1511 
1512  packet.SetFilePos(packet.GetFilePos() + ::strlen("c"));
1513 
1514  // For now just support all continue.
1515  const bool has_continue_address = (packet.GetBytesLeft() > 0);
1516  if (has_continue_address) {
1517  LLDB_LOG(log, "not implemented for c[address] variant [{0} remains]",
1518  packet.Peek());
1519  return SendUnimplementedResponse(packet.GetStringRef().data());
1520  }
1521 
1522  // Ensure we have a native process.
1523  if (!m_continue_process) {
1524  LLDB_LOGF(log,
1525  "GDBRemoteCommunicationServerLLGS::%s no debugged process "
1526  "shared pointer",
1527  __FUNCTION__);
1528  return SendErrorResponse(0x36);
1529  }
1530 
1531  // Build the ResumeActionList
1534 
1535  Status error = m_continue_process->Resume(actions);
1536  if (error.Fail()) {
1537  LLDB_LOG(log, "c failed for process {0}: {1}", m_continue_process->GetID(),
1538  error);
1539  return SendErrorResponse(GDBRemoteServerError::eErrorResume);
1540  }
1541 
1542  LLDB_LOG(log, "continued process {0}", m_continue_process->GetID());
1543  // No response required from continue.
1544  return PacketResult::Success;
1545 }
1546 
1549  StringExtractorGDBRemote &packet) {
1550  StreamString response;
1551  response.Printf("vCont;c;C;s;S");
1552 
1553  return SendPacketNoLock(response.GetString());
1554 }
1555 
1558  StringExtractorGDBRemote &packet) {
1560  LLDB_LOGF(log, "GDBRemoteCommunicationServerLLGS::%s handling vCont packet",
1561  __FUNCTION__);
1562 
1563  packet.SetFilePos(::strlen("vCont"));
1564 
1565  if (packet.GetBytesLeft() == 0) {
1566  LLDB_LOGF(log,
1567  "GDBRemoteCommunicationServerLLGS::%s missing action from "
1568  "vCont package",
1569  __FUNCTION__);
1570  return SendIllFormedResponse(packet, "Missing action from vCont package");
1571  }
1572 
1573  // Check if this is all continue (no options or ";c").
1574  if (::strcmp(packet.Peek(), ";c") == 0) {
1575  // Move past the ';', then do a simple 'c'.
1576  packet.SetFilePos(packet.GetFilePos() + 1);
1577  return Handle_c(packet);
1578  } else if (::strcmp(packet.Peek(), ";s") == 0) {
1579  // Move past the ';', then do a simple 's'.
1580  packet.SetFilePos(packet.GetFilePos() + 1);
1581  return Handle_s(packet);
1582  }
1583 
1584  // Ensure we have a native process.
1585  if (!m_continue_process) {
1586  LLDB_LOG(log, "no debugged process");
1587  return SendErrorResponse(0x36);
1588  }
1589 
1590  ResumeActionList thread_actions;
1591 
1592  while (packet.GetBytesLeft() && *packet.Peek() == ';') {
1593  // Skip the semi-colon.
1594  packet.GetChar();
1595 
1596  // Build up the thread action.
1597  ResumeAction thread_action;
1598  thread_action.tid = LLDB_INVALID_THREAD_ID;
1599  thread_action.state = eStateInvalid;
1600  thread_action.signal = LLDB_INVALID_SIGNAL_NUMBER;
1601 
1602  const char action = packet.GetChar();
1603  switch (action) {
1604  case 'C':
1605  thread_action.signal = packet.GetHexMaxU32(false, 0);
1606  if (thread_action.signal == 0)
1607  return SendIllFormedResponse(
1608  packet, "Could not parse signal in vCont packet C action");
1609  LLVM_FALLTHROUGH;
1610 
1611  case 'c':
1612  // Continue
1613  thread_action.state = eStateRunning;
1614  break;
1615 
1616  case 'S':
1617  thread_action.signal = packet.GetHexMaxU32(false, 0);
1618  if (thread_action.signal == 0)
1619  return SendIllFormedResponse(
1620  packet, "Could not parse signal in vCont packet S action");
1621  LLVM_FALLTHROUGH;
1622 
1623  case 's':
1624  // Step
1625  thread_action.state = eStateStepping;
1626  break;
1627 
1628  default:
1629  return SendIllFormedResponse(packet, "Unsupported vCont action");
1630  break;
1631  }
1632 
1633  // Parse out optional :{thread-id} value.
1634  if (packet.GetBytesLeft() && (*packet.Peek() == ':')) {
1635  // Consume the separator.
1636  packet.GetChar();
1637 
1638  llvm::Expected<lldb::tid_t> tid_ret =
1639  ReadTid(packet, /*allow_all=*/true, m_continue_process->GetID());
1640  if (!tid_ret)
1641  return SendErrorResponse(tid_ret.takeError());
1642 
1643  thread_action.tid = tid_ret.get();
1644  if (thread_action.tid == StringExtractorGDBRemote::AllThreads)
1645  thread_action.tid = LLDB_INVALID_THREAD_ID;
1646  }
1647 
1648  thread_actions.Append(thread_action);
1649  }
1650 
1651  Status error = m_continue_process->Resume(thread_actions);
1652  if (error.Fail()) {
1653  LLDB_LOG(log, "vCont failed for process {0}: {1}",
1655  return SendErrorResponse(GDBRemoteServerError::eErrorResume);
1656  }
1657 
1658  LLDB_LOG(log, "continued process {0}", m_continue_process->GetID());
1659  // No response required from vCont.
1660  return PacketResult::Success;
1661 }
1662 
1665  LLDB_LOG(log, "setting current thread id to {0}", tid);
1666 
1667  m_current_tid = tid;
1668  if (m_current_process)
1670 }
1671 
1674  LLDB_LOG(log, "setting continue thread id to {0}", tid);
1675 
1676  m_continue_tid = tid;
1677 }
1678 
1681  StringExtractorGDBRemote &packet) {
1682  // Handle the $? gdbremote command.
1683 
1684  // If no process, indicate error
1685  if (!m_current_process)
1686  return SendErrorResponse(02);
1687 
1689 }
1690 
1693  lldb::StateType process_state) {
1695 
1696  switch (process_state) {
1697  case eStateAttaching:
1698  case eStateLaunching:
1699  case eStateRunning:
1700  case eStateStepping:
1701  case eStateDetached:
1702  // NOTE: gdb protocol doc looks like it should return $OK
1703  // when everything is running (i.e. no stopped result).
1704  return PacketResult::Success; // Ignore
1705 
1706  case eStateSuspended:
1707  case eStateStopped:
1708  case eStateCrashed: {
1709  assert(m_current_process != nullptr);
1711  // Make sure we set the current thread so g and p packets return the data
1712  // the gdb will expect.
1713  SetCurrentThreadID(tid);
1714  return SendStopReplyPacketForThread(tid);
1715  }
1716 
1717  case eStateInvalid:
1718  case eStateUnloaded:
1719  case eStateExited:
1721 
1722  default:
1723  LLDB_LOG(log, "pid {0}, current state reporting not handled: {1}",
1724  m_current_process->GetID(), process_state);
1725  break;
1726  }
1727 
1728  return SendErrorResponse(0);
1729 }
1730 
1733  StringExtractorGDBRemote &packet) {
1734  // Fail if we don't have a current process.
1735  if (!m_current_process ||
1737  return SendErrorResponse(68);
1738 
1739  // Ensure we have a thread.
1741  if (!thread)
1742  return SendErrorResponse(69);
1743 
1744  // Get the register context for the first thread.
1745  NativeRegisterContext &reg_context = thread->GetRegisterContext();
1746 
1747  // Parse out the register number from the request.
1748  packet.SetFilePos(strlen("qRegisterInfo"));
1749  const uint32_t reg_index =
1750  packet.GetHexMaxU32(false, std::numeric_limits<uint32_t>::max());
1751  if (reg_index == std::numeric_limits<uint32_t>::max())
1752  return SendErrorResponse(69);
1753 
1754  // Return the end of registers response if we've iterated one past the end of
1755  // the register set.
1756  if (reg_index >= reg_context.GetUserRegisterCount())
1757  return SendErrorResponse(69);
1758 
1759  const RegisterInfo *reg_info = reg_context.GetRegisterInfoAtIndex(reg_index);
1760  if (!reg_info)
1761  return SendErrorResponse(69);
1762 
1763  // Build the reginfos response.
1764  StreamGDBRemote response;
1765 
1766  response.PutCString("name:");
1767  response.PutCString(reg_info->name);
1768  response.PutChar(';');
1769 
1770  if (reg_info->alt_name && reg_info->alt_name[0]) {
1771  response.PutCString("alt-name:");
1772  response.PutCString(reg_info->alt_name);
1773  response.PutChar(';');
1774  }
1775 
1776  response.Printf("bitsize:%" PRIu32 ";", reg_info->byte_size * 8);
1777 
1778  if (!reg_context.RegisterOffsetIsDynamic())
1779  response.Printf("offset:%" PRIu32 ";", reg_info->byte_offset);
1780 
1781  llvm::StringRef encoding = GetEncodingNameOrEmpty(*reg_info);
1782  if (!encoding.empty())
1783  response << "encoding:" << encoding << ';';
1784 
1785  llvm::StringRef format = GetFormatNameOrEmpty(*reg_info);
1786  if (!format.empty())
1787  response << "format:" << format << ';';
1788 
1789  const char *const register_set_name =
1790  reg_context.GetRegisterSetNameForRegisterAtIndex(reg_index);
1791  if (register_set_name)
1792  response << "set:" << register_set_name << ';';
1793 
1794  if (reg_info->kinds[RegisterKind::eRegisterKindEHFrame] !=
1796  response.Printf("ehframe:%" PRIu32 ";",
1797  reg_info->kinds[RegisterKind::eRegisterKindEHFrame]);
1798 
1799  if (reg_info->kinds[RegisterKind::eRegisterKindDWARF] != LLDB_INVALID_REGNUM)
1800  response.Printf("dwarf:%" PRIu32 ";",
1801  reg_info->kinds[RegisterKind::eRegisterKindDWARF]);
1802 
1803  llvm::StringRef kind_generic = GetKindGenericOrEmpty(*reg_info);
1804  if (!kind_generic.empty())
1805  response << "generic:" << kind_generic << ';';
1806 
1807  if (reg_info->value_regs && reg_info->value_regs[0] != LLDB_INVALID_REGNUM) {
1808  response.PutCString("container-regs:");
1809  CollectRegNums(reg_info->value_regs, response, true);
1810  response.PutChar(';');
1811  }
1812 
1813  if (reg_info->invalidate_regs && reg_info->invalidate_regs[0]) {
1814  response.PutCString("invalidate-regs:");
1815  CollectRegNums(reg_info->invalidate_regs, response, true);
1816  response.PutChar(';');
1817  }
1818 
1819  return SendPacketNoLock(response.GetString());
1820 }
1821 
1824  StringExtractorGDBRemote &packet) {
1826 
1827  // Fail if we don't have a current process.
1828  if (!m_current_process ||
1830  LLDB_LOG(log, "no process ({0}), returning OK",
1831  m_current_process ? "invalid process id"
1832  : "null m_current_process");
1833  return SendOKResponse();
1834  }
1835 
1836  StreamGDBRemote response;
1837  response.PutChar('m');
1838 
1839  LLDB_LOG(log, "starting thread iteration");
1840  NativeThreadProtocol *thread;
1841  uint32_t thread_index;
1842  for (thread_index = 0,
1843  thread = m_current_process->GetThreadAtIndex(thread_index);
1844  thread; ++thread_index,
1845  thread = m_current_process->GetThreadAtIndex(thread_index)) {
1846  LLDB_LOG(log, "iterated thread {0}(tid={2})", thread_index,
1847  thread->GetID());
1848  if (thread_index > 0)
1849  response.PutChar(',');
1850  response.Printf("%" PRIx64, thread->GetID());
1851  }
1852 
1853  LLDB_LOG(log, "finished thread iteration");
1854  return SendPacketNoLock(response.GetString());
1855 }
1856 
1859  StringExtractorGDBRemote &packet) {
1860  // FIXME for now we return the full thread list in the initial packet and
1861  // always do nothing here.
1862  return SendPacketNoLock("l");
1863 }
1864 
1868 
1869  // Move past packet name.
1870  packet.SetFilePos(strlen("g"));
1871 
1872  // Get the thread to use.
1873  NativeThreadProtocol *thread = GetThreadFromSuffix(packet);
1874  if (!thread) {
1875  LLDB_LOG(log, "failed, no thread available");
1876  return SendErrorResponse(0x15);
1877  }
1878 
1879  // Get the thread's register context.
1880  NativeRegisterContext &reg_ctx = thread->GetRegisterContext();
1881 
1882  std::vector<uint8_t> regs_buffer;
1883  for (uint32_t reg_num = 0; reg_num < reg_ctx.GetUserRegisterCount();
1884  ++reg_num) {
1885  const RegisterInfo *reg_info = reg_ctx.GetRegisterInfoAtIndex(reg_num);
1886 
1887  if (reg_info == nullptr) {
1888  LLDB_LOG(log, "failed to get register info for register index {0}",
1889  reg_num);
1890  return SendErrorResponse(0x15);
1891  }
1892 
1893  if (reg_info->value_regs != nullptr)
1894  continue; // skip registers that are contained in other registers
1895 
1896  RegisterValue reg_value;
1897  Status error = reg_ctx.ReadRegister(reg_info, reg_value);
1898  if (error.Fail()) {
1899  LLDB_LOG(log, "failed to read register at index {0}", reg_num);
1900  return SendErrorResponse(0x15);
1901  }
1902 
1903  if (reg_info->byte_offset + reg_info->byte_size >= regs_buffer.size())
1904  // Resize the buffer to guarantee it can store the register offsetted
1905  // data.
1906  regs_buffer.resize(reg_info->byte_offset + reg_info->byte_size);
1907 
1908  // Copy the register offsetted data to the buffer.
1909  memcpy(regs_buffer.data() + reg_info->byte_offset, reg_value.GetBytes(),
1910  reg_info->byte_size);
1911  }
1912 
1913  // Write the response.
1914  StreamGDBRemote response;
1915  response.PutBytesAsRawHex8(regs_buffer.data(), regs_buffer.size());
1916 
1917  return SendPacketNoLock(response.GetString());
1918 }
1919 
1923 
1924  // Parse out the register number from the request.
1925  packet.SetFilePos(strlen("p"));
1926  const uint32_t reg_index =
1927  packet.GetHexMaxU32(false, std::numeric_limits<uint32_t>::max());
1928  if (reg_index == std::numeric_limits<uint32_t>::max()) {
1929  LLDB_LOGF(log,
1930  "GDBRemoteCommunicationServerLLGS::%s failed, could not "
1931  "parse register number from request \"%s\"",
1932  __FUNCTION__, packet.GetStringRef().data());
1933  return SendErrorResponse(0x15);
1934  }
1935 
1936  // Get the thread to use.
1937  NativeThreadProtocol *thread = GetThreadFromSuffix(packet);
1938  if (!thread) {
1939  LLDB_LOG(log, "failed, no thread available");
1940  return SendErrorResponse(0x15);
1941  }
1942 
1943  // Get the thread's register context.
1944  NativeRegisterContext &reg_context = thread->GetRegisterContext();
1945 
1946  // Return the end of registers response if we've iterated one past the end of
1947  // the register set.
1948  if (reg_index >= reg_context.GetUserRegisterCount()) {
1949  LLDB_LOGF(log,
1950  "GDBRemoteCommunicationServerLLGS::%s failed, requested "
1951  "register %" PRIu32 " beyond register count %" PRIu32,
1952  __FUNCTION__, reg_index, reg_context.GetUserRegisterCount());
1953  return SendErrorResponse(0x15);
1954  }
1955 
1956  const RegisterInfo *reg_info = reg_context.GetRegisterInfoAtIndex(reg_index);
1957  if (!reg_info) {
1958  LLDB_LOGF(log,
1959  "GDBRemoteCommunicationServerLLGS::%s failed, requested "
1960  "register %" PRIu32 " returned NULL",
1961  __FUNCTION__, reg_index);
1962  return SendErrorResponse(0x15);
1963  }
1964 
1965  // Build the reginfos response.
1966  StreamGDBRemote response;
1967 
1968  // Retrieve the value
1969  RegisterValue reg_value;
1970  Status error = reg_context.ReadRegister(reg_info, reg_value);
1971  if (error.Fail()) {
1972  LLDB_LOGF(log,
1973  "GDBRemoteCommunicationServerLLGS::%s failed, read of "
1974  "requested register %" PRIu32 " (%s) failed: %s",
1975  __FUNCTION__, reg_index, reg_info->name, error.AsCString());
1976  return SendErrorResponse(0x15);
1977  }
1978 
1979  const uint8_t *const data =
1980  static_cast<const uint8_t *>(reg_value.GetBytes());
1981  if (!data) {
1982  LLDB_LOGF(log,
1983  "GDBRemoteCommunicationServerLLGS::%s failed to get data "
1984  "bytes from requested register %" PRIu32,
1985  __FUNCTION__, reg_index);
1986  return SendErrorResponse(0x15);
1987  }
1988 
1989  // FIXME flip as needed to get data in big/little endian format for this host.
1990  for (uint32_t i = 0; i < reg_value.GetByteSize(); ++i)
1991  response.PutHex8(data[i]);
1992 
1993  return SendPacketNoLock(response.GetString());
1994 }
1995 
1999 
2000  // Ensure there is more content.
2001  if (packet.GetBytesLeft() < 1)
2002  return SendIllFormedResponse(packet, "Empty P packet");
2003 
2004  // Parse out the register number from the request.
2005  packet.SetFilePos(strlen("P"));
2006  const uint32_t reg_index =
2007  packet.GetHexMaxU32(false, std::numeric_limits<uint32_t>::max());
2008  if (reg_index == std::numeric_limits<uint32_t>::max()) {
2009  LLDB_LOGF(log,
2010  "GDBRemoteCommunicationServerLLGS::%s failed, could not "
2011  "parse register number from request \"%s\"",
2012  __FUNCTION__, packet.GetStringRef().data());
2013  return SendErrorResponse(0x29);
2014  }
2015 
2016  // Note debugserver would send an E30 here.
2017  if ((packet.GetBytesLeft() < 1) || (packet.GetChar() != '='))
2018  return SendIllFormedResponse(
2019  packet, "P packet missing '=' char after register number");
2020 
2021  // Parse out the value.
2022  uint8_t reg_bytes[RegisterValue::kMaxRegisterByteSize];
2023  size_t reg_size = packet.GetHexBytesAvail(reg_bytes);
2024 
2025  // Get the thread to use.
2026  NativeThreadProtocol *thread = GetThreadFromSuffix(packet);
2027  if (!thread) {
2028  LLDB_LOGF(log,
2029  "GDBRemoteCommunicationServerLLGS::%s failed, no thread "
2030  "available (thread index 0)",
2031  __FUNCTION__);
2032  return SendErrorResponse(0x28);
2033  }
2034 
2035  // Get the thread's register context.
2036  NativeRegisterContext &reg_context = thread->GetRegisterContext();
2037  const RegisterInfo *reg_info = reg_context.GetRegisterInfoAtIndex(reg_index);
2038  if (!reg_info) {
2039  LLDB_LOGF(log,
2040  "GDBRemoteCommunicationServerLLGS::%s failed, requested "
2041  "register %" PRIu32 " returned NULL",
2042  __FUNCTION__, reg_index);
2043  return SendErrorResponse(0x48);
2044  }
2045 
2046  // Return the end of registers response if we've iterated one past the end of
2047  // the register set.
2048  if (reg_index >= reg_context.GetUserRegisterCount()) {
2049  LLDB_LOGF(log,
2050  "GDBRemoteCommunicationServerLLGS::%s failed, requested "
2051  "register %" PRIu32 " beyond register count %" PRIu32,
2052  __FUNCTION__, reg_index, reg_context.GetUserRegisterCount());
2053  return SendErrorResponse(0x47);
2054  }
2055 
2056  if (reg_size != reg_info->byte_size)
2057  return SendIllFormedResponse(packet, "P packet register size is incorrect");
2058 
2059  // Build the reginfos response.
2060  StreamGDBRemote response;
2061 
2062  RegisterValue reg_value(makeArrayRef(reg_bytes, reg_size),
2064  Status error = reg_context.WriteRegister(reg_info, reg_value);
2065  if (error.Fail()) {
2066  LLDB_LOGF(log,
2067  "GDBRemoteCommunicationServerLLGS::%s failed, write of "
2068  "requested register %" PRIu32 " (%s) failed: %s",
2069  __FUNCTION__, reg_index, reg_info->name, error.AsCString());
2070  return SendErrorResponse(0x32);
2071  }
2072 
2073  return SendOKResponse();
2074 }
2075 
2079 
2080  // Parse out which variant of $H is requested.
2081  packet.SetFilePos(strlen("H"));
2082  if (packet.GetBytesLeft() < 1) {
2083  LLDB_LOGF(log,
2084  "GDBRemoteCommunicationServerLLGS::%s failed, H command "
2085  "missing {g,c} variant",
2086  __FUNCTION__);
2087  return SendIllFormedResponse(packet, "H command missing {g,c} variant");
2088  }
2089 
2090  const char h_variant = packet.GetChar();
2091  NativeProcessProtocol *default_process;
2092  switch (h_variant) {
2093  case 'g':
2094  default_process = m_current_process;
2095  break;
2096 
2097  case 'c':
2098  default_process = m_continue_process;
2099  break;
2100 
2101  default:
2102  LLDB_LOGF(
2103  log,
2104  "GDBRemoteCommunicationServerLLGS::%s failed, invalid $H variant %c",
2105  __FUNCTION__, h_variant);
2106  return SendIllFormedResponse(packet,
2107  "H variant unsupported, should be c or g");
2108  }
2109 
2110  // Parse out the thread number.
2111  auto pid_tid = packet.GetPidTid(default_process ? default_process->GetID()
2113  if (!pid_tid)
2114  return SendErrorResponse(llvm::make_error<StringError>(
2115  inconvertibleErrorCode(), "Malformed thread-id"));
2116 
2117  lldb::pid_t pid = pid_tid->first;
2118  lldb::tid_t tid = pid_tid->second;
2119 
2121  return SendUnimplementedResponse("Selecting all processes not supported");
2122  if (pid == LLDB_INVALID_PROCESS_ID)
2123  return SendErrorResponse(llvm::make_error<StringError>(
2124  inconvertibleErrorCode(), "No current process and no PID provided"));
2125 
2126  // Check the process ID and find respective process instance.
2127  auto new_process_it = m_debugged_processes.find(pid);
2128  if (new_process_it == m_debugged_processes.end())
2129  return SendErrorResponse(llvm::make_error<StringError>(
2130  inconvertibleErrorCode(),
2131  llvm::formatv("No process with PID {0} debugged", pid)));
2132 
2133  // Ensure we have the given thread when not specifying -1 (all threads) or 0
2134  // (any thread).
2135  if (tid != LLDB_INVALID_THREAD_ID && tid != 0) {
2136  NativeThreadProtocol *thread = new_process_it->second->GetThreadByID(tid);
2137  if (!thread) {
2138  LLDB_LOGF(log,
2139  "GDBRemoteCommunicationServerLLGS::%s failed, tid %" PRIu64
2140  " not found",
2141  __FUNCTION__, tid);
2142  return SendErrorResponse(0x15);
2143  }
2144  }
2145 
2146  // Now switch the given process and thread type.
2147  switch (h_variant) {
2148  case 'g':
2149  m_current_process = new_process_it->second.get();
2150  SetCurrentThreadID(tid);
2151  break;
2152 
2153  case 'c':
2154  m_continue_process = new_process_it->second.get();
2155  SetContinueThreadID(tid);
2156  break;
2157 
2158  default:
2159  assert(false && "unsupported $H variant - shouldn't get here");
2160  return SendIllFormedResponse(packet,
2161  "H variant unsupported, should be c or g");
2162  }
2163 
2164  return SendOKResponse();
2165 }
2166 
2170 
2171  // Fail if we don't have a current process.
2172  if (!m_current_process ||
2174  LLDB_LOGF(
2175  log,
2176  "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
2177  __FUNCTION__);
2178  return SendErrorResponse(0x15);
2179  }
2180 
2181  packet.SetFilePos(::strlen("I"));
2182  uint8_t tmp[4096];
2183  for (;;) {
2184  size_t read = packet.GetHexBytesAvail(tmp);
2185  if (read == 0) {
2186  break;
2187  }
2188  // write directly to stdin *this might block if stdin buffer is full*
2189  // TODO: enqueue this block in circular buffer and send window size to
2190  // remote host
2191  ConnectionStatus status;
2192  Status error;
2193  m_stdio_communication.Write(tmp, read, status, &error);
2194  if (error.Fail()) {
2195  return SendErrorResponse(0x15);
2196  }
2197  }
2198 
2199  return SendOKResponse();
2200 }
2201 
2204  StringExtractorGDBRemote &packet) {
2206 
2207  // Fail if we don't have a current process.
2208  if (!m_current_process ||
2210  LLDB_LOG(log, "failed, no process available");
2211  return SendErrorResponse(0x15);
2212  }
2213 
2214  // Interrupt the process.
2216  if (error.Fail()) {
2217  LLDB_LOG(log, "failed for process {0}: {1}", m_current_process->GetID(),
2218  error);
2219  return SendErrorResponse(GDBRemoteServerError::eErrorResume);
2220  }
2221 
2222  LLDB_LOG(log, "stopped process {0}", m_current_process->GetID());
2223 
2224  // No response required from stop all.
2225  return PacketResult::Success;
2226 }
2227 
2230  StringExtractorGDBRemote &packet) {
2232 
2233  if (!m_current_process ||
2235  LLDB_LOGF(
2236  log,
2237  "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
2238  __FUNCTION__);
2239  return SendErrorResponse(0x15);
2240  }
2241 
2242  // Parse out the memory address.
2243  packet.SetFilePos(strlen("m"));
2244  if (packet.GetBytesLeft() < 1)
2245  return SendIllFormedResponse(packet, "Too short m packet");
2246 
2247  // Read the address. Punting on validation.
2248  // FIXME replace with Hex U64 read with no default value that fails on failed
2249  // read.
2250  const lldb::addr_t read_addr = packet.GetHexMaxU64(false, 0);
2251 
2252  // Validate comma.
2253  if ((packet.GetBytesLeft() < 1) || (packet.GetChar() != ','))
2254  return SendIllFormedResponse(packet, "Comma sep missing in m packet");
2255 
2256  // Get # bytes to read.
2257  if (packet.GetBytesLeft() < 1)
2258  return SendIllFormedResponse(packet, "Length missing in m packet");
2259 
2260  const uint64_t byte_count = packet.GetHexMaxU64(false, 0);
2261  if (byte_count == 0) {
2262  LLDB_LOGF(log,
2263  "GDBRemoteCommunicationServerLLGS::%s nothing to read: "
2264  "zero-length packet",
2265  __FUNCTION__);
2266  return SendOKResponse();
2267  }
2268 
2269  // Allocate the response buffer.
2270  std::string buf(byte_count, '\0');
2271  if (buf.empty())
2272  return SendErrorResponse(0x78);
2273 
2274  // Retrieve the process memory.
2275  size_t bytes_read = 0;
2277  read_addr, &buf[0], byte_count, bytes_read);
2278  if (error.Fail()) {
2279  LLDB_LOGF(log,
2280  "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
2281  " mem 0x%" PRIx64 ": failed to read. Error: %s",
2282  __FUNCTION__, m_current_process->GetID(), read_addr,
2283  error.AsCString());
2284  return SendErrorResponse(0x08);
2285  }
2286 
2287  if (bytes_read == 0) {
2288  LLDB_LOGF(log,
2289  "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
2290  " mem 0x%" PRIx64 ": read 0 of %" PRIu64 " requested bytes",
2291  __FUNCTION__, m_current_process->GetID(), read_addr, byte_count);
2292  return SendErrorResponse(0x08);
2293  }
2294 
2295  StreamGDBRemote response;
2296  packet.SetFilePos(0);
2297  char kind = packet.GetChar('?');
2298  if (kind == 'x')
2299  response.PutEscapedBytes(buf.data(), byte_count);
2300  else {
2301  assert(kind == 'm');
2302  for (size_t i = 0; i < bytes_read; ++i)
2303  response.PutHex8(buf[i]);
2304  }
2305 
2306  return SendPacketNoLock(response.GetString());
2307 }
2308 
2312 
2313  if (!m_current_process ||
2315  LLDB_LOGF(
2316  log,
2317  "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
2318  __FUNCTION__);
2319  return SendErrorResponse(0x15);
2320  }
2321 
2322  // Parse out the memory address.
2323  packet.SetFilePos(strlen("_M"));
2324  if (packet.GetBytesLeft() < 1)
2325  return SendIllFormedResponse(packet, "Too short _M packet");
2326 
2327  const lldb::addr_t size = packet.GetHexMaxU64(false, LLDB_INVALID_ADDRESS);
2328  if (size == LLDB_INVALID_ADDRESS)
2329  return SendIllFormedResponse(packet, "Address not valid");
2330  if (packet.GetChar() != ',')
2331  return SendIllFormedResponse(packet, "Bad packet");
2332  Permissions perms = {};
2333  while (packet.GetBytesLeft() > 0) {
2334  switch (packet.GetChar()) {
2335  case 'r':
2336  perms |= ePermissionsReadable;
2337  break;
2338  case 'w':
2339  perms |= ePermissionsWritable;
2340  break;
2341  case 'x':
2342  perms |= ePermissionsExecutable;
2343  break;
2344  default:
2345  return SendIllFormedResponse(packet, "Bad permissions");
2346  }
2347  }
2348 
2349  llvm::Expected<addr_t> addr = m_current_process->AllocateMemory(size, perms);
2350  if (!addr)
2351  return SendErrorResponse(addr.takeError());
2352 
2353  StreamGDBRemote response;
2354  response.PutHex64(*addr);
2355  return SendPacketNoLock(response.GetString());
2356 }
2357 
2361 
2362  if (!m_current_process ||
2364  LLDB_LOGF(
2365  log,
2366  "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
2367  __FUNCTION__);
2368  return SendErrorResponse(0x15);
2369  }
2370 
2371  // Parse out the memory address.
2372  packet.SetFilePos(strlen("_m"));
2373  if (packet.GetBytesLeft() < 1)
2374  return SendIllFormedResponse(packet, "Too short m packet");
2375 
2376  const lldb::addr_t addr = packet.GetHexMaxU64(false, LLDB_INVALID_ADDRESS);
2377  if (addr == LLDB_INVALID_ADDRESS)
2378  return SendIllFormedResponse(packet, "Address not valid");
2379 
2381  return SendErrorResponse(std::move(Err));
2382 
2383  return SendOKResponse();
2384 }
2385 
2389 
2390  if (!m_current_process ||
2392  LLDB_LOGF(
2393  log,
2394  "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
2395  __FUNCTION__);
2396  return SendErrorResponse(0x15);
2397  }
2398 
2399  // Parse out the memory address.
2400  packet.SetFilePos(strlen("M"));
2401  if (packet.GetBytesLeft() < 1)
2402  return SendIllFormedResponse(packet, "Too short M packet");
2403 
2404  // Read the address. Punting on validation.
2405  // FIXME replace with Hex U64 read with no default value that fails on failed
2406  // read.
2407  const lldb::addr_t write_addr = packet.GetHexMaxU64(false, 0);
2408 
2409  // Validate comma.
2410  if ((packet.GetBytesLeft() < 1) || (packet.GetChar() != ','))
2411  return SendIllFormedResponse(packet, "Comma sep missing in M packet");
2412 
2413  // Get # bytes to read.
2414  if (packet.GetBytesLeft() < 1)
2415  return SendIllFormedResponse(packet, "Length missing in M packet");
2416 
2417  const uint64_t byte_count = packet.GetHexMaxU64(false, 0);
2418  if (byte_count == 0) {
2419  LLDB_LOG(log, "nothing to write: zero-length packet");
2420  return PacketResult::Success;
2421  }
2422 
2423  // Validate colon.
2424  if ((packet.GetBytesLeft() < 1) || (packet.GetChar() != ':'))
2425  return SendIllFormedResponse(
2426  packet, "Comma sep missing in M packet after byte length");
2427 
2428  // Allocate the conversion buffer.
2429  std::vector<uint8_t> buf(byte_count, 0);
2430  if (buf.empty())
2431  return SendErrorResponse(0x78);
2432 
2433  // Convert the hex memory write contents to bytes.
2434  StreamGDBRemote response;
2435  const uint64_t convert_count = packet.GetHexBytes(buf, 0);
2436  if (convert_count != byte_count) {
2437  LLDB_LOG(log,
2438  "pid {0} mem {1:x}: asked to write {2} bytes, but only found {3} "
2439  "to convert.",
2440  m_current_process->GetID(), write_addr, byte_count, convert_count);
2441  return SendIllFormedResponse(packet, "M content byte length specified did "
2442  "not match hex-encoded content "
2443  "length");
2444  }
2445 
2446  // Write the process memory.
2447  size_t bytes_written = 0;
2448  Status error = m_current_process->WriteMemory(write_addr, &buf[0], byte_count,
2449  bytes_written);
2450  if (error.Fail()) {
2451  LLDB_LOG(log, "pid {0} mem {1:x}: failed to write. Error: {2}",
2452  m_current_process->GetID(), write_addr, error);
2453  return SendErrorResponse(0x09);
2454  }
2455 
2456  if (bytes_written == 0) {
2457  LLDB_LOG(log, "pid {0} mem {1:x}: wrote 0 of {2} requested bytes",
2458  m_current_process->GetID(), write_addr, byte_count);
2459  return SendErrorResponse(0x09);
2460  }
2461 
2462  return SendOKResponse();
2463 }
2464 
2467  StringExtractorGDBRemote &packet) {
2469 
2470  // Currently only the NativeProcessProtocol knows if it can handle a
2471  // qMemoryRegionInfoSupported request, but we're not guaranteed to be
2472  // attached to a process. For now we'll assume the client only asks this
2473  // when a process is being debugged.
2474 
2475  // Ensure we have a process running; otherwise, we can't figure this out
2476  // since we won't have a NativeProcessProtocol.
2477  if (!m_current_process ||
2479  LLDB_LOGF(
2480  log,
2481  "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
2482  __FUNCTION__);
2483  return SendErrorResponse(0x15);
2484  }
2485 
2486  // Test if we can get any region back when asking for the region around NULL.
2487  MemoryRegionInfo region_info;
2488  const Status error = m_current_process->GetMemoryRegionInfo(0, region_info);
2489  if (error.Fail()) {
2490  // We don't support memory region info collection for this
2491  // NativeProcessProtocol.
2492  return SendUnimplementedResponse("");
2493  }
2494 
2495  return SendOKResponse();
2496 }
2497 
2500  StringExtractorGDBRemote &packet) {
2502 
2503  // Ensure we have a process.
2504  if (!m_current_process ||
2506  LLDB_LOGF(
2507  log,
2508  "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
2509  __FUNCTION__);
2510  return SendErrorResponse(0x15);
2511  }
2512 
2513  // Parse out the memory address.
2514  packet.SetFilePos(strlen("qMemoryRegionInfo:"));
2515  if (packet.GetBytesLeft() < 1)
2516  return SendIllFormedResponse(packet, "Too short qMemoryRegionInfo: packet");
2517 
2518  // Read the address. Punting on validation.
2519  const lldb::addr_t read_addr = packet.GetHexMaxU64(false, 0);
2520 
2521  StreamGDBRemote response;
2522 
2523  // Get the memory region info for the target address.
2524  MemoryRegionInfo region_info;
2525  const Status error =
2526  m_current_process->GetMemoryRegionInfo(read_addr, region_info);
2527  if (error.Fail()) {
2528  // Return the error message.
2529 
2530  response.PutCString("error:");
2531  response.PutStringAsRawHex8(error.AsCString());
2532  response.PutChar(';');
2533  } else {
2534  // Range start and size.
2535  response.Printf("start:%" PRIx64 ";size:%" PRIx64 ";",
2536  region_info.GetRange().GetRangeBase(),
2537  region_info.GetRange().GetByteSize());
2538 
2539  // Permissions.
2540  if (region_info.GetReadable() || region_info.GetWritable() ||
2541  region_info.GetExecutable()) {
2542  // Write permissions info.
2543  response.PutCString("permissions:");
2544 
2545  if (region_info.GetReadable())
2546  response.PutChar('r');
2547  if (region_info.GetWritable())
2548  response.PutChar('w');
2549  if (region_info.GetExecutable())
2550  response.PutChar('x');
2551 
2552  response.PutChar(';');
2553  }
2554 
2555  // Flags
2556  MemoryRegionInfo::OptionalBool memory_tagged =
2557  region_info.GetMemoryTagged();
2558  if (memory_tagged != MemoryRegionInfo::eDontKnow) {
2559  response.PutCString("flags:");
2560  if (memory_tagged == MemoryRegionInfo::eYes) {
2561  response.PutCString("mt");
2562  }
2563  response.PutChar(';');
2564  }
2565 
2566  // Name
2567  ConstString name = region_info.GetName();
2568  if (name) {
2569  response.PutCString("name:");
2570  response.PutStringAsRawHex8(name.GetStringRef());
2571  response.PutChar(';');
2572  }
2573  }
2574 
2575  return SendPacketNoLock(response.GetString());
2576 }
2577 
2580  // Ensure we have a process.
2581  if (!m_current_process ||
2584  LLDB_LOG(log, "failed, no process available");
2585  return SendErrorResponse(0x15);
2586  }
2587 
2588  // Parse out software or hardware breakpoint or watchpoint requested.
2589  packet.SetFilePos(strlen("Z"));
2590  if (packet.GetBytesLeft() < 1)
2591  return SendIllFormedResponse(
2592  packet, "Too short Z packet, missing software/hardware specifier");
2593 
2594  bool want_breakpoint = true;
2595  bool want_hardware = false;
2596  uint32_t watch_flags = 0;
2597 
2598  const GDBStoppointType stoppoint_type =
2600  switch (stoppoint_type) {
2601  case eBreakpointSoftware:
2602  want_hardware = false;
2603  want_breakpoint = true;
2604  break;
2605  case eBreakpointHardware:
2606  want_hardware = true;
2607  want_breakpoint = true;
2608  break;
2609  case eWatchpointWrite:
2610  watch_flags = 1;
2611  want_hardware = true;
2612  want_breakpoint = false;
2613  break;
2614  case eWatchpointRead:
2615  watch_flags = 2;
2616  want_hardware = true;
2617  want_breakpoint = false;
2618  break;
2619  case eWatchpointReadWrite:
2620  watch_flags = 3;
2621  want_hardware = true;
2622  want_breakpoint = false;
2623  break;
2624  case eStoppointInvalid:
2625  return SendIllFormedResponse(
2626  packet, "Z packet had invalid software/hardware specifier");
2627  }
2628 
2629  if ((packet.GetBytesLeft() < 1) || packet.GetChar() != ',')
2630  return SendIllFormedResponse(
2631  packet, "Malformed Z packet, expecting comma after stoppoint type");
2632 
2633  // Parse out the stoppoint address.
2634  if (packet.GetBytesLeft() < 1)
2635  return SendIllFormedResponse(packet, "Too short Z packet, missing address");
2636  const lldb::addr_t addr = packet.GetHexMaxU64(false, 0);
2637 
2638  if ((packet.GetBytesLeft() < 1) || packet.GetChar() != ',')
2639  return SendIllFormedResponse(
2640  packet, "Malformed Z packet, expecting comma after address");
2641 
2642  // Parse out the stoppoint size (i.e. size hint for opcode size).
2643  const uint32_t size =
2644  packet.GetHexMaxU32(false, std::numeric_limits<uint32_t>::max());
2645  if (size == std::numeric_limits<uint32_t>::max())
2646  return SendIllFormedResponse(
2647  packet, "Malformed Z packet, failed to parse size argument");
2648 
2649  if (want_breakpoint) {
2650  // Try to set the breakpoint.
2651  const Status error =
2652  m_current_process->SetBreakpoint(addr, size, want_hardware);
2653  if (error.Success())
2654  return SendOKResponse();
2656  LLDB_LOG(log, "pid {0} failed to set breakpoint: {1}",
2658  return SendErrorResponse(0x09);
2659  } else {
2660  // Try to set the watchpoint.
2662  addr, size, watch_flags, want_hardware);
2663  if (error.Success())
2664  return SendOKResponse();
2666  LLDB_LOG(log, "pid {0} failed to set watchpoint: {1}",
2668  return SendErrorResponse(0x09);
2669  }
2670 }
2671 
2674  // Ensure we have a process.
2675  if (!m_current_process ||
2678  LLDB_LOG(log, "failed, no process available");
2679  return SendErrorResponse(0x15);
2680  }
2681 
2682  // Parse out software or hardware breakpoint or watchpoint requested.
2683  packet.SetFilePos(strlen("z"));
2684  if (packet.GetBytesLeft() < 1)
2685  return SendIllFormedResponse(
2686  packet, "Too short z packet, missing software/hardware specifier");
2687 
2688  bool want_breakpoint = true;
2689  bool want_hardware = false;
2690 
2691  const GDBStoppointType stoppoint_type =
2693  switch (stoppoint_type) {
2694  case eBreakpointHardware:
2695  want_breakpoint = true;
2696  want_hardware = true;
2697  break;
2698  case eBreakpointSoftware:
2699  want_breakpoint = true;
2700  break;
2701  case eWatchpointWrite:
2702  want_breakpoint = false;
2703  break;
2704  case eWatchpointRead:
2705  want_breakpoint = false;
2706  break;
2707  case eWatchpointReadWrite:
2708  want_breakpoint = false;
2709  break;
2710  default:
2711  return SendIllFormedResponse(
2712  packet, "z packet had invalid software/hardware specifier");
2713  }
2714 
2715  if ((packet.GetBytesLeft() < 1) || packet.GetChar() != ',')
2716  return SendIllFormedResponse(
2717  packet, "Malformed z packet, expecting comma after stoppoint type");
2718 
2719  // Parse out the stoppoint address.
2720  if (packet.GetBytesLeft() < 1)
2721  return SendIllFormedResponse(packet, "Too short z packet, missing address");
2722  const lldb::addr_t addr = packet.GetHexMaxU64(false, 0);
2723 
2724  if ((packet.GetBytesLeft() < 1) || packet.GetChar() != ',')
2725  return SendIllFormedResponse(
2726  packet, "Malformed z packet, expecting comma after address");
2727 
2728  /*
2729  // Parse out the stoppoint size (i.e. size hint for opcode size).
2730  const uint32_t size = packet.GetHexMaxU32 (false,
2731  std::numeric_limits<uint32_t>::max ());
2732  if (size == std::numeric_limits<uint32_t>::max ())
2733  return SendIllFormedResponse(packet, "Malformed z packet, failed to parse
2734  size argument");
2735  */
2736 
2737  if (want_breakpoint) {
2738  // Try to clear the breakpoint.
2739  const Status error =
2740  m_current_process->RemoveBreakpoint(addr, want_hardware);
2741  if (error.Success())
2742  return SendOKResponse();
2744  LLDB_LOG(log, "pid {0} failed to remove breakpoint: {1}",
2746  return SendErrorResponse(0x09);
2747  } else {
2748  // Try to clear the watchpoint.
2750  if (error.Success())
2751  return SendOKResponse();
2753  LLDB_LOG(log, "pid {0} failed to remove watchpoint: {1}",
2755  return SendErrorResponse(0x09);
2756  }
2757 }
2758 
2762 
2763  // Ensure we have a process.
2764  if (!m_continue_process ||
2766  LLDB_LOGF(
2767  log,
2768  "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
2769  __FUNCTION__);
2770  return SendErrorResponse(0x32);
2771  }
2772 
2773  // We first try to use a continue thread id. If any one or any all set, use
2774  // the current thread. Bail out if we don't have a thread id.
2776  if (tid == 0 || tid == LLDB_INVALID_THREAD_ID)
2777  tid = GetCurrentThreadID();
2778  if (tid == LLDB_INVALID_THREAD_ID)
2779  return SendErrorResponse(0x33);
2780 
2781  // Double check that we have such a thread.
2782  // TODO investigate: on MacOSX we might need to do an UpdateThreads () here.
2784  if (!thread)
2785  return SendErrorResponse(0x33);
2786 
2787  // Create the step action for the given thread.
2789 
2790  // Setup the actions list.
2791  ResumeActionList actions;
2792  actions.Append(action);
2793 
2794  // All other threads stop while we're single stepping a thread.
2796  Status error = m_continue_process->Resume(actions);
2797  if (error.Fail()) {
2798  LLDB_LOGF(log,
2799  "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
2800  " tid %" PRIu64 " Resume() failed with error: %s",
2801  __FUNCTION__, m_continue_process->GetID(), tid,
2802  error.AsCString());
2803  return SendErrorResponse(0x49);
2804  }
2805 
2806  // No response here - the stop or exit will come from the resulting action.
2807  return PacketResult::Success;
2808 }
2809 
2810 llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
2812  // Ensure we have a thread.
2814  if (!thread)
2815  return llvm::createStringError(llvm::inconvertibleErrorCode(),
2816  "No thread available");
2817 
2819  // Get the register context for the first thread.
2820  NativeRegisterContext &reg_context = thread->GetRegisterContext();
2821 
2822  StreamString response;
2823 
2824  response.Printf("<?xml version=\"1.0\"?>");
2825  response.Printf("<target version=\"1.0\">");
2826 
2827  response.Printf("<architecture>%s</architecture>",
2829  .GetTriple()
2830  .getArchName()
2831  .str()
2832  .c_str());
2833 
2834  response.Printf("<feature>");
2835 
2836  const int registers_count = reg_context.GetUserRegisterCount();
2837  for (int reg_index = 0; reg_index < registers_count; reg_index++) {
2838  const RegisterInfo *reg_info =
2839  reg_context.GetRegisterInfoAtIndex(reg_index);
2840 
2841  if (!reg_info) {
2842  LLDB_LOGF(log,
2843  "%s failed to get register info for register index %" PRIu32,
2844  "target.xml", reg_index);
2845  continue;
2846  }
2847 
2848  response.Printf("<reg name=\"%s\" bitsize=\"%" PRIu32 "\" regnum=\"%d\" ",
2849  reg_info->name, reg_info->byte_size * 8, reg_index);
2850 
2851  if (!reg_context.RegisterOffsetIsDynamic())
2852  response.Printf("offset=\"%" PRIu32 "\" ", reg_info->byte_offset);
2853 
2854  if (reg_info->alt_name && reg_info->alt_name[0])
2855  response.Printf("altname=\"%s\" ", reg_info->alt_name);
2856 
2857  llvm::StringRef encoding = GetEncodingNameOrEmpty(*reg_info);
2858  if (!encoding.empty())
2859  response << "encoding=\"" << encoding << "\" ";
2860 
2861  llvm::StringRef format = GetFormatNameOrEmpty(*reg_info);
2862  if (!format.empty())
2863  response << "format=\"" << format << "\" ";
2864 
2865  const char *const register_set_name =
2866  reg_context.GetRegisterSetNameForRegisterAtIndex(reg_index);
2867  if (register_set_name)
2868  response << "group=\"" << register_set_name << "\" ";
2869 
2870  if (reg_info->kinds[RegisterKind::eRegisterKindEHFrame] !=
2872  response.Printf("ehframe_regnum=\"%" PRIu32 "\" ",
2873  reg_info->kinds[RegisterKind::eRegisterKindEHFrame]);
2874 
2875  if (reg_info->kinds[RegisterKind::eRegisterKindDWARF] !=
2877  response.Printf("dwarf_regnum=\"%" PRIu32 "\" ",
2878  reg_info->kinds[RegisterKind::eRegisterKindDWARF]);
2879 
2880  llvm::StringRef kind_generic = GetKindGenericOrEmpty(*reg_info);
2881  if (!kind_generic.empty())
2882  response << "generic=\"" << kind_generic << "\" ";
2883 
2884  if (reg_info->value_regs &&
2885  reg_info->value_regs[0] != LLDB_INVALID_REGNUM) {
2886  response.PutCString("value_regnums=\"");
2887  CollectRegNums(reg_info->value_regs, response, false);
2888  response.Printf("\" ");
2889  }
2890 
2891  if (reg_info->invalidate_regs && reg_info->invalidate_regs[0]) {
2892  response.PutCString("invalidate_regnums=\"");
2893  CollectRegNums(reg_info->invalidate_regs, response, false);
2894  response.Printf("\" ");
2895  }
2896 
2897  response.Printf("/>");
2898  }
2899 
2900  response.Printf("</feature>");
2901  response.Printf("</target>");
2902  return MemoryBuffer::getMemBufferCopy(response.GetString(), "target.xml");
2903 }
2904 
2905 llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
2907  llvm::StringRef annex) {
2908  // Make sure we have a valid process.
2909  if (!m_current_process ||
2911  return llvm::createStringError(llvm::inconvertibleErrorCode(),
2912  "No process available");
2913  }
2914 
2915  if (object == "auxv") {
2916  // Grab the auxv data.
2917  auto buffer_or_error = m_current_process->GetAuxvData();
2918  if (!buffer_or_error)
2919  return llvm::errorCodeToError(buffer_or_error.getError());
2920  return std::move(*buffer_or_error);
2921  }
2922 
2923  if (object == "siginfo") {
2925  if (!thread)
2926  return llvm::createStringError(llvm::inconvertibleErrorCode(),
2927  "no current thread");
2928 
2929  auto buffer_or_error = thread->GetSiginfo();
2930  if (!buffer_or_error)
2931  return buffer_or_error.takeError();
2932  return std::move(*buffer_or_error);
2933  }
2934 
2935  if (object == "libraries-svr4") {
2936  auto library_list = m_current_process->GetLoadedSVR4Libraries();
2937  if (!library_list)
2938  return library_list.takeError();
2939 
2940  StreamString response;
2941  response.Printf("<library-list-svr4 version=\"1.0\">");
2942  for (auto const &library : *library_list) {
2943  response.Printf("<library name=\"%s\" ",
2944  XMLEncodeAttributeValue(library.name.c_str()).c_str());
2945  response.Printf("lm=\"0x%" PRIx64 "\" ", library.link_map);
2946  response.Printf("l_addr=\"0x%" PRIx64 "\" ", library.base_addr);
2947  response.Printf("l_ld=\"0x%" PRIx64 "\" />", library.ld_addr);
2948  }
2949  response.Printf("</library-list-svr4>");
2950  return MemoryBuffer::getMemBufferCopy(response.GetString(), __FUNCTION__);
2951  }
2952 
2953  if (object == "features" && annex == "target.xml")
2954  return BuildTargetXml();
2955 
2956  return llvm::make_error<UnimplementedError>();
2957 }
2958 
2961  StringExtractorGDBRemote &packet) {
2962  SmallVector<StringRef, 5> fields;
2963  // The packet format is "qXfer:<object>:<action>:<annex>:offset,length"
2964  StringRef(packet.GetStringRef()).split(fields, ':', 4);
2965  if (fields.size() != 5)
2966  return SendIllFormedResponse(packet, "malformed qXfer packet");
2967  StringRef &xfer_object = fields[1];
2968  StringRef &xfer_action = fields[2];
2969  StringRef &xfer_annex = fields[3];
2970  StringExtractor offset_data(fields[4]);
2971  if (xfer_action != "read")
2972  return SendUnimplementedResponse("qXfer action not supported");
2973  // Parse offset.
2974  const uint64_t xfer_offset =
2975  offset_data.GetHexMaxU64(false, std::numeric_limits<uint64_t>::max());
2976  if (xfer_offset == std::numeric_limits<uint64_t>::max())
2977  return SendIllFormedResponse(packet, "qXfer packet missing offset");
2978  // Parse out comma.
2979  if (offset_data.GetChar() != ',')
2980  return SendIllFormedResponse(packet,
2981  "qXfer packet missing comma after offset");
2982  // Parse out the length.
2983  const uint64_t xfer_length =
2984  offset_data.GetHexMaxU64(false, std::numeric_limits<uint64_t>::max());
2985  if (xfer_length == std::numeric_limits<uint64_t>::max())
2986  return SendIllFormedResponse(packet, "qXfer packet missing length");
2987 
2988  // Get a previously constructed buffer if it exists or create it now.
2989  std::string buffer_key = (xfer_object + xfer_action + xfer_annex).str();
2990  auto buffer_it = m_xfer_buffer_map.find(buffer_key);
2991  if (buffer_it == m_xfer_buffer_map.end()) {
2992  auto buffer_up = ReadXferObject(xfer_object, xfer_annex);
2993  if (!buffer_up)
2994  return SendErrorResponse(buffer_up.takeError());
2995  buffer_it = m_xfer_buffer_map
2996  .insert(std::make_pair(buffer_key, std::move(*buffer_up)))
2997  .first;
2998  }
2999 
3000  // Send back the response
3001  StreamGDBRemote response;
3002  bool done_with_buffer = false;
3003  llvm::StringRef buffer = buffer_it->second->getBuffer();
3004  if (xfer_offset >= buffer.size()) {
3005  // We have nothing left to send. Mark the buffer as complete.
3006  response.PutChar('l');
3007  done_with_buffer = true;
3008  } else {
3009  // Figure out how many bytes are available starting at the given offset.
3010  buffer = buffer.drop_front(xfer_offset);
3011  // Mark the response type according to whether we're reading the remainder
3012  // of the data.
3013  if (xfer_length >= buffer.size()) {
3014  // There will be nothing left to read after this
3015  response.PutChar('l');
3016  done_with_buffer = true;
3017  } else {
3018  // There will still be bytes to read after this request.
3019  response.PutChar('m');
3020  buffer = buffer.take_front(xfer_length);
3021  }
3022  // Now write the data in encoded binary form.
3023  response.PutEscapedBytes(buffer.data(), buffer.size());
3024  }
3025 
3026  if (done_with_buffer)
3027  m_xfer_buffer_map.erase(buffer_it);
3028 
3029  return SendPacketNoLock(response.GetString());
3030 }
3031 
3034  StringExtractorGDBRemote &packet) {
3036 
3037  // Move past packet name.
3038  packet.SetFilePos(strlen("QSaveRegisterState"));
3039 
3040  // Get the thread to use.
3041  NativeThreadProtocol *thread = GetThreadFromSuffix(packet);
3042  if (!thread) {
3044  return SendIllFormedResponse(
3045  packet, "No thread specified in QSaveRegisterState packet");
3046  else
3047  return SendIllFormedResponse(packet,
3048  "No thread was is set with the Hg packet");
3049  }
3050 
3051  // Grab the register context for the thread.
3052  NativeRegisterContext& reg_context = thread->GetRegisterContext();
3053 
3054  // Save registers to a buffer.
3055  DataBufferSP register_data_sp;
3056  Status error = reg_context.ReadAllRegisterValues(register_data_sp);
3057  if (error.Fail()) {
3058  LLDB_LOG(log, "pid {0} failed to save all register values: {1}",
3060  return SendErrorResponse(0x75);
3061  }
3062 
3063  // Allocate a new save id.
3064  const uint32_t save_id = GetNextSavedRegistersID();
3065  assert((m_saved_registers_map.find(save_id) == m_saved_registers_map.end()) &&
3066  "GetNextRegisterSaveID() returned an existing register save id");
3067 
3068  // Save the register data buffer under the save id.
3069  {
3070  std::lock_guard<std::mutex> guard(m_saved_registers_mutex);
3071  m_saved_registers_map[save_id] = register_data_sp;
3072  }
3073 
3074  // Write the response.
3075  StreamGDBRemote response;
3076  response.Printf("%" PRIu32, save_id);
3077  return SendPacketNoLock(response.GetString());
3078 }
3079 
3082  StringExtractorGDBRemote &packet) {
3084 
3085  // Parse out save id.
3086  packet.SetFilePos(strlen("QRestoreRegisterState:"));
3087  if (packet.GetBytesLeft() < 1)
3088  return SendIllFormedResponse(
3089  packet, "QRestoreRegisterState packet missing register save id");
3090 
3091  const uint32_t save_id = packet.GetU32(0);
3092  if (save_id == 0) {
3093  LLDB_LOG(log, "QRestoreRegisterState packet has malformed save id, "
3094  "expecting decimal uint32_t");
3095  return SendErrorResponse(0x76);
3096  }
3097 
3098  // Get the thread to use.
3099  NativeThreadProtocol *thread = GetThreadFromSuffix(packet);
3100  if (!thread) {
3102  return SendIllFormedResponse(
3103  packet, "No thread specified in QRestoreRegisterState packet");
3104  else
3105  return SendIllFormedResponse(packet,
3106  "No thread was is set with the Hg packet");
3107  }
3108 
3109  // Grab the register context for the thread.
3110  NativeRegisterContext &reg_context = thread->GetRegisterContext();
3111 
3112  // Retrieve register state buffer, then remove from the list.
3113  DataBufferSP register_data_sp;
3114  {
3115  std::lock_guard<std::mutex> guard(m_saved_registers_mutex);
3116 
3117  // Find the register set buffer for the given save id.
3118  auto it = m_saved_registers_map.find(save_id);
3119  if (it == m_saved_registers_map.end()) {
3120  LLDB_LOG(log,
3121  "pid {0} does not have a register set save buffer for id {1}",
3122  m_current_process->GetID(), save_id);
3123  return SendErrorResponse(0x77);
3124  }
3125  register_data_sp = it->second;
3126 
3127  // Remove it from the map.
3128  m_saved_registers_map.erase(it);
3129  }
3130 
3131  Status error = reg_context.WriteAllRegisterValues(register_data_sp);
3132  if (error.Fail()) {
3133  LLDB_LOG(log, "pid {0} failed to restore all register values: {1}",
3135  return SendErrorResponse(0x77);
3136  }
3137 
3138  return SendOKResponse();
3139 }
3140 
3143  StringExtractorGDBRemote &packet) {
3145 
3146  // Consume the ';' after vAttach.
3147  packet.SetFilePos(strlen("vAttach"));
3148  if (!packet.GetBytesLeft() || packet.GetChar() != ';')
3149  return SendIllFormedResponse(packet, "vAttach missing expected ';'");
3150 
3151  // Grab the PID to which we will attach (assume hex encoding).
3152  lldb::pid_t pid = packet.GetU32(LLDB_INVALID_PROCESS_ID, 16);
3153  if (pid == LLDB_INVALID_PROCESS_ID)
3154  return SendIllFormedResponse(packet,
3155  "vAttach failed to parse the process id");
3156 
3157  // Attempt to attach.
3158  LLDB_LOGF(log,
3159  "GDBRemoteCommunicationServerLLGS::%s attempting to attach to "
3160  "pid %" PRIu64,
3161  __FUNCTION__, pid);
3162 
3163  Status error = AttachToProcess(pid);
3164 
3165  if (error.Fail()) {
3166  LLDB_LOGF(log,
3167  "GDBRemoteCommunicationServerLLGS::%s failed to attach to "
3168  "pid %" PRIu64 ": %s\n",
3169  __FUNCTION__, pid, error.AsCString());
3170  return SendErrorResponse(error);
3171  }
3172 
3173  // Notify we attached by sending a stop packet.
3175 }
3176 
3179  StringExtractorGDBRemote &packet) {
3181 
3182  // Consume the ';' after the identifier.
3183  packet.SetFilePos(strlen("vAttachWait"));
3184 
3185  if (!packet.GetBytesLeft() || packet.GetChar() != ';')
3186  return SendIllFormedResponse(packet, "vAttachWait missing expected ';'");
3187 
3188  // Allocate the buffer for the process name from vAttachWait.
3189  std::string process_name;
3190  if (!packet.GetHexByteString(process_name))
3191  return SendIllFormedResponse(packet,
3192  "vAttachWait failed to parse process name");
3193 
3194  LLDB_LOG(log, "attempting to attach to process named '{0}'", process_name);
3195 
3196  Status error = AttachWaitProcess(process_name, false);
3197  if (error.Fail()) {
3198  LLDB_LOG(log, "failed to attach to process named '{0}': {1}", process_name,
3199  error);
3200  return SendErrorResponse(error);
3201  }
3202 
3203  // Notify we attached by sending a stop packet.
3205 }
3206 
3209  StringExtractorGDBRemote &packet) {
3210  return SendOKResponse();
3211 }
3212 
3215  StringExtractorGDBRemote &packet) {
3217 
3218  // Consume the ';' after the identifier.
3219  packet.SetFilePos(strlen("vAttachOrWait"));
3220 
3221  if (!packet.GetBytesLeft() || packet.GetChar() != ';')
3222  return SendIllFormedResponse(packet, "vAttachOrWait missing expected ';'");
3223 
3224  // Allocate the buffer for the process name from vAttachWait.
3225  std::string process_name;
3226  if (!packet.GetHexByteString(process_name))
3227  return SendIllFormedResponse(packet,
3228  "vAttachOrWait failed to parse process name");
3229 
3230  LLDB_LOG(log, "attempting to attach to process named '{0}'", process_name);
3231 
3232  Status error = AttachWaitProcess(process_name, true);
3233  if (error.Fail()) {
3234  LLDB_LOG(log, "failed to attach to process named '{0}': {1}", process_name,
3235  error);
3236  return SendErrorResponse(error);
3237  }
3238 
3239  // Notify we attached by sending a stop packet.
3241 }
3242 
3245  StringExtractorGDBRemote &packet) {
3247 
3248  llvm::StringRef s = packet.GetStringRef();
3249  if (!s.consume_front("vRun;"))
3250  return SendErrorResponse(8);
3251 
3252  llvm::SmallVector<llvm::StringRef, 16> argv;
3253  s.split(argv, ';');
3254 
3255  for (llvm::StringRef hex_arg : argv) {
3256  StringExtractor arg_ext{hex_arg};
3257  std::string arg;
3258  arg_ext.GetHexByteString(arg);
3260  LLDB_LOGF(log, "LLGSPacketHandler::%s added arg: \"%s\"", __FUNCTION__,
3261  arg.c_str());
3262  }
3263 
3264  if (!argv.empty()) {
3266  m_process_launch_info.GetArguments()[0].ref(), FileSpec::Style::native);
3270  LLDB_LOG(log, "failed to launch exe: {0}", m_process_launch_error);
3271  }
3272  return SendErrorResponse(8);
3273 }
3274 
3278 
3280 
3281  // Consume the ';' after D.
3282  packet.SetFilePos(1);
3283  if (packet.GetBytesLeft()) {
3284  if (packet.GetChar() != ';')
3285  return SendIllFormedResponse(packet, "D missing expected ';'");
3286 
3287  // Grab the PID from which we will detach (assume hex encoding).
3288  pid = packet.GetU32(LLDB_INVALID_PROCESS_ID, 16);
3289  if (pid == LLDB_INVALID_PROCESS_ID)
3290  return SendIllFormedResponse(packet, "D failed to parse the process id");
3291  }
3292 
3293  // Detach forked children if their PID was specified *or* no PID was requested
3294  // (i.e. detach-all packet).
3295  llvm::Error detach_error = llvm::Error::success();
3296  bool detached = false;
3297  for (auto it = m_debugged_processes.begin();
3298  it != m_debugged_processes.end();) {
3299  if (pid == LLDB_INVALID_PROCESS_ID || pid == it->first) {
3300  if (llvm::Error e = it->second->Detach().ToError())
3301  detach_error = llvm::joinErrors(std::move(detach_error), std::move(e));
3302  else {
3303  if (it->second.get() == m_current_process)
3304  m_current_process = nullptr;
3305  if (it->second.get() == m_continue_process)
3306  m_continue_process = nullptr;
3307  it = m_debugged_processes.erase(it);
3308  detached = true;
3309  continue;
3310  }
3311  }
3312  ++it;
3313  }
3314 
3315  if (detach_error)
3316  return SendErrorResponse(std::move(detach_error));
3317  if (!detached)
3318  return SendErrorResponse(Status("PID %" PRIu64 " not traced", pid));
3319  return SendOKResponse();
3320 }
3321 
3324  StringExtractorGDBRemote &packet) {
3326 
3327  packet.SetFilePos(strlen("qThreadStopInfo"));
3328  const lldb::tid_t tid = packet.GetHexMaxU64(false, LLDB_INVALID_THREAD_ID);
3329  if (tid == LLDB_INVALID_THREAD_ID) {
3330  LLDB_LOGF(log,
3331  "GDBRemoteCommunicationServerLLGS::%s failed, could not "
3332  "parse thread id from request \"%s\"",
3333  __FUNCTION__, packet.GetStringRef().data());
3334  return SendErrorResponse(0x15);
3335  }
3336  return SendStopReplyPacketForThread(tid);
3337 }
3338 
3343 
3344  // Ensure we have a debugged process.
3345  if (!m_current_process ||
3347  return SendErrorResponse(50);
3348  LLDB_LOG(log, "preparing packet for pid {0}", m_current_process->GetID());
3349 
3350  StreamString response;
3351  const bool threads_with_valid_stop_info_only = false;
3352  llvm::Expected<json::Value> threads_info =
3353  GetJSONThreadsInfo(*m_current_process, threads_with_valid_stop_info_only);
3354  if (!threads_info) {
3355  LLDB_LOG_ERROR(log, threads_info.takeError(),
3356  "failed to prepare a packet for pid {1}: {0}",
3358  return SendErrorResponse(52);
3359  }
3360 
3361  response.AsRawOstream() << *threads_info;
3362  StreamGDBRemote escaped_response;
3363  escaped_response.PutEscapedBytes(response.GetData(), response.GetSize());
3364  return SendPacketNoLock(escaped_response.GetString());
3365 }
3366 
3369  StringExtractorGDBRemote &packet) {
3370  // Fail if we don't have a current process.
3371  if (!m_current_process ||
3373  return SendErrorResponse(68);
3374 
3375  packet.SetFilePos(strlen("qWatchpointSupportInfo"));
3376  if (packet.GetBytesLeft() == 0)
3377  return SendOKResponse();
3378  if (packet.GetChar() != ':')
3379  return SendErrorResponse(67);
3380 
3381  auto hw_debug_cap = m_current_process->GetHardwareDebugSupportInfo();
3382 
3383  StreamGDBRemote response;
3384  if (hw_debug_cap == llvm::None)
3385  response.Printf("num:0;");
3386  else
3387  response.Printf("num:%d;", hw_debug_cap->second);
3388 
3389  return SendPacketNoLock(response.GetString());
3390 }
3391 
3394  StringExtractorGDBRemote &packet) {
3395  // Fail if we don't have a current process.
3396  if (!m_current_process ||
3398  return SendErrorResponse(67);
3399 
3400  packet.SetFilePos(strlen("qFileLoadAddress:"));
3401  if (packet.GetBytesLeft() == 0)
3402  return SendErrorResponse(68);
3403 
3404  std::string file_name;
3405  packet.GetHexByteString(file_name);
3406 
3407  lldb::addr_t file_load_address = LLDB_INVALID_ADDRESS;
3408  Status error =
3409  m_current_process->GetFileLoadAddress(file_name, file_load_address);
3410  if (error.Fail())
3411  return SendErrorResponse(69);
3412 
3413  if (file_load_address == LLDB_INVALID_ADDRESS)
3414  return SendErrorResponse(1); // File not loaded
3415 
3416  StreamGDBRemote response;
3417  response.PutHex64(file_load_address);
3418  return SendPacketNoLock(response.GetString());
3419 }
3420 
3423  StringExtractorGDBRemote &packet) {
3424  std::vector<int> signals;
3425  packet.SetFilePos(strlen("QPassSignals:"));
3426 
3427  // Read sequence of hex signal numbers divided by a semicolon and optionally
3428  // spaces.
3429  while (packet.GetBytesLeft() > 0) {
3430  int signal = packet.GetS32(-1, 16);
3431  if (signal < 0)
3432  return SendIllFormedResponse(packet, "Failed to parse signal number.");
3433  signals.push_back(signal);
3434 
3435  packet.SkipSpaces();
3436  char separator = packet.GetChar();
3437  if (separator == '\0')
3438  break; // End of string
3439  if (separator != ';')
3440  return SendIllFormedResponse(packet, "Invalid separator,"
3441  " expected semicolon.");
3442  }
3443 
3444  // Fail if we don't have a current process.
3445  if (!m_current_process)
3446  return SendErrorResponse(68);
3447 
3449  if (error.Fail())
3450  return SendErrorResponse(69);
3451 
3452  return SendOKResponse();
3453 }
3454 
3457  StringExtractorGDBRemote &packet) {
3459 
3460  // Ensure we have a process.
3461  if (!m_current_process ||
3463  LLDB_LOGF(
3464  log,
3465  "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
3466  __FUNCTION__);
3467  return SendErrorResponse(1);
3468  }
3469 
3470  // We are expecting
3471  // qMemTags:<hex address>,<hex length>:<hex type>
3472 
3473  // Address
3474  packet.SetFilePos(strlen("qMemTags:"));
3475  const char *current_char = packet.Peek();
3476  if (!current_char || *current_char == ',')
3477  return SendIllFormedResponse(packet, "Missing address in qMemTags packet");
3478  const lldb::addr_t addr = packet.GetHexMaxU64(/*little_endian=*/false, 0);
3479 
3480  // Length
3481  char previous_char = packet.GetChar();
3482  current_char = packet.Peek();
3483  // If we don't have a separator or the length field is empty
3484  if (previous_char != ',' || (current_char && *current_char == ':'))
3485  return SendIllFormedResponse(packet,
3486  "Invalid addr,length pair in qMemTags packet");
3487 
3488  if (packet.GetBytesLeft() < 1)
3489  return SendIllFormedResponse(
3490  packet, "Too short qMemtags: packet (looking for length)");
3491  const size_t length = packet.GetHexMaxU64(/*little_endian=*/false, 0);
3492 
3493  // Type
3494  const char *invalid_type_err = "Invalid type field in qMemTags: packet";
3495  if (packet.GetBytesLeft() < 1 || packet.GetChar() != ':')
3496  return SendIllFormedResponse(packet, invalid_type_err);
3497 
3498  // Type is a signed integer but packed into the packet as its raw bytes.
3499  // However, our GetU64 uses strtoull which allows +/-. We do not want this.
3500  const char *first_type_char = packet.Peek();
3501  if (first_type_char && (*first_type_char == '+' || *first_type_char == '-'))
3502  return SendIllFormedResponse(packet, invalid_type_err);
3503 
3504  // Extract type as unsigned then cast to signed.
3505  // Using a uint64_t here so that we have some value outside of the 32 bit
3506  // range to use as the invalid return value.
3507  uint64_t raw_type =
3508  packet.GetU64(std::numeric_limits<uint64_t>::max(), /*base=*/16);
3509 
3510  if ( // Make sure the cast below would be valid
3511  raw_type > std::numeric_limits<uint32_t>::max() ||
3512  // To catch inputs like "123aardvark" that will parse but clearly aren't
3513  // valid in this case.
3514  packet.GetBytesLeft()) {
3515  return SendIllFormedResponse(packet, invalid_type_err);
3516  }
3517 
3518  // First narrow to 32 bits otherwise the copy into type would take
3519  // the wrong 4 bytes on big endian.
3520  uint32_t raw_type_32 = raw_type;
3521  int32_t type = reinterpret_cast<int32_t &>(raw_type_32);
3522 
3523  StreamGDBRemote response;
3524  std::vector<uint8_t> tags;
3525  Status error = m_current_process->ReadMemoryTags(type, addr, length, tags);
3526  if (error.Fail())
3527  return SendErrorResponse(1);
3528 
3529  // This m is here in case we want to support multi part replies in the future.
3530  // In the same manner as qfThreadInfo/qsThreadInfo.
3531  response.PutChar('m');
3532  response.PutBytesAsRawHex8(tags.data(), tags.size());
3533  return SendPacketNoLock(response.GetString());
3534 }
3535 
3538  StringExtractorGDBRemote &packet) {
3540 
3541  // Ensure we have a process.
3542  if (!m_current_process ||
3544  LLDB_LOGF(
3545  log,
3546  "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
3547  __FUNCTION__);
3548  return SendErrorResponse(1);
3549  }
3550 
3551  // We are expecting
3552  // QMemTags:<hex address>,<hex length>:<hex type>:<tags as hex bytes>
3553 
3554  // Address
3555  packet.SetFilePos(strlen("QMemTags:"));
3556  const char *current_char = packet.Peek();
3557  if (!current_char || *current_char == ',')
3558  return SendIllFormedResponse(packet, "Missing address in QMemTags packet");
3559  const lldb::addr_t addr = packet.GetHexMaxU64(/*little_endian=*/false, 0);
3560 
3561  // Length
3562  char previous_char = packet.GetChar();
3563  current_char = packet.Peek();
3564  // If we don't have a separator or the length field is empty
3565  if (previous_char != ',' || (current_char && *current_char == ':'))
3566  return SendIllFormedResponse(packet,
3567  "Invalid addr,length pair in QMemTags packet");
3568 
3569  if (packet.GetBytesLeft() < 1)
3570  return SendIllFormedResponse(
3571  packet, "Too short QMemtags: packet (looking for length)");
3572  const size_t length = packet.GetHexMaxU64(/*little_endian=*/false, 0);
3573 
3574  // Type
3575  const char *invalid_type_err = "Invalid type field in QMemTags: packet";
3576  if (packet.GetBytesLeft() < 1 || packet.GetChar() != ':')
3577  return SendIllFormedResponse(packet, invalid_type_err);
3578 
3579  // Our GetU64 uses strtoull which allows leading +/-, we don't want that.
3580  const char *first_type_char = packet.Peek();
3581  if (first_type_char && (*first_type_char == '+' || *first_type_char == '-'))
3582  return SendIllFormedResponse(packet, invalid_type_err);
3583 
3584  // The type is a signed integer but is in the packet as its raw bytes.
3585  // So parse first as unsigned then cast to signed later.
3586  // We extract to 64 bit, even though we only expect 32, so that we've
3587  // got some invalid value we can check for.
3588  uint64_t raw_type =
3589  packet.GetU64(std::numeric_limits<uint64_t>::max(), /*base=*/16);
3590  if (raw_type > std::numeric_limits<uint32_t>::max())
3591  return SendIllFormedResponse(packet, invalid_type_err);
3592 
3593  // First narrow to 32 bits. Otherwise the copy below would get the wrong
3594  // 4 bytes on big endian.
3595  uint32_t raw_type_32 = raw_type;
3596  int32_t type = reinterpret_cast<int32_t &>(raw_type_32);
3597 
3598  // Tag data
3599  if (packet.GetBytesLeft() < 1 || packet.GetChar() != ':')
3600  return SendIllFormedResponse(packet,
3601  "Missing tag data in QMemTags: packet");
3602 
3603  // Must be 2 chars per byte
3604  const char *invalid_data_err = "Invalid tag data in QMemTags: packet";
3605  if (packet.GetBytesLeft() % 2)
3606  return SendIllFormedResponse(packet, invalid_data_err);
3607 
3608  // This is bytes here and is unpacked into target specific tags later
3609  // We cannot assume that number of bytes == length here because the server
3610  // can repeat tags to fill a given range.
3611  std::vector<uint8_t> tag_data;
3612  // Zero length writes will not have any tag data
3613  // (but we pass them on because it will still check that tagging is enabled)
3614  if (packet.GetBytesLeft()) {
3615  size_t byte_count = packet.GetBytesLeft() / 2;
3616  tag_data.resize(byte_count);
3617  size_t converted_bytes = packet.GetHexBytes(tag_data, 0);
3618  if (converted_bytes != byte_count) {
3619  return SendIllFormedResponse(packet, invalid_data_err);
3620  }
3621  }
3622 
3623  Status status =
3624  m_current_process->WriteMemoryTags(type, addr, length, tag_data);
3625  return status.Success() ? SendOKResponse() : SendErrorResponse(1);
3626 }
3627 
3630  StringExtractorGDBRemote &packet) {
3631  // Fail if we don't have a current process.
3632  if (!m_current_process ||
3634  return SendErrorResponse(Status("Process not running."));
3635 
3636  std::string path_hint;
3637 
3638  StringRef packet_str{packet.GetStringRef()};
3639  assert(packet_str.startswith("qSaveCore"));
3640  if (packet_str.consume_front("qSaveCore;")) {
3641  for (auto x : llvm::split(packet_str, ';')) {
3642  if (x.consume_front("path-hint:"))
3643  StringExtractor(x).GetHexByteString(path_hint);
3644  else
3645  return SendErrorResponse(Status("Unsupported qSaveCore option"));
3646  }
3647  }
3648 
3649  llvm::Expected<std::string> ret = m_current_process->SaveCore(path_hint);
3650  if (!ret)
3651  return SendErrorResponse(ret.takeError());
3652 
3653  StreamString response;
3654  response.PutCString("core-path:");
3655  response.PutStringAsRawHex8(ret.get());
3656  return SendPacketNoLock(response.GetString());
3657 }
3658 
3661 
3662  // Tell the stdio connection to shut down.
3664  auto connection = m_stdio_communication.GetConnection();
3665  if (connection) {
3666  Status error;
3667  connection->Disconnect(&error);
3668 
3669  if (error.Success()) {
3670  LLDB_LOGF(log,
3671  "GDBRemoteCommunicationServerLLGS::%s disconnect process "
3672  "terminal stdio - SUCCESS",
3673  __FUNCTION__);
3674  } else {
3675  LLDB_LOGF(log,
3676  "GDBRemoteCommunicationServerLLGS::%s disconnect process "
3677  "terminal stdio - FAIL: %s",
3678  __FUNCTION__, error.AsCString());
3679  }
3680  }
3681  }
3682 }
3683 
3685  StringExtractorGDBRemote &packet) {
3686  // We have no thread if we don't have a process.
3687  if (!m_current_process ||
3689  return nullptr;
3690 
3691  // If the client hasn't asked for thread suffix support, there will not be a
3692  // thread suffix. Use the current thread in that case.
3694  const lldb::tid_t current_tid = GetCurrentThreadID();
3695  if (current_tid == LLDB_INVALID_THREAD_ID)
3696  return nullptr;
3697  else if (current_tid == 0) {
3698  // Pick a thread.
3700  } else
3701  return m_current_process->GetThreadByID(current_tid);
3702  }
3703 
3705 
3706  // Parse out the ';'.
3707  if (packet.GetBytesLeft() < 1 || packet.GetChar() != ';') {
3708  LLDB_LOGF(log,
3709  "GDBRemoteCommunicationServerLLGS::%s gdb-remote parse "
3710  "error: expected ';' prior to start of thread suffix: packet "
3711  "contents = '%s'",
3712  __FUNCTION__, packet.GetStringRef().data());
3713  return nullptr;
3714  }
3715 
3716  if (!packet.GetBytesLeft())
3717  return nullptr;
3718 
3719  // Parse out thread: portion.
3720  if (strncmp(packet.Peek(), "thread:", strlen("thread:")) != 0) {
3721  LLDB_LOGF(log,
3722  "GDBRemoteCommunicationServerLLGS::%s gdb-remote parse "
3723  "error: expected 'thread:' but not found, packet contents = "
3724  "'%s'",
3725  __FUNCTION__, packet.GetStringRef().data());
3726  return nullptr;
3727  }
3728  packet.SetFilePos(packet.GetFilePos() + strlen("thread:"));
3729  const lldb::tid_t tid = packet.GetHexMaxU64(false, 0);
3730  if (tid != 0)
3731  return m_current_process->GetThreadByID(tid);
3732 
3733  return nullptr;
3734 }
3735 
3738  // Use whatever the debug process says is the current thread id since the
3739  // protocol either didn't specify or specified we want any/all threads
3740  // marked as the current thread.
3741  if (!m_current_process)
3742  return LLDB_INVALID_THREAD_ID;
3744  }
3745  // Use the specific current thread id set by the gdb remote protocol.
3746  return m_current_tid;
3747 }
3748 
3750  std::lock_guard<std::mutex> guard(m_saved_registers_mutex);
3751  return m_next_saved_registers_id++;
3752 }
3753 
3756 
3757  LLDB_LOG(log, "clearing {0} xfer buffers", m_xfer_buffer_map.size());
3758  m_xfer_buffer_map.clear();
3759 }
3760 
3761 FileSpec
3763  const ArchSpec &arch) {
3764  if (m_current_process) {
3765  FileSpec file_spec;
3766  if (m_current_process
3767  ->GetLoadedModuleFileSpec(module_path.c_str(), file_spec)
3768  .Success()) {
3769  if (FileSystem::Instance().Exists(file_spec))
3770  return file_spec;
3771  }
3772  }
3773 
3774  return GDBRemoteCommunicationServerCommon::FindModuleFile(module_path, arch);
3775 }
3776 
3778  llvm::StringRef value) {
3779  std::string result;
3780  for (const char &c : value) {
3781  switch (c) {
3782  case '\'':
3783  result += "&apos;";
3784  break;
3785  case '"':
3786  result += "&quot;";
3787  break;
3788  case '<':
3789  result += "&lt;";
3790  break;
3791  case '>':
3792  result += "&gt;";
3793  break;
3794  default:
3795  result += c;
3796  break;
3797  }
3798  }
3799  return result;
3800 }
3801 
3802 llvm::Expected<lldb::tid_t> GDBRemoteCommunicationServerLLGS::ReadTid(
3803  StringExtractorGDBRemote &packet, bool allow_all, lldb::pid_t default_pid) {
3804  assert(m_current_process);
3806 
3807  auto pid_tid = packet.GetPidTid(default_pid);
3808  if (!pid_tid)
3809  return llvm::make_error<StringError>(inconvertibleErrorCode(),
3810  "Malformed thread-id");
3811 
3812  lldb::pid_t pid = pid_tid->first;
3813  lldb::tid_t tid = pid_tid->second;
3814 
3815  if (!allow_all && pid == StringExtractorGDBRemote::AllProcesses)
3816  return llvm::make_error<StringError>(
3817  inconvertibleErrorCode(),
3818  llvm::formatv("PID value {0} not allowed", pid == 0 ? 0 : -1));
3819 
3820  if (!allow_all && tid == StringExtractorGDBRemote::AllThreads)
3821  return llvm::make_error<StringError>(
3822  inconvertibleErrorCode(),
3823  llvm::formatv("TID value {0} not allowed", tid == 0 ? 0 : -1));
3824 
3826  if (pid != m_current_process->GetID())
3827  return llvm::make_error<StringError>(
3828  inconvertibleErrorCode(), llvm::formatv("PID {0} not debugged", pid));
3829  }
3830 
3831  return tid;
3832 }
3833 
3835  const llvm::ArrayRef<llvm::StringRef> client_features) {
3836  std::vector<std::string> ret =
3838  ret.insert(ret.end(), {
3839  "QThreadSuffixSupported+",
3840  "QListThreadsInStopReply+",
3841  "qXfer:features:read+",
3842  });
3843 
3844  // report server-only features
3845  using Extension = NativeProcessProtocol::Extension;
3846  Extension plugin_features = m_process_factory.GetSupportedExtensions();
3847  if (bool(plugin_features & Extension::pass_signals))
3848  ret.push_back("QPassSignals+");
3849  if (bool(plugin_features & Extension::auxv))
3850  ret.push_back("qXfer:auxv:read+");
3851  if (bool(plugin_features & Extension::libraries_svr4))
3852  ret.push_back("qXfer:libraries-svr4:read+");
3853  if (bool(plugin_features & Extension::siginfo_read))
3854  ret.push_back("qXfer:siginfo:read+");
3855  if (bool(plugin_features & Extension::memory_tagging))
3856  ret.push_back("memory-tagging+");
3857  if (bool(plugin_features & Extension::savecore))
3858  ret.push_back("qSaveCore+");
3859 
3860  // check for client features
3862  for (llvm::StringRef x : client_features)
3864  llvm::StringSwitch<Extension>(x)
3865  .Case("multiprocess+", Extension::multiprocess)
3866  .Case("fork-events+", Extension::fork)
3867  .Case("vfork-events+", Extension::vfork)
3868  .Default({});
3869 
3870  m_extensions_supported &= plugin_features;
3871 
3872  // fork & vfork require multiprocess
3873  if (!bool(m_extensions_supported & Extension::multiprocess))
3874  m_extensions_supported &= ~(Extension::fork | Extension::vfork);
3875 
3876  // report only if actually supported
3877  if (bool(m_extensions_supported & Extension::multiprocess))
3878  ret.push_back("multiprocess+");
3880  ret.push_back("fork-events+");
3881  if (bool(m_extensions_supported & Extension::vfork))
3882  ret.push_back("vfork-events+");
3883 
3884  for (auto &x : m_debugged_processes)
3885  SetEnabledExtensions(*x.second);
3886  return ret;
3887 }
3888 
3890  NativeProcessProtocol &process) {
3892  assert(!bool(flags & ~m_process_factory.GetSupportedExtensions()));
3893  process.SetEnabledExtensions(flags);
3894 }
3895 
3898  bool reverse_connect) {
3899  // Try parsing the argument as URL.
3900  if (llvm::Optional<URI> url = URI::Parse(url_arg)) {
3901  if (reverse_connect)
3902  return url_arg.str();
3903 
3904  // Translate the scheme from LLGS notation to ConnectionFileDescriptor.
3905  // If the scheme doesn't match any, pass it through to support using CFD
3906  // schemes directly.
3907  std::string new_url = llvm::StringSwitch<std::string>(url->scheme)
3908  .Case("tcp", "listen")
3909  .Case("unix", "unix-accept")
3910  .Case("unix-abstract", "unix-abstract-accept")
3911  .Default(url->scheme.str());
3912  llvm::append_range(new_url, url_arg.substr(url->scheme.size()));
3913  return new_url;
3914  }
3915 
3916  std::string host_port = url_arg.str();
3917  // If host_and_port starts with ':', default the host to be "localhost" and
3918  // expect the remainder to be the port.
3919  if (url_arg.startswith(":"))
3920  host_port.insert(0, "localhost");
3921 
3922  // Try parsing the (preprocessed) argument as host:port pair.
3923  if (!llvm::errorToBool(Socket::DecodeHostAndPort(host_port).takeError()))
3924  return (reverse_connect ? "connect://" : "listen://") + host_port;
3925 
3926  // If none of the above applied, interpret the argument as UNIX socket path.
3927  return (reverse_connect ? "unix-connect://" : "unix-accept://") +
3928  url_arg.str();
3929 }
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qFileLoadAddress
PacketResult Handle_qFileLoadAddress(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3393
StringExtractorGDBRemote::eServerPacketType_D
@ eServerPacketType_D
Definition: StringExtractorGDBRemote.h:145
lldb_private::ProcessInfo::GetArguments
Args & GetArguments()
Definition: ProcessInfo.h:75
lldb_private::Stream::Format
void Format(const char *format, Args &&... args)
Definition: Stream.h:309
lldb::eFormatVectorOfUInt64
@ eFormatVectorOfUInt64
Definition: lldb-enumerations.h:187
StringExtractorGDBRemote::eServerPacketType__m
@ eServerPacketType__m
Definition: StringExtractorGDBRemote.h:164
lldb_private::ProcessInstanceInfo
Definition: ProcessInfo.h:108
lldb_private::ProcessInstanceInfoMatch::SetNameMatchType
void SetNameMatchType(NameMatch name_match_type)
Definition: ProcessInfo.h:184
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_interrupt
PacketResult Handle_interrupt(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:2203
StringExtractorGDBRemote::AllProcesses
static constexpr lldb::pid_t AllProcesses
Definition: StringExtractorGDBRemote.h:201
LLDB_REGNUM_GENERIC_ARG2
#define LLDB_REGNUM_GENERIC_ARG2
Definition: lldb-defines.h:58
LLDB_REGNUM_GENERIC_ARG3
#define LLDB_REGNUM_GENERIC_ARG3
Definition: lldb-defines.h:60
lldb_private::Range::GetRangeBase
BaseType GetRangeBase() const
Definition: RangeMap.h:46
lldb_private::ArchSpec::GetByteOrder
lldb::ByteOrder GetByteOrder() const
Returns the byte order for the architecture specification.
Definition: ArchSpec.cpp:730
lldb_private::Host::FindProcesses
static uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &proc_infos)
Definition: common/Host.cpp:705
lldb_private::process_gdb_remote::GDBRemoteCommunicationServer::SendErrorResponse
PacketResult SendErrorResponse(const Status &error)
Definition: GDBRemoteCommunicationServer.cpp:106
llvm
Definition: Debugger.h:49
lldb_private::MainLoop::RegisterReadObject
ReadHandleUP RegisterReadObject(const lldb::IOObjectSP &object_sp, const Callback &callback, Status &error) override
Definition: MainLoop.cpp:272
StringExtractorGDBRemote::eServerPacketType_qMemoryRegionInfoSupported
@ eServerPacketType_qMemoryRegionInfoSupported
Definition: StringExtractorGDBRemote.h:115
lldb_private::ArchSpec
Definition: ArchSpec.h:33
LLDB_REGNUM_GENERIC_ARG1
#define LLDB_REGNUM_GENERIC_ARG1
Definition: lldb-defines.h:56
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qfThreadInfo
PacketResult Handle_qfThreadInfo(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1823
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::InitializeDelegate
void InitializeDelegate(NativeProcessProtocol *process) override
Definition: GDBRemoteCommunicationServerLLGS.cpp:440
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_Z
PacketResult Handle_Z(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:2579
FileSystem.h
lldb::eFormatVectorOfUInt128
@ eFormatVectorOfUInt128
Definition: lldb-enumerations.h:191
LLDB_INVALID_REGNUM
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:79
lldb_private::ProcessLaunchInfo::SetWorkingDirectory
void SetWorkingDirectory(const FileSpec &working_dir)
Definition: ProcessLaunchInfo.cpp:128
lldb_private::NativeProcessProtocol::GetCurrentThread
NativeThreadProtocol * GetCurrentThread()
Definition: NativeProcessProtocol.h:209
StringExtractorGDBRemote::eServerPacketType_x
@ eServerPacketType_x
Definition: StringExtractorGDBRemote.h:158
lldb_private::RegisterValue::GetByteSize
uint32_t GetByteSize() const
Definition: RegisterValue.cpp:713
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_QRestoreRegisterState
PacketResult Handle_QRestoreRegisterState(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3081
lldb_private::NativeProcessProtocol::TraceStart
virtual llvm::Error TraceStart(llvm::StringRef json_params, llvm::StringRef type)
Start tracing a process or its threads.
Definition: NativeProcessProtocol.h:329
LLDB_INVALID_PROCESS_ID
#define LLDB_INVALID_PROCESS_ID
Definition: lldb-defines.h:81
lldb_private::NativeProcessProtocol::ReadMemoryWithoutTrap
Status ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read)
Definition: NativeProcessProtocol.cpp:613
lldb_private::Stream::PutHex32
size_t PutHex32(uint32_t uvalue, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
Definition: Stream.cpp:256
lldb_private::NativeRegisterContext::ReadRegister
virtual Status ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value)=0
lldb_private::NativeProcessProtocol::GetThreadAtIndex
NativeThreadProtocol * GetThreadAtIndex(uint32_t idx)
Definition: NativeProcessProtocol.cpp:98
StringExtractorGDBRemote::eServerPacketType_QListThreadsInStopReply
@ eServerPacketType_QListThreadsInStopReply
Definition: StringExtractorGDBRemote.h:97
lldb_private::Communication::SetCloseOnEOF
void SetCloseOnEOF(bool b)
Definition: Communication.h:308
AppendHexValue
static void AppendHexValue(StreamString &response, const uint8_t *buf, uint32_t buf_size, bool swap)
Definition: GDBRemoteCommunicationServerLLGS.cpp:479
lldb_private::RegisterValue
Definition: RegisterValue.h:28
lldb_private::NativeThreadProtocol
Definition: NativeThreadProtocol.h:24
StringExtractor::SetFilePos
void SetFilePos(uint32_t idx)
Definition: StringExtractor.h:39
lldb_private::process_gdb_remote::GDBRemoteCommunicationServer::RegisterPacketHandler
void RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type, PacketHandler handler)
Definition: GDBRemoteCommunicationServer.cpp:38
arm64_dwarf::x29
@ x29
Definition: ARM64_DWARF_Registers.h:46
lldb::eRegisterKindDWARF
@ eRegisterKindDWARF
the register numbers seen DWARF
Definition: lldb-enumerations.h:229
StringExtractor::GetBytesLeft
size_t GetBytesLeft()
Definition: StringExtractor.h:52
StringExtractorGDBRemote::eServerPacketType_qfThreadInfo
@ eServerPacketType_qfThreadInfo
Definition: StringExtractorGDBRemote.h:110
lldb_private::process_gdb_remote::eWatchpointReadWrite
@ eWatchpointReadWrite
Definition: GDBRemoteCommunication.h:42
lldb::eStopReasonVFork
@ eStopReasonVFork
Definition: lldb-enumerations.h:253
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::m_saved_registers_map
std::unordered_map< uint32_t, lldb::DataBufferSP > m_saved_registers_map
Definition: GDBRemoteCommunicationServerLLGS.h:105
lldb_private::URI::Parse
static llvm::Optional< URI > Parse(llvm::StringRef uri)
Definition: UriParser.cpp:27
lldb_private::NativeProcessProtocol::GetAuxvData
virtual llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > GetAuxvData() const =0
StringExtractor::ConsumeFront
bool ConsumeFront(const llvm::StringRef &str)
Definition: StringExtractor.cpp:257
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::m_mainloop
MainLoop & m_mainloop
Definition: GDBRemoteCommunicationServerLLGS.h:88
lldb::eRegisterKindGeneric
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
Definition: lldb-enumerations.h:230
Host.h
StringExtractor::GetStringRef
llvm::StringRef GetStringRef() const
Definition: StringExtractor.h:48
lldb_private::NativeProcessProtocol::GetLoadedSVR4Libraries
virtual llvm::Expected< std::vector< SVR4LibraryInfo > > GetLoadedSVR4Libraries()
Definition: NativeProcessProtocol.h:136
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_stop_reason
PacketResult Handle_stop_reason(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1680
lldb_private::process_gdb_remote::eStoppointInvalid
@ eStoppointInvalid
Definition: GDBRemoteCommunication.h:37
StringExtractor::SkipSpaces
void SkipSpaces()
Definition: StringExtractor.cpp:367
lldb::eStateAttaching
@ eStateAttaching
Process is currently trying to attach.
Definition: lldb-enumerations.h:78
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_vRun
PacketResult Handle_vRun(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3244
LLDB_REGNUM_GENERIC_ARG5
#define LLDB_REGNUM_GENERIC_ARG5
Definition: lldb-defines.h:64
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::GetNextSavedRegistersID
uint32_t GetNextSavedRegistersID()
Definition: GDBRemoteCommunicationServerLLGS.cpp:3749
lldb_private::process_gdb_remote::GDBRemoteCommunication::PacketResult
PacketResult
Definition: GDBRemoteCommunication.h:91
lldb_private::NativeRegisterContext::RegisterOffsetIsDynamic
virtual bool RegisterOffsetIsDynamic() const
Definition: NativeRegisterContext.h:124
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::m_debugged_process_mutex
std::recursive_mutex m_debugged_process_mutex
Definition: GDBRemoteCommunicationServerLLGS.h:95
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_p
PacketResult Handle_p(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1921
lldb_private::NativeProcessProtocol::IgnoreSignals
virtual Status IgnoreSignals(llvm::ArrayRef< int > signals)
Definition: NativeProcessProtocol.cpp:42
lldb_private::NativeProcessProtocol::SetWatchpoint
virtual Status SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags, bool hardware)
Definition: NativeProcessProtocol.cpp:146
StringExtractorGDBRemote::eServerPacketType_stop_reason
@ eServerPacketType_stop_reason
Definition: StringExtractorGDBRemote.h:141
arm64_dwarf::x15
@ x15
Definition: ARM64_DWARF_Registers.h:32
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfoSupported
PacketResult Handle_qMemoryRegionInfoSupported(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:2466
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_s
PacketResult Handle_s(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:2760
StringExtractorGDBRemote::eServerPacketType_vAttachOrWait
@ eServerPacketType_vAttachOrWait
Definition: StringExtractorGDBRemote.h:135
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::SetContinueThreadID
void SetContinueThreadID(lldb::tid_t tid)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1672
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::m_debugged_processes
std::unordered_map< lldb::pid_t, std::unique_ptr< NativeProcessProtocol > > m_debugged_processes
Definition: GDBRemoteCommunicationServerLLGS.h:97
lldb::eStopReasonThreadExiting
@ eStopReasonThreadExiting
Definition: lldb-enumerations.h:249
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:247
lldb_private::NativeProcessProtocol::GetCurrentThreadID
lldb::tid_t GetCurrentThreadID() const
Definition: NativeProcessProtocol.h:207
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::SetCurrentThreadID
void SetCurrentThreadID(lldb::tid_t tid)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1663
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::GetContinueThreadID
lldb::tid_t GetContinueThreadID() const
Definition: GDBRemoteCommunicationServerLLGS.h:232
lldb_private::process_gdb_remote::GDBRemoteCommunicationServer::GetPacketAndSendResponse
PacketResult GetPacketAndSendResponse(Timeout< std::micro > timeout, Status &error, bool &interrupt, bool &quit)
Definition: GDBRemoteCommunicationServer.cpp:45
lldb_private::Flags::Clear
ValueType Clear(ValueType mask=~static_cast< ValueType >(0))
Clear one or more flags.
Definition: Flags.h:61
StringExtractorGDBRemote::eServerPacketType_qLLDBSaveCore
@ eServerPacketType_qLLDBSaveCore
Definition: StringExtractorGDBRemote.h:176
lldb_private::swap
void swap(AdaptedConstIterator< C, E, A > &lhs, AdaptedConstIterator< C, E, A > &rhs)
Definition: Iterable.h:147
lldb_private::Args::AppendArgument
void AppendArgument(llvm::StringRef arg_str, char quote_char='\0')
Appends a new argument to the end of the list argument list.
Definition: Args.cpp:318
lldb_private::ExpeditedRegs::Minimal
@ Minimal
lldb_private::NativeProcessProtocol::AllocateMemory
virtual llvm::Expected< lldb::addr_t > AllocateMemory(size_t size, uint32_t permissions)
Definition: NativeProcessProtocol.h:124
lldb::eEncodingIEEE754
@ eEncodingIEEE754
float
Definition: lldb-enumerations.h:150
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_g
PacketResult Handle_g(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1866
lldb::eStopReasonInvalid
@ eStopReasonInvalid
Definition: lldb-enumerations.h:240
lldb_private::NativeProcessProtocol::GetThreadByID
NativeThreadProtocol * GetThreadByID(lldb::tid_t tid)
Definition: NativeProcessProtocol.cpp:114
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qWatchpointSupportInfo
PacketResult Handle_qWatchpointSupportInfo(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3368
lldb_private::StateAsCString
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition: State.cpp:14
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::AttachWaitProcess
Status AttachWaitProcess(llvm::StringRef process_name, bool include_existing)
Wait to attach to a process with a given name.
Definition: GDBRemoteCommunicationServerLLGS.cpp:371
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qVAttachOrWaitSupported
PacketResult Handle_qVAttachOrWaitSupported(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3208
lldb::eFormatVectorOfSInt16
@ eFormatVectorOfSInt16
Definition: lldb-enumerations.h:182
lldb::eFormatVectorOfSInt32
@ eFormatVectorOfSInt32
Definition: lldb-enumerations.h:184
lldb_private::ProcessLaunchInfo::GetFileActionForFD
const FileAction * GetFileActionForFD(int fd) const
Definition: ProcessLaunchInfo.cpp:116
LIBLLDB_LOG_WATCHPOINTS
#define LIBLLDB_LOG_WATCHPOINTS
Definition: Logging.h:20
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::m_list_threads_in_stop_reply
bool m_list_threads_in_stop_reply
Definition: GDBRemoteCommunicationServerLLGS.h:108
StringExtractorGDBRemote::eServerPacketType_qMemoryRegionInfo
@ eServerPacketType_qMemoryRegionInfo
Definition: StringExtractorGDBRemote.h:114
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::SendStopReplyPacketForThread
PacketResult SendStopReplyPacketForThread(lldb::tid_t tid)
Definition: GDBRemoteCommunicationServerLLGS.cpp:767
reg_size
static const size_t reg_size
Definition: ABISysV_arc.cpp:171
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::m_thread_suffix_supported
bool m_thread_suffix_supported
Definition: GDBRemoteCommunicationServerLLGS.h:107
lldb_private::ProcessInstanceInfoMatch
Definition: ProcessInfo.h:163
StringExtractorGDBRemote::eServerPacketType_qC
@ eServerPacketType_qC
Definition: StringExtractorGDBRemote.h:55
lldb::StopReason
StopReason
Thread stop reasons.
Definition: lldb-enumerations.h:239
StringExtractorGDBRemote::eServerPacketType_I
@ eServerPacketType_I
Definition: StringExtractorGDBRemote.h:149
StringExtractorGDBRemote::eServerPacketType_qProcessInfo
@ eServerPacketType_qProcessInfo
Definition: StringExtractorGDBRemote.h:116
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::StartSTDIOForwarding
void StartSTDIOForwarding()
Definition: GDBRemoteCommunicationServerLLGS.cpp:1160
lldb_private::ResumeAction
Definition: Debug.h:19
StringExtractorGDBRemote::eServerPacketType_M
@ eServerPacketType_M
Definition: StringExtractorGDBRemote.h:152
lldb_private::NativeProcessProtocol::GetHardwareDebugSupportInfo
virtual llvm::Optional< std::pair< uint32_t, uint32_t > > GetHardwareDebugSupportInfo() const
Definition: NativeProcessProtocol.cpp:130
lldb::eStopReasonException
@ eStopReasonException
Definition: lldb-enumerations.h:246
lldb_private::ThreadStopInfo::details
union lldb_private::ThreadStopInfo::@13 details
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::InitializeConnection
Status InitializeConnection(std::unique_ptr< Connection > connection)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1111
StringExtractorGDBRemote::eServerPacketType_vRun
@ eServerPacketType_vRun
Definition: StringExtractorGDBRemote.h:139
RegisterValue.h
lldb_private::NativeProcessProtocol::GetMemoryRegionInfo
virtual Status GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &range_info)
Definition: NativeProcessProtocol.cpp:49
lldb_private::MemoryRegionInfo
Definition: MemoryRegionInfo.h:21
lldb_private::ProcessLaunchInfo::GetFlags
Flags & GetFlags()
Definition: ProcessLaunchInfo.h:64
lldb_private::process_gdb_remote::eWatchpointWrite
@ eWatchpointWrite
Definition: GDBRemoteCommunication.h:40
StringExtractor::GetHexMaxU32
uint32_t GetHexMaxU32(bool little_endian, uint32_t fail_value)
Definition: StringExtractor.cpp:155
StringExtractorGDBRemote.h
lldb_private::NativeProcessProtocol::Signal
virtual Status Signal(int signo)=0
Sends a process a UNIX signal signal.
StringExtractorGDBRemote::eServerPacketType_vAttachWait
@ eServerPacketType_vAttachWait
Definition: StringExtractorGDBRemote.h:134
lldb_private::NativeProcessProtocol::SaveCore
virtual llvm::Expected< std::string > SaveCore(llvm::StringRef path_hint)
Write a core dump (without crashing the program).
Definition: NativeProcessProtocol.h:382
lldb_private::ResumeAction::signal
int signal
Definition: Debug.h:25
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
StringExtractorGDBRemote::eServerPacketType_jLLDBTraceSupported
@ eServerPacketType_jLLDBTraceSupported
Definition: StringExtractorGDBRemote.h:167
StringExtractor
Definition: StringExtractor.h:19
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_QPassSignals
PacketResult Handle_QPassSignals(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3422
lldb::eConnectionStatusNoConnection
@ eConnectionStatusNoConnection
No connection.
Definition: lldb-enumerations.h:300
lldb_private::NativeProcessProtocol::WriteMemoryTags
virtual Status WriteMemoryTags(int32_t type, lldb::addr_t addr, size_t len, const std::vector< uint8_t > &tags)
Definition: NativeProcessProtocol.cpp:62
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_M
PacketResult Handle_M(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:2387
lldb::eStopReasonTrace
@ eStopReasonTrace
Definition: lldb-enumerations.h:242
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qThreadStopInfo
PacketResult Handle_qThreadStopInfo(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3323
lldb_private::NativeProcessProtocol::RemoveWatchpoint
virtual Status RemoveWatchpoint(lldb::addr_t addr)
Definition: NativeProcessProtocol.cpp:206
lldb_private::MemoryRegionInfo::GetMemoryTagged
OptionalBool GetMemoryTagged() const
Definition: MemoryRegionInfo.h:52
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon
Definition: GDBRemoteCommunicationServerCommon.h:27
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qC
PacketResult Handle_qC(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1336
lldb::eConnectionStatusEndOfFile
@ eConnectionStatusEndOfFile
End-of-file encountered.
Definition: lldb-enumerations.h:297
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::NewSubprocess
void NewSubprocess(NativeProcessProtocol *parent_process, std::unique_ptr< NativeProcessProtocol > child_process) override
Definition: GDBRemoteCommunicationServerLLGS.cpp:1079
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_D
PacketResult Handle_D(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3276
lldb_private::Stream::PutStringAsRawHex8
size_t PutStringAsRawHex8(llvm::StringRef s)
Definition: Stream.cpp:382
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::m_stdio_handle_up
MainLoop::ReadHandleUP m_stdio_handle_up
Definition: GDBRemoteCommunicationServerLLGS.h:100
StringExtractorGDBRemote::eServerPacketType_jLLDBTraceStart
@ eServerPacketType_jLLDBTraceStart
Definition: StringExtractorGDBRemote.h:168
lldb_private::StreamString::GetString
llvm::StringRef GetString() const
Definition: StreamString.cpp:51
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::m_stdio_communication
Communication m_stdio_communication
Definition: GDBRemoteCommunicationServerLLGS.h:99
LLDB_REGNUM_GENERIC_ARG6
#define LLDB_REGNUM_GENERIC_ARG6
Definition: lldb-defines.h:66
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_jLLDBTraceStart
PacketResult Handle_jLLDBTraceStart(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1250
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_C
PacketResult Handle_C(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1427
lldb::eStateExited
@ eStateExited
Process has exited and can't be examined.
Definition: lldb-enumerations.h:90
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::HandleInferiorState_Stopped
void HandleInferiorState_Stopped(NativeProcessProtocol *process)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1002
lldb_private::NativeProcessProtocol::Extension::multiprocess
@ multiprocess
lldb_private::MainLoopBase
Definition: MainLoopBase.h:31
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::StopSTDIOForwarding
void StopSTDIOForwarding()
Definition: GDBRemoteCommunicationServerLLGS.cpp:1182
lldb::eFormatVectorOfSInt8
@ eFormatVectorOfSInt8
Definition: lldb-enumerations.h:180
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_QSetDisableASLR
PacketResult Handle_QSetDisableASLR(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1379
lldb_private::NativeProcessProtocol::Kill
virtual Status Kill()=0
lldb::eStateStopped
@ eStateStopped
Process or thread is stopped and can be examined.
Definition: lldb-enumerations.h:84
lldb_private::MemoryRegionInfo::GetWritable
OptionalBool GetWritable() const
Definition: MemoryRegionInfo.h:44
lldb_private::Communication::SetConnection
void SetConnection(std::unique_ptr< Connection > connection)
Sets the connection that it to be used by this class.
Definition: Communication.cpp:423
lldb_private::NativeProcessProtocol::SetCurrentThreadID
void SetCurrentThreadID(lldb::tid_t tid)
Definition: NativeProcessProtocol.h:205
lldb::eRegisterKindEHFrame
@ eRegisterKindEHFrame
the register numbers seen in eh_frame
Definition: lldb-enumerations.h:228
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::m_saved_registers_mutex
std::mutex m_saved_registers_mutex
Definition: GDBRemoteCommunicationServerLLGS.h:104
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::m_inferior_prev_state
lldb::StateType m_inferior_prev_state
Definition: GDBRemoteCommunicationServerLLGS.h:102
lldb_private::MemoryRegionInfo::OptionalBool
OptionalBool
Definition: MemoryRegionInfo.h:25
lldb_private::NativeProcessProtocol::TraceGetBinaryData
virtual llvm::Expected< std::vector< uint8_t > > TraceGetBinaryData(const TraceGetBinaryDataRequest &request)
Get binary data given a trace technology and a data identifier.
Definition: NativeProcessProtocol.h:353
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::HandleInferiorState_Exited
void HandleInferiorState_Exited(NativeProcessProtocol *process)
Definition: GDBRemoteCommunicationServerLLGS.cpp:978
LLDB_REGNUM_GENERIC_FLAGS
#define LLDB_REGNUM_GENERIC_FLAGS
Definition: lldb-defines.h:55
lldb_private::FileSpec
Definition: FileSpec.h:56
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
LLDB_INVALID_SIGNAL_NUMBER
#define LLDB_INVALID_SIGNAL_NUMBER
Definition: lldb-defines.h:84
lldb_private::Status::Success
bool Success() const
Test for success condition.
Definition: Status.cpp:288
lldb_private::StreamString::GetSize
size_t GetSize() const
Definition: StreamString.cpp:38
lldb::eEncodingSint
@ eEncodingSint
signed integer
Definition: lldb-enumerations.h:149
lldb::eFormatVectorOfUInt32
@ eFormatVectorOfUInt32
Definition: lldb-enumerations.h:185
StringExtractorGDBRemote::eServerPacketType_QSaveRegisterState
@ eServerPacketType_QSaveRegisterState
Definition: StringExtractorGDBRemote.h:100
StringExtractor::Peek
const char * Peek()
Definition: StringExtractor.h:100
lldb::eStateCrashed
@ eStateCrashed
Process or thread has crashed and can be examined.
Definition: lldb-enumerations.h:88
StringExtractorGDBRemote::eServerPacketType_c
@ eServerPacketType_c
Definition: StringExtractorGDBRemote.h:143
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::SendProcessOutput
void SendProcessOutput()
Definition: GDBRemoteCommunicationServerLLGS.cpp:1186
lldb::eStopReasonProcessorTrace
@ eStopReasonProcessorTrace
Definition: lldb-enumerations.h:251
ProcessGDBRemote.h
LLDBAssert.h
lldb_private::NativeRegisterContext::ConvertRegisterKindToRegisterNumber
uint32_t ConvertRegisterKindToRegisterNumber(uint32_t kind, uint32_t num) const
Definition: NativeRegisterContext.cpp:425
lldb_private::MemoryRegionInfo::GetExecutable
OptionalBool GetExecutable() const
Definition: MemoryRegionInfo.h:46
StringExtractorGDBRemote::eServerPacketType_qMemTags
@ eServerPacketType_qMemTags
Definition: StringExtractorGDBRemote.h:173
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::SetSTDIOFileDescriptor
Status SetSTDIOFileDescriptor(int fd)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1138
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_vAttachWait
PacketResult Handle_vAttachWait(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3178
StringExtractorGDBRemote::eServerPacketType_Z
@ eServerPacketType_Z
Definition: StringExtractorGDBRemote.h:160
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
lldb_private::NativeProcessProtocol::ReadMemoryTags
virtual Status ReadMemoryTags(int32_t type, lldb::addr_t addr, size_t len, std::vector< uint8_t > &tags)
Definition: NativeProcessProtocol.cpp:56
lldb_private::ConstString::GetStringRef
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:202
StringExtractorGDBRemote::eServerPacketType_QSetDisableASLR
@ eServerPacketType_QSetDisableASLR
Definition: StringExtractorGDBRemote.h:72
Log.h
StringExtractorGDBRemote::eServerPacketType_qThreadStopInfo
@ eServerPacketType_qThreadStopInfo
Definition: StringExtractorGDBRemote.h:124
StringExtractorGDBRemote::eServerPacketType_qWatchpointSupportInfo
@ eServerPacketType_qWatchpointSupportInfo
Definition: StringExtractorGDBRemote.h:126
lldb_private::ResumeAction::state
lldb::StateType state
Definition: Debug.h:23
Args.h
lldb_private::NativeProcessProtocol::Factory::Launch
virtual llvm::Expected< std::unique_ptr< NativeProcessProtocol > > Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate, MainLoop &mainloop) const =0
Launch a process for debugging.
lldb_private::NativeProcessProtocol::WriteMemory
virtual Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written)=0
MemoryRegionInfo.h
lldb_private::NativeThreadProtocol::GetRegisterContext
virtual NativeRegisterContext & GetRegisterContext()=0
lldb::eStopReasonWatchpoint
@ eStopReasonWatchpoint
Definition: lldb-enumerations.h:244
UnimplementedError.h
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qXfer
PacketResult Handle_qXfer(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:2960
lldb_private::RegisterValue::GetBytes
const void * GetBytes() const
Definition: RegisterValue.cpp:693
lldb::eStopReasonNone
@ eStopReasonNone
Definition: lldb-enumerations.h:241
StringExtractorGDBRemote::eServerPacketType_jLLDBTraceGetBinaryData
@ eServerPacketType_jLLDBTraceGetBinaryData
Definition: StringExtractorGDBRemote.h:171
lldb_private::NativeRegisterContext::GetRegisterInfoAtIndex
virtual const RegisterInfo * GetRegisterInfoAtIndex(uint32_t reg) const =0
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::m_xfer_buffer_map
llvm::StringMap< std::unique_ptr< llvm::MemoryBuffer > > m_xfer_buffer_map
Definition: GDBRemoteCommunicationServerLLGS.h:103
lldb_private::Status::Fail
bool Fail() const
Test for error condition.
Definition: Status.cpp:182
lldb_private::ProcessInstanceInfoMatch::GetProcessInfo
ProcessInstanceInfo & GetProcessInfo()
Definition: ProcessInfo.h:174
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::ReadXferObject
llvm::Expected< std::unique_ptr< llvm::MemoryBuffer > > ReadXferObject(llvm::StringRef object, llvm::StringRef annex)
Definition: GDBRemoteCommunicationServerLLGS.cpp:2906
StringExtractorGDBRemote::eServerPacketType_vCont_actions
@ eServerPacketType_vCont_actions
Definition: StringExtractorGDBRemote.h:138
lldb_private::StreamString::GetData
const char * GetData() const
Definition: StreamString.h:43
Socket.h
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::MaybeCloseInferiorTerminalConnection
void MaybeCloseInferiorTerminalConnection()
Definition: GDBRemoteCommunicationServerLLGS.cpp:3659
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::m_next_saved_registers_id
uint32_t m_next_saved_registers_id
Definition: GDBRemoteCommunicationServerLLGS.h:106
lldb::eStateLaunching
@ eStateLaunching
Process is in the process of launching.
Definition: lldb-enumerations.h:79
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::m_process_launch_error
Status m_process_launch_error
Definition: GDBRemoteCommunicationServerCommon.h:36
StreamString.h
lldb_private::NativeRegisterContext::GetRegisterSetNameForRegisterAtIndex
const char * GetRegisterSetNameForRegisterAtIndex(uint32_t reg_index) const
Definition: NativeRegisterContext.cpp:97
lldb_private::MemoryRegionInfo::eYes
@ eYes
Definition: MemoryRegionInfo.h:25
lldb::eStopReasonInstrumentation
@ eStopReasonInstrumentation
Definition: lldb-enumerations.h:250
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::RegisterMemberFunctionHandler
void RegisterMemberFunctionHandler(StringExtractorGDBRemote::ServerPacketType packet_type, PacketResult(T::*handler)(StringExtractorGDBRemote &packet))
Definition: GDBRemoteCommunicationServerCommon.h:119
StringExtractorGDBRemote::eServerPacketType_jLLDBTraceGetState
@ eServerPacketType_jLLDBTraceGetState
Definition: StringExtractorGDBRemote.h:170
StringExtractorGDBRemote::eServerPacketType_QRestoreRegisterState
@ eServerPacketType_QRestoreRegisterState
Definition: StringExtractorGDBRemote.h:99
lldb_private::ThreadStopInfo::reason
lldb::StopReason reason
Definition: Debug.h:132
lldb_private::NativeProcessProtocol::GetID
lldb::pid_t GetID() const
Definition: NativeProcessProtocol.h:172
lldb::eEncodingUint
@ eEncodingUint
unsigned integer
Definition: lldb-enumerations.h:148
lldb_private::ConstString
Definition: ConstString.h:40
StringExtractorGDBRemote::eServerPacketType_g
@ eServerPacketType_g
Definition: StringExtractorGDBRemote.h:146
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_jThreadsInfo
PacketResult Handle_jThreadsInfo(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3340
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::NativeThreadProtocol::GetStopReason
virtual bool GetStopReason(ThreadStopInfo &stop_info, std::string &description)=0
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_QListThreadsInStopReply
PacketResult Handle_QListThreadsInStopReply(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1420
lldb_private::process_gdb_remote::eWatchpointRead
@ eWatchpointRead
Definition: GDBRemoteCommunication.h:41
GDBRemote.h
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::m_continue_tid
lldb::tid_t m_continue_tid
Definition: GDBRemoteCommunicationServerLLGS.h:92
lldb_private::ProcessLaunchInfo::SetUpPtyRedirection
llvm::Error SetUpPtyRedirection()
Definition: ProcessLaunchInfo.cpp:213
lldb_private::process_gdb_remote::GDBRemoteCommunicationServer::SendJSONResponse
PacketResult SendJSONResponse(const llvm::json::Value &value)
Serialize and send a JSON object response.
lldb_private::NativeRegisterContext::GetExpeditedRegisters
virtual std::vector< uint32_t > GetExpeditedRegisters(ExpeditedRegs expType) const
Definition: NativeRegisterContext.cpp:441
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::ClearProcessSpecificData
void ClearProcessSpecificData()
Definition: GDBRemoteCommunicationServerLLGS.cpp:3754
lldb::eConnectionStatusTimedOut
@ eConnectionStatusTimedOut
Request timed out.
Definition: lldb-enumerations.h:299
StringExtractorGDBRemote::eServerPacketType__M
@ eServerPacketType__M
Definition: StringExtractorGDBRemote.h:163
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle__M
PacketResult Handle__M(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:2310
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::AttachToProcess
Status AttachToProcess(lldb::pid_t pid)
Attach to a process.
Definition: GDBRemoteCommunicationServerLLGS.cpp:325
lldb::ConnectionStatus
ConnectionStatus
Connection Status Types.
Definition: lldb-enumerations.h:295
StringExtractorGDBRemote::eServerPacketType_qXfer
@ eServerPacketType_qXfer
Definition: StringExtractorGDBRemote.h:128
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_QSetWorkingDir
PacketResult Handle_QSetWorkingDir(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1390
lldb::eFormatDecimal
@ eFormatDecimal
Definition: lldb-enumerations.h:167
lldb::eConnectionStatusInterrupted
@ eConnectionStatusInterrupted
Interrupted read.
Definition: lldb-enumerations.h:303
StringExtractor::GetHexBytesAvail
size_t GetHexBytesAvail(llvm::MutableArrayRef< uint8_t > dest)
Definition: StringExtractor.cpp:287
lldb_private::RegisterValue::kMaxRegisterByteSize
@ kMaxRegisterByteSize
Definition: RegisterValue.h:31
lldb::eStateDetached
@ eStateDetached
Process has been detached and can't be examined.
Definition: lldb-enumerations.h:89
lldb_private::MemoryRegionInfo::GetName
ConstString GetName() const
Definition: MemoryRegionInfo.h:50
ConnectionFileDescriptor.h
lldb_private::ThreadStopInfo::exception
struct lldb_private::ThreadStopInfo::@13::@15 exception
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_P
PacketResult Handle_P(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1997
lldb_private::NativeProcessProtocol::Extension::vfork
@ vfork
HostInfo.h
lldb_private::NativeProcessProtocol::SetEnabledExtensions
virtual void SetEnabledExtensions(Extension flags)
Method called in order to propagate the bitmap of protocol extensions supported by the client.
Definition: NativeProcessProtocol.h:370
lldb::eFormatVectorOfUInt16
@ eFormatVectorOfUInt16
Definition: lldb-enumerations.h:183
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_QMemTags
PacketResult Handle_QMemTags(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3537
StringExtractor::GetChar
char GetChar(char fail_value='\0')
Definition: StringExtractor.cpp:45
lldb_private::NativeRegisterContext::ReadAllRegisterValues
virtual Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp)=0
lldb_private::process_gdb_remote::GDBRemoteCommunicationServer::m_exit_now
bool m_exit_now
Definition: GDBRemoteCommunicationServer.h:50
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
StringExtractorGDBRemote::GetPidTid
llvm::Optional< std::pair< lldb::pid_t, lldb::tid_t > > GetPidTid(lldb::pid_t default_pid)
Definition: StringExtractorGDBRemote.cpp:624
lldb_private::ProcessLaunchInfo::GetWorkingDirectory
const FileSpec & GetWorkingDirectory() const
Definition: ProcessLaunchInfo.cpp:124
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::HandleFeatures
virtual std::vector< std::string > HandleFeatures(const llvm::ArrayRef< llvm::StringRef > client_features) override
Definition: GDBRemoteCommunicationServerLLGS.cpp:3834
lldb_private::ThreadStopInfo::signal
struct lldb_private::ThreadStopInfo::@13::@14 signal
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_z
PacketResult Handle_z(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:2673
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::FindModuleFile
FileSpec FindModuleFile(const std::string &module_path, const ArchSpec &arch) override
Definition: GDBRemoteCommunicationServerLLGS.cpp:3762
lldb_private::Communication::Write
size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status, Status *error_ptr)
The actual write function that attempts to write to the communications protocol.
Definition: Communication.cpp:173
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::LaunchProcess
Status LaunchProcess() override
Launch a process with the current launch settings.
Definition: GDBRemoteCommunicationServerLLGS.cpp:243
lldb_private::Stream::PutChar
size_t PutChar(char ch)
Definition: Stream.cpp:104
lldb_private::process_gdb_remote
Definition: GDBRemoteClientBase.h:17
lldb::eStateUnloaded
@ eStateUnloaded
Process is object is valid, but not currently loaded.
Definition: lldb-enumerations.h:75
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::DataAvailableCallback
void DataAvailableCallback()
Definition: GDBRemoteCommunicationServerLLGS.cpp:1088
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::SendWResponse
PacketResult SendWResponse(NativeProcessProtocol *process)
Definition: GDBRemoteCommunicationServerLLGS.cpp:454
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_jLLDBTraceSupported
PacketResult Handle_jLLDBTraceSupported(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1218
StringExtractorGDBRemote::eServerPacketType_QSetWorkingDir
@ eServerPacketType_QSetWorkingDir
Definition: StringExtractorGDBRemote.h:77
lldb_private::ProcessLaunchInfo::SetLaunchInSeparateProcessGroup
void SetLaunchInSeparateProcessGroup(bool separate)
Definition: ProcessLaunchInfo.cpp:151
lldb_private::NativeProcessProtocol::Extension::fork
@ fork
lldb_private::NativeProcessProtocol::RemoveBreakpoint
virtual Status RemoveBreakpoint(lldb::addr_t addr, bool hardware=false)
Definition: NativeProcessProtocol.cpp:605
lldb_private::process_gdb_remote::GDBRemoteCommunication::PacketResult::Success
@ Success
NativeProcessProtocol.h
lldb_private::ThreadStopInfo
Definition: Debug.h:131
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_vAttachOrWait
PacketResult Handle_vAttachOrWait(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3214
StringExtractorGDBRemote::AllThreads
static constexpr lldb::tid_t AllThreads
Definition: StringExtractorGDBRemote.h:202
lldb_private::NativeProcessProtocol::GetTerminalFileDescriptor
virtual int GetTerminalFileDescriptor()
Definition: NativeProcessProtocol.h:214
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_jLLDBTraceGetBinaryData
PacketResult Handle_jLLDBTraceGetBinaryData(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1289
lldb_private::process_gdb_remote::GDBRemoteCommunicationServer::SendUnimplementedResponse
PacketResult SendUnimplementedResponse(const char *packet)
Definition: GDBRemoteCommunicationServer.cpp:92
lldb_private::NativeProcessProtocol::Extension
Extension
Extension flag constants, returned by Factory::GetSupportedExtensions() and passed to SetEnabledExten...
Definition: NativeProcessProtocol.h:245
StringExtractorGDBRemote::eServerPacketType_P
@ eServerPacketType_P
Definition: StringExtractorGDBRemote.h:154
lldb_private::process_gdb_remote::LLGSArgToURL
std::string LLGSArgToURL(llvm::StringRef url_arg, bool reverse_connect)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3897
StringExtractor::GetU64
uint64_t GetU64(uint64_t fail_value, int base=0)
Definition: StringExtractor.cpp:125
StringExtractor::GetHexByteString
size_t GetHexByteString(std::string &str)
Definition: StringExtractor.cpp:300
StringExtractorGDBRemote::eServerPacketType_vCont
@ eServerPacketType_vCont
Definition: StringExtractorGDBRemote.h:137
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::ReadTid
llvm::Expected< lldb::tid_t > ReadTid(StringExtractorGDBRemote &packet, bool allow_all, lldb::pid_t default_pid)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3802
StringExtractor::GetHexMaxU64
uint64_t GetHexMaxU64(bool little_endian, uint64_t fail_value)
Definition: StringExtractor.cpp:206
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qsThreadInfo
PacketResult Handle_qsThreadInfo(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1858
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::m_continue_process
NativeProcessProtocol * m_continue_process
Definition: GDBRemoteCommunicationServerLLGS.h:94
lldb::eStateStepping
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
Definition: lldb-enumerations.h:86
lldbassert
#define lldbassert(x)
Definition: LLDBAssert.h:15
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::ProcessStateChanged
void ProcessStateChanged(NativeProcessProtocol *process, lldb::StateType state) override
Definition: GDBRemoteCommunicationServerLLGS.cpp:1028
WriteRegisterValueInHexFixedWidth
static void WriteRegisterValueInHexFixedWidth(StreamString &response, NativeRegisterContext &reg_ctx, const RegisterInfo &reg_info, const RegisterValue *reg_value_p, lldb::ByteOrder byte_order)
Definition: GDBRemoteCommunicationServerLLGS.cpp:584
StringExtractorGDBRemote::eServerPacketType_jThreadsInfo
@ eServerPacketType_jThreadsInfo
Definition: StringExtractorGDBRemote.h:108
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::SendStopReasonForState
PacketResult SendStopReasonForState(lldb::StateType process_state)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1692
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::eStopReasonSignal
@ eStopReasonSignal
Definition: lldb-enumerations.h:245
StringExtractorGDBRemote::eServerPacketType_s
@ eServerPacketType_s
Definition: StringExtractorGDBRemote.h:155
GetEncodingNameOrEmpty
static llvm::StringRef GetEncodingNameOrEmpty(const RegisterInfo &reg_info)
Definition: GDBRemoteCommunicationServerLLGS.cpp:491
lldb_private::Stream::PutHex64
size_t PutHex64(uint64_t uvalue, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
Definition: Stream.cpp:272
GetFormatNameOrEmpty
static llvm::StringRef GetFormatNameOrEmpty(const RegisterInfo &reg_info)
Definition: GDBRemoteCommunicationServerLLGS.cpp:506
lldb::eEncodingVector
@ eEncodingVector
vector registers
Definition: lldb-enumerations.h:151
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::eStopReasonExec
@ eStopReasonExec
Program was re-exec'ed.
Definition: lldb-enumerations.h:247
lldb_private::Status
Definition: Status.h:44
lldb_private::process_gdb_remote::eBreakpointHardware
@ eBreakpointHardware
Definition: GDBRemoteCommunication.h:39
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::SetEnabledExtensions
void SetEnabledExtensions(NativeProcessProtocol &process)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3889
lldb_private::Args::GetArgumentAtIndex
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
Definition: Args.cpp:259
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::BuildTargetXml
llvm::Expected< std::unique_ptr< llvm::MemoryBuffer > > BuildTargetXml()
Definition: GDBRemoteCommunicationServerLLGS.cpp:2811
lldb_private::Socket::DecodeHostAndPort
static llvm::Expected< HostAndPort > DecodeHostAndPort(llvm::StringRef host_and_port)
Definition: Socket.cpp:186
GetStopReasonString
static const char * GetStopReasonString(StopReason stop_reason)
Definition: GDBRemoteCommunicationServerLLGS.cpp:662
lldb_private::Communication::Read
size_t Read(void *dst, size_t dst_len, const Timeout< std::micro > &timeout, lldb::ConnectionStatus &status, Status *error_ptr)
Read bytes from the current connection.
Definition: Communication.cpp:125
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_vCont_actions
PacketResult Handle_vCont_actions(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1548
uint32_t
LIBLLDB_LOG_BREAKPOINTS
#define LIBLLDB_LOG_BREAKPOINTS
Definition: Logging.h:19
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::XMLEncodeAttributeValue
static std::string XMLEncodeAttributeValue(llvm::StringRef value)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3777
StringExtractorGDBRemote::eServerPacketType_qsThreadInfo
@ eServerPacketType_qsThreadInfo
Definition: StringExtractorGDBRemote.h:109
lldb_private::NativeProcessProtocol::TraceStop
virtual llvm::Error TraceStop(const TraceStopRequest &request)
Stop tracing a live process or its threads.
Definition: NativeProcessProtocol.h:337
x28
@ x28
Definition: CompactUnwindInfo.cpp:1245
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_QThreadSuffixSupported
PacketResult Handle_QThreadSuffixSupported(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1413
NativeThreadProtocol.h
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_vAttach
PacketResult Handle_vAttach(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3142
LLDB_REGNUM_GENERIC_SP
#define LLDB_REGNUM_GENERIC_SP
Definition: lldb-defines.h:52
lldb_private::MainLoop
Definition: MainLoop.h:38
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::FindModuleFile
virtual FileSpec FindModuleFile(const std::string &module_path, const ArchSpec &arch)
Definition: GDBRemoteCommunicationServerCommon.cpp:1307
lldb::eConnectionStatusError
@ eConnectionStatusError
Check GetError() for details.
Definition: lldb-enumerations.h:298
CollectRegNums
static void CollectRegNums(const uint32_t *reg_num, StreamString &response, bool usehex)
Definition: GDBRemoteCommunicationServerLLGS.cpp:572
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb::eStopReasonPlanComplete
@ eStopReasonPlanComplete
Definition: lldb-enumerations.h:248
lldb_private::NativeRegisterContext::GetUserRegisterCount
virtual uint32_t GetUserRegisterCount() const =0
lldb_private::NativeProcessProtocol
Definition: NativeProcessProtocol.h:47
lldb_private::MemoryRegionInfo::eDontKnow
@ eDontKnow
Definition: MemoryRegionInfo.h:25
lldb_private::ResumeAction::tid
lldb::tid_t tid
Definition: Debug.h:20
lldb_private::endian::InlHostByteOrder
lldb::ByteOrder InlHostByteOrder()
Definition: Endian.h:25
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::m_extensions_supported
NativeProcessProtocol::Extension m_extensions_supported
Definition: GDBRemoteCommunicationServerLLGS.h:110
StringExtractorGDBRemote::eServerPacketType_interrupt
@ eServerPacketType_interrupt
Definition: StringExtractorGDBRemote.h:51
lldb_private::NativeThreadProtocol::GetID
lldb::tid_t GetID() const
Definition: NativeThreadProtocol.h:39
lldb_private::Host::GetProcessInfo
static bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info)
Definition: freebsd/Host.cpp:230
GetJSONThreadsInfo
static llvm::Expected< json::Array > GetJSONThreadsInfo(NativeProcessProtocol &process, bool abridged)
Definition: GDBRemoteCommunicationServerLLGS.cpp:695
lldb_private::NativeProcessProtocol::GetState
lldb::StateType GetState() const
Definition: NativeProcessProtocol.cpp:693
lldb_private::StreamGDBRemote
Definition: GDBRemote.h:27
StringExtractorGDBRemote::eServerPacketType_qFileLoadAddress
@ eServerPacketType_qFileLoadAddress
Definition: StringExtractorGDBRemote.h:68
lldb_private::Range::GetByteSize
SizeType GetByteSize() const
Definition: RangeMap.h:71
lldb_private::Stream::AsRawOstream
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:357
lldb_private::NativeProcessProtocol::SetBreakpoint
virtual Status SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware)=0
lldb_private::NativeProcessProtocol::TraceGetState
virtual llvm::Expected< llvm::json::Value > TraceGetState(llvm::StringRef type)
Get the current tracing state of the process and its threads.
Definition: NativeProcessProtocol.h:345
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::HandleFeatures
virtual std::vector< std::string > HandleFeatures(llvm::ArrayRef< llvm::StringRef > client_features)
Definition: GDBRemoteCommunicationServerCommon.cpp:1342
lldb_private::process_gdb_remote::GDBRemoteCommunication::SendPacketNoLock
PacketResult SendPacketNoLock(llvm::StringRef payload)
Definition: GDBRemoteCommunication.cpp:116
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_qGetWorkingDir
PacketResult Handle_qGetWorkingDir(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1400
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::DidExec
void DidExec(NativeProcessProtocol *process) override
Definition: GDBRemoteCommunicationServerLLGS.cpp:1075
lldb_private::Communication::IsConnected
bool IsConnected() const
Check if the connection is valid.
Definition: Communication.cpp:116
StringExtractor::GetS32
int32_t GetS32(int32_t fail_value, int base=0)
Definition: StringExtractor.cpp:110
ProcessGDBRemoteLog.h
lldb::eStopReasonBreakpoint
@ eStopReasonBreakpoint
Definition: lldb-enumerations.h:243
lldb_private::NativeProcessProtocol::Factory::GetSupportedExtensions
virtual Extension GetSupportedExtensions() const
Get the bitmask of extensions supported by this process plugin.
Definition: NativeProcessProtocol.h:310
StringExtractorGDBRemote::eServerPacketType_jLLDBTraceStop
@ eServerPacketType_jLLDBTraceStop
Definition: StringExtractorGDBRemote.h:169
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
lldb_private::process_gdb_remote::GDBRemoteCommunicationServer::SendOKResponse
PacketResult SendOKResponse()
Definition: GDBRemoteCommunicationServer.cpp:149
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:240
lldb_private::NativeProcessProtocol::Resume
virtual Status Resume(const ResumeActionList &resume_actions)=0
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_vCont
PacketResult Handle_vCont(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1557
lldb_private::NativeProcessProtocol::GetExitStatus
virtual llvm::Optional< WaitStatus > GetExitStatus()
Definition: NativeProcessProtocol.cpp:68
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private::NativeProcessProtocol::DeallocateMemory
virtual llvm::Error DeallocateMemory(lldb::addr_t addr)
Definition: NativeProcessProtocol.h:129
lldb_private::ThreadStopInfo::fork
struct lldb_private::ThreadStopInfo::@13::@16 fork
lldb::eFormatBinary
@ eFormatBinary
Definition: lldb-enumerations.h:159
lldb_private::MemoryRegionInfo::GetRange
RangeType & GetRange()
Definition: MemoryRegionInfo.h:36
lldb_private::FileSystem::Instance
static FileSystem & Instance()
Definition: common/FileSystem.cpp:45
lldb_private::process_gdb_remote::eBreakpointSoftware
@ eBreakpointSoftware
Definition: GDBRemoteCommunication.h:38
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::SetLaunchInfo
void SetLaunchInfo(const ProcessLaunchInfo &info)
Definition: GDBRemoteCommunicationServerLLGS.cpp:239
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_jLLDBTraceGetState
PacketResult Handle_jLLDBTraceGetState(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1271
lldb::eConnectionStatusSuccess
@ eConnectionStatusSuccess
Success.
Definition: lldb-enumerations.h:296
LLDB_REGNUM_GENERIC_ARG4
#define LLDB_REGNUM_GENERIC_ARG4
Definition: lldb-defines.h:62
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerCommon::CreateProcessInfoResponse_DebugServerStyle
static void CreateProcessInfoResponse_DebugServerStyle(const ProcessInstanceInfo &proc_info, StreamString &response)
Definition: GDBRemoteCommunicationServerCommon.cpp:1236
StringExtractor::GetHexBytes
size_t GetHexBytes(llvm::MutableArrayRef< uint8_t > dest, uint8_t fail_fill_value)
Definition: StringExtractor.cpp:266
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix
NativeThreadProtocol * GetThreadFromSuffix(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:3684
lldb_private::ResumeActionList
Definition: Debug.h:33
lldb_private::process_gdb_remote::GDBRemoteCommunication::PacketResult::ErrorReplyTimeout
@ ErrorReplyTimeout
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::Handle_jLLDBTraceStop
PacketResult Handle_jLLDBTraceStop(StringExtractorGDBRemote &packet)
Definition: GDBRemoteCommunicationServerLLGS.cpp:1230
lldb_private::process_gdb_remote::GDBRemoteCommunicationServerLLGS::RegisterPacketHandlers
void RegisterPacketHandlers()
Definition: GDBRemoteCommunicationServerLLGS.cpp:80
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::eFormatHex
@ eFormatHex
Definition: lldb-enumerations.h:169<