1 # Copyright
(C
) 2015-2022 Free Software Foundation
, Inc.
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.
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.
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
/>.
16 # This file is part of the GDB testsuite. It tests lazy string support
17 # not tested by py
-prettyprinter.exp.
19 load_lib gdb
-python.exp
23 if {[prepare_for_testing
"failed to prepare" $testfile $srcfile {debug c++}]} {
27 # Skip all tests
if Python scripting is not enabled.
28 if { [skip_python_tests
] } { continue }
34 gdb_breakpoint
[gdb_get_line_number
"break here"]
35 gdb_continue_to_breakpoint
"break here"
37 gdb_py_test_silent_cmd
"python null = gdb.parse_and_eval(\"null\")" "get null value" 1
39 gdb_py_test_silent_cmd
"python nullstr = null.lazy_string(length=0)" "create a null lazy string" 1
40 gdb_test
"python print (nullstr.length)" "0" "null lazy string length"
41 gdb_test
"python print (nullstr.address)" "0" "null lazy string address"
42 gdb_test
"python print (nullstr.type)" "const char \\*" "null lazy string type"
43 gdb_test
"python print(nullstr.value())" \
44 "gdb.MemoryError: Cannot create a value from NULL.*Error while executing Python code." \
45 "create value from NULL"
46 gdb_test
"python print(null.lazy_string(length=3).value())" \
47 "gdb.MemoryError: Cannot create a lazy string with address 0x0, and a non-zero length.*Error while executing Python code." \
48 "null lazy string with non-zero length"
49 gdb_test
"python print(null.lazy_string(length=-2))" \
50 "ValueError: Invalid length.*Error while executing Python code." \
53 foreach var_spec
{ { "ptr" "pointer" "const char \\*" -1 } \
54 { "array" "array" "const char \\[6\\]" 6 } \
55 { "typedef_ptr" "typedef pointer" "pointer" -1 } } {
56 set var
[lindex $var_spec
0]
57 set value
[lindex $var_spec
1]
58 set type
[lindex $var_spec
2]
59 set length
[lindex $var_spec
3]
60 with_test_prefix $var
{
61 gdb_test
"print $var" "\"$value\""
62 gdb_py_test_silent_cmd
"python $var = gdb.history (0)" "get value from history" 1
63 gdb_py_test_silent_cmd
"python l$var = $var.lazy_string()" "acquire lazy string" 1
64 gdb_test
"python print ($var.type)" "$type" "string type name equality"
65 gdb_test
"python print (l$var.type)" "$type" "lazy-string type name equality"
66 gdb_test
"python print (l$var.length)" "$length" "lazy string length"
67 gdb_test
"python print (l$var.value())" "\"$value\"" "lazy string value"
68 gdb_py_test_silent_cmd
"python l2$var = $var.lazy_string(length=2)" "acquire lazy string, length 2" 1
69 gdb_test
"python print (l2$var.length)" "2" "lazy string length 2"
70 gdb_test
"python print (l2$var.value())" "\"[string range $value 0 1]\"" "lazy string length 2 value"
71 # This test will have to wait until gdb can handle it. There
's no way,
72 # currently, to internally specify an array of length zero in the C
73 # language support. PR 20786
74 #gdb_test "python print ($var.lazy_string(length=0).value())" "\"\"" "empty lazy string value"