From cd19deb7d99dbc37f987da8b4e91a8ecd8e9e8e4 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 20 Aug 2019 16:27:55 -0400
Subject: [PATCH 086/124] FIXME: show state summaries in
 -fdump-analyzer-exploded-nodes

---
 gcc/analyzer/impl-4.cc | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/gcc/analyzer/impl-4.cc b/gcc/analyzer/impl-4.cc
index 4627975..48c9640 100644
--- a/gcc/analyzer/impl-4.cc
+++ b/gcc/analyzer/impl-4.cc
@@ -835,7 +835,8 @@ public:
 
   void print (const extrinsic_state &ext_state,
 	      pretty_printer *pp) const;
-  std::string to_str (const extrinsic_state &ext_state) const;
+  std::string to_str (const extrinsic_state &ext_state,
+		      bool summarize) const;
 
   void dump_to_pp (const extrinsic_state &ext_state, bool summarize,
 		   pretty_printer *pp) const;
@@ -3705,11 +3706,15 @@ program_state::print (const extrinsic_state &ext_state,
 /* FIXME.  */
 
 std::string
-program_state::to_str (const extrinsic_state &ext_state) const
+program_state::to_str (const extrinsic_state &ext_state,
+		       bool summarize) const
 {
   pretty_printer pp;
   pp_format_decoder (&pp) = default_tree_printer;
-  print (ext_state, &pp);
+  if (summarize)
+    dump_to_pp (ext_state, true, &pp);
+  else
+    print (ext_state, &pp);
   return std::string (pp_formatted_text (&pp));
 }
 
@@ -6026,7 +6031,7 @@ exploded_graph::get_or_create_node (const program_point &point,
     {
       format f (false);
       log ("point: %s", point.to_str (f).c_str ());
-      log ("state: %s", state.to_str (m_ext_state).c_str ());
+      log ("state: %s", state.to_str (m_ext_state, true).c_str ());
     }
 
   auto_cfun sentinel (point.get_function ());
@@ -6045,7 +6050,8 @@ exploded_graph::get_or_create_node (const program_point &point,
 
   if (get_logger ())
     {
-      log ("pruned_state: %s", pruned_state.to_str (m_ext_state).c_str ());
+      log ("pruned_state: %s",
+	   pruned_state.to_str (m_ext_state, true).c_str ());
       pruned_state.m_region_model->dump_to_pp (get_logger_pp (), true);
     }
 
@@ -6141,7 +6147,8 @@ exploded_graph::get_or_create_node (const program_point &point,
       format f (false);
       log ("created EN: %i", node->m_index);
       log ("point: %s", point.to_str (f).c_str ());
-      log ("pruned_state: %s", pruned_state.to_str (m_ext_state).c_str ());
+      log ("pruned_state: %s",
+	   pruned_state.to_str (m_ext_state, true).c_str ());
     }
 
   if (0)
@@ -6459,7 +6466,7 @@ exploded_graph::process_node (exploded_node *node)
       format f (false);
       log ("point: %s, state: %s",
 	   point.to_str (f).c_str (),
-	   state.to_str (m_ext_state).c_str ());
+	   state.to_str (m_ext_state, true).c_str ());
     }
 
   switch (point.m_kind)
@@ -6683,7 +6690,7 @@ exploded_graph::dump_states_for_supernode (FILE *out,
 	  && iter_snode == snode)
 	fprintf (out, "state %i: EN: %i\n  %s\n",
 		 state_idx++, enode->m_index,
-		 enode->get_state ().to_str (m_ext_state).c_str ());
+		 enode->get_state ().to_str (m_ext_state, true).c_str ());
     }
   fprintf (out, "#exploded_node for PK_AFTER_SUPERNODE for SN: %i = %i\n",
 	   snode->m_index, state_idx);
@@ -7739,14 +7746,19 @@ function_comparator (const void *pn1, const void *pn2)
 class enode_label : public range_label
 {
  public:
-  enode_label (exploded_node *enode) : m_enode (enode) {}
+  enode_label (const extrinsic_state &ext_state,
+	       exploded_node *enode)
+  : m_ext_state (ext_state), m_enode (enode) {}
 
   label_text get_text (unsigned) const FINAL OVERRIDE
   {
-    return label_text::take (print (false, "EN: %i", m_enode->m_index));
+    std::string state = m_enode->get_state ().to_str (m_ext_state, true);
+    return label_text::take (print (false, "EN: %i: %s",
+				    m_enode->m_index, state.c_str ()));
   }
 
 private:
+  const extrinsic_state &m_ext_state;
   exploded_node *m_enode;
 };
 
@@ -7789,7 +7801,7 @@ exploded_graph::dump_exploded_nodes () const
 	      else
 		richloc.add_range (stmt->location,
 				   SHOW_RANGE_WITHOUT_CARET,
-				   new enode_label (enode));
+				   new enode_label (m_ext_state, enode));
 	    }
 	}
       warning_at (&richloc, 0, "%i exploded nodes", m_nodes.length ());
-- 
1.8.5.3

