doc/gdbinv-s.m4.in: remove text on special procedures to continue after
[deliverable/binutils-gdb.git] / gdb / solib.c
index f2f646d17f00e4fab48852a5eed1b2330f663a49..d9ec31818fca9d5381416fea54a07c41900f006a 100644 (file)
@@ -26,11 +26,16 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <link.h>
 #include <sys/param.h>
 #include <fcntl.h>
-#include <a.out.h>
+
+#ifndef SVR4_SHARED_LIBS
+ /* SunOS shared libs need the nlist structure.  */
+#include <a.out.h> 
+#endif
 
 #include "symtab.h"
 #include "bfd.h"
 #include "symfile.h"
+#include "objfiles.h"
 #include "gdbcore.h"
 #include "command.h"
 #include "target.h"
@@ -89,12 +94,16 @@ struct so_list {
   struct objfile *objfile;             /* objfile for loaded lib */
   struct section_table *sections;
   struct section_table *sections_end;
+  struct section_table *textsection;
 };
 
 static struct so_list *so_list_head;   /* List of known shared objects */
 static CORE_ADDR debug_base;           /* Base of dynamic linker structures */
 static CORE_ADDR breakpoint_addr;      /* Address where end bkpt is set */
 
+extern int
+fdmatch PARAMS ((int, int));           /* In libiberty */
+
 /* Local function prototypes */
 
 static void
@@ -110,7 +119,7 @@ static int
 disable_break PARAMS ((void));
 
 static void
-info_sharedlibrary_command PARAMS ((void));
+info_sharedlibrary_command PARAMS ((char *, int));
 
 static int
 symbol_add_stub PARAMS ((char *));
@@ -124,16 +133,18 @@ first_link_map_member PARAMS ((void));
 static CORE_ADDR
 locate_base PARAMS ((void));
 
+static void
+solib_map_sections PARAMS ((struct so_list *));
+
+#ifdef SVR4_SHARED_LIBS
+
 static int
 look_for_base PARAMS ((int, CORE_ADDR));
 
 static CORE_ADDR
 bfd_lookup_symbol PARAMS ((bfd *, char *));
 
-static void
-solib_map_sections PARAMS ((struct so_list *));
-
-#ifndef SVR4_SHARED_LIBS
+#else
 
 static void
 solib_add_common_symbols PARAMS ((struct rtc_symb *, struct objfile *));
@@ -216,6 +227,10 @@ solib_map_sections (so)
       p -> addr += (CORE_ADDR) LM_ADDR (so);
       p -> endaddr += (CORE_ADDR) LM_ADDR (so);
       so -> lmend = (CORE_ADDR) max (p -> endaddr, so -> lmend);
+      if (strcmp (p -> sec_ptr -> name, ".text") == 0)
+       {
+         so -> textsection = p;
+       }
     }
 }
 
@@ -287,6 +302,8 @@ solib_add_common_symbols (rtc_symp, objfile)
 
 #endif /* SVR4_SHARED_LIBS */
 
+#ifdef SVR4_SHARED_LIBS
+
 /*
 
 LOCAL FUNCTION
@@ -329,8 +346,8 @@ bfd_lookup_symbol (abfd, symname)
 
   if (storage_needed > 0)
     {
-      symbol_table = (asymbol **) bfd_xmalloc (storage_needed);
-      back_to = make_cleanup (free, symbol_table);
+      symbol_table = (asymbol **) xmalloc (storage_needed);
+      back_to = make_cleanup (free, (PTR)symbol_table);
       number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table); 
   
       for (i = 0; i < number_of_symbols; i++)
@@ -430,6 +447,8 @@ look_for_base (fd, baseaddr)
   return (1);
 }
 
+#endif
+
 /*
 
 LOCAL FUNCTION
@@ -653,7 +672,8 @@ symbol_add_stub (arg)
   register struct so_list *so = (struct so_list *) arg;        /* catch_errs bogon */
   
   so -> objfile = symbol_file_add (so -> so_name, so -> from_tty,
-                                  (unsigned int) LM_ADDR (so), 0, 0, 0);
+                                  (unsigned int) so -> textsection -> addr,
+                                  0, 0, 0);
   return (1);
 }
 
@@ -754,8 +774,9 @@ solib_add (arg_string, from_tty, target)
              if (so -> so_name[0])
                {
                  count = so -> sections_end - so -> sections;
-                 bcopy (so -> sections, (char *)(target -> to_sections + old), 
-                        (sizeof (struct section_table)) * count);
+                 (void) memcpy ((char *) (target -> to_sections + old),
+                                so -> sections, 
+                                (sizeof (struct section_table)) * count);
                  old += count;
                }
            }
@@ -780,7 +801,9 @@ DESCRIPTION
 */
 
 static void
-info_sharedlibrary_command ()
+info_sharedlibrary_command (ignore, from_tty)
+     char *ignore;
+     int from_tty;
 {
   register struct so_list *so = NULL;          /* link map state variable */
   int header_done = 0;
@@ -867,14 +890,14 @@ clear_solib()
     {
       if (so_list_head -> sections)
        {
-         free (so_list_head -> sections);
+         free ((PTR)so_list_head -> sections);
        }
       if (so_list_head -> so_bfd)
        {
          bfd_close (so_list_head -> so_bfd);
        }
       next = so_list_head -> next;
-      free(so_list_head);
+      free((PTR)so_list_head);
       so_list_head = next;
     }
   debug_base = 0;
@@ -992,12 +1015,11 @@ static int
 enable_break ()
 {
 
-  int j;
-
 #ifndef SVR4_SHARED_LIBS
 
+  int j;
   int in_debugger;
-  
+
   /* Get link_dynamic structure */
 
   j = target_read_memory (debug_base, (char *) &dynamic_copy,
@@ -1106,11 +1128,6 @@ FIXME
 void 
 solib_create_inferior_hook()
 {
-  CORE_ADDR debug_addr;
-  int in_debugger;
-  CORE_ADDR in_debugger_addr;
-  CORE_ADDR breakpoint_addr;
-  int i, j;
   
   if ((debug_base = locate_base ()) == 0)
     {
@@ -1187,11 +1204,34 @@ special_symbol_handling (so)
 struct so_list *so;
 {
 #ifndef SVR4_SHARED_LIBS
+  int j;
+
+  if (debug_addr == 0)
+    {
+      /* Get link_dynamic structure */
+
+      j = target_read_memory (debug_base, (char *) &dynamic_copy,
+                             sizeof (dynamic_copy));
+      if (j)
+       {
+         /* unreadable */
+         return;
+       }
+
+      /* Calc address of debugger interface structure */
+      /* FIXME, this needs work for cross-debugging of core files
+        (byteorder, size, alignment, etc).  */
+
+      debug_addr = (CORE_ADDR) dynamic_copy.ldd;
+    }
 
   /* Read the debugger structure from the inferior, just to make sure
      we have a current copy. */
 
-  read_memory (debug_addr, (char *) &debug_copy, sizeof (debug_copy));
+  j = target_read_memory (debug_addr, (char *) &debug_copy,
+                         sizeof (debug_copy));
+  if (j)
+    return;            /* unreadable */
 
   /* Get common symbol definitions for the loaded object. */
 
This page took 0.025921 seconds and 4 git commands to generate.