[PATCH] Limit register display len to preserve multiple TUI columns

Bogdan Harjoc <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <CAF4+tmrQWuP+QJMydDrn7A1uPDYkGMejxJETAbPuEbhY4mn14g@mail.gmail.com>
When TUI layout is regs+asm+cmd, if a register value can be resolved
to a symbol with a long name, the register window becomes
single-column. That makes it hard to look at registers since you have
to scroll down in the regs window.

I couldn't figure out how to make use of gdb print settings to limit
the display length, so I wrote a patch to get the max-reg-len from the
environment (attached). I could change it to make the max-len a gdb
setting, or guess it somehow if someone suggests how.

Regards,
Bogdan
gdb-8.2-max-reg-len.patch (text/x-patch, 1.3 KB)
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 7059b02..bf2c998 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -311,9 +311,13 @@ tui_display_registers_from (int start_element_no)
     {
       int i = start_element_no;
       int j, item_win_width, cur_y;
+      int len_env = 0;
+      const char *env = getenv("GDB_MAX_REG_LEN");
+
+      if (env) len_env = atoi(env);
 
       int max_len = 0;
-      for (i = 0; i < display_info->regs_content_count; i++)
+      for (; i < display_info->regs_content_count; i++)
         {
           struct tui_data_element *data;
           struct tui_gen_win_info *data_item_win;
@@ -326,17 +330,26 @@ tui_display_registers_from (int start_element_no)
           len = 0;
           p = data->content;
           if (p != 0)
-            while (*p)
-              {
-                if (*p++ == '\t')
-                  len = 8 * ((len / 8) + 1);
-                else
-                  len++;
-              }
+	    {
+	      while (*p)
+		{
+		  if (*p++ == '\t')
+		    len = 8 * ((len / 8) + 1);
+		  else
+		    len++;
+		}
+
+	      if (len_env && len > len_env)
+	      {
+		len = len_env;
+		data->content[len] = 0;
+	      }
+	    }
 
           if (len > max_len)
             max_len = len;
         }
+
       item_win_width = max_len + 1;
       i = start_element_no;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.