aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectTarget.cpp
diff options
context:
space:
mode:
authorMichael Buch <michaelbuch12@gmail.com>2025-06-02 10:55:04 +0100
committerGitHub <noreply@github.com>2025-06-02 10:55:04 +0100
commit0f7e10b0272bb297568075e73cf76abbf10db4f8 (patch)
tree836726bfe301e1bf876786180298268d5c952484 /lldb/source/Commands/CommandObjectTarget.cpp
parentb5cf03033251a642b184b2e0ea6bdac171c17702 (diff)
downloadllvm-0f7e10b0272bb297568075e73cf76abbf10db4f8.zip
llvm-0f7e10b0272bb297568075e73cf76abbf10db4f8.tar.gz
llvm-0f7e10b0272bb297568075e73cf76abbf10db4f8.tar.bz2
[lldb] Add filter option to AST dump command (#142164)
Depends on https://github.com/llvm/llvm-project/pull/142163 This patch makes the `-ast-dump-filter` Clang option available to the `target modules dump ast` command. This allows us to selectively dump parts of the AST by name. The AST can quickly grow way too large to skim on the console. This will aid in debugging AST related issues. Example: ``` (lldb) target modules dump ast --filter func Dumping clang ast for 48 modules. Dumping func: FunctionDecl 0xc4b785008 <<invalid sloc>> <invalid sloc> func 'void (int)' extern |-ParmVarDecl 0xc4b7853d8 <<invalid sloc>> <invalid sloc> x 'int' `-AsmLabelAttr 0xc4b785358 <<invalid sloc>> Implicit "_Z4funcIiEvT_" Dumping func<int>: FunctionDecl 0xc4b7850b8 <<invalid sloc>> <invalid sloc> func<int> 'void (int)' implicit_instantiation extern |-TemplateArgument type 'int' | `-BuiltinType 0xc4b85b110 'int' `-ParmVarDecl 0xc4b7853d8 <<invalid sloc>> <invalid sloc> x 'int' ``` The majority of this patch is adjust the `Dump` API. The main change in behaviour is in `TypeSystemClang::Dump`, where we now use the `ASTPrinter` for dumping the `TranslationUnitDecl`. This is where the `-ast-dump-filter` functionality lives in Clang.
Diffstat (limited to 'lldb/source/Commands/CommandObjectTarget.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectTarget.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index e2ba000..21b2195 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -2235,11 +2235,23 @@ public:
: CommandObjectTargetModulesModuleAutoComplete(
interpreter, "target modules dump ast",
"Dump the clang ast for a given module's symbol file.",
- //"target modules dump ast [<file1> ...]")
- nullptr, eCommandRequiresTarget) {}
+ "target modules dump ast [--filter <name>] [<file1> ...]",
+ eCommandRequiresTarget),
+ m_filter(LLDB_OPT_SET_1, false, "filter", 'f', 0, eArgTypeName,
+ "Dump only the decls whose names contain the specified filter "
+ "string.",
+ /*default_value=*/"") {
+ m_option_group.Append(&m_filter, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Finalize();
+ }
+
+ Options *GetOptions() override { return &m_option_group; }
~CommandObjectTargetModulesDumpClangAST() override = default;
+ OptionGroupOptions m_option_group;
+ OptionGroupString m_filter;
+
protected:
void DoExecute(Args &command, CommandReturnObject &result) override {
Target &target = GetTarget();
@@ -2251,6 +2263,8 @@ protected:
return;
}
+ llvm::StringRef filter = m_filter.GetOptionValue().GetCurrentValueAsRef();
+
if (command.GetArgumentCount() == 0) {
// Dump all ASTs for all modules images
result.GetOutputStream().Format("Dumping clang ast for {0} modules.\n",
@@ -2259,7 +2273,7 @@ protected:
if (INTERRUPT_REQUESTED(GetDebugger(), "Interrupted dumping clang ast"))
break;
if (SymbolFile *sf = module_sp->GetSymbolFile())
- sf->DumpClangAST(result.GetOutputStream());
+ sf->DumpClangAST(result.GetOutputStream(), filter);
}
result.SetStatus(eReturnStatusSuccessFinishResult);
return;
@@ -2288,7 +2302,7 @@ protected:
Module *m = module_list.GetModulePointerAtIndex(i);
if (SymbolFile *sf = m->GetSymbolFile())
- sf->DumpClangAST(result.GetOutputStream());
+ sf->DumpClangAST(result.GetOutputStream(), filter);
}
}
result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -5272,7 +5286,7 @@ protected:
// Go over every scratch TypeSystem and dump to the command output.
for (lldb::TypeSystemSP ts : GetTarget().GetScratchTypeSystems())
if (ts)
- ts->Dump(result.GetOutputStream().AsRawOstream());
+ ts->Dump(result.GetOutputStream().AsRawOstream(), "");
result.SetStatus(eReturnStatusSuccessFinishResult);
}