14 #include "clang/Lex/Lexer.h"
31 #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
32 #include "llvm/DebugInfo/PDB/GenericError.h"
33 #include "llvm/DebugInfo/PDB/IPDBDataStream.h"
34 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
35 #include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
36 #include "llvm/DebugInfo/PDB/IPDBSectionContrib.h"
37 #include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
38 #include "llvm/DebugInfo/PDB/IPDBTable.h"
39 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
40 #include "llvm/DebugInfo/PDB/PDBSymbolBlock.h"
41 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
42 #include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h"
43 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
44 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
45 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
46 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
47 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
48 #include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
49 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
50 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
51 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
52 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
53 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
60 #include "llvm/Config/llvm-config.h"
89 return ((requested_line == 0 || actual_line == requested_line) &&
96 #if LLVM_ENABLE_DIA_SDK
97 llvm::StringRef use_native = ::getenv(
"LLDB_USE_NATIVE_PDB_READER");
98 if (!use_native.equals_insensitive(
"on") &&
99 !use_native.equals_insensitive(
"yes") &&
100 !use_native.equals_insensitive(
"1") &&
101 !use_native.equals_insensitive(
"true"))
110 npdb::SymbolFileNativePDB::Initialize();
112 PluginManager::RegisterPlugin(GetPluginNameStatic(),
113 GetPluginDescriptionStatic(), CreateInstance,
120 npdb::SymbolFileNativePDB::Terminate();
122 PluginManager::UnregisterPlugin(CreateInstance);
129 return "Microsoft PDB debug symbol file reader.";
138 :
SymbolFileCommon(std::move(objfile_sp)), m_session_up(), m_global_scope_up() {}
150 auto error = loadDataForEXE(PDB_ReaderType::DIA, llvm::StringRef(exePath),
153 llvm::consumeError(std::move(
error));
158 FileSpec symfile = module_sp->GetSymbolFileFileSpec();
161 error = loadDataForPDB(PDB_ReaderType::DIA,
164 llvm::consumeError(std::move(
error));
175 while (
auto table_up = enum_tables_up->getNext()) {
176 if (table_up->getItemCount() == 0)
178 auto type = table_up->getTableType();
180 case PDB_TableType::Symbols:
186 case PDB_TableType::LineNumbers:
219 uint32_t compile_unit_count = compilands->getChildCount();
224 auto last_compiland_up = compilands->getChildAtIndex(compile_unit_count - 1);
227 if (name ==
"* Linker *")
228 --compile_unit_count;
229 return compile_unit_count;
233 const llvm::pdb::PDBSymbolCompiland &pdb_compiland,
uint32_t &index) {
237 auto uid = pdb_compiland.getSymIndexId();
239 auto compiland_up = results_up->getChildAtIndex(cu_idx);
242 if (compiland_up->getSymIndexId() == uid) {
250 std::unique_ptr<llvm::pdb::PDBSymbolCompiland>
252 return m_session_up->getConcreteSymbolById<PDBSymbolCompiland>(uid);
265 auto compiland_up = results->getChildAtIndex(index);
276 auto details = compiland_up->findOneChild<PDBSymbolCompilandDetails>();
288 auto file_vm_addr = pdb_func.getVirtualAddress();
292 auto func_length = pdb_func.getLength();
303 user_id_t func_type_uid = pdb_func.getSignatureId();
308 std::make_shared<Function>(&comp_unit, pdb_func.getSymIndexId(),
309 func_type_uid, mangled, func_type, func_range);
315 if (
auto err = type_system_or_err.takeError()) {
317 "Unable to parse PDBFunc");
322 llvm::dyn_cast_or_null<TypeSystemClang>(&type_system_or_err.get());
323 if (!clang_type_system)
327 return func_sp.get();
332 size_t func_added = 0;
336 auto results_up = compiland_up->findAllChildren<PDBSymbolFunc>();
339 while (
auto pdb_func_up = results_up->getNext()) {
362 CompileUnit &comp_unit, lldb_private::FileSpecList &support_files) {
373 auto files =
m_session_up->getSourceFilesForCompiland(*compiland_up);
374 if (!files || files->getChildCount() == 0)
377 while (
auto file = files->getNext()) {
378 FileSpec spec(file->getFileName(), FileSpec::Style::windows);
379 support_files.AppendIfUnique(spec);
387 std::vector<SourceModule> &imported_modules) {
393 uint64_t func_file_vm_addr,
const llvm::pdb::PDBSymbol *pdb_symbol,
395 assert(pdb_symbol && parent_block);
397 size_t num_added = 0;
398 switch (pdb_symbol->getSymTag()) {
399 case PDB_SymType::Block:
400 case PDB_SymType::Function: {
401 Block *block =
nullptr;
402 auto &raw_sym = pdb_symbol->getRawSymbol();
403 if (
auto *pdb_func = llvm::dyn_cast<PDBSymbolFunc>(pdb_symbol)) {
404 if (pdb_func->hasNoInlineAttribute())
407 block = parent_block;
410 }
else if (llvm::isa<PDBSymbolBlock>(pdb_symbol)) {
411 auto uid = pdb_symbol->getSymIndexId();
414 if (raw_sym.getVirtualAddress() < func_file_vm_addr)
417 auto block_sp = std::make_shared<Block>(pdb_symbol->getSymIndexId());
419 block = block_sp.get();
421 llvm_unreachable(
"Unexpected PDB symbol!");
424 raw_sym.getVirtualAddress() - func_file_vm_addr, raw_sym.getLength()));
428 auto results_up = pdb_symbol->findAllChildren();
431 while (
auto symbol_up = results_up->getNext()) {
433 func_file_vm_addr, symbol_up.get(), block,
false);
444 size_t num_added = 0;
445 auto uid = func.
GetID();
446 auto pdb_func_up =
m_session_up->getConcreteSymbolById<PDBSymbolFunc>(uid);
451 pdb_func_up->getVirtualAddress(), pdb_func_up.get(), &parent_block,
true);
458 size_t num_added = 0;
463 auto ParseTypesByTagFn = [&num_added,
this](
const PDBSymbol &raw_sym) {
464 std::unique_ptr<IPDBEnumSymbols> results;
465 PDB_SymType tags_to_search[] = {PDB_SymType::Enum, PDB_SymType::Typedef,
467 for (
auto tag : tags_to_search) {
468 results = raw_sym.findAllChildren(tag);
469 if (!results || results->getChildCount() == 0)
471 while (
auto symbol = results->getNext()) {
472 switch (symbol->getSymTag()) {
473 case PDB_SymType::Enum:
474 case PDB_SymType::UDT:
475 case PDB_SymType::Typedef:
487 type->GetFullCompilerType();
494 ParseTypesByTagFn(*compiland);
499 static bool parse_all_global_types =
false;
500 if (!parse_all_global_types) {
502 parse_all_global_types =
true;
513 size_t num_added = 0;
515 auto pdb_func =
m_session_up->getConcreteSymbolById<PDBSymbolFunc>(
531 if (results && results->getChildCount()) {
532 while (
auto result = results->getNext()) {
559 auto find_result =
m_types.find(type_uid);
560 if (find_result !=
m_types.end())
561 return find_result->second.get();
563 auto type_system_or_err =
565 if (
auto err = type_system_or_err.takeError()) {
567 "Unable to ResolveTypeUID");
572 llvm::dyn_cast_or_null<TypeSystemClang>(&type_system_or_err.get());
573 if (!clang_type_system)
580 if (pdb_type ==
nullptr)
585 m_types.insert(std::make_pair(type_uid, result));
597 std::lock_guard<std::recursive_mutex> guard(
600 auto type_system_or_err =
602 if (
auto err = type_system_or_err.takeError()) {
604 "Unable to get dynamic array info for UID");
609 llvm::dyn_cast_or_null<TypeSystemClang>(&type_system_or_err.get());
622 auto type_system_or_err =
624 if (
auto err = type_system_or_err.takeError()) {
626 "Unable to get decl for UID");
631 llvm::dyn_cast_or_null<TypeSystemClang>(&type_system_or_err.get());
652 auto type_system_or_err =
654 if (
auto err = type_system_or_err.takeError()) {
656 "Unable to get DeclContext for UID");
661 llvm::dyn_cast_or_null<TypeSystemClang>(&type_system_or_err.get());
682 auto type_system_or_err =
684 if (
auto err = type_system_or_err.takeError()) {
686 "Unable to get DeclContext containing UID");
691 llvm::dyn_cast_or_null<TypeSystemClang>(&type_system_or_err.get());
704 assert(decl_context);
711 auto type_system_or_err =
713 if (
auto err = type_system_or_err.takeError()) {
715 "Unable to parse decls for context");
720 llvm::dyn_cast_or_null<TypeSystemClang>(&type_system_or_err.get());
734 SymbolContextItem resolve_scope,
738 if (resolve_scope & eSymbolContextCompUnit ||
739 resolve_scope & eSymbolContextVariable ||
740 resolve_scope & eSymbolContextFunction ||
741 resolve_scope & eSymbolContextBlock ||
742 resolve_scope & eSymbolContextLineEntry) {
745 if (resolved_flags & eSymbolContextVariable) {
751 resolved_flags |= eSymbolContextCompUnit;
755 if (resolve_scope & eSymbolContextFunction ||
756 resolve_scope & eSymbolContextBlock) {
759 m_session_up->findSymbolByAddress(file_vm_addr, PDB_SymType::Function);
761 auto *pdb_func = llvm::dyn_cast<PDBSymbolFunc>(symbol_up.get());
763 auto func_uid = pdb_func->getSymIndexId();
769 resolved_flags |= eSymbolContextFunction;
770 if (resolve_scope & eSymbolContextBlock) {
772 file_vm_addr, PDB_SymType::Block);
773 auto block_id = block_symbol ? block_symbol->getSymIndexId()
777 resolved_flags |= eSymbolContextBlock;
783 if (resolve_scope & eSymbolContextLineEntry) {
786 if (line_table->FindLineEntryByAddress(addr, sc.
line_entry))
787 resolved_flags |= eSymbolContextLineEntry;
791 return resolved_flags;
798 const size_t old_size = sc_list.
GetSize();
801 if (resolve_scope & lldb::eSymbolContextCompUnit) {
806 auto compilands =
m_session_up->findCompilandsForSourceFile(
807 file_spec.
GetPath(), PDB_NameSearchFlags::NS_CaseInsensitive);
814 while (
auto compiland = compilands->getNext()) {
820 std::string source_file = compiland->getSourceFileFullPath();
821 if (source_file.empty())
823 FileSpec this_spec(source_file, FileSpec::Style::windows);
838 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock |
839 eSymbolContextLineEntry)) {
842 if ((resolve_scope & eSymbolContextLineEntry) && !has_line_table) {
846 assert(line &&
"Couldn't get all line entries!\n");
852 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) {
859 uint32_t num_line_entries = line_table->GetSize();
865 for (
uint32_t line_idx = 0; line && line_idx < num_line_entries;
867 if (!line_table->GetLineEntryAtIndex(line_idx, sc.
line_entry))
876 file_vm_addr, PDB_SymType::Function);
878 auto func_uid = symbol_up->getSymIndexId();
881 auto pdb_func = llvm::dyn_cast<PDBSymbolFunc>(symbol_up.get());
886 if (sc.
function && (resolve_scope & eSymbolContextBlock)) {
893 }
else if (has_line_table) {
905 return sc_list.
GetSize() - old_size;
913 while (
auto symbol_up = result_up->getNext())
914 if (
auto addr = symbol_up->getRawSymbol().getVirtualAddress())
923 const llvm::pdb::PDBSymbolData &pdb_data) {
925 uint32_t var_uid = pdb_data.getSymIndexId();
928 return result->second;
931 bool is_static_member =
false;
932 bool is_external =
false;
933 bool is_artificial =
false;
935 switch (pdb_data.getDataKind()) {
936 case PDB_DataKind::Global:
940 case PDB_DataKind::Local:
943 case PDB_DataKind::FileStatic:
946 case PDB_DataKind::StaticMember:
947 is_static_member =
true;
950 case PDB_DataKind::Member:
953 case PDB_DataKind::Param:
956 case PDB_DataKind::Constant:
963 switch (pdb_data.getLocationType()) {
964 case PDB_LocType::TLS:
967 case PDB_LocType::RegRel: {
969 if (pdb_data.getDataKind() == PDB_DataKind::ObjectPtr) {
971 is_artificial =
true;
979 if (!is_artificial && !pdb_data.isCompilerGenerated()) {
980 if (
auto lines = pdb_data.getLineNumbers()) {
981 if (
auto first_line = lines->getNext()) {
982 uint32_t src_file_id = first_line->getSourceFileId();
983 auto src_file =
m_session_up->getSourceFileById(src_file_id);
985 FileSpec spec(src_file->getFileName());
987 decl.
SetColumn(first_line->getColumnNumber());
988 decl.
SetLine(first_line->getLineNumber());
1000 function_block.
FindBlockByID(pdb_data.getLexicalParentId());
1002 block = &function_block;
1004 context_scope = block;
1006 for (
size_t i = 0, num_ranges = block->
GetNumRanges(); i < num_ranges;
1018 SymbolFileTypeSP type_sp =
1019 std::make_shared<SymbolFileType>(*
this, pdb_data.getTypeId());
1021 auto var_name = pdb_data.getName();
1023 auto mangled_cstr = mangled.empty() ? nullptr : mangled.c_str();
1027 GetObjectFile()->GetModule(), pdb_data, ranges, is_constant);
1029 var_sp = std::make_shared<Variable>(
1030 var_uid, var_name.c_str(), mangled_cstr, type_sp, scope, context_scope,
1031 ranges, &decl, location, is_external, is_artificial, is_constant,
1034 m_variables.insert(std::make_pair(var_uid, var_sp));
1040 const llvm::pdb::PDBSymbol &pdb_symbol,
1042 size_t num_added = 0;
1044 if (
auto pdb_data = llvm::dyn_cast<PDBSymbolData>(&pdb_symbol)) {
1045 VariableListSP local_variable_list_sp;
1047 auto result =
m_variables.find(pdb_data->getSymIndexId());
1053 if (
auto lexical_parent = pdb_data->getLexicalParent()) {
1054 switch (lexical_parent->getSymTag()) {
1055 case PDB_SymType::Exe:
1058 case PDB_SymType::Compiland: {
1061 if (!local_variable_list_sp) {
1062 local_variable_list_sp = std::make_shared<VariableList>();
1067 case PDB_SymType::Block:
1068 case PDB_SymType::Function: {
1071 lexical_parent->getSymIndexId());
1074 if (!local_variable_list_sp) {
1075 local_variable_list_sp = std::make_shared<VariableList>();
1086 if (local_variable_list_sp) {
1088 local_variable_list_sp->AddVariableIfUnique(var_sp);
1100 if (
auto results = pdb_symbol.findAllChildren()) {
1101 while (
auto result = results->getNext())
1122 size_t old_size = variables.
GetSize();
1123 while (
auto result = results->getNext()) {
1124 auto pdb_data = llvm::dyn_cast<PDBSymbolData>(result.get());
1125 if (max_matches > 0 && matches >= max_matches)
1141 if (parent_decl_ctx.
IsValid() &&
1146 matches = variables.
GetSize() - old_size;
1161 size_t old_size = variables.
GetSize();
1162 while (
auto pdb_data = results->getNext()) {
1163 if (max_matches > 0 && matches >= max_matches)
1166 auto var_name = pdb_data->getName();
1167 if (var_name.empty())
1181 matches = variables.
GetSize() - old_size;
1186 bool include_inlines,
1203 auto pdb_func_up =
m_session_up->getConcreteSymbolById<PDBSymbolFunc>(uid);
1204 if (!pdb_func_up && !(include_inlines && pdb_func_up->hasInlineAttribute()))
1213 std::map<uint64_t, uint32_t> addr_ids;
1216 while (
auto pdb_func_up = results_up->getNext()) {
1217 if (pdb_func_up->isCompilerGenerated())
1220 auto name = pdb_func_up->getName();
1221 auto demangled_name = pdb_func_up->getUndecoratedName();
1222 if (name.empty() && demangled_name.empty())
1225 auto uid = pdb_func_up->getSymIndexId();
1226 if (!demangled_name.empty() && pdb_func_up->getVirtualAddress())
1227 addr_ids.insert(std::make_pair(pdb_func_up->getVirtualAddress(), uid));
1229 if (
auto parent = pdb_func_up->getClassParent()) {
1240 if (!basename.empty())
1246 if (!demangled_name.empty())
1254 if (!basename.empty())
1259 if (name ==
"main") {
1262 if (!demangled_name.empty() && name != demangled_name) {
1266 }
else if (!demangled_name.empty()) {
1275 if (
auto results_up =
1277 while (
auto pub_sym_up = results_up->getNext()) {
1278 if (!pub_sym_up->isFunction())
1280 auto name = pub_sym_up->getName();
1284 if (CPlusPlusLanguage::IsCPPMangledName(name.c_str())) {
1285 auto vm_addr = pub_sym_up->getVirtualAddress();
1288 if (vm_addr && addr_ids.find(vm_addr) != addr_ids.end()) {
1307 FunctionNameType name_type_mask,
bool include_inlines,
1310 lldbassert((name_type_mask & eFunctionNameTypeAuto) == 0);
1312 if (name_type_mask == eFunctionNameTypeNone)
1319 if (name_type_mask & eFunctionNameTypeFull ||
1320 name_type_mask & eFunctionNameTypeBase ||
1321 name_type_mask & eFunctionNameTypeMethod) {
1324 std::set<uint32_t> resolved_ids;
1325 auto ResolveFn = [
this, &name, parent_decl_ctx, include_inlines, &sc_list,
1327 std::vector<uint32_t> ids;
1328 if (!Names.GetValues(name, ids))
1332 if (resolved_ids.find(
id) != resolved_ids.end())
1335 if (parent_decl_ctx.IsValid() &&
1340 resolved_ids.insert(
id);
1343 if (name_type_mask & eFunctionNameTypeFull) {
1348 if (name_type_mask & eFunctionNameTypeBase)
1350 if (name_type_mask & eFunctionNameTypeMethod)
1356 bool include_inlines,
1364 std::set<uint32_t> resolved_ids;
1365 auto ResolveFn = [®ex, include_inlines, &sc_list, &resolved_ids,
1367 std::vector<uint32_t> ids;
1368 if (Names.GetValues(regex, ids)) {
1369 for (
auto id : ids) {
1370 if (resolved_ids.find(
id) == resolved_ids.end())
1372 resolved_ids.insert(
id);
1382 std::vector<lldb_private::ConstString> &mangled_names) {}
1385 std::set<lldb::addr_t> sym_addresses;
1397 while (
auto pub_symbol = results->getNext()) {
1398 auto section_id = pub_symbol->getAddressSection();
1400 auto section = section_list->FindSectionByID(section_id);
1404 auto offset = pub_symbol->getAddressOffset();
1406 auto file_addr = section->GetFileAddress() + offset;
1407 if (sym_addresses.find(file_addr) != sym_addresses.end())
1409 sym_addresses.insert(file_addr);
1411 auto size = pub_symbol->getLength();
1413 Symbol(pub_symbol->getSymIndexId(),
1414 pub_symbol->getName().c_str(),
1435 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
1443 searched_symbol_files.clear();
1444 searched_symbol_files.insert(
this);
1451 auto type_system_or_err =
1453 if (
auto err = type_system_or_err.takeError()) {
1455 "Unable to dump ClangAST");
1459 auto *clang_type_system =
1460 llvm::dyn_cast_or_null<TypeSystemClang>(&type_system_or_err.get());
1461 if (!clang_type_system)
1475 PDB_SymType tags_to_search[] = {PDB_SymType::Enum, PDB_SymType::Typedef,
1477 std::unique_ptr<IPDBEnumSymbols> results;
1481 for (
auto tag : tags_to_search) {
1486 while (
auto result = results->getNext()) {
1487 if (max_matches > 0 && matches >= max_matches)
1491 if (
auto enum_type = llvm::dyn_cast<PDBSymbolTypeEnum>(result.get()))
1492 type_name = enum_type->getName();
1493 else if (
auto typedef_type =
1494 llvm::dyn_cast<PDBSymbolTypeTypedef>(result.get()))
1495 type_name = typedef_type->getName();
1496 else if (
auto class_type = llvm::dyn_cast<PDBSymbolTypeUDT>(result.get()))
1497 type_name = class_type->getName();
1504 if (!regex.
Execute(type_name))
1512 auto iter =
m_types.find(result->getSymIndexId());
1515 types.
Insert(iter->second);
1522 llvm::StringRef name,
1525 std::unique_ptr<IPDBEnumSymbols> results;
1534 while (
auto result = results->getNext()) {
1535 if (max_matches > 0 && matches >= max_matches)
1539 result->getRawSymbol().getName()) != name)
1542 switch (result->getSymTag()) {
1543 case PDB_SymType::Enum:
1544 case PDB_SymType::UDT:
1545 case PDB_SymType::Typedef:
1558 if (parent_decl_ctx.
IsValid() &&
1562 auto iter =
m_types.find(result->getSymIndexId());
1565 types.
Insert(iter->second);
1571 llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages,
1572 llvm::DenseSet<SymbolFile *> &searched_symbol_files,
1578 bool can_parse =
false;
1579 switch (pdb_symbol.getSymTag()) {
1580 case PDB_SymType::ArrayType:
1581 can_parse = ((type_mask & eTypeClassArray) != 0);
1583 case PDB_SymType::BuiltinType:
1584 can_parse = ((type_mask & eTypeClassBuiltin) != 0);
1586 case PDB_SymType::Enum:
1587 can_parse = ((type_mask & eTypeClassEnumeration) != 0);
1589 case PDB_SymType::Function:
1590 case PDB_SymType::FunctionSig:
1591 can_parse = ((type_mask & eTypeClassFunction) != 0);
1593 case PDB_SymType::PointerType:
1594 can_parse = ((type_mask & (eTypeClassPointer | eTypeClassBlockPointer |
1595 eTypeClassMemberPointer)) != 0);
1597 case PDB_SymType::Typedef:
1598 can_parse = ((type_mask & eTypeClassTypedef) != 0);
1600 case PDB_SymType::UDT: {
1601 auto *udt = llvm::dyn_cast<PDBSymbolTypeUDT>(&pdb_symbol);
1603 can_parse = (udt->getUdtKind() != PDB_UdtType::Interface &&
1604 ((type_mask & (eTypeClassClass | eTypeClassStruct |
1605 eTypeClassUnion)) != 0));
1614 std::find(type_collection.begin(), type_collection.end(), type);
1615 if (result == type_collection.end())
1616 type_collection.push_back(type);
1620 auto results_up = pdb_symbol.findAllChildren();
1621 while (
auto symbol_up = results_up->getNext())
1626 TypeClass type_mask,
1647 for (
auto type : type_collection) {
1648 type->GetForwardCompilerType();
1649 type_list.
Insert(type->shared_from_this());
1653 llvm::Expected<lldb_private::TypeSystem &>
1655 auto type_system_or_err =
1656 m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language);
1657 if (type_system_or_err) {
1658 type_system_or_err->SetSymbolFile(
this);
1660 return type_system_or_err;
1664 auto type_system_or_err =
1666 if (
auto err = type_system_or_err.takeError()) {
1668 "Unable to get PDB AST parser");
1672 auto *clang_type_system =
1673 llvm::dyn_cast_or_null<TypeSystemClang>(&type_system_or_err.get());
1674 if (!clang_type_system)
1677 return clang_type_system->GetPDBParser();
1684 auto type_system_or_err =
1686 if (
auto err = type_system_or_err.takeError()) {
1688 "Unable to find namespace {}", name.
AsCString());
1692 auto *clang_type_system =
1693 llvm::dyn_cast_or_null<TypeSystemClang>(&type_system_or_err.get());
1694 if (!clang_type_system)
1701 clang::DeclContext *decl_context =
nullptr;
1702 if (parent_decl_ctx)
1703 decl_context =
static_cast<clang::DeclContext *
>(
1706 auto namespace_decl =
1708 if (!namespace_decl)
1711 return clang_type_system->CreateDeclContext(namespace_decl);
1724 return found_cu->second;
1728 return CompUnitSP();
1731 auto details = compiland_up->findOneChild<PDBSymbolCompilandDetails>();
1738 return CompUnitSP();
1740 std::string path = compiland_up->getSourceFileFullPath();
1742 return CompUnitSP();
1747 auto cu_sp = std::make_shared<CompileUnit>(
m_objfile_sp->GetModule(),
nullptr,
1748 path.c_str(),
id, lang, optimized);
1751 return CompUnitSP();
1771 llvm::DenseMap<uint32_t, uint32_t> index_map;
1773 auto line_table = std::make_unique<LineTable>(&comp_unit);
1776 auto files =
m_session_up->getSourceFilesForCompiland(*compiland_up);
1782 while (
auto file = files->getNext()) {
1783 std::unique_ptr<LineSequence> sequence(
1784 line_table->CreateLineSequenceContainer());
1785 auto lines =
m_session_up->findLineNumbers(*compiland_up, *file);
1788 int entry_count = lines->getChildCount();
1795 for (
int i = 0; i < entry_count; ++i) {
1796 auto line = lines->getChildAtIndex(i);
1798 uint64_t lno = line->getLineNumber();
1799 uint64_t addr = line->getVirtualAddress();
1800 uint32_t length = line->getLength();
1801 uint32_t source_id = line->getSourceFileId();
1802 uint32_t col = line->getColumnNumber();
1803 uint32_t source_idx = index_map[source_id];
1807 bool is_gap = (i > 0) && (prev_addr + prev_length < addr);
1812 if (is_gap && ShouldAddLine(match_line, prev_line, prev_length)) {
1813 line_table->AppendLineEntryToSequence(
1814 sequence.get(), prev_addr + prev_length, prev_line, 0,
1815 prev_source_idx,
false,
false,
false,
false,
true);
1817 line_table->InsertSequence(sequence.get());
1818 sequence = line_table->CreateLineSequenceContainer();
1821 if (ShouldAddLine(match_line, lno, length)) {
1822 bool is_statement = line->isStatement();
1823 bool is_prologue =
false;
1824 bool is_epilogue =
false;
1826 m_session_up->findSymbolByAddress(addr, PDB_SymType::Function);
1828 auto prologue = func->findOneChild<PDBSymbolFuncDebugStart>();
1830 is_prologue = (addr == prologue->getVirtualAddress());
1832 auto epilogue = func->findOneChild<PDBSymbolFuncDebugEnd>();
1834 is_epilogue = (addr == epilogue->getVirtualAddress());
1837 line_table->AppendLineEntryToSequence(sequence.get(), addr, lno, col,
1838 source_idx, is_statement,
false,
1839 is_prologue, is_epilogue,
false);
1843 prev_length = length;
1845 prev_source_idx = source_idx;
1848 if (entry_count > 0 && ShouldAddLine(match_line, prev_line, prev_length)) {
1850 line_table->AppendLineEntryToSequence(
1851 sequence.get(), prev_addr + prev_length, prev_line, 0,
1852 prev_source_idx,
false,
false,
false,
false,
true);
1855 line_table->InsertSequence(sequence.get());
1858 if (line_table->GetSize()) {
1866 const PDBSymbolCompiland &compiland,
1867 llvm::DenseMap<uint32_t, uint32_t> &index_map)
const {
1873 auto source_files =
m_session_up->getSourceFilesForCompiland(compiland);
1878 while (
auto file = source_files->getNext()) {
1879 uint32_t source_id = file->getUniqueId();
1880 index_map[source_id] = index++;
1892 m_session_up->findLineNumbersByAddress(file_vm_addr, 1)) {
1893 if (
auto first_line = lines->getNext())
1898 if (
auto sec_contribs =
m_session_up->getSectionContribs()) {
1899 while (
auto section = sec_contribs->getNext()) {
1900 auto va = section->getVirtualAddress();
1901 if (file_vm_addr >= va && file_vm_addr < va + section->getLength())
1911 auto func_name = pdb_func.getName();
1912 auto func_undecorated_name = pdb_func.getUndecoratedName();
1918 if (!func_undecorated_name.empty()) {
1920 PDB_SymType::PublicSymbol, func_undecorated_name,
1921 PDB_NameSearchFlags::NS_UndecoratedName);
1923 while (
auto symbol_up = result_up->getNext()) {
1926 if (
auto *pdb_public_sym =
1927 llvm::dyn_cast_or_null<PDBSymbolPublicSymbol>(
1929 if (pdb_public_sym->isFunction()) {
1930 func_decorated_name = pdb_public_sym->getName();
1937 if (!func_decorated_name.empty()) {
1938 mangled.SetMangledName(
ConstString(func_decorated_name));
1951 if (!func_undecorated_name.empty() && mangled.GetDemangledName().IsEmpty())
1952 mangled.SetDemangledName(
ConstString(func_undecorated_name));
1959 if (!func_undecorated_name.empty() &&
1960 mangled.GetDemangledName() !=
ConstString(func_undecorated_name))
1961 mangled.SetDemangledName(
ConstString(func_undecorated_name));
1962 }
else if (!func_undecorated_name.empty()) {
1963 mangled.SetDemangledName(
ConstString(func_undecorated_name));
1964 }
else if (!func_name.empty())
1976 if (!decl_ctx_type_system)
1980 if (
auto err = type_system_or_err.takeError()) {
1982 GetLog(LLDBLog::Symbols), std::move(err),
1983 "Unable to determine if DeclContext matches this symbol file");
1987 if (decl_ctx_type_system == &type_system_or_err.get())
1995 return lhs < rhs.Offset;
2000 if (
auto SecContribs =
m_session_up->getSectionContribs()) {
2001 while (
auto SectionContrib = SecContribs->getNext()) {
2002 auto comp_id = SectionContrib->getCompilandId();
2006 auto sec = SectionContrib->getAddressSection();
2009 auto offset = SectionContrib->getAddressOffset();
2011 std::upper_bound(sec_cs.begin(), sec_cs.end(), offset, pred_upper);
2013 auto size = SectionContrib->getLength();
2014 sec_cs.insert(it, {offset, size, comp_id});
2020 if (
auto Lines = data.getLineNumbers()) {
2021 if (
auto FirstLine = Lines->getNext())
2022 return FirstLine->getCompilandId();
2026 uint32_t DataSection = data.getAddressSection();
2027 uint32_t DataOffset = data.getAddressOffset();
2028 if (DataSection == 0) {
2029 if (
auto RVA = data.getRelativeVirtualAddress())
2030 m_session_up->addressForRVA(RVA, DataSection, DataOffset);
2037 std::upper_bound(sec_cs.begin(), sec_cs.end(), DataOffset, pred_upper);
2038 if (it != sec_cs.begin()) {
2040 if (DataOffset < it->Offset + it->Size)
2041 return it->CompilandId;
2045 auto LexParentId = data.getLexicalParentId();
2046 while (
auto LexParent =
m_session_up->getSymbolById(LexParentId)) {
2047 if (LexParent->getSymTag() == PDB_SymType::Exe)
2049 if (LexParent->getSymTag() == PDB_SymType::Compiland)
2051 LexParentId = LexParent->getRawSymbol().getLexicalParentId();