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 #ifndef BASE_DEBUG_STACK_TRACE_H_ | 5 #ifndef BASE_DEBUG_STACK_TRACE_H_ |
6 #define BASE_DEBUG_STACK_TRACE_H_ | 6 #define BASE_DEBUG_STACK_TRACE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <iosfwd> | 10 #include <iosfwd> |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 // doesn't give much more information. | 95 // doesn't give much more information. |
96 static const int kMaxTraces = 62; | 96 static const int kMaxTraces = 62; |
97 | 97 |
98 void* trace_[kMaxTraces]; | 98 void* trace_[kMaxTraces]; |
99 | 99 |
100 // The number of valid frames in |trace_|. | 100 // The number of valid frames in |trace_|. |
101 size_t count_; | 101 size_t count_; |
102 }; | 102 }; |
103 | 103 |
104 #if HAVE_TRACE_STACK_FRAME_POINTERS | 104 #if HAVE_TRACE_STACK_FRAME_POINTERS |
105 | |
106 // Used by TraceStackFramePointers() to store info about the stack. | |
107 struct BASE_EXPORT PerThreadStackInfo { | |
Primiano Tucci (use gerrit)
2016/05/31 16:13:07
maybe s/PerThreadStackInfo/ThreadStackLimits/
Dmitry Skiba
2016/05/31 21:52:18
Acknowledged.
| |
108 PerThreadStackInfo(); | |
109 uintptr_t start_address; | |
110 bool start_address_final; | |
111 }; | |
112 | |
105 // Traces the stack by using frame pointers. This function is faster but less | 113 // Traces the stack by using frame pointers. This function is faster but less |
106 // reliable than StackTrace. It should work for debug and profiling builds, | 114 // reliable than StackTrace. It should work for debug and profiling builds, |
107 // but not for release builds (although there are some exceptions). | 115 // but not for release builds (although there are some exceptions). |
108 // | 116 // |
109 // Writes at most |max_depth| frames (instruction pointers) into |out_trace| | 117 // Writes at most |max_depth| frames (instruction pointers) into |out_trace| |
110 // after skipping |skip_initial| frames. Note that the function itself is not | 118 // after skipping |skip_initial| frames. Note that the function itself is not |
111 // added to the trace so |skip_initial| should be 0 in most cases. | 119 // added to the trace so |skip_initial| should be 0 in most cases. |
112 // Returns number of frames written. | 120 // Returns number of frames written. |
113 BASE_EXPORT size_t TraceStackFramePointers(const void** out_trace, | 121 // |
114 size_t max_depth, | 122 // Note on |stack_info|. By default the function relies on heuristics to check |
Primiano Tucci (use gerrit)
2016/05/31 16:13:07
IMHO this comment is a bit too apologetic. I'd jus
Dmitry Skiba
2016/05/31 21:52:18
Hmm, I don't see it that way. I think it explains
| |
115 size_t skip_initial); | 123 // whether a stack pointer is within the stack before dereferencing it. That |
124 // works, but is not very reliable. Proper way to check that is to ask the OS | |
125 // for the stack info, but that is costly thing to do on each call. | |
126 // This is what |stack_info| is for - it provides a place where function | |
127 // caches info about the stack. Put it in your per-thread data structure, pass | |
128 // into the function, and voila - stack pointers are properly checked without | |
129 // any runtime overhead. | |
130 BASE_EXPORT size_t TraceStackFramePointers( | |
131 const void** out_trace, | |
132 size_t max_depth, | |
133 size_t skip_initial, | |
134 PerThreadStackInfo* stack_info = nullptr); | |
135 | |
116 #endif // HAVE_TRACE_STACK_FRAME_POINTERS | 136 #endif // HAVE_TRACE_STACK_FRAME_POINTERS |
117 | 137 |
118 namespace internal { | 138 namespace internal { |
119 | 139 |
120 #if defined(OS_POSIX) && !defined(OS_ANDROID) | 140 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
121 // POSIX doesn't define any async-signal safe function for converting | 141 // POSIX doesn't define any async-signal safe function for converting |
122 // an integer to ASCII. We'll have to define our own version. | 142 // an integer to ASCII. We'll have to define our own version. |
123 // itoa_r() converts a (signed) integer to ASCII. It returns "buf", if the | 143 // itoa_r() converts a (signed) integer to ASCII. It returns "buf", if the |
124 // conversion was successful or NULL otherwise. It never writes more than "sz" | 144 // conversion was successful or NULL otherwise. It never writes more than "sz" |
125 // bytes. Output will be truncated as needed, and a NUL character is always | 145 // bytes. Output will be truncated as needed, and a NUL character is always |
126 // appended. | 146 // appended. |
127 BASE_EXPORT char *itoa_r(intptr_t i, | 147 BASE_EXPORT char *itoa_r(intptr_t i, |
128 char *buf, | 148 char *buf, |
129 size_t sz, | 149 size_t sz, |
130 int base, | 150 int base, |
131 size_t padding); | 151 size_t padding); |
132 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) | 152 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) |
133 | 153 |
134 } // namespace internal | 154 } // namespace internal |
135 | 155 |
136 } // namespace debug | 156 } // namespace debug |
137 } // namespace base | 157 } // namespace base |
138 | 158 |
139 #endif // BASE_DEBUG_STACK_TRACE_H_ | 159 #endif // BASE_DEBUG_STACK_TRACE_H_ |
OLD | NEW |