--- 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 matchs 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