2002-08-14 Michael Snyder <msnyder@redhat.com>
[deliverable/binutils-gdb.git] / gdb / findvar.c
index 5f5766cac3c8b321367e6c602b6f9a6bb87cced5..d2591321d75dfb7958d9f29cd27c001c78e91e4c 100644 (file)
 #include "floatformat.h"
 #include "symfile.h"           /* for overlay functions */
 #include "regcache.h"
-
-/* This is used to indicate that we don't know the format of the floating point
-   number.  Typically, this is useful for native ports, where the actual format
-   is irrelevant, since no conversions will be taking place.  */
-
-const struct floatformat floatformat_unknown;
+#include "builtin-regs.h"
 
 /* Basic byte-swapping routines.  GDB has needed these for a long time...
    All extract a target-format integer at ADDR which is LEN bytes long.  */
@@ -52,21 +47,21 @@ you lose
 #endif
 
 LONGEST
-extract_signed_integer (void *addr, int len)
+extract_signed_integer (const void *addr, int len)
 {
   LONGEST retval;
-  unsigned char *p;
-  unsigned char *startaddr = (unsigned char *) addr;
-  unsigned char *endaddr = startaddr + len;
+  const unsigned char *p;
+  const unsigned char *startaddr = addr;
+  const unsigned char *endaddr = startaddr + len;
 
   if (len > (int) sizeof (LONGEST))
     error ("\
 That operation is not available on integers of more than %d bytes.",
-          sizeof (LONGEST));
+          (int) sizeof (LONGEST));
 
   /* Start at the most significant end of the integer, and work towards
      the least significant.  */
-  if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+  if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
     {
       p = startaddr;
       /* Do the sign extension once at the start.  */
@@ -86,22 +81,22 @@ That operation is not available on integers of more than %d bytes.",
 }
 
 ULONGEST
-extract_unsigned_integer (void *addr, int len)
+extract_unsigned_integer (const void *addr, int len)
 {
   ULONGEST retval;
-  unsigned char *p;
-  unsigned char *startaddr = (unsigned char *) addr;
-  unsigned char *endaddr = startaddr + len;
+  const unsigned char *p;
+  const unsigned char *startaddr = addr;
+  const unsigned char *endaddr = startaddr + len;
 
   if (len > (int) sizeof (ULONGEST))
     error ("\
 That operation is not available on integers of more than %d bytes.",
-          sizeof (ULONGEST));
+          (int) sizeof (ULONGEST));
 
   /* Start at the most significant end of the integer, and work towards
      the least significant.  */
   retval = 0;
-  if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+  if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
     {
       for (p = startaddr; p < endaddr; ++p)
        retval = (retval << 8) | *p;
@@ -126,7 +121,7 @@ extract_long_unsigned_integer (void *addr, int orig_len, LONGEST *pval)
   int len;
 
   len = orig_len;
-  if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+  if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
     {
       for (p = (char *) addr;
           len > (int) sizeof (LONGEST) && p < (char *) addr + orig_len;
@@ -210,7 +205,7 @@ store_signed_integer (void *addr, int len, LONGEST val)
 
   /* Start at the least significant end of the integer, and work towards
      the most significant.  */
-  if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+  if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
     {
       for (p = endaddr - 1; p >= startaddr; --p)
        {
@@ -237,7 +232,7 @@ store_unsigned_integer (void *addr, int len, ULONGEST val)
 
   /* Start at the least significant end of the integer, and work towards
      the most significant.  */
-  if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+  if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
     {
       for (p = endaddr - 1; p >= startaddr; --p)
        {
@@ -289,15 +284,15 @@ store_typed_address (void *buf, struct type *type, CORE_ADDR addr)
 
 
 
-/* Return a `value' with the contents of register REGNUM
-   in its virtual format, with the type specified by
-   REGISTER_VIRTUAL_TYPE.  
+/* Return a `value' with the contents of (virtual or cooked) register
+   REGNUM as found in the specified FRAME.  The register's type is
+   determined by REGISTER_VIRTUAL_TYPE.
 
-   NOTE: returns NULL if register value is not available.
-   Caller will check return value or die!  */
+   NOTE: returns NULL if register value is not available.  Caller will
+   check return value or die!  */
 
 struct value *
-value_of_register (int regnum)
+value_of_register (int regnum, struct frame_info *frame)
 {
   CORE_ADDR addr;
   int optim;
@@ -305,8 +300,20 @@ value_of_register (int regnum)
   char *raw_buffer = (char*) alloca (MAX_REGISTER_RAW_SIZE);
   enum lval_type lval;
 
+  /* Builtin registers lie completly outside of the range of normal
+     registers.  Catch them early so that the target never sees them.  */
+  if (regnum >= NUM_REGS + NUM_PSEUDO_REGS)
+    return value_of_builtin_reg (regnum, selected_frame);
+
   get_saved_register (raw_buffer, &optim, &addr,
-                     selected_frame, regnum, &lval);
+                     frame, regnum, &lval);
+
+  /* FIXME: cagney/2002-05-15: This test is just bogus.
+
+     It indicates that the target failed to supply a value for a
+     register because it was "not available" at this time.  Problem
+     is, the target still has the register and so get saved_register()
+     may be returning a value saved on the stack.  */
 
   if (register_cached (regnum) < 0)
     return NULL;               /* register value not available */
@@ -557,7 +564,7 @@ addresses have not been bound by the dynamic loader. Try again when executable i
 
        if (frame == NULL)
          return 0;
-       b = get_frame_block (frame);
+       b = get_frame_block (frame, 0);
 
        if (SYMBOL_CLASS (var) == LOC_REGPARM_ADDR)
          {
@@ -813,18 +820,18 @@ value_from_register (struct type *type, int regnum, struct frame_info *frame)
   VALUE_LVAL (v) = lval;
   VALUE_ADDRESS (v) = addr;
 
-  /* Convert raw data to virtual format if necessary.  */
+  /* Convert the raw register to the corresponding data value's memory
+     format, if necessary.  */
 
-  if (REGISTER_CONVERTIBLE (regnum))
+  if (CONVERT_REGISTER_P (regnum))
     {
-      REGISTER_CONVERT_TO_VIRTUAL (regnum, type,
-                                  raw_buffer, VALUE_CONTENTS_RAW (v));
+      REGISTER_TO_VALUE (regnum, type, raw_buffer, VALUE_CONTENTS_RAW (v));
     }
   else
     {
       /* Raw and virtual formats are the same for this register.  */
 
-      if (TARGET_BYTE_ORDER == BIG_ENDIAN && len < REGISTER_RAW_SIZE (regnum))
+      if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG && len < REGISTER_RAW_SIZE (regnum))
        {
          /* Big-endian, and we want less than full size.  */
          VALUE_OFFSET (v) = REGISTER_RAW_SIZE (regnum) - len;
This page took 0.026438 seconds and 4 git commands to generate.