* stabsread.c (get_substring): Declare second arg as int.
[deliverable/binutils-gdb.git] / gdb / irix5-nat.c
index 74004d41d4a1d7ac0e6eafbb0ae5701db3d8956b..fc4c8cb10425a149da7d002fb8c02ca4c27733f8 100644 (file)
@@ -1,5 +1,5 @@
 /* Native support for the SGI Iris running IRIX version 5, for GDB.
-   Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994
+   Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
    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.
@@ -20,13 +20,14 @@ 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, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
 #include "inferior.h"
 #include "gdbcore.h"
 #include "target.h"
 
+#include "gdb_string.h"
 #include <sys/time.h>
 #include <sys/procfs.h>
 #include <setjmp.h>            /* For JB_XXX.  */
@@ -48,6 +49,7 @@ supply_gregset (gregsetp)
 {
   register int regi;
   register greg_t *regp = &(*gregsetp)[0];
+  static char zerobuf[MAX_REGISTER_RAW_SIZE] = {0};
 
   for(regi = 0; regi <= CTX_RA; regi++)
     supply_register (regi, (char *)(regp + regi));
@@ -56,6 +58,9 @@ supply_gregset (gregsetp)
   supply_register (HI_REGNUM, (char *)(regp + CTX_MDHI));
   supply_register (LO_REGNUM, (char *)(regp + CTX_MDLO));
   supply_register (CAUSE_REGNUM, (char *)(regp + CTX_CAUSE));
+
+  /* Fill inaccessible registers with zero.  */
+  supply_register (BADVADDR_REGNUM, zerobuf);
 }
 
 void
@@ -74,7 +79,7 @@ fill_gregset (gregsetp, regno)
     *(regp + CTX_EPC) = *(greg_t *) &registers[REGISTER_BYTE (PC_REGNUM)];
 
   if ((regno == -1) || (regno == CAUSE_REGNUM))
-    *(regp + CTX_CAUSE) = *(greg_t *) &registers[REGISTER_BYTE (PS_REGNUM)];
+    *(regp + CTX_CAUSE) = *(greg_t *) &registers[REGISTER_BYTE (CAUSE_REGNUM)];
 
   if ((regno == -1) || (regno == HI_REGNUM))
     *(regp + CTX_MDHI) = *(greg_t *) &registers[REGISTER_BYTE (HI_REGNUM)];
@@ -96,6 +101,7 @@ supply_fpregset (fpregsetp)
      fpregset_t *fpregsetp;
 {
   register int regi;
+  static char zerobuf[MAX_REGISTER_RAW_SIZE] = {0};
 
   for (regi = 0; regi < 32; regi++)
     supply_register (FP0_REGNUM + regi,
@@ -104,6 +110,7 @@ supply_fpregset (fpregsetp)
   supply_register (FCRCS_REGNUM, (char *)&fpregsetp->fp_csr);
 
   /* FIXME: how can we supply FCRIR_REGNUM?  SGI doesn't tell us. */
+  supply_register (FCRIR_REGNUM, zerobuf);
 }
 
 void
@@ -152,7 +159,7 @@ get_longjmp_target (pc)
   return 1;
 }
 
-void
+static void
 fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
      char *core_reg_sect;
      unsigned core_reg_size;
@@ -173,7 +180,6 @@ fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
 
 #include <sys/types.h>
 #include <signal.h>
-#include <string.h>
 #include <sys/param.h>
 #include <fcntl.h>
 
@@ -190,24 +196,10 @@ fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
 #include "objfiles.h"
 #include "command.h"
 #include "frame.h"
-#include "regex.h"
+#include "gnu-regex.h"
 #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
-};
+#include "gdbcmd.h"
 
 /* The symbol which starts off the list of shared libraries.  */
 #define DEBUG_BASE "__rld_obj_head"
@@ -420,7 +412,7 @@ locate_base ()
   struct minimal_symbol *msymbol;
   CORE_ADDR address = 0;
 
-  msymbol = lookup_minimal_symbol (DEBUG_BASE, symfile_objfile);
+  msymbol = lookup_minimal_symbol (DEBUG_BASE, NULL, symfile_objfile);
   if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
     {
       address = SYMBOL_VALUE_ADDRESS (msymbol);
@@ -614,9 +606,7 @@ solib_add (arg_string, from_tty, target)
     }
   
   /* Add the shared library sections to the section table of the
-     specified target, if any. We have to do this before reading the
-     symbol files as symbol_file_add calls reinit_frame_cache and
-     creating a new frame might access memory in the shared library.  */
+     specified target, if any.  */
   if (target)
     {
       /* Count how many new section_table entries there are.  */
@@ -632,6 +622,13 @@ solib_add (arg_string, from_tty, target)
       
       if (count)
        {
+         int update_coreops;
+
+         /* We must update the to_sections field in the core_ops structure
+            here, otherwise we dereference a potential dangling pointer
+            for each call to target_read/write_memory within this routine.  */
+         update_coreops = core_ops.to_sections == target->to_sections;
+            
          /* Reallocate the target's section table including the new size.  */
          if (target -> to_sections)
            {
@@ -648,6 +645,14 @@ solib_add (arg_string, from_tty, target)
            }
          target -> to_sections_end = target -> to_sections + (count + old);
          
+         /* Update the to_sections field in the core_ops structure
+            if needed.  */
+         if (update_coreops)
+           {
+             core_ops.to_sections = target->to_sections;
+             core_ops.to_sections_end = target->to_sections_end;
+           }
+
          /* Add these section table entries to the target's table.  */
          while ((so = find_solib (so)) != NULL)
            {
@@ -686,6 +691,11 @@ solib_add (arg_string, from_tty, target)
            }
        }
     }
+
+  /* Getting new symbols may change our opinion about what is
+     frameless.  */
+  if (so_last)
+    reinit_frame_cache ();
 }
 
 /*
@@ -751,7 +761,7 @@ GLOBAL FUNCTION
 
 SYNOPSIS
 
-       int solib_address (CORE_ADDR address)
+       char *solib_address (CORE_ADDR address)
 
 DESCRIPTION
 
@@ -767,7 +777,7 @@ DESCRIPTION
        mapped in.
  */
 
-int
+char *
 solib_address (address)
      CORE_ADDR address;
 {
@@ -779,9 +789,7 @@ solib_address (address)
        {
          if ((address >= (CORE_ADDR) LM_ADDR (so)) &&
              (address < (CORE_ADDR) so -> lmend))
-           {
-             return (1);
-           }
+           return (so->lm.o_path);
        }
     }
   return (0);
@@ -804,7 +812,9 @@ clear_solib()
       if (so_list_head -> abfd)
        {
          bfd_filename = bfd_get_filename (so_list_head -> abfd);
-         bfd_close (so_list_head -> abfd);
+         if (!bfd_close (so_list_head -> abfd))
+           warning ("cannot close \"%s\": %s",
+                    bfd_filename, bfd_errmsg (bfd_get_error ()));
        }
       else
        /* This happens for the executable on SVR4.  */
@@ -875,84 +885,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;
 }
   
 /*
@@ -1030,7 +978,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
@@ -1048,7 +995,15 @@ solib_create_inferior_hook()
       warning ("shared library handler failed to disable breakpoint");
     }
 
-  solib_add ((char *) 0, 0, (struct target_ops *) 0);
+  /*  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.  */
+  if (auto_solib_add)
+    solib_add ((char *) 0, 0, (struct target_ops *) 0);
+  stop_soon_quietly = 0;
 }
 
 /*
@@ -1077,9 +1032,36 @@ int from_tty;
 void
 _initialize_solib()
 {
-  
   add_com ("sharedlibrary", class_files, sharedlibrary_command,
           "Load shared object library symbols for files matching REGEXP.");
   add_info ("sharedlibrary", info_sharedlibrary_command, 
            "Status of loaded shared object libraries.");
+
+  add_show_from_set
+    (add_set_cmd ("auto-solib-add", class_support, var_zinteger,
+                 (char *) &auto_solib_add,
+                 "Set autoloading of shared library symbols.\n\
+If nonzero, symbols from all shared object libraries will be loaded\n\
+automatically when the inferior begins execution or when the dynamic linker\n\
+informs gdb that a new library has been loaded.  Otherwise, symbols\n\
+must be loaded manually, using `sharedlibrary'.",
+                 &setlist),
+     &showlist);
+}
+
+\f
+/* Register that we are able to handle irix5 core file formats.
+   This really is bfd_target_unknown_flavour */
+
+static struct core_fns irix5_core_fns =
+{
+  bfd_target_unknown_flavour,
+  fetch_core_registers,
+  NULL
+};
+
+void
+_initialize_core_irix5 ()
+{
+  add_core_fns (&irix5_core_fns);
 }
This page took 0.02717 seconds and 4 git commands to generate.