toolkit/crashreporter/google-breakpad/src/common/dwarf/cfi_assembler.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/common/dwarf/cfi_assembler.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,198 @@
     1.4 +// Copyright (c) 2010, Google Inc.
     1.5 +// All rights reserved.
     1.6 +//
     1.7 +// Redistribution and use in source and binary forms, with or without
     1.8 +// modification, are permitted provided that the following conditions are
     1.9 +// met:
    1.10 +//
    1.11 +//     * Redistributions of source code must retain the above copyright
    1.12 +// notice, this list of conditions and the following disclaimer.
    1.13 +//     * Redistributions in binary form must reproduce the above
    1.14 +// copyright notice, this list of conditions and the following disclaimer
    1.15 +// in the documentation and/or other materials provided with the
    1.16 +// distribution.
    1.17 +//     * Neither the name of Google Inc. nor the names of its
    1.18 +// contributors may be used to endorse or promote products derived from
    1.19 +// this software without specific prior written permission.
    1.20 +//
    1.21 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.22 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.23 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.24 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.25 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.26 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.27 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.28 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.29 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.30 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.31 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.32 +
    1.33 +// Original author: Jim Blandy <jimb@mozilla.com> <jimb@red-bean.com>
    1.34 +
    1.35 +// cfi_assembler.cc: Implementation of google_breakpad::CFISection class.
    1.36 +// See cfi_assembler.h for details.
    1.37 +
    1.38 +#include "common/dwarf/cfi_assembler.h"
    1.39 +
    1.40 +#include <assert.h>
    1.41 +#include <stdlib.h>
    1.42 +
    1.43 +namespace google_breakpad {
    1.44 +
    1.45 +using dwarf2reader::DwarfPointerEncoding;
    1.46 +  
    1.47 +CFISection &CFISection::CIEHeader(uint64_t code_alignment_factor,
    1.48 +                                  int data_alignment_factor,
    1.49 +                                  unsigned return_address_register,
    1.50 +                                  uint8_t version,
    1.51 +                                  const string &augmentation,
    1.52 +                                  bool dwarf64) {
    1.53 +  assert(!entry_length_);
    1.54 +  entry_length_ = new PendingLength();
    1.55 +  in_fde_ = false;
    1.56 +
    1.57 +  if (dwarf64) {
    1.58 +    D32(kDwarf64InitialLengthMarker);
    1.59 +    D64(entry_length_->length);
    1.60 +    entry_length_->start = Here();
    1.61 +    D64(eh_frame_ ? kEHFrame64CIEIdentifier : kDwarf64CIEIdentifier);
    1.62 +  } else {
    1.63 +    D32(entry_length_->length);
    1.64 +    entry_length_->start = Here();
    1.65 +    D32(eh_frame_ ? kEHFrame32CIEIdentifier : kDwarf32CIEIdentifier);
    1.66 +  }
    1.67 +  D8(version);
    1.68 +  AppendCString(augmentation);
    1.69 +  ULEB128(code_alignment_factor);
    1.70 +  LEB128(data_alignment_factor);
    1.71 +  if (version == 1)
    1.72 +    D8(return_address_register);
    1.73 +  else
    1.74 +    ULEB128(return_address_register);
    1.75 +  return *this;
    1.76 +}
    1.77 +
    1.78 +CFISection &CFISection::FDEHeader(Label cie_pointer,
    1.79 +                                  uint64_t initial_location,
    1.80 +                                  uint64_t address_range,
    1.81 +                                  bool dwarf64) {
    1.82 +  assert(!entry_length_);
    1.83 +  entry_length_ = new PendingLength();
    1.84 +  in_fde_ = true;
    1.85 +  fde_start_address_ = initial_location;
    1.86 +
    1.87 +  if (dwarf64) {
    1.88 +    D32(0xffffffff);
    1.89 +    D64(entry_length_->length);
    1.90 +    entry_length_->start = Here();
    1.91 +    if (eh_frame_)
    1.92 +      D64(Here() - cie_pointer);
    1.93 +    else
    1.94 +      D64(cie_pointer);
    1.95 +  } else {
    1.96 +    D32(entry_length_->length);
    1.97 +    entry_length_->start = Here();
    1.98 +    if (eh_frame_)
    1.99 +      D32(Here() - cie_pointer);
   1.100 +    else
   1.101 +      D32(cie_pointer);
   1.102 +  }
   1.103 +  EncodedPointer(initial_location);
   1.104 +  // The FDE length in an .eh_frame section uses the same encoding as the
   1.105 +  // initial location, but ignores the base address (selected by the upper
   1.106 +  // nybble of the encoding), as it's a length, not an address that can be
   1.107 +  // made relative.
   1.108 +  EncodedPointer(address_range,
   1.109 +                 DwarfPointerEncoding(pointer_encoding_ & 0x0f));
   1.110 +  return *this;
   1.111 +}
   1.112 +
   1.113 +CFISection &CFISection::FinishEntry() {
   1.114 +  assert(entry_length_);
   1.115 +  Align(address_size_, dwarf2reader::DW_CFA_nop);
   1.116 +  entry_length_->length = Here() - entry_length_->start;
   1.117 +  delete entry_length_;
   1.118 +  entry_length_ = NULL;
   1.119 +  in_fde_ = false;
   1.120 +  return *this;
   1.121 +}
   1.122 +
   1.123 +CFISection &CFISection::EncodedPointer(uint64_t address,
   1.124 +                                       DwarfPointerEncoding encoding,
   1.125 +                                       const EncodedPointerBases &bases) {
   1.126 +  // Omitted data is extremely easy to emit.
   1.127 +  if (encoding == dwarf2reader::DW_EH_PE_omit)
   1.128 +    return *this;
   1.129 +
   1.130 +  // If (encoding & dwarf2reader::DW_EH_PE_indirect) != 0, then we assume
   1.131 +  // that ADDRESS is the address at which the pointer is stored --- in
   1.132 +  // other words, that bit has no effect on how we write the pointer.
   1.133 +  encoding = DwarfPointerEncoding(encoding & ~dwarf2reader::DW_EH_PE_indirect);
   1.134 +
   1.135 +  // Find the base address to which this pointer is relative. The upper
   1.136 +  // nybble of the encoding specifies this.
   1.137 +  uint64_t base;
   1.138 +  switch (encoding & 0xf0) {
   1.139 +    case dwarf2reader::DW_EH_PE_absptr:  base = 0;                  break;
   1.140 +    case dwarf2reader::DW_EH_PE_pcrel:   base = bases.cfi + Size(); break;
   1.141 +    case dwarf2reader::DW_EH_PE_textrel: base = bases.text;         break;
   1.142 +    case dwarf2reader::DW_EH_PE_datarel: base = bases.data;         break;
   1.143 +    case dwarf2reader::DW_EH_PE_funcrel: base = fde_start_address_; break;
   1.144 +    case dwarf2reader::DW_EH_PE_aligned: base = 0;                  break;
   1.145 +    default: abort();
   1.146 +  };
   1.147 +
   1.148 +  // Make ADDRESS relative. Yes, this is appropriate even for "absptr"
   1.149 +  // values; see gcc/unwind-pe.h.
   1.150 +  address -= base;
   1.151 +
   1.152 +  // Align the pointer, if required.
   1.153 +  if ((encoding & 0xf0) == dwarf2reader::DW_EH_PE_aligned)
   1.154 +    Align(AddressSize());
   1.155 +
   1.156 +  // Append ADDRESS to this section in the appropriate form. For the
   1.157 +  // fixed-width forms, we don't need to differentiate between signed and
   1.158 +  // unsigned encodings, because ADDRESS has already been extended to 64
   1.159 +  // bits before it was passed to us.
   1.160 +  switch (encoding & 0x0f) {
   1.161 +    case dwarf2reader::DW_EH_PE_absptr:
   1.162 +      Address(address);
   1.163 +      break;
   1.164 +
   1.165 +    case dwarf2reader::DW_EH_PE_uleb128:
   1.166 +      ULEB128(address);
   1.167 +      break;
   1.168 +
   1.169 +    case dwarf2reader::DW_EH_PE_sleb128:
   1.170 +      LEB128(address);
   1.171 +      break;
   1.172 +
   1.173 +    case dwarf2reader::DW_EH_PE_udata2:
   1.174 +    case dwarf2reader::DW_EH_PE_sdata2:
   1.175 +      D16(address);
   1.176 +      break;
   1.177 +
   1.178 +    case dwarf2reader::DW_EH_PE_udata4:
   1.179 +    case dwarf2reader::DW_EH_PE_sdata4:
   1.180 +      D32(address);
   1.181 +      break;
   1.182 +
   1.183 +    case dwarf2reader::DW_EH_PE_udata8:
   1.184 +    case dwarf2reader::DW_EH_PE_sdata8:
   1.185 +      D64(address);
   1.186 +      break;
   1.187 +
   1.188 +    default:
   1.189 +      abort();
   1.190 +  }
   1.191 +
   1.192 +  return *this;
   1.193 +};
   1.194 +
   1.195 +const uint32_t CFISection::kDwarf64InitialLengthMarker;
   1.196 +const uint32_t CFISection::kDwarf32CIEIdentifier;
   1.197 +const uint64_t CFISection::kDwarf64CIEIdentifier;
   1.198 +const uint32_t CFISection::kEHFrame32CIEIdentifier;
   1.199 +const uint64_t CFISection::kEHFrame64CIEIdentifier;
   1.200 +
   1.201 +} // namespace google_breakpad

mercurial