DebugCheckers.cpp revision 58f6f1e37ab32fdd0c8bab6771d8e09bc139e9ed
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 20using namespace clang; 21using namespace ento; 22 23//===----------------------------------------------------------------------===// 24// DominatorsTreeDumper 25//===----------------------------------------------------------------------===// 26 27namespace { 28class DominatorsTreeDumper : public Checker<check::ASTCodeBody> { 29public: 30 void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, 31 BugReporter &BR) const { 32 if (AnalysisDeclContext *AC = mgr.getAnalysisDeclContext(D)) { 33 DominatorTree dom(*AC); 34 dom.BuildDominatorTree(); 35 dom.dump(); 36 } 37 } 38}; 39} 40 41void ento::registerDominatorsTreeDumper(CheckerManager &mgr) { 42 mgr.registerChecker<DominatorsTreeDumper>(); 43} 44 45//===----------------------------------------------------------------------===// 46// LiveVariablesDumper 47//===----------------------------------------------------------------------===// 48 49namespace { 50class LiveVariablesDumper : public Checker<check::ASTCodeBody> { 51public: 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 61void ento::registerLiveVariablesDumper(CheckerManager &mgr) { 62 mgr.registerChecker<LiveVariablesDumper>(); 63} 64 65//===----------------------------------------------------------------------===// 66// CFGViewer 67//===----------------------------------------------------------------------===// 68 69namespace { 70class CFGViewer : public Checker<check::ASTCodeBody> { 71public: 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 81void ento::registerCFGViewer(CheckerManager &mgr) { 82 mgr.registerChecker<CFGViewer>(); 83} 84 85//===----------------------------------------------------------------------===// 86// CFGDumper 87//===----------------------------------------------------------------------===// 88 89namespace { 90class CFGDumper : public Checker<check::ASTCodeBody> { 91public: 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 101void ento::registerCFGDumper(CheckerManager &mgr) { 102 mgr.registerChecker<CFGDumper>(); 103} 104