16#include "lldb/Host/Config.h"
33#include "llvm/ADT/SmallString.h"
34#include "llvm/Support/ScopedPrinter.h"
39#define DEBUGSERVER_BASENAME "debugserver"
41#define DEBUGSERVER_BASENAME "lldb-server.exe"
43#define DEBUGSERVER_BASENAME "lldb-server"
46#if defined(HAVE_LIBCOMPRESSION)
47#include <compression.h>
61#ifdef LLDB_CONFIGURATION_DEBUG
62 m_packet_timeout(1000),
67 m_send_acks(true), m_is_platform(false),
77#if defined(HAVE_LIBCOMPRESSION)
78 if (m_decompression_scratch)
79 free (m_decompression_scratch);
86 for (
char c : payload)
89 return checksum & 255;
96 const size_t bytes_written =
WriteAll(&ch, 1, status,
nullptr);
97 LLDB_LOGF(log,
"<%4" PRIu64
"> send packet: %c", (uint64_t)bytes_written, ch);
106 const size_t bytes_written =
WriteAll(&ch, 1, status,
nullptr);
107 LLDB_LOGF(log,
"<%4" PRIu64
"> send packet: %c", (uint64_t)bytes_written, ch);
109 return bytes_written;
116 packet.
Write(payload.data(), payload.size());
119 std::string packet_str = std::string(packet.
GetString());
126 llvm::StringRef notify_type, std::deque<std::string> &queue,
127 llvm::StringRef payload) {
135 packet.
Write(notify_type.data(), notify_type.size());
137 packet.
Write(payload.data(), payload.size());
143 queue.push_back(payload.str());
153 const char *packet_data = packet.data();
154 const size_t packet_length = packet.size();
155 size_t bytes_written =
WriteAll(packet_data, packet_length, status,
nullptr);
157 size_t binary_start_offset = 0;
158 if (strncmp(packet_data,
"$vFile:pwrite:", strlen(
"$vFile:pwrite:")) ==
160 const char *first_comma = strchr(packet_data,
',');
162 const char *second_comma = strchr(first_comma + 1,
',');
164 binary_start_offset = second_comma - packet_data + 1;
175 if (binary_start_offset) {
178 strm.
Printf(
"<%4" PRIu64
"> send packet: %.*s", (uint64_t)bytes_written,
179 (
int)binary_start_offset, packet_data);
182 for (p = (
const uint8_t *)packet_data + binary_start_offset; *p !=
'#';
184 strm.
Printf(
"\\x%2.2x", *p);
186 strm.
Printf(
"%*s", (
int)3, p);
189 LLDB_LOGF(log,
"<%4" PRIu64
"> send packet: %.*s",
190 (uint64_t)bytes_written, (
int)packet_length, packet_data);
196 if (bytes_written == packet_length) {
202 LLDB_LOGF(log,
"error: failed to send packet: %.*s", (
int)packet_length,
225 bool sync_on_timeout) {
243 bool sync_on_timeout) {
244 uint8_t buffer[8192];
253 bool timed_out =
false;
254 bool disconnected =
false;
257 size_t bytes_read =
Read(buffer,
sizeof(buffer), timeout, status, &
error);
260 "Read(buffer, sizeof(buffer), timeout = {0}, "
261 "status = {1}, error = {2}) => bytes_read = {3}",
265 if (bytes_read > 0) {
272 if (sync_on_timeout) {
295 bool sync_success =
false;
296 bool got_actual_response =
false;
298 char echo_packet[32];
299 int echo_packet_len = 0;
303 echo_packet_len = ::snprintf(echo_packet,
sizeof(echo_packet),
305 std::string regex_str =
"^";
306 regex_str += echo_packet;
311 ::snprintf(echo_packet,
sizeof(echo_packet),
"qC");
319 const uint32_t max_retries = 3;
320 uint32_t successful_responses = 0;
321 for (uint32_t i = 0; i < max_retries; ++i) {
326 ++successful_responses;
330 }
else if (successful_responses == 1) {
335 packet = echo_response;
336 got_actual_response =
true;
350 if (got_actual_response) {
393 size_t pkt_size =
m_bytes.size();
406 size_t hash_mark_idx =
m_bytes.find(
'#');
407 if (hash_mark_idx == std::string::npos)
409 if (hash_mark_idx + 2 >=
m_bytes.size())
412 if (!::isxdigit(
m_bytes[hash_mark_idx + 1]) ||
413 !::isxdigit(
m_bytes[hash_mark_idx + 2]))
416 size_t content_length =
419 size_t content_start = 2;
421 size_t checksum_idx =
429 size_t size_of_first_packet = hash_mark_idx + 3;
436 uint64_t decompressed_bufsize = ULONG_MAX;
438 size_t i = content_start;
439 while (i < hash_mark_idx && isdigit(
m_bytes[i]))
441 if (i < hash_mark_idx &&
m_bytes[i] ==
':') {
444 content_length = hash_mark_idx - content_start;
445 std::string bufsize_str(
m_bytes.data() + 2, i - 2 - 1);
447 decompressed_bufsize = ::strtoul(bufsize_str.c_str(),
nullptr, 10);
448 if (errno != 0 || decompressed_bufsize == ULONG_MAX) {
449 m_bytes.erase(0, size_of_first_packet);
456 char packet_checksum_cstr[3];
457 packet_checksum_cstr[0] =
m_bytes[checksum_idx];
458 packet_checksum_cstr[1] =
m_bytes[checksum_idx + 1];
459 packet_checksum_cstr[2] =
'\0';
460 long packet_checksum = strtol(packet_checksum_cstr,
nullptr, 16);
463 llvm::StringRef(
m_bytes).substr(1, hash_mark_idx - 1));
464 bool success = packet_checksum == actual_checksum;
467 "error: checksum mismatch: %.*s expected 0x%2.2x, got 0x%2.2x",
468 (
int)(pkt_size),
m_bytes.c_str(), (uint8_t)packet_checksum,
469 (uint8_t)actual_checksum);
474 m_bytes.erase(0, size_of_first_packet);
490 std::vector<uint8_t> unescaped_content;
491 unescaped_content.reserve(content_length);
492 size_t i = content_start;
493 while (i < hash_mark_idx) {
496 unescaped_content.push_back(
m_bytes[i] ^ 0x20);
498 unescaped_content.push_back(
m_bytes[i]);
503 uint8_t *decompressed_buffer =
nullptr;
504 size_t decompressed_bytes = 0;
506 if (decompressed_bufsize != ULONG_MAX) {
507 decompressed_buffer = (uint8_t *)malloc(decompressed_bufsize);
508 if (decompressed_buffer ==
nullptr) {
509 m_bytes.erase(0, size_of_first_packet);
514#if defined(HAVE_LIBCOMPRESSION)
519 compression_algorithm compression_type;
521 compression_type = COMPRESSION_LZFSE;
523 compression_type = COMPRESSION_ZLIB;
525 compression_type = COMPRESSION_LZ4_RAW;
527 compression_type = COMPRESSION_LZMA;
530 if (m_decompression_scratch) {
531 free (m_decompression_scratch);
532 m_decompression_scratch =
nullptr;
534 size_t scratchbuf_size = 0;
536 scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZFSE);
538 scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZ4_RAW);
540 scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_ZLIB);
543 compression_decode_scratch_buffer_size(COMPRESSION_LZMA);
544 if (scratchbuf_size > 0) {
545 m_decompression_scratch = (
void*) malloc (scratchbuf_size);
550 if (decompressed_bufsize != ULONG_MAX && decompressed_buffer !=
nullptr) {
551 decompressed_bytes = compression_decode_buffer(
552 decompressed_buffer, decompressed_bufsize,
553 (uint8_t *)unescaped_content.data(), unescaped_content.size(),
554 m_decompression_scratch, compression_type);
560 if (decompressed_bytes == 0 && decompressed_bufsize != ULONG_MAX &&
561 decompressed_buffer !=
nullptr &&
564 memset(&stream, 0,
sizeof(z_stream));
565 stream.next_in = (Bytef *)unescaped_content.data();
566 stream.avail_in = (uInt)unescaped_content.size();
568 stream.next_out = (Bytef *)decompressed_buffer;
569 stream.avail_out = decompressed_bufsize;
570 stream.total_out = 0;
571 stream.zalloc = Z_NULL;
572 stream.zfree = Z_NULL;
573 stream.opaque = Z_NULL;
575 if (inflateInit2(&stream, -15) == Z_OK) {
576 int status = inflate(&stream, Z_NO_FLUSH);
578 if (status == Z_STREAM_END) {
579 decompressed_bytes = stream.total_out;
585 if (decompressed_bytes == 0 || decompressed_buffer ==
nullptr) {
586 if (decompressed_buffer)
587 free(decompressed_buffer);
588 m_bytes.erase(0, size_of_first_packet);
592 std::string new_packet;
593 new_packet.reserve(decompressed_bytes + 6);
594 new_packet.push_back(
m_bytes[0]);
595 new_packet.append((
const char *)decompressed_buffer, decompressed_bytes);
596 new_packet.push_back(
'#');
599 llvm::StringRef((
const char *)decompressed_buffer, decompressed_bytes));
600 char decompressed_checksum_str[3];
601 snprintf(decompressed_checksum_str, 3,
"%02x", decompressed_checksum);
602 new_packet.append(decompressed_checksum_str);
604 new_packet.push_back(
'0');
605 new_packet.push_back(
'0');
608 m_bytes.replace(0, size_of_first_packet, new_packet.data(),
611 free(decompressed_buffer);
623 if (src && src_len > 0) {
626 LLDB_LOGF(log,
"GDBRemoteCommunication::%s adding %u bytes: %.*s",
627 __FUNCTION__, (uint32_t)src_len, (uint32_t)src_len, src);
629 m_bytes.append((
const char *)src, src_len);
632 bool isNotifyPacket =
false;
638 size_t content_start = 0;
639 size_t content_length = 0;
640 size_t total_length = 0;
641 size_t checksum_idx = std::string::npos;
644 size_t original_packet_size =
m_bytes.size();
656 content_length = total_length = 1;
660 isNotifyPacket =
true;
666 size_t hash_pos =
m_bytes.find(
'#');
667 if (hash_pos != std::string::npos) {
668 if (hash_pos + 2 <
m_bytes.size()) {
669 checksum_idx = hash_pos + 1;
674 content_length = hash_pos - 1;
680 content_length = std::string::npos;
691 const size_t bytes_len =
m_bytes.size();
694 for (idx = 1; !done && idx < bytes_len; ++idx) {
708 LLDB_LOGF(log,
"GDBRemoteCommunication::%s tossing %u junk bytes: '%.*s'",
709 __FUNCTION__, idx - 1, idx - 1,
m_bytes.c_str());
714 if (content_length == std::string::npos) {
717 }
else if (total_length > 0) {
720 assert(content_length <=
m_bytes.size());
721 assert(total_length <=
m_bytes.size());
722 assert(content_length <= total_length);
723 size_t content_end = content_start + content_length;
737 if (
m_bytes[0] ==
'$' && total_length > 4) {
738 for (
size_t i = 0; !binary && i < total_length; ++i) {
740 if (!llvm::isPrint(c) && !llvm::isSpace(c)) {
749 strm.
Printf(
"<%4" PRIu64
":%" PRIu64
"> read packet: %c",
750 (uint64_t)original_packet_size, (uint64_t)total_length,
753 strm.
Printf(
"<%4" PRIu64
"> read packet: %c",
754 (uint64_t)total_length,
m_bytes[0]);
755 for (
size_t i = content_start; i < content_end; ++i) {
761 const char escapee =
m_bytes[++i] ^ 0x20;
762 strm.
Printf(
"%2.2x", escapee);
764 strm.
Printf(
"%2.2x", (uint8_t)ch);
773 LLDB_LOGF(log,
"<%4" PRIu64
":%" PRIu64
"> read packet: %.*s",
774 (uint64_t)original_packet_size, (uint64_t)total_length,
775 (
int)(total_length),
m_bytes.c_str());
777 LLDB_LOGF(log,
"<%4" PRIu64
"> read packet: %.*s",
778 (uint64_t)total_length, (
int)(total_length),
788 std ::string packet_str =
793 assert(checksum_idx <
m_bytes.size());
794 if (::isxdigit(
m_bytes[checksum_idx + 0]) ||
795 ::isxdigit(
m_bytes[checksum_idx + 1])) {
797 const char *packet_checksum_cstr = &
m_bytes[checksum_idx];
798 char packet_checksum = strtol(packet_checksum_cstr,
nullptr, 16);
800 llvm::StringRef(
m_bytes).slice(content_start, content_end));
801 success = packet_checksum == actual_checksum;
804 "error: checksum mismatch: %.*s expected 0x%2.2x, "
806 (
int)(total_length),
m_bytes.c_str(),
807 (uint8_t)packet_checksum, (uint8_t)actual_checksum);
817 LLDB_LOGF(log,
"error: invalid checksum in packet: '%s'\n",
822 m_bytes.erase(0, total_length);
838 return Status(
"listen thread already running");
840 char listen_url[512];
841 if (hostname && hostname[0])
842 snprintf(listen_url,
sizeof(listen_url),
"listen://%s:%i", hostname, port);
844 snprintf(listen_url,
sizeof(listen_url),
"listen://%i", port);
850 return Status(listen_thread.takeError());
871 [
this](llvm::StringRef port_str) {
873 llvm::to_integer(port_str, port, 10);
874 m_port_promise.set_value(port);
884 uint16_t *port,
const Args *inferior_args,
int pass_comm_fd) {
886 LLDB_LOGF(log,
"GDBRemoteCommunication::%s(url=%s, port=%" PRIu16
")",
887 __FUNCTION__, url ? url :
"<empty>", port ? *port : uint16_t(0));
891 static FileSpec g_debugserver_file_spec;
900 std::string env_debugserver_path = host_env.lookup(
"LLDB_DEBUGSERVER_PATH");
901 if (!env_debugserver_path.empty()) {
902 debugserver_file_spec.
SetFile(env_debugserver_path,
903 FileSpec::Style::native);
905 "GDBRemoteCommunication::%s() gdb-remote stub exe path set "
906 "from environment variable: %s",
907 __FUNCTION__, env_debugserver_path.c_str());
909 debugserver_file_spec = g_debugserver_file_spec;
910 bool debugserver_exists =
912 if (!debugserver_exists) {
914 debugserver_file_spec = HostInfo::GetSupportExeDir();
915 if (debugserver_file_spec) {
918 if (debugserver_exists) {
920 "GDBRemoteCommunication::%s() found gdb-remote stub exe '%s'",
921 __FUNCTION__, debugserver_file_spec.
GetPath().c_str());
923 g_debugserver_file_spec = debugserver_file_spec;
926 debugserver_file_spec =
929 debugserver_file_spec.
Clear();
930 if (debugserver_file_spec) {
933 debugserver_exists =
true;
936 "GDBRemoteCommunication::%s() could not find "
937 "gdb-remote stub exe '%s'",
938 __FUNCTION__, debugserver_file_spec.
GetPath().c_str());
942 g_debugserver_file_spec.
Clear();
947 if (debugserver_exists) {
948 debugserver_file_spec.
GetPath(debugserver_path,
sizeof(debugserver_path));
951 debugserver_args.
Clear();
954 debugserver_args.
AppendArgument(llvm::StringRef(debugserver_path));
956#if !defined(__APPLE__)
965 if (pass_comm_fd >= 0) {
967 fd_arg.
Printf(
"--fd=%i", pass_comm_fd);
975 debugserver_args.
AppendArgument(llvm::StringRef(
"--native-regs"));
981 llvm::SmallString<128> named_pipe_path;
991 if (pass_comm_fd == -1) {
996#if defined(__APPLE__)
1000 false, named_pipe_path);
1003 "GDBRemoteCommunication::%s() "
1004 "named pipe creation failed: %s",
1005 __FUNCTION__,
error.AsCString());
1008 debugserver_args.
AppendArgument(llvm::StringRef(
"--named-pipe"));
1016 "GDBRemoteCommunication::%s() "
1017 "unnamed pipe creation failed: %s",
1018 __FUNCTION__,
error.AsCString());
1032 "GDBRemoteCommunication::%s() unable to start listen "
1034 __FUNCTION__,
error.AsCString());
1040 uint16_t port_ = port_future.wait_for(std::chrono::seconds(10)) ==
1041 std::future_status::ready
1046 snprintf(port_cstr,
sizeof(port_cstr),
"127.0.0.1:%i", port_);
1050 debugserver_args.
AppendArgument(llvm::StringRef(
"--reverse-connect"));
1055 error.SetErrorString(
"failed to bind to port 0 on 127.0.0.1");
1056 LLDB_LOGF(log,
"GDBRemoteCommunication::%s() failed: %s",
1057 __FUNCTION__,
error.AsCString());
1062 std::string env_debugserver_log_file =
1063 host_env.lookup(
"LLDB_DEBUGSERVER_LOG_FILE");
1064 if (!env_debugserver_log_file.empty()) {
1066 llvm::formatv(
"--log-file={0}", env_debugserver_log_file).str());
1069#if defined(__APPLE__)
1070 const char *env_debugserver_log_flags =
1071 getenv(
"LLDB_DEBUGSERVER_LOG_FLAGS");
1072 if (env_debugserver_log_flags) {
1074 llvm::formatv(
"--log-flags={0}", env_debugserver_log_flags).str());
1077 std::string env_debugserver_log_channels =
1078 host_env.lookup(
"LLDB_SERVER_LOG_CHANNELS");
1079 if (!env_debugserver_log_channels.empty()) {
1081 llvm::formatv(
"--log-channels={0}", env_debugserver_log_channels)
1088 uint32_t env_var_index = 1;
1091 char env_var_name[64];
1092 snprintf(env_var_name,
sizeof(env_var_name),
1093 "LLDB_DEBUGSERVER_EXTRA_ARG_%" PRIu32, env_var_index++);
1094 std::string extra_arg = host_env.lookup(env_var_name);
1095 has_env_var = !extra_arg.empty();
1100 "GDBRemoteCommunication::%s adding env var %s contents "
1101 "to stub command line (%s)",
1102 __FUNCTION__, env_var_name, extra_arg.c_str());
1104 }
while (has_env_var);
1126 Platform *
const platform =
nullptr;
1127 launch_info.
Dump(string_stream, platform);
1128 LLDB_LOGF(log,
"launch info for gdb-remote stub:\n%s",
1133 if (
error.Success() &&
1135 pass_comm_fd == -1) {
1136 if (named_pipe_path.size() > 0) {
1140 "GDBRemoteCommunication::%s() "
1141 "failed to open named pipe %s for reading: %s",
1142 __FUNCTION__, named_pipe_path.c_str(),
error.AsCString());
1149 char port_cstr[6] = {0};
1150 size_t num_bytes =
sizeof(port_cstr);
1153 port_cstr, num_bytes, std::chrono::seconds{10}, num_bytes);
1154 if (
error.Success() && (port !=
nullptr)) {
1155 assert(num_bytes > 0 && port_cstr[num_bytes - 1] ==
'\0');
1156 uint16_t child_port = 0;
1158 llvm::to_integer(port_cstr, child_port);
1159 if (*port == 0 || *port == child_port) {
1162 "GDBRemoteCommunication::%s() "
1163 "debugserver listens %u port",
1164 __FUNCTION__, *port);
1167 "GDBRemoteCommunication::%s() "
1168 "debugserver listening on port "
1169 "%d but requested port was %d",
1170 __FUNCTION__, (uint32_t)child_port, (uint32_t)(*port));
1174 "GDBRemoteCommunication::%s() "
1175 "failed to read a port value from pipe %s: %s",
1176 __FUNCTION__, named_pipe_path.c_str(),
error.AsCString());
1178 socket_pipe.
Close();
1181 if (named_pipe_path.size() > 0) {
1182 const auto err = socket_pipe.
Delete(named_pipe_path);
1185 "GDBRemoteCommunication::%s failed to delete pipe %s: %s",
1186 __FUNCTION__, named_pipe_path.c_str(), err.AsCString());
1198 LLDB_LOGF(log,
"GDBRemoteCommunication::%s() failed: %s", __FUNCTION__,
1210 const bool child_processes_inherit =
false;
1211 const int backlog = 5;
1212 TCPSocket listen_socket(
true, child_processes_inherit);
1213 if (llvm::Error
error =
1217 Socket *accept_socket =
nullptr;
1218 std::future<Status> accept_status = std::async(
1219 std::launch::async, [&] {
return listen_socket.
Accept(accept_socket); });
1221 llvm::SmallString<32> remote_addr;
1222 llvm::raw_svector_ostream(remote_addr)
1225 std::unique_ptr<ConnectionFileDescriptor> conn_up(
1229 return llvm::createStringError(llvm::inconvertibleErrorCode(),
1230 "Unable to connect: %s", status.
AsCString());
1233 if (llvm::Error
error = accept_status.get().ToError())
1237 std::make_unique<ConnectionFileDescriptor>(accept_socket));
1238 return llvm::Error::success();
1243 : m_gdb_comm(gdb_comm), m_saved_timeout(0), m_timeout_modified(false) {
1247 if (curr_timeout < timeout) {
1255 if (m_timeout_modified)
1256 m_gdb_comm.SetPacketTimeout(m_saved_timeout);
1259void llvm::format_provider<GDBRemoteCommunication::PacketResult>::format(
1269 Stream <<
"ErrorSendFailed";
1272 Stream <<
"ErrorSendAck";
1275 Stream <<
"ErrorReplyFailed";
1278 Stream <<
"ErrorReplyTimeout";
1281 Stream <<
"ErrorReplyInvalid";
1284 Stream <<
"ErrorReplyAck";
1287 Stream <<
"ErrorDisconnected";
1290 Stream <<
"ErrorNoSequenceLock";
1297 std::string decoded;
1298 decoded.reserve(packet.size());
1299 for (std::string::const_iterator c = packet.begin(); c != packet.end(); ++c) {
1303 char char_to_repeat = decoded.back();
1305 int repeat_count = *++c + 3 -
' ';
1308 for (
int i = 0; i < repeat_count; ++i)
1309 decoded.push_back(char_to_repeat);
1310 }
else if (*c == 0x7d) {
1313 char escapee = *++c ^ 0x20;
1314 decoded.push_back(escapee);
1316 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)
A posix-based implementation of Pipe, a class that abtracts unix style pipes.
Status OpenAsReader(llvm::StringRef name, bool child_process_inherit) override
int GetReadFileDescriptor() const override
lldb::pipe_t GetWritePipe() const override
void CloseWriteFileDescriptor() override
bool CanWrite() const override
bool CanRead() const override
Status ReadWithTimeout(void *buf, size_t size, const std::chrono::microseconds &timeout, size_t &bytes_read) override
Status Delete(llvm::StringRef name) override
Status CreateWithUniqueName(llvm::StringRef prefix, bool child_process_inherit, llvm::SmallVectorImpl< char > &name) override
Status CreateNew(bool child_process_inherit) override
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.