1# Copyright 1998-2020 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 was written by Elena Zannoni (ezannoni@cygnus.com)
17
18# This test deals with calling functions which have strings as parameters.
19# it plays around with constant strings.
20# the corresponding source file is call-strs.c
21#
22
23#debug strarg
24
25
26standard_testfile
27
28# Some targets can't call functions, so don't even bother with this
29# test.
30if [target_info exists gdb,cannot_call_functions] {
31    unsupported "this target can not call functions"
32    continue
33}
34
35
36if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
37    return -1
38}
39
40gdb_test_no_output "set print sevenbit-strings"
41gdb_test_no_output "set print address off"
42gdb_test_no_output "set print symbol off"
43gdb_test_no_output "set width 0"
44
45if ![runto_main] then {
46    perror "couldn't run to breakpoint"
47    continue
48}
49
50set prev_timeout $timeout
51set timeout 120
52
53gdb_test "next 2" \
54    "strcpy\\(buf, \"test string\"\\);" \
55    "step after assignment to s"
56
57#next
58gdb_test "next" \
59    "str_func\\(\"abcd\", \"efgh\", \"ijkl\", \"mnop\", \"qrst\", \"uvwx\", \"yz12\"\\);" \
60    "next over strcpy"
61
62#print buf
63gdb_test "print buf" \
64    "\"test string\",.*repeats 88 times.*"
65
66#print s
67gdb_test "print s" \
68    " = \"test string\".*"
69
70#print str_func1(s)
71if ![gdb_skip_stdio_test "print str_func1(s)"] {
72    gdb_test_stdio "print str_func1(s)" \
73	"first string arg is: test string" \
74	"\"test string\".*"
75}
76
77#print str_func1("test string")
78if ![gdb_skip_stdio_test "print str_func1(teststring)"] {
79    gdb_test_stdio "print str_func1(\"test string\")" \
80	"first string arg is: test string" \
81	"\"test string\".*"
82}
83
84#call str_func1(s)
85if ![gdb_skip_stdio_test "call str_func1(s)"] {
86    gdb_test_stdio "call str_func1(s)" \
87	"first string arg is: test string" \
88	"\"test string\".*"
89}
90
91#call str_func1("test string")
92if ![gdb_skip_stdio_test "call str_func1 (...)"] {
93    gdb_test_stdio "call str_func1(\"test string\")" \
94	"first string arg is: test string" \
95	"\"test string\".*"
96}
97
98#print str_func1(buf)
99if ![gdb_skip_stdio_test "print str_func1(buf)"] {
100    gdb_test_stdio "print str_func1(buf)" \
101	"first string arg is: test string" \
102	"\"test string\".*"
103}
104
105#call str_func1(buf)
106if ![gdb_skip_stdio_test "call str_func1(buf)"] {
107    gdb_test_stdio "call str_func1(buf)" \
108	"first string arg is: test string" \
109	"\"test string\".*"
110}
111
112#print str_func("a","b","c","d","e","f","g")
113if ![gdb_skip_stdio_test "print str_func(a,b,c,d,e,f,g)"] {
114    gdb_test_stdio "print str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" \
115	"first string arg is: a\[ \t\r\n\]+second string arg is: b\[ \t\r\n\]+third string arg is: c\[ \t\r\n\]+fourth string arg is: d\[ \t\r\n\]+fifth string arg is: e\[ \t\r\n\]+sixth string arg is: f\[ \t\r\n\]+seventh string arg is: g\[ \t\r\n\]+" \
116	"= \"abcdefg\".*"
117}
118
119#call str_func("a","b","c","d","e","f","g")
120if ![gdb_skip_stdio_test "call str_func(a,b,c,d,e,f,g)"] {
121    gdb_test_stdio "call str_func(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\")" \
122	"first string arg is: a\[ \t\r\n\]+second string arg is: b\[ \t\r\n\]+third string arg is: c\[ \t\r\n\]+fourth string arg is: d\[ \t\r\n\]+fifth string arg is: e\[ \t\r\n\]+sixth string arg is: f\[ \t\r\n\]+seventh string arg is: g\[ \t\r\n\]+" \
123	"= \"abcdefg\".*"
124}
125
126#print str_func(s,s,s,s,s,s,s)
127if ![gdb_skip_stdio_test "print str_func(s,s,s,s,s,s,s,s)"] {
128    gdb_test_stdio "print str_func(s,s,s,s,s,s,s)" \
129	"first string arg is: test string\[ \t\r\n\]+second string arg is: test string\[ \t\r\n\]+third string arg is: test string\[ \t\r\n\]+fourth string arg is: test string\[ \t\r\n\]+fifth string arg is: test string\[ \t\r\n\]+sixth string arg is: test string\[ \t\r\n\]+seventh string arg is: test string\[ \t\r\n\]+" \
130    "\"test stringtest stringtest stringtest stringtest stringtest stringtest string\".*"
131}
132
133#call str_func(s,s,s,s,s,s,s)
134if ![gdb_skip_stdio_test "call str_func(s,s,s,s,s,s,s,s)"] {
135    gdb_test_stdio "call str_func(s,s,s,s,s,s,s)" \
136	"first string arg is: test string\[ \t\r\n\]+second string arg is: test string\[ \t\r\n\]+third string arg is: test string\[ \t\r\n\]+fourth string arg is: test string\[ \t\r\n\]+fifth string arg is: test string\[ \t\r\n\]+sixth string arg is: test string\[ \t\r\n\]+seventh string arg is: test string\[ \t\r\n\]+" \
137	"\"test stringtest stringtest stringtest stringtest stringtest stringtest string\".*"
138}
139
140gdb_exit
141
142set timeout $prev_timeout
143
144