
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.
71 lines
1.5 KiB
Plaintext
71 lines
1.5 KiB
Plaintext
# Test `image dump ast` command.
|
|
|
|
# RUN: split-file %s %t
|
|
# RUN: %clang_host -g -gdwarf %t/main.cpp -o %t.out
|
|
# RUN: %lldb -x -b -s %t/commands.input %t.out -o exit 2>&1 \
|
|
# RUN: | FileCheck %s
|
|
|
|
#--- main.cpp
|
|
|
|
void A() {}
|
|
void A1() {}
|
|
void BA1() {}
|
|
void AB() {}
|
|
|
|
int main() {
|
|
A();
|
|
A1();
|
|
BA1();
|
|
AB();
|
|
}
|
|
|
|
#--- commands.input
|
|
|
|
break set -n main
|
|
run
|
|
expr A(); A1(); BA1(); AB()
|
|
|
|
image dump ast
|
|
|
|
# CHECK: image dump ast
|
|
# CHECK-DAG: FunctionDecl {{.*}} main
|
|
# CHECK-DAG: FunctionDecl {{.*}} A
|
|
# CHECK-DAG: FunctionDecl {{.*}} A1
|
|
# CHECK-DAG: FunctionDecl {{.*}} BA1
|
|
# CHECK-DAG: FunctionDecl {{.*}} AB
|
|
|
|
image dump ast --filter A
|
|
|
|
# CHECK: image dump ast --filter A
|
|
# CHECK: Dumping A
|
|
# CHECK-NOT: FunctionDecl {{.*}} main
|
|
# CHECK-DAG: FunctionDecl {{.*}} A1
|
|
# CHECK-DAG: FunctionDecl {{.*}} BA1
|
|
# CHECK-DAG: FunctionDecl {{.*}} AB
|
|
|
|
image dump ast --filter A1
|
|
|
|
# CHECK: image dump ast --filter A1
|
|
# CHECK: Dumping A
|
|
# CHECK-NOT: FunctionDecl {{.*}} main
|
|
# CHECK-NOT: FunctionDecl {{.*}} AB
|
|
# CHECK-DAG: FunctionDecl {{.*}} A1
|
|
# CHECK-DAG: FunctionDecl {{.*}} BA1
|
|
|
|
image dump ast --filter ""
|
|
|
|
# CHECK: image dump ast --filter ""
|
|
# CHECK-DAG: FunctionDecl {{.*}} main
|
|
# CHECK-DAG: FunctionDecl {{.*}} AB
|
|
# CHECK-DAG: FunctionDecl {{.*}} A1
|
|
# CHECK-DAG: FunctionDecl {{.*}} BA1
|
|
|
|
image dump ast -f AB
|
|
|
|
# CHECK: image dump ast -f AB
|
|
# CHECK: Dumping AB
|
|
# CHECK-NOT: FunctionDecl {{.*}} main
|
|
# CHECK-NOT: FunctionDecl {{.*}} A1
|
|
# CHECK-NOT: FunctionDecl {{.*}} BA1
|
|
# CHECK: FunctionDecl {{.*}} AB
|