27 :
InUnit.getOrigUnit().getNextUnitOffset();
37 InUnit.getContainingFile().Addresses->applyValidRelocs(DIECopy,
Offset,
38 Data.isLittleEndian());
44 const auto *Abbrev =
InputDieEntry->getAbbreviationDeclarationPtr();
49 for (
const auto &AttrSpec : Abbrev->attributes()) {
66 bool MayHaveRelocs =
false;
67 switch (AttrSpec.Form) {
68 case dwarf::DW_FORM_strp:
69 case dwarf::DW_FORM_line_strp:
70 case dwarf::DW_FORM_string:
71 case dwarf::DW_FORM_strx:
72 case dwarf::DW_FORM_strx1:
73 case dwarf::DW_FORM_strx2:
74 case dwarf::DW_FORM_strx3:
75 case dwarf::DW_FORM_strx4:
78 case dwarf::DW_FORM_ref_addr:
79 case dwarf::DW_FORM_ref1:
80 case dwarf::DW_FORM_ref2:
81 case dwarf::DW_FORM_ref4:
82 case dwarf::DW_FORM_ref8:
83 case dwarf::DW_FORM_ref_udata:
86 case dwarf::DW_FORM_data1:
87 case dwarf::DW_FORM_data2:
88 case dwarf::DW_FORM_data4:
89 case dwarf::DW_FORM_data8:
90 case dwarf::DW_FORM_udata:
91 case dwarf::DW_FORM_sdata:
92 case dwarf::DW_FORM_sec_offset:
93 case dwarf::DW_FORM_flag:
94 case dwarf::DW_FORM_flag_present:
95 case dwarf::DW_FORM_rnglistx:
96 case dwarf::DW_FORM_loclistx:
97 case dwarf::DW_FORM_implicit_const:
100 case dwarf::DW_FORM_block:
101 case dwarf::DW_FORM_block1:
102 case dwarf::DW_FORM_block2:
103 case dwarf::DW_FORM_block4:
104 case dwarf::DW_FORM_exprloc:
106 MayHaveRelocs =
true;
108 case dwarf::DW_FORM_addr:
109 case dwarf::DW_FORM_addrx:
110 case dwarf::DW_FORM_addrx1:
111 case dwarf::DW_FORM_addrx2:
112 case dwarf::DW_FORM_addrx3:
113 case dwarf::DW_FORM_addrx4:
115 MayHaveRelocs =
true;
118 InUnit.warn(
"unsupported attribute form " +
120 " in DieAttributeCloner::clone(). Dropping.",
125 OutUnit.getAsCompileUnit()->getRelocFixups().noteAttribute(
126 InputDieEntry->getTag(), AttrSpec.Attr, InputAttrStartOffset,
127 InputAttrEndOffset, OutputAttrOffset,
Source);
133 std::optional<StringRef> InstallName =
134 InUnit.getContainingFile().Addresses->getLibraryInstallName();
137 dwarf::DW_AT_APPLE_origin,
138 InUnit.getGlobalData().getStringPool().insert(*InstallName).first);
148 &
OutUnit->getOrCreateSectionDescriptor(
155 .addScalarAttribute(dwarf::DW_AT_str_offsets_base,
156 dwarf::DW_FORM_sec_offset,
157 OutUnit->getDebugStrOffsetsHeaderSize())
165 !
InUnit.getGlobalData().getOptions().UpdateIndexTablesOnly) {
174 .addScalarAttribute(dwarf::DW_AT_addr_base,
175 dwarf::DW_FORM_sec_offset,
176 OutUnit->getDebugAddrHeaderSize())
183 switch (AttrSpec.
Attr) {
186 case dwarf::DW_AT_low_pc:
187 case dwarf::DW_AT_high_pc:
188 case dwarf::DW_AT_ranges:
189 if (
InUnit.getGlobalData().getOptions().UpdateIndexTablesOnly)
196 case dwarf::DW_AT_rnglists_base:
201 return !
InUnit.getGlobalData().getOptions().UpdateIndexTablesOnly;
202 case dwarf::DW_AT_loclists_base:
207 return !
InUnit.getGlobalData().getOptions().UpdateIndexTablesOnly;
208 case dwarf::DW_AT_location:
209 case dwarf::DW_AT_frame_base:
210 if (
InUnit.getGlobalData().getOptions().UpdateIndexTablesOnly)
230 InUnit.warn(
"cann't read string attribute.");
235 std::string RemappedPath;
236 if (File.PrefixMap &&
238 RemappedPath = File.remapPath(*
String);
239 String = RemappedPath.c_str();
243 InUnit.getGlobalData().getStringPool().insert(*String).first;
246 if (AttrSpec.
Attr == dwarf::DW_AT_name)
248 else if (AttrSpec.
Attr == dwarf::DW_AT_MIPS_linkage_name ||
249 AttrSpec.
Attr == dwarf::DW_AT_linkage_name)
250 AttrInfo.MangledName = StringInPool;
251 else if (AttrSpec.
Attr == dwarf::DW_AT_APPLE_origin) {
254 std::optional<StringRef> InstallName =
255 InUnit.getContainingFile().Addresses->getLibraryInstallName();
258 InUnit.getGlobalData().getStringPool().insert(*InstallName).first;
261 if (AttrSpec.
Form == dwarf::DW_FORM_line_strp) {
271 .addStringPlaceholderAttribute(AttrSpec.
Attr, dwarf::DW_FORM_line_strp)
289 return Generator.addStringPlaceholderAttribute(Attr, dwarf::DW_FORM_strp)
294 .addIndexedStringAttribute(Attr, dwarf::DW_FORM_strx,
302 if (AttrSpec.
Attr == dwarf::DW_AT_sibling)
305 std::optional<UnitEntryPairTy> RefDiePair =
307 if (!RefDiePair || !RefDiePair->DieEntry) {
315 RefDiePair->CU->getDIEInfo(RefDiePair->DieEntry);
317 RefTypeName = RefDiePair->CU->getDieTypeEntry(RefDiePair->DieEntry);
325 if (RefDiePair->DieEntry->getTag() == dwarf::DW_TAG_module &&
326 AttrSpec.
Attr == dwarf::DW_AT_import && !
OutUnit.isTypeUnit() &&
329 if (RefDiePair->CU->getModulePath(RefDiePair->DieEntry, Path)) {
331 InUnit.getGlobalData().getModulePool().getOrCreate(Path);
336 RefDiePair->CU->getDIEIndex(RefDiePair->DieEntry), Anchor},
339 .addScalarAttribute(AttrSpec.
Attr, dwarf::DW_FORM_ref_addr, 0xBADDEF)
345 assert(RefTypeName &&
"Type name for referenced DIE is not set");
347 "Type name for DIE is not set");
354 .addScalarAttribute(AttrSpec.
Attr, dwarf::DW_FORM_ref4, 0xBADDEF)
363 .addScalarAttribute(AttrSpec.
Attr, dwarf::DW_FORM_ref_addr, 0xBADDEF)
368 uint64_t OutDieOffset = RefDiePair->CU->getDieOutOffset(RefDiePair->DieEntry);
371 bool IsLocal =
OutUnit->getUniqueID() == RefDiePair->CU->getUniqueID();
374 dwarf::Form NewForm = IsLocal ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr;
378 if (IsLocal && (OutDieOffset != 0))
379 return Generator.addScalarAttribute(AttrSpec.
Attr, NewForm, OutDieOffset)
387 RefDiePair->CU->getDIEIndex(RefDiePair->DieEntry)},
389 return Generator.addScalarAttribute(AttrSpec.
Attr, NewForm, 0xBADDEF).second;
399 switch (AttrSpec.
Attr) {
400 case dwarf::DW_AT_macro_info: {
403 InUnit.getContainingFile().Dwarf->getDebugMacinfo();
409 &
OutUnit->getOrCreateSectionDescriptor(
414 case dwarf::DW_AT_macros: {
417 InUnit.getContainingFile().Dwarf->getDebugMacro();
423 &
OutUnit->getOrCreateSectionDescriptor(
428 case dwarf::DW_AT_stmt_list: {
434 case dwarf::DW_AT_str_offsets_base: {
437 &
OutUnit->getOrCreateSectionDescriptor(
444 AttrInfo.HasStringOffsetBaseAttr =
true;
446 .addScalarAttribute(AttrSpec.
Attr, AttrSpec.
Form,
447 OutUnit->getDebugStrOffsetsHeaderSize())
450 case dwarf::DW_AT_decl_file: {
457 if (std::optional<std::pair<StringRef, StringRef>> DirAndFilename =
458 InUnit.getDirAndFilenameFromLineTable(Val))
464 .insert(DirAndFilename->first)
468 .insert(DirAndFilename->second)
479 if (AttrSpec.
Attr == dwarf::DW_AT_const_value &&
484 if (
InUnit.getGlobalData().getOptions().UpdateIndexTablesOnly) {
486 Value = *OptionalValue;
488 Value = *OptionalValue;
490 Value = *OptionalValue;
492 InUnit.warn(
"unsupported scalar attribute form. Dropping attribute.",
497 if (AttrSpec.
Attr == dwarf::DW_AT_declaration &&
Value)
500 if (AttrSpec.
Form == dwarf::DW_FORM_loclistx)
509 if (AttrSpec.
Form == dwarf::DW_FORM_rnglistx) {
518 std::optional<uint64_t>
Offset =
519 InUnit.getOrigUnit().getRnglistOffset(*Index);
526 ResultingForm = dwarf::DW_FORM_sec_offset;
527 }
else if (AttrSpec.
Form == dwarf::DW_FORM_loclistx) {
536 std::optional<uint64_t>
Offset =
537 InUnit.getOrigUnit().getLoclistOffset(*Index);
544 ResultingForm = dwarf::DW_FORM_sec_offset;
545 }
else if (AttrSpec.
Attr == dwarf::DW_AT_high_pc &&
550 std::optional<uint64_t> LowPC =
OutUnit.getAsCompileUnit()->getLowPc();
554 Value =
OutUnit.getAsCompileUnit()->getHighPc() - *LowPC;
555 }
else if (AttrSpec.
Form == dwarf::DW_FORM_sec_offset)
557 else if (AttrSpec.
Form == dwarf::DW_FORM_sdata)
560 Value = *OptionalValue;
562 InUnit.warn(
"unsupported scalar attribute form. Dropping attribute.",
567 if (AttrSpec.
Attr == dwarf::DW_AT_ranges ||
568 AttrSpec.
Attr == dwarf::DW_AT_start_scope) {
578 InUnit.getOrigUnit().getVersion())) {
579 int64_t AddrAdjustmentValue = 0;
588 }
else if (AttrSpec.
Attr == dwarf::DW_AT_addr_base) {
600 .addScalarAttribute(AttrSpec.
Attr, AttrSpec.
Form,
601 OutUnit->getDebugAddrHeaderSize())
603 }
else if (AttrSpec.
Attr == dwarf::DW_AT_declaration &&
Value)
613 if (AttrSpec.
Attr == dwarf::DW_AT_LLVM_stmt_sequence &&
619 if (AttrSpec.
Attr == dwarf::DW_AT_high_pc &&
630 if (AttrSpec.
Attr == dwarf::DW_AT_LLVM_stmt_sequence) {
636 OutUnit.getAsCompileUnit()->noteStmtSeqListAttribute(&Result.first,
Value);
644 return Result.second;
651 switch (
Op.getCode()) {
652 case dwarf::DW_OP_addr:
653 case dwarf::DW_OP_addrx:
654 case dwarf::DW_OP_constx:
682 InUnit.getFormParams().Format);
692 InUnit.cloneDieAttrExpression(
701 if ((ResultForm == dwarf::DW_FORM_block1 && Bytes.
size() > UINT8_MAX) ||
702 (ResultForm == dwarf::DW_FORM_block2 && Bytes.
size() > UINT16_MAX) ||
703 (ResultForm == dwarf::DW_FORM_block4 && Bytes.
size() > UINT32_MAX))
704 ResultForm = dwarf::DW_FORM_block;
706 size_t FinalAttributeSize;
707 if (AttrSpec.
Form == dwarf::DW_FORM_exprloc)
709 Generator.addLocationAttribute(AttrSpec.
Attr, ResultForm, Bytes).second;
712 Generator.addBlockAttribute(AttrSpec.
Attr, ResultForm, Bytes).second;
715 for (
size_t Idx = NumberOfPatchesAtStart; Idx <
PatchesOffsets.size();
723 Source.Expression->addOutputPrefix(FinalAttributeSize - Bytes.
size());
728 InUnit.getGlobalData().getOptions().UpdateIndexTablesOnly;
730 return FinalAttributeSize;
736 if (AttrSpec.
Attr == dwarf::DW_AT_low_pc)
739 if (
InUnit.getGlobalData().getOptions().UpdateIndexTablesOnly)
759 std::optional<DWARFFormValue> AddrAttribute =
764 std::optional<uint64_t> Addr = AddrAttribute->getAsAddress();
766 InUnit.warn(
"cann't read address attribute value.");
771 AttrSpec.
Attr == dwarf::DW_AT_low_pc) {
772 if (std::optional<uint64_t> LowPC =
OutUnit.getAsCompileUnit()->getLowPc())
776 }
else if (
InputDieEntry->getTag() == dwarf::DW_TAG_compile_unit &&
777 AttrSpec.
Attr == dwarf::DW_AT_high_pc) {
778 if (uint64_t HighPc =
OutUnit.getAsCompileUnit()->getHighPc())
783 if (AttrSpec.
Attr == dwarf::DW_AT_high_pc)
791 if (AttrSpec.
Form == dwarf::DW_FORM_addr) {
796 uint64_t AddrIndex =
OutUnit.getAsCompileUnit()->getDebugAddrIndex(*Addr);
798 std::optional<uint64_t> InputOffset =
804 .addScalarAttribute(AttrSpec.
Attr, dwarf::Form::DW_FORM_addrx, AddrIndex)
811 std::optional<uint64_t> LowPC =
815 uint64_t Constrained =
816 InUnit.getContainingFile().Addresses->constrainCodeRangeHighPC(
818 return IsLength ? Constrained - *LowPC : Constrained;
823 size_t AbbrevNumberSize =
827 OutUnit.getAsCompileUnit()->getRelocFixups().finishDIE(AbbrevNumberSize);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static bool expressionDependsOnOriginUnit(const DWARFExpression &Expr)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
This class represents an Operation in the Expression.
Encoding
Size and signedness of expression operations' operands.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM Value Representation.
This class represents DWARF information for source file and it's address map.
size_t cloneBlockAttr(const DWARFFormValue &Val, const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec)
Clone block or exprloc attribute.
AttributesInfo AttrInfo
Cannot be used concurrently.
CompileUnit & InUnit
Input compilation unit.
bool HasLocationExpressionAddress
Indicates whether InputDieEntry has an location attribute containg address expression.
SectionDescriptor & DebugInfoOutputSection
.debug_info section descriptor.
size_t addStringAttr(dwarf::Attribute Attr, StringEntry *String)
Add the string attribute Attr, in the string form of the unit.
unsigned finalizeAbbreviations(bool HasChildrenToClone)
Create abbreviations for the output DIE after all attributes are cloned.
unsigned AttrOutOffset
Output offset after all attributes.
DIEGenerator & Generator
Output DIE generator.
size_t cloneScalarAttr(const DWARFFormValue &Val, const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec)
Clone scalar attribute.
OffsetsPtrVector PatchesOffsets
Patches for the cloned attributes.
void clone()
Clone attributes of input DIE.
size_t cloneDieRefAttr(const DWARFFormValue &Val, const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec)
Clone attribute referencing another DIE.
bool shouldSkipAttribute(DWARFAbbreviationDeclaration::AttributeSpec AttrSpec)
Returns true if attribute should be skipped.
size_t cloneStringAttr(const DWARFFormValue &Val, const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec)
Clone string attribute.
const DWARFDebugInfoEntry * InputDieEntry
Input DIE entry.
std::optional< int64_t > FuncAddressAdjustment
Relocation adjustment for the function address ranges.
RelocationFixups::AttributeSource Source
CompileUnit::OutputUnitVariantPtr OutUnit
Output unit(either "plain" compilation unit, either artificial type unit).
size_t cloneAddressAttr(const DWARFFormValue &Val, const DWARFAbbreviationDeclaration::AttributeSpec &AttrSpec)
Clone address attribute.
uint32_t InputDIEIdx
Input DIE index.
std::optional< int64_t > VarAddressAdjustment
Relocation adjustment for the variable locations.
uint64_t constrainHighPC(uint64_t HighPC, bool IsLength)
Returns the input DIE's DW_AT_high_pc value HighPC, constrained so the code range it ends stays clear...
bool Use_DW_FORM_strp
This flag forces using DW_FORM_strp for string attributes.
LLVM_ABI StringRef FormEncodingString(unsigned Encoding)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
StringMapEntry< std::atomic< TypeEntryBody * > > TypeEntry
StringMapEntry< EmptyStringSetTag > StringEntry
StringEntry keeps data of the string: the length, external offset and a string body which is placed r...
bool isPathAttribute(dwarf::Tag Tag, dwarf::Attribute Attr)
std::optional< uint64_t > toAddress(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an address.
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
LLVM_ABI bool doesFormBelongToClass(dwarf::Form Form, DWARFFormValue::FormClass FC, uint16_t DwarfVersion)
Check whether specified Form belongs to the FC class.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
DWARFExpression::Operation Op
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
static LLVM_ABI bool mayHaveLocationList(dwarf::Attribute Attr)
Identify DWARF attributes that may contain a pointer to a location list.
static LLVM_ABI bool mayHaveLocationExpr(dwarf::Attribute Attr)
Identifies DWARF attributes that may contain a reference to a DWARF expression.
An address attribute cloned from one .debug_addr entry into another.
Information gathered about source DIEs.
bool needToPlaceInTypeTable() const
This structure is used to update a DW_AT_import reference to a DW_TAG_module.
This structure is used to update reference to the DIE.
This structure is used to update reference to the type DIE.
This structure is used to update strings offsets into .debug_line_str.
This structure is used to update location list offset into .debug_loc/.debug_loclists.
This structure is used to update range list offset into .debug_ranges/.debug_rnglists.
This structure is used to update strings offsets into .debug_str.
This structure is used to update reference to the type DIE.
Where the DW_TAG_module DIE describing a clang module ended up in the output.