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