From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29269 invoked by alias); 19 Jul 2012 20:58:18 -0000 Received: (qmail 29257 invoked by uid 22791); 19 Jul 2012 20:58:17 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,SPF_HELO_PASS,TW_BJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 19 Jul 2012 20:58:04 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6JKw4ai025895 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 19 Jul 2012 16:58:04 -0400 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q6JKw3w3032588 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 19 Jul 2012 16:58:03 -0400 From: Tom Tromey To: Jan Kratochvil Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 01/10] change gdb to refcount bfd everywhere References: <87vchk3lxs.fsf@fleche.redhat.com> <20120719141750.GB23801@host2.jankratochvil.net> Date: Thu, 19 Jul 2012 20:58:00 -0000 In-Reply-To: <20120719141750.GB23801@host2.jankratochvil.net> (Jan Kratochvil's message of "Thu, 19 Jul 2012 16:17:50 +0200") Message-ID: <877gtzxyck.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain 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: 2012-07/txt/msg00377.txt.bz2 >>>>> "Jan" == Jan Kratochvil writes: Jan> The comments are present in both and neither is a reference, they Jan> are already out of sync. I don't really follow, but I also don't mind changing the comments -- they ought to be clear for everybody, not just me. How about this? /* Increment the reference count of ABFD. It is fine for ABFD to be NULL; in this case the function does nothing. */ void gdb_bfd_ref (struct bfd *abfd); /* Decrement the reference count of ABFD. If this is the last reference, ABFD will be freed. If ABFD is NULL, this function does nothing. */ void gdb_bfd_unref (struct bfd *abfd); Jan> I personally disagree about the returned value from gdb_bfd_ref Jan> being useful, it makes the code more magic IMO (plus it is not much Jan> compatible with the narrow GNU Coding Standard code formatting). I made this change. I'll test the patch and send it tomorrow. Then I went a bit further and wrote a follow-up patch that wraps the various BFD-opening functions with gdb equivalents. These initialize the refcount and stash the filename. E.g.: /* A wrapper for bfd_fopen that initializes the gdb-specific reference count and calls gdb_bfd_stash_filename. */ bfd *gdb_bfd_fopen (const char *, const char *, const char *, int); I'll send this patch separately tomorrow. I'm curious to know what you think. I find it cleans up the code quite a bit, I wish I'd done this from the beginning. >> @@ -193,9 +194,9 @@ allocate_objfile (bfd *abfd, int flags) [...] >> - objfile->obfd = gdb_bfd_ref (abfd); >> + objfile->obfd = abfd; Jan> Caller could gdb_bfd_unref its reference but YMMV. I will look into this tomorrow. Jan> This all pain would not exist with C++. Yeah, well... >> @@ -2519,14 +2512,10 @@ reread_symbols (void) >> to close the descriptor but BFD lacks a way of closing the >> BFD without closing the descriptor. */ >> obfd_filename = bfd_get_filename (objfile->obfd); >> - if (!bfd_close (objfile->obfd)) >> - error (_("Can't close BFD for %s: %s"), objfile->name, >> - bfd_errmsg (bfd_get_error ())); >> + gdb_bfd_unref (objfile->obfd); >> objfile-> obfd = bfd_open_maybe_remote (obfd_filename); >> if (objfile->obfd == NULL) >> error (_("Can't open %s to read symbols."), objfile->name); >> - else >> - objfile->obfd = gdb_bfd_ref (objfile->obfd); Jan> Why isn't gdb_bfd_ref missing here? bfd_open_maybe_remote returns a new reference. I wonder if I should rename it to gdb_bfd_open_maybe_remote, for consistency. What do you think? I'm inclined to do it. Tom