16#include "lldb/Host/Config.h"
33#include "llvm/ADT/SmallString.h"
34#include "llvm/Config/llvm-config.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");
320 const uint32_t max_retries = 3;
321 uint32_t successful_responses = 0;
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);
544 compression_decode_scratch_buffer_size(COMPRESSION_LZMA);
545 if (scratchbuf_size > 0) {
546 m_decompression_scratch = (
void*) malloc (scratchbuf_size);
551 if (decompressed_bufsize != ULONG_MAX && decompressed_buffer !=
nullptr) {
552 decompressed_bytes = compression_decode_buffer(
553 decompressed_buffer, decompressed_bufsize,
554 (uint8_t *)unescaped_content.data(), unescaped_content.size(),
555 m_decompression_scratch, compression_type);
561 if (decompressed_bytes == 0 && decompressed_bufsize != ULONG_MAX &&
562 decompressed_buffer !=
nullptr &&
565 memset(&stream, 0,
sizeof(z_stream));
566 stream.next_in = (Bytef *)unescaped_content.data();
567 stream.avail_in = (uInt)unescaped_content.size();
569 stream.next_out = (Bytef *)decompressed_buffer;
570 stream.avail_out = decompressed_bufsize;
571 stream.total_out = 0;
572 stream.zalloc = Z_NULL;
573 stream.zfree = Z_NULL;
574 stream.opaque = Z_NULL;
576 if (inflateInit2(&stream, -15) == Z_OK) {
577 int status = inflate(&stream, Z_NO_FLUSH);
579 if (status == Z_STREAM_END) {
580 decompressed_bytes = stream.total_out;
586 if (decompressed_bytes == 0 || decompressed_buffer ==
nullptr) {
587 if (decompressed_buffer)
588 free(decompressed_buffer);
589 m_bytes.erase(0, size_of_first_packet);
593 std::string new_packet;
594 new_packet.reserve(decompressed_bytes + 6);
595 new_packet.push_back(
m_bytes[0]);
596 new_packet.append((
const char *)decompressed_buffer, decompressed_bytes);
597 new_packet.push_back(
'#');
600 llvm::StringRef((
const char *)decompressed_buffer, decompressed_bytes));
601 char decompressed_checksum_str[3];
602 snprintf(decompressed_checksum_str, 3,
"%02x", decompressed_checksum);
603 new_packet.append(decompressed_checksum_str);
605 new_packet.push_back(
'0');
606 new_packet.push_back(
'0');
609 m_bytes.replace(0, size_of_first_packet, new_packet.data(),
612 free(decompressed_buffer);
624 if (src && src_len > 0) {
627 LLDB_LOGF(log,
"GDBRemoteCommunication::%s adding %u bytes: %.*s",
628 __FUNCTION__, (uint32_t)src_len, (uint32_t)src_len, src);
630 m_bytes.append((
const char *)src, src_len);
633 bool isNotifyPacket =
false;
639 size_t content_start = 0;
640 size_t content_length = 0;
641 size_t total_length = 0;
642 size_t checksum_idx = std::string::npos;
645 size_t original_packet_size =
m_bytes.size();
657 content_length = total_length = 1;
661 isNotifyPacket =
true;
667 size_t hash_pos =
m_bytes.find(
'#');
668 if (hash_pos != std::string::npos) {
669 if (hash_pos + 2 <
m_bytes.size()) {
670 checksum_idx = hash_pos + 1;
675 content_length = hash_pos - 1;
681 content_length = std::string::npos;
692 const size_t bytes_len =
m_bytes.size();
695 for (idx = 1; !done && idx < bytes_len; ++idx) {
709 LLDB_LOGF(log,
"GDBRemoteCommunication::%s tossing %u junk bytes: '%.*s'",
710 __FUNCTION__, idx - 1, idx - 1,
m_bytes.c_str());
715 if (content_length == std::string::npos) {
718 }
else if (total_length > 0) {
721 assert(content_length <=
m_bytes.size());
722 assert(total_length <=
m_bytes.size());
723 assert(content_length <= total_length);
724 size_t content_end = content_start + content_length;
738 if (
m_bytes[0] ==
'$' && total_length > 4) {
739 for (
size_t i = 0; !binary && i < total_length; ++i) {
741 if (!llvm::isPrint(c) && !llvm::isSpace(c)) {
750 strm.
Printf(
"<%4" PRIu64
":%" PRIu64
"> read packet: %c",
751 (uint64_t)original_packet_size, (uint64_t)total_length,
754 strm.
Printf(
"<%4" PRIu64
"> read packet: %c",
755 (uint64_t)total_length,
m_bytes[0]);
756 for (
size_t i = content_start; i < content_end; ++i) {
762 const char escapee =
m_bytes[++i] ^ 0x20;
763 strm.
Printf(
"%2.2x", escapee);
765 strm.
Printf(
"%2.2x", (uint8_t)ch);
774 LLDB_LOGF(log,
"<%4" PRIu64
":%" PRIu64
"> read packet: %.*s",
775 (uint64_t)original_packet_size, (uint64_t)total_length,
776 (
int)(total_length),
m_bytes.c_str());
778 LLDB_LOGF(log,
"<%4" PRIu64
"> read packet: %.*s",
779 (uint64_t)total_length, (
int)(total_length),
789 std ::string packet_str =
794 assert(checksum_idx <
m_bytes.size());
795 if (::isxdigit(
m_bytes[checksum_idx + 0]) ||
796 ::isxdigit(
m_bytes[checksum_idx + 1])) {
798 const char *packet_checksum_cstr = &
m_bytes[checksum_idx];
799 char packet_checksum = strtol(packet_checksum_cstr,
nullptr, 16);
801 llvm::StringRef(
m_bytes).slice(content_start, content_end));
802 success = packet_checksum == actual_checksum;
805 "error: checksum mismatch: %.*s expected 0x%2.2x, "
807 (
int)(total_length),
m_bytes.c_str(),
808 (uint8_t)packet_checksum, (uint8_t)actual_checksum);
818 LLDB_LOGF(log,
"error: invalid checksum in packet: '%s'\n",
823 m_bytes.erase(0, total_length);
841 char listen_url[512];
842 if (hostname && hostname[0])
843 snprintf(listen_url,
sizeof(listen_url),
"listen://%s:%i", hostname, port);
845 snprintf(listen_url,
sizeof(listen_url),
"listen://%i", port);
872 [
this](llvm::StringRef port_str) {
874 llvm::to_integer(port_str, port, 10);
875 m_port_promise.set_value(port);
886 static FileSpec g_debugserver_file_spec;
893 std::string env_debugserver_path = host_env.lookup(
"LLDB_DEBUGSERVER_PATH");
894 if (!env_debugserver_path.empty()) {
895 debugserver_file_spec.
SetFile(env_debugserver_path,
896 FileSpec::Style::native);
898 "GDBRemoteCommunication::%s() gdb-remote stub exe path set "
899 "from environment variable: %s",
900 __FUNCTION__, env_debugserver_path.c_str());
902 debugserver_file_spec = g_debugserver_file_spec;
903 bool debugserver_exists =
905 if (!debugserver_exists) {
907 debugserver_file_spec = HostInfo::GetSupportExeDir();
908 if (debugserver_file_spec) {
911 if (debugserver_exists) {
913 "GDBRemoteCommunication::%s() found gdb-remote stub exe '%s'",
914 __FUNCTION__, debugserver_file_spec.
GetPath().c_str());
916 g_debugserver_file_spec = debugserver_file_spec;
919 debugserver_file_spec =
922 debugserver_file_spec.
Clear();
923 if (debugserver_file_spec) {
926 debugserver_exists =
true;
929 "GDBRemoteCommunication::%s() could not find "
930 "gdb-remote stub exe '%s'",
931 __FUNCTION__, debugserver_file_spec.
GetPath().c_str());
935 g_debugserver_file_spec.
Clear();
939 return debugserver_file_spec;
946 LLDB_LOGF(log,
"GDBRemoteCommunication::%s(url=%s, port=%" PRIu16
")",
947 __FUNCTION__, url ? url :
"<empty>", port ? *port : uint16_t(0));
952 std::string debugserver_path = debugserver_file_spec.
GetPath();
955 debugserver_args.
Clear();
958 debugserver_args.
AppendArgument(llvm::StringRef(debugserver_path));
960#if !defined(__APPLE__)
971 fd_arg.
Printf(
"--fd=%" PRIi64, (int64_t)pass_comm_fd);
982 debugserver_args.
AppendArgument(llvm::StringRef(
"--native-regs"));
988 llvm::SmallString<128> named_pipe_path;
1003#if defined(__APPLE__)
1007 false, named_pipe_path);
1010 "GDBRemoteCommunication::%s() "
1011 "named pipe creation failed: %s",
1012 __FUNCTION__,
error.AsCString());
1015 debugserver_args.
AppendArgument(llvm::StringRef(
"--named-pipe"));
1023 "GDBRemoteCommunication::%s() "
1024 "unnamed pipe creation failed: %s",
1025 __FUNCTION__,
error.AsCString());
1039 "GDBRemoteCommunication::%s() unable to start listen "
1041 __FUNCTION__,
error.AsCString());
1047 uint16_t port_ = port_future.wait_for(std::chrono::seconds(10)) ==
1048 std::future_status::ready
1053 snprintf(port_cstr,
sizeof(port_cstr),
"127.0.0.1:%i", port_);
1057 debugserver_args.
AppendArgument(llvm::StringRef(
"--reverse-connect"));
1062 LLDB_LOGF(log,
"GDBRemoteCommunication::%s() failed: %s",
1063 __FUNCTION__,
error.AsCString());
1065 "failed to bind to port 0 on 127.0.0.1");
1071 std::string env_debugserver_log_file =
1072 host_env.lookup(
"LLDB_DEBUGSERVER_LOG_FILE");
1073 if (!env_debugserver_log_file.empty()) {
1075 llvm::formatv(
"--log-file={0}", env_debugserver_log_file).str());
1078#if defined(__APPLE__)
1079 const char *env_debugserver_log_flags =
1080 getenv(
"LLDB_DEBUGSERVER_LOG_FLAGS");
1081 if (env_debugserver_log_flags) {
1083 llvm::formatv(
"--log-flags={0}", env_debugserver_log_flags).str());
1086 std::string env_debugserver_log_channels =
1087 host_env.lookup(
"LLDB_SERVER_LOG_CHANNELS");
1088 if (!env_debugserver_log_channels.empty()) {
1090 llvm::formatv(
"--log-channels={0}", env_debugserver_log_channels)
1097 uint32_t env_var_index = 1;
1100 char env_var_name[64];
1101 snprintf(env_var_name,
sizeof(env_var_name),
1102 "LLDB_DEBUGSERVER_EXTRA_ARG_%" PRIu32, env_var_index++);
1103 std::string extra_arg = host_env.lookup(env_var_name);
1104 has_env_var = !extra_arg.empty();
1109 "GDBRemoteCommunication::%s adding env var %s contents "
1110 "to stub command line (%s)",
1111 __FUNCTION__, env_var_name, extra_arg.c_str());
1113 }
while (has_env_var);
1135 Platform *
const platform =
nullptr;
1136 launch_info.
Dump(string_stream, platform);
1137 LLDB_LOGF(log,
"launch info for gdb-remote stub:\n%s",
1142 if (
error.Success() &&
1145 if (named_pipe_path.size() > 0) {
1149 "GDBRemoteCommunication::%s() "
1150 "failed to open named pipe %s for reading: %s",
1151 __FUNCTION__, named_pipe_path.c_str(),
error.AsCString());
1158 char port_cstr[6] = {0};
1159 size_t num_bytes =
sizeof(port_cstr);
1162 port_cstr, num_bytes, std::chrono::seconds{10}, num_bytes);
1163 if (
error.Success() && (port !=
nullptr)) {
1164 assert(num_bytes > 0 && port_cstr[num_bytes - 1] ==
'\0');
1165 uint16_t child_port = 0;
1167 llvm::to_integer(port_cstr, child_port);
1168 if (*port == 0 || *port == child_port) {
1171 "GDBRemoteCommunication::%s() "
1172 "debugserver listens %u port",
1173 __FUNCTION__, *port);
1176 "GDBRemoteCommunication::%s() "
1177 "debugserver listening on port "
1178 "%d but requested port was %d",
1179 __FUNCTION__, (uint32_t)child_port, (uint32_t)(*port));
1183 "GDBRemoteCommunication::%s() "
1184 "failed to read a port value from pipe %s: %s",
1185 __FUNCTION__, named_pipe_path.c_str(),
error.AsCString());
1187 socket_pipe.
Close();
1190 if (named_pipe_path.size() > 0) {
1191 const auto err = socket_pipe.
Delete(named_pipe_path);
1194 "GDBRemoteCommunication::%s failed to delete pipe %s: %s",
1195 __FUNCTION__, named_pipe_path.c_str(), err.AsCString());
1207 LLDB_LOGF(log,
"GDBRemoteCommunication::%s() failed: %s", __FUNCTION__,
1219 const int backlog = 5;
1221 if (llvm::Error
error =
1225 llvm::SmallString<32> remote_addr;
1226 llvm::raw_svector_ostream(remote_addr)
1229 std::unique_ptr<ConnectionFileDescriptor> conn_up(
1233 return llvm::createStringError(llvm::inconvertibleErrorCode(),
1234 "Unable to connect: %s", status.
AsCString());
1238 Socket *accept_socket =
nullptr;
1239 if (
Status accept_status =
1240 listen_socket.
Accept(std::chrono::seconds(1), accept_socket);
1241 accept_status.Fail())
1242 return accept_status.takeError();
1246 std::make_unique<ConnectionFileDescriptor>(accept_socket));
1247 return llvm::Error::success();
1252 : m_gdb_comm(gdb_comm), m_saved_timeout(0), m_timeout_modified(false) {
1256 if (curr_timeout < timeout) {
1264 if (m_timeout_modified)
1265 m_gdb_comm.SetPacketTimeout(m_saved_timeout);
1268void llvm::format_provider<GDBRemoteCommunication::PacketResult>::format(
1278 Stream <<
"ErrorSendFailed";
1281 Stream <<
"ErrorSendAck";
1284 Stream <<
"ErrorReplyFailed";
1287 Stream <<
"ErrorReplyTimeout";
1290 Stream <<
"ErrorReplyInvalid";
1293 Stream <<
"ErrorReplyAck";
1296 Stream <<
"ErrorDisconnected";
1299 Stream <<
"ErrorNoSequenceLock";
1306 std::string decoded;
1307 decoded.reserve(packet.size());
1308 for (std::string::const_iterator c = packet.begin(); c != packet.end(); ++c) {
1312 char char_to_repeat = decoded.back();
1314 int repeat_count = *++c + 3 -
' ';
1317 for (
int i = 0; i < repeat_count; ++i)
1318 decoded.push_back(char_to_repeat);
1319 }
else if (*c == 0x7d) {
1322 char escapee = *++c ^ 0x20;
1323 decoded.push_back(escapee);
1325 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...
static const shared_fd_t kInvalidFD
llvm::Error ToError() const
FIXME: Replace all uses with takeError() instead.
static Status FromErrorString(const char *str)
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
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
llvm::Expected< std::vector< MainLoopBase::ReadHandleUP > > Accept(MainLoopBase &loop, std::function< void(std::unique_ptr< Socket > socket)> sock_cb) 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)
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
FileSpec GetDebugserverPath(Platform *platform)
Status StartDebugserverProcess(const char *url, Platform *platform, ProcessLaunchInfo &launch_info, uint16_t *port, const Args *inferior_args, shared_fd_t pass_comm_fd)
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.