mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-28 04:25:10 +08:00
012b3a217a
With Intel Memory Protection Extensions it was introduced the concept of boundary violation. A boundary violations is presented to the inferior as a segmentation fault having SIGCODE 3. This patch adds a handler for a boundary violation extending the information displayed when a bound violation is presented to the inferior. In the stop mode case the debugger will also display the kind of violation: "upper" or "lower", bounds and the address accessed. On no stop mode the information will still remain unchanged. Additional information about bound violations are not meaningful in that case user does not know the line in which violation occurred as well. When the segmentation fault handler is stop mode the out puts will be changed as exemplified below. The usual output of a segfault is: Program received signal SIGSEGV, Segmentation fault 0x0000000000400d7c in upper (p=0x603010, a=0x603030, b=0x603050, c=0x603070, d=0x603090, len=7) at i386-mpx-sigsegv.c:68 68 value = *(p + len); In case it is a bound violation it will be presented as: Program received signal SIGSEGV, Segmentation fault Upper bound violation while accessing address 0x7fffffffc3b3 Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3] 0x0000000000400d7c in upper (p=0x603010, a=0x603030, b=0x603050, c=0x603070, d=0x603090, len=7) at i386-mpx-sigsegv.c:68 68 value = *(p + len); In mi mode the output of a segfault is: *stopped,reason="signal-received",signal-name="SIGSEGV", signal-meaning="Segmentation fault", frame={addr="0x0000000000400d7c", func="upper",args=[{name="p", value="0x603010"},{name="a",value="0x603030"} ,{name="b",value="0x603050"}, {name="c",value="0x603070"}, {name="d",value="0x603090"},{name="len",value="7"}], file="i386-mpx-sigsegv.c",fullname="i386-mpx-sigsegv.c",line="68"}, thread-id="1",stopped-threads="all",core="6" in the case of a bound violation: *stopped,reason="signal-received",signal-name="SIGSEGV", signal-meaning="Segmentation fault", sigcode-meaning="Upper bound violation", lower-bound="0x603010",upper-bound="0x603023",bound-access="0x60302f", frame={addr="0x0000000000400d7c",func="upper",args=[{name="p", value="0x603010"},{name="a",value="0x603030"},{name="b",value="0x603050"}, {name="c",value="0x603070"},{name="d",value="0x603090"}, {name="len",value="7"}],file="i386-mpx-sigsegv.c", fullname="i386-mpx-sigsegv.c",line="68"},thread-id="1", stopped-threads="all",core="6" 2016-02-18 Walfred Tedeschi <walfred.tedeschi@intel.com> gdb/ChangeLog: * NEWS: Add entry for bound violation. * amd64-linux-tdep.c (amd64_linux_init_abi_common): Add handler for segmentation fault. * gdbarch.sh (handle_segmentation_fault): New. * gdbarch.c: Regenerate. * gdbarch.h: Regenerate. * i386-linux-tdep.c (i386_linux_handle_segmentation_fault): New. (SIG_CODE_BONDARY_FAULT): New define. (i386_linux_init_abi): Use i386_mpx_bound_violation_handler. * i386-linux-tdep.h (i386_linux_handle_segmentation_fault) New. * i386-tdep.c (i386_mpx_enabled): Add as external. * i386-tdep.c (i386_mpx_enabled): Add as external. * infrun.c (handle_segmentation_fault): New function. (print_signal_received_reason): Use handle_segmentation_fault. gdb/testsuite/ChangeLog: * gdb.arch/i386-mpx-sigsegv.c: New file. * gdb.arch/i386-mpx-sigsegv.exp: New file. * gdb.arch/i386-mpx-simple_segv.c: New file. * gdb.arch/i386-mpx-simple_segv.exp: New file. gdb/doc/ChangeLog: * gdb.texinfo (Signals): Add bound violation display hints for a SIGSEGV.
141 lines
3.9 KiB
Plaintext
141 lines
3.9 KiB
Plaintext
# Copyright (C) 2015-2016 Free Software Foundation, Inc.
|
|
#
|
|
# Contributed by Intel Corp. <walfred.tedeschi@intel.com>
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# Testing handle setup together with boundary violation signals.
|
|
#
|
|
# Some states are not allowed as reported on the manual, as noprint
|
|
# implies nostop, but nostop might print.
|
|
#
|
|
# Caveat: Setting the handle to nopass, ends up in a endless loop.
|
|
|
|
if { ![istarget i?86-*-*] && ![istarget x86_64-*-* ] } {
|
|
verbose "Skipping x86 MPX tests."
|
|
return
|
|
}
|
|
|
|
standard_testfile
|
|
|
|
set comp_flags "-mmpx -fcheck-pointer-bounds -I${srcdir}/../nat/"
|
|
|
|
if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
|
|
[list debug nowarnings additional_flags=${comp_flags}]] } {
|
|
return -1
|
|
}
|
|
|
|
if ![runto_main] {
|
|
untested "could not run to main"
|
|
return -1
|
|
}
|
|
|
|
gdb_test_multiple "print have_mpx ()" "have mpx" {
|
|
-re ".. = 1\r\n$gdb_prompt " {
|
|
pass "check whether processor supports MPX"
|
|
}
|
|
-re ".. = 0\r\n$gdb_prompt " {
|
|
verbose "processor does not support MPX; skipping MPX tests"
|
|
return
|
|
}
|
|
}
|
|
|
|
set violation [multi_line "Program received signal SIGSEGV, Segmentation fault" \
|
|
"Upper bound violation while accessing address $hex" \
|
|
"Bounds: \\\[lower = $hex, upper = $hex\\\]"]
|
|
|
|
set segv_with_exit "Program received signal SIGSEGV,\
|
|
Segmentation fault.*$inferior_exited_re.*"
|
|
|
|
|
|
# Test handler for segmentation fault for:
|
|
# print pass stop
|
|
#
|
|
set parameters "print pass stop"
|
|
with_test_prefix "$parameters" {
|
|
if ![runto_main] {
|
|
fail "could not run to main"
|
|
return -1
|
|
}
|
|
|
|
gdb_test "handle SIGSEGV $parameters"\
|
|
".*SIGSEGV.*Yes.*Yes.*Yes.*Segmentation fault.*"\
|
|
"set parameters"
|
|
|
|
gdb_test "continue" ".*$violation.*" "Display"
|
|
|
|
gdb_test "where" ".*#0 $hex in upper.*"\
|
|
"should be in upper"
|
|
}
|
|
|
|
# Test handler for segmentation fault for:
|
|
# print pass nostop
|
|
#
|
|
set parameters "print pass nostop"
|
|
with_test_prefix "$parameters" {
|
|
if ![runto_main] {
|
|
fail "could not run to main"
|
|
return -1
|
|
}
|
|
|
|
gdb_test "handle SIGSEGV $parameters"\
|
|
".*SIGSEGV.*No.*Yes.*Yes.*Segmentation fault.*"\
|
|
"set parameters"
|
|
|
|
gdb_test "continue" ".*$segv_with_exit.*" "Display"
|
|
|
|
gdb_test "where" "No stack." "no inferior"
|
|
}
|
|
|
|
# Test handler for segmentation fault for:
|
|
# print nopass stop
|
|
#
|
|
set parameters "print nopass stop"
|
|
with_test_prefix "$parameters" {
|
|
if ![runto_main] {
|
|
fail "could not run to main"
|
|
return -1
|
|
}
|
|
|
|
gdb_test "handle SIGSEGV $parameters"\
|
|
".*SIGSEGV.*Yes.*Yes.*No.*Segmentation fault.*"\
|
|
"set parameters"
|
|
|
|
gdb_test "continue" ".*$violation.*" "Display"
|
|
|
|
gdb_test "where" ".*#0 $hex in upper.*"\
|
|
"should be in upper"
|
|
}
|
|
|
|
# Test handler for segmentation fault for:
|
|
# print nopass stop
|
|
#
|
|
set parameters "noprint pass nostop"
|
|
with_test_prefix "$parameters" {
|
|
if ![runto_main] {
|
|
fail "could not run to main"
|
|
return -1
|
|
}
|
|
|
|
gdb_test "handle SIGSEGV $parameters"\
|
|
".*SIGSEGV.*No.*No.*Yes.*Segmentation fault.*"\
|
|
"set parameters"
|
|
|
|
gdb_test "continue" "Continuing\..*$inferior_exited_re.*"\
|
|
"Display"
|
|
|
|
gdb_test "where" "No stack." "no inferior"
|
|
}
|
|
|