From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 109339 invoked by alias); 13 Aug 2015 12:45:15 -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 109240 invoked by uid 89); 13 Aug 2015 12:45:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=AWL,BAYES_20,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-wi0-f181.google.com Received: from mail-wi0-f181.google.com (HELO mail-wi0-f181.google.com) (209.85.212.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 13 Aug 2015 12:45:10 +0000 Received: by wijp15 with SMTP id p15so257131208wij.0 for ; Thu, 13 Aug 2015 05:45:07 -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=NbnVTCahxpHNZTqJooxeE+Z0fUAN7Q4pMziq3b49TJk=; b=fbYNuFewYffnWdR1BqmVPwirJHFRZOBztrJu7xA84ee5inG8r4Ca3binu1x9Sggtw7 38kihy2jKNjpgEzyszKoDN+tGjgRCN3n7NJEPhXs4fvQQ2gmLERteaxuJMqD7bWxNPSz cNA3wqrysCQo73ZugvjedqbTrvt/E9B/l4J0MzQQNkjuUXqJRFz5nUUJYEVpWcCG4Xf3 SRwBuzn/jqWS5BsqGpYrKfRsBQnwQokTOtxFBwjlXt4YI+BifESoJRsHUmVszc3cUF9d xEGLyz5daZeb03CWNRU7Vt3FoTSfO9dcUNSUy75zWc1G+ix/5KmJZxrXzA6obqvYs5qd +BPg== X-Gm-Message-State: ALoCoQlON54tNI8Z5/HWpr53vFZOq4QlO8GWk4COQkNFx4J13P0t5VKyPxp5WAId7PrgTQrHB3d6 X-Received: by 10.180.218.227 with SMTP id pj3mr6160778wic.59.1439469907589; Thu, 13 Aug 2015 05:45:07 -0700 (PDT) Received: from localhost (cust64-dsl91-135-5.idnet.net. [91.135.5.64]) by smtp.gmail.com with ESMTPSA id fz16sm3254939wic.3.2015.08.13.05.45.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Aug 2015 05:45:07 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH v2 2/3] gdb: New maintenance command to disable bfd sharing. Date: Thu, 13 Aug 2015 12:45:00 -0000 Message-Id: <77dce5f054bd1f7be0f87fe36c5d7e4acdef7c9b.1439454670.git.andrew.burgess@embecosm.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes X-SW-Source: 2015-08/txt/msg00343.txt.bz2 In some rare maintainer cases it is desirable to be able to disable bfd sharing. This patch adds new commands maintenance set/show commands for bfd-sharing, allowing gdb's bfd cache to be turned off. gdb/ChangeLog: * gdb_bfd.c (bfd_sharing): New variable. (gdb_bfd_open): Check bfd_sharing variable. (_initialize_gdb_bfd): Add new set/show command. * NEWS: Mention new command. gdb/doc/ChangeLog: * gdb.texinfo (Maintenance Commands): Move documentation of "main info bfds" to... (File Caching): A New section. Outline bfd caching, and add new description for "main set/show bfd-sharing". --- gdb/ChangeLog | 7 +++++++ gdb/NEWS | 4 ++++ gdb/doc/ChangeLog | 7 +++++++ gdb/doc/gdb.texinfo | 35 ++++++++++++++++++++++++++++++----- gdb/gdb_bfd.c | 29 +++++++++++++++++++++++++---- 5 files changed, 73 insertions(+), 9 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d920ea0..0f73f08 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 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. + * NEWS: Mention new command. + +2015-08-11 Andrew Burgess + * gdb_bfd.c (struct gdb_bfd_data): Add size, inode, and device id field. (struct gdb_bfd_cache_search): Likewise. diff --git a/gdb/NEWS b/gdb/NEWS index 3fe6036..87fc14e 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -16,6 +16,10 @@ maint show target-non-stop "set non-stop" is "off". The default is "auto", meaning non-stop mode is enabled if supported by the target. +maint set bfd-sharing +maint show bfd-sharing + Control the reuse of bfd objects. + *** 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 846ac24..9d553db 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,10 @@ +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 + description for "main set/show bfd-sharing". + 2015-08-07 Pedro Alves * gdb.texinfo (Maintenance Commands): Document "maint set/show diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 900970b..3cfb1a7 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -18190,6 +18190,36 @@ Set whether a source file may have multiple base names. Show whether a source file may have multiple base names. @end table +@node File Caching +@section File Caching +@cindex caching of opened files +@cindex caching of bfd objects + +To speed up file loading, and reduce memory usage, @value{GDBN} will +reuse the @code{bfd} objects used to track open files. @xref{Top, , +BFD, bfd, The Binary File Descriptor Library}. The following commands +allow visibility and control of the caching beaviour. + +@table @code +@kindex maint info bfds +@item maint info bfds +This prints information about each @code{bfd} object that is known to +@value{GDBN}. + +@kindex maint set bfd-sharing +@kindex maint show bfd-sharing +@kindex bfd caching +@item maint set bfd-sharing +@item maint show bfd-sharing +Control whether @code{bfd} objects can be shared. When sharing is +enabled @value{GDBN} will reuse already open @code{bfd} objects rather +than reopening the same file. Turning sharing off does not cause +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. +@end table + @node Separate Debug Files @section Debugging Information in Separate Files @cindex separate debugging information files @@ -33987,11 +34017,6 @@ Shared library events. @end table -@kindex maint info bfds -@item maint info bfds -This prints information about each @code{bfd} object that is known to -@value{GDBN}. @xref{Top, , BFD, bfd, The Binary File Descriptor Library}. - @kindex maint info btrace @item maint info btrace Pint information about raw branch tracing data. diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index ee29531..14fdf43 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -111,6 +111,11 @@ DEFINE_REGISTRY (bfd, GDB_BFD_DATA_ACCESSOR) static htab_t gdb_bfd_cache; +/* When true gdb will reuse an existing bfd object if the filename, + modification time, and file size all match. */ + +static int bfd_sharing; + /* 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. */ @@ -394,7 +399,7 @@ gdb_bfd_open (const char *name, const char *target, int fd) opening the BFD may fail; and this would violate hashtab invariants. */ abfd = htab_find_with_hash (gdb_bfd_cache, &search, hash); - if (abfd != NULL) + if (bfd_sharing && abfd != NULL) { close (fd); gdb_bfd_ref (abfd); @@ -405,9 +410,12 @@ gdb_bfd_open (const char *name, const char *target, int fd) if (abfd == NULL) return NULL; - slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, INSERT); - gdb_assert (!*slot); - *slot = abfd; + if (bfd_sharing) + { + slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, INSERT); + gdb_assert (!*slot); + *slot = abfd; + } gdb_bfd_ref (abfd); return abfd; @@ -942,4 +950,17 @@ _initialize_gdb_bfd (void) add_cmd ("bfds", class_maintenance, maintenance_info_bfds, _("\ List the BFDs that are currently open."), &maintenanceinfolist); + + add_setshow_boolean_cmd ("bfd-sharing", no_class, + &bfd_sharing, _("\ +Set whether gdb will share bfds that appear to be the same file."), _("\ +Show whether gdb will share bfds that appear to be the same file."), _("\ +When enabled gdb will reuse existing bfds rather than reopening the\n\ +same file. To decide if two files are the same then gdb compares the\n\ +filename, file size, file modification time, and file inode."), + NULL, + NULL, + &maintenance_set_cmdlist, + &maintenance_show_cmdlist); + bfd_sharing = 1; } -- 2.4.0