DebugCheckers.cpp revision 2d67b90a21c9c1093e6598809c2cbc832919cfe6
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 19using namespace clang; 20using namespace ento; 21 22//===----------------------------------------------------------------------===// 23// LiveVariablesDumper 24//===----------------------------------------------------------------------===// 25 26namespace { 27class LiveVariablesDumper : public CheckerV2<check::ASTCodeBody> { 28public: 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 38void ento::registerLiveVariablesDumper(CheckerManager &mgr) { 39 mgr.registerChecker<LiveVariablesDumper>(); 40} 41 42//===----------------------------------------------------------------------===// 43// CFGViewer 44//===----------------------------------------------------------------------===// 45 46namespace { 47class CFGViewer : public CheckerV2<check::ASTCodeBody> { 48public: 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 58void ento::registerCFGViewer(CheckerManager &mgr) { 59 mgr.registerChecker<CFGViewer>(); 60} 61 62//===----------------------------------------------------------------------===// 63// CFGDumper 64//===----------------------------------------------------------------------===// 65 66namespace { 67class CFGDumper : public CheckerV2<check::ASTCodeBody> { 68public: 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 78void ento::registerCFGDumper(CheckerManager &mgr) { 79 mgr.registerChecker<CFGDumper>(); 80} 81