Commit | Line | Data |
---|---|---|
38a72da0 | 1 | # This testcase is part of GDB, the GNU debugger. |
b811d2c2 | 2 | # Copyright 2018-2020 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 | ||
27 | # Only test C++ if we are able. Always use C. | |
28 | if { [skip_cplus_tests] || [get_compiler_info "c++"] } { | |
29 | set lang {c} | |
30 | } else { | |
31 | set lang {c c++} | |
32 | } | |
33 | ||
34 | set main_basename infcall-nodebug-main | |
35 | set lib_basename infcall-nodebug-lib | |
36 | standard_testfile ${main_basename}.c ${lib_basename}.c | |
37 | ||
38 | set mainsrc "${srcdir}/${subdir}/${srcfile}" | |
39 | set libsrc "${srcdir}/${subdir}/${srcfile2}" | |
40 | ||
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. | |
44 | ||
45 | proc build_and_run_test { lang symbols } { | |
46 | ||
47 | global main_basename lib_basename mainsrc libsrc binfile testfile | |
48 | global gdb_prompt | |
49 | ||
50 | if { $symbols == "debug" } { | |
51 | set debug_flags "debug" | |
52 | } else { | |
53 | set debug_flags "" | |
54 | } | |
55 | ||
56 | # Setup directory. | |
57 | ||
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}]" | |
61 | ||
62 | # Compile both files to objects, then link together. | |
63 | ||
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}] | |
69 | ||
70 | if { [gdb_compile $mainsrc $main_o object ${main_flags}] != "" } { | |
71 | untested "failed to compile main file to object" | |
72 | return -1 | |
73 | } | |
74 | ||
75 | if { [gdb_compile $libsrc $lib_o object ${lib_flags}] != "" } { | |
76 | untested "failed to compile secondary file to object" | |
77 | return -1 | |
78 | } | |
79 | ||
80 | if { [gdb_compile "$main_o $lib_o" ${binfile} executable ""] != "" } { | |
81 | untested "failed to compile" | |
82 | return -1 | |
83 | } | |
84 | ||
85 | # Startup and run to main. | |
86 | ||
87 | clean_restart $binfile | |
88 | ||
89 | if ![runto_main] then { | |
90 | fail "can't run to main" | |
91 | return | |
92 | } | |
93 | ||
94 | # Function call with cast. | |
95 | ||
96 | gdb_test "p (int)foo()" " = 1" | |
97 | ||
98 | # Function call without cast. Will error if there are no debug symbols. | |
99 | ||
100 | set test "p foo()" | |
101 | gdb_test_multiple $test $test { | |
102 | -re " = 1\r\n$gdb_prompt " { | |
103 | gdb_assert [ string equal $symbols "debug" ] | |
104 | pass $test | |
105 | } | |
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" ] | |
108 | pass $test | |
109 | } | |
110 | } | |
111 | ||
112 | } | |
113 | ||
114 | foreach_with_prefix l $lang { | |
115 | foreach_with_prefix s {debug nodebug} { | |
116 | build_and_run_test $l $s | |
117 | } | |
118 | } | |
119 |