]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.guile/scm-lazy-string.exp
Automatic Copyright Year update after running gdb/copyright.py
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.guile / scm-lazy-string.exp
1 # Copyright (C) 2008-2022 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.
17 # It tests the mechanism exposing lazy strings to Guile.
18
19 load_lib gdb-guile.exp
20
21 standard_testfile
22
23 if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
24 return
25 }
26
27 # Skip all tests if Guile scripting is not enabled.
28 if { [skip_guile_tests] } { continue }
29
30 #gdb_install_guile_utils
31 #gdb_install_guile_module
32
33 # The following tests require execution.
34
35 if ![gdb_guile_runto_main] {
36 return
37 }
38
39 gdb_breakpoint [gdb_get_line_number "break here"]
40 gdb_continue_to_breakpoint "break here"
41
42 gdb_scm_test_silent_cmd "gu (define null (parse-and-eval \"null\"))" 1
43
44 gdb_scm_test_silent_cmd "gu (define nullstr (value->lazy-string null #:length 0))" "create a null lazy string" 1
45 gdb_test "gu (print (lazy-string-length nullstr))" "= 0" "null lazy string length"
46 gdb_test "gu (print (lazy-string-address nullstr))" "= 0" "null lazy string address"
47 gdb_test "gu (print (lazy-string-type nullstr))" "const char \\*" "null lazy string type"
48 gdb_test "gu (print (lazy-string->value nullstr))" \
49 "Out of range: cannot create a value from NULL.*Error while executing Scheme code." \
50 "create value from NULL"
51 gdb_test "gu (print (lazy-string->value (value->lazy-string null #:length 3)))" \
52 "Out of range: cannot create a lazy string with address 0x0, and a non-zero length.*Error while executing Scheme code." \
53 "null lazy string with non-zero length"
54 gdb_test "gu (print (value->lazy-string null #:length -2))" \
55 "Out of range: invalid length.*Error while executing Scheme code." \
56 "bad length"
57
58 foreach var_spec { { "ptr" "pointer" "const char \\*" -1 } \
59 { "array" "array" "const char \\[6\\]" 6 } \
60 { "typedef_ptr" "typedef pointer" "pointer" -1 } } {
61 set var [lindex $var_spec 0]
62 set value [lindex $var_spec 1]
63 set type [lindex $var_spec 2]
64 set length [lindex $var_spec 3]
65 with_test_prefix $var {
66 gdb_test "print $var" "\"$value\""
67 gdb_scm_test_silent_cmd "gu (define $var (history-ref 0))" "get value from history" 1
68 gdb_scm_test_silent_cmd "gu (define l$var (value->lazy-string $var))" "acquire lazy string" 1
69 gdb_test "gu (print (value-type $var))" "$type" "string type name equality"
70 gdb_test "gu (print (lazy-string-type l$var))" "$type" "lazy-string type name equality"
71 gdb_test "gu (print (lazy-string-length l$var))" "$length" "lazy string length"
72 gdb_test "gu (print (lazy-string->value l$var))" "\"$value\"" "lazy string value"
73 gdb_scm_test_silent_cmd "gu (define l2$var (value->lazy-string $var #:length 2))" "acquire lazy string, length 2" 1
74 gdb_test "gu (print (lazy-string-length l2$var))" "2" "lazy string length 2"
75 gdb_test "gu (print (lazy-string->value l2$var))" "\"[string range $value 0 1]\"" "lazy string length 2 value"
76 # This test will have to wait until gdb can handle it. There's no way,
77 # currently, to internally specify an array of length zero in the C
78 # language support. PR 20786
79 #gdb_test "gu (print (lazy-string->value (value->lazy-string $var #:length 0)))" "\"\"" "empty lazy string value"
80 }
81 }