Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Subject: checked in: [WINDOWS/RFC] Invalid segment resister value on x86_64-windows
Date: Fri, 04 May 2012 18:38:00 -0000	[thread overview]
Message-ID: <20120504183820.GR15555@adacore.com> (raw)
In-Reply-To: <20120502220953.GA10557@ednor.casa.cgf.cx>

[-- 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
 

      parent reply	other threads:[~2012-05-04 18:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
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               ` Joel Brobecker [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120504183820.GR15555@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox