analyzer: add -fdump-analyzer-exploded-paths
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 15 Jul 2021 19:04:07 +0000 (15:04 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 15 Jul 2021 19:04:07 +0000 (15:04 -0400)
gcc/analyzer/ChangeLog:
* analyzer.opt (fdump-analyzer-exploded-paths): New.
* diagnostic-manager.cc
(diagnostic_manager::emit_saved_diagnostic): Implement it.
* engine.cc (exploded_path::dump_to_pp): Add ext_state param and
use it to dump states if non-NULL.
(exploded_path::dump): Likewise.
(exploded_path::dump_to_file): New.
* exploded-graph.h (exploded_path::dump_to_pp): Add ext_state
param.
(exploded_path::dump): Likewise.
(exploded_path::dump): Likewise.
(exploded_path::dump_to_file): New.

gcc/ChangeLog:
* doc/invoke.texi (-fdump-analyzer-exploded-paths): New.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/analyzer.opt
gcc/analyzer/diagnostic-manager.cc
gcc/analyzer/engine.cc
gcc/analyzer/exploded-graph.h
gcc/doc/invoke.texi

index dd34495..7b77ae8 100644 (file)
@@ -210,6 +210,10 @@ fdump-analyzer-exploded-nodes-3
 Common RejectNegative Var(flag_dump_analyzer_exploded_nodes_3)
 Dump a textual representation of the exploded graph to SRCFILE.eg-ID.txt.
 
+fdump-analyzer-exploded-paths
+Common RejectNegative Var(flag_dump_analyzer_exploded_paths)
+Dump a textual representation of each diagnostic's exploded path to SRCFILE.IDX.KIND.epath.txt.
+
 fdump-analyzer-feasibility
 Common RejectNegative Var(flag_dump_analyzer_feasibility)
 Dump various analyzer internals to SRCFILE.*.fg.dot and SRCFILE.*.tg.dot.
index b7d263b..d005fac 100644 (file)
@@ -1164,6 +1164,17 @@ diagnostic_manager::emit_saved_diagnostic (const exploded_graph &eg,
        inform_n (loc, num_dupes,
                  "%i duplicate", "%i duplicates",
                  num_dupes);
+      if (flag_dump_analyzer_exploded_paths)
+       {
+         auto_timevar tv (TV_ANALYZER_DUMP);
+         pretty_printer pp;
+         pp_printf (&pp, "%s.%i.%s.epath.txt",
+                    dump_base_name, sd.get_index (), sd.m_d->get_kind ());
+         char *filename = xstrdup (pp_formatted_text (&pp));
+         epath->dump_to_file (filename, eg.get_ext_state ());
+         inform (loc, "exploded path written to %qs", filename);
+         free (filename);
+       }
     }
   delete pp;
 }
index 8f3e7f7..dc07a79 100644 (file)
@@ -3630,10 +3630,12 @@ exploded_path::feasible_p (logger *logger, feasibility_problem **out,
   return true;
 }
 
-/* Dump this path in multiline form to PP.  */
+/* Dump this path in multiline form to PP.
+   If EXT_STATE is non-NULL, then show the nodes.  */
 
 void
-exploded_path::dump_to_pp (pretty_printer *pp) const
+exploded_path::dump_to_pp (pretty_printer *pp,
+                          const extrinsic_state *ext_state) const
 {
   for (unsigned i = 0; i < m_edges.length (); i++)
     {
@@ -3643,28 +3645,48 @@ exploded_path::dump_to_pp (pretty_printer *pp) const
                 eedge->m_src->m_index,
                 eedge->m_dest->m_index);
       pp_newline (pp);
+
+      if (ext_state)
+       eedge->m_dest->dump_to_pp (pp, *ext_state);
     }
 }
 
 /* Dump this path in multiline form to FP.  */
 
 void
-exploded_path::dump (FILE *fp) const
+exploded_path::dump (FILE *fp, const extrinsic_state *ext_state) const
 {
   pretty_printer pp;
   pp_format_decoder (&pp) = default_tree_printer;
   pp_show_color (&pp) = pp_show_color (global_dc->printer);
   pp.buffer->stream = fp;
-  dump_to_pp (&pp);
+  dump_to_pp (&pp, ext_state);
   pp_flush (&pp);
 }
 
 /* Dump this path in multiline form to stderr.  */
 
 DEBUG_FUNCTION void
-exploded_path::dump () const
+exploded_path::dump (const extrinsic_state *ext_state) const
 {
-  dump (stderr);
+  dump (stderr, ext_state);
+}
+
+/* Dump this path verbosely to FILENAME.  */
+
+void
+exploded_path::dump_to_file (const char *filename,
+                            const extrinsic_state &ext_state) const
+{
+  FILE *fp = fopen (filename, "w");
+  if (!fp)
+    return;
+  pretty_printer pp;
+  pp_format_decoder (&pp) = default_tree_printer;
+  pp.buffer->stream = fp;
+  dump_to_pp (&pp, &ext_state);
+  pp_flush (&pp);
+  fclose (fp);
 }
 
 /* class feasibility_problem.  */
index 2d25e5e..1d8b73d 100644 (file)
@@ -895,9 +895,12 @@ public:
 
   exploded_node *get_final_enode () const;
 
-  void dump_to_pp (pretty_printer *pp) const;
-  void dump (FILE *fp) const;
-  void dump () const;
+  void dump_to_pp (pretty_printer *pp,
+                  const extrinsic_state *ext_state) const;
+  void dump (FILE *fp, const extrinsic_state *ext_state) const;
+  void dump (const extrinsic_state *ext_state = NULL) const;
+  void dump_to_file (const char *filename,
+                    const extrinsic_state &ext_state) const;
 
   bool feasible_p (logger *logger, feasibility_problem **out,
                    engine *eng, const exploded_graph *eg) const;
index ea88124..62e165f 100644 (file)
@@ -428,6 +428,7 @@ Objective-C and Objective-C++ Dialects}.
 -fdump-analyzer-exploded-nodes @gol
 -fdump-analyzer-exploded-nodes-2 @gol
 -fdump-analyzer-exploded-nodes-3 @gol
+-fdump-analyzer-exploded-paths @gol
 -fdump-analyzer-feasibility @gol
 -fdump-analyzer-json @gol
 -fdump-analyzer-state-purge @gol
@@ -9651,6 +9652,11 @@ Dump a textual representation of the ``exploded graph'' to
 one dump file per node, to @file{@var{file}.eg-@var{id}.txt}.
 This is typically a large number of dump files.
 
+@item -fdump-analyzer-exploded-paths
+@opindex fdump-analyzer-exploded-paths
+Dump a textual representation of the ``exploded path'' for each
+diagnostic to @file{@var{file}.@var{idx}.@var{kind}.epath.txt}.
+
 @item -fdump-analyzer-feasibility
 @opindex dump-analyzer-feasibility
 Dump internal details about the analyzer's search for feasible paths.