[llvm-branch-commits] [lldb] [lldb] Register 'target modules dump pcm-info' from TypeSystemClang (PR #229786)

Charles Zablit via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Oct 7 07:58:18 PDT 2026


https://github.com/charles-zablit created https://github.com/llvm/llvm-project/pull/229786

<sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>

>From 02bb8214979747aee1408f6e0fb5ded3dd92d065 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Wed, 7 Oct 2026 15:26:35 +0100
Subject: [PATCH] [lldb] Register 'target modules dump pcm-info' from
 TypeSystemClang

---
 lldb/include/lldb/Core/PluginManager.h        | 10 ++-
 lldb/source/Commands/CMakeLists.txt           |  3 -
 lldb/source/Commands/CommandObjectTarget.cpp  | 63 ---------------
 lldb/source/Core/PluginManager.cpp            | 13 +--
 .../Plugins/TypeSystem/Clang/CMakeLists.txt   |  2 +
 .../TypeSystem/Clang/TypeSystemClang.cpp      | 79 +++++++++++++++++++
 .../TypeSystem/Clang/TypeSystemClang.h        |  2 +
 7 files changed, 97 insertions(+), 75 deletions(-)

diff --git a/lldb/include/lldb/Core/PluginManager.h b/lldb/include/lldb/Core/PluginManager.h
index 8636a40d00b13..94d90db2854ba 100644
--- a/lldb/include/lldb/Core/PluginManager.h
+++ b/lldb/include/lldb/Core/PluginManager.h
@@ -650,10 +650,12 @@ class PluginManager {
   GetInstrumentationRuntimeCallbacks(bool enabled_only = true);
 
   // TypeSystem
-  static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
-                             TypeSystemCreateInstance create_callback,
-                             LanguageSet supported_languages_for_types,
-                             LanguageSet supported_languages_for_expressions);
+  static bool
+  RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
+                 TypeSystemCreateInstance create_callback,
+                 LanguageSet supported_languages_for_types,
+                 LanguageSet supported_languages_for_expressions,
+                 DebuggerInitializeCallback debugger_init_callback = nullptr);
 
   static bool UnregisterPlugin(TypeSystemCreateInstance create_callback);
 
diff --git a/lldb/source/Commands/CMakeLists.txt b/lldb/source/Commands/CMakeLists.txt
index f2e62243e999e..69e4c45f0b8e5 100644
--- a/lldb/source/Commands/CMakeLists.txt
+++ b/lldb/source/Commands/CMakeLists.txt
@@ -58,9 +58,6 @@ add_lldb_library(lldbCommands NO_PLUGIN_DEPENDENCIES
     lldbUtility
     lldbValueObject
     lldbVersion
-  CLANG_LIBS
-    clangFrontend
-    clangSerialization
   )
 
 add_dependencies(lldbCommands LLDBOptionsGen)
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index bce95fb872c9d..a3db3c1c8ddb7 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -61,17 +61,11 @@
 #include "lldb/lldb-forward.h"
 #include "lldb/lldb-private-enumerations.h"
 
-#include "clang/Driver/CreateInvocationFromArgs.h"
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Frontend/CompilerInvocation.h"
-#include "clang/Frontend/FrontendActions.h"
-#include "clang/Serialization/ObjectFilePCHContainerReader.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatAdapters.h"
 
-
 using namespace lldb;
 using namespace lldb_private;
 
@@ -2181,59 +2175,6 @@ class CommandObjectTargetModulesDumpSections
   }
 };
 
-class CommandObjectTargetModulesDumpClangPCMInfo : public CommandObjectParsed {
-public:
-  CommandObjectTargetModulesDumpClangPCMInfo(CommandInterpreter &interpreter)
-      : CommandObjectParsed(
-            interpreter, "target modules dump pcm-info",
-            "Dump information about the given clang module (pcm).") {
-    // Take a single file argument.
-    AddSimpleArgumentList(eArgTypeFilename);
-  }
-
-  ~CommandObjectTargetModulesDumpClangPCMInfo() override = default;
-
-protected:
-  void DoExecute(Args &command, CommandReturnObject &result) override {
-    if (command.GetArgumentCount() != 1) {
-      result.AppendErrorWithFormat("'%s' takes exactly one pcm path argument",
-                                   m_cmd_name.c_str());
-      return;
-    }
-
-    const char *pcm_path = command.GetArgumentAtIndex(0);
-    const FileSpec pcm_file{pcm_path};
-
-    if (pcm_file.GetFileNameExtension() != ".pcm") {
-      result.AppendError("file must have a .pcm extension");
-      return;
-    }
-
-    if (!FileSystem::Instance().Exists(pcm_file)) {
-      result.AppendError("pcm file does not exist");
-      return;
-    }
-
-    const char *clang_args[] = {"clang", pcm_path};
-    clang::CompilerInstance compiler(clang::createInvocation(clang_args));
-    compiler.setVirtualFileSystem(
-        FileSystem::Instance().GetVirtualFileSystem());
-    compiler.createDiagnostics();
-
-    // Pass empty deleter to not attempt to free memory that was allocated
-    // outside of the current scope, possibly statically.
-    std::shared_ptr<llvm::raw_ostream> Out(
-        &result.GetOutputStream().AsRawOstream(), [](llvm::raw_ostream *) {});
-    clang::DumpModuleInfoAction dump_module_info(Out);
-    // DumpModuleInfoAction requires ObjectFilePCHContainerReader.
-    compiler.getPCHContainerOperations()->registerReader(
-        std::make_unique<clang::ObjectFilePCHContainerReader>());
-
-    if (compiler.ExecuteAction(dump_module_info))
-      result.SetStatus(eReturnStatusSuccessFinishResult);
-  }
-};
-
 #pragma mark CommandObjectTargetModulesDumpClangAST
 
 // Clang AST dumping command
@@ -2711,10 +2652,6 @@ class CommandObjectTargetModulesDump : public CommandObjectMultiword {
     LoadSubCommand("line-table",
                    CommandObjectSP(new CommandObjectTargetModulesDumpLineTable(
                        interpreter)));
-    LoadSubCommand(
-        "pcm-info",
-        CommandObjectSP(
-            new CommandObjectTargetModulesDumpClangPCMInfo(interpreter)));
     LoadSubCommand("separate-debug-info",
                    CommandObjectSP(
                        new CommandObjectTargetModulesDumpSeparateDebugInfoFiles(
diff --git a/lldb/source/Core/PluginManager.cpp b/lldb/source/Core/PluginManager.cpp
index 6efe865d21760..303f4701246c9 100644
--- a/lldb/source/Core/PluginManager.cpp
+++ b/lldb/source/Core/PluginManager.cpp
@@ -2001,9 +2001,10 @@ struct TypeSystemInstance : public PluginInstance<TypeSystemCreateInstance> {
   TypeSystemInstance(llvm::StringRef name, llvm::StringRef description,
                      CallbackType create_callback,
                      LanguageSet supported_languages_for_types,
-                     LanguageSet supported_languages_for_expressions)
-      : PluginInstance<TypeSystemCreateInstance>(name, description,
-                                                 create_callback),
+                     LanguageSet supported_languages_for_expressions,
+                     DebuggerInitializeCallback debugger_init_callback)
+      : PluginInstance<TypeSystemCreateInstance>(
+            name, description, create_callback, debugger_init_callback),
         supported_languages_for_types(supported_languages_for_types),
         supported_languages_for_expressions(
             supported_languages_for_expressions) {}
@@ -2023,10 +2024,11 @@ bool PluginManager::RegisterPlugin(
     llvm::StringRef name, llvm::StringRef description,
     TypeSystemCreateInstance create_callback,
     LanguageSet supported_languages_for_types,
-    LanguageSet supported_languages_for_expressions) {
+    LanguageSet supported_languages_for_expressions,
+    DebuggerInitializeCallback debugger_init_callback) {
   return GetTypeSystemInstances().RegisterPlugin(
       name, description, create_callback, supported_languages_for_types,
-      supported_languages_for_expressions);
+      supported_languages_for_expressions, debugger_init_callback);
 }
 
 bool PluginManager::UnregisterPlugin(TypeSystemCreateInstance create_callback) {
@@ -2245,6 +2247,7 @@ void PluginManager::DebuggerInitialize(Debugger &debugger) {
   GetStructuredDataPluginInstances().PerformDebuggerCallback(debugger);
   GetTracePluginInstances().PerformDebuggerCallback(debugger);
   GetScriptedInterfaceInstances().PerformDebuggerCallback(debugger);
+  GetTypeSystemInstances().PerformDebuggerCallback(debugger);
   GetLanguageInstances().PerformDebuggerCallback(debugger);
 }
 
diff --git a/lldb/source/Plugins/TypeSystem/Clang/CMakeLists.txt b/lldb/source/Plugins/TypeSystem/Clang/CMakeLists.txt
index a316761dea950..72b3ab7558585 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/CMakeLists.txt
+++ b/lldb/source/Plugins/TypeSystem/Clang/CMakeLists.txt
@@ -5,6 +5,7 @@ add_lldb_library(lldbPluginTypeSystemClang PLUGIN
     Support
   LINK_LIBS
     lldbCore
+    lldbInterpreter
     lldbSymbol
     lldbTarget
     lldbUtility
@@ -18,4 +19,5 @@ add_lldb_library(lldbPluginTypeSystemClang PLUGIN
     clangDriver
     clangFrontend
     clangSema
+    clangSerialization
 )
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 0761a39f7f7d5..784822385899c 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -42,11 +42,16 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "clang/Driver/Driver.h"
+#include "clang/Driver/CreateInvocationFromArgs.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "clang/Frontend/FrontendOptions.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
 #include "clang/Lex/ModuleMap.h"
 #include "clang/Sema/Sema.h"
+#include "clang/Serialization/ObjectFilePCHContainerReader.h"
 
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/Threading.h"
@@ -66,7 +71,11 @@
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Core/UniqueCStringMap.h"
 #include "lldb/Expression/Expression.h"
+#include "lldb/Host/FileSystem.h"
 #include "lldb/Host/StreamFile.h"
+#include "lldb/Interpreter/CommandInterpreter.h"
+#include "lldb/Interpreter/CommandObject.h"
+#include "lldb/Interpreter/CommandReturnObject.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Symbol/SymbolFile.h"
 #include "lldb/Target/ExecutionContext.h"
@@ -586,21 +595,91 @@ LanguageSet TypeSystemClang::GetSupportedLanguagesForExpressions() {
   return languages;
 }
 
+namespace {
+class CommandObjectTargetModulesDumpClangPCMInfo : public CommandObjectParsed {
+public:
+  CommandObjectTargetModulesDumpClangPCMInfo(CommandInterpreter &interpreter)
+      : CommandObjectParsed(
+            interpreter, "target modules dump pcm-info",
+            "Dump information about the given clang module (pcm).") {
+    // Take a single file argument.
+    AddSimpleArgumentList(eArgTypeFilename);
+  }
+
+  ~CommandObjectTargetModulesDumpClangPCMInfo() override = default;
+
+protected:
+  void DoExecute(Args &command, CommandReturnObject &result) override {
+    if (command.GetArgumentCount() != 1) {
+      result.AppendErrorWithFormat("'%s' takes exactly one pcm path argument",
+                                   m_cmd_name.c_str());
+      return;
+    }
+
+    const char *pcm_path = command.GetArgumentAtIndex(0);
+    const FileSpec pcm_file{pcm_path};
+
+    if (pcm_file.GetFileNameExtension() != ".pcm") {
+      result.AppendError("file must have a .pcm extension");
+      return;
+    }
+
+    if (!FileSystem::Instance().Exists(pcm_file)) {
+      result.AppendError("pcm file does not exist");
+      return;
+    }
+
+    const char *clang_args[] = {"clang", pcm_path};
+    clang::CompilerInstance compiler(clang::createInvocation(clang_args));
+    compiler.setVirtualFileSystem(
+        FileSystem::Instance().GetVirtualFileSystem());
+    compiler.createDiagnostics();
+
+    // Pass empty deleter to not attempt to free memory that was allocated
+    // outside of the current scope, possibly statically.
+    std::shared_ptr<llvm::raw_ostream> Out(
+        &result.GetOutputStream().AsRawOstream(), [](llvm::raw_ostream *) {});
+    clang::DumpModuleInfoAction dump_module_info(Out);
+    // DumpModuleInfoAction requires ObjectFilePCHContainerReader.
+    compiler.getPCHContainerOperations()->registerReader(
+        std::make_unique<clang::ObjectFilePCHContainerReader>());
+
+    if (compiler.ExecuteAction(dump_module_info))
+      result.SetStatus(eReturnStatusSuccessFinishResult);
+  }
+};
+} // namespace
+
 void TypeSystemClang::Initialize() {
   PluginManager::RegisterPlugin(
       GetPluginNameStatic(), "clang base AST context plug-in", CreateInstance,
+<<<<<<< HEAD
       GetSupportedLanguagesForTypes(), GetSupportedLanguagesForExpressions());
 
   llvm::SmallString<128> path;
   if (clang::driver::Driver::getDefaultModuleCachePath(path))
     ModuleList::GetGlobalModuleListProperties().SetClangModulesCachePath(
         FileSpec(path));
+=======
+      GetSupportedLanguagesForTypes(), GetSupportedLanguagesForExpressions(),
+      DebuggerInitialize);
+>>>>>>> 986dc7988816 ([lldb] Register 'target modules dump pcm-info' from TypeSystemClang)
 }
 
 void TypeSystemClang::Terminate() {
   PluginManager::UnregisterPlugin(CreateInstance);
 }
 
+void TypeSystemClang::DebuggerInitialize(Debugger &debugger) {
+  CommandInterpreter &interpreter = debugger.GetCommandInterpreter();
+  llvm::StringRef parent = "target modules dump";
+  if (CommandObject *dump = interpreter.GetCommandObjectForCommand(parent))
+    dump->LoadSubCommand(
+        "pcm-info",
+        std::make_shared<CommandObjectTargetModulesDumpClangPCMInfo>(
+            interpreter));
+}
+
 void TypeSystemClang::Finalize() {
   assert(m_ast_up);
   GetASTMap().Erase(m_ast_up.get());
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
index 28e79f2b0b11f..ef6d5a9c595b9 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
@@ -163,6 +163,8 @@ class TypeSystemClang : public TypeSystem {
 
   static void Terminate();
 
+  static void DebuggerInitialize(Debugger &debugger);
+
   static TypeSystemClang *GetASTContext(clang::ASTContext *ast_ctx);
 
   /// Returns the display name of this TypeSystemClang that indicates what



More information about the llvm-branch-commits mailing list