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