From patchwork Wed Nov 9 22:22:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1701908 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=yCiXzpo/; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N6zzP5tW1z23lq for ; Thu, 10 Nov 2022 09:24:32 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CAC7E3858C27 for ; Wed, 9 Nov 2022 22:24:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CAC7E3858C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668032669; bh=9YyAjLF/iKa4rHRXBaNHgkqBffnEqNJiSBgCjmB0uWE=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=yCiXzpo/cCmsaQQ+ISO9KXhMfGvFx5nG1oJ9I0m4zea4bHZn1VSIzjXWq1rYGBif/ r+Rd/33/yTvA5i2dWXV/NDznGzBnJXUFzvLTstohATTR5TuR4bPICSO6a5tRV+66PF 8DzdwNyHu13Sw58jI1gNDmSt+xbttkCKX/1WmGBU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 8F5C63858D20 for ; Wed, 9 Nov 2022 22:22:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8F5C63858D20 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-359-aHXZL7irNeOubwwkg8C4uw-1; Wed, 09 Nov 2022 17:22:52 -0500 X-MC-Unique: aHXZL7irNeOubwwkg8C4uw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D825F3C0F66C for ; Wed, 9 Nov 2022 22:22:51 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.17.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0FE540C6EC3; Wed, 9 Nov 2022 22:22:51 +0000 (UTC) To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed] analyzer: better logging of event creation Date: Wed, 9 Nov 2022 17:22:50 -0500 Message-Id: <20221109222250.2594117-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: David Malcolm via Gcc-patches From: David Malcolm Reply-To: David Malcolm Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r13-3867-g965ce1ba392ca0. 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 --- 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 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 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 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)