public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb/tui: avoid theoretical bug with 'tui reg' command
@ 2022-04-07 15:08 Andrew Burgess
  0 siblings, 0 replies; only message in thread
From: Andrew Burgess @ 2022-04-07 15:08 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5783701b36f842b1a5057c02b62d67a0ad703834

commit 5783701b36f842b1a5057c02b62d67a0ad703834
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Thu Mar 31 14:44:25 2022 +0100

    gdb/tui: avoid theoretical bug with 'tui reg' command
    
    While looking at the 'tui reg' command as part of another patch, I
    spotted a theoretical bug.
    
    The 'tui reg' command takes the name of a register group, but also
    handles partial register group matches, though the partial match has to
    be unique.  The current command logic goes:
    
    With the code as currently written, if a target description named a
    register group either 'prev' or 'next' then GDB would see this as an
    ambiguous register name, and refuse to switch groups.
    
    Naming a register group 'prev' or 'next' seems pretty unlikely, but,
    by adding a single else block we can prevent this problem.
    
    Now, if there's a 'prev' or 'next' register group, the user will not
    be able to select the group directly, the 'prev' and 'next' names will
    always iterate through the available groups instead.  But at least the
    user could select their groups by iteration, rather than direct
    selection.

Diff:
---
 gdb/tui/tui-regs.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 5c6189a59b1..75ffa9babbf 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -580,19 +580,21 @@ tui_reg_command (const char *args, int from_tty)
 	match = tui_reg_next (current_group, gdbarch);
       else if (strncmp (args, "prev", len) == 0)
 	match = tui_reg_prev (current_group, gdbarch);
-
-      /* This loop matches on the initial part of a register group
-	 name.  If this initial part in ARGS matches only one register
-	 group then the switch is made.  */
-      for (group = reggroup_next (gdbarch, NULL);
-	   group != NULL;
-	   group = reggroup_next (gdbarch, group))
+      else
 	{
-	  if (strncmp (reggroup_name (group), args, len) == 0)
+	  /* This loop matches on the initial part of a register group
+	     name.  If this initial part in ARGS matches only one register
+	     group then the switch is made.  */
+	  for (group = reggroup_next (gdbarch, NULL);
+	       group != NULL;
+	       group = reggroup_next (gdbarch, group))
 	    {
-	      if (match != NULL)
-		error (_("ambiguous register group name '%s'"), args);
-	      match = group;
+	      if (strncmp (reggroup_name (group), args, len) == 0)
+		{
+		  if (match != NULL)
+		    error (_("ambiguous register group name '%s'"), args);
+		  match = group;
+		}
 	    }
 	}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-07 15:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07 15:08 [binutils-gdb] gdb/tui: avoid theoretical bug with 'tui reg' command Andrew Burgess

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).