Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCHv2 08/16] gdb/tui: fix 'tui reg next/prev' command when data window is hidden
Date: Wed,  6 Apr 2022 13:04:41 +0100	[thread overview]
Message-ID: <c7da9d2b1ae3b91203b0bf6cb6d329b332fdbe5c.1649246539.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1649246538.git.aburgess@redhat.com>

Start GDB like:

  $ gdb -q executable
  (gdb) start
  (gdb) layout src
  ... tui windows are now displayed ...
  (gdb) tui reg next

At this point the data (register) window should be displayed, but will
contain the message 'Register Values Unavailable', and at the console
you'll see the message "unknown register group 'next'".

The same happens with 'tui reg prev' (but the error message is
slightly different).

At this point you can continue to use 'tui reg next' and/or 'tui reg
prev' and you'll keep getting the error message.

The problem is that when the data (register) window is first
displayed, it's current register group is nullptr.  As a consequence
tui_reg_next and tui_reg_prev (tui/tui-regs.c) will always just return
nullptr, which triggers an error in tui_reg_command.

In this commit I change tui_reg_next and tui_reg_prev so that they
instead return the first and last register group respectively if the
current register group is nullptr.

So, after this, using 'tui reg next' will (in the above case) show the
first register group, while 'tui reg prev' will display the last
register group.
---
 gdb/testsuite/gdb.tui/regs.exp | 26 ++++++++++++++++++++++++++
 gdb/tui/tui-regs.c             | 34 ++++++++++++++--------------------
 2 files changed, 40 insertions(+), 20 deletions(-)

diff --git a/gdb/testsuite/gdb.tui/regs.exp b/gdb/testsuite/gdb.tui/regs.exp
index 2f3482f5d38..4f34ced990c 100644
--- a/gdb/testsuite/gdb.tui/regs.exp
+++ b/gdb/testsuite/gdb.tui/regs.exp
@@ -44,3 +44,29 @@ Term::check_box "source box in regs layout" 0 7 80 8
 set text [Term::get_line 1]
 # Just check for any register window content at all.
 Term::check_contents "any register contents" "\\|.*\[^ \].*\\|"
+
+
+# Check that we can successfully cause the register window to appear
+# using the 'tui reg next' and 'tui reg prev' commands.
+foreach_with_prefix cmd { next prev } {
+    Term::clean_restart 24 80 $testfile
+
+    if {![runto_main]} {
+	perror "test suppressed"
+	return
+    }
+
+    if {![Term::enter_tui]} {
+	unsupported "TUI not supported"
+	return
+    }
+
+    Term::command "tui reg ${cmd}"
+    Term::check_box "register box" 0 0 80 8
+    Term::check_box "source box in regs layout" 0 7 80 8
+    Term::check_region_contents "check register group title" \
+	0 0 80 1 "Register group: "
+    set contents [Term::get_region 0 15 80 8 "\r\n"]
+    gdb_assert {![regexp -- "unknown register group '${cmd}'" $contents]} \
+	"check register group is known"
+}
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 75ffa9babbf..b968947fa1c 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -515,38 +515,32 @@ tui_data_item_window::rerender (WINDOW *handle, int field_width)
 }
 
 /* Helper for "tui reg next", wraps a call to REGGROUP_NEXT, but adds wrap
-   around behaviour.  Returns the next register group, or NULL if the
-   register window is not currently being displayed.  */
+   around behaviour.  Will never return nullptr.  If CURRENT_GROUP is
+   nullptr (e.g. if the tui register window has only just been displayed
+   and has no current group selected), then the first register group will
+   be returned.  */
 
 static const reggroup *
 tui_reg_next (const reggroup *current_group, struct gdbarch *gdbarch)
 {
-  const reggroup *group = NULL;
-
-  if (current_group != NULL)
-    {
-      group = reggroup_next (gdbarch, current_group);
-      if (group == NULL)
-	group = reggroup_next (gdbarch, NULL);
-    }
+  const reggroup *group = reggroup_next (gdbarch, current_group);
+  if (group == NULL)
+    group = reggroup_next (gdbarch, NULL);
   return group;
 }
 
 /* Helper for "tui reg prev", wraps a call to REGGROUP_PREV, but adds wrap
-   around behaviour.  Returns the previous register group, or NULL if the
-   register window is not currently being displayed.  */
+   around behaviour.  Will never return nullptr.  If CURRENT_GROUP is
+   nullptr (e.g. if the tui register window has only just been displayed
+   and has no current group selected), then the last register group will
+   be returned.  */
 
 static const reggroup *
 tui_reg_prev (const reggroup *current_group, struct gdbarch *gdbarch)
 {
-  const reggroup *group = NULL;
-
-  if (current_group != NULL)
-    {
-      group = reggroup_prev (gdbarch, current_group);
-      if (group == NULL)
-	group = reggroup_prev (gdbarch, NULL);
-    }
+  const reggroup *group = reggroup_prev (gdbarch, current_group);
+  if (group == NULL)
+    group = reggroup_prev (gdbarch, NULL);
   return group;
 }
 
-- 
2.25.4


  parent reply	other threads:[~2022-04-06 12:09 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-31 21:04 [PATCH 00/16] Default register groups, and general related cleanup Andrew Burgess via Gdb-patches
2022-03-31 21:04 ` [PATCH 01/16] gdb: don't try to use readline before it's initialized Andrew Burgess via Gdb-patches
2022-03-31 21:04 ` [PATCH 02/16] gdb: add some const in gdb/reggroups.c Andrew Burgess via Gdb-patches
2022-03-31 21:04 ` [PATCH 03/16] gdb: make gdbarch_register_reggroup_p take a const reggroup * Andrew Burgess via Gdb-patches
2022-04-04 22:35   ` Lancelot SIX via Gdb-patches
2022-04-05  8:24     ` Andrew Burgess via Gdb-patches
2022-03-31 21:04 ` [PATCH 04/16] gdb: switch to using 'const reggroup *' in tui-regs.{c, h} Andrew Burgess via Gdb-patches
2022-03-31 21:04 ` [PATCH 05/16] gdb: use 'const reggroup *' in python/py-registers.c file Andrew Burgess via Gdb-patches
2022-03-31 21:04 ` [PATCH 06/16] gdb: have reggroup_find return a const Andrew Burgess via Gdb-patches
2022-03-31 21:04 ` [PATCH 07/16] gdb/tui: avoid theoretical bug with 'tui reg' command Andrew Burgess via Gdb-patches
2022-03-31 21:04 ` [PATCH 08/16] gdb/tui: fix 'tui reg next/prev' command when data window is hidden Andrew Burgess via Gdb-patches
2022-03-31 21:04 ` [PATCH 09/16] gdb: always add the default register groups Andrew Burgess via Gdb-patches
2022-03-31 21:04 ` [PATCH 10/16] gdb: convert reggroups to use a std::vector Andrew Burgess via Gdb-patches
2022-03-31 21:04 ` [PATCH 11/16] gdb: remove reggroup_next and reggroup_prev Andrew Burgess via Gdb-patches
2022-04-05 23:11   ` Lancelot SIX via Gdb-patches
2022-04-06 12:06     ` Andrew Burgess via Gdb-patches
2022-03-31 21:04 ` [PATCH 12/16] gdb: more 'const' in gdb/reggroups.{c,h} Andrew Burgess via Gdb-patches
2022-03-31 21:04 ` [PATCH 13/16] gdb: make the pre-defined register groups const Andrew Burgess via Gdb-patches
2022-03-31 21:04 ` [PATCH 14/16] gdb: convert reggroup to a C++ class with constructor, etc Andrew Burgess via Gdb-patches
2022-03-31 21:04 ` [PATCH 15/16] gdb: move struct reggroup into reggroups.h header Andrew Burgess via Gdb-patches
2022-03-31 21:04 ` [PATCH 16/16] gdb: update comments throughout reggroups.{c,h} files Andrew Burgess via Gdb-patches
2022-04-06 14:28   ` Simon Marchi via Gdb-patches
2022-04-06 12:04 ` [PATCHv2 00/16] Default register groups, and general related cleanup Andrew Burgess via Gdb-patches
2022-04-06 12:04   ` [PATCHv2 01/16] gdb: don't try to use readline before it's initialized Andrew Burgess via Gdb-patches
2022-04-06 12:57     ` Simon Marchi via Gdb-patches
2022-04-06 12:04   ` [PATCHv2 02/16] gdb: add some const in gdb/reggroups.c Andrew Burgess via Gdb-patches
2022-04-06 12:58     ` Simon Marchi via Gdb-patches
2022-04-06 12:04   ` [PATCHv2 03/16] gdb: make gdbarch_register_reggroup_p take a const reggroup * Andrew Burgess via Gdb-patches
2022-04-06 12:04   ` [PATCHv2 04/16] gdb: switch to using 'const reggroup *' in tui-regs.{c, h} Andrew Burgess via Gdb-patches
2022-04-06 12:04   ` [PATCHv2 05/16] gdb: use 'const reggroup *' in python/py-registers.c file Andrew Burgess via Gdb-patches
2022-04-06 12:04   ` [PATCHv2 06/16] gdb: have reggroup_find return a const Andrew Burgess via Gdb-patches
2022-04-06 12:04   ` [PATCHv2 07/16] gdb/tui: avoid theoretical bug with 'tui reg' command Andrew Burgess via Gdb-patches
2022-04-06 13:02     ` Simon Marchi via Gdb-patches
2022-04-06 12:04   ` Andrew Burgess via Gdb-patches [this message]
2022-04-06 13:13     ` [PATCHv2 08/16] gdb/tui: fix 'tui reg next/prev' command when data window is hidden Simon Marchi via Gdb-patches
2022-04-06 12:04   ` [PATCHv2 09/16] gdb: always add the default register groups Andrew Burgess via Gdb-patches
2022-04-06 13:22     ` Simon Marchi via Gdb-patches
2022-04-06 12:04   ` [PATCHv2 10/16] gdb: convert reggroups to use a std::vector Andrew Burgess via Gdb-patches
2022-04-06 12:04   ` [PATCHv2 11/16] gdb: remove reggroup_next and reggroup_prev Andrew Burgess via Gdb-patches
2022-04-06 14:22     ` Simon Marchi via Gdb-patches
2022-04-06 14:23       ` Simon Marchi via Gdb-patches
2022-04-06 12:04   ` [PATCHv2 12/16] gdb: more 'const' in gdb/reggroups.{c,h} Andrew Burgess via Gdb-patches
2022-04-06 12:04   ` [PATCHv2 13/16] gdb: make the pre-defined register groups const Andrew Burgess via Gdb-patches
2022-04-06 12:04   ` [PATCHv2 14/16] gdb: convert reggroup to a C++ class with constructor, etc Andrew Burgess via Gdb-patches
2022-04-06 12:04   ` [PATCHv2 15/16] gdb: move struct reggroup into reggroups.h header Andrew Burgess via Gdb-patches
2022-04-06 12:04   ` [PATCHv2 16/16] gdb: update comments throughout reggroups.{c, h} files Andrew Burgess via Gdb-patches
2022-04-06 14:34   ` [PATCHv2 00/16] Default register groups, and general related cleanup Simon Marchi via Gdb-patches
2022-04-07 15:16     ` Andrew Burgess via Gdb-patches

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=c7da9d2b1ae3b91203b0bf6cb6d329b332fdbe5c.1649246539.git.aburgess@redhat.com \
    --to=gdb-patches@sourceware.org \
    --cc=aburgess@redhat.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