Mon Jan 12 11:46:51 1998 Michael Snyder (msnyder@cleaver.cygnus.com)
[external/binutils.git] / gdb / symtab.c
1 /* Symbol table lookup for the GNU debugger, GDB.
2    Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 1997
3              Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20
21 #include "defs.h"
22 #include "symtab.h"
23 #include "gdbtypes.h"
24 #include "gdbcore.h"
25 #include "frame.h"
26 #include "target.h"
27 #include "value.h"
28 #include "symfile.h"
29 #include "objfiles.h"
30 #include "gdbcmd.h"
31 #include "call-cmds.h"
32 #include "gnu-regex.h"
33 #include "expression.h"
34 #include "language.h"
35 #include "demangle.h"
36 #include "inferior.h"
37
38 #include "obstack.h"
39
40 #include <sys/types.h>
41 #include <fcntl.h>
42 #include "gdb_string.h"
43 #include "gdb_stat.h"
44 #include <ctype.h>
45
46 /* Prototypes for local functions */
47
48 extern int
49 find_methods PARAMS ((struct type *, char *, struct symbol **));
50
51 static void
52 completion_list_add_name PARAMS ((char *, char *, int, char *, char *));
53
54 static void
55 build_canonical_line_spec PARAMS ((struct symtab_and_line *, char *, char ***));
56
57 static struct symtabs_and_lines
58 decode_line_2 PARAMS ((struct symbol *[], int, int, char ***));
59
60 static void
61 rbreak_command PARAMS ((char *, int));
62
63 static void
64 types_info PARAMS ((char *, int));
65
66 static void
67 functions_info PARAMS ((char *, int));
68
69 static void
70 variables_info PARAMS ((char *, int));
71
72 static void
73 sources_info PARAMS ((char *, int));
74
75 static void
76 list_symbols PARAMS ((char *, int, int, int));
77
78 static void
79 output_source_filename PARAMS ((char *, int *));
80
81 char *
82 operator_chars PARAMS ((char *, char **));
83
84 static int find_line_common PARAMS ((struct linetable *, int, int *));
85
86 static struct partial_symbol *
87 lookup_partial_symbol PARAMS ((struct partial_symtab *, const char *,
88                                int, namespace_enum));
89
90 static struct symtab *
91 lookup_symtab_1 PARAMS ((char *));
92
93 static void
94 cplusplus_hint PARAMS ((char *));
95
96 static struct symbol *
97 find_active_alias PARAMS ((struct symbol *sym, CORE_ADDR addr));
98
99 /* */
100
101 /* The single non-language-specific builtin type */
102 struct type *builtin_type_error;
103
104 /* Block in which the most recently searched-for symbol was found.
105    Might be better to make this a parameter to lookup_symbol and 
106    value_of_this. */
107
108 const struct block *block_found;
109
110 char no_symtab_msg[] = "No symbol table is loaded.  Use the \"file\" command.";
111
112 /* While the C++ support is still in flux, issue a possibly helpful hint on
113    using the new command completion feature on single quoted demangled C++
114    symbols.  Remove when loose ends are cleaned up.   FIXME -fnf */
115
116 static void
117 cplusplus_hint (name)
118      char *name;
119 {
120   while (*name == '\'')
121     name++;
122   printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name, name);
123   printf_filtered ("(Note leading single quote.)\n");
124 }
125
126 /* Check for a symtab of a specific name; first in symtabs, then in
127    psymtabs.  *If* there is no '/' in the name, a match after a '/'
128    in the symtab filename will also work.  */
129
130 static struct symtab *
131 lookup_symtab_1 (name)
132      char *name;
133 {
134   register struct symtab *s;
135   register struct partial_symtab *ps;
136   register char *slash;
137   register struct objfile *objfile;
138
139  got_symtab:
140
141   /* First, search for an exact match */
142
143   ALL_SYMTABS (objfile, s)
144     if (STREQ (name, s->filename))
145       return s;
146
147   slash = strchr (name, '/');
148
149   /* Now, search for a matching tail (only if name doesn't have any dirs) */
150
151   if (!slash)
152     ALL_SYMTABS (objfile, s)
153       {
154         char *p = s -> filename;
155         char *tail = strrchr (p, '/');
156
157         if (tail)
158           p = tail + 1;
159
160         if (STREQ (p, name))
161           return s;
162       }
163
164   /* Same search rules as above apply here, but now we look thru the
165      psymtabs.  */
166
167   ps = lookup_partial_symtab (name);
168   if (!ps)
169     return (NULL);
170
171   if (ps -> readin)
172     error ("Internal: readin %s pst for `%s' found when no symtab found.",
173            ps -> filename, name);
174
175   s = PSYMTAB_TO_SYMTAB (ps);
176
177   if (s)
178     return s;
179
180   /* At this point, we have located the psymtab for this file, but
181      the conversion to a symtab has failed.  This usually happens
182      when we are looking up an include file.  In this case,
183      PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
184      been created.  So, we need to run through the symtabs again in
185      order to find the file.
186      XXX - This is a crock, and should be fixed inside of the the
187      symbol parsing routines. */
188   goto got_symtab;
189 }
190
191 /* Lookup the symbol table of a source file named NAME.  Try a couple
192    of variations if the first lookup doesn't work.  */
193
194 struct symtab *
195 lookup_symtab (name)
196      char *name;
197 {
198   register struct symtab *s;
199 #if 0
200   register char *copy;
201 #endif
202
203   s = lookup_symtab_1 (name);
204   if (s) return s;
205
206 #if 0
207   /* This screws c-exp.y:yylex if there is both a type "tree" and a symtab
208      "tree.c".  */
209
210   /* If name not found as specified, see if adding ".c" helps.  */
211   /* Why is this?  Is it just a user convenience?  (If so, it's pretty
212      questionable in the presence of C++, FORTRAN, etc.).  It's not in
213      the GDB manual.  */
214
215   copy = (char *) alloca (strlen (name) + 3);
216   strcpy (copy, name);
217   strcat (copy, ".c");
218   s = lookup_symtab_1 (copy);
219   if (s) return s;
220 #endif /* 0 */
221
222   /* We didn't find anything; die.  */
223   return 0;
224 }
225
226 /* Lookup the partial symbol table of a source file named NAME.
227    *If* there is no '/' in the name, a match after a '/'
228    in the psymtab filename will also work.  */
229
230 struct partial_symtab *
231 lookup_partial_symtab (name)
232 char *name;
233 {
234   register struct partial_symtab *pst;
235   register struct objfile *objfile;
236   
237   ALL_PSYMTABS (objfile, pst)
238     {
239       if (STREQ (name, pst -> filename))
240         {
241           return (pst);
242         }
243     }
244
245   /* Now, search for a matching tail (only if name doesn't have any dirs) */
246
247   if (!strchr (name, '/'))
248     ALL_PSYMTABS (objfile, pst)
249       {
250         char *p = pst -> filename;
251         char *tail = strrchr (p, '/');
252
253         if (tail)
254           p = tail + 1;
255
256         if (STREQ (p, name))
257           return (pst);
258       }
259
260   return (NULL);
261 }
262 \f
263 /* Demangle a GDB method stub type.
264    Note that this function is g++ specific. */
265
266 char *
267 gdb_mangle_name (type, i, j)
268      struct type *type;
269      int i, j;
270 {
271   int mangled_name_len;
272   char *mangled_name;
273   struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
274   struct fn_field *method = &f[j];
275   char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
276   char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
277   char *newname = type_name_no_tag (type);
278
279   /* Does the form of physname indicate that it is the full mangled name
280      of a constructor (not just the args)?  */
281   int is_full_physname_constructor;
282
283   int is_constructor;
284   int is_destructor = DESTRUCTOR_PREFIX_P (physname);
285   /* Need a new type prefix.  */
286   char *const_prefix = method->is_const ? "C" : "";
287   char *volatile_prefix = method->is_volatile ? "V" : "";
288   char buf[20];
289   int len = (newname == NULL ? 0 : strlen (newname));
290
291   is_full_physname_constructor = 
292     ((physname[0]=='_' && physname[1]=='_' && 
293       (isdigit(physname[2]) || physname[2]=='Q' || physname[2]=='t'))
294      || (strncmp(physname, "__ct", 4) == 0));
295
296   is_constructor =
297     is_full_physname_constructor || (newname && STREQ(field_name, newname));
298
299   if (!is_destructor)
300     is_destructor = (strncmp(physname, "__dt", 4) == 0); 
301
302   if (is_destructor || is_full_physname_constructor)
303     {
304       mangled_name = (char*) xmalloc(strlen(physname)+1);
305       strcpy(mangled_name, physname);
306       return mangled_name;
307     }
308
309   if (len == 0)
310     {
311       sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
312     }
313   else if (physname[0] == 't' || physname[0] == 'Q')
314     {
315       /* The physname for template and qualified methods already includes
316          the class name.  */
317       sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
318       newname = NULL;
319       len = 0;
320     }
321   else
322     {
323       sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
324     }
325   mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
326                           + strlen (buf) + len
327                           + strlen (physname)
328                           + 1);
329
330   /* Only needed for GNU-mangled names.  ANSI-mangled names
331      work with the normal mechanisms.  */
332   if (OPNAME_PREFIX_P (field_name))
333     {
334       const char *opname = cplus_mangle_opname (field_name + 3, 0);
335       if (opname == NULL)
336         error ("No mangling for \"%s\"", field_name);
337       mangled_name_len += strlen (opname);
338       mangled_name = (char *)xmalloc (mangled_name_len);
339
340       strncpy (mangled_name, field_name, 3);
341       mangled_name[3] = '\0';
342       strcat (mangled_name, opname);
343     }
344   else
345     {
346       mangled_name = (char *)xmalloc (mangled_name_len);
347       if (is_constructor)
348         mangled_name[0] = '\0';
349       else
350         strcpy (mangled_name, field_name);
351     }
352   strcat (mangled_name, buf);
353   /* If the class doesn't have a name, i.e. newname NULL, then we just
354      mangle it using 0 for the length of the class.  Thus it gets mangled
355      as something starting with `::' rather than `classname::'. */ 
356   if (newname != NULL)
357     strcat (mangled_name, newname);
358
359   strcat (mangled_name, physname);
360   return (mangled_name);
361 }
362
363 \f
364
365 struct partial_symbol * fixup_psymbol_section PARAMS ((struct partial_symbol *,
366                                                        struct objfile *));
367
368
369 /* Find which partial symtab on contains PC and SECTION.  Return 0 if none.  */
370
371 struct partial_symtab *
372 find_pc_sect_psymtab (pc, section)
373      CORE_ADDR pc;
374      asection *section;
375 {
376   register struct partial_symtab *pst;
377   register struct objfile *objfile;
378
379   ALL_PSYMTABS (objfile, pst)
380     {
381       if (pc >= pst->textlow && pc < pst->texthigh)
382         {
383           struct minimal_symbol *msymbol;
384           struct partial_symtab *tpst;
385
386           /* An objfile that has its functions reordered might have
387              many partial symbol tables containing the PC, but
388              we want the partial symbol table that contains the
389              function containing the PC.  */
390           if (!(objfile->flags & OBJF_REORDERED) &&
391               section == 0)     /* can't validate section this way */
392             return (pst);
393
394           msymbol = lookup_minimal_symbol_by_pc_section (pc, section);
395           if (msymbol == NULL)
396             return (pst);
397
398           for (tpst = pst; tpst != NULL; tpst = tpst->next)
399             {
400               if (pc >= tpst->textlow && pc < tpst->texthigh)
401                 {
402                   struct partial_symbol *p;
403
404                   p = find_pc_sect_psymbol (tpst, pc, section);
405                   if (p != NULL
406                       && SYMBOL_VALUE_ADDRESS(p)
407                          == SYMBOL_VALUE_ADDRESS (msymbol))
408                     return (tpst);
409                 }
410             }
411           return (pst);
412         }
413     }
414   return (NULL);
415 }
416
417 /* Find which partial symtab contains PC.  Return 0 if none. 
418    Backward compatibility, no section */
419
420 struct partial_symtab *
421 find_pc_psymtab (pc)
422      CORE_ADDR pc;
423 {
424   return find_pc_sect_psymtab (pc, find_pc_mapped_section (pc));
425 }
426
427 /* Find which partial symbol within a psymtab matches PC and SECTION.  
428    Return 0 if none.  Check all psymtabs if PSYMTAB is 0.  */
429
430 struct partial_symbol *
431 find_pc_sect_psymbol (psymtab, pc, section)
432      struct partial_symtab *psymtab;
433      CORE_ADDR pc;
434      asection *section;
435 {
436   struct partial_symbol *best = NULL, *p, **pp;
437   CORE_ADDR best_pc;
438   
439   if (!psymtab)
440     psymtab = find_pc_sect_psymtab (pc, section);
441   if (!psymtab)
442     return 0;
443
444   best_pc = psymtab->textlow - 1;
445
446   /* Search the global symbols as well as the static symbols, so that
447      find_pc_partial_function doesn't use a minimal symbol and thus
448      cache a bad endaddr.  */
449   for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
450        (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
451         < psymtab->n_global_syms);
452        pp++)
453     {
454       p = *pp;
455       if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
456           && SYMBOL_CLASS (p) == LOC_BLOCK
457           && pc >= SYMBOL_VALUE_ADDRESS (p)
458           && SYMBOL_VALUE_ADDRESS (p) > best_pc)
459         {
460           if (section)  /* match on a specific section */
461             {
462               fixup_psymbol_section (p, psymtab->objfile);
463               if (SYMBOL_BFD_SECTION (p) != section)
464                 continue;
465             }
466           best_pc = SYMBOL_VALUE_ADDRESS (p);
467           best = p;
468         }
469     }
470   for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
471        (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
472         < psymtab->n_static_syms);
473        pp++)
474     {
475       p = *pp;
476       if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
477           && SYMBOL_CLASS (p) == LOC_BLOCK
478           && pc >= SYMBOL_VALUE_ADDRESS (p)
479           && SYMBOL_VALUE_ADDRESS (p) > best_pc)
480         {
481           if (section)  /* match on a specific section */
482             {
483               fixup_psymbol_section (p, psymtab->objfile);
484               if (SYMBOL_BFD_SECTION (p) != section)
485                 continue;
486             }
487           best_pc = SYMBOL_VALUE_ADDRESS (p);
488           best = p;
489         }
490     }
491   if (best_pc == psymtab->textlow - 1)
492     return 0;
493   return best;
494 }
495
496 /* Find which partial symbol within a psymtab matches PC.  Return 0 if none.  
497    Check all psymtabs if PSYMTAB is 0.  Backwards compatibility, no section. */
498
499 struct partial_symbol *
500 find_pc_psymbol (psymtab, pc)
501      struct partial_symtab *psymtab;
502      CORE_ADDR pc;
503 {
504   return find_pc_sect_psymbol (psymtab, pc, find_pc_mapped_section (pc));
505 }
506 \f
507 /* Debug symbols usually don't have section information.  We need to dig that
508    out of the minimal symbols and stash that in the debug symbol.  */
509
510 static void
511 fixup_section (ginfo, objfile)
512      struct general_symbol_info *ginfo;
513      struct objfile *objfile;
514 {
515   struct minimal_symbol *msym;
516   msym = lookup_minimal_symbol (ginfo->name, NULL, objfile);
517
518   if (msym)
519     ginfo->bfd_section = SYMBOL_BFD_SECTION (msym);
520 }
521
522 struct symbol *
523 fixup_symbol_section (sym, objfile)
524      struct symbol *sym;
525      struct objfile *objfile;
526 {
527   if (!sym)
528     return NULL;
529
530   if (SYMBOL_BFD_SECTION (sym))
531     return sym;
532
533   fixup_section (&sym->ginfo, objfile);
534
535   return sym;
536 }
537
538 struct partial_symbol *
539 fixup_psymbol_section (psym, objfile)
540      struct partial_symbol *psym;
541      struct objfile *objfile;
542 {
543   if (!psym)
544     return NULL;
545
546   if (SYMBOL_BFD_SECTION (psym))
547     return psym;
548
549   fixup_section (&psym->ginfo, objfile);
550
551   return psym;
552 }
553
554 /* Find the definition for a specified symbol name NAME
555    in namespace NAMESPACE, visible from lexical block BLOCK.
556    Returns the struct symbol pointer, or zero if no symbol is found.
557    If SYMTAB is non-NULL, store the symbol table in which the
558    symbol was found there, or NULL if not found.
559    C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
560    NAME is a field of the current implied argument `this'.  If so set
561    *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero. 
562    BLOCK_FOUND is set to the block in which NAME is found (in the case of
563    a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
564
565 /* This function has a bunch of loops in it and it would seem to be
566    attractive to put in some QUIT's (though I'm not really sure
567    whether it can run long enough to be really important).  But there
568    are a few calls for which it would appear to be bad news to quit
569    out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and
570    nindy_frame_chain_valid in nindy-tdep.c.  (Note that there is C++
571    code below which can error(), but that probably doesn't affect
572    these calls since they are looking for a known variable and thus
573    can probably assume it will never hit the C++ code).  */
574
575 struct symbol *
576 lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
577      const char *name;
578      register const struct block *block;
579      const namespace_enum namespace;
580      int *is_a_field_of_this;
581      struct symtab **symtab;
582 {
583   register struct symbol *sym;
584   register struct symtab *s = NULL;
585   register struct partial_symtab *ps;
586   struct blockvector *bv;
587   register struct objfile *objfile = NULL;
588   register struct block *b;
589   register struct minimal_symbol *msymbol;
590
591   /* Search specified block and its superiors.  */
592
593   while (block != 0)
594     {
595       sym = lookup_block_symbol (block, name, namespace);
596       if (sym) 
597         {
598           block_found = block;
599           if (symtab != NULL)
600             {
601               /* Search the list of symtabs for one which contains the
602                  address of the start of this block.  */
603               ALL_SYMTABS (objfile, s)
604                 {
605                   bv = BLOCKVECTOR (s);
606                   b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
607                   if (BLOCK_START (b) <= BLOCK_START (block)
608                       && BLOCK_END (b) > BLOCK_START (block))
609                     goto found;
610                 }
611 found:
612               *symtab = s;
613             }
614
615           return fixup_symbol_section (sym, objfile);
616         }
617       block = BLOCK_SUPERBLOCK (block);
618     }
619
620   /* FIXME: this code is never executed--block is always NULL at this
621      point.  What is it trying to do, anyway?  We already should have
622      checked the STATIC_BLOCK above (it is the superblock of top-level
623      blocks).  Why is VAR_NAMESPACE special-cased?  */
624   /* Don't need to mess with the psymtabs; if we have a block,
625      that file is read in.  If we don't, then we deal later with
626      all the psymtab stuff that needs checking.  */
627   if (namespace == VAR_NAMESPACE && block != NULL)
628     {
629       struct block *b;
630       /* Find the right symtab.  */
631       ALL_SYMTABS (objfile, s)
632         {
633           bv = BLOCKVECTOR (s);
634           b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
635           if (BLOCK_START (b) <= BLOCK_START (block)
636               && BLOCK_END (b) > BLOCK_START (block))
637             {
638               sym = lookup_block_symbol (b, name, VAR_NAMESPACE);
639               if (sym)
640                 {
641                   block_found = b;
642                   if (symtab != NULL)
643                     *symtab = s;
644                   return fixup_symbol_section (sym, objfile);
645                 }
646             }
647         }
648     }
649
650
651   /* C++: If requested to do so by the caller, 
652      check to see if NAME is a field of `this'. */
653   if (is_a_field_of_this)
654     {
655       struct value *v = value_of_this (0);
656       
657       *is_a_field_of_this = 0;
658       if (v && check_field (v, name))
659         {
660           *is_a_field_of_this = 1;
661           if (symtab != NULL)
662             *symtab = NULL;
663           return NULL;
664         }
665     }
666
667   /* Now search all global blocks.  Do the symtab's first, then
668      check the psymtab's */
669   
670   ALL_SYMTABS (objfile, s)
671     {
672       bv = BLOCKVECTOR (s);
673       block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
674       sym = lookup_block_symbol (block, name, namespace);
675       if (sym) 
676         {
677           block_found = block;
678           if (symtab != NULL)
679             *symtab = s;
680           return fixup_symbol_section (sym, objfile);
681         }
682     }
683
684   /* Check for the possibility of the symbol being a function or
685      a mangled variable that is stored in one of the minimal symbol tables.
686      Eventually, all global symbols might be resolved in this way.  */
687   
688   if (namespace == VAR_NAMESPACE)
689     {
690       msymbol = lookup_minimal_symbol (name, NULL, NULL);
691       if (msymbol != NULL)
692         {
693           s = find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol),
694                                   SYMBOL_BFD_SECTION (msymbol));
695           if (s != NULL)
696             {
697               /* This is a function which has a symtab for its address.  */
698               bv = BLOCKVECTOR (s);
699               block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
700               sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
701                                          namespace);
702               /* We kept static functions in minimal symbol table as well as
703                  in static scope. We want to find them in the symbol table. */
704                 if (!sym) {
705                   block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
706                   sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
707                                              namespace);
708                 }
709
710               /* sym == 0 if symbol was found in the minimal symbol table
711                  but not in the symtab.
712                  Return 0 to use the msymbol definition of "foo_".
713
714                  This happens for Fortran  "foo_" symbols,
715                  which are "foo" in the symtab.
716
717                  This can also happen if "asm" is used to make a
718                  regular symbol but not a debugging symbol, e.g.
719                  asm(".globl _main");
720                  asm("_main:");
721                  */
722
723               if (symtab != NULL)
724                 *symtab = s;
725               return fixup_symbol_section (sym, objfile);
726             }
727           else if (MSYMBOL_TYPE (msymbol) != mst_text
728                    && MSYMBOL_TYPE (msymbol) != mst_file_text
729                    && !STREQ (name, SYMBOL_NAME (msymbol)))
730             {
731               /* This is a mangled variable, look it up by its
732                  mangled name.  */
733               return lookup_symbol (SYMBOL_NAME (msymbol), block, 
734                                     namespace, is_a_field_of_this, symtab);
735             }
736           /* There are no debug symbols for this file, or we are looking
737              for an unmangled variable.
738              Try to find a matching static symbol below. */
739         }
740     }
741       
742   ALL_PSYMTABS (objfile, ps)
743     {
744       if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
745         {
746           s = PSYMTAB_TO_SYMTAB(ps);
747           bv = BLOCKVECTOR (s);
748           block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
749           sym = lookup_block_symbol (block, name, namespace);
750           if (!sym)
751             error ("Internal: global symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);
752           if (symtab != NULL)
753             *symtab = s;
754           return fixup_symbol_section (sym, objfile);
755         }
756     }
757
758   /* Now search all per-file blocks.
759      Not strictly correct, but more useful than an error.
760      Do the symtabs first, then check the psymtabs */
761
762   ALL_SYMTABS (objfile, s)
763     {
764       bv = BLOCKVECTOR (s);
765       block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
766       sym = lookup_block_symbol (block, name, namespace);
767       if (sym) 
768         {
769           block_found = block;
770           if (symtab != NULL)
771             *symtab = s;
772           return fixup_symbol_section (sym, objfile);
773         }
774     }
775
776   ALL_PSYMTABS (objfile, ps)
777     {
778       if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
779         {
780           s = PSYMTAB_TO_SYMTAB(ps);
781           bv = BLOCKVECTOR (s);
782           block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
783           sym = lookup_block_symbol (block, name, namespace);
784           if (!sym)
785             error ("Internal: static symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);
786           if (symtab != NULL)
787             *symtab = s;
788           return fixup_symbol_section (sym, objfile);
789         }
790     }
791
792   if (symtab != NULL)
793     *symtab = NULL;
794   return 0;
795 }
796
797 /* Look, in partial_symtab PST, for symbol NAME.  Check the global
798    symbols if GLOBAL, the static symbols if not */
799
800 static struct partial_symbol *
801 lookup_partial_symbol (pst, name, global, namespace)
802      struct partial_symtab *pst;
803      const char *name;
804      int global;
805      namespace_enum namespace;
806 {
807   struct partial_symbol **start, **psym;
808   struct partial_symbol **top, **bottom, **center;
809   int length = (global ? pst->n_global_syms : pst->n_static_syms);
810   int do_linear_search = 1;
811
812   if (length == 0)
813     {
814       return (NULL);
815     }
816   
817   start = (global ?
818            pst->objfile->global_psymbols.list + pst->globals_offset :
819            pst->objfile->static_psymbols.list + pst->statics_offset  );
820
821   if (global)           /* This means we can use a binary search. */
822     {
823       do_linear_search = 0;
824
825       /* Binary search.  This search is guaranteed to end with center
826          pointing at the earliest partial symbol with the correct
827          name.  At that point *all* partial symbols with that name
828          will be checked against the correct namespace. */
829
830       bottom = start;
831       top = start + length - 1;
832       while (top > bottom)
833         {
834           center = bottom + (top - bottom) / 2;
835           if (!(center < top))
836             abort ();
837           if (!do_linear_search && SYMBOL_LANGUAGE (*center) == language_cplus)
838             {
839               do_linear_search = 1;
840             }
841           if (STRCMP (SYMBOL_NAME (*center), name) >= 0)
842             {
843               top = center;
844             }
845           else
846             {
847               bottom = center + 1;
848             }
849         }
850       if (!(top == bottom))
851         abort ();
852       while (STREQ (SYMBOL_NAME (*top), name))
853         {
854           if (SYMBOL_NAMESPACE (*top) == namespace)
855             {
856               return (*top);
857             }
858           top ++;
859         }
860     }
861
862   /* Can't use a binary search or else we found during the binary search that
863      we should also do a linear search. */
864
865   if (do_linear_search)
866     {
867       for (psym = start; psym < start + length; psym++)
868         {
869           if (namespace == SYMBOL_NAMESPACE (*psym))
870             {
871               if (SYMBOL_MATCHES_NAME (*psym, name))
872                 {
873                   return (*psym);
874                 }
875             }
876         }
877     }
878
879   return (NULL);
880 }
881
882 /* Find the psymtab containing main(). */
883 /* FIXME:  What about languages without main() or specially linked
884    executables that have no main() ? */
885
886 struct partial_symtab *
887 find_main_psymtab ()
888 {
889   register struct partial_symtab *pst;
890   register struct objfile *objfile;
891
892   ALL_PSYMTABS (objfile, pst)
893     {
894       if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE))
895         {
896           return (pst);
897         }
898     }
899   return (NULL);
900 }
901
902 /* Search BLOCK for symbol NAME in NAMESPACE.
903
904    Note that if NAME is the demangled form of a C++ symbol, we will fail
905    to find a match during the binary search of the non-encoded names, but
906    for now we don't worry about the slight inefficiency of looking for
907    a match we'll never find, since it will go pretty quick.  Once the
908    binary search terminates, we drop through and do a straight linear
909    search on the symbols.  Each symbol which is marked as being a C++
910    symbol (language_cplus set) has both the encoded and non-encoded names
911    tested for a match. */
912
913 struct symbol *
914 lookup_block_symbol (block, name, namespace)
915      register const struct block *block;
916      const char *name;
917      const namespace_enum namespace;
918 {
919   register int bot, top, inc;
920   register struct symbol *sym;
921   register struct symbol *sym_found = NULL;
922   register int do_linear_search = 1;
923
924   /* If the blocks's symbols were sorted, start with a binary search.  */
925
926   if (BLOCK_SHOULD_SORT (block))
927     {
928       /* Reset the linear search flag so if the binary search fails, we
929          won't do the linear search once unless we find some reason to
930          do so, such as finding a C++ symbol during the binary search.
931          Note that for C++ modules, ALL the symbols in a block should
932          end up marked as C++ symbols. */
933
934       do_linear_search = 0;
935       top = BLOCK_NSYMS (block);
936       bot = 0;
937
938       /* Advance BOT to not far before the first symbol whose name is NAME. */
939
940       while (1)
941         {
942           inc = (top - bot + 1);
943           /* No need to keep binary searching for the last few bits worth.  */
944           if (inc < 4)
945             {
946               break;
947             }
948           inc = (inc >> 1) + bot;
949           sym = BLOCK_SYM (block, inc);
950           if (!do_linear_search && SYMBOL_LANGUAGE (sym) == language_cplus)
951             {
952               do_linear_search = 1;
953             }
954           if (SYMBOL_NAME (sym)[0] < name[0])
955             {
956               bot = inc;
957             }
958           else if (SYMBOL_NAME (sym)[0] > name[0])
959             {
960               top = inc;
961             }
962           else if (STRCMP (SYMBOL_NAME (sym), name) < 0)
963             {
964               bot = inc;
965             }
966           else
967             {
968               top = inc;
969             }
970         }
971
972       /* Now scan forward until we run out of symbols, find one whose
973          name is greater than NAME, or find one we want.  If there is
974          more than one symbol with the right name and namespace, we
975          return the first one; I believe it is now impossible for us
976          to encounter two symbols with the same name and namespace
977          here, because blocks containing argument symbols are no
978          longer sorted.  */
979
980       top = BLOCK_NSYMS (block);
981       while (bot < top)
982         {
983           sym = BLOCK_SYM (block, bot);
984           inc = SYMBOL_NAME (sym)[0] - name[0];
985           if (inc == 0)
986             {
987               inc = STRCMP (SYMBOL_NAME (sym), name);
988             }
989           if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)
990             {
991               return (sym);
992             }
993           if (inc > 0)
994             {
995               break;
996             }
997           bot++;
998         }
999     }
1000
1001   /* Here if block isn't sorted, or we fail to find a match during the
1002      binary search above.  If during the binary search above, we find a
1003      symbol which is a C++ symbol, then we have re-enabled the linear
1004      search flag which was reset when starting the binary search.
1005
1006      This loop is equivalent to the loop above, but hacked greatly for speed.
1007
1008      Note that parameter symbols do not always show up last in the
1009      list; this loop makes sure to take anything else other than
1010      parameter symbols first; it only uses parameter symbols as a
1011      last resort.  Note that this only takes up extra computation
1012      time on a match.  */
1013
1014   if (do_linear_search)
1015     {
1016       top = BLOCK_NSYMS (block);
1017       bot = 0;
1018       while (bot < top)
1019         {
1020           sym = BLOCK_SYM (block, bot);
1021           if (SYMBOL_NAMESPACE (sym) == namespace &&
1022               SYMBOL_MATCHES_NAME (sym, name))
1023             {
1024               /* If SYM has aliases, then use any alias that is active
1025                  at the current PC.  If no alias is active at the current
1026                  PC, then use the main symbol.
1027
1028                  ?!? Is checking the current pc correct?  Is this routine
1029                  ever called to look up a symbol from another context?  */
1030               if (SYMBOL_ALIASES (sym))
1031                 sym = find_active_alias (sym, read_pc ());
1032
1033               sym_found = sym;
1034               if (SYMBOL_CLASS (sym) != LOC_ARG &&
1035                   SYMBOL_CLASS (sym) != LOC_LOCAL_ARG &&
1036                   SYMBOL_CLASS (sym) != LOC_REF_ARG &&
1037                   SYMBOL_CLASS (sym) != LOC_REGPARM &&
1038                   SYMBOL_CLASS (sym) != LOC_REGPARM_ADDR &&
1039                   SYMBOL_CLASS (sym) != LOC_BASEREG_ARG)
1040                 {
1041                   break;
1042                 }
1043             }
1044           bot++;
1045         }
1046     }
1047   return (sym_found);           /* Will be NULL if not found. */
1048 }
1049
1050 /* Given a main symbol SYM and ADDR, search through the alias
1051    list to determine if an alias is active at ADDR and return
1052    the active alias.
1053
1054    If no alias is active, then return SYM.  */
1055
1056 static struct symbol *
1057 find_active_alias (sym, addr)
1058   struct symbol *sym;
1059   CORE_ADDR addr;
1060 {
1061   struct range_list *r;
1062   struct alias_list *aliases;
1063
1064   /* If we have aliases, check them first.  */
1065   aliases = SYMBOL_ALIASES (sym);
1066
1067   while (aliases)
1068     {
1069       if (!SYMBOL_RANGES (aliases->sym))
1070         return aliases->sym;
1071       for (r = SYMBOL_RANGES (aliases->sym); r; r = r->next)
1072         {
1073           if (r->start <= addr && r->end > addr)
1074             return aliases->sym;
1075         }
1076       aliases = aliases->next;
1077     }
1078
1079   /* Nothing found, return the main symbol.  */
1080   return sym;
1081 }
1082
1083 \f
1084 /* Return the symbol for the function which contains a specified
1085    lexical block, described by a struct block BL.  */
1086
1087 struct symbol *
1088 block_function (bl)
1089      struct block *bl;
1090 {
1091   while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
1092     bl = BLOCK_SUPERBLOCK (bl);
1093
1094   return BLOCK_FUNCTION (bl);
1095 }
1096
1097 /* Find the symtab associated with PC and SECTION.  Look through the
1098    psymtabs and read in another symtab if necessary. */
1099
1100 struct symtab *
1101 find_pc_sect_symtab (pc, section)
1102      CORE_ADDR pc;
1103      asection *section;
1104 {
1105   register struct block *b;
1106   struct blockvector *bv;
1107   register struct symtab *s = NULL;
1108   register struct symtab *best_s = NULL;
1109   register struct partial_symtab *ps;
1110   register struct objfile *objfile;
1111   CORE_ADDR distance = 0;
1112
1113   /* Search all symtabs for the one whose file contains our address, and which
1114      is the smallest of all the ones containing the address.  This is designed
1115      to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1116      and symtab b is at 0x2000-0x3000.  So the GLOBAL_BLOCK for a is from
1117      0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1118
1119      This happens for native ecoff format, where code from included files
1120      gets its own symtab. The symtab for the included file should have
1121      been read in already via the dependency mechanism.
1122      It might be swifter to create several symtabs with the same name
1123      like xcoff does (I'm not sure).
1124
1125      It also happens for objfiles that have their functions reordered.
1126      For these, the symtab we are looking for is not necessarily read in.  */
1127
1128   ALL_SYMTABS (objfile, s)
1129     {
1130       bv = BLOCKVECTOR (s);
1131       b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1132       if (BLOCK_START (b) <= pc
1133           && BLOCK_END (b) > pc
1134           && (distance == 0
1135               || BLOCK_END (b) - BLOCK_START (b) < distance))
1136         {
1137           /* For an objfile that has its functions reordered,
1138              find_pc_psymtab will find the proper partial symbol table
1139              and we simply return its corresponding symtab.  */
1140           /* In order to better support objfiles that contain both
1141              stabs and coff debugging info, we continue on if a psymtab
1142              can't be found. */
1143           if ((objfile->flags & OBJF_REORDERED) && objfile->psymtabs)
1144             {
1145               ps = find_pc_sect_psymtab (pc, section);
1146               if (ps)
1147                 return PSYMTAB_TO_SYMTAB (ps);
1148             }
1149           if (section != 0)
1150             {
1151               int i;
1152
1153               for (i = 0; i < b->nsyms; i++)
1154                 {
1155                   fixup_symbol_section (b->sym[i], objfile);
1156                   if (section == SYMBOL_BFD_SECTION (b->sym[i]))
1157                     break;
1158                 }
1159               if (i >= b->nsyms)
1160                 continue;       /* no symbol in this symtab matches section */
1161             }
1162           distance = BLOCK_END (b) - BLOCK_START (b);
1163           best_s = s;
1164         }
1165     }
1166
1167   if (best_s != NULL)
1168     return(best_s);
1169
1170   s = NULL;
1171   ps = find_pc_sect_psymtab (pc, section);
1172   if (ps)
1173     {
1174       if (ps->readin)
1175         /* Might want to error() here (in case symtab is corrupt and
1176            will cause a core dump), but maybe we can successfully
1177            continue, so let's not.  */
1178         /* FIXME-32x64: assumes pc fits in a long */
1179         warning ("\
1180 (Internal error: pc 0x%lx in read in psymtab, but not in symtab.)\n",
1181                  (unsigned long) pc);
1182       s = PSYMTAB_TO_SYMTAB (ps);
1183     }
1184   return (s);
1185 }
1186
1187 /* Find the symtab associated with PC.  Look through the psymtabs and
1188    read in another symtab if necessary.  Backward compatibility, no section */
1189
1190 struct symtab *
1191 find_pc_symtab (pc)
1192      CORE_ADDR pc;
1193 {
1194   return find_pc_sect_symtab (pc, find_pc_mapped_section (pc));
1195 }
1196
1197 \f
1198 #if 0
1199
1200 /* Find the closest symbol value (of any sort -- function or variable)
1201    for a given address value.  Slow but complete.  (currently unused,
1202    mainly because it is too slow.  We could fix it if each symtab and
1203    psymtab had contained in it the addresses ranges of each of its
1204    sections, which also would be required to make things like "info
1205    line *0x2345" cause psymtabs to be converted to symtabs).  */
1206
1207 struct symbol *
1208 find_addr_symbol (addr, symtabp, symaddrp)
1209      CORE_ADDR addr;
1210      struct symtab **symtabp;
1211      CORE_ADDR *symaddrp;
1212 {
1213   struct symtab *symtab, *best_symtab;
1214   struct objfile *objfile;
1215   register int bot, top;
1216   register struct symbol *sym;
1217   register CORE_ADDR sym_addr;
1218   struct block *block;
1219   int blocknum;
1220
1221   /* Info on best symbol seen so far */
1222
1223   register CORE_ADDR best_sym_addr = 0;
1224   struct symbol *best_sym = 0;
1225
1226   /* FIXME -- we should pull in all the psymtabs, too!  */
1227   ALL_SYMTABS (objfile, symtab)
1228     {
1229       /* Search the global and static blocks in this symtab for
1230          the closest symbol-address to the desired address.  */
1231
1232       for (blocknum = GLOBAL_BLOCK; blocknum <= STATIC_BLOCK; blocknum++)
1233         {
1234           QUIT;
1235           block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), blocknum);
1236           top = BLOCK_NSYMS (block);
1237           for (bot = 0; bot < top; bot++)
1238             {
1239               sym = BLOCK_SYM (block, bot);
1240               switch (SYMBOL_CLASS (sym))
1241                 {
1242                 case LOC_STATIC:        
1243                 case LOC_LABEL: 
1244                   sym_addr = SYMBOL_VALUE_ADDRESS (sym);
1245                   break;
1246
1247                 case LOC_BLOCK:
1248                   sym_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1249                   break;
1250
1251                 default:
1252                   continue;
1253                 }
1254
1255                 if (sym_addr <= addr)
1256                   if (sym_addr > best_sym_addr)
1257                     {
1258                       /* Quit if we found an exact match.  */
1259                       best_sym = sym;
1260                       best_sym_addr = sym_addr;
1261                       best_symtab = symtab;
1262                       if (sym_addr == addr)
1263                         goto done;
1264                     }
1265             }
1266         }
1267     }
1268
1269  done:
1270   if (symtabp)
1271     *symtabp = best_symtab;
1272   if (symaddrp)
1273     *symaddrp = best_sym_addr;
1274   return best_sym;
1275 }
1276 #endif /* 0 */
1277
1278 /* Find the source file and line number for a given PC value and section.
1279    Return a structure containing a symtab pointer, a line number,
1280    and a pc range for the entire source line.
1281    The value's .pc field is NOT the specified pc.
1282    NOTCURRENT nonzero means, if specified pc is on a line boundary,
1283    use the line that ends there.  Otherwise, in that case, the line
1284    that begins there is used.  */
1285
1286 /* The big complication here is that a line may start in one file, and end just
1287    before the start of another file.  This usually occurs when you #include
1288    code in the middle of a subroutine.  To properly find the end of a line's PC
1289    range, we must search all symtabs associated with this compilation unit, and
1290    find the one whose first PC is closer than that of the next line in this
1291    symtab.  */
1292
1293 /* If it's worth the effort, we could be using a binary search.  */
1294
1295 struct symtab_and_line
1296 find_pc_sect_line (pc, section, notcurrent)
1297      CORE_ADDR pc;
1298      struct sec *section;
1299      int notcurrent;
1300 {
1301   struct symtab *s;
1302   register struct linetable *l;
1303   register int len;
1304   register int i;
1305   register struct linetable_entry *item;
1306   struct symtab_and_line val;
1307   struct blockvector *bv;
1308
1309   /* Info on best line seen so far, and where it starts, and its file.  */
1310
1311   struct linetable_entry *best = NULL;
1312   CORE_ADDR best_end = 0;
1313   struct symtab *best_symtab = 0;
1314
1315   /* Store here the first line number
1316      of a file which contains the line at the smallest pc after PC.
1317      If we don't find a line whose range contains PC,
1318      we will use a line one less than this,
1319      with a range from the start of that file to the first line's pc.  */
1320   struct linetable_entry *alt = NULL;
1321   struct symtab *alt_symtab = 0;
1322
1323   /* Info on best line seen in this file.  */
1324
1325   struct linetable_entry *prev;
1326
1327   /* If this pc is not from the current frame,
1328      it is the address of the end of a call instruction.
1329      Quite likely that is the start of the following statement.
1330      But what we want is the statement containing the instruction.
1331      Fudge the pc to make sure we get that.  */
1332
1333   INIT_SAL (&val);      /* initialize to zeroes */
1334
1335   if (notcurrent)
1336     pc -= 1;
1337
1338   s = find_pc_sect_symtab (pc, section);
1339   if (!s)
1340     {
1341       val.pc = pc;
1342       return val;
1343     }
1344
1345   bv = BLOCKVECTOR (s);
1346
1347   /* Look at all the symtabs that share this blockvector.
1348      They all have the same apriori range, that we found was right;
1349      but they have different line tables.  */
1350
1351   for (; s && BLOCKVECTOR (s) == bv; s = s->next)
1352     {
1353       /* Find the best line in this symtab.  */
1354       l = LINETABLE (s);
1355       if (!l)
1356         continue;
1357       len = l->nitems;
1358       if (len <= 0)
1359         {
1360           /* I think len can be zero if the symtab lacks line numbers
1361              (e.g. gcc -g1).  (Either that or the LINETABLE is NULL;
1362              I'm not sure which, and maybe it depends on the symbol
1363              reader).  */
1364           continue;
1365         }
1366
1367       prev = NULL;
1368       item = l->item;           /* Get first line info */
1369
1370       /* Is this file's first line closer than the first lines of other files?
1371          If so, record this file, and its first line, as best alternate.  */
1372       if (item->pc > pc && (!alt || item->pc < alt->pc))
1373         {
1374           alt = item;
1375           alt_symtab = s;
1376         }
1377
1378       for (i = 0; i < len; i++, item++)
1379         {
1380           /* Leave prev pointing to the linetable entry for the last line
1381              that started at or before PC.  */
1382           if (item->pc > pc)
1383             break;
1384
1385           prev = item;
1386         }
1387
1388       /* At this point, prev points at the line whose start addr is <= pc, and
1389          item points at the next line.  If we ran off the end of the linetable
1390          (pc >= start of the last line), then prev == item.  If pc < start of
1391          the first line, prev will not be set.  */
1392
1393       /* Is this file's best line closer than the best in the other files?
1394          If so, record this file, and its best line, as best so far.  */
1395
1396       if (prev && (!best || prev->pc > best->pc))
1397         {
1398           best = prev;
1399           best_symtab = s;
1400           /* If another line is in the linetable, and its PC is closer
1401              than the best_end we currently have, take it as best_end.  */
1402           if (i < len && (best_end == 0 || best_end > item->pc))
1403             best_end = item->pc;
1404         }
1405     }
1406
1407   if (!best_symtab)
1408     {
1409       if (!alt_symtab)
1410         {                       /* If we didn't find any line # info, just
1411                                    return zeros.  */
1412           val.pc = pc;
1413         }
1414       else
1415         {
1416           val.symtab = alt_symtab;
1417           val.line = alt->line - 1;
1418
1419           /* Don't return line 0, that means that we didn't find the line.  */
1420           if (val.line == 0) ++val.line;
1421
1422           val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1423           val.end = alt->pc;
1424         }
1425     }
1426   else
1427     {
1428       val.symtab = best_symtab;
1429       val.line = best->line;
1430       val.pc = best->pc;
1431       if (best_end && (!alt || best_end < alt->pc))
1432         val.end = best_end;
1433       else if (alt)
1434         val.end = alt->pc;
1435       else
1436         val.end = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1437     }
1438   val.section = section;
1439   return val;
1440 }
1441
1442 /* Backward compatibility (no section) */
1443
1444 struct symtab_and_line
1445 find_pc_line (pc, notcurrent)
1446      CORE_ADDR pc;
1447      int notcurrent;
1448 {
1449   asection     *section;
1450
1451   section = find_pc_overlay (pc);
1452   if (pc_in_unmapped_range (pc, section))
1453     pc = overlay_mapped_address (pc, section);
1454   return find_pc_sect_line (pc, section, notcurrent);
1455 }
1456
1457 \f
1458 static int find_line_symtab PARAMS ((struct symtab *, int, struct linetable **,
1459                                      int *, int *));
1460
1461 /* Find line number LINE in any symtab whose name is the same as
1462    SYMTAB.
1463
1464    If found, return 1, set *LINETABLE to the linetable in which it was
1465    found, set *INDEX to the index in the linetable of the best entry
1466    found, and set *EXACT_MATCH nonzero if the value returned is an
1467    exact match.
1468
1469    If not found, return 0.  */
1470
1471 static int
1472 find_line_symtab (symtab, line, linetable, index, exact_match)
1473      struct symtab *symtab;
1474      int line;
1475      struct linetable **linetable;
1476      int *index;
1477      int *exact_match;
1478 {
1479   int exact;
1480
1481   /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
1482      so far seen.  */
1483
1484   int best_index;
1485   struct linetable *best_linetable;
1486
1487   /* First try looking it up in the given symtab.  */
1488   best_linetable = LINETABLE (symtab);
1489   best_index = find_line_common (best_linetable, line, &exact);
1490   if (best_index < 0 || !exact)
1491     {
1492       /* Didn't find an exact match.  So we better keep looking for
1493          another symtab with the same name.  In the case of xcoff,
1494          multiple csects for one source file (produced by IBM's FORTRAN
1495          compiler) produce multiple symtabs (this is unavoidable
1496          assuming csects can be at arbitrary places in memory and that
1497          the GLOBAL_BLOCK of a symtab has a begin and end address).  */
1498
1499       /* BEST is the smallest linenumber > LINE so far seen,
1500          or 0 if none has been seen so far.
1501          BEST_INDEX and BEST_LINETABLE identify the item for it.  */
1502       int best;
1503
1504       struct objfile *objfile;
1505       struct symtab *s;
1506
1507       if (best_index >= 0)
1508         best = best_linetable->item[best_index].line;
1509       else
1510         best = 0;
1511
1512       ALL_SYMTABS (objfile, s)
1513         {
1514           struct linetable *l;
1515           int ind;
1516
1517           if (!STREQ (symtab->filename, s->filename))
1518             continue;
1519           l = LINETABLE (s);
1520           ind = find_line_common (l, line, &exact);
1521           if (ind >= 0)
1522             {
1523               if (exact)
1524                 {
1525                   best_index = ind;
1526                   best_linetable = l;
1527                   goto done;
1528                 }
1529               if (best == 0 || l->item[ind].line < best)
1530                 {
1531                   best = l->item[ind].line;
1532                   best_index = ind;
1533                   best_linetable = l;
1534                 }
1535             }
1536         }
1537     }
1538  done:
1539   if (best_index < 0)
1540     return 0;
1541
1542   if (index)
1543     *index = best_index;
1544   if (linetable)
1545     *linetable = best_linetable;
1546   if (exact_match)
1547     *exact_match = exact;
1548   return 1;
1549 }
1550 \f
1551 /* Find the PC value for a given source file and line number.
1552    Returns zero for invalid line number.
1553    The source file is specified with a struct symtab.  */
1554
1555 CORE_ADDR
1556 find_line_pc (symtab, line)
1557      struct symtab *symtab;
1558      int line;
1559 {
1560   struct linetable *l;
1561   int ind;
1562
1563   if (symtab == 0)
1564     return 0;
1565   if (find_line_symtab (symtab, line, &l, &ind, NULL))
1566     return l->item[ind].pc;
1567   else
1568     return 0;
1569 }
1570
1571 /* Find the range of pc values in a line.
1572    Store the starting pc of the line into *STARTPTR
1573    and the ending pc (start of next line) into *ENDPTR.
1574    Returns 1 to indicate success.
1575    Returns 0 if could not find the specified line.  */
1576
1577 int
1578 find_line_pc_range (sal, startptr, endptr)
1579      struct symtab_and_line sal;
1580      CORE_ADDR *startptr, *endptr;
1581 {
1582   CORE_ADDR startaddr;
1583   struct symtab_and_line found_sal;
1584
1585   startaddr = sal.pc;
1586   if (startaddr == 0)
1587     {
1588       startaddr = find_line_pc (sal.symtab, sal.line);
1589     }
1590   if (startaddr == 0)
1591     return 0;
1592
1593   /* This whole function is based on address.  For example, if line 10 has
1594      two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
1595      "info line *0x123" should say the line goes from 0x100 to 0x200
1596      and "info line *0x355" should say the line goes from 0x300 to 0x400.
1597      This also insures that we never give a range like "starts at 0x134
1598      and ends at 0x12c".  */
1599
1600   found_sal = find_pc_sect_line (startaddr, sal.section, 0);
1601   if (found_sal.line != sal.line)
1602     {
1603       /* The specified line (sal) has zero bytes.  */
1604       *startptr = found_sal.pc;
1605       *endptr = found_sal.pc;
1606     }
1607   else
1608     {
1609       *startptr = found_sal.pc;
1610       *endptr = found_sal.end;
1611     }
1612   return 1;
1613 }
1614
1615 /* Given a line table and a line number, return the index into the line
1616    table for the pc of the nearest line whose number is >= the specified one.
1617    Return -1 if none is found.  The value is >= 0 if it is an index.
1618
1619    Set *EXACT_MATCH nonzero if the value returned is an exact match.  */
1620
1621 static int
1622 find_line_common (l, lineno, exact_match)
1623      register struct linetable *l;
1624      register int lineno;
1625      int *exact_match;
1626 {
1627   register int i;
1628   register int len;
1629
1630   /* BEST is the smallest linenumber > LINENO so far seen,
1631      or 0 if none has been seen so far.
1632      BEST_INDEX identifies the item for it.  */
1633
1634   int best_index = -1;
1635   int best = 0;
1636
1637   if (lineno <= 0)
1638     return -1;
1639   if (l == 0)
1640     return -1;
1641
1642   len = l->nitems;
1643   for (i = 0; i < len; i++)
1644     {
1645       register struct linetable_entry *item = &(l->item[i]);
1646
1647       if (item->line == lineno)
1648         {
1649           /* Return the first (lowest address) entry which matches.  */
1650           *exact_match = 1;
1651           return i;
1652         }
1653
1654       if (item->line > lineno && (best == 0 || item->line < best))
1655         {
1656           best = item->line;
1657           best_index = i;
1658         }
1659     }
1660
1661   /* If we got here, we didn't get an exact match.  */
1662
1663   *exact_match = 0;
1664   return best_index;
1665 }
1666
1667 int
1668 find_pc_line_pc_range (pc, startptr, endptr)
1669      CORE_ADDR pc;
1670      CORE_ADDR *startptr, *endptr;
1671 {
1672   struct symtab_and_line sal;
1673   sal = find_pc_line (pc, 0);
1674   *startptr = sal.pc;
1675   *endptr = sal.end;
1676   return sal.symtab != 0;
1677 }
1678
1679 /* Given a function symbol SYM, find the symtab and line for the start
1680    of the function.
1681    If the argument FUNFIRSTLINE is nonzero, we want the first line
1682    of real code inside the function.  */
1683
1684 static struct symtab_and_line
1685 find_function_start_sal PARAMS ((struct symbol *sym, int));
1686
1687 static struct symtab_and_line
1688 find_function_start_sal (sym, funfirstline)
1689      struct symbol *sym;
1690      int funfirstline;
1691 {
1692   CORE_ADDR pc;
1693   struct symtab_and_line sal;
1694
1695   pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1696   fixup_symbol_section (sym, NULL);
1697   if (funfirstline)
1698     { /* skip "first line" of function (which is actually its prologue) */
1699       asection *section = SYMBOL_BFD_SECTION (sym);
1700       /* If function is in an unmapped overlay, use its unmapped LMA
1701          address, so that SKIP_PROLOGUE has something unique to work on */
1702       if (section_is_overlay (section) &&
1703           !section_is_mapped (section))
1704         pc = overlay_unmapped_address (pc, section);
1705
1706       pc += FUNCTION_START_OFFSET;
1707       SKIP_PROLOGUE (pc);
1708
1709       /* For overlays, map pc back into its mapped VMA range */
1710       pc = overlay_mapped_address (pc, section);
1711     }
1712   sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0);
1713
1714 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1715   /* Convex: no need to suppress code on first line, if any */
1716   sal.pc = pc;
1717 #else
1718   /* Check if SKIP_PROLOGUE left us in mid-line, and the next
1719      line is still part of the same function.  */
1720   if (sal.pc != pc
1721       && BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) <= sal.end
1722       && sal.end < BLOCK_END (SYMBOL_BLOCK_VALUE (sym)))
1723     {
1724       /* First pc of next line */
1725       pc = sal.end;
1726       /* Recalculate the line number (might not be N+1).  */
1727       sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0);
1728     }
1729   sal.pc = pc;
1730 #endif
1731
1732   return sal;
1733 }
1734 \f
1735 /* If P is of the form "operator[ \t]+..." where `...' is
1736    some legitimate operator text, return a pointer to the
1737    beginning of the substring of the operator text.
1738    Otherwise, return "".  */
1739 char *
1740 operator_chars (p, end)
1741      char *p;
1742      char **end;
1743 {
1744   *end = "";
1745   if (strncmp (p, "operator", 8))
1746     return *end;
1747   p += 8;
1748
1749   /* Don't get faked out by `operator' being part of a longer
1750      identifier.  */
1751   if (isalpha(*p) || *p == '_' || *p == '$' || *p == '\0')
1752     return *end;
1753
1754   /* Allow some whitespace between `operator' and the operator symbol.  */
1755   while (*p == ' ' || *p == '\t')
1756     p++;
1757
1758   /* Recognize 'operator TYPENAME'. */
1759
1760   if (isalpha(*p) || *p == '_' || *p == '$')
1761     {
1762       register char *q = p+1;
1763       while (isalnum(*q) || *q == '_' || *q == '$')
1764         q++;
1765       *end = q;
1766       return p;
1767     }
1768
1769   switch (*p)
1770     {
1771     case '!':
1772     case '=':
1773     case '*':
1774     case '/':
1775     case '%':
1776     case '^':
1777       if (p[1] == '=')
1778         *end = p+2;
1779       else
1780         *end = p+1;
1781       return p;
1782     case '<':
1783     case '>':
1784     case '+':
1785     case '-':
1786     case '&':
1787     case '|':
1788       if (p[1] == '=' || p[1] == p[0])
1789         *end = p+2;
1790       else
1791         *end = p+1;
1792       return p;
1793     case '~':
1794     case ',':
1795       *end = p+1;
1796       return p;
1797     case '(':
1798       if (p[1] != ')')
1799         error ("`operator ()' must be specified without whitespace in `()'");
1800       *end = p+2;
1801       return p;
1802     case '?':
1803       if (p[1] != ':')
1804         error ("`operator ?:' must be specified without whitespace in `?:'");
1805       *end = p+2;
1806       return p;
1807     case '[':
1808       if (p[1] != ']')
1809         error ("`operator []' must be specified without whitespace in `[]'");
1810       *end = p+2;
1811       return p;
1812     default:
1813       error ("`operator %s' not supported", p);
1814       break;
1815     }
1816   *end = "";
1817   return *end;
1818 }
1819
1820 /* Return the number of methods described for TYPE, including the
1821    methods from types it derives from. This can't be done in the symbol
1822    reader because the type of the baseclass might still be stubbed
1823    when the definition of the derived class is parsed.  */
1824
1825 static int total_number_of_methods PARAMS ((struct type *type));
1826
1827 static int
1828 total_number_of_methods (type)
1829      struct type *type;
1830 {
1831   int n;
1832   int count;
1833
1834   CHECK_TYPEDEF (type);
1835   if (TYPE_CPLUS_SPECIFIC (type) == NULL)
1836     return 0;
1837   count = TYPE_NFN_FIELDS_TOTAL (type);
1838
1839   for (n = 0; n < TYPE_N_BASECLASSES (type); n++)
1840     count += total_number_of_methods (TYPE_BASECLASS (type, n));
1841
1842   return count;
1843 }
1844
1845 /* Recursive helper function for decode_line_1.
1846    Look for methods named NAME in type T.
1847    Return number of matches.
1848    Put matches in SYM_ARR, which should have been allocated with
1849    a size of total_number_of_methods (T) * sizeof (struct symbol *).
1850    Note that this function is g++ specific.  */
1851
1852 int
1853 find_methods (t, name, sym_arr)
1854      struct type *t;
1855      char *name;
1856      struct symbol **sym_arr;
1857 {
1858   int i1 = 0;
1859   int ibase;
1860   struct symbol *sym_class;
1861   char *class_name = type_name_no_tag (t);
1862   /* Ignore this class if it doesn't have a name.  This is ugly, but
1863      unless we figure out how to get the physname without the name of
1864      the class, then the loop can't do any good.  */
1865   if (class_name
1866       && (sym_class = lookup_symbol (class_name,
1867                                      (struct block *)NULL,
1868                                      STRUCT_NAMESPACE,
1869                                      (int *)NULL,
1870                                      (struct symtab **)NULL)))
1871     {
1872       int method_counter;
1873       /* FIXME: Shouldn't this just be CHECK_TYPEDEF (t)?  */
1874       t = SYMBOL_TYPE (sym_class);
1875       for (method_counter = TYPE_NFN_FIELDS (t) - 1;
1876            method_counter >= 0;
1877            --method_counter)
1878         {
1879           int field_counter;
1880           struct fn_field *f = TYPE_FN_FIELDLIST1 (t, method_counter);
1881           char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
1882           char dem_opname[64];
1883
1884           if (strncmp(method_name, "__", 2)==0 ||
1885             strncmp(method_name, "op", 2)==0 ||
1886             strncmp(method_name, "type", 4)==0 )
1887             {
1888               if (cplus_demangle_opname(method_name, dem_opname, DMGL_ANSI))
1889                 method_name = dem_opname;
1890               else if (cplus_demangle_opname(method_name, dem_opname, 0))
1891                 method_name = dem_opname; 
1892             }
1893           if (STREQ (name, method_name))
1894             /* Find all the fields with that name.  */
1895             for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
1896                  field_counter >= 0;
1897                  --field_counter)
1898               {
1899                 char *phys_name;
1900                 if (TYPE_FN_FIELD_STUB (f, field_counter))
1901                   check_stub_method (t, method_counter, field_counter);
1902                 phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
1903                 /* Destructor is handled by caller, dont add it to the list */
1904                 if (DESTRUCTOR_PREFIX_P (phys_name))
1905                   continue;
1906
1907                 sym_arr[i1] = lookup_symbol (phys_name,
1908                                              NULL, VAR_NAMESPACE,
1909                                              (int *) NULL,
1910                                              (struct symtab **) NULL);
1911                 if (sym_arr[i1])
1912                   i1++;
1913                 else
1914                   {
1915                     fputs_filtered("(Cannot find method ", gdb_stdout);
1916                     fprintf_symbol_filtered (gdb_stdout, phys_name,
1917                                              language_cplus,
1918                                              DMGL_PARAMS | DMGL_ANSI);
1919                     fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
1920                   }
1921               }
1922         }
1923     }
1924
1925   /* Only search baseclasses if there is no match yet, since names in
1926      derived classes override those in baseclasses.
1927
1928      FIXME: The above is not true; it is only true of member functions
1929      if they have the same number of arguments (??? - section 13.1 of the
1930      ARM says the function members are not in the same scope but doesn't
1931      really spell out the rules in a way I understand.  In any case, if
1932      the number of arguments differ this is a case in which we can overload
1933      rather than hiding without any problem, and gcc 2.4.5 does overload
1934      rather than hiding in this case).  */
1935
1936   if (i1)
1937     return i1;
1938   for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
1939     i1 += find_methods(TYPE_BASECLASS(t, ibase), name,
1940                        sym_arr + i1);
1941   return i1;
1942 }
1943
1944 /* Helper function for decode_line_1.
1945    Build a canonical line spec in CANONICAL if it is non-NULL and if
1946    the SAL has a symtab.
1947    If SYMNAME is non-NULL the canonical line spec is `filename:symname'.
1948    If SYMNAME is NULL the line number from SAL is used and the canonical
1949    line spec is `filename:linenum'.  */
1950
1951 static void
1952 build_canonical_line_spec (sal, symname, canonical)
1953      struct symtab_and_line *sal;
1954      char *symname;
1955      char ***canonical;
1956 {
1957   char **canonical_arr;
1958   char *canonical_name;
1959   char *filename;
1960   struct symtab *s = sal->symtab;
1961
1962   if (s == (struct symtab *)NULL
1963       || s->filename == (char *)NULL
1964       || canonical == (char ***)NULL)
1965     return;
1966  
1967   canonical_arr = (char **) xmalloc (sizeof (char *));
1968   *canonical = canonical_arr;
1969
1970   filename = s->filename;
1971   if (symname != NULL)
1972     {
1973       canonical_name = xmalloc (strlen (filename) + strlen (symname) + 2);
1974       sprintf (canonical_name, "%s:%s", filename, symname);
1975     }
1976   else
1977     {
1978       canonical_name = xmalloc (strlen (filename) + 30);
1979       sprintf (canonical_name, "%s:%d", filename, sal->line);
1980     }
1981   canonical_arr[0] = canonical_name;
1982 }
1983
1984 /* Parse a string that specifies a line number.
1985    Pass the address of a char * variable; that variable will be
1986    advanced over the characters actually parsed.
1987
1988    The string can be:
1989
1990    LINENUM -- that line number in current file.  PC returned is 0.
1991    FILE:LINENUM -- that line in that file.  PC returned is 0.
1992    FUNCTION -- line number of openbrace of that function.
1993       PC returned is the start of the function.
1994    VARIABLE -- line number of definition of that variable.
1995       PC returned is 0.
1996    FILE:FUNCTION -- likewise, but prefer functions in that file.
1997    *EXPR -- line in which address EXPR appears.
1998
1999    FUNCTION may be an undebuggable function found in minimal symbol table.
2000
2001    If the argument FUNFIRSTLINE is nonzero, we want the first line
2002    of real code inside a function when a function is specified, and it is
2003    not OK to specify a variable or type to get its line number.
2004
2005    DEFAULT_SYMTAB specifies the file to use if none is specified.
2006    It defaults to current_source_symtab.
2007    DEFAULT_LINE specifies the line number to use for relative
2008    line numbers (that start with signs).  Defaults to current_source_line.
2009    If CANONICAL is non-NULL, store an array of strings containing the canonical
2010    line specs there if necessary. Currently overloaded member functions and
2011    line numbers or static functions without a filename yield a canonical
2012    line spec. The array and the line spec strings are allocated on the heap,
2013    it is the callers responsibility to free them.
2014
2015    Note that it is possible to return zero for the symtab
2016    if no file is validly specified.  Callers must check that.
2017    Also, the line number returned may be invalid.  */
2018
2019 /* We allow single quotes in various places.  This is a hideous
2020    kludge, which exists because the completer can't yet deal with the
2021    lack of single quotes.  FIXME: write a linespec_completer which we
2022    can use as appropriate instead of make_symbol_completion_list.  */
2023
2024 struct symtabs_and_lines
2025 decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
2026      char **argptr;
2027      int funfirstline;
2028      struct symtab *default_symtab;
2029      int default_line;
2030      char ***canonical;
2031 {
2032   struct symtabs_and_lines values;
2033 #ifdef HPPA_COMPILER_BUG
2034   /* FIXME: The native HP 9000/700 compiler has a bug which appears
2035      when optimizing this file with target i960-vxworks.  I haven't
2036      been able to construct a simple test case.  The problem is that
2037      in the second call to SKIP_PROLOGUE below, the compiler somehow
2038      does not realize that the statement val = find_pc_line (...) will
2039      change the values of the fields of val.  It extracts the elements
2040      into registers at the top of the block, and does not update the
2041      registers after the call to find_pc_line.  You can check this by
2042      inserting a printf at the end of find_pc_line to show what values
2043      it is returning for val.pc and val.end and another printf after
2044      the call to see what values the function actually got (remember,
2045      this is compiling with cc -O, with this patch removed).  You can
2046      also examine the assembly listing: search for the second call to
2047      skip_prologue; the LDO statement before the next call to
2048      find_pc_line loads the address of the structure which
2049      find_pc_line will return; if there is a LDW just before the LDO,
2050      which fetches an element of the structure, then the compiler
2051      still has the bug.
2052
2053      Setting val to volatile avoids the problem.  We must undef
2054      volatile, because the HPPA native compiler does not define
2055      __STDC__, although it does understand volatile, and so volatile
2056      will have been defined away in defs.h.  */
2057 #undef volatile
2058   volatile struct symtab_and_line val;
2059 #define volatile /*nothing*/
2060 #else
2061   struct symtab_and_line val;
2062 #endif
2063   register char *p, *p1;
2064   char *q, *pp;
2065 #if 0
2066   char *q1;
2067 #endif
2068   register struct symtab *s;
2069
2070   register struct symbol *sym;
2071   /* The symtab that SYM was found in.  */
2072   struct symtab *sym_symtab;
2073
2074   register CORE_ADDR pc;
2075   register struct minimal_symbol *msymbol;
2076   char *copy;
2077   struct symbol *sym_class;
2078   int i1;
2079   int is_quoted, has_parens;
2080   struct symbol **sym_arr;
2081   struct type *t;
2082   char *saved_arg = *argptr;
2083   extern char *gdb_completer_quote_characters;
2084   
2085   INIT_SAL (&val);      /* initialize to zeroes */
2086
2087   /* Defaults have defaults.  */
2088
2089   if (default_symtab == 0)
2090     {
2091       default_symtab = current_source_symtab;
2092       default_line = current_source_line;
2093     }
2094
2095   /* See if arg is *PC */
2096
2097   if (**argptr == '*')
2098     {
2099       (*argptr)++;
2100       pc = parse_and_eval_address_1 (argptr);
2101       values.sals = (struct symtab_and_line *)
2102         xmalloc (sizeof (struct symtab_and_line));
2103       values.nelts = 1;
2104       values.sals[0] = find_pc_line (pc, 0);
2105       values.sals[0].pc = pc;
2106       return values;
2107     }
2108
2109   /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
2110
2111   s = NULL;
2112   is_quoted = (**argptr
2113                && strchr (gdb_completer_quote_characters, **argptr) != NULL);
2114   has_parens = ((pp = strchr (*argptr, '(')) != NULL
2115                  && (pp = strchr (pp, ')')) != NULL);
2116
2117   for (p = *argptr; *p; p++)
2118     {
2119       if (p[0] == '<') 
2120         {
2121           while(++p && *p != '>');
2122           if (!p)
2123             {
2124               error ("non-matching '<' and '>' in command");
2125             }
2126         }
2127       if (p[0] == ':' || p[0] == ' ' || p[0] == '\t')
2128         break;
2129       if (p[0] == '.' && strchr (p, ':') == NULL) /* Java qualified method. */
2130         {
2131           /* Find the *last* '.', since the others are package qualifiers. */
2132           for (p1 = p;  *p1;  p1++)
2133             {
2134               if (*p1 == '.')
2135                 p = p1;
2136             }
2137           break;
2138         }
2139     }
2140   while (p[0] == ' ' || p[0] == '\t') p++;
2141
2142   if ((p[0] == ':' || p[0] == '.') && !has_parens)
2143     {
2144
2145       /*  C++ or Java */
2146       if (is_quoted) *argptr = *argptr+1;
2147       if (p[0] == '.' || p[1] ==':')
2148         {
2149           /* Extract the class name.  */
2150           p1 = p;
2151           while (p != *argptr && p[-1] == ' ') --p;
2152           copy = (char *) alloca (p - *argptr + 1);
2153           memcpy (copy, *argptr, p - *argptr);
2154           copy[p - *argptr] = 0;
2155
2156           /* Discard the class name from the arg.  */
2157           p = p1 + (p1[0] == ':' ? 2 : 1);
2158           while (*p == ' ' || *p == '\t') p++;
2159           *argptr = p;
2160
2161           sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0, 
2162                                      (struct symtab **)NULL);
2163        
2164           if (sym_class &&
2165               (t = check_typedef (SYMBOL_TYPE (sym_class)),
2166                (TYPE_CODE (t) == TYPE_CODE_STRUCT
2167                 || TYPE_CODE (t) == TYPE_CODE_UNION)))
2168             {
2169               /* Arg token is not digits => try it as a function name
2170                  Find the next token(everything up to end or next blank). */
2171               if (**argptr
2172                   && strchr (gdb_completer_quote_characters, **argptr) != NULL)
2173                 {
2174                   p = skip_quoted(*argptr);
2175                   *argptr = *argptr + 1;
2176                 }
2177               else
2178                 {
2179                   p = *argptr;
2180                   while (*p && *p!=' ' && *p!='\t' && *p!=',' && *p!=':') p++;
2181                 }
2182 /*
2183               q = operator_chars (*argptr, &q1);
2184               if (q1 - q)
2185                 {
2186                   char *opname;
2187                   char *tmp = alloca (q1 - q + 1);
2188                   memcpy (tmp, q, q1 - q);
2189                   tmp[q1 - q] = '\0';
2190                   opname = cplus_mangle_opname (tmp, DMGL_ANSI);
2191                   if (opname == NULL)
2192                     {
2193                       error_begin ();
2194                       printf_filtered ("no mangling for \"%s\"\n", tmp);
2195                       cplusplus_hint (saved_arg);
2196                       return_to_top_level (RETURN_ERROR);
2197                     }
2198                   copy = (char*) alloca (3 + strlen(opname));
2199                   sprintf (copy, "__%s", opname);
2200                   p = q1;
2201                 }
2202               else
2203 */
2204                 {
2205                   copy = (char *) alloca (p - *argptr + 1 );
2206                   memcpy (copy, *argptr, p - *argptr);
2207                   copy[p - *argptr] = '\0';
2208                   if (p != *argptr
2209                       && copy[p - *argptr - 1]
2210                       && strchr (gdb_completer_quote_characters,
2211                                  copy[p - *argptr - 1]) != NULL)
2212                     copy[p - *argptr - 1] = '\0';
2213                 }
2214
2215               /* no line number may be specified */
2216               while (*p == ' ' || *p == '\t') p++;
2217               *argptr = p;
2218
2219               sym = 0;
2220               i1 = 0;           /*  counter for the symbol array */
2221               sym_arr = (struct symbol **) alloca(total_number_of_methods (t)
2222                                                   * sizeof(struct symbol *));
2223
2224               if (destructor_name_p (copy, t))
2225                 {
2226                   /* Destructors are a special case.  */
2227                   int m_index, f_index;
2228
2229                   if (get_destructor_fn_field (t, &m_index, &f_index))
2230                     {
2231                       struct fn_field *f = TYPE_FN_FIELDLIST1 (t, m_index);
2232
2233                       sym_arr[i1] =
2234                         lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, f_index),
2235                                        NULL, VAR_NAMESPACE, (int *) NULL,
2236                                        (struct symtab **)NULL);
2237                       if (sym_arr[i1])
2238                         i1++;
2239                     }
2240                 }
2241               else
2242                 i1 = find_methods (t, copy, sym_arr);
2243               if (i1 == 1)
2244                 {
2245                   /* There is exactly one field with that name.  */
2246                   sym = sym_arr[0];
2247
2248                   if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
2249                     {
2250                       values.sals = (struct symtab_and_line *)
2251                         xmalloc (sizeof (struct symtab_and_line));
2252                       values.nelts = 1;
2253                       values.sals[0] = find_function_start_sal (sym,
2254                                                                 funfirstline);
2255                     }
2256                   else
2257                     {
2258                       values.nelts = 0;
2259                     }
2260                   return values;
2261                 }
2262               if (i1 > 0)
2263                 {
2264                   /* There is more than one field with that name
2265                      (overloaded).  Ask the user which one to use.  */
2266                   return decode_line_2 (sym_arr, i1, funfirstline, canonical);
2267                 }
2268               else
2269                 {
2270                   char *tmp;
2271
2272                   if (OPNAME_PREFIX_P (copy))
2273                     {
2274                       tmp = (char *)alloca (strlen (copy+3) + 9);
2275                       strcpy (tmp, "operator ");
2276                       strcat (tmp, copy+3);
2277                     }
2278                   else
2279                     tmp = copy;
2280                   error_begin ();
2281                   if (tmp[0] == '~')
2282                     printf_filtered
2283                       ("the class `%s' does not have destructor defined\n",
2284                        SYMBOL_SOURCE_NAME(sym_class));
2285                   else
2286                     printf_filtered
2287                       ("the class %s does not have any method named %s\n",
2288                        SYMBOL_SOURCE_NAME(sym_class), tmp);
2289                   cplusplus_hint (saved_arg);
2290                   return_to_top_level (RETURN_ERROR);
2291                 }
2292             }
2293           else
2294             {
2295               error_begin ();
2296               /* The quotes are important if copy is empty.  */
2297               printf_filtered
2298                 ("can't find class, struct, or union named \"%s\"\n", copy);
2299               cplusplus_hint (saved_arg);
2300               return_to_top_level (RETURN_ERROR);
2301             }
2302         }
2303       /*  end of C++  */
2304
2305
2306       /* Extract the file name.  */
2307       p1 = p;
2308       while (p != *argptr && p[-1] == ' ') --p;
2309       copy = (char *) alloca (p - *argptr + 1);
2310       memcpy (copy, *argptr, p - *argptr);
2311       copy[p - *argptr] = 0;
2312
2313       /* Find that file's data.  */
2314       s = lookup_symtab (copy);
2315       if (s == 0)
2316         {
2317           if (!have_full_symbols () && !have_partial_symbols ())
2318             error (no_symtab_msg);
2319           error ("No source file named %s.", copy);
2320         }
2321
2322       /* Discard the file name from the arg.  */
2323       p = p1 + 1;
2324       while (*p == ' ' || *p == '\t') p++;
2325       *argptr = p;
2326     }
2327
2328   /* S is specified file's symtab, or 0 if no file specified.
2329      arg no longer contains the file name.  */
2330
2331   /* Check whether arg is all digits (and sign) */
2332
2333   q = *argptr;
2334   if (*q == '-' || *q == '+') q++;
2335   while (*q >= '0' && *q <= '9')
2336     q++;
2337
2338   if (q != *argptr && (*q == 0 || *q == ' ' || *q == '\t' || *q == ','))
2339     {
2340       /* We found a token consisting of all digits -- at least one digit.  */
2341       enum sign {none, plus, minus} sign = none;
2342
2343       /* We might need a canonical line spec if no file was specified.  */
2344       int need_canonical = (s == 0) ? 1 : 0;
2345
2346       /* This is where we need to make sure that we have good defaults.
2347          We must guarantee that this section of code is never executed
2348          when we are called with just a function name, since
2349          select_source_symtab calls us with such an argument  */
2350
2351       if (s == 0 && default_symtab == 0)
2352         {
2353           select_source_symtab (0);
2354           default_symtab = current_source_symtab;
2355           default_line = current_source_line;
2356         }
2357
2358       if (**argptr == '+')
2359         sign = plus, (*argptr)++;
2360       else if (**argptr == '-')
2361         sign = minus, (*argptr)++;
2362       val.line = atoi (*argptr);
2363       switch (sign)
2364         {
2365         case plus:
2366           if (q == *argptr)
2367             val.line = 5;
2368           if (s == 0)
2369             val.line = default_line + val.line;
2370           break;
2371         case minus:
2372           if (q == *argptr)
2373             val.line = 15;
2374           if (s == 0)
2375             val.line = default_line - val.line;
2376           else
2377             val.line = 1;
2378           break;
2379         case none:
2380           break;        /* No need to adjust val.line.  */
2381         }
2382
2383       while (*q == ' ' || *q == '\t') q++;
2384       *argptr = q;
2385       if (s == 0)
2386         s = default_symtab;
2387       val.symtab = s;
2388       val.pc = 0;
2389       values.sals = (struct symtab_and_line *)
2390         xmalloc (sizeof (struct symtab_and_line));
2391       values.sals[0] = val;
2392       values.nelts = 1;
2393       if (need_canonical)
2394         build_canonical_line_spec (values.sals, NULL, canonical);
2395       return values;
2396     }
2397
2398   /* Arg token is not digits => try it as a variable name
2399      Find the next token (everything up to end or next whitespace).  */
2400
2401   if (**argptr == '$')          /* Convenience variable */
2402     p = skip_quoted (*argptr + 1);
2403   else if (is_quoted)
2404     {
2405       p = skip_quoted (*argptr);
2406       if (p[-1] != '\'')
2407         error ("Unmatched single quote.");
2408     }
2409   else if (has_parens)
2410     {
2411       p = pp+1;
2412     }
2413   else 
2414     {
2415       p = skip_quoted(*argptr);
2416     }
2417
2418   copy = (char *) alloca (p - *argptr + 1);
2419   memcpy (copy, *argptr, p - *argptr);
2420   copy[p - *argptr] = '\0';
2421   if (p != *argptr
2422       && copy[0]
2423       && copy[0] == copy [p - *argptr - 1]
2424       && strchr (gdb_completer_quote_characters, copy[0]) != NULL)
2425     {
2426       copy [p - *argptr - 1] = '\0';
2427       copy++;
2428     }
2429   while (*p == ' ' || *p == '\t') p++;
2430   *argptr = p;
2431
2432   /* See if it's a convenience variable */
2433
2434   if (*copy == '$')
2435     {
2436       value_ptr valx;
2437       int need_canonical = (s == 0) ? 1 : 0;
2438
2439       valx = value_of_internalvar (lookup_internalvar (copy + 1));
2440       if (TYPE_CODE (VALUE_TYPE (valx)) != TYPE_CODE_INT)
2441         error ("Convenience variables used in line specs must have integer values.");
2442
2443       val.symtab = s ? s : default_symtab;
2444       val.line = value_as_long (valx);
2445       val.pc = 0;
2446
2447       values.sals = (struct symtab_and_line *)xmalloc (sizeof val);
2448       values.sals[0] = val;
2449       values.nelts = 1;
2450
2451       if (need_canonical)
2452         build_canonical_line_spec (values.sals, NULL, canonical);
2453
2454       return values;
2455     }
2456
2457
2458   /* Look up that token as a variable.
2459      If file specified, use that file's per-file block to start with.  */
2460
2461   sym = lookup_symbol (copy,
2462                        (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
2463                         : get_selected_block ()),
2464                        VAR_NAMESPACE, 0, &sym_symtab);
2465
2466   if (sym != NULL)
2467     {
2468       if (SYMBOL_CLASS (sym) == LOC_BLOCK)
2469         {
2470           /* Arg is the name of a function */
2471           values.sals = (struct symtab_and_line *)
2472             xmalloc (sizeof (struct symtab_and_line));
2473           values.sals[0] = find_function_start_sal (sym, funfirstline);
2474           values.nelts = 1;
2475
2476           /* Don't use the SYMBOL_LINE; if used at all it points to
2477              the line containing the parameters or thereabouts, not
2478              the first line of code.  */
2479
2480           /* We might need a canonical line spec if it is a static
2481              function.  */
2482           if (s == 0)
2483             {
2484               struct blockvector *bv = BLOCKVECTOR (sym_symtab);
2485               struct block *b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
2486               if (lookup_block_symbol (b, copy, VAR_NAMESPACE) != NULL)
2487                 build_canonical_line_spec (values.sals, copy, canonical);
2488             }
2489           return values;
2490         }
2491       else
2492         {
2493           if (funfirstline)
2494             error ("\"%s\" is not a function", copy);
2495           else if (SYMBOL_LINE (sym) != 0)
2496             {
2497               /* We know its line number.  */
2498               values.sals = (struct symtab_and_line *)
2499                 xmalloc (sizeof (struct symtab_and_line));
2500               values.nelts = 1;
2501               memset (&values.sals[0], 0, sizeof (values.sals[0]));
2502               values.sals[0].symtab = sym_symtab;
2503               values.sals[0].line = SYMBOL_LINE (sym);
2504               return values;
2505             }
2506           else
2507             /* This can happen if it is compiled with a compiler which doesn't
2508                put out line numbers for variables.  */
2509             /* FIXME: Shouldn't we just set .line and .symtab to zero
2510                and return?  For example, "info line foo" could print
2511                the address.  */
2512             error ("Line number not known for symbol \"%s\"", copy);
2513         }
2514     }
2515
2516   msymbol = lookup_minimal_symbol (copy, NULL, NULL);
2517   if (msymbol != NULL)
2518     {
2519       val.pc      = SYMBOL_VALUE_ADDRESS (msymbol);
2520       val.section = SYMBOL_BFD_SECTION (msymbol);
2521       if (funfirstline)
2522         {
2523           val.pc += FUNCTION_START_OFFSET;
2524           SKIP_PROLOGUE (val.pc);
2525         }
2526       values.sals = (struct symtab_and_line *)
2527         xmalloc (sizeof (struct symtab_and_line));
2528       values.sals[0] = val;
2529       values.nelts = 1;
2530       return values;
2531     }
2532
2533   if (!have_full_symbols () &&
2534       !have_partial_symbols () && !have_minimal_symbols ())
2535     error (no_symtab_msg);
2536
2537   error ("Function \"%s\" not defined.", copy);
2538   return values;        /* for lint */
2539 }
2540
2541 struct symtabs_and_lines
2542 decode_line_spec (string, funfirstline)
2543      char *string;
2544      int funfirstline;
2545 {
2546   struct symtabs_and_lines sals;
2547   if (string == 0)
2548     error ("Empty line specification.");
2549   sals = decode_line_1 (&string, funfirstline,
2550                         current_source_symtab, current_source_line,
2551                         (char ***)NULL);
2552   if (*string)
2553     error ("Junk at end of line specification: %s", string);
2554   return sals;
2555 }
2556
2557 /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to
2558    operate on (ask user if necessary).
2559    If CANONICAL is non-NULL return a corresponding array of mangled names
2560    as canonical line specs there.  */
2561
2562 static struct symtabs_and_lines
2563 decode_line_2 (sym_arr, nelts, funfirstline, canonical)
2564      struct symbol *sym_arr[];
2565      int nelts;
2566      int funfirstline;
2567      char ***canonical;
2568 {
2569   struct symtabs_and_lines values, return_values;
2570   char *args, *arg1;
2571   int i;
2572   char *prompt;
2573   char *symname;
2574   struct cleanup *old_chain;
2575   char **canonical_arr = (char **)NULL;
2576
2577   values.sals = (struct symtab_and_line *) 
2578     alloca (nelts * sizeof(struct symtab_and_line));
2579   return_values.sals = (struct symtab_and_line *) 
2580     xmalloc (nelts * sizeof(struct symtab_and_line));
2581   old_chain = make_cleanup (free, return_values.sals);
2582
2583   if (canonical)
2584     {
2585       canonical_arr = (char **) xmalloc (nelts * sizeof (char *));
2586       make_cleanup (free, canonical_arr);
2587       memset (canonical_arr, 0, nelts * sizeof (char *));
2588       *canonical = canonical_arr;
2589     }
2590
2591   i = 0;
2592   printf_unfiltered("[0] cancel\n[1] all\n");
2593   while (i < nelts)
2594     {
2595       INIT_SAL (&return_values.sals[i]);        /* initialize to zeroes */
2596       INIT_SAL (&values.sals[i]);
2597       if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK)
2598         {
2599           values.sals[i] = find_function_start_sal (sym_arr[i], funfirstline);
2600           printf_unfiltered ("[%d] %s at %s:%d\n",
2601                              (i+2),
2602                              SYMBOL_SOURCE_NAME (sym_arr[i]),
2603                              values.sals[i].symtab->filename,
2604                              values.sals[i].line);
2605         }
2606       else
2607         printf_unfiltered ("?HERE\n");
2608       i++;
2609     }
2610   
2611   if ((prompt = getenv ("PS2")) == NULL)
2612     {
2613       prompt = ">";
2614     }
2615   printf_unfiltered("%s ",prompt);
2616   gdb_flush(gdb_stdout);
2617
2618   args = command_line_input ((char *) NULL, 0, "overload-choice");
2619   
2620   if (args == 0 || *args == 0)
2621     error_no_arg ("one or more choice numbers");
2622
2623   i = 0;
2624   while (*args)
2625     {
2626       int num;
2627
2628       arg1 = args;
2629       while (*arg1 >= '0' && *arg1 <= '9') arg1++;
2630       if (*arg1 && *arg1 != ' ' && *arg1 != '\t')
2631         error ("Arguments must be choice numbers.");
2632
2633       num = atoi (args);
2634
2635       if (num == 0)
2636         error ("cancelled");
2637       else if (num == 1)
2638         {
2639           if (canonical_arr)
2640             {
2641               for (i = 0; i < nelts; i++)
2642                 {
2643                   if (canonical_arr[i] == NULL)
2644                     {
2645                       symname = SYMBOL_NAME (sym_arr[i]);
2646                       canonical_arr[i] = savestring (symname, strlen (symname));
2647                     }
2648                 }
2649             }
2650           memcpy (return_values.sals, values.sals,
2651                   (nelts * sizeof(struct symtab_and_line)));
2652           return_values.nelts = nelts;
2653           discard_cleanups (old_chain);
2654           return return_values;
2655         }
2656
2657       if (num >= nelts + 2)
2658         {
2659           printf_unfiltered ("No choice number %d.\n", num);
2660         }
2661       else
2662         {
2663           num -= 2;
2664           if (values.sals[num].pc)
2665             {
2666               if (canonical_arr)
2667                 {
2668                   symname = SYMBOL_NAME (sym_arr[num]);
2669                   make_cleanup (free, symname);
2670                   canonical_arr[i] = savestring (symname, strlen (symname));
2671                 }
2672               return_values.sals[i++] = values.sals[num];
2673               values.sals[num].pc = 0;
2674             }
2675           else
2676             {
2677               printf_unfiltered ("duplicate request for %d ignored.\n", num);
2678             }
2679         }
2680
2681       args = arg1;
2682       while (*args == ' ' || *args == '\t') args++;
2683     }
2684   return_values.nelts = i;
2685   discard_cleanups (old_chain);
2686   return return_values;
2687 }
2688
2689 \f
2690 /* Slave routine for sources_info.  Force line breaks at ,'s.
2691    NAME is the name to print and *FIRST is nonzero if this is the first
2692    name printed.  Set *FIRST to zero.  */
2693 static void
2694 output_source_filename (name, first)
2695      char *name;
2696      int *first;
2697 {
2698   /* Table of files printed so far.  Since a single source file can
2699      result in several partial symbol tables, we need to avoid printing
2700      it more than once.  Note: if some of the psymtabs are read in and
2701      some are not, it gets printed both under "Source files for which
2702      symbols have been read" and "Source files for which symbols will
2703      be read in on demand".  I consider this a reasonable way to deal
2704      with the situation.  I'm not sure whether this can also happen for
2705      symtabs; it doesn't hurt to check.  */
2706   static char **tab = NULL;
2707   /* Allocated size of tab in elements.
2708      Start with one 256-byte block (when using GNU malloc.c).
2709      24 is the malloc overhead when range checking is in effect.  */
2710   static int tab_alloc_size = (256 - 24) / sizeof (char *);
2711   /* Current size of tab in elements.  */
2712   static int tab_cur_size;
2713
2714   char **p;
2715
2716   if (*first)
2717     {
2718       if (tab == NULL)
2719         tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab));
2720       tab_cur_size = 0;
2721     }
2722
2723   /* Is NAME in tab?  */
2724   for (p = tab; p < tab + tab_cur_size; p++)
2725     if (STREQ (*p, name))
2726       /* Yes; don't print it again.  */
2727       return;
2728   /* No; add it to tab.  */
2729   if (tab_cur_size == tab_alloc_size)
2730     {
2731       tab_alloc_size *= 2;
2732       tab = (char **) xrealloc ((char *) tab, tab_alloc_size * sizeof (*tab));
2733     }
2734   tab[tab_cur_size++] = name;
2735
2736   if (*first)
2737     {
2738       *first = 0;
2739     }
2740   else
2741     {
2742       printf_filtered (", ");
2743     }
2744
2745   wrap_here ("");
2746   fputs_filtered (name, gdb_stdout);
2747 }  
2748
2749 static void
2750 sources_info (ignore, from_tty)
2751      char *ignore;
2752      int from_tty;
2753 {
2754   register struct symtab *s;
2755   register struct partial_symtab *ps;
2756   register struct objfile *objfile;
2757   int first;
2758   
2759   if (!have_full_symbols () && !have_partial_symbols ())
2760     {
2761       error (no_symtab_msg);
2762     }
2763   
2764   printf_filtered ("Source files for which symbols have been read in:\n\n");
2765
2766   first = 1;
2767   ALL_SYMTABS (objfile, s)
2768     {
2769       output_source_filename (s -> filename, &first);
2770     }
2771   printf_filtered ("\n\n");
2772   
2773   printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2774
2775   first = 1;
2776   ALL_PSYMTABS (objfile, ps)
2777     {
2778       if (!ps->readin)
2779         {
2780           output_source_filename (ps -> filename, &first);
2781         }
2782     }
2783   printf_filtered ("\n");
2784 }
2785
2786 /* List all symbols (if REGEXP is NULL) or all symbols matching REGEXP.
2787    If CLASS is zero, list all symbols except functions, type names, and
2788                      constants (enums).
2789    If CLASS is 1, list only functions.
2790    If CLASS is 2, list only type names.
2791    If CLASS is 3, list only method names.
2792
2793    BPT is non-zero if we should set a breakpoint at the functions
2794    we find.  */
2795
2796 static void
2797 list_symbols (regexp, class, bpt, from_tty)
2798      char *regexp;
2799      int class;
2800      int bpt;
2801      int from_tty;
2802 {
2803   register struct symtab *s;
2804   register struct partial_symtab *ps;
2805   register struct blockvector *bv;
2806   struct blockvector *prev_bv = 0;
2807   register struct block *b;
2808   register int i, j;
2809   register struct symbol *sym;
2810   struct partial_symbol **psym;
2811   struct objfile *objfile;
2812   struct minimal_symbol *msymbol;
2813   char *val;
2814   static char *classnames[]
2815     = {"variable", "function", "type", "method"};
2816   int found_in_file = 0;
2817   int found_misc = 0;
2818   static enum minimal_symbol_type types[]
2819     = {mst_data, mst_text, mst_abs, mst_unknown};
2820   static enum minimal_symbol_type types2[]
2821     = {mst_bss,  mst_file_text, mst_abs, mst_unknown};
2822   static enum minimal_symbol_type types3[]
2823     = {mst_file_data,  mst_solib_trampoline, mst_abs, mst_unknown};
2824   static enum minimal_symbol_type types4[]
2825     = {mst_file_bss,   mst_text, mst_abs, mst_unknown};
2826   enum minimal_symbol_type ourtype = types[class];
2827   enum minimal_symbol_type ourtype2 = types2[class];
2828   enum minimal_symbol_type ourtype3 = types3[class];
2829   enum minimal_symbol_type ourtype4 = types4[class];
2830
2831   if (regexp != NULL)
2832     {
2833       /* Make sure spacing is right for C++ operators.
2834          This is just a courtesy to make the matching less sensitive
2835          to how many spaces the user leaves between 'operator'
2836          and <TYPENAME> or <OPERATOR>. */
2837       char *opend;
2838       char *opname = operator_chars (regexp, &opend);
2839       if (*opname)
2840         {
2841           int fix = -1; /* -1 means ok; otherwise number of spaces needed. */
2842           if (isalpha(*opname) || *opname == '_' || *opname == '$')
2843             {
2844               /* There should 1 space between 'operator' and 'TYPENAME'. */
2845               if (opname[-1] != ' ' || opname[-2] == ' ')
2846                 fix = 1;
2847             }
2848           else
2849             {
2850               /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2851               if (opname[-1] == ' ')
2852                 fix = 0;
2853             }
2854           /* If wrong number of spaces, fix it. */
2855           if (fix >= 0)
2856             {
2857               char *tmp = (char*) alloca(opend-opname+10);
2858               sprintf(tmp, "operator%.*s%s", fix, " ", opname);
2859               regexp = tmp;
2860             }
2861         }
2862       
2863       if (0 != (val = re_comp (regexp)))
2864         error ("Invalid regexp (%s): %s", val, regexp);
2865     }
2866
2867   /* Search through the partial symtabs *first* for all symbols
2868      matching the regexp.  That way we don't have to reproduce all of
2869      the machinery below. */
2870
2871   ALL_PSYMTABS (objfile, ps)
2872     {
2873       struct partial_symbol **bound, **gbound, **sbound;
2874       int keep_going = 1;
2875       
2876       if (ps->readin) continue;
2877       
2878       gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms;
2879       sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms;
2880       bound = gbound;
2881       
2882       /* Go through all of the symbols stored in a partial
2883          symtab in one loop. */
2884       psym = objfile->global_psymbols.list + ps->globals_offset;
2885       while (keep_going)
2886         {
2887           if (psym >= bound)
2888             {
2889               if (bound == gbound && ps->n_static_syms != 0)
2890                 {
2891                   psym = objfile->static_psymbols.list + ps->statics_offset;
2892                   bound = sbound;
2893                 }
2894               else
2895                 keep_going = 0;
2896               continue;
2897             }
2898           else
2899             {
2900               QUIT;
2901
2902               /* If it would match (logic taken from loop below)
2903                  load the file and go on to the next one */
2904               if ((regexp == NULL || SYMBOL_MATCHES_REGEXP (*psym))
2905                   && ((class == 0 && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
2906                        && SYMBOL_CLASS (*psym) != LOC_BLOCK)
2907                       || (class == 1 && SYMBOL_CLASS (*psym) == LOC_BLOCK)
2908                       || (class == 2 && SYMBOL_CLASS (*psym) == LOC_TYPEDEF)
2909                       || (class == 3 && SYMBOL_CLASS (*psym) == LOC_BLOCK)))
2910                 {
2911                   PSYMTAB_TO_SYMTAB(ps);
2912                   keep_going = 0;
2913                 }
2914             }
2915           psym++;
2916         }
2917     }
2918
2919   /* Here, we search through the minimal symbol tables for functions
2920      and variables that match, and force their symbols to be read.
2921      This is in particular necessary for demangled variable names,
2922      which are no longer put into the partial symbol tables.
2923      The symbol will then be found during the scan of symtabs below.
2924
2925      For functions, find_pc_symtab should succeed if we have debug info
2926      for the function, for variables we have to call lookup_symbol
2927      to determine if the variable has debug info.
2928      If the lookup fails, set found_misc so that we will rescan to print
2929      any matching symbols without debug info.
2930   */
2931
2932   if (class == 0 || class == 1)
2933     {
2934       ALL_MSYMBOLS (objfile, msymbol)
2935         {
2936           if (MSYMBOL_TYPE (msymbol) == ourtype ||
2937               MSYMBOL_TYPE (msymbol) == ourtype2 ||
2938               MSYMBOL_TYPE (msymbol) == ourtype3 ||
2939               MSYMBOL_TYPE (msymbol) == ourtype4)
2940             {
2941               if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol))
2942                 {
2943                   if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)))
2944                     {
2945                       if (class == 1
2946                           || lookup_symbol (SYMBOL_NAME (msymbol), 
2947                                             (struct block *) NULL,
2948                                             VAR_NAMESPACE,
2949                                             0, (struct symtab **) NULL) == NULL)
2950                         found_misc = 1;
2951                     }
2952                 }
2953             }
2954         }
2955     }
2956
2957   /* Printout here so as to get after the "Reading in symbols"
2958      messages which will be generated above.  */
2959   if (!bpt)
2960     printf_filtered (regexp
2961           ? "All %ss matching regular expression \"%s\":\n"
2962           : "All defined %ss:\n",
2963           classnames[class],
2964           regexp);
2965
2966   ALL_SYMTABS (objfile, s)
2967     {
2968       found_in_file = 0;
2969       bv = BLOCKVECTOR (s);
2970       /* Often many files share a blockvector.
2971          Scan each blockvector only once so that
2972          we don't get every symbol many times.
2973          It happens that the first symtab in the list
2974          for any given blockvector is the main file.  */
2975       if (bv != prev_bv)
2976         for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
2977           {
2978             b = BLOCKVECTOR_BLOCK (bv, i);
2979             /* Skip the sort if this block is always sorted.  */
2980             if (!BLOCK_SHOULD_SORT (b))
2981               sort_block_syms (b);
2982             for (j = 0; j < BLOCK_NSYMS (b); j++)
2983               {
2984                 QUIT;
2985                 sym = BLOCK_SYM (b, j);
2986                 if ((regexp == NULL || SYMBOL_MATCHES_REGEXP (sym))
2987                     && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
2988                          && SYMBOL_CLASS (sym) != LOC_BLOCK
2989                          && SYMBOL_CLASS (sym) != LOC_CONST)
2990                         || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)
2991                         || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2992                         || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK)))
2993                   {
2994                     if (bpt)
2995                       {
2996                         /* Set a breakpoint here, if it's a function */
2997                         if (class == 1)
2998                           {
2999                             /* There may be more than one function with the
3000                                same name but in different files.  In order to
3001                                set breakpoints on all of them, we must give
3002                                both the file name and the function name to
3003                                break_command.
3004                                Quoting the symbol name gets rid of problems
3005                                with mangled symbol names that contain
3006                                CPLUS_MARKER characters.  */
3007                             char *string =
3008                               (char *) alloca (strlen (s->filename)
3009                                                + strlen (SYMBOL_NAME(sym))
3010                                                + 4);
3011                             strcpy (string, s->filename);
3012                             strcat (string, ":'");
3013                             strcat (string, SYMBOL_NAME(sym));
3014                             strcat (string, "'");
3015                             break_command (string, from_tty);
3016                           }
3017                       }
3018                     else if (!found_in_file)
3019                       {
3020                         fputs_filtered ("\nFile ", gdb_stdout);
3021                         fputs_filtered (s->filename, gdb_stdout);
3022                         fputs_filtered (":\n", gdb_stdout);
3023                       }
3024                     found_in_file = 1;
3025                     
3026                     if (class != 2 && i == STATIC_BLOCK)
3027                       printf_filtered ("static ");
3028                     
3029                     /* Typedef that is not a C++ class */
3030                     if (class == 2
3031                         && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
3032                       c_typedef_print (SYMBOL_TYPE(sym), sym, gdb_stdout);
3033                     /* variable, func, or typedef-that-is-c++-class */
3034                     else if (class < 2 || 
3035                              (class == 2 && 
3036                               SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE))
3037                       {
3038                         type_print (SYMBOL_TYPE (sym),
3039                                     (SYMBOL_CLASS (sym) == LOC_TYPEDEF
3040                                      ? "" : SYMBOL_SOURCE_NAME (sym)),
3041                                     gdb_stdout, 0);
3042                         
3043                         printf_filtered (";\n");
3044                       }
3045                     else
3046                       {
3047 # if 0
3048 /* Tiemann says: "info methods was never implemented."  */
3049                         char *demangled_name;
3050                         c_type_print_base (TYPE_FN_FIELD_TYPE(t, i),
3051                                            gdb_stdout, 0, 0); 
3052                         c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i),
3053                                                      gdb_stdout, 0); 
3054                         if (TYPE_FN_FIELD_STUB (t, i))
3055                           check_stub_method (TYPE_DOMAIN_TYPE (type), j, i);
3056                         demangled_name =
3057                           cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t, i),
3058                                           DMGL_ANSI | DMGL_PARAMS);
3059                         if (demangled_name == NULL)
3060                           fprintf_filtered (stream, "<badly mangled name %s>",
3061                                             TYPE_FN_FIELD_PHYSNAME (t, i));
3062                         else
3063                           {
3064                             fputs_filtered (demangled_name, stream);
3065                             free (demangled_name);
3066                           }
3067 # endif
3068                       }
3069                   }
3070               }
3071           }
3072       prev_bv = bv;
3073     }
3074
3075   /* If there are no eyes, avoid all contact.  I mean, if there are
3076      no debug symbols, then print directly from the msymbol_vector.  */
3077
3078   if (found_misc || class != 1)
3079     {
3080       found_in_file = 0;
3081       ALL_MSYMBOLS (objfile, msymbol)
3082         {
3083           if (MSYMBOL_TYPE (msymbol) == ourtype ||
3084               MSYMBOL_TYPE (msymbol) == ourtype2 ||
3085               MSYMBOL_TYPE (msymbol) == ourtype3 ||
3086               MSYMBOL_TYPE (msymbol) == ourtype4)
3087             {
3088               if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol))
3089                 {
3090                   /* Functions:  Look up by address. */
3091                   if (class != 1 ||
3092                       (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol))))
3093                     {
3094                       /* Variables/Absolutes:  Look up by name */
3095                       if (lookup_symbol (SYMBOL_NAME (msymbol), 
3096                                          (struct block *) NULL, VAR_NAMESPACE,
3097                                          0, (struct symtab **) NULL) == NULL)
3098                         {
3099                           if (bpt)
3100                             {
3101                               break_command (SYMBOL_NAME (msymbol), from_tty);
3102                               printf_filtered ("<function, no debug info> %s;\n",
3103                                                SYMBOL_SOURCE_NAME (msymbol));
3104                               continue;
3105                             }
3106                           if (!found_in_file)
3107                             {
3108                               printf_filtered ("\nNon-debugging symbols:\n");
3109                               found_in_file = 1;
3110                             }
3111                           printf_filtered ("    %08lx  %s\n",
3112                                            (unsigned long) SYMBOL_VALUE_ADDRESS (msymbol),
3113                                            SYMBOL_SOURCE_NAME (msymbol));
3114                         }
3115                     }
3116                 }
3117             }
3118         }
3119     }
3120 }
3121
3122 static void
3123 variables_info (regexp, from_tty)
3124      char *regexp;
3125      int from_tty;
3126 {
3127   list_symbols (regexp, 0, 0, from_tty);
3128 }
3129
3130 static void
3131 functions_info (regexp, from_tty)
3132      char *regexp;
3133      int from_tty;
3134 {
3135   list_symbols (regexp, 1, 0, from_tty);
3136 }
3137
3138 static void
3139 types_info (regexp, from_tty)
3140      char *regexp;
3141      int from_tty;
3142 {
3143   list_symbols (regexp, 2, 0, from_tty);
3144 }
3145
3146 #if 0
3147 /* Tiemann says: "info methods was never implemented."  */
3148 static void
3149 methods_info (regexp)
3150      char *regexp;
3151 {
3152   list_symbols (regexp, 3, 0, from_tty);
3153 }
3154 #endif /* 0 */
3155
3156 /* Breakpoint all functions matching regular expression. */
3157 static void
3158 rbreak_command (regexp, from_tty)
3159      char *regexp;
3160      int from_tty;
3161 {
3162   list_symbols (regexp, 1, 1, from_tty);
3163 }
3164 \f
3165
3166 /* Return Nonzero if block a is lexically nested within block b,
3167    or if a and b have the same pc range.
3168    Return zero otherwise. */
3169 int
3170 contained_in (a, b)
3171      struct block *a, *b;
3172 {
3173   if (!a || !b)
3174     return 0;
3175   return BLOCK_START (a) >= BLOCK_START (b)
3176       && BLOCK_END (a)   <= BLOCK_END (b);
3177 }
3178
3179 \f
3180 /* Helper routine for make_symbol_completion_list.  */
3181
3182 static int return_val_size;
3183 static int return_val_index;
3184 static char **return_val;
3185
3186 #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
3187   do { \
3188     if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \
3189       /* Put only the mangled name on the list.  */ \
3190       /* Advantage:  "b foo<TAB>" completes to "b foo(int, int)" */ \
3191       /* Disadvantage:  "b foo__i<TAB>" doesn't complete.  */ \
3192       completion_list_add_name \
3193         (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \
3194     else \
3195       completion_list_add_name \
3196         (SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \
3197   } while (0)
3198
3199 /*  Test to see if the symbol specified by SYMNAME (which is already
3200     demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3201     characters.  If so, add it to the current completion list. */
3202
3203 static void
3204 completion_list_add_name (symname, sym_text, sym_text_len, text, word)
3205      char *symname;
3206      char *sym_text;
3207      int sym_text_len;
3208      char *text;
3209      char *word;
3210 {
3211   int newsize;
3212   int i;
3213
3214   /* clip symbols that cannot match */
3215
3216   if (strncmp (symname, sym_text, sym_text_len) != 0)
3217     {
3218       return;
3219     }
3220
3221   /* Clip any symbol names that we've already considered.  (This is a
3222      time optimization)  */
3223
3224   for (i = 0; i < return_val_index; ++i)
3225     {
3226       if (STREQ (symname, return_val[i]))
3227         {
3228           return;
3229         }
3230     }
3231   
3232   /* We have a match for a completion, so add SYMNAME to the current list
3233      of matches. Note that the name is moved to freshly malloc'd space. */
3234
3235   {
3236     char *new;
3237     if (word == sym_text)
3238       {
3239         new = xmalloc (strlen (symname) + 5);
3240         strcpy (new, symname);
3241       }
3242     else if (word > sym_text)
3243       {
3244         /* Return some portion of symname.  */
3245         new = xmalloc (strlen (symname) + 5);
3246         strcpy (new, symname + (word - sym_text));
3247       }
3248     else
3249       {
3250         /* Return some of SYM_TEXT plus symname.  */
3251         new = xmalloc (strlen (symname) + (sym_text - word) + 5);
3252         strncpy (new, word, sym_text - word);
3253         new[sym_text - word] = '\0';
3254         strcat (new, symname);
3255       }
3256
3257     /* Recheck for duplicates if we intend to add a modified symbol.  */
3258     if (word != sym_text)
3259       {
3260         for (i = 0; i < return_val_index; ++i)
3261           {
3262             if (STREQ (new, return_val[i]))
3263               {
3264                 free (new);
3265                 return;
3266               }
3267           }
3268       }
3269
3270     if (return_val_index + 3 > return_val_size)
3271       {
3272         newsize = (return_val_size *= 2) * sizeof (char *);
3273         return_val = (char **) xrealloc ((char *) return_val, newsize);
3274       }
3275     return_val[return_val_index++] = new;
3276     return_val[return_val_index] = NULL;
3277   }
3278 }
3279
3280 /* Return a NULL terminated array of all symbols (regardless of class) which
3281    begin by matching TEXT.  If the answer is no symbols, then the return value
3282    is an array which contains only a NULL pointer.
3283
3284    Problem: All of the symbols have to be copied because readline frees them.
3285    I'm not going to worry about this; hopefully there won't be that many.  */
3286
3287 char **
3288 make_symbol_completion_list (text, word)
3289      char *text;
3290      char *word;
3291 {
3292   register struct symbol *sym;
3293   register struct symtab *s;
3294   register struct partial_symtab *ps;
3295   register struct minimal_symbol *msymbol;
3296   register struct objfile *objfile;
3297   register struct block *b, *surrounding_static_block = 0;
3298   register int i, j;
3299   struct partial_symbol **psym;
3300   /* The symbol we are completing on.  Points in same buffer as text.  */
3301   char *sym_text;
3302   /* Length of sym_text.  */
3303   int sym_text_len;
3304
3305   /* Now look for the symbol we are supposed to complete on.
3306      FIXME: This should be language-specific.  */
3307   {
3308     char *p;
3309     char quote_found;
3310     char *quote_pos = NULL;
3311
3312     /* First see if this is a quoted string.  */
3313     quote_found = '\0';
3314     for (p = text; *p != '\0'; ++p)
3315       {
3316         if (quote_found != '\0')
3317           {
3318             if (*p == quote_found)
3319               /* Found close quote.  */
3320               quote_found = '\0';
3321             else if (*p == '\\' && p[1] == quote_found)
3322               /* A backslash followed by the quote character
3323                  doesn't end the string.  */
3324               ++p;
3325           }
3326         else if (*p == '\'' || *p == '"')
3327           {
3328             quote_found = *p;
3329             quote_pos = p;
3330           }
3331       }
3332     if (quote_found == '\'')
3333       /* A string within single quotes can be a symbol, so complete on it.  */
3334       sym_text = quote_pos + 1;
3335     else if (quote_found == '"')
3336       /* A double-quoted string is never a symbol, nor does it make sense
3337          to complete it any other way.  */
3338       return NULL;
3339     else
3340       {
3341         /* It is not a quoted string.  Break it based on the characters
3342            which are in symbols.  */
3343         while (p > text)
3344           {
3345             if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
3346               --p;
3347             else
3348               break;
3349           }
3350         sym_text = p;
3351       }
3352   }
3353
3354   sym_text_len = strlen (sym_text);
3355
3356   return_val_size = 100;
3357   return_val_index = 0;
3358   return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
3359   return_val[0] = NULL;
3360
3361   /* Look through the partial symtabs for all symbols which begin
3362      by matching SYM_TEXT.  Add each one that you find to the list.  */
3363
3364   ALL_PSYMTABS (objfile, ps)
3365     {
3366       /* If the psymtab's been read in we'll get it when we search
3367          through the blockvector.  */
3368       if (ps->readin) continue;
3369       
3370       for (psym = objfile->global_psymbols.list + ps->globals_offset;
3371            psym < (objfile->global_psymbols.list + ps->globals_offset
3372                    + ps->n_global_syms);
3373            psym++)
3374         {
3375           /* If interrupted, then quit. */
3376           QUIT;
3377           COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word);
3378         }
3379       
3380       for (psym = objfile->static_psymbols.list + ps->statics_offset;
3381            psym < (objfile->static_psymbols.list + ps->statics_offset
3382                    + ps->n_static_syms);
3383            psym++)
3384         {
3385           QUIT;
3386           COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word);
3387         }
3388     }
3389
3390   /* At this point scan through the misc symbol vectors and add each
3391      symbol you find to the list.  Eventually we want to ignore
3392      anything that isn't a text symbol (everything else will be
3393      handled by the psymtab code above).  */
3394
3395   ALL_MSYMBOLS (objfile, msymbol)
3396     {
3397       QUIT;
3398       COMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text, word);
3399     }
3400
3401   /* Search upwards from currently selected frame (so that we can
3402      complete on local vars.  */
3403
3404   for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b))
3405     {
3406       if (!BLOCK_SUPERBLOCK (b))
3407         {
3408           surrounding_static_block = b;         /* For elmin of dups */
3409         }
3410       
3411       /* Also catch fields of types defined in this places which match our
3412          text string.  Only complete on types visible from current context. */
3413
3414       for (i = 0; i < BLOCK_NSYMS (b); i++)
3415         {
3416           sym = BLOCK_SYM (b, i);
3417           COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3418           if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
3419             {
3420               struct type *t = SYMBOL_TYPE (sym);
3421               enum type_code c = TYPE_CODE (t);
3422
3423               if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
3424                 {
3425                   for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
3426                     {
3427                       if (TYPE_FIELD_NAME (t, j))
3428                         {
3429                           completion_list_add_name (TYPE_FIELD_NAME (t, j),
3430                                                       sym_text, sym_text_len, text, word);
3431                         }
3432                     }
3433                 }
3434             }
3435         }
3436     }
3437
3438   /* Go through the symtabs and check the externs and statics for
3439      symbols which match.  */
3440
3441   ALL_SYMTABS (objfile, s)
3442     {
3443       QUIT;
3444       b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
3445       for (i = 0; i < BLOCK_NSYMS (b); i++)
3446         {
3447           sym = BLOCK_SYM (b, i);
3448           COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3449         }
3450     }
3451
3452   ALL_SYMTABS (objfile, s)
3453     {
3454       QUIT;
3455       b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
3456       /* Don't do this block twice.  */
3457       if (b == surrounding_static_block) continue;
3458       for (i = 0; i < BLOCK_NSYMS (b); i++)
3459         {
3460           sym = BLOCK_SYM (b, i);
3461           COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3462         }
3463     }
3464
3465   return (return_val);
3466 }
3467
3468 /* Determine if PC is in the prologue of a function.  The prologue is the area
3469    between the first instruction of a function, and the first executable line.
3470    Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
3471
3472    If non-zero, func_start is where we think the prologue starts, possibly
3473    by previous examination of symbol table information.
3474  */
3475
3476 int
3477 in_prologue (pc, func_start)
3478      CORE_ADDR pc;
3479      CORE_ADDR func_start;
3480 {
3481   struct symtab_and_line sal;
3482   CORE_ADDR func_addr, func_end;
3483
3484   if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
3485     goto nosyms;                /* Might be in prologue */
3486
3487   sal = find_pc_line (func_addr, 0);
3488
3489   if (sal.line == 0)
3490     goto nosyms;
3491
3492   if (sal.end > func_addr
3493       && sal.end <= func_end)   /* Is prologue in function? */
3494     return pc < sal.end;        /* Yes, is pc in prologue? */
3495
3496   /* The line after the prologue seems to be outside the function.  In this
3497      case, tell the caller to find the prologue the hard way.  */
3498
3499   return 1;
3500
3501 /* Come here when symtabs don't contain line # info.  In this case, it is
3502    likely that the user has stepped into a library function w/o symbols, or
3503    is doing a stepi/nexti through code without symbols.  */
3504
3505  nosyms:
3506
3507 /* If func_start is zero (meaning unknown) then we don't know whether pc is
3508    in the prologue or not.  I.E. it might be. */
3509
3510   if (!func_start) return 1;
3511
3512 /* We need to call the target-specific prologue skipping functions with the
3513    function's start address because PC may be pointing at an instruction that
3514    could be mistakenly considered part of the prologue.  */
3515
3516   SKIP_PROLOGUE (func_start);
3517
3518   return pc < func_start;
3519 }
3520
3521 \f
3522 void
3523 _initialize_symtab ()
3524 {
3525   add_info ("variables", variables_info,
3526             "All global and static variable names, or those matching REGEXP.");
3527   add_info ("functions", functions_info,
3528             "All function names, or those matching REGEXP.");
3529
3530   /* FIXME:  This command has at least the following problems:
3531      1.  It prints builtin types (in a very strange and confusing fashion).
3532      2.  It doesn't print right, e.g. with
3533          typedef struct foo *FOO
3534          type_print prints "FOO" when we want to make it (in this situation)
3535          print "struct foo *".
3536      I also think "ptype" or "whatis" is more likely to be useful (but if
3537      there is much disagreement "info types" can be fixed).  */
3538   add_info ("types", types_info,
3539             "All type names, or those matching REGEXP.");
3540
3541 #if 0
3542   add_info ("methods", methods_info,
3543             "All method names, or those matching REGEXP::REGEXP.\n\
3544 If the class qualifier is omitted, it is assumed to be the current scope.\n\
3545 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
3546 are listed.");
3547 #endif
3548   add_info ("sources", sources_info,
3549             "Source files in the program.");
3550
3551   add_com ("rbreak", class_breakpoint, rbreak_command,
3552             "Set a breakpoint for all functions matching REGEXP.");
3553
3554   /* Initialize the one built-in type that isn't language dependent... */
3555   builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0,
3556                                   "<unknown type>", (struct objfile *) NULL);
3557 }