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 ParseChildParameters(containing_decl_ctx, die, is_static, is_variadic,
1226 has_template_params, function_param_types,
1227 function_param_decls, type_quals);
1228 }
1229
1230 bool ignore_containing_context = false;
1231 // Check for templatized class member functions. If we had any
1232 // DW_TAG_template_type_parameter or DW_TAG_template_value_parameter
1233 // the DW_TAG_subprogram DIE, then we can't let this become a method in
1234 // a class. Why? Because templatized functions are only emitted if one
1235 // of the templatized methods is used in the current compile unit and
1236 // we will end up with classes that may or may not include these member
1237 // functions and this means one class won't match another class
1238 // definition and it affects our ability to use a class in the clang
1239 // expression parser. So for the greater good, we currently must not
1240 // allow any template member functions in a class definition.
1241 if (is_cxx_method && has_template_params) {
1242 ignore_containing_context = true;
1243 is_cxx_method = false;
1244 }
1245
1246 clang::CallingConv calling_convention =
1248
1249 // clang_type will get the function prototype clang type after this
1250 // call
1251 CompilerType clang_type =
1252 m_ast.CreateFunctionType(return_clang_type, function_param_types.data(),
1253 function_param_types.size(), is_variadic,
1254 type_quals, calling_convention, attrs.ref_qual);
1255
1256 if (attrs.name) {
1257 bool type_handled = false;
1258 if (tag == DW_TAG_subprogram || tag == DW_TAG_inlined_subroutine) {
1259 if (std::optional<const ObjCLanguage::MethodName> objc_method =
1261 true)) {
1262 type_handled =
1263 ParseObjCMethod(*objc_method, die, clang_type, attrs, is_variadic);
1264 } else if (is_cxx_method) {
1265 auto [handled, type_sp] =
1266 ParseCXXMethod(die, clang_type, attrs, decl_ctx_die, is_static,
1267 ignore_containing_context);
1268 if (type_sp)
1269 return type_sp;
1270
1271 type_handled = handled;
1272 }
1273 }
1274
1275 if (!type_handled) {
1276 clang::FunctionDecl *function_decl = nullptr;
1277 clang::FunctionDecl *template_function_decl = nullptr;
1278
1279 if (attrs.abstract_origin.IsValid()) {
1280 DWARFDIE abs_die = attrs.abstract_origin.Reference();
1281
1282 if (dwarf->ResolveType(abs_die)) {
1283 function_decl = llvm::dyn_cast_or_null<clang::FunctionDecl>(
1285
1286 if (function_decl) {
1287 LinkDeclContextToDIE(function_decl, die);
1288 }
1289 }
1290 }
1291
1292 if (!function_decl) {
1293 char *name_buf = nullptr;
1294 llvm::StringRef name = attrs.name.GetStringRef();
1295
1296 // We currently generate function templates with template parameters in
1297 // their name. In order to get closer to the AST that clang generates
1298 // we want to strip these from the name when creating the AST.
1299 if (attrs.mangled_name) {
1300 llvm::ItaniumPartialDemangler D;
1301 if (!D.partialDemangle(attrs.mangled_name)) {
1302 name_buf = D.getFunctionBaseName(nullptr, nullptr);
1303 name = name_buf;
1304 }
1305 }
1306
1307 // We just have a function that isn't part of a class
1308 function_decl = m_ast.CreateFunctionDeclaration(
1309 ignore_containing_context ? m_ast.GetTranslationUnitDecl()
1310 : containing_decl_ctx,
1311 GetOwningClangModule(die), name, clang_type, attrs.storage,
1312 attrs.is_inline);
1313 std::free(name_buf);
1314
1315 if (has_template_params) {
1316 TypeSystemClang::TemplateParameterInfos template_param_infos;
1317 ParseTemplateParameterInfos(die, template_param_infos);
1318 template_function_decl = m_ast.CreateFunctionDeclaration(
1319 ignore_containing_context ? m_ast.GetTranslationUnitDecl()
1320 : containing_decl_ctx,
1321 GetOwningClangModule(die), attrs.name.GetStringRef(), clang_type,
1322 attrs.storage, attrs.is_inline);
1323 clang::FunctionTemplateDecl *func_template_decl =
1325 containing_decl_ctx, GetOwningClangModule(die),
1326 template_function_decl, template_param_infos);
1328 template_function_decl, func_template_decl, template_param_infos);
1329 }
1330
1331 lldbassert(function_decl);
1332
1333 if (function_decl) {
1334 // Attach an asm(<mangled_name>) label to the FunctionDecl.
1335 // This ensures that clang::CodeGen emits function calls
1336 // using symbols that are mangled according to the DW_AT_linkage_name.
1337 // If we didn't do this, the external symbols wouldn't exactly
1338 // match the mangled name LLDB knows about and the IRExecutionUnit
1339 // would have to fall back to searching object files for
1340 // approximately matching function names. The motivating
1341 // example is generating calls to ABI-tagged template functions.
1342 // This is done separately for member functions in
1343 // AddMethodToCXXRecordType.
1344 if (attrs.mangled_name)
1345 function_decl->addAttr(clang::AsmLabelAttr::CreateImplicit(
1346 m_ast.getASTContext(), attrs.mangled_name, /*literal=*/false));
1347
1348 LinkDeclContextToDIE(function_decl, die);
1349
1350 if (!function_param_decls.empty()) {
1351 m_ast.SetFunctionParameters(function_decl, function_param_decls);
1352 if (template_function_decl)
1353 m_ast.SetFunctionParameters(template_function_decl,
1354 function_param_decls);
1355 }
1356
1357 ClangASTMetadata metadata;
1358 metadata.SetUserID(die.GetID());
1359
1360 char const *object_pointer_name =
1361 attrs.object_pointer ? attrs.object_pointer.GetName() : nullptr;
1362 if (object_pointer_name) {
1363 metadata.SetObjectPtrName(object_pointer_name);
1364 LLDB_LOGF(log,
1365 "Setting object pointer name: %s on function "
1366 "object %p.",
1367 object_pointer_name, static_cast<void *>(function_decl));
1368 }
1369 m_ast.SetMetadata(function_decl, metadata);
1370 }
1371 }
1372 }
1373 }
1374 return dwarf->MakeType(
1375 die.GetID(), attrs.name, std::nullopt, nullptr, LLDB_INVALID_UID,
1376 Type::eEncodingIsUID, &attrs.decl, clang_type, Type::ResolveState::Full);
1377}
1378
1379TypeSP
1381 const ParsedDWARFTypeAttributes &attrs) {
1383
1384 DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(),
1385 DW_TAG_value_to_name(tag), type_name_cstr);
1386
1387 DWARFDIE type_die = attrs.type.Reference();
1388 Type *element_type = dwarf->ResolveTypeUID(type_die, true);
1389
1390 if (!element_type)
1391 return nullptr;
1392
1393 std::optional<SymbolFile::ArrayInfo> array_info = ParseChildArrayInfo(die);
1394 uint32_t byte_stride = attrs.byte_stride;
1395 uint32_t bit_stride = attrs.bit_stride;
1396 if (array_info) {
1397 byte_stride = array_info->byte_stride;
1398 bit_stride = array_info->bit_stride;
1399 }
1400 if (byte_stride == 0 && bit_stride == 0)
1401 byte_stride = element_type->GetByteSize(nullptr).value_or(0);
1402 CompilerType array_element_type = element_type->GetForwardCompilerType();
1403 TypeSystemClang::RequireCompleteType(array_element_type);
1404
1405 uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
1406 CompilerType clang_type;
1407 if (array_info && array_info->element_orders.size() > 0) {
1408 auto end = array_info->element_orders.rend();
1409 for (auto pos = array_info->element_orders.rbegin(); pos != end; ++pos) {
1410 clang_type = m_ast.CreateArrayType(
1411 array_element_type, /*element_count=*/*pos, attrs.is_vector);
1412
1413 uint64_t num_elements = pos->value_or(0);
1414 array_element_type = clang_type;
1415 array_element_bit_stride = num_elements
1416 ? array_element_bit_stride * num_elements
1417 : array_element_bit_stride;
1418 }
1419 } else {
1420 clang_type = m_ast.CreateArrayType(
1421 array_element_type, /*element_count=*/std::nullopt, attrs.is_vector);
1422 }
1423 ConstString empty_name;
1424 TypeSP type_sp =
1425 dwarf->MakeType(die.GetID(), empty_name, array_element_bit_stride / 8,
1426 nullptr, type_die.GetID(), Type::eEncodingIsUID,
1427 &attrs.decl, clang_type, Type::ResolveState::Full);
1428 type_sp->SetEncodingType(element_type);
1429 const clang::Type *type = ClangUtil::GetQualType(clang_type).getTypePtr();
1430 m_ast.SetMetadataAsUserID(type, die.GetID());
1431 return type_sp;
1432}
1433
1435 const DWARFDIE &die, const ParsedDWARFTypeAttributes &attrs) {
1437 Type *pointee_type = dwarf->ResolveTypeUID(attrs.type.Reference(), true);
1438 Type *class_type =
1439 dwarf->ResolveTypeUID(attrs.containing_type.Reference(), true);
1440
1441 // Check to make sure pointers are not NULL before attempting to
1442 // dereference them.
1443 if ((class_type == nullptr) || (pointee_type == nullptr))
1444 return nullptr;
1445
1446 CompilerType pointee_clang_type = pointee_type->GetForwardCompilerType();
1447 CompilerType class_clang_type = class_type->GetForwardCompilerType();
1448
1450 class_clang_type, pointee_clang_type);
1451
1452 if (std::optional<uint64_t> clang_type_size =
1453 clang_type.GetByteSize(nullptr)) {
1454 return dwarf->MakeType(die.GetID(), attrs.name, *clang_type_size, nullptr,
1456 clang_type, Type::ResolveState::Forward);
1457 }
1458 return nullptr;
1459}
1460
1462 const DWARFDIE &die, const DWARFDIE &parent_die,
1463 const CompilerType class_clang_type, const AccessType default_accessibility,
1464 const lldb::ModuleSP &module_sp,
1465 std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> &base_classes,
1466 ClangASTImporter::LayoutInfo &layout_info) {
1467 auto ast =
1468 class_clang_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
1469 if (ast == nullptr)
1470 return;
1471
1472 // TODO: implement DW_TAG_inheritance type parsing.
1473 DWARFAttributes attributes = die.GetAttributes();
1474 if (attributes.Size() == 0)
1475 return;
1476
1477 DWARFFormValue encoding_form;
1478 AccessType accessibility = default_accessibility;
1479 bool is_virtual = false;
1480 bool is_base_of_class = true;
1481 off_t member_byte_offset = 0;
1482
1483 for (uint32_t i = 0; i < attributes.Size(); ++i) {
1484 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1485 DWARFFormValue form_value;
1486 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
1487 switch (attr) {
1488 case DW_AT_type:
1489 encoding_form = form_value;
1490 break;
1491 case DW_AT_data_member_location:
1492 if (auto maybe_offset =
1493 ExtractDataMemberLocation(die, form_value, module_sp))
1494 member_byte_offset = *maybe_offset;
1495 break;
1496
1497 case DW_AT_accessibility:
1498 accessibility =
1500 break;
1501
1502 case DW_AT_virtuality:
1503 is_virtual = form_value.Boolean();
1504 break;
1505
1506 default:
1507 break;
1508 }
1509 }
1510 }
1511
1512 Type *base_class_type = die.ResolveTypeUID(encoding_form.Reference());
1513 if (base_class_type == nullptr) {
1514 module_sp->ReportError("{0:x16}: DW_TAG_inheritance failed to "
1515 "resolve the base class at {1:x16}"
1516 " from enclosing type {2:x16}. \nPlease file "
1517 "a bug and attach the file at the start of "
1518 "this error message",
1519 die.GetOffset(),
1520 encoding_form.Reference().GetOffset(),
1521 parent_die.GetOffset());
1522 return;
1523 }
1524
1525 CompilerType base_class_clang_type = base_class_type->GetFullCompilerType();
1526 assert(base_class_clang_type);
1527 if (TypeSystemClang::IsObjCObjectOrInterfaceType(class_clang_type)) {
1528 ast->SetObjCSuperClass(class_clang_type, base_class_clang_type);
1529 return;
1530 }
1531 std::unique_ptr<clang::CXXBaseSpecifier> result =
1532 ast->CreateBaseClassSpecifier(base_class_clang_type.GetOpaqueQualType(),
1533 accessibility, is_virtual,
1534 is_base_of_class);
1535 if (!result)
1536 return;
1537
1538 base_classes.push_back(std::move(result));
1539
1540 if (is_virtual) {
1541 // Do not specify any offset for virtual inheritance. The DWARF
1542 // produced by clang doesn't give us a constant offset, but gives
1543 // us a DWARF expressions that requires an actual object in memory.
1544 // the DW_AT_data_member_location for a virtual base class looks
1545 // like:
1546 // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref,
1547 // DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref,
1548 // DW_OP_plus )
1549 // Given this, there is really no valid response we can give to
1550 // clang for virtual base class offsets, and this should eventually
1551 // be removed from LayoutRecordType() in the external
1552 // AST source in clang.
1553 } else {
1554 layout_info.base_offsets.insert(std::make_pair(
1555 ast->GetAsCXXRecordDecl(base_class_clang_type.GetOpaqueQualType()),
1556 clang::CharUnits::fromQuantity(member_byte_offset)));
1557 }
1558}
1559
1561 const SymbolContext &sc, const DWARFDIE &die, TypeSP type_sp) {
1562 if (!type_sp)
1563 return type_sp;
1564
1566 dw_tag_t sc_parent_tag = sc_parent_die.Tag();
1567
1568 SymbolContextScope *symbol_context_scope = nullptr;
1569 if (sc_parent_tag == DW_TAG_compile_unit ||
1570 sc_parent_tag == DW_TAG_partial_unit) {
1571 symbol_context_scope = sc.comp_unit;
1572 } else if (sc.function != nullptr && sc_parent_die) {
1573 symbol_context_scope =
1574 sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID());
1575 if (symbol_context_scope == nullptr)
1576 symbol_context_scope = sc.function;
1577 } else {
1578 symbol_context_scope = sc.module_sp.get();
1579 }
1580
1581 if (symbol_context_scope != nullptr)
1582 type_sp->SetSymbolContextScope(symbol_context_scope);
1583 return type_sp;
1584}
1585
1588 lldb::LanguageType language, lldb_private::ConstString &unique_typename,
1589 lldb_private::Declaration &decl_declaration) {
1590 // For C++, we rely solely upon the one definition rule that says
1591 // only one thing can exist at a given decl context. We ignore the
1592 // file and line that things are declared on.
1593 if (!die.IsValid() || !Language::LanguageIsCPlusPlus(language) ||
1594 unique_typename.IsEmpty())
1595 return;
1596 decl_declaration.Clear();
1597 std::string qualified_name;
1598 DWARFDIE parent_decl_ctx_die = die.GetParentDeclContextDIE();
1599 // TODO: change this to get the correct decl context parent....
1600 while (parent_decl_ctx_die) {
1601 // The name may not contain template parameters due to
1602 // -gsimple-template-names; we must reconstruct the full name from child
1603 // template parameter dies via GetDIEClassTemplateParams().
1604 const dw_tag_t parent_tag = parent_decl_ctx_die.Tag();
1605 switch (parent_tag) {
1606 case DW_TAG_namespace: {
1607 if (const char *namespace_name = parent_decl_ctx_die.GetName()) {
1608 qualified_name.insert(0, "::");
1609 qualified_name.insert(0, namespace_name);
1610 } else {
1611 qualified_name.insert(0, "(anonymous namespace)::");
1612 }
1613 parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
1614 break;
1615 }
1616
1617 case DW_TAG_class_type:
1618 case DW_TAG_structure_type:
1619 case DW_TAG_union_type: {
1620 if (const char *class_union_struct_name = parent_decl_ctx_die.GetName()) {
1621 qualified_name.insert(0, "::");
1622 qualified_name.insert(0,
1623 GetDIEClassTemplateParams(parent_decl_ctx_die));
1624 qualified_name.insert(0, class_union_struct_name);
1625 }
1626 parent_decl_ctx_die = parent_decl_ctx_die.GetParentDeclContextDIE();
1627 break;
1628 }
1629
1630 default:
1631 parent_decl_ctx_die.Clear();
1632 break;
1633 }
1634 }
1635
1636 if (qualified_name.empty())
1637 qualified_name.append("::");
1638
1639 qualified_name.append(unique_typename.GetCString());
1640 qualified_name.append(GetDIEClassTemplateParams(die));
1641
1642 unique_typename = ConstString(qualified_name);
1643}
1644
1645TypeSP
1647 const DWARFDIE &die,
1649 CompilerType clang_type;
1650 const dw_tag_t tag = die.Tag();
1652 LanguageType cu_language = SymbolFileDWARF::GetLanguage(*die.GetCU());
1653 Log *log = GetLog(DWARFLog::TypeCompletion | DWARFLog::Lookups);
1654
1655 ConstString unique_typename(attrs.name);
1656 Declaration unique_decl(attrs.decl);
1657 uint64_t byte_size = attrs.byte_size.value_or(0);
1658
1659 if (attrs.name) {
1660 GetUniqueTypeNameAndDeclaration(die, cu_language, unique_typename,
1661 unique_decl);
1662 if (log) {
1663 dwarf->GetObjectFile()->GetModule()->LogMessage(
1664 log, "SymbolFileDWARF({0:p}) - {1:x16}: {2} has unique name: {3} ",
1665 static_cast<void *>(this), die.GetID(), DW_TAG_value_to_name(tag),
1666 unique_typename.AsCString());
1667 }
1668 if (UniqueDWARFASTType *unique_ast_entry_type =
1669 dwarf->GetUniqueDWARFASTTypeMap().Find(
1670 unique_typename, die, unique_decl, byte_size,
1671 attrs.is_forward_declaration)) {
1672 if (TypeSP type_sp = unique_ast_entry_type->m_type_sp) {
1673 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
1675 GetCachedClangDeclContextForDIE(unique_ast_entry_type->m_die), die);
1676 // If the DIE being parsed in this function is a definition and the
1677 // entry in the map is a declaration, then we need to update the entry
1678 // to point to the definition DIE.
1679 if (!attrs.is_forward_declaration &&
1680 unique_ast_entry_type->m_is_forward_declaration) {
1681 unique_ast_entry_type->UpdateToDefDIE(die, unique_decl, byte_size);
1682 clang_type = type_sp->GetForwardCompilerType();
1683
1684 CompilerType compiler_type_no_qualifiers =
1686 dwarf->GetForwardDeclCompilerTypeToDIE().insert_or_assign(
1687 compiler_type_no_qualifiers.GetOpaqueQualType(),
1688 *die.GetDIERef());
1689 }
1690 return type_sp;
1691 }
1692 }
1693 }
1694
1695 DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(),
1696 DW_TAG_value_to_name(tag), type_name_cstr);
1697
1698 int tag_decl_kind = -1;
1699 AccessType default_accessibility = eAccessNone;
1700 if (tag == DW_TAG_structure_type) {
1701 tag_decl_kind = llvm::to_underlying(clang::TagTypeKind::Struct);
1702 default_accessibility = eAccessPublic;
1703 } else if (tag == DW_TAG_union_type) {
1704 tag_decl_kind = llvm::to_underlying(clang::TagTypeKind::Union);
1705 default_accessibility = eAccessPublic;
1706 } else if (tag == DW_TAG_class_type) {
1707 tag_decl_kind = llvm::to_underlying(clang::TagTypeKind::Class);
1708 default_accessibility = eAccessPrivate;
1709 }
1710
1711 if ((attrs.class_language == eLanguageTypeObjC ||
1713 !attrs.is_complete_objc_class) {
1714 // We have a valid eSymbolTypeObjCClass class symbol whose name
1715 // matches the current objective C class that we are trying to find
1716 // and this DIE isn't the complete definition (we checked
1717 // is_complete_objc_class above and know it is false), so the real
1718 // definition is in here somewhere
1719 TypeSP type_sp =
1720 dwarf->FindCompleteObjCDefinitionTypeForDIE(die, attrs.name, true);
1721
1722 if (!type_sp) {
1723 SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile();
1724 if (debug_map_symfile) {
1725 // We weren't able to find a full declaration in this DWARF,
1726 // see if we have a declaration anywhere else...
1727 type_sp = debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE(
1728 die, attrs.name, true);
1729 }
1730 }
1731
1732 if (type_sp) {
1733 if (log) {
1734 dwarf->GetObjectFile()->GetModule()->LogMessage(
1735 log,
1736 "SymbolFileDWARF({0:p}) - {1:x16}: {2} ({3}) type \"{4}\" is an "
1737 "incomplete objc type, complete type is {5:x8}",
1738 static_cast<void *>(this), die.GetID(), DW_TAG_value_to_name(tag),
1739 tag, attrs.name.GetCString(), type_sp->GetID());
1740 }
1741 return type_sp;
1742 }
1743 }
1744
1745 if (attrs.is_forward_declaration) {
1746 // See if the type comes from a Clang module and if so, track down
1747 // that type.
1748 TypeSP type_sp = ParseTypeFromClangModule(sc, die, log);
1749 if (type_sp)
1750 return type_sp;
1751 }
1752
1753 assert(tag_decl_kind != -1);
1754 UNUSED_IF_ASSERT_DISABLED(tag_decl_kind);
1755 clang::DeclContext *containing_decl_ctx =
1757
1759 containing_decl_ctx, die,
1760 attrs.name.GetCString());
1761
1762 if (attrs.accessibility == eAccessNone && containing_decl_ctx) {
1763 // Check the decl context that contains this class/struct/union. If
1764 // it is a class we must give it an accessibility.
1765 const clang::Decl::Kind containing_decl_kind =
1766 containing_decl_ctx->getDeclKind();
1767 if (DeclKindIsCXXClass(containing_decl_kind))
1768 attrs.accessibility = default_accessibility;
1769 }
1770
1771 ClangASTMetadata metadata;
1772 metadata.SetUserID(die.GetID());
1773 metadata.SetIsDynamicCXXType(dwarf->ClassOrStructIsVirtual(die));
1774
1775 TypeSystemClang::TemplateParameterInfos template_param_infos;
1776 if (ParseTemplateParameterInfos(die, template_param_infos)) {
1777 clang::ClassTemplateDecl *class_template_decl =
1779 containing_decl_ctx, GetOwningClangModule(die), attrs.accessibility,
1780 attrs.name.GetCString(), tag_decl_kind, template_param_infos);
1781 if (!class_template_decl) {
1782 if (log) {
1783 dwarf->GetObjectFile()->GetModule()->LogMessage(
1784 log,
1785 "SymbolFileDWARF({0:p}) - {1:x16}: {2} ({3}) type \"{4}\" "
1786 "clang::ClassTemplateDecl failed to return a decl.",
1787 static_cast<void *>(this), die.GetID(), DW_TAG_value_to_name(tag),
1788 tag, attrs.name.GetCString());
1789 }
1790 return TypeSP();
1791 }
1792
1793 clang::ClassTemplateSpecializationDecl *class_specialization_decl =
1795 containing_decl_ctx, GetOwningClangModule(die), class_template_decl,
1796 tag_decl_kind, template_param_infos);
1797 clang_type =
1798 m_ast.CreateClassTemplateSpecializationType(class_specialization_decl);
1799
1800 m_ast.SetMetadata(class_template_decl, metadata);
1801 m_ast.SetMetadata(class_specialization_decl, metadata);
1802 }
1803
1804 if (!clang_type) {
1805 clang_type = m_ast.CreateRecordType(
1806 containing_decl_ctx, GetOwningClangModule(die), attrs.accessibility,
1807 attrs.name.GetCString(), tag_decl_kind, attrs.class_language, metadata,
1808 attrs.exports_symbols);
1809 }
1810
1811 TypeSP type_sp = dwarf->MakeType(
1812 die.GetID(), attrs.name, attrs.byte_size, nullptr, LLDB_INVALID_UID,
1813 Type::eEncodingIsUID, &attrs.decl, clang_type,
1814 Type::ResolveState::Forward,
1816
1817 // Store a forward declaration to this class type in case any
1818 // parameters in any class methods need it for the clang types for
1819 // function prototypes.
1820 clang::DeclContext *type_decl_ctx =
1822 LinkDeclContextToDIE(type_decl_ctx, die);
1823
1824 // UniqueDWARFASTType is large, so don't create a local variables on the
1825 // stack, put it on the heap. This function is often called recursively and
1826 // clang isn't good at sharing the stack space for variables in different
1827 // blocks.
1828 auto unique_ast_entry_up = std::make_unique<UniqueDWARFASTType>();
1829 // Add our type to the unique type map so we don't end up creating many
1830 // copies of the same type over and over in the ASTContext for our
1831 // module
1832 unique_ast_entry_up->m_type_sp = type_sp;
1833 unique_ast_entry_up->m_die = die;
1834 unique_ast_entry_up->m_declaration = unique_decl;
1835 unique_ast_entry_up->m_byte_size = byte_size;
1836 unique_ast_entry_up->m_is_forward_declaration = attrs.is_forward_declaration;
1837 dwarf->GetUniqueDWARFASTTypeMap().Insert(unique_typename,
1838 *unique_ast_entry_up);
1839
1840 // Leave this as a forward declaration until we need to know the
1841 // details of the type. lldb_private::Type will automatically call
1842 // the SymbolFile virtual function
1843 // "SymbolFileDWARF::CompleteType(Type *)" When the definition
1844 // needs to be defined.
1845 bool inserted =
1846 dwarf->GetForwardDeclCompilerTypeToDIE()
1847 .try_emplace(
1848 ClangUtil::RemoveFastQualifiers(clang_type).GetOpaqueQualType(),
1849 *die.GetDIERef())
1850 .second;
1851 assert(inserted && "Type already in the forward declaration map!");
1852 (void)inserted;
1853 m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), true);
1854
1855 // If we made a clang type, set the trivial abi if applicable: We only
1856 // do this for pass by value - which implies the Trivial ABI. There
1857 // isn't a way to assert that something that would normally be pass by
1858 // value is pass by reference, so we ignore that attribute if set.
1859 if (attrs.calling_convention == llvm::dwarf::DW_CC_pass_by_value) {
1860 clang::CXXRecordDecl *record_decl =
1862 if (record_decl && record_decl->getDefinition()) {
1863 record_decl->setHasTrivialSpecialMemberForCall();
1864 }
1865 }
1866
1867 if (attrs.calling_convention == llvm::dwarf::DW_CC_pass_by_reference) {
1868 clang::CXXRecordDecl *record_decl =
1870 if (record_decl)
1871 record_decl->setArgPassingRestrictions(
1872 clang::RecordArgPassingKind::CannotPassInRegs);
1873 }
1874 return type_sp;
1875}
1876
1877// DWARF parsing functions
1878
1880public:
1882 const CompilerType &class_opaque_type, const char *property_name,
1883 const CompilerType &property_opaque_type, // The property type is only
1884 // required if you don't have an
1885 // ivar decl
1886 const char *property_setter_name, const char *property_getter_name,
1887 uint32_t property_attributes, ClangASTMetadata metadata)
1888 : m_class_opaque_type(class_opaque_type), m_property_name(property_name),
1889 m_property_opaque_type(property_opaque_type),
1890 m_property_setter_name(property_setter_name),
1891 m_property_getter_name(property_getter_name),
1892 m_property_attributes(property_attributes), m_metadata(metadata) {}
1893
1894 bool Finalize() {
1897 /*ivar_decl=*/nullptr, m_property_setter_name, m_property_getter_name,
1899 }
1900
1901private:
1903 const char *m_property_name;
1909};
1910
1912 const DWARFDIE &die,
1913 TypeSystemClang::TemplateParameterInfos &template_param_infos) {
1914 const dw_tag_t tag = die.Tag();
1915 bool is_template_template_argument = false;
1916
1917 switch (tag) {
1918 case DW_TAG_GNU_template_parameter_pack: {
1919 template_param_infos.SetParameterPack(
1920 std::make_unique<TypeSystemClang::TemplateParameterInfos>());
1921 for (DWARFDIE child_die : die.children()) {
1922 if (!ParseTemplateDIE(child_die, template_param_infos.GetParameterPack()))
1923 return false;
1924 }
1925 if (const char *name = die.GetName()) {
1926 template_param_infos.SetPackName(name);
1927 }
1928 return true;
1929 }
1930 case DW_TAG_GNU_template_template_param:
1931 is_template_template_argument = true;
1932 [[fallthrough]];
1933 case DW_TAG_template_type_parameter:
1934 case DW_TAG_template_value_parameter: {
1935 DWARFAttributes attributes = die.GetAttributes();
1936 if (attributes.Size() == 0)
1937 return true;
1938
1939 const char *name = nullptr;
1940 const char *template_name = nullptr;
1941 CompilerType clang_type;
1942 uint64_t uval64 = 0;
1943 bool uval64_valid = false;
1944 bool is_default_template_arg = false;
1945 DWARFFormValue form_value;
1946 for (size_t i = 0; i < attributes.Size(); ++i) {
1947 const dw_attr_t attr = attributes.AttributeAtIndex(i);
1948
1949 switch (attr) {
1950 case DW_AT_name:
1951 if (attributes.ExtractFormValueAtIndex(i, form_value))
1952 name = form_value.AsCString();
1953 break;
1954
1955 case DW_AT_GNU_template_name:
1956 if (attributes.ExtractFormValueAtIndex(i, form_value))
1957 template_name = form_value.AsCString();
1958 break;
1959
1960 case DW_AT_type:
1961 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
1962 Type *lldb_type = die.ResolveTypeUID(form_value.Reference());
1963 if (lldb_type)
1964 clang_type = lldb_type->GetForwardCompilerType();
1965 }
1966 break;
1967
1968 case DW_AT_const_value:
1969 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
1970 uval64_valid = true;
1971 uval64 = form_value.Unsigned();
1972 }
1973 break;
1974 case DW_AT_default_value:
1975 if (attributes.ExtractFormValueAtIndex(i, form_value))
1976 is_default_template_arg = form_value.Boolean();
1977 break;
1978 default:
1979 break;
1980 }
1981 }
1982
1983 clang::ASTContext &ast = m_ast.getASTContext();
1984 if (!clang_type)
1985 clang_type = m_ast.GetBasicType(eBasicTypeVoid);
1986
1987 if (!is_template_template_argument) {
1988 bool is_signed = false;
1989 // Get the signed value for any integer or enumeration if available
1990 clang_type.IsIntegerOrEnumerationType(is_signed);
1991
1992 if (name && !name[0])
1993 name = nullptr;
1994
1995 if (tag == DW_TAG_template_value_parameter && uval64_valid) {
1996 std::optional<uint64_t> size = clang_type.GetBitSize(nullptr);
1997 if (!size)
1998 return false;
1999 llvm::APInt apint(*size, uval64, is_signed);
2000 template_param_infos.InsertArg(
2001 name, clang::TemplateArgument(ast, llvm::APSInt(apint, !is_signed),
2002 ClangUtil::GetQualType(clang_type),
2003 is_default_template_arg));
2004 } else {
2005 template_param_infos.InsertArg(
2006 name, clang::TemplateArgument(ClangUtil::GetQualType(clang_type),
2007 /*isNullPtr*/ false,
2008 is_default_template_arg));
2009 }
2010 } else {
2011 auto *tplt_type = m_ast.CreateTemplateTemplateParmDecl(template_name);
2012 template_param_infos.InsertArg(
2013 name, clang::TemplateArgument(clang::TemplateName(tplt_type),
2014 is_default_template_arg));
2015 }
2016 }
2017 return true;
2018
2019 default:
2020 break;
2021 }
2022 return false;
2023}
2024
2026 const DWARFDIE &parent_die,
2027 TypeSystemClang::TemplateParameterInfos &template_param_infos) {
2028
2029 if (!parent_die)
2030 return false;
2031
2032 for (DWARFDIE die : parent_die.children()) {
2033 const dw_tag_t tag = die.Tag();
2034
2035 switch (tag) {
2036 case DW_TAG_template_type_parameter:
2037 case DW_TAG_template_value_parameter:
2038 case DW_TAG_GNU_template_parameter_pack:
2039 case DW_TAG_GNU_template_template_param:
2040 ParseTemplateDIE(die, template_param_infos);
2041 break;
2042
2043 default:
2044 break;
2045 }
2046 }
2047
2048 return !template_param_infos.IsEmpty() ||
2049 template_param_infos.hasParameterPack();
2050}
2051
2053 const CompilerType &clang_type) {
2054 const dw_tag_t tag = die.Tag();
2056
2057 ClangASTImporter::LayoutInfo layout_info;
2058 std::vector<DWARFDIE> contained_type_dies;
2059
2060 if (die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0))
2061 return false; // No definition, cannot complete.
2062
2063 // Start the definition if the type is not being defined already. This can
2064 // happen (e.g.) when adding nested types to a class type -- see
2065 // PrepareContextToReceiveMembers.
2066 if (!clang_type.IsBeingDefined())
2068
2069 AccessType default_accessibility = eAccessNone;
2070 if (tag == DW_TAG_structure_type) {
2071 default_accessibility = eAccessPublic;
2072 } else if (tag == DW_TAG_union_type) {
2073 default_accessibility = eAccessPublic;
2074 } else if (tag == DW_TAG_class_type) {
2075 default_accessibility = eAccessPrivate;
2076 }
2077
2078 std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> bases;
2079 // Parse members and base classes first
2080 std::vector<DWARFDIE> member_function_dies;
2081
2082 DelayedPropertyList delayed_properties;
2083 ParseChildMembers(die, clang_type, bases, member_function_dies,
2084 contained_type_dies, delayed_properties,
2085 default_accessibility, layout_info);
2086
2087 // Now parse any methods if there were any...
2088 for (const DWARFDIE &die : member_function_dies)
2089 dwarf->ResolveType(die);
2090
2092 ConstString class_name(clang_type.GetTypeName());
2093 if (class_name) {
2094 dwarf->GetObjCMethods(class_name, [&](DWARFDIE method_die) {
2095 method_die.ResolveType();
2096 return true;
2097 });
2098
2099 for (DelayedAddObjCClassProperty &property : delayed_properties)
2100 property.Finalize();
2101 }
2102 }
2103
2104 if (!bases.empty()) {
2105 // Make sure all base classes refer to complete types and not forward
2106 // declarations. If we don't do this, clang will crash with an
2107 // assertion in the call to clang_type.TransferBaseClasses()
2108 for (const auto &base_class : bases) {
2109 clang::TypeSourceInfo *type_source_info = base_class->getTypeSourceInfo();
2110 if (type_source_info)
2112 m_ast.GetType(type_source_info->getType()));
2113 }
2114
2115 m_ast.TransferBaseClasses(clang_type.GetOpaqueQualType(), std::move(bases));
2116 }
2117
2121
2122 layout_info.bit_size =
2123 die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8;
2124 layout_info.alignment =
2125 die.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_alignment, 0) * 8;
2126
2127 clang::CXXRecordDecl *record_decl =
2129 if (record_decl)
2130 GetClangASTImporter().SetRecordLayout(record_decl, layout_info);
2131
2132 // DWARF doesn't have the attribute, but we can infer the value the same way
2133 // as Clang Sema does. It's required to calculate the size of pointers to
2134 // member functions of this type.
2135 if (m_ast.getASTContext().getTargetInfo().getCXXABI().isMicrosoft()) {
2136 auto IM = record_decl->calculateInheritanceModel();
2137 record_decl->addAttr(clang::MSInheritanceAttr::CreateImplicit(
2138 m_ast.getASTContext(), true, {},
2139 clang::MSInheritanceAttr::Spelling(IM)));
2140 }
2141
2142 // Now parse all contained types inside of the class. We make forward
2143 // declarations to all classes, but we need the CXXRecordDecl to have decls
2144 // for all contained types because we don't get asked for them via the
2145 // external AST support.
2146 for (const DWARFDIE &die : contained_type_dies)
2147 dwarf->ResolveType(die);
2148
2149 return (bool)clang_type;
2150}
2151
2153 lldb_private::Type *type,
2154 const CompilerType &clang_type) {
2156 if (die.HasChildren()) {
2157 bool is_signed = false;
2158 clang_type.IsIntegerType(is_signed);
2159 ParseChildEnumerators(clang_type, is_signed,
2160 type->GetByteSize(nullptr).value_or(0), die);
2161 }
2163 }
2164 return (bool)clang_type;
2165}
2166
2168 const DWARFDIE &die, lldb_private::Type *type,
2169 const CompilerType &clang_type) {
2171
2172 std::lock_guard<std::recursive_mutex> guard(
2173 dwarf->GetObjectFile()->GetModule()->GetMutex());
2174
2175 // Disable external storage for this type so we don't get anymore
2176 // clang::ExternalASTSource queries for this type.
2177 m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), false);
2178
2179 if (!die)
2180 return false;
2181
2182 const dw_tag_t tag = die.Tag();
2183
2184 assert(clang_type);
2185 switch (tag) {
2186 case DW_TAG_structure_type:
2187 case DW_TAG_union_type:
2188 case DW_TAG_class_type:
2189 CompleteRecordType(die, clang_type);
2190 break;
2191 case DW_TAG_enumeration_type:
2192 CompleteEnumType(die, type, clang_type);
2193 break;
2194 default:
2195 assert(false && "not a forward clang type decl!");
2196 break;
2197 }
2198
2199 // If the type is still not fully defined at this point, it means we weren't
2200 // able to find its definition. We must forcefully complete it to preserve
2201 // clang AST invariants.
2202 if (clang_type.IsBeingDefined()) {
2205 }
2206
2207 return true;
2208}
2209
2211 lldb_private::CompilerDeclContext decl_context) {
2212 auto opaque_decl_ctx =
2213 (clang::DeclContext *)decl_context.GetOpaqueDeclContext();
2214 for (auto it = m_decl_ctx_to_die.find(opaque_decl_ctx);
2215 it != m_decl_ctx_to_die.end() && it->first == opaque_decl_ctx;
2216 it = m_decl_ctx_to_die.erase(it))
2217 for (DWARFDIE decl : it->second.children())
2218 GetClangDeclForDIE(decl);
2219}
2220
2222 clang::Decl *clang_decl = GetClangDeclForDIE(die);
2223 if (clang_decl != nullptr)
2224 return m_ast.GetCompilerDecl(clang_decl);
2225 return {};
2226}
2227
2230 clang::DeclContext *clang_decl_ctx = GetClangDeclContextForDIE(die);
2231 if (clang_decl_ctx)
2232 return m_ast.CreateDeclContext(clang_decl_ctx);
2233 return {};
2234}
2235
2238 clang::DeclContext *clang_decl_ctx =
2240 if (clang_decl_ctx)
2241 return m_ast.CreateDeclContext(clang_decl_ctx);
2242 return {};
2243}
2244
2246 const lldb_private::CompilerType &clang_type, bool is_signed,
2247 uint32_t enumerator_byte_size, const DWARFDIE &parent_die) {
2248 if (!parent_die)
2249 return 0;
2250
2251 size_t enumerators_added = 0;
2252
2253 for (DWARFDIE die : parent_die.children()) {
2254 const dw_tag_t tag = die.Tag();
2255 if (tag != DW_TAG_enumerator)
2256 continue;
2257
2258 DWARFAttributes attributes = die.GetAttributes();
2259 if (attributes.Size() == 0)
2260 continue;
2261
2262 const char *name = nullptr;
2263 bool got_value = false;
2264 int64_t enum_value = 0;
2265 Declaration decl;
2266
2267 for (size_t i = 0; i < attributes.Size(); ++i) {
2268 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2269 DWARFFormValue form_value;
2270 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2271 switch (attr) {
2272 case DW_AT_const_value:
2273 got_value = true;
2274 if (is_signed)
2275 enum_value = form_value.Signed();
2276 else
2277 enum_value = form_value.Unsigned();
2278 break;
2279
2280 case DW_AT_name:
2281 name = form_value.AsCString();
2282 break;
2283
2284 case DW_AT_description:
2285 default:
2286 case DW_AT_decl_file:
2287 decl.SetFile(
2288 attributes.CompileUnitAtIndex(i)->GetFile(form_value.Unsigned()));
2289 break;
2290 case DW_AT_decl_line:
2291 decl.SetLine(form_value.Unsigned());
2292 break;
2293 case DW_AT_decl_column:
2294 decl.SetColumn(form_value.Unsigned());
2295 break;
2296 case DW_AT_sibling:
2297 break;
2298 }
2299 }
2300 }
2301
2302 if (name && name[0] && got_value) {
2304 clang_type, decl, name, enum_value, enumerator_byte_size * 8);
2305 ++enumerators_added;
2306 }
2307 }
2308 return enumerators_added;
2309}
2310
2313 bool is_static = false;
2314 bool is_variadic = false;
2315 bool has_template_params = false;
2316 unsigned type_quals = 0;
2317 std::vector<CompilerType> param_types;
2318 std::vector<clang::ParmVarDecl *> param_decls;
2319 StreamString sstr;
2320
2321 DWARFDeclContext decl_ctx = die.GetDWARFDeclContext();
2322 sstr << decl_ctx.GetQualifiedName();
2323
2324 clang::DeclContext *containing_decl_ctx =
2326 ParseChildParameters(containing_decl_ctx, die, is_static, is_variadic,
2327 has_template_params, param_types, param_decls,
2328 type_quals);
2329 sstr << "(";
2330 for (size_t i = 0; i < param_types.size(); i++) {
2331 if (i > 0)
2332 sstr << ", ";
2333 sstr << param_types[i].GetTypeName();
2334 }
2335 if (is_variadic)
2336 sstr << ", ...";
2337 sstr << ")";
2338 if (type_quals & clang::Qualifiers::Const)
2339 sstr << " const";
2340
2341 return ConstString(sstr.GetString());
2342}
2343
2345 CompileUnit &comp_unit, const DWARFDIE &die, AddressRanges func_ranges) {
2346 llvm::DWARFAddressRangesVector unused_func_ranges;
2347 const char *name = nullptr;
2348 const char *mangled = nullptr;
2349 std::optional<int> decl_file;
2350 std::optional<int> decl_line;
2351 std::optional<int> decl_column;
2352 std::optional<int> call_file;
2353 std::optional<int> call_line;
2354 std::optional<int> call_column;
2355 DWARFExpressionList frame_base;
2356
2357 const dw_tag_t tag = die.Tag();
2358
2359 if (tag != DW_TAG_subprogram)
2360 return nullptr;
2361
2362 if (die.GetDIENamesAndRanges(name, mangled, unused_func_ranges, decl_file,
2363 decl_line, decl_column, call_file, call_line,
2364 call_column, &frame_base)) {
2365 Mangled func_name;
2366 if (mangled)
2367 func_name.SetValue(ConstString(mangled));
2368 else if ((die.GetParent().Tag() == DW_TAG_compile_unit ||
2369 die.GetParent().Tag() == DW_TAG_partial_unit) &&
2374 name && strcmp(name, "main") != 0) {
2375 // If the mangled name is not present in the DWARF, generate the
2376 // demangled name using the decl context. We skip if the function is
2377 // "main" as its name is never mangled.
2379 } else
2380 func_name.SetValue(ConstString(name));
2381
2382 FunctionSP func_sp;
2383 std::unique_ptr<Declaration> decl_up;
2384 if (decl_file || decl_line || decl_column)
2385 decl_up = std::make_unique<Declaration>(
2386 die.GetCU()->GetFile(decl_file ? *decl_file : 0),
2387 decl_line ? *decl_line : 0, decl_column ? *decl_column : 0);
2388
2390 // Supply the type _only_ if it has already been parsed
2391 Type *func_type = dwarf->GetDIEToType().lookup(die.GetDIE());
2392
2393 assert(func_type == nullptr || func_type != DIE_IS_BEING_PARSED);
2394
2395 const user_id_t func_user_id = die.GetID();
2396 func_sp = std::make_shared<Function>(
2397 &comp_unit,
2398 func_user_id, // UserID is the DIE offset
2399 func_user_id, func_name, func_type, std::move(func_ranges));
2400
2401 if (func_sp.get() != nullptr) {
2402 if (frame_base.IsValid())
2403 func_sp->GetFrameBaseExpression() = frame_base;
2404 comp_unit.AddFunction(func_sp);
2405 return func_sp.get();
2406 }
2407 }
2408 return nullptr;
2409}
2410
2411namespace {
2412/// Parsed form of all attributes that are relevant for parsing Objective-C
2413/// properties.
2414struct PropertyAttributes {
2415 explicit PropertyAttributes(const DWARFDIE &die);
2416 const char *prop_name = nullptr;
2417 const char *prop_getter_name = nullptr;
2418 const char *prop_setter_name = nullptr;
2419 /// \see clang::ObjCPropertyAttribute
2420 uint32_t prop_attributes = 0;
2421};
2422
2423struct DiscriminantValue {
2424 explicit DiscriminantValue(const DWARFDIE &die, ModuleSP module_sp);
2425
2426 uint32_t byte_offset;
2427 uint32_t byte_size;
2428 DWARFFormValue type_ref;
2429};
2430
2431struct VariantMember {
2432 explicit VariantMember(DWARFDIE &die, ModuleSP module_sp);
2433 bool IsDefault() const;
2434
2435 std::optional<uint32_t> discr_value;
2436 DWARFFormValue type_ref;
2437 ConstString variant_name;
2438 uint32_t byte_offset;
2439 ConstString GetName() const;
2440};
2441
2442struct VariantPart {
2443 explicit VariantPart(const DWARFDIE &die, const DWARFDIE &parent_die,
2444 ModuleSP module_sp);
2445
2446 std::vector<VariantMember> &members();
2447
2448 DiscriminantValue &discriminant();
2449
2450private:
2451 std::vector<VariantMember> _members;
2452 DiscriminantValue _discriminant;
2453};
2454
2455} // namespace
2456
2457ConstString VariantMember::GetName() const { return this->variant_name; }
2458
2459bool VariantMember::IsDefault() const { return !discr_value; }
2460
2461VariantMember::VariantMember(DWARFDIE &die, lldb::ModuleSP module_sp) {
2462 assert(die.Tag() == llvm::dwarf::DW_TAG_variant);
2463 this->discr_value =
2464 die.GetAttributeValueAsOptionalUnsigned(DW_AT_discr_value);
2465
2466 for (auto child_die : die.children()) {
2467 switch (child_die.Tag()) {
2468 case llvm::dwarf::DW_TAG_member: {
2469 DWARFAttributes attributes = child_die.GetAttributes();
2470 for (std::size_t i = 0; i < attributes.Size(); ++i) {
2471 DWARFFormValue form_value;
2472 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2473 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2474 switch (attr) {
2475 case DW_AT_name:
2476 variant_name = ConstString(form_value.AsCString());
2477 break;
2478 case DW_AT_type:
2479 type_ref = form_value;
2480 break;
2481
2482 case DW_AT_data_member_location:
2483 if (auto maybe_offset =
2484 ExtractDataMemberLocation(die, form_value, module_sp))
2485 byte_offset = *maybe_offset;
2486 break;
2487
2488 default:
2489 break;
2490 }
2491 }
2492 }
2493 break;
2494 }
2495 default:
2496 break;
2497 }
2498 break;
2499 }
2500}
2501
2502DiscriminantValue::DiscriminantValue(const DWARFDIE &die, ModuleSP module_sp) {
2503 auto referenced_die = die.GetReferencedDIE(DW_AT_discr);
2504 DWARFAttributes attributes = referenced_die.GetAttributes();
2505 for (std::size_t i = 0; i < attributes.Size(); ++i) {
2506 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2507 DWARFFormValue form_value;
2508 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2509 switch (attr) {
2510 case DW_AT_type:
2511 type_ref = form_value;
2512 break;
2513 case DW_AT_data_member_location:
2514 if (auto maybe_offset =
2515 ExtractDataMemberLocation(die, form_value, module_sp))
2516 byte_offset = *maybe_offset;
2517 break;
2518 default:
2519 break;
2520 }
2521 }
2522 }
2523}
2524
2525VariantPart::VariantPart(const DWARFDIE &die, const DWARFDIE &parent_die,
2526 lldb::ModuleSP module_sp)
2527 : _members(), _discriminant(die, module_sp) {
2528
2529 for (auto child : die.children()) {
2530 if (child.Tag() == llvm::dwarf::DW_TAG_variant) {
2531 _members.push_back(VariantMember(child, module_sp));
2532 }
2533 }
2534}
2535
2536std::vector<VariantMember> &VariantPart::members() { return this->_members; }
2537
2538DiscriminantValue &VariantPart::discriminant() { return this->_discriminant; }
2539
2541 const DWARFDIE &die, const DWARFDIE &parent_die, ModuleSP module_sp) {
2542 DWARFAttributes attributes = die.GetAttributes();
2543 for (size_t i = 0; i < attributes.Size(); ++i) {
2544 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2545 DWARFFormValue form_value;
2546 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2547 switch (attr) {
2548 case DW_AT_name:
2549 name = form_value.AsCString();
2550 break;
2551 case DW_AT_type:
2552 encoding_form = form_value;
2553 break;
2554 case DW_AT_bit_offset:
2555 bit_offset = form_value.Signed();
2556 break;
2557 case DW_AT_bit_size:
2558 bit_size = form_value.Unsigned();
2559 break;
2560 case DW_AT_byte_size:
2561 byte_size = form_value.Unsigned();
2562 break;
2563 case DW_AT_const_value:
2564 const_value_form = form_value;
2565 break;
2566 case DW_AT_data_bit_offset:
2567 data_bit_offset = form_value.Unsigned();
2568 break;
2569 case DW_AT_data_member_location:
2570 if (auto maybe_offset =
2571 ExtractDataMemberLocation(die, form_value, module_sp))
2572 member_byte_offset = *maybe_offset;
2573 break;
2574
2575 case DW_AT_accessibility:
2578 break;
2579 case DW_AT_artificial:
2580 is_artificial = form_value.Boolean();
2581 break;
2582 case DW_AT_declaration:
2583 is_declaration = form_value.Boolean();
2584 break;
2585 default:
2586 break;
2587 }
2588 }
2589 }
2590
2591 // Clang has a DWARF generation bug where sometimes it represents
2592 // fields that are references with bad byte size and bit size/offset
2593 // information such as:
2594 //
2595 // DW_AT_byte_size( 0x00 )
2596 // DW_AT_bit_size( 0x40 )
2597 // DW_AT_bit_offset( 0xffffffffffffffc0 )
2598 //
2599 // So check the bit offset to make sure it is sane, and if the values
2600 // are not sane, remove them. If we don't do this then we will end up
2601 // with a crash if we try to use this type in an expression when clang
2602 // becomes unhappy with its recycled debug info.
2603 if (byte_size.value_or(0) == 0 && bit_offset < 0) {
2604 bit_size = 0;
2605 bit_offset = 0;
2606 }
2607}
2608
2609PropertyAttributes::PropertyAttributes(const DWARFDIE &die) {
2610
2611 DWARFAttributes attributes = die.GetAttributes();
2612 for (size_t i = 0; i < attributes.Size(); ++i) {
2613 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2614 DWARFFormValue form_value;
2615 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2616 switch (attr) {
2617 case DW_AT_APPLE_property_name:
2618 prop_name = form_value.AsCString();
2619 break;
2620 case DW_AT_APPLE_property_getter:
2621 prop_getter_name = form_value.AsCString();
2622 break;
2623 case DW_AT_APPLE_property_setter:
2624 prop_setter_name = form_value.AsCString();
2625 break;
2626 case DW_AT_APPLE_property_attribute:
2627 prop_attributes = form_value.Unsigned();
2628 break;
2629 default:
2630 break;
2631 }
2632 }
2633 }
2634
2635 if (!prop_name)
2636 return;
2637 ConstString fixed_setter;
2638
2639 // Check if the property getter/setter were provided as full names.
2640 // We want basenames, so we extract them.
2641 if (prop_getter_name && prop_getter_name[0] == '-') {
2642 std::optional<const ObjCLanguage::MethodName> prop_getter_method =
2643 ObjCLanguage::MethodName::Create(prop_getter_name, true);
2644 if (prop_getter_method)
2645 prop_getter_name =
2646 ConstString(prop_getter_method->GetSelector()).GetCString();
2647 }
2648
2649 if (prop_setter_name && prop_setter_name[0] == '-') {
2650 std::optional<const ObjCLanguage::MethodName> prop_setter_method =
2651 ObjCLanguage::MethodName::Create(prop_setter_name, true);
2652 if (prop_setter_method)
2653 prop_setter_name =
2654 ConstString(prop_setter_method->GetSelector()).GetCString();
2655 }
2656
2657 // If the names haven't been provided, they need to be filled in.
2658 if (!prop_getter_name)
2659 prop_getter_name = prop_name;
2660 if (!prop_setter_name && prop_name[0] &&
2661 !(prop_attributes & DW_APPLE_PROPERTY_readonly)) {
2662 StreamString ss;
2663
2664 ss.Printf("set%c%s:", toupper(prop_name[0]), &prop_name[1]);
2665
2666 fixed_setter.SetString(ss.GetString());
2667 prop_setter_name = fixed_setter.GetCString();
2668 }
2669}
2670
2672 const DWARFDIE &die, const DWARFDIE &parent_die,
2673 const lldb_private::CompilerType &class_clang_type,
2674 DelayedPropertyList &delayed_properties) {
2675 // This function can only parse DW_TAG_APPLE_property.
2676 assert(die.Tag() == DW_TAG_APPLE_property);
2677
2678 ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule();
2679
2680 const MemberAttributes attrs(die, parent_die, module_sp);
2681 const PropertyAttributes propAttrs(die);
2682
2683 if (!propAttrs.prop_name) {
2684 module_sp->ReportError("{0:x8}: DW_TAG_APPLE_property has no name.",
2685 die.GetID());
2686 return;
2687 }
2688
2689 Type *member_type = die.ResolveTypeUID(attrs.encoding_form.Reference());
2690 if (!member_type) {
2691 module_sp->ReportError(
2692 "{0:x8}: DW_TAG_APPLE_property '{1}' refers to type {2:x16}"
2693 " which was unable to be parsed",
2694 die.GetID(), propAttrs.prop_name,
2696 return;
2697 }
2698
2699 ClangASTMetadata metadata;
2700 metadata.SetUserID(die.GetID());
2701 delayed_properties.emplace_back(
2702 class_clang_type, propAttrs.prop_name,
2703 member_type->GetLayoutCompilerType(), propAttrs.prop_setter_name,
2704 propAttrs.prop_getter_name, propAttrs.prop_attributes, metadata);
2705}
2706
2708 const CompilerType &int_type, const DWARFFormValue &form_value) const {
2709 clang::QualType qt = ClangUtil::GetQualType(int_type);
2710 assert(qt->isIntegralOrEnumerationType());
2711 auto ts_ptr = int_type.GetTypeSystem().dyn_cast_or_null<TypeSystemClang>();
2712 if (!ts_ptr)
2713 return llvm::createStringError(llvm::inconvertibleErrorCode(),
2714 "TypeSystem not clang");
2715 TypeSystemClang &ts = *ts_ptr;
2716 clang::ASTContext &ast = ts.getASTContext();
2717
2718 const unsigned type_bits = ast.getIntWidth(qt);
2719 const bool is_unsigned = qt->isUnsignedIntegerType();
2720
2721 // The maximum int size supported at the moment by this function. Limited
2722 // by the uint64_t return type of DWARFFormValue::Signed/Unsigned.
2723 constexpr std::size_t max_bit_size = 64;
2724
2725 // For values bigger than 64 bit (e.g. __int128_t values),
2726 // DWARFFormValue's Signed/Unsigned functions will return wrong results so
2727 // emit an error for now.
2728 if (type_bits > max_bit_size) {
2729 auto msg = llvm::formatv("Can only parse integers with up to {0} bits, but "
2730 "given integer has {1} bits.",
2731 max_bit_size, type_bits);
2732 return llvm::createStringError(llvm::inconvertibleErrorCode(), msg.str());
2733 }
2734
2735 // Construct an APInt with the maximum bit size and the given integer.
2736 llvm::APInt result(max_bit_size, form_value.Unsigned(), !is_unsigned);
2737
2738 // Calculate how many bits are required to represent the input value.
2739 // For unsigned types, take the number of active bits in the APInt.
2740 // For signed types, ask APInt how many bits are required to represent the
2741 // signed integer.
2742 const unsigned required_bits =
2743 is_unsigned ? result.getActiveBits() : result.getSignificantBits();
2744
2745 // If the input value doesn't fit into the integer type, return an error.
2746 if (required_bits > type_bits) {
2747 std::string value_as_str = is_unsigned
2748 ? std::to_string(form_value.Unsigned())
2749 : std::to_string(form_value.Signed());
2750 auto msg = llvm::formatv("Can't store {0} value {1} in integer with {2} "
2751 "bits.",
2752 (is_unsigned ? "unsigned" : "signed"),
2753 value_as_str, type_bits);
2754 return llvm::createStringError(llvm::inconvertibleErrorCode(), msg.str());
2755 }
2756
2757 // Trim the result to the bit width our the int type.
2758 if (result.getBitWidth() > type_bits)
2759 result = result.trunc(type_bits);
2760 return result;
2761}
2762
2764 const DWARFDIE &die, const MemberAttributes &attrs,
2765 const lldb_private::CompilerType &class_clang_type) {
2766 Log *log = GetLog(DWARFLog::TypeCompletion | DWARFLog::Lookups);
2767 assert(die.Tag() == DW_TAG_member || die.Tag() == DW_TAG_variable);
2768
2769 Type *var_type = die.ResolveTypeUID(attrs.encoding_form.Reference());
2770
2771 if (!var_type)
2772 return;
2773
2774 auto accessibility =
2776
2777 CompilerType ct = var_type->GetForwardCompilerType();
2778 clang::VarDecl *v = TypeSystemClang::AddVariableToRecordType(
2779 class_clang_type, attrs.name, ct, accessibility);
2780 if (!v) {
2781 LLDB_LOG(log, "Failed to add variable to the record type");
2782 return;
2783 }
2784
2785 bool unused;
2786 // TODO: Support float/double static members as well.
2787 if (!ct.IsIntegerOrEnumerationType(unused) || !attrs.const_value_form)
2788 return;
2789
2790 llvm::Expected<llvm::APInt> const_value_or_err =
2792 if (!const_value_or_err) {
2793 LLDB_LOG_ERROR(log, const_value_or_err.takeError(),
2794 "Failed to add const value to variable {1}: {0}",
2795 v->getQualifiedNameAsString());
2796 return;
2797 }
2798
2800}
2801
2803 const DWARFDIE &die, const DWARFDIE &parent_die,
2804 const lldb_private::CompilerType &class_clang_type,
2805 lldb::AccessType default_accessibility,
2807 FieldInfo &last_field_info) {
2808 // This function can only parse DW_TAG_member.
2809 assert(die.Tag() == DW_TAG_member);
2810
2811 ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule();
2812 const dw_tag_t tag = die.Tag();
2813 // Get the parent byte size so we can verify any members will fit
2814 const uint64_t parent_byte_size =
2815 parent_die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX);
2816 const uint64_t parent_bit_size =
2817 parent_byte_size == UINT64_MAX ? UINT64_MAX : parent_byte_size * 8;
2818
2819 const MemberAttributes attrs(die, parent_die, module_sp);
2820
2821 // Handle static members, which are typically members without
2822 // locations. However, GCC doesn't emit DW_AT_data_member_location
2823 // for any union members (regardless of linkage).
2824 // Non-normative text pre-DWARFv5 recommends marking static
2825 // data members with an DW_AT_external flag. Clang emits this consistently
2826 // whereas GCC emits it only for static data members if not part of an
2827 // anonymous namespace. The flag that is consistently emitted for static
2828 // data members is DW_AT_declaration, so we check it instead.
2829 // The following block is only necessary to support DWARFv4 and earlier.
2830 // Starting with DWARFv5, static data members are marked DW_AT_variable so we
2831 // can consistently detect them on both GCC and Clang without below heuristic.
2832 if (attrs.member_byte_offset == UINT32_MAX &&
2833 attrs.data_bit_offset == UINT64_MAX && attrs.is_declaration) {
2834 CreateStaticMemberVariable(die, attrs, class_clang_type);
2835 return;
2836 }
2837
2838 Type *member_type = die.ResolveTypeUID(attrs.encoding_form.Reference());
2839 if (!member_type) {
2840 if (attrs.name)
2841 module_sp->ReportError(
2842 "{0:x8}: DW_TAG_member '{1}' refers to type {2:x16}"
2843 " which was unable to be parsed",
2844 die.GetID(), attrs.name, attrs.encoding_form.Reference().GetOffset());
2845 else
2846 module_sp->ReportError("{0:x8}: DW_TAG_member refers to type {1:x16}"
2847 " which was unable to be parsed",
2848 die.GetID(),
2850 return;
2851 }
2852
2853 const uint64_t character_width = 8;
2854 CompilerType member_clang_type = member_type->GetLayoutCompilerType();
2855
2856 const auto accessibility = attrs.accessibility == eAccessNone
2857 ? default_accessibility
2858 : attrs.accessibility;
2859
2860 uint64_t field_bit_offset = (attrs.member_byte_offset == UINT32_MAX
2861 ? 0
2862 : (attrs.member_byte_offset * 8ULL));
2863
2864 if (attrs.bit_size > 0) {
2865 FieldInfo this_field_info;
2866 this_field_info.bit_offset = field_bit_offset;
2867 this_field_info.bit_size = attrs.bit_size;
2868
2869 if (attrs.data_bit_offset != UINT64_MAX) {
2870 this_field_info.bit_offset = attrs.data_bit_offset;
2871 } else {
2872 auto byte_size = attrs.byte_size;
2873 if (!byte_size)
2874 byte_size = member_type->GetByteSize(nullptr);
2875
2876 ObjectFile *objfile = die.GetDWARF()->GetObjectFile();
2877 if (objfile->GetByteOrder() == eByteOrderLittle) {
2878 this_field_info.bit_offset += byte_size.value_or(0) * 8;
2879 this_field_info.bit_offset -= (attrs.bit_offset + attrs.bit_size);
2880 } else {
2881 this_field_info.bit_offset += attrs.bit_offset;
2882 }
2883 }
2884
2885 // The ObjC runtime knows the byte offset but we still need to provide
2886 // the bit-offset in the layout. It just means something different then
2887 // what it does in C and C++. So we skip this check for ObjC types.
2888 //
2889 // We also skip this for fields of a union since they will all have a
2890 // zero offset.
2891 if (!TypeSystemClang::IsObjCObjectOrInterfaceType(class_clang_type) &&
2892 !(parent_die.Tag() == DW_TAG_union_type &&
2893 this_field_info.bit_offset == 0) &&
2894 ((this_field_info.bit_offset >= parent_bit_size) ||
2895 (last_field_info.IsBitfield() &&
2896 !last_field_info.NextBitfieldOffsetIsValid(
2897 this_field_info.bit_offset)))) {
2898 ObjectFile *objfile = die.GetDWARF()->GetObjectFile();
2899 objfile->GetModule()->ReportWarning(
2900 "{0:x16}: {1} ({2}) bitfield named \"{3}\" has invalid "
2901 "bit offset ({4:x8}) member will be ignored. Please file a bug "
2902 "against the "
2903 "compiler and include the preprocessed output for {5}\n",
2904 die.GetID(), DW_TAG_value_to_name(tag), tag, attrs.name,
2905 this_field_info.bit_offset, GetUnitName(parent_die).c_str());
2906 return;
2907 }
2908
2909 // Update the field bit offset we will report for layout
2910 field_bit_offset = this_field_info.bit_offset;
2911
2912 // Objective-C has invalid DW_AT_bit_offset values in older
2913 // versions of clang, so we have to be careful and only insert
2914 // unnamed bitfields if we have a new enough clang.
2915 bool detect_unnamed_bitfields = true;
2916
2918 detect_unnamed_bitfields =
2920
2921 if (detect_unnamed_bitfields)
2922 AddUnnamedBitfieldToRecordTypeIfNeeded(layout_info, class_clang_type,
2923 last_field_info, this_field_info);
2924
2925 last_field_info = this_field_info;
2926 last_field_info.SetIsBitfield(true);
2927 } else {
2928 FieldInfo this_field_info;
2929 this_field_info.is_bitfield = false;
2930 this_field_info.bit_offset = field_bit_offset;
2931
2932 // TODO: we shouldn't silently ignore the bit_size if we fail
2933 // to GetByteSize.
2934 if (std::optional<uint64_t> clang_type_size =
2935 member_type->GetByteSize(nullptr)) {
2936 this_field_info.bit_size = *clang_type_size * character_width;
2937 }
2938
2939 if (this_field_info.GetFieldEnd() <= last_field_info.GetEffectiveFieldEnd())
2940 this_field_info.SetEffectiveFieldEnd(
2941 last_field_info.GetEffectiveFieldEnd());
2942
2943 last_field_info = this_field_info;
2944 }
2945
2946 // Don't turn artificial members such as vtable pointers into real FieldDecls
2947 // in our AST. Clang will re-create those articial members and they would
2948 // otherwise just overlap in the layout with the FieldDecls we add here.
2949 // This needs to be done after updating FieldInfo which keeps track of where
2950 // field start/end so we don't later try to fill the space of this
2951 // artificial member with (unnamed bitfield) padding.
2952 if (attrs.is_artificial && ShouldIgnoreArtificialField(attrs.name)) {
2953 last_field_info.SetIsArtificial(true);
2954 return;
2955 }
2956
2957 if (!member_clang_type.IsCompleteType())
2958 member_clang_type.GetCompleteType();
2959
2960 {
2961 // Older versions of clang emit the same DWARF for array[0] and array[1]. If
2962 // the current field is at the end of the structure, then there is
2963 // definitely no room for extra elements and we override the type to
2964 // array[0]. This was fixed by f454dfb6b5af.
2965 CompilerType member_array_element_type;
2966 uint64_t member_array_size;
2967 bool member_array_is_incomplete;
2968
2969 if (member_clang_type.IsArrayType(&member_array_element_type,
2970 &member_array_size,
2971 &member_array_is_incomplete) &&
2972 !member_array_is_incomplete) {
2973 uint64_t parent_byte_size =
2974 parent_die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX);
2975
2976 if (attrs.member_byte_offset >= parent_byte_size) {
2977 if (member_array_size != 1 &&
2978 (member_array_size != 0 ||
2979 attrs.member_byte_offset > parent_byte_size)) {
2980 module_sp->ReportError(
2981 "{0:x8}: DW_TAG_member '{1}' refers to type {2:x16}"
2982 " which extends beyond the bounds of {3:x8}",
2983 die.GetID(), attrs.name,
2984 attrs.encoding_form.Reference().GetOffset(), parent_die.GetID());
2985 }
2986
2987 member_clang_type =
2988 m_ast.CreateArrayType(member_array_element_type, 0, false);
2989 }
2990 }
2991 }
2992
2993 TypeSystemClang::RequireCompleteType(member_clang_type);
2994
2995 clang::FieldDecl *field_decl = TypeSystemClang::AddFieldToRecordType(
2996 class_clang_type, attrs.name, member_clang_type, accessibility,
2997 attrs.bit_size);
2998
2999 m_ast.SetMetadataAsUserID(field_decl, die.GetID());
3000
3001 layout_info.field_offsets.insert(
3002 std::make_pair(field_decl, field_bit_offset));
3003}
3004
3006 const DWARFDIE &parent_die, const CompilerType &class_clang_type,
3007 std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> &base_classes,
3008 std::vector<DWARFDIE> &member_function_dies,
3009 std::vector<DWARFDIE> &contained_type_dies,
3010 DelayedPropertyList &delayed_properties,
3011 const AccessType default_accessibility,
3012 ClangASTImporter::LayoutInfo &layout_info) {
3013 if (!parent_die)
3014 return false;
3015
3016 FieldInfo last_field_info;
3017
3018 ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule();
3019 auto ts = class_clang_type.GetTypeSystem();
3020 auto ast = ts.dyn_cast_or_null<TypeSystemClang>();
3021 if (ast == nullptr)
3022 return false;
3023
3024 for (DWARFDIE die : parent_die.children()) {
3025 dw_tag_t tag = die.Tag();
3026
3027 switch (tag) {
3028 case DW_TAG_APPLE_property:
3029 ParseObjCProperty(die, parent_die, class_clang_type, delayed_properties);
3030 break;
3031
3032 case DW_TAG_variant_part:
3034 ParseRustVariantPart(die, parent_die, class_clang_type,
3035 default_accessibility, layout_info);
3036 }
3037 break;
3038
3039 case DW_TAG_variable: {
3040 const MemberAttributes attrs(die, parent_die, module_sp);
3041 CreateStaticMemberVariable(die, attrs, class_clang_type);
3042 } break;
3043 case DW_TAG_member:
3044 ParseSingleMember(die, parent_die, class_clang_type,
3045 default_accessibility, layout_info, last_field_info);
3046 break;
3047
3048 case DW_TAG_subprogram:
3049 // Let the type parsing code handle this one for us.
3050 member_function_dies.push_back(die);
3051 break;
3052
3053 case DW_TAG_inheritance:
3054 ParseInheritance(die, parent_die, class_clang_type, default_accessibility,
3055 module_sp, base_classes, layout_info);
3056 break;
3057
3058 default:
3059 if (llvm::dwarf::isType(tag))
3060 contained_type_dies.push_back(die);
3061 break;
3062 }
3063 }
3064
3065 return true;
3066}
3067
3069 clang::DeclContext *containing_decl_ctx, const DWARFDIE &parent_die,
3070 bool &is_static, bool &is_variadic, bool &has_template_params,
3071 std::vector<CompilerType> &function_param_types,
3072 std::vector<clang::ParmVarDecl *> &function_param_decls,
3073 unsigned &type_quals) {
3074 if (!parent_die)
3075 return 0;
3076
3077 size_t arg_idx = 0;
3078 for (DWARFDIE die : parent_die.children()) {
3079 const dw_tag_t tag = die.Tag();
3080 switch (tag) {
3081 case DW_TAG_formal_parameter: {
3082 DWARFAttributes attributes = die.GetAttributes();
3083 if (attributes.Size() == 0) {
3084 arg_idx++;
3085 break;
3086 }
3087
3088 const char *name = nullptr;
3089 DWARFFormValue param_type_die_form;
3090 bool is_artificial = false;
3091 // one of None, Auto, Register, Extern, Static, PrivateExtern
3092
3093 clang::StorageClass storage = clang::SC_None;
3094 uint32_t i;
3095 for (i = 0; i < attributes.Size(); ++i) {
3096 const dw_attr_t attr = attributes.AttributeAtIndex(i);
3097 DWARFFormValue form_value;
3098 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
3099 switch (attr) {
3100 case DW_AT_name:
3101 name = form_value.AsCString();
3102 break;
3103 case DW_AT_type:
3104 param_type_die_form = form_value;
3105 break;
3106 case DW_AT_artificial:
3107 is_artificial = form_value.Boolean();
3108 break;
3109 case DW_AT_location:
3110 case DW_AT_const_value:
3111 case DW_AT_default_value:
3112 case DW_AT_description:
3113 case DW_AT_endianity:
3114 case DW_AT_is_optional:
3115 case DW_AT_segment:
3116 case DW_AT_variable_parameter:
3117 default:
3118 case DW_AT_abstract_origin:
3119 case DW_AT_sibling:
3120 break;
3121 }
3122 }
3123 }
3124
3125 bool skip = false;
3126 if (is_artificial) {
3127 // In order to determine if a C++ member function is "const" we
3128 // have to look at the const-ness of "this"...
3129 if (arg_idx == 0 &&
3130 DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()) &&
3131 // Often times compilers omit the "this" name for the
3132 // specification DIEs, so we can't rely upon the name being in
3133 // the formal parameter DIE...
3134 (name == nullptr || ::strcmp(name, "this") == 0)) {
3135 Type *this_type = die.ResolveTypeUID(param_type_die_form.Reference());
3136 if (this_type) {
3137 uint32_t encoding_mask = this_type->GetEncodingMask();
3138 if (encoding_mask & Type::eEncodingIsPointerUID) {
3139 is_static = false;
3140
3141 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
3142 type_quals |= clang::Qualifiers::Const;
3143 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
3144 type_quals |= clang::Qualifiers::Volatile;
3145 }
3146 }
3147 }
3148 skip = true;
3149 }
3150
3151 if (!skip) {
3152 Type *type = die.ResolveTypeUID(param_type_die_form.Reference());
3153 if (type) {
3154 function_param_types.push_back(type->GetForwardCompilerType());
3155
3156 clang::ParmVarDecl *param_var_decl = m_ast.CreateParameterDeclaration(
3157 containing_decl_ctx, GetOwningClangModule(die), name,
3158 type->GetForwardCompilerType(), storage);
3159 assert(param_var_decl);
3160 function_param_decls.push_back(param_var_decl);
3161
3162 m_ast.SetMetadataAsUserID(param_var_decl, die.GetID());
3163 }
3164 }
3165 arg_idx++;
3166 } break;
3167
3168 case DW_TAG_unspecified_parameters:
3169 is_variadic = true;
3170 break;
3171
3172 case DW_TAG_template_type_parameter:
3173 case DW_TAG_template_value_parameter:
3174 case DW_TAG_GNU_template_parameter_pack:
3175 // The one caller of this was never using the template_param_infos, and
3176 // the local variable was taking up a large amount of stack space in
3177 // SymbolFileDWARF::ParseType() so this was removed. If we ever need the
3178 // template params back, we can add them back.
3179 // ParseTemplateDIE (dwarf_cu, die, template_param_infos);
3180 has_template_params = true;
3181 break;
3182
3183 default:
3184 break;
3185 }
3186 }
3187 return arg_idx;
3188}
3189
3191 if (!die)
3192 return nullptr;
3193
3194 switch (die.Tag()) {
3195 case DW_TAG_constant:
3196 case DW_TAG_formal_parameter:
3197 case DW_TAG_imported_declaration:
3198 case DW_TAG_imported_module:
3199 break;
3200 case DW_TAG_variable:
3201 // This means 'die' is a C++ static data member.
3202 // We don't want to create decls for such members
3203 // here.
3204 if (auto parent = die.GetParent();
3205 parent.IsValid() && TagIsRecordType(parent.Tag()))
3206 return nullptr;
3207 break;
3208 default:
3209 return nullptr;
3210 }
3211
3212 DIEToDeclMap::iterator cache_pos = m_die_to_decl.find(die.GetDIE());
3213 if (cache_pos != m_die_to_decl.end())
3214 return cache_pos->second;
3215
3216 if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification)) {
3217 clang::Decl *decl = GetClangDeclForDIE(spec_die);
3218 m_die_to_decl[die.GetDIE()] = decl;
3219 return decl;
3220 }
3221
3222 if (DWARFDIE abstract_origin_die =
3223 die.GetReferencedDIE(DW_AT_abstract_origin)) {
3224 clang::Decl *decl = GetClangDeclForDIE(abstract_origin_die);
3225 m_die_to_decl[die.GetDIE()] = decl;
3226 return decl;
3227 }
3228
3229 clang::Decl *decl = nullptr;
3230 switch (die.Tag()) {
3231 case DW_TAG_variable:
3232 case DW_TAG_constant:
3233 case DW_TAG_formal_parameter: {
3235 Type *type = GetTypeForDIE(die);
3236 if (dwarf && type) {
3237 const char *name = die.GetName();
3238 clang::DeclContext *decl_context =
3240 dwarf->GetDeclContextContainingUID(die.GetID()));
3242 decl_context, GetOwningClangModule(die), name,
3244 }
3245 break;
3246 }
3247 case DW_TAG_imported_declaration: {
3249 DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import);
3250 if (imported_uid) {
3251 CompilerDecl imported_decl = SymbolFileDWARF::GetDecl(imported_uid);
3252 if (imported_decl) {
3253 clang::DeclContext *decl_context =
3255 dwarf->GetDeclContextContainingUID(die.GetID()));
3256 if (clang::NamedDecl *clang_imported_decl =
3257 llvm::dyn_cast<clang::NamedDecl>(
3258 (clang::Decl *)imported_decl.GetOpaqueDecl()))
3260 decl_context, OptionalClangModuleID(), clang_imported_decl);
3261 }
3262 }
3263 break;
3264 }
3265 case DW_TAG_imported_module: {
3267 DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import);
3268
3269 if (imported_uid) {
3270 CompilerDeclContext imported_decl_ctx =
3271 SymbolFileDWARF::GetDeclContext(imported_uid);
3272 if (imported_decl_ctx) {
3273 clang::DeclContext *decl_context =
3275 dwarf->GetDeclContextContainingUID(die.GetID()));
3276 if (clang::NamespaceDecl *ns_decl =
3278 imported_decl_ctx))
3280 decl_context, OptionalClangModuleID(), ns_decl);
3281 }
3282 }
3283 break;
3284 }
3285 default:
3286 break;
3287 }
3288
3289 m_die_to_decl[die.GetDIE()] = decl;
3290
3291 return decl;
3292}
3293
3294clang::DeclContext *
3296 if (die) {
3297 clang::DeclContext *decl_ctx = GetCachedClangDeclContextForDIE(die);
3298 if (decl_ctx)
3299 return decl_ctx;
3300
3301 bool try_parsing_type = true;
3302 switch (die.Tag()) {
3303 case DW_TAG_compile_unit:
3304 case DW_TAG_partial_unit:
3305 decl_ctx = m_ast.GetTranslationUnitDecl();
3306 try_parsing_type = false;
3307 break;
3308
3309 case DW_TAG_namespace:
3310 decl_ctx = ResolveNamespaceDIE(die);
3311 try_parsing_type = false;
3312 break;
3313
3314 case DW_TAG_imported_declaration:
3315 decl_ctx = ResolveImportedDeclarationDIE(die);
3316 try_parsing_type = false;
3317 break;
3318
3319 case DW_TAG_lexical_block:
3320 decl_ctx = GetDeclContextForBlock(die);
3321 try_parsing_type = false;
3322 break;
3323
3324 default:
3325 break;
3326 }
3327
3328 if (decl_ctx == nullptr && try_parsing_type) {
3329 Type *type = die.GetDWARF()->ResolveType(die);
3330 if (type)
3331 decl_ctx = GetCachedClangDeclContextForDIE(die);
3332 }
3333
3334 if (decl_ctx) {
3335 LinkDeclContextToDIE(decl_ctx, die);
3336 return decl_ctx;
3337 }
3338 }
3339 return nullptr;
3340}
3341
3344 if (!die.IsValid())
3345 return {};
3346
3347 for (DWARFDIE parent = die.GetParent(); parent.IsValid();
3348 parent = parent.GetParent()) {
3349 const dw_tag_t tag = parent.Tag();
3350 if (tag == DW_TAG_module) {
3351 DWARFDIE module_die = parent;
3352 auto it = m_die_to_module.find(module_die.GetDIE());
3353 if (it != m_die_to_module.end())
3354 return it->second;
3355 const char *name =
3356 module_die.GetAttributeValueAsString(DW_AT_name, nullptr);
3357 if (!name)
3358 return {};
3359
3362 m_die_to_module.insert({module_die.GetDIE(), id});
3363 return id;
3364 }
3365 }
3366 return {};
3367}
3368
3369static bool IsSubroutine(const DWARFDIE &die) {
3370 switch (die.Tag()) {
3371 case DW_TAG_subprogram:
3372 case DW_TAG_inlined_subroutine:
3373 return true;
3374 default:
3375 return false;
3376 }
3377}
3378
3380 for (DWARFDIE candidate = die; candidate; candidate = candidate.GetParent()) {
3381 if (IsSubroutine(candidate)) {
3382 if (candidate.GetReferencedDIE(DW_AT_abstract_origin)) {
3383 return candidate;
3384 } else {
3385 return DWARFDIE();
3386 }
3387 }
3388 }
3389 assert(0 && "Shouldn't call GetContainingFunctionWithAbstractOrigin on "
3390 "something not in a function");
3391 return DWARFDIE();
3392}
3393
3395 for (DWARFDIE candidate : context.children()) {
3396 if (candidate.GetReferencedDIE(DW_AT_abstract_origin)) {
3397 return candidate;
3398 }
3399 }
3400 return DWARFDIE();
3401}
3402
3404 const DWARFDIE &function) {
3405 assert(IsSubroutine(function));
3406 for (DWARFDIE context = block; context != function.GetParent();
3407 context = context.GetParent()) {
3408 assert(!IsSubroutine(context) || context == function);
3409 if (DWARFDIE child = FindAnyChildWithAbstractOrigin(context)) {
3410 return child;
3411 }
3412 }
3413 return DWARFDIE();
3414}
3415
3416clang::DeclContext *
3418 assert(die.Tag() == DW_TAG_lexical_block);
3419 DWARFDIE containing_function_with_abstract_origin =
3421 if (!containing_function_with_abstract_origin) {
3422 return (clang::DeclContext *)ResolveBlockDIE(die);
3423 }
3425 die, containing_function_with_abstract_origin);
3426 CompilerDeclContext decl_context =
3428 return (clang::DeclContext *)decl_context.GetOpaqueDeclContext();
3429}
3430
3431clang::BlockDecl *DWARFASTParserClang::ResolveBlockDIE(const DWARFDIE &die) {
3432 if (die && die.Tag() == DW_TAG_lexical_block) {
3433 clang::BlockDecl *decl =
3434 llvm::cast_or_null<clang::BlockDecl>(m_die_to_decl_ctx[die.GetDIE()]);
3435
3436 if (!decl) {
3437 DWARFDIE decl_context_die;
3438 clang::DeclContext *decl_context =
3439 GetClangDeclContextContainingDIE(die, &decl_context_die);
3440 decl =
3442
3443 if (decl)
3444 LinkDeclContextToDIE((clang::DeclContext *)decl, die);
3445 }
3446
3447 return decl;
3448 }
3449 return nullptr;
3450}
3451
3452clang::NamespaceDecl *
3454 if (die && die.Tag() == DW_TAG_namespace) {
3455 // See if we already parsed this namespace DIE and associated it with a
3456 // uniqued namespace declaration
3457 clang::NamespaceDecl *namespace_decl =
3458 static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die.GetDIE()]);
3459 if (namespace_decl)
3460 return namespace_decl;
3461 else {
3462 const char *namespace_name = die.GetName();
3463 clang::DeclContext *containing_decl_ctx =
3465 bool is_inline =
3466 die.GetAttributeValueAsUnsigned(DW_AT_export_symbols, 0) != 0;
3467
3468 namespace_decl = m_ast.GetUniqueNamespaceDeclaration(
3469 namespace_name, containing_decl_ctx, GetOwningClangModule(die),
3470 is_inline);
3471
3472 if (namespace_decl)
3473 LinkDeclContextToDIE((clang::DeclContext *)namespace_decl, die);
3474 return namespace_decl;
3475 }
3476 }
3477 return nullptr;
3478}
3479
3480clang::NamespaceDecl *
3482 assert(die && die.Tag() == DW_TAG_imported_declaration);
3483
3484 // See if we cached a NamespaceDecl for this imported declaration
3485 // already
3486 auto it = m_die_to_decl_ctx.find(die.GetDIE());
3487 if (it != m_die_to_decl_ctx.end())
3488 return static_cast<clang::NamespaceDecl *>(it->getSecond());
3489
3490 clang::NamespaceDecl *namespace_decl = nullptr;
3491
3492 const DWARFDIE imported_uid =
3493 die.GetAttributeValueAsReferenceDIE(DW_AT_import);
3494 if (!imported_uid)
3495 return nullptr;
3496
3497 switch (imported_uid.Tag()) {
3498 case DW_TAG_imported_declaration:
3499 namespace_decl = ResolveImportedDeclarationDIE(imported_uid);
3500 break;
3501 case DW_TAG_namespace:
3502 namespace_decl = ResolveNamespaceDIE(imported_uid);
3503 break;
3504 default:
3505 return nullptr;
3506 }
3507
3508 if (!namespace_decl)
3509 return nullptr;
3510
3511 LinkDeclContextToDIE(namespace_decl, die);
3512
3513 return namespace_decl;
3514}
3515
3517 const DWARFDIE &die, DWARFDIE *decl_ctx_die_copy) {
3519
3520 DWARFDIE decl_ctx_die = dwarf->GetDeclContextDIEContainingDIE(die);
3521
3522 if (decl_ctx_die_copy)
3523 *decl_ctx_die_copy = decl_ctx_die;
3524
3525 if (decl_ctx_die) {
3526 clang::DeclContext *clang_decl_ctx =
3527 GetClangDeclContextForDIE(decl_ctx_die);
3528 if (clang_decl_ctx)
3529 return clang_decl_ctx;
3530 }
3532}
3533
3534clang::DeclContext *
3536 if (die) {
3537 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die.GetDIE());
3538 if (pos != m_die_to_decl_ctx.end())
3539 return pos->second;
3540 }
3541 return nullptr;
3542}
3543
3544void DWARFASTParserClang::LinkDeclContextToDIE(clang::DeclContext *decl_ctx,
3545 const DWARFDIE &die) {
3546 m_die_to_decl_ctx[die.GetDIE()] = decl_ctx;
3547 // There can be many DIEs for a single decl context
3548 // m_decl_ctx_to_die[decl_ctx].insert(die.GetDIE());
3549 m_decl_ctx_to_die.insert(std::make_pair(decl_ctx, die));
3550}
3551
3553 const DWARFDIE &src_class_die, const DWARFDIE &dst_class_die,
3554 lldb_private::Type *class_type, std::vector<DWARFDIE> &failures) {
3555 if (!class_type || !src_class_die || !dst_class_die)
3556 return false;
3557 if (src_class_die.Tag() != dst_class_die.Tag())
3558 return false;
3559
3560 // We need to complete the class type so we can get all of the method types
3561 // parsed so we can then unique those types to their equivalent counterparts
3562 // in "dst_cu" and "dst_class_die"
3563 class_type->GetFullCompilerType();
3564
3565 auto gather = [](DWARFDIE die, UniqueCStringMap<DWARFDIE> &map,
3566 UniqueCStringMap<DWARFDIE> &map_artificial) {
3567 if (die.Tag() != DW_TAG_subprogram)
3568 return;
3569 // Make sure this is a declaration and not a concrete instance by looking
3570 // for DW_AT_declaration set to 1. Sometimes concrete function instances are
3571 // placed inside the class definitions and shouldn't be included in the list
3572 // of things that are tracking here.
3573 if (die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0) != 1)
3574 return;
3575
3576 if (const char *name = die.GetMangledName()) {
3577 ConstString const_name(name);
3578 if (die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0))
3579 map_artificial.Append(const_name, die);
3580 else
3581 map.Append(const_name, die);
3582 }
3583 };
3584
3585 UniqueCStringMap<DWARFDIE> src_name_to_die;
3586 UniqueCStringMap<DWARFDIE> dst_name_to_die;
3587 UniqueCStringMap<DWARFDIE> src_name_to_die_artificial;
3588 UniqueCStringMap<DWARFDIE> dst_name_to_die_artificial;
3589 for (DWARFDIE src_die = src_class_die.GetFirstChild(); src_die.IsValid();
3590 src_die = src_die.GetSibling()) {
3591 gather(src_die, src_name_to_die, src_name_to_die_artificial);
3592 }
3593 for (DWARFDIE dst_die = dst_class_die.GetFirstChild(); dst_die.IsValid();
3594 dst_die = dst_die.GetSibling()) {
3595 gather(dst_die, dst_name_to_die, dst_name_to_die_artificial);
3596 }
3597 const uint32_t src_size = src_name_to_die.GetSize();
3598 const uint32_t dst_size = dst_name_to_die.GetSize();
3599
3600 // Is everything kosher so we can go through the members at top speed?
3601 bool fast_path = true;
3602
3603 if (src_size != dst_size)
3604 fast_path = false;
3605
3606 uint32_t idx;
3607
3608 if (fast_path) {
3609 for (idx = 0; idx < src_size; ++idx) {
3610 DWARFDIE src_die = src_name_to_die.GetValueAtIndexUnchecked(idx);
3611 DWARFDIE dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
3612
3613 if (src_die.Tag() != dst_die.Tag())
3614 fast_path = false;
3615
3616 const char *src_name = src_die.GetMangledName();
3617 const char *dst_name = dst_die.GetMangledName();
3618
3619 // Make sure the names match
3620 if (src_name == dst_name || (strcmp(src_name, dst_name) == 0))
3621 continue;
3622
3623 fast_path = false;
3624 }
3625 }
3626
3627 DWARFASTParserClang *src_dwarf_ast_parser =
3628 static_cast<DWARFASTParserClang *>(
3629 SymbolFileDWARF::GetDWARFParser(*src_class_die.GetCU()));
3630 DWARFASTParserClang *dst_dwarf_ast_parser =
3631 static_cast<DWARFASTParserClang *>(
3632 SymbolFileDWARF::GetDWARFParser(*dst_class_die.GetCU()));
3633 auto link = [&](DWARFDIE src, DWARFDIE dst) {
3634 auto &die_to_type = dst_class_die.GetDWARF()->GetDIEToType();
3635 clang::DeclContext *dst_decl_ctx =
3636 dst_dwarf_ast_parser->m_die_to_decl_ctx[dst.GetDIE()];
3637 if (dst_decl_ctx)
3638 src_dwarf_ast_parser->LinkDeclContextToDIE(dst_decl_ctx, src);
3639
3640 if (Type *src_child_type = die_to_type.lookup(src.GetDIE()))
3641 die_to_type[dst.GetDIE()] = src_child_type;
3642 };
3643
3644 // Now do the work of linking the DeclContexts and Types.
3645 if (fast_path) {
3646 // We can do this quickly. Just run across the tables index-for-index
3647 // since we know each node has matching names and tags.
3648 for (idx = 0; idx < src_size; ++idx) {
3649 link(src_name_to_die.GetValueAtIndexUnchecked(idx),
3650 dst_name_to_die.GetValueAtIndexUnchecked(idx));
3651 }
3652 } else {
3653 // We must do this slowly. For each member of the destination, look up a
3654 // member in the source with the same name, check its tag, and unique them
3655 // if everything matches up. Report failures.
3656
3657 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty()) {
3658 src_name_to_die.Sort();
3659
3660 for (idx = 0; idx < dst_size; ++idx) {
3661 ConstString dst_name = dst_name_to_die.GetCStringAtIndex(idx);
3662 DWARFDIE dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
3663 DWARFDIE src_die = src_name_to_die.Find(dst_name, DWARFDIE());
3664
3665 if (src_die && (src_die.Tag() == dst_die.Tag()))
3666 link(src_die, dst_die);
3667 else
3668 failures.push_back(dst_die);
3669 }
3670 }
3671 }
3672
3673 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize();
3674 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize();
3675
3676 if (src_size_artificial && dst_size_artificial) {
3677 dst_name_to_die_artificial.Sort();
3678
3679 for (idx = 0; idx < src_size_artificial; ++idx) {
3680 ConstString src_name_artificial =
3681 src_name_to_die_artificial.GetCStringAtIndex(idx);
3682 DWARFDIE src_die =
3683 src_name_to_die_artificial.GetValueAtIndexUnchecked(idx);
3684 DWARFDIE dst_die =
3685 dst_name_to_die_artificial.Find(src_name_artificial, DWARFDIE());
3686
3687 // Both classes have the artificial types, link them
3688 if (dst_die)
3689 link(src_die, dst_die);
3690 }
3691 }
3692
3693 if (dst_size_artificial) {
3694 for (idx = 0; idx < dst_size_artificial; ++idx) {
3695 failures.push_back(
3696 dst_name_to_die_artificial.GetValueAtIndexUnchecked(idx));
3697 }
3698 }
3699
3700 return !failures.empty();
3701}
3702
3704 FieldInfo const &last_field_info, uint64_t last_field_end,
3705 FieldInfo const &this_field_info,
3706 lldb_private::ClangASTImporter::LayoutInfo const &layout_info) const {
3707 // If we have a gap between the last_field_end and the current
3708 // field we have an unnamed bit-field.
3709 if (this_field_info.bit_offset <= last_field_end)
3710 return false;
3711
3712 // If we have a base class, we assume there is no unnamed
3713 // bit-field if either of the following is true:
3714 // (a) this is the first field since the gap can be
3715 // attributed to the members from the base class.
3716 // FIXME: This assumption is not correct if the first field of
3717 // the derived class is indeed an unnamed bit-field. We currently
3718 // do not have the machinary to track the offset of the last field
3719 // of classes we have seen before, so we are not handling this case.
3720 // (b) Or, the first member of the derived class was a vtable pointer.
3721 // In this case we don't want to create an unnamed bitfield either
3722 // since those will be inserted by clang later.
3723 const bool have_base = layout_info.base_offsets.size() != 0;
3724 const bool this_is_first_field =
3725 last_field_info.bit_offset == 0 && last_field_info.bit_size == 0;
3726 const bool first_field_is_vptr =
3727 last_field_info.bit_offset == 0 && last_field_info.IsArtificial();
3728
3729 if (have_base && (this_is_first_field || first_field_is_vptr))
3730 return false;
3731
3732 return true;
3733}
3734
3736 ClangASTImporter::LayoutInfo &class_layout_info,
3737 const CompilerType &class_clang_type, const FieldInfo &previous_field,
3738 const FieldInfo &current_field) {
3739 // TODO: get this value from target
3740 const uint64_t word_width = 32;
3741 uint64_t last_field_end = previous_field.GetEffectiveFieldEnd();
3742
3743 if (!previous_field.IsBitfield()) {
3744 // The last field was not a bit-field...
3745 // but if it did take up the entire word then we need to extend
3746 // last_field_end so the bit-field does not step into the last
3747 // fields padding.
3748 if (last_field_end != 0 && ((last_field_end % word_width) != 0))
3749 last_field_end += word_width - (last_field_end % word_width);
3750 }
3751
3752 // Nothing to be done.
3753 if (!ShouldCreateUnnamedBitfield(previous_field, last_field_end,
3754 current_field, class_layout_info))
3755 return;
3756
3757 // Place the unnamed bitfield into the gap between the previous field's end
3758 // and the current field's start.
3759 const uint64_t unnamed_bit_size = current_field.bit_offset - last_field_end;
3760 const uint64_t unnamed_bit_offset = last_field_end;
3761
3762 clang::FieldDecl *unnamed_bitfield_decl =
3764 class_clang_type, llvm::StringRef(),
3766 lldb::AccessType::eAccessPublic, unnamed_bit_size);
3767
3768 class_layout_info.field_offsets.insert(
3769 std::make_pair(unnamed_bitfield_decl, unnamed_bit_offset));
3770}
3771
3773 DWARFDIE &die, const DWARFDIE &parent_die,
3774 const CompilerType &class_clang_type,
3775 const lldb::AccessType default_accesibility,
3776 ClangASTImporter::LayoutInfo &layout_info) {
3777 assert(die.Tag() == llvm::dwarf::DW_TAG_variant_part);
3778 assert(SymbolFileDWARF::GetLanguage(*die.GetCU()) ==
3779 LanguageType::eLanguageTypeRust);
3780
3781 ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule();
3782
3783 VariantPart variants(die, parent_die, module_sp);
3784
3785 auto discriminant_type =
3786 die.ResolveTypeUID(variants.discriminant().type_ref.Reference());
3787
3788 auto decl_context = m_ast.GetDeclContextForType(class_clang_type);
3789
3790 auto inner_holder = m_ast.CreateRecordType(
3792 std::string(
3793 llvm::formatv("{0}$Inner", class_clang_type.GetTypeName(false))),
3794 llvm::to_underlying(clang::TagTypeKind::Union), lldb::eLanguageTypeRust);
3796 m_ast.SetIsPacked(inner_holder);
3797
3798 for (auto member : variants.members()) {
3799
3800 auto has_discriminant = !member.IsDefault();
3801
3802 auto member_type = die.ResolveTypeUID(member.type_ref.Reference());
3803
3804 auto field_type = m_ast.CreateRecordType(
3807 std::string(llvm::formatv("{0}$Variant", member.GetName())),
3808 llvm::to_underlying(clang::TagTypeKind::Struct),
3810
3812 auto offset = member.byte_offset;
3813
3814 if (has_discriminant) {
3816 field_type, "$discr$", discriminant_type->GetFullCompilerType(),
3817 lldb::eAccessPublic, variants.discriminant().byte_offset);
3818 offset += discriminant_type->GetByteSize(nullptr).value_or(0);
3819 }
3820
3821 m_ast.AddFieldToRecordType(field_type, "value",
3822 member_type->GetFullCompilerType(),
3823 lldb::eAccessPublic, offset * 8);
3824
3826
3827 auto name = has_discriminant
3828 ? llvm::formatv("$variant${0}", member.discr_value.value())
3829 : std::string("$variant$");
3830
3831 auto variant_decl =
3832 m_ast.AddFieldToRecordType(inner_holder, llvm::StringRef(name),
3833 field_type, default_accesibility, 0);
3834
3835 layout_info.field_offsets.insert({variant_decl, 0});
3836 }
3837
3838 auto inner_field = m_ast.AddFieldToRecordType(class_clang_type,
3839 llvm::StringRef("$variants$"),
3840 inner_holder, eAccessPublic, 0);
3841
3843
3844 layout_info.field_offsets.insert({inner_field, 0});
3845}
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...
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.
bool CompleteRecordType(const lldb_private::plugin::dwarf::DWARFDIE &die, const lldb_private::CompilerType &clang_type)
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)
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 ParseChildParameters(clang::DeclContext *containing_decl_ctx, const lldb_private::plugin::dwarf::DWARFDIE &parent_die, 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)
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)
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)
virtual llvm::DenseMap< const DWARFDebugInfoEntry *, Type * > & GetDIEToType()
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