Jan Kratochvil 30f2069
2012-07-30  Gary Benson  <gbenson@redhat.com>
Jan Kratochvil 30f2069
Jan Kratochvil 30f2069
	* objfiles.h (inhibit_section_map_updates): New function
Jan Kratochvil 30f2069
	declaration.
Jan Kratochvil 30f2069
	(resume_section_map_updates): Likewise.
Jan Kratochvil 30f2069
	(resume_section_map_updates_cleanup): Likewise.
Jan Kratochvil 30f2069
	* objfiles.c (objfile_pspace_info): New field "inhibit_updates".
Jan Kratochvil 30f2069
	(find_pc_section): Do not update the section map if
Jan Kratochvil 30f2069
	inhibit_updates is set.
Jan Kratochvil 30f2069
	(inhibit_section_map_updates): New function.
Jan Kratochvil 30f2069
	(resume_section_map_updates): Likewise.
Jan Kratochvil 30f2069
	(resume_section_map_updates_cleanup): Likewise.
Jan Kratochvil 30f2069
	* solib-svr4.c (svr4_handle_solib_event): Inhibit section map
Jan Kratochvil 30f2069
	updates for calls to evaluate_probe_argument.
Jan Kratochvil 30f2069
Jan Kratochvil 30f2069
Index: gdb-7.4.91.20120814/gdb/objfiles.h
Jan Kratochvil 30f2069
===================================================================
Jan Kratochvil 30f2069
--- gdb-7.4.91.20120814.orig/gdb/objfiles.h	2012-08-14 17:16:54.000000000 +0200
Jan Kratochvil 30f2069
+++ gdb-7.4.91.20120814/gdb/objfiles.h	2012-08-14 17:20:55.913174609 +0200
Jan Kratochvil 30f2069
@@ -526,6 +526,22 @@ extern void set_objfile_data (struct obj
Jan Kratochvil 30f2069
 extern void *objfile_data (struct objfile *objfile,
Jan Kratochvil 30f2069
 			   const struct objfile_data *data);
Jan Kratochvil 30f2069
 
Jan Kratochvil 30f2069
+/* In normal use, the section map will be rebuilt by FIND_PC_SECTION
Jan Kratochvil 30f2069
+   if objfiles have been added, removed or relocated since it was last
Jan Kratochvil 30f2069
+   called.  Calling INHIBIT_SECTION_MAP_UPDATES will inhibit this
Jan Kratochvil 30f2069
+   behavior until RESUME_SECTION_MAP_UPDATES is called.  If you call
Jan Kratochvil 30f2069
+   INHIBIT_SECTION_MAP_UPDATES you must ensure that every call to
Jan Kratochvil 30f2069
+   FIND_PC_SECTION in the inhibited region relates to a section that
Jan Kratochvil 30f2069
+   is already in the section map and has not since been removed or
Jan Kratochvil 30f2069
+   relocated.  */
Jan Kratochvil 30f2069
+extern void inhibit_section_map_updates (void);
Jan Kratochvil 30f2069
+
Jan Kratochvil 30f2069
+/* Resume automatically rebuilding the section map as required.  */
Jan Kratochvil 30f2069
+extern void resume_section_map_updates (void);
Jan Kratochvil 30f2069
+
Jan Kratochvil 30f2069
+/* Version of the above suitable for use as a cleanup.  */
Jan Kratochvil 30f2069
+extern void resume_section_map_updates_cleanup (void *arg);
Jan Kratochvil 30f2069
+
Jan Kratochvil 30f2069
 extern void default_iterate_over_objfiles_in_search_order
Jan Kratochvil 30f2069
   (struct gdbarch *gdbarch,
Jan Kratochvil 30f2069
    iterate_over_objfiles_in_search_order_cb_ftype *cb,
Jan Kratochvil 30f2069
Index: gdb-7.4.91.20120814/gdb/objfiles.c
Jan Kratochvil 30f2069
===================================================================
Jan Kratochvil 30f2069
--- gdb-7.4.91.20120814.orig/gdb/objfiles.c	2012-08-14 17:16:55.000000000 +0200
Jan Kratochvil 30f2069
+++ gdb-7.4.91.20120814/gdb/objfiles.c	2012-08-14 17:20:55.915174609 +0200
Jan Kratochvil 30f2069
@@ -70,6 +70,9 @@ struct objfile_pspace_info
Jan Kratochvil 30f2069
   int objfiles_changed_p;
Jan Kratochvil 30f2069
   struct obj_section **sections;
Jan Kratochvil 30f2069
   int num_sections;
Jan Kratochvil 30f2069
+
Jan Kratochvil 30f2069
+  /* Nonzero if section map updates should be inhibited.  */
Jan Kratochvil 30f2069
+  int inhibit_updates;
Jan Kratochvil 30f2069
 };
Jan Kratochvil 30f2069
 
Jan Kratochvil 30f2069
 /* Per-program-space data key.  */
Jan Kratochvil 30f2069
@@ -1295,7 +1298,7 @@ find_pc_section (CORE_ADDR pc)
Jan Kratochvil 30f2069
     return s;
Jan Kratochvil 30f2069
 
Jan Kratochvil 30f2069
   pspace_info = get_objfile_pspace_data (current_program_space);
Jan Kratochvil 30f2069
-  if (pspace_info->objfiles_changed_p != 0)
Jan Kratochvil 30f2069
+  if (pspace_info->objfiles_changed_p && !pspace_info->inhibit_updates)
Jan Kratochvil 30f2069
     {
Jan Kratochvil 30f2069
       update_section_map (current_program_space,
Jan Kratochvil 30f2069
 			  &pspace_info->sections,
Jan Kratochvil 30f2069
@@ -1463,6 +1466,30 @@ objfiles_changed (void)
Jan Kratochvil 30f2069
   get_objfile_pspace_data (current_program_space)->objfiles_changed_p = 1;
Jan Kratochvil 30f2069
 }
Jan Kratochvil 30f2069
 
Jan Kratochvil 30f2069
+/* See comments in objfiles.h.  */
Jan Kratochvil 30f2069
+
Jan Kratochvil 30f2069
+void
Jan Kratochvil 30f2069
+inhibit_section_map_updates (void)
Jan Kratochvil 30f2069
+{
Jan Kratochvil 30f2069
+  get_objfile_pspace_data (current_program_space)->inhibit_updates = 1;
Jan Kratochvil 30f2069
+}
Jan Kratochvil 30f2069
+
Jan Kratochvil 30f2069
+/* See comments in objfiles.h.  */
Jan Kratochvil 30f2069
+
Jan Kratochvil 30f2069
+void
Jan Kratochvil 30f2069
+resume_section_map_updates (void)
Jan Kratochvil 30f2069
+{
Jan Kratochvil 30f2069
+  get_objfile_pspace_data (current_program_space)->inhibit_updates = 0;
Jan Kratochvil 30f2069
+}
Jan Kratochvil 30f2069
+
Jan Kratochvil 30f2069
+/* See comments in objfiles.h.  */
Jan Kratochvil 30f2069
+
Jan Kratochvil 30f2069
+void
Jan Kratochvil 30f2069
+resume_section_map_updates_cleanup (void *arg)
Jan Kratochvil 30f2069
+{
Jan Kratochvil 30f2069
+  resume_section_map_updates ();
Jan Kratochvil 30f2069
+}
Jan Kratochvil 30f2069
+
Jan Kratochvil 30f2069
 /* The default implementation for the "iterate_over_objfiles_in_search_order"
Jan Kratochvil 30f2069
    gdbarch method.  It is equivalent to use the ALL_OBJFILES macro,
Jan Kratochvil 30f2069
    searching the objfiles in the order they are stored internally,
Jan Kratochvil 30f2069
Index: gdb-7.4.91.20120814/gdb/solib-svr4.c
Jan Kratochvil 30f2069
===================================================================
Jan Kratochvil 30f2069
--- gdb-7.4.91.20120814.orig/gdb/solib-svr4.c	2012-08-14 17:20:42.000000000 +0200
Jan Kratochvil 30f2069
+++ gdb-7.4.91.20120814/gdb/solib-svr4.c	2012-08-14 17:21:14.090169216 +0200
Jan Kratochvil 30f2069
@@ -1847,6 +1847,7 @@ svr4_handle_solib_event (bpstat bs)
Jan Kratochvil 30f2069
   struct svr4_info *info = get_svr4_info ();
Jan Kratochvil 30f2069
   struct probe_and_info buf, *pi = &buf;
Jan Kratochvil 30f2069
   enum probe_action action;
Jan Kratochvil 30f2069
+  struct cleanup *cleanups = NULL;
Jan Kratochvil 30f2069
   struct value *val;
Jan Kratochvil 30f2069
   LONGEST lmid;
Jan Kratochvil 30f2069
   CORE_ADDR debug_base, lm = 0;
Jan Kratochvil 30f2069
@@ -1870,6 +1871,19 @@ svr4_handle_solib_event (bpstat bs)
Jan Kratochvil 30f2069
   if (action == NAMESPACE_NO_ACTION)
Jan Kratochvil 30f2069
     return;
Jan Kratochvil 30f2069
 
Jan Kratochvil 30f2069
+  /* EVALUATE_PROBE_ARGUMENT looks up symbols in the dynamic linker
Jan Kratochvil 30f2069
+     using FIND_PC_SECTION.  FIND_PC_SECTION is accelerated by a cache
Jan Kratochvil 30f2069
+     called the section map.  The section map is invalidated every
Jan Kratochvil 30f2069
+     time a shared library is loaded or unloaded, and if the inferior
Jan Kratochvil 30f2069
+     is generating a lot of shared library events then the section map
Jan Kratochvil 30f2069
+     will be updated every time SVR4_HANDLE_SOLIB_EVENT is called.
Jan Kratochvil 30f2069
+     We called FIND_PC_SECTION in SVR4_CREATE_SOLIB_EVENT_BREAKPOINTS,
Jan Kratochvil 30f2069
+     so we can guarantee that the dynamic linker's sections are in the
Jan Kratochvil 30f2069
+     section map.  We can therefore inhibit section map updates across
Jan Kratochvil 30f2069
+     these calls to EVALUATE_PROBE_ARGUMENT and save a lot of time.  */
Jan Kratochvil 30f2069
+  inhibit_section_map_updates ();
Jan Kratochvil 30f2069
+  cleanups = make_cleanup (resume_section_map_updates_cleanup, NULL);
Jan Kratochvil 30f2069
+
Jan Kratochvil 30f2069
   val = evaluate_probe_argument (pi->probe, 0);
Jan Kratochvil 30f2069
   if (val == NULL)
Jan Kratochvil 30f2069
     goto error;
Jan Kratochvil 30f2069
@@ -1901,6 +1915,9 @@ svr4_handle_solib_event (bpstat bs)
Jan Kratochvil 30f2069
 	action = NAMESPACE_RELOAD;
Jan Kratochvil 30f2069
     }
Jan Kratochvil 30f2069
 
Jan Kratochvil 30f2069
+  do_cleanups (cleanups);
Jan Kratochvil 30f2069
+  cleanups = NULL;
Jan Kratochvil 30f2069
+
Jan Kratochvil 30f2069
   if (action == NAMESPACE_UPDATE_OR_RELOAD)
Jan Kratochvil 30f2069
     {
Jan Kratochvil 30f2069
       if (namespace_update_incremental (info, lmid, lm, is_initial_ns))
Jan Kratochvil 30f2069
@@ -1923,6 +1940,8 @@ svr4_handle_solib_event (bpstat bs)
Jan Kratochvil 30f2069
   warning (_("Probes-based dynamic linker interface failed.\n"
Jan Kratochvil 30f2069
 	     "Reverting to original interface.\n"));
Jan Kratochvil 30f2069
 
Jan Kratochvil 30f2069
+  if (cleanups != NULL)
Jan Kratochvil 30f2069
+    do_cleanups (cleanups);
Jan Kratochvil 30f2069
   free_namespace_table (info);
Jan Kratochvil 30f2069
   free_probes (info);
Jan Kratochvil 30f2069
   info->using_probes = 0;