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
701 const TagRecord &record) {
702 clang::DeclContext *context = nullptr;
703 std::string uname;
704 std::tie(context, uname) = CreateDeclInfoForType(record, id.index);
705 if (!context)
706 return {};
707
708 clang::TagTypeKind ttk = TranslateUdtKind(record);
709 ClangASTMetadata metadata;
710 metadata.SetUserID(toOpaqueUid(id));
711 metadata.SetIsDynamicCXXType(false);
712
713 CompilerType ct = m_clang.CreateRecordType(
714 context, OptionalClangModuleID(), uname, llvm::to_underlying(ttk),
716 if (!ct.IsValid()) {
717 LLDB_LOG(GetLog(LLDBLog::Symbols), "failed to create record type for {0}",
718 id);
719 return {};
720 }
721
723
724 // Even if it's possible, don't complete it at this point. Just mark it
725 // forward resolved, and if/when LLDB needs the full definition, it can
726 // ask us.
727 clang::QualType result =
728 clang::QualType::getFromOpaquePtr(ct.GetOpaqueQualType());
729
730 TypeSystemClang::SetHasExternalStorage(result.getAsOpaquePtr(), true);
731 return result;
732}
733
735 auto iter = m_uid_to_decl.find(toOpaqueUid(uid));
736 if (iter != m_uid_to_decl.end())
737 return iter->second;
738 return nullptr;
739}
740
741clang::NamespaceDecl *
743 clang::DeclContext &context) {
744 clang::NamespaceDecl *ns = m_clang.GetUniqueNamespaceDeclaration(
745 IsAnonymousNamespaceName(name) ? nullptr : name, &context,
747 m_known_namespaces.insert(ns);
748 m_parent_to_namespaces[&context].insert(ns);
749 return ns;
750}
751
752clang::BlockDecl *
754 if (clang::Decl *decl = TryGetDecl(block_id))
755 return llvm::dyn_cast<clang::BlockDecl>(decl);
756
757 clang::DeclContext *scope = GetParentClangDeclContext(block_id);
758
759 clang::BlockDecl *block_decl =
760 m_clang.CreateBlockDeclaration(scope, OptionalClangModuleID());
761 m_uid_to_decl.insert({toOpaqueUid(block_id), block_decl});
762
763 DeclStatus status;
764 status.resolved = true;
765 status.uid = toOpaqueUid(block_id);
766 m_decl_to_status.insert({block_decl, status});
767
768 return block_decl;
769}
770
771clang::VarDecl *
773 clang::DeclContext &scope) {
774 VariableInfo var_info = GetVariableNameInfo(sym);
775 clang::QualType qt = GetOrCreateClangType(var_info.type);
776 if (qt.isNull())
777 return nullptr;
778
779 clang::VarDecl *var_decl = m_clang.CreateVariableDeclaration(
780 &scope, OptionalClangModuleID(), var_info.name.str().c_str(), qt);
781
782 m_uid_to_decl[toOpaqueUid(uid)] = var_decl;
783 DeclStatus status;
784 status.resolved = true;
785 status.uid = toOpaqueUid(uid);
786 m_decl_to_status.insert({var_decl, status});
787 return var_decl;
788}
789
790clang::VarDecl *
792 PdbCompilandSymId var_id) {
793 if (clang::Decl *decl = TryGetDecl(var_id))
794 return llvm::dyn_cast<clang::VarDecl>(decl);
795
796 clang::DeclContext *scope = GetOrCreateClangDeclContextForUid(scope_id);
797 if (!scope)
798 return nullptr;
799
801 m_clang.GetSymbolFile()->GetBackingSymbolFile());
802 PdbIndex &index = pdb->GetIndex();
803 CVSymbol sym = index.ReadSymbolRecord(var_id);
804 return CreateVariableDecl(PdbSymUid(var_id), sym, *scope);
805}
806
807clang::VarDecl *
809 if (clang::Decl *decl = TryGetDecl(var_id))
810 return llvm::dyn_cast<clang::VarDecl>(decl);
811
813 m_clang.GetSymbolFile()->GetBackingSymbolFile());
814 PdbIndex &index = pdb->GetIndex();
815 CVSymbol sym = index.ReadSymbolRecord(var_id);
817 return CreateVariableDecl(PdbSymUid(var_id), sym, *context);
818}
819
821 if (clang::Decl *decl = TryGetDecl(id)) {
822 if (auto *tnd = llvm::dyn_cast<clang::TypedefNameDecl>(decl))
823 return ToCompilerType(m_clang.getASTContext().getTypeDeclType(tnd));
824 return CompilerType();
825 }
826
828 m_clang.GetSymbolFile()->GetBackingSymbolFile());
829 PdbIndex &index = pdb->GetIndex();
830 CVSymbol sym = index.ReadSymbolRecord(id);
831 if (sym.kind() != S_UDT) {
832 assert(false && "called on a non-udt type");
833 return {};
834 }
835 llvm::Expected<UDTSym> udt = SymbolDeserializer::deserializeAs<UDTSym>(sym);
836 if (!udt) {
837 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), udt.takeError(),
838 "Failed to deserialize {1} as UDT: {0}", id);
839 return CompilerType();
840 }
841
842 clang::DeclContext *scope = GetParentClangDeclContext(id);
843
844 PdbTypeSymId real_type_id{udt->Type, false};
845 clang::QualType qt = GetOrCreateClangType(real_type_id);
846 if (qt.isNull() || !scope)
847 return CompilerType();
848
849 std::string uname = std::string(DropNameScope(udt->Name));
850
852 uname.c_str(), ToCompilerDeclContext(scope), 0);
853 DeclStatus status;
854 status.resolved = true;
855 status.uid = toOpaqueUid(id);
856 m_decl_to_status.insert({m_clang.GetAsTypedefDecl(ct), status});
857 return ct;
858}
859
861 CompilerType ct = m_clang.GetBasicType(type);
862 return clang::QualType::getFromOpaquePtr(ct.GetOpaqueQualType());
863}
864
866 if (type.index.isSimple())
867 return CreateSimpleType(type.index);
868
870 m_clang.GetSymbolFile()->GetBackingSymbolFile());
871 PdbIndex &index = pdb->GetIndex();
872 CVType cvt = index.tpi().getType(type.index);
873
874 if (cvt.kind() == LF_MODIFIER) {
875 ModifierRecord modifier;
876 llvm::Error err =
877 TypeDeserializer::deserializeAs<ModifierRecord>(cvt, modifier);
878 if (err) {
879 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
880 "Failed to deserialize {1} as Modifier: {0}", type.index);
881 return {};
882 }
883 return CreateModifierType(modifier);
884 }
885
886 if (cvt.kind() == LF_POINTER) {
887 PointerRecord pointer;
888 llvm::Error err =
889 TypeDeserializer::deserializeAs<PointerRecord>(cvt, pointer);
890 if (err) {
891 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
892 "Failed to deserialize {1} as Pointer: {0}", type.index);
893 return {};
894 }
895 return CreatePointerType(pointer);
896 }
897
898 if (IsTagRecord(cvt)) {
900 if (tag.kind() == CVTagRecord::Union)
901 return CreateRecordType(type.index, tag.asUnion());
902 if (tag.kind() == CVTagRecord::Enum)
903 return CreateEnumType(type.index, tag.asEnum());
904 return CreateRecordType(type.index, tag.asClass());
905 }
906
907 if (cvt.kind() == LF_ARRAY) {
908 ArrayRecord ar;
909 llvm::Error err = TypeDeserializer::deserializeAs<ArrayRecord>(cvt, ar);
910 if (err) {
911 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
912 "Failed to deserialize {1} as Array: {0}", type.index);
913 return {};
914 }
915 return CreateArrayType(ar);
916 }
917
918 if (cvt.kind() == LF_PROCEDURE) {
919 ProcedureRecord pr;
920 llvm::Error err = TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, pr);
921 if (err) {
922 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
923 "Failed to deserialize {1} as Procedure: {0}", type.index);
924 return {};
925 }
926 return CreateFunctionType(pr.ArgumentList, pr.ReturnType, pr.CallConv,
927 /*type_quals=*/0);
928 }
929
930 if (cvt.kind() == LF_MFUNCTION) {
931 MemberFunctionRecord mfr;
932 llvm::Error err =
933 TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfr);
934 if (err) {
935 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
936 "Failed to deserialize {1} as MemberFunction: {0}",
937 type.index);
938 return {};
939 }
940 unsigned int type_quals = 0;
941 if (!mfr.ThisType.isNoneType()) {
942 clang::QualType this_type = GetOrCreateClangType(mfr.getThisType());
943 if (!this_type.isNull())
944 type_quals = this_type->getPointeeType().getLocalFastQualifiers();
945 }
946 return CreateFunctionType(mfr.ArgumentList, mfr.ReturnType, mfr.CallConv,
947 type_quals);
948 }
949
950 return {};
951}
952
954 if (type.index.isNoneType())
955 return {};
956
957 lldb::user_id_t uid = toOpaqueUid(type);
958 auto iter = m_uid_to_type.find(uid);
959 if (iter != m_uid_to_type.end())
960 return iter->second;
961
963 m_clang.GetSymbolFile()->GetBackingSymbolFile());
964 PdbIndex &index = pdb->GetIndex();
965 PdbTypeSymId best_type = GetBestPossibleDecl(type, index.tpi());
966
967 clang::QualType qt;
968 if (best_type.index != type.index) {
969 // This is a forward decl. Call GetOrCreate on the full decl, then map the
970 // forward decl id to the full decl QualType.
971 clang::QualType qt = GetOrCreateClangType(best_type);
972 if (qt.isNull())
973 return {};
974 m_uid_to_type[toOpaqueUid(type)] = qt;
975 return qt;
976 }
977
978 // This is either a full decl, or a forward decl with no matching full decl
979 // in the debug info.
980 qt = CreateType(type);
981 if (qt.isNull())
982 return {};
983
984 m_uid_to_type[toOpaqueUid(type)] = qt;
985 if (IsTagRecord(type, index.tpi())) {
986 clang::TagDecl *tag = qt->getAsTagDecl();
987 assert(m_decl_to_status.count(tag) == 0 && "type already created");
988
989 DeclStatus &status = m_decl_to_status[tag];
990 status.uid = uid;
991 status.resolved = false;
992 }
993 return qt;
994}
995
997 clang::QualType qt = GetOrCreateClangType(type);
998 if (qt.isNull())
999 return {};
1000 return ToCompilerType(qt);
1001}
1002
1004 lldb::opaque_compiler_type_t parent_ty, llvm::StringRef name,
1005 llvm::StringRef asm_label, const CompilerType &method_ct, bool is_virtual,
1006 bool is_static, bool is_artificial) {
1007 clang::CXXMethodDecl *&method_decl = m_cxx_method_decls[{
1008 parent_ty, ConstString(name), method_ct.GetOpaqueQualType()}];
1009 if (!method_decl)
1010 method_decl = m_clang.AddMethodToCXXRecordType(
1011 parent_ty, name, asm_label, method_ct, is_virtual, is_static,
1012 /*is_inline=*/false, /*is_explicit=*/false,
1013 /*is_attr_used=*/false, is_artificial);
1014 return method_decl;
1015}
1016
1018 PdbCompilandSymId func_id, llvm::StringRef func_name, TypeIndex func_ti,
1019 CompilerType func_ct, uint32_t param_count,
1020 clang::StorageClass func_storage, bool is_inline,
1021 clang::DeclContext *parent) {
1022 clang::FunctionDecl *function_decl = nullptr;
1023 if (parent->isRecord()) {
1025 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1026 PdbIndex &index = pdb->GetIndex();
1027 clang::CanQualType parent_qt =
1028 m_clang.getASTContext().getCanonicalTypeDeclType(
1029 llvm::cast<clang::TypeDecl>(parent));
1030 lldb::opaque_compiler_type_t parent_opaque_ty =
1031 ToCompilerType(parent_qt).GetOpaqueQualType();
1032 // The method may already have been added while completing the class.
1033 auto iter =
1034 m_cxx_method_decls.find({parent_opaque_ty, ConstString(func_name),
1035 func_ct.GetOpaqueQualType()});
1036 if (iter != m_cxx_method_decls.end())
1037 return iter->second;
1038
1039 CVType cvt = index.tpi().getType(func_ti);
1040 MemberFunctionRecord func_record(static_cast<TypeRecordKind>(cvt.kind()));
1041 llvm::Error err =
1042 TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, func_record);
1043 if (err) {
1044 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1045 "Failed to deserialize {1} as MemberFunction: {0}",
1046 func_ti);
1047 return nullptr;
1048 }
1049 TypeIndex class_index = func_record.getClassType();
1050
1051 CVType parent_cvt = index.tpi().getType(class_index);
1052 if (!IsTagRecord(parent_cvt))
1053 return nullptr;
1054 TagRecord tag_record = CVTagRecord::create(parent_cvt).asTag();
1055 // If it's a forward reference, try to get the real TypeIndex.
1056 if (tag_record.isForwardRef()) {
1057 llvm::Expected<TypeIndex> eti =
1058 index.tpi().findFullDeclForForwardRef(class_index);
1059 if (eti) {
1060 CVType resolved_tag_record = index.tpi().getType(*eti);
1061 if (!IsTagRecord(resolved_tag_record))
1062 return nullptr;
1063 tag_record = CVTagRecord::create(resolved_tag_record).asTag();
1064 } else {
1065 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), eti.takeError(),
1066 "failed to find full decl for forward ref: {0}");
1067 }
1068 }
1069
1070 std::string asm_label = pdb->GetFunctionCallLabel(func_id);
1071
1072 if (!tag_record.FieldList.isSimple()) {
1073 CVType field_list_cvt = index.tpi().getType(tag_record.FieldList);
1074 FieldListRecord field_list;
1075 if (llvm::Error error = TypeDeserializer::deserializeAs<FieldListRecord>(
1076 field_list_cvt, field_list))
1077 llvm::consumeError(std::move(error));
1078 CreateMethodDecl process(index, *this, func_ti, function_decl,
1079 parent_opaque_ty, func_name, asm_label, func_ct);
1080 if (llvm::Error err = visitMemberRecordStream(field_list.Data, process))
1081 llvm::consumeError(std::move(err));
1082 }
1083
1084 if (!function_decl)
1085 function_decl = GetOrCreateMethodDecl(
1086 parent_opaque_ty, func_name, asm_label, func_ct,
1087 /*is_virtual=*/false, /*is_static=*/false, /*is_artificial=*/false);
1088 } else {
1090 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1091 function_decl = m_clang.CreateFunctionDeclaration(
1092 parent, OptionalClangModuleID(), func_name, func_ct, func_storage,
1093 is_inline, pdb->GetFunctionCallLabel(func_id));
1094 CreateFunctionParameters(func_id, *function_decl, param_count);
1095 }
1096 return function_decl;
1097}
1098
1100 PdbCompilandSymId inlinesite_id) {
1102 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1103 PdbIndex &index = pdb->GetIndex();
1104 CompilandIndexItem *cii = index.compilands().GetCompiland(inlinesite_id.modi);
1105 CVSymbol sym = cii->m_debug_stream.readSymbolAtOffset(inlinesite_id.offset);
1106 InlineSiteSym inline_site(static_cast<SymbolRecordKind>(sym.kind()));
1107 llvm::Error err =
1108 SymbolDeserializer::deserializeAs<InlineSiteSym>(sym, inline_site);
1109 if (err) {
1110 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1111 "Failed to deserialize {1} as InlineSite: {0}",
1112 inlinesite_id);
1113 return nullptr;
1114 }
1115
1116 // Inlinee is the id index to the function id record that is inlined.
1117 PdbTypeSymId func_id(inline_site.Inlinee, true);
1118 // Look up the function decl by the id index to see if we have created a
1119 // function decl for a different inlinesite that refers the same function.
1120 if (clang::Decl *decl = TryGetDecl(func_id))
1121 return llvm::dyn_cast<clang::FunctionDecl>(decl);
1122 clang::FunctionDecl *function_decl =
1123 CreateFunctionDeclFromId(func_id, inlinesite_id);
1124 if (function_decl == nullptr)
1125 return nullptr;
1126
1127 // Use inline site id in m_decl_to_status because it's expected to be a
1128 // PdbCompilandSymId so that we can parse local variables info after it.
1129 uint64_t inlinesite_uid = toOpaqueUid(inlinesite_id);
1130 DeclStatus status;
1131 status.resolved = true;
1132 status.uid = inlinesite_uid;
1133 m_decl_to_status.insert({function_decl, status});
1134 // Use the index in IPI stream as uid in m_uid_to_decl, because index in IPI
1135 // stream are unique and there could be multiple inline sites (different ids)
1136 // referring the same inline function. This avoid creating multiple same
1137 // inline function delcs.
1138 uint64_t func_uid = toOpaqueUid(func_id);
1139 assert(m_uid_to_decl.count(func_uid) == 0 && "already created");
1140 m_uid_to_decl[func_uid] = function_decl;
1141 return function_decl;
1142}
1143
1144clang::FunctionDecl *
1146 PdbCompilandSymId func_sid) {
1147 if (!func_tid.is_ipi) {
1148 assert(false && "called with non-ipi index");
1149 return nullptr;
1150 }
1151
1153 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1154 PdbIndex &index = pdb->GetIndex();
1155 std::optional<CVType> func_cvt =
1156 index.ipi().typeCollection().tryGetType(func_tid.index);
1157 if (!func_cvt)
1158 return nullptr;
1159 llvm::StringRef func_name;
1160 TypeIndex func_ti;
1161 clang::DeclContext *parent = nullptr;
1162 switch (func_cvt->kind()) {
1163 case LF_MFUNC_ID: {
1164 MemberFuncIdRecord mfr;
1165 llvm::Error err =
1166 TypeDeserializer::deserializeAs<MemberFuncIdRecord>(*func_cvt, mfr);
1167 if (err) {
1168 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1169 "Failed to deserialize {1} (IPI) as MemberFuncId: {0}",
1170 func_tid.index);
1171 return nullptr;
1172 }
1173 func_name = mfr.getName();
1174 func_ti = mfr.getFunctionType();
1175 PdbTypeSymId class_type_id(mfr.ClassType, false);
1176 parent = GetOrCreateClangDeclContextForUid(class_type_id);
1177 break;
1178 }
1179 case LF_FUNC_ID: {
1180 FuncIdRecord fir;
1181 llvm::Error err =
1182 TypeDeserializer::deserializeAs<FuncIdRecord>(*func_cvt, fir);
1183 if (err) {
1184 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1185 "Failed to deserialize {1} (IPI) as FuncId: {0}",
1186 func_tid.index);
1187 return nullptr;
1188 }
1189 func_name = fir.getName();
1190 func_ti = fir.getFunctionType();
1192 if (!fir.ParentScope.isNoneType()) {
1193 CVType parent_cvt = index.ipi().getType(fir.ParentScope);
1194 if (parent_cvt.kind() == LF_STRING_ID) {
1195 StringIdRecord sir;
1196 err = TypeDeserializer::deserializeAs<StringIdRecord>(parent_cvt, sir);
1197 if (err) {
1198 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1199 "Failed to deserialize {1} (IPI) as StringId: {0}",
1200 fir.ParentScope);
1201 return nullptr;
1202 }
1203 parent = GetOrCreateNamespaceDecl(sir.String.data(), *parent);
1204 }
1205 }
1206 break;
1207 }
1208 default:
1209 LLDB_LOG(GetLog(LLDBLog::Symbols), "{0} is not a function type", func_tid);
1210 return nullptr;
1211 }
1212 clang::QualType func_qt = GetOrCreateClangType(func_ti);
1213 if (func_qt.isNull() || !parent)
1214 return nullptr;
1215 CompilerType func_ct = ToCompilerType(func_qt);
1216 uint32_t param_count =
1217 llvm::cast<clang::FunctionProtoType>(func_qt)->getNumParams();
1218 return CreateFunctionDecl(func_sid, func_name, func_ti, func_ct, param_count,
1219 clang::SC_None, true, parent);
1220}
1221
1222clang::FunctionDecl *
1224 if (clang::Decl *decl = TryGetDecl(func_id))
1225 return llvm::dyn_cast<clang::FunctionDecl>(decl);
1226
1227 clang::DeclContext *parent = GetParentClangDeclContext(PdbSymUid(func_id));
1228 if (!parent)
1229 return nullptr;
1230 std::string context_name;
1231 if (clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(parent)) {
1232 context_name = ns->getQualifiedNameAsString();
1233 } else if (clang::TagDecl *tag = llvm::dyn_cast<clang::TagDecl>(parent)) {
1234 context_name = tag->getQualifiedNameAsString();
1235 }
1236
1238 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1239 PdbIndex &index = pdb->GetIndex();
1240 CVSymbol cvs = index.ReadSymbolRecord(func_id);
1241 ProcSym proc(static_cast<SymbolRecordKind>(cvs.kind()));
1242 llvm::Error err = SymbolDeserializer::deserializeAs<ProcSym>(cvs, proc);
1243 if (err) {
1244 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1245 "Failed to deserialize {1} as Proc: {0}", func_id);
1246 return nullptr;
1247 }
1248
1249 PdbTypeSymId type_id(proc.FunctionType);
1250 clang::QualType qt = GetOrCreateClangType(type_id);
1251 if (qt.isNull())
1252 return nullptr;
1253
1254 clang::StorageClass storage = clang::SC_None;
1255 if (proc.Kind == SymbolRecordKind::ProcSym)
1256 storage = clang::SC_Static;
1257
1258 const clang::FunctionProtoType *func_type =
1259 llvm::dyn_cast<clang::FunctionProtoType>(qt);
1260 if (!func_type)
1261 return nullptr;
1262
1263 CompilerType func_ct = ToCompilerType(qt);
1264
1265 llvm::StringRef proc_name = proc.Name;
1266 if (!context_name.empty() && !(proc_name.consume_front(context_name) &&
1267 proc_name.consume_front("::"))) {
1268 // If we have some context, but the function name doesn't start with it, use
1269 // the basename.
1270 MSVCUndecoratedNameParser parser(proc.Name);
1271 llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs(parser.GetSpecifiers());
1272 if (!specs.empty())
1273 proc_name = specs.back().GetBaseName();
1274 }
1275 clang::FunctionDecl *function_decl =
1276 CreateFunctionDecl(func_id, proc_name, proc.FunctionType, func_ct,
1277 func_type->getNumParams(), storage, false, parent);
1278 if (function_decl == nullptr)
1279 return nullptr;
1280
1281 assert(m_uid_to_decl.count(toOpaqueUid(func_id)) == 0 && "already created");
1282 m_uid_to_decl[toOpaqueUid(func_id)] = function_decl;
1283 DeclStatus status;
1284 status.resolved = true;
1285 status.uid = toOpaqueUid(func_id);
1286 m_decl_to_status.insert({function_decl, status});
1287
1288 return function_decl;
1289}
1290
1294
1299
1303
1305 PdbCompilandSymId var_id) {
1306 GetOrCreateVariableDecl(scope_id, var_id);
1307}
1308
1312
1314 PdbCompilandSymId func_id, clang::FunctionDecl &function_decl,
1315 uint32_t param_count) {
1317 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1318 PdbIndex &index = pdb->GetIndex();
1319 CompilandIndexItem *cii = index.compilands().GetCompiland(func_id.modi);
1320 CVSymbolArray scope =
1321 cii->m_debug_stream.getSymbolArrayForScope(func_id.offset);
1322
1323 scope.drop_front();
1324 auto begin = scope.begin();
1325 auto end = scope.end();
1326 std::vector<clang::ParmVarDecl *> params;
1327 for (uint32_t i = 0; i < param_count && begin != end;) {
1328 uint32_t record_offset = begin.offset();
1329 PdbCompilandSymId sym_id(func_id.modi, record_offset);
1330 CVSymbol sym = *begin++;
1331
1332 TypeIndex param_type;
1333 llvm::StringRef param_name;
1334 switch (sym.kind()) {
1335 case S_REGREL32: {
1336 RegRelativeSym reg(SymbolRecordKind::RegRelativeSym);
1337 llvm::Error err =
1338 SymbolDeserializer::deserializeAs<RegRelativeSym>(sym, reg);
1339 if (err) {
1340 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1341 "Failed to deserialize {1} as RegRelative: {0}", sym_id);
1342 return;
1343 }
1344 param_type = reg.Type;
1345 param_name = reg.Name;
1346 break;
1347 }
1348 case S_REGREL32_INDIR: {
1349 RegRelativeIndirSym reg(SymbolRecordKind::RegRelativeIndirSym);
1350 llvm::Error err =
1351 SymbolDeserializer::deserializeAs<RegRelativeIndirSym>(sym, reg);
1352 if (err) {
1353 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1354 "Failed to deserialize {1} as RegRelativeIndir: {0}",
1355 sym_id);
1356 return;
1357 }
1358 param_type = reg.Type;
1359 param_name = reg.Name;
1360 break;
1361 }
1362 case S_REGISTER: {
1363 RegisterSym reg(SymbolRecordKind::RegisterSym);
1364 llvm::Error err =
1365 SymbolDeserializer::deserializeAs<RegisterSym>(sym, reg);
1366 if (err) {
1367 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1368 "Failed to deserialize {1} as Register: {0}", sym_id);
1369 return;
1370 }
1371 param_type = reg.Index;
1372 param_name = reg.Name;
1373 break;
1374 }
1375 case S_LOCAL: {
1376 LocalSym local(SymbolRecordKind::LocalSym);
1377 llvm::Error err = SymbolDeserializer::deserializeAs<LocalSym>(sym, local);
1378 if (err) {
1379 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1380 "Failed to deserialize {1} as Local: {0}", sym_id);
1381 return;
1382 }
1383 if ((local.Flags & LocalSymFlags::IsParameter) == LocalSymFlags::None)
1384 continue;
1385 param_type = local.Type;
1386 param_name = local.Name;
1387 break;
1388 }
1389 case S_BLOCK32:
1390 case S_INLINESITE:
1391 case S_INLINESITE2:
1392 // All parameters should come before the first block/inlinesite. If that
1393 // isn't the case, then perhaps this is bad debug info that doesn't
1394 // contain information about all parameters.
1395 return;
1396 default:
1397 continue;
1398 }
1399
1400 PdbCompilandSymId param_uid(func_id.modi, record_offset);
1401 clang::QualType qt = GetOrCreateClangType(param_type);
1402 if (qt.isNull())
1403 return;
1404
1405 CompilerType param_type_ct = m_clang.GetType(qt);
1406 clang::ParmVarDecl *param = m_clang.CreateParameterDeclaration(
1407 &function_decl, OptionalClangModuleID(), param_name.str().c_str(),
1408 param_type_ct, clang::SC_None, true);
1409
1410 assert(m_uid_to_decl.count(toOpaqueUid(param_uid)) == 0 &&
1411 "already created");
1412 m_uid_to_decl[toOpaqueUid(param_uid)] = param;
1413 params.push_back(param);
1414 ++i;
1415 }
1416
1417 if (!params.empty() && params.size() == param_count)
1418 function_decl.setParams(params);
1419}
1420
1422 const EnumRecord &er) {
1423 clang::DeclContext *decl_context = nullptr;
1424 std::string uname;
1425 std::tie(decl_context, uname) = CreateDeclInfoForType(er, id.index);
1426 if (!decl_context)
1427 return {};
1428
1429 clang::QualType underlying_type = GetOrCreateClangType(er.UnderlyingType);
1430 if (underlying_type.isNull())
1431 return {};
1432
1433 Declaration declaration;
1434 CompilerType enum_ct = m_clang.CreateEnumerationType(
1435 uname, decl_context, OptionalClangModuleID(), declaration,
1436 ToCompilerType(underlying_type), er.isScoped());
1437
1440
1441 return clang::QualType::getFromOpaquePtr(enum_ct.GetOpaqueQualType());
1442}
1443
1444clang::QualType PdbAstBuilderClang::CreateArrayType(const ArrayRecord &ar) {
1445 clang::QualType element_type = GetOrCreateClangType(ar.ElementType);
1447
1449 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1450 PdbIndex &index = pdb->GetIndex();
1451 uint64_t element_size = GetSizeOfType({ar.ElementType}, index.tpi());
1452 if (element_type.isNull() || element_size == 0)
1453 return {};
1454 uint64_t element_count = ar.Size / element_size;
1455
1456 CompilerType array_ct = m_clang.CreateArrayType(ToCompilerType(element_type),
1457 element_count, false);
1458 return clang::QualType::getFromOpaquePtr(array_ct.GetOpaqueQualType());
1459}
1460
1462 TypeIndex args_type_idx, TypeIndex return_type_idx,
1463 llvm::codeview::CallingConvention calling_convention,
1464 unsigned int type_quals) {
1466 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1467 PdbIndex &index = pdb->GetIndex();
1468 TpiStream &stream = index.tpi();
1469 CVType args_cvt = stream.getType(args_type_idx);
1470 ArgListRecord args;
1471 llvm::Error err =
1472 TypeDeserializer::deserializeAs<ArgListRecord>(args_cvt, args);
1473 if (err) {
1474 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1475 "Failed to deserialize {1} as ArgList: {0}", args_type_idx);
1476 return {};
1477 }
1478
1479 llvm::ArrayRef<TypeIndex> arg_indices = llvm::ArrayRef(args.ArgIndices);
1480 bool is_variadic = IsCVarArgsFunction(arg_indices);
1481 if (is_variadic)
1482 arg_indices = arg_indices.drop_back();
1483
1484 std::vector<CompilerType> arg_types;
1485 arg_types.reserve(arg_indices.size());
1486
1487 for (TypeIndex arg_index : arg_indices) {
1488 clang::QualType arg_type = GetOrCreateClangType(arg_index);
1489 if (arg_type.isNull())
1490 continue;
1491 arg_types.push_back(ToCompilerType(arg_type));
1492 }
1493
1494 clang::QualType return_type = GetOrCreateClangType(return_type_idx);
1495 if (return_type.isNull())
1496 return {};
1497
1498 std::optional<clang::CallingConv> cc =
1499 TranslateCallingConvention(calling_convention);
1500 if (!cc)
1501 return {};
1502
1503 CompilerType return_ct = ToCompilerType(return_type);
1504 CompilerType func_sig_ast_type = m_clang.CreateFunctionType(
1505 return_ct, arg_types, is_variadic, type_quals, *cc);
1506
1507 return clang::QualType::getFromOpaquePtr(
1508 func_sig_ast_type.GetOpaqueQualType());
1509}
1510
1511static bool isTagDecl(clang::DeclContext &context) {
1512 return llvm::isa<clang::TagDecl>(&context);
1513}
1514
1515static bool isFunctionDecl(clang::DeclContext &context) {
1516 return llvm::isa<clang::FunctionDecl>(&context);
1517}
1518
1519static bool isBlockDecl(clang::DeclContext &context) {
1520 return llvm::isa<clang::BlockDecl>(&context);
1521}
1522
1523void PdbAstBuilderClang::ParseNamespace(clang::DeclContext &context) {
1524 clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(&context);
1525 if (m_parsed_namespaces.contains(ns))
1526 return;
1527 std::string qname = ns->getQualifiedNameAsString();
1529 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1530 PdbIndex &index = pdb->GetIndex();
1531 TypeIndex ti{index.tpi().TypeIndexBegin()};
1532 for (const CVType &cvt : index.tpi().typeArray()) {
1533 PdbTypeSymId tid{ti};
1534 ++ti;
1535
1536 if (!IsTagRecord(cvt))
1537 continue;
1538
1540
1541 // Call CreateDeclInfoForType unconditionally so that the namespace info
1542 // gets created. But only call CreateRecordType if the namespace name
1543 // matches.
1544 clang::DeclContext *context = nullptr;
1545 std::string uname;
1546 std::tie(context, uname) = CreateDeclInfoForType(tag.asTag(), tid.index);
1547 if (!context || !context->isNamespace())
1548 continue;
1549
1550 clang::NamespaceDecl *ns = llvm::cast<clang::NamespaceDecl>(context);
1551 llvm::StringRef ns_name = ns->getName();
1552 if (ns_name.starts_with(qname)) {
1553 ns_name = ns_name.drop_front(qname.size());
1554 if (ns_name.starts_with("::"))
1556 }
1557 }
1559 m_parsed_namespaces.insert(ns);
1560}
1561
1563 llvm::call_once(m_parse_all_types, [this]() {
1565 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1566 PdbIndex &index = pdb->GetIndex();
1567 TypeIndex ti{index.tpi().TypeIndexBegin()};
1568 for (const CVType &cvt : index.tpi().typeArray()) {
1569 PdbTypeSymId tid{ti};
1570 ++ti;
1571
1572 if (!IsTagRecord(cvt))
1573 continue;
1574
1576 }
1577 });
1578}
1579
1581 llvm::call_once(m_parse_functions_and_non_local_vars, [this]() {
1583 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1584 PdbIndex &index = pdb->GetIndex();
1585 uint32_t module_count = index.dbi().modules().getModuleCount();
1586 for (uint16_t modi = 0; modi < module_count; ++modi) {
1588 const CVSymbolArray &symbols = cii.m_debug_stream.getSymbolArray();
1589 auto iter = symbols.begin();
1590 while (iter != symbols.end()) {
1591 PdbCompilandSymId sym_id{modi, iter.offset()};
1592
1593 switch (iter->kind()) {
1594 case S_GPROC32:
1595 case S_LPROC32:
1597 iter = symbols.at(getScopeEndOffset(*iter));
1598 break;
1599 case S_GDATA32:
1600 case S_GTHREAD32:
1601 case S_LDATA32:
1602 case S_LTHREAD32:
1604 ++iter;
1605 break;
1606 default:
1607 ++iter;
1608 continue;
1609 }
1610 }
1611 }
1612 });
1613}
1614
1615static CVSymbolArray skipFunctionParameters(clang::Decl &decl,
1616 const CVSymbolArray &symbols) {
1617 clang::FunctionDecl *func_decl = llvm::dyn_cast<clang::FunctionDecl>(&decl);
1618 if (!func_decl)
1619 return symbols;
1620 unsigned int params = func_decl->getNumParams();
1621 if (params == 0)
1622 return symbols;
1623
1624 CVSymbolArray result = symbols;
1625
1626 while (!result.empty()) {
1627 if (params == 0)
1628 return result;
1629
1630 CVSymbol sym = *result.begin();
1631 result.drop_front();
1632
1633 if (!isLocalVariableType(sym.kind()))
1634 continue;
1635
1636 --params;
1637 }
1638 return result;
1639}
1640
1643 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1644 PdbIndex &index = pdb->GetIndex();
1645 CVSymbol sym = index.ReadSymbolRecord(block_id);
1646 if (sym.kind() != S_GPROC32 && sym.kind() != S_LPROC32 &&
1647 sym.kind() != S_BLOCK32 && sym.kind() != S_INLINESITE) {
1648 assert(false && "called on non-block");
1649 return;
1650 }
1651 CompilandIndexItem &cii =
1652 index.compilands().GetOrCreateCompiland(block_id.modi);
1653 CVSymbolArray symbols =
1654 cii.m_debug_stream.getSymbolArrayForScope(block_id.offset);
1655
1656 // Function parameters should already have been created when the function was
1657 // parsed.
1658 if (sym.kind() == S_GPROC32 || sym.kind() == S_LPROC32)
1659 symbols =
1660 skipFunctionParameters(*m_uid_to_decl[toOpaqueUid(block_id)], symbols);
1661
1662 symbols.drop_front();
1663 auto begin = symbols.begin();
1664 while (begin != symbols.end()) {
1665 PdbCompilandSymId child_sym_id(block_id.modi, begin.offset());
1666 GetOrCreateSymbolForId(child_sym_id);
1667 if (begin->kind() == S_BLOCK32 || begin->kind() == S_INLINESITE) {
1668 ParseBlockChildren(child_sym_id);
1669 begin = symbols.at(getScopeEndOffset(*begin));
1670 }
1671 ++begin;
1672 }
1673}
1674
1676 clang::DeclContext &context) {
1677
1678 clang::Decl *decl = clang::Decl::castFromDeclContext(&context);
1679 if (!decl) {
1680 assert(false);
1681 return;
1682 }
1683
1684 auto iter = m_decl_to_status.find(decl);
1685 if (iter == m_decl_to_status.end()) {
1686 assert(false && "cannot parse unknown decl");
1687 return;
1688 }
1689
1690 if (auto *tag = llvm::dyn_cast<clang::TagDecl>(&context)) {
1691 CompleteTagDecl(*tag);
1692 return;
1693 }
1694
1695 if (isFunctionDecl(context) || isBlockDecl(context)) {
1696 PdbCompilandSymId block_id = PdbSymUid(iter->second.uid).asCompilandSym();
1697 ParseBlockChildren(block_id);
1698 }
1699}
1700
1702 clang::DeclContext *dc = FromCompilerDeclContext(context);
1703 if (!dc)
1704 return;
1705
1706 // Namespaces aren't explicitly represented in the debug info, and the only
1707 // way to parse them is to parse all type info, demangling every single type
1708 // and trying to reconstruct the DeclContext hierarchy this way. Since this
1709 // is an expensive operation, we have to special case it so that we do other
1710 // work (such as parsing the items that appear within the namespaces) at the
1711 // same time.
1712 if (dc->isTranslationUnit()) {
1713 ParseAllTypes();
1715 return;
1716 }
1717
1718 if (dc->isNamespace()) {
1719 ParseNamespace(*dc);
1720 return;
1721 }
1722
1723 if (isTagDecl(*dc) || isFunctionDecl(*dc) || isBlockDecl(*dc)) {
1725 return;
1726 }
1727}
1728
1730 return m_clang.GetCompilerDecl(decl);
1731}
1732
1734 return m_clang.GetType(qt);
1735}
1736
1740
1742PdbAstBuilderClang::ToCompilerDeclContext(clang::DeclContext *context) {
1743 if (!context)
1744 return CompilerDeclContext();
1745 return m_clang.CreateDeclContext(context);
1746}
1747
1749 if (decl.GetTypeSystem() != nullptr)
1750 return ClangUtil::GetDecl(decl);
1751 return nullptr;
1752}
1753
1754clang::DeclContext *
1756 return static_cast<clang::DeclContext *>(context.GetOpaqueDeclContext());
1757}
1758
1759void PdbAstBuilderClang::Dump(Stream &stream, llvm::StringRef filter,
1760 bool show_color) {
1761 m_clang.Dump(stream.AsRawOstream(), filter, show_color);
1762}
1763
1766 llvm::StringRef name) {
1767 clang::DeclContext *parent = FromCompilerDeclContext(parent_ctx);
1768 NamespaceSet *set;
1769
1770 if (parent) {
1771 auto it = m_parent_to_namespaces.find(parent);
1772 if (it == m_parent_to_namespaces.end())
1773 return {};
1774
1775 set = &it->second;
1776 } else {
1777 // In this case, search through all known namespaces
1778 set = &m_known_namespaces;
1779 }
1780 assert(set);
1781
1782 for (clang::NamespaceDecl *namespace_decl : *set)
1783 if (namespace_decl->getName() == name)
1784 return ToCompilerDeclContext(namespace_decl);
1785
1786 for (clang::NamespaceDecl *namespace_decl : *set)
1787 if (namespace_decl->isAnonymousNamespace())
1788 return FindNamespaceDecl(ToCompilerDeclContext(namespace_decl), name);
1789
1790 return {};
1791}
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)
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
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
clang::QualType CreateRecordType(PdbTypeSymId id, const llvm::codeview::TagRecord &record)
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)
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
const llvm::codeview::UnionRecord & asUnion() const
Definition PdbUtil.h:62
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