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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2010 Google Inc.
michael@0 2 // All rights reserved.
michael@0 3 //
michael@0 4 // Redistribution and use in source and binary forms, with or without
michael@0 5 // modification, are permitted provided that the following conditions are
michael@0 6 // met:
michael@0 7 //
michael@0 8 // * Redistributions of source code must retain the above copyright
michael@0 9 // notice, this list of conditions and the following disclaimer.
michael@0 10 // * Redistributions in binary form must reproduce the above
michael@0 11 // copyright notice, this list of conditions and the following disclaimer
michael@0 12 // in the documentation and/or other materials provided with the
michael@0 13 // distribution.
michael@0 14 // * Neither the name of Google Inc. nor the names of its
michael@0 15 // contributors may be used to endorse or promote products derived from
michael@0 16 // this software without specific prior written permission.
michael@0 17 //
michael@0 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
michael@0 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@0 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@0 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
michael@0 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
michael@0 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 29
michael@0 30 // stackwalker_sparc.cc: sparc-specific stackwalker.
michael@0 31 //
michael@0 32 // See stackwalker_sparc.h for documentation.
michael@0 33 //
michael@0 34 // Author: Michael Shang
michael@0 35
michael@0 36
michael@0 37 #include "google_breakpad/processor/call_stack.h"
michael@0 38 #include "google_breakpad/processor/memory_region.h"
michael@0 39 #include "google_breakpad/processor/stack_frame_cpu.h"
michael@0 40 #include "common/logging.h"
michael@0 41 #include "processor/stackwalker_sparc.h"
michael@0 42
michael@0 43 namespace google_breakpad {
michael@0 44
michael@0 45
michael@0 46 StackwalkerSPARC::StackwalkerSPARC(const SystemInfo* system_info,
michael@0 47 const MDRawContextSPARC* context,
michael@0 48 MemoryRegion* memory,
michael@0 49 const CodeModules* modules,
michael@0 50 StackFrameSymbolizer* resolver_helper)
michael@0 51 : Stackwalker(system_info, memory, modules, resolver_helper),
michael@0 52 context_(context) {
michael@0 53 }
michael@0 54
michael@0 55
michael@0 56 StackFrame* StackwalkerSPARC::GetContextFrame() {
michael@0 57 if (!context_) {
michael@0 58 BPLOG(ERROR) << "Can't get context frame without context";
michael@0 59 return NULL;
michael@0 60 }
michael@0 61
michael@0 62 StackFrameSPARC* frame = new StackFrameSPARC();
michael@0 63
michael@0 64 // The instruction pointer is stored directly in a register, so pull it
michael@0 65 // straight out of the CPU context structure.
michael@0 66 frame->context = *context_;
michael@0 67 frame->context_validity = StackFrameSPARC::CONTEXT_VALID_ALL;
michael@0 68 frame->trust = StackFrame::FRAME_TRUST_CONTEXT;
michael@0 69 frame->instruction = frame->context.pc;
michael@0 70
michael@0 71 return frame;
michael@0 72 }
michael@0 73
michael@0 74
michael@0 75 StackFrame* StackwalkerSPARC::GetCallerFrame(const CallStack* stack,
michael@0 76 bool stack_scan_allowed) {
michael@0 77 if (!memory_ || !stack) {
michael@0 78 BPLOG(ERROR) << "Can't get caller frame without memory or stack";
michael@0 79 return NULL;
michael@0 80 }
michael@0 81
michael@0 82 StackFrameSPARC* last_frame = static_cast<StackFrameSPARC*>(
michael@0 83 stack->frames()->back());
michael@0 84
michael@0 85 // new: caller
michael@0 86 // old: callee
michael@0 87 // %fp, %i6 and g_r[30] is the same, see minidump_format.h
michael@0 88 // %sp, %o6 and g_r[14] is the same, see minidump_format.h
michael@0 89 // %sp_new = %fp_old
michael@0 90 // %fp_new = *(%fp_old + 32 + 32 - 8), where the callee's %i6
michael@0 91 // %pc_new = *(%fp_old + 32 + 32 - 4) + 8
michael@0 92 // which is callee's %i7 plus 8
michael@0 93
michael@0 94 // A caller frame must reside higher in memory than its callee frames.
michael@0 95 // Anything else is an error, or an indication that we've reached the
michael@0 96 // end of the stack.
michael@0 97 uint64_t stack_pointer = last_frame->context.g_r[30];
michael@0 98 if (stack_pointer <= last_frame->context.g_r[14]) {
michael@0 99 return NULL;
michael@0 100 }
michael@0 101
michael@0 102 uint32_t instruction;
michael@0 103 if (!memory_->GetMemoryAtAddress(stack_pointer + 60,
michael@0 104 &instruction) || instruction <= 1) {
michael@0 105 return NULL;
michael@0 106 }
michael@0 107
michael@0 108 uint32_t stack_base;
michael@0 109 if (!memory_->GetMemoryAtAddress(stack_pointer + 56,
michael@0 110 &stack_base) || stack_base <= 1) {
michael@0 111 return NULL;
michael@0 112 }
michael@0 113
michael@0 114 StackFrameSPARC* frame = new StackFrameSPARC();
michael@0 115
michael@0 116 frame->context = last_frame->context;
michael@0 117 frame->context.g_r[14] = stack_pointer;
michael@0 118 frame->context.g_r[30] = stack_base;
michael@0 119
michael@0 120 // frame->context.pc is the return address, which is 2 instruction
michael@0 121 // past the branch that caused us to arrive at the callee, which are
michael@0 122 // a CALL instruction then a NOP instruction.
michael@0 123 // frame_ppc->instruction to 8 less than that. Since all sparc
michael@0 124 // instructions are 4 bytes wide, this is the address of the branch
michael@0 125 // instruction. This allows source line information to match up with the
michael@0 126 // line that contains a function call. Callers that require the exact
michael@0 127 // return address value may access the %i7/g_r[31] field of StackFrameSPARC.
michael@0 128 frame->context.pc = instruction + 8;
michael@0 129 frame->instruction = instruction;
michael@0 130 frame->context_validity = StackFrameSPARC::CONTEXT_VALID_PC |
michael@0 131 StackFrameSPARC::CONTEXT_VALID_SP |
michael@0 132 StackFrameSPARC::CONTEXT_VALID_FP;
michael@0 133 frame->trust = StackFrame::FRAME_TRUST_FP;
michael@0 134
michael@0 135 return frame;
michael@0 136 }
michael@0 137
michael@0 138
michael@0 139 } // namespace google_breakpad

mercurial