Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h @@ -124,19 +124,8 @@ ~GDBRemoteCommunication() override; - PacketResult GetAck(); - size_t SendAck(); - size_t SendNack(); - - char CalculcateChecksum(llvm::StringRef payload); - - PacketType CheckForPacket(const uint8_t *src, size_t src_len, - StringExtractorGDBRemote &packet); - - bool GetSendAcks() { return m_send_acks; } - // Set the global packet timeout. // // For clients, this is the timeout that gets used when sending @@ -167,18 +156,9 @@ static llvm::Error ConnectLocally(GDBRemoteCommunication &client, GDBRemoteCommunication &server); - /// Expand GDB run-length encoding. - static std::string ExpandRLE(std::string); - protected: - std::chrono::seconds m_packet_timeout; - uint32_t m_echo_number; LazyBool m_supports_qEcho; - GDBRemoteCommunicationHistory m_history; bool m_send_acks; - bool m_is_platform; // Set to true if this class represents a platform, - // false if this class represents a debug session for - // a single process CompressionType m_compression_type; @@ -186,8 +166,6 @@ PacketResult SendNotificationPacketNoLock(llvm::StringRef notify_type, std::deque& queue, llvm::StringRef payload); - PacketResult SendRawPacketNoLock(llvm::StringRef payload, - bool skip_ack = false); PacketResult ReadPacket(StringExtractorGDBRemote &response, Timeout timeout, bool sync_on_timeout); @@ -197,6 +175,43 @@ bool sync_on_timeout, llvm::function_ref output_callback); + Status StartListenThread(const char *hostname = "127.0.0.1", + uint16_t port = 0); + +private: + std::chrono::seconds m_packet_timeout; + uint32_t m_echo_number; + GDBRemoteCommunicationHistory m_history; + + // Promise used to grab the port number from listening thread + std::promise m_port_promise; + + HostThread m_listen_thread; + std::string m_listen_url; + +#if defined(HAVE_LIBCOMPRESSION) + CompressionType m_decompression_scratch_type = CompressionType::None; + void *m_decompression_scratch = nullptr; +#endif + + GDBRemoteCommunication(const GDBRemoteCommunication &) = delete; + const GDBRemoteCommunication & + operator=(const GDBRemoteCommunication &) = delete; + + PacketResult GetAck(); + + size_t SendNack(); + + char CalculcateChecksum(llvm::StringRef payload); + + PacketType CheckForPacket(const uint8_t *src, size_t src_len, + StringExtractorGDBRemote &packet); + + bool GetSendAcks() { return m_send_acks; } + + PacketResult SendRawPacketNoLock(llvm::StringRef payload, + bool skip_ack = false); + PacketResult WaitForPacketNoLock(StringExtractorGDBRemote &response, Timeout timeout, bool sync_on_timeout); @@ -216,28 +231,9 @@ // on m_bytes. The checksum was for the compressed packet. bool DecompressPacket(); - Status StartListenThread(const char *hostname = "127.0.0.1", - uint16_t port = 0); - bool JoinListenThread(); lldb::thread_result_t ListenThread(); - -private: - // Promise used to grab the port number from listening thread - std::promise m_port_promise; - - HostThread m_listen_thread; - std::string m_listen_url; - -#if defined(HAVE_LIBCOMPRESSION) - CompressionType m_decompression_scratch_type = CompressionType::None; - void *m_decompression_scratch = nullptr; -#endif - - GDBRemoteCommunication(const GDBRemoteCommunication &) = delete; - const GDBRemoteCommunication & - operator=(const GDBRemoteCommunication &) = delete; }; } // namespace process_gdb_remote Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -60,15 +60,14 @@ // GDBRemoteCommunication constructor GDBRemoteCommunication::GDBRemoteCommunication(const char *comm_name, const char *listener_name) - : Communication(comm_name), + : Communication(comm_name), m_supports_qEcho(eLazyBoolCalculate), + m_send_acks(true), m_compression_type(CompressionType::None), #ifdef LLDB_CONFIGURATION_DEBUG m_packet_timeout(1000), #else m_packet_timeout(1), #endif - m_echo_number(0), m_supports_qEcho(eLazyBoolCalculate), m_history(512), - m_send_acks(true), m_is_platform(false), - m_compression_type(CompressionType::None), m_listen_url() { + m_echo_number(0), m_history(512), m_listen_url() { } // Destructor @@ -633,6 +632,33 @@ return true; } +static std::string ExpandRLE(std::string packet) { + // Reserve enough byte for the most common case (no RLE used). + std::string decoded; + decoded.reserve(packet.size()); + for (std::string::const_iterator c = packet.begin(); c != packet.end(); ++c) { + if (*c == '*') { + // '*' indicates RLE. Next character will give us the repeat count and + // previous character is what is to be repeated. + char char_to_repeat = decoded.back(); + // Number of time the previous character is repeated. + int repeat_count = *++c + 3 - ' '; + // We have the char_to_repeat and repeat_count. Now push it in the + // packet. + for (int i = 0; i < repeat_count; ++i) + decoded.push_back(char_to_repeat); + } else if (*c == 0x7d) { + // 0x7d is the escape character. The next character is to be XOR'd with + // 0x20. + char escapee = *++c ^ 0x20; + decoded.push_back(escapee); + } else { + decoded.push_back(*c); + } + } + return decoded; +} + GDBRemoteCommunication::PacketType GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len, StringExtractorGDBRemote &packet) { @@ -1317,30 +1343,3 @@ break; } } - -std::string GDBRemoteCommunication::ExpandRLE(std::string packet) { - // Reserve enough byte for the most common case (no RLE used). - std::string decoded; - decoded.reserve(packet.size()); - for (std::string::const_iterator c = packet.begin(); c != packet.end(); ++c) { - if (*c == '*') { - // '*' indicates RLE. Next character will give us the repeat count and - // previous character is what is to be repeated. - char char_to_repeat = decoded.back(); - // Number of time the previous character is repeated. - int repeat_count = *++c + 3 - ' '; - // We have the char_to_repeat and repeat_count. Now push it in the - // packet. - for (int i = 0; i < repeat_count; ++i) - decoded.push_back(char_to_repeat); - } else if (*c == 0x7d) { - // 0x7d is the escape character. The next character is to be XOR'd with - // 0x20. - char escapee = *++c ^ 0x20; - decoded.push_back(escapee); - } else { - decoded.push_back(*c); - } - } - return decoded; -} Index: lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp =================================================================== --- lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp +++ lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp @@ -66,6 +66,5 @@ ASSERT_TRUE(Write(Test.Packet)); ASSERT_EQ(PacketResult::Success, client.ReadPacket(response)); ASSERT_EQ(Test.Payload, response.GetStringRef()); - ASSERT_EQ(PacketResult::Success, server.GetAck()); } }