Commit | Line | Data |
---|---|---|
38a72da0 | 1 | # This testcase is part of GDB, the GNU debugger. |
3666a048 | 2 | # Copyright 2018-2021 Free Software Foundation, Inc. |
38a72da0 AH |
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 | ||
38a72da0 AH |
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 | ||
38a72da0 AH |
49 | # Compile both files to objects, then link together. |
50 | ||
51 | set main_flags "$lang debug" | |
52 | set lib_flags "$lang $debug_flags" | |
971a3747 TV |
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}] | |
38a72da0 AH |
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 | fail "can't run to main" | |
78 | return | |
79 | } | |
80 | ||
81 | # Function call with cast. | |
82 | ||
83 | gdb_test "p (int)foo()" " = 1" | |
84 | ||
85 | # Function call without cast. Will error if there are no debug symbols. | |
86 | ||
87 | set test "p foo()" | |
88 | gdb_test_multiple $test $test { | |
89 | -re " = 1\r\n$gdb_prompt " { | |
90 | gdb_assert [ string equal $symbols "debug" ] | |
91 | pass $test | |
92 | } | |
93 | -re "has unknown return type; cast the call to its declared return type\r\n$gdb_prompt " { | |
94 | gdb_assert ![ string equal $symbols "debug" ] | |
95 | pass $test | |
96 | } | |
97 | } | |
98 | ||
99 | } | |
100 | ||
971a3747 | 101 | build_and_run_test $lang $debug |