1e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// Copyright (c) 2013 Google Inc. 2e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// All rights reserved. 3e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// 4e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// Redistribution and use in source and binary forms, with or without 5e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// modification, are permitted provided that the following conditions are 6e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// met: 7e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// 8e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// * Redistributions of source code must retain the above copyright 9e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// notice, this list of conditions and the following disclaimer. 10e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// * Redistributions in binary form must reproduce the above 11e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// copyright notice, this list of conditions and the following disclaimer 12e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// in the documentation and/or other materials provided with the 13e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// distribution. 14e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// * Neither the name of Google Inc. nor the names of its 15e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// contributors may be used to endorse or promote products derived from 16e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// this software without specific prior written permission. 17e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// 18e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org 30e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// stackwalker_address_list.cc: a pseudo stack walker. 31e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// 32e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// See stackwalker_address_list.h for documentation. 33e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// 34e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org// Author: Chris Hamilton <chrisha@chromium.org> 35e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org 36e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org#include <assert.h> 37e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org 38e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org#include <vector> 39e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org 40e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org#include "google_breakpad/processor/call_stack.h" 41e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org#include "google_breakpad/processor/memory_region.h" 42e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org#include "google_breakpad/processor/source_line_resolver_interface.h" 43e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org#include "google_breakpad/processor/stack_frame.h" 44e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org#include "processor/logging.h" 45e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org#include "processor/stackwalker_address_list.h" 46e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org 47e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.orgnamespace google_breakpad { 48e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org 49e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.orgStackwalkerAddressList::StackwalkerAddressList( 50e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org const uint64_t* frames, 51e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org size_t frame_count, 52e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org const CodeModules* modules, 53e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org StackFrameSymbolizer* frame_symbolizer) 54e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org : Stackwalker(NULL, NULL, modules, frame_symbolizer), 55e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org frames_(frames), 56e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org frame_count_(frame_count) { 57e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org assert(frames); 58e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org assert(frame_symbolizer); 59e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org} 60e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org 61e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.orgStackFrame* StackwalkerAddressList::GetContextFrame() { 62e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org if (frame_count_ == 0) 63e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org return NULL; 64e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org 65e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org StackFrame* frame = new StackFrame(); 66e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org frame->instruction = frames_[0]; 678d58ea41134906c4e3f3f6ed813720f9d8e5e065chrisha@chromium.org frame->trust = StackFrame::FRAME_TRUST_PREWALKED; 68e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org return frame; 69e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org} 70e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org 71e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.orgStackFrame* StackwalkerAddressList::GetCallerFrame(const CallStack* stack, 72e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org bool stack_scan_allowed) { 73e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org if (!stack) { 74e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org BPLOG(ERROR) << "Can't get caller frame without stack"; 75e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org return NULL; 76e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org } 77e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org 78e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org size_t frame_index = stack->frames()->size(); 79e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org 80e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org // There are no more frames to fetch. 81e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org if (frame_index >= frame_count_) 82e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org return NULL; 83e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org 84e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org // All frames have the highest level of trust because they were 85e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org // explicitly provided. 86e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org StackFrame* frame = new StackFrame(); 87e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org frame->instruction = frames_[frame_index]; 885a82db4773c983cfa2adc0d7f9682ce5717d523echrisha@chromium.org frame->trust = StackFrame::FRAME_TRUST_PREWALKED; 89e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org return frame; 90e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org} 91e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org 92e6758b14481b3ee1eddc4d51725375c7fc7cf6bfchrisha@chromium.org} // namespace google_breakpad 93