This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[rfc] Eliminate config/mips/nm-linux.h
- From: "Ulrich Weigand" <uweigand at de dot ibm dot com>
- To: drow at false dot org, mark dot kettenis at xs4all dot nl
- Cc: gdb-patches at sourceware dot org
- Date: Sat, 5 May 2007 02:02:09 +0200 (CEST)
- Subject: [rfc] Eliminate config/mips/nm-linux.h
Dan,
here's an updated version of the patch to eliminate config/mips/nm-linux.h.
This is a prerequiste to removing the TM file, as dicussed ...
The patch goes back to allowing the register_u_offset callback to return
(CORE_ADDR) -1 for registers that cannot be accessed, and adding a STORE_P
parameter to allow for differing results when fetching and storing register
contents.
I've now also added a GDBARCH parameter, as on some platforms, including
mips, the meaning of a register number really depends on the currently
selected architecture. This allows eliminating references to
current_gdbarch.
In the mips-linux-nat implementation, I've removed the separate
mips_linux_cannot_fetch_register and mips_linux_cannot_store_register
routines, and added their results inline into mips_linux_register_addr
and mips64_linux_register_addr.
I haven't tested the patch beyond making sure everything still compiles.
Maybe you could test in on a native mips target?
Mark,
I've now left in the calls to CANNOT_STORE_REGISTER and CANNOT_FETCH_REGISTER
as you suggested. Does this address your concerns with the original patch?
Bye,
Ulrich
ChangeLog:
* inf-ptrace.c (inf_ptrace_register_u_offset): Adapt parameter list.
(inf_ptrace_fetch_register): Add register_u_offset callback parameters
GDBARCH and STORE_P. Handle callback (CORE_ADDR) -1 return value.
(inf_ptrace_store_register): Likewise.
(inf_ptrace_trad_target): Adapt register_u_offset parameter list.
* inf-ptrace.h (inf_ptrace_trad_target): Likewise.
* vax-nat.c (vax_register_u_offset): Adapt parameter list.
* linux-nat.c (linux_trad_target): Adapt parameter list.
* linux-nat.h (linux_trad_target): Likewise.
* alpha-linux-nat.c (alpha_linux_register_u_offset): Adapt parameters.
* mips-linux-nat.c (mips_linux_cannot_fetch_register): Remove.
(mips_linux_cannot_store_register): Likewise.
(mips_linux_register_addr): Add GDBARCH and STORE_P parameters.
Return (CORE_ADDR) -1 for registers that cannot be fetched or
stored via ptrace. Use GDBARCH instead of current_gdbarch.
(mips64_linux_register_addr): Likewise.
(mips_linux_register_u_offset): Adapt parameter list. Pass
GDBARCH and STORE_P on to mips{64}_linux_register_addr.
* config/mips/linux.mh (NAT_FILE): Set to config/nm-linux.h.
* config/mips/nm-linux.h: Delete file.
diff -urNp gdb-orig/gdb/alpha-linux-nat.c gdb-head/gdb/alpha-linux-nat.c
--- gdb-orig/gdb/alpha-linux-nat.c 2007-05-05 01:03:32.844510619 +0200
+++ gdb-head/gdb/alpha-linux-nat.c 2007-05-05 01:15:19.813592894 +0200
@@ -81,7 +81,7 @@ fill_fpregset (gdb_fpregset_t *fpregsetp
static CORE_ADDR
-alpha_linux_register_u_offset (int regno)
+alpha_linux_register_u_offset (struct gdbarch *gdbarch, int regno, int store_p)
{
if (regno == PC_REGNUM)
return PC;
diff -urNp gdb-orig/gdb/config/mips/linux.mh gdb-head/gdb/config/mips/linux.mh
--- gdb-orig/gdb/config/mips/linux.mh 2007-04-26 02:54:20.000000000 +0200
+++ gdb-head/gdb/config/mips/linux.mh 2007-05-05 01:15:19.818592177 +0200
@@ -1,5 +1,5 @@
# Host: Linux/MIPS
-NAT_FILE= nm-linux.h
+NAT_FILE= config/nm-linux.h
NATDEPFILES= inf-ptrace.o fork-child.o mips-linux-nat.o \
linux-thread-db.o proc-service.o gcore.o \
linux-nat.o linux-fork.o
diff -urNp gdb-orig/gdb/config/mips/nm-linux.h gdb-head/gdb/config/mips/nm-linux.h
--- gdb-orig/gdb/config/mips/nm-linux.h 2007-04-26 02:54:20.000000000 +0200
+++ gdb-head/gdb/config/mips/nm-linux.h 1970-01-01 01:00:00.000000000 +0100
@@ -1,32 +0,0 @@
-/* Native-dependent definitions for GNU/Linux on MIPS.
-
- Copyright 1996, 2001, 2002, 2003, 2007 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 2 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, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
-
-#ifndef NM_MIPSLINUX_H
-#define NM_MIPSLINUX_H
-
-#include "config/nm-linux.h"
-
-int mips_linux_cannot_fetch_register (int regno);
-int mips_linux_cannot_store_register (int regno);
-#define CANNOT_FETCH_REGISTER(regno) mips_linux_cannot_fetch_register (regno)
-#define CANNOT_STORE_REGISTER(regno) mips_linux_cannot_store_register (regno)
-
-#endif /* NM_MIPSLINUX_H */
diff -urNp gdb-orig/gdb/inf-ptrace.c gdb-head/gdb/inf-ptrace.c
--- gdb-orig/gdb/inf-ptrace.c 2007-05-05 01:03:33.185461721 +0200
+++ gdb-head/gdb/inf-ptrace.c 2007-05-05 01:25:36.629903436 +0200
@@ -612,7 +612,7 @@ inf_ptrace_target (void)
/* Pointer to a function that returns the offset within the user area
where a particular register is stored. */
-static CORE_ADDR (*inf_ptrace_register_u_offset)(int);
+static CORE_ADDR (*inf_ptrace_register_u_offset)(struct gdbarch *, int, int);
/* Fetch register REGNUM from the inferior. */
@@ -624,7 +624,9 @@ inf_ptrace_fetch_register (int regnum)
PTRACE_TYPE_RET *buf;
int pid, i;
- if (CANNOT_FETCH_REGISTER (regnum))
+ /* This isn't really an address, but ptrace thinks of it as one. */
+ addr = inf_ptrace_register_u_offset (current_gdbarch, regnum, 0);
+ if (addr == (CORE_ADDR)-1 || CANNOT_FETCH_REGISTER (regnum))
{
regcache_raw_supply (current_regcache, regnum, NULL);
return;
@@ -636,10 +638,7 @@ inf_ptrace_fetch_register (int regnum)
if (pid == 0)
pid = ptid_get_pid (inferior_ptid);
- /* This isn't really an address, but ptrace thinks of it as one. */
- addr = inf_ptrace_register_u_offset (regnum);
size = register_size (current_gdbarch, regnum);
-
gdb_assert ((size % sizeof (PTRACE_TYPE_RET)) == 0);
buf = alloca (size);
@@ -680,7 +679,9 @@ inf_ptrace_store_register (int regnum)
PTRACE_TYPE_RET *buf;
int pid, i;
- if (CANNOT_STORE_REGISTER (regnum))
+ /* This isn't really an address, but ptrace thinks of it as one. */
+ addr = inf_ptrace_register_u_offset (current_gdbarch, regnum, 1);
+ if (addr == (CORE_ADDR)-1 || CANNOT_STORE_REGISTER (regnum))
return;
/* Cater for systems like GNU/Linux, that implement threads as
@@ -689,10 +690,7 @@ inf_ptrace_store_register (int regnum)
if (pid == 0)
pid = ptid_get_pid (inferior_ptid);
- /* This isn't really an address, but ptrace thinks of it as one. */
- addr = inf_ptrace_register_u_offset (regnum);
size = register_size (current_gdbarch, regnum);
-
gdb_assert ((size % sizeof (PTRACE_TYPE_RET)) == 0);
buf = alloca (size);
@@ -728,7 +726,8 @@ inf_ptrace_store_registers (int regnum)
particular register is stored. */
struct target_ops *
-inf_ptrace_trad_target (CORE_ADDR (*register_u_offset)(int))
+inf_ptrace_trad_target (CORE_ADDR (*register_u_offset)
+ (struct gdbarch *, int, int))
{
struct target_ops *t = inf_ptrace_target();
diff -urNp gdb-orig/gdb/inf-ptrace.h gdb-head/gdb/inf-ptrace.h
--- gdb-orig/gdb/inf-ptrace.h 2007-04-26 02:54:20.000000000 +0200
+++ gdb-head/gdb/inf-ptrace.h 2007-05-05 01:25:52.201066772 +0200
@@ -32,6 +32,7 @@ extern struct target_ops *inf_ptrace_tar
particular register is stored. */
extern struct target_ops *
- inf_ptrace_trad_target (CORE_ADDR (*register_u_offset)(int));
+ inf_ptrace_trad_target (CORE_ADDR (*register_u_offset)
+ (struct gdbarch *, int, int));
#endif
diff -urNp gdb-orig/gdb/linux-nat.c gdb-head/gdb/linux-nat.c
--- gdb-orig/gdb/linux-nat.c 2007-05-05 01:03:33.206458709 +0200
+++ gdb-head/gdb/linux-nat.c 2007-05-05 01:15:19.866585303 +0200
@@ -3196,7 +3196,7 @@ linux_target (void)
}
struct target_ops *
-linux_trad_target (CORE_ADDR (*register_u_offset)(int))
+linux_trad_target (CORE_ADDR (*register_u_offset)(struct gdbarch *, int, int))
{
struct target_ops *t;
diff -urNp gdb-orig/gdb/linux-nat.h gdb-head/gdb/linux-nat.h
--- gdb-orig/gdb/linux-nat.h 2007-04-26 02:54:20.000000000 +0200
+++ gdb-head/gdb/linux-nat.h 2007-05-05 01:15:19.909579144 +0200
@@ -91,7 +91,7 @@ struct target_ops * linux_target (void);
/* Create a generic GNU/Linux target using traditional
ptrace register access. */
struct target_ops *
-linux_trad_target (CORE_ADDR (*register_u_offset)(int));
+linux_trad_target (CORE_ADDR (*register_u_offset)(struct gdbarch *, int, int));
/* Register the customized GNU/Linux target. This should be used
instead of calling add_target directly. */
diff -urNp gdb-orig/gdb/mips-linux-nat.c gdb-head/gdb/mips-linux-nat.c
--- gdb-orig/gdb/mips-linux-nat.c 2007-05-05 01:03:33.289446808 +0200
+++ gdb-head/gdb/mips-linux-nat.c 2007-05-05 01:39:35.002981874 +0200
@@ -46,112 +46,75 @@ static int have_ptrace_regsets = 1;
void (*super_fetch_registers) (int);
void (*super_store_registers) (int);
-/* Pseudo registers can not be read. ptrace does not provide a way to
- read (or set) MIPS_PS_REGNUM, and there's no point in reading or
- setting MIPS_ZERO_REGNUM. We also can not set BADVADDR, CAUSE, or
- FCRIR via ptrace(). */
-
-int
-mips_linux_cannot_fetch_register (int regno)
-{
- if (regno > MIPS_ZERO_REGNUM && regno < MIPS_ZERO_REGNUM + 32)
- return 0;
- else if (regno >= mips_regnum (current_gdbarch)->fp0
- && regno <= mips_regnum (current_gdbarch)->fp0 + 32)
- return 0;
- else if (regno == mips_regnum (current_gdbarch)->lo
- || regno == mips_regnum (current_gdbarch)->hi
- || regno == mips_regnum (current_gdbarch)->badvaddr
- || regno == mips_regnum (current_gdbarch)->cause
- || regno == mips_regnum (current_gdbarch)->pc
- || regno == mips_regnum (current_gdbarch)->fp_control_status
- || regno == mips_regnum (current_gdbarch)->fp_implementation_revision)
- return 0;
- else
- return 1;
-}
-
-int
-mips_linux_cannot_store_register (int regno)
-{
- if (regno > MIPS_ZERO_REGNUM && regno < MIPS_ZERO_REGNUM + 32)
- return 0;
- else if (regno >= FP0_REGNUM && regno <= FP0_REGNUM + 32)
- return 0;
- else if (regno == mips_regnum (current_gdbarch)->lo
- || regno == mips_regnum (current_gdbarch)->hi
- || regno == mips_regnum (current_gdbarch)->pc
- || regno == mips_regnum (current_gdbarch)->fp_control_status)
- return 0;
- else
- return 1;
-}
-
/* Map gdb internal register number to ptrace ``address''.
- These ``addresses'' are normally defined in <asm/ptrace.h>. */
+ These ``addresses'' are normally defined in <asm/ptrace.h>.
+
+ ptrace does not provide a way to read (or set) MIPS_PS_REGNUM,
+ and there's no point in reading or setting MIPS_ZERO_REGNUM.
+ We also can not set BADVADDR, CAUSE, or FCRIR via ptrace(). */
static CORE_ADDR
-mips_linux_register_addr (int regno)
+mips_linux_register_addr (struct gdbarch *gdbarch, int regno, int store)
{
- int regaddr;
+ CORE_ADDR regaddr;
if (regno < 0 || regno >= NUM_REGS)
error (_("Bogon register number %d."), regno);
- if (regno < 32)
+ if (regno > MIPS_ZERO_REGNUM && regno < MIPS_ZERO_REGNUM + 32)
regaddr = regno;
- else if ((regno >= mips_regnum (current_gdbarch)->fp0)
- && (regno < mips_regnum (current_gdbarch)->fp0 + 32))
- regaddr = FPR_BASE + (regno - mips_regnum (current_gdbarch)->fp0);
- else if (regno == mips_regnum (current_gdbarch)->pc)
+ else if ((regno >= mips_regnum (gdbarch)->fp0)
+ && (regno < mips_regnum (gdbarch)->fp0 + 32))
+ regaddr = FPR_BASE + (regno - mips_regnum (gdbarch)->fp0);
+ else if (regno == mips_regnum (gdbarch)->pc)
regaddr = PC;
- else if (regno == mips_regnum (current_gdbarch)->cause)
- regaddr = CAUSE;
- else if (regno == mips_regnum (current_gdbarch)->badvaddr)
- regaddr = BADVADDR;
- else if (regno == mips_regnum (current_gdbarch)->lo)
+ else if (regno == mips_regnum (gdbarch)->cause)
+ regaddr = store? (CORE_ADDR) -1 : CAUSE;
+ else if (regno == mips_regnum (gdbarch)->badvaddr)
+ regaddr = store? (CORE_ADDR) -1 : BADVADDR;
+ else if (regno == mips_regnum (gdbarch)->lo)
regaddr = MMLO;
- else if (regno == mips_regnum (current_gdbarch)->hi)
+ else if (regno == mips_regnum (gdbarch)->hi)
regaddr = MMHI;
- else if (regno == mips_regnum (current_gdbarch)->fp_control_status)
+ else if (regno == mips_regnum (gdbarch)->fp_control_status)
regaddr = FPC_CSR;
- else if (regno == mips_regnum (current_gdbarch)->fp_implementation_revision)
- regaddr = FPC_EIR;
+ else if (regno == mips_regnum (gdbarch)->fp_implementation_revision)
+ regaddr = store? (CORE_ADDR) -1 : FPC_EIR;
else
- error (_("Unknowable register number %d."), regno);
+ regaddr = (CORE_ADDR) -1;
return regaddr;
}
static CORE_ADDR
-mips64_linux_register_addr (int regno)
+mips64_linux_register_addr (struct gdbarch *gdbarch, int regno, int store)
{
- int regaddr;
+ CORE_ADDR regaddr;
if (regno < 0 || regno >= NUM_REGS)
error (_("Bogon register number %d."), regno);
- if (regno < 32)
+ if (regno > MIPS_ZERO_REGNUM && regno < MIPS_ZERO_REGNUM + 32)
regaddr = regno;
- else if ((regno >= mips_regnum (current_gdbarch)->fp0)
- && (regno < mips_regnum (current_gdbarch)->fp0 + 32))
+ else if ((regno >= mips_regnum (gdbarch)->fp0)
+ && (regno < mips_regnum (gdbarch)->fp0 + 32))
regaddr = MIPS64_FPR_BASE + (regno - FP0_REGNUM);
- else if (regno == mips_regnum (current_gdbarch)->pc)
+ else if (regno == mips_regnum (gdbarch)->pc)
regaddr = MIPS64_PC;
- else if (regno == mips_regnum (current_gdbarch)->cause)
- regaddr = MIPS64_CAUSE;
- else if (regno == mips_regnum (current_gdbarch)->badvaddr)
- regaddr = MIPS64_BADVADDR;
- else if (regno == mips_regnum (current_gdbarch)->lo)
+ else if (regno == mips_regnum (gdbarch)->cause)
+ regaddr = store? (CORE_ADDR) -1 : MIPS64_CAUSE;
+ else if (regno == mips_regnum (gdbarch)->badvaddr)
+ regaddr = store? (CORE_ADDR) -1 : MIPS64_BADVADDR;
+ else if (regno == mips_regnum (gdbarch)->lo)
regaddr = MIPS64_MMLO;
- else if (regno == mips_regnum (current_gdbarch)->hi)
+ else if (regno == mips_regnum (gdbarch)->hi)
regaddr = MIPS64_MMHI;
- else if (regno == mips_regnum (current_gdbarch)->fp_control_status)
+ else if (regno == mips_regnum (gdbarch)->fp_control_status)
regaddr = MIPS64_FPC_CSR;
- else if (regno == mips_regnum (current_gdbarch)->fp_implementation_revision)
- regaddr = MIPS64_FPC_EIR;
+ else if (regno == mips_regnum (gdbarch)->fp_implementation_revision)
+ regaddr = store? (CORE_ADDR) -1 : MIPS64_FPC_EIR;
else
- error (_("Unknowable register number %d."), regno);
+ regaddr = (CORE_ADDR) -1;
return regaddr;
}
@@ -359,12 +322,12 @@ mips64_linux_store_registers (int regnum
REGNO. */
static CORE_ADDR
-mips_linux_register_u_offset (int regno)
+mips_linux_register_u_offset (struct gdbarch *gdbarch, int regno, int store_p)
{
- if (mips_abi_regsize (current_gdbarch) == 8)
- return mips64_linux_register_addr (regno);
+ if (mips_abi_regsize (gdbarch) == 8)
+ return mips64_linux_register_addr (gdbarch, regno, store_p);
else
- return mips_linux_register_addr (regno);
+ return mips_linux_register_addr (gdbarch, regno, store_p);
}
void _initialize_mips_linux_nat (void);
diff -urNp gdb-orig/gdb/vax-nat.c gdb-head/gdb/vax-nat.c
--- gdb-orig/gdb/vax-nat.c 2007-04-26 02:54:20.000000000 +0200
+++ gdb-head/gdb/vax-nat.c 2007-05-05 01:15:19.931575993 +0200
@@ -69,7 +69,7 @@ vax_register_u_addr (CORE_ADDR u_ar0, in
}
static CORE_ADDR
-vax_register_u_offset (int regnum)
+vax_register_u_offset (struct gdbarch *gdbarch, int regnum, int store_p)
{
size_t u_ar0_offset = offsetof (struct user, u_ar0);
CORE_ADDR u_ar0;
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com