Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA 4/4 take 2] Improved linker-debugger interface
@ 2012-07-19 11:09 Gary Benson
  2012-07-25 19:36 ` Tom Tromey
  2012-08-15 17:24 ` Jan Kratochvil
  0 siblings, 2 replies; 19+ messages in thread
From: Gary Benson @ 2012-07-19 11:09 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 819 bytes --]

Hi all,

This patch implementes the probes-based runtime linker interface, with
incremental library list loading and multiple namespace support.

 - On inferior startup, GDB searches the dynamic linker for a number
   of named probes.

 - If all probes are found, GDB sets a breakpoint on each one.
   Otherwise, the standard function _dl_debug_state is used.

 - When using probes, a per-pspace hashtable is maintained of all
   libraries currently loaded by the inferior.  It's updated as
   necessary every time a solib event stop occurs.

 - When using probes, svr4_current_sos will generate its result
   from the hashtable (rather than reading the entire list from
   the inferior).

 - If any error occurs, GDB will print a warning and revert to
   the standard interface.

Thanks,
Gary

-- 
http://gbenson.net/

[-- Attachment #2: rtld-stap-6.patch --]
[-- Type: text/plain, Size: 60453 bytes --]

gdb/
2012-07-19  Gary Benson  <gbenson@redhat.com>

	* breakpoint.h (handle_solib_event): Moved function definition
	to solib.h, and added a new parameter.
	* breakpoint.c (handle_solib_event): Moved function to solib.c
	and added a new parameter.
	(bpstat_stop_status): Pass new argument to handle_solib_event.
	* solib.h (breakpoint.h): New include.
	(handle_solib_event): Moved function definition from breakpoint.h
	and added a new parameter.
	(update_solib_breakpoints): New function definition.
	* solib.c (handle_solib_event): Moved function from breakpoint.c
	and added a new parameter.
	(update_solib_breakpoints): New function.
	* solist.h (breakpoint.h): New include.
	(target_so_ops): New fields "handle_solib_event" and
	"update_breakpoints".
	* infrun.c (set_stop_on_solib_events): New function.
	(_initialize_infrun): Use the above for "set stop-on-solib-events".
	(handle_inferior_event): Pass new argument to handle_solib_event.
	* solib-svr4.c (probe.h): New include.
	(namespace_table_flatten): New forward declaration.
	(lm_info): New fields "lmid" and "in_initial_ns".
	(probe_action): New enum.
	(probe_info): New struct.
	(probe_info): New static variable.
	(NUM_PROBES): New definition.
	(svr4_info): New fields  "using_probes", "probes" and
	"namespace_table".
	(free_probes): New function.
	(free_namespace_table): Likewise.
	(svr4_pspace_data_cleanup): Free probes and namespace table.
	(svr4_same): Also compare namespaces if using probes.
	(lm_addr_check): Only print .dynamic section at wrong address
	warning for initial namespace if using probes.
	(r_map_from_debug_base): New function.
	(solib_svr4_r_map): Call the above.
	(svr4_read_so_list): New parameter "prev_lm".
	Changed	return type from void to int.
	Return nonzero on success, zero on error.
	(svr4_current_sos_from_debug_base): New function.
	(svr4_current_sos): Create result from namespace table if available.
	Use svr4_current_sos_from_debug_base to generate list otherwise.
	(probe_and_info): New struct.
	(solib_event_probe_at): New function.
	(solib_event_probe_action): Likewise.
	(namespace): New struct.
	(hash_namespace): New function.
	(equal_namespace): Likewise.
	(free_namespace): Likewise.
	(namespace_update_full): Likewise.
	(namespace_update_incremental): Likewise.
	(svr4_handle_solib_event): Likewise.
	(namespace_table_flatten_helper): Likewise.
	(namespace_table_flatten): Likewise.
	(svr4_update_solib_event_breakpoint): Likewise.
	(svr4_update_solib_event_breakpoints): Likewise.
	(svr4_create_solib_event_breakpoints): Likewise.
	(enable_break): Free probes before creating breakpoints.
	Use svr4_create_solib_event_breakpoints to create breakpoints.
	(svr4_solib_create_inferior_hook): Free the namespace table.
	(_initialize_svr4_solib): Initialise svr4_so_ops.handle_solib_event
	and svr4_so_ops.update_breakpoints.

gdb/testsuite
2012-07-19  Gary Benson  <gbenson@redhat.com>

	* gdb.base/break-interp.exp (solib_bp): New constant.
	(reach_1): Use the above instead of "_dl_debug_state".
	(test_attach): Likewise.
	(test_ld): Likewise.
	* gdb.base/break-probes.exp: New file.
	* gdb.base/break-probes.c: Likewise.
	* gdb.base/break-probes-solib.c: Likewise.
	* gdb.base/info-shared.exp: New file.
	* gdb.base/info-shared.c: Likewise.
	* gdb.base/info-shared-solib1.c: Likewise.
	* gdb.base/info-shared-solib2.c: Likewise.
	* gdb.base/break-dlmopen.exp: Likewise.
	* gdb.base/break-dlmopen.c: Likewise.
	* gdb.base/break-dlmopen-solib.c: Likewise.

diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 4e4f875..f678702 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1515,6 +1515,4 @@ extern int user_breakpoint_p (struct breakpoint *);
 /* Attempt to determine architecture of location identified by SAL.  */
 extern struct gdbarch *get_sal_arch (struct symtab_and_line sal);
 
-extern void handle_solib_event (void);
-
 #endif /* !defined (BREAKPOINT_H) */
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 6b9faf3..51c98a7 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5205,7 +5205,7 @@ bpstat_stop_status (struct address_space *aspace,
     {
       if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
 	{
-	  handle_solib_event ();
+	  handle_solib_event (bs);
 	  break;
 	}
     }
@@ -5301,25 +5301,6 @@ handle_jit_event (void)
   target_terminal_inferior ();
 }
 
-/* Handle an solib event by calling solib_add.  */
-
-void
-handle_solib_event (void)
-{
-  clear_program_space_solib_cache (current_inferior ()->pspace);
-
-  /* Check for any newly added shared libraries if we're supposed to
-     be adding them automatically.  Switch terminal for any messages
-     produced by breakpoint_re_set.  */
-  target_terminal_ours_for_output ();
-#ifdef SOLIB_ADD
-  SOLIB_ADD (NULL, 0, &current_target, auto_solib_add);
-#else
-  solib_add (NULL, 0, &current_target, auto_solib_add);
-#endif
-  target_terminal_inferior ();
-}
-
 /* Prepare WHAT final decision for infrun.  */
 
 /* Decide what infrun needs to do with this bpstat.  */
diff --git a/gdb/solib.h b/gdb/solib.h
index 7a2ff84..6e92ddc 100644
--- a/gdb/solib.h
+++ b/gdb/solib.h
@@ -21,6 +21,9 @@
 #ifndef SOLIB_H
 #define SOLIB_H
 
+/* For bpstat.  */
+#include "breakpoint.h"
+
 /* Forward decl's for prototypes */
 struct so_list;
 struct target_ops;
@@ -91,4 +94,15 @@ extern CORE_ADDR gdb_bfd_lookup_symbol_from_symtab (bfd *abfd,
 								      void *),
 						    void *data);
 
+/* Handle an solib event by calling solib_add.  Targets which handle
+   solib events using breakpoints must pass a valid bpstat.  Targets
+   which handle solib events using some other mechanism should pass
+   NULL.  */
+
+extern void handle_solib_event (bpstat bs);
+
+/* Enable or disable optional solib event breakpoints as appropriate.  */
+
+extern void update_solib_breakpoints (void);
+
 #endif /* SOLIB_H */
diff --git a/gdb/solib.c b/gdb/solib.c
index 90439ba..072fe4d 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1209,6 +1209,42 @@ no_shared_libraries (char *ignored, int from_tty)
   objfile_purge_solibs ();
 }
 
+/* See solib.h.  */
+
+void
+handle_solib_event (bpstat bs)
+{
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
+
+  if (ops->handle_solib_event != NULL)
+    ops->handle_solib_event (bs);
+
+  clear_program_space_solib_cache (current_inferior ()->pspace);
+
+  /* Check for any newly added shared libraries if we're supposed to
+     be adding them automatically.  Switch terminal for any messages
+     produced by breakpoint_re_set.  */
+  target_terminal_ours_for_output ();
+#ifdef SOLIB_ADD
+  SOLIB_ADD (NULL, 0, &current_target, auto_solib_add);
+#else
+  solib_add (NULL, 0, &current_target, auto_solib_add);
+#endif
+  target_terminal_inferior ();
+}
+
+/* See solib.h.  */
+
+void
+update_solib_breakpoints (void)
+{
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
+
+  if (ops->update_breakpoints != NULL)
+    ops->update_breakpoints ();
+}
+
+
 /* Reload shared libraries, but avoid reloading the same symbol file
    we already have loaded.  */
 
diff --git a/gdb/solist.h b/gdb/solist.h
index 7413e3b..ea580a9 100644
--- a/gdb/solist.h
+++ b/gdb/solist.h
@@ -23,6 +23,8 @@
 #define SO_NAME_MAX_PATH_SIZE 512	/* FIXME: Should be dynamic */
 /* For domain_enum domain.  */
 #include "symtab.h"
+/* For bpstat.  */
+#include "breakpoint.h"
 
 /* Forward declaration for target specific link map information.  This
    struct is opaque to all but the target specific file.  */
@@ -149,6 +151,20 @@ struct target_so_ops
        core file (in particular, for readonly sections).  */
     int (*keep_data_in_core) (CORE_ADDR vaddr,
 			      unsigned long size);
+
+    /* Target-specific handling of solib events.  For targets which
+       handle solib events using breakpoints a valid bpstat must be
+       passed.  Targets which handle solib events using some other
+       mechanism should pass NULL.  This pointer can be NULL, in which
+       case no specific handling is necessary for this target.  */
+    void (*handle_solib_event) (bpstat bs);
+
+    /* Enable or disable optional solib event breakpoints as
+       appropriate.  This should be called whenever
+       stop_on_solib_events is changed.  This pointer can be
+       NULL, in which case no enabling or disabling is necessary
+       for this target.  */
+    void (*update_breakpoints) (void);
   };
 
 /* Free the memory associated with a (so_list *).  */
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 11f981f..7c621ca 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -361,6 +361,16 @@ static struct symbol *step_start_function;
 /* Nonzero if we want to give control to the user when we're notified
    of shared library events by the dynamic linker.  */
 int stop_on_solib_events;
+
+/* Enable or disable optional shared library event breakpoints
+   as appropriate when the above flag is changed.  */
+
+static void
+set_stop_on_solib_events (char *args, int from_tty, struct cmd_list_element *c)
+{
+  update_solib_breakpoints ();
+}
+
 static void
 show_stop_on_solib_events (struct ui_file *file, int from_tty,
 			   struct cmd_list_element *c, const char *value)
@@ -3308,7 +3318,7 @@ handle_inferior_event (struct execution_control_state *ecs)
 	    context_switch (ecs->ptid);
 	  regcache = get_thread_regcache (ecs->ptid);
 
-	  handle_solib_event ();
+	  handle_solib_event (NULL);
 
 	  ecs->event_thread->control.stop_bpstat
 	    = bpstat_stop_status (get_regcache_aspace (regcache),
@@ -7204,7 +7214,7 @@ Show stopping for shared library events."), _("\
 If nonzero, gdb will give control to the user when the dynamic linker\n\
 notifies gdb of shared library events.  The most common event of interest\n\
 to the user would be loading/unloading of a new library."),
-			    NULL,
+			    set_stop_on_solib_events,
 			    show_stop_on_solib_events,
 			    &setlist, &showlist);
 
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 8e41f19..8298b42 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -47,9 +47,12 @@
 #include "auxv.h"
 #include "exceptions.h"
 
+#include "probe.h"
+
 static struct link_map_offsets *svr4_fetch_link_map_offsets (void);
 static int svr4_have_link_map_offsets (void);
 static void svr4_relocate_main_executable (void);
+static struct so_list *namespace_table_flatten (htab_t namespace_table);
 
 /* Link map info to include in an allocated so_list entry.  */
 
@@ -70,6 +73,16 @@
 
     /* Values read in from inferior's fields of the same name.  */
     CORE_ADDR l_ld, l_next, l_prev, l_name;
+
+    /* Numeric link-map ID of the namespace this object is loaded
+       into.  This value is only valid when using the probes-based
+       interface.  */
+    LONGEST lmid;
+
+    /* Nonzero if the namespace list this object is loaded into is the
+       application's initial namespace (LM_ID_BASE).  This value is
+       only valid when using the probes-based interface.  */
+    unsigned int in_initial_ns : 1;
   };
 
 /* On SVR4 systems, a list of symbols in the dynamic linker where
@@ -106,6 +119,53 @@
   NULL
 };
 
+/* What to do with the namespace table when a probe stop occurs.  */
+
+enum probe_action
+  {
+    /* Something went seriously wrong.  Stop using probes and
+       revert to using the older interface.  */
+    NAMESPACE_TABLE_INVALIDATE,
+
+    /* No action is required.  This namespace is still valid.  */
+    NAMESPACE_NO_ACTION,
+
+    /* This namespace should be reloaded entirely.  */
+    NAMESPACE_RELOAD,
+
+    /* Attempt to incrementally update this namespace. If the
+       update fails or is not possible, fall back to reloading
+       the namespace in full.  */
+    NAMESPACE_UPDATE_OR_RELOAD,
+  };
+
+/* A probe's name and its associated action.  */
+
+struct probe_info
+{
+  /* The name of the probe.  */
+  const char *name;
+
+  /* What to do with the namespace table when a probe stop occurs.  */
+  enum probe_action action;
+};
+
+/* A list of named probes and their associated actions.  If all
+   probes are present in the dynamic linker then the probes-based
+   interface will be used.  */
+
+static const struct probe_info probe_info[] =
+{
+  { "init_start", NAMESPACE_NO_ACTION },
+  { "init_complete", NAMESPACE_RELOAD },
+  { "map_start", NAMESPACE_NO_ACTION },
+  { "reloc_complete", NAMESPACE_UPDATE_OR_RELOAD },
+  { "unmap_start", NAMESPACE_NO_ACTION },
+  { "unmap_complete", NAMESPACE_RELOAD },
+};
+
+#define NUM_PROBES ARRAY_SIZE (probe_info)
+
 /* Per pspace SVR4 specific data.  */
 
 struct svr4_info
@@ -128,17 +188,58 @@
   CORE_ADDR interp_text_sect_high;
   CORE_ADDR interp_plt_sect_low;
   CORE_ADDR interp_plt_sect_high;
+
+  /* Nonzero if we are using the probes-based interface.  */
+  unsigned int using_probes : 1;
+
+  /* Named probes in the dynamic linker.  */
+  VEC (probe_p) *probes[NUM_PROBES];
+
+  /* Table of dynamic linker namespaces, used by the probes-based
+     interface.  */
+  htab_t namespace_table;
 };
 
 /* Per-program-space data key.  */
 static const struct program_space_data *solib_svr4_pspace_data;
 
+/* Free any allocated probe vectors.  */
+
+static void
+free_probes (struct svr4_info *info)
+{
+  int i;
+
+  for (i = 0; i < NUM_PROBES; i++)
+    VEC_free (probe_p, info->probes[i]);
+
+  memset (info->probes, 0, sizeof (info->probes));
+}
+
+/* Free the namespace table.  */
+
+static void
+free_namespace_table (struct svr4_info *info)
+{
+  if (info->namespace_table == NULL)
+    return;
+
+  htab_delete (info->namespace_table);
+  info->namespace_table = NULL;
+}
+
 static void
 svr4_pspace_data_cleanup (struct program_space *pspace, void *arg)
 {
   struct svr4_info *info;
 
   info = program_space_data (pspace, solib_svr4_pspace_data);
+  if (info == NULL)
+    return;
+
+  free_probes (info);
+  free_namespace_table (info);
+
   xfree (info);
 }
 
@@ -187,10 +288,21 @@
   return 0;
 }
 
+/* Return non-zero if GDB and INFERIOR represent the same shared
+   library.  */
+
 static int
 svr4_same (struct so_list *gdb, struct so_list *inferior)
 {
-  return (svr4_same_1 (gdb->so_original_name, inferior->so_original_name));
+  struct svr4_info *info = get_svr4_info ();
+
+  if (info->using_probes)
+    {
+      if (gdb->lm_info->lmid != inferior->lm_info->lmid)
+	return 0;
+    }
+
+  return svr4_same_1 (gdb->so_original_name, inferior->so_original_name);
 }
 
 static struct lm_info *
@@ -321,18 +433,26 @@
 	    }
 	  else
 	    {
-	      /* There is no way to verify the library file matches.  prelink
-		 can during prelinking of an unprelinked file (or unprelinking
-		 of a prelinked file) shift the DYNAMIC segment by arbitrary
-		 offset without any page size alignment.  There is no way to
-		 find out the ELF header and/or Program Headers for a limited
-		 verification if it they match.  One could do a verification
-		 of the DYNAMIC segment.  Still the found address is the best
-		 one GDB could find.  */
-
-	      warning (_(".dynamic section for \"%s\" "
-			 "is not at the expected address "
-			 "(wrong library or version mismatch?)"), so->so_name);
+	      struct svr4_info *info = get_svr4_info ();
+
+	      if (!info->using_probes || so->lm_info->in_initial_ns)
+		{
+		  /* There is no way to verify the library file
+		     matches.  prelink can during prelinking of an
+		     unprelinked file (or unprelinking of a prelinked
+		     file) shift the DYNAMIC segment by arbitrary
+		     offset without any page size alignment.  There is
+		     no way to find out the ELF header and/or Program
+		     Headers for a limited verification if it they
+		     match.  One could do a verification of the
+		     DYNAMIC segment.  Still the found address is the
+		     best one GDB could find.  */
+
+		  warning (_(".dynamic section for \"%s\" "
+			     "is not at the expected address "
+			     "(wrong library or version mismatch?)"),
+			   so->so_name);
+		}
 	    }
 	}
 
@@ -774,16 +894,10 @@
   return info->debug_base;
 }
 
-/* Find the first element in the inferior's dynamic link map, and
-   return its address in the inferior.  Return zero if the address
-   could not be determined.
-
-   FIXME: Perhaps we should validate the info somehow, perhaps by
-   checking r_version for a known version number, or r_state for
-   RT_CONSISTENT.  */
+/* Read the r_map field from the supplied r_debug structure.  */
 
 static CORE_ADDR
-solib_svr4_r_map (struct svr4_info *info)
+r_map_from_debug_base (CORE_ADDR debug_base)
 {
   struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
   struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
@@ -792,13 +906,27 @@
 
   TRY_CATCH (ex, RETURN_MASK_ERROR)
     {
-      addr = read_memory_typed_address (info->debug_base + lmo->r_map_offset,
+      addr = read_memory_typed_address (debug_base + lmo->r_map_offset,
                                         ptr_type);
     }
   exception_print (gdb_stderr, ex);
   return addr;
 }
 
+/* Find the first element in the inferior's dynamic link map, and
+   return its address in the inferior.  Return zero if the address
+   could not be determined.
+
+   FIXME: Perhaps we should validate the info somehow, perhaps by
+   checking r_version for a known version number, or r_state for
+   RT_CONSISTENT.  */
+
+static CORE_ADDR
+solib_svr4_r_map (struct svr4_info *info)
+{
+  return r_map_from_debug_base (info->debug_base);
+}
+
 /* Find r_brk from the inferior's debug base.  */
 
 static CORE_ADDR
@@ -1163,15 +1291,17 @@
   return new;
 }
 
-/* Read the whole inferior libraries chain starting at address LM.  Add the
-   entries to the tail referenced by LINK_PTR_PTR.  Ignore the first entry if
-   IGNORE_FIRST and set global MAIN_LM_ADDR according to it.  */
+/* Read the whole inferior libraries chain starting at address LM.
+   Expect the first entry in the chain's previous entry to be PREV_LM.
+   Add the entries to the tail referenced by LINK_PTR_PTR.  Ignore the
+   first entry if IGNORE_FIRST and set global MAIN_LM_ADDR according
+   to it.  Returns nonzero upon success.  */
 
-static void
-svr4_read_so_list (CORE_ADDR lm, struct so_list ***link_ptr_ptr,
-		   int ignore_first)
+static int
+svr4_read_so_list (CORE_ADDR lm, CORE_ADDR prev_lm,
+		   struct so_list ***link_ptr_ptr, int ignore_first)
 {
-  CORE_ADDR prev_lm = 0, next_lm;
+  CORE_ADDR next_lm;
 
   for (; lm != 0; prev_lm = lm, lm = next_lm)
     {
@@ -1188,7 +1318,7 @@
       if (new->lm_info == NULL)
 	{
 	  do_cleanups (old_chain);
-	  break;
+	  return 0;
 	}
 
       next_lm = new->lm_info->l_next;
@@ -1199,7 +1329,7 @@
 		   paddress (target_gdbarch, prev_lm),
 		   paddress (target_gdbarch, new->lm_info->l_prev));
 	  do_cleanups (old_chain);
-	  break;
+	  return 0;
 	}
 
       /* For SVR4 versions, the first entry in the link map is for the
@@ -1245,20 +1375,61 @@
       **link_ptr_ptr = new;
       *link_ptr_ptr = &new->next;
     }
+
+  return 1;
 }
 
-/* Implement the "current_sos" target_so_ops method.  */
+/* Read the list of loaded libraries from the dynamic linker's base
+   structure.  */
 
 static struct so_list *
-svr4_current_sos (void)
+svr4_current_sos_from_debug_base (void)
 {
+  struct svr4_info *info = get_svr4_info ();
   CORE_ADDR lm;
   struct so_list *head = NULL;
   struct so_list **link_ptr = &head;
-  struct svr4_info *info;
   struct cleanup *back_to;
   int ignore_first;
+
+  gdb_assert (info->debug_base);
+
+  /* Assume that everything is a library if the dynamic loader was loaded
+     late by a static executable.  */
+  if (exec_bfd && bfd_get_section_by_name (exec_bfd, ".dynamic") == NULL)
+    ignore_first = 0;
+  else
+    ignore_first = 1;
+
+  back_to = make_cleanup (svr4_free_library_list, &head);
+
+  /* Walk the inferior's link map list, and build our list of
+     `struct so_list' nodes.  */
+  lm = solib_svr4_r_map (info);
+  if (lm)
+    svr4_read_so_list (lm, 0, &link_ptr, ignore_first);
+
+  /* On Solaris, the dynamic linker is not in the normal list of
+     shared objects, so make sure we pick it up too.  Having
+     symbol information for the dynamic linker is quite crucial
+     for skipping dynamic linker resolver code.  */
+  lm = solib_svr4_r_ldsomap (info);
+  if (lm)
+    svr4_read_so_list (lm, 0, &link_ptr, 0);
+
+  discard_cleanups (back_to);
+
+  return head;
+}
+
+/* Implement the "current_sos" target_so_ops method.  */
+
+static struct so_list *
+svr4_current_sos (void)
+{
+  struct svr4_info *info;
   struct svr4_library_list library_list;
+  struct so_list *result;
 
   /* Fall back to manual examination of the target if the packet is not
      supported or gdbserver failed to find DT_DEBUG.  gdb.server/solib-list.exp
@@ -1281,6 +1452,10 @@
 
   info = get_svr4_info ();
 
+  /* If we have a namespace table then return a flattened copy.  */
+  if (info->namespace_table != NULL)
+    return namespace_table_flatten (info->namespace_table);
+
   /* Always locate the debug struct, in case it has moved.  */
   info->debug_base = 0;
   locate_base (info);
@@ -1290,35 +1465,12 @@
   if (! info->debug_base)
     return svr4_default_sos ();
 
-  /* Assume that everything is a library if the dynamic loader was loaded
-     late by a static executable.  */
-  if (exec_bfd && bfd_get_section_by_name (exec_bfd, ".dynamic") == NULL)
-    ignore_first = 0;
-  else
-    ignore_first = 1;
-
-  back_to = make_cleanup (svr4_free_library_list, &head);
-
-  /* Walk the inferior's link map list, and build our list of
-     `struct so_list' nodes.  */
-  lm = solib_svr4_r_map (info);
-  if (lm)
-    svr4_read_so_list (lm, &link_ptr, ignore_first);
-
-  /* On Solaris, the dynamic linker is not in the normal list of
-     shared objects, so make sure we pick it up too.  Having
-     symbol information for the dynamic linker is quite crucial
-     for skipping dynamic linker resolver code.  */
-  lm = solib_svr4_r_ldsomap (info);
-  if (lm)
-    svr4_read_so_list (lm, &link_ptr, 0);
-
-  discard_cleanups (back_to);
+  result = svr4_current_sos_from_debug_base ();
 
-  if (head == NULL)
+  if (result == NULL)
     return svr4_default_sos ();
 
-  return head;
+  return result;
 }
 
 /* Get the address of the link_map for a given OBJFILE.  */
@@ -1400,6 +1552,498 @@
 					     targ);
 }
 
+/* A probe and its associated information structure.  */
+
+struct probe_and_info
+{
+  /* The probe.  */
+  struct probe *probe;
+
+  /* The probe_info from which the probe was created.  */
+  const struct probe_info *info;
+};
+
+/* Get the solib event probe at the specified location, and the
+   probe_info the probe was created with.  Returns NULL if no solib
+   event probe exists at that location.  */
+
+static struct probe_and_info *
+solib_event_probe_at (struct svr4_info *info, struct bp_location *loc,
+		      struct probe_and_info *result)
+{
+  int i;
+
+  for (i = 0; i < NUM_PROBES; i++)
+    {
+      struct probe *probe;
+      int ix;
+
+      for (ix = 0; VEC_iterate (probe_p, info->probes[i], ix, probe); ++ix)
+	{
+	  if (loc->pspace == current_program_space
+	      && loc->address == probe->address)
+	    {
+	      result->info = &probe_info[i];
+	      result->probe = probe;
+
+	      return result;
+	    }
+	}
+    }
+
+  return NULL;
+}
+
+/* Decide what action to take when the specified solib event probe is
+   hit.  */
+
+static enum probe_action
+solib_event_probe_action (struct probe_and_info *pi)
+{
+  enum probe_action action;
+  unsigned probe_argc;
+
+  action = pi->info->action;
+  if (action == NAMESPACE_NO_ACTION || action == NAMESPACE_TABLE_INVALIDATE)
+    return action;
+
+  gdb_assert (action == NAMESPACE_RELOAD
+	      || action == NAMESPACE_UPDATE_OR_RELOAD);
+
+  /* Check that an appropriate number of arguments has been supplied.
+     We expect:
+       arg0: Lmid_t lmid (mandatory)
+       arg1: struct r_debug *debug_base (mandatory)
+       arg2: struct link_map *new (optional, for incremental updates)  */
+  probe_argc = get_probe_argument_count (pi->probe);
+  if (probe_argc == 2)
+    action = NAMESPACE_RELOAD;
+  else if (probe_argc < 2)
+    return NAMESPACE_TABLE_INVALIDATE;
+
+  return action;
+}
+
+/* A namespace in the dynamic linker.  */
+
+struct namespace
+{
+  /* Numeric link-map ID of the namespace.  */
+  LONGEST lmid;
+
+  /* List of objects loaded into the namespace.  */
+  struct so_list *solist;
+};
+
+/* Returns a hash code for the namespace referenced by p.  */
+
+static hashval_t
+hash_namespace (const PTR p)
+{
+  const struct namespace *ns = (const struct namespace *) p;
+
+  return (hashval_t) ns->lmid;
+}
+
+/* Returns non-zero if the namespaces referenced by p1 and p2
+   are equal.  */
+
+static int
+equal_namespace (const PTR p1, const PTR p2)
+{
+  const struct namespace *ns1 = (const struct namespace *) p1;
+  const struct namespace *ns2 = (const struct namespace *) p2;
+
+  return ns1->lmid == ns2->lmid;
+}
+
+/* Free a namespace.  */
+
+static void
+free_namespace (PTR p)
+{
+  struct namespace *ns = (struct namespace *) p;
+
+  svr4_free_library_list (ns->solist);
+  xfree (ns);
+}
+
+/* Populate this namespace by reading the entire list of shared
+   objects from the inferior.  Returns nonzero on success.  */
+
+static int
+namespace_update_full (struct svr4_info *info, LONGEST lmid,
+		       CORE_ADDR debug_base, int is_initial_ns)
+{
+  struct so_list *result = NULL, *so;
+  struct namespace lookup, *ns;
+  void **slot;
+
+  /* Read the list of shared objects from the inferior.  The
+     initial namespace requires extra processing and is handled
+     separately.  */
+  if (is_initial_ns)
+    {
+      result = svr4_current_sos_from_debug_base ();
+    }
+  else
+    {
+      CORE_ADDR lm = r_map_from_debug_base (debug_base);
+      struct so_list **link_ptr = &result;
+
+      if (!svr4_read_so_list (lm, 0, &link_ptr, 0))
+	return 0;
+    }
+
+  /* If the namespace is empty then delete it from the table.  */
+  if (result == NULL)
+    {
+      if (info->namespace_table != NULL)
+	{
+	  lookup.lmid = lmid;
+	  htab_remove_elt (info->namespace_table, &lookup);
+	}
+
+      return 1;
+    }
+
+  /* Fill in the link-map IDs and initial namespace flags.  */
+  for (so = result; so; so = so->next)
+    {
+      so->lm_info->lmid = lmid;
+      so->lm_info->in_initial_ns = is_initial_ns;
+    }
+
+  /* Create the namespace table, if necessary.  */
+  if (info->namespace_table == NULL)
+    {
+      info->namespace_table = htab_create_alloc (1, hash_namespace,
+						 equal_namespace,
+						 free_namespace,
+						 xcalloc, xfree);
+    }
+
+  /* Update the namespace table with our new list.  */
+  lookup.lmid = lmid;
+  slot = htab_find_slot (info->namespace_table, &lookup, INSERT);
+  if (*slot == HTAB_EMPTY_ENTRY)
+    {
+      ns = xcalloc (sizeof (struct namespace), 1);
+      ns->lmid = lmid;
+      *slot = ns;
+    }
+  else
+    {
+      ns = *slot;
+      svr4_free_library_list (ns->solist);
+    }
+  ns->solist = result;
+
+  return 1;
+}
+
+/* Update this namespace starting from the link-map entry passed by
+   the linker in the probe's third argument.  Returns nonzero if the
+   list was successfully updated, or zero to indicate failure.  */
+
+static int
+namespace_update_incremental (struct svr4_info *info, LONGEST lmid,
+			      CORE_ADDR lm, int is_initial_ns)
+{
+  struct namespace lookup, *ns;
+  struct so_list *tail, **link, *so;
+  struct value *val;
+
+  /* Find our namespace in the table.  */
+  if (info->namespace_table == NULL)
+    return 0;
+
+  lookup.lmid = lmid;
+  ns = htab_find (info->namespace_table, &lookup);
+  if (ns == NULL)
+    return 0;
+
+  /* Walk to the end of the list.  */
+  tail = ns->solist;
+  if (tail == NULL)
+    return 0;
+
+  while (tail->next)
+    tail = tail->next;
+  link = &tail->next;
+
+  /* Read the new objects.  */
+  if (!svr4_read_so_list (lm, tail->lm_info->lm_addr, &link, 0))
+    return 0;
+
+  /* Fill in the link-map IDs and initial namespace flags.  */
+  for (so = tail; so; so = so->next)
+    {
+      so->lm_info->lmid = lmid;
+      so->lm_info->in_initial_ns = is_initial_ns;
+    }
+
+  return 1;
+}
+
+/* Update the namespace table as appropriate when using the
+   probes-based linker interface.  Do nothing if using the
+   standard interface.  */
+
+static void
+svr4_handle_solib_event (bpstat bs)
+{
+  struct svr4_info *info = get_svr4_info ();
+  struct probe_and_info buf, *pi;
+  enum probe_action action;
+  struct value *val;
+  LONGEST lmid;
+  CORE_ADDR debug_base, lm = 0;
+  int is_initial_ns;
+
+  /* It is possible that this function will be called incorrectly
+     by the handle_solib_event in handle_inferior_event if GDB goes
+     fully multi-target.  */
+  gdb_assert (bs != NULL);
+
+  if (!info->using_probes)
+    return;
+
+  pi = solib_event_probe_at (info, bs->bp_location_at, &buf);
+  if (pi == NULL)
+    goto error;
+
+  action = solib_event_probe_action (pi);
+  if (action == NAMESPACE_TABLE_INVALIDATE)
+    goto error;
+
+  if (action == NAMESPACE_NO_ACTION)
+    return;
+
+  val = evaluate_probe_argument (pi->probe, 0);
+  if (val == NULL)
+    goto error;
+
+  lmid = value_as_long (val);
+
+  val = evaluate_probe_argument (pi->probe, 1);
+  if (val == NULL)
+    goto error;
+
+  debug_base = value_as_address (val);
+  if (debug_base == 0)
+    goto error;
+
+  /* Always locate the debug struct, in case it moved.  */
+  info->debug_base = 0;
+  if (locate_base (info) == 0)
+    goto error;
+
+  is_initial_ns = (debug_base == info->debug_base);
+
+  if (action == NAMESPACE_UPDATE_OR_RELOAD)
+    {
+      val = evaluate_probe_argument (pi->probe, 2);
+      if (val != NULL)
+	lm = value_as_address (val);
+
+      if (lm == 0)
+	action = NAMESPACE_RELOAD;
+    }
+
+  if (action == NAMESPACE_UPDATE_OR_RELOAD)
+    {
+      if (namespace_update_incremental (info, lmid, lm, is_initial_ns))
+	return;
+
+      action = NAMESPACE_RELOAD;
+    }
+
+  gdb_assert (action == NAMESPACE_RELOAD);
+
+  if (namespace_update_full (info, lmid, debug_base, is_initial_ns))
+    return;
+
+ error:
+
+  /* We should never reach here, but if we do we disable the
+     probes interface and revert to the original interface.
+     We don't reset the breakpoints as the ones we've set up
+     are adequate.  */
+  warning (_("Probes-based dynamic linker interface failed.\n"
+	     "Reverting to original interface.\n"));
+
+  free_namespace_table (info);
+  free_probes (info);
+  info->using_probes = 0;
+}
+
+/* Helper function for namespace_table_flatten.  */
+
+static int
+namespace_table_flatten_helper (void **slot, void *arg)
+{
+  struct namespace *ns = (struct namespace *) *slot;
+  struct so_list *src = ns->solist;
+  struct so_list **link = (struct so_list **) arg;
+
+  while (*link)
+    link = &(*link)->next;
+
+  while (src != NULL)
+    {
+      struct so_list *dst;
+
+      dst = xmalloc (sizeof (struct so_list));
+      memcpy (dst, src, sizeof (struct so_list));
+
+      dst->lm_info = xmalloc (sizeof (struct lm_info));
+      memcpy (dst->lm_info, src->lm_info, sizeof (struct lm_info));
+
+      *link = dst;
+      link = &dst->next;
+
+      src = src->next;
+    }
+
+  *link = NULL;
+
+  return 1; /* Continue traversal.  */
+}
+
+/* Flatten the namespace table into a single list.  */
+
+static struct so_list *
+namespace_table_flatten (htab_t namespace_table)
+{
+  struct so_list *dst = NULL;
+
+  htab_traverse (namespace_table, namespace_table_flatten_helper, &dst);
+
+  return dst;
+}
+
+/* Helper function for svr4_update_solib_event_breakpoints.  */
+
+static int
+svr4_update_solib_event_breakpoint (struct breakpoint *b, void *arg)
+{
+  struct svr4_info *info = get_svr4_info ();
+  struct bp_location *loc;
+
+  if (b->type != bp_shlib_event)
+    return 0; /* Continue iterating.  */
+
+  for (loc = b->loc; loc; loc = loc->next)
+    {
+      struct probe_and_info buf, *pi;
+
+      pi = solib_event_probe_at (info, loc, &buf);
+      if (pi != NULL)
+	{
+	  if (pi->info->action == NAMESPACE_NO_ACTION)
+	    b->enable_state = (stop_on_solib_events
+			       ? bp_enabled : bp_disabled);
+
+	  return 0; /* Continue iterating.  */
+	}
+    }
+
+  return 0; /* Continue iterating.  */
+}
+
+/* Enable or disable optional solib event breakpoints as appropriate.
+   Called whenever stop_on_solib_events is changed.  */
+
+static void
+svr4_update_solib_event_breakpoints (void)
+{
+  struct svr4_info *info = get_svr4_info ();
+
+  if (info->using_probes)
+    iterate_over_breakpoints (svr4_update_solib_event_breakpoint, NULL);
+}
+
+/* Both the SunOS and the SVR4 dynamic linkers call a marker function
+   before and after mapping and unmapping shared libraries.  The sole
+   purpose of this method is to allow debuggers to set a breakpoint so
+   they can track these changes.
+
+   Some versions of the glibc dynamic linker contain named probes
+   to allow more fine grained stopping.  Given the address of the
+   original marker function, this function attempts to find these
+   probes, and if found, sets breakpoints on those instead.  If the
+   probes aren't found, a single breakpoint is set on the original
+   marker function.  */
+
+static void
+svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
+				     CORE_ADDR address)
+{
+  struct svr4_info *info = get_svr4_info ();
+  struct obj_section *os;
+
+  os = find_pc_section (address);
+  if (os != NULL)
+    {
+      int with_prefix;
+
+      for (with_prefix = 0; with_prefix <= 1; with_prefix++)
+	{
+	  int all_probes_found = 1;
+	  int i;
+
+	  for (i = 0; i < NUM_PROBES; i++)
+	    {
+	      char name[32] = { '\0' };
+
+	      /* Fedora 17, RHEL 6.2, and RHEL 6.3 shipped with an
+		 early version of the probes code in which the probes'
+		 names were prefixed with "rtld_".  The locations and
+		 arguments of the probes are otherwise the same, so we
+		 check for the prefixed version if the unprefixed
+		 probes are not found.  */
+
+	      if (with_prefix)
+		strncat (name, "rtld_", sizeof (name));
+
+	      strncat (name, probe_info[i].name, sizeof (name));
+
+	      info->probes[i] = find_probes_in_objfile (os->objfile, "rtld",
+							name);
+
+	      if (!VEC_length (probe_p, info->probes[i]))
+		{
+		  free_probes (info);
+		  all_probes_found = 0;
+		  break;
+		}
+	    }
+
+	  if (all_probes_found)
+	    {
+	      info->using_probes = 1;
+
+	      for (i = 0; i < NUM_PROBES; i++)
+		{
+		  struct probe *probe;
+		  int ix;
+
+		  for (ix = 0;
+		       VEC_iterate (probe_p, info->probes[i], ix, probe);
+		       ++ix)
+		    create_solib_event_breakpoint (gdbarch, probe->address);
+		}
+
+	      svr4_update_solib_event_breakpoints ();
+	      return;
+	    }
+	}
+    }
+
+  create_solib_event_breakpoint (gdbarch, address);
+}
+
 /* Helper function for gdb_bfd_lookup_symbol.  */
 
 static int
@@ -1452,6 +2096,9 @@
   info->interp_text_sect_low = info->interp_text_sect_high = 0;
   info->interp_plt_sect_low = info->interp_plt_sect_high = 0;
 
+  free_probes (info);
+  info->using_probes = 0;
+
   /* If we already have a shared library list in the target, and
      r_debug contains r_brk, set the breakpoint there - this should
      mean r_brk has already been relocated.  Assume the dynamic linker
@@ -1483,7 +2130,7 @@
 	 That knowledge is encoded in the address, if it's Thumb the low bit
 	 is 1.  However, we've stripped that info above and it's not clear
 	 what all the consequences are of passing a non-addr_bits_remove'd
-	 address to create_solib_event_breakpoint.  The call to
+	 address to svr4_create_solib_event_breakpoints.  The call to
 	 find_pc_section verifies we know about the address and have some
 	 hope of computing the right kind of breakpoint to use (via
 	 symbol info).  It does mean that GDB needs to be pointed at a
@@ -1521,7 +2168,7 @@
 		+ bfd_section_size (tmp_bfd, interp_sect);
 	    }
 
-	  create_solib_event_breakpoint (target_gdbarch, sym_addr);
+	  svr4_create_solib_event_breakpoints (target_gdbarch, sym_addr);
 	  return 1;
 	}
     }
@@ -1676,7 +2323,8 @@
 
       if (sym_addr != 0)
 	{
-	  create_solib_event_breakpoint (target_gdbarch, load_addr + sym_addr);
+	  svr4_create_solib_event_breakpoints (target_gdbarch,
+					       load_addr + sym_addr);
 	  xfree (interp_name);
 	  return 1;
 	}
@@ -1702,7 +2350,7 @@
 	  sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch,
 							 sym_addr,
 							 &current_target);
-	  create_solib_event_breakpoint (target_gdbarch, sym_addr);
+	  svr4_create_solib_event_breakpoints (target_gdbarch, sym_addr);
 	  return 1;
 	}
     }
@@ -1718,7 +2366,7 @@
 	      sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch,
 							     sym_addr,
 							     &current_target);
-	      create_solib_event_breakpoint (target_gdbarch, sym_addr);
+	      svr4_create_solib_event_breakpoints (target_gdbarch, sym_addr);
 	      return 1;
 	    }
 	}
@@ -2228,6 +2876,9 @@
 
   info = get_svr4_info ();
 
+  /* Free the probes-based interface's namespace table.  */
+  free_namespace_table (info);
+
   /* Relocate the main executable if necessary.  */
   svr4_relocate_main_executable ();
 
@@ -2494,4 +3145,6 @@
   svr4_so_ops.lookup_lib_global_symbol = elf_lookup_lib_symbol;
   svr4_so_ops.same = svr4_same;
   svr4_so_ops.keep_data_in_core = svr4_keep_data_in_core;
+  svr4_so_ops.handle_solib_event = svr4_handle_solib_event;
+  svr4_so_ops.update_breakpoints = svr4_update_solib_event_breakpoints;
 }
diff --git a/gdb/testsuite/gdb.base/break-dlmopen-solib.c b/gdb/testsuite/gdb.base/break-dlmopen-solib.c
new file mode 100644
index 0000000..9979ee7
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-dlmopen-solib.c
@@ -0,0 +1,24 @@
+/* Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+
+int
+foo (int n)
+{
+  printf ("foo %d\n", n);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/break-dlmopen.c b/gdb/testsuite/gdb.base/break-dlmopen.c
new file mode 100644
index 0000000..bfe6f3e
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-dlmopen.c
@@ -0,0 +1,58 @@
+/* Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#define _GNU_SOURCE
+#include <dlfcn.h>
+
+void
+stop ()
+{
+}
+
+int
+main ()
+{
+  void *handle1, *handle2, *handle3;
+  void (*func)(int);
+
+  handle1 = dlmopen (LM_ID_NEWLM, SHLIB_NAME, RTLD_LAZY);
+  stop ();
+
+  func = (void (*)(int)) dlsym (handle1, "foo");
+  func (1);
+
+  handle2 = dlmopen (LM_ID_NEWLM, SHLIB_NAME, RTLD_LAZY);
+  stop ();
+
+  func = (void (*)(int)) dlsym (handle2, "foo");
+  func (2);
+
+  handle3 = dlopen (SHLIB_NAME, RTLD_LAZY);
+  stop ();
+
+  func = (void (*)(int)) dlsym (handle3, "foo");
+  func (3);
+
+  dlclose (handle1);
+  stop ();
+
+  dlclose (handle2);
+  stop ();
+
+  dlclose (handle3);
+  stop ();
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/break-dlmopen.exp b/gdb/testsuite/gdb.base/break-dlmopen.exp
new file mode 100644
index 0000000..e9be571
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-dlmopen.exp
@@ -0,0 +1,125 @@
+# Copyright 2012 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if { [skip_shlib_tests] || [is_remote target] } {
+    return 0
+}
+
+standard_testfile
+
+set libname $testfile-solib
+set srcfile_lib $srcdir/$subdir/$libname.c
+set binfile_lib [standard_output_file $libname.so]
+
+set normal_bp "_dl_debug_state"
+set probes_bp "dl_main"
+
+if { [gdb_compile_shlib $srcfile_lib $binfile_lib \
+	  [list additional_flags=-fPIC]] != "" } {
+    untested "Could not compile $binfile_lib."
+    return -1
+}
+
+if { [prepare_for_testing $testfile.exp $testfile $srcfile \
+	  [list additional_flags=-DSHLIB_NAME\=\"$binfile_lib\" libs=-ldl]] } {
+    return -1
+}
+
+# Run "info sharedlibrary" and check our library is shown the expected
+# number of times.
+proc check_info_shared { test expect } {
+    global libname
+    global gdb_prompt
+
+    set actual 0
+
+    gdb_test_multiple "info sharedlibrary" $test {
+	-re $libname {
+	    incr actual 1
+	    exp_continue
+	}
+	-re "\r\n$gdb_prompt $" {
+	    if { $actual == $expect } {
+		pass $test
+	    } else {
+		fail $test
+	    }
+	}
+    }
+}
+
+# Enable stop-on-solib-events
+gdb_test_no_output "set stop-on-solib-events 1"
+
+# Run to the first stop
+gdb_test "run" ".*Stopped due to shared library event.*"
+
+# XFAIL if we are not using probes
+set test "ensure using probes"
+set using_probes 0
+gdb_test_multiple "bt" $test {
+    -re "#0 +\[^\r\n\]*\\m(__GI_)?$normal_bp\\M.*$gdb_prompt $" {
+	xfail $test
+    }
+    -re "#0 +\[^\r\n\]*\\m(__GI_)?$probes_bp\\M.*$gdb_prompt $" {
+	pass $test
+	set using_probes 1
+    }
+}
+
+if { $using_probes } {
+    # Set up breakpoints.
+    gdb_test_no_output "set stop-on-solib-events 0"
+    gdb_test "break stop" {Breakpoint [0-9]+ at .*}
+    gdb_test_no_output "set breakpoint pending on"
+    gdb_test "break foo" {Breakpoint [0-9]+ \(foo\) pending\.}
+
+    # Check our library isn't loaded.
+    check_info_shared "info sharedlibrary #1" 0
+
+    # Run to the first stop and check our library loaded.
+    gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+    check_info_shared "info sharedlibrary #2" 1
+
+    # The next stop should be the function in the library.
+    gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
+
+    # Run to the next stop and check our library is now loaded twice.
+    gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+    check_info_shared "info sharedlibrary #3" 2
+
+    # The next stop should be the function in the library.
+    gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
+
+    # Run to the next stop and check our library is now loaded three
+    # times.
+    gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+    check_info_shared "info sharedlibrary #4" 3
+
+    # The next stop should be the function in the library.
+    gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
+
+    # Run to the next stop and check our library is now loaded twice.
+    gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+    check_info_shared "info sharedlibrary #5" 2
+
+    # Run to the next stop and check our library is now loaded once.
+    gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+    check_info_shared "info sharedlibrary #6" 1
+
+    # Run to the next stop and check our library is not loaded.
+    gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+    check_info_shared "info sharedlibrary #7" 0
+}
diff --git a/gdb/testsuite/gdb.base/break-interp.exp b/gdb/testsuite/gdb.base/break-interp.exp
index 4012e66..7aa6537 100644
--- a/gdb/testsuite/gdb.base/break-interp.exp
+++ b/gdb/testsuite/gdb.base/break-interp.exp
@@ -109,12 +109,19 @@ proc strip_debug {dest} {
     }
 }
 
+# The marker function for the standard runtime linker interface is
+# _dl_debug_state.  The probes-based interface has no specific marker
+# function; the probe we will stop on (init_start) is in dl_main so we
+# check for that.
+
+set solib_bp {(_dl_debug_state|dl_main)}
+
 # Implementation of reach.
 
 proc reach_1 {func command displacement} {
-    global gdb_prompt expect_out
+    global gdb_prompt expect_out solib_bp
 
-    if {$func == "_dl_debug_state"} {
+    if {$func == $solib_bp} {
 	# Breakpoint on _dl_debug_state can have problems due to its overlap
 	# with the existing internal breakpoint from GDB.
 	gdb_test_no_output "set stop-on-solib-events 1"
@@ -142,21 +149,21 @@ proc reach_1 {func command displacement} {
 	    exp_continue
 	}
 	-re "Breakpoint \[0-9\]+, \\.?(__GI_)?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" {
-	    if {$func == "_dl_debug_state"} {
+	    if {$func == $solib_bp} {
 		fail $test
 	    } else {
 		pass $test
 	    }
 	}
 	-re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?(__GI_)?$func \\(\\).*\r\n$gdb_prompt $" {
-	    if {$func == "_dl_debug_state"} {
+	    if {$func == $solib_bp} {
 		fail $test
 	    } else {
 		pass $test
 	    }
 	}
 	-re "Stopped due to (spurious )?shared library event.*\r\n$gdb_prompt $" {
-	    if {$func == "_dl_debug_state"} {
+	    if {$func == $solib_bp} {
 		if {$debug_state_count == 0} {
 		    # First stop does not yet relocate the _start function
 		    # descriptor on ppc64.
@@ -175,7 +182,7 @@ proc reach_1 {func command displacement} {
 	fail $test_displacement
     }
 
-    if {$func == "_dl_debug_state"} {
+    if {$func == $solib_bp} {
 	gdb_test_no_output "set stop-on-solib-events 0"
     }
 }
@@ -357,7 +364,7 @@ proc test_attach {file displacement {relink_args ""}} {
 }
 
 proc test_ld {file ifmain trynosym displacement} {
-    global srcdir subdir gdb_prompt expect_out inferior_exited_re
+    global srcdir subdir gdb_prompt expect_out inferior_exited_re solib_bp
 
     # First test normal `file'-command loaded $FILE with symbols.
 
@@ -385,9 +392,9 @@ proc test_ld {file ifmain trynosym displacement} {
 	gdb_test_no_output "set args ${objdir}/${subdir}/$binfile_test" "set args OBJDIR/${subdir}/$binfile_test"
     }
 
-    reach "_dl_debug_state" "run" $displacement
+    reach $solib_bp "run" $displacement
 
-    gdb_test "bt" "#0 +\[^\r\n\]*\\m(__GI_)?_dl_debug_state\\M.*" "dl bt"
+    gdb_test "bt" "#0 +\[^\r\n\]*\\m(__GI_)?$solib_bp\\M.*" "dl bt"
 
     if $ifmain {
 	reach "main" continue "NONE"
@@ -399,7 +406,7 @@ proc test_ld {file ifmain trynosym displacement} {
 
     # Try re-run if the new PIE displacement takes effect.
     gdb_test "kill" "" "kill" {Kill the program being debugged\? \(y or n\) } "y"
-    reach "_dl_debug_state" "run" $displacement
+    reach $solib_bp "run" $displacement
 
     if $ifmain {
 	test_core $file $displacement
@@ -431,7 +438,7 @@ proc test_ld {file ifmain trynosym displacement} {
 	gdb_test "exec-file $file" "exec-file $escapedfile" "load"
 
 	if $ifmain {
-	    reach "_dl_debug_state" run $displacement
+	    reach $solib_bp run $displacement
 
 	    # Use two separate gdb_test_multiple statements to avoid timeouts due
 	    # to slow processing of wildcard capturing long output
diff --git a/gdb/testsuite/gdb.base/break-probes-solib.c b/gdb/testsuite/gdb.base/break-probes-solib.c
new file mode 100644
index 0000000..9979ee7
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-probes-solib.c
@@ -0,0 +1,24 @@
+/* Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+
+int
+foo (int n)
+{
+  printf ("foo %d\n", n);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/break-probes.c b/gdb/testsuite/gdb.base/break-probes.c
new file mode 100644
index 0000000..a778099
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-probes.c
@@ -0,0 +1,26 @@
+/* Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <dlfcn.h>
+
+int
+main ()
+{
+  void *handle = dlopen (SHLIB_NAME, RTLD_LAZY);
+
+  dlclose (handle);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/break-probes.exp b/gdb/testsuite/gdb.base/break-probes.exp
new file mode 100644
index 0000000..a8dc373
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-probes.exp
@@ -0,0 +1,76 @@
+# Copyright 2012 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if { [skip_shlib_tests] || [is_remote target] } {
+    return 0
+}
+
+standard_testfile
+
+set libname $testfile-solib
+set srcfile_lib $srcdir/$subdir/$libname.c
+set binfile_lib [standard_output_file $libname.so]
+
+set normal_bp "_dl_debug_state"
+set probes_bp "dl_main"
+
+if { [gdb_compile_shlib $srcfile_lib $binfile_lib \
+	  [list additional_flags=-fPIC]] != "" } {
+    untested "Could not compile $binfile_lib."
+    return -1
+}
+
+if { [prepare_for_testing $testfile.exp $testfile $srcfile \
+	  [list additional_flags=-DSHLIB_NAME\=\"$binfile_lib\" libs=-ldl]] } {
+    return -1
+}
+
+# Enable stop-on-solib-events
+gdb_test_no_output "set stop-on-solib-events 1"
+
+# Run to the first stop
+gdb_test "run" ".*Stopped due to shared library event.*"
+
+# XFAIL if we are not using probes
+set test "ensure using probes"
+set using_probes 0
+gdb_test_multiple "bt" $test {
+    -re "#0 +\[^\r\n\]*\\m(__GI_)?$normal_bp\\M.*$gdb_prompt $" {
+	xfail $test
+    }
+    -re "#0 +\[^\r\n\]*\\m(__GI_)?$probes_bp\\M.*$gdb_prompt $" {
+	pass $test
+	set using_probes 1
+    }
+}
+
+if { $using_probes } {
+    # Run til it loads our library
+    set test "run til our library loads"
+    set loaded_library 0
+    while { !$loaded_library } {
+	gdb_test_multiple "c" $test {
+	    -re "Inferior loaded $binfile_lib\\M.*$gdb_prompt $" {
+		pass $test
+		set loaded_library 1
+	    }
+	    -re "Stopped due to shared library event\\M.*$gdb_prompt $" {
+	    }
+	}
+    }
+
+    # Call something to ensure that relocation occurred
+    gdb_test "call foo(23)" "foo 23.*\\\$.* = .*"
+}
diff --git a/gdb/testsuite/gdb.base/info-shared-solib1.c b/gdb/testsuite/gdb.base/info-shared-solib1.c
new file mode 100644
index 0000000..9979ee7
--- /dev/null
+++ b/gdb/testsuite/gdb.base/info-shared-solib1.c
@@ -0,0 +1,24 @@
+/* Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+
+int
+foo (int n)
+{
+  printf ("foo %d\n", n);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/info-shared-solib2.c b/gdb/testsuite/gdb.base/info-shared-solib2.c
new file mode 100644
index 0000000..d4ed1e6
--- /dev/null
+++ b/gdb/testsuite/gdb.base/info-shared-solib2.c
@@ -0,0 +1,24 @@
+/* Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+
+int
+bar (int n)
+{
+  printf ("bar %d\n", n);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/info-shared.c b/gdb/testsuite/gdb.base/info-shared.c
new file mode 100644
index 0000000..d699a11
--- /dev/null
+++ b/gdb/testsuite/gdb.base/info-shared.c
@@ -0,0 +1,48 @@
+/* Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <dlfcn.h>
+
+void
+stop ()
+{
+}
+
+int
+main ()
+{
+  void *handle1, *handle2;
+  void (*func)(int);
+
+  handle1 = dlopen (SHLIB1_NAME, RTLD_LAZY);
+  stop ();
+
+  handle2 = dlopen (SHLIB2_NAME, RTLD_LAZY);
+  stop ();
+
+  func = (void (*)(int)) dlsym (handle1, "foo");
+  func (1);
+
+  func = (void (*)(int)) dlsym (handle2, "bar");
+  func (2);
+
+  dlclose (handle1);
+  stop ();
+
+  dlclose (handle2);
+  stop ();
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/info-shared.exp b/gdb/testsuite/gdb.base/info-shared.exp
new file mode 100644
index 0000000..70a1816
--- /dev/null
+++ b/gdb/testsuite/gdb.base/info-shared.exp
@@ -0,0 +1,139 @@
+# Copyright 2012 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if { [skip_shlib_tests] || [is_remote target] } {
+    return 0
+}
+
+standard_testfile
+
+set lib1name $testfile-solib1
+set srcfile_lib1 $srcdir/$subdir/$lib1name.c
+set binfile_lib1 [standard_output_file $lib1name.so]
+set define1 -DSHLIB1_NAME\=\"$binfile_lib1\"
+
+set lib2name $testfile-solib2
+set srcfile_lib2 $srcdir/$subdir/$lib2name.c
+set binfile_lib2 [standard_output_file $lib2name.so]
+set define2 -DSHLIB2_NAME\=\"$binfile_lib2\"
+
+if { [gdb_compile_shlib $srcfile_lib1 $binfile_lib1 \
+	  [list additional_flags=-fPIC]] != "" } {
+    untested "Could not compile $binfile_lib1."
+    return -1
+}
+
+if { [gdb_compile_shlib $srcfile_lib2 $binfile_lib2 \
+	  [list additional_flags=-fPIC]] != "" } {
+    untested "Could not compile $binfile_lib2."
+    return -1
+}
+
+set cflags "$define1 $define2"
+if { [prepare_for_testing $testfile.exp $testfile $srcfile \
+	  [list additional_flags=$cflags libs=-ldl]] } {
+    return -1
+}
+
+# Run "info sharedlibrary" and check for the presence or absence of
+# our libraries.
+proc check_info_shared { test expect1 expect2 } {
+    global lib1name
+    global lib2name
+    global gdb_prompt
+
+    set actual1 0
+    set actual2 0
+
+    gdb_test_multiple "info sharedlibrary" $test {
+	-re $lib1name {
+	    set actual1 1
+	    exp_continue
+	}
+	-re $lib2name {
+	    set actual2 1
+	    exp_continue
+	}
+	-re "\r\n$gdb_prompt $" {
+	    if { $actual1 == $expect1 && $actual2 == $expect2 } {
+		pass $test
+	    } else {
+		fail $test
+	    }
+	}
+    }
+}
+
+# Set up breakpoints.
+gdb_test "break stop" {Breakpoint [0-9]+ at .*}
+gdb_test_no_output "set breakpoint pending on"
+gdb_test "break foo" {Breakpoint [0-9]+ \(foo\) pending\.}
+gdb_test "break bar" {Breakpoint [0-9]+ \(bar\) pending\.}
+
+# Check neither of the libraries are loaded at the start.
+gdb_test "start" {Temporary breakpoint [0-9]+, .* in main \(\)}
+check_info_shared "info sharedlibrary #1" 0 0
+
+# Run to the first stop and check that only the first library is loaded.
+gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+check_info_shared "info sharedlibrary #2" 1 0
+
+# Run to the second stop and check that both libraries are loaded.
+gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+check_info_shared "info sharedlibrary #3" 1 1
+
+# Check that the next stop is in foo.
+gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
+
+# Check that the next stop is in bar.
+gdb_test "c" {Breakpoint [0-9]+, .* in bar \(\) from .*}
+
+# Restart the inferior and make sure there are no breakpoint reset
+# errors.  These can happen with the probes-based runtime linker
+# interface if the cache is not cleared correctly.
+set test "restart"
+gdb_test_multiple "run" $test {
+    -re {Start it from the beginning\? \(y or n\) } {
+	send_gdb "y\n"
+	exp_continue
+    }
+    -re {Error in re-setting breakpoint} {
+	fail $test
+    }
+    -re "\r\n$gdb_prompt $" {
+	pass $test
+    }
+}
+
+# We're at the first stop.  Check that only the first library is loaded.
+check_info_shared "info sharedlibrary #4" 1 0
+
+# Run to the second stop and check that both libraries are loaded.
+gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+check_info_shared "info sharedlibrary #5" 1 1
+
+# Check that the next stop is in foo.
+gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
+
+# Check that the next stop is in bar.
+gdb_test "c" {Breakpoint [0-9]+, .* in bar \(\) from .*}
+
+# Run to the next stop and check that the first library has been unloaded.
+gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+check_info_shared "info sharedlibrary #6" 0 1
+
+# Run to the last stop and check that both libraries are gone.
+gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+check_info_shared "info sharedlibrary #7" 0 0

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-07-19 11:09 [RFA 4/4 take 2] Improved linker-debugger interface Gary Benson
@ 2012-07-25 19:36 ` Tom Tromey
  2012-07-31 12:12   ` Gary Benson
  2012-08-15 17:24 ` Jan Kratochvil
  1 sibling, 1 reply; 19+ messages in thread
From: Tom Tromey @ 2012-07-25 19:36 UTC (permalink / raw)
  To: gdb-patches

>>>>> "Gary" == Gary Benson <gbenson@redhat.com> writes:

Gary> +static struct probe_and_info *
Gary> +solib_event_probe_at (struct svr4_info *info, struct bp_location *loc,
Gary> +		      struct probe_and_info *result)

I think this would be clearer if it just returned a boolean.

Gary> +  if (probe_argc == 2)
Gary> +    action = NAMESPACE_RELOAD;
Gary> +  else if (probe_argc < 2)
Gary> +    return NAMESPACE_TABLE_INVALIDATE;
Gary> +
Gary> +  return action;

Perhaps that first 'return' could be an assignment to 'action'.

Gary> +static hashval_t
Gary> +hash_namespace (const PTR p)

Use 'void *' instead of PTR.  This occurs in a few spots.
PTR is obsolete.

Gary> +  const struct namespace *ns = (const struct namespace *) p;

You don't need a cast here.

Gary> +  const struct namespace *ns1 = (const struct namespace *) p1;
Gary> +  const struct namespace *ns2 = (const struct namespace *) p2;

Here either.

Gary> +  struct namespace *ns = (struct namespace *) p;

Here either.

Gary> +      ns = xcalloc (sizeof (struct namespace), 1);

I think it is more normal to use XCNEW (struct namespace) here.
xcalloc with 1 element is "funny".
There's a lot of odd little macros like this, used inconsistently...


The rest of the patch looks good to me.
However, I think we should refrain from putting it in until the probes
go in to glibc.  If this makes a chicken-and-egg problem somehow, we can
suggest simultaneous approval or the like.

Tom


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-07-25 19:36 ` Tom Tromey
@ 2012-07-31 12:12   ` Gary Benson
  2012-07-31 12:13     ` Gary Benson
  0 siblings, 1 reply; 19+ messages in thread
From: Gary Benson @ 2012-07-31 12:12 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

Tom Tromey wrote:
> >>>>> "Gary" == Gary Benson <gbenson@redhat.com> writes:
> 
> Gary> +static struct probe_and_info *
> Gary> +solib_event_probe_at (struct svr4_info *info, struct bp_location *loc,
> Gary> +		      struct probe_and_info *result)
> 
> I think this would be clearer if it just returned a boolean.
> 
> Gary> +  if (probe_argc == 2)
> Gary> +    action = NAMESPACE_RELOAD;
> Gary> +  else if (probe_argc < 2)
> Gary> +    return NAMESPACE_TABLE_INVALIDATE;
> Gary> +
> Gary> +  return action;
> 
> Perhaps that first 'return' could be an assignment to 'action'.
> 
> Gary> +static hashval_t
> Gary> +hash_namespace (const PTR p)
> 
> Use 'void *' instead of PTR.  This occurs in a few spots.
> PTR is obsolete.
> 
> Gary> +  const struct namespace *ns = (const struct namespace *) p;
> 
> You don't need a cast here.
> 
> Gary> +  const struct namespace *ns1 = (const struct namespace *) p1;
> Gary> +  const struct namespace *ns2 = (const struct namespace *) p2;
> 
> Here either.
> 
> Gary> +  struct namespace *ns = (struct namespace *) p;
> 
> Here either.
> 
> Gary> +      ns = xcalloc (sizeof (struct namespace), 1);
> 
> I think it is more normal to use XCNEW (struct namespace) here.
> xcalloc with 1 element is "funny".  There's a lot of odd little
> macros like this, used inconsistently...

Attached is an updated version of this patch with these fixes.

> The rest of the patch looks good to me.  However, I think we should
> refrain from putting it in until the probes go in to glibc.  If this
> makes a chicken-and-egg problem somehow, we can suggest simultaneous
> approval or the like.

Probes are in glibc as of Friday:

  http://sourceware.org/ml/libc-alpha/2012-07/msg00557.html

Cheers,
Gary

-- 
http://gbenson.net/


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-07-31 12:12   ` Gary Benson
@ 2012-07-31 12:13     ` Gary Benson
  2012-08-14 19:49       ` Tom Tromey
  0 siblings, 1 reply; 19+ messages in thread
From: Gary Benson @ 2012-07-31 12:13 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 151 bytes --]

Gary Benson wrote:
> Attached is an updated version of this patch with these fixes.

Really attached this time.

Thanks,
Gary

-- 
http://gbenson.net/

[-- Attachment #2: rtld-stap-6.patch --]
[-- Type: text/plain, Size: 60377 bytes --]

gdb/
2012-07-30  Gary Benson  <gbenson@redhat.com>

	* breakpoint.h (handle_solib_event): Moved function definition
	to solib.h, and added a new parameter.
	* breakpoint.c (handle_solib_event): Moved function to solib.c
	and added a new parameter.
	(bpstat_stop_status): Pass new argument to handle_solib_event.
	* solib.h (breakpoint.h): New include.
	(handle_solib_event): Moved function definition from breakpoint.h
	and added a new parameter.
	(update_solib_breakpoints): New function definition.
	* solib.c (handle_solib_event): Moved function from breakpoint.c
	and added a new parameter.
	(update_solib_breakpoints): New function.
	* solist.h (breakpoint.h): New include.
	(target_so_ops): New fields "handle_solib_event" and
	"update_breakpoints".
	* infrun.c (set_stop_on_solib_events): New function.
	(_initialize_infrun): Use the above for "set stop-on-solib-events".
	(handle_inferior_event): Pass new argument to handle_solib_event.
	* solib-svr4.c (probe.h): New include.
	(namespace_table_flatten): New forward declaration.
	(lm_info): New fields "lmid" and "in_initial_ns".
	(probe_action): New enum.
	(probe_info): New struct.
	(probe_info): New static variable.
	(NUM_PROBES): New definition.
	(svr4_info): New fields  "using_probes", "probes" and
	"namespace_table".
	(free_probes): New function.
	(free_namespace_table): Likewise.
	(svr4_pspace_data_cleanup): Free probes and namespace table.
	(svr4_same): Also compare namespaces if using probes.
	(lm_addr_check): Only print .dynamic section at wrong address
	warning for initial namespace if using probes.
	(r_map_from_debug_base): New function.
	(solib_svr4_r_map): Call the above.
	(svr4_read_so_list): New parameter "prev_lm".
	Changed	return type from void to int.
	Return nonzero on success, zero on error.
	(svr4_current_sos_from_debug_base): New function.
	(svr4_current_sos): Create result from namespace table if available.
	Use svr4_current_sos_from_debug_base to generate list otherwise.
	(probe_and_info): New struct.
	(solib_event_probe_at): New function.
	(solib_event_probe_action): Likewise.
	(namespace): New struct.
	(hash_namespace): New function.
	(equal_namespace): Likewise.
	(free_namespace): Likewise.
	(namespace_update_full): Likewise.
	(namespace_update_incremental): Likewise.
	(svr4_handle_solib_event): Likewise.
	(namespace_table_flatten_helper): Likewise.
	(namespace_table_flatten): Likewise.
	(svr4_update_solib_event_breakpoint): Likewise.
	(svr4_update_solib_event_breakpoints): Likewise.
	(svr4_create_solib_event_breakpoints): Likewise.
	(enable_break): Free probes before creating breakpoints.
	Use svr4_create_solib_event_breakpoints to create breakpoints.
	(svr4_solib_create_inferior_hook): Free the namespace table.
	(_initialize_svr4_solib): Initialise svr4_so_ops.handle_solib_event
	and svr4_so_ops.update_breakpoints.

gdb/testsuite
2012-07-30  Gary Benson  <gbenson@redhat.com>

	* gdb.base/break-interp.exp (solib_bp): New constant.
	(reach_1): Use the above instead of "_dl_debug_state".
	(test_attach): Likewise.
	(test_ld): Likewise.
	* gdb.base/break-probes.exp: New file.
	* gdb.base/break-probes.c: Likewise.
	* gdb.base/break-probes-solib.c: Likewise.
	* gdb.base/info-shared.exp: New file.
	* gdb.base/info-shared.c: Likewise.
	* gdb.base/info-shared-solib1.c: Likewise.
	* gdb.base/info-shared-solib2.c: Likewise.
	* gdb.base/break-dlmopen.exp: Likewise.
	* gdb.base/break-dlmopen.c: Likewise.
	* gdb.base/break-dlmopen-solib.c: Likewise.

diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 4e4f875..f678702 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1515,6 +1515,4 @@ extern int user_breakpoint_p (struct breakpoint *);
 /* Attempt to determine architecture of location identified by SAL.  */
 extern struct gdbarch *get_sal_arch (struct symtab_and_line sal);
 
-extern void handle_solib_event (void);
-
 #endif /* !defined (BREAKPOINT_H) */
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 6b9faf3..51c98a7 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5205,7 +5205,7 @@ bpstat_stop_status (struct address_space *aspace,
     {
       if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event)
 	{
-	  handle_solib_event ();
+	  handle_solib_event (bs);
 	  break;
 	}
     }
@@ -5301,25 +5301,6 @@ handle_jit_event (void)
   target_terminal_inferior ();
 }
 
-/* Handle an solib event by calling solib_add.  */
-
-void
-handle_solib_event (void)
-{
-  clear_program_space_solib_cache (current_inferior ()->pspace);
-
-  /* Check for any newly added shared libraries if we're supposed to
-     be adding them automatically.  Switch terminal for any messages
-     produced by breakpoint_re_set.  */
-  target_terminal_ours_for_output ();
-#ifdef SOLIB_ADD
-  SOLIB_ADD (NULL, 0, &current_target, auto_solib_add);
-#else
-  solib_add (NULL, 0, &current_target, auto_solib_add);
-#endif
-  target_terminal_inferior ();
-}
-
 /* Prepare WHAT final decision for infrun.  */
 
 /* Decide what infrun needs to do with this bpstat.  */
diff --git a/gdb/solib.h b/gdb/solib.h
index 7a2ff84..6e92ddc 100644
--- a/gdb/solib.h
+++ b/gdb/solib.h
@@ -21,6 +21,9 @@
 #ifndef SOLIB_H
 #define SOLIB_H
 
+/* For bpstat.  */
+#include "breakpoint.h"
+
 /* Forward decl's for prototypes */
 struct so_list;
 struct target_ops;
@@ -91,4 +94,15 @@ extern CORE_ADDR gdb_bfd_lookup_symbol_from_symtab (bfd *abfd,
 								      void *),
 						    void *data);
 
+/* Handle an solib event by calling solib_add.  Targets which handle
+   solib events using breakpoints must pass a valid bpstat.  Targets
+   which handle solib events using some other mechanism should pass
+   NULL.  */
+
+extern void handle_solib_event (bpstat bs);
+
+/* Enable or disable optional solib event breakpoints as appropriate.  */
+
+extern void update_solib_breakpoints (void);
+
 #endif /* SOLIB_H */
diff --git a/gdb/solib.c b/gdb/solib.c
index 90439ba..072fe4d 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1209,6 +1209,42 @@ no_shared_libraries (char *ignored, int from_tty)
   objfile_purge_solibs ();
 }
 
+/* See solib.h.  */
+
+void
+handle_solib_event (bpstat bs)
+{
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
+
+  if (ops->handle_solib_event != NULL)
+    ops->handle_solib_event (bs);
+
+  clear_program_space_solib_cache (current_inferior ()->pspace);
+
+  /* Check for any newly added shared libraries if we're supposed to
+     be adding them automatically.  Switch terminal for any messages
+     produced by breakpoint_re_set.  */
+  target_terminal_ours_for_output ();
+#ifdef SOLIB_ADD
+  SOLIB_ADD (NULL, 0, &current_target, auto_solib_add);
+#else
+  solib_add (NULL, 0, &current_target, auto_solib_add);
+#endif
+  target_terminal_inferior ();
+}
+
+/* See solib.h.  */
+
+void
+update_solib_breakpoints (void)
+{
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
+
+  if (ops->update_breakpoints != NULL)
+    ops->update_breakpoints ();
+}
+
+
 /* Reload shared libraries, but avoid reloading the same symbol file
    we already have loaded.  */
 
diff --git a/gdb/solist.h b/gdb/solist.h
index 7413e3b..ea580a9 100644
--- a/gdb/solist.h
+++ b/gdb/solist.h
@@ -23,6 +23,8 @@
 #define SO_NAME_MAX_PATH_SIZE 512	/* FIXME: Should be dynamic */
 /* For domain_enum domain.  */
 #include "symtab.h"
+/* For bpstat.  */
+#include "breakpoint.h"
 
 /* Forward declaration for target specific link map information.  This
    struct is opaque to all but the target specific file.  */
@@ -149,6 +151,20 @@ struct target_so_ops
        core file (in particular, for readonly sections).  */
     int (*keep_data_in_core) (CORE_ADDR vaddr,
 			      unsigned long size);
+
+    /* Target-specific handling of solib events.  For targets which
+       handle solib events using breakpoints a valid bpstat must be
+       passed.  Targets which handle solib events using some other
+       mechanism should pass NULL.  This pointer can be NULL, in which
+       case no specific handling is necessary for this target.  */
+    void (*handle_solib_event) (bpstat bs);
+
+    /* Enable or disable optional solib event breakpoints as
+       appropriate.  This should be called whenever
+       stop_on_solib_events is changed.  This pointer can be
+       NULL, in which case no enabling or disabling is necessary
+       for this target.  */
+    void (*update_breakpoints) (void);
   };
 
 /* Free the memory associated with a (so_list *).  */
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 11f981f..7c621ca 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -361,6 +361,16 @@ static struct symbol *step_start_function;
 /* Nonzero if we want to give control to the user when we're notified
    of shared library events by the dynamic linker.  */
 int stop_on_solib_events;
+
+/* Enable or disable optional shared library event breakpoints
+   as appropriate when the above flag is changed.  */
+
+static void
+set_stop_on_solib_events (char *args, int from_tty, struct cmd_list_element *c)
+{
+  update_solib_breakpoints ();
+}
+
 static void
 show_stop_on_solib_events (struct ui_file *file, int from_tty,
 			   struct cmd_list_element *c, const char *value)
@@ -3308,7 +3318,7 @@ handle_inferior_event (struct execution_control_state *ecs)
 	    context_switch (ecs->ptid);
 	  regcache = get_thread_regcache (ecs->ptid);
 
-	  handle_solib_event ();
+	  handle_solib_event (NULL);
 
 	  ecs->event_thread->control.stop_bpstat
 	    = bpstat_stop_status (get_regcache_aspace (regcache),
@@ -7204,7 +7214,7 @@ Show stopping for shared library events."), _("\
 If nonzero, gdb will give control to the user when the dynamic linker\n\
 notifies gdb of shared library events.  The most common event of interest\n\
 to the user would be loading/unloading of a new library."),
-			    NULL,
+			    set_stop_on_solib_events,
 			    show_stop_on_solib_events,
 			    &setlist, &showlist);
 
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 8e41f19..8298b42 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -47,9 +47,12 @@
 #include "auxv.h"
 #include "exceptions.h"
 
+#include "probe.h"
+
 static struct link_map_offsets *svr4_fetch_link_map_offsets (void);
 static int svr4_have_link_map_offsets (void);
 static void svr4_relocate_main_executable (void);
+static struct so_list *namespace_table_flatten (htab_t namespace_table);
 
 /* Link map info to include in an allocated so_list entry.  */
 
@@ -70,6 +73,16 @@
 
     /* Values read in from inferior's fields of the same name.  */
     CORE_ADDR l_ld, l_next, l_prev, l_name;
+
+    /* Numeric link-map ID of the namespace this object is loaded
+       into.  This value is only valid when using the probes-based
+       interface.  */
+    LONGEST lmid;
+
+    /* Nonzero if the namespace list this object is loaded into is the
+       application's initial namespace (LM_ID_BASE).  This value is
+       only valid when using the probes-based interface.  */
+    unsigned int in_initial_ns : 1;
   };
 
 /* On SVR4 systems, a list of symbols in the dynamic linker where
@@ -106,6 +119,53 @@
   NULL
 };
 
+/* What to do with the namespace table when a probe stop occurs.  */
+
+enum probe_action
+  {
+    /* Something went seriously wrong.  Stop using probes and
+       revert to using the older interface.  */
+    NAMESPACE_TABLE_INVALIDATE,
+
+    /* No action is required.  This namespace is still valid.  */
+    NAMESPACE_NO_ACTION,
+
+    /* This namespace should be reloaded entirely.  */
+    NAMESPACE_RELOAD,
+
+    /* Attempt to incrementally update this namespace. If the
+       update fails or is not possible, fall back to reloading
+       the namespace in full.  */
+    NAMESPACE_UPDATE_OR_RELOAD,
+  };
+
+/* A probe's name and its associated action.  */
+
+struct probe_info
+{
+  /* The name of the probe.  */
+  const char *name;
+
+  /* What to do with the namespace table when a probe stop occurs.  */
+  enum probe_action action;
+};
+
+/* A list of named probes and their associated actions.  If all
+   probes are present in the dynamic linker then the probes-based
+   interface will be used.  */
+
+static const struct probe_info probe_info[] =
+{
+  { "init_start", NAMESPACE_NO_ACTION },
+  { "init_complete", NAMESPACE_RELOAD },
+  { "map_start", NAMESPACE_NO_ACTION },
+  { "reloc_complete", NAMESPACE_UPDATE_OR_RELOAD },
+  { "unmap_start", NAMESPACE_NO_ACTION },
+  { "unmap_complete", NAMESPACE_RELOAD },
+};
+
+#define NUM_PROBES ARRAY_SIZE (probe_info)
+
 /* Per pspace SVR4 specific data.  */
 
 struct svr4_info
@@ -128,17 +188,58 @@
   CORE_ADDR interp_text_sect_high;
   CORE_ADDR interp_plt_sect_low;
   CORE_ADDR interp_plt_sect_high;
+
+  /* Nonzero if we are using the probes-based interface.  */
+  unsigned int using_probes : 1;
+
+  /* Named probes in the dynamic linker.  */
+  VEC (probe_p) *probes[NUM_PROBES];
+
+  /* Table of dynamic linker namespaces, used by the probes-based
+     interface.  */
+  htab_t namespace_table;
 };
 
 /* Per-program-space data key.  */
 static const struct program_space_data *solib_svr4_pspace_data;
 
+/* Free any allocated probe vectors.  */
+
+static void
+free_probes (struct svr4_info *info)
+{
+  int i;
+
+  for (i = 0; i < NUM_PROBES; i++)
+    VEC_free (probe_p, info->probes[i]);
+
+  memset (info->probes, 0, sizeof (info->probes));
+}
+
+/* Free the namespace table.  */
+
+static void
+free_namespace_table (struct svr4_info *info)
+{
+  if (info->namespace_table == NULL)
+    return;
+
+  htab_delete (info->namespace_table);
+  info->namespace_table = NULL;
+}
+
 static void
 svr4_pspace_data_cleanup (struct program_space *pspace, void *arg)
 {
   struct svr4_info *info;
 
   info = program_space_data (pspace, solib_svr4_pspace_data);
+  if (info == NULL)
+    return;
+
+  free_probes (info);
+  free_namespace_table (info);
+
   xfree (info);
 }
 
@@ -187,10 +288,21 @@
   return 0;
 }
 
+/* Return non-zero if GDB and INFERIOR represent the same shared
+   library.  */
+
 static int
 svr4_same (struct so_list *gdb, struct so_list *inferior)
 {
-  return (svr4_same_1 (gdb->so_original_name, inferior->so_original_name));
+  struct svr4_info *info = get_svr4_info ();
+
+  if (info->using_probes)
+    {
+      if (gdb->lm_info->lmid != inferior->lm_info->lmid)
+	return 0;
+    }
+
+  return svr4_same_1 (gdb->so_original_name, inferior->so_original_name);
 }
 
 static struct lm_info *
@@ -321,18 +433,26 @@
 	    }
 	  else
 	    {
-	      /* There is no way to verify the library file matches.  prelink
-		 can during prelinking of an unprelinked file (or unprelinking
-		 of a prelinked file) shift the DYNAMIC segment by arbitrary
-		 offset without any page size alignment.  There is no way to
-		 find out the ELF header and/or Program Headers for a limited
-		 verification if it they match.  One could do a verification
-		 of the DYNAMIC segment.  Still the found address is the best
-		 one GDB could find.  */
-
-	      warning (_(".dynamic section for \"%s\" "
-			 "is not at the expected address "
-			 "(wrong library or version mismatch?)"), so->so_name);
+	      struct svr4_info *info = get_svr4_info ();
+
+	      if (!info->using_probes || so->lm_info->in_initial_ns)
+		{
+		  /* There is no way to verify the library file
+		     matches.  prelink can during prelinking of an
+		     unprelinked file (or unprelinking of a prelinked
+		     file) shift the DYNAMIC segment by arbitrary
+		     offset without any page size alignment.  There is
+		     no way to find out the ELF header and/or Program
+		     Headers for a limited verification if it they
+		     match.  One could do a verification of the
+		     DYNAMIC segment.  Still the found address is the
+		     best one GDB could find.  */
+
+		  warning (_(".dynamic section for \"%s\" "
+			     "is not at the expected address "
+			     "(wrong library or version mismatch?)"),
+			   so->so_name);
+		}
 	    }
 	}
 
@@ -774,16 +894,10 @@
   return info->debug_base;
 }
 
-/* Find the first element in the inferior's dynamic link map, and
-   return its address in the inferior.  Return zero if the address
-   could not be determined.
-
-   FIXME: Perhaps we should validate the info somehow, perhaps by
-   checking r_version for a known version number, or r_state for
-   RT_CONSISTENT.  */
+/* Read the r_map field from the supplied r_debug structure.  */
 
 static CORE_ADDR
-solib_svr4_r_map (struct svr4_info *info)
+r_map_from_debug_base (CORE_ADDR debug_base)
 {
   struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
   struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
@@ -792,13 +906,27 @@
 
   TRY_CATCH (ex, RETURN_MASK_ERROR)
     {
-      addr = read_memory_typed_address (info->debug_base + lmo->r_map_offset,
+      addr = read_memory_typed_address (debug_base + lmo->r_map_offset,
                                         ptr_type);
     }
   exception_print (gdb_stderr, ex);
   return addr;
 }
 
+/* Find the first element in the inferior's dynamic link map, and
+   return its address in the inferior.  Return zero if the address
+   could not be determined.
+
+   FIXME: Perhaps we should validate the info somehow, perhaps by
+   checking r_version for a known version number, or r_state for
+   RT_CONSISTENT.  */
+
+static CORE_ADDR
+solib_svr4_r_map (struct svr4_info *info)
+{
+  return r_map_from_debug_base (info->debug_base);
+}
+
 /* Find r_brk from the inferior's debug base.  */
 
 static CORE_ADDR
@@ -1163,15 +1291,17 @@
   return new;
 }
 
-/* Read the whole inferior libraries chain starting at address LM.  Add the
-   entries to the tail referenced by LINK_PTR_PTR.  Ignore the first entry if
-   IGNORE_FIRST and set global MAIN_LM_ADDR according to it.  */
+/* Read the whole inferior libraries chain starting at address LM.
+   Expect the first entry in the chain's previous entry to be PREV_LM.
+   Add the entries to the tail referenced by LINK_PTR_PTR.  Ignore the
+   first entry if IGNORE_FIRST and set global MAIN_LM_ADDR according
+   to it.  Returns nonzero upon success.  */
 
-static void
-svr4_read_so_list (CORE_ADDR lm, struct so_list ***link_ptr_ptr,
-		   int ignore_first)
+static int
+svr4_read_so_list (CORE_ADDR lm, CORE_ADDR prev_lm,
+		   struct so_list ***link_ptr_ptr, int ignore_first)
 {
-  CORE_ADDR prev_lm = 0, next_lm;
+  CORE_ADDR next_lm;
 
   for (; lm != 0; prev_lm = lm, lm = next_lm)
     {
@@ -1188,7 +1318,7 @@
       if (new->lm_info == NULL)
 	{
 	  do_cleanups (old_chain);
-	  break;
+	  return 0;
 	}
 
       next_lm = new->lm_info->l_next;
@@ -1199,7 +1329,7 @@
 		   paddress (target_gdbarch, prev_lm),
 		   paddress (target_gdbarch, new->lm_info->l_prev));
 	  do_cleanups (old_chain);
-	  break;
+	  return 0;
 	}
 
       /* For SVR4 versions, the first entry in the link map is for the
@@ -1245,20 +1375,61 @@
       **link_ptr_ptr = new;
       *link_ptr_ptr = &new->next;
     }
+
+  return 1;
 }
 
-/* Implement the "current_sos" target_so_ops method.  */
+/* Read the list of loaded libraries from the dynamic linker's base
+   structure.  */
 
 static struct so_list *
-svr4_current_sos (void)
+svr4_current_sos_from_debug_base (void)
 {
+  struct svr4_info *info = get_svr4_info ();
   CORE_ADDR lm;
   struct so_list *head = NULL;
   struct so_list **link_ptr = &head;
-  struct svr4_info *info;
   struct cleanup *back_to;
   int ignore_first;
+
+  gdb_assert (info->debug_base);
+
+  /* Assume that everything is a library if the dynamic loader was loaded
+     late by a static executable.  */
+  if (exec_bfd && bfd_get_section_by_name (exec_bfd, ".dynamic") == NULL)
+    ignore_first = 0;
+  else
+    ignore_first = 1;
+
+  back_to = make_cleanup (svr4_free_library_list, &head);
+
+  /* Walk the inferior's link map list, and build our list of
+     `struct so_list' nodes.  */
+  lm = solib_svr4_r_map (info);
+  if (lm)
+    svr4_read_so_list (lm, 0, &link_ptr, ignore_first);
+
+  /* On Solaris, the dynamic linker is not in the normal list of
+     shared objects, so make sure we pick it up too.  Having
+     symbol information for the dynamic linker is quite crucial
+     for skipping dynamic linker resolver code.  */
+  lm = solib_svr4_r_ldsomap (info);
+  if (lm)
+    svr4_read_so_list (lm, 0, &link_ptr, 0);
+
+  discard_cleanups (back_to);
+
+  return head;
+}
+
+/* Implement the "current_sos" target_so_ops method.  */
+
+static struct so_list *
+svr4_current_sos (void)
+{
+  struct svr4_info *info;
   struct svr4_library_list library_list;
+  struct so_list *result;
 
   /* Fall back to manual examination of the target if the packet is not
      supported or gdbserver failed to find DT_DEBUG.  gdb.server/solib-list.exp
@@ -1281,6 +1452,10 @@
 
   info = get_svr4_info ();
 
+  /* If we have a namespace table then return a flattened copy.  */
+  if (info->namespace_table != NULL)
+    return namespace_table_flatten (info->namespace_table);
+
   /* Always locate the debug struct, in case it has moved.  */
   info->debug_base = 0;
   locate_base (info);
@@ -1290,35 +1465,12 @@
   if (! info->debug_base)
     return svr4_default_sos ();
 
-  /* Assume that everything is a library if the dynamic loader was loaded
-     late by a static executable.  */
-  if (exec_bfd && bfd_get_section_by_name (exec_bfd, ".dynamic") == NULL)
-    ignore_first = 0;
-  else
-    ignore_first = 1;
-
-  back_to = make_cleanup (svr4_free_library_list, &head);
-
-  /* Walk the inferior's link map list, and build our list of
-     `struct so_list' nodes.  */
-  lm = solib_svr4_r_map (info);
-  if (lm)
-    svr4_read_so_list (lm, &link_ptr, ignore_first);
-
-  /* On Solaris, the dynamic linker is not in the normal list of
-     shared objects, so make sure we pick it up too.  Having
-     symbol information for the dynamic linker is quite crucial
-     for skipping dynamic linker resolver code.  */
-  lm = solib_svr4_r_ldsomap (info);
-  if (lm)
-    svr4_read_so_list (lm, &link_ptr, 0);
-
-  discard_cleanups (back_to);
+  result = svr4_current_sos_from_debug_base ();
 
-  if (head == NULL)
+  if (result == NULL)
     return svr4_default_sos ();
 
-  return head;
+  return result;
 }
 
 /* Get the address of the link_map for a given OBJFILE.  */
@@ -1400,6 +1552,498 @@
 					     targ);
 }
 
+/* A probe and its associated information structure.  */
+
+struct probe_and_info
+{
+  /* The probe.  */
+  struct probe *probe;
+
+  /* The probe_info from which the probe was created.  */
+  const struct probe_info *info;
+};
+
+/* Get the solib event probe at the specified location, and the
+   probe_info the probe was created with.  Fills in RESULT and
+   returns nonzero if a solib event probe was found at the
+   specified location.  Returns zero if no solib event probe
+   was found.  */
+
+static int
+solib_event_probe_at (struct svr4_info *info, struct bp_location *loc,
+		      struct probe_and_info *result)
+{
+  int i;
+
+  for (i = 0; i < NUM_PROBES; i++)
+    {
+      struct probe *probe;
+      int ix;
+
+      for (ix = 0; VEC_iterate (probe_p, info->probes[i], ix, probe); ++ix)
+	{
+	  if (loc->pspace == current_program_space
+	      && loc->address == probe->address)
+	    {
+	      result->info = &probe_info[i];
+	      result->probe = probe;
+
+	      return 1;
+	    }
+	}
+    }
+
+  return 0;
+}
+
+/* Decide what action to take when the specified solib event probe is
+   hit.  */
+
+static enum probe_action
+solib_event_probe_action (struct probe_and_info *pi)
+{
+  enum probe_action action;
+  unsigned probe_argc;
+
+  action = pi->info->action;
+  if (action == NAMESPACE_NO_ACTION || action == NAMESPACE_TABLE_INVALIDATE)
+    return action;
+
+  gdb_assert (action == NAMESPACE_RELOAD
+	      || action == NAMESPACE_UPDATE_OR_RELOAD);
+
+  /* Check that an appropriate number of arguments has been supplied.
+     We expect:
+       arg0: Lmid_t lmid (mandatory)
+       arg1: struct r_debug *debug_base (mandatory)
+       arg2: struct link_map *new (optional, for incremental updates)  */
+  probe_argc = get_probe_argument_count (pi->probe);
+  if (probe_argc == 2)
+    action = NAMESPACE_RELOAD;
+  else if (probe_argc < 2)
+    action = NAMESPACE_TABLE_INVALIDATE;
+
+  return action;
+}
+
+/* A namespace in the dynamic linker.  */
+
+struct namespace
+{
+  /* Numeric link-map ID of the namespace.  */
+  LONGEST lmid;
+
+  /* List of objects loaded into the namespace.  */
+  struct so_list *solist;
+};
+
+/* Returns a hash code for the namespace referenced by p.  */
+
+static hashval_t
+hash_namespace (const void *p)
+{
+  const struct namespace *ns = p;
+
+  return (hashval_t) ns->lmid;
+}
+
+/* Returns non-zero if the namespaces referenced by p1 and p2
+   are equal.  */
+
+static int
+equal_namespace (const void *p1, const void *p2)
+{
+  const struct namespace *ns1 = p1;
+  const struct namespace *ns2 = p2;
+
+  return ns1->lmid == ns2->lmid;
+}
+
+/* Free a namespace.  */
+
+static void
+free_namespace (void *p)
+{
+  struct namespace *ns = p;
+
+  svr4_free_library_list (ns->solist);
+  xfree (ns);
+}
+
+/* Populate this namespace by reading the entire list of shared
+   objects from the inferior.  Returns nonzero on success.  */
+
+static int
+namespace_update_full (struct svr4_info *info, LONGEST lmid,
+		       CORE_ADDR debug_base, int is_initial_ns)
+{
+  struct so_list *result = NULL, *so;
+  struct namespace lookup, *ns;
+  void **slot;
+
+  /* Read the list of shared objects from the inferior.  The
+     initial namespace requires extra processing and is handled
+     separately.  */
+  if (is_initial_ns)
+    {
+      result = svr4_current_sos_from_debug_base ();
+    }
+  else
+    {
+      CORE_ADDR lm = r_map_from_debug_base (debug_base);
+      struct so_list **link_ptr = &result;
+
+      if (!svr4_read_so_list (lm, 0, &link_ptr, 0))
+	return 0;
+    }
+
+  /* If the namespace is empty then delete it from the table.  */
+  if (result == NULL)
+    {
+      if (info->namespace_table != NULL)
+	{
+	  lookup.lmid = lmid;
+	  htab_remove_elt (info->namespace_table, &lookup);
+	}
+
+      return 1;
+    }
+
+  /* Fill in the link-map IDs and initial namespace flags.  */
+  for (so = result; so; so = so->next)
+    {
+      so->lm_info->lmid = lmid;
+      so->lm_info->in_initial_ns = is_initial_ns;
+    }
+
+  /* Create the namespace table, if necessary.  */
+  if (info->namespace_table == NULL)
+    {
+      info->namespace_table = htab_create_alloc (1, hash_namespace,
+						 equal_namespace,
+						 free_namespace,
+						 xcalloc, xfree);
+    }
+
+  /* Update the namespace table with our new list.  */
+  lookup.lmid = lmid;
+  slot = htab_find_slot (info->namespace_table, &lookup, INSERT);
+  if (*slot == HTAB_EMPTY_ENTRY)
+    {
+      ns = XCNEW (struct namespace);
+      ns->lmid = lmid;
+      *slot = ns;
+    }
+  else
+    {
+      ns = *slot;
+      svr4_free_library_list (ns->solist);
+    }
+  ns->solist = result;
+
+  return 1;
+}
+
+/* Update this namespace starting from the link-map entry passed by
+   the linker in the probe's third argument.  Returns nonzero if the
+   list was successfully updated, or zero to indicate failure.  */
+
+static int
+namespace_update_incremental (struct svr4_info *info, LONGEST lmid,
+			      CORE_ADDR lm, int is_initial_ns)
+{
+  struct namespace lookup, *ns;
+  struct so_list *tail, **link, *so;
+  struct value *val;
+
+  /* Find our namespace in the table.  */
+  if (info->namespace_table == NULL)
+    return 0;
+
+  lookup.lmid = lmid;
+  ns = htab_find (info->namespace_table, &lookup);
+  if (ns == NULL)
+    return 0;
+
+  /* Walk to the end of the list.  */
+  tail = ns->solist;
+  if (tail == NULL)
+    return 0;
+
+  while (tail->next)
+    tail = tail->next;
+  link = &tail->next;
+
+  /* Read the new objects.  */
+  if (!svr4_read_so_list (lm, tail->lm_info->lm_addr, &link, 0))
+    return 0;
+
+  /* Fill in the link-map IDs and initial namespace flags.  */
+  for (so = tail; so; so = so->next)
+    {
+      so->lm_info->lmid = lmid;
+      so->lm_info->in_initial_ns = is_initial_ns;
+    }
+
+  return 1;
+}
+
+/* Update the namespace table as appropriate when using the
+   probes-based linker interface.  Do nothing if using the
+   standard interface.  */
+
+static void
+svr4_handle_solib_event (bpstat bs)
+{
+  struct svr4_info *info = get_svr4_info ();
+  struct probe_and_info buf, *pi = &buf;
+  enum probe_action action;
+  struct value *val;
+  LONGEST lmid;
+  CORE_ADDR debug_base, lm = 0;
+  int is_initial_ns;
+
+  /* It is possible that this function will be called incorrectly
+     by the handle_solib_event in handle_inferior_event if GDB goes
+     fully multi-target.  */
+  gdb_assert (bs != NULL);
+
+  if (!info->using_probes)
+    return;
+
+  if (!solib_event_probe_at (info, bs->bp_location_at, pi))
+    goto error;
+
+  action = solib_event_probe_action (pi);
+  if (action == NAMESPACE_TABLE_INVALIDATE)
+    goto error;
+
+  if (action == NAMESPACE_NO_ACTION)
+    return;
+
+  val = evaluate_probe_argument (pi->probe, 0);
+  if (val == NULL)
+    goto error;
+
+  lmid = value_as_long (val);
+
+  val = evaluate_probe_argument (pi->probe, 1);
+  if (val == NULL)
+    goto error;
+
+  debug_base = value_as_address (val);
+  if (debug_base == 0)
+    goto error;
+
+  /* Always locate the debug struct, in case it moved.  */
+  info->debug_base = 0;
+  if (locate_base (info) == 0)
+    goto error;
+
+  is_initial_ns = (debug_base == info->debug_base);
+
+  if (action == NAMESPACE_UPDATE_OR_RELOAD)
+    {
+      val = evaluate_probe_argument (pi->probe, 2);
+      if (val != NULL)
+	lm = value_as_address (val);
+
+      if (lm == 0)
+	action = NAMESPACE_RELOAD;
+    }
+
+  if (action == NAMESPACE_UPDATE_OR_RELOAD)
+    {
+      if (namespace_update_incremental (info, lmid, lm, is_initial_ns))
+	return;
+
+      action = NAMESPACE_RELOAD;
+    }
+
+  gdb_assert (action == NAMESPACE_RELOAD);
+
+  if (namespace_update_full (info, lmid, debug_base, is_initial_ns))
+    return;
+
+ error:
+
+  /* We should never reach here, but if we do we disable the
+     probes interface and revert to the original interface.
+     We don't reset the breakpoints as the ones we've set up
+     are adequate.  */
+  warning (_("Probes-based dynamic linker interface failed.\n"
+	     "Reverting to original interface.\n"));
+
+  free_namespace_table (info);
+  free_probes (info);
+  info->using_probes = 0;
+}
+
+/* Helper function for namespace_table_flatten.  */
+
+static int
+namespace_table_flatten_helper (void **slot, void *arg)
+{
+  struct namespace *ns = (struct namespace *) *slot;
+  struct so_list *src = ns->solist;
+  struct so_list **link = (struct so_list **) arg;
+
+  while (*link)
+    link = &(*link)->next;
+
+  while (src != NULL)
+    {
+      struct so_list *dst;
+
+      dst = xmalloc (sizeof (struct so_list));
+      memcpy (dst, src, sizeof (struct so_list));
+
+      dst->lm_info = xmalloc (sizeof (struct lm_info));
+      memcpy (dst->lm_info, src->lm_info, sizeof (struct lm_info));
+
+      *link = dst;
+      link = &dst->next;
+
+      src = src->next;
+    }
+
+  *link = NULL;
+
+  return 1; /* Continue traversal.  */
+}
+
+/* Flatten the namespace table into a single list.  */
+
+static struct so_list *
+namespace_table_flatten (htab_t namespace_table)
+{
+  struct so_list *dst = NULL;
+
+  htab_traverse (namespace_table, namespace_table_flatten_helper, &dst);
+
+  return dst;
+}
+
+/* Helper function for svr4_update_solib_event_breakpoints.  */
+
+static int
+svr4_update_solib_event_breakpoint (struct breakpoint *b, void *arg)
+{
+  struct svr4_info *info = get_svr4_info ();
+  struct bp_location *loc;
+
+  if (b->type != bp_shlib_event)
+    return 0; /* Continue iterating.  */
+
+  for (loc = b->loc; loc; loc = loc->next)
+    {
+      struct probe_and_info buf, *pi = &buf;
+
+      if (solib_event_probe_at (info, loc, pi))
+	{
+	  if (pi->info->action == NAMESPACE_NO_ACTION)
+	    b->enable_state = (stop_on_solib_events
+			       ? bp_enabled : bp_disabled);
+
+	  return 0; /* Continue iterating.  */
+	}
+    }
+
+  return 0; /* Continue iterating.  */
+}
+
+/* Enable or disable optional solib event breakpoints as appropriate.
+   Called whenever stop_on_solib_events is changed.  */
+
+static void
+svr4_update_solib_event_breakpoints (void)
+{
+  struct svr4_info *info = get_svr4_info ();
+
+  if (info->using_probes)
+    iterate_over_breakpoints (svr4_update_solib_event_breakpoint, NULL);
+}
+
+/* Both the SunOS and the SVR4 dynamic linkers call a marker function
+   before and after mapping and unmapping shared libraries.  The sole
+   purpose of this method is to allow debuggers to set a breakpoint so
+   they can track these changes.
+
+   Some versions of the glibc dynamic linker contain named probes
+   to allow more fine grained stopping.  Given the address of the
+   original marker function, this function attempts to find these
+   probes, and if found, sets breakpoints on those instead.  If the
+   probes aren't found, a single breakpoint is set on the original
+   marker function.  */
+
+static void
+svr4_create_solib_event_breakpoints (struct gdbarch *gdbarch,
+				     CORE_ADDR address)
+{
+  struct svr4_info *info = get_svr4_info ();
+  struct obj_section *os;
+
+  os = find_pc_section (address);
+  if (os != NULL)
+    {
+      int with_prefix;
+
+      for (with_prefix = 0; with_prefix <= 1; with_prefix++)
+	{
+	  int all_probes_found = 1;
+	  int i;
+
+	  for (i = 0; i < NUM_PROBES; i++)
+	    {
+	      char name[32] = { '\0' };
+
+	      /* Fedora 17, RHEL 6.2, and RHEL 6.3 shipped with an
+		 early version of the probes code in which the probes'
+		 names were prefixed with "rtld_".  The locations and
+		 arguments of the probes are otherwise the same, so we
+		 check for the prefixed version if the unprefixed
+		 probes are not found.  */
+
+	      if (with_prefix)
+		strncat (name, "rtld_", sizeof (name));
+
+	      strncat (name, probe_info[i].name, sizeof (name));
+
+	      info->probes[i] = find_probes_in_objfile (os->objfile, "rtld",
+							name);
+
+	      if (!VEC_length (probe_p, info->probes[i]))
+		{
+		  free_probes (info);
+		  all_probes_found = 0;
+		  break;
+		}
+	    }
+
+	  if (all_probes_found)
+	    {
+	      info->using_probes = 1;
+
+	      for (i = 0; i < NUM_PROBES; i++)
+		{
+		  struct probe *probe;
+		  int ix;
+
+		  for (ix = 0;
+		       VEC_iterate (probe_p, info->probes[i], ix, probe);
+		       ++ix)
+		    create_solib_event_breakpoint (gdbarch, probe->address);
+		}
+
+	      svr4_update_solib_event_breakpoints ();
+	      return;
+	    }
+	}
+    }
+
+  create_solib_event_breakpoint (gdbarch, address);
+}
+
 /* Helper function for gdb_bfd_lookup_symbol.  */
 
 static int
@@ -1452,6 +2096,9 @@
   info->interp_text_sect_low = info->interp_text_sect_high = 0;
   info->interp_plt_sect_low = info->interp_plt_sect_high = 0;
 
+  free_probes (info);
+  info->using_probes = 0;
+
   /* If we already have a shared library list in the target, and
      r_debug contains r_brk, set the breakpoint there - this should
      mean r_brk has already been relocated.  Assume the dynamic linker
@@ -1483,7 +2130,7 @@
 	 That knowledge is encoded in the address, if it's Thumb the low bit
 	 is 1.  However, we've stripped that info above and it's not clear
 	 what all the consequences are of passing a non-addr_bits_remove'd
-	 address to create_solib_event_breakpoint.  The call to
+	 address to svr4_create_solib_event_breakpoints.  The call to
 	 find_pc_section verifies we know about the address and have some
 	 hope of computing the right kind of breakpoint to use (via
 	 symbol info).  It does mean that GDB needs to be pointed at a
@@ -1521,7 +2168,7 @@
 		+ bfd_section_size (tmp_bfd, interp_sect);
 	    }
 
-	  create_solib_event_breakpoint (target_gdbarch, sym_addr);
+	  svr4_create_solib_event_breakpoints (target_gdbarch, sym_addr);
 	  return 1;
 	}
     }
@@ -1676,7 +2323,8 @@
 
       if (sym_addr != 0)
 	{
-	  create_solib_event_breakpoint (target_gdbarch, load_addr + sym_addr);
+	  svr4_create_solib_event_breakpoints (target_gdbarch,
+					       load_addr + sym_addr);
 	  xfree (interp_name);
 	  return 1;
 	}
@@ -1702,7 +2350,7 @@
 	  sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch,
 							 sym_addr,
 							 &current_target);
-	  create_solib_event_breakpoint (target_gdbarch, sym_addr);
+	  svr4_create_solib_event_breakpoints (target_gdbarch, sym_addr);
 	  return 1;
 	}
     }
@@ -1718,7 +2366,7 @@
 	      sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch,
 							     sym_addr,
 							     &current_target);
-	      create_solib_event_breakpoint (target_gdbarch, sym_addr);
+	      svr4_create_solib_event_breakpoints (target_gdbarch, sym_addr);
 	      return 1;
 	    }
 	}
@@ -2228,6 +2876,9 @@
 
   info = get_svr4_info ();
 
+  /* Free the probes-based interface's namespace table.  */
+  free_namespace_table (info);
+
   /* Relocate the main executable if necessary.  */
   svr4_relocate_main_executable ();
 
@@ -2494,4 +3145,6 @@
   svr4_so_ops.lookup_lib_global_symbol = elf_lookup_lib_symbol;
   svr4_so_ops.same = svr4_same;
   svr4_so_ops.keep_data_in_core = svr4_keep_data_in_core;
+  svr4_so_ops.handle_solib_event = svr4_handle_solib_event;
+  svr4_so_ops.update_breakpoints = svr4_update_solib_event_breakpoints;
 }
diff --git a/gdb/testsuite/gdb.base/break-dlmopen-solib.c b/gdb/testsuite/gdb.base/break-dlmopen-solib.c
new file mode 100644
index 0000000..9979ee7
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-dlmopen-solib.c
@@ -0,0 +1,24 @@
+/* Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+
+int
+foo (int n)
+{
+  printf ("foo %d\n", n);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/break-dlmopen.c b/gdb/testsuite/gdb.base/break-dlmopen.c
new file mode 100644
index 0000000..bfe6f3e
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-dlmopen.c
@@ -0,0 +1,58 @@
+/* Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#define _GNU_SOURCE
+#include <dlfcn.h>
+
+void
+stop ()
+{
+}
+
+int
+main ()
+{
+  void *handle1, *handle2, *handle3;
+  void (*func)(int);
+
+  handle1 = dlmopen (LM_ID_NEWLM, SHLIB_NAME, RTLD_LAZY);
+  stop ();
+
+  func = (void (*)(int)) dlsym (handle1, "foo");
+  func (1);
+
+  handle2 = dlmopen (LM_ID_NEWLM, SHLIB_NAME, RTLD_LAZY);
+  stop ();
+
+  func = (void (*)(int)) dlsym (handle2, "foo");
+  func (2);
+
+  handle3 = dlopen (SHLIB_NAME, RTLD_LAZY);
+  stop ();
+
+  func = (void (*)(int)) dlsym (handle3, "foo");
+  func (3);
+
+  dlclose (handle1);
+  stop ();
+
+  dlclose (handle2);
+  stop ();
+
+  dlclose (handle3);
+  stop ();
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/break-dlmopen.exp b/gdb/testsuite/gdb.base/break-dlmopen.exp
new file mode 100644
index 0000000..e9be571
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-dlmopen.exp
@@ -0,0 +1,125 @@
+# Copyright 2012 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if { [skip_shlib_tests] || [is_remote target] } {
+    return 0
+}
+
+standard_testfile
+
+set libname $testfile-solib
+set srcfile_lib $srcdir/$subdir/$libname.c
+set binfile_lib [standard_output_file $libname.so]
+
+set normal_bp "_dl_debug_state"
+set probes_bp "dl_main"
+
+if { [gdb_compile_shlib $srcfile_lib $binfile_lib \
+	  [list additional_flags=-fPIC]] != "" } {
+    untested "Could not compile $binfile_lib."
+    return -1
+}
+
+if { [prepare_for_testing $testfile.exp $testfile $srcfile \
+	  [list additional_flags=-DSHLIB_NAME\=\"$binfile_lib\" libs=-ldl]] } {
+    return -1
+}
+
+# Run "info sharedlibrary" and check our library is shown the expected
+# number of times.
+proc check_info_shared { test expect } {
+    global libname
+    global gdb_prompt
+
+    set actual 0
+
+    gdb_test_multiple "info sharedlibrary" $test {
+	-re $libname {
+	    incr actual 1
+	    exp_continue
+	}
+	-re "\r\n$gdb_prompt $" {
+	    if { $actual == $expect } {
+		pass $test
+	    } else {
+		fail $test
+	    }
+	}
+    }
+}
+
+# Enable stop-on-solib-events
+gdb_test_no_output "set stop-on-solib-events 1"
+
+# Run to the first stop
+gdb_test "run" ".*Stopped due to shared library event.*"
+
+# XFAIL if we are not using probes
+set test "ensure using probes"
+set using_probes 0
+gdb_test_multiple "bt" $test {
+    -re "#0 +\[^\r\n\]*\\m(__GI_)?$normal_bp\\M.*$gdb_prompt $" {
+	xfail $test
+    }
+    -re "#0 +\[^\r\n\]*\\m(__GI_)?$probes_bp\\M.*$gdb_prompt $" {
+	pass $test
+	set using_probes 1
+    }
+}
+
+if { $using_probes } {
+    # Set up breakpoints.
+    gdb_test_no_output "set stop-on-solib-events 0"
+    gdb_test "break stop" {Breakpoint [0-9]+ at .*}
+    gdb_test_no_output "set breakpoint pending on"
+    gdb_test "break foo" {Breakpoint [0-9]+ \(foo\) pending\.}
+
+    # Check our library isn't loaded.
+    check_info_shared "info sharedlibrary #1" 0
+
+    # Run to the first stop and check our library loaded.
+    gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+    check_info_shared "info sharedlibrary #2" 1
+
+    # The next stop should be the function in the library.
+    gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
+
+    # Run to the next stop and check our library is now loaded twice.
+    gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+    check_info_shared "info sharedlibrary #3" 2
+
+    # The next stop should be the function in the library.
+    gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
+
+    # Run to the next stop and check our library is now loaded three
+    # times.
+    gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+    check_info_shared "info sharedlibrary #4" 3
+
+    # The next stop should be the function in the library.
+    gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
+
+    # Run to the next stop and check our library is now loaded twice.
+    gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+    check_info_shared "info sharedlibrary #5" 2
+
+    # Run to the next stop and check our library is now loaded once.
+    gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+    check_info_shared "info sharedlibrary #6" 1
+
+    # Run to the next stop and check our library is not loaded.
+    gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+    check_info_shared "info sharedlibrary #7" 0
+}
diff --git a/gdb/testsuite/gdb.base/break-interp.exp b/gdb/testsuite/gdb.base/break-interp.exp
index 4012e66..7aa6537 100644
--- a/gdb/testsuite/gdb.base/break-interp.exp
+++ b/gdb/testsuite/gdb.base/break-interp.exp
@@ -109,12 +109,19 @@ proc strip_debug {dest} {
     }
 }
 
+# The marker function for the standard runtime linker interface is
+# _dl_debug_state.  The probes-based interface has no specific marker
+# function; the probe we will stop on (init_start) is in dl_main so we
+# check for that.
+
+set solib_bp {(_dl_debug_state|dl_main)}
+
 # Implementation of reach.
 
 proc reach_1 {func command displacement} {
-    global gdb_prompt expect_out
+    global gdb_prompt expect_out solib_bp
 
-    if {$func == "_dl_debug_state"} {
+    if {$func == $solib_bp} {
 	# Breakpoint on _dl_debug_state can have problems due to its overlap
 	# with the existing internal breakpoint from GDB.
 	gdb_test_no_output "set stop-on-solib-events 1"
@@ -142,21 +149,21 @@ proc reach_1 {func command displacement} {
 	    exp_continue
 	}
 	-re "Breakpoint \[0-9\]+, \\.?(__GI_)?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" {
-	    if {$func == "_dl_debug_state"} {
+	    if {$func == $solib_bp} {
 		fail $test
 	    } else {
 		pass $test
 	    }
 	}
 	-re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?(__GI_)?$func \\(\\).*\r\n$gdb_prompt $" {
-	    if {$func == "_dl_debug_state"} {
+	    if {$func == $solib_bp} {
 		fail $test
 	    } else {
 		pass $test
 	    }
 	}
 	-re "Stopped due to (spurious )?shared library event.*\r\n$gdb_prompt $" {
-	    if {$func == "_dl_debug_state"} {
+	    if {$func == $solib_bp} {
 		if {$debug_state_count == 0} {
 		    # First stop does not yet relocate the _start function
 		    # descriptor on ppc64.
@@ -175,7 +182,7 @@ proc reach_1 {func command displacement} {
 	fail $test_displacement
     }
 
-    if {$func == "_dl_debug_state"} {
+    if {$func == $solib_bp} {
 	gdb_test_no_output "set stop-on-solib-events 0"
     }
 }
@@ -357,7 +364,7 @@ proc test_attach {file displacement {relink_args ""}} {
 }
 
 proc test_ld {file ifmain trynosym displacement} {
-    global srcdir subdir gdb_prompt expect_out inferior_exited_re
+    global srcdir subdir gdb_prompt expect_out inferior_exited_re solib_bp
 
     # First test normal `file'-command loaded $FILE with symbols.
 
@@ -385,9 +392,9 @@ proc test_ld {file ifmain trynosym displacement} {
 	gdb_test_no_output "set args ${objdir}/${subdir}/$binfile_test" "set args OBJDIR/${subdir}/$binfile_test"
     }
 
-    reach "_dl_debug_state" "run" $displacement
+    reach $solib_bp "run" $displacement
 
-    gdb_test "bt" "#0 +\[^\r\n\]*\\m(__GI_)?_dl_debug_state\\M.*" "dl bt"
+    gdb_test "bt" "#0 +\[^\r\n\]*\\m(__GI_)?$solib_bp\\M.*" "dl bt"
 
     if $ifmain {
 	reach "main" continue "NONE"
@@ -399,7 +406,7 @@ proc test_ld {file ifmain trynosym displacement} {
 
     # Try re-run if the new PIE displacement takes effect.
     gdb_test "kill" "" "kill" {Kill the program being debugged\? \(y or n\) } "y"
-    reach "_dl_debug_state" "run" $displacement
+    reach $solib_bp "run" $displacement
 
     if $ifmain {
 	test_core $file $displacement
@@ -431,7 +438,7 @@ proc test_ld {file ifmain trynosym displacement} {
 	gdb_test "exec-file $file" "exec-file $escapedfile" "load"
 
 	if $ifmain {
-	    reach "_dl_debug_state" run $displacement
+	    reach $solib_bp run $displacement
 
 	    # Use two separate gdb_test_multiple statements to avoid timeouts due
 	    # to slow processing of wildcard capturing long output
diff --git a/gdb/testsuite/gdb.base/break-probes-solib.c b/gdb/testsuite/gdb.base/break-probes-solib.c
new file mode 100644
index 0000000..9979ee7
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-probes-solib.c
@@ -0,0 +1,24 @@
+/* Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+
+int
+foo (int n)
+{
+  printf ("foo %d\n", n);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/break-probes.c b/gdb/testsuite/gdb.base/break-probes.c
new file mode 100644
index 0000000..a778099
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-probes.c
@@ -0,0 +1,26 @@
+/* Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <dlfcn.h>
+
+int
+main ()
+{
+  void *handle = dlopen (SHLIB_NAME, RTLD_LAZY);
+
+  dlclose (handle);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/break-probes.exp b/gdb/testsuite/gdb.base/break-probes.exp
new file mode 100644
index 0000000..a8dc373
--- /dev/null
+++ b/gdb/testsuite/gdb.base/break-probes.exp
@@ -0,0 +1,76 @@
+# Copyright 2012 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if { [skip_shlib_tests] || [is_remote target] } {
+    return 0
+}
+
+standard_testfile
+
+set libname $testfile-solib
+set srcfile_lib $srcdir/$subdir/$libname.c
+set binfile_lib [standard_output_file $libname.so]
+
+set normal_bp "_dl_debug_state"
+set probes_bp "dl_main"
+
+if { [gdb_compile_shlib $srcfile_lib $binfile_lib \
+	  [list additional_flags=-fPIC]] != "" } {
+    untested "Could not compile $binfile_lib."
+    return -1
+}
+
+if { [prepare_for_testing $testfile.exp $testfile $srcfile \
+	  [list additional_flags=-DSHLIB_NAME\=\"$binfile_lib\" libs=-ldl]] } {
+    return -1
+}
+
+# Enable stop-on-solib-events
+gdb_test_no_output "set stop-on-solib-events 1"
+
+# Run to the first stop
+gdb_test "run" ".*Stopped due to shared library event.*"
+
+# XFAIL if we are not using probes
+set test "ensure using probes"
+set using_probes 0
+gdb_test_multiple "bt" $test {
+    -re "#0 +\[^\r\n\]*\\m(__GI_)?$normal_bp\\M.*$gdb_prompt $" {
+	xfail $test
+    }
+    -re "#0 +\[^\r\n\]*\\m(__GI_)?$probes_bp\\M.*$gdb_prompt $" {
+	pass $test
+	set using_probes 1
+    }
+}
+
+if { $using_probes } {
+    # Run til it loads our library
+    set test "run til our library loads"
+    set loaded_library 0
+    while { !$loaded_library } {
+	gdb_test_multiple "c" $test {
+	    -re "Inferior loaded $binfile_lib\\M.*$gdb_prompt $" {
+		pass $test
+		set loaded_library 1
+	    }
+	    -re "Stopped due to shared library event\\M.*$gdb_prompt $" {
+	    }
+	}
+    }
+
+    # Call something to ensure that relocation occurred
+    gdb_test "call foo(23)" "foo 23.*\\\$.* = .*"
+}
diff --git a/gdb/testsuite/gdb.base/info-shared-solib1.c b/gdb/testsuite/gdb.base/info-shared-solib1.c
new file mode 100644
index 0000000..9979ee7
--- /dev/null
+++ b/gdb/testsuite/gdb.base/info-shared-solib1.c
@@ -0,0 +1,24 @@
+/* Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+
+int
+foo (int n)
+{
+  printf ("foo %d\n", n);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/info-shared-solib2.c b/gdb/testsuite/gdb.base/info-shared-solib2.c
new file mode 100644
index 0000000..d4ed1e6
--- /dev/null
+++ b/gdb/testsuite/gdb.base/info-shared-solib2.c
@@ -0,0 +1,24 @@
+/* Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+
+int
+bar (int n)
+{
+  printf ("bar %d\n", n);
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/info-shared.c b/gdb/testsuite/gdb.base/info-shared.c
new file mode 100644
index 0000000..d699a11
--- /dev/null
+++ b/gdb/testsuite/gdb.base/info-shared.c
@@ -0,0 +1,48 @@
+/* Copyright 2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <dlfcn.h>
+
+void
+stop ()
+{
+}
+
+int
+main ()
+{
+  void *handle1, *handle2;
+  void (*func)(int);
+
+  handle1 = dlopen (SHLIB1_NAME, RTLD_LAZY);
+  stop ();
+
+  handle2 = dlopen (SHLIB2_NAME, RTLD_LAZY);
+  stop ();
+
+  func = (void (*)(int)) dlsym (handle1, "foo");
+  func (1);
+
+  func = (void (*)(int)) dlsym (handle2, "bar");
+  func (2);
+
+  dlclose (handle1);
+  stop ();
+
+  dlclose (handle2);
+  stop ();
+
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/info-shared.exp b/gdb/testsuite/gdb.base/info-shared.exp
new file mode 100644
index 0000000..70a1816
--- /dev/null
+++ b/gdb/testsuite/gdb.base/info-shared.exp
@@ -0,0 +1,139 @@
+# Copyright 2012 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if { [skip_shlib_tests] || [is_remote target] } {
+    return 0
+}
+
+standard_testfile
+
+set lib1name $testfile-solib1
+set srcfile_lib1 $srcdir/$subdir/$lib1name.c
+set binfile_lib1 [standard_output_file $lib1name.so]
+set define1 -DSHLIB1_NAME\=\"$binfile_lib1\"
+
+set lib2name $testfile-solib2
+set srcfile_lib2 $srcdir/$subdir/$lib2name.c
+set binfile_lib2 [standard_output_file $lib2name.so]
+set define2 -DSHLIB2_NAME\=\"$binfile_lib2\"
+
+if { [gdb_compile_shlib $srcfile_lib1 $binfile_lib1 \
+	  [list additional_flags=-fPIC]] != "" } {
+    untested "Could not compile $binfile_lib1."
+    return -1
+}
+
+if { [gdb_compile_shlib $srcfile_lib2 $binfile_lib2 \
+	  [list additional_flags=-fPIC]] != "" } {
+    untested "Could not compile $binfile_lib2."
+    return -1
+}
+
+set cflags "$define1 $define2"
+if { [prepare_for_testing $testfile.exp $testfile $srcfile \
+	  [list additional_flags=$cflags libs=-ldl]] } {
+    return -1
+}
+
+# Run "info sharedlibrary" and check for the presence or absence of
+# our libraries.
+proc check_info_shared { test expect1 expect2 } {
+    global lib1name
+    global lib2name
+    global gdb_prompt
+
+    set actual1 0
+    set actual2 0
+
+    gdb_test_multiple "info sharedlibrary" $test {
+	-re $lib1name {
+	    set actual1 1
+	    exp_continue
+	}
+	-re $lib2name {
+	    set actual2 1
+	    exp_continue
+	}
+	-re "\r\n$gdb_prompt $" {
+	    if { $actual1 == $expect1 && $actual2 == $expect2 } {
+		pass $test
+	    } else {
+		fail $test
+	    }
+	}
+    }
+}
+
+# Set up breakpoints.
+gdb_test "break stop" {Breakpoint [0-9]+ at .*}
+gdb_test_no_output "set breakpoint pending on"
+gdb_test "break foo" {Breakpoint [0-9]+ \(foo\) pending\.}
+gdb_test "break bar" {Breakpoint [0-9]+ \(bar\) pending\.}
+
+# Check neither of the libraries are loaded at the start.
+gdb_test "start" {Temporary breakpoint [0-9]+, .* in main \(\)}
+check_info_shared "info sharedlibrary #1" 0 0
+
+# Run to the first stop and check that only the first library is loaded.
+gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+check_info_shared "info sharedlibrary #2" 1 0
+
+# Run to the second stop and check that both libraries are loaded.
+gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+check_info_shared "info sharedlibrary #3" 1 1
+
+# Check that the next stop is in foo.
+gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
+
+# Check that the next stop is in bar.
+gdb_test "c" {Breakpoint [0-9]+, .* in bar \(\) from .*}
+
+# Restart the inferior and make sure there are no breakpoint reset
+# errors.  These can happen with the probes-based runtime linker
+# interface if the cache is not cleared correctly.
+set test "restart"
+gdb_test_multiple "run" $test {
+    -re {Start it from the beginning\? \(y or n\) } {
+	send_gdb "y\n"
+	exp_continue
+    }
+    -re {Error in re-setting breakpoint} {
+	fail $test
+    }
+    -re "\r\n$gdb_prompt $" {
+	pass $test
+    }
+}
+
+# We're at the first stop.  Check that only the first library is loaded.
+check_info_shared "info sharedlibrary #4" 1 0
+
+# Run to the second stop and check that both libraries are loaded.
+gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+check_info_shared "info sharedlibrary #5" 1 1
+
+# Check that the next stop is in foo.
+gdb_test "c" {Breakpoint [0-9]+, .* in foo \(\) from .*}
+
+# Check that the next stop is in bar.
+gdb_test "c" {Breakpoint [0-9]+, .* in bar \(\) from .*}
+
+# Run to the next stop and check that the first library has been unloaded.
+gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+check_info_shared "info sharedlibrary #6" 0 1
+
+# Run to the last stop and check that both libraries are gone.
+gdb_test "c" {Breakpoint [0-9]+, .* in stop \(\)}
+check_info_shared "info sharedlibrary #7" 0 0

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-07-31 12:13     ` Gary Benson
@ 2012-08-14 19:49       ` Tom Tromey
  0 siblings, 0 replies; 19+ messages in thread
From: Tom Tromey @ 2012-08-14 19:49 UTC (permalink / raw)
  To: gdb-patches

>>>>> "Gary" == Gary Benson <gbenson@redhat.com> writes:

Gary> 2012-07-30  Gary Benson  <gbenson@redhat.com>
Gary> 	* breakpoint.h (handle_solib_event): Moved function definition
Gary> 	to solib.h, and added a new parameter.
[...]

Gary> +static void
Gary> +free_probes (struct svr4_info *info)
Gary> +{
Gary> +  int i;
Gary> +
Gary> +  for (i = 0; i < NUM_PROBES; i++)
Gary> +    VEC_free (probe_p, info->probes[i]);
Gary> +
Gary> +  memset (info->probes, 0, sizeof (info->probes));

VEC_free sets the pointer to NULL, so this memset isn't needed.

Gary> +  val = evaluate_probe_argument (pi->probe, 0);
Gary> +  if (val == NULL)
Gary> +    goto error;

I don't see evaluate_probe_argument in the tree.
Maybe it was in another patch of yours?

Anyway, can it really return NULL?
I would expect it to throw an exception instead.

If it does throw an exception, and since the error case needs some work,
I think you will have to use cleanups here instead.

Gary> +/* Helper function for namespace_table_flatten.  */
Gary> +
Gary> +static int
Gary> +namespace_table_flatten_helper (void **slot, void *arg)
Gary> +{
Gary> +  struct namespace *ns = (struct namespace *) *slot;
Gary> +  struct so_list *src = ns->solist;
Gary> +  struct so_list **link = (struct so_list **) arg;
Gary> +
Gary> +  while (*link)
Gary> +    link = &(*link)->next;

I think this means we iterate over the entire linked list each time we
visit some element in the hash table.

It would not take much more effort to avoid this repeated iteration, by
changing 'arg' to an object that also holds the link pointer at the tail
of the list.

Tom


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-07-19 11:09 [RFA 4/4 take 2] Improved linker-debugger interface Gary Benson
  2012-07-25 19:36 ` Tom Tromey
@ 2012-08-15 17:24 ` Jan Kratochvil
  2012-08-15 17:46   ` Jan Kratochvil
  2012-09-19  9:49   ` Gary Benson
  1 sibling, 2 replies; 19+ messages in thread
From: Jan Kratochvil @ 2012-08-15 17:24 UTC (permalink / raw)
  To: gdb-patches

Hi Gary,

(1)
with the current setup IIRC the dlmopen()ed libraries are only shown with live
process but they cannot be shown when loaded from a core file.

This breaks functionality of core files, I believe glibc needs an extension if
it currently cannot be done otherwise.

(2)
solib-svr4.c is current not used by with gdbsrver and its recent
linux_qxfer_libraries_svr4.

Your testcases is skipped if [is_remote target], with the current general goal
to unify linux-nat with gdbserver and drop linux-nat afterwards I do not think
we should accept more patches increasing the linux-nat vs. gdbserver gap.
The testcase should be specifically compatible with gdbserver.

To give the background: solib-svr4.c is more general and it is kept for all
possible corner cases, it also supports more OSes than just GNU/Linux.
Compared to it linux-low.c can be easier, this is why it is reimplemented and
not shared with solib-svr4.c (it could be shared more but it is not).
Therefore maybe your extensions on top of it all are not feasible for
gdb/common/ but they should be at least reimplemented also for linux-low.c

(3)
There is some issue we already discussed off-list, in some cases (Fedora
Rawhide x86_64 with Fedora patched GDB) it breaks on
	FAIL: gdb.base/break-dlmopen.exp: info sharedlibrary #5

namespace_update_full(lmid=0x1,debug_base=0x7ffff7ffd0f8,is_initial_ns=0
svr4_read_so_list(lm=0x6020a0,prev_lm=0x0)
lm=0x6020a0={next=0x602670,prev=0x0}
lm=0x602670={next=0x0,prev=0x0}
warning: Corrupted shared library list: 0x6020a0 != 0x0
warning: Probes-based dynamic linker interface failed.
Reverting to original interface.


Thanks,
Jan


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-08-15 17:24 ` Jan Kratochvil
@ 2012-08-15 17:46   ` Jan Kratochvil
  2012-08-16 11:14     ` Gary Benson
  2012-08-16 15:52     ` Gary Benson
  2012-09-19  9:49   ` Gary Benson
  1 sibling, 2 replies; 19+ messages in thread
From: Jan Kratochvil @ 2012-08-15 17:46 UTC (permalink / raw)
  To: gdb-patches

Hi Gary,

On Wed, 15 Aug 2012 19:23:46 +0200, Jan Kratochvil wrote:
> (3)
> There is some issue we already discussed off-list, in some cases (Fedora
> Rawhide x86_64 with Fedora patched GDB) it breaks on
> 	FAIL: gdb.base/break-dlmopen.exp: info sharedlibrary #5

reproduced it also with FSF GDB HEAD with the patch below.

Apparently the address 0x6020a0 is already freed/invalid that time, I guess it
is more clear to you:

> namespace_update_full(lmid=0x1,debug_base=0x7ffff7ffd0f8,is_initial_ns=0
> svr4_read_so_list(lm=0x6020a0,prev_lm=0x0)
> lm=0x6020a0={next=0x602670,prev=0x0}
> lm=0x602670={next=0x0,prev=0x0}
> warning: Corrupted shared library list: 0x6020a0 != 0x0


Thanks,
Jan


diff --git a/gdb/testsuite/gdb.base/break-dlmopen.exp b/gdb/testsuite/gdb.base/break-dlmopen.exp
index 52cd5ef..ebf9089 100644
--- a/gdb/testsuite/gdb.base/break-dlmopen.exp
+++ b/gdb/testsuite/gdb.base/break-dlmopen.exp
@@ -33,7 +33,7 @@ if { [gdb_compile_shlib $srcfile_lib $binfile_lib \
 }
 
 if { [prepare_for_testing $testfile.exp $testfile $srcfile \
-	  [list additional_flags=-DSHLIB_NAME\=\"$binfile_lib\" libs=-ldl]] } {
+	  [list additional_flags=-DSHLIB_NAME\=\"$binfile_lib\" libs=-ldl libs=-lmcheck]] } {
     return -1
 }
 


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-08-15 17:46   ` Jan Kratochvil
@ 2012-08-16 11:14     ` Gary Benson
  2012-08-16 15:52     ` Gary Benson
  1 sibling, 0 replies; 19+ messages in thread
From: Gary Benson @ 2012-08-16 11:14 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

Jan Kratochvil wrote:
> On Wed, 15 Aug 2012 19:23:46 +0200, Jan Kratochvil wrote:
> > (3)
> > There is some issue we already discussed off-list, in some cases (Fedora
> > Rawhide x86_64 with Fedora patched GDB) it breaks on
> > 	FAIL: gdb.base/break-dlmopen.exp: info sharedlibrary #5
> 
> reproduced it also with FSF GDB HEAD with the patch below.
> 
> Apparently the address 0x6020a0 is already freed/invalid that time,
> I guess it is more clear to you:
> 
> > namespace_update_full(lmid=0x1,debug_base=0x7ffff7ffd0f8,is_initial_ns=0
> > svr4_read_so_list(lm=0x6020a0,prev_lm=0x0)
> > lm=0x6020a0={next=0x602670,prev=0x0}
> > lm=0x602670={next=0x0,prev=0x0}
> > warning: Corrupted shared library list: 0x6020a0 != 0x0
> 
> diff --git a/gdb/testsuite/gdb.base/break-dlmopen.exp b/gdb/testsuite/gdb.base/break-dlmopen.exp
> index 52cd5ef..ebf9089 100644
> --- a/gdb/testsuite/gdb.base/break-dlmopen.exp
> +++ b/gdb/testsuite/gdb.base/break-dlmopen.exp
> @@ -33,7 +33,7 @@ if { [gdb_compile_shlib $srcfile_lib $binfile_lib \
>  }
>  
>  if { [prepare_for_testing $testfile.exp $testfile $srcfile \
> -	  [list additional_flags=-DSHLIB_NAME\=\"$binfile_lib\" libs=-ldl]] } {
> +	  [list additional_flags=-DSHLIB_NAME\=\"$binfile_lib\" libs=-ldl libs=-lmcheck]] } {
>      return -1
>  }

Thanks for this, I have it reproduced now and I'm looking into it.

Cheers,
Gary

-- 
http://gbenson.net/


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-08-15 17:46   ` Jan Kratochvil
  2012-08-16 11:14     ` Gary Benson
@ 2012-08-16 15:52     ` Gary Benson
  2012-08-17 10:54       ` Gary Benson
  1 sibling, 1 reply; 19+ messages in thread
From: Gary Benson @ 2012-08-16 15:52 UTC (permalink / raw)
  To: gdb-patches

Jan Kratochvil wrote:
> On Wed, 15 Aug 2012 19:23:46 +0200, Jan Kratochvil wrote:
> > (3)
> > There is some issue we already discussed off-list, in some cases (Fedora
> > Rawhide x86_64 with Fedora patched GDB) it breaks on
> > 	FAIL: gdb.base/break-dlmopen.exp: info sharedlibrary #5
> 
> reproduced it also with FSF GDB HEAD with the patch below.
> 
> Apparently the address 0x6020a0 is already freed/invalid that time,
> I guess it is more clear to you:
> 
> > namespace_update_full(lmid=0x1,debug_base=0x7ffff7ffd0f8,is_initial_ns=0
> > svr4_read_so_list(lm=0x6020a0,prev_lm=0x0)
> > lm=0x6020a0={next=0x602670,prev=0x0}
> > lm=0x602670={next=0x0,prev=0x0}
> > warning: Corrupted shared library list: 0x6020a0 != 0x0

This is a glibc issue.  I've mailed a patch to libc-alpha:
http://sourceware.org/ml/libc-alpha/2012-08/msg00366.html

Thanks,
Gary

-- 
http://gbenson.net/


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-08-16 15:52     ` Gary Benson
@ 2012-08-17 10:54       ` Gary Benson
  2012-08-17 16:41         ` Jan Kratochvil
  0 siblings, 1 reply; 19+ messages in thread
From: Gary Benson @ 2012-08-17 10:54 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jan Kratochvil

Gary Benson wrote:
> Jan Kratochvil wrote:
> > On Wed, 15 Aug 2012 19:23:46 +0200, Jan Kratochvil wrote:
> > > (3)
> > > There is some issue we already discussed off-list, in some cases
> > > (Fedora Rawhide x86_64 with Fedora patched GDB) it breaks on

> > > 	FAIL: gdb.base/break-dlmopen.exp: info sharedlibrary #5
> > 
> > reproduced it also with FSF GDB HEAD with the patch below.
> > 
> > Apparently the address 0x6020a0 is already freed/invalid that
> > time, I guess it is more clear to you:
> > 
> > > namespace_update_full(lmid=0x1,debug_base=0x7ffff7ffd0f8,is_initial_ns=0
> > > svr4_read_so_list(lm=0x6020a0,prev_lm=0x0)
> > > lm=0x6020a0={next=0x602670,prev=0x0}
> > > lm=0x602670={next=0x0,prev=0x0}
> > > warning: Corrupted shared library list: 0x6020a0 != 0x0
> 
> This is a glibc issue.  I've mailed a patch to libc-alpha:
> http://sourceware.org/ml/libc-alpha/2012-08/msg00366.html

The fix has been accepted and committed:
http://sourceware.org/ml/libc-alpha/2012-08/msg00385.html

Cheers,
Gary

-- 
http://gbenson.net/


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-08-17 10:54       ` Gary Benson
@ 2012-08-17 16:41         ` Jan Kratochvil
  0 siblings, 0 replies; 19+ messages in thread
From: Jan Kratochvil @ 2012-08-17 16:41 UTC (permalink / raw)
  To: gdb-patches

On Fri, 17 Aug 2012 12:53:44 +0200, Gary Benson wrote:
> The fix has been accepted and committed:
> http://sourceware.org/ml/libc-alpha/2012-08/msg00385.html

The test should XFAIL accordingly, if the -lmcheck is reliable then use it,
otherwise at least check for installed glibc release.


Thanks,
Jan


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-08-15 17:24 ` Jan Kratochvil
  2012-08-15 17:46   ` Jan Kratochvil
@ 2012-09-19  9:49   ` Gary Benson
  2012-09-19 11:14     ` Jan Kratochvil
  1 sibling, 1 reply; 19+ messages in thread
From: Gary Benson @ 2012-09-19  9:49 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

Hi Jan,

Jan Kratochvil wrote:
> solib-svr4.c is current not used by with gdbsrver and its recent
> linux_qxfer_libraries_svr4.
> 
> Your testcases is skipped if [is_remote target], with the current
> general goal to unify linux-nat with gdbserver and drop linux-nat
> afterwards I do not think we should accept more patches increasing
> the linux-nat vs. gdbserver gap.  The testcase should be
> specifically compatible with gdbserver.
> 
> To give the background: solib-svr4.c is more general and it is kept
> for all possible corner cases, it also supports more OSes than just
> GNU/Linux.  Compared to it linux-low.c can be easier, this is why it
> is reimplemented and not shared with solib-svr4.c (it could be
> shared more but it is not).  Therefore maybe your extensions on top
> of it all are not feasible for gdb/common/ but they should be at
> least reimplemented also for linux-low.c

How do I configure/build/test gdb so that it is using linux-low.c?
I've updated the tests to work with gdbserver, but with my current
setup solib-svr4.c is being used, so all the tests are passing.

Thanks,
Gary

-- 
http://gbenson.net/


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-09-19  9:49   ` Gary Benson
@ 2012-09-19 11:14     ` Jan Kratochvil
  2012-09-19 15:06       ` Gary Benson
  0 siblings, 1 reply; 19+ messages in thread
From: Jan Kratochvil @ 2012-09-19 11:14 UTC (permalink / raw)
  To: gdb-patches

Hi Gary,

On Wed, 19 Sep 2012 11:49:34 +0200, Gary Benson wrote:
> How do I configure/build/test gdb so that it is using linux-low.c?
> I've updated the tests to work with gdbserver, but with my current
> setup solib-svr4.c is being used, so all the tests are passing.

it is enough to use gdbserver:
	http://sourceware.org/gdb/wiki/TestingGDB#Testing_gdbserver_in_a_native_configuration

I have put there a debug dump and for example for gdb.base/return.exp it
really prints several SVR4:PASS and no SVR4:FAIL.

There are some corner cases where solib-svr4.c logic may be used but those are
only rare and discussed in some past gdb-patches mails.

Could you be more specific how do you run the test and how have you found
gdb/gdbserver/linux-low.c is not used?


Thanks,
Jan


diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 3d60aa1..4a431f3 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -1277,8 +1277,10 @@ svr4_current_sos (void)
 	  info->main_lm_addr = library_list.main_lm;
 	}
 
+puts("SVR4:PASS");
       return library_list.head ? library_list.head : svr4_default_sos ();
     }
+puts("SVR4:FAIL");
 
   info = get_svr4_info ();
 


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-09-19 11:14     ` Jan Kratochvil
@ 2012-09-19 15:06       ` Gary Benson
  2012-09-19 15:13         ` Jan Kratochvil
  0 siblings, 1 reply; 19+ messages in thread
From: Gary Benson @ 2012-09-19 15:06 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

Jan Kratochvil wrote:
> On Wed, 19 Sep 2012 11:49:34 +0200, Gary Benson wrote:
> > How do I configure/build/test gdb so that it is using linux-low.c?
> > I've updated the tests to work with gdbserver, but with my current
> > setup solib-svr4.c is being used, so all the tests are passing.
> 
> it is enough to use gdbserver:
> 	http://sourceware.org/gdb/wiki/TestingGDB#Testing_gdbserver_in_a_native_configuration
> 

Ah, that's what I did:

  molly:[src]$ echo $DEJAGNU
  /home/gary/work/gdb/dejagnu/my-dejagnu.exp
  molly:[src]$ ls -lR /home/gary/work/gdb/dejagnu
  /home/gary/work/gdb/dejagnu:
  total 4
  drwxr-xr-x. 2 gary gary 4096 Sep 18 11:16 boards/
  -rw-r--r--. 1 gary gary    0 Sep 18 11:16 my-dejagnu.exp
  
  /home/gary/work/gdb/dejagnu/boards:
  total 4
  -rw-r--r--. 1 gary gary 2673 Sep 18 11:16 native-gdbserver.exp
  molly:[src]$ make -C../build check RUNTESTFLAGS="--target_board=native-gdbserver gdb.base/break-probes.exp gdb.base/break-dlmopen.exp gdb.base/info-shared.exp"

> I have put there a debug dump and for example for gdb.base/return.exp
> it really prints several SVR4:PASS and no SVR4:FAIL.

With that I get a load of SVR4:FAIL and no SVR4:PASS.

I also see "warning: Can not parse XML target description; XML support
was disabled at compile time", is that something to do with it?  Is
there some -devel package I'm missing?

Thanks,
Gary

-- 
http://gbenson.net/


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-09-19 15:06       ` Gary Benson
@ 2012-09-19 15:13         ` Jan Kratochvil
  2012-09-21 12:36           ` Gary Benson
  0 siblings, 1 reply; 19+ messages in thread
From: Jan Kratochvil @ 2012-09-19 15:13 UTC (permalink / raw)
  To: gdb-patches

On Wed, 19 Sep 2012 17:06:22 +0200, Gary Benson wrote:
> I also see "warning: Can not parse XML target description; XML support
> was disabled at compile time", is that something to do with it?  Is
> there some -devel package I'm missing?

Yes, on Fedora 'expat-devel'.

Please rpmbuild -bb --with testsuite gdb.spec
or rpmbuild --rebuild --with testsuite gdb*.src.rpm
to get all the pre-requisites.


Thanks,
Jan


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-09-19 15:13         ` Jan Kratochvil
@ 2012-09-21 12:36           ` Gary Benson
  2012-09-21 14:46             ` Jan Kratochvil
  0 siblings, 1 reply; 19+ messages in thread
From: Gary Benson @ 2012-09-21 12:36 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1460 bytes --]

Hi Jan,

Jan Kratochvil wrote:
> On Wed, 19 Sep 2012 17:06:22 +0200, Gary Benson wrote:
> > I also see "warning: Can not parse XML target description; XML
> > support was disabled at compile time", is that something to do
> > with it?  Is there some -devel package I'm missing?
> 
> Yes, on Fedora 'expat-devel'.
> 
> Please rpmbuild -bb --with testsuite gdb.spec
> or rpmbuild --rebuild --with testsuite gdb*.src.rpm
> to get all the pre-requisites.

I'm not having any luck with this.  I've installed all the
prerequisites except the 32-bit ones:

  libgnat(x86-32) is needed by gdb-7.3.50.20110722-16.x86_64
  glibc-devel(x86-32) is needed by gdb-7.3.50.20110722-16.x86_64
  libgcc(x86-32) is needed by gdb-7.3.50.20110722-16.x86_64
  libstdc++(x86-32) is needed by gdb-7.3.50.20110722-16.x86_64
  libgcj(x86-32) is needed by gdb-7.3.50.20110722-16.x86_64
  zlib-devel(x86-32) is needed by gdb-7.3.50.20110722-16.x86_64
  valgrind(x86-32) is needed by gdb-7.3.50.20110722-16.x86_64

I've also passed --with-expat to force the issue.  I'm not seeing the
XML warning any more, but the tests are still using the probes code
and not the code from linux-low.c.  I've attached a gdb.log (patched
with the attached patch) from running:

  make check RUNTESTFLAGS="--target_board=native-gdbserver gdb.base/break-probes.exp"

You can see from the dl_main in there that the probes code is in use.
Any idea what I'm doing wrong?

Thanks,
Gary

-- 
http://gbenson.net/

[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 490 bytes --]

diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 5eb84ba..6aef1ea 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -1446,8 +1446,14 @@ svr4_current_sos (void)
 	  info->main_lm_addr = library_list.main_lm;
 	}
 
+      if (library_list.head)
+	puts_unfiltered ("SVR4:PASS\n");
+      else
+	puts_unfiltered ("SVR4:WHAT?\n");
+
       return library_list.head ? library_list.head : svr4_default_sos ();
     }
+  puts_unfiltered ("SVR4:FAIL\n");
 
   info = get_svr4_info ();
 

[-- Attachment #3: gdb.log --]
[-- Type: text/plain, Size: 7427 bytes --]

Test Run By gary on Fri Sep 21 13:32:44 2012
Native configuration is x86_64-unknown-linux-gnu

		=== gdb tests ===

Schedule of variations:
    native-gdbserver

Running target native-gdbserver
Using /home/gary/work/gdb/dejagnu/boards/native-gdbserver.exp as board description file for target.
Using ../../../src/gdb/testsuite/config/gdbserver.exp as tool-and-target-specific interface file.
Running ../../../src/gdb/testsuite/gdb.base/break-probes.exp ...
Executing on host: gcc  -fPIC -c  -o /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes-solib.c.o ../../../src/gdb/testsuite/gdb.base/break-probes-solib.c    (timeout = 300)
spawn -ignore SIGHUP gcc -fPIC -c -o /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes-solib.c.o ../../../src/gdb/testsuite/gdb.base/break-probes-solib.c
Executing on host: gcc /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes-solib.c.o  -fPIC -shared -Wl,-soname,break-probes-solib.so  -lm   -o /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes-solib.so    (timeout = 300)
spawn -ignore SIGHUP gcc /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes-solib.c.o -fPIC -shared -Wl,-soname,break-probes-solib.so -lm -o /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes-solib.so
get_compiler_info: gcc-4-6-3
Executing on host: gcc  -DSHLIB_NAME="/home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes-solib.so" -c  -o /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes0.o ../../../src/gdb/testsuite/gdb.base/break-probes.c    (timeout = 300)
spawn -ignore SIGHUP gcc -DSHLIB_NAME="/home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes-solib.so" -c -o /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes0.o ../../../src/gdb/testsuite/gdb.base/break-probes.c
Executing on host: gcc /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes0.o  -DSHLIB_NAME="/home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes-solib.so"  -ldl -lm   -o /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes    (timeout = 300)
spawn -ignore SIGHUP gcc /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes0.o -DSHLIB_NAME="/home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes-solib.so" -ldl -lm -o /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes
spawn /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/../data-directory
GNU gdb (GDB) 7.5.50.20120815-cvs
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) set height 0
(gdb) set width 0
(gdb) dir
Reinitialize source path to empty? (y or n) y
Source directories searched: $cdir:$cwd
(gdb) dir ../../../src/gdb/testsuite/gdb.base
Source directories searched: /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/../../../src/gdb/testsuite/gdb.base:$cdir:$cwd
(gdb) kill
The program is not being run.
(gdb) file /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes
Reading symbols from /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes...(no debugging symbols found)...done.
(gdb) set stop-on-solib-events 1
(gdb) PASS: gdb.base/break-probes.exp: set stop-on-solib-events 1
kill
The program is not being run.
(gdb) spawn ../gdbserver/gdbserver --once :2346 /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes
Process /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes created; pid = 5308
Listening on port 2346
target remote localhost:2346
Remote debugging using localhost:2346
Remote debugging from host 127.0.0.1
SVR4:WHAT?
SVR4:WHAT?
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
0x00000031ce4016e0 in _start () from /lib64/ld-linux-x86-64.so.2
(gdb) continue
Continuing.
SVR4:PASS
Stopped due to shared library event (no libraries added or removed)
(gdb) bt
#0  0x00000031ce403429 in dl_main () from /lib64/ld-linux-x86-64.so.2
#1  0x00000031ce415814 in _dl_sysdep_start () from /lib64/ld-linux-x86-64.so.2
#2  0x00000031ce4053d5 in _dl_start () from /lib64/ld-linux-x86-64.so.2
#3  0x00000031ce4016e8 in _start () from /lib64/ld-linux-x86-64.so.2
#4  0x0000000000000001 in ?? ()
#5  0x00007fffffffd85b in ?? ()
#6  0x0000000000000000 in ?? ()
(gdb) PASS: gdb.base/break-probes.exp: ensure using probes
c
Continuing.
SVR4:PASS
Stopped due to shared library event:
  Inferior loaded /lib64/libdl.so.2
    /lib64/libm.so.6
    /lib64/libc.so.6
(gdb) c
Continuing.
SVR4:PASS
Stopped due to shared library event (no libraries added or removed)
(gdb) c
Continuing.
SVR4:PASS
Stopped due to shared library event:
  Inferior loaded /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/gdb.base/break-probes-solib.so
(gdb) PASS: gdb.base/break-probes.exp: run til our library loads
call foo(23)
$1 = 31
(gdb) PASS: gdb.base/break-probes.exp: call foo(23)
testcase ../../../src/gdb/testsuite/gdb.base/break-probes.exp completed in 0 seconds

		=== gdb Summary ===

# of expected passes		4
Executing on host: /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/../data-directory --version    (timeout = 300)
spawn -ignore SIGHUP /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/../data-directory --version
GNU gdb (GDB) 7.5.50.20120815-cvs
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
/home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/../../gdb/gdb version  7.5.50.20120815-cvs -nw -nx -data-directory /home/gary/work/gdb/archer-gbenson-stap-rtld-mainline/build/gdb/testsuite/../data-directory 

runtest completed at Fri Sep 21 13:32:44 2012

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-09-21 12:36           ` Gary Benson
@ 2012-09-21 14:46             ` Jan Kratochvil
  2012-09-28 10:51               ` Gary Benson
  0 siblings, 1 reply; 19+ messages in thread
From: Jan Kratochvil @ 2012-09-21 14:46 UTC (permalink / raw)
  To: gdb-patches

Hi Gary,

On Fri, 21 Sep 2012 14:35:56 +0200, Gary Benson wrote:
> I've also passed --with-expat to force the issue.  I'm not seeing the
> XML warning any more, but the tests are still using the probes code
> and not the code from linux-low.c.

The tests are using linux-low.c:

../gdb gdb.base/break-probes -ex 'target remote localhost:1234' -ex 'set stop-on-solib-events 1' -ex 'set debug remote 1' -ex c
[...]
Sending packet: $qXfer:libraries-svr4:read::0,fff#91...Packet received: l<library-list-svr4 version="1.0" main-lm="0x7ffff7ffe2a8"><library name="/lib64/ld-linux-x86-64.so.2" lm="0x7ffff7ffd998" l_addr="0x7ffff7ddc000" l_ld="0x7ffff7ffcdd8"/></library-list-svr4>
SVR4:PASS
Sending packet: $z0,7ffff7ddf702,1#00...Packet received: OK
[...]
Sending packet: $z0,7ffff7df0285,1#d2...Packet received: OK
Stopped due to shared library event (no libraries added or removed)
(gdb) _

It has stopped on probe due to stop_on_solib_events == 1 but that is unrelated
to how solib-svr4.c fetches the library list.

I see the implementation for the linux-low.c side may not be so easy as
I thought about before.

GDB still needs to stop at the stap probes as it does but:

 * gdbserver needs to fetch probe arguments on its own.  Therefore GDB client
   needs to compile the arguments into AX (agent-expression) and upload them
   to gdbserver.  gdbserver then can do the incremental fetching of solist
   entries like solib-svr4.c with your patches does.

   * svr4_handle_solib_event should disable updating the local list of shared
     libraries as svr4_current_sos->svr4_current_sos_via_xfer_libraries will
     accomplish everything without needing svr4_handle_solib_event.

 * It could transfer only differences of <library-list-svr4> although that is
   an add-on optional feature.  The major reason for implementing
   <library-list-svr4> was the high amount of pings over long latency links.
   The amound of transferred data over wire may not be such a concern.
   Although with your high-performance solib goals it may be also your goal.

I had to clear it up for myself so I wrote it down, I hope I have it right.


Thanks,
Jan


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-09-21 14:46             ` Jan Kratochvil
@ 2012-09-28 10:51               ` Gary Benson
  2012-09-28 10:58                 ` Jan Kratochvil
  0 siblings, 1 reply; 19+ messages in thread
From: Gary Benson @ 2012-09-28 10:51 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gdb-patches

Jan Kratochvil wrote:
> On Fri, 21 Sep 2012 14:35:56 +0200, Gary Benson wrote:
> > I've also passed --with-expat to force the issue.  I'm not seeing the
> > XML warning any more, but the tests are still using the probes code
> > and not the code from linux-low.c.
> 
> The tests are using linux-low.c:
> 
> ../gdb gdb.base/break-probes -ex 'target remote localhost:1234' -ex 'set stop-on-solib-events 1' -ex 'set debug remote 1' -ex c
> [...]
> Sending packet: $qXfer:libraries-svr4:read::0,fff#91...Packet received: l<library-list-svr4 version="1.0" main-lm="0x7ffff7ffe2a8"><library name="/lib64/ld-linux-x86-64.so.2" lm="0x7ffff7ffd998" l_addr="0x7ffff7ddc000" l_ld="0x7ffff7ffcdd8"/></library-list-svr4>
> SVR4:PASS
> Sending packet: $z0,7ffff7ddf702,1#00...Packet received: OK
> [...]
> Sending packet: $z0,7ffff7df0285,1#d2...Packet received: OK
> Stopped due to shared library event (no libraries added or removed)
> (gdb) _
> 
> It has stopped on probe due to stop_on_solib_events == 1 but that is unrelated
> to how solib-svr4.c fetches the library list.

I'm seeing this too now.  I think I assumed gdbserver would be
responsible for everything, but that's not the case; gdb sets the
breakpoints, so in this configuration it's stopping at the probes
breakpoints but using the old-style code in linux-low.c to fetch
the library list.  This explains why the testcases see the probes
breakpoints, and why the check for PR 2328 doesn't segfault.

> I see the implementation for the linux-low.c side may not be so easy
> as I thought about before.
> 
> GDB still needs to stop at the stap probes as it does but:
> 
>  * gdbserver needs to fetch probe arguments on its own.  Therefore GDB client
>    needs to compile the arguments into AX (agent-expression) and upload them
>    to gdbserver.  gdbserver then can do the incremental fetching of solist
>    entries like solib-svr4.c with your patches does.
> 
>  * svr4_handle_solib_event should disable updating the local list of shared
>    libraries as svr4_current_sos->svr4_current_sos_via_xfer_libraries will
>    accomplish everything without needing svr4_handle_solib_event.
> 
>  * It could transfer only differences of <library-list-svr4> although that is
>    an add-on optional feature.  The major reason for implementing
>    <library-list-svr4> was the high amount of pings over long latency links.
>    The amound of transferred data over wire may not be such a concern.
>    Although with your high-performance solib goals it may be also your goal.
> 
> I had to clear it up for myself so I wrote it down, I hope I have it
> right.

Ah, I wondered if the stap code was in gdbserver, but apparently not.

dlmopen support requires the local cache that incremental updating
uses, because when you stop to update a namespace's so_list you can
only see the address of that namespace in the inferior.  The other
namespace's so_lists are fetched from the cache, so either gdb or
gdbserver will have to maintain a cache somewhere.  I'm tempted to
retain the cache in gdb, and have gdbserver send namespace updates.

I'm trying to understand the existing interface between gdb and
gdbserver.  Does gdb request a library list and gdbserver send one,
or does gdbserver recognise the stop and send one, and gdb assumes
it's been sent one and try to read it?

Thanks,
Gary

-- 
http://gbenson.net/


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [RFA 4/4 take 2] Improved linker-debugger interface
  2012-09-28 10:51               ` Gary Benson
@ 2012-09-28 10:58                 ` Jan Kratochvil
  0 siblings, 0 replies; 19+ messages in thread
From: Jan Kratochvil @ 2012-09-28 10:58 UTC (permalink / raw)
  To: gdb-patches

On Fri, 28 Sep 2012 12:51:45 +0200, Gary Benson wrote:
> dlmopen support requires the local cache that incremental updating
> uses, because when you stop to update a namespace's so_list you can
> only see the address of that namespace in the inferior.  The other
> namespace's so_lists are fetched from the cache, so either gdb or
> gdbserver will have to maintain a cache somewhere.  I'm tempted to
> retain the cache in gdb, and have gdbserver send namespace updates.

I believe it is needed to resolve the dlmopen support from core files.
Otherwise this new code may be based on wrong expectations.

If you are not going to implement dlmopen from core files please drop the
dlmopen support.


> I'm trying to understand the existing interface between gdb and
> gdbserver.  Does gdb request a library list and gdbserver send one,

Yes.

> or does gdbserver recognise the stop and send one, and gdb assumes
> it's been sent one and try to read it?

No.

GDB still places the breakpoint (formerly at _dl_debug_state) and when it is
hit gdb->gdbserver sends the request packet: $qXfer:libraries-svr4:read::0,fff#


Thanks,
Jan


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2012-09-28 10:58 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-19 11:09 [RFA 4/4 take 2] Improved linker-debugger interface Gary Benson
2012-07-25 19:36 ` Tom Tromey
2012-07-31 12:12   ` Gary Benson
2012-07-31 12:13     ` Gary Benson
2012-08-14 19:49       ` Tom Tromey
2012-08-15 17:24 ` Jan Kratochvil
2012-08-15 17:46   ` Jan Kratochvil
2012-08-16 11:14     ` Gary Benson
2012-08-16 15:52     ` Gary Benson
2012-08-17 10:54       ` Gary Benson
2012-08-17 16:41         ` Jan Kratochvil
2012-09-19  9:49   ` Gary Benson
2012-09-19 11:14     ` Jan Kratochvil
2012-09-19 15:06       ` Gary Benson
2012-09-19 15:13         ` Jan Kratochvil
2012-09-21 12:36           ` Gary Benson
2012-09-21 14:46             ` Jan Kratochvil
2012-09-28 10:51               ` Gary Benson
2012-09-28 10:58                 ` Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox