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