11 #include "clang/AST/Attr.h"
12 #include "clang/AST/CharUnits.h"
13 #include "clang/AST/Decl.h"
14 #include "clang/AST/DeclCXX.h"
15 #include "clang/AST/Type.h"
35 #include "llvm/DebugInfo/CodeView/CVRecord.h"
36 #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
37 #include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
38 #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
39 #include "llvm/DebugInfo/CodeView/RecordName.h"
40 #include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
41 #include "llvm/DebugInfo/CodeView/SymbolRecordHelpers.h"
42 #include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
43 #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
44 #include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
45 #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
46 #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
47 #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
48 #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
49 #include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
50 #include "llvm/DebugInfo/PDB/Native/TpiStream.h"
51 #include "llvm/DebugInfo/PDB/PDB.h"
52 #include "llvm/DebugInfo/PDB/PDBTypes.h"
53 #include "llvm/Demangle/MicrosoftDemangle.h"
54 #include "llvm/Object/COFF.h"
55 #include "llvm/Support/Allocator.h"
56 #include "llvm/Support/BinaryStreamReader.h"
57 #include "llvm/Support/Error.h"
58 #include "llvm/Support/ErrorOr.h"
59 #include "llvm/Support/MemoryBuffer.h"
90 static std::unique_ptr<PDBFile>
93 using namespace llvm::object;
94 auto expected_binary = createBinary(exe_path);
97 if (!expected_binary) {
98 llvm::consumeError(expected_binary.takeError());
101 OwningBinary<Binary> binary = std::move(*expected_binary);
105 auto *obj = llvm::dyn_cast<llvm::object::COFFObjectFile>(binary.getBinary());
108 const llvm::codeview::DebugInfo *pdb_info =
nullptr;
111 llvm::StringRef pdb_file;
112 if (
llvm::Error e = obj->getDebugPDBInfo(pdb_info, pdb_file)) {
113 consumeError(std::move(e));
120 if (!FileSystem::Instance().Exists(pdb_file)) {
123 pdb_file = exe_dir.CopyByAppendingPathComponent(pdb_name).GetCString();
127 auto pdb = ObjectFilePDB::loadPDBFile(
std::string(pdb_file), allocator);
131 auto expected_info = pdb->getPDBInfoStream();
132 if (!expected_info) {
133 llvm::consumeError(expected_info.takeError());
136 llvm::codeview::GUID guid;
137 memcpy(&guid, pdb_info->PDB70.Signature, 16);
139 if (expected_info->getGuid() != guid)
158 case SimpleTypeKind::Boolean128:
159 case SimpleTypeKind::Boolean16:
160 case SimpleTypeKind::Boolean32:
161 case SimpleTypeKind::Boolean64:
162 case SimpleTypeKind::Boolean8:
164 case SimpleTypeKind::Byte:
165 case SimpleTypeKind::UnsignedCharacter:
166 return "unsigned char";
167 case SimpleTypeKind::NarrowCharacter:
169 case SimpleTypeKind::SignedCharacter:
170 case SimpleTypeKind::SByte:
171 return "signed char";
172 case SimpleTypeKind::Character16:
174 case SimpleTypeKind::Character32:
176 case SimpleTypeKind::Character8:
178 case SimpleTypeKind::Complex80:
179 case SimpleTypeKind::Complex64:
180 case SimpleTypeKind::Complex32:
182 case SimpleTypeKind::Float128:
183 case SimpleTypeKind::Float80:
184 return "long double";
185 case SimpleTypeKind::Float64:
187 case SimpleTypeKind::Float32:
189 case SimpleTypeKind::Float16:
191 case SimpleTypeKind::Int128:
193 case SimpleTypeKind::Int64:
194 case SimpleTypeKind::Int64Quad:
196 case SimpleTypeKind::Int32:
198 case SimpleTypeKind::Int16:
200 case SimpleTypeKind::UInt128:
201 return "unsigned __int128";
202 case SimpleTypeKind::UInt64:
203 case SimpleTypeKind::UInt64Quad:
205 case SimpleTypeKind::HResult:
207 case SimpleTypeKind::UInt32:
209 case SimpleTypeKind::UInt16:
210 case SimpleTypeKind::UInt16Short:
211 return "unsigned short";
212 case SimpleTypeKind::Int32Long:
214 case SimpleTypeKind::UInt32Long:
215 return "unsigned long";
216 case SimpleTypeKind::Void:
218 case SimpleTypeKind::WideCharacter:
236 void SymbolFileNativePDB::Initialize() {
237 PluginManager::RegisterPlugin(GetPluginNameStatic(),
238 GetPluginDescriptionStatic(), CreateInstance,
242 void SymbolFileNativePDB::Terminate() {
243 PluginManager::UnregisterPlugin(CreateInstance);
246 void SymbolFileNativePDB::DebuggerInitialize(
Debugger &debugger) {}
248 llvm::StringRef SymbolFileNativePDB::GetPluginDescriptionStatic() {
249 return "Microsoft PDB debug symbol cross-platform file reader.";
252 SymbolFile *SymbolFileNativePDB::CreateInstance(ObjectFileSP objfile_sp) {
256 SymbolFileNativePDB::SymbolFileNativePDB(ObjectFileSP objfile_sp)
269 if (
auto *pdb = llvm::dyn_cast<ObjectFilePDB>(
m_objfile_sp.get())) {
270 pdb_file = &pdb->GetPDBFile();
281 if (!expected_index) {
282 llvm::consumeError(expected_index.takeError());
285 m_index = std::move(*expected_index);
294 if (
m_index->dbi().isStripped())
305 m_index->ParseSectionContribs();
307 auto ts_or_err =
m_objfile_sp->GetModule()->GetTypeSystemForLanguage(
309 if (
auto err = ts_or_err.takeError()) {
311 "Failed to initialize");
313 ts_or_err->SetSymbolFile(
this);
314 auto *
clang = llvm::cast_or_null<TypeSystemClang>(&ts_or_err.get());
321 const DbiModuleList &modules =
m_index->dbi().modules();
322 uint32_t count = modules.getModuleCount();
329 DbiModuleDescriptor last = modules.getModuleDescriptor(count - 1);
330 if (last.getModuleName() ==
"* Linker *")
340 BlockSP child_block = std::make_shared<Block>(opaque_block_uid);
342 switch (sym.kind()) {
348 Block &block = func->GetBlock(
false);
358 BlockSym block(
static_cast<SymbolRecordKind
>(sym.kind()));
359 cantFail(SymbolDeserializer::deserializeAs<BlockSym>(sym, block));
364 m_ast->GetOrCreateBlockDecl(block_id);
365 m_blocks.insert({opaque_block_uid, child_block});
370 comp_unit->GetLineTable();
372 std::shared_ptr<InlineSite> inline_site =
m_inline_sites[opaque_block_uid];
375 m_ast->GetOrCreateInlinedFunctionDecl(block_id);
377 for (
size_t i = 0; i < inline_site->ranges.GetSize(); ++i) {
378 auto *entry = inline_site->ranges.GetEntryAtIndex(i);
379 child_block->AddRange(
380 Block::Range(entry->GetRangeBase(), entry->GetByteSize()));
382 child_block->FinalizeRanges();
385 Declaration &decl = inline_site->inline_function_info->GetDeclaration();
386 Declaration &callsite = inline_site->inline_function_info->GetCallSite();
387 child_block->SetInlinedFunctionInfo(
388 inline_site->inline_function_info->GetName().GetCString(),
nullptr,
390 m_blocks.insert({opaque_block_uid, child_block});
394 lldbassert(
false &&
"Symbol is not a block!");
407 lldbassert(sym_record.kind() == S_LPROC32 || sym_record.kind() == S_GPROC32);
410 auto file_vm_addr =
m_index->MakeVirtualAddress(sol.
so);
415 comp_unit.
GetModule()->GetSectionList());
419 ProcSym proc(
static_cast<SymbolRecordKind
>(sym_record.kind()));
420 cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym_record, proc));
421 if (proc.FunctionType == TypeIndex::None())
428 Mangled mangled(proc.Name);
429 FunctionSP func_sp = std::make_shared<Function>(
431 func_type.get(), func_range);
435 m_ast->GetOrCreateFunctionDecl(func_id);
450 llvm::SmallString<64> source_file_name =
451 m_index->compilands().GetMainSourceFile(cci);
455 std::make_shared<CompileUnit>(
m_objfile_sp->GetModule(),
nullptr, fs,
463 const ModifierRecord &mr,
465 TpiStream &stream =
m_index->tpi();
468 if (mr.ModifiedType.isSimple())
471 name = computeTypeName(stream.typeCollection(), mr.ModifiedType);
476 modified_type->GetByteSize(
nullptr),
nullptr,
483 const llvm::codeview::PointerRecord &pr,
489 if (pr.isPointerToMember()) {
490 MemberPointerInfo mpi = pr.getMemberInfo();
504 if (ti == TypeIndex::NullptrT()) {
506 return std::make_shared<Type>(
511 if (ti.getSimpleMode() != SimpleTypeMode::Direct) {
514 switch (ti.getSimpleMode()) {
515 case SimpleTypeMode::FarPointer32:
516 case SimpleTypeMode::NearPointer32:
519 case SimpleTypeMode::NearPointer64:
527 return std::make_shared<Type>(
532 if (ti.getSimpleKind() == SimpleTypeKind::NotTranslated)
539 return std::make_shared<Type>(uid,
this,
ConstString(type_name), size,
545 if (!record.hasUniqueName()) {
547 llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs = parser.
GetSpecifiers();
552 llvm::ms_demangle::Demangler demangler;
553 StringView sv(record.UniqueName.begin(), record.UniqueName.size());
554 llvm::ms_demangle::TagTypeNode *ttn = demangler.parseTagUniqueName(sv);
558 llvm::ms_demangle::IdentifierNode *idn =
559 ttn->QualifiedName->getUnqualifiedIdentifier();
560 return idn->toString();
565 const TagRecord &record,
579 const ClassRecord &cr,
585 const UnionRecord &ur,
591 const EnumRecord &er,
598 return std::make_shared<lldb_private::Type>(
606 const ArrayRecord &ar,
611 TypeSP array_sp = std::make_shared<lldb_private::Type>(
615 array_sp->SetEncodingType(element_type.get());
621 const MemberFunctionRecord &mfr,
624 return std::make_shared<lldb_private::Type>(
631 const ProcedureRecord &pr,
634 return std::make_shared<lldb_private::Type>(
641 if (type_id.
index.isSimple())
645 CVType cvt = stream.getType(type_id.
index);
647 if (cvt.kind() == LF_MODIFIER) {
648 ModifierRecord modifier;
650 TypeDeserializer::deserializeAs<ModifierRecord>(cvt, modifier));
654 if (cvt.kind() == LF_POINTER) {
655 PointerRecord pointer;
657 TypeDeserializer::deserializeAs<PointerRecord>(cvt, pointer));
663 llvm::cantFail(TypeDeserializer::deserializeAs<ClassRecord>(cvt, cr));
667 if (cvt.kind() == LF_ENUM) {
669 llvm::cantFail(TypeDeserializer::deserializeAs<EnumRecord>(cvt, er));
673 if (cvt.kind() == LF_UNION) {
675 llvm::cantFail(TypeDeserializer::deserializeAs<UnionRecord>(cvt, ur));
679 if (cvt.kind() == LF_ARRAY) {
681 llvm::cantFail(TypeDeserializer::deserializeAs<ArrayRecord>(cvt, ar));
685 if (cvt.kind() == LF_PROCEDURE) {
687 llvm::cantFail(TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, pr));
690 if (cvt.kind() == LF_MFUNCTION) {
691 MemberFunctionRecord mfr;
692 llvm::cantFail(TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfr));
702 llvm::Optional<PdbTypeSymId> full_decl_uid;
704 auto expected_full_ti =
705 m_index->tpi().findFullDeclForForwardRef(type_id.
index);
706 if (!expected_full_ti)
707 llvm::consumeError(expected_full_ti.takeError());
708 else if (*expected_full_ti != type_id.
index) {
716 if (full_iter !=
m_types.end()) {
717 TypeSP result = full_iter->second;
726 PdbTypeSymId best_decl_id = full_decl_uid ? *full_decl_uid : type_id;
728 clang::QualType qt =
m_ast->GetOrCreateType(best_decl_id);
759 CVSymbol sym =
m_index->symrecords().readRecord(var_id.
offset);
760 if (sym.kind() == S_CONSTANT)
765 llvm::StringRef name;
769 bool is_external =
false;
770 switch (sym.kind()) {
775 DataSym ds(sym.kind());
776 llvm::cantFail(SymbolDeserializer::deserializeAs<DataSym>(sym, ds));
781 section = ds.Segment;
782 offset = ds.DataOffset;
783 addr =
m_index->MakeVirtualAddress(ds.Segment, ds.DataOffset);
790 ThreadLocalDataSym tlds(sym.kind());
792 SymbolDeserializer::deserializeAs<ThreadLocalDataSym>(sym, tlds));
795 section = tlds.Segment;
796 offset = tlds.DataOffset;
797 addr =
m_index->MakeVirtualAddress(tlds.Segment, tlds.DataOffset);
802 llvm_unreachable(
"unreachable!");
805 CompUnitSP comp_unit;
806 llvm::Optional<uint16_t> modi =
m_index->GetModuleIndexForVa(addr);
814 SymbolFileTypeSP type_sp =
815 std::make_shared<SymbolFileType>(*
this,
toOpaqueUid(tid));
818 m_ast->GetOrCreateVariableDecl(var_id);
825 bool artificial =
false;
826 bool location_is_constant_data =
false;
827 bool static_member =
false;
828 VariableSP var_sp = std::make_shared<Variable>(
829 toOpaqueUid(var_id), name.str().c_str(), global_name.c_str(), type_sp,
830 scope, comp_unit.get(), ranges, &decl, location, is_external, artificial,
831 location_is_constant_data, static_member);
838 const CVSymbol &cvs) {
839 TpiStream &tpi =
m_index->tpi();
840 ConstantSym constant(cvs.kind());
842 llvm::cantFail(SymbolDeserializer::deserializeAs<ConstantSym>(cvs, constant));
844 global_name += constant.Name;
846 SymbolFileTypeSP type_sp =
847 std::make_shared<SymbolFileType>(*
this,
toOpaqueUid(tid));
853 constant.Type, tpi, constant.Value, module);
855 bool external =
false;
856 bool artificial =
false;
857 bool location_is_constant_data =
true;
858 bool static_member =
false;
859 VariableSP var_sp = std::make_shared<Variable>(
860 toOpaqueUid(var_id), constant.Name.str().c_str(), global_name.c_str(),
862 external, artificial, location_is_constant_data, static_member);
869 if (emplace_result.second)
872 return emplace_result.first->second;
882 if (emplace_result.second)
883 emplace_result.first->second =
CreateFunction(func_id, comp_unit);
885 return emplace_result.first->second;
891 auto emplace_result =
893 if (emplace_result.second)
897 return emplace_result.first->second;
903 return *iter->second;
910 clang::DeclContext *context =
m_ast->FromCompilerDeclContext(decl_ctx);
913 m_ast->ParseDeclsForContext(*context);
920 if (index >= UINT16_MAX)
948 uint16_t modi = uid.asCompiland().modi;
953 for (
auto iter = syms.begin(); iter != syms.end(); ++iter) {
954 if (iter->kind() != S_LPROC32 && iter->kind() != S_GPROC32)
964 return new_count - count;
969 uint32_t flags = eSymbolContextCompUnit;
970 flags |= eSymbolContextVariable;
971 flags |= eSymbolContextFunction;
972 flags |= eSymbolContextBlock;
973 flags |= eSymbolContextLineEntry;
974 return (resolve_scope & flags) != 0;
984 llvm::Optional<uint16_t> modi =
m_index->GetModuleIndexForVa(file_addr);
992 resolved_flags |= eSymbolContextCompUnit;
995 if (resolve_scope & eSymbolContextFunction ||
996 resolve_scope & eSymbolContextBlock) {
998 std::vector<SymbolAndUid> matches =
m_index->FindSymbolsByVa(file_addr);
1002 for (
const auto &match : llvm::reverse(matches)) {
1007 CVSymbol cvs =
m_index->ReadSymbolRecord(csid);
1009 if (type != PDB_SymType::Function && type != PDB_SymType::Block)
1011 if (type == PDB_SymType::Function) {
1016 addr_t offset = file_addr - func_base;
1020 if (type == PDB_SymType::Block) {
1025 resolved_flags |= eSymbolContextFunction;
1027 resolved_flags |= eSymbolContextBlock;
1032 if (resolve_scope & eSymbolContextLineEntry) {
1035 if (line_table->FindLineEntryByAddress(addr, sc.
line_entry))
1036 resolved_flags |= eSymbolContextLineEntry;
1040 return resolved_flags;
1048 if (resolve_scope & eSymbolContextCompUnit) {
1057 if (file_spec_matches_cu_file_spec) {
1063 return sc_list.
GetSize() - prev_size;
1082 std::set<LineTable::Entry, LineTableEntryComparator> line_set;
1087 for (
const DebugSubsectionRecord &dssr :
1089 if (dssr.kind() != DebugSubsectionKind::Lines)
1092 DebugLinesSubsectionRef lines;
1093 llvm::BinaryStreamReader reader(dssr.getRecordData());
1094 if (
auto EC = lines.initialize(reader)) {
1095 llvm::consumeError(std::move(EC));
1099 const LineFragmentHeader *lfh = lines.header();
1100 uint64_t virtual_addr =
1101 m_index->MakeVirtualAddress(lfh->RelocSegment, lfh->RelocOffset);
1103 for (
const LineColumnEntry &group : lines) {
1104 llvm::Expected<uint32_t> file_index_or_err =
1106 if (!file_index_or_err)
1108 uint32_t file_index = file_index_or_err.get();
1112 for (
const LineNumberEntry &entry : group.LineNumbers) {
1113 LineInfo cur_info(entry.Flags);
1115 if (cur_info.isAlwaysStepInto() || cur_info.isNeverStepInto())
1118 uint64_t addr = virtual_addr + entry.Offset;
1120 bool is_statement = cur_info.isStatement();
1124 uint32_t lno = cur_info.getStartLine();
1127 is_prologue, is_epilogue,
false);
1129 auto iter = line_set.find(new_entry);
1130 if (iter != line_set.end() && iter->is_terminal_entry)
1131 line_set.erase(iter);
1132 line_set.insert(new_entry);
1139 line_entry.
data = {file_index, lno};
1141 LineInfo last_line(group.LineNumbers.back().Flags);
1142 line_set.emplace(virtual_addr + lfh->CodeSize, last_line.getEndLine(), 0,
1143 file_index,
false,
false,
false,
false,
true);
1146 line_entry.
SetRangeEnd(virtual_addr + lfh->CodeSize);
1155 const CVSymbolArray &syms = cii->
m_debug_stream.getSymbolArray();
1156 for (
auto iter = syms.begin(); iter != syms.end();) {
1157 if (iter->kind() != S_LPROC32 && iter->kind() != S_GPROC32) {
1162 uint32_t record_offset = iter.offset();
1163 CVSymbol func_record =
1168 comp_unit.
GetModule()->GetSectionList());
1174 if (kind != S_INLINESITE)
1179 for (
const auto &line_entry :
1184 if (!line_entry.is_terminal_entry)
1185 line_set.erase(line_entry);
1186 line_set.insert(line_entry);
1194 iter = syms.at(getScopeEndOffset(func_record));
1200 auto line_table = std::make_unique<LineTable>(&comp_unit);
1201 std::unique_ptr<LineSequence> sequence(
1202 line_table->CreateLineSequenceContainer());
1203 for (
const auto &line_entry : line_set) {
1204 line_table->AppendLineEntryToSequence(
1205 sequence.get(), line_entry.file_addr, line_entry.line,
1206 line_entry.column, line_entry.file_idx,
1207 line_entry.is_start_of_statement, line_entry.is_start_of_basic_block,
1208 line_entry.is_prologue_end, line_entry.is_epilogue_begin,
1209 line_entry.is_terminal_entry);
1211 line_table->InsertSequence(sequence.get());
1213 if (line_table->GetSize() == 0)
1225 llvm::Expected<uint32_t>
1228 const auto &checksums = cii.
m_strings.checksums().getArray();
1229 const auto &strings = cii.
m_strings.strings();
1233 auto iter = checksums.at(file_id);
1234 if (iter == checksums.end())
1235 return llvm::make_error<RawError>(raw_error_code::no_entry);
1237 llvm::Expected<llvm::StringRef> efn = strings.getString(iter->FileNameOffset);
1239 return efn.takeError();
1245 return std::distance(cii.
m_file_list.begin(), fn_iter);
1246 return llvm::make_error<RawError>(raw_error_code::no_entry);
1250 FileSpecList &support_files) {
1260 f.startswith(
"/") ? FileSpec::Style::posix : FileSpec::Style::windows;
1262 support_files.Append(spec);
1268 const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
1281 CVSymbol sym = cii->
m_debug_stream.readSymbolAtOffset(
id.offset);
1284 InlineSiteSym inline_site(
static_cast<SymbolRecordKind
>(sym.kind()));
1285 cantFail(SymbolDeserializer::deserializeAs<InlineSiteSym>(sym, inline_site));
1288 std::shared_ptr<InlineSite> inline_site_sp =
1289 std::make_shared<InlineSite>(parent_id);
1292 auto iter = cii->
m_inline_map.find(inline_site.Inlinee);
1295 InlineeSourceLine inlinee_line = iter->second;
1297 const FileSpecList &files = comp_unit->GetSupportFiles();
1299 llvm::Expected<uint32_t> file_index_or_err =
1301 if (!file_index_or_err)
1303 uint32_t file_offset = file_index_or_err.get();
1304 decl_file = files.GetFileSpecAtIndex(file_offset);
1305 uint32_t decl_line = inlinee_line.Header->SourceLineNum;
1306 std::unique_ptr<Declaration> decl_up =
1307 std::make_unique<Declaration>(decl_file, decl_line);
1311 int32_t line_offset = 0;
1312 llvm::Optional<uint32_t> code_offset_base;
1313 llvm::Optional<uint32_t> code_offset_end;
1314 llvm::Optional<int32_t> cur_line_offset;
1315 llvm::Optional<int32_t> next_line_offset;
1316 llvm::Optional<uint32_t> next_file_offset;
1318 bool is_terminal_entry =
false;
1319 bool is_start_of_statement =
true;
1321 bool is_prologue_end =
true;
1323 auto update_code_offset = [&](
uint32_t code_delta) {
1324 if (!code_offset_base)
1325 code_offset_base = code_offset;
1326 else if (!code_offset_end)
1327 code_offset_end = *code_offset_base + code_delta;
1329 auto update_line_offset = [&](int32_t line_delta) {
1330 line_offset += line_delta;
1331 if (!code_offset_base || !cur_line_offset)
1332 cur_line_offset = line_offset;
1334 next_line_offset = line_offset;
1337 auto update_file_offset = [&](
uint32_t offset) {
1338 if (!code_offset_base)
1339 file_offset = offset;
1341 next_file_offset = offset;
1344 for (
auto &annot : inline_site.annotations()) {
1345 switch (annot.OpCode) {
1346 case BinaryAnnotationsOpCode::CodeOffset:
1347 case BinaryAnnotationsOpCode::ChangeCodeOffset:
1348 case BinaryAnnotationsOpCode::ChangeCodeOffsetBase:
1349 code_offset += annot.U1;
1350 update_code_offset(annot.U1);
1352 case BinaryAnnotationsOpCode::ChangeLineOffset:
1353 update_line_offset(annot.S1);
1355 case BinaryAnnotationsOpCode::ChangeCodeLength:
1356 update_code_offset(annot.U1);
1357 code_offset += annot.U1;
1358 is_terminal_entry =
true;
1360 case BinaryAnnotationsOpCode::ChangeCodeOffsetAndLineOffset:
1361 code_offset += annot.U1;
1362 update_code_offset(annot.U1);
1363 update_line_offset(annot.S1);
1365 case BinaryAnnotationsOpCode::ChangeCodeLengthAndCodeOffset:
1366 code_offset += annot.U2;
1367 update_code_offset(annot.U2);
1368 update_code_offset(annot.U1);
1369 code_offset += annot.U1;
1370 is_terminal_entry =
true;
1372 case BinaryAnnotationsOpCode::ChangeFile:
1373 update_file_offset(annot.U1);
1380 if (code_offset_base && code_offset_end && cur_line_offset) {
1382 *code_offset_base, *code_offset_end - *code_offset_base,
1383 decl_line + *cur_line_offset));
1385 if (next_file_offset)
1386 file_offset = *next_file_offset;
1387 if (next_line_offset) {
1388 cur_line_offset = next_line_offset;
1389 next_line_offset = llvm::None;
1391 code_offset_base = is_terminal_entry ? llvm::None : code_offset_end;
1392 code_offset_end = next_file_offset = llvm::None;
1394 if (code_offset_base && cur_line_offset) {
1395 if (is_terminal_entry) {
1397 func_base + *code_offset_base, decl_line + *cur_line_offset, 0,
1398 file_offset,
false,
false,
false,
false,
true);
1399 inline_site_sp->line_entries.push_back(line_entry);
1402 decl_line + *cur_line_offset, 0,
1403 file_offset, is_start_of_statement,
false,
1404 is_prologue_end,
false,
false);
1405 inline_site_sp->line_entries.push_back(line_entry);
1406 is_prologue_end =
false;
1407 is_start_of_statement =
false;
1410 if (is_terminal_entry)
1411 is_start_of_statement =
true;
1412 is_terminal_entry =
false;
1415 inline_site_sp->ranges.Sort();
1418 std::unique_ptr<Declaration> callsite_up;
1419 if (!inline_site_sp->ranges.IsEmpty()) {
1420 auto *entry = inline_site_sp->ranges.GetEntryAtIndex(0);
1421 addr_t base_offset = entry->GetRangeBase();
1427 std::shared_ptr<InlineSite> parent_site =
1430 parent_site->inline_function_info->GetDeclaration().GetFile();
1431 if (
auto *parent_entry =
1432 parent_site->ranges.FindEntryThatContains(base_offset)) {
1434 std::make_unique<Declaration>(parent_decl_file, parent_entry->data);
1439 func_base + base_offset)) {
1441 files.GetFileSpecAtIndex(entry->data.first);
1443 std::make_unique<Declaration>(callsite_file, entry->data.second);
1449 CVType inlinee_cvt =
m_index->ipi().getType(inline_site.Inlinee);
1451 if (inlinee_cvt.kind() == LF_MFUNC_ID) {
1452 MemberFuncIdRecord mfr;
1454 TypeDeserializer::deserializeAs<MemberFuncIdRecord>(inlinee_cvt, mfr));
1455 LazyRandomTypeCollection &types =
m_index->tpi().typeCollection();
1456 inlinee_name.append(
std::string(types.getTypeName(mfr.ClassType)));
1457 inlinee_name.append(
"::");
1458 inlinee_name.append(mfr.getName().str());
1459 }
else if (inlinee_cvt.kind() == LF_FUNC_ID) {
1461 cantFail(TypeDeserializer::deserializeAs<FuncIdRecord>(inlinee_cvt, fir));
1462 TypeIndex parent_idx = fir.getParentScope();
1463 if (!parent_idx.isNoneType()) {
1464 LazyRandomTypeCollection &ids =
m_index->ipi().typeCollection();
1465 inlinee_name.append(
std::string(ids.getTypeName(parent_idx)));
1466 inlinee_name.append(
"::");
1468 inlinee_name.append(fir.getName().str());
1470 inline_site_sp->inline_function_info = std::make_shared<InlineFunctionInfo>(
1471 inlinee_name.c_str(), llvm::StringRef(), decl_up.get(),
1482 std::set<uint64_t> remove_uids;
1484 if (kind == S_GPROC32 || kind == S_LPROC32 || kind == S_BLOCK32 ||
1485 kind == S_INLINESITE) {
1487 if (kind == S_INLINESITE)
1494 for (uint64_t uid : remove_uids) {
1504 CVSymbolArray syms =
1508 for (
auto iter = syms.begin(); iter != syms.end(); ++iter) {
1510 if (fn(iter->kind(), child_id))
1523 using SymbolAndOffset = std::pair<uint32_t, llvm::codeview::CVSymbol>;
1525 std::vector<SymbolAndOffset> results =
m_index->globals().findRecordsByName(
1527 for (
const SymbolAndOffset &result : results) {
1529 switch (result.second.kind()) {
1530 case SymbolKind::S_GDATA32:
1531 case SymbolKind::S_LDATA32:
1532 case SymbolKind::S_GTHREAD32:
1533 case SymbolKind::S_LTHREAD32:
1534 case SymbolKind::S_CONSTANT: {
1548 FunctionNameType name_type_mask,
bool include_inlines,
1552 if (!(name_type_mask & eFunctionNameTypeFull ||
1553 name_type_mask & eFunctionNameTypeMethod))
1556 using SymbolAndOffset = std::pair<uint32_t, llvm::codeview::CVSymbol>;
1558 std::vector<SymbolAndOffset> matches =
m_index->globals().findRecordsByName(
1560 for (
const SymbolAndOffset &match : matches) {
1561 if (match.second.kind() != S_PROCREF && match.second.kind() != S_LPROCREF)
1563 ProcRefSym proc(match.second.kind());
1564 cantFail(SymbolDeserializer::deserializeAs<ProcRefSym>(match.second, proc));
1570 m_index->compilands().GetOrCreateCompiland(proc.modi());
1582 bool include_inlines,
1587 uint32_t max_matches, llvm::DenseSet<SymbolFile *> &searched_symbol_files,
1593 searched_symbol_files.clear();
1594 searched_symbol_files.insert(
this);
1601 llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages,
1602 llvm::DenseSet<SymbolFile *> &searched_symbol_files,
TypeMap &types) {}
1608 std::vector<TypeIndex> matches =
m_index->tpi().findRecordsByName(name);
1609 if (max_matches > 0 && max_matches < matches.size())
1610 matches.resize(max_matches);
1612 for (TypeIndex ti : matches) {
1628 LazyRandomTypeCollection &types =
m_index->tpi().typeCollection();
1631 for (
auto ti = types.getFirst(); ti; ti = types.getNext(*ti)) {
1634 (void)type->GetFullCompilerType();
1640 CVSymbol sym =
m_index->ReadSymbolRecord(global);
1641 if (sym.kind() != S_UDT)
1644 UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs<UDTSym>(sym));
1645 bool is_typedef =
true;
1647 CVType cvt =
m_index->tpi().getType(udt.Type);
1649 if (name == udt.Name)
1661 return new_count - old_count;
1687 SymbolFileTypeSP sftype =
1688 std::make_shared<SymbolFileType>(*
this, type_sp->GetID());
1693 bool external =
false;
1694 bool artificial =
false;
1695 bool location_is_constant_data =
false;
1696 bool static_member =
false;
1697 VariableSP var_sp = std::make_shared<Variable>(
1698 toOpaqueUid(var_id), name.c_str(), name.c_str(), sftype, var_scope,
1700 artificial, location_is_constant_data, static_member);
1703 m_ast->GetOrCreateVariableDecl(scope_id, var_id);
1713 return iter->second;
1719 CVSymbol sym =
m_index->ReadSymbolRecord(
id);
1722 UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs<UDTSym>(sym));
1726 (void)
m_ast->GetOrCreateTypedefDecl(
id);
1729 return std::make_shared<lldb_private::Type>(
1731 target_type->GetByteSize(
nullptr),
nullptr, target_type->GetID(),
1733 target_type->GetForwardCompilerType(),
1740 return iter->second;
1753 switch (sym.kind()) {
1756 ProcSym proc(
static_cast<SymbolRecordKind
>(sym.kind()));
1757 cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym, proc));
1758 CVType signature =
m_index->tpi().getType(proc.FunctionType);
1759 ProcedureRecord sig;
1760 cantFail(TypeDeserializer::deserializeAs<ProcedureRecord>(signature, sig));
1761 params_remaining = sig.getParameterCount();
1769 lldbassert(
false &&
"Symbol is not a block!");
1775 variables = std::make_shared<VariableList>();
1779 CVSymbolArray syms = limitSymbolArrayToScope(
1785 auto iter = syms.begin();
1786 auto end = syms.end();
1788 while (iter != end) {
1789 uint32_t record_offset = iter.offset();
1790 CVSymbol variable_cvs = *iter;
1796 if (variable_cvs.kind() == S_BLOCK32 ||
1797 variable_cvs.kind() == S_INLINESITE) {
1798 uint32_t block_end = getScopeEndOffset(variable_cvs);
1800 iter = syms.at(block_end);
1804 bool is_param = params_remaining > 0;
1805 VariableSP variable;
1806 switch (variable_cvs.kind()) {
1814 variables->AddVariableIfUnique(variable);
1832 VariableListSP variables;
1850 variables = std::make_shared<VariableList>();
1856 llvm_unreachable(
"Unreachable!");
1860 if (
auto decl =
m_ast->GetOrCreateDeclForUid(uid))
1861 return decl.getValue();
1868 clang::DeclContext *context =
1873 return m_ast->ToCompilerDeclContext(*context);
1878 clang::DeclContext *context =
m_ast->GetParentDeclContext(
PdbSymUid(uid));
1879 return m_ast->ToCompilerDeclContext(*context);
1884 auto iter =
m_types.find(type_uid);
1891 return &*iter->second;
1896 if (type_id.
index.isNoneType())
1903 llvm::Optional<SymbolFile::ArrayInfo>
1911 clang::QualType qt =
1914 return m_ast->CompleteType(qt);
1918 TypeClass type_mask,
1927 llvm::Expected<TypeSystem &>
1929 auto type_system_or_err =
1930 m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language);
1931 if (type_system_or_err) {
1932 type_system_or_err->SetSymbolFile(
this);
1934 return type_system_or_err;
1939 return m_index->pdb().getFileSize();