* gdbtypes.c (create_string_type): Receive character type as argument.
[deliverable/binutils-gdb.git] / gdb / eval.c
index f42ccefe3795620e3571f9501add87dd0a7952be..df730057d80edc8b63f7b15366375dc35c83d5ae 100644 (file)
@@ -1,8 +1,8 @@
 /* Evaluate expressions for GDB.
 
    Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008
-   Free Software Foundation, Inc.
+   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008,
+   2009 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "exceptions.h"
 #include "regcache.h"
 #include "user-regs.h"
+#include "valprint.h"
+#include "python/python.h"
 
 #include "gdb_assert.h"
 
+#include <ctype.h>
+
 /* This is defined in valops.c */
 extern int overload_resolution;
 
-/* JYG: lookup rtti type of STRUCTOP_PTR when this is set to continue
-   on with successful lookup for member/method of the rtti type. */
-extern int objectprint;
-
 /* Prototypes for local functions. */
 
 static struct value *evaluate_subexp_for_sizeof (struct expression *, int *);
@@ -319,7 +319,8 @@ evaluate_struct_tuple (struct value *struct_val,
                  fieldno++;
                  /* Skip static fields.  */
                  while (fieldno < TYPE_NFIELDS (struct_type)
-                        && TYPE_FIELD_STATIC_KIND (struct_type, fieldno))
+                        && field_is_static (&TYPE_FIELD (struct_type,
+                                                         fieldno)))
                    fieldno++;
                  subfieldno = fieldno;
                  if (fieldno >= TYPE_NFIELDS (struct_type))
@@ -415,7 +416,7 @@ init_array_element (struct value *array, struct value *element,
   return index;
 }
 
-struct value *
+static struct value *
 value_f90_subarray (struct value *array,
                    struct expression *exp, int *pos, enum noside noside)
 {
@@ -753,7 +754,7 @@ evaluate_subexp_standard (struct type *expect_type,
        struct value *val;
 
        (*pos) += 3 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
-       regno = user_reg_map_name_to_regnum (current_gdbarch,
+       regno = user_reg_map_name_to_regnum (exp->gdbarch,
                                             name, strlen (name));
        if (regno == -1)
          error (_("Register $%s not available."), name);
@@ -764,9 +765,9 @@ evaluate_subexp_standard (struct type *expect_type,
            So for these registers, we fetch the register value regardless
            of the evaluation mode.  */
        if (noside == EVAL_AVOID_SIDE_EFFECTS
-           && regno < gdbarch_num_regs (current_gdbarch)
-              + gdbarch_num_pseudo_regs (current_gdbarch))
-         val = value_zero (register_type (current_gdbarch, regno), not_lval);
+           && regno < gdbarch_num_regs (exp->gdbarch)
+                       + gdbarch_num_pseudo_regs (exp->gdbarch))
+         val = value_zero (register_type (exp->gdbarch, regno), not_lval);
        else
          val = value_of_register (regno, get_selected_frame (NULL));
        if (val == NULL)
@@ -788,7 +789,8 @@ evaluate_subexp_standard (struct type *expect_type,
       (*pos) += 3 + BYTES_TO_EXP_ELEM (tem + 1);
       if (noside == EVAL_SKIP)
        goto nosideret;
-      return value_string (&exp->elts[pc + 2].string, tem);
+      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.  */
       tem = longest_to_int (exp->elts[pc + 1].longconst);
@@ -797,7 +799,7 @@ evaluate_subexp_standard (struct type *expect_type,
        {
          goto nosideret;
        }
-      return (struct value *) value_nsstring (&exp->elts[pc + 2].string, tem + 1);
+      return value_nsstring (exp->gdbarch, &exp->elts[pc + 2].string, tem + 1);
 
     case OP_BITSTRING:
       tem = longest_to_int (exp->elts[pc + 1].longconst);
@@ -826,7 +828,7 @@ evaluate_subexp_standard (struct type *expect_type,
       if (expect_type != NULL_TYPE && noside != EVAL_SKIP
          && TYPE_CODE (type) == TYPE_CODE_ARRAY)
        {
-         struct type *range_type = TYPE_FIELD_TYPE (type, 0);
+         struct type *range_type = TYPE_INDEX_TYPE (type);
          struct type *element_type = TYPE_TARGET_TYPE (type);
          struct value *array = allocate_value (expect_type);
          int element_size = TYPE_LENGTH (check_typedef (element_type));
@@ -1009,23 +1011,24 @@ evaluate_subexp_standard (struct type *expect_type,
          sel[len] = 0;         /* Make sure it's terminated.  */
 
        selector_type = builtin_type (exp->gdbarch)->builtin_data_ptr;
-       return value_from_longest (selector_type, lookup_child_selector (sel));
+       return value_from_longest (selector_type,
+                                  lookup_child_selector (exp->gdbarch, sel));
       }
 
     case OP_OBJC_MSGCALL:
       {                                /* Objective C message (method) call.  */
 
-       static CORE_ADDR responds_selector = 0;
-       static CORE_ADDR method_selector = 0;
+       CORE_ADDR responds_selector = 0;
+       CORE_ADDR method_selector = 0;
 
        CORE_ADDR selector = 0;
 
        int struct_return = 0;
        int sub_no_side = 0;
 
-       static struct value *msg_send = NULL;
-       static struct value *msg_send_stret = NULL;
-       static int gnu_runtime = 0;
+       struct value *msg_send = NULL;
+       struct value *msg_send_stret = NULL;
+       int gnu_runtime = 0;
 
        struct value *target = NULL;
        struct value *method = NULL;
@@ -1097,16 +1100,20 @@ evaluate_subexp_standard (struct type *expect_type,
           the verification method than the non-standard, but more
           often used, 'NSObject' class. Make sure we check for both. */
 
-       responds_selector = lookup_child_selector ("respondsToSelector:");
+       responds_selector
+         = lookup_child_selector (exp->gdbarch, "respondsToSelector:");
        if (responds_selector == 0)
-         responds_selector = lookup_child_selector ("respondsTo:");
+         responds_selector
+           = lookup_child_selector (exp->gdbarch, "respondsTo:");
        
        if (responds_selector == 0)
          error (_("no 'respondsTo:' or 'respondsToSelector:' method"));
        
-       method_selector = lookup_child_selector ("methodForSelector:");
+       method_selector
+         = lookup_child_selector (exp->gdbarch, "methodForSelector:");
        if (method_selector == 0)
-         method_selector = lookup_child_selector ("methodFor:");
+         method_selector
+           = lookup_child_selector (exp->gdbarch, "methodFor:");
        
        if (method_selector == 0)
          error (_("no 'methodFor:' or 'methodForSelector:' method"));
@@ -1184,11 +1191,12 @@ evaluate_subexp_standard (struct type *expect_type,
                  val_type = expect_type;
              }
 
-           struct_return = using_struct_return (value_type (method), val_type);
+           struct_return = using_struct_return (exp->gdbarch,
+                                                value_type (method), val_type);
          }
        else if (expect_type != NULL)
          {
-           struct_return = using_struct_return (NULL,
+           struct_return = using_struct_return (exp->gdbarch, NULL,
                                                 check_typedef (expect_type));
          }
        
@@ -1210,9 +1218,9 @@ evaluate_subexp_standard (struct type *expect_type,
            if (TYPE_CODE (value_type (method)) != TYPE_CODE_FUNC)
              error (_("method address has symbol information with non-function type; skipping"));
            if (struct_return)
-             VALUE_ADDRESS (method) = value_as_address (msg_send_stret);
+             set_value_address (method, value_as_address (msg_send_stret));
            else
-             VALUE_ADDRESS (method) = value_as_address (msg_send);
+             set_value_address (method, value_as_address (msg_send));
            called_method = method;
          }
        else
@@ -1436,7 +1444,7 @@ evaluate_subexp_standard (struct type *expect_type,
                 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_offset (temp)
+                                        value_address (temp)
                                         + value_embedded_offset (temp));
              argvec[1] = arg2; /* the ``this'' pointer */
            }
@@ -1514,6 +1522,9 @@ evaluate_subexp_standard (struct type *expect_type,
          else
            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 (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  */
 
@@ -1627,8 +1638,10 @@ evaluate_subexp_standard (struct type *expect_type,
         struct type *type = value_type (arg1);
         struct type *real_type;
         int full, top, using_enc;
-        
-        if (objectprint && TYPE_TARGET_TYPE(type) &&
+       struct value_print_options opts;
+
+       get_user_print_options (&opts);
+        if (opts.objectprint && TYPE_TARGET_TYPE(type) &&
             (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
           {
             real_type = value_rtti_target_type (arg1, &full, &top, &using_enc);
@@ -1976,6 +1989,8 @@ evaluate_subexp_standard (struct type *expect_type,
        if (nargs != ndimensions)
          error (_("Wrong number of subscripts"));
 
+       gdb_assert (nargs > 0);
+
        /* Now that we know we have a legal array subscript expression 
           let us actually find out where this element exists in the array. */
 
@@ -2473,7 +2488,17 @@ evaluate_subexp_standard (struct type *expect_type,
       if (noside == EVAL_SKIP)
         goto nosideret;
       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
-        return allocate_value (exp->elts[pc + 1].type);
+       {
+         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
+            typedefs.  */
+         check_typedef (type);
+         if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+           type = TYPE_TARGET_TYPE (type);
+         return allocate_value (type);
+       }
       else
         error (_("Attempt to use a type name as an expression"));
 
@@ -2558,13 +2583,8 @@ evaluate_subexp_for_address (struct expression *exp, int *pos,
          return
            value_zero (type, not_lval);
        }
-      else if (symbol_read_needs_frame (var))
-       return
-         locate_var_value
-         (var,
-          block_innermost_frame (exp->elts[pc + 1].block));
       else
-       return locate_var_value (var, NULL);
+       return address_of_variable (var, exp->elts[pc + 1].block);
 
     case OP_SCOPE:
       tem = longest_to_int (exp->elts[pc + 2].longconst);
@@ -2618,6 +2638,7 @@ evaluate_subexp_with_coercion (struct expression *exp,
   int pc;
   struct value *val;
   struct symbol *var;
+  struct type *type;
 
   pc = (*pos);
   op = exp->elts[pc].opcode;
@@ -2626,14 +2647,13 @@ evaluate_subexp_with_coercion (struct expression *exp,
     {
     case OP_VAR_VALUE:
       var = exp->elts[pc + 2].symbol;
-      if (TYPE_CODE (check_typedef (SYMBOL_TYPE (var))) == TYPE_CODE_ARRAY
+      type = check_typedef (SYMBOL_TYPE (var));
+      if (TYPE_CODE (type) == TYPE_CODE_ARRAY
          && CAST_IS_CONVERSION)
        {
          (*pos) += 4;
-         val =
-           locate_var_value
-           (var, block_innermost_frame (exp->elts[pc + 1].block));
-         return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (check_typedef (SYMBOL_TYPE (var)))),
+         val = address_of_variable (var, exp->elts[pc + 1].block);
+         return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
                             val);
        }
       /* FALLTHROUGH */
This page took 0.02889 seconds and 4 git commands to generate.