1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
3 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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. */
31 #include "call-cmds.h"
33 #include "expression.h"
39 #include <sys/types.h>
45 /* Prototypes for local functions */
48 find_methods PARAMS ((struct type *, char *, char **, struct symbol **));
51 completion_list_add_symbol PARAMS ((char *));
53 static struct symtabs_and_lines
54 decode_line_2 PARAMS ((struct symbol *[], int, int));
57 rbreak_command PARAMS ((char *, int));
60 types_info PARAMS ((char *, int));
63 functions_info PARAMS ((char *, int));
66 variables_info PARAMS ((char *, int));
69 sources_info PARAMS ((char *, int));
72 list_symbols PARAMS ((char *, int, int));
75 output_source_filename PARAMS ((char *, int *));
78 operator_chars PARAMS ((char *, char **));
81 find_line_common PARAMS ((struct linetable *, int, int *));
83 static struct partial_symbol *
84 lookup_partial_symbol PARAMS ((struct partial_symtab *, const char *,
85 int, enum namespace));
87 static struct partial_symbol *
88 lookup_demangled_partial_symbol PARAMS ((const struct partial_symtab *,
91 static struct symbol *
92 lookup_demangled_block_symbol PARAMS ((const struct block *, const char *));
94 static struct symtab *
95 lookup_symtab_1 PARAMS ((char *));
99 /* The single non-language-specific builtin type */
100 struct type *builtin_type_error;
102 /* Block in which the most recently searched-for symbol was found.
103 Might be better to make this a parameter to lookup_symbol and
106 const struct block *block_found;
108 char no_symtab_msg[] = "No symbol table is loaded. Use the \"file\" command.";
110 /* Check for a symtab of a specific name; first in symtabs, then in
111 psymtabs. *If* there is no '/' in the name, a match after a '/'
112 in the symtab filename will also work. */
114 static struct symtab *
115 lookup_symtab_1 (name)
118 register struct symtab *s;
119 register struct partial_symtab *ps;
120 register char *slash;
122 register struct objfile *objfile;
124 ALL_SYMTABS (objfile, s)
126 if (strcmp (name, s->filename) == 0)
132 ALL_PSYMTABS (objfile, ps)
134 if (strcmp (name, ps -> filename) == 0)
138 error ("Internal: readin pst for `%s' found when no symtab found.", name);
140 return (PSYMTAB_TO_SYMTAB (ps));
144 slash = strchr (name, '/');
149 ALL_SYMTABS (objfile, s)
151 int l = strlen (s->filename);
154 && s->filename[l - len -1] == '/'
155 && (strcmp (s->filename + l - len, name) == 0))
161 ALL_PSYMTABS (objfile, ps)
163 int l = strlen (ps -> filename);
166 && ps -> filename[l - len - 1] == '/'
167 && (strcmp (ps->filename + l - len, name) == 0))
171 error ("Internal: readin pst for `%s' found when no symtab found.", name);
173 return (PSYMTAB_TO_SYMTAB (ps));
180 /* Lookup the symbol table of a source file named NAME. Try a couple
181 of variations if the first lookup doesn't work. */
187 register struct symtab *s;
190 s = lookup_symtab_1 (name);
193 /* If name not found as specified, see if adding ".c" helps. */
195 copy = (char *) alloca (strlen (name) + 3);
198 s = lookup_symtab_1 (copy);
201 /* We didn't find anything; die. */
205 /* Lookup the partial symbol table of a source file named NAME. This
206 only returns true on an exact match (ie. this semantics are
207 different from lookup_symtab. */
209 struct partial_symtab *
210 lookup_partial_symtab (name)
213 register struct partial_symtab *pst;
214 register struct objfile *objfile;
216 ALL_PSYMTABS (objfile, pst)
218 if (strcmp (name, pst -> filename) == 0)
226 /* Demangle a GDB method stub type. */
228 gdb_mangle_name (type, i, j)
232 int mangled_name_len;
234 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
235 struct fn_field *method = &f[j];
236 char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
237 int is_constructor = strcmp(field_name, TYPE_NAME (type)) == 0;
239 /* Need a new type prefix. */
240 char *const_prefix = method->is_const ? "C" : "";
241 char *volatile_prefix = method->is_volatile ? "V" : "";
242 char *newname = type_name_no_tag (type);
244 int len = strlen (newname);
246 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
247 mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
249 + strlen (TYPE_FN_FIELD_PHYSNAME (f, j))
252 /* Only needed for GNU-mangled names. ANSI-mangled names
253 work with the normal mechanisms. */
254 if (OPNAME_PREFIX_P (field_name))
256 char *opname = cplus_mangle_opname (field_name + 3, 0);
258 error ("No mangling for \"%s\"", field_name);
259 mangled_name_len += strlen (opname);
260 mangled_name = (char *)xmalloc (mangled_name_len);
262 strncpy (mangled_name, field_name, 3);
263 mangled_name[3] = '\0';
264 strcat (mangled_name, opname);
268 mangled_name = (char *)xmalloc (mangled_name_len);
270 mangled_name[0] = '\0';
272 strcpy (mangled_name, field_name);
274 strcat (mangled_name, buf);
275 strcat (mangled_name, newname);
276 strcat (mangled_name, TYPE_FN_FIELD_PHYSNAME (f, j));
282 /* Find which partial symtab on contains PC. Return 0 if none. */
284 struct partial_symtab *
286 register CORE_ADDR pc;
288 register struct partial_symtab *pst;
289 register struct objfile *objfile;
291 ALL_PSYMTABS (objfile, pst)
293 if (pc >= pst -> textlow && pc < pst -> texthigh)
301 /* Find which partial symbol within a psymtab contains PC. Return 0
302 if none. Check all psymtabs if PSYMTAB is 0. */
303 struct partial_symbol *
304 find_pc_psymbol (psymtab, pc)
305 struct partial_symtab *psymtab;
308 struct partial_symbol *best, *p;
312 psymtab = find_pc_psymtab (pc);
316 best_pc = psymtab->textlow - 1;
318 for (p = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
319 (p - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
320 < psymtab->n_static_syms);
322 if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
323 && SYMBOL_CLASS (p) == LOC_BLOCK
324 && pc >= SYMBOL_VALUE_ADDRESS (p)
325 && SYMBOL_VALUE_ADDRESS (p) > best_pc)
327 best_pc = SYMBOL_VALUE_ADDRESS (p);
330 if (best_pc == psymtab->textlow - 1)
336 /* Find the definition for a specified symbol name NAME
337 in namespace NAMESPACE, visible from lexical block BLOCK.
338 Returns the struct symbol pointer, or zero if no symbol is found.
339 If SYMTAB is non-NULL, store the symbol table in which the
340 symbol was found there, or NULL if not found.
341 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
342 NAME is a field of the current implied argument `this'. If so set
343 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
344 BLOCK_FOUND is set to the block in which NAME is found (in the case of
345 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
348 lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
350 register const struct block *block;
351 const enum namespace namespace;
352 int *is_a_field_of_this;
353 struct symtab **symtab;
355 register struct symbol *sym;
356 register struct symtab *s;
357 register struct partial_symtab *ps;
358 struct blockvector *bv;
359 register struct objfile *objfile;
360 register struct block *b;
361 register struct minimal_symbol *msymbol;
363 /* Search specified block and its superiors. */
367 sym = lookup_block_symbol (block, name, namespace);
373 /* Search the list of symtabs for one which contains the
374 address of the start of this block. */
375 ALL_SYMTABS (objfile, s)
377 bv = BLOCKVECTOR (s);
378 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
379 if (BLOCK_START (b) <= BLOCK_START (block)
380 && BLOCK_END (b) > BLOCK_START (block))
389 block = BLOCK_SUPERBLOCK (block);
392 /* But that doesn't do any demangling for the STATIC_BLOCK.
393 I'm not sure whether demangling is needed in the case of
394 nested function in inner blocks; if so this needs to be changed.
396 Don't need to mess with the psymtabs; if we have a block,
397 that file is read in. If we don't, then we deal later with
398 all the psymtab stuff that needs checking. */
399 if (namespace == VAR_NAMESPACE && block != NULL)
402 /* Find the right symtab. */
403 ALL_SYMTABS (objfile, s)
405 bv = BLOCKVECTOR (s);
406 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
407 if (BLOCK_START (b) <= BLOCK_START (block)
408 && BLOCK_END (b) > BLOCK_START (block))
410 sym = lookup_demangled_block_symbol (b, name);
423 /* C++: If requested to do so by the caller,
424 check to see if NAME is a field of `this'. */
425 if (is_a_field_of_this)
427 struct value *v = value_of_this (0);
429 *is_a_field_of_this = 0;
430 if (v && check_field (v, name))
432 *is_a_field_of_this = 1;
439 /* Now search all global blocks. Do the symtab's first, then
440 check the psymtab's */
442 ALL_SYMTABS (objfile, s)
444 bv = BLOCKVECTOR (s);
445 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
446 sym = lookup_block_symbol (block, name, namespace);
456 /* Check for the possibility of the symbol being a global function
457 that is stored in one of the minimal symbol tables. Eventually, all
458 global symbols might be resolved in this way. */
460 if (namespace == VAR_NAMESPACE)
462 msymbol = lookup_minimal_symbol (name, (struct objfile *) NULL);
466 /* Test each minimal symbol to see if the minimal symbol's name
467 is a C++ mangled name that matches a user visible name. */
469 int matchcount = strlen (name);
472 ALL_MSYMBOLS (objfile, msymbol)
474 if (strncmp (msymbol -> name, name, matchcount) == 0)
476 demangled = cplus_demangle (msymbol -> name, -1);
477 if (demangled != NULL)
479 if (strcmp (demangled, name) == 0)
491 if (msymbol != NULL && msymbol -> name != NULL)
493 s = find_pc_symtab (msymbol -> address);
494 /* If S is NULL, there are no debug symbols for this file.
495 Skip this stuff and check for matching static symbols below. */
498 bv = BLOCKVECTOR (s);
499 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
500 sym = lookup_block_symbol (block, msymbol -> name, namespace);
501 /* We kept static functions in minimal symbol table as well as
502 in static scope. We want to find them in the symbol table. */
504 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
505 sym = lookup_block_symbol (block, msymbol -> name,
509 /* sym == 0 if symbol was found in the minimal symbol table
510 but not in the symtab.
511 Return 0 to use the msymbol definition of "foo_".
513 This happens for Fortran "foo_" symbols,
514 which are "foo" in the symtab.
516 This can also happen if "asm" is used to make a
517 regular symbol but not a debugging symbol, e.g.
529 ALL_PSYMTABS (objfile, ps)
531 if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
533 s = PSYMTAB_TO_SYMTAB(ps);
534 bv = BLOCKVECTOR (s);
535 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
536 sym = lookup_block_symbol (block, name, namespace);
538 error ("Internal: global symbol `%s' found in psymtab but not in symtab", name);
545 /* Now search all per-file blocks.
546 Not strictly correct, but more useful than an error.
547 Do the symtabs first, then check the psymtabs */
549 ALL_SYMTABS (objfile, s)
551 bv = BLOCKVECTOR (s);
552 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
553 sym = lookup_block_symbol (block, name, namespace);
563 ALL_PSYMTABS (objfile, ps)
565 if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
567 s = PSYMTAB_TO_SYMTAB(ps);
568 bv = BLOCKVECTOR (s);
569 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
570 sym = lookup_block_symbol (block, name, namespace);
572 error ("Internal: static symbol `%s' found in psymtab but not in symtab", name);
579 /* Now search all per-file blocks for static mangled symbols.
580 Do the symtabs first, then check the psymtabs. */
582 if (namespace == VAR_NAMESPACE)
584 ALL_SYMTABS (objfile, s)
586 bv = BLOCKVECTOR (s);
587 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
588 sym = lookup_demangled_block_symbol (block, name);
598 ALL_PSYMTABS (objfile, ps)
600 if (!ps->readin && lookup_demangled_partial_symbol (ps, name))
602 s = PSYMTAB_TO_SYMTAB(ps);
603 bv = BLOCKVECTOR (s);
604 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
605 sym = lookup_demangled_block_symbol (block, name);
607 error ("Internal: mangled static symbol `%s' found in psymtab but not in symtab", name);
620 /* Look for a static demangled symbol in block BLOCK. */
622 static struct symbol *
623 lookup_demangled_block_symbol (block, name)
624 register const struct block *block;
627 register int bot, top, inc;
628 register struct symbol *sym;
631 top = BLOCK_NSYMS (block);
636 sym = BLOCK_SYM (block, bot);
637 if (SYMBOL_NAME (sym)[0] == inc
638 && SYMBOL_NAMESPACE (sym) == VAR_NAMESPACE)
640 char *demangled = cplus_demangle(SYMBOL_NAME (sym), -1);
641 if (demangled != NULL)
643 int cond = strcmp (demangled, name);
655 /* Look, in partial_symtab PST, for static mangled symbol NAME. */
657 static struct partial_symbol *
658 lookup_demangled_partial_symbol (pst, name)
659 const struct partial_symtab *pst;
662 struct partial_symbol *start, *psym;
663 int length = pst->n_static_syms;
664 register int inc = name[0];
667 return (struct partial_symbol *) 0;
669 start = pst->objfile->static_psymbols.list + pst->statics_offset;
670 for (psym = start; psym < start + length; psym++)
672 if (SYMBOL_NAME (psym)[0] == inc
673 && SYMBOL_NAMESPACE (psym) == VAR_NAMESPACE)
675 char *demangled = cplus_demangle(SYMBOL_NAME (psym), -1);
676 if (demangled != NULL)
678 int cond = strcmp (demangled, name);
686 return (struct partial_symbol *) 0;
689 /* Look, in partial_symtab PST, for symbol NAME. Check the global
690 symbols if GLOBAL, the static symbols if not */
692 static struct partial_symbol *
693 lookup_partial_symbol (pst, name, global, namespace)
694 struct partial_symtab *pst;
697 enum namespace namespace;
699 struct partial_symbol *start, *psym;
700 int length = (global ? pst->n_global_syms : pst->n_static_syms);
703 return (struct partial_symbol *) 0;
706 pst->objfile->global_psymbols.list + pst->globals_offset :
707 pst->objfile->static_psymbols.list + pst->statics_offset );
709 if (global) /* This means we can use a binary */
712 struct partial_symbol *top, *bottom, *center;
714 /* Binary search. This search is guaranteed to end with center
715 pointing at the earliest partial symbol with the correct
716 name. At that point *all* partial symbols with that name
717 will be checked against the correct namespace. */
719 top = start + length - 1;
722 center = bottom + (top - bottom) / 2;
724 assert (center < top);
726 if (strcmp (SYMBOL_NAME (center), name) >= 0)
731 assert (top == bottom);
733 while (!strcmp (SYMBOL_NAME (top), name))
735 if (SYMBOL_NAMESPACE (top) == namespace)
742 /* Can't use a binary search */
743 for (psym = start; psym < start + length; psym++)
744 if (namespace == SYMBOL_NAMESPACE (psym)
745 && !strcmp (name, SYMBOL_NAME (psym)))
749 return (struct partial_symbol *) 0;
752 /* Find the psymtab containing main(). */
754 struct partial_symtab *
757 register struct partial_symtab *pst;
758 register struct objfile *objfile;
760 ALL_PSYMTABS (objfile, pst)
762 if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE))
770 /* Look for a symbol in block BLOCK. */
773 lookup_block_symbol (block, name, namespace)
774 register const struct block *block;
776 const enum namespace namespace;
778 register int bot, top, inc;
779 register struct symbol *sym, *parameter_sym;
781 top = BLOCK_NSYMS (block);
784 /* If the blocks's symbols were sorted, start with a binary search. */
786 if (BLOCK_SHOULD_SORT (block))
788 /* First, advance BOT to not far before
789 the first symbol whose name is NAME. */
793 inc = (top - bot + 1);
794 /* No need to keep binary searching for the last few bits worth. */
797 inc = (inc >> 1) + bot;
798 sym = BLOCK_SYM (block, inc);
799 if (SYMBOL_NAME (sym)[0] < name[0])
801 else if (SYMBOL_NAME (sym)[0] > name[0])
803 else if (strcmp (SYMBOL_NAME (sym), name) < 0)
809 /* Now scan forward until we run out of symbols,
810 find one whose name is greater than NAME,
812 If there is more than one symbol with the right name and namespace,
813 we return the first one. dbxread.c is careful to make sure
814 that if one is a register then it comes first. */
816 top = BLOCK_NSYMS (block);
819 sym = BLOCK_SYM (block, bot);
820 inc = SYMBOL_NAME (sym)[0] - name[0];
822 inc = strcmp (SYMBOL_NAME (sym), name);
823 if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)
832 /* Here if block isn't sorted.
833 This loop is equivalent to the loop above,
834 but hacked greatly for speed.
836 Note that parameter symbols do not always show up last in the
837 list; this loop makes sure to take anything else other than
838 parameter symbols first; it only uses parameter symbols as a
839 last resort. Note that this only takes up extra computation
842 parameter_sym = (struct symbol *) 0;
843 top = BLOCK_NSYMS (block);
847 sym = BLOCK_SYM (block, bot);
848 if (SYMBOL_NAME (sym)[0] == inc
849 && !strcmp (SYMBOL_NAME (sym), name)
850 && SYMBOL_NAMESPACE (sym) == namespace)
852 if (SYMBOL_CLASS (sym) == LOC_ARG
853 || SYMBOL_CLASS (sym) == LOC_LOCAL_ARG
854 || SYMBOL_CLASS (sym) == LOC_REF_ARG
855 || SYMBOL_CLASS (sym) == LOC_REGPARM)
862 return parameter_sym; /* Will be 0 if not found. */
865 /* Return the symbol for the function which contains a specified
866 lexical block, described by a struct block BL. */
872 while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
873 bl = BLOCK_SUPERBLOCK (bl);
875 return BLOCK_FUNCTION (bl);
878 /* Subroutine of find_pc_line */
882 register CORE_ADDR pc;
884 register struct block *b;
885 struct blockvector *bv;
886 register struct symtab *s = 0;
887 register struct partial_symtab *ps;
888 register struct objfile *objfile;
890 /* Search all symtabs for one whose file contains our pc */
892 ALL_SYMTABS (objfile, s)
894 bv = BLOCKVECTOR (s);
895 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
896 if (BLOCK_START (b) <= pc
897 && BLOCK_END (b) > pc)
903 ps = find_pc_psymtab (pc);
904 if (ps && ps->readin)
906 printf_filtered ("(Internal error: pc 0x%x in read in psymtab, but not in symtab.)\n", pc);
910 s = PSYMTAB_TO_SYMTAB (ps);
918 /* Find the source file and line number for a given PC value.
919 Return a structure containing a symtab pointer, a line number,
920 and a pc range for the entire source line.
921 The value's .pc field is NOT the specified pc.
922 NOTCURRENT nonzero means, if specified pc is on a line boundary,
923 use the line that ends there. Otherwise, in that case, the line
924 that begins there is used. */
926 struct symtab_and_line
927 find_pc_line (pc, notcurrent)
932 register struct linetable *l;
935 register struct linetable_entry *item;
936 struct symtab_and_line val;
937 struct blockvector *bv;
939 /* Info on best line seen so far, and where it starts, and its file. */
942 CORE_ADDR best_pc = 0;
943 CORE_ADDR best_end = 0;
944 struct symtab *best_symtab = 0;
946 /* Store here the first line number
947 of a file which contains the line at the smallest pc after PC.
948 If we don't find a line whose range contains PC,
949 we will use a line one less than this,
950 with a range from the start of that file to the first line's pc. */
952 CORE_ADDR alt_pc = 0;
953 struct symtab *alt_symtab = 0;
955 /* Info on best line seen in this file. */
960 /* Info on first line of this file. */
965 /* If this pc is not from the current frame,
966 it is the address of the end of a call instruction.
967 Quite likely that is the start of the following statement.
968 But what we want is the statement containing the instruction.
969 Fudge the pc to make sure we get that. */
971 if (notcurrent) pc -= 1;
973 s = find_pc_symtab (pc);
983 bv = BLOCKVECTOR (s);
985 /* Look at all the symtabs that share this blockvector.
986 They all have the same apriori range, that we found was right;
987 but they have different line tables. */
989 for (; s && BLOCKVECTOR (s) == bv; s = s->next)
991 /* Find the best line in this symtab. */
998 for (i = 0; i < len; i++)
1000 item = &(l->item[i]);
1004 first_line = item->line;
1005 first_pc = item->pc;
1007 /* Return the last line that did not start after PC. */
1010 prev_line = item->line;
1017 /* Is this file's best line closer than the best in the other files?
1018 If so, record this file, and its best line, as best so far. */
1019 if (prev_line >= 0 && prev_pc > best_pc)
1022 best_line = prev_line;
1024 /* If another line is in the linetable, and its PC is closer
1025 than the best_end we currently have, take it as best_end. */
1026 if (i < len && (best_end == 0 || best_end > item->pc))
1027 best_end = item->pc;
1029 /* Is this file's first line closer than the first lines of other files?
1030 If so, record this file, and its first line, as best alternate. */
1031 if (first_line >= 0 && first_pc > pc
1032 && (alt_pc == 0 || first_pc < alt_pc))
1035 alt_line = first_line;
1039 if (best_symtab == 0)
1041 val.symtab = alt_symtab;
1042 val.line = alt_line - 1;
1043 val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1048 val.symtab = best_symtab;
1049 val.line = best_line;
1051 if (best_end && (alt_pc == 0 || best_end < alt_pc))
1056 val.end = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1061 /* Find the PC value for a given source file and line number.
1062 Returns zero for invalid line number.
1063 The source file is specified with a struct symtab. */
1066 find_line_pc (symtab, line)
1067 struct symtab *symtab;
1070 register struct linetable *l;
1076 l = LINETABLE (symtab);
1077 ind = find_line_common(l, line, &dummy);
1078 return (ind >= 0) ? l->item[ind].pc : 0;
1081 /* Find the range of pc values in a line.
1082 Store the starting pc of the line into *STARTPTR
1083 and the ending pc (start of next line) into *ENDPTR.
1084 Returns 1 to indicate success.
1085 Returns 0 if could not find the specified line. */
1088 find_line_pc_range (symtab, thisline, startptr, endptr)
1089 struct symtab *symtab;
1091 CORE_ADDR *startptr, *endptr;
1093 register struct linetable *l;
1095 int exact_match; /* did we get an exact linenumber match */
1100 l = LINETABLE (symtab);
1101 ind = find_line_common (l, thisline, &exact_match);
1104 *startptr = l->item[ind].pc;
1105 /* If we have not seen an entry for the specified line,
1106 assume that means the specified line has zero bytes. */
1107 if (!exact_match || ind == l->nitems-1)
1108 *endptr = *startptr;
1110 /* Perhaps the following entry is for the following line.
1111 It's worth a try. */
1112 if (ind+1 < l->nitems
1113 && l->item[ind+1].line == thisline + 1)
1114 *endptr = l->item[ind+1].pc;
1116 *endptr = find_line_pc (symtab, thisline+1);
1123 /* Given a line table and a line number, return the index into the line
1124 table for the pc of the nearest line whose number is >= the specified one.
1125 Return -1 if none is found. The value is >= 0 if it is an index.
1127 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1130 find_line_common (l, lineno, exact_match)
1131 register struct linetable *l;
1132 register int lineno;
1138 /* BEST is the smallest linenumber > LINENO so far seen,
1139 or 0 if none has been seen so far.
1140 BEST_INDEX identifies the item for it. */
1142 int best_index = -1;
1151 for (i = 0; i < len; i++)
1153 register struct linetable_entry *item = &(l->item[i]);
1155 if (item->line == lineno)
1161 if (item->line > lineno && (best == 0 || item->line < best))
1168 /* If we got here, we didn't get an exact match. */
1175 find_pc_line_pc_range (pc, startptr, endptr)
1177 CORE_ADDR *startptr, *endptr;
1179 struct symtab_and_line sal;
1180 sal = find_pc_line (pc, 0);
1183 return sal.symtab != 0;
1186 /* If P is of the form "operator[ \t]+..." where `...' is
1187 some legitimate operator text, return a pointer to the
1188 beginning of the substring of the operator text.
1189 Otherwise, return "". */
1191 operator_chars (p, end)
1196 if (strncmp (p, "operator", 8))
1200 /* Don't get faked out by `operator' being part of a longer
1202 if (isalpha(*p) || *p == '_' || *p == '$' || *p == '\0')
1205 /* Allow some whitespace between `operator' and the operator symbol. */
1206 while (*p == ' ' || *p == '\t')
1209 /* Recognize 'operator TYPENAME'. */
1211 if (isalpha(*p) || *p == '_' || *p == '$')
1213 register char *q = p+1;
1214 while (isalnum(*q) || *q == '_' || *q == '$')
1239 if (p[1] == '=' || p[1] == p[0])
1250 error ("`operator ()' must be specified without whitespace in `()'");
1255 error ("`operator ?:' must be specified without whitespace in `?:'");
1260 error ("`operator []' must be specified without whitespace in `[]'");
1264 error ("`operator %s' not supported", p);
1271 /* Recursive helper function for decode_line_1.
1272 * Look for methods named NAME in type T.
1273 * Return number of matches.
1274 * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1275 * These allocations seem to define "big enough":
1276 * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1277 * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1281 find_methods (t, name, physnames, sym_arr)
1285 struct symbol **sym_arr;
1289 struct symbol *sym_class;
1290 char *class_name = type_name_no_tag (t);
1291 /* Ignore this class if it doesn't have a name.
1292 This prevents core dumps, but is just a workaround
1293 because we might not find the function in
1294 certain cases, such as
1295 struct D {virtual int f();}
1296 struct C : D {virtual int g();}
1297 (in this case g++ 1.35.1- does not put out a name
1298 for D as such, it defines type 19 (for example) in
1299 the same stab as C, and then does a
1300 .stabs "D:T19" and a .stabs "D:t19".
1302 "break C::f" should not be looking for field f in
1304 but just for the field f in the baseclasses of C
1305 (no matter what their names).
1307 However, I don't know how to replace the code below
1308 that depends on knowing the name of D. */
1310 && (sym_class = lookup_symbol (class_name,
1311 (struct block *)NULL,
1314 (struct symtab **)NULL)))
1317 t = SYMBOL_TYPE (sym_class);
1318 for (method_counter = TYPE_NFN_FIELDS (t) - 1;
1319 method_counter >= 0;
1323 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, method_counter);
1325 char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
1326 if (!strcmp (name, method_name))
1327 /* Find all the fields with that name. */
1328 for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
1333 if (TYPE_FN_FIELD_STUB (f, field_counter))
1334 check_stub_method (t, method_counter, field_counter);
1335 phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
1336 physnames[i1] = (char*) alloca (strlen (phys_name) + 1);
1337 strcpy (physnames[i1], phys_name);
1338 sym_arr[i1] = lookup_symbol (phys_name,
1339 SYMBOL_BLOCK_VALUE (sym_class),
1342 (struct symtab **) NULL);
1343 if (sym_arr[i1]) i1++;
1346 fputs_filtered("(Cannot find method ", stdout);
1347 fputs_demangled(phys_name, stdout, 0);
1348 fputs_filtered(" - possibly inlined.)\n", stdout);
1353 /* Only search baseclasses if there is no match yet,
1354 * since names in derived classes override those in baseclasses.
1358 for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
1359 i1 += find_methods(TYPE_BASECLASS(t, ibase), name,
1360 physnames + i1, sym_arr + i1);
1364 /* Parse a string that specifies a line number.
1365 Pass the address of a char * variable; that variable will be
1366 advanced over the characters actually parsed.
1370 LINENUM -- that line number in current file. PC returned is 0.
1371 FILE:LINENUM -- that line in that file. PC returned is 0.
1372 FUNCTION -- line number of openbrace of that function.
1373 PC returned is the start of the function.
1374 VARIABLE -- line number of definition of that variable.
1376 FILE:FUNCTION -- likewise, but prefer functions in that file.
1377 *EXPR -- line in which address EXPR appears.
1379 FUNCTION may be an undebuggable function found in minimal symbol table.
1381 If the argument FUNFIRSTLINE is nonzero, we want the first line
1382 of real code inside a function when a function is specified.
1384 DEFAULT_SYMTAB specifies the file to use if none is specified.
1385 It defaults to current_source_symtab.
1386 DEFAULT_LINE specifies the line number to use for relative
1387 line numbers (that start with signs). Defaults to current_source_line.
1389 Note that it is possible to return zero for the symtab
1390 if no file is validly specified. Callers must check that.
1391 Also, the line number returned may be invalid. */
1393 struct symtabs_and_lines
1394 decode_line_1 (argptr, funfirstline, default_symtab, default_line)
1397 struct symtab *default_symtab;
1400 struct symtabs_and_lines values;
1401 struct symtab_and_line val;
1402 register char *p, *p1;
1404 register struct symtab *s;
1406 register struct symbol *sym;
1407 /* The symtab that SYM was found in. */
1408 struct symtab *sym_symtab;
1410 register CORE_ADDR pc;
1411 register struct minimal_symbol *msymbol;
1413 struct symbol *sym_class;
1415 struct symbol **sym_arr;
1419 /* Defaults have defaults. */
1421 if (default_symtab == 0)
1423 default_symtab = current_source_symtab;
1424 default_line = current_source_line;
1427 /* See if arg is *PC */
1429 if (**argptr == '*')
1432 pc = parse_and_eval_address_1 (argptr);
1433 values.sals = (struct symtab_and_line *)
1434 xmalloc (sizeof (struct symtab_and_line));
1436 values.sals[0] = find_pc_line (pc, 0);
1437 values.sals[0].pc = pc;
1441 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1445 for (p = *argptr; *p; p++)
1447 if (p[0] == ':' || p[0] == ' ' || p[0] == '\t')
1450 while (p[0] == ' ' || p[0] == '\t') p++;
1458 /* Extract the class name. */
1460 while (p != *argptr && p[-1] == ' ') --p;
1461 copy = (char *) alloca (p - *argptr + 1);
1462 bcopy (*argptr, copy, p - *argptr);
1463 copy[p - *argptr] = 0;
1465 /* Discard the class name from the arg. */
1467 while (*p == ' ' || *p == '\t') p++;
1470 sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0,
1471 (struct symtab **)NULL);
1474 ( TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_STRUCT
1475 || TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_UNION))
1477 /* Arg token is not digits => try it as a function name
1478 Find the next token (everything up to end or next whitespace). */
1480 while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p !=':') p++;
1481 q = operator_chars (*argptr, &q1);
1486 char *tmp = alloca (q1 - q + 1);
1487 memcpy (tmp, q, q1 - q);
1489 opname = cplus_mangle_opname (tmp, 1);
1491 error ("No mangling for \"%s\"", tmp);
1492 copy = (char*) alloca (3 + strlen(opname));
1493 sprintf (copy, "__%s", opname);
1498 copy = (char *) alloca (p - *argptr + 1 + (q1 - q));
1499 bcopy (*argptr, copy, p - *argptr);
1500 copy[p - *argptr] = '\0';
1503 /* no line number may be specified */
1504 while (*p == ' ' || *p == '\t') p++;
1508 i1 = 0; /* counter for the symbol array */
1509 t = SYMBOL_TYPE (sym_class);
1510 sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1511 physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1513 if (destructor_name_p (copy, t))
1515 /* destructors are a special case. */
1516 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, 0);
1517 int len = TYPE_FN_FIELDLIST_LENGTH (t, 0) - 1;
1518 char *phys_name = TYPE_FN_FIELD_PHYSNAME (f, len);
1519 physnames[i1] = (char *)alloca (strlen (phys_name) + 1);
1520 strcpy (physnames[i1], phys_name);
1522 lookup_symbol (phys_name, SYMBOL_BLOCK_VALUE (sym_class),
1523 VAR_NAMESPACE, 0, (struct symtab **)NULL);
1524 if (sym_arr[i1]) i1++;
1527 i1 = find_methods (t, copy, physnames, sym_arr);
1530 /* There is exactly one field with that name. */
1533 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1535 /* Arg is the name of a function */
1536 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
1539 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
1541 values.sals[0] = find_pc_line (pc, 0);
1542 values.sals[0].pc = (values.sals[0].end && values.sals[0].pc != pc) ? values.sals[0].end : pc;
1552 /* There is more than one field with that name
1553 (overloaded). Ask the user which one to use. */
1554 return decode_line_2 (sym_arr, i1, funfirstline);
1560 if (OPNAME_PREFIX_P (copy))
1562 tmp = (char *)alloca (strlen (copy+3) + 9);
1563 strcpy (tmp, "operator ");
1564 strcat (tmp, copy+3);
1569 error ("The class `%s' does not have destructor defined",
1572 error ("The class %s does not have any method named %s",
1573 sym_class->name, tmp);
1577 /* The quotes are important if copy is empty. */
1578 error("No class, struct, or union named \"%s\"", copy );
1583 /* Extract the file name. */
1585 while (p != *argptr && p[-1] == ' ') --p;
1586 copy = (char *) alloca (p - *argptr + 1);
1587 bcopy (*argptr, copy, p - *argptr);
1588 copy[p - *argptr] = 0;
1590 /* Find that file's data. */
1591 s = lookup_symtab (copy);
1594 if (!have_full_symbols () && !have_partial_symbols ())
1595 error (no_symtab_msg);
1596 error ("No source file named %s.", copy);
1599 /* Discard the file name from the arg. */
1601 while (*p == ' ' || *p == '\t') p++;
1605 /* S is specified file's symtab, or 0 if no file specified.
1606 arg no longer contains the file name. */
1608 /* Check whether arg is all digits (and sign) */
1611 if (*p == '-' || *p == '+') p++;
1612 while (*p >= '0' && *p <= '9')
1615 if (p != *argptr && (*p == 0 || *p == ' ' || *p == '\t' || *p == ','))
1617 /* We found a token consisting of all digits -- at least one digit. */
1618 enum sign {none, plus, minus} sign = none;
1620 /* This is where we need to make sure that we have good defaults.
1621 We must guarantee that this section of code is never executed
1622 when we are called with just a function name, since
1623 select_source_symtab calls us with such an argument */
1625 if (s == 0 && default_symtab == 0)
1627 select_source_symtab (0);
1628 default_symtab = current_source_symtab;
1629 default_line = current_source_line;
1632 if (**argptr == '+')
1633 sign = plus, (*argptr)++;
1634 else if (**argptr == '-')
1635 sign = minus, (*argptr)++;
1636 val.line = atoi (*argptr);
1643 val.line = default_line + val.line;
1649 val.line = default_line - val.line;
1654 break; /* No need to adjust val.line. */
1657 while (*p == ' ' || *p == '\t') p++;
1663 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
1664 values.sals[0] = val;
1669 /* Arg token is not digits => try it as a variable name
1670 Find the next token (everything up to end or next whitespace). */
1673 while (*p && *p != ' ' && *p != '\t' && *p != ',') p++;
1674 copy = (char *) alloca (p - *argptr + 1);
1675 bcopy (*argptr, copy, p - *argptr);
1676 copy[p - *argptr] = 0;
1677 while (*p == ' ' || *p == '\t') p++;
1680 /* Look up that token as a variable.
1681 If file specified, use that file's per-file block to start with. */
1683 sym = lookup_symbol (copy,
1684 (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
1685 : get_selected_block ()),
1686 VAR_NAMESPACE, 0, &sym_symtab);
1690 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
1692 /* Arg is the name of a function */
1693 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) + FUNCTION_START_OFFSET;
1696 val = find_pc_line (pc, 0);
1697 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1698 /* Convex: no need to suppress code on first line, if any */
1701 /* If SKIP_PROLOGUE left us in mid-line, and the next line is still
1702 part of the same function:
1703 advance to next line,
1704 recalculate its line number (might not be N+1). */
1705 if (val.pc != pc && val.end &&
1706 lookup_minimal_symbol_by_pc (pc) == lookup_minimal_symbol_by_pc (val.end)) {
1707 pc = val.end; /* First pc of next line */
1708 val = find_pc_line (pc, 0);
1712 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
1713 values.sals[0] = val;
1716 /* I think this is always the same as the line that
1717 we calculate above, but the general principle is
1718 "trust the symbols more than stuff like
1720 if (SYMBOL_LINE (sym) != 0)
1721 values.sals[0].line = SYMBOL_LINE (sym);
1725 else if (SYMBOL_LINE (sym) != 0)
1727 /* We know its line number. */
1728 values.sals = (struct symtab_and_line *)
1729 xmalloc (sizeof (struct symtab_and_line));
1731 bzero (&values.sals[0], sizeof (values.sals[0]));
1732 values.sals[0].symtab = sym_symtab;
1733 values.sals[0].line = SYMBOL_LINE (sym);
1737 /* This can happen if it is compiled with a compiler which doesn't
1738 put out line numbers for variables. */
1739 error ("Line number not known for symbol \"%s\"", copy);
1742 msymbol = lookup_minimal_symbol (copy, (struct objfile *) NULL);
1743 if (msymbol != NULL)
1747 val.pc = msymbol -> address + FUNCTION_START_OFFSET;
1749 SKIP_PROLOGUE (val.pc);
1750 values.sals = (struct symtab_and_line *)xmalloc (sizeof (struct symtab_and_line));
1751 values.sals[0] = val;
1756 if (!have_full_symbols () &&
1757 !have_partial_symbols () && !have_minimal_symbols ())
1758 error (no_symtab_msg);
1760 error ("Function %s not defined.", copy);
1761 return values; /* for lint */
1764 struct symtabs_and_lines
1765 decode_line_spec (string, funfirstline)
1769 struct symtabs_and_lines sals;
1771 error ("Empty line specification.");
1772 sals = decode_line_1 (&string, funfirstline,
1773 current_source_symtab, current_source_line);
1775 error ("Junk at end of line specification: %s", string);
1779 /* Given a list of NELTS symbols in sym_arr (with corresponding
1780 mangled names in physnames), return a list of lines to operate on
1781 (ask user if necessary). */
1782 static struct symtabs_and_lines
1783 decode_line_2 (sym_arr, nelts, funfirstline)
1784 struct symbol *sym_arr[];
1788 struct symtabs_and_lines values, return_values;
1789 register CORE_ADDR pc;
1794 values.sals = (struct symtab_and_line *) alloca (nelts * sizeof(struct symtab_and_line));
1795 return_values.sals = (struct symtab_and_line *) xmalloc (nelts * sizeof(struct symtab_and_line));
1798 printf("[0] cancel\n[1] all\n");
1801 if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK)
1803 /* Arg is the name of a function */
1804 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr[i]))
1805 + FUNCTION_START_OFFSET;
1808 values.sals[i] = find_pc_line (pc, 0);
1809 values.sals[i].pc = (values.sals[i].end && values.sals[i].pc != pc) ?
1810 values.sals[i].end : pc;
1811 printf("[%d] file:%s; line number:%d\n",
1812 (i+2), values.sals[i].symtab->filename, values.sals[i].line);
1814 else printf ("?HERE\n");
1818 if ((prompt = getenv ("PS2")) == NULL)
1822 printf("%s ",prompt);
1825 args = command_line_input ((char *) NULL, 0);
1828 error_no_arg ("one or more choice numbers");
1836 while (*arg1 >= '0' && *arg1 <= '9') arg1++;
1837 if (*arg1 && *arg1 != ' ' && *arg1 != '\t')
1838 error ("Arguments must be choice numbers.");
1843 error ("cancelled");
1846 bcopy (values.sals, return_values.sals, (nelts * sizeof(struct symtab_and_line)));
1847 return_values.nelts = nelts;
1848 return return_values;
1851 if (num > nelts + 2)
1853 printf ("No choice number %d.\n", num);
1858 if (values.sals[num].pc)
1860 return_values.sals[i++] = values.sals[num];
1861 values.sals[num].pc = 0;
1865 printf ("duplicate request for %d ignored.\n", num);
1870 while (*args == ' ' || *args == '\t') args++;
1872 return_values.nelts = i;
1873 return return_values;
1877 /* Slave routine for sources_info. Force line breaks at ,'s.
1878 NAME is the name to print and *FIRST is nonzero if this is the first
1879 name printed. Set *FIRST to zero. */
1881 output_source_filename (name, first)
1885 static unsigned int column;
1886 /* Table of files printed so far. Since a single source file can
1887 result in several partial symbol tables, we need to avoid printing
1888 it more than once. Note: if some of the psymtabs are read in and
1889 some are not, it gets printed both under "Source files for which
1890 symbols have been read" and "Source files for which symbols will
1891 be read in on demand". I consider this a reasonable way to deal
1892 with the situation. I'm not sure whether this can also happen for
1893 symtabs; it doesn't hurt to check. */
1894 static char **tab = NULL;
1895 /* Allocated size of tab in elements.
1896 Start with one 256-byte block (when using GNU malloc.c).
1897 24 is the malloc overhead when range checking is in effect. */
1898 static int tab_alloc_size = (256 - 24) / sizeof (char *);
1899 /* Current size of tab in elements. */
1900 static int tab_cur_size;
1907 tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab));
1911 /* Is NAME in tab? */
1912 for (p = tab; p < tab + tab_cur_size; p++)
1913 if (strcmp (*p, name) == 0)
1914 /* Yes; don't print it again. */
1916 /* No; add it to tab. */
1917 if (tab_cur_size == tab_alloc_size)
1919 tab_alloc_size *= 2;
1920 tab = (char **) xrealloc ((char *) tab, tab_alloc_size * sizeof (*tab));
1922 tab[tab_cur_size++] = name;
1931 printf_filtered (",");
1935 if (column != 0 && column + strlen (name) >= 70)
1937 printf_filtered ("\n");
1940 else if (column != 0)
1942 printf_filtered (" ");
1945 fputs_filtered (name, stdout);
1946 column += strlen (name);
1950 sources_info (ignore, from_tty)
1954 register struct symtab *s;
1955 register struct partial_symtab *ps;
1956 register struct objfile *objfile;
1959 if (!have_full_symbols () && !have_partial_symbols ())
1961 error (no_symtab_msg);
1964 printf_filtered ("Source files for which symbols have been read in:\n\n");
1967 ALL_SYMTABS (objfile, s)
1969 output_source_filename (s -> filename, &first);
1971 printf_filtered ("\n\n");
1973 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
1976 ALL_PSYMTABS (objfile, ps)
1980 output_source_filename (ps -> filename, &first);
1983 printf_filtered ("\n");
1990 char *demangled = cplus_demangle(name, -1);
1991 if (demangled != NULL)
1993 int cond = re_exec (demangled);
1997 return re_exec(name);
1999 #define NAME_MATCH(NAME) name_match(NAME)
2001 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2002 If CLASS is zero, list all symbols except functions and type names.
2003 If CLASS is 1, list only functions.
2004 If CLASS is 2, list only type names.
2005 If CLASS is 3, list only method names.
2007 BPT is non-zero if we should set a breakpoint at the functions
2011 list_symbols (regexp, class, bpt)
2016 register struct symtab *s;
2017 register struct partial_symtab *ps;
2018 register struct blockvector *bv;
2019 struct blockvector *prev_bv = 0;
2020 register struct block *b;
2022 register struct symbol *sym;
2023 struct partial_symbol *psym;
2024 struct objfile *objfile;
2025 struct minimal_symbol *msymbol;
2027 static char *classnames[]
2028 = {"variable", "function", "type", "method"};
2029 int found_in_file = 0;
2031 static enum minimal_symbol_type types[]
2032 = {mst_data, mst_text, mst_abs, mst_unknown};
2033 static enum minimal_symbol_type types2[]
2034 = {mst_bss, mst_text, mst_abs, mst_unknown};
2035 enum minimal_symbol_type ourtype = types[class];
2036 enum minimal_symbol_type ourtype2 = types2[class];
2040 /* Make sure spacing is right for C++ operators.
2041 This is just a courtesy to make the matching less sensitive
2042 to how many spaces the user leaves between 'operator'
2043 and <TYPENAME> or <OPERATOR>. */
2045 char *opname = operator_chars (regexp, &opend);
2048 int fix = -1; /* -1 means ok; otherwise number of spaces needed. */
2049 if (isalpha(*opname) || *opname == '_' || *opname == '$')
2051 /* There should 1 space between 'operator' and 'TYPENAME'. */
2052 if (opname[-1] != ' ' || opname[-2] == ' ')
2057 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2058 if (opname[-1] == ' ')
2061 /* If wrong number of spaces, fix it. */
2064 char *tmp = (char*) alloca(opend-opname+10);
2065 sprintf(tmp, "operator%.*s%s", fix, " ", opname);
2070 if (0 != (val = re_comp (regexp)))
2071 error ("Invalid regexp (%s): %s", val, regexp);
2074 /* Search through the partial symtabs *first* for all symbols
2075 matching the regexp. That way we don't have to reproduce all of
2076 the machinery below. */
2078 ALL_PSYMTABS (objfile, ps)
2080 struct partial_symbol *bound, *gbound, *sbound;
2083 if (ps->readin) continue;
2085 gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms;
2086 sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms;
2089 /* Go through all of the symbols stored in a partial
2090 symtab in one loop. */
2091 psym = objfile->global_psymbols.list + ps->globals_offset;
2096 if (bound == gbound && ps->n_static_syms != 0)
2098 psym = objfile->static_psymbols.list + ps->statics_offset;
2109 /* If it would match (logic taken from loop below)
2110 load the file and go on to the next one */
2111 if ((regexp == 0 || NAME_MATCH (SYMBOL_NAME (psym)))
2112 && ((class == 0 && SYMBOL_CLASS (psym) != LOC_TYPEDEF
2113 && SYMBOL_CLASS (psym) != LOC_BLOCK)
2114 || (class == 1 && SYMBOL_CLASS (psym) == LOC_BLOCK)
2115 || (class == 2 && SYMBOL_CLASS (psym) == LOC_TYPEDEF)
2116 || (class == 3 && SYMBOL_CLASS (psym) == LOC_BLOCK)))
2118 (void) PSYMTAB_TO_SYMTAB(ps);
2126 /* Here, we search through the minimal symbol tables for functions that
2127 match, and call find_pc_symtab on them to force their symbols to
2128 be read. The symbol will then be found during the scan of symtabs
2129 below. If find_pc_symtab fails, set found_misc so that we will
2130 rescan to print any matching symbols without debug info. */
2134 ALL_MSYMBOLS (objfile, msymbol)
2136 if (msymbol -> type == ourtype || msymbol -> type == ourtype2)
2138 if (regexp == 0 || NAME_MATCH (msymbol -> name))
2140 if (0 == find_pc_symtab (msymbol -> address))
2149 /* Printout here so as to get after the "Reading in symbols"
2150 messages which will be generated above. */
2152 printf_filtered (regexp
2153 ? "All %ss matching regular expression \"%s\":\n"
2154 : "All defined %ss:\n",
2158 ALL_SYMTABS (objfile, s)
2161 bv = BLOCKVECTOR (s);
2162 /* Often many files share a blockvector.
2163 Scan each blockvector only once so that
2164 we don't get every symbol many times.
2165 It happens that the first symtab in the list
2166 for any given blockvector is the main file. */
2168 for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
2170 b = BLOCKVECTOR_BLOCK (bv, i);
2171 /* Skip the sort if this block is always sorted. */
2172 if (!BLOCK_SHOULD_SORT (b))
2173 sort_block_syms (b);
2174 for (j = 0; j < BLOCK_NSYMS (b); j++)
2177 sym = BLOCK_SYM (b, j);
2178 if ((regexp == 0 || NAME_MATCH (SYMBOL_NAME (sym)))
2179 && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
2180 && SYMBOL_CLASS (sym) != LOC_BLOCK)
2181 || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)
2182 || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2183 || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK)))
2187 /* Set a breakpoint here, if it's a function */
2189 break_command (SYMBOL_NAME(sym), 0);
2191 else if (!found_in_file)
2193 fputs_filtered ("\nFile ", stdout);
2194 fputs_filtered (s->filename, stdout);
2195 fputs_filtered (":\n", stdout);
2199 if (class != 2 && i == STATIC_BLOCK)
2200 printf_filtered ("static ");
2202 /* Typedef that is not a C++ class */
2204 && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
2205 typedef_print (SYMBOL_TYPE(sym), sym, stdout);
2206 /* variable, func, or typedef-that-is-c++-class */
2207 else if (class < 2 ||
2209 SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE))
2211 type_print (SYMBOL_TYPE (sym),
2212 (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2213 ? "" : SYMBOL_NAME (sym)),
2216 printf_filtered (";\n");
2221 /* FIXME, why is this zapped out? */
2223 type_print_base (TYPE_FN_FIELD_TYPE(t, i), stdout, 0, 0);
2224 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i), stdout, 0);
2225 sprintf (buf, " %s::", type_name_no_tag (t));
2226 type_print_method_args (TYPE_FN_FIELD_ARGS (t, i), buf, name, stdout);
2235 /* If there are no eyes, avoid all contact. I mean, if there are
2236 no debug symbols, then print directly from the msymbol_vector. */
2238 if (found_misc || class != 1)
2241 ALL_MSYMBOLS (objfile, msymbol)
2243 if (msymbol -> type == ourtype || msymbol -> type == ourtype2)
2245 if (regexp == 0 || NAME_MATCH (msymbol -> name))
2247 /* Functions: Look up by address. */
2249 (find_pc_symtab (msymbol -> address) != NULL))
2251 /* Variables/Absolutes: Look up by name */
2252 if (lookup_symbol (msymbol -> name,
2253 (struct block *) 0, VAR_NAMESPACE, 0,
2254 (struct symtab **) 0) == NULL)
2258 printf_filtered ("\nNon-debugging symbols:\n");
2261 printf_filtered (" %08x %s\n",
2273 variables_info (regexp, from_tty)
2277 list_symbols (regexp, 0, 0);
2281 functions_info (regexp, from_tty)
2285 list_symbols (regexp, 1, 0);
2289 types_info (regexp, from_tty)
2293 list_symbols (regexp, 2, 0);
2297 /* Tiemann says: "info methods was never implemented." */
2299 methods_info (regexp)
2302 list_symbols (regexp, 3, 0);
2306 /* Breakpoint all functions matching regular expression. */
2308 rbreak_command (regexp, from_tty)
2312 list_symbols (regexp, 1, 1);
2316 /* Return Nonzero if block a is lexically nested within block b,
2317 or if a and b have the same pc range.
2318 Return zero otherwise. */
2321 struct block *a, *b;
2325 return BLOCK_START (a) >= BLOCK_START (b)
2326 && BLOCK_END (a) <= BLOCK_END (b);
2330 /* Helper routine for make_symbol_completion_list. */
2332 int return_val_size, return_val_index;
2336 completion_list_add_symbol (symname)
2339 if (return_val_index + 3 > return_val_size)
2340 return_val = (char **) xrealloc ((char *) return_val,
2341 (return_val_size *= 2) * sizeof (char *));
2343 return_val[return_val_index] =
2344 (char *)xmalloc (1 + strlen (symname));
2346 strcpy (return_val[return_val_index], symname);
2348 return_val[++return_val_index] = (char *)NULL;
2351 /* Return a NULL terminated array of all symbols (regardless of class) which
2352 begin by matching TEXT. If the answer is no symbols, then the return value
2353 is an array which contains only a NULL pointer.
2355 Problem: All of the symbols have to be copied because readline
2356 frees them. I'm not going to worry about this; hopefully there
2357 won't be that many. */
2360 make_symbol_completion_list (text)
2363 register struct symtab *s;
2364 register struct partial_symtab *ps;
2365 register struct minimal_symbol *msymbol;
2366 register struct objfile *objfile;
2367 register struct block *b, *surrounding_static_block = 0;
2369 struct partial_symbol *psym;
2371 int text_len = strlen (text);
2372 return_val_size = 100;
2373 return_val_index = 0;
2375 (char **)xmalloc ((1 + return_val_size) *sizeof (char *));
2376 return_val[0] = (char *)NULL;
2378 /* Look through the partial symtabs for all symbols which begin
2379 by matching TEXT. Add each one that you find to the list. */
2381 ALL_PSYMTABS (objfile, ps)
2383 /* If the psymtab's been read in we'll get it when we search
2384 through the blockvector. */
2385 if (ps->readin) continue;
2387 for (psym = objfile->global_psymbols.list + ps->globals_offset;
2388 psym < (objfile->global_psymbols.list + ps->globals_offset
2389 + ps->n_global_syms);
2392 QUIT; /* If interrupted, then quit. */
2393 if ((strncmp (SYMBOL_NAME (psym), text, text_len) == 0))
2394 completion_list_add_symbol (SYMBOL_NAME (psym));
2397 for (psym = objfile->static_psymbols.list + ps->statics_offset;
2398 psym < (objfile->static_psymbols.list + ps->statics_offset
2399 + ps->n_static_syms);
2403 if ((strncmp (SYMBOL_NAME (psym), text, text_len) == 0))
2404 completion_list_add_symbol (SYMBOL_NAME (psym));
2408 /* At this point scan through the misc symbol vectors and add each
2409 symbol you find to the list. Eventually we want to ignore
2410 anything that isn't a text symbol (everything else will be
2411 handled by the psymtab code above). */
2413 ALL_MSYMBOLS (objfile, msymbol)
2415 if (strncmp (text, msymbol -> name, text_len) == 0)
2417 completion_list_add_symbol (msymbol -> name);
2421 /* Search upwards from currently selected frame (so that we can
2422 complete on local vars. */
2423 for (b = get_selected_block (); b; b = BLOCK_SUPERBLOCK (b))
2425 if (!BLOCK_SUPERBLOCK (b))
2426 surrounding_static_block = b; /* For elmin of dups */
2428 /* Also catch fields of types defined in this places which
2429 match our text string. Only complete on types visible
2430 from current context. */
2431 for (i = 0; i < BLOCK_NSYMS (b); i++)
2433 register struct symbol *sym = BLOCK_SYM (b, i);
2435 if (!strncmp (SYMBOL_NAME (sym), text, text_len))
2436 completion_list_add_symbol (SYMBOL_NAME (sym));
2438 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2440 struct type *t = SYMBOL_TYPE (sym);
2441 enum type_code c = TYPE_CODE (t);
2443 if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
2444 for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
2445 if (TYPE_FIELD_NAME (t, j) &&
2446 !strncmp (TYPE_FIELD_NAME (t, j), text, text_len))
2447 completion_list_add_symbol (TYPE_FIELD_NAME (t, j));
2452 /* Go through the symtabs and check the externs and statics for
2453 symbols which match. */
2455 ALL_SYMTABS (objfile, s)
2457 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
2459 for (i = 0; i < BLOCK_NSYMS (b); i++)
2460 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len))
2461 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i)));
2464 ALL_SYMTABS (objfile, s)
2466 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
2468 /* Don't do this block twice. */
2469 if (b == surrounding_static_block) continue;
2471 for (i = 0; i < BLOCK_NSYMS (b); i++)
2472 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b, i)), text, text_len))
2473 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b, i)));
2476 return (return_val);
2480 /* Add the type of the symbol sym to the type of the current
2481 function whose block we are in (assumed). The type of
2482 this current function is contained in *TYPE.
2484 This basically works as follows: When we find a function
2485 symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record
2486 a pointer to its type in the global in_function_type. Every
2487 time we come across a parameter symbol ('p' in its name), then
2488 this procedure adds the name and type of that parameter
2489 to the function type pointed to by *TYPE. (Which should correspond
2490 to in_function_type if it was called correctly).
2492 Note that since we are modifying a type, the result of
2493 lookup_function_type() should be bcopy()ed before calling
2494 this. When not in strict typing mode, the expression
2495 evaluator can choose to ignore this.
2497 Assumption: All of a function's parameter symbols will
2498 appear before another function symbol is found. The parameters
2499 appear in the same order in the argument list as they do in the
2503 add_param_to_type (type,sym)
2507 int num = ++(TYPE_NFIELDS(*type));
2509 if(TYPE_NFIELDS(*type)-1)
2510 TYPE_FIELDS(*type) = (struct field *)
2511 (*current_objfile->xrealloc) ((char *)(TYPE_FIELDS(*type)),
2512 num*sizeof(struct field));
2514 TYPE_FIELDS(*type) = (struct field *)
2515 (*current_objfile->xmalloc) (num*sizeof(struct field));
2517 TYPE_FIELD_BITPOS(*type,num-1) = num-1;
2518 TYPE_FIELD_BITSIZE(*type,num-1) = 0;
2519 TYPE_FIELD_TYPE(*type,num-1) = SYMBOL_TYPE(sym);
2520 TYPE_FIELD_NAME(*type,num-1) = SYMBOL_NAME(sym);
2525 _initialize_symtab ()
2527 add_info ("variables", variables_info,
2528 "All global and static variable names, or those matching REGEXP.");
2529 add_info ("functions", functions_info,
2530 "All function names, or those matching REGEXP.");
2532 /* FIXME: This command has at least the following problems:
2533 1. It prints builtin types (in a very strange and confusing fashion).
2534 2. It doesn't print right, e.g. with
2535 typedef struct foo *FOO
2536 type_print prints "FOO" when we want to make it (in this situation)
2537 print "struct foo *".
2538 I also think "ptype" or "whatis" is more likely to be useful (but if
2539 there is much disagreement "info types" can be fixed). */
2540 add_info ("types", types_info,
2541 "All type names, or those matching REGEXP.");
2544 add_info ("methods", methods_info,
2545 "All method names, or those matching REGEXP::REGEXP.\n\
2546 If the class qualifier is ommited, it is assumed to be the current scope.\n\
2547 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
2550 add_info ("sources", sources_info,
2551 "Source files in the program.");
2553 add_com ("rbreak", no_class, rbreak_command,
2554 "Set a breakpoint for all functions matching REGEXP.");
2556 /* Initialize the one built-in type that isn't language dependent... */
2557 builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0,
2558 "<unknown type>", (struct objfile *) NULL);