[Lldb-commits] [PATCH] D54072: Add a command to dump a module's clang ast.

Zachary Turner via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Sat Nov 3 10:19:46 PDT 2018


zturner created this revision.
zturner added reviewers: vsk, davide, labath, jingham, aleksandr.urakov, clayborg.
Herald added subscribers: JDevlieghere, aprantl.

This can be useful when diagnosing AST related problems.  For example, I had a bug where I was accidentally creating a record type multiple times instead of re-using the first one.  This is easy to see with a dump of the AST, because it will look like this:

  TranslationUnitDecl 0x18a2bc53b98 <<invalid sloc>> <invalid sloc>
  |-CXXRecordDecl 0x18a2bc54458 <<invalid sloc>> <invalid sloc> class ClassWithPadding
  |-CXXRecordDecl 0x18a2bc54520 <<invalid sloc>> <invalid sloc> class ClassWithPadding
  |-CXXRecordDecl 0x18a2bc545e0 <<invalid sloc>> <invalid sloc> class ClassWithPadding definition
  | |-DefinitionData pass_in_registers standard_layout trivially_copyable trivial literal
  | | |-DefaultConstructor exists trivial needs_implicit
  | | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
  | | |-MoveConstructor exists simple trivial needs_implicit
  | | |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param
  | | |-MoveAssignment exists simple trivial needs_implicit
  | | `-Destructor simple irrelevant trivial needs_implicit
  | |-MSInheritanceAttr 0x18a2bc546a0 <<invalid sloc>> Implicit __single_inheritance
  | |-FieldDecl 0x18a2bc54748 <<invalid sloc>> <invalid sloc> a 'char'
  | |-FieldDecl 0x18a2bc54798 <<invalid sloc>> <invalid sloc> b 'short'
  | |-FieldDecl 0x18a2bc54828 <<invalid sloc>> <invalid sloc> c 'char [2]'
  | |-FieldDecl 0x18a2bc54878 <<invalid sloc>> <invalid sloc> d 'int'
  | |-FieldDecl 0x18a2bc548c8 <<invalid sloc>> <invalid sloc> e 'char'
  | |-FieldDecl 0x18a2bc54918 <<invalid sloc>> <invalid sloc> f 'int'
  | |-FieldDecl 0x18a2bc54968 <<invalid sloc>> <invalid sloc> g 'long long'
  | |-FieldDecl 0x18a2bc549f8 <<invalid sloc>> <invalid sloc> h 'char [3]'
  | |-FieldDecl 0x18a2bc54a48 <<invalid sloc>> <invalid sloc> i 'long long'
  | |-FieldDecl 0x18a2bc54a98 <<invalid sloc>> <invalid sloc> j 'char [2]'
  | |-FieldDecl 0x18a2bc54ae8 <<invalid sloc>> <invalid sloc> k 'long long'
  | |-FieldDecl 0x18a2bc54b38 <<invalid sloc>> <invalid sloc> l 'char'
  | `-FieldDecl 0x18a2bd96f00 <<invalid sloc>> <invalid sloc> m 'long long'
  `-<undeserialized declarations>

Note there are 3 `CXXRecordDecl`s with the same name, but only one definition.  Given the complex interactions between debug info and AST reconstruction, a command like this makes problems within the AST very obvious.  I found several other AST-related problems, so this was not even the only one, so I think this is a largely unexplored front when it comes to areas for potentially improved test coverage.  And since it's in the REPL, it makes it very easy to test out commands in different orders, get a dump, do something else, get another dump, etc to see how the order of commands affects things.


https://reviews.llvm.org/D54072

Files:
  lldb/include/lldb/Symbol/SymbolFile.h
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h
  lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
  lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54072.172495.patch
Type: text/x-patch
Size: 9851 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20181103/628edcd3/attachment-0001.bin>


More information about the lldb-commits mailing list