19 changes: 5 additions & 14 deletions llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,7 @@ static Expected<std::vector<SectionRef>> lookupSections(ObjectFile &OF,

static Expected<std::unique_ptr<BinaryCoverageReader>>
loadBinaryFormat(std::unique_ptr<Binary> Bin, StringRef Arch,
StringRef CompilationDir = "",
std::optional<object::BuildIDRef> *BinaryID = nullptr) {
StringRef CompilationDir = "") {
std::unique_ptr<ObjectFile> OF;
if (auto *Universal = dyn_cast<MachOUniversalBinary>(Bin.get())) {
// If we have a universal binary, try to look up the object for the
Expand Down Expand Up @@ -1053,9 +1052,6 @@ loadBinaryFormat(std::unique_ptr<Binary> Bin, StringRef Arch,
FuncRecords = std::move(WritableBuffer);
}

if (BinaryID)
*BinaryID = getBuildID(OF.get());

return BinaryCoverageReader::createCoverageReaderFromBuffer(
CoverageMapping, std::move(FuncRecords), std::move(ProfileNames),
BytesInAddress, Endian, CompilationDir);
Expand All @@ -1078,7 +1074,7 @@ Expected<std::vector<std::unique_ptr<BinaryCoverageReader>>>
BinaryCoverageReader::create(
MemoryBufferRef ObjectBuffer, StringRef Arch,
SmallVectorImpl<std::unique_ptr<MemoryBuffer>> &ObjectFileBuffers,
StringRef CompilationDir, SmallVectorImpl<object::BuildIDRef> *BinaryIDs) {
StringRef CompilationDir) {
std::vector<std::unique_ptr<BinaryCoverageReader>> Readers;

if (ObjectBuffer.getBuffer().startswith(TestingFormatMagic)) {
Expand Down Expand Up @@ -1118,7 +1114,7 @@ BinaryCoverageReader::create(

return BinaryCoverageReader::create(
ArchiveOrErr.get()->getMemoryBufferRef(), Arch, ObjectFileBuffers,
CompilationDir, BinaryIDs);
CompilationDir);
}
}

Expand All @@ -1131,8 +1127,7 @@ BinaryCoverageReader::create(
return ChildBufOrErr.takeError();

auto ChildReadersOrErr = BinaryCoverageReader::create(
ChildBufOrErr.get(), Arch, ObjectFileBuffers, CompilationDir,
BinaryIDs);
ChildBufOrErr.get(), Arch, ObjectFileBuffers, CompilationDir);
if (!ChildReadersOrErr)
return ChildReadersOrErr.takeError();
for (auto &Reader : ChildReadersOrErr.get())
Expand All @@ -1151,14 +1146,10 @@ BinaryCoverageReader::create(
return std::move(Readers);
}

std::optional<object::BuildIDRef> BinaryID;
auto ReaderOrErr = loadBinaryFormat(std::move(Bin), Arch, CompilationDir,
BinaryIDs ? &BinaryID : nullptr);
auto ReaderOrErr = loadBinaryFormat(std::move(Bin), Arch, CompilationDir);
if (!ReaderOrErr)
return ReaderOrErr.takeError();
Readers.push_back(std::move(ReaderOrErr.get()));
if (BinaryID)
BinaryIDs->push_back(*BinaryID);
return std::move(Readers);
}

Expand Down
2 changes: 0 additions & 2 deletions llvm/tools/llvm-cov/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,3 @@ add_llvm_tool(llvm-cov
SourceCoverageViewText.cpp
TestingSupport.cpp
)

target_link_libraries(llvm-cov PRIVATE LLVMDebuginfod)
30 changes: 6 additions & 24 deletions llvm/tools/llvm-cov/CodeCoverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Debuginfod/BuildIDFetcher.h"
#include "llvm/Debuginfod/Debuginfod.h"
#include "llvm/Debuginfod/HTTPClient.h"
#include "llvm/Object/BuildID.h"
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
#include "llvm/ProfileData/InstrProfReader.h"
#include "llvm/Support/CommandLine.h"
Expand Down Expand Up @@ -183,8 +179,6 @@ class CodeCoverageTool {

/// Allowlist from -name-allowlist to be used for filtering.
std::unique_ptr<SpecialCaseList> NameAllowlist;

std::unique_ptr<object::BuildIDFetcher> BIDFetcher;
};
}

Expand Down Expand Up @@ -441,7 +435,7 @@ std::unique_ptr<CoverageMapping> CodeCoverageTool::load() {
ObjectFilename);
auto CoverageOrErr =
CoverageMapping::load(ObjectFilenames, PGOFilename, CoverageArches,
ViewOpts.CompilationDirectory, BIDFetcher.get());
ViewOpts.CompilationDirectory);
if (Error E = CoverageOrErr.takeError()) {
error("Failed to load coverage: " + toString(std::move(E)));
return nullptr;
Expand Down Expand Up @@ -653,14 +647,6 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
cl::opt<bool> DebugDump("dump", cl::Optional,
cl::desc("Show internal debug dump"));

cl::list<std::string> DebugFileDirectory(
"debug-file-directory",
cl::desc("Directories to search for object files by build ID"));
cl::opt<bool> Debuginfod(
"debuginfod", cl::ZeroOrMore,
cl::desc("Use debuginfod to look up object files from profile"),
cl::init(canUseDebuginfod()));

cl::opt<CoverageViewOptions::OutputFormat> Format(
"format", cl::desc("Output format for line-based coverage reports"),
cl::values(clEnumValN(CoverageViewOptions::OutputFormat::Text, "text",
Expand Down Expand Up @@ -763,18 +749,12 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
auto commandLineParser = [&, this](int argc, const char **argv) -> int {
cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n");
ViewOpts.Debug = DebugDump;
if (Debuginfod) {
HTTPClient::initialize();
BIDFetcher = std::make_unique<DebuginfodFetcher>(DebugFileDirectory);
} else {
BIDFetcher = std::make_unique<object::BuildIDFetcher>(DebugFileDirectory);
}

if (!CovFilename.empty())
ObjectFilenames.emplace_back(CovFilename);
for (const std::string &Filename : CovFilenames)
ObjectFilenames.emplace_back(Filename);
if (ObjectFilenames.empty() && !Debuginfod && DebugFileDirectory.empty()) {
if (ObjectFilenames.empty()) {
errs() << "No filenames specified!\n";
::exit(1);
}
Expand Down Expand Up @@ -887,8 +867,10 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
}
CoverageArches.emplace_back(Arch);
}
if (CoverageArches.size() != 1 &&
CoverageArches.size() != ObjectFilenames.size()) {
if (CoverageArches.size() == 1)
CoverageArches.insert(CoverageArches.end(), ObjectFilenames.size() - 1,
CoverageArches[0]);
if (CoverageArches.size() != ObjectFilenames.size()) {
error("Number of architectures doesn't match the number of objects");
return 1;
}
Expand Down
4 changes: 3 additions & 1 deletion llvm/tools/llvm-objdump/llvm-objdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3198,7 +3198,9 @@ int main(int argc, char **argv) {

// Initialize debuginfod.
const bool ShouldUseDebuginfodByDefault =
InputArgs.hasArg(OBJDUMP_build_id) || canUseDebuginfod();
InputArgs.hasArg(OBJDUMP_build_id) ||
(HTTPClient::isAvailable() &&
!ExitOnErr(getDefaultDebuginfodUrls()).empty());
std::vector<std::string> DebugFileDirectories =
InputArgs.getAllArgValues(OBJDUMP_debug_file_directory);
if (InputArgs.hasFlag(OBJDUMP_debuginfod, OBJDUMP_no_debuginfod,
Expand Down
8 changes: 7 additions & 1 deletion llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,13 @@ int main(int argc, char **argv) {

LLVMSymbolizer Symbolizer(Opts);

if (Args.hasFlag(OPT_debuginfod, OPT_no_debuginfod, canUseDebuginfod()))
// A debuginfod lookup could succeed if a HTTP client is available and at
// least one backing URL is configured.
bool ShouldUseDebuginfodByDefault =
HTTPClient::isAvailable() &&
!ExitOnErr(getDefaultDebuginfodUrls()).empty();
if (Args.hasFlag(OPT_debuginfod, OPT_no_debuginfod,
ShouldUseDebuginfodByDefault))
enableDebuginfod(Symbolizer, Args);

if (Args.hasArg(OPT_filter_markup)) {
Expand Down