Exemplo n.º 1
0
/* 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;
}
Exemplo n.º 2
0
/* 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;
}
Exemplo n.º 3
0
void
pef_load_library (const struct dyld_path_info *d,
                  struct dyld_objfile_entry *e)
{
  bfd *pbfd = NULL;
  bfd *sbfd = NULL;
  char *symname = NULL;
  asection *csection = NULL;
  asection *dsection = NULL;
  struct section_addr_info *addrs;
  unsigned int i = 0;

  pbfd =
    inferior_bfd (e->dyld_name, e->dyld_addr, e->dyld_slide, e->dyld_length);

  if (strcmp (bfd_get_target (pbfd), "pef-xlib") == 0)
    {
      return;
    }

  if (strcmp (bfd_get_target (pbfd), "pef") != 0)
    {
      warning ("Unable to read symbols from %s: invalid file format \"%s\".",
               bfd_get_filename (pbfd), bfd_get_target (pbfd));
      return;
    }

  csection = bfd_get_section_by_name (pbfd, "code");
  if (csection == NULL)
    {
      warning
        ("Unable to find 'code' section in pef container \"%s\" at address 0x%s for 0x%lx",
         e->dyld_name, paddr_nz (e->dyld_addr),
         (unsigned long) e->dyld_length);
      return;
    }

  dsection = bfd_get_section_by_name (pbfd, "packed-data");
  if (dsection == NULL)
    {
      warning
        ("Unable to find 'packed-data' section in pef container \"%s\" at address 0x%s for 0x%lx",
         e->dyld_name, paddr_nz (e->dyld_addr),
         (unsigned long) e->dyld_length);
      return;
    }

  symname = xmalloc (strlen (e->dyld_name) + strlen (".xSYM") + 1);
  sprintf (symname, "%s%s", e->dyld_name, ".xSYM");
  sbfd = bfd_openr (symname, "sym");
  if (sbfd == NULL)
    {
      warning ("unable to open \"%s\": %s", symname,
               bfd_errmsg (bfd_get_error ()));
    }

  addrs = alloc_section_addr_info (bfd_count_sections (pbfd));

  for (i = 0; i < addrs->num_sections; i++)
    {
      addrs->other[i].name = NULL;
      addrs->other[i].addr = e->dyld_addr;
      addrs->other[i].sectindex = 0;
    }

  addrs->addrs_are_offsets = 1;

  if (pbfd != NULL)
    {
      if (!bfd_check_format (pbfd, bfd_object))
        {
          warning ("file \"%s\" is not a valid symbol file", pbfd->filename);
        }
      else
        {
          symbol_file_add_bfd_safe (pbfd, 0, addrs, 0, 0, 0, e->load_flag, 0, 0, NULL);
        }
    }

  addrs->other[0].name = "code";
  addrs->other[0].addr = e->dyld_addr + csection->vma;
  addrs->other[0].sectindex = 0;

  addrs->other[1].name = "packed-data";
  addrs->other[1].addr = e->dyld_addr + dsection->vma;
  addrs->other[1].sectindex = 1;

  for (i = 2; i < addrs->num_sections; i++)
    {
      addrs->other[i].name = NULL;
      addrs->other[i].addr = e->dyld_addr + csection->vma;
      addrs->other[i].sectindex = 0;
    }

  addrs->addrs_are_offsets = 1;

  if (sbfd != NULL)
    {
      if (!bfd_check_format (sbfd, bfd_object))
        {
          warning ("file \"%s\" is not a valid symbol file", sbfd->filename);
        }
      else
        {
          symbol_file_add_bfd_safe (sbfd, 0, addrs, 0, 0, 0, e->load_flag, 0, 0, NULL);
        }
    }
}