Author: Michał Górny Date: 2021-04-13T12:12:25+02:00 New Revision: aab81c2f40d2098f9014473a1e7c8fb7b074360b
URL: https://github.com/llvm/llvm-project/commit/aab81c2f40d2098f9014473a1e7c8fb7b074360b DIFF: https://github.com/llvm/llvm-project/commit/aab81c2f40d2098f9014473a1e7c8fb7b074360b.diff LOG: [lldb] [gdb-remote server] Refactor handling qSupported Refactor handling qSupported to use a virtual HandleFeatures() method. The client-provided features are split into an array and passed to the method. The method returns an array of server features that are concatenated into the qSupported response to the server. The base implementation of HandleFeatures() in GDBRemoteCommunicationServerCommon now includes only flags common to both platform server and llgs, while llgs-specific flags are inserted in GDBRemoteCommunicationServerLLGS. Differential Revision: https://reviews.llvm.org/D100140 Added: Modified: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h Removed: ################################################################################ diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp index c933364cff9c..a0d88b3ab988 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -831,26 +831,10 @@ GDBRemoteCommunicationServerCommon::Handle_qPlatform_chmod( 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::SmallVector<llvm::StringRef, 4> client_features; + packet.GetStringRef().split(client_features, ';'); + return SendPacketNoLock(llvm::join(HandleFeatures(client_features), ";")); } GDBRemoteCommunication::PacketResult @@ -1312,3 +1296,18 @@ GDBRemoteCommunicationServerCommon::GetModuleInfo(llvm::StringRef module_path, return matched_module_spec; } + +std::vector<std::string> GDBRemoteCommunicationServerCommon::HandleFeatures( + const llvm::ArrayRef<llvm::StringRef> 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+", + "QListThreadsInStopReply+", + "qEcho+", + }; +} diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h index 0f933c09cbd4..51d9fdd68037 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h @@ -145,6 +145,11 @@ class GDBRemoteCommunicationServerCommon : public GDBRemoteCommunicationServer { 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<std::string> + HandleFeatures(llvm::ArrayRef<llvm::StringRef> client_features); + private: ModuleSpec GetModuleInfo(llvm::StringRef module_path, llvm::StringRef triple); }; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp index 2f615866a2f4..e9034cb7414a 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -3534,3 +3534,16 @@ GDBRemoteCommunicationServerLLGS::ReadTid(StringExtractorGDBRemote &packet, return tid; } + +std::vector<std::string> GDBRemoteCommunicationServerLLGS::HandleFeatures( + const llvm::ArrayRef<llvm::StringRef> 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; +} diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h index ef7d4471acf6..de7ba6873823 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h @@ -219,6 +219,9 @@ class GDBRemoteCommunicationServerLLGS static std::string XMLEncodeAttributeValue(llvm::StringRef value); + virtual std::vector<std::string> HandleFeatures( + const llvm::ArrayRef<llvm::StringRef> client_features) override; + private: llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> BuildTargetXml(); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits