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