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