LLDB  mainline
PdbAstBuilder.cpp
Go to the documentation of this file.
1 #include "PdbAstBuilder.h"
2 
3 #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
4 #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
5 #include "llvm/DebugInfo/CodeView/RecordName.h"
6 #include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
7 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
8 #include "llvm/DebugInfo/CodeView/SymbolRecordHelpers.h"
9 #include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
10 #include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
11 #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
12 #include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
13 #include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
14 #include "llvm/DebugInfo/PDB/Native/TpiStream.h"
15 #include "llvm/Demangle/MicrosoftDemangle.h"
16 
21 #include "lldb/Core/Module.h"
22 #include "lldb/Symbol/ObjectFile.h"
24 #include "PdbUtil.h"
25 #include "UdtRecordCompleter.h"
26 #include "SymbolFileNativePDB.h"
27 
28 using namespace lldb_private;
29 using namespace lldb_private::npdb;
30 using namespace llvm::codeview;
31 using namespace llvm::pdb;
32 
33 namespace {
34 struct CreateMethodDecl : public TypeVisitorCallbacks {
35  CreateMethodDecl(PdbIndex &m_index, TypeSystemClang &m_clang,
36  TypeIndex func_type_index,
37  clang::FunctionDecl *&function_decl,
39  llvm::StringRef proc_name, CompilerType func_ct)
40  : m_index(m_index), m_clang(m_clang), func_type_index(func_type_index),
41  function_decl(function_decl), parent_ty(parent_ty),
42  proc_name(proc_name), func_ct(func_ct) {}
43  PdbIndex &m_index;
44  TypeSystemClang &m_clang;
45  TypeIndex func_type_index;
46  clang::FunctionDecl *&function_decl;
48  llvm::StringRef proc_name;
49  CompilerType func_ct;
50 
51  llvm::Error visitKnownMember(CVMemberRecord &cvr,
52  OverloadedMethodRecord &overloaded) override {
53  TypeIndex method_list_idx = overloaded.MethodList;
54 
55  CVType method_list_type = m_index.tpi().getType(method_list_idx);
56  assert(method_list_type.kind() == LF_METHODLIST);
57 
58  MethodOverloadListRecord method_list;
59  llvm::cantFail(TypeDeserializer::deserializeAs<MethodOverloadListRecord>(
60  method_list_type, method_list));
61 
62  for (const OneMethodRecord &method : method_list.Methods) {
63  if (method.getType().getIndex() == func_type_index.getIndex())
64  AddMethod(overloaded.Name, method.getAccess(), method.getOptions(),
65  method.Attrs);
66  }
67 
68  return llvm::Error::success();
69  }
70 
71  llvm::Error visitKnownMember(CVMemberRecord &cvr,
72  OneMethodRecord &record) override {
73  AddMethod(record.getName(), record.getAccess(), record.getOptions(),
74  record.Attrs);
75  return llvm::Error::success();
76  }
77 
78  void AddMethod(llvm::StringRef name, MemberAccess access,
79  MethodOptions options, MemberAttributes attrs) {
80  if (name != proc_name || function_decl)
81  return;
82  lldb::AccessType access_type = TranslateMemberAccess(access);
83  bool is_virtual = attrs.isVirtual();
84  bool is_static = attrs.isStatic();
85  bool is_artificial = (options & MethodOptions::CompilerGenerated) ==
86  MethodOptions::CompilerGenerated;
87  function_decl = m_clang.AddMethodToCXXRecordType(
88  parent_ty, proc_name,
89  /*mangled_name=*/nullptr, func_ct, /*access=*/access_type,
90  /*is_virtual=*/is_virtual, /*is_static=*/is_static,
91  /*is_inline=*/false, /*is_explicit=*/false,
92  /*is_attr_used=*/false, /*is_artificial=*/is_artificial);
93  }
94 };
95 } // namespace
96 
97 static clang::TagTypeKind TranslateUdtKind(const TagRecord &cr) {
98  switch (cr.Kind) {
99  case TypeRecordKind::Class:
100  return clang::TTK_Class;
101  case TypeRecordKind::Struct:
102  return clang::TTK_Struct;
103  case TypeRecordKind::Union:
104  return clang::TTK_Union;
105  case TypeRecordKind::Interface:
106  return clang::TTK_Interface;
107  case TypeRecordKind::Enum:
108  return clang::TTK_Enum;
109  default:
110  lldbassert(false && "Invalid tag record kind!");
111  return clang::TTK_Struct;
112  }
113 }
114 
115 static bool IsCVarArgsFunction(llvm::ArrayRef<TypeIndex> args) {
116  if (args.empty())
117  return false;
118  return args.back() == TypeIndex::None();
119 }
120 
121 static bool
122 AnyScopesHaveTemplateParams(llvm::ArrayRef<llvm::ms_demangle::Node *> scopes) {
123  for (llvm::ms_demangle::Node *n : scopes) {
124  auto *idn = static_cast<llvm::ms_demangle::IdentifierNode *>(n);
125  if (idn->TemplateParams)
126  return true;
127  }
128  return false;
129 }
130 
131 static llvm::Optional<clang::CallingConv>
132 TranslateCallingConvention(llvm::codeview::CallingConvention conv) {
133  using CC = llvm::codeview::CallingConvention;
134  switch (conv) {
135 
136  case CC::NearC:
137  case CC::FarC:
138  return clang::CallingConv::CC_C;
139  case CC::NearPascal:
140  case CC::FarPascal:
141  return clang::CallingConv::CC_X86Pascal;
142  case CC::NearFast:
143  case CC::FarFast:
144  return clang::CallingConv::CC_X86FastCall;
145  case CC::NearStdCall:
146  case CC::FarStdCall:
147  return clang::CallingConv::CC_X86StdCall;
148  case CC::ThisCall:
149  return clang::CallingConv::CC_X86ThisCall;
150  case CC::NearVector:
151  return clang::CallingConv::CC_X86VectorCall;
152  default:
153  return std::nullopt;
154  }
155 }
156 
157 static bool IsAnonymousNamespaceName(llvm::StringRef name) {
158  return name == "`anonymous namespace'" || name == "`anonymous-namespace'";
159 }
160 
162 
165 }
166 
167 std::pair<clang::DeclContext *, std::string>
168 PdbAstBuilder::CreateDeclInfoForType(const TagRecord &record, TypeIndex ti) {
169  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
171  // FIXME: Move this to GetDeclContextContainingUID.
172  if (!record.hasUniqueName())
173  return CreateDeclInfoForUndecoratedName(record.Name);
174 
175  llvm::ms_demangle::Demangler demangler;
176  StringView sv(record.UniqueName.begin(), record.UniqueName.size());
177  llvm::ms_demangle::TagTypeNode *ttn = demangler.parseTagUniqueName(sv);
178  if (demangler.Error)
179  return {m_clang.GetTranslationUnitDecl(), std::string(record.UniqueName)};
180 
181  llvm::ms_demangle::IdentifierNode *idn =
182  ttn->QualifiedName->getUnqualifiedIdentifier();
183  std::string uname = idn->toString(llvm::ms_demangle::OF_NoTagSpecifier);
184 
185  llvm::ms_demangle::NodeArrayNode *name_components =
186  ttn->QualifiedName->Components;
187  llvm::ArrayRef<llvm::ms_demangle::Node *> scopes(name_components->Nodes,
188  name_components->Count - 1);
189 
190  clang::DeclContext *context = m_clang.GetTranslationUnitDecl();
191 
192  // If this type doesn't have a parent type in the debug info, then the best we
193  // can do is to say that it's either a series of namespaces (if the scope is
194  // non-empty), or the translation unit (if the scope is empty).
195  llvm::Optional<TypeIndex> parent_index = pdb->GetParentType(ti);
196  if (!parent_index) {
197  if (scopes.empty())
198  return {context, uname};
199 
200  // If there is no parent in the debug info, but some of the scopes have
201  // template params, then this is a case of bad debug info. See, for
202  // example, llvm.org/pr39607. We don't want to create an ambiguity between
203  // a NamespaceDecl and a CXXRecordDecl, so instead we create a class at
204  // global scope with the fully qualified name.
205  if (AnyScopesHaveTemplateParams(scopes))
206  return {context, std::string(record.Name)};
207 
208  for (llvm::ms_demangle::Node *scope : scopes) {
209  auto *nii = static_cast<llvm::ms_demangle::NamedIdentifierNode *>(scope);
210  std::string str = nii->toString();
211  context = GetOrCreateNamespaceDecl(str.c_str(), *context);
212  }
213  return {context, uname};
214  }
215 
216  // Otherwise, all we need to do is get the parent type of this type and
217  // recurse into our lazy type creation / AST reconstruction logic to get an
218  // LLDB TypeSP for the parent. This will cause the AST to automatically get
219  // the right DeclContext created for any parent.
220  clang::QualType parent_qt = GetOrCreateType(*parent_index);
221  if (parent_qt.isNull())
222  return {nullptr, ""};
223 
224  context = clang::TagDecl::castToDeclContext(parent_qt->getAsTagDecl());
225  return {context, uname};
226 }
227 
228 static bool isLocalVariableType(SymbolKind K) {
229  switch (K) {
230  case S_REGISTER:
231  case S_REGREL32:
232  case S_LOCAL:
233  return true;
234  default:
235  break;
236  }
237  return false;
238 }
239 
241  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
243  PdbIndex &index = pdb->GetIndex();
244  CVSymbol cvs = index.ReadSymbolRecord(id);
245 
246  if (isLocalVariableType(cvs.kind())) {
247  clang::DeclContext *scope = GetParentDeclContext(id);
248  if (!scope)
249  return nullptr;
250  clang::Decl *scope_decl = clang::Decl::castFromDeclContext(scope);
251  PdbCompilandSymId scope_id =
252  PdbSymUid(m_decl_to_status[scope_decl].uid).asCompilandSym();
253  return GetOrCreateVariableDecl(scope_id, id);
254  }
255 
256  switch (cvs.kind()) {
257  case S_GPROC32:
258  case S_LPROC32:
259  return GetOrCreateFunctionDecl(id);
260  case S_GDATA32:
261  case S_LDATA32:
262  case S_GTHREAD32:
263  case S_CONSTANT:
264  // global variable
265  return nullptr;
266  case S_BLOCK32:
267  return GetOrCreateBlockDecl(id);
268  case S_INLINESITE:
270  default:
271  return nullptr;
272  }
273 }
274 
275 llvm::Optional<CompilerDecl> PdbAstBuilder::GetOrCreateDeclForUid(PdbSymUid uid) {
276  if (clang::Decl *result = TryGetDecl(uid))
277  return ToCompilerDecl(*result);
278 
279  clang::Decl *result = nullptr;
280  switch (uid.kind()) {
282  result = GetOrCreateSymbolForId(uid.asCompilandSym());
283  break;
284  case PdbSymUidKind::Type: {
285  clang::QualType qt = GetOrCreateType(uid.asTypeSym());
286  if (qt.isNull())
287  return std::nullopt;
288  if (auto *tag = qt->getAsTagDecl()) {
289  result = tag;
290  break;
291  }
292  return std::nullopt;
293  }
294  default:
295  return std::nullopt;
296  }
297 
298  if (!result)
299  return std::nullopt;
300  m_uid_to_decl[toOpaqueUid(uid)] = result;
301  return ToCompilerDecl(*result);
302 }
303 
305  if (uid.kind() == PdbSymUidKind::CompilandSym) {
306  if (uid.asCompilandSym().offset == 0)
308  }
309  auto option = GetOrCreateDeclForUid(uid);
310  if (!option)
311  return nullptr;
312  clang::Decl *decl = FromCompilerDecl(*option);
313  if (!decl)
314  return nullptr;
315 
316  return clang::Decl::castToDeclContext(decl);
317 }
318 
319 std::pair<clang::DeclContext *, std::string>
321  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
323  PdbIndex &index = pdb->GetIndex();
324  MSVCUndecoratedNameParser parser(name);
325  llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs = parser.GetSpecifiers();
326 
328 
329  llvm::StringRef uname = specs.back().GetBaseName();
330  specs = specs.drop_back();
331  if (specs.empty())
332  return {context, std::string(name)};
333 
334  llvm::StringRef scope_name = specs.back().GetFullName();
335 
336  // It might be a class name, try that first.
337  std::vector<TypeIndex> types = index.tpi().findRecordsByName(scope_name);
338  while (!types.empty()) {
339  clang::QualType qt = GetOrCreateType(types.back());
340  if (qt.isNull())
341  continue;
342  clang::TagDecl *tag = qt->getAsTagDecl();
343  if (tag)
344  return {clang::TagDecl::castToDeclContext(tag), std::string(uname)};
345  types.pop_back();
346  }
347 
348  // If that fails, treat it as a series of namespaces.
349  for (const MSVCUndecoratedNameSpecifier &spec : specs) {
350  std::string ns_name = spec.GetBaseName().str();
351  context = GetOrCreateNamespaceDecl(ns_name.c_str(), *context);
352  }
353  return {context, std::string(uname)};
354 }
355 
357  // We must do this *without* calling GetOrCreate on the current uid, as
358  // that would be an infinite recursion.
359  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
361  PdbIndex& index = pdb->GetIndex();
362  switch (uid.kind()) {
364  llvm::Optional<PdbCompilandSymId> scope =
365  pdb->FindSymbolScope(uid.asCompilandSym());
366  if (scope)
367  return GetOrCreateDeclContextForUid(*scope);
368 
369  CVSymbol sym = index.ReadSymbolRecord(uid.asCompilandSym());
370  return CreateDeclInfoForUndecoratedName(getSymbolName(sym)).first;
371  }
372  case PdbSymUidKind::Type: {
373  // It could be a namespace, class, or global. We don't support nested
374  // functions yet. Anyway, we just need to consult the parent type map.
375  PdbTypeSymId type_id = uid.asTypeSym();
376  llvm::Optional<TypeIndex> parent_index = pdb->GetParentType(type_id.index);
377  if (!parent_index)
379  return GetOrCreateDeclContextForUid(PdbTypeSymId(*parent_index));
380  }
382  // In this case the parent DeclContext is the one for the class that this
383  // member is inside of.
384  break;
386  // If this refers to a compiland symbol, just recurse in with that symbol.
387  // The only other possibilities are S_CONSTANT and S_UDT, in which case we
388  // need to parse the undecorated name to figure out the scope, then look
389  // that up in the TPI stream. If it's found, it's a type, othewrise it's
390  // a series of namespaces.
391  // FIXME: do this.
392  CVSymbol global = index.ReadSymbolRecord(uid.asGlobalSym());
393  switch (global.kind()) {
394  case SymbolKind::S_GDATA32:
395  case SymbolKind::S_LDATA32:
396  return CreateDeclInfoForUndecoratedName(getSymbolName(global)).first;;
397  case SymbolKind::S_PROCREF:
398  case SymbolKind::S_LPROCREF: {
399  ProcRefSym ref{global.kind()};
400  llvm::cantFail(
401  SymbolDeserializer::deserializeAs<ProcRefSym>(global, ref));
402  PdbCompilandSymId cu_sym_id{ref.modi(), ref.SymOffset};
403  return GetParentDeclContext(cu_sym_id);
404  }
405  case SymbolKind::S_CONSTANT:
406  case SymbolKind::S_UDT:
407  return CreateDeclInfoForUndecoratedName(getSymbolName(global)).first;
408  default:
409  break;
410  }
411  break;
412  }
413  default:
414  break;
415  }
417 }
418 
419 bool PdbAstBuilder::CompleteType(clang::QualType qt) {
420  if (qt.isNull())
421  return false;
422  clang::TagDecl *tag = qt->getAsTagDecl();
423  if (qt->isArrayType()) {
424  const clang::Type *element_type = qt->getArrayElementTypeNoTypeQual();
425  tag = element_type->getAsTagDecl();
426  }
427  if (!tag)
428  return false;
429 
430  return CompleteTagDecl(*tag);
431 }
432 
433 bool PdbAstBuilder::CompleteTagDecl(clang::TagDecl &tag) {
434  // If this is not in our map, it's an error.
435  auto status_iter = m_decl_to_status.find(&tag);
436  lldbassert(status_iter != m_decl_to_status.end());
437 
438  // If it's already complete, just return.
439  DeclStatus &status = status_iter->second;
440  if (status.resolved)
441  return true;
442 
443  PdbTypeSymId type_id = PdbSymUid(status.uid).asTypeSym();
444  PdbIndex &index = static_cast<SymbolFileNativePDB *>(
446  ->GetIndex();
447  lldbassert(IsTagRecord(type_id, index.tpi()));
448 
449  clang::QualType tag_qt = m_clang.getASTContext().getTypeDeclType(&tag);
450  TypeSystemClang::SetHasExternalStorage(tag_qt.getAsOpaquePtr(), false);
451 
452  TypeIndex tag_ti = type_id.index;
453  CVType cvt = index.tpi().getType(tag_ti);
454  if (cvt.kind() == LF_MODIFIER)
455  tag_ti = LookThroughModifierRecord(cvt);
456 
457  PdbTypeSymId best_ti = GetBestPossibleDecl(tag_ti, index.tpi());
458  cvt = index.tpi().getType(best_ti.index);
459  lldbassert(IsTagRecord(cvt));
460 
461  if (IsForwardRefUdt(cvt)) {
462  // If we can't find a full decl for this forward ref anywhere in the debug
463  // info, then we have no way to complete it.
464  return false;
465  }
466 
467  TypeIndex field_list_ti = GetFieldListIndex(cvt);
468  CVType field_list_cvt = index.tpi().getType(field_list_ti);
469  if (field_list_cvt.kind() != LF_FIELDLIST)
470  return false;
471  FieldListRecord field_list;
472  if (llvm::Error error = TypeDeserializer::deserializeAs<FieldListRecord>(
473  field_list_cvt, field_list))
474  llvm::consumeError(std::move(error));
475 
476  // Visit all members of this class, then perform any finalization necessary
477  // to complete the class.
478  CompilerType ct = ToCompilerType(tag_qt);
479  UdtRecordCompleter completer(best_ti, ct, tag, *this, index, m_decl_to_status,
482  llvm::codeview::visitMemberRecordStream(field_list.Data, completer);
483  completer.complete();
484 
485  m_decl_to_status[&tag].resolved = true;
486  if (error) {
487  llvm::consumeError(std::move(error));
488  return false;
489  }
490  return true;
491 }
492 
494  if (ti == TypeIndex::NullptrT())
496 
497  if (ti.getSimpleMode() != SimpleTypeMode::Direct) {
498  clang::QualType direct_type = GetOrCreateType(ti.makeDirect());
499  if (direct_type.isNull())
500  return {};
501  return m_clang.getASTContext().getPointerType(direct_type);
502  }
503 
504  if (ti.getSimpleKind() == SimpleTypeKind::NotTranslated)
505  return {};
506 
507  lldb::BasicType bt = GetCompilerTypeForSimpleKind(ti.getSimpleKind());
508  if (bt == lldb::eBasicTypeInvalid)
509  return {};
510 
511  return GetBasicType(bt);
512 }
513 
514 clang::QualType PdbAstBuilder::CreatePointerType(const PointerRecord &pointer) {
515  clang::QualType pointee_type = GetOrCreateType(pointer.ReferentType);
516 
517  // This can happen for pointers to LF_VTSHAPE records, which we shouldn't
518  // create in the AST.
519  if (pointee_type.isNull())
520  return {};
521 
522  if (pointer.isPointerToMember()) {
523  MemberPointerInfo mpi = pointer.getMemberInfo();
524  clang::QualType class_type = GetOrCreateType(mpi.ContainingType);
525  if (class_type.isNull())
526  return {};
527  if (clang::TagDecl *tag = class_type->getAsTagDecl()) {
528  clang::MSInheritanceAttr::Spelling spelling;
529  switch (mpi.Representation) {
530  case llvm::codeview::PointerToMemberRepresentation::SingleInheritanceData:
531  case llvm::codeview::PointerToMemberRepresentation::
532  SingleInheritanceFunction:
533  spelling =
534  clang::MSInheritanceAttr::Spelling::Keyword_single_inheritance;
535  break;
536  case llvm::codeview::PointerToMemberRepresentation::
537  MultipleInheritanceData:
538  case llvm::codeview::PointerToMemberRepresentation::
539  MultipleInheritanceFunction:
540  spelling =
541  clang::MSInheritanceAttr::Spelling::Keyword_multiple_inheritance;
542  break;
543  case llvm::codeview::PointerToMemberRepresentation::
544  VirtualInheritanceData:
545  case llvm::codeview::PointerToMemberRepresentation::
546  VirtualInheritanceFunction:
547  spelling =
548  clang::MSInheritanceAttr::Spelling::Keyword_virtual_inheritance;
549  break;
550  case llvm::codeview::PointerToMemberRepresentation::Unknown:
551  spelling =
552  clang::MSInheritanceAttr::Spelling::Keyword_unspecified_inheritance;
553  break;
554  default:
555  spelling = clang::MSInheritanceAttr::Spelling::SpellingNotCalculated;
556  break;
557  }
558  tag->addAttr(clang::MSInheritanceAttr::CreateImplicit(
559  m_clang.getASTContext(), spelling));
560  }
561  return m_clang.getASTContext().getMemberPointerType(
562  pointee_type, class_type.getTypePtr());
563  }
564 
565  clang::QualType pointer_type;
566  if (pointer.getMode() == PointerMode::LValueReference)
567  pointer_type = m_clang.getASTContext().getLValueReferenceType(pointee_type);
568  else if (pointer.getMode() == PointerMode::RValueReference)
569  pointer_type = m_clang.getASTContext().getRValueReferenceType(pointee_type);
570  else
571  pointer_type = m_clang.getASTContext().getPointerType(pointee_type);
572 
573  if ((pointer.getOptions() & PointerOptions::Const) != PointerOptions::None)
574  pointer_type.addConst();
575 
576  if ((pointer.getOptions() & PointerOptions::Volatile) != PointerOptions::None)
577  pointer_type.addVolatile();
578 
579  if ((pointer.getOptions() & PointerOptions::Restrict) != PointerOptions::None)
580  pointer_type.addRestrict();
581 
582  return pointer_type;
583 }
584 
585 clang::QualType
586 PdbAstBuilder::CreateModifierType(const ModifierRecord &modifier) {
587  clang::QualType unmodified_type = GetOrCreateType(modifier.ModifiedType);
588  if (unmodified_type.isNull())
589  return {};
590 
591  if ((modifier.Modifiers & ModifierOptions::Const) != ModifierOptions::None)
592  unmodified_type.addConst();
593  if ((modifier.Modifiers & ModifierOptions::Volatile) != ModifierOptions::None)
594  unmodified_type.addVolatile();
595 
596  return unmodified_type;
597 }
598 
600  const TagRecord &record) {
601  clang::DeclContext *context = nullptr;
602  std::string uname;
603  std::tie(context, uname) = CreateDeclInfoForType(record, id.index);
604  if (!context)
605  return {};
606 
607  clang::TagTypeKind ttk = TranslateUdtKind(record);
608  lldb::AccessType access =
609  (ttk == clang::TTK_Class) ? lldb::eAccessPrivate : lldb::eAccessPublic;
610 
611  ClangASTMetadata metadata;
612  metadata.SetUserID(toOpaqueUid(id));
613  metadata.SetIsDynamicCXXType(false);
614 
615  CompilerType ct =
616  m_clang.CreateRecordType(context, OptionalClangModuleID(), access, uname,
617  ttk, lldb::eLanguageTypeC_plus_plus, &metadata);
618 
619  lldbassert(ct.IsValid());
620 
622 
623  // Even if it's possible, don't complete it at this point. Just mark it
624  // forward resolved, and if/when LLDB needs the full definition, it can
625  // ask us.
626  clang::QualType result =
627  clang::QualType::getFromOpaquePtr(ct.GetOpaqueQualType());
628 
629  TypeSystemClang::SetHasExternalStorage(result.getAsOpaquePtr(), true);
630  return result;
631 }
632 
633 clang::Decl *PdbAstBuilder::TryGetDecl(PdbSymUid uid) const {
634  auto iter = m_uid_to_decl.find(toOpaqueUid(uid));
635  if (iter != m_uid_to_decl.end())
636  return iter->second;
637  return nullptr;
638 }
639 
640 clang::NamespaceDecl *
642  clang::DeclContext &context) {
644  IsAnonymousNamespaceName(name) ? nullptr : name, &context,
646 }
647 
648 clang::BlockDecl *
650  if (clang::Decl *decl = TryGetDecl(block_id))
651  return llvm::dyn_cast<clang::BlockDecl>(decl);
652 
653  clang::DeclContext *scope = GetParentDeclContext(block_id);
654 
655  clang::BlockDecl *block_decl =
657  m_uid_to_decl.insert({toOpaqueUid(block_id), block_decl});
658 
659  DeclStatus status;
660  status.resolved = true;
661  status.uid = toOpaqueUid(block_id);
662  m_decl_to_status.insert({block_decl, status});
663 
664  return block_decl;
665 }
666 
667 clang::VarDecl *PdbAstBuilder::CreateVariableDecl(PdbSymUid uid, CVSymbol sym,
668  clang::DeclContext &scope) {
669  VariableInfo var_info = GetVariableNameInfo(sym);
670  clang::QualType qt = GetOrCreateType(var_info.type);
671  if (qt.isNull())
672  return nullptr;
673 
674  clang::VarDecl *var_decl = m_clang.CreateVariableDeclaration(
675  &scope, OptionalClangModuleID(), var_info.name.str().c_str(), qt);
676 
677  m_uid_to_decl[toOpaqueUid(uid)] = var_decl;
678  DeclStatus status;
679  status.resolved = true;
680  status.uid = toOpaqueUid(uid);
681  m_decl_to_status.insert({var_decl, status});
682  return var_decl;
683 }
684 
685 clang::VarDecl *
687  PdbCompilandSymId var_id) {
688  if (clang::Decl *decl = TryGetDecl(var_id))
689  return llvm::dyn_cast<clang::VarDecl>(decl);
690 
691  clang::DeclContext *scope = GetOrCreateDeclContextForUid(scope_id);
692  if (!scope)
693  return nullptr;
694 
695  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
697  PdbIndex &index = pdb->GetIndex();
698  CVSymbol sym = index.ReadSymbolRecord(var_id);
699  return CreateVariableDecl(PdbSymUid(var_id), sym, *scope);
700 }
701 
703  if (clang::Decl *decl = TryGetDecl(var_id))
704  return llvm::dyn_cast<clang::VarDecl>(decl);
705 
706  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
708  PdbIndex &index = pdb->GetIndex();
709  CVSymbol sym = index.ReadSymbolRecord(var_id);
711  return CreateVariableDecl(PdbSymUid(var_id), sym, *context);
712 }
713 
714 clang::TypedefNameDecl *
716  if (clang::Decl *decl = TryGetDecl(id))
717  return llvm::dyn_cast<clang::TypedefNameDecl>(decl);
718 
719  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
721  PdbIndex &index = pdb->GetIndex();
722  CVSymbol sym = index.ReadSymbolRecord(id);
723  lldbassert(sym.kind() == S_UDT);
724  UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs<UDTSym>(sym));
725 
726  clang::DeclContext *scope = GetParentDeclContext(id);
727 
728  PdbTypeSymId real_type_id{udt.Type, false};
729  clang::QualType qt = GetOrCreateType(real_type_id);
730  if (qt.isNull() || !scope)
731  return nullptr;
732 
733  std::string uname = std::string(DropNameScope(udt.Name));
734 
736  uname.c_str(), ToCompilerDeclContext(*scope), 0);
737  clang::TypedefNameDecl *tnd = m_clang.GetAsTypedefDecl(ct);
738  DeclStatus status;
739  status.resolved = true;
740  status.uid = toOpaqueUid(id);
741  m_decl_to_status.insert({tnd, status});
742  return tnd;
743 }
744 
746  CompilerType ct = m_clang.GetBasicType(type);
747  return clang::QualType::getFromOpaquePtr(ct.GetOpaqueQualType());
748 }
749 
751  if (type.index.isSimple())
752  return CreateSimpleType(type.index);
753 
754  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
756  PdbIndex &index = pdb->GetIndex();
757  CVType cvt = index.tpi().getType(type.index);
758 
759  if (cvt.kind() == LF_MODIFIER) {
760  ModifierRecord modifier;
761  llvm::cantFail(
762  TypeDeserializer::deserializeAs<ModifierRecord>(cvt, modifier));
763  return CreateModifierType(modifier);
764  }
765 
766  if (cvt.kind() == LF_POINTER) {
767  PointerRecord pointer;
768  llvm::cantFail(
769  TypeDeserializer::deserializeAs<PointerRecord>(cvt, pointer));
770  return CreatePointerType(pointer);
771  }
772 
773  if (IsTagRecord(cvt)) {
774  CVTagRecord tag = CVTagRecord::create(cvt);
775  if (tag.kind() == CVTagRecord::Union)
776  return CreateRecordType(type.index, tag.asUnion());
777  if (tag.kind() == CVTagRecord::Enum)
778  return CreateEnumType(type.index, tag.asEnum());
779  return CreateRecordType(type.index, tag.asClass());
780  }
781 
782  if (cvt.kind() == LF_ARRAY) {
783  ArrayRecord ar;
784  llvm::cantFail(TypeDeserializer::deserializeAs<ArrayRecord>(cvt, ar));
785  return CreateArrayType(ar);
786  }
787 
788  if (cvt.kind() == LF_PROCEDURE) {
789  ProcedureRecord pr;
790  llvm::cantFail(TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, pr));
791  return CreateFunctionType(pr.ArgumentList, pr.ReturnType, pr.CallConv);
792  }
793 
794  if (cvt.kind() == LF_MFUNCTION) {
795  MemberFunctionRecord mfr;
796  llvm::cantFail(
797  TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfr));
798  return CreateFunctionType(mfr.ArgumentList, mfr.ReturnType, mfr.CallConv);
799  }
800 
801  return {};
802 }
803 
805  if (type.index.isNoneType())
806  return {};
807 
808  lldb::user_id_t uid = toOpaqueUid(type);
809  auto iter = m_uid_to_type.find(uid);
810  if (iter != m_uid_to_type.end())
811  return iter->second;
812 
813  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
815  PdbIndex &index = pdb->GetIndex();
816  PdbTypeSymId best_type = GetBestPossibleDecl(type, index.tpi());
817 
818  clang::QualType qt;
819  if (best_type.index != type.index) {
820  // This is a forward decl. Call GetOrCreate on the full decl, then map the
821  // forward decl id to the full decl QualType.
822  clang::QualType qt = GetOrCreateType(best_type);
823  if (qt.isNull())
824  return {};
825  m_uid_to_type[toOpaqueUid(type)] = qt;
826  return qt;
827  }
828 
829  // This is either a full decl, or a forward decl with no matching full decl
830  // in the debug info.
831  qt = CreateType(type);
832  if (qt.isNull())
833  return {};
834 
835  m_uid_to_type[toOpaqueUid(type)] = qt;
836  if (IsTagRecord(type, index.tpi())) {
837  clang::TagDecl *tag = qt->getAsTagDecl();
838  lldbassert(m_decl_to_status.count(tag) == 0);
839 
840  DeclStatus &status = m_decl_to_status[tag];
841  status.uid = uid;
842  status.resolved = false;
843  }
844  return qt;
845 }
846 
847 clang::FunctionDecl *
849  llvm::StringRef func_name, TypeIndex func_ti,
850  CompilerType func_ct, uint32_t param_count,
851  clang::StorageClass func_storage,
852  bool is_inline, clang::DeclContext *parent) {
853  clang::FunctionDecl *function_decl = nullptr;
854  if (parent->isRecord()) {
855  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
857  PdbIndex &index = pdb->GetIndex();
858  clang::QualType parent_qt = llvm::cast<clang::TypeDecl>(parent)
859  ->getTypeForDecl()
860  ->getCanonicalTypeInternal();
861  lldb::opaque_compiler_type_t parent_opaque_ty =
862  ToCompilerType(parent_qt).GetOpaqueQualType();
863  // FIXME: Remove this workaround.
864  auto iter = m_cxx_record_map.find(parent_opaque_ty);
865  if (iter != m_cxx_record_map.end()) {
866  if (iter->getSecond().contains({func_name, func_ct})) {
867  return nullptr;
868  }
869  }
870 
871  CVType cvt = index.tpi().getType(func_ti);
872  MemberFunctionRecord func_record(static_cast<TypeRecordKind>(cvt.kind()));
873  llvm::cantFail(TypeDeserializer::deserializeAs<MemberFunctionRecord>(
874  cvt, func_record));
875  TypeIndex class_index = func_record.getClassType();
876 
877  CVType parent_cvt = index.tpi().getType(class_index);
878  TagRecord tag_record = CVTagRecord::create(parent_cvt).asTag();
879  // If it's a forward reference, try to get the real TypeIndex.
880  if (tag_record.isForwardRef()) {
881  llvm::Expected<TypeIndex> eti =
882  index.tpi().findFullDeclForForwardRef(class_index);
883  if (eti) {
884  tag_record = CVTagRecord::create(index.tpi().getType(*eti)).asTag();
885  }
886  }
887  if (!tag_record.FieldList.isSimple()) {
888  CVType field_list_cvt = index.tpi().getType(tag_record.FieldList);
889  FieldListRecord field_list;
890  if (llvm::Error error = TypeDeserializer::deserializeAs<FieldListRecord>(
891  field_list_cvt, field_list))
892  llvm::consumeError(std::move(error));
893  CreateMethodDecl process(index, m_clang, func_ti, function_decl,
894  parent_opaque_ty, func_name, func_ct);
895  if (llvm::Error err = visitMemberRecordStream(field_list.Data, process))
896  llvm::consumeError(std::move(err));
897  }
898 
899  if (!function_decl) {
900  function_decl = m_clang.AddMethodToCXXRecordType(
901  parent_opaque_ty, func_name,
902  /*mangled_name=*/nullptr, func_ct,
904  /*is_virtual=*/false, /*is_static=*/false,
905  /*is_inline=*/false, /*is_explicit=*/false,
906  /*is_attr_used=*/false, /*is_artificial=*/false);
907  }
908  m_cxx_record_map[parent_opaque_ty].insert({func_name, func_ct});
909  } else {
910  function_decl = m_clang.CreateFunctionDeclaration(
911  parent, OptionalClangModuleID(), func_name, func_ct, func_storage,
912  is_inline);
913  CreateFunctionParameters(func_id, *function_decl, param_count);
914  }
915  return function_decl;
916 }
917 
918 clang::FunctionDecl *
920  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
922  PdbIndex &index = pdb->GetIndex();
923  CompilandIndexItem *cii =
924  index.compilands().GetCompiland(inlinesite_id.modi);
925  CVSymbol sym = cii->m_debug_stream.readSymbolAtOffset(inlinesite_id.offset);
926  InlineSiteSym inline_site(static_cast<SymbolRecordKind>(sym.kind()));
927  cantFail(SymbolDeserializer::deserializeAs<InlineSiteSym>(sym, inline_site));
928 
929  // Inlinee is the id index to the function id record that is inlined.
930  PdbTypeSymId func_id(inline_site.Inlinee, true);
931  // Look up the function decl by the id index to see if we have created a
932  // function decl for a different inlinesite that refers the same function.
933  if (clang::Decl *decl = TryGetDecl(func_id))
934  return llvm::dyn_cast<clang::FunctionDecl>(decl);
935  clang::FunctionDecl *function_decl =
936  CreateFunctionDeclFromId(func_id, inlinesite_id);
937  if (function_decl == nullptr)
938  return nullptr;
939 
940  // Use inline site id in m_decl_to_status because it's expected to be a
941  // PdbCompilandSymId so that we can parse local variables info after it.
942  uint64_t inlinesite_uid = toOpaqueUid(inlinesite_id);
943  DeclStatus status;
944  status.resolved = true;
945  status.uid = inlinesite_uid;
946  m_decl_to_status.insert({function_decl, status});
947  // Use the index in IPI stream as uid in m_uid_to_decl, because index in IPI
948  // stream are unique and there could be multiple inline sites (different ids)
949  // referring the same inline function. This avoid creating multiple same
950  // inline function delcs.
951  uint64_t func_uid = toOpaqueUid(func_id);
952  lldbassert(m_uid_to_decl.count(func_uid) == 0);
953  m_uid_to_decl[func_uid] = function_decl;
954  return function_decl;
955 }
956 
957 clang::FunctionDecl *
959  PdbCompilandSymId func_sid) {
960  lldbassert(func_tid.is_ipi);
961  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
963  PdbIndex &index = pdb->GetIndex();
964  CVType func_cvt = index.ipi().getType(func_tid.index);
965  llvm::StringRef func_name;
966  TypeIndex func_ti;
967  clang::DeclContext *parent = nullptr;
968  switch (func_cvt.kind()) {
969  case LF_MFUNC_ID: {
970  MemberFuncIdRecord mfr;
971  cantFail(
972  TypeDeserializer::deserializeAs<MemberFuncIdRecord>(func_cvt, mfr));
973  func_name = mfr.getName();
974  func_ti = mfr.getFunctionType();
975  PdbTypeSymId class_type_id(mfr.ClassType, false);
976  parent = GetOrCreateDeclContextForUid(class_type_id);
977  break;
978  }
979  case LF_FUNC_ID: {
980  FuncIdRecord fir;
981  cantFail(TypeDeserializer::deserializeAs<FuncIdRecord>(func_cvt, fir));
982  func_name = fir.getName();
983  func_ti = fir.getFunctionType();
985  if (!fir.ParentScope.isNoneType()) {
986  CVType parent_cvt = index.ipi().getType(fir.ParentScope);
987  if (parent_cvt.kind() == LF_STRING_ID) {
988  StringIdRecord sir;
989  cantFail(
990  TypeDeserializer::deserializeAs<StringIdRecord>(parent_cvt, sir));
991  parent = GetOrCreateNamespaceDecl(sir.String.data(), *parent);
992  }
993  }
994  break;
995  }
996  default:
997  lldbassert(false && "Invalid function id type!");
998  }
999  clang::QualType func_qt = GetOrCreateType(func_ti);
1000  if (func_qt.isNull() || !parent)
1001  return nullptr;
1002  CompilerType func_ct = ToCompilerType(func_qt);
1003  uint32_t param_count =
1004  llvm::cast<clang::FunctionProtoType>(func_qt)->getNumParams();
1005  return CreateFunctionDecl(func_sid, func_name, func_ti, func_ct, param_count,
1006  clang::SC_None, true, parent);
1007 }
1008 
1009 clang::FunctionDecl *
1011  if (clang::Decl *decl = TryGetDecl(func_id))
1012  return llvm::dyn_cast<clang::FunctionDecl>(decl);
1013 
1014  clang::DeclContext *parent = GetParentDeclContext(PdbSymUid(func_id));
1015  if (!parent)
1016  return nullptr;
1017  std::string context_name;
1018  if (clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(parent)) {
1019  context_name = ns->getQualifiedNameAsString();
1020  } else if (clang::TagDecl *tag = llvm::dyn_cast<clang::TagDecl>(parent)) {
1021  context_name = tag->getQualifiedNameAsString();
1022  }
1023 
1024  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
1026  PdbIndex &index = pdb->GetIndex();
1027  CVSymbol cvs = index.ReadSymbolRecord(func_id);
1028  ProcSym proc(static_cast<SymbolRecordKind>(cvs.kind()));
1029  llvm::cantFail(SymbolDeserializer::deserializeAs<ProcSym>(cvs, proc));
1030 
1031  PdbTypeSymId type_id(proc.FunctionType);
1032  clang::QualType qt = GetOrCreateType(type_id);
1033  if (qt.isNull())
1034  return nullptr;
1035 
1036  clang::StorageClass storage = clang::SC_None;
1037  if (proc.Kind == SymbolRecordKind::ProcSym)
1038  storage = clang::SC_Static;
1039 
1040  const clang::FunctionProtoType *func_type =
1041  llvm::dyn_cast<clang::FunctionProtoType>(qt);
1042 
1043  CompilerType func_ct = ToCompilerType(qt);
1044 
1045  llvm::StringRef proc_name = proc.Name;
1046  proc_name.consume_front(context_name);
1047  proc_name.consume_front("::");
1048  clang::FunctionDecl *function_decl =
1049  CreateFunctionDecl(func_id, proc_name, proc.FunctionType, func_ct,
1050  func_type->getNumParams(), storage, false, parent);
1051  if (function_decl == nullptr)
1052  return nullptr;
1053 
1054  lldbassert(m_uid_to_decl.count(toOpaqueUid(func_id)) == 0);
1055  m_uid_to_decl[toOpaqueUid(func_id)] = function_decl;
1056  DeclStatus status;
1057  status.resolved = true;
1058  status.uid = toOpaqueUid(func_id);
1059  m_decl_to_status.insert({function_decl, status});
1060 
1061  return function_decl;
1062 }
1063 
1065  clang::FunctionDecl &function_decl,
1066  uint32_t param_count) {
1067  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
1069  PdbIndex &index = pdb->GetIndex();
1070  CompilandIndexItem *cii = index.compilands().GetCompiland(func_id.modi);
1071  CVSymbolArray scope =
1072  cii->m_debug_stream.getSymbolArrayForScope(func_id.offset);
1073 
1074  scope.drop_front();
1075  auto begin = scope.begin();
1076  auto end = scope.end();
1077  std::vector<clang::ParmVarDecl *> params;
1078  for (uint32_t i = 0; i < param_count && begin != end;) {
1079  uint32_t record_offset = begin.offset();
1080  CVSymbol sym = *begin++;
1081 
1082  TypeIndex param_type;
1083  llvm::StringRef param_name;
1084  switch (sym.kind()) {
1085  case S_REGREL32: {
1086  RegRelativeSym reg(SymbolRecordKind::RegRelativeSym);
1087  cantFail(SymbolDeserializer::deserializeAs<RegRelativeSym>(sym, reg));
1088  param_type = reg.Type;
1089  param_name = reg.Name;
1090  break;
1091  }
1092  case S_REGISTER: {
1093  RegisterSym reg(SymbolRecordKind::RegisterSym);
1094  cantFail(SymbolDeserializer::deserializeAs<RegisterSym>(sym, reg));
1095  param_type = reg.Index;
1096  param_name = reg.Name;
1097  break;
1098  }
1099  case S_LOCAL: {
1100  LocalSym local(SymbolRecordKind::LocalSym);
1101  cantFail(SymbolDeserializer::deserializeAs<LocalSym>(sym, local));
1102  if ((local.Flags & LocalSymFlags::IsParameter) == LocalSymFlags::None)
1103  continue;
1104  param_type = local.Type;
1105  param_name = local.Name;
1106  break;
1107  }
1108  case S_BLOCK32:
1109  case S_INLINESITE:
1110  case S_INLINESITE2:
1111  // All parameters should come before the first block/inlinesite. If that
1112  // isn't the case, then perhaps this is bad debug info that doesn't
1113  // contain information about all parameters.
1114  return;
1115  default:
1116  continue;
1117  }
1118 
1119  PdbCompilandSymId param_uid(func_id.modi, record_offset);
1120  clang::QualType qt = GetOrCreateType(param_type);
1121  if (qt.isNull())
1122  return;
1123 
1124  CompilerType param_type_ct = m_clang.GetType(qt);
1125  clang::ParmVarDecl *param = m_clang.CreateParameterDeclaration(
1126  &function_decl, OptionalClangModuleID(), param_name.str().c_str(),
1127  param_type_ct, clang::SC_None, true);
1128  lldbassert(m_uid_to_decl.count(toOpaqueUid(param_uid)) == 0);
1129 
1130  m_uid_to_decl[toOpaqueUid(param_uid)] = param;
1131  params.push_back(param);
1132  ++i;
1133  }
1134 
1135  if (!params.empty() && params.size() == param_count)
1136  m_clang.SetFunctionParameters(&function_decl, params);
1137 }
1138 
1140  const EnumRecord &er) {
1141  clang::DeclContext *decl_context = nullptr;
1142  std::string uname;
1143  std::tie(decl_context, uname) = CreateDeclInfoForType(er, id.index);
1144  if (!decl_context)
1145  return {};
1146 
1147  clang::QualType underlying_type = GetOrCreateType(er.UnderlyingType);
1148  if (underlying_type.isNull())
1149  return {};
1150 
1151  Declaration declaration;
1153  uname, decl_context, OptionalClangModuleID(), declaration,
1154  ToCompilerType(underlying_type), er.isScoped());
1155 
1158 
1159  return clang::QualType::getFromOpaquePtr(enum_ct.GetOpaqueQualType());
1160 }
1161 
1162 clang::QualType PdbAstBuilder::CreateArrayType(const ArrayRecord &ar) {
1163  clang::QualType element_type = GetOrCreateType(ar.ElementType);
1164 
1165  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
1167  PdbIndex &index = pdb->GetIndex();
1168  uint64_t element_size = GetSizeOfType({ar.ElementType}, index.tpi());
1169  if (element_type.isNull() || element_size == 0)
1170  return {};
1171  uint64_t element_count = ar.Size / element_size;
1172 
1173  CompilerType array_ct = m_clang.CreateArrayType(ToCompilerType(element_type),
1174  element_count, false);
1175  return clang::QualType::getFromOpaquePtr(array_ct.GetOpaqueQualType());
1176 }
1177 
1179  TypeIndex args_type_idx, TypeIndex return_type_idx,
1180  llvm::codeview::CallingConvention calling_convention) {
1181  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
1183  PdbIndex &index = pdb->GetIndex();
1184  TpiStream &stream = index.tpi();
1185  CVType args_cvt = stream.getType(args_type_idx);
1186  ArgListRecord args;
1187  llvm::cantFail(
1188  TypeDeserializer::deserializeAs<ArgListRecord>(args_cvt, args));
1189 
1190  llvm::ArrayRef<TypeIndex> arg_indices = llvm::makeArrayRef(args.ArgIndices);
1191  bool is_variadic = IsCVarArgsFunction(arg_indices);
1192  if (is_variadic)
1193  arg_indices = arg_indices.drop_back();
1194 
1195  std::vector<CompilerType> arg_types;
1196  arg_types.reserve(arg_indices.size());
1197 
1198  for (TypeIndex arg_index : arg_indices) {
1199  clang::QualType arg_type = GetOrCreateType(arg_index);
1200  if (arg_type.isNull())
1201  continue;
1202  arg_types.push_back(ToCompilerType(arg_type));
1203  }
1204 
1205  clang::QualType return_type = GetOrCreateType(return_type_idx);
1206  if (return_type.isNull())
1207  return {};
1208 
1209  llvm::Optional<clang::CallingConv> cc =
1210  TranslateCallingConvention(calling_convention);
1211  if (!cc)
1212  return {};
1213 
1214  CompilerType return_ct = ToCompilerType(return_type);
1215  CompilerType func_sig_ast_type = m_clang.CreateFunctionType(
1216  return_ct, arg_types.data(), arg_types.size(), is_variadic, 0, *cc);
1217 
1218  return clang::QualType::getFromOpaquePtr(
1219  func_sig_ast_type.GetOpaqueQualType());
1220 }
1221 
1222 static bool isTagDecl(clang::DeclContext &context) {
1223  return llvm::isa<clang::TagDecl>(&context);
1224 }
1225 
1226 static bool isFunctionDecl(clang::DeclContext &context) {
1227  return llvm::isa<clang::FunctionDecl>(&context);
1228 }
1229 
1230 static bool isBlockDecl(clang::DeclContext &context) {
1231  return llvm::isa<clang::BlockDecl>(&context);
1232 }
1233 
1234 void PdbAstBuilder::ParseNamespace(clang::DeclContext &context) {
1235  clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(&context);
1236  if (m_parsed_namespaces.contains(ns))
1237  return;
1238  std::string qname = ns->getQualifiedNameAsString();
1239  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
1241  PdbIndex &index = pdb->GetIndex();
1242  TypeIndex ti{index.tpi().TypeIndexBegin()};
1243  for (const CVType &cvt : index.tpi().typeArray()) {
1244  PdbTypeSymId tid{ti};
1245  ++ti;
1246 
1247  if (!IsTagRecord(cvt))
1248  continue;
1249 
1250  CVTagRecord tag = CVTagRecord::create(cvt);
1251 
1252  // Call CreateDeclInfoForType unconditionally so that the namespace info
1253  // gets created. But only call CreateRecordType if the namespace name
1254  // matches.
1255  clang::DeclContext *context = nullptr;
1256  std::string uname;
1257  std::tie(context, uname) = CreateDeclInfoForType(tag.asTag(), tid.index);
1258  if (!context || !context->isNamespace())
1259  continue;
1260 
1261  clang::NamespaceDecl *ns = llvm::cast<clang::NamespaceDecl>(context);
1262  llvm::StringRef ns_name = ns->getName();
1263  if (ns_name.startswith(qname)) {
1264  ns_name = ns_name.drop_front(qname.size());
1265  if (ns_name.startswith("::"))
1266  GetOrCreateType(tid);
1267  }
1268  }
1270  m_parsed_namespaces.insert(ns);
1271 }
1272 
1274  llvm::call_once(m_parse_all_types, [this]() {
1275  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
1276  m_clang.GetSymbolFile()->GetBackingSymbolFile());
1277  PdbIndex &index = pdb->GetIndex();
1278  TypeIndex ti{index.tpi().TypeIndexBegin()};
1279  for (const CVType &cvt : index.tpi().typeArray()) {
1280  PdbTypeSymId tid{ti};
1281  ++ti;
1282 
1283  if (!IsTagRecord(cvt))
1284  continue;
1285 
1286  GetOrCreateType(tid);
1287  }
1288  });
1289 }
1290 
1292  llvm::call_once(m_parse_functions_and_non_local_vars, [this]() {
1293  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
1294  m_clang.GetSymbolFile()->GetBackingSymbolFile());
1295  PdbIndex &index = pdb->GetIndex();
1296  uint32_t module_count = index.dbi().modules().getModuleCount();
1297  for (uint16_t modi = 0; modi < module_count; ++modi) {
1298  CompilandIndexItem &cii = index.compilands().GetOrCreateCompiland(modi);
1299  const CVSymbolArray &symbols = cii.m_debug_stream.getSymbolArray();
1300  auto iter = symbols.begin();
1301  while (iter != symbols.end()) {
1302  PdbCompilandSymId sym_id{modi, iter.offset()};
1303 
1304  switch (iter->kind()) {
1305  case S_GPROC32:
1306  case S_LPROC32:
1307  GetOrCreateFunctionDecl(sym_id);
1308  iter = symbols.at(getScopeEndOffset(*iter));
1309  break;
1310  case S_GDATA32:
1311  case S_GTHREAD32:
1312  case S_LDATA32:
1313  case S_LTHREAD32:
1314  GetOrCreateVariableDecl(PdbCompilandSymId(modi, 0), sym_id);
1315  ++iter;
1316  break;
1317  default:
1318  ++iter;
1319  continue;
1320  }
1321  }
1322  }
1323  });
1324 }
1325 
1326 static CVSymbolArray skipFunctionParameters(clang::Decl &decl,
1327  const CVSymbolArray &symbols) {
1328  clang::FunctionDecl *func_decl = llvm::dyn_cast<clang::FunctionDecl>(&decl);
1329  if (!func_decl)
1330  return symbols;
1331  unsigned int params = func_decl->getNumParams();
1332  if (params == 0)
1333  return symbols;
1334 
1335  CVSymbolArray result = symbols;
1336 
1337  while (!result.empty()) {
1338  if (params == 0)
1339  return result;
1340 
1341  CVSymbol sym = *result.begin();
1342  result.drop_front();
1343 
1344  if (!isLocalVariableType(sym.kind()))
1345  continue;
1346 
1347  --params;
1348  }
1349  return result;
1350 }
1351 
1353  SymbolFileNativePDB *pdb = static_cast<SymbolFileNativePDB *>(
1355  PdbIndex &index = pdb->GetIndex();
1356  CVSymbol sym = index.ReadSymbolRecord(block_id);
1357  lldbassert(sym.kind() == S_GPROC32 || sym.kind() == S_LPROC32 ||
1358  sym.kind() == S_BLOCK32 || sym.kind() == S_INLINESITE);
1359  CompilandIndexItem &cii =
1360  index.compilands().GetOrCreateCompiland(block_id.modi);
1361  CVSymbolArray symbols =
1362  cii.m_debug_stream.getSymbolArrayForScope(block_id.offset);
1363 
1364  // Function parameters should already have been created when the function was
1365  // parsed.
1366  if (sym.kind() == S_GPROC32 || sym.kind() == S_LPROC32)
1367  symbols =
1368  skipFunctionParameters(*m_uid_to_decl[toOpaqueUid(block_id)], symbols);
1369 
1370  symbols.drop_front();
1371  auto begin = symbols.begin();
1372  while (begin != symbols.end()) {
1373  PdbCompilandSymId child_sym_id(block_id.modi, begin.offset());
1374  GetOrCreateSymbolForId(child_sym_id);
1375  if (begin->kind() == S_BLOCK32 || begin->kind() == S_INLINESITE) {
1376  ParseBlockChildren(child_sym_id);
1377  begin = symbols.at(getScopeEndOffset(*begin));
1378  }
1379  ++begin;
1380  }
1381 }
1382 
1383 void PdbAstBuilder::ParseDeclsForSimpleContext(clang::DeclContext &context) {
1384 
1385  clang::Decl *decl = clang::Decl::castFromDeclContext(&context);
1386  lldbassert(decl);
1387 
1388  auto iter = m_decl_to_status.find(decl);
1389  lldbassert(iter != m_decl_to_status.end());
1390 
1391  if (auto *tag = llvm::dyn_cast<clang::TagDecl>(&context)) {
1392  CompleteTagDecl(*tag);
1393  return;
1394  }
1395 
1396  if (isFunctionDecl(context) || isBlockDecl(context)) {
1397  PdbCompilandSymId block_id = PdbSymUid(iter->second.uid).asCompilandSym();
1398  ParseBlockChildren(block_id);
1399  }
1400 }
1401 
1402 void PdbAstBuilder::ParseDeclsForContext(clang::DeclContext &context) {
1403  // Namespaces aren't explicitly represented in the debug info, and the only
1404  // way to parse them is to parse all type info, demangling every single type
1405  // and trying to reconstruct the DeclContext hierarchy this way. Since this
1406  // is an expensive operation, we have to special case it so that we do other
1407  // work (such as parsing the items that appear within the namespaces) at the
1408  // same time.
1409  if (context.isTranslationUnit()) {
1410  ParseAllTypes();
1412  return;
1413  }
1414 
1415  if (context.isNamespace()) {
1416  ParseNamespace(context);
1417  return;
1418  }
1419 
1420  if (isTagDecl(context) || isFunctionDecl(context) || isBlockDecl(context)) {
1421  ParseDeclsForSimpleContext(context);
1422  return;
1423  }
1424 }
1425 
1427  return m_clang.GetCompilerDecl(&decl);
1428 }
1429 
1431  return {m_clang.weak_from_this(), qt.getAsOpaquePtr()};
1432 }
1433 
1435 PdbAstBuilder::ToCompilerDeclContext(clang::DeclContext &context) {
1436  return m_clang.CreateDeclContext(&context);
1437 }
1438 
1440  return ClangUtil::GetDecl(decl);
1441 }
1442 
1443 clang::DeclContext *
1445  return static_cast<clang::DeclContext *>(context.GetOpaqueDeclContext());
1446 }
1447 
1449  m_clang.Dump(stream.AsRawOstream());
1450 }
lldb_private::npdb::PdbSymUidKind::Type
@ Type
lldb_private::npdb::PdbAstBuilder::m_uid_to_decl
llvm::DenseMap< lldb::user_id_t, clang::Decl * > m_uid_to_decl
Definition: PdbAstBuilder.h:144
lldb_private::npdb::CompilandIndexItem::m_debug_stream
llvm::pdb::ModuleDebugStreamRef m_debug_stream
Definition: CompileUnitIndex.h:48
lldb_private::npdb::PdbAstBuilder::CreateEnumType
clang::QualType CreateEnumType(PdbTypeSymId id, const llvm::codeview::EnumRecord &record)
Definition: PdbAstBuilder.cpp:1139
lldb_private::TypeSystemClang::CreateParameterDeclaration
clang::ParmVarDecl * CreateParameterDeclaration(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, const char *name, const CompilerType &param_type, int storage, bool add_decl=false)
Definition: TypeSystemClang.cpp:2223
lldb_private::TypeSystemClang::CreateBlockDeclaration
clang::BlockDecl * CreateBlockDeclaration(clang::DeclContext *ctx, OptionalClangModuleID owning_module)
Definition: TypeSystemClang.cpp:1934
lldb_private::npdb::CompileUnitIndex::GetCompiland
const CompilandIndexItem * GetCompiland(uint16_t modi) const
Definition: CompileUnitIndex.cpp:194
lldb_private::npdb::PdbAstBuilder::ToCompilerType
CompilerType ToCompilerType(clang::QualType qt)
Definition: PdbAstBuilder.cpp:1430
lldb_private::npdb::PdbAstBuilder::CreateDeclInfoForType
std::pair< clang::DeclContext *, std::string > CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti)
Definition: PdbAstBuilder.cpp:168
lldb_private::npdb::GetFieldListIndex
llvm::codeview::TypeIndex GetFieldListIndex(llvm::codeview::CVType cvt)
lldb_private::npdb::PdbSymUid::asTypeSym
PdbTypeSymId asTypeSym() const
Definition: PdbSymUid.cpp:144
IsAnonymousNamespaceName
static bool IsAnonymousNamespaceName(llvm::StringRef name)
Definition: PdbAstBuilder.cpp:157
lldb_private::TypeSystemClang::GetCompilerDecl
CompilerDecl GetCompilerDecl(clang::Decl *decl)
Creates a CompilerDecl from the given Decl with the current TypeSystemClang instance as its typesyste...
Definition: TypeSystemClang.h:475
lldb_private::TypeSystemClang::getASTContext
clang::ASTContext & getASTContext()
Returns the clang::ASTContext instance managed by this TypeSystemClang.
Definition: TypeSystemClang.cpp:687
lldb_private::TypeSystemClang::CreateDeclContext
CompilerDeclContext CreateDeclContext(clang::DeclContext *ctx)
Creates a CompilerDeclContext from the given DeclContext with the current TypeSystemClang instance as...
Definition: TypeSystemClang.cpp:1200
TypeVisitorCallbacks
lldb_private::npdb::PdbIndex::compilands
CompileUnitIndex & compilands()
Definition: PdbIndex.h:142
lldb_private::npdb::PdbAstBuilder::CreateVariableDecl
clang::VarDecl * CreateVariableDecl(PdbSymUid uid, llvm::codeview::CVSymbol sym, clang::DeclContext &scope)
Definition: PdbAstBuilder.cpp:667
lldb_private::npdb::CVTagRecord::Union
@ Union
Definition: PdbUtil.h:38
TranslateCallingConvention
static llvm::Optional< clang::CallingConv > TranslateCallingConvention(llvm::codeview::CallingConvention conv)
Definition: PdbAstBuilder.cpp:132
lldb_private::npdb::PdbSymUid::asCompilandSym
PdbCompilandSymId asCompilandSym() const
Definition: PdbSymUid.cpp:125
lldb_private::npdb::SymbolFileNativePDB
Definition: SymbolFileNativePDB.h:42
lldb::eBasicTypeInvalid
@ eBasicTypeInvalid
Definition: lldb-enumerations.h:752
MSVCUndecoratedNameParser
Definition: MSVCUndecoratedNameParser.h:31
lldb_private::CompilerDeclContext::GetOpaqueDeclContext
void * GetOpaqueDeclContext() const
Definition: CompilerDeclContext.h:103
lldb_private::TypeSystemClang::CreateFunctionDeclaration
clang::FunctionDecl * CreateFunctionDeclaration(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, llvm::StringRef name, const CompilerType &function_Type, clang::StorageClass storage, bool is_inline)
Definition: TypeSystemClang.cpp:2153
lldb_private::TypeSystemClang::GetTranslationUnitDecl
clang::TranslationUnitDecl * GetTranslationUnitDecl()
Definition: TypeSystemClang.h:223
lldb_private::npdb::CVTagRecord::asUnion
const llvm::codeview::UnionRecord & asUnion() const
Definition: PdbUtil.h:62
lldb_private::npdb::PdbAstBuilder::CreateDeclInfoForUndecoratedName
std::pair< clang::DeclContext *, std::string > CreateDeclInfoForUndecoratedName(llvm::StringRef uname)
Definition: PdbAstBuilder.cpp:320
MSVCUndecoratedNameParser::GetSpecifiers
llvm::ArrayRef< MSVCUndecoratedNameSpecifier > GetSpecifiers() const
Definition: MSVCUndecoratedNameParser.h:35
lldb_private::npdb::PdbAstBuilder::PdbAstBuilder
PdbAstBuilder(TypeSystemClang &clang)
Definition: PdbAstBuilder.cpp:161
lldb_private::npdb::PdbIndex
PdbIndex - Lazy access to the important parts of a PDB file.
Definition: PdbIndex.h:47
lldb_private::npdb::PdbAstBuilder::GetOrCreateBlockDecl
clang::BlockDecl * GetOrCreateBlockDecl(PdbCompilandSymId block_id)
Definition: PdbAstBuilder.cpp:649
lldb_private::npdb::PdbAstBuilder::FromCompilerDeclContext
clang::DeclContext * FromCompilerDeclContext(CompilerDeclContext context)
Definition: PdbAstBuilder.cpp:1444
lldb_private::npdb::PdbCompilandSymId
Definition: PdbSymUid.h:44
lldb_private::npdb::VariableInfo::type
llvm::codeview::TypeIndex type
Definition: PdbUtil.h:104
lldb_private::npdb::PdbTypeSymId::index
llvm::codeview::TypeIndex index
Definition: PdbSymUid.h:76
lldb_private::ClangASTMetadata::SetUserID
void SetUserID(lldb::user_id_t user_id)
Definition: ClangASTMetadata.h:29
lldb_private::npdb::LookThroughModifierRecord
llvm::codeview::TypeIndex LookThroughModifierRecord(llvm::codeview::CVType modifier)
lldb_private::npdb::PdbAstBuilder::CreateRecordType
clang::QualType CreateRecordType(PdbTypeSymId id, const llvm::codeview::TagRecord &record)
Definition: PdbAstBuilder.cpp:599
lldb_private::npdb::TranslateMemberAccess
lldb::AccessType TranslateMemberAccess(llvm::codeview::MemberAccess access)
lldb_private::npdb::PdbSymUidKind::FieldListMember
@ FieldListMember
lldb_private::npdb
Definition: TypeSystem.h:35
lldb_private::npdb::PdbAstBuilder::GetOrCreateNamespaceDecl
clang::NamespaceDecl * GetOrCreateNamespaceDecl(const char *name, clang::DeclContext &context)
Definition: PdbAstBuilder.cpp:641
lldb_private::npdb::DropNameScope
llvm::StringRef DropNameScope(llvm::StringRef name)
Definition: PdbUtil.cpp:599
lldb_private::TypeSystemClang::CreateFunctionType
CompilerType CreateFunctionType(const CompilerType &result_type, const CompilerType *args, unsigned num_args, bool is_variadic, unsigned type_quals, clang::CallingConv cc=clang::CC_C, clang::RefQualifierKind ref_qual=clang::RQ_None)
Definition: TypeSystemClang.cpp:2185
Module.h
lldb_private::npdb::PdbAstBuilder::GetOrCreateTypedefDecl
clang::TypedefNameDecl * GetOrCreateTypedefDecl(PdbGlobalSymId id)
Definition: PdbAstBuilder.cpp:715
lldb_private::TypeSystemClang::CreateEnumerationType
CompilerType CreateEnumerationType(llvm::StringRef name, clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, const Declaration &decl, const CompilerType &integer_qual_type, bool is_scoped)
Definition: TypeSystemClang.cpp:2322
lldb_private::npdb::PdbCompilandSymId::modi
uint16_t modi
Definition: PdbSymUid.h:49
lldb_private::npdb::PdbAstBuilder::CreateFunctionDeclFromId
clang::FunctionDecl * CreateFunctionDeclFromId(PdbTypeSymId func_tid, PdbCompilandSymId func_sid)
Definition: PdbAstBuilder.cpp:958
lldb_private::npdb::PdbAstBuilder::m_clang
TypeSystemClang & m_clang
Definition: PdbAstBuilder.h:138
lldb_private::npdb::PdbIndex::ReadSymbolRecord
llvm::codeview::CVSymbol ReadSymbolRecord(PdbCompilandSymId cu_sym) const
Definition: PdbIndex.cpp:186
lldb_private::npdb::PdbAstBuilder::GetTranslationUnitDecl
lldb_private::CompilerDeclContext GetTranslationUnitDecl()
Definition: PdbAstBuilder.cpp:163
lldb_private::npdb::PdbAstBuilder::GetParentDeclContext
clang::DeclContext * GetParentDeclContext(PdbSymUid uid)
Definition: PdbAstBuilder.cpp:356
lldb_private::CompilerDecl
Represents a generic declaration such as a function declaration.
Definition: CompilerDecl.h:28
lldb_private::npdb::PdbAstBuilder::m_parse_all_types
llvm::once_flag m_parse_all_types
Definition: PdbAstBuilder.h:142
lldb_private::npdb::PdbAstBuilder::GetOrCreateFunctionDecl
clang::FunctionDecl * GetOrCreateFunctionDecl(PdbCompilandSymId func_id)
Definition: PdbAstBuilder.cpp:1010
lldb_private::npdb::PdbAstBuilder::CreateFunctionParameters
void CreateFunctionParameters(PdbCompilandSymId func_id, clang::FunctionDecl &function_decl, uint32_t param_count)
Definition: PdbAstBuilder.cpp:1064
lldb_private::CompilerType::GetOpaqueQualType
lldb::opaque_compiler_type_t GetOpaqueQualType() const
Definition: CompilerType.h:229
lldb_private::npdb::PdbAstBuilder::CreateType
clang::QualType CreateType(PdbTypeSymId type)
Definition: PdbAstBuilder.cpp:750
lldb_private::Stream
Definition: Stream.h:28
lldb::BasicType
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
Definition: lldb-enumerations.h:751
lldb_private::npdb::VariableInfo::name
llvm::StringRef name
Definition: PdbUtil.h:103
lldb_private::npdb::CVTagRecord::asEnum
const llvm::codeview::EnumRecord & asEnum() const
Definition: PdbUtil.h:57
lldb_private::npdb::PdbAstBuilder::ParseAllFunctionsAndNonLocalVars
void ParseAllFunctionsAndNonLocalVars()
Definition: PdbAstBuilder.cpp:1291
lldb_private::TypeSystemClang::CreateArrayType
CompilerType CreateArrayType(const CompilerType &element_type, size_t element_count, bool is_vector)
Definition: TypeSystemClang.cpp:2257
lldb_private::npdb::GetVariableNameInfo
VariableInfo GetVariableNameInfo(llvm::codeview::CVSymbol symbol)
lldb_private::npdb::DeclStatus
Definition: PdbAstBuilder.h:44
ClangUtil.h
lldb_private::npdb::CVTagRecord::create
static CVTagRecord create(llvm::codeview::CVType type)
Definition: PdbUtil.cpp:198
lldb_private::npdb::UdtRecordCompleter::complete
void complete()
Definition: UdtRecordCompleter.cpp:304
lldb_private::npdb::CompileUnitIndex::GetOrCreateCompiland
CompilandIndexItem & GetOrCreateCompiland(uint16_t modi)
Definition: CompileUnitIndex.cpp:133
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::npdb::GetSizeOfType
size_t GetSizeOfType(PdbTypeSymId id, llvm::pdb::TpiStream &tpi)
Definition: PdbUtil.cpp:1065
lldb_private::npdb::PdbSymUidKind::CompilandSym
@ CompilandSym
isTagDecl
static bool isTagDecl(clang::DeclContext &context)
Definition: PdbAstBuilder.cpp:1222
lldb_private::npdb::toOpaqueUid
uint64_t toOpaqueUid(const T &cid)
Definition: PdbSymUid.h:114
LLDBAssert.h
lldb_private::npdb::PdbGlobalSymId
Definition: PdbSymUid.h:57
ClangASTMetadata.h
lldb_private::CompilerType::CreateTypedef
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...
Definition: CompilerType.cpp:516
TypeSystemClang.h
lldb_private::npdb::PdbAstBuilder::GetBasicType
clang::QualType GetBasicType(lldb::BasicType type)
Definition: PdbAstBuilder.cpp:745
lldb_private::npdb::SymbolFileNativePDB::GetParentType
llvm::Optional< llvm::codeview::TypeIndex > GetParentType(llvm::codeview::TypeIndex ti)
Definition: SymbolFileNativePDB.cpp:2323
TranslateUdtKind
static clang::TagTypeKind TranslateUdtKind(const TagRecord &cr)
Definition: PdbAstBuilder.cpp:97
lldb_private::npdb::CVTagRecord::kind
Kind kind() const
Definition: PdbUtil.h:42
skipFunctionParameters
static CVSymbolArray skipFunctionParameters(clang::Decl &decl, const CVSymbolArray &symbols)
Definition: PdbAstBuilder.cpp:1326
lldb_private::npdb::DeclStatus::resolved
bool resolved
Definition: PdbAstBuilder.h:49
lldb_private::npdb::PdbAstBuilder::FromCompilerDecl
clang::Decl * FromCompilerDecl(CompilerDecl decl)
Definition: PdbAstBuilder.cpp:1439
lldb_private::npdb::PdbIndex::tpi
llvm::pdb::TpiStream & tpi()
Definition: PdbIndex.h:124
lldb_private::npdb::GetCompilerTypeForSimpleKind
lldb::BasicType GetCompilerTypeForSimpleKind(llvm::codeview::SimpleTypeKind kind)
lldb_private::npdb::PdbAstBuilder::ToCompilerDeclContext
CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context)
Definition: PdbAstBuilder.cpp:1435
llvm::pdb
Definition: DWARFLocationExpression.h:23
lldb_private::npdb::PdbAstBuilder::m_parsed_namespaces
llvm::DenseSet< clang::NamespaceDecl * > m_parsed_namespaces
Definition: PdbAstBuilder.h:152
MSVCUndecoratedNameParser.h
lldb_private::npdb::CVTagRecord::asClass
const llvm::codeview::ClassRecord & asClass() const
Definition: PdbUtil.h:52
lldb_private::npdb::PdbTypeSymId
Definition: PdbSymUid.h:70
lldb_private::npdb::PdbIndex::dbi
llvm::pdb::DbiStream & dbi()
Definition: PdbIndex.h:121
lldb::eLanguageTypeC_plus_plus
@ eLanguageTypeC_plus_plus
ISO C++:1998.
Definition: lldb-enumerations.h:445
lldb_private::npdb::IsTagRecord
bool IsTagRecord(llvm::codeview::CVType cvt)
Definition: PdbUtil.cpp:517
lldb_private::npdb::PdbAstBuilder::TryGetDecl
clang::Decl * TryGetDecl(PdbSymUid uid) const
Definition: PdbAstBuilder.cpp:633
lldb_private::npdb::PdbAstBuilder::TypeIndex
llvm::codeview::TypeIndex TypeIndex
Definition: PdbAstBuilder.h:94
lldb_private::npdb::PdbCompilandSymId::offset
uint32_t offset
Definition: PdbSymUid.h:54
lldb_private::npdb::GetBestPossibleDecl
PdbTypeSymId GetBestPossibleDecl(PdbTypeSymId id, llvm::pdb::TpiStream &tpi)
lldb_private::ClangASTMetadata::SetIsDynamicCXXType
void SetIsDynamicCXXType(bool b)
Definition: ClangASTMetadata.h:27
lldb_private::npdb::PdbAstBuilder::CompleteTagDecl
bool CompleteTagDecl(clang::TagDecl &tag)
Definition: PdbAstBuilder.cpp:433
lldb_private::npdb::PdbAstBuilder::Dump
void Dump(Stream &stream)
Definition: PdbAstBuilder.cpp:1448
lldb_private::npdb::PdbSymUidKind::GlobalSym
@ GlobalSym
lldb_private::TypeSystemClang::GetUniqueNamespaceDeclaration
clang::NamespaceDecl * GetUniqueNamespaceDeclaration(const char *name, clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, bool is_inline=false)
Definition: TypeSystemClang.cpp:1870
PdbAstBuilder.h
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::ClangASTMetadata
Definition: ClangASTMetadata.h:18
lldb_private::npdb::PdbAstBuilder::CreateArrayType
clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array)
Definition: PdbAstBuilder.cpp:1162
lldb_private::npdb::SymbolFileNativePDB::GetIndex
PdbIndex & GetIndex()
Definition: SymbolFileNativePDB.h:163
lldb_private::npdb::CVTagRecord::asTag
const llvm::codeview::TagRecord & asTag() const
Definition: PdbUtil.h:44
lldb_private::npdb::PdbTypeSymId::is_ipi
bool is_ipi
Definition: PdbSymUid.h:80
lldb_private::npdb::PdbAstBuilder::CompleteType
bool CompleteType(clang::QualType qt)
Definition: PdbAstBuilder.cpp:419
lldb_private::npdb::PdbAstBuilder::m_uid_to_type
llvm::DenseMap< lldb::user_id_t, clang::QualType > m_uid_to_type
Definition: PdbAstBuilder.h:145
lldb_private::CompilerType::IsValid
bool IsValid() const
Definition: CompilerType.h:123
lldb_private::CompilerDeclContext
Represents a generic declaration context in a program.
Definition: CompilerDeclContext.h:30
PdbUtil.h
lldb_private::npdb::PdbAstBuilder::CreateSimpleType
clang::QualType CreateSimpleType(TypeIndex ti)
Definition: PdbAstBuilder.cpp:493
ObjectFile.h
lldb_private::TypeSystemClang::GetType
CompilerType GetType(clang::QualType qt)
Creates a CompilerType form the given QualType with the current TypeSystemClang instance as the Compi...
Definition: TypeSystemClang.h:237
lldb_private::npdb::PdbAstBuilder::m_decl_to_status
llvm::DenseMap< clang::Decl *, DeclStatus > m_decl_to_status
Definition: PdbAstBuilder.h:143
lldb_private::TypeSystemClang::SetFunctionParameters
void SetFunctionParameters(clang::FunctionDecl *function_decl, llvm::ArrayRef< clang::ParmVarDecl * > params)
Definition: TypeSystemClang.cpp:2241
lldb::eAccessPublic
@ eAccessPublic
Definition: lldb-enumerations.h:513
lldbassert
#define lldbassert(x)
Definition: LLDBAssert.h:15
lldb_private::npdb::PdbAstBuilder::CreatePointerType
clang::QualType CreatePointerType(const llvm::codeview::PointerRecord &pointer)
Definition: PdbAstBuilder.cpp:514
lldb_private::npdb::PdbAstBuilder::m_parse_functions_and_non_local_vars
llvm::once_flag m_parse_functions_and_non_local_vars
Definition: PdbAstBuilder.h:141
lldb_private::ClangUtil::GetDecl
static clang::Decl * GetDecl(const CompilerDecl &decl)
Returns the clang::Decl of the given CompilerDecl.
Definition: ClangUtil.cpp:31
isLocalVariableType
static bool isLocalVariableType(SymbolKind K)
Definition: PdbAstBuilder.cpp:228
lldb_private::npdb::PdbAstBuilder::GetOrCreateInlinedFunctionDecl
clang::FunctionDecl * GetOrCreateInlinedFunctionDecl(PdbCompilandSymId inlinesite_id)
Definition: PdbAstBuilder.cpp:919
lldb_private::npdb::VariableInfo
Definition: PdbUtil.h:102
lldb_private::npdb::CompilandIndexItem
Represents a single compile unit.
Definition: CompileUnitIndex.h:39
lldb_private::OptionalClangModuleID
A Clang module ID.
Definition: TypeSystemClang.h:56
lldb_private::TypeSystemClang::GetAsTypedefDecl
static clang::TypedefNameDecl * GetAsTypedefDecl(const CompilerType &type)
Definition: TypeSystemClang.cpp:7329
uint32_t
lldb::eAccessPrivate
@ eAccessPrivate
Definition: lldb-enumerations.h:514
UdtRecordCompleter.h
lldb_private::npdb::UdtRecordCompleter
Definition: UdtRecordCompleter.h:39
lldb_private::TypeSystemClang::CreateVariableDeclaration
clang::VarDecl * CreateVariableDeclaration(clang::DeclContext *decl_context, OptionalClangModuleID owning_module, const char *name, clang::QualType type)
Definition: TypeSystemClang.cpp:2002
lldb_private::npdb::PdbAstBuilder::GetOrCreateDeclContextForUid
clang::DeclContext * GetOrCreateDeclContextForUid(PdbSymUid uid)
Definition: PdbAstBuilder.cpp:304
lldb_private::npdb::PdbAstBuilder::ParseDeclsForContext
void ParseDeclsForContext(clang::DeclContext &context)
Definition: PdbAstBuilder.cpp:1402
lldb_private::npdb::PdbAstBuilder::CreateModifierType
clang::QualType CreateModifierType(const llvm::codeview::ModifierRecord &modifier)
Definition: PdbAstBuilder.cpp:586
lldb_private::Stream::AsRawOstream
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:357
lldb_private::SymbolFile::GetBackingSymbolFile
virtual SymbolFile * GetBackingSymbolFile()
SymbolFileOnDemand class overrides this to return the underlying backing SymbolFile implementation th...
Definition: SymbolFile.h:83
lldb_private::npdb::PdbAstBuilder::ParseAllTypes
void ParseAllTypes()
Definition: PdbAstBuilder.cpp:1273
uint16_t
lldb::eBasicTypeNullPtr
@ eBasicTypeNullPtr
Definition: lldb-enumerations.h:784
AnyScopesHaveTemplateParams
static bool AnyScopesHaveTemplateParams(llvm::ArrayRef< llvm::ms_demangle::Node * > scopes)
Definition: PdbAstBuilder.cpp:122
IsCVarArgsFunction
static bool IsCVarArgsFunction(llvm::ArrayRef< TypeIndex > args)
Definition: PdbAstBuilder.cpp:115
lldb_private::npdb::PdbSymUid::kind
PdbSymUidKind kind() const
Definition: PdbSymUid.cpp:112
lldb_private::npdb::PdbAstBuilder::ParseNamespace
void ParseNamespace(clang::DeclContext &parent)
Definition: PdbAstBuilder.cpp:1234
lldb_private::npdb::PdbAstBuilder::m_cxx_record_map
llvm::DenseMap< lldb::opaque_compiler_type_t, llvm::SmallSet< std::pair< llvm::StringRef, CompilerType >, 8 > > m_cxx_record_map
Definition: PdbAstBuilder.h:151
lldb_private::npdb::PdbIndex::ipi
llvm::pdb::TpiStream & ipi()
Definition: PdbIndex.h:127
SymbolFileNativePDB.h
lldb_private::TypeSystemClang::CreateRecordType
CompilerType CreateRecordType(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, lldb::AccessType access_type, llvm::StringRef name, int kind, lldb::LanguageType language, ClangASTMetadata *metadata=nullptr, bool exports_symbols=false)
Definition: TypeSystemClang.cpp:1270
clang
Definition: ASTResultSynthesizer.h:15
lldb_private::npdb::PdbAstBuilder::GetOrCreateType
clang::QualType GetOrCreateType(PdbTypeSymId type)
Definition: PdbAstBuilder.cpp:804
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:35
lldb_private::npdb::PdbAstBuilder::CreateFunctionDecl
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)
Definition: PdbAstBuilder.cpp:848
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
lldb_private::TypeSystemClang::StartTagDeclarationDefinition
static bool StartTagDeclarationDefinition(const CompilerType &type)
Definition: TypeSystemClang.cpp:8309
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::npdb::PdbSymUid::asGlobalSym
PdbGlobalSymId asGlobalSym() const
Definition: PdbSymUid.cpp:134
lldb_private::npdb::PdbAstBuilder::GetOrCreateDeclForUid
llvm::Optional< lldb_private::CompilerDecl > GetOrCreateDeclForUid(PdbSymUid uid)
Definition: PdbAstBuilder.cpp:275
lldb_private::npdb::PdbAstBuilder::ToCompilerDecl
CompilerDecl ToCompilerDecl(clang::Decl &decl)
Definition: PdbAstBuilder.cpp:1426
llvm::codeview
Definition: DWARFLocationExpression.h:20
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:34
lldb_private::npdb::PdbAstBuilder::CreateFunctionType
clang::QualType CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx, llvm::codeview::CallingConvention calling_convention)
Definition: PdbAstBuilder.cpp:1178
lldb_private::TypeSystemClang::GetBasicType
CompilerType GetBasicType(lldb::BasicType type)
Definition: TypeSystemClang.cpp:931
lldb_private::npdb::PdbAstBuilder::GetOrCreateVariableDecl
clang::VarDecl * GetOrCreateVariableDecl(PdbCompilandSymId scope_id, PdbCompilandSymId var_id)
Definition: PdbAstBuilder.cpp:686
lldb_private::TypeSystemClang
A TypeSystem implementation based on Clang.
Definition: TypeSystemClang.h:105
lldb_private::npdb::DeclStatus::uid
lldb::user_id_t uid
Definition: PdbAstBuilder.h:48
lldb_private::TypeSystemClang::SetHasExternalStorage
static bool SetHasExternalStorage(lldb::opaque_compiler_type_t type, bool has_extern)
Definition: TypeSystemClang.cpp:8256
isFunctionDecl
static bool isFunctionDecl(clang::DeclContext &context)
Definition: PdbAstBuilder.cpp:1226
lldb_private::npdb::PdbAstBuilder::ParseBlockChildren
void ParseBlockChildren(PdbCompilandSymId block_id)
Definition: PdbAstBuilder.cpp:1352
lldb_private::TypeSystem::GetSymbolFile
virtual SymbolFile * GetSymbolFile() const
Definition: TypeSystem.h:98
lldb_private::TypeSystemClang::AddMethodToCXXRecordType
clang::CXXMethodDecl * AddMethodToCXXRecordType(lldb::opaque_compiler_type_t type, llvm::StringRef name, const char *mangled_name, const CompilerType &method_type, lldb::AccessType access, bool is_virtual, bool is_static, bool is_inline, bool is_explicit, bool is_attr_used, bool is_artificial)
Definition: TypeSystemClang.cpp:7647
lldb_private::TypeSystemClang::Dump
void Dump(llvm::raw_ostream &output) override
Definition: TypeSystemClang.cpp:8517
lldb_private::npdb::SymbolFileNativePDB::FindSymbolScope
llvm::Optional< PdbCompilandSymId > FindSymbolScope(PdbCompilandSymId id)
Definition: SymbolFileNativePDB.cpp:2270
lldb_private::npdb::PdbSymUid
Definition: PdbSymUid.h:91
lldb_private::npdb::CVTagRecord::Enum
@ Enum
Definition: PdbUtil.h:38
lldb_private::Declaration
Definition: Declaration.h:24
lldb_private::npdb::CVTagRecord
Definition: PdbUtil.h:37
lldb_private::npdb::PdbAstBuilder::ParseDeclsForSimpleContext
void ParseDeclsForSimpleContext(clang::DeclContext &context)
Definition: PdbAstBuilder.cpp:1383
isBlockDecl
static bool isBlockDecl(clang::DeclContext &context)
Definition: PdbAstBuilder.cpp:1230
lldb::AccessType
AccessType
Definition: lldb-enumerations.h:511
lldb_private::npdb::PdbAstBuilder::GetOrCreateSymbolForId
clang::Decl * GetOrCreateSymbolForId(PdbCompilandSymId id)
Definition: PdbAstBuilder.cpp:240
lldb::opaque_compiler_type_t
void * opaque_compiler_type_t
Definition: lldb-types.h:90
lldb_private::npdb::IsForwardRefUdt
bool IsForwardRefUdt(llvm::codeview::CVType cvt)
MSVCUndecoratedNameSpecifier
Definition: MSVCUndecoratedNameParser.h:17