1# Copyright 1997, 1999, 2004, 2005, 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
19# Test that things still (sort of) work when compiled without -g.
20
21if $tracelevel then {
22	strace $tracelevel
23}
24
25set prms_id 0
26set bug_id 0
27
28set testfile nodebug
29set srcfile $srcdir/$subdir/$testfile.c
30set binfile $objdir/$subdir/$testfile
31
32if [get_compiler_info ${binfile}] {
33    return -1;
34}
35
36if [test_compiler_info "xlc-*"] {
37    # By default, IBM'x xlc compiler doesn't add static variables into the symtab.
38    # Use "-qstatsym" to do so.
39    set exec_opts additional_flags=-qstatsym
40} else {
41    set exec_opts ""
42}
43
44if  { [gdb_compile $srcfile $binfile executable $exec_opts] != "" } {
45    untested "Couldn't compile $srcfile."
46    return -1
47}
48
49# Start with a fresh gdb.
50
51gdb_exit
52gdb_start
53gdb_reinitialize_dir $srcdir/$subdir
54gdb_load $binfile
55
56if [runto inner] then {
57
58    # Expect to find global/local symbols in each of text/data/bss.
59
60    # The exact format for some of this output is not necessarily
61    # ideal, particularly interpreting "p top" requires a fair bit of
62    # savvy about gdb's workings and the meaning of the "{}"
63    # construct.  So the details maybe could be tweaked.  But the
64    # basic purpose should be maintained, which is (a) users should be
65    # able to interact with these variables with some care (they have
66    # to know how to interpret them according to their real type,
67    # since gdb doesn't know the type), but (b) users should be able
68    # to detect that gdb does not know the type, rather than just
69    # being told they are ints or functions returning int like old
70    # versions of gdb used to do.
71
72    # On alpha (and other ecoff systems) the native compilers put
73    # out debugging info for non-aggregate return values of functions
74    # even without -g, which should be accepted.
75    # Irix5, even though it is ELF, counts as "ecoff" because it
76    # encapsulates ecoff debugging info in a .mdebug section.
77    # Irix6 gcc emits no debug info at all for static functions and
78    # variables, so all tests involving statics fail.
79
80    if {![test_compiler_info "gcc-*"]} then { setup_xfail "mips-sgi-irix5*" "mips-sgi-irix6*" }
81    gdb_test "p top" \
82	"\{(<(text variable|function), no debug info>|short \\(int\\)|short \\(\\))\} \[0-9a-fx]* <top(\\(int\\)|)>"
83    if {![test_compiler_info "gcc-*"]} then { setup_xfail "mips-sgi-irix5*" "mips-sgi-irix6*" }
84    gdb_test "whatis top" \
85	"(<(text variable|function), no debug info>|short \\(int\\)|short \\(\\))"
86    if {![test_compiler_info "gcc-*"]} then { setup_xfail "mips-sgi-irix6*" }
87    gdb_test "ptype top" "(short|int) \\((|void|int|<non-float parameter>|<non-float parameter>, <non-float parameter>)\\)"
88
89    if {![test_compiler_info "gcc-*"]} then { setup_xfail "mips-sgi-irix5*" }
90    setup_xfail "mips-sgi-irix6*"
91    gdb_test "p middle" \
92	"\{(<(text variable|function), no debug info>|short \\(int\\)|short \\(\\))\} \[0-9a-fx]* <middle(\\(int\\)|)>"
93    if {![test_compiler_info "gcc-*"]} then { setup_xfail "mips-sgi-irix5*" }
94    setup_xfail "mips-sgi-irix6*"
95    gdb_test "whatis middle" \
96	"(<(text variable|function), no debug info>|short \\(int\\)|short \\(\\))"
97    setup_xfail "mips-sgi-irix6*"
98    gdb_test "ptype middle" "(short|int) \\((|void|int|<non-float parameter>|<non-float parameter>, <non-float parameter>)\\)"
99
100    gdb_test "p dataglobal" "= 3"
101    gdb_test "whatis dataglobal" \
102	"<(data variable|variable), no debug info>|int"
103    gdb_test "ptype dataglobal" "<(data variable|variable), no debug info>|int"
104
105    # The only symbol xcoff puts out for statics is for the TOC entry.
106    # Possible, but hairy, for gdb to deal.  Right now it doesn't, it
107    # doesn't know the variables exist at all.
108    setup_xfail "rs6000*-*-aix*"
109    setup_xfail "powerpc*-*-aix*"
110    if [test_compiler_info "gcc-*"] {
111        setup_xfail "mips-sgi-irix6*"
112    } else {
113        setup_xfail "hppa*-*-hpux*"
114    }
115
116    gdb_test "p datalocal" "= 4"
117
118    setup_xfail "rs6000*-*-aix*"
119    setup_xfail "powerpc*-*-aix*"
120    if [test_compiler_info "gcc-*"] {
121        setup_xfail "mips-sgi-irix6*"
122    } else {
123        setup_xfail "hppa*-*-hpux*"
124    }
125
126    gdb_test "whatis datalocal" "<(data variable|variable), no debug info>"
127
128    setup_xfail "rs6000*-*-aix*"
129    setup_xfail "powerpc*-*-aix*"
130    if [test_compiler_info "gcc-*"] {
131        setup_xfail "mips-sgi-irix6*"
132    } else {
133        setup_xfail "hppa*-*-hpux*"
134    }
135
136    gdb_test "ptype datalocal" "<(data variable|variable), no debug info>"
137    gdb_test "p bssglobal" "= 0"
138    gdb_test "whatis bssglobal" "<(data variable|variable), no debug info>|int"
139    gdb_test "ptype bssglobal" "<(data variable|variable), no debug info>|int"
140
141    setup_xfail "rs6000*-*-aix*"
142    setup_xfail "powerpc*-*-aix*"
143    if [test_compiler_info "gcc-*"] {
144        setup_xfail "mips-sgi-irix6*"
145    } else {
146        setup_xfail "hppa*-*-hpux*"
147    }
148
149    gdb_test "p bsslocal" "= 0"
150
151    setup_xfail "rs6000*-*-aix*"
152    setup_xfail "powerpc*-*-aix*"
153    if [test_compiler_info "gcc-*"] {
154        setup_xfail "mips-sgi-irix6*"
155    } else {
156        setup_xfail "hppa*-*-hpux*"
157    }
158
159    gdb_test "whatis bsslocal" "<(data variable|variable), no debug info>"
160
161    setup_xfail "rs6000*-*-aix*"
162    setup_xfail "powerpc*-*-aix*"
163    if [test_compiler_info "gcc-*"] {
164        setup_xfail "mips-sgi-irix6*"
165    } else {
166        setup_xfail "hppa*-*-hpux*"
167    }
168    gdb_test "ptype bsslocal" "<(data variable|variable), no debug info>"
169
170    if [test_compiler_info "gcc-*"] {
171        setup_xfail "mips-sgi-irix6*"
172    }
173
174    gdb_test "backtrace 10" "#0.*inner.*#1.*middle.*#2.*top.*#3.*main.*" \
175	"backtrace from inner in nodebug.exp"
176    # Or if that doesn't work, at least hope for the external symbols
177    # Commented out because if we aren't going to xfail the above test
178    # ever, why bother with a weaker test?
179    #gdb_test "backtrace 10" "#0.*inner.*#1.*#2.*top.*#3.*main.*" \
180	#    "backtrace from inner in nodebug.exp for externals"
181
182    # This test is not as obscure as it might look.  `p getenv ("TERM")'
183    # is a real-world example, at least on many systems.
184    if { ! [test_compiler_info "gcc-*"]} {
185        setup_xfail "mips-sgi-irix6*"
186    }
187    if [target_info exists gdb,cannot_call_functions] {
188	setup_xfail "*-*-*" 2416
189	fail "p/c array_index(\"abcdef\",2)"
190    } else {
191	#
192	# On HP-UX, a support function (__d_plt_call) necessary to
193	# implement an inferior call is normally only available when
194	# the inferior was compiled with -g.  Thus, we expect this
195	# testpoint to fail on HP-UX.
196	if { [istarget "hppa*-hpux*"] } {
197	    send_gdb "p/c array_index(\"abcdef\",2)\n"
198	    gdb_expect {
199		-re ".*Suggest linking executable with -g.*$gdb_prompt $" { pass "p/c array_index(\"abcdef\",2)" }
200		-re ".*Cannot find __wdb_call_dummy in.*end.o.*" { pass "p/c array_index(\"abcdef\",2)" }
201		-re ".*99 'c'.*" { pass "p/c array_index(\"abcdef\",2)" }
202		timeout { fail "(timeout) p/c array_index" }
203	    }
204	} else {
205	    # We need to up this because this can be really slow on some boards.
206	    # (malloc() is called as part of the test).
207	    set timeout 60;
208	    gdb_test {p/c array_index("abcdef",2)} " = 99 'c'"
209	}
210    }
211
212    # Now, try that we can give names of file-local symbols which happen
213    # to be unique, and have it still work
214    if [test_compiler_info "gcc-*"] {
215        setup_xfail "mips-sgi-irix6*"
216    }
217    if [runto middle] then {
218	gdb_test "backtrace 10" "#0.*middle.*#1.*top.*#2.*main.*" \
219	    "backtrace from middle in nodebug.exp"
220    }
221}
222