1# Copyright 2022-2023 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 test is used to confirm that GDB is able to step, stopping at an 17# epilogue line, then step out of the function. 18 19standard_testfile 20 21if { ![have_epilogue_line_info] } { 22 untested "This test doesn't work with this compiler" 23 return 24} 25 26if { [prepare_for_testing "failed to prepare" $testfile \ 27 {step-through-epilogue.c}] } { 28 untested "failed to prepare" 29 return 30} 31 32if { ![runto_main] } { 33 untested "couldn't run to main" 34 return 35} 36 37proc step_till_epilogue_multiply {} { 38 gdb_test "step" ".*return a . b;.*" "step into multiply" 39 gdb_test "step" \ 40 "$::decimal\\s+\\\}\[^\r\n\]+Epilogue line of multiply.*" \ 41 "stop at the epilogue of multiply" 42} 43 44proc step_till_epilogue_square {} { 45 gdb_test "step" ".*return multiply.*" "step into square" 46 step_till_epilogue_multiply 47 gdb_test "step" \ 48 "$::decimal\\s+\\\}\[^\r\n\]+Epilogue line of square.*" \ 49 "stop at epilogue of square" 50} 51 52with_test_prefix "multiply" { 53 step_till_epilogue_multiply 54 gdb_test "step" "x = square \\(2\\);" "leave function" 55} 56 57with_test_prefix "square" { 58 step_till_epilogue_square 59 gdb_test "step" ".*x = multiply \\(square \\(1\\), square \\(2\\)\\);.*"\ 60 "leave function" 61} 62 63# Some gcc versions can mess this test by requiring extra steps in a 64# few locations. We dynamically test if we're in one such versions in the 65# the first argument, and use that to see if extra steps are needed to 66# finish the second argument 67set midway_return false 68 69with_test_prefix "square, first argument" { 70 step_till_epilogue_square 71 gdb_test_multiple "step" "step back to main" { 72 -re -wrap "multiply \\(square \\(1\\), square \\(2\\)\\);" { 73 set midway_return true 74 gdb_send "step\n" 75 exp_continue 76 } 77 78 -re -wrap "return multiply.*" { 79 pass $gdb_test_name 80 } 81 } 82} 83with_test_prefix "square, second argument" { 84 step_till_epilogue_multiply 85 gdb_test "step" \ 86 "$::decimal\\s+\\\}\[^\r\n\]+Epilogue line of square.*" \ 87 "stop at epilogue of square" 88 if {$midway_return} { 89 gdb_test "step"\ 90 ".*x = multiply \\(square \\(1\\), square \\(2\\)\\);.*"\ 91 "step back to main" 92 } 93} 94 95with_test_prefix "multiply with function args" { 96 step_till_epilogue_multiply 97 gdb_test "step" ".*return 0;.*" "leave last function" 98} 99