Fix powerpc-power8.exp test with new mnemonics
[deliverable/binutils-gdb.git] / gdb / ada-lang.c
index db7eba377cf37a9be1835ae17dfd5f1a525ede09..6ed6b65e705b4bb42b5c1662bb01955d9a7204d6 100644 (file)
@@ -95,8 +95,6 @@ static struct type *desc_index_type (struct type *, int);
 
 static int desc_arity (struct type *);
 
-static int ada_type_match (struct type *, struct type *, int);
-
 static int ada_args_match (struct symbol *, struct value **, int);
 
 static struct value *make_array_descriptor (struct type *, struct value *);
@@ -193,7 +191,7 @@ static int find_struct_field (const char *, struct type *, int,
 
 static int ada_resolve_function (std::vector<struct block_symbol> &,
                                 struct value **, int, const char *,
-                                struct type *, int);
+                                struct type *, bool);
 
 static int ada_is_direct_array_type (struct type *);
 
@@ -2171,9 +2169,9 @@ decode_constrained_packed_array (struct value *arr)
       && ada_is_modular_type (value_type (arr)))
     {
        /* This is a (right-justified) modular type representing a packed
-        array with no wrapper.  In order to interpret the value through
-        the (left-justified) packed array type we just built, we must
-        first left-justify it.  */
+         array with no wrapper.  In order to interpret the value through
+         the (left-justified) packed array type we just built, we must
+         first left-justify it.  */
       int bit_size, bit_pos;
       ULONGEST mod;
 
@@ -2879,8 +2877,11 @@ ada_index_type (struct type *type, int n, const char *name)
       int i;
 
       for (i = 1; i < n; i += 1)
-       type = TYPE_TARGET_TYPE (type);
-      result_type = TYPE_TARGET_TYPE (type->index_type ());
+       {
+         type = ada_check_typedef (type);
+         type = TYPE_TARGET_TYPE (type);
+       }
+      result_type = TYPE_TARGET_TYPE (ada_check_typedef (type)->index_type ());
       /* FIXME: The stabs type r(0,0);bound;bound in an array type
         has a target type of TYPE_CODE_UNDEF.  We compensate here, but
         perhaps stabsread.c would make more sense.  */
@@ -3375,7 +3376,7 @@ See set/show multiple-symbol."));
 /* See ada-lang.h.  */
 
 block_symbol
-ada_find_operator_symbol (enum exp_opcode op, int parse_completion,
+ada_find_operator_symbol (enum exp_opcode op, bool parse_completion,
                          int nargs, value *argvec[])
 {
   if (possible_user_operator_p (op, argvec))
@@ -3398,7 +3399,7 @@ ada_find_operator_symbol (enum exp_opcode op, int parse_completion,
 block_symbol
 ada_resolve_funcall (struct symbol *sym, const struct block *block,
                     struct type *context_type,
-                    int parse_completion,
+                    bool parse_completion,
                     int nargs, value *argvec[],
                     innermost_block_tracker *tracker)
 {
@@ -3428,7 +3429,7 @@ ada_resolve_funcall (struct symbol *sym, const struct block *block,
 block_symbol
 ada_resolve_variable (struct symbol *sym, const struct block *block,
                      struct type *context_type,
-                     int parse_completion,
+                     bool parse_completion,
                      int deprocedure_p,
                      innermost_block_tracker *tracker)
 {
@@ -3492,14 +3493,12 @@ ada_resolve_variable (struct symbol *sym, const struct block *block,
   return candidates[i];
 }
 
-/* Return non-zero if formal type FTYPE matches actual type ATYPE.  If
-   MAY_DEREF is non-zero, the formal may be a pointer and the actual
-   a non-pointer.  */
+/* Return non-zero if formal type FTYPE matches actual type ATYPE.  */
 /* The term "match" here is rather loose.  The match is heuristic and
    liberal.  */
 
 static int
-ada_type_match (struct type *ftype, struct type *atype, int may_deref)
+ada_type_match (struct type *ftype, struct type *atype)
 {
   ftype = ada_check_typedef (ftype);
   atype = ada_check_typedef (atype);
@@ -3514,12 +3513,13 @@ ada_type_match (struct type *ftype, struct type *atype, int may_deref)
     default:
       return ftype->code () == atype->code ();
     case TYPE_CODE_PTR:
-      if (atype->code () == TYPE_CODE_PTR)
-       return ada_type_match (TYPE_TARGET_TYPE (ftype),
-                              TYPE_TARGET_TYPE (atype), 0);
-      else
-       return (may_deref
-               && ada_type_match (TYPE_TARGET_TYPE (ftype), atype, 0));
+      if (atype->code () != TYPE_CODE_PTR)
+       return 0;
+      atype = TYPE_TARGET_TYPE (atype);
+      /* This can only happen if the actual argument is 'null'.  */
+      if (atype->code () == TYPE_CODE_INT && TYPE_LENGTH (atype) == 0)
+       return 1;
+      return ada_type_match (TYPE_TARGET_TYPE (ftype), atype);
     case TYPE_CODE_INT:
     case TYPE_CODE_ENUM:
     case TYPE_CODE_RANGE:
@@ -3580,7 +3580,7 @@ ada_args_match (struct symbol *func, struct value **actuals, int n_actuals)
          struct type *ftype = ada_check_typedef (func_type->field (i).type ());
          struct type *atype = ada_check_typedef (value_type (actuals[i]));
 
-         if (!ada_type_match (ftype, atype, 1))
+         if (!ada_type_match (ftype, atype))
            return 0;
        }
     }
@@ -3634,7 +3634,7 @@ static int
 ada_resolve_function (std::vector<struct block_symbol> &syms,
                      struct value **args, int nargs,
                      const char *name, struct type *context_type,
-                     int parse_completion)
+                     bool parse_completion)
 {
   int fallback;
   int k;
@@ -3690,6 +3690,7 @@ numeric_type_p (struct type *type)
        {
        case TYPE_CODE_INT:
        case TYPE_CODE_FLT:
+       case TYPE_CODE_FIXED_POINT:
          return 1;
        case TYPE_CODE_RANGE:
          return (type == TYPE_TARGET_TYPE (type)
@@ -3737,6 +3738,7 @@ scalar_type_p (struct type *type)
        case TYPE_CODE_RANGE:
        case TYPE_CODE_ENUM:
        case TYPE_CODE_FLT:
+       case TYPE_CODE_FIXED_POINT:
          return 1;
        default:
          return 0;
@@ -4968,7 +4970,7 @@ ada_add_local_symbols (std::vector<struct block_symbol> &result,
     add_symbols_from_enclosing_procs (result, lookup_name, domain);
 }
 
-/* An object of this type is used as the user_data argument when
+/* An object of this type is used as the callback argument when
    calling the map_matching_symbols method.  */
 
 struct match_data
@@ -4979,48 +4981,43 @@ struct match_data
   }
   DISABLE_COPY_AND_ASSIGN (match_data);
 
+  bool operator() (struct block_symbol *bsym);
+
   struct objfile *objfile = nullptr;
   std::vector<struct block_symbol> *resultp;
   struct symbol *arg_sym = nullptr;
   bool found_sym = false;
 };
 
-/* A callback for add_nonlocal_symbols that adds symbol, found in BSYM,
-   to a list of symbols.  DATA is a pointer to a struct match_data *
-   containing the vector that collects the symbol list, the file that SYM
-   must come from, a flag indicating whether a non-argument symbol has
-   been found in the current block, and the last argument symbol
-   passed in SYM within the current block (if any).  When SYM is null,
-   marking the end of a block, the argument symbol is added if no
-   other has been found.  */
+/* A callback for add_nonlocal_symbols that adds symbol, found in
+   BSYM, to a list of symbols.  */
 
-static bool
-aux_add_nonlocal_symbols (struct block_symbol *bsym,
-                         struct match_data *data)
+bool
+match_data::operator() (struct block_symbol *bsym)
 {
   const struct block *block = bsym->block;
   struct symbol *sym = bsym->symbol;
 
   if (sym == NULL)
     {
-      if (!data->found_sym && data->arg_sym != NULL) 
-       add_defn_to_vec (*data->resultp,
-                        fixup_symbol_section (data->arg_sym, data->objfile),
+      if (!found_sym && arg_sym != NULL)
+       add_defn_to_vec (*resultp,
+                        fixup_symbol_section (arg_sym, objfile),
                         block);
-      data->found_sym = false;
-      data->arg_sym = NULL;
+      found_sym = false;
+      arg_sym = NULL;
     }
   else 
     {
       if (SYMBOL_CLASS (sym) == LOC_UNRESOLVED)
        return true;
       else if (SYMBOL_IS_ARGUMENT (sym))
-       data->arg_sym = sym;
+       arg_sym = sym;
       else
        {
-         data->found_sym = true;
-         add_defn_to_vec (*data->resultp,
-                          fixup_symbol_section (sym, data->objfile),
+         found_sym = true;
+         add_defn_to_vec (*resultp,
+                          fixup_symbol_section (sym, objfile),
                           block);
        }
     }
@@ -5178,6 +5175,33 @@ ada_lookup_name (const lookup_name_info &lookup_name)
   return lookup_name.ada ().lookup_name ().c_str ();
 }
 
+/* A helper for add_nonlocal_symbols.  Call expand_matching_symbols
+   for OBJFILE, then walk the objfile's symtabs and update the
+   results.  */
+
+static void
+map_matching_symbols (struct objfile *objfile,
+                     const lookup_name_info &lookup_name,
+                     bool is_wild_match,
+                     domain_enum domain,
+                     int global,
+                     match_data &data)
+{
+  data.objfile = objfile;
+  objfile->expand_matching_symbols (lookup_name, domain, global,
+                                   is_wild_match ? nullptr : compare_names);
+
+  const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
+  for (compunit_symtab *symtab : objfile->compunits ())
+    {
+      const struct block *block
+       = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab), block_kind);
+      if (!iterate_over_symbols_terminated (block, lookup_name,
+                                           domain, data))
+       break;
+    }
+}
+
 /* Add to RESULT all non-local symbols whose name and domain match
    LOOKUP_NAME and DOMAIN respectively.  The search is performed on
    GLOBAL_BLOCK symbols if GLOBAL is non-zero, or on STATIC_BLOCK
@@ -5192,20 +5216,10 @@ add_nonlocal_symbols (std::vector<struct block_symbol> &result,
 
   bool is_wild_match = lookup_name.ada ().wild_match_p ();
 
-  auto callback = [&] (struct block_symbol *bsym)
-    {
-      return aux_add_nonlocal_symbols (bsym, &data);
-    };
-
   for (objfile *objfile : current_program_space->objfiles ())
     {
-      data.objfile = objfile;
-
-      if (objfile->sf != nullptr)
-       objfile->sf->qf->map_matching_symbols (objfile, lookup_name,
-                                              domain, global, callback,
-                                              (is_wild_match
-                                               ? NULL : compare_names));
+      map_matching_symbols (objfile, lookup_name, is_wild_match, domain,
+                           global, data);
 
       for (compunit_symtab *cu : objfile->compunits ())
        {
@@ -5225,14 +5239,8 @@ add_nonlocal_symbols (std::vector<struct block_symbol> &result,
       lookup_name_info name1 (bracket_name, symbol_name_match_type::FULL);
 
       for (objfile *objfile : current_program_space->objfiles ())
-       {
-         data.objfile = objfile;
-         if (objfile->sf != nullptr)
-           objfile->sf->qf->map_matching_symbols (objfile, name1,
-                                                  domain, global, callback,
-                                                  compare_names);
-       }
-    }          
+       map_matching_symbols (objfile, name1, false, domain, global, data);
+    }
 }
 
 /* Find symbols in DOMAIN matching LOOKUP_NAME, in BLOCK and, if
@@ -9101,13 +9109,9 @@ ada_aggregate_component::assign (struct value *container,
     item->assign (container, lhs, exp, indices, low, high);
 }
 
-/* Assuming that LHS represents an lvalue having a record or array
-   type, evaluate an assignment of this aggregate's value to LHS.
-   CONTAINER is an lvalue containing LHS (possibly LHS itself).  Does
-   not modify the inferior's memory, nor does it modify the contents
-   of LHS (unless == CONTAINER).  */
+/* See ada-exp.h.  */
 
-void
+value *
 ada_aggregate_operation::assign_aggregate (struct value *container,
                                           struct value *lhs,
                                           struct expression *exp)
@@ -9144,6 +9148,8 @@ ada_aggregate_operation::assign_aggregate (struct value *container,
 
   std::get<0> (m_storage)->assign (container, lhs, exp, indices,
                                   low_index, high_index);
+
+  return container;
 }
 
 bool
@@ -9349,7 +9355,7 @@ ada_assign_operation::evaluate (struct type *expect_type,
       if (noside != EVAL_NORMAL)
        return arg1;
 
-      ag_op->assign_aggregate (arg1, arg1, exp);
+      arg1 = ag_op->assign_aggregate (arg1, arg1, exp);
       return ada_value_assign (arg1, arg1);
     }
   /* Force the evaluation of the rhs ARG2 to the type of the lhs ARG1,
@@ -9360,7 +9366,7 @@ ada_assign_operation::evaluate (struct type *expect_type,
   if (VALUE_LVAL (arg1) == lval_internalvar)
     type = NULL;
   value *arg2 = std::get<1> (m_storage)->evaluate (type, exp, noside);
-  if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
+  if (noside == EVAL_AVOID_SIDE_EFFECTS)
     return arg1;
   if (VALUE_LVAL (arg1) == lval_internalvar)
     {
@@ -9684,9 +9690,6 @@ eval_ternop_in_range (struct type *expect_type, struct expression *exp,
                      enum noside noside,
                      value *arg1, value *arg2, value *arg3)
 {
-  if (noside == EVAL_SKIP)
-    return eval_skip_value (exp);
-
   binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
   binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
   struct type *type = language_bool_type (exp->language_defn, exp->gdbarch);
@@ -9706,8 +9709,6 @@ ada_unop_neg (struct type *expect_type,
              enum noside noside, enum exp_opcode op,
              struct value *arg1)
 {
-  if (noside == EVAL_SKIP)
-    return eval_skip_value (exp);
   unop_promote (exp->language_defn, exp->gdbarch, &arg1);
   return value_neg (arg1);
 }
@@ -9720,9 +9721,6 @@ ada_unop_in_range (struct type *expect_type,
                   enum noside noside, enum exp_opcode op,
                   struct value *arg1, struct type *type)
 {
-  if (noside == EVAL_SKIP)
-    return eval_skip_value (exp);
-
   struct value *arg2, *arg3;
   switch (type->code ())
     {
@@ -9779,9 +9777,7 @@ ada_atr_size (struct type *expect_type,
   if (type->code () == TYPE_CODE_REF)
     type = TYPE_TARGET_TYPE (type);
 
-  if (noside == EVAL_SKIP)
-    return eval_skip_value (exp);
-  else if (noside == EVAL_AVOID_SIDE_EFFECTS)
+  if (noside == EVAL_AVOID_SIDE_EFFECTS)
     return value_zero (builtin_type (exp->gdbarch)->builtin_int, not_lval);
   else
     return value_from_longest (builtin_type (exp->gdbarch)->builtin_int,
@@ -10096,8 +10092,7 @@ ada_binop_minmax (struct type *expect_type,
   else
     {
       binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
-      return value_binop (arg1, arg2,
-                         op == OP_ATR_MIN ? BINOP_MIN : BINOP_MAX);
+      return value_binop (arg1, arg2, op);
     }
 }
 
@@ -10252,9 +10247,8 @@ ada_var_msym_value_operation::evaluate_for_cast (struct type *expect_type,
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
     return value_zero (expect_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 = ada_value_cast (expect_type, val);
 
@@ -10275,8 +10269,8 @@ ada_var_value_operation::evaluate_for_cast (struct type *expect_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 = ada_value_cast (expect_type, val);
 
@@ -10296,7 +10290,7 @@ ada_var_value_operation::evaluate (struct type *expect_type,
                                   struct expression *exp,
                                   enum noside noside)
 {
-  symbol *sym = std::get<0> (m_storage);
+  symbol *sym = std::get<0> (m_storage).symbol;
 
   if (SYMBOL_DOMAIN (sym) == UNDEF_DOMAIN)
     /* Only encountered when an unresolved symbol occurs in a
@@ -10334,8 +10328,7 @@ ada_var_value_operation::evaluate (struct type *expect_type,
             a fixed type would result in the loss of that type name,
             thus preventing us from printing the name of the ancestor
             type in the type description.  */
-         value *arg1 = var_value_operation::evaluate (nullptr, exp,
-                                                      EVAL_NORMAL);
+         value *arg1 = evaluate (nullptr, exp, EVAL_NORMAL);
 
          if (type->code () != TYPE_CODE_REF)
            {
@@ -10388,19 +10381,19 @@ ada_var_value_operation::resolve (struct expression *exp,
                                  innermost_block_tracker *tracker,
                                  struct type *context_type)
 {
-  symbol *sym = std::get<0> (m_storage);
+  symbol *sym = std::get<0> (m_storage).symbol;
   if (SYMBOL_DOMAIN (sym) == UNDEF_DOMAIN)
     {
       block_symbol resolved
-       = ada_resolve_variable (sym, std::get<1> (m_storage),
+       = ada_resolve_variable (sym, std::get<0> (m_storage).block,
                                context_type, parse_completion,
                                deprocedure_p, tracker);
-      std::get<0> (m_storage) = resolved.symbol;
-      std::get<1> (m_storage) = resolved.block;
+      std::get<0> (m_storage) = resolved;
     }
 
   if (deprocedure_p
-      && SYMBOL_TYPE (std::get<0> (m_storage))->code () == TYPE_CODE_FUNC)
+      && (SYMBOL_TYPE (std::get<0> (m_storage).symbol)->code ()
+         == TYPE_CODE_FUNC))
     return true;
 
   return false;
@@ -10493,6 +10486,11 @@ ada_unop_ind_operation::evaluate (struct type *expect_type,
                              (CORE_ADDR) value_as_address (arg1));
     }
 
+  struct type *target_type = (to_static_fixed_type
+                             (ada_aligned_type
+                              (ada_check_typedef (TYPE_TARGET_TYPE (type)))));
+  ada_ensure_varsize_limit (target_type);
+
   if (ada_is_array_descriptor_type (type))
     /* GDB allows dereferencing GNAT array descriptors.  */
     return ada_coerce_to_simple_array (arg1);
@@ -10717,8 +10715,7 @@ ada_funcall_operation::resolve (struct expression *exp,
                           tracker);
 
   std::get<0> (m_storage)
-    = make_operation<ada_var_value_operation> (resolved.symbol,
-                                              resolved.block);
+    = make_operation<ada_var_value_operation> (resolved);
   return false;
 }
 
@@ -11555,8 +11552,6 @@ static void
 create_excep_cond_exprs (struct ada_catchpoint *c,
                         enum ada_exception_catchpoint_kind ex)
 {
-  struct bp_location *bl;
-
   /* Nothing to do if there's no specific exception to catch.  */
   if (c->excep_string.empty ())
     return;
@@ -11572,7 +11567,7 @@ create_excep_cond_exprs (struct ada_catchpoint *c,
 
   /* Iterate over all the catchpoint's locations, and parse an
      expression for each.  */
-  for (bl = c->loc; bl != NULL; bl = bl->next)
+  for (bp_location *bl : c->locations ())
     {
       struct ada_catchpoint_location *ada_loc
        = (struct ada_catchpoint_location *) bl;
@@ -11868,7 +11863,7 @@ print_mention_exception (struct breakpoint *b)
          {
            std::string info = string_printf (_("`%s' Ada exception"),
                                              c->excep_string.c_str ());
-           uiout->text (info.c_str ());
+           uiout->text (info);
          }
        else
          uiout->text (_("all Ada exceptions"));
@@ -11884,7 +11879,7 @@ print_mention_exception (struct breakpoint *b)
            std::string info
              = string_printf (_("`%s' Ada exception handlers"),
                               c->excep_string.c_str ());
-           uiout->text (info.c_str ());
+           uiout->text (info);
          }
        else
          uiout->text (_("all Ada exceptions handlers"));
@@ -12540,6 +12535,7 @@ ada_add_global_exceptions (compiled_regex *preg,
                             return name_matches_regex (decoded.c_str (), preg);
                           },
                           NULL,
+                          SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
                           VARIABLES_DOMAIN);
 
   for (objfile *objfile : current_program_space->objfiles ())
@@ -13056,6 +13052,7 @@ public:
                             lookup_name,
                             NULL,
                             NULL,
+                            SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
                             ALL_DOMAIN);
 
     /* At this point scan through the misc symbol vectors and add each
@@ -13390,11 +13387,11 @@ _initialize_ada_language ()
 
   add_basic_prefix_cmd ("ada", no_class,
                        _("Prefix command for changing Ada-specific settings."),
-                       &set_ada_list, "set ada ", 0, &setlist);
+                       &set_ada_list, 0, &setlist);
 
   add_show_prefix_cmd ("ada", no_class,
                       _("Generic command for showing Ada-specific settings."),
-                      &show_ada_list, "show ada ", 0, &showlist);
+                      &show_ada_list, 0, &showlist);
 
   add_setshow_boolean_cmd ("trust-PAD-over-XVS", class_obscure,
                           &trust_pad_over_xvs, _("\
@@ -13473,12 +13470,12 @@ the regular expression are listed."));
 
   add_basic_prefix_cmd ("ada", class_maintenance,
                        _("Set Ada maintenance-related variables."),
-                       &maint_set_ada_cmdlist, "maintenance set ada ",
+                       &maint_set_ada_cmdlist,
                        0/*allow-unknown*/, &maintenance_set_cmdlist);
 
   add_show_prefix_cmd ("ada", class_maintenance,
                       _("Show Ada maintenance-related variables."),
-                      &maint_show_ada_cmdlist, "maintenance show ada ",
+                      &maint_show_ada_cmdlist,
                       0/*allow-unknown*/, &maintenance_show_cmdlist);
 
   add_setshow_boolean_cmd
@@ -13491,11 +13488,12 @@ When enabled, the debugger will stop using the DW_AT_GNAT_descriptive_type\n\
 DWARF attribute."),
      NULL, NULL, &maint_set_ada_cmdlist, &maint_show_ada_cmdlist);
 
-  decoded_names_store = htab_create_alloc (256, htab_hash_string, streq_hash,
+  decoded_names_store = htab_create_alloc (256, htab_hash_string,
+                                          htab_eq_string,
                                           NULL, xcalloc, xfree);
 
   /* The ada-lang observers.  */
-  gdb::observers::new_objfile.attach (ada_new_objfile_observer);
-  gdb::observers::free_objfile.attach (ada_free_objfile_observer);
-  gdb::observers::inferior_exit.attach (ada_inferior_exit);
+  gdb::observers::new_objfile.attach (ada_new_objfile_observer, "ada-lang");
+  gdb::observers::free_objfile.attach (ada_free_objfile_observer, "ada-lang");
+  gdb::observers::inferior_exit.attach (ada_inferior_exit, "ada-lang");
 }
This page took 0.035946 seconds and 4 git commands to generate.