toolkit/crashreporter/google-breakpad/src/processor/stackwalker_sparc.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/processor/stackwalker_sparc.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,139 @@
     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 +// stackwalker_sparc.cc: sparc-specific stackwalker.
    1.34 +//
    1.35 +// See stackwalker_sparc.h for documentation.
    1.36 +//
    1.37 +// Author: Michael Shang
    1.38 +
    1.39 +
    1.40 +#include "google_breakpad/processor/call_stack.h"
    1.41 +#include "google_breakpad/processor/memory_region.h"
    1.42 +#include "google_breakpad/processor/stack_frame_cpu.h"
    1.43 +#include "common/logging.h"
    1.44 +#include "processor/stackwalker_sparc.h"
    1.45 +
    1.46 +namespace google_breakpad {
    1.47 +
    1.48 +
    1.49 +StackwalkerSPARC::StackwalkerSPARC(const SystemInfo* system_info,
    1.50 +                                   const MDRawContextSPARC* context,
    1.51 +                                   MemoryRegion* memory,
    1.52 +                                   const CodeModules* modules,
    1.53 +                                   StackFrameSymbolizer* resolver_helper)
    1.54 +    : Stackwalker(system_info, memory, modules, resolver_helper),
    1.55 +      context_(context) {
    1.56 +}
    1.57 +
    1.58 +
    1.59 +StackFrame* StackwalkerSPARC::GetContextFrame() {
    1.60 +  if (!context_) {
    1.61 +    BPLOG(ERROR) << "Can't get context frame without context";
    1.62 +    return NULL;
    1.63 +  }
    1.64 +
    1.65 +  StackFrameSPARC* frame = new StackFrameSPARC();
    1.66 +
    1.67 +  // The instruction pointer is stored directly in a register, so pull it
    1.68 +  // straight out of the CPU context structure.
    1.69 +  frame->context = *context_;
    1.70 +  frame->context_validity = StackFrameSPARC::CONTEXT_VALID_ALL;
    1.71 +  frame->trust = StackFrame::FRAME_TRUST_CONTEXT;
    1.72 +  frame->instruction = frame->context.pc;
    1.73 +
    1.74 +  return frame;
    1.75 +}
    1.76 +
    1.77 +
    1.78 +StackFrame* StackwalkerSPARC::GetCallerFrame(const CallStack* stack,
    1.79 +                                             bool stack_scan_allowed) {
    1.80 +  if (!memory_ || !stack) {
    1.81 +    BPLOG(ERROR) << "Can't get caller frame without memory or stack";
    1.82 +    return NULL;
    1.83 +  }
    1.84 +
    1.85 +  StackFrameSPARC* last_frame = static_cast<StackFrameSPARC*>(
    1.86 +      stack->frames()->back());
    1.87 +
    1.88 +  // new: caller
    1.89 +  // old: callee
    1.90 +  // %fp, %i6 and g_r[30] is the same, see minidump_format.h
    1.91 +  // %sp, %o6 and g_r[14] is the same, see minidump_format.h
    1.92 +  // %sp_new = %fp_old
    1.93 +  // %fp_new = *(%fp_old + 32 + 32 - 8), where the callee's %i6
    1.94 +  // %pc_new = *(%fp_old + 32 + 32 - 4) + 8
    1.95 +  // which is callee's %i7 plus 8
    1.96 +
    1.97 +  // A caller frame must reside higher in memory than its callee frames.
    1.98 +  // Anything else is an error, or an indication that we've reached the
    1.99 +  // end of the stack.
   1.100 +  uint64_t stack_pointer = last_frame->context.g_r[30];
   1.101 +  if (stack_pointer <= last_frame->context.g_r[14]) {
   1.102 +    return NULL;
   1.103 +  }
   1.104 +
   1.105 +  uint32_t instruction;
   1.106 +  if (!memory_->GetMemoryAtAddress(stack_pointer + 60,
   1.107 +                     &instruction) || instruction <= 1) {
   1.108 +    return NULL;
   1.109 +  }
   1.110 +
   1.111 +  uint32_t stack_base;
   1.112 +  if (!memory_->GetMemoryAtAddress(stack_pointer + 56,
   1.113 +                     &stack_base) || stack_base <= 1) {
   1.114 +    return NULL;
   1.115 +  }
   1.116 +
   1.117 +  StackFrameSPARC* frame = new StackFrameSPARC();
   1.118 +
   1.119 +  frame->context = last_frame->context;
   1.120 +  frame->context.g_r[14] = stack_pointer;
   1.121 +  frame->context.g_r[30] = stack_base;
   1.122 +
   1.123 +  // frame->context.pc is the return address, which is 2 instruction
   1.124 +  // past the branch that caused us to arrive at the callee, which are
   1.125 +  // a CALL instruction then a NOP instruction.
   1.126 +  // frame_ppc->instruction to 8 less than that.  Since all sparc
   1.127 +  // instructions are 4 bytes wide, this is the address of the branch
   1.128 +  // instruction.  This allows source line information to match up with the
   1.129 +  // line that contains a function call.  Callers that require the exact
   1.130 +  // return address value may access the %i7/g_r[31] field of StackFrameSPARC.
   1.131 +  frame->context.pc = instruction + 8;
   1.132 +  frame->instruction = instruction;
   1.133 +  frame->context_validity = StackFrameSPARC::CONTEXT_VALID_PC |
   1.134 +                            StackFrameSPARC::CONTEXT_VALID_SP |
   1.135 +                            StackFrameSPARC::CONTEXT_VALID_FP;
   1.136 +  frame->trust = StackFrame::FRAME_TRUST_FP;
   1.137 +
   1.138 +  return frame;
   1.139 +}
   1.140 +
   1.141 +
   1.142 +}  // namespace google_breakpad

mercurial