summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/max-value-size.exp
blob: 2c2dbe6fd1cd5b5eb1b4aa1703341b55833d1bba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Copyright (C) 2016-2019 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/>.

standard_testfile

if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
    return -1
}

if ![runto_main] then {
    fail "can't run to main"
    return 0
}

# Run "show max-value-size" and return the interesting bit of the
# result.  This is either the maximum size in bytes, or the string
# "unlimited".
proc get_max_value_size {} {
    global gdb_prompt
    global decimal

    gdb_test_multiple "show max-value-size" "" {
	-re "Maximum value size is ($decimal) bytes.*$gdb_prompt $" {
	    return $expect_out(1,string)
	}
	-re "Maximum value size is unlimited.*$gdb_prompt $" {
	    return "unlimited"
	}
    }
}

# Assuming that MAX_VALUE_SIZE is the current value for
# max-value-size, print the test values.  Use TEST_PREFIX to make the
# test names unique.
proc do_value_printing { max_value_size test_prefix } {
    with_test_prefix ${test_prefix} {
	gdb_test "p/d one" " = 0"
	if { $max_value_size != "unlimited" && $max_value_size < 100 } then {
	    gdb_test "p/d one_hundred" \
		"value requires 100 bytes, which is more than max-value-size"
	} else {
	    gdb_test "p/d one_hundred" " = \\{0 <repeats 100 times>\\}"
	}
	gdb_test "p/d one_hundred \[99\]" " = 0"
    }
}

# Install SET_VALUE as the value for max-value-size, then print the
# test values.
proc set_and_check_max_value_size { set_value } {
    if { $set_value == "unlimited" } then {
	set check_pattern "unlimited"
    } else {
	set check_pattern "${set_value} bytes"
    }

    gdb_test_no_output "set max-value-size ${set_value}"
    gdb_test "show max-value-size" \
	"Maximum value size is ${check_pattern}." \
	"check that the value shows as ${check_pattern}"

    do_value_printing ${set_value} "max-value-size is '${set_value}'"
}

# Check the default value is sufficient.
do_value_printing [get_max_value_size] "using initial max-value-size"

# Check some values for max-value-size that should prevent some
# allocations.
set_and_check_max_value_size 25
set_and_check_max_value_size 99

# Check values for max-value-size that should allow all allocations.
set_and_check_max_value_size 100
set_and_check_max_value_size 200
set_and_check_max_value_size "unlimited"

# Check that we can't set the maximum size stupidly low.
gdb_test "set max-value-size 1" \
    "max-value-size set too low, increasing to \[0-9\]+ bytes"
gdb_test "set max-value-size 0" \
    "max-value-size set too low, increasing to \[0-9\]+ bytes"
gdb_test "set max-value-size -5" \
    "only -1 is allowed to set as unlimited"