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" |
Ted Kremenek | 682060c | 2011-12-22 23:33:52 +0000 | [diff] [blame^] | 19 | #include "llvm/Support/Process.h" |
Argyrios Kyrtzidis | 2d67b90 | 2011-02-17 21:39:39 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace clang; |
| 22 | using namespace ento; |
| 23 | |
| 24 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 58f6f1e | 2011-10-25 00:25:24 +0000 | [diff] [blame] | 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)) { |
Anna Zaks | 02f34c5 | 2011-12-05 21:33:11 +0000 | [diff] [blame] | 34 | DominatorTree dom; |
| 35 | dom.buildDominatorTree(*AC); |
Ted Kremenek | 58f6f1e | 2011-10-25 00:25:24 +0000 | [diff] [blame] | 36 | dom.dump(); |
| 37 | } |
| 38 | } |
| 39 | }; |
| 40 | } |
| 41 | |
| 42 | void ento::registerDominatorsTreeDumper(CheckerManager &mgr) { |
| 43 | mgr.registerChecker<DominatorsTreeDumper>(); |
| 44 | } |
| 45 | |
| 46 | //===----------------------------------------------------------------------===// |
Argyrios Kyrtzidis | 2d67b90 | 2011-02-17 21:39:39 +0000 | [diff] [blame] | 47 | // LiveVariablesDumper |
| 48 | //===----------------------------------------------------------------------===// |
| 49 | |
| 50 | namespace { |
Argyrios Kyrtzidis | ec8605f | 2011-03-01 01:16:21 +0000 | [diff] [blame] | 51 | class LiveVariablesDumper : public Checker<check::ASTCodeBody> { |
Argyrios Kyrtzidis | 2d67b90 | 2011-02-17 21:39:39 +0000 | [diff] [blame] | 52 | public: |
| 53 | void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, |
| 54 | BugReporter &BR) const { |
Ted Kremenek | a5937bb | 2011-10-07 22:21:02 +0000 | [diff] [blame] | 55 | if (LiveVariables* L = mgr.getAnalysis<LiveVariables>(D)) { |
Argyrios Kyrtzidis | 2d67b90 | 2011-02-17 21:39:39 +0000 | [diff] [blame] | 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 { |
Argyrios Kyrtzidis | ec8605f | 2011-03-01 01:16:21 +0000 | [diff] [blame] | 71 | class CFGViewer : public Checker<check::ASTCodeBody> { |
Argyrios Kyrtzidis | 2d67b90 | 2011-02-17 21:39:39 +0000 | [diff] [blame] | 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 { |
Argyrios Kyrtzidis | ec8605f | 2011-03-01 01:16:21 +0000 | [diff] [blame] | 91 | class CFGDumper : public Checker<check::ASTCodeBody> { |
Argyrios Kyrtzidis | 2d67b90 | 2011-02-17 21:39:39 +0000 | [diff] [blame] | 92 | public: |
| 93 | void checkASTCodeBody(const Decl *D, AnalysisManager& mgr, |
| 94 | BugReporter &BR) const { |
| 95 | if (CFG *cfg = mgr.getCFG(D)) { |
Ted Kremenek | 682060c | 2011-12-22 23:33:52 +0000 | [diff] [blame^] | 96 | cfg->dump(mgr.getLangOptions(), |
| 97 | llvm::sys::Process::StandardErrHasColors()); |
Argyrios Kyrtzidis | 2d67b90 | 2011-02-17 21:39:39 +0000 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | }; |
| 101 | } |
| 102 | |
| 103 | void ento::registerCFGDumper(CheckerManager &mgr) { |
| 104 | mgr.registerChecker<CFGDumper>(); |
| 105 | } |