BuFile* buFileOpen(const char* path, bool preload, int offset) { iovecStreamParams p = {path, preload, offset}; // set default target; without a default target some logic inside bfd goes horribly wrong bfd_set_default_target("binary"); // open file std::unique_ptr<bfd, bfd_boolean (*)(bfd*)> abfd(bfd_openr_iovec(path, 0, iovecOpen, &p, iovecRead, iovecClose, iovecStat), bfd_close); if (!abfd) return 0; // we should be working with an object file now if (!checkFormat(abfd.get(), bfd_object)) return 0; // decompress sections (we don't know if we'll need it) abfd->flags |= BFD_DECOMPRESS; // slurp symtab since all operations need it anyway std::vector<asymbol*> symtab = slurpSymtab(abfd.get()); std::vector<asymbol*> dyntab = slurpDynamicSymtab(abfd.get()); symtab.insert(symtab.end(), dyntab.begin(), dyntab.end()); symtab.push_back(0); return new BuFile(std::move(abfd), std::move(symtab)); }
char * find_separate_debug_file_by_buildid (struct objfile *objfile) { const struct bfd_build_id *build_id; build_id = build_id_bfd_get (objfile->obfd); if (build_id != NULL) { if (separate_debug_file_debug) printf_unfiltered (_("\nLooking for separate debug info (build-id) for " "%s\n"), objfile_name (objfile)); gdb_bfd_ref_ptr abfd (build_id_to_debug_bfd (build_id->size, build_id->data)); /* Prevent looping on a stripped .debug file. */ if (abfd != NULL && filename_cmp (bfd_get_filename (abfd.get ()), objfile_name (objfile)) == 0) warning (_("\"%s\": separate debug info file has no debug info"), bfd_get_filename (abfd.get ())); else if (abfd != NULL) return xstrdup (bfd_get_filename (abfd.get ())); } return NULL; }
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++; } } }