From patchwork Mon Oct 16 09:17:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 77871 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B84A63856243 for ; Mon, 16 Oct 2023 09:17:47 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 558E53858423 for ; Mon, 16 Oct 2023 09:17:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 558E53858423 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 558E53858423 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.220.29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697447850; cv=none; b=AFRA554x76bE4bgtUJDTq9ZEoTnaO+Q5/1qkK7/yShGP5jnTiYjjhjT0szNk79KWZRLqmYEApDcMAk6lkCfW5s18tT/0D6hVcIuTgMW9Yx6j6lEwJ1KRHhrbUHUhSS61CXtAnJMJnSKdPnvqbLYG8a8aulZrJu3kT/Agto+wsHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697447850; c=relaxed/simple; bh=BzyjVPmL0n8oFpgbPoKQWVYckQNnBlOrBKucazH9AtY=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=sxaddttNmyhuvcSI6ZfmYA7al9UgcGeCLdg8XMQ/L/OheN3gWHMdenSgYmoYg2MkIf2OlJymmqETXnphUa19WSRY11sSVnbTqfkzDYHBMAD22W8XXTQ1MyArzitwdUZx5SwQpx//6jlg1oCQutJ/ZdzYjShwq3nNnGsv4pMncGo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 68EF51FEB8 for ; Mon, 16 Oct 2023 09:17:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1697447847; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wh0ve8TjVI7KyLRI1uGus2i3nyUEcGT2kX8laIY1qac=; b=nrdAq8Xaa1DWqVdrxoKwE4Twn/lJ3VBO7Yqqk91UR6Dtn1RjIgp39zrxgC4nJ3EcMCZ2EU GWl+09bm8LWZJiFptWJ/t2JKfww0jjnqGip6BIjj1LePMtFi01iT83aCE+SwE3uZCArNoJ TpmeN9Hoh9tg5VvKYUjAzh7qABGNT7E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1697447847; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wh0ve8TjVI7KyLRI1uGus2i3nyUEcGT2kX8laIY1qac=; b=b3aBeCt6tkJLu6o9CQt39jcUezc2W+VRBMAAT3W1M2+/1JySCJi1P1zHayCwe9nhvTpOm9 iyZf8vcbgR8GlOCw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5763D139F9 for ; Mon, 16 Oct 2023 09:17:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2DdeFKf/LGUXLQAAMHmgww (envelope-from ) for ; Mon, 16 Oct 2023 09:17:27 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v3 3/4] [gdb/cli] Keep track of styling failures in source_cache Date: Mon, 16 Oct 2023 11:17:47 +0200 Message-Id: <20231016091748.26247-4-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231016091748.26247-1-tdevries@suse.de> References: <20231016091748.26247-1-tdevries@suse.de> MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 3.93 X-Spamd-Result: default: False [3.93 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCPT_COUNT_ONE(0.00)[1]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.97)[-0.975]; NEURAL_SPAM_LONG(3.00)[1.000]; MID_CONTAINS_FROM(1.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[99.99%] X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org In source_cache::ensure, keep track of which files failed to be styled, and don't attempt to style them again in case the file dropped out of the cache. Tested on x86_64-linux. --- gdb/source-cache.c | 24 ++++++++++++++++++++++-- gdb/source-cache.h | 4 ++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/gdb/source-cache.c b/gdb/source-cache.c index 191d0043e66..aa8e40425c2 100644 --- a/gdb/source-cache.c +++ b/gdb/source-cache.c @@ -281,7 +281,8 @@ source_cache::ensure (struct symtab *s) return false; } - if (source_styling && gdb_stdout->can_emit_style_escape ()) + if (source_styling && gdb_stdout->can_emit_style_escape () + && m_no_styling_files.count (fullname) == 0) { bool already_styled = try_source_highlight (contents, s->language (), fullname); @@ -291,7 +292,26 @@ source_cache::ensure (struct symtab *s) gdb::optional ext_contents; ext_contents = ext_lang_colorize (fullname, contents); if (ext_contents.has_value ()) - contents = std::move (*ext_contents); + { + contents = std::move (*ext_contents); + already_styled = true; + } + } + + if (!already_styled) + { + /* Styling failed. Styling can fail for instance for these + reasons: + - the language is not supported. + - the language cannot not be auto-detected from the file name. + - no stylers available. + + Since styling failed, don't try styling the file again after it + drops from the cache. + + Note that clearing the source cache also clears + m_no_styling_files. */ + m_no_styling_files.insert (fullname); } } diff --git a/gdb/source-cache.h b/gdb/source-cache.h index bec6598ff9f..f1d30b43ce0 100644 --- a/gdb/source-cache.h +++ b/gdb/source-cache.h @@ -66,6 +66,7 @@ class source_cache { m_source_map.clear (); m_offset_cache.clear (); + m_no_styling_files.clear (); } private: @@ -95,6 +96,9 @@ class source_cache /* The file offset cache. The key is the full name of the source file. */ std::unordered_map> m_offset_cache; + + /* The list of files where styling failed. */ + std::unordered_set m_no_styling_files; }; /* The global source cache. */