diff options
author | Kostya Serebryany <kcc@google.com> | 2015-10-16 23:04:31 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2015-10-16 23:04:31 +0000 |
commit | d6edce97fb762b69f6f63c456b764c25386f7543 (patch) | |
tree | 294cff515f7d09553c33516698cc6967dbe94d97 /llvm/lib/Fuzzer | |
parent | b43d33bf0fee62317cc24239c77ae0f05fdb40f2 (diff) | |
download | bcm5719-llvm-d6edce97fb762b69f6f63c456b764c25386f7543.tar.gz bcm5719-llvm-d6edce97fb762b69f6f63c456b764c25386f7543.zip |
[libFuzzer] print a stack trace on timeout
llvm-svn: 250571
Diffstat (limited to 'llvm/lib/Fuzzer')
-rw-r--r-- | llvm/lib/Fuzzer/FuzzerInternal.h | 1 | ||||
-rw-r--r-- | llvm/lib/Fuzzer/FuzzerLoop.cpp | 9 | ||||
-rw-r--r-- | llvm/lib/Fuzzer/FuzzerUtil.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Fuzzer/test/fuzzer.test | 5 |
4 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerInternal.h b/llvm/lib/Fuzzer/FuzzerInternal.h index c672f23d95f..a720adb21e4 100644 --- a/llvm/lib/Fuzzer/FuzzerInternal.h +++ b/llvm/lib/Fuzzer/FuzzerInternal.h @@ -56,6 +56,7 @@ bool ToASCII(Unit &U); bool IsASCII(const Unit &U); int NumberOfCpuCores(); +int GetPid(); // Dictionary. diff --git a/llvm/lib/Fuzzer/FuzzerLoop.cpp b/llvm/lib/Fuzzer/FuzzerLoop.cpp index 93054298bc4..a642bbbf5cb 100644 --- a/llvm/lib/Fuzzer/FuzzerLoop.cpp +++ b/llvm/lib/Fuzzer/FuzzerLoop.cpp @@ -13,6 +13,10 @@ #include <sanitizer/coverage_interface.h> #include <algorithm> +extern "C" { +__attribute__((weak)) void __sanitizer_print_stack_trace(); +} + namespace fuzzer { static const size_t kMaxUnitSizeToPrint = 256; @@ -76,6 +80,11 @@ void Fuzzer::AlarmCallback() { PrintUnitInASCIIOrTokens(CurrentUnit, "\n"); } WriteUnitToFileWithPrefix(CurrentUnit, "timeout-"); + Printf("==%d== ERROR: libFuzzer: timeout after %d seconds\n", GetPid(), + Seconds); + if (__sanitizer_print_stack_trace) + __sanitizer_print_stack_trace(); + Printf("SUMMARY: libFuzzer: timeout\n"); exit(1); } } diff --git a/llvm/lib/Fuzzer/FuzzerUtil.cpp b/llvm/lib/Fuzzer/FuzzerUtil.cpp index a8856ab3bce..7a04898cf36 100644 --- a/llvm/lib/Fuzzer/FuzzerUtil.cpp +++ b/llvm/lib/Fuzzer/FuzzerUtil.cpp @@ -166,4 +166,6 @@ bool ParseDictionaryFile(const std::string &Text, std::vector<Unit> *Units) { return true; } +int GetPid() { return getpid(); } + } // namespace fuzzer diff --git a/llvm/lib/Fuzzer/test/fuzzer.test b/llvm/lib/Fuzzer/test/fuzzer.test index dccc5e48250..1c29c75d85a 100644 --- a/llvm/lib/Fuzzer/test/fuzzer.test +++ b/llvm/lib/Fuzzer/test/fuzzer.test @@ -14,6 +14,11 @@ MaxTotalTime: Done {{.*}} runs in {{.}} second(s) RUN: not LLVMFuzzer-TimeoutTest -timeout=5 2>&1 | FileCheck %s --check-prefix=TimeoutTest TimeoutTest: ALARM: working on the last Unit for TimeoutTest: Test unit written to ./timeout- +TimeoutTest: == ERROR: libFuzzer: timeout after +TimeoutTest: #0 +TimeoutTest: #1 +TimeoutTest: #2 +TimeoutTest: SUMMARY: libFuzzer: timeout RUN: not LLVMFuzzer-TimeoutTest -timeout=5 -test_single_input=%S/hi.txt 2>&1 | FileCheck %s --check-prefix=SingleInputTimeoutTest SingleInputTimeoutTest: ALARM: working on the last Unit for |