]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/infcall-nodebug.exp.tcl
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / infcall-nodebug.exp.tcl
1 # This testcase is part of GDB, the GNU debugger.
2 # Copyright 2018-2023 Free Software Foundation, Inc.
3
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.
8 #
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.
13 #
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/>.
16
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.
21
22 if [target_info exists gdb,cannot_call_functions] {
23 unsupported "this target can not call functions"
24 continue
25 }
26
27 set main_basename infcall-nodebug-main
28 set lib_basename infcall-nodebug-lib
29 standard_testfile ${main_basename}.c ${lib_basename}.c
30
31 set mainsrc "${srcdir}/${subdir}/${srcfile}"
32 set libsrc "${srcdir}/${subdir}/${srcfile2}"
33
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.
37
38 proc build_and_run_test { lang symbols } {
39
40 global main_basename lib_basename mainsrc libsrc binfile testfile
41 global gdb_prompt
42
43 if { $symbols == "debug" } {
44 set debug_flags "debug"
45 } else {
46 set debug_flags ""
47 }
48
49 # Compile both files to objects, then link together.
50
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}]
56
57 if { [gdb_compile $mainsrc $main_o object ${main_flags}] != "" } {
58 untested "failed to compile main file to object"
59 return -1
60 }
61
62 if { [gdb_compile $libsrc $lib_o object ${lib_flags}] != "" } {
63 untested "failed to compile secondary file to object"
64 return -1
65 }
66
67 if { [gdb_compile "$main_o $lib_o" ${binfile} executable ""] != "" } {
68 untested "failed to compile"
69 return -1
70 }
71
72 # Startup and run to main.
73
74 clean_restart $binfile
75
76 if ![runto_main] then {
77 return
78 }
79
80 # Function call with cast.
81
82 gdb_test "p (int)foo()" " = 1"
83
84 # Function call without cast. Will error if there are no debug symbols.
85
86 set test "p foo()"
87 gdb_test_multiple $test $test {
88 -re " = 1\r\n$gdb_prompt " {
89 gdb_assert [ string equal $symbols "debug" ]
90 pass $test
91 }
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" ]
94 pass $test
95 }
96 }
97
98 }
99
100 build_and_run_test $lang $debug