From patchwork Thu Aug 13 12:45:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 8182 Received: (qmail 110885 invoked by alias); 13 Aug 2015 12:45: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 110786 invoked by uid 89); 13 Aug 2015 12:45:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.1 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-f180.google.com Received: from mail-wi0-f180.google.com (HELO mail-wi0-f180.google.com) (209.85.212.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 13 Aug 2015 12:45:12 +0000 Received: by wibhh20 with SMTP id hh20so72453726wib.0 for ; Thu, 13 Aug 2015 05:45:09 -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=a91KFRhgKq52Pea+9h2rAlSuV9B2vbyGp5Y/Xdbd4Kg=; b=GM4UkV3yB9Y4Q7OJjRo/UEpanObiPS6kEKWkbmDFASicAJavp5m+/UlvsB5k48R/b4 CM950fe4w1iyiRw4FbaKdYH/FNNvlrM8Tn8VSZV1HkD5yn2WlYJJcXL+hc42bBS1tZkh /YoLAqynPcT5lpqqm3E8hm9Raj0KlKHBAxOIyIC6n44v6PBhg6bF4x2UWaShRhsNtNpI Lifp9676fIue5jOuZESF57ZpfvJ0qVzpBeIPFDrBURqObCRdEB5vAZMrjJ1/DTMIuxvC 2X9KY7lL19goQthXe6KxDG+zOo+naJgHOsaicBmCD6jsFu3GntZ2dRwc24E3vEMDvhkL OpyQ== X-Gm-Message-State: ALoCoQl8SiGh7NYBV5HLkO1fZ3/uPXzSNqGYB08uU08gCVK/06eRrRnoKOXkfQ2yzCnGzhSAdvWD X-Received: by 10.180.219.101 with SMTP id pn5mr54713722wic.89.1439469909060; Thu, 13 Aug 2015 05:45:09 -0700 (PDT) Received: from localhost (cust64-dsl91-135-5.idnet.net. [91.135.5.64]) by smtp.gmail.com with ESMTPSA id hn2sm3205100wjc.45.2015.08.13.05.45.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Aug 2015 05:45:08 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH v2 3/3] gdb: Add debug tracing for bfd cache activity. Date: Thu, 13 Aug 2015 13:45:00 +0100 Message-Id: <20978b0a40cbc4fd2a82039f2a36463cb7c6cb83.1439454670.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. 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/doc/ChngeLog: * gdb.texinfo (File Caching): Document "set/show debug bfd-cache". --- gdb/ChangeLog | 9 +++++++++ gdb/NEWS | 4 ++++ gdb/doc/ChangeLog | 4 ++++ gdb/doc/gdb.texinfo | 10 ++++++++++ gdb/gdb_bfd.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 71 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0f73f08..3ef6d0e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,14 @@ 2015-08-11 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-08-11 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 87fc14e..2451ac3 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -20,6 +20,10 @@ maint set bfd-sharing maint show bfd-sharing Control the reuse of bfd objects. +set debug bfd-cache +show debug bfd-cache + Control display of debugging info regarding bfd caching. + *** Changes in GDB 7.10 * Support for process record-replay and reverse debugging on aarch64*-linux* diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 9d553db..2fe1dd9 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,5 +1,9 @@ 2015-08-11 Andrew Burgess + * gdb.texinfo (File Caching): Document "set/show debug bfd-cache". + +2015-08-11 Andrew Burgess + * gdb.texinfo (Maintenance Commands): Move documentation of "main info bfds" to... (File Caching): A New section. Outline bfd caching, and add new diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 3cfb1a7..0a7ced4 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -18218,6 +18218,16 @@ already shared @code{bfd} objects to be unshared, but all future files that are opened will create a new @code{bfd} object. Similarly, re-enabling sharing will not cause multiple existing @code{bfd} objects to be collapsed into a single shared @code{bfd} object. + +@kindex set debug bfd-cache @var{level} +@kindex bfd caching +@item set debug bfd-cache @var{level} +Turns on debugging of the bfd cache, setting the level to @var{level}. + +@kindex show debug bfd-cache +@kindex bfd caching +@item show debug bfd-cache +Show the current debugging level of the bfd cache. @end table @node Separate Debug Files diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 14fdf43..e252999 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -116,6 +116,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. */ @@ -401,6 +405,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; @@ -410,6 +419,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); @@ -478,6 +493,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; @@ -531,7 +552,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); @@ -963,4 +997,13 @@ filename, file size, file modification time, and file inode."), &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); }