[PATCH] D35409: Add new ASAN_OPTION: sleep_after_init.

Martin Liška via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 2 06:18:15 PDT 2017


marxin updated this revision to Diff 109328.
marxin added a comment.

Update versioin where I added test-case. It's verified that it passes regression tests.


https://reviews.llvm.org/D35409

Files:
  lib/asan/asan_flags.inc
  lib/asan/asan_rtl.cc
  test/asan/TestCases/sleep_after_init.c


Index: test/asan/TestCases/sleep_after_init.c
===================================================================
--- /dev/null
+++ test/asan/TestCases/sleep_after_init.c
@@ -0,0 +1,10 @@
+// RUN: %clang_asan -O2 %s -o %t
+// RUN: %env_asan_opts=sleep_after_init=1 not %run %t 2>&1 | FileCheck %s
+
+#include <stdlib.h>
+int main() {
+  // CHECK: Sleeping for 1 second
+  char *x = (char*)malloc(10 * sizeof(char));
+  free(x);
+  return x[5];
+}
Index: lib/asan/asan_rtl.cc
===================================================================
--- lib/asan/asan_rtl.cc
+++ lib/asan/asan_rtl.cc
@@ -608,6 +608,11 @@
   }
 
   VReport(1, "AddressSanitizer Init done\n");
+
+  if (flags()->sleep_after_init) {
+    Report("Sleeping for %d second(s)\n", flags()->sleep_after_init);
+    SleepForSeconds(flags()->sleep_after_init);
+  }
 }
 
 // Initialize as requested from some part of ASan runtime library (interceptors,
Index: lib/asan/asan_flags.inc
===================================================================
--- lib/asan/asan_flags.inc
+++ lib/asan/asan_flags.inc
@@ -79,6 +79,10 @@
     "Number of seconds to sleep between printing an error report and "
     "terminating the program. Useful for debugging purposes (e.g. when one "
     "needs to attach gdb).")
+ASAN_FLAG(
+    int, sleep_after_init, 0,
+    "Number of seconds to sleep after AddressSanitizer is initialized. "
+    "Useful for debugging purposes (e.g. when one needs to attach gdb).")
 ASAN_FLAG(bool, check_malloc_usable_size, true,
           "Allows the users to work around the bug in Nvidia drivers prior to "
           "295.*.")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35409.109328.patch
Type: text/x-patch
Size: 1615 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170802/0fb2ad8a/attachment.bin>


More information about the llvm-commits mailing list