public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCHv3 06/15] gdb/tui: add a tui debugging flag
Date: Mon,  7 Mar 2022 22:13:38 +0000	[thread overview]
Message-ID: <de69e7d915c5123008e188d73462007a24c7b002.1646691034.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1646691034.git.aburgess@redhat.com>

This commit adds 'set debug tui on|off' and 'show debug tui'.  This
commit adds the control variable, and the printing macros in
tui/tui.h.  I've then added some uses of these in tui.c and
tui-layout.c.

To help produce more useful debug output in tui-layout.c, I've added
some helper member functions in the class tui_layout_split, and also
moved the size_info struct out of tui_layout_split::apply into the
tui_layout_split class.

If tui debug is not turned on, then there should be no user visible
changes after this commit.

One thing to note is that, due to the way that the tui terminal is
often cleared, the only way I've found this useful is when I do:

  (gdb) tui enable
  (gdb) set logging file /path/to/file
  (gdb) set logging debugredirect on
  (gdb) set logging enable on

Additionally, gdb has some quirks when it comes to setting up logging
redirect and switching interpreters.  Thus, the above only really
works if the logging is enabled after the tui is enabled, and disabled
again before the tui is disabled.

Enabling logging and switching interpreters can cause undefined
results, including crashes.  This is an existing bug in gdb[1], and
has nothing directly to do with tui debug, but it is worth mentioning
here I think.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=28948
---
 gdb/NEWS             |  4 ++
 gdb/doc/gdb.texinfo  | 11 +++++
 gdb/tui/tui-layout.c | 99 +++++++++++++++++++++++++++++++++++++++-----
 gdb/tui/tui-layout.h | 25 +++++++++++
 gdb/tui/tui.c        | 26 ++++++++++++
 gdb/tui/tui.h        | 14 +++++++
 6 files changed, 168 insertions(+), 11 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 1275d967a2d..eb18ac47804 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -133,6 +133,10 @@ winwidth
   the width of a tui window to be adjusted when windows are laid out
   in horizontal mode.
 
+set debug tui on|off
+show debug tui
+  Control the display of debug output about GDB's tui.
+
 * Changed commands
 
 maint packet
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 6081aa85af4..60173e07747 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -29205,6 +29205,17 @@
 source text at the next tab stop; the compact display uses only as
 much space as is needed for the line numbers in the current file, and
 only a single space to separate the line numbers from the source.
+
+@kindex set debug tui
+@item set debug tui @r{[}on|off@r{]}
+Turn on or off display of @value{GDBN} internal debug messages relating
+to the TUI.
+
+@kindex show debug tui
+@item show debug tui
+Show the current status of displaying @value{GDBN} internal debug
+messages relating to the TUI.
+
 @end table
 
 Note that the colors of the TUI borders can be controlled using the
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index 4e5740fd6d3..8e8b4538c7e 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -426,8 +426,14 @@ tui_layout_window::apply (int x_, int y_, int width_, int height_)
 void
 tui_layout_window::get_sizes (bool height, int *min_value, int *max_value)
 {
+  TUI_SCOPED_DEBUG_ENTER_EXIT;
+
   if (m_window == nullptr)
     m_window = tui_get_window_by_name (m_contents);
+
+  tui_debug_printf ("window = %s, getting %s",
+		    m_window->name (), (height ? "height" : "width"));
+
   if (height)
     {
       *min_value = m_window->min_height ();
@@ -438,6 +444,8 @@ tui_layout_window::get_sizes (bool height, int *min_value, int *max_value)
       *min_value = m_window->min_width ();
       *max_value = m_window->max_width ();
     }
+
+  tui_debug_printf ("min = %d, max = %d", *min_value, *max_value);
 }
 
 /* See tui-layout.h.  */
@@ -522,6 +530,8 @@ tui_layout_split::clone () const
 void
 tui_layout_split::get_sizes (bool height, int *min_value, int *max_value)
 {
+  TUI_SCOPED_DEBUG_ENTER_EXIT;
+
   *min_value = 0;
   *max_value = 0;
   bool first_time = true;
@@ -544,6 +554,8 @@ tui_layout_split::get_sizes (bool height, int *min_value, int *max_value)
 	}
       first_time = false;
     }
+
+  tui_debug_printf ("min_value = %d, max_value = %d", *min_value, *max_value);
 }
 
 /* See tui-layout.h.  */
@@ -578,9 +590,46 @@ tui_layout_split::set_weights_from_sizes ()
 
 /* See tui-layout.h.  */
 
+std::string
+tui_layout_split::tui_debug_weights_to_string () const
+{
+  std::string str;
+
+  for (int i = 0; i < m_splits.size (); ++i)
+    {
+      if (i > 0)
+       str += ", ";
+      str += string_printf ("[%d] %d", i, m_splits[i].weight);
+    }
+
+  return str;
+}
+
+/* See tui-layout.h.  */
+
+void
+tui_layout_split::tui_debug_print_size_info
+  (const std::vector<tui_layout_split::size_info> &info)
+{
+  gdb_assert (debug_tui);
+
+  tui_debug_printf ("current size info data:");
+  for (int i = 0; i < info.size (); ++i)
+    tui_debug_printf ("  [%d] { size = %d, min = %d, max = %d, share_box = %d }",
+		      i, info[i].size, info[i].min_size,
+		      info[i].max_size, info[i].share_box);
+}
+
+/* See tui-layout.h.  */
+
 tui_adjust_result
 tui_layout_split::set_size (const char *name, int new_size, bool set_width_p)
 {
+  TUI_SCOPED_DEBUG_ENTER_EXIT;
+
+  tui_debug_printf ("this = %p, name = %s, new_size = %d",
+		    this, name, new_size);
+
   /* Look through the children.  If one is a layout holding the named
      window, we're done; or if one actually is the named window,
      update it.  */
@@ -611,10 +660,15 @@ tui_layout_split::set_size (const char *name, int new_size, bool set_width_p)
   if (curr_size == new_size)
     return HANDLED;
 
+  tui_debug_printf ("found window %s at index %d", name, found_index);
+
   set_weights_from_sizes ();
   int delta = m_splits[found_index].weight - new_size;
   m_splits[found_index].weight = new_size;
 
+  tui_debug_printf ("before delta (%d) distribution, weights: %s",
+		    delta, tui_debug_weights_to_string ().c_str ());
+
   /* Distribute the "delta" over the next window; but if the next
      window cannot hold it all, keep going until we either find a
      window that does, or until we loop all the way around.  */
@@ -643,8 +697,14 @@ tui_layout_split::set_size (const char *name, int new_size, bool set_width_p)
 	  m_splits[index].weight += grow_by;
 	  delta -= grow_by;
 	}
+
+      tui_debug_printf ("index = %d, weight now: %d",
+			index, m_splits[index].weight);
     }
 
+  tui_debug_printf ("after delta (%d) distribution, weights: %s",
+		    delta, tui_debug_weights_to_string ().c_str ());
+
   if (delta != 0)
     {
       if (set_width_p)
@@ -668,23 +728,18 @@ tui_layout_split::set_size (const char *name, int new_size, bool set_width_p)
 void
 tui_layout_split::apply (int x_, int y_, int width_, int height_)
 {
+  TUI_SCOPED_DEBUG_ENTER_EXIT;
+
   x = x_;
   y = y_;
   width = width_;
   height = height_;
 
-  struct size_info
-  {
-    int size;
-    int min_size;
-    int max_size;
-    /* True if this window will share a box border with the previous
-       window in the list.  */
-    bool share_box;
-  };
-
   std::vector<size_info> info (m_splits.size ());
 
+  tui_debug_printf ("weights are: %s",
+		    tui_debug_weights_to_string ().c_str ());
+
   /* Step 1: Find the min and max size of each sub-layout.
      Fixed-sized layouts are given their desired size, and then the
      remaining space is distributed among the remaining windows
@@ -760,9 +815,31 @@ tui_layout_split::apply (int x_, int y_, int width_, int height_)
 	}
     }
 
+  if (debug_tui)
+    {
+      tui_debug_printf ("after initial size calculation");
+      tui_debug_printf ("available_size = %d, used_size = %d",
+			available_size, used_size);
+      tui_debug_printf ("total_weight = %d, last_index = %d",
+			total_weight, last_index);
+      tui_debug_print_size_info (info);
+    }
+
   /* Allocate any leftover size.  */
   if (available_size >= used_size && last_index != -1)
-    info[last_index].size += available_size - used_size;
+    {
+      info[last_index].size += available_size - used_size;
+
+      if (debug_tui)
+	{
+	  tui_debug_printf ("after final size calculation");
+	  tui_debug_printf ("available_size = %d, used_size = %d",
+			    available_size, used_size);
+	  tui_debug_printf ("total_weight = %d, last_index = %d",
+			    total_weight, last_index);
+	  tui_debug_print_size_info (info);
+	}
+    }
 
   /* Step 3: Resize.  */
   int size_accum = 0;
diff --git a/gdb/tui/tui-layout.h b/gdb/tui/tui-layout.h
index 79ad0b8dafc..26de3c3a979 100644
--- a/gdb/tui/tui-layout.h
+++ b/gdb/tui/tui-layout.h
@@ -249,6 +249,31 @@ class tui_layout_split : public tui_layout_base
      widths (when m_vertical is false).  */
   void set_weights_from_sizes ();
 
+  /* Structure used when resizing, or applying a layout.  An instance of
+     this structure is created for each sub-layout.  */
+  struct size_info
+  {
+    /* The calculated size for this sub-layout.  */
+    int size;
+
+    /* The minimum and maximum sizes for this sub-layout, obtained by
+       calling the get_sizes member function.  */
+    int min_size;
+    int max_size;
+
+    /* True if this window will share a box border with the previous
+       window in the list.  */
+    bool share_box;
+  };
+
+  /* Used for debug, prints the contents of INFO using tui_debug_printf.
+     Only call this when the global debug_tui is true.  */
+  static void tui_debug_print_size_info (const std::vector<size_info> &info);
+
+  /* Used for debug, returns a string describing the current weight of each
+     sub-layout.  */
+  std::string tui_debug_weights_to_string () const;
+
   struct split
   {
     /* The requested weight.  */
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index 776dccf0bb2..6332eceb4af 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -50,6 +50,19 @@
 #include "gdb_curses.h"
 #include "interps.h"
 
+/* See tui.h.  */
+
+bool debug_tui = false;
+
+/* Implement 'show debug tui'.  */
+
+static void
+show_tui_debug (struct ui_file *file, int from_tty,
+		struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("TUI debugging is \"%s\".\n"), value);
+}
+
 /* This redefines CTRL if it is not already defined, so it must come
    after terminal state releated include files like <term.h> and
    "gdb_curses.h".  */
@@ -354,6 +367,8 @@ gdb_getenv_term (void)
 void
 tui_enable (void)
 {
+  TUI_SCOPED_DEBUG_ENTER_EXIT;
+
   if (tui_active)
     return;
 
@@ -494,6 +509,8 @@ tui_enable (void)
 void
 tui_disable (void)
 {
+  TUI_SCOPED_DEBUG_ENTER_EXIT;
+
   if (!tui_active)
     return;
 
@@ -587,4 +604,13 @@ Usage: tui enable"),
 	   _("Disable TUI display mode.\n\
 Usage: tui disable"),
 	   tuicmd);
+
+  /* Debug this tui internals.  */
+  add_setshow_boolean_cmd ("tui", class_maintenance, &debug_tui,  _("\
+Set tui debugging."), _("\
+Show tui debugging."), _("\
+When true, tui specific internal debugging is enabled."),
+			   NULL,
+			   show_tui_debug,
+			   &setdebuglist, &showdebuglist);
 }
diff --git a/gdb/tui/tui.h b/gdb/tui/tui.h
index a4df66f17fc..924d91daa7e 100644
--- a/gdb/tui/tui.h
+++ b/gdb/tui/tui.h
@@ -22,6 +22,20 @@
 #ifndef TUI_TUI_H
 #define TUI_TUI_H
 
+/* Flag to control tui debugging.  */
+
+extern bool debug_tui;
+
+/* Print a "tui" debug statement.  */
+
+#define tui_debug_printf(fmt, ...) \
+  debug_prefixed_printf_cond (debug_tui, "tui", fmt, ##__VA_ARGS__)
+
+/* Print "tui" enter/exit debug statements.  */
+
+#define TUI_SCOPED_DEBUG_ENTER_EXIT \
+  scoped_debug_enter_exit (debug_tui, "tui")
+
 struct ui_file;
 
 /* Types of error returns.  */
-- 
2.25.4


  parent reply	other threads:[~2022-03-07 22:14 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-28 15:55 [PATCH 0/7] TUI command changes, including new winwidth command Andrew Burgess
2022-01-28 15:55 ` [PATCH 1/7] gdb/tui: add window width information to 'info win' output Andrew Burgess
2022-01-28 17:00   ` Eli Zaretskii
2022-02-06 13:43   ` Andrew Burgess
2022-01-28 15:55 ` [PATCH 2/7] gdb/doc: update docs for 'info win' and 'winheight' commands Andrew Burgess
2022-01-28 17:03   ` Eli Zaretskii
2022-02-06 13:43     ` Andrew Burgess
2022-01-28 15:55 ` [PATCH 3/7] gdb: move some commands into the tui namespace Andrew Burgess
2022-01-28 17:04   ` Eli Zaretskii
2022-01-28 15:55 ` [PATCH 4/7] gdb/tui: rename tui_layout_base::adjust_size to ::set_height Andrew Burgess
2022-01-28 15:55 ` [PATCH 5/7] gdb/tui: rename tui_layout_split:set_weights_from_heights Andrew Burgess
2022-01-28 15:55 ` [PATCH 6/7] gdb/testing/tui: add new functionality to tuiterm.exp Andrew Burgess
2022-01-28 15:55 ` [PATCH 7/7] gdb/tui: add new 'tui window width' command and 'winwidth' alias Andrew Burgess
2022-01-28 17:05   ` Eli Zaretskii
2022-02-06 14:12 ` [PATCHv2 00/15] TUI changes, new winwidth command and resizing changes Andrew Burgess
2022-02-06 14:12   ` [PATCHv2 01/15] gdb: move some commands into the tui namespace Andrew Burgess
2022-02-06 15:50     ` Eli Zaretskii
2022-02-06 14:12   ` [PATCHv2 02/15] gdb/tui: rename tui_layout_base::adjust_size to ::set_height Andrew Burgess
2022-02-06 14:12   ` [PATCHv2 03/15] gdb/tui: rename tui_layout_split:set_weights_from_heights Andrew Burgess
2022-02-06 14:12   ` [PATCHv2 04/15] gdb/testing/tui: add new functionality to tuiterm.exp Andrew Burgess
2022-03-04 16:29     ` Tom Tromey
2022-02-06 14:12   ` [PATCHv2 05/15] gdb/tui: add new 'tui window width' command and 'winwidth' alias Andrew Burgess
2022-02-06 15:52     ` Eli Zaretskii
2022-02-09 15:33       ` Andrew Burgess
2022-02-09 17:03         ` Eli Zaretskii
2022-03-03 18:52     ` Pedro Alves
2022-02-06 14:12   ` [PATCHv2 06/15] gdb/tui: add a tui debugging flag Andrew Burgess
2022-02-06 15:53     ` Eli Zaretskii
2022-03-04 16:35     ` Tom Tromey
2022-02-06 14:12   ` [PATCHv2 07/15] gdb/tui: add left_boxed_p and right_boxed_p member functions Andrew Burgess
2022-03-04 16:37     ` Tom Tromey
2022-02-06 14:12   ` [PATCHv2 08/15] gdb/tui/testsuite: refactor new-layout.exp test Andrew Burgess
2022-02-06 14:12   ` [PATCHv2 09/15] gdb/tui: avoid fp exception when applying layouts Andrew Burgess
2022-02-06 14:12   ` [PATCHv2 10/15] gdb/tui: fairer distribution of excess space during apply Andrew Burgess
2022-03-04 16:42     ` Tom Tromey
2022-02-06 14:12   ` [PATCHv2 11/15] gdb/tui: allow cmd window to change size in tui_layout_split::apply Andrew Burgess
2022-02-06 14:12   ` [PATCHv2 12/15] gdb/tui: support placing the cmd window into a horizontal layout Andrew Burgess
2022-03-04 17:17     ` Tom Tromey
2022-03-07 20:05       ` Andrew Burgess
2022-03-07 21:24         ` Tom Tromey
2022-02-06 14:12   ` [PATCHv2 13/15] gdb/testsuite: some additional tests in gdb.tui/scroll.exp Andrew Burgess
2022-02-06 14:12   ` [PATCHv2 14/15] gdb/tui: relax restrictions on window max height and width Andrew Burgess
2022-03-04 17:20     ` Tom Tromey
2022-03-07 20:08       ` Andrew Burgess
2022-02-06 14:12   ` [PATCHv2 15/15] gdb/tui: fair split of delta after a resize Andrew Burgess
2022-03-04 17:22     ` Tom Tromey
2022-03-07 22:07       ` Andrew Burgess
2022-03-07 23:42         ` Tom Tromey
2022-02-21 17:29   ` [PATCHv2 00/15] TUI changes, new winwidth command and resizing changes Andrew Burgess
2022-03-02 17:59     ` Andrew Burgess
2022-03-07 22:13   ` [PATCHv3 " Andrew Burgess
2022-03-07 22:13     ` [PATCHv3 01/15] gdb: move some commands into the tui namespace Andrew Burgess
2022-03-07 22:13     ` [PATCHv3 02/15] gdb/tui: rename tui_layout_base::adjust_size to ::set_height Andrew Burgess
2022-03-07 22:13     ` [PATCHv3 03/15] gdb/tui: rename tui_layout_split:set_weights_from_heights Andrew Burgess
2022-03-07 22:13     ` [PATCHv3 04/15] gdb/testing/tui: add new functionality to tuiterm.exp Andrew Burgess
2022-03-07 22:13     ` [PATCHv3 05/15] gdb/tui: add new 'tui window width' command and 'winwidth' alias Andrew Burgess
2022-03-07 22:13     ` Andrew Burgess [this message]
2022-03-08 12:16       ` [PATCHv3 06/15] gdb/tui: add a tui debugging flag Eli Zaretskii
2022-03-09 11:48         ` Andrew Burgess
2022-03-09 12:58           ` Eli Zaretskii
2022-03-09 17:53           ` Tom Tromey
2022-03-07 22:13     ` [PATCHv3 07/15] gdb/tui: add left_boxed_p and right_boxed_p member functions Andrew Burgess
2022-03-07 22:13     ` [PATCHv3 08/15] gdb/tui/testsuite: refactor new-layout.exp test Andrew Burgess
2022-03-07 22:13     ` [PATCHv3 09/15] gdb/tui: avoid fp exception when applying layouts Andrew Burgess
2022-03-07 22:13     ` [PATCHv3 10/15] gdb/tui: fairer distribution of excess space during apply Andrew Burgess
2022-03-07 22:13     ` [PATCHv3 11/15] gdb/tui: allow cmd window to change size in tui_layout_split::apply Andrew Burgess
2022-03-07 22:13     ` [PATCHv3 12/15] gdb/tui: support placing the cmd window into a horizontal layout Andrew Burgess
2022-03-07 22:13     ` [PATCHv3 13/15] gdb/testsuite: some additional tests in gdb.tui/scroll.exp Andrew Burgess
2022-03-07 22:13     ` [PATCHv3 14/15] gdb/tui: relax restrictions on window max height and width Andrew Burgess
2022-03-07 22:13     ` [PATCHv3 15/15] gdb/tui: fair split of delta after a resize Andrew Burgess
2022-03-21 17:52     ` [PATCHv3 00/15] TUI changes, new winwidth command and resizing changes Andrew Burgess
2022-03-30  9:13       ` Andrew Burgess
2022-04-03 14:43         ` Andrew Burgess
2022-03-04 17:23 ` [PATCH 0/7] TUI command changes, including new winwidth command Tom Tromey

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=de69e7d915c5123008e188d73462007a24c7b002.1646691034.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).