2011-01-05 Michael Snyder <msnyder@vmware.com>
[deliverable/binutils-gdb.git] / gdb / eval.c
index 2c8b01f4d81c7d1ed176d411adea15d2ccbf3f87..8394623d79d6515f9a75d1f4327e665a4609a8b6 100644 (file)
@@ -2,7 +2,7 @@
 
    Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
    1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008,
-   2009, 2010 Free Software Foundation, Inc.
+   2009, 2010, 2011 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -43,6 +43,7 @@
 #include "gdb_obstack.h"
 #include "objfiles.h"
 #include "python/python.h"
+#include "wrapper.h"
 
 #include "gdb_assert.h"
 
@@ -162,6 +163,7 @@ struct value *
 evaluate_expression (struct expression *exp)
 {
   int pc = 0;
+
   return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_NORMAL);
 }
 
@@ -172,6 +174,7 @@ struct value *
 evaluate_type (struct expression *exp)
 {
   int pc = 0;
+
   return evaluate_subexp (NULL_TYPE, exp, &pc, EVAL_AVOID_SIDE_EFFECTS);
 }
 
@@ -184,6 +187,84 @@ evaluate_subexpression_type (struct expression *exp, int subexp)
   return evaluate_subexp (NULL_TYPE, exp, &subexp, EVAL_AVOID_SIDE_EFFECTS);
 }
 
+/* Find the current value of a watchpoint on EXP.  Return the value in
+   *VALP and *RESULTP and the chain of intermediate and final values
+   in *VAL_CHAIN.  RESULTP and VAL_CHAIN may be NULL if the caller does
+   not need them.
+
+   If a memory error occurs while evaluating the expression, *RESULTP will
+   be set to NULL.  *RESULTP may be a lazy value, if the result could
+   not be read from memory.  It is used to determine whether a value
+   is user-specified (we should watch the whole value) or intermediate
+   (we should watch only the bit used to locate the final value).
+
+   If the final value, or any intermediate value, could not be read
+   from memory, *VALP will be set to NULL.  *VAL_CHAIN will still be
+   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.  */
+
+void
+fetch_subexp_value (struct expression *exp, int *pc, struct value **valp,
+                   struct value **resultp, struct value **val_chain)
+{
+  struct value *mark, *new_mark, *result;
+  volatile struct gdb_exception ex;
+
+  *valp = NULL;
+  if (resultp)
+    *resultp = NULL;
+  if (val_chain)
+    *val_chain = NULL;
+
+  /* Evaluate the expression.  */
+  mark = value_mark ();
+  result = NULL;
+
+  TRY_CATCH (ex, RETURN_MASK_ALL)
+    {
+      result = evaluate_subexp (NULL_TYPE, exp, pc, EVAL_NORMAL);
+    }
+  if (ex.reason < 0)
+    {
+      /* Ignore memory errors, we want watchpoints pointing at
+        inaccessible memory to still be created; otherwise, throw the
+        error to some higher catcher.  */
+      switch (ex.error)
+       {
+       case MEMORY_ERROR:
+         break;
+       default:
+         throw_exception (ex);
+         break;
+       }
+    }
+
+  new_mark = value_mark ();
+  if (mark == new_mark)
+    return;
+  if (resultp)
+    *resultp = result;
+
+  /* Make sure it's not lazy, so that after the target stops again we
+     have a non-lazy previous value to compare with.  */
+  if (result != NULL
+      && (!value_lazy (result) || gdb_value_fetch_lazy (result)))
+    *valp = result;
+
+  if (val_chain)
+    {
+      /* Return the chain of intermediate values.  We use this to
+        decide which addresses to watch.  */
+      *val_chain = new_mark;
+      value_release_to_mark (mark);
+    }
+}
+
 /* Extract a field operation from an expression.  If the subexpression
    of EXP starting at *SUBEXP is not a structure dereference
    operation, return NULL.  Otherwise, return the name of the
@@ -196,6 +277,7 @@ extract_field_op (struct expression *exp, int *subexp)
 {
   int tem;
   char *result;
+
   if (exp->elts[*subexp].opcode != STRUCTOP_STRUCT
       && exp->elts[*subexp].opcode != STRUCTOP_PTR)
     return NULL;
@@ -216,6 +298,7 @@ get_label (struct expression *exp, int *pos)
       int pc = (*pos)++;
       char *name = &exp->elts[pc + 2].string;
       int tem = longest_to_int (exp->elts[pc + 1].longconst);
+
       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
       return name;
     }
@@ -237,6 +320,7 @@ evaluate_struct_tuple (struct value *struct_val,
   int fieldno = -1;
   int variantno = -1;
   int subfieldno = -1;
+
   while (--nargs >= 0)
     {
       int pc = *pos;
@@ -252,12 +336,14 @@ evaluate_struct_tuple (struct value *struct_val,
       do
        {
          char *label = get_label (exp, &pc);
+
          if (label)
            {
              for (fieldno = 0; fieldno < TYPE_NFIELDS (struct_type);
                   fieldno++)
                {
                  char *field_name = TYPE_FIELD_NAME (struct_type, fieldno);
+
                  if (field_name != NULL && strcmp (field_name, label) == 0)
                    {
                      variantno = -1;
@@ -270,6 +356,7 @@ evaluate_struct_tuple (struct value *struct_val,
                   fieldno++)
                {
                  char *field_name = TYPE_FIELD_NAME (struct_type, fieldno);
+
                  field_type = TYPE_FIELD_TYPE (struct_type, fieldno);
                  if ((field_name == 0 || *field_name == '\0')
                      && TYPE_CODE (field_type) == TYPE_CODE_UNION)
@@ -381,6 +468,7 @@ init_array_element (struct value *array, struct value *element,
 {
   LONGEST index;
   int element_size = TYPE_LENGTH (value_type (element));
+
   if (exp->elts[*pos].opcode == BINOP_COMMA)
     {
       (*pos)++;
@@ -392,6 +480,7 @@ init_array_element (struct value *array, struct value *element,
   else if (exp->elts[*pos].opcode == BINOP_RANGE)
     {
       LONGEST low, high;
+
       (*pos)++;
       low = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
       high = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
@@ -464,6 +553,7 @@ unop_promote (const struct language_defn *language, struct gdbarch *gdbarch,
             it needs to modify this function.  */
          {
            struct type *builtin_int = builtin_type (gdbarch)->builtin_int;
+
            if (TYPE_LENGTH (type1) < TYPE_LENGTH (builtin_int))
              *arg1 = value_cast (builtin_int, *arg1);
          }
@@ -513,6 +603,7 @@ binop_promote (const struct language_defn *language, struct gdbarch *gdbarch,
        case language_cplus:
        case language_asm:
        case language_objc:
+       case language_opencl:
          /* No promotion required.  */
          break;
 
@@ -600,7 +691,24 @@ binop_promote (const struct language_defn *language, struct gdbarch *gdbarch,
                               : builtin->builtin_long_long);
            }
          break;
-
+       case language_opencl:
+         if (result_len <= TYPE_LENGTH (lookup_signed_typename
+                                        (language, gdbarch, "int")))
+           {
+             promoted_type =
+               (unsigned_operation
+                ? lookup_unsigned_typename (language, gdbarch, "int")
+                : lookup_signed_typename (language, gdbarch, "int"));
+           }
+         else if (result_len <= TYPE_LENGTH (lookup_signed_typename
+                                             (language, gdbarch, "long")))
+           {
+             promoted_type =
+               (unsigned_operation
+                ? lookup_unsigned_typename (language, gdbarch, "long")
+                : lookup_signed_typename (language, gdbarch,"long"));
+           }
+         break;
        default:
          /* For other languages the result type is unchanged from gdb
             version 6.7 for backward compatibility.
@@ -646,7 +754,7 @@ ptrmath_type_p (const struct language_defn *lang, struct type *type)
       return 1;
 
     case TYPE_CODE_ARRAY:
-      return lang->c_style_arrays;
+      return TYPE_VECTOR (type) ? 0 : lang->c_style_arrays;
 
     default:
       return 0;
@@ -759,7 +867,8 @@ evaluate_subexp_standard (struct type *expect_type,
        if (except.reason < 0)
          {
            if (noside == EVAL_AVOID_SIDE_EFFECTS)
-             ret = value_zero (SYMBOL_TYPE (exp->elts[pc + 2].symbol), not_lval);
+             ret = value_zero (SYMBOL_TYPE (exp->elts[pc + 2].symbol),
+                               not_lval);
            else
              throw_exception (except);
          }
@@ -818,7 +927,8 @@ evaluate_subexp_standard (struct type *expect_type,
       type = language_string_char_type (exp->language_defn, exp->gdbarch);
       return value_string (&exp->elts[pc + 2].string, tem, type);
 
-    case OP_OBJC_NSSTRING:             /* Objective C Foundation Class NSString constant.  */
+    case OP_OBJC_NSSTRING:             /* Objective C Foundation Class
+                                          NSString constant.  */
       tem = longest_to_int (exp->elts[pc + 1].longconst);
       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
       if (noside == EVAL_SKIP)
@@ -848,6 +958,7 @@ evaluate_subexp_standard (struct type *expect_type,
          && TYPE_CODE (type) == TYPE_CODE_STRUCT)
        {
          struct value *rec = allocate_value (expect_type);
+
          memset (value_contents_raw (rec), '\0', TYPE_LENGTH (type));
          return evaluate_struct_tuple (rec, exp, pos, noside, nargs);
        }
@@ -860,6 +971,7 @@ evaluate_subexp_standard (struct type *expect_type,
          struct value *array = allocate_value (expect_type);
          int element_size = TYPE_LENGTH (check_typedef (element_type));
          LONGEST low_bound, high_bound, index;
+
          if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
            {
              low_bound = 0;
@@ -871,6 +983,7 @@ evaluate_subexp_standard (struct type *expect_type,
            {
              struct value *element;
              int index_pc = 0;
+
              if (exp->elts[*pos].opcode == BINOP_RANGE)
                {
                  index_pc = ++(*pos);
@@ -882,6 +995,7 @@ evaluate_subexp_standard (struct type *expect_type,
              if (index_pc)
                {
                  int continue_pc = *pos;
+
                  *pos = index_pc;
                  index = init_array_element (array, element, exp, pos, noside,
                                              low_bound, high_bound);
@@ -924,6 +1038,7 @@ evaluate_subexp_standard (struct type *expect_type,
              LONGEST range_low, range_high;
              struct type *range_low_type, *range_high_type;
              struct value *elem_val;
+
              if (exp->elts[*pos].opcode == BINOP_RANGE)
                {
                  (*pos)++;
@@ -968,6 +1083,7 @@ evaluate_subexp_standard (struct type *expect_type,
              for (; range_low <= range_high; range_low++)
                {
                  int bit_index = (unsigned) range_low % TARGET_CHAR_BIT;
+
                  if (gdbarch_bits_big_endian (exp->gdbarch))
                    bit_index = TARGET_CHAR_BIT - 1 - bit_index;
                  valaddr[(unsigned) range_low / TARGET_CHAR_BIT]
@@ -991,9 +1107,10 @@ evaluate_subexp_standard (struct type *expect_type,
       {
        struct value *array = evaluate_subexp (NULL_TYPE, exp, pos, noside);
        int lowbound
-       = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+         = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
        int upper
-       = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+         = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+
        if (noside == EVAL_SKIP)
          goto nosideret;
        return value_slice (array, lowbound, upper - lowbound + 1);
@@ -1003,9 +1120,10 @@ evaluate_subexp_standard (struct type *expect_type,
       {
        struct value *array = evaluate_subexp (NULL_TYPE, exp, pos, noside);
        int lowbound
-       = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+         = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
        int length
-       = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+         = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+
        return value_slice (array, lowbound, length);
       }
 
@@ -1101,6 +1219,7 @@ evaluate_subexp_standard (struct type *expect_type,
        if (gnu_runtime)
          {
            struct type *type = selector_type;
+
            type = lookup_function_type (type);
            type = lookup_pointer_type (type);
            type = lookup_function_type (type);
@@ -1224,7 +1343,8 @@ evaluate_subexp_standard (struct type *expect_type,
              }
 
            struct_return = using_struct_return (exp->gdbarch,
-                                                value_type (method), val_type);
+                                                value_type (method),
+                                                val_type);
          }
        else if (expect_type != NULL)
          {
@@ -1248,12 +1368,14 @@ evaluate_subexp_standard (struct type *expect_type,
        if (method)
          {
            if (TYPE_CODE (value_type (method)) != TYPE_CODE_FUNC)
-             error (_("method address has symbol information with non-function type; skipping"));
-
-           /* Create a function pointer of the appropriate type, and replace
-              its value with the value of msg_send or msg_send_stret.  We must
-              use a pointer here, as msg_send and msg_send_stret are of pointer
-              type, and the representation may be different on systems that use
+             error (_("method address has symbol information "
+                      "with non-function type; skipping"));
+
+           /* Create a function pointer of the appropriate type, and
+              replace its value with the value of msg_send or
+              msg_send_stret.  We must use a pointer here, as
+              msg_send and msg_send_stret are of pointer type, and
+              the representation may be different on systems that use
               function descriptors.  */
            if (struct_return)
              called_method
@@ -1286,6 +1408,7 @@ evaluate_subexp_standard (struct type *expect_type,
               it. */
 
            struct type *type = value_type (called_method);
+
            if (type && TYPE_CODE (type) == TYPE_CODE_PTR)
              type = TYPE_TARGET_TYPE (type);
            type = TYPE_TARGET_TYPE (type);
@@ -1298,7 +1421,8 @@ evaluate_subexp_standard (struct type *expect_type,
                return allocate_value (type);
            }
            else
-             error (_("Expression of type other than \"method returning ...\" used as a method"));
+             error (_("Expression of type other than "
+                      "\"method returning ...\" used as a method"));
          }
 
        /* Now depending on whether we found a symbol for the method,
@@ -1318,7 +1442,8 @@ evaluate_subexp_standard (struct type *expect_type,
            /* Function objc_msg_lookup returns a pointer.  */
            deprecated_set_value_type (argvec[0],
                                       lookup_pointer_type (lookup_function_type (value_type (argvec[0]))));
-           argvec[0] = call_function_by_hand (argvec[0], nargs + 2, argvec + 1);
+           argvec[0]
+             = call_function_by_hand (argvec[0], nargs + 2, argvec + 1);
          }
 
        ret = call_function_by_hand (argvec[0], nargs + 2, argvec + 1);
@@ -1332,7 +1457,8 @@ evaluate_subexp_standard (struct type *expect_type,
       nargs = longest_to_int (exp->elts[pc + 1].longconst);
       /* Allocate arg vector, including space for the function to be
          called in argvec[0] and a terminating NULL */
-      argvec = (struct value **) alloca (sizeof (struct value *) * (nargs + 3));
+      argvec = (struct value **)
+       alloca (sizeof (struct value *) * (nargs + 3));
       if (op == STRUCTOP_MEMBER || op == STRUCTOP_MPTR)
        {
          nargs++;
@@ -1367,6 +1493,7 @@ evaluate_subexp_standard (struct type *expect_type,
          if (noside == EVAL_AVOID_SIDE_EFFECTS)
            {
              struct type *method_type = check_typedef (value_type (arg1));
+
              arg1 = value_zero (method_type, not_lval);
            }
          else
@@ -1409,6 +1536,29 @@ evaluate_subexp_standard (struct type *expect_type,
          else
            {
              arg2 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
+
+             /* Check to see if the operator '->' has been
+                overloaded.  If the operator has been overloaded
+                replace arg2 with the value returned by the custom
+                operator and continue evaluation.  */
+             while (unop_user_defined_p (op, arg2))
+               {
+                 volatile struct gdb_exception except;
+                 struct value *value = NULL;
+                 TRY_CATCH (except, RETURN_MASK_ERROR)
+                   {
+                     value = value_x_unop (arg2, op, noside);
+                   }
+
+                 if (except.reason < 0)
+                   {
+                     if (except.error == NOT_FOUND_ERROR)
+                       break;
+                     else
+                       throw_exception (except);
+                   }
+                 arg2 = value;
+               }
            }
          /* Now, say which argument to start evaluating from */
          tem = 2;
@@ -1458,6 +1608,7 @@ evaluate_subexp_standard (struct type *expect_type,
           /* Save the function position and move pos so that the arguments
              can be evaluated.  */
           int func_name_len;
+
           save_pos1 = *pos;
           tem = 1;
 
@@ -1468,19 +1619,30 @@ evaluate_subexp_standard (struct type *expect_type,
        {
          /* Non-method function call */
          save_pos1 = *pos;
-         argvec[0] = evaluate_subexp_with_coercion (exp, pos, noside);
          tem = 1;
-         type = value_type (argvec[0]);
-         if (type && TYPE_CODE (type) == TYPE_CODE_PTR)
-           type = TYPE_TARGET_TYPE (type);
-         if (type && TYPE_CODE (type) == TYPE_CODE_FUNC)
+
+         /* If this is a C++ function wait until overload resolution.  */
+         if (op == OP_VAR_VALUE
+             && overload_resolution
+             && (exp->language_defn->la_language == language_cplus))
            {
-             for (; tem <= nargs && tem <= TYPE_NFIELDS (type); tem++)
+             (*pos) += 4; /* Skip the evaluation of the symbol.  */
+             argvec[0] = NULL;
+           }
+         else
+           {
+             argvec[0] = evaluate_subexp_with_coercion (exp, pos, noside);
+             type = value_type (argvec[0]);
+             if (type && TYPE_CODE (type) == TYPE_CODE_PTR)
+               type = TYPE_TARGET_TYPE (type);
+             if (type && TYPE_CODE (type) == TYPE_CODE_FUNC)
                {
-                 /* pai: FIXME This seems to be coercing arguments before
-                  * overload resolution has been done! */
-                 argvec[tem] = evaluate_subexp (TYPE_FIELD_TYPE (type, tem - 1),
-                                                exp, pos, noside);
+                 for (; tem <= nargs && tem <= TYPE_NFIELDS (type); tem++)
+                   {
+                     argvec[tem] = evaluate_subexp (TYPE_FIELD_TYPE (type,
+                                                                     tem - 1),
+                                                    exp, pos, noside);
+                   }
                }
            }
        }
@@ -1507,13 +1669,16 @@ evaluate_subexp_standard (struct type *expect_type,
           strcpy (func_name, &exp->elts[string_pc + 1].string);
 
           /* Prepare list of argument types for overload resolution */
-          arg_types = (struct type **) alloca (nargs * (sizeof (struct type *)));
+          arg_types = (struct type **)
+           alloca (nargs * (sizeof (struct type *)));
           for (ix = 1; ix <= nargs; ix++)
             arg_types[ix - 1] = value_type (argvec[ix]);
 
           find_overload_match (arg_types, nargs, func_name,
-                               0 /* not method */ , 0 /* strict match */ ,
-                               NULL, NULL /* pass NULL symbol since symbol is unknown */ ,
+                               NON_METHOD, /* not method */
+                              0,          /* strict match */
+                               NULL, NULL, /* pass NULL symbol since
+                                             symbol is unknown */
                                NULL, &symp, NULL, 0);
 
           /* Now fix the expression being evaluated.  */
@@ -1538,20 +1703,25 @@ evaluate_subexp_standard (struct type *expect_type,
          else
            tstr = function_name;
 
-         if (overload_resolution && (exp->language_defn->la_language == language_cplus))
+         if (overload_resolution && (exp->language_defn->la_language
+                                     == language_cplus))
            {
-             /* Language is C++, do some overload resolution before evaluation */
+             /* Language is C++, do some overload resolution before
+                evaluation */
              struct value *valp = NULL;
 
              /* Prepare list of argument types for overload resolution */
-             arg_types = (struct type **) alloca (nargs * (sizeof (struct type *)));
+             arg_types = (struct type **)
+               alloca (nargs * (sizeof (struct type *)));
              for (ix = 1; ix <= nargs; ix++)
                arg_types[ix - 1] = value_type (argvec[ix]);
 
              (void) find_overload_match (arg_types, nargs, tstr,
-                                    1 /* method */ , 0 /* strict match */ ,
-                                         &arg2 /* the object */ , NULL,
-                                         &valp, NULL, &static_memfuncp, 0);
+                                         METHOD, /* method */
+                                         0,      /* strict match */
+                                         &arg2,  /* the object */
+                                         NULL, &valp, NULL,
+                                         &static_memfuncp, 0);
 
              if (op == OP_SCOPE && !static_memfuncp)
                {
@@ -1561,12 +1731,14 @@ evaluate_subexp_standard (struct type *expect_type,
                         function_name);
                }
              argvec[1] = arg2; /* the ``this'' pointer */
-             argvec[0] = valp; /* use the method found after overload resolution */
+             argvec[0] = valp; /* use the method found after overload
+                                  resolution */
            }
          else
            /* Non-C++ case -- or no overload resolution */
            {
              struct value *temp = arg2;
+
              argvec[0] = value_struct_elt (&temp, argvec + 1, tstr,
                                            &static_memfuncp,
                                            op == STRUCTOP_STRUCT
@@ -1574,9 +1746,10 @@ evaluate_subexp_standard (struct type *expect_type,
              /* value_struct_elt updates temp with the correct value
                 of the ``this'' pointer if necessary, so modify argvec[1] to
                 reflect any ``this'' changes.  */
-             arg2 = value_from_longest (lookup_pointer_type(value_type (temp)),
-                                        value_address (temp)
-                                        + value_embedded_offset (temp));
+             arg2
+               = value_from_longest (lookup_pointer_type(value_type (temp)),
+                                     value_address (temp)
+                                     + value_embedded_offset (temp));
              argvec[1] = arg2; /* the ``this'' pointer */
            }
 
@@ -1599,9 +1772,11 @@ evaluate_subexp_standard (struct type *expect_type,
              in a C++ program, for instance, does not have the fields that 
              are expected here */
 
-         if (overload_resolution && (exp->language_defn->la_language == language_cplus))
+         if (overload_resolution && (exp->language_defn->la_language
+                                     == language_cplus))
            {
-             /* Language is C++, do some overload resolution before evaluation */
+             /* Language is C++, do some overload resolution before
+                evaluation */
              struct symbol *symp;
              int no_adl = 0;
 
@@ -1613,13 +1788,16 @@ evaluate_subexp_standard (struct type *expect_type,
                function = exp->elts[save_pos1+2].symbol;
 
              /* Prepare list of argument types for overload resolution */
-             arg_types = (struct type **) alloca (nargs * (sizeof (struct type *)));
+             arg_types = (struct type **)
+               alloca (nargs * (sizeof (struct type *)));
              for (ix = 1; ix <= nargs; ix++)
                arg_types[ix - 1] = value_type (argvec[ix]);
 
-             (void) find_overload_match (arg_types, nargs, NULL /* no need for name */ ,
-                                0 /* not method */ , 0 /* strict match */ ,
-                     NULL, function /* the function */ ,
+             (void) find_overload_match (arg_types, nargs,
+                                         NULL,        /* no need for name */
+                                         NON_METHOD,  /* not method */
+                                         0,           /* strict match */
+                                         NULL, function, /* the function */
                                          NULL, &symp, NULL, no_adl);
 
              if (op == OP_VAR_VALUE)
@@ -1672,14 +1850,16 @@ evaluate_subexp_standard (struct type *expect_type,
          else if (TYPE_TARGET_TYPE (ftype))
            return allocate_value (TYPE_TARGET_TYPE (ftype));
          else
-           error (_("Expression of type other than \"Function returning ...\" used as function"));
+           error (_("Expression of type other than "
+                    "\"Function returning ...\" used as function"));
        }
       if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_INTERNAL_FUNCTION)
        return call_internal_function (exp->gdbarch, exp->language_defn,
                                       argvec[0], nargs, argvec + 1);
 
       return call_function_by_hand (argvec[0], nargs, argvec + 1);
-      /* pai: FIXME save value from call_function_by_hand, then adjust pc by adjust_fn_pc if +ve  */
+      /* pai: FIXME save value from call_function_by_hand, then adjust
+        pc by adjust_fn_pc if +ve.  */
 
     case OP_F77_UNDETERMINED_ARGLIST:
 
@@ -1738,7 +1918,8 @@ evaluate_subexp_standard (struct type *expect_type,
          /* It's a function call. */
          /* Allocate arg vector, including space for the function to be
             called in argvec[0] and a terminating NULL */
-         argvec = (struct value **) alloca (sizeof (struct value *) * (nargs + 2));
+         argvec = (struct value **)
+           alloca (sizeof (struct value *) * (nargs + 2));
          argvec[0] = arg1;
          tem = 1;
          for (; tem <= nargs; tem++)
@@ -1773,6 +1954,7 @@ evaluate_subexp_standard (struct type *expect_type,
       else
        {
          struct value *temp = arg1;
+
          return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string,
                                   NULL, "structure");
        }
@@ -1784,6 +1966,27 @@ evaluate_subexp_standard (struct type *expect_type,
       if (noside == EVAL_SKIP)
        goto nosideret;
 
+      /* Check to see if operator '->' has been overloaded.  If so replace
+         arg1 with the value returned by evaluating operator->().  */
+      while (unop_user_defined_p (op, arg1))
+       {
+         volatile struct gdb_exception except;
+         struct value *value = NULL;
+         TRY_CATCH (except, RETURN_MASK_ERROR)
+           {
+             value = value_x_unop (arg1, op, noside);
+           }
+
+         if (except.reason < 0)
+           {
+             if (except.error == NOT_FOUND_ERROR)
+               break;
+             else
+               throw_exception (except);
+           }
+         arg1 = value;
+       }
+
       /* JYG: if print object is on we need to replace the base type
         with rtti type in order to continue on with successful
         lookup of member / method only available in the rtti type. */
@@ -1818,6 +2021,7 @@ evaluate_subexp_standard (struct type *expect_type,
       else
        {
          struct value *temp = arg1;
+
          return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string,
                                   NULL, "structure pointer");
        }
@@ -1859,7 +2063,8 @@ evaluate_subexp_standard (struct type *expect_type,
          return value_ind (arg3);
 
        default:
-         error (_("non-pointer-to-member value used in pointer-to-member construct"));
+         error (_("non-pointer-to-member value used "
+                  "in pointer-to-member construct"));
        }
 
     case TYPE_INSTANCE:
@@ -2456,7 +2661,8 @@ evaluate_subexp_standard (struct type *expect_type,
       type = check_typedef (value_type (arg1));
       if (TYPE_CODE (type) == TYPE_CODE_METHODPTR
          || TYPE_CODE (type) == TYPE_CODE_MEMBERPTR)
-       error (_("Attempt to dereference pointer to member without an object"));
+       error (_("Attempt to dereference pointer "
+                "to member without an object"));
       if (noside == EVAL_SKIP)
        goto nosideret;
       if (unop_user_defined_p (op, arg1))
@@ -2500,7 +2706,9 @@ evaluate_subexp_standard (struct type *expect_type,
        }
       else
        {
-         struct value *retvalp = evaluate_subexp_for_address (exp, pos, noside);
+         struct value *retvalp = evaluate_subexp_for_address (exp, pos,
+                                                              noside);
+
          return retvalp;
        }
 
@@ -2559,6 +2767,7 @@ evaluate_subexp_standard (struct type *expect_type,
       else
        {
          CORE_ADDR tls_addr;
+
          tls_addr = target_translate_tls_address (exp->elts[pc + 1].objfile,
                                                   value_as_address (arg1));
          return value_at_lazy (exp->elts[pc + 2].type, tls_addr);
@@ -2579,6 +2788,7 @@ evaluate_subexp_standard (struct type *expect_type,
          else
            {
              struct value *tmp = arg1;
+
              arg2 = value_one (value_type (arg1), not_lval);
              binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
              arg2 = value_binop (tmp, arg2, BINOP_ADD);
@@ -2602,6 +2812,7 @@ evaluate_subexp_standard (struct type *expect_type,
          else
            {
              struct value *tmp = arg1;
+
              arg2 = value_one (value_type (arg1), not_lval);
              binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
              arg2 = value_binop (tmp, arg2, BINOP_SUB);
@@ -2620,18 +2831,21 @@ evaluate_subexp_standard (struct type *expect_type,
        }
       else
        {
+         arg3 = value_non_lval (arg1);
+
          if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
            arg2 = value_ptradd (arg1, 1);
          else
            {
              struct value *tmp = arg1;
+
              arg2 = value_one (value_type (arg1), not_lval);
              binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
              arg2 = value_binop (tmp, arg2, BINOP_ADD);
            }
 
          value_assign (arg1, arg2);
-         return arg1;
+         return arg3;
        }
 
     case UNOP_POSTDECREMENT:
@@ -2644,18 +2858,21 @@ evaluate_subexp_standard (struct type *expect_type,
        }
       else
        {
+         arg3 = value_non_lval (arg1);
+
          if (ptrmath_type_p (exp->language_defn, value_type (arg1)))
            arg2 = value_ptradd (arg1, -1);
          else
            {
              struct value *tmp = arg1;
+
              arg2 = value_one (value_type (arg1), not_lval);
              binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
              arg2 = value_binop (tmp, arg2, BINOP_SUB);
            }
 
          value_assign (arg1, arg2);
-         return arg1;
+         return arg3;
        }
 
     case OP_THIS:
@@ -2675,6 +2892,7 @@ evaluate_subexp_standard (struct type *expect_type,
       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
        {
          struct type *type = exp->elts[pc + 1].type;
+
          /* If this is a typedef, then find its immediate target.  We
             use check_typedef to resolve stubs, but we ignore its
             result because we do not want to dig past all
@@ -2697,8 +2915,8 @@ evaluate_subexp_standard (struct type *expect_type,
          then they should be separate cases, with more descriptive
          error messages.  */
 
-      error (_("\
-GDB does not (yet) know how to evaluate that kind of expression"));
+      error (_("GDB does not (yet) know how to "
+              "evaluate that kind of expression"));
     }
 
 nosideret:
@@ -2757,7 +2975,7 @@ evaluate_subexp_for_address (struct expression *exp, int *pos,
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
        {
          struct type *type =
-         lookup_pointer_type (SYMBOL_TYPE (var));
+           lookup_pointer_type (SYMBOL_TYPE (var));
          enum address_class sym_class = SYMBOL_CLASS (var);
 
          if (sym_class == LOC_CONST
@@ -2796,7 +3014,8 @@ evaluate_subexp_for_address (struct expression *exp, int *pos,
            return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
                               not_lval);
          else
-           error (_("Attempt to take address of value not located in memory."));
+           error (_("Attempt to take address of "
+                    "value not located in memory."));
        }
       return value_addr (x);
     }
@@ -2834,6 +3053,7 @@ evaluate_subexp_with_coercion (struct expression *exp,
       var = exp->elts[pc + 2].symbol;
       type = check_typedef (SYMBOL_TYPE (var));
       if (TYPE_CODE (type) == TYPE_CODE_ARRAY
+         && !TYPE_VECTOR (type)
          && CAST_IS_CONVERSION (exp->language_defn))
        {
          (*pos) += 4;
@@ -2907,6 +3127,7 @@ parse_and_eval_type (char *p, int length)
 {
   char *tmp = (char *) alloca (length + 4);
   struct expression *expr;
+
   tmp[0] = '(';
   memcpy (tmp + 1, p, length);
   tmp[length + 1] = ')';
This page took 0.036164 seconds and 4 git commands to generate.