Fix double-free when creating more than one block in JIT debug info reader
[deliverable/binutils-gdb.git] / gdb / ada-lang.c
index 7ec19d29a633a518b164e7cf067082186e0de23b..030c4aa131b5981f9931c3506eaa4b63b0ebd7f9 100644 (file)
@@ -1,6 +1,6 @@
 /* Ada language support routines for GDB, the GNU debugger.
 
-   Copyright (C) 1992-2017 Free Software Foundation, Inc.
+   Copyright (C) 1992-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -20,7 +20,6 @@
 
 #include "defs.h"
 #include <ctype.h>
-#include "demangle.h"
 #include "gdb_regex.h"
 #include "frame.h"
 #include "symtab.h"
@@ -30,7 +29,6 @@
 #include "parser-defs.h"
 #include "language.h"
 #include "varobj.h"
-#include "c-lang.h"
 #include "inferior.h"
 #include "symfile.h"
 #include "objfiles.h"
 #include "gdb_obstack.h"
 #include "ada-lang.h"
 #include "completer.h"
-#include <sys/stat.h>
 #include "ui-out.h"
 #include "block.h"
 #include "infcall.h"
-#include "dictionary.h"
 #include "annotate.h"
 #include "valprint.h"
 #include "source.h"
-#include "observer.h"
-#include "vec.h"
+#include "observable.h"
 #include "stack.h"
-#include "gdb_vecs.h"
 #include "typeprint.h"
 #include "namespace.h"
+#include "cli/cli-style.h"
 
-#include "psymtab.h"
 #include "value.h"
 #include "mi/mi-common.h"
 #include "arch-utils.h"
 #include "cli/cli-utils.h"
-#include "common/function-view.h"
-#include "common/byte-vector.h"
+#include "gdbsupport/function-view.h"
+#include "gdbsupport/byte-vector.h"
 #include <algorithm>
 
 /* Define whether or not the C operator '/' truncates towards zero for
@@ -124,10 +118,11 @@ static int num_defns_collected (struct obstack *);
 
 static struct block_symbol *defns_collected (struct obstack *, int);
 
-static struct value *resolve_subexp (struct expression **, int *, int,
-                                     struct type *);
+static struct value *resolve_subexp (expression_up *, int *, int,
+                                     struct type *, int,
+                                    innermost_block_tracker *);
 
-static void replace_operator_with_call (struct expression **, int, int, int,
+static void replace_operator_with_call (expression_up *, int, int, int,
                                         struct symbol *, const struct block *);
 
 static int possible_user_operator_p (enum exp_opcode, struct value **);
@@ -144,14 +139,6 @@ static int scalar_type_p (struct type *);
 
 static int discrete_type_p (struct type *);
 
-static enum ada_renaming_category parse_old_style_renaming (struct type *,
-                                                           const char **,
-                                                           int *,
-                                                           const char **);
-
-static struct symbol *find_old_style_renaming_symbol (const char *,
-                                                     const struct block *);
-
 static struct type *ada_lookup_struct_elt_type (struct type *, const char *,
                                                 int, int);
 
@@ -190,8 +177,6 @@ static int ada_is_unconstrained_packed_array_type (struct type *);
 static struct value *value_subscript_packed (struct value *, int,
                                              struct value **);
 
-static void move_bits (gdb_byte *, int, const gdb_byte *, int, int, int);
-
 static struct value *coerce_unspec_val_to_type (struct value *,
                                                 struct type *);
 
@@ -225,12 +210,9 @@ static struct value *ada_value_primitive_field (struct value *, int, int,
 static int find_struct_field (const char *, struct type *, int,
                               struct type **, int *, int *, int *, int *);
 
-static struct value *ada_to_fixed_value_create (struct type *, CORE_ADDR,
-                                                struct value *);
-
 static int ada_resolve_function (struct block_symbol *, int,
                                  struct value **, int, const char *,
-                                 struct type *);
+                                 struct type *, int);
 
 static int ada_is_direct_array_type (struct type *);
 
@@ -345,9 +327,6 @@ static const char *known_auxiliary_function_name_patterns[] = {
   ADA_KNOWN_AUXILIARY_FUNCTION_NAME_PATTERNS NULL
 };
 
-/* Space for allocating results of ada_lookup_symbol_list.  */
-static struct obstack symbol_list_obstack;
-
 /* Maintenance-related settings for this module.  */
 
 static struct cmd_list_element *maint_set_ada_cmdlist;
@@ -372,7 +351,7 @@ maint_show_ada_cmd (const char *args, int from_tty)
 
 /* The "maintenance ada set/show ignore-descriptive-type" value.  */
 
-static int ada_ignore_descriptive_types_p = 0;
+static bool ada_ignore_descriptive_types_p = false;
 
                        /* Inferior-specific data.  */
 
@@ -384,27 +363,16 @@ struct ada_inferior_data
      tagged types.  With older versions of GNAT, this type was directly
      accessible through a component ("tsd") in the object tag.  But this
      is no longer the case, so we cache it for each inferior.  */
-  struct type *tsd_type;
+  struct type *tsd_type = nullptr;
 
   /* The exception_support_info data.  This data is used to determine
      how to implement support for Ada exception catchpoints in a given
      inferior.  */
-  const struct exception_support_info *exception_info;
+  const struct exception_support_info *exception_info = nullptr;
 };
 
 /* Our key to this module's inferior data.  */
-static const struct inferior_data *ada_inferior_data;
-
-/* A cleanup routine for our inferior data.  */
-static void
-ada_inferior_data_cleanup (struct inferior *inf, void *arg)
-{
-  struct ada_inferior_data *data;
-
-  data = (struct ada_inferior_data *) inferior_data (inf, ada_inferior_data);
-  if (data != NULL)
-    xfree (data);
-}
+static const struct inferior_key<ada_inferior_data> ada_inferior_data;
 
 /* Return our inferior data for the given inferior (INF).
 
@@ -419,12 +387,9 @@ get_ada_inferior_data (struct inferior *inf)
 {
   struct ada_inferior_data *data;
 
-  data = (struct ada_inferior_data *) inferior_data (inf, ada_inferior_data);
+  data = ada_inferior_data.get (inf);
   if (data == NULL)
-    {
-      data = XCNEW (struct ada_inferior_data);
-      set_inferior_data (inf, ada_inferior_data, data);
-    }
+    data = ada_inferior_data.emplace (inf);
 
   return data;
 }
@@ -435,8 +400,7 @@ get_ada_inferior_data (struct inferior *inf)
 static void
 ada_inferior_exit (struct inferior *inf)
 {
-  ada_inferior_data_cleanup (inf, NULL);
-  set_inferior_data (inf, ada_inferior_data, NULL);
+  ada_inferior_data.clear (inf);
 }
 
 
@@ -445,12 +409,18 @@ ada_inferior_exit (struct inferior *inf)
 /* This module's per-program-space data.  */
 struct ada_pspace_data
 {
+  ~ada_pspace_data ()
+  {
+    if (sym_cache != NULL)
+      ada_free_symbol_cache (sym_cache);
+  }
+
   /* The Ada symbol cache.  */
-  struct ada_symbol_cache *sym_cache;
+  struct ada_symbol_cache *sym_cache = nullptr;
 };
 
 /* Key to our per-program-space data.  */
-static const struct program_space_data *ada_pspace_data_handle;
+static const struct program_space_key<ada_pspace_data> ada_pspace_data_handle;
 
 /* Return this module's data for the given program space (PSPACE).
    If not is found, add a zero'ed one now.
@@ -462,29 +432,13 @@ get_ada_pspace_data (struct program_space *pspace)
 {
   struct ada_pspace_data *data;
 
-  data = ((struct ada_pspace_data *)
-         program_space_data (pspace, ada_pspace_data_handle));
+  data = ada_pspace_data_handle.get (pspace);
   if (data == NULL)
-    {
-      data = XCNEW (struct ada_pspace_data);
-      set_program_space_data (pspace, ada_pspace_data_handle, data);
-    }
+    data = ada_pspace_data_handle.emplace (pspace);
 
   return data;
 }
 
-/* The cleanup callback for this module's per-program-space data.  */
-
-static void
-ada_pspace_data_cleanup (struct program_space *pspace, void *data)
-{
-  struct ada_pspace_data *pspace_data = (struct ada_pspace_data *) data;
-
-  if (pspace_data->sym_cache != NULL)
-    ada_free_symbol_cache (pspace_data->sym_cache);
-  xfree (pspace_data);
-}
-
                         /* Utilities */
 
 /* If TYPE is a TYPE_CODE_TYPEDEF type, return the target type after
@@ -547,17 +501,12 @@ ada_unqualified_name (const char *decoded_name)
   return result;
 }
 
-/* Return a string starting with '<', followed by STR, and '>'.
-   The result is good until the next call.  */
+/* Return a string starting with '<', followed by STR, and '>'.  */
 
-static char *
+static std::string
 add_angle_brackets (const char *str)
 {
-  static char *result = NULL;
-
-  xfree (result);
-  result = xstrprintf ("<%s>", str);
-  return result;
+  return string_printf ("<%s>", str);
 }
 
 static const char *
@@ -576,11 +525,28 @@ ada_print_array_index (struct value *index_value, struct ui_file *stream,
   fprintf_filtered (stream, " => ");
 }
 
+/* la_watch_location_expression for Ada.  */
+
+static gdb::unique_xmalloc_ptr<char>
+ada_watch_location_expression (struct type *type, CORE_ADDR addr)
+{
+  type = check_typedef (TYPE_TARGET_TYPE (check_typedef (type)));
+  std::string name = type_to_string (type);
+  return gdb::unique_xmalloc_ptr<char>
+    (xstrprintf ("{%s} %s", name.c_str (), core_addr_to_string (addr)));
+}
+
+/* Assuming V points to an array of S objects,  make sure that it contains at
+   least M objects, updating V and S as necessary.  */
+
+#define GROW_VECT(v, s, m)                                    \
+   if ((s) < (m)) (v) = (char *) grow_vect (v, &(s), m, sizeof *(v));
+
 /* Assuming VECT points to an array of *SIZE objects of size
    ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects,
    updating *SIZE as necessary and returning the (new) array.  */
 
-void *
+static void *
 grow_vect (void *vect, size_t *size, size_t min_size, int element_size)
 {
   if (*size < min_size)
@@ -697,7 +663,8 @@ coerce_unspec_val_to_type (struct value *val, struct type *type)
       set_value_component_location (result, val);
       set_value_bitsize (result, value_bitsize (val));
       set_value_bitpos (result, value_bitpos (val));
-      set_value_address (result, value_address (val));
+      if (VALUE_LVAL (result) == lval_memory)
+       set_value_address (result, value_address (val));
       return result;
     }
 }
@@ -857,7 +824,7 @@ get_base_type (struct type *type)
 
 /* Return a decoded version of the given VALUE.  This means returning
    a value whose type is obtained by applying all the GNAT-specific
-   encondings, making the resulting type a static but standard description
+   encodings, making the resulting type a static but standard description
    of the initial type.  */
 
 struct value *
@@ -901,11 +868,10 @@ ada_get_decoded_type (struct type *type)
 /* If the main program is in Ada, return language_ada, otherwise return LANG
    (the main program is in Ada iif the adainit symbol is found).  */
 
-enum language
+static enum language
 ada_update_initial_language (enum language lang)
 {
-  if (lookup_minimal_symbol ("adainit", (const char *) NULL,
-                             (struct objfile *) NULL).minsym != NULL)
+  if (lookup_minimal_symbol ("adainit", NULL, NULL).minsym != NULL)
     return language_ada;
 
   return lang;
@@ -919,7 +885,7 @@ char *
 ada_main_name (void)
 {
   struct bound_minimal_symbol msym;
-  static char *main_program_name = NULL;
+  static gdb::unique_xmalloc_ptr<char> main_program_name;
 
   /* For Ada, the name of the main procedure is stored in a specific
      string constant, generated by the binder.  Look for that symbol,
@@ -937,13 +903,12 @@ ada_main_name (void)
       if (main_program_name_addr == 0)
         error (_("Invalid address for Ada main program name."));
 
-      xfree (main_program_name);
       target_read_string (main_program_name_addr, &main_program_name,
                           1024, &err_code);
 
       if (err_code != 0)
         return NULL;
-      return main_program_name;
+      return main_program_name.get ();
     }
 
   /* The main procedure doesn't seem to be in Ada.  */
@@ -1050,7 +1015,7 @@ ada_encode (const char *decoded)
    quotes, unfolded, but with the quotes stripped away.  Result good
    to next call.  */
 
-char *
+static char *
 ada_fold_name (const char *name)
 {
   static char *fold_buffer = NULL;
@@ -1137,44 +1102,23 @@ ada_remove_po_subprogram_suffix (const char *encoded, int *len)
     *len = *len - 1;
 }
 
-/* Remove trailing X[bn]* suffixes (indicating names in package bodies).  */
-
-static void
-ada_remove_Xbn_suffix (const char *encoded, int *len)
-{
-  int i = *len - 1;
-
-  while (i > 0 && (encoded[i] == 'b' || encoded[i] == 'n'))
-    i--;
-
-  if (encoded[i] != 'X')
-    return;
-
-  if (i == 0)
-    return;
-
-  if (isalnum (encoded[i-1]))
-    *len = i;
-}
-
 /* If ENCODED follows the GNAT entity encoding conventions, then return
    the decoded form of ENCODED.  Otherwise, return "<%s>" where "%s" is
-   replaced by ENCODED.
+   replaced by ENCODED.  */
 
-   The resulting string is valid until the next call of ada_decode.
-   If the string is unchanged by decoding, the original string pointer
-   is returned.  */
-
-const char *
+std::string
 ada_decode (const char *encoded)
 {
   int i, j;
   int len0;
   const char *p;
-  char *decoded;
   int at_start_name;
-  static char *decoding_buffer = NULL;
-  static size_t decoding_buffer_size = 0;
+  std::string decoded;
+
+  /* With function descriptors on PPC64, the value of a symbol named
+     ".FN", if it exists, is the entry point of the function "FN".  */
+  if (encoded[0] == '.')
+    encoded += 1;
 
   /* The name of the Ada main procedure starts with "_ada_".
      This prefix is not part of the decoded name, so skip this part
@@ -1228,8 +1172,7 @@ ada_decode (const char *encoded)
 
   /* Make decoded big enough for possible expansion by operator name.  */
 
-  GROW_VECT (decoding_buffer, decoding_buffer_size, 2 * len0 + 1);
-  decoded = decoding_buffer;
+  decoded.resize (2 * len0 + 1, 'X');
 
   /* Remove trailing __{digit}+ or trailing ${digit}+.  */
 
@@ -1266,7 +1209,7 @@ ada_decode (const char *encoded)
                             op_len - 1) == 0)
                   && !isalnum (encoded[i + op_len]))
                 {
-                  strcpy (decoded + j, ada_opname_table[k].decoded);
+                  strcpy (&decoded.front() + j, ada_opname_table[k].decoded);
                   at_start_name = 0;
                   i += op_len;
                   j += strlen (ada_opname_table[k].decoded);
@@ -1387,27 +1330,22 @@ ada_decode (const char *encoded)
           j += 1;
         }
     }
-  decoded[j] = '\000';
+  decoded.resize (j);
 
   /* Decoded names should never contain any uppercase character.
      Double-check this, and abort the decoding if we find one.  */
 
-  for (i = 0; decoded[i] != '\0'; i += 1)
+  for (i = 0; i < decoded.length(); ++i)
     if (isupper (decoded[i]) || decoded[i] == ' ')
       goto Suppress;
 
-  if (strcmp (decoded, encoded) == 0)
-    return encoded;
-  else
-    return decoded;
+  return decoded;
 
 Suppress:
-  GROW_VECT (decoding_buffer, decoding_buffer_size, strlen (encoded) + 3);
-  decoded = decoding_buffer;
   if (encoded[0] == '<')
-    strcpy (decoded, encoded);
+    decoded = encoded;
   else
-    xsnprintf (decoded, decoding_buffer_size, "<%s>", encoded);
+    decoded = '<' + std::string(encoded) + '>';
   return decoded;
 
 }
@@ -1438,14 +1376,13 @@ ada_decode_symbol (const struct general_symbol_info *arg)
 
   if (!gsymbol->ada_mangled)
     {
-      const char *decoded = ada_decode (gsymbol->name);
+      std::string decoded = ada_decode (gsymbol->name);
       struct obstack *obstack = gsymbol->language_specific.obstack;
 
       gsymbol->ada_mangled = 1;
 
       if (obstack != NULL)
-       *resultp
-         = (const char *) obstack_copy0 (obstack, decoded, strlen (decoded));
+       *resultp = obstack_strdup (obstack, decoded.c_str ());
       else
         {
          /* Sometimes, we can't find a corresponding objfile, in
@@ -1454,10 +1391,10 @@ ada_decode_symbol (const struct general_symbol_info *arg)
             significant memory leak (FIXME).  */
 
           char **slot = (char **) htab_find_slot (decoded_names_store,
-                                                  decoded, INSERT);
+                                                  decoded.c_str (), INSERT);
 
           if (*slot == NULL)
-            *slot = xstrdup (decoded);
+            *slot = xstrdup (decoded.c_str ());
           *resultp = *slot;
         }
     }
@@ -1468,7 +1405,7 @@ ada_decode_symbol (const struct general_symbol_info *arg)
 static char *
 ada_la_decode (const char *encoded, int options)
 {
-  return xstrdup (ada_decode (encoded));
+  return xstrdup (ada_decode (encoded).c_str ());
 }
 
 /* Implement la_sniff_from_mangled_name for Ada.  */
@@ -1476,11 +1413,11 @@ ada_la_decode (const char *encoded, int options)
 static int
 ada_sniff_from_mangled_name (const char *mangled, char **out)
 {
-  const char *demangled = ada_decode (mangled);
+  std::string demangled = ada_decode (mangled);
 
   *out = NULL;
 
-  if (demangled != mangled && demangled != NULL && demangled[0] != '<')
+  if (demangled != mangled && demangled[0] != '<')
     {
       /* Set the gsymbol language to Ada, but still return 0.
         Two reasons for that:
@@ -1521,7 +1458,7 @@ ada_sniff_from_mangled_name (const char *mangled, char **out)
    Otherwise, do nothing.  This function also does nothing if
    INDEX_DESC_TYPE is NULL.
 
-   The GNAT encoding used to describle the array index type evolved a bit.
+   The GNAT encoding used to describe the array index type evolved a bit.
    Initially, the information would be provided through the name of each
    field of the structure type only, while the type of these fields was
    described as unspecified and irrelevant.  The debugger was then expected
@@ -1979,7 +1916,8 @@ ada_is_bogus_array_descriptor (struct type *type)
    the ARR denotes a null array descriptor and BOUNDS is non-zero,
    returns NULL.  The result is simply the type of ARR if ARR is not
    a descriptor.  */
-struct type *
+
+static struct type *
 ada_type_of_array (struct value *arr, int bounds)
 {
   if (ada_is_constrained_packed_array_type (value_type (arr)))
@@ -2319,7 +2257,7 @@ decode_constrained_packed_array (struct value *arr)
       return NULL;
     }
 
-  if (gdbarch_bits_big_endian (get_type_arch (value_type (arr)))
+  if (type_byte_order (value_type (arr)) == BFD_ENDIAN_BIG
       && ada_is_modular_type (value_type (arr)))
     {
        /* This is a (right-justified) modular type representing a packed
@@ -2411,7 +2349,7 @@ has_negatives (struct type *type)
     case TYPE_CODE_INT:
       return !TYPE_UNSIGNED (type);
     case TYPE_CODE_RANGE:
-      return TYPE_LOW_BOUND (type) < 0;
+      return TYPE_LOW_BOUND (type) - TYPE_RANGE_DATA (type)->bias < 0;
     }
 }
 
@@ -2561,7 +2499,7 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr,
   const gdb_byte *src;                /* First byte containing data to unpack */
   gdb_byte *unpacked;
   const int is_scalar = is_scalar_type (type);
-  const int is_big_endian = gdbarch_bits_big_endian (get_type_arch (type));
+  const int is_big_endian = type_byte_order (type) == BFD_ENDIAN_BIG;
   gdb::byte_vector staging;
 
   type = ada_check_typedef (type);
@@ -2665,72 +2603,6 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr,
   return v;
 }
 
-/* Move N bits from SOURCE, starting at bit offset SRC_OFFSET to
-   TARGET, starting at bit offset TARG_OFFSET.  SOURCE and TARGET must
-   not overlap.  */
-static void
-move_bits (gdb_byte *target, int targ_offset, const gdb_byte *source,
-          int src_offset, int n, int bits_big_endian_p)
-{
-  unsigned int accum, mask;
-  int accum_bits, chunk_size;
-
-  target += targ_offset / HOST_CHAR_BIT;
-  targ_offset %= HOST_CHAR_BIT;
-  source += src_offset / HOST_CHAR_BIT;
-  src_offset %= HOST_CHAR_BIT;
-  if (bits_big_endian_p)
-    {
-      accum = (unsigned char) *source;
-      source += 1;
-      accum_bits = HOST_CHAR_BIT - src_offset;
-
-      while (n > 0)
-        {
-          int unused_right;
-
-          accum = (accum << HOST_CHAR_BIT) + (unsigned char) *source;
-          accum_bits += HOST_CHAR_BIT;
-          source += 1;
-          chunk_size = HOST_CHAR_BIT - targ_offset;
-          if (chunk_size > n)
-            chunk_size = n;
-          unused_right = HOST_CHAR_BIT - (chunk_size + targ_offset);
-          mask = ((1 << chunk_size) - 1) << unused_right;
-          *target =
-            (*target & ~mask)
-            | ((accum >> (accum_bits - chunk_size - unused_right)) & mask);
-          n -= chunk_size;
-          accum_bits -= chunk_size;
-          target += 1;
-          targ_offset = 0;
-        }
-    }
-  else
-    {
-      accum = (unsigned char) *source >> src_offset;
-      source += 1;
-      accum_bits = HOST_CHAR_BIT - src_offset;
-
-      while (n > 0)
-        {
-          accum = accum + ((unsigned char) *source << accum_bits);
-          accum_bits += HOST_CHAR_BIT;
-          source += 1;
-          chunk_size = HOST_CHAR_BIT - targ_offset;
-          if (chunk_size > n)
-            chunk_size = n;
-          mask = ((1 << chunk_size) - 1) << targ_offset;
-          *target = (*target & ~mask) | ((accum << targ_offset) & mask);
-          n -= chunk_size;
-          accum_bits -= chunk_size;
-          accum >>= chunk_size;
-          target += 1;
-          targ_offset = 0;
-        }
-    }
-}
-
 /* Store the contents of FROMVAL into the location of TOVAL.
    Return a new value with the location of TOVAL and contents of
    FROMVAL.   Handles assignment into packed fields that have
@@ -2772,12 +2644,14 @@ ada_value_assign (struct value *toval, struct value *fromval)
       from_size = value_bitsize (fromval);
       if (from_size == 0)
        from_size = TYPE_LENGTH (value_type (fromval)) * TARGET_CHAR_BIT;
-      if (gdbarch_bits_big_endian (get_type_arch (type)))
-        move_bits (buffer, value_bitpos (toval),
-                  value_contents (fromval), from_size - bits, bits, 1);
-      else
-        move_bits (buffer, value_bitpos (toval),
-                  value_contents (fromval), 0, bits, 0);
+
+      const int is_big_endian = type_byte_order (type) == BFD_ENDIAN_BIG;
+      ULONGEST from_offset = 0;
+      if (is_big_endian && is_scalar_type (value_type (fromval)))
+       from_offset = from_size - bits;
+      copy_bitwise (buffer, value_bitpos (toval),
+                   value_contents (fromval), from_offset,
+                   bits, is_big_endian);
       write_memory_with_notification (to_addr, buffer, len);
 
       val = value_copy (toval);
@@ -2820,16 +2694,32 @@ value_assign_to_component (struct value *container, struct value *component,
   else
     bits = value_bitsize (component);
 
-  if (gdbarch_bits_big_endian (get_type_arch (value_type (container))))
-    move_bits (value_contents_writeable (container) + offset_in_container,
-              value_bitpos (container) + bit_offset_in_container,
-              value_contents (val),
-              TYPE_LENGTH (value_type (component)) * TARGET_CHAR_BIT - bits,
-              bits, 1);
+  if (type_byte_order (value_type (container)) == BFD_ENDIAN_BIG)
+    {
+      int src_offset;
+
+      if (is_scalar_type (check_typedef (value_type (component))))
+        src_offset
+         = TYPE_LENGTH (value_type (component)) * TARGET_CHAR_BIT - bits;
+      else
+       src_offset = 0;
+      copy_bitwise (value_contents_writeable (container) + offset_in_container,
+                   value_bitpos (container) + bit_offset_in_container,
+                   value_contents (val), src_offset, bits, 1);
+    }
   else
-    move_bits (value_contents_writeable (container) + offset_in_container,
-              value_bitpos (container) + bit_offset_in_container,
-              value_contents (val), 0, bits, 0);
+    copy_bitwise (value_contents_writeable (container) + offset_in_container,
+                 value_bitpos (container) + bit_offset_in_container,
+                 value_contents (val), 0, bits, 0);
+}
+
+/* Determine if TYPE is an access to an unconstrained array.  */
+
+bool
+ada_is_access_to_unconstrained_array (struct type *type)
+{
+  return (TYPE_CODE (type) == TYPE_CODE_TYPEDEF
+         && is_thick_pntr (ada_typedef_target_type (type)));
 }
 
 /* The value of the element of array ARR at the ARITY indices given in IND.
@@ -2852,10 +2742,34 @@ ada_value_subscript (struct value *arr, int arity, struct value **ind)
 
   for (k = 0; k < arity; k += 1)
     {
+      struct type *saved_elt_type = TYPE_TARGET_TYPE (elt_type);
+
       if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY)
         error (_("too many subscripts (%d expected)"), k);
+
       elt = value_subscript (elt, pos_atr (ind[k]));
+
+      if (ada_is_access_to_unconstrained_array (saved_elt_type)
+         && TYPE_CODE (value_type (elt)) != TYPE_CODE_TYPEDEF)
+       {
+         /* The element is a typedef to an unconstrained array,
+            except that the value_subscript call stripped the
+            typedef layer.  The typedef layer is GNAT's way to
+            specify that the element is, at the source level, an
+            access to the unconstrained array, rather than the
+            unconstrained array.  So, we need to restore that
+            typedef layer, which we can do by forcing the element's
+            type back to its original type. Otherwise, the returned
+            value is going to be printed as the array, rather
+            than as an access.  Another symptom of the same issue
+            would be that an expression trying to dereference the
+            element would also be improperly rejected.  */
+         deprecated_set_value_type (elt, saved_elt_type);
+       }
+
+      elt_type = ada_check_typedef (value_type (elt));
     }
+
   return elt;
 }
 
@@ -2913,8 +2827,10 @@ ada_value_slice_from_ptr (struct value *array_ptr, struct type *type,
   struct type *base_index_type = TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type0));
   struct type *index_type
     = create_static_range_type (NULL, base_index_type, low, high);
-  struct type *slice_type =
-    create_array_type (NULL, TYPE_TARGET_TYPE (type0), index_type);
+  struct type *slice_type = create_array_type_with_stride
+                             (NULL, TYPE_TARGET_TYPE (type0), index_type,
+                              get_dyn_prop (DYN_PROP_BYTE_STRIDE, type0),
+                              TYPE_FIELD_BITSIZE (type0, 0));
   int base_low =  ada_discrete_type_low_bound (TYPE_INDEX_TYPE (type0));
   LONGEST base_low_pos, low_pos;
   CORE_ADDR base;
@@ -2941,8 +2857,10 @@ ada_value_slice (struct value *array, int low, int high)
   struct type *base_index_type = TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type));
   struct type *index_type
     = create_static_range_type (NULL, TYPE_INDEX_TYPE (type), low, high);
-  struct type *slice_type =
-    create_array_type (NULL, TYPE_TARGET_TYPE (type), index_type);
+  struct type *slice_type = create_array_type_with_stride
+                             (NULL, TYPE_TARGET_TYPE (type), index_type,
+                              get_dyn_prop (DYN_PROP_BYTE_STRIDE, type),
+                              TYPE_FIELD_BITSIZE (type, 0));
   LONGEST low_pos, high_pos;
 
   if (!discrete_position (base_index_type, low, &low_pos)
@@ -3178,7 +3096,7 @@ ada_array_length (struct value *arr, int n)
     }
 
   arr_type = check_typedef (arr_type);
-  index_type = TYPE_INDEX_TYPE (arr_type);
+  index_type = ada_index_type (arr_type, n, "length");
   if (index_type != NULL)
     {
       struct type *base_type;
@@ -3193,16 +3111,18 @@ ada_array_length (struct value *arr, int n)
   return high - low + 1;
 }
 
-/* An empty array whose type is that of ARR_TYPE (an array type),
-   with bounds LOW to LOW-1.  */
+/* An array whose type is that of ARR_TYPE (an array type), with
+   bounds LOW to HIGH, but whose contents are unimportant.  If HIGH is
+   less than LOW, then LOW-1 is used.  */
 
 static struct value *
-empty_array (struct type *arr_type, int low)
+empty_array (struct type *arr_type, int low, int high)
 {
   struct type *arr_type0 = ada_check_typedef (arr_type);
   struct type *index_type
     = create_static_range_type
-        (NULL, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (arr_type0)),  low, low - 1);
+        (NULL, TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (arr_type0)), low,
+        high < low ? low - 1 : high);
   struct type *elt_type = ada_array_element_type (arr_type0, 1);
 
   return allocate_value (create_array_type (NULL, elt_type, index_type));
@@ -3227,877 +3147,886 @@ ada_decoded_op_name (enum exp_opcode op)
   error (_("Could not find operator name for opcode"));
 }
 
+/* Returns true (non-zero) iff decoded name N0 should appear before N1
+   in a listing of choices during disambiguation (see sort_choices, below).
+   The idea is that overloadings of a subprogram name from the
+   same package should sort in their source order.  We settle for ordering
+   such symbols by their trailing number (__N  or $N).  */
 
-/* Same as evaluate_type (*EXP), but resolves ambiguous symbol
-   references (marked by OP_VAR_VALUE nodes in which the symbol has an
-   undefined namespace) and converts operators that are
-   user-defined into appropriate function calls.  If CONTEXT_TYPE is
-   non-null, it provides a preferred result type [at the moment, only
-   type void has any effect---causing procedures to be preferred over
-   functions in calls].  A null CONTEXT_TYPE indicates that a non-void
-   return type is preferred.  May change (expand) *EXP.  */
-
-static void
-resolve (struct expression **expp, int void_context_p)
+static int
+encoded_ordered_before (const char *N0, const char *N1)
 {
-  struct type *context_type = NULL;
-  int pc = 0;
+  if (N1 == NULL)
+    return 0;
+  else if (N0 == NULL)
+    return 1;
+  else
+    {
+      int k0, k1;
 
-  if (void_context_p)
-    context_type = builtin_type ((*expp)->gdbarch)->builtin_void;
+      for (k0 = strlen (N0) - 1; k0 > 0 && isdigit (N0[k0]); k0 -= 1)
+        ;
+      for (k1 = strlen (N1) - 1; k1 > 0 && isdigit (N1[k1]); k1 -= 1)
+        ;
+      if ((N0[k0] == '_' || N0[k0] == '$') && N0[k0 + 1] != '\000'
+          && (N1[k1] == '_' || N1[k1] == '$') && N1[k1 + 1] != '\000')
+        {
+          int n0, n1;
 
-  resolve_subexp (expp, &pc, 1, context_type);
+          n0 = k0;
+          while (N0[n0] == '_' && n0 > 0 && N0[n0 - 1] == '_')
+            n0 -= 1;
+          n1 = k1;
+          while (N1[n1] == '_' && n1 > 0 && N1[n1 - 1] == '_')
+            n1 -= 1;
+          if (n0 == n1 && strncmp (N0, N1, n0) == 0)
+            return (atoi (N0 + k0 + 1) < atoi (N1 + k1 + 1));
+        }
+      return (strcmp (N0, N1) < 0);
+    }
 }
 
-/* Resolve the operator of the subexpression beginning at
-   position *POS of *EXPP.  "Resolving" consists of replacing
-   the symbols that have undefined namespaces in OP_VAR_VALUE nodes
-   with their resolutions, replacing built-in operators with
-   function calls to user-defined operators, where appropriate, and,
-   when DEPROCEDURE_P is non-zero, converting function-valued variables
-   into parameterless calls.  May expand *EXPP.  The CONTEXT_TYPE functions
-   are as in ada_resolve, above.  */
+/* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by the
+   encoded names.  */
 
-static struct value *
-resolve_subexp (struct expression **expp, int *pos, int deprocedure_p,
-                struct type *context_type)
+static void
+sort_choices (struct block_symbol syms[], int nsyms)
 {
-  int pc = *pos;
   int i;
-  struct expression *exp;       /* Convenience: == *expp.  */
-  enum exp_opcode op = (*expp)->elts[pc].opcode;
-  struct value **argvec;        /* Vector of operand types (alloca'ed).  */
-  int nargs;                    /* Number of operands.  */
-  int oplen;
 
-  argvec = NULL;
-  nargs = 0;
-  exp = *expp;
-
-  /* Pass one: resolve operands, saving their types and updating *pos,
-     if needed.  */
-  switch (op)
+  for (i = 1; i < nsyms; i += 1)
     {
-    case OP_FUNCALL:
-      if (exp->elts[pc + 3].opcode == OP_VAR_VALUE
-          && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
-        *pos += 7;
-      else
+      struct block_symbol sym = syms[i];
+      int j;
+
+      for (j = i - 1; j >= 0; j -= 1)
         {
-          *pos += 3;
-          resolve_subexp (expp, pos, 0, NULL);
+          if (encoded_ordered_before (syms[j].symbol->linkage_name (),
+                                      sym.symbol->linkage_name ()))
+            break;
+          syms[j + 1] = syms[j];
         }
-      nargs = longest_to_int (exp->elts[pc + 1].longconst);
-      break;
+      syms[j + 1] = sym;
+    }
+}
 
-    case UNOP_ADDR:
-      *pos += 1;
-      resolve_subexp (expp, pos, 0, NULL);
-      break;
+/* Whether GDB should display formals and return types for functions in the
+   overloads selection menu.  */
+static bool print_signatures = true;
 
-    case UNOP_QUAL:
-      *pos += 3;
-      resolve_subexp (expp, pos, 1, check_typedef (exp->elts[pc + 1].type));
-      break;
+/* Print the signature for SYM on STREAM according to the FLAGS options.  For
+   all but functions, the signature is just the name of the symbol.  For
+   functions, this is the name of the function, the list of types for formals
+   and the return type (if any).  */
 
-    case OP_ATR_MODULUS:
-    case OP_ATR_SIZE:
-    case OP_ATR_TAG:
-    case OP_ATR_FIRST:
-    case OP_ATR_LAST:
-    case OP_ATR_LENGTH:
-    case OP_ATR_POS:
-    case OP_ATR_VAL:
-    case OP_ATR_MIN:
-    case OP_ATR_MAX:
-    case TERNOP_IN_RANGE:
-    case BINOP_IN_BOUNDS:
-    case UNOP_IN_RANGE:
-    case OP_AGGREGATE:
-    case OP_OTHERS:
-    case OP_CHOICES:
-    case OP_POSITIONAL:
-    case OP_DISCRETE_RANGE:
-    case OP_NAME:
-      ada_forward_operator_length (exp, pc, &oplen, &nargs);
-      *pos += oplen;
-      break;
+static void
+ada_print_symbol_signature (struct ui_file *stream, struct symbol *sym,
+                           const struct type_print_options *flags)
+{
+  struct type *type = SYMBOL_TYPE (sym);
 
-    case BINOP_ASSIGN:
-      {
-        struct value *arg1;
+  fprintf_filtered (stream, "%s", sym->print_name ());
+  if (!print_signatures
+      || type == NULL
+      || TYPE_CODE (type) != TYPE_CODE_FUNC)
+    return;
 
-        *pos += 1;
-        arg1 = resolve_subexp (expp, pos, 0, NULL);
-        if (arg1 == NULL)
-          resolve_subexp (expp, pos, 1, NULL);
-        else
-          resolve_subexp (expp, pos, 1, value_type (arg1));
-        break;
-      }
+  if (TYPE_NFIELDS (type) > 0)
+    {
+      int i;
 
-    case UNOP_CAST:
-      *pos += 3;
-      nargs = 1;
-      break;
+      fprintf_filtered (stream, " (");
+      for (i = 0; i < TYPE_NFIELDS (type); ++i)
+       {
+         if (i > 0)
+           fprintf_filtered (stream, "; ");
+         ada_print_type (TYPE_FIELD_TYPE (type, i), NULL, stream, -1, 0,
+                         flags);
+       }
+      fprintf_filtered (stream, ")");
+    }
+  if (TYPE_TARGET_TYPE (type) != NULL
+      && TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
+    {
+      fprintf_filtered (stream, " return ");
+      ada_print_type (TYPE_TARGET_TYPE (type), NULL, stream, -1, 0, flags);
+    }
+}
 
-    case BINOP_ADD:
-    case BINOP_SUB:
-    case BINOP_MUL:
-    case BINOP_DIV:
-    case BINOP_REM:
-    case BINOP_MOD:
-    case BINOP_EXP:
-    case BINOP_CONCAT:
-    case BINOP_LOGICAL_AND:
-    case BINOP_LOGICAL_OR:
-    case BINOP_BITWISE_AND:
-    case BINOP_BITWISE_IOR:
-    case BINOP_BITWISE_XOR:
-
-    case BINOP_EQUAL:
-    case BINOP_NOTEQUAL:
-    case BINOP_LESS:
-    case BINOP_GTR:
-    case BINOP_LEQ:
-    case BINOP_GEQ:
-
-    case BINOP_REPEAT:
-    case BINOP_SUBSCRIPT:
-    case BINOP_COMMA:
-      *pos += 1;
-      nargs = 2;
-      break;
-
-    case UNOP_NEG:
-    case UNOP_PLUS:
-    case UNOP_LOGICAL_NOT:
-    case UNOP_ABS:
-    case UNOP_IND:
-      *pos += 1;
-      nargs = 1;
-      break;
+/* Read and validate a set of numeric choices from the user in the
+   range 0 .. N_CHOICES-1.  Place the results in increasing
+   order in CHOICES[0 .. N-1], and return N.
 
-    case OP_LONG:
-    case OP_FLOAT:
-    case OP_VAR_VALUE:
-    case OP_VAR_MSYM_VALUE:
-      *pos += 4;
-      break;
+   The user types choices as a sequence of numbers on one line
+   separated by blanks, encoding them as follows:
 
-    case OP_TYPE:
-    case OP_BOOL:
-    case OP_LAST:
-    case OP_INTERNALVAR:
-      *pos += 3;
-      break;
+     + A choice of 0 means to cancel the selection, throwing an error.
+     + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1.
+     + The user chooses k by typing k+IS_ALL_CHOICE+1.
 
-    case UNOP_MEMVAL:
-      *pos += 3;
-      nargs = 1;
-      break;
+   The user is not allowed to choose more than MAX_RESULTS values.
 
-    case OP_REGISTER:
-      *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
-      break;
+   ANNOTATION_SUFFIX, if present, is used to annotate the input
+   prompts (for use with the -f switch).  */
 
-    case STRUCTOP_STRUCT:
-      *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
-      nargs = 1;
-      break;
+static int
+get_selections (int *choices, int n_choices, int max_results,
+                int is_all_choice, const char *annotation_suffix)
+{
+  const char *args;
+  const char *prompt;
+  int n_chosen;
+  int first_choice = is_all_choice ? 2 : 1;
 
-    case TERNOP_SLICE:
-      *pos += 1;
-      nargs = 3;
-      break;
+  prompt = getenv ("PS2");
+  if (prompt == NULL)
+    prompt = "> ";
 
-    case OP_STRING:
-      break;
+  args = command_line_input (prompt, annotation_suffix);
 
-    default:
-      error (_("Unexpected operator during name resolution"));
-    }
+  if (args == NULL)
+    error_no_arg (_("one or more choice numbers"));
 
-  argvec = XALLOCAVEC (struct value *, nargs + 1);
-  for (i = 0; i < nargs; i += 1)
-    argvec[i] = resolve_subexp (expp, pos, 1, NULL);
-  argvec[i] = NULL;
-  exp = *expp;
+  n_chosen = 0;
 
-  /* Pass two: perform any resolution on principal operator.  */
-  switch (op)
+  /* Set choices[0 .. n_chosen-1] to the users' choices in ascending
+     order, as given in args.  Choices are validated.  */
+  while (1)
     {
-    default:
-      break;
-
-    case OP_VAR_VALUE:
-      if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN)
-        {
-          struct block_symbol *candidates;
-          int n_candidates;
+      char *args2;
+      int choice, j;
 
-          n_candidates =
-            ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME
-                                    (exp->elts[pc + 2].symbol),
-                                    exp->elts[pc + 1].block, VAR_DOMAIN,
-                                    &candidates);
+      args = skip_spaces (args);
+      if (*args == '\0' && n_chosen == 0)
+        error_no_arg (_("one or more choice numbers"));
+      else if (*args == '\0')
+        break;
 
-          if (n_candidates > 1)
-            {
-              /* Types tend to get re-introduced locally, so if there
-                 are any local symbols that are not types, first filter
-                 out all types.  */
-              int j;
-              for (j = 0; j < n_candidates; j += 1)
-                switch (SYMBOL_CLASS (candidates[j].symbol))
-                  {
-                  case LOC_REGISTER:
-                  case LOC_ARG:
-                  case LOC_REF_ARG:
-                  case LOC_REGPARM_ADDR:
-                  case LOC_LOCAL:
-                  case LOC_COMPUTED:
-                    goto FoundNonType;
-                  default:
-                    break;
-                  }
-            FoundNonType:
-              if (j < n_candidates)
-                {
-                  j = 0;
-                  while (j < n_candidates)
-                    {
-                      if (SYMBOL_CLASS (candidates[j].symbol) == LOC_TYPEDEF)
-                        {
-                          candidates[j] = candidates[n_candidates - 1];
-                          n_candidates -= 1;
-                        }
-                      else
-                        j += 1;
-                    }
-                }
-            }
+      choice = strtol (args, &args2, 10);
+      if (args == args2 || choice < 0
+          || choice > n_choices + first_choice - 1)
+        error (_("Argument must be choice number"));
+      args = args2;
 
-          if (n_candidates == 0)
-            error (_("No definition found for %s"),
-                   SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
-          else if (n_candidates == 1)
-            i = 0;
-          else if (deprocedure_p
-                   && !is_nonfunction (candidates, n_candidates))
-            {
-              i = ada_resolve_function
-                (candidates, n_candidates, NULL, 0,
-                 SYMBOL_LINKAGE_NAME (exp->elts[pc + 2].symbol),
-                 context_type);
-              if (i < 0)
-                error (_("Could not find a match for %s"),
-                       SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
-            }
-          else
-            {
-              printf_filtered (_("Multiple matches for %s\n"),
-                               SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
-              user_select_syms (candidates, n_candidates, 1);
-              i = 0;
-            }
+      if (choice == 0)
+        error (_("cancelled"));
 
-          exp->elts[pc + 1].block = candidates[i].block;
-          exp->elts[pc + 2].symbol = candidates[i].symbol;
-          if (innermost_block == NULL
-              || contained_in (candidates[i].block, innermost_block))
-            innermost_block = candidates[i].block;
+      if (choice < first_choice)
+        {
+          n_chosen = n_choices;
+          for (j = 0; j < n_choices; j += 1)
+            choices[j] = j;
+          break;
         }
+      choice -= first_choice;
 
-      if (deprocedure_p
-          && (TYPE_CODE (SYMBOL_TYPE (exp->elts[pc + 2].symbol))
-              == TYPE_CODE_FUNC))
+      for (j = n_chosen - 1; j >= 0 && choice < choices[j]; j -= 1)
         {
-          replace_operator_with_call (expp, pc, 0, 0,
-                                      exp->elts[pc + 2].symbol,
-                                      exp->elts[pc + 1].block);
-          exp = *expp;
         }
-      break;
-
-    case OP_FUNCALL:
-      {
-        if (exp->elts[pc + 3].opcode == OP_VAR_VALUE
-            && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
-          {
-            struct block_symbol *candidates;
-            int n_candidates;
-
-            n_candidates =
-              ada_lookup_symbol_list (SYMBOL_LINKAGE_NAME
-                                      (exp->elts[pc + 5].symbol),
-                                      exp->elts[pc + 4].block, VAR_DOMAIN,
-                                      &candidates);
-            if (n_candidates == 1)
-              i = 0;
-            else
-              {
-                i = ada_resolve_function
-                  (candidates, n_candidates,
-                   argvec, nargs,
-                   SYMBOL_LINKAGE_NAME (exp->elts[pc + 5].symbol),
-                   context_type);
-                if (i < 0)
-                  error (_("Could not find a match for %s"),
-                         SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol));
-              }
 
-            exp->elts[pc + 4].block = candidates[i].block;
-            exp->elts[pc + 5].symbol = candidates[i].symbol;
-            if (innermost_block == NULL
-                || contained_in (candidates[i].block, innermost_block))
-              innermost_block = candidates[i].block;
-          }
-      }
-      break;
-    case BINOP_ADD:
-    case BINOP_SUB:
-    case BINOP_MUL:
-    case BINOP_DIV:
-    case BINOP_REM:
-    case BINOP_MOD:
-    case BINOP_CONCAT:
-    case BINOP_BITWISE_AND:
-    case BINOP_BITWISE_IOR:
-    case BINOP_BITWISE_XOR:
-    case BINOP_EQUAL:
-    case BINOP_NOTEQUAL:
-    case BINOP_LESS:
-    case BINOP_GTR:
-    case BINOP_LEQ:
-    case BINOP_GEQ:
-    case BINOP_EXP:
-    case UNOP_NEG:
-    case UNOP_PLUS:
-    case UNOP_LOGICAL_NOT:
-    case UNOP_ABS:
-      if (possible_user_operator_p (op, argvec))
+      if (j < 0 || choice != choices[j])
         {
-          struct block_symbol *candidates;
-          int n_candidates;
-
-          n_candidates =
-            ada_lookup_symbol_list (ada_decoded_op_name (op),
-                                    (struct block *) NULL, VAR_DOMAIN,
-                                    &candidates);
-          i = ada_resolve_function (candidates, n_candidates, argvec, nargs,
-                                    ada_decoded_op_name (op), NULL);
-          if (i < 0)
-            break;
+          int k;
 
-         replace_operator_with_call (expp, pc, nargs, 1,
-                                     candidates[i].symbol,
-                                     candidates[i].block);
-          exp = *expp;
+          for (k = n_chosen - 1; k > j; k -= 1)
+            choices[k + 1] = choices[k];
+          choices[j + 1] = choice;
+          n_chosen += 1;
         }
-      break;
+    }
 
-    case OP_TYPE:
-    case OP_REGISTER:
-      return NULL;
-    }
+  if (n_chosen > max_results)
+    error (_("Select no more than %d of the above"), max_results);
 
-  *pos = pc;
-  return evaluate_subexp_type (exp, pos);
+  return n_chosen;
 }
 
-/* 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.  */
-/* The term "match" here is rather loose.  The match is heuristic and
-   liberal.  */
+/* Given a list of NSYMS symbols in SYMS, select up to MAX_RESULTS>0
+   by asking the user (if necessary), returning the number selected,
+   and setting the first elements of SYMS items.  Error if no symbols
+   selected.  */
+
+/* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought
+   to be re-integrated one of these days.  */
 
 static int
-ada_type_match (struct type *ftype, struct type *atype, int may_deref)
+user_select_syms (struct block_symbol *syms, int nsyms, int max_results)
 {
-  ftype = ada_check_typedef (ftype);
-  atype = ada_check_typedef (atype);
+  int i;
+  int *chosen = XALLOCAVEC (int , nsyms);
+  int n_chosen;
+  int first_choice = (max_results == 1) ? 1 : 2;
+  const char *select_mode = multiple_symbols_select_mode ();
 
-  if (TYPE_CODE (ftype) == TYPE_CODE_REF)
-    ftype = TYPE_TARGET_TYPE (ftype);
-  if (TYPE_CODE (atype) == TYPE_CODE_REF)
-    atype = TYPE_TARGET_TYPE (atype);
+  if (max_results < 1)
+    error (_("Request to select 0 symbols!"));
+  if (nsyms <= 1)
+    return nsyms;
 
-  switch (TYPE_CODE (ftype))
+  if (select_mode == multiple_symbols_cancel)
+    error (_("\
+canceled because the command is ambiguous\n\
+See set/show multiple-symbol."));
+
+  /* If select_mode is "all", then return all possible symbols.
+     Only do that if more than one symbol can be selected, of course.
+     Otherwise, display the menu as usual.  */
+  if (select_mode == multiple_symbols_all && max_results > 1)
+    return nsyms;
+
+  printf_filtered (_("[0] cancel\n"));
+  if (max_results > 1)
+    printf_filtered (_("[1] all\n"));
+
+  sort_choices (syms, nsyms);
+
+  for (i = 0; i < nsyms; i += 1)
     {
-    default:
-      return TYPE_CODE (ftype) == TYPE_CODE (atype);
-    case TYPE_CODE_PTR:
-      if (TYPE_CODE (atype) == 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));
-    case TYPE_CODE_INT:
-    case TYPE_CODE_ENUM:
-    case TYPE_CODE_RANGE:
-      switch (TYPE_CODE (atype))
+      if (syms[i].symbol == NULL)
+        continue;
+
+      if (SYMBOL_CLASS (syms[i].symbol) == LOC_BLOCK)
         {
-        case TYPE_CODE_INT:
-        case TYPE_CODE_ENUM:
-        case TYPE_CODE_RANGE:
-          return 1;
-        default:
-          return 0;
+          struct symtab_and_line sal =
+            find_function_start_sal (syms[i].symbol, 1);
+
+         printf_filtered ("[%d] ", i + first_choice);
+         ada_print_symbol_signature (gdb_stdout, syms[i].symbol,
+                                     &type_print_raw_options);
+         if (sal.symtab == NULL)
+           printf_filtered (_(" at %p[<no source file available>%p]:%d\n"),
+                            metadata_style.style ().ptr (), nullptr, sal.line);
+         else
+           printf_filtered
+             (_(" at %ps:%d\n"),
+              styled_string (file_name_style.style (),
+                             symtab_to_filename_for_display (sal.symtab)),
+              sal.line);
+          continue;
         }
+      else
+        {
+          int is_enumeral =
+            (SYMBOL_CLASS (syms[i].symbol) == LOC_CONST
+             && SYMBOL_TYPE (syms[i].symbol) != NULL
+             && TYPE_CODE (SYMBOL_TYPE (syms[i].symbol)) == TYPE_CODE_ENUM);
+         struct symtab *symtab = NULL;
 
-    case TYPE_CODE_ARRAY:
-      return (TYPE_CODE (atype) == TYPE_CODE_ARRAY
-              || ada_is_array_descriptor_type (atype));
+         if (SYMBOL_OBJFILE_OWNED (syms[i].symbol))
+           symtab = symbol_symtab (syms[i].symbol);
 
-    case TYPE_CODE_STRUCT:
-      if (ada_is_array_descriptor_type (ftype))
-        return (TYPE_CODE (atype) == TYPE_CODE_ARRAY
-                || ada_is_array_descriptor_type (atype));
-      else
-        return (TYPE_CODE (atype) == TYPE_CODE_STRUCT
-                && !ada_is_array_descriptor_type (atype));
+          if (SYMBOL_LINE (syms[i].symbol) != 0 && symtab != NULL)
+           {
+             printf_filtered ("[%d] ", i + first_choice);
+             ada_print_symbol_signature (gdb_stdout, syms[i].symbol,
+                                         &type_print_raw_options);
+             printf_filtered (_(" at %s:%d\n"),
+                              symtab_to_filename_for_display (symtab),
+                              SYMBOL_LINE (syms[i].symbol));
+           }
+          else if (is_enumeral
+                   && TYPE_NAME (SYMBOL_TYPE (syms[i].symbol)) != NULL)
+            {
+              printf_filtered (("[%d] "), i + first_choice);
+              ada_print_type (SYMBOL_TYPE (syms[i].symbol), NULL,
+                              gdb_stdout, -1, 0, &type_print_raw_options);
+              printf_filtered (_("'(%s) (enumeral)\n"),
+                              syms[i].symbol->print_name ());
+            }
+         else
+           {
+             printf_filtered ("[%d] ", i + first_choice);
+             ada_print_symbol_signature (gdb_stdout, syms[i].symbol,
+                                         &type_print_raw_options);
 
-    case TYPE_CODE_UNION:
-    case TYPE_CODE_FLT:
-      return (TYPE_CODE (atype) == TYPE_CODE (ftype));
+             if (symtab != NULL)
+               printf_filtered (is_enumeral
+                                ? _(" in %s (enumeral)\n")
+                                : _(" at %s:?\n"),
+                                symtab_to_filename_for_display (symtab));
+             else
+               printf_filtered (is_enumeral
+                                ? _(" (enumeral)\n")
+                                : _(" at ?\n"));
+           }
+        }
     }
+
+  n_chosen = get_selections (chosen, nsyms, max_results, max_results > 1,
+                             "overload-choice");
+
+  for (i = 0; i < n_chosen; i += 1)
+    syms[i] = syms[chosen[i]];
+
+  return n_chosen;
 }
 
-/* Return non-zero if the formals of FUNC "sufficiently match" the
-   vector of actual argument types ACTUALS of size N_ACTUALS.  FUNC
-   may also be an enumeral, in which case it is treated as a 0-
-   argument function.  */
+/* Same as evaluate_type (*EXP), but resolves ambiguous symbol
+   references (marked by OP_VAR_VALUE nodes in which the symbol has an
+   undefined namespace) and converts operators that are
+   user-defined into appropriate function calls.  If CONTEXT_TYPE is
+   non-null, it provides a preferred result type [at the moment, only
+   type void has any effect---causing procedures to be preferred over
+   functions in calls].  A null CONTEXT_TYPE indicates that a non-void
+   return type is preferred.  May change (expand) *EXP.  */
 
-static int
-ada_args_match (struct symbol *func, struct value **actuals, int n_actuals)
+static void
+resolve (expression_up *expp, int void_context_p, int parse_completion,
+        innermost_block_tracker *tracker)
 {
-  int i;
-  struct type *func_type = SYMBOL_TYPE (func);
+  struct type *context_type = NULL;
+  int pc = 0;
 
-  if (SYMBOL_CLASS (func) == LOC_CONST
-      && TYPE_CODE (func_type) == TYPE_CODE_ENUM)
-    return (n_actuals == 0);
-  else if (func_type == NULL || TYPE_CODE (func_type) != TYPE_CODE_FUNC)
-    return 0;
+  if (void_context_p)
+    context_type = builtin_type ((*expp)->gdbarch)->builtin_void;
 
-  if (TYPE_NFIELDS (func_type) != n_actuals)
-    return 0;
+  resolve_subexp (expp, &pc, 1, context_type, parse_completion, tracker);
+}
 
-  for (i = 0; i < n_actuals; i += 1)
+/* Resolve the operator of the subexpression beginning at
+   position *POS of *EXPP.  "Resolving" consists of replacing
+   the symbols that have undefined namespaces in OP_VAR_VALUE nodes
+   with their resolutions, replacing built-in operators with
+   function calls to user-defined operators, where appropriate, and,
+   when DEPROCEDURE_P is non-zero, converting function-valued variables
+   into parameterless calls.  May expand *EXPP.  The CONTEXT_TYPE functions
+   are as in ada_resolve, above.  */
+
+static struct value *
+resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
+                struct type *context_type, int parse_completion,
+               innermost_block_tracker *tracker)
+{
+  int pc = *pos;
+  int i;
+  struct expression *exp;       /* Convenience: == *expp.  */
+  enum exp_opcode op = (*expp)->elts[pc].opcode;
+  struct value **argvec;        /* Vector of operand types (alloca'ed).  */
+  int nargs;                    /* Number of operands.  */
+  int oplen;
+
+  argvec = NULL;
+  nargs = 0;
+  exp = expp->get ();
+
+  /* Pass one: resolve operands, saving their types and updating *pos,
+     if needed.  */
+  switch (op)
     {
-      if (actuals[i] == NULL)
-        return 0;
+    case OP_FUNCALL:
+      if (exp->elts[pc + 3].opcode == OP_VAR_VALUE
+          && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
+        *pos += 7;
       else
         {
-          struct type *ftype = ada_check_typedef (TYPE_FIELD_TYPE (func_type,
-                                                                  i));
-          struct type *atype = ada_check_typedef (value_type (actuals[i]));
-
-          if (!ada_type_match (ftype, atype, 1))
-            return 0;
+          *pos += 3;
+          resolve_subexp (expp, pos, 0, NULL, parse_completion, tracker);
         }
-    }
-  return 1;
-}
+      nargs = longest_to_int (exp->elts[pc + 1].longconst);
+      break;
 
-/* False iff function type FUNC_TYPE definitely does not produce a value
-   compatible with type CONTEXT_TYPE.  Conservatively returns 1 if
-   FUNC_TYPE is not a valid function type with a non-null return type
-   or an enumerated type.  A null CONTEXT_TYPE indicates any non-void type.  */
+    case UNOP_ADDR:
+      *pos += 1;
+      resolve_subexp (expp, pos, 0, NULL, parse_completion, tracker);
+      break;
 
-static int
-return_match (struct type *func_type, struct type *context_type)
-{
-  struct type *return_type;
+    case UNOP_QUAL:
+      *pos += 3;
+      resolve_subexp (expp, pos, 1, check_typedef (exp->elts[pc + 1].type),
+                     parse_completion, tracker);
+      break;
 
-  if (func_type == NULL)
-    return 1;
+    case OP_ATR_MODULUS:
+    case OP_ATR_SIZE:
+    case OP_ATR_TAG:
+    case OP_ATR_FIRST:
+    case OP_ATR_LAST:
+    case OP_ATR_LENGTH:
+    case OP_ATR_POS:
+    case OP_ATR_VAL:
+    case OP_ATR_MIN:
+    case OP_ATR_MAX:
+    case TERNOP_IN_RANGE:
+    case BINOP_IN_BOUNDS:
+    case UNOP_IN_RANGE:
+    case OP_AGGREGATE:
+    case OP_OTHERS:
+    case OP_CHOICES:
+    case OP_POSITIONAL:
+    case OP_DISCRETE_RANGE:
+    case OP_NAME:
+      ada_forward_operator_length (exp, pc, &oplen, &nargs);
+      *pos += oplen;
+      break;
 
-  if (TYPE_CODE (func_type) == TYPE_CODE_FUNC)
-    return_type = get_base_type (TYPE_TARGET_TYPE (func_type));
-  else
-    return_type = get_base_type (func_type);
-  if (return_type == NULL)
-    return 1;
+    case BINOP_ASSIGN:
+      {
+        struct value *arg1;
 
-  context_type = get_base_type (context_type);
+        *pos += 1;
+        arg1 = resolve_subexp (expp, pos, 0, NULL, parse_completion, tracker);
+        if (arg1 == NULL)
+          resolve_subexp (expp, pos, 1, NULL, parse_completion, tracker);
+        else
+          resolve_subexp (expp, pos, 1, value_type (arg1), parse_completion,
+                         tracker);
+        break;
+      }
 
-  if (TYPE_CODE (return_type) == TYPE_CODE_ENUM)
-    return context_type == NULL || return_type == context_type;
-  else if (context_type == NULL)
-    return TYPE_CODE (return_type) != TYPE_CODE_VOID;
-  else
-    return TYPE_CODE (return_type) == TYPE_CODE (context_type);
-}
+    case UNOP_CAST:
+      *pos += 3;
+      nargs = 1;
+      break;
 
+    case BINOP_ADD:
+    case BINOP_SUB:
+    case BINOP_MUL:
+    case BINOP_DIV:
+    case BINOP_REM:
+    case BINOP_MOD:
+    case BINOP_EXP:
+    case BINOP_CONCAT:
+    case BINOP_LOGICAL_AND:
+    case BINOP_LOGICAL_OR:
+    case BINOP_BITWISE_AND:
+    case BINOP_BITWISE_IOR:
+    case BINOP_BITWISE_XOR:
 
-/* Returns the index in SYMS[0..NSYMS-1] that contains  the symbol for the
-   function (if any) that matches the types of the NARGS arguments in
-   ARGS.  If CONTEXT_TYPE is non-null and there is at least one match
-   that returns that type, then eliminate matches that don't.  If
-   CONTEXT_TYPE is void and there is at least one match that does not
-   return void, eliminate all matches that do.
+    case BINOP_EQUAL:
+    case BINOP_NOTEQUAL:
+    case BINOP_LESS:
+    case BINOP_GTR:
+    case BINOP_LEQ:
+    case BINOP_GEQ:
 
-   Asks the user if there is more than one match remaining.  Returns -1
-   if there is no such symbol or none is selected.  NAME is used
-   solely for messages.  May re-arrange and modify SYMS in
-   the process; the index returned is for the modified vector.  */
+    case BINOP_REPEAT:
+    case BINOP_SUBSCRIPT:
+    case BINOP_COMMA:
+      *pos += 1;
+      nargs = 2;
+      break;
 
-static int
-ada_resolve_function (struct block_symbol syms[],
-                      int nsyms, struct value **args, int nargs,
-                      const char *name, struct type *context_type)
-{
-  int fallback;
-  int k;
-  int m;                        /* Number of hits */
+    case UNOP_NEG:
+    case UNOP_PLUS:
+    case UNOP_LOGICAL_NOT:
+    case UNOP_ABS:
+    case UNOP_IND:
+      *pos += 1;
+      nargs = 1;
+      break;
 
-  m = 0;
-  /* In the first pass of the loop, we only accept functions matching
-     context_type.  If none are found, we add a second pass of the loop
-     where every function is accepted.  */
-  for (fallback = 0; m == 0 && fallback < 2; fallback++)
-    {
-      for (k = 0; k < nsyms; k += 1)
-        {
-          struct type *type = ada_check_typedef (SYMBOL_TYPE (syms[k].symbol));
+    case OP_LONG:
+    case OP_FLOAT:
+    case OP_VAR_VALUE:
+    case OP_VAR_MSYM_VALUE:
+      *pos += 4;
+      break;
 
-          if (ada_args_match (syms[k].symbol, args, nargs)
-              && (fallback || return_match (type, context_type)))
-            {
-              syms[m] = syms[k];
-              m += 1;
-            }
-        }
-    }
+    case OP_TYPE:
+    case OP_BOOL:
+    case OP_LAST:
+    case OP_INTERNALVAR:
+      *pos += 3;
+      break;
 
-  /* If we got multiple matches, ask the user which one to use.  Don't do this
-     interactive thing during completion, though, as the purpose of the
-     completion is providing a list of all possible matches.  Prompting the
-     user to filter it down would be completely unexpected in this case.  */
-  if (m == 0)
-    return -1;
-  else if (m > 1 && !parse_completion)
-    {
-      printf_filtered (_("Multiple matches for %s\n"), name);
-      user_select_syms (syms, m, 1);
-      return 0;
+    case UNOP_MEMVAL:
+      *pos += 3;
+      nargs = 1;
+      break;
+
+    case OP_REGISTER:
+      *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
+      break;
+
+    case STRUCTOP_STRUCT:
+      *pos += 4 + BYTES_TO_EXP_ELEM (exp->elts[pc + 1].longconst + 1);
+      nargs = 1;
+      break;
+
+    case TERNOP_SLICE:
+      *pos += 1;
+      nargs = 3;
+      break;
+
+    case OP_STRING:
+      break;
+
+    default:
+      error (_("Unexpected operator during name resolution"));
     }
-  return 0;
-}
 
-/* Returns true (non-zero) iff decoded name N0 should appear before N1
-   in a listing of choices during disambiguation (see sort_choices, below).
-   The idea is that overloadings of a subprogram name from the
-   same package should sort in their source order.  We settle for ordering
-   such symbols by their trailing number (__N  or $N).  */
+  argvec = XALLOCAVEC (struct value *, nargs + 1);
+  for (i = 0; i < nargs; i += 1)
+    argvec[i] = resolve_subexp (expp, pos, 1, NULL, parse_completion,
+                               tracker);
+  argvec[i] = NULL;
+  exp = expp->get ();
 
-static int
-encoded_ordered_before (const char *N0, const char *N1)
-{
-  if (N1 == NULL)
-    return 0;
-  else if (N0 == NULL)
-    return 1;
-  else
+  /* Pass two: perform any resolution on principal operator.  */
+  switch (op)
     {
-      int k0, k1;
+    default:
+      break;
 
-      for (k0 = strlen (N0) - 1; k0 > 0 && isdigit (N0[k0]); k0 -= 1)
-        ;
-      for (k1 = strlen (N1) - 1; k1 > 0 && isdigit (N1[k1]); k1 -= 1)
-        ;
-      if ((N0[k0] == '_' || N0[k0] == '$') && N0[k0 + 1] != '\000'
-          && (N1[k1] == '_' || N1[k1] == '$') && N1[k1 + 1] != '\000')
+    case OP_VAR_VALUE:
+      if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN)
         {
-          int n0, n1;
+          std::vector<struct block_symbol> candidates;
+          int n_candidates;
 
-          n0 = k0;
-          while (N0[n0] == '_' && n0 > 0 && N0[n0 - 1] == '_')
-            n0 -= 1;
-          n1 = k1;
-          while (N1[n1] == '_' && n1 > 0 && N1[n1 - 1] == '_')
-            n1 -= 1;
-          if (n0 == n1 && strncmp (N0, N1, n0) == 0)
-            return (atoi (N0 + k0 + 1) < atoi (N1 + k1 + 1));
-        }
-      return (strcmp (N0, N1) < 0);
-    }
-}
+          n_candidates =
+            ada_lookup_symbol_list (exp->elts[pc + 2].symbol->linkage_name (),
+                                    exp->elts[pc + 1].block, VAR_DOMAIN,
+                                    &candidates);
 
-/* Sort SYMS[0..NSYMS-1] to put the choices in a canonical order by the
-   encoded names.  */
+          if (n_candidates > 1)
+            {
+              /* Types tend to get re-introduced locally, so if there
+                 are any local symbols that are not types, first filter
+                 out all types.  */
+              int j;
+              for (j = 0; j < n_candidates; j += 1)
+                switch (SYMBOL_CLASS (candidates[j].symbol))
+                  {
+                  case LOC_REGISTER:
+                  case LOC_ARG:
+                  case LOC_REF_ARG:
+                  case LOC_REGPARM_ADDR:
+                  case LOC_LOCAL:
+                  case LOC_COMPUTED:
+                    goto FoundNonType;
+                  default:
+                    break;
+                  }
+            FoundNonType:
+              if (j < n_candidates)
+                {
+                  j = 0;
+                  while (j < n_candidates)
+                    {
+                      if (SYMBOL_CLASS (candidates[j].symbol) == LOC_TYPEDEF)
+                        {
+                          candidates[j] = candidates[n_candidates - 1];
+                          n_candidates -= 1;
+                        }
+                      else
+                        j += 1;
+                    }
+                }
+            }
 
-static void
-sort_choices (struct block_symbol syms[], int nsyms)
-{
-  int i;
+          if (n_candidates == 0)
+            error (_("No definition found for %s"),
+                   exp->elts[pc + 2].symbol->print_name ());
+          else if (n_candidates == 1)
+            i = 0;
+          else if (deprocedure_p
+                   && !is_nonfunction (candidates.data (), n_candidates))
+            {
+              i = ada_resolve_function
+                (candidates.data (), n_candidates, NULL, 0,
+                 exp->elts[pc + 2].symbol->linkage_name (),
+                 context_type, parse_completion);
+              if (i < 0)
+                error (_("Could not find a match for %s"),
+                       exp->elts[pc + 2].symbol->print_name ());
+            }
+          else
+            {
+              printf_filtered (_("Multiple matches for %s\n"),
+                               exp->elts[pc + 2].symbol->print_name ());
+              user_select_syms (candidates.data (), n_candidates, 1);
+              i = 0;
+            }
 
-  for (i = 1; i < nsyms; i += 1)
-    {
-      struct block_symbol sym = syms[i];
-      int j;
+          exp->elts[pc + 1].block = candidates[i].block;
+          exp->elts[pc + 2].symbol = candidates[i].symbol;
+         tracker->update (candidates[i]);
+        }
 
-      for (j = i - 1; j >= 0; j -= 1)
+      if (deprocedure_p
+          && (TYPE_CODE (SYMBOL_TYPE (exp->elts[pc + 2].symbol))
+              == TYPE_CODE_FUNC))
         {
-          if (encoded_ordered_before (SYMBOL_LINKAGE_NAME (syms[j].symbol),
-                                      SYMBOL_LINKAGE_NAME (sym.symbol)))
-            break;
-          syms[j + 1] = syms[j];
+          replace_operator_with_call (expp, pc, 0, 4,
+                                      exp->elts[pc + 2].symbol,
+                                      exp->elts[pc + 1].block);
+          exp = expp->get ();
         }
-      syms[j + 1] = sym;
-    }
-}
-
-/* Whether GDB should display formals and return types for functions in the
-   overloads selection menu.  */
-static int print_signatures = 1;
+      break;
 
-/* Print the signature for SYM on STREAM according to the FLAGS options.  For
-   all but functions, the signature is just the name of the symbol.  For
-   functions, this is the name of the function, the list of types for formals
-   and the return type (if any).  */
+    case OP_FUNCALL:
+      {
+        if (exp->elts[pc + 3].opcode == OP_VAR_VALUE
+            && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
+          {
+           std::vector<struct block_symbol> candidates;
+            int n_candidates;
 
-static void
-ada_print_symbol_signature (struct ui_file *stream, struct symbol *sym,
-                           const struct type_print_options *flags)
-{
-  struct type *type = SYMBOL_TYPE (sym);
+            n_candidates =
+              ada_lookup_symbol_list (exp->elts[pc + 5].symbol->linkage_name (),
+                                      exp->elts[pc + 4].block, VAR_DOMAIN,
+                                      &candidates);
 
-  fprintf_filtered (stream, "%s", SYMBOL_PRINT_NAME (sym));
-  if (!print_signatures
-      || type == NULL
-      || TYPE_CODE (type) != TYPE_CODE_FUNC)
-    return;
+            if (n_candidates == 1)
+              i = 0;
+            else
+              {
+                i = ada_resolve_function
+                  (candidates.data (), n_candidates,
+                   argvec, nargs,
+                   exp->elts[pc + 5].symbol->linkage_name (),
+                   context_type, parse_completion);
+                if (i < 0)
+                  error (_("Could not find a match for %s"),
+                         exp->elts[pc + 5].symbol->print_name ());
+              }
 
-  if (TYPE_NFIELDS (type) > 0)
-    {
-      int i;
+            exp->elts[pc + 4].block = candidates[i].block;
+            exp->elts[pc + 5].symbol = candidates[i].symbol;
+           tracker->update (candidates[i]);
+          }
+      }
+      break;
+    case BINOP_ADD:
+    case BINOP_SUB:
+    case BINOP_MUL:
+    case BINOP_DIV:
+    case BINOP_REM:
+    case BINOP_MOD:
+    case BINOP_CONCAT:
+    case BINOP_BITWISE_AND:
+    case BINOP_BITWISE_IOR:
+    case BINOP_BITWISE_XOR:
+    case BINOP_EQUAL:
+    case BINOP_NOTEQUAL:
+    case BINOP_LESS:
+    case BINOP_GTR:
+    case BINOP_LEQ:
+    case BINOP_GEQ:
+    case BINOP_EXP:
+    case UNOP_NEG:
+    case UNOP_PLUS:
+    case UNOP_LOGICAL_NOT:
+    case UNOP_ABS:
+      if (possible_user_operator_p (op, argvec))
+        {
+         std::vector<struct block_symbol> candidates;
+          int n_candidates;
 
-      fprintf_filtered (stream, " (");
-      for (i = 0; i < TYPE_NFIELDS (type); ++i)
-       {
-         if (i > 0)
-           fprintf_filtered (stream, "; ");
-         ada_print_type (TYPE_FIELD_TYPE (type, i), NULL, stream, -1, 0,
-                         flags);
-       }
-      fprintf_filtered (stream, ")");
-    }
-  if (TYPE_TARGET_TYPE (type) != NULL
-      && TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
-    {
-      fprintf_filtered (stream, " return ");
-      ada_print_type (TYPE_TARGET_TYPE (type), NULL, stream, -1, 0, flags);
-    }
-}
+          n_candidates =
+            ada_lookup_symbol_list (ada_decoded_op_name (op),
+                                   NULL, VAR_DOMAIN,
+                                    &candidates);
 
-/* Given a list of NSYMS symbols in SYMS, select up to MAX_RESULTS>0 
-   by asking the user (if necessary), returning the number selected, 
-   and setting the first elements of SYMS items.  Error if no symbols
-   selected.  */
+          i = ada_resolve_function (candidates.data (), n_candidates, argvec,
+                                   nargs, ada_decoded_op_name (op), NULL,
+                                   parse_completion);
+          if (i < 0)
+            break;
 
-/* NOTE: Adapted from decode_line_2 in symtab.c, with which it ought
-   to be re-integrated one of these days.  */
+         replace_operator_with_call (expp, pc, nargs, 1,
+                                     candidates[i].symbol,
+                                     candidates[i].block);
+          exp = expp->get ();
+        }
+      break;
 
-int
-user_select_syms (struct block_symbol *syms, int nsyms, int max_results)
-{
-  int i;
-  int *chosen = XALLOCAVEC (int , nsyms);
-  int n_chosen;
-  int first_choice = (max_results == 1) ? 1 : 2;
-  const char *select_mode = multiple_symbols_select_mode ();
+    case OP_TYPE:
+    case OP_REGISTER:
+      return NULL;
+    }
 
-  if (max_results < 1)
-    error (_("Request to select 0 symbols!"));
-  if (nsyms <= 1)
-    return nsyms;
+  *pos = pc;
+  if (exp->elts[pc].opcode == OP_VAR_MSYM_VALUE)
+    return evaluate_var_msym_value (EVAL_AVOID_SIDE_EFFECTS,
+                                   exp->elts[pc + 1].objfile,
+                                   exp->elts[pc + 2].msymbol);
+  else
+    return evaluate_subexp_type (exp, pos);
+}
 
-  if (select_mode == multiple_symbols_cancel)
-    error (_("\
-canceled because the command is ambiguous\n\
-See set/show multiple-symbol."));
-  
-  /* If select_mode is "all", then return all possible symbols.
-     Only do that if more than one symbol can be selected, of course.
-     Otherwise, display the menu as usual.  */
-  if (select_mode == multiple_symbols_all && max_results > 1)
-    return nsyms;
+/* 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.  */
+/* The term "match" here is rather loose.  The match is heuristic and
+   liberal.  */
 
-  printf_unfiltered (_("[0] cancel\n"));
-  if (max_results > 1)
-    printf_unfiltered (_("[1] all\n"));
+static int
+ada_type_match (struct type *ftype, struct type *atype, int may_deref)
+{
+  ftype = ada_check_typedef (ftype);
+  atype = ada_check_typedef (atype);
 
-  sort_choices (syms, nsyms);
+  if (TYPE_CODE (ftype) == TYPE_CODE_REF)
+    ftype = TYPE_TARGET_TYPE (ftype);
+  if (TYPE_CODE (atype) == TYPE_CODE_REF)
+    atype = TYPE_TARGET_TYPE (atype);
 
-  for (i = 0; i < nsyms; i += 1)
+  switch (TYPE_CODE (ftype))
     {
-      if (syms[i].symbol == NULL)
-        continue;
-
-      if (SYMBOL_CLASS (syms[i].symbol) == LOC_BLOCK)
-        {
-          struct symtab_and_line sal =
-            find_function_start_sal (syms[i].symbol, 1);
-
-         printf_unfiltered ("[%d] ", i + first_choice);
-         ada_print_symbol_signature (gdb_stdout, syms[i].symbol,
-                                     &type_print_raw_options);
-         if (sal.symtab == NULL)
-           printf_unfiltered (_(" at <no source file available>:%d\n"),
-                              sal.line);
-         else
-           printf_unfiltered (_(" at %s:%d\n"),
-                              symtab_to_filename_for_display (sal.symtab),
-                              sal.line);
-          continue;
-        }
+    default:
+      return TYPE_CODE (ftype) == TYPE_CODE (atype);
+    case TYPE_CODE_PTR:
+      if (TYPE_CODE (atype) == 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));
+    case TYPE_CODE_INT:
+    case TYPE_CODE_ENUM:
+    case TYPE_CODE_RANGE:
+      switch (TYPE_CODE (atype))
         {
-          int is_enumeral =
-            (SYMBOL_CLASS (syms[i].symbol) == LOC_CONST
-             && SYMBOL_TYPE (syms[i].symbol) != NULL
-             && TYPE_CODE (SYMBOL_TYPE (syms[i].symbol)) == TYPE_CODE_ENUM);
-         struct symtab *symtab = NULL;
-
-         if (SYMBOL_OBJFILE_OWNED (syms[i].symbol))
-           symtab = symbol_symtab (syms[i].symbol);
-
-          if (SYMBOL_LINE (syms[i].symbol) != 0 && symtab != NULL)
-           {
-             printf_unfiltered ("[%d] ", i + first_choice);
-             ada_print_symbol_signature (gdb_stdout, syms[i].symbol,
-                                         &type_print_raw_options);
-             printf_unfiltered (_(" at %s:%d\n"),
-                                symtab_to_filename_for_display (symtab),
-                                SYMBOL_LINE (syms[i].symbol));
-           }
-          else if (is_enumeral
-                   && TYPE_NAME (SYMBOL_TYPE (syms[i].symbol)) != NULL)
-            {
-              printf_unfiltered (("[%d] "), i + first_choice);
-              ada_print_type (SYMBOL_TYPE (syms[i].symbol), NULL,
-                              gdb_stdout, -1, 0, &type_print_raw_options);
-              printf_unfiltered (_("'(%s) (enumeral)\n"),
-                                 SYMBOL_PRINT_NAME (syms[i].symbol));
-            }
-         else
-           {
-             printf_unfiltered ("[%d] ", i + first_choice);
-             ada_print_symbol_signature (gdb_stdout, syms[i].symbol,
-                                         &type_print_raw_options);
-
-             if (symtab != NULL)
-               printf_unfiltered (is_enumeral
-                                  ? _(" in %s (enumeral)\n")
-                                  : _(" at %s:?\n"),
-                                  symtab_to_filename_for_display (symtab));
-             else
-               printf_unfiltered (is_enumeral
-                                  ? _(" (enumeral)\n")
-                                  : _(" at ?\n"));
-           }
+        case TYPE_CODE_INT:
+        case TYPE_CODE_ENUM:
+        case TYPE_CODE_RANGE:
+          return 1;
+        default:
+          return 0;
         }
-    }
 
-  n_chosen = get_selections (chosen, nsyms, max_results, max_results > 1,
-                             "overload-choice");
+    case TYPE_CODE_ARRAY:
+      return (TYPE_CODE (atype) == TYPE_CODE_ARRAY
+              || ada_is_array_descriptor_type (atype));
 
-  for (i = 0; i < n_chosen; i += 1)
-    syms[i] = syms[chosen[i]];
+    case TYPE_CODE_STRUCT:
+      if (ada_is_array_descriptor_type (ftype))
+        return (TYPE_CODE (atype) == TYPE_CODE_ARRAY
+                || ada_is_array_descriptor_type (atype));
+      else
+        return (TYPE_CODE (atype) == TYPE_CODE_STRUCT
+                && !ada_is_array_descriptor_type (atype));
 
-  return n_chosen;
+    case TYPE_CODE_UNION:
+    case TYPE_CODE_FLT:
+      return (TYPE_CODE (atype) == TYPE_CODE (ftype));
+    }
 }
 
-/* Read and validate a set of numeric choices from the user in the
-   range 0 .. N_CHOICES-1.  Place the results in increasing
-   order in CHOICES[0 .. N-1], and return N.
+/* Return non-zero if the formals of FUNC "sufficiently match" the
+   vector of actual argument types ACTUALS of size N_ACTUALS.  FUNC
+   may also be an enumeral, in which case it is treated as a 0-
+   argument function.  */
 
-   The user types choices as a sequence of numbers on one line
-   separated by blanks, encoding them as follows:
+static int
+ada_args_match (struct symbol *func, struct value **actuals, int n_actuals)
+{
+  int i;
+  struct type *func_type = SYMBOL_TYPE (func);
 
-     + A choice of 0 means to cancel the selection, throwing an error.
-     + If IS_ALL_CHOICE, a choice of 1 selects the entire set 0 .. N_CHOICES-1.
-     + The user chooses k by typing k+IS_ALL_CHOICE+1.
+  if (SYMBOL_CLASS (func) == LOC_CONST
+      && TYPE_CODE (func_type) == TYPE_CODE_ENUM)
+    return (n_actuals == 0);
+  else if (func_type == NULL || TYPE_CODE (func_type) != TYPE_CODE_FUNC)
+    return 0;
 
-   The user is not allowed to choose more than MAX_RESULTS values.
+  if (TYPE_NFIELDS (func_type) != n_actuals)
+    return 0;
 
-   ANNOTATION_SUFFIX, if present, is used to annotate the input
-   prompts (for use with the -f switch).  */
+  for (i = 0; i < n_actuals; i += 1)
+    {
+      if (actuals[i] == NULL)
+        return 0;
+      else
+        {
+          struct type *ftype = ada_check_typedef (TYPE_FIELD_TYPE (func_type,
+                                                                  i));
+          struct type *atype = ada_check_typedef (value_type (actuals[i]));
 
-int
-get_selections (int *choices, int n_choices, int max_results,
-                int is_all_choice, const char *annotation_suffix)
-{
-  char *args;
-  const char *prompt;
-  int n_chosen;
-  int first_choice = is_all_choice ? 2 : 1;
+          if (!ada_type_match (ftype, atype, 1))
+            return 0;
+        }
+    }
+  return 1;
+}
 
-  prompt = getenv ("PS2");
-  if (prompt == NULL)
-    prompt = "> ";
+/* False iff function type FUNC_TYPE definitely does not produce a value
+   compatible with type CONTEXT_TYPE.  Conservatively returns 1 if
+   FUNC_TYPE is not a valid function type with a non-null return type
+   or an enumerated type.  A null CONTEXT_TYPE indicates any non-void type.  */
 
-  args = command_line_input (prompt, 0, annotation_suffix);
+static int
+return_match (struct type *func_type, struct type *context_type)
+{
+  struct type *return_type;
 
-  if (args == NULL)
-    error_no_arg (_("one or more choice numbers"));
+  if (func_type == NULL)
+    return 1;
 
-  n_chosen = 0;
+  if (TYPE_CODE (func_type) == TYPE_CODE_FUNC)
+    return_type = get_base_type (TYPE_TARGET_TYPE (func_type));
+  else
+    return_type = get_base_type (func_type);
+  if (return_type == NULL)
+    return 1;
 
-  /* Set choices[0 .. n_chosen-1] to the users' choices in ascending
-     order, as given in args.  Choices are validated.  */
-  while (1)
-    {
-      char *args2;
-      int choice, j;
+  context_type = get_base_type (context_type);
 
-      args = skip_spaces (args);
-      if (*args == '\0' && n_chosen == 0)
-        error_no_arg (_("one or more choice numbers"));
-      else if (*args == '\0')
-        break;
+  if (TYPE_CODE (return_type) == TYPE_CODE_ENUM)
+    return context_type == NULL || return_type == context_type;
+  else if (context_type == NULL)
+    return TYPE_CODE (return_type) != TYPE_CODE_VOID;
+  else
+    return TYPE_CODE (return_type) == TYPE_CODE (context_type);
+}
 
-      choice = strtol (args, &args2, 10);
-      if (args == args2 || choice < 0
-          || choice > n_choices + first_choice - 1)
-        error (_("Argument must be choice number"));
-      args = args2;
 
-      if (choice == 0)
-        error (_("cancelled"));
+/* Returns the index in SYMS[0..NSYMS-1] that contains  the symbol for the
+   function (if any) that matches the types of the NARGS arguments in
+   ARGS.  If CONTEXT_TYPE is non-null and there is at least one match
+   that returns that type, then eliminate matches that don't.  If
+   CONTEXT_TYPE is void and there is at least one match that does not
+   return void, eliminate all matches that do.
 
-      if (choice < first_choice)
-        {
-          n_chosen = n_choices;
-          for (j = 0; j < n_choices; j += 1)
-            choices[j] = j;
-          break;
-        }
-      choice -= first_choice;
+   Asks the user if there is more than one match remaining.  Returns -1
+   if there is no such symbol or none is selected.  NAME is used
+   solely for messages.  May re-arrange and modify SYMS in
+   the process; the index returned is for the modified vector.  */
 
-      for (j = n_chosen - 1; j >= 0 && choice < choices[j]; j -= 1)
-        {
-        }
+static int
+ada_resolve_function (struct block_symbol syms[],
+                      int nsyms, struct value **args, int nargs,
+                      const char *name, struct type *context_type,
+                     int parse_completion)
+{
+  int fallback;
+  int k;
+  int m;                        /* Number of hits */
 
-      if (j < 0 || choice != choices[j])
+  m = 0;
+  /* In the first pass of the loop, we only accept functions matching
+     context_type.  If none are found, we add a second pass of the loop
+     where every function is accepted.  */
+  for (fallback = 0; m == 0 && fallback < 2; fallback++)
+    {
+      for (k = 0; k < nsyms; k += 1)
         {
-          int k;
+          struct type *type = ada_check_typedef (SYMBOL_TYPE (syms[k].symbol));
 
-          for (k = n_chosen - 1; k > j; k -= 1)
-            choices[k + 1] = choices[k];
-          choices[j + 1] = choice;
-          n_chosen += 1;
+          if (ada_args_match (syms[k].symbol, args, nargs)
+              && (fallback || return_match (type, context_type)))
+            {
+              syms[m] = syms[k];
+              m += 1;
+            }
         }
     }
 
-  if (n_chosen > max_results)
-    error (_("Select no more than %d of the above"), max_results);
-
-  return n_chosen;
+  /* If we got multiple matches, ask the user which one to use.  Don't do this
+     interactive thing during completion, though, as the purpose of the
+     completion is providing a list of all possible matches.  Prompting the
+     user to filter it down would be completely unexpected in this case.  */
+  if (m == 0)
+    return -1;
+  else if (m > 1 && !parse_completion)
+    {
+      printf_filtered (_("Multiple matches for %s\n"), name);
+      user_select_syms (syms, m, 1);
+      return 0;
+    }
+  return 0;
 }
 
 /* Replace the operator of length OPLEN at position PC in *EXPP with a call
@@ -4105,7 +4034,7 @@ get_selections (int *choices, int n_choices, int max_results,
    arguments.  Update *EXPP as needed to hold more space.  */
 
 static void
-replace_operator_with_call (struct expression **expp, int pc, int nargs,
+replace_operator_with_call (expression_up *expp, int pc, int nargs,
                             int oplen, struct symbol *sym,
                             const struct block *block)
 {
@@ -4114,7 +4043,7 @@ replace_operator_with_call (struct expression **expp, int pc, int nargs,
   struct expression *newexp = (struct expression *)
     xzalloc (sizeof (struct expression)
              + EXP_ELEM_TO_BYTES ((*expp)->nelts + 7 - oplen));
-  struct expression *exp = *expp;
+  struct expression *exp = expp->get ();
 
   newexp->nelts = exp->nelts + 7 - oplen;
   newexp->language_defn = exp->language_defn;
@@ -4130,8 +4059,7 @@ replace_operator_with_call (struct expression **expp, int pc, int nargs,
   newexp->elts[pc + 4].block = block;
   newexp->elts[pc + 5].symbol = sym;
 
-  *expp = newexp;
-  xfree (exp);
+  expp->reset (newexp);
 }
 
 /* Type-class predicates */
@@ -4330,14 +4258,11 @@ ada_parse_renaming (struct symbol *sym,
     {
     default:
       return ADA_NOT_RENAMING;
-    case LOC_TYPEDEF:
-      return parse_old_style_renaming (SYMBOL_TYPE (sym), 
-                                      renamed_entity, len, renaming_expr);
     case LOC_LOCAL:
     case LOC_STATIC:
     case LOC_COMPUTED:
     case LOC_OPTIMIZED_OUT:
-      info = strstr (SYMBOL_LINKAGE_NAME (sym), "___XR");
+      info = strstr (sym->linkage_name (), "___XR");
       if (info == NULL)
        return ADA_NOT_RENAMING;
       switch (info[5])
@@ -4376,65 +4301,6 @@ ada_parse_renaming (struct symbol *sym,
   return kind;
 }
 
-/* Assuming TYPE encodes a renaming according to the old encoding in
-   exp_dbug.ads, returns details of that renaming in *RENAMED_ENTITY,
-   *LEN, and *RENAMING_EXPR, as for ada_parse_renaming, above.  Returns
-   ADA_NOT_RENAMING otherwise.  */
-static enum ada_renaming_category
-parse_old_style_renaming (struct type *type,
-                         const char **renamed_entity, int *len, 
-                         const char **renaming_expr)
-{
-  enum ada_renaming_category kind;
-  const char *name;
-  const char *info;
-  const char *suffix;
-
-  if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM 
-      || TYPE_NFIELDS (type) != 1)
-    return ADA_NOT_RENAMING;
-
-  name = type_name_no_tag (type);
-  if (name == NULL)
-    return ADA_NOT_RENAMING;
-  
-  name = strstr (name, "___XR");
-  if (name == NULL)
-    return ADA_NOT_RENAMING;
-  switch (name[5])
-    {
-    case '\0':
-    case '_':
-      kind = ADA_OBJECT_RENAMING;
-      break;
-    case 'E':
-      kind = ADA_EXCEPTION_RENAMING;
-      break;
-    case 'P':
-      kind = ADA_PACKAGE_RENAMING;
-      break;
-    case 'S':
-      kind = ADA_SUBPROGRAM_RENAMING;
-      break;
-    default:
-      return ADA_NOT_RENAMING;
-    }
-
-  info = TYPE_FIELD_NAME (type, 0);
-  if (info == NULL)
-    return ADA_NOT_RENAMING;
-  if (renamed_entity != NULL)
-    *renamed_entity = info;
-  suffix = strstr (info, "___XE");
-  if (renaming_expr != NULL)
-    *renaming_expr = suffix + 5;
-  if (suffix == NULL || suffix == info)
-    return ADA_NOT_RENAMING;
-  if (len != NULL)
-    *len = suffix - info;
-  return kind;
-}
-
 /* Compute the value of the given RENAMING_SYM, which is expected to
    be a symbol encoding a renaming expression.  BLOCK is the block
    used to evaluate the renaming.  */
@@ -4445,7 +4311,7 @@ ada_read_renaming_var_value (struct symbol *renaming_sym,
 {
   const char *sym_name;
 
-  sym_name = SYMBOL_LINKAGE_NAME (renaming_sym);
+  sym_name = renaming_sym->linkage_name ();
   expression_up expr = parse_exp_1 (&sym_name, 0, block, 0);
   return evaluate_expression (expr.get ());
 }
@@ -4472,7 +4338,132 @@ ensure_lval (struct value *val)
       write_memory (addr, value_contents (val), len);
     }
 
-  return val;
+  return val;
+}
+
+/* Given ARG, a value of type (pointer or reference to a)*
+   structure/union, extract the component named NAME from the ultimate
+   target structure/union and return it as a value with its
+   appropriate type.
+
+   The routine searches for NAME among all members of the structure itself
+   and (recursively) among all members of any wrapper members
+   (e.g., '_parent').
+
+   If NO_ERR, then simply return NULL in case of error, rather than
+   calling error.  */
+
+static struct value *
+ada_value_struct_elt (struct value *arg, const char *name, int no_err)
+{
+  struct type *t, *t1;
+  struct value *v;
+  int check_tag;
+
+  v = NULL;
+  t1 = t = ada_check_typedef (value_type (arg));
+  if (TYPE_CODE (t) == TYPE_CODE_REF)
+    {
+      t1 = TYPE_TARGET_TYPE (t);
+      if (t1 == NULL)
+       goto BadValue;
+      t1 = ada_check_typedef (t1);
+      if (TYPE_CODE (t1) == TYPE_CODE_PTR)
+        {
+          arg = coerce_ref (arg);
+          t = t1;
+        }
+    }
+
+  while (TYPE_CODE (t) == TYPE_CODE_PTR)
+    {
+      t1 = TYPE_TARGET_TYPE (t);
+      if (t1 == NULL)
+       goto BadValue;
+      t1 = ada_check_typedef (t1);
+      if (TYPE_CODE (t1) == TYPE_CODE_PTR)
+        {
+          arg = value_ind (arg);
+          t = t1;
+        }
+      else
+        break;
+    }
+
+  if (TYPE_CODE (t1) != TYPE_CODE_STRUCT && TYPE_CODE (t1) != TYPE_CODE_UNION)
+    goto BadValue;
+
+  if (t1 == t)
+    v = ada_search_struct_field (name, arg, 0, t);
+  else
+    {
+      int bit_offset, bit_size, byte_offset;
+      struct type *field_type;
+      CORE_ADDR address;
+
+      if (TYPE_CODE (t) == TYPE_CODE_PTR)
+       address = value_address (ada_value_ind (arg));
+      else
+       address = value_address (ada_coerce_ref (arg));
+
+      /* Check to see if this is a tagged type.  We also need to handle
+         the case where the type is a reference to a tagged type, but
+         we have to be careful to exclude pointers to tagged types.
+         The latter should be shown as usual (as a pointer), whereas
+         a reference should mostly be transparent to the user.  */
+
+      if (ada_is_tagged_type (t1, 0)
+          || (TYPE_CODE (t1) == TYPE_CODE_REF
+              && ada_is_tagged_type (TYPE_TARGET_TYPE (t1), 0)))
+        {
+          /* We first try to find the searched field in the current type.
+            If not found then let's look in the fixed type.  */
+
+          if (!find_struct_field (name, t1, 0,
+                                  &field_type, &byte_offset, &bit_offset,
+                                  &bit_size, NULL))
+           check_tag = 1;
+         else
+           check_tag = 0;
+        }
+      else
+       check_tag = 0;
+
+      /* Convert to fixed type in all cases, so that we have proper
+        offsets to each field in unconstrained record types.  */
+      t1 = ada_to_fixed_type (ada_get_base_type (t1), NULL,
+                             address, NULL, check_tag);
+
+      if (find_struct_field (name, t1, 0,
+                             &field_type, &byte_offset, &bit_offset,
+                             &bit_size, NULL))
+        {
+          if (bit_size != 0)
+            {
+              if (TYPE_CODE (t) == TYPE_CODE_REF)
+                arg = ada_coerce_ref (arg);
+              else
+                arg = ada_value_ind (arg);
+              v = ada_value_primitive_packed_val (arg, NULL, byte_offset,
+                                                  bit_offset, bit_size,
+                                                  field_type);
+            }
+          else
+            v = value_at_lazy (field_type, address + byte_offset);
+        }
+    }
+
+  if (v != NULL || no_err)
+    return v;
+  else
+    error (_("There is no member named %s."), name);
+
+ BadValue:
+  if (no_err)
+    return NULL;
+  else
+    error (_("Attempt to extract a component of "
+            "a value that is not a record."));
 }
 
 /* Return the value ACTUAL, converted to be an appropriate value for a
@@ -4503,7 +4494,7 @@ ada_convert_actual (struct value *actual, struct type *formal_type0)
       if (TYPE_CODE (formal_target) == TYPE_CODE_ARRAY
           && ada_is_array_descriptor_type (actual_target))
        result = desc_data (actual);
-      else if (TYPE_CODE (actual_type) != TYPE_CODE_PTR)
+      else if (TYPE_CODE (formal_type) != TYPE_CODE_PTR)
         {
           if (VALUE_LVAL (actual) != lval_memory)
             {
@@ -4553,7 +4544,7 @@ value_pointer (struct value *value, struct type *type)
 
   addr = value_address (value);
   gdbarch_address_to_pointer (gdbarch, type, buf, addr);
-  addr = extract_unsigned_integer (buf, len, gdbarch_byte_order (gdbarch));
+  addr = extract_unsigned_integer (buf, len, type_byte_order (type));
   return addr;
 }
 
@@ -4739,8 +4730,7 @@ cache_symbol (const char *name, domain_enum domain, struct symbol *sym,
     return;
 
   h = msymbol_hash (name) % HASH_SIZE;
-  e = (struct cache_entry *) obstack_alloc (&sym_cache->cache_space,
-                                           sizeof (*e));
+  e = XOBNEW (&sym_cache->cache_space, cache_entry);
   e->next = sym_cache->root[h];
   sym_cache->root[h] = e;
   e->name = copy
@@ -4757,7 +4747,7 @@ cache_symbol (const char *name, domain_enum domain, struct symbol *sym,
    searching for all symbols matching LOOKUP_NAME.
 
    LOOKUP_NAME is expected to be a symbol name after transformation
-   for Ada lookups (see ada_name_for_lookup).  */
+   for Ada lookups.  */
 
 static symbol_name_match_type
 name_match_type_from_name (const char *lookup_name)
@@ -4775,11 +4765,11 @@ standard_lookup (const char *name, const struct block *block,
                  domain_enum domain)
 {
   /* Initialize it just to avoid a GCC false warning.  */
-  struct block_symbol sym = {NULL, NULL};
+  struct block_symbol sym = {};
 
   if (lookup_cached_symbol (name, domain, &sym.symbol, NULL))
     return sym.symbol;
-  sym = lookup_symbol_in_language (name, block, domain, language_c, 0);
+  ada_lookup_encoded_symbol (name, block, domain, &sym);
   cache_symbol (name, domain, sym.symbol, sym.block);
   return sym.symbol;
 }
@@ -4842,8 +4832,8 @@ lesseq_defined_than (struct symbol *sym0, struct symbol *sym1)
       {
         struct type *type0 = SYMBOL_TYPE (sym0);
         struct type *type1 = SYMBOL_TYPE (sym1);
-        const char *name0 = SYMBOL_LINKAGE_NAME (sym0);
-        const char *name1 = SYMBOL_LINKAGE_NAME (sym1);
+        const char *name0 = sym0->linkage_name ();
+        const char *name1 = sym1->linkage_name ();
         int len0 = strlen (name0);
 
         return
@@ -4855,6 +4845,15 @@ lesseq_defined_than (struct symbol *sym0, struct symbol *sym1)
     case LOC_CONST:
       return SYMBOL_VALUE (sym0) == SYMBOL_VALUE (sym1)
         && equiv_types (SYMBOL_TYPE (sym0), SYMBOL_TYPE (sym1));
+
+    case LOC_STATIC:
+      {
+        const char *name0 = sym0->linkage_name ();
+        const char *name1 = sym1->linkage_name ();
+        return (strcmp (name0, name1) == 0
+                && SYMBOL_VALUE_ADDRESS (sym0) == SYMBOL_VALUE_ADDRESS (sym1));
+      }
+
     default:
       return 0;
     }
@@ -4932,8 +4931,6 @@ struct bound_minimal_symbol
 ada_lookup_simple_minsym (const char *name)
 {
   struct bound_minimal_symbol result;
-  struct objfile *objfile;
-  struct minimal_symbol *msymbol;
 
   memset (&result, 0, sizeof (result));
 
@@ -4943,16 +4940,19 @@ ada_lookup_simple_minsym (const char *name)
   symbol_name_matcher_ftype *match_name
     = ada_get_symbol_name_matcher (lookup_name);
 
-  ALL_MSYMBOLS (objfile, msymbol)
-  {
-    if (match_name (MSYMBOL_LINKAGE_NAME (msymbol), lookup_name, NULL)
-        && MSYMBOL_TYPE (msymbol) != mst_solib_trampoline)
-      {
-       result.minsym = msymbol;
-       result.objfile = objfile;
-       break;
-      }
-  }
+  for (objfile *objfile : current_program_space->objfiles ())
+    {
+      for (minimal_symbol *msymbol : objfile->msymbols ())
+       {
+         if (match_name (msymbol->linkage_name (), lookup_name, NULL)
+             && MSYMBOL_TYPE (msymbol) != mst_solib_trampoline)
+           {
+             result.minsym = msymbol;
+             result.objfile = objfile;
+             break;
+           }
+       }
+    }
 
   return result;
 }
@@ -5045,7 +5045,7 @@ ada_identical_enum_types_p (struct type *type1, struct type *type2)
    So, for practical purposes, we consider them as the same.  */
 
 static int
-symbols_are_identical_enums (struct block_symbol *syms, int nsyms)
+symbols_are_identical_enums (const std::vector<struct block_symbol> &syms)
 {
   int i;
 
@@ -5057,17 +5057,17 @@ symbols_are_identical_enums (struct block_symbol *syms, int nsyms)
      (see ada_identical_enum_types_p).  */
 
   /* Quick check: All symbols should have an enum type.  */
-  for (i = 0; i < nsyms; i++)
+  for (i = 0; i < syms.size (); i++)
     if (TYPE_CODE (SYMBOL_TYPE (syms[i].symbol)) != TYPE_CODE_ENUM)
       return 0;
 
   /* Quick check: They should all have the same value.  */
-  for (i = 1; i < nsyms; i++)
+  for (i = 1; i < syms.size (); i++)
     if (SYMBOL_VALUE (syms[i].symbol) != SYMBOL_VALUE (syms[0].symbol))
       return 0;
 
   /* Quick check: They should all have the same number of enumerals.  */
-  for (i = 1; i < nsyms; i++)
+  for (i = 1; i < syms.size (); i++)
     if (TYPE_NFIELDS (SYMBOL_TYPE (syms[i].symbol))
         != TYPE_NFIELDS (SYMBOL_TYPE (syms[0].symbol)))
       return 0;
@@ -5075,7 +5075,7 @@ symbols_are_identical_enums (struct block_symbol *syms, int nsyms)
   /* All the sanity checks passed, so we might have a set of
      identical enumeration types.  Perform a more complete
      comparison of the type of each symbol.  */
-  for (i = 1; i < nsyms; i++)
+  for (i = 1; i < syms.size (); i++)
     if (!ada_identical_enum_types_p (SYMBOL_TYPE (syms[i].symbol),
                                      SYMBOL_TYPE (syms[0].symbol)))
       return 0;
@@ -5083,7 +5083,7 @@ symbols_are_identical_enums (struct block_symbol *syms, int nsyms)
   return 1;
 }
 
-/* Remove any non-debugging symbols in SYMS[0 .. NSYMS-1] that definitely
+/* Remove any non-debugging symbols in SYMS that definitely
    duplicate other symbols in the list (The only case I know of where
    this happens is when object files containing stabs-in-ecoff are
    linked with files containing ordinary ecoff debugging symbols (or no
@@ -5091,34 +5091,34 @@ symbols_are_identical_enums (struct block_symbol *syms, int nsyms)
    Returns the number of items in the modified list.  */
 
 static int
-remove_extra_symbols (struct block_symbol *syms, int nsyms)
+remove_extra_symbols (std::vector<struct block_symbol> *syms)
 {
   int i, j;
 
   /* We should never be called with less than 2 symbols, as there
      cannot be any extra symbol in that case.  But it's easy to
      handle, since we have nothing to do in that case.  */
-  if (nsyms < 2)
-    return nsyms;
+  if (syms->size () < 2)
+    return syms->size ();
 
   i = 0;
-  while (i < nsyms)
+  while (i < syms->size ())
     {
       int remove_p = 0;
 
       /* If two symbols have the same name and one of them is a stub type,
          the get rid of the stub.  */
 
-      if (TYPE_STUB (SYMBOL_TYPE (syms[i].symbol))
-          && SYMBOL_LINKAGE_NAME (syms[i].symbol) != NULL)
+      if (TYPE_STUB (SYMBOL_TYPE ((*syms)[i].symbol))
+          && (*syms)[i].symbol->linkage_name () != NULL)
         {
-          for (j = 0; j < nsyms; j++)
+          for (j = 0; j < syms->size (); j++)
             {
               if (j != i
-                  && !TYPE_STUB (SYMBOL_TYPE (syms[j].symbol))
-                  && SYMBOL_LINKAGE_NAME (syms[j].symbol) != NULL
-                  && strcmp (SYMBOL_LINKAGE_NAME (syms[i].symbol),
-                             SYMBOL_LINKAGE_NAME (syms[j].symbol)) == 0)
+                  && !TYPE_STUB (SYMBOL_TYPE ((*syms)[j].symbol))
+                  && (*syms)[j].symbol->linkage_name () != NULL
+                  && strcmp ((*syms)[i].symbol->linkage_name (),
+                             (*syms)[j].symbol->linkage_name ()) == 0)
                 remove_p = 1;
             }
         }
@@ -5126,30 +5126,26 @@ remove_extra_symbols (struct block_symbol *syms, int nsyms)
       /* Two symbols with the same name, same class and same address
          should be identical.  */
 
-      else if (SYMBOL_LINKAGE_NAME (syms[i].symbol) != NULL
-          && SYMBOL_CLASS (syms[i].symbol) == LOC_STATIC
-          && is_nondebugging_type (SYMBOL_TYPE (syms[i].symbol)))
+      else if ((*syms)[i].symbol->linkage_name () != NULL
+          && SYMBOL_CLASS ((*syms)[i].symbol) == LOC_STATIC
+          && is_nondebugging_type (SYMBOL_TYPE ((*syms)[i].symbol)))
         {
-          for (j = 0; j < nsyms; j += 1)
+          for (j = 0; j < syms->size (); j += 1)
             {
               if (i != j
-                  && SYMBOL_LINKAGE_NAME (syms[j].symbol) != NULL
-                  && strcmp (SYMBOL_LINKAGE_NAME (syms[i].symbol),
-                             SYMBOL_LINKAGE_NAME (syms[j].symbol)) == 0
-                  && SYMBOL_CLASS (syms[i].symbol)
-                      == SYMBOL_CLASS (syms[j].symbol)
-                  && SYMBOL_VALUE_ADDRESS (syms[i].symbol)
-                  == SYMBOL_VALUE_ADDRESS (syms[j].symbol))
+                  && (*syms)[j].symbol->linkage_name () != NULL
+                  && strcmp ((*syms)[i].symbol->linkage_name (),
+                             (*syms)[j].symbol->linkage_name ()) == 0
+                  && SYMBOL_CLASS ((*syms)[i].symbol)
+                      == SYMBOL_CLASS ((*syms)[j].symbol)
+                  && SYMBOL_VALUE_ADDRESS ((*syms)[i].symbol)
+                  == SYMBOL_VALUE_ADDRESS ((*syms)[j].symbol))
                 remove_p = 1;
             }
         }
       
       if (remove_p)
-        {
-          for (j = i + 1; j < nsyms; j += 1)
-            syms[j - 1] = syms[j];
-          nsyms -= 1;
-        }
+       syms->erase (syms->begin () + i);
 
       i += 1;
     }
@@ -5166,18 +5162,18 @@ remove_extra_symbols (struct block_symbol *syms, int nsyms)
      to ask the user to disambiguate anyways.  And if we have to
      present a multiple-choice menu, it's less confusing if the list
      isn't missing some choices that were identical and yet distinct.  */
-  if (symbols_are_identical_enums (syms, nsyms))
-    nsyms = 1;
+  if (symbols_are_identical_enums (*syms))
+    syms->resize (1);
 
-  return nsyms;
+  return syms->size ();
 }
 
 /* Given a type that corresponds to a renaming entity, use the type name
    to extract the scope (package name or function name, fully qualified,
    and following the GNAT encoding convention) where this renaming has been
-   defined.  The string returned needs to be deallocated after use.  */
+   defined.  */
 
-static char *
+static std::string
 xget_renaming_scope (struct type *renaming_type)
 {
   /* The renaming types adhere to the following convention:
@@ -5185,11 +5181,9 @@ xget_renaming_scope (struct type *renaming_type)
      So, to extract the scope, we search for the "___XR" extension,
      and then backtrack until we find the first "__".  */
 
-  const char *name = type_name_no_tag (renaming_type);
+  const char *name = TYPE_NAME (renaming_type);
   const char *suffix = strstr (name, "___XR");
   const char *last;
-  int scope_len;
-  char *scope;
 
   /* Now, backtrack a bit until we find the first "__".  Start looking
      at suffix - 3, as the <rename> part is at least one character long.  */
@@ -5199,14 +5193,7 @@ xget_renaming_scope (struct type *renaming_type)
       break;
 
   /* Make a copy of scope and return it.  */
-
-  scope_len = last - name;
-  scope = (char *) xmalloc ((scope_len + 1) * sizeof (char));
-
-  strncpy (scope, name, scope_len);
-  scope[scope_len] = '\0';
-
-  return scope;
+  return std::string (name, last);
 }
 
 /* Return nonzero if NAME corresponds to a package name.  */
@@ -5220,8 +5207,6 @@ is_package_name (const char *name)
      to NAME not existing in our list of symbols.  There is only one
      small complication with library-level functions (see below).  */
 
-  char *fun_name;
-
   /* If it is a function that has not been defined at library level,
      then we should be able to look it up in the symbols.  */
   if (standard_lookup (name, NULL, VAR_DOMAIN) != NULL)
@@ -5235,9 +5220,9 @@ is_package_name (const char *name)
   if (strstr (name, "__") != NULL)
     return 0;
 
-  fun_name = xstrprintf ("_ada_%s", name);
+  std::string fun_name = string_printf ("_ada_%s", name);
 
-  return (standard_lookup (fun_name, NULL, VAR_DOMAIN) == NULL);
+  return (standard_lookup (fun_name.c_str (), NULL, VAR_DOMAIN) == NULL);
 }
 
 /* Return nonzero if SYM corresponds to a renaming entity that is
@@ -5246,21 +5231,14 @@ is_package_name (const char *name)
 static int
 old_renaming_is_invisible (const struct symbol *sym, const char *function_name)
 {
-  char *scope;
-  struct cleanup *old_chain;
-
   if (SYMBOL_CLASS (sym) != LOC_TYPEDEF)
     return 0;
 
-  scope = xget_renaming_scope (SYMBOL_TYPE (sym));
-  old_chain = make_cleanup (xfree, scope);
+  std::string scope = xget_renaming_scope (SYMBOL_TYPE (sym));
 
   /* If the rename has been defined in a package, then it is visible.  */
-  if (is_package_name (scope))
-    {
-      do_cleanups (old_chain);
-      return 0;
-    }
+  if (is_package_name (scope.c_str ()))
+    return 0;
 
   /* Check that the rename is in the current function scope by checking
      that its name starts with SCOPE.  */
@@ -5272,12 +5250,7 @@ old_renaming_is_invisible (const struct symbol *sym, const char *function_name)
   if (startswith (function_name, "_ada_"))
     function_name += 5;
 
-  {
-    int is_invisible = !startswith (function_name, scope);
-
-    do_cleanups (old_chain);
-    return is_invisible;
-  }
+  return !startswith (function_name, scope.c_str ());
 }
 
 /* Remove entries from SYMS that corresponds to a renaming entity that
@@ -5318,8 +5291,8 @@ old_renaming_is_invisible (const struct symbol *sym, const char *function_name)
         the user will be unable to print such rename entities.  */
 
 static int
-remove_irrelevant_renamings (struct block_symbol *syms,
-                            int nsyms, const struct block *current_block)
+remove_irrelevant_renamings (std::vector<struct block_symbol> *syms,
+                            const struct block *current_block)
 {
   struct symbol *current_function;
   const char *current_function_name;
@@ -5330,16 +5303,16 @@ remove_irrelevant_renamings (struct block_symbol *syms,
      a simple variable foo in the same block, discard the latter.
      First, zero out such symbols, then compress.  */
   is_new_style_renaming = 0;
-  for (i = 0; i < nsyms; i += 1)
+  for (i = 0; i < syms->size (); i += 1)
     {
-      struct symbol *sym = syms[i].symbol;
-      const struct block *block = syms[i].block;
+      struct symbol *sym = (*syms)[i].symbol;
+      const struct block *block = (*syms)[i].block;
       const char *name;
       const char *suffix;
 
       if (sym == NULL || SYMBOL_CLASS (sym) == LOC_TYPEDEF)
        continue;
-      name = SYMBOL_LINKAGE_NAME (sym);
+      name = sym->linkage_name ();
       suffix = strstr (name, "___XR");
 
       if (suffix != NULL)
@@ -5348,22 +5321,22 @@ remove_irrelevant_renamings (struct block_symbol *syms,
          int j;
 
          is_new_style_renaming = 1;
-         for (j = 0; j < nsyms; j += 1)
-           if (i != j && syms[j].symbol != NULL
-               && strncmp (name, SYMBOL_LINKAGE_NAME (syms[j].symbol),
+         for (j = 0; j < syms->size (); j += 1)
+           if (i != j && (*syms)[j].symbol != NULL
+               && strncmp (name, (*syms)[j].symbol->linkage_name (),
                            name_len) == 0
-               && block == syms[j].block)
-             syms[j].symbol = NULL;
+               && block == (*syms)[j].block)
+             (*syms)[j].symbol = NULL;
        }
     }
   if (is_new_style_renaming)
     {
       int j, k;
 
-      for (j = k = 0; j < nsyms; j += 1)
-       if (syms[j].symbol != NULL)
+      for (j = k = 0; j < syms->size (); j += 1)
+       if ((*syms)[j].symbol != NULL)
            {
-             syms[k] = syms[j];
+             (*syms)[k] = (*syms)[j];
              k += 1;
            }
       return k;
@@ -5373,38 +5346,33 @@ remove_irrelevant_renamings (struct block_symbol *syms,
      Abort if unable to do so.  */
 
   if (current_block == NULL)
-    return nsyms;
+    return syms->size ();
 
   current_function = block_linkage_function (current_block);
   if (current_function == NULL)
-    return nsyms;
+    return syms->size ();
 
-  current_function_name = SYMBOL_LINKAGE_NAME (current_function);
+  current_function_name = current_function->linkage_name ();
   if (current_function_name == NULL)
-    return nsyms;
+    return syms->size ();
 
   /* Check each of the symbols, and remove it from the list if it is
      a type corresponding to a renaming that is out of the scope of
      the current block.  */
 
   i = 0;
-  while (i < nsyms)
+  while (i < syms->size ())
     {
-      if (ada_parse_renaming (syms[i].symbol, NULL, NULL, NULL)
+      if (ada_parse_renaming ((*syms)[i].symbol, NULL, NULL, NULL)
           == ADA_OBJECT_RENAMING
-          && old_renaming_is_invisible (syms[i].symbol, current_function_name))
-        {
-          int j;
-
-          for (j = i + 1; j < nsyms; j += 1)
-            syms[j - 1] = syms[j];
-          nsyms -= 1;
-        }
+          && old_renaming_is_invisible ((*syms)[i].symbol,
+                                       current_function_name))
+       syms->erase (syms->begin () + i);
       else
         i += 1;
     }
 
-  return nsyms;
+  return syms->size ();
 }
 
 /* Add to OBSTACKP all symbols from BLOCK (and its super-blocks)
@@ -5454,8 +5422,8 @@ struct match_data
   int found_sym;
 };
 
-/* A callback for add_nonlocal_symbols that adds SYM, found in BLOCK,
-   to a list of symbols.  DATA0 is a pointer to a struct match_data *
+/* 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 obstack 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
@@ -5463,11 +5431,13 @@ struct match_data
    marking the end of a block, the argument symbol is added if no
    other has been found.  */
 
-static int
-aux_add_nonlocal_symbols (struct block *block, struct symbol *sym, void *data0)
+static bool
+aux_add_nonlocal_symbols (struct block_symbol *bsym,
+                         struct match_data *data)
 {
-  struct match_data *data = (struct match_data *) data0;
-  
+  const struct block *block = bsym->block;
+  struct symbol *sym = bsym->symbol;
+
   if (sym == NULL)
     {
       if (!data->found_sym && data->arg_sym != NULL) 
@@ -5480,7 +5450,7 @@ aux_add_nonlocal_symbols (struct block *block, struct symbol *sym, void *data0)
   else 
     {
       if (SYMBOL_CLASS (sym) == LOC_UNRESOLVED)
-       return 0;
+       return true;
       else if (SYMBOL_IS_ARGUMENT (sym))
        data->arg_sym = sym;
       else
@@ -5491,7 +5461,7 @@ aux_add_nonlocal_symbols (struct block *block, struct symbol *sym, void *data0)
                           block);
        }
     }
-  return 0;
+  return true;
 }
 
 /* Helper for add_nonlocal_symbols.  Find symbols in DOMAIN which are
@@ -5655,8 +5625,6 @@ add_nonlocal_symbols (struct obstack *obstackp,
                      const lookup_name_info &lookup_name,
                      domain_enum domain, int global)
 {
-  struct objfile *objfile;
-  struct compunit_symtab *cu;
   struct match_data data;
 
   memset (&data, 0, sizeof data);
@@ -5664,24 +5632,21 @@ add_nonlocal_symbols (struct obstack *obstackp,
 
   bool is_wild_match = lookup_name.ada ().wild_match_p ();
 
-  ALL_OBJFILES (objfile)
+  auto callback = [&] (struct block_symbol *bsym)
+    {
+      return aux_add_nonlocal_symbols (bsym, &data);
+    };
+
+  for (objfile *objfile : current_program_space->objfiles ())
     {
       data.objfile = objfile;
 
-      if (is_wild_match)
-       objfile->sf->qf->map_matching_symbols (objfile, lookup_name.name ().c_str (),
-                                              domain, global,
-                                              aux_add_nonlocal_symbols, &data,
-                                              symbol_name_match_type::WILD,
-                                              NULL);
-      else
-       objfile->sf->qf->map_matching_symbols (objfile, lookup_name.name ().c_str (),
-                                              domain, global,
-                                              aux_add_nonlocal_symbols, &data,
-                                              symbol_name_match_type::FULL,
-                                              compare_names);
+      objfile->sf->qf->map_matching_symbols (objfile, lookup_name,
+                                            domain, global, callback,
+                                            (is_wild_match
+                                             ? NULL : compare_names));
 
-      ALL_OBJFILE_COMPUNITS (objfile, cu)
+      for (compunit_symtab *cu : objfile->compunits ())
        {
          const struct block *global_block
            = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cu), GLOBAL_BLOCK);
@@ -5695,16 +5660,14 @@ add_nonlocal_symbols (struct obstack *obstackp,
   if (num_defns_collected (obstackp) == 0 && global && !is_wild_match)
     {
       const char *name = ada_lookup_name (lookup_name);
-      std::string name1 = std::string ("<_ada_") + name + '>';
+      lookup_name_info name1 (std::string ("<_ada_") + name + '>',
+                             symbol_name_match_type::FULL);
 
-      ALL_OBJFILES (objfile)
+      for (objfile *objfile : current_program_space->objfiles ())
         {
          data.objfile = objfile;
-         objfile->sf->qf->map_matching_symbols (objfile, name1.c_str (),
-                                                domain, global,
-                                                aux_add_nonlocal_symbols,
-                                                &data,
-                                                symbol_name_match_type::FULL,
+         objfile->sf->qf->map_matching_symbols (objfile, name1,
+                                                domain, global, callback,
                                                 compare_names);
        }
     }          
@@ -5796,10 +5759,9 @@ ada_add_all_symbols (struct obstack *obstackp,
 /* Find symbols in DOMAIN matching LOOKUP_NAME, in BLOCK and, if FULL_SEARCH
    is non-zero, enclosing scope and in global scopes, returning the number of
    matches.
-   Sets *RESULTS to point to a vector of (SYM,BLOCK) tuples,
-   indicating the symbols found and the blocks and symbol tables (if
-   any) in which they were found.  This vector is transient---good only to
-   the next call of ada_lookup_symbol_list.
+   Fills *RESULTS with (SYM,BLOCK) tuples, indicating the symbols
+   found and the blocks and symbol tables (if any) in which they were
+   found.
 
    When full_search is non-zero, any non-function/non-enumeral
    symbol match within the nest of blocks whose innermost member is BLOCK,
@@ -5814,21 +5776,23 @@ static int
 ada_lookup_symbol_list_worker (const lookup_name_info &lookup_name,
                               const struct block *block,
                               domain_enum domain,
-                              struct block_symbol **results,
+                              std::vector<struct block_symbol> *results,
                               int full_search)
 {
   int syms_from_global_search;
   int ndefns;
+  auto_obstack obstack;
 
-  obstack_free (&symbol_list_obstack, NULL);
-  obstack_init (&symbol_list_obstack);
-  ada_add_all_symbols (&symbol_list_obstack, block, lookup_name,
+  ada_add_all_symbols (&obstack, block, lookup_name,
                       domain, full_search, &syms_from_global_search);
 
-  ndefns = num_defns_collected (&symbol_list_obstack);
-  *results = defns_collected (&symbol_list_obstack, 1);
+  ndefns = num_defns_collected (&obstack);
 
-  ndefns = remove_extra_symbols (*results, ndefns);
+  struct block_symbol *base = defns_collected (&obstack, 1);
+  for (int i = 0; i < ndefns; ++i)
+    results->push_back (base[i]);
+
+  ndefns = remove_extra_symbols (results);
 
   if (ndefns == 0 && full_search && syms_from_global_search)
     cache_symbol (ada_lookup_name (lookup_name), domain, NULL, NULL);
@@ -5837,18 +5801,21 @@ ada_lookup_symbol_list_worker (const lookup_name_info &lookup_name,
     cache_symbol (ada_lookup_name (lookup_name), domain,
                  (*results)[0].symbol, (*results)[0].block);
 
-  ndefns = remove_irrelevant_renamings (*results, ndefns, block);
+  ndefns = remove_irrelevant_renamings (results, block);
+
   return ndefns;
 }
 
 /* Find symbols in DOMAIN matching NAME, in BLOCK and enclosing scope and
-   in global scopes, returning the number of matches, and setting *RESULTS
-   to a vector of (SYM,BLOCK) tuples.
+   in global scopes, returning the number of matches, and filling *RESULTS
+   with (SYM,BLOCK) tuples.
+
    See ada_lookup_symbol_list_worker for further details.  */
 
 int
 ada_lookup_symbol_list (const char *name, const struct block *block,
-                       domain_enum domain, struct block_symbol **results)
+                       domain_enum domain,
+                       std::vector<struct block_symbol> *results)
 {
   symbol_name_match_type name_match_type = name_match_type_from_name (name);
   lookup_name_info lookup_name (name, name_match_type);
@@ -5858,21 +5825,24 @@ ada_lookup_symbol_list (const char *name, const struct block *block,
 
 /* Implementation of the la_iterate_over_symbols method.  */
 
-static void
+static bool
 ada_iterate_over_symbols
   (const struct block *block, const lookup_name_info &name,
    domain_enum domain,
    gdb::function_view<symbol_found_callback_ftype> callback)
 {
   int ndefs, i;
-  struct block_symbol *results;
+  std::vector<struct block_symbol> results;
 
   ndefs = ada_lookup_symbol_list_worker (name, block, domain, &results, 0);
+
   for (i = 0; i < ndefs; ++i)
     {
-      if (!callback (results[i].symbol))
-       break;
+      if (!callback (&results[i]))
+       return false;
     }
+
+  return true;
 }
 
 /* The result is as for ada_lookup_symbol_list with FULL_SEARCH set
@@ -5887,9 +5857,6 @@ ada_lookup_encoded_symbol (const char *name, const struct block *block,
                           domain_enum domain,
                           struct block_symbol *info)
 {
-  struct block_symbol *candidates;
-  int n_candidates;
-
   /* Since we already have an encoded name, wrap it in '<>' to force a
      verbatim match.  Otherwise, if the name happens to not look like
      an encoded name (because it doesn't include a "__"),
@@ -5899,34 +5866,28 @@ ada_lookup_encoded_symbol (const char *name, const struct block *block,
   std::string verbatim = std::string ("<") + name + '>';
 
   gdb_assert (info != NULL);
-  memset (info, 0, sizeof (struct block_symbol));
-
-  n_candidates = ada_lookup_symbol_list (verbatim.c_str (), block,
-                                        domain, &candidates);
-  if (n_candidates == 0)
-    return;
-
-  *info = candidates[0];
-  info->symbol = fixup_symbol_section (info->symbol, NULL);
+  *info = ada_lookup_symbol (verbatim.c_str (), block, domain);
 }
 
 /* Return a symbol in DOMAIN matching NAME, in BLOCK0 and enclosing
    scope and in global scopes, or NULL if none.  NAME is folded and
    encoded first.  Otherwise, the result is as for ada_lookup_symbol_list,
-   choosing the first symbol if there are multiple choices.
-   If IS_A_FIELD_OF_THIS is not NULL, it is set to zero.  */
+   choosing the first symbol if there are multiple choices.  */
 
 struct block_symbol
 ada_lookup_symbol (const char *name, const struct block *block0,
-                   domain_enum domain, int *is_a_field_of_this)
+                   domain_enum domain)
 {
-  struct block_symbol info;
+  std::vector<struct block_symbol> candidates;
+  int n_candidates;
+
+  n_candidates = ada_lookup_symbol_list (name, block0, domain, &candidates);
 
-  if (is_a_field_of_this != NULL)
-    *is_a_field_of_this = 0;
+  if (n_candidates == 0)
+    return {};
 
-  ada_lookup_encoded_symbol (ada_encode (ada_fold_name (name)),
-                            block0, domain, &info);
+  block_symbol info = candidates[0];
+  info.symbol = fixup_symbol_section (info.symbol, NULL);
   return info;
 }
 
@@ -5938,7 +5899,7 @@ ada_lookup_symbol_nonlocal (const struct language_defn *langdef,
 {
   struct block_symbol sym;
 
-  sym = ada_lookup_symbol (name, block_static_block (block), domain, NULL);
+  sym = ada_lookup_symbol (name, block_static_block (block), domain);
   if (sym.symbol != NULL)
     return sym;
 
@@ -5967,7 +5928,7 @@ ada_lookup_symbol_nonlocal (const struct language_defn *langdef,
        return sym;
     }
 
-  return (struct block_symbol) {NULL, NULL};
+  return {};
 }
 
 
@@ -6123,7 +6084,7 @@ is_name_suffix (const char *str)
 static int
 is_valid_name_for_wild_match (const char *name0)
 {
-  const char *decoded_name = ada_decode (name0);
+  std::string decoded_name = ada_decode (name0);
   int i;
 
   /* If the decoded name starts with an angle bracket, it means that
@@ -6259,8 +6220,7 @@ ada_add_block_symbols (struct obstack *obstackp,
        sym != NULL;
        sym = block_iter_match_next (lookup_name, &iter))
     {
-      if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
-                                SYMBOL_DOMAIN (sym), domain))
+      if (symbol_matches_domain (sym->language (), SYMBOL_DOMAIN (sym), domain))
        {
          if (SYMBOL_CLASS (sym) != LOC_UNRESOLVED)
            {
@@ -6299,22 +6259,22 @@ ada_add_block_symbols (struct obstack *obstackp,
 
       ALL_BLOCK_SYMBOLS (block, iter, sym)
       {
-        if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
+        if (symbol_matches_domain (sym->language (),
                                    SYMBOL_DOMAIN (sym), domain))
           {
             int cmp;
 
-            cmp = (int) '_' - (int) SYMBOL_LINKAGE_NAME (sym)[0];
+            cmp = (int) '_' - (int) sym->linkage_name ()[0];
             if (cmp == 0)
               {
-                cmp = !startswith (SYMBOL_LINKAGE_NAME (sym), "_ada_");
+                cmp = !startswith (sym->linkage_name (), "_ada_");
                 if (cmp == 0)
-                  cmp = strncmp (name, SYMBOL_LINKAGE_NAME (sym) + 5,
+                  cmp = strncmp (name, sym->linkage_name () + 5,
                                  name_len);
               }
 
             if (cmp == 0
-                && is_name_suffix (SYMBOL_LINKAGE_NAME (sym) + name_len + 5))
+                && is_name_suffix (sym->linkage_name () + name_len + 5))
               {
                if (SYMBOL_CLASS (sym) != LOC_UNRESOLVED)
                  {
@@ -6352,7 +6312,7 @@ bool
 ada_lookup_name_info::matches
   (const char *sym_name,
    symbol_name_match_type match_type,
-   completion_match *comp_match) const
+   completion_match_result *comp_match_res) const
 {
   bool match = false;
   const char *text = m_encoded_name.c_str ();
@@ -6363,19 +6323,16 @@ ada_lookup_name_info::matches
   if (strncmp (sym_name, text, text_len) == 0)
     match = true;
 
+  std::string decoded_name = ada_decode (sym_name);
   if (match && !m_encoded_p)
     {
       /* One needed check before declaring a positive match is to verify
          that iff we are doing a verbatim match, the decoded version
          of the symbol name starts with '<'.  Otherwise, this symbol name
          is not a suitable completion.  */
-      const char *sym_name_copy = sym_name;
-      bool has_angle_bracket;
 
-      sym_name = ada_decode (sym_name);
-      has_angle_bracket = (sym_name[0] == '<');
+      bool has_angle_bracket = (decoded_name[0] == '<');
       match = (has_angle_bracket == m_verbatim_p);
-      sym_name = sym_name_copy;
     }
 
   if (match && !m_verbatim_p)
@@ -6399,7 +6356,7 @@ ada_lookup_name_info::matches
       /* Since we are doing wild matching, this means that TEXT
          may represent an unqualified symbol name.  We therefore must
          also compare TEXT against the unqualified name of the symbol.  */
-      sym_name = ada_unqualified_name (ada_decode (sym_name));
+      sym_name = ada_unqualified_name (decoded_name.c_str ());
 
       if (strncmp (sym_name, text, text_len) == 0)
        match = true;
@@ -6410,15 +6367,12 @@ ada_lookup_name_info::matches
   if (!match)
     return false;
 
-  if (comp_match != NULL)
+  if (comp_match_res != NULL)
     {
-      std::string &match_str = comp_match->storage ();
+      std::string &match_str = comp_match_res->match.storage ();
 
       if (!m_encoded_p)
-       {
-         match_str = ada_decode (sym_name);
-         comp_match->set_match (match_str.c_str ());
-       }
+       match_str = ada_decode (sym_name);
       else
        {
          if (m_verbatim_p)
@@ -6426,8 +6380,9 @@ ada_lookup_name_info::matches
          else
            match_str = sym_name;
 
-         comp_match->set_match (match_str.c_str ());
        }
+
+      comp_match_res->set_match (match_str.c_str ());
     }
 
   return true;
@@ -6443,22 +6398,13 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
                                       const char *text, const char *word,
                                       enum type_code code)
 {
-  int text_len;
   struct symbol *sym;
-  struct compunit_symtab *s;
-  struct minimal_symbol *msymbol;
-  struct objfile *objfile;
   const struct block *b, *surrounding_static_block = 0;
-  int i;
   struct block_iterator iter;
-  struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
 
   gdb_assert (code == TYPE_CODE_UNDEF);
 
-  text_len = strlen (text);
-
-  lookup_name_info lookup_name (std::string (text, text_len),
-                               name_match_type, true);
+  lookup_name_info lookup_name (text, name_match_type, true);
 
   /* First, look at the partial symtab symbols.  */
   expand_symtabs_matching (NULL,
@@ -6472,16 +6418,38 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
      anything that isn't a text symbol (everything else will be
      handled by the psymtab code above).  */
 
-  ALL_MSYMBOLS (objfile, msymbol)
-  {
-    QUIT;
-
-    completion_list_add_name (tracker,
-                             MSYMBOL_LANGUAGE (msymbol),
-                             MSYMBOL_LINKAGE_NAME (msymbol),
-                             lookup_name,
-                             text, text_len, text, word);
-  }
+  for (objfile *objfile : current_program_space->objfiles ())
+    {
+      for (minimal_symbol *msymbol : objfile->msymbols ())
+       {
+         QUIT;
+
+         if (completion_skip_symbol (mode, msymbol))
+           continue;
+
+         language symbol_language = msymbol->language ();
+
+         /* Ada minimal symbols won't have their language set to Ada.  If
+            we let completion_list_add_name compare using the
+            default/C-like matcher, then when completing e.g., symbols in a
+            package named "pck", we'd match internal Ada symbols like
+            "pckS", which are invalid in an Ada expression, unless you wrap
+            them in '<' '>' to request a verbatim match.
+
+            Unfortunately, some Ada encoded names successfully demangle as
+            C++ symbols (using an old mangling scheme), such as "name__2Xn"
+            -> "Xn::name(void)" and thus some Ada minimal symbols end up
+            with the wrong language set.  Paper over that issue here.  */
+         if (symbol_language == language_auto
+             || symbol_language == language_cplus)
+           symbol_language = language_ada;
+
+         completion_list_add_name (tracker,
+                                   symbol_language,
+                                   msymbol->linkage_name (),
+                                   lookup_name, text, word);
+       }
+    }
 
   /* Search upwards from currently selected frame (so that we can
      complete on local vars.  */
@@ -6493,49 +6461,59 @@ ada_collect_symbol_completion_matches (completion_tracker &tracker,
 
       ALL_BLOCK_SYMBOLS (b, iter, sym)
       {
+       if (completion_skip_symbol (mode, sym))
+         continue;
+
        completion_list_add_name (tracker,
-                                 SYMBOL_LANGUAGE (sym),
-                                 SYMBOL_LINKAGE_NAME (sym),
-                                 lookup_name,
-                                 text, text_len, text, word);
+                                 sym->language (),
+                                 sym->linkage_name (),
+                                 lookup_name, text, word);
       }
     }
 
   /* Go through the symtabs and check the externs and statics for
      symbols which match.  */
 
-  ALL_COMPUNITS (objfile, s)
-  {
-    QUIT;
-    b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), GLOBAL_BLOCK);
-    ALL_BLOCK_SYMBOLS (b, iter, sym)
+  for (objfile *objfile : current_program_space->objfiles ())
     {
-      completion_list_add_name (tracker,
-                               SYMBOL_LANGUAGE (sym),
-                               SYMBOL_LINKAGE_NAME (sym),
-                               lookup_name,
-                               text, text_len, text, word);
-    }
-  }
+      for (compunit_symtab *s : objfile->compunits ())
+       {
+         QUIT;
+         b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), GLOBAL_BLOCK);
+         ALL_BLOCK_SYMBOLS (b, iter, sym)
+           {
+             if (completion_skip_symbol (mode, sym))
+               continue;
 
-  ALL_COMPUNITS (objfile, s)
-  {
-    QUIT;
-    b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), STATIC_BLOCK);
-    /* Don't do this block twice.  */
-    if (b == surrounding_static_block)
-      continue;
-    ALL_BLOCK_SYMBOLS (b, iter, sym)
-    {
-      completion_list_add_name (tracker,
-                               SYMBOL_LANGUAGE (sym),
-                               SYMBOL_LINKAGE_NAME (sym),
-                               lookup_name,
-                               text, text_len, text, word);
+             completion_list_add_name (tracker,
+                                       sym->language (),
+                                       sym->linkage_name (),
+                                       lookup_name, text, word);
+           }
+       }
     }
-  }
 
-  do_cleanups (old_chain);
+  for (objfile *objfile : current_program_space->objfiles ())
+    {
+      for (compunit_symtab *s : objfile->compunits ())
+       {
+         QUIT;
+         b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (s), STATIC_BLOCK);
+         /* Don't do this block twice.  */
+         if (b == surrounding_static_block)
+           continue;
+         ALL_BLOCK_SYMBOLS (b, iter, sym)
+           {
+             if (completion_skip_symbol (mode, sym))
+               continue;
+
+             completion_list_add_name (tracker,
+                                       sym->language (),
+                                       sym->linkage_name (),
+                                       lookup_name, text, word);
+           }
+       }
+    }
 }
 
                                 /* Field Access */
@@ -6586,7 +6564,7 @@ ada_is_ignored_field (struct type *type, int field_num)
 
     /* Anonymous field names should not be printed.
        brobecker/2007-02-20: I don't think this can actually happen
-       but we don't want to print the value of annonymous fields anyway.  */
+       but we don't want to print the value of anonymous fields anyway.  */
     if (name == NULL)
       return 1;
 
@@ -6641,7 +6619,7 @@ ada_is_tag_type (struct type *type)
 
 /* The type of the tag on VAL.  */
 
-struct type *
+static struct type *
 ada_tag_type (struct value *val)
 {
   return ada_lookup_struct_elt_type (value_type (val), "_tag", 1, 0);
@@ -6658,7 +6636,7 @@ is_ada95_tag (struct value *tag)
 
 /* The value of the tag on VAL.  */
 
-struct value *
+static struct value *
 ada_value_tag (struct value *val)
 {
   return ada_value_struct_elt (val, "_tag", 0);
@@ -6731,7 +6709,8 @@ ada_tag_value_at_base_address (struct value *obj)
   if (is_ada95_tag (tag))
     return obj;
 
-  ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr;
+  ptr_type = language_lookup_primitive_type
+    (language_def (language_ada), target_gdbarch(), "storage_offset");
   ptr_type = lookup_pointer_type (ptr_type);
   val = value_cast (ptr_type, tag);
   if (!val)
@@ -6742,16 +6721,15 @@ ada_tag_value_at_base_address (struct value *obj)
      see ada_tag_name for more details.  We do not print the error
      message for the same reason.  */
 
-  TRY
+  try
     {
       offset_to_top = value_as_long (value_ind (value_ptradd (val, -2)));
     }
 
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const gdb_exception_error &e)
     {
       return obj;
     }
-  END_CATCH
 
   /* If offset is null, nothing to do.  */
 
@@ -6765,7 +6743,18 @@ ada_tag_value_at_base_address (struct value *obj)
   if (offset_to_top == -1)
     return obj;
 
-  base_address = value_address (obj) - offset_to_top;
+  /* OFFSET_TO_TOP used to be a positive value to be subtracted
+     from the base address.  This was however incompatible with
+     C++ dispatch table: C++ uses a *negative* value to *add*
+     to the base address.  Ada's convention has therefore been
+     changed in GNAT 19.0w 20171023: since then, C++ and Ada
+     use the same convention.  Here, we support both cases by
+     checking the sign of OFFSET_TO_TOP.  */
+
+  if (offset_to_top > 0)
+    offset_to_top = -offset_to_top;
+
+  base_address = value_address (obj) + offset_to_top;
   tag = value_tag_from_contents_and_address (obj_type, NULL, base_address);
 
   /* Make sure that we have a proper tag at the new address.
@@ -6877,17 +6866,16 @@ ada_tag_name (struct value *tag)
      We also do not print the error message either (which often is very
      low-level (Eg: "Cannot read memory at 0x[...]"), but instead let
      the caller print a more meaningful message if necessary.  */
-  TRY
+  try
     {
       struct value *tsd = ada_get_tsd_from_tag (tag);
 
       if (tsd != NULL)
        name = ada_tag_name_from_tsd (tsd);
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const gdb_exception_error &e)
     {
     }
-  END_CATCH
 
   return name;
 }
@@ -6971,6 +6959,10 @@ ada_is_wrapper_field (struct type *type, int field_num)
 int
 ada_is_variant_part (struct type *type, int field_num)
 {
+  /* Only Ada types are eligible.  */
+  if (!ADA_TYPE_P (type))
+    return 0;
+
   struct type *field_type = TYPE_FIELD_TYPE (type, field_num);
 
   return (TYPE_CODE (field_type) == TYPE_CODE_UNION
@@ -6996,7 +6988,7 @@ ada_variant_discrim_type (struct type *var_type, struct type *outer_type)
    valid field number within it, returns 1 iff field FIELD_NUM of TYPE
    represents a 'when others' clause; otherwise 0.  */
 
-int
+static int
 ada_is_others_clause (struct type *type, int field_num)
 {
   const char *name = TYPE_FIELD_NAME (type, field_num);
@@ -7104,7 +7096,7 @@ ada_scan_number (const char str[], int k, LONGEST * R, int *new_k)
    and FIELD_NUM is a valid field number within it, returns 1 iff VAL is
    in the range encoded by field FIELD_NUM of TYPE; otherwise 0.  */
 
-int
+static int
 ada_in_variant (LONGEST val, struct type *type, int field_num)
 {
   const char *name = TYPE_FIELD_NAME (type, field_num);
@@ -7162,9 +7154,10 @@ ada_value_primitive_field (struct value *arg1, int offset, int fieldno,
   arg_type = ada_check_typedef (arg_type);
   type = TYPE_FIELD_TYPE (arg_type, fieldno);
 
-  /* Handle packed fields.  */
-
-  if (TYPE_FIELD_BITSIZE (arg_type, fieldno) != 0)
+  /* Handle packed fields.  It might be that the field is not packed
+     relative to its containing structure, but the structure itself is
+     packed; in this case we must take the bit-field path.  */
+  if (TYPE_FIELD_BITSIZE (arg_type, fieldno) != 0 || value_bitpos (arg1) != 0)
     {
       int bit_pos = TYPE_FIELD_BITPOS (arg_type, fieldno);
       int bit_size = TYPE_FIELD_BITSIZE (arg_type, fieldno);
@@ -7190,6 +7183,56 @@ ada_value_primitive_field (struct value *arg1, int offset, int fieldno,
    number of fields if not found.   A NULL value of NAME never
    matches; the function just counts visible fields in this case.
    
+   Notice that we need to handle when a tagged record hierarchy
+   has some components with the same name, like in this scenario:
+
+      type Top_T is tagged record
+         N : Integer := 1;
+         U : Integer := 974;
+         A : Integer := 48;
+      end record;
+
+      type Middle_T is new Top.Top_T with record
+         N : Character := 'a';
+         C : Integer := 3;
+      end record;
+
+     type Bottom_T is new Middle.Middle_T with record
+        N : Float := 4.0;
+        C : Character := '5';
+        X : Integer := 6;
+        A : Character := 'J';
+     end record;
+
+   Let's say we now have a variable declared and initialized as follow:
+
+     TC : Top_A := new Bottom_T;
+
+   And then we use this variable to call this function
+
+     procedure Assign (Obj: in out Top_T; TV : Integer);
+
+   as follow:
+
+      Assign (Top_T (B), 12);
+
+   Now, we're in the debugger, and we're inside that procedure
+   then and we want to print the value of obj.c:
+
+   Usually, the tagged record or one of the parent type owns the
+   component to print and there's no issue but in this particular
+   case, what does it mean to ask for Obj.C? Since the actual
+   type for object is type Bottom_T, it could mean two things: type
+   component C from the Middle_T view, but also component C from
+   Bottom_T.  So in that "undefined" case, when the component is
+   not found in the non-resolved type (which includes all the
+   components of the parent type), then resolve it and see if we
+   get better luck once expanded.
+
+   In the case of homonyms in the derived tagged type, we don't
+   guaranty anything, and pick the one that's easiest for us
+   to program.
+
    Returns 1 if found, 0 otherwise.  */
 
 static int
@@ -7199,6 +7242,7 @@ find_struct_field (const char *name, struct type *type, int offset,
                   int *index_p)
 {
   int i;
+  int parent_offset = -1;
 
   type = ada_check_typedef (type);
 
@@ -7220,6 +7264,20 @@ find_struct_field (const char *name, struct type *type, int offset,
       if (t_field_name == NULL)
         continue;
 
+      else if (ada_is_parent_field (type, i))
+        {
+         /* This is a field pointing us to the parent type of a tagged
+            type.  As hinted in this function's documentation, we give
+            preference to fields in the current record first, so what
+            we do here is just record the index of this field before
+            we skip it.  If it turns out we couldn't find our field
+            in the current record, then we'll get back to it and search
+            inside it whether the field might exist in the parent.  */
+
+          parent_offset = i;
+          continue;
+        }
+
       else if (name != NULL && field_name_match (t_field_name, name))
         {
           int bit_size = TYPE_FIELD_BITSIZE (type, i);
@@ -7262,6 +7320,21 @@ find_struct_field (const char *name, struct type *type, int offset,
       else if (index_p != NULL)
        *index_p += 1;
     }
+
+  /* Field not found so far.  If this is a tagged type which
+     has a parent, try finding that field in the parent now.  */
+
+  if (parent_offset != -1)
+    {
+      int bit_pos = TYPE_FIELD_BITPOS (type, parent_offset);
+      int fld_offset = offset + bit_pos / 8;
+
+      if (find_struct_field (name, TYPE_FIELD_TYPE (type, parent_offset),
+                             fld_offset, field_type_p, byte_offset_p,
+                             bit_offset_p, bit_size_p, index_p))
+        return 1;
+    }
+
   return 0;
 }
 
@@ -7281,13 +7354,17 @@ num_visible_fields (struct type *type)
    and search in it assuming it has (class) type TYPE.
    If found, return value, else return NULL.
 
-   Searches recursively through wrapper fields (e.g., '_parent').  */
+   Searches recursively through wrapper fields (e.g., '_parent').
+
+   In the case of homonyms in the tagged types, please refer to the
+   long explanation in find_struct_field's function documentation.  */
 
 static struct value *
 ada_search_struct_field (const char *name, struct value *arg, int offset,
                          struct type *type)
 {
   int i;
+  int parent_offset = -1;
 
   type = ada_check_typedef (type);
   for (i = 0; i < TYPE_NFIELDS (type); i += 1)
@@ -7297,6 +7374,20 @@ ada_search_struct_field (const char *name, struct value *arg, int offset,
       if (t_field_name == NULL)
         continue;
 
+      else if (ada_is_parent_field (type, i))
+        {
+         /* This is a field pointing us to the parent type of a tagged
+            type.  As hinted in this function's documentation, we give
+            preference to fields in the current record first, so what
+            we do here is just record the index of this field before
+            we skip it.  If it turns out we couldn't find our field
+            in the current record, then we'll get back to it and search
+            inside it whether the field might exist in the parent.  */
+
+          parent_offset = i;
+          continue;
+        }
+
       else if (field_name_match (t_field_name, name))
         return ada_value_primitive_field (arg, offset, i, type);
 
@@ -7332,6 +7423,20 @@ ada_search_struct_field (const char *name, struct value *arg, int offset,
             }
         }
     }
+
+  /* Field not found so far.  If this is a tagged type which
+     has a parent, try finding that field in the parent now.  */
+
+  if (parent_offset != -1)
+    {
+      struct value *v = ada_search_struct_field (
+       name, arg, offset + TYPE_FIELD_BITPOS (type, parent_offset) / 8,
+       TYPE_FIELD_TYPE (type, parent_offset));
+
+      if (v != NULL)
+        return v;
+    }
+
   return NULL;
 }
 
@@ -7347,146 +7452,49 @@ static struct value *ada_index_struct_field_1 (int *, struct value *,
 static struct value *
 ada_index_struct_field (int index, struct value *arg, int offset,
                        struct type *type)
-{
-  return ada_index_struct_field_1 (&index, arg, offset, type);
-}
-
-
-/* Auxiliary function for ada_index_struct_field.  Like
- * ada_index_struct_field, but takes index from *INDEX_P and modifies
- * *INDEX_P.  */
-
-static struct value *
-ada_index_struct_field_1 (int *index_p, struct value *arg, int offset,
-                         struct type *type)
-{
-  int i;
-  type = ada_check_typedef (type);
-
-  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
-    {
-      if (TYPE_FIELD_NAME (type, i) == NULL)
-        continue;
-      else if (ada_is_wrapper_field (type, i))
-        {
-          struct value *v =     /* Do not let indent join lines here.  */
-            ada_index_struct_field_1 (index_p, arg,
-                                     offset + TYPE_FIELD_BITPOS (type, i) / 8,
-                                     TYPE_FIELD_TYPE (type, i));
-
-          if (v != NULL)
-            return v;
-        }
-
-      else if (ada_is_variant_part (type, i))
-        {
-         /* PNH: Do we ever get here?  See ada_search_struct_field,
-            find_struct_field.  */
-         error (_("Cannot assign this kind of variant record"));
-        }
-      else if (*index_p == 0)
-        return ada_value_primitive_field (arg, offset, i, type);
-      else
-       *index_p -= 1;
-    }
-  return NULL;
-}
-
-/* Given ARG, a value of type (pointer or reference to a)*
-   structure/union, extract the component named NAME from the ultimate
-   target structure/union and return it as a value with its
-   appropriate type.
-
-   The routine searches for NAME among all members of the structure itself
-   and (recursively) among all members of any wrapper members
-   (e.g., '_parent').
-
-   If NO_ERR, then simply return NULL in case of error, rather than 
-   calling error.  */
-
-struct value *
-ada_value_struct_elt (struct value *arg, const char *name, int no_err)
-{
-  struct type *t, *t1;
-  struct value *v;
-
-  v = NULL;
-  t1 = t = ada_check_typedef (value_type (arg));
-  if (TYPE_CODE (t) == TYPE_CODE_REF)
-    {
-      t1 = TYPE_TARGET_TYPE (t);
-      if (t1 == NULL)
-       goto BadValue;
-      t1 = ada_check_typedef (t1);
-      if (TYPE_CODE (t1) == TYPE_CODE_PTR)
-        {
-          arg = coerce_ref (arg);
-          t = t1;
-        }
-    }
+{
+  return ada_index_struct_field_1 (&index, arg, offset, type);
+}
 
-  while (TYPE_CODE (t) == TYPE_CODE_PTR)
-    {
-      t1 = TYPE_TARGET_TYPE (t);
-      if (t1 == NULL)
-       goto BadValue;
-      t1 = ada_check_typedef (t1);
-      if (TYPE_CODE (t1) == TYPE_CODE_PTR)
-        {
-          arg = value_ind (arg);
-          t = t1;
-        }
-      else
-        break;
-    }
 
-  if (TYPE_CODE (t1) != TYPE_CODE_STRUCT && TYPE_CODE (t1) != TYPE_CODE_UNION)
-    goto BadValue;
+/* Auxiliary function for ada_index_struct_field.  Like
+ * ada_index_struct_field, but takes index from *INDEX_P and modifies
+ * *INDEX_P.  */
 
-  if (t1 == t)
-    v = ada_search_struct_field (name, arg, 0, t);
-  else
+static struct value *
+ada_index_struct_field_1 (int *index_p, struct value *arg, int offset,
+                         struct type *type)
+{
+  int i;
+  type = ada_check_typedef (type);
+
+  for (i = 0; i < TYPE_NFIELDS (type); i += 1)
     {
-      int bit_offset, bit_size, byte_offset;
-      struct type *field_type;
-      CORE_ADDR address;
+      if (TYPE_FIELD_NAME (type, i) == NULL)
+        continue;
+      else if (ada_is_wrapper_field (type, i))
+        {
+          struct value *v =     /* Do not let indent join lines here.  */
+            ada_index_struct_field_1 (index_p, arg,
+                                     offset + TYPE_FIELD_BITPOS (type, i) / 8,
+                                     TYPE_FIELD_TYPE (type, i));
 
-      if (TYPE_CODE (t) == TYPE_CODE_PTR)
-       address = value_address (ada_value_ind (arg));
-      else
-       address = value_address (ada_coerce_ref (arg));
+          if (v != NULL)
+            return v;
+        }
 
-      t1 = ada_to_fixed_type (ada_get_base_type (t1), NULL, address, NULL, 1);
-      if (find_struct_field (name, t1, 0,
-                             &field_type, &byte_offset, &bit_offset,
-                             &bit_size, NULL))
+      else if (ada_is_variant_part (type, i))
         {
-          if (bit_size != 0)
-            {
-              if (TYPE_CODE (t) == TYPE_CODE_REF)
-                arg = ada_coerce_ref (arg);
-              else
-                arg = ada_value_ind (arg);
-              v = ada_value_primitive_packed_val (arg, NULL, byte_offset,
-                                                  bit_offset, bit_size,
-                                                  field_type);
-            }
-          else
-            v = value_at_lazy (field_type, address + byte_offset);
+         /* PNH: Do we ever get here?  See ada_search_struct_field,
+            find_struct_field.  */
+         error (_("Cannot assign this kind of variant record"));
         }
+      else if (*index_p == 0)
+        return ada_value_primitive_field (arg, offset, i, type);
+      else
+       *index_p -= 1;
     }
-
-  if (v != NULL || no_err)
-    return v;
-  else
-    error (_("There is no member named %s."), name);
-
- BadValue:
-  if (no_err)
-    return NULL;
-  else
-    error (_("Attempt to extract a component of "
-            "a value that is not a record."));
+  return NULL;
 }
 
 /* Return a string representation of type TYPE.  */
@@ -7515,6 +7523,9 @@ type_as_string (struct type *type)
 
    Looks recursively into variant clauses and parent types.
 
+   In the case of homonyms in the tagged types, please refer to the
+   long explanation in find_struct_field's function documentation.
+
    If NOERR is nonzero, return NULL if NAME is not suitably defined or
    TYPE is not a type of the right kind.  */
 
@@ -7523,6 +7534,7 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
                             int noerr)
 {
   int i;
+  int parent_offset = -1;
 
   if (name == NULL)
     goto BadName;
@@ -7558,6 +7570,20 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
       if (t_field_name == NULL)
         continue;
 
+      else if (ada_is_parent_field (type, i))
+        {
+         /* This is a field pointing us to the parent type of a tagged
+            type.  As hinted in this function's documentation, we give
+            preference to fields in the current record first, so what
+            we do here is just record the index of this field before
+            we skip it.  If it turns out we couldn't find our field
+            in the current record, then we'll get back to it and search
+            inside it whether the field might exist in the parent.  */
+
+          parent_offset = i;
+          continue;
+        }
+
       else if (field_name_match (t_field_name, name))
        return TYPE_FIELD_TYPE (type, i);
 
@@ -7598,6 +7624,19 @@ ada_lookup_struct_elt_type (struct type *type, const char *name, int refok,
 
     }
 
+    /* Field not found so far.  If this is a tagged type which
+       has a parent, try finding that field in the parent now.  */
+
+    if (parent_offset != -1)
+      {
+        struct type *t;
+
+        t = ada_lookup_struct_elt_type (TYPE_FIELD_TYPE (type, parent_offset),
+                                        name, 0, 1);
+        if (t != NULL)
+         return t;
+      }
+
 BadName:
   if (!noerr)
     {
@@ -7811,80 +7850,11 @@ ada_find_any_type (const char *name)
    symbols whose name is that of NAME_SYM suffixed with  "___XR".
    Return symbol if found, and NULL otherwise.  */
 
-struct symbol *
-ada_find_renaming_symbol (struct symbol *name_sym, const struct block *block)
+static bool
+ada_is_renaming_symbol (struct symbol *name_sym)
 {
-  const char *name = SYMBOL_LINKAGE_NAME (name_sym);
-  struct symbol *sym;
-
-  if (strstr (name, "___XR") != NULL)
-     return name_sym;
-
-  sym = find_old_style_renaming_symbol (name, block);
-
-  if (sym != NULL)
-    return sym;
-
-  /* Not right yet.  FIXME pnh 7/20/2007.  */
-  sym = ada_find_any_type_symbol (name);
-  if (sym != NULL && strstr (SYMBOL_LINKAGE_NAME (sym), "___XR") != NULL)
-    return sym;
-  else
-    return NULL;
-}
-
-static struct symbol *
-find_old_style_renaming_symbol (const char *name, const struct block *block)
-{
-  const struct symbol *function_sym = block_linkage_function (block);
-  char *rename;
-
-  if (function_sym != NULL)
-    {
-      /* If the symbol is defined inside a function, NAME is not fully
-         qualified.  This means we need to prepend the function name
-         as well as adding the ``___XR'' suffix to build the name of
-         the associated renaming symbol.  */
-      const char *function_name = SYMBOL_LINKAGE_NAME (function_sym);
-      /* Function names sometimes contain suffixes used
-         for instance to qualify nested subprograms.  When building
-         the XR type name, we need to make sure that this suffix is
-         not included.  So do not include any suffix in the function
-         name length below.  */
-      int function_name_len = ada_name_prefix_len (function_name);
-      const int rename_len = function_name_len + 2      /*  "__" */
-        + strlen (name) + 6 /* "___XR\0" */ ;
-
-      /* Strip the suffix if necessary.  */
-      ada_remove_trailing_digits (function_name, &function_name_len);
-      ada_remove_po_subprogram_suffix (function_name, &function_name_len);
-      ada_remove_Xbn_suffix (function_name, &function_name_len);
-
-      /* Library-level functions are a special case, as GNAT adds
-         a ``_ada_'' prefix to the function name to avoid namespace
-         pollution.  However, the renaming symbols themselves do not
-         have this prefix, so we need to skip this prefix if present.  */
-      if (function_name_len > 5 /* "_ada_" */
-          && strstr (function_name, "_ada_") == function_name)
-        {
-         function_name += 5;
-         function_name_len -= 5;
-        }
-
-      rename = (char *) alloca (rename_len * sizeof (char));
-      strncpy (rename, function_name, function_name_len);
-      xsnprintf (rename + function_name_len, rename_len - function_name_len,
-                "__%s___XR", name);
-    }
-  else
-    {
-      const int rename_len = strlen (name) + 6;
-
-      rename = (char *) alloca (rename_len * sizeof (char));
-      xsnprintf (rename, rename_len * sizeof (char), "%s___XR", name);
-    }
-
-  return ada_find_any_type_symbol (rename);
+  const char *name = name_sym->linkage_name ();
+  return strstr (name, "___XR") != NULL;
 }
 
 /* Because of GNAT encoding conventions, several GDB symbols may match a
@@ -7912,8 +7882,8 @@ ada_prefer_type (struct type *type0, struct type *type1)
     return 1;
   else
     {
-      const char *type0_name = type_name_no_tag (type0);
-      const char *type1_name = type_name_no_tag (type1);
+      const char *type0_name = TYPE_NAME (type0);
+      const char *type1_name = TYPE_NAME (type1);
 
       if (type0_name != NULL && strstr (type0_name, "___XR") != NULL
          && (type1_name == NULL || strstr (type1_name, "___XR") == NULL))
@@ -7922,18 +7892,15 @@ ada_prefer_type (struct type *type0, struct type *type1)
   return 0;
 }
 
-/* The name of TYPE, which is either its TYPE_NAME, or, if that is
-   null, its TYPE_TAG_NAME.  Null if TYPE is null.  */
+/* The name of TYPE, which is its TYPE_NAME.  Null if TYPE is
+   null.  */
 
 const char *
 ada_type_name (struct type *type)
 {
   if (type == NULL)
     return NULL;
-  else if (TYPE_NAME (type) != NULL)
-    return TYPE_NAME (type);
-  else
-    return TYPE_TAG_NAME (type);
+  return TYPE_NAME (type);
 }
 
 /* Search the list of "descriptive" types associated to TYPE for a type
@@ -8100,9 +8067,8 @@ empty_record (struct type *templ)
   TYPE_CODE (type) = TYPE_CODE_STRUCT;
   TYPE_NFIELDS (type) = 0;
   TYPE_FIELDS (type) = NULL;
-  INIT_CPLUS_SPECIFIC (type);
+  INIT_NONE_SPECIFIC (type);
   TYPE_NAME (type) = "<empty>";
-  TYPE_TAG_NAME (type) = NULL;
   TYPE_LENGTH (type) = 0;
   return type;
 }
@@ -8155,13 +8121,12 @@ ada_template_to_fixed_record_type_1 (struct type *type,
 
   rtype = alloc_type_copy (type);
   TYPE_CODE (rtype) = TYPE_CODE_STRUCT;
-  INIT_CPLUS_SPECIFIC (rtype);
+  INIT_NONE_SPECIFIC (rtype);
   TYPE_NFIELDS (rtype) = nfields;
   TYPE_FIELDS (rtype) = (struct field *)
     TYPE_ALLOC (rtype, nfields * sizeof (struct field));
   memset (TYPE_FIELDS (rtype), 0, sizeof (struct field) * nfields);
   TYPE_NAME (rtype) = ada_type_name (type);
-  TYPE_TAG_NAME (rtype) = NULL;
   TYPE_FIXED_INSTANCE (rtype) = 1;
 
   off = 0;
@@ -8350,11 +8315,11 @@ ada_template_to_fixed_record_type_1 (struct type *type,
   if (TYPE_LENGTH (type) <= 0)
     {
       if (TYPE_NAME (rtype))
-       warning (_("Invalid type size for `%s' detected: %d."),
-                TYPE_NAME (rtype), TYPE_LENGTH (type));
+       warning (_("Invalid type size for `%s' detected: %s."),
+                TYPE_NAME (rtype), pulongest (TYPE_LENGTH (type)));
       else
-       warning (_("Invalid type size for <unnamed> detected: %d."),
-                TYPE_LENGTH (type));
+       warning (_("Invalid type size for <unnamed> detected: %s."),
+                pulongest (TYPE_LENGTH (type)));
     }
   else
     {
@@ -8431,14 +8396,13 @@ template_to_static_fixed_type (struct type *type0)
            {
              TYPE_TARGET_TYPE (type0) = type = alloc_type_copy (type0);
              TYPE_CODE (type) = TYPE_CODE (type0);
-             INIT_CPLUS_SPECIFIC (type);
+             INIT_NONE_SPECIFIC (type);
              TYPE_NFIELDS (type) = nfields;
              TYPE_FIELDS (type) = (struct field *)
                TYPE_ALLOC (type, nfields * sizeof (struct field));
              memcpy (TYPE_FIELDS (type), TYPE_FIELDS (type0),
                      sizeof (struct field) * nfields);
              TYPE_NAME (type) = ada_type_name (type0);
-             TYPE_TAG_NAME (type) = NULL;
              TYPE_FIXED_INSTANCE (type) = 1;
              TYPE_LENGTH (type) = 0;
            }
@@ -8481,14 +8445,13 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
 
   rtype = alloc_type_copy (type);
   TYPE_CODE (rtype) = TYPE_CODE_STRUCT;
-  INIT_CPLUS_SPECIFIC (rtype);
+  INIT_NONE_SPECIFIC (rtype);
   TYPE_NFIELDS (rtype) = nfields;
   TYPE_FIELDS (rtype) =
     (struct field *) TYPE_ALLOC (rtype, nfields * sizeof (struct field));
   memcpy (TYPE_FIELDS (rtype), TYPE_FIELDS (type),
           sizeof (struct field) * nfields);
   TYPE_NAME (rtype) = ada_type_name (type);
-  TYPE_TAG_NAME (rtype) = NULL;
   TYPE_FIXED_INSTANCE (rtype) = 1;
   TYPE_LENGTH (rtype) = TYPE_LENGTH (type);
 
@@ -8621,7 +8584,6 @@ static int
 ada_is_redundant_range_encoding (struct type *range_type,
                                 struct type *encoding_type)
 {
-  struct type *fixed_range_type;
   const char *bounds_str;
   int n;
   LONGEST lo, hi;
@@ -8852,6 +8814,11 @@ ada_to_fixed_type_1 (struct type *type, const gdb_byte *valaddr,
                    CORE_ADDR address, struct value *dval, int check_tag)
 {
   type = ada_check_typedef (type);
+
+  /* Only un-fixed types need to be handled here.  */
+  if (!HAVE_GNAT_AUX_INFO (type))
+    return type;
+
   switch (TYPE_CODE (type))
     {
     default:
@@ -8895,11 +8862,27 @@ ada_to_fixed_type_1 (struct type *type, const gdb_byte *valaddr,
             const char *name = ada_type_name (fixed_record_type);
             char *xvz_name
              = (char *) alloca (strlen (name) + 7 /* "___XVZ\0" */);
+           bool xvz_found = false;
             LONGEST size;
 
             xsnprintf (xvz_name, strlen (name) + 7, "%s___XVZ", name);
-            if (get_int_var_value (xvz_name, size)
-               && TYPE_LENGTH (fixed_record_type) != size)
+           try
+             {
+               xvz_found = get_int_var_value (xvz_name, size);
+             }
+           catch (const gdb_exception_error &except)
+             {
+               /* We found the variable, but somehow failed to read
+                  its value.  Rethrow the same error, but with a little
+                  bit more information, to help the user understand
+                  what went wrong (Eg: the variable might have been
+                  optimized out).  */
+               throw_error (except.error,
+                            _("unable to read value of %s (%s)"),
+                            xvz_name, except.what ());
+             }
+
+            if (xvz_found && TYPE_LENGTH (fixed_record_type) != size)
               {
                 fixed_record_type = copy_type (fixed_record_type);
                 TYPE_LENGTH (fixed_record_type) = size;
@@ -8981,7 +8964,7 @@ ada_to_fixed_type (struct type *type, const gdb_byte *valaddr,
       brobecker/2010-11-19: It seems to me that the only case where it is
       useful to preserve the typedef layer is when dealing with fat pointers.
       Perhaps, we could add a check for that and preserve the typedef layer
-      only in that situation.  But this seems unecessary so far, probably
+      only in that situation.  But this seems unnecessary so far, probably
       because we call check_typedef/ada_check_typedef pretty much everywhere.
       */
   if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF
@@ -9071,23 +9054,23 @@ ada_check_typedef (struct type *type)
   if (type == NULL)
     return NULL;
 
-  /* If our type is a typedef type of a fat pointer, then we're done.
+  /* If our type is an access to an unconstrained array, which is encoded
+     as a TYPE_CODE_TYPEDEF of a fat pointer, then we're done.
      We don't want to strip the TYPE_CODE_TYPDEF layer, because this is
      what allows us to distinguish between fat pointers that represent
      array types, and fat pointers that represent array access types
      (in both cases, the compiler implements them as fat pointers).  */
-  if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF
-      && is_thick_pntr (ada_typedef_target_type (type)))
+  if (ada_is_access_to_unconstrained_array (type))
     return type;
 
   type = check_typedef (type);
   if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM
       || !TYPE_STUB (type)
-      || TYPE_TAG_NAME (type) == NULL)
+      || TYPE_NAME (type) == NULL)
     return type;
   else
     {
-      const char *name = TYPE_TAG_NAME (type);
+      const char *name = TYPE_NAME (type);
       struct type *type1 = ada_find_any_type (name);
 
       if (type1 == NULL)
@@ -9118,8 +9101,16 @@ ada_to_fixed_value_create (struct type *type0, CORE_ADDR address,
 
   if (type == type0 && val0 != NULL)
     return val0;
-  else
-    return value_from_contents_and_address (type, 0, address);
+
+  if (VALUE_LVAL (val0) != lval_memory)
+    {
+      /* Our value does not live in memory; it could be a convenience
+        variable, for instance.  Create a not_lval value using val0's
+        contents.  */
+      return value_from_contents (type, value_contents (val0));
+    }
+
+  return value_from_contents_and_address (type, 0, address);
 }
 
 /* A value representing VAL, but with a standard (static-sized) type
@@ -9130,9 +9121,7 @@ struct value *
 ada_to_fixed_value (struct value *val)
 {
   val = unwrap_value (val);
-  val = ada_to_fixed_value_create (value_type (val),
-                                     value_address (val),
-                                     val);
+  val = ada_to_fixed_value_create (value_type (val), value_address (val), val);
   return val;
 }
 \f
@@ -9159,7 +9148,7 @@ static const char *attribute_names[] = {
   0
 };
 
-const char *
+static const char *
 ada_attribute_name (enum exp_opcode n)
 {
   if (n >= OP_ATR_FIRST && n <= (int) OP_ATR_VAL)
@@ -9221,7 +9210,7 @@ value_val_atr (struct type *type, struct value *arg)
    [At the moment, this is true only for Character and Wide_Character;
    It is a heuristic test that could stand improvement].  */
 
-int
+bool
 ada_is_character_type (struct type *type)
 {
   const char *name;
@@ -9229,7 +9218,7 @@ ada_is_character_type (struct type *type)
   /* If the type code says it's a character, then assume it really is,
      and don't check any further.  */
   if (TYPE_CODE (type) == TYPE_CODE_CHAR)
-    return 1;
+    return true;
   
   /* Otherwise, assume it's a character type iff it is a discrete type
      with a known character type name.  */
@@ -9245,7 +9234,7 @@ ada_is_character_type (struct type *type)
 
 /* True if TYPE appears to be an Ada string type.  */
 
-int
+bool
 ada_is_string_type (struct type *type)
 {
   type = ada_check_typedef (type);
@@ -9260,7 +9249,7 @@ ada_is_string_type (struct type *type)
       return ada_is_character_type (elttype);
     }
   else
-    return 0;
+    return false;
 }
 
 /* The compiler sometimes provides a parallel XVS type for a given
@@ -9272,7 +9261,7 @@ ada_is_string_type (struct type *type)
 
    Set to True if the debugger should trust the contents of PAD types.
    Otherwise, ignore the PAD type if there is a parallel XVS type.  */
-static int trust_pad_over_xvs = 1;
+static bool trust_pad_over_xvs = true;
 
 /* True if TYPE is a struct type introduced by the compiler to force the
    alignment of a value.  Such types have a single field with a
@@ -9327,7 +9316,7 @@ ada_get_base_type (struct type *raw_type)
   if (TYPE_CODE (TYPE_FIELD_TYPE (real_type_namer, 0)) != TYPE_CODE_REF)
     {
       /* This is an older encoding form where the base type needs to be
-        looked up by name.  We prefer the newer enconding because it is
+        looked up by name.  We prefer the newer encoding because it is
         more efficient.  */
       raw_real_type = ada_find_any_type (TYPE_FIELD_NAME (real_type_namer, 0));
       if (raw_real_type == NULL)
@@ -9410,6 +9399,14 @@ ada_enum_name (const char *name)
           if (sscanf (name + 2, "%x", &v) != 1)
             return name;
         }
+      else if (((name[1] >= '0' && name[1] <= '9')
+               || (name[1] >= 'a' && name[1] <= 'z'))
+              && name[2] == '\0')
+       {
+         GROW_VECT (result, result_len, 4);
+         xsnprintf (result, result_len, "'%c'", name[1]);
+         return result;
+       }
       else
         return name;
 
@@ -9678,7 +9675,7 @@ ada_value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
   val = allocate_value (type1);
   store_unsigned_integer (value_contents_raw (val),
                           TYPE_LENGTH (value_type (val)),
-                         gdbarch_byte_order (get_type_arch (type1)), v);
+                         type_byte_order (type1), v);
   return val;
 }
 
@@ -9688,23 +9685,28 @@ ada_value_equal (struct value *arg1, struct value *arg2)
   if (ada_is_direct_array_type (value_type (arg1))
       || ada_is_direct_array_type (value_type (arg2)))
     {
+      struct type *arg1_type, *arg2_type;
+
       /* Automatically dereference any array reference before
          we attempt to perform the comparison.  */
       arg1 = ada_coerce_ref (arg1);
       arg2 = ada_coerce_ref (arg2);
-      
+
       arg1 = ada_coerce_to_simple_array (arg1);
       arg2 = ada_coerce_to_simple_array (arg2);
-      if (TYPE_CODE (value_type (arg1)) != TYPE_CODE_ARRAY
-          || TYPE_CODE (value_type (arg2)) != TYPE_CODE_ARRAY)
+
+      arg1_type = ada_check_typedef (value_type (arg1));
+      arg2_type = ada_check_typedef (value_type (arg2));
+
+      if (TYPE_CODE (arg1_type) != TYPE_CODE_ARRAY
+          || TYPE_CODE (arg2_type) != TYPE_CODE_ARRAY)
         error (_("Attempt to compare array with non-array"));
       /* FIXME: The following works only for types whose
          representations use all bits (no padding or undefined bits)
          and do not have user-defined equality.  */
-      return
-        TYPE_LENGTH (value_type (arg1)) == TYPE_LENGTH (value_type (arg2))
-        && memcmp (value_contents (arg1), value_contents (arg2),
-                   TYPE_LENGTH (value_type (arg1))) == 0;
+      return (TYPE_LENGTH (arg1_type) == TYPE_LENGTH (arg2_type)
+             && memcmp (value_contents (arg1), value_contents (arg2),
+                        TYPE_LENGTH (arg1_type)) == 0);
     }
   return value_equal (arg1, arg2);
 }
@@ -9749,8 +9751,9 @@ assign_component (struct value *container, struct value *lhs, LONGEST index,
 {
   struct value *mark = value_mark ();
   struct value *elt;
+  struct type *lhs_type = check_typedef (value_type (lhs));
 
-  if (TYPE_CODE (value_type (lhs)) == TYPE_CODE_ARRAY)
+  if (TYPE_CODE (lhs_type) == TYPE_CODE_ARRAY)
     {
       struct type *index_type = builtin_type (exp->gdbarch)->builtin_int;
       struct value *index_val = value_from_longest (index_type, index);
@@ -9809,11 +9812,11 @@ assign_aggregate (struct value *container,
   if (!deprecated_value_modifiable (lhs))
     error (_("Left operand of assignment is not a modifiable lvalue."));
 
-  lhs_type = value_type (lhs);
+  lhs_type = check_typedef (value_type (lhs));
   if (ada_is_direct_array_type (lhs_type))
     {
       lhs = ada_coerce_to_simple_array (lhs);
-      lhs_type = value_type (lhs);
+      lhs_type = check_typedef (value_type (lhs));
       low_index = TYPE_ARRAY_LOWER_BOUND_VALUE (lhs_type);
       high_index = TYPE_ARRAY_UPPER_BOUND_VALUE (lhs_type);
     }
@@ -9939,7 +9942,7 @@ aggregate_assign_from_choices (struct value *container,
              name = &exp->elts[choice_pos + 2].string;
              break;
            case OP_VAR_VALUE:
-             name = SYMBOL_NATURAL_NAME (exp->elts[choice_pos + 2].symbol);
+             name = exp->elts[choice_pos + 2].symbol->natural_name ();
              break;
            default:
              error (_("Invalid record component association."));
@@ -10041,13 +10044,13 @@ add_component_interval (LONGEST low, LONGEST high,
    is different.  */
 
 static struct value *
-ada_value_cast (struct type *type, struct value *arg2, enum noside noside)
+ada_value_cast (struct type *type, struct value *arg2)
 {
   if (type == ada_check_typedef (value_type (arg2)))
     return arg2;
 
   if (ada_is_fixed_point_type (type))
-    return (cast_to_fixed (type, arg2));
+    return cast_to_fixed (type, arg2);
 
   if (ada_is_fixed_point_type (value_type (arg2)))
     return cast_from_fixed (type, arg2);
@@ -10110,7 +10113,7 @@ ada_value_cast (struct type *type, struct value *arg2, enum noside noside)
     information nor the associated type structure in GDB are able to
     express such dynamic types.  So what the debugger does is to create
     "fixed" versions of the type that applies to the specific object.
-    We also informally refer to this opperation as "fixing" an object,
+    We also informally refer to this operation as "fixing" an object,
     which means creating its associated fixed type.
 
     Example: when printing the value of variable "Yes" above, its fixed
@@ -10299,16 +10302,68 @@ ada_value_cast (struct type *type, struct value *arg2, enum noside noside)
     one element out of that array.  On the other hand, fixing should
     not be performed on the elements when taking a slice of an array!
 
-    Note that one of the side-effects of miscomputing the offset and
+    Note that one of the side effects of miscomputing the offset and
     size of each field is that we end up also miscomputing the size
     of the containing type.  This can have adverse results when computing
     the value of an entity.  GDB fetches the value of an entity based
     on the size of its type, and thus a wrong size causes GDB to fetch
     the wrong amount of memory.  In the case where the computed size is
     too small, GDB fetches too little data to print the value of our
-    entiry.  Results in this case as unpredicatble, as we usually read
+    entity.  Results in this case are unpredictable, as we usually read
     past the buffer containing the data =:-o.  */
 
+/* Evaluate a subexpression of EXP, at index *POS, and return a value
+   for that subexpression cast to TO_TYPE.  Advance *POS over the
+   subexpression.  */
+
+static value *
+ada_evaluate_subexp_for_cast (expression *exp, int *pos,
+                             enum noside noside, struct type *to_type)
+{
+  int pc = *pos;
+
+  if (exp->elts[pc].opcode == OP_VAR_MSYM_VALUE
+      || exp->elts[pc].opcode == OP_VAR_VALUE)
+    {
+      (*pos) += 4;
+
+      value *val;
+      if (exp->elts[pc].opcode == OP_VAR_MSYM_VALUE)
+        {
+          if (noside == EVAL_AVOID_SIDE_EFFECTS)
+            return value_zero (to_type, not_lval);
+
+          val = evaluate_var_msym_value (noside,
+                                         exp->elts[pc + 1].objfile,
+                                         exp->elts[pc + 2].msymbol);
+        }
+      else
+        val = evaluate_var_value (noside,
+                                  exp->elts[pc + 1].block,
+                                  exp->elts[pc + 2].symbol);
+
+      if (noside == EVAL_SKIP)
+        return eval_skip_value (exp);
+
+      val = ada_value_cast (to_type, val);
+
+      /* Follow the Ada language semantics that do not allow taking
+        an address of the result of a cast (view conversion in Ada).  */
+      if (VALUE_LVAL (val) == lval_memory)
+        {
+          if (value_lazy (val))
+            value_fetch_lazy (val);
+          VALUE_LVAL (val) = not_lval;
+        }
+      return val;
+    }
+
+  value *val = evaluate_subexp (to_type, exp, pos, noside);
+  if (noside == EVAL_SKIP)
+    return eval_skip_value (exp);
+  return ada_value_cast (to_type, val);
+}
+
 /* Implement the evaluate_exp routine in the exp_descriptor structure
    for the Ada language.  */
 
@@ -10347,7 +10402,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
          Similarly, we need to perform the conversion from OP_LONG
          ourselves.  */
       if ((op == OP_FLOAT || op == OP_LONG) && expect_type != NULL)
-        arg1 = ada_value_cast (expect_type, arg1, noside);
+        arg1 = ada_value_cast (expect_type, arg1);
 
       return arg1;
 
@@ -10367,11 +10422,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
     case UNOP_CAST:
       (*pos) += 2;
       type = exp->elts[pc + 1].type;
-      arg1 = evaluate_subexp (type, exp, pos, noside);
-      if (noside == EVAL_SKIP)
-        goto nosideret;
-      arg1 = ada_value_cast (type, arg1, noside);
-      return arg1;
+      return ada_evaluate_subexp_for_cast (exp, pos, noside, type);
 
     case UNOP_QUAL:
       (*pos) += 2;
@@ -10397,7 +10448,11 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       arg2 = evaluate_subexp (type, exp, pos, noside);
       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
         return arg1;
-      if (ada_is_fixed_point_type (value_type (arg1)))
+      if (VALUE_LVAL (arg1) == lval_internalvar)
+       {
+         /* Nothing.  */
+       }
+      else if (ada_is_fixed_point_type (value_type (arg1)))
         arg2 = cast_to_fixed (value_type (arg1), arg2);
       else if (ada_is_fixed_point_type (value_type (arg2)))
         error
@@ -10552,7 +10607,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
            context other than a function call, in which case, it is
            invalid.  */
         error (_("Unexpected unresolved symbol, %s, during evaluation"),
-               SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
+               exp->elts[pc + 2].symbol->print_name ());
 
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
         {
@@ -10642,7 +10697,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       if (exp->elts[*pos].opcode == OP_VAR_VALUE
           && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
         error (_("Unexpected unresolved symbol, %s, during evaluation"),
-               SYMBOL_PRINT_NAME (exp->elts[pc + 5].symbol));
+               exp->elts[pc + 5].symbol->print_name ());
       else
         {
           for (tem = 0; tem <= nargs; tem += 1)
@@ -10712,7 +10767,9 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
                error_call_unknown_return_type (NULL);
              return allocate_value (TYPE_TARGET_TYPE (type));
            }
-         return call_function_by_hand (argvec[0], NULL, nargs, argvec + 1);
+         return call_function_by_hand (argvec[0], NULL,
+                                       gdb::make_array_view (argvec + 1,
+                                                             nargs));
        case TYPE_CODE_INTERNAL_FUNCTION:
          if (noside == EVAL_AVOID_SIDE_EFFECTS)
            /* We don't know anything about what the internal
@@ -10810,7 +10867,8 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
         if (noside == EVAL_AVOID_SIDE_EFFECTS
             && ada_is_array_descriptor_type (ada_check_typedef
                                              (value_type (array))))
-          return empty_array (ada_type_of_array (array, 0), low_bound);
+          return empty_array (ada_type_of_array (array, 0), low_bound,
+                             high_bound);
 
         array = ada_coerce_to_simple_array_ptr (array);
 
@@ -10834,7 +10892,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
             struct type *type0 = ada_check_typedef (value_type (array));
 
             if (high_bound < low_bound || noside == EVAL_AVOID_SIDE_EFFECTS)
-              return empty_array (TYPE_TARGET_TYPE (type0), low_bound);
+              return empty_array (TYPE_TARGET_TYPE (type0), low_bound, high_bound);
             else
               {
                 struct type *arr_type0 =
@@ -10848,7 +10906,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
         else if (noside == EVAL_AVOID_SIDE_EFFECTS)
           return array;
         else if (high_bound < low_bound)
-          return empty_array (value_type (array), low_bound);
+          return empty_array (value_type (array), low_bound, high_bound);
         else
           return ada_value_slice (array, longest_to_int (low_bound),
                                  longest_to_int (high_bound));
@@ -10960,8 +11018,34 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
 
         if (noside == EVAL_SKIP)
           goto nosideret;
+       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
+         {
+           if (type_arg == NULL)
+             type_arg = value_type (arg1);
 
-        if (type_arg == NULL)
+            if (ada_is_constrained_packed_array_type (type_arg))
+             type_arg = decode_constrained_packed_array_type (type_arg);
+
+           if (!discrete_type_p (type_arg))
+             {
+               switch (op)
+                 {
+                 default:          /* Should never happen.  */
+                   error (_("unexpected attribute encountered"));
+                 case OP_ATR_FIRST:
+                 case OP_ATR_LAST:
+                   type_arg = ada_index_type (type_arg, tem,
+                                              ada_attribute_name (op));
+                   break;
+                 case OP_ATR_LENGTH:
+                   type_arg = builtin_type (exp->gdbarch)->builtin_int;
+                   break;
+                 }
+             }
+
+           return value_zero (type_arg, not_lval);
+         }
+        else if (type_arg == NULL)
           {
             arg1 = ada_coerce_ref (arg1);
 
@@ -10978,9 +11062,6 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
                  type = builtin_type (exp->gdbarch)->builtin_int;
              }
 
-            if (noside == EVAL_AVOID_SIDE_EFFECTS)
-              return allocate_value (type);
-
             switch (op)
               {
               default:          /* Should never happen.  */
@@ -11038,9 +11119,6 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
                  type = builtin_type (exp->gdbarch)->builtin_int;
              }
 
-            if (noside == EVAL_AVOID_SIDE_EFFECTS)
-              return allocate_value (type);
-
             switch (op)
               {
               default:
@@ -11343,7 +11421,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
     }
 
 nosideret:
-  return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
+  return eval_skip_value (exp);
 }
 \f
 
@@ -11506,7 +11584,7 @@ get_var_value (const char *name, const char *err_msg)
 {
   lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
 
-  struct block_symbol *syms;
+  std::vector<struct block_symbol> syms;
   int nsyms = ada_lookup_symbol_list_worker (lookup_name,
                                             get_selected_block (0),
                                             VAR_DOMAIN, &syms, 1);
@@ -11633,6 +11711,10 @@ to_fixed_range_type (struct type *raw_type, struct value *dval)
 
       type = create_static_range_type (alloc_type_copy (raw_type),
                                       base_type, L, U);
+      /* create_static_range_type alters the resulting type's length
+         to match the size of the base_type, which is not what we want.
+         Set it back to the original range type's length.  */
+      TYPE_LENGTH (type) = TYPE_LENGTH (raw_type);
       TYPE_NAME (type) = name;
       return type;
     }
@@ -11736,6 +11818,10 @@ struct exception_support_info
       a catchpoint on failed assertions.  */
    const char *catch_assert_sym;
 
+   /* The name of the symbol to break on in order to insert
+      a catchpoint on exception handling.  */
+   const char *catch_handlers_sym;
+
    /* Assuming that the inferior just triggered an unhandled exception
       catchpoint, this function is responsible for returning the address
       in inferior memory where the name of that exception is stored.
@@ -11748,13 +11834,27 @@ static CORE_ADDR ada_unhandled_exception_name_addr_from_raise (void);
 
 /* The following exception support info structure describes how to
    implement exception catchpoints with the latest version of the
-   Ada runtime (as of 2007-03-06).  */
+   Ada runtime (as of 2019-08-??).  */
 
 static const struct exception_support_info default_exception_support_info =
 {
   "__gnat_debug_raise_exception", /* catch_exception_sym */
   "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
   "__gnat_debug_raise_assert_failure", /* catch_assert_sym */
+  "__gnat_begin_handler_v1", /* catch_handlers_sym */
+  ada_unhandled_exception_name_addr
+};
+
+/* The following exception support info structure describes how to
+   implement exception catchpoints with an earlier version of the
+   Ada runtime (as of 2007-03-06) using v0 of the EH ABI.  */
+
+static const struct exception_support_info exception_support_info_v0 =
+{
+  "__gnat_debug_raise_exception", /* catch_exception_sym */
+  "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
+  "__gnat_debug_raise_assert_failure", /* catch_assert_sym */
+  "__gnat_begin_handler", /* catch_handlers_sym */
   ada_unhandled_exception_name_addr
 };
 
@@ -11767,6 +11867,7 @@ static const struct exception_support_info exception_support_info_fallback =
   "__gnat_raise_nodefer_with_msg", /* catch_exception_sym */
   "__gnat_unhandled_exception", /* catch_exception_unhandled_sym */
   "system__assertions__raise_assert_failure",  /* catch_assert_sym */
+  "__gnat_begin_handler", /* catch_handlers_sym */
   ada_unhandled_exception_name_addr_from_raise
 };
 
@@ -11817,8 +11918,34 @@ ada_has_this_exception_support (const struct exception_support_info *einfo)
   /* Make sure that the symbol we found corresponds to a function.  */
 
   if (SYMBOL_CLASS (sym) != LOC_BLOCK)
-    error (_("Symbol \"%s\" is not a function (class = %d)"),
-           SYMBOL_LINKAGE_NAME (sym), SYMBOL_CLASS (sym));
+    {
+      error (_("Symbol \"%s\" is not a function (class = %d)"),
+            sym->linkage_name (), SYMBOL_CLASS (sym));
+      return 0;
+    }
+
+  sym = standard_lookup (einfo->catch_handlers_sym, NULL, VAR_DOMAIN);
+  if (sym == NULL)
+    {
+      struct bound_minimal_symbol msym
+       = lookup_minimal_symbol (einfo->catch_handlers_sym, NULL, NULL);
+
+      if (msym.minsym && MSYMBOL_TYPE (msym.minsym) != mst_solib_trampoline)
+       error (_("Your Ada runtime appears to be missing some debugging "
+                "information.\nCannot insert Ada exception catchpoint "
+                "in this configuration."));
+
+      return 0;
+    }
+
+  /* Make sure that the symbol we found corresponds to a function.  */
+
+  if (SYMBOL_CLASS (sym) != LOC_BLOCK)
+    {
+      error (_("Symbol \"%s\" is not a function (class = %d)"),
+            sym->linkage_name (), SYMBOL_CLASS (sym));
+      return 0;
+    }
 
   return 1;
 }
@@ -11845,6 +11972,13 @@ ada_exception_support_info_sniffer (void)
       return;
     }
 
+  /* Try the v0 exception suport info.  */
+  if (ada_has_this_exception_support (&exception_support_info_v0))
+    {
+      data->exception_info = &exception_support_info_v0;
+      return;
+    }
+
   /* Try our fallback exception suport info.  */
   if (ada_has_this_exception_support (&exception_support_info_fallback))
     {
@@ -11866,7 +12000,7 @@ ada_exception_support_info_sniffer (void)
      loaded.  If it is not started, this may mean that the symbol is
      in a shared library.  */
 
-  if (ptid_get_pid (inferior_ptid) == 0)
+  if (inferior_ptid.pid () == 0)
     error (_("Unable to insert catchpoint. Try to start the program first."));
 
   /* At this point, we know that we are debugging an Ada program and
@@ -11908,7 +12042,7 @@ is_known_support_routine (struct frame_info *frame)
   if (access (fullname, R_OK) != 0)
     return 1;
 
-  /* Check the unit filename againt the Ada runtime file naming.
+  /* Check the unit filename against the Ada runtime file naming.
      We also check the name of the objfile against the name of some
      known system libraries that sometimes come with debugging info
      too.  */
@@ -12001,8 +12135,8 @@ ada_unhandled_exception_name_addr_from_raise (void)
           if (strcmp (func_name.get (),
                      data->exception_info->catch_exception_sym) == 0)
            break; /* We found the frame we were looking for...  */
-         fi = get_prev_frame (fi);
        }
+      fi = get_prev_frame (fi);
     }
 
   if (fi == NULL)
@@ -12035,7 +12169,12 @@ ada_exception_name_addr_1 (enum ada_exception_catchpoint_kind ex,
       case ada_catch_exception_unhandled:
         return data->exception_info->unhandled_exception_name_addr ();
         break;
-      
+
+      case ada_catch_handlers:
+        return 0;  /* The runtimes does not provide access to the exception
+                     name.  */
+        break;
+
       case ada_catch_assert:
         return 0;  /* Exception name is not relevant in this case.  */
         break;
@@ -12045,7 +12184,67 @@ ada_exception_name_addr_1 (enum ada_exception_catchpoint_kind ex,
         break;
     }
 
-  return 0; /* Should never be reached.  */
+  return 0; /* Should never be reached.  */
+}
+
+/* Assuming the inferior is stopped at an exception catchpoint,
+   return the message which was associated to the exception, if
+   available.  Return NULL if the message could not be retrieved.
+
+   Note: The exception message can be associated to an exception
+   either through the use of the Raise_Exception function, or
+   more simply (Ada 2005 and later), via:
+
+       raise Exception_Name with "exception message";
+
+   */
+
+static gdb::unique_xmalloc_ptr<char>
+ada_exception_message_1 (void)
+{
+  struct value *e_msg_val;
+  int e_msg_len;
+
+  /* For runtimes that support this feature, the exception message
+     is passed as an unbounded string argument called "message".  */
+  e_msg_val = parse_and_eval ("message");
+  if (e_msg_val == NULL)
+    return NULL; /* Exception message not supported.  */
+
+  e_msg_val = ada_coerce_to_simple_array (e_msg_val);
+  gdb_assert (e_msg_val != NULL);
+  e_msg_len = TYPE_LENGTH (value_type (e_msg_val));
+
+  /* If the message string is empty, then treat it as if there was
+     no exception message.  */
+  if (e_msg_len <= 0)
+    return NULL;
+
+  gdb::unique_xmalloc_ptr<char> e_msg ((char *) xmalloc (e_msg_len + 1));
+  read_memory_string (value_address (e_msg_val), e_msg.get (), e_msg_len + 1);
+  e_msg.get ()[e_msg_len] = '\0';
+
+  return e_msg;
+}
+
+/* Same as ada_exception_message_1, except that all exceptions are
+   contained here (returning NULL instead).  */
+
+static gdb::unique_xmalloc_ptr<char>
+ada_exception_message (void)
+{
+  gdb::unique_xmalloc_ptr<char> e_msg;
+
+  try
+    {
+      e_msg = ada_exception_message_1 ();
+    }
+  catch (const gdb_exception_error &e)
+    {
+      e_msg.reset (nullptr);
+    }
+
+  return e_msg;
 }
 
 /* Same as ada_exception_name_addr_1, except that it intercepts and contains
@@ -12059,22 +12258,23 @@ ada_exception_name_addr (enum ada_exception_catchpoint_kind ex,
 {
   CORE_ADDR result = 0;
 
-  TRY
+  try
     {
       result = ada_exception_name_addr_1 (ex, b);
     }
 
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const gdb_exception_error &e)
     {
-      warning (_("failed to get exception name: %s"), e.message);
+      warning (_("failed to get exception name: %s"), e.what ());
       return 0;
     }
-  END_CATCH
 
   return result;
 }
 
-static char *ada_exception_catchpoint_cond_string (const char *excep_string);
+static std::string ada_exception_catchpoint_cond_string
+  (const char *excep_string,
+   enum ada_exception_catchpoint_kind ex);
 
 /* Ada catchpoints.
 
@@ -12095,8 +12295,8 @@ static char *ada_exception_catchpoint_cond_string (const char *excep_string);
 class ada_catchpoint_location : public bp_location
 {
 public:
-  ada_catchpoint_location (const bp_location_ops *ops, breakpoint *owner)
-    : bp_location (ops, owner)
+  ada_catchpoint_location (breakpoint *owner)
+    : bp_location (owner, bp_loc_software_breakpoint)
   {}
 
   /* The condition that checks whether the exception that was raised
@@ -12105,46 +12305,33 @@ public:
   expression_up excep_cond_expr;
 };
 
-/* Implement the DTOR method in the bp_location_ops structure for all
-   Ada exception catchpoint kinds.  */
-
-static void
-ada_catchpoint_location_dtor (struct bp_location *bl)
-{
-  struct ada_catchpoint_location *al = (struct ada_catchpoint_location *) bl;
-
-  al->excep_cond_expr.reset ();
-}
-
-/* The vtable to be used in Ada catchpoint locations.  */
-
-static const struct bp_location_ops ada_catchpoint_location_ops =
-{
-  ada_catchpoint_location_dtor
-};
-
 /* An instance of this type is used to represent an Ada catchpoint.  */
 
 struct ada_catchpoint : public breakpoint
 {
-  ~ada_catchpoint () override;
+  explicit ada_catchpoint (enum ada_exception_catchpoint_kind kind)
+    : m_kind (kind)
+  {
+  }
 
   /* The name of the specific exception the user specified.  */
-  char *excep_string;
+  std::string excep_string;
+
+  /* What kind of catchpoint this is.  */
+  enum ada_exception_catchpoint_kind m_kind;
 };
 
 /* Parse the exception condition string in the context of each of the
    catchpoint's locations, and store them for later evaluation.  */
 
 static void
-create_excep_cond_exprs (struct ada_catchpoint *c)
+create_excep_cond_exprs (struct ada_catchpoint *c,
+                         enum ada_exception_catchpoint_kind ex)
 {
-  struct cleanup *old_chain;
   struct bp_location *bl;
-  char *cond_string;
 
   /* Nothing to do if there's no specific exception to catch.  */
-  if (c->excep_string == NULL)
+  if (c->excep_string.empty ())
     return;
 
   /* Same if there are no locations... */
@@ -12153,8 +12340,8 @@ create_excep_cond_exprs (struct ada_catchpoint *c)
 
   /* Compute the condition expression in text form, from the specific
      expection we want to catch.  */
-  cond_string = ada_exception_catchpoint_cond_string (c->excep_string);
-  old_chain = make_cleanup (xfree, cond_string);
+  std::string cond_string
+    = ada_exception_catchpoint_cond_string (c->excep_string.c_str (), ex);
 
   /* Iterate over all the catchpoint's locations, and parse an
      expression for each.  */
@@ -12168,50 +12355,39 @@ create_excep_cond_exprs (struct ada_catchpoint *c)
        {
          const char *s;
 
-         s = cond_string;
-         TRY
+         s = cond_string.c_str ();
+         try
            {
              exp = parse_exp_1 (&s, bl->address,
                                 block_for_pc (bl->address),
                                 0);
            }
-         CATCH (e, RETURN_MASK_ERROR)
+         catch (const gdb_exception_error &e)
            {
              warning (_("failed to reevaluate internal exception condition "
                         "for catchpoint %d: %s"),
-                      c->number, e.message);
+                      c->number, e.what ());
            }
-         END_CATCH
        }
 
       ada_loc->excep_cond_expr = std::move (exp);
     }
-
-  do_cleanups (old_chain);
-}
-
-/* ada_catchpoint destructor.  */
-
-ada_catchpoint::~ada_catchpoint ()
-{
-  xfree (this->excep_string);
 }
 
 /* Implement the ALLOCATE_LOCATION method in the breakpoint_ops
    structure for all exception catchpoint kinds.  */
 
 static struct bp_location *
-allocate_location_exception (enum ada_exception_catchpoint_kind ex,
-                            struct breakpoint *self)
+allocate_location_exception (struct breakpoint *self)
 {
-  return new ada_catchpoint_location (&ada_catchpoint_location_ops, self);
+  return new ada_catchpoint_location (self);
 }
 
 /* Implement the RE_SET method in the breakpoint_ops structure for all
    exception catchpoint kinds.  */
 
 static void
-re_set_exception (enum ada_exception_catchpoint_kind ex, struct breakpoint *b)
+re_set_exception (struct breakpoint *b)
 {
   struct ada_catchpoint *c = (struct ada_catchpoint *) b;
 
@@ -12221,7 +12397,7 @@ re_set_exception (enum ada_exception_catchpoint_kind ex, struct breakpoint *b)
 
   /* Reparse the exception conditional expressions.  One for each
      location.  */
-  create_excep_cond_exprs (c);
+  create_excep_cond_exprs (c, c->m_kind);
 }
 
 /* Returns true if we should stop for this breakpoint hit.  If the
@@ -12236,8 +12412,32 @@ should_stop_exception (const struct bp_location *bl)
     = (const struct ada_catchpoint_location *) bl;
   int stop;
 
+  struct internalvar *var = lookup_internalvar ("_ada_exception");
+  if (c->m_kind == ada_catch_assert)
+    clear_internalvar (var);
+  else
+    {
+      try
+       {
+         const char *expr;
+
+         if (c->m_kind == ada_catch_handlers)
+           expr = ("GNAT_GCC_exception_Access(gcc_exception)"
+                   ".all.occurrence.id");
+         else
+           expr = "e";
+
+         struct value *exc = parse_and_eval (expr);
+         set_internalvar (var, exc);
+       }
+      catch (const gdb_exception_error &ex)
+       {
+         clear_internalvar (var);
+       }
+    }
+
   /* With no specific exception, should always stop.  */
-  if (c->excep_string == NULL)
+  if (c->excep_string.empty ())
     return 1;
 
   if (ada_loc->excep_cond_expr == NULL)
@@ -12248,7 +12448,7 @@ should_stop_exception (const struct bp_location *bl)
     }
 
   stop = 1;
-  TRY
+  try
     {
       struct value *mark;
 
@@ -12256,12 +12456,11 @@ should_stop_exception (const struct bp_location *bl)
       stop = value_true (evaluate_expression (ada_loc->excep_cond_expr.get ()));
       value_free_to_mark (mark);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const gdb_exception &ex)
     {
       exception_fprintf (gdb_stderr, ex,
                         _("Error in testing exception condition:\n"));
     }
-  END_CATCH
 
   return stop;
 }
@@ -12270,7 +12469,7 @@ should_stop_exception (const struct bp_location *bl)
    for all exception catchpoint kinds.  */
 
 static void
-check_status_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
+check_status_exception (bpstat bs)
 {
   bs->stop = should_stop_exception (bs->bp_location_at);
 }
@@ -12279,7 +12478,7 @@ check_status_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
    for all exception catchpoint kinds.  */
 
 static enum print_stop_action
-print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
+print_it_exception (bpstat bs)
 {
   struct ui_out *uiout = current_uiout;
   struct breakpoint *b = bs->breakpoint_at;
@@ -12295,7 +12494,7 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
 
   uiout->text (b->disposition == disp_del
               ? "\nTemporary catchpoint " : "\nCatchpoint ");
-  uiout->field_int ("bkptno", b->number);
+  uiout->field_signed ("bkptno", b->number);
   uiout->text (", ");
 
   /* ada_exception_name_addr relies on the selected frame being the
@@ -12305,12 +12504,14 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
      ada_find_printable_frame).  */
   select_frame (get_current_frame ());
 
-  switch (ex)
+  struct ada_catchpoint *c = (struct ada_catchpoint *) b;
+  switch (c->m_kind)
     {
       case ada_catch_exception:
       case ada_catch_exception_unhandled:
+      case ada_catch_handlers:
        {
-         const CORE_ADDR addr = ada_exception_name_addr (ex, b);
+         const CORE_ADDR addr = ada_exception_name_addr (c->m_kind, b);
          char exception_name[256];
 
          if (addr != 0)
@@ -12334,7 +12535,7 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
             it clearer to the user which kind of catchpoint just got
             hit.  We used ui_out_text to make sure that this extra
             info does not pollute the exception name in the MI case.  */
-         if (ex == ada_catch_exception_unhandled)
+         if (c->m_kind == ada_catch_exception_unhandled)
            uiout->text ("unhandled ");
          uiout->field_string ("exception-name", exception_name);
        }
@@ -12348,6 +12549,15 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
        uiout->text ("failed assertion");
        break;
     }
+
+  gdb::unique_xmalloc_ptr<char> exception_message = ada_exception_message ();
+  if (exception_message != NULL)
+    {
+      uiout->text (" (");
+      uiout->field_string ("exception-message", exception_message.get ());
+      uiout->text (")");
+    }
+
   uiout->text (" at ");
   ada_find_printable_frame (get_current_frame ());
 
@@ -12358,31 +12568,27 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
    for all exception catchpoint kinds.  */
 
 static void
-print_one_exception (enum ada_exception_catchpoint_kind ex,
-                     struct breakpoint *b, struct bp_location **last_loc)
+print_one_exception (struct breakpoint *b, struct bp_location **last_loc)
 { 
   struct ui_out *uiout = current_uiout;
   struct ada_catchpoint *c = (struct ada_catchpoint *) b;
   struct value_print_options opts;
 
   get_user_print_options (&opts);
+
   if (opts.addressprint)
-    {
-      annotate_field (4);
-      uiout->field_core_addr ("addr", b->loc->gdbarch, b->loc->address);
-    }
+    uiout->field_skip ("addr");
 
   annotate_field (5);
-  *last_loc = b->loc;
-  switch (ex)
+  switch (c->m_kind)
     {
       case ada_catch_exception:
-        if (c->excep_string != NULL)
+        if (!c->excep_string.empty ())
           {
-            char *msg = xstrprintf (_("`%s' Ada exception"), c->excep_string);
+           std::string msg = string_printf (_("`%s' Ada exception"),
+                                            c->excep_string.c_str ());
 
             uiout->field_string ("what", msg);
-            xfree (msg);
           }
         else
           uiout->field_string ("what", "all Ada exceptions");
@@ -12393,6 +12599,17 @@ print_one_exception (enum ada_exception_catchpoint_kind ex,
         uiout->field_string ("what", "unhandled Ada exceptions");
         break;
       
+      case ada_catch_handlers:
+        if (!c->excep_string.empty ())
+          {
+           uiout->field_fmt ("what",
+                             _("`%s' Ada exception handlers"),
+                             c->excep_string.c_str ());
+          }
+        else
+         uiout->field_string ("what", "all Ada exceptions handlers");
+        break;
+
       case ada_catch_assert:
         uiout->field_string ("what", "failed Ada assertions");
         break;
@@ -12407,27 +12624,24 @@ print_one_exception (enum ada_exception_catchpoint_kind ex,
    for all exception catchpoint kinds.  */
 
 static void
-print_mention_exception (enum ada_exception_catchpoint_kind ex,
-                         struct breakpoint *b)
+print_mention_exception (struct breakpoint *b)
 {
   struct ada_catchpoint *c = (struct ada_catchpoint *) b;
   struct ui_out *uiout = current_uiout;
 
   uiout->text (b->disposition == disp_del ? _("Temporary catchpoint ")
                                                  : _("Catchpoint "));
-  uiout->field_int ("bkptno", b->number);
+  uiout->field_signed ("bkptno", b->number);
   uiout->text (": ");
 
-  switch (ex)
+  switch (c->m_kind)
     {
       case ada_catch_exception:
-        if (c->excep_string != NULL)
+        if (!c->excep_string.empty ())
          {
-           char *info = xstrprintf (_("`%s' Ada exception"), c->excep_string);
-           struct cleanup *old_chain = make_cleanup (xfree, info);
-
-           uiout->text (info);
-           do_cleanups (old_chain);
+           std::string info = string_printf (_("`%s' Ada exception"),
+                                             c->excep_string.c_str ());
+           uiout->text (info.c_str ());
          }
         else
           uiout->text (_("all Ada exceptions"));
@@ -12436,7 +12650,19 @@ print_mention_exception (enum ada_exception_catchpoint_kind ex,
       case ada_catch_exception_unhandled:
         uiout->text (_("unhandled Ada exceptions"));
         break;
-      
+
+      case ada_catch_handlers:
+        if (!c->excep_string.empty ())
+         {
+           std::string info
+             = string_printf (_("`%s' Ada exception handlers"),
+                              c->excep_string.c_str ());
+           uiout->text (info.c_str ());
+         }
+        else
+          uiout->text (_("all Ada exceptions handlers"));
+        break;
+
       case ada_catch_assert:
         uiout->text (_("failed Ada assertions"));
         break;
@@ -12451,23 +12677,26 @@ print_mention_exception (enum ada_exception_catchpoint_kind ex,
    for all exception catchpoint kinds.  */
 
 static void
-print_recreate_exception (enum ada_exception_catchpoint_kind ex,
-                         struct breakpoint *b, struct ui_file *fp)
+print_recreate_exception (struct breakpoint *b, struct ui_file *fp)
 {
   struct ada_catchpoint *c = (struct ada_catchpoint *) b;
 
-  switch (ex)
+  switch (c->m_kind)
     {
       case ada_catch_exception:
        fprintf_filtered (fp, "catch exception");
-       if (c->excep_string != NULL)
-         fprintf_filtered (fp, " %s", c->excep_string);
+       if (!c->excep_string.empty ())
+         fprintf_filtered (fp, " %s", c->excep_string.c_str ());
        break;
 
       case ada_catch_exception_unhandled:
        fprintf_filtered (fp, "catch exception unhandled");
        break;
 
+      case ada_catch_handlers:
+       fprintf_filtered (fp, "catch handlers");
+       break;
+
       case ada_catch_assert:
        fprintf_filtered (fp, "catch assert");
        break;
@@ -12478,209 +12707,51 @@ print_recreate_exception (enum ada_exception_catchpoint_kind ex,
   print_recreate_thread (b, fp);
 }
 
-/* Virtual table for "catch exception" breakpoints.  */
-
-static struct bp_location *
-allocate_location_catch_exception (struct breakpoint *self)
-{
-  return allocate_location_exception (ada_catch_exception, self);
-}
-
-static void
-re_set_catch_exception (struct breakpoint *b)
-{
-  re_set_exception (ada_catch_exception, b);
-}
-
-static void
-check_status_catch_exception (bpstat bs)
-{
-  check_status_exception (ada_catch_exception, bs);
-}
-
-static enum print_stop_action
-print_it_catch_exception (bpstat bs)
-{
-  return print_it_exception (ada_catch_exception, bs);
-}
-
-static void
-print_one_catch_exception (struct breakpoint *b, struct bp_location **last_loc)
-{
-  print_one_exception (ada_catch_exception, b, last_loc);
-}
-
-static void
-print_mention_catch_exception (struct breakpoint *b)
-{
-  print_mention_exception (ada_catch_exception, b);
-}
-
-static void
-print_recreate_catch_exception (struct breakpoint *b, struct ui_file *fp)
-{
-  print_recreate_exception (ada_catch_exception, b, fp);
-}
-
+/* Virtual tables for various breakpoint types.  */
 static struct breakpoint_ops catch_exception_breakpoint_ops;
-
-/* Virtual table for "catch exception unhandled" breakpoints.  */
-
-static struct bp_location *
-allocate_location_catch_exception_unhandled (struct breakpoint *self)
-{
-  return allocate_location_exception (ada_catch_exception_unhandled, self);
-}
-
-static void
-re_set_catch_exception_unhandled (struct breakpoint *b)
-{
-  re_set_exception (ada_catch_exception_unhandled, b);
-}
-
-static void
-check_status_catch_exception_unhandled (bpstat bs)
-{
-  check_status_exception (ada_catch_exception_unhandled, bs);
-}
-
-static enum print_stop_action
-print_it_catch_exception_unhandled (bpstat bs)
-{
-  return print_it_exception (ada_catch_exception_unhandled, bs);
-}
-
-static void
-print_one_catch_exception_unhandled (struct breakpoint *b,
-                                    struct bp_location **last_loc)
-{
-  print_one_exception (ada_catch_exception_unhandled, b, last_loc);
-}
-
-static void
-print_mention_catch_exception_unhandled (struct breakpoint *b)
-{
-  print_mention_exception (ada_catch_exception_unhandled, b);
-}
-
-static void
-print_recreate_catch_exception_unhandled (struct breakpoint *b,
-                                         struct ui_file *fp)
-{
-  print_recreate_exception (ada_catch_exception_unhandled, b, fp);
-}
-
 static struct breakpoint_ops catch_exception_unhandled_breakpoint_ops;
-
-/* Virtual table for "catch assert" breakpoints.  */
-
-static struct bp_location *
-allocate_location_catch_assert (struct breakpoint *self)
-{
-  return allocate_location_exception (ada_catch_assert, self);
-}
-
-static void
-re_set_catch_assert (struct breakpoint *b)
-{
-  re_set_exception (ada_catch_assert, b);
-}
-
-static void
-check_status_catch_assert (bpstat bs)
-{
-  check_status_exception (ada_catch_assert, bs);
-}
-
-static enum print_stop_action
-print_it_catch_assert (bpstat bs)
-{
-  return print_it_exception (ada_catch_assert, bs);
-}
-
-static void
-print_one_catch_assert (struct breakpoint *b, struct bp_location **last_loc)
-{
-  print_one_exception (ada_catch_assert, b, last_loc);
-}
-
-static void
-print_mention_catch_assert (struct breakpoint *b)
-{
-  print_mention_exception (ada_catch_assert, b);
-}
-
-static void
-print_recreate_catch_assert (struct breakpoint *b, struct ui_file *fp)
-{
-  print_recreate_exception (ada_catch_assert, b, fp);
-}
-
 static struct breakpoint_ops catch_assert_breakpoint_ops;
+static struct breakpoint_ops catch_handlers_breakpoint_ops;
 
-/* Return a newly allocated copy of the first space-separated token
-   in ARGSP, and then adjust ARGSP to point immediately after that
-   token.
+/* See ada-lang.h.  */
 
-   Return NULL if ARGPS does not contain any more tokens.  */
-
-static char *
-ada_get_next_arg (const char **argsp)
+bool
+is_ada_exception_catchpoint (breakpoint *bp)
 {
-  const char *args = *argsp;
-  const char *end;
-  char *result;
-
-  args = skip_spaces (args);
-  if (args[0] == '\0')
-    return NULL; /* No more arguments.  */
-  
-  /* Find the end of the current argument.  */
-
-  end = skip_to_space (args);
-
-  /* Adjust ARGSP to point to the start of the next argument.  */
-
-  *argsp = end;
-
-  /* Make a copy of the current argument and return it.  */
-
-  result = (char *) xmalloc (end - args + 1);
-  strncpy (result, args, end - args);
-  result[end - args] = '\0';
-  
-  return result;
+  return (bp->ops == &catch_exception_breakpoint_ops
+         || bp->ops == &catch_exception_unhandled_breakpoint_ops
+         || bp->ops == &catch_assert_breakpoint_ops
+         || bp->ops == &catch_handlers_breakpoint_ops);
 }
 
 /* Split the arguments specified in a "catch exception" command.  
    Set EX to the appropriate catchpoint type.
    Set EXCEP_STRING to the name of the specific exception if
    specified by the user.
+   IS_CATCH_HANDLERS_CMD: True if the arguments are for a
+   "catch handlers" command.  False otherwise.
    If a condition is found at the end of the arguments, the condition
    expression is stored in COND_STRING (memory must be deallocated
    after use).  Otherwise COND_STRING is set to NULL.  */
 
 static void
 catch_ada_exception_command_split (const char *args,
+                                  bool is_catch_handlers_cmd,
                                    enum ada_exception_catchpoint_kind *ex,
-                                  char **excep_string,
-                                  char **cond_string)
+                                  std::string *excep_string,
+                                  std::string *cond_string)
 {
-  struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
-  char *exception_name;
-  char *cond = NULL;
+  std::string exception_name;
 
-  exception_name = ada_get_next_arg (&args);
-  if (exception_name != NULL && strcmp (exception_name, "if") == 0)
+  exception_name = extract_arg (&args);
+  if (exception_name == "if")
     {
       /* This is not an exception name; this is the start of a condition
         expression for a catchpoint on all exceptions.  So, "un-get"
         this token, and set exception_name to NULL.  */
-      xfree (exception_name);
-      exception_name = NULL;
+      exception_name.clear ();
       args -= 2;
     }
-  make_cleanup (xfree, exception_name);
 
   /* Check to see if we have a condition.  */
 
@@ -12693,8 +12764,7 @@ catch_ada_exception_command_split (const char *args,
 
       if (args[0] == '\0')
         error (_("Condition missing after `if' keyword"));
-      cond = xstrdup (args);
-      make_cleanup (xfree, cond);
+      *cond_string = args;
 
       args += strlen (args);
     }
@@ -12705,19 +12775,23 @@ catch_ada_exception_command_split (const char *args,
   if (args[0] != '\0')
     error (_("Junk at end of expression"));
 
-  discard_cleanups (old_chain);
-
-  if (exception_name == NULL)
+  if (is_catch_handlers_cmd)
+    {
+      /* Catch handling of exceptions.  */
+      *ex = ada_catch_handlers;
+      *excep_string = exception_name;
+    }
+  else if (exception_name.empty ())
     {
       /* Catch all exceptions.  */
       *ex = ada_catch_exception;
-      *excep_string = NULL;
+      excep_string->clear ();
     }
-  else if (strcmp (exception_name, "unhandled") == 0)
+  else if (exception_name == "unhandled")
     {
       /* Catch unhandled exceptions.  */
       *ex = ada_catch_exception_unhandled;
-      *excep_string = NULL;
+      excep_string->clear ();
     }
   else
     {
@@ -12725,7 +12799,6 @@ catch_ada_exception_command_split (const char *args,
       *ex = ada_catch_exception;
       *excep_string = exception_name;
     }
-  *cond_string = cond;
 }
 
 /* Return the name of the symbol on which we should break in order to
@@ -12749,6 +12822,9 @@ ada_exception_sym_name (enum ada_exception_catchpoint_kind ex)
       case ada_catch_assert:
         return (data->exception_info->catch_assert_sym);
         break;
+      case ada_catch_handlers:
+        return (data->exception_info->catch_handlers_sym);
+        break;
       default:
         internal_error (__FILE__, __LINE__,
                         _("unexpected catchpoint kind (%d)"), ex);
@@ -12772,6 +12848,9 @@ ada_exception_breakpoint_ops (enum ada_exception_catchpoint_kind ex)
       case ada_catch_assert:
         return (&catch_assert_breakpoint_ops);
         break;
+      case ada_catch_handlers:
+        return (&catch_handlers_breakpoint_ops);
+        break;
       default:
         internal_error (__FILE__, __LINE__,
                         _("unexpected catchpoint kind (%d)"), ex);
@@ -12782,14 +12861,25 @@ ada_exception_breakpoint_ops (enum ada_exception_catchpoint_kind ex)
    being raised with the exception that the user wants to catch.  This
    assumes that this condition is used when the inferior just triggered
    an exception catchpoint.
-   
-   The string returned is a newly allocated string that needs to be
-   deallocated later.  */
+   EX: the type of catchpoints used for catching Ada exceptions.  */
 
-static char *
-ada_exception_catchpoint_cond_string (const char *excep_string)
+static std::string
+ada_exception_catchpoint_cond_string (const char *excep_string,
+                                      enum ada_exception_catchpoint_kind ex)
 {
   int i;
+  bool is_standard_exc = false;
+  std::string result;
+
+  if (ex == ada_catch_handlers)
+    {
+      /* For exception handlers catchpoints, the condition string does
+         not use the same parameter as for the other exceptions.  */
+      result = ("long_integer (GNAT_GCC_exception_Access"
+               "(gcc_exception).all.occurrence.id)");
+    }
+  else
+    result = "long_integer (e)";
 
   /* The standard exceptions are a special case.  They are defined in
      runtime units that have been compiled without debugging info; if
@@ -12805,7 +12895,7 @@ ada_exception_catchpoint_cond_string (const char *excep_string)
      exception constraint_error" is rewritten into "catch exception
      standard.constraint_error".
 
-     If an exception named contraint_error is defined in another package of
+     If an exception named constraint_error is defined in another package of
      the inferior program, then the only way to specify this exception as a
      breakpoint condition is to use its fully-qualified named:
      e.g. my_package.constraint_error.  */
@@ -12814,26 +12904,31 @@ ada_exception_catchpoint_cond_string (const char *excep_string)
     {
       if (strcmp (standard_exc [i], excep_string) == 0)
        {
-          return xstrprintf ("long_integer (e) = long_integer (&standard.%s)",
-                             excep_string);
+         is_standard_exc = true;
+         break;
        }
     }
-  return xstrprintf ("long_integer (e) = long_integer (&%s)", excep_string);
+
+  result += " = ";
+
+  if (is_standard_exc)
+    string_appendf (result, "long_integer (&standard.%s)", excep_string);
+  else
+    string_appendf (result, "long_integer (&%s)", excep_string);
+
+  return result;
 }
 
 /* Return the symtab_and_line that should be used to insert an exception
    catchpoint of the TYPE kind.
 
-   EXCEP_STRING should contain the name of a specific exception that
-   the catchpoint should catch, or NULL otherwise.
-
    ADDR_STRING returns the name of the function where the real
    breakpoint that implements the catchpoints is set, depending on the
    type of catchpoint we need to create.  */
 
 static struct symtab_and_line
-ada_exception_sal (enum ada_exception_catchpoint_kind ex, char *excep_string,
-                  const char **addr_string, const struct breakpoint_ops **ops)
+ada_exception_sal (enum ada_exception_catchpoint_kind ex,
+                  std::string *addr_string, const struct breakpoint_ops **ops)
 {
   const char *sym_name;
   struct symbol *sym;
@@ -12846,17 +12941,14 @@ ada_exception_sal (enum ada_exception_catchpoint_kind ex, char *excep_string,
   sym_name = ada_exception_sym_name (ex);
   sym = standard_lookup (sym_name, NULL, VAR_DOMAIN);
 
-  /* We can assume that SYM is not NULL at this stage.  If the symbol
-     did not exist, ada_exception_support_info_sniffer would have
-     raised an exception.
+  if (sym == NULL)
+    error (_("Catchpoint symbol not found: %s"), sym_name);
 
-     Also, ada_exception_support_info_sniffer should have already
-     verified that SYM is a function symbol.  */
-  gdb_assert (sym != NULL);
-  gdb_assert (SYMBOL_CLASS (sym) == LOC_BLOCK);
+  if (SYMBOL_CLASS (sym) != LOC_BLOCK)
+    error (_("Unable to insert catchpoint. %s is not a function."), sym_name);
 
   /* Set ADDR_STRING.  */
-  *addr_string = xstrdup (sym_name);
+  *addr_string = sym_name;
 
   /* Set OPS.  */
   *ops = ada_exception_breakpoint_ops (ex);
@@ -12868,15 +12960,11 @@ ada_exception_sal (enum ada_exception_catchpoint_kind ex, char *excep_string,
 
    EX_KIND is the kind of exception catchpoint to be created.
 
-   If EXCEPT_STRING is NULL, this catchpoint is expected to trigger
+   If EXCEPT_STRING is empty, this catchpoint is expected to trigger
    for all exceptions.  Otherwise, EXCEPT_STRING indicates the name
-   of the exception to which this catchpoint applies.  When not NULL,
-   the string must be allocated on the heap, and its deallocation
-   is no longer the responsibility of the caller.
+   of the exception to which this catchpoint applies.
 
-   COND_STRING, if not NULL, is the catchpoint condition.  This string
-   must be allocated on the heap, and its deallocation is no longer
-   the responsibility of the caller.
+   COND_STRING, if not empty, is the catchpoint condition.
 
    TEMPFLAG, if nonzero, means that the underlying breakpoint
    should be temporary.
@@ -12886,24 +12974,23 @@ ada_exception_sal (enum ada_exception_catchpoint_kind ex, char *excep_string,
 void
 create_ada_exception_catchpoint (struct gdbarch *gdbarch,
                                 enum ada_exception_catchpoint_kind ex_kind,
-                                char *excep_string,
-                                char *cond_string,
+                                const std::string &excep_string,
+                                const std::string &cond_string,
                                 int tempflag,
                                 int disabled,
                                 int from_tty)
 {
-  const char *addr_string = NULL;
+  std::string addr_string;
   const struct breakpoint_ops *ops = NULL;
-  struct symtab_and_line sal
-    = ada_exception_sal (ex_kind, excep_string, &addr_string, &ops);
+  struct symtab_and_line sal = ada_exception_sal (ex_kind, &addr_string, &ops);
 
-  std::unique_ptr<ada_catchpoint> c (new ada_catchpoint ());
-  init_ada_exception_breakpoint (c.get (), gdbarch, sal, addr_string,
+  std::unique_ptr<ada_catchpoint> c (new ada_catchpoint (ex_kind));
+  init_ada_exception_breakpoint (c.get (), gdbarch, sal, addr_string.c_str (),
                                 ops, tempflag, disabled, from_tty);
   c->excep_string = excep_string;
-  create_excep_cond_exprs (c.get ());
-  if (cond_string != NULL)
-    set_breakpoint_condition (c.get (), cond_string, from_tty);
+  create_excep_cond_exprs (c.get (), ex_kind);
+  if (!cond_string.empty ())
+    set_breakpoint_condition (c.get (), cond_string.c_str (), from_tty);
   install_breakpoint (0, std::move (c), 1);
 }
 
@@ -12917,14 +13004,39 @@ catch_ada_exception_command (const char *arg_entry, int from_tty,
   struct gdbarch *gdbarch = get_current_arch ();
   int tempflag;
   enum ada_exception_catchpoint_kind ex_kind;
-  char *excep_string = NULL;
-  char *cond_string = NULL;
+  std::string excep_string;
+  std::string cond_string;
+
+  tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
+
+  if (!arg)
+    arg = "";
+  catch_ada_exception_command_split (arg, false, &ex_kind, &excep_string,
+                                    &cond_string);
+  create_ada_exception_catchpoint (gdbarch, ex_kind,
+                                  excep_string, cond_string,
+                                  tempflag, 1 /* enabled */,
+                                  from_tty);
+}
+
+/* Implement the "catch handlers" command.  */
+
+static void
+catch_ada_handlers_command (const char *arg_entry, int from_tty,
+                           struct cmd_list_element *command)
+{
+  const char *arg = arg_entry;
+  struct gdbarch *gdbarch = get_current_arch ();
+  int tempflag;
+  enum ada_exception_catchpoint_kind ex_kind;
+  std::string excep_string;
+  std::string cond_string;
 
   tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
 
   if (!arg)
     arg = "";
-  catch_ada_exception_command_split (arg, &ex_kind, &excep_string,
+  catch_ada_exception_command_split (arg, true, &ex_kind, &excep_string,
                                     &cond_string);
   create_ada_exception_catchpoint (gdbarch, ex_kind,
                                   excep_string, cond_string,
@@ -12932,6 +13044,21 @@ catch_ada_exception_command (const char *arg_entry, int from_tty,
                                   from_tty);
 }
 
+/* Completion function for the Ada "catch" commands.  */
+
+static void
+catch_ada_completer (struct cmd_list_element *cmd, completion_tracker &tracker,
+                    const char *text, const char *word)
+{
+  std::vector<ada_exc_info> exceptions = ada_exceptions_list (NULL);
+
+  for (const ada_exc_info &info : exceptions)
+    {
+      if (startswith (info.name, word))
+       tracker.add_completion (make_unique_xstrdup (info.name));
+    }
+}
+
 /* Split the arguments specified in a "catch assert" command.
 
    ARGS contains the command's arguments (or the empty string if
@@ -12941,7 +13068,7 @@ catch_ada_exception_command (const char *arg_entry, int from_tty,
    (the memory needs to be deallocated after use).  */
 
 static void
-catch_ada_assert_command_split (const char *args, char **cond_string)
+catch_ada_assert_command_split (const char *args, std::string &cond_string)
 {
   args = skip_spaces (args);
 
@@ -12953,7 +13080,7 @@ catch_ada_assert_command_split (const char *args, char **cond_string)
       args = skip_spaces (args);
       if (args[0] == '\0')
         error (_("condition missing after `if' keyword"));
-      *cond_string = xstrdup (args);
+      cond_string.assign (args);
     }
 
   /* Otherwise, there should be no other argument at the end of
@@ -12971,15 +13098,15 @@ catch_assert_command (const char *arg_entry, int from_tty,
   const char *arg = arg_entry;
   struct gdbarch *gdbarch = get_current_arch ();
   int tempflag;
-  char *cond_string = NULL;
+  std::string cond_string;
 
   tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
 
   if (!arg)
     arg = "";
-  catch_ada_assert_command_split (arg, &cond_string);
+  catch_ada_assert_command_split (arg, cond_string);
   create_ada_exception_catchpoint (gdbarch, ada_catch_assert,
-                                  NULL, cond_string,
+                                  "", cond_string,
                                   tempflag, 1 /* enabled */,
                                   from_tty);
 }
@@ -12989,7 +13116,7 @@ catch_assert_command (const char *arg_entry, int from_tty,
 static int
 ada_is_exception_sym (struct symbol *sym)
 {
-  const char *type_name = type_name_no_tag (SYMBOL_TYPE (sym));
+  const char *type_name = TYPE_NAME (SYMBOL_TYPE (sym));
 
   return (SYMBOL_CLASS (sym) != LOC_TYPEDEF
           && SYMBOL_CLASS (sym) != LOC_BLOCK
@@ -13011,13 +13138,13 @@ ada_is_non_standard_exception_sym (struct symbol *sym)
     return 0;
 
   for (i = 0; i < ARRAY_SIZE (standard_exc); i++)
-    if (strcmp (SYMBOL_LINKAGE_NAME (sym), standard_exc[i]) == 0)
+    if (strcmp (sym->linkage_name (), standard_exc[i]) == 0)
       return 0;  /* A standard exception.  */
 
   /* Numeric_Error is also a standard exception, so exclude it.
      See the STANDARD_EXC description for more details as to why
      this exception is not listed in that array.  */
-  if (strcmp (SYMBOL_LINKAGE_NAME (sym), "numeric_error") == 0)
+  if (strcmp (sym->linkage_name (), "numeric_error") == 0)
     return 0;
 
   return 1;
@@ -13130,7 +13257,7 @@ ada_add_exceptions_from_frame (compiled_regex *preg,
            default:
              if (ada_is_exception_sym (sym))
                {
-                 struct ada_exc_info info = {SYMBOL_PRINT_NAME (sym),
+                 struct ada_exc_info info = {sym->print_name (),
                                              SYMBOL_VALUE_ADDRESS (sym)};
 
                  exceptions->push_back (info);
@@ -13149,7 +13276,7 @@ static bool
 name_matches_regex (const char *name, compiled_regex *preg)
 {
   return (preg == NULL
-         || preg->exec (ada_decode (name), 0, NULL, 0) == 0);
+         || preg->exec (ada_decode (name).c_str (), 0, NULL, 0) == 0);
 }
 
 /* Add all exceptions defined globally whose name name match
@@ -13175,9 +13302,6 @@ static void
 ada_add_global_exceptions (compiled_regex *preg,
                           std::vector<ada_exc_info> *exceptions)
 {
-  struct objfile *objfile;
-  struct compunit_symtab *s;
-
   /* In Ada, the symbol "search name" is a linkage name, whereas the
      regular expression used to do the matching refers to the natural
      name.  So match against the decoded name.  */
@@ -13185,32 +13309,35 @@ ada_add_global_exceptions (compiled_regex *preg,
                           lookup_name_info::match_any (),
                           [&] (const char *search_name)
                           {
-                            const char *decoded = ada_decode (search_name);
-                            return name_matches_regex (decoded, preg);
+                            std::string decoded = ada_decode (search_name);
+                            return name_matches_regex (decoded.c_str (), preg);
                           },
                           NULL,
                           VARIABLES_DOMAIN);
 
-  ALL_COMPUNITS (objfile, s)
+  for (objfile *objfile : current_program_space->objfiles ())
     {
-      const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (s);
-      int i;
-
-      for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
+      for (compunit_symtab *s : objfile->compunits ())
        {
-         struct block *b = BLOCKVECTOR_BLOCK (bv, i);
-         struct block_iterator iter;
-         struct symbol *sym;
+         const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (s);
+         int i;
 
-         ALL_BLOCK_SYMBOLS (b, iter, sym)
-           if (ada_is_non_standard_exception_sym (sym)
-               && name_matches_regex (SYMBOL_NATURAL_NAME (sym), preg))
-             {
-               struct ada_exc_info info
-                 = {SYMBOL_PRINT_NAME (sym), SYMBOL_VALUE_ADDRESS (sym)};
+         for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
+           {
+             const struct block *b = BLOCKVECTOR_BLOCK (bv, i);
+             struct block_iterator iter;
+             struct symbol *sym;
 
-               exceptions->push_back (info);
-             }
+             ALL_BLOCK_SYMBOLS (b, iter, sym)
+               if (ada_is_non_standard_exception_sym (sym)
+                   && name_matches_regex (sym->natural_name (), preg))
+                 {
+                   struct ada_exc_info info
+                     = {sym->print_name (), SYMBOL_VALUE_ADDRESS (sym)};
+
+                   exceptions->push_back (info);
+                 }
+           }
        }
     }
 }
@@ -13534,7 +13661,7 @@ ada_print_subexp (struct expression *exp, int *pos,
       return;
 
     case OP_VAR_VALUE:
-      fputs_filtered (SYMBOL_NATURAL_NAME (exp->elts[pc + 2].symbol), stream);
+      fputs_filtered (exp->elts[pc + 2].symbol->natural_name (), stream);
       return;
 
     case BINOP_IN_BOUNDS:
@@ -13700,6 +13827,7 @@ enum ada_primitive_types {
   ada_primitive_type_natural,
   ada_primitive_type_positive,
   ada_primitive_type_system_address,
+  ada_primitive_type_storage_offset,
   nr_ada_primitive_types
 };
 
@@ -13752,6 +13880,18 @@ ada_language_arch_info (struct gdbarch *gdbarch,
   TYPE_NAME (lai->primitive_type_vector [ada_primitive_type_system_address])
     = "system__address";
 
+  /* Create the equivalent of the System.Storage_Elements.Storage_Offset
+     type.  This is a signed integral type whose size is the same as
+     the size of addresses.  */
+  {
+    unsigned int addr_length = TYPE_LENGTH
+      (lai->primitive_type_vector [ada_primitive_type_system_address]);
+
+    lai->primitive_type_vector [ada_primitive_type_storage_offset]
+      = arch_integer_type (gdbarch, addr_length * HOST_CHAR_BIT, 0,
+                          "storage_offset");
+  }
+
   lai->bool_type_symbol = NULL;
   lai->bool_type_default = builtin->builtin_bool;
 }
@@ -13787,7 +13927,7 @@ static const struct exp_descriptor ada_exp_descriptor = {
 static bool
 do_wild_match (const char *symbol_search_name,
               const lookup_name_info &lookup_name,
-              completion_match *match)
+              completion_match_result *comp_match_res)
 {
   return wild_match (symbol_search_name, ada_lookup_name (lookup_name));
 }
@@ -13797,11 +13937,21 @@ do_wild_match (const char *symbol_search_name,
 static bool
 do_full_match (const char *symbol_search_name,
               const lookup_name_info &lookup_name,
-              completion_match *match)
+              completion_match_result *comp_match_res)
 {
   return full_match (symbol_search_name, ada_lookup_name (lookup_name));
 }
 
+/* symbol_name_matcher_ftype for exact (verbatim) matches.  */
+
+static bool
+do_exact_match (const char *symbol_search_name,
+               const lookup_name_info &lookup_name,
+               completion_match_result *comp_match_res)
+{
+  return strcmp (symbol_search_name, ada_lookup_name (lookup_name)) == 0;
+}
+
 /* Build the Ada lookup name for LOOKUP_NAME.  */
 
 ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
@@ -13867,11 +14017,34 @@ ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
 static bool
 ada_symbol_name_matches (const char *symbol_search_name,
                         const lookup_name_info &lookup_name,
-                        completion_match *match)
+                        completion_match_result *comp_match_res)
 {
   return lookup_name.ada ().matches (symbol_search_name,
                                     lookup_name.match_type (),
-                                    match);
+                                    comp_match_res);
+}
+
+/* A name matcher that matches the symbol name exactly, with
+   strcmp.  */
+
+static bool
+literal_symbol_name_matcher (const char *symbol_search_name,
+                            const lookup_name_info &lookup_name,
+                            completion_match_result *comp_match_res)
+{
+  const std::string &name = lookup_name.name ();
+
+  int cmp = (lookup_name.completion_mode ()
+            ? strncmp (symbol_search_name, name.c_str (), name.size ())
+            : strcmp (symbol_search_name, name.c_str ()));
+  if (cmp == 0)
+    {
+      if (comp_match_res != NULL)
+       comp_match_res->set_match (symbol_search_name);
+      return true;
+    }
+  else
+    return false;
 }
 
 /* Implement the "la_get_symbol_name_matcher" language_defn method for
@@ -13880,12 +14053,17 @@ ada_symbol_name_matches (const char *symbol_search_name,
 static symbol_name_matcher_ftype *
 ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
 {
+  if (lookup_name.match_type () == symbol_name_match_type::SEARCH_NAME)
+    return literal_symbol_name_matcher;
+
   if (lookup_name.completion_mode ())
     return ada_symbol_name_matches;
   else
     {
       if (lookup_name.ada ().wild_match_p ())
        return do_wild_match;
+      else if (lookup_name.ada ().verbatim_p ())
+       return do_exact_match;
       else
        return do_full_match;
     }
@@ -13897,17 +14075,14 @@ static struct value *
 ada_read_var_value (struct symbol *var, const struct block *var_block,
                    struct frame_info *frame)
 {
-  const struct block *frame_block = NULL;
-  struct symbol *renaming_sym = NULL;
-
   /* The only case where default_read_var_value is not sufficient
      is when VAR is a renaming...  */
-  if (frame)
-    frame_block = get_frame_block (frame, NULL);
-  if (frame_block)
-    renaming_sym = ada_find_renaming_symbol (var, frame_block);
-  if (renaming_sym != NULL)
-    return ada_read_renaming_var_value (renaming_sym, frame_block);
+  if (frame != nullptr)
+    {
+      const struct block *frame_block = get_frame_block (frame, NULL);
+      if (frame_block != nullptr && ada_is_renaming_symbol (var))
+       return ada_read_renaming_var_value (var, frame_block);
+    }
 
   /* This is a typical case where we expect the default_read_var_value
      function to work.  */
@@ -13931,7 +14106,6 @@ extern const struct language_defn ada_language_defn = {
   ada_extensions,
   &ada_exp_descriptor,
   parse,
-  ada_yyerror,
   resolve,
   ada_printchar,                /* Print a character constant */
   ada_printstr,                 /* Function to print string constant */
@@ -13943,6 +14117,7 @@ extern const struct language_defn ada_language_defn = {
   ada_read_var_value,          /* la_read_var_value */
   NULL,                         /* Language specific skip_trampoline */
   NULL,                         /* name_of_this */
+  true,                         /* la_store_sym_names_in_linkage_form_p */
   ada_lookup_symbol_nonlocal,   /* Looking up non-local symbols.  */
   basic_lookup_transparent_type,        /* lookup_transparent_type */
   ada_la_decode,                /* Language specific symbol demangler */
@@ -13957,15 +14132,15 @@ extern const struct language_defn ada_language_defn = {
   ada_language_arch_info,
   ada_print_array_index,
   default_pass_by_reference,
-  c_get_string,
-  c_watch_location_expression,
+  ada_watch_location_expression,
   ada_get_symbol_name_matcher, /* la_get_symbol_name_matcher */
   ada_iterate_over_symbols,
   default_search_name_hash,
   &ada_varobj_ops,
   NULL,
   NULL,
-  LANG_MAGIC
+  ada_is_string_type,
+  "(...)"                      /* la_struct_too_deep_ellipsis */
 };
 
 /* Command-list for the "set/show ada" prefix command.  */
@@ -13999,33 +14174,43 @@ initialize_ada_catchpoint_ops (void)
 
   ops = &catch_exception_breakpoint_ops;
   *ops = bkpt_breakpoint_ops;
-  ops->allocate_location = allocate_location_catch_exception;
-  ops->re_set = re_set_catch_exception;
-  ops->check_status = check_status_catch_exception;
-  ops->print_it = print_it_catch_exception;
-  ops->print_one = print_one_catch_exception;
-  ops->print_mention = print_mention_catch_exception;
-  ops->print_recreate = print_recreate_catch_exception;
+  ops->allocate_location = allocate_location_exception;
+  ops->re_set = re_set_exception;
+  ops->check_status = check_status_exception;
+  ops->print_it = print_it_exception;
+  ops->print_one = print_one_exception;
+  ops->print_mention = print_mention_exception;
+  ops->print_recreate = print_recreate_exception;
 
   ops = &catch_exception_unhandled_breakpoint_ops;
   *ops = bkpt_breakpoint_ops;
-  ops->allocate_location = allocate_location_catch_exception_unhandled;
-  ops->re_set = re_set_catch_exception_unhandled;
-  ops->check_status = check_status_catch_exception_unhandled;
-  ops->print_it = print_it_catch_exception_unhandled;
-  ops->print_one = print_one_catch_exception_unhandled;
-  ops->print_mention = print_mention_catch_exception_unhandled;
-  ops->print_recreate = print_recreate_catch_exception_unhandled;
+  ops->allocate_location = allocate_location_exception;
+  ops->re_set = re_set_exception;
+  ops->check_status = check_status_exception;
+  ops->print_it = print_it_exception;
+  ops->print_one = print_one_exception;
+  ops->print_mention = print_mention_exception;
+  ops->print_recreate = print_recreate_exception;
 
   ops = &catch_assert_breakpoint_ops;
   *ops = bkpt_breakpoint_ops;
-  ops->allocate_location = allocate_location_catch_assert;
-  ops->re_set = re_set_catch_assert;
-  ops->check_status = check_status_catch_assert;
-  ops->print_it = print_it_catch_assert;
-  ops->print_one = print_one_catch_assert;
-  ops->print_mention = print_mention_catch_assert;
-  ops->print_recreate = print_recreate_catch_assert;
+  ops->allocate_location = allocate_location_exception;
+  ops->re_set = re_set_exception;
+  ops->check_status = check_status_exception;
+  ops->print_it = print_it_exception;
+  ops->print_one = print_one_exception;
+  ops->print_mention = print_mention_exception;
+  ops->print_recreate = print_recreate_exception;
+
+  ops = &catch_handlers_breakpoint_ops;
+  *ops = bkpt_breakpoint_ops;
+  ops->allocate_location = allocate_location_exception;
+  ops->re_set = re_set_exception;
+  ops->check_status = check_status_exception;
+  ops->print_it = print_it_exception;
+  ops->print_one = print_one_exception;
+  ops->print_mention = print_mention_exception;
+  ops->print_recreate = print_recreate_exception;
 }
 
 /* This module's 'new_objfile' observer.  */
@@ -14050,7 +14235,7 @@ _initialize_ada_language (void)
   initialize_ada_catchpoint_ops ();
 
   add_prefix_cmd ("ada", no_class, set_ada_command,
-                  _("Prefix command for changing Ada-specfic settings"),
+                  _("Prefix command for changing Ada-specific settings."),
                   &set_ada_list, "set ada ", 0, &setlist);
 
   add_prefix_cmd ("ada", no_class, show_ada_command,
@@ -14059,8 +14244,8 @@ _initialize_ada_language (void)
 
   add_setshow_boolean_cmd ("trust-PAD-over-XVS", class_obscure,
                            &trust_pad_over_xvs, _("\
-Enable or disable an optimization trusting PAD types over XVS types"), _("\
-Show whether an optimization trusting PAD types over XVS types is activated"),
+Enable or disable an optimization trusting PAD types over XVS types."), _("\
+Show whether an optimization trusting PAD types over XVS types is activated."),
                            _("\
 This is related to the encoding used by the GNAT compiler.  The debugger\n\
 should normally trust the contents of PAD types, but certain older versions\n\
@@ -14074,31 +14259,61 @@ this option to \"off\" unless necessary."),
   add_setshow_boolean_cmd ("print-signatures", class_vars,
                           &print_signatures, _("\
 Enable or disable the output of formal and return types for functions in the \
-overloads selection menu"), _("\
+overloads selection menu."), _("\
 Show whether the output of formal and return types for functions in the \
-overloads selection menu is activated"),
+overloads selection menu is activated."),
                           NULL, NULL, NULL, &set_ada_list, &show_ada_list);
 
   add_catch_command ("exception", _("\
 Catch Ada exceptions, when raised.\n\
-With an argument, catch only exceptions with the given name."),
+Usage: catch exception [ARG] [if CONDITION]\n\
+Without any argument, stop when any Ada exception is raised.\n\
+If ARG is \"unhandled\" (without the quotes), only stop when the exception\n\
+being raised does not have a handler (and will therefore lead to the task's\n\
+termination).\n\
+Otherwise, the catchpoint only stops when the name of the exception being\n\
+raised is the same as ARG.\n\
+CONDITION is a boolean expression that is evaluated to see whether the\n\
+exception should cause a stop."),
                     catch_ada_exception_command,
-                     NULL,
+                    catch_ada_completer,
+                    CATCH_PERMANENT,
+                    CATCH_TEMPORARY);
+
+  add_catch_command ("handlers", _("\
+Catch Ada exceptions, when handled.\n\
+Usage: catch handlers [ARG] [if CONDITION]\n\
+Without any argument, stop when any Ada exception is handled.\n\
+With an argument, catch only exceptions with the given name.\n\
+CONDITION is a boolean expression that is evaluated to see whether the\n\
+exception should cause a stop."),
+                    catch_ada_handlers_command,
+                     catch_ada_completer,
                     CATCH_PERMANENT,
                     CATCH_TEMPORARY);
   add_catch_command ("assert", _("\
 Catch failed Ada assertions, when raised.\n\
-With an argument, catch only exceptions with the given name."),
+Usage: catch assert [if CONDITION]\n\
+CONDITION is a boolean expression that is evaluated to see whether the\n\
+exception should cause a stop."),
                     catch_assert_command,
                      NULL,
                     CATCH_PERMANENT,
                     CATCH_TEMPORARY);
 
   varsize_limit = 65536;
+  add_setshow_uinteger_cmd ("varsize-limit", class_support,
+                           &varsize_limit, _("\
+Set the maximum number of bytes allowed in a variable-size object."), _("\
+Show the maximum number of bytes allowed in a variable-size object."), _("\
+Attempts to access an object whose size is not a compile-time constant\n\
+and exceeds this limit will cause an error."),
+                           NULL, NULL, &setlist, &showlist);
 
   add_info ("exceptions", info_exceptions_command,
            _("\
 List all Ada exception names.\n\
+Usage: info exceptions [REGEXP]\n\
 If a regular expression is passed as an argument, only those matching\n\
 the regular expression are listed."));
 
@@ -14108,7 +14323,7 @@ the regular expression are listed."));
                   0/*allow-unknown*/, &maintenance_set_cmdlist);
 
   add_prefix_cmd ("ada", class_maintenance, maint_show_ada_cmd,
-                 _("Show Ada maintenance-related variables"),
+                 _("Show Ada maintenance-related variables."),
                   &maint_show_ada_cmdlist, "maintenance show ada ",
                   0/*allow-unknown*/, &maintenance_show_cmdlist);
 
@@ -14122,20 +14337,11 @@ 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);
 
-  obstack_init (&symbol_list_obstack);
-
-  decoded_names_store = htab_create_alloc
-    (256, htab_hash_string, (int (*)(const void *, const void *)) streq,
-     NULL, xcalloc, xfree);
+  decoded_names_store = htab_create_alloc (256, htab_hash_string, streq_hash,
+                                          NULL, xcalloc, xfree);
 
   /* The ada-lang observers.  */
-  observer_attach_new_objfile (ada_new_objfile_observer);
-  observer_attach_free_objfile (ada_free_objfile_observer);
-  observer_attach_inferior_exit (ada_inferior_exit);
-
-  /* Setup various context-specific data.  */
-  ada_inferior_data
-    = register_inferior_data_with_cleanup (NULL, ada_inferior_data_cleanup);
-  ada_pspace_data_handle
-    = register_program_space_data_with_cleanup (NULL, ada_pspace_data_cleanup);
+  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);
 }
This page took 0.132648 seconds and 4 git commands to generate.