Blame SOURCES/gdb-dlopen-stap-probe-7of9.patch

01917d
http://sourceware.org/ml/gdb-cvs/2013-06/msg00018.html
01917d
01917d
### src/gdb/ChangeLog	2013/06/04 13:10:53	1.15684
01917d
### src/gdb/ChangeLog	2013/06/04 13:17:05	1.15685
01917d
## -1,5 +1,58 @@
01917d
 2013-06-04  Gary Benson  <gbenson@redhat.com>
01917d
 
01917d
+	* breakpoint.h (handle_solib_event): Moved function declaration
01917d
+	to solib.h.
01917d
+	* breakpoint.c (handle_solib_event): Moved function to solib.c.
01917d
+	(bpstat_stop_status): Pass new argument to handle_solib_event.
01917d
+	* solib.h (update_solib_breakpoints): New function declaration.
01917d
+	(handle_solib_event): Moved function declaration from
01917d
+	breakpoint.h.
01917d
+	* solib.c (update_solib_breakpoints): New function.
01917d
+	(handle_solib_event): Moved function from breakpoint.c.
01917d
+	Updated to call solib_ops->handle_event if not NULL.
01917d
+	* solist.h (target_so_ops): New fields "update_breakpoints" and
01917d
+	"handle_event".
01917d
+	* infrun.c (set_stop_on_solib_events): New function.
01917d
+	(_initialize_infrun): Use the above for "set
01917d
+	stop-on-solib-events".
01917d
+	(handle_inferior_event): Pass new argument to handle_solib_event.
01917d
+	* solib-svr4.c (probe.h): New include.
01917d
+	(svr4_free_library_list): New forward declaration.
01917d
+	(probe_action): New enum.
01917d
+	(probe_info): New struct.
01917d
+	(probe_info): New static variable.
01917d
+	(NUM_PROBES): New definition.
01917d
+	(svr4_info): New fields "using_xfer", "probes_table" and
01917d
+	"solib_list".
01917d
+	(free_probes_table): New function.
01917d
+	(free_solib_list): New function.
01917d
+	(svr4_pspace_data_cleanup): Free probes table and solib list.
01917d
+	(svr4_copy_library_list): New function.
01917d
+	(svr4_current_sos_via_xfer_libraries): New parameter "annex".
01917d
+	(svr4_read_so_list): New parameter "prev_lm".
01917d
+	(svr4_current_sos_direct): Renamed from "svr4_current_sos".
01917d
+	(svr4_current_sos): New function.
01917d
+	(probe_and_action): New struct.
01917d
+	(hash_probe_and_action): New function.
01917d
+	(equal_probe_and_action): Likewise.
01917d
+	(register_solib_event_probe): Likewise.
01917d
+	(solib_event_probe_at): Likewise.
01917d
+	(solib_event_probe_action): Likewise.
01917d
+	(solist_update_full): Likewise.
01917d
+	(solist_update_incremental): Likewise.
01917d
+	(disable_probes_interface_cleanup): Likewise.
01917d
+	(svr4_handle_solib_event): Likewise.
01917d
+	(svr4_update_solib_event_breakpoint): Likewise.
01917d
+	(svr4_update_solib_event_breakpoints): Likewise.
01917d
+	(svr4_create_solib_event_breakpoints): Likewise.
01917d
+	(enable_break): Free probes table before creating breakpoints.
01917d
+	Use svr4_create_solib_event_breakpoints to create breakpoints.
01917d
+	(svr4_solib_create_inferior_hook): Free the solib list.
01917d
+	(_initialize_svr4_solib): Initialise
01917d
+	svr4_so_ops.handle_solib_event and svr4_so_ops.update_breakpoints.
01917d
+
01917d
+2013-06-04  Gary Benson  <gbenson@redhat.com>
01917d
+
01917d
 	* target.h (target_ops): New field
01917d
 	"to_augmented_libraries_svr4_read".
01917d
 	(target_augmented_libraries_svr4_read): New macro.
01917d
Index: gdb-7.6/gdb/breakpoint.h
01917d
===================================================================
01917d
--- gdb-7.6.orig/gdb/breakpoint.h	2013-06-10 14:44:37.455812656 +0200
01917d
+++ gdb-7.6/gdb/breakpoint.h	2013-06-10 14:44:37.709812579 +0200
01917d
@@ -1552,8 +1552,6 @@ extern int user_breakpoint_p (struct bre
01917d
 /* Attempt to determine architecture of location identified by SAL.  */
01917d
 extern struct gdbarch *get_sal_arch (struct symtab_and_line sal);
01917d
 
01917d
-extern void handle_solib_event (void);
01917d
-
01917d
 extern void breakpoint_free_objfile (struct objfile *objfile);
01917d
 
01917d
 extern void breakpoints_relocate (struct objfile *objfile,
01917d
Index: gdb-7.6/gdb/infrun.c
01917d
===================================================================
01917d
--- gdb-7.6.orig/gdb/infrun.c	2013-06-10 14:44:37.427812664 +0200
01917d
+++ gdb-7.6/gdb/infrun.c	2013-06-10 14:44:37.711812579 +0200
01917d
@@ -370,6 +370,16 @@ static struct symbol *step_start_functio
01917d
 /* Nonzero if we want to give control to the user when we're notified
01917d
    of shared library events by the dynamic linker.  */
01917d
 int stop_on_solib_events;
01917d
+
01917d
+/* Enable or disable optional shared library event breakpoints
01917d
+   as appropriate when the above flag is changed.  */
01917d
+
01917d
+static void
01917d
+set_stop_on_solib_events (char *args, int from_tty, struct cmd_list_element *c)
01917d
+{
01917d
+  update_solib_breakpoints ();
01917d
+}
01917d
+
01917d
 static void
01917d
 show_stop_on_solib_events (struct ui_file *file, int from_tty,
01917d
 			   struct cmd_list_element *c, const char *value)
01917d
@@ -7335,7 +7345,7 @@ Show stopping for shared library events.
01917d
 If nonzero, gdb will give control to the user when the dynamic linker\n\
01917d
 notifies gdb of shared library events.  The most common event of interest\n\
01917d
 to the user would be loading/unloading of a new library."),
01917d
-			    NULL,
01917d
+			    set_stop_on_solib_events,
01917d
 			    show_stop_on_solib_events,
01917d
 			    &setlist, &showlist);
01917d
 
01917d
Index: gdb-7.6/gdb/solib-svr4.c
01917d
===================================================================
01917d
--- gdb-7.6.orig/gdb/solib-svr4.c	2013-06-10 14:44:37.392812675 +0200
01917d
+++ gdb-7.6/gdb/solib-svr4.c	2013-06-10 14:44:37.712812578 +0200
01917d
@@ -46,10 +46,12 @@
01917d
 #include "auxv.h"
01917d
 #include "exceptions.h"
01917d
 #include "gdb_bfd.h"
01917d
+#include "probe.h"
01917d
 
01917d
 static struct link_map_offsets *svr4_fetch_link_map_offsets (void);
01917d
 static int svr4_have_link_map_offsets (void);
01917d
 static void svr4_relocate_main_executable (void);
01917d
+static void svr4_free_library_list (void *p_list);
01917d
 
01917d
 /* Link map info to include in an allocated so_list entry.  */
01917d
 
01917d
@@ -106,6 +108,55 @@ static const  char * const main_name_lis
01917d
   NULL
01917d
 };
01917d
 
01917d
+/* What to do when a probe stop occurs.  */
01917d
+
01917d
+enum probe_action
01917d
+{
01917d
+  /* Something went seriously wrong.  Stop using probes and
01917d
+     revert to using the older interface.  */
01917d
+  PROBES_INTERFACE_FAILED,
01917d
+
01917d
+  /* No action is required.  The shared object list is still
01917d
+     valid.  */
01917d
+  DO_NOTHING,
01917d
+
01917d
+  /* The shared object list should be reloaded entirely.  */
01917d
+  FULL_RELOAD,
01917d
+
01917d
+  /* Attempt to incrementally update the shared object list. If
01917d
+     the update fails or is not possible, fall back to reloading
01917d
+     the list in full.  */
01917d
+  UPDATE_OR_RELOAD,
01917d
+};
01917d
+
01917d
+/* A probe's name and its associated action.  */
01917d
+
01917d
+struct probe_info
01917d
+{
01917d
+  /* The name of the probe.  */
01917d
+  const char *name;
01917d
+
01917d
+  /* What to do when a probe stop occurs.  */
01917d
+  enum probe_action action;
01917d
+};
01917d
+
01917d
+/* A list of named probes and their associated actions.  If all
01917d
+   probes are present in the dynamic linker then the probes-based
01917d
+   interface will be used.  */
01917d
+
01917d
+static const struct probe_info probe_info[] =
01917d
+{
01917d
+  { "init_start", DO_NOTHING },
01917d
+  { "init_complete", FULL_RELOAD },
01917d
+  { "map_start", DO_NOTHING },
01917d
+  { "map_failed", DO_NOTHING },
01917d
+  { "reloc_complete", UPDATE_OR_RELOAD },
01917d
+  { "unmap_start", DO_NOTHING },
01917d
+  { "unmap_complete", FULL_RELOAD },
01917d
+};
01917d
+
01917d
+#define NUM_PROBES ARRAY_SIZE (probe_info)
01917d
+
01917d
 /* Return non-zero if GDB_SO_NAME and INFERIOR_SO_NAME represent
01917d
    the same shared library.  */
01917d
 
01917d
@@ -313,17 +364,58 @@ struct svr4_info
01917d
   CORE_ADDR interp_text_sect_high;
01917d
   CORE_ADDR interp_plt_sect_low;
01917d
   CORE_ADDR interp_plt_sect_high;
01917d
+
01917d
+  /* Nonzero if the list of objects was last obtained from the target
01917d
+     via qXfer:libraries-svr4:read.  */
01917d
+  int using_xfer;
01917d
+
01917d
+  /* Table of struct probe_and_action instances, used by the
01917d
+     probes-based interface to map breakpoint addresses to probes
01917d
+     and their associated actions.  Lookup is performed using
01917d
+     probe_and_action->probe->address.  */
01917d
+  htab_t probes_table;
01917d
+
01917d
+  /* List of objects loaded into the inferior, used by the probes-
01917d
+     based interface.  */
01917d
+  struct so_list *solib_list;
01917d
 };
01917d
 
01917d
 /* Per-program-space data key.  */
01917d
 static const struct program_space_data *solib_svr4_pspace_data;
01917d
 
01917d
+/* Free the probes table.  */
01917d
+
01917d
+static void
01917d
+free_probes_table (struct svr4_info *info)
01917d
+{
01917d
+  if (info->probes_table == NULL)
01917d
+    return;
01917d
+
01917d
+  htab_delete (info->probes_table);
01917d
+  info->probes_table = NULL;
01917d
+}
01917d
+
01917d
+/* Free the solib list.  */
01917d
+
01917d
+static void
01917d
+free_solib_list (struct svr4_info *info)
01917d
+{
01917d
+  svr4_free_library_list (&info->solib_list);
01917d
+  info->solib_list = NULL;
01917d
+}
01917d
+
01917d
 static void
01917d
 svr4_pspace_data_cleanup (struct program_space *pspace, void *arg)
01917d
 {
01917d
   struct svr4_info *info;
01917d
 
01917d
   info = program_space_data (pspace, solib_svr4_pspace_data);
01917d
+  if (info == NULL)
01917d
+    return;
01917d
+
01917d
+  free_probes_table (info);
01917d
+  free_solib_list (info);
01917d
+
01917d
   xfree (info);
01917d
 }
01917d
 
01917d
@@ -982,6 +1074,34 @@ svr4_free_library_list (void *p_list)
01917d
     }
01917d
 }
01917d
 
01917d
+/* Copy library list.  */
01917d
+
01917d
+static struct so_list *
01917d
+svr4_copy_library_list (struct so_list *src)
01917d
+{
01917d
+  struct so_list *dst = NULL;
01917d
+  struct so_list **link = &dst;
01917d
+
01917d
+  while (src != NULL)
01917d
+    {
01917d
+      struct so_list *new;
01917d
+
01917d
+      new = xmalloc (sizeof (struct so_list));
01917d
+      memcpy (new, src, sizeof (struct so_list));
01917d
+
01917d
+      new->lm_info = xmalloc (sizeof (struct lm_info));
01917d
+      memcpy (new->lm_info, src->lm_info, sizeof (struct lm_info));
01917d
+
01917d
+      new->next = NULL;
01917d
+      *link = new;
01917d
+      link = &new->next;
01917d
+
01917d
+      src = src->next;
01917d
+    }
01917d
+
01917d
+  return dst;
01917d
+}
01917d
+
01917d
 #ifdef HAVE_LIBEXPAT
01917d
 
01917d
 #include "xml-support.h"
01917d
@@ -1097,23 +1217,30 @@ svr4_parse_libraries (const char *docume
01917d
   return 0;
01917d
 }
01917d
 
01917d
-/* Attempt to get so_list from target via qXfer:libraries:read packet.
01917d
+/* Attempt to get so_list from target via qXfer:libraries-svr4:read packet.
01917d
 
01917d
    Return 0 if packet not supported, *SO_LIST_RETURN is not modified in such
01917d
    case.  Return 1 if *SO_LIST_RETURN contains the library list, it may be
01917d
-   empty, caller is responsible for freeing all its entries.  */
01917d
+   empty, caller is responsible for freeing all its entries.
01917d
+
01917d
+   Note that ANNEX must be NULL if the remote does not explicitly allow
01917d
+   qXfer:libraries-svr4:read packets with non-empty annexes.  Support for
01917d
+   this can be checked using target_augmented_libraries_svr4_read ().  */
01917d
 
01917d
 static int
01917d
-svr4_current_sos_via_xfer_libraries (struct svr4_library_list *list)
01917d
+svr4_current_sos_via_xfer_libraries (struct svr4_library_list *list,
01917d
+				     const char *annex)
01917d
 {
01917d
   char *svr4_library_document;
01917d
   int result;
01917d
   struct cleanup *back_to;
01917d
 
01917d
+  gdb_assert (annex == NULL || target_augmented_libraries_svr4_read ());
01917d
+
01917d
   /* Fetch the list of shared libraries.  */
01917d
   svr4_library_document = target_read_stralloc (&current_target,
01917d
 						TARGET_OBJECT_LIBRARIES_SVR4,
01917d
-						NULL);
01917d
+						annex);
01917d
   if (svr4_library_document == NULL)
01917d
     return 0;
01917d
 
01917d
@@ -1127,7 +1254,8 @@ svr4_current_sos_via_xfer_libraries (str
01917d
 #else
01917d
 
01917d
 static int
01917d
-svr4_current_sos_via_xfer_libraries (struct svr4_library_list *list)
01917d
+svr4_current_sos_via_xfer_libraries (struct svr4_library_list *list,
01917d
+				     const char *annex)
01917d
 {
01917d
   return 0;
01917d
 }
01917d
@@ -1161,15 +1289,19 @@ svr4_default_sos (void)
01917d
   return new;
01917d
 }
01917d
 
01917d
-/* Read the whole inferior libraries chain starting at address LM.  Add the
01917d
-   entries to the tail referenced by LINK_PTR_PTR.  Ignore the first entry if
01917d
-   IGNORE_FIRST and set global MAIN_LM_ADDR according to it.  */
01917d
+/* Read the whole inferior libraries chain starting at address LM.
01917d
+   Expect the first entry in the chain's previous entry to be PREV_LM.
01917d
+   Add the entries to the tail referenced by LINK_PTR_PTR.  Ignore the
01917d
+   first entry if IGNORE_FIRST and set global MAIN_LM_ADDR according
01917d
+   to it.  Returns nonzero upon success.  If zero is returned the
01917d
+   entries stored to LINK_PTR_PTR are still valid although they may
01917d
+   represent only part of the inferior library list.  */
01917d
 
01917d
-static void
01917d
-svr4_read_so_list (CORE_ADDR lm, struct so_list ***link_ptr_ptr,
01917d
-		   int ignore_first)
01917d
+static int
01917d
+svr4_read_so_list (CORE_ADDR lm, CORE_ADDR prev_lm,
01917d
+		   struct so_list ***link_ptr_ptr, int ignore_first)
01917d
 {
01917d
-  CORE_ADDR prev_lm = 0, next_lm;
01917d
+  CORE_ADDR next_lm;
01917d
 
01917d
   for (; lm != 0; prev_lm = lm, lm = next_lm)
01917d
     {
01917d
@@ -1185,7 +1317,7 @@ svr4_read_so_list (CORE_ADDR lm, struct
01917d
       if (new->lm_info == NULL)
01917d
 	{
01917d
 	  do_cleanups (old_chain);
01917d
-	  break;
01917d
+	  return 0;
01917d
 	}
01917d
 
01917d
       next_lm = new->lm_info->l_next;
01917d
@@ -1196,7 +1328,7 @@ svr4_read_so_list (CORE_ADDR lm, struct
01917d
 		   paddress (target_gdbarch (), prev_lm),
01917d
 		   paddress (target_gdbarch (), new->lm_info->l_prev));
01917d
 	  do_cleanups (old_chain);
01917d
-	  break;
01917d
+	  return 0;
01917d
 	}
01917d
 
01917d
       /* For SVR4 versions, the first entry in the link map is for the
01917d
@@ -1291,17 +1423,21 @@ svr4_read_so_list (CORE_ADDR lm, struct
01917d
       **link_ptr_ptr = new;
01917d
       *link_ptr_ptr = &new->next;
01917d
     }
01917d
+
01917d
+  return 1;
01917d
 }
01917d
 
01917d
-/* Implement the "current_sos" target_so_ops method.  */
01917d
+/* Read the full list of currently loaded shared objects directly
01917d
+   from the inferior, without referring to any libraries read and
01917d
+   stored by the probes interface.  Handle special cases relating
01917d
+   to the first elements of the list.  */
01917d
 
01917d
 static struct so_list *
01917d
-svr4_current_sos (void)
01917d
+svr4_current_sos_direct (struct svr4_info *info)
01917d
 {
01917d
   CORE_ADDR lm;
01917d
   struct so_list *head = NULL;
01917d
   struct so_list **link_ptr = &head;
01917d
-  struct svr4_info *info;
01917d
   struct cleanup *back_to;
01917d
   int ignore_first;
01917d
   struct svr4_library_list library_list;
01917d
@@ -1314,19 +1450,16 @@ svr4_current_sos (void)
01917d
      Unfortunately statically linked inferiors will also fall back through this
01917d
      suboptimal code path.  */
01917d
 
01917d
-  if (svr4_current_sos_via_xfer_libraries (&library_list))
01917d
+  info->using_xfer = svr4_current_sos_via_xfer_libraries (&library_list,
01917d
+							  NULL);
01917d
+  if (info->using_xfer)
01917d
     {
01917d
       if (library_list.main_lm)
01917d
-	{
01917d
-	  info = get_svr4_info ();
01917d
-	  info->main_lm_addr = library_list.main_lm;
01917d
-	}
01917d
+	info->main_lm_addr = library_list.main_lm;
01917d
 
01917d
       return library_list.head ? library_list.head : svr4_default_sos ();
01917d
     }
01917d
 
01917d
-  info = get_svr4_info ();
01917d
-
01917d
   /* Always locate the debug struct, in case it has moved.  */
01917d
   info->debug_base = 0;
01917d
   locate_base (info);
01917d
@@ -1349,7 +1482,7 @@ svr4_current_sos (void)
01917d
      `struct so_list' nodes.  */
01917d
   lm = solib_svr4_r_map (info);
01917d
   if (lm)
01917d
-    svr4_read_so_list (lm, &link_ptr, ignore_first);
01917d
+    svr4_read_so_list (lm, 0, &link_ptr, ignore_first);
01917d
 
01917d
   /* On Solaris, the dynamic linker is not in the normal list of
01917d
      shared objects, so make sure we pick it up too.  Having
01917d
@@ -1357,7 +1490,7 @@ svr4_current_sos (void)
01917d
      for skipping dynamic linker resolver code.  */
01917d
   lm = solib_svr4_r_ldsomap (info);
01917d
   if (lm)
01917d
-    svr4_read_so_list (lm, &link_ptr, 0);
01917d
+    svr4_read_so_list (lm, 0, &link_ptr, 0);
01917d
 
01917d
   discard_cleanups (back_to);
01917d
 
01917d
@@ -1367,6 +1500,22 @@ svr4_current_sos (void)
01917d
   return head;
01917d
 }
01917d
 
01917d
+/* Implement the "current_sos" target_so_ops method.  */
01917d
+
01917d
+static struct so_list *
01917d
+svr4_current_sos (void)
01917d
+{
01917d
+  struct svr4_info *info = get_svr4_info ();
01917d
+
01917d
+  /* If the solib list has been read and stored by the probes
01917d
+     interface then we return a copy of the stored list.  */
01917d
+  if (info->solib_list != NULL)
01917d
+    return svr4_copy_library_list (info->solib_list);
01917d
+
01917d
+  /* Otherwise obtain the solib list directly from the inferior.  */
01917d
+  return svr4_current_sos_direct (info);
01917d
+}
01917d
+
01917d
 /* Get the address of the link_map for a given OBJFILE.  */
01917d
 
01917d
 CORE_ADDR
01917d
@@ -1449,6 +1598,476 @@ exec_entry_point (struct bfd *abfd, stru
01917d
   return gdbarch_addr_bits_remove (target_gdbarch (), addr);
01917d
 }
01917d
 
01917d
+/* A probe and its associated action.  */
01917d
+
01917d
+struct probe_and_action
01917d
+{
01917d
+  /* The probe.  */
01917d
+  struct probe *probe;
01917d
+
01917d
+  /* The action.  */
01917d
+  enum probe_action action;
01917d
+};
01917d
+
01917d
+/* Returns a hash code for the probe_and_action referenced by p.  */
01917d
+
01917d
+static hashval_t
01917d
+hash_probe_and_action (const void *p)
01917d
+{
01917d
+  const struct probe_and_action *pa = p;
01917d
+
01917d
+  return (hashval_t) pa->probe->address;
01917d
+}
01917d
+
01917d
+/* Returns non-zero if the probe_and_actions referenced by p1 and p2
01917d
+   are equal.  */
01917d
+
01917d
+static int
01917d
+equal_probe_and_action (const void *p1, const void *p2)
01917d
+{
01917d
+  const struct probe_and_action *pa1 = p1;
01917d
+  const struct probe_and_action *pa2 = p2;
01917d
+
01917d
+  return pa1->probe->address == pa2->probe->address;
01917d
+}
01917d
+
01917d
+/* Register a solib event probe and its associated action in the
01917d
+   probes table.  */
01917d
+
01917d
+static void
01917d
+register_solib_event_probe (struct probe *probe, enum probe_action action)
01917d
+{
01917d
+  struct svr4_info *info = get_svr4_info ();
01917d
+  struct probe_and_action lookup, *pa;
01917d
+  void **slot;
01917d
+
01917d
+  /* Create the probes table, if necessary.  */
01917d
+  if (info->probes_table == NULL)
01917d
+    info->probes_table = htab_create_alloc (1, hash_probe_and_action,
01917d
+					    equal_probe_and_action,
01917d
+					    xfree, xcalloc, xfree);
01917d
+
01917d
+  lookup.probe = probe;
01917d
+  slot = htab_find_slot (info->probes_table, &lookup, INSERT);
01917d
+  gdb_assert (*slot == HTAB_EMPTY_ENTRY);
01917d
+
01917d
+  pa = XCNEW (struct probe_and_action);
01917d
+  pa->probe = probe;
01917d
+  pa->action = action;
01917d
+
01917d
+  *slot = pa;
01917d
+}
01917d
+
01917d
+/* Get the solib event probe at the specified location, and the
01917d
+   action associated with it.  Returns NULL if no solib event probe
01917d
+   was found.  */
01917d
+
01917d
+static struct probe_and_action *
01917d
+solib_event_probe_at (struct svr4_info *info, CORE_ADDR address)
01917d
+{
01917d
+  struct probe lookup_probe;
01917d
+  struct probe_and_action lookup;
01917d
+  void **slot;
01917d
+
01917d
+  lookup_probe.address = address;
01917d
+  lookup.probe = &lookup_probe;
01917d
+  slot = htab_find_slot (info->probes_table, &lookup, NO_INSERT);
01917d
+
01917d
+  if (slot == NULL)
01917d
+    return NULL;
01917d
+
01917d
+  return (struct probe_and_action *) *slot;
01917d
+}
01917d
+
01917d
+/* Decide what action to take when the specified solib event probe is
01917d
+   hit.  */
01917d
+
01917d
+static enum probe_action
01917d
+solib_event_probe_action (struct probe_and_action *pa)
01917d
+{
01917d
+  enum probe_action action;
01917d
+  unsigned probe_argc;
01917d
+
01917d
+  action = pa->action;
01917d
+  if (action == DO_NOTHING || action == PROBES_INTERFACE_FAILED)
01917d
+    return action;
01917d
+
01917d
+  gdb_assert (action == FULL_RELOAD || action == UPDATE_OR_RELOAD);
01917d
+
01917d
+  /* Check that an appropriate number of arguments has been supplied.
01917d
+     We expect:
01917d
+       arg0: Lmid_t lmid (mandatory)
01917d
+       arg1: struct r_debug *debug_base (mandatory)
01917d
+       arg2: struct link_map *new (optional, for incremental updates)  */
01917d
+  probe_argc = get_probe_argument_count (pa->probe);
01917d
+  if (probe_argc == 2)
01917d
+    action = FULL_RELOAD;
01917d
+  else if (probe_argc < 2)
01917d
+    action = PROBES_INTERFACE_FAILED;
01917d
+
01917d
+  return action;
01917d
+}
01917d
+
01917d
+/* Populate the shared object list by reading the entire list of
01917d
+   shared objects from the inferior.  Handle special cases relating
01917d
+   to the first elements of the list.  Returns nonzero on success.  */
01917d
+
01917d
+static int
01917d
+solist_update_full (struct svr4_info *info)
01917d
+{
01917d
+  free_solib_list (info);
01917d
+  info->solib_list = svr4_current_sos_direct (info);
01917d
+
01917d
+  return 1;
01917d
+}
01917d
+
01917d
+/* Update the shared object list starting from the link-map entry
01917d
+   passed by the linker in the probe's third argument.  Returns
01917d
+   nonzero if the list was successfully updated, or zero to indicate
01917d
+   failure.  */
01917d
+
01917d
+static int
01917d
+solist_update_incremental (struct svr4_info *info, CORE_ADDR lm)
01917d
+{
01917d
+  struct so_list *tail;
01917d
+  CORE_ADDR prev_lm;
01917d
+
01917d
+  /* svr4_current_sos_direct contains logic to handle a number of
01917d
+     special cases relating to the first elements of the list.  To
01917d
+     avoid duplicating this logic we defer to solist_update_full
01917d
+     if the list is empty.  */
01917d
+  if (info->solib_list == NULL)
01917d
+    return 0;
01917d
+
01917d
+  /* Fall back to a full update if we are using a remote target
01917d
+     that does not support incremental transfers.  */
01917d
+  if (info->using_xfer && !target_augmented_libraries_svr4_read ())
01917d
+    return 0;
01917d
+
01917d
+  /* Walk to the end of the list.  */
01917d
+  for (tail = info->solib_list; tail->next != NULL; tail = tail->next)
01917d
+    /* Nothing.  */;
01917d
+  prev_lm = tail->lm_info->lm_addr;
01917d
+
01917d
+  /* Read the new objects.  */
01917d
+  if (info->using_xfer)
01917d
+    {
01917d
+      struct svr4_library_list library_list;
01917d
+      char annex[64];
01917d
+
01917d
+      xsnprintf (annex, sizeof (annex), "start=%s;prev=%s",
01917d
+		 phex_nz (lm, sizeof (lm)),
01917d
+		 phex_nz (prev_lm, sizeof (prev_lm)));
01917d
+      if (!svr4_current_sos_via_xfer_libraries (&library_list, annex))
01917d
+	return 0;
01917d
+
01917d
+      tail->next = library_list.head;
01917d
+    }
01917d
+  else
01917d
+    {
01917d
+      struct so_list **link = &tail->next;
01917d
+
01917d
+      /* IGNORE_FIRST may safely be set to zero here because the
01917d
+	 above check and deferral to solist_update_full ensures
01917d
+	 that this call to svr4_read_so_list will never see the
01917d
+	 first element.  */
01917d
+      if (!svr4_read_so_list (lm, prev_lm, &link, 0))
01917d
+	return 0;
01917d
+    }
01917d
+
01917d
+  return 1;
01917d
+}
01917d
+
01917d
+/* Disable the probes-based linker interface and revert to the
01917d
+   original interface.  We don't reset the breakpoints as the
01917d
+   ones set up for the probes-based interface are adequate.  */
01917d
+
01917d
+static void
01917d
+disable_probes_interface_cleanup (void *arg)
01917d
+{
01917d
+  struct svr4_info *info = get_svr4_info ();
01917d
+
01917d
+  warning (_("Probes-based dynamic linker interface failed.\n"
01917d
+	     "Reverting to original interface.\n"));
01917d
+
01917d
+  free_probes_table (info);
01917d
+  free_solib_list (info);
01917d
+}
01917d
+
01917d
+/* Update the solib list as appropriate when using the
01917d
+   probes-based linker interface.  Do nothing if using the
01917d
+   standard interface.  */
01917d
+
01917d
+static void
01917d
+svr4_handle_solib_event (void)
01917d
+{
01917d
+  struct svr4_info *info = get_svr4_info ();
01917d
+  struct probe_and_action *pa;
01917d
+  enum probe_action action;
01917d
+  struct cleanup *old_chain, *usm_chain;
01917d
+  struct value *val;
01917d
+  CORE_ADDR pc, debug_base, lm = 0;
01917d
+  int is_initial_ns;
01917d
+
01917d
+  /* Do nothing if not using the probes interface.  */
01917d
+  if (info->probes_table == NULL)
01917d
+    return;
01917d
+
01917d
+  /* If anything goes wrong we revert to the original linker
01917d
+     interface.  */
01917d
+  old_chain = make_cleanup (disable_probes_interface_cleanup, NULL);
01917d
+
01917d
+  pc = regcache_read_pc (get_current_regcache ());
01917d
+  pa = solib_event_probe_at (info, pc);
01917d
+  if (pa == NULL)
01917d
+    {
01917d
+      do_cleanups (old_chain);
01917d
+      return;
01917d
+    }
01917d
+
01917d
+  action = solib_event_probe_action (pa);
01917d
+  if (action == PROBES_INTERFACE_FAILED)
01917d
+    {
01917d
+      do_cleanups (old_chain);
01917d
+      return;
01917d
+    }
01917d
+
01917d
+  if (action == DO_NOTHING)
01917d
+    {
01917d
+      discard_cleanups (old_chain);
01917d
+      return;
01917d
+    }
01917d
+
01917d
+  /* evaluate_probe_argument looks up symbols in the dynamic linker
01917d
+     using find_pc_section.  find_pc_section is accelerated by a cache
01917d
+     called the section map.  The section map is invalidated every
01917d
+     time a shared library is loaded or unloaded, and if the inferior
01917d
+     is generating a lot of shared library events then the section map
01917d
+     will be updated every time svr4_handle_solib_event is called.
01917d
+     We called find_pc_section in svr4_create_solib_event_breakpoints,
01917d
+     so we can guarantee that the dynamic linker's sections are in the
01917d
+     section map.  We can therefore inhibit section map updates across
01917d
+     these calls to evaluate_probe_argument and save a lot of time.  */
01917d
+  inhibit_section_map_updates (current_program_space);
01917d
+  usm_chain = make_cleanup (resume_section_map_updates_cleanup,
01917d
+			    current_program_space);
01917d
+
01917d
+  val = evaluate_probe_argument (pa->probe, 1);
01917d
+  if (val == NULL)
01917d
+    {
01917d
+      do_cleanups (old_chain);
01917d
+      return;
01917d
+    }
01917d
+
01917d
+  debug_base = value_as_address (val);
01917d
+  if (debug_base == 0)
01917d
+    {
01917d
+      do_cleanups (old_chain);
01917d
+      return;
01917d
+    }
01917d
+
01917d
+  /* Always locate the debug struct, in case it moved.  */
01917d
+  info->debug_base = 0;
01917d
+  if (locate_base (info) == 0)
01917d
+    {
01917d
+      do_cleanups (old_chain);
01917d
+      return;
01917d
+    }
01917d
+
01917d
+  /* GDB does not currently support libraries loaded via dlmopen
01917d
+     into namespaces other than the initial one.  We must ignore
01917d
+     any namespace other than the initial namespace here until
01917d
+     support for this is added to GDB.  */
01917d
+  if (debug_base != info->debug_base)
01917d
+    action = DO_NOTHING;
01917d
+
01917d
+  if (action == UPDATE_OR_RELOAD)
01917d
+    {
01917d
+      val = evaluate_probe_argument (pa->probe, 2);
01917d
+      if (val != NULL)
01917d
+	lm = value_as_address (val);
01917d
+
01917d
+      if (lm == 0)
01917d
+	action = FULL_RELOAD;
01917d
+    }
01917d
+
01917d
+  /* Resume section map updates.  */
01917d
+  do_cleanups (usm_chain);
01917d
+
01917d
+  if (action == UPDATE_OR_RELOAD)
01917d
+    {
01917d
+      if (!solist_update_incremental (info, lm))
01917d
+	action = FULL_RELOAD;
01917d
+    }
01917d
+
01917d
+  if (action == FULL_RELOAD)
01917d
+    {
01917d
+      if (!solist_update_full (info))
01917d
+	{
01917d
+	  do_cleanups (old_chain);
01917d
+	  return;
01917d
+	}
01917d
+    }
01917d
+
01917d
+  discard_cleanups (old_chain);
01917d
+}
01917d
+
01917d
+/* Helper function for svr4_update_solib_event_breakpoints.  */
01917d
+
01917d
+static int
01917d
+svr4_update_solib_event_breakpoint (struct breakpoint *b, void *arg)
01917d
+{
01917d
+  struct bp_location *loc;
01917d
+
01917d
+  if (b->type != bp_shlib_event)
01917d
+    {
01917d
+      /* Continue iterating.  */
01917d
+      return 0;
01917d
+    }
01917d
+
01917d
+  for (loc = b->loc; loc != NULL; loc = loc->next)
01917d
+    {
01917d
+      struct svr4_info *info;
01917d
+      struct probe_and_action *pa;
01917d
+
01917d
+      info = program_space_data (loc->pspace, solib_svr4_pspace_data);
01917d
+      if (info == NULL || info->probes_table == NULL)
01917d
+	continue;
01917d
+
01917d
+      pa = solib_event_probe_at (info, loc->address);
01917d
+      if (pa == NULL)
01917d
+	continue;
01917d
+
01917d
+      if (pa->action == DO_NOTHING)
01917d
+	{
01917d
+	  if (b->enable_state == bp_disabled && stop_on_solib_events)
01917d
+	    enable_breakpoint (b);
01917d
+	  else if (b->enable_state == bp_enabled && !stop_on_solib_events)
01917d
+	    disable_breakpoint (b);
01917d
+	}
01917d
+
01917d
+      break;
01917d
+    }
01917d
+
01917d
+  /* Continue iterating.  */
01917d
+  return 0;
01917d
+}
01917d
+
01917d
+/* Enable or disable optional solib event breakpoints as appropriate.
01917d
+   Called whenever stop_on_solib_events is changed.  */
01917d
+
01917d
+static void
01917d
+svr4_update_solib_event_breakpoints (void)
01917d
+{
01917d
+  iterate_over_breakpoints (svr4_update_solib_event_breakpoint, NULL);
01917d
+}
01917d
+
01917d
+/* Create and register solib event breakpoints.  PROBES is an array
01917d
+   of NUM_PROBES elements, each of which is vector of probes.  A
01917d
+   solib event breakpoint will be created and registered for each
01917d
+   probe.  */
01917d
+
01917d
+static void
01917d
+svr4_create_probe_breakpoints (struct gdbarch *gdbarch,
01917d
+			       VEC (probe_p) **probes)
01917d
+{
01917d
+  int i;
01917d
+
01917d
+  for (i = 0; i < NUM_PROBES; i++)
01917d
+    {
01917d
+      enum probe_action action = probe_info[i].action;
01917d
+      struct probe *probe;
01917d
+      int ix;
01917d
+
01917d
+      for (ix = 0;
01917d
+	   VEC_iterate (probe_p, probes[i], ix, probe);
01917d
+	   ++ix)
01917d
+	{
01917d
+	  create_solib_event_breakpoint (gdbarch, probe->address);
01917d
+	  register_solib_event_probe (probe, action);
01917d
+	}
01917d
+    }
01917d
+
01917d
+  svr4_update_solib_event_breakpoints ();
01917d
+}
01917d
+
01917d
+/* Both the SunOS and the SVR4 dynamic linkers call a marker function
01917d
+   before and after mapping and unmapping shared libraries.  The sole
01917d
+   purpose of this method is to allow debuggers to set a breakpoint so
01917d
+   they can track these changes.
01917d
+
01917d
+   Some versions of the glibc dynamic linker contain named probes
01917d
+   to allow more fine grained stopping.  Given the address of the
01917d
+   original marker function, this function attempts to find these
01917d
+   probes, and if found, sets breakpoints on those instead.  If the
01917d
+   probes aren't found, a single breakpoint is set on the original
01917d
+   marker function.  */
01917d
+
01917d
+static void
01917d
+svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
01917d
+				     CORE_ADDR address)
01917d
+{
01917d
+  struct obj_section *os;
01917d
+
01917d
+  os = find_pc_section (address);
01917d
+  if (os != NULL)
01917d
+    {
01917d
+      int with_prefix;
01917d
+
01917d
+      for (with_prefix = 0; with_prefix <= 1; with_prefix++)
01917d
+	{
01917d
+	  VEC (probe_p) *probes[NUM_PROBES];
01917d
+	  int all_probes_found = 1;
01917d
+	  int i;
01917d
+
01917d
+	  memset (probes, 0, sizeof (probes));
01917d
+	  for (i = 0; i < NUM_PROBES; i++)
01917d
+	    {
01917d
+	      const char *name = probe_info[i].name;
01917d
+	      char buf[32];
01917d
+
01917d
+	      /* Fedora 17 and Red Hat Enterprise Linux 6.2-6.4
01917d
+		 shipped with an early version of the probes code in
01917d
+		 which the probes' names were prefixed with "rtld_"
01917d
+		 and the "map_failed" probe did not exist.  The
01917d
+		 locations of the probes are otherwise the same, so
01917d
+		 we check for probes with prefixed names if probes
01917d
+		 with unprefixed names are not present.  */
01917d
+	      if (with_prefix)
01917d
+		{
01917d
+		  xsnprintf (buf, sizeof (buf), "rtld_%s", name);
01917d
+		  name = buf;
01917d
+		}
01917d
+
01917d
+	      probes[i] = find_probes_in_objfile (os->objfile, "rtld", name);
01917d
+
01917d
+	      /* The "map_failed" probe did not exist in early
01917d
+		 versions of the probes code in which the probes'
01917d
+		 names were prefixed with "rtld_".  */
01917d
+	      if (strcmp (name, "rtld_map_failed") == 0)
01917d
+		continue;
01917d
+
01917d
+	      if (VEC_empty (probe_p, probes[i]))
01917d
+		{
01917d
+		  all_probes_found = 0;
01917d
+		  break;
01917d
+		}
01917d
+	    }
01917d
+
01917d
+	  if (all_probes_found)
01917d
+	    svr4_create_probe_breakpoints (gdbarch, probes);
01917d
+
01917d
+	  for (i = 0; i < NUM_PROBES; i++)
01917d
+	    VEC_free (probe_p, probes[i]);
01917d
+
01917d
+	  if (all_probes_found)
01917d
+	    return;
01917d
+	}
01917d
+    }
01917d
+
01917d
+  create_solib_event_breakpoint (gdbarch, address);
01917d
+}
01917d
+
01917d
 /* Helper function for gdb_bfd_lookup_symbol.  */
01917d
 
01917d
 static int
01917d
@@ -1532,7 +2151,7 @@ enable_break (struct svr4_info *info, in
01917d
 	 That knowledge is encoded in the address, if it's Thumb the low bit
01917d
 	 is 1.  However, we've stripped that info above and it's not clear
01917d
 	 what all the consequences are of passing a non-addr_bits_remove'd
01917d
-	 address to create_solib_event_breakpoint.  The call to
01917d
+	 address to svr4_create_solib_event_breakpoints.  The call to
01917d
 	 find_pc_section verifies we know about the address and have some
01917d
 	 hope of computing the right kind of breakpoint to use (via
01917d
 	 symbol info).  It does mean that GDB needs to be pointed at a
01917d
@@ -1570,7 +2189,7 @@ enable_break (struct svr4_info *info, in
01917d
 		+ bfd_section_size (tmp_bfd, interp_sect);
01917d
 	    }
01917d
 
01917d
-	  create_solib_event_breakpoint (target_gdbarch (), sym_addr);
01917d
+	  svr4_create_solib_event_breakpoints (target_gdbarch (), sym_addr);
01917d
 	  return 1;
01917d
 	}
01917d
     }
01917d
@@ -1728,7 +2347,8 @@ enable_break (struct svr4_info *info, in
01917d
 
01917d
       if (sym_addr != 0)
01917d
 	{
01917d
-	  create_solib_event_breakpoint (target_gdbarch (), load_addr + sym_addr);
01917d
+	  svr4_create_solib_event_breakpoints (target_gdbarch (),
01917d
+					       load_addr + sym_addr);
01917d
 	  xfree (interp_name);
01917d
 	  return 1;
01917d
 	}
01917d
@@ -1754,7 +2374,7 @@ enable_break (struct svr4_info *info, in
01917d
 	  sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
01917d
 							 sym_addr,
01917d
 							 &current_target);
01917d
-	  create_solib_event_breakpoint (target_gdbarch (), sym_addr);
01917d
+	  svr4_create_solib_event_breakpoints (target_gdbarch (), sym_addr);
01917d
 	  return 1;
01917d
 	}
01917d
     }
01917d
@@ -1770,7 +2390,7 @@ enable_break (struct svr4_info *info, in
01917d
 	      sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch (),
01917d
 							     sym_addr,
01917d
 							     &current_target);
01917d
-	      create_solib_event_breakpoint (target_gdbarch (), sym_addr);
01917d
+	      svr4_create_solib_event_breakpoints (target_gdbarch (), sym_addr);
01917d
 	      return 1;
01917d
 	    }
01917d
 	}
01917d
@@ -2266,6 +2886,10 @@ svr4_solib_create_inferior_hook (int fro
01917d
 
01917d
   info = get_svr4_info ();
01917d
 
01917d
+  /* Clear the probes-based interface's state.  */
01917d
+  free_probes_table (info);
01917d
+  free_solib_list (info);
01917d
+
01917d
   /* Relocate the main executable if necessary.  */
01917d
   svr4_relocate_main_executable ();
01917d
 
01917d
@@ -2507,4 +3131,6 @@ _initialize_svr4_solib (void)
01917d
   svr4_so_ops.lookup_lib_global_symbol = elf_lookup_lib_symbol;
01917d
   svr4_so_ops.same = svr4_same;
01917d
   svr4_so_ops.keep_data_in_core = svr4_keep_data_in_core;
01917d
+  svr4_so_ops.update_breakpoints = svr4_update_solib_event_breakpoints;
01917d
+  svr4_so_ops.handle_event = svr4_handle_solib_event;
01917d
 }
01917d
Index: gdb-7.6/gdb/solib.c
01917d
===================================================================
01917d
--- gdb-7.6.orig/gdb/solib.c	2013-06-10 14:44:37.392812675 +0200
01917d
+++ gdb-7.6/gdb/solib.c	2013-06-10 14:44:37.713812578 +0200
01917d
@@ -1221,6 +1221,37 @@ no_shared_libraries (char *ignored, int
01917d
   objfile_purge_solibs ();
01917d
 }
01917d
 
01917d
+/* See solib.h.  */
01917d
+
01917d
+void
01917d
+update_solib_breakpoints (void)
01917d
+{
01917d
+  const struct target_so_ops *ops = solib_ops (target_gdbarch ());
01917d
+
01917d
+  if (ops->update_breakpoints != NULL)
01917d
+    ops->update_breakpoints ();
01917d
+}
01917d
+
01917d
+/* See solib.h.  */
01917d
+
01917d
+void
01917d
+handle_solib_event (void)
01917d
+{
01917d
+  const struct target_so_ops *ops = solib_ops (target_gdbarch ());
01917d
+
01917d
+  if (ops->handle_event != NULL)
01917d
+    ops->handle_event ();
01917d
+
01917d
+  clear_program_space_solib_cache (current_inferior ()->pspace);
01917d
+
01917d
+  /* Check for any newly added shared libraries if we're supposed to
01917d
+     be adding them automatically.  Switch terminal for any messages
01917d
+     produced by breakpoint_re_set.  */
01917d
+  target_terminal_ours_for_output ();
01917d
+  solib_add (NULL, 0, &current_target, auto_solib_add);
01917d
+  target_terminal_inferior ();
01917d
+}
01917d
+
01917d
 /* Reload shared libraries, but avoid reloading the same symbol file
01917d
    we already have loaded.  */
01917d
 
01917d
Index: gdb-7.6/gdb/solib.h
01917d
===================================================================
01917d
--- gdb-7.6.orig/gdb/solib.h	2013-01-01 07:32:51.000000000 +0100
01917d
+++ gdb-7.6/gdb/solib.h	2013-06-10 14:44:37.713812578 +0200
01917d
@@ -90,4 +90,12 @@ extern CORE_ADDR gdb_bfd_lookup_symbol_f
01917d
 								      void *),
01917d
 						    void *data);
01917d
 
01917d
+/* Enable or disable optional solib event breakpoints as appropriate.  */
01917d
+
01917d
+extern void update_solib_breakpoints (void);
01917d
+
01917d
+/* Handle an solib event by calling solib_add.  */
01917d
+
01917d
+extern void handle_solib_event (void);
01917d
+
01917d
 #endif /* SOLIB_H */
01917d
Index: gdb-7.6/gdb/solist.h
01917d
===================================================================
01917d
--- gdb-7.6.orig/gdb/solist.h	2013-01-01 07:32:51.000000000 +0100
01917d
+++ gdb-7.6/gdb/solist.h	2013-06-10 14:44:37.713812578 +0200
01917d
@@ -148,6 +148,19 @@ struct target_so_ops
01917d
        core file (in particular, for readonly sections).  */
01917d
     int (*keep_data_in_core) (CORE_ADDR vaddr,
01917d
 			      unsigned long size);
01917d
+
01917d
+    /* Enable or disable optional solib event breakpoints as
01917d
+       appropriate.  This should be called whenever
01917d
+       stop_on_solib_events is changed.  This pointer can be
01917d
+       NULL, in which case no enabling or disabling is necessary
01917d
+       for this target.  */
01917d
+    void (*update_breakpoints) (void);
01917d
+
01917d
+    /* Target-specific processing of solib events that will be
01917d
+       performed before solib_add is called.  This pointer can be
01917d
+       NULL, in which case no specific preprocessing is necessary
01917d
+       for this target.  */
01917d
+    void (*handle_event) (void);
01917d
   };
01917d
 
01917d
 /* Free the memory associated with a (so_list *).  */
01917d
Index: gdb-7.6/gdb/breakpoint.c
01917d
===================================================================
01917d
--- gdb-7.6.orig/gdb/breakpoint.c	2013-06-10 14:44:37.500812642 +0200
01917d
+++ gdb-7.6/gdb/breakpoint.c	2013-06-10 14:44:57.301806708 +0200
01917d
@@ -5348,25 +5348,6 @@ handle_jit_event (void)
01917d
   target_terminal_inferior ();
01917d
 }
01917d
 
01917d
-/* Handle an solib event by calling solib_add.  */
01917d
-
01917d
-void
01917d
-handle_solib_event (void)
01917d
-{
01917d
-  clear_program_space_solib_cache (current_inferior ()->pspace);
01917d
-
01917d
-  /* Check for any newly added shared libraries if we're supposed to
01917d
-     be adding them automatically.  Switch terminal for any messages
01917d
-     produced by breakpoint_re_set.  */
01917d
-  target_terminal_ours_for_output ();
01917d
-#ifdef SOLIB_ADD
01917d
-  SOLIB_ADD (NULL, 0, &current_target, auto_solib_add);
01917d
-#else
01917d
-  solib_add (NULL, 0, &current_target, auto_solib_add);
01917d
-#endif
01917d
-  target_terminal_inferior ();
01917d
-}
01917d
-
01917d
 /* Prepare WHAT final decision for infrun.  */
01917d
 
01917d
 /* Decide what infrun needs to do with this bpstat.  */