/* Read inferior memory at ADDR to find the header of a loaded object file and read its in-core symbols out of inferior memory. TEMPL is a bfd representing the target's format. NAME is the name to use for this symbol file in messages; it can be NULL or a malloc-allocated string which will be attached to the BFD. */ static struct objfile * symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr, char *name, int from_tty) { struct objfile *objf; struct bfd *nbfd; struct bfd_section *sec; bfd_vma loadbase; struct section_addr_info *sai; unsigned int i; struct cleanup *cleanup; if (bfd_get_flavour (templ) != bfd_target_elf_flavour) error (_("add-symbol-file-from-memory not supported for this target")); nbfd = bfd_elf_bfd_from_remote_memory (templ, addr, &loadbase, target_read_memory_bfd); if (nbfd == NULL) error (_("Failed to read a valid object file image from memory.")); gdb_bfd_ref (nbfd); if (name == NULL) nbfd->filename = "shared object read from target memory"; else { nbfd->filename = name; gdb_bfd_stash_filename (nbfd); xfree (name); } cleanup = make_cleanup_bfd_unref (nbfd); if (!bfd_check_format (nbfd, bfd_object)) error (_("Got object file from memory but can't read symbols: %s."), bfd_errmsg (bfd_get_error ())); sai = alloc_section_addr_info (bfd_count_sections (nbfd)); make_cleanup (xfree, sai); i = 0; for (sec = nbfd->sections; sec != NULL; sec = sec->next) if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0) { sai->other[i].addr = bfd_get_section_vma (nbfd, sec) + loadbase; sai->other[i].name = (char *) bfd_get_section_name (nbfd, sec); sai->other[i].sectindex = sec->index; ++i; } sai->num_sections = i; objf = symbol_file_add_from_bfd (nbfd, bfd_get_filename (nbfd), from_tty ? SYMFILE_VERBOSE : 0, sai, OBJF_SHARED, NULL); /* This might change our ideas about frames already looked at. */ reinit_frame_cache (); do_cleanups (cleanup); return objf; }
/* Read inferior memory at ADDR to find the header of a loaded object file and read its in-core symbols out of inferior memory. TEMPL is a bfd representing the target's format. NAME is the name to use for this symbol file in messages; it can be NULL or a malloc-allocated string which will be attached to the BFD. */ static struct objfile * symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr, char *name, int from_tty) { struct objfile *objf; struct bfd *nbfd; struct bfd_section *sec; bfd_vma loadbase; struct section_addr_info *sai; unsigned int i; if (bfd_get_flavour (templ) != bfd_target_elf_flavour) error (_("add-symbol-file-from-memory not supported for this target")); nbfd = bfd_elf_bfd_from_remote_memory (templ, addr, &loadbase, target_read_memory); if (nbfd == NULL) error (_("Failed to read a valid object file image from memory.")); if (name == NULL) nbfd->filename = xstrdup ("shared object read from target memory"); else nbfd->filename = name; if (!bfd_check_format (nbfd, bfd_object)) { /* FIXME: should be checking for errors from bfd_close (for one thing, on error it does not free all the storage associated with the bfd). */ bfd_close (nbfd); error (_("Got object file from memory but can't read symbols: %s."), bfd_errmsg (bfd_get_error ())); } sai = alloc_section_addr_info (bfd_count_sections (nbfd)); make_cleanup (xfree, sai); i = 0; for (sec = nbfd->sections; sec != NULL; sec = sec->next) if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0) { sai->other[i].addr = bfd_get_section_vma (nbfd, sec) + loadbase; sai->other[i].name = (char *) bfd_get_section_name (nbfd, sec); sai->other[i].sectindex = sec->index; ++i; } objf = symbol_file_add_from_bfd (nbfd, from_tty ? SYMFILE_VERBOSE : 0, sai, OBJF_SHARED); /* This might change our ideas about frames already looked at. */ reinit_frame_cache (); return objf; }
/* Read inferior memory at ADDR to find the header of a loaded object file and read its in-core symbols out of inferior memory. SIZE, if non-zero, is the known size of the object. TEMPL is a bfd representing the target's format. NAME is the name to use for this symbol file in messages; it can be NULL or a malloc-allocated string which will be attached to the BFD. */ static struct objfile * symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr, size_t size, char *name, int from_tty) { struct objfile *objf; struct bfd *nbfd; struct bfd_section *sec; bfd_vma loadbase; symfile_add_flags add_flags = 0; if (bfd_get_flavour (templ) != bfd_target_elf_flavour) error (_("add-symbol-file-from-memory not supported for this target")); nbfd = bfd_elf_bfd_from_remote_memory (templ, addr, size, &loadbase, target_read_memory_bfd); if (nbfd == NULL) error (_("Failed to read a valid object file image from memory.")); /* Manage the new reference for the duration of this function. */ gdb_bfd_ref_ptr nbfd_holder = gdb_bfd_ref_ptr::new_reference (nbfd); xfree (bfd_get_filename (nbfd)); if (name == NULL) nbfd->filename = xstrdup ("shared object read from target memory"); else nbfd->filename = name; if (!bfd_check_format (nbfd, bfd_object)) error (_("Got object file from memory but can't read symbols: %s."), bfd_errmsg (bfd_get_error ())); section_addr_info sai; for (sec = nbfd->sections; sec != NULL; sec = sec->next) if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0) sai.emplace_back (bfd_get_section_vma (nbfd, sec) + loadbase, bfd_get_section_name (nbfd, sec), sec->index); if (from_tty) add_flags |= SYMFILE_VERBOSE; objf = symbol_file_add_from_bfd (nbfd, bfd_get_filename (nbfd), add_flags, &sai, OBJF_SHARED, NULL); add_target_sections_of_objfile (objf); /* This might change our ideas about frames already looked at. */ reinit_frame_cache (); return objf; }