From: Tom Tromey Date: Fri, 12 Dec 2025 19:09:56 +0000 (-0700) Subject: Untabify gdb 'help' output X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1f9e31594acb8b04c68383dcc0f3ff843367f318;p=thirdparty%2Fbinutils-gdb.git Untabify gdb 'help' output 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 --- diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 32bcf962e4c..a4ff6461c6f 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -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, diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index 62f2a8b2142..e2e35598803 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -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); diff --git a/gdb/contrib/check-whitespace-pre-commit.py b/gdb/contrib/check-whitespace-pre-commit.py index 9d82f7749a0..cc2d4ad5f4a 100755 --- a/gdb/contrib/check-whitespace-pre-commit.py +++ b/gdb/contrib/check-whitespace-pre-commit.py @@ -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: diff --git a/gdb/symfile.c b/gdb/symfile.c index 11388772ff5..8230332d4b4 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -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\ diff --git a/gdb/testsuite/gdb.mi/mi-cli.exp b/gdb/testsuite/gdb.mi/mi-cli.exp index 776368911be..11ed6b45027 100644 --- a/gdb/testsuite/gdb.mi/mi-cli.exp +++ b/gdb/testsuite/gdb.mi/mi-cli.exp @@ -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. diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c index 9b3e0a802ea..a7fb8fd0f82 100644 --- a/gdb/tui/tui-regs.c +++ b/gdb/tui/tui-regs.c @@ -36,45 +36,6 @@ #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 (); diff --git a/gdb/ui-file.c b/gdb/ui-file.c index 2e5c06fb43b..77794aa145c 100644 --- a/gdb/ui-file.c +++ b/gdb/ui-file.c @@ -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; + } + } +} diff --git a/gdb/ui-file.h b/gdb/ui-file.h index 1219bde0a75..222d014ee58 100644 --- a/gdb/ui-file.h +++ b/gdb/ui-file.h @@ -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 */