1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
33 #include "call-cmds.h"
34 #include "gdb_regex.h"
35 #include "expression.h"
40 #include "filenames.h" /* for FILENAME_CMP */
44 #include <sys/types.h>
46 #include "gdb_string.h"
51 /* Prototype for one function in parser-defs.h,
52 instead of including that entire file. */
54 extern char *find_template_name_end (char *);
56 /* Prototypes for local functions */
58 static void completion_list_add_name (char *, char *, int, char *, char *);
60 static void rbreak_command (char *, int);
62 static void types_info (char *, int);
64 static void functions_info (char *, int);
66 static void variables_info (char *, int);
68 static void sources_info (char *, int);
70 static void output_source_filename (char *, int *);
72 static int find_line_common (struct linetable *, int, int *);
74 /* This one is used by linespec.c */
76 char *operator_chars (char *p, char **end);
78 static struct partial_symbol *lookup_partial_symbol (struct partial_symtab *,
82 static struct symbol *lookup_symbol_aux (const char *name, const
83 struct block *block, const
84 namespace_enum namespace, int
85 *is_a_field_of_this, struct
89 static struct symbol *find_active_alias (struct symbol *sym, CORE_ADDR addr);
91 /* This flag is used in hppa-tdep.c, and set in hp-symtab-read.c */
92 /* Signals the presence of objects compiled by HP compilers */
93 int hp_som_som_object_present = 0;
95 static void fixup_section (struct general_symbol_info *, struct objfile *);
97 static int file_matches (char *, char **, int);
99 static void print_symbol_info (namespace_enum,
100 struct symtab *, struct symbol *, int, char *);
102 static void print_msymbol_info (struct minimal_symbol *);
104 static void symtab_symbol_info (char *, namespace_enum, int);
106 static void overload_list_add_symbol (struct symbol *sym, char *oload_name);
108 void _initialize_symtab (void);
112 /* The single non-language-specific builtin type */
113 struct type *builtin_type_error;
115 /* Block in which the most recently searched-for symbol was found.
116 Might be better to make this a parameter to lookup_symbol and
119 const struct block *block_found;
121 /* While the C++ support is still in flux, issue a possibly helpful hint on
122 using the new command completion feature on single quoted demangled C++
123 symbols. Remove when loose ends are cleaned up. FIXME -fnf */
126 cplusplus_hint (char *name)
128 while (*name == '\'')
130 printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name, name);
131 printf_filtered ("(Note leading single quote.)\n");
134 /* Check for a symtab of a specific name; first in symtabs, then in
135 psymtabs. *If* there is no '/' in the name, a match after a '/'
136 in the symtab filename will also work. */
139 lookup_symtab (const char *name)
141 register struct symtab *s;
142 register struct partial_symtab *ps;
143 register struct objfile *objfile;
147 /* First, search for an exact match */
149 ALL_SYMTABS (objfile, s)
150 if (FILENAME_CMP (name, s->filename) == 0)
153 /* Now, search for a matching tail (only if name doesn't have any dirs) */
155 if (lbasename (name) == name)
156 ALL_SYMTABS (objfile, s)
158 if (FILENAME_CMP (lbasename (s->filename), name) == 0)
162 /* Same search rules as above apply here, but now we look thru the
165 ps = lookup_partial_symtab (name);
170 error ("Internal: readin %s pst for `%s' found when no symtab found.",
173 s = PSYMTAB_TO_SYMTAB (ps);
178 /* At this point, we have located the psymtab for this file, but
179 the conversion to a symtab has failed. This usually happens
180 when we are looking up an include file. In this case,
181 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
182 been created. So, we need to run through the symtabs again in
183 order to find the file.
184 XXX - This is a crock, and should be fixed inside of the the
185 symbol parsing routines. */
189 /* Lookup the partial symbol table of a source file named NAME.
190 *If* there is no '/' in the name, a match after a '/'
191 in the psymtab filename will also work. */
193 struct partial_symtab *
194 lookup_partial_symtab (const char *name)
196 register struct partial_symtab *pst;
197 register struct objfile *objfile;
199 ALL_PSYMTABS (objfile, pst)
201 if (FILENAME_CMP (name, pst->filename) == 0)
207 /* Now, search for a matching tail (only if name doesn't have any dirs) */
209 if (lbasename (name) == name)
210 ALL_PSYMTABS (objfile, pst)
212 if (FILENAME_CMP (lbasename (pst->filename), name) == 0)
219 /* Mangle a GDB method stub type. This actually reassembles the pieces of the
220 full method name, which consist of the class name (from T), the unadorned
221 method name from METHOD_ID, and the signature for the specific overload,
222 specified by SIGNATURE_ID. Note that this function is g++ specific. */
225 gdb_mangle_name (struct type *type, int method_id, int signature_id)
227 int mangled_name_len;
229 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
230 struct fn_field *method = &f[signature_id];
231 char *field_name = TYPE_FN_FIELDLIST_NAME (type, method_id);
232 char *physname = TYPE_FN_FIELD_PHYSNAME (f, signature_id);
233 char *newname = type_name_no_tag (type);
235 /* Does the form of physname indicate that it is the full mangled name
236 of a constructor (not just the args)? */
237 int is_full_physname_constructor;
240 int is_destructor = is_destructor_name (physname);
241 /* Need a new type prefix. */
242 char *const_prefix = method->is_const ? "C" : "";
243 char *volatile_prefix = method->is_volatile ? "V" : "";
245 int len = (newname == NULL ? 0 : strlen (newname));
247 if (is_operator_name (field_name))
248 return xstrdup (physname);
250 is_full_physname_constructor = is_constructor_name (physname);
253 is_full_physname_constructor || (newname && STREQ (field_name, newname));
256 is_destructor = (strncmp (physname, "__dt", 4) == 0);
258 if (is_destructor || is_full_physname_constructor)
260 mangled_name = (char *) xmalloc (strlen (physname) + 1);
261 strcpy (mangled_name, physname);
267 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
269 else if (physname[0] == 't' || physname[0] == 'Q')
271 /* The physname for template and qualified methods already includes
273 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
279 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
281 mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
282 + strlen (buf) + len + strlen (physname) + 1);
285 mangled_name = (char *) xmalloc (mangled_name_len);
287 mangled_name[0] = '\0';
289 strcpy (mangled_name, field_name);
291 strcat (mangled_name, buf);
292 /* If the class doesn't have a name, i.e. newname NULL, then we just
293 mangle it using 0 for the length of the class. Thus it gets mangled
294 as something starting with `::' rather than `classname::'. */
296 strcat (mangled_name, newname);
298 strcat (mangled_name, physname);
299 return (mangled_name);
304 /* Find which partial symtab on contains PC and SECTION. Return 0 if none. */
306 struct partial_symtab *
307 find_pc_sect_psymtab (CORE_ADDR pc, asection *section)
309 register struct partial_symtab *pst;
310 register struct objfile *objfile;
312 ALL_PSYMTABS (objfile, pst)
314 if (pc >= pst->textlow && pc < pst->texthigh)
316 struct minimal_symbol *msymbol;
317 struct partial_symtab *tpst;
319 /* An objfile that has its functions reordered might have
320 many partial symbol tables containing the PC, but
321 we want the partial symbol table that contains the
322 function containing the PC. */
323 if (!(objfile->flags & OBJF_REORDERED) &&
324 section == 0) /* can't validate section this way */
327 msymbol = lookup_minimal_symbol_by_pc_section (pc, section);
331 for (tpst = pst; tpst != NULL; tpst = tpst->next)
333 if (pc >= tpst->textlow && pc < tpst->texthigh)
335 struct partial_symbol *p;
337 p = find_pc_sect_psymbol (tpst, pc, section);
339 && SYMBOL_VALUE_ADDRESS (p)
340 == SYMBOL_VALUE_ADDRESS (msymbol))
350 /* Find which partial symtab contains PC. Return 0 if none.
351 Backward compatibility, no section */
353 struct partial_symtab *
354 find_pc_psymtab (CORE_ADDR pc)
356 return find_pc_sect_psymtab (pc, find_pc_mapped_section (pc));
359 /* Find which partial symbol within a psymtab matches PC and SECTION.
360 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
362 struct partial_symbol *
363 find_pc_sect_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc,
366 struct partial_symbol *best = NULL, *p, **pp;
370 psymtab = find_pc_sect_psymtab (pc, section);
374 /* Cope with programs that start at address 0 */
375 best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
377 /* Search the global symbols as well as the static symbols, so that
378 find_pc_partial_function doesn't use a minimal symbol and thus
379 cache a bad endaddr. */
380 for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
381 (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
382 < psymtab->n_global_syms);
386 if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
387 && SYMBOL_CLASS (p) == LOC_BLOCK
388 && pc >= SYMBOL_VALUE_ADDRESS (p)
389 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
390 || (psymtab->textlow == 0
391 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
393 if (section) /* match on a specific section */
395 fixup_psymbol_section (p, psymtab->objfile);
396 if (SYMBOL_BFD_SECTION (p) != section)
399 best_pc = SYMBOL_VALUE_ADDRESS (p);
404 for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
405 (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
406 < psymtab->n_static_syms);
410 if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
411 && SYMBOL_CLASS (p) == LOC_BLOCK
412 && pc >= SYMBOL_VALUE_ADDRESS (p)
413 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
414 || (psymtab->textlow == 0
415 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
417 if (section) /* match on a specific section */
419 fixup_psymbol_section (p, psymtab->objfile);
420 if (SYMBOL_BFD_SECTION (p) != section)
423 best_pc = SYMBOL_VALUE_ADDRESS (p);
431 /* Find which partial symbol within a psymtab matches PC. Return 0 if none.
432 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
434 struct partial_symbol *
435 find_pc_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc)
437 return find_pc_sect_psymbol (psymtab, pc, find_pc_mapped_section (pc));
440 /* Debug symbols usually don't have section information. We need to dig that
441 out of the minimal symbols and stash that in the debug symbol. */
444 fixup_section (struct general_symbol_info *ginfo, struct objfile *objfile)
446 struct minimal_symbol *msym;
447 msym = lookup_minimal_symbol (ginfo->name, NULL, objfile);
451 ginfo->bfd_section = SYMBOL_BFD_SECTION (msym);
452 ginfo->section = SYMBOL_SECTION (msym);
457 fixup_symbol_section (struct symbol *sym, struct objfile *objfile)
462 if (SYMBOL_BFD_SECTION (sym))
465 fixup_section (&sym->ginfo, objfile);
470 struct partial_symbol *
471 fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
476 if (SYMBOL_BFD_SECTION (psym))
479 fixup_section (&psym->ginfo, objfile);
484 /* Find the definition for a specified symbol name NAME
485 in namespace NAMESPACE, visible from lexical block BLOCK.
486 Returns the struct symbol pointer, or zero if no symbol is found.
487 If SYMTAB is non-NULL, store the symbol table in which the
488 symbol was found there, or NULL if not found.
489 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
490 NAME is a field of the current implied argument `this'. If so set
491 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
492 BLOCK_FOUND is set to the block in which NAME is found (in the case of
493 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
495 /* This function has a bunch of loops in it and it would seem to be
496 attractive to put in some QUIT's (though I'm not really sure
497 whether it can run long enough to be really important). But there
498 are a few calls for which it would appear to be bad news to quit
499 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and
500 nindy_frame_chain_valid in nindy-tdep.c. (Note that there is C++
501 code below which can error(), but that probably doesn't affect
502 these calls since they are looking for a known variable and thus
503 can probably assume it will never hit the C++ code). */
506 lookup_symbol (const char *name, const struct block *block,
507 const namespace_enum namespace, int *is_a_field_of_this,
508 struct symtab **symtab)
510 char *modified_name = NULL;
511 char *modified_name2 = NULL;
512 int needtofreename = 0;
513 struct symbol *returnval;
515 if (case_sensitivity == case_sensitive_off)
521 copy = (char *) alloca (len + 1);
522 for (i= 0; i < len; i++)
523 copy[i] = tolower (name[i]);
525 modified_name = copy;
528 modified_name = (char *) name;
530 /* If we are using C++ language, demangle the name before doing a lookup, so
531 we can always binary search. */
532 if (current_language->la_language == language_cplus)
534 modified_name2 = cplus_demangle (modified_name, DMGL_ANSI | DMGL_PARAMS);
537 modified_name = modified_name2;
542 returnval = lookup_symbol_aux (modified_name, block, namespace,
543 is_a_field_of_this, symtab);
545 xfree (modified_name2);
550 static struct symbol *
551 lookup_symbol_aux (const char *name, const struct block *block,
552 const namespace_enum namespace, int *is_a_field_of_this,
553 struct symtab **symtab)
555 register struct symbol *sym;
556 register struct symtab *s = NULL;
557 register struct partial_symtab *ps;
558 register struct blockvector *bv;
559 register struct objfile *objfile = NULL;
560 register struct block *b;
561 register struct minimal_symbol *msymbol;
564 /* Search specified block and its superiors. */
568 sym = lookup_block_symbol (block, name, namespace);
574 /* Search the list of symtabs for one which contains the
575 address of the start of this block. */
576 ALL_SYMTABS (objfile, s)
578 bv = BLOCKVECTOR (s);
579 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
580 if (BLOCK_START (b) <= BLOCK_START (block)
581 && BLOCK_END (b) > BLOCK_START (block))
588 return fixup_symbol_section (sym, objfile);
590 block = BLOCK_SUPERBLOCK (block);
593 /* FIXME: this code is never executed--block is always NULL at this
594 point. What is it trying to do, anyway? We already should have
595 checked the STATIC_BLOCK above (it is the superblock of top-level
596 blocks). Why is VAR_NAMESPACE special-cased? */
597 /* Don't need to mess with the psymtabs; if we have a block,
598 that file is read in. If we don't, then we deal later with
599 all the psymtab stuff that needs checking. */
600 /* Note (RT): The following never-executed code looks unnecessary to me also.
601 * If we change the code to use the original (passed-in)
602 * value of 'block', we could cause it to execute, but then what
603 * would it do? The STATIC_BLOCK of the symtab containing the passed-in
604 * 'block' was already searched by the above code. And the STATIC_BLOCK's
605 * of *other* symtabs (those files not containing 'block' lexically)
606 * should not contain 'block' address-wise. So we wouldn't expect this
607 * code to find any 'sym''s that were not found above. I vote for
608 * deleting the following paragraph of code.
610 if (namespace == VAR_NAMESPACE && block != NULL)
613 /* Find the right symtab. */
614 ALL_SYMTABS (objfile, s)
616 bv = BLOCKVECTOR (s);
617 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
618 if (BLOCK_START (b) <= BLOCK_START (block)
619 && BLOCK_END (b) > BLOCK_START (block))
621 sym = lookup_block_symbol (b, name, VAR_NAMESPACE);
627 return fixup_symbol_section (sym, objfile);
634 /* C++: If requested to do so by the caller,
635 check to see if NAME is a field of `this'. */
636 if (is_a_field_of_this)
638 struct value *v = value_of_this (0);
640 *is_a_field_of_this = 0;
641 if (v && check_field (v, name))
643 *is_a_field_of_this = 1;
650 /* Now search all global blocks. Do the symtab's first, then
651 check the psymtab's. If a psymtab indicates the existence
652 of the desired name as a global, then do psymtab-to-symtab
653 conversion on the fly and return the found symbol. */
655 ALL_SYMTABS (objfile, s)
657 bv = BLOCKVECTOR (s);
658 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
659 sym = lookup_block_symbol (block, name, namespace);
665 return fixup_symbol_section (sym, objfile);
671 /* Check for the possibility of the symbol being a function or
672 a mangled variable that is stored in one of the minimal symbol tables.
673 Eventually, all global symbols might be resolved in this way. */
675 if (namespace == VAR_NAMESPACE)
677 msymbol = lookup_minimal_symbol (name, NULL, NULL);
680 s = find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol),
681 SYMBOL_BFD_SECTION (msymbol));
684 /* This is a function which has a symtab for its address. */
685 bv = BLOCKVECTOR (s);
686 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
687 sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
689 /* We kept static functions in minimal symbol table as well as
690 in static scope. We want to find them in the symbol table. */
693 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
694 sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
698 /* sym == 0 if symbol was found in the minimal symbol table
699 but not in the symtab.
700 Return 0 to use the msymbol definition of "foo_".
702 This happens for Fortran "foo_" symbols,
703 which are "foo" in the symtab.
705 This can also happen if "asm" is used to make a
706 regular symbol but not a debugging symbol, e.g.
713 return fixup_symbol_section (sym, objfile);
715 else if (MSYMBOL_TYPE (msymbol) != mst_text
716 && MSYMBOL_TYPE (msymbol) != mst_file_text
717 && !STREQ (name, SYMBOL_NAME (msymbol)))
719 /* This is a mangled variable, look it up by its
721 return lookup_symbol_aux (SYMBOL_NAME (msymbol), block,
722 namespace, is_a_field_of_this, symtab);
724 /* There are no debug symbols for this file, or we are looking
725 for an unmangled variable.
726 Try to find a matching static symbol below. */
732 ALL_PSYMTABS (objfile, ps)
734 if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
736 s = PSYMTAB_TO_SYMTAB (ps);
737 bv = BLOCKVECTOR (s);
738 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
739 sym = lookup_block_symbol (block, name, namespace);
742 /* This shouldn't be necessary, but as a last resort
743 * try looking in the statics even though the psymtab
744 * claimed the symbol was global. It's possible that
745 * the psymtab gets it wrong in some cases.
747 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
748 sym = lookup_block_symbol (block, name, namespace);
750 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
751 %s may be an inlined function, or may be a template function\n\
752 (if a template, try specifying an instantiation: %s<type>).",
753 name, ps->filename, name, name);
757 return fixup_symbol_section (sym, objfile);
761 /* Now search all static file-level symbols.
762 Not strictly correct, but more useful than an error.
763 Do the symtabs first, then check the psymtabs.
764 If a psymtab indicates the existence
765 of the desired name as a file-level static, then do psymtab-to-symtab
766 conversion on the fly and return the found symbol. */
768 ALL_SYMTABS (objfile, s)
770 bv = BLOCKVECTOR (s);
771 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
772 sym = lookup_block_symbol (block, name, namespace);
778 return fixup_symbol_section (sym, objfile);
782 ALL_PSYMTABS (objfile, ps)
784 if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
786 s = PSYMTAB_TO_SYMTAB (ps);
787 bv = BLOCKVECTOR (s);
788 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
789 sym = lookup_block_symbol (block, name, namespace);
792 /* This shouldn't be necessary, but as a last resort
793 * try looking in the globals even though the psymtab
794 * claimed the symbol was static. It's possible that
795 * the psymtab gets it wrong in some cases.
797 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
798 sym = lookup_block_symbol (block, name, namespace);
800 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
801 %s may be an inlined function, or may be a template function\n\
802 (if a template, try specifying an instantiation: %s<type>).",
803 name, ps->filename, name, name);
807 return fixup_symbol_section (sym, objfile);
813 /* Check for the possibility of the symbol being a function or
814 a global variable that is stored in one of the minimal symbol tables.
815 The "minimal symbol table" is built from linker-supplied info.
817 RT: I moved this check to last, after the complete search of
818 the global (p)symtab's and static (p)symtab's. For HP-generated
819 symbol tables, this check was causing a premature exit from
820 lookup_symbol with NULL return, and thus messing up symbol lookups
821 of things like "c::f". It seems to me a check of the minimal
822 symbol table ought to be a last resort in any case. I'm vaguely
823 worried about the comment below which talks about FORTRAN routines "foo_"
824 though... is it saying we need to do the "minsym" check before
825 the static check in this case?
828 if (namespace == VAR_NAMESPACE)
830 msymbol = lookup_minimal_symbol (name, NULL, NULL);
833 /* OK, we found a minimal symbol in spite of not
834 * finding any symbol. There are various possible
835 * explanations for this. One possibility is the symbol
836 * exists in code not compiled -g. Another possibility
837 * is that the 'psymtab' isn't doing its job.
838 * A third possibility, related to #2, is that we were confused
839 * by name-mangling. For instance, maybe the psymtab isn't
840 * doing its job because it only know about demangled
841 * names, but we were given a mangled name...
844 /* We first use the address in the msymbol to try to
845 * locate the appropriate symtab. Note that find_pc_symtab()
846 * has a side-effect of doing psymtab-to-symtab expansion,
847 * for the found symtab.
849 s = find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol));
852 bv = BLOCKVECTOR (s);
853 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
854 sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
856 /* We kept static functions in minimal symbol table as well as
857 in static scope. We want to find them in the symbol table. */
860 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
861 sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
864 /* If we found one, return it */
872 /* If we get here with sym == 0, the symbol was
873 found in the minimal symbol table
874 but not in the symtab.
875 Fall through and return 0 to use the msymbol
876 definition of "foo_".
877 (Note that outer code generally follows up a call
878 to this routine with a call to lookup_minimal_symbol(),
879 so a 0 return means we'll just flow into that other routine).
881 This happens for Fortran "foo_" symbols,
882 which are "foo" in the symtab.
884 This can also happen if "asm" is used to make a
885 regular symbol but not a debugging symbol, e.g.
891 /* If the lookup-by-address fails, try repeating the
892 * entire lookup process with the symbol name from
893 * the msymbol (if different from the original symbol name).
895 else if (MSYMBOL_TYPE (msymbol) != mst_text
896 && MSYMBOL_TYPE (msymbol) != mst_file_text
897 && !STREQ (name, SYMBOL_NAME (msymbol)))
899 return lookup_symbol_aux (SYMBOL_NAME (msymbol), block,
900 namespace, is_a_field_of_this, symtab);
912 /* Look, in partial_symtab PST, for symbol NAME. Check the global
913 symbols if GLOBAL, the static symbols if not */
915 static struct partial_symbol *
916 lookup_partial_symbol (struct partial_symtab *pst, const char *name, int global,
917 namespace_enum namespace)
919 struct partial_symbol *temp;
920 struct partial_symbol **start, **psym;
921 struct partial_symbol **top, **bottom, **center;
922 int length = (global ? pst->n_global_syms : pst->n_static_syms);
923 int do_linear_search = 1;
930 pst->objfile->global_psymbols.list + pst->globals_offset :
931 pst->objfile->static_psymbols.list + pst->statics_offset);
933 if (global) /* This means we can use a binary search. */
935 do_linear_search = 0;
937 /* Binary search. This search is guaranteed to end with center
938 pointing at the earliest partial symbol with the correct
939 name. At that point *all* partial symbols with that name
940 will be checked against the correct namespace. */
943 top = start + length - 1;
946 center = bottom + (top - bottom) / 2;
948 internal_error (__FILE__, __LINE__, "failed internal consistency check");
949 if (!do_linear_search
950 && (SYMBOL_LANGUAGE (*center) == language_java))
952 do_linear_search = 1;
954 if (strcmp (SYMBOL_SOURCE_NAME (*center), name) >= 0)
963 if (!(top == bottom))
964 internal_error (__FILE__, __LINE__, "failed internal consistency check");
966 /* djb - 2000-06-03 - Use SYMBOL_MATCHES_NAME, not a strcmp, so
967 we don't have to force a linear search on C++. Probably holds true
968 for JAVA as well, no way to check.*/
969 while (SYMBOL_MATCHES_NAME (*top,name))
971 if (SYMBOL_NAMESPACE (*top) == namespace)
979 /* Can't use a binary search or else we found during the binary search that
980 we should also do a linear search. */
982 if (do_linear_search)
984 for (psym = start; psym < start + length; psym++)
986 if (namespace == SYMBOL_NAMESPACE (*psym))
988 if (SYMBOL_MATCHES_NAME (*psym, name))
999 /* Look up a type named NAME in the struct_namespace. The type returned
1000 must not be opaque -- i.e., must have at least one field defined
1002 This code was modelled on lookup_symbol -- the parts not relevant to looking
1003 up types were just left out. In particular it's assumed here that types
1004 are available in struct_namespace and only at file-static or global blocks. */
1008 lookup_transparent_type (const char *name)
1010 register struct symbol *sym;
1011 register struct symtab *s = NULL;
1012 register struct partial_symtab *ps;
1013 struct blockvector *bv;
1014 register struct objfile *objfile;
1015 register struct block *block;
1017 /* Now search all the global symbols. Do the symtab's first, then
1018 check the psymtab's. If a psymtab indicates the existence
1019 of the desired name as a global, then do psymtab-to-symtab
1020 conversion on the fly and return the found symbol. */
1022 ALL_SYMTABS (objfile, s)
1024 bv = BLOCKVECTOR (s);
1025 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1026 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1027 if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1029 return SYMBOL_TYPE (sym);
1033 ALL_PSYMTABS (objfile, ps)
1035 if (!ps->readin && lookup_partial_symbol (ps, name, 1, STRUCT_NAMESPACE))
1037 s = PSYMTAB_TO_SYMTAB (ps);
1038 bv = BLOCKVECTOR (s);
1039 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1040 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1043 /* This shouldn't be necessary, but as a last resort
1044 * try looking in the statics even though the psymtab
1045 * claimed the symbol was global. It's possible that
1046 * the psymtab gets it wrong in some cases.
1048 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1049 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1051 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
1052 %s may be an inlined function, or may be a template function\n\
1053 (if a template, try specifying an instantiation: %s<type>).",
1054 name, ps->filename, name, name);
1056 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1057 return SYMBOL_TYPE (sym);
1061 /* Now search the static file-level symbols.
1062 Not strictly correct, but more useful than an error.
1063 Do the symtab's first, then
1064 check the psymtab's. If a psymtab indicates the existence
1065 of the desired name as a file-level static, then do psymtab-to-symtab
1066 conversion on the fly and return the found symbol.
1069 ALL_SYMTABS (objfile, s)
1071 bv = BLOCKVECTOR (s);
1072 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1073 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1074 if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1076 return SYMBOL_TYPE (sym);
1080 ALL_PSYMTABS (objfile, ps)
1082 if (!ps->readin && lookup_partial_symbol (ps, name, 0, STRUCT_NAMESPACE))
1084 s = PSYMTAB_TO_SYMTAB (ps);
1085 bv = BLOCKVECTOR (s);
1086 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1087 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1090 /* This shouldn't be necessary, but as a last resort
1091 * try looking in the globals even though the psymtab
1092 * claimed the symbol was static. It's possible that
1093 * the psymtab gets it wrong in some cases.
1095 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1096 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1098 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
1099 %s may be an inlined function, or may be a template function\n\
1100 (if a template, try specifying an instantiation: %s<type>).",
1101 name, ps->filename, name, name);
1103 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1104 return SYMBOL_TYPE (sym);
1107 return (struct type *) 0;
1111 /* Find the psymtab containing main(). */
1112 /* FIXME: What about languages without main() or specially linked
1113 executables that have no main() ? */
1115 struct partial_symtab *
1116 find_main_psymtab (void)
1118 register struct partial_symtab *pst;
1119 register struct objfile *objfile;
1121 ALL_PSYMTABS (objfile, pst)
1123 if (lookup_partial_symbol (pst, main_name (), 1, VAR_NAMESPACE))
1131 /* Search BLOCK for symbol NAME in NAMESPACE.
1133 Note that if NAME is the demangled form of a C++ symbol, we will fail
1134 to find a match during the binary search of the non-encoded names, but
1135 for now we don't worry about the slight inefficiency of looking for
1136 a match we'll never find, since it will go pretty quick. Once the
1137 binary search terminates, we drop through and do a straight linear
1138 search on the symbols. Each symbol which is marked as being a C++
1139 symbol (language_cplus set) has both the encoded and non-encoded names
1140 tested for a match. */
1143 lookup_block_symbol (register const struct block *block, const char *name,
1144 const namespace_enum namespace)
1146 register int bot, top, inc;
1147 register struct symbol *sym;
1148 register struct symbol *sym_found = NULL;
1149 register int do_linear_search = 1;
1151 /* If the blocks's symbols were sorted, start with a binary search. */
1153 if (BLOCK_SHOULD_SORT (block))
1155 /* Reset the linear search flag so if the binary search fails, we
1156 won't do the linear search once unless we find some reason to
1159 do_linear_search = 0;
1160 top = BLOCK_NSYMS (block);
1163 /* Advance BOT to not far before the first symbol whose name is NAME. */
1167 inc = (top - bot + 1);
1168 /* No need to keep binary searching for the last few bits worth. */
1173 inc = (inc >> 1) + bot;
1174 sym = BLOCK_SYM (block, inc);
1175 if (!do_linear_search && (SYMBOL_LANGUAGE (sym) == language_java))
1177 do_linear_search = 1;
1179 if (SYMBOL_SOURCE_NAME (sym)[0] < name[0])
1183 else if (SYMBOL_SOURCE_NAME (sym)[0] > name[0])
1187 else if (strcmp (SYMBOL_SOURCE_NAME (sym), name) < 0)
1197 /* Now scan forward until we run out of symbols, find one whose
1198 name is greater than NAME, or find one we want. If there is
1199 more than one symbol with the right name and namespace, we
1200 return the first one; I believe it is now impossible for us
1201 to encounter two symbols with the same name and namespace
1202 here, because blocks containing argument symbols are no
1205 top = BLOCK_NSYMS (block);
1208 sym = BLOCK_SYM (block, bot);
1209 if (SYMBOL_NAMESPACE (sym) == namespace &&
1210 SYMBOL_MATCHES_NAME (sym, name))
1214 if (SYMBOL_SOURCE_NAME (sym)[0] > name[0])
1222 /* Here if block isn't sorted, or we fail to find a match during the
1223 binary search above. If during the binary search above, we find a
1224 symbol which is a Java symbol, then we have re-enabled the linear
1225 search flag which was reset when starting the binary search.
1227 This loop is equivalent to the loop above, but hacked greatly for speed.
1229 Note that parameter symbols do not always show up last in the
1230 list; this loop makes sure to take anything else other than
1231 parameter symbols first; it only uses parameter symbols as a
1232 last resort. Note that this only takes up extra computation
1235 if (do_linear_search)
1237 top = BLOCK_NSYMS (block);
1241 sym = BLOCK_SYM (block, bot);
1242 if (SYMBOL_NAMESPACE (sym) == namespace &&
1243 SYMBOL_MATCHES_NAME (sym, name))
1245 /* If SYM has aliases, then use any alias that is active
1246 at the current PC. If no alias is active at the current
1247 PC, then use the main symbol.
1249 ?!? Is checking the current pc correct? Is this routine
1250 ever called to look up a symbol from another context?
1252 FIXME: No, it's not correct. If someone sets a
1253 conditional breakpoint at an address, then the
1254 breakpoint's `struct expression' should refer to the
1255 `struct symbol' appropriate for the breakpoint's
1256 address, which may not be the PC.
1258 Even if it were never called from another context,
1259 it's totally bizarre for lookup_symbol's behavior to
1260 depend on the value of the inferior's current PC. We
1261 should pass in the appropriate PC as well as the
1262 block. The interface to lookup_symbol should change
1263 to require the caller to provide a PC. */
1265 if (SYMBOL_ALIASES (sym))
1266 sym = find_active_alias (sym, read_pc ());
1269 if (SYMBOL_CLASS (sym) != LOC_ARG &&
1270 SYMBOL_CLASS (sym) != LOC_LOCAL_ARG &&
1271 SYMBOL_CLASS (sym) != LOC_REF_ARG &&
1272 SYMBOL_CLASS (sym) != LOC_REGPARM &&
1273 SYMBOL_CLASS (sym) != LOC_REGPARM_ADDR &&
1274 SYMBOL_CLASS (sym) != LOC_BASEREG_ARG)
1282 return (sym_found); /* Will be NULL if not found. */
1285 /* Given a main symbol SYM and ADDR, search through the alias
1286 list to determine if an alias is active at ADDR and return
1289 If no alias is active, then return SYM. */
1291 static struct symbol *
1292 find_active_alias (struct symbol *sym, CORE_ADDR addr)
1294 struct range_list *r;
1295 struct alias_list *aliases;
1297 /* If we have aliases, check them first. */
1298 aliases = SYMBOL_ALIASES (sym);
1302 if (!SYMBOL_RANGES (aliases->sym))
1303 return aliases->sym;
1304 for (r = SYMBOL_RANGES (aliases->sym); r; r = r->next)
1306 if (r->start <= addr && r->end > addr)
1307 return aliases->sym;
1309 aliases = aliases->next;
1312 /* Nothing found, return the main symbol. */
1317 /* Return the symbol for the function which contains a specified
1318 lexical block, described by a struct block BL. */
1321 block_function (struct block *bl)
1323 while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
1324 bl = BLOCK_SUPERBLOCK (bl);
1326 return BLOCK_FUNCTION (bl);
1329 /* Find the symtab associated with PC and SECTION. Look through the
1330 psymtabs and read in another symtab if necessary. */
1333 find_pc_sect_symtab (CORE_ADDR pc, asection *section)
1335 register struct block *b;
1336 struct blockvector *bv;
1337 register struct symtab *s = NULL;
1338 register struct symtab *best_s = NULL;
1339 register struct partial_symtab *ps;
1340 register struct objfile *objfile;
1341 CORE_ADDR distance = 0;
1343 /* Search all symtabs for the one whose file contains our address, and which
1344 is the smallest of all the ones containing the address. This is designed
1345 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1346 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1347 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1349 This happens for native ecoff format, where code from included files
1350 gets its own symtab. The symtab for the included file should have
1351 been read in already via the dependency mechanism.
1352 It might be swifter to create several symtabs with the same name
1353 like xcoff does (I'm not sure).
1355 It also happens for objfiles that have their functions reordered.
1356 For these, the symtab we are looking for is not necessarily read in. */
1358 ALL_SYMTABS (objfile, s)
1360 bv = BLOCKVECTOR (s);
1361 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1363 if (BLOCK_START (b) <= pc
1364 && BLOCK_END (b) > pc
1366 || BLOCK_END (b) - BLOCK_START (b) < distance))
1368 /* For an objfile that has its functions reordered,
1369 find_pc_psymtab will find the proper partial symbol table
1370 and we simply return its corresponding symtab. */
1371 /* In order to better support objfiles that contain both
1372 stabs and coff debugging info, we continue on if a psymtab
1374 if ((objfile->flags & OBJF_REORDERED) && objfile->psymtabs)
1376 ps = find_pc_sect_psymtab (pc, section);
1378 return PSYMTAB_TO_SYMTAB (ps);
1384 for (i = 0; i < b->nsyms; i++)
1386 fixup_symbol_section (b->sym[i], objfile);
1387 if (section == SYMBOL_BFD_SECTION (b->sym[i]))
1391 continue; /* no symbol in this symtab matches section */
1393 distance = BLOCK_END (b) - BLOCK_START (b);
1402 ps = find_pc_sect_psymtab (pc, section);
1406 /* Might want to error() here (in case symtab is corrupt and
1407 will cause a core dump), but maybe we can successfully
1408 continue, so let's not. */
1410 (Internal error: pc 0x%s in read in psymtab, but not in symtab.)\n",
1412 s = PSYMTAB_TO_SYMTAB (ps);
1417 /* Find the symtab associated with PC. Look through the psymtabs and
1418 read in another symtab if necessary. Backward compatibility, no section */
1421 find_pc_symtab (CORE_ADDR pc)
1423 return find_pc_sect_symtab (pc, find_pc_mapped_section (pc));
1429 /* Find the closest symbol value (of any sort -- function or variable)
1430 for a given address value. Slow but complete. (currently unused,
1431 mainly because it is too slow. We could fix it if each symtab and
1432 psymtab had contained in it the addresses ranges of each of its
1433 sections, which also would be required to make things like "info
1434 line *0x2345" cause psymtabs to be converted to symtabs). */
1437 find_addr_symbol (CORE_ADDR addr, struct symtab **symtabp, CORE_ADDR *symaddrp)
1439 struct symtab *symtab, *best_symtab;
1440 struct objfile *objfile;
1441 register int bot, top;
1442 register struct symbol *sym;
1443 register CORE_ADDR sym_addr;
1444 struct block *block;
1447 /* Info on best symbol seen so far */
1449 register CORE_ADDR best_sym_addr = 0;
1450 struct symbol *best_sym = 0;
1452 /* FIXME -- we should pull in all the psymtabs, too! */
1453 ALL_SYMTABS (objfile, symtab)
1455 /* Search the global and static blocks in this symtab for
1456 the closest symbol-address to the desired address. */
1458 for (blocknum = GLOBAL_BLOCK; blocknum <= STATIC_BLOCK; blocknum++)
1461 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), blocknum);
1462 top = BLOCK_NSYMS (block);
1463 for (bot = 0; bot < top; bot++)
1465 sym = BLOCK_SYM (block, bot);
1466 switch (SYMBOL_CLASS (sym))
1470 sym_addr = SYMBOL_VALUE_ADDRESS (sym);
1474 sym_addr = SYMBOL_VALUE_ADDRESS (sym);
1475 /* An indirect symbol really lives at *sym_addr,
1476 * so an indirection needs to be done.
1477 * However, I am leaving this commented out because it's
1478 * expensive, and it's possible that symbolization
1479 * could be done without an active process (in
1480 * case this read_memory will fail). RT
1481 sym_addr = read_memory_unsigned_integer
1482 (sym_addr, TARGET_PTR_BIT / TARGET_CHAR_BIT);
1487 sym_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1494 if (sym_addr <= addr)
1495 if (sym_addr > best_sym_addr)
1497 /* Quit if we found an exact match. */
1499 best_sym_addr = sym_addr;
1500 best_symtab = symtab;
1501 if (sym_addr == addr)
1510 *symtabp = best_symtab;
1512 *symaddrp = best_sym_addr;
1517 /* Find the source file and line number for a given PC value and SECTION.
1518 Return a structure containing a symtab pointer, a line number,
1519 and a pc range for the entire source line.
1520 The value's .pc field is NOT the specified pc.
1521 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1522 use the line that ends there. Otherwise, in that case, the line
1523 that begins there is used. */
1525 /* The big complication here is that a line may start in one file, and end just
1526 before the start of another file. This usually occurs when you #include
1527 code in the middle of a subroutine. To properly find the end of a line's PC
1528 range, we must search all symtabs associated with this compilation unit, and
1529 find the one whose first PC is closer than that of the next line in this
1532 /* If it's worth the effort, we could be using a binary search. */
1534 struct symtab_and_line
1535 find_pc_sect_line (CORE_ADDR pc, struct sec *section, int notcurrent)
1538 register struct linetable *l;
1541 register struct linetable_entry *item;
1542 struct symtab_and_line val;
1543 struct blockvector *bv;
1544 struct minimal_symbol *msymbol;
1545 struct minimal_symbol *mfunsym;
1547 /* Info on best line seen so far, and where it starts, and its file. */
1549 struct linetable_entry *best = NULL;
1550 CORE_ADDR best_end = 0;
1551 struct symtab *best_symtab = 0;
1553 /* Store here the first line number
1554 of a file which contains the line at the smallest pc after PC.
1555 If we don't find a line whose range contains PC,
1556 we will use a line one less than this,
1557 with a range from the start of that file to the first line's pc. */
1558 struct linetable_entry *alt = NULL;
1559 struct symtab *alt_symtab = 0;
1561 /* Info on best line seen in this file. */
1563 struct linetable_entry *prev;
1565 /* If this pc is not from the current frame,
1566 it is the address of the end of a call instruction.
1567 Quite likely that is the start of the following statement.
1568 But what we want is the statement containing the instruction.
1569 Fudge the pc to make sure we get that. */
1571 INIT_SAL (&val); /* initialize to zeroes */
1573 /* Don't even think about line numbers if we can't find a function
1575 if (find_pc_function (pc) == NULL)
1584 /* elz: added this because this function returned the wrong
1585 information if the pc belongs to a stub (import/export)
1586 to call a shlib function. This stub would be anywhere between
1587 two functions in the target, and the line info was erroneously
1588 taken to be the one of the line before the pc.
1590 /* RT: Further explanation:
1592 * We have stubs (trampolines) inserted between procedures.
1594 * Example: "shr1" exists in a shared library, and a "shr1" stub also
1595 * exists in the main image.
1597 * In the minimal symbol table, we have a bunch of symbols
1598 * sorted by start address. The stubs are marked as "trampoline",
1599 * the others appear as text. E.g.:
1601 * Minimal symbol table for main image
1602 * main: code for main (text symbol)
1603 * shr1: stub (trampoline symbol)
1604 * foo: code for foo (text symbol)
1606 * Minimal symbol table for "shr1" image:
1608 * shr1: code for shr1 (text symbol)
1611 * So the code below is trying to detect if we are in the stub
1612 * ("shr1" stub), and if so, find the real code ("shr1" trampoline),
1613 * and if found, do the symbolization from the real-code address
1614 * rather than the stub address.
1616 * Assumptions being made about the minimal symbol table:
1617 * 1. lookup_minimal_symbol_by_pc() will return a trampoline only
1618 * if we're really in the trampoline. If we're beyond it (say
1619 * we're in "foo" in the above example), it'll have a closer
1620 * symbol (the "foo" text symbol for example) and will not
1621 * return the trampoline.
1622 * 2. lookup_minimal_symbol_text() will find a real text symbol
1623 * corresponding to the trampoline, and whose address will
1624 * be different than the trampoline address. I put in a sanity
1625 * check for the address being the same, to avoid an
1626 * infinite recursion.
1628 msymbol = lookup_minimal_symbol_by_pc (pc);
1629 if (msymbol != NULL)
1630 if (MSYMBOL_TYPE (msymbol) == mst_solib_trampoline)
1632 mfunsym = lookup_minimal_symbol_text (SYMBOL_NAME (msymbol), NULL, NULL);
1633 if (mfunsym == NULL)
1634 /* I eliminated this warning since it is coming out
1635 * in the following situation:
1636 * gdb shmain // test program with shared libraries
1637 * (gdb) break shr1 // function in shared lib
1638 * Warning: In stub for ...
1639 * In the above situation, the shared lib is not loaded yet,
1640 * so of course we can't find the real func/line info,
1641 * but the "break" still works, and the warning is annoying.
1642 * So I commented out the warning. RT */
1643 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_NAME(msymbol)) */ ;
1645 else if (SYMBOL_VALUE (mfunsym) == SYMBOL_VALUE (msymbol))
1646 /* Avoid infinite recursion */
1647 /* See above comment about why warning is commented out */
1648 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_NAME(msymbol)) */ ;
1651 return find_pc_line (SYMBOL_VALUE (mfunsym), 0);
1655 s = find_pc_sect_symtab (pc, section);
1658 /* if no symbol information, return previous pc */
1665 bv = BLOCKVECTOR (s);
1667 /* Look at all the symtabs that share this blockvector.
1668 They all have the same apriori range, that we found was right;
1669 but they have different line tables. */
1671 for (; s && BLOCKVECTOR (s) == bv; s = s->next)
1673 /* Find the best line in this symtab. */
1680 /* I think len can be zero if the symtab lacks line numbers
1681 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
1682 I'm not sure which, and maybe it depends on the symbol
1688 item = l->item; /* Get first line info */
1690 /* Is this file's first line closer than the first lines of other files?
1691 If so, record this file, and its first line, as best alternate. */
1692 if (item->pc > pc && (!alt || item->pc < alt->pc))
1698 for (i = 0; i < len; i++, item++)
1700 /* Leave prev pointing to the linetable entry for the last line
1701 that started at or before PC. */
1708 /* At this point, prev points at the line whose start addr is <= pc, and
1709 item points at the next line. If we ran off the end of the linetable
1710 (pc >= start of the last line), then prev == item. If pc < start of
1711 the first line, prev will not be set. */
1713 /* Is this file's best line closer than the best in the other files?
1714 If so, record this file, and its best line, as best so far. */
1716 if (prev && (!best || prev->pc > best->pc))
1721 /* Discard BEST_END if it's before the PC of the current BEST. */
1722 if (best_end <= best->pc)
1726 /* If another line (denoted by ITEM) is in the linetable and its
1727 PC is after BEST's PC, but before the current BEST_END, then
1728 use ITEM's PC as the new best_end. */
1729 if (best && i < len && item->pc > best->pc
1730 && (best_end == 0 || best_end > item->pc))
1731 best_end = item->pc;
1737 { /* If we didn't find any line # info, just
1743 val.symtab = alt_symtab;
1744 val.line = alt->line - 1;
1746 /* Don't return line 0, that means that we didn't find the line. */
1750 val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1756 val.symtab = best_symtab;
1757 val.line = best->line;
1759 if (best_end && (!alt || best_end < alt->pc))
1764 val.end = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1766 val.section = section;
1770 /* Backward compatibility (no section) */
1772 struct symtab_and_line
1773 find_pc_line (CORE_ADDR pc, int notcurrent)
1777 section = find_pc_overlay (pc);
1778 if (pc_in_unmapped_range (pc, section))
1779 pc = overlay_mapped_address (pc, section);
1780 return find_pc_sect_line (pc, section, notcurrent);
1783 /* Find line number LINE in any symtab whose name is the same as
1786 If found, return the symtab that contains the linetable in which it was
1787 found, set *INDEX to the index in the linetable of the best entry
1788 found, and set *EXACT_MATCH nonzero if the value returned is an
1791 If not found, return NULL. */
1794 find_line_symtab (struct symtab *symtab, int line, int *index, int *exact_match)
1798 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
1802 struct linetable *best_linetable;
1803 struct symtab *best_symtab;
1805 /* First try looking it up in the given symtab. */
1806 best_linetable = LINETABLE (symtab);
1807 best_symtab = symtab;
1808 best_index = find_line_common (best_linetable, line, &exact);
1809 if (best_index < 0 || !exact)
1811 /* Didn't find an exact match. So we better keep looking for
1812 another symtab with the same name. In the case of xcoff,
1813 multiple csects for one source file (produced by IBM's FORTRAN
1814 compiler) produce multiple symtabs (this is unavoidable
1815 assuming csects can be at arbitrary places in memory and that
1816 the GLOBAL_BLOCK of a symtab has a begin and end address). */
1818 /* BEST is the smallest linenumber > LINE so far seen,
1819 or 0 if none has been seen so far.
1820 BEST_INDEX and BEST_LINETABLE identify the item for it. */
1823 struct objfile *objfile;
1826 if (best_index >= 0)
1827 best = best_linetable->item[best_index].line;
1831 ALL_SYMTABS (objfile, s)
1833 struct linetable *l;
1836 if (!STREQ (symtab->filename, s->filename))
1839 ind = find_line_common (l, line, &exact);
1849 if (best == 0 || l->item[ind].line < best)
1851 best = l->item[ind].line;
1864 *index = best_index;
1866 *exact_match = exact;
1871 /* Set the PC value for a given source file and line number and return true.
1872 Returns zero for invalid line number (and sets the PC to 0).
1873 The source file is specified with a struct symtab. */
1876 find_line_pc (struct symtab *symtab, int line, CORE_ADDR *pc)
1878 struct linetable *l;
1885 symtab = find_line_symtab (symtab, line, &ind, NULL);
1888 l = LINETABLE (symtab);
1889 *pc = l->item[ind].pc;
1896 /* Find the range of pc values in a line.
1897 Store the starting pc of the line into *STARTPTR
1898 and the ending pc (start of next line) into *ENDPTR.
1899 Returns 1 to indicate success.
1900 Returns 0 if could not find the specified line. */
1903 find_line_pc_range (struct symtab_and_line sal, CORE_ADDR *startptr,
1906 CORE_ADDR startaddr;
1907 struct symtab_and_line found_sal;
1910 if (startaddr == 0 && !find_line_pc (sal.symtab, sal.line, &startaddr))
1913 /* This whole function is based on address. For example, if line 10 has
1914 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
1915 "info line *0x123" should say the line goes from 0x100 to 0x200
1916 and "info line *0x355" should say the line goes from 0x300 to 0x400.
1917 This also insures that we never give a range like "starts at 0x134
1918 and ends at 0x12c". */
1920 found_sal = find_pc_sect_line (startaddr, sal.section, 0);
1921 if (found_sal.line != sal.line)
1923 /* The specified line (sal) has zero bytes. */
1924 *startptr = found_sal.pc;
1925 *endptr = found_sal.pc;
1929 *startptr = found_sal.pc;
1930 *endptr = found_sal.end;
1935 /* Given a line table and a line number, return the index into the line
1936 table for the pc of the nearest line whose number is >= the specified one.
1937 Return -1 if none is found. The value is >= 0 if it is an index.
1939 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1942 find_line_common (register struct linetable *l, register int lineno,
1948 /* BEST is the smallest linenumber > LINENO so far seen,
1949 or 0 if none has been seen so far.
1950 BEST_INDEX identifies the item for it. */
1952 int best_index = -1;
1961 for (i = 0; i < len; i++)
1963 register struct linetable_entry *item = &(l->item[i]);
1965 if (item->line == lineno)
1967 /* Return the first (lowest address) entry which matches. */
1972 if (item->line > lineno && (best == 0 || item->line < best))
1979 /* If we got here, we didn't get an exact match. */
1986 find_pc_line_pc_range (CORE_ADDR pc, CORE_ADDR *startptr, CORE_ADDR *endptr)
1988 struct symtab_and_line sal;
1989 sal = find_pc_line (pc, 0);
1992 return sal.symtab != 0;
1995 /* Given a function symbol SYM, find the symtab and line for the start
1997 If the argument FUNFIRSTLINE is nonzero, we want the first line
1998 of real code inside the function. */
2000 struct symtab_and_line
2001 find_function_start_sal (struct symbol *sym, int funfirstline)
2004 struct symtab_and_line sal;
2006 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
2007 fixup_symbol_section (sym, NULL);
2009 { /* skip "first line" of function (which is actually its prologue) */
2010 asection *section = SYMBOL_BFD_SECTION (sym);
2011 /* If function is in an unmapped overlay, use its unmapped LMA
2012 address, so that SKIP_PROLOGUE has something unique to work on */
2013 if (section_is_overlay (section) &&
2014 !section_is_mapped (section))
2015 pc = overlay_unmapped_address (pc, section);
2017 pc += FUNCTION_START_OFFSET;
2018 pc = SKIP_PROLOGUE (pc);
2020 /* For overlays, map pc back into its mapped VMA range */
2021 pc = overlay_mapped_address (pc, section);
2023 sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0);
2025 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2026 /* Convex: no need to suppress code on first line, if any */
2029 /* Check if SKIP_PROLOGUE left us in mid-line, and the next
2030 line is still part of the same function. */
2032 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) <= sal.end
2033 && sal.end < BLOCK_END (SYMBOL_BLOCK_VALUE (sym)))
2035 /* First pc of next line */
2037 /* Recalculate the line number (might not be N+1). */
2038 sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0);
2046 /* If P is of the form "operator[ \t]+..." where `...' is
2047 some legitimate operator text, return a pointer to the
2048 beginning of the substring of the operator text.
2049 Otherwise, return "". */
2051 operator_chars (char *p, char **end)
2054 if (strncmp (p, "operator", 8))
2058 /* Don't get faked out by `operator' being part of a longer
2060 if (isalpha (*p) || *p == '_' || *p == '$' || *p == '\0')
2063 /* Allow some whitespace between `operator' and the operator symbol. */
2064 while (*p == ' ' || *p == '\t')
2067 /* Recognize 'operator TYPENAME'. */
2069 if (isalpha (*p) || *p == '_' || *p == '$')
2071 register char *q = p + 1;
2072 while (isalnum (*q) || *q == '_' || *q == '$')
2081 case '\\': /* regexp quoting */
2084 if (p[2] == '=') /* 'operator\*=' */
2086 else /* 'operator\*' */
2090 else if (p[1] == '[')
2093 error ("mismatched quoting on brackets, try 'operator\\[\\]'");
2094 else if (p[2] == '\\' && p[3] == ']')
2096 *end = p + 4; /* 'operator\[\]' */
2100 error ("nothing is allowed between '[' and ']'");
2104 /* Gratuitous qoute: skip it and move on. */
2126 if (p[0] == '-' && p[1] == '>')
2128 /* Struct pointer member operator 'operator->'. */
2131 *end = p + 3; /* 'operator->*' */
2134 else if (p[2] == '\\')
2136 *end = p + 4; /* Hopefully 'operator->\*' */
2141 *end = p + 2; /* 'operator->' */
2145 if (p[1] == '=' || p[1] == p[0])
2156 error ("`operator ()' must be specified without whitespace in `()'");
2161 error ("`operator ?:' must be specified without whitespace in `?:'");
2166 error ("`operator []' must be specified without whitespace in `[]'");
2170 error ("`operator %s' not supported", p);
2179 /* If FILE is not already in the table of files, return zero;
2180 otherwise return non-zero. Optionally add FILE to the table if ADD
2181 is non-zero. If *FIRST is non-zero, forget the old table
2184 filename_seen (const char *file, int add, int *first)
2186 /* Table of files seen so far. */
2187 static const char **tab = NULL;
2188 /* Allocated size of tab in elements.
2189 Start with one 256-byte block (when using GNU malloc.c).
2190 24 is the malloc overhead when range checking is in effect. */
2191 static int tab_alloc_size = (256 - 24) / sizeof (char *);
2192 /* Current size of tab in elements. */
2193 static int tab_cur_size;
2199 tab = (const char **) xmalloc (tab_alloc_size * sizeof (*tab));
2203 /* Is FILE in tab? */
2204 for (p = tab; p < tab + tab_cur_size; p++)
2205 if (strcmp (*p, file) == 0)
2208 /* No; maybe add it to tab. */
2211 if (tab_cur_size == tab_alloc_size)
2213 tab_alloc_size *= 2;
2214 tab = (const char **) xrealloc ((char *) tab,
2215 tab_alloc_size * sizeof (*tab));
2217 tab[tab_cur_size++] = file;
2223 /* Slave routine for sources_info. Force line breaks at ,'s.
2224 NAME is the name to print and *FIRST is nonzero if this is the first
2225 name printed. Set *FIRST to zero. */
2227 output_source_filename (char *name, int *first)
2229 /* Since a single source file can result in several partial symbol
2230 tables, we need to avoid printing it more than once. Note: if
2231 some of the psymtabs are read in and some are not, it gets
2232 printed both under "Source files for which symbols have been
2233 read" and "Source files for which symbols will be read in on
2234 demand". I consider this a reasonable way to deal with the
2235 situation. I'm not sure whether this can also happen for
2236 symtabs; it doesn't hurt to check. */
2238 /* Was NAME already seen? */
2239 if (filename_seen (name, 1, first))
2241 /* Yes; don't print it again. */
2244 /* No; print it and reset *FIRST. */
2251 printf_filtered (", ");
2255 fputs_filtered (name, gdb_stdout);
2259 sources_info (char *ignore, int from_tty)
2261 register struct symtab *s;
2262 register struct partial_symtab *ps;
2263 register struct objfile *objfile;
2266 if (!have_full_symbols () && !have_partial_symbols ())
2268 error ("No symbol table is loaded. Use the \"file\" command.");
2271 printf_filtered ("Source files for which symbols have been read in:\n\n");
2274 ALL_SYMTABS (objfile, s)
2276 output_source_filename (s->filename, &first);
2278 printf_filtered ("\n\n");
2280 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2283 ALL_PSYMTABS (objfile, ps)
2287 output_source_filename (ps->filename, &first);
2290 printf_filtered ("\n");
2294 file_matches (char *file, char *files[], int nfiles)
2298 if (file != NULL && nfiles != 0)
2300 for (i = 0; i < nfiles; i++)
2302 if (strcmp (files[i], lbasename (file)) == 0)
2306 else if (nfiles == 0)
2311 /* Free any memory associated with a search. */
2313 free_search_symbols (struct symbol_search *symbols)
2315 struct symbol_search *p;
2316 struct symbol_search *next;
2318 for (p = symbols; p != NULL; p = next)
2326 do_free_search_symbols_cleanup (void *symbols)
2328 free_search_symbols (symbols);
2332 make_cleanup_free_search_symbols (struct symbol_search *symbols)
2334 return make_cleanup (do_free_search_symbols_cleanup, symbols);
2338 /* Search the symbol table for matches to the regular expression REGEXP,
2339 returning the results in *MATCHES.
2341 Only symbols of KIND are searched:
2342 FUNCTIONS_NAMESPACE - search all functions
2343 TYPES_NAMESPACE - search all type names
2344 METHODS_NAMESPACE - search all methods NOT IMPLEMENTED
2345 VARIABLES_NAMESPACE - search all symbols, excluding functions, type names,
2346 and constants (enums)
2348 free_search_symbols should be called when *MATCHES is no longer needed.
2351 search_symbols (char *regexp, namespace_enum kind, int nfiles, char *files[],
2352 struct symbol_search **matches)
2354 register struct symtab *s;
2355 register struct partial_symtab *ps;
2356 register struct blockvector *bv;
2357 struct blockvector *prev_bv = 0;
2358 register struct block *b;
2361 register struct symbol *sym;
2362 struct partial_symbol **psym;
2363 struct objfile *objfile;
2364 struct minimal_symbol *msymbol;
2367 static enum minimal_symbol_type types[]
2369 {mst_data, mst_text, mst_abs, mst_unknown};
2370 static enum minimal_symbol_type types2[]
2372 {mst_bss, mst_file_text, mst_abs, mst_unknown};
2373 static enum minimal_symbol_type types3[]
2375 {mst_file_data, mst_solib_trampoline, mst_abs, mst_unknown};
2376 static enum minimal_symbol_type types4[]
2378 {mst_file_bss, mst_text, mst_abs, mst_unknown};
2379 enum minimal_symbol_type ourtype;
2380 enum minimal_symbol_type ourtype2;
2381 enum minimal_symbol_type ourtype3;
2382 enum minimal_symbol_type ourtype4;
2383 struct symbol_search *sr;
2384 struct symbol_search *psr;
2385 struct symbol_search *tail;
2386 struct cleanup *old_chain = NULL;
2388 if (kind < VARIABLES_NAMESPACE)
2389 error ("must search on specific namespace");
2391 ourtype = types[(int) (kind - VARIABLES_NAMESPACE)];
2392 ourtype2 = types2[(int) (kind - VARIABLES_NAMESPACE)];
2393 ourtype3 = types3[(int) (kind - VARIABLES_NAMESPACE)];
2394 ourtype4 = types4[(int) (kind - VARIABLES_NAMESPACE)];
2396 sr = *matches = NULL;
2401 /* Make sure spacing is right for C++ operators.
2402 This is just a courtesy to make the matching less sensitive
2403 to how many spaces the user leaves between 'operator'
2404 and <TYPENAME> or <OPERATOR>. */
2406 char *opname = operator_chars (regexp, &opend);
2409 int fix = -1; /* -1 means ok; otherwise number of spaces needed. */
2410 if (isalpha (*opname) || *opname == '_' || *opname == '$')
2412 /* There should 1 space between 'operator' and 'TYPENAME'. */
2413 if (opname[-1] != ' ' || opname[-2] == ' ')
2418 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2419 if (opname[-1] == ' ')
2422 /* If wrong number of spaces, fix it. */
2425 char *tmp = (char *) alloca (strlen (regexp) + fix);
2426 sprintf (tmp, "operator%.*s%s", fix, " ", opname);
2431 if (0 != (val = re_comp (regexp)))
2432 error ("Invalid regexp (%s): %s", val, regexp);
2435 /* Search through the partial symtabs *first* for all symbols
2436 matching the regexp. That way we don't have to reproduce all of
2437 the machinery below. */
2439 ALL_PSYMTABS (objfile, ps)
2441 struct partial_symbol **bound, **gbound, **sbound;
2447 gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms;
2448 sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms;
2451 /* Go through all of the symbols stored in a partial
2452 symtab in one loop. */
2453 psym = objfile->global_psymbols.list + ps->globals_offset;
2458 if (bound == gbound && ps->n_static_syms != 0)
2460 psym = objfile->static_psymbols.list + ps->statics_offset;
2471 /* If it would match (logic taken from loop below)
2472 load the file and go on to the next one */
2473 if (file_matches (ps->filename, files, nfiles)
2474 && ((regexp == NULL || SYMBOL_MATCHES_REGEXP (*psym))
2475 && ((kind == VARIABLES_NAMESPACE && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
2476 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
2477 || (kind == FUNCTIONS_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_BLOCK)
2478 || (kind == TYPES_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_TYPEDEF)
2479 || (kind == METHODS_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_BLOCK))))
2481 PSYMTAB_TO_SYMTAB (ps);
2489 /* Here, we search through the minimal symbol tables for functions
2490 and variables that match, and force their symbols to be read.
2491 This is in particular necessary for demangled variable names,
2492 which are no longer put into the partial symbol tables.
2493 The symbol will then be found during the scan of symtabs below.
2495 For functions, find_pc_symtab should succeed if we have debug info
2496 for the function, for variables we have to call lookup_symbol
2497 to determine if the variable has debug info.
2498 If the lookup fails, set found_misc so that we will rescan to print
2499 any matching symbols without debug info.
2502 if (nfiles == 0 && (kind == VARIABLES_NAMESPACE || kind == FUNCTIONS_NAMESPACE))
2504 ALL_MSYMBOLS (objfile, msymbol)
2506 if (MSYMBOL_TYPE (msymbol) == ourtype ||
2507 MSYMBOL_TYPE (msymbol) == ourtype2 ||
2508 MSYMBOL_TYPE (msymbol) == ourtype3 ||
2509 MSYMBOL_TYPE (msymbol) == ourtype4)
2511 if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol))
2513 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)))
2515 if (kind == FUNCTIONS_NAMESPACE
2516 || lookup_symbol (SYMBOL_NAME (msymbol),
2517 (struct block *) NULL,
2519 0, (struct symtab **) NULL) == NULL)
2527 ALL_SYMTABS (objfile, s)
2529 bv = BLOCKVECTOR (s);
2530 /* Often many files share a blockvector.
2531 Scan each blockvector only once so that
2532 we don't get every symbol many times.
2533 It happens that the first symtab in the list
2534 for any given blockvector is the main file. */
2536 for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
2538 b = BLOCKVECTOR_BLOCK (bv, i);
2539 /* Skip the sort if this block is always sorted. */
2540 if (!BLOCK_SHOULD_SORT (b))
2541 sort_block_syms (b);
2542 for (j = 0; j < BLOCK_NSYMS (b); j++)
2545 sym = BLOCK_SYM (b, j);
2546 if (file_matches (s->filename, files, nfiles)
2547 && ((regexp == NULL || SYMBOL_MATCHES_REGEXP (sym))
2548 && ((kind == VARIABLES_NAMESPACE && SYMBOL_CLASS (sym) != LOC_TYPEDEF
2549 && SYMBOL_CLASS (sym) != LOC_BLOCK
2550 && SYMBOL_CLASS (sym) != LOC_CONST)
2551 || (kind == FUNCTIONS_NAMESPACE && SYMBOL_CLASS (sym) == LOC_BLOCK)
2552 || (kind == TYPES_NAMESPACE && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2553 || (kind == METHODS_NAMESPACE && SYMBOL_CLASS (sym) == LOC_BLOCK))))
2556 psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search));
2560 psr->msymbol = NULL;
2565 old_chain = make_cleanup_free_search_symbols (sr);
2576 /* If there are no eyes, avoid all contact. I mean, if there are
2577 no debug symbols, then print directly from the msymbol_vector. */
2579 if (found_misc || kind != FUNCTIONS_NAMESPACE)
2581 ALL_MSYMBOLS (objfile, msymbol)
2583 if (MSYMBOL_TYPE (msymbol) == ourtype ||
2584 MSYMBOL_TYPE (msymbol) == ourtype2 ||
2585 MSYMBOL_TYPE (msymbol) == ourtype3 ||
2586 MSYMBOL_TYPE (msymbol) == ourtype4)
2588 if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol))
2590 /* Functions: Look up by address. */
2591 if (kind != FUNCTIONS_NAMESPACE ||
2592 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol))))
2594 /* Variables/Absolutes: Look up by name */
2595 if (lookup_symbol (SYMBOL_NAME (msymbol),
2596 (struct block *) NULL, VAR_NAMESPACE,
2597 0, (struct symtab **) NULL) == NULL)
2600 psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search));
2602 psr->msymbol = msymbol;
2609 old_chain = make_cleanup_free_search_symbols (sr);
2623 discard_cleanups (old_chain);
2626 /* Helper function for symtab_symbol_info, this function uses
2627 the data returned from search_symbols() to print information
2628 regarding the match to gdb_stdout.
2631 print_symbol_info (namespace_enum kind, struct symtab *s, struct symbol *sym,
2632 int block, char *last)
2634 if (last == NULL || strcmp (last, s->filename) != 0)
2636 fputs_filtered ("\nFile ", gdb_stdout);
2637 fputs_filtered (s->filename, gdb_stdout);
2638 fputs_filtered (":\n", gdb_stdout);
2641 if (kind != TYPES_NAMESPACE && block == STATIC_BLOCK)
2642 printf_filtered ("static ");
2644 /* Typedef that is not a C++ class */
2645 if (kind == TYPES_NAMESPACE
2646 && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
2647 typedef_print (SYMBOL_TYPE (sym), sym, gdb_stdout);
2648 /* variable, func, or typedef-that-is-c++-class */
2649 else if (kind < TYPES_NAMESPACE ||
2650 (kind == TYPES_NAMESPACE &&
2651 SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE))
2653 type_print (SYMBOL_TYPE (sym),
2654 (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2655 ? "" : SYMBOL_SOURCE_NAME (sym)),
2658 printf_filtered (";\n");
2663 /* Tiemann says: "info methods was never implemented." */
2664 char *demangled_name;
2665 c_type_print_base (TYPE_FN_FIELD_TYPE (t, block),
2667 c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (t, block),
2669 if (TYPE_FN_FIELD_STUB (t, block))
2670 check_stub_method (TYPE_DOMAIN_TYPE (type), j, block);
2672 cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t, block),
2673 DMGL_ANSI | DMGL_PARAMS);
2674 if (demangled_name == NULL)
2675 fprintf_filtered (stream, "<badly mangled name %s>",
2676 TYPE_FN_FIELD_PHYSNAME (t, block));
2679 fputs_filtered (demangled_name, stream);
2680 xfree (demangled_name);
2686 /* This help function for symtab_symbol_info() prints information
2687 for non-debugging symbols to gdb_stdout.
2690 print_msymbol_info (struct minimal_symbol *msymbol)
2694 if (TARGET_ADDR_BIT <= 32)
2695 tmp = longest_local_hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol)
2696 & (CORE_ADDR) 0xffffffff,
2699 tmp = longest_local_hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol),
2701 printf_filtered ("%s %s\n",
2702 tmp, SYMBOL_SOURCE_NAME (msymbol));
2705 /* This is the guts of the commands "info functions", "info types", and
2706 "info variables". It calls search_symbols to find all matches and then
2707 print_[m]symbol_info to print out some useful information about the
2711 symtab_symbol_info (char *regexp, namespace_enum kind, int from_tty)
2713 static char *classnames[]
2715 {"variable", "function", "type", "method"};
2716 struct symbol_search *symbols;
2717 struct symbol_search *p;
2718 struct cleanup *old_chain;
2719 char *last_filename = NULL;
2722 /* must make sure that if we're interrupted, symbols gets freed */
2723 search_symbols (regexp, kind, 0, (char **) NULL, &symbols);
2724 old_chain = make_cleanup_free_search_symbols (symbols);
2726 printf_filtered (regexp
2727 ? "All %ss matching regular expression \"%s\":\n"
2728 : "All defined %ss:\n",
2729 classnames[(int) (kind - VARIABLES_NAMESPACE)], regexp);
2731 for (p = symbols; p != NULL; p = p->next)
2735 if (p->msymbol != NULL)
2739 printf_filtered ("\nNon-debugging symbols:\n");
2742 print_msymbol_info (p->msymbol);
2746 print_symbol_info (kind,
2751 last_filename = p->symtab->filename;
2755 do_cleanups (old_chain);
2759 variables_info (char *regexp, int from_tty)
2761 symtab_symbol_info (regexp, VARIABLES_NAMESPACE, from_tty);
2765 functions_info (char *regexp, int from_tty)
2767 symtab_symbol_info (regexp, FUNCTIONS_NAMESPACE, from_tty);
2772 types_info (char *regexp, int from_tty)
2774 symtab_symbol_info (regexp, TYPES_NAMESPACE, from_tty);
2778 /* Tiemann says: "info methods was never implemented." */
2780 methods_info (char *regexp)
2782 symtab_symbol_info (regexp, METHODS_NAMESPACE, 0, from_tty);
2786 /* Breakpoint all functions matching regular expression. */
2789 rbreak_command_wrapper (char *regexp, int from_tty)
2791 rbreak_command (regexp, from_tty);
2795 rbreak_command (char *regexp, int from_tty)
2797 struct symbol_search *ss;
2798 struct symbol_search *p;
2799 struct cleanup *old_chain;
2801 search_symbols (regexp, FUNCTIONS_NAMESPACE, 0, (char **) NULL, &ss);
2802 old_chain = make_cleanup_free_search_symbols (ss);
2804 for (p = ss; p != NULL; p = p->next)
2806 if (p->msymbol == NULL)
2808 char *string = (char *) alloca (strlen (p->symtab->filename)
2809 + strlen (SYMBOL_NAME (p->symbol))
2811 strcpy (string, p->symtab->filename);
2812 strcat (string, ":'");
2813 strcat (string, SYMBOL_NAME (p->symbol));
2814 strcat (string, "'");
2815 break_command (string, from_tty);
2816 print_symbol_info (FUNCTIONS_NAMESPACE,
2820 p->symtab->filename);
2824 break_command (SYMBOL_NAME (p->msymbol), from_tty);
2825 printf_filtered ("<function, no debug info> %s;\n",
2826 SYMBOL_SOURCE_NAME (p->msymbol));
2830 do_cleanups (old_chain);
2834 /* Return Nonzero if block a is lexically nested within block b,
2835 or if a and b have the same pc range.
2836 Return zero otherwise. */
2838 contained_in (struct block *a, struct block *b)
2842 return BLOCK_START (a) >= BLOCK_START (b)
2843 && BLOCK_END (a) <= BLOCK_END (b);
2847 /* Helper routine for make_symbol_completion_list. */
2849 static int return_val_size;
2850 static int return_val_index;
2851 static char **return_val;
2853 #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
2855 if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \
2856 /* Put only the mangled name on the list. */ \
2857 /* Advantage: "b foo<TAB>" completes to "b foo(int, int)" */ \
2858 /* Disadvantage: "b foo__i<TAB>" doesn't complete. */ \
2859 completion_list_add_name \
2860 (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \
2862 completion_list_add_name \
2863 (SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \
2866 /* Test to see if the symbol specified by SYMNAME (which is already
2867 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
2868 characters. If so, add it to the current completion list. */
2871 completion_list_add_name (char *symname, char *sym_text, int sym_text_len,
2872 char *text, char *word)
2877 /* clip symbols that cannot match */
2879 if (strncmp (symname, sym_text, sym_text_len) != 0)
2884 /* We have a match for a completion, so add SYMNAME to the current list
2885 of matches. Note that the name is moved to freshly malloc'd space. */
2889 if (word == sym_text)
2891 new = xmalloc (strlen (symname) + 5);
2892 strcpy (new, symname);
2894 else if (word > sym_text)
2896 /* Return some portion of symname. */
2897 new = xmalloc (strlen (symname) + 5);
2898 strcpy (new, symname + (word - sym_text));
2902 /* Return some of SYM_TEXT plus symname. */
2903 new = xmalloc (strlen (symname) + (sym_text - word) + 5);
2904 strncpy (new, word, sym_text - word);
2905 new[sym_text - word] = '\0';
2906 strcat (new, symname);
2909 if (return_val_index + 3 > return_val_size)
2911 newsize = (return_val_size *= 2) * sizeof (char *);
2912 return_val = (char **) xrealloc ((char *) return_val, newsize);
2914 return_val[return_val_index++] = new;
2915 return_val[return_val_index] = NULL;
2919 /* Return a NULL terminated array of all symbols (regardless of class)
2920 which begin by matching TEXT. If the answer is no symbols, then
2921 the return value is an array which contains only a NULL pointer.
2923 Problem: All of the symbols have to be copied because readline frees them.
2924 I'm not going to worry about this; hopefully there won't be that many. */
2927 make_symbol_completion_list (char *text, char *word)
2929 register struct symbol *sym;
2930 register struct symtab *s;
2931 register struct partial_symtab *ps;
2932 register struct minimal_symbol *msymbol;
2933 register struct objfile *objfile;
2934 register struct block *b, *surrounding_static_block = 0;
2936 struct partial_symbol **psym;
2937 /* The symbol we are completing on. Points in same buffer as text. */
2939 /* Length of sym_text. */
2942 /* Now look for the symbol we are supposed to complete on.
2943 FIXME: This should be language-specific. */
2947 char *quote_pos = NULL;
2949 /* First see if this is a quoted string. */
2951 for (p = text; *p != '\0'; ++p)
2953 if (quote_found != '\0')
2955 if (*p == quote_found)
2956 /* Found close quote. */
2958 else if (*p == '\\' && p[1] == quote_found)
2959 /* A backslash followed by the quote character
2960 doesn't end the string. */
2963 else if (*p == '\'' || *p == '"')
2969 if (quote_found == '\'')
2970 /* A string within single quotes can be a symbol, so complete on it. */
2971 sym_text = quote_pos + 1;
2972 else if (quote_found == '"')
2973 /* A double-quoted string is never a symbol, nor does it make sense
2974 to complete it any other way. */
2976 return_val = (char **) xmalloc (sizeof (char *));
2977 return_val[0] = NULL;
2982 /* It is not a quoted string. Break it based on the characters
2983 which are in symbols. */
2986 if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
2995 sym_text_len = strlen (sym_text);
2997 return_val_size = 100;
2998 return_val_index = 0;
2999 return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
3000 return_val[0] = NULL;
3002 /* Look through the partial symtabs for all symbols which begin
3003 by matching SYM_TEXT. Add each one that you find to the list. */
3005 ALL_PSYMTABS (objfile, ps)
3007 /* If the psymtab's been read in we'll get it when we search
3008 through the blockvector. */
3012 for (psym = objfile->global_psymbols.list + ps->globals_offset;
3013 psym < (objfile->global_psymbols.list + ps->globals_offset
3014 + ps->n_global_syms);
3017 /* If interrupted, then quit. */
3019 COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word);
3022 for (psym = objfile->static_psymbols.list + ps->statics_offset;
3023 psym < (objfile->static_psymbols.list + ps->statics_offset
3024 + ps->n_static_syms);
3028 COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word);
3032 /* At this point scan through the misc symbol vectors and add each
3033 symbol you find to the list. Eventually we want to ignore
3034 anything that isn't a text symbol (everything else will be
3035 handled by the psymtab code above). */
3037 ALL_MSYMBOLS (objfile, msymbol)
3040 COMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text, word);
3043 /* Search upwards from currently selected frame (so that we can
3044 complete on local vars. */
3046 for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b))
3048 if (!BLOCK_SUPERBLOCK (b))
3050 surrounding_static_block = b; /* For elmin of dups */
3053 /* Also catch fields of types defined in this places which match our
3054 text string. Only complete on types visible from current context. */
3056 ALL_BLOCK_SYMBOLS (b, i, sym)
3058 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3059 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
3061 struct type *t = SYMBOL_TYPE (sym);
3062 enum type_code c = TYPE_CODE (t);
3064 if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
3066 for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
3068 if (TYPE_FIELD_NAME (t, j))
3070 completion_list_add_name (TYPE_FIELD_NAME (t, j),
3071 sym_text, sym_text_len, text, word);
3079 /* Go through the symtabs and check the externs and statics for
3080 symbols which match. */
3082 ALL_SYMTABS (objfile, s)
3085 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
3086 ALL_BLOCK_SYMBOLS (b, i, sym)
3088 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3092 ALL_SYMTABS (objfile, s)
3095 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
3096 /* Don't do this block twice. */
3097 if (b == surrounding_static_block)
3099 ALL_BLOCK_SYMBOLS (b, i, sym)
3101 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3105 return (return_val);
3108 /* Like make_symbol_completion_list, but returns a list of symbols
3109 defined in a source file FILE. */
3112 make_file_symbol_completion_list (char *text, char *word, char *srcfile)
3114 register struct symbol *sym;
3115 register struct symtab *s;
3116 register struct block *b;
3118 /* The symbol we are completing on. Points in same buffer as text. */
3120 /* Length of sym_text. */
3123 /* Now look for the symbol we are supposed to complete on.
3124 FIXME: This should be language-specific. */
3128 char *quote_pos = NULL;
3130 /* First see if this is a quoted string. */
3132 for (p = text; *p != '\0'; ++p)
3134 if (quote_found != '\0')
3136 if (*p == quote_found)
3137 /* Found close quote. */
3139 else if (*p == '\\' && p[1] == quote_found)
3140 /* A backslash followed by the quote character
3141 doesn't end the string. */
3144 else if (*p == '\'' || *p == '"')
3150 if (quote_found == '\'')
3151 /* A string within single quotes can be a symbol, so complete on it. */
3152 sym_text = quote_pos + 1;
3153 else if (quote_found == '"')
3154 /* A double-quoted string is never a symbol, nor does it make sense
3155 to complete it any other way. */
3157 return_val = (char **) xmalloc (sizeof (char *));
3158 return_val[0] = NULL;
3163 /* It is not a quoted string. Break it based on the characters
3164 which are in symbols. */
3167 if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
3176 sym_text_len = strlen (sym_text);
3178 return_val_size = 10;
3179 return_val_index = 0;
3180 return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
3181 return_val[0] = NULL;
3183 /* Find the symtab for SRCFILE (this loads it if it was not yet read
3185 s = lookup_symtab (srcfile);
3188 /* Maybe they typed the file with leading directories, while the
3189 symbol tables record only its basename. */
3190 const char *tail = lbasename (srcfile);
3193 s = lookup_symtab (tail);
3196 /* If we have no symtab for that file, return an empty list. */
3198 return (return_val);
3200 /* Go through this symtab and check the externs and statics for
3201 symbols which match. */
3203 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
3204 ALL_BLOCK_SYMBOLS (b, i, sym)
3206 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3209 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
3210 ALL_BLOCK_SYMBOLS (b, i, sym)
3212 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3215 return (return_val);
3218 /* A helper function for make_source_files_completion_list. It adds
3219 another file name to a list of possible completions, growing the
3220 list as necessary. */
3223 add_filename_to_list (const char *fname, char *text, char *word,
3224 char ***list, int *list_used, int *list_alloced)
3227 size_t fnlen = strlen (fname);
3229 if (*list_used + 1 >= *list_alloced)
3232 *list = (char **) xrealloc ((char *) *list,
3233 *list_alloced * sizeof (char *));
3238 /* Return exactly fname. */
3239 new = xmalloc (fnlen + 5);
3240 strcpy (new, fname);
3242 else if (word > text)
3244 /* Return some portion of fname. */
3245 new = xmalloc (fnlen + 5);
3246 strcpy (new, fname + (word - text));
3250 /* Return some of TEXT plus fname. */
3251 new = xmalloc (fnlen + (text - word) + 5);
3252 strncpy (new, word, text - word);
3253 new[text - word] = '\0';
3254 strcat (new, fname);
3256 (*list)[*list_used] = new;
3257 (*list)[++*list_used] = NULL;
3261 not_interesting_fname (const char *fname)
3263 static const char *illegal_aliens[] = {
3264 "_globals_", /* inserted by coff_symtab_read */
3269 for (i = 0; illegal_aliens[i]; i++)
3271 if (strcmp (fname, illegal_aliens[i]) == 0)
3277 /* Return a NULL terminated array of all source files whose names
3278 begin with matching TEXT. The file names are looked up in the
3279 symbol tables of this program. If the answer is no matchess, then
3280 the return value is an array which contains only a NULL pointer. */
3283 make_source_files_completion_list (char *text, char *word)
3285 register struct symtab *s;
3286 register struct partial_symtab *ps;
3287 register struct objfile *objfile;
3289 int list_alloced = 1;
3291 size_t text_len = strlen (text);
3292 char **list = (char **) xmalloc (list_alloced * sizeof (char *));
3293 const char *base_name;
3297 if (!have_full_symbols () && !have_partial_symbols ())
3300 ALL_SYMTABS (objfile, s)
3302 if (not_interesting_fname (s->filename))
3304 if (!filename_seen (s->filename, 1, &first)
3305 #if HAVE_DOS_BASED_FILE_SYSTEM
3306 && strncasecmp (s->filename, text, text_len) == 0
3308 && strncmp (s->filename, text, text_len) == 0
3312 /* This file matches for a completion; add it to the current
3314 add_filename_to_list (s->filename, text, word,
3315 &list, &list_used, &list_alloced);
3319 /* NOTE: We allow the user to type a base name when the
3320 debug info records leading directories, but not the other
3321 way around. This is what subroutines of breakpoint
3322 command do when they parse file names. */
3323 base_name = lbasename (s->filename);
3324 if (base_name != s->filename
3325 && !filename_seen (base_name, 1, &first)
3326 #if HAVE_DOS_BASED_FILE_SYSTEM
3327 && strncasecmp (base_name, text, text_len) == 0
3329 && strncmp (base_name, text, text_len) == 0
3332 add_filename_to_list (base_name, text, word,
3333 &list, &list_used, &list_alloced);
3337 ALL_PSYMTABS (objfile, ps)
3339 if (not_interesting_fname (ps->filename))
3343 if (!filename_seen (ps->filename, 1, &first)
3344 #if HAVE_DOS_BASED_FILE_SYSTEM
3345 && strncasecmp (ps->filename, text, text_len) == 0
3347 && strncmp (ps->filename, text, text_len) == 0
3351 /* This file matches for a completion; add it to the
3352 current list of matches. */
3353 add_filename_to_list (ps->filename, text, word,
3354 &list, &list_used, &list_alloced);
3359 base_name = lbasename (ps->filename);
3360 if (base_name != ps->filename
3361 && !filename_seen (base_name, 1, &first)
3362 #if HAVE_DOS_BASED_FILE_SYSTEM
3363 && strncasecmp (base_name, text, text_len) == 0
3365 && strncmp (base_name, text, text_len) == 0
3368 add_filename_to_list (base_name, text, word,
3369 &list, &list_used, &list_alloced);
3377 /* Determine if PC is in the prologue of a function. The prologue is the area
3378 between the first instruction of a function, and the first executable line.
3379 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
3381 If non-zero, func_start is where we think the prologue starts, possibly
3382 by previous examination of symbol table information.
3386 in_prologue (CORE_ADDR pc, CORE_ADDR func_start)
3388 struct symtab_and_line sal;
3389 CORE_ADDR func_addr, func_end;
3391 /* We have several sources of information we can consult to figure
3393 - Compilers usually emit line number info that marks the prologue
3394 as its own "source line". So the ending address of that "line"
3395 is the end of the prologue. If available, this is the most
3397 - The minimal symbols and partial symbols, which can usually tell
3398 us the starting and ending addresses of a function.
3399 - If we know the function's start address, we can call the
3400 architecture-defined SKIP_PROLOGUE function to analyze the
3401 instruction stream and guess where the prologue ends.
3402 - Our `func_start' argument; if non-zero, this is the caller's
3403 best guess as to the function's entry point. At the time of
3404 this writing, handle_inferior_event doesn't get this right, so
3405 it should be our last resort. */
3407 /* Consult the partial symbol table, to find which function
3409 if (! find_pc_partial_function (pc, NULL, &func_addr, &func_end))
3411 CORE_ADDR prologue_end;
3413 /* We don't even have minsym information, so fall back to using
3414 func_start, if given. */
3416 return 1; /* We *might* be in a prologue. */
3418 prologue_end = SKIP_PROLOGUE (func_start);
3420 return func_start <= pc && pc < prologue_end;
3423 /* If we have line number information for the function, that's
3424 usually pretty reliable. */
3425 sal = find_pc_line (func_addr, 0);
3427 /* Now sal describes the source line at the function's entry point,
3428 which (by convention) is the prologue. The end of that "line",
3429 sal.end, is the end of the prologue.
3431 Note that, for functions whose source code is all on a single
3432 line, the line number information doesn't always end up this way.
3433 So we must verify that our purported end-of-prologue address is
3434 *within* the function, not at its start or end. */
3436 || sal.end <= func_addr
3437 || func_end <= sal.end)
3439 /* We don't have any good line number info, so use the minsym
3440 information, together with the architecture-specific prologue
3442 CORE_ADDR prologue_end = SKIP_PROLOGUE (func_addr);
3444 return func_addr <= pc && pc < prologue_end;
3447 /* We have line number info, and it looks good. */
3448 return func_addr <= pc && pc < sal.end;
3452 /* Begin overload resolution functions */
3453 /* Helper routine for make_symbol_completion_list. */
3455 static int sym_return_val_size;
3456 static int sym_return_val_index;
3457 static struct symbol **sym_return_val;
3459 /* Test to see if the symbol specified by SYMNAME (which is already
3460 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3461 characters. If so, add it to the current completion list. */
3464 overload_list_add_symbol (struct symbol *sym, char *oload_name)
3469 /* Get the demangled name without parameters */
3470 char *sym_name = cplus_demangle (SYMBOL_NAME (sym), DMGL_ARM | DMGL_ANSI);
3473 sym_name = (char *) xmalloc (strlen (SYMBOL_NAME (sym)) + 1);
3474 strcpy (sym_name, SYMBOL_NAME (sym));
3477 /* skip symbols that cannot match */
3478 if (strcmp (sym_name, oload_name) != 0)
3484 /* If there is no type information, we can't do anything, so skip */
3485 if (SYMBOL_TYPE (sym) == NULL)
3488 /* skip any symbols that we've already considered. */
3489 for (i = 0; i < sym_return_val_index; ++i)
3490 if (!strcmp (SYMBOL_NAME (sym), SYMBOL_NAME (sym_return_val[i])))
3493 /* We have a match for an overload instance, so add SYM to the current list
3494 * of overload instances */
3495 if (sym_return_val_index + 3 > sym_return_val_size)
3497 newsize = (sym_return_val_size *= 2) * sizeof (struct symbol *);
3498 sym_return_val = (struct symbol **) xrealloc ((char *) sym_return_val, newsize);
3500 sym_return_val[sym_return_val_index++] = sym;
3501 sym_return_val[sym_return_val_index] = NULL;
3506 /* Return a null-terminated list of pointers to function symbols that
3507 * match name of the supplied symbol FSYM.
3508 * This is used in finding all overloaded instances of a function name.
3509 * This has been modified from make_symbol_completion_list. */
3513 make_symbol_overload_list (struct symbol *fsym)
3515 register struct symbol *sym;
3516 register struct symtab *s;
3517 register struct partial_symtab *ps;
3518 register struct objfile *objfile;
3519 register struct block *b, *surrounding_static_block = 0;
3521 /* The name we are completing on. */
3522 char *oload_name = NULL;
3523 /* Length of name. */
3524 int oload_name_len = 0;
3526 /* Look for the symbol we are supposed to complete on.
3527 * FIXME: This should be language-specific. */
3529 oload_name = cplus_demangle (SYMBOL_NAME (fsym), DMGL_ARM | DMGL_ANSI);
3532 oload_name = (char *) xmalloc (strlen (SYMBOL_NAME (fsym)) + 1);
3533 strcpy (oload_name, SYMBOL_NAME (fsym));
3535 oload_name_len = strlen (oload_name);
3537 sym_return_val_size = 100;
3538 sym_return_val_index = 0;
3539 sym_return_val = (struct symbol **) xmalloc ((sym_return_val_size + 1) * sizeof (struct symbol *));
3540 sym_return_val[0] = NULL;
3542 /* Look through the partial symtabs for all symbols which begin
3543 by matching OLOAD_NAME. Make sure we read that symbol table in. */
3545 ALL_PSYMTABS (objfile, ps)
3547 struct partial_symbol **psym;
3549 /* If the psymtab's been read in we'll get it when we search
3550 through the blockvector. */
3554 for (psym = objfile->global_psymbols.list + ps->globals_offset;
3555 psym < (objfile->global_psymbols.list + ps->globals_offset
3556 + ps->n_global_syms);
3559 /* If interrupted, then quit. */
3561 /* This will cause the symbol table to be read if it has not yet been */
3562 s = PSYMTAB_TO_SYMTAB (ps);
3565 for (psym = objfile->static_psymbols.list + ps->statics_offset;
3566 psym < (objfile->static_psymbols.list + ps->statics_offset
3567 + ps->n_static_syms);
3571 /* This will cause the symbol table to be read if it has not yet been */
3572 s = PSYMTAB_TO_SYMTAB (ps);
3576 /* Search upwards from currently selected frame (so that we can
3577 complete on local vars. */
3579 for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b))
3581 if (!BLOCK_SUPERBLOCK (b))
3583 surrounding_static_block = b; /* For elimination of dups */
3586 /* Also catch fields of types defined in this places which match our
3587 text string. Only complete on types visible from current context. */
3589 ALL_BLOCK_SYMBOLS (b, i, sym)
3591 overload_list_add_symbol (sym, oload_name);
3595 /* Go through the symtabs and check the externs and statics for
3596 symbols which match. */
3598 ALL_SYMTABS (objfile, s)
3601 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
3602 ALL_BLOCK_SYMBOLS (b, i, sym)
3604 overload_list_add_symbol (sym, oload_name);
3608 ALL_SYMTABS (objfile, s)
3611 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
3612 /* Don't do this block twice. */
3613 if (b == surrounding_static_block)
3615 ALL_BLOCK_SYMBOLS (b, i, sym)
3617 overload_list_add_symbol (sym, oload_name);
3623 return (sym_return_val);
3626 /* End of overload resolution functions */
3628 struct symtabs_and_lines
3629 decode_line_spec (char *string, int funfirstline)
3631 struct symtabs_and_lines sals;
3633 error ("Empty line specification.");
3634 sals = decode_line_1 (&string, funfirstline,
3635 current_source_symtab, current_source_line,
3638 error ("Junk at end of line specification: %s", string);
3643 static char *name_of_main;
3646 set_main_name (const char *name)
3648 if (name_of_main != NULL)
3650 xfree (name_of_main);
3651 name_of_main = NULL;
3655 name_of_main = xstrdup (name);
3662 if (name_of_main != NULL)
3663 return name_of_main;
3670 _initialize_symtab (void)
3672 add_info ("variables", variables_info,
3673 "All global and static variable names, or those matching REGEXP.");
3675 add_com ("whereis", class_info, variables_info,
3676 "All global and static variable names, or those matching REGEXP.");
3678 add_info ("functions", functions_info,
3679 "All function names, or those matching REGEXP.");
3682 /* FIXME: This command has at least the following problems:
3683 1. It prints builtin types (in a very strange and confusing fashion).
3684 2. It doesn't print right, e.g. with
3685 typedef struct foo *FOO
3686 type_print prints "FOO" when we want to make it (in this situation)
3687 print "struct foo *".
3688 I also think "ptype" or "whatis" is more likely to be useful (but if
3689 there is much disagreement "info types" can be fixed). */
3690 add_info ("types", types_info,
3691 "All type names, or those matching REGEXP.");
3694 add_info ("methods", methods_info,
3695 "All method names, or those matching REGEXP::REGEXP.\n\
3696 If the class qualifier is omitted, it is assumed to be the current scope.\n\
3697 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
3700 add_info ("sources", sources_info,
3701 "Source files in the program.");
3703 add_com ("rbreak", class_breakpoint, rbreak_command,
3704 "Set a breakpoint for all functions matching REGEXP.");
3708 add_com ("lf", class_info, sources_info, "Source files in the program");
3709 add_com ("lg", class_info, variables_info,
3710 "All global and static variable names, or those matching REGEXP.");
3713 /* Initialize the one built-in type that isn't language dependent... */
3714 builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0,
3715 "<unknown type>", (struct objfile *) NULL);