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