2003-05-14 Elena Zannoni <ezannoni@redhat.com>
[deliverable/binutils-gdb.git] / gdb / values.c
index 28f0f4f7103df0225740d02ec311244829984b50..db667669ff5c7c2dd4cf36ed93f114f2d3b639d6 100644 (file)
@@ -1,7 +1,8 @@
 /* Low level packing and unpacking of values for GDB, the GNU Debugger.
+
    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
-   1995, 1996, 1997, 1998, 1999, 2000, 2002.
-   Free Software Foundation, Inc.
+   1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003 Free Software
+   Foundation, Inc.
 
    This file is part of GDB.
 
@@ -34,6 +35,8 @@
 #include "demangle.h"
 #include "doublest.h"
 #include "gdb_assert.h"
+#include "regcache.h"
+#include "block.h"
 
 /* Prototypes for exported functions. */
 
@@ -404,7 +407,7 @@ lookup_internalvar (char *name)
   register struct internalvar *var;
 
   for (var = internalvars; var; var = var->next)
-    if (STREQ (var->name, name))
+    if (strcmp (var->name, name) == 0)
       return var;
 
   var = (struct internalvar *) xmalloc (sizeof (struct internalvar));
@@ -421,11 +424,6 @@ value_of_internalvar (struct internalvar *var)
 {
   struct value *val;
 
-#ifdef IS_TRAPPED_INTERNALVAR
-  if (IS_TRAPPED_INTERNALVAR (var->name))
-    return VALUE_OF_TRAPPED_INTERNALVAR (var);
-#endif
-
   val = value_copy (var->value);
   if (VALUE_LAZY (val))
     value_fetch_lazy (val);
@@ -440,11 +438,6 @@ set_internalvar_component (struct internalvar *var, int offset, int bitpos,
 {
   register char *addr = VALUE_CONTENTS (var->value) + offset;
 
-#ifdef IS_TRAPPED_INTERNALVAR
-  if (IS_TRAPPED_INTERNALVAR (var->name))
-    SET_TRAPPED_INTERNALVAR (var, newval, bitpos, bitsize, offset);
-#endif
-
   if (bitsize)
     modify_field (addr, value_as_long (newval),
                  bitpos, bitsize);
@@ -457,11 +450,6 @@ set_internalvar (struct internalvar *var, struct value *val)
 {
   struct value *newval;
 
-#ifdef IS_TRAPPED_INTERNALVAR
-  if (IS_TRAPPED_INTERNALVAR (var->name))
-    SET_TRAPPED_INTERNALVAR (var, val, 0, 0, 0);
-#endif
-
   newval = value_copy (val);
   newval->modifiable = 1;
 
@@ -515,10 +503,6 @@ show_convenience (char *ignore, int from_tty)
 
   for (var = internalvars; var; var = var->next)
     {
-#ifdef IS_TRAPPED_INTERNALVAR
-      if (IS_TRAPPED_INTERNALVAR (var->name))
-       continue;
-#endif
       if (!varseen)
        {
          varseen = 1;
@@ -678,7 +662,7 @@ value_as_address (struct value *val)
    to an INT (or some size).  After all, it is only an offset.  */
 
 LONGEST
-unpack_long (struct type *type, char *valaddr)
+unpack_long (struct type *type, const char *valaddr)
 {
   register enum type_code code = TYPE_CODE (type);
   register int len = TYPE_LENGTH (type);
@@ -727,7 +711,7 @@ unpack_long (struct type *type, char *valaddr)
    format, result is in host format.  */
 
 DOUBLEST
-unpack_double (struct type *type, char *valaddr, int *invp)
+unpack_double (struct type *type, const char *valaddr, int *invp)
 {
   enum type_code code;
   int len;
@@ -784,7 +768,7 @@ unpack_double (struct type *type, char *valaddr, int *invp)
    to an INT (or some size).  After all, it is only an offset.  */
 
 CORE_ADDR
-unpack_pointer (struct type *type, char *valaddr)
+unpack_pointer (struct type *type, const char *valaddr)
 {
   /* Assume a CORE_ADDR can fit in a LONGEST (for now).  Not sure
      whether we want this to be true eventually.  */
@@ -792,22 +776,25 @@ unpack_pointer (struct type *type, char *valaddr)
 }
 
 \f
-/* Get the value of the FIELDN'th field (which must be static) of TYPE. */
+/* Get the value of the FIELDN'th field (which must be static) of
+   TYPE.  Return NULL if the field doesn't exist or has been
+   optimized out. */
 
 struct value *
 value_static_field (struct type *type, int fieldno)
 {
-  CORE_ADDR addr;
-  asection *sect;
+  struct value *retval;
+
   if (TYPE_FIELD_STATIC_HAS_ADDR (type, fieldno))
     {
-      addr = TYPE_FIELD_STATIC_PHYSADDR (type, fieldno);
-      sect = NULL;
+      retval = value_at (TYPE_FIELD_TYPE (type, fieldno),
+                        TYPE_FIELD_STATIC_PHYSADDR (type, fieldno),
+                        NULL);
     }
   else
     {
       char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (type, fieldno);
-      struct symbol *sym = lookup_symbol (phys_name, 0, VAR_NAMESPACE, 0, NULL);
+      struct symbol *sym = lookup_symbol (phys_name, 0, VAR_DOMAIN, 0, NULL);
       if (sym == NULL)
        {
          /* With some compilers, e.g. HP aCC, static data members are reported
@@ -817,27 +804,25 @@ value_static_field (struct type *type, int fieldno)
            return NULL;
          else
            {
-             addr = SYMBOL_VALUE_ADDRESS (msym);
-             sect = SYMBOL_BFD_SECTION (msym);
+             retval = value_at (TYPE_FIELD_TYPE (type, fieldno),
+                                SYMBOL_VALUE_ADDRESS (msym),
+                                SYMBOL_BFD_SECTION (msym));
            }
        }
       else
        {
-         /* Anything static that isn't a constant, has an address */
-         if (SYMBOL_CLASS (sym) != LOC_CONST)
-           {
-             addr = SYMBOL_VALUE_ADDRESS (sym);
-             sect = SYMBOL_BFD_SECTION (sym);
-           }
-         /* However, static const's do not, the value is already known.  */
-         else
-           {
-             return value_from_longest (TYPE_FIELD_TYPE (type, fieldno), SYMBOL_VALUE (sym));
-           }
+         /* SYM should never have a SYMBOL_CLASS which will require
+            read_var_value to use the FRAME parameter.  */
+         if (symbol_read_needs_frame (sym))
+           warning ("static field's value depends on the current "
+                    "frame - bad debug info?");
+         retval = read_var_value (sym, NULL);
        }
-      SET_FIELD_PHYSADDR (TYPE_FIELD (type, fieldno), addr);
+      if (retval && VALUE_LVAL (retval) == lval_memory)
+       SET_FIELD_PHYSADDR (TYPE_FIELD (type, fieldno),
+                           VALUE_ADDRESS (retval));
     }
-  return value_at (TYPE_FIELD_TYPE (type, fieldno), addr, sect);
+  return retval;
 }
 
 /* Change the enclosing type of a value object VAL to NEW_ENCL_TYPE.  
@@ -860,7 +845,9 @@ value_change_enclosing_type (struct value *val, struct type *new_encl_type)
       struct value *prev;
       
       new_val = (struct value *) xrealloc (val, sizeof (struct value) + TYPE_LENGTH (new_encl_type));
-      
+
+      VALUE_ENCLOSING_TYPE (new_val) = new_encl_type;
       /* We have to make sure this ends up in the same place in the value
         chain as the original copy, so it's clean-up behavior is the same. 
         If the value has been released, this is a waste of time, but there
@@ -981,7 +968,7 @@ value_fn_field (struct value **arg1p, struct fn_field *f, int j, struct type *ty
   struct symbol *sym;
   struct minimal_symbol *msym;
 
-  sym = lookup_symbol (physname, 0, VAR_NAMESPACE, 0, NULL);
+  sym = lookup_symbol (physname, 0, VAR_DOMAIN, 0, NULL);
   if (sym != NULL)
     {
       msym = NULL;
@@ -1034,7 +1021,7 @@ value_fn_field (struct value **arg1p, struct fn_field *f, int j, struct type *ty
    If the field is signed, we also do sign extension. */
 
 LONGEST
-unpack_field_as_long (struct type *type, char *valaddr, int fieldno)
+unpack_field_as_long (struct type *type, const char *valaddr, int fieldno)
 {
   ULONGEST val;
   ULONGEST valmask;
@@ -1224,12 +1211,12 @@ value_from_double (struct type *type, DOUBLEST num)
 
 /* ARGSUSED */
 struct value *
-value_being_returned (struct type *valtype, char *retbuf, int struct_return)
+value_being_returned (struct type *valtype, struct regcache *retbuf,
+                     int struct_return)
 {
   struct value *val;
   CORE_ADDR addr;
 
-#if 0
   /* If this is not defined, just use EXTRACT_RETURN_VALUE instead.  */
   if (EXTRACT_STRUCT_VALUE_ADDRESS_P ())
     if (struct_return)
@@ -1239,13 +1226,13 @@ value_being_returned (struct type *valtype, char *retbuf, int struct_return)
          error ("Function return value unknown.");
        return value_at (valtype, addr, NULL);
       }
-#endif
 
   /* If this is not defined, just use EXTRACT_RETURN_VALUE instead.  */
   if (DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS_P ())
     if (struct_return)
       {
-       addr = DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS (retbuf);
+       char *buf = deprecated_grub_regcache_for_registers (retbuf);
+       addr = DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS (buf);
        if (!addr)
          error ("Function return value unknown.");
        return value_at (valtype, addr, NULL);
@@ -1253,8 +1240,9 @@ value_being_returned (struct type *valtype, char *retbuf, int struct_return)
 
   val = allocate_value (valtype);
   CHECK_TYPEDEF (valtype);
-#define EXTRACT_RETURN_VALUE DEPRECATED_EXTRACT_RETURN_VALUE
-  EXTRACT_RETURN_VALUE (valtype, retbuf, VALUE_CONTENTS_RAW (val));
+  /* If the function returns void, don't bother fetching the return value.  */
+  if (TYPE_CODE (valtype) != TYPE_CODE_VOID)
+    EXTRACT_RETURN_VALUE (valtype, retbuf, VALUE_CONTENTS_RAW (val));
 
   return val;
 }
@@ -1327,7 +1315,7 @@ set_return_value (struct value *val)
       || code == TYPE_CODE_UNION)      /* FIXME, implement struct return.  */
     error ("GDB does not support specifying a struct or union return value.");
 
-  STORE_RETURN_VALUE (type, VALUE_CONTENTS (val));
+  STORE_RETURN_VALUE (type, current_regcache, VALUE_CONTENTS (val));
 }
 \f
 void
This page took 0.041459 seconds and 4 git commands to generate.