⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbxread.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
{  register struct header_file *f = &header_files[real_filenum];  if (index >= f->length)    {      f->length *= 2;      f->vector = (struct type **)	xrealloc (f->vector, f->length * sizeof (struct type *));      bzero (&f->vector[f->length / 2],	     f->length * sizeof (struct type *) / 2);    }  return &f->vector[index];}#endifstatic voidrecord_minimal_symbol (name, address, type, objfile)     char *name;     CORE_ADDR address;     int type;     struct objfile *objfile;{  enum minimal_symbol_type ms_type;  switch (type &~ N_EXT) {    case N_TEXT:  ms_type = mst_text; break;    case N_DATA:  ms_type = mst_data; break;    case N_BSS:   ms_type = mst_bss;  break;    case N_ABS:   ms_type = mst_abs;  break;#ifdef N_SETV    case N_SETV:  ms_type = mst_data; break;#endif    default:      ms_type = mst_unknown; break;  }  prim_record_minimal_symbol (obsavestring (name, strlen (name), &objfile -> symbol_obstack),			     address, ms_type);}/* Scan and build partial symbols for a symbol file.   We have been initialized by a call to dbx_symfile_init, which    put all the relevant info into a "struct dbx_symfile_info",   hung off the objfile structure.   SECTION_OFFSETS contains offsets relative to which the symbols in the   various sections are (depending where the sections were actually loaded).   MAINLINE is true if we are reading the main symbol   table (as opposed to a shared lib or dynamically loaded file).  */static voiddbx_symfile_read (objfile, section_offsets, mainline)     struct objfile *objfile;     struct section_offsets *section_offsets;     int mainline;	/* FIXME comments above */{  bfd *sym_bfd;  int val;  sym_bfd = objfile->obfd;  val = bfd_seek (objfile->obfd, DBX_SYMTAB_OFFSET (objfile), L_SET);  if (val < 0)    perror_with_name (objfile->name);  /* If we are reinitializing, or if we have never loaded syms yet, init */  if (mainline || objfile->global_psymbols.size == 0 || objfile->static_psymbols.size == 0)    init_psymbol_list (objfile);#ifdef GDB_TARGET_IS_HPPA  symbol_size = obj_dbx_symbol_entry_size (sym_bfd);#else  symbol_size = DBX_SYMBOL_SIZE (objfile);#endif  symbol_table_offset = DBX_SYMTAB_OFFSET (objfile);  pending_blocks = 0;  make_cleanup (really_free_pendings, 0);  init_minimal_symbol_collection ();  make_cleanup (discard_minimal_symbols, 0);  /* Now that the symbol table data of the executable file are all in core,     process them and define symbols accordingly.  */  read_dbx_symtab (section_offsets, objfile,		   bfd_section_vma  (sym_bfd, DBX_TEXT_SECT (objfile)),		   bfd_section_size (sym_bfd, DBX_TEXT_SECT (objfile)));  /* Install any minimal symbols that have been collected as the current     minimal symbols for this objfile. */  install_minimal_symbols (objfile);  if (!have_partial_symbols ()) {    wrap_here ("");    printf_filtered ("(no debugging symbols found)...");    wrap_here ("");  }}/* Initialize anything that needs initializing when a completely new   symbol file is specified (not just adding some symbols from another   file, e.g. a shared library).  */static voiddbx_new_init (ignore)     struct objfile *ignore;{  stabsread_new_init ();  buildsym_new_init ();  init_header_files ();}/* dbx_symfile_init ()   is the dbx-specific initialization routine for reading symbols.   It is passed a struct objfile which contains, among other things,   the BFD for the file whose symbols are being read, and a slot for a pointer   to "private data" which we fill with goodies.   We read the string table into malloc'd space and stash a pointer to it.   Since BFD doesn't know how to read debug symbols in a format-independent   way (and may never do so...), we have to do it ourselves.  We will never   be called unless this is an a.out (or very similar) file.    FIXME, there should be a cleaner peephole into the BFD environment here.  */static voiddbx_symfile_init (objfile)     struct objfile *objfile;{  int val;  bfd *sym_bfd = objfile->obfd;  char *name = bfd_get_filename (sym_bfd);  unsigned char size_temp[4];  /* Allocate struct to keep track of the symfile */  objfile->sym_private = (PTR)    xmmalloc (objfile -> md, sizeof (struct dbx_symfile_info));  /* FIXME POKING INSIDE BFD DATA STRUCTURES */#ifdef GDB_TARGET_IS_HPPA#define STRING_TABLE_OFFSET  (sym_bfd->origin + obj_dbx_str_filepos (sym_bfd))#define SYMBOL_TABLE_OFFSET  (sym_bfd->origin + obj_dbx_sym_filepos (sym_bfd))#define HP_STRING_TABLE_OFFSET  (sym_bfd->origin + obj_hp_str_filepos (sym_bfd))#define HP_SYMBOL_TABLE_OFFSET  (sym_bfd->origin + obj_hp_sym_filepos (sym_bfd))#else#define	STRING_TABLE_OFFSET	(sym_bfd->origin + obj_str_filepos (sym_bfd))#define	SYMBOL_TABLE_OFFSET	(sym_bfd->origin + obj_sym_filepos (sym_bfd))#endif  /* FIXME POKING INSIDE BFD DATA STRUCTURES */  DBX_SYMFILE_INFO (objfile)->stab_section_info = NULL;  DBX_TEXT_SECT (objfile) = bfd_get_section_by_name (sym_bfd, ".text");  if (!DBX_TEXT_SECT (objfile))    error ("Can't find .text section in symbol file");#ifdef GDB_TARGET_IS_HPPA  HP_SYMCOUNT (objfile) = obj_hp_sym_count (sym_bfd);  DBX_SYMCOUNT (objfile) = obj_dbx_sym_count (sym_bfd);#else  DBX_SYMBOL_SIZE (objfile) = obj_symbol_entry_size (sym_bfd);  DBX_SYMCOUNT (objfile) = bfd_get_symcount (sym_bfd);#endif  DBX_SYMTAB_OFFSET (objfile) = SYMBOL_TABLE_OFFSET;  /* Read the string table and stash it away in the psymbol_obstack.  It is     only needed as long as we need to expand psymbols into full symbols,     so when we blow away the psymbol the string table goes away as well.     Note that gdb used to use the results of attempting to malloc the     string table, based on the size it read, as a form of sanity check     for botched byte swapping, on the theory that a byte swapped string     table size would be so totally bogus that the malloc would fail.  Now     that we put in on the psymbol_obstack, we can't do this since gdb gets     a fatal error (out of virtual memory) if the size is bogus.  We can     however at least check to see if the size is zero or some negative     value. */#ifdef GDB_TARGET_IS_HPPA  DBX_STRINGTAB_SIZE (objfile) = obj_dbx_stringtab_size (sym_bfd);  HP_STRINGTAB_SIZE (objfile) = obj_hp_stringtab_size (sym_bfd);#else  val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);  if (val < 0)    perror_with_name (name);  val = bfd_read ((PTR)size_temp, sizeof (long), 1, sym_bfd);  if (val < 0)    perror_with_name (name);  DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);#endif  if (DBX_STRINGTAB_SIZE (objfile) <= 0)    error ("ridiculous string table size (%d bytes).",	   DBX_STRINGTAB_SIZE (objfile));  DBX_STRINGTAB (objfile) =    (char *) obstack_alloc (&objfile -> psymbol_obstack,			    DBX_STRINGTAB_SIZE (objfile));#ifdef GDB_TARGET_IS_HPPA  if (HP_STRINGTAB_SIZE (objfile) <= 0)    error ("ridiculous string table size (%d bytes).",	   HP_STRINGTAB_SIZE (objfile));  HP_STRINGTAB (objfile) =    (char *) obstack_alloc (&objfile -> psymbol_obstack,			    HP_STRINGTAB_SIZE (objfile));#endif  /* Now read in the string table in one big gulp.  */  val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);  if (val < 0)    perror_with_name (name);  val = bfd_read (DBX_STRINGTAB (objfile), DBX_STRINGTAB_SIZE (objfile), 1,		  sym_bfd);  if (val != DBX_STRINGTAB_SIZE (objfile))    perror_with_name (name);#ifdef GDB_TARGET_IS_HPPA  val = bfd_seek (sym_bfd, HP_STRING_TABLE_OFFSET, L_SET);  if (val < 0)    perror_with_name (name);  val = bfd_read (HP_STRINGTAB (objfile), HP_STRINGTAB_SIZE (objfile), 1,		  sym_bfd);  if (val != HP_STRINGTAB_SIZE (objfile))    perror_with_name (name);#endif#ifdef GDB_TARGET_IS_HPPA  HP_SYMTAB_OFFSET (objfile) = HP_SYMBOL_TABLE_OFFSET;#endif}/* Perform any local cleanups required when we are done with a particular   objfile.  I.E, we are in the process of discarding all symbol information   for an objfile, freeing up all memory held for it, and unlinking the   objfile struct from the global list of known objfiles. */static voiddbx_symfile_finish (objfile)     struct objfile *objfile;{  if (objfile->sym_private != NULL)    {      mfree (objfile -> md, objfile->sym_private);    }  free_header_files ();}/* Buffer for reading the symbol table entries.  */static struct internal_nlist symbuf[4096];static int symbuf_idx;static int symbuf_end;/* Name of last function encountered.  Used in Solaris to approximate   object file boundaries.  */static char *last_function_name;/* The address in memory of the string table of the object file we are   reading (which might not be the "main" object file, but might be a   shared library or some other dynamically loaded thing).  This is set   by read_dbx_symtab when building psymtabs, and by read_ofile_symtab    when building symtabs, and is used only by next_symbol_text.  */static char *stringtab_global;/* Refill the symbol table input buffer   and set the variables that control fetching entries from it.   Reports an error if no data available.   This function can read past the end of the symbol table   (into the string table) but this does no harm.  */static voidfill_symbuf (sym_bfd)     bfd *sym_bfd;{  int nbytes = bfd_read ((PTR)symbuf, sizeof (symbuf), 1, sym_bfd);  if (nbytes < 0)    perror_with_name (bfd_get_filename (sym_bfd));  else if (nbytes == 0)    error ("Premature end of file reading symbol table");  symbuf_end = nbytes / symbol_size;  symbuf_idx = 0;}#ifdef GDB_TARGET_IS_HPPA/* same as above for the HP symbol table */static struct symbol_dictionary_record hp_symbuf[4096];static int hp_symbuf_idx;static int hp_symbuf_end;static intfill_hp_symbuf (sym_bfd)     bfd *sym_bfd;{  int nbytes = bfd_read ((PTR)hp_symbuf, sizeof (hp_symbuf), 1, sym_bfd);  if (nbytes <= 0)    error ("error or end of file reading symbol table");  hp_symbuf_end = nbytes / sizeof (struct symbol_dictionary_record);  hp_symbuf_idx = 0;  return 1;}#endif#define SWAP_SYMBOL(symp, abfd) \  { \    (symp)->n_strx = bfd_h_get_32(abfd,			\				(unsigned char *)&(symp)->n_strx);	\    (symp)->n_desc = bfd_h_get_16 (abfd,			\				(unsigned char *)&(symp)->n_desc);  	\    (symp)->n_value = bfd_h_get_32 (abfd,			\				(unsigned char *)&(symp)->n_value); 	\  }/* Invariant: The symbol pointed to by symbuf_idx is the first one   that hasn't been swapped.  Swap the symbol at the same time   that symbuf_idx is incremented.  *//* dbx allows the text of a symbol name to be continued into the   next symbol name!  When such a continuation is encountered   (a \ at the end of the text of a name)   call this function to get the continuation.  */static char *dbx_next_symbol_text (){  if (symbuf_idx == symbuf_end)    fill_symbuf (symfile_bfd);  symnum++;  SWAP_SYMBOL(&symbuf[symbuf_idx], symfile_bfd);  return symbuf[symbuf_idx++].n_strx + stringtab_global	  + file_string_table_offset;}/* Initializes storage for all of the partial symbols that will be   created by read_dbx_symtab and subsidiaries.  */static voidinit_psymbol_list (objfile)     struct objfile *objfile;{  /* Free any previously allocated psymbol lists.  */  if (objfile -> global_psymbols.list)    mfree (objfile -> md, (PTR)objfile -> global_psymbols.list);  if (objfile -> static_psymbols.list)    mfree (objfile -> md, (PTR)objfile -> static_psymbols.list);  /* Current best guess is that there are approximately a twentieth     of the total symbols (in a debugging file) are global or static     oriented symbols */#ifdef GDB_TARGET_IS_HPPA  objfile -> global_psymbols.size = (DBX_SYMCOUNT (objfile) + 				     HP_SYMCOUNT (objfile)) / 10;  objfile -> static_psymbols.size = (DBX_SYMCOUNT (objfile) +				     HP_SYMCOUNT (objfile)) / 10;#else  objfile -> global_psymbols.size = DBX_SYMCOUNT (objfile) / 10;  objfile -> static_psymbols.size = DBX_SYMCOUNT (objfile) / 10;#endif  objfile -> global_psymbols.next = objfile -> global_psymbols.list = (struct partial_symbol *)    xmmalloc (objfile -> md, objfile -> global_psymbols.size * sizeof (struct partial_symbol));  objfile -> static_psymbols.next = objfile -> static_psymbols.list = (struct partial_symbol *)    xmmalloc (objfile -> md, objfile -> static_psymbols.size * sizeof (struct partial_symbol));}/* Initialize the list of bincls to contain none and have some   allocated.  */static voidinit_bincl_list (number, objfile)     int number;     struct objfile *objfile;{  bincls_allocated = number;  next_bincl = bincl_list = (struct header_file_location *)    xmmalloc (objfile -> md, bincls_allocated * sizeof(struct header_file_location));}/* Add a bincl to the list.  */static voidadd_bincl_to_list (pst, name, instance)     struct partial_symtab *pst;     char *name;     int instance;{  if (next_bincl >= bincl_list + bincls_allocated)    {      int offset = next_bincl - bincl_list;      bincls_allocated *= 2;      bincl_list = (struct header_file_location *)	xmrealloc (pst->objfile->md, (char *)bincl_list,		  bincls_allocated * sizeof (struct header_file_location));      next_bincl = bincl_list + offset;    }  next_bincl->pst = pst;  next_bincl->instance = instance;  next_bincl++->name = name;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -