analyzer: add extrinsic_state::dump
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 30 Jan 2020 21:59:15 +0000 (16:59 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Fri, 31 Jan 2020 00:28:43 +0000 (19:28 -0500)
gcc/analyzer/ChangeLog:
* program-state.cc (extrinsic_state::dump_to_pp): New.
(extrinsic_state::dump_to_file): New.
(extrinsic_state::dump): New.
* program-state.h (extrinsic_state::dump_to_pp): New decl.
(extrinsic_state::dump_to_file): New decl.
(extrinsic_state::dump): New decl.
* sm.cc: Include "pretty-print.h".
(state_machine::dump_to_pp): New.
* sm.h (state_machine::dump_to_pp): New decl.

gcc/analyzer/ChangeLog
gcc/analyzer/program-state.cc
gcc/analyzer/program-state.h
gcc/analyzer/sm.cc
gcc/analyzer/sm.h

index 9f24206..709d1cb 100644 (file)
@@ -1,5 +1,17 @@
 2020-01-30  David Malcolm  <dmalcolm@redhat.com>
 
+       * program-state.cc (extrinsic_state::dump_to_pp): New.
+       (extrinsic_state::dump_to_file): New.
+       (extrinsic_state::dump): New.
+       * program-state.h (extrinsic_state::dump_to_pp): New decl.
+       (extrinsic_state::dump_to_file): New decl.
+       (extrinsic_state::dump): New decl.
+       * sm.cc: Include "pretty-print.h".
+       (state_machine::dump_to_pp): New.
+       * sm.h (state_machine::dump_to_pp): New decl.
+
+2020-01-30  David Malcolm  <dmalcolm@redhat.com>
+
        * diagnostic-manager.cc (for_each_state_change): Use
        extrinsic_state::get_num_checkers rather than accessing m_checkers
        directly.
index ead62a5..4c0b9a8 100644 (file)
@@ -59,6 +59,44 @@ along with GCC; see the file COPYING3.  If not see
 
 namespace ana {
 
+/* class extrinsic_state.  */
+
+/* Dump a multiline representation of this state to PP.  */
+
+void
+extrinsic_state::dump_to_pp (pretty_printer *pp) const
+{
+  pp_printf (pp, "extrinsic_state: %i checker(s)\n", get_num_checkers ());
+  unsigned i;
+  state_machine *checker;
+  FOR_EACH_VEC_ELT (m_checkers, i, checker)
+    {
+      pp_printf (pp, "m_checkers[%i]: %qs\n", i, checker->get_name ());
+      checker->dump_to_pp (pp);
+    }
+}
+
+/* Dump a multiline representation of this state to OUTF.  */
+
+void
+extrinsic_state::dump_to_file (FILE *outf) const
+{
+  pretty_printer pp;
+  if (outf == stderr)
+    pp_show_color (&pp) = pp_show_color (global_dc->printer);
+  pp.buffer->stream = outf;
+  dump_to_pp (&pp);
+  pp_flush (&pp);
+}
+
+/* Dump a multiline representation of this state to stderr.  */
+
+DEBUG_FUNCTION void
+extrinsic_state::dump () const
+{
+  dump_to_file (stderr);
+}
+
 /* class sm_state_map.  */
 
 /* sm_state_map's ctor.  */
index a052c6e..d2badb1 100644 (file)
@@ -45,6 +45,10 @@ public:
 
   unsigned get_num_checkers () const { return m_checkers.length (); }
 
+  void dump_to_pp (pretty_printer *pp) const;
+  void dump_to_file (FILE *outf) const;
+  void dump () const;
+
 private:
   /* The state machines.  */
   auto_delete_vec <state_machine> &m_checkers;
index 74fd170..e94c691 100644 (file)
@@ -28,6 +28,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "options.h"
 #include "function.h"
 #include "diagnostic-core.h"
+#include "pretty-print.h"
 #include "analyzer/analyzer.h"
 #include "analyzer/analyzer-logging.h"
 #include "analyzer/sm.h"
@@ -91,6 +92,17 @@ state_machine::validate (state_t s) const
   gcc_assert (s < m_state_names.length ());
 }
 
+/* Dump a multiline representation of this state machine to PP.  */
+
+void
+state_machine::dump_to_pp (pretty_printer *pp) const
+{
+  unsigned i;
+  const char *name;
+  FOR_EACH_VEC_ELT (m_state_names, i, name)
+    pp_printf (pp, "  state %i: %qs\n", i, name);
+}
+
 /* Create instances of the various state machines, each using LOGGER,
    and populate OUT with them.  */
 
index 25163d7..3e8f4b6 100644 (file)
@@ -80,6 +80,8 @@ public:
 
   void validate (state_t s) const;
 
+  void dump_to_pp (pretty_printer *pp) const;
+
 protected:
   state_t add_state (const char *name);