aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.arch
diff options
context:
space:
mode:
authorWalfred Tedeschi <walfred.tedeschi@intel.com>2015-06-09 15:27:02 +0200
committerWalfred Tedeschi <walfred.tedeschi@intel.com>2015-06-10 09:58:06 +0200
commit29c1c24429a099eca297080dba56a8c090e3136a (patch)
treed9f89bc5baef8520972e7ba0a59a3ceeb6580ff8 /gdb/testsuite/gdb.arch
parent422d944b03535efba6187bbd9e35e87f73767dd7 (diff)
downloadgdb-29c1c24429a099eca297080dba56a8c090e3136a.zip
gdb-29c1c24429a099eca297080dba56a8c090e3136a.tar.gz
gdb-29c1c24429a099eca297080dba56a8c090e3136a.tar.bz2
Add support for bound table in the Intel MPX context.
Intel(R) Memory protection bound information are located in register to be tested using the MPX new instructions. Since the number of bound registers are limited a table is used to provide storage for bounds during run-time. In order to investigate the contents of the MPX bound table two new commands are added to GDB. "show mpx bound" and "set mpx bound" are used to display and set values on the MPX bound table. 2015-04-20 Walfred Tedeschi <walfred.tedeschi@intel.com> Mircea Gherzan <mircea.gherzan@intel.com> * i386-tdep.c (MPX_BASE_MASK, MPX_BD_MASK, MPX_BT_MASK, MPX_BD_MASK_32, MPX_BT_MASK_32): New macros. (i386_mpx_set_bounds): New function that implements the command "set-mpx-bound". (i386_mpx_enabled) Helper function to test MPX availability. (i386_mpx_bd_base) Helper function to calculate the base directory address. (i386_mpx_get_bt_entry) Helper function to access a bound table entry. (i386_mpx_print_bounds) Effectively display bound information. (_initialize_i386_tdep): Qdd new commands to commands "set mpx" and "show mpx". (_initialize_i386_tdep): Add "bound" to the commands "show mpx" and "set mpx" commands. (mpx_set_cmdlist and mpx_show_cmdlist): list for the new prefixed "set mpx" and "show mpx" commands. * NEWS: List new commands for MPX support. testsuite: * gdb.arch/i386-mpx-map.c: New file. * gdb.arch/i386-mpx-map.exp: New File. doc: * gdb.texinfo (i386): Add documentation about "show mpx bound" and "set mpx bound".
Diffstat (limited to 'gdb/testsuite/gdb.arch')
-rw-r--r--gdb/testsuite/gdb.arch/i386-mpx-map.c93
-rw-r--r--gdb/testsuite/gdb.arch/i386-mpx-map.exp76
2 files changed, 169 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.arch/i386-mpx-map.c b/gdb/testsuite/gdb.arch/i386-mpx-map.c
new file mode 100644
index 0000000..8a9094c
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/i386-mpx-map.c
@@ -0,0 +1,93 @@
+/* Test program for MPX map allocated bounds.
+
+ Copyright 2015 Free Software Foundation, Inc.
+
+ Contributed by Intel Corp. <walfred.tedeschi@intel.com>
+ <mircea.gherzan@intel.com>
+
+ This file is part of GDB.
+
+ 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/>. */
+
+#include <stdlib.h>
+#include "x86-cpuid.h"
+
+#ifndef NOINLINE
+#define NOINLINE __attribute__ ((noinline))
+#endif
+
+#define SIZE 5
+
+typedef int T;
+
+unsigned int have_mpx (void) NOINLINE;
+
+unsigned int NOINLINE
+have_mpx (void)
+{
+ unsigned int eax, ebx, ecx, edx;
+
+ if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx))
+ return 0;
+
+ if ((ecx & bit_OSXSAVE) == bit_OSXSAVE)
+ {
+ if (__get_cpuid_max (0, NULL) < 7)
+ return 0;
+
+ __cpuid_count (7, 0, eax, ebx, ecx, edx);
+
+ if ((ebx & bit_MPX) == bit_MPX)
+ return 1;
+ else
+ return 0;
+ }
+ return 0;
+}
+
+void
+foo (T *p)
+{
+ T *x;
+
+#if defined __GNUC__ && !defined __INTEL_COMPILER
+ __bnd_store_ptr_bounds (p, &p);
+#endif
+
+ x = p + SIZE - 1;
+
+#if defined __GNUC__ && !defined __INTEL_COMPILER
+ __bnd_store_ptr_bounds (x, &x);
+#endif
+
+ return; /* after-assign */
+}
+
+int
+main (void)
+{
+ if (have_mpx ())
+ {
+ T *a = NULL;
+
+ a = calloc (SIZE, sizeof (T)); /* after-decl */
+#if defined __GNUC__ && !defined __INTEL_COMPILER
+ __bnd_store_ptr_bounds (a, &a);
+#endif
+
+ foo (a); /* after-alloc */
+ free (a);
+ }
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.arch/i386-mpx-map.exp b/gdb/testsuite/gdb.arch/i386-mpx-map.exp
new file mode 100644
index 0000000..47efb16
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/i386-mpx-map.exp
@@ -0,0 +1,76 @@
+# Copyright 2015 Free Software Foundation, Inc.
+#
+# Contributed by Intel Corp. <walfred.tedeschi@intel.com>,
+# <mircea.gherzan@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/>.
+
+if { ![istarget i?86-*-*] && ![istarget x86_64-*-* ] } {
+ verbose "Skipping x86 MPX tests."
+ return
+}
+
+standard_testfile
+
+set comp_flags "-fmpx -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
+}
+
+set supports_mpx 0
+set test "probe MPX support"
+
+gdb_test_multiple "print have_mpx()" $test {
+ -re ".. = 1\r\n$gdb_prompt $" {
+ pass $test
+ set supports_mpx 1
+ }
+ -re ".. = 0\r\n$gdb_prompt $" {
+ pass $test
+ }
+}
+
+if { !$supports_mpx } {
+ unsupported "processor does not support MPX"
+ return
+}
+
+gdb_breakpoint [ gdb_get_line_number "after-decl" ]
+gdb_breakpoint [ gdb_get_line_number "after-alloc" ]
+gdb_breakpoint [ gdb_get_line_number "after-assign" ]
+
+gdb_test "show mpx bound 0x0" "Invalid bounds directory entry at $hex." "NULL address of the pointer"
+
+gdb_continue_to_breakpoint "after-decl" ".*after-decl.*"
+gdb_test "show mpx bound a" "Invalid bounds directory entry at $hex." "pointer instead of pointer address"
+
+gdb_continue_to_breakpoint "after-alloc" ".*after-alloc.*"
+gdb_test "show mpx bound a" "\\\{lbound = $hex, ubound = $hex\\\}: pointer value = $hex, size = \[8, 4\], metadata = 0x0+" "pointer after allocation"
+
+gdb_continue_to_breakpoint "after-assign" ".*after-assign.*"
+gdb_test "show mpx bound x" "\\\{lbound = $hex, ubound = $hex\\\}: pointer value = $hex, size = \[8, 4\], metadata = 0x0+" "pointer after assignment"
+gdb_test "set mpx bound 0x0, 0x1, 0x2" "Invalid bounds directory entry at $hex." "set mpx bound: NULL address of the pointer"
+gdb_test_no_output "set mpx bound x, 0xcafebabe, 0xdeadbeef" "set mpx bound: set bounds for a valid pointer address"
+gdb_test "show mpx bound x" "\\\{lbound = .*cafebabe, ubound = .*deadbeef\\\}: pointer value = $hex, size = $decimal, metadata = 0x0+" "set mpx bound: bounds map entry after set mpx bound"
+
+
+gdb_test "set mpx bound 0x0, 0x1 0x2" "A syntax error in expression.*" "set mpx bound: Controlling syntax error, missing comma "
+gdb_test "set mpx bound 0x0, 0x1" "Wrong number of arguments.*" "set mpx bound: Controlling syntax error, missing argument "