20 std::optional<std::pair<size_t, size_t>> ChildIndex) {
23 assert(Info.needToPlaceInTypeTable() &&
24 "Cann't assign name for non-type DIE");
42 if (CurChild->getTag() == dwarf::DW_TAG_subrange_type ||
43 CurChild->getTag() == dwarf::DW_TAG_generic_subrange) {
45 if (std::optional<DWARFFormValue> Val =
46 InputUnitEntryPair.
CU->
find(CurChild, dwarf::DW_AT_count)) {
47 if (std::optional<uint64_t> ConstVal = Val->getAsUnsignedConstant()) {
49 }
else if (std::optional<int64_t> ConstVal =
50 Val->getAsSignedConstant()) {
62 bool addTemplateParameters) {
76 if (addTemplateParameters &&
77 (ChildTag == dwarf::DW_TAG_template_type_parameter ||
78 ChildTag == dwarf::DW_TAG_template_value_parameter))
80 else if (ChildTag == dwarf::DW_TAG_formal_parameter ||
81 ChildTag == dwarf::DW_TAG_unspecified_parameters)
83 else if (addTemplateParameters &&
84 ChildTag == dwarf::DW_TAG_GNU_template_parameter_pack) {
89 TemplateParameters.
push_back(CurGNUChild);
90 }
else if (ChildTag == dwarf::DW_TAG_GNU_formal_parameter_pack) {
95 FunctionParameters.
push_back(CurGNUChild);
132 if (!TemplateParameters.
empty()) {
138 if (Parameter->getTag() == dwarf::DW_TAG_template_value_parameter) {
139 if (std::optional<DWARFFormValue> Val =
140 CU.find(Parameter, dwarf::DW_AT_const_value)) {
141 if (std::optional<uint64_t> ConstVal = Val->getAsUnsignedConstant())
143 else if (std::optional<int64_t> ConstVal = Val->getAsSignedConstant())
158 std::pair<size_t, size_t> ChildIdx) {
167static std::optional<UnitEntryPairTy>
170 case dwarf::DW_TAG_null:
171 case dwarf::DW_TAG_compile_unit:
172 case dwarf::DW_TAG_partial_unit:
173 case dwarf::DW_TAG_type_unit:
174 case dwarf::DW_TAG_skeleton_unit: {
177 case dwarf::DW_TAG_namespace: {
179 if (UnitEntryPair.
CU->
find(UnitEntryPair.
DieEntry, dwarf::DW_AT_extension))
183 if (!UnitEntryPair.
CU->
find(UnitEntryPair.
DieEntry, dwarf::DW_AT_name))
186 return UnitEntryPair;
189 return UnitEntryPair;
195 std::optional<UnitEntryPairTy> UnitEntryPair = InputUnitEntryPair.
getParent();
204 UnitEntryPair->CU->getDieTypeEntry(UnitEntryPair->DieEntry)) {
213 Parents.push_back(*UnitEntryPair);
215 UnitEntryPair = UnitEntryPair->getParent();
223 }
while (!UnitEntryPair->CU->getDieTypeEntry(UnitEntryPair->DieEntry));
240 if (std::optional<DWARFFormValue> DeclFileVal = InputUnitEntryPair.
CU->
find(
241 InputUnitEntryPair.
DieEntry, dwarf::DW_AT_decl_file)) {
242 if (std::optional<DWARFFormValue> DeclLineVal = InputUnitEntryPair.
CU->
find(
243 InputUnitEntryPair.
DieEntry, dwarf::DW_AT_decl_line)) {
244 if (std::optional<std::pair<StringRef, StringRef>> DirAndFilename =
250 if (std::optional<uint64_t> DeclLineIntVal =
256 HasDeclFileName =
true;
264 if (std::optional<DWARFFormValue> Val =
266 if (std::optional<uint64_t> ConstVal = Val->getAsUnsignedConstant()) {
269 }
else if (std::optional<int64_t> ConstVal = Val->getAsSignedConstant()) {
279 bool FirstIteration =
true;
281 if (std::optional<DWARFFormValue> AttrValue =
283 std::optional<UnitEntryPairTy> RefDie =
290 if (!RefDie->DieEntry)
292 "Cann't resolve DIE reference");
300 std::errc::invalid_argument,
301 "Cann't parse input DWARF. Recursive dependence.");
304 addDIETypeName(*RefDie, std::nullopt, AssignNameToTypeDescriptor))
307 FirstIteration =
false;
315 bool AddParentNames) {
316 bool HasLinkageName =
false;
317 bool HasShortName =
false;
318 bool HasTemplatesInShortName =
false;
319 bool HasDeclFileName =
false;
322 if (std::optional<DWARFFormValue> Val = InputUnitEntryPair.
CU->
find(
324 {dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_AT_linkage_name})) {
327 HasLinkageName =
true;
328 }
else if (std::optional<DWARFFormValue> Val = InputUnitEntryPair.
CU->
find(
329 InputUnitEntryPair.
DieEntry, dwarf::DW_AT_name)) {
335 HasTemplatesInShortName =
336 Name.ends_with(
">") && Name.count(
"<") != 0 && !Name.ends_with(
"<=>");
344 case dwarf::DW_TAG_union_type:
345 case dwarf::DW_TAG_interface_type:
346 case dwarf::DW_TAG_class_type:
347 case dwarf::DW_TAG_structure_type:
348 case dwarf::DW_TAG_subroutine_type:
349 case dwarf::DW_TAG_subprogram: {
351 dwarf::DW_AT_artificial))
359 addSignature(InputUnitEntryPair, !HasTemplatesInShortName))
362 case dwarf::DW_TAG_coarray_type:
363 case dwarf::DW_TAG_array_type: {
366 case dwarf::DW_TAG_subrange_type: {
369 case dwarf::DW_TAG_template_value_parameter: {
370 if (!HasTemplatesInShortName) {
372 addValueName(InputUnitEntryPair, dwarf::DW_AT_const_value);
382 if ((!HasLinkageName && !HasShortName && !HasDeclFileName) ||
396 std::optional<std::pair<size_t, size_t>> ChildIndex,
397 bool AssignNameToTypeDescriptor) {
398 std::optional<UnitEntryPairTy> UnitEntryPair =
424 if (AssignNameToTypeDescriptor) {
443 "expected a DW_TAG_member");
452 return !
CU.find(DieEntry, {dwarf::DW_AT_data_member_location,
453 dwarf::DW_AT_data_bit_offset});
458 switch (DieEntry->
getTag()) {
459 case dwarf::DW_TAG_base_type: {
462 case dwarf::DW_TAG_namespace: {
465 case dwarf::DW_TAG_formal_parameter: {
469 case dwarf::DW_TAG_unspecified_parameters: {
472 case dwarf::DW_TAG_template_type_parameter: {
476 case dwarf::DW_TAG_template_value_parameter: {
479 case dwarf::DW_TAG_GNU_formal_parameter_pack: {
482 case dwarf::DW_TAG_GNU_template_parameter_pack: {
485 case dwarf::DW_TAG_inheritance: {
488 case dwarf::DW_TAG_array_type: {
491 case dwarf::DW_TAG_class_type: {
494 case dwarf::DW_TAG_enumeration_type: {
497 case dwarf::DW_TAG_imported_declaration: {
500 case dwarf::DW_TAG_member: {
508 case dwarf::DW_TAG_pointer_type: {
511 case dwarf::DW_TAG_reference_type: {
514 case dwarf::DW_TAG_string_type: {
517 case dwarf::DW_TAG_structure_type: {
520 case dwarf::DW_TAG_subroutine_type: {
523 case dwarf::DW_TAG_typedef: {
526 case dwarf::DW_TAG_union_type: {
529 case dwarf::DW_TAG_variant: {
532 case dwarf::DW_TAG_inlined_subroutine: {
535 case dwarf::DW_TAG_module: {
538 case dwarf::DW_TAG_ptr_to_member_type: {
541 case dwarf::DW_TAG_set_type: {
544 case dwarf::DW_TAG_subrange_type: {
547 case dwarf::DW_TAG_with_stmt: {
550 case dwarf::DW_TAG_access_declaration: {
553 case dwarf::DW_TAG_catch_block: {
556 case dwarf::DW_TAG_const_type: {
559 case dwarf::DW_TAG_constant: {
562 case dwarf::DW_TAG_enumerator: {
565 case dwarf::DW_TAG_file_type: {
568 case dwarf::DW_TAG_friend: {
571 case dwarf::DW_TAG_namelist: {
574 case dwarf::DW_TAG_namelist_item: {
577 case dwarf::DW_TAG_packed_type: {
580 case dwarf::DW_TAG_subprogram: {
583 case dwarf::DW_TAG_thrown_type: {
586 case dwarf::DW_TAG_variant_part: {
589 case dwarf::DW_TAG_variable: {
592 case dwarf::DW_TAG_volatile_type: {
595 case dwarf::DW_TAG_dwarf_procedure: {
598 case dwarf::DW_TAG_restrict_type: {
601 case dwarf::DW_TAG_interface_type: {
604 case dwarf::DW_TAG_imported_module: {
607 case dwarf::DW_TAG_unspecified_type: {
610 case dwarf::DW_TAG_imported_unit: {
613 case dwarf::DW_TAG_condition: {
616 case dwarf::DW_TAG_shared_type: {
619 case dwarf::DW_TAG_rvalue_reference_type: {
622 case dwarf::DW_TAG_template_alias: {
625 case dwarf::DW_TAG_coarray_type: {
628 case dwarf::DW_TAG_generic_subrange: {
631 case dwarf::DW_TAG_dynamic_type: {
634 case dwarf::DW_TAG_atomic_type: {
637 case dwarf::DW_TAG_call_site: {
640 case dwarf::DW_TAG_call_site_parameter: {
643 case dwarf::DW_TAG_immutable_type: {
646 case dwarf::DW_TAG_entry_point: {
649 case dwarf::DW_TAG_label: {
652 case dwarf::DW_TAG_lexical_block: {
655 case dwarf::DW_TAG_common_block: {
658 case dwarf::DW_TAG_common_inclusion: {
661 case dwarf::DW_TAG_try_block: {
665 case dwarf::DW_TAG_null: {
668 case dwarf::DW_TAG_compile_unit: {
671 case dwarf::DW_TAG_partial_unit: {
674 case dwarf::DW_TAG_type_unit: {
677 case dwarf::DW_TAG_skeleton_unit: {
691 switch (DieEntry->
getTag()) {
692 case dwarf::DW_TAG_array_type:
693 case dwarf::DW_TAG_coarray_type:
694 case dwarf::DW_TAG_class_type:
695 case dwarf::DW_TAG_common_block:
696 case dwarf::DW_TAG_lexical_block:
697 case dwarf::DW_TAG_structure_type:
698 case dwarf::DW_TAG_subprogram:
699 case dwarf::DW_TAG_subroutine_type:
700 case dwarf::DW_TAG_union_type:
701 case dwarf::DW_TAG_GNU_template_template_param:
702 case dwarf::DW_TAG_GNU_formal_parameter_pack:
703 case dwarf::DW_TAG_GNU_template_parameter_pack: {
706 case dwarf::DW_TAG_enumeration_type: {
718 CurChild && CurChild->getAbbreviationDeclarationPtr();
719 CurChild =
CU.getSiblingEntry(CurChild)) {
725 "Wrong index for ChildIndexesWidth");
732 size_t digitsCounter = 1;
733 size_t NumToCompare = 15;
735 while (NumToCompare < Width) {
740 Width = digitsCounter;
750 switch (DieEntry->
getTag()) {
751 case dwarf::DW_TAG_unspecified_parameters:
752 case dwarf::DW_TAG_formal_parameter:
754 case dwarf::DW_TAG_template_value_parameter:
755 case dwarf::DW_TAG_template_type_parameter:
756 case dwarf::DW_TAG_GNU_template_template_param:
758 case dwarf::DW_TAG_enumeration_type:
759 if (std::optional<uint32_t> ParentIdx = DieEntry->
getParentIdx()) {
760 if (*ParentIdx &&
CU.getDebugInfoEntry(*ParentIdx)->getTag() ==
761 dwarf::DW_TAG_array_type)
765 case dwarf::DW_TAG_subrange_type:
767 case dwarf::DW_TAG_generic_subrange:
769 case dwarf::DW_TAG_enumerator:
771 case dwarf::DW_TAG_namelist_item:
773 case dwarf::DW_TAG_member:
784std::optional<std::pair<size_t, size_t>>
792 "Wrong index for ChildIndexesWidth");
794 "Index width exceeds 16 digits.");
796 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 bool isStaticDataMember(CompileUnit &CU, const DWARFDebugInfoEntry *DieEntry)
A C++ static data member is spelled as a DW_TAG_member carrying DW_AT_declaration in DWARF 4 and as a...
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
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
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.
Stores all information relating to a compile unit, be it in its original instance in the object file ...
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 addParentName(UnitEntryPairTy &InputUnitEntryPair)
Add names of parent dies to the built name.
void addOrderedName(CompileUnit &CU, const DWARFDebugInfoEntry *DieEntry)
Add ordered name to the built name.
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.
size_t RecursionDepth
Recursion counter.
SmallString< 1000 > SyntheticName
Buffer keeping bult 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...
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()
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