--- /dev/null
+# Copyright 2023 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/>.
+
+# Test GDB's 'set print characters' setting works for Ada strings.
+
+load_lib "ada.exp"
+
+require allow_ada_tests
+
+standard_ada_testfile foo
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
+ return -1
+}
+
+clean_restart ${testfile}
+
+set bp_location [gdb_get_line_number "STOP" ${testdir}/foo.adb]
+if ![runto "foo.adb:$bp_location" ] then {
+ return -1
+}
+
+gdb_test "print Arg" \
+ " = \"abcdefghijklmnopqrstuvwxyz\"" \
+ "print with default settings"
+
+gdb_test_no_output "set print characters 26"
+gdb_test "print Arg" \
+ " = \"abcdefghijklmnopqrstuvwxyz\"" \
+ "print with character limit of 26"
+
+gdb_test "print -characters 11 -- Arg" \
+ " = \"abcdefghijk\"\\.\\.\\." \
+ "print with character limit of 11"
+
+gdb_test_no_output "set print characters 10"
+gdb_test "print Arg" \
+ " = \"abcdefghij\"\\.\\.\\." \
+ "print with character limit of 10"
+
+gdb_test_no_output "set print characters unlimited"
+gdb_test "print Arg" \
+ " = \"abcdefghijklmnopqrstuvwxyz\"" \
+ "print with unlimited character limit"
+
+# The 'set print elements' command used to control printing of characters
+# in a string, before we created 'set print characters'. This test makes
+# sure that 'set print elements' doens't effect string printing any more.
+gdb_test_no_output "set print elements 12"
+gdb_test "print Arg" \
+ " = \"abcdefghijklmnopqrstuvwxyz\"" \
+ "print with unlimited character limit, but lower element limit"
+
+# Except when 'set print characters elements' has been used.
+gdb_test_no_output "set print characters elements"
+gdb_test "print Arg" \
+ " = \"abcdefghijkl\"\\.\\.\\." \
+ "print with character limit of elements"
--- /dev/null
+-- Copyright 2023 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/>.
+
+procedure Foo is
+
+ procedure Blah (Arg : String) is
+ begin
+ null; -- STOP
+ end;
+
+begin
+
+ Blah ("abcdefghijklmnopqrstuvwxyz");
+end Foo;
}
# Test interaction of the number of print elements to print and the
-# repeat count, set to the default of 10.
+# repeat count, set to the default of 10. SETTING is the print
+# setting to verify, either "elements" or "characters".
-proc test_print_repeats_10 {} {
+proc test_print_repeats_10_one { setting } {
global gdb_prompt decimal
for { set x 1 } { $x <= 16 } { incr x } {
- gdb_test_no_output "set print elements $x" "elements $x repeats"
+ gdb_test_no_output "set print $setting $x" "$setting $x repeats"
for { set e 1 } { $e <= 16 } {incr e } {
set v [expr $e - 1]
set command "p &ctable2\[${v}*16\]"
set xstr "${xstr}\[.\]\[.\]\[.\]"
}
set string " = \[(\]unsigned char \[*\]\[)\] <ctable2(\\+$decimal)?> ${a}${xstr}"
- gdb_test "$command" "$string" "$command with print elements set to $x"
+ gdb_test "$command" "$string" "$command with print $setting set to $x"
}
}
}
+proc test_print_repeats_10 {} {
+ foreach_with_prefix setting { "elements" "characters" } {
+ test_print_repeats_10_one $setting
+ }
+ gdb_test_no_output "set print characters elements"
+}
+
# This tests whether GDB uses the correct element content offsets
# (relative to the complete `some_struct' value) when counting value
# repetitions.
"correct element repeats in array embedded at offset > 0"
}
-proc test_print_strings {} {
+proc test_print_strings_one { setting } {
global gdb_prompt decimal
# We accept "(unsigned char *) " before the string. char vs. unsigned char
# Test that setting print elements unlimited doesn't completely suppress
# printing; this was a bug in older gdb's.
- gdb_test_no_output "set print elements 0"
+ gdb_test_no_output "set print $setting 0"
gdb_test "p teststring" \
- " = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 0"
- gdb_test_no_output "set print elements 1"
+ " = (.unsigned char .. )?\"teststring contents\"" "p teststring with $setting set to 0"
+ gdb_test_no_output "set print $setting 1"
gdb_test "p teststring" \
- " = (.unsigned char .. )?\"t\"\\.\\.\\." "p teststring with elements set to 1"
- gdb_test_no_output "set print elements 5"
+ " = (.unsigned char .. )?\"t\"\\.\\.\\." "p teststring with $setting set to 1"
+ gdb_test_no_output "set print $setting 5"
gdb_test "p teststring" \
- " = (.unsigned char .. )?\"tests\"\\.\\.\\." "p teststring with elements set to 5"
- gdb_test_no_output "set print elements 19"
+ " = (.unsigned char .. )?\"tests\"\\.\\.\\." "p teststring with $setting set to 5"
+ gdb_test_no_output "set print $setting 19"
gdb_test "p teststring" \
- " = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 19"
- gdb_test_no_output "set print elements 20"
+ " = (.unsigned char .. )?\"teststring contents\"" "p teststring with $setting set to 19"
+ gdb_test_no_output "set print $setting 20"
gdb_test "p teststring" \
- " = (.unsigned char .. )?\"teststring contents\"" "p teststring with elements set to 20"
+ " = (.unsigned char .. )?\"teststring contents\"" "p teststring with $setting set to 20"
- gdb_test "p -elements 1 -- teststring" \
+ gdb_test "p -$setting 1 -- teststring" \
" = (.unsigned char .. )?\"t\"\\.\\.\\."
- gdb_test "p -elements 5 -- teststring" \
+ gdb_test "p -$setting 5 -- teststring" \
" = (.unsigned char .. )?\"tests\"\\.\\.\\."
- gdb_test "p -elements 19 -- teststring" \
+ gdb_test "p -$setting 19 -- teststring" \
" = (.unsigned char .. )?\"teststring contents\""
- gdb_test "p -elements 20 -- teststring" \
+ gdb_test "p -$setting 20 -- teststring" \
" = (.unsigned char .. )?\"teststring contents\""
gdb_test "print teststring2" \
" = \\(charptr\\) \"more contents\""
- gdb_test_no_output "set print elements 8"
+ gdb_test_no_output "set print $setting 8"
# Set the target-charset to ASCII, because the output varies from
# different charset.
gdb_test "p &ctable1\[31*8\]" \
" = \\(unsigned char \\*\\) <ctable1\\+$decimal> \"\\\\370\\\\371\\\\372\\\\373\\\\374\\\\375\\\\376\\\\377\"..."
}
+
+ gdb_test_no_output "set print $setting unlimited"
+}
+
+proc test_print_strings {} {
+
+ foreach_with_prefix setting { "elements" "characters" } {
+ test_print_strings_one $setting
+ }
+
+ gdb_test "p -elements 8 -- teststring" \
+ " = (.unsigned char .. )?\"teststring contents\""
+ gdb_test "p -characters 8 -- teststring" \
+ " = (.unsigned char .. )?\"teststri\"\\.\\.\\."
+ gdb_test "p -elements 8 -characters elements -- teststring" \
+ " = (.unsigned char .. )?\"teststri\"\\.\\.\\."
+
+ with_test_prefix strings {
+ gdb_test_no_output "set print characters elements"
+ }
}
proc test_print_int_arrays {} {
gdb_test "show listsize" "Number of source lines gdb will list by default is 100..*" "show listsize (100)"
}
+proc_with_prefix test_setshow_print_characters {} {
+ clean_restart
+
+ gdb_test "p \$_gdb_setting(\"print characters\")" " = void" \
+ "_gdb_setting print characters default"
+ gdb_test "p \$_gdb_setting_str(\"print characters\")" " = \"elements\"" \
+ "_gdb_setting_str print characters default"
+
+ gdb_test_no_output "set print characters unlimited"
+ gdb_test "p \$_gdb_setting(\"print characters\")" " = 0" \
+ "_gdb_setting print characters unlimited"
+ gdb_test "p \$_gdb_setting_str(\"print characters\")" " = \"unlimited\"" \
+ "_gdb_setting_str print characters unlimited"
+
+ gdb_test_no_output "set print characters 1"
+ gdb_test "p \$_gdb_setting(\"print characters\")" " = 1" \
+ "_gdb_setting print characters 1"
+ gdb_test "p \$_gdb_setting_str(\"print characters\")" " = \"1\"" \
+ "_gdb_setting_str print characters 1"
+}
+
proc_with_prefix test_setshow_prompt {} {
clean_restart
test_setshow_history
test_setshow_language
test_setshow_listsize
+test_setshow_print_characters
test_setshow_prompt
test_setshow_radix
test_setshow_width
"listsize"
"print elements"
"max-completions"
+ "print characters"
} {
set param_range_error "integer -1 out of range"
set param_type_error \
set param_get_minus_one -1
set param_set_minus_one ""
}
- "print elements" {
+ "print elements" -
+ "print characters" {
set param_get_zero "#:unlimited"
set param_get_minus_one "#:unlimited"
set param_set_minus_one $param_range_error
gdb_test "guile (print (parameter-value \"$param\"))" \
"#:unlimited" "test value of 'unlimited'"
+
+ if {$param == "print characters"} {
+ gdb_test_no_output "set $param elements" "test set to 'elements'"
+
+ gdb_test "guile (print (parameter-value \"$param\"))" \
+ "#:elements" "test value of 'elements'"
+ }
}
foreach_with_prefix kind {
--- /dev/null
+# Copyright 2023 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/>.
+
+load_lib "pascal.exp"
+
+standard_testfile .pas
+
+if {[gdb_compile_pascal "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug ]] != "" } {
+ return -1
+}
+
+clean_restart ${testfile}
+
+if { ![runto_main] } {
+ return
+}
+
+gdb_breakpoint ${srcfile}:[gdb_get_line_number "set breakpoint 1 here"]
+
+gdb_continue_to_breakpoint "continue to breakpoint"
+
+gdb_test "print message" " = 'abcdefghijklmnopqrstuvwxyz'" \
+ "print message with the default settings"
+
+gdb_test_no_output "set print elements 10"
+gdb_test "print message" " = 'abcdefghij'\\.\\.\\." \
+ "print message with 'print elements' set to 10"
+
+gdb_test_no_output "set print characters 20"
+gdb_test "print message" " = 'abcdefghijklmnopqrst'\\.\\.\\." \
+ "print message with 'print characters' set to 20"
+
+gdb_test_no_output "set print elements 15"
+gdb_test "print message" " = 'abcdefghijklmnopqrst'\\.\\.\\." \
+ "print message with 'print elements' set to 15"
+
+gdb_test_no_output "set print characters unlimited"
+gdb_test "print message" " = 'abcdefghijklmnopqrstuvwxyz'" \
+ "print message with 'print characters' set to unlimited"
+
+gdb_test_no_output "set print characters elements"
+gdb_test "print message" " = 'abcdefghijklmno'\\.\\.\\." \
+ "print message with 'print characters' set to elements"
--- /dev/null
+{
+ Copyright 2023 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/>.
+}
+
+program str_char;
+
+var
+ message : string;
+
+begin
+
+ message := 'abcdefghijklmnopqrstuvwxyz';
+ writeln (message) { set breakpoint 1 here }
+
+end.
}
# Test the max_elements option for gdb.Value.format_string.
-proc_with_prefix test_max_elements {} {
+# SETTING is the print setting to verify, either "elements"
+# or "characters". UNLIMITED is the numeric value to use
+# for the "unlimited" setting.
+
+proc test_max_string_one { setting unlimited } {
global current_lang
global default_pointer_regexp
# 200 is the default maximum number of elements, so setting it should
# not change the output.
- set opts "max_elements=200"
+ set opts "max_$setting=200"
with_test_prefix $opts {
check_format_string "a_point_t" $opts
check_format_string "a_point_t_pointer" $opts
check_format_string "a_binary_string" $opts
check_format_string "a_binary_string_array" $opts
check_format_string "a_big_string" $opts
- check_format_string "an_array" $opts
- check_format_string "an_array_with_repetition" $opts
+ if { $setting == "elements" } {
+ check_format_string "an_array" $opts
+ check_format_string "an_array_with_repetition" $opts
+ }
check_format_string "a_symbol_pointer" $opts
if { $current_lang == "c++" } {
}
}
- set opts "max_elements=3"
+ set opts "max_$setting=3"
with_test_prefix $opts {
check_format_string "a_point_t" $opts
check_format_string "a_point_t_pointer" $opts
"\"hell\"..."
check_format_string "a_big_string" $opts \
[get_cut_big_string 3]
- check_format_string "an_array" $opts
- check_format_string "an_array_with_repetition" $opts \
- "\\{1, 3 <repeats 12 times>...\\}"
+ if { $setting == "elements"} {
+ check_format_string "an_array" $opts
+ check_format_string "an_array_with_repetition" $opts \
+ "\\{1, 3 <repeats 12 times>...\\}"
+ }
check_format_string "a_symbol_pointer" $opts
if { $current_lang == "c++" } {
}
}
- # Both 1,000 (we don't have that many elements) and 0 (unlimited) should
+ # Both 1,000 (we don't have that many elements) and unlimited should
# mean no truncation.
- foreach opts { "max_elements=1000" "max_elements=0" } {
+ foreach opts [list "max_$setting=1000" "max_$setting=$unlimited"] {
with_test_prefix $opts {
check_format_string "a_point_t" $opts
check_format_string "a_point_t_pointer" $opts
check_format_string "a_binary_string_array" $opts
check_format_string "a_big_string" $opts \
[get_cut_big_string 1000]
- check_format_string "an_array" $opts
- check_format_string "an_array_with_repetition" $opts
+ if { $setting == "elements"} {
+ check_format_string "an_array" $opts
+ check_format_string "an_array_with_repetition" $opts
+ }
check_format_string "a_symbol_pointer" $opts
if { $current_lang == "c++" } {
}
}
- with_temp_option "set print elements 4" "set print elements 200" {
+ with_temp_option "set print $setting 4" "set print $setting 200" {
check_format_string "a_string" "" \
"${default_pointer_regexp} \"hell\"..."
check_format_string "a_binary_string" "" \
"${default_pointer_regexp} \"hell\"..."
check_format_string "a_binary_string_array" "" \
"\"hell\"..."
- check_format_string "an_array_with_repetition" "" \
- "\\{1, 3 <repeats 12 times>...\\}"
+ if { $setting == "elements"} {
+ check_format_string "an_array_with_repetition" "" \
+ "\\{1, 3 <repeats 12 times>...\\}"
+ }
+ }
+}
+
+proc_with_prefix test_max_string {} {
+ foreach_with_prefix setting { "elements" "characters" } {
+ test_max_string_one $setting \
+ [string map {elements 0 characters 4294967295} $setting]
}
}
test_deref_refs
test_actual_objects
test_static_members
- test_max_elements
+ test_max_string
test_max_depth
test_repeat_threshold
test_format
"listsize"
"print elements"
"max-completions"
+ "print characters"
} {
clean_restart
set param_get_unlimited None
set param_set_minus_one ""
}
- "print elements" {
+ "print elements" -
+ "print characters" {
set param_get_zero None
set param_get_minus_one None
set param_get_none None
gdb_test "python print(gdb.parameter('$param'))" \
$param_get_unlimited "test value of 'unlimited'"
+
+ if {$param == "print characters"} {
+ gdb_test_no_output \
+ "python gdb.set_parameter('$param', 'elements')" \
+ "test set to 'elements'"
+
+ gdb_test "python print(gdb.parameter('$param'))" \
+ elements "test value of 'elements'"
+ }
}
clean_restart