1*1424dfb3Schristos# This testcase is part of GDB, the GNU debugger.
2*1424dfb3Schristos# Copyright 2018-2020 Free Software Foundation, Inc.
3*1424dfb3Schristos
4*1424dfb3Schristos# This program is free software; you can redistribute it and/or modify
5*1424dfb3Schristos# it under the terms of the GNU General Public License as published by
6*1424dfb3Schristos# the Free Software Foundation; either version 3 of the License, or
7*1424dfb3Schristos# (at your option) any later version.
8*1424dfb3Schristos#
9*1424dfb3Schristos# This program is distributed in the hope that it will be useful,
10*1424dfb3Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
11*1424dfb3Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*1424dfb3Schristos# GNU General Public License for more details.
13*1424dfb3Schristos#
14*1424dfb3Schristos# You should have received a copy of the GNU General Public License
15*1424dfb3Schristos# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16*1424dfb3Schristos
17*1424dfb3Schristos# Test function calls on C++ functions that have no debug information.
18*1424dfb3Schristos# See gdb/22736.  Put the called function in a different object to ensure
19*1424dfb3Schristos# the rest of the test can be complied with debug information.  Whilst we
20*1424dfb3Schristos# are at it, also test functions with debug information and C functions too.
21*1424dfb3Schristos
22*1424dfb3Schristosif [target_info exists gdb,cannot_call_functions] {
23*1424dfb3Schristos    unsupported "this target can not call functions"
24*1424dfb3Schristos    continue
25*1424dfb3Schristos}
26*1424dfb3Schristos
27*1424dfb3Schristosset main_basename infcall-nodebug-main
28*1424dfb3Schristosset lib_basename infcall-nodebug-lib
29*1424dfb3Schristosstandard_testfile ${main_basename}.c ${lib_basename}.c
30*1424dfb3Schristos
31*1424dfb3Schristosset mainsrc "${srcdir}/${subdir}/${srcfile}"
32*1424dfb3Schristosset libsrc "${srcdir}/${subdir}/${srcfile2}"
33*1424dfb3Schristos
34*1424dfb3Schristos# Build both source files to objects using language LANG. Use SYMBOLS to build
35*1424dfb3Schristos# with either debug symbols or without - but always build the main file with
36*1424dfb3Schristos# debug.  Then make function calls across the files.
37*1424dfb3Schristos
38*1424dfb3Schristosproc build_and_run_test { lang symbols } {
39*1424dfb3Schristos
40*1424dfb3Schristos    global main_basename lib_basename mainsrc libsrc binfile testfile
41*1424dfb3Schristos    global gdb_prompt
42*1424dfb3Schristos
43*1424dfb3Schristos    if { $symbols == "debug" } {
44*1424dfb3Schristos	set debug_flags "debug"
45*1424dfb3Schristos    } else {
46*1424dfb3Schristos	set debug_flags ""
47*1424dfb3Schristos    }
48*1424dfb3Schristos
49*1424dfb3Schristos    # Compile both files to objects, then link together.
50*1424dfb3Schristos
51*1424dfb3Schristos    set main_flags "$lang debug"
52*1424dfb3Schristos    set lib_flags "$lang $debug_flags"
53*1424dfb3Schristos    set main_o [standard_output_file ${main_basename}.o]
54*1424dfb3Schristos    set lib_o [standard_output_file ${lib_basename}.o]
55*1424dfb3Schristos    set binfile [standard_output_file ${testfile}]
56*1424dfb3Schristos
57*1424dfb3Schristos    if { [gdb_compile $mainsrc $main_o object ${main_flags}] != "" } {
58*1424dfb3Schristos	untested "failed to compile main file to object"
59*1424dfb3Schristos	return -1
60*1424dfb3Schristos    }
61*1424dfb3Schristos
62*1424dfb3Schristos    if { [gdb_compile $libsrc $lib_o object ${lib_flags}] != "" } {
63*1424dfb3Schristos	untested "failed to compile secondary file to object"
64*1424dfb3Schristos	return -1
65*1424dfb3Schristos    }
66*1424dfb3Schristos
67*1424dfb3Schristos    if { [gdb_compile "$main_o $lib_o" ${binfile} executable ""] != "" } {
68*1424dfb3Schristos	untested "failed to compile"
69*1424dfb3Schristos	return -1
70*1424dfb3Schristos    }
71*1424dfb3Schristos
72*1424dfb3Schristos    # Startup and run to main.
73*1424dfb3Schristos
74*1424dfb3Schristos    clean_restart $binfile
75*1424dfb3Schristos
76*1424dfb3Schristos    if ![runto_main] then {
77*1424dfb3Schristos	fail "can't run to main"
78*1424dfb3Schristos	return
79*1424dfb3Schristos    }
80*1424dfb3Schristos
81*1424dfb3Schristos    # Function call with cast.
82*1424dfb3Schristos
83*1424dfb3Schristos    gdb_test "p (int)foo()" " = 1"
84*1424dfb3Schristos
85*1424dfb3Schristos    # Function call without cast.  Will error if there are no debug symbols.
86*1424dfb3Schristos
87*1424dfb3Schristos    set test "p foo()"
88*1424dfb3Schristos    gdb_test_multiple $test $test {
89*1424dfb3Schristos	-re " = 1\r\n$gdb_prompt " {
90*1424dfb3Schristos	    gdb_assert [ string equal $symbols "debug" ]
91*1424dfb3Schristos	    pass $test
92*1424dfb3Schristos	}
93*1424dfb3Schristos	-re "has unknown return type; cast the call to its declared return type\r\n$gdb_prompt " {
94*1424dfb3Schristos	    gdb_assert ![ string equal $symbols "debug" ]
95*1424dfb3Schristos	    pass $test
96*1424dfb3Schristos	}
97*1424dfb3Schristos    }
98*1424dfb3Schristos
99*1424dfb3Schristos}
100*1424dfb3Schristos
101*1424dfb3Schristosbuild_and_run_test $lang $debug
102