From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 46719385CC8C for ; Thu, 12 Oct 2023 14:46:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 46719385CC8C 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-out1.suse.de (Postfix) with ESMTPS id 455242189C for ; Thu, 12 Oct 2023 14:46:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1697122011; 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=barn6SG5rowjmQxPqRNSYHmRoeTsqGwB1l4HHOFrxqc=; b=V7qQUogAuL6xCUtTdNFXdW1ZCkL4yuBVoDl0PDyUu4qJGUs9BK1HA9lO56N5a5ueC3pjJt LUuYmUMVeBXCzzF4ad9174ucqE2QGZlMuIcjt15o/s3OdGyVe/mYvbWrASxVerrWC1qv3i 7q/tolqG5XTZ9aJeK6O/hppvRMJ0/LA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1697122011; 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=barn6SG5rowjmQxPqRNSYHmRoeTsqGwB1l4HHOFrxqc=; b=W5XD4cJh8CjPFYIwlwyIOk9YLTXJME+hiwmOlkyxpspfUg+53zxzWwvoNLccCiA8BFego2 M6AO7y21CzdJzVAQ== 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 359C9139F9 for ; Thu, 12 Oct 2023 14:46:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SJO8OtoGKGUVIAAAMHmgww (envelope-from ) for ; Thu, 12 Oct 2023 14:46:50 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 4/4] [gdb/cli] Allow source highlighting to be interrupted Date: Thu, 12 Oct 2023 16:47:07 +0200 Message-Id: <20231012144707.13931-4-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231012144707.13931-1-tdevries@suse.de> References: <20231012144707.13931-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -0.17 X-Spamd-Result: default: False [-0.17 / 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_LONG(-3.00)[-1.000]; 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(-1.07)[87.94%] X-Spam-Status: No, score=-12.3 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 List-Id: In PR cli/30934, a problem is reported where gdb becomes unresponsive for 2m13s because the GNU source-highlight library is taking a lot of time to annotate the source. This is due to a problem in the library [1], for which I've posted a patch [2], which brings down the annotation time to 3s. However, GDB should not become unresponsive due to such a problem. Fix this by installing a srchilite::HighlightEventListener that checks whether ^C was pressed, and if so abandons the highlighting by throwing an exception. Abandoning the highlighting looks like this to the user: ... $ gdb -q a.out -ex "b 56" Reading symbols from a.out... Breakpoint 1 at 0x400e2a: file test.cpp, line 56. (gdb) r Starting program: /data/vries/gdb/a.out Breakpoint 1, Solution::numOfSubarrays (this=0x7fffffffdbcf, arr=...) at \ test.cpp:56 ^C 56 return (int) t; (gdb) ... Note that line 56 still can be highlighted, just by pygments instead of source-highlight. It may or may not be a good idea to issue a warning that highlighting by source-highlight was interrupted, I've left it out for now. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30934 [1] https://savannah.gnu.org/bugs/?64747 [2] https://savannah.gnu.org/patch/index.php?10400 --- gdb/source-cache.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/gdb/source-cache.c b/gdb/source-cache.c index c29e5f4a210..3ce2ea9d779 100644 --- a/gdb/source-cache.c +++ b/gdb/source-cache.c @@ -37,6 +37,7 @@ #include #include #include +#include #endif /* The number of source files we'll cache. */ @@ -189,6 +190,21 @@ get_language_name (enum language lang) return nullptr; } +/* Class with notify function called during highlighting. */ + +class gdb_highlight_event_listener : public srchilite::HighlightEventListener +{ +public: + void notify(const srchilite::HighlightEvent &event) override + { + if (check_quit_flag ()) + { + /* Got SIGINT, interrupt highlighting, it may take too long. */ + throw_quit ("Interrupted"); + } + } +}; + #endif /* HAVE_SOURCE_HIGHLIGHT */ /* Try to highlight CONTENTS from file FULLNAME in language LANG_NAME using @@ -216,6 +232,9 @@ try_source_highlight (std::string &contents, const char *lang_name, { highlighter = new srchilite::SourceHighlight ("esc.outlang"); highlighter->setStyleFile ("esc.style"); + + static gdb_highlight_event_listener event_listener; + highlighter->setHighlightEventListener (&event_listener); } std::istringstream input (contents); @@ -304,13 +323,16 @@ source_cache::ensure (struct symtab *s) reasons: - the language is not supported. - the language cannot not be auto-detected from the file name. + - styling took too long and was interrupted by the user. - 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, so if styling took too long, and the user + interrupted it, and the source cache gets cleared, the user will + need to interrupt styling again. */ m_no_styling_files.insert (fullname); } } -- 2.35.3