-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[LLDB] Add support for the structured data plugins in lldb-server #159457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[LLDB] Add support for the structured data plugins in lldb-server #159457
Conversation
@llvm/pr-subscribers-lldb Author: Walter Erquinigo (walter-erquinigo) ChangesThe LLDB client has support for structured data plugins, but lldb-server doesn't have corresponding support for it. This patch adds the missing functionality in LLGS for servers to register their supported plugins and send corresponding async messages. I couldn't find a reasonable way to add a test for this, but the changes are trivial. I tested them with my custom server manually. Full diff: https://github.com/llvm/llvm-project/pull/159457.diff 5 Files Affected:
diff --git a/lldb/include/lldb/Host/common/NativeProcessProtocol.h b/lldb/include/lldb/Host/common/NativeProcessProtocol.h
index 1d5fecfcd5c27..a09a54bcc5ec3 100644
--- a/lldb/include/lldb/Host/common/NativeProcessProtocol.h
+++ b/lldb/include/lldb/Host/common/NativeProcessProtocol.h
@@ -409,6 +409,14 @@ class NativeProcessProtocol {
"Not implemented");
}
+ /// Get the list of structured data plugins supported by this process
+ /// plugin. They must match the `type` fieldused by the corresponding
+ /// StructuredDataPlugins in the client.
+ ///
+ /// \return
+ /// A vector of structured data plugin names.
+ virtual std::vector<std::string> GetStructuredDataPlugins() { return {}; };
+
protected:
struct SoftwareBreakpoint {
uint32_t ref_count;
diff --git a/lldb/include/lldb/Utility/StringExtractorGDBRemote.h b/lldb/include/lldb/Utility/StringExtractorGDBRemote.h
index dd468ef5bddef..439245fdc3083 100644
--- a/lldb/include/lldb/Utility/StringExtractorGDBRemote.h
+++ b/lldb/include/lldb/Utility/StringExtractorGDBRemote.h
@@ -119,6 +119,7 @@ class StringExtractorGDBRemote : public StringExtractor {
eServerPacketType_qRegisterInfo,
eServerPacketType_qShlibInfoAddr,
eServerPacketType_qStepPacketSupported,
+ eServerPacketType_qStructuredDataPlugins,
eServerPacketType_qSupported,
eServerPacketType_qSyncThreadStateSupported,
eServerPacketType_qThreadExtraInfo,
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index e3202d62ec7c8..2f62415446b7a 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -146,6 +146,9 @@ void GDBRemoteCommunicationServerLLGS::RegisterPacketHandlers() {
RegisterMemberFunctionHandler(
StringExtractorGDBRemote::eServerPacketType_QSetWorkingDir,
&GDBRemoteCommunicationServerLLGS::Handle_QSetWorkingDir);
+ RegisterMemberFunctionHandler(
+ StringExtractorGDBRemote::eServerPacketType_qStructuredDataPlugins,
+ &GDBRemoteCommunicationServerLLGS::Handle_qStructuredDataPlugins);
RegisterMemberFunctionHandler(
StringExtractorGDBRemote::eServerPacketType_qsThreadInfo,
&GDBRemoteCommunicationServerLLGS::Handle_qsThreadInfo);
@@ -1245,6 +1248,19 @@ Status GDBRemoteCommunicationServerLLGS::InitializeConnection(
return error;
}
+GDBRemoteCommunication::PacketResult
+GDBRemoteCommunicationServerLLGS::SendStructuredDataPacket(
+ const llvm::json::Value &value) {
+ std::string json_string;
+ raw_string_ostream os(json_string);
+ os << value;
+
+ StreamGDBRemote escaped_response;
+ escaped_response.PutCString("JSON-async:");
+ escaped_response.PutEscapedBytes(json_string.c_str(), json_string.size());
+ return SendPacketNoLock(escaped_response.GetString());
+}
+
GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerLLGS::SendONotification(const char *buffer,
uint32_t len) {
@@ -1436,6 +1452,21 @@ GDBRemoteCommunicationServerLLGS::Handle_jLLDBTraceGetBinaryData(
return SendErrorResponse(bytes.takeError());
}
+GDBRemoteCommunication::PacketResult
+GDBRemoteCommunicationServerLLGS::Handle_qStructuredDataPlugins(
+ StringExtractorGDBRemote &packet) {
+ // Fail if we don't have a current process.
+ if (!m_current_process ||
+ (m_current_process->GetID() == LLDB_INVALID_PROCESS_ID))
+ return SendErrorResponse(68);
+
+ std::vector<std::string> structured_data_plugins =
+ m_current_process->GetStructuredDataPlugins();
+
+ return SendJSONResponse(
+ llvm::json::Value(llvm::json::Array(structured_data_plugins)));
+}
+
GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerLLGS::Handle_qProcessInfo(
StringExtractorGDBRemote &packet) {
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
index 646b6a102abf6..b400cc2fc21cd 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
@@ -86,6 +86,9 @@ class GDBRemoteCommunicationServerLLGS
Status InitializeConnection(std::unique_ptr<Connection> connection);
+ GDBRemoteCommunication::PacketResult
+ SendStructuredDataPacket(const llvm::json::Value &value);
+
struct DebuggedProcess {
enum class Flag {
vkilled = (1u << 0),
@@ -185,6 +188,8 @@ class GDBRemoteCommunicationServerLLGS
PacketResult Handle_qsThreadInfo(StringExtractorGDBRemote &packet);
+ PacketResult Handle_qStructuredDataPlugins(StringExtractorGDBRemote &packet);
+
PacketResult Handle_p(StringExtractorGDBRemote &packet);
PacketResult Handle_P(StringExtractorGDBRemote &packet);
diff --git a/lldb/source/Utility/StringExtractorGDBRemote.cpp b/lldb/source/Utility/StringExtractorGDBRemote.cpp
index c5755b2733605..010149ad4b381 100644
--- a/lldb/source/Utility/StringExtractorGDBRemote.cpp
+++ b/lldb/source/Utility/StringExtractorGDBRemote.cpp
@@ -280,6 +280,8 @@ StringExtractorGDBRemote::GetServerPacketType() const {
return eServerPacketType_qSupported;
if (PACKET_MATCHES("qSyncThreadStateSupported"))
return eServerPacketType_qSyncThreadStateSupported;
+ if (PACKET_MATCHES("qStructuredDataPlugins"))
+ return eServerPacketType_qStructuredDataPlugins;
break;
case 'T':
|
587b5db
to
c86981d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change looks fine to me. Can we add a test for the qStructuredDataPlugins
packet here?
https://github.com/llvm/llvm-project/blob/main/lldb/unittests/tools/lldb-server/tests/LLGSTest.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the 68
mean something special here? Can we use a named constant instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually don't know what it means, but the entire file does that :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, well makes sense to follow the pattern here then.
The LLDB client has support for structured data plugins, but lldb-server doesn't have corresponding support for it. This patch adds the missing functionality in LLGS for servers to register their supported plugins and send corresponding async messages. I couldn't find a reasonable way to add a test for this, but the changes are trivial. I tested them with my custom server manually.
c86981d
to
30b75dd
Compare
@dmpots , I've added the test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, well makes sense to follow the pattern here then.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/59/builds/24402 Here is the relevant piece of the build log for the reference
|
…vm#159457) The LLDB client has support for structured data plugins, but lldb-server doesn't have corresponding support for it. This patch adds the missing functionality in LLGS for servers to register their supported plugins and send corresponding async messages.
…vm#159457) The LLDB client has support for structured data plugins, but lldb-server doesn't have corresponding support for it. This patch adds the missing functionality in LLGS for servers to register their supported plugins and send corresponding async messages.
The LLDB client has support for structured data plugins, but lldb-server doesn't have corresponding support for it. This patch adds the missing functionality in LLGS for servers to register their supported plugins and send corresponding async messages.