Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Unified Diff: src/eh-frame.cc

Issue 2023503002: Reland Implement .eh_frame writer and disassembler. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@eh-frame-base
Patch Set: Rename methods that are not purely getters, add comments. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/eh-frame.cc
diff --git a/src/eh-frame.cc b/src/eh-frame.cc
index af85e0b8d5f7143beb3c5243513a69fef0f5f919..b4b8e444e7ee9e76589cea7a2cc25245a9fc5d12 100644
--- a/src/eh-frame.cc
+++ b/src/eh-frame.cc
@@ -3,94 +3,605 @@
// found in the LICENSE file.
#include "src/eh-frame.h"
-#include "src/objects-inl.h"
-#include "src/objects.h"
+
+#include <iomanip>
+#include <ostream>
+
+#if !defined(V8_TARGET_ARCH_X64) && !defined(V8_TARGET_ARCH_ARM) && \
+ !defined(V8_TARGET_ARCH_ARM64)
+
+// Placeholders for unsupported architectures.
namespace v8 {
namespace internal {
-static const int DW_EH_PE_pcrel = 0x10;
-static const int DW_EH_PE_datarel = 0x30;
-static const int DW_EH_PE_udata4 = 0x03;
-static const int DW_EH_PE_sdata4 = 0x0b;
+STATIC_CONST_MEMBER_DEFINITION const int
+ EhFrameConstants::kDataAlignmentFactor = 1;
-const int EhFrameHdr::kCIESize = 0;
+void EhFrameWriter::WriteReturnAddressRegisterCode() { UNIMPLEMENTED(); }
-static const int kVersionSize = 1;
-static const int kEncodingSpecifiersSize = 3;
+void EhFrameWriter::WriteInitialStateInCIE() { UNIMPLEMENTED(); }
+int EhFrameWriter::RegisterToDwarfCode(Register) {
+ UNIMPLEMENTED();
+ return -1;
+}
+
+#ifdef ENABLE_DISASSEMBLER
+
+const char* EhFrameDisassembler::DwarfRegisterCodeToString(int) {
+ UNIMPLEMENTED();
+ return nullptr;
+}
+
+#endif
+
+} // namespace internal
+} // namespace v8
+
+#endif
+
+namespace v8 {
+namespace internal {
+
+STATIC_CONST_MEMBER_DEFINITION const int
+ EhFrameConstants::kEhFrameTerminatorSize;
+
+STATIC_CONST_MEMBER_DEFINITION const int EhFrameConstants::kEhFrameHdrVersion;
+
+// The dummy eh_frame_hdr is a hack to trigger fp-based unwinding in Linux
+// perf compiled with libunwind support when collecting DWARF-based call graphs.
//
-// In order to calculate offsets in the .eh_frame_hdr, we must know the layout
-// of the DSO generated by perf inject, which is assumed to be the following:
-//
-// | ... | |
-// +---------------+ <-- (F) --- | Larger offsets in file
-// | | ^ |
-// | Instructions | | .text v
-// | | v
-// +---------------+ <-- (E) ---
-// |///////////////|
-// |////Padding////|
-// |///////////////|
-// +---------------+ <-- (D) ---
-// | | ^
-// | CIE | |
-// | | |
-// +---------------+ <-- (C) | .eh_frame
-// | | |
-// | FDE | |
-// | | v
-// +---------------+ <-- (B) ---
-// | version | ^
-// +---------------+ |
-// | encoding | |
-// | specifiers | |
-// +---------------+ <---(A) | .eh_frame_hdr
-// | offset to | |
-// | .eh_frame | |
-// +---------------+ |
-// | ... | ...
-//
-// (F) is aligned at a 16-byte boundary.
-// (D) is aligned at a 8-byte boundary.
-// (B) is aligned at a 4-byte boundary.
-// (E), (C) and (A) have no alignment requirements.
-//
-// The distance between (A) and (B) is 4 bytes.
-//
-// The size of the .eh_frame is required to be a multiple of the pointer size,
-// which means that (B) will be naturally aligned to a 4-byte boundary on all
-// the architectures we support.
-//
-// Because (E) has no alignment requirements, there is padding between (E) and
-// (D). (F) is aligned at a 16-byte boundary, thus to a 8-byte one as well.
+// kDummyEhFrame is effectively a valid header with an empty look up table.
//
-EhFrameHdr::EhFrameHdr(Code* code) {
- int code_size = code->is_crankshafted() ? code->safepoint_table_offset()
- : code->instruction_size();
- version_ = 1;
- eh_frame_ptr_encoding_ = DW_EH_PE_sdata4 | DW_EH_PE_pcrel;
- lut_size_encoding_ = DW_EH_PE_udata4;
- lut_entries_encoding_ = DW_EH_PE_sdata4 | DW_EH_PE_datarel;
-
- // .eh_frame pointer and LUT
- if (code->has_unwinding_info()) {
- DCHECK_GE(code->unwinding_info_size(), EhFrameHdr::kRecordSize);
- int eh_frame_size = code->unwinding_info_size() - EhFrameHdr::kRecordSize;
-
- offset_to_eh_frame_ =
- -(eh_frame_size + kVersionSize + kEncodingSpecifiersSize); // A -> D
- lut_entries_number_ = 1;
- offset_to_procedure_ = -(RoundUp(code_size, 8) + eh_frame_size); // B -> F
- offset_to_fde_ = -(eh_frame_size - kCIESize); // B -> C
+STATIC_CONST_MEMBER_DEFINITION const byte EhFrameConstants::kDummyEhFrame[] = {
+ kEhFrameHdrVersion,
+ // .eh_frame pointer encoding specifier.
+ kSData4 | kPcRel,
+ // LUT size encoding.
+ kUData4,
+ // LUT entries encoding.
+ kSData4 | kDataRel,
+ // Dummy pointers and 0 entries in the LUT.
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
+STATIC_CONST_MEMBER_DEFINITION const uint32_t EhFrameWriter::kInt32Placeholder;
+
+EhFrameWriter::EhFrameWriter(Zone* zone)
+ : cie_size_(0),
+ last_pc_offset_(0),
+ eh_frame_finalised_(false),
+ base_register_(no_reg),
+ base_offset_(0),
+ eh_frame_buffer_(zone) {
+ eh_frame_buffer_.reserve(128);
+ WriteCIE();
+ WriteFDEHeader();
+}
+
+void EhFrameWriter::WriteCIE() {
+ static const int kCIEIdentifier = 0;
+ static const int kCIEVersion = 3;
+ static const int kCodeAlignmentFactor = 1;
+ static const int kAugmentationDataSize = 2;
+ static const byte kAugmentationString[] = {'z', 'L', 'R', 0};
+
+ int size_offset = eh_frame_offset();
+ WriteInt32(kInt32Placeholder);
+
+ int record_start_offset = eh_frame_offset();
+ WriteInt32(kCIEIdentifier);
+ WriteByte(kCIEVersion);
+
+ WriteBytes(&kAugmentationString[0], sizeof(kAugmentationString));
+
+ WriteSLEB128(kCodeAlignmentFactor);
+ WriteSLEB128(EhFrameConstants::kDataAlignmentFactor);
+
+ WriteReturnAddressRegisterCode();
+
+ WriteByte(kAugmentationDataSize);
+ WriteByte(EhFrameConstants::kOmit);
+ WriteByte(EhFrameConstants::kSData4 | EhFrameConstants::kPcRel);
+
+ DCHECK_EQ(eh_frame_offset() - size_offset,
+ EhFrameConstants::kInitialStateOffsetInCIE);
+ WriteInitialStateInCIE();
+
+ WritePaddingTo8ByteAlignment();
+
+ int record_end_offset = eh_frame_offset();
+ int encoded_cie_size = record_end_offset - record_start_offset;
+ cie_size_ = record_end_offset - size_offset;
rmcilroy 2016/07/07 10:11:03 Some comments here like WriteFDEHeader
Stefano Sanfilippo 2016/07/07 10:57:00 Done.
+
+ PatchInt32(size_offset, encoded_cie_size);
+}
+
+void EhFrameWriter::WriteFDEHeader() {
+ DCHECK_NE(cie_size_, 0);
+
+ // Placeholder for size of the FDE.
+ DCHECK_EQ(eh_frame_offset(), fde_offset());
+ WriteInt32(kInt32Placeholder);
+
+ // Backwards offset to the CIE.
+ WriteInt32(cie_size_ + kInt32Size);
+
+ // Placeholder for pointer to procedure.
+ DCHECK_EQ(eh_frame_offset(), GetProcedureAddressOffset());
+ WriteInt32(kInt32Placeholder);
+
+ // Placeholder for size of the procedure.
+ DCHECK_EQ(eh_frame_offset(), GetProcedureSizeOffset());
+ WriteInt32(kInt32Placeholder);
+
+ // No augmentation data.
+ WriteByte(0);
+}
+
+void EhFrameWriter::WriteEhFrameHdr(int code_size) {
+ DCHECK(!eh_frame_finalised_);
+
+ //
+ // In order to calculate offsets in the .eh_frame_hdr, we must know the layout
+ // of the DSO generated by perf inject, which is assumed to be the following:
+ //
+ // | ... | |
+ // +---------------+ <-- (F) --- | Larger offsets in file
+ // | | ^ |
+ // | Instructions | | .text v
+ // | | v
+ // +---------------+ <-- (E) ---
+ // |///////////////|
+ // |////Padding////|
+ // |///////////////|
+ // +---------------+ <-- (D) ---
+ // | | ^
+ // | CIE | |
+ // | | |
+ // +---------------+ <-- (C) |
+ // | | | .eh_frame
+ // | FDE | |
+ // | | |
+ // +---------------+ |
+ // | terminator | v
+ // +---------------+ <-- (B) ---
+ // | version | ^
+ // +---------------+ |
+ // | encoding | |
+ // | specifiers | |
+ // +---------------+ <---(A) | .eh_frame_hdr
+ // | offset to | |
+ // | .eh_frame | |
+ // +---------------+ |
+ // | ... | ...
+ //
+ // (F) is aligned to a 16-byte boundary.
+ // (D) is aligned to a 8-byte boundary.
+ // (B) is aligned to a 4-byte boundary.
+ // (C) is aligned to an addressing unit size boundary.
+ // (E) and (A) have no alignment requirements.
+ //
+ // The distance between (A) and (B) is 4 bytes.
+ //
+ // The size of the FDE is required to be a multiple of the pointer size, which
+ // means that (B) will be naturally aligned to a 4-byte boundary on all the
+ // architectures we support.
+ //
+ // Because (E) has no alignment requirements, there is padding between (E) and
+ // (D). (F) is aligned at a 16-byte boundary, thus to a 8-byte one as well.
+ //
+
+ int eh_frame_size = eh_frame_offset();
+
+ WriteByte(EhFrameConstants::kEhFrameHdrVersion);
+
+ // .eh_frame pointer encoding specifier.
+ WriteByte(EhFrameConstants::kSData4 | EhFrameConstants::kPcRel);
+ // LUT size encoding specifier.
+ WriteByte(EhFrameConstants::kUData4);
+ // LUT entries encoding specifier.
+ WriteByte(EhFrameConstants::kSData4 | EhFrameConstants::kDataRel);
+
+ // Pointer to .eh_frame, relative to this offset (A -> D in the diagram).
+ WriteInt32(-(eh_frame_size + EhFrameConstants::kFdeVersionSize +
+ EhFrameConstants::kFdeEncodingSpecifiersSize));
+
+ // Number of entries in the LUT, one for the only routine.
+ WriteInt32(1);
+
+ // Pointer to the start of the routine, relative to the beginning of the
+ // .eh_frame_hdr (B -> F in the diagram).
+ WriteInt32(-(RoundUp(code_size, 8) + eh_frame_size));
+
+ // Pointer to the start of the associated FDE, relative to the start of the
+ // .eh_frame_hdr (B -> C in the diagram).
+ WriteInt32(-(eh_frame_size - cie_size_));
+
+ DCHECK_EQ(eh_frame_offset() - eh_frame_size,
+ EhFrameConstants::kEhFrameHdrSize);
+}
+
+void EhFrameWriter::WritePaddingTo8ByteAlignment() {
+ DCHECK(!eh_frame_finalised_);
+
+ int unpadded_size = eh_frame_offset();
+ int padded_size = RoundUp(unpadded_size, 8);
+ int padding_size = padded_size - unpadded_size;
+
+ byte nop = static_cast<byte>(EhFrameConstants::DwarfOpcodes::kNop);
+ static const byte kPadding[] = {nop, nop, nop, nop, nop, nop, nop, nop};
+ DCHECK_LE(padding_size, static_cast<int>(sizeof(kPadding)));
+ WriteBytes(&kPadding[0], padding_size);
+}
+
+void EhFrameWriter::AdvanceLocation(int pc_offset) {
+ DCHECK(!eh_frame_finalised_);
+ DCHECK_GE(pc_offset, last_pc_offset_);
+ uint32_t delta = pc_offset - last_pc_offset_;
+
+ if (delta <= EhFrameConstants::kLocationMask) {
+ WriteByte((EhFrameConstants::kLocationTag
+ << EhFrameConstants::kLocationMaskSize) |
+ (delta & EhFrameConstants::kLocationMask));
+ } else if (delta <= kMaxUInt8) {
+ WriteOpcode(EhFrameConstants::DwarfOpcodes::kAdvanceLoc1);
+ WriteByte(delta);
+ } else if (delta <= kMaxUInt16) {
+ WriteOpcode(EhFrameConstants::DwarfOpcodes::kAdvanceLoc2);
+ WriteInt16(delta);
} else {
- // Create a dummy table
- offset_to_eh_frame_ = 0;
- lut_entries_number_ = 0;
- offset_to_procedure_ = 0;
- offset_to_fde_ = 0;
+ WriteOpcode(EhFrameConstants::DwarfOpcodes::kAdvanceLoc4);
+ WriteInt32(delta);
}
+
+ last_pc_offset_ = pc_offset;
+}
+
+void EhFrameWriter::SetBaseAddressOffset(int base_offset) {
+ DCHECK(!eh_frame_finalised_);
+ DCHECK_GE(base_offset, 0);
+ WriteOpcode(EhFrameConstants::DwarfOpcodes::kDefCfaOffset);
+ WriteULEB128(base_offset);
+ base_offset_ = base_offset;
+}
+
+void EhFrameWriter::SetBaseAddressRegister(Register base_register) {
+ DCHECK(!eh_frame_finalised_);
+ int code = RegisterToDwarfCode(base_register);
+ WriteOpcode(EhFrameConstants::DwarfOpcodes::kDefCfaRegister);
+ WriteULEB128(code);
+ base_register_ = base_register;
}
+void EhFrameWriter::SetBaseAddressRegisterAndOffset(Register base_register,
+ int base_offset) {
+ DCHECK(!eh_frame_finalised_);
+ int code = RegisterToDwarfCode(base_register);
+ WriteOpcode(EhFrameConstants::DwarfOpcodes::kDefCfa);
+ WriteULEB128(code);
+ WriteULEB128(base_offset);
+ base_offset_ = base_offset;
+ base_register_ = base_register;
+}
+
+void EhFrameWriter::RecordRegisterSavedToStack(int register_code, int offset) {
+ DCHECK(!eh_frame_finalised_);
+ DCHECK_EQ(offset % EhFrameConstants::kDataAlignmentFactor, 0);
+ int factored_offset = offset / EhFrameConstants::kDataAlignmentFactor;
+ if (factored_offset >= 0) {
+ DCHECK_LE(register_code, EhFrameConstants::kSavedRegisterMask);
+ WriteByte((EhFrameConstants::kSavedRegisterTag
+ << EhFrameConstants::kSavedRegisterMaskSize) |
+ (register_code & EhFrameConstants::kSavedRegisterMask));
+ WriteULEB128(factored_offset);
+ } else {
+ WriteOpcode(EhFrameConstants::DwarfOpcodes::kOffsetExtendedSf);
+ WriteULEB128(register_code);
+ WriteSLEB128(factored_offset);
+ }
+}
+
+void EhFrameWriter::RecordRegisterIsValid(Register name) {
+ DCHECK(!eh_frame_finalised_);
+ WriteOpcode(EhFrameConstants::DwarfOpcodes::kSameValue);
+ WriteULEB128(RegisterToDwarfCode(name));
+}
+
+void EhFrameWriter::RecordRegisterFollowsInitialRule(Register name) {
+ DCHECK(!eh_frame_finalised_);
+ int code = RegisterToDwarfCode(name);
+ DCHECK_LE(code, EhFrameConstants::kFollowInitialRuleMask);
+ WriteByte((EhFrameConstants::kFollowInitialRuleTag
+ << EhFrameConstants::kFollowInitialRuleMaskSize) |
+ (code & EhFrameConstants::kFollowInitialRuleMask));
+}
+
+void EhFrameWriter::Finish(int code_size) {
+ DCHECK(!eh_frame_finalised_);
+ DCHECK_GE(eh_frame_offset(), cie_size_);
+
+ WritePaddingTo8ByteAlignment();
+
+ // Write the size of the FDE now that we know it.
+ // The encoded size does not include the size field itself.
+ int encoded_fde_size = eh_frame_offset() - fde_offset() - kInt32Size;
+ PatchInt32(fde_offset(), encoded_fde_size);
+
+ // Write the size and offset to procedure.
+ PatchInt32(GetProcedureAddressOffset(),
+ -(RoundUp(code_size, 8) + GetProcedureAddressOffset()));
+ PatchInt32(GetProcedureSizeOffset(), code_size);
+
+ // Terminate the .eh_frame.
+ static const byte kTerminator[EhFrameConstants::kEhFrameTerminatorSize] = {0};
+ WriteBytes(&kTerminator[0], EhFrameConstants::kEhFrameTerminatorSize);
+
+ WriteEhFrameHdr(code_size);
+
+ eh_frame_finalised_ = true;
+}
+
+void EhFrameWriter::GetEhFrame(CodeDesc* desc) {
+ DCHECK(eh_frame_finalised_);
+ desc->unwinding_info_size = static_cast<int>(eh_frame_buffer_.size());
+ desc->unwinding_info = eh_frame_buffer_.data();
+}
+
+void EhFrameWriter::WriteULEB128(uint32_t value) {
+ do {
+ byte chunk = value & 0x7f;
+ value >>= 7;
+ if (value != 0) chunk |= 0x80;
+ WriteByte(chunk);
+ } while (value != 0);
+}
+
+void EhFrameWriter::WriteSLEB128(int32_t value) {
+ static const int kSignBitMask = 0x40;
+ bool done;
+ do {
+ byte chunk = value & 0x7f;
+ value >>= 7;
+ done = ((value == 0) && ((chunk & kSignBitMask) == 0)) ||
+ ((value == -1) && ((chunk & kSignBitMask) != 0));
+ if (!done) chunk |= 0x80;
+ WriteByte(chunk);
+ } while (!done);
+}
+
+uint32_t EhFrameIterator::GetNextULEB128() {
+ int size = 0;
+ uint32_t result = DecodeULEB128(next_, &size);
+ DCHECK_LE(next_ + size, end_);
+ next_ += size;
+ return result;
+}
+
+int32_t EhFrameIterator::GetNextSLEB128() {
+ int size = 0;
+ int32_t result = DecodeSLEB128(next_, &size);
+ DCHECK_LE(next_ + size, end_);
+ next_ += size;
+ return result;
+}
+
+// static
+uint32_t EhFrameIterator::DecodeULEB128(const byte* encoded,
+ int* encoded_size) {
+ const byte* current = encoded;
+ uint32_t result = 0;
+ int shift = 0;
+
+ do {
+ DCHECK_LT(shift, 8 * static_cast<int>(sizeof(result)));
+ result |= (*current & 0x7f) << shift;
+ shift += 7;
+ } while (*current++ >= 128);
+
+ DCHECK_NOT_NULL(encoded_size);
+ *encoded_size = static_cast<int>(current - encoded);
+
+ return result;
+}
+
+// static
+int32_t EhFrameIterator::DecodeSLEB128(const byte* encoded, int* encoded_size) {
+ static const byte kSignBitMask = 0x40;
+
+ const byte* current = encoded;
+ int32_t result = 0;
+ int shift = 0;
+ byte chunk;
+
+ do {
+ chunk = *current++;
+ DCHECK_LT(shift, 8 * static_cast<int>(sizeof(result)));
+ result |= (chunk & 0x7f) << shift;
+ shift += 7;
+ } while (chunk >= 128);
+
+ // Sign extend the result if the last chunk has the sign bit set.
+ if (chunk & kSignBitMask) result |= (~0ull) << shift;
+
+ DCHECK_NOT_NULL(encoded_size);
+ *encoded_size = static_cast<int>(current - encoded);
+
+ return result;
+}
+
+#ifdef ENABLE_DISASSEMBLER
+
+namespace {
+
+class StreamModifiersScope final {
+ public:
+ explicit StreamModifiersScope(std::ostream* stream)
+ : stream_(stream), flags_(stream->flags()) {}
+ ~StreamModifiersScope() { stream_->flags(flags_); }
+
+ private:
+ std::ostream* stream_;
+ std::ios::fmtflags flags_;
+};
+
+} // namespace
+
+// static
+void EhFrameDisassembler::DumpDWARFDirectives(std::ostream& stream, // NOLINT
+ const byte* start,
+ const byte* end) {
+ StreamModifiersScope modifiers_scope(&stream);
+
+ EhFrameIterator eh_frame_iterator(start, end);
+ uint32_t offset_in_procedure = 0;
+
+ while (!eh_frame_iterator.Done()) {
+ stream << eh_frame_iterator.current_address() << " ";
+
+ byte bytecode = eh_frame_iterator.GetNextByte();
+
+ if (((bytecode >> EhFrameConstants::kLocationMaskSize) & 0xff) ==
+ EhFrameConstants::kLocationTag) {
+ int value = bytecode & EhFrameConstants::kLocationMask;
+ offset_in_procedure += value;
+ stream << "| pc_offset=" << std::dec << offset_in_procedure
+ << " (delta=0x" << std::hex << value << ")\n";
+ continue;
+ }
+
+ if (((bytecode >> EhFrameConstants::kSavedRegisterMaskSize) & 0xff) ==
+ EhFrameConstants::kSavedRegisterTag) {
+ int decoded_offset = static_cast<int>(eh_frame_iterator.GetNextULEB128());
+ stream << "| " << DwarfRegisterCodeToString(
+ bytecode & EhFrameConstants::kLocationMask)
+ << " saved at base" << std::showpos << std::dec
+ << decoded_offset * EhFrameConstants::kDataAlignmentFactor << '\n';
+ continue;
+ }
+
+ if (((bytecode >> EhFrameConstants::kFollowInitialRuleMaskSize) & 0xff) ==
+ EhFrameConstants::kFollowInitialRuleTag) {
+ stream << "| " << DwarfRegisterCodeToString(
+ bytecode & EhFrameConstants::kLocationMask)
+ << " follows initial rule\n";
+ continue;
+ }
+
+ switch (static_cast<EhFrameConstants::DwarfOpcodes>(bytecode)) {
+ case EhFrameConstants::DwarfOpcodes::kOffsetExtendedSf: {
+ stream << "| "
+ << DwarfRegisterCodeToString(eh_frame_iterator.GetNextULEB128());
+ int32_t decoded_offset = eh_frame_iterator.GetNextSLEB128();
+ stream << " saved at base" << std::showpos << std::dec
+ << decoded_offset * EhFrameConstants::kDataAlignmentFactor
+ << '\n';
+ }
+ case EhFrameConstants::DwarfOpcodes::kAdvanceLoc1: {
+ unsigned value = eh_frame_iterator.GetNextByte();
+ offset_in_procedure += value;
+ stream << "| pc_offset=" << std::dec << offset_in_procedure
+ << " (delta=0x" << std::hex << value << ")\n";
+ break;
+ }
+ case EhFrameConstants::DwarfOpcodes::kAdvanceLoc2: {
+ uint16_t value = eh_frame_iterator.GetNextUInt16();
+ offset_in_procedure += value;
+ stream << "| pc_offset=" << std::dec << offset_in_procedure
+ << " (delta=0x" << std::hex << value << ")\n";
+ break;
+ }
+ case EhFrameConstants::DwarfOpcodes::kAdvanceLoc4: {
+ uint32_t value = eh_frame_iterator.GetNextUInt32();
+ offset_in_procedure += value;
+ stream << "| pc_offset=" << std::dec << offset_in_procedure
+ << " (delta=0x" << std::hex << value << ")\n";
+ break;
+ }
+ case EhFrameConstants::DwarfOpcodes::kDefCfa: {
+ int base_register = eh_frame_iterator.GetNextULEB128();
+ int base_offset = eh_frame_iterator.GetNextULEB128();
+ stream << "| base_register=" << DwarfRegisterCodeToString(base_register)
+ << ", base_offset=0x" << std::hex << base_offset << '\n';
+ break;
+ }
+ case EhFrameConstants::DwarfOpcodes::kDefCfaOffset: {
+ stream << "| base_offset=0x" << std::hex
+ << eh_frame_iterator.GetNextULEB128() << '\n';
+ break;
+ }
+ case EhFrameConstants::DwarfOpcodes::kDefCfaRegister: {
+ stream << "| base_register="
+ << DwarfRegisterCodeToString(eh_frame_iterator.GetNextULEB128())
+ << '\n';
+ break;
+ }
+ case EhFrameConstants::DwarfOpcodes::kSameValue: {
+ stream << "| "
+ << DwarfRegisterCodeToString(eh_frame_iterator.GetNextULEB128())
+ << " to initial value\n";
+ break;
+ }
+ case EhFrameConstants::DwarfOpcodes::kNop:
+ stream << "| nop\n";
+ break;
+ default:
+ UNREACHABLE();
+ return;
+ }
+ }
+}
+
+// static
+void EhFrameDisassembler::DisassembleToStream(std::ostream& stream) { // NOLINT
+ // The encoded CIE size does not include the size field itself.
+ const int cie_size = ReadUnalignedUInt32(start_) + kInt32Size;
+ const int fde_offset = cie_size;
+
+ const byte* cie_directives_start =
+ start_ + EhFrameConstants::kInitialStateOffsetInCIE;
+ const byte* cie_directives_end = start_ + cie_size;
+ DCHECK_LE(cie_directives_start, cie_directives_end);
+
+ stream << reinterpret_cast<const void*>(start_) << " .eh_frame: CIE\n";
+ DumpDWARFDirectives(stream, cie_directives_start, cie_directives_end);
+
+ const byte* procedure_offset_address =
+ start_ + fde_offset + EhFrameConstants::kProcedureAddressOffsetInFde;
+ int32_t procedure_offset =
+ ReadUnalignedValue<int32_t>(procedure_offset_address);
+
+ const byte* procedure_size_address =
+ start_ + fde_offset + EhFrameConstants::kProcedureSizeOffsetInFde;
+ uint32_t procedure_size = ReadUnalignedUInt32(procedure_size_address);
+
+ const byte* fde_start = start_ + fde_offset;
+ stream << reinterpret_cast<const void*>(fde_start) << " .eh_frame: FDE\n"
+ << reinterpret_cast<const void*>(procedure_offset_address)
+ << " | procedure_offset=" << procedure_offset << '\n'
+ << reinterpret_cast<const void*>(procedure_size_address)
+ << " | procedure_size=" << procedure_size << '\n';
+
+ const int fde_directives_offset = fde_offset + 4 * kInt32Size + 1;
+
+ const byte* fde_directives_start = start_ + fde_directives_offset;
+ const byte* fde_directives_end = end_ - EhFrameConstants::kEhFrameHdrSize -
+ EhFrameConstants::kEhFrameTerminatorSize;
+ DCHECK_LE(fde_directives_start, fde_directives_end);
+
+ DumpDWARFDirectives(stream, fde_directives_start, fde_directives_end);
+
+ const byte* fde_terminator_start = fde_directives_end;
+ stream << reinterpret_cast<const void*>(fde_terminator_start)
+ << " .eh_frame: terminator\n";
+
+ const byte* eh_frame_hdr_start =
+ fde_terminator_start + EhFrameConstants::kEhFrameTerminatorSize;
+ stream << reinterpret_cast<const void*>(eh_frame_hdr_start)
+ << " .eh_frame_hdr\n";
+}
+
+#endif
+
} // namespace internal
} // namespace v8
« src/eh-frame.h ('K') | « src/eh-frame.h ('k') | src/full-codegen/full-codegen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698