From 03a06dd13cd27a8241bd7d8509765beb3764fa6c Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 13 Aug 2015 00:45:11 +0000 Subject: [PATCH] Add SourceManager::dump() to dump the current set of SLocEntries. llvm-svn: 244852 --- clang/include/clang/Basic/SourceManager.h | 2 + clang/lib/Basic/SourceManager.cpp | 57 +++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index 3aea5ea9825e..bc10cc836e60 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -1463,6 +1463,8 @@ public: /// void PrintStats() const; + void dump() const; + /// \brief Get the number of local SLocEntries we have. unsigned local_sloc_entry_size() const { return LocalSLocEntryTable.size(); } diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 6c2bd7d2332f..8954c8fb9f0a 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -2135,6 +2135,63 @@ void SourceManager::PrintStats() const { << NumBinaryProbes << " binary.\n"; } +LLVM_DUMP_METHOD void SourceManager::dump() const { + llvm::raw_ostream &out = llvm::errs(); + + auto DumpSLocEntry = [&](int ID, const SrcMgr::SLocEntry &Entry, + llvm::Optional NextStart) { + out << "SLocEntry " << (Entry.isFile() ? "file" : "expansion") + << " \n"; + else + out << "???\?>\n"; + if (Entry.isFile()) { + auto &FI = Entry.getFile(); + if (FI.NumCreatedFIDs) + out << " covers \n"; + if (FI.getIncludeLoc().isValid()) + out << " included from " << FI.getIncludeLoc().getOffset() << "\n"; + if (auto *CC = FI.getContentCache()) { + out << " for " << (CC->OrigEntry ? CC->OrigEntry->getName() : "") + << "\n"; + if (CC->BufferOverridden) + out << " contents overridden\n"; + if (CC->ContentsEntry != CC->OrigEntry) { + out << " contents from " + << (CC->ContentsEntry ? CC->ContentsEntry->getName() : "") + << "\n"; + } + } + } else { + auto &EI = Entry.getExpansion(); + out << " spelling from " << EI.getSpellingLoc().getOffset() << "\n"; + out << " macro " << (EI.isMacroArgExpansion() ? "arg" : "body") + << " range <" << EI.getExpansionLocStart().getOffset() << ":" + << EI.getExpansionLocEnd().getOffset() << ">\n"; + } + }; + + // Dump local SLocEntries. + for (unsigned ID = 0, NumIDs = LocalSLocEntryTable.size(); ID != NumIDs; ++ID) { + DumpSLocEntry(ID, LocalSLocEntryTable[ID], + ID == NumIDs - 1 ? NextLocalOffset + : LocalSLocEntryTable[ID + 1].getOffset()); + } + // Dump loaded SLocEntries. + llvm::Optional NextStart; + for (unsigned Index = 0; Index != LoadedSLocEntryTable.size(); ++Index) { + int ID = -(int)Index - 2; + if (SLocEntryLoaded[Index]) { + DumpSLocEntry(ID, LoadedSLocEntryTable[Index], NextStart); + NextStart = LoadedSLocEntryTable[Index].getOffset(); + } else { + NextStart = None; + } + } +} + ExternalSLocEntrySource::~ExternalSLocEntrySource() { } /// Return the amount of memory used by memory buffers, breaking down