]> Git Repo - binutils.git/blobdiff - gdb/valops.c
More filename renaming.
[binutils.git] / gdb / valops.c
index 75620d0601b7d77eee90b960b7c8cc22fede533d..45cca2e2eeb39cc6d9083499ed5769a36d93b7a6 100644 (file)
@@ -1,25 +1,24 @@
 /* Perform non-arithmetic operations on values, for GDB.
-   Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc.
+   Copyright 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
 
 This file is part of GDB.
 
-GDB is free software; you can redistribute it and/or modify
+This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 1, or (at your option)
-any later version.
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
 
-GDB is distributed in the hope that it will be useful,
+This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GDB; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include <stdio.h>
 #include "defs.h"
-#include "param.h"
 #include "symtab.h"
 #include "value.h"
 #include "frame.h"
@@ -60,7 +59,7 @@ value_cast (type, arg2)
     return value_from_double (type, value_as_double (arg2));
   else if ((code1 == TYPE_CODE_INT || code1 == TYPE_CODE_ENUM)
           && (scalar || code2 == TYPE_CODE_PTR))
-    return value_from_long (type, value_as_long (arg2));
+    return value_from_longest (type, value_as_long (arg2));
   else if (TYPE_LENGTH (type) == TYPE_LENGTH (VALUE_TYPE (arg2)))
     {
       if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
@@ -92,6 +91,10 @@ value_cast (type, arg2)
     {
       return value_at_lazy (type, VALUE_ADDRESS (arg2) + VALUE_OFFSET (arg2));
     }
+  else if (code1 == TYPE_CODE_VOID)
+    {
+      return value_zero (builtin_type_void, not_lval);
+    }
   else
     {
       error ("Invalid cast.");
@@ -159,6 +162,9 @@ value_at_lazy (type, addr)
    data from the user's process, and clears the lazy flag to indicate
    that the data in the buffer is valid.
 
+   If the value is zero-length, we avoid calling read_memory, which would
+   abort.  We mark the value as fetched anyway -- all 0 bytes of it.
+
    This function returns a value because it is used in the VALUE_CONTENTS
    macro as part of an expression, where a void would not work.  The
    value is ignored.  */
@@ -169,8 +175,9 @@ value_fetch_lazy (val)
 {
   CORE_ADDR addr = VALUE_ADDRESS (val) + VALUE_OFFSET (val);
 
-  read_memory (addr, VALUE_CONTENTS_RAW (val), 
-              TYPE_LENGTH (VALUE_TYPE (val)));
+  if (TYPE_LENGTH (VALUE_TYPE (val)))
+    read_memory (addr, VALUE_CONTENTS_RAW (val), 
+                TYPE_LENGTH (VALUE_TYPE (val)));
   VALUE_LAZY (val) = 0;
   return 0;
 }
@@ -397,14 +404,14 @@ value_of_variable (var)
 }
 
 /* Given a value which is an array, return a value which is
-   a pointer to its first element.  */
+   a pointer to its first (actually, zeroth) element. 
+   FIXME, this should be subtracting the array's lower bound. */
 
 value
 value_coerce_array (arg1)
      value arg1;
 {
   register struct type *type;
-  register value val;
 
   if (VALUE_LVAL (arg1) != lval_memory)
     error ("Attempt to take address of value not located in memory.");
@@ -417,12 +424,8 @@ value_coerce_array (arg1)
        Its type is the type of the elements, not an array type.  */
     type = VALUE_TYPE (arg1);
 
-  /* Get the type of the result.  */
-  type = lookup_pointer_type (type);
-  val = value_from_long (builtin_type_long,
+  return value_from_longest (lookup_pointer_type (type),
                       (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
-  VALUE_TYPE (val) = type;
-  return val;
 }
 
 /* Given a value which is a function, return a value which is a pointer
@@ -432,18 +435,12 @@ value
 value_coerce_function (arg1)
      value arg1;
 {
-  register struct type *type;
-  register value val;
 
   if (VALUE_LVAL (arg1) != lval_memory)
     error ("Attempt to take address of value not located in memory.");
 
-  /* Get the type of the result.  */
-  type = lookup_pointer_type (VALUE_TYPE (arg1));
-  val = value_from_long (builtin_type_long,
+  return value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)),
                (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
-  VALUE_TYPE (val) = type;
-  return val;
 }  
 
 /* Return a pointer value for the object for which ARG1 is the contents.  */
@@ -452,12 +449,8 @@ value
 value_addr (arg1)
      value arg1;
 {
-  register struct type *type;
-  register value val;
 
   COERCE_REF(arg1);
-  /* Taking the address of an array is really a no-op
-     once the array is coerced to a pointer to its first element.  */
   if (VALUE_REPEATED (arg1)
       || TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_ARRAY)
     return value_coerce_array (arg1);
@@ -467,12 +460,8 @@ value_addr (arg1)
   if (VALUE_LVAL (arg1) != lval_memory)
     error ("Attempt to take address of value not located in memory.");
 
-  /* Get the type of the result.  */
-  type = lookup_pointer_type (VALUE_TYPE (arg1));
-  val = value_from_long (builtin_type_long,
+  return value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)),
                (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
-  VALUE_TYPE (val) = type;
-  return val;
 }
 
 /* Given a value of a pointer type, apply the C unary * operator to it.  */
@@ -495,7 +484,7 @@ value_ind (arg1)
                     (CORE_ADDR) value_as_long (arg1));
   else if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_PTR)
     return value_at_lazy (TYPE_TARGET_TYPE (VALUE_TYPE (arg1)),
-                    (CORE_ADDR) value_as_long (arg1));
+                         value_as_pointer (arg1));
   error ("Attempt to take contents of a non-pointer value.");
   return 0;  /* For lint -- never reached */
 }
@@ -620,7 +609,7 @@ find_function_addr (function, retval_type)
     }
   else if (code == TYPE_CODE_PTR)
     {
-      funaddr = value_as_long (function);
+      funaddr = value_as_pointer (function);
       if (TYPE_CODE (TYPE_TARGET_TYPE (ftype)) == TYPE_CODE_FUNC
          || TYPE_CODE (TYPE_TARGET_TYPE (ftype)) == TYPE_CODE_METHOD)
        value_type = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype));
@@ -632,10 +621,10 @@ find_function_addr (function, retval_type)
       /* Handle the case of functions lacking debugging info.
         Their values are characters since their addresses are char */
       if (TYPE_LENGTH (ftype) == 1)
-       funaddr = value_as_long (value_addr (function));
+       funaddr = value_as_pointer (value_addr (function));
       else
        /* Handle integer used as address of a function.  */
-       funaddr = value_as_long (function);
+       funaddr = (CORE_ADDR) value_as_long (function);
 
       value_type = builtin_type_int;
     }
@@ -673,7 +662,7 @@ call_function_by_hand (function, nargs, args)
   register int i;
   CORE_ADDR start_sp;
   /* CALL_DUMMY is an array of words (REGISTER_TYPE), but each word
-     in in host byte order.  It is switched to target byte order before calling
+     is in host byte order.  It is switched to target byte order before calling
      FIX_CALL_DUMMY.  */
   static REGISTER_TYPE dummy[] = CALL_DUMMY;
   REGISTER_TYPE dummy1[sizeof dummy / sizeof (REGISTER_TYPE)];
@@ -734,6 +723,7 @@ call_function_by_hand (function, nargs, args)
   /* Convex Unix prohibits executing in the stack segment. */
   /* Hope there is empty room at the top of the text segment. */
   {
+    extern CORE_ADDR text_end;
     static checked = 0;
     if (!checked)
       for (start_sp = text_end - sizeof dummy; start_sp < text_end; ++start_sp)
@@ -746,6 +736,7 @@ call_function_by_hand (function, nargs, args)
   }
 #else /* After text_end.  */
   {
+    extern CORE_ADDR text_end;
     int errcode;
     sp = old_sp;
     start_sp = text_end;
@@ -821,7 +812,8 @@ call_function_by_hand (function, nargs, args)
 #endif
            /* The value we're going to pass is the address of the thing
               we just pushed.  */
-           args[i] = value_from_long (builtin_type_long, (LONGEST) addr);
+           args[i] = value_from_longest (lookup_pointer_type (value_type),
+                                      (LONGEST) addr);
          }
   }
 #endif /* REG_STRUCT_HAS_ADDR.  */
@@ -904,7 +896,7 @@ value_string (ptr, len)
   register int c;
 
   /* Copy the string into COPY, processing escapes.
-     We could not conveniently process them in expread
+     We could not conveniently process them in the parser
      because the string there wants to be a substring of the input.  */
 
   while (i - ibeg < len)
@@ -936,21 +928,21 @@ value_string (ptr, len)
   else
     {
       register int j;
-      for (j = 0; j < misc_function_count; j++)
-       if (!strcmp (misc_function_vector[j].name, "malloc"))
-         break;
-      if (j < misc_function_count)
-       val = value_from_long (builtin_type_long,
-                            (LONGEST) misc_function_vector[j].address);
+      j = lookup_misc_func ("malloc");
+      if (j >= 0)
+       val = value_from_longest (
+               lookup_pointer_type (lookup_function_type (
+                                     lookup_pointer_type (builtin_type_char))),
+                              (LONGEST) misc_function_vector[j].address);
       else
        error ("String constants require the program to have a function \"malloc\".");
     }
 
-  blocklen = value_from_long (builtin_type_int, (LONGEST) (len + 1));
+  blocklen = value_from_longest (builtin_type_int, (LONGEST) (len + 1));
   val = target_call_function (val, 1, &blocklen);
   if (value_zerop (val))
     error ("No memory available for string constant.");
-  write_memory ((CORE_ADDR) value_as_long (val), copy, len + 1);
+  write_memory (value_as_pointer (val), copy, len + 1);
   VALUE_TYPE (val) = lookup_pointer_type (builtin_type_char);
   return val;
 }
@@ -1002,7 +994,8 @@ search_struct_field (name, arg1, offset, type, looking_for_baseclass)
       if (BASETYPE_VIA_VIRTUAL (type, i))
        {
          value v2;
-         baseclass_addr (type, i, VALUE_CONTENTS (arg1) + offset, &v2);
+         baseclass_addr (type, i, VALUE_CONTENTS (arg1) + offset,
+                         &v2, (int *)NULL);
          if (v2 == 0)
            error ("virtual baseclass botch");
          if (found_baseclass)
@@ -1060,7 +1053,7 @@ search_struct_method (name, arg1, args, offset, static_memfuncp, type)
                    return (value)value_virtual_fn_field (arg1, f, j, type);
                  if (TYPE_FN_FIELD_STATIC_P (f, j) && static_memfuncp)
                    *static_memfuncp = 1;
-                 return (value)value_fn_field (arg1, i, j);
+                 return (value)value_fn_field (f, j);
                }
              j--;
            }
@@ -1074,7 +1067,8 @@ search_struct_method (name, arg1, args, offset, static_memfuncp, type)
       if (BASETYPE_VIA_VIRTUAL (type, i))
        {
          value v2;
-         baseclass_addr (type, i, VALUE_CONTENTS (arg1) + offset, &v2);
+         baseclass_addr (type, i, VALUE_CONTENTS (arg1) + offset,
+                         &v2, (int *)NULL);
          if (v2 == 0)
            error ("virtual baseclass botch");
          v = search_struct_method (name, v2, args, 0,
@@ -1174,7 +1168,7 @@ value_struct_elt (argp, args, name, static_memfuncp, err)
       if (!args[1])
        {
          /* destructors are a special case.  */
-         return (value)value_fn_field (*argp, 0,
+         return (value)value_fn_field (TYPE_FN_FIELDLIST1 (t, 0),
                                        TYPE_FN_FIELDLIST_LENGTH (t, 0));
        }
       else
@@ -1211,9 +1205,6 @@ destructor_name_p (name, type)
   if (name[0] == '~')
     {
       char *dname = type_name_no_tag (type);
-
-      if (! TYPE_HAS_DESTRUCTOR (type))
-       error ("type `%s' does not have destructor defined", dname);
       if (strcmp (dname, name+1))
        error ("name of destructor must equal name of class");
       else
@@ -1327,19 +1318,17 @@ value_struct_elt_for_address (domain, intype, name)
                  struct symbol *sym =
                      lookup_symbol (phys_name, 0, VAR_NAMESPACE, 0, NULL);
                  if (! sym) error ("Internal error: could not find physical static variable named %s", phys_name);
-                 v = value_from_long(builtin_type_long,
-                                     (CORE_ADDR)SYMBOL_BLOCK_VALUE (sym));
-                 VALUE_TYPE(v) = lookup_pointer_type (TYPE_FIELD_TYPE (t, i));
-                 return v;
+                 return value_from_longest (
+                       lookup_pointer_type (TYPE_FIELD_TYPE (t, i)),
+                                     (LONGEST)SYMBOL_BLOCK_VALUE (sym));
                }
              if (TYPE_FIELD_PACKED (t, i))
                error ("pointers to bitfield members not allowed");
 
-             v = value_from_long (builtin_type_int,
+             return value_from_longest (
+                   lookup_pointer_type (
+                     lookup_member_type (TYPE_FIELD_TYPE (t, i), baseclass)),
                                   (LONGEST) (TYPE_FIELD_BITPOS (t, i) >> 3));
-             VALUE_TYPE (v)
-               = lookup_pointer_type (lookup_member_type (TYPE_FIELD_TYPE (t, i), baseclass));
-             return v;
            }
        }
 
@@ -1388,7 +1377,10 @@ value_struct_elt_for_address (domain, intype, name)
              check_stub_method (t, i, j);
              if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
                {
-                 v = value_from_long (builtin_type_long,
+                 return value_from_longest (
+                       lookup_pointer_type (
+                         lookup_member_type (TYPE_FN_FIELD_TYPE (f, j),
+                                             baseclass)),
                                       (LONGEST) TYPE_FN_FIELD_VOFFSET (f, j));
                }
              else
@@ -1396,9 +1388,9 @@ value_struct_elt_for_address (domain, intype, name)
                  struct symbol *s = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
                                                    0, VAR_NAMESPACE, 0, NULL);
                  v = locate_var_value (s, 0);
+                 VALUE_TYPE (v) = lookup_pointer_type (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j), baseclass));
+                 return v;
                }
-             VALUE_TYPE (v) = lookup_pointer_type (lookup_member_type (TYPE_FN_FIELD_TYPE (f, j), baseclass));
-             return v;
            }
        }
 
This page took 0.034613 seconds and 4 git commands to generate.