diff options
author | Walfred Tedeschi <walfred.tedeschi@intel.com> | 2016-02-18 17:24:59 +0100 |
---|---|---|
committer | Walfred Tedeschi <walfred.tedeschi@intel.com> | 2016-02-18 17:25:49 +0100 |
commit | 012b3a217a60cc74b802b059029c72a25d77808c (patch) | |
tree | 63f0e9fb65406b6de748f61eb83a158bab54a021 /gdb/i386-linux-tdep.c | |
parent | 5f034a78b986d30a90030b2409c61a8660b9b48c (diff) | |
download | gdb-012b3a217a60cc74b802b059029c72a25d77808c.zip gdb-012b3a217a60cc74b802b059029c72a25d77808c.tar.gz gdb-012b3a217a60cc74b802b059029c72a25d77808c.tar.bz2 |
Intel MPX bound violation handling
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.
Diffstat (limited to 'gdb/i386-linux-tdep.c')
-rw-r--r-- | gdb/i386-linux-tdep.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c index af39e78..63cda45 100644 --- a/gdb/i386-linux-tdep.c +++ b/gdb/i386-linux-tdep.c @@ -30,6 +30,7 @@ #include "i386-tdep.h" #include "i386-linux-tdep.h" #include "linux-tdep.h" +#include "utils.h" #include "glibc-tdep.h" #include "solib-svr4.h" #include "symtab.h" @@ -384,6 +385,71 @@ i386_canonicalize_syscall (int syscall) return gdb_sys_no_syscall; } +/* Value of the sigcode in case of a boundary fault. */ + +#define SIG_CODE_BONDARY_FAULT 3 + +/* i386 GNU/Linux implementation of the handle_segmentation_fault + gdbarch hook. Displays information related to MPX bound + violations. */ +void +i386_linux_handle_segmentation_fault (struct gdbarch *gdbarch, + struct ui_out *uiout) +{ + CORE_ADDR lower_bound, upper_bound, access; + int is_upper; + long sig_code = 0; + + if (!i386_mpx_enabled ()) + return; + + TRY + { + /* Sigcode evaluates if the actual segfault is a boundary violation. */ + sig_code = parse_and_eval_long ("$_siginfo.si_code\n"); + + lower_bound + = parse_and_eval_long ("$_siginfo._sifields._sigfault._addr_bnd._lower"); + upper_bound + = parse_and_eval_long ("$_siginfo._sifields._sigfault._addr_bnd._upper"); + access + = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr"); + } + CATCH (exception, RETURN_MASK_ALL) + { + return; + } + END_CATCH + + /* If this is not a boundary violation just return. */ + if (sig_code != SIG_CODE_BONDARY_FAULT) + return; + + is_upper = (access > upper_bound ? 1 : 0); + + ui_out_text (uiout, "\n"); + if (is_upper) + ui_out_field_string (uiout, "sigcode-meaning", + _("Upper bound violation")); + else + ui_out_field_string (uiout, "sigcode-meaning", + _("Lower bound violation")); + + ui_out_text (uiout, _(" while accessing address ")); + ui_out_field_fmt (uiout, "bound-access", "%s", + paddress (gdbarch, access)); + + ui_out_text (uiout, _("\nBounds: [lower = ")); + ui_out_field_fmt (uiout, "lower-bound", "%s", + paddress (gdbarch, lower_bound)); + + ui_out_text (uiout, _(", upper = ")); + ui_out_field_fmt (uiout, "upper-bound", "%s", + paddress (gdbarch, upper_bound)); + + ui_out_text (uiout, _("]")); +} + /* Parse the arguments of current system call instruction and record the values of the registers and memory that will be changed into "record_arch_list". This instruction is "int 0x80" (Linux @@ -1002,6 +1068,8 @@ i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) i386_linux_get_syscall_number); set_gdbarch_get_siginfo_type (gdbarch, x86_linux_get_siginfo_type); + set_gdbarch_handle_segmentation_fault (gdbarch, + i386_linux_handle_segmentation_fault); } /* Provide a prototype to silence -Wmissing-prototypes. */ |