1 //===- 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 //===----------------------------------------------------------------------===//
10 // llvm-cov is a command line tools to analyze and report coverage information.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/ADT/OwningPtr.h"
15 #include "llvm/Support/CommandLine.h"
16 #include "llvm/Support/GCOV.h"
17 #include "llvm/Support/ManagedStatic.h"
18 #include "llvm/Support/MemoryObject.h"
19 #include "llvm/Support/PrettyStackTrace.h"
20 #include "llvm/Support/Signals.h"
21 #include "llvm/Support/system_error.h"
25 DumpGCOV("dump", cl::init(false), cl::desc("dump gcov file"));
27 static cl::opt<std::string>
28 InputGCNO("gcno", cl::desc("<input gcno file>"), cl::init(""));
30 static cl::opt<std::string>
31 InputGCDA("gcda", cl::desc("<input gcda file>"), cl::init(""));
34 AllBlocks("a", cl::init(false), cl::desc("display all block info"));
37 BranchProb("b", cl::init(false), cl::desc("display branch info"));
40 UncondBranch("u", cl::init(false), cl::desc("display unconditional branch info \
41 (only works with -b)"));
43 //===----------------------------------------------------------------------===//
44 int main(int argc, char **argv) {
45 // Print a stack trace if we signal out.
46 sys::PrintStackTraceOnErrorSignal();
47 PrettyStackTraceProgram X(argc, argv);
48 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
50 cl::ParseCommandLineOptions(argc, argv, "llvm coverage tool\n");
53 if (InputGCNO.empty())
54 errs() << " " << argv[0] << ": No gcov input file!\n";
56 OwningPtr<MemoryBuffer> GCNO_Buff;
57 if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, GCNO_Buff)) {
58 errs() << InputGCNO << ": " << ec.message() << "\n";
61 GCOVBuffer GCNO_GB(GCNO_Buff.get());
62 if (!GF.readGCNO(GCNO_GB)) {
63 errs() << "Invalid .gcno File!\n";
67 if (!InputGCDA.empty()) {
68 OwningPtr<MemoryBuffer> GCDA_Buff;
69 if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) {
70 errs() << InputGCDA << ": " << ec.message() << "\n";
73 GCOVBuffer GCDA_GB(GCDA_Buff.get());
74 if (!GF.readGCDA(GCDA_GB)) {
75 errs() << "Invalid .gcda File!\n";
83 GCOVOptions Options(AllBlocks, BranchProb, UncondBranch);
85 GF.collectLineCounts(FI);
86 FI.print(InputGCNO, InputGCDA);