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

📄 symfile.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
      symfile_objfile = objfile;    }  /* If we have wiped out any old symbol tables, clean up.  */  clear_symtab_users_once ();  /* We're done reading the symbol file; finish off complaints.  */  clear_complaints (0, verbo);  /* Fixup all the breakpoints that may have been redefined by this     symbol file. */  breakpoint_re_set ();}/* Process a symbol file, as either the main file or as a dynamically   loaded file.   NAME is the file name (which will be tilde-expanded and made   absolute herein) (but we don't free or modify NAME itself).   FROM_TTY says how verbose to be.  MAINLINE specifies whether this   is the main symbol file, or whether it's an extra symbol file such   as dynamically loaded code.  If !mainline, ADDR is the address   where the text segment was loaded.   Upon success, returns a pointer to the objfile that was added.   Upon failure, jumps back to command level (never returns). */struct objfile *symbol_file_add (name, from_tty, addr, mainline, mapped, readnow)     char *name;     int from_tty;     CORE_ADDR addr;     int mainline;     int mapped;     int readnow;{  struct objfile *objfile;  struct partial_symtab *psymtab;  bfd *abfd;  /* Open a bfd for the file and then check to see if the file has a     symbol table.  There is a distinction between having no symbol table     (we refuse to read the file, leaving the old set of symbols around)     and having no debugging symbols in the symbol table (we read the file     and end up with a mostly empty symbol table, but with lots of stuff in     the minimal symbol table).  We need to make the decision about whether     to continue with the file before allocating and building a objfile.     FIXME:  This strategy works correctly when the debugging symbols are     intermixed with "normal" symbols.  However, when the debugging symbols     are separate, such as with ELF/DWARF, it is perfectly plausible for     the symbol table to be missing but still have all the DWARF info     intact.  Thus in general it is wrong to assume that having no symbol     table implies no debugging information. */  abfd = symfile_bfd_open (name);  if (!(bfd_get_file_flags (abfd) & HAS_SYMS))    {      error ("%s has no symbol-table", name);    }  if ((have_full_symbols () || have_partial_symbols ())      && mainline      && from_tty      && !query ("Load new symbol table from \"%s\"? ", name))      error ("Not confirmed.");        /* Getting new symbols may change our opinion about what is     frameless.  */  reinit_frame_cache ();  objfile = allocate_objfile (abfd, mapped);  /* If the objfile uses a mapped symbol file, and we have a psymtab for     it, then skip reading any symbols at this time. */  if ((objfile -> flags & OBJF_MAPPED) && (objfile -> flags & OBJF_SYMS))    {      /* We mapped in an existing symbol table file that already has had	 initial symbol reading performed, so we can skip that part.  Notify	 the user that instead of reading the symbols, they have been mapped.	 */      if (from_tty || info_verbose)	{	  printf_filtered ("Mapped symbols for %s...", name);	  wrap_here ("");	  fflush (stdout);	}      init_entry_point_info (objfile);      find_sym_fns (objfile);    }  else    {      /* We either created a new mapped symbol table, mapped an existing	 symbol table file which has not had initial symbol reading	 performed, or need to read an unmapped symbol table. */      if (from_tty || info_verbose)	{	  printf_filtered ("Reading symbols from %s...", name);	  wrap_here ("");	  fflush (stdout);	}      syms_from_objfile (objfile, addr, mainline, from_tty);    }        new_symfile_objfile (objfile, mainline, from_tty);  /* We now have at least a partial symbol table.  Check to see if the     user requested that all symbols be read on initial access via either     the gdb startup command line or on a per symbol file basis.  Expand     all partial symbol tables for this objfile if so. */  if (readnow || readnow_symbol_files)    {      if (from_tty || info_verbose)	{	  printf_filtered ("expanding to full symbols...");	  wrap_here ("");	  fflush (stdout);	}      for (psymtab = objfile -> psymtabs;	   psymtab != NULL;	   psymtab = psymtab -> next)	{	  psymtab_to_symtab (psymtab);	}    }  if (from_tty || info_verbose)    {      printf_filtered ("done.\n");      fflush (stdout);    }  return (objfile);}/* This is the symbol-file command.  Read the file, analyze its symbols,   and add a struct symtab to a symtab list.  */voidsymbol_file_command (args, from_tty)     char *args;     int from_tty;{  char **argv;  char *name = NULL;  struct cleanup *cleanups;  int mapped = 0;  int readnow = 0;  dont_repeat ();  if (args == NULL)    {      if ((have_full_symbols () || have_partial_symbols ())	  && from_tty	  && !query ("Discard symbol table from `%s'? ",		     symfile_objfile -> name))	error ("Not confirmed.");      free_all_objfiles ();      symfile_objfile = NULL;      current_source_symtab = NULL;      current_source_line = 0;      if (from_tty)	{	  printf ("No symbol file now.\n");	}    }  else    {      if ((argv = buildargv (args)) == NULL)	{	  nomem (0);	}      cleanups = make_cleanup (freeargv, (char *) argv);      while (*argv != NULL)	{	  if (strcmp (*argv, "-mapped") == 0)	    {	      mapped = 1;	    }	  else if (strcmp (*argv, "-readnow") == 0)	    {	      readnow = 1;	    }	  else if (**argv == '-')	    {	      error ("unknown option `%s'", *argv);	    }	  else	    {	      name = *argv;	    }	  argv++;	}      if (name == NULL)	{	  error ("no symbol file name was specified");	}      else	{	  symbol_file_add (name, from_tty, (CORE_ADDR)0, 1, mapped, readnow);	  set_initial_language ();	}      do_cleanups (cleanups);    }}/* Set the initial language.   A better solution would be to record the language in the psymtab when reading   partial symbols, and then use it (if known) to set the language.  This would   be a win for formats that encode the language in an easily discoverable place,   such as DWARF.  For stabs, we can jump through hoops looking for specially   named symbols or try to intuit the language from the specific type of stabs   we find, but we can't do that until later when we read in full symbols.   FIXME.  */static voidset_initial_language (){  struct partial_symtab *pst;  enum language lang = language_unknown;  	  pst = find_main_psymtab ();  if (pst != NULL)    {      if (pst -> filename != NULL)	{	  lang = deduce_language_from_filename (pst -> filename);        }      if (lang == language_unknown)	{	    /* Make C the default language */	    lang = language_c;	}      set_language (lang);      expected_language = current_language;	/* Don't warn the user */    }}/* Open file specified by NAME and hand it off to BFD for preliminary   analysis.  Result is a newly initialized bfd *, which includes a newly   malloc'd` copy of NAME (tilde-expanded and made absolute).   In case of trouble, error() is called.  */static bfd *symfile_bfd_open (name)     char *name;{  bfd *sym_bfd;  int desc;  char *absolute_name;  name = tilde_expand (name);	/* Returns 1st new malloc'd copy */  /* Look down path for it, allocate 2nd new malloc'd copy.  */  desc = openp (getenv ("PATH"), 1, name, O_RDONLY, 0, &absolute_name);  if (desc < 0)    {      make_cleanup (free, name);      perror_with_name (name);    }  free (name);			/* Free 1st new malloc'd copy */  name = absolute_name;		/* Keep 2nd malloc'd copy in bfd */				/* It'll be freed in free_objfile(). */  sym_bfd = bfd_fdopenr (name, NULL, desc);  if (!sym_bfd)    {      close (desc);      make_cleanup (free, name);      error ("\"%s\": can't open to read symbols: %s.", name,	     bfd_errmsg (bfd_error));    }  if (!bfd_check_format (sym_bfd, bfd_object))    {      bfd_close (sym_bfd);	/* This also closes desc */      make_cleanup (free, name);      error ("\"%s\": can't read symbols: %s.", name,	     bfd_errmsg (bfd_error));    }  return (sym_bfd);}/* Link a new symtab_fns into the global symtab_fns list.  Called on gdb   startup by the _initialize routine in each object file format reader,   to register information about each format the the reader is prepared   to handle. */voidadd_symtab_fns (sf)     struct sym_fns *sf;{  sf->next = symtab_fns;  symtab_fns = sf;}/* Initialize to read symbols from the symbol file sym_bfd.  It either   returns or calls error().  The result is an initialized struct sym_fns   in the objfile structure, that contains cached information about the   symbol file.  */static voidfind_sym_fns (objfile)     struct objfile *objfile;{  struct sym_fns *sf;  for (sf = symtab_fns; sf != NULL; sf = sf -> next)    {      if (strncmp (bfd_get_target (objfile -> obfd),		    sf -> sym_name, sf -> sym_namelen) == 0)	{	  objfile -> sf = sf;	  return;	}    }  /* XXX What moron thought this error message was cute? */#ifdef notdef  error ("I'm sorry, Dave, I can't do that.  Symbol format `%s' unknown.",	 bfd_get_target (objfile -> obfd));#else  error ("Symbol format `%s' unknown.", bfd_get_target (objfile->obfd));#endif}/* This function runs the load command of our current target.  */static voidload_command (arg, from_tty)     char *arg;     int from_tty;{  target_load (arg, from_tty);}/* This function allows the addition of incrementally linked object files.   It does not modify any state in the target, only in the debugger.  *//* ARGSUSED */static voidadd_symbol_file_command (args, from_tty)     char *args;     int from_tty;{  char *name = NULL;  CORE_ADDR text_addr;  char *arg;  int readnow = 0;  int mapped = 0;    dont_repeat ();  if (args == NULL)    {      error ("add-symbol-file takes a file name and an address");    }  /* Make a copy of the string that we can safely write into. */  args = strdup (args);  make_cleanup (free, args);  /* Pick off any -option args and the file name. */  while ((*args != '\000') && (name == NULL))    {      while (isspace (*args)) {args++;}      arg = args;      while ((*args != '\000') && !isspace (*args)) {args++;}      if (*args != '\000')	{	  *args++ = '\000';	}      if (*arg != '-')	{	  name = arg;	}      else if (strcmp (arg, "-mapped") == 0)	{	  mapped = 1;	}      else if (strcmp (arg, "-readnow") == 0)	{	  readnow = 1;	}      else	{	  error ("unknown option `%s'", arg);	}    }  /* After picking off any options and the file name, args should be     left pointing at the remainder of the command line, which should     be the address expression to evaluate. */  if ((name == NULL) || (*args == '\000') )    {      error ("add-symbol-file takes a file name and an address");    }  name = tilde_expand (name);  make_cleanup (free, name);  text_addr = parse_and_eval_address (args);  if (!query ("add symbol table from file \"%s\" at text_addr = %s?\n",	      name, local_hex_string (text_addr)))    error ("Not confirmed.");  symbol_file_add (name, 0, text_addr, 0, mapped, readnow);}/* Re-read symbols if a symbol-file has changed.  */voidreread_symbols (){  struct objfile *objfile;  long new_modtime;  int reread_one = 0;  struct stat new_statbuf;  int res;  /* With the addition of shared libraries, this should be modified,     the load time should be saved in the partial symbol tables, since     different tables may come from different source files.  FIXME.     This routine should then walk down each partial symbol table     and see if the symbol table that it originates from has been changed */the_big_top:  for (objfile = object_files; objfile; objfile = objfile->next) {    if (objfile->obfd) {#ifdef IBM6000_TARGET     /* If this object is from a shared library, then you should        stat on the library name, not member name. */     if (objfile->obfd->my_archive)       res = stat (objfile->obfd->my_archive->filename, &new_statbuf);     else#endif      res = stat (objfile->name, &new_statbuf);      if (res != 0) {	/* FIXME, should use print_sys_errmsg but it's not filtered. */	printf_filtered ("`%s' has disappeared; keeping its symbols.\n",			 objfile->name);	continue;      }      new_modtime = new_statbuf.st_mtime;      if (new_modtime != objfile->mtime) {	printf_filtered ("`%s' has changed; re-reading symbols.\n",			 objfile->name);	/* FIXME, this should use a different command...that would only 	   affect this objfile's symbols, and would reset objfile->mtime.                (objfile->mtime = new_modtime;) 	   HOWEVER, that command isn't written yet -- so call symbol_file_	   command, and restart the scan from the top, because it munges	   the object_files list.  */	symbol_file_command (objfile->name, 0);	reread_one = 1;	goto the_big_top;	/* Start over.  */      }    }  }  if (reread_one)    breakpoint_re_set ();}/* Functions to handle complaints during symbol reading.  *//* How many complaints about a particular thing should be printed before   we stop whining about it?  Default is no whining at all, since so many

⌨️ 快捷键说明

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