LLDB mainline
PdbAstBuilderClang.cpp
Go to the documentation of this file.
2
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"
17
18#include "PdbUtil.h"
23#include "SymbolFileNativePDB.h"
24#include "UdtRecordCompleter.h"
25#include "lldb/Core/Module.h"
28#include <optional>
29#include <string_view>
30
31using namespace lldb_private;
32using namespace lldb_private::npdb;
33using namespace llvm::codeview;
34using namespace llvm::pdb;
35
36namespace {
37struct CreateMethodDecl : public TypeVisitorCallbacks {
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,
43 CompilerType func_ct)
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),
47 func_ct(func_ct) {}
48 PdbIndex &m_index;
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;
55 CompilerType func_ct;
56
57 llvm::Error visitKnownMember(CVMemberRecord &cvr,
58 OverloadedMethodRecord &overloaded) override {
59 TypeIndex method_list_idx = overloaded.MethodList;
60
61 CVType method_list_type = m_index.tpi().getType(method_list_idx);
62 assert(method_list_type.kind() == LF_METHODLIST);
63
64 MethodOverloadListRecord method_list;
65 llvm::Error err = TypeDeserializer::deserializeAs<MethodOverloadListRecord>(
66 method_list_type, method_list);
67 if (err) {
68 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
69 "Failed to deserialize {1} as MethodOverloadList: {0}",
70 method_list_idx);
71 // Continue even if we couldn't deserialize.
72 return llvm::Error::success();
73 }
74
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);
78 }
79
80 return llvm::Error::success();
81 }
82
83 llvm::Error visitKnownMember(CVMemberRecord &cvr,
84 OneMethodRecord &record) override {
85 AddMethod(record.getName(), record.getOptions(), record.Attrs);
86 return llvm::Error::success();
87 }
88
89 void AddMethod(llvm::StringRef name, MethodOptions options,
90 MemberAttributes attrs) {
91 if (name != proc_name || function_decl)
92 return;
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,
99 is_artificial);
100 }
101};
102} // namespace
103
104static clang::TagTypeKind TranslateUdtKind(const TagRecord &cr) {
105 switch (cr.Kind) {
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;
116 default:
117 assert(false && "Invalid tag record kind!");
118 return clang::TagTypeKind::Struct;
119 }
120}
121
122static bool IsCVarArgsFunction(llvm::ArrayRef<TypeIndex> args) {
123 if (args.empty())
124 return false;
125 return args.back() == TypeIndex::None();
126}
127
128static bool
129AnyScopesHaveTemplateParams(llvm::ArrayRef<llvm::ms_demangle::Node *> scopes) {
130 for (llvm::ms_demangle::Node *n : scopes) {
131 auto *idn = static_cast<llvm::ms_demangle::IdentifierNode *>(n);
132 if (idn->TemplateParams)
133 return true;
134 }
135 return false;
136}
137
138static std::optional<clang::CallingConv>
139TranslateCallingConvention(llvm::codeview::CallingConvention conv) {
140 using CC = llvm::codeview::CallingConvention;
141 switch (conv) {
142
143 case CC::NearC:
144 case CC::FarC:
145 return clang::CallingConv::CC_C;
146 case CC::NearPascal:
147 case CC::FarPascal:
148 return clang::CallingConv::CC_X86Pascal;
149 case CC::NearFast:
150 case CC::FarFast:
151 return clang::CallingConv::CC_X86FastCall;
152 case CC::NearStdCall:
153 case CC::FarStdCall:
154 return clang::CallingConv::CC_X86StdCall;
155 case CC::ThisCall:
156 return clang::CallingConv::CC_X86ThisCall;
157 case CC::NearVector:
158 return clang::CallingConv::CC_X86VectorCall;
159 default:
160 return std::nullopt;
161 }
162}
163
164static bool IsAnonymousNamespaceName(llvm::StringRef name) {
165 return name == "`anonymous namespace'" || name == "`anonymous-namespace'";
166}
167
170
174
175std::pair<clang::DeclContext *, std::string>
177 TypeIndex ti) {
179 m_clang.GetSymbolFile()->GetBackingSymbolFile());
180 // FIXME: Move this to GetDeclContextContainingUID.
181 if (!record.hasUniqueName())
182 return CreateDeclInfoForUndecoratedName(record.Name);
183
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);
187 if (demangler.Error)
188 return CreateDeclInfoForUndecoratedName(record.Name);
189
190 llvm::ms_demangle::IdentifierNode *idn =
191 ttn->QualifiedName->getUnqualifiedIdentifier();
192 std::string uname = idn->toString(llvm::ms_demangle::OF_NoTagSpecifier);
193
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);
198
199 clang::DeclContext *context = m_clang.GetTranslationUnitDecl();
200
201 // If this type doesn't have a parent type in the debug info, then the best we
202 // can do is to say that it's either a series of namespaces (if the scope is
203 // non-empty), or the translation unit (if the scope is empty).
204 std::optional<TypeIndex> parent_index = pdb->GetParentType(ti);
205 if (!parent_index) {
206 if (scopes.empty())
207 return {context, uname};
208
209 // If there is no parent in the debug info, but some of the scopes have
210 // template params, then this is a case of bad debug info. See, for
211 // example, llvm.org/pr39607. We don't want to create an ambiguity between
212 // a NamespaceDecl and a CXXRecordDecl, so instead we create a class at
213 // global scope with the fully qualified name.
214 if (AnyScopesHaveTemplateParams(scopes))
215 return {context, std::string(record.Name)};
216
217 for (llvm::ms_demangle::Node *scope : scopes) {
218 auto *nii = static_cast<llvm::ms_demangle::NamedIdentifierNode *>(scope);
219 std::string str = nii->toString();
220 context = GetOrCreateNamespaceDecl(str.c_str(), *context);
221 }
222 return {context, uname};
223 }
224
225 // Otherwise, all we need to do is get the parent type of this type and
226 // recurse into our lazy type creation / AST reconstruction logic to get an
227 // LLDB TypeSP for the parent. This will cause the AST to automatically get
228 // the right DeclContext created for any parent.
229 clang::QualType parent_qt = GetOrCreateClangType(*parent_index);
230 if (parent_qt.isNull())
231 return {nullptr, ""};
232
233 context = clang::TagDecl::castToDeclContext(parent_qt->getAsTagDecl());
234 return {context, uname};
235}
236
237static bool isLocalVariableType(SymbolKind K) {
238 switch (K) {
239 case S_REGISTER:
240 case S_REGREL32:
241 case S_REGREL32_INDIR:
242 case S_LOCAL:
243 return true;
244 default:
245 break;
246 }
247 return false;
248}
249
252 m_clang.GetSymbolFile()->GetBackingSymbolFile());
253 PdbIndex &index = pdb->GetIndex();
254 CVSymbol cvs = index.ReadSymbolRecord(id);
255
256 if (isLocalVariableType(cvs.kind())) {
257 clang::DeclContext *scope = GetParentClangDeclContext(id);
258 if (!scope)
259 return nullptr;
260 clang::Decl *scope_decl = clang::Decl::castFromDeclContext(scope);
261 PdbCompilandSymId scope_id =
262 PdbSymUid(m_decl_to_status[scope_decl].uid).asCompilandSym();
263 return GetOrCreateVariableDecl(scope_id, id);
264 }
265
266 switch (cvs.kind()) {
267 case S_GPROC32:
268 case S_LPROC32:
269 return GetOrCreateFunctionDecl(id);
270 case S_GDATA32:
271 case S_LDATA32:
272 case S_GTHREAD32:
273 case S_CONSTANT:
274 // global variable
275 return nullptr;
276 case S_BLOCK32:
277 return GetOrCreateBlockDecl(id);
278 case S_INLINESITE:
280 default:
281 return nullptr;
282 }
283}
284
286 if (clang::Decl *result = TryGetDecl(uid))
287 return ToCompilerDecl(result);
288
289 clang::Decl *result = nullptr;
290 switch (uid.kind()) {
293 break;
294 case PdbSymUidKind::Type: {
295 clang::QualType qt = GetOrCreateClangType(uid.asTypeSym());
296 if (qt.isNull())
297 return CompilerDecl();
298 if (auto *tag = qt->getAsTagDecl()) {
299 result = tag;
300 break;
301 }
302 return CompilerDecl();
303 }
304 default:
305 return CompilerDecl();
306 }
307
308 if (!result)
309 return CompilerDecl();
310 m_uid_to_decl[toOpaqueUid(uid)] = result;
311 return ToCompilerDecl(result);
312}
313
314clang::DeclContext *
316 if (uid.kind() == PdbSymUidKind::CompilandSym) {
317 if (uid.asCompilandSym().offset == 0)
319 }
320 clang::Decl *decl = FromCompilerDecl(GetOrCreateDeclForUid(uid));
321 if (!decl)
322 return nullptr;
323
324 return clang::Decl::castToDeclContext(decl);
325}
326
331
332std::pair<clang::DeclContext *, std::string>
335 m_clang.GetSymbolFile()->GetBackingSymbolFile());
336 PdbIndex &index = pdb->GetIndex();
337 MSVCUndecoratedNameParser parser(name);
338 llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs = parser.GetSpecifiers();
339
341
342 llvm::StringRef uname = specs.back().GetBaseName();
343 specs = specs.drop_back();
344 if (specs.empty())
345 return {context, std::string(name)};
346
347 llvm::StringRef scope_name = specs.back().GetFullName();
348
349 // It might be a class name, try that first.
350 std::vector<TypeIndex> types = index.tpi().findRecordsByName(scope_name);
351 while (!types.empty()) {
352 clang::QualType qt = GetOrCreateClangType(types.back());
353 if (qt.isNull())
354 continue;
355 clang::TagDecl *tag = qt->getAsTagDecl();
356 if (tag)
357 return {clang::TagDecl::castToDeclContext(tag), std::string(uname)};
358 types.pop_back();
359 }
360
361 // If that fails, treat it as a series of namespaces.
362 for (const MSVCUndecoratedNameSpecifier &spec : specs) {
363 std::string ns_name = spec.GetBaseName().str();
364 context = GetOrCreateNamespaceDecl(ns_name.c_str(), *context);
365 }
366 return {context, std::string(uname)};
367}
368
369clang::DeclContext *
371 PdbCompilandSymId uid) {
373 m_clang.GetSymbolFile()->GetBackingSymbolFile());
374 PdbIndex &index = pdb->GetIndex();
375 CVSymbol sym = index.ReadSymbolRecord(uid);
376
377 llvm::StringRef symbol_name = getSymbolName(sym);
378
379 std::optional<PdbTypeSymId> func_id = GetFunctionType(sym);
380 if (!func_id || !symbol_name.contains("::"))
381 return CreateDeclInfoForUndecoratedName(symbol_name).first;
382
383 // Try to get the context from class type of an LF_MFUNCTION.
384 // For some types, we might not find a class type.
385 auto get_member_fn_context = [&]() -> clang::DeclContext * {
386 TypeIndex id = func_id->index;
387
388 if (func_id->is_ipi) {
389 // Type from IPI, for example from S_INLINESITE
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)
393 return nullptr;
394
395 MemberFuncIdRecord record;
396 llvm::Error err = TypeDeserializer::deserializeAs<MemberFuncIdRecord>(
397 *func_id_type, record);
398 if (err) {
399 llvm::consumeError(std::move(err));
400 return nullptr;
401 }
402
403 id = record.FunctionType;
404 }
405
406 std::optional<CVType> func_type = index.tpi().tryGetType(id);
407 if (!func_type || func_type->kind() != LF_MFUNCTION)
408 return nullptr;
409
410 MemberFunctionRecord mfr(TypeRecordKind::MemberFunction);
411
412 llvm::Error err =
413 TypeDeserializer::deserializeAs<MemberFunctionRecord>(*func_type, mfr);
414 if (err || mfr.ClassType.isNoneType()) {
415 llvm::consumeError(std::move(err));
416 return nullptr;
417 }
418
419 clang::QualType qt = GetOrCreateClangType(mfr.ClassType);
420 if (qt.isNull())
421 return nullptr;
422 clang::TagDecl *tag = qt->getAsTagDecl();
423 if (!tag)
424 return nullptr;
425
426 return clang::TagDecl::castToDeclContext(tag);
427 };
428
429 clang::DeclContext *context = get_member_fn_context();
430 if (!context)
431 return CreateDeclInfoForUndecoratedName(symbol_name).first;
432
433 return context;
434}
435
436clang::DeclContext *
438 // We must do this *without* calling GetOrCreate on the current uid, as
439 // that would be an infinite recursion.
441 m_clang.GetSymbolFile()->GetBackingSymbolFile());
442 PdbIndex &index = pdb->GetIndex();
443 switch (uid.kind()) {
445 std::optional<PdbCompilandSymId> scope =
446 pdb->FindSymbolScope(uid.asCompilandSym());
447 if (scope)
449
451 }
452 case PdbSymUidKind::Type: {
453 // It could be a namespace, class, or global. We don't support nested
454 // functions yet. Anyway, we just need to consult the parent type map.
455 PdbTypeSymId type_id = uid.asTypeSym();
456 std::optional<TypeIndex> parent_index = pdb->GetParentType(type_id.index);
457 if (!parent_index)
459 return GetOrCreateClangDeclContextForUid(PdbTypeSymId(*parent_index));
460 }
462 // In this case the parent DeclContext is the one for the class that this
463 // member is inside of.
464 break;
466 // If this refers to a compiland symbol, just recurse in with that symbol.
467 // The only other possibilities are S_CONSTANT and S_UDT, in which case we
468 // need to parse the undecorated name to figure out the scope, then look
469 // that up in the TPI stream. If it's found, it's a type, othewrise it's
470 // a series of namespaces.
471 // FIXME: do this.
472 CVSymbol global = index.ReadSymbolRecord(uid.asGlobalSym());
473 switch (global.kind()) {
474 case SymbolKind::S_GDATA32:
475 case SymbolKind::S_LDATA32:
476 return CreateDeclInfoForUndecoratedName(getSymbolName(global)).first;
477 case SymbolKind::S_PROCREF:
478 case SymbolKind::S_LPROCREF: {
479 ProcRefSym ref{global.kind()};
480 llvm::Error err =
481 SymbolDeserializer::deserializeAs<ProcRefSym>(global, ref);
482 if (err) {
483 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
484 "Failed to deserialize {1} as ProcRef: {0}",
485 uid.asGlobalSym());
486 return nullptr;
487 }
488 PdbCompilandSymId cu_sym_id{ref.modi(), ref.SymOffset};
489 return GetParentClangDeclContext(cu_sym_id);
490 }
491 case SymbolKind::S_CONSTANT:
492 case SymbolKind::S_UDT:
493 return CreateDeclInfoForUndecoratedName(getSymbolName(global)).first;
494 default:
495 break;
496 }
497 break;
498 }
499 default:
500 break;
501 }
503}
504
508
510 if (GetClangASTImporter().CanImport(ct))
512
513 clang::QualType qt = FromCompilerType(ct);
514 if (qt.isNull())
515 return false;
516 clang::TagDecl *tag = qt->getAsTagDecl();
517 if (qt->isArrayType()) {
518 const clang::Type *element_type = qt->getArrayElementTypeNoTypeQual();
519 tag = element_type->getAsTagDecl();
520 }
521 if (!tag)
522 return false;
523
524 return CompleteTagDecl(*tag);
525}
526
527bool PdbAstBuilderClang::CompleteTagDecl(clang::TagDecl &tag) {
528 auto status_iter = m_decl_to_status.find(&tag);
529 if (status_iter == m_decl_to_status.end()) {
530 // If this is not in our map, it's an error.
531 assert(false && "completing unknown tag decl");
532 return false;
533 }
534
535 // If it's already complete, just return.
536 DeclStatus &status = status_iter->second;
537 if (status.resolved)
538 return true;
539
540 PdbTypeSymId type_id = PdbSymUid(status.uid).asTypeSym();
541 PdbIndex &index = static_cast<SymbolFileNativePDB *>(
542 m_clang.GetSymbolFile()->GetBackingSymbolFile())
543 ->GetIndex();
544
545 clang::QualType tag_qt = m_clang.getASTContext().getCanonicalTagType(&tag);
546 TypeSystemClang::SetHasExternalStorage(tag_qt.getAsOpaquePtr(), false);
547
548 TypeIndex tag_ti = type_id.index;
549 CVType cvt = index.tpi().getType(tag_ti);
550 if (cvt.kind() == LF_MODIFIER)
551 tag_ti = LookThroughModifierRecord(cvt);
552
553 PdbTypeSymId best_ti = GetBestPossibleDecl(tag_ti, index.tpi());
554 cvt = index.tpi().getType(best_ti.index);
555 if (!IsTagRecord(cvt)) {
556 assert(false && "completing tag record that's not a tag record");
557 return false;
558 }
559
560 if (IsForwardRefUdt(cvt)) {
561 // If we can't find a full decl for this forward ref anywhere in the debug
562 // info, then we have no way to complete it.
563 return false;
564 }
565
566 TypeIndex field_list_ti = GetFieldListIndex(cvt);
567 CVType field_list_cvt = index.tpi().getType(field_list_ti);
568 if (field_list_cvt.kind() != LF_FIELDLIST)
569 return false;
570 FieldListRecord field_list;
571 if (llvm::Error error = TypeDeserializer::deserializeAs<FieldListRecord>(
572 field_list_cvt, field_list))
573 llvm::consumeError(std::move(error));
574
575 // Visit all members of this class, then perform any finalization necessary
576 // to complete the class.
577 CompilerType ct = ToCompilerType(tag_qt);
578 UdtRecordCompleter completer(best_ti, ct, tag, *this, index,
580 llvm::Error error =
581 llvm::codeview::visitMemberRecordStream(field_list.Data, completer);
582 completer.complete();
583
584 m_decl_to_status[&tag].resolved = true;
585 if (error) {
586 llvm::consumeError(std::move(error));
587 return false;
588 }
589 return true;
590}
591
593 if (ti == TypeIndex::NullptrT())
595
596 if (ti.getSimpleMode() != SimpleTypeMode::Direct) {
597 clang::QualType direct_type = GetOrCreateClangType(ti.makeDirect());
598 if (direct_type.isNull())
599 return {};
600 return m_clang.getASTContext().getPointerType(direct_type);
601 }
602
603 if (ti.getSimpleKind() == SimpleTypeKind::NotTranslated)
604 return {};
605
606 lldb::BasicType bt = GetCompilerTypeForSimpleKind(ti.getSimpleKind());
607 if (bt == lldb::eBasicTypeInvalid)
608 return {};
609
610 return GetBasicType(bt);
611}
612
613clang::QualType
614PdbAstBuilderClang::CreatePointerType(const PointerRecord &pointer) {
615 clang::QualType pointee_type = GetOrCreateClangType(pointer.ReferentType);
616
617 // This can happen for pointers to LF_VTSHAPE records, which we shouldn't
618 // create in the AST.
619 if (pointee_type.isNull())
620 return {};
621
622 if (pointer.isPointerToMember()) {
623 MemberPointerInfo mpi = pointer.getMemberInfo();
624 clang::QualType class_type = GetOrCreateClangType(mpi.ContainingType);
625 if (class_type.isNull())
626 return {};
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:
633 spelling =
634 clang::MSInheritanceAttr::Spelling::Keyword_single_inheritance;
635 break;
636 case llvm::codeview::PointerToMemberRepresentation::
637 MultipleInheritanceData:
638 case llvm::codeview::PointerToMemberRepresentation::
639 MultipleInheritanceFunction:
640 spelling =
641 clang::MSInheritanceAttr::Spelling::Keyword_multiple_inheritance;
642 break;
643 case llvm::codeview::PointerToMemberRepresentation::
644 VirtualInheritanceData:
645 case llvm::codeview::PointerToMemberRepresentation::
646 VirtualInheritanceFunction:
647 spelling =
648 clang::MSInheritanceAttr::Spelling::Keyword_virtual_inheritance;
649 break;
650 case llvm::codeview::PointerToMemberRepresentation::Unknown:
651 spelling =
652 clang::MSInheritanceAttr::Spelling::Keyword_unspecified_inheritance;
653 break;
654 default:
655 spelling = clang::MSInheritanceAttr::Spelling::SpellingNotCalculated;
656 break;
657 }
658 tag->addAttr(clang::MSInheritanceAttr::CreateImplicit(
659 m_clang.getASTContext(), spelling));
660 }
661 return m_clang.getASTContext().getMemberPointerType(
662 pointee_type, /*Qualifier=*/std::nullopt,
663 class_type->getAsCXXRecordDecl());
664 }
665
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);
671 else
672 pointer_type = m_clang.getASTContext().getPointerType(pointee_type);
673
674 if ((pointer.getOptions() & PointerOptions::Const) != PointerOptions::None)
675 pointer_type.addConst();
676
677 if ((pointer.getOptions() & PointerOptions::Volatile) != PointerOptions::None)
678 pointer_type.addVolatile();
679
680 if ((pointer.getOptions() & PointerOptions::Restrict) != PointerOptions::None)
681 pointer_type.addRestrict();
682
683 return pointer_type;
684}
685
686clang::QualType
687PdbAstBuilderClang::CreateModifierType(const ModifierRecord &modifier) {
688 clang::QualType unmodified_type = GetOrCreateClangType(modifier.ModifiedType);
689 if (unmodified_type.isNull())
690 return {};
691
692 if ((modifier.Modifiers & ModifierOptions::Const) != ModifierOptions::None)
693 unmodified_type.addConst();
694 if ((modifier.Modifiers & ModifierOptions::Volatile) != ModifierOptions::None)
695 unmodified_type.addVolatile();
696
697 return unmodified_type;
698}
699
700clang::QualType
702 const CVTagRecord &record) {
703 clang::DeclContext *context = nullptr;
704 std::string uname;
705 std::tie(context, uname) = CreateDeclInfoForType(record.asTag(), id.index);
706 if (!context)
707 return {};
708
709 clang::TagTypeKind ttk = TranslateUdtKind(record.asTag());
710 ClangASTMetadata metadata;
711 metadata.SetUserID(toOpaqueUid(id));
712 metadata.SetIsDynamicCXXType(IsDynamicTagRecord(record));
713
714 CompilerType ct = m_clang.CreateRecordType(
715 context, OptionalClangModuleID(), uname, llvm::to_underlying(ttk),
717 if (!ct.IsValid()) {
718 LLDB_LOG(GetLog(LLDBLog::Symbols), "failed to create record type for {0}",
719 id);
720 return {};
721 }
722
724
725 // Even if it's possible, don't complete it at this point. Just mark it
726 // forward resolved, and if/when LLDB needs the full definition, it can
727 // ask us.
728 clang::QualType result =
729 clang::QualType::getFromOpaquePtr(ct.GetOpaqueQualType());
730
731 TypeSystemClang::SetHasExternalStorage(result.getAsOpaquePtr(), true);
732 return result;
733}
734
736 auto iter = m_uid_to_decl.find(toOpaqueUid(uid));
737 if (iter != m_uid_to_decl.end())
738 return iter->second;
739 return nullptr;
740}
741
742clang::NamespaceDecl *
744 clang::DeclContext &context) {
745 clang::NamespaceDecl *ns = m_clang.GetUniqueNamespaceDeclaration(
746 IsAnonymousNamespaceName(name) ? nullptr : name, &context,
748 m_known_namespaces.insert(ns);
749 m_parent_to_namespaces[&context].insert(ns);
750 return ns;
751}
752
753clang::BlockDecl *
755 if (clang::Decl *decl = TryGetDecl(block_id))
756 return llvm::dyn_cast<clang::BlockDecl>(decl);
757
758 clang::DeclContext *scope = GetParentClangDeclContext(block_id);
759
760 clang::BlockDecl *block_decl =
761 m_clang.CreateBlockDeclaration(scope, OptionalClangModuleID());
762 m_uid_to_decl.insert({toOpaqueUid(block_id), block_decl});
763
764 DeclStatus status;
765 status.resolved = true;
766 status.uid = toOpaqueUid(block_id);
767 m_decl_to_status.insert({block_decl, status});
768
769 return block_decl;
770}
771
772clang::VarDecl *
774 clang::DeclContext &scope) {
775 VariableInfo var_info = GetVariableNameInfo(sym);
776 clang::QualType qt = GetOrCreateClangType(var_info.type);
777 if (qt.isNull())
778 return nullptr;
779
780 clang::VarDecl *var_decl = m_clang.CreateVariableDeclaration(
781 &scope, OptionalClangModuleID(), var_info.name.str().c_str(), qt);
782
783 m_uid_to_decl[toOpaqueUid(uid)] = var_decl;
784 DeclStatus status;
785 status.resolved = true;
786 status.uid = toOpaqueUid(uid);
787 m_decl_to_status.insert({var_decl, status});
788 return var_decl;
789}
790
791clang::VarDecl *
793 PdbCompilandSymId var_id) {
794 if (clang::Decl *decl = TryGetDecl(var_id))
795 return llvm::dyn_cast<clang::VarDecl>(decl);
796
797 clang::DeclContext *scope = GetOrCreateClangDeclContextForUid(scope_id);
798 if (!scope)
799 return nullptr;
800
802 m_clang.GetSymbolFile()->GetBackingSymbolFile());
803 PdbIndex &index = pdb->GetIndex();
804 CVSymbol sym = index.ReadSymbolRecord(var_id);
805 return CreateVariableDecl(PdbSymUid(var_id), sym, *scope);
806}
807
808clang::VarDecl *
810 if (clang::Decl *decl = TryGetDecl(var_id))
811 return llvm::dyn_cast<clang::VarDecl>(decl);
812
814 m_clang.GetSymbolFile()->GetBackingSymbolFile());
815 PdbIndex &index = pdb->GetIndex();
816 CVSymbol sym = index.ReadSymbolRecord(var_id);
818 return CreateVariableDecl(PdbSymUid(var_id), sym, *context);
819}
820
822 if (clang::Decl *decl = TryGetDecl(id)) {
823 if (auto *tnd = llvm::dyn_cast<clang::TypedefNameDecl>(decl))
824 return ToCompilerType(m_clang.getASTContext().getTypeDeclType(tnd));
825 return CompilerType();
826 }
827
829 m_clang.GetSymbolFile()->GetBackingSymbolFile());
830 PdbIndex &index = pdb->GetIndex();
831 CVSymbol sym = index.ReadSymbolRecord(id);
832 if (sym.kind() != S_UDT) {
833 assert(false && "called on a non-udt type");
834 return {};
835 }
836 llvm::Expected<UDTSym> udt = SymbolDeserializer::deserializeAs<UDTSym>(sym);
837 if (!udt) {
838 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), udt.takeError(),
839 "Failed to deserialize {1} as UDT: {0}", id);
840 return CompilerType();
841 }
842
843 clang::DeclContext *scope = GetParentClangDeclContext(id);
844
845 PdbTypeSymId real_type_id{udt->Type, false};
846 clang::QualType qt = GetOrCreateClangType(real_type_id);
847 if (qt.isNull() || !scope)
848 return CompilerType();
849
850 std::string uname = std::string(DropNameScope(udt->Name));
851
853 uname.c_str(), ToCompilerDeclContext(scope), 0);
854 DeclStatus status;
855 status.resolved = true;
856 status.uid = toOpaqueUid(id);
857 m_decl_to_status.insert({m_clang.GetAsTypedefDecl(ct), status});
858 return ct;
859}
860
862 CompilerType ct = m_clang.GetBasicType(type);
863 return clang::QualType::getFromOpaquePtr(ct.GetOpaqueQualType());
864}
865
867 if (type.index.isSimple())
868 return CreateSimpleType(type.index);
869
871 m_clang.GetSymbolFile()->GetBackingSymbolFile());
872 PdbIndex &index = pdb->GetIndex();
873 CVType cvt = index.tpi().getType(type.index);
874
875 if (cvt.kind() == LF_MODIFIER) {
876 ModifierRecord modifier;
877 llvm::Error err =
878 TypeDeserializer::deserializeAs<ModifierRecord>(cvt, modifier);
879 if (err) {
880 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
881 "Failed to deserialize {1} as Modifier: {0}", type.index);
882 return {};
883 }
884 return CreateModifierType(modifier);
885 }
886
887 if (cvt.kind() == LF_POINTER) {
888 PointerRecord pointer;
889 llvm::Error err =
890 TypeDeserializer::deserializeAs<PointerRecord>(cvt, pointer);
891 if (err) {
892 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
893 "Failed to deserialize {1} as Pointer: {0}", type.index);
894 return {};
895 }
896 return CreatePointerType(pointer);
897 }
898
899 if (IsTagRecord(cvt)) {
901 if (tag.kind() == CVTagRecord::Enum)
902 return CreateEnumType(type.index, tag.asEnum());
903 return CreateRecordType(type.index, tag);
904 }
905
906 if (cvt.kind() == LF_ARRAY) {
907 ArrayRecord ar;
908 llvm::Error err = TypeDeserializer::deserializeAs<ArrayRecord>(cvt, ar);
909 if (err) {
910 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
911 "Failed to deserialize {1} as Array: {0}", type.index);
912 return {};
913 }
914 return CreateArrayType(ar);
915 }
916
917 if (cvt.kind() == LF_PROCEDURE) {
918 ProcedureRecord pr;
919 llvm::Error err = TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, pr);
920 if (err) {
921 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
922 "Failed to deserialize {1} as Procedure: {0}", type.index);
923 return {};
924 }
925 return CreateFunctionType(pr.ArgumentList, pr.ReturnType, pr.CallConv,
926 /*type_quals=*/0);
927 }
928
929 if (cvt.kind() == LF_MFUNCTION) {
930 MemberFunctionRecord mfr;
931 llvm::Error err =
932 TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfr);
933 if (err) {
934 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
935 "Failed to deserialize {1} as MemberFunction: {0}",
936 type.index);
937 return {};
938 }
939 unsigned int type_quals = 0;
940 if (!mfr.ThisType.isNoneType()) {
941 clang::QualType this_type = GetOrCreateClangType(mfr.getThisType());
942 if (!this_type.isNull())
943 type_quals = this_type->getPointeeType().getLocalFastQualifiers();
944 }
945 return CreateFunctionType(mfr.ArgumentList, mfr.ReturnType, mfr.CallConv,
946 type_quals);
947 }
948
949 return {};
950}
951
953 if (type.index.isNoneType())
954 return {};
955
956 lldb::user_id_t uid = toOpaqueUid(type);
957 auto iter = m_uid_to_type.find(uid);
958 if (iter != m_uid_to_type.end())
959 return iter->second;
960
962 m_clang.GetSymbolFile()->GetBackingSymbolFile());
963 PdbIndex &index = pdb->GetIndex();
964 PdbTypeSymId best_type = GetBestPossibleDecl(type, index.tpi());
965
966 clang::QualType qt;
967 if (best_type.index != type.index) {
968 // This is a forward decl. Call GetOrCreate on the full decl, then map the
969 // forward decl id to the full decl QualType.
970 clang::QualType qt = GetOrCreateClangType(best_type);
971 if (qt.isNull())
972 return {};
973 m_uid_to_type[toOpaqueUid(type)] = qt;
974 return qt;
975 }
976
977 // This is either a full decl, or a forward decl with no matching full decl
978 // in the debug info.
979 qt = CreateType(type);
980 if (qt.isNull())
981 return {};
982
983 m_uid_to_type[toOpaqueUid(type)] = qt;
984 if (IsTagRecord(type, index.tpi())) {
985 clang::TagDecl *tag = qt->getAsTagDecl();
986 assert(m_decl_to_status.count(tag) == 0 && "type already created");
987
988 DeclStatus &status = m_decl_to_status[tag];
989 status.uid = uid;
990 status.resolved = false;
991
992 if (auto *enum_decl = llvm::dyn_cast<clang::EnumDecl>(tag)) {
993 if (!CompleteTagDecl(*enum_decl)) {
995 m_decl_to_status[enum_decl].resolved = true;
996 }
997 }
998 }
999 return qt;
1000}
1001
1003 clang::QualType qt = GetOrCreateClangType(type);
1004 if (qt.isNull())
1005 return {};
1006 return ToCompilerType(qt);
1007}
1008
1010 lldb::opaque_compiler_type_t parent_ty, llvm::StringRef name,
1011 llvm::StringRef asm_label, const CompilerType &method_ct, bool is_virtual,
1012 bool is_static, bool is_artificial) {
1013 clang::CXXMethodDecl *&method_decl = m_cxx_method_decls[{
1014 parent_ty, ConstString(name), method_ct.GetOpaqueQualType()}];
1015 if (!method_decl)
1016 method_decl = m_clang.AddMethodToCXXRecordType(
1017 parent_ty, name, asm_label, method_ct, is_virtual, is_static,
1018 /*is_inline=*/false, /*is_explicit=*/false,
1019 /*is_attr_used=*/false, is_artificial);
1020 return method_decl;
1021}
1022
1024 PdbCompilandSymId func_id, llvm::StringRef func_name, TypeIndex func_ti,
1025 CompilerType func_ct, uint32_t param_count,
1026 clang::StorageClass func_storage, bool is_inline,
1027 clang::DeclContext *parent) {
1028 clang::FunctionDecl *function_decl = nullptr;
1029 if (parent->isRecord()) {
1031 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1032 PdbIndex &index = pdb->GetIndex();
1033 clang::CanQualType parent_qt =
1034 m_clang.getASTContext().getCanonicalTypeDeclType(
1035 llvm::cast<clang::TypeDecl>(parent));
1036 lldb::opaque_compiler_type_t parent_opaque_ty =
1037 ToCompilerType(parent_qt).GetOpaqueQualType();
1038 // The method may already have been added while completing the class.
1039 auto iter =
1040 m_cxx_method_decls.find({parent_opaque_ty, ConstString(func_name),
1041 func_ct.GetOpaqueQualType()});
1042 if (iter != m_cxx_method_decls.end())
1043 return iter->second;
1044
1045 CVType cvt = index.tpi().getType(func_ti);
1046 MemberFunctionRecord func_record(static_cast<TypeRecordKind>(cvt.kind()));
1047 llvm::Error err =
1048 TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, func_record);
1049 if (err) {
1050 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1051 "Failed to deserialize {1} as MemberFunction: {0}",
1052 func_ti);
1053 return nullptr;
1054 }
1055 TypeIndex class_index = func_record.getClassType();
1056
1057 CVType parent_cvt = index.tpi().getType(class_index);
1058 if (!IsTagRecord(parent_cvt))
1059 return nullptr;
1060 TagRecord tag_record = CVTagRecord::create(parent_cvt).asTag();
1061 // If it's a forward reference, try to get the real TypeIndex.
1062 if (tag_record.isForwardRef()) {
1063 llvm::Expected<TypeIndex> eti =
1064 index.tpi().findFullDeclForForwardRef(class_index);
1065 if (eti) {
1066 CVType resolved_tag_record = index.tpi().getType(*eti);
1067 if (!IsTagRecord(resolved_tag_record))
1068 return nullptr;
1069 tag_record = CVTagRecord::create(resolved_tag_record).asTag();
1070 } else {
1071 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), eti.takeError(),
1072 "failed to find full decl for forward ref: {0}");
1073 }
1074 }
1075
1076 std::string asm_label = pdb->GetFunctionCallLabel(func_id);
1077
1078 if (!tag_record.FieldList.isSimple()) {
1079 CVType field_list_cvt = index.tpi().getType(tag_record.FieldList);
1080 FieldListRecord field_list;
1081 if (llvm::Error error = TypeDeserializer::deserializeAs<FieldListRecord>(
1082 field_list_cvt, field_list))
1083 llvm::consumeError(std::move(error));
1084 CreateMethodDecl process(index, *this, func_ti, function_decl,
1085 parent_opaque_ty, func_name, asm_label, func_ct);
1086 if (llvm::Error err = visitMemberRecordStream(field_list.Data, process))
1087 llvm::consumeError(std::move(err));
1088 }
1089
1090 if (!function_decl)
1091 function_decl = GetOrCreateMethodDecl(
1092 parent_opaque_ty, func_name, asm_label, func_ct,
1093 /*is_virtual=*/false, /*is_static=*/false, /*is_artificial=*/false);
1094 } else {
1096 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1097 function_decl = m_clang.CreateFunctionDeclaration(
1098 parent, OptionalClangModuleID(), func_name, func_ct, func_storage,
1099 is_inline, pdb->GetFunctionCallLabel(func_id));
1100 CreateFunctionParameters(func_id, *function_decl, param_count);
1101 }
1102 return function_decl;
1103}
1104
1106 PdbCompilandSymId inlinesite_id) {
1108 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1109 PdbIndex &index = pdb->GetIndex();
1110 CompilandIndexItem *cii = index.compilands().GetCompiland(inlinesite_id.modi);
1111 CVSymbol sym = cii->m_debug_stream.readSymbolAtOffset(inlinesite_id.offset);
1112 InlineSiteSym inline_site(static_cast<SymbolRecordKind>(sym.kind()));
1113 llvm::Error err =
1114 SymbolDeserializer::deserializeAs<InlineSiteSym>(sym, inline_site);
1115 if (err) {
1116 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1117 "Failed to deserialize {1} as InlineSite: {0}",
1118 inlinesite_id);
1119 return nullptr;
1120 }
1121
1122 // Inlinee is the id index to the function id record that is inlined.
1123 PdbTypeSymId func_id(inline_site.Inlinee, true);
1124 // Look up the function decl by the id index to see if we have created a
1125 // function decl for a different inlinesite that refers the same function.
1126 if (clang::Decl *decl = TryGetDecl(func_id))
1127 return llvm::dyn_cast<clang::FunctionDecl>(decl);
1128 clang::FunctionDecl *function_decl =
1129 CreateFunctionDeclFromId(func_id, inlinesite_id);
1130 if (function_decl == nullptr)
1131 return nullptr;
1132
1133 // Use inline site id in m_decl_to_status because it's expected to be a
1134 // PdbCompilandSymId so that we can parse local variables info after it.
1135 uint64_t inlinesite_uid = toOpaqueUid(inlinesite_id);
1136 DeclStatus status;
1137 status.resolved = true;
1138 status.uid = inlinesite_uid;
1139 m_decl_to_status.insert({function_decl, status});
1140 // Use the index in IPI stream as uid in m_uid_to_decl, because index in IPI
1141 // stream are unique and there could be multiple inline sites (different ids)
1142 // referring the same inline function. This avoid creating multiple same
1143 // inline function delcs.
1144 uint64_t func_uid = toOpaqueUid(func_id);
1145 assert(m_uid_to_decl.count(func_uid) == 0 && "already created");
1146 m_uid_to_decl[func_uid] = function_decl;
1147 return function_decl;
1148}
1149
1150clang::FunctionDecl *
1152 PdbCompilandSymId func_sid) {
1153 if (!func_tid.is_ipi) {
1154 assert(false && "called with non-ipi index");
1155 return nullptr;
1156 }
1157
1159 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1160 PdbIndex &index = pdb->GetIndex();
1161 std::optional<CVType> func_cvt =
1162 index.ipi().typeCollection().tryGetType(func_tid.index);
1163 if (!func_cvt)
1164 return nullptr;
1165 llvm::StringRef func_name;
1166 TypeIndex func_ti;
1167 clang::DeclContext *parent = nullptr;
1168 switch (func_cvt->kind()) {
1169 case LF_MFUNC_ID: {
1170 MemberFuncIdRecord mfr;
1171 llvm::Error err =
1172 TypeDeserializer::deserializeAs<MemberFuncIdRecord>(*func_cvt, mfr);
1173 if (err) {
1174 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1175 "Failed to deserialize {1} (IPI) as MemberFuncId: {0}",
1176 func_tid.index);
1177 return nullptr;
1178 }
1179 func_name = mfr.getName();
1180 func_ti = mfr.getFunctionType();
1181 PdbTypeSymId class_type_id(mfr.ClassType, false);
1182 parent = GetOrCreateClangDeclContextForUid(class_type_id);
1183 break;
1184 }
1185 case LF_FUNC_ID: {
1186 FuncIdRecord fir;
1187 llvm::Error err =
1188 TypeDeserializer::deserializeAs<FuncIdRecord>(*func_cvt, fir);
1189 if (err) {
1190 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1191 "Failed to deserialize {1} (IPI) as FuncId: {0}",
1192 func_tid.index);
1193 return nullptr;
1194 }
1195 func_name = fir.getName();
1196 func_ti = fir.getFunctionType();
1198 if (!fir.ParentScope.isNoneType()) {
1199 CVType parent_cvt = index.ipi().getType(fir.ParentScope);
1200 if (parent_cvt.kind() == LF_STRING_ID) {
1201 StringIdRecord sir;
1202 err = TypeDeserializer::deserializeAs<StringIdRecord>(parent_cvt, sir);
1203 if (err) {
1204 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1205 "Failed to deserialize {1} (IPI) as StringId: {0}",
1206 fir.ParentScope);
1207 return nullptr;
1208 }
1209 parent = GetOrCreateNamespaceDecl(sir.String.data(), *parent);
1210 }
1211 }
1212 break;
1213 }
1214 default:
1215 LLDB_LOG(GetLog(LLDBLog::Symbols), "{0} is not a function type", func_tid);
1216 return nullptr;
1217 }
1218 clang::QualType func_qt = GetOrCreateClangType(func_ti);
1219 if (func_qt.isNull() || !parent)
1220 return nullptr;
1221 CompilerType func_ct = ToCompilerType(func_qt);
1222 uint32_t param_count =
1223 llvm::cast<clang::FunctionProtoType>(func_qt)->getNumParams();
1224 return CreateFunctionDecl(func_sid, func_name, func_ti, func_ct, param_count,
1225 clang::SC_None, true, parent);
1226}
1227
1228clang::FunctionDecl *
1230 if (clang::Decl *decl = TryGetDecl(func_id))
1231 return llvm::dyn_cast<clang::FunctionDecl>(decl);
1232
1233 clang::DeclContext *parent = GetParentClangDeclContext(PdbSymUid(func_id));
1234 if (!parent)
1235 return nullptr;
1236 std::string context_name;
1237 if (clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(parent)) {
1238 context_name = ns->getQualifiedNameAsString();
1239 } else if (clang::TagDecl *tag = llvm::dyn_cast<clang::TagDecl>(parent)) {
1240 context_name = tag->getQualifiedNameAsString();
1241 }
1242
1244 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1245 PdbIndex &index = pdb->GetIndex();
1246 CVSymbol cvs = index.ReadSymbolRecord(func_id);
1247 ProcSym proc(static_cast<SymbolRecordKind>(cvs.kind()));
1248 llvm::Error err = SymbolDeserializer::deserializeAs<ProcSym>(cvs, proc);
1249 if (err) {
1250 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1251 "Failed to deserialize {1} as Proc: {0}", func_id);
1252 return nullptr;
1253 }
1254
1255 PdbTypeSymId type_id(proc.FunctionType);
1256 clang::QualType qt = GetOrCreateClangType(type_id);
1257 if (qt.isNull())
1258 return nullptr;
1259
1260 clang::StorageClass storage = clang::SC_None;
1261 if (proc.Kind == SymbolRecordKind::ProcSym)
1262 storage = clang::SC_Static;
1263
1264 const clang::FunctionProtoType *func_type =
1265 llvm::dyn_cast<clang::FunctionProtoType>(qt);
1266 if (!func_type)
1267 return nullptr;
1268
1269 CompilerType func_ct = ToCompilerType(qt);
1270
1271 llvm::StringRef proc_name = proc.Name;
1272 if (!context_name.empty() && !(proc_name.consume_front(context_name) &&
1273 proc_name.consume_front("::"))) {
1274 // If we have some context, but the function name doesn't start with it, use
1275 // the basename.
1276 MSVCUndecoratedNameParser parser(proc.Name);
1277 llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs(parser.GetSpecifiers());
1278 if (!specs.empty())
1279 proc_name = specs.back().GetBaseName();
1280 }
1281 clang::FunctionDecl *function_decl =
1282 CreateFunctionDecl(func_id, proc_name, proc.FunctionType, func_ct,
1283 func_type->getNumParams(), storage, false, parent);
1284 if (function_decl == nullptr)
1285 return nullptr;
1286
1287 assert(m_uid_to_decl.count(toOpaqueUid(func_id)) == 0 && "already created");
1288 m_uid_to_decl[toOpaqueUid(func_id)] = function_decl;
1289 DeclStatus status;
1290 status.resolved = true;
1291 status.uid = toOpaqueUid(func_id);
1292 m_decl_to_status.insert({function_decl, status});
1293
1294 return function_decl;
1295}
1296
1300
1305
1309
1311 PdbCompilandSymId var_id) {
1312 GetOrCreateVariableDecl(scope_id, var_id);
1313}
1314
1318
1320 PdbCompilandSymId func_id, clang::FunctionDecl &function_decl,
1321 uint32_t param_count) {
1323 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1324 PdbIndex &index = pdb->GetIndex();
1325 CompilandIndexItem *cii = index.compilands().GetCompiland(func_id.modi);
1326 CVSymbolArray scope =
1327 cii->m_debug_stream.getSymbolArrayForScope(func_id.offset);
1328
1329 scope.drop_front();
1330 auto begin = scope.begin();
1331 auto end = scope.end();
1332 std::vector<clang::ParmVarDecl *> params;
1333 for (uint32_t i = 0; i < param_count && begin != end;) {
1334 uint32_t record_offset = begin.offset();
1335 PdbCompilandSymId sym_id(func_id.modi, record_offset);
1336 CVSymbol sym = *begin++;
1337
1338 TypeIndex param_type;
1339 llvm::StringRef param_name;
1340 switch (sym.kind()) {
1341 case S_REGREL32: {
1342 RegRelativeSym reg(SymbolRecordKind::RegRelativeSym);
1343 llvm::Error err =
1344 SymbolDeserializer::deserializeAs<RegRelativeSym>(sym, reg);
1345 if (err) {
1346 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1347 "Failed to deserialize {1} as RegRelative: {0}", sym_id);
1348 return;
1349 }
1350 param_type = reg.Type;
1351 param_name = reg.Name;
1352 break;
1353 }
1354 case S_REGREL32_INDIR: {
1355 RegRelativeIndirSym reg(SymbolRecordKind::RegRelativeIndirSym);
1356 llvm::Error err =
1357 SymbolDeserializer::deserializeAs<RegRelativeIndirSym>(sym, reg);
1358 if (err) {
1359 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1360 "Failed to deserialize {1} as RegRelativeIndir: {0}",
1361 sym_id);
1362 return;
1363 }
1364 param_type = reg.Type;
1365 param_name = reg.Name;
1366 break;
1367 }
1368 case S_REGISTER: {
1369 RegisterSym reg(SymbolRecordKind::RegisterSym);
1370 llvm::Error err =
1371 SymbolDeserializer::deserializeAs<RegisterSym>(sym, reg);
1372 if (err) {
1373 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1374 "Failed to deserialize {1} as Register: {0}", sym_id);
1375 return;
1376 }
1377 param_type = reg.Index;
1378 param_name = reg.Name;
1379 break;
1380 }
1381 case S_LOCAL: {
1382 LocalSym local(SymbolRecordKind::LocalSym);
1383 llvm::Error err = SymbolDeserializer::deserializeAs<LocalSym>(sym, local);
1384 if (err) {
1385 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1386 "Failed to deserialize {1} as Local: {0}", sym_id);
1387 return;
1388 }
1389 if ((local.Flags & LocalSymFlags::IsParameter) == LocalSymFlags::None)
1390 continue;
1391 param_type = local.Type;
1392 param_name = local.Name;
1393 break;
1394 }
1395 case S_BLOCK32:
1396 case S_INLINESITE:
1397 case S_INLINESITE2:
1398 // All parameters should come before the first block/inlinesite. If that
1399 // isn't the case, then perhaps this is bad debug info that doesn't
1400 // contain information about all parameters.
1401 return;
1402 default:
1403 continue;
1404 }
1405
1406 PdbCompilandSymId param_uid(func_id.modi, record_offset);
1407 clang::QualType qt = GetOrCreateClangType(param_type);
1408 if (qt.isNull())
1409 return;
1410
1411 CompilerType param_type_ct = m_clang.GetType(qt);
1412 clang::ParmVarDecl *param = m_clang.CreateParameterDeclaration(
1413 &function_decl, OptionalClangModuleID(), param_name.str().c_str(),
1414 param_type_ct, clang::SC_None, true);
1415
1416 assert(m_uid_to_decl.count(toOpaqueUid(param_uid)) == 0 &&
1417 "already created");
1418 m_uid_to_decl[toOpaqueUid(param_uid)] = param;
1419 params.push_back(param);
1420 ++i;
1421 }
1422
1423 if (!params.empty() && params.size() == param_count)
1424 function_decl.setParams(params);
1425}
1426
1428 const EnumRecord &er) {
1429 clang::DeclContext *decl_context = nullptr;
1430 std::string uname;
1431 std::tie(decl_context, uname) = CreateDeclInfoForType(er, id.index);
1432 if (!decl_context)
1433 return {};
1434
1435 clang::QualType underlying_type = GetOrCreateClangType(er.UnderlyingType);
1436 if (underlying_type.isNull())
1437 return {};
1438
1439 Declaration declaration;
1440 CompilerType enum_ct = m_clang.CreateEnumerationType(
1441 uname, decl_context, OptionalClangModuleID(), declaration,
1442 ToCompilerType(underlying_type), er.isScoped());
1443
1446
1447 return clang::QualType::getFromOpaquePtr(enum_ct.GetOpaqueQualType());
1448}
1449
1450clang::QualType PdbAstBuilderClang::CreateArrayType(const ArrayRecord &ar) {
1451 clang::QualType element_type = GetOrCreateClangType(ar.ElementType);
1453
1455 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1456 PdbIndex &index = pdb->GetIndex();
1457 uint64_t element_size = GetSizeOfType({ar.ElementType}, index.tpi());
1458 if (element_type.isNull() || element_size == 0)
1459 return {};
1460 uint64_t element_count = ar.Size / element_size;
1461
1462 CompilerType array_ct = m_clang.CreateArrayType(ToCompilerType(element_type),
1463 element_count, false);
1464 return clang::QualType::getFromOpaquePtr(array_ct.GetOpaqueQualType());
1465}
1466
1468 TypeIndex args_type_idx, TypeIndex return_type_idx,
1469 llvm::codeview::CallingConvention calling_convention,
1470 unsigned int type_quals) {
1472 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1473 PdbIndex &index = pdb->GetIndex();
1474 TpiStream &stream = index.tpi();
1475 CVType args_cvt = stream.getType(args_type_idx);
1476 ArgListRecord args;
1477 llvm::Error err =
1478 TypeDeserializer::deserializeAs<ArgListRecord>(args_cvt, args);
1479 if (err) {
1480 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1481 "Failed to deserialize {1} as ArgList: {0}", args_type_idx);
1482 return {};
1483 }
1484
1485 llvm::ArrayRef<TypeIndex> arg_indices = llvm::ArrayRef(args.ArgIndices);
1486 bool is_variadic = IsCVarArgsFunction(arg_indices);
1487 if (is_variadic)
1488 arg_indices = arg_indices.drop_back();
1489
1490 std::vector<CompilerType> arg_types;
1491 arg_types.reserve(arg_indices.size());
1492
1493 for (TypeIndex arg_index : arg_indices) {
1494 clang::QualType arg_type = GetOrCreateClangType(arg_index);
1495 if (arg_type.isNull())
1496 continue;
1497 arg_types.push_back(ToCompilerType(arg_type));
1498 }
1499
1500 clang::QualType return_type = GetOrCreateClangType(return_type_idx);
1501 if (return_type.isNull())
1502 return {};
1503
1504 std::optional<clang::CallingConv> cc =
1505 TranslateCallingConvention(calling_convention);
1506 if (!cc)
1507 return {};
1508
1509 CompilerType return_ct = ToCompilerType(return_type);
1510 CompilerType func_sig_ast_type = m_clang.CreateFunctionType(
1511 return_ct, arg_types, is_variadic, type_quals, *cc);
1512
1513 return clang::QualType::getFromOpaquePtr(
1514 func_sig_ast_type.GetOpaqueQualType());
1515}
1516
1517static bool isTagDecl(clang::DeclContext &context) {
1518 return llvm::isa<clang::TagDecl>(&context);
1519}
1520
1521static bool isFunctionDecl(clang::DeclContext &context) {
1522 return llvm::isa<clang::FunctionDecl>(&context);
1523}
1524
1525static bool isBlockDecl(clang::DeclContext &context) {
1526 return llvm::isa<clang::BlockDecl>(&context);
1527}
1528
1529void PdbAstBuilderClang::ParseNamespace(clang::DeclContext &context) {
1530 clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(&context);
1531 if (m_parsed_namespaces.contains(ns))
1532 return;
1533 std::string qname = ns->getQualifiedNameAsString();
1535 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1536 PdbIndex &index = pdb->GetIndex();
1537 TypeIndex ti{index.tpi().TypeIndexBegin()};
1538 for (const CVType &cvt : index.tpi().typeArray()) {
1539 PdbTypeSymId tid{ti};
1540 ++ti;
1541
1542 if (!IsTagRecord(cvt))
1543 continue;
1544
1546
1547 // Call CreateDeclInfoForType unconditionally so that the namespace info
1548 // gets created. But only call CreateRecordType if the namespace name
1549 // matches.
1550 clang::DeclContext *context = nullptr;
1551 std::string uname;
1552 std::tie(context, uname) = CreateDeclInfoForType(tag.asTag(), tid.index);
1553 if (!context || !context->isNamespace())
1554 continue;
1555
1556 clang::NamespaceDecl *ns = llvm::cast<clang::NamespaceDecl>(context);
1557 llvm::StringRef ns_name = ns->getName();
1558 if (ns_name.starts_with(qname)) {
1559 ns_name = ns_name.drop_front(qname.size());
1560 if (ns_name.starts_with("::"))
1562 }
1563 }
1565 m_parsed_namespaces.insert(ns);
1566}
1567
1569 llvm::call_once(m_parse_all_types, [this]() {
1571 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1572 PdbIndex &index = pdb->GetIndex();
1573 TypeIndex ti{index.tpi().TypeIndexBegin()};
1574 for (const CVType &cvt : index.tpi().typeArray()) {
1575 PdbTypeSymId tid{ti};
1576 ++ti;
1577
1578 if (!IsTagRecord(cvt))
1579 continue;
1580
1582 }
1583 });
1584}
1585
1587 llvm::call_once(m_parse_functions_and_non_local_vars, [this]() {
1589 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1590 PdbIndex &index = pdb->GetIndex();
1591 uint32_t module_count = index.dbi().modules().getModuleCount();
1592 for (uint16_t modi = 0; modi < module_count; ++modi) {
1594 const CVSymbolArray &symbols = cii.m_debug_stream.getSymbolArray();
1595 auto iter = symbols.begin();
1596 while (iter != symbols.end()) {
1597 PdbCompilandSymId sym_id{modi, iter.offset()};
1598
1599 switch (iter->kind()) {
1600 case S_GPROC32:
1601 case S_LPROC32:
1603 iter = symbols.at(getScopeEndOffset(*iter));
1604 break;
1605 case S_GDATA32:
1606 case S_GTHREAD32:
1607 case S_LDATA32:
1608 case S_LTHREAD32:
1610 ++iter;
1611 break;
1612 default:
1613 ++iter;
1614 continue;
1615 }
1616 }
1617 }
1618 });
1619}
1620
1621static CVSymbolArray skipFunctionParameters(clang::Decl &decl,
1622 const CVSymbolArray &symbols) {
1623 clang::FunctionDecl *func_decl = llvm::dyn_cast<clang::FunctionDecl>(&decl);
1624 if (!func_decl)
1625 return symbols;
1626 unsigned int params = func_decl->getNumParams();
1627 if (params == 0)
1628 return symbols;
1629
1630 CVSymbolArray result = symbols;
1631
1632 while (!result.empty()) {
1633 if (params == 0)
1634 return result;
1635
1636 CVSymbol sym = *result.begin();
1637 result.drop_front();
1638
1639 if (!isLocalVariableType(sym.kind()))
1640 continue;
1641
1642 --params;
1643 }
1644 return result;
1645}
1646
1649 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1650 PdbIndex &index = pdb->GetIndex();
1651 CVSymbol sym = index.ReadSymbolRecord(block_id);
1652 if (sym.kind() != S_GPROC32 && sym.kind() != S_LPROC32 &&
1653 sym.kind() != S_BLOCK32 && sym.kind() != S_INLINESITE) {
1654 assert(false && "called on non-block");
1655 return;
1656 }
1657 CompilandIndexItem &cii =
1658 index.compilands().GetOrCreateCompiland(block_id.modi);
1659 CVSymbolArray symbols =
1660 cii.m_debug_stream.getSymbolArrayForScope(block_id.offset);
1661
1662 // Function parameters should already have been created when the function was
1663 // parsed.
1664 if (sym.kind() == S_GPROC32 || sym.kind() == S_LPROC32)
1665 symbols =
1666 skipFunctionParameters(*m_uid_to_decl[toOpaqueUid(block_id)], symbols);
1667
1668 symbols.drop_front();
1669 auto begin = symbols.begin();
1670 while (begin != symbols.end()) {
1671 PdbCompilandSymId child_sym_id(block_id.modi, begin.offset());
1672 GetOrCreateSymbolForId(child_sym_id);
1673 if (begin->kind() == S_BLOCK32 || begin->kind() == S_INLINESITE) {
1674 ParseBlockChildren(child_sym_id);
1675 begin = symbols.at(getScopeEndOffset(*begin));
1676 }
1677 ++begin;
1678 }
1679}
1680
1682 clang::DeclContext &context) {
1683
1684 clang::Decl *decl = clang::Decl::castFromDeclContext(&context);
1685 if (!decl) {
1686 assert(false);
1687 return;
1688 }
1689
1690 auto iter = m_decl_to_status.find(decl);
1691 if (iter == m_decl_to_status.end()) {
1692 assert(false && "cannot parse unknown decl");
1693 return;
1694 }
1695
1696 if (auto *tag = llvm::dyn_cast<clang::TagDecl>(&context)) {
1697 CompleteTagDecl(*tag);
1698 return;
1699 }
1700
1701 if (isFunctionDecl(context) || isBlockDecl(context)) {
1702 PdbCompilandSymId block_id = PdbSymUid(iter->second.uid).asCompilandSym();
1703 ParseBlockChildren(block_id);
1704 }
1705}
1706
1708 clang::DeclContext *dc = FromCompilerDeclContext(context);
1709 if (!dc)
1710 return;
1711
1712 // Namespaces aren't explicitly represented in the debug info, and the only
1713 // way to parse them is to parse all type info, demangling every single type
1714 // and trying to reconstruct the DeclContext hierarchy this way. Since this
1715 // is an expensive operation, we have to special case it so that we do other
1716 // work (such as parsing the items that appear within the namespaces) at the
1717 // same time.
1718 if (dc->isTranslationUnit()) {
1719 ParseAllTypes();
1721 return;
1722 }
1723
1724 if (dc->isNamespace()) {
1725 ParseNamespace(*dc);
1726 return;
1727 }
1728
1729 if (isTagDecl(*dc) || isFunctionDecl(*dc) || isBlockDecl(*dc)) {
1731 return;
1732 }
1733}
1734
1736 return m_clang.GetCompilerDecl(decl);
1737}
1738
1740 return m_clang.GetType(qt);
1741}
1742
1746
1748PdbAstBuilderClang::ToCompilerDeclContext(clang::DeclContext *context) {
1749 if (!context)
1750 return CompilerDeclContext();
1751 return m_clang.CreateDeclContext(context);
1752}
1753
1755 if (decl.GetTypeSystem() != nullptr)
1756 return ClangUtil::GetDecl(decl);
1757 return nullptr;
1758}
1759
1760clang::DeclContext *
1762 return static_cast<clang::DeclContext *>(context.GetOpaqueDeclContext());
1763}
1764
1765std::string PdbAstBuilderClang::GetQualifiedName(llvm::StringRef name) {
1766 std::string result;
1767 while (!name.empty()) {
1768 size_t pos = name.find('`');
1769 result += name.take_front(pos);
1770 if (pos == llvm::StringRef::npos)
1771 break;
1772 name = name.drop_front(pos);
1773 if (name.consume_front("`anonymous namespace'") ||
1774 name.consume_front("`anonymous-namespace'")) {
1775 result += "(anonymous namespace)";
1776 } else {
1777 result += name.front();
1778 name = name.drop_front();
1779 }
1780 }
1781 return result;
1782}
1783
1784void PdbAstBuilderClang::Dump(Stream &stream, llvm::StringRef filter,
1785 bool show_color) {
1786 m_clang.Dump(stream.AsRawOstream(), filter, show_color);
1787}
1788
1791 llvm::StringRef name) {
1792 clang::DeclContext *parent = FromCompilerDeclContext(parent_ctx);
1793 NamespaceSet *set;
1794
1795 if (parent) {
1796 auto it = m_parent_to_namespaces.find(parent);
1797 if (it == m_parent_to_namespaces.end())
1798 return {};
1799
1800 set = &it->second;
1801 } else {
1802 // In this case, search through all known namespaces
1803 set = &m_known_namespaces;
1804 }
1805 assert(set);
1806
1807 for (clang::NamespaceDecl *namespace_decl : *set)
1808 if (namespace_decl->getName() == name)
1809 return ToCompilerDeclContext(namespace_decl);
1810
1811 for (clang::NamespaceDecl *namespace_decl : *set)
1812 if (namespace_decl->isAnonymousNamespace())
1813 return FindNamespaceDecl(ToCompilerDeclContext(namespace_decl), name);
1814
1815 return {};
1816}
1817
1819 // Unions or enums can't be dynamic.
1821 return false;
1822
1823 // If a class has a vtable, it is dynamic.
1824 if (!tag.asClass().getVTableShape().isNoneType())
1825 return true;
1826
1827 // Otherwise, check if there are any (possibly indirect) virtual bases on the
1828 // type.
1830 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1831 PdbIndex &index = pdb->GetIndex();
1832
1833 std::optional<CVType> cvt = index.tpi().tryGetType(tag.asTag().FieldList);
1834 if (!cvt)
1835 return false;
1836
1837 FieldListRecord fl;
1838 if (llvm::Error ec =
1839 TypeDeserializer::deserializeAs<FieldListRecord>(*cvt, fl)) {
1840 llvm::consumeError(std::move(ec));
1841 return false;
1842 }
1843
1844 struct Visitor : public TypeVisitorCallbacks {
1845 llvm::Error visitKnownMember(CVMemberRecord &CVM,
1846 VirtualBaseClassRecord &Record) override {
1847 m_has_vbase = true;
1848 return llvm::Error::success();
1849 }
1850
1851 bool m_has_vbase = false;
1852 };
1853
1854 Visitor visitor;
1855 llvm::Error ec = llvm::codeview::visitMemberRecordStream(fl.Data, visitor);
1856 if (ec)
1857 llvm::consumeError(std::move(ec));
1858
1859 return visitor.m_has_vbase;
1860}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:375
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:405
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)
void SetUserID(lldb::user_id_t user_id)
void SetIsDynamicCXXType(std::optional< bool > b)
Represents a generic declaration context in a program.
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.
Definition ConstString.h:40
A class that describes the declaration location of a lldb object.
Definition Declaration.h:24
A stream class that can stream formatted output to a file.
Definition Stream.h:28
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition Stream.h:405
A TypeSystem implementation based on Clang.
static bool CompleteTagDeclarationDefinition(const CompilerType &type)
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)
clang::QualType CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx, llvm::codeview::CallingConvention calling_convention, unsigned int type_quals)
clang::DeclContext * GetOrCreateDeclContextForCompilandSymbol(PdbCompilandSymId uid)
clang::QualType CreateModifierType(const llvm::codeview::ModifierRecord &modifier)
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)
clang::QualType CreateRecordType(PdbTypeSymId id, const CVTagRecord &record)
void EnsureVariable(PdbCompilandSymId scope_id, PdbCompilandSymId var_id) override
clang::VarDecl * CreateVariableDecl(PdbSymUid uid, llvm::codeview::CVSymbol sym, clang::DeclContext &scope)
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
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
CompilerDeclContext GetParentDeclContext(PdbSymUid uid) override
clang::DeclContext * FromCompilerDeclContext(CompilerDeclContext context)
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)
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.
Definition PdbIndex.h:47
llvm::pdb::TpiStream & ipi()
Definition PdbIndex.h:127
CompileUnitIndex & compilands()
Definition PdbIndex.h:142
llvm::pdb::DbiStream & dbi()
Definition PdbIndex.h:121
llvm::codeview::CVSymbol ReadSymbolRecord(PdbCompilandSymId cu_sym) const
Definition PdbIndex.cpp:185
llvm::pdb::TpiStream & tpi()
Definition PdbIndex.h:124
PdbGlobalSymId asGlobalSym() const
PdbCompilandSymId asCompilandSym() const
PdbTypeSymId asTypeSym() const
PdbSymUidKind kind() const
std::optional< PdbTypeSymId > GetFunctionType(llvm::codeview::CVSymbol symbol)
Definition PdbUtil.cpp:1204
llvm::StringRef DropNameScope(llvm::StringRef name)
Definition PdbUtil.cpp:602
uint64_t toOpaqueUid(const T &cid)
Definition PdbSymUid.h:111
lldb::BasicType GetCompilerTypeForSimpleKind(llvm::codeview::SimpleTypeKind kind)
VariableInfo GetVariableNameInfo(llvm::codeview::CVSymbol symbol)
bool IsTagRecord(llvm::codeview::CVType cvt)
Definition PdbUtil.cpp:517
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)
Definition PdbUtil.cpp:1150
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.
Definition Log.h:338
void * opaque_compiler_type_t
Definition lldb-types.h:91
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
@ eLanguageTypeC_plus_plus
ISO C++:1998.
uint64_t user_id_t
Definition lldb-types.h:83
static clang::QualType GetQualType(const CompilerType &ct)
Definition ClangUtil.cpp:36
static clang::Decl * GetDecl(const CompilerDecl &decl)
Returns the clang::Decl of the given CompilerDecl.
Definition ClangUtil.cpp:31
CompilerContextKind contextKind() const
Definition PdbUtil.h:75
static CVTagRecord create(llvm::codeview::CVType type)
Definition PdbUtil.cpp:197
const llvm::codeview::ClassRecord & asClass() const
Definition PdbUtil.h:52
const llvm::codeview::EnumRecord & asEnum() const
Definition PdbUtil.h:57
const llvm::codeview::TagRecord & asTag() const
Definition PdbUtil.h:44
Represents a single compile unit.
llvm::pdb::ModuleDebugStreamRef m_debug_stream
llvm::codeview::TypeIndex index
Definition PdbSymUid.h:73
llvm::codeview::TypeIndex type
Definition PdbUtil.h:114