================
@@ -0,0 +1,166 @@
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "Resource.h"
+#include "MCPError.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/Module.h"
+
+using namespace lldb_private::mcp;
+
+template <typename... Args>
+static llvm::Error createStringError(const char *format, Args &&...args) {
+  return llvm::createStringError(
+      llvm::formatv(format, std::forward<Args>(args)...).str());
+}
+
+static llvm::Error createUnsupportedURIError(llvm::StringRef uri) {
+  return llvm::make_error<UnsupportedURI>(uri.str());
+}
+
+protocol::Resource
+DebuggerResourceProvider::GetDebuggerResource(lldb::user_id_t debugger_id) {
+  protocol::Resource resource;
+  resource.uri = llvm::formatv("lldb://debugger/{0}", debugger_id);
+  resource.name = llvm::formatv("debugger {0}", debugger_id);
+  resource.description =
+      llvm::formatv("Information about debugger instance {0}", debugger_id);
+  resource.mimeType = "application/json";
+  return resource;
+}
+
+protocol::Resource
+DebuggerResourceProvider::GetTargetResource(lldb::user_id_t debugger_id,
+                                            lldb::user_id_t target_id) {
+  protocol::Resource resource;
+  resource.uri =
+      llvm::formatv("lldb://debugger/{0}/target/{1}", debugger_id, target_id);
+  resource.name = llvm::formatv("target {0}", target_id);
+  resource.description =
+      llvm::formatv("Information about target {0} in debugger instance {1}",
+                    target_id, debugger_id);
+  resource.mimeType = "application/json";
+  return resource;
+}
+
+std::vector<protocol::Resource> DebuggerResourceProvider::GetResources() const 
{
+  std::vector<protocol::Resource> resources;
+
+  const size_t num_debuggers = Debugger::GetNumDebuggers();
+  for (size_t i = 0; i < num_debuggers; ++i) {
+    lldb::DebuggerSP debugger_sp = Debugger::GetDebuggerAtIndex(i);
+    if (!debugger_sp)
+      continue;
+    resources.emplace_back(GetDebuggerResource(i));
+
+    TargetList &target_list = debugger_sp->GetTargetList();
+    const size_t num_targets = target_list.GetNumTargets();
----------------
JDevlieghere wrote:

I don't believe we have anything more stable. My hope is to rely on the 
listChanged notification in the future, so the client knows the resource went 
away. 

https://github.com/llvm/llvm-project/pull/148075
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to