This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA] Show some tips when file cmd get bfd_error_file_ambiguously_recognized
- From: Doug Evans <dje at google dot com>
- To: Hui Zhu <teawater at gmail dot com>
- Cc: Joel Brobecker <brobecker at adacore dot com>, Jan Kratochvil <jan dot kratochvil at redhat dot com>, gdb-patches ml <gdb-patches at sourceware dot org>, Tristan Gingold <gingold at adacore dot com>, Daniel Jacobowitz <dan at codesourcery dot com>
- Date: Thu, 4 Feb 2010 09:38:38 -0800
- Subject: Re: [RFA] Show some tips when file cmd get bfd_error_file_ambiguously_recognized
- References: <daef60381001131843u683d35d2nf937db926cea9740@mail.gmail.com> <daef60381001190008x3e2964d2h6439db9293e3b3e6@mail.gmail.com> <daef60381001260001j7dfb4c09jdace41e666a1b0a1@mail.gmail.com> <e394668d1001261304o3c723d7apf18891c83da0eaf3@mail.gmail.com> <daef60381001270100w65b4fd08na227041c3e78c686@mail.gmail.com> <20100128215609.GA31654@host0.dyn.jankratochvil.net> <e394668d1001281359y7b01c13fj551da6e06b249678@mail.gmail.com> <20100129035054.GA26827@adacore.com> <daef60381001290105w33f7bf8er9a3578fbd9489b7b@mail.gmail.com> <daef60381002032309w578c3346yb47d6ab118bcd429@mail.gmail.com>
On Wed, Feb 3, 2010 at 11:09 PM, Hui Zhu <teawater@gmail.com> wrote:
> Ping.
Righto. Sorry!
> Thanks,
> Hui
>
> On Fri, Jan 29, 2010 at 17:05, Hui Zhu <teawater@gmail.com> wrote:
>> Thanks guys. ?I make a new patch according to your mails.
>>
>> And about the xrealloc, I don't know what I was thinking when I use
>> it. ?It is really bad, ugly and wasted me a lot of time. ?:(
>>
>> Please help me review the new patch. ?Thanks.
The patch is fine with me with two nits noted below.
No need to resubmit, you can just check it in with the requested changes.
>>
>> Best regards,
>> Hui
>>
>> 2010-01-29 ?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.
>>
>> ---
>> ?defs.h ?| ? ?8 ++++++++
>> ?exec.c ?| ? ?6 ++++--
>> ?utils.c | ? 40 ++++++++++++++++++++++++++++++++++++++++
>> ?3 files changed, 52 insertions(+), 2 deletions(-)
>>
>> --- a/defs.h
>> +++ b/defs.h
>> @@ -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 *);
>> @@ -1226,4 +1233,5 @@ void dummy_obstack_deallocate (void *obj
>> ?extern void initialize_progspace (void);
>> ?extern void initialize_inferiors (void);
>>
>> +
>> ?#endif /* #ifndef DEFS_H */
(1) Please remove the added blank line.
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -219,6 +219,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,
>> @@ -253,13 +254,14 @@ 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 ()));
>> + ? ? ? ? ? ? ? ?scratch_pathname,
>> + ? ? ? ? ? ? ? ?gdb_bfd_errmsg (bfd_get_error (), matching));
>> ? ? ? ?}
>>
>> ? ? ? /* FIXME - This should only be run for RS6000, but the ifdef is a poor
>> --- a/utils.c
>> +++ b/utils.c
>> @@ -3608,6 +3608,46 @@ compare_positive_ints (const void *ap, c
>> ? return * (int *) ap - * (int *) bp;
>> ?}
>>
>> +#define AMBIGUOUS_MESS1 ? ? ? ?".\nMatching formats:"
>> +#define AMBIGUOUS_MESS2 ? ? ? ?".\nUse \"set gnutarget format-name\" specify the format."
(2) Grammar nit.
s,format-name\" specify,format-name\" to specify,
[insert "to" before "specify"]
>> +
>> +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;
>>
>