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