1 # Copyright 2022-2024 Free Software Foundation, Inc. 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 # This testcase checks that if a function has the DW_AT_calling_convention 17 # attribute with the value DW_CC_nocall, then GDB will not: 18 # - call the function, 19 # - try to access the value returned by the function when using the finish 20 # command, 21 # - force a user-provided return value when using the return command. 22 # 23 # In every case, GDB prints a message to the user indicating the issue. For 24 # the return command, GDB asks the user to confirm if the specified value 25 # should be forced. 26 27 load_lib dwarf.exp 28 29 # This test can only be run on targets which support DWARF-2 and use gas. 30 require dwarf2_support 31 32 standard_testfile .c .S 33 34 # First compile the .c file so we can ask GDB what is sizeof(int). 35 if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { 36 untested "failed to compile" 37 return -1 38 } 39 40 # Make some DWARF for the test. 41 set asm_file [standard_output_file $srcfile2] 42 Dwarf::assemble $asm_file { 43 cu {} { 44 compile_unit { 45 {language @DW_LANG_C} 46 {name "calling-convention"} 47 } { 48 declare_labels int_label 49 50 int_label: base_type { 51 {byte_size [get_sizeof "int" 4] sdata} 52 {encoding @DW_ATE_signed} 53 {name "int"} 54 } 55 56 subprogram { 57 {MACRO_AT_func { foo }} 58 {type :$int_label} 59 {calling_convention @DW_CC_nocall} 60 } 61 62 subprogram { 63 {MACRO_AT_func { main }} 64 {type :$int_label} 65 } 66 } 67 } 68 } 69 70 if { [prepare_for_testing "failed to prepare" ${testfile} \ 71 [list $srcfile $asm_file] {nodebug}] } { 72 return -1 73 } 74 75 if {![runto_main]} { 76 return -1 77 } 78 79 gdb_test "call foo ()" \ 80 "Cannot call the function 'foo' which does not follow the target calling convention." 81 gdb_breakpoint "foo" 82 gdb_continue_to_breakpoint "foo" 83 84 gdb_test "return 35" \ 85 "Not confirmed" \ 86 "return 35" \ 87 [multi_line \ 88 "Function 'foo' does not follow the target calling convention\\." \ 89 "If you continue, setting the return value will probably lead to unpredictable behaviors\\." \ 90 "Make foo return now\\? \\(y or n\\) $"] \ 91 "n" 92 93 gdb_test "finish" [multi_line \ 94 "Run till exit from #0 $hex in foo \\(\\)" \ 95 "warning: Function 'foo' does not follow the target calling convention, cannot determine its returned value\." \ 96 "$hex in main \\(\\)" \ 97 "Value returned has type: int. Cannot determine contents"] 98