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