public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: dje@google.com (Doug Evans)
To: gdb-patches@sourceware.org
Subject: [patch] symtab_to_fullname: Use cached copy if it exists.
Date: Sat, 05 Nov 2011 22:08:00 -0000	[thread overview]
Message-ID: <20111105220814.6BE94246194@ruffy.mtv.corp.google.com> (raw)

Hi.
This patches makes {,p}symtab_to_fullname use the previously
computed copy if it exists.
ref: http://sourceware.org/ml/gdb-patches/2011-10/msg00807.html

Callers of these functions assume this behaviour (they call it
once for fullname and immediately again for realpath), dwarf2read.c caches
the result of path lookups, and there is forget_cached_source_info
to flush the values when necessary.

Thus I can see no reason not to apply this patch.
[Am I missing something?]

I will check this in in a few days if there are no objections.

2011-11-05  Doug Evans  <dje@google.com>

	* psymtab.c (psymtab_to_fullname): Use cached copy if it exists.
	* source.c (symtab_to_fullname): Ditto.

Index: psymtab.c
===================================================================
RCS file: /cvs/src/src/gdb/psymtab.c,v
retrieving revision 1.31
diff -u -p -r1.31 psymtab.c
--- psymtab.c	28 Oct 2011 17:29:37 -0000	1.31
+++ psymtab.c	5 Nov 2011 21:29:15 -0000
@@ -1110,6 +1110,7 @@ int find_and_open_source (const char *fi
 
    If this function fails to find the file that this partial_symtab represents,
    NULL will be returned and ps->fullname will be set to NULL.  */
+
 static char *
 psymtab_to_fullname (struct partial_symtab *ps)
 {
@@ -1118,8 +1119,12 @@ psymtab_to_fullname (struct partial_symt
   if (!ps)
     return NULL;
 
-  /* Don't check ps->fullname here, the file could have been
-     deleted/moved/..., look for it again.  */
+  /* Use cached copy if we have it.
+     We rely on forget_cached_source_info being called appropriately
+     to handle cases like the file being moved.  */
+  if (ps->fullname)
+    return ps->fullname;
+
   r = find_and_open_source (ps->filename, ps->dirname, &ps->fullname);
 
   if (r >= 0)
Index: source.c
===================================================================
RCS file: /cvs/src/src/gdb/source.c,v
retrieving revision 1.124
diff -u -p -r1.124 source.c
--- source.c	4 Aug 2011 19:10:12 -0000	1.124
+++ source.c	5 Nov 2011 21:29:15 -0000
@@ -1106,6 +1106,7 @@ open_source_file (struct symtab *s)
 
    If this function fails to find the file that this symtab represents,
    NULL will be returned and s->fullname will be set to NULL.  */
+
 char *
 symtab_to_fullname (struct symtab *s)
 {
@@ -1114,8 +1115,12 @@ symtab_to_fullname (struct symtab *s)
   if (!s)
     return NULL;
 
-  /* Don't check s->fullname here, the file could have been 
-     deleted/moved/..., look for it again.  */
+  /* Use cached copy if we have it.
+     We rely on forget_cached_source_info being called appropriately
+     to handle cases like the file being moved.  */
+  if (s->fullname)
+    return s->fullname;
+
   r = find_and_open_source (s->filename, s->dirname, &s->fullname);
 
   if (r >= 0)

                 reply	other threads:[~2011-11-05 22:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111105220814.6BE94246194@ruffy.mtv.corp.google.com \
    --to=dje@google.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).