Implement attach/detach for multi-threaded programs on Linux.
[deliverable/binutils-gdb.git] / gdb / symfile.c
index 05fd4fbacf1aaf237e5cc0aecc5af5ed7c4b769f..b644af8df26ae1f335ead1bf2f09e4c62054fb91 100644 (file)
@@ -1,5 +1,6 @@
 /* Generic symbol file reading for the GNU debugger, GDB.
-   Copyright 1990-1996, 1998, 2000 Free Software Foundation, Inc.
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+   2000, 2001 Free Software Foundation, Inc.
    Contributed by Cygnus Support, using pieces from other GDB modules.
 
    This file is part of GDB.
@@ -37,7 +38,6 @@
 #include "gdb-stabs.h"
 #include "obstack.h"
 
-#include <assert.h>
 #include <sys/types.h>
 #include <fcntl.h>
 #include "gdb_string.h"
@@ -212,7 +212,7 @@ compare_symbols (const PTR s1p, const PTR s2p)
 
   s1 = (struct symbol **) s1p;
   s2 = (struct symbol **) s2p;
-  return (STRCMP (SYMBOL_SOURCE_NAME (*s1), SYMBOL_SOURCE_NAME (*s2)));
+  return (strcmp (SYMBOL_SOURCE_NAME (*s1), SYMBOL_SOURCE_NAME (*s2)));
 }
 
 /*
@@ -259,18 +259,6 @@ compare_psymbols (const PTR s1p, const PTR s2p)
     }
   else
     {
-      /* Note: I replaced the STRCMP line (commented out below)
-       * with a simpler "strcmp()" which compares the 2 strings
-       * from the beginning. (STRCMP is a macro which first compares
-       * the initial characters, then falls back on strcmp).
-       * The reason is that the STRCMP line was tickling a C compiler
-       * bug on HP-UX 10.30, which is avoided with the simpler
-       * code. The performance gain from the more complicated code
-       * is negligible, given that we have already checked the
-       * initial 2 characters above. I reported the compiler bug,
-       * and once it is fixed the original line can be put back. RT
-       */
-      /* return ( STRCMP (st1 + 2, st2 + 2)); */
       return (strcmp (st1, st2));
     }
 }
@@ -490,8 +478,8 @@ free_section_addr_info (struct section_addr_info *sap)
 
   for (idx = 0; idx < MAX_SECTIONS; idx++)
     if (sap->other[idx].name)
-      free (sap->other[idx].name);
-  free (sap);
+      xfree (sap->other[idx].name);
+  xfree (sap);
 }
 
 
@@ -908,6 +896,41 @@ symbol_file_add (char *name, int from_tty, struct section_addr_info *addrs,
   return (objfile);
 }
 
+/* Just call the above with default values.
+   Used when the file is supplied in the gdb command line. */
+   
+void
+symbol_file_add_main (char *args, int from_tty)
+{
+  symbol_file_add (args, from_tty, NULL, 1, 0);
+}
+
+void
+symbol_file_clear (int from_tty)
+{
+  if ((have_full_symbols () || have_partial_symbols ())
+      && from_tty
+      && !query ("Discard symbol table from `%s'? ",
+                symfile_objfile->name))
+    error ("Not confirmed.");
+    free_all_objfiles ();
+
+    /* solib descriptors may have handles to objfiles.  Since their
+       storage has just been released, we'd better wipe the solib
+       descriptors as well.
+     */
+#if defined(SOLIB_RESTART)
+    SOLIB_RESTART ();
+#endif
+
+    symfile_objfile = NULL;
+    if (from_tty)
+      printf_unfiltered ("No symbol file now.\n");
+#ifdef HPUXHPPA
+    RESET_HP_UX_GLOBALS ();
+#endif
+}
+
 /* This is the symbol-file command.  Read the file, analyze its
    symbols, and add a struct symtab to a symtab list.  The syntax of
    the command is rather bizarre--(1) buildargv implements various
@@ -934,27 +957,7 @@ symbol_file_command (char *args, int from_tty)
 
   if (args == NULL)
     {
-      if ((have_full_symbols () || have_partial_symbols ())
-         && from_tty
-         && !query ("Discard symbol table from `%s'? ",
-                    symfile_objfile->name))
-       error ("Not confirmed.");
-      free_all_objfiles ();
-
-      /* solib descriptors may have handles to objfiles.  Since their
-         storage has just been released, we'd better wipe the solib
-         descriptors as well.
-       */
-#if defined(SOLIB_RESTART)
-      SOLIB_RESTART ();
-#endif
-
-      symfile_objfile = NULL;
-      if (from_tty)
-         printf_unfiltered ("No symbol file now.\n");
-#ifdef HPUXHPPA
-      RESET_HP_UX_GLOBALS ();
-#endif
+      symbol_file_clear (from_tty);
     }
   else
     {
@@ -1049,7 +1052,7 @@ symfile_bfd_open (char *name)
 
   /* Look down path for it, allocate 2nd new malloc'd copy.  */
   desc = openp (getenv ("PATH"), 1, name, O_RDONLY | O_BINARY, 0, &absolute_name);
-#if defined(__GO32__) || defined(_WIN32)
+#if defined(__GO32__) || defined(_WIN32) || defined (__CYGWIN__)
   if (desc < 0)
     {
       char *exename = alloca (strlen (name) + 5);
@@ -1060,10 +1063,10 @@ symfile_bfd_open (char *name)
 #endif
   if (desc < 0)
     {
-      make_cleanup (free, name);
+      make_cleanup (xfree, name);
       perror_with_name (name);
     }
-  free (name);                 /* Free 1st new malloc'd copy */
+  xfree (name);                        /* Free 1st new malloc'd copy */
   name = absolute_name;                /* Keep 2nd malloc'd copy in bfd */
   /* It'll be freed in free_objfile(). */
 
@@ -1071,7 +1074,7 @@ symfile_bfd_open (char *name)
   if (!sym_bfd)
     {
       close (desc);
-      make_cleanup (free, name);
+      make_cleanup (xfree, name);
       error ("\"%s\": can't open to read symbols: %s.", name,
             bfd_errmsg (bfd_get_error ()));
     }
@@ -1083,7 +1086,7 @@ symfile_bfd_open (char *name)
          on error it does not free all the storage associated with the
          bfd).  */
       bfd_close (sym_bfd);     /* This also closes desc */
-      make_cleanup (free, name);
+      make_cleanup (xfree, name);
       error ("\"%s\": can't read symbols: %s.", name,
             bfd_errmsg (bfd_get_error ()));
     }
@@ -1171,7 +1174,7 @@ generic_load (char *args, int from_tty)
   /* Parse the input argument - the user can specify a load offset as
      a second argument. */
   filename = xmalloc (strlen (args) + 1);
-  old_cleanups = make_cleanup (free, filename);
+  old_cleanups = make_cleanup (xfree, filename);
   strcpy (filename, args);
   offptr = strchr (filename, ' ');
   if (offptr != NULL)
@@ -1231,7 +1234,7 @@ generic_load (char *args, int from_tty)
                block_size = size;
 
              buffer = xmalloc (size);
-             old_chain = make_cleanup (free, buffer);
+             old_chain = make_cleanup (xfree, buffer);
 
              /* Is this really necessary?  I guess it gives the user something
                 to look at during a long download.  */
@@ -1268,7 +1271,7 @@ generic_load (char *args, int from_tty)
                          that.  remote.c could implement that method
                          using the ``qCRC'' packet.  */
                      char *check = xmalloc (len);
-                     struct cleanup *verify_cleanups = make_cleanup (free, check);
+                     struct cleanup *verify_cleanups = make_cleanup (xfree, check);
                      if (target_read_memory (lma, check, len) != 0)
                        error ("Download verify read failed at 0x%s",
                               paddr (lma));
@@ -1416,7 +1419,7 @@ add_symbol_file_command (char *args, int from_tty)
   } sect_opts[SECT_OFF_MAX];
 
   struct section_addr_info section_addrs;
-  struct cleanup *my_cleanups;
+  struct cleanup *my_cleanups = make_cleanup (null_cleanup, NULL);
 
   dont_repeat ();
 
@@ -1452,7 +1455,7 @@ add_symbol_file_command (char *args, int from_tty)
        {
          /* The first argument is the file name. */
          filename = tilde_expand (arg);
-         my_cleanups = make_cleanup (free, filename);
+         make_cleanup (xfree, filename);
        }
       else
        if (argcnt == 1)
@@ -1684,13 +1687,13 @@ reread_symbols (void)
              /* obstack_specify_allocation also initializes the obstack so
                 it is empty.  */
              obstack_specify_allocation (&objfile->psymbol_cache.cache, 0, 0,
-                                         xmalloc, free);
+                                         xmalloc, xfree);
              obstack_specify_allocation (&objfile->psymbol_obstack, 0, 0,
-                                         xmalloc, free);
+                                         xmalloc, xfree);
              obstack_specify_allocation (&objfile->symbol_obstack, 0, 0,
-                                         xmalloc, free);
+                                         xmalloc, xfree);
              obstack_specify_allocation (&objfile->type_obstack, 0, 0,
-                                         xmalloc, free);
+                                         xmalloc, xfree);
              if (build_objfile_section_table (objfile))
                {
                  error ("Can't find the file sections in `%s': %s",
@@ -1778,11 +1781,11 @@ add_filename_language (char *ext, enum language lang)
   if (fl_table_next >= fl_table_size)
     {
       fl_table_size += 10;
-      filename_language_table = realloc (filename_language_table,
-                                        fl_table_size);
+      filename_language_table = xrealloc (filename_language_table,
+                                         fl_table_size);
     }
 
-  filename_language_table[fl_table_next].ext = strsave (ext);
+  filename_language_table[fl_table_next].ext = xstrdup (ext);
   filename_language_table[fl_table_next].lang = lang;
   fl_table_next++;
 }
@@ -1840,8 +1843,8 @@ set_ext_lang_command (char *args, int from_tty)
       /*   query ("Really make files of type %s '%s'?", */
       /*          ext_args, language_str (lang));           */
 
-      free (filename_language_table[i].ext);
-      filename_language_table[i].ext = strsave (ext_args);
+      xfree (filename_language_table[i].ext);
+      filename_language_table[i].ext = xstrdup (ext_args);
       filename_language_table[i].lang = lang;
     }
 }
@@ -2953,7 +2956,7 @@ static void
 simple_free_overlay_table (void)
 {
   if (cache_ovly_table)
-    free (cache_ovly_table);
+    xfree (cache_ovly_table);
   cache_novlys = 0;
   cache_ovly_table = NULL;
   cache_ovly_table_base = 0;
@@ -2965,7 +2968,7 @@ static void
 simple_free_overlay_region_table (void)
 {
   if (cache_ovly_region_table)
-    free (cache_ovly_region_table);
+    xfree (cache_ovly_region_table);
   cache_novly_regions = 0;
   cache_ovly_region_table = NULL;
   cache_ovly_region_table_base = 0;
This page took 0.027104 seconds and 4 git commands to generate.