17struct DebuggerResource {
18 uint64_t debugger_id = 0;
20 uint64_t num_targets = 0;
23llvm::json::Value
toJSON(
const DebuggerResource &DR) {
24 llvm::json::Object Result{{
"debugger_id", DR.debugger_id},
25 {
"num_targets", DR.num_targets}};
27 Result.insert({
"name", DR.name});
31struct TargetResource {
32 size_t debugger_id = 0;
33 size_t target_idx = 0;
34 bool selected =
false;
41llvm::json::Value
toJSON(
const TargetResource &TR) {
42 llvm::json::Object Result{{
"debugger_id", TR.debugger_id},
43 {
"target_idx", TR.target_idx},
44 {
"selected", TR.selected},
47 Result.insert({
"arch", TR.arch});
49 Result.insert({
"path", TR.path});
50 if (!TR.platform.empty())
51 Result.insert({
"platform", TR.platform});
58template <
typename...
Args>
60 return llvm::createStringError(
61 llvm::formatv(format, std::forward<Args>(args)...).str());
65 return llvm::make_error<UnsupportedURI>(uri.str());
73 resource.
uri = llvm::formatv(
"lldb://debugger/{0}", debugger_id);
76 llvm::formatv(
"Information about debugger instance {0}: {1}", debugger_id,
86 std::string target_name = llvm::formatv(
"target {0}", target_idx);
89 target_name = exe_module->GetFileSpec().GetFilename().GetString();
93 llvm::formatv(
"lldb://debugger/{0}/target/{1}", debugger_id, target_idx);
94 resource.
name = target_name;
96 llvm::formatv(
"Information about target {0} in debugger instance {1}",
97 target_idx, debugger_id);
102std::vector<lldb_protocol::mcp::Resource>
104 std::vector<lldb_protocol::mcp::Resource> resources;
107 for (
size_t i = 0; i < num_debuggers; ++i) {
113 TargetList &target_list = debugger_sp->GetTargetList();
115 for (
size_t j = 0; j < num_targets; ++j) {
126llvm::Expected<lldb_protocol::mcp::ReadResourceResult>
129 auto [protocol, path] = uri.split(
"://");
131 if (protocol !=
"lldb")
134 llvm::SmallVector<llvm::StringRef, 4> components;
135 path.split(components,
'/');
137 if (components.size() < 2)
140 if (components[0] !=
"debugger")
144 if (components[1].getAsInteger(0, debugger_idx))
148 if (components.size() > 3) {
149 if (components[2] !=
"target")
153 if (components[3].getAsInteger(0, target_idx))
163llvm::Expected<lldb_protocol::mcp::ReadResourceResult>
170 DebuggerResource debugger_resource;
171 debugger_resource.debugger_id = debugger_id;
172 debugger_resource.name = debugger_sp->GetInstanceName();
173 debugger_resource.num_targets = debugger_sp->GetTargetList().GetNumTargets();
178 contents.
text = llvm::formatv(
"{0}",
toJSON(debugger_resource));
181 result.
contents.push_back(contents);
185llvm::Expected<lldb_protocol::mcp::ReadResourceResult>
194 TargetList &target_list = debugger_sp->GetTargetList();
199 TargetResource target_resource;
200 target_resource.debugger_id = debugger_id;
201 target_resource.target_idx = target_idx;
202 target_resource.arch = target_sp->GetArchitecture().GetTriple().str();
203 target_resource.dummy = target_sp->IsDummyTarget();
204 target_resource.selected = target_sp == debugger_sp->GetSelectedTarget();
206 if (
Module *exe_module = target_sp->GetExecutableModulePointer())
207 target_resource.path = exe_module->GetFileSpec().GetPath();
209 target_resource.platform = platform_sp->GetName();
214 contents.
text = llvm::formatv(
"{0}",
toJSON(target_resource));
217 result.
contents.push_back(contents);
static constexpr llvm::StringLiteral kMimeTypeJSON
static llvm::Error createUnsupportedURIError(llvm::StringRef uri)
static llvm::Error createStringError(const char *format, Args &&...args)
A command line argument class.
A class to manage flag bits.
static lldb::DebuggerSP GetDebuggerAtIndex(size_t index)
const std::string & GetInstanceName() const
static lldb::DebuggerSP FindDebuggerWithID(lldb::user_id_t id)
static size_t GetNumDebuggers()
A class that describes an executable image and its associated object and symbol files.
lldb::TargetSP GetTargetAtIndex(uint32_t index) const
size_t GetNumTargets() const
Module * GetExecutableModulePointer()
Debugger & GetDebugger() const
llvm::Expected< lldb_protocol::mcp::ReadResourceResult > ReadResource(llvm::StringRef uri) const override
static llvm::Expected< lldb_protocol::mcp::ReadResourceResult > ReadTargetResource(llvm::StringRef uri, lldb::user_id_t debugger_id, size_t target_idx)
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::ReadResourceResult > ReadDebuggerResource(llvm::StringRef uri, lldb::user_id_t debugger_id)
std::vector< lldb_protocol::mcp::Resource > GetResources() const override
A class that represents a running process on the host machine.
llvm::json::Value toJSON(const TraceSupportedResponse &packet)
llvm::json::Value toJSON(const Request &)
std::shared_ptr< lldb_private::Platform > PlatformSP
std::shared_ptr< lldb_private::Debugger > DebuggerSP
std::shared_ptr< lldb_private::Target > TargetSP
lldb::user_id_t GetID() const
Get accessor for the user ID.
The server's response to a resources/read request from the client.
std::vector< TextResourceContents > contents
A known resource that the server is capable of reading.
std::string description
A description of what this resource represents.
std::string uri
The URI of this resource.
std::string mimeType
The MIME type of this resource, if known.
std::string name
A human-readable name for this resource.
The contents of a specific resource or sub-resource.
std::string text
The text of the item.
std::string uri
The URI of this resource.
std::string mimeType
The MIME type of this resource, if known.