Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / value.h
index 7bf5654ae43b6663f0e9010ae2134221ccecba43..089af59fbd854220b756c36090210b8f773b4847 100644 (file)
@@ -1,6 +1,6 @@
 /* Definitions for values of C expressions, for GDB.
 
-   Copyright (C) 1986-2021 Free Software Foundation, Inc.
+   Copyright (C) 1986-2023 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -23,6 +23,7 @@
 #include "frame.h"             /* For struct frame_id.  */
 #include "extension.h"
 #include "gdbsupport/gdb_ref_ptr.h"
+#include "gmp-utils.h"
 
 struct block;
 struct expression;
@@ -263,6 +264,12 @@ struct lval_funcs
      TOVAL is not considered as an lvalue.  */
   void (*write) (struct value *toval, struct value *fromval);
 
+  /* Return true if any part of V is optimized out, false otherwise.
+     This will only be called for lazy values -- if the value has been
+     fetched, then the value's optimized-out bits are consulted
+     instead.  */
+  bool (*is_optimized_out) (struct value *v);
+
   /* If non-NULL, this is used to implement pointer indirection for
      this value.  This method may return NULL, in which case value_ind
      will fall back to ordinary indirection.  */
@@ -353,7 +360,7 @@ extern void error_value_optimized_out (void);
    get to the real subobject, if the value happens to represent
    something embedded in a larger run-time object.  */
 
-extern gdb_byte *value_contents_raw (struct value *);
+extern gdb::array_view<gdb_byte> value_contents_raw (struct value *);
 
 /* Actual contents of the value.  For use of this value; setting it
    uses the stuff above.  Not valid if lazy is nonzero.  Target
@@ -361,24 +368,24 @@ extern gdb_byte *value_contents_raw (struct value *);
    value.  Note that a value therefore extends beyond what is
    declared here.  */
 
-extern const gdb_byte *value_contents (struct value *);
-extern gdb_byte *value_contents_writeable (struct value *);
+extern gdb::array_view<const gdb_byte> value_contents (struct value *);
+extern gdb::array_view<gdb_byte> value_contents_writeable (struct value *);
 
 /* The ALL variants of the above two macros do not adjust the returned
    pointer by the embedded_offset value.  */
 
-extern gdb_byte *value_contents_all_raw (struct value *);
-extern const gdb_byte *value_contents_all (struct value *);
+extern gdb::array_view<gdb_byte> value_contents_all_raw (struct value *);
+extern gdb::array_view<const gdb_byte> value_contents_all (struct value *);
 
 /* Like value_contents_all, but does not require that the returned
    bits be valid.  This should only be used in situations where you
    plan to check the validity manually.  */
-extern const gdb_byte *value_contents_for_printing (struct value *value);
+extern gdb::array_view<const gdb_byte> value_contents_for_printing (struct value *value);
 
 /* Like value_contents_for_printing, but accepts a constant value
    pointer.  Unlike value_contents_for_printing however, the pointed
    value must _not_ be lazy.  */
-extern const gdb_byte *
+extern gdb::array_view<const gdb_byte>
   value_contents_for_printing_const (const struct value *value);
 
 extern void value_fetch_lazy (struct value *val);
@@ -457,12 +464,6 @@ extern struct internalvar **deprecated_value_internalvar_hack (struct value *);
 extern struct frame_id *deprecated_value_next_frame_id_hack (struct value *);
 #define VALUE_NEXT_FRAME_ID(val) (*deprecated_value_next_frame_id_hack (val))
 
-/* Frame ID of frame to which a register value is relative.  This is
-   similar to VALUE_NEXT_FRAME_ID, above, but may not be assigned to. 
-   Note that VALUE_FRAME_ID effectively undoes the "next" operation
-   that was performed during the assignment to VALUE_NEXT_FRAME_ID.  */
-#define VALUE_FRAME_ID(val) (get_prev_frame_id_by_id (VALUE_NEXT_FRAME_ID (val)))
-
 /* Register number if the value is from a register.  */
 extern int *deprecated_value_regnum_hack (struct value *);
 #define VALUE_REGNUM(val) (*deprecated_value_regnum_hack (val))
@@ -549,7 +550,7 @@ extern void mark_value_bits_unavailable (struct value *value,
    example, to compare a complete object value with itself, including
    its enclosing type chunk, you'd do:
 
-     int len = TYPE_LENGTH (check_typedef (value_enclosing_type (val)));
+     int len = check_typedef (value_enclosing_type (val))->length ();
      value_contents_eq (val, 0, val, 0, len);
 
    Returns true iff the set of available/valid contents match.
@@ -598,6 +599,12 @@ extern bool value_contents_eq (const struct value *val1, LONGEST offset1,
                               const struct value *val2, LONGEST offset2,
                               LONGEST length);
 
+/* An overload of value_contents_eq that compares the entirety of both
+   values.  */
+
+extern bool value_contents_eq (const struct value *val1,
+                              const struct value *val2);
+
 /* Read LENGTH addressable memory units starting at MEMADDR into BUFFER,
    which is (or will be copied to) VAL's contents buffer offset by
    BIT_OFFSET bits.  Marks value contents ranges as unavailable if
@@ -620,7 +627,7 @@ struct value *value_vector_widen (struct value *scalar_value,
 #include "gdbtypes.h"
 #include "expression.h"
 
-struct frame_info;
+class frame_info_ptr;
 struct fn_field;
 
 extern int print_address_demangle (const struct value_print_options *,
@@ -686,6 +693,21 @@ extern struct value *value_from_history_ref (const char *, const char **);
 extern struct value *value_from_component (struct value *, struct type *,
                                           LONGEST);
 
+
+/* Create a new value by extracting it from WHOLE.  TYPE is the type
+   of the new value.  BIT_OFFSET and BIT_LENGTH describe the offset
+   and field width of the value to extract from WHOLE -- BIT_LENGTH
+   may differ from TYPE's length in the case where WHOLE's type is
+   packed.
+
+   When the value does come from a non-byte-aligned offset or field
+   width, it will be marked non_lval.  */
+
+extern struct value *value_from_component_bitsize (struct value *whole,
+                                                  struct type *type,
+                                                  LONGEST bit_offset,
+                                                  LONGEST bit_length);
+
 extern struct value *value_at (struct type *type, CORE_ADDR addr);
 extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
 
@@ -702,13 +724,13 @@ extern struct value *default_value_from_register (struct gdbarch *gdbarch,
                                                  struct frame_id frame_id);
 
 extern void read_frame_register_value (struct value *value,
-                                      struct frame_info *frame);
+                                      frame_info_ptr frame);
 
 extern struct value *value_from_register (struct type *type, int regnum,
-                                         struct frame_info *frame);
+                                         frame_info_ptr frame);
 
 extern CORE_ADDR address_from_register (int regnum,
-                                       struct frame_info *frame);
+                                       frame_info_ptr frame);
 
 extern struct value *value_of_variable (struct symbol *var,
                                        const struct block *b);
@@ -716,9 +738,9 @@ extern struct value *value_of_variable (struct symbol *var,
 extern struct value *address_of_variable (struct symbol *var,
                                          const struct block *b);
 
-extern struct value *value_of_register (int regnum, struct frame_info *frame);
+extern struct value *value_of_register (int regnum, frame_info_ptr frame);
 
-struct value *value_of_register_lazy (struct frame_info *frame, int regnum);
+struct value *value_of_register_lazy (frame_info_ptr frame, int regnum);
 
 /* Return the symbol's reading requirement.  */
 
@@ -731,16 +753,13 @@ extern int symbol_read_needs_frame (struct symbol *);
 
 extern struct value *read_var_value (struct symbol *var,
                                     const struct block *var_block,
-                                    struct frame_info *frame);
+                                    frame_info_ptr frame);
 
 extern struct value *allocate_value (struct type *type);
 extern struct value *allocate_value_lazy (struct type *type);
 extern void value_contents_copy (struct value *dst, LONGEST dst_offset,
                                 struct value *src, LONGEST src_offset,
                                 LONGEST length);
-extern void value_contents_copy_raw (struct value *dst, LONGEST dst_offset,
-                                    struct value *src, LONGEST src_offset,
-                                    LONGEST length);
 
 extern struct value *allocate_repeat_value (struct type *type, int count);
 
@@ -828,7 +847,7 @@ extern struct value *value_neg (struct value *arg1);
 extern struct value *value_complement (struct value *arg1);
 
 extern struct value *value_struct_elt (struct value **argp,
-                                      struct value **args,
+                                      gdb::optional<gdb::array_view <value *>> args,
                                       const char *name, int *static_memfuncp,
                                       const char *err);
 
@@ -916,13 +935,6 @@ extern struct value *evaluate_expression (struct expression *exp,
 
 extern struct value *evaluate_type (struct expression *exp);
 
-extern struct value *evaluate_subexp (struct type *expect_type,
-                                     struct expression *exp,
-                                     int *pos, enum noside noside);
-
-extern struct value *evaluate_subexpression_type (struct expression *exp,
-                                                 int subexp);
-
 extern value *evaluate_var_value (enum noside noside, const block *blk,
                                  symbol *var);
 
@@ -930,18 +942,13 @@ extern value *evaluate_var_msym_value (enum noside noside,
                                       struct objfile *objfile,
                                       minimal_symbol *msymbol);
 
-extern value *eval_skip_value (expression *exp);
-
-extern void fetch_subexp_value (struct expression *exp, int *pc,
+namespace expr { class operation; };
+extern void fetch_subexp_value (struct expression *exp,
+                               expr::operation *op,
                                struct value **valp, struct value **resultp,
                                std::vector<value_ref_ptr> *val_chain,
                                bool preserve_errors);
 
-extern const char *extract_field_op (struct expression *exp, int *subexp);
-
-extern struct value *evaluate_subexp_with_coercion (struct expression *,
-                                                   int *, enum noside);
-
 extern struct value *parse_and_eval (const char *exp);
 
 extern struct value *parse_to_comma_and_eval (const char **expp);
@@ -962,6 +969,10 @@ extern void binop_promote (const struct language_defn *language,
 
 extern struct value *access_value_history (int num);
 
+/* Return the number of items in the value history.  */
+
+extern ULONGEST value_history_count ();
+
 extern struct value *value_of_internalvar (struct gdbarch *gdbarch,
                                           struct internalvar *var);
 
@@ -1012,12 +1023,6 @@ struct internalvar_funcs
                         struct agent_expr *expr,
                         struct axs_value *value,
                         void *data);
-
-  /* If non-NULL, this is called to destroy DATA.  The DATA argument
-     passed to this function is the same argument that was passed to
-     `create_internalvar_type_lazy'.  */
-
-  void (*destroy) (void *data);
 };
 
 extern struct internalvar *create_internalvar_type_lazy (const char *name,
@@ -1042,7 +1047,15 @@ extern int value_equal_contents (struct value *arg1, struct value *arg2);
 
 extern int value_less (struct value *arg1, struct value *arg2);
 
-extern int value_logical_not (struct value *arg1);
+/* Simulate the C operator ! -- return true if ARG1 contains zero.  */
+extern bool value_logical_not (struct value *arg1);
+
+/* Returns true if the value VAL represents a true value.  */
+static inline bool
+value_true (struct value *val)
+{
+  return !value_logical_not (val);
+}
 
 /* C++ */
 
@@ -1097,10 +1110,6 @@ extern void print_floating (const gdb_byte *valaddr, struct type *type,
 extern void value_print (struct value *val, struct ui_file *stream,
                         const struct value_print_options *options);
 
-extern void value_print_array_elements (struct value *val,
-                                       struct ui_file *stream, int format,
-                                       enum val_prettyformat pretty);
-
 /* Release values from the value chain and return them.  Values
    created after MARK are released.  If MARK is nullptr, or if MARK is
    not found on the value chain, then all values are released.  Values
@@ -1122,7 +1131,7 @@ extern int val_print_string (struct type *elttype, const char *encoding,
 
 extern void print_variable_and_value (const char *name,
                                      struct symbol *var,
-                                     struct frame_info *frame,
+                                     frame_info_ptr frame,
                                      struct ui_file *stream,
                                      int indent);
 
@@ -1135,7 +1144,7 @@ extern void preserve_values (struct objfile *);
 
 /* From values.c */
 
-extern struct value *value_copy (struct value *);
+extern struct value *value_copy (const value *);
 
 extern struct value *value_non_lval (struct value *);
 
@@ -1171,10 +1180,6 @@ extern struct value *find_function_in_inferior (const char *,
 
 extern struct value *value_allocate_space_in_inferior (int);
 
-extern struct value *value_subscripted_rvalue (struct value *array,
-                                              LONGEST index,
-                                              LONGEST lowerbound);
-
 /* User function handler.  */
 
 typedef struct value *(*internal_function_fn) (struct gdbarch *gdbarch,
@@ -1222,4 +1227,8 @@ extern struct value *call_xmethod (struct value *method,
    exiting (e.g., on quit_force).  */
 extern void finalize_values ();
 
+/* Convert VALUE to a gdb_mpq.  The caller must ensure that VALUE is
+   of floating-point, fixed-point, or integer type.  */
+extern gdb_mpq value_to_gdb_mpq (struct value *value);
+
 #endif /* !defined (VALUE_H) */