[compiler-rt] r192533 - [Sanitizer] Turn GetStackTrace() into StackTrace::Unwind()

Alexey Samsonov samsonov at google.com
Sat Oct 12 05:23:01 PDT 2013


Author: samsonov
Date: Sat Oct 12 07:23:00 2013
New Revision: 192533

URL: http://llvm.org/viewvc/llvm-project?rev=192533&view=rev
Log:
[Sanitizer] Turn GetStackTrace() into StackTrace::Unwind()

Modified:
    compiler-rt/trunk/lib/asan/asan_stack.h
    compiler-rt/trunk/lib/lsan/lsan_interceptors.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc

Modified: compiler-rt/trunk/lib/asan/asan_stack.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_stack.h?rev=192533&r1=192532&r2=192533&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_stack.h (original)
+++ compiler-rt/trunk/lib/asan/asan_stack.h Sat Oct 12 07:23:00 2013
@@ -31,7 +31,7 @@ void PrintStack(StackTrace *stack);
 #if SANITIZER_WINDOWS
 #define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, pc, bp, fast) \
   StackTrace stack;                                         \
-  GetStackTrace(&stack, max_s, pc, bp, 0, 0, fast)
+  stack.Unwind(max_s, pc, bp, 0, 0, fast)
 #else
 #define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, pc, bp, fast)                \
   StackTrace stack;                                                        \
@@ -42,7 +42,7 @@ void PrintStack(StackTrace *stack);
       uptr stack_top = t->stack_top();                                     \
       uptr stack_bottom = t->stack_bottom();                               \
       ScopedUnwinding unwind_scope(t);                                     \
-      GetStackTrace(&stack, max_s, pc, bp, stack_top, stack_bottom, fast); \
+      stack.Unwind(max_s, pc, bp, stack_top, stack_bottom, fast);          \
     }                                                                      \
   }
 #endif  // SANITIZER_WINDOWS

Modified: compiler-rt/trunk/lib/lsan/lsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_interceptors.cc?rev=192533&r1=192532&r2=192533&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_interceptors.cc Sat Oct 12 07:23:00 2013
@@ -44,9 +44,9 @@ int pthread_setspecific(unsigned key, co
       stack_top = t->stack_end();                                            \
       stack_bottom = t->stack_begin();                                       \
     }                                                                        \
-    GetStackTrace(&stack, __sanitizer::common_flags()->malloc_context_size,  \
-                  StackTrace::GetCurrentPc(),                                \
-                  GET_CURRENT_FRAME(), stack_top, stack_bottom, fast);       \
+    stack.Unwind(__sanitizer::common_flags()->malloc_context_size,           \
+                 StackTrace::GetCurrentPc(),                                 \
+                 GET_CURRENT_FRAME(), stack_top, stack_bottom, fast);        \
   }
 
 ///// Malloc/free interceptors. /////

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc?rev=192533&r1=192532&r2=192533&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cc Sat Oct 12 07:23:00 2013
@@ -90,8 +90,8 @@ int internal_isatty(fd_t fd) {
 }
 
 #ifndef SANITIZER_GO
-void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp,
-                   uptr stack_top, uptr stack_bottom, bool fast) {
+void StackTrace::Unwind(uptr max_depth, uptr pc, uptr bp, uptr stack_top,
+                        uptr stack_bottom, bool fast) {
   // Check if fast unwind is available. Fast unwind is the only option on Mac.
   if (!SANITIZER_CAN_FAST_UNWIND)
     fast = false;
@@ -99,9 +99,9 @@ void GetStackTrace(StackTrace *stack, up
     fast = true;
 
   if (!fast)
-    stack->SlowUnwindStack(pc, max_s);
+    SlowUnwindStack(pc, max_depth);
   else
-    stack->FastUnwindStack(pc, bp, stack_top, stack_bottom, max_s);
+    FastUnwindStack(pc, bp, stack_top, stack_bottom, max_depth);
 }
 #endif  // SANITIZER_GO
 

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc?rev=192533&r1=192532&r2=192533&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc Sat Oct 12 07:23:00 2013
@@ -150,7 +150,6 @@ void StackTrace::PopStackFrames(uptr cou
 // On 32-bits we don't compress stack traces.
 // On 64-bits we compress stack traces: if a given pc differes slightly from
 // the previous one, we record a 31-bit offset instead of the full pc.
-SANITIZER_INTERFACE_ATTRIBUTE
 uptr StackTrace::CompressStack(StackTrace *stack, u32 *compressed, uptr size) {
 #if SANITIZER_WORDSIZE == 32
   // Don't compress, just copy.
@@ -213,7 +212,6 @@ uptr StackTrace::CompressStack(StackTrac
   return res;
 }
 
-SANITIZER_INTERFACE_ATTRIBUTE
 void StackTrace::UncompressStack(StackTrace *stack,
                                  u32 *compressed, uptr size) {
 #if SANITIZER_WORDSIZE == 32

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h?rev=192533&r1=192532&r2=192533&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h Sat Oct 12 07:23:00 2013
@@ -39,6 +39,9 @@ struct StackTrace {
 
   void CopyFrom(const uptr *src, uptr src_size);
 
+  void Unwind(uptr max_depth, uptr pc, uptr bp, uptr stack_top,
+              uptr stack_bottom, bool fast);
+  // FIXME: Make FastUnwindStack and SlowUnwindStack private methods.
   void FastUnwindStack(uptr pc, uptr bp, uptr stack_top, uptr stack_bottom,
                        uptr max_depth);
   void SlowUnwindStack(uptr pc, uptr max_depth);
@@ -48,17 +51,12 @@ struct StackTrace {
   static uptr GetCurrentPc();
   static uptr GetPreviousInstructionPc(uptr pc);
 
-  SANITIZER_INTERFACE_ATTRIBUTE
   static uptr CompressStack(StackTrace *stack,
                             u32 *compressed, uptr size);
-  SANITIZER_INTERFACE_ATTRIBUTE
   static void UncompressStack(StackTrace *stack,
                               u32 *compressed, uptr size);
 };
 
-void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp,
-                   uptr stack_top, uptr stack_bottom, bool fast);
-
 }  // namespace __sanitizer
 
 // Use this macro if you want to print stack trace with the caller

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=192533&r1=192532&r2=192533&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Sat Oct 12 07:23:00 2013
@@ -376,18 +376,18 @@ void GetThreadStackAndTls(bool main, upt
 #endif
 }
 
-void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp,
-                   uptr stack_top, uptr stack_bottom, bool fast) {
+void StackTrace::Unwind(uptr max_depth, uptr pc, uptr bp, uptr stack_top,
+                        uptr stack_bottom, bool fast) {
   (void)fast;
   (void)stack_top;
   (void)stack_bottom;
-  stack->max_size = max_s;
+  max_size = max_depth;
   void *tmp[kStackTraceMax];
 
   // FIXME: CaptureStackBackTrace might be too slow for us.
   // FIXME: Compare with StackWalk64.
   // FIXME: Look at LLVMUnhandledExceptionFilter in Signals.inc
-  uptr cs_ret = CaptureStackBackTrace(1, stack->max_size, tmp, 0);
+  uptr cs_ret = CaptureStackBackTrace(1, max_size, tmp, 0);
   uptr offset = 0;
   // Skip the RTL frames by searching for the PC in the stacktrace.
   // FIXME: this doesn't work well for the malloc/free stacks yet.
@@ -398,9 +398,7 @@ void GetStackTrace(StackTrace *stack, up
     break;
   }
 
-  stack->size = cs_ret - offset;
-  for (uptr i = 0; i < stack->size; i++)
-    stack->trace[i] = (uptr)tmp[i + offset];
+  CopyFrom((uptr*)&tmp[offset], cs_ret - offset);
 }
 
 void MaybeOpenReportFile() {





More information about the llvm-commits mailing list