#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
#include "llvm/DebugInfo/Symbolize/Symbolize.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
#include "llvm/MC/MCInst.h"
#include "llvm/MC/MCInstrAnalysis.h"
#include "llvm/MC/MCInstrInfo.h"
#include "llvm/MC/MCObjectFileInfo.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/Binary.h"
#include "llvm/Object/COFF.h"
#include "llvm/Object/MachO.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/LLVMDriver.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/SHA1.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/SpecialCaseList.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/YAMLParser.h"
#include "llvm/Support/raw_ostream.h"
#include <set>
#include <vector>
usingnamespacellvm;
namespace {
namespace {
usingnamespacellvm::opt;
enum ID { … };
#define PREFIX …
#include "Opts.inc"
#undef PREFIX
static constexpr opt::OptTable::Info InfoTable[] = …;
class SancovOptTable : public opt::GenericOptTable { … };
}
enum ActionType { … };
static ActionType Action;
static std::vector<std::string> ClInputFiles;
static bool ClDemangle;
static bool ClSkipDeadFiles;
static bool ClUseDefaultIgnorelist;
static std::string ClStripPathPrefix;
static std::string ClIgnorelist;
static const char *const DefaultIgnorelistStr = …;
struct FileHeader { … };
static const uint32_t BinCoverageMagic = …;
static const uint32_t Bitness32 = …;
static const uint32_t Bitness64 = …;
static const Regex SancovFileRegex("(.*)\\.[0-9]+\\.sancov");
static const Regex SymcovFileRegex(".*\\.symcov");
struct RawCoverage { … };
struct CoveragePoint { … };
struct SymbolizedCoverage { … };
struct CoverageStats { … };
static void fail(const llvm::Twine &E) { … }
static void failIf(bool B, const llvm::Twine &E) { … }
static void failIfError(std::error_code Error) { … }
template <typename T> static void failIfError(const ErrorOr<T> &E) { … }
static void failIfError(Error Err) { … }
template <typename T> static void failIfError(Expected<T> &E) { … }
static void failIfNotEmpty(const llvm::Twine &E) { … }
template <typename T>
static void failIfEmpty(const std::unique_ptr<T> &Ptr,
const std::string &Message) { … }
template <typename T>
static void readInts(const char *Start, const char *End,
std::set<uint64_t> *Ints) { … }
ErrorOr<std::unique_ptr<RawCoverage>>
RawCoverage::read(const std::string &FileName) { … }
raw_ostream &operator<<(raw_ostream &OS, const RawCoverage &CoverageData) { … }
static raw_ostream &operator<<(raw_ostream &OS, const CoverageStats &Stats) { … }
static void operator<<(json::OStream &W,
const std::vector<CoveragePoint> &Points) { … }
static void operator<<(json::OStream &W, const SymbolizedCoverage &C) { … }
static std::string parseScalarString(yaml::Node *N) { … }
std::unique_ptr<SymbolizedCoverage>
SymbolizedCoverage::read(const std::string &InputFile) { … }
std::string stripPathPrefix(std::string Path) { … }
static std::unique_ptr<symbolize::LLVMSymbolizer> createSymbolizer() { … }
static std::string normalizeFilename(const std::string &FileName) { … }
class Ignorelists { … };
static std::vector<CoveragePoint>
getCoveragePoints(const std::string &ObjectFile,
const std::set<uint64_t> &Addrs,
const std::set<uint64_t> &CoveredAddrs) { … }
static bool isCoveragePointSymbol(StringRef Name) { … }
static void findMachOIndirectCovFunctions(const object::MachOObjectFile &O,
std::set<uint64_t> *Result) { … }
static std::set<uint64_t>
findSanitizerCovFunctions(const object::ObjectFile &O) { … }
static uint64_t getPreviousInstructionPc(uint64_t PC, Triple TheTriple) { … }
static void getObjectCoveragePoints(const object::ObjectFile &O,
std::set<uint64_t> *Addrs) { … }
static void
visitObjectFiles(const object::Archive &A,
function_ref<void(const object::ObjectFile &)> Fn) { … }
static void
visitObjectFiles(const std::string &FileName,
function_ref<void(const object::ObjectFile &)> Fn) { … }
static std::set<uint64_t>
findSanitizerCovFunctions(const std::string &FileName) { … }
static std::set<uint64_t> findCoveragePointAddrs(const std::string &FileName) { … }
static void printCovPoints(const std::string &ObjFile, raw_ostream &OS) { … }
static ErrorOr<bool> isCoverageFile(const std::string &FileName) { … }
static bool isSymbolizedCoverageFile(const std::string &FileName) { … }
static std::unique_ptr<SymbolizedCoverage>
symbolize(const RawCoverage &Data, const std::string ObjectFile) { … }
struct FileFn { … };
static std::set<FileFn>
computeFunctions(const std::vector<CoveragePoint> &Points) { … }
static std::set<FileFn>
computeNotCoveredFunctions(const SymbolizedCoverage &Coverage) { … }
static std::set<FileFn>
computeCoveredFunctions(const SymbolizedCoverage &Coverage) { … }
FunctionLocs;
static FunctionLocs resolveFunctions(const SymbolizedCoverage &Coverage,
const std::set<FileFn> &Fns) { … }
static void printFunctionLocs(const FunctionLocs &FnLocs, raw_ostream &OS) { … }
CoverageStats computeStats(const SymbolizedCoverage &Coverage) { … }
static void printCoveredFunctions(const SymbolizedCoverage &CovData,
raw_ostream &OS) { … }
static void printNotCoveredFunctions(const SymbolizedCoverage &CovData,
raw_ostream &OS) { … }
static void readAndPrintRawCoverage(const std::vector<std::string> &FileNames,
raw_ostream &OS) { … }
static std::unique_ptr<SymbolizedCoverage>
merge(const std::vector<std::unique_ptr<SymbolizedCoverage>> &Coverages) { … }
static std::unique_ptr<SymbolizedCoverage>
readSymbolizeAndMergeCmdArguments(std::vector<std::string> FileNames) { … }
}
static void parseArgs(int Argc, char **Argv) { … }
int sancov_main(int Argc, char **Argv, const llvm::ToolContext &) { … }