Bug 1438866 - Add some utility code to help with debugging. r=emilio

This adds an RAII class and macro that can be quickly added in functions
to log entry/exit from the function. This is useful to debugging.

MozReview-Commit-ID: 4Ud8jLOxI0R

--HG--
extra : rebase_source : 518d30fe44dff67bffb186e23c1eb858c02280af
This commit is contained in:
Kartikaya Gupta 2018-02-16 17:07:39 -05:00
parent 31c634d913
commit 87bfbc06cf

View File

@ -69,6 +69,20 @@ static bool isValidIdentifier(std::string Input) {
return true;
}
struct RAIITracer {
RAIITracer(const char *log) : mLog(log) {
printf("<%s>\n", mLog);
}
~RAIITracer() {
printf("</%s>\n", mLog);
}
const char* mLog;
};
#define TRACEFUNC RAIITracer tracer(__FUNCTION__);
class IndexConsumer;
// For each C++ file seen by the analysis (.cpp or .h), we track a
@ -444,6 +458,10 @@ public:
// in different ways are analyzed completely.
char Buffer[65536];
FILE *Fp = Lock.openFile("r");
if (!Fp) {
fprintf(stderr, "Unable to open input file %s\n", Filename.c_str());
exit(1);
}
while (fgets(Buffer, sizeof(Buffer), Fp)) {
Lines.push_back(std::string(Buffer));
}
@ -460,6 +478,10 @@ public:
// Overwrite the output file with the merged data. Since we have the lock,
// this will happen atomically.
Fp = Lock.openFile("w");
if (!Fp) {
fprintf(stderr, "Unable to open output file %s\n", Filename.c_str());
exit(1);
}
size_t Length = 0;
for (std::string &Line : Nodupes) {
Length += Line.length();