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"
85 case PDB_Lang::ObjCpp:
92bool ShouldAddLine(uint32_t requested_line, uint32_t actual_line,
93 uint32_t addr_length) {
94 return ((requested_line == 0 || actual_line == requested_line) &&
101#if LLVM_ENABLE_DIA_SDK
102 llvm::StringRef use_native = ::getenv(
"LLDB_USE_NATIVE_PDB_READER");
103 if (!use_native.equals_insensitive(
"on") &&
104 !use_native.equals_insensitive(
"yes") &&
105 !use_native.equals_insensitive(
"1") &&
106 !use_native.equals_insensitive(
"true"))
134 return "Microsoft PDB debug symbol file reader.";
143 :
SymbolFileCommon(std::move(objfile_sp)), m_session_up(), m_global_scope_up() {}
148 uint32_t abilities = 0;
154 std::string exePath =
m_objfile_sp->GetFileSpec().GetPath();
155 auto error = loadDataForEXE(PDB_ReaderType::DIA, llvm::StringRef(exePath),
158 llvm::consumeError(std::move(
error));
163 FileSpec symfile = module_sp->GetSymbolFileFileSpec();
166 error = loadDataForPDB(PDB_ReaderType::DIA,
169 llvm::consumeError(std::move(
error));
180 while (
auto table_up = enum_tables_up->getNext()) {
181 if (table_up->getItemCount() == 0)
183 auto type = table_up->getTableType();
185 case PDB_TableType::Symbols:
191 case PDB_TableType::LineNumbers:
224 uint32_t compile_unit_count = compilands->getChildCount();
229 auto last_compiland_up = compilands->getChildAtIndex(compile_unit_count - 1);
231 std::string name = last_compiland_up->getName();
232 if (name ==
"* Linker *")
233 --compile_unit_count;
234 return compile_unit_count;
238 const llvm::pdb::PDBSymbolCompiland &pdb_compiland, uint32_t &index) {
242 auto uid = pdb_compiland.getSymIndexId();
244 auto compiland_up = results_up->getChildAtIndex(cu_idx);
247 if (compiland_up->getSymIndexId() == uid) {
255std::unique_ptr<llvm::pdb::PDBSymbolCompiland>
257 return m_session_up->getConcreteSymbolById<PDBSymbolCompiland>(uid);
270 auto compiland_up = results->getChildAtIndex(index);
281 auto details = compiland_up->findOneChild<PDBSymbolCompilandDetails>();
293 auto file_vm_addr = pdb_func.getVirtualAddress();
297 auto func_length = pdb_func.getLength();
308 user_id_t func_type_uid = pdb_func.getSignatureId();
313 std::make_shared<Function>(&comp_unit, pdb_func.getSymIndexId(),
314 func_type_uid, mangled, func_type, func_range);
320 if (
auto err = type_system_or_err.takeError()) {
322 "Unable to parse PDBFunc: {0}");
326 auto ts = *type_system_or_err;
328 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
329 if (!clang_type_system)
333 return func_sp.get();
338 size_t func_added = 0;
342 auto results_up = compiland_up->findAllChildren<PDBSymbolFunc>();
345 while (
auto pdb_func_up = results_up->getNext()) {
379 auto files =
m_session_up->getSourceFilesForCompiland(*compiland_up);
380 if (!files || files->getChildCount() == 0)
383 while (
auto file = files->getNext()) {
384 FileSpec spec(file->getFileName(), FileSpec::Style::windows);
393 std::vector<SourceModule> &imported_modules) {
399 uint64_t func_file_vm_addr,
const llvm::pdb::PDBSymbol *pdb_symbol,
401 assert(pdb_symbol && parent_block);
403 size_t num_added = 0;
404 switch (pdb_symbol->getSymTag()) {
405 case PDB_SymType::Block:
406 case PDB_SymType::Function: {
407 Block *block =
nullptr;
408 auto &raw_sym = pdb_symbol->getRawSymbol();
409 if (
auto *pdb_func = llvm::dyn_cast<PDBSymbolFunc>(pdb_symbol)) {
410 if (pdb_func->hasNoInlineAttribute())
413 block = parent_block;
416 }
else if (llvm::isa<PDBSymbolBlock>(pdb_symbol)) {
417 auto uid = pdb_symbol->getSymIndexId();
420 if (raw_sym.getVirtualAddress() < func_file_vm_addr)
423 auto block_sp = std::make_shared<Block>(pdb_symbol->getSymIndexId());
425 block = block_sp.get();
427 llvm_unreachable(
"Unexpected PDB symbol!");
430 raw_sym.getVirtualAddress() - func_file_vm_addr, raw_sym.getLength()));
434 auto results_up = pdb_symbol->findAllChildren();
437 while (
auto symbol_up = results_up->getNext()) {
439 func_file_vm_addr, symbol_up.get(), block,
false);
450 size_t num_added = 0;
451 auto uid = func.
GetID();
452 auto pdb_func_up =
m_session_up->getConcreteSymbolById<PDBSymbolFunc>(uid);
457 pdb_func_up->getVirtualAddress(), pdb_func_up.get(), &parent_block,
true);
464 size_t num_added = 0;
469 auto ParseTypesByTagFn = [&num_added,
this](
const PDBSymbol &raw_sym) {
470 std::unique_ptr<IPDBEnumSymbols> results;
471 PDB_SymType tags_to_search[] = {PDB_SymType::Enum, PDB_SymType::Typedef,
473 for (
auto tag : tags_to_search) {
474 results = raw_sym.findAllChildren(tag);
475 if (!results || results->getChildCount() == 0)
477 while (
auto symbol = results->getNext()) {
478 switch (symbol->getSymTag()) {
479 case PDB_SymType::Enum:
480 case PDB_SymType::UDT:
481 case PDB_SymType::Typedef:
493 type->GetFullCompilerType();
500 ParseTypesByTagFn(*compiland);
505 static bool parse_all_global_types =
false;
506 if (!parse_all_global_types) {
508 parse_all_global_types =
true;
519 size_t num_added = 0;
521 auto pdb_func =
m_session_up->getConcreteSymbolById<PDBSymbolFunc>(
537 if (results && results->getChildCount()) {
538 while (
auto result = results->getNext()) {
565 auto find_result =
m_types.find(type_uid);
566 if (find_result !=
m_types.end())
567 return find_result->second.get();
569 auto type_system_or_err =
571 if (
auto err = type_system_or_err.takeError()) {
573 "Unable to ResolveTypeUID: {0}");
577 auto ts = *type_system_or_err;
579 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
580 if (!clang_type_system)
587 if (pdb_type ==
nullptr)
592 m_types.insert(std::make_pair(type_uid, result));
603 std::lock_guard<std::recursive_mutex> guard(
606 auto type_system_or_err =
608 if (
auto err = type_system_or_err.takeError()) {
610 "Unable to get dynamic array info for UID: {0}");
613 auto ts = *type_system_or_err;
615 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
628 auto type_system_or_err =
630 if (
auto err = type_system_or_err.takeError()) {
632 "Unable to get decl for UID: {0}");
635 auto ts = *type_system_or_err;
637 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
658 auto type_system_or_err =
660 if (
auto err = type_system_or_err.takeError()) {
662 "Unable to get DeclContext for UID: {0}");
666 auto ts = *type_system_or_err;
668 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
689 auto type_system_or_err =
691 if (
auto err = type_system_or_err.takeError()) {
693 "Unable to get DeclContext containing UID: {0}");
697 auto ts = *type_system_or_err;
699 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
712 assert(decl_context);
719 auto type_system_or_err =
721 if (
auto err = type_system_or_err.takeError()) {
723 "Unable to parse decls for context: {0}");
727 auto ts = *type_system_or_err;
729 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
743 SymbolContextItem resolve_scope,
746 uint32_t resolved_flags = 0;
747 if (resolve_scope & eSymbolContextCompUnit ||
748 resolve_scope & eSymbolContextVariable ||
749 resolve_scope & eSymbolContextFunction ||
750 resolve_scope & eSymbolContextBlock ||
751 resolve_scope & eSymbolContextLineEntry) {
754 if (resolved_flags & eSymbolContextVariable) {
760 resolved_flags |= eSymbolContextCompUnit;
764 if (resolve_scope & eSymbolContextFunction ||
765 resolve_scope & eSymbolContextBlock) {
768 m_session_up->findSymbolByAddress(file_vm_addr, PDB_SymType::Function);
770 auto *pdb_func = llvm::dyn_cast<PDBSymbolFunc>(symbol_up.get());
772 auto func_uid = pdb_func->getSymIndexId();
778 resolved_flags |= eSymbolContextFunction;
779 if (resolve_scope & eSymbolContextBlock) {
781 file_vm_addr, PDB_SymType::Block);
782 auto block_id = block_symbol ? block_symbol->getSymIndexId()
786 resolved_flags |= eSymbolContextBlock;
792 if (resolve_scope & eSymbolContextLineEntry) {
795 if (line_table->FindLineEntryByAddress(addr, sc.
line_entry))
796 resolved_flags |= eSymbolContextLineEntry;
800 return resolved_flags;
807 const size_t old_size = sc_list.
GetSize();
809 const uint32_t line = src_location_spec.
GetLine().value_or(0);
810 if (resolve_scope & lldb::eSymbolContextCompUnit) {
815 auto compilands =
m_session_up->findCompilandsForSourceFile(
816 file_spec.
GetPath(), PDB_NameSearchFlags::NS_CaseInsensitive);
823 while (
auto compiland = compilands->getNext()) {
829 std::string source_file = compiland->getSourceFileFullPath();
830 if (source_file.empty())
832 FileSpec this_spec(source_file, FileSpec::Style::windows);
847 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock |
848 eSymbolContextLineEntry)) {
851 if ((resolve_scope & eSymbolContextLineEntry) && !has_line_table) {
855 assert(line &&
"Couldn't get all line entries!\n");
861 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) {
868 uint32_t num_line_entries = line_table->GetSize();
874 for (uint32_t line_idx = 0; line && line_idx < num_line_entries;
876 if (!line_table->GetLineEntryAtIndex(line_idx, sc.
line_entry))
885 file_vm_addr, PDB_SymType::Function);
887 auto func_uid = symbol_up->getSymIndexId();
890 auto pdb_func = llvm::dyn_cast<PDBSymbolFunc>(symbol_up.get());
895 if (sc.
function && (resolve_scope & eSymbolContextBlock)) {
902 }
else if (has_line_table) {
914 return sc_list.
GetSize() - old_size;
922 while (
auto symbol_up = result_up->getNext())
923 if (
auto addr = symbol_up->getRawSymbol().getVirtualAddress())
932 const llvm::pdb::PDBSymbolData &pdb_data) {
934 uint32_t var_uid = pdb_data.getSymIndexId();
937 return result->second;
940 bool is_static_member =
false;
941 bool is_external =
false;
942 bool is_artificial =
false;
944 switch (pdb_data.getDataKind()) {
945 case PDB_DataKind::Global:
949 case PDB_DataKind::Local:
952 case PDB_DataKind::FileStatic:
955 case PDB_DataKind::StaticMember:
956 is_static_member =
true;
959 case PDB_DataKind::Member:
962 case PDB_DataKind::Param:
965 case PDB_DataKind::Constant:
972 switch (pdb_data.getLocationType()) {
973 case PDB_LocType::TLS:
976 case PDB_LocType::RegRel: {
978 if (pdb_data.getDataKind() == PDB_DataKind::ObjectPtr) {
980 is_artificial =
true;
988 if (!is_artificial && !pdb_data.isCompilerGenerated()) {
989 if (
auto lines = pdb_data.getLineNumbers()) {
990 if (
auto first_line = lines->getNext()) {
991 uint32_t src_file_id = first_line->getSourceFileId();
992 auto src_file =
m_session_up->getSourceFileById(src_file_id);
994 FileSpec spec(src_file->getFileName());
996 decl.
SetColumn(first_line->getColumnNumber());
997 decl.
SetLine(first_line->getLineNumber());
1009 function_block.
FindBlockByID(pdb_data.getLexicalParentId());
1011 block = &function_block;
1013 context_scope = block;
1015 for (
size_t i = 0, num_ranges = block->
GetNumRanges(); i < num_ranges;
1028 std::make_shared<SymbolFileType>(*
this, pdb_data.getTypeId());
1030 auto var_name = pdb_data.getName();
1032 auto mangled_cstr = mangled.empty() ? nullptr : mangled.c_str();
1038 module_sp, pdb_data, ranges, is_constant),
1041 var_sp = std::make_shared<Variable>(
1042 var_uid, var_name.c_str(), mangled_cstr, type_sp, scope, context_scope,
1043 ranges, &decl, location, is_external, is_artificial, is_constant,
1046 m_variables.insert(std::make_pair(var_uid, var_sp));
1052 const llvm::pdb::PDBSymbol &pdb_symbol,
1054 size_t num_added = 0;
1056 if (
auto pdb_data = llvm::dyn_cast<PDBSymbolData>(&pdb_symbol)) {
1059 auto result =
m_variables.find(pdb_data->getSymIndexId());
1065 if (
auto lexical_parent = pdb_data->getLexicalParent()) {
1066 switch (lexical_parent->getSymTag()) {
1067 case PDB_SymType::Exe:
1070 case PDB_SymType::Compiland: {
1073 if (!local_variable_list_sp) {
1074 local_variable_list_sp = std::make_shared<VariableList>();
1079 case PDB_SymType::Block:
1080 case PDB_SymType::Function: {
1083 lexical_parent->getSymIndexId());
1086 if (!local_variable_list_sp) {
1087 local_variable_list_sp = std::make_shared<VariableList>();
1098 if (local_variable_list_sp) {
1100 local_variable_list_sp->AddVariableIfUnique(var_sp);
1112 if (
auto results = pdb_symbol.findAllChildren()) {
1113 while (
auto result = results->getNext())
1133 uint32_t matches = 0;
1134 size_t old_size = variables.
GetSize();
1135 while (
auto result = results->getNext()) {
1136 auto pdb_data = llvm::dyn_cast<PDBSymbolData>(result.get());
1137 if (max_matches > 0 && matches >= max_matches)
1153 if (parent_decl_ctx.
IsValid() &&
1158 matches = variables.
GetSize() - old_size;
1172 uint32_t matches = 0;
1173 size_t old_size = variables.
GetSize();
1174 while (
auto pdb_data = results->getNext()) {
1175 if (max_matches > 0 && matches >= max_matches)
1178 auto var_name = pdb_data->getName();
1179 if (var_name.empty())
1193 matches = variables.
GetSize() - old_size;
1198 bool include_inlines,
1215 auto pdb_func_up =
m_session_up->getConcreteSymbolById<PDBSymbolFunc>(uid);
1216 if (!pdb_func_up && !(include_inlines && pdb_func_up->hasInlineAttribute()))
1225 std::map<uint64_t, uint32_t> addr_ids;
1228 while (
auto pdb_func_up = results_up->getNext()) {
1229 if (pdb_func_up->isCompilerGenerated())
1232 auto name = pdb_func_up->getName();
1233 auto demangled_name = pdb_func_up->getUndecoratedName();
1234 if (name.empty() && demangled_name.empty())
1237 auto uid = pdb_func_up->getSymIndexId();
1238 if (!demangled_name.empty() && pdb_func_up->getVirtualAddress())
1239 addr_ids.insert(std::make_pair(pdb_func_up->getVirtualAddress(), uid));
1241 if (
auto parent = pdb_func_up->getClassParent()) {
1252 if (!basename.empty())
1258 if (!demangled_name.empty())
1266 if (!basename.empty())
1271 if (name ==
"main") {
1274 if (!demangled_name.empty() && name != demangled_name) {
1278 }
else if (!demangled_name.empty()) {
1287 if (
auto results_up =
1289 while (
auto pub_sym_up = results_up->getNext()) {
1290 if (!pub_sym_up->isFunction())
1292 auto name = pub_sym_up->getName();
1297 auto vm_addr = pub_sym_up->getVirtualAddress();
1300 if (vm_addr && addr_ids.find(vm_addr) != addr_ids.end()) {
1319 bool include_inlines,
1324 lldbassert((name_type_mask & eFunctionNameTypeAuto) == 0);
1326 if (name_type_mask & eFunctionNameTypeFull)
1329 if (name_type_mask == eFunctionNameTypeNone)
1336 if (name_type_mask & eFunctionNameTypeFull ||
1337 name_type_mask & eFunctionNameTypeBase ||
1338 name_type_mask & eFunctionNameTypeMethod) {
1341 std::set<uint32_t> resolved_ids;
1342 auto ResolveFn = [
this, &name, parent_decl_ctx, include_inlines, &sc_list,
1344 std::vector<uint32_t> ids;
1345 if (!Names.GetValues(name, ids))
1348 for (uint32_t
id : ids) {
1349 if (resolved_ids.find(
id) != resolved_ids.end())
1352 if (parent_decl_ctx.IsValid() &&
1357 resolved_ids.insert(
id);
1360 if (name_type_mask & eFunctionNameTypeFull) {
1365 if (name_type_mask & eFunctionNameTypeBase)
1367 if (name_type_mask & eFunctionNameTypeMethod)
1373 bool include_inlines,
1381 std::set<uint32_t> resolved_ids;
1382 auto ResolveFn = [®ex, include_inlines, &sc_list, &resolved_ids,
1384 std::vector<uint32_t> ids;
1385 if (Names.GetValues(regex, ids)) {
1386 for (
auto id : ids) {
1387 if (resolved_ids.find(
id) == resolved_ids.end())
1389 resolved_ids.insert(
id);
1398 const std::string &scope_qualified_name,
1399 std::vector<lldb_private::ConstString> &mangled_names) {}
1402 std::set<lldb::addr_t> sym_addresses;
1414 while (
auto pub_symbol = results->getNext()) {
1415 auto section_id = pub_symbol->getAddressSection();
1417 auto section = section_list->FindSectionByID(section_id);
1421 auto offset = pub_symbol->getAddressOffset();
1423 auto file_addr = section->GetFileAddress() + offset;
1424 if (sym_addresses.find(file_addr) != sym_addresses.end())
1426 sym_addresses.insert(file_addr);
1428 auto size = pub_symbol->getLength();
1430 Symbol(pub_symbol->getSymIndexId(),
1431 pub_symbol->getName().c_str(),
1451 uint32_t max_matches,
1452 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
1460 searched_symbol_files.clear();
1461 searched_symbol_files.insert(
this);
1468 auto type_system_or_err =
1470 if (
auto err = type_system_or_err.takeError()) {
1472 "Unable to dump ClangAST: {0}");
1476 auto ts = *type_system_or_err;
1478 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
1479 if (!clang_type_system)
1493 PDB_SymType tags_to_search[] = {PDB_SymType::Enum, PDB_SymType::Typedef,
1495 std::unique_ptr<IPDBEnumSymbols> results;
1497 uint32_t matches = 0;
1499 for (
auto tag : tags_to_search) {
1504 while (
auto result = results->getNext()) {
1505 if (max_matches > 0 && matches >= max_matches)
1508 std::string type_name;
1509 if (
auto enum_type = llvm::dyn_cast<PDBSymbolTypeEnum>(result.get()))
1510 type_name = enum_type->getName();
1511 else if (
auto typedef_type =
1512 llvm::dyn_cast<PDBSymbolTypeTypedef>(result.get()))
1513 type_name = typedef_type->getName();
1514 else if (
auto class_type = llvm::dyn_cast<PDBSymbolTypeUDT>(result.get()))
1515 type_name = class_type->getName();
1522 if (!regex.
Execute(type_name))
1530 auto iter =
m_types.find(result->getSymIndexId());
1533 types.
Insert(iter->second);
1540 llvm::StringRef name,
1543 std::unique_ptr<IPDBEnumSymbols> results;
1550 uint32_t matches = 0;
1552 while (
auto result = results->getNext()) {
1553 if (max_matches > 0 && matches >= max_matches)
1557 result->getRawSymbol().getName()) != name)
1560 switch (result->getSymTag()) {
1561 case PDB_SymType::Enum:
1562 case PDB_SymType::UDT:
1563 case PDB_SymType::Typedef:
1576 if (parent_decl_ctx.
IsValid() &&
1580 auto iter =
m_types.find(result->getSymIndexId());
1583 types.
Insert(iter->second);
1589 llvm::ArrayRef<CompilerContext> pattern,
LanguageSet languages,
1590 llvm::DenseSet<SymbolFile *> &searched_symbol_files,
1596 bool can_parse =
false;
1597 switch (pdb_symbol.getSymTag()) {
1598 case PDB_SymType::ArrayType:
1599 can_parse = ((type_mask & eTypeClassArray) != 0);
1601 case PDB_SymType::BuiltinType:
1602 can_parse = ((type_mask & eTypeClassBuiltin) != 0);
1604 case PDB_SymType::Enum:
1605 can_parse = ((type_mask & eTypeClassEnumeration) != 0);
1607 case PDB_SymType::Function:
1608 case PDB_SymType::FunctionSig:
1609 can_parse = ((type_mask & eTypeClassFunction) != 0);
1611 case PDB_SymType::PointerType:
1612 can_parse = ((type_mask & (eTypeClassPointer | eTypeClassBlockPointer |
1613 eTypeClassMemberPointer)) != 0);
1615 case PDB_SymType::Typedef:
1616 can_parse = ((type_mask & eTypeClassTypedef) != 0);
1618 case PDB_SymType::UDT: {
1619 auto *udt = llvm::dyn_cast<PDBSymbolTypeUDT>(&pdb_symbol);
1621 can_parse = (udt->getUdtKind() != PDB_UdtType::Interface &&
1622 ((type_mask & (eTypeClassClass | eTypeClassStruct |
1623 eTypeClassUnion)) != 0));
1631 if (!llvm::is_contained(type_collection, type))
1632 type_collection.push_back(type);
1636 auto results_up = pdb_symbol.findAllChildren();
1637 while (
auto symbol_up = results_up->getNext())
1642 TypeClass type_mask,
1663 for (
auto type : type_collection) {
1664 type->GetForwardCompilerType();
1665 type_list.
Insert(type->shared_from_this());
1669llvm::Expected<lldb::TypeSystemSP>
1671 auto type_system_or_err =
1672 m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language);
1673 if (type_system_or_err) {
1674 if (
auto ts = *type_system_or_err)
1675 ts->SetSymbolFile(
this);
1677 return type_system_or_err;
1681 auto type_system_or_err =
1683 if (
auto err = type_system_or_err.takeError()) {
1685 "Unable to get PDB AST parser: {0}");
1689 auto ts = *type_system_or_err;
1690 auto *clang_type_system =
1691 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
1692 if (!clang_type_system)
1695 return clang_type_system->GetPDBParser();
1702 auto type_system_or_err =
1704 if (
auto err = type_system_or_err.takeError()) {
1706 "Unable to find namespace {1}: {0}", name.
AsCString());
1709 auto ts = *type_system_or_err;
1710 auto *clang_type_system =
1711 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
1712 if (!clang_type_system)
1719 clang::DeclContext *decl_context =
nullptr;
1720 if (parent_decl_ctx)
1721 decl_context =
static_cast<clang::DeclContext *
>(
1724 auto namespace_decl =
1726 if (!namespace_decl)
1729 return clang_type_system->CreateDeclContext(namespace_decl);
1742 return found_cu->second;
1749 auto details = compiland_up->findOneChild<PDBSymbolCompilandDetails>();
1758 std::string path = compiland_up->getSourceFileFullPath();
1765 auto cu_sp = std::make_shared<CompileUnit>(
m_objfile_sp->GetModule(),
nullptr,
1766 path.c_str(),
id, lang, optimized);
1780 uint32_t match_line) {
1789 llvm::DenseMap<uint32_t, uint32_t> index_map;
1791 auto line_table = std::make_unique<LineTable>(&comp_unit);
1794 auto files =
m_session_up->getSourceFilesForCompiland(*compiland_up);
1800 while (
auto file = files->getNext()) {
1801 std::unique_ptr<LineSequence> sequence(
1802 line_table->CreateLineSequenceContainer());
1803 auto lines =
m_session_up->findLineNumbers(*compiland_up, *file);
1806 int entry_count = lines->getChildCount();
1809 uint32_t prev_length;
1811 uint32_t prev_source_idx;
1813 for (
int i = 0; i < entry_count; ++i) {
1814 auto line = lines->getChildAtIndex(i);
1816 uint64_t lno = line->getLineNumber();
1817 uint64_t addr = line->getVirtualAddress();
1818 uint32_t length = line->getLength();
1819 uint32_t source_id = line->getSourceFileId();
1820 uint32_t col = line->getColumnNumber();
1821 uint32_t source_idx = index_map[source_id];
1825 bool is_gap = (i > 0) && (prev_addr + prev_length < addr);
1830 if (is_gap && ShouldAddLine(match_line, prev_line, prev_length)) {
1831 line_table->AppendLineEntryToSequence(
1832 sequence.get(), prev_addr + prev_length, prev_line, 0,
1833 prev_source_idx,
false,
false,
false,
false,
true);
1835 line_table->InsertSequence(sequence.get());
1836 sequence = line_table->CreateLineSequenceContainer();
1839 if (ShouldAddLine(match_line, lno, length)) {
1840 bool is_statement = line->isStatement();
1841 bool is_prologue =
false;
1842 bool is_epilogue =
false;
1844 m_session_up->findSymbolByAddress(addr, PDB_SymType::Function);
1846 auto prologue = func->findOneChild<PDBSymbolFuncDebugStart>();
1848 is_prologue = (addr == prologue->getVirtualAddress());
1850 auto epilogue = func->findOneChild<PDBSymbolFuncDebugEnd>();
1852 is_epilogue = (addr == epilogue->getVirtualAddress());
1855 line_table->AppendLineEntryToSequence(sequence.get(), addr, lno, col,
1856 source_idx, is_statement,
false,
1857 is_prologue, is_epilogue,
false);
1861 prev_length = length;
1863 prev_source_idx = source_idx;
1866 if (entry_count > 0 && ShouldAddLine(match_line, prev_line, prev_length)) {
1868 line_table->AppendLineEntryToSequence(
1869 sequence.get(), prev_addr + prev_length, prev_line, 0,
1870 prev_source_idx,
false,
false,
false,
false,
true);
1873 line_table->InsertSequence(sequence.get());
1876 if (line_table->GetSize()) {
1884 const PDBSymbolCompiland &compiland,
1885 llvm::DenseMap<uint32_t, uint32_t> &index_map)
const {
1891 auto source_files =
m_session_up->getSourceFilesForCompiland(compiland);
1896 while (
auto file = source_files->getNext()) {
1897 uint32_t source_id = file->getUniqueId();
1898 index_map[source_id] = index++;
1910 m_session_up->findLineNumbersByAddress(file_vm_addr, 1)) {
1911 if (
auto first_line = lines->getNext())
1916 if (
auto sec_contribs =
m_session_up->getSectionContribs()) {
1917 while (
auto section = sec_contribs->getNext()) {
1918 auto va = section->getVirtualAddress();
1919 if (file_vm_addr >= va && file_vm_addr < va + section->getLength())
1929 auto func_name = pdb_func.getName();
1930 auto func_undecorated_name = pdb_func.getUndecoratedName();
1931 std::string func_decorated_name;
1936 if (!func_undecorated_name.empty()) {
1938 PDB_SymType::PublicSymbol, func_undecorated_name,
1939 PDB_NameSearchFlags::NS_UndecoratedName);
1941 while (
auto symbol_up = result_up->getNext()) {
1944 if (
auto *pdb_public_sym =
1945 llvm::dyn_cast_or_null<PDBSymbolPublicSymbol>(
1947 if (pdb_public_sym->isFunction()) {
1948 func_decorated_name = pdb_public_sym->getName();
1955 if (!func_decorated_name.empty()) {
1977 if (!func_undecorated_name.empty() &&
1980 }
else if (!func_undecorated_name.empty()) {
1982 }
else if (!func_name.empty())
1994 if (!decl_ctx_type_system)
1998 if (
auto err = type_system_or_err.takeError()) {
2000 GetLog(LLDBLog::Symbols), std::move(err),
2001 "Unable to determine if DeclContext matches this symbol file: {0}");
2005 if (decl_ctx_type_system == type_system_or_err->get())
2012 static const auto pred_upper = [](uint32_t lhs,
SecContribInfo rhs) {
2013 return lhs < rhs.Offset;
2018 if (
auto SecContribs =
m_session_up->getSectionContribs()) {
2019 while (
auto SectionContrib = SecContribs->getNext()) {
2020 auto comp_id = SectionContrib->getCompilandId();
2024 auto sec = SectionContrib->getAddressSection();
2027 auto offset = SectionContrib->getAddressOffset();
2028 auto it = llvm::upper_bound(sec_cs, offset, pred_upper);
2030 auto size = SectionContrib->getLength();
2031 sec_cs.insert(it, {offset, size, comp_id});
2037 if (
auto Lines = data.getLineNumbers()) {
2038 if (
auto FirstLine = Lines->getNext())
2039 return FirstLine->getCompilandId();
2043 uint32_t DataSection = data.getAddressSection();
2044 uint32_t DataOffset = data.getAddressOffset();
2045 if (DataSection == 0) {
2046 if (
auto RVA = data.getRelativeVirtualAddress())
2047 m_session_up->addressForRVA(RVA, DataSection, DataOffset);
2053 auto it = llvm::upper_bound(sec_cs, DataOffset, pred_upper);
2054 if (it != sec_cs.begin()) {
2056 if (DataOffset < it->Offset + it->Size)
2057 return it->CompilandId;
2061 auto LexParentId = data.getLexicalParentId();
2062 while (
auto LexParent =
m_session_up->getSymbolById(LexParentId)) {
2063 if (LexParent->getSymTag() == PDB_SymType::Exe)
2065 if (LexParent->getSymTag() == PDB_SymType::Compiland)
2067 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)
void FindTypes(lldb_private::ConstString name, const lldb_private::CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, llvm::DenseSet< lldb_private::SymbolFile * > &searched_symbol_files, lldb_private::TypeMap &types) override
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()
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)
bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit, lldb_private::FileSpecList &support_files) override
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
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
void FindTypesByName(llvm::StringRef name, const lldb_private::CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, lldb_private::TypeMap &types)
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)
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.
void AddChild(const lldb::BlockSP &child_block_sp)
Add a child to this object.
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.
bool AppendIfUnique(const FileSpec &file)
Append a FileSpec object if unique.
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.
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 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
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
AddressRange range
The section offset address range for this line entry.
lldb::user_id_t GetID() const
Get accessor for the user ID.