3#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
4#include "llvm/DebugInfo/CodeView/Formatters.h"
5#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
6#include "llvm/DebugInfo/CodeView/RecordName.h"
7#include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
8#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
9#include "llvm/DebugInfo/CodeView/SymbolRecordHelpers.h"
10#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
11#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
12#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
13#include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
14#include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
15#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
16#include "llvm/Demangle/MicrosoftDemangle.h"
38 CreateMethodDecl(PdbIndex &m_index, PdbAstBuilderClang &m_ast_builder,
39 TypeIndex func_type_index,
40 clang::FunctionDecl *&function_decl,
42 llvm::StringRef proc_name, llvm::StringRef asm_label,
44 : m_index(m_index), m_ast_builder(m_ast_builder),
45 func_type_index(func_type_index), function_decl(function_decl),
46 parent_ty(parent_ty), proc_name(proc_name), asm_label(asm_label),
49 PdbAstBuilderClang &m_ast_builder;
50 TypeIndex func_type_index;
51 clang::FunctionDecl *&function_decl;
53 llvm::StringRef proc_name;
54 llvm::StringRef asm_label;
57 llvm::Error visitKnownMember(CVMemberRecord &cvr,
58 OverloadedMethodRecord &overloaded)
override {
59 TypeIndex method_list_idx = overloaded.MethodList;
61 CVType method_list_type = m_index.tpi().getType(method_list_idx);
62 assert(method_list_type.kind() == LF_METHODLIST);
64 MethodOverloadListRecord method_list;
65 llvm::Error err = TypeDeserializer::deserializeAs<MethodOverloadListRecord>(
66 method_list_type, method_list);
69 "Failed to deserialize {1} as MethodOverloadList: {0}",
72 return llvm::Error::success();
75 for (
const OneMethodRecord &method : method_list.Methods) {
76 if (method.getType().getIndex() == func_type_index.getIndex())
77 AddMethod(overloaded.Name, method.getOptions(), method.Attrs);
80 return llvm::Error::success();
83 llvm::Error visitKnownMember(CVMemberRecord &cvr,
84 OneMethodRecord &record)
override {
85 AddMethod(record.getName(), record.getOptions(), record.Attrs);
86 return llvm::Error::success();
89 void AddMethod(llvm::StringRef name, MethodOptions options,
90 MemberAttributes attrs) {
91 if (name != proc_name || function_decl)
93 bool is_virtual = attrs.isVirtual();
94 bool is_static = attrs.isStatic();
95 bool is_artificial = (options & MethodOptions::CompilerGenerated) ==
96 MethodOptions::CompilerGenerated;
97 function_decl = m_ast_builder.GetOrCreateMethodDecl(
98 parent_ty, proc_name, asm_label, func_ct, is_virtual, is_static,
106 case TypeRecordKind::Class:
107 return clang::TagTypeKind::Class;
108 case TypeRecordKind::Struct:
109 return clang::TagTypeKind::Struct;
110 case TypeRecordKind::Union:
111 return clang::TagTypeKind::Union;
112 case TypeRecordKind::Interface:
113 return clang::TagTypeKind::Interface;
114 case TypeRecordKind::Enum:
115 return clang::TagTypeKind::Enum;
117 assert(
false &&
"Invalid tag record kind!");
118 return clang::TagTypeKind::Struct;
125 return args.back() == TypeIndex::None();
130 for (llvm::ms_demangle::Node *n : scopes) {
131 auto *idn =
static_cast<llvm::ms_demangle::IdentifierNode *
>(n);
132 if (idn->TemplateParams)
138static std::optional<clang::CallingConv>
140 using CC = llvm::codeview::CallingConvention;
145 return clang::CallingConv::CC_C;
148 return clang::CallingConv::CC_X86Pascal;
151 return clang::CallingConv::CC_X86FastCall;
152 case CC::NearStdCall:
154 return clang::CallingConv::CC_X86StdCall;
156 return clang::CallingConv::CC_X86ThisCall;
158 return clang::CallingConv::CC_X86VectorCall;
165 return name ==
"`anonymous namespace'" || name ==
"`anonymous-namespace'";
175std::pair<clang::DeclContext *, std::string>
179 m_clang.GetSymbolFile()->GetBackingSymbolFile());
181 if (!record.hasUniqueName())
184 llvm::ms_demangle::Demangler demangler;
185 std::string_view sv(record.UniqueName.begin(), record.UniqueName.size());
186 llvm::ms_demangle::TagTypeNode *ttn = demangler.parseTagUniqueName(sv);
190 llvm::ms_demangle::IdentifierNode *idn =
191 ttn->QualifiedName->getUnqualifiedIdentifier();
192 std::string uname = idn->toString(llvm::ms_demangle::OF_NoTagSpecifier);
194 llvm::ms_demangle::NodeArrayNode *name_components =
195 ttn->QualifiedName->Components;
196 llvm::ArrayRef<llvm::ms_demangle::Node *> scopes(name_components->Nodes,
197 name_components->Count - 1);
199 clang::DeclContext *context =
m_clang.GetTranslationUnitDecl();
204 std::optional<TypeIndex> parent_index =
pdb->GetParentType(ti);
207 return {context, uname};
215 return {context, std::string(record.Name)};
217 for (llvm::ms_demangle::Node *scope : scopes) {
218 auto *nii =
static_cast<llvm::ms_demangle::NamedIdentifierNode *
>(scope);
219 std::string str = nii->toString();
222 return {context, uname};
230 if (parent_qt.isNull())
231 return {
nullptr,
""};
233 context = clang::TagDecl::castToDeclContext(parent_qt->getAsTagDecl());
234 return {context, uname};
241 case S_REGREL32_INDIR:
252 m_clang.GetSymbolFile()->GetBackingSymbolFile());
260 clang::Decl *scope_decl = clang::Decl::castFromDeclContext(scope);
266 switch (cvs.kind()) {
289 clang::Decl *result =
nullptr;
290 switch (uid.
kind()) {
298 if (
auto *tag = qt->getAsTagDecl()) {
324 return clang::Decl::castToDeclContext(decl);
332std::pair<clang::DeclContext *, std::string>
335 m_clang.GetSymbolFile()->GetBackingSymbolFile());
338 llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs = parser.
GetSpecifiers();
342 llvm::StringRef uname = specs.back().GetBaseName();
343 specs = specs.drop_back();
345 return {context, std::string(name)};
347 llvm::StringRef scope_name = specs.back().GetFullName();
350 std::vector<TypeIndex> types = index.
tpi().findRecordsByName(scope_name);
351 while (!types.empty()) {
355 clang::TagDecl *tag = qt->getAsTagDecl();
357 return {clang::TagDecl::castToDeclContext(tag), std::string(uname)};
363 std::string ns_name = spec.GetBaseName().str();
366 return {context, std::string(uname)};
373 m_clang.GetSymbolFile()->GetBackingSymbolFile());
377 llvm::StringRef symbol_name = getSymbolName(sym);
380 if (!func_id || !symbol_name.contains(
"::"))
385 auto get_member_fn_context = [&]() -> clang::DeclContext * {
388 if (func_id->is_ipi) {
390 std::optional<CVType> func_id_type =
391 index.
ipi().tryGetType(func_id->index);
392 if (!func_id_type || func_id_type->kind() != LF_MFUNC_ID)
395 MemberFuncIdRecord record;
396 llvm::Error err = TypeDeserializer::deserializeAs<MemberFuncIdRecord>(
397 *func_id_type, record);
399 llvm::consumeError(std::move(err));
403 id = record.FunctionType;
406 std::optional<CVType> func_type = index.
tpi().tryGetType(
id);
407 if (!func_type || func_type->kind() != LF_MFUNCTION)
410 MemberFunctionRecord mfr(TypeRecordKind::MemberFunction);
413 TypeDeserializer::deserializeAs<MemberFunctionRecord>(*func_type, mfr);
414 if (err || mfr.ClassType.isNoneType()) {
415 llvm::consumeError(std::move(err));
422 clang::TagDecl *tag = qt->getAsTagDecl();
426 return clang::TagDecl::castToDeclContext(tag);
429 clang::DeclContext *context = get_member_fn_context();
441 m_clang.GetSymbolFile()->GetBackingSymbolFile());
443 switch (uid.
kind()) {
445 std::optional<PdbCompilandSymId> scope =
456 std::optional<TypeIndex> parent_index =
pdb->GetParentType(type_id.
index);
473 switch (global.kind()) {
474 case SymbolKind::S_GDATA32:
475 case SymbolKind::S_LDATA32:
477 case SymbolKind::S_PROCREF:
478 case SymbolKind::S_LPROCREF: {
479 ProcRefSym ref{global.kind()};
481 SymbolDeserializer::deserializeAs<ProcRefSym>(global, ref);
484 "Failed to deserialize {1} as ProcRef: {0}",
491 case SymbolKind::S_CONSTANT:
492 case SymbolKind::S_UDT:
516 clang::TagDecl *tag = qt->getAsTagDecl();
517 if (qt->isArrayType()) {
518 const clang::Type *element_type = qt->getArrayElementTypeNoTypeQual();
519 tag = element_type->getAsTagDecl();
531 assert(
false &&
"completing unknown tag decl");
542 m_clang.GetSymbolFile()->GetBackingSymbolFile())
545 clang::QualType tag_qt =
m_clang.getASTContext().getCanonicalTagType(&tag);
549 CVType cvt = index.
tpi().getType(tag_ti);
550 if (cvt.kind() == LF_MODIFIER)
554 cvt = index.
tpi().getType(best_ti.
index);
556 assert(
false &&
"completing tag record that's not a tag record");
567 CVType field_list_cvt = index.
tpi().getType(field_list_ti);
568 if (field_list_cvt.kind() != LF_FIELDLIST)
570 FieldListRecord field_list;
571 if (llvm::Error
error = TypeDeserializer::deserializeAs<FieldListRecord>(
572 field_list_cvt, field_list))
573 llvm::consumeError(std::move(
error));
581 llvm::codeview::visitMemberRecordStream(field_list.Data, completer);
586 llvm::consumeError(std::move(
error));
593 if (ti == TypeIndex::NullptrT())
596 if (ti.getSimpleMode() != SimpleTypeMode::Direct) {
598 if (direct_type.isNull())
600 return m_clang.getASTContext().getPointerType(direct_type);
603 if (ti.getSimpleKind() == SimpleTypeKind::NotTranslated)
619 if (pointee_type.isNull())
622 if (pointer.isPointerToMember()) {
623 MemberPointerInfo mpi = pointer.getMemberInfo();
625 if (class_type.isNull())
627 if (clang::TagDecl *tag = class_type->getAsTagDecl()) {
628 clang::MSInheritanceAttr::Spelling spelling;
629 switch (mpi.Representation) {
630 case llvm::codeview::PointerToMemberRepresentation::SingleInheritanceData:
631 case llvm::codeview::PointerToMemberRepresentation::
632 SingleInheritanceFunction:
634 clang::MSInheritanceAttr::Spelling::Keyword_single_inheritance;
636 case llvm::codeview::PointerToMemberRepresentation::
637 MultipleInheritanceData:
638 case llvm::codeview::PointerToMemberRepresentation::
639 MultipleInheritanceFunction:
641 clang::MSInheritanceAttr::Spelling::Keyword_multiple_inheritance;
643 case llvm::codeview::PointerToMemberRepresentation::
644 VirtualInheritanceData:
645 case llvm::codeview::PointerToMemberRepresentation::
646 VirtualInheritanceFunction:
648 clang::MSInheritanceAttr::Spelling::Keyword_virtual_inheritance;
650 case llvm::codeview::PointerToMemberRepresentation::Unknown:
652 clang::MSInheritanceAttr::Spelling::Keyword_unspecified_inheritance;
655 spelling = clang::MSInheritanceAttr::Spelling::SpellingNotCalculated;
658 tag->addAttr(clang::MSInheritanceAttr::CreateImplicit(
659 m_clang.getASTContext(), spelling));
661 return m_clang.getASTContext().getMemberPointerType(
662 pointee_type, std::nullopt,
663 class_type->getAsCXXRecordDecl());
666 clang::QualType pointer_type;
667 if (pointer.getMode() == PointerMode::LValueReference)
668 pointer_type =
m_clang.getASTContext().getLValueReferenceType(pointee_type);
669 else if (pointer.getMode() == PointerMode::RValueReference)
670 pointer_type =
m_clang.getASTContext().getRValueReferenceType(pointee_type);
672 pointer_type =
m_clang.getASTContext().getPointerType(pointee_type);
674 if ((pointer.getOptions() & PointerOptions::Const) != PointerOptions::None)
675 pointer_type.addConst();
677 if ((pointer.getOptions() & PointerOptions::Volatile) != PointerOptions::None)
678 pointer_type.addVolatile();
680 if ((pointer.getOptions() & PointerOptions::Restrict) != PointerOptions::None)
681 pointer_type.addRestrict();
689 if (unmodified_type.isNull())
692 if ((modifier.Modifiers & ModifierOptions::Const) != ModifierOptions::None)
693 unmodified_type.addConst();
694 if ((modifier.Modifiers & ModifierOptions::Volatile) != ModifierOptions::None)
695 unmodified_type.addVolatile();
697 return unmodified_type;
701 const TagRecord &record) {
702 clang::DeclContext *context =
nullptr;
727 clang::QualType result =
741clang::NamespaceDecl *
743 clang::DeclContext &context) {
744 clang::NamespaceDecl *ns =
m_clang.GetUniqueNamespaceDeclaration(
755 return llvm::dyn_cast<clang::BlockDecl>(decl);
759 clang::BlockDecl *block_decl =
773 clang::DeclContext &scope) {
779 clang::VarDecl *var_decl =
m_clang.CreateVariableDeclaration(
794 return llvm::dyn_cast<clang::VarDecl>(decl);
801 m_clang.GetSymbolFile()->GetBackingSymbolFile());
810 return llvm::dyn_cast<clang::VarDecl>(decl);
813 m_clang.GetSymbolFile()->GetBackingSymbolFile());
822 if (
auto *tnd = llvm::dyn_cast<clang::TypedefNameDecl>(decl))
828 m_clang.GetSymbolFile()->GetBackingSymbolFile());
831 if (sym.kind() != S_UDT) {
832 assert(
false &&
"called on a non-udt type");
835 llvm::Expected<UDTSym> udt = SymbolDeserializer::deserializeAs<UDTSym>(sym);
838 "Failed to deserialize {1} as UDT: {0}",
id);
846 if (qt.isNull() || !scope)
866 if (type.
index.isSimple())
870 m_clang.GetSymbolFile()->GetBackingSymbolFile());
872 CVType cvt = index.
tpi().getType(type.
index);
874 if (cvt.kind() == LF_MODIFIER) {
875 ModifierRecord modifier;
877 TypeDeserializer::deserializeAs<ModifierRecord>(cvt, modifier);
880 "Failed to deserialize {1} as Modifier: {0}", type.
index);
886 if (cvt.kind() == LF_POINTER) {
887 PointerRecord pointer;
889 TypeDeserializer::deserializeAs<PointerRecord>(cvt, pointer);
892 "Failed to deserialize {1} as Pointer: {0}", type.
index);
907 if (cvt.kind() == LF_ARRAY) {
909 llvm::Error err = TypeDeserializer::deserializeAs<ArrayRecord>(cvt, ar);
912 "Failed to deserialize {1} as Array: {0}", type.
index);
918 if (cvt.kind() == LF_PROCEDURE) {
920 llvm::Error err = TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, pr);
923 "Failed to deserialize {1} as Procedure: {0}", type.
index);
930 if (cvt.kind() == LF_MFUNCTION) {
931 MemberFunctionRecord mfr;
933 TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfr);
936 "Failed to deserialize {1} as MemberFunction: {0}",
940 unsigned int type_quals = 0;
941 if (!mfr.ThisType.isNoneType()) {
943 if (!this_type.isNull())
944 type_quals = this_type->getPointeeType().getLocalFastQualifiers();
954 if (type.
index.isNoneType())
963 m_clang.GetSymbolFile()->GetBackingSymbolFile());
986 clang::TagDecl *tag = qt->getAsTagDecl();
1005 llvm::StringRef asm_label,
const CompilerType &method_ct,
bool is_virtual,
1006 bool is_static,
bool is_artificial) {
1010 method_decl =
m_clang.AddMethodToCXXRecordType(
1011 parent_ty, name, asm_label, method_ct, is_virtual, is_static,
1013 false, is_artificial);
1020 clang::StorageClass func_storage,
bool is_inline,
1021 clang::DeclContext *parent) {
1022 clang::FunctionDecl *function_decl =
nullptr;
1023 if (parent->isRecord()) {
1025 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1027 clang::CanQualType parent_qt =
1028 m_clang.getASTContext().getCanonicalTypeDeclType(
1029 llvm::cast<clang::TypeDecl>(parent));
1037 return iter->second;
1039 CVType cvt = index.
tpi().getType(func_ti);
1040 MemberFunctionRecord func_record(
static_cast<TypeRecordKind
>(cvt.kind()));
1042 TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, func_record);
1045 "Failed to deserialize {1} as MemberFunction: {0}",
1049 TypeIndex class_index = func_record.getClassType();
1051 CVType parent_cvt = index.
tpi().getType(class_index);
1056 if (tag_record.isForwardRef()) {
1057 llvm::Expected<TypeIndex> eti =
1058 index.
tpi().findFullDeclForForwardRef(class_index);
1060 CVType resolved_tag_record = index.
tpi().getType(*eti);
1066 "failed to find full decl for forward ref: {0}");
1070 std::string asm_label =
pdb->GetFunctionCallLabel(func_id);
1072 if (!tag_record.FieldList.isSimple()) {
1073 CVType field_list_cvt = index.
tpi().getType(tag_record.FieldList);
1074 FieldListRecord field_list;
1075 if (llvm::Error
error = TypeDeserializer::deserializeAs<FieldListRecord>(
1076 field_list_cvt, field_list))
1077 llvm::consumeError(std::move(
error));
1078 CreateMethodDecl process(index, *
this, func_ti, function_decl,
1079 parent_opaque_ty, func_name, asm_label, func_ct);
1080 if (llvm::Error err = visitMemberRecordStream(field_list.Data, process))
1081 llvm::consumeError(std::move(err));
1086 parent_opaque_ty, func_name, asm_label, func_ct,
1087 false,
false,
false);
1090 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1091 function_decl =
m_clang.CreateFunctionDeclaration(
1093 is_inline,
pdb->GetFunctionCallLabel(func_id));
1096 return function_decl;
1102 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1106 InlineSiteSym inline_site(
static_cast<SymbolRecordKind
>(sym.kind()));
1108 SymbolDeserializer::deserializeAs<InlineSiteSym>(sym, inline_site);
1111 "Failed to deserialize {1} as InlineSite: {0}",
1121 return llvm::dyn_cast<clang::FunctionDecl>(decl);
1122 clang::FunctionDecl *function_decl =
1124 if (function_decl ==
nullptr)
1129 uint64_t inlinesite_uid =
toOpaqueUid(inlinesite_id);
1132 status.
uid = inlinesite_uid;
1139 assert(
m_uid_to_decl.count(func_uid) == 0 &&
"already created");
1141 return function_decl;
1144clang::FunctionDecl *
1148 assert(
false &&
"called with non-ipi index");
1153 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1155 std::optional<CVType> func_cvt =
1156 index.
ipi().typeCollection().tryGetType(func_tid.
index);
1159 llvm::StringRef func_name;
1161 clang::DeclContext *parent =
nullptr;
1162 switch (func_cvt->kind()) {
1164 MemberFuncIdRecord mfr;
1166 TypeDeserializer::deserializeAs<MemberFuncIdRecord>(*func_cvt, mfr);
1169 "Failed to deserialize {1} (IPI) as MemberFuncId: {0}",
1173 func_name = mfr.getName();
1174 func_ti = mfr.getFunctionType();
1182 TypeDeserializer::deserializeAs<FuncIdRecord>(*func_cvt, fir);
1185 "Failed to deserialize {1} (IPI) as FuncId: {0}",
1189 func_name = fir.getName();
1190 func_ti = fir.getFunctionType();
1192 if (!fir.ParentScope.isNoneType()) {
1193 CVType parent_cvt = index.
ipi().getType(fir.ParentScope);
1194 if (parent_cvt.kind() == LF_STRING_ID) {
1196 err = TypeDeserializer::deserializeAs<StringIdRecord>(parent_cvt, sir);
1199 "Failed to deserialize {1} (IPI) as StringId: {0}",
1213 if (func_qt.isNull() || !parent)
1216 uint32_t param_count =
1217 llvm::cast<clang::FunctionProtoType>(func_qt)->getNumParams();
1219 clang::SC_None,
true, parent);
1222clang::FunctionDecl *
1225 return llvm::dyn_cast<clang::FunctionDecl>(decl);
1230 std::string context_name;
1231 if (clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(parent)) {
1232 context_name = ns->getQualifiedNameAsString();
1233 }
else if (clang::TagDecl *tag = llvm::dyn_cast<clang::TagDecl>(parent)) {
1234 context_name = tag->getQualifiedNameAsString();
1238 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1241 ProcSym proc(
static_cast<SymbolRecordKind
>(cvs.kind()));
1242 llvm::Error err = SymbolDeserializer::deserializeAs<ProcSym>(cvs, proc);
1245 "Failed to deserialize {1} as Proc: {0}", func_id);
1254 clang::StorageClass storage = clang::SC_None;
1255 if (proc.Kind == SymbolRecordKind::ProcSym)
1256 storage = clang::SC_Static;
1258 const clang::FunctionProtoType *func_type =
1259 llvm::dyn_cast<clang::FunctionProtoType>(qt);
1265 llvm::StringRef proc_name = proc.Name;
1266 if (!context_name.empty() && !(proc_name.consume_front(context_name) &&
1267 proc_name.consume_front(
"::"))) {
1271 llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs(parser.
GetSpecifiers());
1273 proc_name = specs.back().GetBaseName();
1275 clang::FunctionDecl *function_decl =
1277 func_type->getNumParams(), storage,
false, parent);
1278 if (function_decl ==
nullptr)
1288 return function_decl;
1315 uint32_t param_count) {
1317 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1320 CVSymbolArray scope =
1324 auto begin = scope.begin();
1325 auto end = scope.end();
1326 std::vector<clang::ParmVarDecl *> params;
1327 for (uint32_t i = 0; i < param_count && begin != end;) {
1328 uint32_t record_offset = begin.offset();
1330 CVSymbol sym = *begin++;
1333 llvm::StringRef param_name;
1334 switch (sym.kind()) {
1336 RegRelativeSym reg(SymbolRecordKind::RegRelativeSym);
1338 SymbolDeserializer::deserializeAs<RegRelativeSym>(sym, reg);
1341 "Failed to deserialize {1} as RegRelative: {0}", sym_id);
1344 param_type = reg.Type;
1345 param_name = reg.Name;
1348 case S_REGREL32_INDIR: {
1349 RegRelativeIndirSym reg(SymbolRecordKind::RegRelativeIndirSym);
1351 SymbolDeserializer::deserializeAs<RegRelativeIndirSym>(sym, reg);
1354 "Failed to deserialize {1} as RegRelativeIndir: {0}",
1358 param_type = reg.Type;
1359 param_name = reg.Name;
1363 RegisterSym reg(SymbolRecordKind::RegisterSym);
1365 SymbolDeserializer::deserializeAs<RegisterSym>(sym, reg);
1368 "Failed to deserialize {1} as Register: {0}", sym_id);
1371 param_type = reg.Index;
1372 param_name = reg.Name;
1376 LocalSym local(SymbolRecordKind::LocalSym);
1377 llvm::Error err = SymbolDeserializer::deserializeAs<LocalSym>(sym, local);
1380 "Failed to deserialize {1} as Local: {0}", sym_id);
1383 if ((local.Flags & LocalSymFlags::IsParameter) == LocalSymFlags::None)
1385 param_type = local.Type;
1386 param_name = local.Name;
1406 clang::ParmVarDecl *param =
m_clang.CreateParameterDeclaration(
1408 param_type_ct, clang::SC_None,
true);
1413 params.push_back(param);
1417 if (!params.empty() && params.size() == param_count)
1418 function_decl.setParams(params);
1422 const EnumRecord &er) {
1423 clang::DeclContext *decl_context =
nullptr;
1430 if (underlying_type.isNull())
1449 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1452 if (element_type.isNull() || element_size == 0)
1454 uint64_t element_count = ar.Size / element_size;
1457 element_count,
false);
1463 llvm::codeview::CallingConvention calling_convention,
1464 unsigned int type_quals) {
1466 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1468 TpiStream &stream = index.
tpi();
1469 CVType args_cvt = stream.getType(args_type_idx);
1472 TypeDeserializer::deserializeAs<ArgListRecord>(args_cvt, args);
1475 "Failed to deserialize {1} as ArgList: {0}", args_type_idx);
1479 llvm::ArrayRef<TypeIndex> arg_indices = llvm::ArrayRef(args.ArgIndices);
1482 arg_indices = arg_indices.drop_back();
1484 std::vector<CompilerType> arg_types;
1485 arg_types.reserve(arg_indices.size());
1487 for (
TypeIndex arg_index : arg_indices) {
1489 if (arg_type.isNull())
1495 if (return_type.isNull())
1498 std::optional<clang::CallingConv> cc =
1505 return_ct, arg_types, is_variadic, type_quals, *cc);
1507 return clang::QualType::getFromOpaquePtr(
1512 return llvm::isa<clang::TagDecl>(&context);
1516 return llvm::isa<clang::FunctionDecl>(&context);
1520 return llvm::isa<clang::BlockDecl>(&context);
1524 clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(&context);
1527 std::string qname = ns->getQualifiedNameAsString();
1529 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1532 for (
const CVType &cvt : index.
tpi().typeArray()) {
1544 clang::DeclContext *context =
nullptr;
1547 if (!context || !context->isNamespace())
1550 clang::NamespaceDecl *ns = llvm::cast<clang::NamespaceDecl>(context);
1551 llvm::StringRef ns_name = ns->getName();
1552 if (ns_name.starts_with(qname)) {
1553 ns_name = ns_name.drop_front(qname.size());
1554 if (ns_name.starts_with(
"::"))
1565 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1568 for (
const CVType &cvt : index.
tpi().typeArray()) {
1583 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1585 uint32_t module_count = index.
dbi().modules().getModuleCount();
1586 for (uint16_t modi = 0; modi < module_count; ++modi) {
1588 const CVSymbolArray &symbols = cii.
m_debug_stream.getSymbolArray();
1589 auto iter = symbols.begin();
1590 while (iter != symbols.end()) {
1593 switch (iter->kind()) {
1597 iter = symbols.at(getScopeEndOffset(*iter));
1616 const CVSymbolArray &symbols) {
1617 clang::FunctionDecl *func_decl = llvm::dyn_cast<clang::FunctionDecl>(&decl);
1620 unsigned int params = func_decl->getNumParams();
1624 CVSymbolArray result = symbols;
1626 while (!result.empty()) {
1630 CVSymbol sym = *result.begin();
1631 result.drop_front();
1643 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1646 if (sym.kind() != S_GPROC32 && sym.kind() != S_LPROC32 &&
1647 sym.kind() != S_BLOCK32 && sym.kind() != S_INLINESITE) {
1648 assert(
false &&
"called on non-block");
1653 CVSymbolArray symbols =
1658 if (sym.kind() == S_GPROC32 || sym.kind() == S_LPROC32)
1662 symbols.drop_front();
1663 auto begin = symbols.begin();
1664 while (begin != symbols.end()) {
1667 if (begin->kind() == S_BLOCK32 || begin->kind() == S_INLINESITE) {
1669 begin = symbols.at(getScopeEndOffset(*begin));
1676 clang::DeclContext &context) {
1678 clang::Decl *decl = clang::Decl::castFromDeclContext(&context);
1686 assert(
false &&
"cannot parse unknown decl");
1690 if (
auto *tag = llvm::dyn_cast<clang::TagDecl>(&context)) {
1712 if (dc->isTranslationUnit()) {
1718 if (dc->isNamespace()) {
1730 return m_clang.GetCompilerDecl(decl);
1745 return m_clang.CreateDeclContext(context);
1766 llvm::StringRef name) {
1782 for (clang::NamespaceDecl *namespace_decl : *set)
1783 if (namespace_decl->getName() == name)
1786 for (clang::NamespaceDecl *namespace_decl : *set)
1787 if (namespace_decl->isAnonymousNamespace())
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOG_ERROR(log, error,...)
static bool isFunctionDecl(clang::DeclContext &context)
static bool isBlockDecl(clang::DeclContext &context)
static CVSymbolArray skipFunctionParameters(clang::Decl &decl, const CVSymbolArray &symbols)
static std::optional< clang::CallingConv > TranslateCallingConvention(llvm::codeview::CallingConvention conv)
static bool isTagDecl(clang::DeclContext &context)
static bool isLocalVariableType(SymbolKind K)
static bool IsAnonymousNamespaceName(llvm::StringRef name)
static clang::TagTypeKind TranslateUdtKind(const TagRecord &cr)
static bool IsCVarArgsFunction(llvm::ArrayRef< TypeIndex > args)
static bool AnyScopesHaveTemplateParams(llvm::ArrayRef< llvm::ms_demangle::Node * > scopes)
llvm::ArrayRef< MSVCUndecoratedNameSpecifier > GetSpecifiers() const
bool CompleteType(const CompilerType &compiler_type)
Represents a generic declaration context in a program.
void * GetOpaqueDeclContext() const
Represents a generic declaration such as a function declaration.
TypeSystem * GetTypeSystem() const
Generic representation of a type in a programming language.
lldb::opaque_compiler_type_t GetOpaqueQualType() const
CompilerType CreateTypedef(const char *name, const CompilerDeclContext &decl_ctx, uint32_t payload) const
Create a typedef to this type using "name" as the name of the typedef this type is valid and the type...
A uniqued constant string class.
A class that describes the declaration location of a lldb object.
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 TypeSystem implementation based on Clang.
static bool SetHasExternalStorage(lldb::opaque_compiler_type_t type, bool has_extern)
static bool StartTagDeclarationDefinition(const CompilerType &type)
static void RequireCompleteType(CompilerType type)
Complete a type from debug info, or mark it as forcefully completed if there is no definition of the ...
CompilandIndexItem & GetOrCreateCompiland(uint16_t modi)
const CompilandIndexItem * GetCompiland(uint16_t modi) const
clang::Decl * GetOrCreateSymbolForId(PdbCompilandSymId id)
std::pair< clang::DeclContext *, std::string > CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti)
void ParseDeclsForSimpleContext(clang::DeclContext &context)
CompilerDeclContext ToCompilerDeclContext(clang::DeclContext *context)
clang::FunctionDecl * GetOrCreateInlinedFunctionDecl(PdbCompilandSymId inlinesite_id)
llvm::DenseMap< clang::DeclContext *, NamespaceSet > m_parent_to_namespaces
void CreateFunctionParameters(PdbCompilandSymId func_id, clang::FunctionDecl &function_decl, uint32_t param_count)
bool CompleteType(CompilerType ct) override
clang::QualType GetBasicType(lldb::BasicType type)
clang::Decl * TryGetDecl(PdbSymUid uid) const
clang::CXXMethodDecl * GetOrCreateMethodDecl(lldb::opaque_compiler_type_t parent_ty, llvm::StringRef name, llvm::StringRef asm_label, const CompilerType &method_ct, bool is_virtual, bool is_static, bool is_artificial)
Returns the method named name with type method_ct in the record parent_ty, creating it if it doesn't ...
clang::QualType CreateType(PdbTypeSymId type)
llvm::DenseMap< std::tuple< lldb::opaque_compiler_type_t, ConstString, lldb::opaque_compiler_type_t >, clang::CXXMethodDecl * > m_cxx_method_decls
clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array)
llvm::DenseMap< clang::Decl *, DeclStatus > m_decl_to_status
clang::FunctionDecl * CreateFunctionDeclFromId(PdbTypeSymId func_tid, PdbCompilandSymId func_sid)
CompilerType GetOrCreateType(PdbTypeSymId type) override
clang::QualType CreatePointerType(const llvm::codeview::PointerRecord &pointer)
llvm::once_flag m_parse_functions_and_non_local_vars
clang::QualType CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx, llvm::codeview::CallingConvention calling_convention, unsigned int type_quals)
NamespaceSet m_parsed_namespaces
clang::DeclContext * GetOrCreateDeclContextForCompilandSymbol(PdbCompilandSymId uid)
clang::QualType CreateModifierType(const llvm::codeview::ModifierRecord &modifier)
CompilerDeclContext GetTranslationUnitDecl()
std::pair< clang::DeclContext *, std::string > CreateDeclInfoForUndecoratedName(llvm::StringRef uname)
clang::FunctionDecl * GetOrCreateFunctionDecl(PdbCompilandSymId func_id)
clang::NamespaceDecl * GetOrCreateNamespaceDecl(const char *name, clang::DeclContext &context)
TypeSystemClang & m_clang
llvm::once_flag m_parse_all_types
void EnsureVariable(PdbCompilandSymId scope_id, PdbCompilandSymId var_id) override
clang::VarDecl * CreateVariableDecl(PdbSymUid uid, llvm::codeview::CVSymbol sym, clang::DeclContext &scope)
void ParseAllFunctionsAndNonLocalVars()
void ParseDeclsForContext(CompilerDeclContext context) override
CompilerDecl ToCompilerDecl(clang::Decl *decl)
void EnsureFunction(PdbCompilandSymId func_id) override
llvm::DenseMap< lldb::user_id_t, clang::QualType > m_uid_to_type
void EnsureBlock(PdbCompilandSymId block_id) override
ClangASTImporter & GetClangASTImporter()
llvm::DenseMap< lldb::user_id_t, clang::Decl * > m_uid_to_decl
CompilerDecl GetOrCreateDeclForUid(PdbSymUid uid) override
CompilerDeclContext FindNamespaceDecl(CompilerDeclContext parent_ctx, llvm::StringRef name) override
void ParseNamespace(clang::DeclContext &parent)
llvm::DenseSet< clang::NamespaceDecl * > NamespaceSet
clang::VarDecl * GetOrCreateVariableDecl(PdbCompilandSymId scope_id, PdbCompilandSymId var_id)
clang::BlockDecl * GetOrCreateBlockDecl(PdbCompilandSymId block_id)
clang::QualType CreateSimpleType(TypeIndex ti)
clang::DeclContext * GetParentClangDeclContext(PdbSymUid uid)
clang::QualType FromCompilerType(CompilerType ct)
clang::QualType CreateEnumType(PdbTypeSymId id, const llvm::codeview::EnumRecord &record)
CompilerType GetOrCreateTypedefType(PdbGlobalSymId id) override
bool CompleteTagDecl(clang::TagDecl &tag)
clang::QualType CreateRecordType(PdbTypeSymId id, const llvm::codeview::TagRecord &record)
CompilerDeclContext GetParentDeclContext(PdbSymUid uid) override
clang::DeclContext * FromCompilerDeclContext(CompilerDeclContext context)
llvm::codeview::TypeIndex TypeIndex
clang::FunctionDecl * CreateFunctionDecl(PdbCompilandSymId func_id, llvm::StringRef func_name, TypeIndex func_ti, CompilerType func_ct, uint32_t param_count, clang::StorageClass func_storage, bool is_inline, clang::DeclContext *parent)
CompilerDeclContext GetOrCreateDeclContextForUid(PdbSymUid uid) override
void EnsureInlinedFunction(PdbCompilandSymId inlinesite_id) override
CompilerType ToCompilerType(clang::QualType qt)
clang::QualType GetOrCreateClangType(PdbTypeSymId type)
void ParseBlockChildren(PdbCompilandSymId block_id)
void Dump(Stream &stream, llvm::StringRef filter, bool show_color) override
clang::Decl * FromCompilerDecl(CompilerDecl decl)
PdbAstBuilderClang(TypeSystemClang &clang)
NamespaceSet m_known_namespaces
clang::DeclContext * GetOrCreateClangDeclContextForUid(PdbSymUid uid)
PdbIndex - Lazy access to the important parts of a PDB file.
llvm::pdb::TpiStream & ipi()
CompileUnitIndex & compilands()
llvm::pdb::DbiStream & dbi()
llvm::codeview::CVSymbol ReadSymbolRecord(PdbCompilandSymId cu_sym) const
llvm::pdb::TpiStream & tpi()
PdbGlobalSymId asGlobalSym() const
PdbCompilandSymId asCompilandSym() const
PdbTypeSymId asTypeSym() const
PdbSymUidKind kind() const
std::optional< PdbTypeSymId > GetFunctionType(llvm::codeview::CVSymbol symbol)
llvm::StringRef DropNameScope(llvm::StringRef name)
uint64_t toOpaqueUid(const T &cid)
lldb::BasicType GetCompilerTypeForSimpleKind(llvm::codeview::SimpleTypeKind kind)
VariableInfo GetVariableNameInfo(llvm::codeview::CVSymbol symbol)
bool IsTagRecord(llvm::codeview::CVType cvt)
llvm::codeview::TypeIndex LookThroughModifierRecord(llvm::codeview::CVType modifier)
bool IsForwardRefUdt(llvm::codeview::CVType cvt)
llvm::codeview::TypeIndex GetFieldListIndex(llvm::codeview::CVType cvt)
size_t GetSizeOfType(PdbTypeSymId id, llvm::pdb::TpiStream &tpi)
PdbTypeSymId GetBestPossibleDecl(PdbTypeSymId id, llvm::pdb::TpiStream &tpi)
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.
void * opaque_compiler_type_t
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
@ eLanguageTypeC_plus_plus
ISO C++:1998.
static clang::QualType GetQualType(const CompilerType &ct)
static clang::Decl * GetDecl(const CompilerDecl &decl)
Returns the clang::Decl of the given CompilerDecl.
const llvm::codeview::UnionRecord & asUnion() const
static CVTagRecord create(llvm::codeview::CVType type)
const llvm::codeview::ClassRecord & asClass() const
const llvm::codeview::EnumRecord & asEnum() const
const llvm::codeview::TagRecord & asTag() const
Represents a single compile unit.
llvm::pdb::ModuleDebugStreamRef m_debug_stream
llvm::codeview::TypeIndex index
llvm::codeview::TypeIndex type