1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 1997
3 Free Software Foundation, Inc.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 #include "call-cmds.h"
32 #include "gnu-regex.h"
33 #include "expression.h"
39 #include <sys/types.h>
41 #include "gdb_string.h"
45 /* Prototypes for local functions */
48 find_methods PARAMS ((struct type *, char *, struct symbol **));
51 completion_list_add_name PARAMS ((char *, char *, int, char *, char *));
54 build_canonical_line_spec PARAMS ((struct symtab_and_line *, char *, char ***));
56 static struct symtabs_and_lines
57 decode_line_2 PARAMS ((struct symbol *[], int, int, char ***));
60 rbreak_command PARAMS ((char *, int));
63 types_info PARAMS ((char *, int));
66 functions_info PARAMS ((char *, int));
69 variables_info PARAMS ((char *, int));
72 sources_info PARAMS ((char *, int));
75 list_symbols PARAMS ((char *, int, int, int));
78 output_source_filename PARAMS ((char *, int *));
81 operator_chars PARAMS ((char *, char **));
83 static int find_line_common PARAMS ((struct linetable *, int, int *));
85 static struct partial_symbol *
86 lookup_partial_symbol PARAMS ((struct partial_symtab *, const char *,
87 int, namespace_enum));
89 static struct symtab *
90 lookup_symtab_1 PARAMS ((char *));
93 cplusplus_hint PARAMS ((char *));
97 /* The single non-language-specific builtin type */
98 struct type *builtin_type_error;
100 /* Block in which the most recently searched-for symbol was found.
101 Might be better to make this a parameter to lookup_symbol and
104 const struct block *block_found;
106 char no_symtab_msg[] = "No symbol table is loaded. Use the \"file\" command.";
108 /* While the C++ support is still in flux, issue a possibly helpful hint on
109 using the new command completion feature on single quoted demangled C++
110 symbols. Remove when loose ends are cleaned up. FIXME -fnf */
113 cplusplus_hint (name)
116 while (*name == '\'')
118 printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name, name);
119 printf_filtered ("(Note leading single quote.)\n");
122 /* Check for a symtab of a specific name; first in symtabs, then in
123 psymtabs. *If* there is no '/' in the name, a match after a '/'
124 in the symtab filename will also work. */
126 static struct symtab *
127 lookup_symtab_1 (name)
130 register struct symtab *s;
131 register struct partial_symtab *ps;
132 register char *slash;
133 register struct objfile *objfile;
137 /* First, search for an exact match */
139 ALL_SYMTABS (objfile, s)
140 if (STREQ (name, s->filename))
143 slash = strchr (name, '/');
145 /* Now, search for a matching tail (only if name doesn't have any dirs) */
148 ALL_SYMTABS (objfile, s)
150 char *p = s -> filename;
151 char *tail = strrchr (p, '/');
160 /* Same search rules as above apply here, but now we look thru the
163 ps = lookup_partial_symtab (name);
168 error ("Internal: readin %s pst for `%s' found when no symtab found.",
169 ps -> filename, name);
171 s = PSYMTAB_TO_SYMTAB (ps);
176 /* At this point, we have located the psymtab for this file, but
177 the conversion to a symtab has failed. This usually happens
178 when we are looking up an include file. In this case,
179 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
180 been created. So, we need to run through the symtabs again in
181 order to find the file.
182 XXX - This is a crock, and should be fixed inside of the the
183 symbol parsing routines. */
187 /* Lookup the symbol table of a source file named NAME. Try a couple
188 of variations if the first lookup doesn't work. */
194 register struct symtab *s;
199 s = lookup_symtab_1 (name);
203 /* This screws c-exp.y:yylex if there is both a type "tree" and a symtab
206 /* If name not found as specified, see if adding ".c" helps. */
207 /* Why is this? Is it just a user convenience? (If so, it's pretty
208 questionable in the presence of C++, FORTRAN, etc.). It's not in
211 copy = (char *) alloca (strlen (name) + 3);
214 s = lookup_symtab_1 (copy);
218 /* We didn't find anything; die. */
222 /* Lookup the partial symbol table of a source file named NAME.
223 *If* there is no '/' in the name, a match after a '/'
224 in the psymtab filename will also work. */
226 struct partial_symtab *
227 lookup_partial_symtab (name)
230 register struct partial_symtab *pst;
231 register struct objfile *objfile;
233 ALL_PSYMTABS (objfile, pst)
235 if (STREQ (name, pst -> filename))
241 /* Now, search for a matching tail (only if name doesn't have any dirs) */
243 if (!strchr (name, '/'))
244 ALL_PSYMTABS (objfile, pst)
246 char *p = pst -> filename;
247 char *tail = strrchr (p, '/');
259 /* Demangle a GDB method stub type.
260 Note that this function is g++ specific. */
263 gdb_mangle_name (type, i, j)
267 int mangled_name_len;
269 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
270 struct fn_field *method = &f[j];
271 char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
272 char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
273 char *newname = type_name_no_tag (type);
275 /* Does the form of physname indicate that it is the full mangled name
276 of a constructor (not just the args)? */
277 int is_full_physname_constructor;
280 int is_destructor = DESTRUCTOR_PREFIX_P (physname);
281 /* Need a new type prefix. */
282 char *const_prefix = method->is_const ? "C" : "";
283 char *volatile_prefix = method->is_volatile ? "V" : "";
285 int len = (newname == NULL ? 0 : strlen (newname));
287 is_full_physname_constructor =
288 ((physname[0]=='_' && physname[1]=='_' &&
289 (isdigit(physname[2]) || physname[2]=='Q' || physname[2]=='t'))
290 || (strncmp(physname, "__ct", 4) == 0));
293 is_full_physname_constructor || (newname && STREQ(field_name, newname));
296 is_destructor = (strncmp(physname, "__dt", 4) == 0);
298 if (is_destructor || is_full_physname_constructor)
300 mangled_name = (char*) xmalloc(strlen(physname)+1);
301 strcpy(mangled_name, physname);
307 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
309 else if (physname[0] == 't' || physname[0] == 'Q')
311 /* The physname for template and qualified methods already includes
313 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
319 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
321 mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
326 /* Only needed for GNU-mangled names. ANSI-mangled names
327 work with the normal mechanisms. */
328 if (OPNAME_PREFIX_P (field_name))
330 const char *opname = cplus_mangle_opname (field_name + 3, 0);
332 error ("No mangling for \"%s\"", field_name);
333 mangled_name_len += strlen (opname);
334 mangled_name = (char *)xmalloc (mangled_name_len);
336 strncpy (mangled_name, field_name, 3);
337 mangled_name[3] = '\0';
338 strcat (mangled_name, opname);
342 mangled_name = (char *)xmalloc (mangled_name_len);
344 mangled_name[0] = '\0';
346 strcpy (mangled_name, field_name);
348 strcat (mangled_name, buf);
349 /* If the class doesn't have a name, i.e. newname NULL, then we just
350 mangle it using 0 for the length of the class. Thus it gets mangled
351 as something starting with `::' rather than `classname::'. */
353 strcat (mangled_name, newname);
355 strcat (mangled_name, physname);
356 return (mangled_name);
361 struct symbol * fixup_symbol_section PARAMS ((struct symbol *,
363 struct partial_symbol * fixup_psymbol_section PARAMS ((struct partial_symbol *,
367 /* Find which partial symtab on contains PC and SECTION. Return 0 if none. */
369 struct partial_symtab *
370 find_pc_sect_psymtab (pc, section)
374 register struct partial_symtab *pst;
375 register struct objfile *objfile;
377 ALL_PSYMTABS (objfile, pst)
379 if (pc >= pst->textlow && pc < pst->texthigh)
381 struct minimal_symbol *msymbol;
382 struct partial_symtab *tpst;
384 /* An objfile that has its functions reordered might have
385 many partial symbol tables containing the PC, but
386 we want the partial symbol table that contains the
387 function containing the PC. */
388 if (!(objfile->flags & OBJF_REORDERED) &&
389 section == 0) /* can't validate section this way */
392 msymbol = lookup_minimal_symbol_by_pc_section (pc, section);
396 for (tpst = pst; tpst != NULL; tpst = tpst->next)
398 if (pc >= tpst->textlow && pc < tpst->texthigh)
400 struct partial_symbol *p;
402 p = find_pc_sect_psymbol (tpst, pc, section);
404 && SYMBOL_VALUE_ADDRESS(p)
405 == SYMBOL_VALUE_ADDRESS (msymbol))
415 /* Find which partial symtab contains PC. Return 0 if none.
416 Backward compatibility, no section */
418 struct partial_symtab *
422 return find_pc_sect_psymtab (pc, find_pc_mapped_section (pc));
425 /* Find which partial symbol within a psymtab matches PC and SECTION.
426 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
428 struct partial_symbol *
429 find_pc_sect_psymbol (psymtab, pc, section)
430 struct partial_symtab *psymtab;
434 struct partial_symbol *best = NULL, *p, **pp;
438 psymtab = find_pc_sect_psymtab (pc, section);
442 best_pc = psymtab->textlow - 1;
444 /* Search the global symbols as well as the static symbols, so that
445 find_pc_partial_function doesn't use a minimal symbol and thus
446 cache a bad endaddr. */
447 for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
448 (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
449 < psymtab->n_global_syms);
453 if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
454 && SYMBOL_CLASS (p) == LOC_BLOCK
455 && pc >= SYMBOL_VALUE_ADDRESS (p)
456 && SYMBOL_VALUE_ADDRESS (p) > best_pc)
458 if (section) /* match on a specific section */
460 fixup_psymbol_section (p, psymtab->objfile);
461 if (SYMBOL_BFD_SECTION (p) != section)
464 best_pc = SYMBOL_VALUE_ADDRESS (p);
468 for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
469 (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
470 < psymtab->n_static_syms);
474 if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
475 && SYMBOL_CLASS (p) == LOC_BLOCK
476 && pc >= SYMBOL_VALUE_ADDRESS (p)
477 && SYMBOL_VALUE_ADDRESS (p) > best_pc)
479 if (section) /* match on a specific section */
481 fixup_psymbol_section (p, psymtab->objfile);
482 if (SYMBOL_BFD_SECTION (p) != section)
485 best_pc = SYMBOL_VALUE_ADDRESS (p);
489 if (best_pc == psymtab->textlow - 1)
494 /* Find which partial symbol within a psymtab matches PC. Return 0 if none.
495 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
497 struct partial_symbol *
498 find_pc_psymbol (psymtab, pc)
499 struct partial_symtab *psymtab;
502 return find_pc_sect_psymbol (psymtab, pc, find_pc_mapped_section (pc));
505 /* Debug symbols usually don't have section information. We need to dig that
506 out of the minimal symbols and stash that in the debug symbol. */
509 fixup_section (ginfo, objfile)
510 struct general_symbol_info *ginfo;
511 struct objfile *objfile;
513 struct minimal_symbol *msym;
514 msym = lookup_minimal_symbol (ginfo->name, NULL, objfile);
517 ginfo->bfd_section = SYMBOL_BFD_SECTION (msym);
521 fixup_symbol_section (sym, objfile)
523 struct objfile *objfile;
525 struct minimal_symbol *msym;
530 if (SYMBOL_BFD_SECTION (sym))
533 fixup_section (&sym->ginfo, objfile);
538 struct partial_symbol *
539 fixup_psymbol_section (psym, objfile)
540 struct partial_symbol *psym;
541 struct objfile *objfile;
543 struct minimal_symbol *msym;
548 if (SYMBOL_BFD_SECTION (psym))
551 fixup_section (&psym->ginfo, objfile);
556 /* Find the definition for a specified symbol name NAME
557 in namespace NAMESPACE, visible from lexical block BLOCK.
558 Returns the struct symbol pointer, or zero if no symbol is found.
559 If SYMTAB is non-NULL, store the symbol table in which the
560 symbol was found there, or NULL if not found.
561 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
562 NAME is a field of the current implied argument `this'. If so set
563 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
564 BLOCK_FOUND is set to the block in which NAME is found (in the case of
565 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
567 /* This function has a bunch of loops in it and it would seem to be
568 attractive to put in some QUIT's (though I'm not really sure
569 whether it can run long enough to be really important). But there
570 are a few calls for which it would appear to be bad news to quit
571 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and
572 nindy_frame_chain_valid in nindy-tdep.c. (Note that there is C++
573 code below which can error(), but that probably doesn't affect
574 these calls since they are looking for a known variable and thus
575 can probably assume it will never hit the C++ code). */
578 lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
580 register const struct block *block;
581 const namespace_enum namespace;
582 int *is_a_field_of_this;
583 struct symtab **symtab;
585 register struct symbol *sym;
586 register struct symtab *s = NULL;
587 register struct partial_symtab *ps;
588 struct blockvector *bv;
589 register struct objfile *objfile = NULL;
590 register struct block *b;
591 register struct minimal_symbol *msymbol;
593 /* Search specified block and its superiors. */
597 sym = lookup_block_symbol (block, name, namespace);
603 /* Search the list of symtabs for one which contains the
604 address of the start of this block. */
605 ALL_SYMTABS (objfile, s)
607 bv = BLOCKVECTOR (s);
608 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
609 if (BLOCK_START (b) <= BLOCK_START (block)
610 && BLOCK_END (b) > BLOCK_START (block))
617 return fixup_symbol_section (sym, objfile);
619 block = BLOCK_SUPERBLOCK (block);
622 /* FIXME: this code is never executed--block is always NULL at this
623 point. What is it trying to do, anyway? We already should have
624 checked the STATIC_BLOCK above (it is the superblock of top-level
625 blocks). Why is VAR_NAMESPACE special-cased? */
626 /* Don't need to mess with the psymtabs; if we have a block,
627 that file is read in. If we don't, then we deal later with
628 all the psymtab stuff that needs checking. */
629 if (namespace == VAR_NAMESPACE && block != NULL)
632 /* Find the right symtab. */
633 ALL_SYMTABS (objfile, s)
635 bv = BLOCKVECTOR (s);
636 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
637 if (BLOCK_START (b) <= BLOCK_START (block)
638 && BLOCK_END (b) > BLOCK_START (block))
640 sym = lookup_block_symbol (b, name, VAR_NAMESPACE);
646 return fixup_symbol_section (sym, objfile);
653 /* C++: If requested to do so by the caller,
654 check to see if NAME is a field of `this'. */
655 if (is_a_field_of_this)
657 struct value *v = value_of_this (0);
659 *is_a_field_of_this = 0;
660 if (v && check_field (v, name))
662 *is_a_field_of_this = 1;
669 /* Now search all global blocks. Do the symtab's first, then
670 check the psymtab's */
672 ALL_SYMTABS (objfile, s)
674 bv = BLOCKVECTOR (s);
675 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
676 sym = lookup_block_symbol (block, name, namespace);
682 return fixup_symbol_section (sym, objfile);
686 /* Check for the possibility of the symbol being a function or
687 a mangled variable that is stored in one of the minimal symbol tables.
688 Eventually, all global symbols might be resolved in this way. */
690 if (namespace == VAR_NAMESPACE)
692 msymbol = lookup_minimal_symbol (name, NULL, NULL);
695 s = find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol),
696 SYMBOL_BFD_SECTION (msymbol));
699 /* This is a function which has a symtab for its address. */
700 bv = BLOCKVECTOR (s);
701 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
702 sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
704 /* We kept static functions in minimal symbol table as well as
705 in static scope. We want to find them in the symbol table. */
707 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
708 sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
712 /* sym == 0 if symbol was found in the minimal symbol table
713 but not in the symtab.
714 Return 0 to use the msymbol definition of "foo_".
716 This happens for Fortran "foo_" symbols,
717 which are "foo" in the symtab.
719 This can also happen if "asm" is used to make a
720 regular symbol but not a debugging symbol, e.g.
727 return fixup_symbol_section (sym, objfile);
729 else if (MSYMBOL_TYPE (msymbol) != mst_text
730 && MSYMBOL_TYPE (msymbol) != mst_file_text
731 && !STREQ (name, SYMBOL_NAME (msymbol)))
733 /* This is a mangled variable, look it up by its
735 return lookup_symbol (SYMBOL_NAME (msymbol), block,
736 namespace, is_a_field_of_this, symtab);
738 /* There are no debug symbols for this file, or we are looking
739 for an unmangled variable.
740 Try to find a matching static symbol below. */
744 ALL_PSYMTABS (objfile, ps)
746 if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
748 s = PSYMTAB_TO_SYMTAB(ps);
749 bv = BLOCKVECTOR (s);
750 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
751 sym = lookup_block_symbol (block, name, namespace);
753 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);
756 return fixup_symbol_section (sym, objfile);
760 /* Now search all per-file blocks.
761 Not strictly correct, but more useful than an error.
762 Do the symtabs first, then check the psymtabs */
764 ALL_SYMTABS (objfile, s)
766 bv = BLOCKVECTOR (s);
767 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
768 sym = lookup_block_symbol (block, name, namespace);
774 return fixup_symbol_section (sym, objfile);
778 ALL_PSYMTABS (objfile, ps)
780 if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
782 s = PSYMTAB_TO_SYMTAB(ps);
783 bv = BLOCKVECTOR (s);
784 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
785 sym = lookup_block_symbol (block, name, namespace);
787 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab", name, ps->filename);
790 return fixup_symbol_section (sym, objfile);
799 /* Look, in partial_symtab PST, for symbol NAME. Check the global
800 symbols if GLOBAL, the static symbols if not */
802 static struct partial_symbol *
803 lookup_partial_symbol (pst, name, global, namespace)
804 struct partial_symtab *pst;
807 namespace_enum namespace;
809 struct partial_symbol **start, **psym;
810 struct partial_symbol **top, **bottom, **center;
811 int length = (global ? pst->n_global_syms : pst->n_static_syms);
812 int do_linear_search = 1;
820 pst->objfile->global_psymbols.list + pst->globals_offset :
821 pst->objfile->static_psymbols.list + pst->statics_offset );
823 if (global) /* This means we can use a binary search. */
825 do_linear_search = 0;
827 /* Binary search. This search is guaranteed to end with center
828 pointing at the earliest partial symbol with the correct
829 name. At that point *all* partial symbols with that name
830 will be checked against the correct namespace. */
833 top = start + length - 1;
836 center = bottom + (top - bottom) / 2;
839 if (!do_linear_search && SYMBOL_LANGUAGE (*center) == language_cplus)
841 do_linear_search = 1;
843 if (STRCMP (SYMBOL_NAME (*center), name) >= 0)
852 if (!(top == bottom))
854 while (STREQ (SYMBOL_NAME (*top), name))
856 if (SYMBOL_NAMESPACE (*top) == namespace)
864 /* Can't use a binary search or else we found during the binary search that
865 we should also do a linear search. */
867 if (do_linear_search)
869 for (psym = start; psym < start + length; psym++)
871 if (namespace == SYMBOL_NAMESPACE (*psym))
873 if (SYMBOL_MATCHES_NAME (*psym, name))
884 /* Find the psymtab containing main(). */
885 /* FIXME: What about languages without main() or specially linked
886 executables that have no main() ? */
888 struct partial_symtab *
891 register struct partial_symtab *pst;
892 register struct objfile *objfile;
894 ALL_PSYMTABS (objfile, pst)
896 if (lookup_partial_symbol (pst, "main", 1, VAR_NAMESPACE))
904 /* Search BLOCK for symbol NAME in NAMESPACE.
906 Note that if NAME is the demangled form of a C++ symbol, we will fail
907 to find a match during the binary search of the non-encoded names, but
908 for now we don't worry about the slight inefficiency of looking for
909 a match we'll never find, since it will go pretty quick. Once the
910 binary search terminates, we drop through and do a straight linear
911 search on the symbols. Each symbol which is marked as being a C++
912 symbol (language_cplus set) has both the encoded and non-encoded names
913 tested for a match. */
916 lookup_block_symbol (block, name, namespace)
917 register const struct block *block;
919 const namespace_enum namespace;
921 register int bot, top, inc;
922 register struct symbol *sym;
923 register struct symbol *sym_found = NULL;
924 register int do_linear_search = 1;
926 /* If the blocks's symbols were sorted, start with a binary search. */
928 if (BLOCK_SHOULD_SORT (block))
930 /* Reset the linear search flag so if the binary search fails, we
931 won't do the linear search once unless we find some reason to
932 do so, such as finding a C++ symbol during the binary search.
933 Note that for C++ modules, ALL the symbols in a block should
934 end up marked as C++ symbols. */
936 do_linear_search = 0;
937 top = BLOCK_NSYMS (block);
940 /* Advance BOT to not far before the first symbol whose name is NAME. */
944 inc = (top - bot + 1);
945 /* No need to keep binary searching for the last few bits worth. */
950 inc = (inc >> 1) + bot;
951 sym = BLOCK_SYM (block, inc);
952 if (!do_linear_search && SYMBOL_LANGUAGE (sym) == language_cplus)
954 do_linear_search = 1;
956 if (SYMBOL_NAME (sym)[0] < name[0])
960 else if (SYMBOL_NAME (sym)[0] > name[0])
964 else if (STRCMP (SYMBOL_NAME (sym), name) < 0)
974 /* Now scan forward until we run out of symbols, find one whose
975 name is greater than NAME, or find one we want. If there is
976 more than one symbol with the right name and namespace, we
977 return the first one; I believe it is now impossible for us
978 to encounter two symbols with the same name and namespace
979 here, because blocks containing argument symbols are no
982 top = BLOCK_NSYMS (block);
985 sym = BLOCK_SYM (block, bot);
986 inc = SYMBOL_NAME (sym)[0] - name[0];
989 inc = STRCMP (SYMBOL_NAME (sym), name);
991 if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)
1003 /* Here if block isn't sorted, or we fail to find a match during the
1004 binary search above. If during the binary search above, we find a
1005 symbol which is a C++ symbol, then we have re-enabled the linear
1006 search flag which was reset when starting the binary search.
1008 This loop is equivalent to the loop above, but hacked greatly for speed.
1010 Note that parameter symbols do not always show up last in the
1011 list; this loop makes sure to take anything else other than
1012 parameter symbols first; it only uses parameter symbols as a
1013 last resort. Note that this only takes up extra computation
1016 if (do_linear_search)
1018 top = BLOCK_NSYMS (block);
1022 sym = BLOCK_SYM (block, bot);
1023 if (SYMBOL_NAMESPACE (sym) == namespace &&
1024 SYMBOL_MATCHES_NAME (sym, name))
1027 if (SYMBOL_CLASS (sym) != LOC_ARG &&
1028 SYMBOL_CLASS (sym) != LOC_LOCAL_ARG &&
1029 SYMBOL_CLASS (sym) != LOC_REF_ARG &&
1030 SYMBOL_CLASS (sym) != LOC_REGPARM &&
1031 SYMBOL_CLASS (sym) != LOC_REGPARM_ADDR &&
1032 SYMBOL_CLASS (sym) != LOC_BASEREG_ARG)
1040 return (sym_found); /* Will be NULL if not found. */
1044 /* Return the symbol for the function which contains a specified
1045 lexical block, described by a struct block BL. */
1051 while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
1052 bl = BLOCK_SUPERBLOCK (bl);
1054 return BLOCK_FUNCTION (bl);
1057 /* Find the symtab associated with PC and SECTION. Look through the
1058 psymtabs and read in another symtab if necessary. */
1061 find_pc_sect_symtab (pc, section)
1065 register struct block *b;
1066 struct blockvector *bv;
1067 register struct symtab *s = NULL;
1068 register struct symtab *best_s = NULL;
1069 register struct partial_symtab *ps;
1070 register struct objfile *objfile;
1073 /* Search all symtabs for the one whose file contains our address, and which
1074 is the smallest of all the ones containing the address. This is designed
1075 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1076 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1077 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1079 This happens for native ecoff format, where code from included files
1080 gets its own symtab. The symtab for the included file should have
1081 been read in already via the dependency mechanism.
1082 It might be swifter to create several symtabs with the same name
1083 like xcoff does (I'm not sure).
1085 It also happens for objfiles that have their functions reordered.
1086 For these, the symtab we are looking for is not necessarily read in. */
1088 ALL_SYMTABS (objfile, s)
1090 bv = BLOCKVECTOR (s);
1091 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1092 if (BLOCK_START (b) <= pc
1093 && BLOCK_END (b) > pc
1095 || BLOCK_END (b) - BLOCK_START (b) < distance))
1097 /* For an objfile that has its functions reordered,
1098 find_pc_psymtab will find the proper partial symbol table
1099 and we simply return its corresponding symtab. */
1100 /* In order to better support objfiles that contain both
1101 stabs and coff debugging info, we continue on if a psymtab
1103 if ((objfile->flags & OBJF_REORDERED) && objfile->psymtabs)
1105 ps = find_pc_sect_psymtab (pc, section);
1107 return PSYMTAB_TO_SYMTAB (ps);
1113 for (i = 0; i < b->nsyms; i++)
1115 fixup_symbol_section (b->sym[i], objfile);
1116 if (section == SYMBOL_BFD_SECTION (b->sym[i]))
1120 continue; /* no symbol in this symtab matches section */
1122 distance = BLOCK_END (b) - BLOCK_START (b);
1131 ps = find_pc_sect_psymtab (pc, section);
1135 /* Might want to error() here (in case symtab is corrupt and
1136 will cause a core dump), but maybe we can successfully
1137 continue, so let's not. */
1138 /* FIXME-32x64: assumes pc fits in a long */
1140 (Internal error: pc 0x%lx in read in psymtab, but not in symtab.)\n",
1141 (unsigned long) pc);
1142 s = PSYMTAB_TO_SYMTAB (ps);
1147 /* Find the symtab associated with PC. Look through the psymtabs and
1148 read in another symtab if necessary. Backward compatibility, no section */
1154 return find_pc_sect_symtab (pc, find_pc_mapped_section (pc));
1160 /* Find the closest symbol value (of any sort -- function or variable)
1161 for a given address value. Slow but complete. (currently unused,
1162 mainly because it is too slow. We could fix it if each symtab and
1163 psymtab had contained in it the addresses ranges of each of its
1164 sections, which also would be required to make things like "info
1165 line *0x2345" cause psymtabs to be converted to symtabs). */
1168 find_addr_symbol (addr, symtabp, symaddrp)
1170 struct symtab **symtabp;
1171 CORE_ADDR *symaddrp;
1173 struct symtab *symtab, *best_symtab;
1174 struct objfile *objfile;
1175 register int bot, top;
1176 register struct symbol *sym;
1177 register CORE_ADDR sym_addr;
1178 struct block *block;
1181 /* Info on best symbol seen so far */
1183 register CORE_ADDR best_sym_addr = 0;
1184 struct symbol *best_sym = 0;
1186 /* FIXME -- we should pull in all the psymtabs, too! */
1187 ALL_SYMTABS (objfile, symtab)
1189 /* Search the global and static blocks in this symtab for
1190 the closest symbol-address to the desired address. */
1192 for (blocknum = GLOBAL_BLOCK; blocknum <= STATIC_BLOCK; blocknum++)
1195 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), blocknum);
1196 top = BLOCK_NSYMS (block);
1197 for (bot = 0; bot < top; bot++)
1199 sym = BLOCK_SYM (block, bot);
1200 switch (SYMBOL_CLASS (sym))
1204 sym_addr = SYMBOL_VALUE_ADDRESS (sym);
1208 sym_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1215 if (sym_addr <= addr)
1216 if (sym_addr > best_sym_addr)
1218 /* Quit if we found an exact match. */
1220 best_sym_addr = sym_addr;
1221 best_symtab = symtab;
1222 if (sym_addr == addr)
1231 *symtabp = best_symtab;
1233 *symaddrp = best_sym_addr;
1238 /* Find the source file and line number for a given PC value and section.
1239 Return a structure containing a symtab pointer, a line number,
1240 and a pc range for the entire source line.
1241 The value's .pc field is NOT the specified pc.
1242 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1243 use the line that ends there. Otherwise, in that case, the line
1244 that begins there is used. */
1246 /* The big complication here is that a line may start in one file, and end just
1247 before the start of another file. This usually occurs when you #include
1248 code in the middle of a subroutine. To properly find the end of a line's PC
1249 range, we must search all symtabs associated with this compilation unit, and
1250 find the one whose first PC is closer than that of the next line in this
1253 /* If it's worth the effort, we could be using a binary search. */
1255 struct symtab_and_line
1256 find_pc_sect_line (pc, section, notcurrent)
1258 struct sec *section;
1262 register struct linetable *l;
1265 register struct linetable_entry *item;
1266 struct symtab_and_line val;
1267 struct blockvector *bv;
1269 /* Info on best line seen so far, and where it starts, and its file. */
1271 struct linetable_entry *best = NULL;
1272 CORE_ADDR best_end = 0;
1273 struct symtab *best_symtab = 0;
1275 /* Store here the first line number
1276 of a file which contains the line at the smallest pc after PC.
1277 If we don't find a line whose range contains PC,
1278 we will use a line one less than this,
1279 with a range from the start of that file to the first line's pc. */
1280 struct linetable_entry *alt = NULL;
1281 struct symtab *alt_symtab = 0;
1283 /* Info on best line seen in this file. */
1285 struct linetable_entry *prev;
1287 /* If this pc is not from the current frame,
1288 it is the address of the end of a call instruction.
1289 Quite likely that is the start of the following statement.
1290 But what we want is the statement containing the instruction.
1291 Fudge the pc to make sure we get that. */
1293 INIT_SAL (&val); /* initialize to zeroes */
1298 s = find_pc_sect_symtab (pc, section);
1305 bv = BLOCKVECTOR (s);
1307 /* Look at all the symtabs that share this blockvector.
1308 They all have the same apriori range, that we found was right;
1309 but they have different line tables. */
1311 for (; s && BLOCKVECTOR (s) == bv; s = s->next)
1313 /* Find the best line in this symtab. */
1320 /* I think len can be zero if the symtab lacks line numbers
1321 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
1322 I'm not sure which, and maybe it depends on the symbol
1328 item = l->item; /* Get first line info */
1330 /* Is this file's first line closer than the first lines of other files?
1331 If so, record this file, and its first line, as best alternate. */
1332 if (item->pc > pc && (!alt || item->pc < alt->pc))
1338 for (i = 0; i < len; i++, item++)
1340 /* Leave prev pointing to the linetable entry for the last line
1341 that started at or before PC. */
1348 /* At this point, prev points at the line whose start addr is <= pc, and
1349 item points at the next line. If we ran off the end of the linetable
1350 (pc >= start of the last line), then prev == item. If pc < start of
1351 the first line, prev will not be set. */
1353 /* Is this file's best line closer than the best in the other files?
1354 If so, record this file, and its best line, as best so far. */
1356 if (prev && (!best || prev->pc > best->pc))
1360 /* If another line is in the linetable, and its PC is closer
1361 than the best_end we currently have, take it as best_end. */
1362 if (i < len && (best_end == 0 || best_end > item->pc))
1363 best_end = item->pc;
1370 { /* If we didn't find any line # info, just
1376 val.symtab = alt_symtab;
1377 val.line = alt->line - 1;
1379 /* Don't return line 0, that means that we didn't find the line. */
1380 if (val.line == 0) ++val.line;
1382 val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1388 val.symtab = best_symtab;
1389 val.line = best->line;
1391 if (best_end && (!alt || best_end < alt->pc))
1396 val.end = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1398 val.section = section;
1402 /* Backward compatibility (no section) */
1404 struct symtab_and_line
1405 find_pc_line (pc, notcurrent)
1411 section = find_pc_overlay (pc);
1412 if (pc_in_unmapped_range (pc, section))
1413 pc = overlay_mapped_address (pc, section);
1414 return find_pc_sect_line (pc, section, notcurrent);
1418 static int find_line_symtab PARAMS ((struct symtab *, int, struct linetable **,
1421 /* Find line number LINE in any symtab whose name is the same as
1424 If found, return 1, set *LINETABLE to the linetable in which it was
1425 found, set *INDEX to the index in the linetable of the best entry
1426 found, and set *EXACT_MATCH nonzero if the value returned is an
1429 If not found, return 0. */
1432 find_line_symtab (symtab, line, linetable, index, exact_match)
1433 struct symtab *symtab;
1435 struct linetable **linetable;
1441 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
1445 struct linetable *best_linetable;
1447 /* First try looking it up in the given symtab. */
1448 best_linetable = LINETABLE (symtab);
1449 best_index = find_line_common (best_linetable, line, &exact);
1450 if (best_index < 0 || !exact)
1452 /* Didn't find an exact match. So we better keep looking for
1453 another symtab with the same name. In the case of xcoff,
1454 multiple csects for one source file (produced by IBM's FORTRAN
1455 compiler) produce multiple symtabs (this is unavoidable
1456 assuming csects can be at arbitrary places in memory and that
1457 the GLOBAL_BLOCK of a symtab has a begin and end address). */
1459 /* BEST is the smallest linenumber > LINE so far seen,
1460 or 0 if none has been seen so far.
1461 BEST_INDEX and BEST_LINETABLE identify the item for it. */
1464 struct objfile *objfile;
1467 if (best_index >= 0)
1468 best = best_linetable->item[best_index].line;
1472 ALL_SYMTABS (objfile, s)
1474 struct linetable *l;
1477 if (!STREQ (symtab->filename, s->filename))
1480 ind = find_line_common (l, line, &exact);
1489 if (best == 0 || l->item[ind].line < best)
1491 best = l->item[ind].line;
1503 *index = best_index;
1505 *linetable = best_linetable;
1507 *exact_match = exact;
1511 /* Find the PC value for a given source file and line number.
1512 Returns zero for invalid line number.
1513 The source file is specified with a struct symtab. */
1516 find_line_pc (symtab, line)
1517 struct symtab *symtab;
1520 struct linetable *l;
1525 if (find_line_symtab (symtab, line, &l, &ind, NULL))
1526 return l->item[ind].pc;
1531 /* Find the range of pc values in a line.
1532 Store the starting pc of the line into *STARTPTR
1533 and the ending pc (start of next line) into *ENDPTR.
1534 Returns 1 to indicate success.
1535 Returns 0 if could not find the specified line. */
1538 find_line_pc_range (sal, startptr, endptr)
1539 struct symtab_and_line sal;
1540 CORE_ADDR *startptr, *endptr;
1542 CORE_ADDR startaddr;
1543 struct symtab_and_line found_sal;
1548 startaddr = find_line_pc (sal.symtab, sal.line);
1553 /* This whole function is based on address. For example, if line 10 has
1554 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
1555 "info line *0x123" should say the line goes from 0x100 to 0x200
1556 and "info line *0x355" should say the line goes from 0x300 to 0x400.
1557 This also insures that we never give a range like "starts at 0x134
1558 and ends at 0x12c". */
1560 found_sal = find_pc_sect_line (startaddr, sal.section, 0);
1561 if (found_sal.line != sal.line)
1563 /* The specified line (sal) has zero bytes. */
1564 *startptr = found_sal.pc;
1565 *endptr = found_sal.pc;
1569 *startptr = found_sal.pc;
1570 *endptr = found_sal.end;
1575 /* Given a line table and a line number, return the index into the line
1576 table for the pc of the nearest line whose number is >= the specified one.
1577 Return -1 if none is found. The value is >= 0 if it is an index.
1579 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1582 find_line_common (l, lineno, exact_match)
1583 register struct linetable *l;
1584 register int lineno;
1590 /* BEST is the smallest linenumber > LINENO so far seen,
1591 or 0 if none has been seen so far.
1592 BEST_INDEX identifies the item for it. */
1594 int best_index = -1;
1603 for (i = 0; i < len; i++)
1605 register struct linetable_entry *item = &(l->item[i]);
1607 if (item->line == lineno)
1609 /* Return the first (lowest address) entry which matches. */
1614 if (item->line > lineno && (best == 0 || item->line < best))
1621 /* If we got here, we didn't get an exact match. */
1628 find_pc_line_pc_range (pc, startptr, endptr)
1630 CORE_ADDR *startptr, *endptr;
1632 struct symtab_and_line sal;
1633 sal = find_pc_line (pc, 0);
1636 return sal.symtab != 0;
1639 /* Given a function symbol SYM, find the symtab and line for the start
1641 If the argument FUNFIRSTLINE is nonzero, we want the first line
1642 of real code inside the function. */
1644 static struct symtab_and_line
1645 find_function_start_sal PARAMS ((struct symbol *sym, int));
1647 static struct symtab_and_line
1648 find_function_start_sal (sym, funfirstline)
1653 struct symtab_and_line sal;
1655 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1656 fixup_symbol_section (sym, NULL);
1658 { /* skip "first line" of function (which is actually its prologue) */
1659 asection *section = SYMBOL_BFD_SECTION (sym);
1660 /* If function is in an unmapped overlay, use its unmapped LMA
1661 address, so that SKIP_PROLOGUE has something unique to work on */
1662 if (section_is_overlay (section) &&
1663 !section_is_mapped (section))
1664 pc = overlay_unmapped_address (pc, section);
1666 pc += FUNCTION_START_OFFSET;
1669 /* For overlays, map pc back into its mapped VMA range */
1670 pc = overlay_mapped_address (pc, section);
1672 sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0);
1674 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1675 /* Convex: no need to suppress code on first line, if any */
1678 /* Check if SKIP_PROLOGUE left us in mid-line, and the next
1679 line is still part of the same function. */
1681 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) <= sal.end
1682 && sal.end < BLOCK_END (SYMBOL_BLOCK_VALUE (sym)))
1684 /* First pc of next line */
1686 /* Recalculate the line number (might not be N+1). */
1687 sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0);
1695 /* If P is of the form "operator[ \t]+..." where `...' is
1696 some legitimate operator text, return a pointer to the
1697 beginning of the substring of the operator text.
1698 Otherwise, return "". */
1700 operator_chars (p, end)
1705 if (strncmp (p, "operator", 8))
1709 /* Don't get faked out by `operator' being part of a longer
1711 if (isalpha(*p) || *p == '_' || *p == '$' || *p == '\0')
1714 /* Allow some whitespace between `operator' and the operator symbol. */
1715 while (*p == ' ' || *p == '\t')
1718 /* Recognize 'operator TYPENAME'. */
1720 if (isalpha(*p) || *p == '_' || *p == '$')
1722 register char *q = p+1;
1723 while (isalnum(*q) || *q == '_' || *q == '$')
1748 if (p[1] == '=' || p[1] == p[0])
1759 error ("`operator ()' must be specified without whitespace in `()'");
1764 error ("`operator ?:' must be specified without whitespace in `?:'");
1769 error ("`operator []' must be specified without whitespace in `[]'");
1773 error ("`operator %s' not supported", p);
1780 /* Return the number of methods described for TYPE, including the
1781 methods from types it derives from. This can't be done in the symbol
1782 reader because the type of the baseclass might still be stubbed
1783 when the definition of the derived class is parsed. */
1785 static int total_number_of_methods PARAMS ((struct type *type));
1788 total_number_of_methods (type)
1794 CHECK_TYPEDEF (type);
1795 if (TYPE_CPLUS_SPECIFIC (type) == NULL)
1797 count = TYPE_NFN_FIELDS_TOTAL (type);
1799 for (n = 0; n < TYPE_N_BASECLASSES (type); n++)
1800 count += total_number_of_methods (TYPE_BASECLASS (type, n));
1805 /* Recursive helper function for decode_line_1.
1806 Look for methods named NAME in type T.
1807 Return number of matches.
1808 Put matches in SYM_ARR, which should have been allocated with
1809 a size of total_number_of_methods (T) * sizeof (struct symbol *).
1810 Note that this function is g++ specific. */
1813 find_methods (t, name, sym_arr)
1816 struct symbol **sym_arr;
1820 struct symbol *sym_class;
1821 char *class_name = type_name_no_tag (t);
1822 /* Ignore this class if it doesn't have a name. This is ugly, but
1823 unless we figure out how to get the physname without the name of
1824 the class, then the loop can't do any good. */
1826 && (sym_class = lookup_symbol (class_name,
1827 (struct block *)NULL,
1830 (struct symtab **)NULL)))
1833 /* FIXME: Shouldn't this just be CHECK_TYPEDEF (t)? */
1834 t = SYMBOL_TYPE (sym_class);
1835 for (method_counter = TYPE_NFN_FIELDS (t) - 1;
1836 method_counter >= 0;
1840 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, method_counter);
1841 char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
1842 char dem_opname[64];
1844 if (strncmp(method_name, "__", 2)==0 ||
1845 strncmp(method_name, "op", 2)==0 ||
1846 strncmp(method_name, "type", 4)==0 )
1848 if (cplus_demangle_opname(method_name, dem_opname, DMGL_ANSI))
1849 method_name = dem_opname;
1850 else if (cplus_demangle_opname(method_name, dem_opname, 0))
1851 method_name = dem_opname;
1853 if (STREQ (name, method_name))
1854 /* Find all the fields with that name. */
1855 for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
1860 if (TYPE_FN_FIELD_STUB (f, field_counter))
1861 check_stub_method (t, method_counter, field_counter);
1862 phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
1863 /* Destructor is handled by caller, dont add it to the list */
1864 if (DESTRUCTOR_PREFIX_P (phys_name))
1867 sym_arr[i1] = lookup_symbol (phys_name,
1868 NULL, VAR_NAMESPACE,
1870 (struct symtab **) NULL);
1875 fputs_filtered("(Cannot find method ", gdb_stdout);
1876 fprintf_symbol_filtered (gdb_stdout, phys_name,
1878 DMGL_PARAMS | DMGL_ANSI);
1879 fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
1885 /* Only search baseclasses if there is no match yet, since names in
1886 derived classes override those in baseclasses.
1888 FIXME: The above is not true; it is only true of member functions
1889 if they have the same number of arguments (??? - section 13.1 of the
1890 ARM says the function members are not in the same scope but doesn't
1891 really spell out the rules in a way I understand. In any case, if
1892 the number of arguments differ this is a case in which we can overload
1893 rather than hiding without any problem, and gcc 2.4.5 does overload
1894 rather than hiding in this case). */
1898 for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
1899 i1 += find_methods(TYPE_BASECLASS(t, ibase), name,
1904 /* Helper function for decode_line_1.
1905 Build a canonical line spec in CANONICAL if it is non-NULL and if
1906 the SAL has a symtab.
1907 If SYMNAME is non-NULL the canonical line spec is `filename:symname'.
1908 If SYMNAME is NULL the line number from SAL is used and the canonical
1909 line spec is `filename:linenum'. */
1912 build_canonical_line_spec (sal, symname, canonical)
1913 struct symtab_and_line *sal;
1917 char **canonical_arr;
1918 char *canonical_name;
1920 struct symtab *s = sal->symtab;
1922 if (s == (struct symtab *)NULL
1923 || s->filename == (char *)NULL
1924 || canonical == (char ***)NULL)
1927 canonical_arr = (char **) xmalloc (sizeof (char *));
1928 *canonical = canonical_arr;
1930 filename = s->filename;
1931 if (symname != NULL)
1933 canonical_name = xmalloc (strlen (filename) + strlen (symname) + 2);
1934 sprintf (canonical_name, "%s:%s", filename, symname);
1938 canonical_name = xmalloc (strlen (filename) + 30);
1939 sprintf (canonical_name, "%s:%d", filename, sal->line);
1941 canonical_arr[0] = canonical_name;
1944 /* Parse a string that specifies a line number.
1945 Pass the address of a char * variable; that variable will be
1946 advanced over the characters actually parsed.
1950 LINENUM -- that line number in current file. PC returned is 0.
1951 FILE:LINENUM -- that line in that file. PC returned is 0.
1952 FUNCTION -- line number of openbrace of that function.
1953 PC returned is the start of the function.
1954 VARIABLE -- line number of definition of that variable.
1956 FILE:FUNCTION -- likewise, but prefer functions in that file.
1957 *EXPR -- line in which address EXPR appears.
1959 FUNCTION may be an undebuggable function found in minimal symbol table.
1961 If the argument FUNFIRSTLINE is nonzero, we want the first line
1962 of real code inside a function when a function is specified, and it is
1963 not OK to specify a variable or type to get its line number.
1965 DEFAULT_SYMTAB specifies the file to use if none is specified.
1966 It defaults to current_source_symtab.
1967 DEFAULT_LINE specifies the line number to use for relative
1968 line numbers (that start with signs). Defaults to current_source_line.
1969 If CANONICAL is non-NULL, store an array of strings containing the canonical
1970 line specs there if necessary. Currently overloaded member functions and
1971 line numbers or static functions without a filename yield a canonical
1972 line spec. The array and the line spec strings are allocated on the heap,
1973 it is the callers responsibility to free them.
1975 Note that it is possible to return zero for the symtab
1976 if no file is validly specified. Callers must check that.
1977 Also, the line number returned may be invalid. */
1979 /* We allow single quotes in various places. This is a hideous
1980 kludge, which exists because the completer can't yet deal with the
1981 lack of single quotes. FIXME: write a linespec_completer which we
1982 can use as appropriate instead of make_symbol_completion_list. */
1984 struct symtabs_and_lines
1985 decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
1988 struct symtab *default_symtab;
1992 struct symtabs_and_lines values;
1993 #ifdef HPPA_COMPILER_BUG
1994 /* FIXME: The native HP 9000/700 compiler has a bug which appears
1995 when optimizing this file with target i960-vxworks. I haven't
1996 been able to construct a simple test case. The problem is that
1997 in the second call to SKIP_PROLOGUE below, the compiler somehow
1998 does not realize that the statement val = find_pc_line (...) will
1999 change the values of the fields of val. It extracts the elements
2000 into registers at the top of the block, and does not update the
2001 registers after the call to find_pc_line. You can check this by
2002 inserting a printf at the end of find_pc_line to show what values
2003 it is returning for val.pc and val.end and another printf after
2004 the call to see what values the function actually got (remember,
2005 this is compiling with cc -O, with this patch removed). You can
2006 also examine the assembly listing: search for the second call to
2007 skip_prologue; the LDO statement before the next call to
2008 find_pc_line loads the address of the structure which
2009 find_pc_line will return; if there is a LDW just before the LDO,
2010 which fetches an element of the structure, then the compiler
2013 Setting val to volatile avoids the problem. We must undef
2014 volatile, because the HPPA native compiler does not define
2015 __STDC__, although it does understand volatile, and so volatile
2016 will have been defined away in defs.h. */
2018 volatile struct symtab_and_line val;
2019 #define volatile /*nothing*/
2021 struct symtab_and_line val;
2023 register char *p, *p1;
2028 register struct symtab *s;
2030 register struct symbol *sym;
2031 /* The symtab that SYM was found in. */
2032 struct symtab *sym_symtab;
2034 register CORE_ADDR pc;
2035 register struct minimal_symbol *msymbol;
2037 struct symbol *sym_class;
2039 int is_quoted, has_parens;
2040 struct symbol **sym_arr;
2042 char *saved_arg = *argptr;
2043 extern char *gdb_completer_quote_characters;
2045 INIT_SAL (&val); /* initialize to zeroes */
2047 /* Defaults have defaults. */
2049 if (default_symtab == 0)
2051 default_symtab = current_source_symtab;
2052 default_line = current_source_line;
2055 /* See if arg is *PC */
2057 if (**argptr == '*')
2060 pc = parse_and_eval_address_1 (argptr);
2061 values.sals = (struct symtab_and_line *)
2062 xmalloc (sizeof (struct symtab_and_line));
2064 values.sals[0] = find_pc_line (pc, 0);
2065 values.sals[0].pc = pc;
2069 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
2072 is_quoted = (**argptr
2073 && strchr (gdb_completer_quote_characters, **argptr) != NULL);
2074 has_parens = ((pp = strchr (*argptr, '(')) != NULL
2075 && (pp = strchr (pp, ')')) != NULL);
2077 for (p = *argptr; *p; p++)
2081 while(++p && *p != '>');
2084 error ("non-matching '<' and '>' in command");
2087 if (p[0] == ':' || p[0] == ' ' || p[0] == '\t')
2090 while (p[0] == ' ' || p[0] == '\t') p++;
2092 if ((p[0] == ':') && !has_parens)
2096 if (is_quoted) *argptr = *argptr+1;
2099 /* Extract the class name. */
2101 while (p != *argptr && p[-1] == ' ') --p;
2102 copy = (char *) alloca (p - *argptr + 1);
2103 memcpy (copy, *argptr, p - *argptr);
2104 copy[p - *argptr] = 0;
2106 /* Discard the class name from the arg. */
2108 while (*p == ' ' || *p == '\t') p++;
2111 sym_class = lookup_symbol (copy, 0, STRUCT_NAMESPACE, 0,
2112 (struct symtab **)NULL);
2115 (t = check_typedef (SYMBOL_TYPE (sym_class)),
2116 (TYPE_CODE (t) == TYPE_CODE_STRUCT
2117 || TYPE_CODE (t) == TYPE_CODE_UNION)))
2119 /* Arg token is not digits => try it as a function name
2120 Find the next token(everything up to end or next blank). */
2122 && strchr (gdb_completer_quote_characters, **argptr) != NULL)
2124 p = skip_quoted(*argptr);
2125 *argptr = *argptr + 1;
2130 while (*p && *p!=' ' && *p!='\t' && *p!=',' && *p!=':') p++;
2133 q = operator_chars (*argptr, &q1);
2137 char *tmp = alloca (q1 - q + 1);
2138 memcpy (tmp, q, q1 - q);
2140 opname = cplus_mangle_opname (tmp, DMGL_ANSI);
2144 printf_filtered ("no mangling for \"%s\"\n", tmp);
2145 cplusplus_hint (saved_arg);
2146 return_to_top_level (RETURN_ERROR);
2148 copy = (char*) alloca (3 + strlen(opname));
2149 sprintf (copy, "__%s", opname);
2155 copy = (char *) alloca (p - *argptr + 1 );
2156 memcpy (copy, *argptr, p - *argptr);
2157 copy[p - *argptr] = '\0';
2159 && copy[p - *argptr - 1]
2160 && strchr (gdb_completer_quote_characters,
2161 copy[p - *argptr - 1]) != NULL)
2162 copy[p - *argptr - 1] = '\0';
2165 /* no line number may be specified */
2166 while (*p == ' ' || *p == '\t') p++;
2170 i1 = 0; /* counter for the symbol array */
2171 sym_arr = (struct symbol **) alloca(total_number_of_methods (t)
2172 * sizeof(struct symbol *));
2174 if (destructor_name_p (copy, t))
2176 /* Destructors are a special case. */
2177 int m_index, f_index;
2179 if (get_destructor_fn_field (t, &m_index, &f_index))
2181 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, m_index);
2184 lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, f_index),
2185 NULL, VAR_NAMESPACE, (int *) NULL,
2186 (struct symtab **)NULL);
2192 i1 = find_methods (t, copy, sym_arr);
2195 /* There is exactly one field with that name. */
2198 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
2200 values.sals = (struct symtab_and_line *)
2201 xmalloc (sizeof (struct symtab_and_line));
2203 values.sals[0] = find_function_start_sal (sym,
2214 /* There is more than one field with that name
2215 (overloaded). Ask the user which one to use. */
2216 return decode_line_2 (sym_arr, i1, funfirstline, canonical);
2222 if (OPNAME_PREFIX_P (copy))
2224 tmp = (char *)alloca (strlen (copy+3) + 9);
2225 strcpy (tmp, "operator ");
2226 strcat (tmp, copy+3);
2233 ("the class `%s' does not have destructor defined\n",
2234 SYMBOL_SOURCE_NAME(sym_class));
2237 ("the class %s does not have any method named %s\n",
2238 SYMBOL_SOURCE_NAME(sym_class), tmp);
2239 cplusplus_hint (saved_arg);
2240 return_to_top_level (RETURN_ERROR);
2246 /* The quotes are important if copy is empty. */
2248 ("can't find class, struct, or union named \"%s\"\n", copy);
2249 cplusplus_hint (saved_arg);
2250 return_to_top_level (RETURN_ERROR);
2256 /* Extract the file name. */
2258 while (p != *argptr && p[-1] == ' ') --p;
2259 copy = (char *) alloca (p - *argptr + 1);
2260 memcpy (copy, *argptr, p - *argptr);
2261 copy[p - *argptr] = 0;
2263 /* Find that file's data. */
2264 s = lookup_symtab (copy);
2267 if (!have_full_symbols () && !have_partial_symbols ())
2268 error (no_symtab_msg);
2269 error ("No source file named %s.", copy);
2272 /* Discard the file name from the arg. */
2274 while (*p == ' ' || *p == '\t') p++;
2278 /* S is specified file's symtab, or 0 if no file specified.
2279 arg no longer contains the file name. */
2281 /* Check whether arg is all digits (and sign) */
2284 if (*q == '-' || *q == '+') q++;
2285 while (*q >= '0' && *q <= '9')
2288 if (q != *argptr && (*q == 0 || *q == ' ' || *q == '\t' || *q == ','))
2290 /* We found a token consisting of all digits -- at least one digit. */
2291 enum sign {none, plus, minus} sign = none;
2293 /* We might need a canonical line spec if no file was specified. */
2294 int need_canonical = (s == 0) ? 1 : 0;
2296 /* This is where we need to make sure that we have good defaults.
2297 We must guarantee that this section of code is never executed
2298 when we are called with just a function name, since
2299 select_source_symtab calls us with such an argument */
2301 if (s == 0 && default_symtab == 0)
2303 select_source_symtab (0);
2304 default_symtab = current_source_symtab;
2305 default_line = current_source_line;
2308 if (**argptr == '+')
2309 sign = plus, (*argptr)++;
2310 else if (**argptr == '-')
2311 sign = minus, (*argptr)++;
2312 val.line = atoi (*argptr);
2319 val.line = default_line + val.line;
2325 val.line = default_line - val.line;
2330 break; /* No need to adjust val.line. */
2333 while (*q == ' ' || *q == '\t') q++;
2339 values.sals = (struct symtab_and_line *)
2340 xmalloc (sizeof (struct symtab_and_line));
2341 values.sals[0] = val;
2344 build_canonical_line_spec (values.sals, NULL, canonical);
2348 /* Arg token is not digits => try it as a variable name
2349 Find the next token (everything up to end or next whitespace). */
2351 if (**argptr == '$') /* Convenience variable */
2352 p = skip_quoted (*argptr + 1);
2355 p = skip_quoted (*argptr);
2357 error ("Unmatched single quote.");
2359 else if (has_parens)
2365 p = skip_quoted(*argptr);
2368 copy = (char *) alloca (p - *argptr + 1);
2369 memcpy (copy, *argptr, p - *argptr);
2370 copy[p - *argptr] = '\0';
2373 && copy[0] == copy [p - *argptr - 1]
2374 && strchr (gdb_completer_quote_characters, copy[0]) != NULL)
2376 copy [p - *argptr - 1] = '\0';
2379 while (*p == ' ' || *p == '\t') p++;
2382 /* See if it's a convenience variable */
2387 int need_canonical = (s == 0) ? 1 : 0;
2389 valx = value_of_internalvar (lookup_internalvar (copy + 1));
2390 if (TYPE_CODE (VALUE_TYPE (valx)) != TYPE_CODE_INT)
2391 error ("Convenience variables used in line specs must have integer values.");
2393 val.symtab = s ? s : default_symtab;
2394 val.line = value_as_long (valx);
2397 values.sals = (struct symtab_and_line *)xmalloc (sizeof val);
2398 values.sals[0] = val;
2402 build_canonical_line_spec (values.sals, NULL, canonical);
2408 /* Look up that token as a variable.
2409 If file specified, use that file's per-file block to start with. */
2411 sym = lookup_symbol (copy,
2412 (s ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)
2413 : get_selected_block ()),
2414 VAR_NAMESPACE, 0, &sym_symtab);
2418 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
2420 /* Arg is the name of a function */
2421 values.sals = (struct symtab_and_line *)
2422 xmalloc (sizeof (struct symtab_and_line));
2423 values.sals[0] = find_function_start_sal (sym, funfirstline);
2426 /* Don't use the SYMBOL_LINE; if used at all it points to
2427 the line containing the parameters or thereabouts, not
2428 the first line of code. */
2430 /* We might need a canonical line spec if it is a static
2434 struct blockvector *bv = BLOCKVECTOR (sym_symtab);
2435 struct block *b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
2436 if (lookup_block_symbol (b, copy, VAR_NAMESPACE) != NULL)
2437 build_canonical_line_spec (values.sals, copy, canonical);
2444 error ("\"%s\" is not a function", copy);
2445 else if (SYMBOL_LINE (sym) != 0)
2447 /* We know its line number. */
2448 values.sals = (struct symtab_and_line *)
2449 xmalloc (sizeof (struct symtab_and_line));
2451 memset (&values.sals[0], 0, sizeof (values.sals[0]));
2452 values.sals[0].symtab = sym_symtab;
2453 values.sals[0].line = SYMBOL_LINE (sym);
2457 /* This can happen if it is compiled with a compiler which doesn't
2458 put out line numbers for variables. */
2459 /* FIXME: Shouldn't we just set .line and .symtab to zero
2460 and return? For example, "info line foo" could print
2462 error ("Line number not known for symbol \"%s\"", copy);
2466 msymbol = lookup_minimal_symbol (copy, NULL, NULL);
2467 if (msymbol != NULL)
2469 val.pc = SYMBOL_VALUE_ADDRESS (msymbol);
2470 val.section = SYMBOL_BFD_SECTION (msymbol);
2473 val.pc += FUNCTION_START_OFFSET;
2474 SKIP_PROLOGUE (val.pc);
2476 values.sals = (struct symtab_and_line *)
2477 xmalloc (sizeof (struct symtab_and_line));
2478 values.sals[0] = val;
2483 if (!have_full_symbols () &&
2484 !have_partial_symbols () && !have_minimal_symbols ())
2485 error (no_symtab_msg);
2487 error ("Function \"%s\" not defined.", copy);
2488 return values; /* for lint */
2491 struct symtabs_and_lines
2492 decode_line_spec (string, funfirstline)
2496 struct symtabs_and_lines sals;
2498 error ("Empty line specification.");
2499 sals = decode_line_1 (&string, funfirstline,
2500 current_source_symtab, current_source_line,
2503 error ("Junk at end of line specification: %s", string);
2507 /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to
2508 operate on (ask user if necessary).
2509 If CANONICAL is non-NULL return a corresponding array of mangled names
2510 as canonical line specs there. */
2512 static struct symtabs_and_lines
2513 decode_line_2 (sym_arr, nelts, funfirstline, canonical)
2514 struct symbol *sym_arr[];
2519 struct symtabs_and_lines values, return_values;
2524 struct cleanup *old_chain;
2525 char **canonical_arr = (char **)NULL;
2527 values.sals = (struct symtab_and_line *)
2528 alloca (nelts * sizeof(struct symtab_and_line));
2529 return_values.sals = (struct symtab_and_line *)
2530 xmalloc (nelts * sizeof(struct symtab_and_line));
2531 old_chain = make_cleanup (free, return_values.sals);
2535 canonical_arr = (char **) xmalloc (nelts * sizeof (char *));
2536 make_cleanup (free, canonical_arr);
2537 memset (canonical_arr, 0, nelts * sizeof (char *));
2538 *canonical = canonical_arr;
2542 printf_unfiltered("[0] cancel\n[1] all\n");
2545 INIT_SAL (&return_values.sals[i]); /* initialize to zeroes */
2546 INIT_SAL (&values.sals[i]);
2547 if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK)
2549 values.sals[i] = find_function_start_sal (sym_arr[i], funfirstline);
2550 printf_unfiltered ("[%d] %s at %s:%d\n",
2552 SYMBOL_SOURCE_NAME (sym_arr[i]),
2553 values.sals[i].symtab->filename,
2554 values.sals[i].line);
2557 printf_unfiltered ("?HERE\n");
2561 if ((prompt = getenv ("PS2")) == NULL)
2565 printf_unfiltered("%s ",prompt);
2566 gdb_flush(gdb_stdout);
2568 args = command_line_input ((char *) NULL, 0, "overload-choice");
2570 if (args == 0 || *args == 0)
2571 error_no_arg ("one or more choice numbers");
2579 while (*arg1 >= '0' && *arg1 <= '9') arg1++;
2580 if (*arg1 && *arg1 != ' ' && *arg1 != '\t')
2581 error ("Arguments must be choice numbers.");
2586 error ("cancelled");
2591 for (i = 0; i < nelts; i++)
2593 if (canonical_arr[i] == NULL)
2595 symname = SYMBOL_NAME (sym_arr[i]);
2596 canonical_arr[i] = savestring (symname, strlen (symname));
2600 memcpy (return_values.sals, values.sals,
2601 (nelts * sizeof(struct symtab_and_line)));
2602 return_values.nelts = nelts;
2603 discard_cleanups (old_chain);
2604 return return_values;
2607 if (num >= nelts + 2)
2609 printf_unfiltered ("No choice number %d.\n", num);
2614 if (values.sals[num].pc)
2618 symname = SYMBOL_NAME (sym_arr[num]);
2619 make_cleanup (free, symname);
2620 canonical_arr[i] = savestring (symname, strlen (symname));
2622 return_values.sals[i++] = values.sals[num];
2623 values.sals[num].pc = 0;
2627 printf_unfiltered ("duplicate request for %d ignored.\n", num);
2632 while (*args == ' ' || *args == '\t') args++;
2634 return_values.nelts = i;
2635 discard_cleanups (old_chain);
2636 return return_values;
2640 /* Slave routine for sources_info. Force line breaks at ,'s.
2641 NAME is the name to print and *FIRST is nonzero if this is the first
2642 name printed. Set *FIRST to zero. */
2644 output_source_filename (name, first)
2648 /* Table of files printed so far. Since a single source file can
2649 result in several partial symbol tables, we need to avoid printing
2650 it more than once. Note: if some of the psymtabs are read in and
2651 some are not, it gets printed both under "Source files for which
2652 symbols have been read" and "Source files for which symbols will
2653 be read in on demand". I consider this a reasonable way to deal
2654 with the situation. I'm not sure whether this can also happen for
2655 symtabs; it doesn't hurt to check. */
2656 static char **tab = NULL;
2657 /* Allocated size of tab in elements.
2658 Start with one 256-byte block (when using GNU malloc.c).
2659 24 is the malloc overhead when range checking is in effect. */
2660 static int tab_alloc_size = (256 - 24) / sizeof (char *);
2661 /* Current size of tab in elements. */
2662 static int tab_cur_size;
2669 tab = (char **) xmalloc (tab_alloc_size * sizeof (*tab));
2673 /* Is NAME in tab? */
2674 for (p = tab; p < tab + tab_cur_size; p++)
2675 if (STREQ (*p, name))
2676 /* Yes; don't print it again. */
2678 /* No; add it to tab. */
2679 if (tab_cur_size == tab_alloc_size)
2681 tab_alloc_size *= 2;
2682 tab = (char **) xrealloc ((char *) tab, tab_alloc_size * sizeof (*tab));
2684 tab[tab_cur_size++] = name;
2692 printf_filtered (", ");
2696 fputs_filtered (name, gdb_stdout);
2700 sources_info (ignore, from_tty)
2704 register struct symtab *s;
2705 register struct partial_symtab *ps;
2706 register struct objfile *objfile;
2709 if (!have_full_symbols () && !have_partial_symbols ())
2711 error (no_symtab_msg);
2714 printf_filtered ("Source files for which symbols have been read in:\n\n");
2717 ALL_SYMTABS (objfile, s)
2719 output_source_filename (s -> filename, &first);
2721 printf_filtered ("\n\n");
2723 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2726 ALL_PSYMTABS (objfile, ps)
2730 output_source_filename (ps -> filename, &first);
2733 printf_filtered ("\n");
2736 /* List all symbols (if REGEXP is NULL) or all symbols matching REGEXP.
2737 If CLASS is zero, list all symbols except functions, type names, and
2739 If CLASS is 1, list only functions.
2740 If CLASS is 2, list only type names.
2741 If CLASS is 3, list only method names.
2743 BPT is non-zero if we should set a breakpoint at the functions
2747 list_symbols (regexp, class, bpt, from_tty)
2753 register struct symtab *s;
2754 register struct partial_symtab *ps;
2755 register struct blockvector *bv;
2756 struct blockvector *prev_bv = 0;
2757 register struct block *b;
2759 register struct symbol *sym;
2760 struct partial_symbol **psym;
2761 struct objfile *objfile;
2762 struct minimal_symbol *msymbol;
2764 static char *classnames[]
2765 = {"variable", "function", "type", "method"};
2766 int found_in_file = 0;
2768 static enum minimal_symbol_type types[]
2769 = {mst_data, mst_text, mst_abs, mst_unknown};
2770 static enum minimal_symbol_type types2[]
2771 = {mst_bss, mst_file_text, mst_abs, mst_unknown};
2772 static enum minimal_symbol_type types3[]
2773 = {mst_file_data, mst_solib_trampoline, mst_abs, mst_unknown};
2774 static enum minimal_symbol_type types4[]
2775 = {mst_file_bss, mst_text, mst_abs, mst_unknown};
2776 enum minimal_symbol_type ourtype = types[class];
2777 enum minimal_symbol_type ourtype2 = types2[class];
2778 enum minimal_symbol_type ourtype3 = types3[class];
2779 enum minimal_symbol_type ourtype4 = types4[class];
2783 /* Make sure spacing is right for C++ operators.
2784 This is just a courtesy to make the matching less sensitive
2785 to how many spaces the user leaves between 'operator'
2786 and <TYPENAME> or <OPERATOR>. */
2788 char *opname = operator_chars (regexp, &opend);
2791 int fix = -1; /* -1 means ok; otherwise number of spaces needed. */
2792 if (isalpha(*opname) || *opname == '_' || *opname == '$')
2794 /* There should 1 space between 'operator' and 'TYPENAME'. */
2795 if (opname[-1] != ' ' || opname[-2] == ' ')
2800 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2801 if (opname[-1] == ' ')
2804 /* If wrong number of spaces, fix it. */
2807 char *tmp = (char*) alloca(opend-opname+10);
2808 sprintf(tmp, "operator%.*s%s", fix, " ", opname);
2813 if (0 != (val = re_comp (regexp)))
2814 error ("Invalid regexp (%s): %s", val, regexp);
2817 /* Search through the partial symtabs *first* for all symbols
2818 matching the regexp. That way we don't have to reproduce all of
2819 the machinery below. */
2821 ALL_PSYMTABS (objfile, ps)
2823 struct partial_symbol **bound, **gbound, **sbound;
2826 if (ps->readin) continue;
2828 gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms;
2829 sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms;
2832 /* Go through all of the symbols stored in a partial
2833 symtab in one loop. */
2834 psym = objfile->global_psymbols.list + ps->globals_offset;
2839 if (bound == gbound && ps->n_static_syms != 0)
2841 psym = objfile->static_psymbols.list + ps->statics_offset;
2852 /* If it would match (logic taken from loop below)
2853 load the file and go on to the next one */
2854 if ((regexp == NULL || SYMBOL_MATCHES_REGEXP (*psym))
2855 && ((class == 0 && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
2856 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
2857 || (class == 1 && SYMBOL_CLASS (*psym) == LOC_BLOCK)
2858 || (class == 2 && SYMBOL_CLASS (*psym) == LOC_TYPEDEF)
2859 || (class == 3 && SYMBOL_CLASS (*psym) == LOC_BLOCK)))
2861 PSYMTAB_TO_SYMTAB(ps);
2869 /* Here, we search through the minimal symbol tables for functions
2870 and variables that match, and force their symbols to be read.
2871 This is in particular necessary for demangled variable names,
2872 which are no longer put into the partial symbol tables.
2873 The symbol will then be found during the scan of symtabs below.
2875 For functions, find_pc_symtab should succeed if we have debug info
2876 for the function, for variables we have to call lookup_symbol
2877 to determine if the variable has debug info.
2878 If the lookup fails, set found_misc so that we will rescan to print
2879 any matching symbols without debug info.
2882 if (class == 0 || class == 1)
2884 ALL_MSYMBOLS (objfile, msymbol)
2886 if (MSYMBOL_TYPE (msymbol) == ourtype ||
2887 MSYMBOL_TYPE (msymbol) == ourtype2 ||
2888 MSYMBOL_TYPE (msymbol) == ourtype3 ||
2889 MSYMBOL_TYPE (msymbol) == ourtype4)
2891 if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol))
2893 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)))
2896 || lookup_symbol (SYMBOL_NAME (msymbol),
2897 (struct block *) NULL,
2899 0, (struct symtab **) NULL) == NULL)
2907 /* Printout here so as to get after the "Reading in symbols"
2908 messages which will be generated above. */
2910 printf_filtered (regexp
2911 ? "All %ss matching regular expression \"%s\":\n"
2912 : "All defined %ss:\n",
2916 ALL_SYMTABS (objfile, s)
2919 bv = BLOCKVECTOR (s);
2920 /* Often many files share a blockvector.
2921 Scan each blockvector only once so that
2922 we don't get every symbol many times.
2923 It happens that the first symtab in the list
2924 for any given blockvector is the main file. */
2926 for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
2928 b = BLOCKVECTOR_BLOCK (bv, i);
2929 /* Skip the sort if this block is always sorted. */
2930 if (!BLOCK_SHOULD_SORT (b))
2931 sort_block_syms (b);
2932 for (j = 0; j < BLOCK_NSYMS (b); j++)
2935 sym = BLOCK_SYM (b, j);
2936 if ((regexp == NULL || SYMBOL_MATCHES_REGEXP (sym))
2937 && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
2938 && SYMBOL_CLASS (sym) != LOC_BLOCK
2939 && SYMBOL_CLASS (sym) != LOC_CONST)
2940 || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)
2941 || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2942 || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK)))
2946 /* Set a breakpoint here, if it's a function */
2949 /* There may be more than one function with the
2950 same name but in different files. In order to
2951 set breakpoints on all of them, we must give
2952 both the file name and the function name to
2954 Quoting the symbol name gets rid of problems
2955 with mangled symbol names that contain
2956 CPLUS_MARKER characters. */
2958 (char *) alloca (strlen (s->filename)
2959 + strlen (SYMBOL_NAME(sym))
2961 strcpy (string, s->filename);
2962 strcat (string, ":'");
2963 strcat (string, SYMBOL_NAME(sym));
2964 strcat (string, "'");
2965 break_command (string, from_tty);
2968 else if (!found_in_file)
2970 fputs_filtered ("\nFile ", gdb_stdout);
2971 fputs_filtered (s->filename, gdb_stdout);
2972 fputs_filtered (":\n", gdb_stdout);
2976 if (class != 2 && i == STATIC_BLOCK)
2977 printf_filtered ("static ");
2979 /* Typedef that is not a C++ class */
2981 && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
2982 c_typedef_print (SYMBOL_TYPE(sym), sym, gdb_stdout);
2983 /* variable, func, or typedef-that-is-c++-class */
2984 else if (class < 2 ||
2986 SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE))
2988 type_print (SYMBOL_TYPE (sym),
2989 (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2990 ? "" : SYMBOL_SOURCE_NAME (sym)),
2993 printf_filtered (";\n");
2998 /* Tiemann says: "info methods was never implemented." */
2999 char *demangled_name;
3000 c_type_print_base (TYPE_FN_FIELD_TYPE(t, i),
3002 c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i),
3004 if (TYPE_FN_FIELD_STUB (t, i))
3005 check_stub_method (TYPE_DOMAIN_TYPE (type), j, i);
3007 cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t, i),
3008 DMGL_ANSI | DMGL_PARAMS);
3009 if (demangled_name == NULL)
3010 fprintf_filtered (stream, "<badly mangled name %s>",
3011 TYPE_FN_FIELD_PHYSNAME (t, i));
3014 fputs_filtered (demangled_name, stream);
3015 free (demangled_name);
3025 /* If there are no eyes, avoid all contact. I mean, if there are
3026 no debug symbols, then print directly from the msymbol_vector. */
3028 if (found_misc || class != 1)
3031 ALL_MSYMBOLS (objfile, msymbol)
3033 if (MSYMBOL_TYPE (msymbol) == ourtype ||
3034 MSYMBOL_TYPE (msymbol) == ourtype2 ||
3035 MSYMBOL_TYPE (msymbol) == ourtype3 ||
3036 MSYMBOL_TYPE (msymbol) == ourtype4)
3038 if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol))
3040 /* Functions: Look up by address. */
3042 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol))))
3044 /* Variables/Absolutes: Look up by name */
3045 if (lookup_symbol (SYMBOL_NAME (msymbol),
3046 (struct block *) NULL, VAR_NAMESPACE,
3047 0, (struct symtab **) NULL) == NULL)
3051 break_command (SYMBOL_NAME (msymbol), from_tty);
3052 printf_filtered ("<function, no debug info> %s;\n",
3053 SYMBOL_SOURCE_NAME (msymbol));
3058 printf_filtered ("\nNon-debugging symbols:\n");
3061 printf_filtered (" %08lx %s\n",
3062 (unsigned long) SYMBOL_VALUE_ADDRESS (msymbol),
3063 SYMBOL_SOURCE_NAME (msymbol));
3073 variables_info (regexp, from_tty)
3077 list_symbols (regexp, 0, 0, from_tty);
3081 functions_info (regexp, from_tty)
3085 list_symbols (regexp, 1, 0, from_tty);
3089 types_info (regexp, from_tty)
3093 list_symbols (regexp, 2, 0, from_tty);
3097 /* Tiemann says: "info methods was never implemented." */
3099 methods_info (regexp)
3102 list_symbols (regexp, 3, 0, from_tty);
3106 /* Breakpoint all functions matching regular expression. */
3108 rbreak_command (regexp, from_tty)
3112 list_symbols (regexp, 1, 1, from_tty);
3116 /* Return Nonzero if block a is lexically nested within block b,
3117 or if a and b have the same pc range.
3118 Return zero otherwise. */
3121 struct block *a, *b;
3125 return BLOCK_START (a) >= BLOCK_START (b)
3126 && BLOCK_END (a) <= BLOCK_END (b);
3130 /* Helper routine for make_symbol_completion_list. */
3132 static int return_val_size;
3133 static int return_val_index;
3134 static char **return_val;
3136 #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
3138 if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \
3139 /* Put only the mangled name on the list. */ \
3140 /* Advantage: "b foo<TAB>" completes to "b foo(int, int)" */ \
3141 /* Disadvantage: "b foo__i<TAB>" doesn't complete. */ \
3142 completion_list_add_name \
3143 (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \
3145 completion_list_add_name \
3146 (SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \
3149 /* Test to see if the symbol specified by SYMNAME (which is already
3150 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3151 characters. If so, add it to the current completion list. */
3154 completion_list_add_name (symname, sym_text, sym_text_len, text, word)
3164 /* clip symbols that cannot match */
3166 if (strncmp (symname, sym_text, sym_text_len) != 0)
3171 /* Clip any symbol names that we've already considered. (This is a
3172 time optimization) */
3174 for (i = 0; i < return_val_index; ++i)
3176 if (STREQ (symname, return_val[i]))
3182 /* We have a match for a completion, so add SYMNAME to the current list
3183 of matches. Note that the name is moved to freshly malloc'd space. */
3187 if (word == sym_text)
3189 new = xmalloc (strlen (symname) + 5);
3190 strcpy (new, symname);
3192 else if (word > sym_text)
3194 /* Return some portion of symname. */
3195 new = xmalloc (strlen (symname) + 5);
3196 strcpy (new, symname + (word - sym_text));
3200 /* Return some of SYM_TEXT plus symname. */
3201 new = xmalloc (strlen (symname) + (sym_text - word) + 5);
3202 strncpy (new, word, sym_text - word);
3203 new[sym_text - word] = '\0';
3204 strcat (new, symname);
3207 /* Recheck for duplicates if we intend to add a modified symbol. */
3208 if (word != sym_text)
3210 for (i = 0; i < return_val_index; ++i)
3212 if (STREQ (new, return_val[i]))
3220 if (return_val_index + 3 > return_val_size)
3222 newsize = (return_val_size *= 2) * sizeof (char *);
3223 return_val = (char **) xrealloc ((char *) return_val, newsize);
3225 return_val[return_val_index++] = new;
3226 return_val[return_val_index] = NULL;
3230 /* Return a NULL terminated array of all symbols (regardless of class) which
3231 begin by matching TEXT. If the answer is no symbols, then the return value
3232 is an array which contains only a NULL pointer.
3234 Problem: All of the symbols have to be copied because readline frees them.
3235 I'm not going to worry about this; hopefully there won't be that many. */
3238 make_symbol_completion_list (text, word)
3242 register struct symbol *sym;
3243 register struct symtab *s;
3244 register struct partial_symtab *ps;
3245 register struct minimal_symbol *msymbol;
3246 register struct objfile *objfile;
3247 register struct block *b, *surrounding_static_block = 0;
3249 struct partial_symbol **psym;
3250 /* The symbol we are completing on. Points in same buffer as text. */
3252 /* Length of sym_text. */
3255 /* Now look for the symbol we are supposed to complete on.
3256 FIXME: This should be language-specific. */
3260 char *quote_pos = NULL;
3262 /* First see if this is a quoted string. */
3264 for (p = text; *p != '\0'; ++p)
3266 if (quote_found != '\0')
3268 if (*p == quote_found)
3269 /* Found close quote. */
3271 else if (*p == '\\' && p[1] == quote_found)
3272 /* A backslash followed by the quote character
3273 doesn't end the string. */
3276 else if (*p == '\'' || *p == '"')
3282 if (quote_found == '\'')
3283 /* A string within single quotes can be a symbol, so complete on it. */
3284 sym_text = quote_pos + 1;
3285 else if (quote_found == '"')
3286 /* A double-quoted string is never a symbol, nor does it make sense
3287 to complete it any other way. */
3291 /* It is not a quoted string. Break it based on the characters
3292 which are in symbols. */
3295 if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
3304 sym_text_len = strlen (sym_text);
3306 return_val_size = 100;
3307 return_val_index = 0;
3308 return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
3309 return_val[0] = NULL;
3311 /* Look through the partial symtabs for all symbols which begin
3312 by matching SYM_TEXT. Add each one that you find to the list. */
3314 ALL_PSYMTABS (objfile, ps)
3316 /* If the psymtab's been read in we'll get it when we search
3317 through the blockvector. */
3318 if (ps->readin) continue;
3320 for (psym = objfile->global_psymbols.list + ps->globals_offset;
3321 psym < (objfile->global_psymbols.list + ps->globals_offset
3322 + ps->n_global_syms);
3325 /* If interrupted, then quit. */
3327 COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word);
3330 for (psym = objfile->static_psymbols.list + ps->statics_offset;
3331 psym < (objfile->static_psymbols.list + ps->statics_offset
3332 + ps->n_static_syms);
3336 COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word);
3340 /* At this point scan through the misc symbol vectors and add each
3341 symbol you find to the list. Eventually we want to ignore
3342 anything that isn't a text symbol (everything else will be
3343 handled by the psymtab code above). */
3345 ALL_MSYMBOLS (objfile, msymbol)
3348 COMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text, word);
3351 /* Search upwards from currently selected frame (so that we can
3352 complete on local vars. */
3354 for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b))
3356 if (!BLOCK_SUPERBLOCK (b))
3358 surrounding_static_block = b; /* For elmin of dups */
3361 /* Also catch fields of types defined in this places which match our
3362 text string. Only complete on types visible from current context. */
3364 for (i = 0; i < BLOCK_NSYMS (b); i++)
3366 sym = BLOCK_SYM (b, i);
3367 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3368 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
3370 struct type *t = SYMBOL_TYPE (sym);
3371 enum type_code c = TYPE_CODE (t);
3373 if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
3375 for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
3377 if (TYPE_FIELD_NAME (t, j))
3379 completion_list_add_name (TYPE_FIELD_NAME (t, j),
3380 sym_text, sym_text_len, text, word);
3388 /* Go through the symtabs and check the externs and statics for
3389 symbols which match. */
3391 ALL_SYMTABS (objfile, s)
3394 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
3395 for (i = 0; i < BLOCK_NSYMS (b); i++)
3397 sym = BLOCK_SYM (b, i);
3398 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3402 ALL_SYMTABS (objfile, s)
3405 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
3406 /* Don't do this block twice. */
3407 if (b == surrounding_static_block) continue;
3408 for (i = 0; i < BLOCK_NSYMS (b); i++)
3410 sym = BLOCK_SYM (b, i);
3411 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3415 return (return_val);
3418 /* Determine if PC is in the prologue of a function. The prologue is the area
3419 between the first instruction of a function, and the first executable line.
3420 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
3422 If non-zero, func_start is where we think the prologue starts, possibly
3423 by previous examination of symbol table information.
3427 in_prologue (pc, func_start)
3429 CORE_ADDR func_start;
3431 struct symtab_and_line sal;
3432 CORE_ADDR func_addr, func_end;
3434 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
3435 goto nosyms; /* Might be in prologue */
3437 sal = find_pc_line (func_addr, 0);
3442 if (sal.end > func_addr
3443 && sal.end <= func_end) /* Is prologue in function? */
3444 return pc < sal.end; /* Yes, is pc in prologue? */
3446 /* The line after the prologue seems to be outside the function. In this
3447 case, tell the caller to find the prologue the hard way. */
3451 /* Come here when symtabs don't contain line # info. In this case, it is
3452 likely that the user has stepped into a library function w/o symbols, or
3453 is doing a stepi/nexti through code without symbols. */
3457 /* If func_start is zero (meaning unknown) then we don't know whether pc is
3458 in the prologue or not. I.E. it might be. */
3460 if (!func_start) return 1;
3462 /* We need to call the target-specific prologue skipping functions with the
3463 function's start address because PC may be pointing at an instruction that
3464 could be mistakenly considered part of the prologue. */
3466 SKIP_PROLOGUE (func_start);
3468 return pc < func_start;
3473 _initialize_symtab ()
3475 add_info ("variables", variables_info,
3476 "All global and static variable names, or those matching REGEXP.");
3477 add_info ("functions", functions_info,
3478 "All function names, or those matching REGEXP.");
3480 /* FIXME: This command has at least the following problems:
3481 1. It prints builtin types (in a very strange and confusing fashion).
3482 2. It doesn't print right, e.g. with
3483 typedef struct foo *FOO
3484 type_print prints "FOO" when we want to make it (in this situation)
3485 print "struct foo *".
3486 I also think "ptype" or "whatis" is more likely to be useful (but if
3487 there is much disagreement "info types" can be fixed). */
3488 add_info ("types", types_info,
3489 "All type names, or those matching REGEXP.");
3492 add_info ("methods", methods_info,
3493 "All method names, or those matching REGEXP::REGEXP.\n\
3494 If the class qualifier is omitted, it is assumed to be the current scope.\n\
3495 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
3498 add_info ("sources", sources_info,
3499 "Source files in the program.");
3501 add_com ("rbreak", no_class, rbreak_command,
3502 "Set a breakpoint for all functions matching REGEXP.");
3504 /* Initialize the one built-in type that isn't language dependent... */
3505 builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0,
3506 "<unknown type>", (struct objfile *) NULL);