Add a new function to help debugging -fanalyzer.

No functional change intended.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r16-255-g0ef00f71969f20.

gcc/analyzer/ChangeLog:
        * call-details.cc (call_details::dump): New overload.
        (call_details::make_dump_widget): New.
        * call-details.h (call_details::dump): Declare new overload.
        (call_details::make_dump_widget): New decl.

Signed-off-by: David Malcolm <dmalc...@redhat.com>
---
 gcc/analyzer/call-details.cc | 59 ++++++++++++++++++++++++++++++++++++
 gcc/analyzer/call-details.h  |  4 +++
 2 files changed, 63 insertions(+)

diff --git a/gcc/analyzer/call-details.cc b/gcc/analyzer/call-details.cc
index 4122f84facd..3d85c17dbcb 100644
--- a/gcc/analyzer/call-details.cc
+++ b/gcc/analyzer/call-details.cc
@@ -366,6 +366,65 @@ call_details::dump (bool simple) const
   dump_to_pp (&pp, simple);
 }
 
+/* Dump a tree-like representation of this call to stderr.  */
+
+DEBUG_FUNCTION void
+call_details::dump () const
+{
+  text_art::dump (*this);
+}
+
+std::unique_ptr<text_art::tree_widget>
+call_details::make_dump_widget (const text_art::dump_widget_info &dwi) const
+{
+  using text_art::tree_widget;
+  std::unique_ptr<tree_widget> cd_widget
+    (tree_widget::from_fmt (dwi, nullptr, "Call Details"));
+
+  {
+    pretty_printer the_pp;
+    pretty_printer * const pp = &the_pp;
+    pp_format_decoder (pp) = default_tree_printer;
+    pp_string (pp, "gcall: ");
+    pp_gimple_stmt_1 (pp, m_call, 0 /* spc */, TDF_NONE /* flags */);
+    cd_widget->add_child (tree_widget::make (dwi, pp));
+  }
+  {
+    pretty_printer the_pp;
+    pretty_printer * const pp = &the_pp;
+    pp_format_decoder (pp) = default_tree_printer;
+    pp_string (pp, "return region: ");
+    if (m_lhs_region)
+      m_lhs_region->dump_to_pp (pp, true);
+    else
+      pp_string (pp, "NULL");
+    auto w = tree_widget::make (dwi, pp);
+    if (m_lhs_region)
+      w->add_child (m_lhs_region->make_dump_widget (dwi));
+    cd_widget->add_child (std::move (w));
+  }
+  if (gimple_call_num_args (m_call) > 0)
+    {
+      std::unique_ptr<tree_widget> args_widget
+       (tree_widget::from_fmt (dwi, nullptr, "Arguments"));
+      for (unsigned i = 0; i < gimple_call_num_args (m_call); i++)
+       {
+         pretty_printer the_pp;
+         pretty_printer * const pp = &the_pp;
+         pp_format_decoder (pp) = default_tree_printer;
+         const svalue *arg_sval = get_arg_svalue (i);
+         pp_printf (pp, "%i: ", i);
+         arg_sval->dump_to_pp (pp, true);
+         auto w = tree_widget::make (dwi, pp);
+         w->add_child (arg_sval->make_dump_widget (dwi));
+         args_widget->add_child (std::move (w));
+       }
+      cd_widget->add_child (std::move (args_widget));
+    }
+
+  return cd_widget;
+}
+
 /* Get a conjured_svalue for this call for REG,
    and purge any state already relating to that conjured_svalue.  */
 
diff --git a/gcc/analyzer/call-details.h b/gcc/analyzer/call-details.h
index fee7ad4bbcb..0f9f400ade6 100644
--- a/gcc/analyzer/call-details.h
+++ b/gcc/analyzer/call-details.h
@@ -68,6 +68,10 @@ public:
 
   void dump_to_pp (pretty_printer *pp, bool simple) const;
   void dump (bool simple) const;
+  void dump () const;
+
+  std::unique_ptr<text_art::tree_widget>
+  make_dump_widget (const text_art::dump_widget_info &dwi) const;
 
   const svalue *get_or_create_conjured_svalue (const region *) const;
 
-- 
2.26.3

Reply via email to