[libFuzzer] print a stack trace on timeout
authorKostya Serebryany <kcc@google.com>
Fri, 16 Oct 2015 23:04:31 +0000 (23:04 +0000)
committerKostya Serebryany <kcc@google.com>
Fri, 16 Oct 2015 23:04:31 +0000 (23:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250571 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/FuzzerInternal.h
lib/Fuzzer/FuzzerLoop.cpp
lib/Fuzzer/FuzzerUtil.cpp
lib/Fuzzer/test/fuzzer.test

index c672f23..a720adb 100644 (file)
@@ -56,6 +56,7 @@ bool ToASCII(Unit &U);
 bool IsASCII(const Unit &U);
 
 int NumberOfCpuCores();
+int GetPid();
 
 // Dictionary.
 
index 9305429..a642bbb 100644 (file)
 #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);
   }
 }
index a8856ab..7a04898 100644 (file)
@@ -166,4 +166,6 @@ bool ParseDictionaryFile(const std::string &Text, std::vector<Unit> *Units) {
   return true;
 }
 
+int GetPid() { return getpid(); }
+
 }  // namespace fuzzer
index dccc5e4..1c29c75 100644 (file)
@@ -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