OLD | NEW |
1 // Copyright (c) 2007, Google Inc. | 1 // Copyright (c) 2007, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 25 matching lines...) Expand all Loading... |
36 // http://www.linux-foundation.org/spec/ELF/ppc64/PPC-elf64abi-1.9.html#STACK | 36 // http://www.linux-foundation.org/spec/ELF/ppc64/PPC-elf64abi-1.9.html#STACK |
37 // Linux has similar code: http://patchwork.ozlabs.org/linuxppc/patch?id=8882 | 37 // Linux has similar code: http://patchwork.ozlabs.org/linuxppc/patch?id=8882 |
38 | 38 |
39 #ifndef BASE_STACKTRACE_POWERPC_INL_H_ | 39 #ifndef BASE_STACKTRACE_POWERPC_INL_H_ |
40 #define BASE_STACKTRACE_POWERPC_INL_H_ | 40 #define BASE_STACKTRACE_POWERPC_INL_H_ |
41 // Note: this file is included into stacktrace.cc more than once. | 41 // Note: this file is included into stacktrace.cc more than once. |
42 // Anything that should only be defined once should be here: | 42 // Anything that should only be defined once should be here: |
43 | 43 |
44 #include <stdint.h> // for uintptr_t | 44 #include <stdint.h> // for uintptr_t |
45 #include <stdlib.h> // for NULL | 45 #include <stdlib.h> // for NULL |
46 #include <gperftools/stacktrace.h> | 46 #include <google/stacktrace.h> |
47 | 47 |
48 // Given a pointer to a stack frame, locate and return the calling | 48 // Given a pointer to a stack frame, locate and return the calling |
49 // stackframe, or return NULL if no stackframe can be found. Perform sanity | 49 // stackframe, or return NULL if no stackframe can be found. Perform sanity |
50 // checks (the strictness of which is controlled by the boolean parameter | 50 // checks (the strictness of which is controlled by the boolean parameter |
51 // "STRICT_UNWINDING") to reduce the chance that a bad pointer is returned. | 51 // "STRICT_UNWINDING") to reduce the chance that a bad pointer is returned. |
52 template<bool STRICT_UNWINDING> | 52 template<bool STRICT_UNWINDING> |
53 static void **NextStackFrame(void **old_sp) { | 53 static void **NextStackFrame(void **old_sp) { |
54 void **new_sp = (void **) *old_sp; | 54 void **new_sp = (void **) *old_sp; |
55 | 55 |
56 // Check that the transition from frame pointer old_sp to frame | 56 // Check that the transition from frame pointer old_sp to frame |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // we did, the list of stack frames wouldn't properly match up with | 119 // we did, the list of stack frames wouldn't properly match up with |
120 // the list of return addresses. Note this means the top pc entry | 120 // the list of return addresses. Note this means the top pc entry |
121 // is probably bogus for linux/ppc (and other SYSV-ABI systems). | 121 // is probably bogus for linux/ppc (and other SYSV-ABI systems). |
122 #else | 122 #else |
123 // The LR save area is used by the callee, so the top entry is bogus. | 123 // The LR save area is used by the callee, so the top entry is bogus. |
124 skip_count++; | 124 skip_count++; |
125 #endif | 125 #endif |
126 | 126 |
127 int n = 0; | 127 int n = 0; |
128 while (sp && n < max_depth) { | 128 while (sp && n < max_depth) { |
| 129 #if IS_STACK_FRAMES |
129 // The GetStackFrames routine is called when we are in some | 130 // The GetStackFrames routine is called when we are in some |
130 // informational context (the failure signal handler for example). | 131 // informational context (the failure signal handler for example). |
131 // Use the non-strict unwinding rules to produce a stack trace | 132 // Use the non-strict unwinding rules to produce a stack trace |
132 // that is as complete as possible (even if it contains a few | 133 // that is as complete as possible (even if it contains a few bogus |
133 // bogus entries in some rare cases). | 134 // entries in some rare cases). |
134 void **next_sp = NextStackFrame<!IS_STACK_FRAMES>(sp); | 135 void **next_sp = NextStackFrame<false>(sp); |
| 136 #else |
| 137 void **next_sp = NextStackFrame<true>(sp); |
| 138 #endif |
135 | 139 |
136 if (skip_count > 0) { | 140 if (skip_count > 0) { |
137 skip_count--; | 141 skip_count--; |
138 } else { | 142 } else { |
139 // PowerPC has 3 main ABIs, which say where in the stack the | 143 // PowerPC has 3 main ABIs, which say where in the stack the |
140 // Link Register is. For DARWIN and AIX (used by apple and | 144 // Link Register is. For DARWIN and AIX (used by apple and |
141 // linux ppc64), it's in sp[2]. For SYSV (used by linux ppc), | 145 // linux ppc64), it's in sp[2]. For SYSV (used by linux ppc), |
142 // it's in sp[1]. | 146 // it's in sp[1]. |
143 #if defined(_CALL_AIX) || defined(_CALL_DARWIN) | 147 #if defined(_CALL_AIX) || defined(_CALL_DARWIN) |
144 result[n] = *(sp+2); | 148 result[n++] = *(sp+2); |
145 #elif defined(_CALL_SYSV) | 149 #elif defined(_CALL_SYSV) |
146 result[n] = *(sp+1); | 150 result[n++] = *(sp+1); |
147 #elif defined(__APPLE__) || (defined(__linux) && defined(__PPC64__)) | 151 #elif defined(__APPLE__) || (defined(__linux) && defined(__PPC64__)) |
148 // This check is in case the compiler doesn't define _CALL_AIX/etc. | 152 // This check is in case the compiler doesn't define _CALL_AIX/etc. |
149 result[n] = *(sp+2); | 153 result[n++] = *(sp+2); |
150 #elif defined(__linux) | 154 #elif defined(__linux) |
151 // This check is in case the compiler doesn't define _CALL_SYSV. | 155 // This check is in case the compiler doesn't define _CALL_SYSV. |
152 result[n] = *(sp+1); | 156 result[n++] = *(sp+1); |
153 #else | 157 #else |
154 #error Need to specify the PPC ABI for your archiecture. | 158 #error Need to specify the PPC ABI for your archiecture. |
155 #endif | 159 #endif |
156 | 160 |
157 #if IS_STACK_FRAMES | 161 #if IS_STACK_FRAME |
158 if (next_sp > sp) { | 162 if (next_sp > sp) { |
159 sizes[n] = (uintptr_t)next_sp - (uintptr_t)sp; | 163 sizes[n] = (uintptr_t)next_sp - (uintptr_t)sp; |
160 } else { | 164 } else { |
161 // A frame-size of 0 is used to indicate unknown frame size. | 165 // A frame-size of 0 is used to indicate unknown frame size. |
162 sizes[n] = 0; | 166 sizes[n] = 0; |
163 } | 167 } |
164 #endif | 168 #endif |
165 n++; | |
166 } | 169 } |
167 sp = next_sp; | 170 sp = next_sp; |
168 } | 171 } |
169 return n; | 172 return n; |
170 } | 173 } |
OLD | NEW |