Speed up GDB startup time by not demangling partial symbols.
[binutils-gdb.git] / gdb / irix5-nat.c
index ad0321dddafb00d9a71d4d6cf8530a9412f8beed..f4137383b9195d75671e498fa1e361753d93c187 100644 (file)
@@ -1,5 +1,6 @@
 /* Native support for the SGI Iris running IRIX version 5, for GDB.
-   Copyright 1988, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+   Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994
+   Free Software Foundation, Inc.
    Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
    and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
    Implemented for Irix 4.x by Garrett A. Wollman.
@@ -193,31 +194,14 @@ fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
 #include "inferior.h"
 #include "language.h"
 
-/* We need to set a breakpoint at a point when we know that the
-   mapping of shared libraries is complete.  dbx simply breaks at main
-   (or, for FORTRAN, MAIN__), so we do the same.  We can not break at
-   the very beginning of main, because the startup code will jump into
-   main after the GP initialization instructions.  SOLIB_BKPT_OFFSET
-   is used to skip those instructions.  */
-
-#define SOLIB_BKPT_OFFSET 12
-
-static char *bkpt_names[] = {
-  "main",
-  "MAIN__",
-  NULL
-};
-
 /* The symbol which starts off the list of shared libraries.  */
 #define DEBUG_BASE "__rld_obj_head"
 
 /* How to get the loaded address of a shared library.  */
-#define LM_ADDR(so) ((so)->lm.o_base_address)
+#define LM_ADDR(so) ((so)->lm.o_praw)
 
 char shadow_contents[BREAKPOINT_MAX];  /* Stash old bkpt addr contents */
 
-extern CORE_ADDR sigtramp_address, sigtramp_end;
-
 struct so_list {
   struct so_list *next;                        /* next structure in linked list */
   struct obj_list ll;
@@ -303,6 +287,7 @@ solib_map_sections (so)
   struct section_table *p;
   struct cleanup *old_chain;
   bfd *abfd;
+  CORE_ADDR offset;
   
   filename = tilde_expand (so -> lm.o_path);
   old_chain = make_cleanup (free, filename);
@@ -342,13 +327,20 @@ solib_map_sections (so)
             bfd_get_filename (exec_bfd), bfd_errmsg (bfd_get_error ()));
     }
 
+  /* Irix 5 shared objects are pre-linked to particular addresses
+     although the dynamic linker may have to relocate them if the
+     address ranges of the libraries used by the main program clash.
+     The offset is the difference between the address where the object
+     is mapped and the binding address of the shared library.  */
+  offset = (CORE_ADDR) LM_ADDR (so) - so -> lm.o_base_address;
+
   for (p = so -> sections; p < so -> sections_end; p++)
     {
       /* Relocate the section binding addresses as recorded in the shared
-        object's file by the base address to which the object was actually
-        mapped. */
-      p -> addr += (CORE_ADDR) LM_ADDR (so);
-      p -> endaddr += (CORE_ADDR) LM_ADDR (so);
+        object's file by the offset to get the address to which the
+        object was actually mapped.  */
+      p -> addr += offset;
+      p -> endaddr += offset;
       so -> lmend = (CORE_ADDR) max (p -> endaddr, so -> lmend);
       if (STREQ (p -> the_bfd_section -> name, ".text"))
        {
@@ -606,36 +598,7 @@ solib_add (arg_string, from_tty, target)
       error ("Invalid regexp: %s", re_err);
     }
   
-  /* Getting new symbols may change our opinion about what is
-     frameless.  */
-  reinit_frame_cache ();
-  /* Not to mention where _sigtramp is.  */
-  sigtramp_address = 0;
-  
-  while ((so = find_solib (so)) != NULL)
-    {
-      if (so -> lm.o_path[0] && re_exec (so -> lm.o_path))
-       {
-         so -> from_tty = from_tty;
-         if (so -> symbols_loaded)
-           {
-             if (from_tty)
-               {
-                 printf_unfiltered ("Symbols already loaded for %s\n", so -> lm.o_path);
-               }
-           }
-         else if (catch_errors
-                  (symbol_add_stub, (char *) so,
-                   "Error while reading shared library symbols:\n",
-                   RETURN_MASK_ALL))
-           {
-             so_last = so;
-             so -> symbols_loaded = 1;
-           }
-       }
-    }
-  
-  /* Now add the shared library sections to the section table of the
+  /* Add the shared library sections to the section table of the
      specified target, if any.  */
   if (target)
     {
@@ -682,6 +645,35 @@ solib_add (arg_string, from_tty, target)
            }
        }
     }
+  
+  /* Now add the symbol files.  */
+  while ((so = find_solib (so)) != NULL)
+    {
+      if (so -> lm.o_path[0] && re_exec (so -> lm.o_path))
+       {
+         so -> from_tty = from_tty;
+         if (so -> symbols_loaded)
+           {
+             if (from_tty)
+               {
+                 printf_unfiltered ("Symbols already loaded for %s\n", so -> lm.o_path);
+               }
+           }
+         else if (catch_errors
+                  (symbol_add_stub, (char *) so,
+                   "Error while reading shared library symbols:\n",
+                   RETURN_MASK_ALL))
+           {
+             so_last = so;
+             so -> symbols_loaded = 1;
+           }
+       }
+    }
+
+  /* Getting new symbols may change our opinion about what is
+     frameless.  */
+  if (so_last)
+    reinit_frame_cache ();
 }
 
 /*
@@ -773,7 +765,7 @@ solib_address (address)
     {
       if (so -> lm.o_path[0])
        {
-         if ((address >= (CORE_ADDR) so->lm.o_base_address) &&
+         if ((address >= (CORE_ADDR) LM_ADDR (so)) &&
              (address < (CORE_ADDR) so -> lmend))
            {
              return (1);
@@ -871,84 +863,22 @@ SYNOPSIS
 
 DESCRIPTION
 
-       Both the SunOS and the SVR4 dynamic linkers have, as part of their
-       debugger interface, support for arranging for the inferior to hit
-       a breakpoint after mapping in the shared libraries.  This function
-       enables that breakpoint.
-
-       For SunOS, there is a special flag location (in_debugger) which we
-       set to 1.  When the dynamic linker sees this flag set, it will set
-       a breakpoint at a location known only to itself, after saving the
-       original contents of that place and the breakpoint address itself,
-       in it's own internal structures.  When we resume the inferior, it
-       will eventually take a SIGTRAP when it runs into the breakpoint.
-       We handle this (in a different place) by restoring the contents of
-       the breakpointed location (which is only known after it stops),
-       chasing around to locate the shared libraries that have been
-       loaded, then resuming.
-
-       For SVR4, the debugger interface structure contains a member (r_brk)
-       which is statically initialized at the time the shared library is
-       built, to the offset of a function (_r_debug_state) which is guaran-
-       teed to be called once before mapping in a library, and again when
-       the mapping is complete.  At the time we are examining this member,
-       it contains only the unrelocated offset of the function, so we have
-       to do our own relocation.  Later, when the dynamic linker actually
-       runs, it relocates r_brk to be the actual address of _r_debug_state().
-
-       The debugger interface structure also contains an enumeration which
-       is set to either RT_ADD or RT_DELETE prior to changing the mapping,
-       depending upon whether or not the library is being mapped or unmapped,
-       and then set to RT_CONSISTENT after the library is mapped/unmapped.
-
-       Irix 5, on the other hand, has no such features.  Instead, we
-       set a breakpoint at main.
+       This functions inserts a breakpoint at the entry point of the
+       main executable, where all shared libraries are mapped in.
 */
 
 static int
 enable_break ()
 {
-  int success = 0;
-  struct minimal_symbol *msymbol;
-  char **bkpt_namep;
-  CORE_ADDR bkpt_addr;
-
-  /* Scan through the list of symbols, trying to look up the symbol and
-     set a breakpoint there.  Terminate loop when we/if we succeed. */
-
-  breakpoint_addr = 0;
-  for (bkpt_namep = bkpt_names; *bkpt_namep != NULL; bkpt_namep++)
+  if (symfile_objfile != NULL
+      && target_insert_breakpoint (symfile_objfile->ei.entry_point,
+                                  shadow_contents) == 0)
     {
-      msymbol = lookup_minimal_symbol (*bkpt_namep, symfile_objfile);
-      if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
-       {
-         bkpt_addr = SYMBOL_VALUE_ADDRESS (msymbol);
-#ifdef SOLIB_BKPT_OFFSET
-         /* We only want to skip if bkpt_addr is currently pointing
-            at a GP setting instruction.  */
-         {
-           char buf[4];
-
-           if (target_read_memory (bkpt_addr, buf, 4) == 0)
-             {
-               unsigned long insn;
-
-               insn = extract_unsigned_integer (buf, 4);
-               if ((insn & 0xffff0000) == 0x3c1c0000) /* lui $gp,n */
-                 bkpt_addr += SOLIB_BKPT_OFFSET;
-             }
-         }
-#endif
-         if (target_insert_breakpoint (bkpt_addr, shadow_contents) == 0)
-           {
-             breakpoint_addr = bkpt_addr;
-             success = 1;
-             break;
-           }
-       }
+      breakpoint_addr = symfile_objfile->ei.entry_point;
+      return 1;
     }
 
-  return (success);
+  return 0;
 }
   
 /*
@@ -1026,7 +956,6 @@ solib_create_inferior_hook()
       wait_for_inferior ();
     }
   while (stop_signal != SIGTRAP);
-  stop_soon_quietly = 0;
   
   /* We are now either at the "mapping complete" breakpoint (or somewhere
      else, a condition we aren't prepared to deal with anyway), so adjust
@@ -1044,7 +973,14 @@ solib_create_inferior_hook()
       warning ("shared library handler failed to disable breakpoint");
     }
 
+  /*  solib_add will call reinit_frame_cache.
+      But we are stopped in the startup code and we might not have symbols
+      for the startup code, so heuristic_proc_start could be called
+      and will put out an annoying warning.
+      Delaying the resetting of stop_soon_quietly until after symbol loading
+      suppresses the warning.  */
   solib_add ((char *) 0, 0, (struct target_ops *) 0);
+  stop_soon_quietly = 0;
 }
 
 /*