Chromium Code Reviews| Index: base/debug/stack_trace.cc |
| diff --git a/base/debug/stack_trace.cc b/base/debug/stack_trace.cc |
| index ac0ead76be2b1cf62339e55fa20b59f6488acbe9..9b2c51fd51457b17fac360c47d5bbcd0f49f53bf 100644 |
| --- a/base/debug/stack_trace.cc |
| +++ b/base/debug/stack_trace.cc |
| @@ -7,11 +7,12 @@ |
| #include <string.h> |
| #include <algorithm> |
| +#include <limits> |
| #include <sstream> |
| #include "base/macros.h" |
| -#if HAVE_TRACE_STACK_FRAME_POINTERS && defined(OS_ANDROID) |
|
Primiano Tucci (use gerrit)
2016/08/03 09:32:03
I think you still need OS_POSIX otherwise that inc
Dmitry Skiba
2016/08/11 16:52:38
Done.
|
| +#if HAVE_TRACE_STACK_FRAME_POINTERS |
| #include <pthread.h> |
| #include "base/process/process_handle.h" |
| #include "base/threading/platform_thread.h" |
| @@ -49,6 +50,8 @@ std::string StackTrace::ToString() const { |
| #if defined(OS_ANDROID) |
| +#define HAVE_GET_STACK_END 1 |
| + |
| static uintptr_t GetStackEnd() { |
|
Primiano Tucci (use gerrit)
2016/08/03 09:32:03
I think all this become more readable and easy to
Dmitry Skiba
2016/08/11 16:52:38
Done.
|
| // Bionic reads proc/maps on every call to pthread_getattr_np() when called |
| // from the main thread. So we need to cache end of stack in that case to get |
| @@ -85,6 +88,25 @@ static uintptr_t GetStackEnd() { |
| #endif // defined(OS_ANDROID) |
| +#if defined(__GLIBC__) |
|
Primiano Tucci (use gerrit)
2016/08/03 09:32:03
Just change lines 89-91 to be:
#elif defined(OS_L
Dmitry Skiba
2016/08/11 16:52:38
Done.
|
| + |
| +#define HAVE_GET_STACK_END 1 |
| + |
| +extern "C" void* __libc_stack_end; |
|
Primiano Tucci (use gerrit)
2016/08/03 09:32:04
Ok it seems we already depend on this in StackFram
Dmitry Skiba
2016/08/11 16:52:38
Acknowledged.
|
| + |
| +static uintptr_t GetStackEnd() { |
| + if (GetCurrentProcId() == PlatformThread::CurrentId()) { |
| + // For the main thread we have a shortcut. |
| + return reinterpret_cast<uintptr_t>(__libc_stack_end); |
| + } else { |
| + // No easy way to get stack end for non-main threads, |
| + // see crbug.com/617730. |
| + return std::numeric_limits<uintptr_t>::max(); |
| + } |
| +} |
| + |
| +#endif // defined(__GLIBC__) |
| + |
| size_t TraceStackFramePointers(const void** out_trace, |
| size_t max_depth, |
| size_t skip_initial) { |
| @@ -93,7 +115,7 @@ size_t TraceStackFramePointers(const void** out_trace, |
| // be valid. |
| uintptr_t sp = reinterpret_cast<uintptr_t>(__builtin_frame_address(0)); |
| -#if defined(OS_ANDROID) |
| +#if HAVE_GET_STACK_END |
| uintptr_t stack_end = GetStackEnd(); |
| #endif |
| @@ -106,7 +128,7 @@ size_t TraceStackFramePointers(const void** out_trace, |
| sp -= sizeof(uintptr_t); |
| #endif |
| -#if defined(OS_ANDROID) |
| +#if HAVE_GET_STACK_END |
| // Both sp[0] and s[1] must be valid. |
| if (sp + 2 * sizeof(uintptr_t) > stack_end) { |
| break; |