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::unique_ptr<PDBFile>
92 using namespace llvm::object;
93 auto expected_binary = createBinary(exe_path);
96 if (!expected_binary) {
97 llvm::consumeError(expected_binary.takeError());
100 OwningBinary<Binary> binary = std::move(*expected_binary);
104 auto *obj = llvm::dyn_cast<llvm::object::COFFObjectFile>(binary.getBinary());
107 const llvm::codeview::DebugInfo *pdb_info =
nullptr;
110 llvm::StringRef pdb_file;
111 if (llvm::Error e = obj->getDebugPDBInfo(pdb_info, pdb_file)) {
112 consumeError(std::move(e));
122 pdb_file = exe_dir.CopyByAppendingPathComponent(pdb_name).GetPathAsConstString().GetStringRef();
130 auto expected_info =
pdb->getPDBInfoStream();
131 if (!expected_info) {
132 llvm::consumeError(expected_info.takeError());
135 llvm::codeview::GUID guid;
136 memcpy(&guid, pdb_info->PDB70.Signature, 16);
138 if (expected_info->getGuid() != guid)
162 case SimpleTypeKind::Boolean128:
164 case SimpleTypeKind::Boolean64:
166 case SimpleTypeKind::Boolean32:
168 case SimpleTypeKind::Boolean16:
170 case SimpleTypeKind::Boolean8:
173 case SimpleTypeKind::Byte:
174 case SimpleTypeKind::UnsignedCharacter:
175 return "unsigned char";
176 case SimpleTypeKind::NarrowCharacter:
178 case SimpleTypeKind::SignedCharacter:
179 case SimpleTypeKind::SByte:
180 return "signed char";
181 case SimpleTypeKind::Character32:
183 case SimpleTypeKind::Character16:
185 case SimpleTypeKind::Character8:
188 case SimpleTypeKind::Complex128:
189 return "_Complex __float128";
190 case SimpleTypeKind::Complex80:
191 return "_Complex long double";
192 case SimpleTypeKind::Complex64:
193 return "_Complex double";
194 case SimpleTypeKind::Complex48:
195 return "_Complex __float48";
196 case SimpleTypeKind::Complex32:
197 case SimpleTypeKind::Complex32PartialPrecision:
198 return "_Complex float";
199 case SimpleTypeKind::Complex16:
200 return "_Complex _Float16";
202 case SimpleTypeKind::Float128:
204 case SimpleTypeKind::Float80:
205 return "long double";
206 case SimpleTypeKind::Float64:
208 case SimpleTypeKind::Float48:
210 case SimpleTypeKind::Float32:
211 case SimpleTypeKind::Float32PartialPrecision:
213 case SimpleTypeKind::Float16:
216 case SimpleTypeKind::Int128Oct:
217 case SimpleTypeKind::Int128:
219 case SimpleTypeKind::Int64:
220 case SimpleTypeKind::Int64Quad:
222 case SimpleTypeKind::Int32Long:
224 case SimpleTypeKind::Int32:
226 case SimpleTypeKind::Int16:
227 case SimpleTypeKind::Int16Short:
230 case SimpleTypeKind::UInt128Oct:
231 case SimpleTypeKind::UInt128:
232 return "unsigned __int128";
233 case SimpleTypeKind::UInt64:
234 case SimpleTypeKind::UInt64Quad:
235 return "unsigned long long";
236 case SimpleTypeKind::UInt32:
238 case SimpleTypeKind::UInt16:
239 case SimpleTypeKind::UInt16Short:
240 return "unsigned short";
241 case SimpleTypeKind::UInt32Long:
242 return "unsigned long";
244 case SimpleTypeKind::HResult:
246 case SimpleTypeKind::Void:
248 case SimpleTypeKind::WideCharacter:
251 case SimpleTypeKind::None:
252 case SimpleTypeKind::NotTranslated:
269static std::optional<CVTagRecord>
288 if (Record.Type.isSimple())
291 CVType cvt = tpi.getType(Record.Type);
300 std::string qname = std::string(parent.
asTag().getUniqueName());
301 if (qname.size() < 4 || child.
asTag().getUniqueName().size() < 4)
307 qname[3] = child.
asTag().getUniqueName()[3];
311 piece += Record.Name;
312 piece.push_back(
'@');
313 qname.insert(4, std::move(piece));
314 if (qname != child.
asTag().UniqueName)
317 return std::move(child);
333 return "Microsoft PDB debug symbol cross-platform file reader.";
349 uint32_t abilities = 0;
357 pdb_file = &
pdb->GetPDBFile();
368 if (!expected_index) {
369 llvm::consumeError(expected_index.takeError());
372 m_index = std::move(*expected_index);
381 if (
m_index->dbi().isStripped())
392 m_index->ParseSectionContribs();
394 auto ts_or_err =
m_objfile_sp->GetModule()->GetTypeSystemForLanguage(
396 if (
auto err = ts_or_err.takeError()) {
398 "Failed to initialize: {0}");
400 if (
auto ts = *ts_or_err)
401 ts->SetSymbolFile(
this);
407 const DbiModuleList &modules =
m_index->dbi().modules();
408 uint32_t count = modules.getModuleCount();
415 DbiModuleDescriptor last = modules.getModuleDescriptor(count - 1);
416 if (last.getModuleName() ==
"* Linker *")
427 if (
auto err = ts_or_err.takeError())
429 auto ts = *ts_or_err;
434 switch (sym.kind()) {
440 return &func->GetBlock(
false);
447 BlockSym block(
static_cast<SymbolRecordKind
>(sym.kind()));
448 cantFail(SymbolDeserializer::deserializeAs<BlockSym>(sym, block));
457 m_index->MakeVirtualAddress(block.Segment, block.CodeOffset);
460 if (block_base >= func_base)
461 child_block->AddRange(
Block::Range(block_base - func_base, block.CodeSize));
464 "S_BLOCK32 at modi: {0:d} offset: {1:d}: adding range "
465 "[{2:x16}-{3:x16}) which has a base that is less than the "
467 "low PC 0x%" PRIx64
". Please file a bug and attach the file at the "
468 "start of this error message",
470 block_base + block.CodeSize, func_base);
473 m_blocks.insert({opaque_block_uid, child_block});
478 comp_unit->GetLineTable();
480 std::shared_ptr<InlineSite> inline_site =
m_inline_sites[opaque_block_uid];
487 for (
size_t i = 0; i < inline_site->ranges.GetSize(); ++i) {
488 auto *entry = inline_site->ranges.GetEntryAtIndex(i);
489 child_block->AddRange(
490 Block::Range(entry->GetRangeBase(), entry->GetByteSize()));
492 child_block->FinalizeRanges();
495 Declaration &decl = inline_site->inline_function_info->GetDeclaration();
496 Declaration &callsite = inline_site->inline_function_info->GetCallSite();
497 child_block->SetInlinedFunctionInfo(
498 inline_site->inline_function_info->GetName().GetCString(),
nullptr,
500 m_blocks.insert({opaque_block_uid, child_block});
504 lldbassert(
false &&
"Symbol is not a block!");
517 lldbassert(sym_record.kind() == S_LPROC32 || sym_record.kind() == S_GPROC32);
529 ProcSym proc(
static_cast<SymbolRecordKind
>(sym_record.kind()));
530 cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym_record, proc));
531 if (proc.FunctionType == TypeIndex::None())
540 SegmentOffset(proc.Segment, proc.CodeOffset), proc.FunctionType);
541 Mangled mangled(mangled_opt.value_or(proc.Name));
543 FunctionSP func_sp = std::make_shared<Function>(
545 func_type.get(), func_addr,
551 if (
auto err = ts_or_err.takeError())
553 auto ts = *ts_or_err;
556 ts->GetNativePDBParser()->GetOrCreateFunctionDecl(func_id);
571 llvm::SmallString<64> source_file_name =
572 m_index->compilands().GetMainSourceFile(cci);
573 FileSpec fs(llvm::sys::path::convert_to_slash(
574 source_file_name, llvm::sys::path::Style::windows_backslash));
576 CompUnitSP cu_sp = std::make_shared<CompileUnit>(
577 m_objfile_sp->GetModule(),
nullptr, std::make_shared<SupportFile>(fs),
585 const ModifierRecord &mr,
587 TpiStream &stream =
m_index->tpi();
591 if ((mr.Modifiers & ModifierOptions::Const) != ModifierOptions::None)
593 if ((mr.Modifiers & ModifierOptions::Volatile) != ModifierOptions::None)
595 if ((mr.Modifiers & ModifierOptions::Unaligned) != ModifierOptions::None)
596 name +=
"__unaligned ";
598 if (mr.ModifiedType.isSimple())
601 name += computeTypeName(stream.typeCollection(), mr.ModifiedType);
606 llvm::expectedToOptional(modified_type->GetByteSize(
nullptr)),
613 const llvm::codeview::PointerRecord &pr,
619 if (pr.isPointerToMember()) {
620 MemberPointerInfo mpi = pr.getMemberInfo();
633 if (ti == TypeIndex::NullptrT()) {
640 if (ti.getSimpleMode() != SimpleTypeMode::Direct) {
642 uint32_t pointer_size = 0;
643 switch (ti.getSimpleMode()) {
644 case SimpleTypeMode::FarPointer32:
645 case SimpleTypeMode::NearPointer32:
648 case SimpleTypeMode::NearPointer64:
660 if (ti.getSimpleKind() == SimpleTypeKind::NotTranslated)
672 if (!record.hasUniqueName())
675 llvm::ms_demangle::Demangler demangler;
676 std::string_view sv(record.UniqueName.begin(), record.UniqueName.size());
677 llvm::ms_demangle::TagTypeNode *ttn = demangler.parseTagUniqueName(sv);
681 llvm::ms_demangle::IdentifierNode *idn =
682 ttn->QualifiedName->getUnqualifiedIdentifier();
683 return idn->toString();
688 const TagRecord &record,
696 decl = std::move(*maybeDecl);
699 "Failed to resolve declaration for '{1}': {0}", uname);
707 const ClassRecord &cr,
713 const UnionRecord &ur,
719 const EnumRecord &er,
726 decl = std::move(*maybeDecl);
729 "Failed to resolve declaration for '{1}': {0}", uname);
735 llvm::expectedToOptional(underlying_type->GetByteSize(
nullptr)),
nullptr,
741 const ArrayRecord &ar,
750 array_sp->SetEncodingType(element_type.get());
755 const MemberFunctionRecord &mfr,
764 const ProcedureRecord &pr,
773 if (type_id.
index.isSimple())
777 CVType cvt = stream.getType(type_id.
index);
779 if (cvt.kind() == LF_MODIFIER) {
780 ModifierRecord modifier;
782 TypeDeserializer::deserializeAs<ModifierRecord>(cvt, modifier));
786 if (cvt.kind() == LF_POINTER) {
787 PointerRecord pointer;
789 TypeDeserializer::deserializeAs<PointerRecord>(cvt, pointer));
795 llvm::cantFail(TypeDeserializer::deserializeAs<ClassRecord>(cvt, cr));
799 if (cvt.kind() == LF_ENUM) {
801 llvm::cantFail(TypeDeserializer::deserializeAs<EnumRecord>(cvt, er));
805 if (cvt.kind() == LF_UNION) {
807 llvm::cantFail(TypeDeserializer::deserializeAs<UnionRecord>(cvt, ur));
811 if (cvt.kind() == LF_ARRAY) {
813 llvm::cantFail(TypeDeserializer::deserializeAs<ArrayRecord>(cvt, ar));
817 if (cvt.kind() == LF_PROCEDURE) {
819 llvm::cantFail(TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, pr));
822 if (cvt.kind() == LF_MFUNCTION) {
823 MemberFunctionRecord mfr;
824 llvm::cantFail(TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfr));
834 std::optional<PdbTypeSymId> full_decl_uid;
836 auto expected_full_ti =
837 m_index->tpi().findFullDeclForForwardRef(type_id.
index);
838 if (!expected_full_ti)
839 llvm::consumeError(expected_full_ti.takeError());
840 else if (*expected_full_ti != type_id.
index) {
848 if (full_iter !=
m_types.end()) {
849 TypeSP result = full_iter->second;
858 PdbTypeSymId best_decl_id = full_decl_uid ? *full_decl_uid : type_id;
860 if (
auto err = ts_or_err.takeError())
862 auto ts = *ts_or_err;
900 CVSymbol sym =
m_index->symrecords().readRecord(var_id.
offset);
901 if (sym.kind() == S_CONSTANT)
906 llvm::StringRef name;
908 uint16_t section = 0;
910 bool is_external =
false;
911 switch (sym.kind()) {
916 DataSym ds(sym.kind());
917 llvm::cantFail(SymbolDeserializer::deserializeAs<DataSym>(sym, ds));
922 section = ds.Segment;
923 offset = ds.DataOffset;
924 addr =
m_index->MakeVirtualAddress(ds.Segment, ds.DataOffset);
931 ThreadLocalDataSym tlds(sym.kind());
933 SymbolDeserializer::deserializeAs<ThreadLocalDataSym>(sym, tlds));
936 section = tlds.Segment;
937 offset = tlds.DataOffset;
938 addr =
m_index->MakeVirtualAddress(tlds.Segment, tlds.DataOffset);
943 llvm_unreachable(
"unreachable!");
947 std::optional<uint16_t> modi =
m_index->GetModuleIndexForVa(addr);
958 std::make_shared<SymbolFileType>(*
this,
toOpaqueUid(tid));
961 if (
auto err = ts_or_err.takeError())
963 auto ts = *ts_or_err;
967 ts->GetNativePDBParser()->GetOrCreateVariableDecl(var_id);
974 std::string global_name(
"::");
976 bool artificial =
false;
977 bool location_is_constant_data =
false;
978 bool static_member =
false;
979 VariableSP var_sp = std::make_shared<Variable>(
980 toOpaqueUid(var_id), name.str().c_str(), global_name.c_str(), type_sp,
981 scope, comp_unit.get(), ranges, &decl, location, is_external, artificial,
982 location_is_constant_data, static_member);
989 const CVSymbol &cvs) {
990 TpiStream &tpi =
m_index->tpi();
991 ConstantSym constant(cvs.kind());
993 llvm::cantFail(SymbolDeserializer::deserializeAs<ConstantSym>(cvs, constant));
994 std::string global_name(
"::");
995 global_name += constant.Name;
998 std::make_shared<SymbolFileType>(*
this,
toOpaqueUid(tid));
1005 constant.Type, tpi, constant.Value, module),
1008 bool external =
false;
1009 bool artificial =
false;
1010 bool location_is_constant_data =
true;
1011 bool static_member =
false;
1012 VariableSP var_sp = std::make_shared<Variable>(
1013 toOpaqueUid(var_id), constant.Name.str().c_str(), global_name.c_str(),
1015 external, artificial, location_is_constant_data, static_member);
1022 if (emplace_result.second) {
1024 emplace_result.first->second = var_sp;
1029 return emplace_result.first->second;
1039 if (emplace_result.second)
1040 emplace_result.first->second =
CreateFunction(func_id, comp_unit);
1042 return emplace_result.first->second;
1048 auto emplace_result =
1050 if (emplace_result.second)
1054 return emplace_result.first->second;
1060 return iter->second.get();
1081 if (index >= UINT16_MAX)
1108 for (
auto pid :
m_index->publics().getPublicsTable()) {
1110 CVSymbol sym =
m_index->ReadSymbolRecord(global);
1111 auto kind = sym.kind();
1112 if (kind != S_PUB32)
1115 llvm::cantFail(SymbolDeserializer::deserializeAs<PublicSym32>(sym));
1117 auto section_sp = section_list->FindSectionByID(pub.Segment);
1122 if ((pub.Flags & PublicSymFlags::Function) != PublicSymFlags::None ||
1123 (pub.Flags & PublicSymFlags::Code) != PublicSymFlags::None)
1151 for (
auto iter = syms.begin(); iter != syms.end(); ++iter) {
1152 if (iter->kind() != S_LPROC32 && iter->kind() != S_GPROC32)
1162 return new_count - count;
1167 uint32_t flags = eSymbolContextCompUnit;
1168 flags |= eSymbolContextVariable;
1169 flags |= eSymbolContextFunction;
1170 flags |= eSymbolContextBlock;
1171 flags |= eSymbolContextLineEntry;
1172 return (resolve_scope & flags) != 0;
1176 const Address &addr, SymbolContextItem resolve_scope, SymbolContext &sc) {
1178 uint32_t resolved_flags = 0;
1182 std::optional<uint16_t> modi =
m_index->GetModuleIndexForVa(file_addr);
1190 resolved_flags |= eSymbolContextCompUnit;
1193 if (resolve_scope & eSymbolContextFunction ||
1194 resolve_scope & eSymbolContextBlock) {
1196 std::vector<SymbolAndUid> matches =
m_index->FindSymbolsByVa(file_addr);
1200 for (
const auto &match : llvm::reverse(matches)) {
1204 PdbCompilandSymId csid = match.uid.asCompilandSym();
1205 CVSymbol cvs =
m_index->ReadSymbolRecord(csid);
1207 if (type != PDB_SymType::Function && type != PDB_SymType::Block)
1209 if (type == PDB_SymType::Function) {
1214 addr_t offset = file_addr - func_base;
1219 if (type == PDB_SymType::Block) {
1227 addr_t offset = file_addr - func_base;
1232 resolved_flags |= eSymbolContextFunction;
1234 resolved_flags |= eSymbolContextBlock;
1239 if (resolve_scope & eSymbolContextLineEntry) {
1242 if (line_table->FindLineEntryByAddress(addr, sc.
line_entry))
1243 resolved_flags |= eSymbolContextLineEntry;
1247 return resolved_flags;
1254 const uint32_t prev_size = sc_list.
GetSize();
1255 if (resolve_scope & eSymbolContextCompUnit) {
1264 if (file_spec_matches_cu_file_spec) {
1270 return sc_list.
GetSize() - prev_size;
1289 std::set<LineTable::Entry, LineTableEntryComparator> line_set;
1294 for (
const DebugSubsectionRecord &dssr :
1296 if (dssr.kind() != DebugSubsectionKind::Lines)
1299 DebugLinesSubsectionRef lines;
1300 llvm::BinaryStreamReader reader(dssr.getRecordData());
1301 if (
auto EC = lines.initialize(reader)) {
1302 llvm::consumeError(std::move(EC));
1306 const LineFragmentHeader *lfh = lines.header();
1307 uint64_t virtual_addr =
1308 m_index->MakeVirtualAddress(lfh->RelocSegment, lfh->RelocOffset);
1312 for (
const LineColumnEntry &group : lines) {
1313 llvm::Expected<uint32_t> file_index_or_err =
1315 if (!file_index_or_err)
1317 uint32_t file_index = file_index_or_err.get();
1321 for (
const LineNumberEntry &entry : group.LineNumbers) {
1322 LineInfo cur_info(entry.Flags);
1324 if (cur_info.isAlwaysStepInto() || cur_info.isNeverStepInto())
1327 uint64_t addr = virtual_addr + entry.Offset;
1329 bool is_statement = cur_info.isStatement();
1333 uint32_t lno = cur_info.getStartLine();
1336 is_prologue, is_epilogue,
false);
1338 auto iter = line_set.find(new_entry);
1339 if (iter != line_set.end() && iter->is_terminal_entry)
1340 line_set.erase(iter);
1341 line_set.insert(new_entry);
1348 line_entry.
data = {file_index, lno};
1350 LineInfo last_line(group.LineNumbers.back().Flags);
1351 line_set.emplace(virtual_addr + lfh->CodeSize, last_line.getEndLine(), 0,
1352 file_index,
false,
false,
false,
false,
true);
1355 line_entry.
SetRangeEnd(virtual_addr + lfh->CodeSize);
1364 const CVSymbolArray &syms = cii->
m_debug_stream.getSymbolArray();
1365 for (
auto iter = syms.begin(); iter != syms.end();) {
1366 if (iter->kind() != S_LPROC32 && iter->kind() != S_GPROC32) {
1371 uint32_t record_offset = iter.offset();
1372 CVSymbol func_record =
1385 if (kind != S_INLINESITE)
1390 for (
const auto &line_entry :
1395 if (!line_entry.is_terminal_entry)
1396 line_set.erase(line_entry);
1397 line_set.insert(line_entry);
1405 iter = syms.at(getScopeEndOffset(func_record));
1411 std::vector<LineTable::Sequence> sequence(1);
1412 for (
const auto &line_entry : line_set) {
1414 sequence.back(), line_entry.file_addr, line_entry.line,
1415 line_entry.column, line_entry.file_idx,
1416 line_entry.is_start_of_statement, line_entry.is_start_of_basic_block,
1417 line_entry.is_prologue_end, line_entry.is_epilogue_begin,
1418 line_entry.is_terminal_entry);
1421 std::make_unique<LineTable>(&comp_unit, std::move(sequence));
1423 if (line_table->GetSize() == 0)
1435llvm::Expected<uint32_t>
1439 return llvm::make_error<RawError>(raw_error_code::no_entry);
1441 const auto &checksums = cii.
m_strings.checksums().getArray();
1442 const auto &strings = cii.
m_strings.strings();
1446 auto iter = checksums.at(file_id);
1447 if (iter == checksums.end())
1448 return llvm::make_error<RawError>(raw_error_code::no_entry);
1450 llvm::Expected<llvm::StringRef> efn = strings.getString(iter->FileNameOffset);
1452 return efn.takeError();
1458 return std::distance(cii.
m_file_list.begin(), fn_iter);
1459 return llvm::make_error<RawError>(raw_error_code::no_entry);
1473 f.starts_with(
"/") ? FileSpec::Style::posix : FileSpec::Style::windows;
1475 support_files.
Append(spec);
1481 const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
1494 CVSymbol sym = cii->
m_debug_stream.readSymbolAtOffset(
id.offset);
1497 InlineSiteSym inline_site(
static_cast<SymbolRecordKind
>(sym.kind()));
1498 cantFail(SymbolDeserializer::deserializeAs<InlineSiteSym>(sym, inline_site));
1501 std::shared_ptr<InlineSite> inline_site_sp =
1502 std::make_shared<InlineSite>(parent_id);
1505 auto iter = cii->
m_inline_map.find(inline_site.Inlinee);
1508 InlineeSourceLine inlinee_line = iter->second;
1512 llvm::Expected<uint32_t> file_index_or_err =
1514 if (!file_index_or_err)
1516 uint32_t file_offset = file_index_or_err.get();
1518 uint32_t decl_line = inlinee_line.Header->SourceLineNum;
1519 std::unique_ptr<Declaration> decl_up =
1520 std::make_unique<Declaration>(decl_file, decl_line);
1523 uint32_t code_offset = 0;
1524 int32_t line_offset = 0;
1525 std::optional<uint32_t> code_offset_base;
1526 std::optional<uint32_t> code_offset_end;
1527 std::optional<int32_t> cur_line_offset;
1528 std::optional<int32_t> next_line_offset;
1529 std::optional<uint32_t> next_file_offset;
1531 bool is_terminal_entry =
false;
1532 bool is_start_of_statement =
true;
1534 bool is_prologue_end =
true;
1536 auto update_code_offset = [&](uint32_t code_delta) {
1537 if (!code_offset_base)
1538 code_offset_base = code_offset;
1539 else if (!code_offset_end)
1540 code_offset_end = *code_offset_base + code_delta;
1542 auto update_line_offset = [&](int32_t line_delta) {
1543 line_offset += line_delta;
1544 if (!code_offset_base || !cur_line_offset)
1545 cur_line_offset = line_offset;
1547 next_line_offset = line_offset;
1550 auto update_file_offset = [&](uint32_t offset) {
1551 if (!code_offset_base)
1552 file_offset = offset;
1554 next_file_offset = offset;
1557 for (
auto &annot : inline_site.annotations()) {
1558 switch (annot.OpCode) {
1559 case BinaryAnnotationsOpCode::CodeOffset:
1560 case BinaryAnnotationsOpCode::ChangeCodeOffset:
1561 case BinaryAnnotationsOpCode::ChangeCodeOffsetBase:
1562 code_offset += annot.U1;
1563 update_code_offset(annot.U1);
1565 case BinaryAnnotationsOpCode::ChangeLineOffset:
1566 update_line_offset(annot.S1);
1568 case BinaryAnnotationsOpCode::ChangeCodeLength:
1569 update_code_offset(annot.U1);
1570 code_offset += annot.U1;
1571 is_terminal_entry =
true;
1573 case BinaryAnnotationsOpCode::ChangeCodeOffsetAndLineOffset:
1574 code_offset += annot.U1;
1575 update_code_offset(annot.U1);
1576 update_line_offset(annot.S1);
1578 case BinaryAnnotationsOpCode::ChangeCodeLengthAndCodeOffset:
1579 code_offset += annot.U2;
1580 update_code_offset(annot.U2);
1581 update_code_offset(annot.U1);
1582 code_offset += annot.U1;
1583 is_terminal_entry =
true;
1585 case BinaryAnnotationsOpCode::ChangeFile:
1586 update_file_offset(annot.U1);
1593 if (code_offset_base && code_offset_end && cur_line_offset) {
1595 *code_offset_base, *code_offset_end - *code_offset_base,
1596 decl_line + *cur_line_offset));
1598 if (next_file_offset)
1599 file_offset = *next_file_offset;
1600 if (next_line_offset) {
1601 cur_line_offset = next_line_offset;
1602 next_line_offset = std::nullopt;
1604 code_offset_base = is_terminal_entry ? std::nullopt : code_offset_end;
1605 code_offset_end = next_file_offset = std::nullopt;
1607 if (code_offset_base && cur_line_offset) {
1608 if (is_terminal_entry) {
1610 func_base + *code_offset_base, decl_line + *cur_line_offset, 0,
1611 file_offset,
false,
false,
false,
false,
true);
1612 inline_site_sp->line_entries.push_back(line_entry);
1615 decl_line + *cur_line_offset, 0,
1616 file_offset, is_start_of_statement,
false,
1617 is_prologue_end,
false,
false);
1618 inline_site_sp->line_entries.push_back(line_entry);
1619 is_prologue_end =
false;
1620 is_start_of_statement =
false;
1623 if (is_terminal_entry)
1624 is_start_of_statement =
true;
1625 is_terminal_entry =
false;
1628 inline_site_sp->ranges.Sort();
1631 std::unique_ptr<Declaration> callsite_up;
1632 if (!inline_site_sp->ranges.IsEmpty()) {
1633 auto *entry = inline_site_sp->ranges.GetEntryAtIndex(0);
1634 addr_t base_offset = entry->GetRangeBase();
1640 std::shared_ptr<InlineSite> parent_site =
1643 parent_site->inline_function_info->GetDeclaration().GetFile();
1644 if (
auto *parent_entry =
1645 parent_site->ranges.FindEntryThatContains(base_offset)) {
1647 std::make_unique<Declaration>(parent_decl_file, parent_entry->data);
1652 func_base + base_offset)) {
1656 std::make_unique<Declaration>(callsite_file, entry->data.second);
1662 CVType inlinee_cvt =
m_index->ipi().getType(inline_site.Inlinee);
1663 std::string inlinee_name;
1664 if (inlinee_cvt.kind() == LF_MFUNC_ID) {
1665 MemberFuncIdRecord mfr;
1667 TypeDeserializer::deserializeAs<MemberFuncIdRecord>(inlinee_cvt, mfr));
1668 LazyRandomTypeCollection &types =
m_index->tpi().typeCollection();
1669 inlinee_name.append(std::string(types.getTypeName(mfr.ClassType)));
1670 inlinee_name.append(
"::");
1671 inlinee_name.append(mfr.getName().str());
1672 }
else if (inlinee_cvt.kind() == LF_FUNC_ID) {
1674 cantFail(TypeDeserializer::deserializeAs<FuncIdRecord>(inlinee_cvt, fir));
1675 TypeIndex parent_idx = fir.getParentScope();
1676 if (!parent_idx.isNoneType()) {
1677 LazyRandomTypeCollection &ids =
m_index->ipi().typeCollection();
1678 inlinee_name.append(std::string(ids.getTypeName(parent_idx)));
1679 inlinee_name.append(
"::");
1681 inlinee_name.append(fir.getName().str());
1683 inline_site_sp->inline_function_info = std::make_shared<InlineFunctionInfo>(
1684 inlinee_name.c_str(), llvm::StringRef(), decl_up.get(),
1695 std::set<uint64_t> remove_uids;
1697 if (kind == S_GPROC32 || kind == S_LPROC32 || kind == S_BLOCK32 ||
1698 kind == S_INLINESITE) {
1700 if (kind == S_INLINESITE)
1707 for (uint64_t uid : remove_uids) {
1719 CVSymbolArray syms =
1723 for (
auto iter = syms.begin(); iter != syms.end(); ++iter) {
1725 if (fn(iter->kind(), child_id))
1737 auto ts = *ts_or_err;
1741 clang->GetNativePDBParser()->Dump(s, filter, show_color);
1749 std::map<std::pair<uint16_t, uint32_t>, uint32_t> func_addr_ids;
1752 for (
const uint32_t gid :
m_index->globals().getGlobalsTable()) {
1753 CVSymbol sym =
m_index->symrecords().readRecord(gid);
1754 auto kind = sym.kind();
1757 llvm::StringRef name;
1759 case SymbolKind::S_GDATA32:
1760 case SymbolKind::S_LDATA32: {
1762 llvm::cantFail(SymbolDeserializer::deserializeAs<DataSym>(sym));
1766 case SymbolKind::S_GTHREAD32:
1767 case SymbolKind::S_LTHREAD32: {
1768 ThreadLocalDataSym data = llvm::cantFail(
1769 SymbolDeserializer::deserializeAs<ThreadLocalDataSym>(sym));
1773 case SymbolKind::S_CONSTANT: {
1775 llvm::cantFail(SymbolDeserializer::deserializeAs<ConstantSym>(sym));
1783 if (!name.empty()) {
1792 if (kind != S_PROCREF && kind != S_LPROCREF)
1799 llvm::cantFail(SymbolDeserializer::deserializeAs<ProcRefSym>(sym));
1800 if (ref.Name.empty())
1805 m_index->compilands().GetOrCreateCompiland(ref.modi());
1806 auto iter = cci.
m_debug_stream.getSymbolArray().at(ref.SymOffset);
1809 kind = iter->kind();
1810 if (kind != S_GPROC32 && kind != S_LPROC32)
1814 llvm::cantFail(SymbolDeserializer::deserializeAs<ProcSym>(*iter));
1815 if ((proc.Flags & ProcSymFlags::IsUnreachable) != ProcSymFlags::None)
1817 if (proc.Name.empty() || proc.FunctionType.isSimple())
1823 func_addr_ids.emplace(std::make_pair(proc.Segment, proc.CodeOffset), gid);
1826 if (basename.empty())
1827 basename = proc.Name;
1833 auto type =
m_index->tpi().getType(proc.FunctionType);
1834 if (type.kind() == LF_MFUNCTION) {
1835 MemberFunctionRecord mfr;
1837 TypeDeserializer::deserializeAs<MemberFunctionRecord>(type, mfr));
1838 if (!mfr.getThisType().isNoneType())
1844 for (
auto pid :
m_index->publics().getPublicsTable()) {
1846 CVSymbol sym =
m_index->ReadSymbolRecord(global);
1847 auto kind = sym.kind();
1848 if (kind != S_PUB32)
1851 llvm::cantFail(SymbolDeserializer::deserializeAs<PublicSym32>(sym));
1858 auto it = func_addr_ids.find({pub.Segment, pub.Offset});
1859 if (it != func_addr_ids.end())
1881 std::vector<uint32_t> results;
1884 size_t n_matches = 0;
1885 for (uint32_t gid : results) {
1888 if (parent_decl_ctx.
IsValid() &&
1897 if (++n_matches >= max_matches)
1909 if (name_type_mask & eFunctionNameTypeFull)
1912 if (!(name_type_mask & eFunctionNameTypeFull ||
1913 name_type_mask & eFunctionNameTypeBase ||
1914 name_type_mask & eFunctionNameTypeMethod))
1918 std::set<uint32_t> resolved_ids;
1920 std::vector<uint32_t> ids;
1921 if (!Names.GetValues(name, ids))
1924 for (uint32_t
id : ids) {
1925 if (!resolved_ids.insert(
id).second)
1929 if (parent_decl_ctx.
IsValid() &&
1933 CVSymbol sym =
m_index->ReadSymbolRecord(global);
1934 auto kind = sym.kind();
1935 lldbassert(kind == S_PROCREF || kind == S_LPROCREF);
1938 cantFail(SymbolDeserializer::deserializeAs<ProcRefSym>(sym));
1944 m_index->compilands().GetOrCreateCompiland(proc.modi());
1960 if (name_type_mask & eFunctionNameTypeFull)
1962 if (name_type_mask & eFunctionNameTypeBase)
1964 if (name_type_mask & eFunctionNameTypeMethod)
1969 bool include_inlines,
1984 std::vector<uint32_t> matches;
1987 for (uint32_t match_idx : matches) {
1989 if (context.empty())
1998 if (results.
Done(query))
2005 uint32_t max_matches,
2008 std::vector<TypeIndex> matches =
m_index->tpi().findRecordsByName(name);
2009 if (max_matches > 0 && max_matches < matches.size())
2010 matches.resize(max_matches);
2012 for (TypeIndex ti : matches) {
2028 LazyRandomTypeCollection &types =
m_index->tpi().typeCollection();
2031 for (
auto ti = types.getFirst(); ti; ti = types.getNext(*ti)) {
2034 (void)type->GetFullCompilerType();
2038 for (
const uint32_t gid :
m_index->globals().getGlobalsTable()) {
2040 CVSymbol sym =
m_index->ReadSymbolRecord(global);
2041 if (sym.kind() != S_UDT)
2044 UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs<UDTSym>(sym));
2045 bool is_typedef =
true;
2047 CVType cvt =
m_index->tpi().getType(udt.Type);
2049 if (name == udt.Name)
2061 return new_count - old_count;
2069 for (
const uint32_t gid :
m_index->globals().getGlobalsTable()) {
2071 CVSymbol sym =
m_index->ReadSymbolRecord(global);
2076 switch (sym.kind()) {
2077 case SymbolKind::S_GDATA32:
2078 case SymbolKind::S_LDATA32:
2079 case SymbolKind::S_GTHREAD32:
2080 case SymbolKind::S_LTHREAD32: {
2101 Block *func_block = block;
2123 std::string name = var_info.
name.str();
2126 std::make_shared<SymbolFileType>(*
this, type_sp->GetID());
2131 bool external =
false;
2132 bool artificial =
false;
2133 bool location_is_constant_data =
false;
2134 bool static_member =
false;
2136 VariableSP var_sp = std::make_shared<Variable>(
2137 toOpaqueUid(var_id), name.c_str(), name.c_str(), sftype, var_scope, block,
2138 scope_ranges, &decl, var_info.
location, external, artificial,
2139 location_is_constant_data, static_member);
2142 if (
auto err = ts_or_err.takeError())
2144 auto ts = *ts_or_err;
2148 ts->GetNativePDBParser()->GetOrCreateVariableDecl(scope_id, var_id);
2158 return iter->second;
2164 CVSymbol sym =
m_index->ReadSymbolRecord(
id);
2167 UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs<UDTSym>(sym));
2172 if (
auto err = ts_or_err.takeError())
2174 auto ts = *ts_or_err;
2178 auto *typedef_decl = ts->GetNativePDBParser()->GetOrCreateTypedefDecl(
id);
2180 CompilerType ct = target_type->GetForwardCompilerType();
2181 if (
auto *
clang = llvm::dyn_cast_or_null<TypeSystemClang>(ts.get()))
2182 ct =
clang->GetType(
clang->getASTContext().getTypeDeclType(typedef_decl));
2186 llvm::expectedToOptional(target_type->GetByteSize(
nullptr)),
2187 nullptr, target_type->GetID(),
2195 return iter->second;
2209 uint32_t params_remaining = 0;
2210 switch (sym.kind()) {
2213 ProcSym proc(
static_cast<SymbolRecordKind
>(sym.kind()));
2214 cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym, proc));
2215 CVType signature =
m_index->tpi().getType(proc.FunctionType);
2216 if (signature.kind() == LF_PROCEDURE) {
2217 ProcedureRecord sig;
2218 if (llvm::Error e = TypeDeserializer::deserializeAs<ProcedureRecord>(
2220 llvm::consumeError(std::move(e));
2223 params_remaining = sig.getParameterCount();
2224 }
else if (signature.kind() == LF_MFUNCTION) {
2225 MemberFunctionRecord sig;
2226 if (llvm::Error e = TypeDeserializer::deserializeAs<MemberFunctionRecord>(
2228 llvm::consumeError(std::move(e));
2231 params_remaining = sig.getParameterCount();
2241 lldbassert(
false &&
"Symbol is not a block!");
2247 variables = std::make_shared<VariableList>();
2251 CVSymbolArray syms = limitSymbolArrayToScope(
2257 auto iter = syms.begin();
2258 auto end = syms.end();
2260 while (iter != end) {
2261 uint32_t record_offset = iter.offset();
2262 CVSymbol variable_cvs = *iter;
2268 if (variable_cvs.kind() == S_BLOCK32 ||
2269 variable_cvs.kind() == S_INLINESITE) {
2270 uint32_t block_end = getScopeEndOffset(variable_cvs);
2272 iter = syms.at(block_end);
2276 bool is_param = params_remaining > 0;
2278 switch (variable_cvs.kind()) {
2286 variables->AddVariableIfUnique(variable);
2322 variables = std::make_shared<VariableList>();
2328 llvm_unreachable(
"Unreachable!");
2333 if (
auto err = ts_or_err.takeError())
2335 auto ts = *ts_or_err;
2339 if (
auto decl = ts->GetNativePDBParser()->GetOrCreateDeclForUid(uid))
2347 if (
auto err = ts_or_err.takeError())
2349 auto ts = *ts_or_err;
2354 clang::DeclContext *context =
2365 if (
auto err = ts_or_err.takeError())
2367 auto ts = *ts_or_err;
2380 auto iter =
m_types.find(type_uid);
2387 return &*iter->second;
2392 if (type_id.
index.isNoneType())
2401std::optional<SymbolFile::ArrayInfo>
2404 return std::nullopt;
2410 if (!clang_type_system)
2414 static_cast<PdbAstBuilder *
>(clang_type_system->GetNativePDBParser());
2418 clang::QualType qt =
2425 TypeClass type_mask,
2434 if (
auto err = ts_or_err.takeError())
2436 auto ts = *ts_or_err;
2439 auto *
clang = llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
2447 clang::DeclContext *decl_context =
nullptr;
2448 if (parent_decl_ctx)
2449 decl_context =
static_cast<clang::DeclContext *
>(
2452 auto *namespace_decl =
2454 if (!namespace_decl)
2457 return clang->CreateDeclContext(namespace_decl);
2460llvm::Expected<lldb::TypeSystemSP>
2462 auto type_system_or_err =
2463 m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language);
2464 if (type_system_or_err)
2465 if (
auto ts = *type_system_or_err)
2466 ts->SetSymbolFile(
this);
2467 return type_system_or_err;
2472 return m_index->pdb().getFileSize();
2476 LazyRandomTypeCollection &types =
m_index->tpi().typeCollection();
2478 llvm::DenseMap<TypeIndex, TypeIndex> forward_to_full;
2479 llvm::DenseMap<TypeIndex, TypeIndex> full_to_forward;
2481 struct RecordIndices {
2486 llvm::StringMap<RecordIndices> record_indices;
2488 for (
auto ti = types.getFirst(); ti; ti = types.getNext(*ti)) {
2489 CVType type = types.getType(*ti);
2495 RecordIndices &indices = record_indices[tag.
asTag().getUniqueName()];
2496 if (tag.
asTag().isForwardRef()) {
2497 indices.forward = *ti;
2505 if (indices.full != TypeIndex::None() &&
2506 indices.forward != TypeIndex::None()) {
2507 forward_to_full[indices.forward] = indices.full;
2508 full_to_forward[indices.full] = indices.forward;
2514 if (tag.
asTag().isForwardRef() || !tag.
asTag().containsNestedClass())
2518 ProcessTpiStream(
PdbIndex &index, TypeIndex parent,
2520 llvm::DenseMap<TypeIndex, TypeIndex> &parents)
2521 : index(index), parents(parents), parent(parent),
2522 parent_cvt(parent_cvt) {}
2525 llvm::DenseMap<TypeIndex, TypeIndex> &parents;
2527 unsigned unnamed_type_index = 1;
2531 llvm::Error visitKnownMember(CVMemberRecord &CVR,
2532 NestedTypeRecord &Record)
override {
2533 std::string unnamed_type_name;
2534 if (Record.Name.empty()) {
2536 llvm::formatv(
"<unnamed-type-$S{0}>", unnamed_type_index).str();
2537 Record.Name = unnamed_type_name;
2538 ++unnamed_type_index;
2540 std::optional<CVTagRecord> tag =
2543 return llvm::ErrorSuccess();
2545 parents[Record.Type] = parent;
2546 return llvm::ErrorSuccess();
2550 CVType field_list_cvt =
m_index->tpi().getType(tag.
asTag().FieldList);
2552 FieldListRecord field_list;
2553 if (llvm::Error
error = TypeDeserializer::deserializeAs<FieldListRecord>(
2554 field_list_cvt, field_list))
2555 llvm::consumeError(std::move(
error));
2556 if (llvm::Error
error = visitMemberRecordStream(field_list.Data, process))
2557 llvm::consumeError(std::move(
error));
2569 std::vector<TypeIndex> full_keys;
2570 std::vector<TypeIndex> fwd_keys;
2572 TypeIndex key = entry.first;
2573 TypeIndex value = entry.second;
2575 auto iter = forward_to_full.find(value);
2576 if (iter != forward_to_full.end())
2577 entry.second = iter->second;
2579 iter = forward_to_full.find(key);
2580 if (iter != forward_to_full.end())
2581 fwd_keys.push_back(key);
2583 full_keys.push_back(key);
2585 for (TypeIndex fwd : fwd_keys) {
2586 TypeIndex full = forward_to_full[fwd];
2590 for (TypeIndex full : full_keys) {
2591 TypeIndex fwd = full_to_forward[full];
2596std::optional<PdbCompilandSymId>
2598 CVSymbol sym =
m_index->ReadSymbolRecord(
id);
2599 if (symbolOpensScope(sym.kind())) {
2602 id.offset = getScopeParentOffset(sym);
2606 return std::nullopt;
2615 auto begin = syms.begin();
2616 auto end = syms.at(
id.offset);
2617 std::vector<PdbCompilandSymId> scope_stack;
2619 while (begin != end) {
2620 if (begin.offset() >
id.offset) {
2622 lldbassert(
false &&
"Invalid compiland symbol id!");
2623 return std::nullopt;
2628 if (symbolOpensScope(begin->kind())) {
2631 uint32_t scope_end = getScopeEndOffset(*begin);
2632 if (scope_end <
id.offset) {
2633 begin = syms.at(scope_end);
2636 scope_stack.emplace_back(
id.modi, begin.offset());
2638 }
else if (symbolEndsScope(begin->kind())) {
2639 scope_stack.pop_back();
2643 if (scope_stack.empty())
2644 return std::nullopt;
2646 return scope_stack.back();
2649std::optional<llvm::codeview::TypeIndex>
2653 return std::nullopt;
2654 return parent_iter->second;
2657std::vector<CompilerContext>
2659 CVType type =
m_index->tpi().getType(ti);
2665 std::optional<Type::ParsedName> parsed_name =
2670 std::vector<CompilerContext> ctx;
2672 for (llvm::StringRef scope : parsed_name->scope) {
2679 for (
auto &el : llvm::reverse(llvm::drop_end(ctx))) {
2685 type =
m_index->tpi().getType(ti);
2686 switch (type.kind()) {
2706std::optional<llvm::StringRef>
2711 return std::nullopt;
2714 if (sym_record.kind() != S_LPROC32 && sym_record.kind() != S_GPROC32)
2715 return std::nullopt;
2717 ProcSym proc(
static_cast<SymbolRecordKind
>(sym_record.kind()));
2718 cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym_record, proc));
2724std::optional<llvm::StringRef>
2726 TypeIndex function_type) {
2727 auto symbol =
m_index->publics().findByAddress(
m_index->symrecords(),
2730 return std::nullopt;
2732 llvm::StringRef name = symbol->first.Name;
2735 if (!function_type.isNoneType() &&
2736 (symbol->first.Flags & PublicSymFlags::Function) != PublicSymFlags::None)
2753 if (!mangled.starts_with(
'_') ||
2754 m_index->dbi().getMachineType() != PDB_Machine::x86)
2758 PDB_CallingConv cc = PDB_CallingConv::NearC;
2759 if (cvt.kind() == LF_PROCEDURE) {
2760 ProcedureRecord proc;
2761 if (llvm::Error
error =
2762 TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, proc))
2763 llvm::consumeError(std::move(
error));
2765 }
else if (cvt.kind() == LF_MFUNCTION) {
2766 MemberFunctionRecord mfunc;
2767 if (llvm::Error
error =
2768 TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfunc))
2769 llvm::consumeError(std::move(
error));
2770 cc = mfunc.CallConv;
2777 if (cc == PDB_CallingConv::NearC || cc == PDB_CallingConv::FarC)
2778 return mangled.drop_front();
2784 for (CVType cvt :
m_index->ipi().typeArray()) {
2785 switch (cvt.kind()) {
2786 case LF_UDT_SRC_LINE: {
2787 UdtSourceLineRecord udt_src;
2788 llvm::cantFail(TypeDeserializer::deserializeAs(cvt, udt_src));
2792 udt_src.LineNumber});
2794 case LF_UDT_MOD_SRC_LINE: {
2795 UdtModSourceLineRecord udt_mod_src;
2796 llvm::cantFail(TypeDeserializer::deserializeAs(cvt, udt_mod_src));
2804 udt_mod_src.LineNumber});
2812llvm::Expected<Declaration>
2818 return llvm::createStringError(
"No UDT declaration found");
2820 llvm::StringRef file_name;
2821 if (it->second.IsIpiIndex) {
2822 CVType cvt =
m_index->ipi().getType(it->second.FileNameIndex);
2823 if (cvt.kind() != LF_STRING_ID)
2824 return llvm::createStringError(
"File name was not a LF_STRING_ID");
2827 llvm::cantFail(TypeDeserializer::deserializeAs(cvt, sid));
2828 file_name = sid.String;
2831 auto string_table =
m_index->pdb().getStringTable();
2833 return string_table.takeError();
2835 llvm::Expected<llvm::StringRef>
string =
2836 string_table->getStringTable().getString(
2837 it->second.FileNameIndex.getIndex());
2839 return string.takeError();
2840 file_name = *string;
2844 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 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)
bool CanImport(const CompilerType &type)
Returns true iff the given type was copied from another TypeSystemClang and the original type in this...
bool CompleteType(const CompilerType &compiler_type)
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
void * GetOpaqueDeclContext() const
Represents a generic declaration such as a function declaration.
Generic representation of a type in a programming language.
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
lldb::opaque_compiler_type_t GetOpaqueQualType() const
A uniqued constant string class.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const char * GetCString() const
Get the string value as a C string.
"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.
static bool Match(const FileSpec &pattern, const FileSpec &file)
Match FileSpec pattern against FileSpec file.
const ConstString & GetFilename() const
Filename string const get accessor.
FileSpec CopyByRemovingLastPathComponent() const
llvm::sys::path::Style Style
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 ...
uint32_t AddSymbol(const Symbol &symbol)
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
ClangASTImporter & GetClangASTImporter()
clang::DeclContext * GetParentDeclContext(PdbSymUid uid)
CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context)
clang::DeclContext * FromCompilerDeclContext(CompilerDeclContext context)
CompilerType ToCompilerType(clang::QualType qt)
clang::NamespaceDecl * FindNamespaceDecl(const clang::DeclContext *parent, llvm::StringRef name)
bool CompleteType(clang::QualType qt)
clang::DeclContext * GetOrCreateDeclContextForUid(PdbSymUid uid)
void ParseDeclsForContext(clang::DeclContext &context)
clang::BlockDecl * GetOrCreateBlockDecl(PdbCompilandSymId block_id)
clang::QualType GetOrCreateType(PdbTypeSymId type)
clang::FunctionDecl * GetOrCreateInlinedFunctionDecl(PdbCompilandSymId inlinesite_id)
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
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::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