mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-24 20:29:53 +00:00
llvm-cov: Split GCOVFile's read into GCNO and GCDA.
This splits the file-scope read() function into readGCNO() and readGCDA(). Also broke file format read into functions that first read the file type, then check the version. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196353 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
045d547516
commit
812ad83e58
@ -28,12 +28,9 @@ class GCOVBlock;
|
|||||||
class FileInfo;
|
class FileInfo;
|
||||||
|
|
||||||
namespace GCOV {
|
namespace GCOV {
|
||||||
enum GCOVFormat {
|
enum GCOVVersion {
|
||||||
InvalidGCOV,
|
V402,
|
||||||
GCNO_402,
|
V404
|
||||||
GCNO_404,
|
|
||||||
GCDA_402,
|
|
||||||
GCDA_404
|
|
||||||
};
|
};
|
||||||
} // end GCOV namespace
|
} // end GCOV namespace
|
||||||
|
|
||||||
@ -43,21 +40,43 @@ class GCOVBuffer {
|
|||||||
public:
|
public:
|
||||||
GCOVBuffer(MemoryBuffer *B) : Buffer(B), Cursor(0) {}
|
GCOVBuffer(MemoryBuffer *B) : Buffer(B), Cursor(0) {}
|
||||||
|
|
||||||
/// readGCOVFormat - Read GCOV signature at the beginning of buffer.
|
/// readGCNOFormat - Check GCNO signature is valid at the beginning of buffer.
|
||||||
GCOV::GCOVFormat readGCOVFormat() {
|
bool readGCNOFormat() {
|
||||||
StringRef Magic = Buffer->getBuffer().slice(0, 8);
|
StringRef File = Buffer->getBuffer().slice(0, 4);
|
||||||
Cursor = 8;
|
if (File != "oncg") {
|
||||||
if (Magic == "oncg*404")
|
errs() << "Unexpected file type: " << File << ".\n";
|
||||||
return GCOV::GCNO_404;
|
return false;
|
||||||
else if (Magic == "oncg*204")
|
}
|
||||||
return GCOV::GCNO_402;
|
Cursor = 4;
|
||||||
else if (Magic == "adcg*404")
|
return true;
|
||||||
return GCOV::GCDA_404;
|
}
|
||||||
else if (Magic == "adcg*204")
|
|
||||||
return GCOV::GCDA_402;
|
/// readGCDAFormat - Check GCDA signature is valid at the beginning of buffer.
|
||||||
|
bool readGCDAFormat() {
|
||||||
Cursor = 0;
|
StringRef File = Buffer->getBuffer().slice(0, 4);
|
||||||
return GCOV::InvalidGCOV;
|
if (File != "adcg") {
|
||||||
|
errs() << "Unexpected file type: " << File << ".\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Cursor = 4;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// readGCOVVersion - Read GCOV version.
|
||||||
|
bool readGCOVVersion(GCOV::GCOVVersion &Version) {
|
||||||
|
StringRef VersionStr = Buffer->getBuffer().slice(Cursor, Cursor+4);
|
||||||
|
if (VersionStr == "*204") {
|
||||||
|
Cursor += 4;
|
||||||
|
Version = GCOV::V402;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (VersionStr == "*404") {
|
||||||
|
Cursor += 4;
|
||||||
|
Version = GCOV::V404;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
errs() << "Unexpected version: " << VersionStr << ".\n";
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// readFunctionTag - If cursor points to a function tag then increment the
|
/// readFunctionTag - If cursor points to a function tag then increment the
|
||||||
@ -193,12 +212,16 @@ private:
|
|||||||
/// (.gcno and .gcda).
|
/// (.gcno and .gcda).
|
||||||
class GCOVFile {
|
class GCOVFile {
|
||||||
public:
|
public:
|
||||||
GCOVFile() : Checksum(0), Functions(), RunCount(0), ProgramCount(0) {}
|
GCOVFile() : gcnoInitialized(false), Checksum(0), Functions(), RunCount(0),
|
||||||
|
ProgramCount(0) {}
|
||||||
~GCOVFile();
|
~GCOVFile();
|
||||||
bool read(GCOVBuffer &Buffer);
|
bool readGCNO(GCOVBuffer &Buffer);
|
||||||
|
bool readGCDA(GCOVBuffer &Buffer);
|
||||||
void dump() const;
|
void dump() const;
|
||||||
void collectLineCounts(FileInfo &FI);
|
void collectLineCounts(FileInfo &FI);
|
||||||
private:
|
private:
|
||||||
|
bool gcnoInitialized;
|
||||||
|
GCOV::GCOVVersion Version;
|
||||||
uint32_t Checksum;
|
uint32_t Checksum;
|
||||||
SmallVector<GCOVFunction *, 16> Functions;
|
SmallVector<GCOVFunction *, 16> Functions;
|
||||||
uint32_t RunCount;
|
uint32_t RunCount;
|
||||||
@ -218,8 +241,8 @@ class GCOVFunction {
|
|||||||
public:
|
public:
|
||||||
GCOVFunction() : Ident(0), LineNumber(0) {}
|
GCOVFunction() : Ident(0), LineNumber(0) {}
|
||||||
~GCOVFunction();
|
~GCOVFunction();
|
||||||
bool readGCNO(GCOVBuffer &Buffer, GCOV::GCOVFormat Format);
|
bool readGCNO(GCOVBuffer &Buffer, GCOV::GCOVVersion Version);
|
||||||
bool readGCDA(GCOVBuffer &Buffer, GCOV::GCOVFormat Format);
|
bool readGCDA(GCOVBuffer &Buffer, GCOV::GCOVVersion Version);
|
||||||
StringRef getFilename() const { return Filename; }
|
StringRef getFilename() const { return Filename; }
|
||||||
void dump() const;
|
void dump() const;
|
||||||
void collectLineCounts(FileInfo &FI);
|
void collectLineCounts(FileInfo &FI);
|
||||||
|
109
lib/IR/GCOV.cpp
109
lib/IR/GCOV.cpp
@ -29,61 +29,64 @@ GCOVFile::~GCOVFile() {
|
|||||||
DeleteContainerPointers(Functions);
|
DeleteContainerPointers(Functions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// isGCDAFile - Return true if Format identifies a .gcda file.
|
/// readGCNO - Read GCNO buffer.
|
||||||
static bool isGCDAFile(GCOV::GCOVFormat Format) {
|
bool GCOVFile::readGCNO(GCOVBuffer &Buffer) {
|
||||||
return Format == GCOV::GCDA_402 || Format == GCOV::GCDA_404;
|
if (!Buffer.readGCNOFormat()) return false;
|
||||||
|
if (!Buffer.readGCOVVersion(Version)) return false;
|
||||||
|
|
||||||
|
if (!Buffer.readInt(Checksum)) return false;
|
||||||
|
while (true) {
|
||||||
|
if (!Buffer.readFunctionTag()) break;
|
||||||
|
GCOVFunction *GFun = new GCOVFunction();
|
||||||
|
if (!GFun->readGCNO(Buffer, Version))
|
||||||
|
return false;
|
||||||
|
Functions.push_back(GFun);
|
||||||
|
}
|
||||||
|
|
||||||
|
gcnoInitialized = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// isGCNOFile - Return true if Format identifies a .gcno file.
|
/// readGCDA - Read GCDA buffer. It is required that readGCDA() can only be
|
||||||
static bool isGCNOFile(GCOV::GCOVFormat Format) {
|
/// called after readGCNO().
|
||||||
return Format == GCOV::GCNO_402 || Format == GCOV::GCNO_404;
|
bool GCOVFile::readGCDA(GCOVBuffer &Buffer) {
|
||||||
}
|
assert(gcnoInitialized && "readGCDA() can only be called after readGCNO()");
|
||||||
|
if (!Buffer.readGCDAFormat()) return false;
|
||||||
/// read - Read GCOV buffer.
|
GCOV::GCOVVersion GCDAVersion;
|
||||||
bool GCOVFile::read(GCOVBuffer &Buffer) {
|
if (!Buffer.readGCOVVersion(GCDAVersion)) return false;
|
||||||
GCOV::GCOVFormat Format = Buffer.readGCOVFormat();
|
if (Version != GCDAVersion) {
|
||||||
if (Format == GCOV::InvalidGCOV)
|
errs() << "GCOV versions do not match.\n";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (isGCNOFile(Format)) {
|
uint32_t GCDAChecksum;
|
||||||
if (!Buffer.readInt(Checksum)) return false;
|
if (!Buffer.readInt(GCDAChecksum)) return false;
|
||||||
while (true) {
|
if (Checksum != GCDAChecksum) {
|
||||||
if (!Buffer.readFunctionTag()) break;
|
errs() << "File checksum does not match.\n";
|
||||||
GCOVFunction *GFun = new GCOVFunction();
|
return false;
|
||||||
if (!GFun->readGCNO(Buffer, Format))
|
}
|
||||||
return false;
|
for (size_t i = 0, e = Functions.size(); i < e; ++i) {
|
||||||
Functions.push_back(GFun);
|
if (!Buffer.readFunctionTag()) {
|
||||||
}
|
errs() << "Unexpected number of functions.\n";
|
||||||
} else if (isGCDAFile(Format)) {
|
|
||||||
uint32_t Checksum2;
|
|
||||||
if (!Buffer.readInt(Checksum2)) return false;
|
|
||||||
if (Checksum != Checksum2) {
|
|
||||||
errs() << "File checksum does not match.\n";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (size_t i = 0, e = Functions.size(); i < e; ++i) {
|
if (!Functions[i]->readGCDA(Buffer, Version))
|
||||||
if (!Buffer.readFunctionTag()) {
|
return false;
|
||||||
errs() << "Unexpected number of functions.\n";
|
}
|
||||||
return false;
|
if (Buffer.readObjectTag()) {
|
||||||
}
|
uint32_t Length;
|
||||||
if (!Functions[i]->readGCDA(Buffer, Format))
|
uint32_t Dummy;
|
||||||
return false;
|
if (!Buffer.readInt(Length)) return false;
|
||||||
}
|
if (!Buffer.readInt(Dummy)) return false; // checksum
|
||||||
if (Buffer.readObjectTag()) {
|
if (!Buffer.readInt(Dummy)) return false; // num
|
||||||
uint32_t Length;
|
if (!Buffer.readInt(RunCount)) return false;;
|
||||||
uint32_t Dummy;
|
Buffer.advanceCursor(Length-3);
|
||||||
if (!Buffer.readInt(Length)) return false;
|
}
|
||||||
if (!Buffer.readInt(Dummy)) return false; // checksum
|
while (Buffer.readProgramTag()) {
|
||||||
if (!Buffer.readInt(Dummy)) return false; // num
|
uint32_t Length;
|
||||||
if (!Buffer.readInt(RunCount)) return false;;
|
if (!Buffer.readInt(Length)) return false;
|
||||||
Buffer.advanceCursor(Length-3);
|
Buffer.advanceCursor(Length);
|
||||||
}
|
++ProgramCount;
|
||||||
while (Buffer.readProgramTag()) {
|
|
||||||
uint32_t Length;
|
|
||||||
if (!Buffer.readInt(Length)) return false;
|
|
||||||
Buffer.advanceCursor(Length);
|
|
||||||
++ProgramCount;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -117,12 +120,12 @@ GCOVFunction::~GCOVFunction() {
|
|||||||
|
|
||||||
/// readGCNO - Read a function from the GCNO buffer. Return false if an error
|
/// readGCNO - Read a function from the GCNO buffer. Return false if an error
|
||||||
/// occurs.
|
/// occurs.
|
||||||
bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVFormat Format) {
|
bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
|
||||||
uint32_t Dummy;
|
uint32_t Dummy;
|
||||||
if (!Buff.readInt(Dummy)) return false; // Function header length
|
if (!Buff.readInt(Dummy)) return false; // Function header length
|
||||||
if (!Buff.readInt(Ident)) return false;
|
if (!Buff.readInt(Ident)) return false;
|
||||||
if (!Buff.readInt(Dummy)) return false; // Checksum #1
|
if (!Buff.readInt(Dummy)) return false; // Checksum #1
|
||||||
if (Format != GCOV::GCNO_402)
|
if (Version != GCOV::V402)
|
||||||
if (!Buff.readInt(Dummy)) return false; // Checksum #2
|
if (!Buff.readInt(Dummy)) return false; // Checksum #2
|
||||||
|
|
||||||
if (!Buff.readString(Name)) return false;
|
if (!Buff.readString(Name)) return false;
|
||||||
@ -198,12 +201,12 @@ bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVFormat Format) {
|
|||||||
|
|
||||||
/// readGCDA - Read a function from the GCDA buffer. Return false if an error
|
/// readGCDA - Read a function from the GCDA buffer. Return false if an error
|
||||||
/// occurs.
|
/// occurs.
|
||||||
bool GCOVFunction::readGCDA(GCOVBuffer &Buff, GCOV::GCOVFormat Format) {
|
bool GCOVFunction::readGCDA(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
|
||||||
uint32_t Dummy;
|
uint32_t Dummy;
|
||||||
if (!Buff.readInt(Dummy)) return false; // Function header length
|
if (!Buff.readInt(Dummy)) return false; // Function header length
|
||||||
if (!Buff.readInt(Ident)) return false;
|
if (!Buff.readInt(Ident)) return false;
|
||||||
if (!Buff.readInt(Dummy)) return false; // Checksum #1
|
if (!Buff.readInt(Dummy)) return false; // Checksum #1
|
||||||
if (Format != GCOV::GCDA_402)
|
if (Version != GCOV::V402)
|
||||||
if (!Buff.readInt(Dummy)) return false; // Checksum #2
|
if (!Buff.readInt(Dummy)) return false; // Checksum #2
|
||||||
|
|
||||||
if (!Buff.readString(Name)) return false;
|
if (!Buff.readString(Name)) return false;
|
||||||
|
@ -49,7 +49,7 @@ int main(int argc, char **argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
GCOVBuffer GCNO_GB(GCNO_Buff.get());
|
GCOVBuffer GCNO_GB(GCNO_Buff.get());
|
||||||
if (!GF.read(GCNO_GB)) {
|
if (!GF.readGCNO(GCNO_GB)) {
|
||||||
errs() << "Invalid .gcno File!\n";
|
errs() << "Invalid .gcno File!\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ int main(int argc, char **argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
GCOVBuffer GCDA_GB(GCDA_Buff.get());
|
GCOVBuffer GCDA_GB(GCDA_Buff.get());
|
||||||
if (!GF.read(GCDA_GB)) {
|
if (!GF.readGCDA(GCDA_GB)) {
|
||||||
errs() << "Invalid .gcda File!\n";
|
errs() << "Invalid .gcda File!\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user