]> granicus.if.org Git - clang/commitdiff
[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()

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

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

index 59140d4736db3fe57749cacc2c2c87655efc23bc..46d7d07e090720c3637467976a42dc3c75f56841 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 ebbafbf4a9ac3c6982c43bf97178a8817f9ef44c..5ff7842407a9a63a312b3c93af0e0eac0fef2a4c 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.
 //===----------------------------------------------------------------------===//