This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] symtab_to_fullname: Use cached copy if it exists.


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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]