static struct vmap * add_vmap (LdInfo *ldi) { bfd *abfd, *last; char *mem, *filename; struct objfile *obj; struct vmap *vp; int fd; ARCH64_DECL (arch64); /* This ldi structure was allocated using alloca() in xcoff_relocate_symtab(). Now we need to have persistent object and member names, so we should save them. */ filename = LDI_FILENAME (ldi, arch64); mem = filename + strlen (filename) + 1; mem = xstrdup (mem); fd = LDI_FD (ldi, arch64); abfd = gdb_bfd_open (filename, gnutarget, fd < 0 ? -1 : fd); if (!abfd) { warning (_("Could not open `%s' as an executable file: %s"), filename, bfd_errmsg (bfd_get_error ())); return NULL; } /* Make sure we have an object file. */ if (bfd_check_format (abfd, bfd_object)) vp = map_vmap (abfd, 0); else if (bfd_check_format (abfd, bfd_archive)) { last = gdb_bfd_openr_next_archived_file (abfd, NULL); while (last != NULL) { bfd *next; if (strcmp (mem, last->filename) == 0) break; next = gdb_bfd_openr_next_archived_file (abfd, last); gdb_bfd_unref (last); last = next; } if (!last) { warning (_("\"%s\": member \"%s\" missing."), filename, mem); gdb_bfd_unref (abfd); return NULL; } if (!bfd_check_format (last, bfd_object)) { warning (_("\"%s\": member \"%s\" not in executable format: %s."), filename, mem, bfd_errmsg (bfd_get_error ())); gdb_bfd_unref (last); gdb_bfd_unref (abfd); return NULL; } vp = map_vmap (last, abfd); /* map_vmap acquired a reference to LAST, so we can release ours. */ gdb_bfd_unref (last); } else { warning (_("\"%s\": not in executable format: %s."), filename, bfd_errmsg (bfd_get_error ())); gdb_bfd_unref (abfd); return NULL; } obj = allocate_objfile (vp->bfd, 0); vp->objfile = obj; /* Always add symbols for the main objfile. */ if (vp == vmap || auto_solib_add) vmap_add_symbols (vp); /* Anything needing a reference to ABFD has already acquired it, so release our local reference. */ gdb_bfd_unref (abfd); return vp; }
static void macho_symfile_read_all_oso (std::vector<oso_el> *oso_vector_ptr, struct objfile *main_objfile, symfile_add_flags symfile_flags) { int ix; oso_el *oso; /* Sort oso by name so that files from libraries are gathered. */ std::sort (oso_vector_ptr->begin (), oso_vector_ptr->end (), oso_el_compare_name); for (ix = 0; ix < oso_vector_ptr->size (); ++ix) { int pfx_len; oso = &(*oso_vector_ptr)[ix]; /* Check if this is a library name. */ pfx_len = get_archive_prefix_len (oso->name); if (pfx_len > 0) { int last_ix; oso_el *oso2; int ix2; std::string archive_name (oso->name, pfx_len); /* Compute number of oso for this archive. */ for (last_ix = ix; last_ix < oso_vector_ptr->size (); last_ix++) { oso2 = &(*oso_vector_ptr)[last_ix]; if (strncmp (oso2->name, archive_name.c_str (), pfx_len) != 0) break; } /* Open the archive and check the format. */ gdb_bfd_ref_ptr archive_bfd (gdb_bfd_open (archive_name.c_str (), gnutarget, -1)); if (archive_bfd == NULL) { warning (_("Could not open OSO archive file \"%s\""), archive_name.c_str ()); ix = last_ix; continue; } if (!bfd_check_format (archive_bfd.get (), bfd_archive)) { warning (_("OSO archive file \"%s\" not an archive."), archive_name.c_str ()); ix = last_ix; continue; } gdb_bfd_ref_ptr member_bfd (gdb_bfd_openr_next_archived_file (archive_bfd.get (), NULL)); if (member_bfd == NULL) { warning (_("Could not read archive members out of " "OSO archive \"%s\""), archive_name.c_str ()); ix = last_ix; continue; } /* Load all oso in this library. */ while (member_bfd != NULL) { 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 = &(*oso_vector_ptr)[ix2]; if (oso2->name && strlen (oso2->name) == pfx_len + member_len + 2 && !memcmp (member_name, oso2->name + pfx_len + 1, member_len)) { macho_add_oso_symfile (oso2, member_bfd, bfd_get_filename (member_bfd), main_objfile, symfile_flags); oso2->name = NULL; break; } } member_bfd = gdb_bfd_openr_next_archived_file (archive_bfd.get (), member_bfd.get ()); } for (ix2 = ix; ix2 < last_ix; ix2++) { oso_el *oso2 = &(*oso_vector_ptr)[ix2]; if (oso2->name != NULL) warning (_("Could not find specified archive member " "for OSO name \"%s\""), oso->name); } ix = last_ix; } else { gdb_bfd_ref_ptr abfd (gdb_bfd_open (oso->name, gnutarget, -1)); if (abfd == NULL) warning (_("`%s': can't open to read symbols: %s."), oso->name, bfd_errmsg (bfd_get_error ())); else macho_add_oso_symfile (oso, abfd, oso->name, main_objfile, symfile_flags); ix++; } } }