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