Fix "nosharedlibrary + continue + shared lib event" crash
[binutils-gdb.git] / gdb / machoread.c
index 230bd860a425af167fb774b2bd6b84a80685c6f6..84e39fdf88550bb128813866e7f1b7788eb2017b 100644 (file)
@@ -1,5 +1,5 @@
 /* Darwin support for GDB, the GNU debugger.
-   Copyright (C) 2008-2018 Free Software Foundation, Inc.
+   Copyright (C) 2008-2019 Free Software Foundation, Inc.
 
    Contributed by AdaCore.
 
 #include "bfd.h"
 #include "symfile.h"
 #include "objfiles.h"
-#include "buildsym.h"
 #include "gdbcmd.h"
 #include "gdbcore.h"
 #include "mach-o.h"
 #include "aout/stab_gnu.h"
-#include "vec.h"
+#include "common/vec.h"
 #include "psympriv.h"
 #include "complaints.h"
 #include "gdb_bfd.h"
@@ -191,8 +190,7 @@ macho_symtab_read (minimal_symbol_reader &reader,
              if (sym->name == NULL || sym->name[0] == 0)
                 {
                   /* Unexpected empty N_SO.  */
-                  complaint (&symfile_complaints,
-                             _("Unexpected empty N_SO stab"));
+                  complaint (_("Unexpected empty N_SO stab"));
                 }
               else
                 {
@@ -209,8 +207,7 @@ macho_symtab_read (minimal_symbol_reader &reader,
                 }
 
               /* Debugging symbols are not expected here.  */
-              complaint (&symfile_complaints,
-                         _("%s: Unexpected debug stab outside SO markers"),
+              complaint (_("%s: Unexpected debug stab outside SO markers"),
                          objfile_name (objfile));
             }
           else
@@ -227,7 +224,7 @@ macho_symtab_read (minimal_symbol_reader &reader,
              if (sym->name == NULL || sym->name[0] == 0)
                 {
                   /* Unexpected empty N_SO.  */
-                  complaint (&symfile_complaints, _("Empty SO section"));
+                  complaint (_("Empty SO section"));
                   state = S_NO_SO;
                 }
               else if (state == S_FIRST_SO)
@@ -237,7 +234,7 @@ macho_symtab_read (minimal_symbol_reader &reader,
                   state = S_SECOND_SO;
                 }
               else
-                complaint (&symfile_complaints, _("Three SO in a raw"));
+                complaint (_("Three SO in a raw"));
             }
           else if (mach_o_sym->n_type == N_OSO)
             {
@@ -258,8 +255,7 @@ macho_symtab_read (minimal_symbol_reader &reader,
                 }
             }
           else
-            complaint (&symfile_complaints,
-                       _("Unexpected stab after SO"));
+            complaint (_("Unexpected stab after SO"));
           break;
 
         case S_STAB_FILE:
@@ -276,7 +272,7 @@ macho_symtab_read (minimal_symbol_reader &reader,
                 }
               else
                 {
-                  complaint (&symfile_complaints, _("Missing nul SO"));
+                  complaint (_("Missing nul SO"));
                   file_so = sym;
                   state = S_FIRST_SO;
                 }
@@ -304,21 +300,19 @@ macho_symtab_read (minimal_symbol_reader &reader,
                     case N_GSYM:
                       break;
                     default:
-                      complaint (&symfile_complaints,
-                                 _("unhandled stab for dwarf OSO file"));
+                      complaint (_("unhandled stab for dwarf OSO file"));
                       break;
                     }
                 }
             }
           else
-            complaint (&symfile_complaints,
-                       _("non-debugging symbol within SO"));
+            complaint (_("non-debugging symbol within SO"));
           break;
         }
     }
 
   if (state != S_NO_SO)
-    complaint (&symfile_complaints, _("missing nul SO"));
+    complaint (_("missing nul SO"));
 }
 
 /* If NAME describes an archive member (ie: ARCHIVE '(' MEMBER ')'),
@@ -496,8 +490,7 @@ macho_add_oso_symfile (oso_el *oso, const gdb_bfd_ref_ptr &abfd,
           ent = (struct macho_sym_hash_entry *)
             bfd_hash_lookup (&table, sym->name, TRUE, FALSE);
           if (ent->sym != NULL)
-            complaint (&symfile_complaints,
-                       _("Duplicated symbol %s in symbol table"), sym->name);
+            complaint (_("Duplicated symbol %s in symbol table"), sym->name);
           else
             {
               if (mach_o_debug_level > 4)
@@ -622,7 +615,7 @@ macho_symfile_read_all_oso (std::vector<oso_el> *oso_vector_ptr,
   std::sort (oso_vector_ptr->begin (), oso_vector_ptr->end (),
             oso_el_compare_name);
 
-  for (ix = 0; ix < oso_vector_ptr->size (); ++ix)
+  for (ix = 0; ix < oso_vector_ptr->size ();)
     {
       int pfx_len;
 
@@ -704,7 +697,7 @@ macho_symfile_read_all_oso (std::vector<oso_el> *oso_vector_ptr,
            }
           for (ix2 = ix; ix2 < last_ix; ix2++)
             {
-              oso_el *oso2 = &(*oso_vector_ptr)[ix2];
+              oso2 = &(*oso_vector_ptr)[ix2];
 
               if (oso2->name != NULL)
                 warning (_("Could not find specified archive member "
@@ -799,6 +792,9 @@ macho_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
   bfd *abfd = objfile->obfd;
   long storage_needed;
   std::vector<oso_el> oso_vector;
+  /* We have to hold on to the symbol table until the call to
+     macho_symfile_read_all_oso at the end of this function.  */
+  gdb::def_vector<asymbol *> symbol_table;
 
   /* Get symbols from the symbol table only if the file is an executable.
      The symbol table of object files is not relocated and is expected to
@@ -818,8 +814,7 @@ macho_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
        {
          long symcount;
 
-         gdb::def_vector<asymbol *> symbol_table (storage_needed
-                                                  / sizeof (asymbol *));
+         symbol_table.resize (storage_needed / sizeof (asymbol *));
 
           minimal_symbol_reader reader (objfile);