Home | History | Annotate | Download | only in processor
      1 // -*- mode: c++ -*-
      2 
      3 // Copyright (c) 2010 Google Inc.
      4 // All rights reserved.
      5 //
      6 // Redistribution and use in source and binary forms, with or without
      7 // modification, are permitted provided that the following conditions are
      8 // met:
      9 //
     10 //     * Redistributions of source code must retain the above copyright
     11 // notice, this list of conditions and the following disclaimer.
     12 //     * Redistributions in binary form must reproduce the above
     13 // copyright notice, this list of conditions and the following disclaimer
     14 // in the documentation and/or other materials provided with the
     15 // distribution.
     16 //     * Neither the name of Google Inc. nor the names of its
     17 // contributors may be used to endorse or promote products derived from
     18 // this software without specific prior written permission.
     19 //
     20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31 
     32 // stackwalker_x86.h: x86-specific stackwalker.
     33 //
     34 // Provides stack frames given x86 register context and a memory region
     35 // corresponding to an x86 stack.
     36 //
     37 // Author: Mark Mentovai
     38 
     39 
     40 #ifndef PROCESSOR_STACKWALKER_X86_H__
     41 #define PROCESSOR_STACKWALKER_X86_H__
     42 
     43 #include <vector>
     44 
     45 #include "google_breakpad/common/breakpad_types.h"
     46 #include "google_breakpad/common/minidump_format.h"
     47 #include "google_breakpad/processor/stackwalker.h"
     48 #include "google_breakpad/processor/stack_frame_cpu.h"
     49 #include "processor/cfi_frame_info.h"
     50 
     51 namespace google_breakpad {
     52 
     53 class CodeModules;
     54 
     55 
     56 class StackwalkerX86 : public Stackwalker {
     57  public:
     58   // context is an x86 context object that gives access to x86-specific
     59   // register state corresponding to the innermost called frame to be
     60   // included in the stack.  The other arguments are passed directly through
     61   // to the base Stackwalker constructor.
     62   StackwalkerX86(const SystemInfo* system_info,
     63                  const MDRawContextX86* context,
     64                  MemoryRegion* memory,
     65                  const CodeModules* modules,
     66                  StackFrameSymbolizer* frame_symbolizer);
     67 
     68  private:
     69   // A STACK CFI-driven frame walker for the X86.
     70   typedef SimpleCFIWalker<uint32_t, MDRawContextX86> CFIWalker;
     71 
     72   // Implementation of Stackwalker, using x86 context (%ebp, %esp, %eip) and
     73   // stack conventions (saved %ebp at [%ebp], saved %eip at 4[%ebp], or
     74   // alternate conventions as guided by any WindowsFrameInfo available for the
     75   // code in question.).
     76   virtual StackFrame* GetContextFrame();
     77   virtual StackFrame* GetCallerFrame(const CallStack* stack,
     78                                      bool stack_scan_allowed);
     79 
     80   // Use windows_frame_info (derived from STACK WIN and FUNC records)
     81   // to construct the frame that called frames.back(). The caller
     82   // takes ownership of the returned frame. Return NULL on failure.
     83   StackFrameX86* GetCallerByWindowsFrameInfo(
     84       const vector<StackFrame*> &frames,
     85       WindowsFrameInfo* windows_frame_info,
     86       bool stack_scan_allowed);
     87 
     88   // Use cfi_frame_info (derived from STACK CFI records) to construct
     89   // the frame that called frames.back(). The caller takes ownership
     90   // of the returned frame. Return NULL on failure.
     91   StackFrameX86* GetCallerByCFIFrameInfo(const vector<StackFrame*> &frames,
     92                                          CFIFrameInfo* cfi_frame_info);
     93 
     94   // Assuming a traditional frame layout --- where the caller's %ebp
     95   // has been pushed just after the return address and the callee's
     96   // %ebp points to the saved %ebp --- construct the frame that called
     97   // frames.back(). The caller takes ownership of the returned frame.
     98   // Return NULL on failure.
     99   StackFrameX86* GetCallerByEBPAtBase(const vector<StackFrame*> &frames,
    100                                       bool stack_scan_allowed);
    101 
    102   // Stores the CPU context corresponding to the innermost stack frame to
    103   // be returned by GetContextFrame.
    104   const MDRawContextX86* context_;
    105 
    106   // Our register map, for cfi_walker_.
    107   static const CFIWalker::RegisterSet cfi_register_map_[];
    108 
    109   // Our CFI frame walker.
    110   const CFIWalker cfi_walker_;
    111 };
    112 
    113 
    114 }  // namespace google_breakpad
    115 
    116 
    117 #endif  // PROCESSOR_STACKWALKER_X86_H__
    118