summaryrefslogtreecommitdiff
path: root/lib/fuzzer/FuzzerTracePC.cpp
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2018-05-16 23:26:37 +0000
committerKostya Serebryany <kcc@google.com>2018-05-16 23:26:37 +0000
commite7a38f86feb619a9bcd31871559f6455e21748bf (patch)
tree585603398b256d9374e0c55eadd8100f7067a585 /lib/fuzzer/FuzzerTracePC.cpp
parent851bfbce9fffe4a357445f9780331c7590b9f0aa (diff)
downloadcompiler-rt-e7a38f86feb619a9bcd31871559f6455e21748bf.tar.gz
[libFuzzer] add an experimental flag -focus_function: libFuzzer will try to focus on inputs that trigger that function
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@332554 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/fuzzer/FuzzerTracePC.cpp')
-rw-r--r--lib/fuzzer/FuzzerTracePC.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/fuzzer/FuzzerTracePC.cpp b/lib/fuzzer/FuzzerTracePC.cpp
index 20230d496..ed62cdcf4 100644
--- a/lib/fuzzer/FuzzerTracePC.cpp
+++ b/lib/fuzzer/FuzzerTracePC.cpp
@@ -229,6 +229,39 @@ void TracePC::IterateCoveredFunctions(CallBack CB) {
}
}
+void TracePC::SetFocusFunction(const std::string &FuncName) {
+ // This function should be called once.
+ assert(FocusFunction.first > NumModulesWithInline8bitCounters);
+ if (FuncName.empty())
+ return;
+ for (size_t M = 0; M < NumModulesWithInline8bitCounters; M++) {
+ auto &PCTE = ModulePCTable[M];
+ size_t N = PCTE.Stop - PCTE.Start;
+ for (size_t I = 0; I < N; I++) {
+ if (!(PCTE.Start[I].PCFlags & 1)) continue; // not a function entry.
+ auto Name = DescribePC("%F", GetNextInstructionPc(PCTE.Start[I].PC));
+ if (Name[0] == 'i' && Name[1] == 'n' && Name[2] == ' ')
+ Name = Name.substr(3, std::string::npos);
+ if (FuncName != Name) continue;
+ Printf("INFO: Focus function is set to '%s'\n", Name.c_str());
+ FocusFunction = {M, I};
+ return;
+ }
+ }
+}
+
+bool TracePC::ObservedFocusFunction() {
+ size_t I = FocusFunction.first;
+ size_t J = FocusFunction.second;
+ if (I >= NumModulesWithInline8bitCounters)
+ return false;
+ auto &MC = ModuleCounters[I];
+ size_t Size = MC.Stop - MC.Start;
+ if (J >= Size)
+ return false;
+ return MC.Start[J] != 0;
+}
+
void TracePC::PrintCoverage() {
if (!EF->__sanitizer_symbolize_pc ||
!EF->__sanitizer_get_module_and_offset_for_pc) {