31#include "clang/Basic/ABI.h"
32#include "llvm/ADT/DenseMap.h"
33#include "llvm/ADT/STLExtras.h"
34#include "llvm/ADT/SmallVector.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/Formatters.h"
39#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
40#include "llvm/DebugInfo/CodeView/RecordName.h"
41#include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
42#include "llvm/DebugInfo/CodeView/SymbolRecordHelpers.h"
43#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
44#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
45#include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
46#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
47#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
48#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
49#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
50#include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
51#include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
52#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
53#include "llvm/DebugInfo/PDB/PDB.h"
54#include "llvm/DebugInfo/PDB/PDBTypes.h"
55#include "llvm/Demangle/MicrosoftDemangle.h"
56#include "llvm/Object/COFF.h"
57#include "llvm/Support/Allocator.h"
58#include "llvm/Support/BinaryStreamReader.h"
59#include "llvm/Support/Error.h"
60#include "llvm/Support/ErrorExtras.h"
61#include "llvm/Support/ErrorOr.h"
62#include "llvm/Support/MemoryBuffer.h"
91 case PDB_Lang::ObjCpp:
98static std::optional<std::string>
100 llvm::StringRef exe_path) {
103 if (fs.
Exists(original_pdb_path))
104 return std::string(original_pdb_path);
109 const FileSpec original_pdb_spec(original_pdb_path,
111 .value_or(FileSpec::Style::native));
112 const llvm::StringRef pdb_filename = original_pdb_spec.
GetFilename();
123 for (
const FileSpec &search_dir : search_paths) {
132static std::unique_ptr<PDBFile>
135 using namespace llvm::object;
136 auto expected_binary = createBinary(exe_path);
139 if (!expected_binary) {
140 llvm::consumeError(expected_binary.takeError());
143 OwningBinary<Binary> binary = std::move(*expected_binary);
147 auto *obj = llvm::dyn_cast<llvm::object::COFFObjectFile>(binary.getBinary());
150 const llvm::codeview::DebugInfo *pdb_info =
nullptr;
153 llvm::StringRef pdb_file;
154 if (llvm::Error e = obj->getDebugPDBInfo(pdb_info, pdb_file)) {
155 consumeError(std::move(e));
159 std::optional<std::string> resolved_pdb_path =
161 if (!resolved_pdb_path)
170 auto expected_info =
pdb->getPDBInfoStream();
171 if (!expected_info) {
172 llvm::consumeError(expected_info.takeError());
175 llvm::codeview::GUID guid;
176 memcpy(&guid, pdb_info->PDB70.Signature, 16);
178 if (expected_info->getGuid() != guid)
191 case SimpleTypeKind::Boolean128:
193 case SimpleTypeKind::Boolean64:
195 case SimpleTypeKind::Boolean32:
197 case SimpleTypeKind::Boolean16:
199 case SimpleTypeKind::Boolean8:
202 case SimpleTypeKind::Byte:
203 case SimpleTypeKind::UnsignedCharacter:
204 return "unsigned char";
205 case SimpleTypeKind::NarrowCharacter:
207 case SimpleTypeKind::SignedCharacter:
208 case SimpleTypeKind::SByte:
209 return "signed char";
210 case SimpleTypeKind::Character32:
212 case SimpleTypeKind::Character16:
214 case SimpleTypeKind::Character8:
217 case SimpleTypeKind::Complex128:
218 return "_Complex __float128";
219 case SimpleTypeKind::Complex80:
220 return "_Complex long double";
221 case SimpleTypeKind::Complex64:
222 return "_Complex double";
223 case SimpleTypeKind::Complex48:
224 return "_Complex __float48";
225 case SimpleTypeKind::Complex32:
226 case SimpleTypeKind::Complex32PartialPrecision:
227 return "_Complex float";
228 case SimpleTypeKind::Complex16:
229 return "_Complex _Float16";
231 case SimpleTypeKind::Float128:
233 case SimpleTypeKind::Float80:
234 return "long double";
235 case SimpleTypeKind::Float64:
237 case SimpleTypeKind::Float48:
239 case SimpleTypeKind::Float32:
240 case SimpleTypeKind::Float32PartialPrecision:
242 case SimpleTypeKind::Float16:
245 case SimpleTypeKind::Int128Oct:
246 case SimpleTypeKind::Int128:
248 case SimpleTypeKind::Int64:
249 case SimpleTypeKind::Int64Quad:
251 case SimpleTypeKind::Int32Long:
253 case SimpleTypeKind::Int32:
255 case SimpleTypeKind::Int16:
256 case SimpleTypeKind::Int16Short:
259 case SimpleTypeKind::UInt128Oct:
260 case SimpleTypeKind::UInt128:
261 return "unsigned __int128";
262 case SimpleTypeKind::UInt64:
263 case SimpleTypeKind::UInt64Quad:
264 return "unsigned long long";
265 case SimpleTypeKind::UInt32:
267 case SimpleTypeKind::UInt16:
268 case SimpleTypeKind::UInt16Short:
269 return "unsigned short";
270 case SimpleTypeKind::UInt32Long:
271 return "unsigned long";
273 case SimpleTypeKind::HResult:
275 case SimpleTypeKind::Void:
277 case SimpleTypeKind::WideCharacter:
280 case SimpleTypeKind::None:
281 case SimpleTypeKind::NotTranslated:
298static std::optional<CVTagRecord>
317 if (Record.Type.isSimple())
320 CVType cvt = tpi.getType(Record.Type);
329 std::string qname = std::string(parent.
asTag().getUniqueName());
330 if (qname.size() < 4 || child.
asTag().getUniqueName().size() < 4)
336 qname[3] = child.
asTag().getUniqueName()[3];
340 piece += Record.Name;
341 piece.push_back(
'@');
342 qname.insert(4, std::move(piece));
343 if (qname != child.
asTag().UniqueName)
346 return std::move(child);
362 return "Microsoft PDB debug symbol cross-platform file reader.";
366 if (!llvm::isa_and_nonnull<ObjectFilePECOFF, ObjectFilePDB>(objfile_sp.get()))
380 uint32_t abilities = 0;
388 pdb_file = &
pdb->GetPDBFile();
400 pdb_file->getFilePath(),
401 m_objfile_sp->GetModule()->GetObjectFile()->GetFileSpec().GetPath());
404 if (!expected_index) {
405 llvm::consumeError(expected_index.takeError());
408 m_index = std::move(*expected_index);
417 if (
m_index->dbi().isStripped())
428 m_index->ParseSectionContribs();
430 auto ts_or_err =
m_objfile_sp->GetModule()->GetTypeSystemForLanguage(
432 if (
auto err = ts_or_err.takeError()) {
434 "Failed to initialize: {0}");
436 if (
auto ts = *ts_or_err)
437 ts->SetSymbolFile(
this);
442 const DbiModuleList &modules =
m_index->dbi().modules();
443 uint32_t count = modules.getModuleCount();
450 DbiModuleDescriptor last = modules.getModuleDescriptor(count - 1);
451 if (last.getModuleName() ==
"* Linker *")
462 if (
auto err = ts_or_err.takeError())
464 auto ts = *ts_or_err;
469 switch (sym.kind()) {
475 return &func->GetBlock(
false);
482 BlockSym block(
static_cast<SymbolRecordKind
>(sym.kind()));
483 if (
auto err = SymbolDeserializer::deserializeAs<BlockSym>(sym, block)) {
485 "Failed to deserialize BlockSym record: {0}");
488 if (block.Parent == 0) {
504 m_index->MakeVirtualAddress(block.Segment, block.CodeOffset);
507 if (block_base >= func_base)
508 child_block->AddRange(
Block::Range(block_base - func_base, block.CodeSize));
511 "S_BLOCK32 at modi: {0:d} offset: {1:d}: adding range "
512 "[{2:x16}-{3:x16}) which has a base that is less than the "
513 "function's low PC {4:x16}",
515 block_base + block.CodeSize, func_base);
519 m_blocks.insert({opaque_block_uid, child_block});
524 comp_unit->GetLineTable();
526 std::shared_ptr<InlineSite> inline_site =
m_inline_sites[opaque_block_uid];
534 for (
size_t i = 0; i < inline_site->ranges.GetSize(); ++i) {
535 auto *entry = inline_site->ranges.GetEntryAtIndex(i);
536 child_block->AddRange(
537 Block::Range(entry->GetRangeBase(), entry->GetByteSize()));
539 child_block->FinalizeRanges();
542 Declaration &decl = inline_site->inline_function_info->GetDeclaration();
543 Declaration &callsite = inline_site->inline_function_info->GetCallSite();
544 child_block->SetInlinedFunctionInfo(
545 inline_site->inline_function_info->GetName().GetCString(),
nullptr,
547 m_blocks.insert({opaque_block_uid, child_block});
568 if (sym_record.kind() != S_LPROC32 && sym_record.kind() != S_GPROC32) {
584 ProcSym proc(
static_cast<SymbolRecordKind
>(sym_record.kind()));
585 if (
auto err = SymbolDeserializer::deserializeAs<ProcSym>(sym_record, proc)) {
587 "Failed to deserialize ProcSym record: {0}");
593 if (!proc.FunctionType.isNoneType()) {
601 SegmentOffset(proc.Segment, proc.CodeOffset), proc.FunctionType);
602 Mangled mangled(mangled_opt.value_or(proc.Name));
604 FunctionSP func_sp = std::make_shared<Function>(
605 &comp_unit,
toOpaqueUid(func_id), func_type_uid, mangled, func_type.get(),
606 func_addr,
AddressRanges{AddressRange(func_addr, sol.length)});
613 if (
auto err = ts_or_err.takeError())
615 auto ts = *ts_or_err;
618 ast_builder->EnsureFunction(func_id);
634 llvm::SmallString<64> source_file_name;
635 if (
auto main_file_or_err =
m_index->compilands().GetMainSourceFile(cci)) {
636 source_file_name = std::move(*main_file_or_err);
639 "Failed to determine main source file: {0}");
641 FileSpec fs(llvm::sys::path::convert_to_slash(
642 source_file_name, llvm::sys::path::Style::windows_backslash));
644 CompUnitSP cu_sp = std::make_shared<CompileUnit>(
645 m_objfile_sp->GetModule(),
nullptr, std::make_shared<SupportFile>(fs),
653 const ModifierRecord &mr,
655 TpiStream &stream =
m_index->tpi();
659 if ((mr.Modifiers & ModifierOptions::Const) != ModifierOptions::None)
661 if ((mr.Modifiers & ModifierOptions::Volatile) != ModifierOptions::None)
663 if ((mr.Modifiers & ModifierOptions::Unaligned) != ModifierOptions::None)
664 name +=
"__unaligned ";
666 if (mr.ModifiedType.isSimple())
669 name += computeTypeName(stream.typeCollection(), mr.ModifiedType);
674 llvm::expectedToOptional(modified_type->GetByteSize(
nullptr)),
681 const llvm::codeview::PointerRecord &pr,
687 if (pr.isPointerToMember()) {
688 MemberPointerInfo mpi = pr.getMemberInfo();
701 if (ti == TypeIndex::NullptrT()) {
708 if (ti.getSimpleMode() != SimpleTypeMode::Direct) {
710 uint32_t pointer_size = 0;
711 switch (ti.getSimpleMode()) {
712 case SimpleTypeMode::FarPointer32:
713 case SimpleTypeMode::NearPointer32:
716 case SimpleTypeMode::NearPointer64:
728 if (ti.getSimpleKind() == SimpleTypeKind::NotTranslated)
740 if (!record.hasUniqueName())
743 llvm::ms_demangle::Demangler demangler;
744 std::string_view sv(record.UniqueName.begin(), record.UniqueName.size());
745 llvm::ms_demangle::TagTypeNode *ttn = demangler.parseTagUniqueName(sv);
749 llvm::ms_demangle::IdentifierNode *idn =
750 ttn->QualifiedName->getUnqualifiedIdentifier();
751 return idn->toString();
756 const TagRecord &record,
764 decl = std::move(*maybeDecl);
767 "Failed to resolve declaration for '{1}': {0}", uname);
775 const ClassRecord &cr,
781 const UnionRecord &ur,
787 const EnumRecord &er,
794 decl = std::move(*maybeDecl);
797 "Failed to resolve declaration for '{1}': {0}", uname);
803 llvm::expectedToOptional(underlying_type->GetByteSize(
nullptr)),
nullptr,
809 const ArrayRecord &ar,
818 array_sp->SetEncodingType(element_type.get());
823 const MemberFunctionRecord &mfr,
825 if (mfr.ReturnType.isSimple())
836 const ProcedureRecord &pr,
838 if (pr.ReturnType.isSimple())
849 llvm::codeview::TypeIndex arglist_ti) {
850 if (arglist_ti.isNoneType())
853 CVType arglist_cvt =
m_index->tpi().getType(arglist_ti);
854 if (arglist_cvt.kind() != LF_ARGLIST)
859 TypeDeserializer::deserializeAs<ArgListRecord>(arglist_cvt, alr)) {
861 "Failed to deserialize ArgListRecord record ({1}): {0}",
865 for (TypeIndex
id : alr.getIndices())
866 if (!
id.isNoneType() &&
id.isSimple())
871 if (type_id.
index.isSimple())
875 CVType cvt = stream.getType(type_id.
index);
877 if (cvt.kind() == LF_MODIFIER) {
878 ModifierRecord modifier;
880 TypeDeserializer::deserializeAs<ModifierRecord>(cvt, modifier)) {
882 "Failed to deserialize ModifierRecord record ({1}): {0}",
889 if (cvt.kind() == LF_POINTER) {
890 PointerRecord pointer;
892 TypeDeserializer::deserializeAs<PointerRecord>(cvt, pointer)) {
894 "Failed to deserialize PointerRecord record ({1}): {0}",
903 if (
auto err = TypeDeserializer::deserializeAs<ClassRecord>(cvt, cr)) {
905 "Failed to deserialize ClassRecord record ({1}): {0}",
912 if (cvt.kind() == LF_ENUM) {
914 if (
auto err = TypeDeserializer::deserializeAs<EnumRecord>(cvt, er)) {
916 "Failed to deserialize EnumRecord record ({1}): {0}",
923 if (cvt.kind() == LF_UNION) {
925 if (
auto err = TypeDeserializer::deserializeAs<UnionRecord>(cvt, ur)) {
927 "Failed to deserialize UnionRecord record ({1}): {0}",
934 if (cvt.kind() == LF_ARRAY) {
936 if (
auto err = TypeDeserializer::deserializeAs<ArrayRecord>(cvt, ar)) {
938 "Failed to deserialize ArrayRecord record ({1}): {0}",
945 if (cvt.kind() == LF_PROCEDURE) {
947 if (
auto err = TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, pr)) {
949 "Failed to deserialize ProcedureRecord record ({1}): {0}",
955 if (cvt.kind() == LF_MFUNCTION) {
956 MemberFunctionRecord mfr;
958 TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfr)) {
961 "Failed to deserialize MemberFunctionRecord record ({1}): {0}",
974 std::optional<PdbTypeSymId> full_decl_uid;
976 auto expected_full_ti =
977 m_index->tpi().findFullDeclForForwardRef(type_id.
index);
978 if (!expected_full_ti)
979 llvm::consumeError(expected_full_ti.takeError());
980 else if (*expected_full_ti != type_id.
index) {
988 if (full_iter !=
m_types.end()) {
989 TypeSP result = full_iter->second;
998 PdbTypeSymId best_decl_id = full_decl_uid ? *full_decl_uid : type_id;
1000 if (
auto err = ts_or_err.takeError())
1002 auto ts = *ts_or_err;
1032 return iter->second;
1041 CVSymbol sym =
m_index->symrecords().readRecord(var_id.
offset);
1042 if (sym.kind() == S_CONSTANT)
1048 llvm::StringRef name;
1051 bool is_external =
false;
1053 switch (sym.kind()) {
1058 DataSym ds(sym.kind());
1059 if (
auto err = SymbolDeserializer::deserializeAs<DataSym>(sym, ds)) {
1061 "Failed to deserialize DataSym record: {0}");
1069 addr =
m_index->MakeVirtualAddress(ds.Segment, ds.DataOffset);
1080 ThreadLocalDataSym tlds(sym.kind());
1082 SymbolDeserializer::deserializeAs<ThreadLocalDataSym>(sym, tlds)) {
1084 "Failed to deserialize ThreadLocalDataSym record: {0}");
1090 addr =
m_index->MakeVirtualAddress(tlds.Segment, tlds.DataOffset);
1099 llvm_unreachable(
"unreachable!");
1103 std::optional<uint16_t> modi =
m_index->GetModuleIndexForVa(addr);
1114 std::make_shared<SymbolFileType>(*
this,
toOpaqueUid(tid));
1117 if (
auto err = ts_or_err.takeError())
1119 auto ts = *ts_or_err;
1120 std::string var_name = name.str();
1122 if (
PdbAstBuilder *ast_builder = ts->GetNativePDBParser()) {
1123 ast_builder->EnsureVariable(var_id);
1124 var_name = ast_builder->GetQualifiedName(name);
1133 bool artificial =
false;
1134 bool location_is_constant_data =
false;
1135 bool static_member =
false;
1136 VariableSP var_sp = std::make_shared<Variable>(
1137 toOpaqueUid(var_id), var_name.c_str(), mangled_name.str().c_str(),
1138 type_sp, scope, comp_unit.get(), ranges, &decl, location, is_external,
1139 artificial, location_is_constant_data, static_member);
1146 const CVSymbol &cvs) {
1147 TpiStream &tpi =
m_index->tpi();
1148 ConstantSym constant(cvs.kind());
1150 if (cvs.kind() != S_CONSTANT)
1154 SymbolDeserializer::deserializeAs<ConstantSym>(cvs, constant)) {
1156 "Failed to deserialize ConstantSym record: {0}");
1161 std::make_shared<SymbolFileType>(*
this,
toOpaqueUid(tid));
1167 constant.Value, module);
1168 if (!location_or_err) {
1170 "Failed to make constant location expression for {1}: {0}",
1176 std::string var_name = constant.Name.str();
1178 if (
auto err = ts_or_err.takeError()) {
1180 "Failed to get type system for {1}: {0}", constant.Name);
1181 }
else if (
auto ts = *ts_or_err) {
1183 var_name = ast_builder->GetQualifiedName(constant.Name);
1186 bool external =
false;
1187 bool artificial =
false;
1188 bool location_is_constant_data =
true;
1189 bool static_member =
false;
1190 VariableSP var_sp = std::make_shared<Variable>(
1193 ranges, &decl, location, external, artificial, location_is_constant_data,
1201 if (emplace_result.second) {
1203 emplace_result.first->second = var_sp;
1208 return emplace_result.first->second;
1218 if (emplace_result.second)
1219 emplace_result.first->second =
CreateFunction(func_id, comp_unit);
1221 return emplace_result.first->second;
1227 auto emplace_result =
1229 if (emplace_result.second) {
1235 return emplace_result.first->second;
1241 return iter->second.get();
1260 assert(index < UINT16_MAX &&
"Invalid compile unit index");
1261 if (index >= UINT16_MAX)
1273 assert(
false &&
"uid of compile unit not a compiland");
1288 auto *section_list =
1289 m_objfile_sp->GetModule()->GetObjectFile()->GetSectionList();
1293 llvm::DenseMap<lldb::addr_t, llvm::SmallVector<uint32_t, 1>> symbols_by_addr;
1294 for (uint32_t i = 0, n = symtab.
GetNumSymbols(); i < n; ++i) {
1300 PublicSym32 last_sym;
1301 size_t last_sym_idx = 0;
1309 auto finish_last_symbol = [&](
const PublicSym32 *next) {
1316 if (next && last_sym.Segment == next->Segment) {
1317 if (next->Offset < last_sym.Offset) {
1319 "Ignoring size estimate for '{0}': segment {1} offset {2} is "
1320 "greater than the following offset {3}",
1321 last_sym.Name, last_sym.Segment, last_sym.Offset,
1325 last->
SetByteSize(next->Offset - last_sym.Offset);
1328 if (section_sp->GetByteSize() < last_sym.Offset) {
1330 "Ignoring size estimate for '{0}': segment {1} offset {2} is "
1331 "past the end of section '{3}' (size {4})",
1332 last_sym.Name, last_sym.Segment, last_sym.Offset,
1333 section_sp->GetName(), section_sp->GetByteSize());
1336 last->
SetByteSize(section_sp->GetByteSize() - last_sym.Offset);
1341 for (
auto pid :
m_index->publics().getAddressMap()) {
1343 CVSymbol sym =
m_index->ReadSymbolRecord(global);
1344 auto kind = sym.kind();
1345 if (kind != S_PUB32)
1347 auto pub_or_err = SymbolDeserializer::deserializeAs<PublicSym32>(sym);
1350 "Failed to deserialize PublicSym32 record: {0}");
1353 PublicSym32 pub = std::move(*pub_or_err);
1354 finish_last_symbol(&pub);
1356 if (!section_sp || last_sym.Segment != pub.Segment)
1357 section_sp = section_list->FindSectionByID(pub.Segment);
1363 if ((pub.Flags & PublicSymFlags::Function) != PublicSymFlags::None ||
1364 (pub.Flags & PublicSymFlags::Code) != PublicSymFlags::None)
1382 if (it != symbols_by_addr.end() &&
1383 llvm::any_of(it->second, [&](uint32_t idx) {
1384 Symbol *sym = symtab.SymbolAtIndex(idx);
1385 return sym && sym->GetMangled() == pub_symbol.GetMangled();
1389 last_sym_idx = symtab.
AddSymbol(pub_symbol);
1393 finish_last_symbol(
nullptr);
1403 assert(
false &&
"uid of compile unit not a compiland");
1411 for (
auto iter = syms.begin(); iter != syms.end(); ++iter) {
1412 if (iter->kind() != S_LPROC32 && iter->kind() != S_GPROC32)
1421 if (new_count < count) {
1422 assert(
false &&
"less functions after parsing than before");
1425 return new_count - count;
1430 uint32_t flags = eSymbolContextCompUnit;
1431 flags |= eSymbolContextVariable;
1432 flags |= eSymbolContextFunction;
1433 flags |= eSymbolContextBlock;
1434 flags |= eSymbolContextLineEntry;
1435 return (resolve_scope & flags) != 0;
1439 const Address &addr, SymbolContextItem resolve_scope, SymbolContext &sc) {
1441 uint32_t resolved_flags = 0;
1445 std::optional<uint16_t> modi =
m_index->GetModuleIndexForVa(file_addr);
1453 resolved_flags |= eSymbolContextCompUnit;
1456 if (resolve_scope & eSymbolContextFunction ||
1457 resolve_scope & eSymbolContextBlock) {
1460 "missing compile unit for symbol at address {0:x}", file_addr);
1463 std::vector<SymbolAndUid> matches =
m_index->FindSymbolsByVa(file_addr);
1467 for (
const auto &match : llvm::reverse(matches)) {
1471 PdbCompilandSymId csid = match.uid.asCompilandSym();
1472 CVSymbol cvs =
m_index->ReadSymbolRecord(csid);
1474 if (type != PDB_SymType::Function && type != PDB_SymType::Block)
1476 if (type == PDB_SymType::Function) {
1481 addr_t offset = file_addr - func_base;
1486 if (type == PDB_SymType::Block) {
1494 addr_t offset = file_addr - func_base;
1499 resolved_flags |= eSymbolContextFunction;
1501 resolved_flags |= eSymbolContextBlock;
1506 if (resolve_scope & eSymbolContextLineEntry) {
1509 "missing compile unit for symbol at address {0:x}", file_addr);
1513 if (line_table->FindLineEntryByAddress(addr, sc.
line_entry))
1514 resolved_flags |= eSymbolContextLineEntry;
1518 return resolved_flags;
1525 const uint32_t prev_size = sc_list.
GetSize();
1526 if (resolve_scope & eSymbolContextCompUnit) {
1535 if (file_spec_matches_cu_file_spec) {
1541 return sc_list.
GetSize() - prev_size;
1551 const ProcSym &proc) {
1553 auto it = line_set.upper_bound(
1555 if (it == line_set.begin())
1556 return line_set.end();
1558 if (it->is_terminal_entry || it->file_addr < func_addr)
1559 return line_set.end();
1563 if (proc.DbgStart != 0 && proc.DbgStart < proc.CodeSize) {
1565 auto it = entry_containing(addr);
1566 if (it != line_set.end()) {
1572 line_set.insert(entry);
1576 if (proc.DbgEnd > proc.DbgStart && proc.DbgEnd < proc.CodeSize) {
1578 auto it = entry_containing(addr);
1579 if (it != line_set.end() && it->file_addr == addr) {
1583 line_set.insert(entry);
1596 assert(
false &&
"uid of compile unit not a compiland");
1615 for (
const DebugSubsectionRecord &dssr :
1617 if (dssr.kind() != DebugSubsectionKind::Lines)
1620 DebugLinesSubsectionRef lines;
1621 llvm::BinaryStreamReader reader(dssr.getRecordData());
1622 if (
auto EC = lines.initialize(reader)) {
1623 llvm::consumeError(std::move(EC));
1627 const LineFragmentHeader *lfh = lines.header();
1628 uint64_t virtual_addr =
1629 m_index->MakeVirtualAddress(lfh->RelocSegment, lfh->RelocOffset);
1633 for (
const LineColumnEntry &group : lines) {
1634 llvm::Expected<uint32_t> file_index_or_err =
1636 if (!file_index_or_err) {
1638 "failed to get file index for line entry: {0}");
1641 uint32_t file_index = file_index_or_err.get();
1642 if (group.LineNumbers.empty()) {
1644 "no line numbers for {0} in modi={1}", group.NameIndex, modi);
1649 const bool has_columns = lines.hasColumnInfo() &&
1650 group.Columns.size() == group.LineNumbers.size();
1651 for (
const auto &[i, entry] : llvm::enumerate(group.LineNumbers)) {
1652 LineInfo cur_info(entry.Flags);
1653 uint16_t column = has_columns ? group.Columns[i].StartColumn : 0;
1655 if (cur_info.isAlwaysStepInto() || cur_info.isNeverStepInto())
1658 uint64_t addr = virtual_addr + entry.Offset;
1660 bool is_statement = cur_info.isStatement();
1661 uint32_t lno = cur_info.getStartLine();
1664 false,
false,
false,
false);
1666 auto iter = line_set.find(new_entry);
1667 if (iter != line_set.end() && iter->is_terminal_entry)
1668 line_set.erase(iter);
1669 line_set.insert(new_entry);
1676 line_entry.
data = {file_index, lno};
1678 LineInfo last_line(group.LineNumbers.back().Flags);
1679 line_set.emplace(virtual_addr + lfh->CodeSize, last_line.getEndLine(), 0,
1680 file_index,
false,
false,
false,
false,
true);
1683 line_entry.
SetRangeEnd(virtual_addr + lfh->CodeSize);
1692 const CVSymbolArray &syms = cii->
m_debug_stream.getSymbolArray();
1693 for (
auto iter = syms.begin(); iter != syms.end();) {
1694 if (iter->kind() != S_LPROC32 && iter->kind() != S_GPROC32) {
1699 uint32_t record_offset = iter.offset();
1700 CVSymbol func_record =
1702 ProcSym proc(
static_cast<SymbolRecordKind
>(func_record.kind()));
1703 if (llvm::Error
error =
1704 SymbolDeserializer::deserializeAs<ProcSym>(func_record, proc)) {
1705 llvm::consumeError(std::move(
error));
1706 iter = syms.at(getScopeEndOffset(func_record));
1710 m_index->MakeVirtualAddress(proc.Segment, proc.CodeOffset);
1712 iter = syms.at(getScopeEndOffset(func_record));
1721 if (kind != S_INLINESITE)
1726 for (
const auto &line_entry :
1731 if (!line_entry.is_terminal_entry)
1732 line_set.erase(line_entry);
1733 line_set.insert(line_entry);
1744 iter = syms.at(getScopeEndOffset(func_record));
1750 std::vector<LineTable::Sequence> sequence(1);
1751 for (
const auto &line_entry : line_set) {
1753 sequence.back(), line_entry.file_addr, line_entry.line,
1754 line_entry.column, line_entry.file_idx,
1755 line_entry.is_start_of_statement, line_entry.is_start_of_basic_block,
1756 line_entry.is_prologue_end, line_entry.is_epilogue_begin,
1757 line_entry.is_terminal_entry);
1760 std::make_unique<LineTable>(&comp_unit, std::move(sequence));
1762 if (line_table->GetSize() == 0)
1774llvm::Expected<uint32_t>
1778 return llvm::make_error<RawError>(raw_error_code::no_entry);
1780 const auto &checksums = cii.
m_strings.checksums().getArray();
1781 const auto &strings = cii.
m_strings.strings();
1785 auto iter = checksums.at(file_id);
1786 if (iter == checksums.end())
1787 return llvm::make_error<RawError>(raw_error_code::no_entry);
1789 llvm::Expected<llvm::StringRef> efn = strings.getString(iter->FileNameOffset);
1791 return efn.takeError();
1797 return std::distance(cii.
m_file_list.begin(), fn_iter);
1798 return llvm::make_error<RawError>(raw_error_code::no_entry);
1806 assert(
false &&
"uid of compile unit not a compiland");
1819 f.starts_with(
"/") ? FileSpec::Style::posix : FileSpec::Style::windows;
1821 support_files.
Append(spec);
1827 const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
1840 CVSymbol sym = cii->
m_debug_stream.readSymbolAtOffset(
id.offset);
1842 if (sym.kind() != S_INLINESITE)
1845 InlineSiteSym inline_site(
static_cast<SymbolRecordKind
>(sym.kind()));
1847 SymbolDeserializer::deserializeAs<InlineSiteSym>(sym, inline_site)) {
1849 "Failed to deserialize InlineSiteSym record: {0}");
1854 std::shared_ptr<InlineSite> inline_site_sp =
1855 std::make_shared<InlineSite>(parent_id);
1858 auto iter = cii->
m_inline_map.find(inline_site.Inlinee);
1861 InlineeSourceLine inlinee_line = iter->second;
1865 llvm::Expected<uint32_t> file_index_or_err =
1867 if (!file_index_or_err) {
1869 "failed to get file index for inline site: {0}");
1872 uint32_t file_offset = file_index_or_err.get();
1874 uint32_t decl_line = inlinee_line.Header->SourceLineNum;
1875 std::unique_ptr<Declaration> decl_up =
1876 std::make_unique<Declaration>(decl_file, decl_line);
1879 uint32_t code_offset = 0;
1880 int32_t line_offset = 0;
1881 std::optional<uint32_t> code_offset_base;
1882 std::optional<uint32_t> code_offset_end;
1883 std::optional<int32_t> cur_line_offset;
1884 std::optional<int32_t> next_line_offset;
1885 std::optional<uint32_t> next_file_offset;
1887 bool is_terminal_entry =
false;
1888 bool is_start_of_statement =
true;
1890 bool is_prologue_end =
true;
1892 auto update_code_offset = [&](uint32_t code_delta) {
1893 if (!code_offset_base)
1894 code_offset_base = code_offset;
1895 else if (!code_offset_end)
1896 code_offset_end = *code_offset_base + code_delta;
1898 auto update_line_offset = [&](int32_t line_delta) {
1899 line_offset += line_delta;
1900 if (!code_offset_base || !cur_line_offset)
1901 cur_line_offset = line_offset;
1903 next_line_offset = line_offset;
1906 auto update_file_offset = [&](uint32_t offset) {
1907 if (!code_offset_base)
1908 file_offset = offset;
1910 next_file_offset = offset;
1913 for (
auto &annot : inline_site.annotations()) {
1914 switch (annot.OpCode) {
1915 case BinaryAnnotationsOpCode::CodeOffset:
1916 case BinaryAnnotationsOpCode::ChangeCodeOffset:
1917 case BinaryAnnotationsOpCode::ChangeCodeOffsetBase:
1918 code_offset += annot.U1;
1919 update_code_offset(annot.U1);
1921 case BinaryAnnotationsOpCode::ChangeLineOffset:
1922 update_line_offset(annot.S1);
1924 case BinaryAnnotationsOpCode::ChangeCodeLength:
1925 update_code_offset(annot.U1);
1926 code_offset += annot.U1;
1927 is_terminal_entry =
true;
1929 case BinaryAnnotationsOpCode::ChangeCodeOffsetAndLineOffset:
1930 code_offset += annot.U1;
1931 update_code_offset(annot.U1);
1932 update_line_offset(annot.S1);
1934 case BinaryAnnotationsOpCode::ChangeCodeLengthAndCodeOffset:
1935 code_offset += annot.U2;
1936 update_code_offset(annot.U2);
1937 update_code_offset(annot.U1);
1938 code_offset += annot.U1;
1939 is_terminal_entry =
true;
1941 case BinaryAnnotationsOpCode::ChangeFile:
1942 update_file_offset(annot.U1);
1949 if (code_offset_base && code_offset_end && cur_line_offset) {
1951 *code_offset_base, *code_offset_end - *code_offset_base,
1952 decl_line + *cur_line_offset));
1954 if (next_file_offset)
1955 file_offset = *next_file_offset;
1956 if (next_line_offset) {
1957 cur_line_offset = next_line_offset;
1958 next_line_offset = std::nullopt;
1960 code_offset_base = is_terminal_entry ? std::nullopt : code_offset_end;
1961 code_offset_end = next_file_offset = std::nullopt;
1963 if (code_offset_base && cur_line_offset) {
1964 if (is_terminal_entry) {
1966 func_base + *code_offset_base, decl_line + *cur_line_offset, 0,
1967 file_offset,
false,
false,
false,
false,
true);
1968 inline_site_sp->line_entries.push_back(line_entry);
1971 decl_line + *cur_line_offset, 0,
1972 file_offset, is_start_of_statement,
false,
1973 is_prologue_end,
false,
false);
1974 inline_site_sp->line_entries.push_back(line_entry);
1975 is_prologue_end =
false;
1976 is_start_of_statement =
false;
1979 if (is_terminal_entry)
1980 is_start_of_statement =
true;
1981 is_terminal_entry =
false;
1984 inline_site_sp->ranges.Sort();
1987 std::unique_ptr<Declaration> callsite_up;
1988 if (!inline_site_sp->ranges.IsEmpty()) {
1989 auto *entry = inline_site_sp->ranges.GetEntryAtIndex(0);
1990 addr_t base_offset = entry->GetRangeBase();
1996 std::shared_ptr<InlineSite> parent_site =
1999 parent_site->inline_function_info->GetDeclaration().GetFile();
2000 if (
auto *parent_entry =
2001 parent_site->ranges.FindEntryThatContains(base_offset)) {
2003 std::make_unique<Declaration>(parent_decl_file, parent_entry->data);
2008 func_base + base_offset)) {
2012 std::make_unique<Declaration>(callsite_file, entry->data.second);
2018 std::string inlinee_name;
2019 llvm::Expected<CVType> inlinee_cvt =
2020 m_index->ipi().typeCollection().getTypeOrError(inline_site.Inlinee);
2022 inlinee_name =
"[error reading function name: " +
2023 llvm::toString(inlinee_cvt.takeError()) +
"]";
2024 }
else if (inlinee_cvt->kind() == LF_MFUNC_ID) {
2025 MemberFuncIdRecord mfr;
2026 if (
auto err = TypeDeserializer::deserializeAs<MemberFuncIdRecord>(
2027 *inlinee_cvt, mfr)) {
2029 "[error reading function name: " + llvm::toString(std::move(err)) +
2032 LazyRandomTypeCollection &types =
m_index->tpi().typeCollection();
2033 inlinee_name.append(std::string(types.getTypeName(mfr.ClassType)));
2034 inlinee_name.append(
"::");
2035 inlinee_name.append(mfr.getName().str());
2037 }
else if (inlinee_cvt->kind() == LF_FUNC_ID) {
2040 TypeDeserializer::deserializeAs<FuncIdRecord>(*inlinee_cvt, fir)) {
2042 "[error reading function name: " + llvm::toString(std::move(err)) +
2045 TypeIndex parent_idx = fir.getParentScope();
2046 if (!parent_idx.isNoneType()) {
2047 LazyRandomTypeCollection &ids =
m_index->ipi().typeCollection();
2048 inlinee_name.append(std::string(ids.getTypeName(parent_idx)));
2049 inlinee_name.append(
"::");
2051 inlinee_name.append(fir.getName().str());
2054 inline_site_sp->inline_function_info = std::make_shared<InlineFunctionInfo>(
2055 inlinee_name.c_str(), llvm::StringRef(), decl_up.get(),
2066 std::set<uint64_t> remove_uids;
2068 if (kind == S_GPROC32 || kind == S_LPROC32 || kind == S_BLOCK32 ||
2069 kind == S_INLINESITE) {
2071 if (kind == S_INLINESITE)
2078 for (uint64_t uid : remove_uids) {
2090 CVSymbolArray syms =
2094 for (
auto iter = syms.begin(); iter != syms.end(); ++iter) {
2096 if (fn(iter->kind(), child_id))
2108 "failed to get C++ type system: {0}");
2111 auto ts = *ts_or_err;
2118 ast_builder->
Dump(s, filter, show_color);
2126 std::map<std::pair<uint16_t, uint32_t>, uint32_t> func_addr_ids;
2129 for (
const uint32_t gid :
m_index->globals().getGlobalsTable()) {
2130 CVSymbol sym =
m_index->symrecords().readRecord(gid);
2131 auto kind = sym.kind();
2134 llvm::StringRef name;
2136 case SymbolKind::S_GDATA32:
2137 case SymbolKind::S_LDATA32: {
2138 auto data_or_err = SymbolDeserializer::deserializeAs<DataSym>(sym);
2141 "Failed to deserialize DataSym record: {0}");
2144 name = data_or_err->Name;
2147 case SymbolKind::S_GTHREAD32:
2148 case SymbolKind::S_LTHREAD32: {
2150 SymbolDeserializer::deserializeAs<ThreadLocalDataSym>(sym);
2153 "Failed to deserialize ThreadLocalDataSym record: {0}");
2156 name = data_or_err->Name;
2159 case SymbolKind::S_CONSTANT: {
2160 auto data_or_err = SymbolDeserializer::deserializeAs<ConstantSym>(sym);
2163 "Failed to deserialize ConstantSym record: {0}");
2166 name = data_or_err->Name;
2173 if (!name.empty()) {
2182 if (kind != S_PROCREF && kind != S_LPROCREF)
2188 auto ref_or_err = SymbolDeserializer::deserializeAs<ProcRefSym>(sym);
2191 "Failed to deserialize ProcRefSym record: {0}");
2194 ProcRefSym ref = std::move(*ref_or_err);
2195 if (ref.Name.empty())
2200 m_index->compilands().GetOrCreateCompiland(ref.modi());
2201 auto iter = cci.
m_debug_stream.getSymbolArray().at(ref.SymOffset);
2204 kind = iter->kind();
2205 if (kind != S_GPROC32 && kind != S_LPROC32)
2208 auto proc_or_err = SymbolDeserializer::deserializeAs<ProcSym>(*iter);
2211 "Failed to deserialize ProcSym record: {0}");
2214 ProcSym proc = std::move(*proc_or_err);
2215 if ((proc.Flags & ProcSymFlags::IsUnreachable) != ProcSymFlags::None)
2217 if (proc.Name.empty() || proc.FunctionType.isSimple())
2223 func_addr_ids.emplace(std::make_pair(proc.Segment, proc.CodeOffset), gid);
2226 if (basename.empty())
2227 basename = proc.Name;
2233 auto type =
m_index->tpi().getType(proc.FunctionType);
2234 if (type.kind() == LF_MFUNCTION) {
2235 MemberFunctionRecord mfr;
2236 if (
auto err = TypeDeserializer::deserializeAs<MemberFunctionRecord>(
2240 "Failed to deserialize MemberFunctionRecord record ({1}): {0}",
2242 }
else if (!mfr.getThisType().isNoneType())
2248 for (
auto pid :
m_index->publics().getPublicsTable()) {
2250 CVSymbol sym =
m_index->ReadSymbolRecord(global);
2251 auto kind = sym.kind();
2252 if (kind != S_PUB32)
2254 auto pub_or_err = SymbolDeserializer::deserializeAs<PublicSym32>(sym);
2257 "Failed to deserialize PublicSym32 record: {0}");
2260 PublicSym32 pub = std::move(*pub_or_err);
2267 auto it = func_addr_ids.find({pub.Segment, pub.Offset});
2268 if (it != func_addr_ids.end())
2292 bool is_rooted = lookup_name.consume_front(
"::");
2294 llvm::StringRef context;
2295 llvm::StringRef basename;
2298 basename = lookup_name;
2299 std::string scoped_suffix = (
"::" + lookup_name).str();
2301 std::vector<uint32_t> results;
2304 size_t n_matches = 0;
2305 for (uint32_t gid : results) {
2308 if (parent_decl_ctx.
IsValid() &&
2315 if (is_rooted || !context.empty()) {
2316 llvm::StringRef var_name = var->GetName().GetStringRef();
2317 if (var_name != lookup_name &&
2318 (is_rooted || !var_name.ends_with(scoped_suffix)))
2323 if (++n_matches >= max_matches)
2335 if (name_type_mask & eFunctionNameTypeFull)
2338 if (!(name_type_mask & eFunctionNameTypeFull ||
2339 name_type_mask & eFunctionNameTypeBase ||
2340 name_type_mask & eFunctionNameTypeMethod))
2344 std::set<uint32_t> resolved_ids;
2346 std::vector<uint32_t> ids;
2347 if (!Names.GetValues(name, ids))
2350 for (uint32_t
id : ids) {
2351 if (!resolved_ids.insert(
id).second)
2355 if (parent_decl_ctx.
IsValid() &&
2363 if (name_type_mask & eFunctionNameTypeFull)
2365 if (name_type_mask & eFunctionNameTypeBase)
2367 if (name_type_mask & eFunctionNameTypeMethod)
2372 bool include_inlines,
2379 std::vector<uint32_t> ids;
2383 std::set<uint32_t> resolved_ids;
2384 for (uint32_t
id : ids)
2385 if (resolved_ids.insert(
id).second)
2391 CVSymbol sym =
m_index->ReadSymbolRecord(global);
2392 auto kind = sym.kind();
2393 if (kind != S_PROCREF && kind != S_LPROCREF) {
2398 auto proc_or_err = SymbolDeserializer::deserializeAs<ProcRefSym>(sym);
2401 "Failed to deserialize ProcRefSym record: {0}");
2404 ProcRefSym proc = std::move(*proc_or_err);
2410 m_index->compilands().GetOrCreateCompiland(proc.modi());
2439 std::vector<uint32_t> matches;
2442 for (uint32_t match_idx : matches) {
2444 if (context.empty())
2453 if (results.
Done(query))
2459 std::vector<uint32_t> typedef_matches;
2461 for (uint32_t gid : typedef_matches) {
2471 if (results.
Done(query))
2476std::vector<CompilerContext>
2478 CVSymbol sym =
m_index->ReadSymbolRecord(
id);
2479 if (sym.kind() != S_UDT)
2481 auto udt_or_err = SymbolDeserializer::deserializeAs<UDTSym>(sym);
2483 llvm::consumeError(udt_or_err.takeError());
2487 std::optional<Type::ParsedName> parsed_name =
2494 std::vector<CompilerContext> ctx;
2495 for (llvm::StringRef scope : parsed_name->scope)
2503 uint32_t max_matches,
2506 std::vector<TypeIndex> matches =
m_index->tpi().findRecordsByName(name);
2507 if (max_matches > 0 && max_matches < matches.size())
2508 matches.resize(max_matches);
2510 for (TypeIndex ti : matches) {
2526 LazyRandomTypeCollection &types =
m_index->tpi().typeCollection();
2529 for (
auto ti = types.getFirst(); ti; ti = types.getNext(*ti)) {
2532 (void)type->GetFullCompilerType();
2536 for (
const uint32_t gid :
m_index->globals().getGlobalsTable()) {
2538 CVSymbol sym =
m_index->ReadSymbolRecord(global);
2539 if (sym.kind() != S_UDT)
2542 auto udt_or_err = SymbolDeserializer::deserializeAs<UDTSym>(sym);
2545 "Failed to deserialize UDTSym record: {0}");
2556 return new_count - old_count;
2562 for (
const uint32_t gid :
m_index->globals().getGlobalsTable()) {
2564 CVSymbol sym =
m_index->ReadSymbolRecord(global);
2569 switch (sym.kind()) {
2570 case SymbolKind::S_GDATA32:
2571 case SymbolKind::S_LDATA32:
2572 case SymbolKind::S_GTHREAD32:
2573 case SymbolKind::S_LTHREAD32: {
2575 if (var && var->GetSymbolContextScope() == &comp_unit)
2601 bool location_is_constant_data = is_constant;
2605 if (sym.kind() != S_CONSTANT)
2607 ConstantSym constant(sym.kind());
2609 SymbolDeserializer::deserializeAs<ConstantSym>(sym, constant)) {
2611 "Failed to deserialize ConstantSym record: {0}");
2615 var_info.
name = constant.Name;
2616 var_info.
type = constant.Type;
2618 constant.Type,
m_index->tpi(), constant.Value, module);
2619 if (!location_or_err) {
2621 "Failed to make constant location expression for {1}: {0}",
2629 Block *func_block = block;
2650 std::string name = var_info.
name.str();
2653 std::make_shared<SymbolFileType>(*
this, type_sp->GetID());
2658 bool external =
false;
2659 bool artificial =
false;
2660 bool static_member =
false;
2662 VariableSP var_sp = std::make_shared<Variable>(
2663 toOpaqueUid(var_id), name.c_str(), name.c_str(), sftype, var_scope, block,
2664 scope_ranges, &decl, var_info.
location, external, artificial,
2665 location_is_constant_data, static_member);
2668 if (
auto err = ts_or_err.takeError())
2670 auto ts = *ts_or_err;
2673 ast_builder->EnsureVariable(scope_id, var_id);
2683 bool is_param,
bool is_constant) {
2686 return iter->second;
2696 return iter->second;
2703 CVSymbol sym =
m_index->ReadSymbolRecord(var_id);
2705 llvm::StringRef name;
2708 switch (sym.kind()) {
2710 DataSym ds(sym.kind());
2711 if (
auto err = SymbolDeserializer::deserializeAs<DataSym>(sym, ds)) {
2713 "Failed to deserialize DataSym record: {0}");
2723 ThreadLocalDataSym tlds(sym.kind());
2725 SymbolDeserializer::deserializeAs<ThreadLocalDataSym>(sym, tlds)) {
2727 "Failed to deserialize ThreadLocalDataSym record: {0}");
2745 std::make_shared<SymbolFileType>(*
this, type_sp->GetID());
2749 VariableSP var_sp = std::make_shared<Variable>(
2750 toOpaqueUid(var_id), name.str().c_str(),
nullptr, sftype,
2759 if (
auto err = ts_or_err.takeError())
2760 llvm::consumeError(std::move(err));
2761 else if (
auto ts = *ts_or_err)
2763 ast_builder->EnsureVariable(scope_id, var_id);
2771 CVSymbol sym =
m_index->ReadSymbolRecord(
id);
2772 if (sym.kind() != S_UDT) {
2777 auto udt_or_err = SymbolDeserializer::deserializeAs<UDTSym>(sym);
2780 "Failed to deserialize UDTSym record: {0}");
2783 UDTSym udt = std::move(*udt_or_err);
2788 if (
auto err = ts_or_err.takeError())
2790 auto ts = *ts_or_err;
2798 ct = target_type->GetForwardCompilerType();
2802 llvm::expectedToOptional(target_type->GetByteSize(
nullptr)),
2803 nullptr, target_type->GetID(),
2811 return iter->second;
2823 CVType cvt =
m_index->tpi().getType(udt.Type);
2836 uint32_t params_remaining = 0;
2837 switch (sym.kind()) {
2840 ProcSym proc(
static_cast<SymbolRecordKind
>(sym.kind()));
2841 if (
auto err = SymbolDeserializer::deserializeAs<ProcSym>(sym, proc)) {
2843 "Failed to deserialize ProcSym record: {0}");
2846 if (proc.FunctionType.isNoneType())
2849 CVType signature =
m_index->tpi().getType(proc.FunctionType);
2850 if (signature.kind() == LF_PROCEDURE) {
2851 ProcedureRecord sig;
2852 if (llvm::Error e = TypeDeserializer::deserializeAs<ProcedureRecord>(
2854 llvm::consumeError(std::move(e));
2857 params_remaining = sig.getParameterCount();
2858 }
else if (signature.kind() == LF_MFUNCTION) {
2859 MemberFunctionRecord sig;
2860 if (llvm::Error e = TypeDeserializer::deserializeAs<MemberFunctionRecord>(
2862 llvm::consumeError(std::move(e));
2865 params_remaining = sig.getParameterCount();
2881 variables = std::make_shared<VariableList>();
2885 CVSymbolArray syms = limitSymbolArrayToScope(
2891 auto iter = syms.begin();
2892 auto end = syms.end();
2894 while (iter != end) {
2895 uint32_t record_offset = iter.offset();
2896 CVSymbol variable_cvs = *iter;
2902 if (variable_cvs.kind() == S_BLOCK32 ||
2903 variable_cvs.kind() == S_INLINESITE) {
2904 uint32_t block_end = getScopeEndOffset(variable_cvs);
2906 iter = syms.at(block_end);
2910 bool is_param = params_remaining > 0;
2912 switch (variable_cvs.kind()) {
2914 case S_REGREL32_INDIR:
2921 variables->AddVariableIfUnique(variable);
2928 variables->AddVariableIfUnique(variable);
2934 variables->AddVariableIfUnique(variable);
2968 variables = std::make_shared<VariableList>();
2975 "missing missing block, function, or module for symbol context");
2981 if (
auto err = ts_or_err.takeError())
2983 auto ts = *ts_or_err;
2995 if (
auto err = ts_or_err.takeError())
2997 auto ts = *ts_or_err;
3009 if (
auto err = ts_or_err.takeError())
3011 auto ts = *ts_or_err;
3025 auto iter =
m_types.find(type_uid);
3032 return &*iter->second;
3036 assert(
false &&
"uid is not a type index");
3040 if (type_id.
index.isNoneType())
3049std::optional<SymbolFile::ArrayInfo>
3052 return std::nullopt;
3068 TypeClass type_mask,
3077 if (
auto err = ts_or_err.takeError())
3079 auto ts = *ts_or_err;
3082 auto *
clang = llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
3096 std::string qualified_name;
3097 if (parent_decl_ctx.
IsValid())
3107llvm::Expected<lldb::TypeSystemSP>
3109 auto type_system_or_err =
3110 m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language);
3111 if (type_system_or_err)
3112 if (
auto ts = *type_system_or_err)
3113 ts->SetSymbolFile(
this);
3114 return type_system_or_err;
3119 return m_index->pdb().getFileSize();
3127 LazyRandomTypeCollection &types =
m_index->tpi().typeCollection();
3129 llvm::DenseMap<TypeIndex, TypeIndex> forward_to_full;
3130 llvm::DenseMap<TypeIndex, TypeIndex> full_to_forward;
3132 struct RecordIndices {
3137 llvm::StringMap<RecordIndices> record_indices;
3139 for (
auto ti = types.getFirst(); ti; ti = types.getNext(*ti)) {
3140 CVType type = types.getType(*ti);
3146 RecordIndices &indices = record_indices[tag.
asTag().getUniqueName()];
3147 if (tag.
asTag().isForwardRef()) {
3148 indices.forward = *ti;
3156 if (indices.full != TypeIndex::None() &&
3157 indices.forward != TypeIndex::None()) {
3158 forward_to_full[indices.forward] = indices.full;
3159 full_to_forward[indices.full] = indices.forward;
3165 if (tag.
asTag().isForwardRef() || !tag.
asTag().containsNestedClass())
3169 ProcessTpiStream(
PdbIndex &index, TypeIndex parent,
3171 llvm::DenseMap<TypeIndex, TypeIndex> &parents)
3172 : index(index), parents(parents), parent(parent),
3173 parent_cvt(parent_cvt) {}
3176 llvm::DenseMap<TypeIndex, TypeIndex> &parents;
3178 unsigned unnamed_type_index = 1;
3182 llvm::Error visitKnownMember(CVMemberRecord &CVR,
3183 NestedTypeRecord &Record)
override {
3184 std::string unnamed_type_name;
3185 if (Record.Name.empty()) {
3187 llvm::formatv(
"<unnamed-type-$S{0}>", unnamed_type_index).str();
3188 Record.Name = unnamed_type_name;
3189 ++unnamed_type_index;
3191 std::optional<CVTagRecord> tag =
3194 return llvm::ErrorSuccess();
3196 parents[Record.Type] = parent;
3197 return llvm::ErrorSuccess();
3201 CVType field_list_cvt =
m_index->tpi().getType(tag.
asTag().FieldList);
3202 if (field_list_cvt.kind() != LF_FIELDLIST)
3206 FieldListRecord field_list;
3207 if (llvm::Error
error = TypeDeserializer::deserializeAs<FieldListRecord>(
3208 field_list_cvt, field_list))
3209 llvm::consumeError(std::move(
error));
3210 if (llvm::Error
error = visitMemberRecordStream(field_list.Data, process))
3211 llvm::consumeError(std::move(
error));
3218 for (
const uint32_t gid :
m_index->globals().getGlobalsTable()) {
3219 CVSymbol sym =
m_index->symrecords().readRecord(gid);
3220 if (sym.kind() != S_UDT)
3222 auto udt_or_err = SymbolDeserializer::deserializeAs<UDTSym>(sym);
3224 llvm::consumeError(udt_or_err.takeError());
3230 llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs = parser.
GetSpecifiers();
3242 std::vector<TypeIndex> full_keys;
3243 std::vector<TypeIndex> fwd_keys;
3245 TypeIndex key = entry.first;
3246 TypeIndex value = entry.second;
3248 auto iter = forward_to_full.find(value);
3249 if (iter != forward_to_full.end())
3250 entry.second = iter->second;
3252 iter = forward_to_full.find(key);
3253 if (iter != forward_to_full.end())
3254 fwd_keys.push_back(key);
3256 full_keys.push_back(key);
3258 for (TypeIndex fwd : fwd_keys) {
3259 TypeIndex full = forward_to_full[fwd];
3263 for (TypeIndex full : full_keys) {
3264 TypeIndex fwd = full_to_forward[full];
3269std::optional<PdbCompilandSymId>
3271 CVSymbol sym =
m_index->ReadSymbolRecord(
id);
3272 if (symbolOpensScope(sym.kind())) {
3275 id.offset = getScopeParentOffset(sym);
3279 return std::nullopt;
3288 auto begin = syms.begin();
3289 auto end = syms.at(
id.offset);
3290 std::vector<PdbCompilandSymId> scope_stack;
3292 while (begin != end) {
3293 if (begin.offset() >
id.offset) {
3297 return std::nullopt;
3302 if (symbolOpensScope(begin->kind())) {
3305 uint32_t scope_end = getScopeEndOffset(*begin);
3306 if (scope_end <
id.offset) {
3307 begin = syms.at(scope_end);
3310 scope_stack.emplace_back(
id.modi, begin.offset());
3312 }
else if (symbolEndsScope(begin->kind())) {
3313 scope_stack.pop_back();
3317 if (scope_stack.empty())
3318 return std::nullopt;
3320 return scope_stack.back();
3323std::optional<llvm::codeview::TypeIndex>
3328 return std::nullopt;
3329 return parent_iter->second;
3332std::vector<CompilerContext>
3334 CVType type =
m_index->tpi().getType(ti);
3340 std::optional<Type::ParsedName> parsed_name =
3345 std::vector<CompilerContext> ctx;
3347 for (llvm::StringRef scope : parsed_name->scope) {
3354 for (
auto &el : llvm::reverse(llvm::drop_end(ctx))) {
3360 type =
m_index->tpi().getType(ti);
3361 switch (type.kind()) {
3381std::optional<llvm::StringRef>
3383 TypeIndex function_type) {
3384 auto symbol =
m_index->publics().findByAddress(
m_index->symrecords(),
3387 return std::nullopt;
3389 llvm::StringRef name = symbol->first.Name;
3392 if (!function_type.isNoneType() &&
3393 (symbol->first.Flags & PublicSymFlags::Function) != PublicSymFlags::None)
3410 if (!mangled.starts_with(
'_') ||
3411 m_index->dbi().getMachineType() != PDB_Machine::x86)
3415 PDB_CallingConv cc = PDB_CallingConv::NearC;
3416 if (cvt.kind() == LF_PROCEDURE) {
3417 ProcedureRecord proc;
3418 if (llvm::Error
error =
3419 TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, proc))
3420 llvm::consumeError(std::move(
error));
3422 }
else if (cvt.kind() == LF_MFUNCTION) {
3423 MemberFunctionRecord mfunc;
3424 if (llvm::Error
error =
3425 TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfunc))
3426 llvm::consumeError(std::move(
error));
3427 cc = mfunc.CallConv;
3434 if (cc == PDB_CallingConv::NearC || cc == PDB_CallingConv::FarC)
3435 return mangled.drop_front();
3442 llvm::StringRef lookup_name) {
3443 if (lookup_name.empty())
3463 CVSymbol sym_record = cci->
m_debug_stream.readSymbolAtOffset(
id.offset);
3464 if (sym_record.kind() != S_LPROC32 && sym_record.kind() != S_GPROC32)
3467 ProcSym proc(
static_cast<SymbolRecordKind
>(sym_record.kind()));
3468 if (
auto err = SymbolDeserializer::deserializeAs<ProcSym>(sym_record, proc)) {
3470 "Failed to deserialize ProcSym record: {0}");
3476 llvm::StringRef lookup_name =
3479 .value_or(proc.Name);
3485 llvm::StringRef qualified_name) {
3486 if (std::optional<PdbCompilandSymId> func_id =
3492std::optional<PdbCompilandSymId>
3494 TypeIndex method_type) {
3497 if (
m_index->globals().getGlobalsTable().HashRecords.empty())
3498 return std::nullopt;
3501 for (
const auto &[offset, sym] :
m_index->globals().findRecordsByName(
3502 qualified_name,
m_index->symrecords())) {
3503 if (sym.kind() != S_PROCREF && sym.kind() != S_LPROCREF)
3505 auto ref_or_err = SymbolDeserializer::deserializeAs<ProcRefSym>(sym);
3508 "Failed to deserialize ProcRefSym record: {0}");
3514 m_index->compilands().GetOrCreateCompiland(ref_or_err->modi());
3515 auto iter = cci.
m_debug_stream.getSymbolArray().at(ref_or_err->SymOffset);
3518 if (iter->kind() != S_GPROC32 && iter->kind() != S_LPROC32)
3520 auto proc_or_err = SymbolDeserializer::deserializeAs<ProcSym>(*iter);
3523 "Failed to deserialize ProcSym record: {0}");
3528 if (proc_or_err->FunctionType == method_type)
3531 return std::nullopt;
3534llvm::Expected<SymbolContext>
3541 !discriminator.empty()) {
3542 const bool is_ctor = discriminator.consume_front(
"C");
3544 bool is_defined =
false;
3545 if ((is_ctor || discriminator.consume_front(
"D")) &&
3546 llvm::to_integer(discriminator, kind))
3547 is_defined = is_ctor ? kind == clang::CXXCtorType::Ctor_Complete ||
3548 kind == clang::CXXCtorType::Ctor_Base
3549 : kind == clang::CXXDtorType::Dtor_Complete ||
3550 kind == clang::CXXDtorType::Dtor_Base;
3552 return llvm::createStringErrorV(
3553 "{0} refers to a structor variant without debug info", label);
3558 return llvm::createStringErrorV(
"invalid function ID in {0}", label);
3563 return llvm::createStringErrorV(
"invalid compiland in {0}", label);
3567 return llvm::createStringErrorV(
"failed to create compile unit for {0}",
3572 return llvm::createStringErrorV(
"failed to create function for {0}", label);
3575 func->CalculateSymbolContext(&sc);
3580 for (CVType cvt :
m_index->ipi().typeArray()) {
3581 switch (cvt.kind()) {
3582 case LF_UDT_SRC_LINE: {
3583 UdtSourceLineRecord udt_src;
3584 if (
auto err = TypeDeserializer::deserializeAs(cvt, udt_src)) {
3586 "Failed to deserialize UdtSourceLineRecord record: {0}");
3592 udt_src.LineNumber});
3594 case LF_UDT_MOD_SRC_LINE: {
3595 UdtModSourceLineRecord udt_mod_src;
3596 if (
auto err = TypeDeserializer::deserializeAs(cvt, udt_mod_src)) {
3599 "Failed to deserialize UdtModSourceLineRecord record: {0}");
3609 udt_mod_src.LineNumber});
3617llvm::Expected<Declaration>
3623 return llvm::createStringError(
"no UDT declaration found");
3625 llvm::StringRef file_name;
3626 if (it->second.IsIpiIndex) {
3627 CVType cvt =
m_index->ipi().getType(it->second.FileNameIndex);
3628 if (cvt.kind() != LF_STRING_ID)
3629 return llvm::createStringError(
"file name was not a LF_STRING_ID");
3632 if (
auto err = TypeDeserializer::deserializeAs(cvt, sid))
3633 return std::move(err);
3634 file_name = sid.String;
3637 auto string_table =
m_index->pdb().getStringTable();
3639 return string_table.takeError();
3641 llvm::Expected<llvm::StringRef>
string =
3642 string_table->getStringTable().getString(
3643 it->second.FileNameIndex.getIndex());
3645 return string.takeError();
3646 file_name = *string;
3650 if (file_name ==
"\\<unknown>")
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOG_ERROR(log, error,...)
static std::unique_ptr< PDBFile > loadMatchingPDBFile(std::string exe_path, llvm::BumpPtrAllocator &allocator)
static std::optional< CVTagRecord > GetNestedTagDefinition(const NestedTypeRecord &Record, const CVTagRecord &parent, TpiStream &tpi)
static lldb::LanguageType TranslateLanguage(PDB_Lang lang)
static std::string GetUnqualifiedTypeName(const TagRecord &record)
static llvm::StringRef GetSimpleTypeName(SimpleTypeKind kind)
static bool IsClassRecord(TypeLeafKind kind)
static bool NeedsResolvedCompileUnit(uint32_t resolve_scope)
static std::optional< std::string > findMatchingPDBFilePath(llvm::StringRef original_pdb_path, llvm::StringRef exe_path)
llvm::ArrayRef< MSVCUndecoratedNameSpecifier > GetSpecifiers() const
static llvm::StringRef DropScope(llvm::StringRef name)
static bool UseNativePDB()
A section + offset based address class.
lldb::addr_t GetFileAddress() const
Get the file address.
bool IsValid() const
Check if the object state is valid.
A class that describes a single lexical block.
lldb::VariableListSP GetBlockVariableList(bool can_create)
Get the variable list for this block only.
Block * FindInnermostBlockByOffset(const lldb::addr_t offset)
void SetBlockInfoHasBeenParsed(bool b, bool set_children)
lldb::BlockSP CreateChild(lldb::user_id_t uid)
Creates a block with the specified UID uid.
Function * CalculateSymbolContextFunction() override
void SetVariableList(lldb::VariableListSP &variable_list_sp)
Set accessor for the variable list.
Block * GetParent() const
Get the parent block.
bool GetStartAddress(Address &addr)
void SetDidParseVariables(bool b, bool set_children)
static bool ExtractContextAndIdentifier(llvm::StringRef name, llvm::StringRef &context, llvm::StringRef &identifier)
A class that describes a compilation unit.
void SetVariableList(lldb::VariableListSP &variable_list_sp)
Set accessor for the variable list.
lldb::VariableListSP GetVariableList(bool can_create)
Get the variable list for a compile unit.
const FileSpec & GetPrimaryFile() const
Return the primary source spec associated with this compile unit.
void ResolveSymbolContext(const SourceLocationSpec &src_location_spec, lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list, RealpathPrefixes *realpath_prefixes=nullptr)
Resolve symbol contexts by file and line.
void SetLineTable(LineTable *line_table)
Set the line table for the compile unit.
void AddFunction(lldb::FunctionSP &function_sp)
Add a function to this compile unit.
size_t GetNumFunctions() const
Returns the number of functions in this compile unit.
lldb::LanguageType GetLanguage()
LineTable * GetLineTable()
Get the line table for the compile unit.
Represents a generic declaration context in a program.
ConstString GetScopeQualifiedName() const
TypeSystem * GetTypeSystem() const
Represents a generic declaration such as a function declaration.
Generic representation of a type in a programming language.
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
A uniqued constant string class.
std::string GetString() const
Get the string value as a std::string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
bool IsValid() const
Return true if the location expression contains data.
void SetFuncFileAddress(lldb::addr_t func_file_addr)
"lldb/Expression/DWARFExpression.h" Encapsulates a DWARF location expression and interprets it.
A class to manage flag bits.
A class that describes the declaration location of a lldb object.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
FileSpec CopyByAppendingPathComponent(llvm::StringRef component) const
static std::optional< Style > GuessPathStyle(llvm::StringRef absolute_path)
Attempt to guess path style for a given path string.
static bool Match(const FileSpec &pattern, const FileSpec &file)
Match FileSpec pattern against FileSpec file.
llvm::StringRef GetFilename() const
Filename string const get accessor.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
FileSpec CopyByRemovingLastPathComponent() const
llvm::sys::path::Style Style
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
static FileSystem & Instance()
A class that describes a function.
const Address & GetAddress() const
Return the address of the function (its entry point).
Block & GetBlock(bool can_create)
Get accessor for the block list.
static void AppendLineEntryToSequence(Sequence &sequence, lldb::addr_t file_addr, uint32_t line, uint16_t column, uint16_t file_idx, bool is_start_of_statement, bool is_start_of_basic_block, bool is_prologue_end, bool is_epilogue_begin, bool is_terminal_entry)
A class that handles mangled names.
static bool IsMangledName(llvm::StringRef name)
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
A class that encapsulates name lookup information.
lldb::FunctionNameType GetNameTypeMask() const
ConstString GetLookupName() const
ConstString GetName() const
static std::unique_ptr< llvm::pdb::PDBFile > loadPDBFile(std::string PdbPath, llvm::BumpPtrAllocator &Allocator)
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
RangeData< lldb::addr_t, uint32_t, std::pair< uint32_t, uint32_t > > Entry
void Append(const Entry &entry)
Entry * FindEntryThatContains(B addr)
"lldb/Core/SourceLocationSpec.h" A source location specifier class.
FileSpec GetFileSpec() const
A stream class that can stream formatted output to a file.
A list of support files for a CompileUnit.
const FileSpec & GetFileSpecAtIndex(size_t idx) const
void Append(const FileSpec &file)
Defines a list of symbol context objects.
uint32_t GetSize() const
Get accessor for a symbol context list size.
void Append(const SymbolContext &sc)
Append a new symbol context to the list.
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
Block * block
The Block for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
LineEntry line_entry
The LineEntry for a given query.
lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) override
ObjectFile * GetObjectFile() override
virtual TypeList & GetTypeList()
lldb::ObjectFileSP m_objfile_sp
void SetCompileUnitAtIndex(uint32_t idx, const lldb::CompUnitSP &cu_sp)
SymbolFileCommon(lldb::ObjectFileSP objfile_sp)
uint32_t GetNumCompileUnits() override
lldb::TypeSP MakeType(lldb::user_id_t uid, ConstString name, std::optional< uint64_t > byte_size, SymbolContextScope *context, lldb::user_id_t encoding_uid, Type::EncodingDataType encoding_uid_type, const Declaration &decl, const CompilerType &compiler_qual_type, Type::ResolveState compiler_type_resolve_state, uint32_t opaque_payload=0) override
This function is used to create types that belong to a SymbolFile.
@ kAllAbilities
All detailed debug-information abilities.
virtual std::recursive_mutex & GetModuleMutex() const
Symbols file subclasses should override this to return the Module that owns the TypeSystem that this ...
bool ValueIsAddress() const
void SetType(lldb::SymbolType type)
Address & GetAddressRef()
void SetByteSize(lldb::addr_t size)
Symbol * SymbolAtIndex(size_t idx)
uint32_t AddSymbol(const Symbol &symbol)
size_t GetNumSymbols() const
static FileSpecList GetDefaultDebugFileSearchPaths()
void Insert(const lldb::TypeSP &type)
void Insert(const lldb::TypeSP &type)
A class that contains all state required for type lookups.
ConstString GetTypeBasename() const
Get the type basename to use when searching the type indexes in each SymbolFile object.
bool ContextMatches(llvm::ArrayRef< lldb_private::CompilerContext > context) const
Check of a CompilerContext array from matching type from a symbol file matches the m_context.
This class tracks the state and results of a TypeQuery.
bool InsertUnique(const lldb::TypeSP &type_sp)
When types that match a TypeQuery are found, this API is used to insert the matching types.
bool Done(const TypeQuery &query) const
Check if the type matching has found all of the matches that it needs.
bool AlreadySearched(lldb_private::SymbolFile *sym_file)
Check if a SymbolFile object has already been searched by this type match object.
A TypeSystem implementation based on Clang.
Interface for representing a type system.
virtual npdb::PdbAstBuilder * GetNativePDBParser()
@ eEncodingIsTypedefUID
This type is alias to a type whose UID is m_encoding_uid.
@ eEncodingIsUID
This type is the type whose UID is m_encoding_uid.
static std::optional< ParsedName > GetTypeScopeAndBasename(llvm::StringRef name)
void AddVariable(const lldb::VariableSP &var_sp)
RangeVector< lldb::addr_t, lldb::addr_t > RangeList
virtual CompilerType GetOrCreateTypedefType(PdbGlobalSymId id)=0
virtual void Dump(Stream &stream, llvm::StringRef filter, bool show_color)=0
virtual CompilerDeclContext FindNamespaceDecl(CompilerDeclContext parent_ctx, llvm::StringRef name)=0
virtual bool CompleteType(CompilerType ct)=0
virtual void EnsureBlock(PdbCompilandSymId block_id)=0
virtual CompilerDeclContext GetParentDeclContext(PdbSymUid uid)=0
virtual CompilerType GetOrCreateType(PdbTypeSymId type)=0
virtual CompilerDecl GetOrCreateDeclForUid(PdbSymUid uid)=0
virtual void EnsureInlinedFunction(PdbCompilandSymId inlinesite_id)=0
virtual void ParseDeclsForContext(CompilerDeclContext context)=0
virtual CompilerDeclContext GetOrCreateDeclContextForUid(PdbSymUid uid)=0
PdbIndex - Lazy access to the important parts of a PDB file.
static llvm::Expected< std::unique_ptr< PdbIndex > > create(llvm::pdb::PDBFile *)
llvm::pdb::TpiStream & tpi()
PdbCompilandId asCompiland() const
PdbCompilandSymId asCompilandSym() const
PdbTypeSymId asTypeSym() const
uint64_t toOpaqueId() const
PdbSymUidKind kind() const
void CreateSimpleArgumentListTypes(llvm::codeview::TypeIndex arglist_ti)
lldb::VariableSP GetOrCreateGlobalVariable(PdbGlobalSymId var_id)
bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override
lldb::TypeSP CreateArrayType(PdbTypeSymId type_id, const llvm::codeview::ArrayRecord &ar, CompilerType ct)
std::optional< ArrayInfo > GetDynamicArrayInfoForUID(lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) override
If type_uid points to an array type, return its characteristics.
void CacheGlobalBaseNames()
Caches the basenames of symbols found in the globals stream.
llvm::Expected< Declaration > ResolveUdtDeclaration(PdbTypeSymId type_id)
lldb::VariableSP CreateGlobalVariable(PdbGlobalSymId var_id)
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
void InitializeObject() override
Initialize the SymbolFile object.
lldb_private::UniqueCStringMap< uint32_t > m_func_base_names
basename -> Global ID(s)
static SymbolFile * CreateInstance(lldb::ObjectFileSP objfile_sp)
uint32_t CalculateNumCompileUnits() override
llvm::DenseMap< lldb::user_id_t, lldb::TypeSP > m_types
bool CompleteType(CompilerType &compiler_type) override
lldb::LanguageType ParseLanguage(lldb_private::CompileUnit &comp_unit) override
CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override
void DumpClangAST(Stream &s, llvm::StringRef filter, bool show_color) override
size_t ParseVariablesForContext(const SymbolContext &sc) override
size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override
lldb::TypeSP CreatePointerType(PdbTypeSymId type_id, const llvm::codeview::PointerRecord &pr, CompilerType ct)
lldb::FunctionSP CreateFunction(PdbCompilandSymId func_id, CompileUnit &comp_unit)
llvm::DenseMap< lldb::user_id_t, lldb::BlockSP > m_blocks
bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit, SupportFileList &support_files) override
CompilerDecl GetDeclForUID(lldb::user_id_t uid) override
std::vector< CompilerContext > GetContextForTypedef(PdbGlobalSymId id)
SymbolFileNativePDB(lldb::ObjectFileSP objfile_sp)
lldb::TypeSP GetOrCreateTypedef(PdbGlobalSymId id)
void FindTypesByName(llvm::StringRef name, uint32_t max_matches, TypeMap &types)
lldb::TypeSP CreateTagType(PdbTypeSymId type_id, const llvm::codeview::ClassRecord &cr, CompilerType ct)
lldb::TypeSP GetOrCreateType(PdbTypeSymId type_id)
llvm::BumpPtrAllocator m_allocator
void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, TypeList &type_list) override
std::string GetFunctionCallLabel(PdbCompilandSymId id)
Build the asm label for the declaration of a function so that calls to it are routed through ResolveF...
llvm::DenseMap< lldb::user_id_t, lldb::VariableSP > m_local_variables
~SymbolFileNativePDB() override
llvm::Expected< SymbolContext > ResolveFunctionCallLabel(FunctionCallLabel &label) override
Resolves the function corresponding to the specified LLDB function call label.
lldb::VariableSP CreateConstantSymbol(PdbGlobalSymId var_id, const llvm::codeview::CVSymbol &cvs)
lldb::TypeSP CreateType(PdbTypeSymId type_id, CompilerType ct)
lldb_private::UniqueCStringMap< uint32_t > m_func_method_names
method basename -> Global ID(s)
bool AddOrModifySymbols(Symtab &symtab) override
Add symbols from this SymbolFile to the ObjectFile's symbol table, or update the symbols already in i...
std::optional< llvm::codeview::TypeIndex > GetParentType(llvm::codeview::TypeIndex ti)
lldb_private::UniqueCStringMap< uint32_t > m_global_variable_base_names
global variable basename -> Global ID(s)
void FindFunctions(const Module::LookupInfo &lookup_info, const CompilerDeclContext &parent_decl_ctx, bool include_inlines, SymbolContextList &sc_list) override
static llvm::StringRef GetPluginDescriptionStatic()
std::unique_ptr< llvm::pdb::PDBFile > m_file_up
lldb::TypeSP CreateProcedureType(PdbTypeSymId type_id, const llvm::codeview::ProcedureRecord &pr, CompilerType ct)
lldb::TypeSP CreateModifierType(PdbTypeSymId type_id, const llvm::codeview::ModifierRecord &mr, CompilerType ct)
uint64_t GetDebugInfoSize(bool load_all_debug_info=false) override
Metrics gathering functions.
std::optional< llvm::StringRef > FindMangledSymbol(SegmentOffset so, llvm::codeview::TypeIndex function_type=llvm::codeview::TypeIndex())
Find a symbol name at a specific address (so).
size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override
Block * GetOrCreateBlock(PdbCompilandSymId block_id)
lldb::VariableSP GetOrCreateLocalVariable(PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param, bool is_constant=false)
lldb::addr_t m_obj_load_address
size_t ParseBlocksRecursive(Function &func) override
std::once_flag m_cached_udt_declarations
void CacheUdtDeclarations()
void AppendFunctionForProcRef(PdbGlobalSymId global, SymbolContextList &sc_list)
Append the function referenced by the S_PROCREF/S_LPROCREF global.
std::optional< PdbCompilandSymId > FindMethodDefinition(llvm::StringRef qualified_name, llvm::codeview::TypeIndex method_type)
Find the S_GPROC32/S_LPROC32 record named qualified_name whose type is method_type.
lldb::CompUnitSP CreateCompileUnit(const CompilandIndexItem &cci)
std::optional< PdbCompilandSymId > FindSymbolScope(PdbCompilandSymId id)
size_t ParseSymbolArrayInScope(PdbCompilandSymId parent, llvm::function_ref< bool(llvm::codeview::SymbolKind, PdbCompilandSymId)> fn)
llvm::StringMap< uint32_t > m_typedef_scopes
Qualified name of a scope of a typedef -> Global ID of a typedef in it.
size_t ParseVariablesForCompileUnit(CompileUnit &comp_unit, VariableList &variables)
uint32_t CalculateAbilities() override
llvm::DenseMap< lldb::user_id_t, lldb::CompUnitSP > m_compilands
Block * CreateBlock(PdbCompilandSymId block_id)
std::vector< CompilerContext > GetContextForType(llvm::codeview::TypeIndex ti)
lldb_private::UniqueCStringMap< uint32_t > m_typedef_base_names
typedef basename -> Global ID(s) of its S_UDT
llvm::Expected< uint32_t > GetFileIndex(const CompilandIndexItem &cii, uint32_t file_id)
lldb::CompUnitSP GetOrCreateCompileUnit(const CompilandIndexItem &cci)
Type * ResolveTypeUID(lldb::user_id_t type_uid) override
std::set< lldb_private::LineTable::Entry, LineTableEntryComparator > LineSet
llvm::DenseMap< lldb::user_id_t, lldb::FunctionSP > m_functions
bool ParseImportedModules(const SymbolContext &sc, std::vector< lldb_private::SourceModule > &imported_modules) override
bool IsTypedefUdt(const llvm::codeview::UDTSym &udt)
Returns true if udt is a typedef rather than the S_UDT that is emitted for every tag type.
llvm::StringRef StripMangledFunctionName(llvm::StringRef mangled, PdbTypeSymId func_ty)
static void DebuggerInitialize(Debugger &debugger)
lldb::VariableSP CreateLocalVariable(PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param, bool is_constant=false)
llvm::DenseMap< lldb::user_id_t, std::shared_ptr< InlineSite > > m_inline_sites
void ParseInlineSite(PdbCompilandSymId inline_site_id, Address func_addr)
std::string MakeFunctionCallLabel(PdbSymUid uid, llvm::StringRef lookup_name)
lldb::TypeSP CreateClassStructUnion(PdbTypeSymId type_id, const llvm::codeview::TagRecord &record, size_t size, CompilerType ct)
void FindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, VariableList &variables) override
static llvm::StringRef GetPluginNameStatic()
size_t ParseVariablesForBlock(PdbCompilandSymId block_id)
void ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override
lldb::FunctionSP GetOrCreateFunction(PdbCompilandSymId func_id, CompileUnit &comp_unit)
llvm::DenseMap< llvm::codeview::TypeIndex, llvm::codeview::TypeIndex > m_parent_types
lldb_private::UniqueCStringMap< uint32_t > m_func_full_names
mangled name/full function name -> Global ID(s)
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override
lldb::TypeSP CreateFunctionType(PdbTypeSymId type_id, const llvm::codeview::MemberFunctionRecord &pr, CompilerType ct)
static void MarkPrologueAndEpilogue(LineSet &line_set, lldb::addr_t func_addr, const llvm::codeview::ProcSym &proc)
Record where a procedure's prologue ends and its epilogue begins in the line table.
lldb_private::UniqueCStringMap< uint32_t > m_type_base_names
lldb::TypeSP CreateAndCacheType(PdbTypeSymId type_id)
CompilerDeclContext FindNamespace(ConstString name, const CompilerDeclContext &parent_decl_ctx, bool only_root_namespaces) override
Finds a namespace of name name and whose parent context is parent_decl_ctx.
CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override
bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override
lldb::TypeSP CreateTypedef(PdbGlobalSymId id)
bool m_done_full_type_scan
llvm::DenseMap< llvm::codeview::TypeIndex, UdtDeclaration > m_udt_declarations
void FindTypes(const lldb_private::TypeQuery &match, lldb_private::TypeResults &results) override
Find types using a type-matching object that contains all search parameters.
static char ID
LLVM RTTI support.
std::string GetMethodCallLabel(llvm::codeview::TypeIndex method_type, llvm::StringRef qualified_name)
Build the asm label for a method that was declared in the field list of its class.
uint32_t ResolveSymbolContext(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc) override
lldb::VariableSP GetOrCreateLocalStaticVariable(PdbCompilandSymId scope_id, PdbCompilandSymId var_id)
std::unique_ptr< PdbIndex > m_index
llvm::DenseMap< lldb::user_id_t, lldb::VariableSP > m_global_vars
lldb::TypeSP CreateSimpleType(llvm::codeview::TypeIndex ti, CompilerType ct)
#define LLDB_INVALID_ADDRESS
uint64_t toOpaqueUid(const T &cid)
size_t GetTypeSizeForSimpleKind(llvm::codeview::SimpleTypeKind kind)
SegmentOffsetLength GetSegmentOffsetAndLength(const llvm::codeview::CVSymbol &sym)
bool IsTagRecord(llvm::codeview::CVType cvt)
bool IsValidRecord(const RecordT &sym)
llvm::Expected< DWARFExpression > MakeConstantLocationExpression(llvm::codeview::TypeIndex underlying_ti, llvm::pdb::TpiStream &tpi, const llvm::APSInt &constant, lldb::ModuleSP module)
DWARFExpression MakeGlobalLocationExpression(uint16_t section, uint32_t offset, lldb::ModuleSP module)
VariableInfo GetVariableLocationInfo(PdbIndex &index, PdbCompilandSymId var_id, Block &func_block, lldb::ModuleSP module)
bool IsForwardRefUdt(llvm::codeview::CVType cvt)
llvm::pdb::PDB_SymType CVSymToPDBSym(llvm::codeview::SymbolKind kind)
DWARFExpression MakeGlobalThreadLocalLocationExpression(uint32_t offset, const lldb::ModuleSP &module)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::shared_ptr< lldb_private::Function > FunctionSP
std::shared_ptr< lldb_private::Block > BlockSP
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
@ eLanguageTypeObjC_plus_plus
Objective-C++.
@ eLanguageTypeSwift
Swift.
@ eLanguageTypeC
Non-standardized C, such as K&R.
@ eLanguageTypeObjC
Objective-C.
@ eLanguageTypeC_plus_plus
ISO C++:1998.
std::shared_ptr< lldb_private::Type > TypeSP
@ eSymbolTypeAdditional
When symbols take more than one entry, the extra entries get this type.
std::shared_ptr< lldb_private::VariableList > VariableListSP
std::shared_ptr< lldb_private::SymbolFileType > SymbolFileTypeSP
std::shared_ptr< lldb_private::Variable > VariableSP
@ eValueTypeVariableGlobal
globals variable
@ eValueTypeVariableLocal
function local variables
@ eValueTypeVariableArgument
function argument variables
@ eValueTypeVariableStatic
static variable
@ eValueTypeVariableThreadLocal
thread local storage variable
std::shared_ptr< lldb_private::Section > SectionSP
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
Holds parsed information about a function call label that LLDB attaches as an AsmLabel to function AS...
lldb::user_id_t symbol_id
Unique identifier of the function symbol on which to perform the function call.
std::string toString() const
Encode this FunctionCallLabel into its string representation.
llvm::StringRef discriminator
Arbitrary string which language plugins can interpret for their own needs.
uint32_t is_epilogue_begin
Indicates this entry is one (of possibly many) where execution should be suspended for an exit breakp...
uint32_t is_prologue_end
Indicates this entry is one (of possibly many) where execution should be suspended for an entry break...
lldb::addr_t file_addr
The file address for this line entry.
BaseType GetRangeBase() const
void SetRangeEnd(BaseType end)
void SetRangeBase(BaseType b)
Set the start value for the range, and keep the same size.
lldb::user_id_t GetID() const
Get accessor for the user ID.
CompilerContextKind contextKind() const
static CVTagRecord create(llvm::codeview::CVType type)
const llvm::codeview::TagRecord & asTag() const
llvm::StringRef name() const
Represents a single compile unit.
std::map< llvm::codeview::TypeIndex, llvm::codeview::InlineeSourceLine > m_inline_map
std::optional< llvm::codeview::Compile3Sym > m_compile_opts
llvm::pdb::ModuleDebugStreamRef m_debug_stream
GlobalLineTable m_global_line_table
llvm::codeview::StringsAndChecksumsRef m_strings
std::vector< llvm::StringRef > m_file_list
llvm::codeview::TypeIndex index
DWARFExpressionList location
llvm::codeview::TypeIndex type