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