* symtab.h (enum address_class): Remove LOC_INDIRECT and
[deliverable/binutils-gdb.git] / gdb / value.c
index 8435404d687b9227e292a5c6036028e607695cfa..71ddf5c0399a77bd8618be72a4117e74a2d4c8d8 100644 (file)
@@ -1,7 +1,7 @@
 /* Low level packing and unpacking of values for GDB, the GNU Debugger.
 
    Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007
+   1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -34,6 +34,8 @@
 #include "gdb_assert.h"
 #include "regcache.h"
 #include "block.h"
+#include "dfp.h"
+#include "objfiles.h"
 
 /* Prototypes for exported functions. */
 
@@ -71,8 +73,8 @@ struct value
   int bitsize;
 
   /* Only used for bitfields; position of start of field.  For
-     BITS_BIG_ENDIAN=0 targets, it is the position of the LSB.  For
-     BITS_BIG_ENDIAN=1 targets, it is the position of the MSB. */
+     gdbarch_bits_big_endian=0 targets, it is the position of the LSB.  For
+     gdbarch_bits_big_endian=1 targets, it is the position of the MSB. */
   int bitpos;
 
   /* Frame register value is relative to.  This will be described in
@@ -136,9 +138,9 @@ struct value
   short regnum;
 
   /* If zero, contents of this value are in the contents field.  If
-     nonzero, contents are in inferior memory at address in the
-     location.address field plus the offset field (and the lval field
-     should be lval_memory).
+     nonzero, contents are in inferior.  If the lval field is lval_memory,
+     the contents are in inferior memory at location.address plus offset.
+     The lval field may also be lval_register.
 
      WARNING: This field is used by the code which handles watchpoints
      (see breakpoint.c) to decide whether a particular value can be
@@ -238,7 +240,7 @@ allocate_value (struct type *type)
 }
 
 /* Allocate a  value  that has the correct length
-   for COUNT repetitions type TYPE.  */
+   for COUNT repetitions of type TYPE.  */
 
 struct value *
 allocate_repeat_value (struct type *type, int count)
@@ -663,14 +665,14 @@ show_values (char *num_exp, int from_tty)
 
   if (num_exp)
     {
-      /* "info history +" should print from the stored position.
-         "info history <exp>" should print around value number <exp>.  */
+      /* "show values +" should print from the stored position.
+         "show values <exp>" should print around value number <exp>.  */
       if (num_exp[0] != '+' || num_exp[1] != '\0')
        num = parse_and_eval_long (num_exp) - 5;
     }
   else
     {
-      /* "info history" means print the last 10 values.  */
+      /* "show values" means print the last 10 values.  */
       num = value_history_count - 9;
     }
 
@@ -685,12 +687,12 @@ show_values (char *num_exp, int from_tty)
       printf_filtered (("\n"));
     }
 
-  /* The next "info history +" should start after what we just printed.  */
+  /* The next "show values +" should start after what we just printed.  */
   num += 10;
 
   /* Hitting just return after this command should do the same thing as
-     "info history +".  If num_exp is null, this is unnecessary, since
-     "info history +" is not useful after "info history".  */
+     "show values +".  If num_exp is null, this is unnecessary, since
+     "show values +" is not useful after "show values".  */
   if (from_tty && num_exp)
     {
       num_exp[0] = '+';
@@ -742,10 +744,10 @@ init_if_undefined_command (char* args, int from_tty)
    normally include a dollar sign.
 
    If the specified internal variable does not exist,
-   one is created, with a void value.  */
+   the return value is NULL.  */
 
 struct internalvar *
-lookup_internalvar (char *name)
+lookup_only_internalvar (char *name)
 {
   struct internalvar *var;
 
@@ -753,6 +755,17 @@ lookup_internalvar (char *name)
     if (strcmp (var->name, name) == 0)
       return var;
 
+  return NULL;
+}
+
+
+/* Create an internal variable with name NAME and with a void value.
+   NAME should not normally include a dollar sign.  */
+
+struct internalvar *
+create_internalvar (char *name)
+{
+  struct internalvar *var;
   var = (struct internalvar *) xmalloc (sizeof (struct internalvar));
   var->name = concat (name, (char *)NULL);
   var->value = allocate_value (builtin_type_void);
@@ -763,6 +776,25 @@ lookup_internalvar (char *name)
   return var;
 }
 
+
+/* Look up an internal variable with name NAME.  NAME should not
+   normally include a dollar sign.
+
+   If the specified internal variable does not exist,
+   one is created, with a void value.  */
+
+struct internalvar *
+lookup_internalvar (char *name)
+{
+  struct internalvar *var;
+
+  var = lookup_only_internalvar (name);
+  if (var)
+    return var;
+
+  return create_internalvar (name);
+}
+
 struct value *
 value_of_internalvar (struct internalvar *var)
 {
@@ -951,6 +983,7 @@ value_as_double (struct value *val)
     error (_("Invalid floating value found in program."));
   return foo;
 }
+
 /* Extract a value as a C pointer. Does not deallocate the value.  
    Note that val's type may not actually be a pointer; value_as_long
    handles all the cases.  */
@@ -1096,6 +1129,11 @@ unpack_long (struct type *type, const gdb_byte *valaddr)
     case TYPE_CODE_FLT:
       return extract_typed_floating (valaddr, type);
 
+    case TYPE_CODE_DECFLOAT:
+      /* libdecnumber has a function to convert from decimal to integer, but
+        it doesn't work when the decimal number has a fractional part.  */
+      return decimal_to_doublest (valaddr, len);
+
     case TYPE_CODE_PTR:
     case TYPE_CODE_REF:
       /* Assume a CORE_ADDR can fit in a LONGEST (for now).  Not sure
@@ -1153,6 +1191,8 @@ unpack_double (struct type *type, const gdb_byte *valaddr, int *invp)
 
       return extract_typed_floating (valaddr, type);
     }
+  else if (code == TYPE_CODE_DECFLOAT)
+    return decimal_to_doublest (valaddr, len);
   else if (nosign)
     {
       /* Unsigned -- be sure we compensate for signed LONGEST.  */
@@ -1204,7 +1244,7 @@ value_static_field (struct type *type, int fieldno)
   else
     {
       char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (type, fieldno);
-      struct symbol *sym = lookup_symbol (phys_name, 0, VAR_DOMAIN, 0, NULL);
+      struct symbol *sym = lookup_symbol (phys_name, 0, VAR_DOMAIN, 0);
       if (sym == NULL)
        {
          /* With some compilers, e.g. HP aCC, static data members are reported
@@ -1314,7 +1354,7 @@ value_primitive_field (struct value *arg1, int offset,
          bases, etc.  */
       v = allocate_value (value_enclosing_type (arg1));
       v->type = type;
-      if (value_lazy (arg1))
+      if (VALUE_LVAL (arg1) == lval_memory && value_lazy (arg1))
        set_value_lazy (v, 1);
       else
        memcpy (value_contents_all_raw (v), value_contents_all_raw (arg1),
@@ -1328,7 +1368,7 @@ value_primitive_field (struct value *arg1, int offset,
       /* Plain old data member */
       offset += TYPE_FIELD_BITPOS (arg_type, fieldno) / 8;
       v = allocate_value (type);
-      if (value_lazy (arg1))
+      if (VALUE_LVAL (arg1) == lval_memory && value_lazy (arg1))
        set_value_lazy (v, 1);
       else
        memcpy (value_contents_raw (v),
@@ -1374,7 +1414,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_DOMAIN, 0, NULL);
+  sym = lookup_symbol (physname, 0, VAR_DOMAIN, 0);
   if (sym != NULL)
     {
       msym = NULL;
@@ -1394,7 +1434,14 @@ value_fn_field (struct value **arg1p, struct fn_field *f, int j, struct type *ty
     }
   else
     {
-      VALUE_ADDRESS (v) = SYMBOL_VALUE_ADDRESS (msym);
+      /* The minimal symbol might point to a function descriptor;
+        resolve it to the actual code address instead.  */
+      struct objfile *objfile = msymbol_objfile (msym);
+      struct gdbarch *gdbarch = get_objfile_arch (objfile);
+
+      VALUE_ADDRESS (v)
+       = gdbarch_convert_from_func_ptr_addr
+          (gdbarch, SYMBOL_VALUE_ADDRESS (msym), &current_target);
     }
 
   if (arg1p)
@@ -1442,7 +1489,7 @@ unpack_field_as_long (struct type *type, const gdb_byte *valaddr, int fieldno)
 
   /* Extract bits.  See comment above. */
 
-  if (BITS_BIG_ENDIAN)
+  if (gdbarch_bits_big_endian (current_gdbarch))
     lsbcount = (sizeof val * 8 - bitpos % 8 - bitsize);
   else
     lsbcount = (bitpos % 8);
@@ -1498,7 +1545,7 @@ modify_field (gdb_byte *addr, LONGEST fieldval, int bitpos, int bitsize)
   oword = extract_unsigned_integer (addr, sizeof oword);
 
   /* Shifting for bit field depends on endianness of the target machine.  */
-  if (BITS_BIG_ENDIAN)
+  if (gdbarch_bits_big_endian (current_gdbarch))
     bitpos = sizeof (oword) * 8 - bitpos - bitsize;
 
   oword &= ~(mask << bitpos);
@@ -1611,6 +1658,16 @@ value_from_double (struct type *type, DOUBLEST num)
   return val;
 }
 
+struct value *
+value_from_decfloat (struct type *type, const gdb_byte *dec)
+{
+  struct value *val = allocate_value (type);
+
+  memcpy (value_contents_raw (val), dec, TYPE_LENGTH (type));
+
+  return val;
+}
+
 struct value *
 coerce_ref (struct value *arg)
 {
@@ -1651,39 +1708,12 @@ coerce_enum (struct value *arg)
 }
 \f
 
-/* Should we use DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS instead of
-   gdbarch_extract_return_value?  GCC_P is true if compiled with gcc and TYPE
-   is the type (which is known to be struct, union or array).
-
-   On most machines, the struct convention is used unless we are
-   using gcc and the type is of a special size.  */
-/* As of about 31 Mar 93, GCC was changed to be compatible with the
-   native compiler.  GCC 2.3.3 was the last release that did it the
-   old way.  Since gcc2_compiled was not changed, we have no
-   way to correctly win in all cases, so we just do the right thing
-   for gcc1 and for gcc2 after this change.  Thus it loses for gcc
-   2.0-2.3.3.  This is somewhat unfortunate, but changing gcc2_compiled
-   would cause more chaos than dealing with some struct returns being
-   handled wrong.  */
-/* NOTE: cagney/2004-06-13: Deleted check for "gcc_p".  GCC 1.x is
-   dead.  */
-
-int
-generic_use_struct_convention (int gcc_p, struct type *value_type)
-{
-  return !(TYPE_LENGTH (value_type) == 1
-          || TYPE_LENGTH (value_type) == 2
-          || TYPE_LENGTH (value_type) == 4
-          || TYPE_LENGTH (value_type) == 8);
-}
-
 /* Return true if the function returning the specified type is using
    the convention of returning structures in memory (passing in the
-   address as a hidden first parameter).  GCC_P is nonzero if compiled
-   with GCC.  */
+   address as a hidden first parameter).  */
 
 int
-using_struct_return (struct type *value_type, int gcc_p)
+using_struct_return (struct type *func_type, struct type *value_type)
 {
   enum type_code code = TYPE_CODE (value_type);
 
@@ -1696,7 +1726,7 @@ using_struct_return (struct type *value_type, int gcc_p)
     return 0;
 
   /* Probe the architecture for the return-value convention.  */
-  return (gdbarch_return_value (current_gdbarch, value_type,
+  return (gdbarch_return_value (current_gdbarch, func_type, value_type,
                                NULL, NULL, NULL)
          != RETURN_VALUE_REGISTER_CONVENTION);
 }
This page took 0.041127 seconds and 4 git commands to generate.