From: David Malcolm Date: Wed, 9 Nov 2022 22:20:06 +0000 (-0500) Subject: analyzer: better logging of event creation X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=965ce1ba392ca03c746cabb9ba73e66258557dcb;p=platform%2Fupstream%2Fgcc.git 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 --- diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc index 40f9ccfe..ffab91c 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 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 c8de5c9..46f4875 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 event) - { - m_events.safe_push (event.release ()); - } + void add_event (std::unique_ptr 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 m_setjmp_event_ids; + + logger *m_logger; }; } // namespace ana diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index e775475..74cc736 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)