f5f0455f95b652d0ad23199fbd504ec27ef830dc
[external/binutils.git] / gdb / symtab.c
1 /* Symbol table lookup for the GNU debugger, GDB.
2    Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
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., 675 Mass Ave, Cambridge, MA 02139, 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 "regex.h"
33 #include "expression.h"
34 #include "language.h"
35 #include "demangle.h"
36
37 #include <obstack.h>
38 #include <assert.h>
39
40 #include <sys/types.h>
41 #include <fcntl.h>
42 #include <string.h>
43 #include <sys/stat.h>
44 #include <ctype.h>
45
46 /* Prototypes for local functions */
47
48 static char *
49 expensive_mangler PARAMS ((const char *));
50
51 extern int
52 find_methods PARAMS ((struct type *, char *, char **, struct symbol **));
53
54 static void
55 completion_list_add_symbol PARAMS ((char *, char *, int));
56
57 static struct symtabs_and_lines
58 decode_line_2 PARAMS ((struct symbol *[], int, int));
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));
77
78 static void
79 output_source_filename PARAMS ((char *, int *));
80
81 static char *
82 operator_chars PARAMS ((char *, char **));
83
84 static int
85 find_line_common PARAMS ((struct linetable *, int, int *));
86
87 static struct partial_symbol *
88 lookup_partial_symbol PARAMS ((struct partial_symtab *, const char *,
89                                int, enum namespace));
90
91 static struct partial_symbol *
92 lookup_demangled_partial_symbol PARAMS ((const struct partial_symtab *,
93                                          const char *));
94
95 static struct symbol *
96 lookup_demangled_block_symbol PARAMS ((const struct block *, const char *));
97
98 static struct symtab *
99 lookup_symtab_1 PARAMS ((char *));
100
101 /* */
102
103 /* The single non-language-specific builtin type */
104 struct type *builtin_type_error;
105
106 /* Block in which the most recently searched-for symbol was found.
107    Might be better to make this a parameter to lookup_symbol and 
108    value_of_this. */
109
110 const struct block *block_found;
111
112 char no_symtab_msg[] = "No symbol table is loaded.  Use the \"file\" command.";
113
114 /* While the C++ support is still in flux, issue a possibly helpful hint on
115    using the new command completion feature on single quoted demangled C++
116    symbols.  Remove when loose ends are cleaned up.   FIXME -fnf */
117
118 void
119 cplusplus_hint (name)
120      char *name;
121 {
122   printf ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name, name);
123   printf ("(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 (strcmp (name, s->filename) == 0)
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 (strcmp (p, name) == 0)
161           return s;
162       }
163
164   /* Same search rules as above apply here, but now we look thru the
165      psymtabs.  */
166
167   ALL_PSYMTABS (objfile, ps)
168     if (strcmp (name, ps -> filename) == 0)
169       goto got_psymtab;
170
171   if (!slash)
172     ALL_PSYMTABS (objfile, ps)
173       {
174         char *p = ps -> filename;
175         char *tail = strrchr (p, '/');
176
177         if (tail)
178           p = tail + 1;
179
180         if (strcmp (p, name) == 0)
181           goto got_psymtab;
182       }
183
184   return (NULL);
185
186  got_psymtab:
187
188   if (ps -> readin)
189     error ("Internal: readin %s pst for `%s' found when no symtab found.",
190            ps -> filename, name);
191
192   s = PSYMTAB_TO_SYMTAB (ps);
193
194   if (s)
195     return s;
196
197   /* At this point, we have located the psymtab for this file, but
198      the conversion to a symtab has failed.  This usually happens
199      when we are looking up an include file.  In this case,
200      PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
201      been created.  So, we need to run through the symtabs again in
202      order to find the file.
203      XXX - This is a crock, and should be fixed inside of the the
204      symbol parsing routines. */
205   goto got_symtab;
206 }
207
208 /* Lookup the symbol table of a source file named NAME.  Try a couple
209    of variations if the first lookup doesn't work.  */
210
211 struct symtab *
212 lookup_symtab (name)
213      char *name;
214 {
215   register struct symtab *s;
216   register char *copy;
217
218   s = lookup_symtab_1 (name);
219   if (s) return s;
220
221   /* If name not found as specified, see if adding ".c" helps.  */
222
223   copy = (char *) alloca (strlen (name) + 3);
224   strcpy (copy, name);
225   strcat (copy, ".c");
226   s = lookup_symtab_1 (copy);
227   if (s) return s;
228
229   /* We didn't find anything; die.  */
230   return 0;
231 }
232
233 /* Lookup the partial symbol table of a source file named NAME.  This
234    only returns true on an exact match (ie. this semantics are
235    different from lookup_symtab.  */
236
237 struct partial_symtab *
238 lookup_partial_symtab (name)
239 char *name;
240 {
241   register struct partial_symtab *pst;
242   register struct objfile *objfile;
243   
244   ALL_PSYMTABS (objfile, pst)
245     {
246       if (strcmp (name, pst -> filename) == 0)
247         {
248           return (pst);
249         }
250     }
251   return (NULL);
252 }
253 \f
254 /* Demangle a GDB method stub type.  */
255 char *
256 gdb_mangle_name (type, i, j)
257      struct type *type;
258      int i, j;
259 {
260   int mangled_name_len;
261   char *mangled_name;
262   struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
263   struct fn_field *method = &f[j];
264   char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
265   char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
266   char *newname = type_name_no_tag (type);
267   int is_constructor = strcmp(field_name, newname) == 0;
268   int is_destructor = is_constructor && physname[0] == '_'
269       && physname[1] == CPLUS_MARKER && physname[2] == '_';
270   /* Need a new type prefix.  */
271   char *const_prefix = method->is_const ? "C" : "";
272   char *volatile_prefix = method->is_volatile ? "V" : "";
273   char buf[20];
274 #ifndef GCC_MANGLE_BUG
275   int len = strlen (newname);
276
277   if (is_destructor)
278     {
279       mangled_name = (char*) xmalloc(strlen(physname)+1);
280       strcpy(mangled_name, physname);
281       return mangled_name;
282     }
283
284   sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
285   mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
286                           + strlen (buf) + len
287                           + strlen (physname)
288                           + 1);
289
290   /* Only needed for GNU-mangled names.  ANSI-mangled names
291      work with the normal mechanisms.  */
292   if (OPNAME_PREFIX_P (field_name))
293     {
294       char *opname = cplus_mangle_opname (field_name + 3, 0);
295       if (opname == NULL)
296         error ("No mangling for \"%s\"", field_name);
297       mangled_name_len += strlen (opname);
298       mangled_name = (char *)xmalloc (mangled_name_len);
299
300       strncpy (mangled_name, field_name, 3);
301       mangled_name[3] = '\0';
302       strcat (mangled_name, opname);
303     }
304   else
305     {
306       mangled_name = (char *)xmalloc (mangled_name_len);
307       if (is_constructor)
308         mangled_name[0] = '\0';
309       else
310         strcpy (mangled_name, field_name);
311     }
312   strcat (mangled_name, buf);
313   strcat (mangled_name, newname);
314 #else
315   char *opname;
316
317   if (is_constructor)
318     {
319       buf[0] = '\0';
320     }
321   else
322     {
323       sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
324     }
325
326   mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
327                       + strlen (buf) + strlen (physname) + 1);
328
329   /* Only needed for GNU-mangled names.  ANSI-mangled names
330      work with the normal mechanisms.  */
331   if (OPNAME_PREFIX_P (field_name))
332     {
333       opname = cplus_mangle_opname (field_name + 3, 0);
334       if (opname == NULL)
335         {
336           error ("No mangling for \"%s\"", field_name);
337         }
338       mangled_name_len += strlen (opname);
339       mangled_name = (char *) xmalloc (mangled_name_len);
340
341       strncpy (mangled_name, field_name, 3);
342       strcpy (mangled_name + 3, opname);
343     }
344   else
345     {
346       mangled_name = (char *) xmalloc (mangled_name_len);
347       if (is_constructor)
348         {
349           mangled_name[0] = '\0';
350         }
351       else
352         {
353           strcpy (mangled_name, field_name);
354         }
355     }
356   strcat (mangled_name, buf);
357
358 #endif
359   strcat (mangled_name, physname);
360   return (mangled_name);
361 }
362
363 \f
364 /* Find which partial symtab on contains PC.  Return 0 if none.  */
365
366 struct partial_symtab *
367 find_pc_psymtab (pc)
368      register CORE_ADDR pc;
369 {
370   register struct partial_symtab *pst;
371   register struct objfile *objfile;
372
373   ALL_PSYMTABS (objfile, pst)
374     {
375       if (pc >= pst->textlow && pc < pst->texthigh)
376         return (pst);
377     }
378   return (NULL);
379 }
380
381 /* Find which partial symbol within a psymtab contains PC.  Return 0
382    if none.  Check all psymtabs if PSYMTAB is 0.  */
383 struct partial_symbol *
384 find_pc_psymbol (psymtab, pc)
385      struct partial_symtab *psymtab;
386      CORE_ADDR pc;
387 {
388   struct partial_symbol *best, *p;
389   CORE_ADDR best_pc;
390   
391   if (!psymtab)
392     psymtab = find_pc_psymtab (pc);
393   if (!psymtab)
394     return 0;
395
396   best_pc = psymtab->textlow - 1;
397
398   for (p = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
399        (p - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
400         < psymtab->n_static_syms);
401        p++)
402     if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
403         && SYMBOL_CLASS (p) == LOC_BLOCK
404         && pc >= SYMBOL_VALUE_ADDRESS (p)
405         && SYMBOL_VALUE_ADDRESS (p) > best_pc)
406       {
407         best_pc = SYMBOL_VALUE_ADDRESS (p);
408         best = p;
409       }
410   if (best_pc == psymtab->textlow - 1)
411     return 0;
412   return best;
413 }
414
415 \f
416 /* Find the definition for a specified symbol name NAME
417    in namespace NAMESPACE, visible from lexical block BLOCK.
418    Returns the struct symbol pointer, or zero if no symbol is found.
419    If SYMTAB is non-NULL, store the symbol table in which the
420    symbol was found there, or NULL if not found.
421    C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
422    NAME is a field of the current implied argument `this'.  If so set
423    *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero. 
424    BLOCK_FOUND is set to the block in which NAME is found (in the case of
425    a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
426
427 struct symbol *
428 lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
429      const char *name;
430      register const struct block *block;
431      const enum namespace namespace;
432      int *is_a_field_of_this;
433      struct symtab **symtab;
434 {
435   register struct symbol *sym;
436   register struct symtab *s;
437   register struct partial_symtab *ps;
438   struct blockvector *bv;
439   register struct objfile *objfile;
440   register struct block *b;
441   register struct minimal_symbol *msymbol;
442   char *temp;
443   extern char *gdb_completer_word_break_characters;
444
445   /* If NAME contains any characters from gdb_completer_word_break_characters
446      then it is probably from a quoted name string.  So check to see if it
447      has a C++ mangled equivalent, and if so, use the mangled equivalent. */
448
449   if (strpbrk (name, gdb_completer_word_break_characters) != NULL)
450     {
451       if ((temp = expensive_mangler (name)) != NULL)
452         {
453           name = temp;
454         }
455     }
456
457   /* Search specified block and its superiors.  */
458
459   while (block != 0)
460     {
461       sym = lookup_block_symbol (block, name, namespace);
462       if (sym) 
463         {
464           block_found = block;
465           if (symtab != NULL)
466             {
467               /* Search the list of symtabs for one which contains the
468                  address of the start of this block.  */
469               ALL_SYMTABS (objfile, s)
470                 {
471                   bv = BLOCKVECTOR (s);
472                   b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
473                   if (BLOCK_START (b) <= BLOCK_START (block)
474                       && BLOCK_END (b) > BLOCK_START (block))
475                     goto found;
476                 }
477 found:
478               *symtab = s;
479             }
480
481           return (sym);
482         }
483       block = BLOCK_SUPERBLOCK (block);
484     }
485
486   /* But that doesn't do any demangling for the STATIC_BLOCK.
487      I'm not sure whether demangling is needed in the case of
488      nested function in inner blocks; if so this needs to be changed.
489      
490      Don't need to mess with the psymtabs; if we have a block,
491      that file is read in.  If we don't, then we deal later with
492      all the psymtab stuff that needs checking.  */
493   if (namespace == VAR_NAMESPACE && block != NULL)
494     {
495       struct block *b;
496       /* Find the right symtab.  */
497       ALL_SYMTABS (objfile, s)
498         {
499           bv = BLOCKVECTOR (s);
500           b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
501           if (BLOCK_START (b) <= BLOCK_START (block)
502               && BLOCK_END (b) > BLOCK_START (block))
503             {
504               sym = lookup_demangled_block_symbol (b, name);
505               if (sym)
506                 {
507                   block_found = b;
508                   if (symtab != NULL)
509                     *symtab = s;
510                   return sym;
511                 }
512             }
513         }
514     }
515
516
517   /* C++: If requested to do so by the caller, 
518      check to see if NAME is a field of `this'. */
519   if (is_a_field_of_this)
520     {
521       struct value *v = value_of_this (0);
522       
523       *is_a_field_of_this = 0;
524       if (v && check_field (v, name))
525         {
526           *is_a_field_of_this = 1;
527           if (symtab != NULL)
528             *symtab = NULL;
529           return 0;
530         }
531     }
532
533   /* Now search all global blocks.  Do the symtab's first, then
534      check the psymtab's */
535   
536   ALL_SYMTABS (objfile, s)
537     {
538       bv = BLOCKVECTOR (s);
539       block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
540       sym = lookup_block_symbol (block, name, namespace);
541       if (sym) 
542         {
543           block_found = block;
544           if (symtab != NULL)
545             *symtab = s;
546           return sym;
547         }
548     }
549
550   /* Check for the possibility of the symbol being a global function
551      that is stored in one of the minimal symbol tables.  Eventually, all
552      global symbols might be resolved in this way.  */
553   
554   if (namespace == VAR_NAMESPACE)
555     {
556       msymbol = lookup_minimal_symbol (name, (struct objfile *) NULL);
557
558       if (msymbol == NULL)
559         {
560           /* Test each minimal symbol to see if the minimal symbol's name
561              is a C++ mangled name that matches a user visible name.  */
562
563           char *demangled;
564
565           ALL_MSYMBOLS (objfile, msymbol)
566             {
567               demangled = demangle_and_match (msymbol -> name, name,
568                                               DMGL_PARAMS | DMGL_ANSI);
569               if (demangled != NULL)
570                 {
571                   free (demangled);
572                   goto found_msym;
573                 }
574             }
575           msymbol = NULL;               /* Not found */
576         }
577
578 found_msym:
579       if (msymbol != NULL)
580         {
581           s = find_pc_symtab (msymbol -> address);
582           /* If S is NULL, there are no debug symbols for this file.
583              Skip this stuff and check for matching static symbols below. */
584           if (s != NULL)
585             {
586               bv = BLOCKVECTOR (s);
587               block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
588               sym = lookup_block_symbol (block, msymbol -> name, namespace);
589               /* We kept static functions in minimal symbol table as well as
590                  in static scope. We want to find them in the symbol table. */
591                 if (!sym) {
592                   block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
593                   sym = lookup_block_symbol (block, msymbol -> name,
594                                              namespace);
595                 }
596
597               /* sym == 0 if symbol was found in the minimal symbol table
598                  but not in the symtab.
599                  Return 0 to use the msymbol definition of "foo_".
600
601                  This happens for Fortran  "foo_" symbols,
602                  which are "foo" in the symtab.
603
604                  This can also happen if "asm" is used to make a
605                  regular symbol but not a debugging symbol, e.g.
606                  asm(".globl _main");
607                  asm("_main:");
608                  */
609
610               if (symtab != NULL)
611                 *symtab = s;
612               return sym;
613             }
614         }
615     }
616       
617   ALL_PSYMTABS (objfile, ps)
618     {
619       if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
620         {
621           s = PSYMTAB_TO_SYMTAB(ps);
622           bv = BLOCKVECTOR (s);
623           block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
624           sym = lookup_block_symbol (block, name, namespace);
625           if (!sym)
626             error ("Internal: global symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);
627           if (symtab != NULL)
628             *symtab = s;
629           return sym;
630         }
631     }
632
633   /* Now search all per-file blocks.
634      Not strictly correct, but more useful than an error.
635      Do the symtabs first, then check the psymtabs */
636
637   ALL_SYMTABS (objfile, s)
638     {
639       bv = BLOCKVECTOR (s);
640       block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
641       sym = lookup_block_symbol (block, name, namespace);
642       if (sym) 
643         {
644           block_found = block;
645           if (symtab != NULL)
646             *symtab = s;
647           return sym;
648         }
649     }
650
651   ALL_PSYMTABS (objfile, ps)
652     {
653       if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
654         {
655           s = PSYMTAB_TO_SYMTAB(ps);
656           bv = BLOCKVECTOR (s);
657           block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
658           sym = lookup_block_symbol (block, name, namespace);
659           if (!sym)
660             error ("Internal: static symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);
661           if (symtab != NULL)
662             *symtab = s;
663           return sym;
664         }
665     }
666
667   /* Now search all per-file blocks for static mangled symbols.
668      Do the symtabs first, then check the psymtabs.  */
669
670   if (namespace == VAR_NAMESPACE)
671     {
672       ALL_SYMTABS (objfile, s)
673         {
674           bv = BLOCKVECTOR (s);
675           block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
676           sym = lookup_demangled_block_symbol (block, name);
677           if (sym) 
678             {
679               block_found = block;
680               if (symtab != NULL)
681                 *symtab = s;
682               return sym;
683             }
684         }
685
686       ALL_PSYMTABS (objfile, ps)
687         {
688           if (!ps->readin && lookup_demangled_partial_symbol (ps, name))
689             {
690               s = PSYMTAB_TO_SYMTAB(ps);
691               bv = BLOCKVECTOR (s);
692               block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
693               sym = lookup_demangled_block_symbol (block, name);
694               if (!sym)
695                 error ("Internal: mangled static symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);
696               if (symtab != NULL)
697                 *symtab = s;
698               return sym;
699             }
700         }
701     }
702
703   if (symtab != NULL)
704     *symtab = NULL;
705   return 0;
706 }
707
708 /* Look for a static demangled symbol in block BLOCK.  */
709
710 static struct symbol *
711 lookup_demangled_block_symbol (block, name)
712      register const struct block *block;
713      const char *name;
714 {
715   register int bot, top;
716   register struct symbol *sym;
717   char *demangled;
718
719   bot = 0;
720   top = BLOCK_NSYMS (block);
721
722   while (bot < top)
723     {
724       sym = BLOCK_SYM (block, bot);
725       if (SYMBOL_NAMESPACE (sym) == VAR_NAMESPACE)
726         {
727           demangled = demangle_and_match (SYMBOL_NAME (sym), name,
728                                           DMGL_PARAMS | DMGL_ANSI);
729           if (demangled != NULL)
730             {
731               free (demangled);
732               return (sym);
733             }
734         }
735       bot++;
736     }
737
738   return (NULL);
739 }
740
741 /* Look, in partial_symtab PST, for static mangled symbol NAME. */
742
743 static struct partial_symbol *
744 lookup_demangled_partial_symbol (pst, name)
745      const struct partial_symtab *pst;
746      const char *name;
747 {
748   struct partial_symbol *start, *psym;
749   int length = pst->n_static_syms;
750   char *demangled;
751
752   if (!length)
753     return (struct partial_symbol *) 0;
754   
755   start = pst->objfile->static_psymbols.list + pst->statics_offset;
756   for (psym = start; psym < start + length; psym++)
757     {
758       if (SYMBOL_NAMESPACE (psym) == VAR_NAMESPACE)
759         {
760           demangled = demangle_and_match (SYMBOL_NAME (psym), name,
761                                           DMGL_PARAMS | DMGL_ANSI);
762           if (demangled != NULL)
763             {
764               free (demangled);
765               return (psym);
766             }
767         }
768     }
769
770   return (NULL);
771 }
772
773 /* Look, in partial_symtab PST, for symbol NAME.  Check the global
774    symbols if GLOBAL, the static symbols if not */
775
776 static struct partial_symbol *
777 lookup_partial_symbol (pst, name, global, namespace)
778      struct partial_symtab *pst;
779      const char *name;
780      int global;
781      enum namespace namespace;
782 {
783   struct partial_symbol *start, *psym;
784   int length = (global ? pst->n_global_syms : pst->n_static_syms);
785
786   if (!length)
787     return (struct partial_symbol *) 0;
788   
789   start = (global ?
790            pst->objfile->global_psymbols.list + pst->globals_offset :
791            pst->objfile->static_psymbols.list + pst->statics_offset  );
792
793   if (global)                   /* This means we can use a binary */
794                                 /* search.  */
795     {
796       struct partial_symbol *top, *bottom, *center;
797
798       /* Binary search.  This search is guaranteed to end with center
799          pointing at the earliest partial symbol with the correct
800          name.  At that point *all* partial symbols with that name
801          will be checked against the correct namespace. */
802       bottom = start;
803       top = start + length - 1;
804       while (top > bottom)
805         {
806           center = bottom + (top - bottom) / 2;
807
808           assert (center < top);
809           
810           if (strcmp (SYMBOL_NAME (center), name) >= 0)
811             top = center;
812           else
813             bottom = center + 1;
814         }
815       assert (top == bottom);
816       
817       while (!strcmp (SYMBOL_NAME (top), name))
818         {
819           if (SYMBOL_NAMESPACE (top) == namespace)
820             return top;
821           top ++;
822         }
823     }
824   else
825     {
826       /* Can't use a binary search */
827       for (psym = start; psym < start + length; psym++)
828         if (namespace == SYMBOL_NAMESPACE (psym)
829             && !strcmp (name, SYMBOL_NAME (psym)))
830           return psym;
831     }
832
833   return (struct partial_symbol *) 0;
834 }
835
836 /* Find the psymtab containing main(). */
837 /* FIXME:  What about languages without main() or specially linked
838    executables that have no main() ? */
839
840 struct partial_symtab *
841 find_main_psymtab ()
842 {
843   register struct partial_symtab *pst;
844   register struct objfile *objfile;
845
846   ALL_PSYMTABS (objfile, pst)
847     {
848       if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE))
849         {
850           return (pst);
851         }
852     }
853   return (NULL);
854 }
855
856 /* Look for a symbol in block BLOCK.  */
857
858 struct symbol *
859 lookup_block_symbol (block, name, namespace)
860      register const struct block *block;
861      const char *name;
862      const enum namespace namespace;
863 {
864   register int bot, top, inc;
865   register struct symbol *sym, *parameter_sym;
866
867   top = BLOCK_NSYMS (block);
868   bot = 0;
869
870   /* If the blocks's symbols were sorted, start with a binary search.  */
871
872   if (BLOCK_SHOULD_SORT (block))
873     {
874       /* First, advance BOT to not far before
875          the first symbol whose name is NAME.  */
876
877       while (1)
878         {
879           inc = (top - bot + 1);
880           /* No need to keep binary searching for the last few bits worth.  */
881           if (inc < 4)
882             break;
883           inc = (inc >> 1) + bot;
884           sym = BLOCK_SYM (block, inc);
885           if (SYMBOL_NAME (sym)[0] < name[0])
886             bot = inc;
887           else if (SYMBOL_NAME (sym)[0] > name[0])
888             top = inc;
889           else if (strcmp (SYMBOL_NAME (sym), name) < 0)
890             bot = inc;
891           else
892             top = inc;
893         }
894
895       /* Now scan forward until we run out of symbols,
896          find one whose name is greater than NAME,
897          or find one we want.
898          If there is more than one symbol with the right name and namespace,
899          we return the first one.  dbxread.c is careful to make sure
900          that if one is a register then it comes first.  */
901
902       top = BLOCK_NSYMS (block);
903       while (bot < top)
904         {
905           sym = BLOCK_SYM (block, bot);
906           inc = SYMBOL_NAME (sym)[0] - name[0];
907           if (inc == 0)
908             inc = strcmp (SYMBOL_NAME (sym), name);
909           if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)
910             return sym;
911           if (inc > 0)
912             return 0;
913           bot++;
914         }
915       return 0;
916     }
917
918   /* Here if block isn't sorted.
919      This loop is equivalent to the loop above,
920      but hacked greatly for speed.
921
922      Note that parameter symbols do not always show up last in the
923      list; this loop makes sure to take anything else other than
924      parameter symbols first; it only uses parameter symbols as a
925      last resort.  Note that this only takes up extra computation
926      time on a match.  */
927
928   parameter_sym = (struct symbol *) 0;
929   top = BLOCK_NSYMS (block);
930   inc = name[0];
931   while (bot < top)
932     {
933       sym = BLOCK_SYM (block, bot);
934       if (SYMBOL_NAME (sym)[0] == inc
935           && !strcmp (SYMBOL_NAME (sym), name)
936           && SYMBOL_NAMESPACE (sym) == namespace)
937         {
938           if (SYMBOL_CLASS (sym) == LOC_ARG
939               || SYMBOL_CLASS (sym) == LOC_LOCAL_ARG
940               || SYMBOL_CLASS (sym) == LOC_REF_ARG
941               || SYMBOL_CLASS (sym) == LOC_REGPARM)
942             parameter_sym = sym;
943           else
944             return sym;
945         }
946       bot++;
947     }
948   return parameter_sym;         /* Will be 0 if not found. */
949 }
950 \f
951 /* Return the symbol for the function which contains a specified
952    lexical block, described by a struct block BL.  */
953
954 struct symbol *
955 block_function (bl)
956      struct block *bl;
957 {
958   while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
959     bl = BLOCK_SUPERBLOCK (bl);
960
961   return BLOCK_FUNCTION (bl);
962 }
963
964 /* Find the symtab associated with PC.  Look through the psymtabs and read in
965    another symtab if necessary. */
966
967 struct symtab *
968 find_pc_symtab (pc)
969      register CORE_ADDR pc;
970 {
971   register struct block *b;
972   struct blockvector *bv;
973   register struct symtab *s = 0;
974   register struct partial_symtab *ps;
975   register struct objfile *objfile;
976
977   /* Search all symtabs for one whose file contains our pc */
978
979   ALL_SYMTABS (objfile, s)
980     {
981       bv = BLOCKVECTOR (s);
982       b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
983       if (BLOCK_START (b) <= pc
984           && BLOCK_END (b) > pc)
985         return (s);
986     }
987
988   ps = find_pc_psymtab (pc);
989   if (ps)
990     {
991       if (ps->readin)
992         printf_filtered ("(Internal error: pc 0x%x in read in psymtab, but not in symtab.)\n", pc);
993       s = PSYMTAB_TO_SYMTAB (ps);
994     }
995 }
996
997 /* Find the source file and line number for a given PC value.
998    Return a structure containing a symtab pointer, a line number,
999    and a pc range for the entire source line.
1000    The value's .pc field is NOT the specified pc.
1001    NOTCURRENT nonzero means, if specified pc is on a line boundary,
1002    use the line that ends there.  Otherwise, in that case, the line
1003    that begins there is used.  */
1004
1005 struct symtab_and_line
1006 find_pc_line (pc, notcurrent)
1007      CORE_ADDR pc;
1008      int notcurrent;
1009 {
1010   struct symtab *s;
1011   register struct linetable *l;
1012   register int len;
1013   register int i;
1014   register struct linetable_entry item;
1015   struct symtab_and_line val;
1016   struct blockvector *bv;
1017
1018   /* Info on best line seen so far, and where it starts, and its file.  */
1019
1020   struct linetable_entry best;
1021   CORE_ADDR best_end = 0;
1022   struct symtab *best_symtab = 0;
1023
1024   /* Store here the first line number
1025      of a file which contains the line at the smallest pc after PC.
1026      If we don't find a line whose range contains PC,
1027      we will use a line one less than this,
1028      with a range from the start of that file to the first line's pc.  */
1029   struct linetable_entry alt;
1030   struct symtab *alt_symtab = 0;
1031
1032   /* Info on best line seen in this file.  */
1033
1034   struct linetable_entry prev;
1035
1036   best.line = 0;
1037   best.pc = 0;
1038   alt.line = 0;
1039   alt.pc = 0;
1040
1041   /* If this pc is not from the current frame,
1042      it is the address of the end of a call instruction.
1043      Quite likely that is the start of the following statement.
1044      But what we want is the statement containing the instruction.
1045      Fudge the pc to make sure we get that.  */
1046
1047   if (notcurrent) pc -= 1;
1048
1049   s = find_pc_symtab (pc);
1050   if (!s)
1051     {
1052       val.symtab = 0;
1053       val.line = 0;
1054       val.pc = pc;
1055       val.end = 0;
1056       return val;
1057     }
1058
1059   bv = BLOCKVECTOR (s);
1060
1061   /* Look at all the symtabs that share this blockvector.
1062      They all have the same apriori range, that we found was right;
1063      but they have different line tables.  */
1064
1065   for (; s && BLOCKVECTOR (s) == bv; s = s->next)
1066     {
1067       /* Find the best line in this symtab.  */
1068       l = LINETABLE (s);
1069       if (!l)
1070         continue;
1071       len = l->nitems;
1072       if (len <= 0)
1073         {
1074           fprintf (stderr, "Inconsistent line number info for %s\n",
1075                    s->filename);
1076           continue;
1077         }
1078
1079       prev.line = -1;
1080       item = l->item[0];        /* Get first line info */
1081
1082       /* Is this file's first line closer than the first lines of other files?
1083          If so, record this file, and its first line, as best alternate.  */
1084       if (item.pc > pc && (alt.pc == 0 || item.pc < alt.pc))
1085         {
1086           alt = item;
1087           alt_symtab = s;
1088         }
1089
1090       for (i = 0; i < len; i++)
1091         {
1092           item = l->item[i];
1093
1094           /* Return the last line that did not start after PC.  */
1095           if (item.pc > pc)
1096             break;
1097
1098           prev = item;
1099         }
1100
1101       /* At this point, prev points at the line whose start addr is <= pc, and
1102          item points at the next line.  If we ran off the end of the linetable
1103          (pc >= start of the last line), then prev == item.  If pc < start of
1104          the first line, prev will not be set.  */
1105
1106       /* Is this file's best line closer than the best in the other files?
1107          If so, record this file, and its best line, as best so far.  */
1108
1109       if (prev.line >= 0 && prev.pc > best.pc)
1110         {
1111           best = prev;
1112           best_symtab = s;
1113           /* If another line is in the linetable, and its PC is closer
1114              than the best_end we currently have, take it as best_end.  */
1115           if (i < len && (best_end == 0 || best_end > item.pc))
1116             best_end = item.pc;
1117         }
1118     }
1119
1120   if (!best_symtab)
1121     {
1122       if (!alt_symtab)
1123         {                       /* If we didn't find any line # info, just
1124                                  return zeros.  */
1125           val.symtab = 0;
1126           val.line = 0;
1127           val.pc = pc;
1128           val.end = 0;
1129         }
1130       else
1131         {
1132           val.symtab = alt_symtab;
1133           val.line = alt.line - 1;
1134           val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1135           val.end = alt.pc;
1136         }
1137     }
1138   else
1139     {
1140       val.symtab = best_symtab;
1141       val.line = best.line;
1142       val.pc = best.pc;
1143       if (best_end && (alt.pc == 0 || best_end < alt.pc))
1144         val.end = best_end;
1145       else if (alt.pc)
1146         val.end = alt.pc;
1147       else
1148         val.end = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1149     }
1150   return val;
1151 }
1152 \f
1153 /* Find the PC value for a given source file and line number.
1154    Returns zero for invalid line number.
1155    The source file is specified with a struct symtab.  */
1156
1157 CORE_ADDR
1158 find_line_pc (symtab, line)
1159      struct symtab *symtab;
1160      int line;
1161 {
1162   register struct linetable *l;
1163   register int ind;
1164   int dummy;
1165
1166   if (symtab == 0)
1167     return 0;
1168   l = LINETABLE (symtab);
1169   ind = find_line_common(l, line, &dummy);
1170   return (ind >= 0) ? l->item[ind].pc : 0;
1171 }
1172
1173 /* Find the range of pc values in a line.
1174    Store the starting pc of the line into *STARTPTR
1175    and the ending pc (start of next line) into *ENDPTR.
1176    Returns 1 to indicate success.
1177    Returns 0 if could not find the specified line.  */
1178
1179 int
1180 find_line_pc_range (symtab, thisline, startptr, endptr)
1181      struct symtab *symtab;
1182      int thisline;
1183      CORE_ADDR *startptr, *endptr;
1184 {
1185   register struct linetable *l;
1186   register int ind;
1187   int exact_match;              /* did we get an exact linenumber match */
1188
1189   if (symtab == 0)
1190     return 0;
1191
1192   l = LINETABLE (symtab);
1193   ind = find_line_common (l, thisline, &exact_match);
1194   if (ind >= 0)
1195     {
1196       *startptr = l->item[ind].pc;
1197       /* If we have not seen an entry for the specified line,
1198          assume that means the specified line has zero bytes.  */
1199       if (!exact_match || ind == l->nitems-1)
1200         *endptr = *startptr;
1201       else
1202         /* Perhaps the following entry is for the following line.
1203            It's worth a try.  */
1204         if (ind+1 < l->nitems
1205          && l->item[ind+1].line == thisline + 1)
1206           *endptr = l->item[ind+1].pc;
1207         else
1208           *endptr = find_line_pc (symtab, thisline+1);
1209       return 1;
1210     }
1211
1212   return 0;
1213 }
1214
1215 /* Given a line table and a line number, return the index into the line
1216    table for the pc of the nearest line whose number is >= the specified one.
1217    Return -1 if none is found.  The value is >= 0 if it is an index.
1218
1219    Set *EXACT_MATCH nonzero if the value returned is an exact match.  */
1220
1221 static int
1222 find_line_common (l, lineno, exact_match)
1223      register struct linetable *l;
1224      register int lineno;
1225      int *exact_match;
1226 {
1227   register int i;
1228   register int len;
1229
1230   /* BEST is the smallest linenumber > LINENO so far seen,
1231      or 0 if none has been seen so far.
1232      BEST_INDEX identifies the item for it.  */
1233
1234   int best_index = -1;
1235   int best = 0;
1236
1237   if (lineno <= 0)
1238     return -1;
1239   if (l == 0)
1240     return -1;
1241
1242   len = l->nitems;
1243   for (i = 0; i < len; i++)
1244     {
1245       register struct linetable_entry *item = &(l->item[i]);
1246
1247       if (item->line == lineno)
1248         {
1249           *exact_match = 1;
1250           return i;
1251         }
1252
1253       if (item->line > lineno && (best == 0 || item->line < best))
1254         {
1255           best = item->line;
1256           best_index = i;
1257         }
1258     }
1259
1260   /* If we got here, we didn't get an exact match.  */
1261
1262   *exact_match = 0;
1263   return best_index;
1264 }
1265
1266 int
1267 find_pc_line_pc_range (pc, startptr, endptr)
1268      CORE_ADDR pc;
1269      CORE_ADDR *startptr, *endptr;
1270 {
1271   struct symtab_and_line sal;
1272   sal = find_pc_line (pc, 0);
1273   *startptr = sal.pc;
1274   *endptr = sal.end;
1275   return sal.symtab != 0;
1276 }
1277 \f
1278 /* If P is of the form "operator[ \t]+..." where `...' is
1279    some legitimate operator text, return a pointer to the
1280    beginning of the substring of the operator text.
1281    Otherwise, return "".  */
1282 static char *
1283 operator_chars (p, end)
1284      char *p;
1285      char **end;
1286 {
1287   *end = "";
1288   if (strncmp (p, "operator", 8))
1289     return *end;
1290   p += 8;
1291
1292   /* Don't get faked out by `operator' being part of a longer
1293      identifier.  */
1294   if (isalpha(*p) || *p == '_' || *p == '$' || *p == '\0')
1295     return *end;
1296
1297   /* Allow some whitespace between `operator' and the operator symbol.  */
1298   while (*p == ' ' || *p == '\t')
1299     p++;
1300
1301   /* Recognize 'operator TYPENAME'. */
1302
1303   if (isalpha(*p) || *p == '_' || *p == '$')
1304     {
1305       register char *q = p+1;
1306       while (isalnum(*q) || *q == '_' || *q == '$')
1307         q++;
1308       *end = q;
1309       return p;
1310     }
1311
1312   switch (*p)
1313     {
1314     case '!':
1315     case '=':
1316     case '*':
1317     case '/':
1318     case '%':
1319     case '^':
1320       if (p[1] == '=')
1321         *end = p+2;
1322       else
1323         *end = p+1;
1324       return p;
1325     case '<':
1326     case '>':
1327     case '+':
1328     case '-':
1329     case '&':
1330     case '|':
1331       if (p[1] == '=' || p[1] == p[0])
1332         *end = p+2;
1333       else
1334         *end = p+1;
1335       return p;
1336     case '~':
1337     case ',':
1338       *end = p+1;
1339       return p;
1340     case '(':
1341       if (p[1] != ')')
1342         error ("`operator ()' must be specified without whitespace in `()'");
1343       *end = p+2;
1344       return p;
1345     case '?':
1346       if (p[1] != ':')
1347         error ("`operator ?:' must be specified without whitespace in `?:'");
1348       *end = p+2;
1349       return p;
1350     case '[':
1351       if (p[1] != ']')
1352         error ("`operator []' must be specified without whitespace in `[]'");
1353       *end = p+2;
1354       return p;
1355     default:
1356       error ("`operator %s' not supported", p);
1357       break;
1358     }
1359   *end = "";
1360   return *end;
1361 }
1362
1363 /* Recursive helper function for decode_line_1.
1364  * Look for methods named NAME in type T.
1365  * Return number of matches.
1366  * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1367  * These allocations seem to define "big enough":
1368  * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1369  * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1370  */
1371
1372 int
1373 find_methods (t, name, physnames, sym_arr)
1374      struct type *t;
1375      char *name;
1376      char **physnames;
1377      struct symbol **sym_arr;
1378 {
1379   int i1 = 0;
1380   int ibase;
1381   struct symbol *sym_class;
1382   char *class_name = type_name_no_tag (t);
1383   /* Ignore this class if it doesn't have a name.
1384      This prevents core dumps, but is just a workaround
1385      because we might not find the function in
1386      certain cases, such as
1387      struct D {virtual int f();}
1388      struct C : D {virtual int g();}
1389      (in this case g++ 1.35.1- does not put out a name
1390      for D as such, it defines type 19 (for example) in
1391      the same stab as C, and then does a
1392      .stabs "D:T19" and a .stabs "D:t19".
1393      Thus
1394      "break C::f" should not be looking for field f in
1395      the class named D, 
1396      but just for the field f in the baseclasses of C
1397      (no matter what their names).
1398      
1399      However, I don't know how to replace the code below
1400      that depends on knowing the name of D.  */
1401   if (class_name
1402       && (sym_class = lookup_symbol (class_name,
1403                                      (struct block *)NULL,
1404                                      STRUCT_NAMESPACE,
1405                                      (int *)NULL,
1406                                      (struct symtab **)NULL)))
1407     {
1408       int method_counter;
1409       t = SYMBOL_TYPE (sym_class);
1410       for (method_counter = TYPE_NFN_FIELDS (t) - 1;
1411            method_counter >= 0;
1412            --method_counter)
1413         {
1414           int field_counter;
1415           struct fn_field *f = TYPE_FN_FIELDLIST1 (t, method_counter);
1416
1417           char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
1418           if (!strcmp (name, method_name))
1419             /* Find all the fields with that name.  */
1420             for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
1421                  field_counter >= 0;
1422                  --field_counter)
1423               {
1424                 char *phys_name;
1425                 if (TYPE_FN_FIELD_STUB (f, field_counter))
1426                   check_stub_method (t, method_counter, field_counter);
1427                 phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
1428                 physnames[i1] = (char*) alloca (strlen (phys_name) + 1);
1429                 strcpy (physnames[i1], phys_name);
1430                 sym_arr[i1] = lookup_symbol (phys_name,
1431                                              SYMBOL_BLOCK_VALUE (sym_class),
1432                                              VAR_NAMESPACE,
1433                                              (int *) NULL,
1434                                              (struct symtab **) NULL);
1435                 if (sym_arr[i1]) i1++;
1436                 else
1437                   {
1438                     fputs_filtered("(Cannot find method ", stdout);
1439                     fputs_demangled(phys_name, stdout, DMGL_PARAMS);
1440                     fputs_filtered(" - possibly inlined.)\n", stdout);
1441                   }
1442               }
1443         }
1444     }
1445   /* Only search baseclasses if there is no match yet,
1446    * since names in derived classes override those in baseclasses.
1447    */
1448   if (i1)
1449     return i1;
1450   for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
1451     i1 += find_methods(TYPE_BASECLASS(t, ibase), name,
1452                        physnames + i1, sym_arr + i1);
1453   return i1;
1454 }
1455
1456 /* Parse a string that specifies a line number.
1457    Pass the address of a char * variable; that variable will be
1458    advanced over the characters actually parsed.
1459
1460    The string can be:
1461
1462    LINENUM -- that line number in current file.  PC returned is 0.
1463    FILE:LINENUM -- that line in that file.  PC returned is 0.
1464    FUNCTION -- line number of openbrace of that function.
1465       PC returned is the start of the function.
1466    VARIABLE -- line number of definition of that variable.
1467       PC returned is 0.
1468    FILE:FUNCTION -- likewise, but prefer functions in that file.
1469    *EXPR -- line in which address EXPR appears.
1470
1471    FUNCTION may be an undebuggable function found in minimal symbol table.
1472
1473    If the argument FUNFIRSTLINE is nonzero, we want the first line
1474    of real code inside a function when a function is specified.
1475
1476    DEFAULT_SYMTAB specifies the file to use if none is specified.
1477    It defaults to current_source_symtab.
1478    DEFAULT_LINE specifies the line number to use for relative
1479    line numbers (that start with signs).  Defaults to current_source_line.
1480
1481    Note that it is possible to return zero for the symtab
1482    if no file is validly specified.  Callers must check that.
1483    Also, the line number returned may be invalid.  */
1484
1485 struct symtabs_and_lines
1486 decode_line_1 (argptr, funfirstline, default_symtab, default_line)
1487      char **argptr;
1488      int funfirstline;
1489      struct symtab *default_symtab;
1490      int default_line;
1491 {
1492   struct symtabs_and_lines values;
1493 #ifdef HPPA_COMPILER_BUG
1494   /* FIXME: The native HP 9000/700 compiler has a bug which appears
1495      when optimizing this file with target i960-vxworks.  I haven't
1496      been able to construct a simple test case.  The problem is that
1497      in the second call to SKIP_PROLOGUE below, the compiler somehow
1498      does not realize that the statement val = find_pc_line (...) will
1499      change the values of the fields of val.  It extracts the elements
1500      into registers at the top of the block, and does not update the
1501      registers after the call to find_pc_line.  You can check this by
1502      inserting a printf at the end of find_pc_line to show what values
1503      it is returning for val.pc and val.end and another printf after
1504      the call to see what values the function actually got (remember,
1505      this is compiling with cc -O, with this patch removed).  You can
1506      also examine the assembly listing: search for the second call to
1507      skip_prologue; the LDO statement before the next call to
1508      find_pc_line loads the address of the structure which
1509      find_pc_line will return; if there is a LDW just before the LDO,
1510      which fetches an element of the structure, then the compiler
1511      still has the bug.
1512
1513      Setting val to volatile avoids the problem.  We must undef
1514      volatile, because the HPPA native compiler does not define
1515      __STDC__, although it does understand volatile, and so volatile
1516      will have been defined away in defs.h.  */
1517 #undef volatile
1518   volatile struct symtab_and_line val;
1519 #define volatile /*nothing*/
1520 #else
1521   struct symtab_and_line val;
1522 #endif
1523   register char *p, *p1;
1524   char *q, *q1;
1525   register struct symtab *s;
1526
1527   register struct symbol *sym;
1528   /* The symtab that SYM was found in.  */
1529   struct symtab *sym_symtab;
1530
1531   register CORE_ADDR pc;
1532   register struct minimal_symbol *msymbol;
1533   char *copy;
1534   struct symbol *sym_class;
1535   int i1;
1536   int is_quoted;
1537   struct symbol **sym_arr;
1538   struct type *t;
1539   char **physnames;
1540   char *saved_arg = *argptr;
1541   extern char *gdb_completer_quote_characters;
1542   
1543   /* Defaults have defaults.  */
1544
1545   if (default_symtab == 0)
1546     {
1547       default_symtab = current_source_symtab;
1548       default_line = current_source_line;
1549     }
1550
1551   /* See if arg is *PC */
1552
1553   if (**argptr == '*')
1554     {
1555       if (**argptr == '*')
1556         {
1557           (*argptr)++;
1558         }
1559       pc = parse_and_eval_address_1 (argptr);
1560       values.sals = (struct symtab_and_line *)
1561         xmalloc (sizeof (struct symtab_and_line));
1562       values.nelts = 1;
1563       values.sals[0] = find_pc_line (pc, 0);
1564       values.sals[0].pc = pc;
1565       return values;
1566     }
1567
1568   /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1569
1570   s = NULL;
1571   is_quoted = (strchr (gdb_completer_quote_characters, **argptr) != NULL);
1572
1573   for (p = *argptr; *p; p++)
1574     {
1575       if (p[0] == ':' || p[0] == ' ' || p[0] == '\t')
1576         break;
1577     }
1578   while (p[0] == ' ' || p[0] == '\t') p++;
1579
1580   if ((p[0] == ':') && !is_quoted)
1581     {
1582
1583       /*  C++  */
1584       if (p[1] ==':')
1585         {
1586           /* Extract the class name.  */
1587           p1 = p;
1588           while (p != *argptr && p[-1] == ' ') --p;
1589           copy = (char *) alloca (p - *argptr + 1);
1590           memcpy (copy, *argptr, p - *argptr);
1591           copy[p - *argptr] = 0;
1592
1593           /* Discard the class name from the arg.  */
1594           p = p1 + 2;
1595           while (*p == ' ' || *p == '\t') p++;
1596           *argptr = p;
1597
1598           sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0, 
1599                                      (struct symtab **)NULL);
1600        
1601           if (sym_class &&
1602               (   TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_STRUCT
1603                || TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_UNION))
1604             {
1605               /* Arg token is not digits => try it as a function name
1606                  Find the next token (everything up to end or next whitespace). */
1607               p = *argptr;
1608               while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p !=':') p++;
1609               q = operator_chars (*argptr, &q1);
1610
1611               if (q1 - q)
1612                 {
1613                   char *opname;
1614                   char *tmp = alloca (q1 - q + 1);
1615                   memcpy (tmp, q, q1 - q);
1616                   tmp[q1 - q] = '\0';
1617                   opname = cplus_mangle_opname (tmp, DMGL_ANSI);
1618                   if (opname == NULL)
1619                     {
1620                       warning ("no mangling for \"%s\"", tmp);
1621                       cplusplus_hint (saved_arg);
1622                       return_to_top_level ();
1623                     }
1624                   copy = (char*) alloca (3 + strlen(opname));
1625                   sprintf (copy, "__%s", opname);
1626                   p = q1;
1627                 }
1628               else
1629                 {
1630                   copy = (char *) alloca (p - *argptr + 1 + (q1 - q));
1631                   memcpy (copy, *argptr, p - *argptr);
1632                   copy[p - *argptr] = '\0';
1633                 }
1634
1635               /* no line number may be specified */
1636               while (*p == ' ' || *p == '\t') p++;
1637               *argptr = p;
1638
1639               sym = 0;
1640               i1 = 0;           /*  counter for the symbol array */
1641               t = SYMBOL_TYPE (sym_class);
1642               sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1643               physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1644
1645               if (destructor_name_p (copy, t))
1646                 {
1647                   /* destructors are a special case.  */
1648                   struct fn_field *f = TYPE_FN_FIELDLIST1 (t, 0);
1649                   int len = TYPE_FN_FIELDLIST_LENGTH (t, 0) - 1;
1650                   char *phys_name = TYPE_FN_FIELD_PHYSNAME (f, len);
1651                   physnames[i1] = (char *)alloca (strlen (phys_name) + 1);
1652                   strcpy (physnames[i1], phys_name);
1653                   sym_arr[i1] =
1654                     lookup_symbol (phys_name, SYMBOL_BLOCK_VALUE (sym_class),
1655                                    VAR_NAMESPACE, 0, (struct symtab **)NULL);
1656                   if (sym_arr[i1]) i1++;
1657                 }
1658               else
1659                 i1 = find_methods (t, copy, physnames, sym_arr);
1660               if (i1 == 1)
1661                 {
1662                   /* There is exactly one field with that name.  */
1663                   sym = sym_arr[0];
1664
1665                   if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1666                     {
1667                       /* Arg is the name of a function */
1668                       pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
1669                       if (funfirstline)
1670                         SKIP_PROLOGUE (pc);
1671                       values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
1672                       values.nelts = 1;
1673                       values.sals[0] = find_pc_line (pc, 0);
1674                       values.sals[0].pc = (values.sals[0].end && values.sals[0].pc != pc) ? values.sals[0].end : pc;
1675                     }
1676                   else
1677                     {
1678                       values.nelts = 0;
1679                     }
1680                   return values;
1681                 }
1682               if (i1 > 0)
1683                 {
1684                   /* There is more than one field with that name
1685                      (overloaded).  Ask the user which one to use.  */
1686                   return decode_line_2 (sym_arr, i1, funfirstline);
1687                 }
1688               else
1689                 {
1690                   char *tmp;
1691
1692                   if (OPNAME_PREFIX_P (copy))
1693                     {
1694                       tmp = (char *)alloca (strlen (copy+3) + 9);
1695                       strcpy (tmp, "operator ");
1696                       strcat (tmp, copy+3);
1697                     }
1698                   else
1699                     tmp = copy;
1700                   if (tmp[0] == '~')
1701                     warning ("the class `%s' does not have destructor defined",
1702                              sym_class->name);
1703                   else
1704                     warning ("the class %s does not have any method named %s",
1705                              sym_class->name, tmp);
1706                   cplusplus_hint (saved_arg);
1707                   return_to_top_level ();
1708                 }
1709             }
1710           else
1711             {
1712               /* The quotes are important if copy is empty.  */
1713               warning ("can't find class, struct, or union named \"%s\"",
1714                        copy);
1715               cplusplus_hint (saved_arg);
1716               return_to_top_level ();
1717             }
1718         }
1719       /*  end of C++  */
1720
1721
1722       /* Extract the file name.  */
1723       p1 = p;
1724       while (p != *argptr && p[-1] == ' ') --p;
1725       copy = (char *) alloca (p - *argptr + 1);
1726       memcpy (copy, *argptr, p - *argptr);
1727       copy[p - *argptr] = 0;
1728
1729       /* Find that file's data.  */
1730       s = lookup_symtab (copy);
1731       if (s == 0)
1732         {
1733           if (!have_full_symbols () && !have_partial_symbols ())
1734             error (no_symtab_msg);
1735           error ("No source file named %s.", copy);
1736         }
1737
1738       /* Discard the file name from the arg.  */
1739       p = p1 + 1;
1740       while (*p == ' ' || *p == '\t') p++;
1741       *argptr = p;
1742     }
1743
1744   /* S is specified file's symtab, or 0 if no file specified.
1745      arg no longer contains the file name.  */
1746
1747   /* Check whether arg is all digits (and sign) */
1748
1749   p = *argptr;
1750   if (*p == '-' || *p == '+') p++;
1751   while (*p >= '0' && *p <= '9')
1752     p++;
1753
1754   if (p != *argptr && (*p == 0 || *p == ' ' || *p == '\t' || *p == ','))
1755     {
1756       /* We found a token consisting of all digits -- at least one digit.  */
1757       enum sign {none, plus, minus} sign = none;
1758
1759       /* This is where we need to make sure that we have good defaults.
1760          We must guarantee that this section of code is never executed
1761          when we are called with just a function name, since
1762          select_source_symtab calls us with such an argument  */
1763
1764       if (s == 0 && default_symtab == 0)
1765         {
1766           select_source_symtab (0);
1767           default_symtab = current_source_symtab;
1768           default_line = current_source_line;
1769         }
1770
1771       if (**argptr == '+')
1772         sign = plus, (*argptr)++;
1773       else if (**argptr == '-')
1774         sign = minus, (*argptr)++;
1775       val.line = atoi (*argptr);
1776       switch (sign)
1777         {
1778         case plus:
1779           if (p == *argptr)
1780             val.line = 5;
1781           if (s == 0)
1782             val.line = default_line + val.line;
1783           break;
1784         case minus:
1785           if (p == *argptr)
1786             val.line = 15;
1787           if (s == 0)
1788             val.line = default_line - val.line;
1789           else
1790             val.line = 1;
1791           break;
1792         case none:
1793           break;        /* No need to adjust val.line.  */
1794         }
1795
1796       while (*p == ' ' || *p == '\t') p++;
1797       *argptr = p;
1798       if (s == 0)
1799         s = default_symtab;
1800       val.symtab = s;
1801       val.pc = 0;
1802       values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
1803       values.sals[0] = val;
1804       values.nelts = 1;
1805       return values;
1806     }
1807
1808   /* Arg token is not digits => try it as a variable name
1809      Find the next token (everything up to end or next whitespace).  */
1810
1811   p = skip_quoted (*argptr);
1812   copy = (char *) alloca (p - *argptr + 1);
1813   memcpy (copy, *argptr, p - *argptr);
1814   copy[p - *argptr] = '\0';
1815   if ((copy[0] == copy [p - *argptr - 1])
1816       && strchr (gdb_completer_quote_characters, copy[0]) != NULL)
1817     {
1818       char *temp;
1819       copy [p - *argptr - 1] = '\0';
1820       copy++;
1821       if ((temp = expensive_mangler (copy)) != NULL)
1822         {
1823           copy = temp;
1824         }
1825     }
1826   while (*p == ' ' || *p == '\t') p++;
1827   *argptr = p;
1828
1829   /* Look up that token as a variable.
1830      If file specified, use that file's per-file block to start with.  */
1831
1832   sym = lookup_symbol (copy,
1833                        (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
1834                         : get_selected_block ()),
1835                        VAR_NAMESPACE, 0, &sym_symtab);
1836
1837   if (sym != NULL)
1838     {
1839       if (SYMBOL_CLASS (sym) == LOC_BLOCK)
1840         {
1841           /* Arg is the name of a function */
1842           pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
1843           if (funfirstline)
1844             SKIP_PROLOGUE (pc);
1845           val = find_pc_line (pc, 0);
1846 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1847           /* Convex: no need to suppress code on first line, if any */
1848           val.pc = pc;
1849 #else
1850           /* If SKIP_PROLOGUE left us in mid-line, and the next line is still
1851              part of the same function:
1852                 advance to next line, 
1853                 recalculate its line number (might not be N+1).  */
1854           if (val.pc != pc && val.end &&
1855               lookup_minimal_symbol_by_pc (pc) == lookup_minimal_symbol_by_pc (val.end)) {
1856             pc = val.end;       /* First pc of next line */
1857             val = find_pc_line (pc, 0);
1858           }
1859           val.pc = pc;
1860 #endif
1861           values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
1862           values.sals[0] = val;
1863           values.nelts = 1;
1864           
1865           /* I think this is always the same as the line that
1866              we calculate above, but the general principle is
1867              "trust the symbols more than stuff like
1868              SKIP_PROLOGUE".  */
1869           if (SYMBOL_LINE (sym) != 0)
1870             values.sals[0].line = SYMBOL_LINE (sym);
1871           
1872           return values;
1873         }
1874       else if (SYMBOL_LINE (sym) != 0)
1875         {
1876           /* We know its line number.  */
1877           values.sals = (struct symtab_and_line *)
1878             xmalloc (sizeof (struct symtab_and_line));
1879           values.nelts = 1;
1880           memset (&values.sals[0], 0, sizeof (values.sals[0]));
1881           values.sals[0].symtab = sym_symtab;
1882           values.sals[0].line = SYMBOL_LINE (sym);
1883           return values;
1884         }
1885       else
1886         /* This can happen if it is compiled with a compiler which doesn't
1887            put out line numbers for variables.  */
1888         error ("Line number not known for symbol \"%s\"", copy);
1889     }
1890
1891   msymbol = lookup_minimal_symbol (copy, (struct objfile *) NULL);
1892   if (msymbol != NULL)
1893     {
1894       val.symtab = 0;
1895       val.line = 0;
1896       val.pc = msymbol -> address + FUNCTION_START_OFFSET;
1897       if (funfirstline)
1898         SKIP_PROLOGUE (val.pc);
1899       values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
1900       values.sals[0] = val;
1901       values.nelts = 1;
1902       return values;
1903     }
1904
1905   if (!have_full_symbols () &&
1906       !have_partial_symbols () && !have_minimal_symbols ())
1907     error (no_symtab_msg);
1908
1909   error ("Function \"%s\" not defined.", copy);
1910   return values;        /* for lint */
1911 }
1912
1913 struct symtabs_and_lines
1914 decode_line_spec (string, funfirstline)
1915      char *string;
1916      int funfirstline;
1917 {
1918   struct symtabs_and_lines sals;
1919   if (string == 0)
1920     error ("Empty line specification.");
1921   sals = decode_line_1 (&string, funfirstline,
1922                         current_source_symtab, current_source_line);
1923   if (*string)
1924     error ("Junk at end of line specification: %s", string);
1925   return sals;
1926 }
1927
1928 /* Given a list of NELTS symbols in sym_arr (with corresponding
1929    mangled names in physnames), return a list of lines to operate on
1930    (ask user if necessary).  */
1931 static struct symtabs_and_lines
1932 decode_line_2 (sym_arr, nelts, funfirstline)
1933      struct symbol *sym_arr[];
1934      int nelts;
1935      int funfirstline;
1936 {
1937   struct symtabs_and_lines values, return_values;
1938   register CORE_ADDR pc;
1939   char *args, *arg1;
1940   int i;
1941   char *prompt;
1942   char *demangled;
1943
1944   values.sals = (struct symtab_and_line *) alloca (nelts * sizeof(struct symtab_and_line));
1945   return_values.sals = (struct symtab_and_line *) xmalloc (nelts * sizeof(struct symtab_and_line));
1946
1947   i = 0;
1948   printf("[0] cancel\n[1] all\n");
1949   while (i < nelts)
1950     {
1951       if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK)
1952         {
1953           /* Arg is the name of a function */
1954           pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr[i])) 
1955                + FUNCTION_START_OFFSET;
1956           if (funfirstline)
1957             SKIP_PROLOGUE (pc);
1958           values.sals[i] = find_pc_line (pc, 0);
1959           values.sals[i].pc = (values.sals[i].end && values.sals[i].pc != pc) ?
1960                                values.sals[i].end                      :  pc;
1961           demangled = cplus_demangle (SYMBOL_NAME (sym_arr[i]),
1962                                       DMGL_PARAMS | DMGL_ANSI);
1963           printf("[%d] %s at %s:%d\n", (i+2),
1964                  demangled ? demangled : SYMBOL_NAME (sym_arr[i]), 
1965                  values.sals[i].symtab->filename, values.sals[i].line);
1966           if (demangled != NULL)
1967             {
1968               free (demangled);
1969             }
1970         }
1971       else printf ("?HERE\n");
1972       i++;
1973     }
1974   
1975   if ((prompt = getenv ("PS2")) == NULL)
1976     {
1977       prompt = ">";
1978     }
1979   printf("%s ",prompt);
1980   fflush(stdout);
1981
1982   args = command_line_input ((char *) NULL, 0);
1983   
1984   if (args == 0)
1985     error_no_arg ("one or more choice numbers");
1986
1987   i = 0;
1988   while (*args)
1989     {
1990       int num;
1991
1992       arg1 = args;
1993       while (*arg1 >= '0' && *arg1 <= '9') arg1++;
1994       if (*arg1 && *arg1 != ' ' && *arg1 != '\t')
1995         error ("Arguments must be choice numbers.");
1996
1997       num = atoi (args);
1998
1999       if (num == 0)
2000         error ("cancelled");
2001       else if (num == 1)
2002         {
2003           memcpy (return_values.sals, values.sals,
2004                   (nelts * sizeof(struct symtab_and_line)));
2005           return_values.nelts = nelts;
2006           return return_values;
2007         }
2008
2009       if (num > nelts + 2)
2010         {
2011           printf ("No choice number %d.\n", num);
2012         }
2013       else
2014         {
2015           num -= 2;
2016           if (values.sals[num].pc)
2017             {
2018               return_values.sals[i++] = values.sals[num];
2019               values.sals[num].pc = 0;
2020             }
2021           else
2022             {
2023               printf ("duplicate request for %d ignored.\n", num);
2024             }
2025         }
2026
2027       args = arg1;
2028       while (*args == ' ' || *args == '\t') args++;
2029     }
2030   return_values.nelts = i;
2031   return return_values;
2032 }
2033
2034 \f
2035 /* Slave routine for sources_info.  Force line breaks at ,'s.
2036    NAME is the name to print and *FIRST is nonzero if this is the first
2037    name printed.  Set *FIRST to zero.  */
2038 static void
2039 output_source_filename (name, first)
2040      char *name;
2041      int *first;
2042 {
2043   /* Table of files printed so far.  Since a single source file can
2044      result in several partial symbol tables, we need to avoid printing
2045      it more than once.  Note: if some of the psymtabs are read in and
2046      some are not, it gets printed both under "Source files for which
2047      symbols have been read" and "Source files for which symbols will
2048      be read in on demand".  I consider this a reasonable way to deal
2049      with the situation.  I'm not sure whether this can also happen for
2050      symtabs; it doesn't hurt to check.  */
2051   static char **tab = NULL;
2052   /* Allocated size of tab in elements.
2053      Start with one 256-byte block (when using GNU malloc.c).
2054      24 is the malloc overhead when range checking is in effect.  */
2055   static int tab_alloc_size = (256 - 24) / sizeof (char *);
2056   /* Current size of tab in elements.  */
2057   static int tab_cur_size;
2058
2059   char **p;
2060
2061   if (*first)
2062     {
2063       if (tab == NULL)
2064         tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab));
2065       tab_cur_size = 0;
2066     }
2067
2068   /* Is NAME in tab?  */
2069   for (p = tab; p < tab + tab_cur_size; p++)
2070     if (strcmp (*p, name) == 0)
2071       /* Yes; don't print it again.  */
2072       return;
2073   /* No; add it to tab.  */
2074   if (tab_cur_size == tab_alloc_size)
2075     {
2076       tab_alloc_size *= 2;
2077       tab = (char **) xrealloc ((char *) tab, tab_alloc_size * sizeof (*tab));
2078     }
2079   tab[tab_cur_size++] = name;
2080
2081   if (*first)
2082     {
2083       *first = 0;
2084     }
2085   else
2086     {
2087       printf_filtered (", ");
2088     }
2089
2090   wrap_here ("");
2091   fputs_filtered (name, stdout);
2092 }  
2093
2094 static void
2095 sources_info (ignore, from_tty)
2096      char *ignore;
2097      int from_tty;
2098 {
2099   register struct symtab *s;
2100   register struct partial_symtab *ps;
2101   register struct objfile *objfile;
2102   int first;
2103   
2104   if (!have_full_symbols () && !have_partial_symbols ())
2105     {
2106       error (no_symtab_msg);
2107     }
2108   
2109   printf_filtered ("Source files for which symbols have been read in:\n\n");
2110
2111   first = 1;
2112   ALL_SYMTABS (objfile, s)
2113     {
2114       output_source_filename (s -> filename, &first);
2115     }
2116   printf_filtered ("\n\n");
2117   
2118   printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2119
2120   first = 1;
2121   ALL_PSYMTABS (objfile, ps)
2122     {
2123       if (!ps->readin)
2124         {
2125           output_source_filename (ps -> filename, &first);
2126         }
2127     }
2128   printf_filtered ("\n");
2129 }
2130
2131 static int
2132 name_match (name)
2133      char *name;
2134 {
2135   char *demangled = cplus_demangle (name, DMGL_ANSI);
2136   if (demangled != NULL)
2137     {
2138       int cond = re_exec (demangled);
2139       free (demangled);
2140       return (cond);
2141     }
2142   return (re_exec (name));
2143 }
2144 #define NAME_MATCH(NAME) name_match(NAME)
2145
2146 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2147    If CLASS is zero, list all symbols except functions, type names, and
2148                      constants (enums).
2149    If CLASS is 1, list only functions.
2150    If CLASS is 2, list only type names.
2151    If CLASS is 3, list only method names.
2152
2153    BPT is non-zero if we should set a breakpoint at the functions
2154    we find.  */
2155
2156 static void
2157 list_symbols (regexp, class, bpt)
2158      char *regexp;
2159      int class;
2160      int bpt;
2161 {
2162   register struct symtab *s;
2163   register struct partial_symtab *ps;
2164   register struct blockvector *bv;
2165   struct blockvector *prev_bv = 0;
2166   register struct block *b;
2167   register int i, j;
2168   register struct symbol *sym;
2169   struct partial_symbol *psym;
2170   struct objfile *objfile;
2171   struct minimal_symbol *msymbol;
2172   char *val;
2173   static char *classnames[]
2174     = {"variable", "function", "type", "method"};
2175   int found_in_file = 0;
2176   int found_misc = 0;
2177   static enum minimal_symbol_type types[]
2178     = {mst_data, mst_text, mst_abs, mst_unknown};
2179   static enum minimal_symbol_type types2[]
2180     = {mst_bss,  mst_text, mst_abs, mst_unknown};
2181   enum minimal_symbol_type ourtype = types[class];
2182   enum minimal_symbol_type ourtype2 = types2[class];
2183
2184   if (regexp)
2185     {
2186       /* Make sure spacing is right for C++ operators.
2187          This is just a courtesy to make the matching less sensitive
2188          to how many spaces the user leaves between 'operator'
2189          and <TYPENAME> or <OPERATOR>. */
2190       char *opend;
2191       char *opname = operator_chars (regexp, &opend);
2192       if (*opname)
2193         {
2194           int fix = -1; /* -1 means ok; otherwise number of spaces needed. */
2195           if (isalpha(*opname) || *opname == '_' || *opname == '$')
2196             {
2197               /* There should 1 space between 'operator' and 'TYPENAME'. */
2198               if (opname[-1] != ' ' || opname[-2] == ' ')
2199                 fix = 1;
2200             }
2201           else
2202             {
2203               /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2204               if (opname[-1] == ' ')
2205                 fix = 0;
2206             }
2207           /* If wrong number of spaces, fix it. */
2208           if (fix >= 0)
2209             {
2210               char *tmp = (char*) alloca(opend-opname+10);
2211               sprintf(tmp, "operator%.*s%s", fix, " ", opname);
2212               regexp = tmp;
2213             }
2214         }
2215       
2216       if (0 != (val = re_comp (regexp)))
2217         error ("Invalid regexp (%s): %s", val, regexp);
2218     }
2219
2220   /* Search through the partial symtabs *first* for all symbols
2221      matching the regexp.  That way we don't have to reproduce all of
2222      the machinery below. */
2223
2224   ALL_PSYMTABS (objfile, ps)
2225     {
2226       struct partial_symbol *bound, *gbound, *sbound;
2227       int keep_going = 1;
2228       
2229       if (ps->readin) continue;
2230       
2231       gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms;
2232       sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms;
2233       bound = gbound;
2234       
2235       /* Go through all of the symbols stored in a partial
2236          symtab in one loop. */
2237       psym = objfile->global_psymbols.list + ps->globals_offset;
2238       while (keep_going)
2239         {
2240           if (psym >= bound)
2241             {
2242               if (bound == gbound && ps->n_static_syms != 0)
2243                 {
2244                   psym = objfile->static_psymbols.list + ps->statics_offset;
2245                   bound = sbound;
2246                 }
2247               else
2248                 keep_going = 0;
2249               continue;
2250             }
2251           else
2252             {
2253               QUIT;
2254
2255               /* If it would match (logic taken from loop below)
2256                  load the file and go on to the next one */
2257               if ((regexp == 0 || NAME_MATCH (SYMBOL_NAME (psym)))
2258                   && ((class == 0 && SYMBOL_CLASS (psym) != LOC_TYPEDEF
2259                        && SYMBOL_CLASS (psym) != LOC_BLOCK)
2260                       || (class == 1 && SYMBOL_CLASS (psym) == LOC_BLOCK)
2261                       || (class == 2 && SYMBOL_CLASS (psym) == LOC_TYPEDEF)
2262                       || (class == 3 && SYMBOL_CLASS (psym) == LOC_BLOCK)))
2263                 {
2264                   PSYMTAB_TO_SYMTAB(ps);
2265                   keep_going = 0;
2266                 }
2267             }
2268           psym++;
2269         }
2270     }
2271
2272   /* Here, we search through the minimal symbol tables for functions that
2273      match, and call find_pc_symtab on them to force their symbols to
2274      be read.  The symbol will then be found during the scan of symtabs
2275      below.  If find_pc_symtab fails, set found_misc so that we will
2276      rescan to print any matching symbols without debug info.  */
2277
2278   if (class == 1)
2279     {
2280       ALL_MSYMBOLS (objfile, msymbol)
2281         {
2282           if (msymbol -> type == ourtype || msymbol -> type == ourtype2)
2283             {
2284               if (regexp == 0 || NAME_MATCH (msymbol -> name))
2285                 {
2286                   if (0 == find_pc_symtab (msymbol -> address))
2287                     {
2288                       found_misc = 1;
2289                     }
2290                 }
2291             }
2292         }
2293     }
2294
2295   /* Printout here so as to get after the "Reading in symbols"
2296      messages which will be generated above.  */
2297   if (!bpt)
2298     printf_filtered (regexp
2299           ? "All %ss matching regular expression \"%s\":\n"
2300           : "All defined %ss:\n",
2301           classnames[class],
2302           regexp);
2303
2304   ALL_SYMTABS (objfile, s)
2305     {
2306       found_in_file = 0;
2307       bv = BLOCKVECTOR (s);
2308       /* Often many files share a blockvector.
2309          Scan each blockvector only once so that
2310          we don't get every symbol many times.
2311          It happens that the first symtab in the list
2312          for any given blockvector is the main file.  */
2313       if (bv != prev_bv)
2314         for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
2315           {
2316             b = BLOCKVECTOR_BLOCK (bv, i);
2317             /* Skip the sort if this block is always sorted.  */
2318             if (!BLOCK_SHOULD_SORT (b))
2319               sort_block_syms (b);
2320             for (j = 0; j < BLOCK_NSYMS (b); j++)
2321               {
2322                 QUIT;
2323                 sym = BLOCK_SYM (b, j);
2324                 if ((regexp == 0 || NAME_MATCH (SYMBOL_NAME (sym)))
2325                     && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
2326                          && SYMBOL_CLASS (sym) != LOC_BLOCK
2327                          && SYMBOL_CLASS (sym) != LOC_CONST)
2328                         || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)
2329                         || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2330                         || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK)))
2331                   {
2332                     if (bpt)
2333                       {
2334                         /* Set a breakpoint here, if it's a function */
2335                         if (class == 1)
2336                           break_command (SYMBOL_NAME(sym), 0);
2337                       }
2338                     else if (!found_in_file)
2339                       {
2340                         fputs_filtered ("\nFile ", stdout);
2341                         fputs_filtered (s->filename, stdout);
2342                         fputs_filtered (":\n", stdout);
2343                       }
2344                     found_in_file = 1;
2345                     
2346                     if (class != 2 && i == STATIC_BLOCK)
2347                       printf_filtered ("static ");
2348                     
2349                     /* Typedef that is not a C++ class */
2350                     if (class == 2
2351                         && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
2352                       typedef_print (SYMBOL_TYPE(sym), sym, stdout);
2353                     /* variable, func, or typedef-that-is-c++-class */
2354                     else if (class < 2 || 
2355                              (class == 2 && 
2356                               SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE))
2357                       {
2358                         type_print (SYMBOL_TYPE (sym),
2359                                     (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2360                                      ? "" : SYMBOL_NAME (sym)),
2361                                     stdout, 0);
2362                         
2363                         printf_filtered (";\n");
2364                       }
2365                     else
2366                       {
2367 # if 0
2368 /* FIXME, why is this zapped out? */
2369                         char buf[1024];
2370                         type_print_base (TYPE_FN_FIELD_TYPE(t, i), stdout, 0, 0); 
2371                         type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i), stdout, 0); 
2372                         sprintf (buf, " %s::", type_name_no_tag (t));
2373                         type_print_method_args (TYPE_FN_FIELD_ARGS (t, i), buf, name, stdout);
2374 # endif
2375                       }
2376                   }
2377               }
2378           }
2379       prev_bv = bv;
2380     }
2381
2382   /* If there are no eyes, avoid all contact.  I mean, if there are
2383      no debug symbols, then print directly from the msymbol_vector.  */
2384
2385   if (found_misc || class != 1)
2386     {
2387       found_in_file = 0;
2388       ALL_MSYMBOLS (objfile, msymbol)
2389         {
2390           if (msymbol -> type == ourtype || msymbol -> type == ourtype2)
2391             {
2392               if (regexp == 0 || NAME_MATCH (msymbol -> name))
2393                 {
2394                   /* Functions:  Look up by address. */
2395                   if (class != 1 ||
2396                       (0 == find_pc_symtab (msymbol -> address)))
2397                     {
2398                       /* Variables/Absolutes:  Look up by name */
2399                       if (lookup_symbol (msymbol -> name, 
2400                                          (struct block *) 0, VAR_NAMESPACE, 0,
2401                                          (struct symtab **) 0) == NULL)
2402                         {
2403                           if (!found_in_file)
2404                             {
2405                               printf_filtered ("\nNon-debugging symbols:\n");
2406                               found_in_file = 1;
2407                             }
2408                           printf_filtered ("    %08x  %s\n",
2409                                            msymbol -> address,
2410                                            msymbol -> name);
2411                         }
2412                     }
2413                 }
2414             }
2415         }
2416     }
2417 }
2418
2419 static void
2420 variables_info (regexp, from_tty)
2421      char *regexp;
2422      int from_tty;
2423 {
2424   list_symbols (regexp, 0, 0);
2425 }
2426
2427 static void
2428 functions_info (regexp, from_tty)
2429      char *regexp;
2430      int from_tty;
2431 {
2432   list_symbols (regexp, 1, 0);
2433 }
2434
2435 static void
2436 types_info (regexp, from_tty)
2437      char *regexp;
2438      int from_tty;
2439 {
2440   list_symbols (regexp, 2, 0);
2441 }
2442
2443 #if 0
2444 /* Tiemann says: "info methods was never implemented."  */
2445 static void
2446 methods_info (regexp)
2447      char *regexp;
2448 {
2449   list_symbols (regexp, 3, 0);
2450 }
2451 #endif /* 0 */
2452
2453 /* Breakpoint all functions matching regular expression. */
2454 static void
2455 rbreak_command (regexp, from_tty)
2456      char *regexp;
2457      int from_tty;
2458 {
2459   list_symbols (regexp, 1, 1);
2460 }
2461 \f
2462
2463 /* Return Nonzero if block a is lexically nested within block b,
2464    or if a and b have the same pc range.
2465    Return zero otherwise. */
2466 int
2467 contained_in (a, b)
2468      struct block *a, *b;
2469 {
2470   if (!a || !b)
2471     return 0;
2472   return BLOCK_START (a) >= BLOCK_START (b)
2473       && BLOCK_END (a)   <= BLOCK_END (b);
2474 }
2475
2476 \f
2477 /* Helper routine for make_symbol_completion_list.  */
2478
2479 static int return_val_size;
2480 static int return_val_index;
2481 static char **return_val;
2482
2483 /*  Test to see if the symbol specified by SYMNAME (or it's demangled
2484     equivalent) matches TEXT in the first TEXT_LEN characters.  If so,
2485     add it to the current completion list. */
2486
2487 static void
2488 completion_list_add_symbol (symname, text, text_len)
2489      char *symname;
2490      char *text;
2491      int text_len;
2492 {
2493   char *demangled;
2494   int newsize;
2495   int i;
2496
2497   /* clip symbols that cannot match */
2498
2499   if (!cplus_match (symname, text, text_len)) {
2500     return;
2501   }
2502
2503   /* matches mangled, may match unmangled.  now clip any symbol names
2504      that we've already considered.  (This is a time optimization)  */
2505
2506   for (i = 0; i < return_val_index; ++i) {
2507     if (strcmp (symname, return_val[i]) == 0) {
2508       return;
2509     }
2510   }
2511   
2512   /* See if SYMNAME is a C++ mangled name, and if so, use the
2513      demangled name instead, including any parameters.  */
2514
2515   if ((demangled = cplus_demangle (symname, DMGL_PARAMS | DMGL_ANSI)) != NULL)
2516     {
2517       if (strncmp (demangled, text, text_len) != 0) {
2518         return;
2519       } /* demangled, but didn't match so clip it */
2520
2521       symname = demangled;
2522     } else {
2523       symname = savestring (symname, strlen (symname));
2524     }
2525
2526   /* If we have a match for a completion, then add SYMNAME to the current
2527      list of matches. Note that the name is in freshly malloc'd space;
2528      either from cplus_demangle or from savestring above.  */
2529
2530   if (return_val_index + 3 > return_val_size)
2531     {
2532       newsize = (return_val_size *= 2) * sizeof (char *);
2533       return_val = (char **) xrealloc ((char *) return_val, newsize);
2534     }
2535   return_val[return_val_index++] = symname;
2536   return_val[return_val_index] = NULL;
2537
2538   return;
2539 }
2540
2541 /* Return a NULL terminated array of all symbols (regardless of class) which
2542    begin by matching TEXT.  If the answer is no symbols, then the return value
2543    is an array which contains only a NULL pointer.
2544
2545    Problem: All of the symbols have to be copied because readline frees them.
2546    I'm not going to worry about this; hopefully there won't be that many.  */
2547
2548 char **
2549 make_symbol_completion_list (text)
2550   char *text;
2551 {
2552   register struct symbol *sym;
2553   register struct symtab *s;
2554   register struct partial_symtab *ps;
2555   register struct minimal_symbol *msymbol;
2556   register struct objfile *objfile;
2557   register struct block *b, *surrounding_static_block = 0;
2558   register int i, j;
2559   int text_len;
2560   struct partial_symbol *psym;
2561
2562   text_len = strlen (text);
2563   return_val_size = 100;
2564   return_val_index = 0;
2565   return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
2566   return_val[0] = NULL;
2567
2568   /* Look through the partial symtabs for all symbols which begin
2569      by matching TEXT.  Add each one that you find to the list.  */
2570
2571   ALL_PSYMTABS (objfile, ps)
2572     {
2573       /* If the psymtab's been read in we'll get it when we search
2574          through the blockvector.  */
2575       if (ps->readin) continue;
2576       
2577       for (psym = objfile->global_psymbols.list + ps->globals_offset;
2578            psym < (objfile->global_psymbols.list + ps->globals_offset
2579                    + ps->n_global_syms);
2580            psym++)
2581         {
2582           /* If interrupted, then quit. */
2583           QUIT;
2584           completion_list_add_symbol (SYMBOL_NAME (psym), text, text_len);
2585         }
2586       
2587       for (psym = objfile->static_psymbols.list + ps->statics_offset;
2588            psym < (objfile->static_psymbols.list + ps->statics_offset
2589                    + ps->n_static_syms);
2590            psym++)
2591         {
2592           QUIT;
2593           completion_list_add_symbol (SYMBOL_NAME (psym), text, text_len);
2594         }
2595     }
2596
2597   /* At this point scan through the misc symbol vectors and add each
2598      symbol you find to the list.  Eventually we want to ignore
2599      anything that isn't a text symbol (everything else will be
2600      handled by the psymtab code above).  */
2601
2602   ALL_MSYMBOLS (objfile, msymbol)
2603     {
2604       QUIT;
2605       completion_list_add_symbol (msymbol -> name, text, text_len);
2606     }
2607
2608   /* Search upwards from currently selected frame (so that we can
2609      complete on local vars.  */
2610
2611   for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b))
2612     {
2613       if (!BLOCK_SUPERBLOCK (b))
2614         {
2615           surrounding_static_block = b;         /* For elmin of dups */
2616         }
2617       
2618       /* Also catch fields of types defined in this places which match our
2619          text string.  Only complete on types visible from current context. */
2620
2621       for (i = 0; i < BLOCK_NSYMS (b); i++)
2622         {
2623           sym = BLOCK_SYM (b, i);
2624           completion_list_add_symbol (SYMBOL_NAME (sym), text, text_len);
2625           if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2626             {
2627               struct type *t = SYMBOL_TYPE (sym);
2628               enum type_code c = TYPE_CODE (t);
2629
2630               if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
2631                 {
2632                   for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
2633                     {
2634                       if (TYPE_FIELD_NAME (t, j))
2635                         {
2636                           completion_list_add_symbol (TYPE_FIELD_NAME (t, j),
2637                                                       text, text_len);
2638                         }
2639                     }
2640                 }
2641             }
2642         }
2643     }
2644
2645   /* Go through the symtabs and check the externs and statics for
2646      symbols which match.  */
2647
2648   ALL_SYMTABS (objfile, s)
2649     {
2650       QUIT;
2651       b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
2652       for (i = 0; i < BLOCK_NSYMS (b); i++)
2653         {
2654           sym = BLOCK_SYM (b, i);
2655           completion_list_add_symbol (SYMBOL_NAME (sym), text, text_len);
2656         }
2657     }
2658
2659   ALL_SYMTABS (objfile, s)
2660     {
2661       QUIT;
2662       b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
2663       /* Don't do this block twice.  */
2664       if (b == surrounding_static_block) continue;
2665       for (i = 0; i < BLOCK_NSYMS (b); i++)
2666         {
2667           sym = BLOCK_SYM (b, i);
2668           completion_list_add_symbol (SYMBOL_NAME (sym), text, text_len);
2669         }
2670     }
2671
2672   return (return_val);
2673 }
2674
2675 \f
2676 /* Find a mangled symbol that corresponds to LOOKFOR using brute force.
2677    Basically we go munging through available symbols, demangling each one,
2678    looking for a match on the demangled result. */
2679
2680 static char *
2681 expensive_mangler (lookfor)
2682      const char *lookfor;
2683 {
2684   register struct symbol *sym;
2685   register struct symtab *s;
2686   register struct partial_symtab *ps;
2687   register struct minimal_symbol *msymbol;
2688   register struct objfile *objfile;
2689   register struct block *b, *surrounding_static_block = 0;
2690   register int i, j;
2691   struct partial_symbol *psym;
2692   char *demangled;
2693
2694   /* Look through the partial symtabs for a symbol that matches */
2695
2696   ALL_PSYMTABS (objfile, ps)
2697     {
2698       /* If the psymtab's been read in we'll get it when we search
2699          through the blockvector.  */
2700       if (ps->readin) continue;
2701       
2702       for (psym = objfile->global_psymbols.list + ps->globals_offset;
2703            psym < (objfile->global_psymbols.list + ps->globals_offset
2704                    + ps->n_global_syms);
2705            psym++)
2706         {
2707           QUIT;                 /* If interrupted, then quit. */
2708           demangled = demangle_and_match (SYMBOL_NAME (psym), lookfor,
2709                                           DMGL_PARAMS | DMGL_ANSI);
2710           if (demangled != NULL)
2711             {
2712               free (demangled);
2713               return (SYMBOL_NAME (psym));
2714             }
2715         }
2716       
2717       for (psym = objfile->static_psymbols.list + ps->statics_offset;
2718            psym < (objfile->static_psymbols.list + ps->statics_offset
2719                    + ps->n_static_syms);
2720            psym++)
2721         {
2722           QUIT;
2723           demangled = demangle_and_match (SYMBOL_NAME (psym), lookfor,
2724                                           DMGL_PARAMS | DMGL_ANSI);
2725           if (demangled != NULL)
2726             {
2727               free (demangled);
2728               return (SYMBOL_NAME (psym));
2729             }
2730         }
2731     }
2732
2733   /* Scan through the misc symbol vectors looking for a match. */
2734
2735   ALL_MSYMBOLS (objfile, msymbol)
2736     {
2737       QUIT;
2738       demangled = demangle_and_match (msymbol -> name, lookfor,
2739                                       DMGL_PARAMS | DMGL_ANSI);
2740       if (demangled != NULL)
2741         {
2742           free (demangled);
2743           return (msymbol -> name);
2744         }
2745     }
2746
2747   /* Search upwards from currently selected frame looking for a match */
2748
2749   for (b = get_selected_block (); b; b = BLOCK_SUPERBLOCK (b))
2750     {
2751       if (!BLOCK_SUPERBLOCK (b))
2752         surrounding_static_block = b; /* For elmin of dups */
2753       
2754       /* Also catch fields of types defined in this places which
2755          match our text string.  Only complete on types visible
2756          from current context.  */
2757       for (i = 0; i < BLOCK_NSYMS (b); i++)
2758         {
2759           sym = BLOCK_SYM (b, i);
2760           demangled = demangle_and_match (SYMBOL_NAME (sym), lookfor,
2761                                           DMGL_PARAMS | DMGL_ANSI);
2762           if (demangled != NULL)
2763             {
2764               free (demangled);
2765               return (SYMBOL_NAME (sym));
2766             }
2767           if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2768             {
2769               struct type *t = SYMBOL_TYPE (sym);
2770               enum type_code c = TYPE_CODE (t);
2771
2772               if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
2773                 {
2774                   for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
2775                     {
2776                       if (TYPE_FIELD_NAME (t, j))
2777                         {
2778                           demangled =
2779                             demangle_and_match (TYPE_FIELD_NAME (t, j),
2780                                                 lookfor,
2781                                                 DMGL_PARAMS | DMGL_ANSI);
2782                           if (demangled != NULL)
2783                             {
2784                               free (demangled);
2785                               return (TYPE_FIELD_NAME (t, j));
2786                             }
2787                         }
2788                     }
2789                 }
2790             }
2791         }
2792     }
2793
2794   /* Go through the symtabs and check the externs and statics for
2795      symbols which match.  */
2796
2797   ALL_SYMTABS (objfile, s)
2798     {
2799       QUIT;
2800       b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
2801       for (i = 0; i < BLOCK_NSYMS (b); i++)
2802         {
2803           sym = BLOCK_SYM (b, i);
2804           demangled = demangle_and_match (SYMBOL_NAME (sym), lookfor,
2805                                           DMGL_PARAMS | DMGL_ANSI);
2806           if (demangled != NULL)
2807             {
2808               free (demangled);
2809               return (SYMBOL_NAME (sym));
2810             }
2811         }
2812     }
2813
2814   ALL_SYMTABS (objfile, s)
2815     {
2816       QUIT;
2817       b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
2818       /* Don't do this block twice.  */
2819       if (b == surrounding_static_block) continue;
2820       for (i = 0; i < BLOCK_NSYMS (b); i++)
2821         {
2822           sym = BLOCK_SYM (b, i);
2823           demangled = demangle_and_match (SYMBOL_NAME (sym), lookfor,
2824                                           DMGL_PARAMS | DMGL_ANSI);
2825           if (demangled != NULL)
2826             {
2827               free (demangled);
2828               return (SYMBOL_NAME (sym));
2829             }
2830         }
2831     }
2832
2833   return (NULL);
2834 }
2835
2836 \f
2837 #if 0
2838 /* Add the type of the symbol sym to the type of the current
2839    function whose block we are in (assumed).  The type of
2840    this current function is contained in *TYPE.
2841    
2842    This basically works as follows:  When we find a function
2843    symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record
2844    a pointer to its type in the global in_function_type.  Every 
2845    time we come across a parameter symbol ('p' in its name), then
2846    this procedure adds the name and type of that parameter
2847    to the function type pointed to by *TYPE.  (Which should correspond
2848    to in_function_type if it was called correctly).
2849
2850    Note that since we are modifying a type, the result of 
2851    lookup_function_type() should be memcpy()ed before calling
2852    this.  When not in strict typing mode, the expression
2853    evaluator can choose to ignore this.
2854
2855    Assumption:  All of a function's parameter symbols will
2856    appear before another function symbol is found.  The parameters 
2857    appear in the same order in the argument list as they do in the
2858    symbol table. */
2859
2860 void
2861 add_param_to_type (type,sym)
2862    struct type **type;
2863    struct symbol *sym;
2864 {
2865    int num = ++(TYPE_NFIELDS(*type));
2866
2867    if(TYPE_NFIELDS(*type)-1)
2868       TYPE_FIELDS(*type) = (struct field *)
2869           (*current_objfile->xrealloc) ((char *)(TYPE_FIELDS(*type)),
2870                                         num*sizeof(struct field));
2871    else
2872       TYPE_FIELDS(*type) = (struct field *)
2873           (*current_objfile->xmalloc) (num*sizeof(struct field));
2874    
2875    TYPE_FIELD_BITPOS(*type,num-1) = num-1;
2876    TYPE_FIELD_BITSIZE(*type,num-1) = 0;
2877    TYPE_FIELD_TYPE(*type,num-1) = SYMBOL_TYPE(sym);
2878    TYPE_FIELD_NAME(*type,num-1) = SYMBOL_NAME(sym);
2879 }
2880 #endif 
2881 \f
2882 void
2883 _initialize_symtab ()
2884 {
2885   add_info ("variables", variables_info,
2886             "All global and static variable names, or those matching REGEXP.");
2887   add_info ("functions", functions_info,
2888             "All function names, or those matching REGEXP.");
2889
2890   /* FIXME:  This command has at least the following problems:
2891      1.  It prints builtin types (in a very strange and confusing fashion).
2892      2.  It doesn't print right, e.g. with
2893          typedef struct foo *FOO
2894          type_print prints "FOO" when we want to make it (in this situation)
2895          print "struct foo *".
2896      I also think "ptype" or "whatis" is more likely to be useful (but if
2897      there is much disagreement "info types" can be fixed).  */
2898   add_info ("types", types_info,
2899             "All type names, or those matching REGEXP.");
2900
2901 #if 0
2902   add_info ("methods", methods_info,
2903             "All method names, or those matching REGEXP::REGEXP.\n\
2904 If the class qualifier is omitted, it is assumed to be the current scope.\n\
2905 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
2906 are listed.");
2907 #endif
2908   add_info ("sources", sources_info,
2909             "Source files in the program.");
2910
2911   add_com ("rbreak", no_class, rbreak_command,
2912             "Set a breakpoint for all functions matching REGEXP.");
2913
2914   /* Initialize the one built-in type that isn't language dependent... */
2915   builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0,
2916                                   "<unknown type>", (struct objfile *) NULL);
2917 }