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 #include "llvm/Support/Process.h" 20 21 using namespace clang; 22 using namespace ento; 23 24 //===----------------------------------------------------------------------===// 25 // DominatorsTreeDumper 26 //===----------------------------------------------------------------------===// 27 28 namespace { 29 class DominatorsTreeDumper : public Checker<check::ASTCodeBody> { 30 public: 31 void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, 32 BugReporter &BR) const { 33 if (AnalysisDeclContext *AC = mgr.getAnalysisDeclContext(D)) { 34 DominatorTree dom; 35 dom.buildDominatorTree(*AC); 36 dom.dump(); 37 } 38 } 39 }; 40 } 41 42 void ento::registerDominatorsTreeDumper(CheckerManager &mgr) { 43 mgr.registerChecker<DominatorsTreeDumper>(); 44 } 45 46 //===----------------------------------------------------------------------===// 47 // LiveVariablesDumper 48 //===----------------------------------------------------------------------===// 49 50 namespace { 51 class LiveVariablesDumper : public Checker<check::ASTCodeBody> { 52 public: 53 void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, 54 BugReporter &BR) const { 55 if (LiveVariables* L = mgr.getAnalysis<LiveVariables>(D)) { 56 L->dumpBlockLiveness(mgr.getSourceManager()); 57 } 58 } 59 }; 60 } 61 62 void ento::registerLiveVariablesDumper(CheckerManager &mgr) { 63 mgr.registerChecker<LiveVariablesDumper>(); 64 } 65 66 //===----------------------------------------------------------------------===// 67 // CFGViewer 68 //===----------------------------------------------------------------------===// 69 70 namespace { 71 class CFGViewer : public Checker<check::ASTCodeBody> { 72 public: 73 void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, 74 BugReporter &BR) const { 75 if (CFG *cfg = mgr.getCFG(D)) { 76 cfg->viewCFG(mgr.getLangOptions()); 77 } 78 } 79 }; 80 } 81 82 void ento::registerCFGViewer(CheckerManager &mgr) { 83 mgr.registerChecker<CFGViewer>(); 84 } 85 86 //===----------------------------------------------------------------------===// 87 // CFGDumper 88 //===----------------------------------------------------------------------===// 89 90 namespace { 91 class CFGDumper : public Checker<check::ASTCodeBody> { 92 public: 93 void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, 94 BugReporter &BR) const { 95 if (CFG *cfg = mgr.getCFG(D)) { 96 cfg->dump(mgr.getLangOptions(), 97 llvm::sys::Process::StandardErrHasColors()); 98 } 99 } 100 }; 101 } 102 103 void ento::registerCFGDumper(CheckerManager &mgr) { 104 mgr.registerChecker<CFGDumper>(); 105 } 106