stackwalker_x86.h revision 7f1455601db0fe4a44bcc9b38bd5b28bfbd37aba
1// -*- mode: c++ -*-
2
3// Copyright (c) 2006, 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
44#include "google_breakpad/common/breakpad_types.h"
45#include "google_breakpad/common/minidump_format.h"
46#include "google_breakpad/processor/stackwalker.h"
47#include "google_breakpad/processor/stack_frame_cpu.h"
48
49namespace google_breakpad {
50
51class CodeModules;
52
53
54class StackwalkerX86 : public Stackwalker {
55 public:
56  // context is an x86 context object that gives access to x86-specific
57  // register state corresponding to the innermost called frame to be
58  // included in the stack.  The other arguments are passed directly through
59  // to the base Stackwalker constructor.
60  StackwalkerX86(const SystemInfo *system_info,
61                 const MDRawContextX86 *context,
62                 MemoryRegion *memory,
63                 const CodeModules *modules,
64                 SymbolSupplier *supplier,
65                 SourceLineResolverInterface *resolver);
66
67 private:
68  // Implementation of Stackwalker, using x86 context (%ebp, %esp, %eip) and
69  // stack conventions (saved %ebp at [%ebp], saved %eip at 4[%ebp], or
70  // alternate conventions as guided by any WindowsFrameInfo available for the
71  // code in question.).
72  virtual StackFrame *GetContextFrame();
73  virtual StackFrame *GetCallerFrame(const CallStack *stack);
74
75  // Use windows_frame_info (derived from STACK WIN and FUNC records)
76  // to construct the frame that called frames.back(). The caller
77  // takes ownership of the returned frame. Return NULL on failure.
78  StackFrameX86 *GetCallerByWindowsFrameInfo(
79      const vector<StackFrame*> &frames,
80      WindowsFrameInfo *windows_frame_info);
81
82  // Assuming a traditional frame layout --- where the caller's %ebp
83  // has been pushed just after the return address and the callee's
84  // %ebp points to the saved %ebp --- construct the frame that called
85  // frames.back(). The caller takes ownership of the returned frame.
86  // Return NULL on failure.
87  StackFrameX86 *GetCallerByEBPAtBase(const vector<StackFrame*> &frames);
88
89  // Scan the stack starting at location_start, looking for an address
90  // that looks like a valid instruction pointer. Addresses must
91  // 1) be contained in the current stack memory
92  // 2) pass the checks in Stackwalker::InstructionAddressSeemsValid
93  //
94  // Returns true if a valid-looking instruction pointer was found.
95  // When returning true, sets location_found to the address at which
96  // the value was found, and eip_found to the value contained at that
97  // location in memory.
98  bool ScanForReturnAddress(u_int32_t location_start,
99                            u_int32_t *location_found,
100                            u_int32_t *eip_found);
101
102  // Stores the CPU context corresponding to the innermost stack frame to
103  // be returned by GetContextFrame.
104  const MDRawContextX86 *context_;
105};
106
107
108}  // namespace google_breakpad
109
110
111#endif  // PROCESSOR_STACKWALKER_X86_H__
112