[PATCH] Fix sanitizers' FastUnwindStack() to work in the unwinding state

Viktor Kutuzov vkutuzov at accesssoftek.com
Thu Jul 10 06:15:54 PDT 2014


Hi kcc, samsonov,

According to GetStackTraceWithPcBpAndContext() implementation:

  void GetStackTraceWithPcBpAndContext(StackTrace *stack, uptr max_depth, uptr pc,
                                       uptr bp, void *context, bool fast) {
  #if SANITIZER_WINDOWS
    stack->Unwind(max_depth, pc, bp, context, 0, 0, fast);
  #else
    ...
      if ((t = GetCurrentThread()) && !t->isUnwinding()) {
        ...
      } else if (t == 0 && !fast) {
          /* If GetCurrentThread() has failed, try to do slow unwind anyways. */
        stack->Unwind(max_depth, pc, bp, context, 0, 0, false);
      }
    }
  #endif  // SANITIZER_WINDOWS
  }

if the current thread is in the unwinding state, the 'stack_top' and 'stack_bottom' parameters of the StackTrace::FastUnwindStack() function both set to 0. That, in turn, results in the sanity condition for 'stack_top' within that function always met and thus no call stack is provided.

http://reviews.llvm.org/D4460

Files:
  lib/sanitizer_common/sanitizer_stacktrace.cc

Index: lib/sanitizer_common/sanitizer_stacktrace.cc
===================================================================
--- lib/sanitizer_common/sanitizer_stacktrace.cc
+++ lib/sanitizer_common/sanitizer_stacktrace.cc
@@ -44,7 +44,8 @@
   size = 1;
   uhwptr *frame = (uhwptr *)bp;
   uhwptr *prev_frame = frame - 1;
-  if (stack_top < 4096) return;  // Sanity check for stack top.
+  // Sanity check for stack top.
+  if ((stack_top != 0 || stack_bottom != 0) && stack_top < 4096) return;
   // Avoid infinite loop when frame == frame[0] by using frame > prev_frame.
   while (frame > prev_frame &&
          frame < (uhwptr *)stack_top - 2 &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4460.11265.patch
Type: text/x-patch
Size: 645 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140710/6cc642c3/attachment.bin>


More information about the llvm-commits mailing list