[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 c672f23d95f18b0dac3469e280c481041524a21a..a720adb21e41af8a7193e3d3a38ddce564ad8f70 100644 (file)
@@ -56,6 +56,7 @@ bool ToASCII(Unit &U);
 bool IsASCII(const Unit &U);
 
 int NumberOfCpuCores();
+int GetPid();
 
 // Dictionary.
 
index 93054298bc401a30cca6db76759ce15c026ef15e..a642bbbf5cba8cd8941f839136929e5b51c0b1f6 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 a8856ab3bce8d66f5ea0b6dadd9cb9a397119f2f..7a04898cf3637ce86d14e3e179aecc6bb2e2806b 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 dccc5e482500649f00ef0899aa11be6f8f0777ea..1c29c75d85a931e572710e9a739a117528633731 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