1 //==- DebugCheckers.cpp - Debugging Checkers ---------------------*- C++ -*-==// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines a checkers that display debugging information. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "ClangSACheckers.h" 15 #include "clang/StaticAnalyzer/Core/Checker.h" 16 #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h" 17 #include "clang/Analysis/Analyses/LiveVariables.h" 18 #include "clang/Analysis/Analyses/Dominators.h" 19 20 using namespace clang; 21 using namespace ento; 22 23 //===----------------------------------------------------------------------===// 24 // DominatorsTreeDumper 25 //===----------------------------------------------------------------------===// 26 27 namespace { 28 class DominatorsTreeDumper : public Checker<check::ASTCodeBody> { 29 public: 30 void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, 31 BugReporter &BR) const { 32 if (AnalysisDeclContext *AC = mgr.getAnalysisDeclContext(D)) { 33 DominatorTree dom; 34 dom.buildDominatorTree(*AC); 35 dom.dump(); 36 } 37 } 38 }; 39 } 40 41 void ento::registerDominatorsTreeDumper(CheckerManager &mgr) { 42 mgr.registerChecker<DominatorsTreeDumper>(); 43 } 44 45 //===----------------------------------------------------------------------===// 46 // LiveVariablesDumper 47 //===----------------------------------------------------------------------===// 48 49 namespace { 50 class LiveVariablesDumper : public Checker<check::ASTCodeBody> { 51 public: 52 void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, 53 BugReporter &BR) const { 54 if (LiveVariables* L = mgr.getAnalysis<LiveVariables>(D)) { 55 L->dumpBlockLiveness(mgr.getSourceManager()); 56 } 57 } 58 }; 59 } 60 61 void ento::registerLiveVariablesDumper(CheckerManager &mgr) { 62 mgr.registerChecker<LiveVariablesDumper>(); 63 } 64 65 //===----------------------------------------------------------------------===// 66 // CFGViewer 67 //===----------------------------------------------------------------------===// 68 69 namespace { 70 class CFGViewer : public Checker<check::ASTCodeBody> { 71 public: 72 void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, 73 BugReporter &BR) const { 74 if (CFG *cfg = mgr.getCFG(D)) { 75 cfg->viewCFG(mgr.getLangOptions()); 76 } 77 } 78 }; 79 } 80 81 void ento::registerCFGViewer(CheckerManager &mgr) { 82 mgr.registerChecker<CFGViewer>(); 83 } 84 85 //===----------------------------------------------------------------------===// 86 // CFGDumper 87 //===----------------------------------------------------------------------===// 88 89 namespace { 90 class CFGDumper : public Checker<check::ASTCodeBody> { 91 public: 92 void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, 93 BugReporter &BR) const { 94 if (CFG *cfg = mgr.getCFG(D)) { 95 cfg->dump(mgr.getLangOptions()); 96 } 97 } 98 }; 99 } 100 101 void ento::registerCFGDumper(CheckerManager &mgr) { 102 mgr.registerChecker<CFGDumper>(); 103 } 104