From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14859 invoked by alias); 4 Feb 2010 17:38:49 -0000 Received: (qmail 14845 invoked by uid 22791); 4 Feb 2010 17:38:48 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 04 Feb 2010 17:38:43 +0000 Received: from wpaz9.hot.corp.google.com (wpaz9.hot.corp.google.com [172.24.198.73]) by smtp-out.google.com with ESMTP id o14Hcffx015917 for ; Thu, 4 Feb 2010 09:38:41 -0800 Received: from fg-out-1718.google.com (fgae21.prod.google.com [10.86.56.21]) by wpaz9.hot.corp.google.com with ESMTP id o14HcdY0001063 for ; Thu, 4 Feb 2010 09:38:40 -0800 Received: by fg-out-1718.google.com with SMTP id e21so19232fga.16 for ; Thu, 04 Feb 2010 09:38:39 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.89.139 with SMTP id c11mr757488wef.198.1265305119161; Thu, 04 Feb 2010 09:38:39 -0800 (PST) In-Reply-To: References: <20100128215609.GA31654@host0.dyn.jankratochvil.net> <20100129035054.GA26827@adacore.com> Date: Thu, 04 Feb 2010 17:38:00 -0000 Message-ID: Subject: Re: [RFA] Show some tips when file cmd get bfd_error_file_ambiguously_recognized From: Doug Evans To: Hui Zhu 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-System-Of-Record: true 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/msg00124.txt.bz2 On Wed, Feb 3, 2010 at 11:09 PM, Hui Zhu wrote: > Ping. Righto. Sorry! > 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 **mat= ching); >> + >> =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, &match= ing)) >> =A0 =A0 =A0 =A0{ >> =A0 =A0 =A0 =A0 =A0/* Make sure to close exec_bfd, or else "run" might t= ry 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_e= rror ())); >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0scratch_pathname, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0gdb_bfd_errmsg (bfd_get_error (), match= ing)); >> =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-n= ame\" 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 || matchin= g =3D=3D NULL) >> + =A0 =A0return bfd_errmsg (error_tag); >> + >> + =A0ret_len =3D strlen (bfd_errmsg (error_tag)) + strlen (AMBIGUOUS_MES= S1) >> + =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; >> >