[patch] Speed up find_pc_section

Paul Pluzhnikov ppluzhnikov@google.com
Wed Jul 22 19:34:00 GMT 2009


On Wed, Jul 22, 2009 at 11:34 AM, Pedro Alves<pedro@codesourcery.com> wrote:

> A new function objfiles.c:objfiles_changed that is called
> from reread_symbols, would still be better, that abusing that
> observer, IMHO.

I agree. Try #4 tested and attached.

Thanks,
-- 
Paul Pluzhnikov

2009-07-22  Paul Pluzhnikov  <ppluzhnikov@google.com>

	* objfiles.h (objfiles_changed): New prototype.
        * objfiles.c (objfiles_updated_p): Rename to objfiles_changed_p.
	(allocate_objfile, free_objfile): Must rebuild section map.
        (objfile_relocate): Likewise.
	(update_section_map, find_pc_section): Adjust.
	(set_objfiles_updated_on_exe_change): Remove.
       	(set_objfiles_updated_on_solib_activity): Remove.
       	(_initialize_objfiles): Remove.
	(objfiles_changed): New function.
	* symfile.c (reread_symbols): Call objfiles_changed.
-------------- next part --------------
Index: objfiles.h
===================================================================
RCS file: /cvs/src/src/gdb/objfiles.h,v
retrieving revision 1.59
diff -u -p -u -r1.59 objfiles.h
--- objfiles.h	15 Jan 2009 16:35:22 -0000	1.59
+++ objfiles.h	22 Jul 2009 18:48:36 -0000
@@ -482,6 +482,8 @@ extern int have_partial_symbols (void);
 
 extern int have_full_symbols (void);
 
+extern void objfiles_changed (void);
+
 /* This operation deletes all objfile entries that represent solibs that
    weren't explicitly loaded by the user, via e.g., the add-symbol-file
    command.
Index: objfiles.c
===================================================================
RCS file: /cvs/src/src/gdb/objfiles.c,v
retrieving revision 1.86
diff -u -p -u -r1.86 objfiles.c
--- objfiles.c	21 Jul 2009 20:54:30 -0000	1.86
+++ objfiles.c	22 Jul 2009 18:48:36 -0000
@@ -68,7 +68,7 @@ struct objfile *rt_common_objfile;	/* Fo
 /* Records whether any objfiles appeared or disappeared since we last updated
    address to obj section map.  */
 
-static int objfiles_updated_p;
+static int objfiles_changed_p;
 
 /* Locate all mappable sections of a BFD file. 
    objfile_p_char is a char * to get it through
@@ -235,6 +235,8 @@ allocate_objfile (bfd *abfd, int flags)
   /* Save passed in flag bits. */
   objfile->flags |= flags;
 
+  objfiles_changed_p = 1;  /* Rebuild section map next time we need it.  */
+
   return (objfile);
 }
 
@@ -501,6 +503,7 @@ free_objfile (struct objfile *objfile)
   obstack_free (&objfile->objfile_obstack, 0);
   xfree (objfile);
   objfile = NULL;
+  objfiles_changed_p = 1;  /* Rebuild section map next time we need it.  */
 }
 
 static void
@@ -682,6 +685,7 @@ objfile_relocate (struct objfile *objfil
 
   /* Relocate breakpoints as necessary, after things are relocated. */
   breakpoint_re_set ();
+  objfiles_changed_p = 1;  /* Rebuild section map next time we need it.  */
 }
 

 /* Many places in gdb want to test just to see if we have any partial
@@ -798,7 +802,7 @@ update_section_map (struct obj_section *
   struct obj_section *s, **map;
   struct objfile *objfile;
 
-  gdb_assert (objfiles_updated_p != 0);
+  gdb_assert (objfiles_changed_p != 0);
 
   map = *pmap;
   xfree (map);
@@ -857,13 +861,13 @@ find_pc_section (CORE_ADDR pc)
   if (s)
     return s;
 
-  if (objfiles_updated_p != 0)
+  if (objfiles_changed_p != 0)
     {
       update_section_map (&sections, &num_sections);
 
       /* Don't need updates to section map until objfiles are added
          or removed.  */
-      objfiles_updated_p = 0;
+      objfiles_changed_p = 0;
     }
 
   sp = (struct obj_section **) bsearch (&pc, sections, num_sections,
@@ -989,28 +993,11 @@ objfile_data (struct objfile *objfile, c
   return objfile->data[data->index];
 }
 
-/* Set objfiles_updated_p so section map will be rebuilt next time it
-   is used.  Called by executable_changed observer.  */
-
-static void
-set_objfiles_updated_on_exe_change (void)
-{
-  objfiles_updated_p = 1;  /* Rebuild section map next time we need it.  */
-}
-
-/* Set objfiles_updated_p so section map will be rebuilt next time it
-   is used.  Called by solib_loaded/unloaded observer.  */
-
-static void
-set_objfiles_updated_on_solib_activity (struct so_list *so_list)
-{
-  objfiles_updated_p = 1;  /* Rebuild section map next time we need it.  */
-}
+/* Set objfiles_changed_p so section map will be rebuilt next time it
+   is used.  Called by reread_symbols.  */
 
 void
-_initialize_objfiles (void)
+objfiles_changed (void)
 {
-  observer_attach_executable_changed (set_objfiles_updated_on_exe_change);
-  observer_attach_solib_loaded (set_objfiles_updated_on_solib_activity);
-  observer_attach_solib_unloaded (set_objfiles_updated_on_solib_activity);
+  objfiles_changed_p = 1;  /* Rebuild section map next time we need it.  */
 }
Index: symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.237
diff -u -p -u -r1.237 symfile.c
--- symfile.c	2 Jul 2009 17:25:58 -0000	1.237
+++ symfile.c	22 Jul 2009 18:48:37 -0000
@@ -2457,8 +2457,10 @@ reread_symbols (void)
       /* At least one objfile has changed, so we can consider that
          the executable we're debugging has changed too.  */
       observer_notify_executable_changed ();
+
+      /* Notify objfiles that we've modified objfile sections.  */
+      objfiles_changed ();
     }
-      
 }
 
 


More information about the Gdb-patches mailing list