[lldb] Add a test for how we lazily create Clang AST nodes

Authored by teemperor on Dec 9 2019, 12:54 AM.


[lldb] Add a test for how we lazily create Clang AST nodes

One of the ways we try to make LLDB faster is by only creating the Clang declarations (and loading the associated types)
when we actually need them for something. For example an evaluated expression might need to load types to
type check and codegen the expression.

Currently this mechanism isn't really tested, so we currently have no way to know how many Clang nodes we load and
when we load them. In general there seems to be some confusion when and why certain Clang nodes are created.
As we are about to make some changes to the code which is creating Clang AST nodes we probably should have
a test that at least checks that the current behaviour doesn't change. It also serves as some kind of documentation
on the current behaviour.

The test in this patch is just evaluating some expressions and checks which Clang nodes are created due to this in the
module AST. The check happens by looking at the AST dump of the current module and then scanning it for the
declarations we are looking for.

I'm aware that there are things missing in this test (inheritance, template parameters, non-expression evaluation commands)
but I'll expand it in follow up patches.

Also this test found two potential bugs in LLDB which are documented near the respective asserts in the test:

  1. LLDB seems to always load all types of local variables even when we don't reference them in the expression. We had patches

that tried to prevent this but it seems that didn't work as well as it should have (even though we don't complete these

  1. We always seem to complete the first field of any record we run into. This has the funny side effect that LLDB is faster when

all classes in a project have an arbitrary char unused; as their first member. We probably want to fix this.

Reviewers: shafik

Subscribers: abidh, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D71056