Source code

Revision control

Copy as Markdown

Other Tools

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
// Copyright (c) 2010 Google Inc. All Rights Reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// CFI reader author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
// Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
// Implementation of dwarf2reader::LineInfo, dwarf2reader::CompilationUnit,
// and dwarf2reader::CallFrameInfo. See dwarf2reader.h for details.
// This file is derived from the following files in
// toolkit/crashreporter/google-breakpad:
// src/common/dwarf/bytereader.cc
// src/common/dwarf/dwarf2reader.cc
// src/common/dwarf_cfi_to_module.cc
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stack>
#include <string>
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/Sprintf.h"
#include "mozilla/Vector.h"
#include "LulCommonExt.h"
#include "LulDwarfInt.h"
// Set this to 1 for verbose logging
#define DEBUG_DWARF 0
namespace lul {
using std::pair;
using std::string;
ByteReader::ByteReader(enum Endianness endian)
: offset_reader_(NULL),
address_reader_(NULL),
endian_(endian),
address_size_(0),
offset_size_(0),
have_section_base_(),
have_text_base_(),
have_data_base_(),
have_function_base_() {}
ByteReader::~ByteReader() {}
void ByteReader::SetOffsetSize(uint8 size) {
offset_size_ = size;
MOZ_ASSERT(size == 4 || size == 8);
if (size == 4) {
this->offset_reader_ = &ByteReader::ReadFourBytes;
} else {
this->offset_reader_ = &ByteReader::ReadEightBytes;
}
}
void ByteReader::SetAddressSize(uint8 size) {
address_size_ = size;
MOZ_ASSERT(size == 4 || size == 8);
if (size == 4) {
this->address_reader_ = &ByteReader::ReadFourBytes;
} else {
this->address_reader_ = &ByteReader::ReadEightBytes;
}
}
uint64 ByteReader::ReadInitialLength(const char* start, size_t* len) {
const uint64 initial_length = ReadFourBytes(start);
start += 4;
// In DWARF2/3, if the initial length is all 1 bits, then the offset
// size is 8 and we need to read the next 8 bytes for the real length.
if (initial_length == 0xffffffff) {
SetOffsetSize(8);
*len = 12;
return ReadOffset(start);
} else {
SetOffsetSize(4);
*len = 4;
}
return initial_length;
}
bool ByteReader::ValidEncoding(DwarfPointerEncoding encoding) const {
if (encoding == DW_EH_PE_omit) return true;
if (encoding == DW_EH_PE_aligned) return true;
if ((encoding & 0x7) > DW_EH_PE_udata8) return false;
if ((encoding & 0x70) > DW_EH_PE_funcrel) return false;
return true;
}
bool ByteReader::UsableEncoding(DwarfPointerEncoding encoding) const {
switch (encoding & 0x70) {
case DW_EH_PE_absptr:
return true;
case DW_EH_PE_pcrel:
return have_section_base_;
case DW_EH_PE_textrel:
return have_text_base_;
case DW_EH_PE_datarel:
return have_data_base_;
case DW_EH_PE_funcrel:
return have_function_base_;
default:
return false;
}
}
uint64 ByteReader::ReadEncodedPointer(const char* buffer,
DwarfPointerEncoding encoding,
size_t* len) const {
// UsableEncoding doesn't approve of DW_EH_PE_omit, so we shouldn't
// see it here.
MOZ_ASSERT(encoding != DW_EH_PE_omit);
// The Linux Standards Base 4.0 does not make this clear, but the
// GNU tools (gcc/unwind-pe.h; readelf/dwarf.c; gdb/dwarf2-frame.c)
// agree that aligned pointers are always absolute, machine-sized,
// machine-signed pointers.
if (encoding == DW_EH_PE_aligned) {
MOZ_ASSERT(have_section_base_);
// We don't need to align BUFFER in *our* address space. Rather, we
// need to find the next position in our buffer that would be aligned
// when the .eh_frame section the buffer contains is loaded into the
// program's memory. So align assuming that buffer_base_ gets loaded at
// address section_base_, where section_base_ itself may or may not be
// aligned.
// First, find the offset to START from the closest prior aligned
// address.
uint64 skew = section_base_ & (AddressSize() - 1);
// Now find the offset from that aligned address to buffer.
uint64 offset = skew + (buffer - buffer_base_);
// Round up to the next boundary.
uint64 aligned = (offset + AddressSize() - 1) & -AddressSize();
// Convert back to a pointer.
const char* aligned_buffer = buffer_base_ + (aligned - skew);
// Finally, store the length and actually fetch the pointer.
*len = aligned_buffer - buffer + AddressSize();
return ReadAddress(aligned_buffer);
}
// Extract the value first, ignoring whether it's a pointer or an
// offset relative to some base.
uint64 offset;
switch (encoding & 0x0f) {
case DW_EH_PE_absptr:
// DW_EH_PE_absptr is weird, as it is used as a meaningful value for
// both the high and low nybble of encoding bytes. When it appears in
// the high nybble, it means that the pointer is absolute, not an
// offset from some base address. When it appears in the low nybble,
// as here, it means that the pointer is stored as a normal
// machine-sized and machine-signed address. A low nybble of
// DW_EH_PE_absptr does not imply that the pointer is absolute; it is
// correct for us to treat the value as an offset from a base address
// if the upper nybble is not DW_EH_PE_absptr.
offset = ReadAddress(buffer);
*len = AddressSize();
break;
case DW_EH_PE_uleb128:
offset = ReadUnsignedLEB128(buffer, len);
break;
case DW_EH_PE_udata2:
offset = ReadTwoBytes(buffer);
*len = 2;
break;
case DW_EH_PE_udata4:
offset = ReadFourBytes(buffer);
*len = 4;
break;
case DW_EH_PE_udata8:
offset = ReadEightBytes(buffer);
*len = 8;
break;
case DW_EH_PE_sleb128:
offset = ReadSignedLEB128(buffer, len);
break;
case DW_EH_PE_sdata2:
offset = ReadTwoBytes(buffer);
// Sign-extend from 16 bits.
offset = (offset ^ 0x8000) - 0x8000;
*len = 2;
break;
case DW_EH_PE_sdata4:
offset = ReadFourBytes(buffer);
// Sign-extend from 32 bits.
offset = (offset ^ 0x80000000ULL) - 0x80000000ULL;
*len = 4;
break;
case DW_EH_PE_sdata8:
// No need to sign-extend; this is the full width of our type.
offset = ReadEightBytes(buffer);
*len = 8;
break;
default:
abort();
}
// Find the appropriate base address.
uint64 base;
switch (encoding & 0x70) {
case DW_EH_PE_absptr:
base = 0;
break;
case DW_EH_PE_pcrel:
MOZ_ASSERT(have_section_base_);
base = section_base_ + (buffer - buffer_base_);
break;
case DW_EH_PE_textrel:
MOZ_ASSERT(have_text_base_);
base = text_base_;
break;
case DW_EH_PE_datarel:
MOZ_ASSERT(have_data_base_);
base = data_base_;
break;
case DW_EH_PE_funcrel:
MOZ_ASSERT(have_function_base_);
base = function_base_;
break;
default:
abort();
}
uint64 pointer = base + offset;
// Remove inappropriate upper bits.
if (AddressSize() == 4)
pointer = pointer & 0xffffffff;
else
MOZ_ASSERT(AddressSize() == sizeof(uint64));
return pointer;
}
// A DWARF rule for recovering the address or value of a register, or
// computing the canonical frame address. This is an 8-way sum-of-products
// type. Excluding the INVALID variant, there is one subclass of this for
// each '*Rule' member function in CallFrameInfo::Handler.
//
// This could logically be nested within State, but then the qualified names
// get horrendous.
class CallFrameInfo::Rule final {
public:
enum Tag {
INVALID,
Undefined,
SameValue,
Offset,
ValOffset,
Register,
Expression,
ValExpression
};
private:
// tag_ (below) indicates the form of the expression. There are 7 forms
// plus INVALID. All non-INVALID expressions denote a machine-word-sized
// value at unwind time. The description below assumes the presence of, at
// unwind time:
//
// * a function R, which takes a Dwarf register number and returns its value
// in the callee frame (the one we are unwinding out of).
//
// * a function EvalDwarfExpr, which evaluates a Dwarf expression.
//
// Register numbers are encoded using the target ABI's Dwarf
// register-numbering conventions. Except where otherwise noted, a register
// value may also be the special value CallFrameInfo::Handler::kCFARegister
// ("the CFA").
//
// The expression forms are represented using tag_, word1_ and word2_. The
// forms and denoted values are as follows:
//
// * INVALID: not a valid expression.
// valid fields: (none)
// denotes: no value
//
// * Undefined: denotes no value. This is used for a register whose value
// cannot be recovered.
// valid fields: (none)
// denotes: no value
//
// * SameValue: the register's value is the same as in the callee.
// valid fields: (none)
// denotes: R(the register that this Rule is associated with,
// not stored here)
//
// * Offset: the register's value is in memory at word2_ bytes away from
// Dwarf register number word1_. word2_ is interpreted as a *signed*
// offset.
// valid fields: word1_=DwarfReg, word2=Offset
// denotes: *(R(word1_) + word2_)
//
// * ValOffset: same as Offset, without the dereference.
// valid fields: word1_=DwarfReg, word2=Offset
// denotes: R(word1_) + word2_
//
// * Register: the register's value is in some other register,
// which may not be the CFA.
// valid fields: word1_=DwarfReg
// denotes: R(word1_)
//
// * Expression: the register's value is in memory at a location that can be
// computed from the Dwarf expression contained in the word2_ bytes
// starting at word1_. Note these locations are into the area of the .so
// temporarily mmaped info for debuginfo reading and have no validity once
// debuginfo reading has finished.
// valid fields: ExprStart=word1_, ExprLen=word2_
// denotes: *(EvalDwarfExpr(word1_, word2_))
//
// * ValExpression: same as Expression, without the dereference.
// valid fields: ExprStart=word1_, ExprLen=word2_
// denotes: EvalDwarfExpr(word1_, word2_)
//
// 3 words (or less) for representation. Unused word1_/word2_ fields must
// be set to zero.
Tag tag_;
uintptr_t word1_;
uintptr_t word2_;
// To ensure that word1_ can hold a pointer to an expression string.
static_assert(sizeof(const char*) <= sizeof(word1_));
// To ensure that word2_ can hold any string length or memory offset.
static_assert(sizeof(size_t) <= sizeof(word2_));
// This class denotes an 8-way sum-of-product type, and accessing invalid
// fields is meaningless. The accessors and constructors below enforce
// that.
bool isCanonical() const {
switch (tag_) {
case Tag::INVALID:
case Tag::Undefined:
case Tag::SameValue:
return word1_ == 0 && word2_ == 0;
case Tag::Offset:
case Tag::ValOffset:
return true;
case Tag::Register:
return word2_ == 0;
case Tag::Expression:
case Tag::ValExpression:
return true;
default:
MOZ_CRASH();
}
}
public:
Tag tag() const { return tag_; }
int dwreg() const {
switch (tag_) {
case Tag::Offset:
case Tag::ValOffset:
case Tag::Register:
return (int)word1_;
default:
MOZ_CRASH();
}
}
intptr_t offset() const {
switch (tag_) {
case Tag::Offset:
case Tag::ValOffset:
return (intptr_t)word2_;
default:
MOZ_CRASH();
}
}
ImageSlice expr() const {
switch (tag_) {
case Tag::Expression:
case Tag::ValExpression:
return ImageSlice((const char*)word1_, (size_t)word2_);
default:
MOZ_CRASH();
}
}
// Constructor-y stuff
Rule() {
tag_ = Tag::INVALID;
word1_ = 0;
word2_ = 0;
}
static Rule mkINVALID() {
Rule r; // is initialised by Rule()
return r;
}
static Rule mkUndefinedRule() {
Rule r;
r.tag_ = Tag::Undefined;
r.word1_ = 0;
r.word2_ = 0;
return r;
}
static Rule mkSameValueRule() {
Rule r;
r.tag_ = Tag::SameValue;
r.word1_ = 0;
r.word2_ = 0;
return r;
}
static Rule mkOffsetRule(int dwreg, intptr_t offset) {
Rule r;
r.tag_ = Tag::Offset;
r.word1_ = (uintptr_t)dwreg;
r.word2_ = (uintptr_t)offset;
return r;
}
static Rule mkValOffsetRule(int dwreg, intptr_t offset) {
Rule r;
r.tag_ = Tag::ValOffset;
r.word1_ = (uintptr_t)dwreg;
r.word2_ = (uintptr_t)offset;
return r;
}
static Rule mkRegisterRule(int dwreg) {
Rule r;
r.tag_ = Tag::Register;
r.word1_ = (uintptr_t)dwreg;
r.word2_ = 0;
return r;
}
static Rule mkExpressionRule(ImageSlice expr) {
Rule r;
r.tag_ = Tag::Expression;
r.word1_ = (uintptr_t)expr.start_;
r.word2_ = (uintptr_t)expr.length_;
return r;
}
static Rule mkValExpressionRule(ImageSlice expr) {
Rule r;
r.tag_ = Tag::ValExpression;
r.word1_ = (uintptr_t)expr.start_;
r.word2_ = (uintptr_t)expr.length_;
return r;
}
// Misc
inline bool isVALID() const { return tag_ != Tag::INVALID; }
bool operator==(const Rule& rhs) const {
MOZ_ASSERT(isVALID() && rhs.isVALID());
MOZ_ASSERT(isCanonical());
MOZ_ASSERT(rhs.isCanonical());
if (tag_ != rhs.tag_) {
return false;
}
switch (tag_) {
case Tag::INVALID:
MOZ_CRASH();
case Tag::Undefined:
case Tag::SameValue:
return true;
case Tag::Offset:
case Tag::ValOffset:
return word1_ == rhs.word1_ && word2_ == rhs.word2_;
case Tag::Register:
return word1_ == rhs.word1_;
case Tag::Expression:
case Tag::ValExpression:
return expr() == rhs.expr();
default:
MOZ_CRASH();
}
}
bool operator!=(const Rule& rhs) const { return !(*this == rhs); }
// Tell HANDLER that, at ADDRESS in the program, REG can be
// recovered using this rule. If REG is kCFARegister, then this rule
// describes how to compute the canonical frame address. Return what the
// HANDLER member function returned.
bool Handle(Handler* handler, uint64 address, int reg) const {
MOZ_ASSERT(isVALID());
MOZ_ASSERT(isCanonical());
switch (tag_) {
case Tag::Undefined:
return handler->UndefinedRule(address, reg);
case Tag::SameValue:
return handler->SameValueRule(address, reg);
case Tag::Offset:
return handler->OffsetRule(address, reg, word1_, word2_);
case Tag::ValOffset:
return handler->ValOffsetRule(address, reg, word1_, word2_);
case Tag::Register:
return handler->RegisterRule(address, reg, word1_);
case Tag::Expression:
return handler->ExpressionRule(
address, reg, ImageSlice((const char*)word1_, (size_t)word2_));
case Tag::ValExpression:
return handler->ValExpressionRule(
address, reg, ImageSlice((const char*)word1_, (size_t)word2_));
default:
MOZ_CRASH();
}
}
void SetBaseRegister(unsigned reg) {
MOZ_ASSERT(isVALID());
MOZ_ASSERT(isCanonical());
switch (tag_) {
case Tag::ValOffset:
word1_ = reg;
break;
case Tag::Offset:
// We don't actually need SetBaseRegister or SetOffset here, since they
// are only ever applied to CFA rules, for DW_CFA_def_cfa_offset, and it
// doesn't make sense to use OffsetRule for computing the CFA: it
// computes the address at which a register is saved, not a value.
// (fallthrough)
case Tag::Undefined:
case Tag::SameValue:
case Tag::Register:
case Tag::Expression:
case Tag::ValExpression:
// Do nothing
break;
default:
MOZ_CRASH();
}
}
void SetOffset(long long offset) {
MOZ_ASSERT(isVALID());
MOZ_ASSERT(isCanonical());
switch (tag_) {
case Tag::ValOffset:
word2_ = offset;
break;
case Tag::Offset:
// Same comment as in SetBaseRegister applies
// (fallthrough)
case Tag::Undefined:
case Tag::SameValue:
case Tag::Register:
case Tag::Expression:
case Tag::ValExpression:
// Do nothing
break;
default:
MOZ_CRASH();
}
}
// For debugging only
string show() const {
char buf[100];
string s = "";
switch (tag_) {
case Tag::INVALID:
s = "INVALID";
break;
case Tag::Undefined:
s = "Undefined";
break;
case Tag::SameValue:
s = "SameValue";
break;
case Tag::Offset:
s = "Offset{..}";
break;
case Tag::ValOffset:
sprintf(buf, "ValOffset{reg=%d offs=%lld}", (int)word1_,
(long long int)word2_);
s = string(buf);
break;
case Tag::Register:
s = "Register{..}";
break;
case Tag::Expression:
s = "Expression{..}";
break;
case Tag::ValExpression:
s = "ValExpression{..}";
break;
default:
MOZ_CRASH();
}
return s;
}
};
// `RuleMapLowLevel` is a simple class that maps from `int` (register numbers)
// to `Rule`. This is implemented as a vector of `<int, Rule>` pairs, with a
// 12-element inline capacity. From a big-O perspective this is obviously a
// terrible way to implement an associative map. This workload is however
// quite special in that the maximum number of elements is normally 7 (on
// x86_64-linux), and so this implementation is much faster than one based on
// std::map with its attendant R-B-tree node allocation and balancing
// overheads.
//
// An iterator that enumerates the mapping in increasing order of the `int`
// keys is provided. This ordered iteration facility is required by
// CallFrameInfo::RuleMap::HandleTransitionTo, which needs to iterate through
// two such maps simultaneously and in-order so as to compare them.
// All `Rule`s in the map must satisfy `isVALID()`. That conveniently means
// that `Rule::mkINVALID()` can be used to indicate "not found` in `get()`.
class CallFrameInfo::RuleMapLowLevel {
using Entry = pair<int, Rule>;
// The inline capacity of 12 is carefully chosen. It would be wise to make
// careful measurements of time, instruction count, allocation count and
// allocated bytes before changing it. For x86_64-linux, a value of 8 is
// marginally better; using 12 increases the total heap bytes allocated by
// around 20%. For arm64-linux, a value of 24 is better; using 12 increases
// the total blocks allocated by around 20%. But it's a not bad tradeoff
// for both targets, and in any case is vastly superior to the previous
// scheme of using `std::map`.
mozilla::Vector<Entry, 12> entries_;
public:
void clear() { entries_.clear(); }
RuleMapLowLevel() { clear(); }
RuleMapLowLevel& operator=(const RuleMapLowLevel& rhs) {
entries_.clear();
for (size_t i = 0; i < rhs.entries_.length(); i++) {
bool ok = entries_.append(rhs.entries_[i]);
MOZ_RELEASE_ASSERT(ok);
}
return *this;
}
void set(int reg, Rule rule) {
MOZ_ASSERT(rule.isVALID());
// Find the place where it should go, if any
size_t i = 0;
size_t nEnt = entries_.length();
while (i < nEnt && entries_[i].first < reg) {
i++;
}
if (i == nEnt) {
// No entry exists, and all the existing ones are for lower register
// numbers. So just add it at the end.
bool ok = entries_.append(Entry(reg, rule));
MOZ_RELEASE_ASSERT(ok);
} else {
// It needs to live at location `i`, and ..
MOZ_ASSERT(i < nEnt);
if (entries_[i].first == reg) {
// .. there's already an old entry, so just update it.
entries_[i].second = rule;
} else {
// .. there's no previous entry, so shift `i` and all those following
// it one place to the right, and put the new entry at `i`. Doing it
// manually is measurably cheaper than using `Vector::insert`.
MOZ_ASSERT(entries_[i].first > reg);
bool ok = entries_.append(Entry(999999, Rule::mkINVALID()));
MOZ_RELEASE_ASSERT(ok);
for (size_t j = nEnt; j >= i + 1; j--) {
entries_[j] = entries_[j - 1];
}
entries_[i] = Entry(reg, rule);
}
}
// Check in-order-ness and validity.
for (size_t i = 0; i < entries_.length(); i++) {
MOZ_ASSERT(entries_[i].second.isVALID());
MOZ_ASSERT_IF(i > 0, entries_[i - 1].first < entries_[i].first);
}
MOZ_ASSERT(get(reg).isVALID());
}
// Find the entry for `reg`, or return `Rule::mkINVALID()` if not found.
Rule get(int reg) const {
size_t nEnt = entries_.length();
// "early exit" in the case where `entries_[i].first > reg` was tested on
// x86_64 and found to be slightly slower than just testing all entries,
// presumably because the reduced amount of searching was not offset by
// the cost of an extra test per iteration.
for (size_t i = 0; i < nEnt; i++) {
if (entries_[i].first == reg) {
CallFrameInfo::Rule ret = entries_[i].second;
MOZ_ASSERT(ret.isVALID());
return ret;
}
}
return CallFrameInfo::Rule::mkINVALID();
}
// A very simple in-order iteration facility.
class Iter {
const RuleMapLowLevel* rmll_;
size_t nextIx_;
public:
explicit Iter(const RuleMapLowLevel* rmll) : rmll_(rmll), nextIx_(0) {}
bool avail() const { return nextIx_ < rmll_->entries_.length(); }
bool finished() const { return !avail(); }
// Move the iterator to the next entry.
void step() {
MOZ_RELEASE_ASSERT(nextIx_ < rmll_->entries_.length());
nextIx_++;
}
// Get the value at the current iteration point, but don't advance to the
// next entry.
pair<int, Rule> peek() {
MOZ_RELEASE_ASSERT(nextIx_ < rmll_->entries_.length());
return rmll_->entries_[nextIx_];
}
};
};
// A map from register numbers to rules. This is a wrapper around
// `RuleMapLowLevel`, with added logic for dealing with the "special" CFA
// rule, and with `HandleTransitionTo`, which effectively computes the
// difference between two `RuleMaps`.
class CallFrameInfo::RuleMap {
public:
RuleMap() : cfa_rule_(Rule::mkINVALID()) {}
RuleMap(const RuleMap& rhs) : cfa_rule_(Rule::mkINVALID()) { *this = rhs; }
~RuleMap() { Clear(); }
RuleMap& operator=(const RuleMap& rhs);
// Set the rule for computing the CFA to RULE.
void SetCFARule(Rule rule) { cfa_rule_ = rule; }
// Return the current CFA rule. Be careful not to modify it -- it's returned
// by value. If you want to modify the CFA rule, use CFARuleRef() instead.
// We use these two for DW_CFA_def_cfa_offset and DW_CFA_def_cfa_register,
// and for detecting references to the CFA before a rule for it has been
// established.
Rule CFARule() const { return cfa_rule_; }
Rule* CFARuleRef() { return &cfa_rule_; }
// Return the rule for REG, or the INVALID rule if there is none.
Rule RegisterRule(int reg) const;
// Set the rule for computing REG to RULE.
void SetRegisterRule(int reg, Rule rule);
// Make all the appropriate calls to HANDLER as if we were changing from
// this RuleMap to NEW_RULES at ADDRESS. We use this to implement
// DW_CFA_restore_state, where lots of rules can change simultaneously.
// Return true if all handlers returned true; otherwise, return false.
bool HandleTransitionTo(Handler* handler, uint64 address,
const RuleMap& new_rules) const;
private:
// Remove all register rules and clear cfa_rule_.
void Clear();
// The rule for computing the canonical frame address.
Rule cfa_rule_;
// A map from register numbers to postfix expressions to recover
// their values.
RuleMapLowLevel registers_;
};
CallFrameInfo::RuleMap& CallFrameInfo::RuleMap::operator=(const RuleMap& rhs) {
Clear();
if (rhs.cfa_rule_.isVALID()) cfa_rule_ = rhs.cfa_rule_;
registers_ = rhs.registers_;
return *this;
}
CallFrameInfo::Rule CallFrameInfo::RuleMap::RegisterRule(int reg) const {
MOZ_ASSERT(reg != Handler::kCFARegister);
return registers_.get(reg);
}
void CallFrameInfo::RuleMap::SetRegisterRule(int reg, Rule rule) {
MOZ_ASSERT(reg != Handler::kCFARegister);
MOZ_ASSERT(rule.isVALID());
registers_.set(reg, rule);
}
bool CallFrameInfo::RuleMap::HandleTransitionTo(
Handler* handler, uint64 address, const RuleMap& new_rules) const {
// Transition from cfa_rule_ to new_rules.cfa_rule_.
if (cfa_rule_.isVALID() && new_rules.cfa_rule_.isVALID()) {
if (cfa_rule_ != new_rules.cfa_rule_ &&
!new_rules.cfa_rule_.Handle(handler, address, Handler::kCFARegister)) {
return false;
}
} else if (cfa_rule_.isVALID()) {
// this RuleMap has a CFA rule but new_rules doesn't.
// CallFrameInfo::Handler has no way to handle this --- and shouldn't;
// it's garbage input. The instruction interpreter should have
// detected this and warned, so take no action here.
} else if (new_rules.cfa_rule_.isVALID()) {
// This shouldn't be possible: NEW_RULES is some prior state, and
// there's no way to remove entries.
MOZ_ASSERT(0);
} else {
// Both CFA rules are empty. No action needed.
}
// Traverse the two maps in order by register number, and report
// whatever differences we find.
RuleMapLowLevel::Iter old_it(&registers_);
RuleMapLowLevel::Iter new_it(&new_rules.registers_);
while (!old_it.finished() && !new_it.finished()) {
pair<int, Rule> old_pair = old_it.peek();
pair<int, Rule> new_pair = new_it.peek();
if (old_pair.first < new_pair.first) {
// This RuleMap has an entry for old.first, but NEW_RULES doesn't.
//
// This isn't really the right thing to do, but since CFI generally
// only mentions callee-saves registers, and GCC's convention for
// callee-saves registers is that they are unchanged, it's a good
// approximation.
if (!handler->SameValueRule(address, old_pair.first)) {
return false;
}
old_it.step();
} else if (old_pair.first > new_pair.first) {
// NEW_RULES has an entry for new_pair.first, but this RuleMap
// doesn't. This shouldn't be possible: NEW_RULES is some prior
// state, and there's no way to remove entries.
MOZ_ASSERT(0);
} else {
// Both maps have an entry for this register. Report the new
// rule if it is different.
if (old_pair.second != new_pair.second &&
!new_pair.second.Handle(handler, address, new_pair.first)) {
return false;
}
new_it.step();
old_it.step();
}
}
// Finish off entries from this RuleMap with no counterparts in new_rules.
while (!old_it.finished()) {
pair<int, Rule> old_pair = old_it.peek();
if (!handler->SameValueRule(address, old_pair.first)) return false;
old_it.step();
}
// Since we only make transitions from a rule set to some previously
// saved rule set, and we can only add rules to the map, NEW_RULES
// must have fewer rules than *this.
MOZ_ASSERT(new_it.finished());
return true;
}
// Remove all register rules and clear cfa_rule_.
void CallFrameInfo::RuleMap::Clear() {
cfa_rule_ = Rule::mkINVALID();
registers_.clear();
}
// The state of the call frame information interpreter as it processes
// instructions from a CIE and FDE.
class CallFrameInfo::State {
public:
// Create a call frame information interpreter state with the given
// reporter, reader, handler, and initial call frame info address.
State(ByteReader* reader, Handler* handler, Reporter* reporter,
uint64 address)
: reader_(reader),
handler_(handler),
reporter_(reporter),
address_(address),
entry_(NULL),
cursor_(NULL),
saved_rules_(NULL) {}
~State() {
if (saved_rules_) delete saved_rules_;
}
// Interpret instructions from CIE, save the resulting rule set for
// DW_CFA_restore instructions, and return true. On error, report
// the problem to reporter_ and return false.
bool InterpretCIE(const CIE& cie);
// Interpret instructions from FDE, and return true. On error,
// report the problem to reporter_ and return false.
bool InterpretFDE(const FDE& fde);
private:
// The operands of a CFI instruction, for ParseOperands.
struct Operands {
unsigned register_number; // A register number.
uint64 offset; // An offset or address.
long signed_offset; // A signed offset.
ImageSlice expression; // A DWARF expression.
};
// Parse CFI instruction operands from STATE's instruction stream as
// described by FORMAT. On success, populate OPERANDS with the
// results, and return true. On failure, report the problem and
// return false.
//
// Each character of FORMAT should be one of the following:
//
// 'r' unsigned LEB128 register number (OPERANDS->register_number)
// 'o' unsigned LEB128 offset (OPERANDS->offset)
// 's' signed LEB128 offset (OPERANDS->signed_offset)
// 'a' machine-size address (OPERANDS->offset)
// (If the CIE has a 'z' augmentation string, 'a' uses the
// encoding specified by the 'R' argument.)
// '1' a one-byte offset (OPERANDS->offset)
// '2' a two-byte offset (OPERANDS->offset)
// '4' a four-byte offset (OPERANDS->offset)
// '8' an eight-byte offset (OPERANDS->offset)
// 'e' a DW_FORM_block holding a (OPERANDS->expression)
// DWARF expression
bool ParseOperands(const char* format, Operands* operands);
// Interpret one CFI instruction from STATE's instruction stream, update
// STATE, report any rule changes to handler_, and return true. On
// failure, report the problem and return false.
MOZ_ALWAYS_INLINE bool DoInstruction();
// Repeatedly call `DoInstruction`, until either:
// * it returns `false`, which indicates some kind of failure,
// in which case return `false` from here too, or
// * we've run out of instructions (that is, `cursor_ >= entry_->end`),
// in which case return `true`.
// This is marked as never-inline because it is the only place that
// `DoInstruction` is called from, and we want to maximise the chances that
// `DoInstruction` is inlined into this routine.
MOZ_NEVER_INLINE bool DoInstructions();
// The following Do* member functions are subroutines of DoInstruction,
// factoring out the actual work of operations that have several
// different encodings.
// Set the CFA rule to be the value of BASE_REGISTER plus OFFSET, and
// return true. On failure, report and return false. (Used for
// DW_CFA_def_cfa and DW_CFA_def_cfa_sf.)
bool DoDefCFA(unsigned base_register, long offset);
// Change the offset of the CFA rule to OFFSET, and return true. On
// failure, report and return false. (Subroutine for
// DW_CFA_def_cfa_offset and DW_CFA_def_cfa_offset_sf.)
bool DoDefCFAOffset(long offset);
// Specify that REG can be recovered using RULE, and return true. On
// failure, report and return false.
bool DoRule(unsigned reg, Rule rule);
// Specify that REG can be found at OFFSET from the CFA, and return true.
// On failure, report and return false. (Subroutine for DW_CFA_offset,
// DW_CFA_offset_extended, and DW_CFA_offset_extended_sf.)
bool DoOffset(unsigned reg, long offset);
// Specify that the caller's value for REG is the CFA plus OFFSET,
// and return true. On failure, report and return false. (Subroutine
// for DW_CFA_val_offset and DW_CFA_val_offset_sf.)
bool DoValOffset(unsigned reg, long offset);
// Restore REG to the rule established in the CIE, and return true. On
// failure, report and return false. (Subroutine for DW_CFA_restore and
// DW_CFA_restore_extended.)
bool DoRestore(unsigned reg);
// Return the section offset of the instruction at cursor. For use
// in error messages.
uint64 CursorOffset() { return entry_->offset + (cursor_ - entry_->start); }
// Report that entry_ is incomplete, and return false. For brevity.
bool ReportIncomplete() {
reporter_->Incomplete(entry_->offset, entry_->kind);
return false;
}
// For reading multi-byte values with the appropriate endianness.
ByteReader* reader_;
// The handler to which we should report the data we find.
Handler* handler_;
// For reporting problems in the info we're parsing.
Reporter* reporter_;
// The code address to which the next instruction in the stream applies.
uint64 address_;
// The entry whose instructions we are currently processing. This is
// first a CIE, and then an FDE.
const Entry* entry_;
// The next instruction to process.
const char* cursor_;
// The current set of rules.
RuleMap rules_;
// The set of rules established by the CIE, used by DW_CFA_restore
// and DW_CFA_restore_extended. We set this after interpreting the
// CIE's instructions.
RuleMap cie_rules_;
// A stack of saved states, for DW_CFA_remember_state and
// DW_CFA_restore_state.
std::stack<RuleMap>* saved_rules_;
};
bool CallFrameInfo::State::InterpretCIE(const CIE& cie) {
entry_ = &cie;
cursor_ = entry_->instructions;
if (!DoInstructions()) {
return false;
}
// Note the rules established by the CIE, for use by DW_CFA_restore
// and DW_CFA_restore_extended.
cie_rules_ = rules_;
return true;
}
bool CallFrameInfo::State::InterpretFDE(const FDE& fde) {
entry_ = &fde;
cursor_ = entry_->instructions;
return DoInstructions();
}
bool CallFrameInfo::State::ParseOperands(const char* format,
Operands* operands) {
size_t len;
const char* operand;
for (operand = format; *operand; operand++) {
size_t bytes_left = entry_->end - cursor_;
switch (*operand) {
case 'r':
operands->register_number = reader_->ReadUnsignedLEB128(cursor_, &len);
if (len > bytes_left) return ReportIncomplete();
cursor_ += len;
break;
case 'o':
operands->offset = reader_->ReadUnsignedLEB128(cursor_, &len);
if (len > bytes_left) return ReportIncomplete();
cursor_ += len;
break;
case 's':
operands->signed_offset = reader_->ReadSignedLEB128(cursor_, &len);
if (len > bytes_left) return ReportIncomplete();
cursor_ += len;
break;
case 'a':
operands->offset = reader_->ReadEncodedPointer(
cursor_, entry_->cie->pointer_encoding, &len);
if (len > bytes_left) return ReportIncomplete();
cursor_ += len;
break;
case '1':
if (1 > bytes_left) return ReportIncomplete();
operands->offset = static_cast<unsigned char>(*cursor_++);
break;
case '2':
if (2 > bytes_left) return ReportIncomplete();
operands->offset = reader_->ReadTwoBytes(cursor_);
cursor_ += 2;
break;
case '4':
if (4 > bytes_left) return ReportIncomplete();
operands->offset = reader_->ReadFourBytes(cursor_);
cursor_ += 4;
break;
case '8':
if (8 > bytes_left) return ReportIncomplete();
operands->offset = reader_->ReadEightBytes(cursor_);
cursor_ += 8;
break;
case 'e': {
size_t expression_length = reader_->ReadUnsignedLEB128(cursor_, &len);
if (len > bytes_left || expression_length > bytes_left - len)
return ReportIncomplete();
cursor_ += len;
operands->expression = ImageSlice(cursor_, expression_length);
cursor_ += expression_length;
break;
}
default:
MOZ_ASSERT(0);
}
}
return true;
}
MOZ_ALWAYS_INLINE
bool CallFrameInfo::State::DoInstruction() {
CIE* cie = entry_->cie;
Operands ops;
// Our entry's kind should have been set by now.
MOZ_ASSERT(entry_->kind != kUnknown);
// We shouldn't have been invoked unless there were more
// instructions to parse.
MOZ_ASSERT(cursor_ < entry_->end);
unsigned opcode = *cursor_++;
if ((opcode & 0xc0) != 0) {
switch (opcode & 0xc0) {
// Advance the address.
case DW_CFA_advance_loc: {
size_t code_offset = opcode & 0x3f;
address_ += code_offset * cie->code_alignment_factor;
break;
}
// Find a register at an offset from the CFA.
case DW_CFA_offset:
if (!ParseOperands("o", &ops) ||
!DoOffset(opcode & 0x3f, ops.offset * cie->data_alignment_factor))
return false;
break;
// Restore the rule established for a register by the CIE.
case DW_CFA_restore:
if (!DoRestore(opcode & 0x3f)) return false;
break;
// The 'if' above should have excluded this possibility.
default:
MOZ_ASSERT(0);
}
// Return here, so the big switch below won't be indented.
return true;
}
switch (opcode) {
// Set the address.
case DW_CFA_set_loc:
if (!ParseOperands("a", &ops)) return false;
address_ = ops.offset;
break;
// Advance the address.
case DW_CFA_advance_loc1:
if (!ParseOperands("1", &ops)) return false;
address_ += ops.offset * cie->code_alignment_factor;
break;
// Advance the address.
case DW_CFA_advance_loc2:
if (!ParseOperands("2", &ops)) return false;
address_ += ops.offset * cie->code_alignment_factor;
break;
// Advance the address.
case DW_CFA_advance_loc4:
if (!ParseOperands("4", &ops)) return false;
address_ += ops.offset * cie->code_alignment_factor;
break;
// Advance the address.
case DW_CFA_MIPS_advance_loc8:
if (!ParseOperands("8", &ops)) return false;
address_ += ops.offset * cie->code_alignment_factor;
break;
// Compute the CFA by adding an offset to a register.
case DW_CFA_def_cfa:
if (!ParseOperands("ro", &ops) ||
!DoDefCFA(ops.register_number, ops.offset))
return false;
break;
// Compute the CFA by adding an offset to a register.
case DW_CFA_def_cfa_sf:
if (!ParseOperands("rs", &ops) ||
!DoDefCFA(ops.register_number,
ops.signed_offset * cie->data_alignment_factor))
return false;
break;
// Change the base register used to compute the CFA.
case DW_CFA_def_cfa_register: {
Rule* cfa_rule = rules_.CFARuleRef();
if (!cfa_rule->isVALID()) {
reporter_->NoCFARule(entry_->offset, entry_->kind, CursorOffset());
return false;
}
if (!ParseOperands("r", &ops)) return false;
cfa_rule->SetBaseRegister(ops.register_number);
if (!cfa_rule->Handle(handler_, address_, Handler::kCFARegister))
return false;
break;
}
// Change the offset used to compute the CFA.
case DW_CFA_def_cfa_offset:
if (!ParseOperands("o", &ops) || !DoDefCFAOffset(ops.offset))
return false;
break;
// Change the offset used to compute the CFA.
case DW_CFA_def_cfa_offset_sf:
if (!ParseOperands("s", &ops) ||
!DoDefCFAOffset(ops.signed_offset * cie->data_alignment_factor))
return false;
break;
// Specify an expression whose value is the CFA.
case DW_CFA_def_cfa_expression: {
if (!ParseOperands("e", &ops)) return false;
Rule rule = Rule::mkValExpressionRule(ops.expression);
rules_.SetCFARule(rule);
if (!rule.Handle(handler_, address_, Handler::kCFARegister)) return false;
break;
}
// The register's value cannot be recovered.
case DW_CFA_undefined: {
if (!ParseOperands("r", &ops) ||
!DoRule(ops.register_number, Rule::mkUndefinedRule()))
return false;
break;
}
// The register's value is unchanged from its value in the caller.
case DW_CFA_same_value: {
if (!ParseOperands("r", &ops) ||
!DoRule(ops.register_number, Rule::mkSameValueRule()))
return false;
break;
}
// Find a register at an offset from the CFA.
case DW_CFA_offset_extended:
if (!ParseOperands("ro", &ops) ||
!DoOffset(ops.register_number,
ops.offset * cie->data_alignment_factor))
return false;
break;
// The register is saved at an offset from the CFA.
case DW_CFA_offset_extended_sf:
if (!ParseOperands("rs", &ops) ||
!DoOffset(ops.register_number,
ops.signed_offset * cie->data_alignment_factor))
return false;
break;
// The register is saved at an offset from the CFA.
case DW_CFA_GNU_negative_offset_extended:
if (!ParseOperands("ro", &ops) ||
!DoOffset(ops.register_number,
-ops.offset * cie->data_alignment_factor))
return false;
break;
// The register's value is the sum of the CFA plus an offset.
case DW_CFA_val_offset:
if (!ParseOperands("ro", &ops) ||
!DoValOffset(ops.register_number,
ops.offset * cie->data_alignment_factor))
return false;
break;
// The register's value is the sum of the CFA plus an offset.
case DW_CFA_val_offset_sf:
if (!ParseOperands("rs", &ops) ||
!DoValOffset(ops.register_number,
ops.signed_offset * cie->data_alignment_factor))
return false;
break;
// The register has been saved in another register.
case DW_CFA_register: {
if (!ParseOperands("ro", &ops) ||
!DoRule(ops.register_number, Rule::mkRegisterRule(ops.offset)))
return false;
break;
}
// An expression yields the address at which the register is saved.
case DW_CFA_expression: {
if (!ParseOperands("re", &ops) ||
!DoRule(ops.register_number, Rule::mkExpressionRule(ops.expression)))
return false;
break;
}
// An expression yields the caller's value for the register.
case DW_CFA_val_expression: {
if (!ParseOperands("re", &ops) ||
!DoRule(ops.register_number,
Rule::mkValExpressionRule(ops.expression)))
return false;
break;
}
// Restore the rule established for a register by the CIE.
case DW_CFA_restore_extended:
if (!ParseOperands("r", &ops) || !DoRestore(ops.register_number))
return false;
break;
// Save the current set of rules on a stack.
case DW_CFA_remember_state:
if (!saved_rules_) {
saved_rules_ = new std::stack<RuleMap>();
}
saved_rules_->push(rules_);
break;
// Pop the current set of rules off the stack.
case DW_CFA_restore_state: {
if (!saved_rules_ || saved_rules_->empty()) {
reporter_->EmptyStateStack(entry_->offset, entry_->kind,
CursorOffset());
return false;
}
const RuleMap& new_rules = saved_rules_->top();
if (rules_.CFARule().isVALID() && !new_rules.CFARule().isVALID()) {
reporter_->ClearingCFARule(entry_->offset, entry_->kind,
CursorOffset());
return false;
}
rules_.HandleTransitionTo(handler_, address_, new_rules);
rules_ = new_rules;
saved_rules_->pop();
break;
}
// No operation. (Padding instruction.)
case DW_CFA_nop:
break;
// A SPARC register window save: Registers 8 through 15 (%o0-%o7)
// are saved in registers 24 through 31 (%i0-%i7), and registers
// 16 through 31 (%l0-%l7 and %i0-%i7) are saved at CFA offsets
// (0-15 * the register size). The register numbers must be
// hard-coded. A GNU extension, and not a pretty one.
case DW_CFA_GNU_window_save: {
// Save %o0-%o7 in %i0-%i7.
for (int i = 8; i < 16; i++)
if (!DoRule(i, Rule::mkRegisterRule(i + 16))) return false;
// Save %l0-%l7 and %i0-%i7 at the CFA.
for (int i = 16; i < 32; i++)
// Assume that the byte reader's address size is the same as
// the architecture's register size. !@#%*^ hilarious.
if (!DoRule(i, Rule::mkOffsetRule(Handler::kCFARegister,
(i - 16) * reader_->AddressSize())))
return false;
break;
}
// I'm not sure what this is. GDB doesn't use it for unwinding.
case DW_CFA_GNU_args_size:
if (!ParseOperands("o", &ops)) return false;
break;
// An opcode we don't recognize.
default: {
reporter_->BadInstruction(entry_->offset, entry_->kind, CursorOffset());
return false;
}
}
return true;
}
// See declaration above for rationale re the no-inline directive.
MOZ_NEVER_INLINE
bool CallFrameInfo::State::DoInstructions() {
while (cursor_ < entry_->end) {
if (!DoInstruction()) {
return false;
}
}
return true;
}
bool CallFrameInfo::State::DoDefCFA(unsigned base_register, long offset) {
Rule rule = Rule::mkValOffsetRule(base_register, offset);
rules_.SetCFARule(rule);
return rule.Handle(handler_, address_, Handler::kCFARegister);
}
bool CallFrameInfo::State::DoDefCFAOffset(long offset) {
Rule* cfa_rule = rules_.CFARuleRef();
if (!cfa_rule->isVALID()) {
reporter_->NoCFARule(entry_->offset, entry_->kind, CursorOffset());
return false;
}
cfa_rule->SetOffset(offset);
return cfa_rule->Handle(handler_, address_, Handler::kCFARegister);
}
bool CallFrameInfo::State::DoRule(unsigned reg, Rule rule) {
rules_.SetRegisterRule(reg, rule);
return rule.Handle(handler_, address_, reg);
}
bool CallFrameInfo::State::DoOffset(unsigned reg, long offset) {
if (!rules_.CFARule().isVALID()) {
reporter_->NoCFARule(entry_->offset, entry_->kind, CursorOffset());
return false;
}
Rule rule = Rule::mkOffsetRule(Handler::kCFARegister, offset);
return DoRule(reg, rule);
}
bool CallFrameInfo::State::DoValOffset(unsigned reg, long offset) {
if (!rules_.CFARule().isVALID()) {
reporter_->NoCFARule(entry_->offset, entry_->kind, CursorOffset());
return false;
}
return DoRule(reg, Rule::mkValOffsetRule(Handler::kCFARegister, offset));
}
bool CallFrameInfo::State::DoRestore(unsigned reg) {
// DW_CFA_restore and DW_CFA_restore_extended don't make sense in a CIE.
if (entry_->kind == kCIE) {
reporter_->RestoreInCIE(entry_->offset, CursorOffset());
return false;
}
Rule rule = cie_rules_.RegisterRule(reg);
if (!rule.isVALID()) {
// This isn't really the right thing to do, but since CFI generally
// only mentions callee-saves registers, and GCC's convention for
// callee-saves registers is that they are unchanged, it's a good
// approximation.
rule = Rule::mkSameValueRule();
}
return DoRule(reg, rule);
}
bool CallFrameInfo::ReadEntryPrologue(const char* cursor, Entry* entry) {
const char* buffer_end = buffer_ + buffer_length_;
// Initialize enough of ENTRY for use in error reporting.
entry->offset = cursor - buffer_;
entry->start = cursor;
entry->kind = kUnknown;
entry->end = NULL;
// Read the initial length. This sets reader_'s offset size.
size_t length_size;
uint64 length = reader_->ReadInitialLength(cursor, &length_size);
if (length_size > size_t(buffer_end - cursor)) return ReportIncomplete(entry);
cursor += length_size;
// In a .eh_frame section, a length of zero marks the end of the series
// of entries.
if (length == 0 && eh_frame_) {
entry->kind = kTerminator;
entry->end = cursor;
return true;
}
// Validate the length.
if (length > size_t(buffer_end - cursor)) return ReportIncomplete(entry);
// The length is the number of bytes after the initial length field;
// we have that position handy at this point, so compute the end
// now. (If we're parsing 64-bit-offset DWARF on a 32-bit machine,
// and the length didn't fit in a size_t, we would have rejected it
// above.)
entry->end = cursor + length;
// Parse the next field: either the offset of a CIE or a CIE id.
size_t offset_size = reader_->OffsetSize();
if (offset_size > size_t(entry->end - cursor)) return ReportIncomplete(entry);
entry->id = reader_->ReadOffset(cursor);
// Don't advance cursor past id field yet; in .eh_frame data we need
// the id's position to compute the section offset of an FDE's CIE.
// Now we can decide what kind of entry this is.
if (eh_frame_) {
// In .eh_frame data, an ID of zero marks the entry as a CIE, and
// anything else is an offset from the id field of the FDE to the start
// of the CIE.
if (entry->id == 0) {
entry->kind = kCIE;
} else {
entry->kind = kFDE;
// Turn the offset from the id into an offset from the buffer's start.
entry->id = (cursor - buffer_) - entry->id;
}
} else {
// In DWARF CFI data, an ID of ~0 (of the appropriate width, given the
// offset size for the entry) marks the entry as a CIE, and anything
// else is the offset of the CIE from the beginning of the section.
if (offset_size == 4)
entry->kind = (entry->id == 0xffffffff) ? kCIE : kFDE;
else {
MOZ_ASSERT(offset_size == 8);
entry->kind = (entry->id == 0xffffffffffffffffULL) ? kCIE : kFDE;
}
}
// Now advance cursor past the id.
cursor += offset_size;
// The fields specific to this kind of entry start here.
entry->fields = cursor;
entry->cie = NULL;
return true;
}
bool CallFrameInfo::ReadCIEFields(CIE* cie) {
const char* cursor = cie->fields;
size_t len;
MOZ_ASSERT(cie->kind == kCIE);
// Prepare for early exit.
cie->version = 0;
cie->augmentation.clear();
cie->code_alignment_factor = 0;
cie->data_alignment_factor = 0;
cie->return_address_register = 0;
cie->has_z_augmentation = false;
cie->pointer_encoding = DW_EH_PE_absptr;
cie->instructions = 0;
// Parse the version number.