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]

[commit] Delete generic_target_read_pc


Hello,

This deletes the function generic_target_read_pc(). It's replaced by explicit tests for TARGET_READ_PC and PC_REGNUM in read_pc_pid.

The intent here is to strip away the various nested function calls so that it is very clear where/how read_pc_pid() obtains a PC value.

committed,
Andrew

PS: Notice how read_pc_pid carefully swaps PTID and INFERIOR_PTID.

CORE_ADDR
read_pc_pid (ptid_t ptid)
{
  ptid_t saved_inferior_ptid;
  CORE_ADDR pc_val;

  /* In case ptid != inferior_ptid. */
  saved_inferior_ptid = inferior_ptid;
  inferior_ptid = ptid;

pc_val = TARGET_READ_PC (ptid);

  inferior_ptid = saved_inferior_ptid;
  return pc_val;
}

But check this is, the architecture specific TARGET_READ_PC vis:


static CORE_ADDR
d10v_read_pc (ptid_t ptid)
{
  ptid_t save_ptid;
  CORE_ADDR pc;
  CORE_ADDR retval;

  save_ptid = inferior_ptid;
  inferior_ptid = ptid;
  pc = (int) read_register (D10V_PC_REGNUM);
  inferior_ptid = save_ptid;
  retval = d10v_make_iaddr (pc);
  return retval;
}

is also trying to carefully swap the PTID and INFERIOR_PTID. Left hand VS right hand. Arrg!!
2003-06-07  Andrew Cagney  <cagney@redhat.com>

	* gdbarch.sh (TARGET_READ_PC): Add predicate, remove default.
	* gdbarch.h, gdbarch.c: Re-generate.
	* regcache.c: Update comments on read_pc et.al.
	(generic_target_read_pc): Delete function.
	(read_pc_pid): Try TARGET_READ_PC and PC_REGNUM for a PC register.
	* inferior.h (generic_target_read_pc): Delete declaration.
	* frv-tdep.c (frv_gdbarch_init): Do not set read_pc to
	generic_target_read_pc.
	* sparc-tdep.c (sparc_gdbarch_init): Ditto.
	* sh-tdep.c (sh_gdbarch_init): Ditto.
	* rs6000-tdep.c (rs6000_gdbarch_init): Ditto.
	* m68hc11-tdep.c (m68hc11_gdbarch_init): Ditto.
	
Index: frv-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/frv-tdep.c,v
retrieving revision 1.39
diff -u -r1.39 frv-tdep.c
--- frv-tdep.c	3 Jun 2003 01:24:42 -0000	1.39
+++ frv-tdep.c	7 Jun 2003 16:12:29 -0000
@@ -1099,7 +1099,6 @@
   /* Settings that should be unnecessary.  */
   set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
 
-  set_gdbarch_read_pc (gdbarch, generic_target_read_pc);
   set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
   set_gdbarch_read_sp (gdbarch, generic_target_read_sp);
   set_gdbarch_deprecated_dummy_write_sp (gdbarch, generic_target_write_sp);
Index: gdbarch.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.c,v
retrieving revision 1.218
diff -u -r1.218 gdbarch.c
--- gdbarch.c	2 Jun 2003 02:54:33 -0000	1.218
+++ gdbarch.c	7 Jun 2003 16:13:41 -0000
@@ -501,7 +501,6 @@
   current_gdbarch->ptr_bit = TARGET_INT_BIT;
   current_gdbarch->bfd_vma_bit = TARGET_ARCHITECTURE->bits_per_address;
   current_gdbarch->char_signed = -1;
-  current_gdbarch->read_pc = generic_target_read_pc;
   current_gdbarch->write_pc = generic_target_write_pc;
   current_gdbarch->read_sp = generic_target_read_sp;
   current_gdbarch->virtual_frame_pointer = legacy_virtual_frame_pointer;
@@ -620,7 +619,7 @@
   /* Skip verify of bfd_vma_bit, invalid_p == 0 */
   if (gdbarch->char_signed == -1)
     gdbarch->char_signed = 1;
-  /* Skip verify of read_pc, invalid_p == 0 */
+  /* Skip verify of read_pc, has predicate */
   /* Skip verify of write_pc, invalid_p == 0 */
   /* Skip verify of deprecated_target_read_fp, has predicate */
   /* Skip verify of read_sp, invalid_p == 0 */
@@ -2546,6 +2545,15 @@
                       "gdbarch_dump: TARGET_PTR_BIT = %d\n",
                       TARGET_PTR_BIT);
 #endif
+#ifdef TARGET_READ_PC_P
+  fprintf_unfiltered (file,
+                      "gdbarch_dump: %s # %s\n",
+                      "TARGET_READ_PC_P()",
+                      XSTRING (TARGET_READ_PC_P ()));
+  fprintf_unfiltered (file,
+                      "gdbarch_dump: TARGET_READ_PC_P() = %d\n",
+                      TARGET_READ_PC_P ());
+#endif
 #ifdef TARGET_READ_PC
   fprintf_unfiltered (file,
                       "gdbarch_dump: %s # %s\n",
@@ -2874,6 +2882,13 @@
                          int char_signed)
 {
   gdbarch->char_signed = char_signed;
+}
+
+int
+gdbarch_read_pc_p (struct gdbarch *gdbarch)
+{
+  gdb_assert (gdbarch != NULL);
+  return gdbarch->read_pc != 0;
 }
 
 CORE_ADDR
Index: gdbarch.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.h,v
retrieving revision 1.188
diff -u -r1.188 gdbarch.h
--- gdbarch.h	2 Jun 2003 02:54:33 -0000	1.188
+++ gdbarch.h	7 Jun 2003 16:13:47 -0000
@@ -283,9 +283,29 @@
 #define TARGET_CHAR_SIGNED (gdbarch_char_signed (current_gdbarch))
 #endif
 
+#if defined (TARGET_READ_PC)
+/* Legacy for systems yet to multi-arch TARGET_READ_PC */
+#if !defined (TARGET_READ_PC_P)
+#define TARGET_READ_PC_P() (1)
+#endif
+#endif
+
+/* Default predicate for non- multi-arch targets. */
+#if (!GDB_MULTI_ARCH) && !defined (TARGET_READ_PC_P)
+#define TARGET_READ_PC_P() (0)
+#endif
+
+extern int gdbarch_read_pc_p (struct gdbarch *gdbarch);
+#if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) && defined (TARGET_READ_PC_P)
+#error "Non multi-arch definition of TARGET_READ_PC"
+#endif
+#if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) || !defined (TARGET_READ_PC_P)
+#define TARGET_READ_PC_P() (gdbarch_read_pc_p (current_gdbarch))
+#endif
+
 /* Default (function) for non- multi-arch platforms. */
 #if (!GDB_MULTI_ARCH) && !defined (TARGET_READ_PC)
-#define TARGET_READ_PC(ptid) (generic_target_read_pc (ptid))
+#define TARGET_READ_PC(ptid) (internal_error (__FILE__, __LINE__, "TARGET_READ_PC"), 0)
 #endif
 
 typedef CORE_ADDR (gdbarch_read_pc_ftype) (ptid_t ptid);
Index: gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.240
diff -u -r1.240 gdbarch.sh
--- gdbarch.sh	2 Jun 2003 02:54:34 -0000	1.240
+++ gdbarch.sh	7 Jun 2003 16:13:48 -0000
@@ -426,7 +426,7 @@
 # One if \`char' acts like \`signed char', zero if \`unsigned char'.
 v:2:TARGET_CHAR_SIGNED:int:char_signed::::1:-1:1::::
 #
-f:2:TARGET_READ_PC:CORE_ADDR:read_pc:ptid_t ptid:ptid::0:generic_target_read_pc::0
+F:2:TARGET_READ_PC:CORE_ADDR:read_pc:ptid_t ptid:ptid
 f:2:TARGET_WRITE_PC:void:write_pc:CORE_ADDR val, ptid_t ptid:val, ptid::0:generic_target_write_pc::0
 # This is simply not needed.  See value_of_builtin_frame_fp_reg and
 # call_function_by_hand.
Index: inferior.h
===================================================================
RCS file: /cvs/src/src/gdb/inferior.h,v
retrieving revision 1.55
diff -u -r1.55 inferior.h
--- inferior.h	5 May 2003 17:56:55 -0000	1.55
+++ inferior.h	7 Jun 2003 16:13:49 -0000
@@ -168,8 +168,6 @@
 
 extern CORE_ADDR read_pc_pid (ptid_t);
 
-extern CORE_ADDR generic_target_read_pc (ptid_t);
-
 extern void write_pc (CORE_ADDR);
 
 extern void write_pc_pid (CORE_ADDR, ptid_t);
Index: m68hc11-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/m68hc11-tdep.c,v
retrieving revision 1.69
diff -u -r1.69 m68hc11-tdep.c
--- m68hc11-tdep.c	3 Jun 2003 01:24:42 -0000	1.69
+++ m68hc11-tdep.c	7 Jun 2003 16:13:55 -0000
@@ -1365,7 +1365,6 @@
   set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, m68hc11_frame_init_saved_regs);
   set_gdbarch_frame_args_skip (gdbarch, 0);
 
-  set_gdbarch_read_pc (gdbarch, generic_target_read_pc);
   set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
   set_gdbarch_read_sp (gdbarch, generic_target_read_sp);
   set_gdbarch_deprecated_dummy_write_sp (gdbarch, generic_target_write_sp);
Index: regcache.c
===================================================================
RCS file: /cvs/src/src/gdb/regcache.c,v
retrieving revision 1.82
diff -u -r1.82 regcache.c
--- regcache.c	17 May 2003 05:59:58 -0000	1.82
+++ regcache.c	7 Jun 2003 16:14:00 -0000
@@ -1267,41 +1267,22 @@
 /* read_pc, write_pc, read_sp, deprecated_read_fp, etc.  Special
    handling for registers PC, SP, and FP.  */
 
-/* NOTE: cagney/2001-02-18: The functions generic_target_read_pc(),
-   read_pc_pid(), read_pc(), generic_target_write_pc(),
-   write_pc_pid(), write_pc(), generic_target_read_sp(), read_sp(),
-   generic_target_write_sp(), and deprecated_read_fp(), will
-   eventually be moved out of the reg-cache into either frame.[hc] or
-   to the multi-arch framework.  The are not part of the raw register
-   cache.  */
-
-/* This routine is getting awfully cluttered with #if's.  It's probably
-   time to turn this into READ_PC and define it in the tm.h file.
-   Ditto for write_pc.
-
-   1999-06-08: The following were re-written so that it assumes the
-   existence of a TARGET_READ_PC et.al. macro.  A default generic
-   version of that macro is made available where needed.
-
-   Since the ``TARGET_READ_PC'' et.al. macro is going to be controlled
-   by the multi-arch framework, it will eventually be possible to
-   eliminate the intermediate read_pc_pid().  The client would call
-   TARGET_READ_PC directly. (cagney). */
-
-CORE_ADDR
-generic_target_read_pc (ptid_t ptid)
-{
-#ifdef PC_REGNUM
-  if (PC_REGNUM >= 0)
-    {
-      CORE_ADDR pc_val = ADDR_BITS_REMOVE ((CORE_ADDR) read_register_pid (PC_REGNUM, ptid));
-      return pc_val;
-    }
-#endif
-  internal_error (__FILE__, __LINE__,
-		  "generic_target_read_pc");
-  return 0;
-}
+/* NOTE: cagney/2001-02-18: The functions read_pc_pid(), read_pc(),
+   read_sp(), and deprecated_read_fp(), will eventually be replaced by
+   per-frame methods.  Instead of relying on the global INFERIOR_PTID,
+   they will use the contextual information provided by the FRAME.
+   These functions do not belong in the register cache.  */
+
+/* NOTE: cagney/2003-06-07: The function generic_target_read_sp()
+   should be deleted.  */
+
+/* NOTE: cagney/2003-06-07: The function generic_target_write_sp()
+   should be deleted.  */
+
+/* NOTE: cagney/2003-06-07: The functions generic_target_write_pc(),
+   write_pc_pid(), write_pc(), and deprecated_read_fp(), all need to
+   be replaced by something that does not rely on global state.  But
+   what?  */
 
 CORE_ADDR
 read_pc_pid (ptid_t ptid)
@@ -1313,7 +1294,17 @@
   saved_inferior_ptid = inferior_ptid;
   inferior_ptid = ptid;
 
-  pc_val = TARGET_READ_PC (ptid);
+  if (TARGET_READ_PC_P ())
+    pc_val = TARGET_READ_PC (ptid);
+  /* Else use per-frame method on get_current_frame.  */
+  else if (PC_REGNUM >= 0)
+    {
+      CORE_ADDR raw_val = read_register_pid (PC_REGNUM, ptid);
+      CORE_ADDR pc_val = ADDR_BITS_REMOVE (raw_val);
+      return pc_val;
+    }
+  else
+    internal_error (__FILE__, __LINE__, "read_pc_pid: Unable to find PC");
 
   inferior_ptid = saved_inferior_ptid;
   return pc_val;
Index: rs6000-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v
retrieving revision 1.136
diff -u -r1.136 rs6000-tdep.c
--- rs6000-tdep.c	2 Jun 2003 02:54:35 -0000	1.136
+++ rs6000-tdep.c	7 Jun 2003 16:14:04 -0000
@@ -2910,7 +2910,6 @@
   else
     set_gdbarch_print_insn (gdbarch, gdb_print_insn_powerpc);
 
-  set_gdbarch_read_pc (gdbarch, generic_target_read_pc);
   set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
   set_gdbarch_read_sp (gdbarch, generic_target_read_sp);
   set_gdbarch_deprecated_dummy_write_sp (gdbarch, generic_target_write_sp);
Index: sh-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sh-tdep.c,v
retrieving revision 1.125
diff -u -r1.125 sh-tdep.c
--- sh-tdep.c	2 Jun 2003 02:09:39 -0000	1.125
+++ sh-tdep.c	7 Jun 2003 16:14:11 -0000
@@ -4637,7 +4637,6 @@
       break;
     }
 
-  set_gdbarch_read_pc (gdbarch, generic_target_read_pc);
   set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
   set_gdbarch_read_sp (gdbarch, generic_target_read_sp);
   set_gdbarch_deprecated_dummy_write_sp (gdbarch, generic_target_write_sp);
Index: sparc-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sparc-tdep.c,v
retrieving revision 1.107
diff -u -r1.107 sparc-tdep.c
--- sparc-tdep.c	3 Jun 2003 21:02:49 -0000	1.107
+++ sparc-tdep.c	7 Jun 2003 16:14:12 -0000
@@ -3321,7 +3321,6 @@
   set_gdbarch_deprecated_pop_frame (gdbarch, sparc_pop_frame);
   set_gdbarch_deprecated_push_return_address (gdbarch, sparc_push_return_address);
   set_gdbarch_deprecated_push_dummy_frame (gdbarch, sparc_push_dummy_frame);
-  set_gdbarch_read_pc (gdbarch, generic_target_read_pc);
   set_gdbarch_reg_struct_has_addr (gdbarch, sparc_reg_struct_has_addr);
   set_gdbarch_return_value_on_stack (gdbarch, sparc_return_value_on_stack);
   set_gdbarch_deprecated_saved_pc_after_call (gdbarch, sparc_saved_pc_after_call);

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