1 //===- tools/llvm-cov/llvm-cov.cpp - LLVM coverage tool -------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 // llvm-cov is a command line tools to analyze and report coverage information.
14 //===----------------------------------------------------------------------===//
16 #include "GCOVReader.h"
17 #include "llvm/ADT/OwningPtr.h"
18 #include "llvm/Support/CommandLine.h"
19 #include "llvm/Support/ManagedStatic.h"
20 #include "llvm/Support/MemoryObject.h"
21 #include "llvm/Support/PrettyStackTrace.h"
22 #include "llvm/Support/Signals.h"
23 #include "llvm/Support/system_error.h"
27 DumpGCOV("dump", cl::init(false), cl::desc("dump gcov file"));
29 static cl::opt<std::string>
30 InputGCNO("gcno", cl::desc("<input gcno file>"), cl::init(""));
32 static cl::opt<std::string>
33 InputGCDA("gcda", cl::desc("<input gcda file>"), cl::init(""));
36 //===----------------------------------------------------------------------===//
37 int main(int argc, char **argv) {
38 // Print a stack trace if we signal out.
39 sys::PrintStackTraceOnErrorSignal();
40 PrettyStackTraceProgram X(argc, argv);
41 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
43 cl::ParseCommandLineOptions(argc, argv, "llvm cov\n");
47 if (InputGCNO.empty())
48 errs() << " " << argv[0] << ": No gcov input file!\n";
50 OwningPtr<MemoryBuffer> Buff;
51 if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, Buff)) {
52 errs() << InputGCNO << ": " << ec.message() << "\n";
55 GCOVBuffer GB(Buff.take());
58 errs() << "Invalid .gcno File!\n";
62 if (!InputGCDA.empty()) {
63 OwningPtr<MemoryBuffer> Buff2;
64 if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, Buff2)) {
65 errs() << InputGCDA << ": " << ec.message() << "\n";
68 GCOVBuffer GB2(Buff2.take());
71 errs() << "Invalid .gcda File!\n";
81 GF.collectLineCounts(FI);