aboutsummaryrefslogtreecommitdiff
path: root/gcc/analyzer/diagnostic-manager.cc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2020-09-18 13:59:21 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2020-09-22 14:47:03 -0400
commit809192e77e6e112a0fe32dee7fada7a49fbf25cd (patch)
treed6a2be6a09802aad22e6eb2a779f6baefacf700c /gcc/analyzer/diagnostic-manager.cc
parent7c8ba5da80d5d95a8521010d6731d0d83036145d (diff)
downloadgcc-809192e77e6e112a0fe32dee7fada7a49fbf25cd.zip
gcc-809192e77e6e112a0fe32dee7fada7a49fbf25cd.tar.gz
gcc-809192e77e6e112a0fe32dee7fada7a49fbf25cd.tar.bz2
analyzer: add -fdump-analyzer-json
I've found this useful for debugging state explosions in the analyzer. gcc/analyzer/ChangeLog: * analysis-plan.cc: Include "json.h". * analyzer.opt (fdump-analyzer-json): New. * call-string.cc: Include "json.h". (call_string::to_json): New. * call-string.h (call_string::to_json): New decl. * checker-path.cc: Include "json.h". * constraint-manager.cc: Include "json.h". (equiv_class::to_json): New. (constraint::to_json): New. (constraint_manager::to_json): New. * constraint-manager.h (equiv_class::to_json): New decl. (constraint::to_json): New decl. (constraint_manager::to_json): New decl. * diagnostic-manager.cc: Include "json.h". (saved_diagnostic::to_json): New. (diagnostic_manager::to_json): New. * diagnostic-manager.h (saved_diagnostic::to_json): New decl. (diagnostic_manager::to_json): New decl. * engine.cc: Include "json.h", <zlib.h>. (exploded_node::status_to_str): New. (exploded_node::to_json): New. (exploded_edge::to_json): New. (exploded_graph::to_json): New. (dump_analyzer_json): New. (impl_run_checkers): Call it. * exploded-graph.h (exploded_node::status_to_str): New decl. (exploded_node::to_json): New. (exploded_edge::to_json): New. (exploded_graph::to_json): New. * pending-diagnostic.cc: Include "json.h". * program-point.cc: Include "json.h". (program_point::to_json): New. * program-point.h (program_point::to_json): New decl. * program-state.cc: Include "json.h". (extrinsic_state::to_json): New. (sm_state_map::to_json): New. (program_state::to_json): New. * program-state.h (extrinsic_state::to_json): New decl. (sm_state_map::to_json): New decl. (program_state::to_json): New decl. * region-model-impl-calls.cc: Include "json.h". * region-model-manager.cc: Include "json.h". * region-model-reachability.cc: Include "json.h". * region-model.cc: Include "json.h". * region-model.h (svalue::to_json): New decl. (region::to_json): New decl. * region.cc: Include "json.h". (region::to_json: New. * sm-file.cc: Include "json.h". * sm-malloc.cc: Include "json.h". * sm-pattern-test.cc: Include "json.h". * sm-sensitive.cc: Include "json.h". * sm-signal.cc: Include "json.h". (signal_delivery_edge_info_t::to_json): New. * sm-taint.cc: Include "json.h". * sm.cc: Include "diagnostic.h", "tree-diagnostic.h", and "json.h". (state_machine::state::to_json): New. (state_machine::to_json): New. * sm.h (state_machine::state::to_json): New. (state_machine::to_json): New. * state-purge.cc: Include "json.h". * store.cc: Include "json.h". (binding_key::get_desc): New. (binding_map::to_json): New. (binding_cluster::to_json): New. (store::to_json): New. * store.h (binding_key::get_desc): New decl. (binding_map::to_json): New decl. (binding_cluster::to_json): New decl. (store::to_json): New decl. * supergraph.cc: Include "json.h". (supergraph::to_json): New. (supernode::to_json): New. (superedge::to_json): New. * supergraph.h (supergraph::to_json): New decl. (supernode::to_json): New decl. (superedge::to_json): New decl. * svalue.cc: Include "json.h". (svalue::to_json): New. gcc/ChangeLog: * doc/analyzer.texi (Other Debugging Techniques): Mention -fdump-analyzer-json. * doc/invoke.texi (Static Analyzer Options): Add -fdump-analyzer-json.
Diffstat (limited to 'gcc/analyzer/diagnostic-manager.cc')
-rw-r--r--gcc/analyzer/diagnostic-manager.cc58
1 files changed, 58 insertions, 0 deletions
diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc
index 4a95d4c..8d7e508 100644
--- a/gcc/analyzer/diagnostic-manager.cc
+++ b/gcc/analyzer/diagnostic-manager.cc
@@ -37,6 +37,7 @@ along with GCC; see the file COPYING3. If not see
#include "tristate.h"
#include "selftest.h"
#include "ordered-hash-map.h"
+#include "json.h"
#include "analyzer/analyzer.h"
#include "analyzer/analyzer-logging.h"
#include "analyzer/sm.h"
@@ -114,6 +115,43 @@ saved_diagnostic::operator== (const saved_diagnostic &other) const
&& m_trailing_eedge == other.m_trailing_eedge);
}
+/* Return a new json::object of the form
+ {"sm": optional str,
+ "enode": int,
+ "snode": int,
+ "sval": optional str,
+ "state": optional str,
+ "path_length": int,
+ "pending_diagnostic": str}. */
+
+json::object *
+saved_diagnostic::to_json () const
+{
+ json::object *sd_obj = new json::object ();
+
+ if (m_sm)
+ sd_obj->set ("sm", new json::string (m_sm->get_name ()));
+ sd_obj->set ("enode", new json::integer_number (m_enode->m_index));
+ sd_obj->set ("snode", new json::integer_number (m_snode->m_index));
+ if (m_sval)
+ sd_obj->set ("sval", m_sval->to_json ());
+ if (m_state)
+ sd_obj->set ("state", m_state->to_json ());
+ sd_obj->set ("path_length", new json::integer_number (m_epath_length));
+ sd_obj->set ("pending_diagnostic", new json::string (m_d->get_kind ()));
+
+ /* We're not yet JSONifying the following fields:
+ const gimple *m_stmt;
+ stmt_finder *m_stmt_finder;
+ tree m_var;
+ exploded_edge *m_trailing_eedge;
+ enum status m_status;
+ feasibility_problem *m_problem;
+ */
+
+ return sd_obj;
+}
+
/* State for building a checker_path from a particular exploded_path.
In particular, this precomputes reachability information: the set of
source enodes for which a path be found to the diagnostic enode. */
@@ -199,6 +237,26 @@ diagnostic_manager::add_diagnostic (const exploded_node *enode,
add_diagnostic (NULL, enode, snode, stmt, finder, NULL_TREE, NULL, 0, d);
}
+/* Return a new json::object of the form
+ {"diagnostics" : [obj for saved_diagnostic]}. */
+
+json::object *
+diagnostic_manager::to_json () const
+{
+ json::object *dm_obj = new json::object ();
+
+ {
+ json::array *sd_arr = new json::array ();
+ int i;
+ saved_diagnostic *sd;
+ FOR_EACH_VEC_ELT (m_saved_diagnostics, i, sd)
+ sd_arr->append (sd->to_json ());
+ dm_obj->set ("diagnostics", sd_arr);
+ }
+
+ return dm_obj;
+}
+
/* A class for identifying sets of duplicated pending_diagnostic.
We want to find the simplest dedupe_candidate amongst those that share a