return value_from_double (type, value_as_double (arg2));
else if (code1 == TYPE_CODE_DECFLOAT && scalar)
{
+ enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
int dec_len = TYPE_LENGTH (type);
gdb_byte dec[16];
if (code2 == TYPE_CODE_FLT)
- decimal_from_floating (arg2, dec, dec_len);
+ decimal_from_floating (arg2, dec, dec_len, byte_order);
else if (code2 == TYPE_CODE_DECFLOAT)
decimal_convert (value_contents (arg2), TYPE_LENGTH (type2),
- dec, dec_len);
+ byte_order, dec, dec_len, byte_order);
else
/* The only option left is an integral type. */
- decimal_from_integral (arg2, dec, dec_len);
+ decimal_from_integral (arg2, dec, dec_len, byte_order);
return value_from_decfloat (type, dec);
}
sees a cast as a simple reinterpretation of the pointer's
bits. */
if (code2 == TYPE_CODE_PTR)
- longest = extract_unsigned_integer (value_contents (arg2),
- TYPE_LENGTH (type2));
+ longest = extract_unsigned_integer
+ (value_contents (arg2), TYPE_LENGTH (type2),
+ gdbarch_byte_order (get_type_arch (type2)));
else
longest = value_as_long (arg2);
return value_from_longest (type, convert_to_boolean ?
otherwise occur when dealing with a target having two byte
pointers and four byte addresses. */
- int addr_bit = gdbarch_addr_bit (current_gdbarch);
+ int addr_bit = gdbarch_addr_bit (get_type_arch (type2));
LONGEST longest = value_as_long (arg2);
if (addr_bit < sizeof (LONGEST) * HOST_CHAR_BIT)
return value_at_lazy (type, value_address (arg2));
else if (code1 == TYPE_CODE_VOID)
{
- return value_zero (builtin_type_void, not_lval);
+ return value_zero (type, not_lval);
}
else
{
value_one (struct type *type, enum lval_type lv)
{
struct type *type1 = check_typedef (type);
- struct value *val = NULL; /* avoid -Wall warning */
+ struct value *val;
if (TYPE_CODE (type1) == TYPE_CODE_DECFLOAT)
{
- struct value *int_one = value_from_longest (builtin_type_int32, 1);
- struct value *val;
+ enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
gdb_byte v[16];
-
- decimal_from_integral (int_one, v, TYPE_LENGTH (builtin_type_int32));
+ decimal_from_string (v, TYPE_LENGTH (type), byte_order, "1");
val = value_from_decfloat (type, v);
}
else if (TYPE_CODE (type1) == TYPE_CODE_FLT)
return val;
}
+/* Helper function for value_at, value_at_lazy, and value_at_lazy_stack. */
+
+static struct value *
+get_value_at (struct type *type, CORE_ADDR addr, int lazy)
+{
+ struct value *val;
+
+ if (TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
+ error (_("Attempt to dereference a generic pointer."));
+
+ if (lazy)
+ {
+ val = allocate_value_lazy (type);
+ }
+ else
+ {
+ val = allocate_value (type);
+ read_memory (addr, value_contents_all_raw (val), TYPE_LENGTH (type));
+ }
+
+ VALUE_LVAL (val) = lval_memory;
+ set_value_address (val, addr);
+
+ return val;
+}
+
/* Return a value with type TYPE located at ADDR.
Call value_at only if the data needs to be fetched immediately;
struct value *
value_at (struct type *type, CORE_ADDR addr)
{
- struct value *val;
-
- if (TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
- error (_("Attempt to dereference a generic pointer."));
-
- val = allocate_value (type);
-
- read_memory (addr, value_contents_all_raw (val), TYPE_LENGTH (type));
-
- VALUE_LVAL (val) = lval_memory;
- set_value_address (val, addr);
-
- return val;
+ return get_value_at (type, addr, 0);
}
/* Return a lazy value with type TYPE located at ADDR (cf. value_at). */
struct value *
value_at_lazy (struct type *type, CORE_ADDR addr)
{
- struct value *val;
-
- if (TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
- error (_("Attempt to dereference a generic pointer."));
-
- val = allocate_value_lazy (type);
-
- VALUE_LVAL (val) = lval_memory;
- set_value_address (val, addr);
-
- return val;
+ return get_value_at (type, addr, 1);
}
/* Called only from the value_contents and value_contents_all()
{
gdb_assert (value_lazy (val));
allocate_value_contents (val);
- if (VALUE_LVAL (val) == lval_memory)
+ if (value_bitsize (val))
+ {
+ /* To read a lazy bitfield, read the entire enclosing value. This
+ prevents reading the same block of (possibly volatile) memory once
+ per bitfield. It would be even better to read only the containing
+ word, but we have no way to record that just specific bits of a
+ value have been fetched. */
+ struct type *type = check_typedef (value_type (val));
+ enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
+ struct value *parent = value_parent (val);
+ LONGEST offset = value_offset (val);
+ LONGEST num = unpack_bits_as_long (value_type (val),
+ value_contents (parent) + offset,
+ value_bitpos (val),
+ value_bitsize (val));
+ int length = TYPE_LENGTH (type);
+ store_signed_integer (value_contents_raw (val), length, byte_order, num);
+ }
+ else if (VALUE_LVAL (val) == lval_memory)
{
CORE_ADDR addr = value_address (val);
int length = TYPE_LENGTH (check_typedef (value_enclosing_type (val)));
if (length)
- read_memory (addr, value_contents_all_raw (val), length);
+ {
+ if (value_stack (val))
+ read_stack (addr, value_contents_all_raw (val), length);
+ else
+ read_memory (addr, value_contents_all_raw (val), length);
+ }
}
else if (VALUE_LVAL (val) == lval_register)
{
fprintf_unfiltered (gdb_stdlog, " register=%d",
VALUE_REGNUM (new_val));
else if (VALUE_LVAL (new_val) == lval_memory)
- fprintf_unfiltered (gdb_stdlog, " address=0x%s",
- paddr_nz (value_address (new_val)));
+ fprintf_unfiltered (gdb_stdlog, " address=%s",
+ paddress (gdbarch,
+ value_address (new_val)));
else
fprintf_unfiltered (gdb_stdlog, " computed");
if (value_bitsize (toval))
{
- /* We assume that the argument to read_memory is in units
- of host chars. FIXME: Is that correct? */
changed_len = (value_bitpos (toval)
+ value_bitsize (toval)
+ HOST_CHAR_BIT - 1)
/ HOST_CHAR_BIT;
+ /* If we can read-modify-write exactly the size of the
+ containing type (e.g. short or int) then do so. This
+ is safer for volatile bitfields mapped to hardware
+ registers. */
+ if (changed_len < TYPE_LENGTH (type)
+ && TYPE_LENGTH (type) <= (int) sizeof (LONGEST)
+ && ((LONGEST) value_address (toval) % TYPE_LENGTH (type)) == 0)
+ changed_len = TYPE_LENGTH (type);
+
if (changed_len > (int) sizeof (LONGEST))
error (_("Can't handle bitfields which don't fit in a %d bit word."),
(int) sizeof (LONGEST) * HOST_CHAR_BIT);
read_memory (value_address (toval), buffer, changed_len);
- modify_field (buffer, value_as_long (fromval),
+ modify_field (type, buffer, value_as_long (fromval),
value_bitpos (toval), value_bitsize (toval));
changed_addr = value_address (toval);
dest_buffer = buffer;
case lval_register:
{
struct frame_info *frame;
+ struct gdbarch *gdbarch;
int value_reg;
/* Figure out which frame this is in currently. */
if (!frame)
error (_("Value being assigned to is no longer active."));
-
- if (gdbarch_convert_register_p
- (current_gdbarch, VALUE_REGNUM (toval), type))
+
+ gdbarch = get_frame_arch (frame);
+ if (gdbarch_convert_register_p (gdbarch, VALUE_REGNUM (toval), type))
{
/* If TOVAL is a special machine register requiring
conversion of program values to a special raw
format. */
- gdbarch_value_to_register (current_gdbarch, frame,
+ gdbarch_value_to_register (gdbarch, frame,
VALUE_REGNUM (toval), type,
value_contents (fromval));
}
value_offset (toval),
changed_len, buffer);
- modify_field (buffer, value_as_long (fromval),
- value_bitpos (toval),
- value_bitsize (toval));
+ modify_field (type, buffer, value_as_long (fromval),
+ value_bitpos (toval), value_bitsize (toval));
put_frame_register_bytes (frame, value_reg,
value_offset (toval),
frame = block_innermost_frame (b);
if (!frame)
{
- if (BLOCK_FUNCTION (b)
+ if (BLOCK_FUNCTION (b) && !block_inlined_p (b)
&& SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)))
error (_("No frame is currently executing in block %s."),
SYMBOL_PRINT_NAME (BLOCK_FUNCTION (b)));
int idx;
unsigned int typelength;
struct value *val;
- struct type *rangetype;
struct type *arraytype;
CORE_ADDR addr;
}
}
- rangetype = create_range_type ((struct type *) NULL,
- builtin_type_int32,
- lowbound, highbound);
- arraytype = create_array_type ((struct type *) NULL,
- value_enclosing_type (elemvec[0]),
- rangetype);
+ arraytype = lookup_array_range_type (value_enclosing_type (elemvec[0]),
+ lowbound, highbound);
if (!current_language->c_style_arrays)
{
}
struct value *
-value_typed_string (char *ptr, int len, struct type *char_type)
+value_cstring (char *ptr, int len, struct type *char_type)
{
struct value *val;
int lowbound = current_language->string_lower_bound;
int highbound = len / TYPE_LENGTH (char_type);
- struct type *rangetype = create_range_type ((struct type *) NULL,
- builtin_type_int32,
- lowbound,
- highbound + lowbound - 1);
struct type *stringtype
- = create_array_type ((struct type *) NULL, char_type, rangetype);
+ = lookup_array_range_type (char_type, lowbound, highbound + lowbound - 1);
val = allocate_value (stringtype);
memcpy (value_contents_raw (val), ptr, len);
string may contain embedded null bytes. */
struct value *
-value_string (char *ptr, int len)
+value_string (char *ptr, int len, struct type *char_type)
{
struct value *val;
int lowbound = current_language->string_lower_bound;
- struct type *rangetype = create_range_type ((struct type *) NULL,
- builtin_type_int32,
- lowbound,
- len + lowbound - 1);
+ int highbound = len / TYPE_LENGTH (char_type);
struct type *stringtype
- = create_string_type ((struct type *) NULL, rangetype);
- CORE_ADDR addr;
+ = lookup_string_range_type (char_type, lowbound, highbound + lowbound - 1);
- if (current_language->c_style_arrays == 0)
- {
- val = allocate_value (stringtype);
- memcpy (value_contents_raw (val), ptr, len);
- return val;
- }
-
-
- /* Allocate space to store the string in the inferior, and then copy
- LEN bytes from PTR in gdb to that address in the inferior. */
-
- addr = allocate_space_in_inferior (len);
- write_memory (addr, (gdb_byte *) ptr, len);
-
- val = value_at_lazy (stringtype, addr);
- return (val);
+ val = allocate_value (stringtype);
+ memcpy (value_contents_raw (val), ptr, len);
+ return val;
}
struct value *
-value_bitstring (char *ptr, int len)
+value_bitstring (char *ptr, int len, struct type *index_type)
{
struct value *val;
- struct type *domain_type = create_range_type (NULL,
- builtin_type_int32,
- 0, len - 1);
- struct type *type = create_set_type ((struct type *) NULL,
- domain_type);
+ struct type *domain_type
+ = create_range_type (NULL, index_type, 0, len - 1);
+ struct type *type = create_set_type (NULL, domain_type);
TYPE_CODE (type) = TYPE_CODE_BITSTRING;
val = allocate_value (type);
memcpy (value_contents_raw (val), ptr, TYPE_LENGTH (type));
else if (element > 0)
{
int j = i % TARGET_CHAR_BIT;
- if (gdbarch_bits_big_endian (current_gdbarch))
+ if (gdbarch_bits_big_endian (get_type_arch (array_type)))
j = TARGET_CHAR_BIT - 1 - j;
value_contents_raw (slice)[i / TARGET_CHAR_BIT] |= (1 << j);
}