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