Index: third_party/tcmalloc/chromium/src/stacktrace_android-inl.h |
diff --git a/third_party/tcmalloc/vendor/src/stacktrace_generic-inl.h b/third_party/tcmalloc/chromium/src/stacktrace_android-inl.h |
similarity index 61% |
copy from third_party/tcmalloc/vendor/src/stacktrace_generic-inl.h |
copy to third_party/tcmalloc/chromium/src/stacktrace_android-inl.h |
index 5a526e228a1164853c1c327f9ce72e67ddb6a787..aedcc268e310d872148c05bba9b606bf96a25466 100644 |
--- a/third_party/tcmalloc/vendor/src/stacktrace_generic-inl.h |
+++ b/third_party/tcmalloc/chromium/src/stacktrace_android-inl.h |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2005, Google Inc. |
+// Copyright (c) 2013, Google Inc. |
// All rights reserved. |
// |
// Redistribution and use in source and binary forms, with or without |
@@ -28,22 +28,60 @@ |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
// --- |
-// Author: Sanjay Ghemawat |
+// Author: Marcus Bulach |
+// This is inspired by Doug Kwan's ARM's stacktrace code. |
// |
-// Portable implementation - just use glibc |
-// |
-// Note: The glibc implementation may cause a call to malloc. |
-// This can cause a deadlock in HeapProfiler. |
-#ifndef BASE_STACKTRACE_GENERIC_INL_H_ |
-#define BASE_STACKTRACE_GENERIC_INL_H_ |
+#ifndef BASE_STACKTRACE_ANDROID_INL_H_ |
+#define BASE_STACKTRACE_ANDROID_INL_H_ |
// Note: this file is included into stacktrace.cc more than once. |
// Anything that should only be defined once should be here: |
-#include <execinfo.h> |
-#include <string.h> |
-#include "gperftools/stacktrace.h" |
-#endif // BASE_STACKTRACE_GENERIC_INL_H_ |
+#include <stdint.h> // for uintptr_t |
+#include <unwind.h> |
Dai Mikurube (NOT FULLTIME)
2013/05/03 11:02:35
Import comments mentioning http://crbug.com/236855
bulach
2013/05/07 14:55:51
Done.
|
+ |
+typedef _Unwind_Context __unwind_context; |
+ |
+struct stack_crawl_state_t { |
+ uintptr_t* frames; |
+ size_t frame_count; |
+ int max_depth; |
+ int skip_count; |
+ bool have_skipped_self; |
+ |
+ stack_crawl_state_t(uintptr_t* frames, int max_depth, int skip_count) |
+ : frames(frames), |
+ frame_count(0), |
+ max_depth(max_depth), |
+ skip_count(skip_count), |
+ have_skipped_self(false) { |
+ } |
+}; |
+ |
+static _Unwind_Reason_Code tracer(__unwind_context* context, void* arg) { |
+ stack_crawl_state_t* state = static_cast<stack_crawl_state_t*>(arg); |
+ |
+ uintptr_t ip = _Unwind_GetIP(context); |
Dai Mikurube (NOT FULLTIME)
2013/05/03 11:02:35
Need to import the hack for Clang. (See the lates
bulach
2013/05/07 14:55:51
Done.
|
+ |
+ // The first stack frame is this function itself. Skip it. |
+ if (ip != 0 && !state->have_skipped_self) { |
+ state->have_skipped_self = true; |
+ return _URC_NO_REASON; |
+ } |
+ |
+ if (state->skip_count) { |
+ --state->skip_count; |
+ return _URC_NO_REASON; |
+ } |
+ |
+ state->frames[state->frame_count++] = ip; |
+ if (state->frame_count >= state->max_depth) |
+ return _URC_END_OF_STACK; |
+ else |
+ return _URC_NO_REASON; |
+} |
+ |
+#endif // BASE_STACKTRACE_ANDROID_INL_H_ |
// Note: this part of the file is included several times. |
// Do not put globals below. |
@@ -60,24 +98,7 @@ |
// int skip_count: how many stack pointers to skip before storing in result |
// void* ucp: a ucontext_t* (GetStack{Trace,Frames}WithContext only) |
int GET_STACK_TRACE_OR_FRAMES { |
- static const int kStackLength = 64; |
- void * stack[kStackLength]; |
- int size; |
- |
- size = backtrace(stack, kStackLength); |
- skip_count++; // we want to skip the current frame as well |
- int result_count = size - skip_count; |
- if (result_count < 0) |
- result_count = 0; |
- if (result_count > max_depth) |
- result_count = max_depth; |
- for (int i = 0; i < result_count; i++) |
- result[i] = stack[i + skip_count]; |
- |
-#if IS_STACK_FRAMES |
- // No implementation for finding out the stack frame sizes yet. |
- memset(sizes, 0, sizeof(*sizes) * result_count); |
-#endif |
- |
- return result_count; |
+ stack_crawl_state_t state( |
+ reinterpret_cast<uintptr_t*>(result), max_depth, skip_count); |
Dai Mikurube (NOT FULLTIME)
2013/05/03 11:02:35
nit: indent by 4
bulach
2013/05/07 14:55:51
Done.
|
+ _Unwind_Backtrace(tracer, &state); |
Dai Mikurube (NOT FULLTIME)
2013/05/03 11:02:35
We need
return state.frame_count;
here. (It's the
bulach
2013/05/07 14:55:51
ahn, great!!! done.
|
} |