SymbolFileDWARF::ParseDeclsForContext getting slow with multiple expr evals


I’ve noticed that expr causes LLDB to spend a substantial amount of time on SymbolFileDWARF::ParseDeclsForContext as more types get realized. So I put together a tiny project to try to better understand that behavior, and I was wondering if you guys could help me.

The project ( consists of a main function that calls three functions (f1, f2, f3) in an infinite loop. Each function is implemented in its own file and the function itself simply declares a local variable of a type declared inside the function file in an anonymous namespace.

I added a breakpoint to the loop in main (cd test && g++ -g -x c++ *.cpp && lldb a.out -o 'b main.cpp:7' -o 'r'), and tried to evaluate an undefined symbol (expr undefinedVariable) inside the loop, then inside each of the functions, and inside of the loop again (s and expr undefinedVariable four times). To my surprise, the symbols hidden inside the anonymous namespace of the function files would be carried around, regardless of the current scope (custom log trying to describe the calls to ClangASTContext::DeclContextFindDeclByName and SymbolFileDWARF::ParseDeclsForContext - So, I have a few questions about that.

  1. Why do we need to keep track of names out of scope?
  2. Despite the reason behind 1), aren’t we missing an opportunity of caching those compiler declaration contexts somehow so as to avoid iterating over the whole DIE vector inside ParseDeclsForContext every time? If I understood the code correctly, when you run multiple expression evaluations, the vast majority of the ast_parser->GetDeclForUIDFromDWARF(decl) calls ( will end up having no side effect as those DIEs will already be in the DWARFASTParserClang::m_die_to_decl map (

I’m sorry for the lengthy email.

Many thanks!
Guilherme (1.78 KB)