Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2019-2020 Free Software Foundation, Inc. |
c855a912 TBA |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | # Check that GDB can call C++ functions whose parameters have | |
17 | # object type, and are either passed by value or implicitly by reference. | |
18 | # | |
19 | # This is a companion test to pass-by-ref.exp. In this test, the input | |
20 | # is manually-written. In pass-by-ref.exp, the test input is generated. | |
21 | # | |
22 | # We include tests for classes that | |
23 | # - contain arrays as fields, | |
24 | # - are dynamic (i.e. have virtual methods) | |
25 | # - have inlined copy ctor | |
26 | # - have deleted destructor | |
27 | ||
28 | if {[skip_cplus_tests]} { | |
29 | untested "c++ test skipped" | |
30 | continue | |
31 | } | |
32 | ||
33 | standard_testfile .cc | |
34 | ||
35 | set options {debug c++ additional_flags=-std=c++11} | |
36 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile $options]} { | |
37 | return -1 | |
38 | } | |
39 | ||
40 | if {![runto_main]} { | |
41 | untested "failed to run to main" | |
42 | return -1 | |
43 | } | |
44 | ||
5f440116 TBA |
45 | # GCC version <= 6 and Clang do not emit DW_AT_defaulted and DW_AT_deleted. |
46 | set is_gcc_6_or_older [test_compiler_info {gcc-[0-6]-*}] | |
47 | set is_clang [test_compiler_info {clang-*}] | |
48 | ||
c855a912 TBA |
49 | set bp_location [gdb_get_line_number "stop here"] |
50 | gdb_breakpoint $bp_location | |
51 | gdb_continue_to_breakpoint "end of main" ".*return .*;" | |
52 | ||
53 | gdb_test "print cbvArrayContainerByVal (arrayContainerByVal)" "6" \ | |
54 | "call cbvArrayContainerByVal" | |
55 | gdb_test "print arrayContainerByVal.items\[0\].x" "2" \ | |
56 | "cbv argument 'arrayContainerByVal' should not change" | |
57 | ||
58 | gdb_test "print cbvArrayContainerByRef (arrayContainerByRef)" "7" \ | |
59 | "call cbvArrayContainerByRef" | |
60 | gdb_test "print arrayContainerByRef.items\[0\].x" "2" \ | |
61 | "cbv argument 'arrayContainerByRef' should not change" | |
62 | ||
63 | gdb_test "print cbvDynamic (dynamic)" "48" \ | |
64 | "call cbvDynamic" | |
65 | gdb_test "print dynamic.x" "2" \ | |
66 | "cbv argument 'dynamic' should not change" | |
67 | ||
68 | set sig "\"Inlined\:\:Inlined\\(.*Inlined const\&\\)\"" | |
69 | gdb_test "print cbvInlined (inlined)" \ | |
70 | "expression cannot be evaluated .* \\(maybe inlined\\?\\)" | |
71 | ||
5f440116 | 72 | if {$is_gcc_6_or_older || $is_clang} {setup_xfail "*-*-*"} |
c855a912 TBA |
73 | gdb_test "print cbvDtorDel (*dtorDel)" \ |
74 | ".* cannot be evaluated .* 'DtorDel' is not destructible" \ | |
75 | "type not destructible" | |
76 | ||
77 | # Test that GDB calls the correct copy ctor | |
78 | gdb_test "print cbvFourCCtor (fourCctor_c0v0)" "13" \ | |
79 | "call cbvFourCCtor (c0v0)" | |
80 | gdb_test "print fourCctor_c0v0.x" "2" \ | |
81 | "cbv argument 'twoCctor_c0v0' should not change" | |
82 | ||
83 | gdb_test "print cbvFourCCtor (fourCctor_c1v0)" "14" \ | |
84 | "call cbvFourCCtor (c1v0)" | |
85 | gdb_test "print fourCctor_c1v0.x" "2" \ | |
86 | "cbv argument 'twoCctor_c1v0' should not change" | |
87 | ||
88 | gdb_test "print cbvFourCCtor (fourCctor_c0v1)" "15" \ | |
89 | "call cbvFourCCtor (c0v1)" | |
90 | gdb_test "print fourCctor_c0v1.x" "2" \ | |
91 | "cbv argument 'twoCctor_c0v1' should not change" | |
92 | ||
93 | gdb_test "print cbvFourCCtor (fourCctor_c1v1)" "16" \ | |
94 | "call cbvFourCCtor (c1v1)" | |
95 | gdb_test "print fourCctor_c1v1.x" "2" \ | |
96 | "cbv argument 'twoCctor_c1v1' should not change" | |
97 | ||
98 | gdb_test "print cbvTwoMCtor (twoMctor)" \ | |
99 | ".* cannot be evaluated .* 'TwoMCtor' is not copy constructible" \ | |
100 | "copy ctor is implicitly deleted" | |
101 | ||
5f440116 | 102 | if {$is_gcc_6_or_older || $is_clang} {setup_xfail "*-*-*"} |
c855a912 TBA |
103 | gdb_test "print cbvTwoMCtorAndCCtor (twoMctorAndCctor)" "12" \ |
104 | "call cbvTwoMCtorAndCCtor" | |
105 | gdb_test "print twoMctorAndCctor.x" "2" \ | |
106 | "cbv argument 'twoMctorAndCtor' should not change" | |
107 | ||
108 | # Test that we get a breakpoint from the cctor during infcall and | |
109 | # we can examine arguments. This is a test that the dummy frame | |
110 | # of the copy constructor is set up correctly by the infcall mechanism. | |
111 | set bp_location [gdb_get_line_number "ByRef-cctor"] | |
112 | gdb_breakpoint $bp_location | |
113 | gdb_test "print cbvArrayContainerByRef (arrayContainerByRef)" \ | |
114 | ".*The program being debugged stopped.*" \ | |
115 | "call cbvArrayContainerByRef with BP" | |
116 | gdb_test "backtrace" [multi_line \ | |
117 | "#0 ByRef\:\:ByRef .* at .*$srcfile:$bp_location" \ | |
118 | "#1 .* ArrayContainerByRef::ArrayContainerByRef .*" \ | |
119 | "#2 <function called from gdb>" \ | |
120 | "#3 main.*"] |