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