From 9f7ba9bd52823eb0fdb64767f2d09fb6b96b8179 Mon Sep 17 00:00:00 2001 From: Anna Zaks Date: Mon, 24 Jun 2013 18:12:12 +0000 Subject: [PATCH] [analyzer] Add a debug checker that prints Exploded Graph Add a debug checker that is useful to understand how the ExplodedGraph is built; it can be triggered using the following command: MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit clang -cc1 -analyze -analyzer-checker=debug.ViewExplodedGraph my_program.c A patch by Béatrice Creusillet! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184768 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/analyzer/DebugChecks.rst | 4 ++++ lib/StaticAnalyzer/Checkers/Checkers.td | 4 ++++ lib/StaticAnalyzer/Checkers/DebugCheckers.cpp | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/docs/analyzer/DebugChecks.rst b/docs/analyzer/DebugChecks.rst index f8e6f827c1..a0f2a07a00 100644 --- a/docs/analyzer/DebugChecks.rst +++ b/docs/analyzer/DebugChecks.rst @@ -30,6 +30,10 @@ using a 'dot' format viewer (such as Graphviz on OS X) instead. - debug.DumpLiveVars: Show the results of live variable analysis for each top-level function being analyzed. +- debug.ViewExplodedGraph: Show the Exploded Graphs generated for the + analysis of different functions in the input translation unit. When there + are several functions analyzed, display one graph per function. Beware + that these graphs may grow very large, even for small functions. Path Tracking ============= diff --git a/lib/StaticAnalyzer/Checkers/Checkers.td b/lib/StaticAnalyzer/Checkers/Checkers.td index fc35b223ee..cc25ae5e8d 100644 --- a/lib/StaticAnalyzer/Checkers/Checkers.td +++ b/lib/StaticAnalyzer/Checkers/Checkers.td @@ -538,4 +538,8 @@ def ExprInspectionChecker : Checker<"ExprInspection">, HelpText<"Check the analyzer's understanding of expressions">, DescFile<"ExprInspectionChecker.cpp">; +def ExplodedGraphViewer : Checker<"ViewExplodedGraph">, + HelpText<"View Exploded Graphs using GraphViz">, + DescFile<"DebugCheckers.cpp">; + } // end "debug" diff --git a/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp b/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp index fe12866e51..c374d0da0e 100644 --- a/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp +++ b/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp @@ -17,6 +17,8 @@ #include "clang/Analysis/CallGraph.h" #include "clang/StaticAnalyzer/Core/Checker.h" #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h" #include "llvm/Support/Process.h" using namespace clang; @@ -179,3 +181,22 @@ public: void ento::registerConfigDumper(CheckerManager &mgr) { mgr.registerChecker(); } + +//===----------------------------------------------------------------------===// +// ExplodedGraph Viewer +//===----------------------------------------------------------------------===// + +namespace { +class ExplodedGraphViewer : public Checker< check::EndAnalysis > { +public: + ExplodedGraphViewer() {} + void checkEndAnalysis(ExplodedGraph &G, BugReporter &B,ExprEngine &Eng) const { + Eng.ViewGraph(0); + } +}; + +} + +void ento::registerExplodedGraphViewer(CheckerManager &mgr) { + mgr.registerChecker(); +} -- 2.40.0