aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorPaul Pluzhnikov <ppluzhnikov@google.com>2023-05-08 01:03:42 +0000
committerPaul Pluzhnikov <ppluzhnikov@google.com>2023-05-13 18:10:05 +0000
commitd2b585f3cfc253678bf33b552a219e25eb29e686 (patch)
treed2dee89582caa642cbc98422ed25483e3acf64dd /gdb/testsuite
parent249d1bad51b568c74ea37e8b3e76c179eb53a733 (diff)
downloadbinutils-d2b585f3cfc253678bf33b552a219e25eb29e686.zip
binutils-d2b585f3cfc253678bf33b552a219e25eb29e686.tar.gz
binutils-d2b585f3cfc253678bf33b552a219e25eb29e686.tar.bz2
Fix bad interaction between element limit and repeated values (BZ#24331).
Currently print -elements=3 -- "AAAAAA" prints complete string, which is not what the user asked for. Fix two buggy tests exposed by the fix, and add a new test. Reviewed-by: Keith Seitz <keiths@redhat.com>
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/gdb.base/printcmds.exp15
-rw-r--r--gdb/testsuite/gdb.python/py-format-string.exp2
2 files changed, 16 insertions, 1 deletions
diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp
index db57769..f2be549 100644
--- a/gdb/testsuite/gdb.base/printcmds.exp
+++ b/gdb/testsuite/gdb.base/printcmds.exp
@@ -1027,6 +1027,9 @@ proc test_repeat_bytes {} {
set fmt(SR) "\"%s\", %s"
set fmt(SS) "\"%s%s\""
+ # We have up to 60 elements to print.
+ gdb_test_no_output "set print elements 100"
+
# Set the target-charset to ASCII, because the output varies from
# different charset.
with_target_charset "ASCII" {
@@ -1074,6 +1077,17 @@ proc test_repeat_bytes {} {
}
}
+# Test for BZ#24331
+proc test_repeat_bytes_limit {} {
+ gdb_test "print -elem 3 -- \"AAAAA\"" "= \"AAA\"..."
+ gdb_test "print -char 3 -elem 10 -- \"AAAAA\"" "= \"AAA\"..."
+ gdb_test "print -elem 3 -- \"ABBBB\"" "= \"ABB\"..."
+ gdb_test "print -char 3 -elem 10 -- \"ABBBB\"" "= \"ABB\"..."
+
+ gdb_test "print -elem 3 -repeats 2 -- \"AAABBB\"" "= 'A' <repeats 3 times>..."
+ gdb_test "print -elem 4 -repeats 2 -- \"AAABBB\"" "= 'A' <repeats 3 times>, 'B' <repeats 3 times>"
+}
+
# Test printf of convenience variables.
# These tests can be done with or without a running inferior.
# PREFIX ensures uniqueness of test names.
@@ -1199,3 +1213,4 @@ test_printf_with_strings
test_print_symbol
test_repeat_bytes
test_radices
+test_repeat_bytes_limit
diff --git a/gdb/testsuite/gdb.python/py-format-string.exp b/gdb/testsuite/gdb.python/py-format-string.exp
index 1d50f59..2a011eb 100644
--- a/gdb/testsuite/gdb.python/py-format-string.exp
+++ b/gdb/testsuite/gdb.python/py-format-string.exp
@@ -748,7 +748,7 @@ proc test_max_string_one { setting unlimited } {
# This will print four characters instead of three, see
# <https://sourceware.org/bugzilla/show_bug.cgi?id=24331>.
check_format_string "a_binary_string_array" $opts \
- "\"hell\"..."
+ "\"hel\"..."
check_format_string "a_big_string" $opts \
[get_cut_big_string 3]
if { $setting == "elements"} {