*** Changes since GDB 13
+* GDB now recognizes the NO_COLOR environment variable and disables
+ styling according to the spec. See https://no-color.org/.
+ Styling can be re-enabled with "set style enabled on".
+
* The AArch64 'org.gnu.gdb.aarch64.pauth' Pointer Authentication feature string
has been deprecated in favor of the 'org.gnu.gdb.aarch64.pauth_v2' feature
string.
Enable or disable all styling. The default is host-dependent, with
most hosts defaulting to @samp{on}.
+If the @env{NO_COLOR} environment variable is set to a non-empty
+value, then @value{GDBN} will change this to @samp{off} at startup.
+
@item show style enabled
Show the current state of styling.
int save_auto_load;
int ret = 1;
+ const char *no_color = getenv ("NO_COLOR");
+ if (no_color != nullptr && *no_color != '\0')
+ cli_styling = false;
+
#ifdef HAVE_USEFUL_SBRK
/* Set this before constructing scoped_command_stats. */
lim_at_start = (char *) sbrk (0);
}
}
-save_vars { env(TERM) } {
- # We need an ANSI-capable terminal to get the output.
- setenv TERM ansi
+with_ansi_styling_terminal {
# Start GDB and confirm that the version string is styled.
save_vars { INTERNAL_GDBFLAGS env(HOME) env(XDG_CONFIG_HOME) } {
return -1
}
+setenv TERM dumb
+
# INPUTRC gets reset for the next testfile.
setenv INPUTRC $inputrc
clean_restart ${binfile}
standard_testfile
-save_vars { env(TERM) } {
- # We need an ANSI-capable terminal to get the output.
- setenv TERM ansi
-
+with_ansi_styling_terminal {
if { [prepare_for_testing "failed to prepare" \
${testfile} ${srcfile}] } {
return
standard_testfile style.c
-save_vars { env(TERM) } {
- # We need an ANSI-capable terminal to get the output.
- setenv TERM ansi
-
+with_ansi_styling_terminal {
if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
return -1
}
global testfile srcfile hex binfile
global currently_disabled_style decimal hex
- save_vars { env(TERM) } {
- # We need an ANSI-capable terminal to get the output.
- setenv TERM ansi
-
+ with_ansi_styling_terminal {
# Restart GDB with the correct TERM variable setting, this
# means that GDB will enable styling.
clean_restart_and_disable "restart 1" ${binfile}
# Python pygments module is not available, so, when we disable
# disassembler styling, we should always see a change in output.
proc test_disable_disassembler_styling { } {
- save_vars { env(TERM) } {
+ save_vars { env(TERM) env(NO_COLOR) } {
# We need an ANSI-capable terminal to get the output.
setenv TERM ansi
+ setenv NO_COLOR ""
# Restart GDB with the correct TERM variable setting, this
# means that GDB will enable styling.
return
}
- save_vars { env(TERM) } {
+ save_vars { env(TERM) env(NO_COLOR) } {
# We need an ANSI-capable terminal to get the output.
setenv TERM ansi
+ setenv NO_COLOR ""
# Restart GDB with the correct TERM variable setting, this
# means that GDB will enable styling.
# Do the same thing again, but this time check that the styling is
# correct.
with_test_prefix "check styling" {
- save_vars { env(TERM) } {
- # We need an ANSI-capable terminal to get styled output.
- setenv TERM ansi
-
+ with_ansi_styling_terminal {
clean_restart
gdb_test_no_output "set debug-file-directory ${debug_file_directory}" \
# Do the same thing again, but this time check that the styling is
# correct.
with_test_prefix "check styling" {
- save_vars { env(TERM) } {
- # We need an ANSI-capable terminal to get styled output.
- setenv TERM ansi
-
+ with_ansi_styling_terminal {
clean_restart
set debug_file_re [style "${escapedobjdirsubdir}/crc_mismatch-2\\.debug" file]
# Perform C Tests.
if { [build_inferior "${binfile}" "c"] == 0 } {
with_test_prefix "lang_c" {
- save_vars { env(TERM) } {
+ with_ansi_styling_terminal {
# We run all of these tests in an environment where styling
# could work, but we only expect the final call to
# test_styling to actually produce any styled output.
- setenv TERM ansi
set current_lang "c"
prepare_gdb "${binfile}"
test_all_common
standard_testfile
-save_vars { env(TERM) } {
+with_ansi_styling_terminal {
# We need an ANSI-capable terminal to get the output, additionally
# we need to set LC_ALL so GDB knows the terminal is UTF-8
# capable, otherwise we'll get a UnicodeEncodeError trying to
# encode the output.
- setenv TERM ansi
-
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
return -1
}
gdb_exit
}
-save_vars { env(TERM) } {
- # We need an ANSI-capable terminal to get the output.
- setenv TERM ansi
-
+with_ansi_styling_terminal {
# Check the features are off by default.
test_python_settings "off"
require allow_rust_tests
require {can_compile rust}
-save_vars { env(TERM) } {
- # We need an ANSI-capable terminal to get the output.
- setenv TERM ansi
-
+with_ansi_styling_terminal {
standard_testfile .rs
if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
{debug rust}]} {
set dumb_terminal [string equal $terminal "dumb"]
- if {$dumb_terminal} {
- clean_restart $binfile
- } else {
- Term::clean_restart 24 80 $binfile
- if {![Term::prepare_for_tui]} {
- unsupported "TUI not supported"
- return
+ global env
+ save_vars { env(TERM) } {
+ setenv TERM $terminal
+ if {$dumb_terminal} {
+ clean_restart $binfile
+ } else {
+ Term::clean_restart 24 80 $binfile
+ if {![Term::prepare_for_tui]} {
+ unsupported "TUI not supported"
+ return
+ }
}
}
# This disables style output, which would interfere with many
# tests.
- setenv TERM "dumb"
+ setenv NO_COLOR sorry
# This setting helps detect bugs in the Python code and doesn't
# seem to have a significant downside for the tests.
return $result
}
+# Run BODY after setting the TERM environment variable to 'ansi', and
+# unsetting the NO_COLOR environment variable.
+proc with_ansi_styling_terminal { body } {
+ save_vars { ::env(TERM) ::env(NO_COLOR) } {
+ # Set environment variables to allow styling.
+ setenv TERM ansi
+ unset -nocomplain ::env(NO_COLOR)
+
+ set code [catch {uplevel 1 $body} result]
+ }
+
+ if {$code == 1} {
+ global errorInfo errorCode
+ return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
+ } else {
+ return -code $code $result
+ }
+}
+
# Setup tuiterm.exp environment. To be used in test-cases instead of
# "load_lib tuiterm.exp". Calls initialization function and schedules
# finalization function.
# BODY.
proc with_tuiterm {rows cols body} {
global env stty_init
- save_vars {env(TERM) stty_init} {
+ save_vars {env(TERM) env(NO_COLOR) stty_init} {
setenv TERM ansi
+ setenv NO_COLOR ""
_setup $rows $cols
uplevel $body