Argyrios Kyrtzidis | 2d67b90 | 2011-02-17 21:39:39 +0000 | [diff] [blame] | 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" |
Argyrios Kyrtzidis | ec8605f | 2011-03-01 01:16:21 +0000 | [diff] [blame] | 15 | #include "clang/StaticAnalyzer/Core/Checker.h" |
Argyrios Kyrtzidis | 2d67b90 | 2011-02-17 21:39:39 +0000 | [diff] [blame] | 16 | #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h" |
| 17 | #include "clang/Analysis/Analyses/LiveVariables.h" |
Ted Kremenek | 58f6f1e | 2011-10-25 00:25:24 +0000 | [diff] [blame] | 18 | #include "clang/Analysis/Analyses/Dominators.h" |
Argyrios Kyrtzidis | 2d67b90 | 2011-02-17 21:39:39 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace clang; |
| 21 | using namespace ento; |
| 22 | |
| 23 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 58f6f1e | 2011-10-25 00:25:24 +0000 | [diff] [blame] | 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)) { |
Anna Zaks | 02f34c5 | 2011-12-05 21:33:11 +0000 | [diff] [blame^] | 33 | DominatorTree dom; |
| 34 | dom.buildDominatorTree(*AC); |
Ted Kremenek | 58f6f1e | 2011-10-25 00:25:24 +0000 | [diff] [blame] | 35 | dom.dump(); |
| 36 | } |
| 37 | } |
| 38 | }; |
| 39 | } |
| 40 | |
| 41 | void ento::registerDominatorsTreeDumper(CheckerManager &mgr) { |
| 42 | mgr.registerChecker<DominatorsTreeDumper>(); |
| 43 | } |
| 44 | |
| 45 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 2d67b90 | 2011-02-17 21:39:39 +0000 | [diff] [blame] | 46 | // LiveVariablesDumper |
| 47 | //===----------------------------------------------------------------------===// |
| 48 | |
| 49 | namespace { |
Argyrios Kyrtzidis | ec8605f | 2011-03-01 01:16:21 +0000 | [diff] [blame] | 50 | class LiveVariablesDumper : public Checker<check::ASTCodeBody> { |
Argyrios Kyrtzidis | 2d67b90 | 2011-02-17 21:39:39 +0000 | [diff] [blame] | 51 | public: |
| 52 | void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, |
| 53 | BugReporter &BR) const { |
Ted Kremenek | a5937bb | 2011-10-07 22:21:02 +0000 | [diff] [blame] | 54 | if (LiveVariables* L = mgr.getAnalysis<LiveVariables>(D)) { |
Argyrios Kyrtzidis | 2d67b90 | 2011-02-17 21:39:39 +0000 | [diff] [blame] | 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 { |
Argyrios Kyrtzidis | ec8605f | 2011-03-01 01:16:21 +0000 | [diff] [blame] | 70 | class CFGViewer : public Checker<check::ASTCodeBody> { |
Argyrios Kyrtzidis | 2d67b90 | 2011-02-17 21:39:39 +0000 | [diff] [blame] | 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 { |
Argyrios Kyrtzidis | ec8605f | 2011-03-01 01:16:21 +0000 | [diff] [blame] | 90 | class CFGDumper : public Checker<check::ASTCodeBody> { |
Argyrios Kyrtzidis | 2d67b90 | 2011-02-17 21:39:39 +0000 | [diff] [blame] | 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 | } |