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