2 Commits

Author SHA1 Message Date
nerix
852cc9200f
[LLDB][NativePDB] Implement FindNamespace (#151950)
`FindNamespace` was not implemented for `SymbolFileNativePDB`. Without
it, it wasn't possible to lookup items through namespaces when
evaluating expressions.

This is mostly the same as in
[SymbolFilePDB](f1eb869bae/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp (L1664-L1696))
as well as
[PDBAstParser](f1eb869bae/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp (L1126-L1150)):
The AST parser/builder saves the created namespaces in a map to lookup
when a namespace is requested.

This is working towards making
[Shell/SymbolFile/PDB/expressions.test](f1eb869bae/lldb/test/Shell/SymbolFile/PDB/expressions.test)
pass with the native PDB plugin.
2025-08-05 11:10:27 +01:00
nerix
d95dadff8f
[LLDB][NativePDB] Allow type lookup in namespaces (#149876)
Previously, `type lookup` for types in namespaces didn't work with the
native PDB plugin, because `FindTypes` would only look for types whose
base name was equal to their full name. PDB/CodeView does not store the
base names in the TPI stream, but the types have their full name (e.g.
`std::thread` instead of `thread`). So `findRecordsByName` would only
return types in the top level namespace.

This PR changes the lookup to go through all types and check their base
name. As that could be a bit expensive, the names are first cached
(similar to the function lookup in the DIA PDB plugin). Potential types
are checked with `TypeQuery::ContextMatches`.

To be able to handle anonymous namespaces, I changed
`TypeQuery::ContextMatches`. The [`TypeQuery`
constructor](9ad7edef42/lldb/source/Symbol/Type.cpp (L76-L79))
inserts all name components as `CompilerContextKind::AnyDeclContext`. To
skip over anonymous namespaces, `ContextMatches` checked if a component
was empty and exactly of kind `Namespace`. For our query, the last check
was always false, so we never skipped anonymous namespaces. DWARF
doesn't have this problem, as it [constructs the context
outside](abe93d9d7e/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp (L154-L160))
and has proper information about namespaces. I'm not fully sure if my
change is correct and that it doesn't break other users of `TypeQuery`.

This enables `type lookup <type>` to work on types in namespaces.
However, expressions don't work with this yet, because `FindNamespace`
is unimplemented for native PDB.
2025-08-04 08:56:04 +01:00