LLDB  mainline
DWARFASTParserClang.cpp
Go to the documentation of this file.
1 //===-- DWARFASTParserClang.cpp -------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include <cstdlib>
10 
11 #include "DWARFASTParserClang.h"
12 #include "DWARFDebugInfo.h"
13 #include "DWARFDeclContext.h"
14 #include "DWARFDefines.h"
15 #include "SymbolFileDWARF.h"
17 #include "SymbolFileDWARFDwo.h"
18 #include "UniqueDWARFASTType.h"
19 
24 #include "lldb/Core/Module.h"
25 #include "lldb/Core/Value.h"
26 #include "lldb/Host/Host.h"
28 #include "lldb/Symbol/Function.h"
29 #include "lldb/Symbol/ObjectFile.h"
30 #include "lldb/Symbol/SymbolFile.h"
31 #include "lldb/Symbol/TypeList.h"
32 #include "lldb/Symbol/TypeMap.h"
33 #include "lldb/Target/Language.h"
35 #include "lldb/Utility/Log.h"
37 
38 #include "llvm/Demangle/Demangle.h"
39 
40 #include "clang/AST/CXXInheritance.h"
41 #include "clang/AST/DeclCXX.h"
42 #include "clang/AST/DeclObjC.h"
43 #include "clang/AST/DeclTemplate.h"
44 
45 #include <map>
46 #include <memory>
47 #include <vector>
48 
49 //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
50 
51 #ifdef ENABLE_DEBUG_PRINTF
52 #include <cstdio>
53 #define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
54 #else
55 #define DEBUG_PRINTF(fmt, ...)
56 #endif
57 
58 using namespace lldb;
59 using namespace lldb_private;
61  : m_ast(ast), m_die_to_decl_ctx(), m_decl_ctx_to_die() {}
62 
64 
65 static AccessType DW_ACCESS_to_AccessType(uint32_t dwarf_accessibility) {
66  switch (dwarf_accessibility) {
67  case DW_ACCESS_public:
68  return eAccessPublic;
69  case DW_ACCESS_private:
70  return eAccessPrivate;
71  case DW_ACCESS_protected:
72  return eAccessProtected;
73  default:
74  break;
75  }
76  return eAccessNone;
77 }
78 
79 static bool DeclKindIsCXXClass(clang::Decl::Kind decl_kind) {
80  switch (decl_kind) {
81  case clang::Decl::CXXRecord:
82  case clang::Decl::ClassTemplateSpecialization:
83  return true;
84  default:
85  break;
86  }
87  return false;
88 }
89 
90 
93  m_clang_ast_importer_up = std::make_unique<ClangASTImporter>();
94  }
96 }
97 
98 /// Detect a forward declaration that is nested in a DW_TAG_module.
99 static bool IsClangModuleFwdDecl(const DWARFDIE &Die) {
100  if (!Die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0))
101  return false;
102  auto Parent = Die.GetParent();
103  while (Parent.IsValid()) {
104  if (Parent.Tag() == DW_TAG_module)
105  return true;
106  Parent = Parent.GetParent();
107  }
108  return false;
109 }
110 
112  if (die.IsValid()) {
113  DWARFDIE top_module_die;
114  // Now make sure this DIE is scoped in a DW_TAG_module tag and return true
115  // if so
116  for (DWARFDIE parent = die.GetParent(); parent.IsValid();
117  parent = parent.GetParent()) {
118  const dw_tag_t tag = parent.Tag();
119  if (tag == DW_TAG_module)
120  top_module_die = parent;
121  else if (tag == DW_TAG_compile_unit || tag == DW_TAG_partial_unit)
122  break;
123  }
124 
125  return top_module_die;
126  }
127  return DWARFDIE();
128 }
129 
130 static lldb::ModuleSP GetContainingClangModule(const DWARFDIE &die) {
131  if (die.IsValid()) {
132  DWARFDIE clang_module_die = GetContainingClangModuleDIE(die);
133 
134  if (clang_module_die) {
135  const char *module_name = clang_module_die.GetName();
136  if (module_name)
137  return die.GetDWARF()->GetExternalModule(
138  lldb_private::ConstString(module_name));
139  }
140  }
141  return lldb::ModuleSP();
142 }
143 
145  const DWARFDIE &die,
146  Log *log) {
147  ModuleSP clang_module_sp = GetContainingClangModule(die);
148  if (!clang_module_sp)
149  return TypeSP();
150 
151  // If this type comes from a Clang module, recursively look in the
152  // DWARF section of the .pcm file in the module cache. Clang
153  // generates DWO skeleton units as breadcrumbs to find them.
154  llvm::SmallVector<CompilerContext, 4> decl_context;
155  die.GetDeclContext(decl_context);
156  TypeMap pcm_types;
157 
158  // The type in the Clang module must have the same language as the current CU.
159  LanguageSet languages;
161  llvm::DenseSet<SymbolFile *> searched_symbol_files;
162  clang_module_sp->GetSymbolFile()->FindTypes(decl_context, languages,
163  searched_symbol_files, pcm_types);
164  if (pcm_types.Empty()) {
165  // Since this type is defined in one of the Clang modules imported
166  // by this symbol file, search all of them. Instead of calling
167  // sym_file->FindTypes(), which would return this again, go straight
168  // to the imported modules.
169  auto &sym_file = die.GetCU()->GetSymbolFileDWARF();
170 
171  // Well-formed clang modules never form cycles; guard against corrupted
172  // ones by inserting the current file.
173  searched_symbol_files.insert(&sym_file);
174  sym_file.ForEachExternalModule(
175  *sc.comp_unit, searched_symbol_files, [&](Module &module) {
176  module.GetSymbolFile()->FindTypes(decl_context, languages,
177  searched_symbol_files, pcm_types);
178  return pcm_types.GetSize();
179  });
180  }
181 
182  if (!pcm_types.GetSize())
183  return TypeSP();
184 
185  // We found a real definition for this type in the Clang module, so lets use
186  // it and cache the fact that we found a complete type for this die.
187  TypeSP pcm_type_sp = pcm_types.GetTypeAtIndex(0);
188  if (!pcm_type_sp)
189  return TypeSP();
190 
191  lldb_private::CompilerType pcm_type = pcm_type_sp->GetForwardCompilerType();
193  GetClangASTImporter().CopyType(m_ast, pcm_type);
194 
195  if (!type)
196  return TypeSP();
197 
198  // Under normal operation pcm_type is a shallow forward declaration
199  // that gets completed later. This is necessary to support cyclic
200  // data structures. If, however, pcm_type is already complete (for
201  // example, because it was loaded for a different target before),
202  // the definition needs to be imported right away, too.
203  // Type::ResolveClangType() effectively ignores the ResolveState
204  // inside type_sp and only looks at IsDefined(), so it never calls
205  // ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo(),
206  // which does extra work for Objective-C classes. This would result
207  // in only the forward declaration to be visible.
208  if (pcm_type.IsDefined())
209  GetClangASTImporter().RequireCompleteType(ClangUtil::GetQualType(type));
210 
211  SymbolFileDWARF *dwarf = die.GetDWARF();
212  TypeSP type_sp(new Type(die.GetID(), dwarf, pcm_type_sp->GetName(),
213  pcm_type_sp->GetByteSize(nullptr), nullptr,
215  &pcm_type_sp->GetDeclaration(), type,
216  Type::ResolveState::Forward,
218 
219  dwarf->GetTypeList().Insert(type_sp);
220  dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
221  clang::TagDecl *tag_decl = TypeSystemClang::GetAsTagDecl(type);
222  if (tag_decl) {
223  LinkDeclContextToDIE(tag_decl, die);
224  } else {
225  clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE(die);
226  if (defn_decl_ctx)
227  LinkDeclContextToDIE(defn_decl_ctx, die);
228  }
229 
230  return type_sp;
231 }
232 
234  bool started = TypeSystemClang::StartTagDeclarationDefinition(type);
235  lldbassert(started && "Unable to start a class type definition.");
236  TypeSystemClang::CompleteTagDeclarationDefinition(type);
237  const clang::TagDecl *td = ClangUtil::GetAsTagDecl(type);
238  auto &ts = llvm::cast<TypeSystemClang>(*type.GetTypeSystem());
239  ts.GetMetadata(td)->SetIsForcefullyCompleted();
240 }
241 
242 /// Complete a type from debug info, or mark it as forcefully completed if
243 /// there is no definition of the type in the current Module. Call this function
244 /// in contexts where the usual C++ rules require a type to be complete (base
245 /// class, member, etc.).
247  // Technically, enums can be incomplete too, but we don't handle those as they
248  // are emitted even under -flimit-debug-info.
249  if (!TypeSystemClang::IsCXXClassType(type))
250  return;
251 
252  if (type.GetCompleteType())
253  return;
254 
255  // No complete definition in this module. Mark the class as complete to
256  // satisfy local ast invariants, but make a note of the fact that
257  // it is not _really_ complete so we can later search for a definition in a
258  // different module.
259  // Since we provide layout assistance, layouts of types containing this class
260  // will be correct even if we are not able to find the definition elsewhere.
262 }
263 
264 /// This function serves a similar purpose as RequireCompleteType above, but it
265 /// avoids completing the type if it is not immediately necessary. It only
266 /// ensures we _can_ complete the type later.
268  ClangASTImporter &ast_importer,
269  clang::DeclContext *decl_ctx,
270  DWARFDIE die,
271  const char *type_name_cstr) {
272  auto *tag_decl_ctx = clang::dyn_cast<clang::TagDecl>(decl_ctx);
273  if (!tag_decl_ctx)
274  return; // Non-tag context are always ready.
275 
276  // We have already completed the type, or we have found its definition and are
277  // ready to complete it later (cf. ParseStructureLikeDIE).
278  if (tag_decl_ctx->isCompleteDefinition() || tag_decl_ctx->isBeingDefined())
279  return;
280 
281  // We reach this point of the tag was present in the debug info as a
282  // declaration only. If it was imported from another AST context (in the
283  // gmodules case), we can complete the type by doing a full import.
284 
285  // If this type was not imported from an external AST, there's nothing to do.
286  CompilerType type = ast.GetTypeForDecl(tag_decl_ctx);
287  if (type && ast_importer.CanImport(type)) {
288  auto qual_type = ClangUtil::GetQualType(type);
289  if (ast_importer.RequireCompleteType(qual_type))
290  return;
291  die.GetDWARF()->GetObjectFile()->GetModule()->ReportError(
292  "Unable to complete the Decl context for DIE '%s' at offset "
293  "0x%8.8x.\nPlease file a bug report.",
294  type_name_cstr ? type_name_cstr : "", die.GetOffset());
295  }
296 
297  // We don't have a type definition and/or the import failed. We must
298  // forcefully complete the type to avoid crashes.
300 }
301 
303  DWARFAttributes attributes;
304  size_t num_attributes = die.GetAttributes(attributes);
305  for (size_t i = 0; i < num_attributes; ++i) {
306  dw_attr_t attr = attributes.AttributeAtIndex(i);
307  DWARFFormValue form_value;
308  if (!attributes.ExtractFormValueAtIndex(i, form_value))
309  continue;
310  switch (attr) {
311  case DW_AT_abstract_origin:
312  abstract_origin = form_value;
313  break;
314 
315  case DW_AT_accessibility:
317  break;
318 
319  case DW_AT_artificial:
320  is_artificial = form_value.Boolean();
321  break;
322 
323  case DW_AT_bit_stride:
324  bit_stride = form_value.Unsigned();
325  break;
326 
327  case DW_AT_byte_size:
328  byte_size = form_value.Unsigned();
329  break;
330 
331  case DW_AT_byte_stride:
332  byte_stride = form_value.Unsigned();
333  break;
334 
335  case DW_AT_calling_convention:
336  calling_convention = form_value.Unsigned();
337  break;
338 
339  case DW_AT_containing_type:
340  containing_type = form_value;
341  break;
342 
343  case DW_AT_decl_file:
344  // die.GetCU() can differ if DW_AT_specification uses DW_FORM_ref_addr.
345  decl.SetFile(
346  attributes.CompileUnitAtIndex(i)->GetFile(form_value.Unsigned()));
347  break;
348  case DW_AT_decl_line:
349  decl.SetLine(form_value.Unsigned());
350  break;
351  case DW_AT_decl_column:
352  decl.SetColumn(form_value.Unsigned());
353  break;
354 
355  case DW_AT_declaration:
356  is_forward_declaration = form_value.Boolean();
357  break;
358 
359  case DW_AT_encoding:
360  encoding = form_value.Unsigned();
361  break;
362 
363  case DW_AT_enum_class:
364  is_scoped_enum = form_value.Boolean();
365  break;
366 
367  case DW_AT_explicit:
368  is_explicit = form_value.Boolean();
369  break;
370 
371  case DW_AT_external:
372  if (form_value.Unsigned())
373  storage = clang::SC_Extern;
374  break;
375 
376  case DW_AT_inline:
377  is_inline = form_value.Boolean();
378  break;
379 
380  case DW_AT_linkage_name:
381  case DW_AT_MIPS_linkage_name:
382  mangled_name = form_value.AsCString();
383  break;
384 
385  case DW_AT_name:
386  name.SetCString(form_value.AsCString());
387  break;
388 
389  case DW_AT_object_pointer:
390  object_pointer = form_value.Reference();
391  break;
392 
393  case DW_AT_signature:
394  signature = form_value;
395  break;
396 
397  case DW_AT_specification:
398  specification = form_value;
399  break;
400 
401  case DW_AT_type:
402  type = form_value;
403  break;
404 
405  case DW_AT_virtuality:
406  is_virtual = form_value.Boolean();
407  break;
408 
409  case DW_AT_APPLE_objc_complete_type:
410  is_complete_objc_class = form_value.Signed();
411  break;
412 
413  case DW_AT_APPLE_objc_direct:
414  is_objc_direct_call = true;
415  break;
416 
417  case DW_AT_APPLE_runtime_class:
418  class_language = (LanguageType)form_value.Signed();
419  break;
420 
421  case DW_AT_GNU_vector:
422  is_vector = form_value.Boolean();
423  break;
424  case DW_AT_export_symbols:
425  exports_symbols = form_value.Boolean();
426  break;
427  }
428  }
429 }
430 
431 static std::string GetUnitName(const DWARFDIE &die) {
432  if (DWARFUnit *unit = die.GetCU())
433  return unit->GetAbsolutePath().GetPath();
434  return "<missing DWARF unit path>";
435 }
436 
438  const DWARFDIE &die,
439  bool *type_is_new_ptr) {
440  if (type_is_new_ptr)
441  *type_is_new_ptr = false;
442 
443  if (!die)
444  return nullptr;
445 
446  Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION |
448 
449  SymbolFileDWARF *dwarf = die.GetDWARF();
450  if (log) {
451  DWARFDIE context_die;
452  clang::DeclContext *context =
453  GetClangDeclContextContainingDIE(die, &context_die);
454 
455  dwarf->GetObjectFile()->GetModule()->LogMessage(
456  log,
457  "DWARFASTParserClang::ParseTypeFromDWARF "
458  "(die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')",
459  die.GetOffset(), static_cast<void *>(context), context_die.GetOffset(),
460  die.GetTagAsCString(), die.GetName());
461  }
462 
463  Type *type_ptr = dwarf->GetDIEToType().lookup(die.GetDIE());
464  if (type_ptr == DIE_IS_BEING_PARSED)
465  return nullptr;
466  if (type_ptr)
467  return type_ptr->shared_from_this();
468  // Set a bit that lets us know that we are currently parsing this
469  dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED;
470 
471  ParsedDWARFTypeAttributes attrs(die);
472 
473  if (DWARFDIE signature_die = attrs.signature.Reference()) {
474  if (TypeSP type_sp =
475  ParseTypeFromDWARF(sc, signature_die, type_is_new_ptr)) {
476  dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
477  if (clang::DeclContext *decl_ctx =
478  GetCachedClangDeclContextForDIE(signature_die))
479  LinkDeclContextToDIE(decl_ctx, die);
480  return type_sp;
481  }
482  return nullptr;
483  }
484 
485  if (type_is_new_ptr)
486  *type_is_new_ptr = true;
487 
488  const dw_tag_t tag = die.Tag();
489 
490  TypeSP type_sp;
491 
492  switch (tag) {
493  case DW_TAG_typedef:
494  case DW_TAG_base_type:
495  case DW_TAG_pointer_type:
496  case DW_TAG_reference_type:
497  case DW_TAG_rvalue_reference_type:
498  case DW_TAG_const_type:
499  case DW_TAG_restrict_type:
500  case DW_TAG_volatile_type:
501  case DW_TAG_atomic_type:
502  case DW_TAG_unspecified_type: {
503  type_sp = ParseTypeModifier(sc, die, attrs);
504  break;
505  }
506 
507  case DW_TAG_structure_type:
508  case DW_TAG_union_type:
509  case DW_TAG_class_type: {
510  type_sp = ParseStructureLikeDIE(sc, die, attrs);
511  break;
512  }
513 
514  case DW_TAG_enumeration_type: {
515  type_sp = ParseEnum(sc, die, attrs);
516  break;
517  }
518 
519  case DW_TAG_inlined_subroutine:
520  case DW_TAG_subprogram:
521  case DW_TAG_subroutine_type: {
522  type_sp = ParseSubroutine(die, attrs);
523  break;
524  }
525  case DW_TAG_array_type: {
526  type_sp = ParseArrayType(die, attrs);
527  break;
528  }
529  case DW_TAG_ptr_to_member_type: {
530  type_sp = ParsePointerToMemberType(die, attrs);
531  break;
532  }
533  default:
534  dwarf->GetObjectFile()->GetModule()->ReportError(
535  "{0x%8.8x}: unhandled type tag 0x%4.4x (%s), please file a bug and "
536  "attach the file at the start of this error message",
537  die.GetOffset(), tag, DW_TAG_value_to_name(tag));
538  break;
539  }
540 
541  // TODO: We should consider making the switch above exhaustive to simplify
542  // control flow in ParseTypeFromDWARF. Then, we could simply replace this
543  // return statement with a call to llvm_unreachable.
544  return UpdateSymbolContextScopeForType(sc, die, type_sp);
545 }
546 
547 lldb::TypeSP
549  const DWARFDIE &die,
550  ParsedDWARFTypeAttributes &attrs) {
551  Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION |
553  SymbolFileDWARF *dwarf = die.GetDWARF();
554  const dw_tag_t tag = die.Tag();
555  LanguageType cu_language = SymbolFileDWARF::GetLanguage(*die.GetCU());
556  Type::ResolveState resolve_state = Type::ResolveState::Unresolved;
557  Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
558  TypeSP type_sp;
559  CompilerType clang_type;
560 
561  if (tag == DW_TAG_typedef) {
562  // DeclContext will be populated when the clang type is materialized in
563  // Type::ResolveCompilerType.
566  GetClangDeclContextContainingDIE(die, nullptr), die,
567  attrs.name.GetCString());
568 
569  if (attrs.type.IsValid()) {
570  // Try to parse a typedef from the (DWARF embedded in the) Clang
571  // module file first as modules can contain typedef'ed
572  // structures that have no names like:
573  //
574  // typedef struct { int a; } Foo;
575  //
576  // In this case we will have a structure with no name and a
577  // typedef named "Foo" that points to this unnamed
578  // structure. The name in the typedef is the only identifier for
579  // the struct, so always try to get typedefs from Clang modules
580  // if possible.
581  //
582  // The type_sp returned will be empty if the typedef doesn't
583  // exist in a module file, so it is cheap to call this function
584  // just to check.
585  //
586  // If we don't do this we end up creating a TypeSP that says
587  // this is a typedef to type 0x123 (the DW_AT_type value would
588  // be 0x123 in the DW_TAG_typedef), and this is the unnamed
589  // structure type. We will have a hard time tracking down an
590  // unnammed structure type in the module debug info, so we make
591  // sure we don't get into this situation by always resolving
592  // typedefs from the module.
593  const DWARFDIE encoding_die = attrs.type.Reference();
594 
595  // First make sure that the die that this is typedef'ed to _is_
596  // just a declaration (DW_AT_declaration == 1), not a full
597  // definition since template types can't be represented in
598  // modules since only concrete instances of templates are ever
599  // emitted and modules won't contain those
600  if (encoding_die &&
601  encoding_die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0) == 1) {
602  type_sp = ParseTypeFromClangModule(sc, die, log);
603  if (type_sp)
604  return type_sp;
605  }
606  }
607  }
608 
609  DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8lx\n", die.GetID(),
610  DW_TAG_value_to_name(tag), type_name_cstr,
611  encoding_uid.Reference());
612 
613  switch (tag) {
614  default:
615  break;
616 
617  case DW_TAG_unspecified_type:
618  if (attrs.name == "nullptr_t" || attrs.name == "decltype(nullptr)") {
619  resolve_state = Type::ResolveState::Full;
620  clang_type = m_ast.GetBasicType(eBasicTypeNullPtr);
621  break;
622  }
623  // Fall through to base type below in case we can handle the type
624  // there...
625  LLVM_FALLTHROUGH;
626 
627  case DW_TAG_base_type:
628  resolve_state = Type::ResolveState::Full;
630  attrs.name.GetStringRef(), attrs.encoding,
631  attrs.byte_size.getValueOr(0) * 8);
632  break;
633 
634  case DW_TAG_pointer_type:
635  encoding_data_type = Type::eEncodingIsPointerUID;
636  break;
637  case DW_TAG_reference_type:
638  encoding_data_type = Type::eEncodingIsLValueReferenceUID;
639  break;
640  case DW_TAG_rvalue_reference_type:
641  encoding_data_type = Type::eEncodingIsRValueReferenceUID;
642  break;
643  case DW_TAG_typedef:
644  encoding_data_type = Type::eEncodingIsTypedefUID;
645  break;
646  case DW_TAG_const_type:
647  encoding_data_type = Type::eEncodingIsConstUID;
648  break;
649  case DW_TAG_restrict_type:
650  encoding_data_type = Type::eEncodingIsRestrictUID;
651  break;
652  case DW_TAG_volatile_type:
653  encoding_data_type = Type::eEncodingIsVolatileUID;
654  break;
655  case DW_TAG_atomic_type:
656  encoding_data_type = Type::eEncodingIsAtomicUID;
657  break;
658  }
659 
660  if (!clang_type && (encoding_data_type == Type::eEncodingIsPointerUID ||
661  encoding_data_type == Type::eEncodingIsTypedefUID)) {
662  if (tag == DW_TAG_pointer_type) {
663  DWARFDIE target_die = die.GetReferencedDIE(DW_AT_type);
664 
665  if (target_die.GetAttributeValueAsUnsigned(DW_AT_APPLE_block, 0)) {
666  // Blocks have a __FuncPtr inside them which is a pointer to a
667  // function of the proper type.
668 
669  for (DWARFDIE child_die : target_die.children()) {
670  if (!strcmp(child_die.GetAttributeValueAsString(DW_AT_name, ""),
671  "__FuncPtr")) {
672  DWARFDIE function_pointer_type =
673  child_die.GetReferencedDIE(DW_AT_type);
674 
675  if (function_pointer_type) {
676  DWARFDIE function_type =
677  function_pointer_type.GetReferencedDIE(DW_AT_type);
678 
679  bool function_type_is_new_pointer;
680  TypeSP lldb_function_type_sp = ParseTypeFromDWARF(
681  sc, function_type, &function_type_is_new_pointer);
682 
683  if (lldb_function_type_sp) {
684  clang_type = m_ast.CreateBlockPointerType(
685  lldb_function_type_sp->GetForwardCompilerType());
686  encoding_data_type = Type::eEncodingIsUID;
687  attrs.type.Clear();
688  resolve_state = Type::ResolveState::Full;
689  }
690  }
691 
692  break;
693  }
694  }
695  }
696  }
697 
698  if (cu_language == eLanguageTypeObjC ||
699  cu_language == eLanguageTypeObjC_plus_plus) {
700  if (attrs.name) {
701  if (attrs.name == "id") {
702  if (log)
703  dwarf->GetObjectFile()->GetModule()->LogMessage(
704  log,
705  "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' "
706  "is Objective-C 'id' built-in type.",
707  die.GetOffset(), die.GetTagAsCString(), die.GetName());
708  clang_type = m_ast.GetBasicType(eBasicTypeObjCID);
709  encoding_data_type = Type::eEncodingIsUID;
710  attrs.type.Clear();
711  resolve_state = Type::ResolveState::Full;
712  } else if (attrs.name == "Class") {
713  if (log)
714  dwarf->GetObjectFile()->GetModule()->LogMessage(
715  log,
716  "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' "
717  "is Objective-C 'Class' built-in type.",
718  die.GetOffset(), die.GetTagAsCString(), die.GetName());
719  clang_type = m_ast.GetBasicType(eBasicTypeObjCClass);
720  encoding_data_type = Type::eEncodingIsUID;
721  attrs.type.Clear();
722  resolve_state = Type::ResolveState::Full;
723  } else if (attrs.name == "SEL") {
724  if (log)
725  dwarf->GetObjectFile()->GetModule()->LogMessage(
726  log,
727  "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' "
728  "is Objective-C 'selector' built-in type.",
729  die.GetOffset(), die.GetTagAsCString(), die.GetName());
730  clang_type = m_ast.GetBasicType(eBasicTypeObjCSel);
731  encoding_data_type = Type::eEncodingIsUID;
732  attrs.type.Clear();
733  resolve_state = Type::ResolveState::Full;
734  }
735  } else if (encoding_data_type == Type::eEncodingIsPointerUID &&
736  attrs.type.IsValid()) {
737  // Clang sometimes erroneously emits id as objc_object*. In that
738  // case we fix up the type to "id".
739 
740  const DWARFDIE encoding_die = attrs.type.Reference();
741 
742  if (encoding_die && encoding_die.Tag() == DW_TAG_structure_type) {
743  llvm::StringRef struct_name = encoding_die.GetName();
744  if (struct_name == "objc_object") {
745  if (log)
746  dwarf->GetObjectFile()->GetModule()->LogMessage(
747  log,
748  "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s "
749  "'%s' is 'objc_object*', which we overrode to "
750  "'id'.",
751  die.GetOffset(), die.GetTagAsCString(), die.GetName());
752  clang_type = m_ast.GetBasicType(eBasicTypeObjCID);
753  encoding_data_type = Type::eEncodingIsUID;
754  attrs.type.Clear();
755  resolve_state = Type::ResolveState::Full;
756  }
757  }
758  }
759  }
760  }
761 
762  type_sp = std::make_shared<Type>(
763  die.GetID(), dwarf, attrs.name, attrs.byte_size, nullptr,
764  dwarf->GetUID(attrs.type.Reference()), encoding_data_type, &attrs.decl,
765  clang_type, resolve_state, TypePayloadClang(GetOwningClangModule(die)));
766 
767  dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
768  return type_sp;
769 }
770 
772  const DWARFDIE &die,
773  ParsedDWARFTypeAttributes &attrs) {
774  Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION |
776  SymbolFileDWARF *dwarf = die.GetDWARF();
777  const dw_tag_t tag = die.Tag();
778  TypeSP type_sp;
779 
780  if (attrs.is_forward_declaration) {
781  type_sp = ParseTypeFromClangModule(sc, die, log);
782  if (type_sp)
783  return type_sp;
784 
786 
787  type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx);
788 
789  if (!type_sp) {
790  SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile();
791  if (debug_map_symfile) {
792  // We weren't able to find a full declaration in this DWARF,
793  // see if we have a declaration anywhere else...
794  type_sp = debug_map_symfile->FindDefinitionTypeForDWARFDeclContext(
795  die_decl_ctx);
796  }
797  }
798 
799  if (type_sp) {
800  if (log) {
801  dwarf->GetObjectFile()->GetModule()->LogMessage(
802  log,
803  "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a "
804  "forward declaration, complete type is 0x%8.8" PRIx64,
805  static_cast<void *>(this), die.GetOffset(),
806  DW_TAG_value_to_name(tag), attrs.name.GetCString(),
807  type_sp->GetID());
808  }
809 
810  // We found a real definition for this type elsewhere so lets use
811  // it and cache the fact that we found a complete type for this
812  // die
813  dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
814  clang::DeclContext *defn_decl_ctx =
815  GetCachedClangDeclContextForDIE(dwarf->GetDIE(type_sp->GetID()));
816  if (defn_decl_ctx)
817  LinkDeclContextToDIE(defn_decl_ctx, die);
818  return type_sp;
819  }
820  }
821  DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(),
822  DW_TAG_value_to_name(tag), type_name_cstr);
823 
824  CompilerType enumerator_clang_type;
825  CompilerType clang_type;
826  clang_type.SetCompilerType(
827  &m_ast, dwarf->GetForwardDeclDieToClangType().lookup(die.GetDIE()));
828  if (!clang_type) {
829  if (attrs.type.IsValid()) {
830  Type *enumerator_type =
831  dwarf->ResolveTypeUID(attrs.type.Reference(), true);
832  if (enumerator_type)
833  enumerator_clang_type = enumerator_type->GetFullCompilerType();
834  }
835 
836  if (!enumerator_clang_type) {
837  if (attrs.byte_size) {
838  enumerator_clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize(
839  "", DW_ATE_signed, *attrs.byte_size * 8);
840  } else {
841  enumerator_clang_type = m_ast.GetBasicType(eBasicTypeInt);
842  }
843  }
844 
845  clang_type = m_ast.CreateEnumerationType(
846  attrs.name.GetCString(), GetClangDeclContextContainingDIE(die, nullptr),
847  GetOwningClangModule(die), attrs.decl, enumerator_clang_type,
848  attrs.is_scoped_enum);
849  } else {
850  enumerator_clang_type = m_ast.GetEnumerationIntegerType(clang_type);
851  }
852 
853  LinkDeclContextToDIE(TypeSystemClang::GetDeclContextForType(clang_type), die);
854 
855  type_sp = std::make_shared<Type>(
856  die.GetID(), dwarf, attrs.name, attrs.byte_size, nullptr,
857  dwarf->GetUID(attrs.type.Reference()), Type::eEncodingIsUID, &attrs.decl,
858  clang_type, Type::ResolveState::Forward,
860 
861  if (TypeSystemClang::StartTagDeclarationDefinition(clang_type)) {
862  if (die.HasChildren()) {
863  bool is_signed = false;
864  enumerator_clang_type.IsIntegerType(is_signed);
865  ParseChildEnumerators(clang_type, is_signed,
866  type_sp->GetByteSize(nullptr).getValueOr(0), die);
867  }
868  TypeSystemClang::CompleteTagDeclarationDefinition(clang_type);
869  } else {
870  dwarf->GetObjectFile()->GetModule()->ReportError(
871  "DWARF DIE at 0x%8.8x named \"%s\" was not able to start its "
872  "definition.\nPlease file a bug and attach the file at the "
873  "start of this error message",
874  die.GetOffset(), attrs.name.GetCString());
875  }
876  return type_sp;
877 }
878 
879 static clang::CallingConv
881  switch (attrs.calling_convention) {
882  case llvm::dwarf::DW_CC_normal:
883  return clang::CC_C;
884  case llvm::dwarf::DW_CC_BORLAND_stdcall:
885  return clang::CC_X86StdCall;
886  case llvm::dwarf::DW_CC_BORLAND_msfastcall:
887  return clang::CC_X86FastCall;
888  case llvm::dwarf::DW_CC_LLVM_vectorcall:
889  return clang::CC_X86VectorCall;
890  case llvm::dwarf::DW_CC_BORLAND_pascal:
891  return clang::CC_X86Pascal;
892  case llvm::dwarf::DW_CC_LLVM_Win64:
893  return clang::CC_Win64;
894  case llvm::dwarf::DW_CC_LLVM_X86_64SysV:
895  return clang::CC_X86_64SysV;
896  case llvm::dwarf::DW_CC_LLVM_X86RegCall:
897  return clang::CC_X86RegCall;
898  default:
899  break;
900  }
901 
902  Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION |
904  LLDB_LOG(log, "Unsupported DW_AT_calling_convention value: {0}",
905  attrs.calling_convention);
906  // Use the default calling convention as a fallback.
907  return clang::CC_C;
908 }
909 
911  ParsedDWARFTypeAttributes &attrs) {
912  Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION |
914 
915  SymbolFileDWARF *dwarf = die.GetDWARF();
916  const dw_tag_t tag = die.Tag();
917 
918  bool is_variadic = false;
919  bool is_static = false;
920  bool has_template_params = false;
921 
922  unsigned type_quals = 0;
923 
924  std::string object_pointer_name;
925  if (attrs.object_pointer) {
926  const char *object_pointer_name_cstr = attrs.object_pointer.GetName();
927  if (object_pointer_name_cstr)
928  object_pointer_name = object_pointer_name_cstr;
929  }
930 
931  DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(),
932  DW_TAG_value_to_name(tag), type_name_cstr);
933 
934  CompilerType return_clang_type;
935  Type *func_type = NULL;
936 
937  if (attrs.type.IsValid())
938  func_type = dwarf->ResolveTypeUID(attrs.type.Reference(), true);
939 
940  if (func_type)
941  return_clang_type = func_type->GetForwardCompilerType();
942  else
943  return_clang_type = m_ast.GetBasicType(eBasicTypeVoid);
944 
945  std::vector<CompilerType> function_param_types;
946  std::vector<clang::ParmVarDecl *> function_param_decls;
947 
948  // Parse the function children for the parameters
949 
950  DWARFDIE decl_ctx_die;
951  clang::DeclContext *containing_decl_ctx =
952  GetClangDeclContextContainingDIE(die, &decl_ctx_die);
953  const clang::Decl::Kind containing_decl_kind =
954  containing_decl_ctx->getDeclKind();
955 
956  bool is_cxx_method = DeclKindIsCXXClass(containing_decl_kind);
957  // Start off static. This will be set to false in
958  // ParseChildParameters(...) if we find a "this" parameters as the
959  // first parameter
960  if (is_cxx_method) {
961  is_static = true;
962  }
963 
964  if (die.HasChildren()) {
965  bool skip_artificial = true;
966  ParseChildParameters(containing_decl_ctx, die, skip_artificial, is_static,
967  is_variadic, has_template_params,
968  function_param_types, function_param_decls,
969  type_quals);
970  }
971 
972  bool ignore_containing_context = false;
973  // Check for templatized class member functions. If we had any
974  // DW_TAG_template_type_parameter or DW_TAG_template_value_parameter
975  // the DW_TAG_subprogram DIE, then we can't let this become a method in
976  // a class. Why? Because templatized functions are only emitted if one
977  // of the templatized methods is used in the current compile unit and
978  // we will end up with classes that may or may not include these member
979  // functions and this means one class won't match another class
980  // definition and it affects our ability to use a class in the clang
981  // expression parser. So for the greater good, we currently must not
982  // allow any template member functions in a class definition.
983  if (is_cxx_method && has_template_params) {
984  ignore_containing_context = true;
985  is_cxx_method = false;
986  }
987 
988  clang::CallingConv calling_convention =
990 
991  // clang_type will get the function prototype clang type after this
992  // call
994  return_clang_type, function_param_types.data(),
995  function_param_types.size(), is_variadic, type_quals, calling_convention);
996 
997  if (attrs.name) {
998  bool type_handled = false;
999  if (tag == DW_TAG_subprogram || tag == DW_TAG_inlined_subroutine) {
1000  ObjCLanguage::MethodName objc_method(attrs.name.GetStringRef(), true);
1001  if (objc_method.IsValid(true)) {
1002  CompilerType class_opaque_type;
1003  ConstString class_name(objc_method.GetClassName());
1004  if (class_name) {
1005  TypeSP complete_objc_class_type_sp(
1006  dwarf->FindCompleteObjCDefinitionTypeForDIE(DWARFDIE(),
1007  class_name, false));
1008 
1009  if (complete_objc_class_type_sp) {
1010  CompilerType type_clang_forward_type =
1011  complete_objc_class_type_sp->GetForwardCompilerType();
1012  if (TypeSystemClang::IsObjCObjectOrInterfaceType(
1013  type_clang_forward_type))
1014  class_opaque_type = type_clang_forward_type;
1015  }
1016  }
1017 
1018  if (class_opaque_type) {
1019  // If accessibility isn't set to anything valid, assume public
1020  // for now...
1021  if (attrs.accessibility == eAccessNone)
1022  attrs.accessibility = eAccessPublic;
1023 
1024  clang::ObjCMethodDecl *objc_method_decl =
1026  class_opaque_type, attrs.name.GetCString(), clang_type,
1027  attrs.accessibility, attrs.is_artificial, is_variadic,
1028  attrs.is_objc_direct_call);
1029  type_handled = objc_method_decl != NULL;
1030  if (type_handled) {
1031  LinkDeclContextToDIE(objc_method_decl, die);
1032  m_ast.SetMetadataAsUserID(objc_method_decl, die.GetID());
1033  } else {
1034  dwarf->GetObjectFile()->GetModule()->ReportError(
1035  "{0x%8.8x}: invalid Objective-C method 0x%4.4x (%s), "
1036  "please file a bug and attach the file at the start of "
1037  "this error message",
1038  die.GetOffset(), tag, DW_TAG_value_to_name(tag));
1039  }
1040  }
1041  } else if (is_cxx_method) {
1042  // Look at the parent of this DIE and see if is is a class or
1043  // struct and see if this is actually a C++ method
1044  Type *class_type = dwarf->ResolveType(decl_ctx_die);
1045  if (class_type) {
1046  bool alternate_defn = false;
1047  if (class_type->GetID() != decl_ctx_die.GetID() ||
1048  IsClangModuleFwdDecl(decl_ctx_die)) {
1049  alternate_defn = true;
1050 
1051  // We uniqued the parent class of this function to another
1052  // class so we now need to associate all dies under
1053  // "decl_ctx_die" to DIEs in the DIE for "class_type"...
1054  DWARFDIE class_type_die = dwarf->GetDIE(class_type->GetID());
1055 
1056  if (class_type_die) {
1057  std::vector<DWARFDIE> failures;
1058 
1059  CopyUniqueClassMethodTypes(decl_ctx_die, class_type_die,
1060  class_type, failures);
1061 
1062  // FIXME do something with these failures that's
1063  // smarter than just dropping them on the ground.
1064  // Unfortunately classes don't like having stuff added
1065  // to them after their definitions are complete...
1066 
1067  Type *type_ptr = dwarf->GetDIEToType()[die.GetDIE()];
1068  if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) {
1069  return type_ptr->shared_from_this();
1070  }
1071  }
1072  }
1073 
1074  if (attrs.specification.IsValid()) {
1075  // We have a specification which we are going to base our
1076  // function prototype off of, so we need this type to be
1077  // completed so that the m_die_to_decl_ctx for the method in
1078  // the specification has a valid clang decl context.
1079  class_type->GetForwardCompilerType();
1080  // If we have a specification, then the function type should
1081  // have been made with the specification and not with this
1082  // die.
1083  DWARFDIE spec_die = attrs.specification.Reference();
1084  clang::DeclContext *spec_clang_decl_ctx =
1085  GetClangDeclContextForDIE(spec_die);
1086  if (spec_clang_decl_ctx) {
1087  LinkDeclContextToDIE(spec_clang_decl_ctx, die);
1088  } else {
1089  dwarf->GetObjectFile()->GetModule()->ReportWarning(
1090  "0x%8.8" PRIx64 ": DW_AT_specification(0x%8.8x"
1091  ") has no decl\n",
1092  die.GetID(), spec_die.GetOffset());
1093  }
1094  type_handled = true;
1095  } else if (attrs.abstract_origin.IsValid()) {
1096  // We have a specification which we are going to base our
1097  // function prototype off of, so we need this type to be
1098  // completed so that the m_die_to_decl_ctx for the method in
1099  // the abstract origin has a valid clang decl context.
1100  class_type->GetForwardCompilerType();
1101 
1102  DWARFDIE abs_die = attrs.abstract_origin.Reference();
1103  clang::DeclContext *abs_clang_decl_ctx =
1104  GetClangDeclContextForDIE(abs_die);
1105  if (abs_clang_decl_ctx) {
1106  LinkDeclContextToDIE(abs_clang_decl_ctx, die);
1107  } else {
1108  dwarf->GetObjectFile()->GetModule()->ReportWarning(
1109  "0x%8.8" PRIx64 ": DW_AT_abstract_origin(0x%8.8x"
1110  ") has no decl\n",
1111  die.GetID(), abs_die.GetOffset());
1112  }
1113  type_handled = true;
1114  } else {
1115  CompilerType class_opaque_type =
1116  class_type->GetForwardCompilerType();
1117  if (TypeSystemClang::IsCXXClassType(class_opaque_type)) {
1118  if (class_opaque_type.IsBeingDefined() || alternate_defn) {
1119  if (!is_static && !die.HasChildren()) {
1120  // We have a C++ member function with no children (this
1121  // pointer!) and clang will get mad if we try and make
1122  // a function that isn't well formed in the DWARF, so
1123  // we will just skip it...
1124  type_handled = true;
1125  } else {
1126  bool add_method = true;
1127  if (alternate_defn) {
1128  // If an alternate definition for the class exists,
1129  // then add the method only if an equivalent is not
1130  // already present.
1131  clang::CXXRecordDecl *record_decl =
1133  class_opaque_type.GetOpaqueQualType());
1134  if (record_decl) {
1135  for (auto method_iter = record_decl->method_begin();
1136  method_iter != record_decl->method_end();
1137  method_iter++) {
1138  clang::CXXMethodDecl *method_decl = *method_iter;
1139  if (method_decl->getNameInfo().getAsString() ==
1140  attrs.name.GetStringRef()) {
1141  if (method_decl->getType() ==
1142  ClangUtil::GetQualType(clang_type)) {
1143  add_method = false;
1144  LinkDeclContextToDIE(method_decl, die);
1145  type_handled = true;
1146 
1147  break;
1148  }
1149  }
1150  }
1151  }
1152  }
1153 
1154  if (add_method) {
1155  llvm::PrettyStackTraceFormat stack_trace(
1156  "SymbolFileDWARF::ParseType() is adding a method "
1157  "%s to class %s in DIE 0x%8.8" PRIx64 " from %s",
1158  attrs.name.GetCString(),
1159  class_type->GetName().GetCString(), die.GetID(),
1160  dwarf->GetObjectFile()
1161  ->GetFileSpec()
1162  .GetPath()
1163  .c_str());
1164 
1165  const bool is_attr_used = false;
1166  // Neither GCC 4.2 nor clang++ currently set a valid
1167  // accessibility in the DWARF for C++ methods...
1168  // Default to public for now...
1169  if (attrs.accessibility == eAccessNone)
1170  attrs.accessibility = eAccessPublic;
1171 
1172  clang::CXXMethodDecl *cxx_method_decl =
1174  class_opaque_type.GetOpaqueQualType(),
1175  attrs.name.GetCString(), attrs.mangled_name,
1176  clang_type, attrs.accessibility, attrs.is_virtual,
1177  is_static, attrs.is_inline, attrs.is_explicit,
1178  is_attr_used, attrs.is_artificial);
1179 
1180  type_handled = cxx_method_decl != NULL;
1181  // Artificial methods are always handled even when we
1182  // don't create a new declaration for them.
1183  type_handled |= attrs.is_artificial;
1184 
1185  if (cxx_method_decl) {
1186  LinkDeclContextToDIE(cxx_method_decl, die);
1187 
1188  ClangASTMetadata metadata;
1189  metadata.SetUserID(die.GetID());
1190 
1191  if (!object_pointer_name.empty()) {
1192  metadata.SetObjectPtrName(
1193  object_pointer_name.c_str());
1194  LLDB_LOGF(log,
1195  "Setting object pointer name: %s on method "
1196  "object %p.\n",
1197  object_pointer_name.c_str(),
1198  static_cast<void *>(cxx_method_decl));
1199  }
1200  m_ast.SetMetadata(cxx_method_decl, metadata);
1201  } else {
1202  ignore_containing_context = true;
1203  }
1204  }
1205  }
1206  } else {
1207  // We were asked to parse the type for a method in a
1208  // class, yet the class hasn't been asked to complete
1209  // itself through the clang::ExternalASTSource protocol,
1210  // so we need to just have the class complete itself and
1211  // do things the right way, then our
1212  // DIE should then have an entry in the
1213  // dwarf->GetDIEToType() map. First
1214  // we need to modify the dwarf->GetDIEToType() so it
1215  // doesn't think we are trying to parse this DIE
1216  // anymore...
1217  dwarf->GetDIEToType()[die.GetDIE()] = NULL;
1218 
1219  // Now we get the full type to force our class type to
1220  // complete itself using the clang::ExternalASTSource
1221  // protocol which will parse all base classes and all
1222  // methods (including the method for this DIE).
1223  class_type->GetFullCompilerType();
1224 
1225  // The type for this DIE should have been filled in the
1226  // function call above
1227  Type *type_ptr = dwarf->GetDIEToType()[die.GetDIE()];
1228  if (type_ptr && type_ptr != DIE_IS_BEING_PARSED) {
1229  return type_ptr->shared_from_this();
1230  }
1231 
1232  // FIXME This is fixing some even uglier behavior but we
1233  // really need to
1234  // uniq the methods of each class as well as the class
1235  // itself. <rdar://problem/11240464>
1236  type_handled = true;
1237  }
1238  }
1239  }
1240  }
1241  }
1242  }
1243 
1244  if (!type_handled) {
1245  clang::FunctionDecl *function_decl = nullptr;
1246  clang::FunctionDecl *template_function_decl = nullptr;
1247 
1248  if (attrs.abstract_origin.IsValid()) {
1249  DWARFDIE abs_die = attrs.abstract_origin.Reference();
1250 
1251  if (dwarf->ResolveType(abs_die)) {
1252  function_decl = llvm::dyn_cast_or_null<clang::FunctionDecl>(
1254 
1255  if (function_decl) {
1256  LinkDeclContextToDIE(function_decl, die);
1257  }
1258  }
1259  }
1260 
1261  if (!function_decl) {
1262  char *name_buf = nullptr;
1263  llvm::StringRef name = attrs.name.GetStringRef();
1264 
1265  // We currently generate function templates with template parameters in
1266  // their name. In order to get closer to the AST that clang generates
1267  // we want to strip these from the name when creating the AST.
1268  if (attrs.mangled_name) {
1269  llvm::ItaniumPartialDemangler D;
1270  if (!D.partialDemangle(attrs.mangled_name)) {
1271  name_buf = D.getFunctionBaseName(nullptr, nullptr);
1272  name = name_buf;
1273  }
1274  }
1275 
1276  // We just have a function that isn't part of a class
1277  function_decl = m_ast.CreateFunctionDeclaration(
1278  ignore_containing_context ? m_ast.GetTranslationUnitDecl()
1279  : containing_decl_ctx,
1280  GetOwningClangModule(die), name, clang_type, attrs.storage,
1281  attrs.is_inline);
1282  std::free(name_buf);
1283 
1284  if (has_template_params) {
1285  TypeSystemClang::TemplateParameterInfos template_param_infos;
1286  ParseTemplateParameterInfos(die, template_param_infos);
1287  template_function_decl = m_ast.CreateFunctionDeclaration(
1288  ignore_containing_context ? m_ast.GetTranslationUnitDecl()
1289  : containing_decl_ctx,
1290  GetOwningClangModule(die), attrs.name.GetStringRef(), clang_type,
1291  attrs.storage, attrs.is_inline);
1292  clang::FunctionTemplateDecl *func_template_decl =
1294  containing_decl_ctx, GetOwningClangModule(die),
1295  template_function_decl, template_param_infos);
1297  template_function_decl, func_template_decl, template_param_infos);
1298  }
1299 
1300  lldbassert(function_decl);
1301 
1302  if (function_decl) {
1303  LinkDeclContextToDIE(function_decl, die);
1304 
1305  if (!function_param_decls.empty()) {
1306  m_ast.SetFunctionParameters(function_decl, function_param_decls);
1307  if (template_function_decl)
1308  m_ast.SetFunctionParameters(template_function_decl,
1309  function_param_decls);
1310  }
1311 
1312  ClangASTMetadata metadata;
1313  metadata.SetUserID(die.GetID());
1314 
1315  if (!object_pointer_name.empty()) {
1316  metadata.SetObjectPtrName(object_pointer_name.c_str());
1317  LLDB_LOGF(log,
1318  "Setting object pointer name: %s on function "
1319  "object %p.",
1320  object_pointer_name.c_str(),
1321  static_cast<void *>(function_decl));
1322  }
1323  m_ast.SetMetadata(function_decl, metadata);
1324  }
1325  }
1326  }
1327  }
1328  return std::make_shared<Type>(
1329  die.GetID(), dwarf, attrs.name, llvm::None, nullptr, LLDB_INVALID_UID,
1330  Type::eEncodingIsUID, &attrs.decl, clang_type, Type::ResolveState::Full);
1331 }
1332 
1334  ParsedDWARFTypeAttributes &attrs) {
1335  SymbolFileDWARF *dwarf = die.GetDWARF();
1336 
1337  DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(),
1338  DW_TAG_value_to_name(tag), type_name_cstr);
1339 
1340  DWARFDIE type_die = attrs.type.Reference();
1341  Type *element_type = dwarf->ResolveTypeUID(type_die, true);
1342 
1343  if (!element_type)
1344  return nullptr;
1345 
1346  llvm::Optional<SymbolFile::ArrayInfo> array_info = ParseChildArrayInfo(die);
1347  if (array_info) {
1348  attrs.byte_stride = array_info->byte_stride;
1349  attrs.bit_stride = array_info->bit_stride;
1350  }
1351  if (attrs.byte_stride == 0 && attrs.bit_stride == 0)
1352  attrs.byte_stride = element_type->GetByteSize(nullptr).getValueOr(0);
1353  CompilerType array_element_type = element_type->GetForwardCompilerType();
1354  RequireCompleteType(array_element_type);
1355 
1356  uint64_t array_element_bit_stride =
1357  attrs.byte_stride * 8 + attrs.bit_stride;
1358  CompilerType clang_type;
1359  if (array_info && array_info->element_orders.size() > 0) {
1360  uint64_t num_elements = 0;
1361  auto end = array_info->element_orders.rend();
1362  for (auto pos = array_info->element_orders.rbegin(); pos != end; ++pos) {
1363  num_elements = *pos;
1364  clang_type = m_ast.CreateArrayType(array_element_type, num_elements,
1365  attrs.is_vector);
1366  array_element_type = clang_type;
1367  array_element_bit_stride = num_elements
1368  ? array_element_bit_stride * num_elements
1369  : array_element_bit_stride;
1370  }
1371  } else {
1372  clang_type =
1373  m_ast.CreateArrayType(array_element_type, 0, attrs.is_vector);
1374  }
1375  ConstString empty_name;
1376  TypeSP type_sp = std::make_shared<Type>(
1377  die.GetID(), dwarf, empty_name, array_element_bit_stride / 8, nullptr,
1378  dwarf->GetUID(type_die), Type::eEncodingIsUID, &attrs.decl, clang_type,
1379  Type::ResolveState::Full);
1380  type_sp->SetEncodingType(element_type);
1381  const clang::Type *type = ClangUtil::GetQualType(clang_type).getTypePtr();
1382  m_ast.SetMetadataAsUserID(type, die.GetID());
1383  return type_sp;
1384 }
1385 
1387  const DWARFDIE &die, const ParsedDWARFTypeAttributes &attrs) {
1388  SymbolFileDWARF *dwarf = die.GetDWARF();
1389  Type *pointee_type = dwarf->ResolveTypeUID(attrs.type.Reference(), true);
1390  Type *class_type =
1391  dwarf->ResolveTypeUID(attrs.containing_type.Reference(), true);
1392 
1393  CompilerType pointee_clang_type = pointee_type->GetForwardCompilerType();
1394  CompilerType class_clang_type = class_type->GetForwardCompilerType();
1395 
1396  CompilerType clang_type = TypeSystemClang::CreateMemberPointerType(
1397  class_clang_type, pointee_clang_type);
1398 
1399  if (llvm::Optional<uint64_t> clang_type_size =
1400  clang_type.GetByteSize(nullptr)) {
1401  return std::make_shared<Type>(die.GetID(), dwarf, attrs.name,
1402  *clang_type_size, nullptr, LLDB_INVALID_UID,
1403  Type::eEncodingIsUID, nullptr, clang_type,
1404  Type::ResolveState::Forward);
1405  }
1406  return nullptr;
1407 }
1408 
1410  const DWARFDIE &die, const DWARFDIE &parent_die,
1411  const CompilerType class_clang_type, const AccessType default_accessibility,
1412  const lldb::ModuleSP &module_sp,
1413  std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> &base_classes,
1414  ClangASTImporter::LayoutInfo &layout_info) {
1415 
1416  TypeSystemClang *ast =
1417  llvm::dyn_cast_or_null<TypeSystemClang>(class_clang_type.GetTypeSystem());
1418  if (ast == nullptr)
1419  return;
1420 
1421  // TODO: implement DW_TAG_inheritance type parsing.
1422  DWARFAttributes attributes;
1423  const size_t num_attributes = die.GetAttributes(attributes);
1424  if (num_attributes == 0)
1425  return;
1426 
1427  DWARFFormValue encoding_form;
1428  AccessType accessibility = default_accessibility;
1429  bool is_virtual = false;
1430  bool is_base_of_class = true;
1431  off_t member_byte_offset = 0;
1432 
1433  for (uint32_t i = 0; i < num_attributes; ++i) {
1434  const dw_attr_t attr = attributes.AttributeAtIndex(i);
1435  DWARFFormValue form_value;
1436  if (attributes.ExtractFormValueAtIndex(i, form_value)) {
1437  switch (attr) {
1438  case DW_AT_type:
1439  encoding_form = form_value;
1440  break;
1441  case DW_AT_data_member_location:
1442  if (form_value.BlockData()) {
1443  Value initialValue(0);
1444  Value memberOffset(0);
1445  const DWARFDataExtractor &debug_info_data = die.GetData();
1446  uint32_t block_length = form_value.Unsigned();
1447  uint32_t block_offset =
1448  form_value.BlockData() - debug_info_data.GetDataStart();
1449  if (DWARFExpression::Evaluate(
1450  nullptr, nullptr, module_sp,
1451  DataExtractor(debug_info_data, block_offset, block_length),
1452  die.GetCU(), eRegisterKindDWARF, &initialValue, nullptr,
1453  memberOffset, nullptr)) {
1454  member_byte_offset = memberOffset.ResolveValue(nullptr).UInt();
1455  }
1456  } else {
1457  // With DWARF 3 and later, if the value is an integer constant,
1458  // this form value is the offset in bytes from the beginning of
1459  // the containing entity.
1460  member_byte_offset = form_value.Unsigned();
1461  }
1462  break;
1463 
1464  case DW_AT_accessibility:
1465  accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
1466  break;
1467 
1468  case DW_AT_virtuality:
1469  is_virtual = form_value.Boolean();
1470  break;
1471 
1472  default:
1473  break;
1474  }
1475  }
1476  }
1477 
1478  Type *base_class_type = die.ResolveTypeUID(encoding_form.Reference());
1479  if (base_class_type == nullptr) {
1480  module_sp->ReportError("0x%8.8x: DW_TAG_inheritance failed to "
1481  "resolve the base class at 0x%8.8x"
1482  " from enclosing type 0x%8.8x. \nPlease file "
1483  "a bug and attach the file at the start of "
1484  "this error message",
1485  die.GetOffset(),
1486  encoding_form.Reference().GetOffset(),
1487  parent_die.GetOffset());
1488  return;
1489  }
1490 
1491  CompilerType base_class_clang_type = base_class_type->GetFullCompilerType();
1492  assert(base_class_clang_type);
1493  if (TypeSystemClang::IsObjCObjectOrInterfaceType(class_clang_type)) {
1494  ast->SetObjCSuperClass(class_clang_type, base_class_clang_type);
1495  return;
1496  }
1497  std::unique_ptr<clang::CXXBaseSpecifier> result =
1498  ast->CreateBaseClassSpecifier(base_class_clang_type.GetOpaqueQualType(),
1499  accessibility, is_virtual,
1500  is_base_of_class);
1501  if (!result)
1502  return;
1503 
1504  base_classes.push_back(std::move(result));
1505 
1506  if (is_virtual) {
1507  // Do not specify any offset for virtual inheritance. The DWARF
1508  // produced by clang doesn't give us a constant offset, but gives
1509  // us a DWARF expressions that requires an actual object in memory.
1510  // the DW_AT_data_member_location for a virtual base class looks
1511  // like:
1512  // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref,
1513  // DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref,
1514  // DW_OP_plus )
1515  // Given this, there is really no valid response we can give to
1516  // clang for virtual base class offsets, and this should eventually
1517  // be removed from LayoutRecordType() in the external
1518  // AST source in clang.
1519  } else {
1520  layout_info.base_offsets.insert(std::make_pair(
1521  ast->GetAsCXXRecordDecl(base_class_clang_type.GetOpaqueQualType()),
1522  clang::CharUnits::fromQuantity(member_byte_offset)));
1523  }
1524 }
1525 
1527  const SymbolContext &sc, const DWARFDIE &die, TypeSP type_sp) {
1528  if (!type_sp)
1529  return type_sp;
1530 
1531  SymbolFileDWARF *dwarf = die.GetDWARF();
1532  TypeList &type_list = dwarf->GetTypeList();
1534  dw_tag_t sc_parent_tag = sc_parent_die.Tag();
1535 
1536  SymbolContextScope *symbol_context_scope = nullptr;
1537  if (sc_parent_tag == DW_TAG_compile_unit ||
1538  sc_parent_tag == DW_TAG_partial_unit) {
1539  symbol_context_scope = sc.comp_unit;
1540  } else if (sc.function != nullptr && sc_parent_die) {
1541  symbol_context_scope =
1542  sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID());
1543  if (symbol_context_scope == nullptr)
1544  symbol_context_scope = sc.function;
1545  } else {
1546  symbol_context_scope = sc.module_sp.get();
1547  }
1548 
1549  if (symbol_context_scope != nullptr)
1550  type_sp->SetSymbolContextScope(symbol_context_scope);
1551 
1552  // We are ready to put this type into the uniqued list up at the module
1553  // level.
1554  type_list.Insert(type_sp);
1555 
1556  dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
1557  return type_sp;
1558 }
1559 
1560 TypeSP
1562  const DWARFDIE &die,
1563  ParsedDWARFTypeAttributes &attrs) {
1564  TypeSP type_sp;
1565  CompilerType clang_type;
1566  const dw_tag_t tag = die.Tag();
1567  SymbolFileDWARF *dwarf = die.GetDWARF();
1568  LanguageType cu_language = SymbolFileDWARF::GetLanguage(*die.GetCU());
1569  Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_TYPE_COMPLETION |
1571 
1572  // UniqueDWARFASTType is large, so don't create a local variables on the
1573  // stack, put it on the heap. This function is often called recursively and
1574  // clang isn't good at sharing the stack space for variables in different
1575  // blocks.
1576  auto unique_ast_entry_up = std::make_unique<UniqueDWARFASTType>();
1577 
1578  ConstString unique_typename(attrs.name);
1579  Declaration unique_decl(attrs.decl);
1580 
1581  if (attrs.name) {
1582  if (Language::LanguageIsCPlusPlus(cu_language)) {
1583  // For C++, we rely solely upon the one definition rule that says
1584  // only one thing can exist at a given decl context. We ignore the
1585  // file and line that things are declared on.
1586  std::string qualified_name;
1587  if (die.GetQualifiedName(qualified_name))
1588  unique_typename = ConstString(qualified_name);
1589  unique_decl.Clear();
1590  }
1591 
1592  if (dwarf->GetUniqueDWARFASTTypeMap().Find(
1593  unique_typename, die, unique_decl, attrs.byte_size.getValueOr(-1),
1594  *unique_ast_entry_up)) {
1595  type_sp = unique_ast_entry_up->m_type_sp;
1596  if (type_sp) {
1597  dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
1599  GetCachedClangDeclContextForDIE(unique_ast_entry_up->m_die), die);
1600  return type_sp;
1601  }
1602  }
1603  }
1604 
1605  DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(),
1606  DW_TAG_value_to_name(tag), type_name_cstr);
1607 
1608  int tag_decl_kind = -1;
1609  AccessType default_accessibility = eAccessNone;
1610  if (tag == DW_TAG_structure_type) {
1611  tag_decl_kind = clang::TTK_Struct;
1612  default_accessibility = eAccessPublic;
1613  } else if (tag == DW_TAG_union_type) {
1614  tag_decl_kind = clang::TTK_Union;
1615  default_accessibility = eAccessPublic;
1616  } else if (tag == DW_TAG_class_type) {
1617  tag_decl_kind = clang::TTK_Class;
1618  default_accessibility = eAccessPrivate;
1619  }
1620 
1621  if (attrs.byte_size && *attrs.byte_size == 0 && attrs.name &&
1622  !die.HasChildren() && cu_language == eLanguageTypeObjC) {
1623  // Work around an issue with clang at the moment where forward
1624  // declarations for objective C classes are emitted as:
1625  // DW_TAG_structure_type [2]
1626  // DW_AT_name( "ForwardObjcClass" )
1627  // DW_AT_byte_size( 0x00 )
1628  // DW_AT_decl_file( "..." )
1629  // DW_AT_decl_line( 1 )
1630  //
1631  // Note that there is no DW_AT_declaration and there are no children,
1632  // and the byte size is zero.
1633  attrs.is_forward_declaration = true;
1634  }
1635 
1636  if (attrs.class_language == eLanguageTypeObjC ||
1638  if (!attrs.is_complete_objc_class &&
1640  // We have a valid eSymbolTypeObjCClass class symbol whose name
1641  // matches the current objective C class that we are trying to find
1642  // and this DIE isn't the complete definition (we checked
1643  // is_complete_objc_class above and know it is false), so the real
1644  // definition is in here somewhere
1645  type_sp =
1646  dwarf->FindCompleteObjCDefinitionTypeForDIE(die, attrs.name, true);
1647 
1648  if (!type_sp) {
1649  SymbolFileDWARFDebugMap *debug_map_symfile =
1650  dwarf->GetDebugMapSymfile();
1651  if (debug_map_symfile) {
1652  // We weren't able to find a full declaration in this DWARF,
1653  // see if we have a declaration anywhere else...
1654  type_sp = debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE(
1655  die, attrs.name, true);
1656  }
1657  }
1658 
1659  if (type_sp) {
1660  if (log) {
1661  dwarf->GetObjectFile()->GetModule()->LogMessage(
1662  log,
1663  "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an "
1664  "incomplete objc type, complete type is 0x%8.8" PRIx64,
1665  static_cast<void *>(this), die.GetOffset(),
1666  DW_TAG_value_to_name(tag), attrs.name.GetCString(),
1667  type_sp->GetID());
1668  }
1669 
1670  // We found a real definition for this type elsewhere so lets use
1671  // it and cache the fact that we found a complete type for this
1672  // die
1673  dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
1674  return type_sp;
1675  }
1676  }
1677  }
1678 
1679  if (attrs.is_forward_declaration) {
1680  // We have a forward declaration to a type and we need to try and
1681  // find a full declaration. We look in the current type index just in
1682  // case we have a forward declaration followed by an actual
1683  // declarations in the DWARF. If this fails, we need to look
1684  // elsewhere...
1685  if (log) {
1686  dwarf->GetObjectFile()->GetModule()->LogMessage(
1687  log,
1688  "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a "
1689  "forward declaration, trying to find complete type",
1690  static_cast<void *>(this), die.GetOffset(), DW_TAG_value_to_name(tag),
1691  attrs.name.GetCString());
1692  }
1693 
1694  // See if the type comes from a Clang module and if so, track down
1695  // that type.
1696  type_sp = ParseTypeFromClangModule(sc, die, log);
1697  if (type_sp)
1698  return type_sp;
1699 
1701 
1702  // type_sp = FindDefinitionTypeForDIE (dwarf_cu, die,
1703  // type_name_const_str);
1704  type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx);
1705 
1706  if (!type_sp) {
1707  SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile();
1708  if (debug_map_symfile) {
1709  // We weren't able to find a full declaration in this DWARF, see
1710  // if we have a declaration anywhere else...
1711  type_sp = debug_map_symfile->FindDefinitionTypeForDWARFDeclContext(
1712  die_decl_ctx);
1713  }
1714  }
1715 
1716  if (type_sp) {
1717  if (log) {
1718  dwarf->GetObjectFile()->GetModule()->LogMessage(
1719  log,
1720  "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a "
1721  "forward declaration, complete type is 0x%8.8" PRIx64,
1722  static_cast<void *>(this), die.GetOffset(),
1723  DW_TAG_value_to_name(tag), attrs.name.GetCString(),
1724  type_sp->GetID());
1725  }
1726 
1727  // We found a real definition for this type elsewhere so lets use
1728  // it and cache the fact that we found a complete type for this die
1729  dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
1730  clang::DeclContext *defn_decl_ctx =
1731  GetCachedClangDeclContextForDIE(dwarf->GetDIE(type_sp->GetID()));
1732  if (defn_decl_ctx)
1733  LinkDeclContextToDIE(defn_decl_ctx, die);
1734  return type_sp;
1735  }
1736  }
1737  assert(tag_decl_kind != -1);
1738  (void)tag_decl_kind;
1739  bool clang_type_was_created = false;
1740  clang_type.SetCompilerType(
1741  &m_ast, dwarf->GetForwardDeclDieToClangType().lookup(die.GetDIE()));
1742  if (!clang_type) {
1743  clang::DeclContext *decl_ctx =
1744  GetClangDeclContextContainingDIE(die, nullptr);
1745 
1747  attrs.name.GetCString());
1748 
1749  if (attrs.accessibility == eAccessNone && decl_ctx) {
1750  // Check the decl context that contains this class/struct/union. If
1751  // it is a class we must give it an accessibility.
1752  const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
1753  if (DeclKindIsCXXClass(containing_decl_kind))
1754  attrs.accessibility = default_accessibility;
1755  }
1756 
1757  ClangASTMetadata metadata;
1758  metadata.SetUserID(die.GetID());
1759  metadata.SetIsDynamicCXXType(dwarf->ClassOrStructIsVirtual(die));
1760 
1761  if (attrs.name.GetStringRef().contains('<')) {
1762  TypeSystemClang::TemplateParameterInfos template_param_infos;
1763  if (ParseTemplateParameterInfos(die, template_param_infos)) {
1764  clang::ClassTemplateDecl *class_template_decl =
1766  decl_ctx, GetOwningClangModule(die), attrs.accessibility,
1767  attrs.name.GetCString(), tag_decl_kind, template_param_infos);
1768  if (!class_template_decl) {
1769  if (log) {
1770  dwarf->GetObjectFile()->GetModule()->LogMessage(
1771  log,
1772  "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" "
1773  "clang::ClassTemplateDecl failed to return a decl.",
1774  static_cast<void *>(this), die.GetOffset(),
1775  DW_TAG_value_to_name(tag), attrs.name.GetCString());
1776  }
1777  return TypeSP();
1778  }
1779 
1780  clang::ClassTemplateSpecializationDecl *class_specialization_decl =
1782  decl_ctx, GetOwningClangModule(die), class_template_decl,
1783  tag_decl_kind, template_param_infos);
1785  class_specialization_decl);
1786  clang_type_was_created = true;
1787 
1788  m_ast.SetMetadata(class_template_decl, metadata);
1789  m_ast.SetMetadata(class_specialization_decl, metadata);
1790  }
1791  }
1792 
1793  if (!clang_type_was_created) {
1794  clang_type_was_created = true;
1795  clang_type = m_ast.CreateRecordType(
1796  decl_ctx, GetOwningClangModule(die), attrs.accessibility,
1797  attrs.name.GetCString(), tag_decl_kind, attrs.class_language,
1798  &metadata, attrs.exports_symbols);
1799  }
1800  }
1801 
1802  // Store a forward declaration to this class type in case any
1803  // parameters in any class methods need it for the clang types for
1804  // function prototypes.
1806  type_sp = std::make_shared<Type>(
1807  die.GetID(), dwarf, attrs.name, attrs.byte_size, nullptr,
1808  LLDB_INVALID_UID, Type::eEncodingIsUID, &attrs.decl, clang_type,
1809  Type::ResolveState::Forward,
1811 
1812  // Add our type to the unique type map so we don't end up creating many
1813  // copies of the same type over and over in the ASTContext for our
1814  // module
1815  unique_ast_entry_up->m_type_sp = type_sp;
1816  unique_ast_entry_up->m_die = die;
1817  unique_ast_entry_up->m_declaration = unique_decl;
1818  unique_ast_entry_up->m_byte_size = attrs.byte_size.getValueOr(0);
1819  dwarf->GetUniqueDWARFASTTypeMap().Insert(unique_typename,
1820  *unique_ast_entry_up);
1821 
1822  if (!attrs.is_forward_declaration) {
1823  // Always start the definition for a class type so that if the class
1824  // has child classes or types that require the class to be created
1825  // for use as their decl contexts the class will be ready to accept
1826  // these child definitions.
1827  if (!die.HasChildren()) {
1828  // No children for this struct/union/class, lets finish it
1829  if (TypeSystemClang::StartTagDeclarationDefinition(clang_type)) {
1830  TypeSystemClang::CompleteTagDeclarationDefinition(clang_type);
1831  } else {
1832  dwarf->GetObjectFile()->GetModule()->ReportError(
1833  "DWARF DIE at 0x%8.8x named \"%s\" was not able to start its "
1834  "definition.\nPlease file a bug and attach the file at the "
1835  "start of this error message",
1836  die.GetOffset(), attrs.name.GetCString());
1837  }
1838 
1839  // If the byte size of the record is specified then overwrite the size
1840  // that would be computed by Clang. This is only needed as LLDB's
1841  // TypeSystemClang is always in C++ mode, but some compilers such as
1842  // GCC and Clang give empty structs a size of 0 in C mode (in contrast to
1843  // the size of 1 for empty structs that would be computed in C++ mode).
1844  if (attrs.byte_size) {
1845  clang::RecordDecl *record_decl =
1846  TypeSystemClang::GetAsRecordDecl(clang_type);
1847  if (record_decl) {
1849  layout.bit_size = *attrs.byte_size * 8;
1850  GetClangASTImporter().SetRecordLayout(record_decl, layout);
1851  }
1852  }
1853  } else if (clang_type_was_created) {
1854  // Start the definition if the class is not objective C since the
1855  // underlying decls respond to isCompleteDefinition(). Objective
1856  // C decls don't respond to isCompleteDefinition() so we can't
1857  // start the declaration definition right away. For C++
1858  // class/union/structs we want to start the definition in case the
1859  // class is needed as the declaration context for a contained class
1860  // or type without the need to complete that type..
1861 
1862  if (attrs.class_language != eLanguageTypeObjC &&
1864  TypeSystemClang::StartTagDeclarationDefinition(clang_type);
1865 
1866  // Leave this as a forward declaration until we need to know the
1867  // details of the type. lldb_private::Type will automatically call
1868  // the SymbolFile virtual function
1869  // "SymbolFileDWARF::CompleteType(Type *)" When the definition
1870  // needs to be defined.
1871  assert(!dwarf->GetForwardDeclClangTypeToDie().count(
1872  ClangUtil::RemoveFastQualifiers(clang_type)
1873  .GetOpaqueQualType()) &&
1874  "Type already in the forward declaration map!");
1875  // Can't assume m_ast.GetSymbolFile() is actually a
1876  // SymbolFileDWARF, it can be a SymbolFileDWARFDebugMap for Apple
1877  // binaries.
1878  dwarf->GetForwardDeclDieToClangType()[die.GetDIE()] =
1879  clang_type.GetOpaqueQualType();
1880  dwarf->GetForwardDeclClangTypeToDie().try_emplace(
1881  ClangUtil::RemoveFastQualifiers(clang_type).GetOpaqueQualType(),
1882  *die.GetDIERef());
1883  m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), true);
1884  }
1885  }
1886 
1887  // If we made a clang type, set the trivial abi if applicable: We only
1888  // do this for pass by value - which implies the Trivial ABI. There
1889  // isn't a way to assert that something that would normally be pass by
1890  // value is pass by reference, so we ignore that attribute if set.
1891  if (attrs.calling_convention == llvm::dwarf::DW_CC_pass_by_value) {
1892  clang::CXXRecordDecl *record_decl =
1894  if (record_decl && record_decl->getDefinition()) {
1895  record_decl->setHasTrivialSpecialMemberForCall();
1896  }
1897  }
1898 
1899  if (attrs.calling_convention == llvm::dwarf::DW_CC_pass_by_reference) {
1900  clang::CXXRecordDecl *record_decl =
1902  if (record_decl)
1903  record_decl->setArgPassingRestrictions(
1904  clang::RecordDecl::APK_CannotPassInRegs);
1905  }
1906  return type_sp;
1907 }
1908 
1909 // DWARF parsing functions
1910 
1912 public:
1914  const CompilerType &class_opaque_type, const char *property_name,
1915  const CompilerType &property_opaque_type, // The property type is only
1916  // required if you don't have an
1917  // ivar decl
1918  const char *property_setter_name, const char *property_getter_name,
1919  uint32_t property_attributes, const ClangASTMetadata *metadata)
1920  : m_class_opaque_type(class_opaque_type), m_property_name(property_name),
1921  m_property_opaque_type(property_opaque_type),
1922  m_property_setter_name(property_setter_name),
1923  m_property_getter_name(property_getter_name),
1924  m_property_attributes(property_attributes) {
1925  if (metadata != nullptr) {
1926  m_metadata_up = std::make_unique<ClangASTMetadata>();
1927  *m_metadata_up = *metadata;
1928  }
1929  }
1930 
1932  *this = rhs;
1933  }
1934 
1943 
1944  if (rhs.m_metadata_up) {
1945  m_metadata_up = std::make_unique<ClangASTMetadata>();
1946  *m_metadata_up = *rhs.m_metadata_up;
1947  }
1948  return *this;
1949  }
1950 
1951  bool Finalize() {
1952  return TypeSystemClang::AddObjCClassProperty(
1954  /*ivar_decl=*/nullptr, m_property_setter_name, m_property_getter_name,
1956  }
1957 
1958 private:
1960  const char *m_property_name;
1965  std::unique_ptr<ClangASTMetadata> m_metadata_up;
1966 };
1967 
1969  const DWARFDIE &die,
1970  TypeSystemClang::TemplateParameterInfos &template_param_infos) {
1971  const dw_tag_t tag = die.Tag();
1972  bool is_template_template_argument = false;
1973 
1974  switch (tag) {
1975  case DW_TAG_GNU_template_parameter_pack: {
1976  template_param_infos.packed_args =
1977  std::make_unique<TypeSystemClang::TemplateParameterInfos>();
1978  for (DWARFDIE child_die : die.children()) {
1979  if (!ParseTemplateDIE(child_die, *template_param_infos.packed_args))
1980  return false;
1981  }
1982  if (const char *name = die.GetName()) {
1983  template_param_infos.pack_name = name;
1984  }
1985  return true;
1986  }
1987  case DW_TAG_GNU_template_template_param:
1988  is_template_template_argument = true;
1989  LLVM_FALLTHROUGH;
1990  case DW_TAG_template_type_parameter:
1991  case DW_TAG_template_value_parameter: {
1992  DWARFAttributes attributes;
1993  const size_t num_attributes = die.GetAttributes(attributes);
1994  const char *name = nullptr;
1995  const char *template_name = nullptr;
1996  CompilerType clang_type;
1997  uint64_t uval64 = 0;
1998  bool uval64_valid = false;
1999  if (num_attributes > 0) {
2000  DWARFFormValue form_value;
2001  for (size_t i = 0; i < num_attributes; ++i) {
2002  const dw_attr_t attr = attributes.AttributeAtIndex(i);
2003 
2004  switch (attr) {
2005  case DW_AT_name:
2006  if (attributes.ExtractFormValueAtIndex(i, form_value))
2007  name = form_value.AsCString();
2008  break;
2009 
2010  case DW_AT_GNU_template_name:
2011  if (attributes.ExtractFormValueAtIndex(i, form_value))
2012  template_name = form_value.AsCString();
2013  break;
2014 
2015  case DW_AT_type:
2016  if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2017  Type *lldb_type = die.ResolveTypeUID(form_value.Reference());
2018  if (lldb_type)
2019  clang_type = lldb_type->GetForwardCompilerType();
2020  }
2021  break;
2022 
2023  case DW_AT_const_value:
2024  if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2025  uval64_valid = true;
2026  uval64 = form_value.Unsigned();
2027  }
2028  break;
2029  default:
2030  break;
2031  }
2032  }
2033 
2034  clang::ASTContext &ast = m_ast.getASTContext();
2035  if (!clang_type)
2036  clang_type = m_ast.GetBasicType(eBasicTypeVoid);
2037 
2038  if (!is_template_template_argument) {
2039  bool is_signed = false;
2040  if (name && name[0])
2041  template_param_infos.names.push_back(name);
2042  else
2043  template_param_infos.names.push_back(NULL);
2044 
2045  // Get the signed value for any integer or enumeration if available
2046  clang_type.IsIntegerOrEnumerationType(is_signed);
2047 
2048  if (tag == DW_TAG_template_value_parameter && uval64_valid) {
2049  llvm::Optional<uint64_t> size = clang_type.GetBitSize(nullptr);
2050  if (!size)
2051  return false;
2052  llvm::APInt apint(*size, uval64, is_signed);
2053  template_param_infos.args.push_back(
2054  clang::TemplateArgument(ast, llvm::APSInt(apint, !is_signed),
2055  ClangUtil::GetQualType(clang_type)));
2056  } else {
2057  template_param_infos.args.push_back(
2058  clang::TemplateArgument(ClangUtil::GetQualType(clang_type)));
2059  }
2060  } else {
2061  auto *tplt_type = m_ast.CreateTemplateTemplateParmDecl(template_name);
2062  template_param_infos.names.push_back(name);
2063  template_param_infos.args.push_back(
2064  clang::TemplateArgument(clang::TemplateName(tplt_type)));
2065  }
2066  }
2067  }
2068  return true;
2069 
2070  default:
2071  break;
2072  }
2073  return false;
2074 }
2075 
2077  const DWARFDIE &parent_die,
2078  TypeSystemClang::TemplateParameterInfos &template_param_infos) {
2079 
2080  if (!parent_die)
2081  return false;
2082 
2083  for (DWARFDIE die : parent_die.children()) {
2084  const dw_tag_t tag = die.Tag();
2085 
2086  switch (tag) {
2087  case DW_TAG_template_type_parameter:
2088  case DW_TAG_template_value_parameter:
2089  case DW_TAG_GNU_template_parameter_pack:
2090  case DW_TAG_GNU_template_template_param:
2091  ParseTemplateDIE(die, template_param_infos);
2092  break;
2093 
2094  default:
2095  break;
2096  }
2097  }
2098  return template_param_infos.args.size() == template_param_infos.names.size();
2099 }
2100 
2102  lldb_private::Type *type,
2103  CompilerType &clang_type) {
2104  const dw_tag_t tag = die.Tag();
2105  SymbolFileDWARF *dwarf = die.GetDWARF();
2106 
2107  ClangASTImporter::LayoutInfo layout_info;
2108 
2109  if (die.HasChildren()) {
2110  const bool type_is_objc_object_or_interface =
2111  TypeSystemClang::IsObjCObjectOrInterfaceType(clang_type);
2112  if (type_is_objc_object_or_interface) {
2113  // For objective C we don't start the definition when the class is
2114  // created.
2115  TypeSystemClang::StartTagDeclarationDefinition(clang_type);
2116  }
2117 
2118  AccessType default_accessibility = eAccessNone;
2119  if (tag == DW_TAG_structure_type) {
2120  default_accessibility = eAccessPublic;
2121  } else if (tag == DW_TAG_union_type) {
2122  default_accessibility = eAccessPublic;
2123  } else if (tag == DW_TAG_class_type) {
2124  default_accessibility = eAccessPrivate;
2125  }
2126 
2127  std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> bases;
2128  // Parse members and base classes first
2129  std::vector<DWARFDIE> member_function_dies;
2130 
2131  DelayedPropertyList delayed_properties;
2132  ParseChildMembers(die, clang_type, bases, member_function_dies,
2133  delayed_properties, default_accessibility, layout_info);
2134 
2135  // Now parse any methods if there were any...
2136  for (const DWARFDIE &die : member_function_dies)
2137  dwarf->ResolveType(die);
2138 
2139  if (type_is_objc_object_or_interface) {
2140  ConstString class_name(clang_type.GetTypeName());
2141  if (class_name) {
2142  dwarf->GetObjCMethods(class_name, [&](DWARFDIE method_die) {
2143  method_die.ResolveType();
2144  return true;
2145  });
2146 
2147  for (DelayedAddObjCClassProperty &property : delayed_properties)
2148  property.Finalize();
2149  }
2150  }
2151 
2152  if (!bases.empty()) {
2153  // Make sure all base classes refer to complete types and not forward
2154  // declarations. If we don't do this, clang will crash with an
2155  // assertion in the call to clang_type.TransferBaseClasses()
2156  for (const auto &base_class : bases) {
2157  clang::TypeSourceInfo *type_source_info =
2158  base_class->getTypeSourceInfo();
2159  if (type_source_info)
2160  RequireCompleteType(m_ast.GetType(type_source_info->getType()));
2161  }
2162 
2164  std::move(bases));
2165  }
2166  }
2167 
2169  TypeSystemClang::BuildIndirectFields(clang_type);
2170  TypeSystemClang::CompleteTagDeclarationDefinition(clang_type);
2171 
2172  if (!layout_info.field_offsets.empty() || !layout_info.base_offsets.empty() ||
2173  !layout_info.vbase_offsets.empty()) {
2174  if (type)
2175  layout_info.bit_size = type->GetByteSize(nullptr).getValueOr(0) * 8;
2176  if (layout_info.bit_size == 0)
2177  layout_info.bit_size =
2178  die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8;
2179 
2180  clang::CXXRecordDecl *record_decl =
2182  if (record_decl)
2183  GetClangASTImporter().SetRecordLayout(record_decl, layout_info);
2184  }
2185 
2186  return (bool)clang_type;
2187 }
2188 
2190  lldb_private::Type *type,
2191  CompilerType &clang_type) {
2192  if (TypeSystemClang::StartTagDeclarationDefinition(clang_type)) {
2193  if (die.HasChildren()) {
2194  bool is_signed = false;
2195  clang_type.IsIntegerType(is_signed);
2196  ParseChildEnumerators(clang_type, is_signed,
2197  type->GetByteSize(nullptr).getValueOr(0), die);
2198  }
2199  TypeSystemClang::CompleteTagDeclarationDefinition(clang_type);
2200  }
2201  return (bool)clang_type;
2202 }
2203 
2205  lldb_private::Type *type,
2206  CompilerType &clang_type) {
2207  SymbolFileDWARF *dwarf = die.GetDWARF();
2208 
2209  std::lock_guard<std::recursive_mutex> guard(
2210  dwarf->GetObjectFile()->GetModule()->GetMutex());
2211 
2212  // Disable external storage for this type so we don't get anymore
2213  // clang::ExternalASTSource queries for this type.
2214  m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), false);
2215 
2216  if (!die)
2217  return false;
2218 
2219  const dw_tag_t tag = die.Tag();
2220 
2221  Log *log =
2222  nullptr; // (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
2223  if (log)
2224  dwarf->GetObjectFile()->GetModule()->LogMessageVerboseBacktrace(
2225  log, "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
2226  die.GetID(), die.GetTagAsCString(), type->GetName().AsCString());
2227  assert(clang_type);
2228  DWARFAttributes attributes;
2229  switch (tag) {
2230  case DW_TAG_structure_type:
2231  case DW_TAG_union_type:
2232  case DW_TAG_class_type:
2233  return CompleteRecordType(die, type, clang_type);
2234  case DW_TAG_enumeration_type:
2235  return CompleteEnumType(die, type, clang_type);
2236  default:
2237  assert(false && "not a forward clang type decl!");
2238  break;
2239  }
2240 
2241  return false;
2242 }
2243 
2245  lldb_private::CompilerDeclContext decl_context) {
2246  auto opaque_decl_ctx =
2247  (clang::DeclContext *)decl_context.GetOpaqueDeclContext();
2248  for (auto it = m_decl_ctx_to_die.find(opaque_decl_ctx);
2249  it != m_decl_ctx_to_die.end() && it->first == opaque_decl_ctx;
2250  it = m_decl_ctx_to_die.erase(it))
2251  for (DWARFDIE decl : it->second.children())
2252  GetClangDeclForDIE(decl);
2253 }
2254 
2256  clang::Decl *clang_decl = GetClangDeclForDIE(die);
2257  if (clang_decl != nullptr)
2258  return m_ast.GetCompilerDecl(clang_decl);
2259  return CompilerDecl();
2260 }
2261 
2264  clang::DeclContext *clang_decl_ctx = GetClangDeclContextForDIE(die);
2265  if (clang_decl_ctx)
2266  return m_ast.CreateDeclContext(clang_decl_ctx);
2267  return CompilerDeclContext();
2268 }
2269 
2272  clang::DeclContext *clang_decl_ctx =
2273  GetClangDeclContextContainingDIE(die, nullptr);
2274  if (clang_decl_ctx)
2275  return m_ast.CreateDeclContext(clang_decl_ctx);
2276  return CompilerDeclContext();
2277 }
2278 
2280  lldb_private::CompilerType &clang_type, bool is_signed,
2281  uint32_t enumerator_byte_size, const DWARFDIE &parent_die) {
2282  if (!parent_die)
2283  return 0;
2284 
2285  size_t enumerators_added = 0;
2286 
2287  for (DWARFDIE die : parent_die.children()) {
2288  const dw_tag_t tag = die.Tag();
2289  if (tag == DW_TAG_enumerator) {
2290  DWARFAttributes attributes;
2291  const size_t num_child_attributes = die.GetAttributes(attributes);
2292  if (num_child_attributes > 0) {
2293  const char *name = nullptr;
2294  bool got_value = false;
2295  int64_t enum_value = 0;
2296  Declaration decl;
2297 
2298  uint32_t i;
2299  for (i = 0; i < num_child_attributes; ++i) {
2300  const dw_attr_t attr = attributes.AttributeAtIndex(i);
2301  DWARFFormValue form_value;
2302  if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2303  switch (attr) {
2304  case DW_AT_const_value:
2305  got_value = true;
2306  if (is_signed)
2307  enum_value = form_value.Signed();
2308  else
2309  enum_value = form_value.Unsigned();
2310  break;
2311 
2312  case DW_AT_name:
2313  name = form_value.AsCString();
2314  break;
2315 
2316  case DW_AT_description:
2317  default:
2318  case DW_AT_decl_file:
2319  decl.SetFile(attributes.CompileUnitAtIndex(i)->GetFile(
2320  form_value.Unsigned()));
2321  break;
2322  case DW_AT_decl_line:
2323  decl.SetLine(form_value.Unsigned());
2324  break;
2325  case DW_AT_decl_column:
2326  decl.SetColumn(form_value.Unsigned());
2327  break;
2328  case DW_AT_sibling:
2329  break;
2330  }
2331  }
2332  }
2333 
2334  if (name && name[0] && got_value) {
2336  clang_type, decl, name, enum_value, enumerator_byte_size * 8);
2337  ++enumerators_added;
2338  }
2339  }
2340  }
2341  }
2342  return enumerators_added;
2343 }
2344 
2346  const DWARFDIE &die) {
2347  DWARFRangeList func_ranges;
2348  const char *name = nullptr;
2349  const char *mangled = nullptr;
2350  int decl_file = 0;
2351  int decl_line = 0;
2352  int decl_column = 0;
2353  int call_file = 0;
2354  int call_line = 0;
2355  int call_column = 0;
2356  DWARFExpression frame_base;
2357 
2358  const dw_tag_t tag = die.Tag();
2359 
2360  if (tag != DW_TAG_subprogram)
2361  return nullptr;
2362 
2363  if (die.GetDIENamesAndRanges(name, mangled, func_ranges, decl_file, decl_line,
2364  decl_column, call_file, call_line, call_column,
2365  &frame_base)) {
2366 
2367  // Union of all ranges in the function DIE (if the function is
2368  // discontiguous)
2369  AddressRange func_range;
2370  lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase(0);
2371  lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd(0);
2372  if (lowest_func_addr != LLDB_INVALID_ADDRESS &&
2373  lowest_func_addr <= highest_func_addr) {
2374  ModuleSP module_sp(die.GetModule());
2376  lowest_func_addr, module_sp->GetSectionList());
2377  if (func_range.GetBaseAddress().IsValid())
2378  func_range.SetByteSize(highest_func_addr - lowest_func_addr);
2379  }
2380 
2381  if (func_range.GetBaseAddress().IsValid()) {
2382  Mangled func_name;
2383  if (mangled)
2384  func_name.SetValue(ConstString(mangled), true);
2385  else if ((die.GetParent().Tag() == DW_TAG_compile_unit ||
2386  die.GetParent().Tag() == DW_TAG_partial_unit) &&
2387  Language::LanguageIsCPlusPlus(
2389  !Language::LanguageIsObjC(
2391  name && strcmp(name, "main") != 0) {
2392  // If the mangled name is not present in the DWARF, generate the
2393  // demangled name using the decl context. We skip if the function is
2394  // "main" as its name is never mangled.
2395  bool is_static = false;
2396  bool is_variadic = false;
2397  bool has_template_params = false;
2398  unsigned type_quals = 0;
2399  std::vector<CompilerType> param_types;
2400  std::vector<clang::ParmVarDecl *> param_decls;
2401  StreamString sstr;
2402 
2404  sstr << decl_ctx.GetQualifiedName();
2405 
2406  clang::DeclContext *containing_decl_ctx =
2407  GetClangDeclContextContainingDIE(die, nullptr);
2408  ParseChildParameters(containing_decl_ctx, die, true, is_static,
2409  is_variadic, has_template_params, param_types,
2410  param_decls, type_quals);
2411  sstr << "(";
2412  for (size_t i = 0; i < param_types.size(); i++) {
2413  if (i > 0)
2414  sstr << ", ";
2415  sstr << param_types[i].GetTypeName();
2416  }
2417  if (is_variadic)
2418  sstr << ", ...";
2419  sstr << ")";
2420  if (type_quals & clang::Qualifiers::Const)
2421  sstr << " const";
2422 
2423  func_name.SetValue(ConstString(sstr.GetString()), false);
2424  } else
2425  func_name.SetValue(ConstString(name), false);
2426 
2427  FunctionSP func_sp;
2428  std::unique_ptr<Declaration> decl_up;
2429  if (decl_file != 0 || decl_line != 0 || decl_column != 0)
2430  decl_up = std::make_unique<Declaration>(die.GetCU()->GetFile(decl_file),
2431  decl_line, decl_column);
2432 
2433  SymbolFileDWARF *dwarf = die.GetDWARF();
2434  // Supply the type _only_ if it has already been parsed
2435  Type *func_type = dwarf->GetDIEToType().lookup(die.GetDIE());
2436 
2437  assert(func_type == nullptr || func_type != DIE_IS_BEING_PARSED);
2438 
2439  if (dwarf->FixupAddress(func_range.GetBaseAddress())) {
2440  const user_id_t func_user_id = die.GetID();
2441  func_sp =
2442  std::make_shared<Function>(&comp_unit,
2443  func_user_id, // UserID is the DIE offset
2444  func_user_id, func_name, func_type,
2445  func_range); // first address range
2446 
2447  if (func_sp.get() != nullptr) {
2448  if (frame_base.IsValid())
2449  func_sp->GetFrameBaseExpression() = frame_base;
2450  comp_unit.AddFunction(func_sp);
2451  return func_sp.get();
2452  }
2453  }
2454  }
2455  }
2456  return nullptr;
2457 }
2458 
2459 namespace {
2460 /// Parsed form of all attributes that are relevant for parsing type members.
2461 struct MemberAttributes {
2462  explicit MemberAttributes(const DWARFDIE &die, const DWARFDIE &parent_die,
2463  ModuleSP module_sp);
2464  const char *name = nullptr;
2465  /// Indicates how many bits into the word (according to the host endianness)
2466  /// the low-order bit of the field starts. Can be negative.
2467  int64_t bit_offset = 0;
2468  /// Indicates the size of the field in bits.
2469  size_t bit_size = 0;
2470  uint64_t data_bit_offset = UINT64_MAX;
2471  AccessType accessibility = eAccessNone;
2472  llvm::Optional<uint64_t> byte_size;
2473  DWARFFormValue encoding_form;
2474  /// Indicates the byte offset of the word from the base address of the
2475  /// structure.
2476  uint32_t member_byte_offset;
2477  bool is_artificial = false;
2478  /// On DW_TAG_members, this means the member is static.
2479  bool is_external = false;
2480 };
2481 
2482 /// Parsed form of all attributes that are relevant for parsing Objective-C
2483 /// properties.
2484 struct PropertyAttributes {
2485  explicit PropertyAttributes(const DWARFDIE &die);
2486  const char *prop_name = nullptr;
2487  const char *prop_getter_name = nullptr;
2488  const char *prop_setter_name = nullptr;
2489  /// \see clang::ObjCPropertyAttribute
2490  uint32_t prop_attributes = 0;
2491 };
2492 } // namespace
2493 
2494 MemberAttributes::MemberAttributes(const DWARFDIE &die,
2495  const DWARFDIE &parent_die,
2496  ModuleSP module_sp) {
2497  member_byte_offset = (parent_die.Tag() == DW_TAG_union_type) ? 0 : UINT32_MAX;
2498 
2499  DWARFAttributes attributes;
2500  const size_t num_attributes = die.GetAttributes(attributes);
2501  for (std::size_t i = 0; i < num_attributes; ++i) {
2502  const dw_attr_t attr = attributes.AttributeAtIndex(i);
2503  DWARFFormValue form_value;
2504  if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2505  switch (attr) {
2506  case DW_AT_name:
2507  name = form_value.AsCString();
2508  break;
2509  case DW_AT_type:
2510  encoding_form = form_value;
2511  break;
2512  case DW_AT_bit_offset:
2513  bit_offset = form_value.Signed();
2514  break;
2515  case DW_AT_bit_size:
2516  bit_size = form_value.Unsigned();
2517  break;
2518  case DW_AT_byte_size:
2519  byte_size = form_value.Unsigned();
2520  break;
2521  case DW_AT_data_bit_offset:
2522  data_bit_offset = form_value.Unsigned();
2523  break;
2524  case DW_AT_data_member_location:
2525  if (form_value.BlockData()) {
2526  Value initialValue(0);
2527  Value memberOffset(0);
2528  const DWARFDataExtractor &debug_info_data = die.GetData();
2529  uint32_t block_length = form_value.Unsigned();
2530  uint32_t block_offset =
2531  form_value.BlockData() - debug_info_data.GetDataStart();
2532  if (DWARFExpression::Evaluate(
2533  nullptr, // ExecutionContext *
2534  nullptr, // RegisterContext *
2535  module_sp,
2536  DataExtractor(debug_info_data, block_offset, block_length),
2537  die.GetCU(), eRegisterKindDWARF, &initialValue, nullptr,
2538  memberOffset, nullptr)) {
2539  member_byte_offset = memberOffset.ResolveValue(nullptr).UInt();
2540  }
2541  } else {
2542  // With DWARF 3 and later, if the value is an integer constant,
2543  // this form value is the offset in bytes from the beginning of
2544  // the containing entity.
2545  member_byte_offset = form_value.Unsigned();
2546  }
2547  break;
2548 
2549  case DW_AT_accessibility:
2550  accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
2551  break;
2552  case DW_AT_artificial:
2553  is_artificial = form_value.Boolean();
2554  break;
2555  case DW_AT_external:
2556  is_external = form_value.Boolean();
2557  break;
2558  default:
2559  break;
2560  }
2561  }
2562  }
2563 
2564  // Clang has a DWARF generation bug where sometimes it represents
2565  // fields that are references with bad byte size and bit size/offset
2566  // information such as:
2567  //
2568  // DW_AT_byte_size( 0x00 )
2569  // DW_AT_bit_size( 0x40 )
2570  // DW_AT_bit_offset( 0xffffffffffffffc0 )
2571  //
2572  // So check the bit offset to make sure it is sane, and if the values
2573  // are not sane, remove them. If we don't do this then we will end up
2574  // with a crash if we try to use this type in an expression when clang
2575  // becomes unhappy with its recycled debug info.
2576  if (byte_size.getValueOr(0) == 0 && bit_offset < 0) {
2577  bit_size = 0;
2578  bit_offset = 0;
2579  }
2580 }
2581 
2582 PropertyAttributes::PropertyAttributes(const DWARFDIE &die) {
2583 
2584  DWARFAttributes attributes;
2585  const size_t num_attributes = die.GetAttributes(attributes);
2586  for (size_t i = 0; i < num_attributes; ++i) {
2587  const dw_attr_t attr = attributes.AttributeAtIndex(i);
2588  DWARFFormValue form_value;
2589  if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2590  switch (attr) {
2591  case DW_AT_APPLE_property_name:
2592  prop_name = form_value.AsCString();
2593  break;
2594  case DW_AT_APPLE_property_getter:
2595  prop_getter_name = form_value.AsCString();
2596  break;
2597  case DW_AT_APPLE_property_setter:
2598  prop_setter_name = form_value.AsCString();
2599  break;
2600  case DW_AT_APPLE_property_attribute:
2601  prop_attributes = form_value.Unsigned();
2602  break;
2603  default:
2604  break;
2605  }
2606  }
2607  }
2608 
2609  if (!prop_name)
2610  return;
2611  ConstString fixed_setter;
2612 
2613  // Check if the property getter/setter were provided as full names.
2614  // We want basenames, so we extract them.
2615  if (prop_getter_name && prop_getter_name[0] == '-') {
2616  ObjCLanguage::MethodName prop_getter_method(prop_getter_name, true);
2617  prop_getter_name = prop_getter_method.GetSelector().GetCString();
2618  }
2619 
2620  if (prop_setter_name && prop_setter_name[0] == '-') {
2621  ObjCLanguage::MethodName prop_setter_method(prop_setter_name, true);
2622  prop_setter_name = prop_setter_method.GetSelector().GetCString();
2623  }
2624 
2625  // If the names haven't been provided, they need to be filled in.
2626  if (!prop_getter_name)
2627  prop_getter_name = prop_name;
2628  if (!prop_setter_name && prop_name[0] &&
2629  !(prop_attributes & DW_APPLE_PROPERTY_readonly)) {
2630  StreamString ss;
2631 
2632  ss.Printf("set%c%s:", toupper(prop_name[0]), &prop_name[1]);
2633 
2634  fixed_setter.SetString(ss.GetString());
2635  prop_setter_name = fixed_setter.GetCString();
2636  }
2637 }
2638 
2640  const DWARFDIE &die, const DWARFDIE &parent_die,
2641  const lldb_private::CompilerType &class_clang_type,
2642  DelayedPropertyList &delayed_properties) {
2643  // This function can only parse DW_TAG_APPLE_property.
2644  assert(die.Tag() == DW_TAG_APPLE_property);
2645 
2646  ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule();
2647 
2648  const MemberAttributes attrs(die, parent_die, module_sp);
2649  const PropertyAttributes propAttrs(die);
2650 
2651  if (!propAttrs.prop_name) {
2652  module_sp->ReportError(
2653  "0x%8.8" PRIx64 ": DW_TAG_APPLE_property has no name.", die.GetID());
2654  return;
2655  }
2656 
2657  Type *member_type = die.ResolveTypeUID(attrs.encoding_form.Reference());
2658  if (!member_type) {
2659  module_sp->ReportError("0x%8.8" PRIx64
2660  ": DW_TAG_APPLE_property '%s' refers to type 0x%8.8x"
2661  " which was unable to be parsed",
2662  die.GetID(), propAttrs.prop_name,
2663  attrs.encoding_form.Reference().GetOffset());
2664  return;
2665  }
2666 
2667  ClangASTMetadata metadata;
2668  metadata.SetUserID(die.GetID());
2669  delayed_properties.push_back(DelayedAddObjCClassProperty(
2670  class_clang_type, propAttrs.prop_name,
2671  member_type->GetLayoutCompilerType(), propAttrs.prop_setter_name,
2672  propAttrs.prop_getter_name, propAttrs.prop_attributes, &metadata));
2673 }
2674 
2676  const DWARFDIE &die, const DWARFDIE &parent_die,
2677  const lldb_private::CompilerType &class_clang_type,
2678  lldb::AccessType default_accessibility,
2680  FieldInfo &last_field_info) {
2681  // This function can only parse DW_TAG_member.
2682  assert(die.Tag() == DW_TAG_member);
2683 
2684  ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule();
2685  const dw_tag_t tag = die.Tag();
2686  // Get the parent byte size so we can verify any members will fit
2687  const uint64_t parent_byte_size =
2688  parent_die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX);
2689  const uint64_t parent_bit_size =
2690  parent_byte_size == UINT64_MAX ? UINT64_MAX : parent_byte_size * 8;
2691 
2692  // FIXME: Remove the workarounds below and make this const.
2693  MemberAttributes attrs(die, parent_die, module_sp);
2694  // Skip artificial members such as vtable pointers.
2695  // FIXME: This check should verify that this is indeed an artificial member
2696  // we are supposed to ignore.
2697  if (attrs.is_artificial)
2698  return;
2699 
2700  const bool class_is_objc_object_or_interface =
2701  TypeSystemClang::IsObjCObjectOrInterfaceType(class_clang_type);
2702 
2703  // FIXME: Make Clang ignore Objective-C accessibility for expressions
2704  if (class_is_objc_object_or_interface)
2705  attrs.accessibility = eAccessNone;
2706 
2707  // Handle static members
2708  if (attrs.is_external && attrs.member_byte_offset == UINT32_MAX) {
2709  Type *var_type = die.ResolveTypeUID(attrs.encoding_form.Reference());
2710 
2711  if (var_type) {
2712  if (attrs.accessibility == eAccessNone)
2713  attrs.accessibility = eAccessPublic;
2714  TypeSystemClang::AddVariableToRecordType(
2715  class_clang_type, attrs.name, var_type->GetForwardCompilerType(),
2716  attrs.accessibility);
2717  }
2718  return;
2719  }
2720 
2721  Type *member_type = die.ResolveTypeUID(attrs.encoding_form.Reference());
2722  if (!member_type) {
2723  if (attrs.name)
2724  module_sp->ReportError(
2725  "0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8x"
2726  " which was unable to be parsed",
2727  die.GetID(), attrs.name, attrs.encoding_form.Reference().GetOffset());
2728  else
2729  module_sp->ReportError(
2730  "0x%8.8" PRIx64 ": DW_TAG_member refers to type 0x%8.8x"
2731  " which was unable to be parsed",
2732  die.GetID(), attrs.encoding_form.Reference().GetOffset());
2733  return;
2734  }
2735 
2736  clang::FieldDecl *field_decl = nullptr;
2737  const uint64_t character_width = 8;
2738  const uint64_t word_width = 32;
2739  CompilerType member_clang_type = member_type->GetLayoutCompilerType();
2740 
2741  if (attrs.accessibility == eAccessNone)
2742  attrs.accessibility = default_accessibility;
2743 
2744  uint64_t field_bit_offset = (attrs.member_byte_offset == UINT32_MAX
2745  ? 0
2746  : (attrs.member_byte_offset * 8));
2747 
2748  if (attrs.bit_size > 0) {
2749  FieldInfo this_field_info;
2750  this_field_info.bit_offset = field_bit_offset;
2751  this_field_info.bit_size = attrs.bit_size;
2752 
2753  if (attrs.data_bit_offset != UINT64_MAX) {
2754  this_field_info.bit_offset = attrs.data_bit_offset;
2755  } else {
2756  if (!attrs.byte_size)
2757  attrs.byte_size = member_type->GetByteSize(nullptr);
2758 
2759  ObjectFile *objfile = die.GetDWARF()->GetObjectFile();
2760  if (objfile->GetByteOrder() == eByteOrderLittle) {
2761  this_field_info.bit_offset += attrs.byte_size.getValueOr(0) * 8;
2762  this_field_info.bit_offset -= (attrs.bit_offset + attrs.bit_size);
2763  } else {
2764  this_field_info.bit_offset += attrs.bit_offset;
2765  }
2766  }
2767 
2768  // The ObjC runtime knows the byte offset but we still need to provide
2769  // the bit-offset in the layout. It just means something different then
2770  // what it does in C and C++. So we skip this check for ObjC types.
2771  //
2772  // We also skip this for fields of a union since they will all have a
2773  // zero offset.
2774  if (!TypeSystemClang::IsObjCObjectOrInterfaceType(class_clang_type) &&
2775  !(parent_die.Tag() == DW_TAG_union_type &&
2776  this_field_info.bit_offset == 0) &&
2777  ((this_field_info.bit_offset >= parent_bit_size) ||
2778  (last_field_info.IsBitfield() &&
2779  !last_field_info.NextBitfieldOffsetIsValid(
2780  this_field_info.bit_offset)))) {
2781  ObjectFile *objfile = die.GetDWARF()->GetObjectFile();
2782  objfile->GetModule()->ReportWarning(
2783  "0x%8.8" PRIx64 ": %s bitfield named \"%s\" has invalid "
2784  "bit offset (0x%8.8" PRIx64
2785  ") member will be ignored. Please file a bug against the "
2786  "compiler and include the preprocessed output for %s\n",
2787  die.GetID(), DW_TAG_value_to_name(tag), attrs.name,
2788  this_field_info.bit_offset, GetUnitName(parent_die).c_str());
2789  return;
2790  }
2791 
2792  // Update the field bit offset we will report for layout
2793  field_bit_offset = this_field_info.bit_offset;
2794 
2795  // Objective-C has invalid DW_AT_bit_offset values in older
2796  // versions of clang, so we have to be careful and only insert
2797  // unnamed bitfields if we have a new enough clang.
2798  bool detect_unnamed_bitfields = true;
2799 
2800  if (class_is_objc_object_or_interface)
2801  detect_unnamed_bitfields =
2803 
2804  if (detect_unnamed_bitfields) {
2805  clang::Optional<FieldInfo> unnamed_field_info;
2806  uint64_t last_field_end = 0;
2807 
2808  last_field_end = last_field_info.bit_offset + last_field_info.bit_size;
2809 
2810  if (!last_field_info.IsBitfield()) {
2811  // The last field was not a bit-field...
2812  // but if it did take up the entire word then we need to extend
2813  // last_field_end so the bit-field does not step into the last
2814  // fields padding.
2815  if (last_field_end != 0 && ((last_field_end % word_width) != 0))
2816  last_field_end += word_width - (last_field_end % word_width);
2817  }
2818 
2819  // If we have a gap between the last_field_end and the current
2820  // field we have an unnamed bit-field.
2821  // If we have a base class, we assume there is no unnamed
2822  // bit-field if this is the first field since the gap can be
2823  // attributed to the members from the base class. This assumption
2824  // is not correct if the first field of the derived class is
2825  // indeed an unnamed bit-field. We currently do not have the
2826  // machinary to track the offset of the last field of classes we
2827  // have seen before, so we are not handling this case.
2828  if (this_field_info.bit_offset != last_field_end &&
2829  this_field_info.bit_offset > last_field_end &&
2830  !(last_field_info.bit_offset == 0 &&
2831  last_field_info.bit_size == 0 &&
2832  layout_info.base_offsets.size() != 0)) {
2833  unnamed_field_info = FieldInfo{};
2834  unnamed_field_info->bit_size =
2835  this_field_info.bit_offset - last_field_end;
2836  unnamed_field_info->bit_offset = last_field_end;
2837  }
2838 
2839  if (unnamed_field_info) {
2840  clang::FieldDecl *unnamed_bitfield_decl =
2841  TypeSystemClang::AddFieldToRecordType(
2842  class_clang_type, llvm::StringRef(),
2844  word_width),
2845  attrs.accessibility, unnamed_field_info->bit_size);
2846 
2847  layout_info.field_offsets.insert(std::make_pair(
2848  unnamed_bitfield_decl, unnamed_field_info->bit_offset));
2849  }
2850  }
2851 
2852  last_field_info = this_field_info;
2853  last_field_info.SetIsBitfield(true);
2854  } else {
2855  last_field_info.bit_offset = field_bit_offset;
2856 
2857  if (llvm::Optional<uint64_t> clang_type_size =
2858  member_type->GetByteSize(nullptr)) {
2859  last_field_info.bit_size = *clang_type_size * character_width;
2860  }
2861 
2862  last_field_info.SetIsBitfield(false);
2863  }
2864 
2865  if (!member_clang_type.IsCompleteType())
2866  member_clang_type.GetCompleteType();
2867 
2868  {
2869  // Older versions of clang emit array[0] and array[1] in the
2870  // same way (<rdar://problem/12566646>). If the current field
2871  // is at the end of the structure, then there is definitely no
2872  // room for extra elements and we override the type to
2873  // array[0].
2874 
2875  CompilerType member_array_element_type;
2876  uint64_t member_array_size;
2877  bool member_array_is_incomplete;
2878 
2879  if (member_clang_type.IsArrayType(&member_array_element_type,
2880  &member_array_size,
2881  &member_array_is_incomplete) &&
2882  !member_array_is_incomplete) {
2883  uint64_t parent_byte_size =
2884  parent_die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX);
2885 
2886  if (attrs.member_byte_offset >= parent_byte_size) {
2887  if (member_array_size != 1 &&
2888  (member_array_size != 0 ||
2889  attrs.member_byte_offset > parent_byte_size)) {
2890  module_sp->ReportError(
2891  "0x%8.8" PRIx64 ": DW_TAG_member '%s' refers to type 0x%8.8x"
2892  " which extends beyond the bounds of 0x%8.8" PRIx64,
2893  die.GetID(), attrs.name,
2894  attrs.encoding_form.Reference().GetOffset(),
2895  parent_die.GetID());
2896  }
2897 
2898  member_clang_type =
2899  m_ast.CreateArrayType(member_array_element_type, 0, false);
2900  }
2901  }
2902  }
2903 
2904  RequireCompleteType(member_clang_type);
2905 
2906  field_decl = TypeSystemClang::AddFieldToRecordType(
2907  class_clang_type, attrs.name, member_clang_type, attrs.accessibility,
2908  attrs.bit_size);
2909 
2910  m_ast.SetMetadataAsUserID(field_decl, die.GetID());
2911 
2912  layout_info.field_offsets.insert(
2913  std::make_pair(field_decl, field_bit_offset));
2914 }
2915 
2917  const DWARFDIE &parent_die, CompilerType &class_clang_type,
2918  std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> &base_classes,
2919  std::vector<DWARFDIE> &member_function_dies,
2920  DelayedPropertyList &delayed_properties,
2921  const AccessType default_accessibility,
2922  ClangASTImporter::LayoutInfo &layout_info) {
2923  if (!parent_die)
2924  return false;
2925 
2926  FieldInfo last_field_info;
2927 
2928  ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule();
2929  TypeSystemClang *ast =
2930  llvm::dyn_cast_or_null<TypeSystemClang>(class_clang_type.GetTypeSystem());
2931  if (ast == nullptr)
2932  return false;
2933 
2934  for (DWARFDIE die : parent_die.children()) {
2935  dw_tag_t tag = die.Tag();
2936 
2937  switch (tag) {
2938  case DW_TAG_APPLE_property:
2939  ParseObjCProperty(die, parent_die, class_clang_type, delayed_properties);
2940  break;
2941 
2942  case DW_TAG_member:
2943  ParseSingleMember(die, parent_die, class_clang_type,
2944  default_accessibility, layout_info, last_field_info);
2945  break;
2946 
2947  case DW_TAG_subprogram:
2948  // Let the type parsing code handle this one for us.
2949  member_function_dies.push_back(die);
2950  break;
2951 
2952  case DW_TAG_inheritance:
2953  ParseInheritance(die, parent_die, class_clang_type, default_accessibility,
2954  module_sp, base_classes, layout_info);
2955  break;
2956 
2957  default:
2958  break;
2959  }
2960  }
2961 
2962  return true;
2963 }
2964 
2966  clang::DeclContext *containing_decl_ctx, const DWARFDIE &parent_die,
2967  bool skip_artificial, bool &is_static, bool &is_variadic,
2968  bool &has_template_params, std::vector<CompilerType> &function_param_types,
2969  std::vector<clang::ParmVarDecl *> &function_param_decls,
2970  unsigned &type_quals) {
2971  if (!parent_die)
2972  return 0;
2973 
2974  size_t arg_idx = 0;
2975  for (DWARFDIE die : parent_die.children()) {
2976  const dw_tag_t tag = die.Tag();
2977  switch (tag) {
2978  case DW_TAG_formal_parameter: {
2979  DWARFAttributes attributes;
2980  const size_t num_attributes = die.GetAttributes(attributes);
2981  if (num_attributes > 0) {
2982  const char *name = nullptr;
2983  DWARFFormValue param_type_die_form;
2984  bool is_artificial = false;
2985  // one of None, Auto, Register, Extern, Static, PrivateExtern
2986 
2987  clang::StorageClass storage = clang::SC_None;
2988  uint32_t i;
2989  for (i = 0; i < num_attributes; ++i) {
2990  const dw_attr_t attr = attributes.AttributeAtIndex(i);
2991  DWARFFormValue form_value;
2992  if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2993  switch (attr) {
2994  case DW_AT_name:
2995  name = form_value.AsCString();
2996  break;
2997  case DW_AT_type:
2998  param_type_die_form = form_value;
2999  break;
3000  case DW_AT_artificial:
3001  is_artificial = form_value.Boolean();
3002  break;
3003  case DW_AT_location:
3004  case DW_AT_const_value:
3005  case DW_AT_default_value:
3006  case DW_AT_description:
3007  case DW_AT_endianity:
3008  case DW_AT_is_optional:
3009  case DW_AT_segment:
3010  case DW_AT_variable_parameter:
3011  default:
3012  case DW_AT_abstract_origin:
3013  case DW_AT_sibling:
3014  break;
3015  }
3016  }
3017  }
3018 
3019  bool skip = false;
3020  if (skip_artificial && is_artificial) {
3021  // In order to determine if a C++ member function is "const" we
3022  // have to look at the const-ness of "this"...
3023  if (arg_idx == 0 &&
3024  DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()) &&
3025  // Often times compilers omit the "this" name for the
3026  // specification DIEs, so we can't rely upon the name being in
3027  // the formal parameter DIE...
3028  (name == nullptr || ::strcmp(name, "this") == 0)) {
3029  Type *this_type =
3030  die.ResolveTypeUID(param_type_die_form.Reference());
3031  if (this_type) {
3032  uint32_t encoding_mask = this_type->GetEncodingMask();
3033  if (encoding_mask & Type::eEncodingIsPointerUID) {
3034  is_static = false;
3035 
3036  if (encoding_mask & (1u << Type::eEncodingIsConstUID))
3037  type_quals |= clang::Qualifiers::Const;
3038  if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
3039  type_quals |= clang::Qualifiers::Volatile;
3040  }
3041  }
3042  }
3043  skip = true;
3044  }
3045 
3046  if (!skip) {
3047  Type *type = die.ResolveTypeUID(param_type_die_form.Reference());
3048  if (type) {
3049  function_param_types.push_back(type->GetForwardCompilerType());
3050 
3051  clang::ParmVarDecl *param_var_decl =
3053  containing_decl_ctx, GetOwningClangModule(die), name,
3054  type->GetForwardCompilerType(), storage);
3055  assert(param_var_decl);
3056  function_param_decls.push_back(param_var_decl);
3057 
3058  m_ast.SetMetadataAsUserID(param_var_decl, die.GetID());
3059  }
3060  }
3061  }
3062  arg_idx++;
3063  } break;
3064 
3065  case DW_TAG_unspecified_parameters:
3066  is_variadic = true;
3067  break;
3068 
3069  case DW_TAG_template_type_parameter:
3070  case DW_TAG_template_value_parameter:
3071  case DW_TAG_GNU_template_parameter_pack:
3072  // The one caller of this was never using the template_param_infos, and
3073  // the local variable was taking up a large amount of stack space in
3074  // SymbolFileDWARF::ParseType() so this was removed. If we ever need the
3075  // template params back, we can add them back.
3076  // ParseTemplateDIE (dwarf_cu, die, template_param_infos);
3077  has_template_params = true;
3078  break;
3079 
3080  default:
3081  break;
3082  }
3083  }
3084  return arg_idx;
3085 }
3086 
3087 llvm::Optional<SymbolFile::ArrayInfo>
3089  const ExecutionContext *exe_ctx) {
3090  SymbolFile::ArrayInfo array_info;
3091  if (!parent_die)
3092  return llvm::None;
3093 
3094  for (DWARFDIE die : parent_die.children()) {
3095  const dw_tag_t tag = die.Tag();
3096  if (tag != DW_TAG_subrange_type)
3097  continue;
3098 
3099  DWARFAttributes attributes;
3100  const size_t num_child_attributes = die.GetAttributes(attributes);
3101  if (num_child_attributes > 0) {
3102  uint64_t num_elements = 0;
3103  uint64_t lower_bound = 0;
3104  uint64_t upper_bound = 0;
3105  bool upper_bound_valid = false;
3106  uint32_t i;
3107  for (i = 0; i < num_child_attributes; ++i) {
3108  const dw_attr_t attr = attributes.AttributeAtIndex(i);
3109  DWARFFormValue form_value;
3110  if (attributes.ExtractFormValueAtIndex(i, form_value)) {
3111  switch (attr) {
3112  case DW_AT_name:
3113  break;
3114 
3115  case DW_AT_count:
3116  if (DWARFDIE var_die = die.GetReferencedDIE(DW_AT_count)) {
3117  if (var_die.Tag() == DW_TAG_variable)
3118  if (exe_ctx) {
3119  if (auto frame = exe_ctx->GetFrameSP()) {
3120  Status error;
3121  lldb::VariableSP var_sp;
3122  auto valobj_sp = frame->GetValueForVariableExpressionPath(
3123  var_die.GetName(), eNoDynamicValues, 0, var_sp,
3124  error);
3125  if (valobj_sp) {
3126  num_elements = valobj_sp->GetValueAsUnsigned(0);
3127  break;
3128  }
3129  }
3130  }
3131  } else
3132  num_elements = form_value.Unsigned();
3133  break;
3134 
3135  case DW_AT_bit_stride:
3136  array_info.bit_stride = form_value.Unsigned();
3137  break;
3138 
3139  case DW_AT_byte_stride:
3140  array_info.byte_stride = form_value.Unsigned();
3141  break;
3142 
3143  case DW_AT_lower_bound:
3144  lower_bound = form_value.Unsigned();
3145  break;
3146 
3147  case DW_AT_upper_bound:
3148  upper_bound_valid = true;
3149  upper_bound = form_value.Unsigned();
3150  break;
3151 
3152  default:
3153  case DW_AT_abstract_origin:
3154  case DW_AT_accessibility:
3155  case DW_AT_allocated:
3156  case DW_AT_associated:
3157  case DW_AT_data_location:
3158  case DW_AT_declaration:
3159  case DW_AT_description:
3160  case DW_AT_sibling:
3161  case DW_AT_threads_scaled:
3162  case DW_AT_type:
3163  case DW_AT_visibility:
3164  break;
3165  }
3166  }
3167  }
3168 
3169  if (num_elements == 0) {
3170  if (upper_bound_valid && upper_bound >= lower_bound)
3171  num_elements = upper_bound - lower_bound + 1;
3172  }
3173 
3174  array_info.element_orders.push_back(num_elements);
3175  }
3176  }
3177  return array_info;
3178 }
3179 
3181  if (die) {
3182  SymbolFileDWARF *dwarf = die.GetDWARF();
3183  DWARFAttributes attributes;
3184  const size_t num_attributes = die.GetAttributes(attributes);
3185  if (num_attributes > 0) {
3186  DWARFFormValue type_die_form;
3187  for (size_t i = 0; i < num_attributes; ++i) {
3188  dw_attr_t attr = attributes.AttributeAtIndex(i);
3189  DWARFFormValue form_value;
3190 
3191  if (attr == DW_AT_type &&
3192  attributes.ExtractFormValueAtIndex(i, form_value))
3193  return dwarf->ResolveTypeUID(form_value.Reference(), true);
3194  }
3195  }
3196  }
3197 
3198  return nullptr;
3199 }
3200 
3202  if (!die)
3203  return nullptr;
3204 
3205  switch (die.Tag()) {
3206  case DW_TAG_variable:
3207  case DW_TAG_constant:
3208  case DW_TAG_formal_parameter:
3209  case DW_TAG_imported_declaration:
3210  case DW_TAG_imported_module:
3211  break;
3212  default:
3213  return nullptr;
3214  }
3215 
3216  DIEToDeclMap::iterator cache_pos = m_die_to_decl.find(die.GetDIE());
3217  if (cache_pos != m_die_to_decl.end())
3218  return cache_pos->second;
3219 
3220  if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification)) {
3221  clang::Decl *decl = GetClangDeclForDIE(spec_die);
3222  m_die_to_decl[die.GetDIE()] = decl;
3223  return decl;
3224  }
3225 
3226  if (DWARFDIE abstract_origin_die =
3227  die.GetReferencedDIE(DW_AT_abstract_origin)) {
3228  clang::Decl *decl = GetClangDeclForDIE(abstract_origin_die);
3229  m_die_to_decl[die.GetDIE()] = decl;
3230  return decl;
3231  }
3232 
3233  clang::Decl *decl = nullptr;
3234  switch (die.Tag()) {
3235  case DW_TAG_variable:
3236  case DW_TAG_constant:
3237  case DW_TAG_formal_parameter: {
3238  SymbolFileDWARF *dwarf = die.GetDWARF();
3239  Type *type = GetTypeForDIE(die);
3240  if (dwarf && type) {
3241  const char *name = die.GetName();
3242  clang::DeclContext *decl_context =
3243  TypeSystemClang::DeclContextGetAsDeclContext(
3244  dwarf->GetDeclContextContainingUID(die.GetID()));
3246  decl_context, GetOwningClangModule(die), name,
3247  ClangUtil::GetQualType(type->GetForwardCompilerType()));
3248  }
3249  break;
3250  }
3251  case DW_TAG_imported_declaration: {
3252  SymbolFileDWARF *dwarf = die.GetDWARF();
3253  DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import);
3254  if (imported_uid) {
3255  CompilerDecl imported_decl = SymbolFileDWARF::GetDecl(imported_uid);
3256  if (imported_decl) {
3257  clang::DeclContext *decl_context =
3258  TypeSystemClang::DeclContextGetAsDeclContext(
3259  dwarf->GetDeclContextContainingUID(die.GetID()));
3260  if (clang::NamedDecl *clang_imported_decl =
3261  llvm::dyn_cast<clang::NamedDecl>(
3262  (clang::Decl *)imported_decl.GetOpaqueDecl()))
3264  decl_context, OptionalClangModuleID(), clang_imported_decl);
3265  }
3266  }
3267  break;
3268  }
3269  case DW_TAG_imported_module: {
3270  SymbolFileDWARF *dwarf = die.GetDWARF();
3271  DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import);
3272 
3273  if (imported_uid) {
3274  CompilerDeclContext imported_decl_ctx =
3275  SymbolFileDWARF::GetDeclContext(imported_uid);
3276  if (imported_decl_ctx) {
3277  clang::DeclContext *decl_context =
3278  TypeSystemClang::DeclContextGetAsDeclContext(
3279  dwarf->GetDeclContextContainingUID(die.GetID()));
3280  if (clang::NamespaceDecl *ns_decl =
3281  TypeSystemClang::DeclContextGetAsNamespaceDecl(
3282  imported_decl_ctx))
3284  decl_context, OptionalClangModuleID(), ns_decl);
3285  }
3286  }
3287  break;
3288  }
3289  default:
3290  break;
3291  }
3292 
3293  m_die_to_decl[die.GetDIE()] = decl;
3294 
3295  return decl;
3296 }
3297 
3298 clang::DeclContext *
3300  if (die) {
3301  clang::DeclContext *decl_ctx = GetCachedClangDeclContextForDIE(die);
3302  if (decl_ctx)
3303  return decl_ctx;
3304 
3305  bool try_parsing_type = true;
3306  switch (die.Tag()) {
3307  case DW_TAG_compile_unit:
3308  case DW_TAG_partial_unit:
3309  decl_ctx = m_ast.GetTranslationUnitDecl();
3310  try_parsing_type = false;
3311  break;
3312 
3313  case DW_TAG_namespace:
3314  decl_ctx = ResolveNamespaceDIE(die);
3315  try_parsing_type = false;
3316  break;
3317 
3318  case DW_TAG_lexical_block:
3319  decl_ctx = GetDeclContextForBlock(die);
3320  try_parsing_type = false;
3321  break;
3322 
3323  default:
3324  break;
3325  }
3326 
3327  if (decl_ctx == nullptr && try_parsing_type) {
3328  Type *type = die.GetDWARF()->ResolveType(die);
3329  if (type)
3330  decl_ctx = GetCachedClangDeclContextForDIE(die);
3331  }
3332 
3333  if (decl_ctx) {
3334  LinkDeclContextToDIE(decl_ctx, die);
3335  return decl_ctx;
3336  }
3337  }
3338  return nullptr;
3339 }
3340 
3343  if (!die.IsValid())
3344  return {};
3345 
3346  for (DWARFDIE parent = die.GetParent(); parent.IsValid();
3347  parent = parent.GetParent()) {
3348  const dw_tag_t tag = parent.Tag();
3349  if (tag == DW_TAG_module) {
3350  DWARFDIE module_die = parent;
3351  auto it = m_die_to_module.find(module_die.GetDIE());
3352  if (it != m_die_to_module.end())
3353  return it->second;
3354  const char *name = module_die.GetAttributeValueAsString(DW_AT_name, 0);
3355  if (!name)
3356  return {};
3357 
3360  m_die_to_module.insert({module_die.GetDIE(), id});
3361  return id;
3362  }
3363  }
3364  return {};
3365 }
3366 
3367 static bool IsSubroutine(const DWARFDIE &die) {
3368  switch (die.Tag()) {
3369  case DW_TAG_subprogram:
3370  case DW_TAG_inlined_subroutine:
3371  return true;
3372  default:
3373  return false;
3374  }
3375 }
3376 
3378  for (DWARFDIE candidate = die; candidate; candidate = candidate.GetParent()) {
3379  if (IsSubroutine(candidate)) {
3380  if (candidate.GetReferencedDIE(DW_AT_abstract_origin)) {
3381  return candidate;
3382  } else {
3383  return DWARFDIE();
3384  }
3385  }
3386  }
3387  assert(0 && "Shouldn't call GetContainingFunctionWithAbstractOrigin on "
3388  "something not in a function");
3389  return DWARFDIE();
3390 }
3391 
3393  for (DWARFDIE candidate : context.children()) {
3394  if (candidate.GetReferencedDIE(DW_AT_abstract_origin)) {
3395  return candidate;
3396  }
3397  }
3398  return DWARFDIE();
3399 }
3400 
3402  const DWARFDIE &function) {
3403  assert(IsSubroutine(function));
3404  for (DWARFDIE context = block; context != function.GetParent();
3405  context = context.GetParent()) {
3406  assert(!IsSubroutine(context) || context == function);
3407  if (DWARFDIE child = FindAnyChildWithAbstractOrigin(context)) {
3408  return child;
3409  }
3410  }
3411  return DWARFDIE();
3412 }
3413 
3414 clang::DeclContext *
3416  assert(die.Tag() == DW_TAG_lexical_block);
3417  DWARFDIE containing_function_with_abstract_origin =
3419  if (!containing_function_with_abstract_origin) {
3420  return (clang::DeclContext *)ResolveBlockDIE(die);
3421  }
3423  die, containing_function_with_abstract_origin);
3424  CompilerDeclContext decl_context =
3426  return (clang::DeclContext *)decl_context.GetOpaqueDeclContext();
3427 }
3428 
3429 clang::BlockDecl *DWARFASTParserClang::ResolveBlockDIE(const DWARFDIE &die) {
3430  if (die && die.Tag() == DW_TAG_lexical_block) {
3431  clang::BlockDecl *decl =
3432  llvm::cast_or_null<clang::BlockDecl>(m_die_to_decl_ctx[die.GetDIE()]);
3433 
3434  if (!decl) {
3435  DWARFDIE decl_context_die;
3436  clang::DeclContext *decl_context =
3437  GetClangDeclContextContainingDIE(die, &decl_context_die);
3438  decl =
3440 
3441  if (decl)
3442  LinkDeclContextToDIE((clang::DeclContext *)decl, die);
3443  }
3444 
3445  return decl;
3446  }
3447  return nullptr;
3448 }
3449 
3450 clang::NamespaceDecl *
3452  if (die && die.Tag() == DW_TAG_namespace) {
3453  // See if we already parsed this namespace DIE and associated it with a
3454  // uniqued namespace declaration
3455  clang::NamespaceDecl *namespace_decl =
3456  static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die.GetDIE()]);
3457  if (namespace_decl)
3458  return namespace_decl;
3459  else {
3460  const char *namespace_name = die.GetName();
3461  clang::DeclContext *containing_decl_ctx =
3462  GetClangDeclContextContainingDIE(die, nullptr);
3463  bool is_inline =
3464  die.GetAttributeValueAsUnsigned(DW_AT_export_symbols, 0) != 0;
3465 
3466  namespace_decl = m_ast.GetUniqueNamespaceDeclaration(
3467  namespace_name, containing_decl_ctx, GetOwningClangModule(die),
3468  is_inline);
3469  Log *log =
3470  nullptr; // (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
3471  if (log) {
3472  SymbolFileDWARF *dwarf = die.GetDWARF();
3473  if (namespace_name) {
3474  dwarf->GetObjectFile()->GetModule()->LogMessage(
3475  log,
3476  "ASTContext => %p: 0x%8.8" PRIx64
3477  ": DW_TAG_namespace with DW_AT_name(\"%s\") => "
3478  "clang::NamespaceDecl *%p (original = %p)",
3479  static_cast<void *>(&m_ast.getASTContext()), die.GetID(),
3480  namespace_name, static_cast<void *>(namespace_decl),
3481  static_cast<void *>(namespace_decl->getOriginalNamespace()));
3482  } else {
3483  dwarf->GetObjectFile()->GetModule()->LogMessage(
3484  log,
3485  "ASTContext => %p: 0x%8.8" PRIx64
3486  ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p "
3487  "(original = %p)",
3488  static_cast<void *>(&m_ast.getASTContext()), die.GetID(),
3489  static_cast<void *>(namespace_decl),
3490  static_cast<void *>(namespace_decl->getOriginalNamespace()));
3491  }
3492  }
3493 
3494  if (namespace_decl)
3495  LinkDeclContextToDIE((clang::DeclContext *)namespace_decl, die);
3496  return namespace_decl;
3497  }
3498  }
3499  return nullptr;
3500 }
3501 
3503  const DWARFDIE &die, DWARFDIE *decl_ctx_die_copy) {
3504  SymbolFileDWARF *dwarf = die.GetDWARF();
3505 
3506  DWARFDIE decl_ctx_die = dwarf->GetDeclContextDIEContainingDIE(die);
3507 
3508  if (decl_ctx_die_copy)
3509  *decl_ctx_die_copy = decl_ctx_die;
3510 
3511  if (decl_ctx_die) {
3512  clang::DeclContext *clang_decl_ctx =
3513  GetClangDeclContextForDIE(decl_ctx_die);
3514  if (clang_decl_ctx)
3515  return clang_decl_ctx;
3516  }
3517  return m_ast.GetTranslationUnitDecl();
3518 }
3519 
3520 clang::DeclContext *
3522  if (die) {
3523  DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die.GetDIE());
3524  if (pos != m_die_to_decl_ctx.end())
3525  return pos->second;
3526  }
3527  return nullptr;
3528 }
3529 
3530 void DWARFASTParserClang::LinkDeclContextToDIE(clang::DeclContext *decl_ctx,
3531  const DWARFDIE &die) {
3532  m_die_to_decl_ctx[die.GetDIE()] = decl_ctx;
3533  // There can be many DIEs for a single decl context
3534  // m_decl_ctx_to_die[decl_ctx].insert(die.GetDIE());
3535  m_decl_ctx_to_die.insert(std::make_pair(decl_ctx, die));
3536 }
3537 
3539  const DWARFDIE &src_class_die, const DWARFDIE &dst_class_die,
3540  lldb_private::Type *class_type, std::vector<DWARFDIE> &failures) {
3541  if (!class_type || !src_class_die || !dst_class_die)
3542  return false;
3543  if (src_class_die.Tag() != dst_class_die.Tag())
3544  return false;
3545 
3546  // We need to complete the class type so we can get all of the method types
3547  // parsed so we can then unique those types to their equivalent counterparts
3548  // in "dst_cu" and "dst_class_die"
3549  class_type->GetFullCompilerType();
3550 
3551  DWARFDIE src_die;
3552  DWARFDIE dst_die;
3553  UniqueCStringMap<DWARFDIE> src_name_to_die;
3554  UniqueCStringMap<DWARFDIE> dst_name_to_die;
3555  UniqueCStringMap<DWARFDIE> src_name_to_die_artificial;
3556  UniqueCStringMap<DWARFDIE> dst_name_to_die_artificial;
3557  for (src_die = src_class_die.GetFirstChild(); src_die.IsValid();
3558  src_die = src_die.GetSibling()) {
3559  if (src_die.Tag() == DW_TAG_subprogram) {
3560  // Make sure this is a declaration and not a concrete instance by looking
3561  // for DW_AT_declaration set to 1. Sometimes concrete function instances
3562  // are placed inside the class definitions and shouldn't be included in
3563  // the list of things are are tracking here.
3564  if (src_die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0) == 1) {
3565  const char *src_name = src_die.GetMangledName();
3566  if (src_name) {
3567  ConstString src_const_name(src_name);
3568  if (src_die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0))
3569  src_name_to_die_artificial.Append(src_const_name, src_die);
3570  else
3571  src_name_to_die.Append(src_const_name, src_die);
3572  }
3573  }
3574  }
3575  }
3576  for (dst_die = dst_class_die.GetFirstChild(); dst_die.IsValid();
3577  dst_die = dst_die.GetSibling()) {
3578  if (dst_die.Tag() == DW_TAG_subprogram) {
3579  // Make sure this is a declaration and not a concrete instance by looking
3580  // for DW_AT_declaration set to 1. Sometimes concrete function instances
3581  // are placed inside the class definitions and shouldn't be included in
3582  // the list of things are are tracking here.
3583  if (dst_die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0) == 1) {
3584  const char *dst_name = dst_die.GetMangledName();
3585  if (dst_name) {
3586  ConstString dst_const_name(dst_name);
3587  if (dst_die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0))
3588  dst_name_to_die_artificial.Append(dst_const_name, dst_die);
3589  else
3590  dst_name_to_die.Append(dst_const_name, dst_die);
3591  }
3592  }
3593  }
3594  }
3595  const uint32_t src_size = src_name_to_die.GetSize();
3596  const uint32_t dst_size = dst_name_to_die.GetSize();
3597  Log *log = nullptr; // (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO |
3598  // DWARF_LOG_TYPE_COMPLETION));
3599 
3600  // Is everything kosher so we can go through the members at top speed?
3601  bool fast_path = true;
3602 
3603  if (src_size != dst_size) {
3604  if (src_size != 0 && dst_size != 0) {
3605  LLDB_LOGF(log,
3606  "warning: trying to unique class DIE 0x%8.8x to 0x%8.8x, "
3607  "but they didn't have the same size (src=%d, dst=%d)",
3608  src_class_die.GetOffset(), dst_class_die.GetOffset(), src_size,
3609  dst_size);
3610  }
3611 
3612  fast_path = false;
3613  }
3614 
3615  uint32_t idx;
3616 
3617  if (fast_path) {
3618  for (idx = 0; idx < src_size; ++idx) {
3619  src_die = src_name_to_die.GetValueAtIndexUnchecked(idx);
3620  dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
3621 
3622  if (src_die.Tag() != dst_die.Tag()) {
3623  LLDB_LOGF(log,
3624  "warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, "
3625  "but 0x%8.8x (%s) tags didn't match 0x%8.8x (%s)",
3626  src_class_die.GetOffset(), dst_class_die.GetOffset(),
3627  src_die.GetOffset(), src_die.GetTagAsCString(),
3628  dst_die.GetOffset(), dst_die.GetTagAsCString());
3629  fast_path = false;
3630  }
3631 
3632  const char *src_name = src_die.GetMangledName();
3633  const char *dst_name = dst_die.GetMangledName();
3634 
3635  // Make sure the names match
3636  if (src_name == dst_name || (strcmp(src_name, dst_name) == 0))
3637  continue;
3638 
3639  LLDB_LOGF(log,
3640  "warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, "
3641  "but 0x%8.8x (%s) names didn't match 0x%8.8x (%s)",
3642  src_class_die.GetOffset(), dst_class_die.GetOffset(),
3643  src_die.GetOffset(), src_name, dst_die.GetOffset(), dst_name);
3644 
3645  fast_path = false;
3646  }
3647  }
3648 
3649  DWARFASTParserClang *src_dwarf_ast_parser =
3650  static_cast<DWARFASTParserClang *>(
3652  DWARFASTParserClang *dst_dwarf_ast_parser =
3653  static_cast<DWARFASTParserClang *>(
3655 
3656  // Now do the work of linking the DeclContexts and Types.
3657  if (fast_path) {
3658  // We can do this quickly. Just run across the tables index-for-index
3659  // since we know each node has matching names and tags.
3660  for (idx = 0; idx < src_size; ++idx) {
3661  src_die = src_name_to_die.GetValueAtIndexUnchecked(idx);
3662  dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
3663 
3664  clang::DeclContext *src_decl_ctx =
3665  src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()];
3666  if (src_decl_ctx) {
3667  LLDB_LOGF(log, "uniquing decl context %p from 0x%8.8x for 0x%8.8x",
3668  static_cast<void *>(src_decl_ctx), src_die.GetOffset(),
3669  dst_die.GetOffset());
3670  dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, dst_die);
3671  } else {
3672  LLDB_LOGF(log,
3673  "warning: tried to unique decl context from 0x%8.8x for "
3674  "0x%8.8x, but none was found",
3675  src_die.GetOffset(), dst_die.GetOffset());
3676  }
3677 
3678  Type *src_child_type =
3679  dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()];
3680  if (src_child_type) {
3681  LLDB_LOGF(log,
3682  "uniquing type %p (uid=0x%" PRIx64
3683  ") from 0x%8.8x for 0x%8.8x",
3684  static_cast<void *>(src_child_type), src_child_type->GetID(),
3685  src_die.GetOffset(), dst_die.GetOffset());
3686  dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type;
3687  } else {
3688  LLDB_LOGF(log,
3689  "warning: tried to unique lldb_private::Type from "
3690  "0x%8.8x for 0x%8.8x, but none was found",
3691  src_die.GetOffset(), dst_die.GetOffset());
3692  }
3693  }
3694  } else {
3695  // We must do this slowly. For each member of the destination, look up a
3696  // member in the source with the same name, check its tag, and unique them
3697  // if everything matches up. Report failures.
3698 
3699  if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty()) {
3700  src_name_to_die.Sort();
3701 
3702  for (idx = 0; idx < dst_size; ++idx) {
3703  ConstString dst_name = dst_name_to_die.GetCStringAtIndex(idx);
3704  dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
3705  src_die = src_name_to_die.Find(dst_name, DWARFDIE());
3706 
3707  if (src_die && (src_die.Tag() == dst_die.Tag())) {
3708  clang::DeclContext *src_decl_ctx =
3709  src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()];
3710  if (src_decl_ctx) {
3711  LLDB_LOGF(log, "uniquing decl context %p from 0x%8.8x for 0x%8.8x",
3712  static_cast<void *>(src_decl_ctx), src_die.GetOffset(),
3713  dst_die.GetOffset());
3714  dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, dst_die);
3715  } else {
3716  LLDB_LOGF(log,
3717  "warning: tried to unique decl context from 0x%8.8x "
3718  "for 0x%8.8x, but none was found",
3719  src_die.GetOffset(), dst_die.GetOffset());
3720  }
3721 
3722  Type *src_child_type =
3723  dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()];
3724  if (src_child_type) {
3725  LLDB_LOGF(
3726  log,
3727  "uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
3728  static_cast<void *>(src_child_type), src_child_type->GetID(),
3729  src_die.GetOffset(), dst_die.GetOffset());
3730  dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] =
3731  src_child_type;
3732  } else {
3733  LLDB_LOGF(log,
3734  "warning: tried to unique lldb_private::Type from "
3735  "0x%8.8x for 0x%8.8x, but none was found",
3736  src_die.GetOffset(), dst_die.GetOffset());
3737  }
3738  } else {
3739  LLDB_LOGF(log, "warning: couldn't find a match for 0x%8.8x",
3740  dst_die.GetOffset());
3741 
3742  failures.push_back(dst_die);
3743  }
3744  }
3745  }
3746  }
3747 
3748  const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize();
3749  const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize();
3750 
3751  if (src_size_artificial && dst_size_artificial) {
3752  dst_name_to_die_artificial.Sort();
3753 
3754  for (idx = 0; idx < src_size_artificial; ++idx) {
3755  ConstString src_name_artificial =
3756  src_name_to_die_artificial.GetCStringAtIndex(idx);
3757  src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked(idx);
3758  dst_die =
3759  dst_name_to_die_artificial.Find(src_name_artificial, DWARFDIE());
3760 
3761  if (dst_die) {
3762  // Both classes have the artificial types, link them
3763  clang::DeclContext *src_decl_ctx =
3764  src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()];
3765  if (src_decl_ctx) {
3766  LLDB_LOGF(log, "uniquing decl context %p from 0x%8.8x for 0x%8.8x",
3767  static_cast<void *>(src_decl_ctx), src_die.GetOffset(),
3768  dst_die.GetOffset());
3769  dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, dst_die);
3770  } else {
3771  LLDB_LOGF(log,
3772  "warning: tried to unique decl context from 0x%8.8x "
3773  "for 0x%8.8x, but none was found",
3774  src_die.GetOffset(), dst_die.GetOffset());
3775  }
3776 
3777  Type *src_child_type =
3778  dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()];
3779  if (src_child_type) {
3780  LLDB_LOGF(
3781  log,
3782  "uniquing type %p (uid=0x%" PRIx64 ") from 0x%8.8x for 0x%8.8x",
3783  static_cast<void *>(src_child_type), src_child_type->GetID(),
3784  src_die.GetOffset(), dst_die.GetOffset());
3785  dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type;
3786  } else {
3787  LLDB_LOGF(log,
3788  "warning: tried to unique lldb_private::Type from "
3789  "0x%8.8x for 0x%8.8x, but none was found",
3790  src_die.GetOffset(), dst_die.GetOffset());
3791  }
3792  }
3793  }
3794  }
3795 
3796  if (dst_size_artificial) {
3797  for (idx = 0; idx < dst_size_artificial; ++idx) {
3798  ConstString dst_name_artificial =
3799  dst_name_to_die_artificial.GetCStringAtIndex(idx);
3800  dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked(idx);
3801  LLDB_LOGF(log,
3802  "warning: need to create artificial method for 0x%8.8x for "
3803  "method '%s'",
3804  dst_die.GetOffset(), dst_name_artificial.GetCString());
3805 
3806  failures.push_back(dst_die);
3807  }
3808  }
3809 
3810  return !failures.empty();
3811 }
lldb_private::Declaration::SetLine
void SetLine(uint32_t line)
Set accessor for the declaration line number.
Definition: Declaration.h:170
lldb_private::ClangASTImporter::LayoutInfo::field_offsets
llvm::DenseMap< const clang::FieldDecl *, uint64_t > field_offsets
Definition: ClangASTImporter.h:73
lldb_private::TypeSystemClang::CreateBlockPointerType
CompilerType CreateBlockPointerType(const CompilerType &function_type)
Definition: TypeSystemClang.cpp:2220
ParsedDWARFTypeAttributes::is_vector
bool is_vector
Definition: DWARFASTParserClang.h:267
DWARFASTParserClang::DelayedAddObjCClassProperty
Definition: DWARFASTParserClang.cpp:1911
lldb_private::AddressRange::GetBaseAddress
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:209
DWARFASTParserClang::CopyUniqueClassMethodTypes
bool CopyUniqueClassMethodTypes(const DWARFDIE &src_class_die, const DWARFDIE &dst_class_die, lldb_private::Type *class_type, std::vector< DWARFDIE > &failures)
Definition: DWARFASTParserClang.cpp:3538
SymbolFileDWARFDebugMap.h
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:2195
lldb_private::TypeSystemClang::CreateBlockDeclaration
clang::BlockDecl * CreateBlockDeclaration(clang::DeclContext *ctx, OptionalClangModuleID owning_module)
Definition: TypeSystemClang.cpp:1907
lldb_private::DW_TAG_value_to_name
const char * DW_TAG_value_to_name(uint32_t val)
Definition: DWARFDefines.cpp:17
DWARFASTParserClang::DelayedAddObjCClassProperty::m_metadata_up
std::unique_ptr< ClangASTMetadata > m_metadata_up
Definition: DWARFASTParserClang.cpp:1965
DWARFASTParserClang::GetTypeForDIE
lldb_private::Type * GetTypeForDIE(const DWARFDIE &die)
Definition: DWARFASTParserClang.cpp:3180
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::SymbolContext::comp_unit
CompileUnit * comp_unit
The CompileUnit for a given query.
Definition: SymbolContext.h:319
lldb_private::ClangASTImporter::CopyType
CompilerType CopyType(TypeSystemClang &dst, const CompilerType &src_type)
Copies the given type and the respective declarations to the destination type system.
Definition: ClangASTImporter.cpp:31
lldb_private::Type::EncodingDataType
EncodingDataType
Definition: Type.h:68
DWARFFormValue::Reference
DWARFDIE Reference() const
Definition: DWARFFormValue.cpp:501
DWARFDIE::GetParent
DWARFDIE GetParent() const
Definition: DWARFDIE.cpp:90
lldb_private::UniqueCStringMap::Sort
void Sort()
Definition: UniqueCStringMap.h:168
DWARFBaseDIE::GetData
const lldb_private::DWARFDataExtractor & GetData() const
Definition: DWARFBaseDIE.cpp:123
FindFirstChildWithAbstractOrigin
static DWARFDIE FindFirstChildWithAbstractOrigin(const DWARFDIE &block, const DWARFDIE &function)
Definition: DWARFASTParserClang.cpp:3401
lldb_private::TypeSystemClang::TransferBaseClasses
bool TransferBaseClasses(lldb::opaque_compiler_type_t type, std::vector< std::unique_ptr< clang::CXXBaseSpecifier >> bases)
Definition: TypeSystemClang.cpp:7715
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:461
lldb_private::TypeSystemClang::getASTContext
clang::ASTContext & getASTContext()
Returns the clang::ASTContext instance managed by this TypeSystemClang.
Definition: TypeSystemClang.cpp:688
lldb_private::Address::IsValid
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:336
DWARFASTParserClang::DelayedAddObjCClassProperty::DelayedAddObjCClassProperty
DelayedAddObjCClassProperty(const CompilerType &class_opaque_type, const char *property_name, const CompilerType &property_opaque_type, const char *property_setter_name, const char *property_getter_name, uint32_t property_attributes, const ClangASTMetadata *metadata)
Definition: DWARFASTParserClang.cpp:1913
ParsedDWARFTypeAttributes::name
lldb_private::ConstString name
Definition: DWARFASTParserClang.h:273
DWARFBaseDIE::GetDIERef
llvm::Optional< DIERef > GetDIERef() const
Definition: DWARFBaseDIE.cpp:21
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:1204
ParsedDWARFTypeAttributes
Parsed form of all attributes that are relevant for type reconstruction.
Definition: DWARFASTParserClang.h:257
CompileUnit.h
lldb_private::TypeSystemClang::CreateTemplateTemplateParmDecl
clang::TemplateTemplateParmDecl * CreateTemplateTemplateParmDecl(const char *template_name)
Definition: TypeSystemClang.cpp:1626
lldb::eRegisterKindDWARF
@ eRegisterKindDWARF
the register numbers seen DWARF
Definition: lldb-enumerations.h:229
lldb::eAccessProtected
@ eAccessProtected
Definition: lldb-enumerations.h:511
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)
Definition: TypeSystemClang.cpp:2157
DWARFASTParserClang::GetCachedClangDeclContextForDIE
clang::DeclContext * GetCachedClangDeclContextForDIE(const DWARFDIE &die)
Definition: DWARFASTParserClang.cpp:3521
lldb_private::CompilerType::IsDefined
bool IsDefined() const
Definition: CompilerType.cpp:201
TypeMap.h
ParsedDWARFTypeAttributes::type
DWARFFormValue type
Definition: DWARFASTParserClang.h:280
lldb_private::Value
Definition: Value.h:38
lldb::eNoDynamicValues
@ eNoDynamicValues
Definition: lldb-enumerations.h:495
DWARFBaseDIE::Supports_DW_AT_APPLE_objc_complete_type
bool Supports_DW_AT_APPLE_objc_complete_type() const
Definition: DWARFBaseDIE.cpp:103
ParsedDWARFTypeAttributes::is_forward_declaration
bool is_forward_declaration
Definition: DWARFASTParserClang.h:264
DWARFASTParserClang::DelayedAddObjCClassProperty::m_property_setter_name
const char * m_property_setter_name
Definition: DWARFASTParserClang.cpp:1962
Host.h
SymbolFileDWARF::GetParentSymbolContextDIE
static DWARFDIE GetParentSymbolContextDIE(const DWARFDIE &die)
Definition: SymbolFileDWARF.cpp:410
lldb_private::TypeMap::GetTypeAtIndex
lldb::TypeSP GetTypeAtIndex(uint32_t idx)
Definition: TypeMap.cpp:83
DWARFASTParserClang::ParseChildMembers
bool ParseChildMembers(const DWARFDIE &die, lldb_private::CompilerType &class_compiler_type, std::vector< std::unique_ptr< clang::CXXBaseSpecifier >> &base_classes, std::vector< DWARFDIE > &member_function_dies, DelayedPropertyList &delayed_properties, const lldb::AccessType default_accessibility, lldb_private::ClangASTImporter::LayoutInfo &layout_info)
Definition: DWARFASTParserClang.cpp:2916
DWARFBaseDIE::GetAttributes
size_t GetAttributes(DWARFAttributes &attributes, Recurse recurse=Recurse::yes) const
Definition: DWARFBaseDIE.cpp:107
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:2123
lldb_private::TypeSystemClang::GetTranslationUnitDecl
clang::TranslationUnitDecl * GetTranslationUnitDecl()
Definition: TypeSystemClang.h:221
dw_tag_t
llvm::dwarf::Tag dw_tag_t
Definition: dwarf.h:25
DWARFASTParserClang::DelayedPropertyList
std::vector< DelayedAddObjCClassProperty > DelayedPropertyList
Definition: DWARFASTParserClang.h:73
DWARF_LOG_LOOKUPS
#define DWARF_LOG_LOOKUPS
Definition: LogChannelDWARF.h:16
DWARFASTParser::ParseChildArrayInfo
static llvm::Optional< lldb_private::SymbolFile::ArrayInfo > ParseChildArrayInfo(const DWARFDIE &parent_die, const lldb_private::ExecutionContext *exe_ctx=nullptr)
Definition: DWARFASTParserClang.cpp:3088
ParsedDWARFTypeAttributes::class_language
lldb::LanguageType class_language
Definition: DWARFASTParserClang.h:281
lldb_private::SymbolFile::ArrayInfo::byte_stride
uint32_t byte_stride
Definition: SymbolFile.h:188
lldb_private::ClangASTMetadata::SetUserID
void SetUserID(lldb::user_id_t user_id)
Definition: ClangASTMetadata.h:29
lldb_private::Type::GetLayoutCompilerType
CompilerType GetLayoutCompilerType()
Definition: Type.cpp:651
LLDB_INVALID_UID
#define LLDB_INVALID_UID
Definition: lldb-defines.h:92
lldb_private::CompilerType::IsCompleteType
bool IsCompleteType() const
Definition: CompilerType.cpp:83
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
lldb_private::CompilerDecl::GetOpaqueDecl
void * GetOpaqueDecl() const
Definition: CompilerDecl.h:58
skip
static bool skip(llvm::StringRef data)
Check if we should reply to the given packet.
Definition: GDBRemoteCommunicationReplayServer.cpp:54
DWARFASTParserClang::ResolveNamespaceDIE
clang::NamespaceDecl * ResolveNamespaceDIE(const DWARFDIE &die)
Definition: DWARFASTParserClang.cpp:3451
lldb_private::RangeVector::GetMinRangeBase
BaseType GetMinRangeBase(BaseType fail_value) const
Definition: RangeMap.h:218
lldb_private::TypeSystemClang::GetBuiltinTypeForEncodingAndBitSize
CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding, size_t bit_size) override
Definition: TypeSystemClang.cpp:799
Module.h
ParsedDWARFTypeAttributes::signature
DWARFFormValue signature
Definition: DWARFASTParserClang.h:278
SymbolFileDWARFDebugMap::FindCompleteObjCDefinitionTypeForDIE
lldb::TypeSP FindCompleteObjCDefinitionTypeForDIE(const DWARFDIE &die, lldb_private::ConstString type_name, bool must_be_implementation)
Definition: SymbolFileDWARFDebugMap.cpp:1112
IsClangModuleFwdDecl
static bool IsClangModuleFwdDecl(const DWARFDIE &Die)
Detect a forward declaration that is nested in a DW_TAG_module.
Definition: DWARFASTParserClang.cpp:99
DWARFASTParserClang::GetDeclForUIDFromDWARF
lldb_private::CompilerDecl GetDeclForUIDFromDWARF(const DWARFDIE &die) override
Definition: DWARFASTParserClang.cpp:2255
SymbolFileDWARF
Definition: SymbolFileDWARF.h:58
DWARFASTParserClang::DelayedAddObjCClassProperty::m_property_attributes
uint32_t m_property_attributes
Definition: DWARFASTParserClang.cpp:1964
DIE_IS_BEING_PARSED
#define DIE_IS_BEING_PARSED
Definition: SymbolFileDWARF.h:56
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
SymbolFileDWARF.h
lldb_private::ClangASTImporter::LayoutInfo
Definition: ClangASTImporter.h:66
ParsedDWARFTypeAttributes::byte_stride
uint32_t byte_stride
Definition: DWARFASTParserClang.h:285
lldb_private::CompilerDecl
Represents a generic declaration such as a function declaration.
Definition: CompilerDecl.h:28
lldb_private::ConstString::SetCString
void SetCString(const char *cstr)
Set the C string value.
Definition: ConstString.cpp:302
lldb_private::Module
Definition: Module.h:84
lldb_private::ConstString::AsCString
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:193
DWARFASTParserClang::ParseTemplateParameterInfos
bool ParseTemplateParameterInfos(const DWARFDIE &parent_die, lldb_private::TypeSystemClang::TemplateParameterInfos &template_param_infos)
Definition: DWARFASTParserClang.cpp:2076
lldb_private::SymbolFile::GetObjectFile
ObjectFile * GetObjectFile()
Definition: SymbolFile.h:266
lldb_private::CompilerType::GetByteSize
llvm::Optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
Definition: CompilerType.cpp:489
lldb_private::CompilerType::GetOpaqueQualType
lldb::opaque_compiler_type_t GetOpaqueQualType() const
Definition: CompilerType.h:173
DWARFDIE::GetDeclContext
void GetDeclContext(llvm::SmallVectorImpl< lldb_private::CompilerContext > &context) const
Return this DIE's decl context as it is needed to look up types in Clang's -gmodules debug info forma...
Definition: DWARFDIE.cpp:375
DWARFBaseDIE::GetModule
lldb::ModuleSP GetModule() const
Definition: DWARFBaseDIE.cpp:77
lldb_private::ClangASTImporter::RequireCompleteType
bool RequireCompleteType(clang::QualType type)
Definition: ClangASTImporter.cpp:684
DWARFBaseDIE::GetDWARF
SymbolFileDWARF * GetDWARF() const
Definition: DWARFBaseDIE.cpp:92
lldb_private::TypePayloadClang
The implementation of lldb::Type's m_payload field for TypeSystemClang.
Definition: TypeSystemClang.h:68
lldb_private::LanguageSet::Insert
void Insert(lldb::LanguageType language)
Definition: TypeSystem.cpp:33
lldb_private::Type::GetName
ConstString GetName()
Definition: Type.cpp:301
lldb_private::DWARFDataExtractor
Definition: DWARFDataExtractor.h:18
UniqueDWARFASTType.h
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
Language.h
lldb_private::UniqueCStringMap::Find
T Find(ConstString unique_cstr, T fail_value) const
Definition: UniqueCStringMap.h:86
DWARFDIE::ResolveType
lldb_private::Type * ResolveType() const
Definition: DWARFDIE.cpp:348
DWARFBaseDIE::GetCU
DWARFUnit * GetCU() const
Definition: DWARFBaseDIE.h:54
DWARFASTParserClang::ParseStructureLikeDIE
lldb::TypeSP ParseStructureLikeDIE(const lldb_private::SymbolContext &sc, const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs)
Parse a structure, class, or union type DIE.
Definition: DWARFASTParserClang.cpp:1561
DWARFASTParserClang::DelayedAddObjCClassProperty::m_property_opaque_type
CompilerType m_property_opaque_type
Definition: DWARFASTParserClang.cpp:1961
DWARFASTParserClang::DelayedAddObjCClassProperty::m_property_getter_name
const char * m_property_getter_name
Definition: DWARFASTParserClang.cpp:1963
ForcefullyCompleteType
static void ForcefullyCompleteType(CompilerType type)
Definition: DWARFASTParserClang.cpp:233
IsSubroutine
static bool IsSubroutine(const DWARFDIE &die)
Definition: DWARFASTParserClang.cpp:3367
lldb_private::SymbolContext
Definition: SymbolContext.h:33
DWARFDefines.h
DWARFDIE::ResolveTypeUID
lldb_private::Type * ResolveTypeUID(const DWARFDIE &die) const
Definition: DWARFDIE.cpp:355
lldb_private::TypeMap::GetSize
uint32_t GetSize() const
Definition: TypeMap.cpp:75
lldb_private::ObjCLanguage::MethodName::GetClassName
ConstString GetClassName()
Definition: ObjCLanguage.cpp:115
lldb_private::TypeSystemClang::CreateArrayType
CompilerType CreateArrayType(const CompilerType &element_type, size_t element_count, bool is_vector)
Definition: TypeSystemClang.cpp:2229
lldb_private::StreamString::GetString
llvm::StringRef GetString() const
Definition: StreamString.cpp:51
DWARFAttributes
Definition: DWARFAttribute.h:44
DWARFDIE::GetAttributeValueAsReferenceDIE
DWARFDIE GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const
Definition: DWARFDIE.cpp:130
DWARFDeclContext.h
lldb_private::UniqueCStringMap::IsEmpty
bool IsEmpty() const
Definition: UniqueCStringMap.h:151
ClangUtil.h
lldb_private::CompileUnit
Definition: CompileUnit.h:38
lldb_private::CompilerType::IsIntegerOrEnumerationType
bool IsIntegerOrEnumerationType(bool &is_signed) const
Definition: CompilerType.cpp:153
DWARFDIE
Definition: DWARFDIE.h:16
DWARFFormValue::Boolean
bool Boolean() const
Definition: DWARFFormValue.h:63
DWARFASTParserClang::GetClangDeclForDIE
clang::Decl * GetClangDeclForDIE(const DWARFDIE &die)
Definition: DWARFASTParserClang.cpp:3201
lldb_private::Type::GetByteSize
llvm::Optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope)
Definition: Type.cpp:339
lldb_private::Type::ResolveState
ResolveState
Definition: Type.h:90
DEBUG_PRINTF
#define DEBUG_PRINTF(fmt,...)
Definition: DWARFASTParserClang.cpp:55
lldb_private::UniqueCStringMap::GetValueAtIndexUnchecked
T GetValueAtIndexUnchecked(uint32_t idx) const
Definition: UniqueCStringMap.h:68
lldb_private::ClangASTImporter::LayoutInfo::base_offsets
OffsetMap base_offsets
Definition: ClangASTImporter.h:74
lldb::eEncodingInvalid
@ eEncodingInvalid
Definition: lldb-enumerations.h:147
SymbolFileDWARFDwo.h
DWARFASTParserClang::LinkDeclContextToDIE
void LinkDeclContextToDIE(clang::DeclContext *decl_ctx, const DWARFDIE &die)
Definition: DWARFASTParserClang.cpp:3530
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
DWARFASTParserClang::ParseChildParameters
size_t ParseChildParameters(clang::DeclContext *containing_decl_ctx, const DWARFDIE &parent_die, bool skip_artificial, bool &is_static, bool &is_variadic, bool &has_template_params, std::vector< lldb_private::CompilerType > &function_args, std::vector< clang::ParmVarDecl * > &function_param_decls, unsigned &type_quals)
Definition: DWARFASTParserClang.cpp:2965
lldb::eEncodingSint
@ eEncodingSint
signed integer
Definition: lldb-enumerations.h:149
DWARFASTParserClang::GetClangDeclContextContainingDIE
clang::DeclContext * GetClangDeclContextContainingDIE(const DWARFDIE &die, DWARFDIE *decl_ctx_die)
Definition: DWARFASTParserClang.cpp:3502
GetUnitName
static std::string GetUnitName(const DWARFDIE &die)
Definition: DWARFASTParserClang.cpp:431
lldb_private::Function
Definition: Function.h:413
SymbolFileDWARF::ForEachExternalModule
bool ForEachExternalModule(lldb_private::CompileUnit &, llvm::DenseSet< lldb_private::SymbolFile * > &, llvm::function_ref< bool(lldb_private::Module &)>) override
Definition: SymbolFileDWARF.cpp:937
DWARFUnit
Definition: DWARFUnit.h:81
LLDBAssert.h
DWARFASTParserClang::UpdateSymbolContextScopeForType
lldb::TypeSP UpdateSymbolContextScopeForType(const lldb_private::SymbolContext &sc, const DWARFDIE &die, lldb::TypeSP type_sp)
If type_sp is valid, calculate and set its symbol context scope, and update the type list for its bac...
Definition: DWARFASTParserClang.cpp:1526
lldb_private::ConstString::SetString
void SetString(const llvm::StringRef &s)
Definition: ConstString.cpp:306
DeclKindIsCXXClass
static bool DeclKindIsCXXClass(clang::Decl::Kind decl_kind)
Definition: DWARFASTParserClang.cpp:79
ClangASTMetadata.h
DWARFDIE::GetQualifiedName
const char * GetQualifiedName(std::string &storage) const
Definition: DWARFDIE.cpp:217
DWARFASTParserClang::GetClangDeclContextForDIE
clang::DeclContext * GetClangDeclContextForDIE(const DWARFDIE &die)
Definition: DWARFASTParserClang.cpp:3299
dwarf
Definition: ABISysV_arc.cpp:61
lldb_private::TypeSystemClang::GetAsCXXRecordDecl
static clang::CXXRecordDecl * GetAsCXXRecordDecl(lldb::opaque_compiler_type_t type)
Definition: TypeSystemClang.cpp:7209
DWARFASTParserClang::ParseFunctionFromDWARF
lldb_private::Function * ParseFunctionFromDWARF(lldb_private::CompileUnit &comp_unit, const DWARFDIE &die) override
Definition: DWARFASTParserClang.cpp:2345
lldb_private::DataExtractor
Definition: DataExtractor.h:48
lldb_private::ConstString::GetStringRef
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:202
ParsedDWARFTypeAttributes::storage
clang::StorageClass storage
Definition: DWARFASTParserClang.h:271
SymbolFileDWARFDebugMap::FindDefinitionTypeForDWARFDeclContext
lldb::TypeSP FindDefinitionTypeForDWARFDeclContext(const DWARFDeclContext &die_decl_ctx)
Definition: SymbolFileDWARFDebugMap.cpp:1086
Log.h
DWARFASTParserClang::DelayedAddObjCClassProperty::Finalize
bool Finalize()
Definition: DWARFASTParserClang.cpp:1951
ParsedDWARFTypeAttributes::is_inline
bool is_inline
Definition: DWARFASTParserClang.h:265
lldb_private::UniqueCStringMap::GetSize
size_t GetSize() const
Definition: UniqueCStringMap.h:148
lldb_private::ClangASTMetadata::SetObjectPtrName
void SetObjectPtrName(const char *name)
Definition: ClangASTMetadata.h:55
lldb_private::Declaration::SetColumn
void SetColumn(uint16_t column)
Set accessor for the declaration column number.
Definition: Declaration.h:177
lldb_private::TypeList::Insert
void Insert(const lldb::TypeSP &type)
Definition: TypeList.cpp:27
DWARFASTParserClang::FieldInfo::NextBitfieldOffsetIsValid
bool NextBitfieldOffsetIsValid(const uint64_t next_bit_offset) const
Definition: DWARFASTParserClang.h:183
lldb_private::Function::GetBlock
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition: Function.cpp:344
DWARFASTParserClang::m_die_to_module
DIEToModuleMap m_die_to_module
Definition: DWARFASTParserClang.h:90
DWARFASTParserClang::GetDeclContextContainingUIDFromDWARF
lldb_private::CompilerDeclContext GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) override
Definition: DWARFASTParserClang.cpp:2271
lldb_private::TypeMap::Empty
bool Empty() const
Definition: TypeMap.cpp:77
DWARFASTParserClang::CompleteRecordType
bool CompleteRecordType(const DWARFDIE &die, lldb_private::Type *type, lldb_private::CompilerType &clang_type)
Definition: DWARFASTParserClang.cpp:2101
lldb_private::TypeSystemClang::CreateEnumerationType
CompilerType CreateEnumerationType(const char *name, clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, const Declaration &decl, const CompilerType &integer_qual_type, bool is_scoped)
Definition: TypeSystemClang.cpp:2294
DWARFASTParserClang::ParseTypeFromDWARF
lldb::TypeSP ParseTypeFromDWARF(const lldb_private::SymbolContext &sc, const DWARFDIE &die, bool *type_is_new_ptr) override
Definition: DWARFASTParserClang.cpp:437
DWARFDeclContext::GetQualifiedName
const char * GetQualifiedName() const
Definition: DWARFDeclContext.cpp:11
ParsedDWARFTypeAttributes::accessibility
lldb::AccessType accessibility
Definition: DWARFASTParserClang.h:260
DWARFASTParserClang::FieldInfo::bit_offset
uint64_t bit_offset
Definition: DWARFASTParserClang.h:175
lldb::eAccessNone
@ eAccessNone
Definition: lldb-enumerations.h:508
lldb_private::TypeSystemClang::SetMetadata
void SetMetadata(const clang::Decl *object, ClangASTMetadata &meta_data)
Definition: TypeSystemClang.cpp:2544
lldb_private::TypeSystemClang::SetObjCSuperClass
static bool SetObjCSuperClass(const CompilerType &type, const CompilerType &superclass_compiler_type)
Definition: TypeSystemClang.cpp:7734
DWARFBaseDIE::GetTagAsCString
const char * GetTagAsCString() const
Definition: DWARFBaseDIE.cpp:36
DWARFASTParserClang::FieldInfo::SetIsBitfield
void SetIsBitfield(bool flag)
Definition: DWARFASTParserClang.h:180
DWARFDIE::GetName
void GetName(lldb_private::Stream &s) const
Definition: DWARFDIE.cpp:229
lldb_private::SymbolContext::function
Function * function
The Function for a given query.
Definition: SymbolContext.h:320
StreamString.h
SymbolFileDWARF::GetLanguageFamily
static lldb::LanguageType GetLanguageFamily(DWARFUnit &unit)
Same as GetLanguage() but reports all C++ versions as C++ (no version).
Definition: SymbolFileDWARF.cpp:4070
lldb_private::CompileUnit::AddFunction
void AddFunction(lldb::FunctionSP &function_sp)
Add a function to this compile unit.
Definition: CompileUnit.cpp:139
lldb::eBasicTypeInt
@ eBasicTypeInt
Definition: lldb-enumerations.h:754
lldb_private::DWARFExpression
Definition: DWARFExpression.h:35
DWARFDIE::GetMangledName
const char * GetMangledName() const
Definition: DWARFDIE.cpp:203
lldb_private::DataExtractor::GetDataStart
const uint8_t * GetDataStart() const
Get the data start pointer.
Definition: DataExtractor.h:422
lldb_private::ConstString
Definition: ConstString.h:40
SymbolFileDWARFDebugMap
Definition: SymbolFileDWARFDebugMap.h:25
GetContainingClangModule
static lldb::ModuleSP GetContainingClangModule(const DWARFDIE &die)
Definition: DWARFASTParserClang.cpp:130
lldb_private::TypeSystemClang::GetTypeForDecl
CompilerType GetTypeForDecl(clang::NamedDecl *decl)
Definition: TypeSystemClang.cpp:1210
lldb_private::ObjectFile::GetByteOrder
virtual lldb::ByteOrder GetByteOrder() const =0
Gets whether endian swapping should occur when extracting data from this object file.
lldb_private::StreamString
Definition: StreamString.h:23
lldb_private::AddressRange
Definition: AddressRange.h:25
ParsedDWARFTypeAttributes::abstract_origin
DWARFFormValue abstract_origin
Definition: DWARFASTParserClang.h:276
lldb_private::Scalar::UInt
unsigned int UInt(unsigned int fail_value=0) const
Definition: Scalar.cpp:320
SymbolFileDWARF::GetDWARFDeclContext
static DWARFDeclContext GetDWARFDeclContext(const DWARFDIE &die)
Definition: SymbolFileDWARF.cpp:4044
ObjCLanguage.h
DWARFUnit::Supports_unnamed_objc_bitfields
bool Supports_unnamed_objc_bitfields()
Definition: DWARFUnit.cpp:656
DWARFFormValue
Definition: DWARFFormValue.h:20
SymbolFileDWARF::GetDIEToType
virtual DIEToTypePtr & GetDIEToType()
Definition: SymbolFileDWARF.h:481
lldb_private::ClangASTMetadata::SetIsDynamicCXXType
void SetIsDynamicCXXType(bool b)
Definition: ClangASTMetadata.h:27
GetContainingClangModuleDIE
static DWARFDIE GetContainingClangModuleDIE(const DWARFDIE &die)
Definition: DWARFASTParserClang.cpp:111
lldb_private::Declaration::SetFile
void SetFile(const FileSpec &file_spec)
Set accessor for the declaration file specification.
Definition: Declaration.h:163
DWARFFormValue::Clear
void Clear()
Definition: DWARFFormValue.cpp:24
DWARFASTParserClang::DelayedAddObjCClassProperty::m_class_opaque_type
CompilerType m_class_opaque_type
Definition: DWARFASTParserClang.cpp:1959
lldb::eBasicTypeVoid
@ eBasicTypeVoid
Definition: lldb-enumerations.h:743
DWARFASTParserClang::ParseInheritance
void ParseInheritance(const DWARFDIE &die, const DWARFDIE &parent_die, const lldb_private::CompilerType class_clang_type, const lldb::AccessType default_accessibility, const lldb::ModuleSP &module_sp, std::vector< std::unique_ptr< clang::CXXBaseSpecifier >> &base_classes, lldb_private::ClangASTImporter::LayoutInfo &layout_info)
Parses a DW_TAG_inheritance DIE into a base/super class.
Definition: DWARFASTParserClang.cpp:1409
DWARFDIE::GetReferencedDIE
DWARFDIE GetReferencedDIE(const dw_attr_t attr) const
Definition: DWARFDIE.cpp:114
lldb_private::TypeSystemClang::CreateClassTemplateSpecializationType
CompilerType CreateClassTemplateSpecializationType(clang::ClassTemplateSpecializationDecl *class_template_specialization_decl)
Definition: TypeSystemClang.cpp:1683
DWARFASTParserClang::m_die_to_decl_ctx
DIEToDeclContextMap m_die_to_decl_ctx
Definition: DWARFASTParserClang.h:88
lldb_private::TypeSystemClang::GetUniqueNamespaceDeclaration
clang::NamespaceDecl * GetUniqueNamespaceDeclaration(const char *name, clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, bool is_inline=false)
Definition: TypeSystemClang.cpp:1843
lldb_private::CompilerType::IsIntegerType
bool IsIntegerType(bool &is_signed) const
Definition: CompilerType.cpp:141
DWARFBaseDIE::GetAttributeValueAsString
const char * GetAttributeValueAsString(const dw_attr_t attr, const char *fail_value) const
Definition: DWARFBaseDIE.cpp:40
FindAnyChildWithAbstractOrigin
static DWARFDIE FindAnyChildWithAbstractOrigin(const DWARFDIE &context)
Definition: DWARFASTParserClang.cpp:3392
lldb::eLanguageTypeObjC
@ eLanguageTypeObjC
Objective-C.
Definition: lldb-enumerations.h:453
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
DWARFDIE::GetFirstChild
DWARFDIE GetFirstChild() const
Definition: DWARFDIE.cpp:98
DWARFDebugInfo.h
lldb_private::RangeVector::GetMaxRangeEnd
BaseType GetMaxRangeEnd(BaseType fail_value) const
Definition: RangeMap.h:229
lldb_private::TypeSystemClang::TemplateParameterInfos::pack_name
const char * pack_name
Definition: TypeSystemClang.h:336
SymbolFileDWARF::GetExternalModule
lldb::ModuleSP GetExternalModule(lldb_private::ConstString name)
Definition: SymbolFileDWARF.cpp:1653
lldb_private::TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize
CompilerType GetBuiltinTypeForDWARFEncodingAndBitSize(llvm::StringRef type_name, uint32_t dw_ate, uint32_t bit_size)
Definition: TypeSystemClang.cpp:945
lldb_private::ClangASTMetadata
Definition: ClangASTMetadata.h:18
ParsedDWARFTypeAttributes::is_explicit
bool is_explicit
Definition: DWARFASTParserClang.h:263
lldb::eBasicTypeObjCClass
@ eBasicTypeObjCClass
Definition: lldb-enumerations.h:771
lldb::eLanguageTypeObjC_plus_plus
@ eLanguageTypeObjC_plus_plus
Objective-C++.
Definition: lldb-enumerations.h:454
DWARFAttributes::ExtractFormValueAtIndex
bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const
Definition: DWARFAttribute.cpp:36
lldb_private::RangeVector
Definition: RangeMap.h:125
ParsedDWARFTypeAttributes::is_objc_direct_call
bool is_objc_direct_call
Definition: DWARFASTParserClang.h:269
lldb_private::ObjCLanguage::MethodName
Definition: ObjCLanguage.h:26
lldb_private::TypeSystemClang::GetOrCreateClangModule
OptionalClangModuleID GetOrCreateClangModule(llvm::StringRef name, OptionalClangModuleID parent, bool is_framework=false, bool is_explicit=false)
Synthesize a clang::Module and return its ID or a default-constructed ID.
Definition: TypeSystemClang.cpp:1240
DWARFFormValue::Unsigned
uint64_t Unsigned() const
Definition: DWARFFormValue.h:64
ParsedDWARFTypeAttributes::bit_stride
uint32_t bit_stride
Definition: DWARFASTParserClang.h:284
lldb_private::UniqueCStringMap
Definition: UniqueCStringMap.h:26
lldb_private::TypeMap
Definition: TypeMap.h:20
SymbolFileDWARF::GetDWARFParser
static DWARFASTParser * GetDWARFParser(DWARFUnit &unit)
Definition: SymbolFileDWARF.cpp:4015
DWARFDIE::GetDIENamesAndRanges
bool GetDIENamesAndRanges(const char *&name, const char *&mangled, DWARFRangeList &ranges, int &decl_file, int &decl_line, int &decl_column, int &call_file, int &call_line, int &call_column, lldb_private::DWARFExpression *frame_base) const
Definition: DWARFDIE.cpp:439
DWARFFormValue::Signed
int64_t Signed() const
Definition: DWARFFormValue.h:66
lldb_private::CompilerDeclContext
Represents a generic declaration context in a program.
Definition: CompilerDeclContext.h:30
DWARFASTParserClang::FieldInfo
Definition: DWARFASTParserClang.h:173
lldb_private::SymbolContextScope
Definition: SymbolContextScope.h:64
ObjectFile.h
DWARFASTParserClang::GetClangASTImporter
lldb_private::ClangASTImporter & GetClangASTImporter()
Definition: DWARFASTParserClang.cpp:91
lldb_private::UserID::GetID
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47
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:235
lldb_private::Type::GetEncodingMask
uint32_t GetEncodingMask()
Definition: Type.cpp:637
lldb_private::TypeSystemClang::AddMethodOverridesForCXXRecordType
void AddMethodOverridesForCXXRecordType(lldb::opaque_compiler_type_t type)
Definition: TypeSystemClang.cpp:7692
lldb_private::CompilerType::GetCompleteType
bool GetCompleteType() const
Type Completion.
Definition: CompilerType.cpp:264
lldb_private::ClangASTImporter::SetRecordLayout
void SetRecordLayout(clang::RecordDecl *decl, const LayoutInfo &layout)
Sets the layout for the given RecordDecl.
Definition: ClangASTImporter.cpp:548
lldb_private::Value::ResolveValue
Scalar & ResolveValue(ExecutionContext *exe_ctx)
Definition: Value.cpp:563
lldb_private::TypeSystemClang::SetFunctionParameters
void SetFunctionParameters(clang::FunctionDecl *function_decl, llvm::ArrayRef< clang::ParmVarDecl * > params)
Definition: TypeSystemClang.cpp:2213
lldb_private::ClangASTImporter::LayoutInfo::vbase_offsets
OffsetMap vbase_offsets
Definition: ClangASTImporter.h:75
lldb_private::Declaration::Clear
void Clear()
Clear the object's state.
Definition: Declaration.h:57
lldb::eAccessPublic
@ eAccessPublic
Definition: lldb-enumerations.h:509
SymbolFileDWARF::ResolveType
lldb_private::Type * ResolveType(const DWARFDIE &die, bool assert_not_being_parsed=true, bool resolve_function_context=false)
Definition: SymbolFileDWARF.cpp:1589
lldb::eBasicTypeObjCID
@ eBasicTypeObjCID
Definition: lldb-enumerations.h:770
TypeList.h
ParsedDWARFTypeAttributes::calling_convention
size_t calling_convention
Definition: DWARFASTParserClang.h:283
DWARFASTParserClang::DelayedAddObjCClassProperty::operator=
DelayedAddObjCClassProperty & operator=(const DelayedAddObjCClassProperty &rhs)
Definition: DWARFASTParserClang.cpp:1936
lldb_private::UniqueCStringMap::GetCStringAtIndex
ConstString GetCStringAtIndex(uint32_t idx) const
Definition: UniqueCStringMap.h:76
DWARFASTParserClang::FieldInfo::IsBitfield
bool IsBitfield()
Definition: DWARFASTParserClang.h:181
lldbassert
#define lldbassert(x)
Definition: LLDBAssert.h:15
ParsedDWARFTypeAttributes::encoding
uint32_t encoding
Definition: DWARFASTParserClang.h:286
DWARFASTParserClang::~DWARFASTParserClang
~DWARFASTParserClang() override
DWARFASTParserClang
Definition: DWARFASTParserClang.h:37
ParsedDWARFTypeAttributes::is_complete_objc_class
bool is_complete_objc_class
Definition: DWARFASTParserClang.h:262
SymbolFileDWARF::GetDecl
static lldb_private::CompilerDecl GetDecl(const DWARFDIE &die)
Definition: SymbolFileDWARF.cpp:4025
DWARFBaseDIE::GetAttributeValueAsUnsigned
uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr, uint64_t fail_value) const
Definition: DWARFBaseDIE.cpp:48
lldb_private::TypeSystemClang::ParseClassTemplateDecl
clang::ClassTemplateDecl * ParseClassTemplateDecl(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, lldb::AccessType access_type, const char *parent_name, int tag_decl_kind, const TypeSystemClang::TemplateParameterInfos &template_param_infos)
Definition: TypeSystemClang.cpp:9208
lldb_private::Status
Definition: Status.h:44
lldb_private::UniqueCStringMap::Append
void Append(ConstString unique_cstr, const T &value)
Definition: UniqueCStringMap.h:42
SymbolFileDWARF::GetLanguage
static lldb::LanguageType GetLanguage(DWARFUnit &unit)
Definition: SymbolFileDWARF.cpp:4066
lldb_private::OptionalClangModuleID
A Clang module ID.
Definition: TypeSystemClang.h:57
ConvertDWARFCallingConventionToClang
static clang::CallingConv ConvertDWARFCallingConventionToClang(const ParsedDWARFTypeAttributes &attrs)
Definition: DWARFASTParserClang.cpp:880
uint32_t
DWARFASTParserClang::FieldInfo::bit_size
uint64_t bit_size
Definition: DWARFASTParserClang.h:174
DWARFASTParserClang::ParseTypeModifier
lldb::TypeSP ParseTypeModifier(const lldb_private::SymbolContext &sc, const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs)
Definition: DWARFASTParserClang.cpp:548
lldb::eAccessPrivate
@ eAccessPrivate
Definition: lldb-enumerations.h:510
DWARFFormValue::BlockData
const uint8_t * BlockData() const
Definition: DWARFFormValue.cpp:566
lldb_private::CompilerType::SetCompilerType
void SetCompilerType(TypeSystem *type_system, lldb::opaque_compiler_type_t type)
Definition: CompilerType.cpp:312
lldb_private::TypeSystemClang::GetEnumerationIntegerType
CompilerType GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) override
Definition: TypeSystemClang.cpp:4258
lldb_private::ExecutionContext::GetFrameSP
const lldb::StackFrameSP & GetFrameSP() const
Get accessor to get the frame shared pointer.
Definition: ExecutionContext.h:469
ParsedDWARFTypeAttributes::mangled_name
const char * mangled_name
Definition: DWARFASTParserClang.h:272
DWARFASTParserClang.h
DWARFASTParserClang::GetDeclContextForUIDFromDWARF
lldb_private::CompilerDeclContext GetDeclContextForUIDFromDWARF(const DWARFDIE &die) override
Definition: DWARFASTParserClang.cpp:2263
id
void * id
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:20
SymbolFileDWARF::GetDeclContext
static lldb_private::CompilerDeclContext GetDeclContext(const DWARFDIE &die)
Definition: SymbolFileDWARF.cpp:4031
ParsedDWARFTypeAttributes::byte_size
llvm::Optional< uint64_t > byte_size
Definition: DWARFASTParserClang.h:282
lldb_private::TypeSystemClang::CreateVariableDeclaration
clang::VarDecl * CreateVariableDeclaration(clang::DeclContext *decl_context, OptionalClangModuleID owning_module, const char *name, clang::QualType type)
Definition: TypeSystemClang.cpp:1975
DWARFASTParserClang::m_die_to_decl
DIEToDeclMap m_die_to_decl
Definition: DWARFASTParserClang.h:87
lldb_private::CompilerType::GetTypeSystem
TypeSystem * GetTypeSystem() const
Accessors.
Definition: CompilerType.h:162
lldb_private::CompilerType::GetBitSize
llvm::Optional< uint64_t > GetBitSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bits.
Definition: CompilerType.cpp:482
DWARFASTParserClang::EnsureAllDIEsInDeclContextHaveBeenParsed
void EnsureAllDIEsInDeclContextHaveBeenParsed(lldb_private::CompilerDeclContext decl_context) override
Definition: DWARFASTParserClang.cpp:2244
lldb_private::CompilerType::GetTypeName
ConstString GetTypeName() const
Definition: CompilerType.cpp:277
lldb_private::Type
Definition: Type.h:66
DWARFASTParserClang::CompleteTypeFromDWARF
bool CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type, lldb_private::CompilerType &compiler_type) override
Definition: DWARFASTParserClang.cpp:2204
RequireCompleteType
static void RequireCompleteType(CompilerType type)
Complete a type from debug info, or mark it as forcefully completed if there is no definition of the ...
Definition: DWARFASTParserClang.cpp:246
DWARFBaseDIE::GetOffset
dw_offset_t GetOffset() const
Definition: DWARFBaseDIE.cpp:85
DWARFASTParserClang::m_ast
lldb_private::TypeSystemClang & m_ast
Definition: DWARFASTParserClang.h:86
lldb_private::CompilerType::IsArrayType
bool IsArrayType(CompilerType *element_type=nullptr, uint64_t *size=nullptr, bool *is_incomplete=nullptr) const
Definition: CompilerType.cpp:49
lldb_private::Address::ResolveAddressUsingFileSections
bool ResolveAddressUsingFileSections(lldb::addr_t addr, const SectionList *sections)
Resolve a file virtual address using a section list.
Definition: Address.cpp:247
DWARFDIE::GetDIE
DWARFDIE GetDIE(dw_offset_t die_offset) const
Definition: DWARFDIE.cpp:122
lldb_private::TypeSystemClang::CreateFunctionTemplateDecl
clang::FunctionTemplateDecl * CreateFunctionTemplateDecl(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, clang::FunctionDecl *func_decl, const TemplateParameterInfos &infos)
Definition: TypeSystemClang.cpp:1416
lldb_private::Type::GetForwardCompilerType
CompilerType GetForwardCompilerType()
Definition: Type.cpp:656
DWARFASTParserClang::ParseEnum
lldb::TypeSP ParseEnum(const lldb_private::SymbolContext &sc, const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs)
Definition: DWARFASTParserClang.cpp:771
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
DWARFASTParserClang::ParseObjCProperty
void ParseObjCProperty(const DWARFDIE &die, const DWARFDIE &parent_die, const lldb_private::CompilerType &class_clang_type, DelayedPropertyList &delayed_properties)
Parses a DW_TAG_APPLE_property DIE and appends the parsed data to the list of delayed Objective-C pro...
Definition: DWARFASTParserClang.cpp:2639
DWARFASTParserClang::ParseArrayType
lldb::TypeSP ParseArrayType(const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs)
Definition: DWARFASTParserClang.cpp:1333
lldb_private::ModuleChild::GetModule
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
Definition: ModuleChild.cpp:24
lldb_private::SymbolContext::module_sp
lldb::ModuleSP module_sp
The Module for a given query.
Definition: SymbolContext.h:318
uint16_t
lldb::eBasicTypeNullPtr
@ eBasicTypeNullPtr
Definition: lldb-enumerations.h:773
DWARFBaseDIE::GetID
lldb::user_id_t GetID() const
Definition: DWARFBaseDIE.cpp:64
lldb_private::ClangASTImporter
Manages and observes all Clang AST node importing in LLDB.
Definition: ClangASTImporter.h:64
lldb_private::AddressRange::SetByteSize
void SetByteSize(lldb::addr_t byte_size)
Set accessor for the byte size of this range.
Definition: AddressRange.h:237
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
lldb_private::ConstString::GetCString
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:242
DWARFFormValue::AsCString
const char * AsCString() const
Definition: DWARFFormValue.cpp:458
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:1274
DWARFAttributes::AttributeAtIndex
dw_attr_t AttributeAtIndex(uint32_t i) const
Definition: DWARFAttribute.h:55
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
Function.h
lldb_private::SymbolFile::ArrayInfo::element_orders
llvm::SmallVector< uint64_t, 1 > element_orders
Definition: SymbolFile.h:187
ParsedDWARFTypeAttributes::specification
DWARFFormValue specification
Definition: DWARFASTParserClang.h:279
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
ParsedDWARFTypeAttributes::decl
lldb_private::Declaration decl
Definition: DWARFASTParserClang.h:274
DWARFASTParserClang::ResolveBlockDIE
clang::BlockDecl * ResolveBlockDIE(const DWARFDIE &die)
Definition: DWARFASTParserClang.cpp:3429
lldb_private::TypeSystemClang::TemplateParameterInfos::args
llvm::SmallVector< clang::TemplateArgument, 2 > args
Definition: TypeSystemClang.h:334
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
ParsedDWARFTypeAttributes::containing_type
DWARFFormValue containing_type
Definition: DWARFASTParserClang.h:277
DWARFDeclContext
Definition: DWARFDeclContext.h:23
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
DWARFDIE::children
llvm::iterator_range< child_iterator > children() const
The range of all the children of this DIE.
Definition: DWARFDIE.cpp:452
PrepareContextToReceiveMembers
static void PrepareContextToReceiveMembers(TypeSystemClang &ast, ClangASTImporter &ast_importer, clang::DeclContext *decl_ctx, DWARFDIE die, const char *type_name_cstr)
This function serves a similar purpose as RequireCompleteType above, but it avoids completing the typ...
Definition: DWARFASTParserClang.cpp:267
DWARFASTParserClang::ParseSubroutine
lldb::TypeSP ParseSubroutine(const DWARFDIE &die, ParsedDWARFTypeAttributes &attrs)
Definition: DWARFASTParserClang.cpp:910
lldb_private::Block::FindBlockByID
Block * FindBlockByID(lldb::user_id_t block_id)
Definition: Block.cpp:111
GetContainingFunctionWithAbstractOrigin
static DWARFDIE GetContainingFunctionWithAbstractOrigin(const DWARFDIE &die)
Definition: DWARFASTParserClang.cpp:3377
lldb_private::TypeList
Definition: TypeList.h:20
lldb_private::ObjCLanguage::MethodName::IsValid
bool IsValid(bool strict) const
Definition: ObjCLanguage.h:45
lldb_private::TypeSystemClang::GetBasicType
CompilerType GetBasicType(lldb::BasicType type)
Definition: TypeSystemClang.cpp:934
lldb_private::SymbolFile::ArrayInfo
The characteristics of an array type.
Definition: SymbolFile.h:185
DWARFASTParserClang::DelayedAddObjCClassProperty::DelayedAddObjCClassProperty
DelayedAddObjCClassProperty(const DelayedAddObjCClassProperty &rhs)
Definition: DWARFASTParserClang.cpp:1931
lldb_private::TypeSystemClang::CreateUsingDirectiveDeclaration
clang::UsingDirectiveDecl * CreateUsingDirectiveDeclaration(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, clang::NamespaceDecl *ns_decl)
Definition: TypeSystemClang.cpp:1937
lldb_private::TypeSystemClang
A TypeSystem implementation based on Clang.
Definition: TypeSystemClang.h:106
lldb_private::CompilerType::IsBeingDefined
bool IsBeingDefined() const
Definition: CompilerType.cpp:256
DWARFASTParserClang::ParseTemplateDIE
bool ParseTemplateDIE(const DWARFDIE &die, lldb_private::TypeSystemClang::TemplateParameterInfos &template_param_infos)
Definition: DWARFASTParserClang.cpp:1968
DWARFDIE::GetSibling
DWARFDIE GetSibling() const
Definition: DWARFDIE.cpp:106
DWARF_LOG_TYPE_COMPLETION
#define DWARF_LOG_TYPE_COMPLETION
Definition: LogChannelDWARF.h:17
ClangASTImporter.h
lldb_private::TypeSystemClang::AddEnumerationValueToEnumerationType
clang::EnumConstantDecl * AddEnumerationValueToEnumerationType(const CompilerType &enum_type, const Declaration &decl, const char *name, int64_t enum_value, uint32_t enum_value_bit_size)
Definition: TypeSystemClang.cpp:8309
lldb_private::LanguageSet
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
Definition: TypeSystem.h:40
ParsedDWARFTypeAttributes::is_scoped_enum
bool is_scoped_enum
Definition: DWARFASTParserClang.h:266
DWARFASTParserClang::GetOwningClangModule
lldb_private::OptionalClangModuleID GetOwningClangModule(const DWARFDIE &die)
Definition: DWARFASTParserClang.cpp:3342
DWARFASTParserClang::ParseTypeFromClangModule
lldb::TypeSP ParseTypeFromClangModule(const lldb_private::SymbolContext &sc, const DWARFDIE &die, lldb_private::Log *log)
Follow Clang Module Skeleton CU references to find a type definition.
Definition: DWARFASTParserClang.cpp:144
lldb_private::TypeSystemClang::SetHasExternalStorage
static bool SetHasExternalStorage(lldb::opaque_compiler_type_t type, bool has_extern)
Definition: TypeSystemClang.cpp:8104
lldb_private::TypeSystemClang::TemplateParameterInfos
Definition: TypeSystemClang.h:320
lldb::eBasicTypeObjCSel
@ eBasicTypeObjCSel
Definition: lldb-enumerations.h:772
lldb_private::Log
Definition: Log.h:49
DWARFASTParserClang::GetDeclContextForBlock
clang::DeclContext * GetDeclContextForBlock(const DWARFDIE &die)
Definition: DWARFASTParserClang.cpp:3415
DWARFUnit::GetSymbolFileDWARF
SymbolFileDWARF & GetSymbolFileDWARF() const
Definition: DWARFUnit.h:195
DWARFASTParserClang::ParseSingleMember
void ParseSingleMember(const DWARFDIE &die, const DWARFDIE &parent_die, const lldb_private::CompilerType &class_clang_type, lldb::AccessType default_accessibility, lldb_private::ClangASTImporter::LayoutInfo &layout_info, FieldInfo &last_field_info)
Definition: DWARFASTParserClang.cpp:2675
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:7501
DWARFASTParserClang::DelayedAddObjCClassProperty::m_property_name
const char * m_property_name
Definition: DWARFASTParserClang.cpp:1960
ParsedDWARFTypeAttributes::is_artificial
bool is_artificial
Definition: DWARFASTParserClang.h:261
ParsedDWARFTypeAttributes::object_pointer
DWARFDIE object_pointer
Definition: DWARFASTParserClang.h:275
DWARFASTParserClang::m_decl_ctx_to_die
DeclContextToDIEMap m_decl_ctx_to_die
Definition: DWARFASTParserClang.h:89
lldb_private::TypeSystemClang::AddMethodToObjCObjectType
static clang::ObjCMethodDecl * AddMethodToObjCObjectType(const CompilerType &type, const char *name, const CompilerType &method_compiler_type, lldb::AccessType access, bool is_artificial, bool is_variadic, bool is_objc_direct_call)
Definition: TypeSystemClang.cpp:7970
lldb_private::TypeSystemClang::GetDeclContextForType
static clang::DeclContext * GetDeclContextForType(clang::QualType type)
Definition: TypeSystemClang.cpp:2606
lldb_private::ClangASTImporter::CanImport
bool CanImport(const CompilerType &type)
Returns true iff the given type was copied from another TypeSystemClang and the original type in this...
Definition: ClangASTImporter.cpp:358
DWARFASTParserClang::DWARFASTParserClang
DWARFASTParserClang(lldb_private::TypeSystemClang &ast)
Definition: DWARFASTParserClang.cpp:60
ParsedDWARFTypeAttributes::ParsedDWARFTypeAttributes
ParsedDWARFTypeAttributes(const DWARFDIE &die)
Definition: DWARFASTParserClang.cpp:302
lldb_private::Declaration
Definition: Declaration.h:24
DWARFAttributes::CompileUnitAtIndex
DWARFUnit * CompileUnitAtIndex(uint32_t i) const
Definition: DWARFAttribute.h:51
lldb_private::DWARFExpression::IsValid
bool IsValid() const
Return true if the location expression contains data.
Definition: DWARFExpression.cpp:72
lldb::eByteOrderLittle
@ eByteOrderLittle
Definition: lldb-enumerations.h:142
DW_ACCESS_to_AccessType
static AccessType DW_ACCESS_to_AccessType(uint32_t dwarf_accessibility)
Definition: DWARFASTParserClang.cpp:65
lldb_private::TypeSystemClang::CreateUsingDeclaration
clang::UsingDecl * CreateUsingDeclaration(clang::DeclContext *current_decl_ctx, OptionalClangModuleID owning_module, clang::NamedDecl *target)
Definition: TypeSystemClang.cpp:1956
ParsedDWARFTypeAttributes::exports_symbols
bool exports_symbols
Definition: DWARFASTParserClang.h:270
lldb_private::TypeSystemClang::CreateClassTemplateSpecializationDecl
clang::ClassTemplateSpecializationDecl * CreateClassTemplateSpecializationDecl(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, clang::ClassTemplateDecl *class_template_decl, int kind, const TemplateParameterInfos &infos)
Definition: TypeSystemClang.cpp:1649
lldb_private::SymbolFile::ArrayInfo::bit_stride
uint32_t bit_stride
Definition: SymbolFile.h:189
lldb
Definition: SBAddress.h:15
DWARFBaseDIE::Tag
dw_tag_t Tag() const
Definition: DWARFBaseDIE.cpp:29
Value.h
lldb_private::TypeSystemClang::CreateFunctionTemplateSpecializationInfo
void CreateFunctionTemplateSpecializationInfo(clang::FunctionDecl *func_decl, clang::FunctionTemplateDecl *Template, const TemplateParameterInfos &infos)
Definition: TypeSystemClang.cpp:1448
lldb_private::Type::GetFullCompilerType
CompilerType GetFullCompilerType()
Definition: Type.cpp:646
lldb_private::TypeSystemClang::SetMetadataAsUserID
void SetMetadataAsUserID(const clang::Decl *decl, lldb::user_id_t user_id)
Definition: TypeSystemClang.cpp:2530
DWARFASTParserClang::CompleteEnumType
bool CompleteEnumType(const DWARFDIE &die, lldb_private::Type *type, lldb_private::CompilerType &clang_type)
Definition: DWARFASTParserClang.cpp:2189
lldb::AccessType
AccessType
Definition: lldb-enumerations.h:507
SymbolFile.h
DWARFASTParserClang::ParsePointerToMemberType
lldb::TypeSP ParsePointerToMemberType(const DWARFDIE &die, const ParsedDWARFTypeAttributes &attrs)
Definition: DWARFASTParserClang.cpp:1386
DWARFASTParserClang::ParseChildEnumerators
size_t ParseChildEnumerators(lldb_private::CompilerType &compiler_type, bool is_signed, uint32_t enumerator_byte_size, const DWARFDIE &parent_die)
Definition: DWARFASTParserClang.cpp:2279
DWARFBaseDIE::HasChildren
bool HasChildren() const
Definition: DWARFBaseDIE.cpp:99
lldb_private::TypeSystemClang::CreateBaseClassSpecifier
std::unique_ptr< clang::CXXBaseSpecifier > CreateBaseClassSpecifier(lldb::opaque_compiler_type_t type, lldb::AccessType access, bool is_virtual, bool base_of_class)
Definition: TypeSystemClang.cpp:7702
lldb_private::ObjectFile
Definition: ObjectFile.h:58
lldb_private::ClangASTImporter::LayoutInfo::bit_size
uint64_t bit_size
Definition: ClangASTImporter.h:71
DWARFASTParserClang::m_clang_ast_importer_up
std::unique_ptr< lldb_private::ClangASTImporter > m_clang_ast_importer_up
Definition: DWARFASTParserClang.h:91
ParsedDWARFTypeAttributes::is_virtual
bool is_virtual
Definition: DWARFASTParserClang.h:268
DWARFFormValue::IsValid
bool IsValid() const
Definition: DWARFFormValue.h:70
UINT64_MAX
#define UINT64_MAX
Definition: lldb-defines.h:35
DWARFUnit::GetFile
lldb_private::FileSpec GetFile(size_t file_idx)
Definition: DWARFUnit.cpp:754
lldb_private::TypeSystemClang::TemplateParameterInfos::names
llvm::SmallVector< const char *, 2 > names
Definition: TypeSystemClang.h:333
DWARFBaseDIE::IsValid
bool IsValid() const
Definition: DWARFBaseDIE.h:45
lldb_private::TypeSystemClang::TemplateParameterInfos::packed_args
std::unique_ptr< TemplateParameterInfos > packed_args
Definition: TypeSystemClang.h:337