1 /* Symbol table lookup for the GNU debugger, GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
34 #include "call-cmds.h"
35 #include "gdb_regex.h"
36 #include "expression.h"
41 #include "filenames.h" /* for FILENAME_CMP */
45 #include <sys/types.h>
47 #include "gdb_string.h"
52 /* Prototype for one function in parser-defs.h,
53 instead of including that entire file. */
55 extern char *find_template_name_end (char *);
57 /* Prototypes for local functions */
59 static void completion_list_add_name (char *, char *, int, char *, char *);
61 static void rbreak_command (char *, int);
63 static void types_info (char *, int);
65 static void functions_info (char *, int);
67 static void variables_info (char *, int);
69 static void sources_info (char *, int);
71 static void output_source_filename (char *, int *);
73 static int find_line_common (struct linetable *, int, int *);
75 /* This one is used by linespec.c */
77 char *operator_chars (char *p, char **end);
79 static struct partial_symbol *lookup_partial_symbol (struct partial_symtab *,
83 static struct symbol *lookup_symbol_aux (const char *name, const
84 struct block *block, const
85 namespace_enum namespace, int
86 *is_a_field_of_this, struct
90 static struct symbol *find_active_alias (struct symbol *sym, CORE_ADDR addr);
92 /* This flag is used in hppa-tdep.c, and set in hp-symtab-read.c */
93 /* Signals the presence of objects compiled by HP compilers */
94 int hp_som_som_object_present = 0;
96 static void fixup_section (struct general_symbol_info *, struct objfile *);
98 static int file_matches (char *, char **, int);
100 static void print_symbol_info (namespace_enum,
101 struct symtab *, struct symbol *, int, char *);
103 static void print_msymbol_info (struct minimal_symbol *);
105 static void symtab_symbol_info (char *, namespace_enum, int);
107 static void overload_list_add_symbol (struct symbol *sym, char *oload_name);
109 void _initialize_symtab (void);
113 /* The single non-language-specific builtin type */
114 struct type *builtin_type_error;
116 /* Block in which the most recently searched-for symbol was found.
117 Might be better to make this a parameter to lookup_symbol and
120 const struct block *block_found;
122 /* While the C++ support is still in flux, issue a possibly helpful hint on
123 using the new command completion feature on single quoted demangled C++
124 symbols. Remove when loose ends are cleaned up. FIXME -fnf */
127 cplusplus_hint (char *name)
129 while (*name == '\'')
131 printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name, name);
132 printf_filtered ("(Note leading single quote.)\n");
135 /* Check for a symtab of a specific name; first in symtabs, then in
136 psymtabs. *If* there is no '/' in the name, a match after a '/'
137 in the symtab filename will also work. */
140 lookup_symtab (const char *name)
142 register struct symtab *s;
143 register struct partial_symtab *ps;
144 register struct objfile *objfile;
145 char *real_path = NULL;
147 /* Here we are interested in canonicalizing an absolute path, not
148 absolutizing a relative path. */
149 if (IS_ABSOLUTE_PATH (name))
150 real_path = gdb_realpath (name);
154 /* First, search for an exact match */
156 ALL_SYMTABS (objfile, s)
158 if (FILENAME_CMP (name, s->filename) == 0)
163 /* If the user gave us an absolute path, try to find the file in
164 this symtab and use its absolute path. */
165 if (real_path != NULL)
167 char *rp = symtab_to_filename (s);
168 if (FILENAME_CMP (real_path, rp) == 0)
178 /* Now, search for a matching tail (only if name doesn't have any dirs) */
180 if (lbasename (name) == name)
181 ALL_SYMTABS (objfile, s)
183 if (FILENAME_CMP (lbasename (s->filename), name) == 0)
187 /* Same search rules as above apply here, but now we look thru the
190 ps = lookup_partial_symtab (name);
195 error ("Internal: readin %s pst for `%s' found when no symtab found.",
198 s = PSYMTAB_TO_SYMTAB (ps);
203 /* At this point, we have located the psymtab for this file, but
204 the conversion to a symtab has failed. This usually happens
205 when we are looking up an include file. In this case,
206 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
207 been created. So, we need to run through the symtabs again in
208 order to find the file.
209 XXX - This is a crock, and should be fixed inside of the the
210 symbol parsing routines. */
214 /* Lookup the partial symbol table of a source file named NAME.
215 *If* there is no '/' in the name, a match after a '/'
216 in the psymtab filename will also work. */
218 struct partial_symtab *
219 lookup_partial_symtab (const char *name)
221 register struct partial_symtab *pst;
222 register struct objfile *objfile;
223 char *real_path = NULL;
225 /* Here we are interested in canonicalizing an absolute path, not
226 absolutizing a relative path. */
227 if (IS_ABSOLUTE_PATH (name))
228 real_path = gdb_realpath (name);
230 ALL_PSYMTABS (objfile, pst)
232 if (FILENAME_CMP (name, pst->filename) == 0)
237 /* If the user gave us an absolute path, try to find the file in
238 this symtab and use its absolute path. */
239 if (real_path != NULL)
241 if (pst->fullname == NULL)
242 source_full_path_of (pst->filename, &pst->fullname);
243 if (pst->fullname != NULL
244 && FILENAME_CMP (real_path, pst->fullname) == 0)
254 /* Now, search for a matching tail (only if name doesn't have any dirs) */
256 if (lbasename (name) == name)
257 ALL_PSYMTABS (objfile, pst)
259 if (FILENAME_CMP (lbasename (pst->filename), name) == 0)
266 /* Mangle a GDB method stub type. This actually reassembles the pieces of the
267 full method name, which consist of the class name (from T), the unadorned
268 method name from METHOD_ID, and the signature for the specific overload,
269 specified by SIGNATURE_ID. Note that this function is g++ specific. */
272 gdb_mangle_name (struct type *type, int method_id, int signature_id)
274 int mangled_name_len;
276 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
277 struct fn_field *method = &f[signature_id];
278 char *field_name = TYPE_FN_FIELDLIST_NAME (type, method_id);
279 char *physname = TYPE_FN_FIELD_PHYSNAME (f, signature_id);
280 char *newname = type_name_no_tag (type);
282 /* Does the form of physname indicate that it is the full mangled name
283 of a constructor (not just the args)? */
284 int is_full_physname_constructor;
287 int is_destructor = is_destructor_name (physname);
288 /* Need a new type prefix. */
289 char *const_prefix = method->is_const ? "C" : "";
290 char *volatile_prefix = method->is_volatile ? "V" : "";
292 int len = (newname == NULL ? 0 : strlen (newname));
294 if (is_operator_name (field_name))
295 return xstrdup (physname);
297 is_full_physname_constructor = is_constructor_name (physname);
300 is_full_physname_constructor || (newname && STREQ (field_name, newname));
303 is_destructor = (strncmp (physname, "__dt", 4) == 0);
305 if (is_destructor || is_full_physname_constructor)
307 mangled_name = (char *) xmalloc (strlen (physname) + 1);
308 strcpy (mangled_name, physname);
314 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
316 else if (physname[0] == 't' || physname[0] == 'Q')
318 /* The physname for template and qualified methods already includes
320 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
326 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
328 mangled_name_len = ((is_constructor ? 0 : strlen (field_name))
329 + strlen (buf) + len + strlen (physname) + 1);
332 mangled_name = (char *) xmalloc (mangled_name_len);
334 mangled_name[0] = '\0';
336 strcpy (mangled_name, field_name);
338 strcat (mangled_name, buf);
339 /* If the class doesn't have a name, i.e. newname NULL, then we just
340 mangle it using 0 for the length of the class. Thus it gets mangled
341 as something starting with `::' rather than `classname::'. */
343 strcat (mangled_name, newname);
345 strcat (mangled_name, physname);
346 return (mangled_name);
351 /* Find which partial symtab on contains PC and SECTION. Return 0 if none. */
353 struct partial_symtab *
354 find_pc_sect_psymtab (CORE_ADDR pc, asection *section)
356 register struct partial_symtab *pst;
357 register struct objfile *objfile;
358 struct minimal_symbol *msymbol;
360 /* If we know that this is not a text address, return failure. This is
361 necessary because we loop based on texthigh and textlow, which do
362 not include the data ranges. */
363 msymbol = lookup_minimal_symbol_by_pc_section (pc, section);
365 && (msymbol->type == mst_data
366 || msymbol->type == mst_bss
367 || msymbol->type == mst_abs
368 || msymbol->type == mst_file_data
369 || msymbol->type == mst_file_bss))
372 ALL_PSYMTABS (objfile, pst)
374 if (pc >= pst->textlow && pc < pst->texthigh)
376 struct partial_symtab *tpst;
378 /* An objfile that has its functions reordered might have
379 many partial symbol tables containing the PC, but
380 we want the partial symbol table that contains the
381 function containing the PC. */
382 if (!(objfile->flags & OBJF_REORDERED) &&
383 section == 0) /* can't validate section this way */
389 for (tpst = pst; tpst != NULL; tpst = tpst->next)
391 if (pc >= tpst->textlow && pc < tpst->texthigh)
393 struct partial_symbol *p;
395 p = find_pc_sect_psymbol (tpst, pc, section);
397 && SYMBOL_VALUE_ADDRESS (p)
398 == SYMBOL_VALUE_ADDRESS (msymbol))
408 /* Find which partial symtab contains PC. Return 0 if none.
409 Backward compatibility, no section */
411 struct partial_symtab *
412 find_pc_psymtab (CORE_ADDR pc)
414 return find_pc_sect_psymtab (pc, find_pc_mapped_section (pc));
417 /* Find which partial symbol within a psymtab matches PC and SECTION.
418 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
420 struct partial_symbol *
421 find_pc_sect_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc,
424 struct partial_symbol *best = NULL, *p, **pp;
428 psymtab = find_pc_sect_psymtab (pc, section);
432 /* Cope with programs that start at address 0 */
433 best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
435 /* Search the global symbols as well as the static symbols, so that
436 find_pc_partial_function doesn't use a minimal symbol and thus
437 cache a bad endaddr. */
438 for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
439 (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
440 < psymtab->n_global_syms);
444 if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
445 && SYMBOL_CLASS (p) == LOC_BLOCK
446 && pc >= SYMBOL_VALUE_ADDRESS (p)
447 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
448 || (psymtab->textlow == 0
449 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
451 if (section) /* match on a specific section */
453 fixup_psymbol_section (p, psymtab->objfile);
454 if (SYMBOL_BFD_SECTION (p) != section)
457 best_pc = SYMBOL_VALUE_ADDRESS (p);
462 for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
463 (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
464 < psymtab->n_static_syms);
468 if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
469 && SYMBOL_CLASS (p) == LOC_BLOCK
470 && pc >= SYMBOL_VALUE_ADDRESS (p)
471 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
472 || (psymtab->textlow == 0
473 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
475 if (section) /* match on a specific section */
477 fixup_psymbol_section (p, psymtab->objfile);
478 if (SYMBOL_BFD_SECTION (p) != section)
481 best_pc = SYMBOL_VALUE_ADDRESS (p);
489 /* Find which partial symbol within a psymtab matches PC. Return 0 if none.
490 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
492 struct partial_symbol *
493 find_pc_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc)
495 return find_pc_sect_psymbol (psymtab, pc, find_pc_mapped_section (pc));
498 /* Debug symbols usually don't have section information. We need to dig that
499 out of the minimal symbols and stash that in the debug symbol. */
502 fixup_section (struct general_symbol_info *ginfo, struct objfile *objfile)
504 struct minimal_symbol *msym;
505 msym = lookup_minimal_symbol (ginfo->name, NULL, objfile);
509 ginfo->bfd_section = SYMBOL_BFD_SECTION (msym);
510 ginfo->section = SYMBOL_SECTION (msym);
515 fixup_symbol_section (struct symbol *sym, struct objfile *objfile)
520 if (SYMBOL_BFD_SECTION (sym))
523 fixup_section (&sym->ginfo, objfile);
528 struct partial_symbol *
529 fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
534 if (SYMBOL_BFD_SECTION (psym))
537 fixup_section (&psym->ginfo, objfile);
542 /* Find the definition for a specified symbol name NAME
543 in namespace NAMESPACE, visible from lexical block BLOCK.
544 Returns the struct symbol pointer, or zero if no symbol is found.
545 If SYMTAB is non-NULL, store the symbol table in which the
546 symbol was found there, or NULL if not found.
547 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
548 NAME is a field of the current implied argument `this'. If so set
549 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
550 BLOCK_FOUND is set to the block in which NAME is found (in the case of
551 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
553 /* This function has a bunch of loops in it and it would seem to be
554 attractive to put in some QUIT's (though I'm not really sure
555 whether it can run long enough to be really important). But there
556 are a few calls for which it would appear to be bad news to quit
557 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and
558 nindy_frame_chain_valid in nindy-tdep.c. (Note that there is C++
559 code below which can error(), but that probably doesn't affect
560 these calls since they are looking for a known variable and thus
561 can probably assume it will never hit the C++ code). */
564 lookup_symbol (const char *name, const struct block *block,
565 const namespace_enum namespace, int *is_a_field_of_this,
566 struct symtab **symtab)
568 char *modified_name = NULL;
569 char *modified_name2 = NULL;
570 int needtofreename = 0;
571 struct symbol *returnval;
573 if (case_sensitivity == case_sensitive_off)
579 copy = (char *) alloca (len + 1);
580 for (i= 0; i < len; i++)
581 copy[i] = tolower (name[i]);
583 modified_name = copy;
586 modified_name = (char *) name;
588 /* If we are using C++ language, demangle the name before doing a lookup, so
589 we can always binary search. */
590 if (current_language->la_language == language_cplus)
592 modified_name2 = cplus_demangle (modified_name, DMGL_ANSI | DMGL_PARAMS);
595 modified_name = modified_name2;
600 returnval = lookup_symbol_aux (modified_name, block, namespace,
601 is_a_field_of_this, symtab);
603 xfree (modified_name2);
608 static struct symbol *
609 lookup_symbol_aux (const char *name, const struct block *block,
610 const namespace_enum namespace, int *is_a_field_of_this,
611 struct symtab **symtab)
613 register struct symbol *sym;
614 register struct symtab *s = NULL;
615 register struct partial_symtab *ps;
616 register struct blockvector *bv;
617 register struct objfile *objfile = NULL;
618 register struct block *b;
619 register struct minimal_symbol *msymbol;
622 /* Search specified block and its superiors. */
626 sym = lookup_block_symbol (block, name, namespace);
632 /* Search the list of symtabs for one which contains the
633 address of the start of this block. */
634 ALL_SYMTABS (objfile, s)
636 bv = BLOCKVECTOR (s);
637 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
638 if (BLOCK_START (b) <= BLOCK_START (block)
639 && BLOCK_END (b) > BLOCK_START (block))
646 return fixup_symbol_section (sym, objfile);
648 block = BLOCK_SUPERBLOCK (block);
651 /* FIXME: this code is never executed--block is always NULL at this
652 point. What is it trying to do, anyway? We already should have
653 checked the STATIC_BLOCK above (it is the superblock of top-level
654 blocks). Why is VAR_NAMESPACE special-cased? */
655 /* Don't need to mess with the psymtabs; if we have a block,
656 that file is read in. If we don't, then we deal later with
657 all the psymtab stuff that needs checking. */
658 /* Note (RT): The following never-executed code looks unnecessary to me also.
659 * If we change the code to use the original (passed-in)
660 * value of 'block', we could cause it to execute, but then what
661 * would it do? The STATIC_BLOCK of the symtab containing the passed-in
662 * 'block' was already searched by the above code. And the STATIC_BLOCK's
663 * of *other* symtabs (those files not containing 'block' lexically)
664 * should not contain 'block' address-wise. So we wouldn't expect this
665 * code to find any 'sym''s that were not found above. I vote for
666 * deleting the following paragraph of code.
668 if (namespace == VAR_NAMESPACE && block != NULL)
671 /* Find the right symtab. */
672 ALL_SYMTABS (objfile, s)
674 bv = BLOCKVECTOR (s);
675 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
676 if (BLOCK_START (b) <= BLOCK_START (block)
677 && BLOCK_END (b) > BLOCK_START (block))
679 sym = lookup_block_symbol (b, name, VAR_NAMESPACE);
685 return fixup_symbol_section (sym, objfile);
692 /* C++: If requested to do so by the caller,
693 check to see if NAME is a field of `this'. */
694 if (is_a_field_of_this)
696 struct value *v = value_of_this (0);
698 *is_a_field_of_this = 0;
699 if (v && check_field (v, name))
701 *is_a_field_of_this = 1;
708 /* Now search all global blocks. Do the symtab's first, then
709 check the psymtab's. If a psymtab indicates the existence
710 of the desired name as a global, then do psymtab-to-symtab
711 conversion on the fly and return the found symbol. */
713 ALL_SYMTABS (objfile, s)
715 bv = BLOCKVECTOR (s);
716 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
717 sym = lookup_block_symbol (block, name, namespace);
723 return fixup_symbol_section (sym, objfile);
729 /* Check for the possibility of the symbol being a function or
730 a mangled variable that is stored in one of the minimal symbol tables.
731 Eventually, all global symbols might be resolved in this way. */
733 if (namespace == VAR_NAMESPACE)
735 msymbol = lookup_minimal_symbol (name, NULL, NULL);
738 s = find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol),
739 SYMBOL_BFD_SECTION (msymbol));
742 /* This is a function which has a symtab for its address. */
743 bv = BLOCKVECTOR (s);
744 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
745 sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
747 /* We kept static functions in minimal symbol table as well as
748 in static scope. We want to find them in the symbol table. */
751 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
752 sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
756 /* sym == 0 if symbol was found in the minimal symbol table
757 but not in the symtab.
758 Return 0 to use the msymbol definition of "foo_".
760 This happens for Fortran "foo_" symbols,
761 which are "foo" in the symtab.
763 This can also happen if "asm" is used to make a
764 regular symbol but not a debugging symbol, e.g.
771 return fixup_symbol_section (sym, objfile);
773 else if (MSYMBOL_TYPE (msymbol) != mst_text
774 && MSYMBOL_TYPE (msymbol) != mst_file_text
775 && !STREQ (name, SYMBOL_NAME (msymbol)))
777 /* This is a mangled variable, look it up by its
779 return lookup_symbol_aux (SYMBOL_NAME (msymbol), block,
780 namespace, is_a_field_of_this, symtab);
782 /* There are no debug symbols for this file, or we are looking
783 for an unmangled variable.
784 Try to find a matching static symbol below. */
790 ALL_PSYMTABS (objfile, ps)
792 if (!ps->readin && lookup_partial_symbol (ps, name, 1, namespace))
794 s = PSYMTAB_TO_SYMTAB (ps);
795 bv = BLOCKVECTOR (s);
796 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
797 sym = lookup_block_symbol (block, name, namespace);
800 /* This shouldn't be necessary, but as a last resort
801 * try looking in the statics even though the psymtab
802 * claimed the symbol was global. It's possible that
803 * the psymtab gets it wrong in some cases.
805 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
806 sym = lookup_block_symbol (block, name, namespace);
808 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
809 %s may be an inlined function, or may be a template function\n\
810 (if a template, try specifying an instantiation: %s<type>).",
811 name, ps->filename, name, name);
815 return fixup_symbol_section (sym, objfile);
819 /* Now search all static file-level symbols.
820 Not strictly correct, but more useful than an error.
821 Do the symtabs first, then check the psymtabs.
822 If a psymtab indicates the existence
823 of the desired name as a file-level static, then do psymtab-to-symtab
824 conversion on the fly and return the found symbol. */
826 ALL_SYMTABS (objfile, s)
828 bv = BLOCKVECTOR (s);
829 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
830 sym = lookup_block_symbol (block, name, namespace);
836 return fixup_symbol_section (sym, objfile);
840 ALL_PSYMTABS (objfile, ps)
842 if (!ps->readin && lookup_partial_symbol (ps, name, 0, namespace))
844 s = PSYMTAB_TO_SYMTAB (ps);
845 bv = BLOCKVECTOR (s);
846 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
847 sym = lookup_block_symbol (block, name, namespace);
850 /* This shouldn't be necessary, but as a last resort
851 * try looking in the globals even though the psymtab
852 * claimed the symbol was static. It's possible that
853 * the psymtab gets it wrong in some cases.
855 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
856 sym = lookup_block_symbol (block, name, namespace);
858 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
859 %s may be an inlined function, or may be a template function\n\
860 (if a template, try specifying an instantiation: %s<type>).",
861 name, ps->filename, name, name);
865 return fixup_symbol_section (sym, objfile);
871 /* Check for the possibility of the symbol being a function or
872 a global variable that is stored in one of the minimal symbol tables.
873 The "minimal symbol table" is built from linker-supplied info.
875 RT: I moved this check to last, after the complete search of
876 the global (p)symtab's and static (p)symtab's. For HP-generated
877 symbol tables, this check was causing a premature exit from
878 lookup_symbol with NULL return, and thus messing up symbol lookups
879 of things like "c::f". It seems to me a check of the minimal
880 symbol table ought to be a last resort in any case. I'm vaguely
881 worried about the comment below which talks about FORTRAN routines "foo_"
882 though... is it saying we need to do the "minsym" check before
883 the static check in this case?
886 if (namespace == VAR_NAMESPACE)
888 msymbol = lookup_minimal_symbol (name, NULL, NULL);
891 /* OK, we found a minimal symbol in spite of not
892 * finding any symbol. There are various possible
893 * explanations for this. One possibility is the symbol
894 * exists in code not compiled -g. Another possibility
895 * is that the 'psymtab' isn't doing its job.
896 * A third possibility, related to #2, is that we were confused
897 * by name-mangling. For instance, maybe the psymtab isn't
898 * doing its job because it only know about demangled
899 * names, but we were given a mangled name...
902 /* We first use the address in the msymbol to try to
903 * locate the appropriate symtab. Note that find_pc_symtab()
904 * has a side-effect of doing psymtab-to-symtab expansion,
905 * for the found symtab.
907 s = find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol));
910 bv = BLOCKVECTOR (s);
911 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
912 sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
914 /* We kept static functions in minimal symbol table as well as
915 in static scope. We want to find them in the symbol table. */
918 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
919 sym = lookup_block_symbol (block, SYMBOL_NAME (msymbol),
922 /* If we found one, return it */
930 /* If we get here with sym == 0, the symbol was
931 found in the minimal symbol table
932 but not in the symtab.
933 Fall through and return 0 to use the msymbol
934 definition of "foo_".
935 (Note that outer code generally follows up a call
936 to this routine with a call to lookup_minimal_symbol(),
937 so a 0 return means we'll just flow into that other routine).
939 This happens for Fortran "foo_" symbols,
940 which are "foo" in the symtab.
942 This can also happen if "asm" is used to make a
943 regular symbol but not a debugging symbol, e.g.
949 /* If the lookup-by-address fails, try repeating the
950 * entire lookup process with the symbol name from
951 * the msymbol (if different from the original symbol name).
953 else if (MSYMBOL_TYPE (msymbol) != mst_text
954 && MSYMBOL_TYPE (msymbol) != mst_file_text
955 && !STREQ (name, SYMBOL_NAME (msymbol)))
957 return lookup_symbol_aux (SYMBOL_NAME (msymbol), block,
958 namespace, is_a_field_of_this, symtab);
970 /* Look, in partial_symtab PST, for symbol NAME. Check the global
971 symbols if GLOBAL, the static symbols if not */
973 static struct partial_symbol *
974 lookup_partial_symbol (struct partial_symtab *pst, const char *name, int global,
975 namespace_enum namespace)
977 struct partial_symbol *temp;
978 struct partial_symbol **start, **psym;
979 struct partial_symbol **top, **bottom, **center;
980 int length = (global ? pst->n_global_syms : pst->n_static_syms);
981 int do_linear_search = 1;
988 pst->objfile->global_psymbols.list + pst->globals_offset :
989 pst->objfile->static_psymbols.list + pst->statics_offset);
991 if (global) /* This means we can use a binary search. */
993 do_linear_search = 0;
995 /* Binary search. This search is guaranteed to end with center
996 pointing at the earliest partial symbol with the correct
997 name. At that point *all* partial symbols with that name
998 will be checked against the correct namespace. */
1001 top = start + length - 1;
1002 while (top > bottom)
1004 center = bottom + (top - bottom) / 2;
1005 if (!(center < top))
1006 internal_error (__FILE__, __LINE__, "failed internal consistency check");
1007 if (!do_linear_search
1008 && (SYMBOL_LANGUAGE (*center) == language_java))
1010 do_linear_search = 1;
1012 if (strcmp (SYMBOL_SOURCE_NAME (*center), name) >= 0)
1018 bottom = center + 1;
1021 if (!(top == bottom))
1022 internal_error (__FILE__, __LINE__, "failed internal consistency check");
1024 /* djb - 2000-06-03 - Use SYMBOL_MATCHES_NAME, not a strcmp, so
1025 we don't have to force a linear search on C++. Probably holds true
1026 for JAVA as well, no way to check.*/
1027 while (SYMBOL_MATCHES_NAME (*top,name))
1029 if (SYMBOL_NAMESPACE (*top) == namespace)
1037 /* Can't use a binary search or else we found during the binary search that
1038 we should also do a linear search. */
1040 if (do_linear_search)
1042 for (psym = start; psym < start + length; psym++)
1044 if (namespace == SYMBOL_NAMESPACE (*psym))
1046 if (SYMBOL_MATCHES_NAME (*psym, name))
1057 /* Look up a type named NAME in the struct_namespace. The type returned
1058 must not be opaque -- i.e., must have at least one field defined
1060 This code was modelled on lookup_symbol -- the parts not relevant to looking
1061 up types were just left out. In particular it's assumed here that types
1062 are available in struct_namespace and only at file-static or global blocks. */
1066 lookup_transparent_type (const char *name)
1068 register struct symbol *sym;
1069 register struct symtab *s = NULL;
1070 register struct partial_symtab *ps;
1071 struct blockvector *bv;
1072 register struct objfile *objfile;
1073 register struct block *block;
1075 /* Now search all the global symbols. Do the symtab's first, then
1076 check the psymtab's. If a psymtab indicates the existence
1077 of the desired name as a global, then do psymtab-to-symtab
1078 conversion on the fly and return the found symbol. */
1080 ALL_SYMTABS (objfile, s)
1082 bv = BLOCKVECTOR (s);
1083 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1084 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1085 if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1087 return SYMBOL_TYPE (sym);
1091 ALL_PSYMTABS (objfile, ps)
1093 if (!ps->readin && lookup_partial_symbol (ps, name, 1, STRUCT_NAMESPACE))
1095 s = PSYMTAB_TO_SYMTAB (ps);
1096 bv = BLOCKVECTOR (s);
1097 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1098 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1101 /* This shouldn't be necessary, but as a last resort
1102 * try looking in the statics even though the psymtab
1103 * claimed the symbol was global. It's possible that
1104 * the psymtab gets it wrong in some cases.
1106 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1107 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1109 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
1110 %s may be an inlined function, or may be a template function\n\
1111 (if a template, try specifying an instantiation: %s<type>).",
1112 name, ps->filename, name, name);
1114 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1115 return SYMBOL_TYPE (sym);
1119 /* Now search the static file-level symbols.
1120 Not strictly correct, but more useful than an error.
1121 Do the symtab's first, then
1122 check the psymtab's. If a psymtab indicates the existence
1123 of the desired name as a file-level static, then do psymtab-to-symtab
1124 conversion on the fly and return the found symbol.
1127 ALL_SYMTABS (objfile, s)
1129 bv = BLOCKVECTOR (s);
1130 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1131 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1132 if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1134 return SYMBOL_TYPE (sym);
1138 ALL_PSYMTABS (objfile, ps)
1140 if (!ps->readin && lookup_partial_symbol (ps, name, 0, STRUCT_NAMESPACE))
1142 s = PSYMTAB_TO_SYMTAB (ps);
1143 bv = BLOCKVECTOR (s);
1144 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1145 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1148 /* This shouldn't be necessary, but as a last resort
1149 * try looking in the globals even though the psymtab
1150 * claimed the symbol was static. It's possible that
1151 * the psymtab gets it wrong in some cases.
1153 block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1154 sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
1156 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
1157 %s may be an inlined function, or may be a template function\n\
1158 (if a template, try specifying an instantiation: %s<type>).",
1159 name, ps->filename, name, name);
1161 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
1162 return SYMBOL_TYPE (sym);
1165 return (struct type *) 0;
1169 /* Find the psymtab containing main(). */
1170 /* FIXME: What about languages without main() or specially linked
1171 executables that have no main() ? */
1173 struct partial_symtab *
1174 find_main_psymtab (void)
1176 register struct partial_symtab *pst;
1177 register struct objfile *objfile;
1179 ALL_PSYMTABS (objfile, pst)
1181 if (lookup_partial_symbol (pst, main_name (), 1, VAR_NAMESPACE))
1189 /* Search BLOCK for symbol NAME in NAMESPACE.
1191 Note that if NAME is the demangled form of a C++ symbol, we will fail
1192 to find a match during the binary search of the non-encoded names, but
1193 for now we don't worry about the slight inefficiency of looking for
1194 a match we'll never find, since it will go pretty quick. Once the
1195 binary search terminates, we drop through and do a straight linear
1196 search on the symbols. Each symbol which is marked as being a C++
1197 symbol (language_cplus set) has both the encoded and non-encoded names
1198 tested for a match. */
1201 lookup_block_symbol (register const struct block *block, const char *name,
1202 const namespace_enum namespace)
1204 register int bot, top, inc;
1205 register struct symbol *sym;
1206 register struct symbol *sym_found = NULL;
1207 register int do_linear_search = 1;
1209 /* If the blocks's symbols were sorted, start with a binary search. */
1211 if (BLOCK_SHOULD_SORT (block))
1213 /* Reset the linear search flag so if the binary search fails, we
1214 won't do the linear search once unless we find some reason to
1217 do_linear_search = 0;
1218 top = BLOCK_NSYMS (block);
1221 /* Advance BOT to not far before the first symbol whose name is NAME. */
1225 inc = (top - bot + 1);
1226 /* No need to keep binary searching for the last few bits worth. */
1231 inc = (inc >> 1) + bot;
1232 sym = BLOCK_SYM (block, inc);
1233 if (!do_linear_search && (SYMBOL_LANGUAGE (sym) == language_java))
1235 do_linear_search = 1;
1237 if (SYMBOL_SOURCE_NAME (sym)[0] < name[0])
1241 else if (SYMBOL_SOURCE_NAME (sym)[0] > name[0])
1245 else if (strcmp (SYMBOL_SOURCE_NAME (sym), name) < 0)
1255 /* Now scan forward until we run out of symbols, find one whose
1256 name is greater than NAME, or find one we want. If there is
1257 more than one symbol with the right name and namespace, we
1258 return the first one; I believe it is now impossible for us
1259 to encounter two symbols with the same name and namespace
1260 here, because blocks containing argument symbols are no
1263 top = BLOCK_NSYMS (block);
1266 sym = BLOCK_SYM (block, bot);
1267 if (SYMBOL_NAMESPACE (sym) == namespace &&
1268 SYMBOL_MATCHES_NAME (sym, name))
1272 if (SYMBOL_SOURCE_NAME (sym)[0] > name[0])
1280 /* Here if block isn't sorted, or we fail to find a match during the
1281 binary search above. If during the binary search above, we find a
1282 symbol which is a Java symbol, then we have re-enabled the linear
1283 search flag which was reset when starting the binary search.
1285 This loop is equivalent to the loop above, but hacked greatly for speed.
1287 Note that parameter symbols do not always show up last in the
1288 list; this loop makes sure to take anything else other than
1289 parameter symbols first; it only uses parameter symbols as a
1290 last resort. Note that this only takes up extra computation
1293 if (do_linear_search)
1295 top = BLOCK_NSYMS (block);
1299 sym = BLOCK_SYM (block, bot);
1300 if (SYMBOL_NAMESPACE (sym) == namespace &&
1301 SYMBOL_MATCHES_NAME (sym, name))
1303 /* If SYM has aliases, then use any alias that is active
1304 at the current PC. If no alias is active at the current
1305 PC, then use the main symbol.
1307 ?!? Is checking the current pc correct? Is this routine
1308 ever called to look up a symbol from another context?
1310 FIXME: No, it's not correct. If someone sets a
1311 conditional breakpoint at an address, then the
1312 breakpoint's `struct expression' should refer to the
1313 `struct symbol' appropriate for the breakpoint's
1314 address, which may not be the PC.
1316 Even if it were never called from another context,
1317 it's totally bizarre for lookup_symbol's behavior to
1318 depend on the value of the inferior's current PC. We
1319 should pass in the appropriate PC as well as the
1320 block. The interface to lookup_symbol should change
1321 to require the caller to provide a PC. */
1323 if (SYMBOL_ALIASES (sym))
1324 sym = find_active_alias (sym, read_pc ());
1327 if (SYMBOL_CLASS (sym) != LOC_ARG &&
1328 SYMBOL_CLASS (sym) != LOC_LOCAL_ARG &&
1329 SYMBOL_CLASS (sym) != LOC_REF_ARG &&
1330 SYMBOL_CLASS (sym) != LOC_REGPARM &&
1331 SYMBOL_CLASS (sym) != LOC_REGPARM_ADDR &&
1332 SYMBOL_CLASS (sym) != LOC_BASEREG_ARG)
1340 return (sym_found); /* Will be NULL if not found. */
1343 /* Given a main symbol SYM and ADDR, search through the alias
1344 list to determine if an alias is active at ADDR and return
1347 If no alias is active, then return SYM. */
1349 static struct symbol *
1350 find_active_alias (struct symbol *sym, CORE_ADDR addr)
1352 struct range_list *r;
1353 struct alias_list *aliases;
1355 /* If we have aliases, check them first. */
1356 aliases = SYMBOL_ALIASES (sym);
1360 if (!SYMBOL_RANGES (aliases->sym))
1361 return aliases->sym;
1362 for (r = SYMBOL_RANGES (aliases->sym); r; r = r->next)
1364 if (r->start <= addr && r->end > addr)
1365 return aliases->sym;
1367 aliases = aliases->next;
1370 /* Nothing found, return the main symbol. */
1375 /* Return the symbol for the function which contains a specified
1376 lexical block, described by a struct block BL. */
1379 block_function (struct block *bl)
1381 while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
1382 bl = BLOCK_SUPERBLOCK (bl);
1384 return BLOCK_FUNCTION (bl);
1387 /* Find the symtab associated with PC and SECTION. Look through the
1388 psymtabs and read in another symtab if necessary. */
1391 find_pc_sect_symtab (CORE_ADDR pc, asection *section)
1393 register struct block *b;
1394 struct blockvector *bv;
1395 register struct symtab *s = NULL;
1396 register struct symtab *best_s = NULL;
1397 register struct partial_symtab *ps;
1398 register struct objfile *objfile;
1399 CORE_ADDR distance = 0;
1400 struct minimal_symbol *msymbol;
1402 /* If we know that this is not a text address, return failure. This is
1403 necessary because we loop based on the block's high and low code
1404 addresses, which do not include the data ranges, and because
1405 we call find_pc_sect_psymtab which has a similar restriction based
1406 on the partial_symtab's texthigh and textlow. */
1407 msymbol = lookup_minimal_symbol_by_pc_section (pc, section);
1409 && (msymbol->type == mst_data
1410 || msymbol->type == mst_bss
1411 || msymbol->type == mst_abs
1412 || msymbol->type == mst_file_data
1413 || msymbol->type == mst_file_bss))
1416 /* Search all symtabs for the one whose file contains our address, and which
1417 is the smallest of all the ones containing the address. This is designed
1418 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1419 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1420 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1422 This happens for native ecoff format, where code from included files
1423 gets its own symtab. The symtab for the included file should have
1424 been read in already via the dependency mechanism.
1425 It might be swifter to create several symtabs with the same name
1426 like xcoff does (I'm not sure).
1428 It also happens for objfiles that have their functions reordered.
1429 For these, the symtab we are looking for is not necessarily read in. */
1431 ALL_SYMTABS (objfile, s)
1433 bv = BLOCKVECTOR (s);
1434 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1436 if (BLOCK_START (b) <= pc
1437 && BLOCK_END (b) > pc
1439 || BLOCK_END (b) - BLOCK_START (b) < distance))
1441 /* For an objfile that has its functions reordered,
1442 find_pc_psymtab will find the proper partial symbol table
1443 and we simply return its corresponding symtab. */
1444 /* In order to better support objfiles that contain both
1445 stabs and coff debugging info, we continue on if a psymtab
1447 if ((objfile->flags & OBJF_REORDERED) && objfile->psymtabs)
1449 ps = find_pc_sect_psymtab (pc, section);
1451 return PSYMTAB_TO_SYMTAB (ps);
1457 for (i = 0; i < b->nsyms; i++)
1459 fixup_symbol_section (b->sym[i], objfile);
1460 if (section == SYMBOL_BFD_SECTION (b->sym[i]))
1464 continue; /* no symbol in this symtab matches section */
1466 distance = BLOCK_END (b) - BLOCK_START (b);
1475 ps = find_pc_sect_psymtab (pc, section);
1479 /* Might want to error() here (in case symtab is corrupt and
1480 will cause a core dump), but maybe we can successfully
1481 continue, so let's not. */
1483 (Internal error: pc 0x%s in read in psymtab, but not in symtab.)\n",
1485 s = PSYMTAB_TO_SYMTAB (ps);
1490 /* Find the symtab associated with PC. Look through the psymtabs and
1491 read in another symtab if necessary. Backward compatibility, no section */
1494 find_pc_symtab (CORE_ADDR pc)
1496 return find_pc_sect_symtab (pc, find_pc_mapped_section (pc));
1502 /* Find the closest symbol value (of any sort -- function or variable)
1503 for a given address value. Slow but complete. (currently unused,
1504 mainly because it is too slow. We could fix it if each symtab and
1505 psymtab had contained in it the addresses ranges of each of its
1506 sections, which also would be required to make things like "info
1507 line *0x2345" cause psymtabs to be converted to symtabs). */
1510 find_addr_symbol (CORE_ADDR addr, struct symtab **symtabp, CORE_ADDR *symaddrp)
1512 struct symtab *symtab, *best_symtab;
1513 struct objfile *objfile;
1514 register int bot, top;
1515 register struct symbol *sym;
1516 register CORE_ADDR sym_addr;
1517 struct block *block;
1520 /* Info on best symbol seen so far */
1522 register CORE_ADDR best_sym_addr = 0;
1523 struct symbol *best_sym = 0;
1525 /* FIXME -- we should pull in all the psymtabs, too! */
1526 ALL_SYMTABS (objfile, symtab)
1528 /* Search the global and static blocks in this symtab for
1529 the closest symbol-address to the desired address. */
1531 for (blocknum = GLOBAL_BLOCK; blocknum <= STATIC_BLOCK; blocknum++)
1534 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), blocknum);
1535 top = BLOCK_NSYMS (block);
1536 for (bot = 0; bot < top; bot++)
1538 sym = BLOCK_SYM (block, bot);
1539 switch (SYMBOL_CLASS (sym))
1543 sym_addr = SYMBOL_VALUE_ADDRESS (sym);
1547 sym_addr = SYMBOL_VALUE_ADDRESS (sym);
1548 /* An indirect symbol really lives at *sym_addr,
1549 * so an indirection needs to be done.
1550 * However, I am leaving this commented out because it's
1551 * expensive, and it's possible that symbolization
1552 * could be done without an active process (in
1553 * case this read_memory will fail). RT
1554 sym_addr = read_memory_unsigned_integer
1555 (sym_addr, TARGET_PTR_BIT / TARGET_CHAR_BIT);
1560 sym_addr = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
1567 if (sym_addr <= addr)
1568 if (sym_addr > best_sym_addr)
1570 /* Quit if we found an exact match. */
1572 best_sym_addr = sym_addr;
1573 best_symtab = symtab;
1574 if (sym_addr == addr)
1583 *symtabp = best_symtab;
1585 *symaddrp = best_sym_addr;
1590 /* Find the source file and line number for a given PC value and SECTION.
1591 Return a structure containing a symtab pointer, a line number,
1592 and a pc range for the entire source line.
1593 The value's .pc field is NOT the specified pc.
1594 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1595 use the line that ends there. Otherwise, in that case, the line
1596 that begins there is used. */
1598 /* The big complication here is that a line may start in one file, and end just
1599 before the start of another file. This usually occurs when you #include
1600 code in the middle of a subroutine. To properly find the end of a line's PC
1601 range, we must search all symtabs associated with this compilation unit, and
1602 find the one whose first PC is closer than that of the next line in this
1605 /* If it's worth the effort, we could be using a binary search. */
1607 struct symtab_and_line
1608 find_pc_sect_line (CORE_ADDR pc, struct sec *section, int notcurrent)
1611 register struct linetable *l;
1614 register struct linetable_entry *item;
1615 struct symtab_and_line val;
1616 struct blockvector *bv;
1617 struct minimal_symbol *msymbol;
1618 struct minimal_symbol *mfunsym;
1620 /* Info on best line seen so far, and where it starts, and its file. */
1622 struct linetable_entry *best = NULL;
1623 CORE_ADDR best_end = 0;
1624 struct symtab *best_symtab = 0;
1626 /* Store here the first line number
1627 of a file which contains the line at the smallest pc after PC.
1628 If we don't find a line whose range contains PC,
1629 we will use a line one less than this,
1630 with a range from the start of that file to the first line's pc. */
1631 struct linetable_entry *alt = NULL;
1632 struct symtab *alt_symtab = 0;
1634 /* Info on best line seen in this file. */
1636 struct linetable_entry *prev;
1638 /* If this pc is not from the current frame,
1639 it is the address of the end of a call instruction.
1640 Quite likely that is the start of the following statement.
1641 But what we want is the statement containing the instruction.
1642 Fudge the pc to make sure we get that. */
1644 INIT_SAL (&val); /* initialize to zeroes */
1646 /* It's tempting to assume that, if we can't find debugging info for
1647 any function enclosing PC, that we shouldn't search for line
1648 number info, either. However, GAS can emit line number info for
1649 assembly files --- very helpful when debugging hand-written
1650 assembly code. In such a case, we'd have no debug info for the
1651 function, but we would have line info. */
1656 /* elz: added this because this function returned the wrong
1657 information if the pc belongs to a stub (import/export)
1658 to call a shlib function. This stub would be anywhere between
1659 two functions in the target, and the line info was erroneously
1660 taken to be the one of the line before the pc.
1662 /* RT: Further explanation:
1664 * We have stubs (trampolines) inserted between procedures.
1666 * Example: "shr1" exists in a shared library, and a "shr1" stub also
1667 * exists in the main image.
1669 * In the minimal symbol table, we have a bunch of symbols
1670 * sorted by start address. The stubs are marked as "trampoline",
1671 * the others appear as text. E.g.:
1673 * Minimal symbol table for main image
1674 * main: code for main (text symbol)
1675 * shr1: stub (trampoline symbol)
1676 * foo: code for foo (text symbol)
1678 * Minimal symbol table for "shr1" image:
1680 * shr1: code for shr1 (text symbol)
1683 * So the code below is trying to detect if we are in the stub
1684 * ("shr1" stub), and if so, find the real code ("shr1" trampoline),
1685 * and if found, do the symbolization from the real-code address
1686 * rather than the stub address.
1688 * Assumptions being made about the minimal symbol table:
1689 * 1. lookup_minimal_symbol_by_pc() will return a trampoline only
1690 * if we're really in the trampoline. If we're beyond it (say
1691 * we're in "foo" in the above example), it'll have a closer
1692 * symbol (the "foo" text symbol for example) and will not
1693 * return the trampoline.
1694 * 2. lookup_minimal_symbol_text() will find a real text symbol
1695 * corresponding to the trampoline, and whose address will
1696 * be different than the trampoline address. I put in a sanity
1697 * check for the address being the same, to avoid an
1698 * infinite recursion.
1700 msymbol = lookup_minimal_symbol_by_pc (pc);
1701 if (msymbol != NULL)
1702 if (MSYMBOL_TYPE (msymbol) == mst_solib_trampoline)
1704 mfunsym = lookup_minimal_symbol_text (SYMBOL_NAME (msymbol), NULL, NULL);
1705 if (mfunsym == NULL)
1706 /* I eliminated this warning since it is coming out
1707 * in the following situation:
1708 * gdb shmain // test program with shared libraries
1709 * (gdb) break shr1 // function in shared lib
1710 * Warning: In stub for ...
1711 * In the above situation, the shared lib is not loaded yet,
1712 * so of course we can't find the real func/line info,
1713 * but the "break" still works, and the warning is annoying.
1714 * So I commented out the warning. RT */
1715 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_NAME(msymbol)) */ ;
1717 else if (SYMBOL_VALUE (mfunsym) == SYMBOL_VALUE (msymbol))
1718 /* Avoid infinite recursion */
1719 /* See above comment about why warning is commented out */
1720 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_NAME(msymbol)) */ ;
1723 return find_pc_line (SYMBOL_VALUE (mfunsym), 0);
1727 s = find_pc_sect_symtab (pc, section);
1730 /* if no symbol information, return previous pc */
1737 bv = BLOCKVECTOR (s);
1739 /* Look at all the symtabs that share this blockvector.
1740 They all have the same apriori range, that we found was right;
1741 but they have different line tables. */
1743 for (; s && BLOCKVECTOR (s) == bv; s = s->next)
1745 /* Find the best line in this symtab. */
1752 /* I think len can be zero if the symtab lacks line numbers
1753 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
1754 I'm not sure which, and maybe it depends on the symbol
1760 item = l->item; /* Get first line info */
1762 /* Is this file's first line closer than the first lines of other files?
1763 If so, record this file, and its first line, as best alternate. */
1764 if (item->pc > pc && (!alt || item->pc < alt->pc))
1770 for (i = 0; i < len; i++, item++)
1772 /* Leave prev pointing to the linetable entry for the last line
1773 that started at or before PC. */
1780 /* At this point, prev points at the line whose start addr is <= pc, and
1781 item points at the next line. If we ran off the end of the linetable
1782 (pc >= start of the last line), then prev == item. If pc < start of
1783 the first line, prev will not be set. */
1785 /* Is this file's best line closer than the best in the other files?
1786 If so, record this file, and its best line, as best so far. */
1788 if (prev && (!best || prev->pc > best->pc))
1793 /* Discard BEST_END if it's before the PC of the current BEST. */
1794 if (best_end <= best->pc)
1798 /* If another line (denoted by ITEM) is in the linetable and its
1799 PC is after BEST's PC, but before the current BEST_END, then
1800 use ITEM's PC as the new best_end. */
1801 if (best && i < len && item->pc > best->pc
1802 && (best_end == 0 || best_end > item->pc))
1803 best_end = item->pc;
1809 { /* If we didn't find any line # info, just
1815 val.symtab = alt_symtab;
1816 val.line = alt->line - 1;
1818 /* Don't return line 0, that means that we didn't find the line. */
1822 val.pc = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1828 val.symtab = best_symtab;
1829 val.line = best->line;
1831 if (best_end && (!alt || best_end < alt->pc))
1836 val.end = BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
1838 val.section = section;
1842 /* Backward compatibility (no section) */
1844 struct symtab_and_line
1845 find_pc_line (CORE_ADDR pc, int notcurrent)
1849 section = find_pc_overlay (pc);
1850 if (pc_in_unmapped_range (pc, section))
1851 pc = overlay_mapped_address (pc, section);
1852 return find_pc_sect_line (pc, section, notcurrent);
1855 /* Find line number LINE in any symtab whose name is the same as
1858 If found, return the symtab that contains the linetable in which it was
1859 found, set *INDEX to the index in the linetable of the best entry
1860 found, and set *EXACT_MATCH nonzero if the value returned is an
1863 If not found, return NULL. */
1866 find_line_symtab (struct symtab *symtab, int line, int *index, int *exact_match)
1870 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
1874 struct linetable *best_linetable;
1875 struct symtab *best_symtab;
1877 /* First try looking it up in the given symtab. */
1878 best_linetable = LINETABLE (symtab);
1879 best_symtab = symtab;
1880 best_index = find_line_common (best_linetable, line, &exact);
1881 if (best_index < 0 || !exact)
1883 /* Didn't find an exact match. So we better keep looking for
1884 another symtab with the same name. In the case of xcoff,
1885 multiple csects for one source file (produced by IBM's FORTRAN
1886 compiler) produce multiple symtabs (this is unavoidable
1887 assuming csects can be at arbitrary places in memory and that
1888 the GLOBAL_BLOCK of a symtab has a begin and end address). */
1890 /* BEST is the smallest linenumber > LINE so far seen,
1891 or 0 if none has been seen so far.
1892 BEST_INDEX and BEST_LINETABLE identify the item for it. */
1895 struct objfile *objfile;
1898 if (best_index >= 0)
1899 best = best_linetable->item[best_index].line;
1903 ALL_SYMTABS (objfile, s)
1905 struct linetable *l;
1908 if (!STREQ (symtab->filename, s->filename))
1911 ind = find_line_common (l, line, &exact);
1921 if (best == 0 || l->item[ind].line < best)
1923 best = l->item[ind].line;
1936 *index = best_index;
1938 *exact_match = exact;
1943 /* Set the PC value for a given source file and line number and return true.
1944 Returns zero for invalid line number (and sets the PC to 0).
1945 The source file is specified with a struct symtab. */
1948 find_line_pc (struct symtab *symtab, int line, CORE_ADDR *pc)
1950 struct linetable *l;
1957 symtab = find_line_symtab (symtab, line, &ind, NULL);
1960 l = LINETABLE (symtab);
1961 *pc = l->item[ind].pc;
1968 /* Find the range of pc values in a line.
1969 Store the starting pc of the line into *STARTPTR
1970 and the ending pc (start of next line) into *ENDPTR.
1971 Returns 1 to indicate success.
1972 Returns 0 if could not find the specified line. */
1975 find_line_pc_range (struct symtab_and_line sal, CORE_ADDR *startptr,
1978 CORE_ADDR startaddr;
1979 struct symtab_and_line found_sal;
1982 if (startaddr == 0 && !find_line_pc (sal.symtab, sal.line, &startaddr))
1985 /* This whole function is based on address. For example, if line 10 has
1986 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
1987 "info line *0x123" should say the line goes from 0x100 to 0x200
1988 and "info line *0x355" should say the line goes from 0x300 to 0x400.
1989 This also insures that we never give a range like "starts at 0x134
1990 and ends at 0x12c". */
1992 found_sal = find_pc_sect_line (startaddr, sal.section, 0);
1993 if (found_sal.line != sal.line)
1995 /* The specified line (sal) has zero bytes. */
1996 *startptr = found_sal.pc;
1997 *endptr = found_sal.pc;
2001 *startptr = found_sal.pc;
2002 *endptr = found_sal.end;
2007 /* Given a line table and a line number, return the index into the line
2008 table for the pc of the nearest line whose number is >= the specified one.
2009 Return -1 if none is found. The value is >= 0 if it is an index.
2011 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
2014 find_line_common (register struct linetable *l, register int lineno,
2020 /* BEST is the smallest linenumber > LINENO so far seen,
2021 or 0 if none has been seen so far.
2022 BEST_INDEX identifies the item for it. */
2024 int best_index = -1;
2033 for (i = 0; i < len; i++)
2035 register struct linetable_entry *item = &(l->item[i]);
2037 if (item->line == lineno)
2039 /* Return the first (lowest address) entry which matches. */
2044 if (item->line > lineno && (best == 0 || item->line < best))
2051 /* If we got here, we didn't get an exact match. */
2058 find_pc_line_pc_range (CORE_ADDR pc, CORE_ADDR *startptr, CORE_ADDR *endptr)
2060 struct symtab_and_line sal;
2061 sal = find_pc_line (pc, 0);
2064 return sal.symtab != 0;
2067 /* Given a function symbol SYM, find the symtab and line for the start
2069 If the argument FUNFIRSTLINE is nonzero, we want the first line
2070 of real code inside the function. */
2072 struct symtab_and_line
2073 find_function_start_sal (struct symbol *sym, int funfirstline)
2076 struct symtab_and_line sal;
2078 pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym));
2079 fixup_symbol_section (sym, NULL);
2081 { /* skip "first line" of function (which is actually its prologue) */
2082 asection *section = SYMBOL_BFD_SECTION (sym);
2083 /* If function is in an unmapped overlay, use its unmapped LMA
2084 address, so that SKIP_PROLOGUE has something unique to work on */
2085 if (section_is_overlay (section) &&
2086 !section_is_mapped (section))
2087 pc = overlay_unmapped_address (pc, section);
2089 pc += FUNCTION_START_OFFSET;
2090 pc = SKIP_PROLOGUE (pc);
2092 /* For overlays, map pc back into its mapped VMA range */
2093 pc = overlay_mapped_address (pc, section);
2095 sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0);
2097 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2098 /* Convex: no need to suppress code on first line, if any */
2101 /* Check if SKIP_PROLOGUE left us in mid-line, and the next
2102 line is still part of the same function. */
2104 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) <= sal.end
2105 && sal.end < BLOCK_END (SYMBOL_BLOCK_VALUE (sym)))
2107 /* First pc of next line */
2109 /* Recalculate the line number (might not be N+1). */
2110 sal = find_pc_sect_line (pc, SYMBOL_BFD_SECTION (sym), 0);
2118 /* If P is of the form "operator[ \t]+..." where `...' is
2119 some legitimate operator text, return a pointer to the
2120 beginning of the substring of the operator text.
2121 Otherwise, return "". */
2123 operator_chars (char *p, char **end)
2126 if (strncmp (p, "operator", 8))
2130 /* Don't get faked out by `operator' being part of a longer
2132 if (isalpha (*p) || *p == '_' || *p == '$' || *p == '\0')
2135 /* Allow some whitespace between `operator' and the operator symbol. */
2136 while (*p == ' ' || *p == '\t')
2139 /* Recognize 'operator TYPENAME'. */
2141 if (isalpha (*p) || *p == '_' || *p == '$')
2143 register char *q = p + 1;
2144 while (isalnum (*q) || *q == '_' || *q == '$')
2153 case '\\': /* regexp quoting */
2156 if (p[2] == '=') /* 'operator\*=' */
2158 else /* 'operator\*' */
2162 else if (p[1] == '[')
2165 error ("mismatched quoting on brackets, try 'operator\\[\\]'");
2166 else if (p[2] == '\\' && p[3] == ']')
2168 *end = p + 4; /* 'operator\[\]' */
2172 error ("nothing is allowed between '[' and ']'");
2176 /* Gratuitous qoute: skip it and move on. */
2198 if (p[0] == '-' && p[1] == '>')
2200 /* Struct pointer member operator 'operator->'. */
2203 *end = p + 3; /* 'operator->*' */
2206 else if (p[2] == '\\')
2208 *end = p + 4; /* Hopefully 'operator->\*' */
2213 *end = p + 2; /* 'operator->' */
2217 if (p[1] == '=' || p[1] == p[0])
2228 error ("`operator ()' must be specified without whitespace in `()'");
2233 error ("`operator ?:' must be specified without whitespace in `?:'");
2238 error ("`operator []' must be specified without whitespace in `[]'");
2242 error ("`operator %s' not supported", p);
2251 /* If FILE is not already in the table of files, return zero;
2252 otherwise return non-zero. Optionally add FILE to the table if ADD
2253 is non-zero. If *FIRST is non-zero, forget the old table
2256 filename_seen (const char *file, int add, int *first)
2258 /* Table of files seen so far. */
2259 static const char **tab = NULL;
2260 /* Allocated size of tab in elements.
2261 Start with one 256-byte block (when using GNU malloc.c).
2262 24 is the malloc overhead when range checking is in effect. */
2263 static int tab_alloc_size = (256 - 24) / sizeof (char *);
2264 /* Current size of tab in elements. */
2265 static int tab_cur_size;
2271 tab = (const char **) xmalloc (tab_alloc_size * sizeof (*tab));
2275 /* Is FILE in tab? */
2276 for (p = tab; p < tab + tab_cur_size; p++)
2277 if (strcmp (*p, file) == 0)
2280 /* No; maybe add it to tab. */
2283 if (tab_cur_size == tab_alloc_size)
2285 tab_alloc_size *= 2;
2286 tab = (const char **) xrealloc ((char *) tab,
2287 tab_alloc_size * sizeof (*tab));
2289 tab[tab_cur_size++] = file;
2295 /* Slave routine for sources_info. Force line breaks at ,'s.
2296 NAME is the name to print and *FIRST is nonzero if this is the first
2297 name printed. Set *FIRST to zero. */
2299 output_source_filename (char *name, int *first)
2301 /* Since a single source file can result in several partial symbol
2302 tables, we need to avoid printing it more than once. Note: if
2303 some of the psymtabs are read in and some are not, it gets
2304 printed both under "Source files for which symbols have been
2305 read" and "Source files for which symbols will be read in on
2306 demand". I consider this a reasonable way to deal with the
2307 situation. I'm not sure whether this can also happen for
2308 symtabs; it doesn't hurt to check. */
2310 /* Was NAME already seen? */
2311 if (filename_seen (name, 1, first))
2313 /* Yes; don't print it again. */
2316 /* No; print it and reset *FIRST. */
2323 printf_filtered (", ");
2327 fputs_filtered (name, gdb_stdout);
2331 sources_info (char *ignore, int from_tty)
2333 register struct symtab *s;
2334 register struct partial_symtab *ps;
2335 register struct objfile *objfile;
2338 if (!have_full_symbols () && !have_partial_symbols ())
2340 error ("No symbol table is loaded. Use the \"file\" command.");
2343 printf_filtered ("Source files for which symbols have been read in:\n\n");
2346 ALL_SYMTABS (objfile, s)
2348 output_source_filename (s->filename, &first);
2350 printf_filtered ("\n\n");
2352 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2355 ALL_PSYMTABS (objfile, ps)
2359 output_source_filename (ps->filename, &first);
2362 printf_filtered ("\n");
2366 file_matches (char *file, char *files[], int nfiles)
2370 if (file != NULL && nfiles != 0)
2372 for (i = 0; i < nfiles; i++)
2374 if (strcmp (files[i], lbasename (file)) == 0)
2378 else if (nfiles == 0)
2383 /* Free any memory associated with a search. */
2385 free_search_symbols (struct symbol_search *symbols)
2387 struct symbol_search *p;
2388 struct symbol_search *next;
2390 for (p = symbols; p != NULL; p = next)
2398 do_free_search_symbols_cleanup (void *symbols)
2400 free_search_symbols (symbols);
2404 make_cleanup_free_search_symbols (struct symbol_search *symbols)
2406 return make_cleanup (do_free_search_symbols_cleanup, symbols);
2410 /* Search the symbol table for matches to the regular expression REGEXP,
2411 returning the results in *MATCHES.
2413 Only symbols of KIND are searched:
2414 FUNCTIONS_NAMESPACE - search all functions
2415 TYPES_NAMESPACE - search all type names
2416 METHODS_NAMESPACE - search all methods NOT IMPLEMENTED
2417 VARIABLES_NAMESPACE - search all symbols, excluding functions, type names,
2418 and constants (enums)
2420 free_search_symbols should be called when *MATCHES is no longer needed.
2423 search_symbols (char *regexp, namespace_enum kind, int nfiles, char *files[],
2424 struct symbol_search **matches)
2426 register struct symtab *s;
2427 register struct partial_symtab *ps;
2428 register struct blockvector *bv;
2429 struct blockvector *prev_bv = 0;
2430 register struct block *b;
2433 register struct symbol *sym;
2434 struct partial_symbol **psym;
2435 struct objfile *objfile;
2436 struct minimal_symbol *msymbol;
2439 static enum minimal_symbol_type types[]
2441 {mst_data, mst_text, mst_abs, mst_unknown};
2442 static enum minimal_symbol_type types2[]
2444 {mst_bss, mst_file_text, mst_abs, mst_unknown};
2445 static enum minimal_symbol_type types3[]
2447 {mst_file_data, mst_solib_trampoline, mst_abs, mst_unknown};
2448 static enum minimal_symbol_type types4[]
2450 {mst_file_bss, mst_text, mst_abs, mst_unknown};
2451 enum minimal_symbol_type ourtype;
2452 enum minimal_symbol_type ourtype2;
2453 enum minimal_symbol_type ourtype3;
2454 enum minimal_symbol_type ourtype4;
2455 struct symbol_search *sr;
2456 struct symbol_search *psr;
2457 struct symbol_search *tail;
2458 struct cleanup *old_chain = NULL;
2460 if (kind < VARIABLES_NAMESPACE)
2461 error ("must search on specific namespace");
2463 ourtype = types[(int) (kind - VARIABLES_NAMESPACE)];
2464 ourtype2 = types2[(int) (kind - VARIABLES_NAMESPACE)];
2465 ourtype3 = types3[(int) (kind - VARIABLES_NAMESPACE)];
2466 ourtype4 = types4[(int) (kind - VARIABLES_NAMESPACE)];
2468 sr = *matches = NULL;
2473 /* Make sure spacing is right for C++ operators.
2474 This is just a courtesy to make the matching less sensitive
2475 to how many spaces the user leaves between 'operator'
2476 and <TYPENAME> or <OPERATOR>. */
2478 char *opname = operator_chars (regexp, &opend);
2481 int fix = -1; /* -1 means ok; otherwise number of spaces needed. */
2482 if (isalpha (*opname) || *opname == '_' || *opname == '$')
2484 /* There should 1 space between 'operator' and 'TYPENAME'. */
2485 if (opname[-1] != ' ' || opname[-2] == ' ')
2490 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2491 if (opname[-1] == ' ')
2494 /* If wrong number of spaces, fix it. */
2497 char *tmp = (char *) alloca (8 + fix + strlen (opname) + 1);
2498 sprintf (tmp, "operator%.*s%s", fix, " ", opname);
2503 if (0 != (val = re_comp (regexp)))
2504 error ("Invalid regexp (%s): %s", val, regexp);
2507 /* Search through the partial symtabs *first* for all symbols
2508 matching the regexp. That way we don't have to reproduce all of
2509 the machinery below. */
2511 ALL_PSYMTABS (objfile, ps)
2513 struct partial_symbol **bound, **gbound, **sbound;
2519 gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms;
2520 sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms;
2523 /* Go through all of the symbols stored in a partial
2524 symtab in one loop. */
2525 psym = objfile->global_psymbols.list + ps->globals_offset;
2530 if (bound == gbound && ps->n_static_syms != 0)
2532 psym = objfile->static_psymbols.list + ps->statics_offset;
2543 /* If it would match (logic taken from loop below)
2544 load the file and go on to the next one */
2545 if (file_matches (ps->filename, files, nfiles)
2546 && ((regexp == NULL || SYMBOL_MATCHES_REGEXP (*psym))
2547 && ((kind == VARIABLES_NAMESPACE && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
2548 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
2549 || (kind == FUNCTIONS_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_BLOCK)
2550 || (kind == TYPES_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_TYPEDEF)
2551 || (kind == METHODS_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_BLOCK))))
2553 PSYMTAB_TO_SYMTAB (ps);
2561 /* Here, we search through the minimal symbol tables for functions
2562 and variables that match, and force their symbols to be read.
2563 This is in particular necessary for demangled variable names,
2564 which are no longer put into the partial symbol tables.
2565 The symbol will then be found during the scan of symtabs below.
2567 For functions, find_pc_symtab should succeed if we have debug info
2568 for the function, for variables we have to call lookup_symbol
2569 to determine if the variable has debug info.
2570 If the lookup fails, set found_misc so that we will rescan to print
2571 any matching symbols without debug info.
2574 if (nfiles == 0 && (kind == VARIABLES_NAMESPACE || kind == FUNCTIONS_NAMESPACE))
2576 ALL_MSYMBOLS (objfile, msymbol)
2578 if (MSYMBOL_TYPE (msymbol) == ourtype ||
2579 MSYMBOL_TYPE (msymbol) == ourtype2 ||
2580 MSYMBOL_TYPE (msymbol) == ourtype3 ||
2581 MSYMBOL_TYPE (msymbol) == ourtype4)
2583 if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol))
2585 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)))
2587 if (kind == FUNCTIONS_NAMESPACE
2588 || lookup_symbol (SYMBOL_NAME (msymbol),
2589 (struct block *) NULL,
2591 0, (struct symtab **) NULL) == NULL)
2599 ALL_SYMTABS (objfile, s)
2601 bv = BLOCKVECTOR (s);
2602 /* Often many files share a blockvector.
2603 Scan each blockvector only once so that
2604 we don't get every symbol many times.
2605 It happens that the first symtab in the list
2606 for any given blockvector is the main file. */
2608 for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
2610 b = BLOCKVECTOR_BLOCK (bv, i);
2611 /* Skip the sort if this block is always sorted. */
2612 if (!BLOCK_SHOULD_SORT (b))
2613 sort_block_syms (b);
2614 for (j = 0; j < BLOCK_NSYMS (b); j++)
2617 sym = BLOCK_SYM (b, j);
2618 if (file_matches (s->filename, files, nfiles)
2619 && ((regexp == NULL || SYMBOL_MATCHES_REGEXP (sym))
2620 && ((kind == VARIABLES_NAMESPACE && SYMBOL_CLASS (sym) != LOC_TYPEDEF
2621 && SYMBOL_CLASS (sym) != LOC_BLOCK
2622 && SYMBOL_CLASS (sym) != LOC_CONST)
2623 || (kind == FUNCTIONS_NAMESPACE && SYMBOL_CLASS (sym) == LOC_BLOCK)
2624 || (kind == TYPES_NAMESPACE && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
2625 || (kind == METHODS_NAMESPACE && SYMBOL_CLASS (sym) == LOC_BLOCK))))
2628 psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search));
2632 psr->msymbol = NULL;
2637 old_chain = make_cleanup_free_search_symbols (sr);
2648 /* If there are no eyes, avoid all contact. I mean, if there are
2649 no debug symbols, then print directly from the msymbol_vector. */
2651 if (found_misc || kind != FUNCTIONS_NAMESPACE)
2653 ALL_MSYMBOLS (objfile, msymbol)
2655 if (MSYMBOL_TYPE (msymbol) == ourtype ||
2656 MSYMBOL_TYPE (msymbol) == ourtype2 ||
2657 MSYMBOL_TYPE (msymbol) == ourtype3 ||
2658 MSYMBOL_TYPE (msymbol) == ourtype4)
2660 if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol))
2662 /* Functions: Look up by address. */
2663 if (kind != FUNCTIONS_NAMESPACE ||
2664 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol))))
2666 /* Variables/Absolutes: Look up by name */
2667 if (lookup_symbol (SYMBOL_NAME (msymbol),
2668 (struct block *) NULL, VAR_NAMESPACE,
2669 0, (struct symtab **) NULL) == NULL)
2672 psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search));
2674 psr->msymbol = msymbol;
2681 old_chain = make_cleanup_free_search_symbols (sr);
2695 discard_cleanups (old_chain);
2698 /* Helper function for symtab_symbol_info, this function uses
2699 the data returned from search_symbols() to print information
2700 regarding the match to gdb_stdout.
2703 print_symbol_info (namespace_enum kind, struct symtab *s, struct symbol *sym,
2704 int block, char *last)
2706 if (last == NULL || strcmp (last, s->filename) != 0)
2708 fputs_filtered ("\nFile ", gdb_stdout);
2709 fputs_filtered (s->filename, gdb_stdout);
2710 fputs_filtered (":\n", gdb_stdout);
2713 if (kind != TYPES_NAMESPACE && block == STATIC_BLOCK)
2714 printf_filtered ("static ");
2716 /* Typedef that is not a C++ class */
2717 if (kind == TYPES_NAMESPACE
2718 && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
2719 typedef_print (SYMBOL_TYPE (sym), sym, gdb_stdout);
2720 /* variable, func, or typedef-that-is-c++-class */
2721 else if (kind < TYPES_NAMESPACE ||
2722 (kind == TYPES_NAMESPACE &&
2723 SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE))
2725 type_print (SYMBOL_TYPE (sym),
2726 (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2727 ? "" : SYMBOL_SOURCE_NAME (sym)),
2730 printf_filtered (";\n");
2735 /* Tiemann says: "info methods was never implemented." */
2736 char *demangled_name;
2737 c_type_print_base (TYPE_FN_FIELD_TYPE (t, block),
2739 c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (t, block),
2741 if (TYPE_FN_FIELD_STUB (t, block))
2742 check_stub_method (TYPE_DOMAIN_TYPE (type), j, block);
2744 cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t, block),
2745 DMGL_ANSI | DMGL_PARAMS);
2746 if (demangled_name == NULL)
2747 fprintf_filtered (stream, "<badly mangled name %s>",
2748 TYPE_FN_FIELD_PHYSNAME (t, block));
2751 fputs_filtered (demangled_name, stream);
2752 xfree (demangled_name);
2758 /* This help function for symtab_symbol_info() prints information
2759 for non-debugging symbols to gdb_stdout.
2762 print_msymbol_info (struct minimal_symbol *msymbol)
2766 if (TARGET_ADDR_BIT <= 32)
2767 tmp = longest_local_hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol)
2768 & (CORE_ADDR) 0xffffffff,
2771 tmp = longest_local_hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol),
2773 printf_filtered ("%s %s\n",
2774 tmp, SYMBOL_SOURCE_NAME (msymbol));
2777 /* This is the guts of the commands "info functions", "info types", and
2778 "info variables". It calls search_symbols to find all matches and then
2779 print_[m]symbol_info to print out some useful information about the
2783 symtab_symbol_info (char *regexp, namespace_enum kind, int from_tty)
2785 static char *classnames[]
2787 {"variable", "function", "type", "method"};
2788 struct symbol_search *symbols;
2789 struct symbol_search *p;
2790 struct cleanup *old_chain;
2791 char *last_filename = NULL;
2794 /* must make sure that if we're interrupted, symbols gets freed */
2795 search_symbols (regexp, kind, 0, (char **) NULL, &symbols);
2796 old_chain = make_cleanup_free_search_symbols (symbols);
2798 printf_filtered (regexp
2799 ? "All %ss matching regular expression \"%s\":\n"
2800 : "All defined %ss:\n",
2801 classnames[(int) (kind - VARIABLES_NAMESPACE)], regexp);
2803 for (p = symbols; p != NULL; p = p->next)
2807 if (p->msymbol != NULL)
2811 printf_filtered ("\nNon-debugging symbols:\n");
2814 print_msymbol_info (p->msymbol);
2818 print_symbol_info (kind,
2823 last_filename = p->symtab->filename;
2827 do_cleanups (old_chain);
2831 variables_info (char *regexp, int from_tty)
2833 symtab_symbol_info (regexp, VARIABLES_NAMESPACE, from_tty);
2837 functions_info (char *regexp, int from_tty)
2839 symtab_symbol_info (regexp, FUNCTIONS_NAMESPACE, from_tty);
2844 types_info (char *regexp, int from_tty)
2846 symtab_symbol_info (regexp, TYPES_NAMESPACE, from_tty);
2850 /* Tiemann says: "info methods was never implemented." */
2852 methods_info (char *regexp)
2854 symtab_symbol_info (regexp, METHODS_NAMESPACE, 0, from_tty);
2858 /* Breakpoint all functions matching regular expression. */
2861 rbreak_command_wrapper (char *regexp, int from_tty)
2863 rbreak_command (regexp, from_tty);
2867 rbreak_command (char *regexp, int from_tty)
2869 struct symbol_search *ss;
2870 struct symbol_search *p;
2871 struct cleanup *old_chain;
2873 search_symbols (regexp, FUNCTIONS_NAMESPACE, 0, (char **) NULL, &ss);
2874 old_chain = make_cleanup_free_search_symbols (ss);
2876 for (p = ss; p != NULL; p = p->next)
2878 if (p->msymbol == NULL)
2880 char *string = (char *) alloca (strlen (p->symtab->filename)
2881 + strlen (SYMBOL_NAME (p->symbol))
2883 strcpy (string, p->symtab->filename);
2884 strcat (string, ":'");
2885 strcat (string, SYMBOL_NAME (p->symbol));
2886 strcat (string, "'");
2887 break_command (string, from_tty);
2888 print_symbol_info (FUNCTIONS_NAMESPACE,
2892 p->symtab->filename);
2896 break_command (SYMBOL_NAME (p->msymbol), from_tty);
2897 printf_filtered ("<function, no debug info> %s;\n",
2898 SYMBOL_SOURCE_NAME (p->msymbol));
2902 do_cleanups (old_chain);
2906 /* Return Nonzero if block a is lexically nested within block b,
2907 or if a and b have the same pc range.
2908 Return zero otherwise. */
2910 contained_in (struct block *a, struct block *b)
2914 return BLOCK_START (a) >= BLOCK_START (b)
2915 && BLOCK_END (a) <= BLOCK_END (b);
2919 /* Helper routine for make_symbol_completion_list. */
2921 static int return_val_size;
2922 static int return_val_index;
2923 static char **return_val;
2925 #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
2927 if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \
2928 /* Put only the mangled name on the list. */ \
2929 /* Advantage: "b foo<TAB>" completes to "b foo(int, int)" */ \
2930 /* Disadvantage: "b foo__i<TAB>" doesn't complete. */ \
2931 completion_list_add_name \
2932 (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \
2934 completion_list_add_name \
2935 (SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \
2938 /* Test to see if the symbol specified by SYMNAME (which is already
2939 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
2940 characters. If so, add it to the current completion list. */
2943 completion_list_add_name (char *symname, char *sym_text, int sym_text_len,
2944 char *text, char *word)
2949 /* clip symbols that cannot match */
2951 if (strncmp (symname, sym_text, sym_text_len) != 0)
2956 /* We have a match for a completion, so add SYMNAME to the current list
2957 of matches. Note that the name is moved to freshly malloc'd space. */
2961 if (word == sym_text)
2963 new = xmalloc (strlen (symname) + 5);
2964 strcpy (new, symname);
2966 else if (word > sym_text)
2968 /* Return some portion of symname. */
2969 new = xmalloc (strlen (symname) + 5);
2970 strcpy (new, symname + (word - sym_text));
2974 /* Return some of SYM_TEXT plus symname. */
2975 new = xmalloc (strlen (symname) + (sym_text - word) + 5);
2976 strncpy (new, word, sym_text - word);
2977 new[sym_text - word] = '\0';
2978 strcat (new, symname);
2981 if (return_val_index + 3 > return_val_size)
2983 newsize = (return_val_size *= 2) * sizeof (char *);
2984 return_val = (char **) xrealloc ((char *) return_val, newsize);
2986 return_val[return_val_index++] = new;
2987 return_val[return_val_index] = NULL;
2991 /* Return a NULL terminated array of all symbols (regardless of class)
2992 which begin by matching TEXT. If the answer is no symbols, then
2993 the return value is an array which contains only a NULL pointer.
2995 Problem: All of the symbols have to be copied because readline frees them.
2996 I'm not going to worry about this; hopefully there won't be that many. */
2999 make_symbol_completion_list (char *text, char *word)
3001 register struct symbol *sym;
3002 register struct symtab *s;
3003 register struct partial_symtab *ps;
3004 register struct minimal_symbol *msymbol;
3005 register struct objfile *objfile;
3006 register struct block *b, *surrounding_static_block = 0;
3008 struct partial_symbol **psym;
3009 /* The symbol we are completing on. Points in same buffer as text. */
3011 /* Length of sym_text. */
3014 /* Now look for the symbol we are supposed to complete on.
3015 FIXME: This should be language-specific. */
3019 char *quote_pos = NULL;
3021 /* First see if this is a quoted string. */
3023 for (p = text; *p != '\0'; ++p)
3025 if (quote_found != '\0')
3027 if (*p == quote_found)
3028 /* Found close quote. */
3030 else if (*p == '\\' && p[1] == quote_found)
3031 /* A backslash followed by the quote character
3032 doesn't end the string. */
3035 else if (*p == '\'' || *p == '"')
3041 if (quote_found == '\'')
3042 /* A string within single quotes can be a symbol, so complete on it. */
3043 sym_text = quote_pos + 1;
3044 else if (quote_found == '"')
3045 /* A double-quoted string is never a symbol, nor does it make sense
3046 to complete it any other way. */
3048 return_val = (char **) xmalloc (sizeof (char *));
3049 return_val[0] = NULL;
3054 /* It is not a quoted string. Break it based on the characters
3055 which are in symbols. */
3058 if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
3067 sym_text_len = strlen (sym_text);
3069 return_val_size = 100;
3070 return_val_index = 0;
3071 return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
3072 return_val[0] = NULL;
3074 /* Look through the partial symtabs for all symbols which begin
3075 by matching SYM_TEXT. Add each one that you find to the list. */
3077 ALL_PSYMTABS (objfile, ps)
3079 /* If the psymtab's been read in we'll get it when we search
3080 through the blockvector. */
3084 for (psym = objfile->global_psymbols.list + ps->globals_offset;
3085 psym < (objfile->global_psymbols.list + ps->globals_offset
3086 + ps->n_global_syms);
3089 /* If interrupted, then quit. */
3091 COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word);
3094 for (psym = objfile->static_psymbols.list + ps->statics_offset;
3095 psym < (objfile->static_psymbols.list + ps->statics_offset
3096 + ps->n_static_syms);
3100 COMPLETION_LIST_ADD_SYMBOL (*psym, sym_text, sym_text_len, text, word);
3104 /* At this point scan through the misc symbol vectors and add each
3105 symbol you find to the list. Eventually we want to ignore
3106 anything that isn't a text symbol (everything else will be
3107 handled by the psymtab code above). */
3109 ALL_MSYMBOLS (objfile, msymbol)
3112 COMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text, word);
3115 /* Search upwards from currently selected frame (so that we can
3116 complete on local vars. */
3118 for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b))
3120 if (!BLOCK_SUPERBLOCK (b))
3122 surrounding_static_block = b; /* For elmin of dups */
3125 /* Also catch fields of types defined in this places which match our
3126 text string. Only complete on types visible from current context. */
3128 ALL_BLOCK_SYMBOLS (b, i, sym)
3130 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3131 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
3133 struct type *t = SYMBOL_TYPE (sym);
3134 enum type_code c = TYPE_CODE (t);
3136 if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
3138 for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++)
3140 if (TYPE_FIELD_NAME (t, j))
3142 completion_list_add_name (TYPE_FIELD_NAME (t, j),
3143 sym_text, sym_text_len, text, word);
3151 /* Go through the symtabs and check the externs and statics for
3152 symbols which match. */
3154 ALL_SYMTABS (objfile, s)
3157 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
3158 ALL_BLOCK_SYMBOLS (b, i, sym)
3160 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3164 ALL_SYMTABS (objfile, s)
3167 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
3168 /* Don't do this block twice. */
3169 if (b == surrounding_static_block)
3171 ALL_BLOCK_SYMBOLS (b, i, sym)
3173 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3177 return (return_val);
3180 /* Like make_symbol_completion_list, but returns a list of symbols
3181 defined in a source file FILE. */
3184 make_file_symbol_completion_list (char *text, char *word, char *srcfile)
3186 register struct symbol *sym;
3187 register struct symtab *s;
3188 register struct block *b;
3190 /* The symbol we are completing on. Points in same buffer as text. */
3192 /* Length of sym_text. */
3195 /* Now look for the symbol we are supposed to complete on.
3196 FIXME: This should be language-specific. */
3200 char *quote_pos = NULL;
3202 /* First see if this is a quoted string. */
3204 for (p = text; *p != '\0'; ++p)
3206 if (quote_found != '\0')
3208 if (*p == quote_found)
3209 /* Found close quote. */
3211 else if (*p == '\\' && p[1] == quote_found)
3212 /* A backslash followed by the quote character
3213 doesn't end the string. */
3216 else if (*p == '\'' || *p == '"')
3222 if (quote_found == '\'')
3223 /* A string within single quotes can be a symbol, so complete on it. */
3224 sym_text = quote_pos + 1;
3225 else if (quote_found == '"')
3226 /* A double-quoted string is never a symbol, nor does it make sense
3227 to complete it any other way. */
3229 return_val = (char **) xmalloc (sizeof (char *));
3230 return_val[0] = NULL;
3235 /* It is not a quoted string. Break it based on the characters
3236 which are in symbols. */
3239 if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
3248 sym_text_len = strlen (sym_text);
3250 return_val_size = 10;
3251 return_val_index = 0;
3252 return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
3253 return_val[0] = NULL;
3255 /* Find the symtab for SRCFILE (this loads it if it was not yet read
3257 s = lookup_symtab (srcfile);
3260 /* Maybe they typed the file with leading directories, while the
3261 symbol tables record only its basename. */
3262 const char *tail = lbasename (srcfile);
3265 s = lookup_symtab (tail);
3268 /* If we have no symtab for that file, return an empty list. */
3270 return (return_val);
3272 /* Go through this symtab and check the externs and statics for
3273 symbols which match. */
3275 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
3276 ALL_BLOCK_SYMBOLS (b, i, sym)
3278 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3281 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
3282 ALL_BLOCK_SYMBOLS (b, i, sym)
3284 COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
3287 return (return_val);
3290 /* A helper function for make_source_files_completion_list. It adds
3291 another file name to a list of possible completions, growing the
3292 list as necessary. */
3295 add_filename_to_list (const char *fname, char *text, char *word,
3296 char ***list, int *list_used, int *list_alloced)
3299 size_t fnlen = strlen (fname);
3301 if (*list_used + 1 >= *list_alloced)
3304 *list = (char **) xrealloc ((char *) *list,
3305 *list_alloced * sizeof (char *));
3310 /* Return exactly fname. */
3311 new = xmalloc (fnlen + 5);
3312 strcpy (new, fname);
3314 else if (word > text)
3316 /* Return some portion of fname. */
3317 new = xmalloc (fnlen + 5);
3318 strcpy (new, fname + (word - text));
3322 /* Return some of TEXT plus fname. */
3323 new = xmalloc (fnlen + (text - word) + 5);
3324 strncpy (new, word, text - word);
3325 new[text - word] = '\0';
3326 strcat (new, fname);
3328 (*list)[*list_used] = new;
3329 (*list)[++*list_used] = NULL;
3333 not_interesting_fname (const char *fname)
3335 static const char *illegal_aliens[] = {
3336 "_globals_", /* inserted by coff_symtab_read */
3341 for (i = 0; illegal_aliens[i]; i++)
3343 if (strcmp (fname, illegal_aliens[i]) == 0)
3349 /* Return a NULL terminated array of all source files whose names
3350 begin with matching TEXT. The file names are looked up in the
3351 symbol tables of this program. If the answer is no matchess, then
3352 the return value is an array which contains only a NULL pointer. */
3355 make_source_files_completion_list (char *text, char *word)
3357 register struct symtab *s;
3358 register struct partial_symtab *ps;
3359 register struct objfile *objfile;
3361 int list_alloced = 1;
3363 size_t text_len = strlen (text);
3364 char **list = (char **) xmalloc (list_alloced * sizeof (char *));
3365 const char *base_name;
3369 if (!have_full_symbols () && !have_partial_symbols ())
3372 ALL_SYMTABS (objfile, s)
3374 if (not_interesting_fname (s->filename))
3376 if (!filename_seen (s->filename, 1, &first)
3377 #if HAVE_DOS_BASED_FILE_SYSTEM
3378 && strncasecmp (s->filename, text, text_len) == 0
3380 && strncmp (s->filename, text, text_len) == 0
3384 /* This file matches for a completion; add it to the current
3386 add_filename_to_list (s->filename, text, word,
3387 &list, &list_used, &list_alloced);
3391 /* NOTE: We allow the user to type a base name when the
3392 debug info records leading directories, but not the other
3393 way around. This is what subroutines of breakpoint
3394 command do when they parse file names. */
3395 base_name = lbasename (s->filename);
3396 if (base_name != s->filename
3397 && !filename_seen (base_name, 1, &first)
3398 #if HAVE_DOS_BASED_FILE_SYSTEM
3399 && strncasecmp (base_name, text, text_len) == 0
3401 && strncmp (base_name, text, text_len) == 0
3404 add_filename_to_list (base_name, text, word,
3405 &list, &list_used, &list_alloced);
3409 ALL_PSYMTABS (objfile, ps)
3411 if (not_interesting_fname (ps->filename))
3415 if (!filename_seen (ps->filename, 1, &first)
3416 #if HAVE_DOS_BASED_FILE_SYSTEM
3417 && strncasecmp (ps->filename, text, text_len) == 0
3419 && strncmp (ps->filename, text, text_len) == 0
3423 /* This file matches for a completion; add it to the
3424 current list of matches. */
3425 add_filename_to_list (ps->filename, text, word,
3426 &list, &list_used, &list_alloced);
3431 base_name = lbasename (ps->filename);
3432 if (base_name != ps->filename
3433 && !filename_seen (base_name, 1, &first)
3434 #if HAVE_DOS_BASED_FILE_SYSTEM
3435 && strncasecmp (base_name, text, text_len) == 0
3437 && strncmp (base_name, text, text_len) == 0
3440 add_filename_to_list (base_name, text, word,
3441 &list, &list_used, &list_alloced);
3449 /* Determine if PC is in the prologue of a function. The prologue is the area
3450 between the first instruction of a function, and the first executable line.
3451 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
3453 If non-zero, func_start is where we think the prologue starts, possibly
3454 by previous examination of symbol table information.
3458 in_prologue (CORE_ADDR pc, CORE_ADDR func_start)
3460 struct symtab_and_line sal;
3461 CORE_ADDR func_addr, func_end;
3463 /* We have several sources of information we can consult to figure
3465 - Compilers usually emit line number info that marks the prologue
3466 as its own "source line". So the ending address of that "line"
3467 is the end of the prologue. If available, this is the most
3469 - The minimal symbols and partial symbols, which can usually tell
3470 us the starting and ending addresses of a function.
3471 - If we know the function's start address, we can call the
3472 architecture-defined SKIP_PROLOGUE function to analyze the
3473 instruction stream and guess where the prologue ends.
3474 - Our `func_start' argument; if non-zero, this is the caller's
3475 best guess as to the function's entry point. At the time of
3476 this writing, handle_inferior_event doesn't get this right, so
3477 it should be our last resort. */
3479 /* Consult the partial symbol table, to find which function
3481 if (! find_pc_partial_function (pc, NULL, &func_addr, &func_end))
3483 CORE_ADDR prologue_end;
3485 /* We don't even have minsym information, so fall back to using
3486 func_start, if given. */
3488 return 1; /* We *might* be in a prologue. */
3490 prologue_end = SKIP_PROLOGUE (func_start);
3492 return func_start <= pc && pc < prologue_end;
3495 /* If we have line number information for the function, that's
3496 usually pretty reliable. */
3497 sal = find_pc_line (func_addr, 0);
3499 /* Now sal describes the source line at the function's entry point,
3500 which (by convention) is the prologue. The end of that "line",
3501 sal.end, is the end of the prologue.
3503 Note that, for functions whose source code is all on a single
3504 line, the line number information doesn't always end up this way.
3505 So we must verify that our purported end-of-prologue address is
3506 *within* the function, not at its start or end. */
3508 || sal.end <= func_addr
3509 || func_end <= sal.end)
3511 /* We don't have any good line number info, so use the minsym
3512 information, together with the architecture-specific prologue
3514 CORE_ADDR prologue_end = SKIP_PROLOGUE (func_addr);
3516 return func_addr <= pc && pc < prologue_end;
3519 /* We have line number info, and it looks good. */
3520 return func_addr <= pc && pc < sal.end;
3524 /* Begin overload resolution functions */
3525 /* Helper routine for make_symbol_completion_list. */
3527 static int sym_return_val_size;
3528 static int sym_return_val_index;
3529 static struct symbol **sym_return_val;
3531 /* Test to see if the symbol specified by SYMNAME (which is already
3532 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3533 characters. If so, add it to the current completion list. */
3536 overload_list_add_symbol (struct symbol *sym, char *oload_name)
3541 /* Get the demangled name without parameters */
3542 char *sym_name = cplus_demangle (SYMBOL_NAME (sym), DMGL_ARM | DMGL_ANSI);
3545 sym_name = (char *) xmalloc (strlen (SYMBOL_NAME (sym)) + 1);
3546 strcpy (sym_name, SYMBOL_NAME (sym));
3549 /* skip symbols that cannot match */
3550 if (strcmp (sym_name, oload_name) != 0)
3556 /* If there is no type information, we can't do anything, so skip */
3557 if (SYMBOL_TYPE (sym) == NULL)
3560 /* skip any symbols that we've already considered. */
3561 for (i = 0; i < sym_return_val_index; ++i)
3562 if (!strcmp (SYMBOL_NAME (sym), SYMBOL_NAME (sym_return_val[i])))
3565 /* We have a match for an overload instance, so add SYM to the current list
3566 * of overload instances */
3567 if (sym_return_val_index + 3 > sym_return_val_size)
3569 newsize = (sym_return_val_size *= 2) * sizeof (struct symbol *);
3570 sym_return_val = (struct symbol **) xrealloc ((char *) sym_return_val, newsize);
3572 sym_return_val[sym_return_val_index++] = sym;
3573 sym_return_val[sym_return_val_index] = NULL;
3578 /* Return a null-terminated list of pointers to function symbols that
3579 * match name of the supplied symbol FSYM.
3580 * This is used in finding all overloaded instances of a function name.
3581 * This has been modified from make_symbol_completion_list. */
3585 make_symbol_overload_list (struct symbol *fsym)
3587 register struct symbol *sym;
3588 register struct symtab *s;
3589 register struct partial_symtab *ps;
3590 register struct objfile *objfile;
3591 register struct block *b, *surrounding_static_block = 0;
3593 /* The name we are completing on. */
3594 char *oload_name = NULL;
3595 /* Length of name. */
3596 int oload_name_len = 0;
3598 /* Look for the symbol we are supposed to complete on.
3599 * FIXME: This should be language-specific. */
3601 oload_name = cplus_demangle (SYMBOL_NAME (fsym), DMGL_ARM | DMGL_ANSI);
3604 oload_name = (char *) xmalloc (strlen (SYMBOL_NAME (fsym)) + 1);
3605 strcpy (oload_name, SYMBOL_NAME (fsym));
3607 oload_name_len = strlen (oload_name);
3609 sym_return_val_size = 100;
3610 sym_return_val_index = 0;
3611 sym_return_val = (struct symbol **) xmalloc ((sym_return_val_size + 1) * sizeof (struct symbol *));
3612 sym_return_val[0] = NULL;
3614 /* Look through the partial symtabs for all symbols which begin
3615 by matching OLOAD_NAME. Make sure we read that symbol table in. */
3617 ALL_PSYMTABS (objfile, ps)
3619 struct partial_symbol **psym;
3621 /* If the psymtab's been read in we'll get it when we search
3622 through the blockvector. */
3626 for (psym = objfile->global_psymbols.list + ps->globals_offset;
3627 psym < (objfile->global_psymbols.list + ps->globals_offset
3628 + ps->n_global_syms);
3631 /* If interrupted, then quit. */
3633 /* This will cause the symbol table to be read if it has not yet been */
3634 s = PSYMTAB_TO_SYMTAB (ps);
3637 for (psym = objfile->static_psymbols.list + ps->statics_offset;
3638 psym < (objfile->static_psymbols.list + ps->statics_offset
3639 + ps->n_static_syms);
3643 /* This will cause the symbol table to be read if it has not yet been */
3644 s = PSYMTAB_TO_SYMTAB (ps);
3648 /* Search upwards from currently selected frame (so that we can
3649 complete on local vars. */
3651 for (b = get_selected_block (); b != NULL; b = BLOCK_SUPERBLOCK (b))
3653 if (!BLOCK_SUPERBLOCK (b))
3655 surrounding_static_block = b; /* For elimination of dups */
3658 /* Also catch fields of types defined in this places which match our
3659 text string. Only complete on types visible from current context. */
3661 ALL_BLOCK_SYMBOLS (b, i, sym)
3663 overload_list_add_symbol (sym, oload_name);
3667 /* Go through the symtabs and check the externs and statics for
3668 symbols which match. */
3670 ALL_SYMTABS (objfile, s)
3673 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
3674 ALL_BLOCK_SYMBOLS (b, i, sym)
3676 overload_list_add_symbol (sym, oload_name);
3680 ALL_SYMTABS (objfile, s)
3683 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
3684 /* Don't do this block twice. */
3685 if (b == surrounding_static_block)
3687 ALL_BLOCK_SYMBOLS (b, i, sym)
3689 overload_list_add_symbol (sym, oload_name);
3695 return (sym_return_val);
3698 /* End of overload resolution functions */
3700 struct symtabs_and_lines
3701 decode_line_spec (char *string, int funfirstline)
3703 struct symtabs_and_lines sals;
3705 error ("Empty line specification.");
3706 sals = decode_line_1 (&string, funfirstline,
3707 current_source_symtab, current_source_line,
3710 error ("Junk at end of line specification: %s", string);
3715 static char *name_of_main;
3718 set_main_name (const char *name)
3720 if (name_of_main != NULL)
3722 xfree (name_of_main);
3723 name_of_main = NULL;
3727 name_of_main = xstrdup (name);
3734 if (name_of_main != NULL)
3735 return name_of_main;
3742 _initialize_symtab (void)
3744 add_info ("variables", variables_info,
3745 "All global and static variable names, or those matching REGEXP.");
3747 add_com ("whereis", class_info, variables_info,
3748 "All global and static variable names, or those matching REGEXP.");
3750 add_info ("functions", functions_info,
3751 "All function names, or those matching REGEXP.");
3754 /* FIXME: This command has at least the following problems:
3755 1. It prints builtin types (in a very strange and confusing fashion).
3756 2. It doesn't print right, e.g. with
3757 typedef struct foo *FOO
3758 type_print prints "FOO" when we want to make it (in this situation)
3759 print "struct foo *".
3760 I also think "ptype" or "whatis" is more likely to be useful (but if
3761 there is much disagreement "info types" can be fixed). */
3762 add_info ("types", types_info,
3763 "All type names, or those matching REGEXP.");
3766 add_info ("methods", methods_info,
3767 "All method names, or those matching REGEXP::REGEXP.\n\
3768 If the class qualifier is omitted, it is assumed to be the current scope.\n\
3769 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
3772 add_info ("sources", sources_info,
3773 "Source files in the program.");
3775 add_com ("rbreak", class_breakpoint, rbreak_command,
3776 "Set a breakpoint for all functions matching REGEXP.");
3780 add_com ("lf", class_info, sources_info, "Source files in the program");
3781 add_com ("lg", class_info, variables_info,
3782 "All global and static variable names, or those matching REGEXP.");
3785 /* Initialize the one built-in type that isn't language dependent... */
3786 builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0,
3787 "<unknown type>", (struct objfile *) NULL);