x86: Adjust linker tests for --disable-separate-code
[binutils-gdb.git] / gdb / eval.c
index 9510eee962a5fe0e59ef3390559af6dc9469bf90..bcdb78f05bcfedc8f832073b96e129a5f9a8e414 100644 (file)
@@ -42,6 +42,7 @@
 #include <ctype.h>
 #include "expop.h"
 #include "c-exp.h"
+#include "inferior.h"
 
 \f
 /* Parse the string EXP as a C expression, evaluate it,
@@ -92,7 +93,7 @@ struct value *
 expression::evaluate (struct type *expect_type, enum noside noside)
 {
   gdb::optional<enable_thread_stack_temporaries> stack_temporaries;
-  if (target_has_execution ()
+  if (target_has_execution () && inferior_ptid != null_ptid
       && language_defn->la_language == language_cplus
       && !thread_stack_temporaries_enabled_p (inferior_thread ()))
     stack_temporaries.emplace (inferior_thread ());
@@ -578,10 +579,10 @@ var_value_operation::evaluate (struct type *expect_type,
                               struct expression *exp,
                               enum noside noside)
 {
-  symbol *var = std::get<0> (m_storage);
+  symbol *var = std::get<0> (m_storage).symbol;
   if (SYMBOL_TYPE (var)->code () == TYPE_CODE_ERROR)
     error_unknown_type (var->print_name ());
-  return evaluate_var_value (noside, std::get<1> (m_storage), var);
+  return evaluate_var_value (noside, std::get<0> (m_storage).block, var);
 }
 
 } /* namespace expr */
@@ -687,8 +688,16 @@ operation::evaluate_funcall (struct type *expect_type,
   std::vector<value *> vals (args.size ());
 
   value *callee = evaluate_with_coercion (exp, noside);
+  struct type *type = value_type (callee);
+  if (type->code () == TYPE_CODE_PTR)
+    type = TYPE_TARGET_TYPE (type);
   for (int i = 0; i < args.size (); ++i)
-    vals[i] = args[i]->evaluate_with_coercion (exp, noside);
+    {
+      if (i < type->num_fields ())
+       vals[i] = args[i]->evaluate (type->field (i).type (), exp, noside);
+      else
+       vals[i] = args[i]->evaluate_with_coercion (exp, noside);
+    }
 
   return evaluate_subexp_do_call (exp, noside, callee, vals,
                                  function_name, expect_type);
@@ -710,12 +719,13 @@ var_value_operation::evaluate_funcall (struct type *expect_type,
 
   struct symbol *symp;
   find_overload_match (argvec, NULL, NON_METHOD,
-                      NULL, std::get<0> (m_storage),
+                      NULL, std::get<0> (m_storage).symbol,
                       NULL, &symp, NULL, 0, noside);
 
   if (SYMBOL_TYPE (symp)->code () == TYPE_CODE_ERROR)
     error_unknown_type (symp->print_name ());
-  value *callee = evaluate_var_value (noside, std::get<1> (m_storage), symp);
+  value *callee = evaluate_var_value (noside, std::get<0> (m_storage).block,
+                                     symp);
 
   return evaluate_subexp_do_call (exp, noside, callee, argvec,
                                  nullptr, expect_type);
@@ -862,6 +872,8 @@ structop_base_operation::evaluate_funcall
      (struct type *expect_type, struct expression *exp, enum noside noside,
       const std::vector<operation_up> &args)
 {
+  /* Allocate space for the function call arguments, Including space for a
+     `this' pointer at the start.  */
   std::vector<value *> vals (args.size () + 1);
   /* First, evaluate the structure into vals[0].  */
   enum exp_opcode op = opcode ();
@@ -908,9 +920,13 @@ structop_base_operation::evaluate_funcall
        }
     }
 
+  /* Evaluate the arguments.  The '+ 1' here is to allow for the `this'
+     pointer we placed into vals[0].  */
   for (int i = 0; i < args.size (); ++i)
     vals[i + 1] = args[i]->evaluate_with_coercion (exp, noside);
-  gdb::array_view<value *> arg_view = vals;
+
+  /* The array view includes the `this' pointer.  */
+  gdb::array_view<value *> arg_view (vals);
 
   int static_memfuncp;
   value *callee;
@@ -931,7 +947,7 @@ structop_base_operation::evaluate_funcall
     {
       struct value *temp = vals[0];
 
-      callee = value_struct_elt (&temp, &vals[1], tstr,
+      callee = value_struct_elt (&temp, arg_view, tstr,
                                 &static_memfuncp,
                                 op == STRUCTOP_STRUCT
                                 ? "structure" : "structure pointer");
@@ -1005,14 +1021,15 @@ eval_op_var_entry_value (struct type *expect_type, struct expression *exp,
 struct value *
 eval_op_var_msym_value (struct type *expect_type, struct expression *exp,
                        enum noside noside, bool outermost_p,
-                       minimal_symbol *msymbol, struct objfile *objfile)
+                       bound_minimal_symbol msymbol)
 {
-  value *val = evaluate_var_msym_value (noside, objfile, msymbol);
+  value *val = evaluate_var_msym_value (noside, msymbol.objfile,
+                                       msymbol.minsym);
 
   struct type *type = value_type (val);
   if (type->code () == TYPE_CODE_ERROR
       && (noside != EVAL_AVOID_SIDE_EFFECTS || !outermost_p))
-    error_unknown_type (msymbol->print_name ());
+    error_unknown_type (msymbol.minsym->print_name ());
   return val;
 }
 
@@ -1115,7 +1132,7 @@ eval_op_structop_struct (struct type *expect_type, struct expression *exp,
                         enum noside noside,
                         struct value *arg1, const char *string)
 {
-  struct value *arg3 = value_struct_elt (&arg1, NULL, string,
+  struct value *arg3 = value_struct_elt (&arg1, {}, string,
                                         NULL, "structure");
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
     arg3 = value_zero (value_type (arg3), VALUE_LVAL (arg3));
@@ -1171,7 +1188,7 @@ eval_op_structop_ptr (struct type *expect_type, struct expression *exp,
       }
   }
 
-  struct value *arg3 = value_struct_elt (&arg1, NULL, string,
+  struct value *arg3 = value_struct_elt (&arg1, {}, string,
                                         NULL, "structure pointer");
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
     arg3 = value_zero (value_type (arg3), VALUE_LVAL (arg3));
@@ -1579,12 +1596,10 @@ eval_op_ind (struct type *expect_type, struct expression *exp,
         There is a risk that this dereference will have side-effects
         in the inferior, but being able to print accurate type
         information seems worth the risk. */
-      if ((type->code () != TYPE_CODE_PTR
-          && !TYPE_IS_REFERENCE (type))
+      if (!type->is_pointer_or_reference ()
          || !is_dynamic_type (TYPE_TARGET_TYPE (type)))
        {
-         if (type->code () == TYPE_CODE_PTR
-             || TYPE_IS_REFERENCE (type)
+         if (type->is_pointer_or_reference ()
              /* In C you can dereference an array to get the 1st elt.  */
              || type->code () == TYPE_CODE_ARRAY)
            return value_zero (TYPE_TARGET_TYPE (type),
@@ -1955,8 +1970,8 @@ eval_op_objc_msgcall (struct type *expect_type, struct expression *exp,
 
       /* The address might point to a function descriptor;
         resolve it to the actual code address instead.  */
-      addr = gdbarch_convert_from_func_ptr_addr (exp->gdbarch, addr,
-                                                current_top_target ());
+      addr = gdbarch_convert_from_func_ptr_addr
+       (exp->gdbarch, addr, current_inferior ()->top_target ());
 
       /* Is it a high_level symbol?  */
       sym = find_pc_function (addr);
@@ -2189,7 +2204,7 @@ logical_and_operation::evaluate (struct type *expect_type,
     }
   else
     {
-      int tem = value_logical_not (arg1);
+      bool tem = value_logical_not (arg1);
       if (!tem)
        {
          arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
@@ -2218,7 +2233,7 @@ logical_or_operation::evaluate (struct type *expect_type,
     }
   else
     {
-      int tem = value_logical_not (arg1);
+      bool tem = value_logical_not (arg1);
       if (tem)
        {
          arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
@@ -2283,7 +2298,7 @@ array_operation::evaluate_struct_tuple (struct value *struct_val,
        error (_("too many initializers"));
       field_type = struct_type->field (fieldno).type ();
       if (field_type->code () == TYPE_CODE_UNION
-         && TYPE_FIELD_NAME (struct_type, fieldno)[0] == '0')
+         && struct_type->field (fieldno).name ()[0] == '0')
        error (_("don't know which variant you want to set"));
 
       /* Here, struct_type is the type of the inner struct,
@@ -2306,13 +2321,13 @@ array_operation::evaluate_struct_tuple (struct value *struct_val,
        val = value_cast (field_type, val);
 
       bitsize = TYPE_FIELD_BITSIZE (struct_type, fieldno);
-      bitpos = TYPE_FIELD_BITPOS (struct_type, fieldno);
-      addr = value_contents_writeable (struct_val) + bitpos / 8;
+      bitpos = struct_type->field (fieldno).loc_bitpos ();
+      addr = value_contents_writeable (struct_val).data () + bitpos / 8;
       if (bitsize)
        modify_field (struct_type, addr,
                      value_as_long (val), bitpos % 8, bitsize);
       else
-       memcpy (addr, value_contents (val),
+       memcpy (addr, value_contents (val).data (),
                TYPE_LENGTH (value_type (val)));
 
     }
@@ -2336,7 +2351,7 @@ array_operation::evaluate (struct type *expect_type,
     {
       struct value *rec = allocate_value (expect_type);
 
-      memset (value_contents_raw (rec), '\0', TYPE_LENGTH (type));
+      memset (value_contents_raw (rec).data (), '\0', TYPE_LENGTH (type));
       return evaluate_struct_tuple (rec, exp, noside, nargs);
     }
 
@@ -2355,7 +2370,7 @@ array_operation::evaluate (struct type *expect_type,
          high_bound = (TYPE_LENGTH (type) / element_size) - 1;
        }
       index = low_bound;
-      memset (value_contents_raw (array), 0, TYPE_LENGTH (expect_type));
+      memset (value_contents_raw (array).data (), 0, TYPE_LENGTH (expect_type));
       for (tem = nargs; --nargs >= 0;)
        {
          struct value *element;
@@ -2367,9 +2382,9 @@ array_operation::evaluate (struct type *expect_type,
          if (index > high_bound)
            /* To avoid memory corruption.  */
            error (_("Too many array elements"));
-         memcpy (value_contents_raw (array)
+         memcpy (value_contents_raw (array).data ()
                  + (index - low_bound) * element_size,
-                 value_contents (element),
+                 value_contents (element).data (),
                  element_size);
          index++;
        }
@@ -2380,7 +2395,7 @@ array_operation::evaluate (struct type *expect_type,
       && type->code () == TYPE_CODE_SET)
     {
       struct value *set = allocate_value (expect_type);
-      gdb_byte *valaddr = value_contents_raw (set);
+      gdb_byte *valaddr = value_contents_raw (set).data ();
       struct type *element_type = type->index_type ();
       struct type *check_type = element_type;
       LONGEST low_bound, high_bound;
@@ -2529,9 +2544,8 @@ value *
 var_msym_value_operation::evaluate_for_address (struct expression *exp,
                                                enum noside noside)
 {
-  value *val = evaluate_var_msym_value (noside,
-                                       std::get<1> (m_storage),
-                                       std::get<0> (m_storage));
+  const bound_minimal_symbol &b = std::get<0> (m_storage);
+  value *val = evaluate_var_msym_value (noside, b.objfile, b.minsym);
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
     {
       struct type *type = lookup_pointer_type (value_type (val));
@@ -2564,7 +2578,7 @@ value *
 var_value_operation::evaluate_for_address (struct expression *exp,
                                           enum noside noside)
 {
-  symbol *var = std::get<0> (m_storage);
+  symbol *var = std::get<0> (m_storage).symbol;
 
   /* C++: The "address" of a reference should yield the address
    * of the object pointed to.  Let value_addr() deal with it.  */
@@ -2584,20 +2598,21 @@ var_value_operation::evaluate_for_address (struct expression *exp,
       return value_zero (type, not_lval);
     }
   else
-    return address_of_variable (var, std::get<1> (m_storage));
+    return address_of_variable (var, std::get<0> (m_storage).block);
 }
 
 value *
 var_value_operation::evaluate_with_coercion (struct expression *exp,
                                             enum noside noside)
 {
-  struct symbol *var = std::get<0> (m_storage);
+  struct symbol *var = std::get<0> (m_storage).symbol;
   struct type *type = check_typedef (SYMBOL_TYPE (var));
   if (type->code () == TYPE_CODE_ARRAY
       && !type->is_vector ()
       && CAST_IS_CONVERSION (exp->language_defn))
     {
-      struct value *val = address_of_variable (var, std::get<1> (m_storage));
+      struct value *val = address_of_variable (var,
+                                              std::get<0> (m_storage).block);
       return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)), val);
     }
   return evaluate (nullptr, exp, noside);
@@ -2637,14 +2652,12 @@ var_msym_value_operation::evaluate_for_sizeof (struct expression *exp,
                                               enum noside noside)
 
 {
-  minimal_symbol *msymbol = std::get<0> (m_storage);
-  value *mval = evaluate_var_msym_value (noside,
-                                        std::get<1> (m_storage),
-                                        msymbol);
+  const bound_minimal_symbol &b = std::get<0> (m_storage);
+  value *mval = evaluate_var_msym_value (noside, b.objfile, b.minsym);
 
   struct type *type = value_type (mval);
   if (type->code () == TYPE_CODE_ERROR)
-    error_unknown_type (msymbol->print_name ());
+    error_unknown_type (b.minsym->print_name ());
 
   /* FIXME: This should be size_t.  */
   struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
@@ -2691,8 +2704,7 @@ unop_ind_base_operation::evaluate_for_sizeof (struct expression *exp,
   value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
                                                  EVAL_AVOID_SIDE_EFFECTS);
   struct type *type = check_typedef (value_type (val));
-  if (type->code () != TYPE_CODE_PTR
-      && !TYPE_IS_REFERENCE (type)
+  if (!type->is_pointer_or_reference ()
       && type->code () != TYPE_CODE_ARRAY)
     error (_("Attempt to take contents of a non-pointer value."));
   type = TYPE_TARGET_TYPE (type);
@@ -2723,7 +2735,7 @@ value *
 var_value_operation::evaluate_for_sizeof (struct expression *exp,
                                          enum noside noside)
 {
-  struct type *type = SYMBOL_TYPE (std::get<0> (m_storage));
+  struct type *type = SYMBOL_TYPE (std::get<0> (m_storage).symbol);
   if (is_dynamic_type (type))
     {
       value *val = evaluate (nullptr, exp, EVAL_NORMAL);
@@ -2750,9 +2762,8 @@ var_msym_value_operation::evaluate_for_cast (struct type *to_type,
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
     return value_zero (to_type, not_lval);
 
-  value *val = evaluate_var_msym_value (noside,
-                                       std::get<1> (m_storage),
-                                       std::get<0> (m_storage));
+  const bound_minimal_symbol &b = std::get<0> (m_storage);
+  value *val = evaluate_var_msym_value (noside, b.objfile, b.minsym);
 
   val = value_cast (to_type, val);
 
@@ -2772,8 +2783,8 @@ var_value_operation::evaluate_for_cast (struct type *to_type,
                                        enum noside noside)
 {
   value *val = evaluate_var_value (noside,
-                                  std::get<1> (m_storage),
-                                  std::get<0> (m_storage));
+                                  std::get<0> (m_storage).block,
+                                  std::get<0> (m_storage).symbol);
 
   val = value_cast (to_type, val);