From 8df5c9b5d65beec807e4e77dae2813dd193f77dd Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 2 Aug 2011 11:12:41 +0000 Subject: [PATCH] Add a debugging dump for Module (also emitted as part of the AST reader statistics), to show the local-to-global mappings. The only such mapping we have (at least, for now) is for source location offsets. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136687 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Serialization/ASTReader.h | 6 ++-- lib/Serialization/ASTReader.cpp | 42 ++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index bcf5384bc6..e28179d335 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -176,8 +176,7 @@ enum ModuleKind { /// Each instance of the Module class corresponds to a single AST file, which /// may be a precompiled header, precompiled preamble, or an AST file of some /// sort loaded as the main file, all of which are specific formulations of -/// the general notion of a "module". A module may depend on another module -/// (FIXME: or a set of other modules). +/// the general notion of a "module". A module may depend on another module. class Module { public: Module(ModuleKind Kind); @@ -403,6 +402,9 @@ public: /// \brief List of modules which this module depends on llvm::SetVector Imports; + + /// \brief Dump debugging output for this module. + void dump(); }; /// \brief The manager for modules loaded by the ASTReader. diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 177d4c91af..69fdf10a1a 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -4364,7 +4364,7 @@ dumpModuleIDMap(StringRef Name, } void ASTReader::dump() { - llvm::errs() << "*** AST File Remapping:\n"; + llvm::errs() << "*** PCH/Module Remappings:\n"; dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); dumpModuleIDMap("Global type map", GlobalTypeMap); @@ -4375,6 +4375,12 @@ void ASTReader::dump() { dumpModuleIDMap("Global macro definition map", GlobalMacroDefinitionMap); dumpModuleIDMap("Global preprocessed entity map", GlobalPreprocessedEntityMap); + + llvm::errs() << "\n*** PCH/Modules Loaded:"; + for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(), + MEnd = ModuleMgr.end(); + M != MEnd; ++M) + (*M)->dump(); } /// Return the amount of memory used by memory buffers, breaking down @@ -5477,6 +5483,40 @@ Module::~Module() { delete static_cast(SelectorLookupTable); } +template +static void +dumpLocalRemap(StringRef Name, + const ContinuousRangeMap &Map) { + if (Map.begin() == Map.end()) + return; + + typedef ContinuousRangeMap MapType; + llvm::errs() << " " << Name << ":\n"; + for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); + I != IEnd; ++I) { + llvm::errs() << " " << I->first << " -> " << I->second + << "\n"; + } +} + +void Module::dump() { + llvm::errs() << "\nModule: " << FileName << "\n"; + if (!Imports.empty()) { + llvm::errs() << " Imports: "; + for (unsigned I = 0, N = Imports.size(); I != N; ++I) { + if (I) + llvm::errs() << ", "; + llvm::errs() << Imports[I]->FileName; + } + llvm::errs() << "\n"; + } + + // Remapping tables. + llvm::errs() << " Base source location offset: " << SLocEntryBaseOffset + << '\n'; + dumpLocalRemap("Source location offset map", SLocRemap); +} + Module *ModuleManager::lookup(StringRef Name) { const FileEntry *Entry = FileMgr.getFile(Name); return Modules[Entry];