22 std::optional<std::pair<size_t, size_t>> ChildIndex) {
25 assert(Info.needToPlaceInTypeTable() &&
26 "Cann't assign name for non-type DIE");
44 if (CurChild->getTag() == dwarf::DW_TAG_subrange_type ||
45 CurChild->getTag() == dwarf::DW_TAG_generic_subrange) {
47 if (std::optional<DWARFFormValue> Val =
48 InputUnitEntryPair.
CU->
find(CurChild, dwarf::DW_AT_count)) {
49 if (std::optional<uint64_t> ConstVal = Val->getAsUnsignedConstant()) {
51 }
else if (std::optional<int64_t> ConstVal =
52 Val->getAsSignedConstant()) {
64 bool addTemplateParameters) {
78 if (addTemplateParameters &&
79 (ChildTag == dwarf::DW_TAG_template_type_parameter ||
80 ChildTag == dwarf::DW_TAG_template_value_parameter))
82 else if (ChildTag == dwarf::DW_TAG_formal_parameter ||
83 ChildTag == dwarf::DW_TAG_unspecified_parameters)
85 else if (addTemplateParameters &&
86 ChildTag == dwarf::DW_TAG_GNU_template_parameter_pack) {
91 TemplateParameters.
push_back(CurGNUChild);
92 }
else if (ChildTag == dwarf::DW_TAG_GNU_formal_parameter_pack) {
97 FunctionParameters.
push_back(CurGNUChild);
134 if (!TemplateParameters.
empty()) {
140 if (Parameter->getTag() == dwarf::DW_TAG_template_value_parameter) {
141 if (std::optional<DWARFFormValue> Val =
142 CU.find(Parameter, dwarf::DW_AT_const_value)) {
143 if (std::optional<uint64_t> ConstVal = Val->getAsUnsignedConstant())
145 else if (std::optional<int64_t> ConstVal = Val->getAsSignedConstant())
160 std::pair<size_t, size_t> ChildIdx) {
169static std::optional<UnitEntryPairTy>
172 case dwarf::DW_TAG_null:
173 case dwarf::DW_TAG_compile_unit:
174 case dwarf::DW_TAG_partial_unit:
175 case dwarf::DW_TAG_type_unit:
176 case dwarf::DW_TAG_skeleton_unit: {
179 case dwarf::DW_TAG_namespace: {
181 if (UnitEntryPair.
CU->
find(UnitEntryPair.
DieEntry, dwarf::DW_AT_extension))
185 if (!UnitEntryPair.
CU->
find(UnitEntryPair.
DieEntry, dwarf::DW_AT_name))
188 return UnitEntryPair;
191 return UnitEntryPair;
197 std::optional<UnitEntryPairTy> UnitEntryPair = InputUnitEntryPair.
getParent();
206 UnitEntryPair->CU->getDieTypeEntry(UnitEntryPair->DieEntry)) {
215 Parents.push_back(*UnitEntryPair);
217 UnitEntryPair = UnitEntryPair->getParent();
225 }
while (!UnitEntryPair->CU->getDieTypeEntry(UnitEntryPair->DieEntry));
242 if (std::optional<DWARFFormValue> DeclFileVal = InputUnitEntryPair.
CU->
find(
243 InputUnitEntryPair.
DieEntry, dwarf::DW_AT_decl_file)) {
244 if (std::optional<DWARFFormValue> DeclLineVal = InputUnitEntryPair.
CU->
find(
245 InputUnitEntryPair.
DieEntry, dwarf::DW_AT_decl_line)) {
246 if (std::optional<std::pair<StringRef, StringRef>> DirAndFilename =
252 if (std::optional<uint64_t> DeclLineIntVal =
258 HasDeclFileName =
true;
266 if (std::optional<DWARFFormValue> Val =
268 if (std::optional<uint64_t> ConstVal = Val->getAsUnsignedConstant()) {
271 }
else if (std::optional<int64_t> ConstVal = Val->getAsSignedConstant()) {
281 std::optional<DWARFFormValue> AttrValue =
286 std::optional<UnitEntryPairTy> RefDie =
289 if (RefDie && !RefDie->DieEntry)
291 "cannot resolve DIE reference");
298 "cannot parse input DWARF: recursive dependence");
305 bool FirstIteration =
true;
320 addDIETypeName(**RefDie, std::nullopt, AssignNameToTypeDescriptor))
323 FirstIteration =
false;
330 bool AddParentNames) {
331 bool HasLinkageName =
false;
332 bool HasShortName =
false;
333 bool HasTemplatesInShortName =
false;
334 bool HasDeclFileName =
false;
337 if (std::optional<DWARFFormValue> Val = InputUnitEntryPair.
CU->
find(
339 {dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_AT_linkage_name})) {
342 HasLinkageName =
true;
343 }
else if (std::optional<DWARFFormValue> Val = InputUnitEntryPair.
CU->
find(
344 InputUnitEntryPair.
DieEntry, dwarf::DW_AT_name)) {
350 HasTemplatesInShortName =
351 Name.ends_with(
">") && Name.count(
"<") != 0 && !Name.ends_with(
"<=>");
364 case dwarf::DW_TAG_union_type:
365 case dwarf::DW_TAG_interface_type:
366 case dwarf::DW_TAG_class_type:
367 case dwarf::DW_TAG_structure_type:
368 case dwarf::DW_TAG_subroutine_type:
369 case dwarf::DW_TAG_subprogram: {
371 dwarf::DW_AT_artificial))
379 addSignature(InputUnitEntryPair, !HasTemplatesInShortName))
382 case dwarf::DW_TAG_coarray_type:
383 case dwarf::DW_TAG_array_type: {
386 case dwarf::DW_TAG_subrange_type: {
389 case dwarf::DW_TAG_template_value_parameter: {
390 if (!HasTemplatesInShortName) {
392 addValueName(InputUnitEntryPair, dwarf::DW_AT_const_value);
402 if ((!HasLinkageName && !HasShortName && !HasDeclFileName) ||
416 std::optional<std::pair<size_t, size_t>> ChildIndex,
417 bool AssignNameToTypeDescriptor) {
418 std::optional<UnitEntryPairTy> UnitEntryPair =
444 if (AssignNameToTypeDescriptor) {
464 CU.getFirstChildEntry(InputUnitEntryPair.
DieEntry);
465 CurChild && CurChild->getAbbreviationDeclarationPtr();
466 CurChild =
CU.getSiblingEntry(CurChild)) {
473 if (std::optional<DWARFFormValue> Val =
474 CU.find(CurChild, dwarf::DW_AT_name))
498 if (std::optional<DWARFFormValue> Val =
499 Type.CU->find(
Type.DieEntry, dwarf::DW_AT_name)) {
502 if (
Type.DieEntry->getTag() == dwarf::DW_TAG_array_type)
516 switch (DieEntry->
getTag()) {
517 case dwarf::DW_TAG_base_type: {
520 case dwarf::DW_TAG_namespace: {
523 case dwarf::DW_TAG_formal_parameter: {
527 case dwarf::DW_TAG_unspecified_parameters: {
530 case dwarf::DW_TAG_template_type_parameter: {
534 case dwarf::DW_TAG_template_value_parameter: {
537 case dwarf::DW_TAG_GNU_formal_parameter_pack: {
540 case dwarf::DW_TAG_GNU_template_parameter_pack: {
543 case dwarf::DW_TAG_inheritance: {
546 case dwarf::DW_TAG_array_type: {
549 case dwarf::DW_TAG_class_type: {
552 case dwarf::DW_TAG_enumeration_type: {
555 case dwarf::DW_TAG_imported_declaration: {
558 case dwarf::DW_TAG_member: {
566 case dwarf::DW_TAG_pointer_type: {
569 case dwarf::DW_TAG_reference_type: {
572 case dwarf::DW_TAG_string_type: {
575 case dwarf::DW_TAG_structure_type: {
578 case dwarf::DW_TAG_subroutine_type: {
581 case dwarf::DW_TAG_typedef: {
584 case dwarf::DW_TAG_union_type: {
587 case dwarf::DW_TAG_variant: {
590 case dwarf::DW_TAG_inlined_subroutine: {
593 case dwarf::DW_TAG_module: {
596 case dwarf::DW_TAG_ptr_to_member_type: {
599 case dwarf::DW_TAG_set_type: {
602 case dwarf::DW_TAG_subrange_type: {
605 case dwarf::DW_TAG_with_stmt: {
608 case dwarf::DW_TAG_access_declaration: {
611 case dwarf::DW_TAG_catch_block: {
614 case dwarf::DW_TAG_const_type: {
617 case dwarf::DW_TAG_constant: {
620 case dwarf::DW_TAG_enumerator: {
623 case dwarf::DW_TAG_file_type: {
626 case dwarf::DW_TAG_friend: {
629 case dwarf::DW_TAG_namelist: {
632 case dwarf::DW_TAG_namelist_item: {
635 case dwarf::DW_TAG_packed_type: {
638 case dwarf::DW_TAG_subprogram: {
641 case dwarf::DW_TAG_thrown_type: {
644 case dwarf::DW_TAG_variant_part: {
647 case dwarf::DW_TAG_variable: {
650 case dwarf::DW_TAG_volatile_type: {
653 case dwarf::DW_TAG_dwarf_procedure: {
656 case dwarf::DW_TAG_restrict_type: {
659 case dwarf::DW_TAG_interface_type: {
662 case dwarf::DW_TAG_imported_module: {
665 case dwarf::DW_TAG_unspecified_type: {
668 case dwarf::DW_TAG_imported_unit: {
671 case dwarf::DW_TAG_condition: {
674 case dwarf::DW_TAG_shared_type: {
677 case dwarf::DW_TAG_rvalue_reference_type: {
680 case dwarf::DW_TAG_template_alias: {
683 case dwarf::DW_TAG_coarray_type: {
686 case dwarf::DW_TAG_generic_subrange: {
689 case dwarf::DW_TAG_dynamic_type: {
692 case dwarf::DW_TAG_atomic_type: {
695 case dwarf::DW_TAG_call_site: {
698 case dwarf::DW_TAG_call_site_parameter: {
701 case dwarf::DW_TAG_immutable_type: {
704 case dwarf::DW_TAG_entry_point: {
707 case dwarf::DW_TAG_label: {
710 case dwarf::DW_TAG_lexical_block: {
713 case dwarf::DW_TAG_common_block: {
716 case dwarf::DW_TAG_common_inclusion: {
719 case dwarf::DW_TAG_try_block: {
723 case dwarf::DW_TAG_null: {
726 case dwarf::DW_TAG_compile_unit: {
729 case dwarf::DW_TAG_partial_unit: {
732 case dwarf::DW_TAG_type_unit: {
735 case dwarf::DW_TAG_skeleton_unit: {
749 switch (DieEntry->
getTag()) {
750 case dwarf::DW_TAG_array_type:
751 case dwarf::DW_TAG_coarray_type:
752 case dwarf::DW_TAG_class_type:
753 case dwarf::DW_TAG_common_block:
754 case dwarf::DW_TAG_lexical_block:
755 case dwarf::DW_TAG_structure_type:
756 case dwarf::DW_TAG_subprogram:
757 case dwarf::DW_TAG_subroutine_type:
758 case dwarf::DW_TAG_union_type:
759 case dwarf::DW_TAG_GNU_template_template_param:
760 case dwarf::DW_TAG_GNU_formal_parameter_pack:
761 case dwarf::DW_TAG_GNU_template_parameter_pack: {
764 case dwarf::DW_TAG_enumeration_type: {
776 CurChild && CurChild->getAbbreviationDeclarationPtr();
777 CurChild =
CU.getSiblingEntry(CurChild)) {
783 "Wrong index for ChildIndexesWidth");
790 size_t digitsCounter = 1;
791 size_t NumToCompare = 15;
793 while (NumToCompare < Width) {
798 Width = digitsCounter;
808 switch (DieEntry->
getTag()) {
809 case dwarf::DW_TAG_unspecified_parameters:
810 case dwarf::DW_TAG_formal_parameter:
812 case dwarf::DW_TAG_template_value_parameter:
813 case dwarf::DW_TAG_template_type_parameter:
814 case dwarf::DW_TAG_GNU_template_template_param:
816 case dwarf::DW_TAG_enumeration_type:
817 if (std::optional<uint32_t> ParentIdx = DieEntry->
getParentIdx()) {
818 if (*ParentIdx &&
CU.getDebugInfoEntry(*ParentIdx)->getTag() ==
819 dwarf::DW_TAG_array_type)
823 case dwarf::DW_TAG_subrange_type:
825 case dwarf::DW_TAG_generic_subrange:
827 case dwarf::DW_TAG_enumerator:
829 case dwarf::DW_TAG_namelist_item:
831 case dwarf::DW_TAG_member:
842std::optional<std::pair<size_t, size_t>>
850 "Wrong index for ChildIndexesWidth");
852 "Index width exceeds 16 digits.");
854 std::pair<size_t, size_t> Result = std::make_pair(
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static std::optional< UnitEntryPairTy > getTypeDeduplicationCandidate(UnitEntryPairTy UnitEntryPair)
static dwarf::Attribute TypeAttr[]
Represent a constant reference to an array (0 or more elements consecutively in memory),...
DWARFDebugInfoEntry - A DIE with only the minimum required data.
dwarf::Tag getTag() const
std::optional< uint32_t > getParentIdx() const
Returns index of the parent die.
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
Stores all information related to a compile unit, be it in its original instance of the object file o...
std::optional< std::pair< StringRef, StringRef > > getDirAndFilenameFromLineTable(const DWARFFormValue &FileIdxValue)
Returns directory and file from the line table by index.
std::optional< UnitEntryPairTy > resolveDIEReference(const DWARFFormValue &RefValue, ResolveInterCUReferencesMode CanResolveInterCUReferences)
Resolve the DIE attribute reference that has been extracted in RefValue.
OrderedChildrenIndexesArrayTy ChildIndexesWidth
OrderedChildrenIndexAssigner(CompileUnit &CU, const DWARFDebugInfoEntry *DieEntry)
std::optional< size_t > tagToArrayIndex(CompileUnit &CU, const DWARFDebugInfoEntry *DieEntry)
std::optional< std::pair< size_t, size_t > > getChildIndex(CompileUnit &CU, const DWARFDebugInfoEntry *ChildDieEntry)
Returns index of the specified child and width of hexadecimal representation.
OrderedChildrenIndexesArrayTy OrderedChildIdxs
Error addReferencedODRDies(UnitEntryPairTy InputUnitEntryPair, bool AssignNameToTypeDescriptor, ArrayRef< dwarf::Attribute > ODRAttrs)
Analyze InputUnitEntryPair's ODR attributes and put names of the referenced type dies to the built na...
Error addTemplateParamNames(CompileUnit &CU, SmallVector< const DWARFDebugInfoEntry *, 10 > &TemplateParameters)
Add specified TemplateParameters to the built name.
Error incrementRecursionDepth()
Count a referenced DIE toward the recursion limit.
Error addParentName(UnitEntryPairTy &InputUnitEntryPair)
Add names of parent dies to the built name.
Error addUnqualifiedTypeName(UnitEntryPairTy InputUnitEntryPair)
Add the type InputUnitEntryPair refers to, without parent scopes.
Error addSignature(UnitEntryPairTy InputUnitEntryPair, bool addTemplateParameters)
Add signature( entry type plus type of parameters plus type of template parameters(if addTemplatePara...
Error addParamNames(CompileUnit &CU, SmallVector< const DWARFDebugInfoEntry *, 20 > &FunctionParameters)
Add specified FunctionParameters to the built name.
void addDieNameFromDeclFileAndDeclLine(UnitEntryPairTy &InputUnitEntryPair, bool &HasDeclFileName)
TypePool & TypePoolRef
Type pool.
Error addUnnamedTypeContents(UnitEntryPairTy InputUnitEntryPair)
Add contents of the unnamed type InputUnitEntryPair.
size_t RecursionDepth
Recursion counter.
Expected< std::optional< UnitEntryPairTy > > resolveReference(UnitEntryPairTy InputUnitEntryPair, dwarf::Attribute Attr)
Resolve the DIE that Attr of InputUnitEntryPair refers to.
SmallString< 1000 > SyntheticName
Buffer keeping bult name.
void addOrderedName(std::pair< size_t, size_t > ChildIdx)
Add ordered name to the built name.
Error assignName(UnitEntryPairTy InputUnitEntryPair, std::optional< std::pair< size_t, size_t > > ChildIndex)
Create synthetic name for the specified DIE InputUnitEntryPair and assign created name to the DIE typ...
Error addDIETypeName(UnitEntryPairTy InputUnitEntryPair, std::optional< std::pair< size_t, size_t > > ChildIndex, bool AssignNameToTypeDescriptor)
Analyze InputUnitEntryPair for the type name and possibly assign built type name to the DIE's type in...
static constexpr size_t MaxRecursionDepth
Bounds RecursionDepth, which malformed input can make unbounded.
Error addTypeName(UnitEntryPairTy InputUnitEntryPair, bool AddParentNames)
Add type name to the built name.
void addArrayDimension(UnitEntryPairTy InputUnitEntryPair)
Add array type dimension.
void addValueName(UnitEntryPairTy InputUnitEntryPair, dwarf::Attribute Attr)
Add value name to the built name.
void addTypePrefix(CompileUnit &CU, const DWARFDebugInfoEntry *DieEntry)
Add type prefix to the built name.
A raw_ostream that writes to an std::string.
TypeEntry * getDieTypeEntry(uint32_t Idx)
Idx index of the DIE.
DIEInfo & getDIEInfo(unsigned Idx)
Idx index of the DIE.
void setDieTypeEntry(uint32_t Idx, TypeEntry *Entry)
Idx index of the DIE.
const DWARFDebugInfoEntry * getSiblingEntry(const DWARFDebugInfoEntry *Die) const
const DWARFDebugInfoEntry * getFirstChildEntry(const DWARFDebugInfoEntry *Die) const
std::optional< DWARFFormValue > find(uint32_t DieIdx, ArrayRef< dwarf::Attribute > Attrs) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
StringMapEntry< std::atomic< TypeEntryBody * > > TypeEntry
ArrayRef< dwarf::Attribute > getODRAttributes()
LLVM_ABI bool isIdentifiedByChildren(dwarf::Tag Tag)
Test if an unnamed type with tag Tag is identified by its children, which tell it apart from other un...
LLVM_ABI bool isStaticDataMember(const DWARFDie &Die)
Test if the DW_TAG_member Die is a DWARF 2-4 style static data member: a declaration with no storage ...
LLVM_ABI bool isIdentifyingChild(const DWARFDie &Die)
Test if Die is a child that identifies its unnamed parent type.
StringRef toStringRef(const std::optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
std::optional< uint64_t > toUnsigned(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
This is an optimization pass for GlobalISel generic memory operations.
std::string utohexstr(uint64_t X, bool LowerCase=false, unsigned Width=0)
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
auto reverse(ContainerTy &&C)
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
Information gathered about source DIEs.
This is a helper structure which keeps a debug info entry with it's containing compilation unit.
std::optional< UnitEntryPairTy > getParent()
UnitEntryPairTy getNamespaceOrigin()
const DWARFDebugInfoEntry * DieEntry