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, TypeSystemClang &m_clang,
39 TypeIndex func_type_index,
40 clang::FunctionDecl *&function_decl,
42 llvm::StringRef proc_name, ConstString mangled_name,
43 CompilerType func_ct)
44 : m_index(m_index), m_clang(m_clang), func_type_index(func_type_index),
45 function_decl(function_decl), parent_ty(parent_ty),
46 proc_name(proc_name), mangled_name(mangled_name), func_ct(func_ct) {}
47 PdbIndex &m_index;
48 TypeSystemClang &m_clang;
49 TypeIndex func_type_index;
50 clang::FunctionDecl *&function_decl;
52 llvm::StringRef proc_name;
53 ConstString mangled_name;
54 CompilerType func_ct;
55
56 llvm::Error visitKnownMember(CVMemberRecord &cvr,
57 OverloadedMethodRecord &overloaded) override {
58 TypeIndex method_list_idx = overloaded.MethodList;
59
60 CVType method_list_type = m_index.tpi().getType(method_list_idx);
61 assert(method_list_type.kind() == LF_METHODLIST);
62
63 MethodOverloadListRecord method_list;
64 llvm::Error err = TypeDeserializer::deserializeAs<MethodOverloadListRecord>(
65 method_list_type, method_list);
66 if (err) {
67 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
68 "Failed to deserialize {1} as MethodOverloadList: {0}",
69 method_list_idx);
70 // Continue even if we couldn't deserialize.
71 return llvm::Error::success();
72 }
73
74 for (const OneMethodRecord &method : method_list.Methods) {
75 if (method.getType().getIndex() == func_type_index.getIndex())
76 AddMethod(overloaded.Name, method.getOptions(), method.Attrs);
77 }
78
79 return llvm::Error::success();
80 }
81
82 llvm::Error visitKnownMember(CVMemberRecord &cvr,
83 OneMethodRecord &record) override {
84 AddMethod(record.getName(), record.getOptions(), record.Attrs);
85 return llvm::Error::success();
86 }
87
88 void AddMethod(llvm::StringRef name, MethodOptions options,
89 MemberAttributes attrs) {
90 if (name != proc_name || function_decl)
91 return;
92 bool is_virtual = attrs.isVirtual();
93 bool is_static = attrs.isStatic();
94 bool is_artificial = (options & MethodOptions::CompilerGenerated) ==
95 MethodOptions::CompilerGenerated;
96 function_decl = m_clang.AddMethodToCXXRecordType(
97 parent_ty, proc_name, mangled_name, func_ct,
98 /*is_virtual=*/is_virtual, /*is_static=*/is_static,
99 /*is_inline=*/false, /*is_explicit=*/false,
100 /*is_attr_used=*/false, /*is_artificial=*/is_artificial);
101 }
102};
103} // namespace
104
105static clang::TagTypeKind TranslateUdtKind(const TagRecord &cr) {
106 switch (cr.Kind) {
107 case TypeRecordKind::Class:
108 return clang::TagTypeKind::Class;
109 case TypeRecordKind::Struct:
110 return clang::TagTypeKind::Struct;
111 case TypeRecordKind::Union:
112 return clang::TagTypeKind::Union;
113 case TypeRecordKind::Interface:
114 return clang::TagTypeKind::Interface;
115 case TypeRecordKind::Enum:
116 return clang::TagTypeKind::Enum;
117 default:
118 assert(false && "Invalid tag record kind!");
119 return clang::TagTypeKind::Struct;
120 }
121}
122
123static bool IsCVarArgsFunction(llvm::ArrayRef<TypeIndex> args) {
124 if (args.empty())
125 return false;
126 return args.back() == TypeIndex::None();
127}
128
129static bool
130AnyScopesHaveTemplateParams(llvm::ArrayRef<llvm::ms_demangle::Node *> scopes) {
131 for (llvm::ms_demangle::Node *n : scopes) {
132 auto *idn = static_cast<llvm::ms_demangle::IdentifierNode *>(n);
133 if (idn->TemplateParams)
134 return true;
135 }
136 return false;
137}
138
139static std::optional<clang::CallingConv>
140TranslateCallingConvention(llvm::codeview::CallingConvention conv) {
141 using CC = llvm::codeview::CallingConvention;
142 switch (conv) {
143
144 case CC::NearC:
145 case CC::FarC:
146 return clang::CallingConv::CC_C;
147 case CC::NearPascal:
148 case CC::FarPascal:
149 return clang::CallingConv::CC_X86Pascal;
150 case CC::NearFast:
151 case CC::FarFast:
152 return clang::CallingConv::CC_X86FastCall;
153 case CC::NearStdCall:
154 case CC::FarStdCall:
155 return clang::CallingConv::CC_X86StdCall;
156 case CC::ThisCall:
157 return clang::CallingConv::CC_X86ThisCall;
158 case CC::NearVector:
159 return clang::CallingConv::CC_X86VectorCall;
160 default:
161 return std::nullopt;
162 }
163}
164
165static bool IsAnonymousNamespaceName(llvm::StringRef name) {
166 return name == "`anonymous namespace'" || name == "`anonymous-namespace'";
167}
168
171
175
176std::pair<clang::DeclContext *, std::string>
178 TypeIndex ti) {
180 m_clang.GetSymbolFile()->GetBackingSymbolFile());
181 // FIXME: Move this to GetDeclContextContainingUID.
182 if (!record.hasUniqueName())
183 return CreateDeclInfoForUndecoratedName(record.Name);
184
185 llvm::ms_demangle::Demangler demangler;
186 std::string_view sv(record.UniqueName.begin(), record.UniqueName.size());
187 llvm::ms_demangle::TagTypeNode *ttn = demangler.parseTagUniqueName(sv);
188 if (demangler.Error)
189 return CreateDeclInfoForUndecoratedName(record.Name);
190
191 llvm::ms_demangle::IdentifierNode *idn =
192 ttn->QualifiedName->getUnqualifiedIdentifier();
193 std::string uname = idn->toString(llvm::ms_demangle::OF_NoTagSpecifier);
194
195 llvm::ms_demangle::NodeArrayNode *name_components =
196 ttn->QualifiedName->Components;
197 llvm::ArrayRef<llvm::ms_demangle::Node *> scopes(name_components->Nodes,
198 name_components->Count - 1);
199
200 clang::DeclContext *context = m_clang.GetTranslationUnitDecl();
201
202 // If this type doesn't have a parent type in the debug info, then the best we
203 // can do is to say that it's either a series of namespaces (if the scope is
204 // non-empty), or the translation unit (if the scope is empty).
205 std::optional<TypeIndex> parent_index = pdb->GetParentType(ti);
206 if (!parent_index) {
207 if (scopes.empty())
208 return {context, uname};
209
210 // If there is no parent in the debug info, but some of the scopes have
211 // template params, then this is a case of bad debug info. See, for
212 // example, llvm.org/pr39607. We don't want to create an ambiguity between
213 // a NamespaceDecl and a CXXRecordDecl, so instead we create a class at
214 // global scope with the fully qualified name.
215 if (AnyScopesHaveTemplateParams(scopes))
216 return {context, std::string(record.Name)};
217
218 for (llvm::ms_demangle::Node *scope : scopes) {
219 auto *nii = static_cast<llvm::ms_demangle::NamedIdentifierNode *>(scope);
220 std::string str = nii->toString();
221 context = GetOrCreateNamespaceDecl(str.c_str(), *context);
222 }
223 return {context, uname};
224 }
225
226 // Otherwise, all we need to do is get the parent type of this type and
227 // recurse into our lazy type creation / AST reconstruction logic to get an
228 // LLDB TypeSP for the parent. This will cause the AST to automatically get
229 // the right DeclContext created for any parent.
230 clang::QualType parent_qt = GetOrCreateClangType(*parent_index);
231 if (parent_qt.isNull())
232 return {nullptr, ""};
233
234 context = clang::TagDecl::castToDeclContext(parent_qt->getAsTagDecl());
235 return {context, uname};
236}
237
238static bool isLocalVariableType(SymbolKind K) {
239 switch (K) {
240 case S_REGISTER:
241 case S_REGREL32:
242 case S_REGREL32_INDIR:
243 case S_LOCAL:
244 return true;
245 default:
246 break;
247 }
248 return false;
249}
250
253 m_clang.GetSymbolFile()->GetBackingSymbolFile());
254 PdbIndex &index = pdb->GetIndex();
255 CVSymbol cvs = index.ReadSymbolRecord(id);
256
257 if (isLocalVariableType(cvs.kind())) {
258 clang::DeclContext *scope = GetParentClangDeclContext(id);
259 if (!scope)
260 return nullptr;
261 clang::Decl *scope_decl = clang::Decl::castFromDeclContext(scope);
262 PdbCompilandSymId scope_id =
263 PdbSymUid(m_decl_to_status[scope_decl].uid).asCompilandSym();
264 return GetOrCreateVariableDecl(scope_id, id);
265 }
266
267 switch (cvs.kind()) {
268 case S_GPROC32:
269 case S_LPROC32:
270 return GetOrCreateFunctionDecl(id);
271 case S_GDATA32:
272 case S_LDATA32:
273 case S_GTHREAD32:
274 case S_CONSTANT:
275 // global variable
276 return nullptr;
277 case S_BLOCK32:
278 return GetOrCreateBlockDecl(id);
279 case S_INLINESITE:
281 default:
282 return nullptr;
283 }
284}
285
287 if (clang::Decl *result = TryGetDecl(uid))
288 return ToCompilerDecl(result);
289
290 clang::Decl *result = nullptr;
291 switch (uid.kind()) {
294 break;
295 case PdbSymUidKind::Type: {
296 clang::QualType qt = GetOrCreateClangType(uid.asTypeSym());
297 if (qt.isNull())
298 return CompilerDecl();
299 if (auto *tag = qt->getAsTagDecl()) {
300 result = tag;
301 break;
302 }
303 return CompilerDecl();
304 }
305 default:
306 return CompilerDecl();
307 }
308
309 if (!result)
310 return CompilerDecl();
311 m_uid_to_decl[toOpaqueUid(uid)] = result;
312 return ToCompilerDecl(result);
313}
314
315clang::DeclContext *
317 if (uid.kind() == PdbSymUidKind::CompilandSym) {
318 if (uid.asCompilandSym().offset == 0)
320 }
321 clang::Decl *decl = FromCompilerDecl(GetOrCreateDeclForUid(uid));
322 if (!decl)
323 return nullptr;
324
325 return clang::Decl::castToDeclContext(decl);
326}
327
332
333std::pair<clang::DeclContext *, std::string>
336 m_clang.GetSymbolFile()->GetBackingSymbolFile());
337 PdbIndex &index = pdb->GetIndex();
338 MSVCUndecoratedNameParser parser(name);
339 llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs = parser.GetSpecifiers();
340
342
343 llvm::StringRef uname = specs.back().GetBaseName();
344 specs = specs.drop_back();
345 if (specs.empty())
346 return {context, std::string(name)};
347
348 llvm::StringRef scope_name = specs.back().GetFullName();
349
350 // It might be a class name, try that first.
351 std::vector<TypeIndex> types = index.tpi().findRecordsByName(scope_name);
352 while (!types.empty()) {
353 clang::QualType qt = GetOrCreateClangType(types.back());
354 if (qt.isNull())
355 continue;
356 clang::TagDecl *tag = qt->getAsTagDecl();
357 if (tag)
358 return {clang::TagDecl::castToDeclContext(tag), std::string(uname)};
359 types.pop_back();
360 }
361
362 // If that fails, treat it as a series of namespaces.
363 for (const MSVCUndecoratedNameSpecifier &spec : specs) {
364 std::string ns_name = spec.GetBaseName().str();
365 context = GetOrCreateNamespaceDecl(ns_name.c_str(), *context);
366 }
367 return {context, std::string(uname)};
368}
369
370clang::DeclContext *
372 PdbCompilandSymId uid) {
374 m_clang.GetSymbolFile()->GetBackingSymbolFile());
375 PdbIndex &index = pdb->GetIndex();
376 CVSymbol sym = index.ReadSymbolRecord(uid);
377
378 llvm::StringRef symbol_name = getSymbolName(sym);
379
380 std::optional<PdbTypeSymId> func_id = GetFunctionType(sym);
381 if (!func_id || !symbol_name.contains("::"))
382 return CreateDeclInfoForUndecoratedName(symbol_name).first;
383
384 // Try to get the context from class type of an LF_MFUNCTION.
385 // For some types, we might not find a class type.
386 auto get_member_fn_context = [&]() -> clang::DeclContext * {
387 TypeIndex id = func_id->index;
388
389 if (func_id->is_ipi) {
390 // Type from IPI, for example from S_INLINESITE
391 std::optional<CVType> func_id_type =
392 index.ipi().tryGetType(func_id->index);
393 if (!func_id_type || func_id_type->kind() != LF_MFUNC_ID)
394 return nullptr;
395
396 MemberFuncIdRecord record;
397 llvm::Error err = TypeDeserializer::deserializeAs<MemberFuncIdRecord>(
398 *func_id_type, record);
399 if (err) {
400 llvm::consumeError(std::move(err));
401 return nullptr;
402 }
403
404 id = record.FunctionType;
405 }
406
407 std::optional<CVType> func_type = index.tpi().tryGetType(id);
408 if (!func_type || func_type->kind() != LF_MFUNCTION)
409 return nullptr;
410
411 MemberFunctionRecord mfr(TypeRecordKind::MemberFunction);
412
413 llvm::Error err =
414 TypeDeserializer::deserializeAs<MemberFunctionRecord>(*func_type, mfr);
415 if (err || mfr.ClassType.isNoneType()) {
416 llvm::consumeError(std::move(err));
417 return nullptr;
418 }
419
420 clang::QualType qt = GetOrCreateClangType(mfr.ClassType);
421 if (qt.isNull())
422 return nullptr;
423 clang::TagDecl *tag = qt->getAsTagDecl();
424 if (!tag)
425 return nullptr;
426
427 return clang::TagDecl::castToDeclContext(tag);
428 };
429
430 clang::DeclContext *context = get_member_fn_context();
431 if (!context)
432 return CreateDeclInfoForUndecoratedName(symbol_name).first;
433
434 return context;
435}
436
437clang::DeclContext *
439 // We must do this *without* calling GetOrCreate on the current uid, as
440 // that would be an infinite recursion.
442 m_clang.GetSymbolFile()->GetBackingSymbolFile());
443 PdbIndex &index = pdb->GetIndex();
444 switch (uid.kind()) {
446 std::optional<PdbCompilandSymId> scope =
447 pdb->FindSymbolScope(uid.asCompilandSym());
448 if (scope)
450
452 }
453 case PdbSymUidKind::Type: {
454 // It could be a namespace, class, or global. We don't support nested
455 // functions yet. Anyway, we just need to consult the parent type map.
456 PdbTypeSymId type_id = uid.asTypeSym();
457 std::optional<TypeIndex> parent_index = pdb->GetParentType(type_id.index);
458 if (!parent_index)
460 return GetOrCreateClangDeclContextForUid(PdbTypeSymId(*parent_index));
461 }
463 // In this case the parent DeclContext is the one for the class that this
464 // member is inside of.
465 break;
467 // If this refers to a compiland symbol, just recurse in with that symbol.
468 // The only other possibilities are S_CONSTANT and S_UDT, in which case we
469 // need to parse the undecorated name to figure out the scope, then look
470 // that up in the TPI stream. If it's found, it's a type, othewrise it's
471 // a series of namespaces.
472 // FIXME: do this.
473 CVSymbol global = index.ReadSymbolRecord(uid.asGlobalSym());
474 switch (global.kind()) {
475 case SymbolKind::S_GDATA32:
476 case SymbolKind::S_LDATA32:
477 return CreateDeclInfoForUndecoratedName(getSymbolName(global)).first;
478 case SymbolKind::S_PROCREF:
479 case SymbolKind::S_LPROCREF: {
480 ProcRefSym ref{global.kind()};
481 llvm::Error err =
482 SymbolDeserializer::deserializeAs<ProcRefSym>(global, ref);
483 if (err) {
484 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
485 "Failed to deserialize {1} as ProcRef: {0}",
486 uid.asGlobalSym());
487 return nullptr;
488 }
489 PdbCompilandSymId cu_sym_id{ref.modi(), ref.SymOffset};
490 return GetParentClangDeclContext(cu_sym_id);
491 }
492 case SymbolKind::S_CONSTANT:
493 case SymbolKind::S_UDT:
494 return CreateDeclInfoForUndecoratedName(getSymbolName(global)).first;
495 default:
496 break;
497 }
498 break;
499 }
500 default:
501 break;
502 }
504}
505
509
511 if (GetClangASTImporter().CanImport(ct))
513
514 clang::QualType qt = FromCompilerType(ct);
515 if (qt.isNull())
516 return false;
517 clang::TagDecl *tag = qt->getAsTagDecl();
518 if (qt->isArrayType()) {
519 const clang::Type *element_type = qt->getArrayElementTypeNoTypeQual();
520 tag = element_type->getAsTagDecl();
521 }
522 if (!tag)
523 return false;
524
525 return CompleteTagDecl(*tag);
526}
527
528bool PdbAstBuilderClang::CompleteTagDecl(clang::TagDecl &tag) {
529 auto status_iter = m_decl_to_status.find(&tag);
530 if (status_iter == m_decl_to_status.end()) {
531 // If this is not in our map, it's an error.
532 assert(false && "completing unknown tag decl");
533 return false;
534 }
535
536 // If it's already complete, just return.
537 DeclStatus &status = status_iter->second;
538 if (status.resolved)
539 return true;
540
541 PdbTypeSymId type_id = PdbSymUid(status.uid).asTypeSym();
542 PdbIndex &index = static_cast<SymbolFileNativePDB *>(
543 m_clang.GetSymbolFile()->GetBackingSymbolFile())
544 ->GetIndex();
545
546 clang::QualType tag_qt = m_clang.getASTContext().getCanonicalTagType(&tag);
547 TypeSystemClang::SetHasExternalStorage(tag_qt.getAsOpaquePtr(), false);
548
549 TypeIndex tag_ti = type_id.index;
550 CVType cvt = index.tpi().getType(tag_ti);
551 if (cvt.kind() == LF_MODIFIER)
552 tag_ti = LookThroughModifierRecord(cvt);
553
554 PdbTypeSymId best_ti = GetBestPossibleDecl(tag_ti, index.tpi());
555 cvt = index.tpi().getType(best_ti.index);
556 if (!IsTagRecord(cvt)) {
557 assert(false && "completing tag record that's not a tag record");
558 return false;
559 }
560
561 if (IsForwardRefUdt(cvt)) {
562 // If we can't find a full decl for this forward ref anywhere in the debug
563 // info, then we have no way to complete it.
564 return false;
565 }
566
567 TypeIndex field_list_ti = GetFieldListIndex(cvt);
568 CVType field_list_cvt = index.tpi().getType(field_list_ti);
569 if (field_list_cvt.kind() != LF_FIELDLIST)
570 return false;
571 FieldListRecord field_list;
572 if (llvm::Error error = TypeDeserializer::deserializeAs<FieldListRecord>(
573 field_list_cvt, field_list))
574 llvm::consumeError(std::move(error));
575
576 // Visit all members of this class, then perform any finalization necessary
577 // to complete the class.
578 CompilerType ct = ToCompilerType(tag_qt);
579 UdtRecordCompleter completer(best_ti, ct, tag, *this, index, m_decl_to_status,
581 llvm::Error error =
582 llvm::codeview::visitMemberRecordStream(field_list.Data, completer);
583 completer.complete();
584
585 m_decl_to_status[&tag].resolved = true;
586 if (error) {
587 llvm::consumeError(std::move(error));
588 return false;
589 }
590 return true;
591}
592
594 if (ti == TypeIndex::NullptrT())
596
597 if (ti.getSimpleMode() != SimpleTypeMode::Direct) {
598 clang::QualType direct_type = GetOrCreateClangType(ti.makeDirect());
599 if (direct_type.isNull())
600 return {};
601 return m_clang.getASTContext().getPointerType(direct_type);
602 }
603
604 if (ti.getSimpleKind() == SimpleTypeKind::NotTranslated)
605 return {};
606
607 lldb::BasicType bt = GetCompilerTypeForSimpleKind(ti.getSimpleKind());
608 if (bt == lldb::eBasicTypeInvalid)
609 return {};
610
611 return GetBasicType(bt);
612}
613
614clang::QualType
615PdbAstBuilderClang::CreatePointerType(const PointerRecord &pointer) {
616 clang::QualType pointee_type = GetOrCreateClangType(pointer.ReferentType);
617
618 // This can happen for pointers to LF_VTSHAPE records, which we shouldn't
619 // create in the AST.
620 if (pointee_type.isNull())
621 return {};
622
623 if (pointer.isPointerToMember()) {
624 MemberPointerInfo mpi = pointer.getMemberInfo();
625 clang::QualType class_type = GetOrCreateClangType(mpi.ContainingType);
626 if (class_type.isNull())
627 return {};
628 if (clang::TagDecl *tag = class_type->getAsTagDecl()) {
629 clang::MSInheritanceAttr::Spelling spelling;
630 switch (mpi.Representation) {
631 case llvm::codeview::PointerToMemberRepresentation::SingleInheritanceData:
632 case llvm::codeview::PointerToMemberRepresentation::
633 SingleInheritanceFunction:
634 spelling =
635 clang::MSInheritanceAttr::Spelling::Keyword_single_inheritance;
636 break;
637 case llvm::codeview::PointerToMemberRepresentation::
638 MultipleInheritanceData:
639 case llvm::codeview::PointerToMemberRepresentation::
640 MultipleInheritanceFunction:
641 spelling =
642 clang::MSInheritanceAttr::Spelling::Keyword_multiple_inheritance;
643 break;
644 case llvm::codeview::PointerToMemberRepresentation::
645 VirtualInheritanceData:
646 case llvm::codeview::PointerToMemberRepresentation::
647 VirtualInheritanceFunction:
648 spelling =
649 clang::MSInheritanceAttr::Spelling::Keyword_virtual_inheritance;
650 break;
651 case llvm::codeview::PointerToMemberRepresentation::Unknown:
652 spelling =
653 clang::MSInheritanceAttr::Spelling::Keyword_unspecified_inheritance;
654 break;
655 default:
656 spelling = clang::MSInheritanceAttr::Spelling::SpellingNotCalculated;
657 break;
658 }
659 tag->addAttr(clang::MSInheritanceAttr::CreateImplicit(
660 m_clang.getASTContext(), spelling));
661 }
662 return m_clang.getASTContext().getMemberPointerType(
663 pointee_type, /*Qualifier=*/std::nullopt,
664 class_type->getAsCXXRecordDecl());
665 }
666
667 clang::QualType pointer_type;
668 if (pointer.getMode() == PointerMode::LValueReference)
669 pointer_type = m_clang.getASTContext().getLValueReferenceType(pointee_type);
670 else if (pointer.getMode() == PointerMode::RValueReference)
671 pointer_type = m_clang.getASTContext().getRValueReferenceType(pointee_type);
672 else
673 pointer_type = m_clang.getASTContext().getPointerType(pointee_type);
674
675 if ((pointer.getOptions() & PointerOptions::Const) != PointerOptions::None)
676 pointer_type.addConst();
677
678 if ((pointer.getOptions() & PointerOptions::Volatile) != PointerOptions::None)
679 pointer_type.addVolatile();
680
681 if ((pointer.getOptions() & PointerOptions::Restrict) != PointerOptions::None)
682 pointer_type.addRestrict();
683
684 return pointer_type;
685}
686
687clang::QualType
688PdbAstBuilderClang::CreateModifierType(const ModifierRecord &modifier) {
689 clang::QualType unmodified_type = GetOrCreateClangType(modifier.ModifiedType);
690 if (unmodified_type.isNull())
691 return {};
692
693 if ((modifier.Modifiers & ModifierOptions::Const) != ModifierOptions::None)
694 unmodified_type.addConst();
695 if ((modifier.Modifiers & ModifierOptions::Volatile) != ModifierOptions::None)
696 unmodified_type.addVolatile();
697
698 return unmodified_type;
699}
700
702 const TagRecord &record) {
703 clang::DeclContext *context = nullptr;
704 std::string uname;
705 std::tie(context, uname) = CreateDeclInfoForType(record, id.index);
706 if (!context)
707 return {};
708
709 clang::TagTypeKind ttk = TranslateUdtKind(record);
710 ClangASTMetadata metadata;
711 metadata.SetUserID(toOpaqueUid(id));
712 metadata.SetIsDynamicCXXType(false);
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::Union)
902 return CreateRecordType(type.index, tag.asUnion());
903 if (tag.kind() == CVTagRecord::Enum)
904 return CreateEnumType(type.index, tag.asEnum());
905 return CreateRecordType(type.index, tag.asClass());
906 }
907
908 if (cvt.kind() == LF_ARRAY) {
909 ArrayRecord ar;
910 llvm::Error err = TypeDeserializer::deserializeAs<ArrayRecord>(cvt, ar);
911 if (err) {
912 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
913 "Failed to deserialize {1} as Array: {0}", type.index);
914 return {};
915 }
916 return CreateArrayType(ar);
917 }
918
919 if (cvt.kind() == LF_PROCEDURE) {
920 ProcedureRecord pr;
921 llvm::Error err = TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, pr);
922 if (err) {
923 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
924 "Failed to deserialize {1} as Procedure: {0}", type.index);
925 return {};
926 }
927 return CreateFunctionType(pr.ArgumentList, pr.ReturnType, pr.CallConv,
928 /*type_quals=*/0);
929 }
930
931 if (cvt.kind() == LF_MFUNCTION) {
932 MemberFunctionRecord mfr;
933 llvm::Error err =
934 TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfr);
935 if (err) {
936 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
937 "Failed to deserialize {1} as MemberFunction: {0}",
938 type.index);
939 return {};
940 }
941 unsigned int type_quals = 0;
942 if (!mfr.ThisType.isNoneType()) {
943 clang::QualType this_type = GetOrCreateClangType(mfr.getThisType());
944 if (!this_type.isNull())
945 type_quals = this_type->getPointeeType().getLocalFastQualifiers();
946 }
947 return CreateFunctionType(mfr.ArgumentList, mfr.ReturnType, mfr.CallConv,
948 type_quals);
949 }
950
951 return {};
952}
953
955 if (type.index.isNoneType())
956 return {};
957
958 lldb::user_id_t uid = toOpaqueUid(type);
959 auto iter = m_uid_to_type.find(uid);
960 if (iter != m_uid_to_type.end())
961 return iter->second;
962
964 m_clang.GetSymbolFile()->GetBackingSymbolFile());
965 PdbIndex &index = pdb->GetIndex();
966 PdbTypeSymId best_type = GetBestPossibleDecl(type, index.tpi());
967
968 clang::QualType qt;
969 if (best_type.index != type.index) {
970 // This is a forward decl. Call GetOrCreate on the full decl, then map the
971 // forward decl id to the full decl QualType.
972 clang::QualType qt = GetOrCreateClangType(best_type);
973 if (qt.isNull())
974 return {};
975 m_uid_to_type[toOpaqueUid(type)] = qt;
976 return qt;
977 }
978
979 // This is either a full decl, or a forward decl with no matching full decl
980 // in the debug info.
981 qt = CreateType(type);
982 if (qt.isNull())
983 return {};
984
985 m_uid_to_type[toOpaqueUid(type)] = qt;
986 if (IsTagRecord(type, index.tpi())) {
987 clang::TagDecl *tag = qt->getAsTagDecl();
988 assert(m_decl_to_status.count(tag) == 0 && "type already created");
989
990 DeclStatus &status = m_decl_to_status[tag];
991 status.uid = uid;
992 status.resolved = false;
993 }
994 return qt;
995}
996
998 clang::QualType qt = GetOrCreateClangType(type);
999 if (qt.isNull())
1000 return {};
1001 return ToCompilerType(qt);
1002}
1003
1005 PdbCompilandSymId func_id, llvm::StringRef func_name, TypeIndex func_ti,
1006 CompilerType func_ct, uint32_t param_count,
1007 clang::StorageClass func_storage, bool is_inline,
1008 clang::DeclContext *parent) {
1009 clang::FunctionDecl *function_decl = nullptr;
1010 if (parent->isRecord()) {
1012 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1013 PdbIndex &index = pdb->GetIndex();
1014 clang::CanQualType parent_qt =
1015 m_clang.getASTContext().getCanonicalTypeDeclType(
1016 llvm::cast<clang::TypeDecl>(parent));
1017 lldb::opaque_compiler_type_t parent_opaque_ty =
1018 ToCompilerType(parent_qt).GetOpaqueQualType();
1019 // FIXME: Remove this workaround.
1020 auto iter = m_cxx_record_map.find(parent_opaque_ty);
1021 if (iter != m_cxx_record_map.end()) {
1022 if (iter->getSecond().contains({func_name, func_ct})) {
1023 return nullptr;
1024 }
1025 }
1026
1027 CVType cvt = index.tpi().getType(func_ti);
1028 MemberFunctionRecord func_record(static_cast<TypeRecordKind>(cvt.kind()));
1029 llvm::Error err =
1030 TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, func_record);
1031 if (err) {
1032 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1033 "Failed to deserialize {1} as MemberFunction: {0}",
1034 func_ti);
1035 return nullptr;
1036 }
1037 TypeIndex class_index = func_record.getClassType();
1038
1039 CVType parent_cvt = index.tpi().getType(class_index);
1040 if (!IsTagRecord(parent_cvt))
1041 return nullptr;
1042 TagRecord tag_record = CVTagRecord::create(parent_cvt).asTag();
1043 // If it's a forward reference, try to get the real TypeIndex.
1044 if (tag_record.isForwardRef()) {
1045 llvm::Expected<TypeIndex> eti =
1046 index.tpi().findFullDeclForForwardRef(class_index);
1047 if (eti) {
1048 CVType resolved_tag_record = index.tpi().getType(*eti);
1049 if (!IsTagRecord(resolved_tag_record))
1050 return nullptr;
1051 tag_record = CVTagRecord::create(resolved_tag_record).asTag();
1052 } else {
1053 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), eti.takeError(),
1054 "failed to find full decl for forward ref: {0}");
1055 }
1056 }
1057
1058 ConstString mangled_name(
1059 pdb->FindMangledFunctionName(func_id).value_or(llvm::StringRef()));
1060
1061 if (!tag_record.FieldList.isSimple()) {
1062 CVType field_list_cvt = index.tpi().getType(tag_record.FieldList);
1063 FieldListRecord field_list;
1064 if (llvm::Error error = TypeDeserializer::deserializeAs<FieldListRecord>(
1065 field_list_cvt, field_list))
1066 llvm::consumeError(std::move(error));
1067 CreateMethodDecl process(index, m_clang, func_ti, function_decl,
1068 parent_opaque_ty, func_name, mangled_name,
1069 func_ct);
1070 if (llvm::Error err = visitMemberRecordStream(field_list.Data, process))
1071 llvm::consumeError(std::move(err));
1072 }
1073
1074 if (!function_decl) {
1075 function_decl = m_clang.AddMethodToCXXRecordType(
1076 parent_opaque_ty, func_name, mangled_name, func_ct,
1077 /*is_virtual=*/false, /*is_static=*/false,
1078 /*is_inline=*/false, /*is_explicit=*/false,
1079 /*is_attr_used=*/false, /*is_artificial=*/false);
1080 }
1081 m_cxx_record_map[parent_opaque_ty].insert({func_name, func_ct});
1082 } else {
1083 function_decl = m_clang.CreateFunctionDeclaration(
1084 parent, OptionalClangModuleID(), func_name, func_ct, func_storage,
1085 is_inline, /*asm_label=*/{});
1086 CreateFunctionParameters(func_id, *function_decl, param_count);
1087 }
1088 return function_decl;
1089}
1090
1092 PdbCompilandSymId inlinesite_id) {
1094 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1095 PdbIndex &index = pdb->GetIndex();
1096 CompilandIndexItem *cii = index.compilands().GetCompiland(inlinesite_id.modi);
1097 CVSymbol sym = cii->m_debug_stream.readSymbolAtOffset(inlinesite_id.offset);
1098 InlineSiteSym inline_site(static_cast<SymbolRecordKind>(sym.kind()));
1099 llvm::Error err =
1100 SymbolDeserializer::deserializeAs<InlineSiteSym>(sym, inline_site);
1101 if (err) {
1102 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1103 "Failed to deserialize {1} as InlineSite: {0}",
1104 inlinesite_id);
1105 return nullptr;
1106 }
1107
1108 // Inlinee is the id index to the function id record that is inlined.
1109 PdbTypeSymId func_id(inline_site.Inlinee, true);
1110 // Look up the function decl by the id index to see if we have created a
1111 // function decl for a different inlinesite that refers the same function.
1112 if (clang::Decl *decl = TryGetDecl(func_id))
1113 return llvm::dyn_cast<clang::FunctionDecl>(decl);
1114 clang::FunctionDecl *function_decl =
1115 CreateFunctionDeclFromId(func_id, inlinesite_id);
1116 if (function_decl == nullptr)
1117 return nullptr;
1118
1119 // Use inline site id in m_decl_to_status because it's expected to be a
1120 // PdbCompilandSymId so that we can parse local variables info after it.
1121 uint64_t inlinesite_uid = toOpaqueUid(inlinesite_id);
1122 DeclStatus status;
1123 status.resolved = true;
1124 status.uid = inlinesite_uid;
1125 m_decl_to_status.insert({function_decl, status});
1126 // Use the index in IPI stream as uid in m_uid_to_decl, because index in IPI
1127 // stream are unique and there could be multiple inline sites (different ids)
1128 // referring the same inline function. This avoid creating multiple same
1129 // inline function delcs.
1130 uint64_t func_uid = toOpaqueUid(func_id);
1131 assert(m_uid_to_decl.count(func_uid) == 0 && "already created");
1132 m_uid_to_decl[func_uid] = function_decl;
1133 return function_decl;
1134}
1135
1136clang::FunctionDecl *
1138 PdbCompilandSymId func_sid) {
1139 if (!func_tid.is_ipi) {
1140 assert(false && "called with non-ipi index");
1141 return nullptr;
1142 }
1143
1145 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1146 PdbIndex &index = pdb->GetIndex();
1147 std::optional<CVType> func_cvt =
1148 index.ipi().typeCollection().tryGetType(func_tid.index);
1149 if (!func_cvt)
1150 return nullptr;
1151 llvm::StringRef func_name;
1152 TypeIndex func_ti;
1153 clang::DeclContext *parent = nullptr;
1154 switch (func_cvt->kind()) {
1155 case LF_MFUNC_ID: {
1156 MemberFuncIdRecord mfr;
1157 llvm::Error err =
1158 TypeDeserializer::deserializeAs<MemberFuncIdRecord>(*func_cvt, mfr);
1159 if (err) {
1160 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1161 "Failed to deserialize {1} (IPI) as MemberFuncId: {0}",
1162 func_tid.index);
1163 return nullptr;
1164 }
1165 func_name = mfr.getName();
1166 func_ti = mfr.getFunctionType();
1167 PdbTypeSymId class_type_id(mfr.ClassType, false);
1168 parent = GetOrCreateClangDeclContextForUid(class_type_id);
1169 break;
1170 }
1171 case LF_FUNC_ID: {
1172 FuncIdRecord fir;
1173 llvm::Error err =
1174 TypeDeserializer::deserializeAs<FuncIdRecord>(*func_cvt, fir);
1175 if (err) {
1176 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1177 "Failed to deserialize {1} (IPI) as FuncId: {0}",
1178 func_tid.index);
1179 return nullptr;
1180 }
1181 func_name = fir.getName();
1182 func_ti = fir.getFunctionType();
1184 if (!fir.ParentScope.isNoneType()) {
1185 CVType parent_cvt = index.ipi().getType(fir.ParentScope);
1186 if (parent_cvt.kind() == LF_STRING_ID) {
1187 StringIdRecord sir;
1188 err = TypeDeserializer::deserializeAs<StringIdRecord>(parent_cvt, sir);
1189 if (err) {
1190 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1191 "Failed to deserialize {1} (IPI) as StringId: {0}",
1192 fir.ParentScope);
1193 return nullptr;
1194 }
1195 parent = GetOrCreateNamespaceDecl(sir.String.data(), *parent);
1196 }
1197 }
1198 break;
1199 }
1200 default:
1201 LLDB_LOG(GetLog(LLDBLog::Symbols), "{0} is not a function type", func_tid);
1202 return nullptr;
1203 }
1204 clang::QualType func_qt = GetOrCreateClangType(func_ti);
1205 if (func_qt.isNull() || !parent)
1206 return nullptr;
1207 CompilerType func_ct = ToCompilerType(func_qt);
1208 uint32_t param_count =
1209 llvm::cast<clang::FunctionProtoType>(func_qt)->getNumParams();
1210 return CreateFunctionDecl(func_sid, func_name, func_ti, func_ct, param_count,
1211 clang::SC_None, true, parent);
1212}
1213
1214clang::FunctionDecl *
1216 if (clang::Decl *decl = TryGetDecl(func_id))
1217 return llvm::dyn_cast<clang::FunctionDecl>(decl);
1218
1219 clang::DeclContext *parent = GetParentClangDeclContext(PdbSymUid(func_id));
1220 if (!parent)
1221 return nullptr;
1222 std::string context_name;
1223 if (clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(parent)) {
1224 context_name = ns->getQualifiedNameAsString();
1225 } else if (clang::TagDecl *tag = llvm::dyn_cast<clang::TagDecl>(parent)) {
1226 context_name = tag->getQualifiedNameAsString();
1227 }
1228
1230 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1231 PdbIndex &index = pdb->GetIndex();
1232 CVSymbol cvs = index.ReadSymbolRecord(func_id);
1233 ProcSym proc(static_cast<SymbolRecordKind>(cvs.kind()));
1234 llvm::Error err = SymbolDeserializer::deserializeAs<ProcSym>(cvs, proc);
1235 if (err) {
1236 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1237 "Failed to deserialize {1} as Proc: {0}", func_id);
1238 return nullptr;
1239 }
1240
1241 PdbTypeSymId type_id(proc.FunctionType);
1242 clang::QualType qt = GetOrCreateClangType(type_id);
1243 if (qt.isNull())
1244 return nullptr;
1245
1246 clang::StorageClass storage = clang::SC_None;
1247 if (proc.Kind == SymbolRecordKind::ProcSym)
1248 storage = clang::SC_Static;
1249
1250 const clang::FunctionProtoType *func_type =
1251 llvm::dyn_cast<clang::FunctionProtoType>(qt);
1252 if (!func_type)
1253 return nullptr;
1254
1255 CompilerType func_ct = ToCompilerType(qt);
1256
1257 llvm::StringRef proc_name = proc.Name;
1258 if (!context_name.empty() && !(proc_name.consume_front(context_name) &&
1259 proc_name.consume_front("::"))) {
1260 // If we have some context, but the function name doesn't start with it, use
1261 // the basename.
1262 MSVCUndecoratedNameParser parser(proc.Name);
1263 llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs(parser.GetSpecifiers());
1264 if (!specs.empty())
1265 proc_name = specs.back().GetBaseName();
1266 }
1267 clang::FunctionDecl *function_decl =
1268 CreateFunctionDecl(func_id, proc_name, proc.FunctionType, func_ct,
1269 func_type->getNumParams(), storage, false, parent);
1270 if (function_decl == nullptr)
1271 return nullptr;
1272
1273 assert(m_uid_to_decl.count(toOpaqueUid(func_id)) == 0 && "already created");
1274 m_uid_to_decl[toOpaqueUid(func_id)] = function_decl;
1275 DeclStatus status;
1276 status.resolved = true;
1277 status.uid = toOpaqueUid(func_id);
1278 m_decl_to_status.insert({function_decl, status});
1279
1280 return function_decl;
1281}
1282
1286
1291
1295
1297 PdbCompilandSymId var_id) {
1298 GetOrCreateVariableDecl(scope_id, var_id);
1299}
1300
1304
1306 PdbCompilandSymId func_id, clang::FunctionDecl &function_decl,
1307 uint32_t param_count) {
1309 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1310 PdbIndex &index = pdb->GetIndex();
1311 CompilandIndexItem *cii = index.compilands().GetCompiland(func_id.modi);
1312 CVSymbolArray scope =
1313 cii->m_debug_stream.getSymbolArrayForScope(func_id.offset);
1314
1315 scope.drop_front();
1316 auto begin = scope.begin();
1317 auto end = scope.end();
1318 std::vector<clang::ParmVarDecl *> params;
1319 for (uint32_t i = 0; i < param_count && begin != end;) {
1320 uint32_t record_offset = begin.offset();
1321 PdbCompilandSymId sym_id(func_id.modi, record_offset);
1322 CVSymbol sym = *begin++;
1323
1324 TypeIndex param_type;
1325 llvm::StringRef param_name;
1326 switch (sym.kind()) {
1327 case S_REGREL32: {
1328 RegRelativeSym reg(SymbolRecordKind::RegRelativeSym);
1329 llvm::Error err =
1330 SymbolDeserializer::deserializeAs<RegRelativeSym>(sym, reg);
1331 if (err) {
1332 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1333 "Failed to deserialize {1} as RegRelative: {0}", sym_id);
1334 return;
1335 }
1336 param_type = reg.Type;
1337 param_name = reg.Name;
1338 break;
1339 }
1340 case S_REGREL32_INDIR: {
1341 RegRelativeIndirSym reg(SymbolRecordKind::RegRelativeIndirSym);
1342 llvm::Error err =
1343 SymbolDeserializer::deserializeAs<RegRelativeIndirSym>(sym, reg);
1344 if (err) {
1345 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1346 "Failed to deserialize {1} as RegRelativeIndir: {0}",
1347 sym_id);
1348 return;
1349 }
1350 param_type = reg.Type;
1351 param_name = reg.Name;
1352 break;
1353 }
1354 case S_REGISTER: {
1355 RegisterSym reg(SymbolRecordKind::RegisterSym);
1356 llvm::Error err =
1357 SymbolDeserializer::deserializeAs<RegisterSym>(sym, reg);
1358 if (err) {
1359 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1360 "Failed to deserialize {1} as Register: {0}", sym_id);
1361 return;
1362 }
1363 param_type = reg.Index;
1364 param_name = reg.Name;
1365 break;
1366 }
1367 case S_LOCAL: {
1368 LocalSym local(SymbolRecordKind::LocalSym);
1369 llvm::Error err = SymbolDeserializer::deserializeAs<LocalSym>(sym, local);
1370 if (err) {
1371 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1372 "Failed to deserialize {1} as Local: {0}", sym_id);
1373 return;
1374 }
1375 if ((local.Flags & LocalSymFlags::IsParameter) == LocalSymFlags::None)
1376 continue;
1377 param_type = local.Type;
1378 param_name = local.Name;
1379 break;
1380 }
1381 case S_BLOCK32:
1382 case S_INLINESITE:
1383 case S_INLINESITE2:
1384 // All parameters should come before the first block/inlinesite. If that
1385 // isn't the case, then perhaps this is bad debug info that doesn't
1386 // contain information about all parameters.
1387 return;
1388 default:
1389 continue;
1390 }
1391
1392 PdbCompilandSymId param_uid(func_id.modi, record_offset);
1393 clang::QualType qt = GetOrCreateClangType(param_type);
1394 if (qt.isNull())
1395 return;
1396
1397 CompilerType param_type_ct = m_clang.GetType(qt);
1398 clang::ParmVarDecl *param = m_clang.CreateParameterDeclaration(
1399 &function_decl, OptionalClangModuleID(), param_name.str().c_str(),
1400 param_type_ct, clang::SC_None, true);
1401
1402 assert(m_uid_to_decl.count(toOpaqueUid(param_uid)) == 0 &&
1403 "already created");
1404 m_uid_to_decl[toOpaqueUid(param_uid)] = param;
1405 params.push_back(param);
1406 ++i;
1407 }
1408
1409 if (!params.empty() && params.size() == param_count)
1410 function_decl.setParams(params);
1411}
1412
1414 const EnumRecord &er) {
1415 clang::DeclContext *decl_context = nullptr;
1416 std::string uname;
1417 std::tie(decl_context, uname) = CreateDeclInfoForType(er, id.index);
1418 if (!decl_context)
1419 return {};
1420
1421 clang::QualType underlying_type = GetOrCreateClangType(er.UnderlyingType);
1422 if (underlying_type.isNull())
1423 return {};
1424
1425 Declaration declaration;
1426 CompilerType enum_ct = m_clang.CreateEnumerationType(
1427 uname, decl_context, OptionalClangModuleID(), declaration,
1428 ToCompilerType(underlying_type), er.isScoped());
1429
1432
1433 return clang::QualType::getFromOpaquePtr(enum_ct.GetOpaqueQualType());
1434}
1435
1436clang::QualType PdbAstBuilderClang::CreateArrayType(const ArrayRecord &ar) {
1437 clang::QualType element_type = GetOrCreateClangType(ar.ElementType);
1439
1441 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1442 PdbIndex &index = pdb->GetIndex();
1443 uint64_t element_size = GetSizeOfType({ar.ElementType}, index.tpi());
1444 if (element_type.isNull() || element_size == 0)
1445 return {};
1446 uint64_t element_count = ar.Size / element_size;
1447
1448 CompilerType array_ct = m_clang.CreateArrayType(ToCompilerType(element_type),
1449 element_count, false);
1450 return clang::QualType::getFromOpaquePtr(array_ct.GetOpaqueQualType());
1451}
1452
1454 TypeIndex args_type_idx, TypeIndex return_type_idx,
1455 llvm::codeview::CallingConvention calling_convention,
1456 unsigned int type_quals) {
1458 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1459 PdbIndex &index = pdb->GetIndex();
1460 TpiStream &stream = index.tpi();
1461 CVType args_cvt = stream.getType(args_type_idx);
1462 ArgListRecord args;
1463 llvm::Error err =
1464 TypeDeserializer::deserializeAs<ArgListRecord>(args_cvt, args);
1465 if (err) {
1466 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1467 "Failed to deserialize {1} as ArgList: {0}", args_type_idx);
1468 return {};
1469 }
1470
1471 llvm::ArrayRef<TypeIndex> arg_indices = llvm::ArrayRef(args.ArgIndices);
1472 bool is_variadic = IsCVarArgsFunction(arg_indices);
1473 if (is_variadic)
1474 arg_indices = arg_indices.drop_back();
1475
1476 std::vector<CompilerType> arg_types;
1477 arg_types.reserve(arg_indices.size());
1478
1479 for (TypeIndex arg_index : arg_indices) {
1480 clang::QualType arg_type = GetOrCreateClangType(arg_index);
1481 if (arg_type.isNull())
1482 continue;
1483 arg_types.push_back(ToCompilerType(arg_type));
1484 }
1485
1486 clang::QualType return_type = GetOrCreateClangType(return_type_idx);
1487 if (return_type.isNull())
1488 return {};
1489
1490 std::optional<clang::CallingConv> cc =
1491 TranslateCallingConvention(calling_convention);
1492 if (!cc)
1493 return {};
1494
1495 CompilerType return_ct = ToCompilerType(return_type);
1496 CompilerType func_sig_ast_type = m_clang.CreateFunctionType(
1497 return_ct, arg_types, is_variadic, type_quals, *cc);
1498
1499 return clang::QualType::getFromOpaquePtr(
1500 func_sig_ast_type.GetOpaqueQualType());
1501}
1502
1503static bool isTagDecl(clang::DeclContext &context) {
1504 return llvm::isa<clang::TagDecl>(&context);
1505}
1506
1507static bool isFunctionDecl(clang::DeclContext &context) {
1508 return llvm::isa<clang::FunctionDecl>(&context);
1509}
1510
1511static bool isBlockDecl(clang::DeclContext &context) {
1512 return llvm::isa<clang::BlockDecl>(&context);
1513}
1514
1515void PdbAstBuilderClang::ParseNamespace(clang::DeclContext &context) {
1516 clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(&context);
1517 if (m_parsed_namespaces.contains(ns))
1518 return;
1519 std::string qname = ns->getQualifiedNameAsString();
1521 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1522 PdbIndex &index = pdb->GetIndex();
1523 TypeIndex ti{index.tpi().TypeIndexBegin()};
1524 for (const CVType &cvt : index.tpi().typeArray()) {
1525 PdbTypeSymId tid{ti};
1526 ++ti;
1527
1528 if (!IsTagRecord(cvt))
1529 continue;
1530
1532
1533 // Call CreateDeclInfoForType unconditionally so that the namespace info
1534 // gets created. But only call CreateRecordType if the namespace name
1535 // matches.
1536 clang::DeclContext *context = nullptr;
1537 std::string uname;
1538 std::tie(context, uname) = CreateDeclInfoForType(tag.asTag(), tid.index);
1539 if (!context || !context->isNamespace())
1540 continue;
1541
1542 clang::NamespaceDecl *ns = llvm::cast<clang::NamespaceDecl>(context);
1543 llvm::StringRef ns_name = ns->getName();
1544 if (ns_name.starts_with(qname)) {
1545 ns_name = ns_name.drop_front(qname.size());
1546 if (ns_name.starts_with("::"))
1548 }
1549 }
1551 m_parsed_namespaces.insert(ns);
1552}
1553
1555 llvm::call_once(m_parse_all_types, [this]() {
1557 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1558 PdbIndex &index = pdb->GetIndex();
1559 TypeIndex ti{index.tpi().TypeIndexBegin()};
1560 for (const CVType &cvt : index.tpi().typeArray()) {
1561 PdbTypeSymId tid{ti};
1562 ++ti;
1563
1564 if (!IsTagRecord(cvt))
1565 continue;
1566
1568 }
1569 });
1570}
1571
1573 llvm::call_once(m_parse_functions_and_non_local_vars, [this]() {
1575 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1576 PdbIndex &index = pdb->GetIndex();
1577 uint32_t module_count = index.dbi().modules().getModuleCount();
1578 for (uint16_t modi = 0; modi < module_count; ++modi) {
1580 const CVSymbolArray &symbols = cii.m_debug_stream.getSymbolArray();
1581 auto iter = symbols.begin();
1582 while (iter != symbols.end()) {
1583 PdbCompilandSymId sym_id{modi, iter.offset()};
1584
1585 switch (iter->kind()) {
1586 case S_GPROC32:
1587 case S_LPROC32:
1589 iter = symbols.at(getScopeEndOffset(*iter));
1590 break;
1591 case S_GDATA32:
1592 case S_GTHREAD32:
1593 case S_LDATA32:
1594 case S_LTHREAD32:
1596 ++iter;
1597 break;
1598 default:
1599 ++iter;
1600 continue;
1601 }
1602 }
1603 }
1604 });
1605}
1606
1607static CVSymbolArray skipFunctionParameters(clang::Decl &decl,
1608 const CVSymbolArray &symbols) {
1609 clang::FunctionDecl *func_decl = llvm::dyn_cast<clang::FunctionDecl>(&decl);
1610 if (!func_decl)
1611 return symbols;
1612 unsigned int params = func_decl->getNumParams();
1613 if (params == 0)
1614 return symbols;
1615
1616 CVSymbolArray result = symbols;
1617
1618 while (!result.empty()) {
1619 if (params == 0)
1620 return result;
1621
1622 CVSymbol sym = *result.begin();
1623 result.drop_front();
1624
1625 if (!isLocalVariableType(sym.kind()))
1626 continue;
1627
1628 --params;
1629 }
1630 return result;
1631}
1632
1635 m_clang.GetSymbolFile()->GetBackingSymbolFile());
1636 PdbIndex &index = pdb->GetIndex();
1637 CVSymbol sym = index.ReadSymbolRecord(block_id);
1638 if (sym.kind() != S_GPROC32 && sym.kind() != S_LPROC32 &&
1639 sym.kind() != S_BLOCK32 && sym.kind() != S_INLINESITE) {
1640 assert(false && "called on non-block");
1641 return;
1642 }
1643 CompilandIndexItem &cii =
1644 index.compilands().GetOrCreateCompiland(block_id.modi);
1645 CVSymbolArray symbols =
1646 cii.m_debug_stream.getSymbolArrayForScope(block_id.offset);
1647
1648 // Function parameters should already have been created when the function was
1649 // parsed.
1650 if (sym.kind() == S_GPROC32 || sym.kind() == S_LPROC32)
1651 symbols =
1652 skipFunctionParameters(*m_uid_to_decl[toOpaqueUid(block_id)], symbols);
1653
1654 symbols.drop_front();
1655 auto begin = symbols.begin();
1656 while (begin != symbols.end()) {
1657 PdbCompilandSymId child_sym_id(block_id.modi, begin.offset());
1658 GetOrCreateSymbolForId(child_sym_id);
1659 if (begin->kind() == S_BLOCK32 || begin->kind() == S_INLINESITE) {
1660 ParseBlockChildren(child_sym_id);
1661 begin = symbols.at(getScopeEndOffset(*begin));
1662 }
1663 ++begin;
1664 }
1665}
1666
1668 clang::DeclContext &context) {
1669
1670 clang::Decl *decl = clang::Decl::castFromDeclContext(&context);
1671 if (!decl) {
1672 assert(false);
1673 return;
1674 }
1675
1676 auto iter = m_decl_to_status.find(decl);
1677 if (iter == m_decl_to_status.end()) {
1678 assert(false && "cannot parse unknown decl");
1679 return;
1680 }
1681
1682 if (auto *tag = llvm::dyn_cast<clang::TagDecl>(&context)) {
1683 CompleteTagDecl(*tag);
1684 return;
1685 }
1686
1687 if (isFunctionDecl(context) || isBlockDecl(context)) {
1688 PdbCompilandSymId block_id = PdbSymUid(iter->second.uid).asCompilandSym();
1689 ParseBlockChildren(block_id);
1690 }
1691}
1692
1694 clang::DeclContext *dc = FromCompilerDeclContext(context);
1695 if (!dc)
1696 return;
1697
1698 // Namespaces aren't explicitly represented in the debug info, and the only
1699 // way to parse them is to parse all type info, demangling every single type
1700 // and trying to reconstruct the DeclContext hierarchy this way. Since this
1701 // is an expensive operation, we have to special case it so that we do other
1702 // work (such as parsing the items that appear within the namespaces) at the
1703 // same time.
1704 if (dc->isTranslationUnit()) {
1705 ParseAllTypes();
1707 return;
1708 }
1709
1710 if (dc->isNamespace()) {
1711 ParseNamespace(*dc);
1712 return;
1713 }
1714
1715 if (isTagDecl(*dc) || isFunctionDecl(*dc) || isBlockDecl(*dc)) {
1717 return;
1718 }
1719}
1720
1722 return m_clang.GetCompilerDecl(decl);
1723}
1724
1726 return m_clang.GetType(qt);
1727}
1728
1732
1734PdbAstBuilderClang::ToCompilerDeclContext(clang::DeclContext *context) {
1735 return m_clang.CreateDeclContext(context);
1736}
1737
1739 if (decl.GetTypeSystem() != nullptr)
1740 return ClangUtil::GetDecl(decl);
1741 return nullptr;
1742}
1743
1744clang::DeclContext *
1746 return static_cast<clang::DeclContext *>(context.GetOpaqueDeclContext());
1747}
1748
1749void PdbAstBuilderClang::Dump(Stream &stream, llvm::StringRef filter,
1750 bool show_color) {
1751 m_clang.Dump(stream.AsRawOstream(), filter, show_color);
1752}
1753
1756 llvm::StringRef name) {
1757 clang::DeclContext *parent = FromCompilerDeclContext(parent_ctx);
1758 NamespaceSet *set;
1759
1760 if (parent) {
1761 auto it = m_parent_to_namespaces.find(parent);
1762 if (it == m_parent_to_namespaces.end())
1763 return {};
1764
1765 set = &it->second;
1766 } else {
1767 // In this case, search through all known namespaces
1768 set = &m_known_namespaces;
1769 }
1770 assert(set);
1771
1772 for (clang::NamespaceDecl *namespace_decl : *set)
1773 if (namespace_decl->getName() == name)
1774 return ToCompilerDeclContext(namespace_decl);
1775
1776 for (clang::NamespaceDecl *namespace_decl : *set)
1777 if (namespace_decl->isAnonymousNamespace())
1778 return FindNamespaceDecl(ToCompilerDeclContext(namespace_decl), name);
1779
1780 return {};
1781}
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::QualType CreateType(PdbTypeSymId type)
clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array)
llvm::DenseMap< clang::Decl *, DeclStatus > m_decl_to_status
llvm::DenseMap< lldb::opaque_compiler_type_t, llvm::SmallSet< std::pair< llvm::StringRef, CompilerType >, 8 > > m_cxx_record_map
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