I found this useful whilst investigating a bug.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Committed to master as ebe9174e940c94e99cd688a05309833ae64a998b.

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/program-state.cc | 38 +++++++++++++++++++++++++++++++++++
 gcc/analyzer/program-state.h  |  4 ++++
 gcc/analyzer/sm.cc            | 12 +++++++++++
 gcc/analyzer/sm.h             |  2 ++
 4 files changed, 56 insertions(+)

diff --git a/gcc/analyzer/program-state.cc b/gcc/analyzer/program-state.cc
index ead62a5d423..4c0b9a8bfa0 100644
--- a/gcc/analyzer/program-state.cc
+++ b/gcc/analyzer/program-state.cc
@@ -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.  */
diff --git a/gcc/analyzer/program-state.h b/gcc/analyzer/program-state.h
index a052c6e8026..d2badb1a2ed 100644
--- a/gcc/analyzer/program-state.h
+++ b/gcc/analyzer/program-state.h
@@ -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;
diff --git a/gcc/analyzer/sm.cc b/gcc/analyzer/sm.cc
index 74fd17033ff..e94c691c16c 100644
--- a/gcc/analyzer/sm.cc
+++ b/gcc/analyzer/sm.cc
@@ -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.  */
 
diff --git a/gcc/analyzer/sm.h b/gcc/analyzer/sm.h
index 25163d7a7b1..3e8f4b6891d 100644
--- a/gcc/analyzer/sm.h
+++ b/gcc/analyzer/sm.h
@@ -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);
 
-- 
2.21.0

Reply via email to