9#ifndef LLVM_DEBUGINFO_DWARF_DWARFDEBUGFRAME_H
10#define LLVM_DEBUGINFO_DWARF_DWARFDEBUGFRAME_H
25class DWARFDataExtractor;
70 std::optional<uint32_t> AddrSpace;
72 std::optional<DWARFExpression> Expr;
81 AddrSpace(
std::nullopt), Dereference(
false) {}
84 std::optional<uint32_t> AS,
bool Deref)
85 : Kind(K), RegNum(
Reg), Offset(Off), AddrSpace(AS), Dereference(Deref) {}
87 UnwindLocation(DWARFExpression
E,
bool Deref)
118 static UnwindLocation
120 std::optional<uint32_t> AddrSpace = std::nullopt);
121 static UnwindLocation
123 std::optional<uint32_t> AddrSpace = std::nullopt);
146 void setOffset(int32_t NewOffset) { Offset = NewOffset; }
183 std::map<uint32_t, UnwindLocation> Locations;
193 auto Pos = Locations.find(RegNum);
194 if (Pos == Locations.end())
205 Locations.erase(RegNum);
206 Locations.insert(std::make_pair(RegNum, Location));
230 size_t size()
const {
return Locations.size(); }
233 return Locations ==
RHS.Locations;
258 std::optional<uint64_t> Address;
307 unsigned IndentLevel = 0)
const;
327 size_t size()
const {
return Rows.size(); }
352 unsigned IndentLevel = 0)
const;
378 std::optional<uint64_t> EndAddress;
439 unsigned size()
const {
return (
unsigned)Instructions.size(); }
440 bool empty()
const {
return Instructions.empty(); }
442 int64_t
dataAlign()
const {
return DataAlignmentFactor; }
447 : CodeAlignmentFactor(CodeAlignmentFactor),
448 DataAlignmentFactor(DataAlignmentFactor),
458 std::optional<uint64_t> InitialLocation)
const;
466 std::vector<Instruction> Instructions;
468 const int64_t DataAlignmentFactor;
479 Instructions.back().Ops.push_back(Operand1);
484 Instructions.push_back(Instruction(Opcode));
485 Instructions.back().Ops.push_back(Operand1);
486 Instructions.back().Ops.push_back(Operand2);
509 OT_FactoredCodeOffset,
510 OT_SignedFactDataOffset,
511 OT_UnsignedFactDataOffset,
518 static const char *operandTypeString(OperandType OT);
522 static ArrayRef<OperandType[MaxOperands]> getOperandTypes();
525 void printOperand(raw_ostream &
OS, DIDumpOptions DumpOpts,
526 const Instruction &Instr,
unsigned OperandIdx,
539 CFIs(CodeAlign, DataAlign, Arch) {}
573 uint8_t SegmentDescriptorSize,
uint64_t CodeAlignmentFactor,
574 int64_t DataAlignmentFactor,
uint64_t ReturnAddressRegister,
576 uint32_t LSDAPointerEncoding, std::optional<uint64_t> Personality,
579 DataAlignmentFactor, Arch),
580 Version(Version), Augmentation(
std::
move(Augmentation)),
581 AddressSize(AddressSize), SegmentDescriptorSize(SegmentDescriptorSize),
582 CodeAlignmentFactor(CodeAlignmentFactor),
583 DataAlignmentFactor(DataAlignmentFactor),
584 ReturnAddressRegister(ReturnAddressRegister),
585 AugmentationData(
std::
move(AugmentationData)),
586 FDEPointerEncoding(FDEPointerEncoding),
587 LSDAPointerEncoding(LSDAPointerEncoding), Personality(Personality),
588 PersonalityEnc(PersonalityEnc) {}
599 return PersonalityEnc;
612 const uint8_t Version;
614 const uint8_t AddressSize;
615 const uint8_t SegmentDescriptorSize;
617 const int64_t DataAlignmentFactor;
618 const uint64_t ReturnAddressRegister;
624 const std::optional<uint64_t> Personality;
625 const std::optional<uint32_t> PersonalityEnc;
635 Cie ? Cie->getCodeAlignmentFactor() : 0,
637 CIEPointer(CIEPointer), InitialLocation(InitialLocation),
660 const CIE *LinkedCIE;
661 const std::optional<uint64_t> LSDAAddress;
674 std::vector<std::unique_ptr<dwarf::FrameEntry>> Entries;
686 bool IsEH =
false,
uint64_t EHFrameAddress = 0);
691 std::optional<uint64_t>
Offset)
const;
698 bool empty()
const {
return Entries.empty(); }
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static int getDataAlignmentFactor(MCStreamer &streamer)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
A class that represents an address range.
A parsed .debug_frame or .eh_frame section.
iterator_range< iterator > entries() const
void dump(raw_ostream &OS, DIDumpOptions DumpOpts, std::optional< uint64_t > Offset) const
Dump the section data into the given stream.
iterator begin() const
DWARF Frame entries accessors.
uint64_t getEHFrameAddress() const
bool empty() const
Return whether the section has any entries.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
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.
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
Represent a sequence of Call Frame Information instructions that, when read in order,...
std::vector< Instruction > InstrList
const_iterator end() const
InstrList::const_iterator const_iterator
void dump(raw_ostream &OS, DIDumpOptions DumpOpts, unsigned IndentLevel, std::optional< uint64_t > InitialLocation) const
Triple::ArchType triple() const
InstrList::iterator iterator
uint64_t codeAlign() const
static constexpr size_t MaxOperands
SmallVector< uint64_t, MaxOperands > Operands
const_iterator begin() const
void addInstruction(const Instruction &I)
CFIProgram(uint64_t CodeAlignmentFactor, int64_t DataAlignmentFactor, Triple::ArchType Arch)
int64_t dataAlign() const
StringRef callFrameString(unsigned Opcode) const
Get a DWARF CFI call frame string for the given DW_CFA opcode.
DWARF Common Information Entry (CIE)
static bool classof(const FrameEntry *FE)
CIE(bool IsDWARF64, uint64_t Offset, uint64_t Length, uint8_t Version, SmallString< 8 > Augmentation, uint8_t AddressSize, uint8_t SegmentDescriptorSize, uint64_t CodeAlignmentFactor, int64_t DataAlignmentFactor, uint64_t ReturnAddressRegister, SmallString< 8 > AugmentationData, uint32_t FDEPointerEncoding, uint32_t LSDAPointerEncoding, std::optional< uint64_t > Personality, std::optional< uint32_t > PersonalityEnc, Triple::ArchType Arch)
uint64_t getReturnAddressRegister() const
uint8_t getVersion() const
int64_t getDataAlignmentFactor() const
std::optional< uint32_t > getPersonalityEncoding() const
std::optional< uint64_t > getPersonalityAddress() const
StringRef getAugmentationData() const
uint64_t getCodeAlignmentFactor() const
void dump(raw_ostream &OS, DIDumpOptions DumpOpts) const override
Dump the instructions in this CFI fragment.
uint32_t getLSDAPointerEncoding() const
uint32_t getFDEPointerEncoding() const
StringRef getAugmentationString() const
DWARF Frame Description Entry (FDE)
uint64_t getAddressRange() const
uint64_t getInitialLocation() const
uint64_t getCIEPointer() const
std::optional< uint64_t > getLSDAAddress() const
const CIE * getLinkedCIE() const
static bool classof(const FrameEntry *FE)
FDE(bool IsDWARF64, uint64_t Offset, uint64_t Length, uint64_t CIEPointer, uint64_t InitialLocation, uint64_t AddressRange, CIE *Cie, std::optional< uint64_t > LSDAAddress, Triple::ArchType Arch)
void dump(raw_ostream &OS, DIDumpOptions DumpOpts) const override
Dump the instructions in this CFI fragment.
An entry in either debug_frame or eh_frame.
FrameEntry(FrameKind K, bool IsDWARF64, uint64_t Offset, uint64_t Length, uint64_t CodeAlign, int64_t DataAlign, Triple::ArchType Arch)
const uint64_t Length
Entry length as specified in DWARF.
const uint64_t Offset
Offset of this entry in the section.
virtual ~FrameEntry()=default
virtual void dump(raw_ostream &OS, DIDumpOptions DumpOpts) const =0
Dump the instructions in this CFI fragment.
const CFIProgram & cfis() const
FrameKind getKind() const
uint64_t getLength() const
uint64_t getOffset() const
A class that can track all registers with locations in a UnwindRow object.
bool operator==(const RegisterLocations &RHS) const
std::optional< UnwindLocation > getRegisterLocation(uint32_t RegNum) const
Return the location for the register in RegNum if there is a location.
void dump(raw_ostream &OS, DIDumpOptions DumpOpts) const
Dump all registers + locations that are currently defined in this object.
void setRegisterLocation(uint32_t RegNum, const UnwindLocation &Location)
Set the location for the register in RegNum to Location.
bool hasLocations() const
Returns true if we have any register locations in this object.
void removeRegisterLocation(uint32_t RegNum)
Removes any rule for the register in RegNum.
A class that represents a location for the Call Frame Address (CFA) or a register.
static UnwindLocation createUndefined()
Create a location where the value is undefined and not available.
void setConstant(int32_t Value)
Some opcodes modify a constant value and we need to be able to update the constant value (DW_CFA_GNU_...
void setOffset(int32_t NewOffset)
Some opcodes will modify the CFA location's offset only, so we need to be able to modify the CFA offs...
uint32_t getRegister() const
static UnwindLocation createAtRegisterPlusOffset(uint32_t Reg, int32_t Off, std::optional< uint32_t > AddrSpace=std::nullopt)
static UnwindLocation createIsRegisterPlusOffset(uint32_t Reg, int32_t Off, std::optional< uint32_t > AddrSpace=std::nullopt)
Create a location where the saved value is in (Deref == false) or at (Deref == true) a regiser plus a...
int32_t getOffset() const
static UnwindLocation createAtDWARFExpression(DWARFExpression Expr)
static UnwindLocation createUnspecified()
Create a location whose rule is set to Unspecified.
static UnwindLocation createIsDWARFExpression(DWARFExpression Expr)
Create a location whose value is the result of evaluating a DWARF expression.
@ Undefined
Register is not available and can't be recovered.
@ Constant
Value is a constant value contained in "Offset": reg = Offset.
@ DWARFExpr
Register or CFA value is in or at a value found by evaluating a DWARF expression: reg = eval(dwarf_ex...
@ Same
Register value is in the register, nothing needs to be done to unwind it: reg = reg.
@ CFAPlusOffset
Register is in or at the CFA plus an offset: reg = CFA + offset reg = defef(CFA + offset)
@ Unspecified
Not specified.
@ RegPlusOffset
Register or CFA is in or at a register plus offset, optionally in an address space: reg = reg + offse...
Location getLocation() const
static UnwindLocation createIsConstant(int32_t Value)
void dump(raw_ostream &OS, DIDumpOptions DumpOpts) const
Dump a location expression as text and use the register information if some is provided.
uint32_t getAddressSpace() const
std::optional< DWARFExpression > getDWARFExpressionBytes() const
static UnwindLocation createAtCFAPlusOffset(int32_t Off)
static UnwindLocation createSame()
Create a location where the value is known to be in the register itself.
int32_t getConstant() const
static UnwindLocation createIsCFAPlusOffset(int32_t Off)
Create a location that is in (Deref == false) or at (Deref == true) the CFA plus an offset.
void setRegister(uint32_t NewRegNum)
Some opcodes will modify the CFA location's register only, so we need to be able to modify the CFA re...
A class that represents a single row in the unwind table that is decoded by parsing the DWARF Call Fr...
void dump(raw_ostream &OS, DIDumpOptions DumpOpts, unsigned IndentLevel=0) const
Dump the UnwindRow to the stream.
void setAddress(uint64_t Addr)
Set the address for this UnwindRow.
void slideAddress(uint64_t Offset)
Offset the address for this UnwindRow.
uint64_t getAddress() const
Get the address for this row.
const RegisterLocations & getRegisterLocations() const
UnwindLocation & getCFAValue()
const UnwindLocation & getCFAValue() const
RegisterLocations & getRegisterLocations()
bool hasAddress() const
Returns true if the address is valid in this object.
A class that contains all UnwindRow objects for an FDE or a single unwind row for a CIE.
static Expected< UnwindTable > create(const CIE *Cie)
Create an UnwindTable from a Common Information Entry (CIE).
const_iterator end() const
std::vector< UnwindRow > RowContainer
RowContainer::const_iterator const_iterator
const_iterator begin() const
void dump(raw_ostream &OS, DIDumpOptions DumpOpts, unsigned IndentLevel=0) const
Dump the UnwindTable to the stream.
RowContainer::iterator iterator
const UnwindRow & operator[](size_t Index) const
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
constexpr uint32_t InvalidRegisterNumber
raw_ostream & operator<<(raw_ostream &OS, const UnwindLocation &R)
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
Container for dump options that control which debug information will be dumped.
An instruction consists of a DWARF CFI opcode and an optional sequence of operands.
std::optional< DWARFExpression > Expression
Expected< uint64_t > getOperandAsUnsigned(const CFIProgram &CFIP, uint32_t OperandIdx) const
Instruction(uint8_t Opcode)
Expected< int64_t > getOperandAsSigned(const CFIProgram &CFIP, uint32_t OperandIdx) const
An iterator type that allows iterating over the pointees via some other iterator.