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/CheckerV2.h" 16 #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h" 17 #include "clang/Analysis/Analyses/LiveVariables.h" 18 19 using namespace clang; 20 using namespace ento; 21 22 //===----------------------------------------------------------------------===// 23 // LiveVariablesDumper 24 //===----------------------------------------------------------------------===// 25 26 namespace { 27 class LiveVariablesDumper : public CheckerV2<check::ASTCodeBody> { 28 public: 29 void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, 30 BugReporter &BR) const { 31 if (LiveVariables* L = mgr.getLiveVariables(D)) { 32 L->dumpBlockLiveness(mgr.getSourceManager()); 33 } 34 } 35 }; 36 } 37 38 void ento::registerLiveVariablesDumper(CheckerManager &mgr) { 39 mgr.registerChecker<LiveVariablesDumper>(); 40 } 41 42 //===----------------------------------------------------------------------===// 43 // CFGViewer 44 //===----------------------------------------------------------------------===// 45 46 namespace { 47 class CFGViewer : public CheckerV2<check::ASTCodeBody> { 48 public: 49 void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, 50 BugReporter &BR) const { 51 if (CFG *cfg = mgr.getCFG(D)) { 52 cfg->viewCFG(mgr.getLangOptions()); 53 } 54 } 55 }; 56 } 57 58 void ento::registerCFGViewer(CheckerManager &mgr) { 59 mgr.registerChecker<CFGViewer>(); 60 } 61 62 //===----------------------------------------------------------------------===// 63 // CFGDumper 64 //===----------------------------------------------------------------------===// 65 66 namespace { 67 class CFGDumper : public CheckerV2<check::ASTCodeBody> { 68 public: 69 void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, 70 BugReporter &BR) const { 71 if (CFG *cfg = mgr.getCFG(D)) { 72 cfg->dump(mgr.getLangOptions()); 73 } 74 } 75 }; 76 } 77 78 void ento::registerCFGDumper(CheckerManager &mgr) { 79 mgr.registerChecker<CFGDumper>(); 80 } 81