public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH] [gdb/tui] Assert on tui_refreshing_registers recursion
Date: Sat,  9 Dec 2023 09:24:53 +0100	[thread overview]
Message-ID: <20231209082453.21019-1-tdevries@suse.de> (raw)

In gdb/tui/tui-hooks.c, we have a variable:
...
/* Prevent recursion of deprecated_register_changed_hook().  */
static bool tui_refreshing_registers = false;
...

I tried to detect the moment it's preventing recursion, both by running the
TUI testsuite and test-driving TUI, but didn't manage.

Change the behaviour from preventing recursion to asserting on detecting
recursion.

Also as a cleanup, fold usage of the variable into a single function.

Tested on x86_64-linux.
---
 gdb/tui/tui-hooks.c | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/gdb/tui/tui-hooks.c b/gdb/tui/tui-hooks.c
index 6525f0f2b6c..fa9fd443db2 100644
--- a/gdb/tui/tui-hooks.c
+++ b/gdb/tui/tui-hooks.c
@@ -63,8 +63,28 @@ static void
 tui_all_objfiles_removed (program_space *pspace)
 { tui_on_objfiles_changed (); }
 
-/* Prevent recursion of deprecated_register_changed_hook().  */
-static bool tui_refreshing_registers = false;
+/* As TUI_DATA_WIN->check_register_values, but with recursion detection.  */
+
+static void
+check_register_values (frame_info_ptr fi)
+{
+  static bool tui_refreshing_registers = false;
+
+  if (tui_refreshing_registers)
+    {
+      /* Recursion detected.  We used to stop recursion here, but we
+	 think it no longer occurs, so instead we detect it verbosely.
+	 If we don't manage to trigger it for a while, we can just remove the
+	 detection.  */
+      gdb_assert_not_reached ("recursion detected in check_register_values");
+    }
+  else
+    {
+      tui_refreshing_registers = true;
+      TUI_DATA_WIN->check_register_values (fi);
+      tui_refreshing_registers = false;
+    }
+}
 
 /* Observer for the register_changed notification.  */
 
@@ -82,12 +102,7 @@ tui_register_changed (frame_info_ptr frame, int regno)
      up in the other.  So we always use the selected frame here, and ignore
      FRAME.  */
   fi = get_selected_frame (NULL);
-  if (!tui_refreshing_registers)
-    {
-      tui_refreshing_registers = true;
-      TUI_DATA_WIN->check_register_values (fi);
-      tui_refreshing_registers = false;
-    }
+  check_register_values (fi);
 }
 
 /* Breakpoint creation hook.
@@ -145,11 +160,7 @@ tui_refresh_frame_and_register_information ()
       /* Refresh the register window if it's visible.  */
       if (tui_is_window_visible (DATA_WIN)
 	  && (frame_info_changed_p || from_stack))
-	{
-	  tui_refreshing_registers = true;
-	  TUI_DATA_WIN->check_register_values (fi);
-	  tui_refreshing_registers = false;
-	}
+	check_register_values (fi);
     }
   else if (!from_stack)
     {

base-commit: 95385060771b0cac95a39320c44eca857fb177ae
-- 
2.35.3


             reply	other threads:[~2023-12-09  8:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-09  8:24 Tom de Vries [this message]
2023-12-09 16:06 ` Tom Tromey

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=20231209082453.21019-1-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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).