11#include "lldb/Host/Config.h"
46#include "llvm/Support/ErrorExtras.h"
47#include "llvm/Support/ErrorHandling.h"
48#include "llvm/Support/JSON.h"
49#include "llvm/Support/ScopedPrinter.h"
50#include "llvm/TargetParser/Triple.h"
65enum GDBRemoteServerError {
68 eErrorNoProcess = eErrorFirst,
231 eServerPacketType_jAcceleratorPluginBreakpointHit,
248 bool &interrupt,
bool &quit) {
284 "%s: no process command line specified to launch", __FUNCTION__);
286 const bool should_forward_stdio =
293 if (should_forward_stdio) {
298 win_size.
cols == 0 && win_size.
rows == 0) {
314 "process but one already exists");
324 SetEnabledExtensions(*m_current_process);
331 if (should_forward_stdio) {
336 "pid = {0}: setting up stdout/stderr redirection via $O "
337 "gdb-remote commands",
338 m_current_process->GetID());
341 auto terminal_fd = m_current_process->GetTerminalFileDescriptor();
342 if (terminal_fd >= 0) {
344 "ProcessGDBRemoteCommunicationServerLLGS::%s setting "
345 "inferior STDIO fd to %d",
346 __FUNCTION__, terminal_fd);
347 Status status = SetSTDIOFileDescriptor(terminal_fd);
352 "ProcessGDBRemoteCommunicationServerLLGS::%s ignoring "
353 "inferior STDIO since terminal fd reported as %d",
354 __FUNCTION__, terminal_fd);
358 "pid = {0} skipping stdout/stderr redirection via $O: inferior "
359 "will communicate over client-provided file descriptors",
360 m_current_process->GetID());
363 printf(
"Launched '%s' as process %" PRIu64
"...\n",
364 m_process_launch_info.GetArguments().GetArgumentAtIndex(0),
365 m_current_process->GetID());
372 LLDB_LOGF(log,
"GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64,
379 "cannot attach to process %" PRIu64
380 " when another process with pid %" PRIu64
" is being debugged.",
387 llvm::errs() << llvm::formatv(
"failed to attach to process {0}: {1}\n", pid,
395 SetEnabledExtensions(*m_current_process);
398 auto terminal_fd = m_current_process->GetTerminalFileDescriptor();
399 if (terminal_fd >= 0) {
401 "ProcessGDBRemoteCommunicationServerLLGS::%s setting "
402 "inferior STDIO fd to %d",
403 __FUNCTION__, terminal_fd);
404 Status status = SetSTDIOFileDescriptor(terminal_fd);
409 "ProcessGDBRemoteCommunicationServerLLGS::%s ignoring "
410 "inferior STDIO since terminal fd reported as %d",
411 __FUNCTION__, terminal_fd);
414 printf(
"Attached to process %" PRIu64
"...\n", pid);
419 llvm::StringRef process_name,
bool include_existing) {
422 std::chrono::milliseconds polling_interval = std::chrono::milliseconds(1);
428 process_name, llvm::sys::path::Style::native);
431 if (include_existing) {
432 LLDB_LOG(log,
"including existing processes in search");
436 LLDB_LOG(log,
"placed '{0}' processes in the exclusion list.",
437 exclusion_list.size());
440 LLDB_LOG(log,
"waiting for '{0}' to appear", process_name);
442 auto is_in_exclusion_list =
444 for (
auto &excluded : exclusion_list) {
445 if (excluded.GetProcessID() == info.GetProcessID())
453 loop_process_list.clear();
456 llvm::erase_if(loop_process_list, is_in_exclusion_list);
459 if (loop_process_list.size() == 1) {
460 auto matching_process_pid = loop_process_list[0].GetProcessID();
461 LLDB_LOG(log,
"found pid {0}", matching_process_pid);
466 if (loop_process_list.size() > 1) {
469 "Multiple executables with name: '{0}' found. Pids: ",
471 for (
size_t i = 0; i < loop_process_list.size() - 1; ++i) {
472 error_stream.
Format(
"{0}, ", loop_process_list[i].GetProcessID());
474 error_stream.
Format(
"{0}.", loop_process_list.back().GetProcessID());
482 LLDB_LOG(log,
"sleep {0} seconds", polling_interval);
483 std::this_thread::sleep_for(polling_interval);
489 assert(process &&
"process cannot be NULL");
492 "GDBRemoteCommunicationServerLLGS::%s called with "
493 "NativeProcessProtocol pid %" PRIu64
", current state: %s",
494 __FUNCTION__, process->
GetID(),
501 assert(process &&
"process cannot be NULL");
507 LLDB_LOG(log,
"pid = {0}, failed to retrieve process exit status",
512 response.
PutHex8(GDBRemoteServerError::eErrorExitStatus);
516 LLDB_LOG(log,
"pid = {0}, returning exit type {1}", process->
GetID(),
525 response.
Format(
"{0:g}", *wait_status);
528 response.
Format(
";process:{0:x-}", process->
GetID());
536 uint32_t buf_size,
bool swap) {
539 for (i = buf_size - 1; i >= 0; i--)
542 for (i = 0; i < buf_size; i++)
563 switch (reg_info.
format) {
573 return "bytes-with-ascii";
577 return "char-printable";
589 return "hex-uppercase";
605 return "vector-char";
607 return "vector-sint64";
609 return "vector-float16";
611 return "vector-float64";
613 return "vector-sint8";
615 return "vector-uint8";
617 return "vector-sint16";
619 return "vector-uint16";
621 return "vector-sint32";
623 return "vector-uint32";
625 return "vector-float32";
627 return "vector-uint64";
629 return "vector-uint128";
631 return "complex-integer";
635 return "address-info";
639 return "instruction";
647 llvm_unreachable(
"Unknown register format");
692 response.
Printf(
"%" PRIx32, *reg_num);
694 response.
Printf(
"%" PRIu32, *reg_num);
706 reg_value_p = ®_value;
717 std::vector<uint8_t> zeros(reg_info.
byte_size,
'\0');
723static std::optional<json::Object>
729 json::Object register_object;
731#ifdef LLDB_JTHREADSINFO_FULL_REGISTER_SET
732 const auto expedited_regs =
735 const auto expedited_regs =
738 if (expedited_regs.empty())
741 for (
auto ®_num : expedited_regs) {
744 if (reg_info_p ==
nullptr) {
746 "%s failed to get register info for register index %" PRIu32,
747 __FUNCTION__, reg_num);
758 LLDB_LOGF(log,
"%s failed to read register '%s' index %" PRIu32
": %s",
760 reg_info_p->
name ? reg_info_p->
name :
"<unnamed-register>",
761 reg_num,
error.AsCString());
769 register_object.try_emplace(llvm::to_string(reg_num),
773 return register_object;
777 switch (stop_reason) {
791 return "processor trace";
799 return "async interrupt";
811static llvm::Expected<json::Array>
815 json::Array threads_array;
822 std::string description;
823 if (!thread.GetStopReason(tid_stop_info, description))
824 return llvm::createStringError(
"failed to get stop reason");
826 const int signum = tid_stop_info.
signo;
828 "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
830 " got signal signo = %d, reason = %d, exc_type = %" PRIu64,
831 __FUNCTION__, process.
GetID(), tid, signum, tid_stop_info.
reason,
834 json::Object thread_obj;
838 thread_obj.try_emplace(
"registers", std::move(*registers));
841 thread_obj.try_emplace(
"tid",
static_cast<int64_t
>(tid));
844 thread_obj.try_emplace(
"signal", signum);
846 const std::string thread_name = thread.GetName();
847 if (!thread_name.empty())
848 thread_obj.try_emplace(
"name", thread_name);
852 thread_obj.try_emplace(
"reason", stop_reason);
854 if (!description.empty())
855 thread_obj.try_emplace(
"description", description);
859 thread_obj.try_emplace(
862 json::Array medata_array;
865 medata_array.push_back(
868 thread_obj.try_emplace(
"medata", std::move(medata_array));
870 threads_array.push_back(std::move(thread_obj));
872 return threads_array;
882 LLDB_LOG(log,
"preparing packet for pid {0} tid {1}", process.
GetID(),
888 std::string description;
889 if (!thread.GetStopReason(tid_stop_info, description))
900 int signum = tid_stop_info.
signo;
903 "pid {0}, tid {1}, got signal signo = {2}, reason = {3}, exc_type = {4}",
904 process.
GetID(), thread.GetID(), signum,
int(tid_stop_info.
reason),
908 response.
PutHex8(signum & 0xff);
916 const std::string thread_name = thread.GetName();
917 if (!thread_name.empty()) {
918 size_t thread_name_len = thread_name.length();
920 if (::strcspn(thread_name.c_str(),
"$#+-;:") == thread_name_len) {
942 uint32_t thread_num = 0;
946 response.
Printf(
"%" PRIx64, listed_thread.GetID());
956 if (thread_num > 1) {
957 const bool threads_with_valid_stop_info_only =
true;
963 unescaped_response.
AsRawOstream() << std::move(*threads_info);
968 "failed to prepare a jstopinfo field for pid {1}: {0}",
974 char delimiter =
':';
986 LLDB_LOGF(log,
"%s failed to read register '%s' index %" PRIu32
": %s",
988 reg_info_p->
name ? reg_info_p->
name :
"<unnamed-register>",
989 reg_to_read,
error.AsCString());
1008 const auto expedited_regs =
1011 for (
auto ®_num : expedited_regs) {
1015 if (reg_info_p !=
nullptr && reg_info_p->
value_regs ==
nullptr) {
1018 if (
error.Success()) {
1019 response.
Printf(
"%.02x:", reg_num);
1025 "GDBRemoteCommunicationServerLLGS::%s failed to read "
1026 "register '%s' index %" PRIu32
": %s",
1028 reg_info_p->
name ? reg_info_p->
name :
"<unnamed-register>",
1029 reg_num,
error.AsCString());
1035 if (reason_str !=
nullptr) {
1036 response.
Printf(
"reason:%s;", reason_str);
1039 if (!description.empty()) {
1070 response.
Printf(
"%s:p%" PRIx64
".%" PRIx64
";", reason_str,
1092 if (response.
Empty())
1112 if (listed_thread.GetID() != thread_to_skip) {
1114 if (!stop_reply.
Empty())
1122 assert(process &&
"process cannot be NULL");
1125 LLDB_LOGF(log,
"GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
1131 "GDBRemoteCommunicationServerLLGS::%s failed to send stop "
1132 "notification for PID %" PRIu64
", state: eStateExited",
1133 __FUNCTION__, process->
GetID());
1164 assert(process &&
"process cannot be NULL");
1167 LLDB_LOGF(log,
"GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
1173 "GDBRemoteCommunicationServerLLGS::%s failed to send stop "
1174 "notification for PID %" PRIu64
", state: eStateExited",
1175 __FUNCTION__, process->
GetID());
1181 assert(process &&
"process cannot be NULL");
1184 "GDBRemoteCommunicationServerLLGS::%s called with "
1185 "NativeProcessProtocol pid %" PRIu64
", state: %s",
1213 "GDBRemoteCommunicationServerLLGS::%s didn't handle state "
1214 "change for pid %" PRIu64
", new state: %s",
1226 std::unique_ptr<NativeProcessProtocol> child_process) {
1236 llvm::StringRef data) {
1265 bool interrupt =
false;
1270 std::chrono::microseconds(0),
error, interrupt, done);
1276 "GDBRemoteCommunicationServerLLGS::%s processing a packet "
1278 __FUNCTION__,
error.AsCString());
1286 std::unique_ptr<Connection> connection) {
1287 IOObjectSP read_object_sp = connection->GetReadObject();
1299 const llvm::json::Value &value) {
1300 std::string json_string;
1301 raw_string_ostream os(json_string);
1306 escaped_response.
PutEscapedBytes(json_string.c_str(), json_string.size());
1313 if ((buffer ==
nullptr) || (len == 0)) {
1332 std::unique_ptr<ConnectionFileDescriptor> conn_up(
1344 "failed to set connection for inferior I/O communication");
1366 LLDB_LOG(log,
"Failed to set up stdio forwarding: {0}",
error);
1380 buffer,
sizeof buffer, std::chrono::microseconds(0), status, &
error);
1391 "GDBRemoteCommunicationServerLLGS::%s Stopping stdio "
1392 "forwarding as communication returned status %d (error: "
1394 __FUNCTION__, status,
error.AsCString());
1426 Expected<TraceStopRequest> stop_request =
1427 json::parse<TraceStopRequest>(packet.
Peek(),
"TraceStopRequest");
1447 Expected<TraceStartRequest> request =
1448 json::parse<TraceStartRequest>(packet.
Peek(),
"TraceStartRequest");
1468 Expected<TraceGetStateRequest> request =
1469 json::parse<TraceGetStateRequest>(packet.
Peek(),
"TraceGetStateRequest");
1486 llvm::Expected<TraceGetBinaryDataRequest> request =
1487 llvm::json::parse<TraceGetBinaryDataRequest>(packet.
Peek(),
1488 "TraceGetBinaryDataRequest");
1492 if (Expected<std::vector<uint8_t>> bytes =
1509 std::vector<std::string> structured_data_plugins =
1513 llvm::json::Value(llvm::json::Array(structured_data_plugins)));
1570 LLDB_LOG(log,
"No debugged process found.");
1576 LLDB_LOG(log,
"Killing process {0}", it->first);
1579 LLDB_LOG(log,
"Failed to kill debugged process {0}: {1}", it->first,
1600 "vKill failed to parse the process id");
1618 packet.
SetFilePos(::strlen(
"QSetDisableASLR:"));
1629 packet.
SetFilePos(::strlen(
"QSetWorkingDir:"));
1671 LLDB_LOG(log,
"process {0} cannot be resumed (state={1})", process.
GetID(),
1690 LLDB_LOGF(log,
"GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
1695 "GDBRemoteCommunicationServerLLGS::%s no debugged process "
1707 const uint32_t signo =
1708 packet.
GetHexMaxU32(
false, std::numeric_limits<uint32_t>::max());
1709 if (signo == std::numeric_limits<uint32_t>::max())
1715 if (*packet.
Peek() ==
';')
1719 packet,
"unexpected content after $C{signal-number}");
1725 LLDB_LOG(log,
"process cannot be resumed (state={0})",
1746 static_cast<int>(signo)};
1750 resume_actions.
Append(action);
1756 LLDB_LOG(log,
"failed to send signal for process {0}: {1}",
1777 LLDB_LOGF(log,
"GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
1782 const bool has_continue_address = (packet.
GetBytesLeft() > 0);
1783 if (has_continue_address) {
1784 LLDB_LOG(log,
"not implemented for c[address] variant [{0} remains]",
1792 "GDBRemoteCommunicationServerLLGS::%s no debugged process "
1813 response.
Printf(
"vCont;c;C;s;S;t");
1834 LLDB_LOGF(log,
"GDBRemoteCommunicationServerLLGS::%s handling vCont packet",
1841 "GDBRemoteCommunicationServerLLGS::%s missing action from "
1847 if (::strcmp(packet.
Peek(),
";s") == 0) {
1853 std::unordered_map<lldb::pid_t, ResumeActionList> thread_actions;
1865 const char action = packet.
GetChar();
1869 if (thread_action.
signal == 0)
1871 packet,
"Could not parse signal in vCont packet C action");
1881 if (thread_action.
signal == 0)
1883 packet,
"Could not parse signal in vCont packet S action");
1914 pid = pid_tid->first;
1915 tid = pid_tid->second;
1921 packet,
"'t' action not supported for individual threads");
1927 LLDB_LOG(log,
"no process selected via Hc");
1936 thread_action.
tid = tid;
1941 packet,
"vCont: p-1 is not valid with a specific tid");
1943 thread_actions[process_it.first].Append(thread_action);
1945 thread_actions[pid].Append(thread_action);
1948 assert(thread_actions.size() >= 1);
1949 if (thread_actions.size() > 1 && !
m_non_stop)
1952 "Resuming multiple processes is supported in non-stop mode only");
1954 for (std::pair<lldb::pid_t, ResumeActionList> x : thread_actions) {
1957 LLDB_LOG(log,
"vCont failed for process {0}: process not debugged",
1974 assert(process_it->second.process_up);
1976 if (process_it->second.process_up->IsRunning()) {
1979 Status error = process_it->second.process_up->Interrupt();
1981 LLDB_LOG(log,
"vCont failed to halt process {0}: {1}", x.first,
1986 LLDB_LOG(log,
"halted process {0}", x.first);
1990 assert(thread_actions.size() == 1);
2006 LLDB_LOG(log,
"setting current thread id to {0}", tid);
2015 LLDB_LOG(log,
"setting continue thread id to {0}", tid);
2029 return x.front() !=
'W' && x.front() !=
'X';
2039 if (!stop_reply.
Empty())
2066 bool force_synchronous) {
2083 if (it.second.process_up->IsRunning())
2093 switch (process_state) {
2119 LLDB_LOG(log,
"pid {0}, current state reporting not handled: {1}",
2120 process.
GetID(), process_state);
2145 const uint32_t reg_index =
2146 packet.
GetHexMaxU32(
false, std::numeric_limits<uint32_t>::max());
2147 if (reg_index == std::numeric_limits<uint32_t>::max())
2178 if (!encoding.empty())
2179 response <<
"encoding:" << encoding <<
';';
2182 if (!format.empty())
2183 response <<
"format:" << format <<
';';
2185 const char *
const register_set_name =
2187 if (register_set_name)
2188 response <<
"set:" << register_set_name <<
';';
2192 response.
Printf(
"ehframe:%" PRIu32
";",
2196 response.
Printf(
"dwarf:%" PRIu32
";",
2200 if (!kind_generic.empty())
2201 response <<
"generic:" << kind_generic <<
';';
2226 LLDB_LOG(log,
"iterating over threads of process {0}", process.
GetID());
2228 LLDB_LOG(log,
"iterated thread tid={0}", thread.GetID());
2229 response.
PutChar(had_any ?
',' :
'm');
2242 bool had_any =
false;
2271 LLDB_LOG(log,
"failed, no thread available");
2278 std::vector<uint8_t> regs_buffer;
2283 if (reg_info ==
nullptr) {
2284 LLDB_LOG(log,
"failed to get register info for register index {0}",
2295 LLDB_LOG(log,
"failed to read register at index {0}", reg_num);
2322 const uint32_t reg_index =
2323 packet.
GetHexMaxU32(
false, std::numeric_limits<uint32_t>::max());
2324 if (reg_index == std::numeric_limits<uint32_t>::max()) {
2326 "GDBRemoteCommunicationServerLLGS::%s failed, could not "
2327 "parse register number from request \"%s\"",
2335 LLDB_LOG(log,
"failed, no thread available");
2346 "GDBRemoteCommunicationServerLLGS::%s failed, requested "
2347 "register %" PRIu32
" beyond register count %" PRIu32,
2355 "GDBRemoteCommunicationServerLLGS::%s failed, requested "
2356 "register %" PRIu32
" returned NULL",
2357 __FUNCTION__, reg_index);
2369 "GDBRemoteCommunicationServerLLGS::%s failed, read of "
2370 "requested register %" PRIu32
" (%s) failed: %s",
2371 __FUNCTION__, reg_index, reg_info->
name,
error.AsCString());
2375 const uint8_t *
const data =
2376 static_cast<const uint8_t *
>(reg_value.
GetBytes());
2379 "GDBRemoteCommunicationServerLLGS::%s failed to get data "
2380 "bytes from requested register %" PRIu32,
2381 __FUNCTION__, reg_index);
2386 for (uint32_t i = 0; i < reg_value.
GetByteSize(); ++i)
2402 const uint32_t reg_index =
2403 packet.
GetHexMaxU32(
false, std::numeric_limits<uint32_t>::max());
2404 if (reg_index == std::numeric_limits<uint32_t>::max()) {
2406 "GDBRemoteCommunicationServerLLGS::%s failed, could not "
2407 "parse register number from request \"%s\"",
2415 packet,
"P packet missing '=' char after register number");
2424 "GDBRemoteCommunicationServerLLGS::%s failed, no thread "
2425 "available (thread index 0)",
2435 "GDBRemoteCommunicationServerLLGS::%s failed, requested "
2436 "register %" PRIu32
" returned NULL",
2437 __FUNCTION__, reg_index);
2445 "GDBRemoteCommunicationServerLLGS::%s failed, requested "
2446 "register %" PRIu32
" beyond register count %" PRIu32,
2462 "GDBRemoteCommunicationServerLLGS::%s failed, write of "
2463 "requested register %" PRIu32
" (%s) failed: %s",
2464 __FUNCTION__, reg_index, reg_info->
name,
error.AsCString());
2479 "GDBRemoteCommunicationServerLLGS::%s failed, H command "
2480 "missing {g,c} variant",
2485 const char h_variant = packet.
GetChar();
2487 switch (h_variant) {
2499 "GDBRemoteCommunicationServerLLGS::%s failed, invalid $H variant %c",
2500 __FUNCTION__, h_variant);
2502 "H variant unsupported, should be c or g");
2506 auto pid_tid = packet.
GetPidTid(default_process ? default_process->
GetID()
2518 llvm::createStringError(
"no current process and no PID provided"));
2524 llvm::createStringErrorV(
"no process with PID {0} debugged", pid));
2530 new_process_it->second.process_up->GetThreadByID(tid);
2533 "GDBRemoteCommunicationServerLLGS::%s failed, tid %" PRIu64
2541 switch (h_variant) {
2553 assert(
false &&
"unsupported $H variant - shouldn't get here");
2555 "H variant unsupported, should be c or g");
2570 "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
2613 LLDB_LOG(log,
"failed, no process available");
2640 "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
2663 const uint64_t byte_count = packet.
GetHexMaxU64(
false, 0);
2664 if (byte_count == 0) {
2666 "GDBRemoteCommunicationServerLLGS::%s nothing to read: "
2667 "zero-length packet",
2673 std::string buf(byte_count,
'\0');
2678 size_t bytes_read = 0;
2680 read_addr, &buf[0], byte_count, bytes_read);
2683 "ReadMemoryWithoutTrap({0}) read {1} of {2} requested bytes (error: {3})",
2684 read_addr, byte_count, bytes_read,
error);
2685 if (bytes_read == 0)
2690 char kind = packet.
GetChar(
'?');
2694 assert(kind ==
'm');
2695 for (
size_t i = 0; i < bytes_read; ++i)
2710 "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
2725 Permissions perms = {};
2729 perms |= ePermissionsReadable;
2732 perms |= ePermissionsWritable;
2735 perms |= ePermissionsExecutable;
2759 "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
2787 "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
2810 const uint64_t byte_count = packet.
GetHexMaxU64(
false, 0);
2811 if (byte_count == 0) {
2812 LLDB_LOG(log,
"nothing to write: zero-length packet");
2819 packet,
"Comma sep missing in M packet after byte length");
2822 std::vector<uint8_t> buf(byte_count, 0);
2828 const uint64_t convert_count = packet.
GetHexBytes(buf, 0);
2829 if (convert_count != byte_count) {
2831 "pid {0} mem {1:x}: asked to write {2} bytes, but only found {3} "
2835 "not match hex-encoded content "
2840 size_t bytes_written = 0;
2844 LLDB_LOG(log,
"pid {0} mem {1:x}: failed to write. Error: {2}",
2849 if (bytes_written == 0) {
2850 LLDB_LOG(log,
"pid {0} mem {1:x}: wrote 0 of {2} requested bytes",
2874 "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
2901 "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
2907 packet.
SetFilePos(strlen(
"qMemoryRegionInfo:"));
2928 response.
Printf(
"start:%" PRIx64
";size:%" PRIx64
";",
2972 if (std::optional<unsigned> protection_key = region_info.
GetProtectionKey())
2973 response.
Printf(
"protection-key:%" PRIu32
";", *protection_key);
2980struct UseBreakpoint {
2981 bool want_hardware =
false;
2983struct UseWatchpoint {
2985 static constexpr bool want_hardware =
true;
2987struct InvalidStoppoint {};
2989std::variant<UseBreakpoint, UseWatchpoint, InvalidStoppoint>
2991 switch (stoppoint_type) {
2993 return UseBreakpoint{
false};
2995 return UseBreakpoint{
true};
2997 return UseWatchpoint{ 1};
2999 return UseWatchpoint{ 2};
3001 return UseWatchpoint{ 3};
3003 return InvalidStoppoint();
3005 llvm_unreachable(
"unhandled GDBStoppointType");
3011 llvm::StringRef packet_str) {
3016 LLDB_LOG(log,
"failed, no process available");
3026 "Too short Z packet, missing software/hardware specifier"};
3030 std::variant<UseBreakpoint, UseWatchpoint, InvalidStoppoint> bp_variant =
3031 getBreakpointKind(stoppoint_type);
3032 if (std::holds_alternative<InvalidStoppoint>(bp_variant))
3034 "Z packet had invalid software/hardware specifier"};
3038 "Malformed Z packet, expecting comma after stoppoint type"};
3047 "Malformed Z packet, expecting comma after address"};
3050 const uint32_t size =
3051 packet.
GetHexMaxU32(
false, std::numeric_limits<uint32_t>::max());
3052 if (size == std::numeric_limits<uint32_t>::max())
3054 "Malformed Z packet, failed to parse size argument"};
3057 if (
auto *bp_kind = std::get_if<UseBreakpoint>(&bp_variant)) {
3060 if (
error.Success())
3063 LLDB_LOG(log,
"pid {0} failed to set breakpoint: {1}",
3069 auto wp_kind = std::get<UseWatchpoint>(bp_variant);
3071 addr, size, wp_kind.flags, wp_kind.want_hardware);
3072 if (
error.Success())
3075 LLDB_LOG(log,
"pid {0} failed to set watchpoint: {1}",
3082 llvm::StringRef packet_str) {
3087 LLDB_LOG(log,
"failed, no process available");
3097 "Too short z packet, missing software/hardware specifier"};
3101 std::variant<UseBreakpoint, UseWatchpoint, InvalidStoppoint> bp_variant =
3102 getBreakpointKind(stoppoint_type);
3103 if (std::holds_alternative<InvalidStoppoint>(bp_variant))
3105 "z packet had invalid software/hardware specifier"};
3109 "Malformed z packet, expecting comma after stoppoint type"};
3118 "Malformed z packet, expecting comma after address"};
3130 if (
auto *bp_kind = std::get_if<UseBreakpoint>(&bp_variant)) {
3133 if (
error.Success())
3136 LLDB_LOG(log,
"pid {0} failed to remove breakpoint: {1}",
3142 if (
error.Success())
3145 LLDB_LOG(log,
"pid {0} failed to remove watchpoint: {1}",
3155 using T = std::decay_t<
decltype(arg)>;
3156 static_assert(std::is_same_v<T, BreakpointOK> ||
3157 std::is_same_v<T, BreakpointError> ||
3158 std::is_same_v<T, BreakpointIllFormed>,
3159 "non-exhaustive visitor!");
3160 if constexpr (std::is_same_v<T, BreakpointOK>)
3162 else if constexpr (std::is_same_v<T, BreakpointError>)
3186 if (!packet_str.consume_front(
"jMultiBreakpoint:"))
3188 "Invalid jMultiBreakpoint packet prefix");
3190 llvm::Expected<llvm::json::Value> parsed = llvm::json::parse(packet_str);
3192 llvm::consumeError(parsed.takeError());
3194 "jMultiBreakpoint did not contain valid JSON");
3196 llvm::json::Object *request_dict = parsed->getAsObject();
3199 packet,
"jMultiBreakpoint did not contain a JSON dictionary");
3201 llvm::json::Array *request_array =
3202 request_dict->getArray(
"breakpoint_requests");
3206 "jMultiBreakpoint did not contain a valid 'breakpoint_requests' field");
3208 llvm::json::Array reply_array;
3209 for (
const llvm::json::Value &value : *request_array) {
3210 std::optional<llvm::StringRef> request = value.getAsString();
3213 "jMultiBreakpoint had a non-string entry");
3218 [&](
const auto &arg) {
3219 using T = std::decay_t<
decltype(arg)>;
3220 static_assert(std::is_same_v<T, BreakpointOK> ||
3221 std::is_same_v<T, BreakpointError> ||
3222 std::is_same_v<T, BreakpointIllFormed>,
3223 "non-exhaustive visitor!");
3224 if constexpr (std::is_same_v<T, BreakpointOK>)
3225 reply_array.push_back(
"OK");
3226 else if constexpr (std::is_same_v<T, BreakpointError>)
3227 reply_array.push_back(
3228 llvm::formatv(
"E{0:X-2}", arg.error_code).str());
3230 reply_array.push_back(
"E03");
3235 llvm::json::Object dict;
3236 dict.try_emplace(
"results", std::move(reply_array));
3239 stream.
AsRawOstream() << llvm::json::Value(std::move(dict));
3240 StringRef response_str = stream.
GetString();
3255 "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
3293llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
3298 return llvm::createStringError(llvm::inconvertibleErrorCode(),
3299 "No thread available");
3307 response.
Printf(
"<?xml version=\"1.0\"?>\n");
3308 response.
Printf(
"<target version=\"1.0\">\n");
3312 response.
Printf(
"<architecture>%s</architecture>\n",
3319 response.
Indent(
"<feature>\n");
3322 if (registers_count)
3325 llvm::StringSet<> field_enums_seen;
3326 for (
int reg_index = 0; reg_index < registers_count; reg_index++) {
3332 "%s failed to get register info for register index %" PRIu32,
3333 "target.xml", reg_index);
3345 response.
Printf(
"<reg name=\"%s\" bitsize=\"%" PRIu32
3346 "\" regnum=\"%d\" ",
3356 if (!encoding.empty())
3357 response <<
"encoding=\"" << encoding <<
"\" ";
3360 if (!format.empty())
3361 response <<
"format=\"" << format <<
"\" ";
3366 const char *
const register_set_name =
3368 if (register_set_name)
3369 response <<
"group=\"" << register_set_name <<
"\" ";
3373 response.
Printf(
"ehframe_regnum=\"%" PRIu32
"\" ",
3378 response.
Printf(
"dwarf_regnum=\"%" PRIu32
"\" ",
3382 if (!kind_generic.empty())
3383 response <<
"generic=\"" << kind_generic <<
"\" ";
3393 response.
PutCString(
"invalidate_regnums=\"");
3401 if (registers_count)
3404 response.
Indent(
"</feature>\n");
3406 response.
Indent(
"</target>\n");
3407 return MemoryBuffer::getMemBufferCopy(response.
GetString(),
"target.xml");
3410llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
3412 llvm::StringRef annex) {
3416 return llvm::createStringError(llvm::inconvertibleErrorCode(),
3417 "No process available");
3420 if (
object ==
"auxv") {
3423 if (!buffer_or_error)
3424 return llvm::errorCodeToError(buffer_or_error.getError());
3425 return std::move(*buffer_or_error);
3428 if (
object ==
"siginfo") {
3431 return llvm::createStringError(llvm::inconvertibleErrorCode(),
3432 "no current thread");
3434 auto buffer_or_error = thread->GetSiginfo();
3435 if (!buffer_or_error)
3436 return buffer_or_error.takeError();
3437 return std::move(*buffer_or_error);
3440 if (
object ==
"libraries-svr4") {
3443 return library_list.takeError();
3446 response.
Printf(
"<library-list-svr4 version=\"1.0\">");
3447 for (
auto const &library : *library_list) {
3448 response.
Printf(
"<library name=\"%s\" ",
3450 response.
Printf(
"lm=\"0x%" PRIx64
"\" ", library.link_map);
3451 response.
Printf(
"l_addr=\"0x%" PRIx64
"\" ", library.base_addr);
3452 response.
Printf(
"l_ld=\"0x%" PRIx64
"\" />", library.ld_addr);
3454 response.
Printf(
"</library-list-svr4>");
3455 return MemoryBuffer::getMemBufferCopy(response.
GetString(), __FUNCTION__);
3458 if (
object ==
"libraries") {
3461 return library_list.takeError();
3464 response.
Printf(
"<library-list>");
3465 for (
auto const &library : *library_list) {
3466 response.
Printf(
"<library name=\"%s\">",
3468 response.
Printf(
"<section address=\"0x%" PRIx64
"\"/>",
3470 response.
Printf(
"</library>");
3472 response.
Printf(
"</library-list>");
3473 return MemoryBuffer::getMemBufferCopy(response.
GetString(), __FUNCTION__);
3476 if (
object ==
"features" && annex ==
"target.xml")
3479 return llvm::make_error<UnimplementedError>();
3485 SmallVector<StringRef, 5> fields;
3487 StringRef(packet.
GetStringRef()).split(fields,
':', 4);
3488 if (fields.size() != 5)
3490 StringRef &xfer_object = fields[1];
3491 StringRef &xfer_action = fields[2];
3492 StringRef &xfer_annex = fields[3];
3494 if (xfer_action !=
"read")
3497 const uint64_t xfer_offset =
3498 offset_data.
GetHexMaxU64(
false, std::numeric_limits<uint64_t>::max());
3499 if (xfer_offset == std::numeric_limits<uint64_t>::max())
3502 if (offset_data.
GetChar() !=
',')
3504 "qXfer packet missing comma after offset");
3506 const uint64_t xfer_length =
3507 offset_data.
GetHexMaxU64(
false, std::numeric_limits<uint64_t>::max());
3508 if (xfer_length == std::numeric_limits<uint64_t>::max())
3512 std::string buffer_key = (xfer_object + xfer_action + xfer_annex).str();
3519 .insert(std::make_pair(buffer_key, std::move(*buffer_up)))
3525 bool done_with_buffer =
false;
3526 llvm::StringRef buffer = buffer_it->second->getBuffer();
3527 if (xfer_offset >= buffer.size()) {
3530 done_with_buffer =
true;
3533 buffer = buffer.drop_front(xfer_offset);
3536 if (xfer_length >= buffer.size()) {
3539 done_with_buffer =
true;
3543 buffer = buffer.take_front(xfer_length);
3549 if (done_with_buffer)
3561 packet.
SetFilePos(strlen(
"QSaveRegisterState"));
3568 packet,
"No thread specified in QSaveRegisterState packet");
3571 "No thread was is set with the Hg packet");
3581 LLDB_LOG(log,
"pid {0} failed to save all register values: {1}",
3589 "GetNextRegisterSaveID() returned an existing register save id");
3599 response.
Printf(
"%" PRIu32, save_id);
3609 packet.
SetFilePos(strlen(
"QRestoreRegisterState:"));
3612 packet,
"QRestoreRegisterState packet missing register save id");
3614 const uint32_t save_id = packet.
GetU32(0);
3616 LLDB_LOG(log,
"QRestoreRegisterState packet has malformed save id, "
3617 "expecting decimal uint32_t");
3626 packet,
"No thread specified in QRestoreRegisterState packet");
3629 "No thread was is set with the Hg packet");
3644 "pid {0} does not have a register set save buffer for id {1}",
3648 register_data_sp = it->second;
3656 LLDB_LOG(log,
"pid {0} failed to restore all register values: {1}",
3678 "vAttach failed to parse the process id");
3682 "GDBRemoteCommunicationServerLLGS::%s attempting to attach to "
3690 "GDBRemoteCommunicationServerLLGS::%s failed to attach to "
3691 "pid %" PRIu64
": %s\n",
3692 __FUNCTION__, pid,
error.AsCString());
3715 std::string process_name;
3718 "vAttachWait failed to parse process name");
3720 LLDB_LOG(log,
"attempting to attach to process named '{0}'", process_name);
3724 LLDB_LOG(log,
"failed to attach to process named '{0}': {1}", process_name,
3754 std::string process_name;
3757 "vAttachOrWait failed to parse process name");
3759 LLDB_LOG(log,
"attempting to attach to process named '{0}'", process_name);
3763 LLDB_LOG(log,
"failed to attach to process named '{0}': {1}", process_name,
3781 if (!s.consume_front(
"vRun;"))
3784 llvm::SmallVector<llvm::StringRef, 16> argv;
3787 for (llvm::StringRef hex_arg : argv) {
3792 LLDB_LOGF(log,
"LLGSPacketHandler::%s added arg: \"%s\"", __FUNCTION__,
3831 llvm::Error detach_error = llvm::Error::success();
3832 bool detached =
false;
3837 "GDBRemoteCommunicationServerLLGS::%s detaching %" PRId64,
3838 __FUNCTION__, it->first);
3839 if (llvm::Error e = it->second.process_up->Detach().ToError())
3840 detach_error = llvm::joinErrors(std::move(detach_error), std::move(e));
3871 packet.
SetFilePos(strlen(
"qThreadStopInfo"));
3875 "GDBRemoteCommunicationServerLLGS::%s failed, could not "
3876 "parse thread id from request \"%s\"",
3896 const bool threads_with_valid_stop_info_only =
false;
3897 llvm::Expected<json::Value> threads_info =
3899 if (!threads_info) {
3901 "failed to prepare a packet for pid {1}: {0}",
3920 packet.
SetFilePos(strlen(
"qWatchpointSupportInfo"));
3929 if (hw_debug_cap == std::nullopt)
3930 response.
Printf(
"num:0;");
3932 response.
Printf(
"num:%d;", hw_debug_cap->second);
3945 packet.
SetFilePos(strlen(
"qFileLoadAddress:"));
3949 std::string file_name;
3962 response.
PutHex64(file_load_address);
3969 std::vector<int> signals;
3975 int signal = packet.
GetS32(-1, 16);
3978 signals.push_back(signal);
3981 char separator = packet.
GetChar();
3982 if (separator ==
'\0')
3984 if (separator !=
';')
3986 " expected semicolon.");
4010 "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
4020 const char *current_char = packet.
Peek();
4021 if (!current_char || *current_char ==
',')
4026 char previous_char = packet.
GetChar();
4027 current_char = packet.
Peek();
4029 if (previous_char !=
',' || (current_char && *current_char ==
':'))
4031 "Invalid addr,length pair in qMemTags packet");
4035 packet,
"Too short qMemtags: packet (looking for length)");
4039 const char *invalid_type_err =
"Invalid type field in qMemTags: packet";
4045 const char *first_type_char = packet.
Peek();
4046 if (first_type_char && (*first_type_char ==
'+' || *first_type_char ==
'-'))
4053 packet.
GetU64(std::numeric_limits<uint64_t>::max(), 16);
4056 raw_type > std::numeric_limits<uint32_t>::max() ||
4065 uint32_t raw_type_32 = raw_type;
4066 int32_t type =
reinterpret_cast<int32_t &
>(raw_type_32);
4069 std::vector<uint8_t> tags;
4091 "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
4101 const char *current_char = packet.
Peek();
4102 if (!current_char || *current_char ==
',')
4107 char previous_char = packet.
GetChar();
4108 current_char = packet.
Peek();
4110 if (previous_char !=
',' || (current_char && *current_char ==
':'))
4112 "Invalid addr,length pair in QMemTags packet");
4116 packet,
"Too short QMemtags: packet (looking for length)");
4120 const char *invalid_type_err =
"Invalid type field in QMemTags: packet";
4125 const char *first_type_char = packet.
Peek();
4126 if (first_type_char && (*first_type_char ==
'+' || *first_type_char ==
'-'))
4134 packet.
GetU64(std::numeric_limits<uint64_t>::max(), 16);
4135 if (raw_type > std::numeric_limits<uint32_t>::max())
4140 uint32_t raw_type_32 = raw_type;
4141 int32_t type =
reinterpret_cast<int32_t &
>(raw_type_32);
4146 "Missing tag data in QMemTags: packet");
4149 const char *invalid_data_err =
"Invalid tag data in QMemTags: packet";
4156 std::vector<uint8_t> tag_data;
4161 tag_data.resize(byte_count);
4162 size_t converted_bytes = packet.
GetHexBytes(tag_data, 0);
4163 if (converted_bytes != byte_count) {
4181 std::string path_hint;
4184 assert(packet_str.starts_with(
"qSaveCore"));
4185 if (packet_str.consume_front(
"qSaveCore;")) {
4186 for (
auto x : llvm::split(packet_str,
';')) {
4187 if (x.consume_front(
"path-hint:"))
4211 assert(packet_str.starts_with(
"QNonStop:"));
4212 packet_str.consume_front(
"QNonStop:");
4213 if (packet_str ==
"0") {
4217 if (process_it.second.process_up->IsRunning()) {
4219 Status error = process_it.second.process_up->Interrupt();
4222 "while disabling nonstop, failed to halt process {0}: {1}",
4223 process_it.first,
error);
4237 }
else if (packet_str ==
"1") {
4249 std::deque<std::string> &queue) {
4293 return interrupt_res;
4313 llvm::createStringError(
"no current process and no PID provided"));
4321 if (!new_process_it->second.process_up->GetThreadByID(tid))
4335 connection->Disconnect(&
error);
4337 if (
error.Success()) {
4339 "GDBRemoteCommunicationServerLLGS::%s disconnect process "
4340 "terminal stdio - SUCCESS",
4344 "GDBRemoteCommunicationServerLLGS::%s disconnect process "
4345 "terminal stdio - FAIL: %s",
4346 __FUNCTION__,
error.AsCString());
4365 else if (current_tid == 0) {
4377 "GDBRemoteCommunicationServerLLGS::%s gdb-remote parse "
4378 "error: expected ';' prior to start of thread suffix: packet "
4388 if (strncmp(packet.
Peek(),
"thread:", strlen(
"thread:")) != 0) {
4390 "GDBRemoteCommunicationServerLLGS::%s gdb-remote parse "
4391 "error: expected 'thread:' but not found, packet contents = "
4435 ->GetLoadedModuleFileSpec(module_path.c_str(), file_spec)
4446 llvm::StringRef value) {
4448 for (
const char &c : value) {
4471 const llvm::ArrayRef<llvm::StringRef> client_features) {
4472 std::vector<std::string> ret =
4474 ret.insert(ret.end(), {
4475 "QThreadSuffixSupported+",
4476 "QListThreadsInStopReply+",
4477 "qXfer:features:read+",
4479 "jMultiBreakpoint+",
4485 if (
bool(plugin_features & Extension::pass_signals))
4486 ret.push_back(
"QPassSignals+");
4487 if (
bool(plugin_features & Extension::auxv))
4488 ret.push_back(
"qXfer:auxv:read+");
4489 if (
bool(plugin_features & Extension::libraries_svr4))
4490 ret.push_back(
"qXfer:libraries-svr4:read+");
4491 if (
bool(plugin_features & Extension::libraries))
4492 ret.push_back(
"qXfer:libraries:read+");
4493 if (
bool(plugin_features & Extension::siginfo_read))
4494 ret.push_back(
"qXfer:siginfo:read+");
4495 if (
bool(plugin_features & Extension::memory_tagging))
4496 ret.push_back(
"memory-tagging+");
4497 if (
bool(plugin_features & Extension::savecore))
4498 ret.push_back(
"qSaveCore+");
4500 ret.push_back(
"accelerator-plugins+");
4504 for (llvm::StringRef x : client_features)
4506 llvm::StringSwitch<Extension>(x)
4507 .Case(
"multiprocess+", Extension::multiprocess)
4508 .Case(
"fork-events+", Extension::fork)
4509 .Case(
"vfork-events+", Extension::vfork)
4524 ret.push_back(
"multiprocess+");
4526 ret.push_back(
"fork-events+");
4528 ret.push_back(
"vfork-events+");
4554 response.
Format(
"p{0:x-}.", pid);
4555 response.
Format(
"{0:x-}", tid);
4560 bool reverse_connect) {
4562 if (std::optional<URI> url =
URI::Parse(url_arg)) {
4563 if (reverse_connect)
4564 return url_arg.str();
4569 std::string new_url = llvm::StringSwitch<std::string>(url->scheme)
4570 .Case(
"tcp",
"listen")
4571 .Case(
"unix",
"unix-accept")
4572 .Case(
"unix-abstract",
"unix-abstract-accept")
4573 .Default(url->scheme.str());
4574 llvm::append_range(new_url, url_arg.substr(url->scheme.size()));
4578 std::string host_port = url_arg.str();
4581 if (url_arg.starts_with(
":"))
4582 host_port.insert(0,
"localhost");
4586 return (reverse_connect ?
"connect://" :
"listen://") + host_port;
4589 return (reverse_connect ?
"unix-connect://" :
"unix-accept://") +
4594 std::unique_ptr<LLDBServerAcceleratorPlugin> plugin_up) {
4601 std::vector<AcceleratorActions> accelerator_actions;
4602 for (std::unique_ptr<lldb_server::LLDBServerAcceleratorPlugin> &plugin_up :
4604 if (
auto actions = plugin_up->GetInitializeActions())
4605 accelerator_actions.push_back(std::move(*actions));
4615 packet.
ConsumeFront(
"jAcceleratorPluginBreakpointHit:");
4616 llvm::Expected<AcceleratorBreakpointHitArgs> args =
4617 llvm::json::parse<AcceleratorBreakpointHitArgs>(
4618 packet.
Peek(),
"AcceleratorBreakpointHitArgs");
4622 for (std::unique_ptr<lldb_server::LLDBServerAcceleratorPlugin> &plugin_up :
4624 if (plugin_up->GetPluginName() == args->plugin_name) {
4625 llvm::Expected<AcceleratorBreakpointHitResponse> bp_response =
4626 plugin_up->BreakpointWasHit(*args);
4631 response.
PutAsJSON(*bp_response,
false);
static const size_t reg_size
static llvm::raw_ostream & error(Stream &strm)
static llvm::StringRef GetEncodingNameOrEmpty(const RegisterInfo ®_info)
static llvm::StringRef GetFormatNameOrEmpty(const RegisterInfo ®_info)
static void WriteRegisterValueInHexFixedWidth(StreamString &response, NativeRegisterContext ®_ctx, const RegisterInfo ®_info, const RegisterValue *reg_value_p, lldb::ByteOrder byte_order)
static void AppendHexValue(StreamString &response, const uint8_t *buf, uint32_t buf_size, bool swap)
static std::optional< json::Object > GetRegistersAsJSON(NativeThreadProtocol &thread)
static const char * GetStopReasonString(StopReason stop_reason)
static void CollectRegNums(const uint32_t *reg_num, StreamString &response, bool usehex)
static bool ResumeActionListStopsAllThreads(ResumeActionList &actions)
static llvm::StringRef GetKindGenericOrEmpty(const RegisterInfo ®_info)
static llvm::Expected< json::Array > GetJSONThreadsInfo(NativeProcessProtocol &process, bool abridged)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
#define LLDB_LOG_ERROR(log, error,...)
void swap(lldb_private::NonNullSharedPtr< T > &lhs, lldb_private::NonNullSharedPtr< T > &rhs)
Specialized swap function for NonNullSharedPtr to enable argument-dependent lookup (ADL) and efficien...
An architecture specification class.
virtual void SetConnection(std::unique_ptr< Connection > connection)
Sets the connection that it to be used by this class.
A uniqued constant string class.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
static FileSystem & Instance()
static bool GetProcessInfo(lldb::pid_t pid, ProcessInstanceInfo &proc_info)
static uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info, ProcessInstanceInfoList &proc_infos)
virtual void RequestTermination()
LazyBool GetReadable() const
std::optional< unsigned > GetProtectionKey() const
ConstString GetName() const
LazyBool GetExecutable() const
LazyBool IsShadowStack() const
LazyBool GetWritable() const
LazyBool GetMemoryTagged() const
virtual std::optional< WaitStatus > GetExitStatus()
virtual void SetEnabledExtensions(Extension flags)
Method called in order to propagate the bitmap of protocol extensions supported by the client.
lldb::pid_t GetID() const
lldb::StateType GetState() const
NativeThreadProtocol * GetThreadByID(lldb::tid_t tid)
virtual Status Resume(const ResumeActionList &resume_actions)=0
virtual bool HasPendingLibraryEvents()
lldb::tid_t GetCurrentThreadID() const
Extension
Extension flag constants, returned by Manager::GetSupportedExtensions() and passed to SetEnabledExten...
ThreadIterable Threads() const
uint32_t ConvertRegisterKindToRegisterNumber(uint32_t kind, uint32_t num) const
virtual uint32_t GetUserRegisterCount() const =0
virtual const RegisterInfo * GetRegisterInfoAtIndex(uint32_t reg) const =0
const char * GetRegisterSetNameForRegisterAtIndex(uint32_t reg_index) const
virtual Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp)=0
virtual Status ReadRegister(const RegisterInfo *reg_info, RegisterValue ®_value)=0
virtual bool RegisterOffsetIsDynamic() const
virtual Status ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp)=0
virtual std::vector< uint32_t > GetExpeditedRegisters(ExpeditedRegs expType) const
virtual Status WriteRegister(const RegisterInfo *reg_info, const RegisterValue ®_value)=0
FileSpec & GetExecutableFile()
void SetNameMatchType(NameMatch name_match_type)
ProcessInstanceInfo & GetProcessInfo()
void EnumsToXML(Stream &strm, llvm::StringSet<> &seen) const
Enum types must be defined before use, and GDBRemoteCommunicationServerLLGS view of the register type...
const std::string & GetID() const
void ToXML(Stream &strm) const
Output XML that describes this set of flags.
const void * GetBytes() const
uint32_t GetByteSize() const
const ResumeAction * GetActionForThread(lldb::tid_t tid, bool default_ok) const
void Append(const ResumeAction &action)
bool SetDefaultThreadActionIfNeeded(lldb::StateType action, int signal)
static llvm::Expected< HostAndPort > DecodeHostAndPort(llvm::StringRef host_and_port)
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
bool Fail() const
Test for error condition.
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
bool Success() const
Test for success condition.
int PutAsJSON(const T &obj, bool hex_ascii)
int PutEscapedBytes(const void *s, size_t src_len)
Output a block of data to the stream performing GDB-remote escaping.
int PutAsJSONArray(const std::vector< T > &array, bool hex_ascii)
const char * GetData() const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
void Format(const char *format, Args &&... args)
Forwards the arguments to llvm::formatv and writes to the stream.
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
size_t size_t PutHex8(uint8_t uvalue)
Append an uint8_t value in the hexadecimal format to the stream.
size_t PutStringAsRawHex8(llvm::StringRef s)
size_t PutHex64(uint64_t uvalue, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
size_t PutHex32(uint32_t uvalue, lldb::ByteOrder byte_order=lldb::eByteOrderInvalid)
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
size_t PutBytesAsRawHex8(const void *src, size_t src_len, lldb::ByteOrder src_byte_order=lldb::eByteOrderInvalid, lldb::ByteOrder dst_byte_order=lldb::eByteOrderInvalid)
void IndentMore(unsigned amount=2)
Increment the current indentation level.
GDBRemoteCommunicationServerCommon()
virtual FileSpec FindModuleFile(const std::string &module_path, const ArchSpec &arch)
void RegisterMemberFunctionHandler(StringExtractorGDBRemote::ServerPacketType packet_type, PacketResult(T::*handler)(StringExtractorGDBRemote &packet))
static void CreateProcessInfoResponse_DebugServerStyle(const ProcessInstanceInfo &proc_info, StreamString &response)
Status m_process_launch_error
ProcessLaunchInfo m_process_launch_info
virtual std::vector< std::string > HandleFeatures(llvm::ArrayRef< llvm::StringRef > client_features)
PacketResult Handle_QMemTags(StringExtractorGDBRemote &packet)
PacketResult Handle_qVAttachOrWaitSupported(StringExtractorGDBRemote &packet)
PacketResult Handle_vStdio(StringExtractorGDBRemote &packet)
PacketResult HandleNotificationAck(std::deque< std::string > &queue)
PacketResult Handle_QSetDisableASLR(StringExtractorGDBRemote &packet)
void SetLaunchInfo(const ProcessLaunchInfo &info)
PacketResult SendONotification(const char *buffer, uint32_t len)
PacketResult Handle_D(StringExtractorGDBRemote &packet)
NativeProcessProtocol::Extension m_extensions_supported
PacketResult Handle_qMemTags(StringExtractorGDBRemote &packet)
void AddProcessThreads(StreamGDBRemote &response, NativeProcessProtocol &process, bool &had_any)
llvm::StringMap< std::unique_ptr< llvm::MemoryBuffer > > m_xfer_buffer_map
PacketResult SendStopReasonForState(NativeProcessProtocol &process, lldb::StateType process_state, bool force_synchronous)
std::vector< std::unique_ptr< lldb_server::LLDBServerAcceleratorPlugin > > m_accelerator_plugins
void EnqueueStopReplyPackets(lldb::tid_t thread_to_skip)
PacketResult Handle_jLLDBTraceGetBinaryData(StringExtractorGDBRemote &packet)
PacketResult Handle_qfThreadInfo(StringExtractorGDBRemote &packet)
StreamString PrepareStopReplyPacketForThread(NativeThreadProtocol &thread)
uint8_t m_reg_bytes[RegisterValue::kMaxRegisterByteSize]
PacketResult Handle__m(StringExtractorGDBRemote &packet)
GDBRemoteCommunication::PacketResult SendStructuredDataPacket(const llvm::json::Value &value)
PacketResult Handle_g(StringExtractorGDBRemote &packet)
std::variant< BreakpointOK, BreakpointIllFormed, BreakpointError > BreakpointResult
uint32_t m_next_saved_registers_id
void RegisterPacketHandlers()
PacketResult Handle_qMemoryRegionInfoSupported(StringExtractorGDBRemote &packet)
PacketResult Handle_qThreadStopInfo(StringExtractorGDBRemote &packet)
BreakpointResult ExecuteRemoveBreakpoint(llvm::StringRef packet_str)
Core logic for a z (remove breakpoint/watchpoint) request.
PacketResult Handle_c(StringExtractorGDBRemote &packet)
PacketResult Handle_QThreadSuffixSupported(StringExtractorGDBRemote &packet)
PacketResult Handle_interrupt(StringExtractorGDBRemote &packet)
PacketResult Handle_vKill(StringExtractorGDBRemote &packet)
std::unordered_map< lldb::pid_t, DebuggedProcess > m_debugged_processes
void InitializeDelegate(NativeProcessProtocol *process) override
FileSpec FindModuleFile(const std::string &module_path, const ArchSpec &arch) override
std::string m_pending_output_buffer
PacketResult Handle_vAttachOrWait(StringExtractorGDBRemote &packet)
PacketResult Handle_vAttach(StringExtractorGDBRemote &packet)
PacketResult Handle_stop_reason(StringExtractorGDBRemote &packet)
PacketResult Handle_jLLDBTraceSupported(StringExtractorGDBRemote &packet)
std::deque< std::string > m_stop_notification_queue
PacketResult Handle_qsThreadInfo(StringExtractorGDBRemote &packet)
PacketResult Handle_vStopped(StringExtractorGDBRemote &packet)
PacketResult Handle_z(StringExtractorGDBRemote &packet)
bool m_disabling_non_stop
lldb::tid_t GetContinueThreadID() const
PacketResult Handle_H(StringExtractorGDBRemote &packet)
void StopSTDIOForwarding()
PacketResult SendContinueSuccessResponse()
PacketResult Handle_jLLDBTraceGetState(StringExtractorGDBRemote &packet)
std::deque< std::string > m_stdio_notification_queue
void NewProcessOutput(NativeProcessProtocol *process, llvm::StringRef data) override
Forward a chunk of inferior stdout/stderr produced by the platform's own reader.
bool m_list_threads_in_stop_reply
PacketResult Handle_qFileLoadAddress(StringExtractorGDBRemote &packet)
void NewSubprocess(NativeProcessProtocol *parent_process, std::unique_ptr< NativeProcessProtocol > child_process) override
PacketResult Handle_qC(StringExtractorGDBRemote &packet)
static std::string XMLEncodeAttributeValue(llvm::StringRef value)
NativeThreadProtocol * GetThreadFromSuffix(StringExtractorGDBRemote &packet)
Status SetSTDIOFileDescriptor(int fd)
lldb::tid_t GetCurrentThreadID() const
PacketResult Handle_QNonStop(StringExtractorGDBRemote &packet)
Status AttachToProcess(lldb::pid_t pid)
Attach to a process.
PacketResult Handle_jAcceleratorPluginBreakpointHit(StringExtractorGDBRemote &packet)
PacketResult SendWResponse(NativeProcessProtocol *process)
PacketResult Handle_s(StringExtractorGDBRemote &packet)
Status InitializeConnection(std::unique_ptr< Connection > connection)
bool m_thread_suffix_supported
void HandleInferiorState_Exited(NativeProcessProtocol *process)
lldb::tid_t m_continue_tid
PacketResult Handle_P(StringExtractorGDBRemote &packet)
PacketResult SendBreakpointResponse(StringExtractorGDBRemote &packet, const BreakpointResult &result)
Convert a BreakpointResult into a PacketResult, sending the appropriate response.
PacketResult Handle_qSaveCore(StringExtractorGDBRemote &packet)
NativeProcessProtocol * m_current_process
void HandleInferiorState_Stopped(NativeProcessProtocol *process)
BreakpointResult ExecuteSetBreakpoint(llvm::StringRef packet_str)
Core logic for a Z (set breakpoint/watchpoint) request.
NativeProcessProtocol * m_continue_process
PacketResult Handle_vCont(StringExtractorGDBRemote &packet)
PacketResult Handle_vCont_actions(StringExtractorGDBRemote &packet)
PacketResult Handle_vCtrlC(StringExtractorGDBRemote &packet)
PacketResult Handle_jLLDBTraceStart(StringExtractorGDBRemote &packet)
Status LaunchProcess() override
Launch a process with the current launch settings.
PacketResult Handle_qGetWorkingDir(StringExtractorGDBRemote &packet)
void DataAvailableCallback()
PacketResult Handle_qStructuredDataPlugins(StringExtractorGDBRemote &packet)
PacketResult Handle_jThreadsInfo(StringExtractorGDBRemote &packet)
PacketResult Handle_M(StringExtractorGDBRemote &packet)
std::mutex m_pending_output_mutex
void FlushPendingProcessOutput()
Drain m_pending_output_buffer and emit a $O packet if the debuggee is currently in a running state.
void DidExec(NativeProcessProtocol *process) override
PacketResult Handle_memory_read(StringExtractorGDBRemote &packet)
Status AttachWaitProcess(llvm::StringRef process_name, bool include_existing)
Wait to attach to a process with a given name.
PacketResult Handle_vAttachWait(StringExtractorGDBRemote &packet)
PacketResult ResumeProcess(NativeProcessProtocol &process, const ResumeActionList &actions)
PacketResult Handle_QListThreadsInStopReply(StringExtractorGDBRemote &packet)
void InstallPlugin(std::unique_ptr< lldb_server::LLDBServerAcceleratorPlugin > plugin_up)
PacketResult Handle_jLLDBTraceStop(StringExtractorGDBRemote &packet)
PacketResult Handle_T(StringExtractorGDBRemote &packet)
GDBRemoteCommunicationServerLLGS(MainLoop &mainloop, NativeProcessProtocol::Manager &process_manager)
PacketResult Handle_QSetWorkingDir(StringExtractorGDBRemote &packet)
PacketResult Handle_k(StringExtractorGDBRemote &packet)
PacketResult Handle_qXfer(StringExtractorGDBRemote &packet)
PacketResult Handle_jMultiBreakpoint(StringExtractorGDBRemote &packet)
PacketResult SendStopReplyPacketForThread(NativeProcessProtocol &process, lldb::tid_t tid, bool force_synchronous)
void StartSTDIOForwarding()
PacketResult Handle_C(StringExtractorGDBRemote &packet)
PacketResult Handle__M(StringExtractorGDBRemote &packet)
void AppendThreadIDToResponse(Stream &response, lldb::pid_t pid, lldb::tid_t tid)
std::vector< std::string > HandleFeatures(const llvm::ArrayRef< llvm::StringRef > client_features) override
void ClearProcessSpecificData()
PacketResult Handle_Z(StringExtractorGDBRemote &packet)
PacketResult Handle_QPassSignals(StringExtractorGDBRemote &packet)
PacketResult Handle_qWatchpointSupportInfo(StringExtractorGDBRemote &packet)
void ProcessStateChanged(NativeProcessProtocol *process, lldb::StateType state) override
lldb::tid_t m_current_tid
void SetEnabledExtensions(NativeProcessProtocol &process)
std::unordered_map< uint32_t, lldb::DataBufferSP > m_saved_registers_map
PacketResult Handle_QRestoreRegisterState(StringExtractorGDBRemote &packet)
NativeProcessProtocol::Manager & m_process_manager
void SetContinueThreadID(lldb::tid_t tid)
PacketResult Handle_p(StringExtractorGDBRemote &packet)
PacketResult Handle_qRegisterInfo(StringExtractorGDBRemote &packet)
void SetCurrentThreadID(lldb::tid_t tid)
std::mutex m_saved_registers_mutex
PacketResult Handle_qProcessInfo(StringExtractorGDBRemote &packet)
PacketResult Handle_vRun(StringExtractorGDBRemote &packet)
MainLoop::ReadHandleUP m_stdio_handle_up
void MaybeCloseInferiorTerminalConnection()
PacketResult Handle_jAcceleratorPluginInitialize(StringExtractorGDBRemote &packet)
MainLoop::ReadHandleUP m_network_handle_up
PacketResult Handle_qMemoryRegionInfo(StringExtractorGDBRemote &packet)
llvm::Expected< std::unique_ptr< llvm::MemoryBuffer > > ReadXferObject(llvm::StringRef object, llvm::StringRef annex)
PacketResult Handle_QSaveRegisterState(StringExtractorGDBRemote &packet)
std::recursive_mutex m_debugged_process_mutex
uint32_t GetNextSavedRegistersID()
Communication m_stdio_communication
llvm::Expected< std::unique_ptr< llvm::MemoryBuffer > > BuildTargetXml()
PacketResult Handle_I(StringExtractorGDBRemote &packet)
void RegisterPacketHandler(StringExtractorGDBRemote::ServerPacketType packet_type, PacketHandler handler)
PacketResult SendErrorResponse(const Status &error)
PacketResult SendIllFormedResponse(const StringExtractorGDBRemote &packet, const char *error_message)
PacketResult GetPacketAndSendResponse(Timeout< std::micro > timeout, Status &error, bool &interrupt, bool &quit)
PacketResult SendJSONResponse(const llvm::json::Value &value)
Serialize and send a JSON object response.
PacketResult SendUnimplementedResponse(const char *packet)
PacketResult SendOKResponse()
PacketResult SendNotificationPacketNoLock(llvm::StringRef notify_type, std::deque< std::string > &queue, llvm::StringRef payload)
PacketResult SendPacketNoLock(llvm::StringRef payload)
#define LLDB_REGNUM_GENERIC_RA
#define LLDB_REGNUM_GENERIC_ARG8
#define LLDB_INVALID_SIGNAL_NUMBER
#define LLDB_INVALID_THREAD_ID
#define LLDB_REGNUM_GENERIC_ARG6
#define LLDB_REGNUM_GENERIC_SP
#define LLDB_REGNUM_GENERIC_ARG4
#define LLDB_REGNUM_GENERIC_ARG3
#define LLDB_REGNUM_GENERIC_ARG1
#define LLDB_REGNUM_GENERIC_ARG7
#define LLDB_REGNUM_GENERIC_FLAGS
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_REGNUM
#define LLDB_REGNUM_GENERIC_TP
#define LLDB_INVALID_PROCESS_ID
#define LLDB_REGNUM_GENERIC_ARG2
#define LLDB_REGNUM_GENERIC_PC
#define LLDB_REGNUM_GENERIC_FP
#define LLDB_REGNUM_GENERIC_ARG5
lldb::ByteOrder InlHostByteOrder()
std::string LLGSArgToURL(llvm::StringRef url_arg, bool reverse_connect)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
bool StateIsRunningState(lldb::StateType state)
Check if a state represents a state where the process or thread is running.
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
std::shared_ptr< lldb_private::IOObject > IOObjectSP
ConnectionStatus
Connection Status Types.
@ eConnectionStatusError
Check GetError() for details.
@ eConnectionStatusInterrupted
Interrupted read.
@ eConnectionStatusTimedOut
Request timed out.
@ eConnectionStatusEndOfFile
End-of-file encountered.
@ eConnectionStatusSuccess
Success.
@ eConnectionStatusLostConnection
Lost connection while connected to a valid connection.
@ eConnectionStatusNoConnection
No connection.
@ eFormatCString
NULL terminated C strings.
@ eFormatCharArray
Print characters with no single quotes, used for character arrays that can contain non printable char...
@ eFormatInstruction
Disassemble an opcode.
@ eFormatVoid
Do not print this.
@ eFormatComplex
Floating point complex type.
@ eFormatHexFloat
ISO C99 hex float string.
@ eFormatOSType
OS character codes encoded into an integer 'PICT' 'text' etc...
@ eFormatAddressInfo
Describe what an address points to (func + offset with file/line, symbol + offset,...
@ eFormatCharPrintable
Only printable characters, '.' if not printable.
@ eFormatComplexInteger
Integer complex type.
@ eFormatFloat128
Disambiguate between 128-bit long double (which uses eFormatFloat) and __float128 (which uses eFormat...
StateType
Process and Thread States.
@ eStateUnloaded
Process is object is valid, but not currently loaded.
@ eStateDetached
Process has been detached and can't be examined.
@ eStateStopped
Process or thread is stopped and can be examined.
@ eStateSuspended
Process or thread is in a suspended state as far as the debugger is concerned while other processes o...
@ eStateRunning
Process or thread is running and can't be examined.
@ eStateLaunching
Process is in the process of launching.
@ eStateAttaching
Process is currently trying to attach.
@ eStateExited
Process has exited and can't be examined.
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
@ eStateCrashed
Process or thread has crashed and can be examined.
@ eEncodingVector
vector registers
@ eEncodingUint
unsigned integer
@ eEncodingSint
signed integer
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
StopReason
Thread stop reasons.
@ eStopReasonInstrumentation
@ eStopReasonPlanComplete
@ eStopReasonHistoryBoundary
@ eStopReasonExec
Program was re-exec'ed.
@ eStopReasonInterrupt
Thread requested interrupt.
@ eStopReasonProcessorTrace
@ eStopReasonThreadExiting
@ eRegisterKindGeneric
insn ptr reg, stack ptr reg, etc not specific to any particular target
@ eRegisterKindDWARF
the register numbers seen DWARF
@ eRegisterKindEHFrame
the register numbers seen in eh_frame
Terminal window dimensions to use when the launcher creates a pseudo-terminal for the inferior's stdi...
BaseType GetRangeBase() const
SizeType GetByteSize() const
Every register is described in detail including its name, alternate name (optional),...
lldb::Encoding encoding
Encoding of the register bits.
const char * alt_name
Alternate name of this register, can be NULL.
uint32_t * value_regs
List of registers (terminated with LLDB_INVALID_REGNUM).
uint32_t byte_offset
The byte offset in the register context data where this register's value is found.
uint32_t byte_size
Size in bytes of the register.
uint32_t kinds[lldb::kNumRegisterKinds]
Holds all of the various register numbers for all register kinds.
const RegisterFlags * flags_type
If not nullptr, a type defined by XML descriptions.
const char * name
Name of this register, can't be NULL.
lldb::Format format
Default display format.
uint32_t * invalidate_regs
List of registers (terminated with LLDB_INVALID_REGNUM).
struct lldb_private::ThreadStopInfo::@116236113001137253323017204263037302160273237376::@034237007264067231263360140073224264215170222231 exception
struct lldb_private::ThreadStopInfo::@116236113001137253323017204263037302160273237376::@075376350020015165106375110034031012204332263127 fork
union lldb_private::ThreadStopInfo::@116236113001137253323017204263037302160273237376 details
static std::optional< URI > Parse(llvm::StringRef uri)