diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-10 00:03:11 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-10 00:03:11 +0000 |
commit | 0c96391ea345ecffe6a02c12709c119fc7fcbfc1 (patch) | |
tree | 4111bbe4204e81e5f653b4fdb45fa91c1b864b10 /base | |
parent | 2c21105930d83313a6fd4438acc8914873e23dbd (diff) | |
download | chromium_src-0c96391ea345ecffe6a02c12709c119fc7fcbfc1.zip chromium_src-0c96391ea345ecffe6a02c12709c119fc7fcbfc1.tar.gz chromium_src-0c96391ea345ecffe6a02c12709c119fc7fcbfc1.tar.bz2 |
Clean up base/debug/stack_trace_android.cc.
It's looking like we'll be sticking with <unwind.h> for the forseeable future.
Clean up the code to match Chromium style and remove TODOs relating to switching away from <unwind.h>.
BUG=236855
Review URL: https://chromiumcodereview.appspot.com/18337008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210676 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/debug/stack_trace_android.cc | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/base/debug/stack_trace_android.cc b/base/debug/stack_trace_android.cc index 4c11a24..487cbc4 100644 --- a/base/debug/stack_trace_android.cc +++ b/base/debug/stack_trace_android.cc @@ -5,49 +5,40 @@ #include "base/debug/stack_trace.h" #include <android/log.h> -#include <unwind.h> // TODO(dmikurube): Remove. See http://crbug.com/236855. +#include <unwind.h> #include "base/debug/proc_maps_linux.h" #include "base/strings/stringprintf.h" -// TODO(dmikurube): Remove when Bionic's get_backtrace() gets popular. -// See http://crbug.com/236855. namespace { -/* depends how the system includes define this */ -#ifdef HAVE_UNWIND_CONTEXT_STRUCT -typedef struct _Unwind_Context __unwind_context; -#else -typedef _Unwind_Context __unwind_context; -#endif +struct StackCrawlState { + StackCrawlState(uintptr_t* frames, size_t max_depth) + : frames(frames), + frame_count(0), + max_depth(max_depth), + have_skipped_self(false) {} -struct stack_crawl_state_t { uintptr_t* frames; size_t frame_count; size_t max_depth; bool have_skipped_self; - - stack_crawl_state_t(uintptr_t* frames, size_t max_depth) - : frames(frames), - frame_count(0), - max_depth(max_depth), - 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); - +// Clang's unwind.h doesn't provide _Unwind_GetIP on ARM, refer to +// http://llvm.org/bugs/show_bug.cgi?id=16564 for details. #if defined(__clang__) - // Vanilla Clang's unwind.h doesn't have _Unwind_GetIP for ARM. - // See http://crbug.com/236855, too. +uintptr_t _Unwind_GetIP(_Unwind_Context* context) { uintptr_t ip = 0; _Unwind_VRS_Get(context, _UVRSC_CORE, 15, _UVRSD_UINT32, &ip); - ip &= ~(uintptr_t)0x1; // remove thumb mode bit -#else - uintptr_t ip = _Unwind_GetIP(context); + return ip & ~static_cast<uintptr_t>(0x1); // Remove thumb mode bit. +} #endif +_Unwind_Reason_Code TraceStackFrame(_Unwind_Context* context, void* arg) { + StackCrawlState* state = static_cast<StackCrawlState*>(arg); + uintptr_t ip = _Unwind_GetIP(context); + // The first stack frame is this function itself. Skip it. if (ip != 0 && !state->have_skipped_self) { state->have_skipped_self = true; @@ -57,8 +48,7 @@ static _Unwind_Reason_Code tracer(__unwind_context* context, void* arg) { state->frames[state->frame_count++] = ip; if (state->frame_count >= state->max_depth) return _URC_END_OF_STACK; - else - return _URC_NO_REASON; + return _URC_NO_REASON; } } // namespace @@ -79,12 +69,9 @@ bool EnableInProcessStackDumping() { } StackTrace::StackTrace() { - // TODO(dmikurube): Replace it with Bionic's get_backtrace(). - // See http://crbug.com/236855. - stack_crawl_state_t state(reinterpret_cast<uintptr_t*>(trace_), kMaxTraces); - _Unwind_Backtrace(tracer, &state); + StackCrawlState state(reinterpret_cast<uintptr_t*>(trace_), kMaxTraces); + _Unwind_Backtrace(&TraceStackFrame, &state); count_ = state.frame_count; - // TODO(dmikurube): Symbolize in Chrome. } void StackTrace::PrintBacktrace() const { |