This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
PATCH: Remove regmap from i386-linux-nat.c
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: GDB <gdb-patches at sourceware dot org>
- Date: Mon, 12 Apr 2010 06:49:55 -0700
- Subject: PATCH: Remove regmap from i386-linux-nat.c
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
There is no need to have both regmap in i386-linux-nat.c and
i386_linux_gregset_reg_offset in i386-linux-tdep.c when they
have basically the same thing. This patch removes regmap from
i386-linux-nat.c. This patch depends on
http://sourceware.org/ml/gdb-patches/2010-04/msg00346.html
OK to install?
Thanks.
H.J.
---
2010-04-12 H.J. Lu <hongjiu.lu@intel.com>
* i386-linux-nat.c (regmap): Removed.
(fetch_register): Replace regmap with tdep->gregset_reg_offset.
(store_register): Likewise.
(supply_gregset): Likewise.
diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c
index 2ba120b..943382a 100644
--- a/gdb/i386-linux-nat.c
+++ b/gdb/i386-linux-nat.c
@@ -99,26 +99,6 @@ static int have_ptrace_getregset = -1;
those names are now used for the register sets used in the
`mcontext_t' type, and have a different size and layout. */
-/* Mapping between the general-purpose registers in `struct user'
- format and GDB's register array layout. */
-static int regmap[] =
-{
- EAX, ECX, EDX, EBX,
- UESP, EBP, ESI, EDI,
- EIP, EFL, CS, SS,
- DS, ES, FS, GS,
- -1, -1, -1, -1, /* st0, st1, st2, st3 */
- -1, -1, -1, -1, /* st4, st5, st6, st7 */
- -1, -1, -1, -1, /* fctrl, fstat, ftag, fiseg */
- -1, -1, -1, -1, /* fioff, foseg, fooff, fop */
- -1, -1, -1, -1, /* xmm0, xmm1, xmm2, xmm3 */
- -1, -1, -1, -1, /* xmm4, xmm5, xmm6, xmm6 */
- -1, /* mxcsr */
- -1, -1, -1, -1, /* ymm0h, ymm1h, ymm2h, ymm3h */
- -1, -1, -1, -1, /* ymm4h, ymm5h, ymm6h, ymm6h */
- ORIG_EAX
-};
-
/* Which ptrace request retrieves which registers?
These apply to the corresponding SET requests as well. */
@@ -166,9 +146,12 @@ fetch_register (struct regcache *regcache, int regno)
{
int tid;
int val;
+ struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ int *reg_offset = tdep->gregset_reg_offset;
gdb_assert (!have_ptrace_getregs);
- if (regmap[regno] == -1)
+ if (reg_offset[regno] == -1)
{
regcache_raw_supply (regcache, regno, NULL);
return;
@@ -180,7 +163,7 @@ fetch_register (struct regcache *regcache, int regno)
tid = PIDGET (inferior_ptid); /* Not a threaded program. */
errno = 0;
- val = ptrace (PTRACE_PEEKUSER, tid, 4 * regmap[regno], 0);
+ val = ptrace (PTRACE_PEEKUSER, tid, reg_offset[regno], 0);
if (errno != 0)
error (_("Couldn't read register %s (#%d): %s."),
gdbarch_register_name (get_regcache_arch (regcache), regno),
@@ -196,9 +179,12 @@ store_register (const struct regcache *regcache, int regno)
{
int tid;
int val;
+ struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ int *reg_offset = tdep->gregset_reg_offset;
gdb_assert (!have_ptrace_getregs);
- if (regmap[regno] == -1)
+ if (reg_offset[regno] == -1)
return;
/* GNU/Linux LWP ID's are process ID's. */
@@ -208,7 +194,7 @@ store_register (const struct regcache *regcache, int regno)
errno = 0;
regcache_raw_collect (regcache, regno, &val);
- ptrace (PTRACE_POKEUSER, tid, 4 * regmap[regno], val);
+ ptrace (PTRACE_POKEUSER, tid, reg_offset[regno], val);
if (errno != 0)
error (_("Couldn't write register %s (#%d): %s."),
gdbarch_register_name (get_regcache_arch (regcache), regno),
@@ -225,16 +211,20 @@ store_register (const struct regcache *regcache, int regno)
void
supply_gregset (struct regcache *regcache, const elf_gregset_t *gregsetp)
{
- const elf_greg_t *regp = (const elf_greg_t *) gregsetp;
+ const char *regp = (const char *) gregsetp;
+ struct gdbarch *gdbarch = get_regcache_arch (regcache);
+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+ int *reg_offset = tdep->gregset_reg_offset;
+ int num_regs = tdep->gregset_num_regs;
int i;
- for (i = 0; i < I386_NUM_GREGS; i++)
- regcache_raw_supply (regcache, i, regp + regmap[i]);
-
- if (I386_LINUX_ORIG_EAX_REGNUM
- < gdbarch_num_regs (get_regcache_arch (regcache)))
- regcache_raw_supply (regcache, I386_LINUX_ORIG_EAX_REGNUM,
- regp + ORIG_EAX);
+ gdb_assert (num_regs == gdbarch_num_regs (gdbarch));
+ for (i = 0; i < num_regs; i ++)
+ {
+ int offset = reg_offset[i];
+ if (offset != -1)
+ regcache_raw_supply (regcache, i, regp + offset);
+ }
}
/* Fill register REGNO (if it is a general-purpose register) in