[lldb-dev] ASTImporter usage
gclayton at apple.com
Thu Aug 16 10:56:57 PDT 2012
The ASTImporter is used to import types from one AST into another. When we debug in LLDB, we create one AST for each binary (executable, shared library, etc):
"a.out" has its own AST
"libc.so" has its own AST
And now you debug and stop somewhere and you want to run an expression:
(lldb) expr (int)printf("argv = '%s'\n", argv)
When we evaluate an expression, we create a new AST for the expression itself since it can define local variables and many other things (think of an expression that we can do with lldb like "int x=0; int y=12; x + y", this would not use any variables from the program, but it would define them in the expression AST only).
So then the following would happen:
- expression evaluation would find "argv" in the AST for "a.out", and import the definition into the expression AST.
- expression evaluation would find "printf" in the AST for "libc.so", and import the definition into the expression AST.
The importing also is done lazily and the expansion happens on demand, so if the "a.out" AST has a full definition for std::string, it doesn't need to import the full definition for "std::string" into the expresssion AST, it will start by importing a forward decl that can be completed on demand. This helps when you have an expression like:
(lldb) expr std::string *p = NULL
So the ASTImporter does smart importing from one AST to another and always downgrades classes with full definitions into completable forward decls in the destination AST.
Does this make sense?
On Aug 16, 2012, at 10:15 AM, habbey at cs.wisc.edu wrote:
> I'm a graduate student at the University of Wisconsin Madison and am
> beginning work on a static analyzer using clang. I've been looking at the
> ASTImporter class of clang and noticed that it doesn't seem to be complete
> and isn't used directly by any part of clang, but that LLDB does use it.
> I was wondering if anyone could help me understand what parts of the
> ASTImporter class LLDB uses and for what overall purpose. If anyone has
> even a little bit of insight on this topic it'd be much appreciated.
> Thank you
> --henry abbey
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
More information about the lldb-dev