From 9b24e29d7275dbf813238515e9196529f72a7416 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Fri, 16 Oct 2015 23:04:31 +0000 Subject: [PATCH] [libFuzzer] print a stack trace on timeout git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250571 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Fuzzer/FuzzerInternal.h | 1 + lib/Fuzzer/FuzzerLoop.cpp | 9 +++++++++ lib/Fuzzer/FuzzerUtil.cpp | 2 ++ lib/Fuzzer/test/fuzzer.test | 5 +++++ 4 files changed, 17 insertions(+) diff --git a/lib/Fuzzer/FuzzerInternal.h b/lib/Fuzzer/FuzzerInternal.h index c672f23d95f..a720adb21e4 100644 --- a/lib/Fuzzer/FuzzerInternal.h +++ b/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/lib/Fuzzer/FuzzerLoop.cpp b/lib/Fuzzer/FuzzerLoop.cpp index 93054298bc4..a642bbbf5cb 100644 --- a/lib/Fuzzer/FuzzerLoop.cpp +++ b/lib/Fuzzer/FuzzerLoop.cpp @@ -13,6 +13,10 @@ #include #include +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/lib/Fuzzer/FuzzerUtil.cpp b/lib/Fuzzer/FuzzerUtil.cpp index a8856ab3bce..7a04898cf36 100644 --- a/lib/Fuzzer/FuzzerUtil.cpp +++ b/lib/Fuzzer/FuzzerUtil.cpp @@ -166,4 +166,6 @@ bool ParseDictionaryFile(const std::string &Text, std::vector *Units) { return true; } +int GetPid() { return getpid(); } + } // namespace fuzzer diff --git a/lib/Fuzzer/test/fuzzer.test b/lib/Fuzzer/test/fuzzer.test index dccc5e48250..1c29c75d85a 100644 --- a/lib/Fuzzer/test/fuzzer.test +++ b/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 -- 2.34.1