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

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