Remove tp_t typedef
[deliverable/binutils-gdb.git] / gdb / eval.c
index 24f32f887d92b014eff29d1ebf0f9effb198d092..5bd6e2cbfea489c6baa775c84378c51610323c81 100644 (file)
@@ -1,6 +1,6 @@
 /* Evaluate expressions for GDB.
 
-   Copyright (C) 1986-2017 Free Software Foundation, Inc.
+   Copyright (C) 1986-2018 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -69,27 +69,20 @@ struct value *
 evaluate_subexp (struct type *expect_type, struct expression *exp,
                 int *pos, enum noside noside)
 {
-  struct cleanup *cleanups;
   struct value *retval;
-  int cleanup_temps = 0;
 
+  gdb::optional<enable_thread_stack_temporaries> stack_temporaries;
   if (*pos == 0 && target_has_execution
       && exp->language_defn->la_language == language_cplus
       && !thread_stack_temporaries_enabled_p (inferior_ptid))
-    {
-      cleanups = enable_thread_stack_temporaries (inferior_ptid);
-      cleanup_temps = 1;
-    }
+    stack_temporaries.emplace (inferior_ptid);
 
   retval = (*exp->language_defn->la_exp_desc->evaluate_exp)
     (expect_type, exp, pos, noside);
 
-  if (cleanup_temps)
-    {
-      if (value_in_thread_stack_temporaries (retval, inferior_ptid))
-       retval = value_non_lval (retval);
-      do_cleanups (cleanups);
-    }
+  if (stack_temporaries.has_value ()
+      && value_in_thread_stack_temporaries (retval, inferior_ptid))
+    retval = value_non_lval (retval);
 
   return retval;
 }
@@ -186,14 +179,14 @@ evaluate_subexpression_type (struct expression *exp, int subexp)
    set to any referenced values.  *VALP will never be a lazy value.
    This is the value which we store in struct breakpoint.
 
-   If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the
-   value chain.  The caller must free the values individually.  If
-   VAL_CHAIN is NULL, all generated values will be left on the value
-   chain.  */
+   If VAL_CHAIN is non-NULL, the values put into *VAL_CHAIN will be
+   released from the value chain.  If VAL_CHAIN is NULL, all generated
+   values will be left on the value chain.  */
 
 void
 fetch_subexp_value (struct expression *exp, int *pc, struct value **valp,
-                   struct value **resultp, struct value **val_chain,
+                   struct value **resultp,
+                   std::vector<value_ref_ptr> *val_chain,
                    int preserve_errors)
 {
   struct value *mark, *new_mark, *result;
@@ -202,7 +195,7 @@ fetch_subexp_value (struct expression *exp, int *pc, struct value **valp,
   if (resultp)
     *resultp = NULL;
   if (val_chain)
-    *val_chain = NULL;
+    val_chain->clear ();
 
   /* Evaluate the expression.  */
   mark = value_mark ();
@@ -222,6 +215,7 @@ fetch_subexp_value (struct expression *exp, int *pc, struct value **valp,
        case MEMORY_ERROR:
          if (!preserve_errors)
            break;
+         /* Fall through.  */
        default:
          throw_exception (ex);
          break;
@@ -260,8 +254,7 @@ fetch_subexp_value (struct expression *exp, int *pc, struct value **valp,
     {
       /* Return the chain of intermediate values.  We use this to
         decide which addresses to watch.  */
-      *val_chain = new_mark;
-      value_release_to_mark (mark);
+      *val_chain = value_release_to_mark (mark);
     }
 }
 
@@ -272,7 +265,7 @@ fetch_subexp_value (struct expression *exp, int *pc, struct value **valp,
    subexpression of the left-hand-side of the dereference.  This is
    used when completing field names.  */
 
-char *
+const char *
 extract_field_op (struct expression *exp, int *subexp)
 {
   int tem;
@@ -642,18 +635,33 @@ ptrmath_type_p (const struct language_defn *lang, struct type *type)
     }
 }
 
-/* Constructs a fake method with the given parameter types.  This
-   function is used by the parser to construct an "expected" type for
+/* Represents a fake method with the given parameter types.  This is
+   used by the parser to construct a temporary "expected" type for
    method overload resolution.  FLAGS is used as instance flags of the
    new type, in order to be able to make the new type represent a
    const/volatile overload.  */
 
-static struct type *
-make_params (type_instance_flags flags,
-            int num_types, struct type **param_types)
+class fake_method
+{
+public:
+  fake_method (type_instance_flags flags,
+              int num_types, struct type **param_types);
+  ~fake_method ();
+
+  /* The constructed type.  */
+  struct type *type () { return &m_type; }
+
+private:
+  struct type m_type {};
+  main_type m_main_type {};
+};
+
+fake_method::fake_method (type_instance_flags flags,
+                         int num_types, struct type **param_types)
 {
-  struct type *type = XCNEW (struct type);
-  TYPE_MAIN_TYPE (type) = XCNEW (struct main_type);
+  struct type *type = &m_type;
+
+  TYPE_MAIN_TYPE (type) = &m_main_type;
   TYPE_LENGTH (type) = 1;
   TYPE_CODE (type) = TYPE_CODE_METHOD;
   TYPE_CHAIN (type) = type;
@@ -681,13 +689,16 @@ make_params (type_instance_flags flags,
 
   while (num_types-- > 0)
     TYPE_FIELD_TYPE (type, num_types) = param_types[num_types];
+}
 
-  return type;
+fake_method::~fake_method ()
+{
+  xfree (TYPE_FIELDS (&m_type));
 }
 
 /* Helper for evaluating an OP_VAR_VALUE.  */
 
-static value *
+value *
 evaluate_var_value (enum noside noside, const block *blk, symbol *var)
 {
   /* JYG: We used to just return value_zero of the symbol type if
@@ -720,26 +731,22 @@ evaluate_var_value (enum noside noside, const block *blk, symbol *var)
 
 /* Helper for evaluating an OP_VAR_MSYM_VALUE.  */
 
-static value *
+value *
 evaluate_var_msym_value (enum noside noside,
                         struct objfile *objfile, minimal_symbol *msymbol)
 {
-  if (noside == EVAL_AVOID_SIDE_EFFECTS)
-    {
-      type *the_type = find_minsym_type_and_address (msymbol, objfile, NULL);
-      return value_zero (the_type, not_lval);
-    }
+  CORE_ADDR address;
+  type *the_type = find_minsym_type_and_address (msymbol, objfile, &address);
+
+  if (noside == EVAL_AVOID_SIDE_EFFECTS && !TYPE_GNU_IFUNC (the_type))
+    return value_zero (the_type, not_lval);
   else
-    {
-      CORE_ADDR address;
-      type *the_type = find_minsym_type_and_address (msymbol, objfile, &address);
-      return value_at_lazy (the_type, address);
-    }
+    return value_at_lazy (the_type, address);
 }
 
 /* Helper for returning a value when handling EVAL_SKIP.  */
 
-static value *
+value *
 eval_skip_value (expression *exp)
 {
   return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
@@ -787,6 +794,15 @@ eval_call (expression *exp, enum noside noside,
       else if (TYPE_CODE (ftype) == TYPE_CODE_FUNC
               || TYPE_CODE (ftype) == TYPE_CODE_METHOD)
        {
+         if (TYPE_GNU_IFUNC (ftype))
+           {
+             CORE_ADDR address = value_address (argvec[0]);
+             type *resolved_type = find_gnu_ifunc_target_type (address);
+
+             if (resolved_type != NULL)
+               ftype = resolved_type;
+           }
+
          type *return_type = TYPE_TARGET_TYPE (ftype);
 
          if (return_type == NULL)
@@ -1028,13 +1044,13 @@ evaluate_funcall (type *expect_type, expression *exp, int *pos,
        {
          if (op == OP_VAR_MSYM_VALUE)
            {
-             symbol *sym = exp->elts[*pos + 2].symbol;
-             var_func_name = SYMBOL_PRINT_NAME (sym);
+             minimal_symbol *msym = exp->elts[*pos + 2].msymbol;
+             var_func_name = MSYMBOL_PRINT_NAME (msym);
            }
          else if (op == OP_VAR_VALUE)
            {
-             minimal_symbol *msym = exp->elts[*pos + 2].msymbol;
-             var_func_name = MSYMBOL_PRINT_NAME (msym);
+             symbol *sym = exp->elts[*pos + 2].symbol;
+             var_func_name = SYMBOL_PRINT_NAME (sym);
            }
 
          argvec[0] = evaluate_subexp_with_coercion (exp, pos, noside);
@@ -1259,15 +1275,10 @@ evaluate_subexp_standard (struct type *expect_type,
       return value_from_longest (exp->elts[pc + 1].type,
                                 exp->elts[pc + 2].longconst);
 
-    case OP_DOUBLE:
-      (*pos) += 3;
-      return value_from_double (exp->elts[pc + 1].type,
-                               exp->elts[pc + 2].doubleconst);
-
-    case OP_DECFLOAT:
+    case OP_FLOAT:
       (*pos) += 3;
-      return value_from_decfloat (exp->elts[pc + 1].type,
-                                 exp->elts[pc + 2].decfloatconst);
+      return value_from_contents (exp->elts[pc + 1].type,
+                                 exp->elts[pc + 2].floatconst);
 
     case OP_ADL_FUNC:
     case OP_VAR_VALUE:
@@ -1737,7 +1748,7 @@ evaluate_subexp_standard (struct type *expect_type,
            /* 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_target);
+                                                      target_stack);
 
            /* Is it a high_level symbol?  */
            sym = find_pc_function (addr);
@@ -2076,13 +2087,9 @@ evaluate_subexp_standard (struct type *expect_type,
        for (ix = 0; ix < nargs; ++ix)
          arg_types[ix] = exp->elts[pc + 2 + ix + 1].type;
 
-       expect_type = make_params (flags, nargs, arg_types);
+       fake_method expect_type (flags, nargs, arg_types);
        *(pos) += 4 + nargs;
-       arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside);
-       xfree (TYPE_FIELDS (expect_type));
-       xfree (TYPE_MAIN_TYPE (expect_type));
-       xfree (expect_type);
-       return arg1;
+       return evaluate_subexp_standard (expect_type.type (), exp, pos, noside);
       }
 
     case BINOP_CONCAT:
@@ -2661,6 +2668,19 @@ evaluate_subexp_standard (struct type *expect_type,
        }
       return evaluate_subexp_for_sizeof (exp, pos, noside);
 
+    case UNOP_ALIGNOF:
+      {
+       struct type *type
+         = value_type (evaluate_subexp (NULL_TYPE, exp, pos,
+                                        EVAL_AVOID_SIDE_EFFECTS));
+       /* FIXME: This should be size_t.  */
+       struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
+       ULONGEST align = type_align (type);
+       if (align == 0)
+         error (_("could not determine alignment of type"));
+       return value_from_longest (size_type, align);
+      }
+
     case UNOP_CAST:
       (*pos) += 2;
       type = exp->elts[pc + 1].type;
This page took 0.028281 seconds and 4 git commands to generate.