Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA/commit 1/2] Regenerate the features/i386 target description .c files
  2012-05-01 23:04 Invalid segment resister value on x86_64-windows Joel Brobecker
@ 2012-05-01 23:04 ` Joel Brobecker
  2012-05-02  6:34   ` Sergio Durigan Junior
  2012-05-01 23:05 ` [RFA 2/2] [x86/x86_64] Segment registers are 16 bits long (not 32bits) Joel Brobecker
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 15+ messages in thread
From: Joel Brobecker @ 2012-05-01 23:04 UTC (permalink / raw)
  To: gdb-patches; +Cc: Joel Brobecker

There's been a minor change in the code generator that affects
how a couple of local variables are being declared.  This patch
regenerates the .c files in features/i386 to bring them up to
date.

gdb/ChangeLog:

	* features/i386/amd64-avx-linux.c, features/i386/amd64-avx.c,
	features/i386/amd64-linux.c, features/i386/amd64.c,
	features/i386/i386-avx-linux.c, features/i386/i386-avx.c,
	features/i386/i386-linux.c, features/i386/i386-mmx-linux.c,
	features/i386/i386.c, features/i386/x32-avx-linux.c,
	features/i386/x32-avx.c, features/i386/x32-linux.c,
	features/i386/x32.c: Regenerate.

Will commit in a day or two pending comments.

---
 gdb/features/i386/amd64-avx-linux.c |    3 ++-
 gdb/features/i386/amd64-avx.c       |    3 ++-
 gdb/features/i386/amd64-linux.c     |    3 ++-
 gdb/features/i386/amd64.c           |    3 ++-
 gdb/features/i386/i386-avx-linux.c  |    3 ++-
 gdb/features/i386/i386-avx.c        |    3 ++-
 gdb/features/i386/i386-linux.c      |    3 ++-
 gdb/features/i386/i386-mmx-linux.c  |    2 +-
 gdb/features/i386/i386.c            |    3 ++-
 gdb/features/i386/x32-avx-linux.c   |    3 ++-
 gdb/features/i386/x32-avx.c         |    3 ++-
 gdb/features/i386/x32-linux.c       |    3 ++-
 gdb/features/i386/x32.c             |    3 ++-
 13 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/gdb/features/i386/amd64-avx-linux.c b/gdb/features/i386/amd64-avx-linux.c
index 73392d3..81e8ca7 100644
--- a/gdb/features/i386/amd64-avx-linux.c
+++ b/gdb/features/i386/amd64-avx-linux.c
@@ -10,7 +10,8 @@ initialize_tdesc_amd64_avx_linux (void)
 {
   struct target_desc *result = allocate_target_description ();
   struct tdesc_feature *feature;
-  struct tdesc_type *field_type, *type;
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
 
   set_tdesc_architecture (result, bfd_scan_arch ("i386:x86-64"));
 
diff --git a/gdb/features/i386/amd64-avx.c b/gdb/features/i386/amd64-avx.c
index 05c60ff..d69d427 100644
--- a/gdb/features/i386/amd64-avx.c
+++ b/gdb/features/i386/amd64-avx.c
@@ -10,7 +10,8 @@ initialize_tdesc_amd64_avx (void)
 {
   struct target_desc *result = allocate_target_description ();
   struct tdesc_feature *feature;
-  struct tdesc_type *field_type, *type;
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
 
   set_tdesc_architecture (result, bfd_scan_arch ("i386:x86-64"));
 
diff --git a/gdb/features/i386/amd64-linux.c b/gdb/features/i386/amd64-linux.c
index 71efcbe..db97118 100644
--- a/gdb/features/i386/amd64-linux.c
+++ b/gdb/features/i386/amd64-linux.c
@@ -10,7 +10,8 @@ initialize_tdesc_amd64_linux (void)
 {
   struct target_desc *result = allocate_target_description ();
   struct tdesc_feature *feature;
-  struct tdesc_type *field_type, *type;
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
 
   set_tdesc_architecture (result, bfd_scan_arch ("i386:x86-64"));
 
diff --git a/gdb/features/i386/amd64.c b/gdb/features/i386/amd64.c
index 154e8df..951b36d 100644
--- a/gdb/features/i386/amd64.c
+++ b/gdb/features/i386/amd64.c
@@ -10,7 +10,8 @@ initialize_tdesc_amd64 (void)
 {
   struct target_desc *result = allocate_target_description ();
   struct tdesc_feature *feature;
-  struct tdesc_type *field_type, *type;
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
 
   set_tdesc_architecture (result, bfd_scan_arch ("i386:x86-64"));
 
diff --git a/gdb/features/i386/i386-avx-linux.c b/gdb/features/i386/i386-avx-linux.c
index 1aa939b..038073e 100644
--- a/gdb/features/i386/i386-avx-linux.c
+++ b/gdb/features/i386/i386-avx-linux.c
@@ -10,7 +10,8 @@ initialize_tdesc_i386_avx_linux (void)
 {
   struct target_desc *result = allocate_target_description ();
   struct tdesc_feature *feature;
-  struct tdesc_type *field_type, *type;
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
 
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
diff --git a/gdb/features/i386/i386-avx.c b/gdb/features/i386/i386-avx.c
index 1e74ed5..cdfebf8 100644
--- a/gdb/features/i386/i386-avx.c
+++ b/gdb/features/i386/i386-avx.c
@@ -10,7 +10,8 @@ initialize_tdesc_i386_avx (void)
 {
   struct target_desc *result = allocate_target_description ();
   struct tdesc_feature *feature;
-  struct tdesc_type *field_type, *type;
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
 
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
diff --git a/gdb/features/i386/i386-linux.c b/gdb/features/i386/i386-linux.c
index cc1fb99..cdc41a8 100644
--- a/gdb/features/i386/i386-linux.c
+++ b/gdb/features/i386/i386-linux.c
@@ -10,7 +10,8 @@ initialize_tdesc_i386_linux (void)
 {
   struct target_desc *result = allocate_target_description ();
   struct tdesc_feature *feature;
-  struct tdesc_type *field_type, *type;
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
 
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
diff --git a/gdb/features/i386/i386-mmx-linux.c b/gdb/features/i386/i386-mmx-linux.c
index 364ade4..872826a 100644
--- a/gdb/features/i386/i386-mmx-linux.c
+++ b/gdb/features/i386/i386-mmx-linux.c
@@ -10,7 +10,7 @@ initialize_tdesc_i386_mmx_linux (void)
 {
   struct target_desc *result = allocate_target_description ();
   struct tdesc_feature *feature;
-  struct tdesc_type *field_type, *type;
+  struct tdesc_type *field_type;
 
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
diff --git a/gdb/features/i386/i386.c b/gdb/features/i386/i386.c
index 7f7beb3..b1de96f 100644
--- a/gdb/features/i386/i386.c
+++ b/gdb/features/i386/i386.c
@@ -10,7 +10,8 @@ initialize_tdesc_i386 (void)
 {
   struct target_desc *result = allocate_target_description ();
   struct tdesc_feature *feature;
-  struct tdesc_type *field_type, *type;
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
 
   set_tdesc_architecture (result, bfd_scan_arch ("i386"));
 
diff --git a/gdb/features/i386/x32-avx-linux.c b/gdb/features/i386/x32-avx-linux.c
index d2e5ce9..b01013a 100644
--- a/gdb/features/i386/x32-avx-linux.c
+++ b/gdb/features/i386/x32-avx-linux.c
@@ -10,7 +10,8 @@ initialize_tdesc_x32_avx_linux (void)
 {
   struct target_desc *result = allocate_target_description ();
   struct tdesc_feature *feature;
-  struct tdesc_type *field_type, *type;
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
 
   set_tdesc_architecture (result, bfd_scan_arch ("i386:x64-32"));
 
diff --git a/gdb/features/i386/x32-avx.c b/gdb/features/i386/x32-avx.c
index 47d7305..af235cd 100644
--- a/gdb/features/i386/x32-avx.c
+++ b/gdb/features/i386/x32-avx.c
@@ -10,7 +10,8 @@ initialize_tdesc_x32_avx (void)
 {
   struct target_desc *result = allocate_target_description ();
   struct tdesc_feature *feature;
-  struct tdesc_type *field_type, *type;
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
 
   set_tdesc_architecture (result, bfd_scan_arch ("i386:x64-32"));
 
diff --git a/gdb/features/i386/x32-linux.c b/gdb/features/i386/x32-linux.c
index b42287d..d34a2a9 100644
--- a/gdb/features/i386/x32-linux.c
+++ b/gdb/features/i386/x32-linux.c
@@ -10,7 +10,8 @@ initialize_tdesc_x32_linux (void)
 {
   struct target_desc *result = allocate_target_description ();
   struct tdesc_feature *feature;
-  struct tdesc_type *field_type, *type;
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
 
   set_tdesc_architecture (result, bfd_scan_arch ("i386:x64-32"));
 
diff --git a/gdb/features/i386/x32.c b/gdb/features/i386/x32.c
index 6342ddd..755ec69 100644
--- a/gdb/features/i386/x32.c
+++ b/gdb/features/i386/x32.c
@@ -10,7 +10,8 @@ initialize_tdesc_x32 (void)
 {
   struct target_desc *result = allocate_target_description ();
   struct tdesc_feature *feature;
-  struct tdesc_type *field_type, *type;
+  struct tdesc_type *field_type;
+  struct tdesc_type *type;
 
   set_tdesc_architecture (result, bfd_scan_arch ("i386:x64-32"));
 
-- 
1.7.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Invalid segment resister value on x86_64-windows
@ 2012-05-01 23:04 Joel Brobecker
  2012-05-01 23:04 ` [RFA/commit 1/2] Regenerate the features/i386 target description .c files Joel Brobecker
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Joel Brobecker @ 2012-05-01 23:04 UTC (permalink / raw)
  To: gdb-patches

Hello,

One of our customers noticed that GDB was displaying invalid values
for the ss & gs register.  It's obviously invalid because the value
was wider than the registers' size (16 bits). I noticed that the XML
files define these register as being 32bit, which I am assuming was
an oversight (?).

As a result of the 32bit size, GDB was reading the value of these
registers as 4 bytes, instead of just 2. On GNU/Linux, I did not
check the kernel sources, but it appears that it was harmless,
because the extra bytes were always zero. But on some Windows
systems, we werent' that lucky.  The extra 2 bytes were not null,
and thus we ended up with a polluted value.

This patch series first regenerates the .c files in features/i386,
because I noticed a difference between the current files and the
generated version.  And the second patch changes the size of all
segment registers to match the size found in the various reference
manuals.

The series was tested on x86_64-linux, standalone and then with
gdbserver. I also checked by hand that the new GDB is still able
to work with an older GDBserver (thanks to the fact that GDBserver
sends the target description to GDB). And I also tested this patch
on x86_64-windows, using AdaCore's testsuite.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [RFA 2/2] [x86/x86_64] Segment registers are 16 bits long (not 32bits)
  2012-05-01 23:04 Invalid segment resister value on x86_64-windows Joel Brobecker
  2012-05-01 23:04 ` [RFA/commit 1/2] Regenerate the features/i386 target description .c files Joel Brobecker
@ 2012-05-01 23:05 ` Joel Brobecker
  2012-05-02  0:01 ` [RFA 3/2(+)] Test size of x86/x86_64 segment registers Joel Brobecker
  2012-05-02 10:10 ` Invalid segment resister value on x86_64-windows Mark Kettenis
  3 siblings, 0 replies; 15+ messages in thread
From: Joel Brobecker @ 2012-05-01 23:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Joel Brobecker

This patch changes the description of all segment registers for
x86 and x86_64 targets to 16 bits. On GNU/Linux systems, this
discrepancy appears to be harmless. But, on some Windows systems,
the wider size lead us to read the value of those registers as
4-byte values instead of 2 bytes values, resulting in incorrect
results.

gdb/changeLog:

	* features/i386/32bit-core.xml, features/i386/64bit-core.xml,
	features/i386/x32-core.xml: Set bitsize and type of all
	segment registers to 16 and "int16" respectively.
	* features/i386/amd64-avx-linux.c, features/i386/amd64-avx.c,
	features/i386/amd64-linux.c, features/i386/amd64.c,
	features/i386/i386-avx-linux.c, features/i386/i386-avx.c,
	features/i386/i386-linux.c, features/i386/i386-mmx-linux.c,
	features/i386/i386-mmx.c, features/i386/i386.c,
	features/i386/x32-avx-linux.c, features/i386/x32-avx.c,
	features/i386/x32-linux.c, features/i386/x32.c: Regenerate.
	* regformats/i386/amd64-avx-linux.dat, regformats/i386/amd64-avx.dat,
	regformats/i386/amd64-linux.dat, regformats/i386/amd64.dat,
	regformats/i386/i386-avx-linux.dat, regformats/i386/i386-avx.dat,
	regformats/i386/i386-linux.dat, regformats/i386/i386-mmx-linux.dat,
	regformats/i386/i386-mmx.dat, regformats/i386/i386.dat,
	regformats/i386/x32-avx-linux.dat, regformats/i386/x32-avx.dat,
	regformats/i386/x32-linux.dat, regformats/i386/x32.dat: Regenerate.

OK to commit?

Thanks,
-- 
Joel

---
 gdb/features/i386/32bit-core.xml        |   12 ++++++------
 gdb/features/i386/64bit-core.xml        |   12 ++++++------
 gdb/features/i386/amd64-avx-linux.c     |   12 ++++++------
 gdb/features/i386/amd64-avx.c           |   12 ++++++------
 gdb/features/i386/amd64-linux.c         |   12 ++++++------
 gdb/features/i386/amd64.c               |   12 ++++++------
 gdb/features/i386/i386-avx-linux.c      |   12 ++++++------
 gdb/features/i386/i386-avx.c            |   12 ++++++------
 gdb/features/i386/i386-linux.c          |   12 ++++++------
 gdb/features/i386/i386-mmx-linux.c      |   12 ++++++------
 gdb/features/i386/i386-mmx.c            |   12 ++++++------
 gdb/features/i386/i386.c                |   12 ++++++------
 gdb/features/i386/x32-avx-linux.c       |   12 ++++++------
 gdb/features/i386/x32-avx.c             |   12 ++++++------
 gdb/features/i386/x32-core.xml          |   12 ++++++------
 gdb/features/i386/x32-linux.c           |   12 ++++++------
 gdb/features/i386/x32.c                 |   12 ++++++------
 gdb/regformats/i386/amd64-avx-linux.dat |   12 ++++++------
 gdb/regformats/i386/amd64-avx.dat       |   12 ++++++------
 gdb/regformats/i386/amd64-linux.dat     |   12 ++++++------
 gdb/regformats/i386/amd64.dat           |   12 ++++++------
 gdb/regformats/i386/i386-avx-linux.dat  |   12 ++++++------
 gdb/regformats/i386/i386-avx.dat        |   12 ++++++------
 gdb/regformats/i386/i386-linux.dat      |   12 ++++++------
 gdb/regformats/i386/i386-mmx-linux.dat  |   12 ++++++------
 gdb/regformats/i386/i386-mmx.dat        |   12 ++++++------
 gdb/regformats/i386/i386.dat            |   12 ++++++------
 gdb/regformats/i386/x32-avx-linux.dat   |   12 ++++++------
 gdb/regformats/i386/x32-avx.dat         |   12 ++++++------
 gdb/regformats/i386/x32-linux.dat       |   12 ++++++------
 gdb/regformats/i386/x32.dat             |   12 ++++++------
 31 files changed, 186 insertions(+), 186 deletions(-)

diff --git a/gdb/features/i386/32bit-core.xml b/gdb/features/i386/32bit-core.xml
index e7742ef..5912504 100644
--- a/gdb/features/i386/32bit-core.xml
+++ b/gdb/features/i386/32bit-core.xml
@@ -38,12 +38,12 @@
 
   <reg name="eip" bitsize="32" type="code_ptr"/>
   <reg name="eflags" bitsize="32" type="i386_eflags"/>
-  <reg name="cs" bitsize="32" type="int32"/>
-  <reg name="ss" bitsize="32" type="int32"/>
-  <reg name="ds" bitsize="32" type="int32"/>
-  <reg name="es" bitsize="32" type="int32"/>
-  <reg name="fs" bitsize="32" type="int32"/>
-  <reg name="gs" bitsize="32" type="int32"/>
+  <reg name="cs" bitsize="16" type="int16"/>
+  <reg name="ss" bitsize="16" type="int16"/>
+  <reg name="ds" bitsize="16" type="int16"/>
+  <reg name="es" bitsize="16" type="int16"/>
+  <reg name="fs" bitsize="16" type="int16"/>
+  <reg name="gs" bitsize="16" type="int16"/>
 
   <reg name="st0" bitsize="80" type="i387_ext"/>
   <reg name="st1" bitsize="80" type="i387_ext"/>
diff --git a/gdb/features/i386/64bit-core.xml b/gdb/features/i386/64bit-core.xml
index 6dd6cdb..1380ec1 100644
--- a/gdb/features/i386/64bit-core.xml
+++ b/gdb/features/i386/64bit-core.xml
@@ -46,12 +46,12 @@
 
   <reg name="rip" bitsize="64" type="code_ptr"/>
   <reg name="eflags" bitsize="32" type="i386_eflags"/>
-  <reg name="cs" bitsize="32" type="int32"/>
-  <reg name="ss" bitsize="32" type="int32"/>
-  <reg name="ds" bitsize="32" type="int32"/>
-  <reg name="es" bitsize="32" type="int32"/>
-  <reg name="fs" bitsize="32" type="int32"/>
-  <reg name="gs" bitsize="32" type="int32"/>
+  <reg name="cs" bitsize="16" type="int16"/>
+  <reg name="ss" bitsize="16" type="int16"/>
+  <reg name="ds" bitsize="16" type="int16"/>
+  <reg name="es" bitsize="16" type="int16"/>
+  <reg name="fs" bitsize="16" type="int16"/>
+  <reg name="gs" bitsize="16" type="int16"/>
 
   <reg name="st0" bitsize="80" type="i387_ext"/>
   <reg name="st1" bitsize="80" type="i387_ext"/>
diff --git a/gdb/features/i386/amd64-avx-linux.c b/gdb/features/i386/amd64-avx-linux.c
index 81e8ca7..b799e49 100644
--- a/gdb/features/i386/amd64-avx-linux.c
+++ b/gdb/features/i386/amd64-avx-linux.c
@@ -55,12 +55,12 @@ initialize_tdesc_amd64_avx_linux (void)
   tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
   tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "code_ptr");
   tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "cs", 18, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ss", 19, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ds", 20, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "es", 21, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "fs", 22, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "gs", 23, 1, NULL, 16, "int16");
   tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
diff --git a/gdb/features/i386/amd64-avx.c b/gdb/features/i386/amd64-avx.c
index d69d427..96b2ec3 100644
--- a/gdb/features/i386/amd64-avx.c
+++ b/gdb/features/i386/amd64-avx.c
@@ -53,12 +53,12 @@ initialize_tdesc_amd64_avx (void)
   tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
   tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "code_ptr");
   tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "cs", 18, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ss", 19, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ds", 20, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "es", 21, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "fs", 22, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "gs", 23, 1, NULL, 16, "int16");
   tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
diff --git a/gdb/features/i386/amd64-linux.c b/gdb/features/i386/amd64-linux.c
index db97118..bf9bb49 100644
--- a/gdb/features/i386/amd64-linux.c
+++ b/gdb/features/i386/amd64-linux.c
@@ -55,12 +55,12 @@ initialize_tdesc_amd64_linux (void)
   tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
   tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "code_ptr");
   tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "cs", 18, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ss", 19, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ds", 20, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "es", 21, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "fs", 22, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "gs", 23, 1, NULL, 16, "int16");
   tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
diff --git a/gdb/features/i386/amd64.c b/gdb/features/i386/amd64.c
index 951b36d..4aa2b12 100644
--- a/gdb/features/i386/amd64.c
+++ b/gdb/features/i386/amd64.c
@@ -53,12 +53,12 @@ initialize_tdesc_amd64 (void)
   tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
   tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "code_ptr");
   tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "cs", 18, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ss", 19, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ds", 20, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "es", 21, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "fs", 22, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "gs", 23, 1, NULL, 16, "int16");
   tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
diff --git a/gdb/features/i386/i386-avx-linux.c b/gdb/features/i386/i386-avx-linux.c
index 038073e..cae4f0b 100644
--- a/gdb/features/i386/i386-avx-linux.c
+++ b/gdb/features/i386/i386-avx-linux.c
@@ -47,12 +47,12 @@ initialize_tdesc_i386_avx_linux (void)
   tdesc_create_reg (feature, "edi", 7, 1, NULL, 32, "int32");
   tdesc_create_reg (feature, "eip", 8, 1, NULL, 32, "code_ptr");
   tdesc_create_reg (feature, "eflags", 9, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 10, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 11, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 12, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 13, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 14, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 15, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "cs", 10, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ss", 11, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ds", 12, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "es", 13, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "fs", 14, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "gs", 15, 1, NULL, 16, "int16");
   tdesc_create_reg (feature, "st0", 16, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st1", 17, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st2", 18, 1, NULL, 80, "i387_ext");
diff --git a/gdb/features/i386/i386-avx.c b/gdb/features/i386/i386-avx.c
index cdfebf8..bb3ba86 100644
--- a/gdb/features/i386/i386-avx.c
+++ b/gdb/features/i386/i386-avx.c
@@ -45,12 +45,12 @@ initialize_tdesc_i386_avx (void)
   tdesc_create_reg (feature, "edi", 7, 1, NULL, 32, "int32");
   tdesc_create_reg (feature, "eip", 8, 1, NULL, 32, "code_ptr");
   tdesc_create_reg (feature, "eflags", 9, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 10, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 11, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 12, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 13, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 14, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 15, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "cs", 10, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ss", 11, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ds", 12, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "es", 13, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "fs", 14, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "gs", 15, 1, NULL, 16, "int16");
   tdesc_create_reg (feature, "st0", 16, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st1", 17, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st2", 18, 1, NULL, 80, "i387_ext");
diff --git a/gdb/features/i386/i386-linux.c b/gdb/features/i386/i386-linux.c
index cdc41a8..c6a47ad 100644
--- a/gdb/features/i386/i386-linux.c
+++ b/gdb/features/i386/i386-linux.c
@@ -47,12 +47,12 @@ initialize_tdesc_i386_linux (void)
   tdesc_create_reg (feature, "edi", 7, 1, NULL, 32, "int32");
   tdesc_create_reg (feature, "eip", 8, 1, NULL, 32, "code_ptr");
   tdesc_create_reg (feature, "eflags", 9, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 10, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 11, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 12, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 13, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 14, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 15, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "cs", 10, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ss", 11, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ds", 12, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "es", 13, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "fs", 14, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "gs", 15, 1, NULL, 16, "int16");
   tdesc_create_reg (feature, "st0", 16, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st1", 17, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st2", 18, 1, NULL, 80, "i387_ext");
diff --git a/gdb/features/i386/i386-mmx-linux.c b/gdb/features/i386/i386-mmx-linux.c
index 872826a..dc3bdc3 100644
--- a/gdb/features/i386/i386-mmx-linux.c
+++ b/gdb/features/i386/i386-mmx-linux.c
@@ -46,12 +46,12 @@ initialize_tdesc_i386_mmx_linux (void)
   tdesc_create_reg (feature, "edi", 7, 1, NULL, 32, "int32");
   tdesc_create_reg (feature, "eip", 8, 1, NULL, 32, "code_ptr");
   tdesc_create_reg (feature, "eflags", 9, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 10, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 11, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 12, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 13, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 14, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 15, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "cs", 10, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ss", 11, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ds", 12, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "es", 13, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "fs", 14, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "gs", 15, 1, NULL, 16, "int16");
   tdesc_create_reg (feature, "st0", 16, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st1", 17, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st2", 18, 1, NULL, 80, "i387_ext");
diff --git a/gdb/features/i386/i386-mmx.c b/gdb/features/i386/i386-mmx.c
index 7ca2467..7710f7b 100644
--- a/gdb/features/i386/i386-mmx.c
+++ b/gdb/features/i386/i386-mmx.c
@@ -44,12 +44,12 @@ initialize_tdesc_i386_mmx (void)
   tdesc_create_reg (feature, "edi", 7, 1, NULL, 32, "int32");
   tdesc_create_reg (feature, "eip", 8, 1, NULL, 32, "code_ptr");
   tdesc_create_reg (feature, "eflags", 9, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 10, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 11, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 12, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 13, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 14, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 15, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "cs", 10, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ss", 11, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ds", 12, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "es", 13, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "fs", 14, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "gs", 15, 1, NULL, 16, "int16");
   tdesc_create_reg (feature, "st0", 16, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st1", 17, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st2", 18, 1, NULL, 80, "i387_ext");
diff --git a/gdb/features/i386/i386.c b/gdb/features/i386/i386.c
index b1de96f..0befb45 100644
--- a/gdb/features/i386/i386.c
+++ b/gdb/features/i386/i386.c
@@ -45,12 +45,12 @@ initialize_tdesc_i386 (void)
   tdesc_create_reg (feature, "edi", 7, 1, NULL, 32, "int32");
   tdesc_create_reg (feature, "eip", 8, 1, NULL, 32, "code_ptr");
   tdesc_create_reg (feature, "eflags", 9, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 10, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 11, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 12, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 13, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 14, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 15, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "cs", 10, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ss", 11, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ds", 12, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "es", 13, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "fs", 14, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "gs", 15, 1, NULL, 16, "int16");
   tdesc_create_reg (feature, "st0", 16, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st1", 17, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st2", 18, 1, NULL, 80, "i387_ext");
diff --git a/gdb/features/i386/x32-avx-linux.c b/gdb/features/i386/x32-avx-linux.c
index b01013a..5a6edf1 100644
--- a/gdb/features/i386/x32-avx-linux.c
+++ b/gdb/features/i386/x32-avx-linux.c
@@ -55,12 +55,12 @@ initialize_tdesc_x32_avx_linux (void)
   tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
   tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "uint64");
   tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "cs", 18, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ss", 19, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ds", 20, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "es", 21, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "fs", 22, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "gs", 23, 1, NULL, 16, "int16");
   tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
diff --git a/gdb/features/i386/x32-avx.c b/gdb/features/i386/x32-avx.c
index af235cd..a3d01e1 100644
--- a/gdb/features/i386/x32-avx.c
+++ b/gdb/features/i386/x32-avx.c
@@ -53,12 +53,12 @@ initialize_tdesc_x32_avx (void)
   tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
   tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "uint64");
   tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "cs", 18, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ss", 19, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ds", 20, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "es", 21, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "fs", 22, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "gs", 23, 1, NULL, 16, "int16");
   tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
diff --git a/gdb/features/i386/x32-core.xml b/gdb/features/i386/x32-core.xml
index 1e41417..bb64fd6 100644
--- a/gdb/features/i386/x32-core.xml
+++ b/gdb/features/i386/x32-core.xml
@@ -46,12 +46,12 @@
 
   <reg name="rip" bitsize="64" type="uint64"/>
   <reg name="eflags" bitsize="32" type="i386_eflags"/>
-  <reg name="cs" bitsize="32" type="int32"/>
-  <reg name="ss" bitsize="32" type="int32"/>
-  <reg name="ds" bitsize="32" type="int32"/>
-  <reg name="es" bitsize="32" type="int32"/>
-  <reg name="fs" bitsize="32" type="int32"/>
-  <reg name="gs" bitsize="32" type="int32"/>
+  <reg name="cs" bitsize="16" type="int16"/>
+  <reg name="ss" bitsize="16" type="int16"/>
+  <reg name="ds" bitsize="16" type="int16"/>
+  <reg name="es" bitsize="16" type="int16"/>
+  <reg name="fs" bitsize="16" type="int16"/>
+  <reg name="gs" bitsize="16" type="int16"/>
 
   <reg name="st0" bitsize="80" type="i387_ext"/>
   <reg name="st1" bitsize="80" type="i387_ext"/>
diff --git a/gdb/features/i386/x32-linux.c b/gdb/features/i386/x32-linux.c
index d34a2a9..e74b41c 100644
--- a/gdb/features/i386/x32-linux.c
+++ b/gdb/features/i386/x32-linux.c
@@ -55,12 +55,12 @@ initialize_tdesc_x32_linux (void)
   tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
   tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "uint64");
   tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "cs", 18, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ss", 19, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ds", 20, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "es", 21, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "fs", 22, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "gs", 23, 1, NULL, 16, "int16");
   tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
diff --git a/gdb/features/i386/x32.c b/gdb/features/i386/x32.c
index 755ec69..8e5cbd8 100644
--- a/gdb/features/i386/x32.c
+++ b/gdb/features/i386/x32.c
@@ -53,12 +53,12 @@ initialize_tdesc_x32 (void)
   tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "int64");
   tdesc_create_reg (feature, "rip", 16, 1, NULL, 64, "uint64");
   tdesc_create_reg (feature, "eflags", 17, 1, NULL, 32, "i386_eflags");
-  tdesc_create_reg (feature, "cs", 18, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ss", 19, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "ds", 20, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "es", 21, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "fs", 22, 1, NULL, 32, "int32");
-  tdesc_create_reg (feature, "gs", 23, 1, NULL, 32, "int32");
+  tdesc_create_reg (feature, "cs", 18, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ss", 19, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "ds", 20, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "es", 21, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "fs", 22, 1, NULL, 16, "int16");
+  tdesc_create_reg (feature, "gs", 23, 1, NULL, 16, "int16");
   tdesc_create_reg (feature, "st0", 24, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st1", 25, 1, NULL, 80, "i387_ext");
   tdesc_create_reg (feature, "st2", 26, 1, NULL, 80, "i387_ext");
diff --git a/gdb/regformats/i386/amd64-avx-linux.dat b/gdb/regformats/i386/amd64-avx-linux.dat
index 4491313..ded0117 100644
--- a/gdb/regformats/i386/amd64-avx-linux.dat
+++ b/gdb/regformats/i386/amd64-avx-linux.dat
@@ -20,12 +20,12 @@ expedite:rbp,rsp,rip
 64:r15
 64:rip
 32:eflags
-32:cs
-32:ss
-32:ds
-32:es
-32:fs
-32:gs
+16:cs
+16:ss
+16:ds
+16:es
+16:fs
+16:gs
 80:st0
 80:st1
 80:st2
diff --git a/gdb/regformats/i386/amd64-avx.dat b/gdb/regformats/i386/amd64-avx.dat
index 62cfdd7..713d691 100644
--- a/gdb/regformats/i386/amd64-avx.dat
+++ b/gdb/regformats/i386/amd64-avx.dat
@@ -20,12 +20,12 @@ expedite:rbp,rsp,rip
 64:r15
 64:rip
 32:eflags
-32:cs
-32:ss
-32:ds
-32:es
-32:fs
-32:gs
+16:cs
+16:ss
+16:ds
+16:es
+16:fs
+16:gs
 80:st0
 80:st1
 80:st2
diff --git a/gdb/regformats/i386/amd64-linux.dat b/gdb/regformats/i386/amd64-linux.dat
index 02a2c78..fed8185 100644
--- a/gdb/regformats/i386/amd64-linux.dat
+++ b/gdb/regformats/i386/amd64-linux.dat
@@ -20,12 +20,12 @@ expedite:rbp,rsp,rip
 64:r15
 64:rip
 32:eflags
-32:cs
-32:ss
-32:ds
-32:es
-32:fs
-32:gs
+16:cs
+16:ss
+16:ds
+16:es
+16:fs
+16:gs
 80:st0
 80:st1
 80:st2
diff --git a/gdb/regformats/i386/amd64.dat b/gdb/regformats/i386/amd64.dat
index d589218..90f6005 100644
--- a/gdb/regformats/i386/amd64.dat
+++ b/gdb/regformats/i386/amd64.dat
@@ -20,12 +20,12 @@ expedite:rbp,rsp,rip
 64:r15
 64:rip
 32:eflags
-32:cs
-32:ss
-32:ds
-32:es
-32:fs
-32:gs
+16:cs
+16:ss
+16:ds
+16:es
+16:fs
+16:gs
 80:st0
 80:st1
 80:st2
diff --git a/gdb/regformats/i386/i386-avx-linux.dat b/gdb/regformats/i386/i386-avx-linux.dat
index e9eb951..a943ead 100644
--- a/gdb/regformats/i386/i386-avx-linux.dat
+++ b/gdb/regformats/i386/i386-avx-linux.dat
@@ -12,12 +12,12 @@ expedite:ebp,esp,eip
 32:edi
 32:eip
 32:eflags
-32:cs
-32:ss
-32:ds
-32:es
-32:fs
-32:gs
+16:cs
+16:ss
+16:ds
+16:es
+16:fs
+16:gs
 80:st0
 80:st1
 80:st2
diff --git a/gdb/regformats/i386/i386-avx.dat b/gdb/regformats/i386/i386-avx.dat
index 4a19a2b..aec41c5 100644
--- a/gdb/regformats/i386/i386-avx.dat
+++ b/gdb/regformats/i386/i386-avx.dat
@@ -12,12 +12,12 @@ expedite:ebp,esp,eip
 32:edi
 32:eip
 32:eflags
-32:cs
-32:ss
-32:ds
-32:es
-32:fs
-32:gs
+16:cs
+16:ss
+16:ds
+16:es
+16:fs
+16:gs
 80:st0
 80:st1
 80:st2
diff --git a/gdb/regformats/i386/i386-linux.dat b/gdb/regformats/i386/i386-linux.dat
index 6fef8d9..621870c 100644
--- a/gdb/regformats/i386/i386-linux.dat
+++ b/gdb/regformats/i386/i386-linux.dat
@@ -12,12 +12,12 @@ expedite:ebp,esp,eip
 32:edi
 32:eip
 32:eflags
-32:cs
-32:ss
-32:ds
-32:es
-32:fs
-32:gs
+16:cs
+16:ss
+16:ds
+16:es
+16:fs
+16:gs
 80:st0
 80:st1
 80:st2
diff --git a/gdb/regformats/i386/i386-mmx-linux.dat b/gdb/regformats/i386/i386-mmx-linux.dat
index 9dcf223..6de7dca 100644
--- a/gdb/regformats/i386/i386-mmx-linux.dat
+++ b/gdb/regformats/i386/i386-mmx-linux.dat
@@ -12,12 +12,12 @@ expedite:ebp,esp,eip
 32:edi
 32:eip
 32:eflags
-32:cs
-32:ss
-32:ds
-32:es
-32:fs
-32:gs
+16:cs
+16:ss
+16:ds
+16:es
+16:fs
+16:gs
 80:st0
 80:st1
 80:st2
diff --git a/gdb/regformats/i386/i386-mmx.dat b/gdb/regformats/i386/i386-mmx.dat
index 38a95d4..393e71a 100644
--- a/gdb/regformats/i386/i386-mmx.dat
+++ b/gdb/regformats/i386/i386-mmx.dat
@@ -12,12 +12,12 @@ expedite:ebp,esp,eip
 32:edi
 32:eip
 32:eflags
-32:cs
-32:ss
-32:ds
-32:es
-32:fs
-32:gs
+16:cs
+16:ss
+16:ds
+16:es
+16:fs
+16:gs
 80:st0
 80:st1
 80:st2
diff --git a/gdb/regformats/i386/i386.dat b/gdb/regformats/i386/i386.dat
index 923d879..5b2ae8a 100644
--- a/gdb/regformats/i386/i386.dat
+++ b/gdb/regformats/i386/i386.dat
@@ -12,12 +12,12 @@ expedite:ebp,esp,eip
 32:edi
 32:eip
 32:eflags
-32:cs
-32:ss
-32:ds
-32:es
-32:fs
-32:gs
+16:cs
+16:ss
+16:ds
+16:es
+16:fs
+16:gs
 80:st0
 80:st1
 80:st2
diff --git a/gdb/regformats/i386/x32-avx-linux.dat b/gdb/regformats/i386/x32-avx-linux.dat
index 1203806..8dc1122 100644
--- a/gdb/regformats/i386/x32-avx-linux.dat
+++ b/gdb/regformats/i386/x32-avx-linux.dat
@@ -20,12 +20,12 @@ expedite:rbp,rsp,rip
 64:r15
 64:rip
 32:eflags
-32:cs
-32:ss
-32:ds
-32:es
-32:fs
-32:gs
+16:cs
+16:ss
+16:ds
+16:es
+16:fs
+16:gs
 80:st0
 80:st1
 80:st2
diff --git a/gdb/regformats/i386/x32-avx.dat b/gdb/regformats/i386/x32-avx.dat
index f13bf28..fd8c8b3 100644
--- a/gdb/regformats/i386/x32-avx.dat
+++ b/gdb/regformats/i386/x32-avx.dat
@@ -20,12 +20,12 @@ expedite:rbp,rsp,rip
 64:r15
 64:rip
 32:eflags
-32:cs
-32:ss
-32:ds
-32:es
-32:fs
-32:gs
+16:cs
+16:ss
+16:ds
+16:es
+16:fs
+16:gs
 80:st0
 80:st1
 80:st2
diff --git a/gdb/regformats/i386/x32-linux.dat b/gdb/regformats/i386/x32-linux.dat
index 6eda64a..85c34c7 100644
--- a/gdb/regformats/i386/x32-linux.dat
+++ b/gdb/regformats/i386/x32-linux.dat
@@ -20,12 +20,12 @@ expedite:rbp,rsp,rip
 64:r15
 64:rip
 32:eflags
-32:cs
-32:ss
-32:ds
-32:es
-32:fs
-32:gs
+16:cs
+16:ss
+16:ds
+16:es
+16:fs
+16:gs
 80:st0
 80:st1
 80:st2
diff --git a/gdb/regformats/i386/x32.dat b/gdb/regformats/i386/x32.dat
index 6c63a8a..7ae7ac1 100644
--- a/gdb/regformats/i386/x32.dat
+++ b/gdb/regformats/i386/x32.dat
@@ -20,12 +20,12 @@ expedite:rbp,rsp,rip
 64:r15
 64:rip
 32:eflags
-32:cs
-32:ss
-32:ds
-32:es
-32:fs
-32:gs
+16:cs
+16:ss
+16:ds
+16:es
+16:fs
+16:gs
 80:st0
 80:st1
 80:st2
-- 
1.7.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [RFA 3/2(+)] Test size of x86/x86_64 segment registers
  2012-05-01 23:04 Invalid segment resister value on x86_64-windows Joel Brobecker
  2012-05-01 23:04 ` [RFA/commit 1/2] Regenerate the features/i386 target description .c files Joel Brobecker
  2012-05-01 23:05 ` [RFA 2/2] [x86/x86_64] Segment registers are 16 bits long (not 32bits) Joel Brobecker
@ 2012-05-02  0:01 ` Joel Brobecker
  2012-05-02 10:10 ` Invalid segment resister value on x86_64-windows Mark Kettenis
  3 siblings, 0 replies; 15+ messages in thread
From: Joel Brobecker @ 2012-05-02  0:01 UTC (permalink / raw)
  To: gdb-patches; +Cc: Joel Brobecker

(forgot to write a testcase)

Rather than verifying the value of the segment registers, which I think
would be tricky, one way to regression-test the problem is to verify
that the size of the segment registers is 2 bytes, rather than 4.

gdb/testsuite/ChangeLog:

        * gdb.arch/i386-segregs.c, gdb.arch/i386-segregs.exp: New files.

Tested on x86_64-linux.

---
 gdb/testsuite/gdb.arch/i386-segregs.c   |   22 +++++++++++++++++
 gdb/testsuite/gdb.arch/i386-segregs.exp |   39 +++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 0 deletions(-)
 create mode 100644 gdb/testsuite/gdb.arch/i386-segregs.c
 create mode 100644 gdb/testsuite/gdb.arch/i386-segregs.exp

diff --git a/gdb/testsuite/gdb.arch/i386-segregs.c b/gdb/testsuite/gdb.arch/i386-segregs.c
new file mode 100644
index 0000000..6fdc6f8
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/i386-segregs.c
@@ -0,0 +1,22 @@
+/* Copyright 2012 Free Software Foundation, Inc.
+
+   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/>.  */
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.arch/i386-segregs.exp b/gdb/testsuite/gdb.arch/i386-segregs.exp
new file mode 100644
index 0000000..58d1b13
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/i386-segregs.exp
@@ -0,0 +1,39 @@
+# Copyright 2012 Free Software Foundation, Inc.
+
+# 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/>.
+
+# This testcase is going to verify the handling of the x86/x86_64
+# segment registers.  Skip this test if the target CPU does not match.
+if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } then {
+    return 0
+}
+
+set testfile "i386-segregs"
+set srcfile ${testfile}.c
+
+if [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug $additional_flags}] {
+    untested "failed to compile ${testfile}"
+    return -1
+}
+
+if ![runto_main] then {
+    untested "could not run to main"
+    return -1
+}
+
+# Print the size of all segment registers.  It should always be 2.
+foreach reg_name {"cs" "ss" "ds" "es" "fs" "gs"} {
+    gdb_test "print sizeof \$$reg_name" "= 2"
+}
+
-- 
1.7.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFA/commit 1/2] Regenerate the features/i386 target description .c files
  2012-05-01 23:04 ` [RFA/commit 1/2] Regenerate the features/i386 target description .c files Joel Brobecker
@ 2012-05-02  6:34   ` Sergio Durigan Junior
  0 siblings, 0 replies; 15+ messages in thread
From: Sergio Durigan Junior @ 2012-05-02  6:34 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On Tuesday, May 01 2012, Joel Brobecker wrote:

> There's been a minor change in the code generator that affects
> how a couple of local variables are being declared.  This patch
> regenerates the .c files in features/i386 to bring them up to
> date.

Hi Joel,

Sorry, I only read your message after committing my patch to clean more
bits in the features/ directory.

    http://sourceware.org/ml/gdb-patches/2012-05/msg00010.html

Anyway, the only file my commit touched was `i386/i386-mmx-linux.c'.  If
it's not too much troube for you, I think you can remove this specific
diff from the patch, and apply the rest safely.

Thanks,

> gdb/ChangeLog:
>
> 	* features/i386/amd64-avx-linux.c, features/i386/amd64-avx.c,
> 	features/i386/amd64-linux.c, features/i386/amd64.c,
> 	features/i386/i386-avx-linux.c, features/i386/i386-avx.c,
> 	features/i386/i386-linux.c, features/i386/i386-mmx-linux.c,
> 	features/i386/i386.c, features/i386/x32-avx-linux.c,
> 	features/i386/x32-avx.c, features/i386/x32-linux.c,
> 	features/i386/x32.c: Regenerate.
>
> Will commit in a day or two pending comments.
>
> ---
>  gdb/features/i386/amd64-avx-linux.c |    3 ++-
>  gdb/features/i386/amd64-avx.c       |    3 ++-
>  gdb/features/i386/amd64-linux.c     |    3 ++-
>  gdb/features/i386/amd64.c           |    3 ++-
>  gdb/features/i386/i386-avx-linux.c  |    3 ++-
>  gdb/features/i386/i386-avx.c        |    3 ++-
>  gdb/features/i386/i386-linux.c      |    3 ++-
>  gdb/features/i386/i386-mmx-linux.c  |    2 +-
>  gdb/features/i386/i386.c            |    3 ++-
>  gdb/features/i386/x32-avx-linux.c   |    3 ++-
>  gdb/features/i386/x32-avx.c         |    3 ++-
>  gdb/features/i386/x32-linux.c       |    3 ++-
>  gdb/features/i386/x32.c             |    3 ++-
>  13 files changed, 25 insertions(+), 13 deletions(-)
>
> diff --git a/gdb/features/i386/amd64-avx-linux.c b/gdb/features/i386/amd64-avx-linux.c
> index 73392d3..81e8ca7 100644
> --- a/gdb/features/i386/amd64-avx-linux.c
> +++ b/gdb/features/i386/amd64-avx-linux.c
> @@ -10,7 +10,8 @@ initialize_tdesc_amd64_avx_linux (void)
>  {
>    struct target_desc *result = allocate_target_description ();
>    struct tdesc_feature *feature;
> -  struct tdesc_type *field_type, *type;
> +  struct tdesc_type *field_type;
> +  struct tdesc_type *type;
>  
>    set_tdesc_architecture (result, bfd_scan_arch ("i386:x86-64"));
>  
> diff --git a/gdb/features/i386/amd64-avx.c b/gdb/features/i386/amd64-avx.c
> index 05c60ff..d69d427 100644
> --- a/gdb/features/i386/amd64-avx.c
> +++ b/gdb/features/i386/amd64-avx.c
> @@ -10,7 +10,8 @@ initialize_tdesc_amd64_avx (void)
>  {
>    struct target_desc *result = allocate_target_description ();
>    struct tdesc_feature *feature;
> -  struct tdesc_type *field_type, *type;
> +  struct tdesc_type *field_type;
> +  struct tdesc_type *type;
>  
>    set_tdesc_architecture (result, bfd_scan_arch ("i386:x86-64"));
>  
> diff --git a/gdb/features/i386/amd64-linux.c b/gdb/features/i386/amd64-linux.c
> index 71efcbe..db97118 100644
> --- a/gdb/features/i386/amd64-linux.c
> +++ b/gdb/features/i386/amd64-linux.c
> @@ -10,7 +10,8 @@ initialize_tdesc_amd64_linux (void)
>  {
>    struct target_desc *result = allocate_target_description ();
>    struct tdesc_feature *feature;
> -  struct tdesc_type *field_type, *type;
> +  struct tdesc_type *field_type;
> +  struct tdesc_type *type;
>  
>    set_tdesc_architecture (result, bfd_scan_arch ("i386:x86-64"));
>  
> diff --git a/gdb/features/i386/amd64.c b/gdb/features/i386/amd64.c
> index 154e8df..951b36d 100644
> --- a/gdb/features/i386/amd64.c
> +++ b/gdb/features/i386/amd64.c
> @@ -10,7 +10,8 @@ initialize_tdesc_amd64 (void)
>  {
>    struct target_desc *result = allocate_target_description ();
>    struct tdesc_feature *feature;
> -  struct tdesc_type *field_type, *type;
> +  struct tdesc_type *field_type;
> +  struct tdesc_type *type;
>  
>    set_tdesc_architecture (result, bfd_scan_arch ("i386:x86-64"));
>  
> diff --git a/gdb/features/i386/i386-avx-linux.c b/gdb/features/i386/i386-avx-linux.c
> index 1aa939b..038073e 100644
> --- a/gdb/features/i386/i386-avx-linux.c
> +++ b/gdb/features/i386/i386-avx-linux.c
> @@ -10,7 +10,8 @@ initialize_tdesc_i386_avx_linux (void)
>  {
>    struct target_desc *result = allocate_target_description ();
>    struct tdesc_feature *feature;
> -  struct tdesc_type *field_type, *type;
> +  struct tdesc_type *field_type;
> +  struct tdesc_type *type;
>  
>    set_tdesc_architecture (result, bfd_scan_arch ("i386"));
>  
> diff --git a/gdb/features/i386/i386-avx.c b/gdb/features/i386/i386-avx.c
> index 1e74ed5..cdfebf8 100644
> --- a/gdb/features/i386/i386-avx.c
> +++ b/gdb/features/i386/i386-avx.c
> @@ -10,7 +10,8 @@ initialize_tdesc_i386_avx (void)
>  {
>    struct target_desc *result = allocate_target_description ();
>    struct tdesc_feature *feature;
> -  struct tdesc_type *field_type, *type;
> +  struct tdesc_type *field_type;
> +  struct tdesc_type *type;
>  
>    set_tdesc_architecture (result, bfd_scan_arch ("i386"));
>  
> diff --git a/gdb/features/i386/i386-linux.c b/gdb/features/i386/i386-linux.c
> index cc1fb99..cdc41a8 100644
> --- a/gdb/features/i386/i386-linux.c
> +++ b/gdb/features/i386/i386-linux.c
> @@ -10,7 +10,8 @@ initialize_tdesc_i386_linux (void)
>  {
>    struct target_desc *result = allocate_target_description ();
>    struct tdesc_feature *feature;
> -  struct tdesc_type *field_type, *type;
> +  struct tdesc_type *field_type;
> +  struct tdesc_type *type;
>  
>    set_tdesc_architecture (result, bfd_scan_arch ("i386"));
>  
> diff --git a/gdb/features/i386/i386-mmx-linux.c b/gdb/features/i386/i386-mmx-linux.c
> index 364ade4..872826a 100644
> --- a/gdb/features/i386/i386-mmx-linux.c
> +++ b/gdb/features/i386/i386-mmx-linux.c
> @@ -10,7 +10,7 @@ initialize_tdesc_i386_mmx_linux (void)
>  {
>    struct target_desc *result = allocate_target_description ();
>    struct tdesc_feature *feature;
> -  struct tdesc_type *field_type, *type;
> +  struct tdesc_type *field_type;
>  
>    set_tdesc_architecture (result, bfd_scan_arch ("i386"));
>  
> diff --git a/gdb/features/i386/i386.c b/gdb/features/i386/i386.c
> index 7f7beb3..b1de96f 100644
> --- a/gdb/features/i386/i386.c
> +++ b/gdb/features/i386/i386.c
> @@ -10,7 +10,8 @@ initialize_tdesc_i386 (void)
>  {
>    struct target_desc *result = allocate_target_description ();
>    struct tdesc_feature *feature;
> -  struct tdesc_type *field_type, *type;
> +  struct tdesc_type *field_type;
> +  struct tdesc_type *type;
>  
>    set_tdesc_architecture (result, bfd_scan_arch ("i386"));
>  
> diff --git a/gdb/features/i386/x32-avx-linux.c b/gdb/features/i386/x32-avx-linux.c
> index d2e5ce9..b01013a 100644
> --- a/gdb/features/i386/x32-avx-linux.c
> +++ b/gdb/features/i386/x32-avx-linux.c
> @@ -10,7 +10,8 @@ initialize_tdesc_x32_avx_linux (void)
>  {
>    struct target_desc *result = allocate_target_description ();
>    struct tdesc_feature *feature;
> -  struct tdesc_type *field_type, *type;
> +  struct tdesc_type *field_type;
> +  struct tdesc_type *type;
>  
>    set_tdesc_architecture (result, bfd_scan_arch ("i386:x64-32"));
>  
> diff --git a/gdb/features/i386/x32-avx.c b/gdb/features/i386/x32-avx.c
> index 47d7305..af235cd 100644
> --- a/gdb/features/i386/x32-avx.c
> +++ b/gdb/features/i386/x32-avx.c
> @@ -10,7 +10,8 @@ initialize_tdesc_x32_avx (void)
>  {
>    struct target_desc *result = allocate_target_description ();
>    struct tdesc_feature *feature;
> -  struct tdesc_type *field_type, *type;
> +  struct tdesc_type *field_type;
> +  struct tdesc_type *type;
>  
>    set_tdesc_architecture (result, bfd_scan_arch ("i386:x64-32"));
>  
> diff --git a/gdb/features/i386/x32-linux.c b/gdb/features/i386/x32-linux.c
> index b42287d..d34a2a9 100644
> --- a/gdb/features/i386/x32-linux.c
> +++ b/gdb/features/i386/x32-linux.c
> @@ -10,7 +10,8 @@ initialize_tdesc_x32_linux (void)
>  {
>    struct target_desc *result = allocate_target_description ();
>    struct tdesc_feature *feature;
> -  struct tdesc_type *field_type, *type;
> +  struct tdesc_type *field_type;
> +  struct tdesc_type *type;
>  
>    set_tdesc_architecture (result, bfd_scan_arch ("i386:x64-32"));
>  
> diff --git a/gdb/features/i386/x32.c b/gdb/features/i386/x32.c
> index 6342ddd..755ec69 100644
> --- a/gdb/features/i386/x32.c
> +++ b/gdb/features/i386/x32.c
> @@ -10,7 +10,8 @@ initialize_tdesc_x32 (void)
>  {
>    struct target_desc *result = allocate_target_description ();
>    struct tdesc_feature *feature;
> -  struct tdesc_type *field_type, *type;
> +  struct tdesc_type *field_type;
> +  struct tdesc_type *type;
>  
>    set_tdesc_architecture (result, bfd_scan_arch ("i386:x64-32"));
>  
> -- 
> 1.7.1

-- 
Sergio


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Invalid segment resister value on x86_64-windows
  2012-05-01 23:04 Invalid segment resister value on x86_64-windows Joel Brobecker
                   ` (2 preceding siblings ...)
  2012-05-02  0:01 ` [RFA 3/2(+)] Test size of x86/x86_64 segment registers Joel Brobecker
@ 2012-05-02 10:10 ` Mark Kettenis
  2012-05-02 17:57   ` Joel Brobecker
  3 siblings, 1 reply; 15+ messages in thread
From: Mark Kettenis @ 2012-05-02 10:10 UTC (permalink / raw)
  To: brobecker; +Cc: gdb-patches

> From: Joel Brobecker <brobecker@adacore.com>
> Date: Tue,  1 May 2012 16:04:19 -0700
> 
> Hello,
> 
> One of our customers noticed that GDB was displaying invalid values
> for the ss & gs register.  It's obviously invalid because the value
> was wider than the registers' size (16 bits). I noticed that the XML
> files define these register as being 32bit, which I am assuming was
> an oversight (?).

Not really an oversight.  While the segment registers are 16-bit,
they're pushed on the stack as 32-bit values (or 64-bit values in
"long" mode).  That's probably why most OSes make them available that
way, and this was carried over into the design of GDB.  In that sense
it was an oversight that they were not widened to 64-bit when we added
amd64 support.

> As a result of the 32bit size, GDB was reading the value of these
> registers as 4 bytes, instead of just 2.

Well, with the current state of affairs, that's a buf in the native
Windows support code ;).

> On GNU/Linux, I did not check the kernel sources, but it appears
> that it was harmless, because the extra bytes were always zero. But
> on some Windows systems, we werent' that lucky.  The extra 2 bytes
> were not null, and thus we ended up with a polluted value.

Linux falls into the "most OSes" category above and makes the segment
registers available as 32-bit or 64-bit values.  Interestingly it
seems that 32-bit Windows does make them available as 32-bit values as
well.  It's 64-bit Windows that is the odd one out here in that it
only provides 16 bits.

> This patch series first regenerates the .c files in features/i386,
> because I noticed a difference between the current files and the
> generated version.  And the second patch changes the size of all
> segment registers to match the size found in the various reference
> manuals.

I'm not sure we can make those changes.  The default layout for the
registers in the target description is chosen such that it is
compatible with the "old" register cache layout used for stubs that
didn't provide a target description.  That layout is still extensively
used by kernel stubs such as the ones in the Linux and NetBSD kernels.
I don't think breaking those would be acceptable, as kernel debugging
is where the segment registers actually matter!


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Invalid segment resister value on x86_64-windows
  2012-05-02 10:10 ` Invalid segment resister value on x86_64-windows Mark Kettenis
@ 2012-05-02 17:57   ` Joel Brobecker
  2012-05-02 20:45     ` Mark Kettenis
  0 siblings, 1 reply; 15+ messages in thread
From: Joel Brobecker @ 2012-05-02 17:57 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1339 bytes --]

> I'm not sure we can make those changes.  The default layout for the
> registers in the target description is chosen such that it is
> compatible with the "old" register cache layout used for stubs that
> didn't provide a target description.  That layout is still extensively
> used by kernel stubs such as the ones in the Linux and NetBSD kernels.
> I don't think breaking those would be acceptable, as kernel debugging
> is where the segment registers actually matter!

That's something I was concerned about. Here is another approach, which
adds special handling for those registers for Windows. The issue was
that the same code was used for both 32bit and 64bit Windows, so
I needed to extend the tdep structure to be able to determine whether
register N was a segment register or not.

Does the attached patch look good to you?

gdb/ChangeLog:

        * i386-tdep.h (struct gdbarch_tdep): New field
        `first_segment_regnum'.
        * amd64-tdep.c (amd64_init_abi): Set tdep->first_segment_regnum.
        * i386-tdep.c (i386_gdbarch_init): Likewise.
        * windows-nat.c (do_windows_fetch_inferior_registers): Only
        read the first 16 bits of segment register values.

Tested on x86-windows and x86_64-windows using AdaCore's testsuite.
Tested on x86_64-linux with the official testsuite (JIC).

Thank you,
-- 
Joel

[-- Attachment #2: segment-registers-windows.diff --]
[-- Type: text/x-diff, Size: 2931 bytes --]

commit 657e5f87523009cab319c427829543b0231923af
Author: Joel Brobecker <brobecker@adacore.com>
Date:   Wed May 2 09:00:11 2012 -0700

    Segment register reading on Windows targets.
    
    gdb/ChangeLog:
    
            * i386-tdep.h (struct gdbarch_tdep): New field
            `first_segment_regnum'.
            * amd64-tdep.c (amd64_init_abi): Set tdep->first_segment_regnum.
            * i386-tdep.c (i386_gdbarch_init): Likewise.
            * windows-nat.c (do_windows_fetch_inferior_registers): Only
            read the first 16 bits of segment register values.

diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 685fa48..27988bf 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -2585,6 +2585,8 @@ amd64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   const struct target_desc *tdesc = info.target_desc;
 
+  tdep->first_segment_regnum = AMD64_CS_REGNUM;
+
   /* AMD64 generally uses `fxsave' instead of `fsave' for saving its
      floating-point registers.  */
   tdep->sizeof_fpregset = I387_SIZEOF_FXSAVE;
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 769ef42..e6457f6 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -7613,6 +7613,8 @@ i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   tdep->gregset_num_regs = I386_NUM_GREGS;
   tdep->sizeof_gregset = 0;
 
+  tdep->first_segment_regnum = I386_CS_REGNUM;
+
   /* Floating-point registers.  */
   tdep->fpregset = NULL;
   tdep->sizeof_fpregset = I387_SIZEOF_FSAVE;
diff --git a/gdb/i386-tdep.h b/gdb/i386-tdep.h
index f297ae7..e2acbbc 100644
--- a/gdb/i386-tdep.h
+++ b/gdb/i386-tdep.h
@@ -75,6 +75,10 @@ struct gdbarch_tdep
   int gregset_num_regs;
   size_t sizeof_gregset;
 
+  /* Register number for the first segment register.  Its value
+     depends on whether we're debugging on an x86 or amd64 target.  */
+  int first_segment_regnum;
+
   /* The general-purpose registers used to pass integers when making
      function calls.  This only applies to amd64, as all parameters
      are passed through the stack on x86.  */
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index f536ed1..a265462 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -456,6 +456,15 @@ do_windows_fetch_inferior_registers (struct regcache *regcache, int r)
       l = (*((long *) context_offset) >> 16) & ((1 << 11) - 1);
       regcache_raw_supply (regcache, r, (char *) &l);
     }
+  else if (r >= tdep->first_segment_regnum
+	   && r < tdep->first_segment_regnum + 6)
+    {
+      /* GDB treats segment registers as 32bit registers, but they are
+	 in fact only 16 bits long.  Make sure we do not read extra
+	 bits from our source buffer.  */
+      l = *((long *) context_offset) & 0xffff;
+      regcache_raw_supply (regcache, r, (char *) &l);
+    }
   else if (r >= 0)
     regcache_raw_supply (regcache, r, context_offset);
   else

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Invalid segment resister value on x86_64-windows
  2012-05-02 17:57   ` Joel Brobecker
@ 2012-05-02 20:45     ` Mark Kettenis
  2012-05-02 21:26       ` Joel Brobecker
  0 siblings, 1 reply; 15+ messages in thread
From: Mark Kettenis @ 2012-05-02 20:45 UTC (permalink / raw)
  To: brobecker; +Cc: gdb-patches

> Date: Wed, 2 May 2012 10:57:24 -0700
> From: Joel Brobecker <brobecker@adacore.com>
> 
> > I'm not sure we can make those changes.  The default layout for the
> > registers in the target description is chosen such that it is
> > compatible with the "old" register cache layout used for stubs that
> > didn't provide a target description.  That layout is still extensively
> > used by kernel stubs such as the ones in the Linux and NetBSD kernels.
> > I don't think breaking those would be acceptable, as kernel debugging
> > is where the segment registers actually matter!
> 
> That's something I was concerned about. Here is another approach, which
> adds special handling for those registers for Windows. The issue was
> that the same code was used for both 32bit and 64bit Windows, so
> I needed to extend the tdep structure to be able to determine whether
> register N was a segment register or not.
> 
> Does the attached patch look good to you?

Hmm, it should be possible to do this without changing any of the
-tdep.c code, but if you prefer to do it this way, can you rename the
new field into cs_regnum, change the comment into "Register number for
%cs", and move it somewhere around the other _regnum variables that
are already part of the struct?  That makes things a bit more
consistent.

> gdb/ChangeLog:
> 
>         * i386-tdep.h (struct gdbarch_tdep): New field
>         `first_segment_regnum'.
>         * amd64-tdep.c (amd64_init_abi): Set tdep->first_segment_regnum.
>         * i386-tdep.c (i386_gdbarch_init): Likewise.
>         * windows-nat.c (do_windows_fetch_inferior_registers): Only
>         read the first 16 bits of segment register values.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Invalid segment resister value on x86_64-windows
  2012-05-02 20:45     ` Mark Kettenis
@ 2012-05-02 21:26       ` Joel Brobecker
  2012-05-02 21:27         ` Joel Brobecker
  0 siblings, 1 reply; 15+ messages in thread
From: Joel Brobecker @ 2012-05-02 21:26 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: gdb-patches

> Hmm, it should be possible to do this without changing any of the
> -tdep.c code, but if you prefer to do it this way, can you rename the
> new field into cs_regnum, change the comment into "Register number for
> %cs", and move it somewhere around the other _regnum variables that
> are already part of the struct?  That makes things a bit more
> consistent.

If you prefer, I can do something similar to what we do to handle
the register mapping.  Attached is a patch that does that, and only
touches windows *-nat code. Untested for now; will test and add
a ChangeLog if this is your prefered approach.

This can be simplified a little further and have everything done
in windows-nat.c, but it would probably be considered uglier:
include "i386-tdep.h" and "amd64-tdep.h" in windows-nat.c, and
then have a quick check to determine which platform we are, and
then set then implement the segment_register_p function using either
a check on sizeof (void *), or a #ifdef [...] #else [...]...

-- 
Joel


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Invalid segment resister value on x86_64-windows
  2012-05-02 21:26       ` Joel Brobecker
@ 2012-05-02 21:27         ` Joel Brobecker
  2012-05-02 21:50           ` Mark Kettenis
  2012-05-02 21:58           ` [WINDOWS/RFC] " Joel Brobecker
  0 siblings, 2 replies; 15+ messages in thread
From: Joel Brobecker @ 2012-05-02 21:27 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1050 bytes --]

[ENOPATCH]

> > Hmm, it should be possible to do this without changing any of the
> > -tdep.c code, but if you prefer to do it this way, can you rename the
> > new field into cs_regnum, change the comment into "Register number for
> > %cs", and move it somewhere around the other _regnum variables that
> > are already part of the struct?  That makes things a bit more
> > consistent.
> 
> If you prefer, I can do something similar to what we do to handle
> the register mapping.  Attached is a patch that does that, and only
> touches windows *-nat code. Untested for now; will test and add
> a ChangeLog if this is your prefered approach.
> 
> This can be simplified a little further and have everything done
> in windows-nat.c, but it would probably be considered uglier:
> include "i386-tdep.h" and "amd64-tdep.h" in windows-nat.c, and
> then have a quick check to determine which platform we are, and
> then set then implement the segment_register_p function using either
> a check on sizeof (void *), or a #ifdef [...] #else [...]...

-- 
Joel

[-- Attachment #2: windows-seg-regs-v2-untested.diff --]
[-- Type: text/x-diff, Size: 4060 bytes --]

commit ca26ab21b1b2d080e9002d86f23e3e41161af6de
Author: Joel Brobecker <brobecker@adacore.com>
Date:   Wed May 2 14:19:23 2012 -0700

    Segment register reading on Windows targets.

diff --git a/gdb/amd64-windows-nat.c b/gdb/amd64-windows-nat.c
index bc2c047..e5fb0e0 100644
--- a/gdb/amd64-windows-nat.c
+++ b/gdb/amd64-windows-nat.c
@@ -18,6 +18,8 @@
 #include "defs.h"
 #include "windows-nat.h"
 #include "i386-nat.h"
+#include "amd64-tdep.h"
+
 #include <windows.h>
 
 #define context_offset(x) (offsetof (CONTEXT, x))
@@ -85,6 +87,14 @@ static const int mappings[] =
 };
 #undef context_offset
 
+/* segment_register_p_ftype implementation for amd64.  */
+
+static int
+amd64_windows_segment_register_p (int regnum)
+{
+  return regnum >= AMD64_CS_REGNUM && regnum <= AMD64_GS_REGNUM;
+}
+
 /* -Wmissing-prototypes */
 extern initialize_file_ftype _initialize_amd64_windows_nat;
 
@@ -92,5 +102,6 @@ void
 _initialize_amd64_windows_nat (void)
 {
   windows_set_context_register_offsets (mappings);
+  windows_set_segment_register_p (amd64_windows_segment_register_p);
   i386_set_debug_register_length (8);
 }
diff --git a/gdb/i386-windows-nat.c b/gdb/i386-windows-nat.c
index 5d93915..0928c9f 100644
--- a/gdb/i386-windows-nat.c
+++ b/gdb/i386-windows-nat.c
@@ -18,6 +18,7 @@
 #include "defs.h"
 #include "windows-nat.h"
 #include "i386-nat.h"
+#include "i386-tdep.h"
 
 #include <windows.h>
 
@@ -70,6 +71,14 @@ static const int mappings[] =
 };
 #undef context_offset
 
+/* segment_register_p_ftype implementation for x86.  */
+
+static int
+i386_windows_segment_register_p (int regnum)
+{
+  return regnum >= I386_CS_REGNUM && regnum <= I386_GS_REGNUM;
+}
+
 /* -Wmissing-prototypes */
 extern initialize_file_ftype _initialize_i386_windows_nat;
 
@@ -77,5 +86,6 @@ void
 _initialize_i386_windows_nat (void)
 {
   windows_set_context_register_offsets (mappings);
+  windows_set_segment_register_p (i386_windows_segment_register_p);
   i386_set_debug_register_length (4);
 }
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index f536ed1..000c86f 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -243,6 +243,10 @@ static int useshell = 0;		/* use shell for subprocesses */
 
 static const int *mappings;
 
+/* The function to use in order to determine whether a register is
+   a segment register or not.  */
+static segment_register_p_ftype *segment_register_p;
+
 /* This vector maps the target's idea of an exception (extracted
    from the DEBUG_EVENT structure) to GDB's idea.  */
 
@@ -272,6 +276,14 @@ windows_set_context_register_offsets (const int *offsets)
   mappings = offsets;
 }
 
+/* See windows-nat.h.  */
+
+void
+windows_set_segment_register_p (segment_register_p_ftype *fun)
+{
+  segment_register_p = fun;
+}
+
 static void
 check (BOOL ok, const char *file, int line)
 {
@@ -456,6 +468,14 @@ do_windows_fetch_inferior_registers (struct regcache *regcache, int r)
       l = (*((long *) context_offset) >> 16) & ((1 << 11) - 1);
       regcache_raw_supply (regcache, r, (char *) &l);
     }
+  else if (segment_register_p (r))
+    {
+      /* GDB treats segment registers as 32bit registers, but they are
+	 in fact only 16 bits long.  Make sure we do not read extra
+	 bits from our source buffer.  */
+      l = *((long *) context_offset) & 0xffff;
+      regcache_raw_supply (regcache, r, (char *) &l);
+    }
   else if (r >= 0)
     regcache_raw_supply (regcache, r, context_offset);
   else
diff --git a/gdb/windows-nat.h b/gdb/windows-nat.h
index 08200b9..a6cc5ec 100644
--- a/gdb/windows-nat.h
+++ b/gdb/windows-nat.h
@@ -20,5 +20,13 @@
 
 extern void windows_set_context_register_offsets (const int *offsets);
 
+/* A pointer to a function that should return non-zero iff REGNUM
+   corresponds to one of the segment registers.  */
+typedef int (segment_register_p_ftype) (int regnum);
+
+/* Set the function that should be used by this module to determine
+   whether a given register is a segment register or not.  */
+extern void windows_set_segment_register_p (segment_register_p_ftype *fun);
+
 #endif
 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Invalid segment resister value on x86_64-windows
  2012-05-02 21:27         ` Joel Brobecker
@ 2012-05-02 21:50           ` Mark Kettenis
  2012-05-02 21:58           ` [WINDOWS/RFC] " Joel Brobecker
  1 sibling, 0 replies; 15+ messages in thread
From: Mark Kettenis @ 2012-05-02 21:50 UTC (permalink / raw)
  To: brobecker; +Cc: gdb-patches

> Date: Wed, 2 May 2012 14:27:26 -0700
> From: Joel Brobecker <brobecker@adacore.com>
> 
> [ENOPATCH]
> 
> > > Hmm, it should be possible to do this without changing any of the
> > > -tdep.c code, but if you prefer to do it this way, can you rename the
> > > new field into cs_regnum, change the comment into "Register number for
> > > %cs", and move it somewhere around the other _regnum variables that
> > > are already part of the struct?  That makes things a bit more
> > > consistent.
> > 
> > If you prefer, I can do something similar to what we do to handle
> > the register mapping.  Attached is a patch that does that, and only
> > touches windows *-nat code. Untested for now; will test and add
> > a ChangeLog if this is your prefered approach.
> > 
> > This can be simplified a little further and have everything done
> > in windows-nat.c, but it would probably be considered uglier:
> > include "i386-tdep.h" and "amd64-tdep.h" in windows-nat.c, and
> > then have a quick check to determine which platform we are, and
> > then set then implement the segment_register_p function using either
> > a check on sizeof (void *), or a #ifdef [...] #else [...]...
> 
> -- 
> Joel

I don't really care about the native Windows support bits.  If Chris
is happy with this, I'd say go for it.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [WINDOWS/RFC] Invalid segment resister value on x86_64-windows
  2012-05-02 21:27         ` Joel Brobecker
  2012-05-02 21:50           ` Mark Kettenis
@ 2012-05-02 21:58           ` Joel Brobecker
  2012-05-02 22:10             ` Christopher Faylor
  1 sibling, 1 reply; 15+ messages in thread
From: Joel Brobecker @ 2012-05-02 21:58 UTC (permalink / raw)
  To: cgf; +Cc: gdb-patches

Hi Chris,

Would you mind telling us what you think on this issue?

Thanks!

> > > Hmm, it should be possible to do this without changing any of the
> > > -tdep.c code, but if you prefer to do it this way, can you rename the
> > > new field into cs_regnum, change the comment into "Register number for
> > > %cs", and move it somewhere around the other _regnum variables that
> > > are already part of the struct?  That makes things a bit more
> > > consistent.
> > 
> > If you prefer, I can do something similar to what we do to handle
> > the register mapping.  Attached is a patch that does that, and only
> > touches windows *-nat code. Untested for now; will test and add
> > a ChangeLog if this is your prefered approach.
> > 
> > This can be simplified a little further and have everything done
> > in windows-nat.c, but it would probably be considered uglier:
> > include "i386-tdep.h" and "amd64-tdep.h" in windows-nat.c, and
> > then have a quick check to determine which platform we are, and
> > then set then implement the segment_register_p function using either
> > a check on sizeof (void *), or a #ifdef [...] #else [...]...

commit ca26ab21b1b2d080e9002d86f23e3e41161af6de
Author: Joel Brobecker <brobecker@adacore.com>
Date:   Wed May 2 14:19:23 2012 -0700

    Segment register reading on Windows targets.

diff --git a/gdb/amd64-windows-nat.c b/gdb/amd64-windows-nat.c
index bc2c047..e5fb0e0 100644
--- a/gdb/amd64-windows-nat.c
+++ b/gdb/amd64-windows-nat.c
@@ -18,6 +18,8 @@
 #include "defs.h"
 #include "windows-nat.h"
 #include "i386-nat.h"
+#include "amd64-tdep.h"
+
 #include <windows.h>
 
 #define context_offset(x) (offsetof (CONTEXT, x))
@@ -85,6 +87,14 @@ static const int mappings[] =
 };
 #undef context_offset
 
+/* segment_register_p_ftype implementation for amd64.  */
+
+static int
+amd64_windows_segment_register_p (int regnum)
+{
+  return regnum >= AMD64_CS_REGNUM && regnum <= AMD64_GS_REGNUM;
+}
+
 /* -Wmissing-prototypes */
 extern initialize_file_ftype _initialize_amd64_windows_nat;
 
@@ -92,5 +102,6 @@ void
 _initialize_amd64_windows_nat (void)
 {
   windows_set_context_register_offsets (mappings);
+  windows_set_segment_register_p (amd64_windows_segment_register_p);
   i386_set_debug_register_length (8);
 }
diff --git a/gdb/i386-windows-nat.c b/gdb/i386-windows-nat.c
index 5d93915..0928c9f 100644
--- a/gdb/i386-windows-nat.c
+++ b/gdb/i386-windows-nat.c
@@ -18,6 +18,7 @@
 #include "defs.h"
 #include "windows-nat.h"
 #include "i386-nat.h"
+#include "i386-tdep.h"
 
 #include <windows.h>
 
@@ -70,6 +71,14 @@ static const int mappings[] =
 };
 #undef context_offset
 
+/* segment_register_p_ftype implementation for x86.  */
+
+static int
+i386_windows_segment_register_p (int regnum)
+{
+  return regnum >= I386_CS_REGNUM && regnum <= I386_GS_REGNUM;
+}
+
 /* -Wmissing-prototypes */
 extern initialize_file_ftype _initialize_i386_windows_nat;
 
@@ -77,5 +86,6 @@ void
 _initialize_i386_windows_nat (void)
 {
   windows_set_context_register_offsets (mappings);
+  windows_set_segment_register_p (i386_windows_segment_register_p);
   i386_set_debug_register_length (4);
 }
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index f536ed1..000c86f 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -243,6 +243,10 @@ static int useshell = 0;		/* use shell for subprocesses */
 
 static const int *mappings;
 
+/* The function to use in order to determine whether a register is
+   a segment register or not.  */
+static segment_register_p_ftype *segment_register_p;
+
 /* This vector maps the target's idea of an exception (extracted
    from the DEBUG_EVENT structure) to GDB's idea.  */
 
@@ -272,6 +276,14 @@ windows_set_context_register_offsets (const int *offsets)
   mappings = offsets;
 }
 
+/* See windows-nat.h.  */
+
+void
+windows_set_segment_register_p (segment_register_p_ftype *fun)
+{
+  segment_register_p = fun;
+}
+
 static void
 check (BOOL ok, const char *file, int line)
 {
@@ -456,6 +468,14 @@ do_windows_fetch_inferior_registers (struct regcache *regcache, int r)
       l = (*((long *) context_offset) >> 16) & ((1 << 11) - 1);
       regcache_raw_supply (regcache, r, (char *) &l);
     }
+  else if (segment_register_p (r))
+    {
+      /* GDB treats segment registers as 32bit registers, but they are
+	 in fact only 16 bits long.  Make sure we do not read extra
+	 bits from our source buffer.  */
+      l = *((long *) context_offset) & 0xffff;
+      regcache_raw_supply (regcache, r, (char *) &l);
+    }
   else if (r >= 0)
     regcache_raw_supply (regcache, r, context_offset);
   else
diff --git a/gdb/windows-nat.h b/gdb/windows-nat.h
index 08200b9..a6cc5ec 100644
--- a/gdb/windows-nat.h
+++ b/gdb/windows-nat.h
@@ -20,5 +20,13 @@
 
 extern void windows_set_context_register_offsets (const int *offsets);
 
+/* A pointer to a function that should return non-zero iff REGNUM
+   corresponds to one of the segment registers.  */
+typedef int (segment_register_p_ftype) (int regnum);
+
+/* Set the function that should be used by this module to determine
+   whether a given register is a segment register or not.  */
+extern void windows_set_segment_register_p (segment_register_p_ftype *fun);
+
 #endif

-- 
Joel


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [WINDOWS/RFC] Invalid segment resister value on x86_64-windows
  2012-05-02 21:58           ` [WINDOWS/RFC] " Joel Brobecker
@ 2012-05-02 22:10             ` Christopher Faylor
  2012-05-02 22:16               ` Christopher Faylor
  2012-05-04 18:38               ` checked in: " Joel Brobecker
  0 siblings, 2 replies; 15+ messages in thread
From: Christopher Faylor @ 2012-05-02 22:10 UTC (permalink / raw)
  To: gdb-patches, Joel Brobecker

On Wed, May 02, 2012 at 02:57:38PM -0700, Joel Brobecker wrote:
>Hi Chris,
>
>Would you mind telling us what you think on this issue?

Please don't use a random email address that you found on the net to
send me personal email.  I was actually fairly successful in keeping
that spam-free until now.

The patch is approved.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [WINDOWS/RFC] Invalid segment resister value on x86_64-windows
  2012-05-02 22:10             ` Christopher Faylor
@ 2012-05-02 22:16               ` Christopher Faylor
  2012-05-04 18:38               ` checked in: " Joel Brobecker
  1 sibling, 0 replies; 15+ messages in thread
From: Christopher Faylor @ 2012-05-02 22:16 UTC (permalink / raw)
  To: gdb-patches, Joel Brobecker

On Wed, May 02, 2012 at 06:09:53PM -0400, Christopher Faylor wrote:
>On Wed, May 02, 2012 at 02:57:38PM -0700, Joel Brobecker wrote:
>>Hi Chris,
>>
>>Would you mind telling us what you think on this issue?
>
>Please don't use a random email address that you found on the net to
>send me personal email.  I was actually fairly successful in keeping
>that spam-free until now.

Aha.  I see that's what is listed for me in MAINTAINERS.  Sorry.

I've removed that email address and I'll use this opportunity to step
down as the Windows maintainer.  I've been meaning to do this for a
while.

I'll still be reading the mailing list but someone else can approve
future changes.

cgf


^ permalink raw reply	[flat|nested] 15+ messages in thread

* checked in: [WINDOWS/RFC] Invalid segment resister value on x86_64-windows
  2012-05-02 22:10             ` Christopher Faylor
  2012-05-02 22:16               ` Christopher Faylor
@ 2012-05-04 18:38               ` Joel Brobecker
  1 sibling, 0 replies; 15+ messages in thread
From: Joel Brobecker @ 2012-05-04 18:38 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 123 bytes --]

> The patch is approved.

Attached is what I tested on both x86 and x86_64 Windows, and then
checked in.

Thanks!
-- 
Joel

[-- Attachment #2: windows-segment-regs-final.diff --]
[-- Type: text/x-diff, Size: 5941 bytes --]

commit b180b0bc166534ae1ec8f1fcf02bcc28ecae2106
Author: Joel Brobecker <brobecker@adacore.com>
Date:   Wed May 2 14:19:23 2012 -0700

    Segment register reading on Windows targets.
    
    This patch makes sure that the value of segment registers are
    read properly as 16bit values on Windows.
    
    gdb/ChangeLog:
    
            * windows-nat.h (segment_register_p_ftype): New typedef.
            (windows_set_segment_register_p): Add declaration.
            * windows-nat.c (segment_register_p): New static global.
            (windows_set_segment_register_p): New function.
            (do_windows_fetch_inferior_registers): Add special handling
            for segment registers.
            * amd64-windows-nat.c: #include "amd64-tdep.h".
            (amd64_windows_segment_register_p): New function.
            (_initialize_amd64_windows_nat): Call windows_set_segment_register_p.
            * i386-windows-nat.c: #include "i386-tdep.h".
            (i386_windows_segment_register_p): New function.
            (_initialize_i386_windows_nat): Call windows_set_segment_register_p.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a073454..5e63549 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,18 @@
+2012-05-04  Joel Brobecker  <brobecker@adacore.com>
+
+	* windows-nat.h (segment_register_p_ftype): New typedef.
+	(windows_set_segment_register_p): Add declaration.
+	* windows-nat.c (segment_register_p): New static global.
+	(windows_set_segment_register_p): New function.
+	(do_windows_fetch_inferior_registers): Add special handling
+	for segment registers.
+	* amd64-windows-nat.c: #include "amd64-tdep.h".
+	(amd64_windows_segment_register_p): New function.
+	(_initialize_amd64_windows_nat): Call windows_set_segment_register_p.
+	* i386-windows-nat.c: #include "i386-tdep.h".
+	(i386_windows_segment_register_p): New function.
+	(_initialize_i386_windows_nat): Call windows_set_segment_register_p.
+
 2012-05-04  Tristan Gingold  <gingold@adacore.com>
 
 	* printcmd.c (set_command): Emit a warning if the expression is not
diff --git a/gdb/amd64-windows-nat.c b/gdb/amd64-windows-nat.c
index bc2c047..e5fb0e0 100644
--- a/gdb/amd64-windows-nat.c
+++ b/gdb/amd64-windows-nat.c
@@ -18,6 +18,8 @@
 #include "defs.h"
 #include "windows-nat.h"
 #include "i386-nat.h"
+#include "amd64-tdep.h"
+
 #include <windows.h>
 
 #define context_offset(x) (offsetof (CONTEXT, x))
@@ -85,6 +87,14 @@ static const int mappings[] =
 };
 #undef context_offset
 
+/* segment_register_p_ftype implementation for amd64.  */
+
+static int
+amd64_windows_segment_register_p (int regnum)
+{
+  return regnum >= AMD64_CS_REGNUM && regnum <= AMD64_GS_REGNUM;
+}
+
 /* -Wmissing-prototypes */
 extern initialize_file_ftype _initialize_amd64_windows_nat;
 
@@ -92,5 +102,6 @@ void
 _initialize_amd64_windows_nat (void)
 {
   windows_set_context_register_offsets (mappings);
+  windows_set_segment_register_p (amd64_windows_segment_register_p);
   i386_set_debug_register_length (8);
 }
diff --git a/gdb/i386-windows-nat.c b/gdb/i386-windows-nat.c
index 5d93915..0928c9f 100644
--- a/gdb/i386-windows-nat.c
+++ b/gdb/i386-windows-nat.c
@@ -18,6 +18,7 @@
 #include "defs.h"
 #include "windows-nat.h"
 #include "i386-nat.h"
+#include "i386-tdep.h"
 
 #include <windows.h>
 
@@ -70,6 +71,14 @@ static const int mappings[] =
 };
 #undef context_offset
 
+/* segment_register_p_ftype implementation for x86.  */
+
+static int
+i386_windows_segment_register_p (int regnum)
+{
+  return regnum >= I386_CS_REGNUM && regnum <= I386_GS_REGNUM;
+}
+
 /* -Wmissing-prototypes */
 extern initialize_file_ftype _initialize_i386_windows_nat;
 
@@ -77,5 +86,6 @@ void
 _initialize_i386_windows_nat (void)
 {
   windows_set_context_register_offsets (mappings);
+  windows_set_segment_register_p (i386_windows_segment_register_p);
   i386_set_debug_register_length (4);
 }
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index f536ed1..000c86f 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -243,6 +243,10 @@ static int useshell = 0;		/* use shell for subprocesses */
 
 static const int *mappings;
 
+/* The function to use in order to determine whether a register is
+   a segment register or not.  */
+static segment_register_p_ftype *segment_register_p;
+
 /* This vector maps the target's idea of an exception (extracted
    from the DEBUG_EVENT structure) to GDB's idea.  */
 
@@ -272,6 +276,14 @@ windows_set_context_register_offsets (const int *offsets)
   mappings = offsets;
 }
 
+/* See windows-nat.h.  */
+
+void
+windows_set_segment_register_p (segment_register_p_ftype *fun)
+{
+  segment_register_p = fun;
+}
+
 static void
 check (BOOL ok, const char *file, int line)
 {
@@ -456,6 +468,14 @@ do_windows_fetch_inferior_registers (struct regcache *regcache, int r)
       l = (*((long *) context_offset) >> 16) & ((1 << 11) - 1);
       regcache_raw_supply (regcache, r, (char *) &l);
     }
+  else if (segment_register_p (r))
+    {
+      /* GDB treats segment registers as 32bit registers, but they are
+	 in fact only 16 bits long.  Make sure we do not read extra
+	 bits from our source buffer.  */
+      l = *((long *) context_offset) & 0xffff;
+      regcache_raw_supply (regcache, r, (char *) &l);
+    }
   else if (r >= 0)
     regcache_raw_supply (regcache, r, context_offset);
   else
diff --git a/gdb/windows-nat.h b/gdb/windows-nat.h
index 08200b9..a6cc5ec 100644
--- a/gdb/windows-nat.h
+++ b/gdb/windows-nat.h
@@ -20,5 +20,13 @@
 
 extern void windows_set_context_register_offsets (const int *offsets);
 
+/* A pointer to a function that should return non-zero iff REGNUM
+   corresponds to one of the segment registers.  */
+typedef int (segment_register_p_ftype) (int regnum);
+
+/* Set the function that should be used by this module to determine
+   whether a given register is a segment register or not.  */
+extern void windows_set_segment_register_p (segment_register_p_ftype *fun);
+
 #endif
 

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2012-05-04 18:38 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-01 23:04 Invalid segment resister value on x86_64-windows Joel Brobecker
2012-05-01 23:04 ` [RFA/commit 1/2] Regenerate the features/i386 target description .c files Joel Brobecker
2012-05-02  6:34   ` Sergio Durigan Junior
2012-05-01 23:05 ` [RFA 2/2] [x86/x86_64] Segment registers are 16 bits long (not 32bits) Joel Brobecker
2012-05-02  0:01 ` [RFA 3/2(+)] Test size of x86/x86_64 segment registers Joel Brobecker
2012-05-02 10:10 ` Invalid segment resister value on x86_64-windows Mark Kettenis
2012-05-02 17:57   ` Joel Brobecker
2012-05-02 20:45     ` Mark Kettenis
2012-05-02 21:26       ` Joel Brobecker
2012-05-02 21:27         ` Joel Brobecker
2012-05-02 21:50           ` Mark Kettenis
2012-05-02 21:58           ` [WINDOWS/RFC] " Joel Brobecker
2012-05-02 22:10             ` Christopher Faylor
2012-05-02 22:16               ` Christopher Faylor
2012-05-04 18:38               ` checked in: " Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox