Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lldb/include/lldb/Host/common/NativeProcessProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@ class NativeProcessProtocol {
"Not implemented");
}

/// Get the list of structured data plugins supported by this process. They
/// must match the `type` field used 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;
Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/Utility/StringExtractorGDBRemote.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class StringExtractorGDBRemote : public StringExtractor {
eServerPacketType_qRegisterInfo,
eServerPacketType_qShlibInfoAddr,
eServerPacketType_qStepPacketSupported,
eServerPacketType_qStructuredDataPlugins,
eServerPacketType_qSupported,
eServerPacketType_qSyncThreadStateSupported,
eServerPacketType_qThreadExtraInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Copy link
Contributor

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?

Copy link
Member Author

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 :(

Copy link
Contributor

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.


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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions lldb/source/Utility/StringExtractorGDBRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
14 changes: 14 additions & 0 deletions lldb/unittests/tools/lldb-server/tests/LLGSTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "TestBase.h"
#include "lldb/Host/Host.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"

using namespace llgs_tests;
using namespace lldb_private;
Expand Down Expand Up @@ -74,3 +75,16 @@ TEST_F(TestBase, LLGS_TEST(vAttachRichError)) {
testing::StartsWith(
"cannot attach to process 1 when another process with pid"))));
}

TEST_F(TestBase, LLGS_TEST(qStructuredDataPlugins)) {
auto ClientOr = TestClient::launchCustom(
getLogFileName(),
/* disable_stdio */ true, {}, {getInferiorPath("environment_check")});
ASSERT_THAT_EXPECTED(ClientOr, Succeeded());
auto &Client = **ClientOr;
std::string response_string;
ASSERT_THAT_ERROR(
Client.SendMessage("qStructuredDataPlugins", response_string),
Succeeded());
EXPECT_STREQ("[]", response_string.c_str());
}
Loading