Index: base/debug/stack_trace.h |
diff --git a/base/debug/stack_trace.h b/base/debug/stack_trace.h |
index 23e7b5164b63472409a92e992c5c1095dfa48d26..749b5ee4785cccb0fc09b89f1cfca8bf16b7c55f 100644 |
--- a/base/debug/stack_trace.h |
+++ b/base/debug/stack_trace.h |
@@ -102,6 +102,14 @@ class BASE_EXPORT StackTrace { |
}; |
#if HAVE_TRACE_STACK_FRAME_POINTERS |
+ |
+// Used by TraceStackFramePointers() to store info about the stack. |
+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.
|
+ PerThreadStackInfo(); |
+ uintptr_t start_address; |
+ bool start_address_final; |
+}; |
+ |
// Traces the stack by using frame pointers. This function is faster but less |
// reliable than StackTrace. It should work for debug and profiling builds, |
// but not for release builds (although there are some exceptions). |
@@ -110,9 +118,21 @@ class BASE_EXPORT StackTrace { |
// after skipping |skip_initial| frames. Note that the function itself is not |
// added to the trace so |skip_initial| should be 0 in most cases. |
// Returns number of frames written. |
-BASE_EXPORT size_t TraceStackFramePointers(const void** out_trace, |
- size_t max_depth, |
- size_t skip_initial); |
+// |
+// 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
|
+// whether a stack pointer is within the stack before dereferencing it. That |
+// works, but is not very reliable. Proper way to check that is to ask the OS |
+// for the stack info, but that is costly thing to do on each call. |
+// This is what |stack_info| is for - it provides a place where function |
+// caches info about the stack. Put it in your per-thread data structure, pass |
+// into the function, and voila - stack pointers are properly checked without |
+// any runtime overhead. |
+BASE_EXPORT size_t TraceStackFramePointers( |
+ const void** out_trace, |
+ size_t max_depth, |
+ size_t skip_initial, |
+ PerThreadStackInfo* stack_info = nullptr); |
+ |
#endif // HAVE_TRACE_STACK_FRAME_POINTERS |
namespace internal { |