1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
32 #include "call-cmds.h"
33 #include "gdb_regex.h"
34 #include "expression.h"
42 #include <sys/types.h>
44 #include "gdb_string.h"
48 /* Prototype for one function in parser-defs.h,
49 instead of including that entire file. */
51 extern char *find_template_name_end (char *);
53 /* Prototypes for local functions */
55 static void completion_list_add_name (char *, char *, int, char *, char *);
57 static void rbreak_command (char *, int);
59 static void types_info (char *, int);
61 static void functions_info (char *, int);
63 static void variables_info (char *, int);
65 static void sources_info (char *, int);
67 static void output_source_filename (char *, int *);
69 static int find_line_common (struct linetable
*, int, int *);
71 /* This one is used by linespec.c */
73 char *operator_chars (char *p
, char **end
);
75 static struct partial_symbol
*lookup_partial_symbol (struct partial_symtab
*,
79 static struct symtab
*lookup_symtab_1 (char *);
81 static struct symbol
*lookup_symbol_aux (const char *name
, const
82 struct block
*block
, const
83 namespace_enum
namespace, int
84 *is_a_field_of_this
, struct
88 static struct symbol
*find_active_alias (struct symbol
*sym
, CORE_ADDR addr
);
90 /* This flag is used in hppa-tdep.c, and set in hp-symtab-read.c */
91 /* Signals the presence of objects compiled by HP compilers */
92 int hp_som_som_object_present
= 0;
94 static void fixup_section (struct general_symbol_info
*, struct objfile
*);
96 static int file_matches (char *, char **, int);
98 static void print_symbol_info (namespace_enum
,
99 struct symtab
*, struct symbol
*, int, char *);
101 static void print_msymbol_info (struct minimal_symbol
*);
103 static void symtab_symbol_info (char *, namespace_enum
, int);
105 static void overload_list_add_symbol (struct symbol
*sym
, char *oload_name
);
107 void _initialize_symtab (void);
111 /* The single non-language-specific builtin type */
112 struct type
*builtin_type_error
;
114 /* Block in which the most recently searched-for symbol was found.
115 Might be better to make this a parameter to lookup_symbol and
118 const struct block
*block_found
;
120 /* While the C++ support is still in flux, issue a possibly helpful hint on
121 using the new command completion feature on single quoted demangled C++
122 symbols. Remove when loose ends are cleaned up. FIXME -fnf */
125 cplusplus_hint (char *name
)
127 while (*name
== '\'')
129 printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name
, name
);
130 printf_filtered ("(Note leading single quote.)\n");
133 /* Check for a symtab of a specific name; first in symtabs, then in
134 psymtabs. *If* there is no '/' in the name, a match after a '/'
135 in the symtab filename will also work. */
137 static struct symtab
*
138 lookup_symtab_1 (char *name
)
140 register struct symtab
*s
;
141 register struct partial_symtab
*ps
;
142 register char *slash
;
143 register struct objfile
*objfile
;
147 /* First, search for an exact match */
149 ALL_SYMTABS (objfile
, s
)
150 if (STREQ (name
, s
->filename
))
153 slash
= strchr (name
, '/');
155 /* Now, search for a matching tail (only if name doesn't have any dirs) */
158 ALL_SYMTABS (objfile
, s
)
160 char *p
= s
->filename
;
161 char *tail
= strrchr (p
, '/');
170 /* Same search rules as above apply here, but now we look thru the
173 ps
= lookup_partial_symtab (name
);
178 error ("Internal: readin %s pst for `%s' found when no symtab found.",
181 s
= PSYMTAB_TO_SYMTAB (ps
);
186 /* At this point, we have located the psymtab for this file, but
187 the conversion to a symtab has failed. This usually happens
188 when we are looking up an include file. In this case,
189 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
190 been created. So, we need to run through the symtabs again in
191 order to find the file.
192 XXX - This is a crock, and should be fixed inside of the the
193 symbol parsing routines. */
197 /* Lookup the symbol table of a source file named NAME. Try a couple
198 of variations if the first lookup doesn't work. */
201 lookup_symtab (char *name
)
203 register struct symtab
*s
;
208 s
= lookup_symtab_1 (name
);
213 /* This screws c-exp.y:yylex if there is both a type "tree" and a symtab
216 /* If name not found as specified, see if adding ".c" helps. */
217 /* Why is this? Is it just a user convenience? (If so, it's pretty
218 questionable in the presence of C++, FORTRAN, etc.). It's not in
221 copy
= (char *) alloca (strlen (name
) + 3);
224 s
= lookup_symtab_1 (copy
);
229 /* We didn't find anything; die. */
233 /* Lookup the partial symbol table of a source file named NAME.
234 *If* there is no '/' in the name, a match after a '/'
235 in the psymtab filename will also work. */
237 struct partial_symtab
*
238 lookup_partial_symtab (char *name
)
240 register struct partial_symtab
*pst
;
241 register struct objfile
*objfile
;
243 ALL_PSYMTABS (objfile
, pst
)
245 if (STREQ (name
, pst
->filename
))
251 /* Now, search for a matching tail (only if name doesn't have any dirs) */
253 if (!strchr (name
, '/'))
254 ALL_PSYMTABS (objfile
, pst
)
256 char *p
= pst
->filename
;
257 char *tail
= strrchr (p
, '/');
269 /* Mangle a GDB method stub type. This actually reassembles the pieces of the
270 full method name, which consist of the class name (from T), the unadorned
271 method name from METHOD_ID, and the signature for the specific overload,
272 specified by SIGNATURE_ID. Note that this function is g++ specific. */
275 gdb_mangle_name (struct type
*type
, int method_id
, int signature_id
)
277 int mangled_name_len
;
279 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
280 struct fn_field
*method
= &f
[signature_id
];
281 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, method_id
);
282 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, signature_id
);
283 char *newname
= type_name_no_tag (type
);
285 /* Does the form of physname indicate that it is the full mangled name
286 of a constructor (not just the args)? */
287 int is_full_physname_constructor
;
290 int is_destructor
= DESTRUCTOR_PREFIX_P (physname
);
291 /* Need a new type prefix. */
292 char *const_prefix
= method
->is_const
? "C" : "";
293 char *volatile_prefix
= method
->is_volatile
? "V" : "";
295 int len
= (newname
== NULL
? 0 : strlen (newname
));
297 if (OPNAME_PREFIX_P (field_name
))
298 return xstrdup (physname
);
300 is_full_physname_constructor
=
301 ((physname
[0] == '_' && physname
[1] == '_' &&
302 (isdigit (physname
[2]) || physname
[2] == 'Q' || physname
[2] == 't'))
303 || (strncmp (physname
, "__ct", 4) == 0));
306 is_full_physname_constructor
|| (newname
&& STREQ (field_name
, newname
));
309 is_destructor
= (strncmp (physname
, "__dt", 4) == 0);
311 if (is_destructor
|| is_full_physname_constructor
)
313 mangled_name
= (char *) xmalloc (strlen (physname
) + 1);
314 strcpy (mangled_name
, physname
);
320 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
322 else if (physname
[0] == 't' || physname
[0] == 'Q')
324 /* The physname for template and qualified methods already includes
326 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
332 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
334 mangled_name_len
= ((is_constructor
? 0 : strlen (field_name
))
335 + strlen (buf
) + len
+ strlen (physname
) + 1);
338 mangled_name
= (char *) xmalloc (mangled_name_len
);
340 mangled_name
[0] = '\0';
342 strcpy (mangled_name
, field_name
);
344 strcat (mangled_name
, buf
);
345 /* If the class doesn't have a name, i.e. newname NULL, then we just
346 mangle it using 0 for the length of the class. Thus it gets mangled
347 as something starting with `::' rather than `classname::'. */
349 strcat (mangled_name
, newname
);
351 strcat (mangled_name
, physname
);
352 return (mangled_name
);
357 /* Find which partial symtab on contains PC and SECTION. Return 0 if none. */
359 struct partial_symtab
*
360 find_pc_sect_psymtab (CORE_ADDR pc
, asection
*section
)
362 register struct partial_symtab
*pst
;
363 register struct objfile
*objfile
;
365 ALL_PSYMTABS (objfile
, pst
)
367 if (pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
369 struct minimal_symbol
*msymbol
;
370 struct partial_symtab
*tpst
;
372 /* An objfile that has its functions reordered might have
373 many partial symbol tables containing the PC, but
374 we want the partial symbol table that contains the
375 function containing the PC. */
376 if (!(objfile
->flags
& OBJF_REORDERED
) &&
377 section
== 0) /* can't validate section this way */
380 msymbol
= lookup_minimal_symbol_by_pc_section (pc
, section
);
384 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
386 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
388 struct partial_symbol
*p
;
390 p
= find_pc_sect_psymbol (tpst
, pc
, section
);
392 && SYMBOL_VALUE_ADDRESS (p
)
393 == SYMBOL_VALUE_ADDRESS (msymbol
))
403 /* Find which partial symtab contains PC. Return 0 if none.
404 Backward compatibility, no section */
406 struct partial_symtab
*
407 find_pc_psymtab (CORE_ADDR pc
)
409 return find_pc_sect_psymtab (pc
, find_pc_mapped_section (pc
));
412 /* Find which partial symbol within a psymtab matches PC and SECTION.
413 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
415 struct partial_symbol
*
416 find_pc_sect_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
,
419 struct partial_symbol
*best
= NULL
, *p
, **pp
;
423 psymtab
= find_pc_sect_psymtab (pc
, section
);
427 /* Cope with programs that start at address 0 */
428 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
430 /* Search the global symbols as well as the static symbols, so that
431 find_pc_partial_function doesn't use a minimal symbol and thus
432 cache a bad endaddr. */
433 for (pp
= psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
434 (pp
- (psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
435 < psymtab
->n_global_syms
);
439 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
440 && SYMBOL_CLASS (p
) == LOC_BLOCK
441 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
442 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
443 || (psymtab
->textlow
== 0
444 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
446 if (section
) /* match on a specific section */
448 fixup_psymbol_section (p
, psymtab
->objfile
);
449 if (SYMBOL_BFD_SECTION (p
) != section
)
452 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
457 for (pp
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
458 (pp
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
459 < psymtab
->n_static_syms
);
463 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
464 && SYMBOL_CLASS (p
) == LOC_BLOCK
465 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
466 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
467 || (psymtab
->textlow
== 0
468 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
470 if (section
) /* match on a specific section */
472 fixup_psymbol_section (p
, psymtab
->objfile
);
473 if (SYMBOL_BFD_SECTION (p
) != section
)
476 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
484 /* Find which partial symbol within a psymtab matches PC. Return 0 if none.
485 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
487 struct partial_symbol
*
488 find_pc_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
)
490 return find_pc_sect_psymbol (psymtab
, pc
, find_pc_mapped_section (pc
));
493 /* Debug symbols usually don't have section information. We need to dig that
494 out of the minimal symbols and stash that in the debug symbol. */
497 fixup_section (struct general_symbol_info
*ginfo
, struct objfile
*objfile
)
499 struct minimal_symbol
*msym
;
500 msym
= lookup_minimal_symbol (ginfo
->name
, NULL
, objfile
);
504 ginfo
->bfd_section
= SYMBOL_BFD_SECTION (msym
);
505 ginfo
->section
= SYMBOL_SECTION (msym
);
510 fixup_symbol_section (struct symbol
*sym
, struct objfile
*objfile
)
515 if (SYMBOL_BFD_SECTION (sym
))
518 fixup_section (&sym
->ginfo
, objfile
);
523 struct partial_symbol
*
524 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
529 if (SYMBOL_BFD_SECTION (psym
))
532 fixup_section (&psym
->ginfo
, objfile
);
537 /* Find the definition for a specified symbol name NAME
538 in namespace NAMESPACE, visible from lexical block BLOCK.
539 Returns the struct symbol pointer, or zero if no symbol is found.
540 If SYMTAB is non-NULL, store the symbol table in which the
541 symbol was found there, or NULL if not found.
542 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
543 NAME is a field of the current implied argument `this'. If so set
544 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
545 BLOCK_FOUND is set to the block in which NAME is found (in the case of
546 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
548 /* This function has a bunch of loops in it and it would seem to be
549 attractive to put in some QUIT's (though I'm not really sure
550 whether it can run long enough to be really important). But there
551 are a few calls for which it would appear to be bad news to quit
552 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and
553 nindy_frame_chain_valid in nindy-tdep.c. (Note that there is C++
554 code below which can error(), but that probably doesn't affect
555 these calls since they are looking for a known variable and thus
556 can probably assume it will never hit the C++ code). */
559 lookup_symbol (const char *name
, const struct block
*block
,
560 const namespace_enum
namespace, int *is_a_field_of_this
,
561 struct symtab
**symtab
)
563 char *modified_name
= NULL
;
564 char *modified_name2
= NULL
;
565 int needtofreename
= 0;
566 struct symbol
*returnval
;
568 if (case_sensitivity
== case_sensitive_off
)
574 copy
= (char *) alloca (len
+ 1);
575 for (i
= 0; i
< len
; i
++)
576 copy
[i
] = tolower (name
[i
]);
578 modified_name
= copy
;
581 modified_name
= (char *) name
;
583 /* If we are using C++ language, demangle the name before doing a lookup, so
584 we can always binary search. */
585 if (current_language
->la_language
== language_cplus
)
587 modified_name2
= cplus_demangle (modified_name
, DMGL_ANSI
| DMGL_PARAMS
);
590 modified_name
= modified_name2
;
595 returnval
= lookup_symbol_aux (modified_name
, block
, namespace,
596 is_a_field_of_this
, symtab
);
598 free (modified_name2
);
603 static struct symbol
*
604 lookup_symbol_aux (const char *name
, const struct block
*block
,
605 const namespace_enum
namespace, int *is_a_field_of_this
,
606 struct symtab
**symtab
)
608 register struct symbol
*sym
;
609 register struct symtab
*s
= NULL
;
610 register struct partial_symtab
*ps
;
611 register struct blockvector
*bv
;
612 register struct objfile
*objfile
= NULL
;
613 register struct block
*b
;
614 register struct minimal_symbol
*msymbol
;
617 /* Search specified block and its superiors. */
621 sym
= lookup_block_symbol (block
, name
, namespace);
627 /* Search the list of symtabs for one which contains the
628 address of the start of this block. */
629 ALL_SYMTABS (objfile
, s
)
631 bv
= BLOCKVECTOR (s
);
632 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
633 if (BLOCK_START (b
) <= BLOCK_START (block
)
634 && BLOCK_END (b
) > BLOCK_START (block
))
641 return fixup_symbol_section (sym
, objfile
);
643 block
= BLOCK_SUPERBLOCK (block
);
646 /* FIXME: this code is never executed--block is always NULL at this
647 point. What is it trying to do, anyway? We already should have
648 checked the STATIC_BLOCK above (it is the superblock of top-level
649 blocks). Why is VAR_NAMESPACE special-cased? */
650 /* Don't need to mess with the psymtabs; if we have a block,
651 that file is read in. If we don't, then we deal later with
652 all the psymtab stuff that needs checking. */
653 /* Note (RT): The following never-executed code looks unnecessary to me also.
654 * If we change the code to use the original (passed-in)
655 * value of 'block', we could cause it to execute, but then what
656 * would it do? The STATIC_BLOCK of the symtab containing the passed-in
657 * 'block' was already searched by the above code. And the STATIC_BLOCK's
658 * of *other* symtabs (those files not containing 'block' lexically)
659 * should not contain 'block' address-wise. So we wouldn't expect this
660 * code to find any 'sym''s that were not found above. I vote for
661 * deleting the following paragraph of code.
663 if (namespace == VAR_NAMESPACE
&& block
!= NULL
)
666 /* Find the right symtab. */
667 ALL_SYMTABS (objfile
, s
)
669 bv
= BLOCKVECTOR (s
);
670 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
671 if (BLOCK_START (b
) <= BLOCK_START (block
)
672 && BLOCK_END (b
) > BLOCK_START (block
))
674 sym
= lookup_block_symbol (b
, name
, VAR_NAMESPACE
);
680 return fixup_symbol_section (sym
, objfile
);
687 /* C++: If requested to do so by the caller,
688 check to see if NAME is a field of `this'. */
689 if (is_a_field_of_this
)
691 struct value
*v
= value_of_this (0);
693 *is_a_field_of_this
= 0;
694 if (v
&& check_field (v
, name
))
696 *is_a_field_of_this
= 1;
703 /* Now search all global blocks. Do the symtab's first, then
704 check the psymtab's. If a psymtab indicates the existence
705 of the desired name as a global, then do psymtab-to-symtab
706 conversion on the fly and return the found symbol. */
708 ALL_SYMTABS (objfile
, s
)
710 bv
= BLOCKVECTOR (s
);
711 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
712 sym
= lookup_block_symbol (block
, name
, namespace);
718 return fixup_symbol_section (sym
, objfile
);
724 /* Check for the possibility of the symbol being a function or
725 a mangled variable that is stored in one of the minimal symbol tables.
726 Eventually, all global symbols might be resolved in this way. */
728 if (namespace == VAR_NAMESPACE
)
730 msymbol
= lookup_minimal_symbol (name
, NULL
, NULL
);
733 s
= find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol
),
734 SYMBOL_BFD_SECTION (msymbol
));
737 /* This is a function which has a symtab for its address. */
738 bv
= BLOCKVECTOR (s
);
739 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
740 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
742 /* We kept static functions in minimal symbol table as well as
743 in static scope. We want to find them in the symbol table. */
746 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
747 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
751 /* sym == 0 if symbol was found in the minimal symbol table
752 but not in the symtab.
753 Return 0 to use the msymbol definition of "foo_".
755 This happens for Fortran "foo_" symbols,
756 which are "foo" in the symtab.
758 This can also happen if "asm" is used to make a
759 regular symbol but not a debugging symbol, e.g.
766 return fixup_symbol_section (sym
, objfile
);
768 else if (MSYMBOL_TYPE (msymbol
) != mst_text
769 && MSYMBOL_TYPE (msymbol
) != mst_file_text
770 && !STREQ (name
, SYMBOL_NAME (msymbol
)))
772 /* This is a mangled variable, look it up by its
774 return lookup_symbol (SYMBOL_NAME (msymbol
), block
,
775 namespace, is_a_field_of_this
, symtab
);
777 /* There are no debug symbols for this file, or we are looking
778 for an unmangled variable.
779 Try to find a matching static symbol below. */
785 ALL_PSYMTABS (objfile
, ps
)
787 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
789 s
= PSYMTAB_TO_SYMTAB (ps
);
790 bv
= BLOCKVECTOR (s
);
791 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
792 sym
= lookup_block_symbol (block
, name
, namespace);
795 /* This shouldn't be necessary, but as a last resort
796 * try looking in the statics even though the psymtab
797 * claimed the symbol was global. It's possible that
798 * the psymtab gets it wrong in some cases.
800 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
801 sym
= lookup_block_symbol (block
, name
, namespace);
803 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
804 %s may be an inlined function, or may be a template function\n\
805 (if a template, try specifying an instantiation: %s<type>).",
806 name
, ps
->filename
, name
, name
);
810 return fixup_symbol_section (sym
, objfile
);
814 /* Now search all static file-level symbols.
815 Not strictly correct, but more useful than an error.
816 Do the symtabs first, then check the psymtabs.
817 If a psymtab indicates the existence
818 of the desired name as a file-level static, then do psymtab-to-symtab
819 conversion on the fly and return the found symbol. */
821 ALL_SYMTABS (objfile
, s
)
823 bv
= BLOCKVECTOR (s
);
824 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
825 sym
= lookup_block_symbol (block
, name
, namespace);
831 return fixup_symbol_section (sym
, objfile
);
835 ALL_PSYMTABS (objfile
, ps
)
837 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
839 s
= PSYMTAB_TO_SYMTAB (ps
);
840 bv
= BLOCKVECTOR (s
);
841 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
842 sym
= lookup_block_symbol (block
, name
, namespace);
845 /* This shouldn't be necessary, but as a last resort
846 * try looking in the globals even though the psymtab
847 * claimed the symbol was static. It's possible that
848 * the psymtab gets it wrong in some cases.
850 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
851 sym
= lookup_block_symbol (block
, name
, namespace);
853 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
854 %s may be an inlined function, or may be a template function\n\
855 (if a template, try specifying an instantiation: %s<type>).",
856 name
, ps
->filename
, name
, name
);
860 return fixup_symbol_section (sym
, objfile
);
866 /* Check for the possibility of the symbol being a function or
867 a global variable that is stored in one of the minimal symbol tables.
868 The "minimal symbol table" is built from linker-supplied info.
870 RT: I moved this check to last, after the complete search of
871 the global (p)symtab's and static (p)symtab's. For HP-generated
872 symbol tables, this check was causing a premature exit from
873 lookup_symbol with NULL return, and thus messing up symbol lookups
874 of things like "c::f". It seems to me a check of the minimal
875 symbol table ought to be a last resort in any case. I'm vaguely
876 worried about the comment below which talks about FORTRAN routines "foo_"
877 though... is it saying we need to do the "minsym" check before
878 the static check in this case?
881 if (namespace == VAR_NAMESPACE
)
883 msymbol
= lookup_minimal_symbol (name
, NULL
, NULL
);
886 /* OK, we found a minimal symbol in spite of not
887 * finding any symbol. There are various possible
888 * explanations for this. One possibility is the symbol
889 * exists in code not compiled -g. Another possibility
890 * is that the 'psymtab' isn't doing its job.
891 * A third possibility, related to #2, is that we were confused
892 * by name-mangling. For instance, maybe the psymtab isn't
893 * doing its job because it only know about demangled
894 * names, but we were given a mangled name...
897 /* We first use the address in the msymbol to try to
898 * locate the appropriate symtab. Note that find_pc_symtab()
899 * has a side-effect of doing psymtab-to-symtab expansion,
900 * for the found symtab.
902 s
= find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
));
905 bv
= BLOCKVECTOR (s
);
906 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
907 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
909 /* We kept static functions in minimal symbol table as well as
910 in static scope. We want to find them in the symbol table. */
913 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
914 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
917 /* If we found one, return it */
925 /* If we get here with sym == 0, the symbol was
926 found in the minimal symbol table
927 but not in the symtab.
928 Fall through and return 0 to use the msymbol
929 definition of "foo_".
930 (Note that outer code generally follows up a call
931 to this routine with a call to lookup_minimal_symbol(),
932 so a 0 return means we'll just flow into that other routine).
934 This happens for Fortran "foo_" symbols,
935 which are "foo" in the symtab.
937 This can also happen if "asm" is used to make a
938 regular symbol but not a debugging symbol, e.g.
944 /* If the lookup-by-address fails, try repeating the
945 * entire lookup process with the symbol name from
946 * the msymbol (if different from the original symbol name).
948 else if (MSYMBOL_TYPE (msymbol
) != mst_text
949 && MSYMBOL_TYPE (msymbol
) != mst_file_text
950 && !STREQ (name
, SYMBOL_NAME (msymbol
)))
952 return lookup_symbol (SYMBOL_NAME (msymbol
), block
,
953 namespace, is_a_field_of_this
, symtab
);
965 /* Look, in partial_symtab PST, for symbol NAME. Check the global
966 symbols if GLOBAL, the static symbols if not */
968 static struct partial_symbol
*
969 lookup_partial_symbol (struct partial_symtab
*pst
, const char *name
, int global
,
970 namespace_enum
namespace)
972 struct partial_symbol
*temp
;
973 struct partial_symbol
**start
, **psym
;
974 struct partial_symbol
**top
, **bottom
, **center
;
975 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
976 int do_linear_search
= 1;
983 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
984 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
986 if (global
) /* This means we can use a binary search. */
988 do_linear_search
= 0;
990 /* Binary search. This search is guaranteed to end with center
991 pointing at the earliest partial symbol with the correct
992 name. At that point *all* partial symbols with that name
993 will be checked against the correct namespace. */
996 top
= start
+ length
- 1;
999 center
= bottom
+ (top
- bottom
) / 2;
1000 if (!(center
< top
))
1002 if (!do_linear_search
1003 && (SYMBOL_LANGUAGE (*center
) == language_java
))
1005 do_linear_search
= 1;
1007 if (STRCMP (SYMBOL_SOURCE_NAME (*center
), name
) >= 0)
1013 bottom
= center
+ 1;
1016 if (!(top
== bottom
))
1019 /* djb - 2000-06-03 - Use SYMBOL_MATCHES_NAME, not a strcmp, so
1020 we don't have to force a linear search on C++. Probably holds true
1021 for JAVA as well, no way to check.*/
1022 while (SYMBOL_MATCHES_NAME (*top
,name
))
1024 if (SYMBOL_NAMESPACE (*top
) == namespace)
1032 /* Can't use a binary search or else we found during the binary search that
1033 we should also do a linear search. */
1035 if (do_linear_search
)
1037 for (psym
= start
; psym
< start
+ length
; psym
++)
1039 if (namespace == SYMBOL_NAMESPACE (*psym
))
1041 if (SYMBOL_MATCHES_NAME (*psym
, name
))
1052 /* Look up a type named NAME in the struct_namespace. The type returned
1053 must not be opaque -- i.e., must have at least one field defined
1055 This code was modelled on lookup_symbol -- the parts not relevant to looking
1056 up types were just left out. In particular it's assumed here that types
1057 are available in struct_namespace and only at file-static or global blocks. */
1061 lookup_transparent_type (const char *name
)
1063 register struct symbol
*sym
;
1064 register struct symtab
*s
= NULL
;
1065 register struct partial_symtab
*ps
;
1066 struct blockvector
*bv
;
1067 register struct objfile
*objfile
;
1068 register struct block
*block
;
1070 /* Now search all the global symbols. Do the symtab's first, then
1071 check the psymtab's. If a psymtab indicates the existence
1072 of the desired name as a global, then do psymtab-to-symtab
1073 conversion on the fly and return the found symbol. */
1075 ALL_SYMTABS (objfile
, s
)
1077 bv
= BLOCKVECTOR (s
);
1078 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1079 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1080 if (sym
&& !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1082 return SYMBOL_TYPE (sym
);
1086 ALL_PSYMTABS (objfile
, ps
)
1088 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, STRUCT_NAMESPACE
))
1090 s
= PSYMTAB_TO_SYMTAB (ps
);
1091 bv
= BLOCKVECTOR (s
);
1092 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1093 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1096 /* This shouldn't be necessary, but as a last resort
1097 * try looking in the statics even though the psymtab
1098 * claimed the symbol was global. It's possible that
1099 * the psymtab gets it wrong in some cases.
1101 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1102 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1104 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
1105 %s may be an inlined function, or may be a template function\n\
1106 (if a template, try specifying an instantiation: %s<type>).",
1107 name
, ps
->filename
, name
, name
);
1109 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1110 return SYMBOL_TYPE (sym
);
1114 /* Now search the static file-level symbols.
1115 Not strictly correct, but more useful than an error.
1116 Do the symtab's first, then
1117 check the psymtab's. If a psymtab indicates the existence
1118 of the desired name as a file-level static, then do psymtab-to-symtab
1119 conversion on the fly and return the found symbol.
1122 ALL_SYMTABS (objfile
, s
)
1124 bv
= BLOCKVECTOR (s
);
1125 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1126 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1127 if (sym
&& !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1129 return SYMBOL_TYPE (sym
);
1133 ALL_PSYMTABS (objfile
, ps
)
1135 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, STRUCT_NAMESPACE
))
1137 s
= PSYMTAB_TO_SYMTAB (ps
);
1138 bv
= BLOCKVECTOR (s
);
1139 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1140 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1143 /* This shouldn't be necessary, but as a last resort
1144 * try looking in the globals even though the psymtab
1145 * claimed the symbol was static. It's possible that
1146 * the psymtab gets it wrong in some cases.
1148 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1149 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1151 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
1152 %s may be an inlined function, or may be a template function\n\
1153 (if a template, try specifying an instantiation: %s<type>).",
1154 name
, ps
->filename
, name
, name
);
1156 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1157 return SYMBOL_TYPE (sym
);
1160 return (struct type
*) 0;
1164 /* Find the psymtab containing main(). */
1165 /* FIXME: What about languages without main() or specially linked
1166 executables that have no main() ? */
1168 struct partial_symtab
*
1169 find_main_psymtab (void)
1171 register struct partial_symtab
*pst
;
1172 register struct objfile
*objfile
;
1174 ALL_PSYMTABS (objfile
, pst
)
1176 if (lookup_partial_symbol (pst
, "main", 1, VAR_NAMESPACE
))
1184 /* Search BLOCK for symbol NAME in NAMESPACE.
1186 Note that if NAME is the demangled form of a C++ symbol, we will fail
1187 to find a match during the binary search of the non-encoded names, but
1188 for now we don't worry about the slight inefficiency of looking for
1189 a match we'll never find, since it will go pretty quick. Once the
1190 binary search terminates, we drop through and do a straight linear
1191 search on the symbols. Each symbol which is marked as being a C++
1192 symbol (language_cplus set) has both the encoded and non-encoded names
1193 tested for a match. */
1196 lookup_block_symbol (register const struct block
*block
, const char *name
,
1197 const namespace_enum
namespace)
1199 register int bot
, top
, inc
;
1200 register struct symbol
*sym
;
1201 register struct symbol
*sym_found
= NULL
;
1202 register int do_linear_search
= 1;
1204 /* If the blocks's symbols were sorted, start with a binary search. */
1206 if (BLOCK_SHOULD_SORT (block
))
1208 /* Reset the linear search flag so if the binary search fails, we
1209 won't do the linear search once unless we find some reason to
1212 do_linear_search
= 0;
1213 top
= BLOCK_NSYMS (block
);
1216 /* Advance BOT to not far before the first symbol whose name is NAME. */
1220 inc
= (top
- bot
+ 1);
1221 /* No need to keep binary searching for the last few bits worth. */
1226 inc
= (inc
>> 1) + bot
;
1227 sym
= BLOCK_SYM (block
, inc
);
1228 if (!do_linear_search
&& (SYMBOL_LANGUAGE (sym
) == language_java
))
1230 do_linear_search
= 1;
1232 if (SYMBOL_SOURCE_NAME (sym
)[0] < name
[0])
1236 else if (SYMBOL_SOURCE_NAME (sym
)[0] > name
[0])
1240 else if (STRCMP (SYMBOL_SOURCE_NAME (sym
), name
) < 0)
1250 /* Now scan forward until we run out of symbols, find one whose
1251 name is greater than NAME, or find one we want. If there is
1252 more than one symbol with the right name and namespace, we
1253 return the first one; I believe it is now impossible for us
1254 to encounter two symbols with the same name and namespace
1255 here, because blocks containing argument symbols are no
1258 top
= BLOCK_NSYMS (block
);
1261 sym
= BLOCK_SYM (block
, bot
);
1262 if (SYMBOL_MATCHES_NAME (sym
, name
))
1268 /* Here if block isn't sorted, or we fail to find a match during the
1269 binary search above. If during the binary search above, we find a
1270 symbol which is a C++ symbol, then we have re-enabled the linear
1271 search flag which was reset when starting the binary search.
1273 This loop is equivalent to the loop above, but hacked greatly for speed.
1275 Note that parameter symbols do not always show up last in the
1276 list; this loop makes sure to take anything else other than
1277 parameter symbols first; it only uses parameter symbols as a
1278 last resort. Note that this only takes up extra computation
1281 if (do_linear_search
)
1283 top
= BLOCK_NSYMS (block
);
1287 sym
= BLOCK_SYM (block
, bot
);
1288 if (SYMBOL_NAMESPACE (sym
) == namespace &&
1289 SYMBOL_MATCHES_NAME (sym
, name
))
1291 /* If SYM has aliases, then use any alias that is active
1292 at the current PC. If no alias is active at the current
1293 PC, then use the main symbol.
1295 ?!? Is checking the current pc correct? Is this routine
1296 ever called to look up a symbol from another context?
1298 FIXME: No, it's not correct. If someone sets a
1299 conditional breakpoint at an address, then the
1300 breakpoint's `struct expression' should refer to the
1301 `struct symbol' appropriate for the breakpoint's
1302 address, which may not be the PC.
1304 Even if it were never called from another context,
1305 it's totally bizarre for lookup_symbol's behavior to
1306 depend on the value of the inferior's current PC. We
1307 should pass in the appropriate PC as well as the
1308 block. The interface to lookup_symbol should change
1309 to require the caller to provide a PC. */
1311 if (SYMBOL_ALIASES (sym
))
1312 sym
= find_active_alias (sym
, read_pc ());
1315 if (SYMBOL_CLASS (sym
) != LOC_ARG
&&
1316 SYMBOL_CLASS (sym
) != LOC_LOCAL_ARG
&&
1317 SYMBOL_CLASS (sym
) != LOC_REF_ARG
&&
1318 SYMBOL_CLASS (sym
) != LOC_REGPARM
&&
1319 SYMBOL_CLASS (sym
) != LOC_REGPARM_ADDR
&&
1320 SYMBOL_CLASS (sym
) != LOC_BASEREG_ARG
)
1328 return (sym_found
); /* Will be NULL if not found. */
1331 /* Given a main symbol SYM and ADDR, search through the alias
1332 list to determine if an alias is active at ADDR and return
1335 If no alias is active, then return SYM. */
1337 static struct symbol
*
1338 find_active_alias (struct symbol
*sym
, CORE_ADDR addr
)
1340 struct range_list
*r
;
1341 struct alias_list
*aliases
;
1343 /* If we have aliases, check them first. */
1344 aliases
= SYMBOL_ALIASES (sym
);
1348 if (!SYMBOL_RANGES (aliases
->sym
))
1349 return aliases
->sym
;
1350 for (r
= SYMBOL_RANGES (aliases
->sym
); r
; r
= r
->next
)
1352 if (r
->start
<= addr
&& r
->end
> addr
)
1353 return aliases
->sym
;
1355 aliases
= aliases
->next
;
1358 /* Nothing found, return the main symbol. */
1363 /* Return the symbol for the function which contains a specified
1364 lexical block, described by a struct block BL. */
1367 block_function (struct block
*bl
)
1369 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
1370 bl
= BLOCK_SUPERBLOCK (bl
);
1372 return BLOCK_FUNCTION (bl
);
1375 /* Find the symtab associated with PC and SECTION. Look through the
1376 psymtabs and read in another symtab if necessary. */
1379 find_pc_sect_symtab (CORE_ADDR pc
, asection
*section
)
1381 register struct block
*b
;
1382 struct blockvector
*bv
;
1383 register struct symtab
*s
= NULL
;
1384 register struct symtab
*best_s
= NULL
;
1385 register struct partial_symtab
*ps
;
1386 register struct objfile
*objfile
;
1387 CORE_ADDR distance
= 0;
1389 /* Search all symtabs for the one whose file contains our address, and which
1390 is the smallest of all the ones containing the address. This is designed
1391 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1392 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1393 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1395 This happens for native ecoff format, where code from included files
1396 gets its own symtab. The symtab for the included file should have
1397 been read in already via the dependency mechanism.
1398 It might be swifter to create several symtabs with the same name
1399 like xcoff does (I'm not sure).
1401 It also happens for objfiles that have their functions reordered.
1402 For these, the symtab we are looking for is not necessarily read in. */
1404 ALL_SYMTABS (objfile
, s
)
1406 bv
= BLOCKVECTOR (s
);
1407 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1409 if (BLOCK_START (b
) <= pc
1410 && BLOCK_END (b
) > pc
1412 || BLOCK_END (b
) - BLOCK_START (b
) < distance
))
1414 /* For an objfile that has its functions reordered,
1415 find_pc_psymtab will find the proper partial symbol table
1416 and we simply return its corresponding symtab. */
1417 /* In order to better support objfiles that contain both
1418 stabs and coff debugging info, we continue on if a psymtab
1420 if ((objfile
->flags
& OBJF_REORDERED
) && objfile
->psymtabs
)
1422 ps
= find_pc_sect_psymtab (pc
, section
);
1424 return PSYMTAB_TO_SYMTAB (ps
);
1430 for (i
= 0; i
< b
->nsyms
; i
++)
1432 fixup_symbol_section (b
->sym
[i
], objfile
);
1433 if (section
== SYMBOL_BFD_SECTION (b
->sym
[i
]))
1437 continue; /* no symbol in this symtab matches section */
1439 distance
= BLOCK_END (b
) - BLOCK_START (b
);
1448 ps
= find_pc_sect_psymtab (pc
, section
);
1452 /* Might want to error() here (in case symtab is corrupt and
1453 will cause a core dump), but maybe we can successfully
1454 continue, so let's not. */
1456 (Internal error: pc 0x%s in read in psymtab, but not in symtab.)\n",
1458 s
= PSYMTAB_TO_SYMTAB (ps
);
1463 /* Find the symtab associated with PC. Look through the psymtabs and
1464 read in another symtab if necessary. Backward compatibility, no section */
1467 find_pc_symtab (CORE_ADDR pc
)
1469 return find_pc_sect_symtab (pc
, find_pc_mapped_section (pc
));
1475 /* Find the closest symbol value (of any sort -- function or variable)
1476 for a given address value. Slow but complete. (currently unused,
1477 mainly because it is too slow. We could fix it if each symtab and
1478 psymtab had contained in it the addresses ranges of each of its
1479 sections, which also would be required to make things like "info
1480 line *0x2345" cause psymtabs to be converted to symtabs). */
1483 find_addr_symbol (CORE_ADDR addr
, struct symtab
**symtabp
, CORE_ADDR
*symaddrp
)
1485 struct symtab
*symtab
, *best_symtab
;
1486 struct objfile
*objfile
;
1487 register int bot
, top
;
1488 register struct symbol
*sym
;
1489 register CORE_ADDR sym_addr
;
1490 struct block
*block
;
1493 /* Info on best symbol seen so far */
1495 register CORE_ADDR best_sym_addr
= 0;
1496 struct symbol
*best_sym
= 0;
1498 /* FIXME -- we should pull in all the psymtabs, too! */
1499 ALL_SYMTABS (objfile
, symtab
)
1501 /* Search the global and static blocks in this symtab for
1502 the closest symbol-address to the desired address. */
1504 for (blocknum
= GLOBAL_BLOCK
; blocknum
<= STATIC_BLOCK
; blocknum
++)
1507 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab
), blocknum
);
1508 top
= BLOCK_NSYMS (block
);
1509 for (bot
= 0; bot
< top
; bot
++)
1511 sym
= BLOCK_SYM (block
, bot
);
1512 switch (SYMBOL_CLASS (sym
))
1516 sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1520 sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1521 /* An indirect symbol really lives at *sym_addr,
1522 * so an indirection needs to be done.
1523 * However, I am leaving this commented out because it's
1524 * expensive, and it's possible that symbolization
1525 * could be done without an active process (in
1526 * case this read_memory will fail). RT
1527 sym_addr = read_memory_unsigned_integer
1528 (sym_addr, TARGET_PTR_BIT / TARGET_CHAR_BIT);
1533 sym_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1540 if (sym_addr
<= addr
)
1541 if (sym_addr
> best_sym_addr
)
1543 /* Quit if we found an exact match. */
1545 best_sym_addr
= sym_addr
;
1546 best_symtab
= symtab
;
1547 if (sym_addr
== addr
)
1556 *symtabp
= best_symtab
;
1558 *symaddrp
= best_sym_addr
;
1563 /* Find the source file and line number for a given PC value and SECTION.
1564 Return a structure containing a symtab pointer, a line number,
1565 and a pc range for the entire source line.
1566 The value's .pc field is NOT the specified pc.
1567 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1568 use the line that ends there. Otherwise, in that case, the line
1569 that begins there is used. */
1571 /* The big complication here is that a line may start in one file, and end just
1572 before the start of another file. This usually occurs when you #include
1573 code in the middle of a subroutine. To properly find the end of a line's PC
1574 range, we must search all symtabs associated with this compilation unit, and
1575 find the one whose first PC is closer than that of the next line in this
1578 /* If it's worth the effort, we could be using a binary search. */
1580 struct symtab_and_line
1581 find_pc_sect_line (CORE_ADDR pc
, struct sec
*section
, int notcurrent
)
1584 register struct linetable
*l
;
1587 register struct linetable_entry
*item
;
1588 struct symtab_and_line val
;
1589 struct blockvector
*bv
;
1590 struct minimal_symbol
*msymbol
;
1591 struct minimal_symbol
*mfunsym
;
1593 /* Info on best line seen so far, and where it starts, and its file. */
1595 struct linetable_entry
*best
= NULL
;
1596 CORE_ADDR best_end
= 0;
1597 struct symtab
*best_symtab
= 0;
1599 /* Store here the first line number
1600 of a file which contains the line at the smallest pc after PC.
1601 If we don't find a line whose range contains PC,
1602 we will use a line one less than this,
1603 with a range from the start of that file to the first line's pc. */
1604 struct linetable_entry
*alt
= NULL
;
1605 struct symtab
*alt_symtab
= 0;
1607 /* Info on best line seen in this file. */
1609 struct linetable_entry
*prev
;
1611 /* If this pc is not from the current frame,
1612 it is the address of the end of a call instruction.
1613 Quite likely that is the start of the following statement.
1614 But what we want is the statement containing the instruction.
1615 Fudge the pc to make sure we get that. */
1617 INIT_SAL (&val
); /* initialize to zeroes */
1622 /* elz: added this because this function returned the wrong
1623 information if the pc belongs to a stub (import/export)
1624 to call a shlib function. This stub would be anywhere between
1625 two functions in the target, and the line info was erroneously
1626 taken to be the one of the line before the pc.
1628 /* RT: Further explanation:
1630 * We have stubs (trampolines) inserted between procedures.
1632 * Example: "shr1" exists in a shared library, and a "shr1" stub also
1633 * exists in the main image.
1635 * In the minimal symbol table, we have a bunch of symbols
1636 * sorted by start address. The stubs are marked as "trampoline",
1637 * the others appear as text. E.g.:
1639 * Minimal symbol table for main image
1640 * main: code for main (text symbol)
1641 * shr1: stub (trampoline symbol)
1642 * foo: code for foo (text symbol)
1644 * Minimal symbol table for "shr1" image:
1646 * shr1: code for shr1 (text symbol)
1649 * So the code below is trying to detect if we are in the stub
1650 * ("shr1" stub), and if so, find the real code ("shr1" trampoline),
1651 * and if found, do the symbolization from the real-code address
1652 * rather than the stub address.
1654 * Assumptions being made about the minimal symbol table:
1655 * 1. lookup_minimal_symbol_by_pc() will return a trampoline only
1656 * if we're really in the trampoline. If we're beyond it (say
1657 * we're in "foo" in the above example), it'll have a closer
1658 * symbol (the "foo" text symbol for example) and will not
1659 * return the trampoline.
1660 * 2. lookup_minimal_symbol_text() will find a real text symbol
1661 * corresponding to the trampoline, and whose address will
1662 * be different than the trampoline address. I put in a sanity
1663 * check for the address being the same, to avoid an
1664 * infinite recursion.
1666 msymbol
= lookup_minimal_symbol_by_pc (pc
);
1667 if (msymbol
!= NULL
)
1668 if (MSYMBOL_TYPE (msymbol
) == mst_solib_trampoline
)
1670 mfunsym
= lookup_minimal_symbol_text (SYMBOL_NAME (msymbol
), NULL
, NULL
);
1671 if (mfunsym
== NULL
)
1672 /* I eliminated this warning since it is coming out
1673 * in the following situation:
1674 * gdb shmain // test program with shared libraries
1675 * (gdb) break shr1 // function in shared lib
1676 * Warning: In stub for ...
1677 * In the above situation, the shared lib is not loaded yet,
1678 * so of course we can't find the real func/line info,
1679 * but the "break" still works, and the warning is annoying.
1680 * So I commented out the warning. RT */
1681 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_NAME(msymbol)) */ ;
1683 else if (SYMBOL_VALUE (mfunsym
) == SYMBOL_VALUE (msymbol
))
1684 /* Avoid infinite recursion */
1685 /* See above comment about why warning is commented out */
1686 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_NAME(msymbol)) */ ;
1689 return find_pc_line (SYMBOL_VALUE (mfunsym
), 0);
1693 s
= find_pc_sect_symtab (pc
, section
);
1696 /* if no symbol information, return previous pc */
1703 bv
= BLOCKVECTOR (s
);
1705 /* Look at all the symtabs that share this blockvector.
1706 They all have the same apriori range, that we found was right;
1707 but they have different line tables. */
1709 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1711 /* Find the best line in this symtab. */
1718 /* I think len can be zero if the symtab lacks line numbers
1719 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
1720 I'm not sure which, and maybe it depends on the symbol
1726 item
= l
->item
; /* Get first line info */
1728 /* Is this file's first line closer than the first lines of other files?
1729 If so, record this file, and its first line, as best alternate. */
1730 if (item
->pc
> pc
&& (!alt
|| item
->pc
< alt
->pc
))
1736 for (i
= 0; i
< len
; i
++, item
++)
1738 /* Leave prev pointing to the linetable entry for the last line
1739 that started at or before PC. */
1746 /* At this point, prev points at the line whose start addr is <= pc, and
1747 item points at the next line. If we ran off the end of the linetable
1748 (pc >= start of the last line), then prev == item. If pc < start of
1749 the first line, prev will not be set. */
1751 /* Is this file's best line closer than the best in the other files?
1752 If so, record this file, and its best line, as best so far. */
1754 if (prev
&& (!best
|| prev
->pc
> best
->pc
))
1758 /* If another line is in the linetable, and its PC is closer
1759 than the best_end we currently have, take it as best_end. */
1760 if (i
< len
&& (best_end
== 0 || best_end
> item
->pc
))
1761 best_end
= item
->pc
;
1768 { /* If we didn't find any line # info, just
1774 val
.symtab
= alt_symtab
;
1775 val
.line
= alt
->line
- 1;
1777 /* Don't return line 0, that means that we didn't find the line. */
1781 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1787 val
.symtab
= best_symtab
;
1788 val
.line
= best
->line
;
1790 if (best_end
&& (!alt
|| best_end
< alt
->pc
))
1795 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1797 val
.section
= section
;
1801 /* Backward compatibility (no section) */
1803 struct symtab_and_line
1804 find_pc_line (CORE_ADDR pc
, int notcurrent
)
1808 section
= find_pc_overlay (pc
);
1809 if (pc_in_unmapped_range (pc
, section
))
1810 pc
= overlay_mapped_address (pc
, section
);
1811 return find_pc_sect_line (pc
, section
, notcurrent
);
1814 /* Find line number LINE in any symtab whose name is the same as
1817 If found, return the symtab that contains the linetable in which it was
1818 found, set *INDEX to the index in the linetable of the best entry
1819 found, and set *EXACT_MATCH nonzero if the value returned is an
1822 If not found, return NULL. */
1825 find_line_symtab (struct symtab
*symtab
, int line
, int *index
, int *exact_match
)
1829 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
1833 struct linetable
*best_linetable
;
1834 struct symtab
*best_symtab
;
1836 /* First try looking it up in the given symtab. */
1837 best_linetable
= LINETABLE (symtab
);
1838 best_symtab
= symtab
;
1839 best_index
= find_line_common (best_linetable
, line
, &exact
);
1840 if (best_index
< 0 || !exact
)
1842 /* Didn't find an exact match. So we better keep looking for
1843 another symtab with the same name. In the case of xcoff,
1844 multiple csects for one source file (produced by IBM's FORTRAN
1845 compiler) produce multiple symtabs (this is unavoidable
1846 assuming csects can be at arbitrary places in memory and that
1847 the GLOBAL_BLOCK of a symtab has a begin and end address). */
1849 /* BEST is the smallest linenumber > LINE so far seen,
1850 or 0 if none has been seen so far.
1851 BEST_INDEX and BEST_LINETABLE identify the item for it. */
1854 struct objfile
*objfile
;
1857 if (best_index
>= 0)
1858 best
= best_linetable
->item
[best_index
].line
;
1862 ALL_SYMTABS (objfile
, s
)
1864 struct linetable
*l
;
1867 if (!STREQ (symtab
->filename
, s
->filename
))
1870 ind
= find_line_common (l
, line
, &exact
);
1880 if (best
== 0 || l
->item
[ind
].line
< best
)
1882 best
= l
->item
[ind
].line
;
1895 *index
= best_index
;
1897 *exact_match
= exact
;
1902 /* Set the PC value for a given source file and line number and return true.
1903 Returns zero for invalid line number (and sets the PC to 0).
1904 The source file is specified with a struct symtab. */
1907 find_line_pc (struct symtab
*symtab
, int line
, CORE_ADDR
*pc
)
1909 struct linetable
*l
;
1916 symtab
= find_line_symtab (symtab
, line
, &ind
, NULL
);
1919 l
= LINETABLE (symtab
);
1920 *pc
= l
->item
[ind
].pc
;
1927 /* Find the range of pc values in a line.
1928 Store the starting pc of the line into *STARTPTR
1929 and the ending pc (start of next line) into *ENDPTR.
1930 Returns 1 to indicate success.
1931 Returns 0 if could not find the specified line. */
1934 find_line_pc_range (struct symtab_and_line sal
, CORE_ADDR
*startptr
,
1937 CORE_ADDR startaddr
;
1938 struct symtab_and_line found_sal
;
1941 if (startaddr
== 0 && !find_line_pc (sal
.symtab
, sal
.line
, &startaddr
))
1944 /* This whole function is based on address. For example, if line 10 has
1945 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
1946 "info line *0x123" should say the line goes from 0x100 to 0x200
1947 and "info line *0x355" should say the line goes from 0x300 to 0x400.
1948 This also insures that we never give a range like "starts at 0x134
1949 and ends at 0x12c". */
1951 found_sal
= find_pc_sect_line (startaddr
, sal
.section
, 0);
1952 if (found_sal
.line
!= sal
.line
)
1954 /* The specified line (sal) has zero bytes. */
1955 *startptr
= found_sal
.pc
;
1956 *endptr
= found_sal
.pc
;
1960 *startptr
= found_sal
.pc
;
1961 *endptr
= found_sal
.end
;
1966 /* Given a line table and a line number, return the index into the line
1967 table for the pc of the nearest line whose number is >= the specified one.
1968 Return -1 if none is found. The value is >= 0 if it is an index.
1970 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1973 find_line_common (register struct linetable
*l
, register int lineno
,
1979 /* BEST is the smallest linenumber > LINENO so far seen,
1980 or 0 if none has been seen so far.
1981 BEST_INDEX identifies the item for it. */
1983 int best_index
= -1;
1992 for (i
= 0; i
< len
; i
++)
1994 register struct linetable_entry
*item
= &(l
->item
[i
]);
1996 if (item
->line
== lineno
)
1998 /* Return the first (lowest address) entry which matches. */
2003 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
2010 /* If we got here, we didn't get an exact match. */
2017 find_pc_line_pc_range (CORE_ADDR pc
, CORE_ADDR
*startptr
, CORE_ADDR
*endptr
)
2019 struct symtab_and_line sal
;
2020 sal
= find_pc_line (pc
, 0);
2023 return sal
.symtab
!= 0;
2026 /* Given a function symbol SYM, find the symtab and line for the start
2028 If the argument FUNFIRSTLINE is nonzero, we want the first line
2029 of real code inside the function. */
2031 struct symtab_and_line
2032 find_function_start_sal (struct symbol
*sym
, int funfirstline
)
2035 struct symtab_and_line sal
;
2037 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
2038 fixup_symbol_section (sym
, NULL
);
2040 { /* skip "first line" of function (which is actually its prologue) */
2041 asection
*section
= SYMBOL_BFD_SECTION (sym
);
2042 /* If function is in an unmapped overlay, use its unmapped LMA
2043 address, so that SKIP_PROLOGUE has something unique to work on */
2044 if (section_is_overlay (section
) &&
2045 !section_is_mapped (section
))
2046 pc
= overlay_unmapped_address (pc
, section
);
2048 pc
+= FUNCTION_START_OFFSET
;
2049 pc
= SKIP_PROLOGUE (pc
);
2051 /* For overlays, map pc back into its mapped VMA range */
2052 pc
= overlay_mapped_address (pc
, section
);
2054 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
2056 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2057 /* Convex: no need to suppress code on first line, if any */
2060 /* Check if SKIP_PROLOGUE left us in mid-line, and the next
2061 line is still part of the same function. */
2063 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) <= sal
.end
2064 && sal
.end
< BLOCK_END (SYMBOL_BLOCK_VALUE (sym
)))
2066 /* First pc of next line */
2068 /* Recalculate the line number (might not be N+1). */
2069 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
2077 /* If P is of the form "operator[ \t]+..." where `...' is
2078 some legitimate operator text, return a pointer to the
2079 beginning of the substring of the operator text.
2080 Otherwise, return "". */
2082 operator_chars (char *p
, char **end
)
2085 if (strncmp (p
, "operator", 8))
2089 /* Don't get faked out by `operator' being part of a longer
2091 if (isalpha (*p
) || *p
== '_' || *p
== '$' || *p
== '\0')
2094 /* Allow some whitespace between `operator' and the operator symbol. */
2095 while (*p
== ' ' || *p
== '\t')
2098 /* Recognize 'operator TYPENAME'. */
2100 if (isalpha (*p
) || *p
== '_' || *p
== '$')
2102 register char *q
= p
+ 1;
2103 while (isalnum (*q
) || *q
== '_' || *q
== '$')
2128 if (p
[1] == '=' || p
[1] == p
[0])
2139 error ("`operator ()' must be specified without whitespace in `()'");
2144 error ("`operator ?:' must be specified without whitespace in `?:'");
2149 error ("`operator []' must be specified without whitespace in `[]'");
2153 error ("`operator %s' not supported", p
);
2161 /* Slave routine for sources_info. Force line breaks at ,'s.
2162 NAME is the name to print and *FIRST is nonzero if this is the first
2163 name printed. Set *FIRST to zero. */
2165 output_source_filename (char *name
, int *first
)
2167 /* Table of files printed so far. Since a single source file can
2168 result in several partial symbol tables, we need to avoid printing
2169 it more than once. Note: if some of the psymtabs are read in and
2170 some are not, it gets printed both under "Source files for which
2171 symbols have been read" and "Source files for which symbols will
2172 be read in on demand". I consider this a reasonable way to deal
2173 with the situation. I'm not sure whether this can also happen for
2174 symtabs; it doesn't hurt to check. */
2175 static char **tab
= NULL
;
2176 /* Allocated size of tab in elements.
2177 Start with one 256-byte block (when using GNU malloc.c).
2178 24 is the malloc overhead when range checking is in effect. */
2179 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
2180 /* Current size of tab in elements. */
2181 static int tab_cur_size
;
2188 tab
= (char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
2192 /* Is NAME in tab? */
2193 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
2194 if (STREQ (*p
, name
))
2195 /* Yes; don't print it again. */
2197 /* No; add it to tab. */
2198 if (tab_cur_size
== tab_alloc_size
)
2200 tab_alloc_size
*= 2;
2201 tab
= (char **) xrealloc ((char *) tab
, tab_alloc_size
* sizeof (*tab
));
2203 tab
[tab_cur_size
++] = name
;
2211 printf_filtered (", ");
2215 fputs_filtered (name
, gdb_stdout
);
2219 sources_info (char *ignore
, int from_tty
)
2221 register struct symtab
*s
;
2222 register struct partial_symtab
*ps
;
2223 register struct objfile
*objfile
;
2226 if (!have_full_symbols () && !have_partial_symbols ())
2228 error ("No symbol table is loaded. Use the \"file\" command.");
2231 printf_filtered ("Source files for which symbols have been read in:\n\n");
2234 ALL_SYMTABS (objfile
, s
)
2236 output_source_filename (s
->filename
, &first
);
2238 printf_filtered ("\n\n");
2240 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2243 ALL_PSYMTABS (objfile
, ps
)
2247 output_source_filename (ps
->filename
, &first
);
2250 printf_filtered ("\n");
2254 file_matches (char *file
, char *files
[], int nfiles
)
2258 if (file
!= NULL
&& nfiles
!= 0)
2260 for (i
= 0; i
< nfiles
; i
++)
2262 if (strcmp (files
[i
], basename (file
)) == 0)
2266 else if (nfiles
== 0)
2271 /* Free any memory associated with a search. */
2273 free_search_symbols (struct symbol_search
*symbols
)
2275 struct symbol_search
*p
;
2276 struct symbol_search
*next
;
2278 for (p
= symbols
; p
!= NULL
; p
= next
)
2286 do_free_search_symbols_cleanup (void *symbols
)
2288 free_search_symbols (symbols
);
2292 make_cleanup_free_search_symbols (struct symbol_search
*symbols
)
2294 return make_cleanup (do_free_search_symbols_cleanup
, symbols
);
2298 /* Search the symbol table for matches to the regular expression REGEXP,
2299 returning the results in *MATCHES.
2301 Only symbols of KIND are searched:
2302 FUNCTIONS_NAMESPACE - search all functions
2303 TYPES_NAMESPACE - search all type names
2304 METHODS_NAMESPACE - search all methods NOT IMPLEMENTED
2305 VARIABLES_NAMESPACE - search all symbols, excluding functions, type names,
2306 and constants (enums)
2308 free_search_symbols should be called when *MATCHES is no longer needed.
2311 search_symbols (char *regexp
, namespace_enum kind
, int nfiles
, char *files
[],
2312 struct symbol_search
**matches
)
2314 register struct symtab
*s
;
2315 register struct partial_symtab
*ps
;
2316 register struct blockvector
*bv
;
2317 struct blockvector
*prev_bv
= 0;
2318 register struct block
*b
;
2321 register struct symbol
*sym
;
2322 struct partial_symbol
**psym
;
2323 struct objfile
*objfile
;
2324 struct minimal_symbol
*msymbol
;
2327 static enum minimal_symbol_type types
[]
2329 {mst_data
, mst_text
, mst_abs
, mst_unknown
};
2330 static enum minimal_symbol_type types2
[]
2332 {mst_bss
, mst_file_text
, mst_abs
, mst_unknown
};
2333 static enum minimal_symbol_type types3
[]
2335 {mst_file_data
, mst_solib_trampoline
, mst_abs
, mst_unknown
};
2336 static enum minimal_symbol_type types4
[]
2338 {mst_file_bss
, mst_text
, mst_abs
, mst_unknown
};
2339 enum minimal_symbol_type ourtype
;
2340 enum minimal_symbol_type ourtype2
;
2341 enum minimal_symbol_type ourtype3
;
2342 enum minimal_symbol_type ourtype4
;
2343 struct symbol_search
*sr
;
2344 struct symbol_search
*psr
;
2345 struct symbol_search
*tail
;
2346 struct cleanup
*old_chain
= NULL
;
2348 if (kind
< LABEL_NAMESPACE
)
2349 error ("must search on specific namespace");
2351 ourtype
= types
[(int) (kind
- VARIABLES_NAMESPACE
)];
2352 ourtype2
= types2
[(int) (kind
- VARIABLES_NAMESPACE
)];
2353 ourtype3
= types3
[(int) (kind
- VARIABLES_NAMESPACE
)];
2354 ourtype4
= types4
[(int) (kind
- VARIABLES_NAMESPACE
)];
2356 sr
= *matches
= NULL
;
2361 /* Make sure spacing is right for C++ operators.
2362 This is just a courtesy to make the matching less sensitive
2363 to how many spaces the user leaves between 'operator'
2364 and <TYPENAME> or <OPERATOR>. */
2366 char *opname
= operator_chars (regexp
, &opend
);
2369 int fix
= -1; /* -1 means ok; otherwise number of spaces needed. */
2370 if (isalpha (*opname
) || *opname
== '_' || *opname
== '$')
2372 /* There should 1 space between 'operator' and 'TYPENAME'. */
2373 if (opname
[-1] != ' ' || opname
[-2] == ' ')
2378 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2379 if (opname
[-1] == ' ')
2382 /* If wrong number of spaces, fix it. */
2385 char *tmp
= (char *) alloca (opend
- opname
+ 10);
2386 sprintf (tmp
, "operator%.*s%s", fix
, " ", opname
);
2391 if (0 != (val
= re_comp (regexp
)))
2392 error ("Invalid regexp (%s): %s", val
, regexp
);
2395 /* Search through the partial symtabs *first* for all symbols
2396 matching the regexp. That way we don't have to reproduce all of
2397 the machinery below. */
2399 ALL_PSYMTABS (objfile
, ps
)
2401 struct partial_symbol
**bound
, **gbound
, **sbound
;
2407 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2408 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2411 /* Go through all of the symbols stored in a partial
2412 symtab in one loop. */
2413 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2418 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2420 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2431 /* If it would match (logic taken from loop below)
2432 load the file and go on to the next one */
2433 if (file_matches (ps
->filename
, files
, nfiles
)
2434 && ((regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (*psym
))
2435 && ((kind
== VARIABLES_NAMESPACE
&& SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
2436 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
2437 || (kind
== FUNCTIONS_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
2438 || (kind
== TYPES_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
)
2439 || (kind
== METHODS_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
))))
2441 PSYMTAB_TO_SYMTAB (ps
);
2449 /* Here, we search through the minimal symbol tables for functions
2450 and variables that match, and force their symbols to be read.
2451 This is in particular necessary for demangled variable names,
2452 which are no longer put into the partial symbol tables.
2453 The symbol will then be found during the scan of symtabs below.
2455 For functions, find_pc_symtab should succeed if we have debug info
2456 for the function, for variables we have to call lookup_symbol
2457 to determine if the variable has debug info.
2458 If the lookup fails, set found_misc so that we will rescan to print
2459 any matching symbols without debug info.
2462 if (nfiles
== 0 && (kind
== VARIABLES_NAMESPACE
|| kind
== FUNCTIONS_NAMESPACE
))
2464 ALL_MSYMBOLS (objfile
, msymbol
)
2466 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
2467 MSYMBOL_TYPE (msymbol
) == ourtype2
||
2468 MSYMBOL_TYPE (msymbol
) == ourtype3
||
2469 MSYMBOL_TYPE (msymbol
) == ourtype4
)
2471 if (regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (msymbol
))
2473 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
)))
2475 if (kind
== FUNCTIONS_NAMESPACE
2476 || lookup_symbol (SYMBOL_NAME (msymbol
),
2477 (struct block
*) NULL
,
2479 0, (struct symtab
**) NULL
) == NULL
)
2487 ALL_SYMTABS (objfile
, s
)
2489 bv
= BLOCKVECTOR (s
);
2490 /* Often many files share a blockvector.
2491 Scan each blockvector only once so that
2492 we don't get every symbol many times.
2493 It happens that the first symtab in the list
2494 for any given blockvector is the main file. */
2496 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
2498 b
= BLOCKVECTOR_BLOCK (bv
, i
);
2499 /* Skip the sort if this block is always sorted. */
2500 if (!BLOCK_SHOULD_SORT (b
))
2501 sort_block_syms (b
);
2502 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
2505 sym
= BLOCK_SYM (b
, j
);
2506 if (file_matches (s
->filename
, files
, nfiles
)
2507 && ((regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (sym
))
2508 && ((kind
== VARIABLES_NAMESPACE
&& SYMBOL_CLASS (sym
) != LOC_TYPEDEF
2509 && SYMBOL_CLASS (sym
) != LOC_BLOCK
2510 && SYMBOL_CLASS (sym
) != LOC_CONST
)
2511 || (kind
== FUNCTIONS_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2512 || (kind
== TYPES_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2513 || (kind
== METHODS_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
))))
2516 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
2520 psr
->msymbol
= NULL
;
2525 old_chain
= make_cleanup_free_search_symbols (sr
);
2536 /* If there are no eyes, avoid all contact. I mean, if there are
2537 no debug symbols, then print directly from the msymbol_vector. */
2539 if (found_misc
|| kind
!= FUNCTIONS_NAMESPACE
)
2541 ALL_MSYMBOLS (objfile
, msymbol
)
2543 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
2544 MSYMBOL_TYPE (msymbol
) == ourtype2
||
2545 MSYMBOL_TYPE (msymbol
) == ourtype3
||
2546 MSYMBOL_TYPE (msymbol
) == ourtype4
)
2548 if (regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (msymbol
))
2550 /* Functions: Look up by address. */
2551 if (kind
!= FUNCTIONS_NAMESPACE
||
2552 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
))))
2554 /* Variables/Absolutes: Look up by name */
2555 if (lookup_symbol (SYMBOL_NAME (msymbol
),
2556 (struct block
*) NULL
, VAR_NAMESPACE
,
2557 0, (struct symtab
**) NULL
) == NULL
)
2560 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
2562 psr
->msymbol
= msymbol
;
2569 old_chain
= make_cleanup_free_search_symbols (sr
);
2583 discard_cleanups (old_chain
);
2586 /* Helper function for symtab_symbol_info, this function uses
2587 the data returned from search_symbols() to print information
2588 regarding the match to gdb_stdout.
2591 print_symbol_info (namespace_enum kind
, struct symtab
*s
, struct symbol
*sym
,
2592 int block
, char *last
)
2594 if (last
== NULL
|| strcmp (last
, s
->filename
) != 0)
2596 fputs_filtered ("\nFile ", gdb_stdout
);
2597 fputs_filtered (s
->filename
, gdb_stdout
);
2598 fputs_filtered (":\n", gdb_stdout
);
2601 if (kind
!= TYPES_NAMESPACE
&& block
== STATIC_BLOCK
)
2602 printf_filtered ("static ");
2604 /* Typedef that is not a C++ class */
2605 if (kind
== TYPES_NAMESPACE
2606 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
2607 typedef_print (SYMBOL_TYPE (sym
), sym
, gdb_stdout
);
2608 /* variable, func, or typedef-that-is-c++-class */
2609 else if (kind
< TYPES_NAMESPACE
||
2610 (kind
== TYPES_NAMESPACE
&&
2611 SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
))
2613 type_print (SYMBOL_TYPE (sym
),
2614 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2615 ? "" : SYMBOL_SOURCE_NAME (sym
)),
2618 printf_filtered (";\n");
2623 /* Tiemann says: "info methods was never implemented." */
2624 char *demangled_name
;
2625 c_type_print_base (TYPE_FN_FIELD_TYPE (t
, block
),
2627 c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (t
, block
),
2629 if (TYPE_FN_FIELD_STUB (t
, block
))
2630 check_stub_method (TYPE_DOMAIN_TYPE (type
), j
, block
);
2632 cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t
, block
),
2633 DMGL_ANSI
| DMGL_PARAMS
);
2634 if (demangled_name
== NULL
)
2635 fprintf_filtered (stream
, "<badly mangled name %s>",
2636 TYPE_FN_FIELD_PHYSNAME (t
, block
));
2639 fputs_filtered (demangled_name
, stream
);
2640 free (demangled_name
);
2646 /* This help function for symtab_symbol_info() prints information
2647 for non-debugging symbols to gdb_stdout.
2650 print_msymbol_info (struct minimal_symbol
*msymbol
)
2652 printf_filtered (" %08lx %s\n",
2653 (unsigned long) SYMBOL_VALUE_ADDRESS (msymbol
),
2654 SYMBOL_SOURCE_NAME (msymbol
));
2657 /* This is the guts of the commands "info functions", "info types", and
2658 "info variables". It calls search_symbols to find all matches and then
2659 print_[m]symbol_info to print out some useful information about the
2663 symtab_symbol_info (char *regexp
, namespace_enum kind
, int from_tty
)
2665 static char *classnames
[]
2667 {"variable", "function", "type", "method"};
2668 struct symbol_search
*symbols
;
2669 struct symbol_search
*p
;
2670 struct cleanup
*old_chain
;
2671 char *last_filename
= NULL
;
2674 /* must make sure that if we're interrupted, symbols gets freed */
2675 search_symbols (regexp
, kind
, 0, (char **) NULL
, &symbols
);
2676 old_chain
= make_cleanup_free_search_symbols (symbols
);
2678 printf_filtered (regexp
2679 ? "All %ss matching regular expression \"%s\":\n"
2680 : "All defined %ss:\n",
2681 classnames
[(int) (kind
- VARIABLES_NAMESPACE
)], regexp
);
2683 for (p
= symbols
; p
!= NULL
; p
= p
->next
)
2687 if (p
->msymbol
!= NULL
)
2691 printf_filtered ("\nNon-debugging symbols:\n");
2694 print_msymbol_info (p
->msymbol
);
2698 print_symbol_info (kind
,
2703 last_filename
= p
->symtab
->filename
;
2707 do_cleanups (old_chain
);
2711 variables_info (char *regexp
, int from_tty
)
2713 symtab_symbol_info (regexp
, VARIABLES_NAMESPACE
, from_tty
);
2717 functions_info (char *regexp
, int from_tty
)
2719 symtab_symbol_info (regexp
, FUNCTIONS_NAMESPACE
, from_tty
);
2724 types_info (char *regexp
, int from_tty
)
2726 symtab_symbol_info (regexp
, TYPES_NAMESPACE
, from_tty
);
2730 /* Tiemann says: "info methods was never implemented." */
2732 methods_info (char *regexp
)
2734 symtab_symbol_info (regexp
, METHODS_NAMESPACE
, 0, from_tty
);
2738 /* Breakpoint all functions matching regular expression. */
2741 rbreak_command_wrapper (char *regexp
, int from_tty
)
2743 rbreak_command (regexp
, from_tty
);
2747 rbreak_command (char *regexp
, int from_tty
)
2749 struct symbol_search
*ss
;
2750 struct symbol_search
*p
;
2751 struct cleanup
*old_chain
;
2753 search_symbols (regexp
, FUNCTIONS_NAMESPACE
, 0, (char **) NULL
, &ss
);
2754 old_chain
= make_cleanup_free_search_symbols (ss
);
2756 for (p
= ss
; p
!= NULL
; p
= p
->next
)
2758 if (p
->msymbol
== NULL
)
2760 char *string
= (char *) alloca (strlen (p
->symtab
->filename
)
2761 + strlen (SYMBOL_NAME (p
->symbol
))
2763 strcpy (string
, p
->symtab
->filename
);
2764 strcat (string
, ":'");
2765 strcat (string
, SYMBOL_NAME (p
->symbol
));
2766 strcat (string
, "'");
2767 break_command (string
, from_tty
);
2768 print_symbol_info (FUNCTIONS_NAMESPACE
,
2772 p
->symtab
->filename
);
2776 break_command (SYMBOL_NAME (p
->msymbol
), from_tty
);
2777 printf_filtered ("<function, no debug info> %s;\n",
2778 SYMBOL_SOURCE_NAME (p
->msymbol
));
2782 do_cleanups (old_chain
);
2786 /* Return Nonzero if block a is lexically nested within block b,
2787 or if a and b have the same pc range.
2788 Return zero otherwise. */
2790 contained_in (struct block
*a
, struct block
*b
)
2794 return BLOCK_START (a
) >= BLOCK_START (b
)
2795 && BLOCK_END (a
) <= BLOCK_END (b
);
2799 /* Helper routine for make_symbol_completion_list. */
2801 static int return_val_size
;
2802 static int return_val_index
;
2803 static char **return_val
;
2805 #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
2807 if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \
2808 /* Put only the mangled name on the list. */ \
2809 /* Advantage: "b foo<TAB>" completes to "b foo(int, int)" */ \
2810 /* Disadvantage: "b foo__i<TAB>" doesn't complete. */ \
2811 completion_list_add_name \
2812 (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \
2814 completion_list_add_name \
2815 (SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \
2818 /* Test to see if the symbol specified by SYMNAME (which is already
2819 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
2820 characters. If so, add it to the current completion list. */
2823 completion_list_add_name (char *symname
, char *sym_text
, int sym_text_len
,
2824 char *text
, char *word
)
2829 /* clip symbols that cannot match */
2831 if (strncmp (symname
, sym_text
, sym_text_len
) != 0)
2836 /* Clip any symbol names that we've already considered. (This is a
2837 time optimization) */
2839 for (i
= 0; i
< return_val_index
; ++i
)
2841 if (STREQ (symname
, return_val
[i
]))
2847 /* We have a match for a completion, so add SYMNAME to the current list
2848 of matches. Note that the name is moved to freshly malloc'd space. */
2852 if (word
== sym_text
)
2854 new = xmalloc (strlen (symname
) + 5);
2855 strcpy (new, symname
);
2857 else if (word
> sym_text
)
2859 /* Return some portion of symname. */
2860 new = xmalloc (strlen (symname
) + 5);
2861 strcpy (new, symname
+ (word
- sym_text
));
2865 /* Return some of SYM_TEXT plus symname. */
2866 new = xmalloc (strlen (symname
) + (sym_text
- word
) + 5);
2867 strncpy (new, word
, sym_text
- word
);
2868 new[sym_text
- word
] = '\0';
2869 strcat (new, symname
);
2872 /* Recheck for duplicates if we intend to add a modified symbol. */
2873 if (word
!= sym_text
)
2875 for (i
= 0; i
< return_val_index
; ++i
)
2877 if (STREQ (new, return_val
[i
]))
2885 if (return_val_index
+ 3 > return_val_size
)
2887 newsize
= (return_val_size
*= 2) * sizeof (char *);
2888 return_val
= (char **) xrealloc ((char *) return_val
, newsize
);
2890 return_val
[return_val_index
++] = new;
2891 return_val
[return_val_index
] = NULL
;
2895 /* Return a NULL terminated array of all symbols (regardless of class) which
2896 begin by matching TEXT. If the answer is no symbols, then the return value
2897 is an array which contains only a NULL pointer.
2899 Problem: All of the symbols have to be copied because readline frees them.
2900 I'm not going to worry about this; hopefully there won't be that many. */
2903 make_symbol_completion_list (char *text
, char *word
)
2905 register struct symbol
*sym
;
2906 register struct symtab
*s
;
2907 register struct partial_symtab
*ps
;
2908 register struct minimal_symbol
*msymbol
;
2909 register struct objfile
*objfile
;
2910 register struct block
*b
, *surrounding_static_block
= 0;
2912 struct partial_symbol
**psym
;
2913 /* The symbol we are completing on. Points in same buffer as text. */
2915 /* Length of sym_text. */
2918 /* Now look for the symbol we are supposed to complete on.
2919 FIXME: This should be language-specific. */
2923 char *quote_pos
= NULL
;
2925 /* First see if this is a quoted string. */
2927 for (p
= text
; *p
!= '\0'; ++p
)
2929 if (quote_found
!= '\0')
2931 if (*p
== quote_found
)
2932 /* Found close quote. */
2934 else if (*p
== '\\' && p
[1] == quote_found
)
2935 /* A backslash followed by the quote character
2936 doesn't end the string. */
2939 else if (*p
== '\'' || *p
== '"')
2945 if (quote_found
== '\'')
2946 /* A string within single quotes can be a symbol, so complete on it. */
2947 sym_text
= quote_pos
+ 1;
2948 else if (quote_found
== '"')
2949 /* A double-quoted string is never a symbol, nor does it make sense
2950 to complete it any other way. */
2954 /* It is not a quoted string. Break it based on the characters
2955 which are in symbols. */
2958 if (isalnum (p
[-1]) || p
[-1] == '_' || p
[-1] == '\0')
2967 sym_text_len
= strlen (sym_text
);
2969 return_val_size
= 100;
2970 return_val_index
= 0;
2971 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
2972 return_val
[0] = NULL
;
2974 /* Look through the partial symtabs for all symbols which begin
2975 by matching SYM_TEXT. Add each one that you find to the list. */
2977 ALL_PSYMTABS (objfile
, ps
)
2979 /* If the psymtab's been read in we'll get it when we search
2980 through the blockvector. */
2984 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2985 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
2986 + ps
->n_global_syms
);
2989 /* If interrupted, then quit. */
2991 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
2994 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2995 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
2996 + ps
->n_static_syms
);
3000 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3004 /* At this point scan through the misc symbol vectors and add each
3005 symbol you find to the list. Eventually we want to ignore
3006 anything that isn't a text symbol (everything else will be
3007 handled by the psymtab code above). */
3009 ALL_MSYMBOLS (objfile
, msymbol
)
3012 COMPLETION_LIST_ADD_SYMBOL (msymbol
, sym_text
, sym_text_len
, text
, word
);
3015 /* Search upwards from currently selected frame (so that we can
3016 complete on local vars. */
3018 for (b
= get_selected_block (); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
3020 if (!BLOCK_SUPERBLOCK (b
))
3022 surrounding_static_block
= b
; /* For elmin of dups */
3025 /* Also catch fields of types defined in this places which match our
3026 text string. Only complete on types visible from current context. */
3028 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3030 sym
= BLOCK_SYM (b
, i
);
3031 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3032 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3034 struct type
*t
= SYMBOL_TYPE (sym
);
3035 enum type_code c
= TYPE_CODE (t
);
3037 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
3039 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
3041 if (TYPE_FIELD_NAME (t
, j
))
3043 completion_list_add_name (TYPE_FIELD_NAME (t
, j
),
3044 sym_text
, sym_text_len
, text
, word
);
3052 /* Go through the symtabs and check the externs and statics for
3053 symbols which match. */
3055 ALL_SYMTABS (objfile
, s
)
3058 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3059 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3061 sym
= BLOCK_SYM (b
, i
);
3062 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3066 ALL_SYMTABS (objfile
, s
)
3069 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3070 /* Don't do this block twice. */
3071 if (b
== surrounding_static_block
)
3073 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3075 sym
= BLOCK_SYM (b
, i
);
3076 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3080 return (return_val
);
3083 /* Determine if PC is in the prologue of a function. The prologue is the area
3084 between the first instruction of a function, and the first executable line.
3085 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
3087 If non-zero, func_start is where we think the prologue starts, possibly
3088 by previous examination of symbol table information.
3092 in_prologue (CORE_ADDR pc
, CORE_ADDR func_start
)
3094 struct symtab_and_line sal
;
3095 CORE_ADDR func_addr
, func_end
;
3097 /* We have several sources of information we can consult to figure
3099 - Compilers usually emit line number info that marks the prologue
3100 as its own "source line". So the ending address of that "line"
3101 is the end of the prologue. If available, this is the most
3103 - The minimal symbols and partial symbols, which can usually tell
3104 us the starting and ending addresses of a function.
3105 - If we know the function's start address, we can call the
3106 architecture-defined SKIP_PROLOGUE function to analyze the
3107 instruction stream and guess where the prologue ends.
3108 - Our `func_start' argument; if non-zero, this is the caller's
3109 best guess as to the function's entry point. At the time of
3110 this writing, handle_inferior_event doesn't get this right, so
3111 it should be our last resort. */
3113 /* Consult the partial symbol table, to find which function
3115 if (! find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
3117 CORE_ADDR prologue_end
;
3119 /* We don't even have minsym information, so fall back to using
3120 func_start, if given. */
3122 return 1; /* We *might* be in a prologue. */
3124 prologue_end
= SKIP_PROLOGUE (func_start
);
3126 return func_start
<= pc
&& pc
< prologue_end
;
3129 /* If we have line number information for the function, that's
3130 usually pretty reliable. */
3131 sal
= find_pc_line (func_addr
, 0);
3133 /* Now sal describes the source line at the function's entry point,
3134 which (by convention) is the prologue. The end of that "line",
3135 sal.end, is the end of the prologue.
3137 Note that, for functions whose source code is all on a single
3138 line, the line number information doesn't always end up this way.
3139 So we must verify that our purported end-of-prologue address is
3140 *within* the function, not at its start or end. */
3142 || sal
.end
<= func_addr
3143 || func_end
<= sal
.end
)
3145 /* We don't have any good line number info, so use the minsym
3146 information, together with the architecture-specific prologue
3148 CORE_ADDR prologue_end
= SKIP_PROLOGUE (func_addr
);
3150 return func_addr
<= pc
&& pc
< prologue_end
;
3153 /* We have line number info, and it looks good. */
3154 return func_addr
<= pc
&& pc
< sal
.end
;
3158 /* Begin overload resolution functions */
3159 /* Helper routine for make_symbol_completion_list. */
3161 static int sym_return_val_size
;
3162 static int sym_return_val_index
;
3163 static struct symbol
**sym_return_val
;
3165 /* Test to see if the symbol specified by SYMNAME (which is already
3166 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3167 characters. If so, add it to the current completion list. */
3170 overload_list_add_symbol (struct symbol
*sym
, char *oload_name
)
3175 /* Get the demangled name without parameters */
3176 char *sym_name
= cplus_demangle (SYMBOL_NAME (sym
), DMGL_ARM
| DMGL_ANSI
);
3179 sym_name
= (char *) xmalloc (strlen (SYMBOL_NAME (sym
)) + 1);
3180 strcpy (sym_name
, SYMBOL_NAME (sym
));
3183 /* skip symbols that cannot match */
3184 if (strcmp (sym_name
, oload_name
) != 0)
3190 /* If there is no type information, we can't do anything, so skip */
3191 if (SYMBOL_TYPE (sym
) == NULL
)
3194 /* skip any symbols that we've already considered. */
3195 for (i
= 0; i
< sym_return_val_index
; ++i
)
3196 if (!strcmp (SYMBOL_NAME (sym
), SYMBOL_NAME (sym_return_val
[i
])))
3199 /* We have a match for an overload instance, so add SYM to the current list
3200 * of overload instances */
3201 if (sym_return_val_index
+ 3 > sym_return_val_size
)
3203 newsize
= (sym_return_val_size
*= 2) * sizeof (struct symbol
*);
3204 sym_return_val
= (struct symbol
**) xrealloc ((char *) sym_return_val
, newsize
);
3206 sym_return_val
[sym_return_val_index
++] = sym
;
3207 sym_return_val
[sym_return_val_index
] = NULL
;
3212 /* Return a null-terminated list of pointers to function symbols that
3213 * match name of the supplied symbol FSYM.
3214 * This is used in finding all overloaded instances of a function name.
3215 * This has been modified from make_symbol_completion_list. */
3219 make_symbol_overload_list (struct symbol
*fsym
)
3221 register struct symbol
*sym
;
3222 register struct symtab
*s
;
3223 register struct partial_symtab
*ps
;
3224 register struct objfile
*objfile
;
3225 register struct block
*b
, *surrounding_static_block
= 0;
3227 /* The name we are completing on. */
3228 char *oload_name
= NULL
;
3229 /* Length of name. */
3230 int oload_name_len
= 0;
3232 /* Look for the symbol we are supposed to complete on.
3233 * FIXME: This should be language-specific. */
3235 oload_name
= cplus_demangle (SYMBOL_NAME (fsym
), DMGL_ARM
| DMGL_ANSI
);
3238 oload_name
= (char *) xmalloc (strlen (SYMBOL_NAME (fsym
)) + 1);
3239 strcpy (oload_name
, SYMBOL_NAME (fsym
));
3241 oload_name_len
= strlen (oload_name
);
3243 sym_return_val_size
= 100;
3244 sym_return_val_index
= 0;
3245 sym_return_val
= (struct symbol
**) xmalloc ((sym_return_val_size
+ 1) * sizeof (struct symbol
*));
3246 sym_return_val
[0] = NULL
;
3248 /* Look through the partial symtabs for all symbols which begin
3249 by matching OLOAD_NAME. Make sure we read that symbol table in. */
3251 ALL_PSYMTABS (objfile
, ps
)
3253 struct partial_symbol
**psym
;
3255 /* If the psymtab's been read in we'll get it when we search
3256 through the blockvector. */
3260 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
3261 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
3262 + ps
->n_global_syms
);
3265 /* If interrupted, then quit. */
3267 /* This will cause the symbol table to be read if it has not yet been */
3268 s
= PSYMTAB_TO_SYMTAB (ps
);
3271 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
3272 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
3273 + ps
->n_static_syms
);
3277 /* This will cause the symbol table to be read if it has not yet been */
3278 s
= PSYMTAB_TO_SYMTAB (ps
);
3282 /* Search upwards from currently selected frame (so that we can
3283 complete on local vars. */
3285 for (b
= get_selected_block (); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
3287 if (!BLOCK_SUPERBLOCK (b
))
3289 surrounding_static_block
= b
; /* For elimination of dups */
3292 /* Also catch fields of types defined in this places which match our
3293 text string. Only complete on types visible from current context. */
3295 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3297 sym
= BLOCK_SYM (b
, i
);
3298 overload_list_add_symbol (sym
, oload_name
);
3302 /* Go through the symtabs and check the externs and statics for
3303 symbols which match. */
3305 ALL_SYMTABS (objfile
, s
)
3308 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3309 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3311 sym
= BLOCK_SYM (b
, i
);
3312 overload_list_add_symbol (sym
, oload_name
);
3316 ALL_SYMTABS (objfile
, s
)
3319 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3320 /* Don't do this block twice. */
3321 if (b
== surrounding_static_block
)
3323 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3325 sym
= BLOCK_SYM (b
, i
);
3326 overload_list_add_symbol (sym
, oload_name
);
3332 return (sym_return_val
);
3335 /* End of overload resolution functions */
3337 struct symtabs_and_lines
3338 decode_line_spec (char *string
, int funfirstline
)
3340 struct symtabs_and_lines sals
;
3342 error ("Empty line specification.");
3343 sals
= decode_line_1 (&string
, funfirstline
,
3344 current_source_symtab
, current_source_line
,
3347 error ("Junk at end of line specification: %s", string
);
3352 _initialize_symtab (void)
3354 add_info ("variables", variables_info
,
3355 "All global and static variable names, or those matching REGEXP.");
3357 add_com ("whereis", class_info
, variables_info
,
3358 "All global and static variable names, or those matching REGEXP.");
3360 add_info ("functions", functions_info
,
3361 "All function names, or those matching REGEXP.");
3364 /* FIXME: This command has at least the following problems:
3365 1. It prints builtin types (in a very strange and confusing fashion).
3366 2. It doesn't print right, e.g. with
3367 typedef struct foo *FOO
3368 type_print prints "FOO" when we want to make it (in this situation)
3369 print "struct foo *".
3370 I also think "ptype" or "whatis" is more likely to be useful (but if
3371 there is much disagreement "info types" can be fixed). */
3372 add_info ("types", types_info
,
3373 "All type names, or those matching REGEXP.");
3376 add_info ("methods", methods_info
,
3377 "All method names, or those matching REGEXP::REGEXP.\n\
3378 If the class qualifier is omitted, it is assumed to be the current scope.\n\
3379 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
3382 add_info ("sources", sources_info
,
3383 "Source files in the program.");
3385 add_com ("rbreak", class_breakpoint
, rbreak_command
,
3386 "Set a breakpoint for all functions matching REGEXP.");
3390 add_com ("lf", class_info
, sources_info
, "Source files in the program");
3391 add_com ("lg", class_info
, variables_info
,
3392 "All global and static variable names, or those matching REGEXP.");
3395 /* Initialize the one built-in type that isn't language dependent... */
3396 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
3397 "<unknown type>", (struct objfile
*) NULL
);