[analyzer] Add debug helper LocationContext::dumpStack().
authorJordan Rose <jordan_rose@apple.com>
Sat, 30 Mar 2013 01:31:35 +0000 (01:31 +0000)
committerJordan Rose <jordan_rose@apple.com>
Sat, 30 Mar 2013 01:31:35 +0000 (01:31 +0000)
Sample output:
  #0 void construct(pointer __p, llvm::ImutAVLTree<llvm::ImutContainerInfo<clang::ento::BugType *> > *const &__val)
  #1 void push_back(const value_type &__x)
  #2 void destroy()
  #3 void release()
  #4 void ~ImmutableSet()

llvm-svn: 178400

clang/include/clang/Analysis/AnalysisContext.h
clang/lib/Analysis/AnalysisDeclContext.cpp

index 59140d4..46d7d07 100644 (file)
@@ -256,6 +256,8 @@ public:
 
   virtual void Profile(llvm::FoldingSetNodeID &ID) = 0;
 
+  LLVM_ATTRIBUTE_USED void dumpStack() const;
+
 public:
   static void ProfileCommon(llvm::FoldingSetNodeID &ID,
                             ContextKind ck,
index ebbafbf..5ff7842 100644 (file)
@@ -28,6 +28,7 @@
 #include "clang/Analysis/Support/BumpVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/SaveAndRestore.h"
 
 using namespace clang;
@@ -386,6 +387,31 @@ bool LocationContext::isParentOf(const LocationContext *LC) const {
   return false;
 }
 
+void LocationContext::dumpStack() const {
+  ASTContext &Ctx = getAnalysisDeclContext()->getASTContext();
+  PrintingPolicy PP(Ctx.getLangOpts());
+  PP.TerseOutput = 1;
+
+  unsigned Frame = 0;
+  for (const LocationContext *LCtx = this; LCtx; LCtx = LCtx->getParent()) {
+    switch (LCtx->getKind()) {
+    case StackFrame:
+      llvm::errs() << '#' << Frame++ << ' ';
+      cast<StackFrameContext>(LCtx)->getDecl()->print(llvm::errs(), PP);
+      llvm::errs() << '\n';
+      break;
+    case Scope:
+      llvm::errs() << "    (scope)\n";
+      break;
+    case Block:
+      llvm::errs() << "    (block context: "
+                   << cast<BlockInvocationContext>(LCtx)->getContextData()
+                   << ")\n";
+      break;
+    }
+  }
+}
+
 //===----------------------------------------------------------------------===//
 // Lazily generated map to query the external variables referenced by a Block.
 //===----------------------------------------------------------------------===//