]> granicus.if.org Git - clang/commitdiff
[VFS] Add dump methods to the VFS overlay tree
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Fri, 6 May 2016 23:21:57 +0000 (23:21 +0000)
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Fri, 6 May 2016 23:21:57 +0000 (23:21 +0000)
Useful when debugging issues within the VFS overlay.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@268820 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/VirtualFileSystem.cpp

index be7a637a73e314cfb98a491e77165c1986574445..7cffabc67de0d6fadf0a97ce049b31c345301b50 100644 (file)
@@ -16,6 +16,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Debug.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
@@ -920,6 +921,29 @@ public:
     return ExternalContentsPrefixDir;
   }
 
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+LLVM_DUMP_METHOD void dump() const {
+    for (const std::unique_ptr<Entry> &Root : Roots)
+      dumpEntry(Root.get());
+  }
+
+LLVM_DUMP_METHOD void dumpEntry(Entry *E, int NumSpaces = 0) const {
+    StringRef Name = E->getName();
+    for (int i = 0, e = NumSpaces; i < e; ++i)
+      dbgs() << " ";
+    dbgs() << "'" << Name.str().c_str() << "'" << "\n";
+
+    if (E->getKind() == EK_Directory) {
+      auto *DE = dyn_cast<RedirectingDirectoryEntry>(E);
+      assert(DE && "Should be a directory");
+
+      for (std::unique_ptr<Entry> &SubEntry :
+           llvm::make_range(DE->contents_begin(), DE->contents_end()))
+        dumpEntry(SubEntry.get(), NumSpaces+2);
+    }
+  }
+#endif
+
 };
 
 /// \brief A helper class to hold the common YAML parsing state.