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
1752 const SymbolContext &sc, const DWARFDIE &die,
1753 const ParsedDWARFTypeAttributes &attrs) {
1754 CompilerType clang_type;
1755 const dw_tag_t tag = die.Tag();
1757 LanguageType cu_language = SymbolFileDWARF::GetLanguage(*die.GetCU());
1759
1760 ConstString unique_typename(attrs.name);
1761 Declaration unique_decl(attrs.decl);
1762 uint64_t byte_size = attrs.byte_size.value_or(0);
1763
1764 if (attrs.name) {
1765 GetUniqueTypeNameAndDeclaration(die, cu_language, unique_typename,
1766 unique_decl);
1767 if (log) {
1768 dwarf->GetObjectFile()->GetModule()->LogMessage(
1769 log, "SymbolFileDWARF({0:p}) - {1:x16}: {2} has unique name: {3} ",
1770 static_cast<void *>(this), die.GetID(), DW_TAG_value_to_name(tag),
1771 unique_typename.AsCString(nullptr));
1772 }
1773 if (UniqueDWARFASTType *unique_ast_entry_type =
1774 dwarf->GetUniqueDWARFASTTypeMap().Find(
1775 unique_typename, die, unique_decl, byte_size,
1776 attrs.is_forward_declaration)) {
1777 if (TypeSP type_sp = unique_ast_entry_type->m_type_sp) {
1778 dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get();
1780 GetCachedClangDeclContextForDIE(unique_ast_entry_type->m_die), die);
1781 // If the DIE being parsed in this function is a definition and the
1782 // entry in the map is a declaration, then we need to update the entry
1783 // to point to the definition DIE.
1784 if (!attrs.is_forward_declaration &&
1785 unique_ast_entry_type->m_is_forward_declaration) {
1786 unique_ast_entry_type->UpdateToDefDIE(die, unique_decl, byte_size);
1787 clang_type = type_sp->GetForwardCompilerType();
1788
1789 CompilerType compiler_type_no_qualifiers =
1791 dwarf->GetForwardDeclCompilerTypeToDIE().insert_or_assign(
1792 compiler_type_no_qualifiers.GetOpaqueQualType(),
1793 *die.GetDIERef());
1794 }
1795 return type_sp;
1796 }
1797 }
1798 }
1799
1800 if ((attrs.class_language == eLanguageTypeObjC ||
1802 !attrs.is_complete_objc_class) {
1803 // We have a valid eSymbolTypeObjCClass class symbol whose name
1804 // matches the current objective C class that we are trying to find
1805 // and this DIE isn't the complete definition (we checked
1806 // is_complete_objc_class above and know it is false), so the real
1807 // definition is in here somewhere
1808 TypeSP type_sp =
1809 dwarf->FindCompleteObjCDefinitionTypeForDIE(die, attrs.name, true);
1810
1811 if (!type_sp) {
1812 SymbolFileDWARFDebugMap *debug_map_symfile = dwarf->GetDebugMapSymfile();
1813 if (debug_map_symfile) {
1814 // We weren't able to find a full declaration in this DWARF,
1815 // see if we have a declaration anywhere else...
1816 type_sp = debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE(
1817 die, attrs.name, true);
1818 }
1819 }
1820
1821 if (type_sp) {
1822 if (log) {
1823 dwarf->GetObjectFile()->GetModule()->LogMessage(
1824 log,
1825 "SymbolFileDWARF({0:p}) - {1:x16}: {2} ({3}) type \"{4}\" is an "
1826 "incomplete objc type, complete type is {5:x8}",
1827 static_cast<void *>(this), die.GetID(), DW_TAG_value_to_name(tag),
1828 tag, attrs.name.GetCString(), type_sp->GetID());
1829 }
1830 return type_sp;
1831 }
1832 }
1833
1834 if (attrs.is_forward_declaration) {
1835 // See if the type comes from a Clang module and if so, track down
1836 // that type.
1837 TypeSP type_sp = ParseTypeFromClangModule(sc, die, log);
1838 if (type_sp)
1839 return type_sp;
1840 }
1841
1842 int tag_decl_kind = -1;
1843 if (tag == DW_TAG_structure_type)
1844 tag_decl_kind = llvm::to_underlying(clang::TagTypeKind::Struct);
1845 else if (tag == DW_TAG_union_type)
1846 tag_decl_kind = llvm::to_underlying(clang::TagTypeKind::Union);
1847 else if (tag == DW_TAG_class_type)
1848 tag_decl_kind = llvm::to_underlying(clang::TagTypeKind::Class);
1849 else
1850 assert(false && "Unexpected tag kind.");
1851
1852 clang::DeclContext *containing_decl_ctx =
1854
1856 containing_decl_ctx, die,
1857 attrs.name.GetCString());
1858
1859 ClangASTMetadata metadata;
1860 metadata.SetUserID(die.GetID());
1861 if (!attrs.is_forward_declaration)
1862 metadata.SetIsDynamicCXXType(dwarf->ClassOrStructIsVirtual(die));
1863
1864 TypeSystemClang::TemplateParameterInfos template_param_infos;
1865 if (ParseTemplateParameterInfos(die, template_param_infos)) {
1866 clang::ClassTemplateDecl *class_template_decl =
1867 m_ast.ParseClassTemplateDecl(
1868 containing_decl_ctx, GetOwningClangModule(die),
1869 attrs.name.GetCString(), tag_decl_kind, template_param_infos);
1870 if (!class_template_decl) {
1871 if (log) {
1872 dwarf->GetObjectFile()->GetModule()->LogMessage(
1873 log,
1874 "SymbolFileDWARF({0:p}) - {1:x16}: {2} ({3}) type \"{4}\" "
1875 "clang::ClassTemplateDecl failed to return a decl.",
1876 static_cast<void *>(this), die.GetID(), DW_TAG_value_to_name(tag),
1877 tag, attrs.name.GetCString());
1878 }
1879 return TypeSP();
1880 }
1881
1882 clang::ClassTemplateSpecializationDecl *class_specialization_decl =
1883 m_ast.CreateClassTemplateSpecializationDecl(
1884 containing_decl_ctx, GetOwningClangModule(die), class_template_decl,
1885 tag_decl_kind, template_param_infos);
1886 if (!class_specialization_decl) {
1887 if (log) {
1888 dwarf->GetObjectFile()->GetModule()->LogMessage(
1889 log,
1890 "SymbolFileDWARF({0:p}) - Failed to create specialization for "
1891 "clang::ClassTemplateDecl({1}, {2:p}).",
1892 this, llvm::StringRef(attrs.name), class_template_decl);
1893 }
1894 return TypeSP();
1895 }
1896
1897 clang_type =
1898 m_ast.CreateClassTemplateSpecializationType(class_specialization_decl);
1899
1900 m_ast.SetMetadata(class_template_decl, metadata);
1901 m_ast.SetMetadata(class_specialization_decl, metadata);
1902 }
1903
1904 if (!clang_type) {
1905 clang_type = m_ast.CreateRecordType(
1906 containing_decl_ctx, GetOwningClangModule(die), attrs.name.GetCString(),
1907 tag_decl_kind, attrs.class_language, metadata, attrs.exports_symbols);
1908 }
1909
1910 TypeSP type_sp = dwarf->MakeType(
1911 die.GetID(), attrs.name, attrs.byte_size, nullptr, LLDB_INVALID_UID,
1912 Type::eEncodingIsUID, &attrs.decl, clang_type,
1915
1916 // Store a forward declaration to this class type in case any
1917 // parameters in any class methods need it for the clang types for
1918 // function prototypes.
1919 clang::DeclContext *type_decl_ctx =
1921 LinkDeclContextToDIE(type_decl_ctx, die);
1922
1923 // UniqueDWARFASTType is large, so don't create a local variables on the
1924 // stack, put it on the heap. This function is often called recursively and
1925 // clang isn't good at sharing the stack space for variables in different
1926 // blocks.
1927 auto unique_ast_entry_up = std::make_unique<UniqueDWARFASTType>();
1928 // Add our type to the unique type map so we don't end up creating many
1929 // copies of the same type over and over in the ASTContext for our
1930 // module
1931 unique_ast_entry_up->m_type_sp = type_sp;
1932 unique_ast_entry_up->m_die = die;
1933 unique_ast_entry_up->m_declaration = unique_decl;
1934 unique_ast_entry_up->m_byte_size = byte_size;
1935 unique_ast_entry_up->m_is_forward_declaration = attrs.is_forward_declaration;
1936 dwarf->GetUniqueDWARFASTTypeMap().Insert(unique_typename,
1937 *unique_ast_entry_up);
1938
1939 // Leave this as a forward declaration until we need to know the
1940 // details of the type. lldb_private::Type will automatically call
1941 // the SymbolFile virtual function
1942 // "SymbolFileDWARF::CompleteType(Type *)" When the definition
1943 // needs to be defined.
1944 bool inserted =
1945 dwarf->GetForwardDeclCompilerTypeToDIE()
1946 .try_emplace(
1947 ClangUtil::RemoveFastQualifiers(clang_type).GetOpaqueQualType(),
1948 *die.GetDIERef())
1949 .second;
1950 assert(inserted && "Type already in the forward declaration map!");
1951 (void)inserted;
1952 m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), true);
1953
1954 // If we made a clang type, set the trivial abi if applicable: We only
1955 // do this for pass by value - which implies the Trivial ABI. There
1956 // isn't a way to assert that something that would normally be pass by
1957 // value is pass by reference, so we ignore that attribute if set.
1958 if (attrs.calling_convention == llvm::dwarf::DW_CC_pass_by_value) {
1959 clang::CXXRecordDecl *record_decl =
1960 m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType());
1961 if (record_decl && record_decl->getDefinition()) {
1962 record_decl->setHasTrivialSpecialMemberForCall();
1963 }
1964 }
1965
1966 if (attrs.calling_convention == llvm::dwarf::DW_CC_pass_by_reference) {
1967 clang::CXXRecordDecl *record_decl =
1968 m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType());
1969 if (record_decl)
1970 record_decl->setArgPassingRestrictions(
1971 clang::RecordArgPassingKind::CannotPassInRegs);
1972 }
1973 return type_sp;
1974}
1975
1976// DWARF parsing functions
1977
1979public:
1981 const CompilerType &class_opaque_type, const char *property_name,
1982 const CompilerType &property_opaque_type, // The property type is only
1983 // required if you don't have an
1984 // ivar decl
1985 const char *property_setter_name, const char *property_getter_name,
1986 uint32_t property_attributes, ClangASTMetadata metadata)
1987 : m_class_opaque_type(class_opaque_type), m_property_name(property_name),
1988 m_property_opaque_type(property_opaque_type),
1989 m_property_setter_name(property_setter_name),
1990 m_property_getter_name(property_getter_name),
1991 m_property_attributes(property_attributes), m_metadata(metadata) {}
1992
1999
2000private:
2002 const char *m_property_name;
2008};
2009
2010static std::optional<clang::APValue> MakeAPValue(const clang::ASTContext &ast,
2011 CompilerType clang_type,
2012 uint64_t value) {
2013 std::optional<uint64_t> bit_width =
2014 llvm::expectedToOptional(clang_type.GetBitSize(nullptr));
2015 if (!bit_width)
2016 return std::nullopt;
2017
2018 bool is_signed = false;
2019 const bool is_integral = clang_type.IsIntegerOrEnumerationType(is_signed);
2020
2021 llvm::APSInt apint(*bit_width, !is_signed);
2022 apint = value;
2023
2024 if (is_integral)
2025 return clang::APValue(apint);
2026
2027 // FIXME: we currently support a limited set of floating point types.
2028 // E.g., 16-bit floats are not supported.
2029 if (!clang_type.IsRealFloatingPointType())
2030 return std::nullopt;
2031
2032 return clang::APValue(llvm::APFloat(
2033 ast.getFloatTypeSemantics(ClangUtil::GetQualType(clang_type)), apint));
2034}
2035
2037 const DWARFDIE &die,
2038 TypeSystemClang::TemplateParameterInfos &template_param_infos) {
2039 const dw_tag_t tag = die.Tag();
2040 bool is_template_template_argument = false;
2041
2042 switch (tag) {
2043 case DW_TAG_GNU_template_parameter_pack: {
2044 template_param_infos.SetParameterPack(
2045 std::make_unique<TypeSystemClang::TemplateParameterInfos>());
2046 for (DWARFDIE child_die : die.children()) {
2047 if (!ParseTemplateDIE(child_die, template_param_infos.GetParameterPack()))
2048 return false;
2049 }
2050 if (const char *name = die.GetName()) {
2051 template_param_infos.SetPackName(name);
2052 }
2053 return true;
2054 }
2055 case DW_TAG_GNU_template_template_param:
2056 is_template_template_argument = true;
2057 [[fallthrough]];
2058 case DW_TAG_template_type_parameter:
2059 case DW_TAG_template_value_parameter: {
2060 DWARFAttributes attributes = die.GetAttributes();
2061 if (attributes.Size() == 0)
2062 return true;
2063
2064 const char *name = nullptr;
2065 const char *template_name = nullptr;
2066 CompilerType clang_type;
2067 uint64_t uval64 = 0;
2068 bool uval64_valid = false;
2069 bool is_default_template_arg = false;
2070 DWARFFormValue form_value;
2071 for (size_t i = 0; i < attributes.Size(); ++i) {
2072 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2073
2074 switch (attr) {
2075 case DW_AT_name:
2076 if (attributes.ExtractFormValueAtIndex(i, form_value))
2077 name = form_value.AsCString();
2078 break;
2079
2080 case DW_AT_GNU_template_name:
2081 if (attributes.ExtractFormValueAtIndex(i, form_value))
2082 template_name = form_value.AsCString();
2083 break;
2084
2085 case DW_AT_type:
2086 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2087 Type *lldb_type = die.ResolveTypeUID(form_value.Reference());
2088 if (lldb_type)
2089 clang_type = lldb_type->GetForwardCompilerType();
2090 }
2091 break;
2092
2093 case DW_AT_const_value:
2094 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2095 uval64_valid = true;
2096 uval64 = form_value.Unsigned();
2097 }
2098 break;
2099 case DW_AT_default_value:
2100 if (attributes.ExtractFormValueAtIndex(i, form_value))
2101 is_default_template_arg = form_value.Boolean();
2102 break;
2103 default:
2104 break;
2105 }
2106 }
2107
2108 clang::ASTContext &ast = m_ast.getASTContext();
2109 if (!clang_type)
2110 clang_type = m_ast.GetBasicType(eBasicTypeVoid);
2111
2112 if (!is_template_template_argument) {
2113
2114 if (name && !name[0])
2115 name = nullptr;
2116
2117 if (tag == DW_TAG_template_value_parameter && uval64_valid) {
2118 if (auto value = MakeAPValue(ast, clang_type, uval64)) {
2119 template_param_infos.InsertArg(
2120 name, clang::TemplateArgument(
2121 ast, ClangUtil::GetQualType(clang_type),
2122 std::move(*value), is_default_template_arg));
2123 return true;
2124 }
2125 }
2126
2127 // We get here if this is a type-template parameter or we couldn't create
2128 // a non-type template parameter.
2129 template_param_infos.InsertArg(
2130 name, clang::TemplateArgument(ClangUtil::GetQualType(clang_type),
2131 /*isNullPtr*/ false,
2132 is_default_template_arg));
2133 } else {
2134 auto *tplt_type = m_ast.CreateTemplateTemplateParmDecl(template_name);
2135 template_param_infos.InsertArg(
2136 name, clang::TemplateArgument(clang::TemplateName(tplt_type),
2137 is_default_template_arg));
2138 }
2139 }
2140 return true;
2141
2142 default:
2143 break;
2144 }
2145 return false;
2146}
2147
2149 const DWARFDIE &parent_die,
2150 TypeSystemClang::TemplateParameterInfos &template_param_infos) {
2151
2152 if (!parent_die)
2153 return false;
2154
2155 for (DWARFDIE die : parent_die.children()) {
2156 const dw_tag_t tag = die.Tag();
2157
2158 switch (tag) {
2159 case DW_TAG_template_type_parameter:
2160 case DW_TAG_template_value_parameter:
2161 case DW_TAG_GNU_template_parameter_pack:
2162 case DW_TAG_GNU_template_template_param:
2163 ParseTemplateDIE(die, template_param_infos);
2164 break;
2165
2166 default:
2167 break;
2168 }
2169 }
2170
2171 return !template_param_infos.IsEmpty() ||
2172 template_param_infos.hasParameterPack();
2173}
2174
2176 const CompilerType &clang_type) {
2178
2179 ClangASTImporter::LayoutInfo layout_info;
2180 std::vector<DWARFDIE> contained_type_dies;
2181
2182 if (die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0))
2183 return false; // No definition, cannot complete.
2184
2185 // Start the definition if the type is not being defined already. This can
2186 // happen (e.g.) when adding nested types to a class type -- see
2187 // PrepareContextToReceiveMembers.
2188 if (!clang_type.IsBeingDefined())
2190
2191 std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> bases;
2192 // Parse members and base classes first
2193 std::vector<DWARFDIE> member_function_dies;
2194
2195 DelayedPropertyList delayed_properties;
2196 ParseChildMembers(die, clang_type, bases, member_function_dies,
2197 contained_type_dies, delayed_properties, layout_info);
2198
2199 // Now parse any methods if there were any...
2200 for (const DWARFDIE &die : member_function_dies)
2201 dwarf->ResolveType(die);
2202
2204 ConstString class_name(clang_type.GetTypeName());
2205 if (class_name) {
2206 dwarf->GetObjCMethods(class_name, [&](DWARFDIE method_die) {
2207 method_die.ResolveType();
2209 });
2210
2211 for (DelayedAddObjCClassProperty &property : delayed_properties)
2212 property.Finalize();
2213 }
2214 } else if (Language::LanguageIsObjC(
2216 DW_AT_APPLE_runtime_class, eLanguageTypeUnknown)))) {
2217 /// The forward declaration was C++ but the definition is Objective-C.
2218 /// We currently don't handle such situations. In such cases, keep the
2219 /// forward declaration without a definition to avoid violating Clang AST
2220 /// invariants.
2222 "WARNING: Type completion aborted because forward declaration for "
2223 "'{0}' is C++ while definition is Objective-C.",
2224 llvm::StringRef(die.GetName()));
2225 return {};
2226 }
2227
2228 if (!bases.empty())
2229 m_ast.TransferBaseClasses(clang_type.GetOpaqueQualType(), std::move(bases));
2230
2231 m_ast.AddMethodOverridesForCXXRecordType(clang_type.GetOpaqueQualType());
2234
2235 layout_info.bit_size =
2236 die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8;
2237 layout_info.alignment =
2238 die.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_alignment, 0) * 8;
2239
2240 clang::CXXRecordDecl *record_decl =
2241 m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType());
2242 if (record_decl)
2243 GetClangASTImporter().SetRecordLayout(record_decl, layout_info);
2244
2245 // DWARF doesn't have the attribute, but we can infer the value the same way
2246 // as Clang Sema does. It's required to calculate the size of pointers to
2247 // member functions of this type.
2248 if (m_ast.getASTContext().getTargetInfo().getCXXABI().isMicrosoft()) {
2249 auto IM = record_decl->calculateInheritanceModel();
2250 record_decl->addAttr(clang::MSInheritanceAttr::CreateImplicit(
2251 m_ast.getASTContext(), true, {},
2252 clang::MSInheritanceAttr::Spelling(IM)));
2253 }
2254
2255 // Now parse all contained types inside of the class. We make forward
2256 // declarations to all classes, but we need the CXXRecordDecl to have decls
2257 // for all contained types because we don't get asked for them via the
2258 // external AST support.
2259 for (const DWARFDIE &die : contained_type_dies)
2260 dwarf->ResolveType(die);
2261
2262 return (bool)clang_type;
2263}
2264
2266 lldb_private::Type *type,
2267 const CompilerType &clang_type) {
2268 assert(clang_type.IsEnumerationType());
2269
2271 if (die.HasChildren())
2273 clang_type, clang_type.IsEnumerationIntegerTypeSigned(),
2274 llvm::expectedToOptional(type->GetByteSize(nullptr)).value_or(0),
2275 die);
2276
2278 }
2279 return (bool)clang_type;
2280}
2281
2283 const DWARFDIE &die, lldb_private::Type *type,
2284 const CompilerType &clang_type) {
2286
2287 std::lock_guard<std::recursive_mutex> guard(
2288 dwarf->GetObjectFile()->GetModule()->GetMutex());
2289
2290 // Disable external storage for this type so we don't get anymore
2291 // clang::ExternalASTSource queries for this type.
2292 m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), false);
2293
2294 if (!die)
2295 return false;
2296
2297 const dw_tag_t tag = die.Tag();
2298
2299 assert(clang_type);
2300 switch (tag) {
2301 case DW_TAG_structure_type:
2302 case DW_TAG_union_type:
2303 case DW_TAG_class_type:
2304 CompleteRecordType(die, clang_type);
2305 break;
2306 case DW_TAG_enumeration_type:
2307 CompleteEnumType(die, type, clang_type);
2308 break;
2309 default:
2310 assert(false && "not a forward clang type decl!");
2311 break;
2312 }
2313
2314 // If the type is still not fully defined at this point, it means we weren't
2315 // able to find its definition. We must forcefully complete it to preserve
2316 // clang AST invariants.
2317 if (clang_type.IsBeingDefined()) {
2319 m_ast.SetDeclIsForcefullyCompleted(ClangUtil::GetAsTagDecl(clang_type));
2320 }
2321
2322 return true;
2323}
2324
2326 lldb_private::CompilerDeclContext decl_context) {
2327 auto opaque_decl_ctx =
2328 (clang::DeclContext *)decl_context.GetOpaqueDeclContext();
2329 for (auto it = m_decl_ctx_to_die.find(opaque_decl_ctx);
2330 it != m_decl_ctx_to_die.end() && it->first == opaque_decl_ctx;
2331 it = m_decl_ctx_to_die.erase(it))
2332 for (DWARFDIE decl : it->second.children())
2333 GetClangDeclForDIE(decl);
2334}
2335
2337 clang::Decl *clang_decl = GetClangDeclForDIE(die);
2338 if (clang_decl != nullptr)
2339 return m_ast.GetCompilerDecl(clang_decl);
2340 return {};
2341}
2342
2345 clang::DeclContext *clang_decl_ctx = GetClangDeclContextForDIE(die);
2346 if (clang_decl_ctx)
2347 return m_ast.CreateDeclContext(clang_decl_ctx);
2348 return {};
2349}
2350
2353 clang::DeclContext *clang_decl_ctx =
2355 if (clang_decl_ctx)
2356 return m_ast.CreateDeclContext(clang_decl_ctx);
2357 return {};
2358}
2359
2361 const lldb_private::CompilerType &clang_type, bool is_signed,
2362 uint32_t enumerator_byte_size, const DWARFDIE &parent_die) {
2363 if (!parent_die)
2364 return 0;
2365
2366 size_t enumerators_added = 0;
2367
2368 for (DWARFDIE die : parent_die.children()) {
2369 const dw_tag_t tag = die.Tag();
2370 if (tag != DW_TAG_enumerator)
2371 continue;
2372
2373 DWARFAttributes attributes = die.GetAttributes();
2374 if (attributes.Size() == 0)
2375 continue;
2376
2377 const char *name = nullptr;
2378 std::optional<uint64_t> enum_value;
2379 Declaration decl;
2380
2381 for (size_t i = 0; i < attributes.Size(); ++i) {
2382 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2383 DWARFFormValue form_value;
2384 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2385 switch (attr) {
2386 case DW_AT_const_value:
2387 if (is_signed)
2388 enum_value = form_value.Signed();
2389 else
2390 enum_value = form_value.Unsigned();
2391 break;
2392
2393 case DW_AT_name:
2394 name = form_value.AsCString();
2395 break;
2396
2397 case DW_AT_description:
2398 default:
2399 case DW_AT_decl_file:
2400 decl.SetFile(
2401 attributes.CompileUnitAtIndex(i)->GetFile(form_value.Unsigned()));
2402 break;
2403 case DW_AT_decl_line:
2404 decl.SetLine(form_value.Unsigned());
2405 break;
2406 case DW_AT_decl_column:
2407 decl.SetColumn(form_value.Unsigned());
2408 break;
2409 case DW_AT_sibling:
2410 break;
2411 }
2412 }
2413 }
2414
2415 if (name && name[0] && enum_value) {
2416 m_ast.AddEnumerationValueToEnumerationType(
2417 clang_type, decl, name, *enum_value, enumerator_byte_size * 8);
2418 ++enumerators_added;
2419 }
2420 }
2421 return enumerators_added;
2422}
2423
2426 bool is_variadic = false;
2427 bool has_template_params = false;
2428 std::vector<CompilerType> param_types;
2429 llvm::SmallVector<llvm::StringRef> param_names;
2430 StreamString sstr;
2431
2432 DWARFDeclContext decl_ctx = die.GetDWARFDeclContext();
2433 sstr << decl_ctx.GetQualifiedName();
2434
2435 DWARFDIE decl_ctx_die;
2436 clang::DeclContext *containing_decl_ctx =
2437 GetClangDeclContextContainingDIE(die, &decl_ctx_die);
2438 assert(containing_decl_ctx);
2439
2440 const unsigned cv_quals =
2441 GetCXXMethodCVQuals(die, GetObjectParameter(die, decl_ctx_die));
2442
2443 ParseChildParameters(containing_decl_ctx, die, is_variadic,
2444 has_template_params, param_types, param_names);
2445 sstr << "(";
2446 for (size_t i = 0; i < param_types.size(); i++) {
2447 if (i > 0)
2448 sstr << ", ";
2449 sstr << param_types[i].GetTypeName();
2450 }
2451 if (is_variadic)
2452 sstr << ", ...";
2453 sstr << ")";
2454 if (cv_quals & clang::Qualifiers::Const)
2455 sstr << " const";
2456
2457 return ConstString(sstr.GetString());
2458}
2459
2461 CompileUnit &comp_unit, const DWARFDIE &die, AddressRanges func_ranges) {
2462 llvm::DWARFAddressRangesVector unused_func_ranges;
2463 const char *name = nullptr;
2464 const char *mangled = nullptr;
2465 std::optional<int> decl_file;
2466 std::optional<int> decl_line;
2467 std::optional<int> decl_column;
2468 std::optional<int> call_file;
2469 std::optional<int> call_line;
2470 std::optional<int> call_column;
2471 DWARFExpressionList frame_base;
2472
2473 const dw_tag_t tag = die.Tag();
2474
2475 if (tag != DW_TAG_subprogram)
2476 return nullptr;
2477
2478 if (die.GetDIENamesAndRanges(name, mangled, unused_func_ranges, decl_file,
2479 decl_line, decl_column, call_file, call_line,
2480 call_column, &frame_base)) {
2481 Mangled func_name;
2482 if (mangled && name &&
2484 // The linkage name is present but is not actually a mangled name (e.g.
2485 // wasi-libc renames `main` to its `__main_argc_argv` argv-passing
2486 // wrapper). Display the source name (DW_AT_name) and keep the linkage
2487 // name as the symbol so lookups by either name still resolve.
2488 func_name.SetDemangledName(ConstString(name));
2489 func_name.SetMangledName(ConstString(mangled));
2490 } else if (mangled) {
2491 func_name.SetValue(ConstString(mangled));
2492 } else if ((die.GetParent().Tag() == DW_TAG_compile_unit ||
2493 die.GetParent().Tag() == DW_TAG_partial_unit) &&
2498 name && strcmp(name, "main") != 0) {
2499 // If the mangled name is not present in the DWARF, generate the
2500 // demangled name using the decl context. We skip if the function is
2501 // "main" as its name is never mangled.
2503 // Ensure symbol is preserved (as the mangled name).
2504 func_name.SetMangledName(ConstString(name));
2505 } else {
2506 func_name.SetValue(ConstString(name));
2507 }
2508
2509 FunctionSP func_sp;
2510
2512 // Supply the type _only_ if it has already been parsed
2513 Type *func_type = dwarf->GetDIEToType().lookup(die.GetDIE());
2514
2515 assert(func_type == nullptr || func_type != DIE_IS_BEING_PARSED);
2516
2517 const user_id_t func_user_id = die.GetID();
2518
2519 // The base address of the scope for any of the debugging information
2520 // entries listed above is given by either the DW_AT_low_pc attribute or the
2521 // first address in the first range entry in the list of ranges given by the
2522 // DW_AT_ranges attribute.
2523 // -- DWARFv5, Section 2.17 Code Addresses, Ranges and Base Addresses
2524 //
2525 // If no DW_AT_entry_pc attribute is present, then the entry address is
2526 // assumed to be the same as the base address of the containing scope.
2527 // -- DWARFv5, Section 2.18 Entry Address
2528 //
2529 // We currently don't support Debug Info Entries with
2530 // DW_AT_low_pc/DW_AT_entry_pc and DW_AT_ranges attributes (the latter
2531 // attributes are ignored even though they should be used for the address of
2532 // the function), but compilers also don't emit that kind of information. If
2533 // this becomes a problem we need to plumb these attributes separately.
2534 Address func_addr = func_ranges[0].GetBaseAddress();
2535
2536 func_sp = std::make_shared<Function>(
2537 &comp_unit,
2538 func_user_id, // UserID is the DIE offset
2539 func_user_id, func_name, func_type, std::move(func_addr),
2540 std::move(func_ranges));
2541
2542 if (func_sp.get() != nullptr) {
2543 if (frame_base.IsValid())
2544 func_sp->GetFrameBaseExpression() = frame_base;
2545 comp_unit.AddFunction(func_sp);
2546 return func_sp.get();
2547 }
2548 }
2549 return nullptr;
2550}
2551
2552namespace {
2553/// Parsed form of all attributes that are relevant for parsing Objective-C
2554/// properties.
2555struct PropertyAttributes {
2556 explicit PropertyAttributes(const DWARFDIE &die);
2557 const char *prop_name = nullptr;
2558 const char *prop_getter_name = nullptr;
2559 const char *prop_setter_name = nullptr;
2560 /// \see clang::ObjCPropertyAttribute
2561 uint32_t prop_attributes = 0;
2562};
2563
2564struct DiscriminantValue {
2565 explicit DiscriminantValue(const DWARFDIE &die, ModuleSP module_sp);
2566
2567 uint32_t byte_offset;
2568 uint32_t byte_size;
2569 DWARFFormValue type_ref;
2570};
2571
2572struct VariantMember {
2573 explicit VariantMember(DWARFDIE &die, ModuleSP module_sp);
2574 bool IsDefault() const;
2575
2576 std::optional<llvm::APInt> discr_value;
2577 DWARFFormValue type_ref;
2578 ConstString variant_name;
2579 uint32_t byte_offset;
2580 ConstString GetName() const;
2581};
2582
2583struct VariantPart {
2584 explicit VariantPart(const DWARFDIE &die, const DWARFDIE &parent_die,
2585 ModuleSP module_sp);
2586
2587 std::vector<VariantMember> &members();
2588
2589 DiscriminantValue &discriminant();
2590
2591private:
2592 std::vector<VariantMember> _members;
2593 DiscriminantValue _discriminant;
2594};
2595
2596} // namespace
2597
2598ConstString VariantMember::GetName() const { return this->variant_name; }
2599
2600bool VariantMember::IsDefault() const { return !discr_value; }
2601
2602VariantMember::VariantMember(DWARFDIE &die, lldb::ModuleSP module_sp) {
2603 assert(die.Tag() == llvm::dwarf::DW_TAG_variant);
2604
2605 DWARFFormValue discr_form;
2606 die.GetDIE()->GetAttributeValue(die.GetCU(), DW_AT_discr_value, discr_form);
2607
2608 // Rust can output 128-bit discriminants (e.g. NonNull<u128>) as
2609 // `DW_FORM_block1`. There is a `data16` dwarf form, but DWARFFormValue treats
2610 // it as a BlockData anyway. Handling is included for it just in case rust's
2611 // output changes to the `data16` form.
2612 dw_form_t form = discr_form.Form();
2613 if ((form == DW_FORM_block1 && discr_form.Unsigned() == 16) ||
2614 form == DW_FORM_data16) {
2615 const uint8_t *block_data = discr_form.BlockData();
2616
2617 DataExtractor extractor(block_data, 16, die.GetCU()->GetByteOrder(),
2618 die.GetCU()->GetAddressByteSize());
2619 lldb::offset_t offset = 0;
2620 uint64_t lo = extractor.GetU64(&offset);
2621 uint64_t hi = extractor.GetU64(&offset);
2622 uint64_t words[] = {lo, hi};
2623 this->discr_value = llvm::APInt(128, words);
2624 } else {
2625 if (auto result =
2626 die.GetAttributeValueAsOptionalUnsigned(DW_AT_discr_value)) {
2627 this->discr_value = llvm::APInt(sizeof(uint64_t) * 8, result.value());
2628 } else {
2629 this->discr_value = std::nullopt;
2630 };
2631 }
2632
2633 for (auto child_die : die.children()) {
2634 switch (child_die.Tag()) {
2635 case llvm::dwarf::DW_TAG_member: {
2636 DWARFAttributes attributes = child_die.GetAttributes();
2637 for (std::size_t i = 0; i < attributes.Size(); ++i) {
2638 DWARFFormValue form_value;
2639 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2640 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2641 switch (attr) {
2642 case DW_AT_name:
2643 variant_name = ConstString(form_value.AsCString());
2644 break;
2645 case DW_AT_type:
2646 type_ref = form_value;
2647 break;
2648
2649 case DW_AT_data_member_location:
2650 if (auto maybe_offset =
2651 ExtractDataMemberLocation(die, form_value, module_sp))
2652 byte_offset = *maybe_offset;
2653 break;
2654
2655 default:
2656 break;
2657 }
2658 }
2659 }
2660 break;
2661 }
2662 default:
2663 break;
2664 }
2665 break;
2666 }
2667}
2668
2669DiscriminantValue::DiscriminantValue(const DWARFDIE &die, ModuleSP module_sp) {
2670 auto referenced_die = die.GetReferencedDIE(DW_AT_discr);
2671 DWARFAttributes attributes = referenced_die.GetAttributes();
2672 for (std::size_t i = 0; i < attributes.Size(); ++i) {
2673 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2674 DWARFFormValue form_value;
2675 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2676 switch (attr) {
2677 case DW_AT_type:
2678 type_ref = form_value;
2679 break;
2680 case DW_AT_data_member_location:
2681 if (auto maybe_offset =
2682 ExtractDataMemberLocation(die, form_value, module_sp))
2683 byte_offset = *maybe_offset;
2684 break;
2685 default:
2686 break;
2687 }
2688 }
2689 }
2690}
2691
2692VariantPart::VariantPart(const DWARFDIE &die, const DWARFDIE &parent_die,
2693 lldb::ModuleSP module_sp)
2694 : _members(), _discriminant(die, module_sp) {
2695
2696 for (auto child : die.children()) {
2697 if (child.Tag() == llvm::dwarf::DW_TAG_variant) {
2698 _members.push_back(VariantMember(child, module_sp));
2699 }
2700 }
2701}
2702
2703std::vector<VariantMember> &VariantPart::members() { return this->_members; }
2704
2705DiscriminantValue &VariantPart::discriminant() { return this->_discriminant; }
2706
2708 const DWARFDIE &die, const DWARFDIE &parent_die, ModuleSP module_sp) {
2709 DWARFAttributes attributes = die.GetAttributes();
2710 for (size_t i = 0; i < attributes.Size(); ++i) {
2711 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2712 DWARFFormValue form_value;
2713 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2714 switch (attr) {
2715 case DW_AT_name:
2716 name = form_value.AsCString();
2717 break;
2718 case DW_AT_type:
2719 encoding_form = form_value;
2720 break;
2721 case DW_AT_bit_offset:
2722 bit_offset = form_value.Signed();
2723 break;
2724 case DW_AT_bit_size:
2725 bit_size = form_value.Unsigned();
2726 break;
2727 case DW_AT_byte_size:
2728 byte_size = form_value.Unsigned();
2729 break;
2730 case DW_AT_const_value:
2731 const_value_form = form_value;
2732 break;
2733 case DW_AT_data_bit_offset:
2734 data_bit_offset = form_value.Unsigned();
2735 break;
2736 case DW_AT_data_member_location:
2737 if (auto maybe_offset =
2738 ExtractDataMemberLocation(die, form_value, module_sp))
2739 member_byte_offset = *maybe_offset;
2740 break;
2741
2742 case DW_AT_artificial:
2743 is_artificial = form_value.Boolean();
2744 break;
2745 case DW_AT_declaration:
2746 is_declaration = form_value.Boolean();
2747 break;
2748 default:
2749 break;
2750 }
2751 }
2752 }
2753
2754 // Clang has a DWARF generation bug where sometimes it represents
2755 // fields that are references with bad byte size and bit size/offset
2756 // information such as:
2757 //
2758 // DW_AT_byte_size( 0x00 )
2759 // DW_AT_bit_size( 0x40 )
2760 // DW_AT_bit_offset( 0xffffffffffffffc0 )
2761 //
2762 // So check the bit offset to make sure it is sane, and if the values
2763 // are not sane, remove them. If we don't do this then we will end up
2764 // with a crash if we try to use this type in an expression when clang
2765 // becomes unhappy with its recycled debug info.
2766 if (byte_size.value_or(0) == 0 && bit_offset < 0) {
2767 bit_size = 0;
2768 bit_offset = 0;
2769 }
2770}
2771
2772PropertyAttributes::PropertyAttributes(const DWARFDIE &die) {
2773
2774 DWARFAttributes attributes = die.GetAttributes();
2775 for (size_t i = 0; i < attributes.Size(); ++i) {
2776 const dw_attr_t attr = attributes.AttributeAtIndex(i);
2777 DWARFFormValue form_value;
2778 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
2779 switch (attr) {
2780 case DW_AT_APPLE_property_name:
2781 prop_name = form_value.AsCString();
2782 break;
2783 case DW_AT_APPLE_property_getter:
2784 prop_getter_name = form_value.AsCString();
2785 break;
2786 case DW_AT_APPLE_property_setter:
2787 prop_setter_name = form_value.AsCString();
2788 break;
2789 case DW_AT_APPLE_property_attribute:
2790 prop_attributes = form_value.Unsigned();
2791 break;
2792 default:
2793 break;
2794 }
2795 }
2796 }
2797
2798 if (!prop_name)
2799 return;
2800 ConstString fixed_setter;
2801
2802 // Check if the property getter/setter were provided as full names.
2803 // We want basenames, so we extract them.
2804 if (prop_getter_name && prop_getter_name[0] == '-') {
2805 std::optional<const ObjCLanguage::ObjCMethodName> prop_getter_method =
2806 ObjCLanguage::ObjCMethodName::Create(prop_getter_name, true);
2807 if (prop_getter_method)
2808 prop_getter_name =
2809 ConstString(prop_getter_method->GetSelector()).GetCString();
2810 }
2811
2812 if (prop_setter_name && prop_setter_name[0] == '-') {
2813 std::optional<const ObjCLanguage::ObjCMethodName> prop_setter_method =
2814 ObjCLanguage::ObjCMethodName::Create(prop_setter_name, true);
2815 if (prop_setter_method)
2816 prop_setter_name =
2817 ConstString(prop_setter_method->GetSelector()).GetCString();
2818 }
2819
2820 // If the names haven't been provided, they need to be filled in.
2821 if (!prop_getter_name)
2822 prop_getter_name = prop_name;
2823 if (!prop_setter_name && prop_name[0] &&
2824 !(prop_attributes & DW_APPLE_PROPERTY_readonly)) {
2825 StreamString ss;
2826
2827 ss.Printf("set%c%s:", toupper(prop_name[0]), &prop_name[1]);
2828
2829 fixed_setter.SetString(ss.GetString());
2830 prop_setter_name = fixed_setter.GetCString();
2831 }
2832}
2833
2835 const DWARFDIE &die, const DWARFDIE &parent_die,
2836 const lldb_private::CompilerType &class_clang_type,
2837 DelayedPropertyList &delayed_properties) {
2838 // This function can only parse DW_TAG_APPLE_property.
2839 assert(die.Tag() == DW_TAG_APPLE_property);
2840
2841 ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule();
2842
2843 const MemberAttributes attrs(die, parent_die, module_sp);
2844 const PropertyAttributes propAttrs(die);
2845
2846 if (!propAttrs.prop_name) {
2847 module_sp->ReportError("{0:x8}: DW_TAG_APPLE_property has no name.",
2848 die.GetID());
2849 return;
2850 }
2851
2852 Type *member_type = die.ResolveTypeUID(attrs.encoding_form.Reference());
2853 if (!member_type) {
2854 module_sp->ReportError(
2855 "{0:x8}: DW_TAG_APPLE_property '{1}' refers to type {2:x16}"
2856 " which was unable to be parsed",
2857 die.GetID(), propAttrs.prop_name,
2859 return;
2860 }
2861
2862 ClangASTMetadata metadata;
2863 metadata.SetUserID(die.GetID());
2864 delayed_properties.emplace_back(
2865 class_clang_type, propAttrs.prop_name,
2866 member_type->GetLayoutCompilerType(), propAttrs.prop_setter_name,
2867 propAttrs.prop_getter_name, propAttrs.prop_attributes, metadata);
2868}
2869
2871 const CompilerType &int_type, const DWARFFormValue &form_value) const {
2872 clang::QualType qt = ClangUtil::GetQualType(int_type);
2873 assert(qt->isIntegralOrEnumerationType());
2874 auto ts_ptr = int_type.GetTypeSystem<TypeSystemClang>();
2875 if (!ts_ptr)
2876 return llvm::createStringError(llvm::inconvertibleErrorCode(),
2877 "TypeSystem not clang");
2878 TypeSystemClang &ts = *ts_ptr;
2879 clang::ASTContext &ast = ts.getASTContext();
2880
2881 const unsigned type_bits = ast.getIntWidth(qt);
2882 const bool is_unsigned = qt->isUnsignedIntegerType();
2883
2884 // The maximum int size supported at the moment by this function. Limited
2885 // by the uint64_t return type of DWARFFormValue::Signed/Unsigned.
2886 constexpr std::size_t max_bit_size = 64;
2887
2888 // For values bigger than 64 bit (e.g. __int128_t values),
2889 // DWARFFormValue's Signed/Unsigned functions will return wrong results so
2890 // emit an error for now.
2891 if (type_bits > max_bit_size) {
2892 auto msg = llvm::formatv("Can only parse integers with up to {0} bits, but "
2893 "given integer has {1} bits.",
2894 max_bit_size, type_bits);
2895 return llvm::createStringError(llvm::inconvertibleErrorCode(), msg.str());
2896 }
2897
2898 // Construct an APInt with the maximum bit size and the given integer.
2899 llvm::APInt result(max_bit_size, form_value.Unsigned(), !is_unsigned);
2900
2901 // Calculate how many bits are required to represent the input value.
2902 // For unsigned types, take the number of active bits in the APInt.
2903 // For signed types, ask APInt how many bits are required to represent the
2904 // signed integer.
2905 const unsigned required_bits =
2906 is_unsigned ? result.getActiveBits() : result.getSignificantBits();
2907
2908 // If the input value doesn't fit into the integer type, return an error.
2909 if (required_bits > type_bits) {
2910 std::string value_as_str = is_unsigned
2911 ? std::to_string(form_value.Unsigned())
2912 : std::to_string(form_value.Signed());
2913 auto msg = llvm::formatv("Can't store {0} value {1} in integer with {2} "
2914 "bits.",
2915 (is_unsigned ? "unsigned" : "signed"),
2916 value_as_str, type_bits);
2917 return llvm::createStringError(llvm::inconvertibleErrorCode(), msg.str());
2918 }
2919
2920 // Trim the result to the bit width our the int type.
2921 if (result.getBitWidth() > type_bits)
2922 result = result.trunc(type_bits);
2923 return result;
2924}
2925
2927 const DWARFDIE &die, const MemberAttributes &attrs,
2928 const lldb_private::CompilerType &class_clang_type) {
2930 assert(die.Tag() == DW_TAG_member || die.Tag() == DW_TAG_variable);
2931
2932 Type *var_type = die.ResolveTypeUID(attrs.encoding_form.Reference());
2933
2934 if (!var_type)
2935 return;
2936
2937 CompilerType ct = var_type->GetForwardCompilerType();
2938 clang::VarDecl *v = TypeSystemClang::AddVariableToRecordType(class_clang_type,
2939 attrs.name, ct);
2940 if (!v) {
2941 LLDB_LOG(log, "Failed to add variable to the record type");
2942 return;
2943 }
2944
2945 bool unused;
2946 // TODO: Support float/double static members as well.
2947 if (!ct.IsIntegerOrEnumerationType(unused) || !attrs.const_value_form)
2948 return;
2949
2950 llvm::Expected<llvm::APInt> const_value_or_err =
2952 if (!const_value_or_err) {
2953 LLDB_LOG_ERROR(log, const_value_or_err.takeError(),
2954 "Failed to add const value to variable {1}: {0}",
2955 v->getQualifiedNameAsString());
2956 return;
2957 }
2958
2960}
2961
2963 const DWARFDIE &die, const DWARFDIE &parent_die,
2964 const lldb_private::CompilerType &class_clang_type,
2966 FieldInfo &last_field_info) {
2967 // This function can only parse DW_TAG_member.
2968 assert(die.Tag() == DW_TAG_member);
2969
2970 ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule();
2971 const dw_tag_t tag = die.Tag();
2972 // Get the parent byte size so we can verify any members will fit
2973 const uint64_t parent_byte_size =
2974 parent_die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX);
2975 const uint64_t parent_bit_size =
2976 parent_byte_size == UINT64_MAX ? UINT64_MAX : parent_byte_size * 8;
2977
2978 const MemberAttributes attrs(die, parent_die, module_sp);
2979
2980 // Handle static members, which are typically members without
2981 // locations. However, GCC doesn't emit DW_AT_data_member_location
2982 // for any union members (regardless of linkage).
2983 // Non-normative text pre-DWARFv5 recommends marking static
2984 // data members with an DW_AT_external flag. Clang emits this consistently
2985 // whereas GCC emits it only for static data members if not part of an
2986 // anonymous namespace. The flag that is consistently emitted for static
2987 // data members is DW_AT_declaration, so we check it instead.
2988 // The following block is only necessary to support DWARFv4 and earlier.
2989 // Starting with DWARFv5, static data members are marked DW_AT_variable so we
2990 // can consistently detect them on both GCC and Clang without below heuristic.
2991 if (attrs.member_byte_offset == UINT32_MAX &&
2992 attrs.data_bit_offset == UINT64_MAX && attrs.is_declaration) {
2993 CreateStaticMemberVariable(die, attrs, class_clang_type);
2994 return;
2995 }
2996
2997 Type *member_type = die.ResolveTypeUID(attrs.encoding_form.Reference());
2998 if (!member_type) {
2999 if (attrs.name)
3000 module_sp->ReportError(
3001 "{0:x8}: DW_TAG_member '{1}' refers to type {2:x16}"
3002 " which was unable to be parsed",
3003 die.GetID(), attrs.name, attrs.encoding_form.Reference().GetOffset());
3004 else
3005 module_sp->ReportError("{0:x8}: DW_TAG_member refers to type {1:x16}"
3006 " which was unable to be parsed",
3007 die.GetID(),
3009 return;
3010 }
3011
3012 const uint64_t character_width = 8;
3013 CompilerType member_clang_type = member_type->GetLayoutCompilerType();
3014
3015 uint64_t field_bit_offset = (attrs.member_byte_offset == UINT32_MAX
3016 ? 0
3017 : (attrs.member_byte_offset * 8ULL));
3018
3019 if (attrs.bit_size > 0) {
3020 FieldInfo this_field_info;
3021 this_field_info.bit_offset = field_bit_offset;
3022 this_field_info.bit_size = attrs.bit_size;
3023
3024 if (attrs.data_bit_offset != UINT64_MAX) {
3025 this_field_info.bit_offset = attrs.data_bit_offset;
3026 } else {
3027 auto byte_size = attrs.byte_size;
3028 if (!byte_size)
3029 byte_size = llvm::expectedToOptional(member_type->GetByteSize(nullptr));
3030
3031 ObjectFile *objfile = die.GetDWARF()->GetObjectFile();
3032 if (objfile->GetByteOrder() == eByteOrderLittle) {
3033 this_field_info.bit_offset += byte_size.value_or(0) * 8;
3034 this_field_info.bit_offset -= (attrs.bit_offset + attrs.bit_size);
3035 } else {
3036 this_field_info.bit_offset += attrs.bit_offset;
3037 }
3038 }
3039
3040 // The ObjC runtime knows the byte offset but we still need to provide
3041 // the bit-offset in the layout. It just means something different then
3042 // what it does in C and C++. So we skip this check for ObjC types.
3043 //
3044 // We also skip this for fields of a union since they will all have a
3045 // zero offset.
3046 if (!TypeSystemClang::IsObjCObjectOrInterfaceType(class_clang_type) &&
3047 !(parent_die.Tag() == DW_TAG_union_type &&
3048 this_field_info.bit_offset == 0) &&
3049 ((this_field_info.bit_offset >= parent_bit_size) ||
3050 (last_field_info.IsBitfield() &&
3051 !last_field_info.NextBitfieldOffsetIsValid(
3052 this_field_info.bit_offset)))) {
3053 ObjectFile *objfile = die.GetDWARF()->GetObjectFile();
3054 objfile->GetModule()->ReportWarning(
3055 "{0:x16}: {1} ({2}) bitfield named \"{3}\" has invalid "
3056 "bit offset ({4:x8}) member will be ignored. Please file a bug "
3057 "against the "
3058 "compiler and include the preprocessed output for {5}",
3059 die.GetID(), DW_TAG_value_to_name(tag), tag, attrs.name,
3060 this_field_info.bit_offset, GetUnitName(parent_die).c_str());
3061 return;
3062 }
3063
3064 // Update the field bit offset we will report for layout
3065 field_bit_offset = this_field_info.bit_offset;
3066
3067 // Objective-C has invalid DW_AT_bit_offset values in older
3068 // versions of clang, so we have to be careful and only insert
3069 // unnamed bitfields if we have a new enough clang.
3070 bool detect_unnamed_bitfields = true;
3071
3073 detect_unnamed_bitfields =
3075
3076 if (detect_unnamed_bitfields)
3077 AddUnnamedBitfieldToRecordTypeIfNeeded(layout_info, class_clang_type,
3078 last_field_info, this_field_info);
3079
3080 last_field_info = this_field_info;
3081 last_field_info.SetIsBitfield(true);
3082 } else {
3083 FieldInfo this_field_info;
3084 this_field_info.is_bitfield = false;
3085 this_field_info.bit_offset = field_bit_offset;
3086
3087 // TODO: we shouldn't silently ignore the bit_size if we fail
3088 // to GetByteSize.
3089 if (std::optional<uint64_t> clang_type_size =
3090 llvm::expectedToOptional(member_type->GetByteSize(nullptr))) {
3091 this_field_info.bit_size = *clang_type_size * character_width;
3092 }
3093
3094 if (this_field_info.GetFieldEnd() <= last_field_info.GetEffectiveFieldEnd())
3095 this_field_info.SetEffectiveFieldEnd(
3096 last_field_info.GetEffectiveFieldEnd());
3097
3098 last_field_info = this_field_info;
3099 }
3100
3101 // Don't turn artificial members such as vtable pointers into real FieldDecls
3102 // in our AST. Clang will re-create those articial members and they would
3103 // otherwise just overlap in the layout with the FieldDecls we add here.
3104 // This needs to be done after updating FieldInfo which keeps track of where
3105 // field start/end so we don't later try to fill the space of this
3106 // artificial member with (unnamed bitfield) padding.
3107 if (attrs.is_artificial && ShouldIgnoreArtificialField(attrs.name)) {
3108 last_field_info.SetIsArtificial(true);
3109 return;
3110 }
3111
3112 if (!member_clang_type.IsCompleteType())
3113 member_clang_type.GetCompleteType();
3114
3115 TypeSystemClang::RequireCompleteType(member_clang_type);
3116
3117 clang::FieldDecl *field_decl = TypeSystemClang::AddFieldToRecordType(
3118 class_clang_type, attrs.name, member_clang_type, attrs.bit_size);
3119
3120 m_ast.SetMetadataAsUserID(field_decl, die.GetID());
3121
3122 layout_info.field_offsets.insert(
3123 std::make_pair(field_decl, field_bit_offset));
3124}
3125
3127 const DWARFDIE &parent_die, const CompilerType &class_clang_type,
3128 std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> &base_classes,
3129 std::vector<DWARFDIE> &member_function_dies,
3130 std::vector<DWARFDIE> &contained_type_dies,
3131 DelayedPropertyList &delayed_properties,
3132 ClangASTImporter::LayoutInfo &layout_info) {
3133 if (!parent_die)
3134 return false;
3135
3136 FieldInfo last_field_info;
3137
3138 ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule();
3139 auto ast = class_clang_type.GetTypeSystem<TypeSystemClang>();
3140 if (ast == nullptr)
3141 return false;
3142
3143 for (DWARFDIE die : parent_die.children()) {
3144 dw_tag_t tag = die.Tag();
3145
3146 switch (tag) {
3147 case DW_TAG_APPLE_property:
3148 ParseObjCProperty(die, parent_die, class_clang_type, delayed_properties);
3149 break;
3150
3151 case DW_TAG_variant_part:
3153 ParseRustVariantPart(die, parent_die, class_clang_type, layout_info);
3154 }
3155 break;
3156
3157 case DW_TAG_variable: {
3158 const MemberAttributes attrs(die, parent_die, module_sp);
3159 CreateStaticMemberVariable(die, attrs, class_clang_type);
3160 } break;
3161 case DW_TAG_member:
3162 ParseSingleMember(die, parent_die, class_clang_type, layout_info,
3163 last_field_info);
3164 break;
3165
3166 case DW_TAG_subprogram:
3167 // Let the type parsing code handle this one for us.
3168 member_function_dies.push_back(die);
3169 break;
3170
3171 case DW_TAG_inheritance:
3172 ParseInheritance(die, parent_die, class_clang_type, module_sp,
3173 base_classes, layout_info);
3174 break;
3175
3176 default:
3177 if (llvm::dwarf::isType(tag))
3178 contained_type_dies.push_back(die);
3179 break;
3180 }
3181 }
3182
3183 return true;
3184}
3185
3187 clang::DeclContext *containing_decl_ctx, const DWARFDIE &parent_die,
3188 bool &is_variadic, bool &has_template_params,
3189 std::vector<CompilerType> &function_param_types,
3190 llvm::SmallVectorImpl<llvm::StringRef> &function_param_names) {
3191 if (!parent_die)
3192 return;
3193
3194 for (DWARFDIE die : parent_die.children()) {
3195 const dw_tag_t tag = die.Tag();
3196 switch (tag) {
3197 case DW_TAG_formal_parameter: {
3198 if (die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0))
3199 continue;
3200
3201 DWARFDIE param_type_die = die.GetAttributeValueAsReferenceDIE(DW_AT_type);
3202
3203 Type *type = die.ResolveTypeUID(param_type_die);
3204 if (!type)
3205 break;
3206
3207 function_param_names.emplace_back(die.GetName());
3208 function_param_types.push_back(type->GetForwardCompilerType());
3209 } break;
3210
3211 case DW_TAG_unspecified_parameters:
3212 is_variadic = true;
3213 break;
3214
3215 case DW_TAG_template_type_parameter:
3216 case DW_TAG_template_value_parameter:
3217 case DW_TAG_GNU_template_parameter_pack:
3218 // The one caller of this was never using the template_param_infos, and
3219 // the local variable was taking up a large amount of stack space in
3220 // SymbolFileDWARF::ParseType() so this was removed. If we ever need the
3221 // template params back, we can add them back.
3222 // ParseTemplateDIE (dwarf_cu, die, template_param_infos);
3223 has_template_params = true;
3224 break;
3225
3226 default:
3227 break;
3228 }
3229 }
3230
3231 assert(function_param_names.size() == function_param_types.size());
3232}
3233
3235 if (!die)
3236 return nullptr;
3237
3238 switch (die.Tag()) {
3239 case DW_TAG_constant:
3240 case DW_TAG_formal_parameter:
3241 case DW_TAG_imported_declaration:
3242 case DW_TAG_imported_module:
3243 break;
3244 case DW_TAG_variable:
3245 // This means 'die' is a C++ static data member.
3246 // We don't want to create decls for such members
3247 // here.
3248 if (auto parent = die.GetParent();
3249 parent.IsValid() && TagIsRecordType(parent.Tag()))
3250 return nullptr;
3251 break;
3252 default:
3253 return nullptr;
3254 }
3255
3256 DIEToDeclMap::iterator cache_pos = m_die_to_decl.find(die.GetDIE());
3257 if (cache_pos != m_die_to_decl.end())
3258 return cache_pos->second;
3259
3260 if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification)) {
3261 clang::Decl *decl = GetClangDeclForDIE(spec_die);
3262 m_die_to_decl[die.GetDIE()] = decl;
3263 return decl;
3264 }
3265
3266 if (DWARFDIE abstract_origin_die =
3267 die.GetReferencedDIE(DW_AT_abstract_origin)) {
3268 clang::Decl *decl = GetClangDeclForDIE(abstract_origin_die);
3269 m_die_to_decl[die.GetDIE()] = decl;
3270 return decl;
3271 }
3272
3273 clang::Decl *decl = nullptr;
3274 switch (die.Tag()) {
3275 case DW_TAG_variable:
3276 case DW_TAG_constant:
3277 case DW_TAG_formal_parameter: {
3279 Type *type = GetTypeForDIE(die);
3280 if (dwarf && type) {
3281 const char *name = die.GetName();
3282 clang::DeclContext *decl_context =
3284 dwarf->GetDeclContextContainingUID(die.GetID()));
3285 decl = m_ast.CreateVariableDeclaration(
3286 decl_context, GetOwningClangModule(die), name,
3288 }
3289 break;
3290 }
3291 case DW_TAG_imported_declaration: {
3293 DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import);
3294 if (imported_uid) {
3295 CompilerDecl imported_decl = SymbolFileDWARF::GetDecl(imported_uid);
3296 if (imported_decl) {
3297 clang::DeclContext *decl_context =
3299 dwarf->GetDeclContextContainingUID(die.GetID()));
3300 if (clang::NamedDecl *clang_imported_decl =
3301 llvm::dyn_cast<clang::NamedDecl>(
3302 (clang::Decl *)imported_decl.GetOpaqueDecl()))
3303 decl = m_ast.CreateUsingDeclaration(
3304 decl_context, OptionalClangModuleID(), clang_imported_decl);
3305 }
3306 }
3307 break;
3308 }
3309 case DW_TAG_imported_module: {
3311 DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import);
3312
3313 if (imported_uid) {
3314 CompilerDeclContext imported_decl_ctx =
3315 SymbolFileDWARF::GetDeclContext(imported_uid);
3316 if (imported_decl_ctx) {
3317 clang::DeclContext *decl_context =
3319 dwarf->GetDeclContextContainingUID(die.GetID()));
3320 if (clang::NamespaceDecl *ns_decl =
3322 imported_decl_ctx))
3323 decl = m_ast.CreateUsingDirectiveDeclaration(
3324 decl_context, OptionalClangModuleID(), ns_decl);
3325 }
3326 }
3327 break;
3328 }
3329 default:
3330 break;
3331 }
3332
3333 m_die_to_decl[die.GetDIE()] = decl;
3334
3335 return decl;
3336}
3337
3338clang::DeclContext *
3340 if (die) {
3341 clang::DeclContext *decl_ctx = GetCachedClangDeclContextForDIE(die);
3342 if (decl_ctx)
3343 return decl_ctx;
3344
3345 bool try_parsing_type = true;
3346 switch (die.Tag()) {
3347 case DW_TAG_compile_unit:
3348 case DW_TAG_partial_unit:
3349 decl_ctx = m_ast.GetTranslationUnitDecl();
3350 try_parsing_type = false;
3351 break;
3352
3353 case DW_TAG_namespace:
3354 decl_ctx = ResolveNamespaceDIE(die);
3355 try_parsing_type = false;
3356 break;
3357
3358 case DW_TAG_imported_declaration:
3359 decl_ctx = ResolveImportedDeclarationDIE(die);
3360 try_parsing_type = false;
3361 break;
3362
3363 case DW_TAG_lexical_block:
3364 decl_ctx = GetDeclContextForBlock(die);
3365 try_parsing_type = false;
3366 break;
3367
3368 default:
3369 break;
3370 }
3371
3372 if (decl_ctx == nullptr && try_parsing_type) {
3373 Type *type = die.GetDWARF()->ResolveType(die);
3374 if (type)
3375 decl_ctx = GetCachedClangDeclContextForDIE(die);
3376 }
3377
3378 if (decl_ctx) {
3379 LinkDeclContextToDIE(decl_ctx, die);
3380 return decl_ctx;
3381 }
3382 }
3383 return nullptr;
3384}
3385
3388 if (!die.IsValid())
3389 return {};
3390
3391 for (DWARFDIE parent = die.GetParent(); parent.IsValid();
3392 parent = parent.GetParent()) {
3393 const dw_tag_t tag = parent.Tag();
3394 if (tag == DW_TAG_module) {
3395 DWARFDIE module_die = parent;
3396 auto it = m_die_to_module.find(module_die.GetDIE());
3397 if (it != m_die_to_module.end())
3398 return it->second;
3399 const char *name =
3400 module_die.GetAttributeValueAsString(DW_AT_name, nullptr);
3401 if (!name)
3402 return {};
3403
3405 m_ast.GetOrCreateClangModule(name, GetOwningClangModule(module_die));
3406 m_die_to_module.insert({module_die.GetDIE(), id});
3407 return id;
3408 }
3409 }
3410 return {};
3411}
3412
3413static bool IsSubroutine(const DWARFDIE &die) {
3414 switch (die.Tag()) {
3415 case DW_TAG_subprogram:
3416 case DW_TAG_inlined_subroutine:
3417 return true;
3418 default:
3419 return false;
3420 }
3421}
3422
3424 for (DWARFDIE candidate = die; candidate; candidate = candidate.GetParent()) {
3425 if (IsSubroutine(candidate)) {
3426 if (candidate.GetReferencedDIE(DW_AT_abstract_origin)) {
3427 return candidate;
3428 } else {
3429 return DWARFDIE();
3430 }
3431 }
3432 }
3433 assert(0 && "Shouldn't call GetContainingFunctionWithAbstractOrigin on "
3434 "something not in a function");
3435 return DWARFDIE();
3436}
3437
3439 for (DWARFDIE candidate : context.children()) {
3440 if (candidate.GetReferencedDIE(DW_AT_abstract_origin)) {
3441 return candidate;
3442 }
3443 }
3444 return DWARFDIE();
3445}
3446
3448 const DWARFDIE &function) {
3449 assert(IsSubroutine(function));
3450 for (DWARFDIE context = block; context != function.GetParent();
3451 context = context.GetParent()) {
3452 assert(!IsSubroutine(context) || context == function);
3453 if (DWARFDIE child = FindAnyChildWithAbstractOrigin(context)) {
3454 return child;
3455 }
3456 }
3457 return DWARFDIE();
3458}
3459
3460clang::DeclContext *
3462 assert(die.Tag() == DW_TAG_lexical_block);
3463 DWARFDIE containing_function_with_abstract_origin =
3465 if (!containing_function_with_abstract_origin) {
3466 return (clang::DeclContext *)ResolveBlockDIE(die);
3467 }
3469 die, containing_function_with_abstract_origin);
3470 CompilerDeclContext decl_context =
3472 return (clang::DeclContext *)decl_context.GetOpaqueDeclContext();
3473}
3474
3475clang::BlockDecl *DWARFASTParserClang::ResolveBlockDIE(const DWARFDIE &die) {
3476 if (die && die.Tag() == DW_TAG_lexical_block) {
3477 clang::BlockDecl *decl =
3478 llvm::cast_or_null<clang::BlockDecl>(m_die_to_decl_ctx[die.GetDIE()]);
3479
3480 if (!decl) {
3481 DWARFDIE decl_context_die;
3482 clang::DeclContext *decl_context =
3483 GetClangDeclContextContainingDIE(die, &decl_context_die);
3484 decl =
3485 m_ast.CreateBlockDeclaration(decl_context, GetOwningClangModule(die));
3486
3487 if (decl)
3488 LinkDeclContextToDIE((clang::DeclContext *)decl, die);
3489 }
3490
3491 return decl;
3492 }
3493 return nullptr;
3494}
3495
3496clang::NamespaceDecl *
3498 if (die && die.Tag() == DW_TAG_namespace) {
3499 // See if we already parsed this namespace DIE and associated it with a
3500 // uniqued namespace declaration
3501 clang::NamespaceDecl *namespace_decl =
3502 static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die.GetDIE()]);
3503 if (namespace_decl)
3504 return namespace_decl;
3505 else {
3506 const char *namespace_name = die.GetName();
3507 clang::DeclContext *containing_decl_ctx =
3509 bool is_inline =
3510 die.GetAttributeValueAsUnsigned(DW_AT_export_symbols, 0) != 0;
3511
3512 namespace_decl = m_ast.GetUniqueNamespaceDeclaration(
3513 namespace_name, containing_decl_ctx, GetOwningClangModule(die),
3514 is_inline);
3515
3516 if (namespace_decl)
3517 LinkDeclContextToDIE((clang::DeclContext *)namespace_decl, die);
3518 return namespace_decl;
3519 }
3520 }
3521 return nullptr;
3522}
3523
3524clang::NamespaceDecl *
3526 assert(die && die.Tag() == DW_TAG_imported_declaration);
3527
3528 // See if we cached a NamespaceDecl for this imported declaration
3529 // already
3530 auto it = m_die_to_decl_ctx.find(die.GetDIE());
3531 if (it != m_die_to_decl_ctx.end())
3532 return static_cast<clang::NamespaceDecl *>(it->getSecond());
3533
3534 clang::NamespaceDecl *namespace_decl = nullptr;
3535
3536 const DWARFDIE imported_uid =
3537 die.GetAttributeValueAsReferenceDIE(DW_AT_import);
3538 if (!imported_uid)
3539 return nullptr;
3540
3541 switch (imported_uid.Tag()) {
3542 case DW_TAG_imported_declaration:
3543 namespace_decl = ResolveImportedDeclarationDIE(imported_uid);
3544 break;
3545 case DW_TAG_namespace:
3546 namespace_decl = ResolveNamespaceDIE(imported_uid);
3547 break;
3548 default:
3549 return nullptr;
3550 }
3551
3552 if (!namespace_decl)
3553 return nullptr;
3554
3555 LinkDeclContextToDIE(namespace_decl, die);
3556
3557 return namespace_decl;
3558}
3559
3561 const DWARFDIE &die, DWARFDIE *decl_ctx_die_copy) {
3563
3564 DWARFDIE decl_ctx_die = dwarf->GetDeclContextDIEContainingDIE(die);
3565
3566 if (decl_ctx_die_copy)
3567 *decl_ctx_die_copy = decl_ctx_die;
3568
3569 if (decl_ctx_die) {
3570 clang::DeclContext *clang_decl_ctx =
3571 GetClangDeclContextForDIE(decl_ctx_die);
3572 if (clang_decl_ctx)
3573 return clang_decl_ctx;
3574 }
3575 return m_ast.GetTranslationUnitDecl();
3576}
3577
3578clang::DeclContext *
3580 if (die) {
3581 DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die.GetDIE());
3582 if (pos != m_die_to_decl_ctx.end())
3583 return pos->second;
3584 }
3585 return nullptr;
3586}
3587
3588void DWARFASTParserClang::LinkDeclContextToDIE(clang::DeclContext *decl_ctx,
3589 const DWARFDIE &die) {
3590 m_die_to_decl_ctx[die.GetDIE()] = decl_ctx;
3591 // There can be many DIEs for a single decl context
3592 // m_decl_ctx_to_die[decl_ctx].insert(die.GetDIE());
3593 m_decl_ctx_to_die.insert(std::make_pair(decl_ctx, die));
3594}
3595
3597 const DWARFDIE &src_class_die, const DWARFDIE &dst_class_die,
3598 lldb_private::Type *class_type, std::vector<DWARFDIE> &failures) {
3599 if (!class_type || !src_class_die || !dst_class_die)
3600 return false;
3601 if (src_class_die.Tag() != dst_class_die.Tag())
3602 return false;
3603
3604 // We need to complete the class type so we can get all of the method types
3605 // parsed so we can then unique those types to their equivalent counterparts
3606 // in "dst_cu" and "dst_class_die"
3607 class_type->GetFullCompilerType();
3608
3609 auto gather = [](DWARFDIE die, UniqueCStringMap<DWARFDIE> &map,
3610 UniqueCStringMap<DWARFDIE> &map_artificial) {
3611 if (die.Tag() != DW_TAG_subprogram)
3612 return;
3613 // Make sure this is a declaration and not a concrete instance by looking
3614 // for DW_AT_declaration set to 1. Sometimes concrete function instances are
3615 // placed inside the class definitions and shouldn't be included in the list
3616 // of things that are tracking here.
3617 if (die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0) != 1)
3618 return;
3619
3620 if (const char *name = die.GetMangledName()) {
3621 ConstString const_name(name);
3622 if (die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0))
3623 map_artificial.Append(const_name, die);
3624 else
3625 map.Append(const_name, die);
3626 }
3627 };
3628
3629 UniqueCStringMap<DWARFDIE> src_name_to_die;
3630 UniqueCStringMap<DWARFDIE> dst_name_to_die;
3631 UniqueCStringMap<DWARFDIE> src_name_to_die_artificial;
3632 UniqueCStringMap<DWARFDIE> dst_name_to_die_artificial;
3633 for (DWARFDIE src_die = src_class_die.GetFirstChild(); src_die.IsValid();
3634 src_die = src_die.GetSibling()) {
3635 gather(src_die, src_name_to_die, src_name_to_die_artificial);
3636 }
3637 for (DWARFDIE dst_die = dst_class_die.GetFirstChild(); dst_die.IsValid();
3638 dst_die = dst_die.GetSibling()) {
3639 gather(dst_die, dst_name_to_die, dst_name_to_die_artificial);
3640 }
3641 const uint32_t src_size = src_name_to_die.GetSize();
3642 const uint32_t dst_size = dst_name_to_die.GetSize();
3643
3644 // Is everything kosher so we can go through the members at top speed?
3645 bool fast_path = true;
3646
3647 if (src_size != dst_size)
3648 fast_path = false;
3649
3650 uint32_t idx;
3651
3652 if (fast_path) {
3653 for (idx = 0; idx < src_size; ++idx) {
3654 DWARFDIE src_die = src_name_to_die.GetValueAtIndexUnchecked(idx);
3655 DWARFDIE dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
3656
3657 if (src_die.Tag() != dst_die.Tag())
3658 fast_path = false;
3659
3660 const char *src_name = src_die.GetMangledName();
3661 const char *dst_name = dst_die.GetMangledName();
3662
3663 // Make sure the names match
3664 if (src_name == dst_name || (strcmp(src_name, dst_name) == 0))
3665 continue;
3666
3667 fast_path = false;
3668 }
3669 }
3670
3671 auto *src_dwarf_ast_parser = llvm::cast<DWARFASTParserClang>(
3672 SymbolFileDWARF::GetDWARFParser(*src_class_die.GetCU()));
3673 auto *dst_dwarf_ast_parser = llvm::cast<DWARFASTParserClang>(
3674 SymbolFileDWARF::GetDWARFParser(*dst_class_die.GetCU()));
3675 auto link = [&](DWARFDIE src, DWARFDIE dst) {
3676 auto &die_to_type = dst_class_die.GetDWARF()->GetDIEToType();
3677 clang::DeclContext *dst_decl_ctx =
3678 dst_dwarf_ast_parser->m_die_to_decl_ctx[dst.GetDIE()];
3679 if (dst_decl_ctx)
3680 src_dwarf_ast_parser->LinkDeclContextToDIE(dst_decl_ctx, src);
3681
3682 if (Type *src_child_type = die_to_type.lookup(src.GetDIE()))
3683 die_to_type[dst.GetDIE()] = src_child_type;
3684 };
3685
3686 // Now do the work of linking the DeclContexts and Types.
3687 if (fast_path) {
3688 // We can do this quickly. Just run across the tables index-for-index
3689 // since we know each node has matching names and tags.
3690 for (idx = 0; idx < src_size; ++idx) {
3691 link(src_name_to_die.GetValueAtIndexUnchecked(idx),
3692 dst_name_to_die.GetValueAtIndexUnchecked(idx));
3693 }
3694 } else {
3695 // We must do this slowly. For each member of the destination, look up a
3696 // member in the source with the same name, check its tag, and unique them
3697 // if everything matches up. Report failures.
3698
3699 if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty()) {
3700 src_name_to_die.Sort();
3701
3702 for (idx = 0; idx < dst_size; ++idx) {
3703 ConstString dst_name = dst_name_to_die.GetCStringAtIndex(idx);
3704 DWARFDIE dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
3705 DWARFDIE src_die = src_name_to_die.Find(dst_name, DWARFDIE());
3706
3707 if (src_die && (src_die.Tag() == dst_die.Tag()))
3708 link(src_die, dst_die);
3709 else
3710 failures.push_back(dst_die);
3711 }
3712 }
3713 }
3714
3715 const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize();
3716 const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize();
3717
3718 if (src_size_artificial && dst_size_artificial) {
3719 dst_name_to_die_artificial.Sort();
3720
3721 for (idx = 0; idx < src_size_artificial; ++idx) {
3722 ConstString src_name_artificial =
3723 src_name_to_die_artificial.GetCStringAtIndex(idx);
3724 DWARFDIE src_die =
3725 src_name_to_die_artificial.GetValueAtIndexUnchecked(idx);
3726 DWARFDIE dst_die =
3727 dst_name_to_die_artificial.Find(src_name_artificial, DWARFDIE());
3728
3729 // Both classes have the artificial types, link them
3730 if (dst_die)
3731 link(src_die, dst_die);
3732 }
3733 }
3734
3735 if (dst_size_artificial) {
3736 for (idx = 0; idx < dst_size_artificial; ++idx) {
3737 failures.push_back(
3738 dst_name_to_die_artificial.GetValueAtIndexUnchecked(idx));
3739 }
3740 }
3741
3742 return !failures.empty();
3743}
3744
3746 FieldInfo const &last_field_info, uint64_t last_field_end,
3747 FieldInfo const &this_field_info,
3748 lldb_private::ClangASTImporter::LayoutInfo const &layout_info) const {
3749 // If we have a gap between the last_field_end and the current
3750 // field we have an unnamed bit-field.
3751 if (this_field_info.bit_offset <= last_field_end)
3752 return false;
3753
3754 // If we have a base class, we assume there is no unnamed
3755 // bit-field if either of the following is true:
3756 // (a) this is the first field since the gap can be
3757 // attributed to the members from the base class.
3758 // FIXME: This assumption is not correct if the first field of
3759 // the derived class is indeed an unnamed bit-field. We currently
3760 // do not have the machinary to track the offset of the last field
3761 // of classes we have seen before, so we are not handling this case.
3762 // (b) Or, the first member of the derived class was a vtable pointer.
3763 // In this case we don't want to create an unnamed bitfield either
3764 // since those will be inserted by clang later.
3765 const bool have_base = layout_info.base_offsets.size() != 0;
3766 const bool this_is_first_field =
3767 last_field_info.bit_offset == 0 && last_field_info.bit_size == 0;
3768 const bool first_field_is_vptr =
3769 last_field_info.bit_offset == 0 && last_field_info.IsArtificial();
3770
3771 if (have_base && (this_is_first_field || first_field_is_vptr))
3772 return false;
3773
3774 return true;
3775}
3776
3778 ClangASTImporter::LayoutInfo &class_layout_info,
3779 const CompilerType &class_clang_type, const FieldInfo &previous_field,
3780 const FieldInfo &current_field) {
3781 // TODO: get this value from target
3782 const uint64_t word_width = 32;
3783 uint64_t last_field_end = previous_field.GetEffectiveFieldEnd();
3784
3785 if (!previous_field.IsBitfield()) {
3786 // The last field was not a bit-field...
3787 // but if it did take up the entire word then we need to extend
3788 // last_field_end so the bit-field does not step into the last
3789 // fields padding.
3790 if (last_field_end != 0 && ((last_field_end % word_width) != 0))
3791 last_field_end += word_width - (last_field_end % word_width);
3792 }
3793
3794 // Nothing to be done.
3795 if (!ShouldCreateUnnamedBitfield(previous_field, last_field_end,
3796 current_field, class_layout_info))
3797 return;
3798
3799 // Place the unnamed bitfield into the gap between the previous field's end
3800 // and the current field's start.
3801 const uint64_t unnamed_bit_size = current_field.bit_offset - last_field_end;
3802 const uint64_t unnamed_bit_offset = last_field_end;
3803
3804 clang::FieldDecl *unnamed_bitfield_decl =
3806 class_clang_type, llvm::StringRef(),
3807 m_ast.GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width),
3808 unnamed_bit_size);
3809
3810 class_layout_info.field_offsets.insert(
3811 std::make_pair(unnamed_bitfield_decl, unnamed_bit_offset));
3812}
3813
3815 DWARFDIE &die, const DWARFDIE &parent_die,
3816 const CompilerType &class_clang_type,
3817 ClangASTImporter::LayoutInfo &layout_info) {
3818 assert(die.Tag() == llvm::dwarf::DW_TAG_variant_part);
3819 assert(SymbolFileDWARF::GetLanguage(*die.GetCU()) ==
3821
3822 ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule();
3823
3824 VariantPart variants(die, parent_die, module_sp);
3825
3826 auto discriminant_type =
3827 die.ResolveTypeUID(variants.discriminant().type_ref.Reference());
3828
3829 auto decl_context = m_ast.GetDeclContextForType(class_clang_type);
3830
3831 auto inner_holder = m_ast.CreateRecordType(
3832 decl_context, OptionalClangModuleID(),
3833 std::string(
3834 llvm::formatv("{0}$Inner", class_clang_type.GetTypeName(false))),
3835 llvm::to_underlying(clang::TagTypeKind::Union), lldb::eLanguageTypeRust);
3836 m_ast.StartTagDeclarationDefinition(inner_holder);
3837 m_ast.SetIsPacked(inner_holder);
3838
3839 for (auto member : variants.members()) {
3840
3841 auto has_discriminant = !member.IsDefault();
3842
3843 auto member_type = die.ResolveTypeUID(member.type_ref.Reference());
3844
3845 auto field_type = m_ast.CreateRecordType(
3846 m_ast.GetDeclContextForType(inner_holder), OptionalClangModuleID(),
3847 std::string(llvm::formatv("{0}$Variant", member.GetName())),
3848 llvm::to_underlying(clang::TagTypeKind::Struct),
3850
3851 m_ast.StartTagDeclarationDefinition(field_type);
3852 auto offset = member.byte_offset;
3853
3854 if (has_discriminant) {
3855 m_ast.AddFieldToRecordType(field_type, "$discr$",
3856 discriminant_type->GetFullCompilerType(),
3857 variants.discriminant().byte_offset);
3858 offset +=
3859 llvm::expectedToOptional(discriminant_type->GetByteSize(nullptr))
3860 .value_or(0);
3861 }
3862
3863 m_ast.AddFieldToRecordType(field_type, "value",
3864 member_type->GetFullCompilerType(), offset * 8);
3865
3866 m_ast.CompleteTagDeclarationDefinition(field_type);
3867
3868 auto name = std::string("$variant$");
3869 if (has_discriminant) {
3870 // u128::MAX = 340282366920938463463374607431768211455 which is 39 digits
3871 // long + 1 for null terminator.
3872 llvm::SmallString<40> discr_str;
3873 member.discr_value.value().toStringUnsigned(discr_str);
3874 name.append(discr_str.c_str());
3875 }
3876
3877 auto variant_decl = m_ast.AddFieldToRecordType(
3878 inner_holder, llvm::StringRef(name), field_type, 0);
3879
3880 layout_info.field_offsets.insert({variant_decl, 0});
3881 }
3882
3883 auto inner_field = m_ast.AddFieldToRecordType(
3884 class_clang_type, llvm::StringRef("$variants$"), inner_holder, 0);
3885
3886 m_ast.CompleteTagDeclarationDefinition(inner_holder);
3887
3888 layout_info.field_offsets.insert({inner_field, 0});
3889}
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 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:376
#define LLDB_LOGF(log,...)
Definition Log.h:390
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:406
#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:376
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition Function.cpp:379
static bool LanguageIsCPlusPlus(lldb::LanguageType language)
Definition Language.cpp:342
static bool LanguageIsObjC(lldb::LanguageType language)
Definition Language.cpp:357
A class that handles mangled names.
Definition Mangled.h:34
void SetDemangledName(ConstString name)
Definition Mangled.h:160
void SetMangledName(ConstString name)
Definition Mangled.h:165
void SetValue(ConstString name)
Set the string value in this object.
Definition Mangled.cpp:124
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:582
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.
Definition Type.h:104
void AddLanguage(lldb::LanguageType language)
Add a language family to the list of languages that should produce a match.
Definition Type.cpp:120
This class tracks the state and results of a TypeQuery.
Definition Type.h:344
TypeMap & GetTypeMap()
Definition Type.h:386
bool AlreadySearched(lldb_private::SymbolFile *sym_file)
Check if a SymbolFile object has already been searched by this type match object.
Definition Type.cpp:191
llvm::DenseSet< lldb_private::SymbolFile * > & GetSearchedSymbolFiles()
Access the set of searched symbol files.
Definition Type.h:381
void SetParameterPack(std::unique_ptr< TemplateParameterInfos > args)
void InsertArg(char const *name, clang::TemplateArgument arg)
TemplateParameterInfos const & GetParameterPack() const
A TypeSystem implementation based on Clang.
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()
Definition Type.cpp:791
uint32_t GetEncodingMask()
Definition Type.cpp:772
@ eEncodingIsRestrictUID
This type is the type whose UID is m_encoding_uid with the restrict qualifier added.
Definition Type.h:429
@ eEncodingIsConstUID
This type is the type whose UID is m_encoding_uid with the const qualifier added.
Definition Type.h:426
@ eEncodingIsVolatileUID
This type is the type whose UID is m_encoding_uid with the volatile qualifier added.
Definition Type.h:432
@ eEncodingIsAtomicUID
This type is the type whose UID is m_encoding_uid as an atomic type.
Definition Type.h:442
@ eEncodingIsLLVMPtrAuthUID
This type is a signed pointer.
Definition Type.h:446
@ eEncodingInvalid
Invalid encoding.
Definition Type.h:421
@ eEncodingIsTypedefUID
This type is alias to a type whose UID is m_encoding_uid.
Definition Type.h:434
@ eEncodingIsPointerUID
This type is pointer to a type whose UID is m_encoding_uid.
Definition Type.h:436
@ eEncodingIsLValueReferenceUID
This type is L value reference to a type whose UID is m_encoding_uid.
Definition Type.h:438
@ eEncodingIsRValueReferenceUID
This type is R value reference to a type whose UID is m_encoding_uid.
Definition Type.h:440
@ eEncodingIsUID
This type is the type whose UID is m_encoding_uid.
Definition Type.h:423
CompilerType GetLayoutCompilerType()
Definition Type.cpp:786
CompilerType GetFullCompilerType()
Definition Type.cpp:781
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *exe_scope)
Definition Type.cpp:460
ConstString GetCStringAtIndex(uint32_t idx) const
T GetValueAtIndexUnchecked(uint32_t idx) const
T Find(ConstString unique_cstr, T fail_value) const
lldb_private::Type * GetTypeForDIE(const DWARFDIE &die)
static lldb::AccessType GetAccessTypeFromDWARF(uint32_t dwarf_accessibility)
static std::optional< SymbolFile::ArrayInfo > ParseChildArrayInfo(const DWARFDIE &parent_die, const ExecutionContext *exe_ctx=nullptr)
DWARFUnit * CompileUnitAtIndex(uint32_t i) const
dw_attr_t AttributeAtIndex(uint32_t i) const
bool ExtractFormValueAtIndex(uint32_t i, DWARFFormValue &form_value) const
DWARFAttributes GetAttributes(Recurse recurse=Recurse::yes) const
std::optional< uint64_t > GetAttributeValueAsOptionalUnsigned(const dw_attr_t attr) const
const DWARFDataExtractor & GetData() const
const char * GetAttributeValueAsString(const dw_attr_t attr, const char *fail_value) const
std::optional< DIERef > GetDIERef() const
uint64_t GetAttributeValueAsUnsigned(const dw_attr_t attr, uint64_t fail_value) const
const char * GetMangledName(bool substitute_name_allowed=true) const
Definition DWARFDIE.cpp:212
bool GetDIENamesAndRanges(const char *&name, const char *&mangled, llvm::DWARFAddressRangesVector &ranges, std::optional< int > &decl_file, std::optional< int > &decl_line, std::optional< int > &decl_column, std::optional< int > &call_file, std::optional< int > &call_line, std::optional< int > &call_column, DWARFExpressionList *frame_base) const
Definition DWARFDIE.cpp:584
DWARFDIE GetDIE(dw_offset_t die_offset) const
Definition DWARFDIE.cpp:126
llvm::iterator_range< child_iterator > children() const
The range of all the children of this DIE.
Definition DWARFDIE.cpp:601
Type * ResolveTypeUID(const DWARFDIE &die) const
Definition DWARFDIE.cpp:375
std::vector< CompilerContext > GetDeclContext(bool derive_template_names=false) const
Return this DIE's decl context as it is needed to look up types in Clang modules.
Definition DWARFDIE.cpp:456
DWARFDIE GetAttributeValueAsReferenceDIE(const dw_attr_t attr) const
Definition DWARFDIE.cpp:134
DWARFDeclContext GetDWARFDeclContext() const
Definition DWARFDIE.cpp:526
DWARFDIE GetReferencedDIE(const dw_attr_t attr) const
Definition DWARFDIE.cpp:118
SymbolFileDWARF & GetSymbolFileDWARF() const
Definition DWARFUnit.h: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:339
std::shared_ptr< lldb_private::Function > FunctionSP
@ eBasicTypeObjCClass
uint64_t offset_t
Definition lldb-types.h:85
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
@ eLanguageTypeRust
Rust.
@ eLanguageTypeObjC_plus_plus
Objective-C++.
@ eLanguageTypeObjC
Objective-C.
std::shared_ptr< lldb_private::Type > TypeSP
@ eEncodingSint
signed integer
uint64_t user_id_t
Definition lldb-types.h:82
std::shared_ptr< lldb_private::Module > ModuleSP
@ eRegisterKindDWARF
the register numbers seen DWARF
uint64_t GetEffectiveFieldEnd() const
If this field was folded into storage of a previous field, returns the offset in bits of where that s...
uint64_t bit_offset
Offset of this field in bits from the beginning of the containing struct.
bool NextBitfieldOffsetIsValid(const uint64_t next_bit_offset) const
uint64_t GetFieldEnd() const
Returns the offset in bits of where the storage this field occupies ends.
uint64_t bit_size
Size in bits that this field occupies.
bool is_bitfield
Set to 'true' if this field is a bit-field.
Parsed form of all attributes that are relevant for parsing type members.
int64_t bit_offset
Indicates how many bits into the word (according to the host endianness) the low-order bit of the fie...
uint32_t member_byte_offset
Indicates the byte offset of the word from the base address of the structure.
lldb_private::plugin::dwarf::DWARFFormValue encoding_form
size_t bit_size
Indicates the size of the field in bits.
std::optional< lldb_private::plugin::dwarf::DWARFFormValue > const_value_form
MemberAttributes(const lldb_private::plugin::dwarf::DWARFDIE &die, const lldb_private::plugin::dwarf::DWARFDIE &parent_die, lldb::ModuleSP module_sp)
Parsed form of all attributes that are relevant for type reconstruction.
lldb_private::Declaration decl
uint32_t encoding
Indicates ref-qualifier of C++ member function if present.
lldb_private::ConstString name
std::optional< clang::EnumExtensibilityAttr::Kind > enum_kind
std::optional< uint64_t > alignment
lldb::LanguageType class_language
std::optional< uint64_t > byte_size
lldb_private::plugin::dwarf::DWARFFormValue signature
lldb_private::plugin::dwarf::DWARFFormValue type
ParsedDWARFTypeAttributes(const lldb_private::plugin::dwarf::DWARFDIE &die)
clang::RefQualifierKind ref_qual
Has a value if this DIE represents an enum that was declared with enum_extensibility.
lldb_private::plugin::dwarf::DWARFFormValue specification
lldb_private::plugin::dwarf::DWARFFormValue abstract_origin
std::optional< uint64_t > data_bit_size
lldb_private::plugin::dwarf::DWARFFormValue containing_type
llvm::DenseMap< const clang::FieldDecl *, uint64_t > field_offsets
static clang::QualType GetQualType(const CompilerType &ct)
Definition ClangUtil.cpp:36
static CompilerType RemoveFastQualifiers(const CompilerType &ct)
Definition ClangUtil.cpp:51
static clang::TagDecl * GetAsTagDecl(const CompilerType &type)
Definition ClangUtil.cpp:60
Holds parsed information about a function call label that LLDB attaches as an AsmLabel to function AS...
Definition Expression.h:110
std::string toString() const
Encode this FunctionCallLabel into its string representation.
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition UserID.h:47