Yuchen Wu | c3e6424 | 2013-12-05 22:02:29 +0000 | [diff] [blame] | 1 | //===- llvm-cov.cpp - LLVM coverage tool ----------------------------------===// |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 10 | // llvm-cov is a command line tools to analyze and report coverage information. |
| 11 | // |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/OwningPtr.h" |
| 15 | #include "llvm/Support/CommandLine.h" |
Devang Patel | 8dfb655 | 2011-10-04 17:24:48 +0000 | [diff] [blame] | 16 | #include "llvm/Support/GCOV.h" |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 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" |
| 22 | using namespace llvm; |
| 23 | |
| 24 | static cl::opt<bool> |
| 25 | DumpGCOV("dump", cl::init(false), cl::desc("dump gcov file")); |
| 26 | |
| 27 | static cl::opt<std::string> |
| 28 | InputGCNO("gcno", cl::desc("<input gcno file>"), cl::init("")); |
| 29 | |
| 30 | static cl::opt<std::string> |
| 31 | InputGCDA("gcda", cl::desc("<input gcda file>"), cl::init("")); |
| 32 | |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 33 | //===----------------------------------------------------------------------===// |
| 34 | int main(int argc, char **argv) { |
| 35 | // Print a stack trace if we signal out. |
| 36 | sys::PrintStackTraceOnErrorSignal(); |
| 37 | PrettyStackTraceProgram X(argc, argv); |
| 38 | llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
| 39 | |
Yuchen Wu | 9194d7b | 2013-10-31 02:01:24 +0000 | [diff] [blame] | 40 | cl::ParseCommandLineOptions(argc, argv, "llvm coverage tool\n"); |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 41 | |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 42 | GCOVFile GF; |
| 43 | if (InputGCNO.empty()) |
| 44 | errs() << " " << argv[0] << ": No gcov input file!\n"; |
| 45 | |
Devang Patel | a9e8a25 | 2011-09-29 16:46:47 +0000 | [diff] [blame] | 46 | OwningPtr<MemoryBuffer> GCNO_Buff; |
| 47 | if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, GCNO_Buff)) { |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 48 | errs() << InputGCNO << ": " << ec.message() << "\n"; |
| 49 | return 1; |
| 50 | } |
Benjamin Kramer | 67421c1 | 2013-11-15 09:44:17 +0000 | [diff] [blame] | 51 | GCOVBuffer GCNO_GB(GCNO_Buff.get()); |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 52 | if (!GF.readGCNO(GCNO_GB)) { |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 53 | errs() << "Invalid .gcno File!\n"; |
| 54 | return 1; |
| 55 | } |
| 56 | |
| 57 | if (!InputGCDA.empty()) { |
Devang Patel | a9e8a25 | 2011-09-29 16:46:47 +0000 | [diff] [blame] | 58 | OwningPtr<MemoryBuffer> GCDA_Buff; |
| 59 | if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) { |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 60 | errs() << InputGCDA << ": " << ec.message() << "\n"; |
| 61 | return 1; |
| 62 | } |
Benjamin Kramer | 67421c1 | 2013-11-15 09:44:17 +0000 | [diff] [blame] | 63 | GCOVBuffer GCDA_GB(GCDA_Buff.get()); |
Yuchen Wu | bec4e90 | 2013-12-04 04:49:23 +0000 | [diff] [blame] | 64 | if (!GF.readGCDA(GCDA_GB)) { |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 65 | errs() << "Invalid .gcda File!\n"; |
| 66 | return 1; |
| 67 | } |
| 68 | } |
| 69 | |
Yuchen Wu | e68c5f8 | 2013-11-05 01:56:29 +0000 | [diff] [blame] | 70 | |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 71 | if (DumpGCOV) |
| 72 | GF.dump(); |
| 73 | |
| 74 | FileInfo FI; |
| 75 | GF.collectLineCounts(FI); |
Yuchen Wu | 26326ad | 2013-12-03 00:57:11 +0000 | [diff] [blame] | 76 | FI.print(InputGCNO, InputGCDA); |
Devang Patel | 3714065 | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 77 | return 0; |
| 78 | } |