From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2366 invoked by alias); 7 Jun 2007 21:01:31 -0000 Received: (qmail 2352 invoked by uid 22791); 7 Jun 2007 21:01:27 -0000 X-Spam-Check-By: sourceware.org Received: from mtagate6.de.ibm.com (HELO mtagate6.de.ibm.com) (195.212.29.155) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 07 Jun 2007 21:01:18 +0000 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate6.de.ibm.com (8.13.8/8.13.8) with ESMTP id l57L1FYg146300 for ; Thu, 7 Jun 2007 21:01:15 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v8.3) with ESMTP id l57L1Fsg3776704 for ; Thu, 7 Jun 2007 23:01:15 +0200 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id l57L1F41021413 for ; Thu, 7 Jun 2007 23:01:15 +0200 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with SMTP id l57L1E5P021410 for ; Thu, 7 Jun 2007 23:01:14 +0200 Message-Id: <200706072101.l57L1E5P021410@d12av02.megacenter.de.ibm.com> Received: by tuxmaker.boeblingen.de.ibm.com (sSMTP sendmail emulation); Thu, 7 Jun 2007 23:01:14 +0200 Subject: [rfc][12/13] Eliminate read_register: Uses in read_pc / write_pc callbacks To: gdb-patches@sourceware.org Date: Thu, 07 Jun 2007 21:01:00 -0000 From: "Ulrich Weigand" X-Mailer: ELM [version 2.5 PL2] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-06/txt/msg00091.txt.bz2 Hello, this patch eliminates the last major set of callers of read_register and write_register, the read_pc / write_pc callbacks. These callbacks currently receive a PTID argument which they pass through to read_register_pid / write_register_pid. However, I'd argue it makes more sense to identify the thread whose PC is to be accessed via a REGCACHE argument: Today, the PTID is redundant as the caller always sets inferior_ptid to the PTID anyway. In the future, once we per-thread register caches, the REGCACHE itself will be sufficient to identify a thread, so an additional PTID would also be redundant. This patch implements the change: it removes the PTID argument, adds a REGCACHE argument, and changes all implementations to access that register cache instead of calling read_register_pid / write_register_pid (or, as some implementations still do, re-setting inferior_ptid and calling read_register / write_register directly). In addition, the patch eliminates the need to install the generic_target_write_pc routine by adding a predicate to the write_pc callback and handling the default case inline. This matches a change done for read_pc a while ago. Bye, Ulrich ChangeLog: * gdbarch.sh (read_pc): Add REGCACHE argument. Remove PTID argument. (write_pc): Likewise. Remove default implementation, add predicate. * gdbarch.c, gdbarch.h: Regenerate. * regcache.c (read_pc_pid): Use current regcache instead of calling read_register_pid. (write_pc_pid): Check gdbarch_write_pc predicate, implement default case inline. (generic_target_write_pc): Remove. * inferior.h (generic_target_write_pc): Remove. * frv-tdep.c (frv_gdbarch_init): Do not install it. * m68hc11-tdep.c (m68hc11_gdbarch_init): Likewise. * rs6000-tdep.c (rs6000_gdbarch_init): Likewise. * sh64-tdep.c (sh64_gdbarch_init): Likewise. * sh-tdep.c (sh_gdbarch_init): Likewise. * xstormy16-tdep.c (xstormy16_gdbarch_init): Likewise. * avr-tdep.c (avr_read_pc): Add REGCACHE argument. Remove PTID argument. Use REGCACHE instead of calling read_register_pid. * hppa-hpux-tdep.c (hppa_hpux_read_pc): Likewise. * hppa-tdep.c (hppa_read_pc): Likewise. * hppa-tdep.h (hppa_read_pc): Likewise. * ia64-tdep.c (ia64_read_pc): Likewise. * m32r-tdep.c (m32r_read_pc): Likewise. * mep-tdep.c (mep_read_pc): Likewise. * mn10300-tdep.c (mn10300_read_pc): Likewise. * spu-tdep.c (spu_read_pc): Likewise. * arm-tdep.c (arm_write_pc): Add REGCACHE argument. Remove PTID argument. Use REGCACHE instead of calling write_register_pid. * avr-tdep.c (avr_write_pc): Likewise. * hppa-hpux-tdep.c (hppa_hpux_write_pc): Likewise. * hppa-tdep.c (hppa_write_pc): Likewise. * hppa-tdep.h (hppa_write_pc): Likewise. * i386-linux-tdep.c (i386_linux_write_pc): Likewise. * amd64-linux-tdep.c (amd64_linux_write_pc): Likewise. * ia64-linux-tdep.c (ia64_linux_write_pc): Likewise. * ia64-tdep.c (ia64_write_pc): Likewise. * ia64-tdep.h (ia64_write_pc): Likewise. * m32r-tdep.c (m32r_write_pc): Likewise. * m88k-tdep.c (m88k_write_pc): Likewise. * mep-tdep.c (mep_write_pc): Likewise. * mips-tdep.c (mips_write_pc): Likewise. * mn10300-tdep.c (mn10300_write_pc): Likewise. * sparc-tdep.c (sparc_write_pc): Likewise. * spu-tdep.c (spu_write_pc): Likewise. * mips-tdep.c (read_signed_register): Remove. (read_signed_register_pid): Likewise. (mips_read_pc): Add REGCACHE argument. Remove PTID argument. Use REGCACHE instead of calling read_signed_register_pid. diff -urNp gdb-orig/gdb/amd64-linux-tdep.c gdb-head/gdb/amd64-linux-tdep.c --- gdb-orig/gdb/amd64-linux-tdep.c 2007-06-06 18:56:32.466921658 +0200 +++ gdb-head/gdb/amd64-linux-tdep.c 2007-06-06 19:47:27.290229486 +0200 @@ -237,9 +237,9 @@ amd64_linux_register_reggroup_p (struct /* Set the program counter for process PTID to PC. */ static void -amd64_linux_write_pc (CORE_ADDR pc, ptid_t ptid) +amd64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc) { - write_register_pid (AMD64_RIP_REGNUM, pc, ptid); + regcache_cooked_write_unsigned (regcache, AMD64_RIP_REGNUM, pc); /* We must be careful with modifying the program counter. If we just interrupted a system call, the kernel might try to restart @@ -255,7 +255,7 @@ amd64_linux_write_pc (CORE_ADDR pc, ptid when we resume the inferior on return from a function call from within GDB. In all other cases the system call will not be restarted. */ - write_register_pid (AMD64_LINUX_ORIG_RAX_REGNUM, -1, ptid); + regcache_cooked_write_unsigned (regcache, AMD64_LINUX_ORIG_RAX_REGNUM, -1); } static void diff -urNp gdb-orig/gdb/arm-tdep.c gdb-head/gdb/arm-tdep.c --- gdb-orig/gdb/arm-tdep.c 2007-06-06 19:46:31.105809485 +0200 +++ gdb-head/gdb/arm-tdep.c 2007-06-06 19:47:27.299228191 +0200 @@ -2581,18 +2581,20 @@ arm_coff_make_msymbol_special(int val, s } static void -arm_write_pc (CORE_ADDR pc, ptid_t ptid) +arm_write_pc (struct regcache *regcache, CORE_ADDR pc) { - write_register_pid (ARM_PC_REGNUM, pc, ptid); + regcache_cooked_write_unsigned (regcache, ARM_PC_REGNUM, pc); /* If necessary, set the T bit. */ if (arm_apcs_32) { - CORE_ADDR val = read_register_pid (ARM_PS_REGNUM, ptid); + ULONGEST val; + regcache_cooked_read_unsigned (regcache, ARM_PS_REGNUM, &val); if (arm_pc_is_thumb (pc)) - write_register_pid (ARM_PS_REGNUM, val | 0x20, ptid); + regcache_cooked_write_unsigned (regcache, ARM_PS_REGNUM, val | 0x20); else - write_register_pid (ARM_PS_REGNUM, val & ~(CORE_ADDR) 0x20, ptid); + regcache_cooked_write_unsigned (regcache, ARM_PS_REGNUM, + val & ~(ULONGEST) 0x20); } } diff -urNp gdb-orig/gdb/avr-tdep.c gdb-head/gdb/avr-tdep.c --- gdb-orig/gdb/avr-tdep.c 2007-06-06 18:59:45.444410477 +0200 +++ gdb-head/gdb/avr-tdep.c 2007-06-06 19:47:27.344221717 +0200 @@ -312,29 +312,18 @@ avr_pointer_to_address (struct type *typ } static CORE_ADDR -avr_read_pc (ptid_t ptid) +avr_read_pc (struct regcache *regcache) { - ptid_t save_ptid; ULONGEST pc; - CORE_ADDR retval; - - save_ptid = inferior_ptid; - inferior_ptid = ptid; - regcache_cooked_read_unsigned (current_regcache, AVR_PC_REGNUM, &pc); - inferior_ptid = save_ptid; - retval = avr_make_iaddr (pc); - return retval; + regcache_cooked_read_unsigned (regcache, AVR_PC_REGNUM, &pc); + return avr_make_iaddr (pc); } static void -avr_write_pc (CORE_ADDR val, ptid_t ptid) +avr_write_pc (struct regcache *regcache, CORE_ADDR val) { - ptid_t save_ptid; - - save_ptid = inferior_ptid; - inferior_ptid = ptid; - write_register (AVR_PC_REGNUM, avr_convert_iaddr_to_raw (val)); - inferior_ptid = save_ptid; + regcache_cooked_write_unsigned (regcache, AVR_PC_REGNUM, + avr_convert_iaddr_to_raw (val)); } static int diff -urNp gdb-orig/gdb/frv-tdep.c gdb-head/gdb/frv-tdep.c --- gdb-orig/gdb/frv-tdep.c 2007-06-06 18:56:53.854036422 +0200 +++ gdb-head/gdb/frv-tdep.c 2007-06-06 19:47:27.398213947 +0200 @@ -1517,8 +1517,6 @@ frv_gdbarch_init (struct gdbarch_info in /* Settings that should be unnecessary. */ set_gdbarch_inner_than (gdbarch, core_addr_lessthan); - set_gdbarch_write_pc (gdbarch, generic_target_write_pc); - /* Hardware watchpoint / breakpoint support. */ switch (info.bfd_arch_info->mach) { diff -urNp gdb-orig/gdb/gdbarch.c gdb-head/gdb/gdbarch.c --- gdb-orig/gdb/gdbarch.c 2007-06-06 19:47:16.265221871 +0200 +++ gdb-head/gdb/gdbarch.c 2007-06-06 19:47:27.459205170 +0200 @@ -410,7 +410,6 @@ gdbarch_alloc (const struct gdbarch_info current_gdbarch->ptr_bit = TARGET_INT_BIT; current_gdbarch->bfd_vma_bit = TARGET_ARCHITECTURE->bits_per_address; current_gdbarch->char_signed = -1; - current_gdbarch->write_pc = generic_target_write_pc; current_gdbarch->virtual_frame_pointer = legacy_virtual_frame_pointer; current_gdbarch->num_regs = -1; current_gdbarch->sp_regnum = -1; @@ -528,7 +527,7 @@ verify_gdbarch (struct gdbarch *current_ if (current_gdbarch->char_signed == -1) current_gdbarch->char_signed = 1; /* Skip verify of read_pc, has predicate */ - /* Skip verify of write_pc, invalid_p == 0 */ + /* Skip verify of write_pc, has predicate */ /* Skip verify of virtual_frame_pointer, invalid_p == 0 */ /* Skip verify of pseudo_register_read, has predicate */ /* Skip verify of pseudo_register_write, has predicate */ @@ -1183,21 +1182,9 @@ gdbarch_dump (struct gdbarch *current_gd fprintf_unfiltered (file, "gdbarch_dump: push_dummy_code = <0x%lx>\n", (long) current_gdbarch->push_dummy_code); -#ifdef TARGET_READ_PC_P - fprintf_unfiltered (file, - "gdbarch_dump: %s # %s\n", - "TARGET_READ_PC_P()", - XSTRING (TARGET_READ_PC_P ())); -#endif fprintf_unfiltered (file, "gdbarch_dump: gdbarch_read_pc_p() = %d\n", gdbarch_read_pc_p (current_gdbarch)); -#ifdef TARGET_READ_PC - fprintf_unfiltered (file, - "gdbarch_dump: %s # %s\n", - "TARGET_READ_PC(ptid)", - XSTRING (TARGET_READ_PC (ptid))); -#endif fprintf_unfiltered (file, "gdbarch_dump: read_pc = <0x%lx>\n", (long) current_gdbarch->read_pc); @@ -1424,12 +1411,9 @@ gdbarch_dump (struct gdbarch *current_gd fprintf_unfiltered (file, "gdbarch_dump: vtable_function_descriptors = %s\n", paddr_d (current_gdbarch->vtable_function_descriptors)); -#ifdef TARGET_WRITE_PC fprintf_unfiltered (file, - "gdbarch_dump: %s # %s\n", - "TARGET_WRITE_PC(val, ptid)", - XSTRING (TARGET_WRITE_PC (val, ptid))); -#endif + "gdbarch_dump: gdbarch_write_pc_p() = %d\n", + gdbarch_write_pc_p (current_gdbarch)); fprintf_unfiltered (file, "gdbarch_dump: write_pc = <0x%lx>\n", (long) current_gdbarch->write_pc); @@ -1727,13 +1711,13 @@ gdbarch_read_pc_p (struct gdbarch *gdbar } CORE_ADDR -gdbarch_read_pc (struct gdbarch *gdbarch, ptid_t ptid) +gdbarch_read_pc (struct gdbarch *gdbarch, struct regcache *regcache) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->read_pc != NULL); if (gdbarch_debug >= 2) fprintf_unfiltered (gdb_stdlog, "gdbarch_read_pc called\n"); - return gdbarch->read_pc (ptid); + return gdbarch->read_pc (regcache); } void @@ -1743,14 +1727,21 @@ set_gdbarch_read_pc (struct gdbarch *gdb gdbarch->read_pc = read_pc; } +int +gdbarch_write_pc_p (struct gdbarch *gdbarch) +{ + gdb_assert (gdbarch != NULL); + return gdbarch->write_pc != NULL; +} + void -gdbarch_write_pc (struct gdbarch *gdbarch, CORE_ADDR val, ptid_t ptid) +gdbarch_write_pc (struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR val) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->write_pc != NULL); if (gdbarch_debug >= 2) fprintf_unfiltered (gdb_stdlog, "gdbarch_write_pc called\n"); - gdbarch->write_pc (val, ptid); + gdbarch->write_pc (regcache, val); } void diff -urNp gdb-orig/gdb/gdbarch.h gdb-head/gdb/gdbarch.h --- gdb-orig/gdb/gdbarch.h 2007-06-06 19:47:16.309215540 +0200 +++ gdb-head/gdb/gdbarch.h 2007-06-06 19:47:27.516196969 +0200 @@ -235,40 +235,17 @@ extern void set_gdbarch_bfd_vma_bit (str extern int gdbarch_char_signed (struct gdbarch *gdbarch); extern void set_gdbarch_char_signed (struct gdbarch *gdbarch, int char_signed); -#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 - extern int gdbarch_read_pc_p (struct gdbarch *gdbarch); -#if !defined (GDB_TM_FILE) && defined (TARGET_READ_PC_P) -#error "Non multi-arch definition of TARGET_READ_PC" -#endif -#if !defined (TARGET_READ_PC_P) -#define TARGET_READ_PC_P() (gdbarch_read_pc_p (current_gdbarch)) -#endif -typedef CORE_ADDR (gdbarch_read_pc_ftype) (ptid_t ptid); -extern CORE_ADDR gdbarch_read_pc (struct gdbarch *gdbarch, ptid_t ptid); +typedef CORE_ADDR (gdbarch_read_pc_ftype) (struct regcache *regcache); +extern CORE_ADDR gdbarch_read_pc (struct gdbarch *gdbarch, struct regcache *regcache); extern void set_gdbarch_read_pc (struct gdbarch *gdbarch, gdbarch_read_pc_ftype *read_pc); -#if !defined (GDB_TM_FILE) && defined (TARGET_READ_PC) -#error "Non multi-arch definition of TARGET_READ_PC" -#endif -#if !defined (TARGET_READ_PC) -#define TARGET_READ_PC(ptid) (gdbarch_read_pc (current_gdbarch, ptid)) -#endif -typedef void (gdbarch_write_pc_ftype) (CORE_ADDR val, ptid_t ptid); -extern void gdbarch_write_pc (struct gdbarch *gdbarch, CORE_ADDR val, ptid_t ptid); +extern int gdbarch_write_pc_p (struct gdbarch *gdbarch); + +typedef void (gdbarch_write_pc_ftype) (struct regcache *regcache, CORE_ADDR val); +extern void gdbarch_write_pc (struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR val); extern void set_gdbarch_write_pc (struct gdbarch *gdbarch, gdbarch_write_pc_ftype *write_pc); -#if !defined (GDB_TM_FILE) && defined (TARGET_WRITE_PC) -#error "Non multi-arch definition of TARGET_WRITE_PC" -#endif -#if !defined (TARGET_WRITE_PC) -#define TARGET_WRITE_PC(val, ptid) (gdbarch_write_pc (current_gdbarch, val, ptid)) -#endif /* Function for getting target's idea of a frame pointer. FIXME: GDB's whole scheme for dealing with "frames" and "frame pointers" needs a diff -urNp gdb-orig/gdb/gdbarch.sh gdb-head/gdb/gdbarch.sh --- gdb-orig/gdb/gdbarch.sh 2007-06-06 19:47:16.318214245 +0200 +++ gdb-head/gdb/gdbarch.sh 2007-06-06 19:47:27.534327418 +0200 @@ -420,8 +420,8 @@ v:TARGET_BFD_VMA_BIT:int:bfd_vma_bit:::8 # One if \`char' acts like \`signed char', zero if \`unsigned char'. v::int:char_signed:::1:-1:1 # -F:TARGET_READ_PC:CORE_ADDR:read_pc:ptid_t ptid:ptid -f:TARGET_WRITE_PC:void:write_pc:CORE_ADDR val, ptid_t ptid:val, ptid:0:generic_target_write_pc::0 +F::CORE_ADDR:read_pc:struct regcache *regcache:regcache +F::void:write_pc:struct regcache *regcache, CORE_ADDR val:regcache, val # Function for getting target's idea of a frame pointer. FIXME: GDB's # whole scheme for dealing with "frames" and "frame pointers" needs a # serious shakedown. diff -urNp gdb-orig/gdb/hppa-hpux-tdep.c gdb-head/gdb/hppa-hpux-tdep.c --- gdb-orig/gdb/hppa-hpux-tdep.c 2007-06-06 19:47:16.360208202 +0200 +++ gdb-head/gdb/hppa-hpux-tdep.c 2007-06-06 19:47:27.590319360 +0200 @@ -1370,29 +1370,33 @@ hppa_hpux_regset_from_core_section (stru #define HPPA_HPUX_SS_INSYSCALL 0x02 static CORE_ADDR -hppa_hpux_read_pc (ptid_t ptid) +hppa_hpux_read_pc (struct regcache *regcache) { ULONGEST flags; /* If we're currently in a system call return the contents of %r31. */ - flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid); + regcache_cooked_read_unsigned (regcache, HPPA_FLAGS_REGNUM, &flags); if (flags & HPPA_HPUX_SS_INSYSCALL) - return read_register_pid (HPPA_R31_REGNUM, ptid) & ~0x3; + { + ULONGEST pc; + regcache_cooked_read_unsigned (regcache, HPPA_R31_REGNUM, &pc); + return pc & ~0x3; + } - return hppa_read_pc (ptid); + return hppa_read_pc (regcache); } static void -hppa_hpux_write_pc (CORE_ADDR pc, ptid_t ptid) +hppa_hpux_write_pc (struct regcache *regcache, CORE_ADDR pc) { ULONGEST flags; /* If we're currently in a system call also write PC into %r31. */ - flags = read_register_pid (HPPA_FLAGS_REGNUM, ptid); + regcache_cooked_read_unsigned (regcache, HPPA_FLAGS_REGNUM, &flags); if (flags & HPPA_HPUX_SS_INSYSCALL) - write_register_pid (HPPA_R31_REGNUM, pc | 0x3, ptid); + regcache_cooked_write_unsigned (regcache, HPPA_R31_REGNUM, pc | 0x3); - return hppa_write_pc (pc, ptid); + return hppa_write_pc (regcache, pc); } static CORE_ADDR diff -urNp gdb-orig/gdb/hppa-linux-tdep.c gdb-head/gdb/hppa-linux-tdep.c --- gdb-orig/gdb/hppa-linux-tdep.c 2007-06-06 18:56:32.599902522 +0200 +++ gdb-head/gdb/hppa-linux-tdep.c 2007-06-06 19:47:27.595318641 +0200 @@ -56,11 +56,11 @@ hppa_dwarf_reg_to_regnum (int reg) #endif static void -hppa_linux_target_write_pc (CORE_ADDR v, ptid_t ptid) +hppa_linux_target_write_pc (struct regcache *regcache, CORE_ADDR v) { /* Probably this should be done by the kernel, but it isn't. */ - write_register_pid (HPPA_PCOQ_HEAD_REGNUM, v | 0x3, ptid); - write_register_pid (HPPA_PCOQ_TAIL_REGNUM, (v + 4) | 0x3, ptid); + regcache_cooked_write_unsigned (regcache, HPPA_PCOQ_HEAD_REGNUM, v | 0x3); + regcache_cooked_write_unsigned (regcache, HPPA_PCOQ_TAIL_REGNUM, (v + 4) | 0x3); } /* An instruction to match. */ diff -urNp gdb-orig/gdb/hppa-tdep.c gdb-head/gdb/hppa-tdep.c --- gdb-orig/gdb/hppa-tdep.c 2007-06-06 19:41:42.668580680 +0200 +++ gdb-head/gdb/hppa-tdep.c 2007-06-06 19:47:27.604317346 +0200 @@ -1274,13 +1274,13 @@ hppa64_frame_align (struct gdbarch *gdba } CORE_ADDR -hppa_read_pc (ptid_t ptid) +hppa_read_pc (struct regcache *regcache) { ULONGEST ipsw; - CORE_ADDR pc; + ULONGEST pc; - ipsw = read_register_pid (HPPA_IPSW_REGNUM, ptid); - pc = read_register_pid (HPPA_PCOQ_HEAD_REGNUM, ptid); + regcache_cooked_read_unsigned (regcache, HPPA_IPSW_REGNUM, &ipsw); + regcache_cooked_read_unsigned (regcache, HPPA_PCOQ_HEAD_REGNUM, &pc); /* If the current instruction is nullified, then we are effectively still executing the previous instruction. Pretend we are still @@ -1294,10 +1294,10 @@ hppa_read_pc (ptid_t ptid) } void -hppa_write_pc (CORE_ADDR pc, ptid_t ptid) +hppa_write_pc (struct regcache *regcache, CORE_ADDR pc) { - write_register_pid (HPPA_PCOQ_HEAD_REGNUM, pc, ptid); - write_register_pid (HPPA_PCOQ_TAIL_REGNUM, pc + 4, ptid); + regcache_cooked_write_unsigned (regcache, HPPA_PCOQ_HEAD_REGNUM, pc); + regcache_cooked_write_unsigned (regcache, HPPA_PCOQ_TAIL_REGNUM, pc + 4); } /* return the alignment of a type in bytes. Structures have the maximum diff -urNp gdb-orig/gdb/hppa-tdep.h gdb-head/gdb/hppa-tdep.h --- gdb-orig/gdb/hppa-tdep.h 2007-06-06 19:41:42.673579960 +0200 +++ gdb-head/gdb/hppa-tdep.h 2007-06-06 19:47:27.646311303 +0200 @@ -233,8 +233,8 @@ extern void enum lval_type *lvalp, CORE_ADDR *addrp, int *realnump, gdb_byte *valuep); -extern CORE_ADDR hppa_read_pc (ptid_t ptid); -extern void hppa_write_pc (CORE_ADDR pc, ptid_t ptid); +extern CORE_ADDR hppa_read_pc (struct regcache *regcache); +extern void hppa_write_pc (struct regcache *regcache, CORE_ADDR pc); extern CORE_ADDR hppa_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame); diff -urNp gdb-orig/gdb/i386-linux-tdep.c gdb-head/gdb/i386-linux-tdep.c --- gdb-orig/gdb/i386-linux-tdep.c 2007-06-06 18:56:32.623899069 +0200 +++ gdb-head/gdb/i386-linux-tdep.c 2007-06-06 19:47:27.650310728 +0200 @@ -317,9 +317,9 @@ i386_linux_sigcontext_addr (struct frame /* Set the program counter for process PTID to PC. */ static void -i386_linux_write_pc (CORE_ADDR pc, ptid_t ptid) +i386_linux_write_pc (struct regcache *regcache, CORE_ADDR pc) { - write_register_pid (I386_EIP_REGNUM, pc, ptid); + regcache_cooked_write_unsigned (regcache, I386_EIP_REGNUM, pc); /* We must be careful with modifying the program counter. If we just interrupted a system call, the kernel might try to restart @@ -335,7 +335,7 @@ i386_linux_write_pc (CORE_ADDR pc, ptid_ when we resume the inferior on return from a function call from within GDB. In all other cases the system call will not be restarted. */ - write_register_pid (I386_LINUX_ORIG_EAX_REGNUM, -1, ptid); + regcache_cooked_write_unsigned (regcache, I386_LINUX_ORIG_EAX_REGNUM, -1); } diff -urNp gdb-orig/gdb/ia64-linux-tdep.c gdb-head/gdb/ia64-linux-tdep.c --- gdb-orig/gdb/ia64-linux-tdep.c 2007-06-06 18:56:32.627898494 +0200 +++ gdb-head/gdb/ia64-linux-tdep.c 2007-06-06 19:47:27.654310152 +0200 @@ -100,9 +100,9 @@ ia64_linux_sigcontext_register_address ( } static void -ia64_linux_write_pc (CORE_ADDR pc, ptid_t ptid) +ia64_linux_write_pc (struct regcache *regcache, CORE_ADDR pc) { - ia64_write_pc (pc, ptid); + ia64_write_pc (regcache, pc); /* We must be careful with modifying the instruction-pointer: if we just interrupt a system call, the kernel would ordinarily try to @@ -113,7 +113,7 @@ ia64_linux_write_pc (CORE_ADDR pc, ptid_ The clearing of r10 is safe as long as ia64_write_pc() is only called as part of setting up an inferior call. */ - write_register_pid (IA64_GR10_REGNUM, 0, ptid); + regcache_cooked_write_unsigned (regcache, IA64_GR10_REGNUM, 0); } static void diff -urNp gdb-orig/gdb/ia64-tdep.c gdb-head/gdb/ia64-tdep.c --- gdb-orig/gdb/ia64-tdep.c 2007-06-06 18:59:45.540396664 +0200 +++ gdb-head/gdb/ia64-tdep.c 2007-06-06 19:47:27.664308713 +0200 @@ -637,27 +637,32 @@ ia64_breakpoint_from_pc (CORE_ADDR *pcpt } static CORE_ADDR -ia64_read_pc (ptid_t ptid) +ia64_read_pc (struct regcache *regcache) { - CORE_ADDR psr_value = read_register_pid (IA64_PSR_REGNUM, ptid); - CORE_ADDR pc_value = read_register_pid (IA64_IP_REGNUM, ptid); - int slot_num = (psr_value >> 41) & 3; + ULONGEST psr_value, pc_value; + int slot_num; + + regcache_cooked_read_unsigned (regcache, IA64_PSR_REGNUM, &psr_value); + regcache_cooked_read_unsigned (regcache, IA64_IP_REGNUM, &pc_value); + slot_num = (psr_value >> 41) & 3; return pc_value | (slot_num * SLOT_MULTIPLIER); } void -ia64_write_pc (CORE_ADDR new_pc, ptid_t ptid) +ia64_write_pc (struct regcache *regcache, CORE_ADDR new_pc) { int slot_num = (int) (new_pc & 0xf) / SLOT_MULTIPLIER; - CORE_ADDR psr_value = read_register_pid (IA64_PSR_REGNUM, ptid); + ULONGEST psr_value; + + regcache_cooked_read_unsigned (regcache, IA64_PSR_REGNUM, &psr_value); psr_value &= ~(3LL << 41); - psr_value |= (CORE_ADDR)(slot_num & 0x3) << 41; + psr_value |= (ULONGEST)(slot_num & 0x3) << 41; new_pc &= ~0xfLL; - write_register_pid (IA64_PSR_REGNUM, psr_value, ptid); - write_register_pid (IA64_IP_REGNUM, new_pc, ptid); + regcache_cooked_write_unsigned (regcache, IA64_PSR_REGNUM, psr_value); + regcache_cooked_write_unsigned (regcache, IA64_IP_REGNUM, new_pc); } #define IS_NaT_COLLECTION_ADDR(addr) ((((addr) >> 3) & 0x3f) == 0x3f) diff -urNp gdb-orig/gdb/ia64-tdep.h gdb-head/gdb/ia64-tdep.h --- gdb-orig/gdb/ia64-tdep.h 2007-06-06 18:56:32.645895904 +0200 +++ gdb-head/gdb/ia64-tdep.h 2007-06-06 19:47:27.669307994 +0200 @@ -202,6 +202,6 @@ struct gdbarch_tdep int (*pc_in_sigtramp) (CORE_ADDR); }; -extern void ia64_write_pc (CORE_ADDR, ptid_t); +extern void ia64_write_pc (struct regcache *, CORE_ADDR); #endif /* ia64-tdep.h */ diff -urNp gdb-orig/gdb/inferior.h gdb-head/gdb/inferior.h --- gdb-orig/gdb/inferior.h 2007-06-06 18:56:32.651895041 +0200 +++ gdb-head/gdb/inferior.h 2007-06-06 19:47:27.673307418 +0200 @@ -172,8 +172,6 @@ extern void write_pc (CORE_ADDR); extern void write_pc_pid (CORE_ADDR, ptid_t); -extern void generic_target_write_pc (CORE_ADDR, ptid_t); - extern CORE_ADDR unsigned_pointer_to_address (struct type *type, const gdb_byte *buf); extern void unsigned_address_to_pointer (struct type *type, gdb_byte *buf, diff -urNp gdb-orig/gdb/m32r-tdep.c gdb-head/gdb/m32r-tdep.c --- gdb-orig/gdb/m32r-tdep.c 2007-06-06 18:56:32.657894177 +0200 +++ gdb-head/gdb/m32r-tdep.c 2007-06-06 19:47:27.679306555 +0200 @@ -643,27 +643,17 @@ m32r_frame_unwind_cache (struct frame_in } static CORE_ADDR -m32r_read_pc (ptid_t ptid) +m32r_read_pc (struct regcache *regcache) { - ptid_t save_ptid; ULONGEST pc; - - save_ptid = inferior_ptid; - inferior_ptid = ptid; - regcache_cooked_read_unsigned (current_regcache, M32R_PC_REGNUM, &pc); - inferior_ptid = save_ptid; + regcache_cooked_read_unsigned (regcache, M32R_PC_REGNUM, &pc); return pc; } static void -m32r_write_pc (CORE_ADDR val, ptid_t ptid) +m32r_write_pc (struct regcache *regcache, CORE_ADDR val) { - ptid_t save_ptid; - - save_ptid = inferior_ptid; - inferior_ptid = ptid; - write_register (M32R_PC_REGNUM, val); - inferior_ptid = save_ptid; + regcache_cooked_write_unsigned (regcache, M32R_PC_REGNUM, val); } static CORE_ADDR diff -urNp gdb-orig/gdb/m68hc11-tdep.c gdb-head/gdb/m68hc11-tdep.c --- gdb-orig/gdb/m68hc11-tdep.c 2007-06-06 18:56:32.665893026 +0200 +++ gdb-head/gdb/m68hc11-tdep.c 2007-06-06 19:47:27.685305692 +0200 @@ -1502,8 +1502,6 @@ m68hc11_gdbarch_init (struct gdbarch_inf /* Set register info. */ set_gdbarch_fp0_regnum (gdbarch, -1); - set_gdbarch_write_pc (gdbarch, generic_target_write_pc); - set_gdbarch_sp_regnum (gdbarch, HARD_SP_REGNUM); set_gdbarch_register_name (gdbarch, m68hc11_register_name); set_gdbarch_register_type (gdbarch, m68hc11_register_type); diff -urNp gdb-orig/gdb/m88k-tdep.c gdb-head/gdb/m88k-tdep.c --- gdb-orig/gdb/m88k-tdep.c 2007-06-06 18:56:32.673891875 +0200 +++ gdb-head/gdb/m88k-tdep.c 2007-06-06 19:47:27.691304829 +0200 @@ -122,7 +122,7 @@ m88k_unwind_pc (struct gdbarch *gdbarch, } static void -m88k_write_pc (CORE_ADDR pc, ptid_t ptid) +m88k_write_pc (struct regcache *regcache, CORE_ADDR pc) { /* According to the MC88100 RISC Microprocessor User's Manual, section 6.4.3.1.2: @@ -140,9 +140,9 @@ m88k_write_pc (CORE_ADDR pc, ptid_t ptid with it. We could even (presumably) give it a totally bogus value. */ - write_register_pid (M88K_SXIP_REGNUM, pc, ptid); - write_register_pid (M88K_SNIP_REGNUM, pc | 2, ptid); - write_register_pid (M88K_SFIP_REGNUM, (pc + 4) | 2, ptid); + regcache_cooked_write_unsigned (regcache, M88K_SXIP_REGNUM, pc); + regcache_cooked_write_unsigned (regcache, M88K_SNIP_REGNUM, pc | 2); + regcache_cooked_write_unsigned (regcache, M88K_SFIP_REGNUM, (pc + 4) | 2); } diff -urNp gdb-orig/gdb/mep-tdep.c gdb-head/gdb/mep-tdep.c --- gdb-orig/gdb/mep-tdep.c 2007-06-06 18:56:56.008127477 +0200 +++ gdb-head/gdb/mep-tdep.c 2007-06-06 19:47:27.710302095 +0200 @@ -1121,31 +1121,17 @@ mep_register_type (struct gdbarch *gdbar static CORE_ADDR -mep_read_pc (ptid_t ptid) +mep_read_pc (struct regcache *regcache) { - ptid_t saved_ptid; - CORE_ADDR pc; - - saved_ptid = inferior_ptid; - inferior_ptid = ptid; - - pc = read_register (MEP_PC_REGNUM); - - inferior_ptid = saved_ptid; + ULONGEST pc; + regcache_cooked_read_unsigned (regcache, MEP_PC_REGNUM, &pc); return pc; } static void -mep_write_pc (CORE_ADDR pc, ptid_t ptid) +mep_write_pc (struct regcache *regcache, CORE_ADDR pc) { - ptid_t saved_ptid; - - saved_ptid = inferior_ptid; - inferior_ptid = ptid; - - write_register (MEP_PC_REGNUM, pc); - - inferior_ptid = saved_ptid; + regcache_cooked_write_unsigned (regcache, MEP_PC_REGNUM, pc); } diff -urNp gdb-orig/gdb/mips-tdep.c gdb-head/gdb/mips-tdep.c --- gdb-orig/gdb/mips-tdep.c 2007-06-06 19:41:42.732571472 +0200 +++ gdb-head/gdb/mips-tdep.c 2007-06-06 19:47:27.724300081 +0200 @@ -216,36 +216,6 @@ unmake_mips16_addr (CORE_ADDR addr) return ((addr) & ~(CORE_ADDR) 1); } -/* Return the contents of register REGNUM as a signed integer. */ - -static LONGEST -read_signed_register (int regnum) -{ - LONGEST val; - regcache_cooked_read_signed (current_regcache, regnum, &val); - return val; -} - -static LONGEST -read_signed_register_pid (int regnum, ptid_t ptid) -{ - ptid_t save_ptid; - LONGEST retval; - - if (ptid_equal (ptid, inferior_ptid)) - return read_signed_register (regnum); - - save_ptid = inferior_ptid; - - inferior_ptid = ptid; - - retval = read_signed_register (regnum); - - inferior_ptid = save_ptid; - - return retval; -} - /* Return the MIPS ABI associated with GDBARCH. */ enum mips_abi mips_abi (struct gdbarch *gdbarch) @@ -791,9 +761,12 @@ mips_pc_is_mips16 (CORE_ADDR memaddr) all registers should be sign extended for simplicity? */ static CORE_ADDR -mips_read_pc (ptid_t ptid) +mips_read_pc (struct regcache *regcache) { - return read_signed_register_pid (mips_regnum (current_gdbarch)->pc, ptid); + ULONGEST pc; + int regnum = mips_regnum (get_regcache_arch (regcache))->pc; + regcache_cooked_read_signed (regcache, regnum, &pc); + return pc; } static CORE_ADDR @@ -828,9 +801,10 @@ mips_unwind_dummy_id (struct gdbarch *gd } static void -mips_write_pc (CORE_ADDR pc, ptid_t ptid) +mips_write_pc (struct regcache *regcache, CORE_ADDR pc) { - write_register_pid (mips_regnum (current_gdbarch)->pc, pc, ptid); + int regnum = mips_regnum (get_regcache_arch (regcache))->pc; + regcache_cooked_write_unsigned (regcache, regnum, pc); } /* Fetch and return instruction from the specified location. If the PC diff -urNp gdb-orig/gdb/mn10300-tdep.c gdb-head/gdb/mn10300-tdep.c --- gdb-orig/gdb/mn10300-tdep.c 2007-06-06 18:59:45.614386017 +0200 +++ gdb-head/gdb/mn10300-tdep.c 2007-06-06 19:47:27.730299217 +0200 @@ -269,15 +269,17 @@ mn10300_register_type (struct gdbarch *g } static CORE_ADDR -mn10300_read_pc (ptid_t ptid) +mn10300_read_pc (struct regcache *regcache) { - return read_register_pid (E_PC_REGNUM, ptid); + ULONGEST val; + regcache_cooked_read_unsigned (regcache, E_PC_REGNUM, &val); + return val; } static void -mn10300_write_pc (CORE_ADDR val, ptid_t ptid) +mn10300_write_pc (struct regcache *regcache, CORE_ADDR val) { - return write_register_pid (E_PC_REGNUM, val, ptid); + regcache_cooked_write_unsigned (regcache, E_PC_REGNUM, val); } /* The breakpoint instruction must be the same size as the smallest diff -urNp gdb-orig/gdb/regcache.c gdb-head/gdb/regcache.c --- gdb-orig/gdb/regcache.c 2007-06-06 18:56:32.748881085 +0200 +++ gdb-head/gdb/regcache.c 2007-06-06 19:47:27.737298210 +0200 @@ -887,6 +887,9 @@ regcache_raw_collect (const struct regca CORE_ADDR read_pc_pid (ptid_t ptid) { + struct regcache *regcache = current_regcache; + struct gdbarch *gdbarch = get_regcache_arch (regcache); + ptid_t saved_inferior_ptid; CORE_ADDR pc_val; @@ -894,13 +897,14 @@ read_pc_pid (ptid_t ptid) saved_inferior_ptid = inferior_ptid; inferior_ptid = ptid; - if (TARGET_READ_PC_P ()) - pc_val = TARGET_READ_PC (ptid); + if (gdbarch_read_pc_p (gdbarch)) + pc_val = gdbarch_read_pc (gdbarch, regcache); /* Else use per-frame method on get_current_frame. */ else if (PC_REGNUM >= 0) { - CORE_ADDR raw_val = read_register_pid (PC_REGNUM, ptid); - pc_val = ADDR_BITS_REMOVE (raw_val); + ULONGEST raw_val; + regcache_cooked_read_unsigned (regcache, PC_REGNUM, &raw_val); + pc_val = ADDR_BITS_REMOVE ((CORE_ADDR) raw_val); } else internal_error (__FILE__, __LINE__, _("read_pc_pid: Unable to find PC")); @@ -916,25 +920,24 @@ read_pc (void) } void -generic_target_write_pc (CORE_ADDR pc, ptid_t ptid) -{ - if (PC_REGNUM >= 0) - write_register_pid (PC_REGNUM, pc, ptid); - else - internal_error (__FILE__, __LINE__, - _("generic_target_write_pc")); -} - -void write_pc_pid (CORE_ADDR pc, ptid_t ptid) { + struct regcache *regcache = current_regcache; + struct gdbarch *gdbarch = get_regcache_arch (regcache); + ptid_t saved_inferior_ptid; /* In case ptid != inferior_ptid. */ saved_inferior_ptid = inferior_ptid; inferior_ptid = ptid; - TARGET_WRITE_PC (pc, ptid); + if (gdbarch_write_pc_p (gdbarch)) + gdbarch_write_pc (gdbarch, regcache, pc); + else if (PC_REGNUM >= 0) + regcache_cooked_write_unsigned (regcache, PC_REGNUM, pc); + else + internal_error (__FILE__, __LINE__, + _("write_pc_pid: Unable to update PC")); inferior_ptid = saved_inferior_ptid; } diff -urNp gdb-orig/gdb/rs6000-tdep.c gdb-head/gdb/rs6000-tdep.c --- gdb-orig/gdb/rs6000-tdep.c 2007-06-06 19:41:42.761567300 +0200 +++ gdb-head/gdb/rs6000-tdep.c 2007-06-06 19:47:27.746296915 +0200 @@ -3498,8 +3498,6 @@ rs6000_gdbarch_init (struct gdbarch_info else set_gdbarch_print_insn (gdbarch, gdb_print_insn_powerpc); - set_gdbarch_write_pc (gdbarch, generic_target_write_pc); - set_gdbarch_num_regs (gdbarch, v->nregs); set_gdbarch_num_pseudo_regs (gdbarch, v->npregs); set_gdbarch_register_name (gdbarch, rs6000_register_name); diff -urNp gdb-orig/gdb/sh64-tdep.c gdb-head/gdb/sh64-tdep.c --- gdb-orig/gdb/sh64-tdep.c 2007-06-06 18:58:46.781941039 +0200 +++ gdb-head/gdb/sh64-tdep.c 2007-06-06 19:47:27.765294182 +0200 @@ -2483,8 +2483,6 @@ sh64_gdbarch_init (struct gdbarch_info i set_gdbarch_print_insn (gdbarch, gdb_print_insn_sh64); set_gdbarch_register_sim_regno (gdbarch, legacy_register_sim_regno); - set_gdbarch_write_pc (gdbarch, generic_target_write_pc); - set_gdbarch_return_value (gdbarch, sh64_return_value); set_gdbarch_deprecated_extract_struct_value_address (gdbarch, sh64_extract_struct_value_address); diff -urNp gdb-orig/gdb/sh-tdep.c gdb-head/gdb/sh-tdep.c --- gdb-orig/gdb/sh-tdep.c 2007-06-06 18:59:34.224295736 +0200 +++ gdb-head/gdb/sh-tdep.c 2007-06-06 19:47:27.774292887 +0200 @@ -2669,8 +2669,6 @@ sh_gdbarch_init (struct gdbarch_info inf set_gdbarch_print_insn (gdbarch, gdb_print_insn_sh); set_gdbarch_register_sim_regno (gdbarch, legacy_register_sim_regno); - set_gdbarch_write_pc (gdbarch, generic_target_write_pc); - set_gdbarch_return_value (gdbarch, sh_return_value_nofpu); set_gdbarch_deprecated_extract_struct_value_address (gdbarch, sh_extract_struct_value_address); diff -urNp gdb-orig/gdb/sparc-tdep.c gdb-head/gdb/sparc-tdep.c --- gdb-orig/gdb/sparc-tdep.c 2007-06-06 19:47:16.373206332 +0200 +++ gdb-head/gdb/sparc-tdep.c 2007-06-06 19:47:27.781291879 +0200 @@ -1348,12 +1348,12 @@ sparc_software_single_step (struct frame } static void -sparc_write_pc (CORE_ADDR pc, ptid_t ptid) +sparc_write_pc (struct regcache *regcache, CORE_ADDR pc) { - struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); + struct gdbarch_tdep *tdep = gdbarch_tdep (get_regcache_arch (regcache)); - write_register_pid (tdep->pc_regnum, pc, ptid); - write_register_pid (tdep->npc_regnum, pc + 4, ptid); + regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc); + regcache_cooked_write_unsigned (regcache, tdep->npc_regnum, pc + 4); } /* Unglobalize NAME. */ diff -urNp gdb-orig/gdb/spu-tdep.c gdb-head/gdb/spu-tdep.c --- gdb-orig/gdb/spu-tdep.c 2007-06-06 19:00:38.753851447 +0200 +++ gdb-head/gdb/spu-tdep.c 2007-06-06 19:47:27.787291016 +0200 @@ -839,19 +839,22 @@ spu_unwind_sp (struct gdbarch *gdbarch, } static CORE_ADDR -spu_read_pc (ptid_t ptid) +spu_read_pc (struct regcache *regcache) { - CORE_ADDR pc = read_register_pid (SPU_PC_REGNUM, ptid); + ULONGEST pc; + regcache_cooked_read_unsigned (regcache, SPU_PC_REGNUM, &pc); /* Mask off interrupt enable bit. */ return pc & -4; } static void -spu_write_pc (CORE_ADDR pc, ptid_t ptid) +spu_write_pc (struct regcache *regcache, CORE_ADDR pc) { /* Keep interrupt enabled state unchanged. */ - CORE_ADDR old_pc = read_register_pid (SPU_PC_REGNUM, ptid); - write_register_pid (SPU_PC_REGNUM, (pc & -4) | (old_pc & 3), ptid); + ULONGEST old_pc; + regcache_cooked_read_unsigned (regcache, SPU_PC_REGNUM, &old_pc); + regcache_cooked_write_unsigned (regcache, SPU_PC_REGNUM, + (pc & -4) | (old_pc & 3)); } diff -urNp gdb-orig/gdb/xstormy16-tdep.c gdb-head/gdb/xstormy16-tdep.c --- gdb-orig/gdb/xstormy16-tdep.c 2007-06-06 19:41:42.782564279 +0200 +++ gdb-head/gdb/xstormy16-tdep.c 2007-06-06 19:47:27.792290297 +0200 @@ -825,8 +825,6 @@ xstormy16_gdbarch_init (struct gdbarch_i set_gdbarch_address_to_pointer (gdbarch, xstormy16_address_to_pointer); set_gdbarch_pointer_to_address (gdbarch, xstormy16_pointer_to_address); - set_gdbarch_write_pc (gdbarch, generic_target_write_pc); - /* Stack grows up. */ set_gdbarch_inner_than (gdbarch, core_addr_greaterthan); -- Dr. Ulrich Weigand GNU Toolchain for Linux on System z and Cell BE Ulrich.Weigand@de.ibm.com