[RFA] Show some tips when file cmd get bfd_error_file_ambiguously_recognized

Hui Zhu teawater@gmail.com
Tue Jan 19 08:08:00 GMT 2010


>
>> +           fprintf_filtered (gdb_stderr, _("It matchs formats:"));
>
> "matches"
>

Fixed.

Thanks,
Hui

2010-01-19  Hui Zhu  <teawater@gmail.com>

	* exec.c (exec_file_attach): Output some tips when
	bfd_get_error is bfd_error_file_ambiguously_recognized.
-------------- next part --------------
---
 exec.c |   22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

--- a/exec.c
+++ b/exec.c
@@ -225,6 +225,7 @@ exec_file_attach (char *filename, int fr
       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,
@@ -259,13 +260,28 @@ exec_file_attach (char *filename, int fr
       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 ()));
+
+	  if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
+	    {
+	      char **p;
+
+	      fprintf_filtered (gdb_stderr, _("\"%s\": not in executable format: %s\n"),
+		                scratch_pathname, bfd_errmsg (bfd_get_error ()));
+	      fprintf_filtered (gdb_stderr, _("It matches formats:"));
+	      for (p = matching; *p; p++)
+		fprintf_filtered (gdb_stderr, " %s", *p);
+	      fputc_filtered ('\n', gdb_stderr);
+	      xfree (matching);
+	      error (_("Use command \"set gnutarget format_name\" to handle it."));
+	    }
+	  else
+	    error (_("\"%s\": not in executable format: %s"),
+		   scratch_pathname, bfd_errmsg (bfd_get_error ()));
 	}
 
       /* FIXME - This should only be run for RS6000, but the ifdef is a poor


More information about the Gdb-patches mailing list