switch (*p) { case '!': case '=': case '*': case '/': case '%': case '^': if (p[1] == '=') *end = p+2; else *end = p+1; return p; case '<': case '>': case '+': case '-': case '&': case '|': if (p[1] == '=' || p[1] == p[0]) *end = p+2; else *end = p+1; return p; case '~': case ',': *end = p+1; return p; case '(': if (p[1] != ')') error ("`operator ()' must be specified without whitespace in `()'"); *end = p+2; return p; case '?': if (p[1] != ':') error ("`operator ?:' must be specified without whitespace in `?:'"); *end = p+2; return p; case '[': if (p[1] != ']') error ("`operator []' must be specified without whitespace in `[]'"); *end = p+2; return p; default: error ("`operator %s' not supported", p); break; }
while (*p) switch (*p) { case '\\':			 if (p[1] == '*') { if (p[2] == '=')	 *end = p + 3; else			 *end = p + 2; return p; } else if (p[1] == '[') { if (p[2] == ']') error ("mismatched quoting on brackets, try 'operator\\[\\]'"); else if (p[2] == '\\' && p[3] == ']') { *end = p + 4;	 return p; } else error ("nothing is allowed between '[' and ']'"); } else {  p++; continue; } break; case '!': case '=': case '*': case '/': case '%': case '^': if (p[1] == '=') *end = p + 2; else *end = p + 1; return p; case '<': case '>': case '+': case '-': case '&': case '|': if (p[0] == '-' && p[1] == '>') {  if (p[2] == '*') { *end = p + 3;	 return p; } else if (p[2] == '\\') { *end = p + 4;	 return p; } else { *end = p + 2;	 return p; } } if (p[1] == '=' || p[1] == p[0]) *end = p + 2; else *end = p + 1; return p; case '~': case ',': *end = p + 1; return p; case '(': if (p[1] != ')') error ("`operator ()' must be specified without whitespace in `()'"); *end = p + 2; return p; case '?': if (p[1] != ':') error ("`operator ?:' must be specified without whitespace in `?:'"); *end = p + 2; return p; case '[': if (p[1] != ']') error ("`operator []' must be specified without whitespace in `[]'"); *end = p + 2; return p; default: error ("`operator %s' not supported", p); break; }
operator_chars PARAMS ((char *, char **));static int find_line_common PARAMS ((struct linetable *, int, int *));static struct partial_symbol *lookup_partial_symbol PARAMS ((struct partial_symtab *, const char *,			       int, namespace_enum));static struct symtab *lookup_symtab_1 PARAMS ((char *));static voidcplusplus_hint PARAMS ((char *));/* *//* The single non-language-specific builtin type */struct type *builtin_type_error;/* Block in which the most recently searched-for symbol was found.   Might be better to make this a parameter to lookup_symbol and    value_of_this. */const struct block *block_found;char no_symtab_msg[] = "No symbol table is loaded.  Use the \"file\" command.";/* While the C++ support is still in flux, issue a possibly helpful hint on   using the new command completion feature on single quoted demangled C++   symbols.  Remove when loose ends are cleaned up.   FIXME -fnf */static voidcplusplus_hint (name)     char *name;{  while (*name == '\'')    name++;  printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name, name);  printf_filtered ("(Note leading single quote.)\n");}/* Check for a symtab of a specific name; first in symtabs, then in   psymtabs.  *If* there is no '/' in the name, a match after a '/'   in the symtab filename will also work.  */static struct symtab *lookup_symtab_1 (name)     char *name;{  register struct symtab *s;  register struct partial_symtab *ps;  register char *slash;  register struct objfile *objfile; got_symtab:  /* First, search for an exact match */  ALL_SYMTABS (objfile, s)    if (STREQ (name, s->filename))      return s;  slash = strchr (name, '/');  /* Now, search for a matching tail (only if name doesn't have any dirs) */  if (!slash)    ALL_SYMTABS (objfile, s)      {	char *p = s -> filename;	char *tail = strrchr (p, '/');	if (tail)	  p = tail + 1;	if (STREQ (p, name))	  return s;      }  /* Same search rules as above apply here, but now we look thru the     psymtabs.  */  ps = lookup_partial_symtab (name);  if (!ps)    return (NULL);  if (ps -> readin)    error ("Internal: readin %s pst for `%s' found when no symtab found.",	   ps -> filename, name);  s = PSYMTAB_TO_SYMTAB (ps);  if (s)    return s;  /* At this point, we have located the psymtab for this file, but     the conversion to a symtab has failed.  This usually happens     when we are looking up an include file.  In this case,     PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has     been created.  So, we need to run through the symtabs again in     order to find the file.     XXX - This is a crock, and should be fixed inside of the the     symbol parsing routines. */  goto got_symtab;}/* Lookup the symbol table of a source file named NAME.  Try a couple   of variations if the first lookup doesn't work.  */struct symtab *lookup_symtab (name)     char *name;{  register struct symtab *s;#if 0  register char *copy;#endif  s = lookup_symtab_1 (name);  if (s) return s;#if 0  /* This screws c-exp.y:yylex if there is both a type "tree" and a symtab     "tree.c".  */  /* If name not found as specified, see if adding ".c" helps.  */  /* Why is this?  Is it just a user convenience?  (If so, it's pretty     questionable in the presence of C++, FORTRAN, etc.).  It's not in     the GDB manual.  */  copy = (char *) alloca (strlen (name) + 3);  strcpy (copy, name);  strcat (copy, ".c");  s = lookup_symtab_1 (copy);  if (s) return s;#endif /* 0 */  /* We didn't find anything; die.  */  return 0;}/* Lookup the partial symbol table of a source file named NAME.   *If* there is no '/' in the name, a match after a '/'   in the psymtab filename will also work.  */struct partial_symtab *lookup_partial_symtab (name)char *name;{  register struct partial_symtab *pst;  register struct objfile *objfile;    ALL_PSYMTABS (objfile, pst)    {      if (STREQ (name, pst -> filename))	{	  return (pst);	}    }  /* Now, search for a matching tail (only if name doesn't have any dirs) */  if (!strchr (name, '/'))    ALL_PSYMTABS (objfile, pst)      {	char *p = pst -> filename;	char *tail = strrchr (p, '/');	if (tail)	  p = tail + 1;	if (STREQ (p, name))	  return (pst);      }  return (NULL);}/* Demangle a GDB method stub type.   Note that this function is g++ specific. */char *gdb_mangle_name (type, i, j)     struct type *type;     int i, j;{  int mangled_name_len;  char *mangled_name;  struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);  struct fn_field *method = &f[j];  char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);  char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);  char *newname = type_name_no_tag (type);  /* Does the form of physname indicate that it is the full mangled name     of a constructor (not just the args)?  */  int is_full_physname_constructor;  int is_constructor;  int is_destructor = DESTRUCTOR_PREFIX_P (physname);  /* Need a new type prefix.  */  char *const_prefix = method->is_const ? "C" : "";  char *volatile_prefix = method->is_volatile ? "V" : "";  char buf[20];  int len = (newname == NULL ? 0 : strlen (newname));  is_full_physname_constructor =     ((physname[0]=='_' && physname[1]=='_' &&       (isdigit(physname[2]) || physname[2]=='Q' || physname[2]=='t'))     || (strncmp(physname, "__ct", 4) == 0));  is_constructor =    is_full_physname_constructor || (newname && STREQ(field_name, newname));  if (!is_destructor)    is_destructor = (strncmp(physname, "__dt", 4) == 0);   if (is_destructor || is_full_physname_constructor)    {      mangled_name = (char*) xmalloc(strlen(physname)+1);      strcpy(mangled_name, physname);      return mangled_name;    }  if (len == 0)    {      sprintf (buf, "__%s%s", const_prefix, volatile_prefix);      if (strcmp(buf, "__") == 0)	buf[0] = '\0';    }  else if (newname != NULL && strchr (newname, '<') != NULL)    {      /* Template methods are fully mangled.  */      sprintf (buf, "__%s%s", const_prefix, volatile_prefix);      newname = NULL;      len = 0;    }  else    {      sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);    }  mangled_name_len = ((is_constructor ? 0 : strlen (field_name))			  + strlen (buf) + len			  + strlen (physname)			  + 1);  /* Only needed for GNU-mangled names.  ANSI-mangled names     work with the normal mechanisms.  */  if (OPNAME_PREFIX_P (field_name))    {      const char *opname = cplus_mangle_opname (field_name + 3, 0);      if (opname == NULL)	error ("No mangling for \"%s\"", field_name);      mangled_name_len += strlen (opname);      mangled_name = (char *)xmalloc (mangled_name_len);      strncpy (mangled_name, field_name, 3);      mangled_name[3] = '\0';      strcat (mangled_name, opname);    }  else    {      mangled_name = (char *)xmalloc (mangled_name_len);      if (is_constructor)	mangled_name[0] = '\0';      else	strcpy (mangled_name, field_name);    }  strcat (mangled_name, buf);  /* If the class doesn't have a name, i.e. newname NULL, then we just     mangle it using 0 for the length of the class.  Thus it gets mangled     as something starting with `::' rather than `classname::'. */   if (newname != NULL)    strcat (mangled_name, newname);  strcat (mangled_name, physname);  return (mangled_name);}/* Find which partial symtab on contains PC.  Return 0 if none.  */struct partial_symtab *find_pc_psymtab (pc)     register CORE_ADDR pc;{  register struct partial_symtab *pst;  register struct objfile *objfile;  ALL_PSYMTABS (objfile, pst)    {      if (pc >= pst->textlow && pc < pst->texthigh)	{	  struct minimal_symbol *msymbol;	  struct partial_symtab *tpst;	  /* An objfile that has its functions reordered might have	     many partial symbol tables containing the PC, but	     we want the partial symbol table that contains the	     function containing the PC.  */	  if (!(objfile->flags & OBJF_REORDERED))	    return (pst);	  msymbol = lookup_minimal_symbol_by_pc (pc);	  if (msymbol == NULL)	    return (pst);	  for (tpst = pst; tpst != NULL; tpst = tpst->next)	    {	      if (pc >= tpst->textlow && pc < tpst->texthigh)		{		  struct partial_symbol *p;		  p = find_pc_psymbol (tpst, pc);		  if (p != NULL		      && SYMBOL_VALUE_ADDRESS(p)			 == SYMBOL_VALUE_ADDRESS (msymbol))		    return (tpst);		}	    }	  return (pst);	}    }  return (NULL);}/* Find which partial symbol within a psymtab contains PC.  Return 0   if none.  Check all psymtabs if PSYMTAB is 0.  */struct partial_symbol *find_pc_psymbol (psymtab, pc)     struct partial_symtab *psymtab;     CORE_ADDR pc;{  struct partial_symbol *best = NULL, *p, **pp;  CORE_ADDR best_pc;    if (!psymtab)    psymtab = find_pc_psymtab (pc);  if (!psymtab)    return 0;  best_pc = psymtab->textlow - 1;  /* Search the global symbols as well as the static symbols, so that     find_pc_partial_function doesn't use a minimal symbol and thus     cache a bad endaddr.  */  for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;       (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)	< psymtab->n_global_syms);       pp++)    {      p = *pp;      if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE	  && SYMBOL_CLASS (p) == LOC_BLOCK	  && pc >= SYMBOL_VALUE_ADDRESS (p)	  && SYMBOL_VALUE_ADDRESS (p) > best_pc)	{	  best_pc = SYMBOL_VALUE_ADDRESS (p);	  best = p;	}    }  for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;       (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)	< psymtab->n_static_syms);       pp++)    {      p = *pp;      if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE	  && SYMBOL_CLASS (p) == LOC_BLOCK	  && pc >= SYMBOL_VALUE_ADDRESS (p)	  && SYMBOL_VALUE_ADDRESS (p) > best_pc)	{	  best_pc = SYMBOL_VALUE_ADDRESS (p);	  best = p;	}    }  if (best_pc == psymtab->textlow - 1)    return 0;  return best;}/* Find the definition for a specified symbol name NAME   in namespace NAMESPACE, visible from lexical block BLOCK.   Returns the struct symbol pointer, or zero if no symbol is found.   If SYMTAB is non-NULL, store the symbol table in which the   symbol was found there, or NULL if not found.   C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if   NAME is a field of the current implied argument `this'.  If so set   *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.    BLOCK_FOUND is set to the block in which NAME is found (in the case of   a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) *//* This function has a bunch of loops in it and it would seem to be   attractive to put in some QUIT's (though I'm not really sure   whether it can run long enough to be really important).  But there   are a few calls for which it would appear to be bad news to quit   out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and   nindy_frame_chain_valid in nindy-tdep.c.  (Note that there is C++   code below which can error(), but that probably doesn't affect   these calls since they are looking for a known variable and thus   can probably assume it will never hit the C++ code).  */struct symbol *lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)     const char *name;     register const struct block *block;     const namespace_enum namespace;     int *is_a_field_of_this;     struct symtab **symtab;{  register struct symbol *sym;  register struct symtab *s = NULL;  register struct partial_symtab *ps;  struct blockvector *bv;  register struct objfile *objfile;  register struct block *b;  register struct minimal_symbol *msymbol;  /* Search specified block and its superiors.  */  while (block != 0)    {      sym = lookup_block_symbol (block, name, namespace);      if (sym) 	{	  block_found = block;	  if (symtab != NULL)	    {	      /* Search the list of symtabs for one which contains the		 address of the start of this block.  */	      ALL_SYMTABS (objfile, s)		{		  bv = BLOCKVECTOR (s);		  b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);		  if (BLOCK_START (b) <= BLOCK_START (block)		      && BLOCK_END (b) > BLOCK_START (block))		    goto found;		}found:	      *symtab = s;	    }	  return (sym);	}      block = BLOCK_SUPERBLOCK (block);    }  /* FIXME: this code is never executed--block is always NULL at this     point.  What is it trying to do, anyway?  We already should have     checked the STATIC_BLOCK above (it is the superblock of top-level     blocks).  Why is VAR_NAMESPACE special-cased?  */  /* Don't need to mess with the psymtabs; if we have a block,     that file is read in.  If we don't, then we deal later with     all the psymtab stuff that needs checking.  */  if (namespace == VAR_NAMESPACE && block != NULL)    {      struct block *b;      /* Find the right symtab.  */      ALL_SYMTABS (objfile, s)	{	  bv = BLOCKVECTOR (s);	  b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);	  if (BLOCK_START (b) <= BLOCK_START (block)	      && BLOCK_END (b) > BLOCK_START (block))	    {	      sym = lookup_block_symbol (b, name, VAR_NAMESPACE);	      if (sym)		{		  block_found = b;		  if (symtab != NULL)		    *symtab = s;		  return sym;		}	    }	}    }  /* C++: If requested to do so by the caller,      check to see if NAME is a field of `this'. */  if (is_a_field_of_this)    {      struct value *v = value_of_this (0);            *is_a_field_of_this = 0;      if (v && check_field (v, name))	{	  *is_a_field_of_this = 1;	  if (symtab != NULL)	    *symtab = NULL;	  return 0;	}    }  /* Now search all global blocks.  Do the symtab's first, then     check the psymtab's */    ALL_SYMTABS (objfile, s)    {      bv = BLOCKVECTOR (s);      block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);      sym = lookup_block_symbol (block, name, namespace);      if (sym) 	{	  block_found = block;	  if (symtab != NULL)	    *symtab = s;	  return sym;	}    }  /* Check for the possibility of the symbol being a function or     a mangled variable that is stored in one of the minimal symbol tables.     Eventually, all global symbols might be resolved in this way.  */    if (namespace == VAR_NAMESPACE)    {      msymbol = lookup_minimal_symbol (name, NULL, NULL);      if (msymbol != NULL)	{	  s = find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol));	  if (s != NULL)	    {	      /* This is a function which has a symtab for its address.  */	      bv = BLOCKVECTOR (s);	      block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);	      sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),					 namespace);              /* We kept static functions in minimal symbol table as well as		 in static scope. We want to find them in the symbol table. */		if (!sym) {		  block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);		  sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),					     namespace);		}	      /* sym == 0 if symbol was found in the minimal symbol table		 but not in the symtab.		 Return 0 to use the msymbol definition of "foo_".		 This happens for Fortran  "foo_" symbols,		 which are "foo" in the symtab.		 This can also happen if "asm" is used to make a		 regular symbol but not a debugging symbol, e.g.		 asm(".globl _main");		 asm("_main:");		 */	      if (symtab != NULL)		*symtab = s;	      return sym;	    }	  else if (MSYMBOL_TYPE (msymbol) != mst_text		   && MSYMBOL_TYPE (msymbol) != mst_file_text		   && !STREQ (name, SYMBOL_NAME (msymbol)))	    {	      /* This is a mangled variable, look it up by its		 mangled name.  */	      return lookup_symbol (SYMBOL_NAME (msymbol), block,				    namespace, is_a_field_of_this, symtab);	    }	  /* There are no debug symbols for this file, or we are looking	     for an unmangled variable.	     Try to find a matching static symbol below. */	}    }        ALL_PSYMTABS (objfile, ps)    {      if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))	{	  s = PSYMTAB_TO_SYMTAB(ps);	  bv = BLOCKVECTOR (s);	  block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);	  sym = lookup_block_symbol (block, name, namespace);	  if (!sym)	    error ("Internal: global symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);	  if (symtab != NULL)	    *symtab = s;	  return sym;	}    }  /* Now search all per-file blocks.     Not strictly correct, but more useful than an error.     Do the symtabs first, then check the psymtabs */  ALL_SYMTABS (objfile, s)    {      bv = BLOCKVECTOR (s);      block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);      sym = lookup_block_symbol (block, name, namespace);      if (sym) 	{	  block_found = block;	  if (symtab != NULL)	    *symtab = s;	  return sym;	}    }  ALL_PSYMTABS (objfile, ps)    {      if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))	{	  s = PSYMTAB_TO_SYMTAB(ps);	  bv = BLOCKVECTOR (s);	  block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);	  sym = lookup_block_symbol (block, name, namespace);	  if (!sym)	    error ("Internal: static symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);	  if (symtab != NULL)	    *symtab = s;	  return sym;	}    }  if (symtab != NULL)    *symtab = NULL;  return 0;}/* Look, in partial_symtab PST, for symbol NAME.  Check the global   symbols if GLOBAL, the static symbols if not */static struct partial_symbol *lookup_partial_symbol (pst, name, global, namespace)     struct partial_symtab *pst;     const char *name;     int global;     namespace_enum namespace;{  struct partial_symbol **start, **psym;  struct partial_symbol **top, **bottom, **center;  int length = (global ? pst->n_global_syms : pst->n_static_syms);  int do_linear_search = 1;  if (length == 0)    {      return (NULL);    }    start = (global ?	   pst->objfile->global_psymbols.list + pst->globals_offset :	   pst->objfile->static_psymbols.list + pst->statics_offset  );  if (global)		/* This means we can use a binary search. */    {      do_linear_search = 0;      /* Binary search.  This search is guaranteed to end with center         pointing at the earliest partial symbol with the correct	 name.  At that point *all* partial symbols with that name	 will be checked against the correct namespace. */      bottom = start;      top = start + length - 1;      while (top > bottom)	{	  center = bottom + (top - bottom) / 2;	  if (!(center < top))	    abort ();	  if (!do_linear_search && SYMBOL_LANGUAGE (*center) == language_cplus)	    {	      do_linear_search = 1;	    }	  if (STRCMP (SYMBOL_NAME (*center), name) >= 0)	    {	      top = center;	    }	  else	    {	      bottom = center + 1;	    }	}      if (!(top == bottom))	abort ();      while (STREQ (SYMBOL_NAME (*top), name))	{	  if (SYMBOL_NAMESPACE (*top) == namespace)	    {	      return (*top);	    }	  top ++;	}    }  /* Can't use a binary search or else we found during the binary search that     we should also do a linear search. */  if (do_linear_search)    {      for (psym = start; psym < start + length; psym++)	{	  if (namespace == SYMBOL_NAMESPACE (*psym))	    {	      if (SYMBOL_MATCHES_NAME (*psym, name))		{		  return (*psym);		}	    }	}    }  return (NULL);}/* Find the psymtab containing main(). *//* FIXME:  What about languages without main() or specially linked   executables that have no main() ? */struct partial_symtab *find_main_psymtab (){  register struct partial_symtab *pst;  register struct objfile *objfile;  ALL_PSYMTABS (objfile, pst)    {      if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE))	{	  return (pst);	}    }  return (NULL);}/* Search BLOCK for symbol NAME in NAMESPACE.   Note that if NAME is the demangled form of a C++ symbol, we will fail   to find a match during the binary search of the non-encoded names, but   for now we don't worry about the slight inefficiency of looking for   a match we'll never find, since it will go pretty quick.  Once the   binary search terminates, we drop through and do a straight linear   search on the symbols.  Each symbol which is marked as being a C++   symbol (language_cplus set) has both the encoded and non-encoded names   tested for a match. */struct symbol *lookup_block_symbol (block, name, namespace)     register const struct block *block;     const char *name;     const namespace_enum namespace;{  register int bot, top, inc;  register struct symbol *sym;  register struct symbol *sym_found = NULL;  register int do_linear_search = 1;  /* If the blocks's symbols were sorted, start with a binary search.  */  if (BLOCK_SHOULD_SORT (block))    {      /* Reset the linear search flag so if the binary search fails, we	 won't do the linear search once unless we find some reason to	 do so, such as finding a C++ symbol during the binary search.	 Note that for C++ modules, ALL the symbols in a block should	 end up marked as C++ symbols. */      do_linear_search = 0;      top = BLOCK_NSYMS (block);      bot = 0;      /* Advance BOT to not far before the first symbol whose name is NAME. */      while (1)	{	  inc = (top - bot + 1);	  /* No need to keep binary searching for the last few bits worth.  */	  if (inc < 4)	    {	      break;	    }	  inc = (inc >> 1) + bot;	  sym = BLOCK_SYM (block, inc);	  if (!do_linear_search && SYMBOL_LANGUAGE (sym) == language_cplus)	    {	      do_linear_search = 1;	    }	  if (SYMBOL_NAME (sym)[0] < name[0])	    {	      bot = inc;	    }	  else if (SYMBOL_NAME (sym)[0] > name[0])	    {	      top = inc;	    }	  else if (STRCMP (SYMBOL_NAME (sym), name) < 0)	    {	      bot = inc;	    }	  else	    {	      top = inc;	    }	}      /* Now scan forward until we run out of symbols, find one whose	 name is greater than NAME, or find one we want.  If there is	 more than one symbol with the right name and namespace, we	 return the first one; I believe it is now impossible for us	 to encounter two symbols with the same name and namespace	 here, because blocks containing argument symbols are no	 longer sorted.  */      top = BLOCK_NSYMS (block);      while (bot < top)	{	  sym = BLOCK_SYM (block, bot);	  inc = SYMBOL_NAME (sym)[0] - name[0];	  if (inc == 0)	    {	      inc = STRCMP (SYMBOL_NAME (sym), name);	    }	  if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)	    {	      return (sym);	    }	  if (inc > 0)	    {	      break;	    }	  bot++;	}    }  /* Here if block isn't sorted, or we fail to find a match during the     binary search above.  If during the binary search above, we find a     symbol which is a C++ symbol, then we have re-enabled the linear     search flag which was reset when starting the binary search.     This loop is equivalent to the loop above, but hacked greatly for speed.     Note that parameter symbols do not always show up last in the     list; this loop makes sure to take anything else other than     parameter symbols first; it only uses parameter symbols as a     last resort.  Note that this only takes up extra computation     time on a match.  */  if (do_linear_search)    {      top = BLOCK_NSYMS (block);      bot = 0;      while (bot < top)	{	  sym = BLOCK_SYM (block, bot);	  if (SYMBOL_NAMESPACE (sym) == namespace &&	      SYMBOL_MATCHES_NAME (sym, name))	    {	      sym_found = sym;	      if (SYMBOL_CLASS (sym) != LOC_ARG &&		  SYMBOL_CLASS (sym) != LOC_LOCAL_ARG &&		  SYMBOL_CLASS (sym) != LOC_REF_ARG &&		  SYMBOL_CLASS (sym) != LOC_REGPARM &&		  SYMBOL_CLASS (sym) != LOC_REGPARM_ADDR &&		  SYMBOL_CLASS (sym) != LOC_BASEREG_ARG)		{		  break;		}	    }	  bot++;	}    }  return (sym_found);		/* Will be NULL if not found. */}/* Return the symbol for the function which contains a specified   lexical block, described by a struct block BL.  */struct symbol *block_function (bl)     struct block *bl;{  while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)    bl = BLOCK_SUPERBLOCK (bl);  return BLOCK_FUNCTION (bl);}/* Find the symtab associated with PC.  Look through the psymtabs and read in   another symtab if necessary. */struct symtab *find_pc_symtab (pc)     register CORE_ADDR pc;{  register struct block *b;  struct blockvector *bv;  register struct symtab *s = NULL;  register struct symtab *best_s = NULL;  register struct partial_symtab *ps;  register struct objfile *objfile;  int distance = 0;  /* Search all symtabs for the one whose file contains our address, and which     is the smallest of all the ones containing the address.  This is designed     to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000     and symtab b is at 0x2000-0x3000.  So the GLOBAL_BLOCK for a is from     0x1000-0x4000, but for address 0x2345 we want to return symtab b.     This happens for native ecoff format, where code from included files     gets its own symtab. The symtab for the included file should have     been read in already via the dependency mechanism.     It might be swifter to create several symtabs with the same name     like xcoff does (I'm not sure).     It also happens for objfiles that have their functions reordered.     For these, the symtab we are looking for is not necessarily read in.  */  ALL_SYMTABS (objfile, s)    {      bv = BLOCKVECTOR (s);      b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);      if (BLOCK_START (b) <= pc	  && BLOCK_END (b) > pc	  && (distance == 0	      || BLOCK_END (b) - BLOCK_START (b) < distance))	{	  /* For an objfile that has its functions reordered,	     find_pc_psymtab will find the proper partial symbol table	     and we simply return its corresponding symtab.  */	  if ((objfile->flags & OBJF_REORDERED) && objfile->psymtabs)	    {	      ps = find_pc_psymtab (pc);	      if (ps)		s = PSYMTAB_TO_SYMTAB (ps);	      else	        s = NULL;	      return (s);	    }	  distance = BLOCK_END (b) - BLOCK_START (b);	  best_s = s;	}    }  if (best_s != NULL)    return(best_s);  s = NULL;  ps = find_pc_psymtab (pc);  if (ps)    {      if (ps->readin)	/* Might want to error() here (in case symtab is corrupt and	   will cause a core dump), but maybe we can successfully	   continue, so let's not.  */	/* FIXME-32x64: assumes pc fits in a long */	warning ("\(Internal error: pc 0x%lx in read in psymtab, but not in symtab.)\n",	         (unsigned long) pc);      s = PSYMTAB_TO_SYMTAB (ps);    }  return (s);}#if 0/* Find the closest symbol value (of any sort -- function or variable)   for a given address value.  Slow but complete.  (currently unused,   mainly because it is too slow.  We could fix it if each symtab and   psymtab had contained in it the addresses ranges of each of its   sections, which also would be required to make things like "info   line *0x2345" cause psymtabs to be converted to symtabs).  */struct symbol *find_addr_symbol (addr, symtabp, symaddrp)     CORE_ADDR addr;     struct symtab **symtabp;     CORE_ADDR *symaddrp;{  struct symtab *symtab, *best_symtab;  struct objfile *objfile;  register int bot, top;  register struct symbol *sym;  register CORE_ADDR sym_addr;  struct block *block;  int blocknum;  /* Info on best symbol seen so far */  register CORE_ADDR best_sym_addr = 0;  struct symbol *best_sym = 0;  /* FIXME -- we should pull in all the psymtabs, too!  */  ALL_SYMTABS (objfile, symtab)    {      /* Search the global and static blocks in this symtab for	 the closest symbol-address to the desired address.  */      for (blocknum = GLOBAL_BLOCK; blocknum <= STATIC_BLOCK; blocknum++)	{	  QUIT;	  block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), blocknum);	  top = BLOCK_NSYMS (block);	  for (bot = 0; bot < top; bot++)	    {	      sym = BLOCK_SYM (block, bot);	      switch (SYMBOL_CLASS (sym))		{		case LOC_STATIC:			case LOC_LABEL:			  sym_addr = SYMBOL_VALUE_ADDRESS (sym);		  break;		case LOC_BLOCK:		  sym_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));		  break;		default:		  continue;		}		if (sym_addr <= addr)		  if (sym_addr > best_sym_addr)		    {		      /* Quit if we found an exact match.  */		      best_sym = sym;		      best_sym_addr = sym_addr;		      best_symtab = symtab;		      if (sym_addr == addr)			goto done;		    }	    }	}    } done:  if (symtabp)    *symtabp = best_symtab;  if (symaddrp)    *symaddrp = best_sym_addr;  return best_sym;}#endif /* 0 *//* Find the source file and line number for a given PC value.   Return a structure containing a symtab pointer, a line number,   and a pc range for the entire source line.   The value's .pc field is NOT the specified pc.   NOTCURRENT nonzero means, if specified pc is on a line boundary,   use the line that ends there.  Otherwise, in that case, the line   that begins there is used.  *//* The big complication here is that a line may start in one file, and end just   before the start of another file.  This usually occurs when you #include   code in the middle of a subroutine.  To properly find the end of a line's PC   range, we must search all symtabs associated with this compilation unit, and   find the one whose first PC is closer than that of the next line in this   symtab.  *//* If it's worth the effort, we could be using a binary search.  */struct symtab_and_linefind_pc_line (pc, notcurrent)     CORE_ADDR pc;     int notcurrent;{  struct symtab *s;  register struct linetable *l;  register int len;  register int i;  register struct linetable_entry *item;  struct symtab_and_line val;  struct blockvector *bv;  /* Info on best line seen so far, and where it starts, and its file.  */  struct linetable_entry *best = NULL;  CORE_ADDR best_end = 0;  struct symtab *best_symtab = 0;  /* Store here the first line number     of a file which contains the line at the smallest pc after PC.     If we don't find a line whose range contains PC,     we will use a line one less than this,     with a range from the start of that file to the first line's pc.  */  struct linetable_entry *alt = NULL;  struct symtab *alt_symtab = 0;  /* Info on best line seen in this file.  */  struct linetable_entry *prev;  /* If this pc is not from the current frame,     it is the address of the end of a call instruction.     Quite likely that is the start of the following statement.     But what we want is the statement containing the instruction.     Fudge the pc to make sure we get that.  */  if (notcurrent) pc -= 1;  s = find_pc_symtab (pc);  if (!s)    {      val.symtab = 0;      val.line = 0;      val.pc = pc;      val.end = 0;      return val;    }  bv = BLOCKVECTOR (s);  /* Look at all the symtabs that share this blockvector.     They all have the same apriori range, that we found was right;     but they have different line tables.  */  for (; s && BLOCKVECTOR (s) == bv; s = s->next)    {      /* Find the best line in this symtab.  */      l = LINETABLE (s);      if (!l)        continue;      len = l->nitems;      if (len <= 0)	{	  /* I think len can be zero if the symtab lacks line numbers	     (e.g. gcc -g1).  (Either that or the LINETABLE is NULL;	     I'm not sure which, and maybe it depends on the symbol	     reader).  */	  continue;	}      prev = NULL;      item = l->item;		/* Get first line info */      /* Is this file's first line closer than the first lines of other files?	 If so, record this file, and its first line, as best alternate.  */      if (item->pc > pc && (!alt || item->pc < alt->pc))	{	  alt = item;	  alt_symtab = s;	}      for (i = 0; i < len; i++, item++)	{	  /* Leave prev pointing to the linetable entry for the last line	     that started at or before PC.  */	  if (item->pc > pc)	    break;	  prev = item;	}      /* At this point, prev points at the line whose start addr is <= pc, and	 item points at the next line.  If we ran off the end of the linetable	 (pc >= start of the last line), then prev == item.  If pc < start of	 the first line, prev will not be set.  */      /* Is this file's best line closer than the best in the other files?	 If so, record this file, and its best line, as best so far.  */      if (prev && (!best || prev->pc > best->pc))	{	  best = prev;	  best_symtab = s;	  /* If another line is in the linetable, and its PC is closer	     than the best_end we currently have, take it as best_end.  */	  if (i < len && (best_end == 0 || best_end > item->pc))	    best_end = item->pc;	}    }  if (!best_symtab)    {      if (!alt_symtab)	{			/* If we didn't find any line # info, just				 return zeros.  */	  val.symtab = 0;	  val.line = 0;	  val.pc = pc;	  val.end = 0;	}      else	{	  val.symtab = alt_symtab;	  val.line = alt->line - 1;	  /* Don't return line 0, that means that we didn't find the line.  */	  if (val.line == 0) ++val.line;	  val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));	  val.end = alt->pc;	}    }  else    {      val.symtab = best_symtab;      val.line = best->line;      val.pc = best->pc;      if (best_end && (!alt || best_end < alt->pc))	val.end = best_end;      else if (alt)	val.end = alt->pc;      else	val.end = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));    }  return val;}static int find_line_symtab PARAMS ((struct symtab *, int, struct linetable **,				     int *, int *));/* Find line number LINE in any symtab whose name is the same as   SYMTAB.   If found, return 1, set *LINETABLE to the linetable in which it was   found, set *INDEX to the index in the linetable of the best entry   found, and set *EXACT_MATCH nonzero if the value returned is an   exact match.   If not found, return 0.  */static intfind_line_symtab (symtab, line, linetable, index, exact_match)     struct symtab *symtab;     int line;     struct linetable **linetable;     int *index;     int *exact_match;{  int exact;  /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE     so far seen.  */  int best_index;  struct linetable *best_linetable;  /* First try looking it up in the given symtab.  */  best_linetable = LINETABLE (symtab);  best_index = find_line_common (best_linetable, line, &exact);  if (best_index < 0 || !exact)    {      /* Didn't find an exact match.  So we better keep looking for	 another symtab with the same name.  In the case of xcoff,	 multiple csects for one source file (produced by IBM's FORTRAN	 compiler) produce multiple symtabs (this is unavoidable	 assuming csects can be at arbitrary places in memory and that	 the GLOBAL_BLOCK of a symtab has a begin and end address).  */      /* BEST is the smallest linenumber > LINE so far seen,	 or 0 if none has been seen so far.	 BEST_INDEX and BEST_LINETABLE identify the item for it.  */      int best;      struct objfile *objfile;      struct symtab *s;      if (best_index >= 0)	best = best_linetable->item[best_index].line;      else	best = 0;      ALL_SYMTABS (objfile, s)	{	  struct linetable *l;	  int ind;	  if (!STREQ (symtab->filename, s->filename))	    continue;	  l = LINETABLE (s);	  ind = find_line_common (l, line, &exact);	  if (ind >= 0)	    {	      if (exact)		{		  best_index = ind;		  best_linetable = l;		  goto done;		}	      if (best == 0 || l->item[ind].line < best)		{		  best = l->item[ind].line;		  best_index = ind;		  best_linetable = l;		}	    }	}    } done:  if (best_index < 0)    return 0;  if (index)    *index = best_index;  if (linetable)    *linetable = best_linetable;  if (exact_match)    *exact_match = exact;  return 1;}/* Find the PC value for a given source file and line number.   Returns zero for invalid line number.   The source file is specified with a struct symtab.  */CORE_ADDRfind_line_pc (symtab, line)     struct symtab *symtab;     int line;{  struct linetable *l;  int ind;  if (symtab == 0)    return 0;  if (find_line_symtab (symtab, line, &l, &ind, NULL))    return l->item[ind].pc;  else    return 0;}/* Find the range of pc values in a line.   Store the starting pc of the line into *STARTPTR   and the ending pc (start of next line) into *ENDPTR.   Returns 1 to indicate success.   Returns 0 if could not find the specified line.  */intfind_line_pc_range (sal, startptr, endptr)     struct symtab_and_line sal;     CORE_ADDR *startptr, *endptr;{  CORE_ADDR startaddr;  struct symtab_and_line found_sal;  startaddr = sal.pc;  if (startaddr == 0)    {      startaddr = find_line_pc (sal.symtab, sal.line);    }  if (startaddr == 0)    return 0;  /* This whole function is based on address.  For example, if line 10 has     two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then     "info line *0x123" should say the line goes from 0x100 to 0x200     and "info line *0x355" should say the line goes from 0x300 to 0x400.     This also insures that we never give a range like "starts at 0x134     and ends at 0x12c".  */  found_sal = find_pc_line (startaddr, 0);  if (found_sal.line != sal.line)    {      /* The specified line (sal) has zero bytes.  */      *startptr = found_sal.pc;      *endptr = found_sal.pc;    }  else    {      *startptr = found_sal.pc;      *endptr = found_sal.end;    }  return 1;}/* Given a line table and a line number, return the index into the line   table for the pc of the nearest line whose number is >= the specified one.   Return -1 if none is found.  The value is >= 0 if it is an index.   Set *EXACT_MATCH nonzero if the value returned is an exact match.  */static intfind_line_common (l, lineno, exact_match)     register struct linetable *l;     register int lineno;     int *exact_match;{  register int i;  register int len;  /* BEST is the smallest linenumber > LINENO so far seen,     or 0 if none has been seen so far.     BEST_INDEX identifies the item for it.  */  int best_index = -1;  int best = 0;  if (lineno <= 0)    return -1;  if (l == 0)    return -1;  len = l->nitems;  for (i = 0; i < len; i++)    {      register struct linetable_entry *item = &(l->item[i]);      if (item->line == lineno)	{	  /* Return the first (lowest address) entry which matches.  */	  *exact_match = 1;	  return i;	}      if (item->line > lineno && (best == 0 || item->line < best))	{	  best = item->line;	  best_index = i;	}    }  /* If we got here, we didn't get an exact match.  */  *exact_match = 0;  return best_index;}intfind_pc_line_pc_range (pc, startptr, endptr)     CORE_ADDR pc;     CORE_ADDR *startptr, *endptr;{  struct symtab_and_line sal;  sal = find_pc_line (pc, 0);  *startptr = sal.pc;  *endptr = sal.end;  return sal.symtab != 0;}/* Given a function symbol SYM, find the symtab and line for the start   of the function.   If the argument FUNFIRSTLINE is nonzero, we want the first line   of real code inside the function.  */static struct symtab_and_linefind_function_start_sal PARAMS ((struct symbol *sym, int));static struct symtab_and_linefind_function_start_sal (sym, funfirstline)     struct symbol *sym;     int funfirstline;{  CORE_ADDR pc;  struct symtab_and_line sal;  pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));  if (funfirstline)    {      pc += FUNCTION_START_OFFSET;      SKIP_PROLOGUE (pc);    }  sal = find_pc_line (pc, 0);#ifdef PROLOGUE_FIRSTLINE_OVERLAP  /* Convex: no need to suppress code on first line, if any */  sal.pc = pc;#else  /* Check if SKIP_PROLOGUE left us in mid-line, and the next     line is still part of the same function.  */  if (sal.pc != pc      && BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) <= sal.end      && sal.end < BLOCK_END (SYMBOL_BLOCK_VALUE (sym)))    {      /* First pc of next line */      pc = sal.end;      /* Recalculate the line number (might not be N+1).  */      sal = find_pc_line (pc, 0);    }  sal.pc = pc;#endif  return sal;}/* If P is of the form "operator[ \t]+..." where `...' is   some legitimate operator text, return a pointer to the   beginning of the substring of the operator text.   Otherwise, return "".  */char *operator_chars (p, end)     char *p;     char **end;{  *end = "";  if (strncmp (p, "operator", 8))    return *end;  p += 8;  /* Don't get faked out by `operator' being part of a longer     identifier.  */  if (isalpha(*p) || *p == '_' || *p == '$' || *p == '\0')    return *end;  /* Allow some whitespace between `operator' and the operator symbol.  */  while (*p == ' ' || *p == '\t')    p++;  /* Recognize 'operator TYPENAME'. */  if (isalpha(*p) || *p == '_' || *p == '$')    {      register char *q = p+1;      while (isalnum(*q) || *q == '_' || *q == '$')	q++;      *end = q;      return p;    }  switch (*p)    {    case '!':    case '=':    case '*':    case '/':    case '%':    case '^':      if (p[1] == '=')	*end = p+2;      else	*end = p+1;      return p;    case '<':    case '>':    case '+':    case '-':    case '&':    case '|':      if (p[1] == '=' || p[1] == p[0])	*end = p+2;      else	*end = p+1;      return p;    case '~':    case ',':      *end = p+1;      return p;    case '(':      if (p[1] != ')')	error ("`operator ()' must be specified without whitespace in `()'");      *end = p+2;      return p;    case '?':      if (p[1] != ':')	error ("`operator ?:' must be specified without whitespace in `?:'");      *end = p+2;      return p;    case '[':      if (p[1] != ']')	error ("`operator []' must be specified without whitespace in `[]'");      *end = p+2;      return p;    default:      error ("`operator %s' not supported", p);      break;    }  *end = "";  return *end;}