contrib/gdb-7/gdb/jit.c
static void
jit_bfd_try_read_symtab (struct jit_code_entry *code_entry,
                         CORE_ADDR entry_addr,
                         struct gdbarch *gdbarch)
{
  bfd *nbfd;
  struct section_addr_info *sai;
  struct bfd_section *sec;
  struct objfile *objfile;
  struct cleanup *old_cleanups;
  int i;
  const struct bfd_arch_info *b;

  if (jit_debug)
    fprintf_unfiltered (gdb_stdlog,
			"jit_register_code, symfile_addr = %s, "
			"symfile_size = %s\n",
			paddress (gdbarch, code_entry->symfile_addr),
			pulongest (code_entry->symfile_size));

  nbfd = bfd_open_from_target_memory (code_entry->symfile_addr,
                                      code_entry->symfile_size, gnutarget);
  if (nbfd == NULL)
    {
      puts_unfiltered (_("Error opening JITed symbol file, ignoring it.\n"));
      return;
    }

  /* Check the format.  NOTE: This initializes important data that GDB uses!
     We would segfault later without this line.  */
  if (!bfd_check_format (nbfd, bfd_object))
    {
      printf_unfiltered (_("\
JITed symbol file is not an object file, ignoring it.\n"));
      bfd_close (nbfd);
      return;
    }

  /* Check bfd arch.  */
  b = gdbarch_bfd_arch_info (gdbarch);
  if (b->compatible (b, bfd_get_arch_info (nbfd)) != b)
    warning (_("JITed object file architecture %s is not compatible "
               "with target architecture %s."), bfd_get_arch_info
             (nbfd)->printable_name, b->printable_name);

  /* Read the section address information out of the symbol file.  Since the
     file is generated by the JIT at runtime, it should all of the absolute
     addresses that we care about.  */
  sai = alloc_section_addr_info (bfd_count_sections (nbfd));
  old_cleanups = make_cleanup_free_section_addr_info (sai);
  i = 0;
  for (sec = nbfd->sections; sec != NULL; sec = sec->next)
    if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0)
      {
        /* We assume that these virtual addresses are absolute, and do not
           treat them as offsets.  */
        sai->other[i].addr = bfd_get_section_vma (nbfd, sec);
        sai->other[i].name = xstrdup (bfd_get_section_name (nbfd, sec));
        sai->other[i].sectindex = sec->index;
        ++i;
      }

  /* This call takes ownership of NBFD.  It does not take ownership of SAI.  */
  objfile = symbol_file_add_from_bfd (nbfd, 0, sai, OBJF_SHARED, NULL);

  do_cleanups (old_cleanups);
  add_objfile_entry (objfile, entry_addr);
}
/* Try to read CODE_ENTRY using BFD.  ENTRY_ADDR is the address of the
   struct jit_code_entry in the inferior address space.  */
Try to read CODE_ENTRY using BFD.  ENTRY_ADDR is the address of the
struct jit_code_entry in the inferior address space.
Try to read CODE_ENTRY using BFD . ENTRY_ADDR is the address of the struct jit_code_entry in the inferior address space .
static void
jit_bfd_try_read_symtab (struct jit_code_entry *code_entry,
                         CORE_ADDR entry_addr,
                         struct gdbarch *gdbarch)
{
  bfd *nbfd;
  struct section_addr_info *sai;
  struct bfd_section *sec;
  struct objfile *objfile;
  struct cleanup *old_cleanups;
  int i;
  const struct bfd_arch_info *b;
  if (jit_debug)
    fprintf_unfiltered (gdb_stdlog,
			"jit_register_code, symfile_addr = %s, "
			"symfile_size = %s\n",
			paddress (gdbarch, code_entry->symfile_addr),
			pulongest (code_entry->symfile_size));
  nbfd = bfd_open_from_target_memory (code_entry->symfile_addr,
                                      code_entry->symfile_size, gnutarget);
  if (nbfd == NULL)
    {
      puts_unfiltered (_("Error opening JITed symbol file, ignoring it.\n"));
      return;
    }
  if (!bfd_check_format (nbfd, bfd_object))
    {
      printf_unfiltered (_("\
JITed symbol file is not an object file, ignoring it.\n"));
      bfd_close (nbfd);
      return;
    }
  b = gdbarch_bfd_arch_info (gdbarch);
  if (b->compatible (b, bfd_get_arch_info (nbfd)) != b)
    warning (_("JITed object file architecture %s is not compatible "
               "with target architecture %s."), bfd_get_arch_info
             (nbfd)->printable_name, b->printable_name);
  sai = alloc_section_addr_info (bfd_count_sections (nbfd));
  old_cleanups = make_cleanup_free_section_addr_info (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);
        sai->other[i].name = xstrdup (bfd_get_section_name (nbfd, sec));
        sai->other[i].sectindex = sec->index;
        ++i;
      }
  objfile = symbol_file_add_from_bfd (nbfd, 0, sai, OBJF_SHARED, NULL);
  do_cleanups (old_cleanups);
  add_objfile_entry (objfile, entry_addr);
}
static void jit_bfd_try_read_symtab ( struct jit_code_entry * code_entry , CORE_ADDR entry_addr , struct gdbarch * gdbarch ) { bfd * nbfd ; struct section_addr_info * sai ; struct bfd_section * sec ; struct objfile * objfile ; struct cleanup * old_cleanups ; int i ; const struct bfd_arch_info * b ; if ( jit_debug ) fprintf_unfiltered ( gdb_stdlog , " " " \n " , paddress ( gdbarch , code_entry -> symfile_addr ) , pulongest ( code_entry -> symfile_size ) ) ; nbfd = bfd_open_from_target_memory ( code_entry -> symfile_addr , code_entry -> symfile_size , gnutarget ) ; if ( nbfd == NULL ) { puts_unfiltered ( _ ( " \n " ) ) ; return ; } if ( ! bfd_check_format ( nbfd , bfd_object ) ) { printf_unfiltered ( _ ( " \
 \n " ) ) ; bfd_close ( nbfd ) ; return ; } b = gdbarch_bfd_arch_info ( gdbarch ) ; if ( b -> compatible ( b , bfd_get_arch_info ( nbfd ) ) != b ) warning ( _ ( " " " " ) , bfd_get_arch_info ( nbfd ) -> printable_name , b -> printable_name ) ; sai = alloc_section_addr_info ( bfd_count_sections ( nbfd ) ) ; old_cleanups = make_cleanup_free_section_addr_info ( 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 ) ; sai -> other [ i ] . name = xstrdup ( bfd_get_section_name ( nbfd , sec ) ) ; sai -> other [ i ] . sectindex = sec -> index ; ++ i ; } objfile = symbol_file_add_from_bfd ( nbfd , 0 , sai , OBJF_SHARED , NULL ) ; do_cleanups ( old_cleanups ) ; add_objfile_entry ( objfile , entry_addr ) ; }
Try to read CODE_ENTRY using BFD.
Try to read CODE_ENTRY using BFD .
/* Check the format.  NOTE: This initializes important data that GDB uses!
     We would segfault later without this line.  */ /* Check bfd arch.  */ /* Read the section address information out of the symbol file.  Since the
     file is generated by the JIT at runtime, it should all of the absolute
     addresses that we care about.  */ /* We assume that these virtual addresses are absolute, and do not
           treat them as offsets.  */ /* This call takes ownership of NBFD.  It does not take ownership of SAI.  */