From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14290 invoked by alias); 2 May 2012 21:27:51 -0000 Received: (qmail 14282 invoked by uid 22791); 2 May 2012 21:27:50 -0000 X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_HOSTKARMA_NO,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,TW_EG X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 02 May 2012 21:27:37 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 024781C69F9; Wed, 2 May 2012 17:27:37 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id qRdUMkpMLqrq; Wed, 2 May 2012 17:27:36 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id C09BE1C69C8; Wed, 2 May 2012 17:27:36 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id A548B145616; Wed, 2 May 2012 14:27:26 -0700 (PDT) Date: Wed, 02 May 2012 21:27:00 -0000 From: Joel Brobecker To: Mark Kettenis Cc: gdb-patches@sourceware.org Subject: Re: Invalid segment resister value on x86_64-windows Message-ID: <20120502212726.GA24839@adacore.com> References: <1335913461-1628-1-git-send-email-brobecker@adacore.com> <201205021009.q42A9G4s021744@glazunov.sibelius.xs4all.nl> <20120502175724.GW10958@adacore.com> <201205022044.q42KiQLc021611@glazunov.sibelius.xs4all.nl> <20120502212612.GB15555@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="WIyZ46R2i8wDzkSu" Content-Disposition: inline In-Reply-To: <20120502212612.GB15555@adacore.com> User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-05/txt/msg00033.txt.bz2 --WIyZ46R2i8wDzkSu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1050 [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 --WIyZ46R2i8wDzkSu Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="windows-seg-regs-v2-untested.diff" Content-length: 4060 commit ca26ab21b1b2d080e9002d86f23e3e41161af6de Author: Joel Brobecker 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 #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 @@ -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 --WIyZ46R2i8wDzkSu--