GDB (API)
/home/stan/gdb/src/gdb/regcache.c
Go to the documentation of this file.
00001 /* Cache and manage the values of registers for GDB, the GNU debugger.
00002 
00003    Copyright (C) 1986-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "inferior.h"
00022 #include "target.h"
00023 #include "gdbarch.h"
00024 #include "gdbcmd.h"
00025 #include "regcache.h"
00026 #include "reggroups.h"
00027 #include "gdb_assert.h"
00028 #include "gdb_string.h"
00029 #include "gdbcmd.h"             /* For maintenanceprintlist.  */
00030 #include "observer.h"
00031 #include "exceptions.h"
00032 #include "remote.h"
00033 #include "valprint.h"
00034 
00035 /*
00036  * DATA STRUCTURE
00037  *
00038  * Here is the actual register cache.
00039  */
00040 
00041 /* Per-architecture object describing the layout of a register cache.
00042    Computed once when the architecture is created.  */
00043 
00044 struct gdbarch_data *regcache_descr_handle;
00045 
00046 struct regcache_descr
00047 {
00048   /* The architecture this descriptor belongs to.  */
00049   struct gdbarch *gdbarch;
00050 
00051   /* The raw register cache.  Each raw (or hard) register is supplied
00052      by the target interface.  The raw cache should not contain
00053      redundant information - if the PC is constructed from two
00054      registers then those registers and not the PC lives in the raw
00055      cache.  */
00056   int nr_raw_registers;
00057   long sizeof_raw_registers;
00058   long sizeof_raw_register_status;
00059 
00060   /* The cooked register space.  Each cooked register in the range
00061      [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
00062      register.  The remaining [NR_RAW_REGISTERS
00063      .. NR_COOKED_REGISTERS) (a.k.a. pseudo registers) are mapped onto
00064      both raw registers and memory by the architecture methods
00065      gdbarch_pseudo_register_read and gdbarch_pseudo_register_write.  */
00066   int nr_cooked_registers;
00067   long sizeof_cooked_registers;
00068   long sizeof_cooked_register_status;
00069 
00070   /* Offset and size (in 8 bit bytes), of each register in the
00071      register cache.  All registers (including those in the range
00072      [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an
00073      offset.  */
00074   long *register_offset;
00075   long *sizeof_register;
00076 
00077   /* Cached table containing the type of each register.  */
00078   struct type **register_type;
00079 };
00080 
00081 static void *
00082 init_regcache_descr (struct gdbarch *gdbarch)
00083 {
00084   int i;
00085   struct regcache_descr *descr;
00086   gdb_assert (gdbarch != NULL);
00087 
00088   /* Create an initial, zero filled, table.  */
00089   descr = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct regcache_descr);
00090   descr->gdbarch = gdbarch;
00091 
00092   /* Total size of the register space.  The raw registers are mapped
00093      directly onto the raw register cache while the pseudo's are
00094      either mapped onto raw-registers or memory.  */
00095   descr->nr_cooked_registers = gdbarch_num_regs (gdbarch)
00096                                + gdbarch_num_pseudo_regs (gdbarch);
00097   descr->sizeof_cooked_register_status
00098     = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
00099 
00100   /* Fill in a table of register types.  */
00101   descr->register_type
00102     = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers,
00103                               struct type *);
00104   for (i = 0; i < descr->nr_cooked_registers; i++)
00105     descr->register_type[i] = gdbarch_register_type (gdbarch, i);
00106 
00107   /* Construct a strictly RAW register cache.  Don't allow pseudo's
00108      into the register cache.  */
00109   descr->nr_raw_registers = gdbarch_num_regs (gdbarch);
00110   descr->sizeof_raw_register_status = gdbarch_num_regs (gdbarch);
00111 
00112   /* Lay out the register cache.
00113 
00114      NOTE: cagney/2002-05-22: Only register_type() is used when
00115      constructing the register cache.  It is assumed that the
00116      register's raw size, virtual size and type length are all the
00117      same.  */
00118 
00119   {
00120     long offset = 0;
00121 
00122     descr->sizeof_register
00123       = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
00124     descr->register_offset
00125       = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
00126     for (i = 0; i < descr->nr_raw_registers; i++)
00127       {
00128         descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
00129         descr->register_offset[i] = offset;
00130         offset += descr->sizeof_register[i];
00131         gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]);
00132       }
00133     /* Set the real size of the raw register cache buffer.  */
00134     descr->sizeof_raw_registers = offset;
00135 
00136     for (; i < descr->nr_cooked_registers; i++)
00137       {
00138         descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
00139         descr->register_offset[i] = offset;
00140         offset += descr->sizeof_register[i];
00141         gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]);
00142       }
00143     /* Set the real size of the readonly register cache buffer.  */
00144     descr->sizeof_cooked_registers = offset;
00145   }
00146 
00147   return descr;
00148 }
00149 
00150 static struct regcache_descr *
00151 regcache_descr (struct gdbarch *gdbarch)
00152 {
00153   return gdbarch_data (gdbarch, regcache_descr_handle);
00154 }
00155 
00156 /* Utility functions returning useful register attributes stored in
00157    the regcache descr.  */
00158 
00159 struct type *
00160 register_type (struct gdbarch *gdbarch, int regnum)
00161 {
00162   struct regcache_descr *descr = regcache_descr (gdbarch);
00163 
00164   gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
00165   return descr->register_type[regnum];
00166 }
00167 
00168 /* Utility functions returning useful register attributes stored in
00169    the regcache descr.  */
00170 
00171 int
00172 register_size (struct gdbarch *gdbarch, int regnum)
00173 {
00174   struct regcache_descr *descr = regcache_descr (gdbarch);
00175   int size;
00176 
00177   gdb_assert (regnum >= 0
00178               && regnum < (gdbarch_num_regs (gdbarch)
00179                            + gdbarch_num_pseudo_regs (gdbarch)));
00180   size = descr->sizeof_register[regnum];
00181   return size;
00182 }
00183 
00184 /* The register cache for storing raw register values.  */
00185 
00186 struct regcache
00187 {
00188   struct regcache_descr *descr;
00189 
00190   /* The address space of this register cache (for registers where it
00191      makes sense, like PC or SP).  */
00192   struct address_space *aspace;
00193 
00194   /* The register buffers.  A read-only register cache can hold the
00195      full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a read/write
00196      register cache can only hold [0 .. gdbarch_num_regs).  */
00197   gdb_byte *registers;
00198   /* Register cache status.  */
00199   signed char *register_status;
00200   /* Is this a read-only cache?  A read-only cache is used for saving
00201      the target's register state (e.g, across an inferior function
00202      call or just before forcing a function return).  A read-only
00203      cache can only be updated via the methods regcache_dup() and
00204      regcache_cpy().  The actual contents are determined by the
00205      reggroup_save and reggroup_restore methods.  */
00206   int readonly_p;
00207   /* If this is a read-write cache, which thread's registers is
00208      it connected to?  */
00209   ptid_t ptid;
00210 };
00211 
00212 static struct regcache *
00213 regcache_xmalloc_1 (struct gdbarch *gdbarch, struct address_space *aspace,
00214                     int readonly_p)
00215 {
00216   struct regcache_descr *descr;
00217   struct regcache *regcache;
00218 
00219   gdb_assert (gdbarch != NULL);
00220   descr = regcache_descr (gdbarch);
00221   regcache = XMALLOC (struct regcache);
00222   regcache->descr = descr;
00223   regcache->readonly_p = readonly_p;
00224   if (readonly_p)
00225     {
00226       regcache->registers
00227         = XCALLOC (descr->sizeof_cooked_registers, gdb_byte);
00228       regcache->register_status
00229         = XCALLOC (descr->sizeof_cooked_register_status, signed char);
00230     }
00231   else
00232     {
00233       regcache->registers
00234         = XCALLOC (descr->sizeof_raw_registers, gdb_byte);
00235       regcache->register_status
00236         = XCALLOC (descr->sizeof_raw_register_status, signed char);
00237     }
00238   regcache->aspace = aspace;
00239   regcache->ptid = minus_one_ptid;
00240   return regcache;
00241 }
00242 
00243 struct regcache *
00244 regcache_xmalloc (struct gdbarch *gdbarch, struct address_space *aspace)
00245 {
00246   return regcache_xmalloc_1 (gdbarch, aspace, 1);
00247 }
00248 
00249 void
00250 regcache_xfree (struct regcache *regcache)
00251 {
00252   if (regcache == NULL)
00253     return;
00254   xfree (regcache->registers);
00255   xfree (regcache->register_status);
00256   xfree (regcache);
00257 }
00258 
00259 static void
00260 do_regcache_xfree (void *data)
00261 {
00262   regcache_xfree (data);
00263 }
00264 
00265 struct cleanup *
00266 make_cleanup_regcache_xfree (struct regcache *regcache)
00267 {
00268   return make_cleanup (do_regcache_xfree, regcache);
00269 }
00270 
00271 /* Return REGCACHE's architecture.  */
00272 
00273 struct gdbarch *
00274 get_regcache_arch (const struct regcache *regcache)
00275 {
00276   return regcache->descr->gdbarch;
00277 }
00278 
00279 struct address_space *
00280 get_regcache_aspace (const struct regcache *regcache)
00281 {
00282   return regcache->aspace;
00283 }
00284 
00285 /* Return  a pointer to register REGNUM's buffer cache.  */
00286 
00287 static gdb_byte *
00288 register_buffer (const struct regcache *regcache, int regnum)
00289 {
00290   return regcache->registers + regcache->descr->register_offset[regnum];
00291 }
00292 
00293 void
00294 regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
00295                void *src)
00296 {
00297   struct gdbarch *gdbarch = dst->descr->gdbarch;
00298   gdb_byte buf[MAX_REGISTER_SIZE];
00299   int regnum;
00300 
00301   /* The DST should be `read-only', if it wasn't then the save would
00302      end up trying to write the register values back out to the
00303      target.  */
00304   gdb_assert (dst->readonly_p);
00305   /* Clear the dest.  */
00306   memset (dst->registers, 0, dst->descr->sizeof_cooked_registers);
00307   memset (dst->register_status, 0,
00308           dst->descr->sizeof_cooked_register_status);
00309   /* Copy over any registers (identified by their membership in the
00310      save_reggroup) and mark them as valid.  The full [0 .. gdbarch_num_regs +
00311      gdbarch_num_pseudo_regs) range is checked since some architectures need
00312      to save/restore `cooked' registers that live in memory.  */
00313   for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
00314     {
00315       if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
00316         {
00317           enum register_status status = cooked_read (src, regnum, buf);
00318 
00319           if (status == REG_VALID)
00320             memcpy (register_buffer (dst, regnum), buf,
00321                     register_size (gdbarch, regnum));
00322           else
00323             {
00324               gdb_assert (status != REG_UNKNOWN);
00325 
00326               memset (register_buffer (dst, regnum), 0,
00327                       register_size (gdbarch, regnum));
00328             }
00329           dst->register_status[regnum] = status;
00330         }
00331     }
00332 }
00333 
00334 static void
00335 regcache_restore (struct regcache *dst,
00336                   regcache_cooked_read_ftype *cooked_read,
00337                   void *cooked_read_context)
00338 {
00339   struct gdbarch *gdbarch = dst->descr->gdbarch;
00340   gdb_byte buf[MAX_REGISTER_SIZE];
00341   int regnum;
00342 
00343   /* The dst had better not be read-only.  If it is, the `restore'
00344      doesn't make much sense.  */
00345   gdb_assert (!dst->readonly_p);
00346   /* Copy over any registers, being careful to only restore those that
00347      were both saved and need to be restored.  The full [0 .. gdbarch_num_regs
00348      + gdbarch_num_pseudo_regs) range is checked since some architectures need
00349      to save/restore `cooked' registers that live in memory.  */
00350   for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++)
00351     {
00352       if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
00353         {
00354           enum register_status status;
00355 
00356           status = cooked_read (cooked_read_context, regnum, buf);
00357           if (status == REG_VALID)
00358             regcache_cooked_write (dst, regnum, buf);
00359         }
00360     }
00361 }
00362 
00363 static enum register_status
00364 do_cooked_read (void *src, int regnum, gdb_byte *buf)
00365 {
00366   struct regcache *regcache = src;
00367 
00368   return regcache_cooked_read (regcache, regnum, buf);
00369 }
00370 
00371 void
00372 regcache_cpy (struct regcache *dst, struct regcache *src)
00373 {
00374   gdb_assert (src != NULL && dst != NULL);
00375   gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
00376   gdb_assert (src != dst);
00377   gdb_assert (src->readonly_p || dst->readonly_p);
00378 
00379   if (!src->readonly_p)
00380     regcache_save (dst, do_cooked_read, src);
00381   else if (!dst->readonly_p)
00382     regcache_restore (dst, do_cooked_read, src);
00383   else
00384     regcache_cpy_no_passthrough (dst, src);
00385 }
00386 
00387 void
00388 regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src)
00389 {
00390   gdb_assert (src != NULL && dst != NULL);
00391   gdb_assert (src->descr->gdbarch == dst->descr->gdbarch);
00392   /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
00393      move of data into a thread's regcache.  Doing this would be silly
00394      - it would mean that regcache->register_status would be
00395      completely invalid.  */
00396   gdb_assert (dst->readonly_p && src->readonly_p);
00397 
00398   memcpy (dst->registers, src->registers,
00399           dst->descr->sizeof_cooked_registers);
00400   memcpy (dst->register_status, src->register_status,
00401           dst->descr->sizeof_cooked_register_status);
00402 }
00403 
00404 struct regcache *
00405 regcache_dup (struct regcache *src)
00406 {
00407   struct regcache *newbuf;
00408 
00409   newbuf = regcache_xmalloc (src->descr->gdbarch, get_regcache_aspace (src));
00410   regcache_cpy (newbuf, src);
00411   return newbuf;
00412 }
00413 
00414 enum register_status
00415 regcache_register_status (const struct regcache *regcache, int regnum)
00416 {
00417   gdb_assert (regcache != NULL);
00418   gdb_assert (regnum >= 0);
00419   if (regcache->readonly_p)
00420     gdb_assert (regnum < regcache->descr->nr_cooked_registers);
00421   else
00422     gdb_assert (regnum < regcache->descr->nr_raw_registers);
00423 
00424   return regcache->register_status[regnum];
00425 }
00426 
00427 void
00428 regcache_invalidate (struct regcache *regcache, int regnum)
00429 {
00430   gdb_assert (regcache != NULL);
00431   gdb_assert (regnum >= 0);
00432   gdb_assert (!regcache->readonly_p);
00433   gdb_assert (regnum < regcache->descr->nr_raw_registers);
00434   regcache->register_status[regnum] = REG_UNKNOWN;
00435 }
00436 
00437 
00438 /* Global structure containing the current regcache.  */
00439 
00440 /* NOTE: this is a write-through cache.  There is no "dirty" bit for
00441    recording if the register values have been changed (eg. by the
00442    user).  Therefore all registers must be written back to the
00443    target when appropriate.  */
00444 
00445 struct regcache_list
00446 {
00447   struct regcache *regcache;
00448   struct regcache_list *next;
00449 };
00450 
00451 static struct regcache_list *current_regcache;
00452 
00453 struct regcache *
00454 get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
00455                                  struct address_space *aspace)
00456 {
00457   struct regcache_list *list;
00458   struct regcache *new_regcache;
00459 
00460   for (list = current_regcache; list; list = list->next)
00461     if (ptid_equal (list->regcache->ptid, ptid)
00462         && get_regcache_arch (list->regcache) == gdbarch)
00463       return list->regcache;
00464 
00465   new_regcache = regcache_xmalloc_1 (gdbarch, aspace, 0);
00466   new_regcache->ptid = ptid;
00467 
00468   list = xmalloc (sizeof (struct regcache_list));
00469   list->regcache = new_regcache;
00470   list->next = current_regcache;
00471   current_regcache = list;
00472 
00473   return new_regcache;
00474 }
00475 
00476 struct regcache *
00477 get_thread_arch_regcache (ptid_t ptid, struct gdbarch *gdbarch)
00478 {
00479   struct address_space *aspace;
00480 
00481   /* For the benefit of "maint print registers" & co when debugging an
00482      executable, allow dumping the regcache even when there is no
00483      thread selected (target_thread_address_space internal-errors if
00484      no address space is found).  Note that normal user commands will
00485      fail higher up on the call stack due to no
00486      target_has_registers.  */
00487   aspace = (ptid_equal (null_ptid, ptid)
00488             ? NULL
00489             : target_thread_address_space (ptid));
00490 
00491   return get_thread_arch_aspace_regcache  (ptid, gdbarch, aspace);
00492 }
00493 
00494 static ptid_t current_thread_ptid;
00495 static struct gdbarch *current_thread_arch;
00496 
00497 struct regcache *
00498 get_thread_regcache (ptid_t ptid)
00499 {
00500   if (!current_thread_arch || !ptid_equal (current_thread_ptid, ptid))
00501     {
00502       current_thread_ptid = ptid;
00503       current_thread_arch = target_thread_architecture (ptid);
00504     }
00505 
00506   return get_thread_arch_regcache (ptid, current_thread_arch);
00507 }
00508 
00509 struct regcache *
00510 get_current_regcache (void)
00511 {
00512   return get_thread_regcache (inferior_ptid);
00513 }
00514 
00515 
00516 /* Observer for the target_changed event.  */
00517 
00518 static void
00519 regcache_observer_target_changed (struct target_ops *target)
00520 {
00521   registers_changed ();
00522 }
00523 
00524 /* Update global variables old ptids to hold NEW_PTID if they were
00525    holding OLD_PTID.  */
00526 static void
00527 regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
00528 {
00529   struct regcache_list *list;
00530 
00531   for (list = current_regcache; list; list = list->next)
00532     if (ptid_equal (list->regcache->ptid, old_ptid))
00533       list->regcache->ptid = new_ptid;
00534 }
00535 
00536 /* Low level examining and depositing of registers.
00537 
00538    The caller is responsible for making sure that the inferior is
00539    stopped before calling the fetching routines, or it will get
00540    garbage.  (a change from GDB version 3, in which the caller got the
00541    value from the last stop).  */
00542 
00543 /* REGISTERS_CHANGED ()
00544 
00545    Indicate that registers may have changed, so invalidate the cache.  */
00546 
00547 void
00548 registers_changed_ptid (ptid_t ptid)
00549 {
00550   struct regcache_list *list, **list_link;
00551 
00552   list = current_regcache;
00553   list_link = &current_regcache;
00554   while (list)
00555     {
00556       if (ptid_match (list->regcache->ptid, ptid))
00557         {
00558           struct regcache_list *dead = list;
00559 
00560           *list_link = list->next;
00561           regcache_xfree (list->regcache);
00562           list = *list_link;
00563           xfree (dead);
00564           continue;
00565         }
00566 
00567       list_link = &list->next;
00568       list = *list_link;
00569     }
00570 
00571   if (ptid_match (current_thread_ptid, ptid))
00572     {
00573       current_thread_ptid = null_ptid;
00574       current_thread_arch = NULL;
00575     }
00576 
00577   if (ptid_match (inferior_ptid, ptid))
00578     {
00579       /* We just deleted the regcache of the current thread.  Need to
00580          forget about any frames we have cached, too.  */
00581       reinit_frame_cache ();
00582     }
00583 }
00584 
00585 void
00586 registers_changed (void)
00587 {
00588   registers_changed_ptid (minus_one_ptid);
00589 
00590   /* Force cleanup of any alloca areas if using C alloca instead of
00591      a builtin alloca.  This particular call is used to clean up
00592      areas allocated by low level target code which may build up
00593      during lengthy interactions between gdb and the target before
00594      gdb gives control to the user (ie watchpoints).  */
00595   alloca (0);
00596 }
00597 
00598 enum register_status
00599 regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf)
00600 {
00601   gdb_assert (regcache != NULL && buf != NULL);
00602   gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
00603   /* Make certain that the register cache is up-to-date with respect
00604      to the current thread.  This switching shouldn't be necessary
00605      only there is still only one target side register cache.  Sigh!
00606      On the bright side, at least there is a regcache object.  */
00607   if (!regcache->readonly_p
00608       && regcache_register_status (regcache, regnum) == REG_UNKNOWN)
00609     {
00610       struct cleanup *old_chain = save_inferior_ptid ();
00611 
00612       inferior_ptid = regcache->ptid;
00613       target_fetch_registers (regcache, regnum);
00614       do_cleanups (old_chain);
00615 
00616       /* A number of targets can't access the whole set of raw
00617          registers (because the debug API provides no means to get at
00618          them).  */
00619       if (regcache->register_status[regnum] == REG_UNKNOWN)
00620         regcache->register_status[regnum] = REG_UNAVAILABLE;
00621     }
00622 
00623   if (regcache->register_status[regnum] != REG_VALID)
00624     memset (buf, 0, regcache->descr->sizeof_register[regnum]);
00625   else
00626     memcpy (buf, register_buffer (regcache, regnum),
00627             regcache->descr->sizeof_register[regnum]);
00628 
00629   return regcache->register_status[regnum];
00630 }
00631 
00632 enum register_status
00633 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
00634 {
00635   gdb_byte *buf;
00636   enum register_status status;
00637 
00638   gdb_assert (regcache != NULL);
00639   gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
00640   buf = alloca (regcache->descr->sizeof_register[regnum]);
00641   status = regcache_raw_read (regcache, regnum, buf);
00642   if (status == REG_VALID)
00643     *val = extract_signed_integer
00644       (buf, regcache->descr->sizeof_register[regnum],
00645        gdbarch_byte_order (regcache->descr->gdbarch));
00646   else
00647     *val = 0;
00648   return status;
00649 }
00650 
00651 enum register_status
00652 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
00653                             ULONGEST *val)
00654 {
00655   gdb_byte *buf;
00656   enum register_status status;
00657 
00658   gdb_assert (regcache != NULL);
00659   gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
00660   buf = alloca (regcache->descr->sizeof_register[regnum]);
00661   status = regcache_raw_read (regcache, regnum, buf);
00662   if (status == REG_VALID)
00663     *val = extract_unsigned_integer
00664       (buf, regcache->descr->sizeof_register[regnum],
00665        gdbarch_byte_order (regcache->descr->gdbarch));
00666   else
00667     *val = 0;
00668   return status;
00669 }
00670 
00671 void
00672 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
00673 {
00674   void *buf;
00675 
00676   gdb_assert (regcache != NULL);
00677   gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
00678   buf = alloca (regcache->descr->sizeof_register[regnum]);
00679   store_signed_integer (buf, regcache->descr->sizeof_register[regnum],
00680                         gdbarch_byte_order (regcache->descr->gdbarch), val);
00681   regcache_raw_write (regcache, regnum, buf);
00682 }
00683 
00684 void
00685 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
00686                              ULONGEST val)
00687 {
00688   void *buf;
00689 
00690   gdb_assert (regcache != NULL);
00691   gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers);
00692   buf = alloca (regcache->descr->sizeof_register[regnum]);
00693   store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum],
00694                           gdbarch_byte_order (regcache->descr->gdbarch), val);
00695   regcache_raw_write (regcache, regnum, buf);
00696 }
00697 
00698 enum register_status
00699 regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf)
00700 {
00701   gdb_assert (regnum >= 0);
00702   gdb_assert (regnum < regcache->descr->nr_cooked_registers);
00703   if (regnum < regcache->descr->nr_raw_registers)
00704     return regcache_raw_read (regcache, regnum, buf);
00705   else if (regcache->readonly_p
00706            && regcache->register_status[regnum] != REG_UNKNOWN)
00707     {
00708       /* Read-only register cache, perhaps the cooked value was
00709          cached?  */
00710       if (regcache->register_status[regnum] == REG_VALID)
00711         memcpy (buf, register_buffer (regcache, regnum),
00712                 regcache->descr->sizeof_register[regnum]);
00713       else
00714         memset (buf, 0, regcache->descr->sizeof_register[regnum]);
00715 
00716       return regcache->register_status[regnum];
00717     }
00718   else if (gdbarch_pseudo_register_read_value_p (regcache->descr->gdbarch))
00719     {
00720       struct value *mark, *computed;
00721       enum register_status result = REG_VALID;
00722 
00723       mark = value_mark ();
00724 
00725       computed = gdbarch_pseudo_register_read_value (regcache->descr->gdbarch,
00726                                                      regcache, regnum);
00727       if (value_entirely_available (computed))
00728         memcpy (buf, value_contents_raw (computed),
00729                 regcache->descr->sizeof_register[regnum]);
00730       else
00731         {
00732           memset (buf, 0, regcache->descr->sizeof_register[regnum]);
00733           result = REG_UNAVAILABLE;
00734         }
00735 
00736       value_free_to_mark (mark);
00737 
00738       return result;
00739     }
00740   else
00741     return gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache,
00742                                          regnum, buf);
00743 }
00744 
00745 struct value *
00746 regcache_cooked_read_value (struct regcache *regcache, int regnum)
00747 {
00748   gdb_assert (regnum >= 0);
00749   gdb_assert (regnum < regcache->descr->nr_cooked_registers);
00750 
00751   if (regnum < regcache->descr->nr_raw_registers
00752       || (regcache->readonly_p
00753           && regcache->register_status[regnum] != REG_UNKNOWN)
00754       || !gdbarch_pseudo_register_read_value_p (regcache->descr->gdbarch))
00755     {
00756       struct value *result;
00757 
00758       result = allocate_value (register_type (regcache->descr->gdbarch,
00759                                               regnum));
00760       VALUE_LVAL (result) = lval_register;
00761       VALUE_REGNUM (result) = regnum;
00762 
00763       /* It is more efficient in general to do this delegation in this
00764          direction than in the other one, even though the value-based
00765          API is preferred.  */
00766       if (regcache_cooked_read (regcache, regnum,
00767                                 value_contents_raw (result)) == REG_UNAVAILABLE)
00768         mark_value_bytes_unavailable (result, 0,
00769                                       TYPE_LENGTH (value_type (result)));
00770 
00771       return result;
00772     }
00773   else
00774     return gdbarch_pseudo_register_read_value (regcache->descr->gdbarch,
00775                                                regcache, regnum);
00776 }
00777 
00778 enum register_status
00779 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
00780                              LONGEST *val)
00781 {
00782   enum register_status status;
00783   gdb_byte *buf;
00784 
00785   gdb_assert (regcache != NULL);
00786   gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
00787   buf = alloca (regcache->descr->sizeof_register[regnum]);
00788   status = regcache_cooked_read (regcache, regnum, buf);
00789   if (status == REG_VALID)
00790     *val = extract_signed_integer
00791       (buf, regcache->descr->sizeof_register[regnum],
00792        gdbarch_byte_order (regcache->descr->gdbarch));
00793   else
00794     *val = 0;
00795   return status;
00796 }
00797 
00798 enum register_status
00799 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
00800                                ULONGEST *val)
00801 {
00802   enum register_status status;
00803   gdb_byte *buf;
00804 
00805   gdb_assert (regcache != NULL);
00806   gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers);
00807   buf = alloca (regcache->descr->sizeof_register[regnum]);
00808   status = regcache_cooked_read (regcache, regnum, buf);
00809   if (status == REG_VALID)
00810     *val = extract_unsigned_integer
00811       (buf, regcache->descr->sizeof_register[regnum],
00812        gdbarch_byte_order (regcache->descr->gdbarch));
00813   else
00814     *val = 0;
00815   return status;
00816 }
00817 
00818 void
00819 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
00820                               LONGEST val)
00821 {
00822   void *buf;
00823 
00824   gdb_assert (regcache != NULL);
00825   gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
00826   buf = alloca (regcache->descr->sizeof_register[regnum]);
00827   store_signed_integer (buf, regcache->descr->sizeof_register[regnum],
00828                         gdbarch_byte_order (regcache->descr->gdbarch), val);
00829   regcache_cooked_write (regcache, regnum, buf);
00830 }
00831 
00832 void
00833 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
00834                                 ULONGEST val)
00835 {
00836   void *buf;
00837 
00838   gdb_assert (regcache != NULL);
00839   gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers);
00840   buf = alloca (regcache->descr->sizeof_register[regnum]);
00841   store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum],
00842                           gdbarch_byte_order (regcache->descr->gdbarch), val);
00843   regcache_cooked_write (regcache, regnum, buf);
00844 }
00845 
00846 void
00847 regcache_raw_write (struct regcache *regcache, int regnum,
00848                     const gdb_byte *buf)
00849 {
00850   struct cleanup *old_chain;
00851 
00852   gdb_assert (regcache != NULL && buf != NULL);
00853   gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
00854   gdb_assert (!regcache->readonly_p);
00855 
00856   /* On the sparc, writing %g0 is a no-op, so we don't even want to
00857      change the registers array if something writes to this register.  */
00858   if (gdbarch_cannot_store_register (get_regcache_arch (regcache), regnum))
00859     return;
00860 
00861   /* If we have a valid copy of the register, and new value == old
00862      value, then don't bother doing the actual store.  */
00863   if (regcache_register_status (regcache, regnum) == REG_VALID
00864       && (memcmp (register_buffer (regcache, regnum), buf,
00865                   regcache->descr->sizeof_register[regnum]) == 0))
00866     return;
00867 
00868   old_chain = save_inferior_ptid ();
00869   inferior_ptid = regcache->ptid;
00870 
00871   target_prepare_to_store (regcache);
00872   memcpy (register_buffer (regcache, regnum), buf,
00873           regcache->descr->sizeof_register[regnum]);
00874   regcache->register_status[regnum] = REG_VALID;
00875   target_store_registers (regcache, regnum);
00876 
00877   do_cleanups (old_chain);
00878 }
00879 
00880 void
00881 regcache_cooked_write (struct regcache *regcache, int regnum,
00882                        const gdb_byte *buf)
00883 {
00884   gdb_assert (regnum >= 0);
00885   gdb_assert (regnum < regcache->descr->nr_cooked_registers);
00886   if (regnum < regcache->descr->nr_raw_registers)
00887     regcache_raw_write (regcache, regnum, buf);
00888   else
00889     gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache,
00890                                    regnum, buf);
00891 }
00892 
00893 /* Perform a partial register transfer using a read, modify, write
00894    operation.  */
00895 
00896 typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
00897                                     void *buf);
00898 typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
00899                                      const void *buf);
00900 
00901 static enum register_status
00902 regcache_xfer_part (struct regcache *regcache, int regnum,
00903                     int offset, int len, void *in, const void *out,
00904                     enum register_status (*read) (struct regcache *regcache,
00905                                                   int regnum,
00906                                                   gdb_byte *buf),
00907                     void (*write) (struct regcache *regcache, int regnum,
00908                                    const gdb_byte *buf))
00909 {
00910   struct regcache_descr *descr = regcache->descr;
00911   gdb_byte reg[MAX_REGISTER_SIZE];
00912 
00913   gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]);
00914   gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]);
00915   /* Something to do?  */
00916   if (offset + len == 0)
00917     return REG_VALID;
00918   /* Read (when needed) ...  */
00919   if (in != NULL
00920       || offset > 0
00921       || offset + len < descr->sizeof_register[regnum])
00922     {
00923       enum register_status status;
00924 
00925       gdb_assert (read != NULL);
00926       status = read (regcache, regnum, reg);
00927       if (status != REG_VALID)
00928         return status;
00929     }
00930   /* ... modify ...  */
00931   if (in != NULL)
00932     memcpy (in, reg + offset, len);
00933   if (out != NULL)
00934     memcpy (reg + offset, out, len);
00935   /* ... write (when needed).  */
00936   if (out != NULL)
00937     {
00938       gdb_assert (write != NULL);
00939       write (regcache, regnum, reg);
00940     }
00941 
00942   return REG_VALID;
00943 }
00944 
00945 enum register_status
00946 regcache_raw_read_part (struct regcache *regcache, int regnum,
00947                         int offset, int len, gdb_byte *buf)
00948 {
00949   struct regcache_descr *descr = regcache->descr;
00950 
00951   gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
00952   return regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
00953                              regcache_raw_read, regcache_raw_write);
00954 }
00955 
00956 void
00957 regcache_raw_write_part (struct regcache *regcache, int regnum,
00958                          int offset, int len, const gdb_byte *buf)
00959 {
00960   struct regcache_descr *descr = regcache->descr;
00961 
00962   gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
00963   regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
00964                       regcache_raw_read, regcache_raw_write);
00965 }
00966 
00967 enum register_status
00968 regcache_cooked_read_part (struct regcache *regcache, int regnum,
00969                            int offset, int len, gdb_byte *buf)
00970 {
00971   struct regcache_descr *descr = regcache->descr;
00972 
00973   gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
00974   return regcache_xfer_part (regcache, regnum, offset, len, buf, NULL,
00975                              regcache_cooked_read, regcache_cooked_write);
00976 }
00977 
00978 void
00979 regcache_cooked_write_part (struct regcache *regcache, int regnum,
00980                             int offset, int len, const gdb_byte *buf)
00981 {
00982   struct regcache_descr *descr = regcache->descr;
00983 
00984   gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
00985   regcache_xfer_part (regcache, regnum, offset, len, NULL, buf,
00986                       regcache_cooked_read, regcache_cooked_write);
00987 }
00988 
00989 /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE.  */
00990 
00991 void
00992 regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
00993 {
00994   void *regbuf;
00995   size_t size;
00996 
00997   gdb_assert (regcache != NULL);
00998   gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
00999   gdb_assert (!regcache->readonly_p);
01000 
01001   regbuf = register_buffer (regcache, regnum);
01002   size = regcache->descr->sizeof_register[regnum];
01003 
01004   if (buf)
01005     {
01006       memcpy (regbuf, buf, size);
01007       regcache->register_status[regnum] = REG_VALID;
01008     }
01009   else
01010     {
01011       /* This memset not strictly necessary, but better than garbage
01012          in case the register value manages to escape somewhere (due
01013          to a bug, no less).  */
01014       memset (regbuf, 0, size);
01015       regcache->register_status[regnum] = REG_UNAVAILABLE;
01016     }
01017 }
01018 
01019 /* Collect register REGNUM from REGCACHE and store its contents in BUF.  */
01020 
01021 void
01022 regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
01023 {
01024   const void *regbuf;
01025   size_t size;
01026 
01027   gdb_assert (regcache != NULL && buf != NULL);
01028   gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers);
01029 
01030   regbuf = register_buffer (regcache, regnum);
01031   size = regcache->descr->sizeof_register[regnum];
01032   memcpy (buf, regbuf, size);
01033 }
01034 
01035 
01036 /* Special handling for register PC.  */
01037 
01038 CORE_ADDR
01039 regcache_read_pc (struct regcache *regcache)
01040 {
01041   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01042 
01043   CORE_ADDR pc_val;
01044 
01045   if (gdbarch_read_pc_p (gdbarch))
01046     pc_val = gdbarch_read_pc (gdbarch, regcache);
01047   /* Else use per-frame method on get_current_frame.  */
01048   else if (gdbarch_pc_regnum (gdbarch) >= 0)
01049     {
01050       ULONGEST raw_val;
01051 
01052       if (regcache_cooked_read_unsigned (regcache,
01053                                          gdbarch_pc_regnum (gdbarch),
01054                                          &raw_val) == REG_UNAVAILABLE)
01055         throw_error (NOT_AVAILABLE_ERROR, _("PC register is not available"));
01056 
01057       pc_val = gdbarch_addr_bits_remove (gdbarch, raw_val);
01058     }
01059   else
01060     internal_error (__FILE__, __LINE__,
01061                     _("regcache_read_pc: Unable to find PC"));
01062   return pc_val;
01063 }
01064 
01065 void
01066 regcache_write_pc (struct regcache *regcache, CORE_ADDR pc)
01067 {
01068   struct gdbarch *gdbarch = get_regcache_arch (regcache);
01069 
01070   if (gdbarch_write_pc_p (gdbarch))
01071     gdbarch_write_pc (gdbarch, regcache, pc);
01072   else if (gdbarch_pc_regnum (gdbarch) >= 0)
01073     regcache_cooked_write_unsigned (regcache,
01074                                     gdbarch_pc_regnum (gdbarch), pc);
01075   else
01076     internal_error (__FILE__, __LINE__,
01077                     _("regcache_write_pc: Unable to update PC"));
01078 
01079   /* Writing the PC (for instance, from "load") invalidates the
01080      current frame.  */
01081   reinit_frame_cache ();
01082 }
01083 
01084 
01085 static void
01086 reg_flush_command (char *command, int from_tty)
01087 {
01088   /* Force-flush the register cache.  */
01089   registers_changed ();
01090   if (from_tty)
01091     printf_filtered (_("Register cache flushed.\n"));
01092 }
01093 
01094 enum regcache_dump_what
01095 {
01096   regcache_dump_none, regcache_dump_raw,
01097   regcache_dump_cooked, regcache_dump_groups,
01098   regcache_dump_remote
01099 };
01100 
01101 static void
01102 regcache_dump (struct regcache *regcache, struct ui_file *file,
01103                enum regcache_dump_what what_to_dump)
01104 {
01105   struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
01106   struct gdbarch *gdbarch = regcache->descr->gdbarch;
01107   int regnum;
01108   int footnote_nr = 0;
01109   int footnote_register_size = 0;
01110   int footnote_register_offset = 0;
01111   int footnote_register_type_name_null = 0;
01112   long register_offset = 0;
01113   gdb_byte buf[MAX_REGISTER_SIZE];
01114 
01115 #if 0
01116   fprintf_unfiltered (file, "nr_raw_registers %d\n",
01117                       regcache->descr->nr_raw_registers);
01118   fprintf_unfiltered (file, "nr_cooked_registers %d\n",
01119                       regcache->descr->nr_cooked_registers);
01120   fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
01121                       regcache->descr->sizeof_raw_registers);
01122   fprintf_unfiltered (file, "sizeof_raw_register_status %ld\n",
01123                       regcache->descr->sizeof_raw_register_status);
01124   fprintf_unfiltered (file, "gdbarch_num_regs %d\n", 
01125                       gdbarch_num_regs (gdbarch));
01126   fprintf_unfiltered (file, "gdbarch_num_pseudo_regs %d\n",
01127                       gdbarch_num_pseudo_regs (gdbarch));
01128 #endif
01129 
01130   gdb_assert (regcache->descr->nr_cooked_registers
01131               == (gdbarch_num_regs (gdbarch)
01132                   + gdbarch_num_pseudo_regs (gdbarch)));
01133 
01134   for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++)
01135     {
01136       /* Name.  */
01137       if (regnum < 0)
01138         fprintf_unfiltered (file, " %-10s", "Name");
01139       else
01140         {
01141           const char *p = gdbarch_register_name (gdbarch, regnum);
01142 
01143           if (p == NULL)
01144             p = "";
01145           else if (p[0] == '\0')
01146             p = "''";
01147           fprintf_unfiltered (file, " %-10s", p);
01148         }
01149 
01150       /* Number.  */
01151       if (regnum < 0)
01152         fprintf_unfiltered (file, " %4s", "Nr");
01153       else
01154         fprintf_unfiltered (file, " %4d", regnum);
01155 
01156       /* Relative number.  */
01157       if (regnum < 0)
01158         fprintf_unfiltered (file, " %4s", "Rel");
01159       else if (regnum < gdbarch_num_regs (gdbarch))
01160         fprintf_unfiltered (file, " %4d", regnum);
01161       else
01162         fprintf_unfiltered (file, " %4d",
01163                             (regnum - gdbarch_num_regs (gdbarch)));
01164 
01165       /* Offset.  */
01166       if (regnum < 0)
01167         fprintf_unfiltered (file, " %6s  ", "Offset");
01168       else
01169         {
01170           fprintf_unfiltered (file, " %6ld",
01171                               regcache->descr->register_offset[regnum]);
01172           if (register_offset != regcache->descr->register_offset[regnum]
01173               || (regnum > 0
01174                   && (regcache->descr->register_offset[regnum]
01175                       != (regcache->descr->register_offset[regnum - 1]
01176                           + regcache->descr->sizeof_register[regnum - 1])))
01177               )
01178             {
01179               if (!footnote_register_offset)
01180                 footnote_register_offset = ++footnote_nr;
01181               fprintf_unfiltered (file, "*%d", footnote_register_offset);
01182             }
01183           else
01184             fprintf_unfiltered (file, "  ");
01185           register_offset = (regcache->descr->register_offset[regnum]
01186                              + regcache->descr->sizeof_register[regnum]);
01187         }
01188 
01189       /* Size.  */
01190       if (regnum < 0)
01191         fprintf_unfiltered (file, " %5s ", "Size");
01192       else
01193         fprintf_unfiltered (file, " %5ld",
01194                             regcache->descr->sizeof_register[regnum]);
01195 
01196       /* Type.  */
01197       {
01198         const char *t;
01199 
01200         if (regnum < 0)
01201           t = "Type";
01202         else
01203           {
01204             static const char blt[] = "builtin_type";
01205 
01206             t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum));
01207             if (t == NULL)
01208               {
01209                 char *n;
01210 
01211                 if (!footnote_register_type_name_null)
01212                   footnote_register_type_name_null = ++footnote_nr;
01213                 n = xstrprintf ("*%d", footnote_register_type_name_null);
01214                 make_cleanup (xfree, n);
01215                 t = n;
01216               }
01217             /* Chop a leading builtin_type.  */
01218             if (strncmp (t, blt, strlen (blt)) == 0)
01219               t += strlen (blt);
01220           }
01221         fprintf_unfiltered (file, " %-15s", t);
01222       }
01223 
01224       /* Leading space always present.  */
01225       fprintf_unfiltered (file, " ");
01226 
01227       /* Value, raw.  */
01228       if (what_to_dump == regcache_dump_raw)
01229         {
01230           if (regnum < 0)
01231             fprintf_unfiltered (file, "Raw value");
01232           else if (regnum >= regcache->descr->nr_raw_registers)
01233             fprintf_unfiltered (file, "<cooked>");
01234           else if (regcache_register_status (regcache, regnum) == REG_UNKNOWN)
01235             fprintf_unfiltered (file, "<invalid>");
01236           else if (regcache_register_status (regcache, regnum) == REG_UNAVAILABLE)
01237             fprintf_unfiltered (file, "<unavailable>");
01238           else
01239             {
01240               regcache_raw_read (regcache, regnum, buf);
01241               print_hex_chars (file, buf,
01242                                regcache->descr->sizeof_register[regnum],
01243                                gdbarch_byte_order (gdbarch));
01244             }
01245         }
01246 
01247       /* Value, cooked.  */
01248       if (what_to_dump == regcache_dump_cooked)
01249         {
01250           if (regnum < 0)
01251             fprintf_unfiltered (file, "Cooked value");
01252           else
01253             {
01254               enum register_status status;
01255 
01256               status = regcache_cooked_read (regcache, regnum, buf);
01257               if (status == REG_UNKNOWN)
01258                 fprintf_unfiltered (file, "<invalid>");
01259               else if (status == REG_UNAVAILABLE)
01260                 fprintf_unfiltered (file, "<unavailable>");
01261               else
01262                 print_hex_chars (file, buf,
01263                                  regcache->descr->sizeof_register[regnum],
01264                                  gdbarch_byte_order (gdbarch));
01265             }
01266         }
01267 
01268       /* Group members.  */
01269       if (what_to_dump == regcache_dump_groups)
01270         {
01271           if (regnum < 0)
01272             fprintf_unfiltered (file, "Groups");
01273           else
01274             {
01275               const char *sep = "";
01276               struct reggroup *group;
01277 
01278               for (group = reggroup_next (gdbarch, NULL);
01279                    group != NULL;
01280                    group = reggroup_next (gdbarch, group))
01281                 {
01282                   if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
01283                     {
01284                       fprintf_unfiltered (file,
01285                                           "%s%s", sep, reggroup_name (group));
01286                       sep = ",";
01287                     }
01288                 }
01289             }
01290         }
01291 
01292       /* Remote packet configuration.  */
01293       if (what_to_dump == regcache_dump_remote)
01294         {
01295           if (regnum < 0)
01296             {
01297               fprintf_unfiltered (file, "Rmt Nr  g/G Offset");
01298             }
01299           else if (regnum < regcache->descr->nr_raw_registers)
01300             {
01301               int pnum, poffset;
01302 
01303               if (remote_register_number_and_offset (get_regcache_arch (regcache), regnum,
01304                                                      &pnum, &poffset))
01305                 fprintf_unfiltered (file, "%7d %11d", pnum, poffset);
01306             }
01307         }
01308 
01309       fprintf_unfiltered (file, "\n");
01310     }
01311 
01312   if (footnote_register_size)
01313     fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n",
01314                         footnote_register_size);
01315   if (footnote_register_offset)
01316     fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
01317                         footnote_register_offset);
01318   if (footnote_register_type_name_null)
01319     fprintf_unfiltered (file, 
01320                         "*%d: Register type's name NULL.\n",
01321                         footnote_register_type_name_null);
01322   do_cleanups (cleanups);
01323 }
01324 
01325 static void
01326 regcache_print (char *args, enum regcache_dump_what what_to_dump)
01327 {
01328   if (args == NULL)
01329     regcache_dump (get_current_regcache (), gdb_stdout, what_to_dump);
01330   else
01331     {
01332       struct cleanup *cleanups;
01333       struct ui_file *file = gdb_fopen (args, "w");
01334 
01335       if (file == NULL)
01336         perror_with_name (_("maintenance print architecture"));
01337       cleanups = make_cleanup_ui_file_delete (file);
01338       regcache_dump (get_current_regcache (), file, what_to_dump);
01339       do_cleanups (cleanups);
01340     }
01341 }
01342 
01343 static void
01344 maintenance_print_registers (char *args, int from_tty)
01345 {
01346   regcache_print (args, regcache_dump_none);
01347 }
01348 
01349 static void
01350 maintenance_print_raw_registers (char *args, int from_tty)
01351 {
01352   regcache_print (args, regcache_dump_raw);
01353 }
01354 
01355 static void
01356 maintenance_print_cooked_registers (char *args, int from_tty)
01357 {
01358   regcache_print (args, regcache_dump_cooked);
01359 }
01360 
01361 static void
01362 maintenance_print_register_groups (char *args, int from_tty)
01363 {
01364   regcache_print (args, regcache_dump_groups);
01365 }
01366 
01367 static void
01368 maintenance_print_remote_registers (char *args, int from_tty)
01369 {
01370   regcache_print (args, regcache_dump_remote);
01371 }
01372 
01373 extern initialize_file_ftype _initialize_regcache; /* -Wmissing-prototype */
01374 
01375 void
01376 _initialize_regcache (void)
01377 {
01378   regcache_descr_handle
01379     = gdbarch_data_register_post_init (init_regcache_descr);
01380 
01381   observer_attach_target_changed (regcache_observer_target_changed);
01382   observer_attach_thread_ptid_changed (regcache_thread_ptid_changed);
01383 
01384   add_com ("flushregs", class_maintenance, reg_flush_command,
01385            _("Force gdb to flush its register cache (maintainer command)"));
01386 
01387   add_cmd ("registers", class_maintenance, maintenance_print_registers,
01388            _("Print the internal register configuration.\n"
01389              "Takes an optional file parameter."), &maintenanceprintlist);
01390   add_cmd ("raw-registers", class_maintenance,
01391            maintenance_print_raw_registers,
01392            _("Print the internal register configuration "
01393              "including raw values.\n"
01394              "Takes an optional file parameter."), &maintenanceprintlist);
01395   add_cmd ("cooked-registers", class_maintenance,
01396            maintenance_print_cooked_registers,
01397            _("Print the internal register configuration "
01398              "including cooked values.\n"
01399              "Takes an optional file parameter."), &maintenanceprintlist);
01400   add_cmd ("register-groups", class_maintenance,
01401            maintenance_print_register_groups,
01402            _("Print the internal register configuration "
01403              "including each register's group.\n"
01404              "Takes an optional file parameter."),
01405            &maintenanceprintlist);
01406   add_cmd ("remote-registers", class_maintenance,
01407            maintenance_print_remote_registers, _("\
01408 Print the internal register configuration including each register's\n\
01409 remote register number and buffer offset in the g/G packets.\n\
01410 Takes an optional file parameter."),
01411            &maintenanceprintlist);
01412 
01413 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines