mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-15 04:31:49 +08:00
9d2d8a16e1
This commit adds a new 'version' style, which replaces the hard coded styling currently used for GDB's version string. GDB's version number is displayed: 1. In the output of 'show version', and 2. When GDB starts up (without the --quiet option). This new style can only ever affect the first of these two cases as the second case is printed before GDB has processed any initialization files, or processed any GDB commands passed on the command line. However, because the first case exists I think this commit makes sense, it means the style is no longer hard coded into GDB, and we can add some tests that the style can be enabled/disabled correctly. This commit is an alternative to a patch Tom posted here: https://sourceware.org/pipermail/gdb-patches/2020-June/169820.html I've used the style name 'version' instead of 'startup' to reflect what the style is actually used for. If other parts of the startup text end up being highlighted I imagine they would get their own styles based on what is being highlighted. I feel this is more inline with the other style names that are already in use within GDB. I also decoupled adding this style from the idea of startup options, and the possibility of auto-saving startup options. Those ideas can be explored in later patches. This commit should probably be considered only a partial solution to issue PR cli/25956. The colours of the style are no longer hard coded, however, it is still impossible to change the styling of the version string displayed during startup, so in one sense, the styling of that string is still "hard coded". A later patch will hopefully extend GDB to allow it to adjust the version styling before the initial version string is printed. gdb/ChangeLog: PR cli/25956 * cli/cli-style.c: Add 'cli/cli-setshow.h' include. (version_style): Define. (cli_style_option::cli_style_option): Add intensity parameter, and use as appropriate. (_initialize_cli_style): Register version style set/show commands. * cli/cli-style.h (cli_style_option): Add intensity parameter. (version_style): Declare. * top.c (print_gdb_version): Use version_stype, and styled_string to print the GDB version string. gdb/doc/ChangeLog: PR cli/25956 * gdb.texinfo (Output Styling): Document version style. gdb/testsuite/ChangeLog: PR cli/25956 * gdb.base/style.exp (run_style_tests): Add version string test. (test_startup_version_string): Use version style name. * lib/gdb-utils.exp (style): Handle version style name.
62 lines
2.0 KiB
Plaintext
62 lines
2.0 KiB
Plaintext
# Copyright 2014-2021 Free Software Foundation, Inc.
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# Utility procedures, shared between test suite domains.
|
|
|
|
# A helper procedure to retrieve commands to send to GDB before a program
|
|
# is started.
|
|
|
|
proc gdb_init_commands {} {
|
|
set commands ""
|
|
if [target_info exists gdb_init_command] {
|
|
lappend commands [target_info gdb_init_command]
|
|
}
|
|
if [target_info exists gdb_init_commands] {
|
|
set commands [concat $commands [target_info gdb_init_commands]]
|
|
}
|
|
return $commands
|
|
}
|
|
|
|
# Given an input string, adds backslashes as needed to create a
|
|
# regexp that will match the string.
|
|
|
|
proc string_to_regexp {str} {
|
|
set result $str
|
|
regsub -all {[]?*+.|(){}^$\[\\]} $str {\\&} result
|
|
return $result
|
|
}
|
|
|
|
# Wrap STR in an ANSI terminal escape sequences -- one to set the
|
|
# style to STYLE, and one to reset the style to the default. The
|
|
# return value is suitable for use as a regular expression.
|
|
|
|
# STYLE can either be the payload part of an ANSI terminal sequence,
|
|
# or a shorthand for one of the gdb standard styles: "file",
|
|
# "function", "variable", or "address".
|
|
|
|
proc style {str style} {
|
|
switch -exact -- $style {
|
|
title { set style 1 }
|
|
file { set style 32 }
|
|
function { set style 33 }
|
|
highlight { set style 31 }
|
|
variable { set style 36 }
|
|
address { set style 34 }
|
|
metadata { set style 2 }
|
|
version { set style "35;1" }
|
|
}
|
|
return "\033\\\[${style}m${str}\033\\\[m"
|
|
}
|