Re: [PATCHv2 08/16] gdb/tui: fix 'tui reg next/prev' command when data window is hidden

Simon Marchi via Gdb-patches
2022-04-06T13:14:20Z

On 2022-04-06 08:04, Andrew Burgess via Gdb-patches wrote:
> 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.

I don't have a strong opinion on this, but my understanding of the
current code is that tui_reg_next / tui_reg_prev expect that if the
reg window is displayed, there is a current group. So one fix could
also be to make sure the tui_regs_layout call selects an initial
reggroup, and then tui_reg_next / tui_reg_prev would work as expected.

Hmm however, that would give a slightly different behavior. When the
tui reg window is not shown and you do "tui reg next", which register
group do you want to show? With your solution, we will show the first
group. With my proposal, we would show the second. I think that
showing the first group makes more sense, so I agree with your solution
actually.

But then I wonder if "tui reg prev" should behave the same, show the
first group. Not really important though, I doubt that anybody will
ever care much about that detail in the behavior of the "tui reg prev"
command.

The patch LGTM.

Simon