12 #include "llvm/Support/DataTypes.h"
21 using namespace dwarf;
30 :
Kind(K), Data(D), Offset(Offset), Length(Length) {}
36 virtual uint64_t
getOffset()
const {
return Offset; }
42 virtual void parseInstructions(uint32_t *Offset, uint32_t EndOffset);
48 virtual void dumpInstructions(
raw_ostream &OS)
const;
85 Instructions.back().Ops.push_back(Operand1);
90 Instructions.back().Ops.push_back(Operand1);
91 Instructions.back().Ops.push_back(Operand2);
102 while (*Offset < EndOffset) {
103 uint8_t Opcode = Data.getU8(Offset);
115 addInstruction(Primary, Op1);
118 addInstruction(Primary, Op1, Data.getULEB128(Offset));
129 addInstruction(Opcode);
133 addInstruction(Opcode, Data.getAddress(Offset));
137 addInstruction(Opcode, Data.getU8(Offset));
141 addInstruction(Opcode, Data.getU16(Offset));
145 addInstruction(Opcode, Data.getU32(Offset));
153 addInstruction(Opcode, Data.getULEB128(Offset));
157 addInstruction(Opcode, Data.getSLEB128(Offset));
164 addInstruction(Opcode, Data.getULEB128(Offset),
165 Data.getULEB128(Offset));
171 addInstruction(Opcode, Data.getULEB128(Offset),
172 Data.getSLEB128(Offset));
188 for (std::vector<Instruction>::const_iterator
I = Instructions.begin(),
189 E = Instructions.end();
191 uint8_t Opcode =
I->Opcode;
205 CIE(
DataExtractor D, uint64_t Offset, uint64_t Length, uint8_t Version,
207 int64_t DataAlignmentFactor, uint64_t ReturnAddressRegister)
208 :
FrameEntry(FK_CIE, D, Offset, Length), Version(Version),
209 Augmentation(Augmentation), CodeAlignmentFactor(CodeAlignmentFactor),
210 DataAlignmentFactor(DataAlignmentFactor),
211 ReturnAddressRegister(ReturnAddressRegister) {}
217 OS <<
format(
"%08x %08x %08x CIE",
218 (uint32_t)Offset, (uint32_t)Length,
DW_CIE_ID)
220 OS <<
format(
" Version: %d\n", Version);
221 OS <<
" Augmentation: \"" << Augmentation <<
"\"\n";
222 OS <<
format(
" Code alignment factor: %u\n",
223 (uint32_t)CodeAlignmentFactor);
224 OS <<
format(
" Data alignment factor: %d\n",
225 (int32_t)DataAlignmentFactor);
226 OS <<
format(
" Return address column: %d\n",
227 (int32_t)ReturnAddressRegister);
232 return FE->
getKind() == FK_CIE;
239 uint64_t CodeAlignmentFactor;
240 int64_t DataAlignmentFactor;
241 uint64_t ReturnAddressRegister;
252 int64_t LinkedCIEOffset, uint64_t InitialLocation, uint64_t AddressRange)
253 :
FrameEntry(FK_FDE, D, Offset, Length), LinkedCIEOffset(LinkedCIEOffset),
254 InitialLocation(InitialLocation), AddressRange(AddressRange),
261 OS <<
format(
"%08x %08x %08x FDE ",
262 (uint32_t)Offset, (uint32_t)Length, (int32_t)LinkedCIEOffset);
263 OS <<
format(
"cie=%08x pc=%08x...%08x\n",
264 (int32_t)LinkedCIEOffset,
265 (uint32_t)InitialLocation,
266 (uint32_t)InitialLocation + (uint32_t)AddressRange);
268 OS <<
format(
"%p\n", LinkedCIE);
273 return FE->
getKind() == FK_FDE;
278 uint64_t LinkedCIEOffset;
279 uint64_t InitialLocation;
280 uint64_t AddressRange;
291 for (EntryVector::iterator
I = Entries.begin(), E = Entries.end();
299 uint32_t Offset,
int Length) {
301 for (
int i = 0; i < Length; ++i) {
302 uint8_t c = Data.
getU8(&Offset);
313 uint32_t StartOffset = Offset;
315 bool IsDWARF64 =
false;
316 uint64_t Length = Data.
getU32(&Offset);
319 if (Length == UINT32_MAX) {
324 Length = Data.
getU64(&Offset);
333 uint32_t EndStructureOffset = Offset +
static_cast<uint32_t
>(Length);
345 uint8_t Version = Data.
getU8(&Offset);
346 const char *Augmentation = Data.
getCStr(&Offset);
347 uint64_t CodeAlignmentFactor = Data.
getULEB128(&Offset);
348 int64_t DataAlignmentFactor = Data.
getSLEB128(&Offset);
349 uint64_t ReturnAddressRegister = Data.
getULEB128(&Offset);
351 Entry =
new CIE(Data, StartOffset, Length, Version,
352 StringRef(Augmentation), CodeAlignmentFactor,
353 DataAlignmentFactor, ReturnAddressRegister);
356 uint64_t CIEPointer =
Id;
357 uint64_t InitialLocation = Data.
getAddress(&Offset);
358 uint64_t AddressRange = Data.
getAddress(&Offset);
360 Entry =
new FDE(Data, StartOffset, Length, CIEPointer,
361 InitialLocation, AddressRange);
364 assert(Entry &&
"Expected Entry to be populated with CIE or FDE");
367 if (Offset == EndStructureOffset) {
369 Entries.push_back(Entry);
373 OS <<
format(
"Parsing entry instructions at %lx failed",
383 for (EntryVector::const_iterator
I = Entries.begin(), E = Entries.end();
Instruction(uint8_t Opcode)
uint64_t Offset
Offset of this entry in the section.
const uint8_t DWARF_CFI_PRIMARY_OPCODE_MASK
FrameEntry(FrameKind K, DataExtractor D, uint64_t Offset, uint64_t Length)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
uint64_t Length
Entry length as specified in DWARF.
#define llvm_unreachable(msg)
const char * CallFrameString(unsigned Encoding)
virtual void dumpInstructions(raw_ostream &OS) const
Dump the entry's instructions to the given output stream.
FrameKind getKind() const
format_object1< T > format(const char *Fmt, const T &Val)
raw_ostream & write_hex(unsigned long long N)
write_hex - Output N in hexadecimal, without any prefix or padding.
virtual void dumpHeader(raw_ostream &OS) const =0
Dump the entry header to the given output stream.
#define LLVM_ATTRIBUTE_UNUSED
void addInstruction(uint8_t Opcode, uint64_t Operand1)
const uint8_t DWARF_CFI_PRIMARY_OPERAND_MASK
std::vector< uint64_t > Operands
void addInstruction(uint8_t Opcode)
std::vector< Instruction > Instructions
DataExtractor Data
The data stream holding the section from which the entry was parsed.
virtual void parseInstructions(uint32_t *Offset, uint32_t EndOffset)
Parse and store a sequence of CFI instructions from our data stream, starting at *Offset and ending a...
void parse(DataExtractor Data)
Parse the section from raw data. data is assumed to be pointing to the beginning of the section...
virtual uint64_t getOffset() const
static void LLVM_ATTRIBUTE_UNUSED dumpDataAux(DataExtractor Data, uint32_t Offset, int Length)
void addInstruction(uint8_t Opcode, uint64_t Operand1, uint64_t Operand2)
void dump(raw_ostream &OS) const
Dump the section data into the given stream.
const uint64_t DW64_CIE_ID
Abstract frame entry defining the common interface concrete entries implement.