contrib/gdb-7/gdb/jit.c
static void
finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
{
  struct symtab *symtab;
  struct gdb_block *gdb_block_iter, *gdb_block_iter_tmp;
  struct block *block_iter;
  int actual_nblocks, i, blockvector_size;
  CORE_ADDR begin, end;

  actual_nblocks = FIRST_LOCAL_BLOCK + stab->nblocks;

  symtab = allocate_symtab (stab->file_name, objfile);
  /* JIT compilers compile in memory.  */
  symtab->dirname = NULL;

  /* Copy over the linetable entry if one was provided.  */
  if (stab->linetable)
    {
      int size = ((stab->linetable->nitems - 1)
                  * sizeof (struct linetable_entry)
                  + sizeof (struct linetable));
      LINETABLE (symtab) = obstack_alloc (&objfile->objfile_obstack, size);
      memcpy (LINETABLE (symtab), stab->linetable, size);
    }
  else
    {
      LINETABLE (symtab) = NULL;
    }

  blockvector_size = (sizeof (struct blockvector)
                      + (actual_nblocks - 1) * sizeof (struct block *));
  symtab->blockvector = obstack_alloc (&objfile->objfile_obstack,
                                       blockvector_size);

  /* (begin, end) will contain the PC range this entire blockvector
     spans.  */
  symtab->primary = 1;
  BLOCKVECTOR_MAP (symtab->blockvector) = NULL;
  begin = stab->blocks->begin;
  end = stab->blocks->end;
  BLOCKVECTOR_NBLOCKS (symtab->blockvector) = actual_nblocks;

  /* First run over all the gdb_block objects, creating a real block
     object for each.  Simultaneously, keep setting the real_block
     fields.  */
  for (i = (actual_nblocks - 1), gdb_block_iter = stab->blocks;
       i >= FIRST_LOCAL_BLOCK;
       i--, gdb_block_iter = gdb_block_iter->next)
    {
      struct block *new_block = allocate_block (&objfile->objfile_obstack);
      struct symbol *block_name = obstack_alloc (&objfile->objfile_obstack,
                                                 sizeof (struct symbol));

      BLOCK_DICT (new_block) = dict_create_linear (&objfile->objfile_obstack,
                                                   NULL);
      /* The address range.  */
      BLOCK_START (new_block) = (CORE_ADDR) gdb_block_iter->begin;
      BLOCK_END (new_block) = (CORE_ADDR) gdb_block_iter->end;

      /* The name.  */
      memset (block_name, 0, sizeof (struct symbol));
      SYMBOL_DOMAIN (block_name) = VAR_DOMAIN;
      SYMBOL_CLASS (block_name) = LOC_BLOCK;
      SYMBOL_SYMTAB (block_name) = symtab;
      SYMBOL_BLOCK_VALUE (block_name) = new_block;

      block_name->ginfo.name = obsavestring (gdb_block_iter->name,
                                             strlen (gdb_block_iter->name),
                                             &objfile->objfile_obstack);

      BLOCK_FUNCTION (new_block) = block_name;

      BLOCKVECTOR_BLOCK (symtab->blockvector, i) = new_block;
      if (begin > BLOCK_START (new_block))
        begin = BLOCK_START (new_block);
      if (end < BLOCK_END (new_block))
        end = BLOCK_END (new_block);

      gdb_block_iter->real_block = new_block;
    }

  /* Now add the special blocks.  */
  block_iter = NULL;
  for (i = 0; i < FIRST_LOCAL_BLOCK; i++)
    {
      struct block *new_block = allocate_block (&objfile->objfile_obstack);
      BLOCK_DICT (new_block) = dict_create_linear (&objfile->objfile_obstack,
                                                   NULL);
      BLOCK_SUPERBLOCK (new_block) = block_iter;
      block_iter = new_block;

      BLOCK_START (new_block) = (CORE_ADDR) begin;
      BLOCK_END (new_block) = (CORE_ADDR) end;

      BLOCKVECTOR_BLOCK (symtab->blockvector, i) = new_block;
    }

  /* Fill up the superblock fields for the real blocks, using the
     real_block fields populated earlier.  */
  for (gdb_block_iter = stab->blocks;
       gdb_block_iter;
       gdb_block_iter = gdb_block_iter->next)
    {
      if (gdb_block_iter->parent != NULL)
        BLOCK_SUPERBLOCK (gdb_block_iter->real_block) =
          gdb_block_iter->parent->real_block;
    }

  /* Free memory.  */
  gdb_block_iter = stab->blocks;

  for (gdb_block_iter = stab->blocks, gdb_block_iter_tmp = gdb_block_iter->next;
       gdb_block_iter;
       gdb_block_iter = gdb_block_iter_tmp)
    {
      xfree ((void *) gdb_block_iter->name);
      xfree (gdb_block_iter);
    }
  xfree (stab->linetable);
  xfree ((char *) stab->file_name);
  xfree (stab);
}
/* Transform STAB to a proper symtab, and add it it OBJFILE.  */
Transform STAB to a proper symtab, and add it it OBJFILE.
Transform STAB to a proper symtab and add it it OBJFILE .
static void
finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
{
  struct symtab *symtab;
  struct gdb_block *gdb_block_iter, *gdb_block_iter_tmp;
  struct block *block_iter;
  int actual_nblocks, i, blockvector_size;
  CORE_ADDR begin, end;
  actual_nblocks = FIRST_LOCAL_BLOCK + stab->nblocks;
  symtab = allocate_symtab (stab->file_name, objfile);
  symtab->dirname = NULL;
  if (stab->linetable)
    {
      int size = ((stab->linetable->nitems - 1)
                  * sizeof (struct linetable_entry)
                  + sizeof (struct linetable));
      LINETABLE (symtab) = obstack_alloc (&objfile->objfile_obstack, size);
      memcpy (LINETABLE (symtab), stab->linetable, size);
    }
  else
    {
      LINETABLE (symtab) = NULL;
    }
  blockvector_size = (sizeof (struct blockvector)
                      + (actual_nblocks - 1) * sizeof (struct block *));
  symtab->blockvector = obstack_alloc (&objfile->objfile_obstack,
                                       blockvector_size);
  symtab->primary = 1;
  BLOCKVECTOR_MAP (symtab->blockvector) = NULL;
  begin = stab->blocks->begin;
  end = stab->blocks->end;
  BLOCKVECTOR_NBLOCKS (symtab->blockvector) = actual_nblocks;
  for (i = (actual_nblocks - 1), gdb_block_iter = stab->blocks;
       i >= FIRST_LOCAL_BLOCK;
       i--, gdb_block_iter = gdb_block_iter->next)
    {
      struct block *new_block = allocate_block (&objfile->objfile_obstack);
      struct symbol *block_name = obstack_alloc (&objfile->objfile_obstack,
                                                 sizeof (struct symbol));
      BLOCK_DICT (new_block) = dict_create_linear (&objfile->objfile_obstack,
                                                   NULL);
      BLOCK_START (new_block) = (CORE_ADDR) gdb_block_iter->begin;
      BLOCK_END (new_block) = (CORE_ADDR) gdb_block_iter->end;
      memset (block_name, 0, sizeof (struct symbol));
      SYMBOL_DOMAIN (block_name) = VAR_DOMAIN;
      SYMBOL_CLASS (block_name) = LOC_BLOCK;
      SYMBOL_SYMTAB (block_name) = symtab;
      SYMBOL_BLOCK_VALUE (block_name) = new_block;
      block_name->ginfo.name = obsavestring (gdb_block_iter->name,
                                             strlen (gdb_block_iter->name),
                                             &objfile->objfile_obstack);
      BLOCK_FUNCTION (new_block) = block_name;
      BLOCKVECTOR_BLOCK (symtab->blockvector, i) = new_block;
      if (begin > BLOCK_START (new_block))
        begin = BLOCK_START (new_block);
      if (end < BLOCK_END (new_block))
        end = BLOCK_END (new_block);
      gdb_block_iter->real_block = new_block;
    }
  block_iter = NULL;
  for (i = 0; i < FIRST_LOCAL_BLOCK; i++)
    {
      struct block *new_block = allocate_block (&objfile->objfile_obstack);
      BLOCK_DICT (new_block) = dict_create_linear (&objfile->objfile_obstack,
                                                   NULL);
      BLOCK_SUPERBLOCK (new_block) = block_iter;
      block_iter = new_block;
      BLOCK_START (new_block) = (CORE_ADDR) begin;
      BLOCK_END (new_block) = (CORE_ADDR) end;
      BLOCKVECTOR_BLOCK (symtab->blockvector, i) = new_block;
    }
  for (gdb_block_iter = stab->blocks;
       gdb_block_iter;
       gdb_block_iter = gdb_block_iter->next)
    {
      if (gdb_block_iter->parent != NULL)
        BLOCK_SUPERBLOCK (gdb_block_iter->real_block) =
          gdb_block_iter->parent->real_block;
    }
  gdb_block_iter = stab->blocks;
  for (gdb_block_iter = stab->blocks, gdb_block_iter_tmp = gdb_block_iter->next;
       gdb_block_iter;
       gdb_block_iter = gdb_block_iter_tmp)
    {
      xfree ((void *) gdb_block_iter->name);
      xfree (gdb_block_iter);
    }
  xfree (stab->linetable);
  xfree ((char *) stab->file_name);
  xfree (stab);
}
static void finalize_symtab ( struct gdb_symtab * stab , struct objfile * objfile ) { struct symtab * symtab ; struct gdb_block * gdb_block_iter , * gdb_block_iter_tmp ; struct block * block_iter ; int actual_nblocks , i , blockvector_size ; CORE_ADDR begin , end ; actual_nblocks = FIRST_LOCAL_BLOCK + stab -> nblocks ; symtab = allocate_symtab ( stab -> file_name , objfile ) ; symtab -> dirname = NULL ; if ( stab -> linetable ) { int size = ( ( stab -> linetable -> nitems - 1 ) * sizeof ( struct linetable_entry ) + sizeof ( struct linetable ) ) ; LINETABLE ( symtab ) = obstack_alloc ( & objfile -> objfile_obstack , size ) ; memcpy ( LINETABLE ( symtab ) , stab -> linetable , size ) ; } else { LINETABLE ( symtab ) = NULL ; } blockvector_size = ( sizeof ( struct blockvector ) + ( actual_nblocks - 1 ) * sizeof ( struct block * ) ) ; symtab -> blockvector = obstack_alloc ( & objfile -> objfile_obstack , blockvector_size ) ; symtab -> primary = 1 ; BLOCKVECTOR_MAP ( symtab -> blockvector ) = NULL ; begin = stab -> blocks -> begin ; end = stab -> blocks -> end ; BLOCKVECTOR_NBLOCKS ( symtab -> blockvector ) = actual_nblocks ; for ( i = ( actual_nblocks - 1 ) , gdb_block_iter = stab -> blocks ; i >= FIRST_LOCAL_BLOCK ; i -- , gdb_block_iter = gdb_block_iter -> next ) { struct block * new_block = allocate_block ( & objfile -> objfile_obstack ) ; struct symbol * block_name = obstack_alloc ( & objfile -> objfile_obstack , sizeof ( struct symbol ) ) ; BLOCK_DICT ( new_block ) = dict_create_linear ( & objfile -> objfile_obstack , NULL ) ; BLOCK_START ( new_block ) = ( CORE_ADDR ) gdb_block_iter -> begin ; BLOCK_END ( new_block ) = ( CORE_ADDR ) gdb_block_iter -> end ; memset ( block_name , 0 , sizeof ( struct symbol ) ) ; SYMBOL_DOMAIN ( block_name ) = VAR_DOMAIN ; SYMBOL_CLASS ( block_name ) = LOC_BLOCK ; SYMBOL_SYMTAB ( block_name ) = symtab ; SYMBOL_BLOCK_VALUE ( block_name ) = new_block ; block_name -> ginfo . name = obsavestring ( gdb_block_iter -> name , strlen ( gdb_block_iter -> name ) , & objfile -> objfile_obstack ) ; BLOCK_FUNCTION ( new_block ) = block_name ; BLOCKVECTOR_BLOCK ( symtab -> blockvector , i ) = new_block ; if ( begin > BLOCK_START ( new_block ) ) begin = BLOCK_START ( new_block ) ; if ( end < BLOCK_END ( new_block ) ) end = BLOCK_END ( new_block ) ; gdb_block_iter -> real_block = new_block ; } block_iter = NULL ; for ( i = 0 ; i < FIRST_LOCAL_BLOCK ; i ++ ) { struct block * new_block = allocate_block ( & objfile -> objfile_obstack ) ; BLOCK_DICT ( new_block ) = dict_create_linear ( & objfile -> objfile_obstack , NULL ) ; BLOCK_SUPERBLOCK ( new_block ) = block_iter ; block_iter = new_block ; BLOCK_START ( new_block ) = ( CORE_ADDR ) begin ; BLOCK_END ( new_block ) = ( CORE_ADDR ) end ; BLOCKVECTOR_BLOCK ( symtab -> blockvector , i ) = new_block ; } for ( gdb_block_iter = stab -> blocks ; gdb_block_iter ; gdb_block_iter = gdb_block_iter -> next ) { if ( gdb_block_iter -> parent != NULL ) BLOCK_SUPERBLOCK ( gdb_block_iter -> real_block ) = gdb_block_iter -> parent -> real_block ; } gdb_block_iter = stab -> blocks ; for ( gdb_block_iter = stab -> blocks , gdb_block_iter_tmp = gdb_block_iter -> next ; gdb_block_iter ; gdb_block_iter = gdb_block_iter_tmp ) { xfree ( ( void * ) gdb_block_iter -> name ) ; xfree ( gdb_block_iter ) ; } xfree ( stab -> linetable ) ; xfree ( ( char * ) stab -> file_name ) ; xfree ( stab ) ; }
Transform STAB to a proper symtab, and add it it OBJFILE.
Transform STAB to a proper symtab and add it it OBJFILE .
/* JIT compilers compile in memory.  */ /* Copy over the linetable entry if one was provided.  */ /* (begin, end) will contain the PC range this entire blockvector
     spans.  */ /* First run over all the gdb_block objects, creating a real block
     object for each.  Simultaneously, keep setting the real_block
     fields.  */ /* The address range.  */ /* The name.  */ /* Now add the special blocks.  */ /* Fill up the superblock fields for the real blocks, using the
     real_block fields populated earlier.  */ /* Free memory.  */