28#include "llvm/DebugInfo/CodeView/CVRecord.h"
29#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
30#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
31#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
32#include "llvm/DebugInfo/CodeView/RecordName.h"
33#include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
34#include "llvm/DebugInfo/CodeView/SymbolRecordHelpers.h"
35#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
36#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
37#include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
38#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
39#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
40#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
41#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
42#include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
43#include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
44#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
45#include "llvm/DebugInfo/PDB/PDB.h"
46#include "llvm/DebugInfo/PDB/PDBTypes.h"
47#include "llvm/Demangle/MicrosoftDemangle.h"
48#include "llvm/Object/COFF.h"
49#include "llvm/Support/Allocator.h"
50#include "llvm/Support/BinaryStreamReader.h"
51#include "llvm/Support/Error.h"
52#include "llvm/Support/ErrorOr.h"
53#include "llvm/Support/MemoryBuffer.h"
82 case PDB_Lang::ObjCpp:
89static std::optional<std::string>
91 llvm::StringRef exe_path) {
94 if (fs.
Exists(original_pdb_path))
95 return std::string(original_pdb_path);
100 const FileSpec original_pdb_spec(original_pdb_path,
102 .value_or(FileSpec::Style::native));
103 const llvm::StringRef pdb_filename = original_pdb_spec.
GetFilename();
114 for (
const FileSpec &search_dir : search_paths) {
123static std::unique_ptr<PDBFile>
126 using namespace llvm::object;
127 auto expected_binary = createBinary(exe_path);
130 if (!expected_binary) {
131 llvm::consumeError(expected_binary.takeError());
134 OwningBinary<Binary> binary = std::move(*expected_binary);
138 auto *obj = llvm::dyn_cast<llvm::object::COFFObjectFile>(binary.getBinary());
141 const llvm::codeview::DebugInfo *pdb_info =
nullptr;
144 llvm::StringRef pdb_file;
145 if (llvm::Error e = obj->getDebugPDBInfo(pdb_info, pdb_file)) {
146 consumeError(std::move(e));
150 std::optional<std::string> resolved_pdb_path =
152 if (!resolved_pdb_path)
161 auto expected_info =
pdb->getPDBInfoStream();
162 if (!expected_info) {
163 llvm::consumeError(expected_info.takeError());
166 llvm::codeview::GUID guid;
167 memcpy(&guid, pdb_info->PDB70.Signature, 16);
169 if (expected_info->getGuid() != guid)
196 case SimpleTypeKind::Boolean128:
198 case SimpleTypeKind::Boolean64:
200 case SimpleTypeKind::Boolean32:
202 case SimpleTypeKind::Boolean16:
204 case SimpleTypeKind::Boolean8:
207 case SimpleTypeKind::Byte:
208 case SimpleTypeKind::UnsignedCharacter:
209 return "unsigned char";
210 case SimpleTypeKind::NarrowCharacter:
212 case SimpleTypeKind::SignedCharacter:
213 case SimpleTypeKind::SByte:
214 return "signed char";
215 case SimpleTypeKind::Character32:
217 case SimpleTypeKind::Character16:
219 case SimpleTypeKind::Character8:
222 case SimpleTypeKind::Complex128:
223 return "_Complex __float128";
224 case SimpleTypeKind::Complex80:
225 return "_Complex long double";
226 case SimpleTypeKind::Complex64:
227 return "_Complex double";
228 case SimpleTypeKind::Complex48:
229 return "_Complex __float48";
230 case SimpleTypeKind::Complex32:
231 case SimpleTypeKind::Complex32PartialPrecision:
232 return "_Complex float";
233 case SimpleTypeKind::Complex16:
234 return "_Complex _Float16";
236 case SimpleTypeKind::Float128:
238 case SimpleTypeKind::Float80:
239 return "long double";
240 case SimpleTypeKind::Float64:
242 case SimpleTypeKind::Float48:
244 case SimpleTypeKind::Float32:
245 case SimpleTypeKind::Float32PartialPrecision:
247 case SimpleTypeKind::Float16:
250 case SimpleTypeKind::Int128Oct:
251 case SimpleTypeKind::Int128:
253 case SimpleTypeKind::Int64:
254 case SimpleTypeKind::Int64Quad:
256 case SimpleTypeKind::Int32Long:
258 case SimpleTypeKind::Int32:
260 case SimpleTypeKind::Int16:
261 case SimpleTypeKind::Int16Short:
264 case SimpleTypeKind::UInt128Oct:
265 case SimpleTypeKind::UInt128:
266 return "unsigned __int128";
267 case SimpleTypeKind::UInt64:
268 case SimpleTypeKind::UInt64Quad:
269 return "unsigned long long";
270 case SimpleTypeKind::UInt32:
272 case SimpleTypeKind::UInt16:
273 case SimpleTypeKind::UInt16Short:
274 return "unsigned short";
275 case SimpleTypeKind::UInt32Long:
276 return "unsigned long";
278 case SimpleTypeKind::HResult:
280 case SimpleTypeKind::Void:
282 case SimpleTypeKind::WideCharacter:
285 case SimpleTypeKind::None:
286 case SimpleTypeKind::NotTranslated:
303static std::optional<CVTagRecord>
322 if (Record.Type.isSimple())
325 CVType cvt = tpi.getType(Record.Type);
334 std::string qname = std::string(parent.
asTag().getUniqueName());
335 if (qname.size() < 4 || child.
asTag().getUniqueName().size() < 4)
341 qname[3] = child.
asTag().getUniqueName()[3];
345 piece += Record.Name;
346 piece.push_back(
'@');
347 qname.insert(4, std::move(piece));
348 if (qname != child.
asTag().UniqueName)
351 return std::move(child);
367 return "Microsoft PDB debug symbol cross-platform file reader.";
383 uint32_t abilities = 0;
391 pdb_file = &
pdb->GetPDBFile();
402 if (!expected_index) {
403 llvm::consumeError(expected_index.takeError());
406 m_index = std::move(*expected_index);
415 if (
m_index->dbi().isStripped())
426 m_index->ParseSectionContribs();
428 auto ts_or_err =
m_objfile_sp->GetModule()->GetTypeSystemForLanguage(
430 if (
auto err = ts_or_err.takeError()) {
432 "Failed to initialize: {0}");
434 if (
auto ts = *ts_or_err)
435 ts->SetSymbolFile(
this);
441 const DbiModuleList &modules =
m_index->dbi().modules();
442 uint32_t count = modules.getModuleCount();
449 DbiModuleDescriptor last = modules.getModuleDescriptor(count - 1);
450 if (last.getModuleName() ==
"* Linker *")
461 if (
auto err = ts_or_err.takeError())
463 auto ts = *ts_or_err;
468 switch (sym.kind()) {
474 return &func->GetBlock(
false);
481 BlockSym block(
static_cast<SymbolRecordKind
>(sym.kind()));
482 cantFail(SymbolDeserializer::deserializeAs<BlockSym>(sym, block));
491 m_index->MakeVirtualAddress(block.Segment, block.CodeOffset);
494 if (block_base >= func_base)
495 child_block->AddRange(
Block::Range(block_base - func_base, block.CodeSize));
498 "S_BLOCK32 at modi: {0:d} offset: {1:d}: adding range "
499 "[{2:x16}-{3:x16}) which has a base that is less than the "
501 "low PC 0x%" PRIx64
". Please file a bug and attach the file at the "
502 "start of this error message",
504 block_base + block.CodeSize, func_base);
508 m_blocks.insert({opaque_block_uid, child_block});
513 comp_unit->GetLineTable();
515 std::shared_ptr<InlineSite> inline_site =
m_inline_sites[opaque_block_uid];
523 for (
size_t i = 0; i < inline_site->ranges.GetSize(); ++i) {
524 auto *entry = inline_site->ranges.GetEntryAtIndex(i);
525 child_block->AddRange(
526 Block::Range(entry->GetRangeBase(), entry->GetByteSize()));
528 child_block->FinalizeRanges();
531 Declaration &decl = inline_site->inline_function_info->GetDeclaration();
532 Declaration &callsite = inline_site->inline_function_info->GetCallSite();
533 child_block->SetInlinedFunctionInfo(
534 inline_site->inline_function_info->GetName().GetCString(),
nullptr,
536 m_blocks.insert({opaque_block_uid, child_block});
540 lldbassert(
false &&
"Symbol is not a block!");
553 lldbassert(sym_record.kind() == S_LPROC32 || sym_record.kind() == S_GPROC32);
565 ProcSym proc(
static_cast<SymbolRecordKind
>(sym_record.kind()));
566 cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym_record, proc));
567 if (proc.FunctionType == TypeIndex::None())
576 SegmentOffset(proc.Segment, proc.CodeOffset), proc.FunctionType);
577 Mangled mangled(mangled_opt.value_or(proc.Name));
579 FunctionSP func_sp = std::make_shared<Function>(
581 func_type.get(), func_addr,
587 if (
auto err = ts_or_err.takeError())
589 auto ts = *ts_or_err;
592 ast_builder->EnsureFunction(func_id);
608 llvm::SmallString<64> source_file_name =
609 m_index->compilands().GetMainSourceFile(cci);
610 FileSpec fs(llvm::sys::path::convert_to_slash(
611 source_file_name, llvm::sys::path::Style::windows_backslash));
613 CompUnitSP cu_sp = std::make_shared<CompileUnit>(
614 m_objfile_sp->GetModule(),
nullptr, std::make_shared<SupportFile>(fs),
622 const ModifierRecord &mr,
624 TpiStream &stream =
m_index->tpi();
628 if ((mr.Modifiers & ModifierOptions::Const) != ModifierOptions::None)
630 if ((mr.Modifiers & ModifierOptions::Volatile) != ModifierOptions::None)
632 if ((mr.Modifiers & ModifierOptions::Unaligned) != ModifierOptions::None)
633 name +=
"__unaligned ";
635 if (mr.ModifiedType.isSimple())
638 name += computeTypeName(stream.typeCollection(), mr.ModifiedType);
643 llvm::expectedToOptional(modified_type->GetByteSize(
nullptr)),
650 const llvm::codeview::PointerRecord &pr,
656 if (pr.isPointerToMember()) {
657 MemberPointerInfo mpi = pr.getMemberInfo();
670 if (ti == TypeIndex::NullptrT()) {
677 if (ti.getSimpleMode() != SimpleTypeMode::Direct) {
679 uint32_t pointer_size = 0;
680 switch (ti.getSimpleMode()) {
681 case SimpleTypeMode::FarPointer32:
682 case SimpleTypeMode::NearPointer32:
685 case SimpleTypeMode::NearPointer64:
697 if (ti.getSimpleKind() == SimpleTypeKind::NotTranslated)
709 if (!record.hasUniqueName())
712 llvm::ms_demangle::Demangler demangler;
713 std::string_view sv(record.UniqueName.begin(), record.UniqueName.size());
714 llvm::ms_demangle::TagTypeNode *ttn = demangler.parseTagUniqueName(sv);
718 llvm::ms_demangle::IdentifierNode *idn =
719 ttn->QualifiedName->getUnqualifiedIdentifier();
720 return idn->toString();
725 const TagRecord &record,
733 decl = std::move(*maybeDecl);
736 "Failed to resolve declaration for '{1}': {0}", uname);
744 const ClassRecord &cr,
750 const UnionRecord &ur,
756 const EnumRecord &er,
763 decl = std::move(*maybeDecl);
766 "Failed to resolve declaration for '{1}': {0}", uname);
772 llvm::expectedToOptional(underlying_type->GetByteSize(
nullptr)),
nullptr,
778 const ArrayRecord &ar,
787 array_sp->SetEncodingType(element_type.get());
792 const MemberFunctionRecord &mfr,
794 if (mfr.ReturnType.isSimple())
805 const ProcedureRecord &pr,
807 if (pr.ReturnType.isSimple())
818 llvm::codeview::TypeIndex arglist_ti) {
819 if (arglist_ti.isNoneType())
822 CVType arglist_cvt =
m_index->tpi().getType(arglist_ti);
823 if (arglist_cvt.kind() != LF_ARGLIST)
828 TypeDeserializer::deserializeAs<ArgListRecord>(arglist_cvt, alr));
829 for (TypeIndex
id : alr.getIndices())
830 if (!
id.isNoneType() &&
id.isSimple())
835 if (type_id.
index.isSimple())
839 CVType cvt = stream.getType(type_id.
index);
841 if (cvt.kind() == LF_MODIFIER) {
842 ModifierRecord modifier;
844 TypeDeserializer::deserializeAs<ModifierRecord>(cvt, modifier));
848 if (cvt.kind() == LF_POINTER) {
849 PointerRecord pointer;
851 TypeDeserializer::deserializeAs<PointerRecord>(cvt, pointer));
857 llvm::cantFail(TypeDeserializer::deserializeAs<ClassRecord>(cvt, cr));
861 if (cvt.kind() == LF_ENUM) {
863 llvm::cantFail(TypeDeserializer::deserializeAs<EnumRecord>(cvt, er));
867 if (cvt.kind() == LF_UNION) {
869 llvm::cantFail(TypeDeserializer::deserializeAs<UnionRecord>(cvt, ur));
873 if (cvt.kind() == LF_ARRAY) {
875 llvm::cantFail(TypeDeserializer::deserializeAs<ArrayRecord>(cvt, ar));
879 if (cvt.kind() == LF_PROCEDURE) {
881 llvm::cantFail(TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, pr));
884 if (cvt.kind() == LF_MFUNCTION) {
885 MemberFunctionRecord mfr;
886 llvm::cantFail(TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfr));
896 std::optional<PdbTypeSymId> full_decl_uid;
898 auto expected_full_ti =
899 m_index->tpi().findFullDeclForForwardRef(type_id.
index);
900 if (!expected_full_ti)
901 llvm::consumeError(expected_full_ti.takeError());
902 else if (*expected_full_ti != type_id.
index) {
910 if (full_iter !=
m_types.end()) {
911 TypeSP result = full_iter->second;
920 PdbTypeSymId best_decl_id = full_decl_uid ? *full_decl_uid : type_id;
922 if (
auto err = ts_or_err.takeError())
924 auto ts = *ts_or_err;
963 CVSymbol sym =
m_index->symrecords().readRecord(var_id.
offset);
964 if (sym.kind() == S_CONSTANT)
969 llvm::StringRef name;
971 uint16_t section = 0;
973 bool is_external =
false;
974 switch (sym.kind()) {
979 DataSym ds(sym.kind());
980 llvm::cantFail(SymbolDeserializer::deserializeAs<DataSym>(sym, ds));
985 section = ds.Segment;
986 offset = ds.DataOffset;
987 addr =
m_index->MakeVirtualAddress(ds.Segment, ds.DataOffset);
994 ThreadLocalDataSym tlds(sym.kind());
996 SymbolDeserializer::deserializeAs<ThreadLocalDataSym>(sym, tlds));
999 section = tlds.Segment;
1000 offset = tlds.DataOffset;
1001 addr =
m_index->MakeVirtualAddress(tlds.Segment, tlds.DataOffset);
1006 llvm_unreachable(
"unreachable!");
1010 std::optional<uint16_t> modi =
m_index->GetModuleIndexForVa(addr);
1021 std::make_shared<SymbolFileType>(*
this,
toOpaqueUid(tid));
1024 if (
auto err = ts_or_err.takeError())
1026 auto ts = *ts_or_err;
1029 ast_builder->EnsureVariable(var_id);
1037 std::string global_name(
"::");
1038 global_name += name;
1039 bool artificial =
false;
1040 bool location_is_constant_data =
false;
1041 bool static_member =
false;
1042 VariableSP var_sp = std::make_shared<Variable>(
1043 toOpaqueUid(var_id), name.str().c_str(), global_name.c_str(), type_sp,
1044 scope, comp_unit.get(), ranges, &decl, location, is_external, artificial,
1045 location_is_constant_data, static_member);
1052 const CVSymbol &cvs) {
1053 TpiStream &tpi =
m_index->tpi();
1054 ConstantSym constant(cvs.kind());
1056 llvm::cantFail(SymbolDeserializer::deserializeAs<ConstantSym>(cvs, constant));
1057 std::string global_name(
"::");
1058 global_name += constant.Name;
1061 std::make_shared<SymbolFileType>(*
this,
toOpaqueUid(tid));
1068 constant.Type, tpi, constant.Value, module),
1071 bool external =
false;
1072 bool artificial =
false;
1073 bool location_is_constant_data =
true;
1074 bool static_member =
false;
1075 VariableSP var_sp = std::make_shared<Variable>(
1076 toOpaqueUid(var_id), constant.Name.str().c_str(), global_name.c_str(),
1078 external, artificial, location_is_constant_data, static_member);
1085 if (emplace_result.second) {
1087 emplace_result.first->second = var_sp;
1092 return emplace_result.first->second;
1102 if (emplace_result.second)
1103 emplace_result.first->second =
CreateFunction(func_id, comp_unit);
1105 return emplace_result.first->second;
1111 auto emplace_result =
1113 if (emplace_result.second)
1117 return emplace_result.first->second;
1123 return iter->second.get();
1143 if (index >= UINT16_MAX)
1166 auto *section_list =
1167 m_objfile_sp->GetModule()->GetObjectFile()->GetSectionList();
1171 PublicSym32 last_sym;
1172 size_t last_sym_idx = 0;
1180 auto finish_last_symbol = [&](
const PublicSym32 *next) {
1187 if (next && last_sym.Segment == next->Segment) {
1188 assert(last_sym.Offset <= next->Offset);
1189 last->
SetByteSize(next->Offset - last_sym.Offset);
1192 assert(section_sp->GetByteSize() >= last_sym.Offset);
1193 assert(!next || next->Segment > last_sym.Segment);
1194 last->
SetByteSize(section_sp->GetByteSize() - last_sym.Offset);
1199 for (
auto pid :
m_index->publics().getAddressMap()) {
1201 CVSymbol sym =
m_index->ReadSymbolRecord(global);
1202 auto kind = sym.kind();
1203 if (kind != S_PUB32)
1206 llvm::cantFail(SymbolDeserializer::deserializeAs<PublicSym32>(sym));
1207 finish_last_symbol(&pub);
1209 if (!section_sp || last_sym.Segment != pub.Segment)
1210 section_sp = section_list->FindSectionByID(pub.Segment);
1216 if ((pub.Flags & PublicSymFlags::Function) != PublicSymFlags::None ||
1217 (pub.Flags & PublicSymFlags::Code) != PublicSymFlags::None)
1237 finish_last_symbol(
nullptr);
1249 for (
auto iter = syms.begin(); iter != syms.end(); ++iter) {
1250 if (iter->kind() != S_LPROC32 && iter->kind() != S_GPROC32)
1260 return new_count - count;
1265 uint32_t flags = eSymbolContextCompUnit;
1266 flags |= eSymbolContextVariable;
1267 flags |= eSymbolContextFunction;
1268 flags |= eSymbolContextBlock;
1269 flags |= eSymbolContextLineEntry;
1270 return (resolve_scope & flags) != 0;
1274 const Address &addr, SymbolContextItem resolve_scope, SymbolContext &sc) {
1276 uint32_t resolved_flags = 0;
1280 std::optional<uint16_t> modi =
m_index->GetModuleIndexForVa(file_addr);
1288 resolved_flags |= eSymbolContextCompUnit;
1291 if (resolve_scope & eSymbolContextFunction ||
1292 resolve_scope & eSymbolContextBlock) {
1294 std::vector<SymbolAndUid> matches =
m_index->FindSymbolsByVa(file_addr);
1298 for (
const auto &match : llvm::reverse(matches)) {
1302 PdbCompilandSymId csid = match.uid.asCompilandSym();
1303 CVSymbol cvs =
m_index->ReadSymbolRecord(csid);
1305 if (type != PDB_SymType::Function && type != PDB_SymType::Block)
1307 if (type == PDB_SymType::Function) {
1312 addr_t offset = file_addr - func_base;
1317 if (type == PDB_SymType::Block) {
1325 addr_t offset = file_addr - func_base;
1330 resolved_flags |= eSymbolContextFunction;
1332 resolved_flags |= eSymbolContextBlock;
1337 if (resolve_scope & eSymbolContextLineEntry) {
1340 if (line_table->FindLineEntryByAddress(addr, sc.
line_entry))
1341 resolved_flags |= eSymbolContextLineEntry;
1345 return resolved_flags;
1352 const uint32_t prev_size = sc_list.
GetSize();
1353 if (resolve_scope & eSymbolContextCompUnit) {
1362 if (file_spec_matches_cu_file_spec) {
1368 return sc_list.
GetSize() - prev_size;
1387 std::set<LineTable::Entry, LineTableEntryComparator> line_set;
1392 for (
const DebugSubsectionRecord &dssr :
1394 if (dssr.kind() != DebugSubsectionKind::Lines)
1397 DebugLinesSubsectionRef lines;
1398 llvm::BinaryStreamReader reader(dssr.getRecordData());
1399 if (
auto EC = lines.initialize(reader)) {
1400 llvm::consumeError(std::move(EC));
1404 const LineFragmentHeader *lfh = lines.header();
1405 uint64_t virtual_addr =
1406 m_index->MakeVirtualAddress(lfh->RelocSegment, lfh->RelocOffset);
1410 for (
const LineColumnEntry &group : lines) {
1411 llvm::Expected<uint32_t> file_index_or_err =
1413 if (!file_index_or_err)
1415 uint32_t file_index = file_index_or_err.get();
1419 for (
const LineNumberEntry &entry : group.LineNumbers) {
1420 LineInfo cur_info(entry.Flags);
1422 if (cur_info.isAlwaysStepInto() || cur_info.isNeverStepInto())
1425 uint64_t addr = virtual_addr + entry.Offset;
1427 bool is_statement = cur_info.isStatement();
1431 uint32_t lno = cur_info.getStartLine();
1434 is_prologue, is_epilogue,
false);
1436 auto iter = line_set.find(new_entry);
1437 if (iter != line_set.end() && iter->is_terminal_entry)
1438 line_set.erase(iter);
1439 line_set.insert(new_entry);
1446 line_entry.
data = {file_index, lno};
1448 LineInfo last_line(group.LineNumbers.back().Flags);
1449 line_set.emplace(virtual_addr + lfh->CodeSize, last_line.getEndLine(), 0,
1450 file_index,
false,
false,
false,
false,
true);
1453 line_entry.
SetRangeEnd(virtual_addr + lfh->CodeSize);
1462 const CVSymbolArray &syms = cii->
m_debug_stream.getSymbolArray();
1463 for (
auto iter = syms.begin(); iter != syms.end();) {
1464 if (iter->kind() != S_LPROC32 && iter->kind() != S_GPROC32) {
1469 uint32_t record_offset = iter.offset();
1470 CVSymbol func_record =
1483 if (kind != S_INLINESITE)
1488 for (
const auto &line_entry :
1493 if (!line_entry.is_terminal_entry)
1494 line_set.erase(line_entry);
1495 line_set.insert(line_entry);
1503 iter = syms.at(getScopeEndOffset(func_record));
1509 std::vector<LineTable::Sequence> sequence(1);
1510 for (
const auto &line_entry : line_set) {
1512 sequence.back(), line_entry.file_addr, line_entry.line,
1513 line_entry.column, line_entry.file_idx,
1514 line_entry.is_start_of_statement, line_entry.is_start_of_basic_block,
1515 line_entry.is_prologue_end, line_entry.is_epilogue_begin,
1516 line_entry.is_terminal_entry);
1519 std::make_unique<LineTable>(&comp_unit, std::move(sequence));
1521 if (line_table->GetSize() == 0)
1533llvm::Expected<uint32_t>
1537 return llvm::make_error<RawError>(raw_error_code::no_entry);
1539 const auto &checksums = cii.
m_strings.checksums().getArray();
1540 const auto &strings = cii.
m_strings.strings();
1544 auto iter = checksums.at(file_id);
1545 if (iter == checksums.end())
1546 return llvm::make_error<RawError>(raw_error_code::no_entry);
1548 llvm::Expected<llvm::StringRef> efn = strings.getString(iter->FileNameOffset);
1550 return efn.takeError();
1556 return std::distance(cii.
m_file_list.begin(), fn_iter);
1557 return llvm::make_error<RawError>(raw_error_code::no_entry);
1571 f.starts_with(
"/") ? FileSpec::Style::posix : FileSpec::Style::windows;
1573 support_files.
Append(spec);
1579 const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
1592 CVSymbol sym = cii->
m_debug_stream.readSymbolAtOffset(
id.offset);
1595 InlineSiteSym inline_site(
static_cast<SymbolRecordKind
>(sym.kind()));
1596 cantFail(SymbolDeserializer::deserializeAs<InlineSiteSym>(sym, inline_site));
1599 std::shared_ptr<InlineSite> inline_site_sp =
1600 std::make_shared<InlineSite>(parent_id);
1603 auto iter = cii->
m_inline_map.find(inline_site.Inlinee);
1606 InlineeSourceLine inlinee_line = iter->second;
1610 llvm::Expected<uint32_t> file_index_or_err =
1612 if (!file_index_or_err)
1614 uint32_t file_offset = file_index_or_err.get();
1616 uint32_t decl_line = inlinee_line.Header->SourceLineNum;
1617 std::unique_ptr<Declaration> decl_up =
1618 std::make_unique<Declaration>(decl_file, decl_line);
1621 uint32_t code_offset = 0;
1622 int32_t line_offset = 0;
1623 std::optional<uint32_t> code_offset_base;
1624 std::optional<uint32_t> code_offset_end;
1625 std::optional<int32_t> cur_line_offset;
1626 std::optional<int32_t> next_line_offset;
1627 std::optional<uint32_t> next_file_offset;
1629 bool is_terminal_entry =
false;
1630 bool is_start_of_statement =
true;
1632 bool is_prologue_end =
true;
1634 auto update_code_offset = [&](uint32_t code_delta) {
1635 if (!code_offset_base)
1636 code_offset_base = code_offset;
1637 else if (!code_offset_end)
1638 code_offset_end = *code_offset_base + code_delta;
1640 auto update_line_offset = [&](int32_t line_delta) {
1641 line_offset += line_delta;
1642 if (!code_offset_base || !cur_line_offset)
1643 cur_line_offset = line_offset;
1645 next_line_offset = line_offset;
1648 auto update_file_offset = [&](uint32_t offset) {
1649 if (!code_offset_base)
1650 file_offset = offset;
1652 next_file_offset = offset;
1655 for (
auto &annot : inline_site.annotations()) {
1656 switch (annot.OpCode) {
1657 case BinaryAnnotationsOpCode::CodeOffset:
1658 case BinaryAnnotationsOpCode::ChangeCodeOffset:
1659 case BinaryAnnotationsOpCode::ChangeCodeOffsetBase:
1660 code_offset += annot.U1;
1661 update_code_offset(annot.U1);
1663 case BinaryAnnotationsOpCode::ChangeLineOffset:
1664 update_line_offset(annot.S1);
1666 case BinaryAnnotationsOpCode::ChangeCodeLength:
1667 update_code_offset(annot.U1);
1668 code_offset += annot.U1;
1669 is_terminal_entry =
true;
1671 case BinaryAnnotationsOpCode::ChangeCodeOffsetAndLineOffset:
1672 code_offset += annot.U1;
1673 update_code_offset(annot.U1);
1674 update_line_offset(annot.S1);
1676 case BinaryAnnotationsOpCode::ChangeCodeLengthAndCodeOffset:
1677 code_offset += annot.U2;
1678 update_code_offset(annot.U2);
1679 update_code_offset(annot.U1);
1680 code_offset += annot.U1;
1681 is_terminal_entry =
true;
1683 case BinaryAnnotationsOpCode::ChangeFile:
1684 update_file_offset(annot.U1);
1691 if (code_offset_base && code_offset_end && cur_line_offset) {
1693 *code_offset_base, *code_offset_end - *code_offset_base,
1694 decl_line + *cur_line_offset));
1696 if (next_file_offset)
1697 file_offset = *next_file_offset;
1698 if (next_line_offset) {
1699 cur_line_offset = next_line_offset;
1700 next_line_offset = std::nullopt;
1702 code_offset_base = is_terminal_entry ? std::nullopt : code_offset_end;
1703 code_offset_end = next_file_offset = std::nullopt;
1705 if (code_offset_base && cur_line_offset) {
1706 if (is_terminal_entry) {
1708 func_base + *code_offset_base, decl_line + *cur_line_offset, 0,
1709 file_offset,
false,
false,
false,
false,
true);
1710 inline_site_sp->line_entries.push_back(line_entry);
1713 decl_line + *cur_line_offset, 0,
1714 file_offset, is_start_of_statement,
false,
1715 is_prologue_end,
false,
false);
1716 inline_site_sp->line_entries.push_back(line_entry);
1717 is_prologue_end =
false;
1718 is_start_of_statement =
false;
1721 if (is_terminal_entry)
1722 is_start_of_statement =
true;
1723 is_terminal_entry =
false;
1726 inline_site_sp->ranges.Sort();
1729 std::unique_ptr<Declaration> callsite_up;
1730 if (!inline_site_sp->ranges.IsEmpty()) {
1731 auto *entry = inline_site_sp->ranges.GetEntryAtIndex(0);
1732 addr_t base_offset = entry->GetRangeBase();
1738 std::shared_ptr<InlineSite> parent_site =
1741 parent_site->inline_function_info->GetDeclaration().GetFile();
1742 if (
auto *parent_entry =
1743 parent_site->ranges.FindEntryThatContains(base_offset)) {
1745 std::make_unique<Declaration>(parent_decl_file, parent_entry->data);
1750 func_base + base_offset)) {
1754 std::make_unique<Declaration>(callsite_file, entry->data.second);
1760 std::string inlinee_name;
1761 llvm::Expected<CVType> inlinee_cvt =
1762 m_index->ipi().typeCollection().getTypeOrError(inline_site.Inlinee);
1764 inlinee_name =
"[error reading function name: " +
1765 llvm::toString(inlinee_cvt.takeError()) +
"]";
1766 }
else if (inlinee_cvt->kind() == LF_MFUNC_ID) {
1767 MemberFuncIdRecord mfr;
1769 TypeDeserializer::deserializeAs<MemberFuncIdRecord>(*inlinee_cvt, mfr));
1770 LazyRandomTypeCollection &types =
m_index->tpi().typeCollection();
1771 inlinee_name.append(std::string(types.getTypeName(mfr.ClassType)));
1772 inlinee_name.append(
"::");
1773 inlinee_name.append(mfr.getName().str());
1774 }
else if (inlinee_cvt->kind() == LF_FUNC_ID) {
1776 cantFail(TypeDeserializer::deserializeAs<FuncIdRecord>(*inlinee_cvt, fir));
1777 TypeIndex parent_idx = fir.getParentScope();
1778 if (!parent_idx.isNoneType()) {
1779 LazyRandomTypeCollection &ids =
m_index->ipi().typeCollection();
1780 inlinee_name.append(std::string(ids.getTypeName(parent_idx)));
1781 inlinee_name.append(
"::");
1783 inlinee_name.append(fir.getName().str());
1785 inline_site_sp->inline_function_info = std::make_shared<InlineFunctionInfo>(
1786 inlinee_name.c_str(), llvm::StringRef(), decl_up.get(),
1797 std::set<uint64_t> remove_uids;
1799 if (kind == S_GPROC32 || kind == S_LPROC32 || kind == S_BLOCK32 ||
1800 kind == S_INLINESITE) {
1802 if (kind == S_INLINESITE)
1809 for (uint64_t uid : remove_uids) {
1821 CVSymbolArray syms =
1825 for (
auto iter = syms.begin(); iter != syms.end(); ++iter) {
1827 if (fn(iter->kind(), child_id))
1839 auto ts = *ts_or_err;
1846 ast_builder->
Dump(s, filter, show_color);
1854 std::map<std::pair<uint16_t, uint32_t>, uint32_t> func_addr_ids;
1857 for (
const uint32_t gid :
m_index->globals().getGlobalsTable()) {
1858 CVSymbol sym =
m_index->symrecords().readRecord(gid);
1859 auto kind = sym.kind();
1862 llvm::StringRef name;
1864 case SymbolKind::S_GDATA32:
1865 case SymbolKind::S_LDATA32: {
1867 llvm::cantFail(SymbolDeserializer::deserializeAs<DataSym>(sym));
1871 case SymbolKind::S_GTHREAD32:
1872 case SymbolKind::S_LTHREAD32: {
1873 ThreadLocalDataSym data = llvm::cantFail(
1874 SymbolDeserializer::deserializeAs<ThreadLocalDataSym>(sym));
1878 case SymbolKind::S_CONSTANT: {
1880 llvm::cantFail(SymbolDeserializer::deserializeAs<ConstantSym>(sym));
1888 if (!name.empty()) {
1897 if (kind != S_PROCREF && kind != S_LPROCREF)
1904 llvm::cantFail(SymbolDeserializer::deserializeAs<ProcRefSym>(sym));
1905 if (ref.Name.empty())
1910 m_index->compilands().GetOrCreateCompiland(ref.modi());
1911 auto iter = cci.
m_debug_stream.getSymbolArray().at(ref.SymOffset);
1914 kind = iter->kind();
1915 if (kind != S_GPROC32 && kind != S_LPROC32)
1919 llvm::cantFail(SymbolDeserializer::deserializeAs<ProcSym>(*iter));
1920 if ((proc.Flags & ProcSymFlags::IsUnreachable) != ProcSymFlags::None)
1922 if (proc.Name.empty() || proc.FunctionType.isSimple())
1928 func_addr_ids.emplace(std::make_pair(proc.Segment, proc.CodeOffset), gid);
1931 if (basename.empty())
1932 basename = proc.Name;
1938 auto type =
m_index->tpi().getType(proc.FunctionType);
1939 if (type.kind() == LF_MFUNCTION) {
1940 MemberFunctionRecord mfr;
1942 TypeDeserializer::deserializeAs<MemberFunctionRecord>(type, mfr));
1943 if (!mfr.getThisType().isNoneType())
1949 for (
auto pid :
m_index->publics().getPublicsTable()) {
1951 CVSymbol sym =
m_index->ReadSymbolRecord(global);
1952 auto kind = sym.kind();
1953 if (kind != S_PUB32)
1956 llvm::cantFail(SymbolDeserializer::deserializeAs<PublicSym32>(sym));
1963 auto it = func_addr_ids.find({pub.Segment, pub.Offset});
1964 if (it != func_addr_ids.end())
1986 std::vector<uint32_t> results;
1989 size_t n_matches = 0;
1990 for (uint32_t gid : results) {
1993 if (parent_decl_ctx.
IsValid() &&
2002 if (++n_matches >= max_matches)
2014 if (name_type_mask & eFunctionNameTypeFull)
2017 if (!(name_type_mask & eFunctionNameTypeFull ||
2018 name_type_mask & eFunctionNameTypeBase ||
2019 name_type_mask & eFunctionNameTypeMethod))
2023 std::set<uint32_t> resolved_ids;
2025 std::vector<uint32_t> ids;
2026 if (!Names.GetValues(name, ids))
2029 for (uint32_t
id : ids) {
2030 if (!resolved_ids.insert(
id).second)
2034 if (parent_decl_ctx.
IsValid() &&
2038 CVSymbol sym =
m_index->ReadSymbolRecord(global);
2039 auto kind = sym.kind();
2040 lldbassert(kind == S_PROCREF || kind == S_LPROCREF);
2043 cantFail(SymbolDeserializer::deserializeAs<ProcRefSym>(sym));
2049 m_index->compilands().GetOrCreateCompiland(proc.modi());
2065 if (name_type_mask & eFunctionNameTypeFull)
2067 if (name_type_mask & eFunctionNameTypeBase)
2069 if (name_type_mask & eFunctionNameTypeMethod)
2074 bool include_inlines,
2089 std::vector<uint32_t> matches;
2092 for (uint32_t match_idx : matches) {
2094 if (context.empty())
2103 if (results.
Done(query))
2110 uint32_t max_matches,
2113 std::vector<TypeIndex> matches =
m_index->tpi().findRecordsByName(name);
2114 if (max_matches > 0 && max_matches < matches.size())
2115 matches.resize(max_matches);
2117 for (TypeIndex ti : matches) {
2133 LazyRandomTypeCollection &types =
m_index->tpi().typeCollection();
2136 for (
auto ti = types.getFirst(); ti; ti = types.getNext(*ti)) {
2139 (void)type->GetFullCompilerType();
2143 for (
const uint32_t gid :
m_index->globals().getGlobalsTable()) {
2145 CVSymbol sym =
m_index->ReadSymbolRecord(global);
2146 if (sym.kind() != S_UDT)
2149 UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs<UDTSym>(sym));
2150 bool is_typedef =
true;
2152 CVType cvt =
m_index->tpi().getType(udt.Type);
2154 if (name == udt.Name)
2166 return new_count - old_count;
2174 for (
const uint32_t gid :
m_index->globals().getGlobalsTable()) {
2176 CVSymbol sym =
m_index->ReadSymbolRecord(global);
2181 switch (sym.kind()) {
2182 case SymbolKind::S_GDATA32:
2183 case SymbolKind::S_LDATA32:
2184 case SymbolKind::S_GTHREAD32:
2185 case SymbolKind::S_LTHREAD32: {
2206 Block *func_block = block;
2228 std::string name = var_info.
name.str();
2231 std::make_shared<SymbolFileType>(*
this, type_sp->GetID());
2236 bool external =
false;
2237 bool artificial =
false;
2238 bool location_is_constant_data =
false;
2239 bool static_member =
false;
2241 VariableSP var_sp = std::make_shared<Variable>(
2242 toOpaqueUid(var_id), name.c_str(), name.c_str(), sftype, var_scope, block,
2243 scope_ranges, &decl, var_info.
location, external, artificial,
2244 location_is_constant_data, static_member);
2247 if (
auto err = ts_or_err.takeError())
2249 auto ts = *ts_or_err;
2252 ast_builder->EnsureVariable(scope_id, var_id);
2263 return iter->second;
2269 CVSymbol sym =
m_index->ReadSymbolRecord(
id);
2272 UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs<UDTSym>(sym));
2277 if (
auto err = ts_or_err.takeError())
2279 auto ts = *ts_or_err;
2287 ct = target_type->GetForwardCompilerType();
2291 llvm::expectedToOptional(target_type->GetByteSize(
nullptr)),
2292 nullptr, target_type->GetID(),
2300 return iter->second;
2314 uint32_t params_remaining = 0;
2315 switch (sym.kind()) {
2318 ProcSym proc(
static_cast<SymbolRecordKind
>(sym.kind()));
2319 cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym, proc));
2320 CVType signature =
m_index->tpi().getType(proc.FunctionType);
2321 if (signature.kind() == LF_PROCEDURE) {
2322 ProcedureRecord sig;
2323 if (llvm::Error e = TypeDeserializer::deserializeAs<ProcedureRecord>(
2325 llvm::consumeError(std::move(e));
2328 params_remaining = sig.getParameterCount();
2329 }
else if (signature.kind() == LF_MFUNCTION) {
2330 MemberFunctionRecord sig;
2331 if (llvm::Error e = TypeDeserializer::deserializeAs<MemberFunctionRecord>(
2333 llvm::consumeError(std::move(e));
2336 params_remaining = sig.getParameterCount();
2346 lldbassert(
false &&
"Symbol is not a block!");
2352 variables = std::make_shared<VariableList>();
2356 CVSymbolArray syms = limitSymbolArrayToScope(
2362 auto iter = syms.begin();
2363 auto end = syms.end();
2365 while (iter != end) {
2366 uint32_t record_offset = iter.offset();
2367 CVSymbol variable_cvs = *iter;
2373 if (variable_cvs.kind() == S_BLOCK32 ||
2374 variable_cvs.kind() == S_INLINESITE) {
2375 uint32_t block_end = getScopeEndOffset(variable_cvs);
2377 iter = syms.at(block_end);
2381 bool is_param = params_remaining > 0;
2383 switch (variable_cvs.kind()) {
2391 variables->AddVariableIfUnique(variable);
2427 variables = std::make_shared<VariableList>();
2433 llvm_unreachable(
"Unreachable!");
2438 if (
auto err = ts_or_err.takeError())
2440 auto ts = *ts_or_err;
2452 if (
auto err = ts_or_err.takeError())
2454 auto ts = *ts_or_err;
2466 if (
auto err = ts_or_err.takeError())
2468 auto ts = *ts_or_err;
2479 auto iter =
m_types.find(type_uid);
2486 return &*iter->second;
2491 if (type_id.
index.isNoneType())
2500std::optional<SymbolFile::ArrayInfo>
2503 return std::nullopt;
2519 TypeClass type_mask,
2528 if (
auto err = ts_or_err.takeError())
2530 auto ts = *ts_or_err;
2533 auto *
clang = llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
2544llvm::Expected<lldb::TypeSystemSP>
2546 auto type_system_or_err =
2547 m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language);
2548 if (type_system_or_err)
2549 if (
auto ts = *type_system_or_err)
2550 ts->SetSymbolFile(
this);
2551 return type_system_or_err;
2556 return m_index->pdb().getFileSize();
2560 LazyRandomTypeCollection &types =
m_index->tpi().typeCollection();
2562 llvm::DenseMap<TypeIndex, TypeIndex> forward_to_full;
2563 llvm::DenseMap<TypeIndex, TypeIndex> full_to_forward;
2565 struct RecordIndices {
2570 llvm::StringMap<RecordIndices> record_indices;
2572 for (
auto ti = types.getFirst(); ti; ti = types.getNext(*ti)) {
2573 CVType type = types.getType(*ti);
2579 RecordIndices &indices = record_indices[tag.
asTag().getUniqueName()];
2580 if (tag.
asTag().isForwardRef()) {
2581 indices.forward = *ti;
2589 if (indices.full != TypeIndex::None() &&
2590 indices.forward != TypeIndex::None()) {
2591 forward_to_full[indices.forward] = indices.full;
2592 full_to_forward[indices.full] = indices.forward;
2598 if (tag.
asTag().isForwardRef() || !tag.
asTag().containsNestedClass())
2602 ProcessTpiStream(
PdbIndex &index, TypeIndex parent,
2604 llvm::DenseMap<TypeIndex, TypeIndex> &parents)
2605 : index(index), parents(parents), parent(parent),
2606 parent_cvt(parent_cvt) {}
2609 llvm::DenseMap<TypeIndex, TypeIndex> &parents;
2611 unsigned unnamed_type_index = 1;
2615 llvm::Error visitKnownMember(CVMemberRecord &CVR,
2616 NestedTypeRecord &Record)
override {
2617 std::string unnamed_type_name;
2618 if (Record.Name.empty()) {
2620 llvm::formatv(
"<unnamed-type-$S{0}>", unnamed_type_index).str();
2621 Record.Name = unnamed_type_name;
2622 ++unnamed_type_index;
2624 std::optional<CVTagRecord> tag =
2627 return llvm::ErrorSuccess();
2629 parents[Record.Type] = parent;
2630 return llvm::ErrorSuccess();
2634 CVType field_list_cvt =
m_index->tpi().getType(tag.
asTag().FieldList);
2636 FieldListRecord field_list;
2637 if (llvm::Error
error = TypeDeserializer::deserializeAs<FieldListRecord>(
2638 field_list_cvt, field_list))
2639 llvm::consumeError(std::move(
error));
2640 if (llvm::Error
error = visitMemberRecordStream(field_list.Data, process))
2641 llvm::consumeError(std::move(
error));
2653 std::vector<TypeIndex> full_keys;
2654 std::vector<TypeIndex> fwd_keys;
2656 TypeIndex key = entry.first;
2657 TypeIndex value = entry.second;
2659 auto iter = forward_to_full.find(value);
2660 if (iter != forward_to_full.end())
2661 entry.second = iter->second;
2663 iter = forward_to_full.find(key);
2664 if (iter != forward_to_full.end())
2665 fwd_keys.push_back(key);
2667 full_keys.push_back(key);
2669 for (TypeIndex fwd : fwd_keys) {
2670 TypeIndex full = forward_to_full[fwd];
2674 for (TypeIndex full : full_keys) {
2675 TypeIndex fwd = full_to_forward[full];
2680std::optional<PdbCompilandSymId>
2682 CVSymbol sym =
m_index->ReadSymbolRecord(
id);
2683 if (symbolOpensScope(sym.kind())) {
2686 id.offset = getScopeParentOffset(sym);
2690 return std::nullopt;
2699 auto begin = syms.begin();
2700 auto end = syms.at(
id.offset);
2701 std::vector<PdbCompilandSymId> scope_stack;
2703 while (begin != end) {
2704 if (begin.offset() >
id.offset) {
2706 lldbassert(
false &&
"Invalid compiland symbol id!");
2707 return std::nullopt;
2712 if (symbolOpensScope(begin->kind())) {
2715 uint32_t scope_end = getScopeEndOffset(*begin);
2716 if (scope_end <
id.offset) {
2717 begin = syms.at(scope_end);
2720 scope_stack.emplace_back(
id.modi, begin.offset());
2722 }
else if (symbolEndsScope(begin->kind())) {
2723 scope_stack.pop_back();
2727 if (scope_stack.empty())
2728 return std::nullopt;
2730 return scope_stack.back();
2733std::optional<llvm::codeview::TypeIndex>
2737 return std::nullopt;
2738 return parent_iter->second;
2741std::vector<CompilerContext>
2743 CVType type =
m_index->tpi().getType(ti);
2749 std::optional<Type::ParsedName> parsed_name =
2754 std::vector<CompilerContext> ctx;
2756 for (llvm::StringRef scope : parsed_name->scope) {
2763 for (
auto &el : llvm::reverse(llvm::drop_end(ctx))) {
2769 type =
m_index->tpi().getType(ti);
2770 switch (type.kind()) {
2790std::optional<llvm::StringRef>
2795 return std::nullopt;
2798 if (sym_record.kind() != S_LPROC32 && sym_record.kind() != S_GPROC32)
2799 return std::nullopt;
2801 ProcSym proc(
static_cast<SymbolRecordKind
>(sym_record.kind()));
2802 cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym_record, proc));
2808std::optional<llvm::StringRef>
2810 TypeIndex function_type) {
2811 auto symbol =
m_index->publics().findByAddress(
m_index->symrecords(),
2814 return std::nullopt;
2816 llvm::StringRef name = symbol->first.Name;
2819 if (!function_type.isNoneType() &&
2820 (symbol->first.Flags & PublicSymFlags::Function) != PublicSymFlags::None)
2837 if (!mangled.starts_with(
'_') ||
2838 m_index->dbi().getMachineType() != PDB_Machine::x86)
2842 PDB_CallingConv cc = PDB_CallingConv::NearC;
2843 if (cvt.kind() == LF_PROCEDURE) {
2844 ProcedureRecord proc;
2845 if (llvm::Error
error =
2846 TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, proc))
2847 llvm::consumeError(std::move(
error));
2849 }
else if (cvt.kind() == LF_MFUNCTION) {
2850 MemberFunctionRecord mfunc;
2851 if (llvm::Error
error =
2852 TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfunc))
2853 llvm::consumeError(std::move(
error));
2854 cc = mfunc.CallConv;
2861 if (cc == PDB_CallingConv::NearC || cc == PDB_CallingConv::FarC)
2862 return mangled.drop_front();
2868 for (CVType cvt :
m_index->ipi().typeArray()) {
2869 switch (cvt.kind()) {
2870 case LF_UDT_SRC_LINE: {
2871 UdtSourceLineRecord udt_src;
2872 llvm::cantFail(TypeDeserializer::deserializeAs(cvt, udt_src));
2876 udt_src.LineNumber});
2878 case LF_UDT_MOD_SRC_LINE: {
2879 UdtModSourceLineRecord udt_mod_src;
2880 llvm::cantFail(TypeDeserializer::deserializeAs(cvt, udt_mod_src));
2888 udt_mod_src.LineNumber});
2896llvm::Expected<Declaration>
2902 return llvm::createStringError(
"No UDT declaration found");
2904 llvm::StringRef file_name;
2905 if (it->second.IsIpiIndex) {
2906 CVType cvt =
m_index->ipi().getType(it->second.FileNameIndex);
2907 if (cvt.kind() != LF_STRING_ID)
2908 return llvm::createStringError(
"File name was not a LF_STRING_ID");
2911 llvm::cantFail(TypeDeserializer::deserializeAs(cvt, sid));
2912 file_name = sid.String;
2915 auto string_table =
m_index->pdb().getStringTable();
2917 return string_table.takeError();
2919 llvm::Expected<llvm::StringRef>
string =
2920 string_table->getStringTable().getString(
2921 it->second.FileNameIndex.getIndex());
2923 return string.takeError();
2924 file_name = *string;
2928 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 IsFunctionEpilogue(const CompilandIndexItem &cci, lldb::addr_t addr)
static bool NeedsResolvedCompileUnit(uint32_t resolve_scope)
static std::optional< std::string > findMatchingPDBFilePath(llvm::StringRef original_pdb_path, llvm::StringRef exe_path)
static bool IsFunctionPrologue(const CompilandIndexItem &cci, lldb::addr_t addr)
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)
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.
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.
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.
const ConstString & 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.
virtual std::recursive_mutex & GetModuleMutex() const
Symbols file subclasses should override this to return the Module that owns the TypeSystem that this ...
void SetByteSize(lldb::addr_t size)
Symbol * SymbolAtIndex(size_t idx)
uint32_t AddSymbol(const Symbol &symbol)
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
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
lldb::VariableSP GetOrCreateLocalVariable(PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param)
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::optional< llvm::StringRef > FindMangledFunctionName(PdbCompilandSymId id)
Find the mangled name for a function.
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
llvm::DenseMap< lldb::user_id_t, lldb::VariableSP > m_local_variables
~SymbolFileNativePDB() override
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)
void AddSymbols(Symtab &symtab) override
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::VariableSP CreateLocalVariable(PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param)
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::addr_t m_obj_load_address
size_t ParseBlocksRecursive(Function &func) override
std::once_flag m_cached_udt_declarations
void CacheUdtDeclarations()
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)
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)
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
llvm::DenseMap< lldb::user_id_t, lldb::FunctionSP > m_functions
bool ParseImportedModules(const SymbolContext &sc, std::vector< lldb_private::SourceModule > &imported_modules) override
llvm::StringRef StripMangledFunctionName(llvm::StringRef mangled, PdbTypeSymId func_ty)
static void DebuggerInitialize(Debugger &debugger)
llvm::DenseMap< lldb::user_id_t, std::shared_ptr< InlineSite > > m_inline_sites
void ParseInlineSite(PdbCompilandSymId inline_site_id, Address func_addr)
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)
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.
uint32_t ResolveSymbolContext(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc) override
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)
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 MakeConstantLocationExpression(llvm::codeview::TypeIndex underlying_ti, llvm::pdb::TpiStream &tpi, const llvm::APSInt &constant, 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
std::shared_ptr< lldb_private::VariableList > VariableListSP
std::shared_ptr< lldb_private::SymbolFileType > SymbolFileTypeSP
std::shared_ptr< lldb_private::Variable > VariableSP
std::shared_ptr< lldb_private::Section > SectionSP
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
@ eValueTypeVariableGlobal
globals variable
@ eValueTypeVariableLocal
function local variables
@ eValueTypeVariableArgument
function argument variables
@ eValueTypeVariableStatic
static variable
@ eValueTypeVariableThreadLocal
thread local storage variable
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