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 <android/log.h> | 7 #include <android/log.h> |
8 #include <unwind.h> | 8 #include <unwind.h> |
9 | 9 |
10 #include "base/debug/proc_maps_linux.h" | 10 #include "base/debug/proc_maps_linux.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 struct StackCrawlState { | 16 struct StackCrawlState { |
17 StackCrawlState(uintptr_t* frames, size_t max_depth) | 17 StackCrawlState(uintptr_t* frames, size_t max_depth) |
18 : frames(frames), | 18 : frames(frames), |
19 frame_count(0), | 19 frame_count(0), |
20 max_depth(max_depth), | 20 max_depth(max_depth), |
21 have_skipped_self(false) {} | 21 have_skipped_self(false) {} |
22 | 22 |
23 uintptr_t* frames; | 23 uintptr_t* frames; |
24 size_t frame_count; | 24 size_t frame_count; |
25 size_t max_depth; | 25 size_t max_depth; |
26 bool have_skipped_self; | 26 bool have_skipped_self; |
27 }; | 27 }; |
28 | 28 |
| 29 // Clang's unwind.h doesn't provide _Unwind_GetIP on ARM, refer to |
| 30 // http://llvm.org/bugs/show_bug.cgi?id=16564 for details. |
| 31 #if defined(__clang__) |
| 32 uintptr_t _Unwind_GetIP(_Unwind_Context* context) { |
| 33 uintptr_t ip = 0; |
| 34 _Unwind_VRS_Get(context, _UVRSC_CORE, 15, _UVRSD_UINT32, &ip); |
| 35 return ip & ~static_cast<uintptr_t>(0x1); // Remove thumb mode bit. |
| 36 } |
| 37 #endif |
| 38 |
29 _Unwind_Reason_Code TraceStackFrame(_Unwind_Context* context, void* arg) { | 39 _Unwind_Reason_Code TraceStackFrame(_Unwind_Context* context, void* arg) { |
30 StackCrawlState* state = static_cast<StackCrawlState*>(arg); | 40 StackCrawlState* state = static_cast<StackCrawlState*>(arg); |
31 uintptr_t ip = _Unwind_GetIP(context); | 41 uintptr_t ip = _Unwind_GetIP(context); |
32 | 42 |
33 // The first stack frame is this function itself. Skip it. | 43 // The first stack frame is this function itself. Skip it. |
34 if (ip != 0 && !state->have_skipped_self) { | 44 if (ip != 0 && !state->have_skipped_self) { |
35 state->have_skipped_self = true; | 45 state->have_skipped_self = true; |
36 return _URC_NO_REASON; | 46 return _URC_NO_REASON; |
37 } | 47 } |
38 | 48 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } else { | 123 } else { |
114 *os << "<unknown>"; | 124 *os << "<unknown>"; |
115 } | 125 } |
116 | 126 |
117 *os << "\n"; | 127 *os << "\n"; |
118 } | 128 } |
119 } | 129 } |
120 | 130 |
121 } // namespace debug | 131 } // namespace debug |
122 } // namespace base | 132 } // namespace base |
OLD | NEW |