1#   Copyright (C) 1997, 1998, 2007 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# Please email any bugs, comments, and/or additions to this file to:
17# bug-gdb@prep.ai.mit.edu
18
19if $tracelevel then {
20	strace $tracelevel
21}
22
23set prms_id 0
24set bug_id 0
25
26set testfile langs
27set binfile ${objdir}/${subdir}/${testfile}
28
29if [is_remote host] {
30    remote_download host ${srcdir}/${subdir}/langs1.f
31    remote_download host ${srcdir}/${subdir}/langs2.cxx
32}
33
34
35if  { [gdb_compile "${srcdir}/${subdir}/langs0.c" "${binfile}0.o" object {debug}] != "" } {
36     untested langs.exp
37     return -1
38}
39
40if  { [gdb_compile "${srcdir}/${subdir}/langs1.c" "${binfile}1.o" object {debug}] != "" } {
41     untested langs.exp
42     return -1
43}
44
45if  { [gdb_compile "${srcdir}/${subdir}/langs2.c" "${binfile}2.o" object {debug}] != "" } {
46     untested langs.exp
47     return -1
48}
49
50if  { [gdb_compile "${binfile}0.o ${binfile}1.o ${binfile}2.o" ${binfile} executable {debug}] != "" } {
51     untested langs.exp
52     return -1
53}
54
55set oldtimeout $timeout
56set timeout 10
57
58
59
60# Create and source the file that provides information about the compiler
61# used to compile the test case.
62if [get_compiler_info ${binfile}] {
63    return -1;
64}
65
66gdb_exit
67gdb_start
68gdb_reinitialize_dir $srcdir/$subdir
69gdb_load $binfile
70
71gdb_test_multiple "b langs0" "break on nonexistent function in langs.exp" {
72	-re "Function \"langs0\" not defined\..*Make breakpoint pending on future shared library load.*y or .n.. $" {
73
74		gdb_test "n" "" "break on nonexistent function in langs.exp"
75	}
76	-re "Breakpoint .* (deferred).*$gdb_prompt $" {
77		pass "break on nonexistent function in langs.exp"
78	}
79}
80
81if {$hp_aCC_compiler} {
82    set isfixed 1
83    set lang c\\+\\+
84    set ext cxx
85    set foo_func foo__Fi__Fi
86    set do_func do::langs0
87} else {
88    if {$hp_cc_compiler} {
89        set isfixed 1
90        set lang c
91        set ext c
92    } else {
93        set isfixed 0
94    }
95    set foo_func foo__Fi
96    set do_func langs0__2do
97}
98
99if [runto csub] then {
100
101    if { !$isfixed } { set lang c }
102    gdb_test "show language" "currently $lang\".*" \
103	"show language at csub in langs.exp"
104    # On some machines, foo doesn't get demangled because the N_SOL for
105    # langs2.cxx is seen only after the function stab for foo.  So
106    # the following regexps are kludged to accept foo__Fi as well as foo,
107    # even though only the latter is correct.  I haven't tried to xfail it
108    # because it depends on details of the compiler.
109
110    # Take out xfail. This test has been passing for some time now.
111    #if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
112    gdb_test "bt" "#0.*csub.*#1.*(foo|$foo_func) \\(.*#2.*cppsub_ .*#3.*fsub.*#4.*$do_func \\(.*#5  \[0-9a-fx\]* in main.*" "backtrace in langs.exp"
113
114    if { !$isfixed } { set lang c\\+\\+; set ext cxx }
115    if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" }
116    gdb_test "up" ".* in (foo|$foo_func).* at langs2\\.$ext.*return csub \\(.*" \
117	"up to foo in langs.exp"
118    gdb_test "show language" "currently $lang.*" \
119	"show language at foo in langs.exp"
120
121    if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" }
122    gdb_test "up" ".* in cppsub_ .* at langs2\\.$ext.*return foo \\(.*" \
123	"up to cppsub_ in langs.exp"
124    gdb_test "show language" "currently $lang.*" \
125	"show language at cppsub_ in langs.exp"
126
127    if { !$isfixed } { set lang fortran }
128    if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" }
129    gdb_test "up" ".* in fsub.* at langs1\\.f.*" \
130	"up to fsub in langs.exp"
131    gdb_test "show language" "currently $lang.*" \
132	"show language at fsub in langs.exp"
133
134    # Take out xfail. This test has been passing for sometime now.
135    #if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
136    if { !$isfixed } { set lang c }
137    gdb_test "up" ".* in $do_func .* at .*langs0\\.c.*return fsub.*" \
138	"up to langs0__2do in langs.exp"
139    gdb_test "show language" "currently $lang\".*" \
140	"show language at langs0__2do in langs.exp"
141
142    gdb_test "up" ".* in main .* at .*langs0\\.c.*if \\(langs0__2do \\(.*" \
143	"up to main in langs.exp"
144    gdb_test "show language" "currently $lang\".*" \
145	"show language at main in langs.exp"
146
147    if [target_info exists gdb,noresults] { return }
148
149    if [target_info exists use_gdb_stub] {
150	gdb_breakpoint "exit"
151	gdb_test "cont" "Breakpoint .*exit.*" "continue to exit in langs.exp"
152    } else {
153	gdb_test "cont" "Program exited normally\\..*" \
154		"continue to exit in langs.exp"
155    }
156}
157
158gdb_exit
159gdb_start
160gdb_reinitialize_dir $srcdir/$subdir
161gdb_load $binfile
162
163# Try exercising the "minimal" language a bit...
164
165if [runto csub] then {
166    gdb_test "set lang minimal" \
167             "Warning: the current language does not match this frame." \
168             "set lang to minimal"
169
170    gdb_test "print x" " = 5000" "print parameter value"
171}
172
173set timeout $oldtimeout
174return 0
175