14#include "clang/Lex/Lexer.h"
31#include "llvm/Config/llvm-config.h"
32#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
33#include "llvm/DebugInfo/PDB/GenericError.h"
34#include "llvm/DebugInfo/PDB/IPDBDataStream.h"
35#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
36#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
37#include "llvm/DebugInfo/PDB/IPDBSectionContrib.h"
38#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
39#include "llvm/DebugInfo/PDB/IPDBTable.h"
40#include "llvm/DebugInfo/PDB/PDBSymbol.h"
41#include "llvm/DebugInfo/PDB/PDBSymbolBlock.h"
42#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
43#include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h"
44#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
45#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
46#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
47#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
48#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
49#include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
50#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
51#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
52#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
53#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
54#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
61#include "llvm/Config/llvm-config.h"
86 case PDB_Lang::ObjCpp:
93bool ShouldAddLine(uint32_t requested_line, uint32_t actual_line,
94 uint32_t addr_length) {
95 return ((requested_line == 0 || actual_line == requested_line) &&
102#if LLVM_ENABLE_DIA_SDK
103 llvm::StringRef use_native = ::getenv(
"LLDB_USE_NATIVE_PDB_READER");
104 if (!use_native.equals_insensitive(
"on") &&
105 !use_native.equals_insensitive(
"yes") &&
106 !use_native.equals_insensitive(
"1") &&
107 !use_native.equals_insensitive(
"true"))
135 return "Microsoft PDB debug symbol file reader.";
144 :
SymbolFileCommon(std::move(objfile_sp)), m_session_up(), m_global_scope_up() {}
149 uint32_t abilities = 0;
155 std::string exePath =
m_objfile_sp->GetFileSpec().GetPath();
156 auto error = loadDataForEXE(PDB_ReaderType::DIA, llvm::StringRef(exePath),
159 llvm::consumeError(std::move(
error));
164 FileSpec symfile = module_sp->GetSymbolFileFileSpec();
167 error = loadDataForPDB(PDB_ReaderType::DIA,
170 llvm::consumeError(std::move(
error));
181 while (
auto table_up = enum_tables_up->getNext()) {
182 if (table_up->getItemCount() == 0)
184 auto type = table_up->getTableType();
186 case PDB_TableType::Symbols:
192 case PDB_TableType::LineNumbers:
225 uint32_t compile_unit_count = compilands->getChildCount();
230 auto last_compiland_up = compilands->getChildAtIndex(compile_unit_count - 1);
232 std::string name = last_compiland_up->getName();
233 if (name ==
"* Linker *")
234 --compile_unit_count;
235 return compile_unit_count;
239 const llvm::pdb::PDBSymbolCompiland &pdb_compiland, uint32_t &index) {
243 auto uid = pdb_compiland.getSymIndexId();
245 auto compiland_up = results_up->getChildAtIndex(cu_idx);
248 if (compiland_up->getSymIndexId() == uid) {
256std::unique_ptr<llvm::pdb::PDBSymbolCompiland>
258 return m_session_up->getConcreteSymbolById<PDBSymbolCompiland>(uid);
271 auto compiland_up = results->getChildAtIndex(index);
282 auto details = compiland_up->findOneChild<PDBSymbolCompilandDetails>();
294 auto file_vm_addr = pdb_func.getVirtualAddress();
298 auto func_length = pdb_func.getLength();
309 user_id_t func_type_uid = pdb_func.getSignatureId();
313 FunctionSP func_sp = std::make_shared<Function>(
314 &comp_unit, pdb_func.getSymIndexId(), func_type_uid, mangled, func_type,
321 if (
auto err = type_system_or_err.takeError()) {
323 "Unable to parse PDBFunc: {0}");
327 auto ts = *type_system_or_err;
329 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
330 if (!clang_type_system)
334 return func_sp.get();
339 size_t func_added = 0;
343 auto results_up = compiland_up->findAllChildren<PDBSymbolFunc>();
346 while (
auto pdb_func_up = results_up->getNext()) {
380 auto files =
m_session_up->getSourceFilesForCompiland(*compiland_up);
381 if (!files || files->getChildCount() == 0)
384 while (
auto file = files->getNext()) {
385 FileSpec spec(file->getFileName(), FileSpec::Style::windows);
394 std::vector<SourceModule> &imported_modules) {
400 uint64_t func_file_vm_addr,
const llvm::pdb::PDBSymbol *pdb_symbol,
402 assert(pdb_symbol && parent_block);
404 size_t num_added = 0;
406 if (!is_top_parent) {
408 if (pdb_symbol->getSymTag() != PDB_SymType::Block)
411 auto &raw_sym = pdb_symbol->getRawSymbol();
412 assert(llvm::isa<PDBSymbolBlock>(pdb_symbol));
413 auto uid = pdb_symbol->getSymIndexId();
416 if (raw_sym.getVirtualAddress() < func_file_vm_addr)
419 Block *block = parent_block->
CreateChild(pdb_symbol->getSymIndexId()).get();
421 raw_sym.getVirtualAddress() - func_file_vm_addr, raw_sym.getLength()));
424 auto results_up = pdb_symbol->findAllChildren();
428 while (
auto symbol_up = results_up->getNext()) {
430 func_file_vm_addr, symbol_up.get(), parent_block,
false);
437 size_t num_added = 0;
438 auto uid = func.
GetID();
439 auto pdb_func_up =
m_session_up->getConcreteSymbolById<PDBSymbolFunc>(uid);
444 pdb_func_up->getVirtualAddress(), pdb_func_up.get(), &parent_block,
true);
451 size_t num_added = 0;
456 auto ParseTypesByTagFn = [&num_added,
this](
const PDBSymbol &raw_sym) {
457 std::unique_ptr<IPDBEnumSymbols> results;
458 PDB_SymType tags_to_search[] = {PDB_SymType::Enum, PDB_SymType::Typedef,
460 for (
auto tag : tags_to_search) {
461 results = raw_sym.findAllChildren(tag);
462 if (!results || results->getChildCount() == 0)
464 while (
auto symbol = results->getNext()) {
465 switch (symbol->getSymTag()) {
466 case PDB_SymType::Enum:
467 case PDB_SymType::UDT:
468 case PDB_SymType::Typedef:
480 type->GetFullCompilerType();
487 ParseTypesByTagFn(*compiland);
492 static bool parse_all_global_types =
false;
493 if (!parse_all_global_types) {
495 parse_all_global_types =
true;
506 size_t num_added = 0;
508 auto pdb_func =
m_session_up->getConcreteSymbolById<PDBSymbolFunc>(
524 if (results && results->getChildCount()) {
525 while (
auto result = results->getNext()) {
552 auto find_result =
m_types.find(type_uid);
553 if (find_result !=
m_types.end())
554 return find_result->second.get();
556 auto type_system_or_err =
558 if (
auto err = type_system_or_err.takeError()) {
560 "Unable to ResolveTypeUID: {0}");
564 auto ts = *type_system_or_err;
566 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
567 if (!clang_type_system)
574 if (pdb_type ==
nullptr)
579 m_types.insert(std::make_pair(type_uid, result));
590 std::lock_guard<std::recursive_mutex> guard(
593 auto type_system_or_err =
595 if (
auto err = type_system_or_err.takeError()) {
597 "Unable to get dynamic array info for UID: {0}");
600 auto ts = *type_system_or_err;
602 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
615 auto type_system_or_err =
617 if (
auto err = type_system_or_err.takeError()) {
619 "Unable to get decl for UID: {0}");
622 auto ts = *type_system_or_err;
624 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
645 auto type_system_or_err =
647 if (
auto err = type_system_or_err.takeError()) {
649 "Unable to get DeclContext for UID: {0}");
653 auto ts = *type_system_or_err;
655 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
676 auto type_system_or_err =
678 if (
auto err = type_system_or_err.takeError()) {
680 "Unable to get DeclContext containing UID: {0}");
684 auto ts = *type_system_or_err;
686 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
699 assert(decl_context);
706 auto type_system_or_err =
708 if (
auto err = type_system_or_err.takeError()) {
710 "Unable to parse decls for context: {0}");
714 auto ts = *type_system_or_err;
716 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
730 SymbolContextItem resolve_scope,
733 uint32_t resolved_flags = 0;
734 if (resolve_scope & eSymbolContextCompUnit ||
735 resolve_scope & eSymbolContextVariable ||
736 resolve_scope & eSymbolContextFunction ||
737 resolve_scope & eSymbolContextBlock ||
738 resolve_scope & eSymbolContextLineEntry) {
741 if (resolved_flags & eSymbolContextVariable) {
747 resolved_flags |= eSymbolContextCompUnit;
751 if (resolve_scope & eSymbolContextFunction ||
752 resolve_scope & eSymbolContextBlock) {
755 m_session_up->findSymbolByAddress(file_vm_addr, PDB_SymType::Function);
757 auto *pdb_func = llvm::dyn_cast<PDBSymbolFunc>(symbol_up.get());
759 auto func_uid = pdb_func->getSymIndexId();
765 resolved_flags |= eSymbolContextFunction;
766 if (resolve_scope & eSymbolContextBlock) {
768 file_vm_addr, PDB_SymType::Block);
769 auto block_id = block_symbol ? block_symbol->getSymIndexId()
773 resolved_flags |= eSymbolContextBlock;
779 if (resolve_scope & eSymbolContextLineEntry) {
782 if (line_table->FindLineEntryByAddress(addr, sc.
line_entry))
783 resolved_flags |= eSymbolContextLineEntry;
787 return resolved_flags;
794 const size_t old_size = sc_list.
GetSize();
796 const uint32_t line = src_location_spec.
GetLine().value_or(0);
797 if (resolve_scope & lldb::eSymbolContextCompUnit) {
802 auto compilands =
m_session_up->findCompilandsForSourceFile(
803 file_spec.
GetPath(), PDB_NameSearchFlags::NS_CaseInsensitive);
810 while (
auto compiland = compilands->getNext()) {
816 std::string source_file = compiland->getSourceFileFullPath();
817 if (source_file.empty())
819 FileSpec this_spec(source_file, FileSpec::Style::windows);
834 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock |
835 eSymbolContextLineEntry)) {
838 if ((resolve_scope & eSymbolContextLineEntry) && !has_line_table) {
842 assert(line &&
"Couldn't get all line entries!\n");
848 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) {
855 uint32_t num_line_entries = line_table->GetSize();
861 for (uint32_t line_idx = 0; line && line_idx < num_line_entries;
863 if (!line_table->GetLineEntryAtIndex(line_idx, sc.
line_entry))
872 file_vm_addr, PDB_SymType::Function);
874 auto func_uid = symbol_up->getSymIndexId();
877 auto pdb_func = llvm::dyn_cast<PDBSymbolFunc>(symbol_up.get());
882 if (sc.
function && (resolve_scope & eSymbolContextBlock)) {
889 }
else if (has_line_table) {
901 return sc_list.
GetSize() - old_size;
909 while (
auto symbol_up = result_up->getNext())
910 if (
auto addr = symbol_up->getRawSymbol().getVirtualAddress())
919 const llvm::pdb::PDBSymbolData &pdb_data) {
921 uint32_t var_uid = pdb_data.getSymIndexId();
924 return result->second;
927 bool is_static_member =
false;
928 bool is_external =
false;
929 bool is_artificial =
false;
931 switch (pdb_data.getDataKind()) {
932 case PDB_DataKind::Global:
936 case PDB_DataKind::Local:
939 case PDB_DataKind::FileStatic:
942 case PDB_DataKind::StaticMember:
943 is_static_member =
true;
946 case PDB_DataKind::Member:
949 case PDB_DataKind::Param:
952 case PDB_DataKind::Constant:
959 switch (pdb_data.getLocationType()) {
960 case PDB_LocType::TLS:
963 case PDB_LocType::RegRel: {
965 if (pdb_data.getDataKind() == PDB_DataKind::ObjectPtr) {
967 is_artificial =
true;
975 if (!is_artificial && !pdb_data.isCompilerGenerated()) {
976 if (
auto lines = pdb_data.getLineNumbers()) {
977 if (
auto first_line = lines->getNext()) {
978 uint32_t src_file_id = first_line->getSourceFileId();
979 auto src_file =
m_session_up->getSourceFileById(src_file_id);
981 FileSpec spec(src_file->getFileName());
983 decl.
SetColumn(first_line->getColumnNumber());
984 decl.
SetLine(first_line->getLineNumber());
998 block = &function_block;
1000 context_scope = block;
1002 for (
size_t i = 0, num_ranges = block->
GetNumRanges(); i < num_ranges;
1015 std::make_shared<SymbolFileType>(*
this, pdb_data.getTypeId());
1017 auto var_name = pdb_data.getName();
1019 auto mangled_cstr = mangled.empty() ? nullptr : mangled.c_str();
1025 module_sp, pdb_data, ranges, is_constant),
1028 var_sp = std::make_shared<Variable>(
1029 var_uid, var_name.c_str(), mangled_cstr, type_sp, scope, context_scope,
1030 ranges, &decl, location, is_external, is_artificial, is_constant,
1033 m_variables.insert(std::make_pair(var_uid, var_sp));
1039 const llvm::pdb::PDBSymbol &pdb_symbol,
1041 size_t num_added = 0;
1043 if (
auto pdb_data = llvm::dyn_cast<PDBSymbolData>(&pdb_symbol)) {
1046 auto result =
m_variables.find(pdb_data->getSymIndexId());
1052 if (
auto lexical_parent = pdb_data->getLexicalParent()) {
1053 switch (lexical_parent->getSymTag()) {
1054 case PDB_SymType::Exe:
1057 case PDB_SymType::Compiland: {
1060 if (!local_variable_list_sp) {
1061 local_variable_list_sp = std::make_shared<VariableList>();
1066 case PDB_SymType::Block:
1067 case PDB_SymType::Function: {
1070 lexical_parent->getSymIndexId());
1073 if (!local_variable_list_sp) {
1074 local_variable_list_sp = std::make_shared<VariableList>();
1085 if (local_variable_list_sp) {
1087 local_variable_list_sp->AddVariableIfUnique(var_sp);
1099 if (
auto results = pdb_symbol.findAllChildren()) {
1100 while (
auto result = results->getNext())
1120 uint32_t matches = 0;
1121 size_t old_size = variables.
GetSize();
1122 while (
auto result = results->getNext()) {
1123 auto pdb_data = llvm::dyn_cast<PDBSymbolData>(result.get());
1124 if (max_matches > 0 && matches >= max_matches)
1140 if (parent_decl_ctx.
IsValid() &&
1145 matches = variables.
GetSize() - old_size;
1159 uint32_t matches = 0;
1160 size_t old_size = variables.
GetSize();
1161 while (
auto pdb_data = results->getNext()) {
1162 if (max_matches > 0 && matches >= max_matches)
1165 auto var_name = pdb_data->getName();
1166 if (var_name.empty())
1180 matches = variables.
GetSize() - old_size;
1185 bool include_inlines,
1202 auto pdb_func_up =
m_session_up->getConcreteSymbolById<PDBSymbolFunc>(uid);
1203 if (!pdb_func_up && !(include_inlines && pdb_func_up->hasInlineAttribute()))
1212 std::map<uint64_t, uint32_t> addr_ids;
1215 while (
auto pdb_func_up = results_up->getNext()) {
1216 if (pdb_func_up->isCompilerGenerated())
1219 auto name = pdb_func_up->getName();
1220 auto demangled_name = pdb_func_up->getUndecoratedName();
1221 if (name.empty() && demangled_name.empty())
1224 auto uid = pdb_func_up->getSymIndexId();
1225 if (!demangled_name.empty() && pdb_func_up->getVirtualAddress())
1226 addr_ids.insert(std::make_pair(pdb_func_up->getVirtualAddress(), uid));
1228 if (
auto parent = pdb_func_up->getClassParent()) {
1239 if (!basename.empty())
1245 if (!demangled_name.empty())
1253 if (!basename.empty())
1258 if (name ==
"main") {
1261 if (!demangled_name.empty() && name != demangled_name) {
1265 }
else if (!demangled_name.empty()) {
1274 if (
auto results_up =
1276 while (
auto pub_sym_up = results_up->getNext()) {
1277 if (!pub_sym_up->isFunction())
1279 auto name = pub_sym_up->getName();
1285 if (
auto vm_addr = pub_sym_up->getVirtualAddress()) {
1286 if (
auto it = addr_ids.find(vm_addr); it != addr_ids.end())
1305 bool include_inlines,
1310 lldbassert((name_type_mask & eFunctionNameTypeAuto) == 0);
1312 if (name_type_mask & eFunctionNameTypeFull)
1315 if (name_type_mask == eFunctionNameTypeNone)
1322 if (name_type_mask & eFunctionNameTypeFull ||
1323 name_type_mask & eFunctionNameTypeBase ||
1324 name_type_mask & eFunctionNameTypeMethod) {
1327 std::set<uint32_t> resolved_ids;
1328 auto ResolveFn = [
this, &name, parent_decl_ctx, include_inlines, &sc_list,
1330 std::vector<uint32_t> ids;
1331 if (!Names.GetValues(name, ids))
1334 for (uint32_t
id : ids) {
1335 if (resolved_ids.find(
id) != resolved_ids.end())
1338 if (parent_decl_ctx.IsValid() &&
1343 resolved_ids.insert(
id);
1346 if (name_type_mask & eFunctionNameTypeFull) {
1351 if (name_type_mask & eFunctionNameTypeBase)
1353 if (name_type_mask & eFunctionNameTypeMethod)
1359 bool include_inlines,
1367 std::set<uint32_t> resolved_ids;
1368 auto ResolveFn = [®ex, include_inlines, &sc_list, &resolved_ids,
1370 std::vector<uint32_t> ids;
1371 if (Names.GetValues(regex, ids)) {
1372 for (
auto id : ids) {
1373 if (resolved_ids.find(
id) == resolved_ids.end())
1375 resolved_ids.insert(
id);
1384 const std::string &scope_qualified_name,
1385 std::vector<lldb_private::ConstString> &mangled_names) {}
1388 std::set<lldb::addr_t> sym_addresses;
1400 while (
auto pub_symbol = results->getNext()) {
1401 auto section_id = pub_symbol->getAddressSection();
1403 auto section = section_list->FindSectionByID(section_id);
1407 auto offset = pub_symbol->getAddressOffset();
1409 auto file_addr = section->GetFileAddress() + offset;
1410 if (sym_addresses.find(file_addr) != sym_addresses.end())
1412 sym_addresses.insert(file_addr);
1414 auto size = pub_symbol->getLength();
1416 Symbol(pub_symbol->getSymIndexId(),
1417 pub_symbol->getName().c_str(),
1436 auto type_system_or_err =
1438 if (
auto err = type_system_or_err.takeError()) {
1440 "Unable to dump ClangAST: {0}");
1444 auto ts = *type_system_or_err;
1446 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
1447 if (!clang_type_system)
1461 PDB_SymType tags_to_search[] = {PDB_SymType::Enum, PDB_SymType::Typedef,
1463 std::unique_ptr<IPDBEnumSymbols> results;
1465 uint32_t matches = 0;
1467 for (
auto tag : tags_to_search) {
1472 while (
auto result = results->getNext()) {
1473 if (max_matches > 0 && matches >= max_matches)
1476 std::string type_name;
1477 if (
auto enum_type = llvm::dyn_cast<PDBSymbolTypeEnum>(result.get()))
1478 type_name = enum_type->getName();
1479 else if (
auto typedef_type =
1480 llvm::dyn_cast<PDBSymbolTypeTypedef>(result.get()))
1481 type_name = typedef_type->getName();
1482 else if (
auto class_type = llvm::dyn_cast<PDBSymbolTypeUDT>(result.get()))
1483 type_name = class_type->getName();
1490 if (!regex.
Execute(type_name))
1498 auto iter =
m_types.find(result->getSymIndexId());
1501 types.
Insert(iter->second);
1516 std::unique_ptr<IPDBEnumSymbols> results;
1518 if (basename.empty())
1524 while (
auto result = results->getNext()) {
1526 switch (result->getSymTag()) {
1527 case PDB_SymType::Enum:
1528 case PDB_SymType::UDT:
1529 case PDB_SymType::Typedef:
1538 result->getRawSymbol().getName()) != basename)
1546 auto iter =
m_types.find(result->getSymIndexId());
1550 ConstString name = iter->second->GetQualifiedName();
1554 if (type_results.
Done(query))
1563 bool can_parse =
false;
1564 switch (pdb_symbol.getSymTag()) {
1565 case PDB_SymType::ArrayType:
1566 can_parse = ((type_mask & eTypeClassArray) != 0);
1568 case PDB_SymType::BuiltinType:
1569 can_parse = ((type_mask & eTypeClassBuiltin) != 0);
1571 case PDB_SymType::Enum:
1572 can_parse = ((type_mask & eTypeClassEnumeration) != 0);
1574 case PDB_SymType::Function:
1575 case PDB_SymType::FunctionSig:
1576 can_parse = ((type_mask & eTypeClassFunction) != 0);
1578 case PDB_SymType::PointerType:
1579 can_parse = ((type_mask & (eTypeClassPointer | eTypeClassBlockPointer |
1580 eTypeClassMemberPointer)) != 0);
1582 case PDB_SymType::Typedef:
1583 can_parse = ((type_mask & eTypeClassTypedef) != 0);
1585 case PDB_SymType::UDT: {
1586 auto *udt = llvm::dyn_cast<PDBSymbolTypeUDT>(&pdb_symbol);
1588 can_parse = (udt->getUdtKind() != PDB_UdtType::Interface &&
1589 ((type_mask & (eTypeClassClass | eTypeClassStruct |
1590 eTypeClassUnion)) != 0));
1598 if (!llvm::is_contained(type_collection, type))
1599 type_collection.push_back(type);
1603 auto results_up = pdb_symbol.findAllChildren();
1604 while (
auto symbol_up = results_up->getNext())
1609 TypeClass type_mask,
1630 for (
auto type : type_collection) {
1631 type->GetForwardCompilerType();
1632 type_list.
Insert(type->shared_from_this());
1636llvm::Expected<lldb::TypeSystemSP>
1638 auto type_system_or_err =
1639 m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language);
1640 if (type_system_or_err) {
1641 if (
auto ts = *type_system_or_err)
1642 ts->SetSymbolFile(
this);
1644 return type_system_or_err;
1648 auto type_system_or_err =
1650 if (
auto err = type_system_or_err.takeError()) {
1652 "Unable to get PDB AST parser: {0}");
1656 auto ts = *type_system_or_err;
1657 auto *clang_type_system =
1658 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
1659 if (!clang_type_system)
1662 return clang_type_system->GetPDBParser();
1669 auto type_system_or_err =
1671 if (
auto err = type_system_or_err.takeError()) {
1673 "Unable to find namespace {1}: {0}", name.
AsCString());
1676 auto ts = *type_system_or_err;
1677 auto *clang_type_system =
1678 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
1679 if (!clang_type_system)
1686 clang::DeclContext *decl_context =
nullptr;
1687 if (parent_decl_ctx)
1688 decl_context =
static_cast<clang::DeclContext *
>(
1691 auto namespace_decl =
1693 if (!namespace_decl)
1696 return clang_type_system->CreateDeclContext(namespace_decl);
1709 return found_cu->second;
1716 auto details = compiland_up->findOneChild<PDBSymbolCompilandDetails>();
1725 std::string path = compiland_up->getSourceFileFullPath();
1732 auto cu_sp = std::make_shared<CompileUnit>(
m_objfile_sp->GetModule(),
nullptr,
1733 path.c_str(),
id, lang, optimized);
1747 uint32_t match_line) {
1756 llvm::DenseMap<uint32_t, uint32_t> index_map;
1758 auto line_table = std::make_unique<LineTable>(&comp_unit);
1761 auto files =
m_session_up->getSourceFilesForCompiland(*compiland_up);
1767 while (
auto file = files->getNext()) {
1768 std::unique_ptr<LineSequence> sequence(
1769 line_table->CreateLineSequenceContainer());
1770 auto lines =
m_session_up->findLineNumbers(*compiland_up, *file);
1773 int entry_count = lines->getChildCount();
1776 uint32_t prev_length;
1778 uint32_t prev_source_idx;
1780 for (
int i = 0; i < entry_count; ++i) {
1781 auto line = lines->getChildAtIndex(i);
1783 uint64_t lno = line->getLineNumber();
1784 uint64_t addr = line->getVirtualAddress();
1785 uint32_t length = line->getLength();
1786 uint32_t source_id = line->getSourceFileId();
1787 uint32_t col = line->getColumnNumber();
1788 uint32_t source_idx = index_map[source_id];
1792 bool is_gap = (i > 0) && (prev_addr + prev_length < addr);
1797 if (is_gap && ShouldAddLine(match_line, prev_line, prev_length)) {
1798 line_table->AppendLineEntryToSequence(
1799 sequence.get(), prev_addr + prev_length, prev_line, 0,
1800 prev_source_idx,
false,
false,
false,
false,
true);
1802 line_table->InsertSequence(sequence.get());
1803 sequence = line_table->CreateLineSequenceContainer();
1806 if (ShouldAddLine(match_line, lno, length)) {
1807 bool is_statement = line->isStatement();
1808 bool is_prologue =
false;
1809 bool is_epilogue =
false;
1811 m_session_up->findSymbolByAddress(addr, PDB_SymType::Function);
1813 auto prologue = func->findOneChild<PDBSymbolFuncDebugStart>();
1815 is_prologue = (addr == prologue->getVirtualAddress());
1817 auto epilogue = func->findOneChild<PDBSymbolFuncDebugEnd>();
1819 is_epilogue = (addr == epilogue->getVirtualAddress());
1822 line_table->AppendLineEntryToSequence(sequence.get(), addr, lno, col,
1823 source_idx, is_statement,
false,
1824 is_prologue, is_epilogue,
false);
1828 prev_length = length;
1830 prev_source_idx = source_idx;
1833 if (entry_count > 0 && ShouldAddLine(match_line, prev_line, prev_length)) {
1835 line_table->AppendLineEntryToSequence(
1836 sequence.get(), prev_addr + prev_length, prev_line, 0,
1837 prev_source_idx,
false,
false,
false,
false,
true);
1840 line_table->InsertSequence(sequence.get());
1843 if (line_table->GetSize()) {
1851 const PDBSymbolCompiland &compiland,
1852 llvm::DenseMap<uint32_t, uint32_t> &index_map)
const {
1858 auto source_files =
m_session_up->getSourceFilesForCompiland(compiland);
1863 while (
auto file = source_files->getNext()) {
1864 uint32_t source_id = file->getUniqueId();
1865 index_map[source_id] = index++;
1877 m_session_up->findLineNumbersByAddress(file_vm_addr, 1)) {
1878 if (
auto first_line = lines->getNext())
1883 if (
auto sec_contribs =
m_session_up->getSectionContribs()) {
1884 while (
auto section = sec_contribs->getNext()) {
1885 auto va = section->getVirtualAddress();
1886 if (file_vm_addr >= va && file_vm_addr < va + section->getLength())
1896 auto func_name = pdb_func.getName();
1897 auto func_undecorated_name = pdb_func.getUndecoratedName();
1898 std::string func_decorated_name;
1903 if (!func_undecorated_name.empty()) {
1905 PDB_SymType::PublicSymbol, func_undecorated_name,
1906 PDB_NameSearchFlags::NS_UndecoratedName);
1908 while (
auto symbol_up = result_up->getNext()) {
1911 if (
auto *pdb_public_sym =
1912 llvm::dyn_cast_or_null<PDBSymbolPublicSymbol>(
1914 if (pdb_public_sym->isFunction()) {
1915 func_decorated_name = pdb_public_sym->getName();
1922 if (!func_decorated_name.empty()) {
1944 if (!func_undecorated_name.empty() &&
1947 }
else if (!func_undecorated_name.empty()) {
1949 }
else if (!func_name.empty())
1961 if (!decl_ctx_type_system)
1965 if (
auto err = type_system_or_err.takeError()) {
1967 GetLog(LLDBLog::Symbols), std::move(err),
1968 "Unable to determine if DeclContext matches this symbol file: {0}");
1972 if (decl_ctx_type_system == type_system_or_err->get())
1979 static const auto pred_upper = [](uint32_t lhs,
SecContribInfo rhs) {
1980 return lhs < rhs.Offset;
1985 if (
auto SecContribs =
m_session_up->getSectionContribs()) {
1986 while (
auto SectionContrib = SecContribs->getNext()) {
1987 auto comp_id = SectionContrib->getCompilandId();
1991 auto sec = SectionContrib->getAddressSection();
1994 auto offset = SectionContrib->getAddressOffset();
1995 auto it = llvm::upper_bound(sec_cs, offset, pred_upper);
1997 auto size = SectionContrib->getLength();
1998 sec_cs.insert(it, {offset, size, comp_id});
2004 if (
auto Lines = data.getLineNumbers()) {
2005 if (
auto FirstLine = Lines->getNext())
2006 return FirstLine->getCompilandId();
2010 uint32_t DataSection = data.getAddressSection();
2011 uint32_t DataOffset = data.getAddressOffset();
2012 if (DataSection == 0) {
2013 if (
auto RVA = data.getRelativeVirtualAddress())
2014 m_session_up->addressForRVA(RVA, DataSection, DataOffset);
2020 auto it = llvm::upper_bound(sec_cs, DataOffset, pred_upper);
2021 if (it != sec_cs.begin()) {
2023 if (DataOffset < it->Offset + it->Size)
2024 return it->CompilandId;
2028 auto LexParentId = data.getLexicalParentId();
2029 while (
auto LexParent =
m_session_up->getSymbolById(LexParentId)) {
2030 if (LexParent->getSymTag() == PDB_SymType::Exe)
2032 if (LexParent->getSymTag() == PDB_SymType::Compiland)
2034 LexParentId = LexParent->getRawSymbol().getLexicalParentId();
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG_ERROR(log, error,...)
DWARFExpression ConvertPDBLocationToDWARFExpression(ModuleSP module, const PDBSymbolData &symbol, const Variable::RangeList &ranges, bool &is_constant)
#define LLDB_PLUGIN_DEFINE(PluginName)
static lldb::LanguageType TranslateLanguage(PDB_Lang lang)
static size_t ParseFunctionBlocksForPDBSymbol(uint64_t func_file_vm_addr, const llvm::pdb::PDBSymbol *pdb_symbol, lldb_private::Block *parent_block, bool is_top_parent)
static bool ShouldUseNativeReader()
static llvm::StringRef DropScope(llvm::StringRef name)
clang::NamespaceDecl * FindNamespaceDecl(const clang::DeclContext *parent, llvm::StringRef name)
lldb::TypeSP CreateLLDBTypeFromPDBType(const llvm::pdb::PDBSymbol &type)
clang::DeclContext * GetDeclContextForSymbol(const llvm::pdb::PDBSymbol &symbol)
void ParseDeclsForDeclContext(const clang::DeclContext *decl_context)
bool CompleteTypeFromPDB(lldb_private::CompilerType &compiler_type)
clang::Decl * GetDeclForSymbol(const llvm::pdb::PDBSymbol &symbol)
clang::DeclContext * GetDeclContextContainingSymbol(const llvm::pdb::PDBSymbol &symbol)
lldb_private::CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override
std::unique_ptr< llvm::pdb::PDBSymbolCompiland > GetPDBCompilandByUID(uint32_t uid)
static lldb_private::SymbolFile * CreateInstance(lldb::ObjectFileSP objfile_sp)
std::unique_ptr< llvm::pdb::IPDBSession > m_session_up
lldb::CompUnitSP GetCompileUnitContainsAddress(const lldb_private::Address &so_addr)
void GetMangledNamesForFunction(const std::string &scope_qualified_name, std::vector< lldb_private::ConstString > &mangled_names) override
void GetTypes(lldb_private::SymbolContextScope *sc_scope, lldb::TypeClass type_mask, lldb_private::TypeList &type_list) override
void FindFunctions(const lldb_private::Module::LookupInfo &lookup_info, const lldb_private::CompilerDeclContext &parent_decl_ctx, bool include_inlines, lldb_private::SymbolContextList &sc_list) override
lldb_private::CompilerDeclContext FindNamespace(lldb_private::ConstString name, const lldb_private::CompilerDeclContext &parent_decl_ctx, bool only_root_namespaces) override
Finds a namespace of name name and whose parent context is parent_decl_ctx.
std::unique_ptr< llvm::pdb::PDBSymbolExe > m_global_scope_up
llvm::DenseMap< uint32_t, lldb::CompUnitSP > m_comp_units
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.
size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override
static llvm::StringRef GetPluginNameStatic()
bool ParseCompileUnitLineTable(lldb_private::CompileUnit &comp_unit, uint32_t match_line)
void BuildSupportFileIdToSupportFileIndexMap(const llvm::pdb::PDBSymbolCompiland &pdb_compiland, llvm::DenseMap< uint32_t, uint32_t > &index_map) const
lldb_private::Function * ParseCompileUnitFunctionForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func, lldb_private::CompileUnit &comp_unit)
lldb_private::UniqueCStringMap< uint32_t > m_func_base_names
bool ParseImportedModules(const lldb_private::SymbolContext &sc, std::vector< lldb_private::SourceModule > &imported_modules) override
void FindGlobalVariables(lldb_private::ConstString name, const lldb_private::CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, lldb_private::VariableList &variables) override
size_t ParseVariablesForContext(const lldb_private::SymbolContext &sc) override
bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override
void GetCompileUnitIndex(const llvm::pdb::PDBSymbolCompiland &pdb_compiland, uint32_t &index)
llvm::DenseMap< uint32_t, lldb::TypeSP > m_types
void AddSymbols(lldb_private::Symtab &symtab) override
size_t ParseBlocksRecursive(lldb_private::Function &func) override
void CacheFunctionNames()
llvm::DenseMap< uint64_t, std::string > m_public_names
size_t ParseVariables(const lldb_private::SymbolContext &sc, const llvm::pdb::PDBSymbol &pdb_data, lldb_private::VariableList *variable_list=nullptr)
lldb::LanguageType ParseLanguage(lldb_private::CompileUnit &comp_unit) override
bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override
void InitializeObject() override
Initialize the SymbolFile object.
uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr, lldb::SymbolContextItem resolve_scope, lldb_private::SymbolContext &sc) override
PDBASTParser * GetPDBAstParser()
uint32_t CalculateNumCompileUnits() override
SymbolFilePDB(lldb::ObjectFileSP objfile_sp)
~SymbolFilePDB() override
uint32_t GetCompilandId(const llvm::pdb::PDBSymbolData &data)
llvm::pdb::IPDBSession & GetPDBSession()
bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit, lldb_private::SupportFileList &support_files) override
static char ID
LLVM RTTI support.
void FindTypesByRegex(const lldb_private::RegularExpression ®ex, uint32_t max_matches, lldb_private::TypeMap &types)
size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override
lldb::CompUnitSP ParseCompileUnitForUID(uint32_t id, uint32_t index=UINT32_MAX)
lldb_private::Mangled GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func)
std::vector< lldb_private::Type * > TypeCollection
void ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override
void DumpClangAST(lldb_private::Stream &s) override
void GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol, uint32_t type_mask, TypeCollection &type_collection)
bool CompleteType(lldb_private::CompilerType &compiler_type) override
static void DebuggerInitialize(lldb_private::Debugger &debugger)
static llvm::StringRef GetPluginDescriptionStatic()
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override
std::string GetMangledForPDBData(const llvm::pdb::PDBSymbolData &pdb_data)
lldb_private::Type * ResolveTypeUID(lldb::user_id_t type_uid) override
lldb_private::UniqueCStringMap< uint32_t > m_func_full_names
lldb_private::UniqueCStringMap< uint32_t > m_func_method_names
bool DeclContextMatchesThisSymbolFile(const lldb_private::CompilerDeclContext &decl_ctx)
lldb_private::CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override
void FindTypes(const lldb_private::TypeQuery &match, lldb_private::TypeResults &results) override
Find types using a type-matching object that contains all search parameters.
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
SecContribsMap m_sec_contribs
lldb::VariableSP ParseVariableForPDBData(const lldb_private::SymbolContext &sc, const llvm::pdb::PDBSymbolData &pdb_data)
bool ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func, bool include_inlines, lldb_private::SymbolContextList &sc_list)
uint32_t CalculateAbilities() override
llvm::DenseMap< uint32_t, lldb::VariableSP > m_variables
lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override
A section + offset based address range class.
Address & GetBaseAddress()
Get accessor for the base address of the range.
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
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.
bool GetRangeAtIndex(uint32_t range_idx, AddressRange &range)
lldb::BlockSP CreateChild(lldb::user_id_t uid)
Creates a block with the specified UID uid.
Block * FindBlockByID(lldb::user_id_t block_id)
void SetVariableList(lldb::VariableListSP &variable_list_sp)
Set accessor for the variable list.
size_t GetNumRanges() const
void SetDidParseVariables(bool b, bool set_children)
void AddRange(const Range &range)
Add a new offset range to this block.
static bool IsCPPMangledName(llvm::StringRef name)
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.
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.
lldb::FunctionSP FindFunctionByUID(lldb::user_id_t uid)
Finds a function by user ID.
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.
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
bool IsEmpty() const
Test for empty string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
A class to manage flag bits.
A class that describes the declaration location of a lldb object.
void SetLine(uint32_t line)
Set accessor for the declaration line number.
void SetColumn(uint16_t column)
Set accessor for the declaration column number.
void SetFile(const FileSpec &file_spec)
Set accessor for the declaration file specification.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
const ConstString & GetDirectory() const
Directory string const get accessor.
static int Compare(const FileSpec &lhs, const FileSpec &rhs, bool full)
Compare two FileSpec objects.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
A class that describes a function.
Block & GetBlock(bool can_create)
Get accessor for the block list.
A class that handles mangled names.
void SetDemangledName(ConstString name)
ConstString GetDemangledName() const
Demangled name get accessor.
void SetMangledName(ConstString name)
void SetValue(ConstString name)
Set the string value in this object.
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 bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
void Append(const Entry &entry)
bool IsValid() const
Test if this object contains a valid regular expression.
bool Execute(llvm::StringRef string, llvm::SmallVectorImpl< llvm::StringRef > *matches=nullptr) const
Execute a regular expression match using the compiled regular expression that is already in this obje...
"lldb/Core/SourceLocationSpec.h" A source location specifier class.
std::optional< uint32_t > GetLine() const
bool GetCheckInlines() const
FileSpec GetFileSpec() const
A stream class that can stream formatted output to a file.
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
A list of support files for a CompileUnit.
bool AppendIfUnique(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...
virtual CompileUnit * CalculateSymbolContextCompileUnit()
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.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
LineEntry line_entry
The LineEntry for a given query.
Containing protected virtual methods for child classes to override.
ObjectFile * GetObjectFile() override
lldb::ObjectFileSP m_objfile_sp
void SetCompileUnitAtIndex(uint32_t idx, const lldb::CompUnitSP &cu_sp)
uint32_t GetNumCompileUnits() override
Provides public interface for all SymbolFiles.
virtual std::recursive_mutex & GetModuleMutex() const
Symbols file subclasses should override this to return the Module that owns the TypeSystem that this ...
lldb::addr_t GetFileAddress() const
Symbol * SymbolAtIndex(size_t idx)
uint32_t AddSymbol(const Symbol &symbol)
size_t GetNumSymbols() const
void Insert(const lldb::TypeSP &type)
void Insert(const lldb::TypeSP &type)
A class that contains all state required for type lookups.
std::vector< lldb_private::CompilerContext > & GetContextRef()
Access the internal compiler context array.
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.
CompilerDecl GetCompilerDecl(clang::Decl *decl)
Creates a CompilerDecl from the given Decl with the current TypeSystemClang instance as its typesyste...
void Dump(llvm::raw_ostream &output) override
CompilerDeclContext CreateDeclContext(clang::DeclContext *ctx)
Creates a CompilerDeclContext from the given DeclContext with the current TypeSystemClang instance as...
PDBASTParser * GetPDBParser() override
Interface for representing a type system.
virtual lldb::LanguageType GetMinimumLanguage(lldb::opaque_compiler_type_t type)=0
void Append(ConstString unique_cstr, const T &value)
bool AddVariableIfUnique(const lldb::VariableSP &var_sp)
#define LLDB_INVALID_ADDRESS
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::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
@ eValueTypeConstResult
constant result variables
@ eValueTypeVariableLocal
function local variables
@ eValueTypeVariableArgument
function argument variables
@ eValueTypeVariableStatic
static variable
@ eValueTypeVariableThreadLocal
thread local storage variable
AddressRange range
The section offset address range for this line entry.
lldb::user_id_t GetID() const
Get accessor for the user ID.