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