Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h @@ -145,6 +145,11 @@ virtual FileSpec FindModuleFile(const std::string &module_path, const ArchSpec &arch); + // Process client_features (qSupported) and return an array of server features + // to be returned in response. + virtual std::vector + HandleFeatures(const llvm::ArrayRef client_features); + private: ModuleSpec GetModuleInfo(llvm::StringRef module_path, llvm::StringRef triple); }; Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -831,26 +831,11 @@ GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerCommon::Handle_qSupported( StringExtractorGDBRemote &packet) { - StreamGDBRemote response; - - // Features common to lldb-platform and llgs. - uint32_t max_packet_size = 128 * 1024; // 128KBytes is a reasonable max packet - // size--debugger can always use less - response.Printf("PacketSize=%x", max_packet_size); - - response.PutCString(";QStartNoAckMode+"); - response.PutCString(";QThreadSuffixSupported+"); - response.PutCString(";QListThreadsInStopReply+"); - response.PutCString(";qEcho+"); - response.PutCString(";qXfer:features:read+"); -#if defined(__linux__) || defined(__NetBSD__) || defined(__FreeBSD__) - response.PutCString(";QPassSignals+"); - response.PutCString(";qXfer:auxv:read+"); - response.PutCString(";qXfer:libraries-svr4:read+"); -#endif - response.PutCString(";multiprocess+"); - - return SendPacketNoLock(response.GetString()); + // Parse client-indicated features. + llvm::StringRef view = packet.GetStringRef(); + llvm::SmallVector client_features; + view.split(client_features, ';'); + return SendPacketNoLock(llvm::join(HandleFeatures(client_features), ";")); } GDBRemoteCommunication::PacketResult @@ -1312,3 +1297,17 @@ return matched_module_spec; } + +std::vector GDBRemoteCommunicationServerCommon::HandleFeatures( + const llvm::ArrayRef client_features) { + // 128KBytes is a reasonable max packet size--debugger can always use less. + constexpr uint32_t max_packet_size = 128 * 1024; + + // Features common to platform server and llgs. + return { + llvm::formatv("PacketSize={0}", max_packet_size), + "QStartNoAckMode+", + "QThreadSuffixSupported+", + "qEcho+", + }; +} Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h @@ -219,6 +219,9 @@ static std::string XMLEncodeAttributeValue(llvm::StringRef value); + virtual std::vector + HandleFeatures(const llvm::ArrayRef client_features) override; + private: llvm::Expected> BuildTargetXml(); Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -3534,3 +3534,16 @@ return tid; } + +std::vector GDBRemoteCommunicationServerLLGS::HandleFeatures( + const llvm::ArrayRef client_features) { + auto ret = + GDBRemoteCommunicationServerCommon::HandleFeatures(client_features); + ret.insert(ret.end(), { + "qXfer:features:read+", "multiprocess+", +#if defined(__linux__) || defined(__NetBSD__) || defined(__FreeBSD__) + "QPassSignals+", "qXfer:auxv:read+", "qXfer:libraries-svr4:read+", +#endif + }); + return ret; +}