2010-02-05 Hui Zhu <teawater@gmail.com>
authorHui Zhu <teawater@gmail.com>
Fri, 5 Feb 2010 02:22:39 +0000 (02:22 +0000)
committerHui Zhu <teawater@gmail.com>
Fri, 5 Feb 2010 02:22:39 +0000 (02:22 +0000)
* defs.h (gdb_bfd_errmsg): New extern.
* exec.c (exec_file_attach): Change bfd_errmsg to
gdb_bfd_errmsg.
* utils.c (AMBIGUOUS_MESS1): New macro.
(AMBIGUOUS_MESS2): New macro.
(gdb_bfd_errmsg): New function.

gdb/ChangeLog
gdb/defs.h
gdb/exec.c
gdb/utils.c

index 4fda810a805b4c3fe22ec5fb8bfedd6ef40d2cc6..d3170ccad0adc7b55e6eb5127e108513eeaa1573 100644 (file)
@@ -1,3 +1,12 @@
+2010-02-05  Hui Zhu  <teawater@gmail.com>
+
+       * defs.h (gdb_bfd_errmsg): New extern.
+       * exec.c (exec_file_attach): Change bfd_errmsg to
+       gdb_bfd_errmsg.
+       * utils.c (AMBIGUOUS_MESS1): New macro.
+       (AMBIGUOUS_MESS2): New macro.
+       (gdb_bfd_errmsg): New function.
+
 2010-02-04  Doug Evans  <dje@google.com>
 
        * solib-svr4.c (enable_break): Add comment.
index 5b5c261604bfcb3625b0001158ef71cb615aeb00..770d1719428e38f6cd068579ada211e69ecceb54 100644 (file)
@@ -419,6 +419,13 @@ char **gdb_buildargv (const char *);
 
 int compare_positive_ints (const void *ap, const void *bp);
 
+/* A wrapper for bfd_errmsg to produce a more helpful error message
+   in the case of bfd_error_file_ambiguously recognized.
+   MATCHING, if non-NULL, is the corresponding argument to
+   bfd_check_format_matches, and will be freed.  */
+
+extern const char *gdb_bfd_errmsg (bfd_error_type error_tag, char **matching);
+
 /* From demangle.c */
 
 extern void set_demangling_style (char *);
index 4ced96851b16696aaeaa20e0383886ff4f5e2049..51b33a5512a1bd2ca353f04fe6992184530ec618 100644 (file)
@@ -219,6 +219,7 @@ exec_file_attach (char *filename, int from_tty)
       char *scratch_pathname;
       int scratch_chan;
       struct target_section *sections = NULL, *sections_end = NULL;
+      char **matching;
 
       scratch_chan = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, filename,
                   write_files ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY,
@@ -253,13 +254,14 @@ exec_file_attach (char *filename, int from_tty)
       scratch_pathname = xstrdup (scratch_pathname);
       cleanups = make_cleanup (xfree, scratch_pathname);
 
-      if (!bfd_check_format (exec_bfd, bfd_object))
+      if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
        {
          /* Make sure to close exec_bfd, or else "run" might try to use
             it.  */
          exec_close ();
          error (_("\"%s\": not in executable format: %s"),
-                scratch_pathname, bfd_errmsg (bfd_get_error ()));
+                scratch_pathname,
+                gdb_bfd_errmsg (bfd_get_error (), matching));
        }
 
       /* FIXME - This should only be run for RS6000, but the ifdef is a poor
index 82a66a10020ef4a46c62c6a76ad28caf9f758a51..33c195a41dcebc22dd71e2b343a582b3a25a2351 100644 (file)
@@ -3608,6 +3608,46 @@ compare_positive_ints (const void *ap, const void *bp)
   return * (int *) ap - * (int *) bp;
 }
 
+#define AMBIGUOUS_MESS1        ".\nMatching formats:"
+#define AMBIGUOUS_MESS2        ".\nUse \"set gnutarget format-name\" to specify the format."
+
+const char *
+gdb_bfd_errmsg (bfd_error_type error_tag, char **matching)
+{
+  char *ret, *retp;
+  int ret_len;
+  char **p;
+
+  /* Check if errmsg just need simple return.  */
+  if (error_tag != bfd_error_file_ambiguously_recognized || matching == NULL)
+    return bfd_errmsg (error_tag);
+
+  ret_len = strlen (bfd_errmsg (error_tag)) + strlen (AMBIGUOUS_MESS1)
+            + strlen (AMBIGUOUS_MESS2);
+  for (p = matching; *p; p++)
+    ret_len += strlen (*p) + 1;
+  ret = xmalloc (ret_len + 1);
+  retp = ret;
+  make_cleanup (xfree, ret);
+
+  strcpy (retp, bfd_errmsg (error_tag));
+  retp += strlen (retp);
+
+  strcpy (retp, AMBIGUOUS_MESS1);
+  retp += strlen (retp);
+
+  for (p = matching; *p; p++)
+    {
+      sprintf (retp, " %s", *p);
+      retp += strlen (retp);
+    }
+  xfree (matching);
+
+  strcpy (retp, AMBIGUOUS_MESS2);
+
+  return ret;
+}
+
 /* Provide a prototype to silence -Wmissing-prototypes.  */
 extern initialize_file_ftype _initialize_utils;
 
This page took 0.037067 seconds and 4 git commands to generate.