diff options
| author | Kostya Serebryany <kcc@google.com> | 2016-10-13 19:06:46 +0000 |
|---|---|---|
| committer | Kostya Serebryany <kcc@google.com> | 2016-10-13 19:06:46 +0000 |
| commit | a17d23eaa7e60d54b2695e09b3aad4eb2155f629 (patch) | |
| tree | 67f369e148820b6f53c484a2ebec8afe506e8892 /llvm/lib/Fuzzer/FuzzerLoop.cpp | |
| parent | 92db01ebd7b7a3a0cc54e938b807a7e55cbddd82 (diff) | |
| download | bcm5719-llvm-a17d23eaa7e60d54b2695e09b3aad4eb2155f629.tar.gz bcm5719-llvm-a17d23eaa7e60d54b2695e09b3aad4eb2155f629.zip | |
[libFuzzer] add -trace_malloc= flag
llvm-svn: 284149
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerLoop.cpp')
| -rw-r--r-- | llvm/lib/Fuzzer/FuzzerLoop.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerLoop.cpp b/llvm/lib/Fuzzer/FuzzerLoop.cpp index 1b5e0265e13..37db6ee09e5 100644 --- a/llvm/lib/Fuzzer/FuzzerLoop.cpp +++ b/llvm/lib/Fuzzer/FuzzerLoop.cpp @@ -111,23 +111,46 @@ bool Fuzzer::RecordMaxCoverage(Fuzzer::Coverage *C) { // Leak detection is expensive, so we first check if there were more mallocs // than frees (using the sanitizer malloc hooks) and only then try to call lsan. struct MallocFreeTracer { - void Start() { + void Start(int TraceLevel) { + this->TraceLevel = TraceLevel; + if (TraceLevel) + Printf("MallocFreeTracer: START\n"); Mallocs = 0; Frees = 0; } // Returns true if there were more mallocs than frees. - bool Stop() { return Mallocs > Frees; } + bool Stop() { + if (TraceLevel) + Printf("MallocFreeTracer: STOP %zd %zd (%s)\n", Mallocs.load(), + Frees.load(), Mallocs == Frees ? "same" : "DIFFERENT"); + bool Result = Mallocs > Frees; + Mallocs = 0; + Frees = 0; + TraceLevel = 0; + return Result; + } std::atomic<size_t> Mallocs; std::atomic<size_t> Frees; + int TraceLevel = 0; }; static MallocFreeTracer AllocTracer; void MallocHook(const volatile void *ptr, size_t size) { - AllocTracer.Mallocs++; + size_t N = AllocTracer.Mallocs++; + if (int TraceLevel = AllocTracer.TraceLevel) { + Printf("MALLOC[%zd] %p %zd\n", N, ptr, size); + if (TraceLevel >= 2 && EF) + EF->__sanitizer_print_stack_trace(); + } } void FreeHook(const volatile void *ptr) { - AllocTracer.Frees++; + size_t N = AllocTracer.Frees++; + if (int TraceLevel = AllocTracer.TraceLevel) { + Printf("FREE[%zd] %p %zd\n", N, ptr); + if (TraceLevel >= 2 && EF) + EF->__sanitizer_print_stack_trace(); + } } Fuzzer::Fuzzer(UserCallback CB, InputCorpus &Corpus, MutationDispatcher &MD, @@ -486,7 +509,7 @@ void Fuzzer::ExecuteCallback(const uint8_t *Data, size_t Size) { if (CurrentUnitData && CurrentUnitData != Data) memcpy(CurrentUnitData, Data, Size); CurrentUnitSize = Size; - AllocTracer.Start(); + AllocTracer.Start(Options.TraceMalloc); UnitStartTime = system_clock::now(); ResetCounters(); // Reset coverage right before the callback. TPC.ResetMaps(); |

