This is the mail archive of the gdb-patches@sources.redhat.com 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]

Re: [patch/rfc] Revise REGISTER_SIM_REGNO()


> +enum {
> +  /* Normal sane architecture.  The corresponding register cache
> +     entry is zero filled and the register is marked as unavailable.  */
> +  SIM_REGNO_UNAVAILABLE = -1,
> 
> Does:
>     SIM_REGNO_DNE = -1,
> sound better?

(I spelt it out - SIM_REGNO_DOES_NOT_EXIST)

> For the moment remote-sim.c would mark the register as unavailable (fixme comment).  At least, though, the name is right.
> 
> +  /* For possible backward compatibility.  The register cache doesn't
> +     have a corresponding name.  Skip the register entirely.  */
> +  LEGACY_SIM_REGNO_IGNORE = -2
> +};

as per the attached.  Committed.

Andrew

2002-05-28  Andrew Cagney  <ac131313@redhat.com>

	* sim-regno.h: New file.
	* Makefile.in (sim_regno_h): Define.
	(d10v-tdep.o, remote-sim.o): Add dependency on $(sim_regno_h).
	* remote-sim.c: Include "sim-regno.h" and "gdb_assert.h".
	(legacy_register_sim_regno): New function.
	(one2one_register_sim_regno): New function.
	(gdbsim_fetch_register): Rewrite.
	(gdbsim_store_register): Only store a register when
	REGISTER_SIM_REGNO is valid.
	* d10v-tdep.c: Include "sim-regno.h".
	(d10v_ts2_register_sim_regno): Add legacy_regiter_sim_regno check.
	(d10v_ts3_register_sim_regno): Ditto.
	* gdbarch.sh: Include "sim-regno.h".
	(REGISTER_SIM_REGNO): Set default to legacy_register_sim_regno.
	* gdbarch.h, gdbarch.c: Regenerate.
	* arch-utils.h (default_register_sim_regno): Delete declaration.
	* arch-utils.c (default_register_sim_regno): Delete function.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.200
diff -u -r1.200 Makefile.in
--- Makefile.in	24 May 2002 00:12:16 -0000	1.200
+++ Makefile.in	29 May 2002 01:22:55 -0000
@@ -652,6 +652,7 @@
 ser_unix_h =	ser-unix.h
 serial_h =	serial.h
 sh_tdep_h =	sh-tdep.h osabi.h
+sim_regno_h =	sim-regno.h
 solist_h =	solist.h
 source_h =	source.h
 stabsread_h =	stabsread.h
@@ -1405,7 +1406,8 @@
 d10v-tdep.o: d10v-tdep.c $(defs_h) $(frame_h) $(obstack_h) $(symtab_h) \
 	$(gdbtypes_h) $(gdbcmd_h) $(gdbcore_h) $(gdb_string_h) $(value_h) \
 	$(inferior_h) $(dis-asm_h) $(symfile_h) $(objfiles_h) $(language_h) \
-	$(arch_utils_h) $(regcache_h) $(floatformat_h) $(sim_d10v_h)
+	$(arch_utils_h) $(regcache_h) $(floatformat_h) $(sim_d10v_h) \
+	$(sim_regno_h)
 
 dbxread.o: dbxread.c $(breakpoint_h) $(buildsym_h) $(command_h) \
 	$(complaints_h) $(defs_h) $(expression_h) $(gdb_stabs_h) $(gdbcore_h) \
@@ -1998,7 +2000,8 @@
 
 remote-sim.o: remote-sim.c $(defs_h) $(inferior_h) $(value_h) $(gdb_string_h) \
 	$(terminal_h) $(target_h) $(gdbcore_h) $(INCLUDE_DIR)/callback.h \
-	$(remote_sim_h) $(remote_utils_h) $(command_h) $(regcache_h) 
+	$(remote_sim_h) $(remote_utils_h) $(command_h) $(regcache_h) \
+	$(sim_regno_h)
 
 remote-st.o: remote-st.c $(defs_h) $(gdbcore_h) $(serial_h) \
 	$(target_h) $(gdb_string_h) $(regcache_h)
Index: arch-utils.c
===================================================================
RCS file: /cvs/src/src/gdb/arch-utils.c,v
retrieving revision 1.57
diff -u -r1.57 arch-utils.c
--- arch-utils.c	12 May 2002 03:09:11 -0000	1.57
+++ arch-utils.c	29 May 2002 01:22:56 -0000
@@ -267,13 +267,6 @@
   return 0;
 }
 
-int
-default_register_sim_regno (int num)
-{
-  return num;
-}
-
-
 CORE_ADDR
 core_addr_identity (CORE_ADDR addr)
 {
Index: arch-utils.h
===================================================================
RCS file: /cvs/src/src/gdb/arch-utils.h,v
retrieving revision 1.32
diff -u -r1.32 arch-utils.h
--- arch-utils.h	12 May 2002 03:09:11 -0000	1.32
+++ arch-utils.h	29 May 2002 01:22:56 -0000
@@ -94,11 +94,6 @@
 
 extern int (*target_architecture_hook) (const struct bfd_arch_info *);
 
-
-/* Default raw->sim register re-numbering - does nothing. */
-
-extern int default_register_sim_regno (int reg_nr);
-
 /* Identity function on a CORE_ADDR.  Just returns its parameter.  */
 
 extern CORE_ADDR core_addr_identity (CORE_ADDR addr);
Index: d10v-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/d10v-tdep.c,v
retrieving revision 1.42
diff -u -r1.42 d10v-tdep.c
--- d10v-tdep.c	24 May 2002 00:12:16 -0000	1.42
+++ d10v-tdep.c	29 May 2002 01:22:57 -0000
@@ -41,6 +41,7 @@
 
 #include "floatformat.h"
 #include "gdb/sim-d10v.h"
+#include "sim-regno.h"
 
 struct frame_extra_info
   {
@@ -296,6 +297,8 @@
 static int
 d10v_ts2_register_sim_regno (int nr)
 {
+  if (legacy_register_sim_regno (nr) < 0)
+    return legacy_register_sim_regno (nr);
   if (nr >= TS2_IMAP0_REGNUM
       && nr < TS2_IMAP0_REGNUM + NR_IMAP_REGS)
     return nr - TS2_IMAP0_REGNUM + SIM_D10V_IMAP0_REGNUM;
@@ -310,6 +313,8 @@
 static int
 d10v_ts3_register_sim_regno (int nr)
 {
+  if (legacy_register_sim_regno (nr) < 0)
+    return legacy_register_sim_regno (nr);
   if (nr >= TS3_IMAP0_REGNUM
       && nr < TS3_IMAP0_REGNUM + NR_IMAP_REGS)
     return nr - TS3_IMAP0_REGNUM + SIM_D10V_IMAP0_REGNUM;
Index: gdbarch.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.c,v
retrieving revision 1.127
diff -u -r1.127 gdbarch.c
--- gdbarch.c	13 May 2002 17:20:57 -0000	1.127
+++ gdbarch.c	29 May 2002 01:22:58 -0000
@@ -39,6 +39,7 @@
 #if GDB_MULTI_ARCH
 #include "gdbcmd.h"
 #include "inferior.h" /* enum CALL_DUMMY_LOCATION et.al. */
+#include "sim-regno.h"		/* For legacy_register_sim_regno().  */
 #else
 /* Just include everything in sight so that the every old definition
    of macro is visible. */
@@ -488,7 +489,7 @@
   current_gdbarch->max_register_virtual_size = -1;
   current_gdbarch->do_registers_info = do_registers_info;
   current_gdbarch->print_float_info = default_print_float_info;
-  current_gdbarch->register_sim_regno = default_register_sim_regno;
+  current_gdbarch->register_sim_regno = legacy_register_sim_regno;
   current_gdbarch->cannot_fetch_register = cannot_register_not;
   current_gdbarch->cannot_store_register = cannot_register_not;
   current_gdbarch->use_generic_dummy_frames = -1;
Index: gdbarch.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.h,v
retrieving revision 1.95
diff -u -r1.95 gdbarch.h
--- gdbarch.h	13 May 2002 17:20:58 -0000	1.95
+++ gdbarch.h	29 May 2002 01:22:59 -0000
@@ -40,6 +40,7 @@
 /* Pull in function declarations refered to, indirectly, via macros.  */
 #include "value.h" /* For default_coerce_float_to_double which is referenced by a macro.  */
 #include "inferior.h"		/* For unsigned_address_to_pointer().  */
+#include "sim-regno.h"		/* For legacy_register_sim_regno().  */
 #endif
 
 struct frame_info;
@@ -811,7 +812,7 @@
 
 /* Default (function) for non- multi-arch platforms. */
 #if (!GDB_MULTI_ARCH) && !defined (REGISTER_SIM_REGNO)
-#define REGISTER_SIM_REGNO(reg_nr) (default_register_sim_regno (reg_nr))
+#define REGISTER_SIM_REGNO(reg_nr) (legacy_register_sim_regno (reg_nr))
 #endif
 
 typedef int (gdbarch_register_sim_regno_ftype) (int reg_nr);
Index: gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.138
diff -u -r1.138 gdbarch.sh
--- gdbarch.sh	13 May 2002 17:20:58 -0000	1.138
+++ gdbarch.sh	29 May 2002 01:23:01 -0000
@@ -471,7 +471,7 @@
 f:2:PRINT_FLOAT_INFO:void:print_float_info:void::::default_print_float_info::0
 # MAP a GDB RAW register number onto a simulator register number.  See
 # also include/...-sim.h.
-f:2:REGISTER_SIM_REGNO:int:register_sim_regno:int reg_nr:reg_nr:::default_register_sim_regno::0
+f:2:REGISTER_SIM_REGNO:int:register_sim_regno:int reg_nr:reg_nr:::legacy_register_sim_regno::0
 F:2:REGISTER_BYTES_OK:int:register_bytes_ok:long nr_bytes:nr_bytes::0:0
 f:2:CANNOT_FETCH_REGISTER:int:cannot_fetch_register:int regnum:regnum:::cannot_register_not::0
 f:2:CANNOT_STORE_REGISTER:int:cannot_store_register:int regnum:regnum:::cannot_register_not::0
@@ -759,6 +759,7 @@
 /* Pull in function declarations refered to, indirectly, via macros.  */
 #include "value.h" /* For default_coerce_float_to_double which is referenced by a macro.  */
 #include "inferior.h"		/* For unsigned_address_to_pointer().  */
+#include "sim-regno.h"		/* For legacy_register_sim_regno().  */
 #endif
 
 struct frame_info;
@@ -1220,6 +1221,7 @@
 #if GDB_MULTI_ARCH
 #include "gdbcmd.h"
 #include "inferior.h" /* enum CALL_DUMMY_LOCATION et.al. */
+#include "sim-regno.h"		/* For legacy_register_sim_regno().  */
 #else
 /* Just include everything in sight so that the every old definition
    of macro is visible. */
Index: remote-sim.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-sim.c,v
retrieving revision 1.21
diff -u -r1.21 remote-sim.c
--- remote-sim.c	20 Jan 2002 19:26:48 -0000	1.21
+++ remote-sim.c	29 May 2002 01:23:01 -0000
@@ -40,6 +40,8 @@
 #include "remote-utils.h"
 #include "command.h"
 #include "regcache.h"
+#include "gdb_assert.h"
+#include "sim-regno.h"
 
 /* Prototypes */
 
@@ -276,46 +278,88 @@
     }
 }
 
+int
+legacy_register_sim_regno (int regnum)
+{
+  /* Only makes sense to supply raw registers.  */
+  gdb_assert (regnum >= 0 && regnum < NUM_REGS);
+  /* NOTE: cagney/2002-05-13: The old code did it this way and it is
+     suspected that some GDB/SIM combinations may rely on this
+     behavour.  The default should be one2one_register_sim_regno
+     (below).  */
+  if (REGISTER_NAME (regnum) != NULL
+      && REGISTER_NAME (regnum)[0] != '\0')
+    return regnum;
+  else
+    return LEGACY_SIM_REGNO_IGNORE;
+}
+
+int
+one2one_register_sim_regno (int regnum)
+{
+  /* Only makes sense to supply raw registers.  */
+  gdb_assert (regnum >= 0 && regnum < NUM_REGS);
+  return regnum;
+}
+
 static void
 gdbsim_fetch_register (int regno)
 {
-  static int warn_user = 1;
   if (regno == -1)
     {
       for (regno = 0; regno < NUM_REGS; regno++)
 	gdbsim_fetch_register (regno);
+      return;
     }
-  else if (REGISTER_NAME (regno) != NULL
-	   && *REGISTER_NAME (regno) != '\0')
+
+  switch (REGISTER_SIM_REGNO (regno))
     {
-      char buf[MAX_REGISTER_RAW_SIZE];
-      int nr_bytes;
-      if (REGISTER_SIM_REGNO (regno) >= 0)
+    case LEGACY_SIM_REGNO_IGNORE:
+      break;
+    case SIM_REGNO_DOES_NOT_EXIST:
+      {
+	/* For moment treat a `does not exist' register the same way
+           as an ``unavailable'' register.  */
+	char *buf = alloca (MAX_REGISTER_RAW_SIZE);
+	int nr_bytes;
+	memset (buf, 0, MAX_REGISTER_RAW_SIZE);
+	supply_register (regno, buf);
+	set_register_cached (regno, -1);
+	break;
+      }
+    default:
+      {
+	static int warn_user = 1;
+	char *buf = alloca (MAX_REGISTER_RAW_SIZE);
+	int nr_bytes;
+	gdb_assert (regno >= 0 && regno < NUM_REGS);
+	memset (buf, 0, MAX_REGISTER_RAW_SIZE);
 	nr_bytes = sim_fetch_register (gdbsim_desc,
 				       REGISTER_SIM_REGNO (regno),
 				       buf, REGISTER_RAW_SIZE (regno));
-      else
-	nr_bytes = 0;
-      if (nr_bytes == 0)
-	/* register not applicable, supply zero's */
-	memset (buf, 0, MAX_REGISTER_RAW_SIZE);
-      else if (nr_bytes > 0 && nr_bytes != REGISTER_RAW_SIZE (regno)
-	       && warn_user)
-	{
-	  fprintf_unfiltered (gdb_stderr,
-			      "Size of register %s (%d/%d) incorrect (%d instead of %d))",
-			      REGISTER_NAME (regno),
-			      regno, REGISTER_SIM_REGNO (regno),
-			      nr_bytes, REGISTER_RAW_SIZE (regno));
-	  warn_user = 0;
-	}
-      supply_register (regno, buf);
-      if (sr_get_debug ())
-	{
-	  printf_filtered ("gdbsim_fetch_register: %d", regno);
-	  /* FIXME: We could print something more intelligible.  */
-	  dump_mem (buf, REGISTER_RAW_SIZE (regno));
-	}
+	if (nr_bytes > 0 && nr_bytes != REGISTER_RAW_SIZE (regno) && warn_user)
+	  {
+	    fprintf_unfiltered (gdb_stderr,
+				"Size of register %s (%d/%d) incorrect (%d instead of %d))",
+				REGISTER_NAME (regno),
+				regno, REGISTER_SIM_REGNO (regno),
+				nr_bytes, REGISTER_RAW_SIZE (regno));
+	    warn_user = 0;
+	  }
+	/* FIXME: cagney/2002-05-27: Should check `nr_bytes == 0'
+	   indicatingthat GDB and the SIM have different ideas about
+	   which registers are fetchable.  */
+	/* Else if (nr_bytes < 0): an old simulator, that doesn't
+	   think to return the register size.  Just assume all is ok.  */
+	supply_register (regno, buf);
+	if (sr_get_debug ())
+	  {
+	    printf_filtered ("gdbsim_fetch_register: %d", regno);
+	    /* FIXME: We could print something more intelligible.  */
+	    dump_mem (buf, REGISTER_RAW_SIZE (regno));
+	  }
+	break;
+      }
     }
 }
 
@@ -327,10 +371,9 @@
     {
       for (regno = 0; regno < NUM_REGS; regno++)
 	gdbsim_store_register (regno);
+      return;
     }
-  else if (REGISTER_NAME (regno) != NULL
-	   && *REGISTER_NAME (regno) != '\0'
-	   && REGISTER_SIM_REGNO (regno) >= 0)
+  else if (REGISTER_SIM_REGNO (regno) >= 0)
     {
       char tmp[MAX_REGISTER_RAW_SIZE];
       int nr_bytes;
@@ -341,6 +384,9 @@
       if (nr_bytes > 0 && nr_bytes != REGISTER_RAW_SIZE (regno))
 	internal_error (__FILE__, __LINE__,
 			"Register size different to expected");
+      /* FIXME: cagney/2002-05-27: Should check `nr_bytes == 0'
+	 indicatingthat GDB and the SIM have different ideas about
+	 which registers are fetchable.  */
       if (sr_get_debug ())
 	{
 	  printf_filtered ("gdbsim_store_register: %d", regno);
Index: sim-regno.h
===================================================================
RCS file: sim-regno.h
diff -N sim-regno.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ sim-regno.h	29 May 2002 01:23:01 -0000
@@ -0,0 +1,50 @@
+/* Generic remote debugging interface for simulators.
+
+   Copyright 2002 Free Software Foundation, Inc.
+
+   Contributed by Red Hat, 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 SIM_REGNO_H
+#define SIM_REGNO_H
+
+/* The REGISTER_SIM_REGNO(REGNUM) method, when there is a
+   corresponding simulator register, returns that register number as a
+   cardinal.  When there is no corresponding register, it returns a
+   negative value.  */
+
+enum sim_regno {
+  /* Normal sane architecture.  The simulator is known to not model
+     this register.  */
+  SIM_REGNO_DOES_NOT_EXIST = -1,
+  /* For possible backward compatibility.  The register cache doesn't
+     have a corresponding name.  Skip the register entirely.  */
+  LEGACY_SIM_REGNO_IGNORE = -2
+};
+
+/* For compatibility with older architectures, returns
+   (LEGACY_SIM_REGNO_IGNORE) when a register doesn't have.  */
+
+extern int legacy_register_sim_regno (int regnum);
+
+/* Treat all raw registers as valid.  */
+
+extern int one2one_register_sim_regno (int regnum);
+
+#endif

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