This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[rfc/rft] [3/4] Untangle register_addr - v2 - mips-linux


Hello,

this is the updated mips-linux patch.  Main difference is moving
mips_linux_cannot_fetch_register and mips_linux_cannot_store_register
to mips-linux-tdep.c and installing them as gdbarch callbacks.

Tested by building --target=mips-linux and --host=mips-linux.

Bye,
Ulrich

ChangeLog:

	* config/mips/linux.mh (NAT_FILE): Set to config/nm-linux.h.
	* config/mips/nm-linux.h: Delete file.
	* mips-linux-nat.c: No longer include "gdbcore.h".
	(mips_linux_cannot_fetch_register): Move to mips-linux-tdep.c
	(mips_linux_cannot_store_register): Likewise.
	(mips_linux_register_addr): Move from mips-linux-tdep.c.
	(mips64_linux_register_addr): Likewise.
	(mips_linux_register_u_offset): Call mips_linux_cannot_fetch_register
	and mips_linux_cannot_store_register instead of CANNOT_FETCH_REGISTER
	and CANNOT_STORE_REGISTER.  Call mips_linux_register_addr or
	mips64_linux_register_addr instead of register_addr.
	* mips-linux-tdep.c (mips_linux_cannot_fetch_register,
	mips_linux_cannot_store_register): Move from mips-linux-nat.c.
	(mips_linux_register_addr, mips64_linux_register_addr): Move to
	mips-linux-nat.c.
	(register_addr): Remove.
	(register_addr_data, init_register_addr_data): Remove.
	(_initialize_mips_linux_tdep): Do not initialize register_addr_data.
	(set_mips_linux_register_addr): Remove.
	(mips_linux_init_abi): Do not call set_mips_linux_register_addr.
	Register mips_linux_cannot_fetch/store_register.


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-14 18:08:00.000000000 +0200
+++ gdb-head/gdb/config/mips/linux.mh	2007-04-23 16:10:42.934002816 +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-23 16:14:22.639140002 +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/mips-linux-nat.c gdb-head/gdb/mips-linux-nat.c
--- gdb-orig/gdb/mips-linux-nat.c	2007-04-23 16:14:30.098275103 +0200
+++ gdb-head/gdb/mips-linux-nat.c	2007-04-23 16:12:18.789000720 +0200
@@ -26,7 +26,6 @@
 #include "target.h"
 #include "linux-nat.h"
 #include "mips-linux-tdep.h"
-#include "gdbcore.h"
 
 #include "gdb_proc_service.h"
 
@@ -46,45 +45,73 @@ 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;
+/* Map gdb internal register number to ptrace ``address''.
+   These ``addresses'' are normally defined in <asm/ptrace.h>.  */
+
+static CORE_ADDR
+mips_linux_register_addr (int regno)
+{
+  int regaddr;
+
+  if (regno < 0 || regno >= NUM_REGS)
+    error (_("Bogon register number %d."), regno);
+
+  if (regno < 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)
+    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)
+    regaddr = MMLO;
+  else if (regno == mips_regnum (current_gdbarch)->hi)
+    regaddr = MMHI;
+  else if (regno == mips_regnum (current_gdbarch)->fp_control_status)
+    regaddr = FPC_CSR;
+  else if (regno == mips_regnum (current_gdbarch)->fp_implementation_revision)
+    regaddr = FPC_EIR;
   else
-    return 1;
+    error (_("Unknowable register number %d."), regno);
+
+  return regaddr;
 }
 
-int
-mips_linux_cannot_store_register (int regno)
+static CORE_ADDR
+mips64_linux_register_addr (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;
+  int regaddr;
+
+  if (regno < 0 || regno >= NUM_REGS)
+    error (_("Bogon register number %d."), regno);
+
+  if (regno < 32)
+    regaddr = regno;
+  else if ((regno >= mips_regnum (current_gdbarch)->fp0)
+	   && (regno < mips_regnum (current_gdbarch)->fp0 + 32))
+    regaddr = MIPS64_FPR_BASE + (regno - FP0_REGNUM);
+  else if (regno == mips_regnum (current_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)
+    regaddr = MIPS64_MMLO;
+  else if (regno == mips_regnum (current_gdbarch)->hi)
+    regaddr = MIPS64_MMHI;
+  else if (regno == mips_regnum (current_gdbarch)->fp_control_status)
+    regaddr = MIPS64_FPC_CSR;
+  else if (regno == mips_regnum (current_gdbarch)->fp_implementation_revision)
+    regaddr = MIPS64_FPC_EIR;
   else
-    return 1;
+    error (_("Unknowable register number %d."), regno);
+
+  return regaddr;
 }
 
 /* Fetch the thread-local storage pointer for libthread_db.  */
@@ -253,10 +280,10 @@ mips64_linux_store_registers (int regnum
 static CORE_ADDR
 mips_linux_register_u_offset (int regno)
 {
-  /* FIXME drow/2005-09-04: The hardcoded use of register_addr should go
-     away.  This requires disentangling the various definitions of it
-     (particularly alpha-nat.c's).  */
-  return register_addr (regno, 0);
+  if (mips_abi_regsize (current_gdbarch) == 8)
+    return mips64_linux_register_addr (regno);
+  else
+    return mips_linux_register_addr (regno);
 }
 
 void _initialize_mips_linux_nat (void);
diff -urNp gdb-orig/gdb/mips-linux-tdep.c gdb-head/gdb/mips-linux-tdep.c
--- gdb-orig/gdb/mips-linux-tdep.c	2007-04-14 18:08:00.000000000 +0200
+++ gdb-head/gdb/mips-linux-tdep.c	2007-04-23 16:13:52.199813455 +0200
@@ -218,42 +218,6 @@ mips_fill_fpregset (mips_elf_fpregset_t 
     }
 }
 
-/* Map gdb internal register number to ptrace ``address''.
-   These ``addresses'' are normally defined in <asm/ptrace.h>.  */
-
-static CORE_ADDR
-mips_linux_register_addr (int regno, CORE_ADDR blockend)
-{
-  int regaddr;
-
-  if (regno < 0 || regno >= NUM_REGS)
-    error (_("Bogon register number %d."), regno);
-
-  if (regno < 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)
-    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)
-    regaddr = MMLO;
-  else if (regno == mips_regnum (current_gdbarch)->hi)
-    regaddr = MMHI;
-  else if (regno == mips_regnum (current_gdbarch)->fp_control_status)
-    regaddr = FPC_CSR;
-  else if (regno == mips_regnum (current_gdbarch)->fp_implementation_revision)
-    regaddr = FPC_EIR;
-  else
-    error (_("Unknowable register number %d."), regno);
-
-  return regaddr;
-}
-
 /* Support for 64-bit ABIs.  */
 
 /* Figure out where the longjmp will land.
@@ -487,42 +451,6 @@ mips64_fill_fpregset (mips64_elf_fpregse
 }
 
 
-/* Map gdb internal register number to ptrace ``address''.
-   These ``addresses'' are normally defined in <asm/ptrace.h>.  */
-
-static CORE_ADDR
-mips64_linux_register_addr (int regno, CORE_ADDR blockend)
-{
-  int regaddr;
-
-  if (regno < 0 || regno >= NUM_REGS)
-    error (_("Bogon register number %d."), regno);
-
-  if (regno < 32)
-    regaddr = regno;
-  else if ((regno >= mips_regnum (current_gdbarch)->fp0)
-	   && (regno < mips_regnum (current_gdbarch)->fp0 + 32))
-    regaddr = MIPS64_FPR_BASE + (regno - FP0_REGNUM);
-  else if (regno == mips_regnum (current_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)
-    regaddr = MIPS64_MMLO;
-  else if (regno == mips_regnum (current_gdbarch)->hi)
-    regaddr = MIPS64_MMHI;
-  else if (regno == mips_regnum (current_gdbarch)->fp_control_status)
-    regaddr = MIPS64_FPC_CSR;
-  else if (regno == mips_regnum (current_gdbarch)->fp_implementation_revision)
-    regaddr = MIPS64_FPC_EIR;
-  else
-    error (_("Unknowable register number %d."), regno);
-
-  return regaddr;
-}
-
 /*  Use a local version of this function to get the correct types for
     regsets, until multi-arch core support is ready.  */
 
@@ -584,35 +512,6 @@ static struct core_fns regset_core_fns =
   NULL					/* next */
 };
 
-/* Handle for obtaining pointer to the current register_addr()
-   function for a given architecture.  */
-static struct gdbarch_data *register_addr_data;
-
-CORE_ADDR
-register_addr (int regno, CORE_ADDR blockend)
-{
-  CORE_ADDR (*register_addr_ptr) (int, CORE_ADDR) =
-    gdbarch_data (current_gdbarch, register_addr_data);
-
-  gdb_assert (register_addr_ptr != 0);
-
-  return register_addr_ptr (regno, blockend);
-}
-
-static void
-set_mips_linux_register_addr (struct gdbarch *gdbarch,
-                              CORE_ADDR (*register_addr_ptr) (int,
-							      CORE_ADDR))
-{
-  deprecated_set_gdbarch_data (gdbarch, register_addr_data,
-			       register_addr_ptr);
-}
-
-static void *
-init_register_addr_data (struct gdbarch *gdbarch)
-{
-  return 0;
-}
 
 /* Check the code at PC for a dynamic linker lazy resolution stub.
    Because they aren't in the .plt section, we pattern-match on the
@@ -1123,6 +1022,49 @@ fill_fpregset (mips_elf_fpregset_t *fpre
     mips64_fill_fpregset ((void *) fpregsetp, regno);
 }
 
+
+/* 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().  */
+
+static 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;
+}
+
+static 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;
+}
+
+
 /* Initialize one of the GNU/Linux OS ABIs.  */
 
 static void
@@ -1139,7 +1081,6 @@ mips_linux_init_abi (struct gdbarch_info
 	                                mips_linux_get_longjmp_target);
 	set_solib_svr4_fetch_link_map_offsets
 	  (gdbarch, svr4_ilp32_fetch_link_map_offsets);
-	set_mips_linux_register_addr (gdbarch, mips_linux_register_addr);
 	tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_sigframe);
 	tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_rt_sigframe);
 	break;
@@ -1148,7 +1089,6 @@ mips_linux_init_abi (struct gdbarch_info
 	                                mips_linux_get_longjmp_target);
 	set_solib_svr4_fetch_link_map_offsets
 	  (gdbarch, svr4_ilp32_fetch_link_map_offsets);
-	set_mips_linux_register_addr (gdbarch, mips64_linux_register_addr);
 	set_gdbarch_long_double_bit (gdbarch, 128);
 	/* These floatformats should probably be renamed.  MIPS uses
 	   the same 128-bit IEEE floating point format that IA-64 uses,
@@ -1162,7 +1102,6 @@ mips_linux_init_abi (struct gdbarch_info
 	                                mips64_linux_get_longjmp_target);
 	set_solib_svr4_fetch_link_map_offsets
 	  (gdbarch, svr4_lp64_fetch_link_map_offsets);
-	set_mips_linux_register_addr (gdbarch, mips64_linux_register_addr);
 	set_gdbarch_long_double_bit (gdbarch, 128);
 	/* These floatformats should probably be renamed.  MIPS uses
 	   the same 128-bit IEEE floating point format that IA-64 uses,
@@ -1179,6 +1118,9 @@ mips_linux_init_abi (struct gdbarch_info
   set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
   set_gdbarch_skip_solib_resolver (gdbarch, mips_linux_skip_resolver);
 
+  set_gdbarch_cannot_fetch_register (gdbarch, mips_linux_cannot_fetch_register);
+  set_gdbarch_cannot_store_register (gdbarch, mips_linux_cannot_store_register);
+
   set_gdbarch_software_single_step (gdbarch, mips_software_single_step);
 
   /* Enable TLS support.  */
@@ -1191,9 +1133,6 @@ _initialize_mips_linux_tdep (void)
 {
   const struct bfd_arch_info *arch_info;
 
-  register_addr_data =
-    gdbarch_data_register_post_init (init_register_addr_data);
-
   for (arch_info = bfd_lookup_arch (bfd_arch_mips, 0);
        arch_info != NULL;
        arch_info = arch_info->next)
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]