Mercurial > hg > CbC > CbC_llvm
comparison tools/llvm-cov/TestingSupport.cpp @ 122:36195a0db682
merging ( incomplete )
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Nov 2017 20:32:31 +0900 |
parents | 803732b1fca8 |
children | c2174574ed3a |
comparison
equal
deleted
inserted
replaced
119:d9df2cbd60cd | 122:36195a0db682 |
---|---|
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 | 9 |
10 #include "llvm/Object/ObjectFile.h" | 10 #include "llvm/Object/ObjectFile.h" |
11 #include "llvm/ProfileData/InstrProf.h" | |
11 #include "llvm/Support/CommandLine.h" | 12 #include "llvm/Support/CommandLine.h" |
12 #include "llvm/Support/LEB128.h" | 13 #include "llvm/Support/LEB128.h" |
13 #include "llvm/Support/ManagedStatic.h" | |
14 #include "llvm/Support/PrettyStackTrace.h" | |
15 #include "llvm/Support/Signals.h" | |
16 #include "llvm/Support/raw_ostream.h" | 14 #include "llvm/Support/raw_ostream.h" |
17 #include <functional> | 15 #include <functional> |
18 #include <system_error> | 16 #include <system_error> |
19 | 17 |
20 using namespace llvm; | 18 using namespace llvm; |
21 using namespace object; | 19 using namespace object; |
22 | 20 |
23 int convertForTestingMain(int argc, const char *argv[]) { | 21 int convertForTestingMain(int argc, const char *argv[]) { |
24 sys::PrintStackTraceOnErrorSignal(); | |
25 PrettyStackTraceProgram X(argc, argv); | |
26 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. | |
27 | |
28 cl::opt<std::string> InputSourceFile(cl::Positional, cl::Required, | 22 cl::opt<std::string> InputSourceFile(cl::Positional, cl::Required, |
29 cl::desc("<Source file>")); | 23 cl::desc("<Source file>")); |
30 | 24 |
31 cl::opt<std::string> OutputFilename( | 25 cl::opt<std::string> OutputFilename( |
32 "o", cl::Required, | 26 "o", cl::Required, |
34 "File with the profile data obtained after an instrumented run")); | 28 "File with the profile data obtained after an instrumented run")); |
35 | 29 |
36 cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n"); | 30 cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n"); |
37 | 31 |
38 auto ObjErr = llvm::object::ObjectFile::createObjectFile(InputSourceFile); | 32 auto ObjErr = llvm::object::ObjectFile::createObjectFile(InputSourceFile); |
39 if (auto Err = ObjErr.getError()) { | 33 if (!ObjErr) { |
40 errs() << "error: " << Err.message() << "\n"; | 34 std::string Buf; |
35 raw_string_ostream OS(Buf); | |
36 logAllUnhandledErrors(ObjErr.takeError(), OS, ""); | |
37 OS.flush(); | |
38 errs() << "error: " << Buf; | |
41 return 1; | 39 return 1; |
42 } | 40 } |
43 ObjectFile *OF = ObjErr.get().getBinary(); | 41 ObjectFile *OF = ObjErr.get().getBinary(); |
44 auto BytesInAddress = OF->getBytesInAddress(); | 42 auto BytesInAddress = OF->getBytesInAddress(); |
45 if (BytesInAddress != 8) { | 43 if (BytesInAddress != 8) { |
48 } | 46 } |
49 | 47 |
50 // Look for the sections that we are interested in. | 48 // Look for the sections that we are interested in. |
51 int FoundSectionCount = 0; | 49 int FoundSectionCount = 0; |
52 SectionRef ProfileNames, CoverageMapping; | 50 SectionRef ProfileNames, CoverageMapping; |
51 auto ObjFormat = OF->getTripleObjectFormat(); | |
53 for (const auto &Section : OF->sections()) { | 52 for (const auto &Section : OF->sections()) { |
54 StringRef Name; | 53 StringRef Name; |
55 if (Section.getName(Name)) | 54 if (Section.getName(Name)) |
56 return 1; | 55 return 1; |
57 if (Name == "__llvm_prf_names") { | 56 if (Name == llvm::getInstrProfSectionName(IPSK_name, ObjFormat, |
57 /*AddSegmentInfo=*/false)) { | |
58 ProfileNames = Section; | 58 ProfileNames = Section; |
59 } else if (Name == "__llvm_covmap") { | 59 } else if (Name == llvm::getInstrProfSectionName( |
60 IPSK_covmap, ObjFormat, /*AddSegmentInfo=*/false)) { | |
60 CoverageMapping = Section; | 61 CoverageMapping = Section; |
61 } else | 62 } else |
62 continue; | 63 continue; |
63 ++FoundSectionCount; | 64 ++FoundSectionCount; |
64 } | 65 } |
82 | 83 |
83 raw_fd_ostream OS(FD, true); | 84 raw_fd_ostream OS(FD, true); |
84 OS << "llvmcovmtestdata"; | 85 OS << "llvmcovmtestdata"; |
85 encodeULEB128(ProfileNamesData.size(), OS); | 86 encodeULEB128(ProfileNamesData.size(), OS); |
86 encodeULEB128(ProfileNamesAddress, OS); | 87 encodeULEB128(ProfileNamesAddress, OS); |
87 OS << ProfileNamesData << CoverageMappingData; | 88 OS << ProfileNamesData; |
89 // Coverage mapping data is expected to have an alignment of 8. | |
90 for (unsigned Pad = OffsetToAlignment(OS.tell(), 8); Pad; --Pad) | |
91 OS.write(uint8_t(0)); | |
92 OS << CoverageMappingData; | |
88 | 93 |
89 return 0; | 94 return 0; |
90 } | 95 } |