36static bool IsMainFile(llvm::StringRef main, llvm::StringRef other) {
43 if (llvm::sys::fs::equivalent(main, other))
46 llvm::SmallString<64> normalized(other);
47 llvm::sys::path::native(normalized);
48 return main.equals_insensitive(normalized);
73 BuildInfoSym bis(SymbolRecordKind::BuildInfoSym);
74 if (
auto err = SymbolDeserializer::deserializeAs<BuildInfoSym>(sym, bis))
79 LazyRandomTypeCollection &types = index.
ipi().typeCollection();
80 std::optional<CVType> cvt = types.tryGetType(bis.BuildId);
82 if (!cvt || cvt->kind() != LF_BUILDINFO)
83 return llvm::Error::success();
86 if (
auto err = TypeDeserializer::deserializeAs<BuildInfoRecord>(*cvt, bir))
88 cci.
m_build_info.assign(bir.ArgIndices.begin(), bir.ArgIndices.end());
89 return llvm::Error::success();
131 for (
const auto &ss : item.
m_debug_stream.getSubsectionsArray()) {
132 if (ss.kind() != DebugSubsectionKind::InlineeLines)
135 DebugInlineeLinesSubsectionRef inlinee_lines;
136 llvm::BinaryStreamReader reader(ss.getRecordData());
137 if (llvm::Error
error = inlinee_lines.initialize(reader)) {
139 "Failed to initialize inlinee lines subsection: {0}");
143 for (
const InlineeSourceLine &Line : inlinee_lines) {
158 return *result.first->second;
162 const DbiModuleList &modules =
m_index.dbi().modules();
163 llvm::pdb::DbiModuleDescriptor descriptor = modules.getModuleDescriptor(modi);
164 uint16_t stream = descriptor.getModuleStreamIndex();
165 std::unique_ptr<llvm::msf::MappedBlockStream> stream_data =
166 m_index.pdb().createIndexedStream(stream);
169 std::unique_ptr<CompilandIndexItem>& cci = result.first->second;
172 llvm::pdb::ModuleDebugStreamRef debug_stream(descriptor,
nullptr);
173 cci = std::make_unique<CompilandIndexItem>(
PdbCompilandId{ modi }, debug_stream, std::move(descriptor));
177 llvm::pdb::ModuleDebugStreamRef debug_stream(descriptor,
178 std::move(stream_data));
180 if (llvm::Error err = debug_stream.reload()) {
182 "Failed to reload debug stream for module {1}: {0}", modi);
183 llvm::pdb::ModuleDebugStreamRef empty_stream(descriptor,
nullptr);
184 cci = std::make_unique<CompilandIndexItem>(
189 cci = std::make_unique<CompilandIndexItem>(
190 PdbCompilandId{modi}, std::move(debug_stream), std::move(descriptor));
194 auto strings =
m_index.pdb().getStringTable();
196 cci->m_strings.initialize(cci->m_debug_stream.getSubsectionsArray());
197 cci->m_strings.setStrings(strings->getStringTable());
200 "Failed to get PDB string table: {0}");
209 llvm::SmallString<64> main_file;
211 main_file = std::move(*main_file_or_err);
214 "Failed to determine main source file for module {1}: {0}",
217 llvm::sys::path::native(main_file);
219 uint32_t file_count = modules.getSourceFileCount(modi);
220 cci->m_file_list.reserve(file_count);
221 bool found_main_file =
false;
222 for (llvm::StringRef file : modules.source_files(modi)) {
223 if (!found_main_file &&
IsMainFile(main_file, file)) {
224 cci->m_file_list.insert(cci->m_file_list.begin(), file);
225 found_main_file =
true;
228 cci->m_file_list.push_back(file);
262 return llvm::SmallString<64>(
"");
264 LazyRandomTypeCollection &types =
m_index.ipi().typeCollection();
266 StringIdRecord working_dir;
267 StringIdRecord file_name;
271 TypeDeserializer::deserializeAs<StringIdRecord>(dir_cvt, working_dir))
272 return std::move(err);
274 TypeDeserializer::deserializeAs<StringIdRecord>(file_cvt, file_name))
275 return std::move(err);
277 llvm::sys::path::Style style = working_dir.String.starts_with(
"/")
278 ? llvm::sys::path::Style::posix
279 : llvm::sys::path::Style::windows;
280 if (llvm::sys::path::is_absolute(file_name.String, style))
281 return file_name.String;
283 llvm::SmallString<64> absolute_path = working_dir.String;
284 llvm::sys::path::append(absolute_path, file_name.String);
285 return absolute_path;