[Lldb-commits] [lldb] [lldb] Add `scripting extension list --instances` (PR #226043)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 6 17:58:59 PDT 2026


================
@@ -0,0 +1,109 @@
+//===----------------------------------------------------------------------===//
+//
+// 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_INTERPRETER_SCRIPTEDINSTANCEREGISTRY_H
+#define LLDB_INTERPRETER_SCRIPTEDINSTANCEREGISTRY_H
+
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/StructuredData.h"
+#include "lldb/Utility/UUID.h"
+#include "lldb/lldb-defines.h"
+#include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-forward.h"
+#include "lldb/lldb-types.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+
+#include <cstdint>
+#include <mutex>
+#include <string>
+#include <vector>
+
+namespace lldb_private {
+
+struct ScriptedInstanceInfo {
+  uint64_t id = 0;
+  UUID uuid;
+  lldb::addr_t object_address = LLDB_INVALID_ADDRESS;
+  /// The interface's PluginManager name, from the string literal its
+  /// GetPluginNameStatic() returns, so this never dangles.
+  llvm::StringRef plugin_name;
+  std::string class_name;
+  FileSpec source_path;
+  StructuredData::DictionarySP args_sp;
+};
+
+/// The live instances of one extension class. Instances belong to the same
+/// group when they share a class name, source path and extension kind, so a
+/// class reused for several kinds of extension gets one group per kind.
+struct ScriptedInstanceGroup {
+  std::string class_name;
+  lldb::ScriptedExtension extension = lldb::eScriptedExtensionInvalid;
+  FileSpec source_path;
+  std::vector<ScriptedInstanceInfo> instances;
+
+  bool operator<(const ScriptedInstanceGroup &other) const;
+
+  StructuredData::DictionarySP ToStructuredData() const;
+
+  void Dump(Stream &s, const Debugger &debugger, bool use_color) const;
+};
+
+/// Entries are snapshots taken when the object is created, so listing them
+/// never calls back into an interface that might be mid-destruction on
+/// another thread.
+class ScriptedInstanceRegistry {
+public:
+  uint64_t Add(ScriptedInstanceInfo info) {
+    std::lock_guard<std::mutex> guard(m_mutex);
+    const uint64_t id = m_next_id++;
+    info.id = id;
+    info.uuid = UUID::Generate();
+    m_instances[id] = std::move(info);
+    return id;
+  }
+
+  void Remove(uint64_t id) {
+    std::lock_guard<std::mutex> guard(m_mutex);
+    m_instances.erase(id);
+  }
+
+  std::vector<ScriptedInstanceInfo> GetInstances() const {
+    std::vector<ScriptedInstanceInfo> instances = CopyInstances();
+    llvm::sort(instances, CreatedBefore);
+    return instances;
+  }
----------------
JDevlieghere wrote:

Let's move all the bodies to the `.cpp` file to speed up compilation. I think this class is doing too much in the header.

https://github.com/llvm/llvm-project/pull/226043


More information about the lldb-commits mailing list