Report failed attempts to locate DT_NEEDED files when --verbose is in effect.
[deliverable/binutils-gdb.git] / gdb / ada-lang.c
index d87412951e8276a502fa6668d276173363691bab..be2f47a6bc964d0bda001e57c9e344612055a35e 100644 (file)
@@ -1452,6 +1452,45 @@ ada_la_decode (const char *encoded, int options)
   return xstrdup (ada_decode (encoded));
 }
 
+/* Implement la_sniff_from_mangled_name for Ada.  */
+
+static int
+ada_sniff_from_mangled_name (const char *mangled, char **out)
+{
+  const char *demangled = ada_decode (mangled);
+
+  *out = NULL;
+
+  if (demangled != mangled && demangled != NULL && demangled[0] != '<')
+    {
+      /* Set the gsymbol language to Ada, but still return 0.
+        Two reasons for that:
+
+        1. For Ada, we prefer computing the symbol's decoded name
+        on the fly rather than pre-compute it, in order to save
+        memory (Ada projects are typically very large).
+
+        2. There are some areas in the definition of the GNAT
+        encoding where, with a bit of bad luck, we might be able
+        to decode a non-Ada symbol, generating an incorrect
+        demangled name (Eg: names ending with "TB" for instance
+        are identified as task bodies and so stripped from
+        the decoded name returned).
+
+        Returning 1, here, but not setting *DEMANGLED, helps us get a
+        little bit of the best of both worlds.  Because we're last,
+        we should not affect any of the other languages that were
+        able to demangle the symbol before us; we get to correctly
+        tag Ada symbols as such; and even if we incorrectly tagged a
+        non-Ada symbol, which should be rare, any routing through the
+        Ada language should be transparent (Ada tries to behave much
+        like C/C++ with non-Ada symbols).  */
+      return 1;
+    }
+
+  return 0;
+}
+
 /* Returns non-zero iff SYM_NAME matches NAME, ignoring any trailing
    suffixes that encode debugging information or leading _ada_ on
    SYM_NAME (see is_name_suffix commentary for the debugging
@@ -2486,7 +2525,7 @@ ada_unpack_from_contents (const gdb_byte *src, int bit_offset, int bit_size,
       accumSize += HOST_CHAR_BIT - unusedLS;
       if (accumSize >= HOST_CHAR_BIT)
         {
-          unpacked[unpacked_idx] = accum & ~(~0L << HOST_CHAR_BIT);
+          unpacked[unpacked_idx] = accum & ~(~0UL << HOST_CHAR_BIT);
           accumSize -= HOST_CHAR_BIT;
           accum >>= HOST_CHAR_BIT;
           unpacked_bytes_left -= 1;
@@ -2500,7 +2539,7 @@ ada_unpack_from_contents (const gdb_byte *src, int bit_offset, int bit_size,
   while (unpacked_bytes_left > 0)
     {
       accum |= sign << accumSize;
-      unpacked[unpacked_idx] = accum & ~(~0L << HOST_CHAR_BIT);
+      unpacked[unpacked_idx] = accum & ~(~0UL << HOST_CHAR_BIT);
       accumSize -= HOST_CHAR_BIT;
       if (accumSize < 0)
        accumSize = 0;
@@ -7576,6 +7615,39 @@ ada_value_struct_elt (struct value *arg, char *name, int no_err)
             "a value that is not a record."));
 }
 
+/* Return a string representation of type TYPE.  Caller must free
+   result.  */
+
+static char *
+type_as_string (struct type *type)
+{
+  struct ui_file *tmp_stream = mem_fileopen ();
+  struct cleanup *old_chain;
+  char *str;
+
+  tmp_stream = mem_fileopen ();
+  old_chain = make_cleanup_ui_file_delete (tmp_stream);
+
+  type_print (type, "", tmp_stream, -1);
+  str = ui_file_xstrdup (tmp_stream, NULL);
+
+  do_cleanups (old_chain);
+  return str;
+}
+
+/* Return a string representation of type TYPE, and install a cleanup
+   that releases it.  */
+
+static char *
+type_as_string_and_cleanup (struct type *type)
+{
+  char *str;
+
+  str = type_as_string (type);
+  make_cleanup (xfree, str);
+  return str;
+}
+
 /* Given a type TYPE, look up the type of the component of type named NAME.
    If DISPP is non-null, add its byte displacement from the beginning of a
    structure (pointed to by a value) of type TYPE to *DISPP (does not
@@ -7616,22 +7688,15 @@ ada_lookup_struct_elt_type (struct type *type, char *name, int refok,
       || (TYPE_CODE (type) != TYPE_CODE_STRUCT
           && TYPE_CODE (type) != TYPE_CODE_UNION))
     {
+      const char *type_str;
+
       if (noerr)
         return NULL;
-      else
-        {
-          target_terminal_ours ();
-          gdb_flush (gdb_stdout);
-         if (type == NULL)
-           error (_("Type (null) is not a structure or union type"));
-         else
-           {
-             /* XXX: type_sprint */
-             fprintf_unfiltered (gdb_stderr, _("Type "));
-             type_print (type, "", gdb_stderr, -1);
-             error (_(" is not a structure or union type"));
-           }
-        }
+
+      type_str = (type != NULL
+                 ? type_as_string_and_cleanup (type)
+                 : _("(null)"));
+      error (_("Type %s is not a structure or union type"), type_str);
     }
 
   type = to_static_fixed_type (type);
@@ -7701,22 +7766,10 @@ ada_lookup_struct_elt_type (struct type *type, char *name, int refok,
 BadName:
   if (!noerr)
     {
-      target_terminal_ours ();
-      gdb_flush (gdb_stdout);
-      if (name == NULL)
-        {
-         /* XXX: type_sprint */
-         fprintf_unfiltered (gdb_stderr, _("Type "));
-         type_print (type, "", gdb_stderr, -1);
-         error (_(" has no component named <null>"));
-       }
-      else
-       {
-         /* XXX: type_sprint */
-         fprintf_unfiltered (gdb_stderr, _("Type "));
-         type_print (type, "", gdb_stderr, -1);
-         error (_(" has no component named %s"), name);
-       }
+      const char *name_str = name != NULL ? name : _("<null>");
+
+      error (_("Type %s has no component named %s"),
+            type_as_string_and_cleanup (type), name_str);
     }
 
   return NULL;
@@ -12169,6 +12222,8 @@ ada_unhandled_exception_name_addr_from_raise (void)
    (of any type), return the address in inferior memory where the name
    of the exception is stored, if applicable.
 
+   Assumes the selected frame is the current frame.
+
    Return zero if the address could not be computed, or if not relevant.  */
 
 static CORE_ADDR
@@ -12470,6 +12525,13 @@ print_it_exception (enum ada_exception_catchpoint_kind ex, bpstat bs)
   ui_out_field_int (uiout, "bkptno", b->number);
   ui_out_text (uiout, ", ");
 
+  /* ada_exception_name_addr relies on the selected frame being the
+     current frame.  Need to do this here because this function may be
+     called more than once when printing a stop, and below, we'll
+     select the first frame past the Ada run-time (see
+     ada_find_printable_frame).  */
+  select_frame (get_current_frame ());
+
   switch (ex)
     {
       case ada_catch_exception:
@@ -13942,16 +14004,16 @@ ada_language_arch_info (struct gdbarch *gdbarch,
     = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "character");
   lai->primitive_type_vector [ada_primitive_type_float]
     = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch),
-                      "float", NULL);
+                      "float", gdbarch_float_format (gdbarch));
   lai->primitive_type_vector [ada_primitive_type_double]
     = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
-                      "long_float", NULL);
+                      "long_float", gdbarch_double_format (gdbarch));
   lai->primitive_type_vector [ada_primitive_type_long_long]
     = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch),
                         0, "long_long_integer");
   lai->primitive_type_vector [ada_primitive_type_long_double]
-    = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch),
-                      "long_long_float", NULL);
+    = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch),
+                      "long_long_float", gdbarch_long_double_format (gdbarch));
   lai->primitive_type_vector [ada_primitive_type_natural]
     = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
                         0, "natural");
@@ -14031,6 +14093,11 @@ ada_read_var_value (struct symbol *var, const struct block *var_block,
   return default_read_var_value (var, var_block, frame);
 }
 
+static const char *ada_extensions[] =
+{
+  ".adb", ".ads", ".a", ".ada", ".dg", NULL
+};
+
 const struct language_defn ada_language_defn = {
   "ada",                        /* Language name */
   "Ada",
@@ -14040,9 +14107,10 @@ const struct language_defn ada_language_defn = {
                                    that's not quite what this means.  */
   array_row_major,
   macro_expansion_no,
+  ada_extensions,
   &ada_exp_descriptor,
   parse,
-  ada_error,
+  ada_yyerror,
   resolve,
   ada_printchar,                /* Print a character constant */
   ada_printstr,                 /* Function to print string constant */
@@ -14057,6 +14125,7 @@ const struct language_defn ada_language_defn = {
   ada_lookup_symbol_nonlocal,   /* Looking up non-local symbols.  */
   basic_lookup_transparent_type,        /* lookup_transparent_type */
   ada_la_decode,                /* Language specific symbol demangler */
+  ada_sniff_from_mangled_name,
   NULL,                         /* Language specific
                                   class_name_from_physname */
   ada_op_print_tab,             /* expression operators for printing */
This page took 0.028758 seconds and 4 git commands to generate.