]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Untabify gdb 'help' output
authorTom Tromey <tromey@adacore.com>
Fri, 12 Dec 2025 19:09:56 +0000 (12:09 -0700)
committerTom Tromey <tromey@adacore.com>
Tue, 16 Dec 2025 17:14:17 +0000 (10:14 -0700)
This changes the gdb 'help' command to untabify its output.  This lets
us fix the last couple of warnings from the whitespace checker.

Regression tested on x86-64 Fedora 41.

Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/cli/cli-cmds.c
gdb/cli/cli-decode.c
gdb/contrib/check-whitespace-pre-commit.py
gdb/symfile.c
gdb/testsuite/gdb.mi/mi-cli.exp
gdb/tui/tui-regs.c
gdb/ui-file.c
gdb/ui-file.h

index 32bcf962e4c212237571ddcd049682a8fd0295ae..a4ff6461c6f52d98991b958d2839ee6dd9623dc1 100644 (file)
@@ -2745,7 +2745,7 @@ Show mode for script filename extension recognition."), _("\
 off  == no filename extension recognition (all sourced files are GDB scripts)\n\
 soft == evaluate script according to filename extension, fallback to GDB script\n\
 strict == evaluate script according to filename extension,\n\
-          error if not supported"
+         error if not supported"
   ),
                        NULL,
                        show_script_ext_mode,
index 62f2a8b21423785b11913c1b62822fc3619a3b5b..e2e35598803d82780ed77925240185f0e20a0750 100644 (file)
@@ -1880,7 +1880,10 @@ help_cmd (const char *command, struct ui_file *stream)
         the false indicates to not output the (single) command name.  */
       fput_command_names_styled (*c, false, "\n", stream);
       fput_aliases_definition_styled (*c, stream);
-      gdb_puts (c->doc, stream);
+
+      /* Be sure to expand TABs in the documentation.  */
+      tab_expansion_file expander (stream);
+      gdb_puts (c->doc, &expander);
     }
   else
     {
@@ -1897,7 +1900,7 @@ help_cmd (const char *command, struct ui_file *stream)
 
   gdb_printf (stream, "\n");
 
-  /* If this is a prefix command, print it's subcommands.  */
+  /* If this is a prefix command, print its subcommands.  */
   if (c->is_prefix ())
     help_list (*c->subcommands, c->prefixname_no_space ().c_str (),
               all_commands, stream);
index 9d82f7749a08ab95897a86e55ed4dbe46069b86e..cc2d4ad5f4a7118eba46c3be52fb50d3f42be3f3 100755 (executable)
@@ -21,14 +21,11 @@ import sys
 re_clean = re.compile(
     "(^(gdb/testsuite/|gdbsupport/|gdbserver/)|[.](m4|ac|def|[chly])$|NEWS)"
 )
-re_clean_exclude = re.compile("^(gdb/symfile.c|gdb/cli/cli-cmds.c)$")
 
 clean = []
 other = []
 for f in sys.argv[1:]:
     m = re_clean.search(f)
-    if m and re_clean_exclude.search(f):
-        m = None
     if m:
         clean.append(f)
     else:
index 11388772ff5f4e8bb3fbce696296d47893f3901e..8230332d4b445bf528231534765df5d28dc5bf0e 100644 (file)
@@ -3808,7 +3808,7 @@ to execute.\n" READNOW_READNEVER_HELP), &cmdlist);
   c = add_cmd ("add-symbol-file", class_files, add_symbol_file_command, _("\
 Load symbols from FILE, assuming FILE has been dynamically loaded.\n\
 Usage: add-symbol-file FILE [-readnow|-readnever] [-o OFF] [ADDR]\n\
-                       [-s SECT-NAME SECT-ADDR]...\n\
+                      [-s SECT-NAME SECT-ADDR]...\n\
 ADDR is the starting address of the file's text.\n\
 Each '-s' argument provides a section name and address, and\n\
 should be specified if the data and bss segments are not contiguous\n\
index 776368911be1192e9124c9f02f6c10c2d0c7bc17..11ed6b450278493b043d6612bbcc89e23aadea62 100644 (file)
@@ -239,7 +239,7 @@ mi_gdb_test "-interpreter-exec console \"list\"" \
     "-interpreter-exec console \"list\" at basics.c:\$line_main_callme_2"
 
 mi_gdb_test "-interpreter-exec console \"help set args\"" \
-  {\~"Set argument list to give program being debugged when it is started\.\\nFollow this command with any number of args, to be passed to the program\.".*\^done} \
+  {~"Set argument list to give program being debugged when it is started\.\\n".*~"Follow this command with any number of args, to be passed to the program\.\\n".*\^done} \
   "-interpreter-exec console \"help set args\""
 
 # NOTE: cagney/2003-02-03: Not yet.
index 9b3e0a802ea82c77563fadbc9904034a7eee6121..a7fb8fd0f8250263f5f33b0c325d485f85ccd5cd 100644 (file)
 
 #include "gdb_curses.h"
 
-/* A subclass of string_file that expands tab characters.  */
-class tab_expansion_file : public string_file
-{
-public:
-
-  tab_expansion_file () = default;
-
-  void write (const char *buf, long length_buf) override;
-
-private:
-
-  int m_column = 0;
-};
-
-void
-tab_expansion_file::write (const char *buf, long length_buf)
-{
-  for (long i = 0; i < length_buf; ++i)
-    {
-      if (buf[i] == '\t')
-       {
-         do
-           {
-             string_file::write (" ", 1);
-             ++m_column;
-           }
-         while ((m_column % 8) != 0);
-       }
-      else
-       {
-         string_file::write (&buf[i], 1);
-         if (buf[i] == '\n')
-           m_column = 0;
-         else
-           ++m_column;
-       }
-    }
-}
-
 /* Get the register from the frame and return a printable
    representation of it.  */
 
@@ -84,8 +45,9 @@ tui_register_format (const frame_info_ptr &frame, int regnum)
   struct gdbarch *gdbarch = get_frame_arch (frame);
 
   /* Expand tabs into spaces, since ncurses on MS-Windows doesn't.  */
-  tab_expansion_file stream;
-  gdbarch_print_registers_info (gdbarch, &stream, frame, regnum, 1);
+  string_file stream;
+  tab_expansion_file expander (&stream);
+  gdbarch_print_registers_info (gdbarch, &expander, frame, regnum, 1);
 
   /* Remove the possible \n.  */
   std::string str = stream.release ();
index 2e5c06fb43b12a93e06dfa772e1320f8fb8afefe..77794aa145c80784182d298f70841f17235c8a00 100644 (file)
@@ -524,3 +524,28 @@ timestamped_file::write (const char *buf, long len)
   else
     m_stream->write (buf, len);
 }
+
+void
+tab_expansion_file::write (const char *buf, long length_buf)
+{
+  for (long i = 0; i < length_buf; ++i)
+    {
+      if (buf[i] == '\t')
+       {
+         do
+           {
+             m_stream->write (" ", 1);
+             ++m_column;
+           }
+         while ((m_column % 8) != 0);
+       }
+      else
+       {
+         m_stream->write (&buf[i], 1);
+         if (buf[i] == '\n')
+           m_column = 0;
+         else
+           ++m_column;
+       }
+    }
+}
index 1219bde0a75809ad2ff727f7df8924510041e223..222d014ee58acc3f321bed1ae72a2423a8f2954a 100644 (file)
@@ -484,4 +484,27 @@ private:
   bool m_needs_timestamp = true;
 };
 
+/* A wrapped_file that expands TABs as it prints.  A TAB character is
+   always processed and will expand to the number of spaces required
+   to move to the next tab stop.
+
+   Note that this only really handles ASCII output correctly.  */
+
+class tab_expansion_file : public wrapped_file
+{
+public:
+
+  explicit tab_expansion_file (ui_file *stream)
+    : wrapped_file (stream)
+  {
+  }
+
+  void write (const char *buf, long length_buf) override;
+
+private:
+
+  /* The current column.  */
+  int m_column = 0;
+};
+
 #endif /* GDB_UI_FILE_H */