Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit f6f49c0

Browse files
committed
Add new ASAN_OPTION: sleep_after_init.
Summary: As mentioned in google/sanitizers#834, suggested option can be handy for debugging. Reviewers: kcc Reviewed By: kcc Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D35409 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@309854 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent e476079 commit f6f49c0

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

lib/asan/asan_flags.inc

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ ASAN_FLAG(
7979
"Number of seconds to sleep between printing an error report and "
8080
"terminating the program. Useful for debugging purposes (e.g. when one "
8181
"needs to attach gdb).")
82+
ASAN_FLAG(
83+
int, sleep_after_init, 0,
84+
"Number of seconds to sleep after AddressSanitizer is initialized. "
85+
"Useful for debugging purposes (e.g. when one needs to attach gdb).")
8286
ASAN_FLAG(bool, check_malloc_usable_size, true,
8387
"Allows the users to work around the bug in Nvidia drivers prior to "
8488
"295.*.")

lib/asan/asan_rtl.cc

+5
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,11 @@ static void AsanInitInternal() {
484484
}
485485

486486
VReport(1, "AddressSanitizer Init done\n");
487+
488+
if (flags()->sleep_after_init) {
489+
Report("Sleeping for %d second(s)\n", flags()->sleep_after_init);
490+
SleepForSeconds(flags()->sleep_after_init);
491+
}
487492
}
488493

489494
// Initialize as requested from some part of ASan runtime library (interceptors,
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_asan -O2 %s -o %t
2+
// RUN: %env_asan_opts=sleep_after_init=1 not %run %t 2>&1 | FileCheck %s
3+
4+
#include <stdlib.h>
5+
int main() {
6+
// CHECK: Sleeping for 1 second
7+
char *x = (char*)malloc(10 * sizeof(char));
8+
free(x);
9+
return x[5];
10+
}

0 commit comments

Comments
 (0)