This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA] Auto set gnutarget when bfd_check_format_matches get bfd_error_file_ambiguously_recognized
- From: Hui Zhu <teawater at gmail dot com>
- To: gdb-patches ml <gdb-patches at sourceware dot org>
- Date: Wed, 30 Jun 2010 16:49:59 +0800
- Subject: [RFA] Auto set gnutarget when bfd_check_format_matches get bfd_error_file_ambiguously_recognized
Hello,
In sometime before, I add a patch to make GDB show some help message
when bfd_check_format_matches get
bfd_error_file_ambiguously_recognized, like:
"/home/teawater/Desktop/vmlinux": not in executable format: File
format is ambiguous.
Matching formats: elf64-bigmips elf64-tradbigmips.
Use "set gnutarget format-name" to specify the format.
But to really open this file, user need set gnutarget elf64-bigmips
and file /home/teawater/Desktop/vmlinux.
So I add a patch to auto do it. Like:
warning: "/home/teawater/Desktop/vmlinux": not in executable format:
File format is ambiguous.
Matching formats: elf64-bigmips elf64-tradbigmips.
Use "set gnutarget format-name" to specify the format.
warning: Auto set it to "elf64-bigmips".
Reading symbols from /home/teawater/Desktop/vmlinux...done.
Please help me review it.
Thanks,
Hui
2010-06-30 Hui Zhu <teawater@gmail.com>
* exec.c (exec_file_attach): Add code to handle
bfd_error_file_ambiguously_recognized.
---
exec.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
--- a/exec.c
+++ b/exec.c
@@ -217,6 +217,7 @@ exec_file_attach (char *filename, int fr
struct target_section *sections = NULL, *sections_end = NULL;
char **matching;
+retry:
scratch_chan = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, filename,
write_files ? O_RDWR | O_BINARY : O_RDONLY | O_BINARY,
&scratch_pathname);
@@ -253,12 +254,27 @@ exec_file_attach (char *filename, int fr
if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
{
+ bfd_error_type error_tag = bfd_get_error ();
+
/* 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,
- gdb_bfd_errmsg (bfd_get_error (), matching));
+
+ if (error_tag != bfd_error_file_ambiguously_recognized
+ || matching == NULL)
+ error (_("\"%s\": not in executable format: %s"),
+ scratch_pathname,
+ gdb_bfd_errmsg (error_tag, matching));
+ else
+ {
+ set_gnutarget (*matching);
+ warning (_("\"%s\": not in executable format: %s"),
+ scratch_pathname,
+ gdb_bfd_errmsg (error_tag, matching));
+ warning (_("Auto set it to \"%s\"."), gnutarget);
+ do_cleanups (cleanups);
+ goto retry;
+ }
}
/* FIXME - This should only be run for RS6000, but the ifdef is a poor