diff options
author | Kostya Serebryany <kcc@google.com> | 2012-08-28 13:25:55 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2012-08-28 13:25:55 +0000 |
commit | 2b939c3abc8b7713ef28000bd768ca6d77445f45 (patch) | |
tree | 52290ded4e51a97e788ec2b2ecbddda1bdc0a685 /lib | |
parent | 8757a68c78f76fca32d3f2256fa70a7b550aa9e1 (diff) | |
download | compiler-rt-2b939c3abc8b7713ef28000bd768ca6d77445f45.tar.gz compiler-rt-2b939c3abc8b7713ef28000bd768ca6d77445f45.tar.bz2 compiler-rt-2b939c3abc8b7713ef28000bd768ca6d77445f45.tar.xz |
[asan] more refactoring to move StackTrace to sanitizer_common
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@162752 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/asan/asan_linux.cc | 15 | ||||
-rw-r--r-- | lib/asan/asan_mac.cc | 12 | ||||
-rw-r--r-- | lib/asan/asan_stack.cc | 16 | ||||
-rw-r--r-- | lib/asan/asan_stack.h | 10 |
4 files changed, 26 insertions, 27 deletions
diff --git a/lib/asan/asan_linux.cc b/lib/asan/asan_linux.cc index bbc7dad1..5c52ddc9 100644 --- a/lib/asan/asan_linux.cc +++ b/lib/asan/asan_linux.cc @@ -17,6 +17,7 @@ #include "asan_internal.h" #include "asan_lock.h" #include "asan_thread.h" +#include "asan_thread_registry.h" #include "sanitizer_common/sanitizer_libc.h" #include "sanitizer_common/sanitizer_procmaps.h" @@ -131,15 +132,17 @@ _Unwind_Reason_Code Unwind_Trace(struct _Unwind_Context *ctx, return UNWIND_CONTINUE; } -void StackTrace::GetStackTrace(uptr max_s, uptr pc, uptr bp) { - size = 0; - trace[0] = pc; +void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp) { + stack->size = 0; + stack->trace[0] = pc; if ((max_s) > 1) { - max_size = max_s; + stack->max_size = max_s; #ifdef __arm__ - _Unwind_Backtrace(Unwind_Trace, this); + _Unwind_Backtrace(Unwind_Trace, stack); #else - FastUnwindStack(pc, bp); + if (!asan_inited) return; + if (AsanThread *t = asanThreadRegistry().GetCurrent()) + stack->FastUnwindStack(pc, bp, t->stack_top(), t->stack_bottom()); #endif } } diff --git a/lib/asan/asan_mac.cc b/lib/asan/asan_mac.cc index d7fc6c47..a96117df 100644 --- a/lib/asan/asan_mac.cc +++ b/lib/asan/asan_mac.cc @@ -152,12 +152,14 @@ void AsanLock::Unlock() { OSSpinLockUnlock((OSSpinLock*)&opaque_storage_); } -void StackTrace::GetStackTrace(uptr max_s, uptr pc, uptr bp) { - size = 0; - trace[0] = pc; +void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp) { + stack->size = 0; + stack->trace[0] = pc; if ((max_s) > 1) { - max_size = max_s; - FastUnwindStack(pc, bp); + stack->max_size = max_s; + if (!asan_inited) return; + if (AsanThread *t = asanThreadRegistry().GetCurrent()) + stack->FastUnwindStack(pc, bp, t->stack_top(), t->stack_bottom()); } } diff --git a/lib/asan/asan_stack.cc b/lib/asan/asan_stack.cc index 08fdb425..618fc32d 100644 --- a/lib/asan/asan_stack.cc +++ b/lib/asan/asan_stack.cc @@ -11,12 +11,8 @@ // // Code for ASan stack trace. //===----------------------------------------------------------------------===// -#include "asan_interceptors.h" #include "asan_interface.h" -#include "asan_lock.h" #include "asan_stack.h" -#include "asan_thread.h" -#include "asan_thread_registry.h" #include "sanitizer_common/sanitizer_procmaps.h" #include "sanitizer_common/sanitizer_symbolizer.h" @@ -100,19 +96,15 @@ uptr StackTrace::GetCurrentPc() { return GET_CALLER_PC(); } -void StackTrace::FastUnwindStack(uptr pc, uptr bp) { +void StackTrace::FastUnwindStack(uptr pc, uptr bp, + uptr stack_top, uptr stack_bottom) { CHECK(size == 0 && trace[0] == pc); size = 1; - if (!asan_inited) return; - AsanThread *t = asanThreadRegistry().GetCurrent(); - if (!t) return; uptr *frame = (uptr*)bp; uptr *prev_frame = frame; - uptr *top = (uptr*)t->stack_top(); - uptr *bottom = (uptr*)t->stack_bottom(); while (frame >= prev_frame && - frame < top - 2 && - frame > bottom && + frame < (uptr*)stack_top - 2 && + frame > (uptr*)stack_bottom && size < max_size) { uptr pc1 = frame[1]; if (pc1 != pc) { diff --git a/lib/asan/asan_stack.h b/lib/asan/asan_stack.h index df1f2466..0d483b9a 100644 --- a/lib/asan/asan_stack.h +++ b/lib/asan/asan_stack.h @@ -43,9 +43,7 @@ struct StackTrace { } } - void GetStackTrace(uptr max_s, uptr pc, uptr bp); - - void FastUnwindStack(uptr pc, uptr bp); + void FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom); static uptr GetCurrentPc(); @@ -55,6 +53,10 @@ struct StackTrace { u32 *compressed, uptr size); }; +void GetStackTrace(StackTrace *trace, uptr max_s, uptr pc, uptr bp); + + + } // namespace __asan // Use this macro if you want to print stack trace with the caller @@ -79,7 +81,7 @@ struct StackTrace { // fast_unwind is currently unused. #define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, pc, bp) \ StackTrace stack; \ - stack.GetStackTrace(max_s, pc, bp) + GetStackTrace(&stack, max_s, pc, bp) // NOTE: A Rule of thumb is to retrieve stack trace in the interceptors // as early as possible (in functions exposed to the user), as we generally |