From patchwork Fri Oct 13 12:19:52 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: 77658 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 87A47385771C for ; Fri, 13 Oct 2023 12:20:14 +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 CB1B73858D35 for ; Fri, 13 Oct 2023 12:19:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB1B73858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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 E82841FDA0 for ; Fri, 13 Oct 2023 12:19:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1697199579; 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=SAe06IIfY0s0gKEFEWJWHYjzPGoen4WjkR1pGfwRJK8=; b=Qat0iKJDdzLjrQTHHUOpR1nC6ogKAollFSJxAq7OUe/ZXlRhMI4leGv2VqAQF5aL5Qktw7 Hi/Hg1kxz5BwOuCqbUfNNify4OUPoxO/wDaEyXQ7UNVKWDx9u9zCi6Hc3wrcGCZGLpWZ9K 4ZhGeDe0bi/tiFkCnD0Wna2VIdLllcg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1697199579; 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=SAe06IIfY0s0gKEFEWJWHYjzPGoen4WjkR1pGfwRJK8=; b=yrK62+RhQAdHcUnNw+sI+Tr8QXlcWPFWBM5Rvoz8EOS+lEdOJwfJvC+J7hSGQhyGXa69/A sTfGjkKceuXcIRAg== 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 D42E2139ED for ; Fri, 13 Oct 2023 12:19:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gCbMMts1KWU0bQAAMHmgww (envelope-from ) for ; Fri, 13 Oct 2023 12:19:39 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 3/4] [gdb/cli] Keep track of styling failures in source_cache Date: Fri, 13 Oct 2023 14:19:52 +0200 Message-Id: <20231013121953.25917-4-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231013121953.25917-1-tdevries@suse.de> References: <20231013121953.25917-1-tdevries@suse.de> MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -2.10 X-Spamd-Result: default: False [-2.10 / 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]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-3.00)[-1.000]; TO_DN_NONE(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-1.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.98%] 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 9757721e932..f8c98d7e23f 100644 --- a/gdb/source-cache.c +++ b/gdb/source-cache.c @@ -285,7 +285,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); @@ -295,7 +296,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. */