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 if (GetStackFramePC(fp) < 32768) | |
Mark Mentovai
2017/02/15 21:05:57
You could go even bigger. On x86_64, you’ll genera
erikchen
2017/02/15 21:52:45
Also, this is run on all plaforms.
Wez
2017/02/15 22:38:22
Maybe use a kConstant here, so we can define it to
erikchen
2017/02/15 22:52:24
Done.
| |
116 return false; | |
117 | |
114 if (stack_end) { | 118 if (stack_end) { |
115 // Both fp[0] and fp[1] must be within the stack. | 119 // Both fp[0] and fp[1] must be within the stack. |
116 if (fp > stack_end - 2 * sizeof(uintptr_t)) return false; | 120 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; | |
120 } | 121 } |
121 | 122 |
122 return true; | 123 return true; |
123 }; | 124 }; |
124 | 125 |
125 // ScanStackForNextFrame() scans the stack for a valid frame to allow unwinding | 126 // ScanStackForNextFrame() scans the stack for a valid frame to allow unwinding |
126 // past system libraries. Only supported on Linux where system libraries are | 127 // past system libraries. Only supported on Linux where system libraries are |
127 // usually in the middle of the trace: | 128 // usually in the middle of the trace: |
128 // | 129 // |
129 // TraceStackFramePointers | 130 // TraceStackFramePointers |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 ScopedStackFrameLinker::~ScopedStackFrameLinker() { | 265 ScopedStackFrameLinker::~ScopedStackFrameLinker() { |
265 void* previous_parent_fp = LinkStackFrames(fp_, original_parent_fp_); | 266 void* previous_parent_fp = LinkStackFrames(fp_, original_parent_fp_); |
266 CHECK_EQ(parent_fp_, previous_parent_fp) | 267 CHECK_EQ(parent_fp_, previous_parent_fp) |
267 << "Stack frame's parent pointer has changed!"; | 268 << "Stack frame's parent pointer has changed!"; |
268 } | 269 } |
269 | 270 |
270 #endif // HAVE_TRACE_STACK_FRAME_POINTERS | 271 #endif // HAVE_TRACE_STACK_FRAME_POINTERS |
271 | 272 |
272 } // namespace debug | 273 } // namespace debug |
273 } // namespace base | 274 } // namespace base |
OLD | NEW |