From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 3E5153858D33 for ; Wed, 18 Oct 2023 17:21:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3E5153858D33 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 3E5153858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2178:6::1c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697649683; cv=none; b=OIbKxnI06OmZHAM6PjF+7o1Xexc95QM1yY9kJ3surrJ+nusuKcI22sVu+OazqPtHq7x76koEU5bXEp7yqZJvcFR7qIbdMt7AaQSVkX89mz6xYRNih97NKnlg4EHTRFzgKHBi/m9kkQnVNQqEvYfwWR4hisdUKR2Yky/muwheNJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697649683; c=relaxed/simple; bh=JxRzCJUZSxZULhvBwSvxxC5V52Lel+TLQGZCV4cgiug=; h=DKIM-Signature:DKIM-Signature:Message-ID:Date:MIME-Version: Subject:To:From; b=vZSdHTXa8apcaNG0WWGG5+Nynqgq2MLxwe8izEHWof0HBL2ODX+BdEwqOVDOWp2LxgCDqFm44JFFOKZbex5bTyxIvOQSCmYBo2vpDPQ5w/FWfoL/EJ2rKHLnCTlIK9IwBvUwoXHkx6qz/Q9/+q3eLG/w+DHQU2kDojw93ZLYoJs= 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-out1.suse.de (Postfix) with ESMTPS id 10927219EC; Wed, 18 Oct 2023 17:21:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1697649681; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=53sfsu7lKRZVo2m74be/eqoA4zUZJNemUZD4R4IdSKo=; b=bS5iyDcZ04lE90pwHlJbWO03t1J8m7ErSiH4w1u6pGHacMHRuaMRlSTBJwu7d+qM7QpX3b YasNVsr0BkPfNyIRHREIxTFAnuZ8gfY4uf7DtU+QNhpyHLqo2VcgZY5nho2xUO+tZWWlvD opxjlKI/NZhM3hG5mdyQdAn0h+o6UP0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1697649681; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=53sfsu7lKRZVo2m74be/eqoA4zUZJNemUZD4R4IdSKo=; b=UfWKa1VFbHOaWmnuYr4JPx4pmlY1Jww9CGVwUMlprHkCn8966lJwRCaMVz05fvyja8uGEB cBxPMd/jqcZlSNAw== 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 F0BF013780; Wed, 18 Oct 2023 17:21:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Pg+YORAUMGVoMgAAMHmgww (envelope-from ); Wed, 18 Oct 2023 17:21:20 +0000 Message-ID: Date: Wed, 18 Oct 2023 19:21:54 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 4/4] [gdb/cli] Allow source highlighting to be interrupted Content-Language: en-US To: Pedro Alves , gdb-patches@sourceware.org References: <20231016091748.26247-1-tdevries@suse.de> <20231016091748.26247-5-tdevries@suse.de> <965cd924-0980-498e-89f4-d952c812dfc0@palves.net> From: Tom de Vries In-Reply-To: <965cd924-0980-498e-89f4-d952c812dfc0@palves.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -7.09 X-Spamd-Result: default: False [-7.09 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; XM_UA_NO_VERSION(0.01)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-3.00)[-1.000]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCPT_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-Spam-Status: No, score=-11.9 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: On 10/17/23 02:20, Pedro Alves wrote: > Hi, > > On 2023-10-16 10:17, Tom de Vries wrote: > >> 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) > > A ctor with one parameter should usually be "explicit". > Hi, thanks for the review. Done. >> + : m_fullname (fullname) >> + { >> + } >> + >> + void notify(const srchilite::HighlightEvent &event) override >> + { >> + /* If the terminal is ours, we can ask the user a question and get an >> + answer. */ >> + gdb_assert (target_terminal::is_ours ()); > > How sure are we that we won't ever print source listings while the inferior > has the terminal (either both for I/O, or just for input with is_ours_for_output)? > I'm not too sure. > I was trying to think of scenarios, but not much came out. I'm imagining maybe a > Python script hooking into events, internal breakpoints, or timers, or some such and > printing sources while the inferior is running? OTOH, that printing might well come out > badly formatted as the Python layer doesn't expose target_terminal::{ours,ours_for_output}() > to Python. Maybe we don't need to worry about it. At least we have the assertion. > I've gone back and forth a bit about this, I don't particularly like the assert, but I like the alternatives less I guess. I've thought about adding a way to enable the assert in development builds (to detect it if the situation happens) and disable it in releases (to give end users a stable debugger). But I've left it as is for now. > If we ever do manage to get here with "!target_terminal::ours ()" , then we'd want to > be sure that a Ctrl-C that happens to be pressed exactly while GDB is printing > the sources isn't immediately interpreted as a request to cancel source highlight, > because the source highlight may well end up being quickly, and the user was just > unlucky enough that Ctrl-C was pressed in that short window. In that scenario, it > is better to assume that the source highlight will finish quickly, and that the > Ctrl-C is meant to interrupt the inferior. The remote target handles this by > only asking the user the second time the user presses > Ctrl-C -- see remote.c:remote_target::remote_serial_quit_handler(). > But we can worry about this if we ever come to it, assuming it isn't really expected > to end up printing sources while the inferior is running. It's just unfortunate that > if such case does exits, reproducing it won't be super easy, as it'll be timing > dependent. > > Assuming we don't want to bother with that for now, the approach in the patch seems > fine to me. A few nits/comments below. > >> + >> + 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 ()); > > I don't think it's usual for secondary prompts / queries to end in newline, and then > the "(y or n)" appearing on the next line? I think most (all?) other queries / secondary > prompts leave the "(y or n)" on the same line as the question text? > Done. > Also, I think we should skip the query if sync_quit_force_run is set, so that > if we got a SIGTERM we abort quickly and end up in the top level exiting GDB ASAP. > To make that work properly we'll need to tweak try_source_highlight to not swallow > gdb_exception_forced_quit, though, it currently swallows _everything_. > > Thanks, good point, I overlooked that. I've restructured the patch into a v4 patch series, and added handling of SIGTERM. >> + 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; > > It doesn't hurt to do it this way, but the QUIT idea looked more appealing when it seemed > like you could get rid of the check_quit_flag() call too, in v1. With the query in the middle, > the end result is just that default_quit_handler ends up in "quit ();", which you could call > directly here: > > /* Interrupt highlighting. */ > quit (); > > But OTOH, the default_quit_handler approach is more future proof, especially considering > SIGTERM handling in maybe_quit and quit, which would move elsewhere someday. So yeah, hmm, > better do it the default_quit_handler/QUIT way after all. > OK :) >> + } >> + >> +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); >> + }); > > clear_event_listener is never used, so this could instead be a simpler SCOPE_EXIT: > > SCOPE_EXIT { highlighter->setHighlightEventListener (nullptr); }; > Done. I've posted the v4 here ( https://sourceware.org/pipermail/gdb-patches/2023-October/203391.html ). Thanks, - Tom