public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/3] [gdb/tui] Add setting for default focus window
@ 2023-05-27 18:28 Tom de Vries
  2023-05-27 18:28 ` [PATCH 1/3] [gdb/tui] Add tui_default_focus_window Tom de Vries
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Tom de Vries @ 2023-05-27 18:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This patch series adds a new setting "set tui default-focus first/cmd".

There are two preparatory patches, and a patch adding the new setting.

Tom de Vries (3):
  [gdb/tui] Add tui_default_focus_window
  [gdb/tui] Add tui_get_cmd_set/show_list
  [gdb/tui] Add set tui default-focus first/cmd

 gdb/doc/gdb.texinfo  |  6 ++++++
 gdb/tui/tui-layout.c | 48 +++++++++++++++++++++++++++++++++++++-----
 gdb/tui/tui-layout.h |  4 ++++
 gdb/tui/tui-win.c    | 50 +++++++++++++++++++++++++++++++++++++-------
 gdb/tui/tui-win.h    |  6 ++++++
 gdb/tui/tui.c        |  2 +-
 6 files changed, 103 insertions(+), 13 deletions(-)


base-commit: 225df051d3d4cf714d1791b9035966a6686b3f3d
-- 
2.35.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] [gdb/tui] Add tui_default_focus_window
  2023-05-27 18:28 [PATCH 0/3] [gdb/tui] Add setting for default focus window Tom de Vries
@ 2023-05-27 18:28 ` Tom de Vries
  2023-05-30 13:39   ` Alexandra Petlanova Hajkova
  2023-05-27 18:28 ` [PATCH 2/3] [gdb/tui] Add tui_get_cmd_set/show_list Tom de Vries
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Tom de Vries @ 2023-05-27 18:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

There are two moments when TUI makes an in principle arbitrary choice about
what window will get the focus:
- when entering TUI, and
- when changing into another layout removes the focused window.

In the latter case, it picks the first window in the window list.

In the former case, it picks the src window, which at that point also happens
to be the first window in the window list.

Introduce a new function tui_default_focus_window that formalizes this way of
picking a window to focus on, and use it in both cases.

To keep the function interface simple, tui_default_focus_window picks the
first in the tui_windows list, which requires a minor rewrite in
tui_apply_current_layout to ensure that tui_windows is updated before we call
tui_default_focus_window.

No functional changes.

Tested on x86_64-linux.
---
 gdb/tui/tui-layout.c | 19 ++++++++++++++-----
 gdb/tui/tui-layout.h |  4 ++++
 gdb/tui/tui.c        |  2 +-
 3 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index 50c568fb7d7..ea8b4378d1e 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -66,6 +66,14 @@ std::vector<tui_win_info *> tui_windows;
 
 /* See tui-layout.h.  */
 
+struct tui_win_info *
+tui_default_focus_window ()
+{
+  return tui_windows[0];
+}
+
+/* See tui-layout.h.  */
+
 void
 tui_apply_current_layout (bool preserve_cmd_win_size_p)
 {
@@ -94,21 +102,22 @@ tui_apply_current_layout (bool preserve_cmd_win_size_p)
   std::vector<tui_win_info *> new_tui_windows;
   applied_layout->get_windows (&new_tui_windows);
 
+  /* Replace the global list of active windows.  */
+  std::vector<tui_win_info *> old_tui_windows = std::move (tui_windows);
+  tui_windows = std::move (new_tui_windows);
+
   /* Now delete any window that was not re-applied.  */
   tui_win_info *focus = tui_win_with_focus ();
-  for (tui_win_info *win_info : tui_windows)
+  for (tui_win_info *win_info : old_tui_windows)
     {
       if (!win_info->is_visible ())
 	{
 	  if (focus == win_info)
-	    tui_set_win_focus_to (new_tui_windows[0]);
+	    tui_set_win_focus_to (tui_default_focus_window ());
 	  delete win_info;
 	}
     }
 
-  /* Replace the global list of active windows.  */
-  tui_windows = std::move (new_tui_windows);
-
   if (gdbarch == nullptr && TUI_DISASM_WIN != nullptr)
     tui_get_begin_asm_address (&gdbarch, &addr);
   tui_update_source_windows_with_addr (gdbarch, addr);
diff --git a/gdb/tui/tui-layout.h b/gdb/tui/tui-layout.h
index ff354fb7c2f..29f21437118 100644
--- a/gdb/tui/tui-layout.h
+++ b/gdb/tui/tui-layout.h
@@ -413,4 +413,8 @@ using known_window_names_range
 
 extern known_window_names_range all_known_window_names ();
 
+/* Return the window to set the focus to, in case that requires a choice.  */
+
+extern struct tui_win_info *tui_default_focus_window ();
+
 #endif /* TUI_TUI_LAYOUT_H */
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index 10cf811a41e..f2e4c717193 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -458,7 +458,7 @@ tui_enable (void)
 
       tui_show_frame_info (0);
       tui_set_initial_layout ();
-      tui_set_win_focus_to (TUI_SRC_WIN);
+      tui_set_win_focus_to (tui_default_focus_window ());
       keypad (TUI_CMD_WIN->handle.get (), TRUE);
       wrefresh (TUI_CMD_WIN->handle.get ());
       tui_finish_init = false;
-- 
2.35.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/3] [gdb/tui] Add tui_get_cmd_set/show_list
  2023-05-27 18:28 [PATCH 0/3] [gdb/tui] Add setting for default focus window Tom de Vries
  2023-05-27 18:28 ` [PATCH 1/3] [gdb/tui] Add tui_default_focus_window Tom de Vries
@ 2023-05-27 18:28 ` Tom de Vries
  2023-05-30 13:41   ` Alexandra Petlanova Hajkova
  2023-05-27 18:28 ` [PATCH 3/3] [gdb/tui] Add set tui default-focus first/cmd Tom de Vries
  2023-05-28  5:15 ` [PATCH 0/3] [gdb/tui] Add setting for default focus window Eli Zaretskii
  3 siblings, 1 reply; 9+ messages in thread
From: Tom de Vries @ 2023-05-27 18:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Add new functions:
- tui_get_cmd_set_list, and
- tui_get_cmd_show_list,
similar to tui_get_cmd_list that allow introducing "set/show tui" commands in
files other than tui/tui-win.c.

No functional changes.  No users in this patch.

Tested on x86_64-linux.
---
 gdb/tui/tui-win.c | 50 ++++++++++++++++++++++++++++++++++++++++-------
 gdb/tui/tui-win.h |  6 ++++++
 2 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 7abd1e225b9..c187f7c33ad 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -336,6 +336,47 @@ tui_get_cmd_list (void)
   return &tuilist;
 }
 
+/* The "tui set" command list. */
+
+static struct cmd_list_element *tui_setlist;
+
+/* The "tui show" command list. */
+
+static struct cmd_list_element *tui_showlist;
+
+/* Initialize the tui_setlist and tui_showlist variables. */
+
+static void
+init_tui_set_show_lists ()
+{
+  if (tui_setlist != nullptr)
+    return;
+
+  add_setshow_prefix_cmd ("tui", class_tui,
+			  _("TUI configuration variables."),
+			  _("TUI configuration variables."),
+			  &tui_setlist, &tui_showlist,
+			  &setlist, &showlist);
+}
+
+/* See tui-win.h.  */
+
+struct cmd_list_element **
+tui_get_cmd_set_list ()
+{
+  init_tui_set_show_lists ();
+  return &tui_setlist;
+}
+
+/* See tui-win.h.  */
+
+struct cmd_list_element **
+tui_get_cmd_show_list ()
+{
+  init_tui_set_show_lists ();
+  return &tui_showlist;
+}
+
 /* The set_func hook of "set tui ..." commands that affect the window
    borders on the TUI display.  */
 
@@ -1127,16 +1168,11 @@ void _initialize_tui_win ();
 void
 _initialize_tui_win ()
 {
-  static struct cmd_list_element *tui_setlist;
-  static struct cmd_list_element *tui_showlist;
+  /* Initialize tui_setlist and tui_showlist.  */
+  init_tui_set_show_lists ();
 
   /* Define the classes of commands.
      They will appear in the help list in the reverse of this order.  */
-  add_setshow_prefix_cmd ("tui", class_tui,
-			  _("TUI configuration variables."),
-			  _("TUI configuration variables."),
-			  &tui_setlist, &tui_showlist,
-			  &setlist, &showlist);
 
   cmd_list_element *refresh_cmd
     = add_cmd ("refresh", class_tui, tui_refresh_all_command,
diff --git a/gdb/tui/tui-win.h b/gdb/tui/tui-win.h
index 3d35f1dfb7f..4de938fa280 100644
--- a/gdb/tui/tui-win.h
+++ b/gdb/tui/tui-win.h
@@ -48,6 +48,12 @@ extern void tui_update_gdb_sizes (void);
 /* Create or get the TUI command list.  */
 struct cmd_list_element **tui_get_cmd_list (void);
 
+/* Create or get the TUI set command list.  */
+extern struct cmd_list_element **tui_get_cmd_set_list ();
+
+/* Create or get the TUI show command list.  */
+extern struct cmd_list_element **tui_get_cmd_show_list ();
+
 /* Whether compact source display should be used.  */
 extern bool compact_source;
 
-- 
2.35.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/3] [gdb/tui] Add set tui default-focus first/cmd
  2023-05-27 18:28 [PATCH 0/3] [gdb/tui] Add setting for default focus window Tom de Vries
  2023-05-27 18:28 ` [PATCH 1/3] [gdb/tui] Add tui_default_focus_window Tom de Vries
  2023-05-27 18:28 ` [PATCH 2/3] [gdb/tui] Add tui_get_cmd_set/show_list Tom de Vries
@ 2023-05-27 18:28 ` Tom de Vries
  2023-05-28  5:15   ` Eli Zaretskii
  2023-05-30 13:42   ` Alexandra Petlanova Hajkova
  2023-05-28  5:15 ` [PATCH 0/3] [gdb/tui] Add setting for default focus window Eli Zaretskii
  3 siblings, 2 replies; 9+ messages in thread
From: Tom de Vries @ 2023-05-27 18:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Add a new command "set tui default-focus first/cmd" that set the default focus
window.

If set to first, it's the first window in the window list.

If set to cmd, it's the command window.

The default value is first, so the default behaviour is unchanged.

Tested on x86_64-linux.

PR tui/24137
https://sourceware.org/bugzilla/show_bug.cgi?id=24137

Reported-By: Martin Liška <marxin.liska@gmail.com>
---
 gdb/doc/gdb.texinfo  |  6 ++++++
 gdb/tui/tui-layout.c | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index d1059e0cb7f..de8b42e99c7 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -30318,6 +30318,12 @@ The default display uses more space for line numbers; the compact
 display uses only as much space as is needed for the line numbers in
 the current file.
 
+@item set tui default-focus @r{[}first@r{|}cmd@r{]}
+@kindex set tui default-focus
+The default TUI window to focus on.  If set to first, it's the first
+window in the window list.  If set to cmd, it's the command window.
+The default value is first.
+
 @kindex set debug tui
 @item set debug tui @r{[}on|off@r{]}
 Turn on or off display of @value{GDBN} internal debug messages relating
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index ea8b4378d1e..92609e63190 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -46,6 +46,7 @@
 #include "gdbsupport/gdb-safe-ctype.h"
 
 static void extract_display_start_addr (struct gdbarch **, CORE_ADDR *);
+static tui_win_info *tui_get_window_by_name (const std::string &name);
 
 /* The layouts.  */
 static std::vector<std::unique_ptr<tui_layout_split>> layouts;
@@ -64,12 +65,28 @@ static tui_layout_split *asm_regs_layout;
 /* See tui-data.h.  */
 std::vector<tui_win_info *> tui_windows;
 
+/* Choices for "tui default-focus".  */
+static const char *const tui_default_focus_enums[] = {
+  "first",
+  "cmd",
+  NULL
+};
+
+/* Value of "tui default-focus".  */
+static const char *tui_default_focus = "first";
+
 /* See tui-layout.h.  */
 
 struct tui_win_info *
 tui_default_focus_window ()
 {
-  return tui_windows[0];
+  if (strcmp (tui_default_focus, "first") == 0)
+    return tui_windows[0];
+
+  if (strcmp (tui_default_focus, "cmd") == 0)
+    return tui_get_window_by_name ("cmd");
+
+  gdb_assert_not_reached ("");
 }
 
 /* See tui-layout.h.  */
@@ -1347,6 +1364,18 @@ Each WEIGHT is an integer, which holds the relative size\n\
 to be allocated to the window."),
 	   tui_get_cmd_list ());
 
+
+  add_setshow_enum_cmd ("default-focus", no_class, tui_default_focus_enums,
+			&tui_default_focus, _("\
+Set the default focus window"), _("\
+Show the default focus window"), _("\
+This variable controls which TUI window is focused by default:\n\
+   first           first window in the window list\n\
+   cmd             command window"),
+			nullptr,
+			nullptr,
+			tui_get_cmd_set_list (), tui_get_cmd_show_list ());
+
   initialize_layouts ();
   initialize_known_windows ();
 }
-- 
2.35.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] [gdb/tui] Add set tui default-focus first/cmd
  2023-05-27 18:28 ` [PATCH 3/3] [gdb/tui] Add set tui default-focus first/cmd Tom de Vries
@ 2023-05-28  5:15   ` Eli Zaretskii
  2023-05-30 13:42   ` Alexandra Petlanova Hajkova
  1 sibling, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2023-05-28  5:15 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches, tom

> Cc: Tom Tromey <tom@tromey.com>
> Date: Sat, 27 May 2023 20:28:09 +0200
> From: Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
> 
> Add a new command "set tui default-focus first/cmd" that set the default focus
> window.
> 
> If set to first, it's the first window in the window list.
> 
> If set to cmd, it's the command window.
> 
> The default value is first, so the default behaviour is unchanged.
> 
> Tested on x86_64-linux.
> 
> PR tui/24137
> https://sourceware.org/bugzilla/show_bug.cgi?id=24137
> 
> Reported-By: Martin Liška <marxin.liska@gmail.com>
> ---
>  gdb/doc/gdb.texinfo  |  6 ++++++
>  gdb/tui/tui-layout.c | 31 ++++++++++++++++++++++++++++++-
>  2 files changed, 36 insertions(+), 1 deletion(-)

Thanks.

> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index d1059e0cb7f..de8b42e99c7 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -30318,6 +30318,12 @@ The default display uses more space for line numbers; the compact
>  display uses only as much space as is needed for the line numbers in
>  the current file.
>  
> +@item set tui default-focus @r{[}first@r{|}cmd@r{]}
> +@kindex set tui default-focus
> +The default TUI window to focus on.  If set to first, it's the first
> +window in the window list.  If set to cmd, it's the command window.
> +The default value is first.

"first" and "cmd" should have the @code or @samp markup.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/3] [gdb/tui] Add setting for default focus window
  2023-05-27 18:28 [PATCH 0/3] [gdb/tui] Add setting for default focus window Tom de Vries
                   ` (2 preceding siblings ...)
  2023-05-27 18:28 ` [PATCH 3/3] [gdb/tui] Add set tui default-focus first/cmd Tom de Vries
@ 2023-05-28  5:15 ` Eli Zaretskii
  3 siblings, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2023-05-28  5:15 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches, tom

> Cc: Tom Tromey <tom@tromey.com>
> Date: Sat, 27 May 2023 20:28:06 +0200
> From: Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
> 
> This patch series adds a new setting "set tui default-focus first/cmd".

Should this be called out in NEWS?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] [gdb/tui] Add tui_default_focus_window
  2023-05-27 18:28 ` [PATCH 1/3] [gdb/tui] Add tui_default_focus_window Tom de Vries
@ 2023-05-30 13:39   ` Alexandra Petlanova Hajkova
  0 siblings, 0 replies; 9+ messages in thread
From: Alexandra Petlanova Hajkova @ 2023-05-30 13:39 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches, Tom Tromey

[-- Attachment #1: Type: text/plain, Size: 1076 bytes --]

On Sat, May 27, 2023 at 8:28 PM Tom de Vries via Gdb-patches <
gdb-patches@sourceware.org> wrote:

> There are two moments when TUI makes an in principle arbitrary choice about
> what window will get the focus:
> - when entering TUI, and
> - when changing into another layout removes the focused window.
>
> In the latter case, it picks the first window in the window list.
>
> In the former case, it picks the src window, which at that point also
> happens
> to be the first window in the window list.
>
> Introduce a new function tui_default_focus_window that formalizes this way
> of
> picking a window to focus on, and use it in both cases.
>
> To keep the function interface simple, tui_default_focus_window picks the
> first in the tui_windows list, which requires a minor rewrite in
> tui_apply_current_layout to ensure that tui_windows is updated before we
> call
> tui_default_focus_window.
>
> No functional changes.
>
> Tested on x86_64-linux.
> ---
>
> I can confirm the patch causes no regressions on ppc64le with Fedora
Rawhide.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] [gdb/tui] Add tui_get_cmd_set/show_list
  2023-05-27 18:28 ` [PATCH 2/3] [gdb/tui] Add tui_get_cmd_set/show_list Tom de Vries
@ 2023-05-30 13:41   ` Alexandra Petlanova Hajkova
  0 siblings, 0 replies; 9+ messages in thread
From: Alexandra Petlanova Hajkova @ 2023-05-30 13:41 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches, Tom Tromey

[-- Attachment #1: Type: text/plain, Size: 488 bytes --]

On Sat, May 27, 2023 at 8:28 PM Tom de Vries via Gdb-patches <
gdb-patches@sourceware.org> wrote:

> Add new functions:
> - tui_get_cmd_set_list, and
> - tui_get_cmd_show_list,
> similar to tui_get_cmd_list that allow introducing "set/show tui" commands
> in
> files other than tui/tui-win.c.
>
> No functional changes.  No users in this patch.
>
> Tested on x86_64-linux.
> ---
>
I can confirm this change causes no regressions on ppc64le with Fedora
Rawhide.

>
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] [gdb/tui] Add set tui default-focus first/cmd
  2023-05-27 18:28 ` [PATCH 3/3] [gdb/tui] Add set tui default-focus first/cmd Tom de Vries
  2023-05-28  5:15   ` Eli Zaretskii
@ 2023-05-30 13:42   ` Alexandra Petlanova Hajkova
  1 sibling, 0 replies; 9+ messages in thread
From: Alexandra Petlanova Hajkova @ 2023-05-30 13:42 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches, Tom Tromey

[-- Attachment #1: Type: text/plain, Size: 646 bytes --]

On Sat, May 27, 2023 at 8:28 PM Tom de Vries via Gdb-patches <
gdb-patches@sourceware.org> wrote:

> Add a new command "set tui default-focus first/cmd" that set the default
> focus
> window.
>
> If set to first, it's the first window in the window list.
>
> If set to cmd, it's the command window.
>
> The default value is first, so the default behaviour is unchanged.
>
> Tested on x86_64-linux.
>
> PR tui/24137
> https://sourceware.org/bugzilla/show_bug.cgi?id=24137
>
> Reported-By: Martin Liška <marxin.liska@gmail.com>
> ---
>
I can confirm the patch causes no regressions on ppc64le with Fedora
Rawhide.

>
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-05-30 13:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-27 18:28 [PATCH 0/3] [gdb/tui] Add setting for default focus window Tom de Vries
2023-05-27 18:28 ` [PATCH 1/3] [gdb/tui] Add tui_default_focus_window Tom de Vries
2023-05-30 13:39   ` Alexandra Petlanova Hajkova
2023-05-27 18:28 ` [PATCH 2/3] [gdb/tui] Add tui_get_cmd_set/show_list Tom de Vries
2023-05-30 13:41   ` Alexandra Petlanova Hajkova
2023-05-27 18:28 ` [PATCH 3/3] [gdb/tui] Add set tui default-focus first/cmd Tom de Vries
2023-05-28  5:15   ` Eli Zaretskii
2023-05-30 13:42   ` Alexandra Petlanova Hajkova
2023-05-28  5:15 ` [PATCH 0/3] [gdb/tui] Add setting for default focus window Eli Zaretskii

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