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