toolkit/crashreporter/google-breakpad/src/processor/stackwalker_ppc.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_ppc.cc: ppc-specific stackwalker.
michael@0 31 //
michael@0 32 // See stackwalker_ppc.h for documentation.
michael@0 33 //
michael@0 34 // Author: Mark Mentovai
michael@0 35
michael@0 36
michael@0 37 #include "processor/stackwalker_ppc.h"
michael@0 38 #include "google_breakpad/processor/call_stack.h"
michael@0 39 #include "google_breakpad/processor/memory_region.h"
michael@0 40 #include "google_breakpad/processor/stack_frame_cpu.h"
michael@0 41 #include "common/logging.h"
michael@0 42
michael@0 43 namespace google_breakpad {
michael@0 44
michael@0 45
michael@0 46 StackwalkerPPC::StackwalkerPPC(const SystemInfo* system_info,
michael@0 47 const MDRawContextPPC* 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 if (memory_ && memory_->GetBase() + memory_->GetSize() - 1 > 0xffffffff) {
michael@0 54 // This implementation only covers 32-bit ppc CPUs. The limits of the
michael@0 55 // supplied stack are invalid. Mark memory_ = NULL, which will cause
michael@0 56 // stackwalking to fail.
michael@0 57 BPLOG(ERROR) << "Memory out of range for stackwalking: " <<
michael@0 58 HexString(memory_->GetBase()) << "+" <<
michael@0 59 HexString(memory_->GetSize());
michael@0 60 memory_ = NULL;
michael@0 61 }
michael@0 62 }
michael@0 63
michael@0 64
michael@0 65 StackFrame* StackwalkerPPC::GetContextFrame() {
michael@0 66 if (!context_) {
michael@0 67 BPLOG(ERROR) << "Can't get context frame without context";
michael@0 68 return NULL;
michael@0 69 }
michael@0 70
michael@0 71 StackFramePPC* frame = new StackFramePPC();
michael@0 72
michael@0 73 // The instruction pointer is stored directly in a register, so pull it
michael@0 74 // straight out of the CPU context structure.
michael@0 75 frame->context = *context_;
michael@0 76 frame->context_validity = StackFramePPC::CONTEXT_VALID_ALL;
michael@0 77 frame->trust = StackFrame::FRAME_TRUST_CONTEXT;
michael@0 78 frame->instruction = frame->context.srr0;
michael@0 79
michael@0 80 return frame;
michael@0 81 }
michael@0 82
michael@0 83
michael@0 84 StackFrame* StackwalkerPPC::GetCallerFrame(const CallStack* stack,
michael@0 85 bool stack_scan_allowed) {
michael@0 86 if (!memory_ || !stack) {
michael@0 87 BPLOG(ERROR) << "Can't get caller frame without memory or stack";
michael@0 88 return NULL;
michael@0 89 }
michael@0 90
michael@0 91 // The instruction pointers for previous frames are saved on the stack.
michael@0 92 // The typical ppc calling convention is for the called procedure to store
michael@0 93 // its return address in the calling procedure's stack frame at 8(%r1),
michael@0 94 // and to allocate its own stack frame by decrementing %r1 (the stack
michael@0 95 // pointer) and saving the old value of %r1 at 0(%r1). Because the ppc has
michael@0 96 // no hardware stack, there is no distinction between the stack pointer and
michael@0 97 // frame pointer, and what is typically thought of as the frame pointer on
michael@0 98 // an x86 is usually referred to as the stack pointer on a ppc.
michael@0 99
michael@0 100 StackFramePPC* last_frame = static_cast<StackFramePPC*>(
michael@0 101 stack->frames()->back());
michael@0 102
michael@0 103 // A caller frame must reside higher in memory than its callee frames.
michael@0 104 // Anything else is an error, or an indication that we've reached the
michael@0 105 // end of the stack.
michael@0 106 uint32_t stack_pointer;
michael@0 107 if (!memory_->GetMemoryAtAddress(last_frame->context.gpr[1],
michael@0 108 &stack_pointer) ||
michael@0 109 stack_pointer <= last_frame->context.gpr[1]) {
michael@0 110 return NULL;
michael@0 111 }
michael@0 112
michael@0 113 // Mac OS X/Darwin gives 1 as the return address from the bottom-most
michael@0 114 // frame in a stack (a thread's entry point). I haven't found any
michael@0 115 // documentation on this, but 0 or 1 would be bogus return addresses,
michael@0 116 // so check for them here and return false (end of stack) when they're
michael@0 117 // hit to avoid having a phantom frame.
michael@0 118 uint32_t instruction;
michael@0 119 if (!memory_->GetMemoryAtAddress(stack_pointer + 8, &instruction) ||
michael@0 120 instruction <= 1) {
michael@0 121 return NULL;
michael@0 122 }
michael@0 123
michael@0 124 StackFramePPC* frame = new StackFramePPC();
michael@0 125
michael@0 126 frame->context = last_frame->context;
michael@0 127 frame->context.srr0 = instruction;
michael@0 128 frame->context.gpr[1] = stack_pointer;
michael@0 129 frame->context_validity = StackFramePPC::CONTEXT_VALID_SRR0 |
michael@0 130 StackFramePPC::CONTEXT_VALID_GPR1;
michael@0 131 frame->trust = StackFrame::FRAME_TRUST_FP;
michael@0 132
michael@0 133 // frame->context.srr0 is the return address, which is one instruction
michael@0 134 // past the branch that caused us to arrive at the callee. Set
michael@0 135 // frame_ppc->instruction to four less than that. Since all ppc
michael@0 136 // instructions are 4 bytes wide, this is the address of the branch
michael@0 137 // instruction. This allows source line information to match up with the
michael@0 138 // line that contains a function call. Callers that require the exact
michael@0 139 // return address value may access the context.srr0 field of StackFramePPC.
michael@0 140 frame->instruction = frame->context.srr0 - 4;
michael@0 141
michael@0 142 return frame;
michael@0 143 }
michael@0 144
michael@0 145
michael@0 146 } // namespace google_breakpad

mercurial