From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v5 6/6] [gdb/cli] Simplify gdb_highlight_event_listener::notify
Date: Tue, 24 Oct 2023 11:49:33 +0200 [thread overview]
Message-ID: <20231024094933.12009-7-tdevries@suse.de> (raw)
In-Reply-To: <20231024094933.12009-1-tdevries@suse.de>
Currently gdb_highlight_event_listener::notify does things more complicated
than necessary because of the unittest.
In more detail, the unit test cannot handle it if force_quit is called.
Fix this by making signal_handler_selftest capture force_quit.
This causes the question also to be asked for the SIGTERM case, so it leaves a
less attractive command line after terminating:
...
$ gdb -q a.out -ex "list"
Reading symbols from a.out...
$ ncel source styling using GNU source highlight of test.cpp? ([y] or n)
...
This patch currently makes gdb.gdb/unittest.exp fail:
...
FAIL: gdb.gdb/unittest.exp: no executable loaded: \
maintenance selftest (got interactive prompt)
FAIL: gdb.gdb/unittest.exp: reversed initialization: \
selftest not dependent on initialization order
FAIL: gdb.gdb/unittest.exp: executable loaded: \
maintenance selftest (got interactive prompt)
...
because the testsuite triggers on the highlighting question.
Since this patch is an RFC at this point, I haven't invested time in addressing
this yet.
Tested on x86_64-linux.
---
gdb/event-top.c | 4 ++++
gdb/source-cache.c | 29 +++++++++++------------------
gdb/top.c | 7 +++++++
gdb/top.h | 7 +++++++
4 files changed, 29 insertions(+), 18 deletions(-)
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 8c01c0902ea..b4b3fec5cdc 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -1235,6 +1235,8 @@ signal_handler_selftest::signal_handler_selftest ()
m_saved_sigint_handler = signal (SIGINT, SIG_IGN);
m_saved_sigterm_handler = signal (SIGTERM, SIG_IGN);
+ capture_quit_force = true;
+
/* Only code from the selftest itself can cause the SIGINT or SIGTERM signal
handlers to run. */
m_valid = true;
@@ -1242,6 +1244,8 @@ signal_handler_selftest::signal_handler_selftest ()
signal_handler_selftest::~signal_handler_selftest ()
{
+ capture_quit_force = false;
+
/* Make sure that no pending SIGINT or SIGTERM escapes from the
selftest. */
clear_pending_sigint ();
diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index 6f514cbba3e..032a5d5b234 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -221,25 +221,18 @@ class gdb_highlight_event_listener : public srchilite::HighlightEventListener
return;
}
- /* If we got a SIGTERM, skip querying. This isn't strictly
- necessary as yquery runs a nested event loop for the secondary
- prompt, which runs pending async signal handlers. However,
- this helps with the unit test, which makes sure that the quit
- call at the bottom throws a gdb_exception_forced_quit exception
- and that our caller doesn't swallow it. Note we may receive a
- SIGTERM in between the query and the quit call. */
- if (!sync_quit_force_run)
+ /* Ask the user what to do. If we got a SIGTERM, don't skip querying.
+ Skipping isn't necessary as yquery runs a nested event loop for the
+ secondary prompt, which runs pending async signal handlers. Note we
+ may receive a SIGTERM in between the query and the quit call. */
+ int resp
+ = (yquery
+ (_("Cancel source styling using GNU source highlight of %s? "),
+ m_fullname.c_str ()));
+ if (!sync_quit_force_run && !resp)
{
- /* 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;
- }
+ /* Continue highlighting. */
+ return;
}
/* Interrupt highlighting. Note we don't abort via the QUIT macro
diff --git a/gdb/top.c b/gdb/top.c
index 5028440b671..03b9ec5e1ae 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1725,12 +1725,19 @@ undo_terminal_modifications_before_exit (void)
current_ui = saved_top_level;
}
+#if GDB_SELF_TEST
+bool capture_quit_force;
+#endif
/* Quit without asking for confirmation. */
void
quit_force (int *exit_arg, int from_tty)
{
+#if GDB_SELF_TEST
+ if (capture_quit_force)
+ throw_forced_quit ("capture_quit_force");
+#endif
int exit_code = 0;
/* Clear the quit flag and sync_quit_force_run so that a
diff --git a/gdb/top.h b/gdb/top.h
index 47e16ca104e..d63396e6598 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -109,4 +109,11 @@ extern bool check_quiet_mode ();
extern void unbuffer_stream (FILE *stream);
+#if GDB_SELF_TEST
+/* Rather than forcibly quitting when quit_force is called, note that it was
+ called by throwing a forced_quit. This allows selftests to handle this
+ situation. */
+extern bool capture_quit_force;
+#endif
+
#endif
--
2.35.3
prev parent reply other threads:[~2023-10-24 9:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-24 9:49 [PATCH v5 0/6] [gdb/cli] Allow source highlighting to be interrupted Tom de Vries
2023-10-24 9:49 ` [PATCH v5 1/6] [gdb/cli] Add signal_handler_selftest Tom de Vries
2023-11-22 16:26 ` Tom de Vries
2023-10-24 9:49 ` [PATCH v5 2/6] [gdb/python] Make python selftest more robust Tom de Vries
2023-10-24 9:49 ` [PATCH v5 3/6] [gdb/cli] Add gnu-source-highlight selftest Tom de Vries
2023-10-24 12:33 ` Tom de Vries
2023-10-24 9:49 ` [PATCH v5 4/6] [gdb/cli] Allow source highlighting to be interrupted Tom de Vries
2023-10-24 9:49 ` [PATCH v5 5/6] [gdb/cli] Ask if source highlighting should " Tom de Vries
2023-10-24 9:49 ` Tom de Vries [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231024094933.12009-7-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).