17#include "lldb/Host/Config.h"
34#include "llvm/ADT/SmallString.h"
35#include "llvm/Support/ScopedPrinter.h"
40#define DEBUGSERVER_BASENAME "debugserver"
42#define DEBUGSERVER_BASENAME "lldb-server.exe"
44#define DEBUGSERVER_BASENAME "lldb-server"
47#if defined(HAVE_LIBCOMPRESSION)
48#include <compression.h>
62#ifdef LLDB_CONFIGURATION_DEBUG
63 m_packet_timeout(1000),
68 m_send_acks(true), m_is_platform(false),
78#if defined(HAVE_LIBCOMPRESSION)
79 if (m_decompression_scratch)
80 free (m_decompression_scratch);
87 for (
char c : payload)
90 return checksum & 255;
97 const size_t bytes_written =
WriteAll(&ch, 1, status,
nullptr);
98 LLDB_LOGF(log,
"<%4" PRIu64
"> send packet: %c", (uint64_t)bytes_written, ch);
100 return bytes_written;
107 const size_t bytes_written =
WriteAll(&ch, 1, status,
nullptr);
108 LLDB_LOGF(log,
"<%4" PRIu64
"> send packet: %c", (uint64_t)bytes_written, ch);
110 return bytes_written;
117 packet.
Write(payload.data(), payload.size());
120 std::string packet_str = std::string(packet.
GetString());
127 llvm::StringRef notify_type, std::deque<std::string> &queue,
128 llvm::StringRef payload) {
136 packet.
Write(notify_type.data(), notify_type.size());
138 packet.
Write(payload.data(), payload.size());
144 queue.push_back(payload.str());
154 const char *packet_data = packet.data();
155 const size_t packet_length = packet.size();
156 size_t bytes_written =
WriteAll(packet_data, packet_length, status,
nullptr);
158 size_t binary_start_offset = 0;
159 if (strncmp(packet_data,
"$vFile:pwrite:", strlen(
"$vFile:pwrite:")) ==
161 const char *first_comma = strchr(packet_data,
',');
163 const char *second_comma = strchr(first_comma + 1,
',');
165 binary_start_offset = second_comma - packet_data + 1;
176 if (binary_start_offset) {
179 strm.
Printf(
"<%4" PRIu64
"> send packet: %.*s", (uint64_t)bytes_written,
180 (
int)binary_start_offset, packet_data);
183 for (p = (
const uint8_t *)packet_data + binary_start_offset; *p !=
'#';
185 strm.
Printf(
"\\x%2.2x", *p);
187 strm.
Printf(
"%*s", (
int)3, p);
190 LLDB_LOGF(log,
"<%4" PRIu64
"> send packet: %.*s",
191 (uint64_t)bytes_written, (
int)packet_length, packet_data);
197 if (bytes_written == packet_length) {
203 LLDB_LOGF(log,
"error: failed to send packet: %.*s", (
int)packet_length,
226 bool sync_on_timeout) {
244 bool sync_on_timeout) {
245 uint8_t buffer[8192];
254 bool timed_out =
false;
255 bool disconnected =
false;
258 size_t bytes_read =
Read(buffer,
sizeof(buffer), timeout, status, &
error);
261 "Read(buffer, sizeof(buffer), timeout = {0}, "
262 "status = {1}, error = {2}) => bytes_read = {3}",
266 if (bytes_read > 0) {
273 if (sync_on_timeout) {
296 bool sync_success =
false;
297 bool got_actual_response =
false;
299 char echo_packet[32];
300 int echo_packet_len = 0;
304 echo_packet_len = ::snprintf(echo_packet,
sizeof(echo_packet),
306 std::string regex_str =
"^";
307 regex_str += echo_packet;
312 ::snprintf(echo_packet,
sizeof(echo_packet),
"qC");
322 for (
uint32_t i = 0; i < max_retries; ++i) {
327 ++successful_responses;
331 }
else if (successful_responses == 1) {
336 packet = echo_response;
337 got_actual_response =
true;
351 if (got_actual_response) {
394 size_t pkt_size =
m_bytes.size();
407 size_t hash_mark_idx =
m_bytes.find(
'#');
408 if (hash_mark_idx == std::string::npos)
410 if (hash_mark_idx + 2 >=
m_bytes.size())
413 if (!::isxdigit(
m_bytes[hash_mark_idx + 1]) ||
414 !::isxdigit(
m_bytes[hash_mark_idx + 2]))
417 size_t content_length =
420 size_t content_start = 2;
422 size_t checksum_idx =
430 size_t size_of_first_packet = hash_mark_idx + 3;
437 uint64_t decompressed_bufsize = ULONG_MAX;
439 size_t i = content_start;
440 while (i < hash_mark_idx && isdigit(
m_bytes[i]))
442 if (i < hash_mark_idx &&
m_bytes[i] ==
':') {
445 content_length = hash_mark_idx - content_start;
446 std::string bufsize_str(
m_bytes.data() + 2, i - 2 - 1);
448 decompressed_bufsize = ::strtoul(bufsize_str.c_str(),
nullptr, 10);
449 if (errno != 0 || decompressed_bufsize == ULONG_MAX) {
450 m_bytes.erase(0, size_of_first_packet);
457 char packet_checksum_cstr[3];
458 packet_checksum_cstr[0] =
m_bytes[checksum_idx];
459 packet_checksum_cstr[1] =
m_bytes[checksum_idx + 1];
460 packet_checksum_cstr[2] =
'\0';
461 long packet_checksum = strtol(packet_checksum_cstr,
nullptr, 16);
464 llvm::StringRef(
m_bytes).substr(1, hash_mark_idx - 1));
465 bool success = packet_checksum == actual_checksum;
468 "error: checksum mismatch: %.*s expected 0x%2.2x, got 0x%2.2x",
469 (
int)(pkt_size),
m_bytes.c_str(), (uint8_t)packet_checksum,
470 (uint8_t)actual_checksum);
475 m_bytes.erase(0, size_of_first_packet);
491 std::vector<uint8_t> unescaped_content;
492 unescaped_content.reserve(content_length);
493 size_t i = content_start;
494 while (i < hash_mark_idx) {
497 unescaped_content.push_back(
m_bytes[i] ^ 0x20);
499 unescaped_content.push_back(
m_bytes[i]);
504 uint8_t *decompressed_buffer =
nullptr;
505 size_t decompressed_bytes = 0;
507 if (decompressed_bufsize != ULONG_MAX) {
508 decompressed_buffer = (uint8_t *)malloc(decompressed_bufsize);
509 if (decompressed_buffer ==
nullptr) {
510 m_bytes.erase(0, size_of_first_packet);
515#if defined(HAVE_LIBCOMPRESSION)
520 compression_algorithm compression_type;
522 compression_type = COMPRESSION_LZFSE;
524 compression_type = COMPRESSION_ZLIB;
526 compression_type = COMPRESSION_LZ4_RAW;
528 compression_type = COMPRESSION_LZMA;
531 if (m_decompression_scratch) {
532 free (m_decompression_scratch);
533 m_decompression_scratch =
nullptr;
535 size_t scratchbuf_size = 0;
537 scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZFSE);
539 scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZ4_RAW);
541 scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_ZLIB);
543 scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZMA);
545 scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZFSE);
546 if (scratchbuf_size > 0) {
547 m_decompression_scratch = (
void*) malloc (scratchbuf_size);
552 if (decompressed_bufsize != ULONG_MAX && decompressed_buffer !=
nullptr) {
553 decompressed_bytes = compression_decode_buffer(
554 decompressed_buffer, decompressed_bufsize,
555 (uint8_t *)unescaped_content.data(), unescaped_content.size(),
556 m_decompression_scratch, compression_type);
562 if (decompressed_bytes == 0 && decompressed_bufsize != ULONG_MAX &&
563 decompressed_buffer !=
nullptr &&
566 memset(&stream, 0,
sizeof(z_stream));
567 stream.next_in = (Bytef *)unescaped_content.data();
568 stream.avail_in = (uInt)unescaped_content.size();
570 stream.next_out = (Bytef *)decompressed_buffer;
571 stream.avail_out = decompressed_bufsize;
572 stream.total_out = 0;
573 stream.zalloc = Z_NULL;
574 stream.zfree = Z_NULL;
575 stream.opaque = Z_NULL;
577 if (inflateInit2(&stream, -15) == Z_OK) {
578 int status = inflate(&stream, Z_NO_FLUSH);
580 if (status == Z_STREAM_END) {
581 decompressed_bytes = stream.total_out;
587 if (decompressed_bytes == 0 || decompressed_buffer ==
nullptr) {
588 if (decompressed_buffer)
589 free(decompressed_buffer);
590 m_bytes.erase(0, size_of_first_packet);
594 std::string new_packet;
595 new_packet.reserve(decompressed_bytes + 6);
596 new_packet.push_back(
m_bytes[0]);
597 new_packet.append((
const char *)decompressed_buffer, decompressed_bytes);
598 new_packet.push_back(
'#');
601 llvm::StringRef((
const char *)decompressed_buffer, decompressed_bytes));
602 char decompressed_checksum_str[3];
603 snprintf(decompressed_checksum_str, 3,
"%02x", decompressed_checksum);
604 new_packet.append(decompressed_checksum_str);
606 new_packet.push_back(
'0');
607 new_packet.push_back(
'0');
610 m_bytes.replace(0, size_of_first_packet, new_packet.data(),
613 free(decompressed_buffer);
625 if (src && src_len > 0) {
628 LLDB_LOGF(log,
"GDBRemoteCommunication::%s adding %u bytes: %.*s",
631 m_bytes.append((
const char *)src, src_len);
634 bool isNotifyPacket =
false;
640 size_t content_start = 0;
641 size_t content_length = 0;
642 size_t total_length = 0;
643 size_t checksum_idx = std::string::npos;
646 size_t original_packet_size =
m_bytes.size();
658 content_length = total_length = 1;
662 isNotifyPacket =
true;
668 size_t hash_pos =
m_bytes.find(
'#');
669 if (hash_pos != std::string::npos) {
670 if (hash_pos + 2 <
m_bytes.size()) {
671 checksum_idx = hash_pos + 1;
676 content_length = hash_pos - 1;
682 content_length = std::string::npos;
693 const size_t bytes_len =
m_bytes.size();
696 for (idx = 1; !done && idx < bytes_len; ++idx) {
710 LLDB_LOGF(log,
"GDBRemoteCommunication::%s tossing %u junk bytes: '%.*s'",
711 __FUNCTION__, idx - 1, idx - 1,
m_bytes.c_str());
716 if (content_length == std::string::npos) {
719 }
else if (total_length > 0) {
722 assert(content_length <=
m_bytes.size());
723 assert(total_length <=
m_bytes.size());
724 assert(content_length <= total_length);
725 size_t content_end = content_start + content_length;
739 if (
m_bytes[0] ==
'$' && total_length > 4) {
740 for (
size_t i = 0; !binary && i < total_length; ++i) {
742 if (!llvm::isPrint(c) && !llvm::isSpace(c)) {
751 strm.
Printf(
"<%4" PRIu64
":%" PRIu64
"> read packet: %c",
752 (uint64_t)original_packet_size, (uint64_t)total_length,
755 strm.
Printf(
"<%4" PRIu64
"> read packet: %c",
756 (uint64_t)total_length,
m_bytes[0]);
757 for (
size_t i = content_start; i < content_end; ++i) {
763 const char escapee =
m_bytes[++i] ^ 0x20;
764 strm.
Printf(
"%2.2x", escapee);
766 strm.
Printf(
"%2.2x", (uint8_t)ch);
775 LLDB_LOGF(log,
"<%4" PRIu64
":%" PRIu64
"> read packet: %.*s",
776 (uint64_t)original_packet_size, (uint64_t)total_length,
777 (
int)(total_length),
m_bytes.c_str());
779 LLDB_LOGF(log,
"<%4" PRIu64
"> read packet: %.*s",
780 (uint64_t)total_length, (
int)(total_length),
790 std ::string packet_str =
795 assert(checksum_idx <
m_bytes.size());
796 if (::isxdigit(
m_bytes[checksum_idx + 0]) ||
797 ::isxdigit(
m_bytes[checksum_idx + 1])) {
799 const char *packet_checksum_cstr = &
m_bytes[checksum_idx];
800 char packet_checksum = strtol(packet_checksum_cstr,
nullptr, 16);
802 llvm::StringRef(
m_bytes).slice(content_start, content_end));
803 success = packet_checksum == actual_checksum;
806 "error: checksum mismatch: %.*s expected 0x%2.2x, "
808 (
int)(total_length),
m_bytes.c_str(),
809 (uint8_t)packet_checksum, (uint8_t)actual_checksum);
819 LLDB_LOGF(log,
"error: invalid checksum in packet: '%s'\n",
824 m_bytes.erase(0, total_length);
840 return Status(
"listen thread already running");
842 char listen_url[512];
843 if (hostname && hostname[0])
844 snprintf(listen_url,
sizeof(listen_url),
"listen://%s:%i", hostname, port);
846 snprintf(listen_url,
sizeof(listen_url),
"listen://%i", port);
852 return Status(listen_thread.takeError());
873 [
this](llvm::StringRef port_str) {
875 llvm::to_integer(port_str, port, 10);
876 m_port_promise.set_value(port);
886 uint16_t *port,
const Args *inferior_args,
int pass_comm_fd) {
888 LLDB_LOGF(log,
"GDBRemoteCommunication::%s(url=%s, port=%" PRIu16
")",
889 __FUNCTION__, url ? url :
"<empty>", port ? *port :
uint16_t(0));
893 static FileSpec g_debugserver_file_spec;
902 std::string env_debugserver_path = host_env.lookup(
"LLDB_DEBUGSERVER_PATH");
903 if (!env_debugserver_path.empty()) {
904 debugserver_file_spec.
SetFile(env_debugserver_path,
905 FileSpec::Style::native);
907 "GDBRemoteCommunication::%s() gdb-remote stub exe path set "
908 "from environment variable: %s",
909 __FUNCTION__, env_debugserver_path.c_str());
911 debugserver_file_spec = g_debugserver_file_spec;
912 bool debugserver_exists =
914 if (!debugserver_exists) {
916 debugserver_file_spec = HostInfo::GetSupportExeDir();
917 if (debugserver_file_spec) {
920 if (debugserver_exists) {
922 "GDBRemoteCommunication::%s() found gdb-remote stub exe '%s'",
923 __FUNCTION__, debugserver_file_spec.
GetPath().c_str());
925 g_debugserver_file_spec = debugserver_file_spec;
928 debugserver_file_spec =
931 debugserver_file_spec.
Clear();
932 if (debugserver_file_spec) {
935 debugserver_exists =
true;
938 "GDBRemoteCommunication::%s() could not find "
939 "gdb-remote stub exe '%s'",
940 __FUNCTION__, debugserver_file_spec.
GetPath().c_str());
944 g_debugserver_file_spec.
Clear();
949 if (debugserver_exists) {
950 debugserver_file_spec.
GetPath(debugserver_path,
sizeof(debugserver_path));
953 debugserver_args.
Clear();
956 debugserver_args.
AppendArgument(llvm::StringRef(debugserver_path));
958#if !defined(__APPLE__)
967 if (pass_comm_fd >= 0) {
969 fd_arg.
Printf(
"--fd=%i", pass_comm_fd);
977 debugserver_args.
AppendArgument(llvm::StringRef(
"--native-regs"));
983 llvm::SmallString<128> named_pipe_path;
993 if (pass_comm_fd == -1) {
998#if defined(__APPLE__)
1001 error = socket_pipe.CreateWithUniqueName(
"debugserver-named-pipe",
1002 false, named_pipe_path);
1005 "GDBRemoteCommunication::%s() "
1006 "named pipe creation failed: %s",
1007 __FUNCTION__,
error.AsCString());
1010 debugserver_args.
AppendArgument(llvm::StringRef(
"--named-pipe"));
1015 error = socket_pipe.CreateNew(
true);
1018 "GDBRemoteCommunication::%s() "
1019 "unnamed pipe creation failed: %s",
1020 __FUNCTION__,
error.AsCString());
1023 pipe_t write = socket_pipe.GetWritePipe();
1034 "GDBRemoteCommunication::%s() unable to start listen "
1036 __FUNCTION__,
error.AsCString());
1042 uint16_t port_ = port_future.wait_for(std::chrono::seconds(10)) ==
1043 std::future_status::ready
1048 snprintf(port_cstr,
sizeof(port_cstr),
"127.0.0.1:%i", port_);
1052 debugserver_args.
AppendArgument(llvm::StringRef(
"--reverse-connect"));
1057 error.SetErrorString(
"failed to bind to port 0 on 127.0.0.1");
1058 LLDB_LOGF(log,
"GDBRemoteCommunication::%s() failed: %s",
1059 __FUNCTION__,
error.AsCString());
1064 std::string env_debugserver_log_file =
1065 host_env.lookup(
"LLDB_DEBUGSERVER_LOG_FILE");
1066 if (!env_debugserver_log_file.empty()) {
1068 llvm::formatv(
"--log-file={0}", env_debugserver_log_file).str());
1071#if defined(__APPLE__)
1072 const char *env_debugserver_log_flags =
1073 getenv(
"LLDB_DEBUGSERVER_LOG_FLAGS");
1074 if (env_debugserver_log_flags) {
1076 llvm::formatv(
"--log-flags={0}", env_debugserver_log_flags).str());
1079 std::string env_debugserver_log_channels =
1080 host_env.lookup(
"LLDB_SERVER_LOG_CHANNELS");
1081 if (!env_debugserver_log_channels.empty()) {
1083 llvm::formatv(
"--log-channels={0}", env_debugserver_log_channels)
1093 char env_var_name[64];
1094 snprintf(env_var_name,
sizeof(env_var_name),
1095 "LLDB_DEBUGSERVER_EXTRA_ARG_%" PRIu32, env_var_index++);
1096 std::string extra_arg = host_env.lookup(env_var_name);
1097 has_env_var = !extra_arg.empty();
1102 "GDBRemoteCommunication::%s adding env var %s contents "
1103 "to stub command line (%s)",
1104 __FUNCTION__, env_var_name, extra_arg.c_str());
1106 }
while (has_env_var);
1128 Platform *
const platform =
nullptr;
1129 launch_info.
Dump(string_stream, platform);
1130 LLDB_LOGF(log,
"launch info for gdb-remote stub:\n%s",
1135 if (
error.Success() &&
1137 pass_comm_fd == -1) {
1138 if (named_pipe_path.size() > 0) {
1139 error = socket_pipe.OpenAsReader(named_pipe_path,
false);
1142 "GDBRemoteCommunication::%s() "
1143 "failed to open named pipe %s for reading: %s",
1144 __FUNCTION__, named_pipe_path.c_str(),
error.AsCString());
1147 if (socket_pipe.CanWrite())
1148 socket_pipe.CloseWriteFileDescriptor();
1149 if (socket_pipe.CanRead()) {
1151 port_cstr[0] =
'\0';
1152 size_t num_bytes =
sizeof(port_cstr);
1154 error = socket_pipe.ReadWithTimeout(
1155 port_cstr, num_bytes, std::chrono::seconds{10}, num_bytes);
1156 if (
error.Success() && (port !=
nullptr)) {
1157 assert(num_bytes > 0 && port_cstr[num_bytes - 1] ==
'\0');
1160 llvm::to_integer(port_cstr, child_port);
1161 if (*port == 0 || *port == child_port) {
1164 "GDBRemoteCommunication::%s() "
1165 "debugserver listens %u port",
1166 __FUNCTION__, *port);
1169 "GDBRemoteCommunication::%s() "
1170 "debugserver listening on port "
1171 "%d but requested port was %d",
1176 "GDBRemoteCommunication::%s() "
1177 "failed to read a port value from pipe %s: %s",
1178 __FUNCTION__, named_pipe_path.c_str(),
error.AsCString());
1180 socket_pipe.Close();
1183 if (named_pipe_path.size() > 0) {
1184 const auto err = socket_pipe.Delete(named_pipe_path);
1187 "GDBRemoteCommunication::%s failed to delete pipe %s: %s",
1188 __FUNCTION__, named_pipe_path.c_str(), err.AsCString());
1200 LLDB_LOGF(log,
"GDBRemoteCommunication::%s() failed: %s", __FUNCTION__,
1212 const bool child_processes_inherit =
false;
1213 const int backlog = 5;
1214 TCPSocket listen_socket(
true, child_processes_inherit);
1215 if (llvm::Error
error =
1219 Socket *accept_socket =
nullptr;
1220 std::future<Status> accept_status = std::async(
1221 std::launch::async, [&] {
return listen_socket.
Accept(accept_socket); });
1223 llvm::SmallString<32> remote_addr;
1224 llvm::raw_svector_ostream(remote_addr)
1227 std::unique_ptr<ConnectionFileDescriptor> conn_up(
1231 return llvm::createStringError(llvm::inconvertibleErrorCode(),
1232 "Unable to connect: %s", status.
AsCString());
1235 if (llvm::Error
error = accept_status.get().ToError())
1239 std::make_unique<ConnectionFileDescriptor>(accept_socket));
1240 return llvm::Error::success();
1245 : m_gdb_comm(gdb_comm), m_saved_timeout(0), m_timeout_modified(false) {
1249 if (curr_timeout < timeout) {
1257 if (m_timeout_modified)
1258 m_gdb_comm.SetPacketTimeout(m_saved_timeout);
1261void llvm::format_provider<GDBRemoteCommunication::PacketResult>::format(
1271 Stream <<
"ErrorSendFailed";
1274 Stream <<
"ErrorSendAck";
1277 Stream <<
"ErrorReplyFailed";
1280 Stream <<
"ErrorReplyTimeout";
1283 Stream <<
"ErrorReplyInvalid";
1286 Stream <<
"ErrorReplyAck";
1289 Stream <<
"ErrorDisconnected";
1292 Stream <<
"ErrorNoSequenceLock";
1299 std::string decoded;
1300 decoded.reserve(packet.size());
1301 for (std::string::const_iterator c = packet.begin(); c != packet.end(); ++c) {
1305 char char_to_repeat = decoded.back();
1307 int repeat_count = *++c + 3 -
' ';
1310 for (
int i = 0; i < repeat_count; ++i)
1311 decoded.push_back(char_to_repeat);
1312 }
else if (*c == 0x7d) {
1315 char escapee = *++c ^ 0x20;
1316 decoded.push_back(escapee);
1318 decoded.push_back(*c);
static llvm::raw_ostream & error(Stream &strm)
#define DEBUGSERVER_BASENAME
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOGF(log,...)
#define LLDB_LOGV(log,...)
A command line argument class.
void AppendArguments(const Args &rhs)
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
void AppendArgument(llvm::StringRef arg_str, char quote_char='\0')
Appends a new argument to the end of the list argument list.
void Clear()
Clear the arguments.
An abstract communications class.
virtual 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.
bool IsConnected() const
Check if the connection is valid.
virtual void SetConnection(std::unique_ptr< Connection > connection)
Sets the connection that it to be used by this class.
size_t WriteAll(const void *src, size_t src_len, lldb::ConnectionStatus &status, Status *error_ptr)
Repeatedly attempt writing until either src_len bytes are written or a permanent failure occurs.
virtual lldb::ConnectionStatus Disconnect(Status *error_ptr=nullptr)
Disconnect the communications connection if one is currently connected.
static std::string ConnectionStatusAsString(lldb::ConnectionStatus status)
lldb_private::Connection * GetConnection()
lldb::ConnectionStatus Connect(llvm::StringRef url, Status *error_ptr) override
Connect using the connect string url.
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
void AppendPathComponent(llvm::StringRef component)
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
void Clear()
Clears the object state.
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
static FileSystem & Instance()
Status Join(lldb::thread_result_t *result)
static Status LaunchProcess(ProcessLaunchInfo &launch_info)
Launch the process specified in launch_info.
static Environment GetEnvironment()
void PutString(llvm::StringRef str)
void Dump(Stream &s, Platform *platform) const
lldb::pid_t GetProcessID() const
FileSpec & GetExecutableFile()
Environment & GetEnvironment()
bool AppendSuppressFileAction(int fd, bool read, bool write)
bool AppendCloseFileAction(int fd)
bool AppendDuplicateFileAction(int fd, int dup_fd)
bool GetLaunchInSeparateProcessGroup() const
bool Execute(llvm::StringRef string, llvm::SmallVectorImpl< llvm::StringRef > *matches=nullptr) const
Execute a regular expression match using the compiled regular expression that is already in this obje...
llvm::Error ToError() const
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
const char * GetData() const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
size_t size_t PutHex8(uint8_t uvalue)
Append an uint8_t value in the hexadecimal format to the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Status Listen(llvm::StringRef name, int backlog) override
Status Accept(Socket *&conn_socket) override
uint16_t GetLocalPortNumber() const
static llvm::Expected< HostThread > LaunchThread(llvm::StringRef name, std::function< lldb::thread_result_t()> thread_function, size_t min_stack_byte_size=0)
void Dump(Stream &strm) const
void AddPacket(char packet_char, GDBRemotePacket::Type type, uint32_t bytes_transmitted)
bool DidDumpToLog() const
std::chrono::seconds m_saved_timeout
GDBRemoteCommunication & m_gdb_comm
ScopedTimeout(GDBRemoteCommunication &gdb_comm, std::chrono::seconds timeout)
std::chrono::seconds SetPacketTimeout(std::chrono::seconds packet_timeout)
static llvm::Error ConnectLocally(GDBRemoteCommunication &client, GDBRemoteCommunication &server)
PacketResult ReadPacket(StringExtractorGDBRemote &response, Timeout< std::micro > timeout, bool sync_on_timeout)
Status StartDebugserverProcess(const char *url, Platform *platform, ProcessLaunchInfo &launch_info, uint16_t *port, const Args *inferior_args, int pass_comm_fd)
char CalculcateChecksum(llvm::StringRef payload)
lldb::thread_result_t ListenThread()
~GDBRemoteCommunication() override
PacketResult SendNotificationPacketNoLock(llvm::StringRef notify_type, std::deque< std::string > &queue, llvm::StringRef payload)
std::recursive_mutex m_bytes_mutex
PacketResult WaitForPacketNoLock(StringExtractorGDBRemote &response, Timeout< std::micro > timeout, bool sync_on_timeout)
void DumpHistory(Stream &strm)
bool CompressionIsEnabled()
LazyBool m_supports_qEcho
PacketResult SendRawPacketNoLock(llvm::StringRef payload, bool skip_ack=false)
CompressionType m_compression_type
PacketResult SendPacketNoLock(llvm::StringRef payload)
HostThread m_listen_thread
Status StartListenThread(const char *hostname="127.0.0.1", uint16_t port=0)
std::promise< uint16_t > m_port_promise
static std::string ExpandRLE(std::string)
Expand GDB run-length encoding.
std::chrono::seconds GetPacketTimeout() const
PacketType CheckForPacket(const uint8_t *src, size_t src_len, StringExtractorGDBRemote &packet)
GDBRemoteCommunicationHistory m_history
#define LLDB_INVALID_PROCESS_ID
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.
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.