From patchwork Mon Apr 13 17:30:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 6185 Received: (qmail 117193 invoked by alias); 13 Apr 2015 17:33:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 117148 invoked by uid 89); 13 Apr 2015 17:33:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-wi0-f172.google.com Received: from mail-wi0-f172.google.com (HELO mail-wi0-f172.google.com) (209.85.212.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 13 Apr 2015 17:33:16 +0000 Received: by wiun10 with SMTP id n10so75567856wiu.1 for ; Mon, 13 Apr 2015 10:33:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=181FWB5n2m8ssMtd+ntVaQpP26g6Y8sO3YvR2/6908k=; b=fsudEEqKbd9YF75SC4mIHgT5LhBPef4loGWiRs8uokppIeZw2saeuc1nUePjKhbtFr S99hT2ALFuMQTxShRhnxGQNWYgYmCwdC53KlWfow6+MWlniltsMmq7eh5L/CP+TOSo6k JJKo8/WRp67qaRcSkCBEwTh2UuwaWW8urN2sk6NzaJJDGaoeau/fgKWMnllvzANYhLUI H2aahsrVTN4g7jDeWApOpyGNqiw46mG9svaBnNxL5luG5y+49wuI4CHaGb8NQfu/cfgt PtnYCs9RWNzuI5sKjnuT7CkdQkZTRLgpzho+T0LRPQQBC/9lA2GuxdwRpacYwJ56nnai 0S2w== X-Gm-Message-State: ALoCoQl4zTYjxW3lyW9lq42Y4Ec0KkTpuslCVQ+GBcO1Vr8dW/KMdsiU5lgwBhalKUWIYBLfjDof X-Received: by 10.194.103.169 with SMTP id fx9mr30291393wjb.148.1428946393709; Mon, 13 Apr 2015 10:33:13 -0700 (PDT) Received: from localhost (host86-133-100-115.range86-133.btcentralplus.com. [86.133.100.115]) by mx.google.com with ESMTPSA id s4sm2813911wix.14.2015.04.13.10.33.12 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Apr 2015 10:33:13 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 3/3] gdb: Add debug tracing for bfd cache activity. Date: Mon, 13 Apr 2015 18:30:09 +0100 Message-Id: <012010337085347ea39a0418076a3937ed8149ba.1428941320.git.andrew.burgess@embecosm.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes This patch adds a new debug flag bfd-cache, which when set to non-zero produces debugging log messages relating to gdb's bfd cache. OK to apply? Thanks, Andrew gdb/ChangeLog: * gdb_bfd.c (debug_bfd_cache): New variable. (gdb_bfd_open): Add debug logging. (gdb_bfd_ref): Likewise. (gdb_bfd_unref): Likewise. (_initialize_gdb_bfd): Add new set/show command. * NEWS: Mention new command. --- gdb/ChangeLog | 9 +++++++++ gdb/NEWS | 4 ++++ gdb/gdb_bfd.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 291c1be..16af460 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,14 @@ 2015-04-13 Andrew Burgess + * gdb_bfd.c (debug_bfd_cache): New variable. + (gdb_bfd_open): Add debug logging. + (gdb_bfd_ref): Likewise. + (gdb_bfd_unref): Likewise. + (_initialize_gdb_bfd): Add new set/show command. + * NEWS: Mention new command. + +2015-04-13 Andrew Burgess + * gdb_bfd.c (bfd_sharing): New variable. (gdb_bfd_open): Check bfd_sharing variable. (_initialize_gdb_bfd): Add new set/show command. diff --git a/gdb/NEWS b/gdb/NEWS index 673aca4..07017ec 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -55,6 +55,10 @@ record bts * New options +set debug bfd-cache +show debug bfd-cache + Control display of debugging info regarding bfd caching. + set max-completions show max-completions Set the maximum number of candidates to be considered during diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 48838cc..ba4f74f 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -109,6 +109,10 @@ static htab_t gdb_bfd_cache; static int bfd_sharing; +/* When non-zero debugging of the bfd caches is enabled. */ + +static unsigned int debug_bfd_cache; + /* The type of an object being looked up in gdb_bfd_cache. We use htab's capability of storing one kind of object (BFD in this case) and using a different sort of object for searching. */ @@ -396,6 +400,11 @@ gdb_bfd_open (const char *name, const char *target, int fd) abfd = htab_find_with_hash (gdb_bfd_cache, &search, hash); if (bfd_sharing && abfd != NULL) { + if (debug_bfd_cache) + fprintf_unfiltered (gdb_stdlog, + "Reusing cached bfd %s for %s\n", + host_address_to_string (abfd), + bfd_get_filename (abfd)); close (fd); gdb_bfd_ref (abfd); return abfd; @@ -405,6 +414,12 @@ gdb_bfd_open (const char *name, const char *target, int fd) if (abfd == NULL) return NULL; + if (debug_bfd_cache) + fprintf_unfiltered (gdb_stdlog, + "Creating new bfd %s for %s\n", + host_address_to_string (abfd), + bfd_get_filename (abfd)); + if (bfd_sharing) { slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, INSERT); @@ -472,6 +487,12 @@ gdb_bfd_ref (struct bfd *abfd) gdata = bfd_usrdata (abfd); + if (debug_bfd_cache) + fprintf_unfiltered (gdb_stdlog, + "Increase reference count on bfd %s (%s)\n", + host_address_to_string (abfd), + bfd_get_filename (abfd)); + if (gdata != NULL) { gdata->refc += 1; @@ -514,7 +535,20 @@ gdb_bfd_unref (struct bfd *abfd) gdata->refc -= 1; if (gdata->refc > 0) - return; + { + if (debug_bfd_cache) + fprintf_unfiltered (gdb_stdlog, + "Decrease reference count on bfd %s (%s)\n", + host_address_to_string (abfd), + bfd_get_filename (abfd)); + return; + } + + if (debug_bfd_cache) + fprintf_unfiltered (gdb_stdlog, + "Delete final reference count on bfd %s (%s)\n", + host_address_to_string (abfd), + bfd_get_filename (abfd)); archive_bfd = gdata->archive_bfd; search.filename = bfd_get_filename (abfd); @@ -944,4 +978,13 @@ disc has changed."), &maintenance_set_cmdlist, &maintenance_show_cmdlist); bfd_sharing = 1; + + add_setshow_zuinteger_cmd ("bfd-cache", class_maintenance, + &debug_bfd_cache, _("\ +Set bfd cache debugging."), _("\ +Show bfd cache debugging."), _("\ +When non-zero, bfd cache specific debugging is enabled."), + NULL, + NULL, + &setdebuglist, &showdebuglist); }