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