X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fvalue.c;h=9a144fb7fb62439b52a4ec5ebd25c81c050b5957;hb=ba18742c3a1b62ff218db99bee47bb932af6dab9;hp=ec615b36630d7a7e79a05e1d262c27a3003d732c;hpb=eb3ff9a55175dcdac8328b558d54951a14d719b1;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/value.c b/gdb/value.c index ec615b3663..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-2017 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" @@ -43,10 +42,6 @@ #include #include "completer.h" -/* Prototypes for exported functions. */ - -void _initialize_values (void); - /* Definition of a user function. */ struct internal_function { @@ -813,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) @@ -852,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) @@ -865,17 +860,17 @@ 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 +bool value_contents_eq (const struct value *val1, LONGEST offset1, const struct value *val2, LONGEST offset2, LONGEST length) @@ -885,12 +880,6 @@ value_contents_eq (const struct value *val1, LONGEST offset1, 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 @@ -980,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); @@ -1638,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); @@ -1970,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; @@ -2010,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 @@ -2100,7 +2086,7 @@ 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; @@ -2563,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. */ } @@ -2665,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; @@ -2711,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. */ @@ -2738,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. */ @@ -2750,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). @@ -2769,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. */ @@ -2927,12 +2897,8 @@ 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: @@ -2947,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 @@ -3028,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. */ @@ -3548,6 +3469,11 @@ pack_long (gdb_byte *buf, struct type *type, LONGEST num) 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)); @@ -3585,6 +3511,11 @@ pack_unsigned_long (gdb_byte *buf, struct type *type, ULONGEST num) 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."), @@ -3694,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. */