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
--- a/build/clang-plugin/mozsearch-plugin/MozsearchIndexer.cpp
+++ b/build/clang-plugin/mozsearch-plugin/MozsearchIndexer.cpp
@@ -64,16 +64,30 @@ static bool isValidIdentifier(std::strin
for (char C : Input) {
if (!(isalpha(C) || isdigit(C) || C == '_')) {
return false;
}
}
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
// FileInfo. This object tracks whether the file is "interesting" (i.e., whether
// it's in the source dir or the objdir). We also store the analysis output
// here.
struct FileInfo {
FileInfo(std::string &Rname) : Realname(Rname) {
@@ -439,32 +453,40 @@ public:
std::vector<std::string> Lines;
// Read all the existing lines in from the output file. Rather than
// overwrite them, we want to merge our results with what was already
// there. This ensures that header files that are included multiple times
// 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));
}
fclose(Fp);
// Insert the newly generated analysis data into what was read. Sort the
// results and then remove duplicates.
Lines.insert(Lines.end(), Info.Output.begin(), Info.Output.end());
std::sort(Lines.begin(), Lines.end());
std::vector<std::string> Nodupes;
std::unique_copy(Lines.begin(), Lines.end(), std::back_inserter(Nodupes));
// 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();
if (fwrite(Line.c_str(), Line.length(), 1, Fp) != 1) {
fprintf(stderr, "Unable to write to output file %s\n", Filename.c_str());
}
}
fclose(Fp);