|
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 // Scan the stack for plausible return addresses. The caller takes ownership |
|
82 // of the returned frame. Return NULL on failure. |
|
83 StackFrameAMD64* GetCallerByStackScan(const vector<StackFrame*> &frames); |
|
84 |
|
85 // Stores the CPU context corresponding to the innermost stack frame to |
|
86 // be returned by GetContextFrame. |
|
87 const MDRawContextAMD64* context_; |
|
88 |
|
89 // Our register map, for cfi_walker_. |
|
90 static const CFIWalker::RegisterSet cfi_register_map_[]; |
|
91 |
|
92 // Our CFI frame walker. |
|
93 const CFIWalker cfi_walker_; |
|
94 }; |
|
95 |
|
96 |
|
97 } // namespace google_breakpad |
|
98 |
|
99 |
|
100 #endif // PROCESSOR_STACKWALKER_AMD64_H__ |