public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-3867] analyzer: better logging of event creation
@ 2022-11-09 22:20 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2022-11-09 22:20 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:965ce1ba392ca03c746cabb9ba73e66258557dcb

commit r13-3867-g965ce1ba392ca03c746cabb9ba73e66258557dcb
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Wed Nov 9 17:20:06 2022 -0500

    analyzer: better logging of event creation
    
    gcc/analyzer/ChangeLog:
            * checker-path.cc (checker_event::debug): New.
            (checker_path::add_event): Move here from checker-path.h.  Add
            logging.
            * checker-path.h (checker_event::debug): New decl.
            (checker_path::checker_path): Add logger param.
            (checker_path::add_event): Move definition from here to
            checker-path.cc.
            (checker_path::m_logger): New field.
            * diagnostic-manager.cc
            (diagnostic_manager::emit_saved_diagnostic): Pass logger to
            checker_path ctor.
            (diagnostic_manager::add_events_for_eedge): Log scope when
            processing a run of stmts.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/analyzer/checker-path.cc       | 29 +++++++++++++++++++++++++++++
 gcc/analyzer/checker-path.h        | 10 +++++-----
 gcc/analyzer/diagnostic-manager.cc |  3 ++-
 3 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc
index 40f9ccfe08f..ffab91c26ff 100644
--- a/gcc/analyzer/checker-path.cc
+++ b/gcc/analyzer/checker-path.cc
@@ -204,6 +204,20 @@ checker_event::dump (pretty_printer *pp) const
 	     get_location ());
 }
 
+/* Dump this event to stderr (for debugging/logging purposes).  */
+
+DEBUG_FUNCTION void
+checker_event::debug () const
+{
+  pretty_printer pp;
+  pp_format_decoder (&pp) = default_tree_printer;
+  pp_show_color (&pp) = pp_show_color (global_dc->printer);
+  pp.buffer->stream = stderr;
+  dump (&pp);
+  pp_newline (&pp);
+  pp_flush (&pp);
+}
+
 /* Hook for being notified when this event has its final id EMISSION_ID
    and is about to emitted for PD.
 
@@ -1228,6 +1242,21 @@ checker_path::maybe_log (logger *logger, const char *desc) const
     }
 }
 
+void
+checker_path::add_event (std::unique_ptr<checker_event> event)
+{
+  if (m_logger)
+    {
+      m_logger->start_log_line ();
+      m_logger->log_partial ("added event[%i]: %s ",
+			     m_events.length (),
+			     event_kind_to_string (event.get ()->m_kind));
+      event.get ()->dump (m_logger->get_printer ());
+      m_logger->end_log_line ();
+    }
+  m_events.safe_push (event.release ());
+}
+
 /* Print a multiline form of this path to STDERR.  */
 
 DEBUG_FUNCTION void
diff --git a/gcc/analyzer/checker-path.h b/gcc/analyzer/checker-path.h
index c8de5c9be2c..46f4875f541 100644
--- a/gcc/analyzer/checker-path.h
+++ b/gcc/analyzer/checker-path.h
@@ -118,6 +118,7 @@ public:
   }
 
   void dump (pretty_printer *pp) const;
+  void debug () const;
 
   void set_location (location_t loc) { m_loc = loc; }
 
@@ -607,7 +608,7 @@ private:
 class checker_path : public diagnostic_path
 {
 public:
-  checker_path () : diagnostic_path () {}
+  checker_path (logger *logger) : diagnostic_path (), m_logger (logger) {}
 
   /* Implementation of diagnostic_path vfuncs.  */
 
@@ -631,10 +632,7 @@ public:
 
   void maybe_log (logger *logger, const char *desc) const;
 
-  void add_event (std::unique_ptr<checker_event> event)
-  {
-    m_events.safe_push (event.release ());
-  }
+  void add_event (std::unique_ptr<checker_event> event);
 
   void delete_event (int idx)
   {
@@ -711,6 +709,8 @@ private:
      exploded_node *, so that rewind events can refer to them in their
      descriptions.  */
   hash_map <const exploded_node *, diagnostic_event_id_t> m_setjmp_event_ids;
+
+  logger *m_logger;
 };
 
 } // namespace ana
diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc
index e77547567c1..74cc7369d77 100644
--- a/gcc/analyzer/diagnostic-manager.cc
+++ b/gcc/analyzer/diagnostic-manager.cc
@@ -1356,7 +1356,7 @@ diagnostic_manager::emit_saved_diagnostic (const exploded_graph &eg,
 
   /* This is the diagnostic_path subclass that will be built for
      the diagnostic.  */
-  checker_path emission_path;
+  checker_path emission_path (get_logger ());
 
   /* Populate emission_path with a full description of EPATH.  */
   build_emission_path (pb, *epath, &emission_path);
@@ -1963,6 +1963,7 @@ diagnostic_manager::add_events_for_eedge (const path_builder &pb,
 	   events for them.  */
 	if (dst_state.m_region_model)
 	  {
+	    log_scope s (get_logger (), "processing run of stmts");
 	    program_state iter_state (dst_state);
 	    program_point iter_point (dst_point);
 	    while (1)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-09 22:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-09 22:20 [gcc r13-3867] analyzer: better logging of event creation David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).