This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] solib-svr4.c: Warn if no shared library support


I've just committed the patch below.

For a (non-native) Linux/MIPS target, if you do:

    set osabi none

and then connect to the remote target, you'll (eventually) see an
internal error similar to the following:

    .../solib-svr4.c:1368: internal-error: legacy_fetch_link_map_offsets
    called without legacy link_map support enabled.
    A problem internal to GDB has been detected.  Further
    debugging may prove unreliable.

The patch below will cause a warning to be printed instead when connecting
to the target:

    warning: no shared library support for this OS / ABI

This makes debugging somewhat more reliable (assuming that you knew
what you were doing when setting osabi in the first place).

Native targets are unaffected because they pick up shared library
via the host's <link.h> file.  That said, this support is quite
likely wrong when changing the osabi to a value for which no shared
library support has been defined.

Thanks (again) to Chris Demetriou for bringing this problem to my
attention.

	* solib-svr4.c (svr4_have_link_map_offsets): New function.
	(locate_base): Return early if there aren't any link map offsets.
	(svr4_solib_create_inferior_hook): Warn if shared library support
	is unavailable.

Index: solib-svr4.c
===================================================================
RCS file: /cvs/src/src/gdb/solib-svr4.c,v
retrieving revision 1.31
diff -u -p -r1.31 solib-svr4.c
--- solib-svr4.c	8 Apr 2003 19:21:15 -0000	1.31
+++ solib-svr4.c	15 Apr 2003 00:26:43 -0000
@@ -43,6 +43,7 @@
 
 static struct link_map_offsets *svr4_fetch_link_map_offsets (void);
 static struct link_map_offsets *legacy_fetch_link_map_offsets (void);
+static int svr4_have_link_map_offsets (void);
 
 /* fetch_link_map_offsets_gdbarch_data is a handle used to obtain the
    architecture specific link map offsets fetching function.  */
@@ -542,9 +543,10 @@ locate_base (void)
   /* Check to see if we have a currently valid address, and if so, avoid
      doing all this work again and just return the cached address.  If
      we have no cached address, try to locate it in the dynamic info
-     section for ELF executables.  */
+     section for ELF executables.  There's no point in doing any of this
+     though if we don't have some link map offsets to work with.  */
 
-  if (debug_base == 0)
+  if (debug_base == 0 && svr4_have_link_map_offsets ())
     {
       if (exec_bfd != NULL
 	  && bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
@@ -1273,6 +1275,13 @@ svr4_solib_create_inferior_hook (void)
   /* Relocate the main executable if necessary.  */
   svr4_relocate_main_executable ();
 
+  if (!svr4_have_link_map_offsets ())
+    {
+      warning ("no shared library support for this OS / ABI");
+      return;
+
+    }
+
   if (!enable_break ())
     {
       warning ("shared library handler failed to enable breakpoint");
@@ -1390,6 +1399,20 @@ svr4_fetch_link_map_offsets (void)
     }
   else
     return (flmo ());
+}
+
+/* Return 1 if a link map offset fetcher has been defined, 0 otherwise.  */
+static int
+svr4_have_link_map_offsets (void)
+{
+  struct link_map_offsets *(*flmo)(void) =
+    gdbarch_data (current_gdbarch, fetch_link_map_offsets_gdbarch_data);
+  if (flmo == NULL
+      || (flmo == legacy_fetch_link_map_offsets 
+          && legacy_svr4_fetch_link_map_offsets_hook == NULL))
+    return 0;
+  else
+    return 1;
 }
 
 /* set_solib_svr4_fetch_link_map_offsets() is intended to be called by


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]