Fix prologue analysis for moxie.
[deliverable/binutils-gdb.git] / gdb / value.c
index 7b95c42973b52651d7f98513e9402152dda1c82f..fffc183af07564884b291c4fb02aefc1f6c72ad3 100644 (file)
@@ -20,6 +20,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include "arch-utils.h"
 #include "gdb_string.h"
 #include "symtab.h"
 #include "gdbtypes.h"
@@ -1162,7 +1163,7 @@ set_internalvar_component (struct internalvar *var, int offset, int bitpos,
       addr = value_contents_writeable (var->u.value);
 
       if (bitsize)
-       modify_field (addr + offset,
+       modify_field (value_type (var->u.value), addr + offset,
                      value_as_long (newval), bitpos, bitsize);
       else
        memcpy (addr + offset, value_contents (newval),
@@ -1325,7 +1326,9 @@ value_internal_function_name (struct value *val)
 }
 
 struct value *
-call_internal_function (struct value *func, int argc, struct value **argv)
+call_internal_function (struct gdbarch *gdbarch,
+                       const struct language_defn *language,
+                       struct value *func, int argc, struct value **argv)
 {
   struct internal_function *ifn;
   int result;
@@ -1334,7 +1337,7 @@ call_internal_function (struct value *func, int argc, struct value **argv)
   result = get_internalvar_function (VALUE_INTERNALVAR (func), &ifn);
   gdb_assert (result);
 
-  return (*ifn->handler) (ifn->cookie, argc, argv);
+  return (*ifn->handler) (gdbarch, language, ifn->cookie, argc, argv);
 }
 
 /* The 'function' command.  This does nothing -- it is just a
@@ -1448,7 +1451,7 @@ preserve_values (struct objfile *objfile)
 static void
 show_convenience (char *ignore, int from_tty)
 {
-  struct gdbarch *gdbarch = current_gdbarch;
+  struct gdbarch *gdbarch = get_current_arch ();
   struct internalvar *var;
   int varseen = 0;
   struct value_print_options opts;
@@ -1505,13 +1508,15 @@ value_as_double (struct value *val)
 CORE_ADDR
 value_as_address (struct value *val)
 {
+  struct gdbarch *gdbarch = get_type_arch (value_type (val));
+
   /* Assume a CORE_ADDR can fit in a LONGEST (for now).  Not sure
      whether we want this to be true eventually.  */
 #if 0
   /* gdbarch_addr_bits_remove is wrong if we are being called for a
      non-address (e.g. argument to "signal", "info break", etc.), or
      for pointers to char, in which the low bits *are* significant.  */
-  return gdbarch_addr_bits_remove (current_gdbarch, value_as_long (val));
+  return gdbarch_addr_bits_remove (gdbarch, value_as_long (val));
 #else
 
   /* There are several targets (IA-64, PowerPC, and others) which
@@ -1596,8 +1601,8 @@ value_as_address (struct value *val)
 
   if (TYPE_CODE (value_type (val)) != TYPE_CODE_PTR
       && TYPE_CODE (value_type (val)) != TYPE_CODE_REF
-      && gdbarch_integer_to_address_p (current_gdbarch))
-    return gdbarch_integer_to_address (current_gdbarch, value_type (val),
+      && gdbarch_integer_to_address_p (gdbarch))
+    return gdbarch_integer_to_address (gdbarch, value_type (val),
                                       value_contents (val));
 
   return unpack_long (value_type (val), value_contents (val));
@@ -1621,6 +1626,7 @@ value_as_address (struct value *val)
 LONGEST
 unpack_long (struct type *type, const gdb_byte *valaddr)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
   enum type_code code = TYPE_CODE (type);
   int len = TYPE_LENGTH (type);
   int nosign = TYPE_UNSIGNED (type);
@@ -1637,9 +1643,9 @@ unpack_long (struct type *type, const gdb_byte *valaddr)
     case TYPE_CODE_RANGE:
     case TYPE_CODE_MEMBERPTR:
       if (nosign)
-       return extract_unsigned_integer (valaddr, len);
+       return extract_unsigned_integer (valaddr, len, byte_order);
       else
-       return extract_signed_integer (valaddr, len);
+       return extract_signed_integer (valaddr, len, byte_order);
 
     case TYPE_CODE_FLT:
       return extract_typed_floating (valaddr, type);
@@ -1647,7 +1653,7 @@ unpack_long (struct type *type, const gdb_byte *valaddr)
     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);
+      return decimal_to_doublest (valaddr, len, byte_order);
 
     case TYPE_CODE_PTR:
     case TYPE_CODE_REF:
@@ -1670,6 +1676,7 @@ unpack_long (struct type *type, const gdb_byte *valaddr)
 DOUBLEST
 unpack_double (struct type *type, const gdb_byte *valaddr, int *invp)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
   enum type_code code;
   int len;
   int nosign;
@@ -1707,7 +1714,7 @@ 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);
+    return decimal_to_doublest (valaddr, len, byte_order);
   else if (nosign)
     {
       /* Unsigned -- be sure we compensate for signed LONGEST.  */
@@ -1975,6 +1982,7 @@ value_fn_field (struct value **arg1p, struct fn_field *f, int j, struct type *ty
 LONGEST
 unpack_field_as_long (struct type *type, const gdb_byte *valaddr, int fieldno)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
   ULONGEST val;
   ULONGEST valmask;
   int bitpos = TYPE_FIELD_BITPOS (type, fieldno);
@@ -1982,13 +1990,14 @@ unpack_field_as_long (struct type *type, const gdb_byte *valaddr, int fieldno)
   int lsbcount;
   struct type *field_type;
 
-  val = extract_unsigned_integer (valaddr + bitpos / 8, sizeof (val));
+  val = extract_unsigned_integer (valaddr + bitpos / 8,
+                                 sizeof (val), byte_order);
   field_type = TYPE_FIELD_TYPE (type, fieldno);
   CHECK_TYPEDEF (field_type);
 
   /* Extract bits.  See comment above. */
 
-  if (gdbarch_bits_big_endian (current_gdbarch))
+  if (gdbarch_bits_big_endian (get_type_arch (type)))
     lsbcount = (sizeof val * 8 - bitpos % 8 - bitsize);
   else
     lsbcount = (bitpos % 8);
@@ -2020,8 +2029,10 @@ unpack_field_as_long (struct type *type, const gdb_byte *valaddr, int fieldno)
    0 <= BITPOS, where lbits is the size of a LONGEST in bits.  */
 
 void
-modify_field (gdb_byte *addr, LONGEST fieldval, int bitpos, int bitsize)
+modify_field (struct type *type, gdb_byte *addr,
+             LONGEST fieldval, int bitpos, int bitsize)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
   ULONGEST oword;
   ULONGEST mask = (ULONGEST) -1 >> (8 * sizeof (ULONGEST) - bitsize);
 
@@ -2041,16 +2052,16 @@ modify_field (gdb_byte *addr, LONGEST fieldval, int bitpos, int bitsize)
       fieldval &= mask;
     }
 
-  oword = extract_unsigned_integer (addr, sizeof oword);
+  oword = extract_unsigned_integer (addr, sizeof oword, byte_order);
 
   /* Shifting for bit field depends on endianness of the target machine.  */
-  if (gdbarch_bits_big_endian (current_gdbarch))
+  if (gdbarch_bits_big_endian (get_type_arch (type)))
     bitpos = sizeof (oword) * 8 - bitpos - bitsize;
 
   oword &= ~(mask << bitpos);
   oword |= fieldval << bitpos;
 
-  store_unsigned_integer (addr, sizeof oword, oword);
+  store_unsigned_integer (addr, sizeof oword, byte_order, oword);
 }
 \f
 /* Pack NUM into BUF using a target format of TYPE.  */
@@ -2058,6 +2069,7 @@ modify_field (gdb_byte *addr, LONGEST fieldval, int bitpos, int bitsize)
 void
 pack_long (gdb_byte *buf, struct type *type, LONGEST num)
 {
+  enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
   int len;
 
   type = check_typedef (type);
@@ -2072,7 +2084,7 @@ pack_long (gdb_byte *buf, struct type *type, LONGEST num)
     case TYPE_CODE_BOOL:
     case TYPE_CODE_RANGE:
     case TYPE_CODE_MEMBERPTR:
-      store_signed_integer (buf, len, num);
+      store_signed_integer (buf, len, byte_order, num);
       break;
 
     case TYPE_CODE_REF:
This page took 0.0415 seconds and 4 git commands to generate.