[asan] new run-time flag: sleep_before_dying (asan Issue #31)

git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@149306 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/asan/asan_internal.h b/lib/asan/asan_internal.h
index fc92e9c..eecedd6 100644
--- a/lib/asan/asan_internal.h
+++ b/lib/asan/asan_internal.h
@@ -166,6 +166,7 @@
 extern size_t FLAG_max_malloc_fill_size;
 extern int    FLAG_exitcode;
 extern bool   FLAG_allow_user_poisoning;
+extern int    FLAG_sleep_before_dying;
 extern bool   FLAG_handle_segv;
 
 extern int asan_inited;
diff --git a/lib/asan/asan_posix.cc b/lib/asan/asan_posix.cc
index cac3589..2d48a19 100644
--- a/lib/asan/asan_posix.cc
+++ b/lib/asan/asan_posix.cc
@@ -70,6 +70,10 @@
 }
 
 void AsanDie() {
+  if (FLAG_sleep_before_dying) {
+    Report("Sleeping for %d second(s)\n", FLAG_sleep_before_dying);
+    sleep(FLAG_sleep_before_dying);
+  }
   _exit(FLAG_exitcode);
 }
 
diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc
index 5a0da37..b40bc41 100644
--- a/lib/asan/asan_rtl.cc
+++ b/lib/asan/asan_rtl.cc
@@ -47,6 +47,7 @@
 bool   FLAG_use_fake_stack;
 int    FLAG_exitcode = EXIT_FAILURE;
 bool   FLAG_allow_user_poisoning;
+int    FLAG_sleep_before_dying;
 
 // -------------------------- Globals --------------------- {{{1
 int asan_inited;
@@ -411,6 +412,7 @@
   FLAG_exitcode = IntFlagValue(options, "exitcode=", EXIT_FAILURE);
   FLAG_allow_user_poisoning = IntFlagValue(options,
                                            "allow_user_poisoning=", 1);
+  FLAG_sleep_before_dying = IntFlagValue(options, "sleep_before_dying=", 0);
 
   if (FLAG_atexit) {
     atexit(asan_atexit);
diff --git a/lib/asan/tests/test_output.sh b/lib/asan/tests/test_output.sh
index 1dfe959..385fba2 100755
--- a/lib/asan/tests/test_output.sh
+++ b/lib/asan/tests/test_output.sh
@@ -19,6 +19,11 @@
 ./a.out 2>&1 | grep "heap-use-after-free" > /dev/null
 rm ./a.out
 
+echo "Testing sleep_before_dying"
+$CC -g -faddress-sanitizer -O2 $C_TEST.c
+ASAN_OPTIONS=sleep_before_dying=1 ./a.out 2>&1 | grep "Sleeping for 1 second" > /dev/null
+rm a.out
+
 for t in  *.tmpl; do
   for b in 32 64; do
     for O in 0 1 2 3; do