]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-lazy-string.exp
522530cb128dd7d271fd111542130df73fe39565
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-lazy-string.exp
1 # Copyright (C) 2015-2023 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # This file is part of the GDB testsuite. It tests lazy string support
17 # not tested by py-prettyprinter.exp.
18
19 load_lib gdb-python.exp
20
21 require allow_python_tests
22
23 standard_testfile
24
25 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
26 return -1
27 }
28
29 if ![runto_main ] {
30 return -1
31 }
32
33 gdb_breakpoint [gdb_get_line_number "break here"]
34 gdb_continue_to_breakpoint "break here"
35
36 gdb_py_test_silent_cmd "python null = gdb.parse_and_eval(\"null\")" "get null value" 1
37
38 gdb_py_test_silent_cmd "python nullstr = null.lazy_string(length=0)" "create a null lazy string" 1
39 gdb_test "python print (nullstr.length)" "0" "null lazy string length"
40 gdb_test "python print (nullstr.address)" "0" "null lazy string address"
41 gdb_test "python print (nullstr.type)" "const char \\*" "null lazy string type"
42 gdb_test "python print(nullstr.value())" \
43 "gdb.MemoryError: Cannot create a value from NULL.*Error while executing Python code." \
44 "create value from NULL"
45 gdb_test "python print(null.lazy_string(length=3).value())" \
46 "gdb.MemoryError: Cannot create a lazy string with address 0x0, and a non-zero length.*Error while executing Python code." \
47 "null lazy string with non-zero length"
48 gdb_test "python print(null.lazy_string(length=-2))" \
49 "ValueError: Invalid length.*Error while executing Python code." \
50 "bad length"
51
52 foreach var_spec { { "ptr" "pointer" "const char \\*" -1 } \
53 { "array" "array" "const char \\[6\\]" 6 } \
54 { "typedef_ptr" "typedef pointer" "pointer" -1 } } {
55 set var [lindex $var_spec 0]
56 set value [lindex $var_spec 1]
57 set type [lindex $var_spec 2]
58 set length [lindex $var_spec 3]
59 with_test_prefix $var {
60 gdb_test "print $var" "\"$value\""
61 gdb_py_test_silent_cmd "python $var = gdb.history (0)" "get value from history" 1
62 gdb_py_test_silent_cmd "python l$var = $var.lazy_string()" "acquire lazy string" 1
63 gdb_test "python print ($var.type)" "$type" "string type name equality"
64 gdb_test "python print (l$var.type)" "$type" "lazy-string type name equality"
65 gdb_test "python print (l$var.length)" "$length" "lazy string length"
66 gdb_test "python print (l$var.value())" "\"$value\"" "lazy string value"
67 gdb_py_test_silent_cmd "python l2$var = $var.lazy_string(length=2)" "acquire lazy string, length 2" 1
68 gdb_test "python print (l2$var.length)" "2" "lazy string length 2"
69 gdb_test "python print (l2$var.value())" "\"[string range $value 0 1]\"" "lazy string length 2 value"
70 # This test will have to wait until gdb can handle it. There's no way,
71 # currently, to internally specify an array of length zero in the C
72 # language support. PR 20786
73 #gdb_test "python print ($var.lazy_string(length=0).value())" "\"\"" "empty lazy string value"
74 }
75 }