From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3493 invoked by alias); 5 Feb 2010 02:44:46 -0000 Received: (qmail 3339 invoked by uid 22791); 5 Feb 2010 02:44:45 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail-pz0-f185.google.com (HELO mail-pz0-f185.google.com) (209.85.222.185) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 05 Feb 2010 02:44:39 +0000 Received: by pzk15 with SMTP id 15so3450409pzk.25 for ; Thu, 04 Feb 2010 18:44:37 -0800 (PST) MIME-Version: 1.0 Received: by 10.142.65.14 with SMTP id n14mr1267739wfa.212.1265337877355; Thu, 04 Feb 2010 18:44:37 -0800 (PST) In-Reply-To: References: <20100128215609.GA31654@host0.dyn.jankratochvil.net> <20100129035054.GA26827@adacore.com> From: Hui Zhu Date: Fri, 05 Feb 2010 02:44:00 -0000 Message-ID: Subject: Re: [RFA] Show some tips when file cmd get bfd_error_file_ambiguously_recognized To: Doug Evans Cc: Joel Brobecker , Jan Kratochvil , gdb-patches ml , Tristan Gingold , Daniel Jacobowitz Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-02/txt/msg00155.txt.bz2 Fixed and checked in. Thanks Doug. Best regards, Hui On Fri, Feb 5, 2010 at 01:38, Doug Evans wrote: > On Wed, Feb 3, 2010 at 11:09 PM, Hui Zhu wrote: >> Ping. > > Righto. =A0Sorry! > >> Thanks, >> Hui >> >> On Fri, Jan 29, 2010 at 17:05, Hui Zhu wrote: >>> Thanks guys. =A0I make a new patch according to your mails. >>> >>> And about the xrealloc, I don't know what I was thinking when I use >>> it. =A0It is really bad, ugly and wasted me a lot of time. =A0:( >>> >>> Please help me review the new patch. =A0Thanks. > > 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 =A0Hui Zhu =A0 >>> >>> =A0 =A0 =A0 =A0* defs.h (gdb_bfd_errmsg): New extern. >>> =A0 =A0 =A0 =A0* exec.c (exec_file_attach): Change bfd_errmsg to >>> =A0 =A0 =A0 =A0gdb_bfd_errmsg. >>> =A0 =A0 =A0 =A0* utils.c (AMBIGUOUS_MESS1): New macro. >>> =A0 =A0 =A0 =A0(AMBIGUOUS_MESS2): New macro. >>> =A0 =A0 =A0 =A0(gdb_bfd_errmsg): New function. >>> >>> --- >>> =A0defs.h =A0| =A0 =A08 ++++++++ >>> =A0exec.c =A0| =A0 =A06 ++++-- >>> =A0utils.c | =A0 40 ++++++++++++++++++++++++++++++++++++++++ >>> =A03 files changed, 52 insertions(+), 2 deletions(-) >>> >>> --- a/defs.h >>> +++ b/defs.h >>> @@ -419,6 +419,13 @@ char **gdb_buildargv (const char *); >>> >>> =A0int compare_positive_ints (const void *ap, const void *bp); >>> >>> +/* A wrapper for bfd_errmsg to produce a more helpful error message >>> + =A0 in the case of bfd_error_file_ambiguously recognized. >>> + =A0 MATCHING, if non-NULL, is the corresponding argument to >>> + =A0 bfd_check_format_matches, and will be freed. =A0*/ >>> + >>> +extern const char *gdb_bfd_errmsg (bfd_error_type error_tag, char **ma= tching); >>> + >>> =A0/* From demangle.c */ >>> >>> =A0extern void set_demangling_style (char *); >>> @@ -1226,4 +1233,5 @@ void dummy_obstack_deallocate (void *obj >>> =A0extern void initialize_progspace (void); >>> =A0extern void initialize_inferiors (void); >>> >>> + >>> =A0#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 >>> =A0 =A0 =A0 char *scratch_pathname; >>> =A0 =A0 =A0 int scratch_chan; >>> =A0 =A0 =A0 struct target_section *sections =3D NULL, *sections_end =3D= NULL; >>> + =A0 =A0 =A0char **matching; >>> >>> =A0 =A0 =A0 scratch_chan =3D openp (getenv ("PATH"), OPF_TRY_CWD_FIRST,= filename, >>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 write_files ? O_RDWR | O_BINARY : O= _RDONLY | O_BINARY, >>> @@ -253,13 +254,14 @@ exec_file_attach (char *filename, int fr >>> =A0 =A0 =A0 scratch_pathname =3D xstrdup (scratch_pathname); >>> =A0 =A0 =A0 cleanups =3D make_cleanup (xfree, scratch_pathname); >>> >>> - =A0 =A0 =A0if (!bfd_check_format (exec_bfd, bfd_object)) >>> + =A0 =A0 =A0if (!bfd_check_format_matches (exec_bfd, bfd_object, &matc= hing)) >>> =A0 =A0 =A0 =A0{ >>> =A0 =A0 =A0 =A0 =A0/* Make sure to close exec_bfd, or else "run" might = try to use >>> =A0 =A0 =A0 =A0 =A0 =A0 it. =A0*/ >>> =A0 =A0 =A0 =A0 =A0exec_close (); >>> =A0 =A0 =A0 =A0 =A0error (_("\"%s\": not in executable format: %s"), >>> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0scratch_pathname, bfd_errmsg (bfd_get_= error ())); >>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0scratch_pathname, >>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0gdb_bfd_errmsg (bfd_get_error (), matc= hing)); >>> =A0 =A0 =A0 =A0} >>> >>> =A0 =A0 =A0 /* FIXME - This should only be run for RS6000, but the ifde= f is a poor >>> --- a/utils.c >>> +++ b/utils.c >>> @@ -3608,6 +3608,46 @@ compare_positive_ints (const void *ap, c >>> =A0 return * (int *) ap - * (int *) bp; >>> =A0} >>> >>> +#define AMBIGUOUS_MESS1 =A0 =A0 =A0 =A0".\nMatching formats:" >>> +#define AMBIGUOUS_MESS2 =A0 =A0 =A0 =A0".\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) >>> +{ >>> + =A0char *ret, *retp; >>> + =A0int ret_len; >>> + =A0char **p; >>> + >>> + =A0/* Check if errmsg just need simple return. =A0*/ >>> + =A0if (error_tag !=3D bfd_error_file_ambiguously_recognized || matchi= ng =3D=3D NULL) >>> + =A0 =A0return bfd_errmsg (error_tag); >>> + >>> + =A0ret_len =3D strlen (bfd_errmsg (error_tag)) + strlen (AMBIGUOUS_ME= SS1) >>> + =A0 =A0 =A0 =A0 =A0 =A0+ strlen (AMBIGUOUS_MESS2); >>> + =A0for (p =3D matching; *p; p++) >>> + =A0 =A0ret_len +=3D strlen (*p) + 1; >>> + =A0ret =3D xmalloc (ret_len + 1); >>> + =A0retp =3D ret; >>> + =A0make_cleanup (xfree, ret); >>> + >>> + =A0strcpy (retp, bfd_errmsg (error_tag)); >>> + =A0retp +=3D strlen (retp); >>> + >>> + =A0strcpy (retp, AMBIGUOUS_MESS1); >>> + =A0retp +=3D strlen (retp); >>> + >>> + =A0for (p =3D matching; *p; p++) >>> + =A0 =A0{ >>> + =A0 =A0 =A0sprintf (retp, " %s", *p); >>> + =A0 =A0 =A0retp +=3D strlen (retp); >>> + =A0 =A0} >>> + =A0xfree (matching); >>> + >>> + =A0strcpy (retp, AMBIGUOUS_MESS2); >>> + >>> + =A0return ret; >>> +} >>> + >>> =A0/* Provide a prototype to silence -Wmissing-prototypes. =A0*/ >>> =A0extern initialize_file_ftype _initialize_utils; >>> >> >