From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id E497B3857404; Thu, 7 Apr 2022 15:08:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E497B3857404 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/tui: fix 'tui reg next/prev' command when data window is hidden X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 5783701b36f842b1a5057c02b62d67a0ad703834 X-Git-Newrev: 07c316ecaa2e47721b5e1281456e6b8b0d15c7ba Message-Id: <20220407150821.E497B3857404@sourceware.org> Date: Thu, 7 Apr 2022 15:08:21 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Apr 2022 15:08:22 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D07c316ecaa2e= 47721b5e1281456e6b8b0d15c7ba commit 07c316ecaa2e47721b5e1281456e6b8b0d15c7ba Author: Andrew Burgess Date: Thu Mar 31 15:17:27 2022 +0100 gdb/tui: fix 'tui reg next/prev' command when data window is hidden =20 Start GDB like: =20 $ gdb -q executable (gdb) start (gdb) layout src ... tui windows are now displayed ... (gdb) tui reg next =20 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'". =20 The same happens with 'tui reg prev' (but the error message is slightly different). =20 At this point you can continue to use 'tui reg next' and/or 'tui reg prev' and you'll keep getting the error message. =20 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. =20 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. =20 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. Diff: --- 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 f= ield_width) } =20 /* 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. */ =20 static const reggroup * tui_reg_next (const reggroup *current_group, struct gdbarch *gdbarch) { - const reggroup *group =3D NULL; - - if (current_group !=3D NULL) - { - group =3D reggroup_next (gdbarch, current_group); - if (group =3D=3D NULL) - group =3D reggroup_next (gdbarch, NULL); - } + const reggroup *group =3D reggroup_next (gdbarch, current_group); + if (group =3D=3D NULL) + group =3D reggroup_next (gdbarch, NULL); return group; } =20 /* 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. */ =20 static const reggroup * tui_reg_prev (const reggroup *current_group, struct gdbarch *gdbarch) { - const reggroup *group =3D NULL; - - if (current_group !=3D NULL) - { - group =3D reggroup_prev (gdbarch, current_group); - if (group =3D=3D NULL) - group =3D reggroup_prev (gdbarch, NULL); - } + const reggroup *group =3D reggroup_prev (gdbarch, current_group); + if (group =3D=3D NULL) + group =3D reggroup_prev (gdbarch, NULL); return group; }