1 # This testcase is part of GDB, the GNU debugger.
2 # Copyright 2018-2023 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 set main_basename infcall-nodebug-main
28 set lib_basename infcall-nodebug-lib
29 standard_testfile
${main_basename
}.c
${lib_basename
}.c
31 set mainsrc
"${srcdir}/${subdir}/${srcfile}"
32 set libsrc
"${srcdir}/${subdir}/${srcfile2}"
34 # Build both source files to objects using language LANG. Use SYMBOLS to build
35 # with either debug symbols or without - but always build the main file with
36 # debug. Then make function calls across the files.
38 proc build_and_run_test
{ lang symbols
} {
40 global main_basename lib_basename mainsrc libsrc binfile testfile
43 if { $symbols == "debug" } {
44 set debug_flags
"debug"
49 # Compile both files to objects, then link together.
51 set main_flags
"$lang debug"
52 set lib_flags
"$lang $debug_flags"
53 set main_o
[standard_output_file
${main_basename
}.o
]
54 set lib_o
[standard_output_file
${lib_basename
}.o
]
55 set binfile
[standard_output_file
${testfile
}]
57 if { [gdb_compile
$mainsrc $main_o object
${main_flags
}] != "" } {
58 untested
"failed to compile main file to object"
62 if { [gdb_compile
$libsrc $lib_o object
${lib_flags
}] != "" } {
63 untested
"failed to compile secondary file to object"
67 if { [gdb_compile
"$main_o $lib_o" ${binfile
} executable
""] != "" } {
68 untested
"failed to compile"
72 # Startup and run to main.
74 clean_restart
$binfile
76 if ![runto_main
] then
{
80 # Function call with cast.
82 gdb_test
"p (int)foo()" " = 1"
84 # Function call without cast. Will error if there are no debug symbols.
87 gdb_test_multiple
$test $test {
88 -re " = 1\r\n$gdb_prompt " {
89 gdb_assert
[ string equal
$symbols "debug" ]
92 -re "has unknown return type; cast the call to its declared return type\r\n$gdb_prompt " {
93 gdb_assert
![ string equal
$symbols "debug" ]
100 build_and_run_test
$lang $debug