blob: d7e7af1c8eaac97be26753b2ac436e810acced6b [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"
Ted Kremenek682060c2011-12-22 23:33:52 +000019#include "llvm/Support/Process.h"
Argyrios Kyrtzidis2d67b902011-02-17 21:39:39 +000020
21using namespace clang;
22using namespace ento;
23
24//===----------------------------------------------------------------------===//
Ted Kremenek58f6f1e2011-10-25 00:25:24 +000025// DominatorsTreeDumper
26//===----------------------------------------------------------------------===//
27
28namespace {
29class DominatorsTreeDumper : public Checker<check::ASTCodeBody> {
30public:
31 void checkASTCodeBody(const Decl *D, AnalysisManager& mgr,
32 BugReporter &BR) const {
33 if (AnalysisDeclContext *AC = mgr.getAnalysisDeclContext(D)) {
Anna Zaks02f34c52011-12-05 21:33:11 +000034 DominatorTree dom;
35 dom.buildDominatorTree(*AC);
Ted Kremenek58f6f1e2011-10-25 00:25:24 +000036 dom.dump();
37 }
38 }
39};
40}
41
42void ento::registerDominatorsTreeDumper(CheckerManager &mgr) {
43 mgr.registerChecker<DominatorsTreeDumper>();
44}
45
46//===----------------------------------------------------------------------===//
Argyrios Kyrtzidis2d67b902011-02-17 21:39:39 +000047// LiveVariablesDumper
48//===----------------------------------------------------------------------===//
49
50namespace {
Argyrios Kyrtzidisec8605f2011-03-01 01:16:21 +000051class LiveVariablesDumper : public Checker<check::ASTCodeBody> {
Argyrios Kyrtzidis2d67b902011-02-17 21:39:39 +000052public:
53 void checkASTCodeBody(const Decl *D, AnalysisManager& mgr,
54 BugReporter &BR) const {
Ted Kremeneka5937bb2011-10-07 22:21:02 +000055 if (LiveVariables* L = mgr.getAnalysis<LiveVariables>(D)) {
Argyrios Kyrtzidis2d67b902011-02-17 21:39:39 +000056 L->dumpBlockLiveness(mgr.getSourceManager());
57 }
58 }
59};
60}
61
62void ento::registerLiveVariablesDumper(CheckerManager &mgr) {
63 mgr.registerChecker<LiveVariablesDumper>();
64}
65
66//===----------------------------------------------------------------------===//
67// CFGViewer
68//===----------------------------------------------------------------------===//
69
70namespace {
Argyrios Kyrtzidisec8605f2011-03-01 01:16:21 +000071class CFGViewer : public Checker<check::ASTCodeBody> {
Argyrios Kyrtzidis2d67b902011-02-17 21:39:39 +000072public:
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
82void ento::registerCFGViewer(CheckerManager &mgr) {
83 mgr.registerChecker<CFGViewer>();
84}
85
86//===----------------------------------------------------------------------===//
87// CFGDumper
88//===----------------------------------------------------------------------===//
89
90namespace {
Argyrios Kyrtzidisec8605f2011-03-01 01:16:21 +000091class CFGDumper : public Checker<check::ASTCodeBody> {
Argyrios Kyrtzidis2d67b902011-02-17 21:39:39 +000092public:
93 void checkASTCodeBody(const Decl *D, AnalysisManager& mgr,
94 BugReporter &BR) const {
95 if (CFG *cfg = mgr.getCFG(D)) {
Ted Kremenek682060c2011-12-22 23:33:52 +000096 cfg->dump(mgr.getLangOptions(),
97 llvm::sys::Process::StandardErrHasColors());
Argyrios Kyrtzidis2d67b902011-02-17 21:39:39 +000098 }
99 }
100};
101}
102
103void ento::registerCFGDumper(CheckerManager &mgr) {
104 mgr.registerChecker<CFGDumper>();
105}