[Lldb-commits] [lldb] [LLDB][NativePDB] Resolve declaration for tag types (PR #152579)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Mon Aug 11 23:48:39 PDT 2025
================
@@ -2441,3 +2440,55 @@ SymbolFileNativePDB::GetContextForType(TypeIndex ti) {
}
return ctx;
}
+
+void SymbolFileNativePDB::CacheUdtDeclarations() {
+ if (m_has_cached_udt_declatations)
+ return;
+ m_has_cached_udt_declatations = true;
+
+ for (CVType cvt : m_index->ipi().typeArray()) {
+ if (cvt.kind() != LF_UDT_MOD_SRC_LINE)
+ continue;
+
+ UdtModSourceLineRecord udt_mod_src;
+ llvm::cantFail(TypeDeserializer::deserializeAs(cvt, udt_mod_src));
+ // Some types might be contributed by multiple modules. We assume that they
+ // all point to the same file and line because we can only provide one
+ // location.
+ m_udt_declarations.try_emplace(udt_mod_src.UDT,
+ udt_mod_src.SourceFile.getIndex(),
+ udt_mod_src.LineNumber);
+ }
+}
+
+Declaration SymbolFileNativePDB::ResolveUdtDeclaration(PdbTypeSymId type_id) {
+ CacheUdtDeclarations();
+ auto it = m_udt_declarations.find(type_id.index);
+ if (it == m_udt_declarations.end())
+ return Declaration();
+
+ auto [file_index, line] = it->second;
+ auto string_table = m_index->pdb().getStringTable();
+ if (!string_table) {
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), string_table.takeError(),
+ "Failed to get string table: {0}");
+ return Declaration();
+ }
+
+ llvm::Expected<llvm::StringRef> file_name =
+ string_table->getStringTable().getString(file_index);
+ if (!file_name) {
+ LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), file_name.takeError(),
+ "Failed to get string with id {1}: {0}", file_index);
+ return Declaration();
+ }
+
+ // rustc sets the filename to "<unknown>" for some files
+ if (*file_name == "\\<unknown>")
+ return Declaration();
----------------
Michael137 wrote:
Is there a way to test this?
https://github.com/llvm/llvm-project/pull/152579
More information about the lldb-commits
mailing list