From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 72898 invoked by alias); 1 Apr 2015 12:13:18 -0000 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 Received: (qmail 72851 invoked by uid 89); 1 Apr 2015 12:13:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 01 Apr 2015 12:13:17 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 4B64CBBF46 for ; Wed, 1 Apr 2015 12:13:16 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t31CDELG026621; Wed, 1 Apr 2015 08:13:15 -0400 Message-ID: <551BE0D9.9000902@redhat.com> Date: Wed, 01 Apr 2015 12:13:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Gary Benson , gdb-patches@sourceware.org Subject: Re: [PATCH 5/9] Rearrange symfile_bfd_open References: <1426870087-32654-1-git-send-email-gbenson@redhat.com> <1426870087-32654-6-git-send-email-gbenson@redhat.com> In-Reply-To: <1426870087-32654-6-git-send-email-gbenson@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2015-04/txt/msg00028.txt.bz2 On 03/20/2015 04:48 PM, Gary Benson wrote: > symfile_bfd_open handles what were remote files as a special case. > Now that remote files are replaced with target the reverse is true > and the BFD opening, format checking and error printing code is > essentially duplicated. This commit rearranges symfile_bfd_open > to treat local files as a special case, removing the duplication. Where were they already done? Can you add a comment? > > gdb/ChangeLog: > > * symfile.c (symfile_bfd_open): Reorder to remove duplicated > checks and error messages. > --- > gdb/ChangeLog | 5 ++++ > gdb/symfile.c | 69 ++++++++++++++++++++++++-------------------------------- > 2 files changed, 35 insertions(+), 39 deletions(-) > > diff --git a/gdb/symfile.c b/gdb/symfile.c > index 0d8dae7..0c35ffa 100644 > --- a/gdb/symfile.c > +++ b/gdb/symfile.c > @@ -1718,60 +1718,51 @@ set_initial_language (void) > absolute). In case of trouble, error() is called. */ > > bfd * > -symfile_bfd_open (const char *cname) > +symfile_bfd_open (const char *name) > { > bfd *sym_bfd; > - int desc; > - char *name, *absolute_name; > - struct cleanup *back_to; > + int desc = -1; > + struct cleanup *back_to = make_cleanup (null_cleanup, 0); > > - if (is_target_filename (cname)) > + if (!is_target_filename (name)) > { > - sym_bfd = gdb_bfd_open (cname, gnutarget, -1); > - if (!sym_bfd) > - error (_("`%s': can't open to read symbols: %s."), cname, > - bfd_errmsg (bfd_get_error ())); > - > - if (!bfd_check_format (sym_bfd, bfd_object)) > - { > - make_cleanup_bfd_unref (sym_bfd); > - error (_("`%s': can't read symbols: %s."), cname, > - bfd_errmsg (bfd_get_error ())); > - } > + char *expanded_name, *absolute_name; > > - return sym_bfd; > - } > - > - name = tilde_expand (cname); /* Returns 1st new malloc'd copy. */ > + expanded_name = tilde_expand (name); /* Returns 1st new malloc'd copy. */ > > - /* Look down path for it, allocate 2nd new malloc'd copy. */ > - desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, name, > - O_RDONLY | O_BINARY, &absolute_name); > + /* Look down path for it, allocate 2nd new malloc'd copy. */ > + desc = openp (getenv ("PATH"), > + OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, > + expanded_name, O_RDONLY | O_BINARY, &absolute_name); > #if defined(__GO32__) || defined(_WIN32) || defined (__CYGWIN__) > - if (desc < 0) > - { > - char *exename = alloca (strlen (name) + 5); > + if (desc < 0) > + { > + char *exename = alloca (strlen (expanded_name) + 5); > > - strcat (strcpy (exename, name), ".exe"); > - desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, > - exename, O_RDONLY | O_BINARY, &absolute_name); > - } > + strcat (strcpy (exename, expanded_name), ".exe"); > + desc = openp (getenv ("PATH"), > + OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, > + exename, O_RDONLY | O_BINARY, &absolute_name); > + } > #endif > - if (desc < 0) > - { > - make_cleanup (xfree, name); > - perror_with_name (name); > - } > + if (desc < 0) > + { > + make_cleanup (xfree, expanded_name); > + perror_with_name (expanded_name); > + } > > - xfree (name); > - name = absolute_name; > - back_to = make_cleanup (xfree, name); > + xfree (expanded_name); > + make_cleanup (xfree, absolute_name); > + name = absolute_name; > + } > > sym_bfd = gdb_bfd_open (name, gnutarget, desc); > if (!sym_bfd) > error (_("`%s': can't open to read symbols: %s."), name, > bfd_errmsg (bfd_get_error ())); > - bfd_set_cacheable (sym_bfd, 1); > + > + if (!gdb_bfd_has_target_filename (sym_bfd)) > + bfd_set_cacheable (sym_bfd, 1); > > if (!bfd_check_format (sym_bfd, bfd_object)) > { > Thanks, Pedro Alves