Home | History | Annotate | Line # | Download | only in gdb.cp
      1      1.1  christos # This testcase is part of GDB, the GNU debugger.
      2  1.1.1.3  christos # Copyright 2018-2024 Free Software Foundation, Inc.
      3      1.1  christos 
      4      1.1  christos # This program is free software; you can redistribute it and/or modify
      5      1.1  christos # it under the terms of the GNU General Public License as published by
      6      1.1  christos # the Free Software Foundation; either version 3 of the License, or
      7      1.1  christos # (at your option) any later version.
      8      1.1  christos #
      9      1.1  christos # This program is distributed in the hope that it will be useful,
     10      1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     11      1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12      1.1  christos # GNU General Public License for more details.
     13      1.1  christos #
     14      1.1  christos # You should have received a copy of the GNU General Public License
     15      1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16      1.1  christos 
     17      1.1  christos # Test function calls on C++ functions that have no debug information.
     18      1.1  christos # See gdb/22736.  Put the called function in a different object to ensure
     19      1.1  christos # the rest of the test can be complied with debug information.  Whilst we
     20      1.1  christos # are at it, also test functions with debug information and C functions too.
     21      1.1  christos 
     22      1.1  christos if [target_info exists gdb,cannot_call_functions] {
     23      1.1  christos     unsupported "this target can not call functions"
     24      1.1  christos     continue
     25      1.1  christos }
     26      1.1  christos 
     27      1.1  christos set main_basename infcall-nodebug-main
     28      1.1  christos set lib_basename infcall-nodebug-lib
     29      1.1  christos standard_testfile ${main_basename}.c ${lib_basename}.c
     30      1.1  christos 
     31      1.1  christos set mainsrc "${srcdir}/${subdir}/${srcfile}"
     32      1.1  christos set libsrc "${srcdir}/${subdir}/${srcfile2}"
     33      1.1  christos 
     34      1.1  christos # Build both source files to objects using language LANG. Use SYMBOLS to build
     35      1.1  christos # with either debug symbols or without - but always build the main file with
     36      1.1  christos # debug.  Then make function calls across the files.
     37      1.1  christos 
     38      1.1  christos proc build_and_run_test { lang symbols } {
     39      1.1  christos 
     40      1.1  christos     global main_basename lib_basename mainsrc libsrc binfile testfile
     41      1.1  christos     global gdb_prompt
     42      1.1  christos 
     43      1.1  christos     if { $symbols == "debug" } {
     44      1.1  christos 	set debug_flags "debug"
     45      1.1  christos     } else {
     46      1.1  christos 	set debug_flags ""
     47      1.1  christos     }
     48      1.1  christos 
     49      1.1  christos     # Compile both files to objects, then link together.
     50      1.1  christos 
     51      1.1  christos     set main_flags "$lang debug"
     52      1.1  christos     set lib_flags "$lang $debug_flags"
     53      1.1  christos     set main_o [standard_output_file ${main_basename}.o]
     54      1.1  christos     set lib_o [standard_output_file ${lib_basename}.o]
     55      1.1  christos     set binfile [standard_output_file ${testfile}]
     56      1.1  christos 
     57      1.1  christos     if { [gdb_compile $mainsrc $main_o object ${main_flags}] != "" } {
     58      1.1  christos 	untested "failed to compile main file to object"
     59      1.1  christos 	return -1
     60      1.1  christos     }
     61      1.1  christos 
     62      1.1  christos     if { [gdb_compile $libsrc $lib_o object ${lib_flags}] != "" } {
     63      1.1  christos 	untested "failed to compile secondary file to object"
     64      1.1  christos 	return -1
     65      1.1  christos     }
     66      1.1  christos 
     67      1.1  christos     if { [gdb_compile "$main_o $lib_o" ${binfile} executable ""] != "" } {
     68      1.1  christos 	untested "failed to compile"
     69      1.1  christos 	return -1
     70      1.1  christos     }
     71      1.1  christos 
     72      1.1  christos     # Startup and run to main.
     73      1.1  christos 
     74      1.1  christos     clean_restart $binfile
     75      1.1  christos 
     76      1.1  christos     if ![runto_main] then {
     77      1.1  christos 	return
     78      1.1  christos     }
     79      1.1  christos 
     80      1.1  christos     # Function call with cast.
     81      1.1  christos 
     82      1.1  christos     gdb_test "p (int)foo()" " = 1"
     83      1.1  christos 
     84      1.1  christos     # Function call without cast.  Will error if there are no debug symbols.
     85      1.1  christos 
     86      1.1  christos     set test "p foo()"
     87      1.1  christos     gdb_test_multiple $test $test {
     88      1.1  christos 	-re " = 1\r\n$gdb_prompt " {
     89      1.1  christos 	    gdb_assert [ string equal $symbols "debug" ]
     90      1.1  christos 	    pass $test
     91      1.1  christos 	}
     92      1.1  christos 	-re "has unknown return type; cast the call to its declared return type\r\n$gdb_prompt " {
     93      1.1  christos 	    gdb_assert ![ string equal $symbols "debug" ]
     94      1.1  christos 	    pass $test
     95      1.1  christos 	}
     96      1.1  christos     }
     97      1.1  christos 
     98      1.1  christos }
     99      1.1  christos 
    100      1.1  christos build_and_run_test $lang $debug
    101