[Lldb-commits] [lldb] [lldb] Let language plugins register their mangling schemes (PR #232925)

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 2 09:58:42 PST 2026


================
@@ -36,6 +41,165 @@ using namespace lldb_private;
 
 #pragma mark Mangled
 
+namespace {
+/// A mangling scheme that a language plugin registered.
+struct RegisteredManglingScheme {
+  static constexpr size_t g_inline_prefixes = 12;
+  static constexpr size_t g_inline_prefix_length = 16;
+
+  llvm::SmallVector<llvm::SmallString<g_inline_prefix_length>,
+                    g_inline_prefixes>
+      prefixes;
+  /// If set, a name that starts with one of the prefixes must also match.
+  Mangled::ManglingSchemeMatcher matches = nullptr;
+  lldb::LanguageType language = lldb::eLanguageTypeUnknown;
+  /// Schemes are never removed, so that GetManglingScheme() can read them
+  /// without a lock. Unregistered schemes are only marked inactive. No other
+  /// data is published through this flag, so it needs no memory ordering.
+  std::atomic<bool> active = false;
+};
+
+/// The mangling schemes that language plugins registered.
+class ManglingSchemeRegistry {
+public:
+  Mangled::ManglingScheme Register(llvm::ArrayRef<llvm::StringRef> prefixes,
+                                   lldb::LanguageType language,
+                                   Mangled::ManglingSchemeMatcher matches);
+  void Unregister(Mangled::ManglingScheme scheme);
+  lldb::LanguageType GetLanguage(Mangled::ManglingScheme scheme) const;
+  Mangled::ManglingScheme Find(llvm::StringRef name) const;
+
+private:
+  /// Serializes registering and unregistering schemes.
+  std::mutex m_mutex;
+  std::array<RegisteredManglingScheme,
+             Mangled::g_num_mangling_schemes -
+                 Mangled::eFirstRegisteredManglingScheme>
+      m_schemes;
+  /// The number of initialized entries in m_schemes. Incrementing it publishes
+  /// a new entry to readers.
+  std::atomic<size_t> m_num_schemes = 0;
+};
+} // namespace
+
+static ManglingSchemeRegistry &GetManglingSchemeRegistry() {
+  // Never destroyed, since other threads may still look up mangling schemes
+  // while static destructors run at exit.
+  static ManglingSchemeRegistry *g_registry = new ManglingSchemeRegistry();
----------------
adrian-prantl wrote:

I am not sure this is correct. For a static the destructor would run at exit. But as the comment says, other destructors might still access the registry.

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


More information about the lldb-commits mailing list