1# Copyright (C) 2015-2023 Free Software Foundation, Inc. 2# 3# Contributed by Intel Corp. <walfred.tedeschi@intel.com> 4# 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 3 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18# Testing handle setup together with boundary violation signals. 19# 20# Some states are not allowed as reported on the manual, as noprint 21# implies nostop, but nostop might print. 22# 23# Caveat: Setting the handle to nopass, ends up in a endless loop. 24 25if { ![istarget i?86-*-*] && ![istarget x86_64-*-* ] } { 26 verbose "Skipping x86 MPX tests." 27 return 28} 29 30standard_testfile 31 32if { ![supports_mpx_check_pointer_bounds] } { 33 return -1 34} 35 36if { ![have_mpx] } { 37 unsupported "processor does not support MPX" 38 return -1 39} 40 41set comp_flags "-mmpx -fcheck-pointer-bounds -I${srcdir}/../nat/" 42 43if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ 44 [list debug nowarnings additional_flags=${comp_flags}]] } { 45 return -1 46} 47 48if ![runto_main] { 49 return -1 50} 51 52set violation [multi_line "Program received signal SIGSEGV, Segmentation fault" \ 53 "Upper bound violation while accessing address $hex" \ 54 "Bounds: \\\[lower = $hex, upper = $hex\\\]"] 55 56set segv_with_exit "Program received signal SIGSEGV,\ 57 Segmentation fault.*$inferior_exited_re.*" 58 59 60# Test handler for segmentation fault for: 61# print pass stop 62# 63set parameters "print pass stop" 64with_test_prefix "$parameters" { 65 if ![runto_main] { 66 return -1 67 } 68 69 gdb_test "handle SIGSEGV $parameters"\ 70 ".*SIGSEGV.*Yes.*Yes.*Yes.*Segmentation fault.*"\ 71 "set parameters" 72 73 gdb_test "continue" ".*$violation.*" "display" 74 75 gdb_test "where" ".*#0 $hex in upper.*"\ 76 "should be in upper" 77} 78 79# Test handler for segmentation fault for: 80# print pass nostop 81# 82set parameters "print pass nostop" 83with_test_prefix "$parameters" { 84 if ![runto_main] { 85 return -1 86 } 87 88 gdb_test "handle SIGSEGV $parameters"\ 89 ".*SIGSEGV.*No.*Yes.*Yes.*Segmentation fault.*"\ 90 "set parameters" 91 92 gdb_test "continue" ".*$segv_with_exit.*" "display" 93 94 gdb_test "where" "No stack." "no inferior" 95} 96 97# Test handler for segmentation fault for: 98# print nopass stop 99# 100set parameters "print nopass stop" 101with_test_prefix "$parameters" { 102 if ![runto_main] { 103 return -1 104 } 105 106 gdb_test "handle SIGSEGV $parameters"\ 107 ".*SIGSEGV.*Yes.*Yes.*No.*Segmentation fault.*"\ 108 "set parameters" 109 110 gdb_test "continue" ".*$violation.*" "display" 111 112 gdb_test "where" ".*#0 $hex in upper.*"\ 113 "should be in upper" 114} 115 116# Test handler for segmentation fault for: 117# print nopass stop 118# 119set parameters "noprint pass nostop" 120with_test_prefix "$parameters" { 121 if ![runto_main] { 122 return -1 123 } 124 125 gdb_test "handle SIGSEGV $parameters"\ 126 ".*SIGSEGV.*No.*No.*Yes.*Segmentation fault.*"\ 127 "set parameters" 128 129 gdb_test "continue" "Continuing\..*$inferior_exited_re.*"\ 130 "Display" 131 132 gdb_test "where" "No stack." "no inferior" 133} 134 135