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 return qt;
993}
994
996 clang::QualType qt = GetOrCreateClangType(type);
997 if (qt.isNull())
998 return {};
999 return ToCompilerType(qt);
1000}
1001
1003 lldb::opaque_compiler_type_t parent_ty, llvm::StringRef name,
1004 llvm::StringRef asm_label, const CompilerType &method_ct, bool is_virtual,
1005 bool is_static, bool is_artificial) {
1006 clang::CXXMethodDecl *&method_decl = m_cxx_method_decls[{
1007 parent_ty, ConstString(name), method_ct.GetOpaqueQualType()}];
1008 if (!method_decl)
1009 method_decl = m_clang.AddMethodToCXXRecordType(
1010 parent_ty, name, asm_label, method_ct, is_virtual, is_static,
1011 /*is_inline=*/false, /*is_explicit=*/false,
1012 /*is_attr_used=*/false, is_artificial);
1013 return method_decl;
1014}
1015
1017 PdbCompilandSymId func_id, llvm::StringRef func_name, TypeIndex func_ti,
1018 CompilerType func_ct, uint32_t param_count,
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());
1025 PdbIndex &index = pdb->GetIndex();
1026 clang::CanQualType parent_qt =
1027 m_clang.getASTContext().getCanonicalTypeDeclType(
1028 llvm::cast<clang::TypeDecl>(parent));
1029 lldb::opaque_compiler_type_t parent_opaque_ty =
1030 ToCompilerType(parent_qt).GetOpaqueQualType();
1031 // The method may already have been added while completing the class.
1032 auto iter =
1033 m_cxx_method_decls.find({parent_opaque_ty, ConstString(func_name),
1034 func_ct.GetOpaqueQualType()});
1035 if (iter != m_cxx_method_decls.end())
1036 return iter->second;
1037
1038 CVType cvt = index.tpi().getType(func_ti);
1039 MemberFunctionRecord func_record(static_cast<TypeRecordKind>(cvt.kind()));
1040 llvm::Error err =
1041 TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, func_record);
1042 if (err) {
1043 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1044 "Failed to deserialize {1} as MemberFunction: {0}",
1045 func_ti);
1046 return nullptr;
1047 }
1048 TypeIndex class_index = func_record.getClassType();
1049
1050 CVType parent_cvt = index.tpi().getType(class_index);
1051 if (!IsTagRecord(parent_cvt))
1052 return nullptr;
1053 TagRecord tag_record = CVTagRecord::create(parent_cvt).asTag();
1054 // If it's a forward reference, try to get the real TypeIndex.
1055 if (tag_record.isForwardRef()) {
1056 llvm::Expected<TypeIndex> eti =
1057 index.tpi().findFullDeclForForwardRef(class_index);
1058 if (eti) {
1059 CVType resolved_tag_record = index.tpi().getType(*eti);
1060 if (!IsTagRecord(resolved_tag_record))
1061 return nullptr;
1062 tag_record = CVTagRecord::create(resolved_tag_record).asTag();
1063 } else {
1064 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), eti.takeError(),
1065 "failed to find full decl for forward ref: {0}");
1066 }
1067 }
1068
1069 std::string asm_label = pdb->GetFunctionCallLabel(func_id);
1070
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));
1081 }
1082
1083 if (!function_decl)
1084 function_decl = GetOrCreateMethodDecl(
1085 parent_opaque_ty, func_name, asm_label, func_ct,
1086 /*is_virtual=*/false, /*is_static=*/false, /*is_artificial=*/false);
1087 } else {
1089 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1090 function_decl = m_clang.CreateFunctionDeclaration(
1091 parent, OptionalClangModuleID(), func_name, func_ct, func_storage,
1092 is_inline, pdb->GetFunctionCallLabel(func_id));
1093 CreateFunctionParameters(func_id, *function_decl, param_count);
1094 }
1095 return function_decl;
1096}
1097
1099 PdbCompilandSymId inlinesite_id) {
1101 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1102 PdbIndex &index = pdb->GetIndex();
1103 CompilandIndexItem *cii = index.compilands().GetCompiland(inlinesite_id.modi);
1104 CVSymbol sym = cii->m_debug_stream.readSymbolAtOffset(inlinesite_id.offset);
1105 InlineSiteSym inline_site(static_cast<SymbolRecordKind>(sym.kind()));
1106 llvm::Error err =
1107 SymbolDeserializer::deserializeAs<InlineSiteSym>(sym, inline_site);
1108 if (err) {
1109 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1110 "Failed to deserialize {1} as InlineSite: {0}",
1111 inlinesite_id);
1112 return nullptr;
1113 }
1114
1115 // Inlinee is the id index to the function id record that is inlined.
1116 PdbTypeSymId func_id(inline_site.Inlinee, true);
1117 // Look up the function decl by the id index to see if we have created a
1118 // function decl for a different inlinesite that refers the same function.
1119 if (clang::Decl *decl = TryGetDecl(func_id))
1120 return llvm::dyn_cast<clang::FunctionDecl>(decl);
1121 clang::FunctionDecl *function_decl =
1122 CreateFunctionDeclFromId(func_id, inlinesite_id);
1123 if (function_decl == nullptr)
1124 return nullptr;
1125
1126 // Use inline site id in m_decl_to_status because it's expected to be a
1127 // PdbCompilandSymId so that we can parse local variables info after it.
1128 uint64_t inlinesite_uid = toOpaqueUid(inlinesite_id);
1129 DeclStatus status;
1130 status.resolved = true;
1131 status.uid = inlinesite_uid;
1132 m_decl_to_status.insert({function_decl, status});
1133 // Use the index in IPI stream as uid in m_uid_to_decl, because index in IPI
1134 // stream are unique and there could be multiple inline sites (different ids)
1135 // referring the same inline function. This avoid creating multiple same
1136 // inline function delcs.
1137 uint64_t func_uid = toOpaqueUid(func_id);
1138 assert(m_uid_to_decl.count(func_uid) == 0 && "already created");
1139 m_uid_to_decl[func_uid] = function_decl;
1140 return function_decl;
1141}
1142
1143clang::FunctionDecl *
1145 PdbCompilandSymId func_sid) {
1146 if (!func_tid.is_ipi) {
1147 assert(false && "called with non-ipi index");
1148 return nullptr;
1149 }
1150
1152 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1153 PdbIndex &index = pdb->GetIndex();
1154 std::optional<CVType> func_cvt =
1155 index.ipi().typeCollection().tryGetType(func_tid.index);
1156 if (!func_cvt)
1157 return nullptr;
1158 llvm::StringRef func_name;
1159 TypeIndex func_ti;
1160 clang::DeclContext *parent = nullptr;
1161 switch (func_cvt->kind()) {
1162 case LF_MFUNC_ID: {
1163 MemberFuncIdRecord mfr;
1164 llvm::Error err =
1165 TypeDeserializer::deserializeAs<MemberFuncIdRecord>(*func_cvt, mfr);
1166 if (err) {
1167 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1168 "Failed to deserialize {1} (IPI) as MemberFuncId: {0}",
1169 func_tid.index);
1170 return nullptr;
1171 }
1172 func_name = mfr.getName();
1173 func_ti = mfr.getFunctionType();
1174 PdbTypeSymId class_type_id(mfr.ClassType, false);
1175 parent = GetOrCreateClangDeclContextForUid(class_type_id);
1176 break;
1177 }
1178 case LF_FUNC_ID: {
1179 FuncIdRecord fir;
1180 llvm::Error err =
1181 TypeDeserializer::deserializeAs<FuncIdRecord>(*func_cvt, fir);
1182 if (err) {
1183 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1184 "Failed to deserialize {1} (IPI) as FuncId: {0}",
1185 func_tid.index);
1186 return nullptr;
1187 }
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) {
1194 StringIdRecord sir;
1195 err = TypeDeserializer::deserializeAs<StringIdRecord>(parent_cvt, sir);
1196 if (err) {
1197 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1198 "Failed to deserialize {1} (IPI) as StringId: {0}",
1199 fir.ParentScope);
1200 return nullptr;
1201 }
1202 parent = GetOrCreateNamespaceDecl(sir.String.data(), *parent);
1203 }
1204 }
1205 break;
1206 }
1207 default:
1208 LLDB_LOG(GetLog(LLDBLog::Symbols), "{0} is not a function type", func_tid);
1209 return nullptr;
1210 }
1211 clang::QualType func_qt = GetOrCreateClangType(func_ti);
1212 if (func_qt.isNull() || !parent)
1213 return nullptr;
1214 CompilerType func_ct = ToCompilerType(func_qt);
1215 uint32_t param_count =
1216 llvm::cast<clang::FunctionProtoType>(func_qt)->getNumParams();
1217 return CreateFunctionDecl(func_sid, func_name, func_ti, func_ct, param_count,
1218 clang::SC_None, true, parent);
1219}
1220
1221clang::FunctionDecl *
1223 if (clang::Decl *decl = TryGetDecl(func_id))
1224 return llvm::dyn_cast<clang::FunctionDecl>(decl);
1225
1226 clang::DeclContext *parent = GetParentClangDeclContext(PdbSymUid(func_id));
1227 if (!parent)
1228 return nullptr;
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();
1234 }
1235
1237 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1238 PdbIndex &index = pdb->GetIndex();
1239 CVSymbol cvs = index.ReadSymbolRecord(func_id);
1240 ProcSym proc(static_cast<SymbolRecordKind>(cvs.kind()));
1241 llvm::Error err = SymbolDeserializer::deserializeAs<ProcSym>(cvs, proc);
1242 if (err) {
1243 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1244 "Failed to deserialize {1} as Proc: {0}", func_id);
1245 return nullptr;
1246 }
1247
1248 PdbTypeSymId type_id(proc.FunctionType);
1249 clang::QualType qt = GetOrCreateClangType(type_id);
1250 if (qt.isNull())
1251 return nullptr;
1252
1253 clang::StorageClass storage = clang::SC_None;
1254 if (proc.Kind == SymbolRecordKind::ProcSym)
1255 storage = clang::SC_Static;
1256
1257 const clang::FunctionProtoType *func_type =
1258 llvm::dyn_cast<clang::FunctionProtoType>(qt);
1259 if (!func_type)
1260 return nullptr;
1261
1262 CompilerType func_ct = ToCompilerType(qt);
1263
1264 llvm::StringRef proc_name = proc.Name;
1265 if (!context_name.empty() && !(proc_name.consume_front(context_name) &&
1266 proc_name.consume_front("::"))) {
1267 // If we have some context, but the function name doesn't start with it, use
1268 // the basename.
1269 MSVCUndecoratedNameParser parser(proc.Name);
1270 llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs(parser.GetSpecifiers());
1271 if (!specs.empty())
1272 proc_name = specs.back().GetBaseName();
1273 }
1274 clang::FunctionDecl *function_decl =
1275 CreateFunctionDecl(func_id, proc_name, proc.FunctionType, func_ct,
1276 func_type->getNumParams(), storage, false, parent);
1277 if (function_decl == nullptr)
1278 return nullptr;
1279
1280 assert(m_uid_to_decl.count(toOpaqueUid(func_id)) == 0 && "already created");
1281 m_uid_to_decl[toOpaqueUid(func_id)] = function_decl;
1282 DeclStatus status;
1283 status.resolved = true;
1284 status.uid = toOpaqueUid(func_id);
1285 m_decl_to_status.insert({function_decl, status});
1286
1287 return function_decl;
1288}
1289
1293
1298
1302
1304 PdbCompilandSymId var_id) {
1305 GetOrCreateVariableDecl(scope_id, var_id);
1306}
1307
1311
1313 PdbCompilandSymId func_id, clang::FunctionDecl &function_decl,
1314 uint32_t param_count) {
1316 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1317 PdbIndex &index = pdb->GetIndex();
1318 CompilandIndexItem *cii = index.compilands().GetCompiland(func_id.modi);
1319 CVSymbolArray scope =
1320 cii->m_debug_stream.getSymbolArrayForScope(func_id.offset);
1321
1322 scope.drop_front();
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();
1328 PdbCompilandSymId sym_id(func_id.modi, record_offset);
1329 CVSymbol sym = *begin++;
1330
1331 TypeIndex param_type;
1332 llvm::StringRef param_name;
1333 switch (sym.kind()) {
1334 case S_REGREL32: {
1335 RegRelativeSym reg(SymbolRecordKind::RegRelativeSym);
1336 llvm::Error err =
1337 SymbolDeserializer::deserializeAs<RegRelativeSym>(sym, reg);
1338 if (err) {
1339 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1340 "Failed to deserialize {1} as RegRelative: {0}", sym_id);
1341 return;
1342 }
1343 param_type = reg.Type;
1344 param_name = reg.Name;
1345 break;
1346 }
1347 case S_REGREL32_INDIR: {
1348 RegRelativeIndirSym reg(SymbolRecordKind::RegRelativeIndirSym);
1349 llvm::Error err =
1350 SymbolDeserializer::deserializeAs<RegRelativeIndirSym>(sym, reg);
1351 if (err) {
1352 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1353 "Failed to deserialize {1} as RegRelativeIndir: {0}",
1354 sym_id);
1355 return;
1356 }
1357 param_type = reg.Type;
1358 param_name = reg.Name;
1359 break;
1360 }
1361 case S_REGISTER: {
1362 RegisterSym reg(SymbolRecordKind::RegisterSym);
1363 llvm::Error err =
1364 SymbolDeserializer::deserializeAs<RegisterSym>(sym, reg);
1365 if (err) {
1366 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1367 "Failed to deserialize {1} as Register: {0}", sym_id);
1368 return;
1369 }
1370 param_type = reg.Index;
1371 param_name = reg.Name;
1372 break;
1373 }
1374 case S_LOCAL: {
1375 LocalSym local(SymbolRecordKind::LocalSym);
1376 llvm::Error err = SymbolDeserializer::deserializeAs<LocalSym>(sym, local);
1377 if (err) {
1378 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1379 "Failed to deserialize {1} as Local: {0}", sym_id);
1380 return;
1381 }
1382 if ((local.Flags & LocalSymFlags::IsParameter) == LocalSymFlags::None)
1383 continue;
1384 param_type = local.Type;
1385 param_name = local.Name;
1386 break;
1387 }
1388 case S_BLOCK32:
1389 case S_INLINESITE:
1390 case S_INLINESITE2:
1391 // All parameters should come before the first block/inlinesite. If that
1392 // isn't the case, then perhaps this is bad debug info that doesn't
1393 // contain information about all parameters.
1394 return;
1395 default:
1396 continue;
1397 }
1398
1399 PdbCompilandSymId param_uid(func_id.modi, record_offset);
1400 clang::QualType qt = GetOrCreateClangType(param_type);
1401 if (qt.isNull())
1402 return;
1403
1404 CompilerType param_type_ct = m_clang.GetType(qt);
1405 clang::ParmVarDecl *param = m_clang.CreateParameterDeclaration(
1406 &function_decl, OptionalClangModuleID(), param_name.str().c_str(),
1407 param_type_ct, clang::SC_None, true);
1408
1409 assert(m_uid_to_decl.count(toOpaqueUid(param_uid)) == 0 &&
1410 "already created");
1411 m_uid_to_decl[toOpaqueUid(param_uid)] = param;
1412 params.push_back(param);
1413 ++i;
1414 }
1415
1416 if (!params.empty() && params.size() == param_count)
1417 function_decl.setParams(params);
1418}
1419
1421 const EnumRecord &er) {
1422 clang::DeclContext *decl_context = nullptr;
1423 std::string uname;
1424 std::tie(decl_context, uname) = CreateDeclInfoForType(er, id.index);
1425 if (!decl_context)
1426 return {};
1427
1428 clang::QualType underlying_type = GetOrCreateClangType(er.UnderlyingType);
1429 if (underlying_type.isNull())
1430 return {};
1431
1432 Declaration declaration;
1433 CompilerType enum_ct = m_clang.CreateEnumerationType(
1434 uname, decl_context, OptionalClangModuleID(), declaration,
1435 ToCompilerType(underlying_type), er.isScoped());
1436
1439
1440 return clang::QualType::getFromOpaquePtr(enum_ct.GetOpaqueQualType());
1441}
1442
1443clang::QualType PdbAstBuilderClang::CreateArrayType(const ArrayRecord &ar) {
1444 clang::QualType element_type = GetOrCreateClangType(ar.ElementType);
1446
1448 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1449 PdbIndex &index = pdb->GetIndex();
1450 uint64_t element_size = GetSizeOfType({ar.ElementType}, index.tpi());
1451 if (element_type.isNull() || element_size == 0)
1452 return {};
1453 uint64_t element_count = ar.Size / element_size;
1454
1455 CompilerType array_ct = m_clang.CreateArrayType(ToCompilerType(element_type),
1456 element_count, false);
1457 return clang::QualType::getFromOpaquePtr(array_ct.GetOpaqueQualType());
1458}
1459
1461 TypeIndex args_type_idx, TypeIndex return_type_idx,
1462 llvm::codeview::CallingConvention calling_convention,
1463 unsigned int type_quals) {
1465 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1466 PdbIndex &index = pdb->GetIndex();
1467 TpiStream &stream = index.tpi();
1468 CVType args_cvt = stream.getType(args_type_idx);
1469 ArgListRecord args;
1470 llvm::Error err =
1471 TypeDeserializer::deserializeAs<ArgListRecord>(args_cvt, args);
1472 if (err) {
1473 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1474 "Failed to deserialize {1} as ArgList: {0}", args_type_idx);
1475 return {};
1476 }
1477
1478 llvm::ArrayRef<TypeIndex> arg_indices = llvm::ArrayRef(args.ArgIndices);
1479 bool is_variadic = IsCVarArgsFunction(arg_indices);
1480 if (is_variadic)
1481 arg_indices = arg_indices.drop_back();
1482
1483 std::vector<CompilerType> arg_types;
1484 arg_types.reserve(arg_indices.size());
1485
1486 for (TypeIndex arg_index : arg_indices) {
1487 clang::QualType arg_type = GetOrCreateClangType(arg_index);
1488 if (arg_type.isNull())
1489 continue;
1490 arg_types.push_back(ToCompilerType(arg_type));
1491 }
1492
1493 clang::QualType return_type = GetOrCreateClangType(return_type_idx);
1494 if (return_type.isNull())
1495 return {};
1496
1497 std::optional<clang::CallingConv> cc =
1498 TranslateCallingConvention(calling_convention);
1499 if (!cc)
1500 return {};
1501
1502 CompilerType return_ct = ToCompilerType(return_type);
1503 CompilerType func_sig_ast_type = m_clang.CreateFunctionType(
1504 return_ct, arg_types, is_variadic, type_quals, *cc);
1505
1506 return clang::QualType::getFromOpaquePtr(
1507 func_sig_ast_type.GetOpaqueQualType());
1508}
1509
1510static bool isTagDecl(clang::DeclContext &context) {
1511 return llvm::isa<clang::TagDecl>(&context);
1512}
1513
1514static bool isFunctionDecl(clang::DeclContext &context) {
1515 return llvm::isa<clang::FunctionDecl>(&context);
1516}
1517
1518static bool isBlockDecl(clang::DeclContext &context) {
1519 return llvm::isa<clang::BlockDecl>(&context);
1520}
1521
1522void PdbAstBuilderClang::ParseNamespace(clang::DeclContext &context) {
1523 clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(&context);
1524 if (m_parsed_namespaces.contains(ns))
1525 return;
1526 std::string qname = ns->getQualifiedNameAsString();
1528 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1529 PdbIndex &index = pdb->GetIndex();
1530 TypeIndex ti{index.tpi().TypeIndexBegin()};
1531 for (const CVType &cvt : index.tpi().typeArray()) {
1532 PdbTypeSymId tid{ti};
1533 ++ti;
1534
1535 if (!IsTagRecord(cvt))
1536 continue;
1537
1539
1540 // Call CreateDeclInfoForType unconditionally so that the namespace info
1541 // gets created. But only call CreateRecordType if the namespace name
1542 // matches.
1543 clang::DeclContext *context = nullptr;
1544 std::string uname;
1545 std::tie(context, uname) = CreateDeclInfoForType(tag.asTag(), tid.index);
1546 if (!context || !context->isNamespace())
1547 continue;
1548
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("::"))
1555 }
1556 }
1558 m_parsed_namespaces.insert(ns);
1559}
1560
1562 llvm::call_once(m_parse_all_types, [this]() {
1564 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1565 PdbIndex &index = pdb->GetIndex();
1566 TypeIndex ti{index.tpi().TypeIndexBegin()};
1567 for (const CVType &cvt : index.tpi().typeArray()) {
1568 PdbTypeSymId tid{ti};
1569 ++ti;
1570
1571 if (!IsTagRecord(cvt))
1572 continue;
1573
1575 }
1576 });
1577}
1578
1580 llvm::call_once(m_parse_functions_and_non_local_vars, [this]() {
1582 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1583 PdbIndex &index = pdb->GetIndex();
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()) {
1590 PdbCompilandSymId sym_id{modi, iter.offset()};
1591
1592 switch (iter->kind()) {
1593 case S_GPROC32:
1594 case S_LPROC32:
1596 iter = symbols.at(getScopeEndOffset(*iter));
1597 break;
1598 case S_GDATA32:
1599 case S_GTHREAD32:
1600 case S_LDATA32:
1601 case S_LTHREAD32:
1603 ++iter;
1604 break;
1605 default:
1606 ++iter;
1607 continue;
1608 }
1609 }
1610 }
1611 });
1612}
1613
1614static CVSymbolArray skipFunctionParameters(clang::Decl &decl,
1615 const CVSymbolArray &symbols) {
1616 clang::FunctionDecl *func_decl = llvm::dyn_cast<clang::FunctionDecl>(&decl);
1617 if (!func_decl)
1618 return symbols;
1619 unsigned int params = func_decl->getNumParams();
1620 if (params == 0)
1621 return symbols;
1622
1623 CVSymbolArray result = symbols;
1624
1625 while (!result.empty()) {
1626 if (params == 0)
1627 return result;
1628
1629 CVSymbol sym = *result.begin();
1630 result.drop_front();
1631
1632 if (!isLocalVariableType(sym.kind()))
1633 continue;
1634
1635 --params;
1636 }
1637 return result;
1638}
1639
1642 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1643 PdbIndex &index = pdb->GetIndex();
1644 CVSymbol sym = index.ReadSymbolRecord(block_id);
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");
1648 return;
1649 }
1650 CompilandIndexItem &cii =
1651 index.compilands().GetOrCreateCompiland(block_id.modi);
1652 CVSymbolArray symbols =
1653 cii.m_debug_stream.getSymbolArrayForScope(block_id.offset);
1654
1655 // Function parameters should already have been created when the function was
1656 // parsed.
1657 if (sym.kind() == S_GPROC32 || sym.kind() == S_LPROC32)
1658 symbols =
1659 skipFunctionParameters(*m_uid_to_decl[toOpaqueUid(block_id)], symbols);
1660
1661 symbols.drop_front();
1662 auto begin = symbols.begin();
1663 while (begin != symbols.end()) {
1664 PdbCompilandSymId child_sym_id(block_id.modi, begin.offset());
1665 GetOrCreateSymbolForId(child_sym_id);
1666 if (begin->kind() == S_BLOCK32 || begin->kind() == S_INLINESITE) {
1667 ParseBlockChildren(child_sym_id);
1668 begin = symbols.at(getScopeEndOffset(*begin));
1669 }
1670 ++begin;
1671 }
1672}
1673
1675 clang::DeclContext &context) {
1676
1677 clang::Decl *decl = clang::Decl::castFromDeclContext(&context);
1678 if (!decl) {
1679 assert(false);
1680 return;
1681 }
1682
1683 auto iter = m_decl_to_status.find(decl);
1684 if (iter == m_decl_to_status.end()) {
1685 assert(false && "cannot parse unknown decl");
1686 return;
1687 }
1688
1689 if (auto *tag = llvm::dyn_cast<clang::TagDecl>(&context)) {
1690 CompleteTagDecl(*tag);
1691 return;
1692 }
1693
1694 if (isFunctionDecl(context) || isBlockDecl(context)) {
1695 PdbCompilandSymId block_id = PdbSymUid(iter->second.uid).asCompilandSym();
1696 ParseBlockChildren(block_id);
1697 }
1698}
1699
1701 clang::DeclContext *dc = FromCompilerDeclContext(context);
1702 if (!dc)
1703 return;
1704
1705 // Namespaces aren't explicitly represented in the debug info, and the only
1706 // way to parse them is to parse all type info, demangling every single type
1707 // and trying to reconstruct the DeclContext hierarchy this way. Since this
1708 // is an expensive operation, we have to special case it so that we do other
1709 // work (such as parsing the items that appear within the namespaces) at the
1710 // same time.
1711 if (dc->isTranslationUnit()) {
1712 ParseAllTypes();
1714 return;
1715 }
1716
1717 if (dc->isNamespace()) {
1718 ParseNamespace(*dc);
1719 return;
1720 }
1721
1722 if (isTagDecl(*dc) || isFunctionDecl(*dc) || isBlockDecl(*dc)) {
1724 return;
1725 }
1726}
1727
1729 return m_clang.GetCompilerDecl(decl);
1730}
1731
1733 return m_clang.GetType(qt);
1734}
1735
1739
1741PdbAstBuilderClang::ToCompilerDeclContext(clang::DeclContext *context) {
1742 if (!context)
1743 return CompilerDeclContext();
1744 return m_clang.CreateDeclContext(context);
1745}
1746
1748 if (decl.GetTypeSystem() != nullptr)
1749 return ClangUtil::GetDecl(decl);
1750 return nullptr;
1751}
1752
1753clang::DeclContext *
1755 return static_cast<clang::DeclContext *>(context.GetOpaqueDeclContext());
1756}
1757
1758std::string PdbAstBuilderClang::GetQualifiedName(llvm::StringRef name) {
1759 std::string result;
1760 while (!name.empty()) {
1761 size_t pos = name.find('`');
1762 result += name.take_front(pos);
1763 if (pos == llvm::StringRef::npos)
1764 break;
1765 name = name.drop_front(pos);
1766 if (name.consume_front("`anonymous namespace'") ||
1767 name.consume_front("`anonymous-namespace'")) {
1768 result += "(anonymous namespace)";
1769 } else {
1770 result += name.front();
1771 name = name.drop_front();
1772 }
1773 }
1774 return result;
1775}
1776
1777void PdbAstBuilderClang::Dump(Stream &stream, llvm::StringRef filter,
1778 bool show_color) {
1779 m_clang.Dump(stream.AsRawOstream(), filter, show_color);
1780}
1781
1784 llvm::StringRef name) {
1785 clang::DeclContext *parent = FromCompilerDeclContext(parent_ctx);
1786 NamespaceSet *set;
1787
1788 if (parent) {
1789 auto it = m_parent_to_namespaces.find(parent);
1790 if (it == m_parent_to_namespaces.end())
1791 return {};
1792
1793 set = &it->second;
1794 } else {
1795 // In this case, search through all known namespaces
1796 set = &m_known_namespaces;
1797 }
1798 assert(set);
1799
1800 for (clang::NamespaceDecl *namespace_decl : *set)
1801 if (namespace_decl->getName() == name)
1802 return ToCompilerDeclContext(namespace_decl);
1803
1804 for (clang::NamespaceDecl *namespace_decl : *set)
1805 if (namespace_decl->isAnonymousNamespace())
1806 return FindNamespaceDecl(ToCompilerDeclContext(namespace_decl), name);
1807
1808 return {};
1809}
1810
1812 // Unions or enums can't be dynamic.
1814 return false;
1815
1816 // If a class has a vtable, it is dynamic.
1817 if (!tag.asClass().getVTableShape().isNoneType())
1818 return true;
1819
1820 // Otherwise, check if there are any (possibly indirect) virtual bases on the
1821 // type.
1823 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1824 PdbIndex &index = pdb->GetIndex();
1825
1826 std::optional<CVType> cvt = index.tpi().tryGetType(tag.asTag().FieldList);
1827 if (!cvt)
1828 return false;
1829
1830 FieldListRecord fl;
1831 if (llvm::Error ec =
1832 TypeDeserializer::deserializeAs<FieldListRecord>(*cvt, fl)) {
1833 llvm::consumeError(std::move(ec));
1834 return false;
1835 }
1836
1837 struct Visitor : public TypeVisitorCallbacks {
1838 llvm::Error visitKnownMember(CVMemberRecord &CVM,
1839 VirtualBaseClassRecord &Record) override {
1840 m_has_vbase = true;
1841 return llvm::Error::success();
1842 }
1843
1844 bool m_has_vbase = false;
1845 };
1846
1847 Visitor visitor;
1848 llvm::Error ec = llvm::codeview::visitMemberRecordStream(fl.Data, visitor);
1849 if (ec)
1850 llvm::consumeError(std::move(ec));
1851
1852 return visitor.m_has_vbase;
1853}
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 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