2009-12-15 Tristan Gingold <gingold@adacore.com>
[deliverable/binutils-gdb.git] / gdb / machoread.c
index ac7063dd0d3fd32d816a5910ec9121a6a962aa38..0194ee521620a9e1b4eec4c881a374a46e751492 100644 (file)
@@ -69,7 +69,9 @@ typedef struct oso_el
   int num_sections;
 
   /* Each seaction of the object file is represented by a symbol and its
-     offset.  */
+     offset.  If the offset is 0, we assume that the symbol is at offset 0
+     in the OSO object file and a symbol lookup in the main file is
+     required to get the offset.  */
   asymbol **symbols;
   bfd_vma *offsets;
 }
@@ -124,14 +126,17 @@ macho_symtab_read (struct objfile *objfile,
        {
          bfd_vma addr;
 
+          /* Debugging symbols are used to collect OSO file names as well
+             as section offsets.  */
+
          switch (mach_o_sym->n_type)
            {
            case N_SO:
-             if ((sym->name == NULL || sym->name[0] == 0)
-                 && oso_file != NULL)
+              /* An empty SO entry terminates a chunk for an OSO file.  */
+             if ((sym->name == NULL || sym->name[0] == 0) && oso_file != NULL)
                {
                  macho_add_oso (oso_file, nbr_sections,
-                                first_symbol, first_offset);
+                                 first_symbol, first_offset);
                  first_symbol = NULL;
                  first_offset = NULL;
                  oso_file = NULL;
@@ -149,6 +154,7 @@ macho_symtab_read (struct objfile *objfile,
              if (addr != 0
                  && first_symbol[sym->section->index] == NULL)
                {
+                  /* These STAB entries can directly relocate a section.  */
                  first_symbol[sym->section->index] = sym;
                  first_offset[sym->section->index] = addr + offset;
                }
@@ -156,9 +162,15 @@ macho_symtab_read (struct objfile *objfile,
            case N_GSYM:
              gdb_assert (oso_file != NULL);
              if (first_symbol[sym->section->index] == NULL)
-               first_symbol[sym->section->index] = sym;
+                {
+                  /* This STAB entry needs a symbol look-up to relocate
+                     the section.  */
+                  first_symbol[sym->section->index] = sym;
+                  first_offset[sym->section->index] = 0;
+                }
              break;
            case N_OSO:
+              /* New OSO file.  */
              gdb_assert (oso_file == NULL);
              first_symbol = (asymbol **)xmalloc (nbr_sections
                                                  * sizeof (asymbol *));
@@ -233,6 +245,7 @@ macho_symtab_read (struct objfile *objfile,
          if (oso_file != NULL
              && first_symbol[sym->section->index] == NULL)
            {
+              /* Standard symbols can directly relocate sections.  */
              first_symbol[sym->section->index] = sym;
              first_offset[sym->section->index] = symaddr;
            }
@@ -243,6 +256,7 @@ macho_symtab_read (struct objfile *objfile,
        }
     }
 
+  /* Just in case there is no trailing SO entry.  */
   if (oso_file != NULL)
     macho_add_oso (oso_file, nbr_sections, first_symbol, first_offset);
 }
@@ -429,6 +443,7 @@ macho_oso_symfile (struct objfile *main_objfile)
              const char *member_name = member_bfd->filename;
               int member_len = strlen (member_name);
 
+              /* If this member is referenced, add it as a symfile.  */
               for (ix2 = ix; ix2 < last_ix; ix2++)
                 {
                   oso2 = VEC_index (oso_el, vec, ix2);
@@ -447,7 +462,9 @@ macho_oso_symfile (struct objfile *main_objfile)
               prev = member_bfd;
              member_bfd = bfd_openr_next_archived_file
                (archive_bfd, member_bfd);
-              if (ix2 < last_ix)
+
+              /* Free previous member if not referenced by an oso.  */
+              if (ix2 >= last_ix)
                 bfd_close (prev);
            }
           for (ix2 = ix; ix2 < last_ix; ix2++)
@@ -502,9 +519,8 @@ macho_check_dsym (struct objfile *objfile)
   size_t base_len = strlen (base_name);
   char *dsym_filename = alloca (name_len + dsym_len + base_len + 1);
   bfd *dsym_bfd;
-  asection *sect;
-  bfd_byte main_uuid[16];
-  bfd_byte dsym_uuid[16];
+  bfd_mach_o_load_command *main_uuid;
+  bfd_mach_o_load_command *dsym_uuid;
 
   strcpy (dsym_filename, objfile->name);
   strcpy (dsym_filename + name_len, DSYM_SUFFIX);
@@ -513,19 +529,12 @@ macho_check_dsym (struct objfile *objfile)
   if (access (dsym_filename, R_OK) != 0)
     return NULL;
 
-  sect = bfd_get_section_by_name (objfile->obfd, "LC_UUID");
-  if (sect == NULL)
+  if (bfd_mach_o_lookup_command (objfile->obfd,
+                                 BFD_MACH_O_LC_UUID, &main_uuid) == 0)
     {
       warning (_("can't find UUID in %s"), objfile->name);
       return NULL;
     }
-  if (!bfd_get_section_contents (objfile->obfd, sect, main_uuid,
-                                0, sizeof (main_uuid)))
-    {
-      warning (_("can't read UUID in %s"), objfile->name);
-      return NULL;
-    }
-
   dsym_filename = xstrdup (dsym_filename);
   dsym_bfd = bfd_openr (dsym_filename, gnutarget);
   if (dsym_bfd == NULL)
@@ -543,23 +552,16 @@ macho_check_dsym (struct objfile *objfile)
       return NULL;
     }
 
-  sect = bfd_get_section_by_name (dsym_bfd, "LC_UUID");
-  if (sect == NULL)
+  if (bfd_mach_o_lookup_command (dsym_bfd,
+                                 BFD_MACH_O_LC_UUID, &dsym_uuid) == 0)
     {
       warning (_("can't find UUID in %s"), dsym_filename);
       bfd_close (dsym_bfd);
       xfree (dsym_filename);
       return NULL;
     }
-  if (!bfd_get_section_contents (dsym_bfd, sect, dsym_uuid,
-                                0, sizeof (dsym_uuid)))
-    {
-      warning (_("can't read UUID in %s"), dsym_filename);
-      bfd_close (dsym_bfd);
-      xfree (dsym_filename);
-      return NULL;
-    }
-  if (memcmp (dsym_uuid, main_uuid, sizeof (main_uuid)))
+  if (memcmp (dsym_uuid->command.uuid.uuid, main_uuid->command.uuid.uuid,
+              sizeof (main_uuid->command.uuid.uuid)))
     {
       warning (_("dsym file UUID doesn't match the one in %s"), objfile->name);
       bfd_close (dsym_bfd);
@@ -567,11 +569,10 @@ macho_check_dsym (struct objfile *objfile)
       return NULL;
     }
   return dsym_bfd;
-
 }
 
 static void
-macho_symfile_read (struct objfile *objfile, int mainline)
+macho_symfile_read (struct objfile *objfile, int symfile_flags)
 {
   bfd *abfd = objfile->obfd;
   struct cleanup *back_to;
@@ -638,18 +639,18 @@ macho_symfile_read (struct objfile *objfile, int mainline)
          VEC_free (oso_el, oso_vector);
          oso_vector = NULL;
 
-         /* Now recurse: read dwarf from dsym.  */
-         symbol_file_add_from_bfd (dsym_bfd, 0, NULL, 0);
+         /* Add the dsym file as a separate file.  */
+          symbol_file_add_separate (dsym_bfd, symfile_flags, objfile);
       
          /* Don't try to read dwarf2 from main file or shared libraries.  */
-         return;
+          return;
        }
     }
 
   if (dwarf2_has_info (objfile))
     {
       /* DWARF 2 sections */
-      dwarf2_build_psymtabs (objfile, mainline);
+      dwarf2_build_psymtabs (objfile);
     }
 
   /* Do not try to read .eh_frame/.debug_frame as they are not relocated
@@ -730,6 +731,8 @@ static struct sym_fns macho_sym_fns = {
   macho_symfile_read,           /* sym_read: read a symbol file into symtab */
   macho_symfile_finish,         /* sym_finish: finished with file, cleanup */
   macho_symfile_offsets,        /* sym_offsets:  xlate external to internal form */
+  default_symfile_segments,    /* sym_segments: Get segment information from
+                                  a file.  */
   NULL                          /* next: pointer to next struct sym_fns */
 };
 
This page took 0.02786 seconds and 4 git commands to generate.