From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id e5d2KtgOLWXwPy8AWB0awg (envelope-from ) for ; Mon, 16 Oct 2023 06:22:16 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=lancelotsix.com header.i=@lancelotsix.com header.a=rsa-sha256 header.s=2021 header.b=ZoquAtjP; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id A33B81E0C1; Mon, 16 Oct 2023 06:22:16 -0400 (EDT) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 8FD031E00F for ; Mon, 16 Oct 2023 06:22:14 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1E0683858D38 for ; Mon, 16 Oct 2023 10:22:14 +0000 (GMT) Received: from lndn.lancelotsix.com (lndn.lancelotsix.com [51.195.220.111]) by sourceware.org (Postfix) with ESMTPS id E56C93858D33 for ; Mon, 16 Oct 2023 10:22:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E56C93858D33 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=lancelotsix.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=lancelotsix.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E56C93858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=51.195.220.111 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697451722; cv=none; b=Kcm9l1DmdrQV+jyy+guoiCG28XaZQ1h+jOSPEsJxpM6USi21EYGKWE/ygZY80WkgOR/BEal4L3U0+W7IEGBXJl8nPgdjzfx1Om3ZZWhtiWtUD68MzD31fF1PIcNU+z3JIVMtT2KiP/kjESxD1tYa7AMhFly+qxABbYaF1uZol2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697451722; c=relaxed/simple; bh=RCEs6xM/5sv0vePzw9W7D+HxWaHLq475ZcnoTF77h3I=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=mNJDfh/f/4hQ6Z28PdMRsinA6+uYElj3SIIK8soin/RH2TnB7WAUtPeSPyvLVWtJ5/+YIGBlB+zAuanIxl80lZBJmMTKaxE+9JQHT0avmTgzJzO9FZvswaAa2wSve8+IUAKTqclchVRpzDjS5iO1ZLZwZfC6avpZZtexFIqeHTk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from octopus (cust120-dsl54.idnet.net [212.69.54.120]) by lndn.lancelotsix.com (Postfix) with ESMTPSA id 2F34C84CB8; Mon, 16 Oct 2023 10:22:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lancelotsix.com; s=2021; t=1697451720; bh=RCEs6xM/5sv0vePzw9W7D+HxWaHLq475ZcnoTF77h3I=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZoquAtjPbTNEuAoHnuBBxcGEJdAh4sL5ZtMZsMUYOqh6pThqX97SF3rlaPDMjce0g 4YuErNdPzCJawiavEaX34tGN7dnHUL/D0jBA//+Icqzp+etwEWhvffPQSgASpwl/UG uzLb5QjdtkAwayz9g/lieSqjGjpCGJlk2vRB3SA1v+cZb22gw2Pg6WiNLUgvXgQU/B WT4Dkx+3MBwRZh0sT5Yjg3aNaAM647nSfdJ/3nHQoVQ2Vx1FRTWR1yIv3CZIE4UZ6T 3owqVLeaP/yW3duCIC6V/q+0gxJqErClSsRT/6UNwo1vTfLFe/qjVvJhke8pgXEo9C /xgm22aKlFLmg== Date: Mon, 16 Oct 2023 11:21:55 +0100 From: Lancelot SIX To: Tom de Vries Cc: gdb-patches@sourceware.org Subject: Re: [PATCH v3 4/4] [gdb/cli] Allow source highlighting to be interrupted Message-ID: <20231016102128.tc5ihxxbrteuu3le@octopus> References: <20231016091748.26247-1-tdevries@suse.de> <20231016091748.26247-5-tdevries@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231016091748.26247-5-tdevries@suse.de> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.2 (lndn.lancelotsix.com [0.0.0.0]); Mon, 16 Oct 2023 10:22:00 +0000 (UTC) X-Spam-Status: No, score=-12.0 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+public-inbox=simark.ca@sourceware.org Hi Tom, I have one minor nit below. On Mon, Oct 16, 2023 at 11:17:48AM +0200, Tom de Vries wrote: > 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 > - asks the user whether it should interrupt highlighting, and if so > - abandons the highlighting by throwing an exception. > > Interrupting 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 () at test.cpp:56 > ^CCancel source styling using GNU source highlight of /data/vries/gdb/test.cpp? > ([y] or n) y > 56 return (int) t; > (gdb) > ... > Note that line 56 still can be highlighted, just by pygments instead of > source-highlight. > > Tested on x86_64-linux. > > Co-Authored-By: Lancelot Six > > 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 | 68 ++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 66 insertions(+), 2 deletions(-) > > diff --git a/gdb/source-cache.c b/gdb/source-cache.c > index aa8e40425c2..39d8bcf7aec 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,48 @@ get_language_name (enum language lang) > return nullptr; > } > > +/* Class with notify function called during highlighting. */ > + > +class gdb_highlight_event_listener : public srchilite::HighlightEventListener > +{ > +public: > + gdb_highlight_event_listener (const std::string &fullname) > + : m_fullname (fullname) > + { > + } > + > + void notify(const srchilite::HighlightEvent &event) override ^ A space is missing here before the "(". Otherwise, and FWIW, this LGTM. Best, Lancelot. > + { > + /* If the terminal is ours, we can ask the user a question and get an > + answer. */ > + gdb_assert (target_terminal::is_ours ()); > + > + if (!check_quit_flag ()) > + { > + /* User didn't press ^C, nothing to do. */ > + return; > + } > + > + /* Ask the user what to do. */ > + int resp > + = yquery (_("Cancel source styling using GNU source highlight of %s?\n"), > + m_fullname.c_str ()); > + if (!resp) > + { > + /* Continue highlighting. */ > + return; > + } > + > + /* Interrupt highlighting. Note that check_quit_flag clears the > + quit_flag, so we have to set it again. */ > + set_quit_flag (); > + QUIT; > + } > + > +private: > + const std::string &m_fullname; > +}; > + > #endif /* HAVE_SOURCE_HIGHLIGHT */ > > /* Try to highlight CONTENTS from file FULLNAME in language LANG using > @@ -223,9 +266,27 @@ try_source_highlight (std::string &contents ATTRIBUTE_UNUSED, > highlighter->setStyleFile ("esc.style"); > } > > + gdb_highlight_event_listener event_listener (fullname); > + highlighter->setHighlightEventListener (&event_listener); > + /* Make sure that the highlighter's EventListener doesn't become a > + dangling pointer. */ > + auto clear_event_listener = make_scope_exit ([]() > + { > + highlighter->setHighlightEventListener (nullptr); > + }); > + > std::istringstream input (contents); > std::ostringstream output; > - highlighter->highlight (input, output, lang_name, fullname); > + { > + /* We want to be able to interrupt the call to source-highlight. If > + the current quit_handler is infrun_quit_handler, pressing ^C is > + ignored by QUIT (assuming target_terminal::is_ours), so install the > + default quit handler. */ > + scoped_restore restore_quit_handler > + = make_scoped_restore (&quit_handler, default_quit_handler); > + > + highlighter->highlight (input, output, lang_name, fullname); > + } > contents = std::move (output).str(); > styled = true; > } > @@ -304,13 +365,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 >