X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fvalue.c;h=9a144fb7fb62439b52a4ec5ebd25c81c050b5957;hb=ba18742c3a1b62ff218db99bee47bb932af6dab9;hp=35fb50351a6e9aa725227cbf715c7038c9946b62;hpb=870f88f7551b0f2d6aaaa36fb684b5ff8f468107;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/value.c b/gdb/value.c index 35fb50351a..9a144fb7fb 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1,6 +1,6 @@ /* Low level packing and unpacking of values for GDB, the GNU Debugger. - Copyright (C) 1986-2016 Free Software Foundation, Inc. + Copyright (C) 1986-2018 Free Software Foundation, Inc. This file is part of GDB. @@ -28,10 +28,9 @@ #include "target.h" #include "language.h" #include "demangle.h" -#include "doublest.h" #include "regcache.h" #include "block.h" -#include "dfp.h" +#include "target-float.h" #include "objfiles.h" #include "valprint.h" #include "cli/cli-decode.h" @@ -40,10 +39,8 @@ #include "tracepoint.h" #include "cp-abi.h" #include "user-regs.h" - -/* Prototypes for exported functions. */ - -void _initialize_values (void); +#include +#include "completer.h" /* Definition of a user function. */ struct internal_function @@ -65,10 +62,10 @@ struct internal_function struct range { /* Lowest offset in the range. */ - int offset; + LONGEST offset; /* Length of the range. */ - int length; + LONGEST length; }; typedef struct range range_s; @@ -79,13 +76,13 @@ DEF_VEC_O(range_s); [offset2, offset2+len2) overlap. */ static int -ranges_overlap (int offset1, int len1, - int offset2, int len2) +ranges_overlap (LONGEST offset1, LONGEST len1, + LONGEST offset2, LONGEST len2) { ULONGEST h, l; - l = max (offset1, offset2); - h = min (offset1 + len1, offset2 + len2); + l = std::max (offset1, offset2); + h = std::min (offset1 + len1, offset2 + len2); return (l < h); } @@ -104,10 +101,10 @@ range_lessthan (const range_s *r1, const range_s *r2) OFFSET+LENGTH). */ static int -ranges_contain (VEC(range_s) *ranges, int offset, int length) +ranges_contain (VEC(range_s) *ranges, LONGEST offset, LONGEST length) { range_s what; - int i; + LONGEST i; what.offset = offset; what.length = length; @@ -204,17 +201,23 @@ struct value /* If the value has been released. */ unsigned int released : 1; - /* Register number if the value is from a register. */ - short regnum; - /* Location of value (if lval). */ union { - /* If lval == lval_memory, this is the address in the inferior. - If lval == lval_register, this is the byte offset into the - registers structure. */ + /* If lval == lval_memory, this is the address in the inferior */ CORE_ADDR address; + /*If lval == lval_register, the value is from a register. */ + struct + { + /* Register number. */ + int regnum; + /* Frame ID of "next" frame to which a register value is relative. + If the register value is found relative to frame F, then the + frame id of F->next will be stored in next_frame_id. */ + struct frame_id next_frame_id; + } reg; + /* Pointer to internal variable. */ struct internalvar *internalvar; @@ -235,19 +238,17 @@ struct value } location; /* Describes offset of a value within lval of a structure in target - addressable memory units. If lval == lval_memory, this is an offset to - the address. If lval == lval_register, this is a further offset from - location.address within the registers structure. Note also the member - embedded_offset below. */ - int offset; + addressable memory units. Note also the member embedded_offset + below. */ + LONGEST offset; /* Only used for bitfields; number of bits contained in them. */ - int bitsize; + LONGEST bitsize; /* Only used for bitfields; position of start of field. For 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; + LONGEST bitpos; /* The number of references to this value. When a value is created, the value chain holds a reference, so REFERENCE_COUNT is 1. If @@ -261,10 +262,6 @@ struct value bitfields. */ struct value *parent; - /* Frame register value is relative to. This will be described in - the lval enum above as "lval_register". */ - struct frame_id frame_id; - /* Type of the value. */ struct type *type; @@ -309,8 +306,8 @@ struct value `type', and `embedded_offset' is zero, so everything works normally. */ struct type *enclosing_type; - int embedded_offset; - int pointed_to_offset; + LONGEST embedded_offset; + LONGEST pointed_to_offset; /* Values are stored in a chain, so that they can be deleted easily over calls to the inferior. Values assigned to internal @@ -349,7 +346,7 @@ get_value_arch (const struct value *value) } int -value_bits_available (const struct value *value, int offset, int length) +value_bits_available (const struct value *value, LONGEST offset, LONGEST length) { gdb_assert (!value->lazy); @@ -357,7 +354,8 @@ value_bits_available (const struct value *value, int offset, int length) } int -value_bytes_available (const struct value *value, int offset, int length) +value_bytes_available (const struct value *value, + LONGEST offset, LONGEST length) { return value_bits_available (value, offset * TARGET_CHAR_BIT, @@ -427,7 +425,8 @@ value_entirely_optimized_out (struct value *value) OFFSET bits, and extending for the next LENGTH bits. */ static void -insert_into_bit_range_vector (VEC(range_s) **vectorp, int offset, int length) +insert_into_bit_range_vector (VEC(range_s) **vectorp, + LONGEST offset, LONGEST length) { range_s newr; int i; @@ -526,8 +525,8 @@ insert_into_bit_range_vector (VEC(range_s) **vectorp, int offset, int length) if (ranges_overlap (bef->offset, bef->length, offset, length)) { /* #1 */ - ULONGEST l = min (bef->offset, offset); - ULONGEST h = max (bef->offset + bef->length, offset + length); + ULONGEST l = std::min (bef->offset, offset); + ULONGEST h = std::max (bef->offset + bef->length, offset + length); bef->offset = l; bef->length = h - l; @@ -570,8 +569,8 @@ insert_into_bit_range_vector (VEC(range_s) **vectorp, int offset, int length) { ULONGEST l, h; - l = min (t->offset, r->offset); - h = max (t->offset + t->length, r->offset + r->length); + l = std::min (t->offset, r->offset); + h = std::max (t->offset + t->length, r->offset + r->length); t->offset = l; t->length = h - l; @@ -592,13 +591,15 @@ insert_into_bit_range_vector (VEC(range_s) **vectorp, int offset, int length) } void -mark_value_bits_unavailable (struct value *value, int offset, int length) +mark_value_bits_unavailable (struct value *value, + LONGEST offset, LONGEST length) { insert_into_bit_range_vector (&value->unavailable, offset, length); } void -mark_value_bytes_unavailable (struct value *value, int offset, int length) +mark_value_bytes_unavailable (struct value *value, + LONGEST offset, LONGEST length) { mark_value_bits_unavailable (value, offset * TARGET_CHAR_BIT, @@ -612,7 +613,7 @@ mark_value_bytes_unavailable (struct value *value, int offset, int length) static int find_first_range_overlap (VEC(range_s) *ranges, int pos, - int offset, int length) + LONGEST offset, LONGEST length) { range_s *r; int i; @@ -748,8 +749,8 @@ struct ranges_and_idx static int find_first_range_overlap_and_match (struct ranges_and_idx *rp1, struct ranges_and_idx *rp2, - int offset1, int offset2, - int length, ULONGEST *l, ULONGEST *h) + LONGEST offset1, LONGEST offset2, + LONGEST length, ULONGEST *l, ULONGEST *h) { rp1->idx = find_first_range_overlap (rp1->ranges, rp1->idx, offset1, length); @@ -776,11 +777,11 @@ find_first_range_overlap_and_match (struct ranges_and_idx *rp1, /* Get the unavailable windows intersected by the incoming ranges. The first and last ranges that overlap the argument range may be wider than said incoming arguments ranges. */ - l1 = max (offset1, r1->offset); - h1 = min (offset1 + length, r1->offset + r1->length); + l1 = std::max (offset1, r1->offset); + h1 = std::min (offset1 + length, r1->offset + r1->length); - l2 = max (offset2, r2->offset); - h2 = min (offset2 + length, offset2 + r2->length); + l2 = std::max (offset2, r2->offset); + h2 = std::min (offset2 + length, offset2 + r2->length); /* Make them relative to the respective start offsets, so we can compare them for equality. */ @@ -807,7 +808,7 @@ find_first_range_overlap_and_match (struct ranges_and_idx *rp1, with LENGTH bits of VAL2's contents starting at OFFSET2 bits. Return true if the available bits match. */ -static int +static bool value_contents_bits_eq (const struct value *val1, int offset1, const struct value *val2, int offset2, int length) @@ -846,7 +847,7 @@ value_contents_bits_eq (const struct value *val1, int offset1, if (!find_first_range_overlap_and_match (&rp1[i], &rp2[i], offset1, offset2, length, &l_tmp, &h_tmp)) - return 0; + return false; /* We're interested in the lowest/first range found. */ if (i == 0 || l_tmp < l) @@ -859,32 +860,26 @@ value_contents_bits_eq (const struct value *val1, int offset1, /* Compare the available/valid contents. */ if (memcmp_with_bit_offsets (val1->contents, offset1, val2->contents, offset2, l) != 0) - return 0; + return false; length -= h; offset1 += h; offset2 += h; } - return 1; + return true; } -int -value_contents_eq (const struct value *val1, int offset1, - const struct value *val2, int offset2, - int length) +bool +value_contents_eq (const struct value *val1, LONGEST offset1, + const struct value *val2, LONGEST offset2, + LONGEST length) { return value_contents_bits_eq (val1, offset1 * TARGET_CHAR_BIT, val2, offset2 * TARGET_CHAR_BIT, length * TARGET_CHAR_BIT); } -/* Prototypes for local functions. */ - -static void show_values (char *, int); - -static void show_convenience (char *, int); - /* The value-history records all the values printed by print commands during this session. Each chunk @@ -938,11 +933,9 @@ allocate_value_lazy (struct type *type) val->enclosing_type = type; VALUE_LVAL (val) = not_lval; val->location.address = 0; - VALUE_FRAME_ID (val) = null_frame_id; val->offset = 0; val->bitpos = 0; val->bitsize = 0; - VALUE_REGNUM (val) = -1; val->lazy = 1; val->embedded_offset = 0; val->pointed_to_offset = 0; @@ -976,7 +969,7 @@ gdb_static_assert (sizeof (LONGEST) <= MIN_VALUE_FOR_MAX_VALUE_SIZE); /* Implement the "set max-value-size" command. */ static void -set_max_value_size (char *args, int from_tty, +set_max_value_size (const char *args, int from_tty, struct cmd_list_element *c) { gdb_assert (max_value_size == -1 || max_value_size >= 0); @@ -1109,35 +1102,35 @@ deprecated_set_value_type (struct value *value, struct type *type) value->type = type; } -int +LONGEST value_offset (const struct value *value) { return value->offset; } void -set_value_offset (struct value *value, int offset) +set_value_offset (struct value *value, LONGEST offset) { value->offset = offset; } -int +LONGEST value_bitpos (const struct value *value) { return value->bitpos; } void -set_value_bitpos (struct value *value, int bit) +set_value_bitpos (struct value *value, LONGEST bit) { value->bitpos = bit; } -int +LONGEST value_bitsize (const struct value *value) { return value->bitsize; } void -set_value_bitsize (struct value *value, int bit) +set_value_bitsize (struct value *value, LONGEST bit) { value->bitsize = bit; } @@ -1202,8 +1195,7 @@ value_actual_type (struct value *value, int resolve_simple_types, { /* If result's target type is TYPE_CODE_STRUCT, proceed to fetch its rtti type. */ - if ((TYPE_CODE (result) == TYPE_CODE_PTR - || TYPE_CODE (result) == TYPE_CODE_REF) + if ((TYPE_CODE (result) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (result)) && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result))) == TYPE_CODE_STRUCT && !value_optimized_out (value)) @@ -1293,8 +1285,9 @@ ranges_copy_adjusted (VEC (range_s) **dst_range, int dst_bit_offset, { ULONGEST h, l; - l = max (r->offset, src_bit_offset); - h = min (r->offset + r->length, src_bit_offset + bit_length); + l = std::max (r->offset, (LONGEST) src_bit_offset); + h = std::min (r->offset + r->length, + (LONGEST) src_bit_offset + bit_length); if (l < h) insert_into_bit_range_vector (dst_range, @@ -1330,10 +1323,10 @@ value_ranges_copy_adjusted (struct value *dst, int dst_bit_offset, DST_OFFSET+LENGTH) range are wholly available. */ void -value_contents_copy_raw (struct value *dst, int dst_offset, - struct value *src, int src_offset, int length) +value_contents_copy_raw (struct value *dst, LONGEST dst_offset, + struct value *src, LONGEST src_offset, LONGEST length) { - int src_bit_offset, dst_bit_offset, bit_length; + LONGEST src_bit_offset, dst_bit_offset, bit_length; struct gdbarch *arch = get_value_arch (src); int unit_size = gdbarch_addressable_memory_unit_size (arch); @@ -1377,8 +1370,8 @@ value_contents_copy_raw (struct value *dst, int dst_offset, DST_OFFSET+LENGTH) range are wholly available. */ void -value_contents_copy (struct value *dst, int dst_offset, - struct value *src, int src_offset, int length) +value_contents_copy (struct value *dst, LONGEST dst_offset, + struct value *src, LONGEST src_offset, LONGEST length) { if (src->lazy) value_fetch_lazy (src); @@ -1462,14 +1455,15 @@ mark_value_bytes_optimized_out (struct value *value, int offset, int length) /* See value.h. */ void -mark_value_bits_optimized_out (struct value *value, int offset, int length) +mark_value_bits_optimized_out (struct value *value, + LONGEST offset, LONGEST length) { insert_into_bit_range_vector (&value->optimized_out, offset, length); } int value_bits_synthetic_pointer (const struct value *value, - int offset, int length) + LONGEST offset, LONGEST length) { if (value->lval != lval_computed || !value->location.computed.funcs->check_synthetic_pointer) @@ -1479,26 +1473,26 @@ value_bits_synthetic_pointer (const struct value *value, length); } -int +LONGEST value_embedded_offset (const struct value *value) { return value->embedded_offset; } void -set_value_embedded_offset (struct value *value, int val) +set_value_embedded_offset (struct value *value, LONGEST val) { value->embedded_offset = val; } -int +LONGEST value_pointed_to_offset (const struct value *value) { return value->pointed_to_offset; } void -set_value_pointed_to_offset (struct value *value, int val) +set_value_pointed_to_offset (struct value *value, LONGEST val) { value->pointed_to_offset = val; } @@ -1534,9 +1528,7 @@ value_lval_const (const struct value *value) CORE_ADDR value_address (const struct value *value) { - if (value->lval == lval_internalvar - || value->lval == lval_internalvar_component - || value->lval == lval_xcallable) + if (value->lval != lval_memory) return 0; if (value->parent != NULL) return value_address (value->parent) + value->offset; @@ -1552,9 +1544,7 @@ value_address (const struct value *value) CORE_ADDR value_raw_address (const struct value *value) { - if (value->lval == lval_internalvar - || value->lval == lval_internalvar_component - || value->lval == lval_xcallable) + if (value->lval != lval_memory) return 0; return value->location.address; } @@ -1562,9 +1552,7 @@ value_raw_address (const struct value *value) void set_value_address (struct value *value, CORE_ADDR addr) { - gdb_assert (value->lval != lval_internalvar - && value->lval != lval_internalvar_component - && value->lval != lval_xcallable); + gdb_assert (value->lval == lval_memory); value->location.address = addr; } @@ -1575,15 +1563,17 @@ deprecated_value_internalvar_hack (struct value *value) } struct frame_id * -deprecated_value_frame_id_hack (struct value *value) +deprecated_value_next_frame_id_hack (struct value *value) { - return &value->frame_id; + gdb_assert (value->lval == lval_register); + return &value->location.reg.next_frame_id; } -short * +int * deprecated_value_regnum_hack (struct value *value) { - return &value->regnum; + gdb_assert (value->lval == lval_register); + return &value->location.reg.regnum; } int @@ -1637,7 +1627,7 @@ value_free (struct value *val) funcs->free_closure (val); } else if (VALUE_LVAL (val) == lval_xcallable) - free_xmethod_worker (val->location.xm_worker); + delete val->location.xm_worker; xfree (val->contents); VEC_free (range_s, val->unavailable); @@ -1779,8 +1769,6 @@ value_copy (struct value *arg) val->offset = arg->offset; val->bitpos = arg->bitpos; val->bitsize = arg->bitsize; - VALUE_FRAME_ID (val) = VALUE_FRAME_ID (arg); - VALUE_REGNUM (val) = VALUE_REGNUM (arg); val->lazy = arg->lazy; val->embedded_offset = value_embedded_offset (arg); val->pointed_to_offset = arg->pointed_to_offset; @@ -1971,7 +1959,7 @@ access_value_history (int num) } static void -show_values (char *num_exp, int from_tty) +show_values (const char *num_exp, int from_tty) { int i; struct value *val; @@ -2011,10 +1999,7 @@ show_values (char *num_exp, int from_tty) "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] = '+'; - num_exp[1] = '\0'; - } + set_repeat_arguments ("+"); } enum internalvar_kind @@ -2101,14 +2086,12 @@ static struct internalvar *internalvars; /* If the variable does not already exist create it and give it the value given. If no value is given then the default is zero. */ static void -init_if_undefined_command (char* args, int from_tty) +init_if_undefined_command (const char* args, int from_tty) { struct internalvar* intvar; /* Parse the expression - this is taken from set_command(). */ - struct expression *expr = parse_expression (args); - register struct cleanup *old_chain = - make_cleanup (free_current_contents, &expr); + expression_up expr = parse_expression (args); /* Validate the expression. Was the expression an assignment? @@ -2126,9 +2109,7 @@ init_if_undefined_command (char* args, int from_tty) /* Only evaluate the expression if the lvalue is void. This may still fail if the expresssion is invalid. */ if (intvar->kind == INTERNALVAR_VOID) - evaluate_expression (expr); - - do_cleanups (old_chain); + evaluate_expression (expr.get ()); } @@ -2150,14 +2131,12 @@ lookup_only_internalvar (const char *name) return NULL; } -/* Complete NAME by comparing it to the names of internal variables. - Returns a vector of newly allocated strings, or NULL if no matches - were found. */ +/* Complete NAME by comparing it to the names of internal + variables. */ -VEC (char_ptr) * -complete_internalvar (const char *name) +void +complete_internalvar (completion_tracker &tracker, const char *name) { - VEC (char_ptr) *result = NULL; struct internalvar *var; int len; @@ -2166,12 +2145,10 @@ complete_internalvar (const char *name) for (var = internalvars; var; var = var->next) if (strncmp (var->name, name, len) == 0) { - char *r = xstrdup (var->name); + gdb::unique_xmalloc_ptr copy (xstrdup (var->name)); - VEC_safe_push (char_ptr, result, r); + tracker.add_completion (std::move (copy)); } - - return result; } /* Create an internal variable with name NAME and with a void value. @@ -2371,8 +2348,9 @@ get_internalvar_function (struct internalvar *var, } void -set_internalvar_component (struct internalvar *var, int offset, int bitpos, - int bitsize, struct value *newval) +set_internalvar_component (struct internalvar *var, + LONGEST offset, LONGEST bitpos, + LONGEST bitsize, struct value *newval) { gdb_byte *addr; struct gdbarch *arch; @@ -2571,7 +2549,7 @@ call_internal_function (struct gdbarch *gdbarch, the implementation of the sub-command that is created when registering an internal function. */ static void -function_command (char *command, int from_tty) +function_command (const char *command, int from_tty) { /* Do nothing. */ } @@ -2673,7 +2651,7 @@ preserve_values (struct objfile *objfile) } static void -show_convenience (char *ignore, int from_tty) +show_convenience (const char *ignore, int from_tty) { struct gdbarch *gdbarch = get_current_arch (); struct internalvar *var; @@ -2719,23 +2697,20 @@ show_convenience (char *ignore, int from_tty) } } -/* Return the TYPE_CODE_XMETHOD value corresponding to WORKER. */ + +/* See value.h. */ struct value * -value_of_xmethod (struct xmethod_worker *worker) +value_from_xmethod (xmethod_worker_up &&worker) { - if (worker->value == NULL) - { - struct value *v; + struct value *v; - v = allocate_value (builtin_type (target_gdbarch ())->xmethod); - v->lval = lval_xcallable; - v->location.xm_worker = worker; - v->modifiable = 0; - worker->value = v; - } + v = allocate_value (builtin_type (target_gdbarch ())->xmethod); + v->lval = lval_xcallable; + v->location.xm_worker = worker.release (); + v->modifiable = 0; - return worker->value; + return v; } /* Return the type of the result of TYPE_CODE_XMETHOD value METHOD. */ @@ -2746,8 +2721,8 @@ result_type_of_xmethod (struct value *method, int argc, struct value **argv) gdb_assert (TYPE_CODE (value_type (method)) == TYPE_CODE_XMETHOD && method->lval == lval_xcallable && argc > 0); - return get_xmethod_result_type (method->location.xm_worker, - argv[0], argv + 1, argc - 1); + return method->location.xm_worker->get_result_type + (argv[0], argv + 1, argc - 1); } /* Call the xmethod corresponding to the TYPE_CODE_XMETHOD value METHOD. */ @@ -2758,8 +2733,7 @@ call_xmethod (struct value *method, int argc, struct value **argv) gdb_assert (TYPE_CODE (value_type (method)) == TYPE_CODE_XMETHOD && method->lval == lval_xcallable && argc > 0); - return invoke_xmethod (method->location.xm_worker, - argv[0], argv + 1, argc - 1); + return method->location.xm_worker->invoke (argv[0], argv + 1, argc - 1); } /* Extract a value as a C number (either long or double). @@ -2777,18 +2751,6 @@ value_as_long (struct value *val) return unpack_long (value_type (val), value_contents (val)); } -DOUBLEST -value_as_double (struct value *val) -{ - DOUBLEST foo; - int inv; - - foo = unpack_double (value_type (val), value_contents (val), &inv); - if (inv) - 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. */ @@ -2887,7 +2849,7 @@ value_as_address (struct value *val) ABI-specific code is a more reasonable place to handle it. */ if (TYPE_CODE (value_type (val)) != TYPE_CODE_PTR - && TYPE_CODE (value_type (val)) != TYPE_CODE_REF + && !TYPE_IS_REFERENCE (value_type (val)) && gdbarch_integer_to_address_p (gdbarch)) return gdbarch_integer_to_address (gdbarch, value_type (val), value_contents (val)); @@ -2935,15 +2897,12 @@ unpack_long (struct type *type, const gdb_byte *valaddr) return extract_signed_integer (valaddr, len, byte_order); case TYPE_CODE_FLT: - return (LONGEST) 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 (LONGEST) decimal_to_doublest (valaddr, len, byte_order); + return target_float_to_longest (valaddr, type); case TYPE_CODE_PTR: case TYPE_CODE_REF: + case TYPE_CODE_RVALUE_REF: /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure whether we want this to be true eventually. */ return extract_typed_address (valaddr, type); @@ -2954,66 +2913,6 @@ unpack_long (struct type *type, const gdb_byte *valaddr) return 0; /* Placate lint. */ } -/* Return a double value from the specified type and address. - INVP points to an int which is set to 0 for valid value, - 1 for invalid value (bad float format). In either case, - the returned double is OK to use. Argument is in target - format, result is in host format. */ - -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; - - *invp = 0; /* Assume valid. */ - type = check_typedef (type); - code = TYPE_CODE (type); - len = TYPE_LENGTH (type); - nosign = TYPE_UNSIGNED (type); - if (code == TYPE_CODE_FLT) - { - /* NOTE: cagney/2002-02-19: There was a test here to see if the - floating-point value was valid (using the macro - INVALID_FLOAT). That test/macro have been removed. - - It turns out that only the VAX defined this macro and then - only in a non-portable way. Fixing the portability problem - wouldn't help since the VAX floating-point code is also badly - bit-rotten. The target needs to add definitions for the - methods gdbarch_float_format and gdbarch_double_format - these - exactly describe the target floating-point format. The - problem here is that the corresponding floatformat_vax_f and - floatformat_vax_d values these methods should be set to are - also not defined either. Oops! - - Hopefully someone will add both the missing floatformat - definitions and the new cases for floatformat_is_valid (). */ - - if (!floatformat_is_valid (floatformat_from_type (type), valaddr)) - { - *invp = 1; - return 0.0; - } - - return extract_typed_floating (valaddr, type); - } - else if (code == TYPE_CODE_DECFLOAT) - return decimal_to_doublest (valaddr, len, byte_order); - else if (nosign) - { - /* Unsigned -- be sure we compensate for signed LONGEST. */ - return (ULONGEST) unpack_long (type, valaddr); - } - else - { - /* Signed -- we are OK with unpack_long. */ - return unpack_long (type, valaddr); - } -} - /* Unpack raw data (copied from debugee, target byte order) at VALADDR as a CORE_ADDR, assuming the raw data is described by type TYPE. We don't assume any alignment for the raw data. Return value is in @@ -3035,6 +2934,21 @@ unpack_pointer (struct type *type, const gdb_byte *valaddr) return unpack_long (type, valaddr); } +bool +is_floating_value (struct value *val) +{ + struct type *type = check_typedef (value_type (val)); + + if (is_floating_type (type)) + { + if (!target_float_is_valid (value_contents (val), type)) + error (_("Invalid floating value found in program.")); + return true; + } + + return false; +} + /* Get the value of the FIELDNO'th field (which must be static) of TYPE. */ @@ -3107,7 +3021,7 @@ set_value_enclosing_type (struct value *val, struct type *new_encl_type) FIELDNO says which field. */ struct value * -value_primitive_field (struct value *arg1, int offset, +value_primitive_field (struct value *arg1, LONGEST offset, int fieldno, struct type *arg_type) { struct value *v; @@ -3137,8 +3051,8 @@ value_primitive_field (struct value *arg1, int offset, bit. Assume that the address, offset, and embedded offset are sufficiently aligned. */ - int bitpos = TYPE_FIELD_BITPOS (arg_type, fieldno); - int container_bitsize = TYPE_LENGTH (type) * 8; + LONGEST bitpos = TYPE_FIELD_BITPOS (arg_type, fieldno); + LONGEST container_bitsize = TYPE_LENGTH (type) * 8; v = allocate_value_lazy (type); v->bitsize = TYPE_FIELD_BITSIZE (arg_type, fieldno); @@ -3159,7 +3073,7 @@ value_primitive_field (struct value *arg1, int offset, /* This field is actually a base subobject, so preserve the entire object's contents for later references to virtual bases, etc. */ - int boffset; + LONGEST boffset; /* Lazy register values with offsets are not supported. */ if (VALUE_LVAL (arg1) == lval_register && value_lazy (arg1)) @@ -3223,8 +3137,6 @@ value_primitive_field (struct value *arg1, int offset, + value_embedded_offset (arg1)); } set_value_component_location (v, arg1); - VALUE_REGNUM (v) = VALUE_REGNUM (arg1); - VALUE_FRAME_ID (v) = VALUE_FRAME_ID (arg1); return v; } @@ -3248,7 +3160,7 @@ value_field (struct value *arg1, int fieldno) struct value * value_fn_field (struct value **arg1p, struct fn_field *f, int j, struct type *type, - int offset) + LONGEST offset) { struct value *v; struct type *ftype = TYPE_FN_FIELD_TYPE (f, j); @@ -3270,6 +3182,7 @@ value_fn_field (struct value **arg1p, struct fn_field *f, } v = allocate_value (ftype); + VALUE_LVAL (v) = lval_memory; if (sym) { set_value_address (v, BLOCK_START (SYMBOL_BLOCK_VALUE (sym))); @@ -3318,14 +3231,14 @@ value_fn_field (struct value **arg1p, struct fn_field *f, static LONGEST unpack_bits_as_long (struct type *field_type, const gdb_byte *valaddr, - int bitpos, int bitsize) + LONGEST bitpos, LONGEST bitsize) { enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (field_type)); ULONGEST val; ULONGEST valmask; int lsbcount; - int bytes_read; - int read_offset; + LONGEST bytes_read; + LONGEST read_offset; /* Read the minimum number of bytes required; there may not be enough bytes to read an entire ULONGEST. */ @@ -3374,7 +3287,7 @@ unpack_bits_as_long (struct type *field_type, const gdb_byte *valaddr, int unpack_value_field_as_long (struct type *type, const gdb_byte *valaddr, - int embedded_offset, int fieldno, + LONGEST embedded_offset, int fieldno, const struct value *val, LONGEST *result) { int bitpos = TYPE_FIELD_BITPOS (type, fieldno); @@ -3417,24 +3330,31 @@ unpack_field_as_long (struct type *type, const gdb_byte *valaddr, int fieldno) void unpack_value_bitfield (struct value *dest_val, - int bitpos, int bitsize, - const gdb_byte *valaddr, int embedded_offset, + LONGEST bitpos, LONGEST bitsize, + const gdb_byte *valaddr, LONGEST embedded_offset, const struct value *val) { enum bfd_endian byte_order; int src_bit_offset; int dst_bit_offset; - LONGEST num; struct type *field_type = value_type (dest_val); - /* First, unpack and sign extend the bitfield as if it was wholly - available. Invalid/unavailable bits are read as zero, but that's - OK, as they'll end up marked below. */ byte_order = gdbarch_byte_order (get_type_arch (field_type)); - num = unpack_bits_as_long (field_type, valaddr + embedded_offset, - bitpos, bitsize); - store_signed_integer (value_contents_raw (dest_val), - TYPE_LENGTH (field_type), byte_order, num); + + /* First, unpack and sign extend the bitfield as if it was wholly + valid. Optimized out/unavailable bits are read as zero, but + that's OK, as they'll end up marked below. If the VAL is + wholly-invalid we may have skipped allocating its contents, + though. See allocate_optimized_out_value. */ + if (valaddr != NULL) + { + LONGEST num; + + num = unpack_bits_as_long (field_type, valaddr + embedded_offset, + bitpos, bitsize); + store_signed_integer (value_contents_raw (dest_val), + TYPE_LENGTH (field_type), byte_order, num); + } /* Now copy the optimized out / unavailability ranges to the right bits. */ @@ -3456,7 +3376,7 @@ unpack_value_bitfield (struct value *dest_val, struct value * value_field_bitfield (struct type *type, int fieldno, const gdb_byte *valaddr, - int embedded_offset, const struct value *val) + LONGEST embedded_offset, const struct value *val) { int bitpos = TYPE_FIELD_BITPOS (type, fieldno); int bitsize = TYPE_FIELD_BITSIZE (type, fieldno); @@ -3477,12 +3397,12 @@ value_field_bitfield (struct type *type, int fieldno, void modify_field (struct type *type, gdb_byte *addr, - LONGEST fieldval, int bitpos, int bitsize) + LONGEST fieldval, LONGEST bitpos, LONGEST bitsize) { enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type)); ULONGEST oword; ULONGEST mask = (ULONGEST) -1 >> (8 * sizeof (ULONGEST) - bitsize); - int bytesize; + LONGEST bytesize; /* Normalize BITPOS. */ addr += bitpos / 8; @@ -3498,7 +3418,7 @@ modify_field (struct type *type, gdb_byte *addr, { /* FIXME: would like to include fieldval in the message, but we don't have a sprintf_longest. */ - warning (_("Value does not fit in %d bits."), bitsize); + warning (_("Value does not fit in %s bits."), plongest (bitsize)); /* Truncate it, otherwise adjoining fields may be corrupted. */ fieldval &= mask; @@ -3526,7 +3446,7 @@ 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; + LONGEST len; type = check_typedef (type); len = TYPE_LENGTH (type); @@ -3544,10 +3464,16 @@ pack_long (gdb_byte *buf, struct type *type, LONGEST num) break; case TYPE_CODE_REF: + case TYPE_CODE_RVALUE_REF: case TYPE_CODE_PTR: store_typed_address (buf, type, (CORE_ADDR) num); break; + case TYPE_CODE_FLT: + case TYPE_CODE_DECFLOAT: + target_float_from_longest (buf, type, num); + break; + default: error (_("Unexpected type (%d) encountered for integer constant."), TYPE_CODE (type)); @@ -3560,7 +3486,7 @@ pack_long (gdb_byte *buf, struct type *type, LONGEST num) static void pack_unsigned_long (gdb_byte *buf, struct type *type, ULONGEST num) { - int len; + LONGEST len; enum bfd_endian byte_order; type = check_typedef (type); @@ -3580,10 +3506,16 @@ pack_unsigned_long (gdb_byte *buf, struct type *type, ULONGEST num) break; case TYPE_CODE_REF: + case TYPE_CODE_RVALUE_REF: case TYPE_CODE_PTR: store_typed_address (buf, type, (CORE_ADDR) num); break; + case TYPE_CODE_FLT: + case TYPE_CODE_DECFLOAT: + target_float_from_ulongest (buf, type, num); + break; + default: error (_("Unexpected type (%d) encountered " "for unsigned integer constant."), @@ -3649,8 +3581,8 @@ value_from_contents_and_address_unresolved (struct type *type, v = allocate_value_lazy (type); else v = value_from_contents (type, valaddr); - set_value_address (v, address); VALUE_LVAL (v) = lval_memory; + set_value_address (v, address); return v; } @@ -3675,8 +3607,8 @@ value_from_contents_and_address (struct type *type, if (TYPE_DATA_LOCATION (resolved_type_no_typedef) != NULL && TYPE_DATA_LOCATION_KIND (resolved_type_no_typedef) == PROP_CONST) address = TYPE_DATA_LOCATION_ADDR (resolved_type_no_typedef); - set_value_address (v, address); VALUE_LVAL (v) = lval_memory; + set_value_address (v, address); return v; } @@ -3693,32 +3625,6 @@ value_from_contents (struct type *type, const gdb_byte *contents) return result; } -struct value * -value_from_double (struct type *type, DOUBLEST num) -{ - struct value *val = allocate_value (type); - struct type *base_type = check_typedef (type); - enum type_code code = TYPE_CODE (base_type); - - if (code == TYPE_CODE_FLT) - { - store_typed_floating (value_contents_raw (val), base_type, num); - } - else - error (_("Unexpected type encountered for floating constant.")); - - 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; -} - /* Extract a value from the history file. Input will be of the form $digits or $$digits. See block comment above 'write_dollar_variable' for details. */ @@ -3782,12 +3688,35 @@ value_from_history_ref (const char *h, const char **endp) return access_value_history (index); } +/* Get the component value (offset by OFFSET bytes) of a struct or + union WHOLE. Component's type is TYPE. */ + +struct value * +value_from_component (struct value *whole, struct type *type, LONGEST offset) +{ + struct value *v; + + if (VALUE_LVAL (whole) == lval_memory && value_lazy (whole)) + v = allocate_value_lazy (type); + else + { + v = allocate_value (type); + value_contents_copy (v, value_embedded_offset (v), + whole, value_embedded_offset (whole) + offset, + type_length_units (type)); + } + v->offset = value_offset (whole) + offset + value_embedded_offset (whole); + set_value_component_location (v, whole); + + return v; +} + struct value * coerce_ref_if_computed (const struct value *arg) { const struct lval_funcs *funcs; - if (TYPE_CODE (check_typedef (value_type (arg))) != TYPE_CODE_REF) + if (!TYPE_IS_REFERENCE (check_typedef (value_type (arg)))) return NULL; if (value_lval_const (arg) != lval_computed) @@ -3829,7 +3758,7 @@ coerce_ref (struct value *arg) if (retval) return retval; - if (TYPE_CODE (value_type_arg_tmp) != TYPE_CODE_REF) + if (!TYPE_IS_REFERENCE (value_type_arg_tmp)) return arg; enc_type = check_typedef (value_enclosing_type (arg)); @@ -3963,7 +3892,7 @@ value_fetch_lazy (struct value *val) } else if (VALUE_LVAL (val) == lval_register) { - struct frame_info *frame; + struct frame_info *next_frame; int regnum; struct type *type = check_typedef (value_type (val)); struct value *new_val = val, *mark = value_mark (); @@ -3974,27 +3903,33 @@ value_fetch_lazy (struct value *val) while (VALUE_LVAL (new_val) == lval_register && value_lazy (new_val)) { - struct frame_id frame_id = VALUE_FRAME_ID (new_val); + struct frame_id next_frame_id = VALUE_NEXT_FRAME_ID (new_val); - frame = frame_find_by_id (frame_id); + next_frame = frame_find_by_id (next_frame_id); regnum = VALUE_REGNUM (new_val); - gdb_assert (frame != NULL); + gdb_assert (next_frame != NULL); /* Convertible register routines are used for multi-register values and for interpretation in different types (e.g. float or int from a double register). Lazy register values should have the register's natural type, so they do not apply. */ - gdb_assert (!gdbarch_convert_register_p (get_frame_arch (frame), + gdb_assert (!gdbarch_convert_register_p (get_frame_arch (next_frame), regnum, type)); - new_val = get_frame_register_value (frame, regnum); + /* FRAME was obtained, above, via VALUE_NEXT_FRAME_ID. + Since a "->next" operation was performed when setting + this field, we do not need to perform a "next" operation + again when unwinding the register. That's why + frame_unwind_register_value() is called here instead of + get_frame_register_value(). */ + new_val = frame_unwind_register_value (next_frame, regnum); /* If we get another lazy lval_register value, it means the - register is found by reading it from the next frame. - get_frame_register_value should never return a value with - the frame id pointing to FRAME. If it does, it means we + register is found by reading it from NEXT_FRAME's next frame. + frame_unwind_register_value should never return a value with + the frame id pointing to NEXT_FRAME. If it does, it means we either have two consecutive frames with the same frame id in the frame chain, or some code is trying to unwind behind get_prev_frame's back (e.g., a frame unwind @@ -4003,7 +3938,7 @@ value_fetch_lazy (struct value *val) in this situation. */ if (VALUE_LVAL (new_val) == lval_register && value_lazy (new_val) - && frame_id_eq (VALUE_FRAME_ID (new_val), frame_id)) + && frame_id_eq (VALUE_NEXT_FRAME_ID (new_val), next_frame_id)) internal_error (__FILE__, __LINE__, _("infinite loop while fetching a register")); } @@ -4023,6 +3958,9 @@ value_fetch_lazy (struct value *val) if (frame_debug) { struct gdbarch *gdbarch; + struct frame_info *frame; + /* VALUE_FRAME_ID is used here, instead of VALUE_NEXT_FRAME_ID, + so that the frame level will be shown correctly. */ frame = frame_find_by_id (VALUE_FRAME_ID (val)); regnum = VALUE_REGNUM (val); gdbarch = get_frame_arch (frame);