From patchwork Wed Oct 18 17:11:48 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: 78111 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 4D74138582A1 for ; Wed, 18 Oct 2023 17:11:40 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id DECF63858CDB for ; Wed, 18 Oct 2023 17:11:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DECF63858CDB 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 DECF63858CDB 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=1697649081; cv=none; b=PUPqURelsd+UlDpBB5wBYc8TzCZEXJI3/lrdWeZ6zS9S9nhZqZmlP22hxx/lYcEasQNEisJ0f3xB5kAUPZN2mNF44ZlgQm1DGO0W1xQo/hqd8cOvAuqcyk6p5aYwuae41LEedm6AkrVU5F2yi0DsgZO4nbeVKTAAhks3YxNUg6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697649081; c=relaxed/simple; bh=pjffVP5WRspoGvt2RbRFsUIUxNXM5hAbTORRwk5FlLY=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=a+ZO7AiPWLDf1j0zjVPDLp/Nh30/XGxY3YGdm+odNpp0qtiKIAYCPj5xWU3YH7GN4DxxGSElWnwj4ZfZH1VyelSjteZVtx7m805ffAia7ou514+Zw5715kQxVo8Kx/AI7lIJ5k2w3Y4AB4qPjdAyvPDuY1DAb1nAO9NKCa/5jF0= 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 A371021B39 for ; Wed, 18 Oct 2023 17:11:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1697649078; 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=rBFJg8CKoCci9q4HeOKOEtd+QYy2UzAmGjLw6UKxGVM=; b=R8BYy0+Op2Dtq5chFcLqLxugtzRYk5O7ZCn22lhsqNA3C413B3/DlKqgJQYssADW5CVA3B NoeBlyw6lVDdkBsQ+kH3W+TpEx/0vY3lidWYsunM8oMeRo9fp//FSMu3KefJMkTY/s5ok/ ir0pWm4i2INIbYKUb/o1XBZqLNxc0zs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1697649078; 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=rBFJg8CKoCci9q4HeOKOEtd+QYy2UzAmGjLw6UKxGVM=; b=D7eqnzAQ4Qpi0NvtPKGWLlO7rGXG5HSFSdl6ObSjEoe3PIc9/mCe+ZhbUnOm1+CHUD6iV6 CL6NwYDTxrk4OoAg== 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 8F207139E0 for ; Wed, 18 Oct 2023 17:11:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wPzVIbYRMGXZLQAAMHmgww (envelope-from ) for ; Wed, 18 Oct 2023 17:11:18 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v4 1/4] [gdb/cli] Add gnu-source-highlight selftest Date: Wed, 18 Oct 2023 19:11:48 +0200 Message-Id: <20231018171151.25427-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231018171151.25427-1-tdevries@suse.de> References: <20231018171151.25427-1-tdevries@suse.de> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -2.01 X-Spamd-Result: default: False [-2.01 / 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(-2.91)[99.62%] 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 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 Add a selftest gnu-source-highlight: ... $ gdb -q -batch -ex "maint selftest gnu-source-highlight" Running selftest gnu-source-highlight. Ran 1 unit tests, 0 failed ... Tested on x86_64-linux. --- gdb/source-cache.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/gdb/source-cache.c b/gdb/source-cache.c index 99be3334803..7d8339a16df 100644 --- a/gdb/source-cache.c +++ b/gdb/source-cache.c @@ -39,6 +39,10 @@ #include #endif +#if GDB_SELF_TEST +#include "gdbsupport/block-signals.h" +#endif + /* The number of source files we'll cache. */ #define MAX_ENTRIES 5 @@ -244,6 +248,62 @@ try_source_highlight (std::string &contents ATTRIBUTE_UNUSED, #endif /* HAVE_SOURCE_HIGHLIGHT */ } +#ifdef HAVE_SOURCE_HIGHLIGHT +#if GDB_SELF_TEST +namespace selftests +{ +static void gnu_source_highlight_test () +{ + const std::string prog + = ("int\n" + "foo (void)\n" + "{\n" + " return 0;\n" + "}\n"); + const std::string fullname = "test.c"; + std::string styled_prog; + + /* Make sure that the user can't raise SIGTERM and SIGINT. */ + gdb::block_signals blocker; + + /* If SIGINT or SIGTERM is pending, handle it as usual. */ + QUIT; + gdb_assert (!sync_quit_force_run); + + /* In some cases, QUIT doesn't handle SIGINT. If so, bail out. */ + if (check_quit_flag ()) + { + set_quit_flag (); + return; + } + gdb_assert (!check_quit_flag ()); + + bool res = false; + bool saw_exception = false; + styled_prog = prog; + try + { + res = try_source_highlight (styled_prog, language_c, fullname); + } + catch (...) + { + saw_exception = true; + } + + SELF_CHECK (!saw_exception); + if (res) + SELF_CHECK (prog.size () < styled_prog.size ()); + else + SELF_CHECK (prog == styled_prog); + + /* Make sure there are no SIGINT or SIGTERM pending. */ + sync_quit_force_run = false; + check_quit_flag (); +} +} +#endif /* GDB_SELF_TEST */ +#endif /* HAVE_SOURCE_HIGHLIGHT */ + /* See source-cache.h. */ bool @@ -475,5 +535,9 @@ styling to source code lines that are shown."), #if GDB_SELF_TEST selftests::register_test ("source-cache", selftests::extract_lines_test); +#ifdef HAVE_SOURCE_HIGHLIGHT + selftests::register_test ("gnu-source-highlight", + selftests::gnu_source_highlight_test); +#endif #endif } From patchwork Wed Oct 18 17:11:49 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: 78110 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 1162A3857803 for ; Wed, 18 Oct 2023 17:11:40 +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 [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id DEB733858D33 for ; Wed, 18 Oct 2023 17:11:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DEB733858D33 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 DEB733858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2178:6::1d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697649081; cv=none; b=Ia0ppo8fhVQuBmgwFXwzEl9Wy2A5Lrbf7lrsIZ58kWL6mt6f36A9tGBWCPodN/uhsDMYXMejDojhBH2WaaXX4gDzwDKycyqZu6nwCcuPMlyP1pm2s/O+6pNJs3XXtAgxoKFuMoQfnmQBNTTxNyJY3eSb1ZK743mIo/RIDbQEf5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697649081; c=relaxed/simple; bh=imr7uGSQZkyRqdSbJwPIb1Ky5BqTM4TyKO0ErWLga24=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=gnDeQVNvgPqycmBz+dDK+Qipy0vyl1zv92V/tNUw519sMaPOJqo6lcsQ4NhPfvzwk5Kiqlph+QQupXQonU7NVkAxHeleI2GDDc1hEwu6ebVK9uc1ncok7neCunvYcUXWRwPbVeQhloJd8Gudti8tmMxcz0aB/3oEYSwOFYEcUSI= 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 B9A851FD7E for ; Wed, 18 Oct 2023 17:11:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1697649078; 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=jqXEei0dnJdPgrjknG8tByUBjjb6J6VOdW68tP2Klag=; b=KiJJuoEJvc4yszBVYl+egJZltfz2ucDPXXFOu1Wm1xKWkeufe2mzNMvZRsBcrgyXu2uzvw uttUXsZ88G0XVoFJLBaWqA6o0yF2hMmXKDF9J1mbEEpBMK4DkZ/S1q8b/6lJXNccPzjvPj 0N94n4OkVsKXWdUqh3yjZB6aROwq9rI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1697649078; 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=jqXEei0dnJdPgrjknG8tByUBjjb6J6VOdW68tP2Klag=; b=5e/EzpcX+vX76/X3BzYePR2eGqKsrwfd3CN4vVI2qZA7Ax8Z/61cWwOXfWGThiotRfPRuG VBqywIQhDuwZmkAg== 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 A5F7313A6B for ; Wed, 18 Oct 2023 17:11:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4GqDJ7YRMGXZLQAAMHmgww (envelope-from ) for ; Wed, 18 Oct 2023 17:11:18 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v4 2/4] [gdb/cli] Allow source highlighting to be interrupted Date: Wed, 18 Oct 2023 19:11:49 +0200 Message-Id: <20231018171151.25427-3-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231018171151.25427-1-tdevries@suse.de> References: <20231018171151.25427-1-tdevries@suse.de> MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -1.92 X-Spamd-Result: default: False [-1.92 / 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(-2.82)[99.24%] 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 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 Currently highlighting by the GNU source-highlight library cannot be interrupted by either SIGINT or SIGTERM. Fix this by installing a srchilite::HighlightEventListener that: - checks whether SIGINT or SIGTERM was issued, and if so - interrupts the command. Interrupting the highlighting with SIGINT (using ^C) looks like this to the user: ... $ gdb -q a.out Reading symbols from a.out... (gdb) list ^CQuit (gdb) ... and with SIGTERM (using kill -SIGTERM $(pidof gdb)): ... $ gdb -q a.out Reading symbols from a.out... (gdb) list $ ... Tested on x86_64-linux. --- gdb/source-cache.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/gdb/source-cache.c b/gdb/source-cache.c index 7d8339a16df..f04a9d42e0d 100644 --- a/gdb/source-cache.c +++ b/gdb/source-cache.c @@ -37,6 +37,7 @@ #include #include #include +#include #endif #if GDB_SELF_TEST @@ -193,6 +194,17 @@ 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 + { + QUIT; + } +}; + #endif /* HAVE_SOURCE_HIGHLIGHT */ /* Try to highlight CONTENTS from file FULLNAME in language LANG using @@ -225,6 +237,9 @@ try_source_highlight (std::string &contents ATTRIBUTE_UNUSED, { 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); @@ -233,6 +248,16 @@ try_source_highlight (std::string &contents ATTRIBUTE_UNUSED, contents = std::move (output).str (); styled = true; } + catch (const gdb_exception_forced_quit &) + { + /* SIGTERM, rethrow. */ + throw; + } + catch (const gdb_exception_quit &) + { + /* SIGINT, rethrow. */ + throw; + } catch (...) { /* Source Highlight will throw an exception if @@ -299,6 +324,51 @@ static void gnu_source_highlight_test () /* Make sure there are no SIGINT or SIGTERM pending. */ sync_quit_force_run = false; check_quit_flag (); + + /* Pretend user send SIGTERM. */ + set_force_quit_flag (); + + bool saw_forced_quit = false; + res = false; + styled_prog = prog; + try + { + res = try_source_highlight (styled_prog, language_c, "test.c"); + } + catch (const gdb_exception_forced_quit &ex) + { + saw_forced_quit = true; + } + + SELF_CHECK (saw_forced_quit); + SELF_CHECK (!res); + SELF_CHECK (prog == styled_prog); + + /* Make sure there are no SIGINT or SIGTERM pending. */ + sync_quit_force_run = false; + check_quit_flag (); + + /* Pretend user send SIGINT. */ + set_quit_flag (); + + bool saw_quit = false; + res = false; + styled_prog = prog; + try + { + res = try_source_highlight (styled_prog, language_c, "test.c"); + } + catch (const gdb_exception_quit &ex) + { + saw_quit = true; + } + SELF_CHECK (saw_quit); + SELF_CHECK (!res); + SELF_CHECK (prog == styled_prog); + + /* Make sure there are no SIGINT or SIGTERM pending. */ + sync_quit_force_run = false; + check_quit_flag (); } } #endif /* GDB_SELF_TEST */ From patchwork Wed Oct 18 17:11:50 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: 78112 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 275253857352 for ; Wed, 18 Oct 2023 17:12:08 +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 [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 2B25F3858C5E for ; Wed, 18 Oct 2023 17:11:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B25F3858C5E 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 2B25F3858C5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2178:6::1d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697649081; cv=none; b=EsQafsdYrM5PGMzbvalntaGoDtJ9fViGKugZY92cYyWiXZLyliMpY71AQbjkgVi5Oi5WlDyo0+y5aM5Q91+YoY9Yhxr5k7ADRw4SHkrab/jormSz0Lshbk47cimIz9B4s5ixCRvzMPuS6UDK+G0xZK+Qzv14C6lyaSbVM5etAVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697649081; c=relaxed/simple; bh=CX8XXtnLQVr4A4M07UvJrxO/smXWrH2Q+/1tstRyzko=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=jtrddaxey1MV4i+72KYrtdFvGgD9klI9ftzzvgpkivzHOu3X6im09AnQrvRJihZoW0FnrO3KeXWWWQddnK/KZDpDAMFvjKwgSNbv0SqjV3IPSG3MHVKlb/DLtXjokGYyFDlvJQ/xdSMXYM8DovoZ6bWNSTezkFWvF/pEDfBi5O4= 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 D093E1FD80 for ; Wed, 18 Oct 2023 17:11:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1697649078; 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=VOdCo68PyBJeQIJkP37EM3+FkJ1W06sraevE/gwmzNk=; b=HOj/WzfcSncaWdkY8jL+7Z4PWOmaAzuuZNZbAgK6Jw5FGYdf2WpEGC7jDiHsvIFZHMb0hX cL671Ec1FUjDG5YlaE9vmyXdGzqbtWkgTtdsgH9QPJX5ACR6v+LgT/jCDgqXup96stmZkl dTHXRxX6Gse0WY/8LP8+7smw1zn8+v8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1697649078; 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=VOdCo68PyBJeQIJkP37EM3+FkJ1W06sraevE/gwmzNk=; b=kbZZDlD27RE+3pdYnJi5YZk0lPCfZpshuSFhBORdDt1uV5IS6St+s5NY4s4RN89klP0v/v 4AFpLpj3+qzMTxCw== 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 BD951139E0 for ; Wed, 18 Oct 2023 17:11:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KCwpLbYRMGXZLQAAMHmgww (envelope-from ) for ; Wed, 18 Oct 2023 17:11:18 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v4 3/4] [gdb/cli] Allow source highlighting to be interrupted (continued) Date: Wed, 18 Oct 2023 19:11:50 +0200 Message-Id: <20231018171151.25427-4-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231018171151.25427-1-tdevries@suse.de> References: <20231018171151.25427-1-tdevries@suse.de> MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -0.73 X-Spamd-Result: default: False [-0.73 / 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(-1.63)[92.63%] 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 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 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: ... $ gdb -q a.out -ex "b 56" Reading symbols from a.out... Breakpoint 1 at 0x400e2a: file test.cpp, line 56. (gdb) run Starting program: /data/vries/gdb/a.out Breakpoint 1, Solution::numOfSubarrays () at test.cpp:56 <... wait for it ...> 56 return (int) t; (gdb) ... 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. The previous patch allows us to interrupt a list command during highlighting by either SIGTERM or SIGINT. In this case, we can use SIGTERM to interrupt the run command, but not SIGINT. This is due to the fact that the infrun_quit_handler is still active. The purpose of infrun_quit_handler is to: - if !target_terminal::is_ours, pass ^C to the inferior, and - if target_terminal::is_ours, ignore ^C. If gdb is executing say a continue in the background, it generates events and we don't want to interrupt the handling of these events. In this case however, the reason target_terminal::is_ours is not because there's background execution, but because normal_stop has decided that we have stopped execution, and it's preparing to hand back control to GDB. Fix this by switching back to the default_quit_handler during notify_normal_stop. 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/infrun.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index 4fde96800fb..816a76a1b2c 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -9063,12 +9063,23 @@ normal_stop () if (saved_context.changed ()) return true; - /* Notify observers about the stop. This is where the interpreters - print the stop event. */ - notify_normal_stop ((inferior_ptid != null_ptid - ? inferior_thread ()->control.stop_bpstat - : nullptr), - stop_print_frame); + { + /* If the current quit_handler is infrun_quit_handler, and + target_terminal::is_ours, pressing ^C is ignored by QUIT. See + infrun_quit_handler for an explanation. At this point, there's + no need for this behaviour anymore, and we want to be able to interrupt + notify_normal_stop, so install the default_quit_handler. */ + scoped_restore restore_quit_handler + = make_scoped_restore (&quit_handler, default_quit_handler); + + /* Notify observers about the stop. This is where the interpreters + print the stop event. */ + notify_normal_stop ((inferior_ptid != null_ptid + ? inferior_thread ()->control.stop_bpstat + : nullptr), + stop_print_frame); + } + annotate_stopped (); if (target_has_execution ()) From patchwork Wed Oct 18 17:11:51 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: 78113 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 3C54A385735A for ; Wed, 18 Oct 2023 17:12:09 +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 207F23858C52 for ; Wed, 18 Oct 2023 17:11:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 207F23858C52 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 207F23858C52 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=1697649081; cv=none; b=wONbnDNBF62bpdAQPyBM9DkS+2FhNmxOk73pfZAvTIxFqj3h0upZJ9YRUHiI6H2cvOVklk4WBvYN7zSaJzLEURF3PV2zVUHveuRWfd6dbmXcDC8W9DxMuoblNM2oWGL/tqs3HKNOMF24znCm5ikowfBG5C4tSvSWxvA91H+eauU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697649081; c=relaxed/simple; bh=SffZhydMr+rS3aO3otJW1tYxUXq5Qu+YywmZOSkqxfI=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=IVN2DFTSlfemqIiwWtiPr+zLsjOcs8qfRiBxeV0tw3R0MV5SyNokTCamqdzXGYs6caz9V0LpYNZY+RaoLGJckvfDb8ZjY9aeC0su8vYJwJI20taT3aiQvpm204wX0VH4pYBJ7pOOTbhTwUcOjaXPMTxdbsXCdWBsSsEd5L/a9zE= 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 E9B901FD82 for ; Wed, 18 Oct 2023 17:11:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1697649078; 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=ZBlKxh8KKSMbmkS6ZgtB7d9xZZYiLWpGfzivHP7TTy0=; b=zi0sQomjF8t+rhUolj2CTPdfSzjSM/7EKKzJfuDmKNMaYv52+q2MiMfY5kZ2i9Bxd3VW5a zF8sq0dPbstguP5Z4u65QiwTn1kZlE3Q352H7RpSnSk4nIz8Jy659NW6zFtM0TjPpgslvg SyDTxjVjn2fRq2A96+R3Rw3AL++nun4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1697649078; 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=ZBlKxh8KKSMbmkS6ZgtB7d9xZZYiLWpGfzivHP7TTy0=; b=JYdX1gG2Mrue9xsWx3w7CrB+2aoHtlQ+VJaTEW9X47KbZLgbl8rOf0904wjvoNl+WIuHbd J2Kwt4hnRrZYrcAw== 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 D523F13A6B for ; Wed, 18 Oct 2023 17:11:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ALfoMrYRMGXZLQAAMHmgww (envelope-from ) for ; Wed, 18 Oct 2023 17:11:18 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v4 4/4] [gdb/cli] Ask if source highlighting should be interrupted Date: Wed, 18 Oct 2023 19:11:51 +0200 Message-Id: <20231018171151.25427-5-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231018171151.25427-1-tdevries@suse.de> References: <20231018171151.25427-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)[100.00%] 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 When source highlighting is done using the GNU source-highlight library, and it takes a long time, it can be interrupted using ^C, but that cancels the rest of the command: ... $ 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 ^C (gdb) ... That means in this case that the user doesn't get to see the line gdb stopped at. This is especially problematic if the user actually meant to interrupt the inferior execution. Instead, ask the user whether highlighting needs to be interrupted, and if so, interrupt only the highlighting part, and continue with the command: ... $ 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 after cancelling, line 56 still can be highlighted, just by pygments instead of source-highlight. Co-Authored-By: Lancelot Six Tested on x86_64-linux. --- gdb/source-cache.c | 64 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/gdb/source-cache.c b/gdb/source-cache.c index f04a9d42e0d..b742478c4c8 100644 --- a/gdb/source-cache.c +++ b/gdb/source-cache.c @@ -42,6 +42,7 @@ #if GDB_SELF_TEST #include "gdbsupport/block-signals.h" +#include "top.h" #endif /* The number of source files we'll cache. */ @@ -199,10 +200,51 @@ get_language_name (enum language lang) class gdb_highlight_event_listener : public srchilite::HighlightEventListener { public: + explicit gdb_highlight_event_listener (const std::string &fullname) + : m_fullname (fullname) + { + } + void notify (const srchilite::HighlightEvent &event) override { + if (sync_quit_force_run) + { + /* Handle SIGTERM. */ + QUIT; + gdb_assert_not_reached (""); + } + + /* If target_terminal::is_ours, we can ask the user a question and get an + answer. We're not sure if or how !target_terminal::is_ours can happen. + Assert to catch it happening. Note that we're asserting before + checking the quit flag, such that we don't rely on the user pressing + ^C so detect this. */ + 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?"), + 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 */ @@ -237,11 +279,14 @@ try_source_highlight (std::string &contents ATTRIBUTE_UNUSED, { highlighter = new srchilite::SourceHighlight ("esc.outlang"); highlighter->setStyleFile ("esc.style"); - - static gdb_highlight_event_listener event_listener; - highlighter->setHighlightEventListener (&event_listener); } + gdb_highlight_event_listener event_listener (fullname); + highlighter->setHighlightEventListener (&event_listener); + /* Make sure that the highlighter's EventListener doesn't become a + dangling pointer. */ + SCOPE_EXIT { highlighter->setHighlightEventListener (nullptr); }; + std::istringstream input (contents); std::ostringstream output; highlighter->highlight (input, output, lang_name, fullname); @@ -255,8 +300,7 @@ try_source_highlight (std::string &contents ATTRIBUTE_UNUSED, } catch (const gdb_exception_quit &) { - /* SIGINT, rethrow. */ - throw; + /* SIGINT, ignore. */ } catch (...) { @@ -348,6 +392,9 @@ static void gnu_source_highlight_test () sync_quit_force_run = false; check_quit_flag (); + scoped_restore save_confirm + = make_scoped_restore (&confirm, false); + /* Pretend user send SIGINT. */ set_quit_flag (); @@ -362,7 +409,7 @@ static void gnu_source_highlight_test () { saw_quit = true; } - SELF_CHECK (saw_quit); + SELF_CHECK (!saw_quit); SELF_CHECK (!res); SELF_CHECK (prog == styled_prog); @@ -434,13 +481,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); } }