OLD | NEW |
| (Empty) |
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 // stack_frame_cpu.h: CPU-specific StackFrame extensions. | |
33 // | |
34 // These types extend the StackFrame structure to carry CPU-specific register | |
35 // state. They are defined in this header instead of stack_frame.h to | |
36 // avoid the need to include minidump_format.h when only the generic | |
37 // StackFrame type is needed. | |
38 // | |
39 // Author: Mark Mentovai | |
40 | |
41 #ifndef GOOGLE_BREAKPAD_PROCESSOR_STACK_FRAME_CPU_H__ | |
42 #define GOOGLE_BREAKPAD_PROCESSOR_STACK_FRAME_CPU_H__ | |
43 | |
44 #include "google_breakpad/common/minidump_format.h" | |
45 #include "google_breakpad/processor/stack_frame.h" | |
46 | |
47 namespace google_breakpad { | |
48 | |
49 struct WindowsFrameInfo; | |
50 struct CFIFrameInfo; | |
51 | |
52 struct StackFrameX86 : public StackFrame { | |
53 // ContextValidity has one entry for each relevant hardware pointer | |
54 // register (%eip and %esp) and one entry for each general-purpose | |
55 // register. It's worthwhile having validity flags for caller-saves | |
56 // registers: they are valid in the youngest frame, and such a frame | |
57 // might save a callee-saves register in a caller-saves register, but | |
58 // SimpleCFIWalker won't touch registers unless they're marked as valid. | |
59 enum ContextValidity { | |
60 CONTEXT_VALID_NONE = 0, | |
61 CONTEXT_VALID_EIP = 1 << 0, | |
62 CONTEXT_VALID_ESP = 1 << 1, | |
63 CONTEXT_VALID_EBP = 1 << 2, | |
64 CONTEXT_VALID_EAX = 1 << 3, | |
65 CONTEXT_VALID_EBX = 1 << 4, | |
66 CONTEXT_VALID_ECX = 1 << 5, | |
67 CONTEXT_VALID_EDX = 1 << 6, | |
68 CONTEXT_VALID_ESI = 1 << 7, | |
69 CONTEXT_VALID_EDI = 1 << 8, | |
70 CONTEXT_VALID_ALL = -1 | |
71 }; | |
72 | |
73 // Indicates how well we trust the instruction pointer we derived | |
74 // during stack walking. Since the stack walker can resort to | |
75 // stack scanning, we can wind up with dubious frames. | |
76 // In rough order of "trust metric". | |
77 enum FrameTrust { | |
78 FRAME_TRUST_NONE, // Unknown | |
79 FRAME_TRUST_SCAN, // Scanned the stack, found this | |
80 FRAME_TRUST_CFI_SCAN, // Scanned the stack using call frame info, found this | |
81 FRAME_TRUST_FP, // Derived from frame pointer | |
82 FRAME_TRUST_CFI, // Derived from call frame info | |
83 FRAME_TRUST_CONTEXT // Given as instruction pointer in a context | |
84 }; | |
85 | |
86 StackFrameX86() | |
87 : context(), | |
88 context_validity(CONTEXT_VALID_NONE), | |
89 trust(FRAME_TRUST_NONE), | |
90 windows_frame_info(NULL), | |
91 cfi_frame_info(NULL) {} | |
92 ~StackFrameX86(); | |
93 | |
94 // Register state. This is only fully valid for the topmost frame in a | |
95 // stack. In other frames, the values of nonvolatile registers may be | |
96 // present, given sufficient debugging information. Refer to | |
97 // context_validity. | |
98 MDRawContextX86 context; | |
99 | |
100 // context_validity is actually ContextValidity, but int is used because | |
101 // the OR operator doesn't work well with enumerated types. This indicates | |
102 // which fields in context are valid. | |
103 int context_validity; | |
104 | |
105 // Amount of trust the stack walker has in the instruction pointer | |
106 // of this frame. | |
107 FrameTrust trust; | |
108 | |
109 // Any stack walking information we found describing this.instruction. | |
110 // These may be NULL if there is no such information for that address. | |
111 WindowsFrameInfo *windows_frame_info; | |
112 CFIFrameInfo *cfi_frame_info; | |
113 }; | |
114 | |
115 struct StackFramePPC : public StackFrame { | |
116 // ContextValidity should eventually contain entries for the validity of | |
117 // other nonvolatile (callee-save) registers as in | |
118 // StackFrameX86::ContextValidity, but the ppc stackwalker doesn't currently | |
119 // locate registers other than the ones listed here. | |
120 enum ContextValidity { | |
121 CONTEXT_VALID_NONE = 0, | |
122 CONTEXT_VALID_SRR0 = 1 << 0, | |
123 CONTEXT_VALID_GPR1 = 1 << 1, | |
124 CONTEXT_VALID_ALL = -1 | |
125 }; | |
126 | |
127 StackFramePPC() : context(), context_validity(CONTEXT_VALID_NONE) {} | |
128 | |
129 // Register state. This is only fully valid for the topmost frame in a | |
130 // stack. In other frames, the values of nonvolatile registers may be | |
131 // present, given sufficient debugging information. Refer to | |
132 // context_validity. | |
133 MDRawContextPPC context; | |
134 | |
135 // context_validity is actually ContextValidity, but int is used because | |
136 // the OR operator doesn't work well with enumerated types. This indicates | |
137 // which fields in context are valid. | |
138 int context_validity; | |
139 }; | |
140 | |
141 struct StackFrameAMD64 : public StackFrame { | |
142 // ContextValidity has one entry for each register that we might be able | |
143 // to recover. | |
144 enum ContextValidity { | |
145 CONTEXT_VALID_NONE = 0, | |
146 CONTEXT_VALID_RAX = 1 << 0, | |
147 CONTEXT_VALID_RDX = 1 << 1, | |
148 CONTEXT_VALID_RCX = 1 << 2, | |
149 CONTEXT_VALID_RBX = 1 << 3, | |
150 CONTEXT_VALID_RSI = 1 << 4, | |
151 CONTEXT_VALID_RDI = 1 << 5, | |
152 CONTEXT_VALID_RBP = 1 << 6, | |
153 CONTEXT_VALID_RSP = 1 << 7, | |
154 CONTEXT_VALID_R8 = 1 << 8, | |
155 CONTEXT_VALID_R9 = 1 << 9, | |
156 CONTEXT_VALID_R10 = 1 << 10, | |
157 CONTEXT_VALID_R11 = 1 << 11, | |
158 CONTEXT_VALID_R12 = 1 << 12, | |
159 CONTEXT_VALID_R13 = 1 << 13, | |
160 CONTEXT_VALID_R14 = 1 << 14, | |
161 CONTEXT_VALID_R15 = 1 << 15, | |
162 CONTEXT_VALID_RIP = 1 << 16, | |
163 CONTEXT_VALID_ALL = -1 | |
164 }; | |
165 | |
166 StackFrameAMD64() : context(), context_validity(CONTEXT_VALID_NONE) {} | |
167 | |
168 // Register state. This is only fully valid for the topmost frame in a | |
169 // stack. In other frames, which registers are present depends on what | |
170 // debugging information we had available. Refer to context_validity. | |
171 MDRawContextAMD64 context; | |
172 | |
173 // For each register in context whose value has been recovered, we set | |
174 // the corresponding CONTEXT_VALID_ bit in context_validity. | |
175 // | |
176 // context_validity's type should actually be ContextValidity, but | |
177 // we use int instead because the bitwise inclusive or operator | |
178 // yields an int when applied to enum values, and C++ doesn't | |
179 // silently convert from ints to enums. | |
180 int context_validity; | |
181 }; | |
182 | |
183 struct StackFrameSPARC : public StackFrame { | |
184 // to be confirmed | |
185 enum ContextValidity { | |
186 CONTEXT_VALID_NONE = 0, | |
187 CONTEXT_VALID_PC = 1 << 0, | |
188 CONTEXT_VALID_SP = 1 << 1, | |
189 CONTEXT_VALID_FP = 1 << 2, | |
190 CONTEXT_VALID_ALL = -1 | |
191 }; | |
192 | |
193 StackFrameSPARC() : context(), context_validity(CONTEXT_VALID_NONE) {} | |
194 | |
195 // Register state. This is only fully valid for the topmost frame in a | |
196 // stack. In other frames, the values of nonvolatile registers may be | |
197 // present, given sufficient debugging information. Refer to | |
198 // context_validity. | |
199 MDRawContextSPARC context; | |
200 | |
201 // context_validity is actually ContextValidity, but int is used because | |
202 // the OR operator doesn't work well with enumerated types. This indicates | |
203 // which fields in context are valid. | |
204 int context_validity; | |
205 }; | |
206 | |
207 struct StackFrameARM : public StackFrame { | |
208 // A flag for each register we might know. | |
209 enum ContextValidity { | |
210 CONTEXT_VALID_NONE = 0, | |
211 CONTEXT_VALID_R0 = 1 << 0, | |
212 CONTEXT_VALID_R1 = 1 << 1, | |
213 CONTEXT_VALID_R2 = 1 << 2, | |
214 CONTEXT_VALID_R3 = 1 << 3, | |
215 CONTEXT_VALID_R4 = 1 << 4, | |
216 CONTEXT_VALID_R5 = 1 << 5, | |
217 CONTEXT_VALID_R6 = 1 << 6, | |
218 CONTEXT_VALID_R7 = 1 << 7, | |
219 CONTEXT_VALID_R8 = 1 << 8, | |
220 CONTEXT_VALID_R9 = 1 << 9, | |
221 CONTEXT_VALID_R10 = 1 << 10, | |
222 CONTEXT_VALID_R11 = 1 << 11, | |
223 CONTEXT_VALID_R12 = 1 << 12, | |
224 CONTEXT_VALID_R13 = 1 << 13, | |
225 CONTEXT_VALID_R14 = 1 << 14, | |
226 CONTEXT_VALID_R15 = 1 << 15, | |
227 CONTEXT_VALID_ALL = ~CONTEXT_VALID_NONE, | |
228 | |
229 // Aliases for registers with dedicated or conventional roles. | |
230 CONTEXT_VALID_FP = CONTEXT_VALID_R11, | |
231 CONTEXT_VALID_SP = CONTEXT_VALID_R13, | |
232 CONTEXT_VALID_LR = CONTEXT_VALID_R14, | |
233 CONTEXT_VALID_PC = CONTEXT_VALID_R15 | |
234 }; | |
235 | |
236 StackFrameARM() : context(), context_validity(CONTEXT_VALID_NONE) {} | |
237 | |
238 // Return the ContextValidity flag for register rN. | |
239 static ContextValidity RegisterValidFlag(int n) { | |
240 return ContextValidity(1 << n); | |
241 } | |
242 | |
243 // Register state. This is only fully valid for the topmost frame in a | |
244 // stack. In other frames, the values of nonvolatile registers may be | |
245 // present, given sufficient debugging information. Refer to | |
246 // context_validity. | |
247 MDRawContextARM context; | |
248 | |
249 // For each register in context whose value has been recovered, we set | |
250 // the corresponding CONTEXT_VALID_ bit in context_validity. | |
251 // | |
252 // context_validity's type should actually be ContextValidity, but | |
253 // we use int instead because the bitwise inclusive or operator | |
254 // yields an int when applied to enum values, and C++ doesn't | |
255 // silently convert from ints to enums. | |
256 int context_validity; | |
257 }; | |
258 | |
259 } // namespace google_breakpad | |
260 | |
261 #endif // GOOGLE_BREAKPAD_PROCESSOR_STACK_FRAME_CPU_H__ | |
OLD | NEW |