OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/debug/stack_trace.h" | 5 #include "base/debug/stack_trace.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // With the stack growing downwards, older stack frame must be | 104 // With the stack growing downwards, older stack frame must be |
105 // at a greater address that the current one. | 105 // at a greater address that the current one. |
106 if (fp <= prev_fp) return false; | 106 if (fp <= prev_fp) return false; |
107 | 107 |
108 // Assume huge stack frames are bogus. | 108 // Assume huge stack frames are bogus. |
109 if (fp - prev_fp > 100000) return false; | 109 if (fp - prev_fp > 100000) return false; |
110 | 110 |
111 // Check alignment. | 111 // Check alignment. |
112 if (fp & (sizeof(uintptr_t) - 1)) return false; | 112 if (fp & (sizeof(uintptr_t) - 1)) return false; |
113 | 113 |
114 // A PC that is too small means we've gone off the end of the stack. | |
115 const uintptr_t kMinimumReasonablePC = 32768; | |
116 if (GetStackFramePC(fp) < kMinimumReasonablePC) | |
117 return false; | |
118 | |
119 if (stack_end) { | 114 if (stack_end) { |
120 // Both fp[0] and fp[1] must be within the stack. | 115 // Both fp[0] and fp[1] must be within the stack. |
121 if (fp > stack_end - 2 * sizeof(uintptr_t)) return false; | 116 if (fp > stack_end - 2 * sizeof(uintptr_t)) return false; |
| 117 |
| 118 // Additional check to filter out false positives. |
| 119 if (GetStackFramePC(fp) < 32768) return false; |
122 } | 120 } |
123 | 121 |
124 return true; | 122 return true; |
125 }; | 123 }; |
126 | 124 |
127 // ScanStackForNextFrame() scans the stack for a valid frame to allow unwinding | 125 // ScanStackForNextFrame() scans the stack for a valid frame to allow unwinding |
128 // past system libraries. Only supported on Linux where system libraries are | 126 // past system libraries. Only supported on Linux where system libraries are |
129 // usually in the middle of the trace: | 127 // usually in the middle of the trace: |
130 // | 128 // |
131 // TraceStackFramePointers | 129 // TraceStackFramePointers |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 ScopedStackFrameLinker::~ScopedStackFrameLinker() { | 264 ScopedStackFrameLinker::~ScopedStackFrameLinker() { |
267 void* previous_parent_fp = LinkStackFrames(fp_, original_parent_fp_); | 265 void* previous_parent_fp = LinkStackFrames(fp_, original_parent_fp_); |
268 CHECK_EQ(parent_fp_, previous_parent_fp) | 266 CHECK_EQ(parent_fp_, previous_parent_fp) |
269 << "Stack frame's parent pointer has changed!"; | 267 << "Stack frame's parent pointer has changed!"; |
270 } | 268 } |
271 | 269 |
272 #endif // HAVE_TRACE_STACK_FRAME_POINTERS | 270 #endif // HAVE_TRACE_STACK_FRAME_POINTERS |
273 | 271 |
274 } // namespace debug | 272 } // namespace debug |
275 } // namespace base | 273 } // namespace base |
OLD | NEW |