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

📄 symtab.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
	    SKIP_PROLOGUE (pc);	  values.sals[i] = find_pc_line (pc, 0);	  values.sals[i].pc = (values.sals[i].end && values.sals[i].pc != pc) ?			       values.sals[i].end                      :  pc;	  demangled = cplus_demangle (SYMBOL_NAME (sym_arr[i]),				      DMGL_PARAMS | DMGL_ANSI);	  printf("[%d] %s at %s:%d\n", (i+2),		 demangled ? demangled : SYMBOL_NAME (sym_arr[i]), 		 values.sals[i].symtab->filename, values.sals[i].line);	  if (demangled != NULL)	    {	      free (demangled);	    }	}      else printf ("?HERE\n");      i++;    }    if ((prompt = getenv ("PS2")) == NULL)    {      prompt = ">";    }  printf("%s ",prompt);  fflush(stdout);  args = command_line_input ((char *) NULL, 0);    if (args == 0)    error_no_arg ("one or more choice numbers");  i = 0;  while (*args)    {      int num;      arg1 = args;      while (*arg1 >= '0' && *arg1 <= '9') arg1++;      if (*arg1 && *arg1 != ' ' && *arg1 != '\t')	error ("Arguments must be choice numbers.");      num = atoi (args);      if (num == 0)	error ("cancelled");      else if (num == 1)	{	  memcpy (return_values.sals, values.sals,		  (nelts * sizeof(struct symtab_and_line)));	  return_values.nelts = nelts;	  return return_values;	}      if (num > nelts + 2)	{	  printf ("No choice number %d.\n", num);	}      else	{	  num -= 2;	  if (values.sals[num].pc)	    {	      return_values.sals[i++] = values.sals[num];	      values.sals[num].pc = 0;	    }	  else	    {	      printf ("duplicate request for %d ignored.\n", num);	    }	}      args = arg1;      while (*args == ' ' || *args == '\t') args++;    }  return_values.nelts = i;  return return_values;}/* Slave routine for sources_info.  Force line breaks at ,'s.   NAME is the name to print and *FIRST is nonzero if this is the first   name printed.  Set *FIRST to zero.  */static voidoutput_source_filename (name, first)     char *name;     int *first;{  /* Table of files printed so far.  Since a single source file can     result in several partial symbol tables, we need to avoid printing     it more than once.  Note: if some of the psymtabs are read in and     some are not, it gets printed both under "Source files for which     symbols have been read" and "Source files for which symbols will     be read in on demand".  I consider this a reasonable way to deal     with the situation.  I'm not sure whether this can also happen for     symtabs; it doesn't hurt to check.  */  static char **tab = NULL;  /* Allocated size of tab in elements.     Start with one 256-byte block (when using GNU malloc.c).     24 is the malloc overhead when range checking is in effect.  */  static int tab_alloc_size = (256 - 24) / sizeof (char *);  /* Current size of tab in elements.  */  static int tab_cur_size;  char **p;  if (*first)    {      if (tab == NULL)	tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab));      tab_cur_size = 0;    }  /* Is NAME in tab?  */  for (p = tab; p < tab + tab_cur_size; p++)    if (strcmp (*p, name) == 0)      /* Yes; don't print it again.  */      return;  /* No; add it to tab.  */  if (tab_cur_size == tab_alloc_size)    {      tab_alloc_size *= 2;      tab = (char **) xrealloc ((char *) tab, tab_alloc_size * sizeof (*tab));    }  tab[tab_cur_size++] = name;  if (*first)    {      *first = 0;    }  else    {      printf_filtered (", ");    }  wrap_here ("");  fputs_filtered (name, stdout);}  static voidsources_info (ignore, from_tty)     char *ignore;     int from_tty;{  register struct symtab *s;  register struct partial_symtab *ps;  register struct objfile *objfile;  int first;    if (!have_full_symbols () && !have_partial_symbols ())    {      error (no_symtab_msg);    }    printf_filtered ("Source files for which symbols have been read in:\n\n");  first = 1;  ALL_SYMTABS (objfile, s)    {      output_source_filename (s -> filename, &first);    }  printf_filtered ("\n\n");    printf_filtered ("Source files for which symbols will be read in on demand:\n\n");  first = 1;  ALL_PSYMTABS (objfile, ps)    {      if (!ps->readin)	{	  output_source_filename (ps -> filename, &first);	}    }  printf_filtered ("\n");}static intname_match (name)     char *name;{  char *demangled = cplus_demangle (name, DMGL_ANSI);  if (demangled != NULL)    {      int cond = re_exec (demangled);      free (demangled);      return (cond);    }  return (re_exec (name));}#define NAME_MATCH(NAME) name_match(NAME)/* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.   If CLASS is zero, list all symbols except functions, type names, and		     constants (enums).   If CLASS is 1, list only functions.   If CLASS is 2, list only type names.   If CLASS is 3, list only method names.   BPT is non-zero if we should set a breakpoint at the functions   we find.  */static voidlist_symbols (regexp, class, bpt)     char *regexp;     int class;     int bpt;{  register struct symtab *s;  register struct partial_symtab *ps;  register struct blockvector *bv;  struct blockvector *prev_bv = 0;  register struct block *b;  register int i, j;  register struct symbol *sym;  struct partial_symbol *psym;  struct objfile *objfile;  struct minimal_symbol *msymbol;  char *val;  static char *classnames[]    = {"variable", "function", "type", "method"};  int found_in_file = 0;  int found_misc = 0;  static enum minimal_symbol_type types[]    = {mst_data, mst_text, mst_abs, mst_unknown};  static enum minimal_symbol_type types2[]    = {mst_bss,  mst_text, mst_abs, mst_unknown};  enum minimal_symbol_type ourtype = types[class];  enum minimal_symbol_type ourtype2 = types2[class];  if (regexp)    {      /* Make sure spacing is right for C++ operators.	 This is just a courtesy to make the matching less sensitive	 to how many spaces the user leaves between 'operator'	 and <TYPENAME> or <OPERATOR>. */      char *opend;      char *opname = operator_chars (regexp, &opend);      if (*opname)	{          int fix = -1; /* -1 means ok; otherwise number of spaces needed. */	  if (isalpha(*opname) || *opname == '_' || *opname == '$')	    {	      /* There should 1 space between 'operator' and 'TYPENAME'. */	      if (opname[-1] != ' ' || opname[-2] == ' ')	        fix = 1;	    }	  else	    {	      /* There should 0 spaces between 'operator' and 'OPERATOR'. */	      if (opname[-1] == ' ')	        fix = 0;	    }	  /* If wrong number of spaces, fix it. */	  if (fix >= 0)	    {	      char *tmp = (char*) alloca(opend-opname+10);	      sprintf(tmp, "operator%.*s%s", fix, " ", opname);	      regexp = tmp;	    }        }            if (0 != (val = re_comp (regexp)))	error ("Invalid regexp (%s): %s", val, regexp);    }  /* Search through the partial symtabs *first* for all symbols     matching the regexp.  That way we don't have to reproduce all of     the machinery below. */  ALL_PSYMTABS (objfile, ps)    {      struct partial_symbol *bound, *gbound, *sbound;      int keep_going = 1;            if (ps->readin) continue;            gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms;      sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms;      bound = gbound;            /* Go through all of the symbols stored in a partial	 symtab in one loop. */      psym = objfile->global_psymbols.list + ps->globals_offset;      while (keep_going)	{	  if (psym >= bound)	    {	      if (bound == gbound && ps->n_static_syms != 0)		{		  psym = objfile->static_psymbols.list + ps->statics_offset;		  bound = sbound;		}	      else		keep_going = 0;	      continue;	    }	  else	    {	      QUIT;	      /* If it would match (logic taken from loop below)		 load the file and go on to the next one */	      if ((regexp == 0 || NAME_MATCH (SYMBOL_NAME (psym)))		  && ((class == 0 && SYMBOL_CLASS (psym) != LOC_TYPEDEF		       && SYMBOL_CLASS (psym) != LOC_BLOCK)		      || (class == 1 && SYMBOL_CLASS (psym) == LOC_BLOCK)		      || (class == 2 && SYMBOL_CLASS (psym) == LOC_TYPEDEF)		      || (class == 3 && SYMBOL_CLASS (psym) == LOC_BLOCK)))		{		  PSYMTAB_TO_SYMTAB(ps);		  keep_going = 0;		}	    }	  psym++;	}    }  /* Here, we search through the minimal symbol tables for functions that     match, and call find_pc_symtab on them to force their symbols to     be read.  The symbol will then be found during the scan of symtabs     below.  If find_pc_symtab fails, set found_misc so that we will     rescan to print any matching symbols without debug info.  */  if (class == 1)    {      ALL_MSYMBOLS (objfile, msymbol)	{	  if (msymbol -> type == ourtype || msymbol -> type == ourtype2)	    {	      if (regexp == 0 || NAME_MATCH (msymbol -> name))		{		  if (0 == find_pc_symtab (msymbol -> address))		    {		      found_misc = 1;		    }		}	    }	}    }  /* Printout here so as to get after the "Reading in symbols"     messages which will be generated above.  */  if (!bpt)    printf_filtered (regexp	  ? "All %ss matching regular expression \"%s\":\n"	  : "All defined %ss:\n",	  classnames[class],	  regexp);  ALL_SYMTABS (objfile, s)    {      found_in_file = 0;      bv = BLOCKVECTOR (s);      /* Often many files share a blockvector.	 Scan each blockvector only once so that	 we don't get every symbol many times.	 It happens that the first symtab in the list	 for any given blockvector is the main file.  */      if (bv != prev_bv)	for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)	  {	    b = BLOCKVECTOR_BLOCK (bv, i);	    /* Skip the sort if this block is always sorted.  */	    if (!BLOCK_SHOULD_SORT (b))	      sort_block_syms (b);	    for (j = 0; j < BLOCK_NSYMS (b); j++)	      {		QUIT;		sym = BLOCK_SYM (b, j);		if ((regexp == 0 || NAME_MATCH (SYMBOL_NAME (sym)))		    && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF			 && SYMBOL_CLASS (sym) != LOC_BLOCK			 && SYMBOL_CLASS (sym) != LOC_CONST)			|| (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)			|| (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)			|| (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK)))		  {		    if (bpt)		      {			/* Set a breakpoint here, if it's a function */			if (class == 1)			  break_command (SYMBOL_NAME(sym), 0);		      }		    else if (!found_in_file)		      {			fputs_filtered ("\nFile ", stdout);			fputs_filtered (s->filename, stdout);			fputs_filtered (":\n", stdout);		      }		    found_in_file = 1;		    		    if (class != 2 && i == STATIC_BLOCK)		      printf_filtered ("static ");		    		    /* Typedef that is not a C++ class */		    if (class == 2			&& SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)		      typedef_print (SYMBOL_TYPE(sym), sym, stdout);		    /* variable, func, or typedef-that-is-c++-class */		    else if (class < 2 || 			     (class == 2 && 			      SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE))		      {			type_print (SYMBOL_TYPE (sym),				    (SYMBOL_CLASS (sym) == LOC_TYPEDEF				     ? "" : SYMBOL_NAME (sym)),				    stdout, 0);						printf_filtered (";\n");		      }		    else		      {# if 0/* FIXME, why is this zapped out? */			char buf[1024];			type_print_base (TYPE_FN_FIELD_TYPE(t, i), stdout, 0, 0); 			type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i), stdout, 0); 			sprintf (buf, " %s::", type_name_no_tag (t));			type_print_method_args (TYPE_FN_FIELD_ARGS (t, i), buf, name, stdout);# endif		      }		  }	      }	  }      prev_bv = bv;    }  /* If there are no eyes, avoid all contact.  I mean, if there are     no debug symbols, then print directly from the msymbol_vector.  */  if (found_misc || class != 1)    {      found_in_file = 0;      ALL_MSYMBOLS (objfile, msymbol)	{	  if (msymbol -> type == ourtype || msymbol -> type == ourtype2)	    {	      if (regexp == 0 || NAME_MATCH (msymbol -> name))		{		  /* Functions:  Look up by address. */		  if (class != 1 ||		      (0 == find_pc_symtab (msymbol -> address)))		    {		      /* Variables/Absolutes:  Look up by name */		      if (lookup_symbol (msymbol -> name, 					 (struct block *) 0, VAR_NAMESPACE, 0,					 (struct symtab **) 0) == NULL)			{			  if (!found_in_file)			    {			      printf_filtered ("\nNon-debugging symbols:\n");			      found_in_file = 1;			    }			  printf_filtered ("	%08x  %s\n",					   msymbol -> address,					   msymbol -> name);			}		    }		}	    }	}    }}static voidvariables_info (regexp, from_tty)     char *regexp;     int from_tty;{  list_symbols (regexp, 0, 0);}static voidfunctions_info (regexp, from_tty)     char *regexp;     int from_tty;{  list_symbols (regexp, 1, 0);}static voidtypes_info (regexp, from_tty)     char *regexp;     int from_tty;{  list_symbols (re

⌨️ 快捷键说明

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