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: 17856 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp592515wru; Wed, 9 Nov 2022 14:24:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf4TxnhFq4LB3Kx6NKbFNaWiFMx9wCR6YdpcvT+oV3N5Yd9dDti1SsTZ7YhVekFWOd+1gJYf X-Received: by 2002:a17:907:94c1:b0:792:56d7:2879 with SMTP id dn1-20020a17090794c100b0079256d72879mr10151865ejc.144.1668032695075; Wed, 09 Nov 2022 14:24:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668032695; cv=none; d=google.com; s=arc-20160816; b=fs/EPD2UteZ0aQfROarvMnfZTFUH04FelAYfK/oaHVqo7LMdMvsRtjaih24SL1tiK1 ghP+4OaKjAfefzw+z+E8tOijoG1YZfR8T/kp32IJFQT9IefSCQJ/0vIvUePXaLjNN0eC 2tN+6CCJPX9qoMrqt1WoHPMh8UyiqdswOaJMLox9rkLZyxwLqBlDJ53KwaE1108ePouG tcT3AMW1r4SsAKcJWwdGdgroVSl6YAYzD9zVLM8zxtaMAap+w9+mWrPYyu3LohAk/OoX p4Zil+mILrC4FBOhsTaSMruWmos9OBMebCPoRkLMyBvnLoVrPBrUwCV0IxBGxNZA+F2p BuHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=9YyAjLF/iKa4rHRXBaNHgkqBffnEqNJiSBgCjmB0uWE=; b=z0D4olGPmVtkxxcTnjEJfp0ikN5ERz2IyfXqeiBhvxNIV8Mf1wHGUDgG9y63XYCFNW zAO2F+rOmkdcpjoSdUYhbYGGfnZdza4z/w9il+41RKlQ9edtxkZujUtHuCmX5VMA1PMa YGwkdCciOuHKgFuf+Ybfqs2VggjuRjiPZ79rmybrHhB6PaMBbomGmghbs2xtRFR43MGe L7zlbpW4GUzrMO0FL32hpMlpe/5cTlWIrLG0LzCRvRYVTZO0OaxQPzbxn39lFGP9VLUz 8VOc9dhXdXZrYBi4rO2u2y8+qj6N5p0UC+saejLZD1gCQsGYUZkQtGaN4EZ+zCmLqvvN Yt8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kFYU2PhI; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k1-20020a170906680100b007307fd1b9bbsi12667200ejr.589.2022.11.09.14.24.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 14:24:55 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kFYU2PhI; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E0A9A3858D1E for ; Wed, 9 Nov 2022 22:24:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E0A9A3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668032693; 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=kFYU2PhIAhCLiPZfip06t4B30JkeGNPAmyTZDWJ3eEIfbhFwXWg0ZsalmTQ8hNpR6 92LLt7H6+XaT5EDvr9rpvmmFs5Ag2MjjbM5Qu1qCpTcwzIqkZMq1D+eBofgtFkOTRJ 3ir4yJAU/CpjPwe5d3iGA/fCA+k4/5rwO5ZlCdMM= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749059051453063678?= X-GMAIL-MSGID: =?utf-8?q?1749059051453063678?= 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)