1 # This testcase is part of GDB, the GNU debugger.
2 # Copyright 2018-2019 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Test function calls on C++ functions that have no debug information.
18 # See gdb/22736. Put the called function in a different object to ensure
19 # the rest of the test can be complied with debug information. Whilst we
20 # are at it, also test functions with debug information and C functions too.
22 if [target_info exists gdb,cannot_call_functions] {
23 unsupported "this target can not call functions"
27 # Only test C++ if we are able. Always use C.
28 if { [skip_cplus_tests] || [get_compiler_info "c++"] } {
34 set main_basename infcall-nodebug-main
35 set lib_basename infcall-nodebug-lib
36 standard_testfile ${main_basename}.c ${lib_basename}.c
38 set mainsrc "${srcdir}/${subdir}/${srcfile}"
39 set libsrc "${srcdir}/${subdir}/${srcfile2}"
41 # Build both source files to objects using language LANG. Use SYMBOLS to build
42 # with either debug symbols or without - but always build the main file with
43 # debug. Then make function calls across the files.
45 proc build_and_run_test { lang symbols } {
47 global main_basename lib_basename mainsrc libsrc binfile testfile
50 if { $symbols == "debug" } {
51 set debug_flags "debug"
58 set dir "$lang-$symbols"
59 remote_exec build "rm -rf [standard_output_file ${dir}]"
60 remote_exec build "mkdir -p [standard_output_file ${dir}]"
62 # Compile both files to objects, then link together.
64 set main_flags "$lang debug"
65 set lib_flags "$lang $debug_flags"
66 set main_o [standard_output_file ${dir}/${main_basename}.o]
67 set lib_o [standard_output_file ${dir}/${lib_basename}.o]
68 set binfile [standard_output_file ${dir}/${testfile}]
70 if { [gdb_compile $mainsrc $main_o object ${main_flags}] != "" } {
71 untested "failed to compile main file to object"
75 if { [gdb_compile $libsrc $lib_o object ${lib_flags}] != "" } {
76 untested "failed to compile secondary file to object"
80 if { [gdb_compile "$main_o $lib_o" ${binfile} executable ""] != "" } {
81 untested "failed to compile"
85 # Startup and run to main.
87 clean_restart $binfile
89 if ![runto_main] then {
90 fail "can't run to main"
94 # Function call with cast.
96 gdb_test "p (int)foo()" " = 1"
98 # Function call without cast. Will error if there are no debug symbols.
101 gdb_test_multiple $test $test {
102 -re " = 1\r\n$gdb_prompt " {
103 gdb_assert [ string equal $symbols "debug" ]
106 -re "has unknown return type; cast the call to its declared return type\r\n$gdb_prompt " {
107 gdb_assert ![ string equal $symbols "debug" ]
114 foreach_with_prefix l $lang {
115 foreach_with_prefix s {debug nodebug} {
116 build_and_run_test $l $s