Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Hui Zhu <teawater@gmail.com>
To: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: gdb-patches ml <gdb-patches@sourceware.org>,
	Tristan Gingold <gingold@adacore.com>,
	 	Daniel Jacobowitz <dan@codesourcery.com>
Subject: Re: [RFA] Show some tips when file cmd get bfd_error_file_ambiguously_recognized
Date: Tue, 19 Jan 2010 07:01:00 -0000	[thread overview]
Message-ID: <daef60381001182301l6b0297c5pd43b56c64e8f277c@mail.gmail.com> (raw)
In-Reply-To: <20100114101348.GA24756@host0.dyn.jankratochvil.net>

[-- Attachment #1: Type: text/plain, Size: 2464 bytes --]

Thanks Jan.

I make a new patch according to your mail.
And keep the "formats".  Because in before, we use "not in executable
format".  And in other program like nm.c size.c, they all use
"format".  So I think format is better.

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.

On Thu, Jan 14, 2010 at 18:13, Jan Kratochvil <jan.kratochvil@redhat.com> wrote:
> On Thu, 14 Jan 2010 03:43:58 +0100, Hui Zhu wrote:
>>  exec_file_attach (char *filename, int from_tty)
>>  {
>> +  char **matching;
>
> This new variable could be moved to one more inner block.
>
>> +          if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
>> +            {
>> +              char **p = matching;
>
> There is commonly an empty line between declarations and first code line.
>
>> +              fprintf_filtered (gdb_stderr, _("\"%s\":Matching formats:"),
>> +                                scratch_pathname);
>
> Missing space before "Matching formats".
>
> Isn't it "Matching targets" instead?
>
> Anyway I would still prefer to print even bfd_errmsg() for it as it is now IMO
> unclear why "Matching formats" has been printed and that any error occured:
>
>> "/ls":Matching formats: elf32-nbigmips elf32-ntradbigmips
>> Use command "set gnutarget" handle it.
>
>
>> +              while (*p)
>> +                fprintf_filtered (gdb_stderr, " %s", *p++);
>
> (Only a personal preference: for (p = matching; *p != NULL; p++)
>  as this is the most common iterating loop, nothing special to use `while'.)
>
>> +              fprintf_filtered (gdb_stderr, "\n");
>
> (There exists also fputc_filtered.)
>
>> +              free (matching);
>
> Use xfree (see gdbint); despite the memory does not come from xmalloc.
>
>> +              error (_("Use command \"set gnutarget\" handle it."));
>
> Missing "to" - "to handle it"; or just use _("Use command \"...\".").
>
>> +            }
>> +          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
>
> Your patch has been sent with spaces (' ') instead of tabs ('\t') to follow
> the GNU coding style (not using `indent -nut').
>
>
> Regards,
> Jan
>

[-- Attachment #2: tips.txt --]
[-- Type: text/plain, Size: 1736 bytes --]

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

  reply	other threads:[~2010-01-19  7:01 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-14  2:44 Hui Zhu
2010-01-14 10:15 ` Jan Kratochvil
2010-01-19  7:01   ` Hui Zhu [this message]
2010-01-19  7:57     ` Jan Kratochvil
2010-01-19  8:08       ` Hui Zhu
2010-01-26  8:01         ` Hui Zhu
2010-01-26 21:04           ` Doug Evans
2010-01-27  9:01             ` Hui Zhu
2010-01-28 18:18               ` Doug Evans
2010-01-28 21:56               ` Jan Kratochvil
2010-01-28 21:59                 ` Doug Evans
2010-01-29  3:51                   ` Joel Brobecker
2010-01-29  9:06                     ` Hui Zhu
2010-02-04  7:09                       ` Hui Zhu
2010-02-04 17:38                         ` Doug Evans
2010-02-05  2:44                           ` Hui Zhu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=daef60381001182301l6b0297c5pd43b56c64e8f277c@mail.gmail.com \
    --to=teawater@gmail.com \
    --cc=dan@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    --cc=gingold@adacore.com \
    --cc=jan.kratochvil@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox