From: Joel Brobecker <brobecker@adacore.com>
To: Mark Kettenis <mark.kettenis@xs4all.nl>
Cc: gdb-patches@sourceware.org
Subject: Re: Invalid segment resister value on x86_64-windows
Date: Wed, 02 May 2012 17:57:00 -0000 [thread overview]
Message-ID: <20120502175724.GW10958@adacore.com> (raw)
In-Reply-To: <201205021009.q42A9G4s021744@glazunov.sibelius.xs4all.nl>
[-- 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
next prev parent reply other threads:[~2012-05-02 17:57 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 [this message]
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
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=20120502175724.GW10958@adacore.com \
--to=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=mark.kettenis@xs4all.nl \
/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