r178400 - [analyzer] Add debug helper LocationContext::dumpStack().

Jordan Rose jordan_rose at apple.com
Fri Mar 29 18:31:35 PDT 2013


Author: jrose
Date: Fri Mar 29 20:31:35 2013
New Revision: 178400

URL: http://llvm.org/viewvc/llvm-project?rev=178400&view=rev
Log:
[analyzer] Add debug helper LocationContext::dumpStack().

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()

Modified:
    cfe/trunk/include/clang/Analysis/AnalysisContext.h
    cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp

Modified: cfe/trunk/include/clang/Analysis/AnalysisContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/AnalysisContext.h?rev=178400&r1=178399&r2=178400&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/AnalysisContext.h (original)
+++ cfe/trunk/include/clang/Analysis/AnalysisContext.h Fri Mar 29 20:31:35 2013
@@ -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,

Modified: cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp?rev=178400&r1=178399&r2=178400&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp (original)
+++ cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp Fri Mar 29 20:31:35 2013
@@ -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 L
   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.
 //===----------------------------------------------------------------------===//





More information about the cfe-commits mailing list