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;
703 clang::DeclContext *context =
nullptr;
728 clang::QualType result =
742clang::NamespaceDecl *
744 clang::DeclContext &context) {
745 clang::NamespaceDecl *ns =
m_clang.GetUniqueNamespaceDeclaration(
756 return llvm::dyn_cast<clang::BlockDecl>(decl);
760 clang::BlockDecl *block_decl =
774 clang::DeclContext &scope) {
780 clang::VarDecl *var_decl =
m_clang.CreateVariableDeclaration(
795 return llvm::dyn_cast<clang::VarDecl>(decl);
802 m_clang.GetSymbolFile()->GetBackingSymbolFile());
811 return llvm::dyn_cast<clang::VarDecl>(decl);
814 m_clang.GetSymbolFile()->GetBackingSymbolFile());
823 if (
auto *tnd = llvm::dyn_cast<clang::TypedefNameDecl>(decl))
829 m_clang.GetSymbolFile()->GetBackingSymbolFile());
832 if (sym.kind() != S_UDT) {
833 assert(
false &&
"called on a non-udt type");
836 llvm::Expected<UDTSym> udt = SymbolDeserializer::deserializeAs<UDTSym>(sym);
839 "Failed to deserialize {1} as UDT: {0}",
id);
847 if (qt.isNull() || !scope)
867 if (type.
index.isSimple())
871 m_clang.GetSymbolFile()->GetBackingSymbolFile());
873 CVType cvt = index.
tpi().getType(type.
index);
875 if (cvt.kind() == LF_MODIFIER) {
876 ModifierRecord modifier;
878 TypeDeserializer::deserializeAs<ModifierRecord>(cvt, modifier);
881 "Failed to deserialize {1} as Modifier: {0}", type.
index);
887 if (cvt.kind() == LF_POINTER) {
888 PointerRecord pointer;
890 TypeDeserializer::deserializeAs<PointerRecord>(cvt, pointer);
893 "Failed to deserialize {1} as Pointer: {0}", type.
index);
906 if (cvt.kind() == LF_ARRAY) {
908 llvm::Error err = TypeDeserializer::deserializeAs<ArrayRecord>(cvt, ar);
911 "Failed to deserialize {1} as Array: {0}", type.
index);
917 if (cvt.kind() == LF_PROCEDURE) {
919 llvm::Error err = TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, pr);
922 "Failed to deserialize {1} as Procedure: {0}", type.
index);
929 if (cvt.kind() == LF_MFUNCTION) {
930 MemberFunctionRecord mfr;
932 TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfr);
935 "Failed to deserialize {1} as MemberFunction: {0}",
939 unsigned int type_quals = 0;
940 if (!mfr.ThisType.isNoneType()) {
942 if (!this_type.isNull())
943 type_quals = this_type->getPointeeType().getLocalFastQualifiers();
953 if (type.
index.isNoneType())
962 m_clang.GetSymbolFile()->GetBackingSymbolFile());
985 clang::TagDecl *tag = qt->getAsTagDecl();
1004 llvm::StringRef asm_label,
const CompilerType &method_ct,
bool is_virtual,
1005 bool is_static,
bool is_artificial) {
1009 method_decl =
m_clang.AddMethodToCXXRecordType(
1010 parent_ty, name, asm_label, method_ct, is_virtual, is_static,
1012 false, is_artificial);
1019 clang::StorageClass func_storage,
bool is_inline,
1020 clang::DeclContext *parent) {
1021 clang::FunctionDecl *function_decl =
nullptr;
1022 if (parent->isRecord()) {
1024 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1026 clang::CanQualType parent_qt =
1027 m_clang.getASTContext().getCanonicalTypeDeclType(
1028 llvm::cast<clang::TypeDecl>(parent));
1036 return iter->second;
1038 CVType cvt = index.
tpi().getType(func_ti);
1039 MemberFunctionRecord func_record(
static_cast<TypeRecordKind
>(cvt.kind()));
1041 TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, func_record);
1044 "Failed to deserialize {1} as MemberFunction: {0}",
1048 TypeIndex class_index = func_record.getClassType();
1050 CVType parent_cvt = index.
tpi().getType(class_index);
1055 if (tag_record.isForwardRef()) {
1056 llvm::Expected<TypeIndex> eti =
1057 index.
tpi().findFullDeclForForwardRef(class_index);
1059 CVType resolved_tag_record = index.
tpi().getType(*eti);
1065 "failed to find full decl for forward ref: {0}");
1069 std::string asm_label =
pdb->GetFunctionCallLabel(func_id);
1071 if (!tag_record.FieldList.isSimple()) {
1072 CVType field_list_cvt = index.
tpi().getType(tag_record.FieldList);
1073 FieldListRecord field_list;
1074 if (llvm::Error
error = TypeDeserializer::deserializeAs<FieldListRecord>(
1075 field_list_cvt, field_list))
1076 llvm::consumeError(std::move(
error));
1077 CreateMethodDecl process(index, *
this, func_ti, function_decl,
1078 parent_opaque_ty, func_name, asm_label, func_ct);
1079 if (llvm::Error err = visitMemberRecordStream(field_list.Data, process))
1080 llvm::consumeError(std::move(err));
1085 parent_opaque_ty, func_name, asm_label, func_ct,
1086 false,
false,
false);
1089 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1090 function_decl =
m_clang.CreateFunctionDeclaration(
1092 is_inline,
pdb->GetFunctionCallLabel(func_id));
1095 return function_decl;
1101 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1105 InlineSiteSym inline_site(
static_cast<SymbolRecordKind
>(sym.kind()));
1107 SymbolDeserializer::deserializeAs<InlineSiteSym>(sym, inline_site);
1110 "Failed to deserialize {1} as InlineSite: {0}",
1120 return llvm::dyn_cast<clang::FunctionDecl>(decl);
1121 clang::FunctionDecl *function_decl =
1123 if (function_decl ==
nullptr)
1128 uint64_t inlinesite_uid =
toOpaqueUid(inlinesite_id);
1131 status.
uid = inlinesite_uid;
1138 assert(
m_uid_to_decl.count(func_uid) == 0 &&
"already created");
1140 return function_decl;
1143clang::FunctionDecl *
1147 assert(
false &&
"called with non-ipi index");
1152 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1154 std::optional<CVType> func_cvt =
1155 index.
ipi().typeCollection().tryGetType(func_tid.
index);
1158 llvm::StringRef func_name;
1160 clang::DeclContext *parent =
nullptr;
1161 switch (func_cvt->kind()) {
1163 MemberFuncIdRecord mfr;
1165 TypeDeserializer::deserializeAs<MemberFuncIdRecord>(*func_cvt, mfr);
1168 "Failed to deserialize {1} (IPI) as MemberFuncId: {0}",
1172 func_name = mfr.getName();
1173 func_ti = mfr.getFunctionType();
1181 TypeDeserializer::deserializeAs<FuncIdRecord>(*func_cvt, fir);
1184 "Failed to deserialize {1} (IPI) as FuncId: {0}",
1188 func_name = fir.getName();
1189 func_ti = fir.getFunctionType();
1191 if (!fir.ParentScope.isNoneType()) {
1192 CVType parent_cvt = index.
ipi().getType(fir.ParentScope);
1193 if (parent_cvt.kind() == LF_STRING_ID) {
1195 err = TypeDeserializer::deserializeAs<StringIdRecord>(parent_cvt, sir);
1198 "Failed to deserialize {1} (IPI) as StringId: {0}",
1212 if (func_qt.isNull() || !parent)
1215 uint32_t param_count =
1216 llvm::cast<clang::FunctionProtoType>(func_qt)->getNumParams();
1218 clang::SC_None,
true, parent);
1221clang::FunctionDecl *
1224 return llvm::dyn_cast<clang::FunctionDecl>(decl);
1229 std::string context_name;
1230 if (clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(parent)) {
1231 context_name = ns->getQualifiedNameAsString();
1232 }
else if (clang::TagDecl *tag = llvm::dyn_cast<clang::TagDecl>(parent)) {
1233 context_name = tag->getQualifiedNameAsString();
1237 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1240 ProcSym proc(
static_cast<SymbolRecordKind
>(cvs.kind()));
1241 llvm::Error err = SymbolDeserializer::deserializeAs<ProcSym>(cvs, proc);
1244 "Failed to deserialize {1} as Proc: {0}", func_id);
1253 clang::StorageClass storage = clang::SC_None;
1254 if (proc.Kind == SymbolRecordKind::ProcSym)
1255 storage = clang::SC_Static;
1257 const clang::FunctionProtoType *func_type =
1258 llvm::dyn_cast<clang::FunctionProtoType>(qt);
1264 llvm::StringRef proc_name = proc.Name;
1265 if (!context_name.empty() && !(proc_name.consume_front(context_name) &&
1266 proc_name.consume_front(
"::"))) {
1270 llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs(parser.
GetSpecifiers());
1272 proc_name = specs.back().GetBaseName();
1274 clang::FunctionDecl *function_decl =
1276 func_type->getNumParams(), storage,
false, parent);
1277 if (function_decl ==
nullptr)
1287 return function_decl;
1314 uint32_t param_count) {
1316 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1319 CVSymbolArray scope =
1323 auto begin = scope.begin();
1324 auto end = scope.end();
1325 std::vector<clang::ParmVarDecl *> params;
1326 for (uint32_t i = 0; i < param_count && begin != end;) {
1327 uint32_t record_offset = begin.offset();
1329 CVSymbol sym = *begin++;
1332 llvm::StringRef param_name;
1333 switch (sym.kind()) {
1335 RegRelativeSym reg(SymbolRecordKind::RegRelativeSym);
1337 SymbolDeserializer::deserializeAs<RegRelativeSym>(sym, reg);
1340 "Failed to deserialize {1} as RegRelative: {0}", sym_id);
1343 param_type = reg.Type;
1344 param_name = reg.Name;
1347 case S_REGREL32_INDIR: {
1348 RegRelativeIndirSym reg(SymbolRecordKind::RegRelativeIndirSym);
1350 SymbolDeserializer::deserializeAs<RegRelativeIndirSym>(sym, reg);
1353 "Failed to deserialize {1} as RegRelativeIndir: {0}",
1357 param_type = reg.Type;
1358 param_name = reg.Name;
1362 RegisterSym reg(SymbolRecordKind::RegisterSym);
1364 SymbolDeserializer::deserializeAs<RegisterSym>(sym, reg);
1367 "Failed to deserialize {1} as Register: {0}", sym_id);
1370 param_type = reg.Index;
1371 param_name = reg.Name;
1375 LocalSym local(SymbolRecordKind::LocalSym);
1376 llvm::Error err = SymbolDeserializer::deserializeAs<LocalSym>(sym, local);
1379 "Failed to deserialize {1} as Local: {0}", sym_id);
1382 if ((local.Flags & LocalSymFlags::IsParameter) == LocalSymFlags::None)
1384 param_type = local.Type;
1385 param_name = local.Name;
1405 clang::ParmVarDecl *param =
m_clang.CreateParameterDeclaration(
1407 param_type_ct, clang::SC_None,
true);
1412 params.push_back(param);
1416 if (!params.empty() && params.size() == param_count)
1417 function_decl.setParams(params);
1421 const EnumRecord &er) {
1422 clang::DeclContext *decl_context =
nullptr;
1429 if (underlying_type.isNull())
1448 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1451 if (element_type.isNull() || element_size == 0)
1453 uint64_t element_count = ar.Size / element_size;
1456 element_count,
false);
1462 llvm::codeview::CallingConvention calling_convention,
1463 unsigned int type_quals) {
1465 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1467 TpiStream &stream = index.
tpi();
1468 CVType args_cvt = stream.getType(args_type_idx);
1471 TypeDeserializer::deserializeAs<ArgListRecord>(args_cvt, args);
1474 "Failed to deserialize {1} as ArgList: {0}", args_type_idx);
1478 llvm::ArrayRef<TypeIndex> arg_indices = llvm::ArrayRef(args.ArgIndices);
1481 arg_indices = arg_indices.drop_back();
1483 std::vector<CompilerType> arg_types;
1484 arg_types.reserve(arg_indices.size());
1486 for (
TypeIndex arg_index : arg_indices) {
1488 if (arg_type.isNull())
1494 if (return_type.isNull())
1497 std::optional<clang::CallingConv> cc =
1504 return_ct, arg_types, is_variadic, type_quals, *cc);
1506 return clang::QualType::getFromOpaquePtr(
1511 return llvm::isa<clang::TagDecl>(&context);
1515 return llvm::isa<clang::FunctionDecl>(&context);
1519 return llvm::isa<clang::BlockDecl>(&context);
1523 clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(&context);
1526 std::string qname = ns->getQualifiedNameAsString();
1528 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1531 for (
const CVType &cvt : index.
tpi().typeArray()) {
1543 clang::DeclContext *context =
nullptr;
1546 if (!context || !context->isNamespace())
1549 clang::NamespaceDecl *ns = llvm::cast<clang::NamespaceDecl>(context);
1550 llvm::StringRef ns_name = ns->getName();
1551 if (ns_name.starts_with(qname)) {
1552 ns_name = ns_name.drop_front(qname.size());
1553 if (ns_name.starts_with(
"::"))
1564 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1567 for (
const CVType &cvt : index.
tpi().typeArray()) {
1582 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1584 uint32_t module_count = index.
dbi().modules().getModuleCount();
1585 for (uint16_t modi = 0; modi < module_count; ++modi) {
1587 const CVSymbolArray &symbols = cii.
m_debug_stream.getSymbolArray();
1588 auto iter = symbols.begin();
1589 while (iter != symbols.end()) {
1592 switch (iter->kind()) {
1596 iter = symbols.at(getScopeEndOffset(*iter));
1615 const CVSymbolArray &symbols) {
1616 clang::FunctionDecl *func_decl = llvm::dyn_cast<clang::FunctionDecl>(&decl);
1619 unsigned int params = func_decl->getNumParams();
1623 CVSymbolArray result = symbols;
1625 while (!result.empty()) {
1629 CVSymbol sym = *result.begin();
1630 result.drop_front();
1642 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1645 if (sym.kind() != S_GPROC32 && sym.kind() != S_LPROC32 &&
1646 sym.kind() != S_BLOCK32 && sym.kind() != S_INLINESITE) {
1647 assert(
false &&
"called on non-block");
1652 CVSymbolArray symbols =
1657 if (sym.kind() == S_GPROC32 || sym.kind() == S_LPROC32)
1661 symbols.drop_front();
1662 auto begin = symbols.begin();
1663 while (begin != symbols.end()) {
1666 if (begin->kind() == S_BLOCK32 || begin->kind() == S_INLINESITE) {
1668 begin = symbols.at(getScopeEndOffset(*begin));
1675 clang::DeclContext &context) {
1677 clang::Decl *decl = clang::Decl::castFromDeclContext(&context);
1685 assert(
false &&
"cannot parse unknown decl");
1689 if (
auto *tag = llvm::dyn_cast<clang::TagDecl>(&context)) {
1711 if (dc->isTranslationUnit()) {
1717 if (dc->isNamespace()) {
1729 return m_clang.GetCompilerDecl(decl);
1744 return m_clang.CreateDeclContext(context);
1760 while (!name.empty()) {
1761 size_t pos = name.find(
'`');
1762 result += name.take_front(pos);
1763 if (pos == llvm::StringRef::npos)
1765 name = name.drop_front(pos);
1766 if (name.consume_front(
"`anonymous namespace'") ||
1767 name.consume_front(
"`anonymous-namespace'")) {
1768 result +=
"(anonymous namespace)";
1770 result += name.front();
1771 name = name.drop_front();
1784 llvm::StringRef name) {
1800 for (clang::NamespaceDecl *namespace_decl : *set)
1801 if (namespace_decl->getName() == name)
1804 for (clang::NamespaceDecl *namespace_decl : *set)
1805 if (namespace_decl->isAnonymousNamespace())
1817 if (!tag.
asClass().getVTableShape().isNoneType())
1823 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1826 std::optional<CVType> cvt = index.
tpi().tryGetType(tag.
asTag().FieldList);
1831 if (llvm::Error ec =
1832 TypeDeserializer::deserializeAs<FieldListRecord>(*cvt, fl)) {
1833 llvm::consumeError(std::move(ec));
1838 llvm::Error visitKnownMember(CVMemberRecord &CVM,
1839 VirtualBaseClassRecord &Record)
override {
1841 return llvm::Error::success();
1844 bool m_has_vbase =
false;
1848 llvm::Error ec = llvm::codeview::visitMemberRecordStream(fl.Data, visitor);
1850 llvm::consumeError(std::move(ec));
1852 return visitor.m_has_vbase;
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
clang::QualType CreateRecordType(PdbTypeSymId id, const CVTagRecord &record)
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
bool IsDynamicTagRecord(const CVTagRecord &tag)
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)
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
std::string GetQualifiedName(llvm::StringRef name) override
Convert a CodeView qualified name into the spelling used by the language of this AST (e....
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.
CompilerContextKind contextKind() 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