[libFuzzer] print new functions as they are discovered in the fork mode

git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/fuzzer@354092 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/FuzzerTracePC.cpp b/FuzzerTracePC.cpp
index f5fdbf5..a2d3b7e 100644
--- a/FuzzerTracePC.cpp
+++ b/FuzzerTracePC.cpp
@@ -174,7 +174,7 @@
 
 /// \return the address of the next instruction.
 /// Note: the logic is copied from `sanitizer_common/sanitizer_stacktrace.cc`
-inline ALWAYS_INLINE uintptr_t GetNextInstructionPc(uintptr_t PC) {
+ALWAYS_INLINE uintptr_t TracePC::GetNextInstructionPc(uintptr_t PC) {
 #if defined(__mips__)
   return PC + 8;
 #elif defined(__powerpc__) || defined(__sparc__) || defined(__arm__) || \
@@ -196,7 +196,7 @@
   };
 
   auto Observe = [&](const PCTableEntry *TE) {
-    if (TE->PCFlags & 1)
+    if (PcIsFuncEntry(TE))
       if (++ObservedFuncs[TE->PC] == 1 && NumPrintNewFuncs)
         CoveredFuncs.push_back(TE->PC);
     ObservePC(TE);
@@ -239,6 +239,16 @@
   return 0;
 }
 
+const TracePC::PCTableEntry *TracePC::PCTableEntryByIdx(uintptr_t Idx) {
+  for (size_t i = 0; i < NumPCTables; i++) {
+    auto &M = ModulePCTable[i];
+    size_t Size = M.Stop - M.Start;
+    if (Idx < Size) return &M.Start[Idx];
+    Idx -= Size;
+  }
+  return nullptr;
+}
+
 static std::string GetModuleName(uintptr_t PC) {
   char ModulePathRaw[4096] = "";  // What's PATH_MAX in portable C++?
   void *OffsetRaw = nullptr;
@@ -257,10 +267,10 @@
     auto ModuleName = GetModuleName(M.Start->PC);
     for (auto NextFE = M.Start; NextFE < M.Stop; ) {
       auto FE = NextFE;
-      assert((FE->PCFlags & 1) && "Not a function entry point");
+      assert(PcIsFuncEntry(FE) && "Not a function entry point");
       do {
         NextFE++;
-      } while (NextFE < M.Stop && !(NextFE->PCFlags & 1));
+      } while (NextFE < M.Stop && !(PcIsFuncEntry(NextFE)));
       CB(FE, NextFE, ObservedFuncs[FE->PC]);
     }
   }
@@ -275,7 +285,7 @@
     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.
+      if (!(PcIsFuncEntry(&PCTE.Start[I]))) 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);