blob: bd1b8542f671ce5f08e479699c0e29bb4150907e [file] [log] [blame]
Argyrios Kyrtzidis2d67b902011-02-17 21:39:39 +00001//==- 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 Kyrtzidisec8605f2011-03-01 01:16:21 +000015#include "clang/StaticAnalyzer/Core/Checker.h"
Argyrios Kyrtzidis2d67b902011-02-17 21:39:39 +000016#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
17#include "clang/Analysis/Analyses/LiveVariables.h"
Ted Kremenek58f6f1e2011-10-25 00:25:24 +000018#include "clang/Analysis/Analyses/Dominators.h"
Argyrios Kyrtzidis2d67b902011-02-17 21:39:39 +000019
20using namespace clang;
21using namespace ento;
22
23//===----------------------------------------------------------------------===//
Ted Kremenek58f6f1e2011-10-25 00:25:24 +000024// 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)) {
Anna Zaks02f34c52011-12-05 21:33:11 +000033 DominatorTree dom;
34 dom.buildDominatorTree(*AC);
Ted Kremenek58f6f1e2011-10-25 00:25:24 +000035 dom.dump();
36 }
37 }
38};
39}
40
41void ento::registerDominatorsTreeDumper(CheckerManager &mgr) {
42 mgr.registerChecker<DominatorsTreeDumper>();
43}
44
45//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis2d67b902011-02-17 21:39:39 +000046// LiveVariablesDumper
47//===----------------------------------------------------------------------===//
48
49namespace {
Argyrios Kyrtzidisec8605f2011-03-01 01:16:21 +000050class LiveVariablesDumper : public Checker<check::ASTCodeBody> {
Argyrios Kyrtzidis2d67b902011-02-17 21:39:39 +000051public:
52 void checkASTCodeBody(const Decl *D, AnalysisManager& mgr,
53 BugReporter &BR) const {
Ted Kremeneka5937bb2011-10-07 22:21:02 +000054 if (LiveVariables* L = mgr.getAnalysis<LiveVariables>(D)) {
Argyrios Kyrtzidis2d67b902011-02-17 21:39:39 +000055 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 {
Argyrios Kyrtzidisec8605f2011-03-01 01:16:21 +000070class CFGViewer : public Checker<check::ASTCodeBody> {
Argyrios Kyrtzidis2d67b902011-02-17 21:39:39 +000071public:
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 {
Argyrios Kyrtzidisec8605f2011-03-01 01:16:21 +000090class CFGDumper : public Checker<check::ASTCodeBody> {
Argyrios Kyrtzidis2d67b902011-02-17 21:39:39 +000091public:
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}