From 38c36e3216d68c8907fb52001a64b5930097a6e2 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Sat, 9 Jan 2016 03:46:08 +0000 Subject: [PATCH] [libFuzzer] debug prints in tracing git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257249 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Fuzzer/FuzzerTraceState.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/Fuzzer/FuzzerTraceState.cpp b/lib/Fuzzer/FuzzerTraceState.cpp index 83130444a16..36fc6dcfd23 100644 --- a/lib/Fuzzer/FuzzerTraceState.cpp +++ b/lib/Fuzzer/FuzzerTraceState.cpp @@ -170,6 +170,25 @@ struct TraceBasedMutation { uint8_t Data[kMaxSize]; }; +static void PrintDataByte(uint8_t Byte) { + if (Byte == '\\') + Printf("\\\\"); + else if (Byte == '"') + Printf("\\\""); + else if (Byte >= 32 && Byte < 127) + Printf("%c", Byte); + else + Printf("\\x02x", Byte); +} + +static void PrintData(const uint8_t *Data, size_t Size) { + Printf("\""); + for (size_t i = 0; i < Size; i++) { + PrintDataByte(Data[i]); + } + Printf("\""); +} + const size_t TraceBasedMutation::kMaxSize; class TraceState { @@ -394,8 +413,14 @@ void TraceState::TraceMemcmpCallback(size_t CmpSize, const uint8_t *Data1, const uint8_t *Data2) { if (!RecordingTraces || !IsMyThread) return; CmpSize = std::min(CmpSize, TraceBasedMutation::kMaxSize); - TryToAddDesiredData(Data1, Data2, CmpSize); - TryToAddDesiredData(Data2, Data1, CmpSize); + int Added2 = TryToAddDesiredData(Data1, Data2, CmpSize); + int Added1 = TryToAddDesiredData(Data2, Data1, CmpSize); + if ((Added1 || Added2) && Options.Verbosity >= 3) { + Printf("MemCmp Added %d%d: ", Added1, Added2); + if (Added1) PrintData(Data1, CmpSize); + if (Added2) PrintData(Data2, CmpSize); + Printf("\n"); + } } void TraceState::TraceSwitchCallback(uintptr_t PC, size_t ValSizeInBits, -- 2.34.1