From patchwork Thu Aug 13 12:44:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 8180 Received: (qmail 108639 invoked by alias); 13 Aug 2015 12:45:10 -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 108586 invoked by uid 89); 13 Aug 2015 12:45:10 -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:09 +0000 Received: by wibhh20 with SMTP id hh20so72451640wib.0 for ; Thu, 13 Aug 2015 05:45:06 -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=M9P7P51E2zU82dPqyanTfmTRzQivsWhMp4b1xwI6h+M=; b=j8goF2eLHqozXUo7NqsonzsHH4FGp4fDPIcN9RL4p5FxBH5wd4qr609SWzO34hX+AH MXIKgOjv22SKUzJBp4mm5LBeHSiCInDZq4yS6mm0FblnZobgaFQIDhxO0XSDdchJq9Zr g4SNElaAiDjUDEfA9RVJ84CQOemdMWct+H0upXxFaxJ8tlPSwkEgM3I1AHSesUHS7TrV mhZnAqVGspk2pDq4QBun8BOr8SAodfa5z9Zfh2sxk6jaaR/kwqACUnuVH/E43Cb3VsTp su89F3ecEIxoU2+7wH4ho/6EwkdeACAWGVw0i5lbZLSNnTgzCisotIfT1WL6nhU82kGo wq8w== X-Gm-Message-State: ALoCoQkepiN8O/zV4N343xN5Jkh5aTSLlZXK2KcfT5sse/R4nWQpnKCAvhT0AQntg+nQvAXZVhZM X-Received: by 10.180.106.68 with SMTP id gs4mr6034523wib.61.1439469906254; Thu, 13 Aug 2015 05:45:06 -0700 (PDT) Received: from localhost (cust64-dsl91-135-5.idnet.net. [91.135.5.64]) by smtp.gmail.com with ESMTPSA id ev2sm3224167wib.21.2015.08.13.05.45.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Aug 2015 05:45:05 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH v2 1/3] gdb: Improve cache matching criteria for the bfd cache. Date: Thu, 13 Aug 2015 13:44:58 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes Within gdb open bfd objects are reused where possible if an attempt is made to reopen a file that is already being debugged. To spot if the on disc file has changed gdb currently examines the mtime of the file and compares it to the mtime of the open bfd in the cache. A problem exists when the on disc file is being rapidly regenerated, as happens, for example, with automated testing. In some cases the file is generated so quickly that the mtime appears not to change, while the on disc file has changed. This patch extends the bfd cache to also hold the file size of the file, the inode of the file, and the device id of the file; gdb can then compare filename, file size, mtime, inode, and device id to determine if an existing bfd object can be reused. gdb/ChangeLog: * gdb_bfd.c (struct gdb_bfd_data): Add size, inode, and device id field. (struct gdb_bfd_cache_search): Likewise. (eq_bfd): Compare the size, inode, and device id fields. (gdb_bfd_open): Initialise the size, inode, and device id fields. (gdb_bfd_ref): Likewise. (gdb_bfd_unref): Likewise. --- gdb/ChangeLog | 10 ++++++++++ gdb/gdb_bfd.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a104670..d920ea0 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +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. + (eq_bfd): Compare the size, inode, and device id fields. + (gdb_bfd_open): Initialise the size, inode, and device id fields. + (gdb_bfd_ref): Likewise. + (gdb_bfd_unref): Likewise. + 2015-08-10 Doug Evans Keith Seitz diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 1781d80..ee29531 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -69,6 +69,15 @@ struct gdb_bfd_data /* The mtime of the BFD at the point the cache entry was made. */ time_t mtime; + /* The file size (in bytes) at the point the cache entry was made. */ + off_t size; + + /* The inode of the file at the point the cache entry was made. */ + ino_t inode; + + /* The device id of the file at the point the cache entry was made. */ + dev_t device_id; + /* This is true if we have determined whether this BFD has any sections requiring relocation. */ unsigned int relocation_computed : 1; @@ -112,6 +121,12 @@ struct gdb_bfd_cache_search const char *filename; /* The mtime. */ time_t mtime; + /* The file size (in bytes). */ + off_t size; + /* The inode of the file. */ + ino_t inode; + /* The device id of the file. */ + dev_t device_id; }; /* A hash function for BFDs. */ @@ -136,6 +151,9 @@ eq_bfd (const void *a, const void *b) struct gdb_bfd_data *gdata = bfd_usrdata (abfd); return (gdata->mtime == s->mtime + && gdata->size == s->size + && gdata->inode == s->inode + && gdata->device_id == s->device_id && strcmp (bfd_get_filename (abfd), s->filename) == 0); } @@ -358,9 +376,17 @@ gdb_bfd_open (const char *name, const char *target, int fd) { /* Weird situation here. */ search.mtime = 0; + search.size = 0; + search.inode = 0; + search.device_id = 0; } else - search.mtime = st.st_mtime; + { + search.mtime = st.st_mtime; + search.size = st.st_size; + search.inode = st.st_ino; + search.device_id = st.st_dev; + } /* Note that this must compute the same result as hash_bfd. */ hash = htab_hash_string (name); @@ -435,6 +461,7 @@ gdb_bfd_close_or_warn (struct bfd *abfd) void gdb_bfd_ref (struct bfd *abfd) { + struct stat buf; struct gdb_bfd_data *gdata; void **slot; @@ -455,7 +482,19 @@ gdb_bfd_ref (struct bfd *abfd) gdata = bfd_zalloc (abfd, sizeof (struct gdb_bfd_data)); gdata->refc = 1; gdata->mtime = bfd_get_mtime (abfd); + gdata->size = bfd_get_size (abfd); gdata->archive_bfd = NULL; + if (bfd_stat (abfd, &buf) == 0) + { + gdata->inode = buf.st_ino; + gdata->device_id = buf.st_dev; + } + else + { + /* The stat failed. */ + gdata->inode = 0; + gdata->device_id = 0; + } bfd_usrdata (abfd) = gdata; bfd_alloc_data (abfd); @@ -495,6 +534,9 @@ gdb_bfd_unref (struct bfd *abfd) void **slot; search.mtime = gdata->mtime; + search.size = gdata->size; + search.inode = gdata->inode; + search.device_id = gdata->device_id; slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, NO_INSERT);