23 std::optional<std::pair<size_t, size_t>> ChildIndex) {
26 assert(Info.needToPlaceInTypeTable() &&
27 "Cann't assign name for non-type DIE");
45 if (CurChild->getTag() == dwarf::DW_TAG_subrange_type ||
46 CurChild->getTag() == dwarf::DW_TAG_generic_subrange) {
48 if (std::optional<DWARFFormValue> Val =
49 InputUnitEntryPair.
CU->
find(CurChild, dwarf::DW_AT_count)) {
50 if (std::optional<uint64_t> ConstVal = Val->getAsUnsignedConstant()) {
52 }
else if (std::optional<int64_t> ConstVal =
53 Val->getAsSignedConstant()) {
66 bool addTemplateParameters) {
79 if (ChildTag == dwarf::DW_TAG_formal_parameter ||
80 ChildTag == dwarf::DW_TAG_unspecified_parameters)
82 else if (ChildTag == dwarf::DW_TAG_GNU_formal_parameter_pack) {
87 FunctionParameters.
push_back(CurGNUChild);
95 if (addTemplateParameters)
110 if (ChildTag == dwarf::DW_TAG_template_type_parameter ||
111 ChildTag == dwarf::DW_TAG_template_value_parameter)
113 else if (ChildTag == dwarf::DW_TAG_GNU_template_parameter_pack) {
118 TemplateParameters.
push_back(CurGNUChild);
147 if (!TemplateParameters.
empty()) {
154 if (Parameter->getTag() == dwarf::DW_TAG_template_value_parameter) {
155 if (std::optional<DWARFFormValue> Val =
156 CU.find(Parameter, dwarf::DW_AT_const_value)) {
157 if (std::optional<uint64_t> ConstVal = Val->getAsUnsignedConstant())
159 else if (std::optional<int64_t> ConstVal = Val->getAsSignedConstant())
174 std::pair<size_t, size_t> ChildIdx) {
183static std::optional<UnitEntryPairTy>
186 case dwarf::DW_TAG_null:
187 case dwarf::DW_TAG_compile_unit:
188 case dwarf::DW_TAG_partial_unit:
189 case dwarf::DW_TAG_type_unit:
190 case dwarf::DW_TAG_skeleton_unit: {
193 case dwarf::DW_TAG_namespace: {
195 if (UnitEntryPair.
CU->
find(UnitEntryPair.
DieEntry, dwarf::DW_AT_extension))
199 if (!UnitEntryPair.
CU->
find(UnitEntryPair.
DieEntry, dwarf::DW_AT_name))
202 return UnitEntryPair;
205 return UnitEntryPair;
211 std::optional<UnitEntryPairTy> UnitEntryPair = InputUnitEntryPair.
getParent();
220 UnitEntryPair->CU->getDieTypeEntry(UnitEntryPair->DieEntry)) {
229 Parents.push_back(*UnitEntryPair);
231 UnitEntryPair = UnitEntryPair->getParent();
239 }
while (!UnitEntryPair->CU->getDieTypeEntry(UnitEntryPair->DieEntry));
256 if (std::optional<DWARFFormValue> DeclFileVal = InputUnitEntryPair.
CU->
find(
257 InputUnitEntryPair.
DieEntry, dwarf::DW_AT_decl_file)) {
258 if (std::optional<DWARFFormValue> DeclLineVal = InputUnitEntryPair.
CU->
find(
259 InputUnitEntryPair.
DieEntry, dwarf::DW_AT_decl_line)) {
260 if (std::optional<std::pair<StringRef, StringRef>> DirAndFilename =
266 if (std::optional<uint64_t> DeclLineIntVal =
272 HasDeclFileName =
true;
280 if (std::optional<DWARFFormValue> Val =
282 if (std::optional<uint64_t> ConstVal = Val->getAsUnsignedConstant()) {
285 }
else if (std::optional<int64_t> ConstVal = Val->getAsSignedConstant()) {
295 std::optional<DWARFFormValue> AttrValue =
300 std::optional<UnitEntryPairTy> RefDie =
303 if (RefDie && !RefDie->DieEntry)
305 "cannot resolve DIE reference");
312 "cannot parse input DWARF: recursive dependence");
319 bool FirstIteration =
true;
334 addDIETypeName(**RefDie, std::nullopt, AssignNameToTypeDescriptor))
337 FirstIteration =
false;
344 bool AddParentNames) {
345 bool HasLinkageName =
false;
346 bool HasShortName =
false;
347 bool HasTemplatesInShortName =
false;
348 bool HasDeclFileName =
false;
351 if (std::optional<DWARFFormValue> Val = InputUnitEntryPair.
CU->
find(
353 {dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_AT_linkage_name})) {
356 HasLinkageName =
true;
357 }
else if (std::optional<DWARFFormValue> Val = InputUnitEntryPair.
CU->
find(
358 InputUnitEntryPair.
DieEntry, dwarf::DW_AT_name)) {
364 HasTemplatesInShortName =
365 Name.ends_with(
">") && Name.count(
"<") != 0 && !Name.ends_with(
"<=>");
378 case dwarf::DW_TAG_union_type:
379 case dwarf::DW_TAG_interface_type:
380 case dwarf::DW_TAG_class_type:
381 case dwarf::DW_TAG_structure_type:
382 case dwarf::DW_TAG_subroutine_type:
383 case dwarf::DW_TAG_subprogram: {
385 dwarf::DW_AT_artificial))
391 if (!HasLinkageName) {
393 addSignature(InputUnitEntryPair, !HasTemplatesInShortName))
396 dwarf::DW_TAG_subprogram &&
399 dwarf::DW_AT_external),
410 case dwarf::DW_TAG_coarray_type:
411 case dwarf::DW_TAG_array_type: {
414 case dwarf::DW_TAG_subrange_type: {
417 case dwarf::DW_TAG_ptr_to_member_type: {
424 case dwarf::DW_TAG_template_value_parameter: {
425 if (!HasTemplatesInShortName) {
427 addValueName(InputUnitEntryPair, dwarf::DW_AT_const_value);
437 if ((!HasLinkageName && !HasShortName && !HasDeclFileName) ||
451 std::optional<std::pair<size_t, size_t>> ChildIndex,
452 bool AssignNameToTypeDescriptor) {
453 std::optional<UnitEntryPairTy> UnitEntryPair =
480 if (AssignNameToTypeDescriptor)
505 CU.getFirstChildEntry(InputUnitEntryPair.
DieEntry);
506 CurChild && CurChild->getAbbreviationDeclarationPtr();
507 CurChild =
CU.getSiblingEntry(CurChild)) {
514 if (std::optional<DWARFFormValue> Val =
515 CU.find(CurChild, dwarf::DW_AT_name))
549 if (std::optional<DWARFFormValue> Val =
550 Type.CU->find(
Type.DieEntry, dwarf::DW_AT_name)) {
553 if (
Type.DieEntry->getTag() == dwarf::DW_TAG_array_type)
567 switch (DieEntry->
getTag()) {
568 case dwarf::DW_TAG_base_type: {
571 case dwarf::DW_TAG_namespace: {
574 case dwarf::DW_TAG_formal_parameter: {
578 case dwarf::DW_TAG_unspecified_parameters: {
581 case dwarf::DW_TAG_template_type_parameter: {
585 case dwarf::DW_TAG_template_value_parameter: {
588 case dwarf::DW_TAG_GNU_formal_parameter_pack: {
591 case dwarf::DW_TAG_GNU_template_parameter_pack: {
594 case dwarf::DW_TAG_inheritance: {
597 case dwarf::DW_TAG_array_type: {
600 case dwarf::DW_TAG_class_type: {
603 case dwarf::DW_TAG_enumeration_type: {
606 case dwarf::DW_TAG_imported_declaration: {
609 case dwarf::DW_TAG_member: {
617 case dwarf::DW_TAG_pointer_type: {
620 case dwarf::DW_TAG_reference_type: {
623 case dwarf::DW_TAG_string_type: {
626 case dwarf::DW_TAG_structure_type: {
629 case dwarf::DW_TAG_subroutine_type: {
632 case dwarf::DW_TAG_typedef: {
635 case dwarf::DW_TAG_union_type: {
638 case dwarf::DW_TAG_variant: {
641 case dwarf::DW_TAG_inlined_subroutine: {
644 case dwarf::DW_TAG_module: {
647 case dwarf::DW_TAG_ptr_to_member_type: {
650 case dwarf::DW_TAG_set_type: {
653 case dwarf::DW_TAG_subrange_type: {
656 case dwarf::DW_TAG_with_stmt: {
659 case dwarf::DW_TAG_access_declaration: {
662 case dwarf::DW_TAG_catch_block: {
665 case dwarf::DW_TAG_const_type: {
668 case dwarf::DW_TAG_constant: {
671 case dwarf::DW_TAG_enumerator: {
674 case dwarf::DW_TAG_file_type: {
677 case dwarf::DW_TAG_friend: {
680 case dwarf::DW_TAG_namelist: {
683 case dwarf::DW_TAG_namelist_item: {
686 case dwarf::DW_TAG_packed_type: {
689 case dwarf::DW_TAG_subprogram: {
692 case dwarf::DW_TAG_thrown_type: {
695 case dwarf::DW_TAG_variant_part: {
698 case dwarf::DW_TAG_variable: {
701 case dwarf::DW_TAG_volatile_type: {
704 case dwarf::DW_TAG_dwarf_procedure: {
707 case dwarf::DW_TAG_restrict_type: {
710 case dwarf::DW_TAG_interface_type: {
713 case dwarf::DW_TAG_imported_module: {
716 case dwarf::DW_TAG_unspecified_type: {
719 case dwarf::DW_TAG_imported_unit: {
722 case dwarf::DW_TAG_condition: {
725 case dwarf::DW_TAG_shared_type: {
728 case dwarf::DW_TAG_rvalue_reference_type: {
731 case dwarf::DW_TAG_template_alias: {
734 case dwarf::DW_TAG_coarray_type: {
737 case dwarf::DW_TAG_generic_subrange: {
740 case dwarf::DW_TAG_dynamic_type: {
743 case dwarf::DW_TAG_atomic_type: {
746 case dwarf::DW_TAG_call_site: {
749 case dwarf::DW_TAG_call_site_parameter: {
752 case dwarf::DW_TAG_immutable_type: {
755 case dwarf::DW_TAG_entry_point: {
758 case dwarf::DW_TAG_label: {
761 case dwarf::DW_TAG_lexical_block: {
764 case dwarf::DW_TAG_common_block: {
767 case dwarf::DW_TAG_common_inclusion: {
770 case dwarf::DW_TAG_try_block: {
774 case dwarf::DW_TAG_null: {
777 case dwarf::DW_TAG_compile_unit: {
780 case dwarf::DW_TAG_partial_unit: {
783 case dwarf::DW_TAG_type_unit: {
786 case dwarf::DW_TAG_skeleton_unit: {
800 switch (DieEntry->
getTag()) {
801 case dwarf::DW_TAG_array_type:
802 case dwarf::DW_TAG_coarray_type:
803 case dwarf::DW_TAG_class_type:
804 case dwarf::DW_TAG_common_block:
805 case dwarf::DW_TAG_lexical_block:
806 case dwarf::DW_TAG_structure_type:
807 case dwarf::DW_TAG_subprogram:
808 case dwarf::DW_TAG_subroutine_type:
809 case dwarf::DW_TAG_union_type:
810 case dwarf::DW_TAG_GNU_template_template_param:
811 case dwarf::DW_TAG_GNU_formal_parameter_pack:
812 case dwarf::DW_TAG_GNU_template_parameter_pack: {
815 case dwarf::DW_TAG_enumeration_type: {
827 CurChild && CurChild->getAbbreviationDeclarationPtr();
828 CurChild =
CU.getSiblingEntry(CurChild)) {
834 "Wrong index for ChildIndexesWidth");
841 size_t digitsCounter = 1;
842 size_t NumToCompare = 15;
844 while (NumToCompare < Width) {
849 Width = digitsCounter;
859 switch (DieEntry->
getTag()) {
860 case dwarf::DW_TAG_unspecified_parameters:
861 case dwarf::DW_TAG_formal_parameter:
863 case dwarf::DW_TAG_template_value_parameter:
864 case dwarf::DW_TAG_template_type_parameter:
865 case dwarf::DW_TAG_GNU_template_template_param:
867 case dwarf::DW_TAG_enumeration_type:
868 if (std::optional<uint32_t> ParentIdx = DieEntry->
getParentIdx()) {
869 if (*ParentIdx &&
CU.getDebugInfoEntry(*ParentIdx)->getTag() ==
870 dwarf::DW_TAG_array_type)
874 case dwarf::DW_TAG_subrange_type:
876 case dwarf::DW_TAG_generic_subrange:
878 case dwarf::DW_TAG_enumerator:
880 case dwarf::DW_TAG_namelist_item:
882 case dwarf::DW_TAG_member:
893std::optional<std::pair<size_t, size_t>>
901 "Wrong index for ChildIndexesWidth");
903 "Index width exceeds 16 digits.");
905 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[]
static dwarf::Attribute ContainingTypeAttr[]
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.
TypeKey SyntheticName
Buffer keeping bult 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 a fixed-size digest of the contents of the unnamed type InputUnitEntryPair, so the names of the t...
size_t RecursionDepth
Recursion counter.
Expected< std::optional< UnitEntryPairTy > > resolveReference(UnitEntryPairTy InputUnitEntryPair, dwarf::Attribute Attr)
Resolve the DIE that Attr of InputUnitEntryPair refers to.
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.
DenseMap< const DWARFDebugInfoEntry *, std::string > ContentsDigests
Digests of the contents of unnamed types, by DIE.
void addArrayDimension(UnitEntryPairTy InputUnitEntryPair)
Add array type dimension.
void addValueName(UnitEntryPairTy InputUnitEntryPair, dwarf::Attribute Attr)
Add value name to the built name.
Error addTemplateArguments(UnitEntryPairTy InputUnitEntryPair)
Add the template arguments of InputUnitEntryPair 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.
ArrayRef< CharT > arrayRefFromStringRef(StringRef Input)
Construct an array ref of bytes from a string ref.
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.
XXH128_hash_t xxh3_128bits(ArrayRef< uint8_t > data)
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.
The return value from 128-bit hashes.
uint64_t low64
value & 0xFFFFFFFFFFFFFFFF
uint64_t high64
value >> 64
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