[lldb][SymbolFileDWARF] Support by-name lookup of global variables in inline namespaces
authorMichael Buch <michaelbuch12@gmail.com>
Wed, 1 Feb 2023 13:42:24 +0000 (13:42 +0000)
committerMichael Buch <michaelbuch12@gmail.com>
Thu, 2 Feb 2023 11:35:29 +0000 (11:35 +0000)
commitf8c9b30eb3e8cffc6c7adaa3003c774422643cf7
treeb2363babd603012a88b61cacc62d8a101bc20aff
parent3c66729887d6113068025776994b4c49bd8e45e2
[lldb][SymbolFileDWARF] Support by-name lookup of global variables in inline namespaces

Currently evaluating an expression involving a global variable inside
an inline namespace will fail to lookup said variable. This is because
the `SymbolFileDWARF::FindGlobalVariables` discards from consideration
all DIEs whose decl_context doesn't exactly match that of the lookup.

This patch relaxes this restriction by checking whether C++ rules
would permit the lookup. This is permitted by the DWARFv5 spec in
chapter `3.2.2 Namespace Entries`:
```
A namespace may have a DW_AT_export_symbols attribute which is a flag
which indicates that all member names defined within the namespace may be
referenced as if they were defined within the containing namespace.
```

The motivation for this is evaluating `std::ranges` expressions, which
heavily rely on global variables inside inline namespaces. E.g.,
`std::views::all(...)` is just an invocation of the `operator()`
on `std::ranges::views::__cpo::all`.

**Testing**

* Added API tests

Differential Revision: https://reviews.llvm.org/D143068
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/test/API/commands/expression/inline-namespace/TestInlineNamespace.py
lldb/test/API/commands/expression/inline-namespace/main.cpp