Blame SOURCES/gdb-upstream.patch

e1d87d
commit 16eb6b2db49e6cf2fdca56efd37689fcc170cd37
e1d87d
Author: Leszek Swirski <leszeks@google.com>
e1d87d
Date:   Mon Aug 7 16:40:38 2017 +0200
e1d87d
e1d87d
    Fix dwarf2_string_attr for -gsplit-dwarf
e1d87d
    
e1d87d
    The dwarf2_string_attr did not allow DW_FORM_GNU_str_index as a form for
e1d87d
    string types. This manifested as null strings in the namespace_name
e1d87d
    lookup (replaced with "(anonymous namespace)") when debugging
e1d87d
    Fission-compiled code.
e1d87d
    
e1d87d
    gdb/ChangeLog:
e1d87d
    
e1d87d
            * dwarf2read.c (dwarf2_string_attr): Allow DW_FORM_GNU_strp_alt.
e1d87d
e1d87d
### a/gdb/ChangeLog
e1d87d
### b/gdb/ChangeLog
e1d87d
## -1,3 +1,7 @@
e1d87d
+2017-08-07  Leszek Swirski  <leszeks@google.com>
e1d87d
+
e1d87d
+	* dwarf2read.c (dwarf2_string_attr): Allow DW_FORM_GNU_strp_alt.
e1d87d
+
e1d87d
 2017-08-07  Simon Marchi  <simon.marchi@ericsson.com>
e1d87d
 
e1d87d
 	* remote-sim.c (gdbsim_load): Remove char **argv local variable.
e1d87d
--- a/gdb/dwarf2read.c
e1d87d
+++ b/gdb/dwarf2read.c
e1d87d
@@ -17623,7 +17623,8 @@ dwarf2_string_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *c
e1d87d
   if (attr != NULL)
e1d87d
     {
e1d87d
       if (attr->form == DW_FORM_strp || attr->form == DW_FORM_line_strp
e1d87d
-	  || attr->form == DW_FORM_string || attr->form == DW_FORM_GNU_strp_alt)
e1d87d
+	  || attr->form == DW_FORM_string || DW_FORM_GNU_str_index
e1d87d
+	  || attr->form == DW_FORM_GNU_strp_alt)
e1d87d
 	str = DW_STRING (attr);
e1d87d
       else
e1d87d
         complaint (&symfile_complaints,
e1d87d
e1d87d
e1d87d
e1d87d
commit b33404388e5bbd8a1fddfde73cd4593ae2b557e8
e1d87d
Author: H.J. Lu <hjl.tools@gmail.com>
e1d87d
Date:   Wed Aug 9 05:01:55 2017 -0700
e1d87d
e1d87d
    gdb: Fix build failure with GCC 7
e1d87d
    
e1d87d
    Fix:
e1d87d
    
e1d87d
    /export/gnu/import/git/sources/binutils-gdb/gdb/dwarf2read.c: In function ‘const char* dwarf2_string_attr(die_info*, unsigned int, dwarf2_cu*)’:
e1d87d
    /export/gnu/import/git/sources/binutils-gdb/gdb/dwarf2read.c:17626:39: error: enum constant in boolean context [-Werror=int-in-bool-context]
e1d87d
        || attr->form == DW_FORM_string || DW_FORM_GNU_str_index
e1d87d
    
e1d87d
            * dwarf2read.c (dwarf2_string_attr): Fix a typo.
e1d87d
e1d87d
### a/gdb/ChangeLog
e1d87d
### b/gdb/ChangeLog
e1d87d
## -1,3 +1,7 @@
e1d87d
+2017-08-09  H.J. Lu  <hongjiu.lu@intel.com>
e1d87d
+
e1d87d
+	* dwarf2read.c (dwarf2_string_attr): Fix a typo.
e1d87d
+
e1d87d
 2017-08-09  Alex Lindsay  <alexlindsay239@gmail.com>
e1d87d
 	    Yao Qi  <yao.qi@linaro.org>
e1d87d
 
e1d87d
--- a/gdb/dwarf2read.c
e1d87d
+++ b/gdb/dwarf2read.c
e1d87d
@@ -17623,7 +17623,8 @@ dwarf2_string_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *c
e1d87d
   if (attr != NULL)
e1d87d
     {
e1d87d
       if (attr->form == DW_FORM_strp || attr->form == DW_FORM_line_strp
e1d87d
-	  || attr->form == DW_FORM_string || DW_FORM_GNU_str_index
e1d87d
+	  || attr->form == DW_FORM_string
e1d87d
+	  || attr->form == DW_FORM_GNU_str_index
e1d87d
 	  || attr->form == DW_FORM_GNU_strp_alt)
e1d87d
 	str = DW_STRING (attr);
e1d87d
       else
15e4b0
15e4b0
15e4b0
15e4b0
commit f24b864960e61f9a91f8c168c1afe12a6676ad7a
15e4b0
Author: Walfred Tedeschi <walfred.tedeschi@intel.com>
15e4b0
Date:   Mon Oct 16 08:59:38 2017 +0200
15e4b0
15e4b0
    PR22137: gdbserver crashes on host with pkru register.
15e4b0
    
15e4b0
    This patch adds missing backslash on a makefile and regenerate the
15e4b0
    files created via the xml files.  Those were not in sync with the xml file.
15e4b0
    
15e4b0
    gdb/ChangeLog:
15e4b0
    
15e4b0
    2017-10-16  Walfred Tedeschi  <walfred.tedeschi@intel.com>
15e4b0
    
15e4b0
            * features/Makefile (i386-avx-mpx-avx512-pku.dat): Add backslash
15e4b0
            at the end of the line.
15e4b0
            * regformats/i386/amd64-avx-mpx-avx512-pku-linux.dat: Regenerate.
15e4b0
            * regformats/i386/amd64-avx-mpx-avx512-pku.dat: Regenerate.
15e4b0
15e4b0
### a/gdb/ChangeLog
15e4b0
### b/gdb/ChangeLog
15e4b0
## -1,3 +1,10 @@
15e4b0
+2017-10-16  Walfred Tedeschi  <walfred.tedeschi@intel.com>
15e4b0
+
15e4b0
+	* features/Makefile (i386-avx-mpx-avx512-pku.dat): Add backslash 
15e4b0
+	at the end of the line.
15e4b0
+	* regformats/i386/amd64-avx-mpx-avx512-pku-linux.dat: Regenerate.
15e4b0
+	* regformats/i386/amd64-avx-mpx-avx512-pku.dat: Regenerate.
15e4b0
+
15e4b0
 2017-09-07  Joel Brobecker  <brobecker@adacore.com>
15e4b0
 
15e4b0
 	* version.in: Set GDB version number to 8.0.1.DATE-git.
15e4b0
--- a/gdb/features/Makefile
15e4b0
+++ b/gdb/features/Makefile
15e4b0
@@ -281,7 +281,7 @@ $(outdir)/i386/i386-avx-avx512.dat: i386/32bit-core.xml i386/32bit-avx.xml \
15e4b0
 			       i386/32bit-avx512.xml
15e4b0
 $(outdir)/i386/i386-avx-avx512-linux.dat: i386/32bit-core.xml i386/32bit-avx.xml \
15e4b0
 			       i386/32bit-linux.xml i386/32bit-avx512.xml
15e4b0
-$(outdir)/i386/i386-avx-mpx-avx512-pku.dat: i386/32bit-core.xml
15e4b0
+$(outdir)/i386/i386-avx-mpx-avx512-pku.dat: i386/32bit-core.xml \
15e4b0
 			       i386/32bit-avx.xml i386/32bit-mpx.xml i386/32bit-avx512.xml \
15e4b0
 			       i386/32bit-pkeys.xml
15e4b0
 $(outdir)/i386/i386-avx-mpx-avx512-pku-linux.dat: i386/32bit-core.xml \
15e4b0
--- a/gdb/regformats/i386/amd64-avx-mpx-avx512-pku-linux.dat
15e4b0
+++ b/gdb/regformats/i386/amd64-avx-mpx-avx512-pku-linux.dat
15e4b0
@@ -157,3 +157,4 @@ expedite:rbp,rsp,rip
15e4b0
 256:zmm29h
15e4b0
 256:zmm30h
15e4b0
 256:zmm31h
15e4b0
+32:pkru
15e4b0
--- a/gdb/regformats/i386/amd64-avx-mpx-avx512-pku.dat
15e4b0
+++ b/gdb/regformats/i386/amd64-avx-mpx-avx512-pku.dat
15e4b0
@@ -60,9 +60,6 @@ expedite:rbp,rsp,rip
15e4b0
 128:xmm14
15e4b0
 128:xmm15
15e4b0
 32:mxcsr
15e4b0
-64:orig_rax
15e4b0
-64:fs_base
15e4b0
-64:gs_base
15e4b0
 128:ymm0h
15e4b0
 128:ymm1h
15e4b0
 128:ymm2h
15e4b0
15e4b0
15e4b0
15e4b0
commit 50a1fdd59c1777672a9be0e81fe2301c2a115fce
15e4b0
Author: Pedro Alves <palves@redhat.com>
15e4b0
Date:   Mon Dec 4 15:59:20 2017 +0000
15e4b0
15e4b0
    Fix displaced-stepping RIP-relative VEX-encoded instructions (AVX) (PR gdb/22499)
15e4b0
    
15e4b0
    PR gdb/22499 is about a latent bug exposed by the switch to "maint set
15e4b0
    target-non-stop on" by default on x86-64 GNU/Linux, a while ago.  With
15e4b0
    that on, GDB is also preferring to use displaced-stepping by default.
15e4b0
    
15e4b0
    The testcase in the bug is failing because GDB ends up incorrectly
15e4b0
    displaced-stepping over a RIP-relative VEX-encoded instruction, like
15e4b0
    this:
15e4b0
    
15e4b0
     0x00000000004007f5 <+15>:    c5 fb 10 05 8b 01 00 00 vmovsd 0x18b(%rip),%xmm0        # 0x400988
15e4b0
    
15e4b0
    While RIP-relative instructions need adjustment when relocated to the
15e4b0
    scratch pad, GDB ends up just copying VEX-encoded instructions to the
15e4b0
    scratch pad unmodified, with the end result that the inferior ends up
15e4b0
    executing an instruction that fetches/writes memory from the wrong
15e4b0
    address...
15e4b0
    
15e4b0
    This patch teaches GDB about the VEX-encoding prefixes, fixing the
15e4b0
    problem, and adds a testcase that fails without the GDB fix.
15e4b0
    
15e4b0
    I think we may need a similar treatment for EVEX-encoded instructions,
15e4b0
    but I didn't address that simply because I couldn't find any
15e4b0
    EVEX-encoded RIP-relative instruction in the gas testsuite.  In any
15e4b0
    case, this commit is forward progress as-is already.
15e4b0
    
15e4b0
    gdb/ChangeLog:
15e4b0
    2017-12-04  Pedro Alves  <palves@redhat.com>
15e4b0
    
15e4b0
            PR gdb/22499
15e4b0
            * amd64-tdep.c (amd64_insn::rex_offset): Rename to...
15e4b0
            (amd64_insn::enc_prefix_offset): ... this, and tweak comment.
15e4b0
            (vex2_prefix_p, vex3_prefix_p): New functions.
15e4b0
            (amd64_get_insn_details): Adjust to rename.  Also skip VEX2 and
15e4b0
            VEX3 prefixes.
15e4b0
            (fixup_riprel): Set VEX3.!B.
15e4b0
    
15e4b0
    gdb/testsuite/ChangeLog:
15e4b0
    2017-12-04  Pedro Alves  <palves@redhat.com>
15e4b0
    
15e4b0
            PR gdb/22499
15e4b0
            * gdb.arch/amd64-disp-step-avx.S: New file.
15e4b0
            * gdb.arch/amd64-disp-step-avx.exp: New file.
15e4b0
15e4b0
### a/gdb/ChangeLog
15e4b0
### b/gdb/ChangeLog
15e4b0
## -1,3 +1,13 @@
15e4b0
+2017-12-04  Pedro Alves  <palves@redhat.com>
15e4b0
+
15e4b0
+	PR gdb/22499
15e4b0
+	* amd64-tdep.c (amd64_insn::rex_offset): Rename to...
15e4b0
+	(amd64_insn::enc_prefix_offset): ... this, and tweak comment.
15e4b0
+	(vex2_prefix_p, vex3_prefix_p): New functions.
15e4b0
+	(amd64_get_insn_details): Adjust to rename.  Also skip VEX2 and
15e4b0
+	VEX3 prefixes.
15e4b0
+	(fixup_riprel): Set VEX3.!B.
15e4b0
+
15e4b0
 2017-12-03  Simon Marchi  <simon.marchi@ericsson.com>
15e4b0
 
15e4b0
 	* target.h (mem_region_vector): Remove.
15e4b0
--- a/gdb/amd64-tdep.c
15e4b0
+++ b/gdb/amd64-tdep.c
15e4b0
@@ -1037,8 +1037,9 @@ struct amd64_insn
15e4b0
 {
15e4b0
   /* The number of opcode bytes.  */
15e4b0
   int opcode_len;
15e4b0
-  /* The offset of the rex prefix or -1 if not present.  */
15e4b0
-  int rex_offset;
15e4b0
+  /* The offset of the REX/VEX instruction encoding prefix or -1 if
15e4b0
+     not present.  */
15e4b0
+  int enc_prefix_offset;
15e4b0
   /* The offset to the first opcode byte.  */
15e4b0
   int opcode_offset;
15e4b0
   /* The offset to the modrm byte or -1 if not present.  */
15e4b0
@@ -1124,6 +1125,22 @@ rex_prefix_p (gdb_byte pfx)
15e4b0
   return REX_PREFIX_P (pfx);
15e4b0
 }
15e4b0
 
15e4b0
+/* True if PFX is the start of the 2-byte VEX prefix.  */
15e4b0
+
15e4b0
+static bool
15e4b0
+vex2_prefix_p (gdb_byte pfx)
15e4b0
+{
15e4b0
+  return pfx == 0xc5;
15e4b0
+}
15e4b0
+
15e4b0
+/* True if PFX is the start of the 3-byte VEX prefix.  */
15e4b0
+
15e4b0
+static bool
15e4b0
+vex3_prefix_p (gdb_byte pfx)
15e4b0
+{
15e4b0
+  return pfx == 0xc4;
15e4b0
+}
15e4b0
+
15e4b0
 /* Skip the legacy instruction prefixes in INSN.
15e4b0
    We assume INSN is properly sentineled so we don't have to worry
15e4b0
    about falling off the end of the buffer.  */
15e4b0
@@ -1242,19 +1259,30 @@ amd64_get_insn_details (gdb_byte *insn, struct amd64_insn *details)
15e4b0
   details->raw_insn = insn;
15e4b0
 
15e4b0
   details->opcode_len = -1;
15e4b0
-  details->rex_offset = -1;
15e4b0
+  details->enc_prefix_offset = -1;
15e4b0
   details->opcode_offset = -1;
15e4b0
   details->modrm_offset = -1;
15e4b0
 
15e4b0
   /* Skip legacy instruction prefixes.  */
15e4b0
   insn = amd64_skip_prefixes (insn);
15e4b0
 
15e4b0
-  /* Skip REX instruction prefix.  */
15e4b0
+  /* Skip REX/VEX instruction encoding prefixes.  */
15e4b0
   if (rex_prefix_p (*insn))
15e4b0
     {
15e4b0
-      details->rex_offset = insn - start;
15e4b0
+      details->enc_prefix_offset = insn - start;
15e4b0
       ++insn;
15e4b0
     }
15e4b0
+  else if (vex2_prefix_p (*insn))
15e4b0
+    {
15e4b0
+      /* Don't record the offset in this case because this prefix has
15e4b0
+	 no REX.B equivalent.  */
15e4b0
+      insn += 2;
15e4b0
+    }
15e4b0
+  else if (vex3_prefix_p (*insn))
15e4b0
+    {
15e4b0
+      details->enc_prefix_offset = insn - start;
15e4b0
+      insn += 3;
15e4b0
+    }
15e4b0
 
15e4b0
   details->opcode_offset = insn - start;
15e4b0
 
15e4b0
@@ -1329,10 +1357,22 @@ fixup_riprel (struct gdbarch *gdbarch, amd64_displaced_step_closure *dsc,
15e4b0
   arch_tmp_regno = amd64_get_unused_input_int_reg (insn_details);
15e4b0
   tmp_regno = amd64_arch_reg_to_regnum (arch_tmp_regno);
15e4b0
 
15e4b0
-  /* REX.B should be unset as we were using rip-relative addressing,
15e4b0
-     but ensure it's unset anyway, tmp_regno is not r8-r15.  */
15e4b0
-  if (insn_details->rex_offset != -1)
15e4b0
-    dsc->insn_buf[insn_details->rex_offset] &= ~REX_B;
15e4b0
+  /* Position of the not-B bit in the 3-byte VEX prefix (in byte 1).  */
15e4b0
+  static constexpr gdb_byte VEX3_NOT_B = 0x20;
15e4b0
+
15e4b0
+  /* REX.B should be unset (VEX.!B set) as we were using rip-relative
15e4b0
+     addressing, but ensure it's unset (set for VEX) anyway, tmp_regno
15e4b0
+     is not r8-r15.  */
15e4b0
+  if (insn_details->enc_prefix_offset != -1)
15e4b0
+    {
15e4b0
+      gdb_byte *pfx = &dsc->insn_buf[insn_details->enc_prefix_offset];
15e4b0
+      if (rex_prefix_p (pfx[0]))
15e4b0
+	pfx[0] &= ~REX_B;
15e4b0
+      else if (vex3_prefix_p (pfx[0]))
15e4b0
+	pfx[1] |= VEX3_NOT_B;
15e4b0
+      else
15e4b0
+	gdb_assert_not_reached ("unhandled prefix");
15e4b0
+    }
15e4b0
 
15e4b0
   regcache_cooked_read_unsigned (regs, tmp_regno, &orig_value);
15e4b0
   dsc->tmp_regno = tmp_regno;
15e4b0
### a/gdb/testsuite/ChangeLog
15e4b0
### b/gdb/testsuite/ChangeLog
15e4b0
## -1,3 +1,9 @@
15e4b0
+2017-12-04  Pedro Alves  <palves@redhat.com>
15e4b0
+
15e4b0
+	PR gdb/22499
15e4b0
+	* gdb.arch/amd64-disp-step-avx.S: New file.
15e4b0
+	* gdb.arch/amd64-disp-step-avx.exp: New file.
15e4b0
+
15e4b0
 2017-12-03  Pedro Alves  <palves@redhat.com>
15e4b0
 
15e4b0
 	* gdb.threads/process-dies-while-detaching.c: Include <errno.h>
15e4b0
--- /dev/null
15e4b0
+++ b/gdb/testsuite/gdb.arch/amd64-disp-step-avx.S
15e4b0
@@ -0,0 +1,70 @@
15e4b0
+/* Copyright 2009-2017 Free Software Foundation, Inc.
15e4b0
+
15e4b0
+   This program is free software; you can redistribute it and/or modify
15e4b0
+   it under the terms of the GNU General Public License as published by
15e4b0
+   the Free Software Foundation; either version 3 of the License, or
15e4b0
+   (at your option) any later version.
15e4b0
+
15e4b0
+   This program is distributed in the hope that it will be useful,
15e4b0
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
15e4b0
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15e4b0
+   GNU General Public License for more details.
15e4b0
+
15e4b0
+   You should have received a copy of the GNU General Public License
15e4b0
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
15e4b0
+
15e4b0
+   This file is part of the gdb testsuite.
15e4b0
+
15e4b0
+   Test displaced stepping over VEX-encoded RIP-relative AVX
15e4b0
+   instructions.  */
15e4b0
+
15e4b0
+	.text
15e4b0
+
15e4b0
+	.global main
15e4b0
+main:
15e4b0
+	nop
15e4b0
+
15e4b0
+/***********************************************/
15e4b0
+
15e4b0
+/* Test a VEX2-encoded RIP-relative instruction.  */
15e4b0
+
15e4b0
+	.global test_rip_vex2
15e4b0
+test_rip_vex2:
15e4b0
+	vmovsd ro_var(%rip),%xmm0
15e4b0
+	.global test_rip_vex2
15e4b0
+test_rip_vex2_end:
15e4b0
+	nop
15e4b0
+
15e4b0
+/* Test a VEX3-encoded RIP-relative instruction.  */
15e4b0
+
15e4b0
+	.global test_rip_vex3
15e4b0
+test_rip_vex3:
15e4b0
+	vextractf128 $0x0,%ymm0,var128(%rip)
15e4b0
+	.global test_rip_vex3
15e4b0
+test_rip_vex3_end:
15e4b0
+	nop
15e4b0
+
15e4b0
+	/* skip over test data */
15e4b0
+	jmp done
15e4b0
+
15e4b0
+/* RIP-relative ro-data for VEX2 test above.  */
15e4b0
+
15e4b0
+ro_var:
15e4b0
+	.8byte 0x1122334455667788
15e4b0
+	.8byte 0x8877665544332211
15e4b0
+
15e4b0
+/***********************************************/
15e4b0
+
15e4b0
+/* All done.  */
15e4b0
+
15e4b0
+done:
15e4b0
+	mov $0,%rdi
15e4b0
+	call exit
15e4b0
+	hlt
15e4b0
+
15e4b0
+/* RIP-relative data for VEX3 test above.  */
15e4b0
+
15e4b0
+.data
15e4b0
+var128:
15e4b0
+	.8byte 0xaa55aa55aa55aa55
15e4b0
+	.8byte 0x55aa55aa55aa55aa
15e4b0
--- /dev/null
15e4b0
+++ b/gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp
15e4b0
@@ -0,0 +1,141 @@
15e4b0
+# Copyright 2009-2017 Free Software Foundation, Inc.
15e4b0
+
15e4b0
+# This program is free software; you can redistribute it and/or modify
15e4b0
+# it under the terms of the GNU General Public License as published by
15e4b0
+# the Free Software Foundation; either version 3 of the License, or
15e4b0
+# (at your option) any later version.
15e4b0
+#
15e4b0
+# This program is distributed in the hope that it will be useful,
15e4b0
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
15e4b0
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15e4b0
+# GNU General Public License for more details.
15e4b0
+#
15e4b0
+# You should have received a copy of the GNU General Public License
15e4b0
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15e4b0
+
15e4b0
+# This file is part of the gdb testsuite.
15e4b0
+
15e4b0
+# Test displaced stepping over VEX-encoded RIP-relative AVX
15e4b0
+# instructions.
15e4b0
+
15e4b0
+if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
15e4b0
+    verbose "Skipping x86_64 displaced stepping tests."
15e4b0
+    return
15e4b0
+}
15e4b0
+
15e4b0
+standard_testfile .S
15e4b0
+
15e4b0
+set additional_flags "-Wa,-g"
15e4b0
+
15e4b0
+if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \
15e4b0
+	  [list debug $additional_flags]] } {
15e4b0
+    return -1
15e4b0
+}
15e4b0
+
15e4b0
+# Get things started.
15e4b0
+
15e4b0
+gdb_test "set displaced-stepping on" ""
15e4b0
+gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"
15e4b0
+
15e4b0
+if ![runto_main] then {
15e4b0
+    fail "can't run to main"
15e4b0
+    return 0
15e4b0
+}
15e4b0
+
15e4b0
+# GDB picks a spare register from this list to hold the RIP-relative
15e4b0
+# address.
15e4b0
+set rip_regs { "rax" "rbx" "rcx" "rdx" "rbp" "rsi" "rdi" }
15e4b0
+
15e4b0
+# Assign VAL to all the RIP_REGS.
15e4b0
+
15e4b0
+proc set_regs { val } {
15e4b0
+    global gdb_prompt
15e4b0
+    global rip_regs
15e4b0
+
15e4b0
+    foreach reg ${rip_regs} {
15e4b0
+	gdb_test_no_output "set \$${reg} = ${val}"
15e4b0
+    }
15e4b0
+}
15e4b0
+
15e4b0
+# Verify all RIP_REGS print as HEX_VAL_RE in hex.
15e4b0
+
15e4b0
+proc verify_regs { hex_val_re } {
15e4b0
+    global rip_regs
15e4b0
+
15e4b0
+    foreach reg ${rip_regs} {
15e4b0
+	gdb_test "p /x \$${reg}" " = ${hex_val_re}" "${reg} expected value"
15e4b0
+    }
15e4b0
+}
15e4b0
+
15e4b0
+# Set a break at FUNC, which starts with a RIP-relative instruction
15e4b0
+# that we want to displaced-step over, and then continue over the
15e4b0
+# breakpoint, forcing a displaced-stepping sequence.
15e4b0
+
15e4b0
+proc disp_step_func { func } {
15e4b0
+    global srcfile
15e4b0
+
15e4b0
+    set test_start_label "${func}"
15e4b0
+    set test_end_label "${func}_end"
15e4b0
+
15e4b0
+    gdb_test "break ${test_start_label}" \
15e4b0
+	"Breakpoint.*at.* file .*$srcfile, line.*" \
15e4b0
+	"break ${test_start_label}"
15e4b0
+    gdb_test "break ${test_end_label}" \
15e4b0
+	"Breakpoint.*at.* file .*$srcfile, line.*" \
15e4b0
+	"break ${test_end_label}"
15e4b0
+
15e4b0
+    gdb_test "continue" \
15e4b0
+	"Continuing.*Breakpoint.*, ${test_start_label} ().*" \
15e4b0
+	"continue to ${test_start_label}"
15e4b0
+
15e4b0
+    # GDB picks a spare register to hold the RIP-relative address.
15e4b0
+    # Ensure the spare register value is restored properly (rax-rdi,
15e4b0
+    # sans rsp).
15e4b0
+    set value "0xdeadbeefd3adb33f"
15e4b0
+    set_regs $value
15e4b0
+
15e4b0
+    gdb_test "continue" \
15e4b0
+	"Continuing.*Breakpoint.*, ${test_end_label} ().*" \
15e4b0
+	"continue to ${test_end_label}"
15e4b0
+
15e4b0
+    verify_regs $value
15e4b0
+}
15e4b0
+
15e4b0
+# Test a VEX2-encoded RIP-relative instruction.
15e4b0
+with_test_prefix "vex2" {
15e4b0
+    # This case writes to the 'xmm0' register.  Confirm the register's
15e4b0
+    # value is what we believe it is before the AVX instruction runs.
15e4b0
+    # Fedora: 0* for missing: https://sourceware.org/bugzilla/show_bug.cgi?id=16225
15e4b0
+    gdb_test "p /x \$xmm0.uint128" " = 0x00*" \
15e4b0
+	"xmm0 has expected value before"
15e4b0
+
15e4b0
+    disp_step_func "test_rip_vex2"
15e4b0
+
15e4b0
+    # Confirm the instruction's expected side effects.  It should have
15e4b0
+    # modified xmm0.
15e4b0
+    # Fedora: 0* for missing: https://sourceware.org/bugzilla/show_bug.cgi?id=16225
15e4b0
+    gdb_test "p /x \$xmm0.uint128" " = 0x0*1122334455667788" \
15e4b0
+	"xmm0 has expected value after"
15e4b0
+}
15e4b0
+
15e4b0
+# Test a VEX3-encoded RIP-relative instruction.
15e4b0
+with_test_prefix "vex3" {
15e4b0
+    # This case writes to the 'var128' variable.  Confirm the
15e4b0
+    # variable's value is what we believe it is before the AVX
15e4b0
+    # instruction runs.
15e4b0
+    gdb_test "p /x (unsigned long long \[2\]) var128" \
15e4b0
+	" = \\{0xaa55aa55aa55aa55, 0x55aa55aa55aa55aa\\}" \
15e4b0
+	"var128 has expected value before"
15e4b0
+
15e4b0
+    # Run the AVX instruction.
15e4b0
+    disp_step_func "test_rip_vex3"
15e4b0
+
15e4b0
+    # Confirm the instruction's expected side effects.  It should have
15e4b0
+    # modifed the 'var128' variable.
15e4b0
+    gdb_test "p /x (unsigned long long \[2\]) var128" \
15e4b0
+	" = \\{0x1122334455667788, 0x0\\}" \
15e4b0
+	"var128 has expected value after"
15e4b0
+}
15e4b0
+
15e4b0
+# Done, run program to exit.
15e4b0
+gdb_continue_to_end "amd64-disp-step-avx"