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