From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25631 invoked by alias); 4 Feb 2010 07:09:49 -0000 Received: (qmail 25622 invoked by uid 22791); 4 Feb 2010 07:09:48 -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-iw0-f198.google.com (HELO mail-iw0-f198.google.com) (209.85.223.198) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 04 Feb 2010 07:09:43 +0000 Received: by mail-iw0-f198.google.com with SMTP id 36so2433661iwn.3 for ; Wed, 03 Feb 2010 23:09:43 -0800 (PST) MIME-Version: 1.0 Received: by 10.231.145.74 with SMTP id c10mr1269774ibv.51.1265267383094; Wed, 03 Feb 2010 23:09:43 -0800 (PST) In-Reply-To: References: <20100119075642.GA30154@host0.dyn.jankratochvil.net> <20100128215609.GA31654@host0.dyn.jankratochvil.net> <20100129035054.GA26827@adacore.com> From: Hui Zhu Date: Thu, 04 Feb 2010 07:09:00 -0000 Message-ID: Subject: Re: [RFA] Show some tips when file cmd get bfd_error_file_ambiguously_recognized To: Joel Brobecker , Doug Evans , Jan Kratochvil Cc: 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/msg00106.txt.bz2 Ping. 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. > > 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 **matc= hing); > + > =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 */ > --- 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 N= ULL; > + =A0 =A0 =A0char **matching; > > =A0 =A0 =A0 scratch_chan =3D openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, f= ilename, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 write_files ? O_RDWR | O_BINARY : O_R= DONLY | 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, &matchi= ng)) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0/* Make sure to close exec_bfd, or else "run" might tr= y 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_er= ror ())); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0scratch_pathname, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0gdb_bfd_errmsg (bfd_get_error (), matchi= ng)); > =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 /* 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 > =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-na= me\" specify > the format." > + > +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 || matching= =3D=3D NULL) > + =A0 =A0return bfd_errmsg (error_tag); > + > + =A0ret_len =3D strlen (bfd_errmsg (error_tag)) + strlen (AMBIGUOUS_MESS= 1) > + =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; >