
This PR moves the MCP protocol code into its own library (`lldbProtocolMCP`) so the code can be shared between the `ProtocolServerMCP` plugin in LLDB as well as `lldb-mcp`. The goal is to do the same thing for DAP (which, for now, would be used exclusively from `lldb-dap`). To make it clear that it's neither part of the `lldb` nor the `lldb_private` namespace, I created a new `lldb_protocol` namespace. Depending on how much code would be reused by lldb-dap, we may move more code into the protocol library.
53 lines
1.8 KiB
C++
53 lines
1.8 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLDB_PLUGINS_PROTOCOL_MCP_RESOURCE_H
|
|
#define LLDB_PLUGINS_PROTOCOL_MCP_RESOURCE_H
|
|
|
|
#include "lldb/Protocol/MCP/Protocol.h"
|
|
#include "lldb/lldb-private.h"
|
|
#include <vector>
|
|
|
|
namespace lldb_private::mcp {
|
|
|
|
class ResourceProvider {
|
|
public:
|
|
ResourceProvider() = default;
|
|
virtual ~ResourceProvider() = default;
|
|
|
|
virtual std::vector<lldb_protocol::mcp::Resource> GetResources() const = 0;
|
|
virtual llvm::Expected<lldb_protocol::mcp::ResourceResult>
|
|
ReadResource(llvm::StringRef uri) const = 0;
|
|
};
|
|
|
|
class DebuggerResourceProvider : public ResourceProvider {
|
|
public:
|
|
using ResourceProvider::ResourceProvider;
|
|
virtual ~DebuggerResourceProvider() = default;
|
|
|
|
virtual std::vector<lldb_protocol::mcp::Resource>
|
|
GetResources() const override;
|
|
virtual llvm::Expected<lldb_protocol::mcp::ResourceResult>
|
|
ReadResource(llvm::StringRef uri) const override;
|
|
|
|
private:
|
|
static lldb_protocol::mcp::Resource GetDebuggerResource(Debugger &debugger);
|
|
static lldb_protocol::mcp::Resource GetTargetResource(size_t target_idx,
|
|
Target &target);
|
|
|
|
static llvm::Expected<lldb_protocol::mcp::ResourceResult>
|
|
ReadDebuggerResource(llvm::StringRef uri, lldb::user_id_t debugger_id);
|
|
static llvm::Expected<lldb_protocol::mcp::ResourceResult>
|
|
ReadTargetResource(llvm::StringRef uri, lldb::user_id_t debugger_id,
|
|
size_t target_idx);
|
|
};
|
|
|
|
} // namespace lldb_private::mcp
|
|
|
|
#endif
|