1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 1997
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 #include "call-cmds.h"
32 #include "gnu-regex.h"
33 #include "expression.h"
40 #include <sys/types.h>
42 #include "gdb_string.h"
46 /* Prototypes for local functions */
49 find_methods
PARAMS ((struct type
*, char *, struct symbol
**));
52 completion_list_add_name
PARAMS ((char *, char *, int, char *, char *));
55 build_canonical_line_spec
PARAMS ((struct symtab_and_line
*, char *, char ***));
57 static struct symtabs_and_lines
58 decode_line_2
PARAMS ((struct symbol
*[], int, int, char ***));
61 rbreak_command
PARAMS ((char *, int));
64 types_info
PARAMS ((char *, int));
67 functions_info
PARAMS ((char *, int));
70 variables_info
PARAMS ((char *, int));
73 sources_info
PARAMS ((char *, int));
76 output_source_filename
PARAMS ((char *, int *));
79 operator_chars
PARAMS ((char *, char **));
81 static int find_line_common
PARAMS ((struct linetable
*, int, int *));
83 static struct partial_symbol
*
84 lookup_partial_symbol
PARAMS ((struct partial_symtab
*, const char *,
85 int, namespace_enum
));
87 static struct partial_symbol
*
88 fixup_psymbol_section
PARAMS ((struct partial_symbol
*, struct objfile
*));
90 static struct symtab
*
91 lookup_symtab_1
PARAMS ((char *));
94 cplusplus_hint
PARAMS ((char *));
96 static struct symbol
*
97 find_active_alias
PARAMS ((struct symbol
*sym
, CORE_ADDR addr
));
101 /* The single non-language-specific builtin type */
102 struct type
*builtin_type_error
;
104 /* Block in which the most recently searched-for symbol was found.
105 Might be better to make this a parameter to lookup_symbol and
108 const struct block
*block_found
;
110 char no_symtab_msg
[] = "No symbol table is loaded. Use the \"file\" command.";
112 /* While the C++ support is still in flux, issue a possibly helpful hint on
113 using the new command completion feature on single quoted demangled C++
114 symbols. Remove when loose ends are cleaned up. FIXME -fnf */
117 cplusplus_hint (name
)
120 while (*name
== '\'')
122 printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name
, name
);
123 printf_filtered ("(Note leading single quote.)\n");
126 /* Check for a symtab of a specific name; first in symtabs, then in
127 psymtabs. *If* there is no '/' in the name, a match after a '/'
128 in the symtab filename will also work. */
130 static struct symtab
*
131 lookup_symtab_1 (name
)
134 register struct symtab
*s
;
135 register struct partial_symtab
*ps
;
136 register char *slash
;
137 register struct objfile
*objfile
;
141 /* First, search for an exact match */
143 ALL_SYMTABS (objfile
, s
)
144 if (STREQ (name
, s
->filename
))
147 slash
= strchr (name
, '/');
149 /* Now, search for a matching tail (only if name doesn't have any dirs) */
152 ALL_SYMTABS (objfile
, s
)
154 char *p
= s
-> filename
;
155 char *tail
= strrchr (p
, '/');
164 /* Same search rules as above apply here, but now we look thru the
167 ps
= lookup_partial_symtab (name
);
172 error ("Internal: readin %s pst for `%s' found when no symtab found.",
173 ps
-> filename
, name
);
175 s
= PSYMTAB_TO_SYMTAB (ps
);
180 /* At this point, we have located the psymtab for this file, but
181 the conversion to a symtab has failed. This usually happens
182 when we are looking up an include file. In this case,
183 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
184 been created. So, we need to run through the symtabs again in
185 order to find the file.
186 XXX - This is a crock, and should be fixed inside of the the
187 symbol parsing routines. */
191 /* Lookup the symbol table of a source file named NAME. Try a couple
192 of variations if the first lookup doesn't work. */
198 register struct symtab
*s
;
203 s
= lookup_symtab_1 (name
);
207 /* This screws c-exp.y:yylex if there is both a type "tree" and a symtab
210 /* If name not found as specified, see if adding ".c" helps. */
211 /* Why is this? Is it just a user convenience? (If so, it's pretty
212 questionable in the presence of C++, FORTRAN, etc.). It's not in
215 copy
= (char *) alloca (strlen (name
) + 3);
218 s
= lookup_symtab_1 (copy
);
222 /* We didn't find anything; die. */
226 /* Lookup the partial symbol table of a source file named NAME.
227 *If* there is no '/' in the name, a match after a '/'
228 in the psymtab filename will also work. */
230 struct partial_symtab
*
231 lookup_partial_symtab (name
)
234 register struct partial_symtab
*pst
;
235 register struct objfile
*objfile
;
237 ALL_PSYMTABS (objfile
, pst
)
239 if (STREQ (name
, pst
-> filename
))
245 /* Now, search for a matching tail (only if name doesn't have any dirs) */
247 if (!strchr (name
, '/'))
248 ALL_PSYMTABS (objfile
, pst
)
250 char *p
= pst
-> filename
;
251 char *tail
= strrchr (p
, '/');
263 /* Mangle a GDB method stub type. This actually reassembles the pieces of the
264 full method name, which consist of the class name (from T), the unadorned
265 method name from METHOD_ID, and the signature for the specific overload,
266 specified by SIGNATURE_ID. Note that this function is g++ specific. */
269 gdb_mangle_name (type
, method_id
, signature_id
)
271 int method_id
, signature_id
;
273 int mangled_name_len
;
275 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
276 struct fn_field
*method
= &f
[signature_id
];
277 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, method_id
);
278 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, signature_id
);
279 char *newname
= type_name_no_tag (type
);
281 /* Does the form of physname indicate that it is the full mangled name
282 of a constructor (not just the args)? */
283 int is_full_physname_constructor
;
286 int is_destructor
= DESTRUCTOR_PREFIX_P (physname
);
287 /* Need a new type prefix. */
288 char *const_prefix
= method
->is_const
? "C" : "";
289 char *volatile_prefix
= method
->is_volatile
? "V" : "";
291 int len
= (newname
== NULL
? 0 : strlen (newname
));
293 is_full_physname_constructor
=
294 ((physname
[0]=='_' && physname
[1]=='_' &&
295 (isdigit(physname
[2]) || physname
[2]=='Q' || physname
[2]=='t'))
296 || (strncmp(physname
, "__ct", 4) == 0));
299 is_full_physname_constructor
|| (newname
&& STREQ(field_name
, newname
));
302 is_destructor
= (strncmp(physname
, "__dt", 4) == 0);
304 if (is_destructor
|| is_full_physname_constructor
)
306 mangled_name
= (char*) xmalloc(strlen(physname
)+1);
307 strcpy(mangled_name
, physname
);
313 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
315 else if (physname
[0] == 't' || physname
[0] == 'Q')
317 /* The physname for template and qualified methods already includes
319 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
325 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
327 mangled_name_len
= ((is_constructor
? 0 : strlen (field_name
))
332 /* Only needed for GNU-mangled names. ANSI-mangled names
333 work with the normal mechanisms. */
334 if (OPNAME_PREFIX_P (field_name
))
336 const char *opname
= cplus_mangle_opname (field_name
+ 3, 0);
338 error ("No mangling for \"%s\"", field_name
);
339 mangled_name_len
+= strlen (opname
);
340 mangled_name
= (char *)xmalloc (mangled_name_len
);
342 strncpy (mangled_name
, field_name
, 3);
343 mangled_name
[3] = '\0';
344 strcat (mangled_name
, opname
);
348 mangled_name
= (char *)xmalloc (mangled_name_len
);
350 mangled_name
[0] = '\0';
352 strcpy (mangled_name
, field_name
);
354 strcat (mangled_name
, buf
);
355 /* If the class doesn't have a name, i.e. newname NULL, then we just
356 mangle it using 0 for the length of the class. Thus it gets mangled
357 as something starting with `::' rather than `classname::'. */
359 strcat (mangled_name
, newname
);
361 strcat (mangled_name
, physname
);
362 return (mangled_name
);
367 /* Find which partial symtab on contains PC and SECTION. Return 0 if none. */
369 struct partial_symtab
*
370 find_pc_sect_psymtab (pc
, section
)
374 register struct partial_symtab
*pst
;
375 register struct objfile
*objfile
;
377 ALL_PSYMTABS (objfile
, pst
)
379 if (pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
381 struct minimal_symbol
*msymbol
;
382 struct partial_symtab
*tpst
;
384 /* An objfile that has its functions reordered might have
385 many partial symbol tables containing the PC, but
386 we want the partial symbol table that contains the
387 function containing the PC. */
388 if (!(objfile
->flags
& OBJF_REORDERED
) &&
389 section
== 0) /* can't validate section this way */
392 msymbol
= lookup_minimal_symbol_by_pc_section (pc
, section
);
396 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
398 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
400 struct partial_symbol
*p
;
402 p
= find_pc_sect_psymbol (tpst
, pc
, section
);
404 && SYMBOL_VALUE_ADDRESS(p
)
405 == SYMBOL_VALUE_ADDRESS (msymbol
))
415 /* Find which partial symtab contains PC. Return 0 if none.
416 Backward compatibility, no section */
418 struct partial_symtab
*
422 return find_pc_sect_psymtab (pc
, find_pc_mapped_section (pc
));
425 /* Find which partial symbol within a psymtab matches PC and SECTION.
426 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
428 struct partial_symbol
*
429 find_pc_sect_psymbol (psymtab
, pc
, section
)
430 struct partial_symtab
*psymtab
;
434 struct partial_symbol
*best
= NULL
, *p
, **pp
;
438 psymtab
= find_pc_sect_psymtab (pc
, section
);
442 best_pc
= psymtab
->textlow
- 1;
444 /* Search the global symbols as well as the static symbols, so that
445 find_pc_partial_function doesn't use a minimal symbol and thus
446 cache a bad endaddr. */
447 for (pp
= psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
448 (pp
- (psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
449 < psymtab
->n_global_syms
);
453 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
454 && SYMBOL_CLASS (p
) == LOC_BLOCK
455 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
456 && SYMBOL_VALUE_ADDRESS (p
) > best_pc
)
458 if (section
) /* match on a specific section */
460 fixup_psymbol_section (p
, psymtab
->objfile
);
461 if (SYMBOL_BFD_SECTION (p
) != section
)
464 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
468 for (pp
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
469 (pp
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
470 < psymtab
->n_static_syms
);
474 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
475 && SYMBOL_CLASS (p
) == LOC_BLOCK
476 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
477 && SYMBOL_VALUE_ADDRESS (p
) > best_pc
)
479 if (section
) /* match on a specific section */
481 fixup_psymbol_section (p
, psymtab
->objfile
);
482 if (SYMBOL_BFD_SECTION (p
) != section
)
485 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
489 if (best_pc
== psymtab
->textlow
- 1)
494 /* Find which partial symbol within a psymtab matches PC. Return 0 if none.
495 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
497 struct partial_symbol
*
498 find_pc_psymbol (psymtab
, pc
)
499 struct partial_symtab
*psymtab
;
502 return find_pc_sect_psymbol (psymtab
, pc
, find_pc_mapped_section (pc
));
505 /* Debug symbols usually don't have section information. We need to dig that
506 out of the minimal symbols and stash that in the debug symbol. */
509 fixup_section (ginfo
, objfile
)
510 struct general_symbol_info
*ginfo
;
511 struct objfile
*objfile
;
513 struct minimal_symbol
*msym
;
514 msym
= lookup_minimal_symbol (ginfo
->name
, NULL
, objfile
);
517 ginfo
->bfd_section
= SYMBOL_BFD_SECTION (msym
);
521 fixup_symbol_section (sym
, objfile
)
523 struct objfile
*objfile
;
528 if (SYMBOL_BFD_SECTION (sym
))
531 fixup_section (&sym
->ginfo
, objfile
);
536 static struct partial_symbol
*
537 fixup_psymbol_section (psym
, objfile
)
538 struct partial_symbol
*psym
;
539 struct objfile
*objfile
;
544 if (SYMBOL_BFD_SECTION (psym
))
547 fixup_section (&psym
->ginfo
, objfile
);
552 /* Find the definition for a specified symbol name NAME
553 in namespace NAMESPACE, visible from lexical block BLOCK.
554 Returns the struct symbol pointer, or zero if no symbol is found.
555 If SYMTAB is non-NULL, store the symbol table in which the
556 symbol was found there, or NULL if not found.
557 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
558 NAME is a field of the current implied argument `this'. If so set
559 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
560 BLOCK_FOUND is set to the block in which NAME is found (in the case of
561 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
563 /* This function has a bunch of loops in it and it would seem to be
564 attractive to put in some QUIT's (though I'm not really sure
565 whether it can run long enough to be really important). But there
566 are a few calls for which it would appear to be bad news to quit
567 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and
568 nindy_frame_chain_valid in nindy-tdep.c. (Note that there is C++
569 code below which can error(), but that probably doesn't affect
570 these calls since they are looking for a known variable and thus
571 can probably assume it will never hit the C++ code). */
574 lookup_symbol (name
, block
, namespace, is_a_field_of_this
, symtab
)
576 register const struct block
*block
;
577 const namespace_enum
namespace;
578 int *is_a_field_of_this
;
579 struct symtab
**symtab
;
581 register struct symbol
*sym
;
582 register struct symtab
*s
= NULL
;
583 register struct partial_symtab
*ps
;
584 struct blockvector
*bv
;
585 register struct objfile
*objfile
= NULL
;
586 register struct block
*b
;
587 register struct minimal_symbol
*msymbol
;
589 /* Search specified block and its superiors. */
593 sym
= lookup_block_symbol (block
, name
, namespace);
599 /* Search the list of symtabs for one which contains the
600 address of the start of this block. */
601 ALL_SYMTABS (objfile
, s
)
603 bv
= BLOCKVECTOR (s
);
604 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
605 if (BLOCK_START (b
) <= BLOCK_START (block
)
606 && BLOCK_END (b
) > BLOCK_START (block
))
613 return fixup_symbol_section (sym
, objfile
);
615 block
= BLOCK_SUPERBLOCK (block
);
618 /* FIXME: this code is never executed--block is always NULL at this
619 point. What is it trying to do, anyway? We already should have
620 checked the STATIC_BLOCK above (it is the superblock of top-level
621 blocks). Why is VAR_NAMESPACE special-cased? */
622 /* Don't need to mess with the psymtabs; if we have a block,
623 that file is read in. If we don't, then we deal later with
624 all the psymtab stuff that needs checking. */
625 if (namespace == VAR_NAMESPACE
&& block
!= NULL
)
628 /* Find the right symtab. */
629 ALL_SYMTABS (objfile
, s
)
631 bv
= BLOCKVECTOR (s
);
632 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
633 if (BLOCK_START (b
) <= BLOCK_START (block
)
634 && BLOCK_END (b
) > BLOCK_START (block
))
636 sym
= lookup_block_symbol (b
, name
, VAR_NAMESPACE
);
642 return fixup_symbol_section (sym
, objfile
);
649 /* C++: If requested to do so by the caller,
650 check to see if NAME is a field of `this'. */
651 if (is_a_field_of_this
)
653 struct value
*v
= value_of_this (0);
655 *is_a_field_of_this
= 0;
656 if (v
&& check_field (v
, name
))
658 *is_a_field_of_this
= 1;
665 /* Now search all global blocks. Do the symtab's first, then
666 check the psymtab's */
668 ALL_SYMTABS (objfile
, s
)
670 bv
= BLOCKVECTOR (s
);
671 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
672 sym
= lookup_block_symbol (block
, name
, namespace);
678 return fixup_symbol_section (sym
, objfile
);
682 /* Check for the possibility of the symbol being a function or
683 a mangled variable that is stored in one of the minimal symbol tables.
684 Eventually, all global symbols might be resolved in this way. */
686 if (namespace == VAR_NAMESPACE
)
688 msymbol
= lookup_minimal_symbol (name
, NULL
, NULL
);
691 s
= find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol
),
692 SYMBOL_BFD_SECTION (msymbol
));
695 /* This is a function which has a symtab for its address. */
696 bv
= BLOCKVECTOR (s
);
697 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
698 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
700 /* We kept static functions in minimal symbol table as well as
701 in static scope. We want to find them in the symbol table. */
703 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
704 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
708 /* sym == 0 if symbol was found in the minimal symbol table
709 but not in the symtab.
710 Return 0 to use the msymbol definition of "foo_".
712 This happens for Fortran "foo_" symbols,
713 which are "foo" in the symtab.
715 This can also happen if "asm" is used to make a
716 regular symbol but not a debugging symbol, e.g.
723 return fixup_symbol_section (sym
, objfile
);
725 else if (MSYMBOL_TYPE (msymbol
) != mst_text
726 && MSYMBOL_TYPE (msymbol
) != mst_file_text
727 && !STREQ (name
, SYMBOL_NAME (msymbol
)))
729 /* This is a mangled variable, look it up by its
731 return lookup_symbol (SYMBOL_NAME (msymbol
), block
,
732 namespace, is_a_field_of_this
, symtab
);
734 /* There are no debug symbols for this file, or we are looking
735 for an unmangled variable.
736 Try to find a matching static symbol below. */
740 ALL_PSYMTABS (objfile
, ps
)
742 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
744 s
= PSYMTAB_TO_SYMTAB(ps
);
745 bv
= BLOCKVECTOR (s
);
746 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
747 sym
= lookup_block_symbol (block
, name
, namespace);
749 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab", name
, ps
->filename
);
752 return fixup_symbol_section (sym
, objfile
);
756 /* Now search all per-file blocks.
757 Not strictly correct, but more useful than an error.
758 Do the symtabs first, then check the psymtabs */
760 ALL_SYMTABS (objfile
, s
)
762 bv
= BLOCKVECTOR (s
);
763 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
764 sym
= lookup_block_symbol (block
, name
, namespace);
770 return fixup_symbol_section (sym
, objfile
);
774 ALL_PSYMTABS (objfile
, ps
)
776 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
778 s
= PSYMTAB_TO_SYMTAB(ps
);
779 bv
= BLOCKVECTOR (s
);
780 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
781 sym
= lookup_block_symbol (block
, name
, namespace);
783 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab", name
, ps
->filename
);
786 return fixup_symbol_section (sym
, objfile
);
795 /* Look, in partial_symtab PST, for symbol NAME. Check the global
796 symbols if GLOBAL, the static symbols if not */
798 static struct partial_symbol
*
799 lookup_partial_symbol (pst
, name
, global
, namespace)
800 struct partial_symtab
*pst
;
803 namespace_enum
namespace;
805 struct partial_symbol
**start
, **psym
;
806 struct partial_symbol
**top
, **bottom
, **center
;
807 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
808 int do_linear_search
= 1;
816 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
817 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
819 if (global
) /* This means we can use a binary search. */
821 do_linear_search
= 0;
823 /* Binary search. This search is guaranteed to end with center
824 pointing at the earliest partial symbol with the correct
825 name. At that point *all* partial symbols with that name
826 will be checked against the correct namespace. */
829 top
= start
+ length
- 1;
832 center
= bottom
+ (top
- bottom
) / 2;
835 if (!do_linear_search
836 && (SYMBOL_LANGUAGE (*center
) == language_cplus
837 /* start-sanitize-java */
838 || SYMBOL_LANGUAGE (*center
) == language_java
839 /* end-sanitize-java */
842 do_linear_search
= 1;
844 if (STRCMP (SYMBOL_NAME (*center
), name
) >= 0)
853 if (!(top
== bottom
))
855 while (STREQ (SYMBOL_NAME (*top
), name
))
857 if (SYMBOL_NAMESPACE (*top
) == namespace)
865 /* Can't use a binary search or else we found during the binary search that
866 we should also do a linear search. */
868 if (do_linear_search
)
870 for (psym
= start
; psym
< start
+ length
; psym
++)
872 if (namespace == SYMBOL_NAMESPACE (*psym
))
874 if (SYMBOL_MATCHES_NAME (*psym
, name
))
885 /* Find the psymtab containing main(). */
886 /* FIXME: What about languages without main() or specially linked
887 executables that have no main() ? */
889 struct partial_symtab
*
892 register struct partial_symtab
*pst
;
893 register struct objfile
*objfile
;
895 ALL_PSYMTABS (objfile
, pst
)
897 if (lookup_partial_symbol (pst
, "main", 1, VAR_NAMESPACE
))
905 /* Search BLOCK for symbol NAME in NAMESPACE.
907 Note that if NAME is the demangled form of a C++ symbol, we will fail
908 to find a match during the binary search of the non-encoded names, but
909 for now we don't worry about the slight inefficiency of looking for
910 a match we'll never find, since it will go pretty quick. Once the
911 binary search terminates, we drop through and do a straight linear
912 search on the symbols. Each symbol which is marked as being a C++
913 symbol (language_cplus set) has both the encoded and non-encoded names
914 tested for a match. */
917 lookup_block_symbol (block
, name
, namespace)
918 register const struct block
*block
;
920 const namespace_enum
namespace;
922 register int bot
, top
, inc
;
923 register struct symbol
*sym
;
924 register struct symbol
*sym_found
= NULL
;
925 register int do_linear_search
= 1;
927 /* If the blocks's symbols were sorted, start with a binary search. */
929 if (BLOCK_SHOULD_SORT (block
))
931 /* Reset the linear search flag so if the binary search fails, we
932 won't do the linear search once unless we find some reason to
933 do so, such as finding a C++ symbol during the binary search.
934 Note that for C++ modules, ALL the symbols in a block should
935 end up marked as C++ symbols. */
937 do_linear_search
= 0;
938 top
= BLOCK_NSYMS (block
);
941 /* Advance BOT to not far before the first symbol whose name is NAME. */
945 inc
= (top
- bot
+ 1);
946 /* No need to keep binary searching for the last few bits worth. */
951 inc
= (inc
>> 1) + bot
;
952 sym
= BLOCK_SYM (block
, inc
);
953 if (!do_linear_search
954 && (SYMBOL_LANGUAGE (sym
) == language_cplus
955 /* start-sanitize-java */
956 || SYMBOL_LANGUAGE (sym
) == language_java
957 /* end-sanitize-java */
960 do_linear_search
= 1;
962 if (SYMBOL_NAME (sym
)[0] < name
[0])
966 else if (SYMBOL_NAME (sym
)[0] > name
[0])
970 else if (STRCMP (SYMBOL_NAME (sym
), name
) < 0)
980 /* Now scan forward until we run out of symbols, find one whose
981 name is greater than NAME, or find one we want. If there is
982 more than one symbol with the right name and namespace, we
983 return the first one; I believe it is now impossible for us
984 to encounter two symbols with the same name and namespace
985 here, because blocks containing argument symbols are no
988 top
= BLOCK_NSYMS (block
);
991 sym
= BLOCK_SYM (block
, bot
);
992 inc
= SYMBOL_NAME (sym
)[0] - name
[0];
995 inc
= STRCMP (SYMBOL_NAME (sym
), name
);
997 if (inc
== 0 && SYMBOL_NAMESPACE (sym
) == namespace)
1009 /* Here if block isn't sorted, or we fail to find a match during the
1010 binary search above. If during the binary search above, we find a
1011 symbol which is a C++ symbol, then we have re-enabled the linear
1012 search flag which was reset when starting the binary search.
1014 This loop is equivalent to the loop above, but hacked greatly for speed.
1016 Note that parameter symbols do not always show up last in the
1017 list; this loop makes sure to take anything else other than
1018 parameter symbols first; it only uses parameter symbols as a
1019 last resort. Note that this only takes up extra computation
1022 if (do_linear_search
)
1024 top
= BLOCK_NSYMS (block
);
1028 sym
= BLOCK_SYM (block
, bot
);
1029 if (SYMBOL_NAMESPACE (sym
) == namespace &&
1030 SYMBOL_MATCHES_NAME (sym
, name
))
1032 /* If SYM has aliases, then use any alias that is active
1033 at the current PC. If no alias is active at the current
1034 PC, then use the main symbol.
1036 ?!? Is checking the current pc correct? Is this routine
1037 ever called to look up a symbol from another context? */
1038 if (SYMBOL_ALIASES (sym
))
1039 sym
= find_active_alias (sym
, read_pc ());
1042 if (SYMBOL_CLASS (sym
) != LOC_ARG
&&
1043 SYMBOL_CLASS (sym
) != LOC_LOCAL_ARG
&&
1044 SYMBOL_CLASS (sym
) != LOC_REF_ARG
&&
1045 SYMBOL_CLASS (sym
) != LOC_REGPARM
&&
1046 SYMBOL_CLASS (sym
) != LOC_REGPARM_ADDR
&&
1047 SYMBOL_CLASS (sym
) != LOC_BASEREG_ARG
)
1055 return (sym_found
); /* Will be NULL if not found. */
1058 /* Given a main symbol SYM and ADDR, search through the alias
1059 list to determine if an alias is active at ADDR and return
1062 If no alias is active, then return SYM. */
1064 static struct symbol
*
1065 find_active_alias (sym
, addr
)
1069 struct range_list
*r
;
1070 struct alias_list
*aliases
;
1072 /* If we have aliases, check them first. */
1073 aliases
= SYMBOL_ALIASES (sym
);
1077 if (!SYMBOL_RANGES (aliases
->sym
))
1078 return aliases
->sym
;
1079 for (r
= SYMBOL_RANGES (aliases
->sym
); r
; r
= r
->next
)
1081 if (r
->start
<= addr
&& r
->end
> addr
)
1082 return aliases
->sym
;
1084 aliases
= aliases
->next
;
1087 /* Nothing found, return the main symbol. */
1092 /* Return the symbol for the function which contains a specified
1093 lexical block, described by a struct block BL. */
1099 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
1100 bl
= BLOCK_SUPERBLOCK (bl
);
1102 return BLOCK_FUNCTION (bl
);
1105 /* Find the symtab associated with PC and SECTION. Look through the
1106 psymtabs and read in another symtab if necessary. */
1109 find_pc_sect_symtab (pc
, section
)
1113 register struct block
*b
;
1114 struct blockvector
*bv
;
1115 register struct symtab
*s
= NULL
;
1116 register struct symtab
*best_s
= NULL
;
1117 register struct partial_symtab
*ps
;
1118 register struct objfile
*objfile
;
1119 CORE_ADDR distance
= 0;
1121 /* Search all symtabs for the one whose file contains our address, and which
1122 is the smallest of all the ones containing the address. This is designed
1123 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1124 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1125 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1127 This happens for native ecoff format, where code from included files
1128 gets its own symtab. The symtab for the included file should have
1129 been read in already via the dependency mechanism.
1130 It might be swifter to create several symtabs with the same name
1131 like xcoff does (I'm not sure).
1133 It also happens for objfiles that have their functions reordered.
1134 For these, the symtab we are looking for is not necessarily read in. */
1136 ALL_SYMTABS (objfile
, s
)
1138 bv
= BLOCKVECTOR (s
);
1139 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1140 if (BLOCK_START (b
) <= pc
1141 && BLOCK_END (b
) > pc
1143 || BLOCK_END (b
) - BLOCK_START (b
) < distance
))
1145 /* For an objfile that has its functions reordered,
1146 find_pc_psymtab will find the proper partial symbol table
1147 and we simply return its corresponding symtab. */
1148 /* In order to better support objfiles that contain both
1149 stabs and coff debugging info, we continue on if a psymtab
1151 if ((objfile
->flags
& OBJF_REORDERED
) && objfile
->psymtabs
)
1153 ps
= find_pc_sect_psymtab (pc
, section
);
1155 return PSYMTAB_TO_SYMTAB (ps
);
1161 for (i
= 0; i
< b
->nsyms
; i
++)
1163 fixup_symbol_section (b
->sym
[i
], objfile
);
1164 if (section
== SYMBOL_BFD_SECTION (b
->sym
[i
]))
1168 continue; /* no symbol in this symtab matches section */
1170 distance
= BLOCK_END (b
) - BLOCK_START (b
);
1179 ps
= find_pc_sect_psymtab (pc
, section
);
1183 /* Might want to error() here (in case symtab is corrupt and
1184 will cause a core dump), but maybe we can successfully
1185 continue, so let's not. */
1186 /* FIXME-32x64: assumes pc fits in a long */
1188 (Internal error: pc 0x%lx in read in psymtab, but not in symtab.)\n",
1189 (unsigned long) pc
);
1190 s
= PSYMTAB_TO_SYMTAB (ps
);
1195 /* Find the symtab associated with PC. Look through the psymtabs and
1196 read in another symtab if necessary. Backward compatibility, no section */
1202 return find_pc_sect_symtab (pc
, find_pc_mapped_section (pc
));
1208 /* Find the closest symbol value (of any sort -- function or variable)
1209 for a given address value. Slow but complete. (currently unused,
1210 mainly because it is too slow. We could fix it if each symtab and
1211 psymtab had contained in it the addresses ranges of each of its
1212 sections, which also would be required to make things like "info
1213 line *0x2345" cause psymtabs to be converted to symtabs). */
1216 find_addr_symbol (addr
, symtabp
, symaddrp
)
1218 struct symtab
**symtabp
;
1219 CORE_ADDR
*symaddrp
;
1221 struct symtab
*symtab
, *best_symtab
;
1222 struct objfile
*objfile
;
1223 register int bot
, top
;
1224 register struct symbol
*sym
;
1225 register CORE_ADDR sym_addr
;
1226 struct block
*block
;
1229 /* Info on best symbol seen so far */
1231 register CORE_ADDR best_sym_addr
= 0;
1232 struct symbol
*best_sym
= 0;
1234 /* FIXME -- we should pull in all the psymtabs, too! */
1235 ALL_SYMTABS (objfile
, symtab
)
1237 /* Search the global and static blocks in this symtab for
1238 the closest symbol-address to the desired address. */
1240 for (blocknum
= GLOBAL_BLOCK
; blocknum
<= STATIC_BLOCK
; blocknum
++)
1243 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab
), blocknum
);
1244 top
= BLOCK_NSYMS (block
);
1245 for (bot
= 0; bot
< top
; bot
++)
1247 sym
= BLOCK_SYM (block
, bot
);
1248 switch (SYMBOL_CLASS (sym
))
1252 sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1256 sym_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1263 if (sym_addr
<= addr
)
1264 if (sym_addr
> best_sym_addr
)
1266 /* Quit if we found an exact match. */
1268 best_sym_addr
= sym_addr
;
1269 best_symtab
= symtab
;
1270 if (sym_addr
== addr
)
1279 *symtabp
= best_symtab
;
1281 *symaddrp
= best_sym_addr
;
1286 /* Find the source file and line number for a given PC value and section.
1287 Return a structure containing a symtab pointer, a line number,
1288 and a pc range for the entire source line.
1289 The value's .pc field is NOT the specified pc.
1290 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1291 use the line that ends there. Otherwise, in that case, the line
1292 that begins there is used. */
1294 /* The big complication here is that a line may start in one file, and end just
1295 before the start of another file. This usually occurs when you #include
1296 code in the middle of a subroutine. To properly find the end of a line's PC
1297 range, we must search all symtabs associated with this compilation unit, and
1298 find the one whose first PC is closer than that of the next line in this
1301 /* If it's worth the effort, we could be using a binary search. */
1303 struct symtab_and_line
1304 find_pc_sect_line (pc
, section
, notcurrent
)
1306 struct sec
*section
;
1310 register struct linetable
*l
;
1313 register struct linetable_entry
*item
;
1314 struct symtab_and_line val
;
1315 struct blockvector
*bv
;
1317 /* Info on best line seen so far, and where it starts, and its file. */
1319 struct linetable_entry
*best
= NULL
;
1320 CORE_ADDR best_end
= 0;
1321 struct symtab
*best_symtab
= 0;
1323 /* Store here the first line number
1324 of a file which contains the line at the smallest pc after PC.
1325 If we don't find a line whose range contains PC,
1326 we will use a line one less than this,
1327 with a range from the start of that file to the first line's pc. */
1328 struct linetable_entry
*alt
= NULL
;
1329 struct symtab
*alt_symtab
= 0;
1331 /* Info on best line seen in this file. */
1333 struct linetable_entry
*prev
;
1335 /* If this pc is not from the current frame,
1336 it is the address of the end of a call instruction.
1337 Quite likely that is the start of the following statement.
1338 But what we want is the statement containing the instruction.
1339 Fudge the pc to make sure we get that. */
1341 INIT_SAL (&val
); /* initialize to zeroes */
1346 s
= find_pc_sect_symtab (pc
, section
);
1349 /* if no symbol information, return previous pc */
1356 bv
= BLOCKVECTOR (s
);
1358 /* Look at all the symtabs that share this blockvector.
1359 They all have the same apriori range, that we found was right;
1360 but they have different line tables. */
1362 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1364 /* Find the best line in this symtab. */
1371 /* I think len can be zero if the symtab lacks line numbers
1372 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
1373 I'm not sure which, and maybe it depends on the symbol
1379 item
= l
->item
; /* Get first line info */
1381 /* Is this file's first line closer than the first lines of other files?
1382 If so, record this file, and its first line, as best alternate. */
1383 if (item
->pc
> pc
&& (!alt
|| item
->pc
< alt
->pc
))
1389 for (i
= 0; i
< len
; i
++, item
++)
1391 /* Leave prev pointing to the linetable entry for the last line
1392 that started at or before PC. */
1399 /* At this point, prev points at the line whose start addr is <= pc, and
1400 item points at the next line. If we ran off the end of the linetable
1401 (pc >= start of the last line), then prev == item. If pc < start of
1402 the first line, prev will not be set. */
1404 /* Is this file's best line closer than the best in the other files?
1405 If so, record this file, and its best line, as best so far. */
1407 if (prev
&& (!best
|| prev
->pc
> best
->pc
))
1411 /* If another line is in the linetable, and its PC is closer
1412 than the best_end we currently have, take it as best_end. */
1413 if (i
< len
&& (best_end
== 0 || best_end
> item
->pc
))
1414 best_end
= item
->pc
;
1421 { /* If we didn't find any line # info, just
1427 val
.symtab
= alt_symtab
;
1428 val
.line
= alt
->line
- 1;
1430 /* Don't return line 0, that means that we didn't find the line. */
1431 if (val
.line
== 0) ++val
.line
;
1433 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1439 val
.symtab
= best_symtab
;
1440 val
.line
= best
->line
;
1442 if (best_end
&& (!alt
|| best_end
< alt
->pc
))
1447 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1449 val
.section
= section
;
1453 /* Backward compatibility (no section) */
1455 struct symtab_and_line
1456 find_pc_line (pc
, notcurrent
)
1462 section
= find_pc_overlay (pc
);
1463 if (pc_in_unmapped_range (pc
, section
))
1464 pc
= overlay_mapped_address (pc
, section
);
1465 return find_pc_sect_line (pc
, section
, notcurrent
);
1469 static int find_line_symtab
PARAMS ((struct symtab
*, int, struct linetable
**,
1472 /* Find line number LINE in any symtab whose name is the same as
1475 If found, return 1, set *LINETABLE to the linetable in which it was
1476 found, set *INDEX to the index in the linetable of the best entry
1477 found, and set *EXACT_MATCH nonzero if the value returned is an
1480 If not found, return 0. */
1483 find_line_symtab (symtab
, line
, linetable
, index
, exact_match
)
1484 struct symtab
*symtab
;
1486 struct linetable
**linetable
;
1492 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
1496 struct linetable
*best_linetable
;
1498 /* First try looking it up in the given symtab. */
1499 best_linetable
= LINETABLE (symtab
);
1500 best_index
= find_line_common (best_linetable
, line
, &exact
);
1501 if (best_index
< 0 || !exact
)
1503 /* Didn't find an exact match. So we better keep looking for
1504 another symtab with the same name. In the case of xcoff,
1505 multiple csects for one source file (produced by IBM's FORTRAN
1506 compiler) produce multiple symtabs (this is unavoidable
1507 assuming csects can be at arbitrary places in memory and that
1508 the GLOBAL_BLOCK of a symtab has a begin and end address). */
1510 /* BEST is the smallest linenumber > LINE so far seen,
1511 or 0 if none has been seen so far.
1512 BEST_INDEX and BEST_LINETABLE identify the item for it. */
1515 struct objfile
*objfile
;
1518 if (best_index
>= 0)
1519 best
= best_linetable
->item
[best_index
].line
;
1523 ALL_SYMTABS (objfile
, s
)
1525 struct linetable
*l
;
1528 if (!STREQ (symtab
->filename
, s
->filename
))
1531 ind
= find_line_common (l
, line
, &exact
);
1540 if (best
== 0 || l
->item
[ind
].line
< best
)
1542 best
= l
->item
[ind
].line
;
1554 *index
= best_index
;
1556 *linetable
= best_linetable
;
1558 *exact_match
= exact
;
1562 /* Set the PC value for a given source file and line number and return true.
1563 Returns zero for invalid line number (and sets the PC to 0).
1564 The source file is specified with a struct symtab. */
1567 find_line_pc (symtab
, line
, pc
)
1568 struct symtab
*symtab
;
1572 struct linetable
*l
;
1579 if (find_line_symtab (symtab
, line
, &l
, &ind
, NULL
))
1581 *pc
= l
->item
[ind
].pc
;
1588 /* Find the range of pc values in a line.
1589 Store the starting pc of the line into *STARTPTR
1590 and the ending pc (start of next line) into *ENDPTR.
1591 Returns 1 to indicate success.
1592 Returns 0 if could not find the specified line. */
1595 find_line_pc_range (sal
, startptr
, endptr
)
1596 struct symtab_and_line sal
;
1597 CORE_ADDR
*startptr
, *endptr
;
1599 CORE_ADDR startaddr
;
1600 struct symtab_and_line found_sal
;
1603 if (startaddr
==0 && !find_line_pc (sal
.symtab
, sal
.line
, &startaddr
))
1606 /* This whole function is based on address. For example, if line 10 has
1607 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
1608 "info line *0x123" should say the line goes from 0x100 to 0x200
1609 and "info line *0x355" should say the line goes from 0x300 to 0x400.
1610 This also insures that we never give a range like "starts at 0x134
1611 and ends at 0x12c". */
1613 found_sal
= find_pc_sect_line (startaddr
, sal
.section
, 0);
1614 if (found_sal
.line
!= sal
.line
)
1616 /* The specified line (sal) has zero bytes. */
1617 *startptr
= found_sal
.pc
;
1618 *endptr
= found_sal
.pc
;
1622 *startptr
= found_sal
.pc
;
1623 *endptr
= found_sal
.end
;
1628 /* Given a line table and a line number, return the index into the line
1629 table for the pc of the nearest line whose number is >= the specified one.
1630 Return -1 if none is found. The value is >= 0 if it is an index.
1632 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1635 find_line_common (l
, lineno
, exact_match
)
1636 register struct linetable
*l
;
1637 register int lineno
;
1643 /* BEST is the smallest linenumber > LINENO so far seen,
1644 or 0 if none has been seen so far.
1645 BEST_INDEX identifies the item for it. */
1647 int best_index
= -1;
1656 for (i
= 0; i
< len
; i
++)
1658 register struct linetable_entry
*item
= &(l
->item
[i
]);
1660 if (item
->line
== lineno
)
1662 /* Return the first (lowest address) entry which matches. */
1667 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
1674 /* If we got here, we didn't get an exact match. */
1681 find_pc_line_pc_range (pc
, startptr
, endptr
)
1683 CORE_ADDR
*startptr
, *endptr
;
1685 struct symtab_and_line sal
;
1686 sal
= find_pc_line (pc
, 0);
1689 return sal
.symtab
!= 0;
1692 /* Given a function symbol SYM, find the symtab and line for the start
1694 If the argument FUNFIRSTLINE is nonzero, we want the first line
1695 of real code inside the function. */
1697 static struct symtab_and_line
1698 find_function_start_sal
PARAMS ((struct symbol
*sym
, int));
1700 static struct symtab_and_line
1701 find_function_start_sal (sym
, funfirstline
)
1706 struct symtab_and_line sal
;
1708 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1709 fixup_symbol_section (sym
, NULL
);
1711 { /* skip "first line" of function (which is actually its prologue) */
1712 asection
*section
= SYMBOL_BFD_SECTION (sym
);
1713 /* If function is in an unmapped overlay, use its unmapped LMA
1714 address, so that SKIP_PROLOGUE has something unique to work on */
1715 if (section_is_overlay (section
) &&
1716 !section_is_mapped (section
))
1717 pc
= overlay_unmapped_address (pc
, section
);
1719 pc
+= FUNCTION_START_OFFSET
;
1722 /* For overlays, map pc back into its mapped VMA range */
1723 pc
= overlay_mapped_address (pc
, section
);
1725 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
1727 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1728 /* Convex: no need to suppress code on first line, if any */
1731 /* Check if SKIP_PROLOGUE left us in mid-line, and the next
1732 line is still part of the same function. */
1734 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) <= sal
.end
1735 && sal
.end
< BLOCK_END (SYMBOL_BLOCK_VALUE (sym
)))
1737 /* First pc of next line */
1739 /* Recalculate the line number (might not be N+1). */
1740 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
1748 /* If P is of the form "operator[ \t]+..." where `...' is
1749 some legitimate operator text, return a pointer to the
1750 beginning of the substring of the operator text.
1751 Otherwise, return "". */
1753 operator_chars (p
, end
)
1758 if (strncmp (p
, "operator", 8))
1762 /* Don't get faked out by `operator' being part of a longer
1764 if (isalpha(*p
) || *p
== '_' || *p
== '$' || *p
== '\0')
1767 /* Allow some whitespace between `operator' and the operator symbol. */
1768 while (*p
== ' ' || *p
== '\t')
1771 /* Recognize 'operator TYPENAME'. */
1773 if (isalpha(*p
) || *p
== '_' || *p
== '$')
1775 register char *q
= p
+1;
1776 while (isalnum(*q
) || *q
== '_' || *q
== '$')
1801 if (p
[1] == '=' || p
[1] == p
[0])
1812 error ("`operator ()' must be specified without whitespace in `()'");
1817 error ("`operator ?:' must be specified without whitespace in `?:'");
1822 error ("`operator []' must be specified without whitespace in `[]'");
1826 error ("`operator %s' not supported", p
);
1833 /* Return the number of methods described for TYPE, including the
1834 methods from types it derives from. This can't be done in the symbol
1835 reader because the type of the baseclass might still be stubbed
1836 when the definition of the derived class is parsed. */
1838 static int total_number_of_methods
PARAMS ((struct type
*type
));
1841 total_number_of_methods (type
)
1847 CHECK_TYPEDEF (type
);
1848 if (TYPE_CPLUS_SPECIFIC (type
) == NULL
)
1850 count
= TYPE_NFN_FIELDS_TOTAL (type
);
1852 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
1853 count
+= total_number_of_methods (TYPE_BASECLASS (type
, n
));
1858 /* Recursive helper function for decode_line_1.
1859 Look for methods named NAME in type T.
1860 Return number of matches.
1861 Put matches in SYM_ARR, which should have been allocated with
1862 a size of total_number_of_methods (T) * sizeof (struct symbol *).
1863 Note that this function is g++ specific. */
1866 find_methods (t
, name
, sym_arr
)
1869 struct symbol
**sym_arr
;
1873 struct symbol
*sym_class
;
1874 char *class_name
= type_name_no_tag (t
);
1876 /* Ignore this class if it doesn't have a name. This is ugly, but
1877 unless we figure out how to get the physname without the name of
1878 the class, then the loop can't do any good. */
1880 && (sym_class
= lookup_symbol (class_name
,
1881 (struct block
*)NULL
,
1884 (struct symtab
**)NULL
)))
1888 /* FIXME: Shouldn't this just be CHECK_TYPEDEF (t)? */
1889 t
= SYMBOL_TYPE (sym_class
);
1891 /* Loop over each method name. At this level, all overloads of a name
1892 are counted as a single name. There is an inner loop which loops over
1895 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
1896 method_counter
>= 0;
1900 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
1901 char dem_opname
[64];
1903 if (strncmp (method_name
, "__", 2) == 0 ||
1904 strncmp (method_name
, "op", 2) == 0 ||
1905 strncmp (method_name
, "type", 4) == 0)
1906 if (cplus_demangle_opname (method_name
, dem_opname
, DMGL_ANSI
))
1907 method_name
= dem_opname
;
1908 else if (cplus_demangle_opname (method_name
, dem_opname
, 0))
1909 method_name
= dem_opname
;
1911 if (STREQ (name
, method_name
))
1912 /* Find all the overloaded methods with that name. */
1913 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
1920 f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
1922 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
1926 tmp_name
= gdb_mangle_name (t
,
1929 phys_name
= alloca (strlen (tmp_name
) + 1);
1930 strcpy (phys_name
, tmp_name
);
1934 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
1936 /* Destructor is handled by caller, dont add it to the list */
1937 if (DESTRUCTOR_PREFIX_P (phys_name
))
1940 sym_arr
[i1
] = lookup_symbol (phys_name
,
1941 NULL
, VAR_NAMESPACE
,
1943 (struct symtab
**) NULL
);
1948 /* This error message gets printed, but the method
1949 still seems to be found
1950 fputs_filtered("(Cannot find method ", gdb_stdout);
1951 fprintf_symbol_filtered (gdb_stdout, phys_name,
1953 DMGL_PARAMS | DMGL_ANSI);
1954 fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
1961 /* Only search baseclasses if there is no match yet, since names in
1962 derived classes override those in baseclasses.
1964 FIXME: The above is not true; it is only true of member functions
1965 if they have the same number of arguments (??? - section 13.1 of the
1966 ARM says the function members are not in the same scope but doesn't
1967 really spell out the rules in a way I understand. In any case, if
1968 the number of arguments differ this is a case in which we can overload
1969 rather than hiding without any problem, and gcc 2.4.5 does overload
1970 rather than hiding in this case). */
1973 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
1974 i1
+= find_methods (TYPE_BASECLASS (t
, ibase
), name
, sym_arr
+ i1
);
1979 /* Helper function for decode_line_1.
1980 Build a canonical line spec in CANONICAL if it is non-NULL and if
1981 the SAL has a symtab.
1982 If SYMNAME is non-NULL the canonical line spec is `filename:symname'.
1983 If SYMNAME is NULL the line number from SAL is used and the canonical
1984 line spec is `filename:linenum'. */
1987 build_canonical_line_spec (sal
, symname
, canonical
)
1988 struct symtab_and_line
*sal
;
1992 char **canonical_arr
;
1993 char *canonical_name
;
1995 struct symtab
*s
= sal
->symtab
;
1997 if (s
== (struct symtab
*)NULL
1998 || s
->filename
== (char *)NULL
1999 || canonical
== (char ***)NULL
)
2002 canonical_arr
= (char **) xmalloc (sizeof (char *));
2003 *canonical
= canonical_arr
;
2005 filename
= s
->filename
;
2006 if (symname
!= NULL
)
2008 canonical_name
= xmalloc (strlen (filename
) + strlen (symname
) + 2);
2009 sprintf (canonical_name
, "%s:%s", filename
, symname
);
2013 canonical_name
= xmalloc (strlen (filename
) + 30);
2014 sprintf (canonical_name
, "%s:%d", filename
, sal
->line
);
2016 canonical_arr
[0] = canonical_name
;
2019 /* Parse a string that specifies a line number.
2020 Pass the address of a char * variable; that variable will be
2021 advanced over the characters actually parsed.
2025 LINENUM -- that line number in current file. PC returned is 0.
2026 FILE:LINENUM -- that line in that file. PC returned is 0.
2027 FUNCTION -- line number of openbrace of that function.
2028 PC returned is the start of the function.
2029 VARIABLE -- line number of definition of that variable.
2031 FILE:FUNCTION -- likewise, but prefer functions in that file.
2032 *EXPR -- line in which address EXPR appears.
2034 FUNCTION may be an undebuggable function found in minimal symbol table.
2036 If the argument FUNFIRSTLINE is nonzero, we want the first line
2037 of real code inside a function when a function is specified, and it is
2038 not OK to specify a variable or type to get its line number.
2040 DEFAULT_SYMTAB specifies the file to use if none is specified.
2041 It defaults to current_source_symtab.
2042 DEFAULT_LINE specifies the line number to use for relative
2043 line numbers (that start with signs). Defaults to current_source_line.
2044 If CANONICAL is non-NULL, store an array of strings containing the canonical
2045 line specs there if necessary. Currently overloaded member functions and
2046 line numbers or static functions without a filename yield a canonical
2047 line spec. The array and the line spec strings are allocated on the heap,
2048 it is the callers responsibility to free them.
2050 Note that it is possible to return zero for the symtab
2051 if no file is validly specified. Callers must check that.
2052 Also, the line number returned may be invalid. */
2054 /* We allow single quotes in various places. This is a hideous
2055 kludge, which exists because the completer can't yet deal with the
2056 lack of single quotes. FIXME: write a linespec_completer which we
2057 can use as appropriate instead of make_symbol_completion_list. */
2059 struct symtabs_and_lines
2060 decode_line_1 (argptr
, funfirstline
, default_symtab
, default_line
, canonical
)
2063 struct symtab
*default_symtab
;
2067 struct symtabs_and_lines values
;
2068 #ifdef HPPA_COMPILER_BUG
2069 /* FIXME: The native HP 9000/700 compiler has a bug which appears
2070 when optimizing this file with target i960-vxworks. I haven't
2071 been able to construct a simple test case. The problem is that
2072 in the second call to SKIP_PROLOGUE below, the compiler somehow
2073 does not realize that the statement val = find_pc_line (...) will
2074 change the values of the fields of val. It extracts the elements
2075 into registers at the top of the block, and does not update the
2076 registers after the call to find_pc_line. You can check this by
2077 inserting a printf at the end of find_pc_line to show what values
2078 it is returning for val.pc and val.end and another printf after
2079 the call to see what values the function actually got (remember,
2080 this is compiling with cc -O, with this patch removed). You can
2081 also examine the assembly listing: search for the second call to
2082 skip_prologue; the LDO statement before the next call to
2083 find_pc_line loads the address of the structure which
2084 find_pc_line will return; if there is a LDW just before the LDO,
2085 which fetches an element of the structure, then the compiler
2088 Setting val to volatile avoids the problem. We must undef
2089 volatile, because the HPPA native compiler does not define
2090 __STDC__, although it does understand volatile, and so volatile
2091 will have been defined away in defs.h. */
2093 volatile struct symtab_and_line val
;
2094 #define volatile /*nothing*/
2096 struct symtab_and_line val
;
2098 register char *p
, *p1
;
2100 register struct symtab
*s
;
2102 register struct symbol
*sym
;
2103 /* The symtab that SYM was found in. */
2104 struct symtab
*sym_symtab
;
2106 register CORE_ADDR pc
;
2107 register struct minimal_symbol
*msymbol
;
2109 int is_quoted
, has_parens
;
2110 char *saved_arg
= *argptr
;
2111 extern char *gdb_completer_quote_characters
;
2113 INIT_SAL (&val
); /* initialize to zeroes */
2115 /* Defaults have defaults. */
2117 if (default_symtab
== 0)
2119 default_symtab
= current_source_symtab
;
2120 default_line
= current_source_line
;
2123 /* See if arg is *PC */
2125 if (**argptr
== '*')
2128 pc
= parse_and_eval_address_1 (argptr
);
2130 values
.sals
= (struct symtab_and_line
*)
2131 xmalloc (sizeof (struct symtab_and_line
));
2134 values
.sals
[0] = find_pc_line (pc
, 0);
2135 values
.sals
[0].pc
= pc
;
2136 values
.sals
[0].section
= find_pc_overlay (pc
);
2141 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
2144 is_quoted
= (**argptr
2145 && strchr (gdb_completer_quote_characters
, **argptr
) != NULL
);
2146 has_parens
= ((pp
= strchr (*argptr
, '(')) != NULL
2147 && (pp
= strchr (pp
, ')')) != NULL
);
2149 for (p
= *argptr
; *p
; p
++)
2153 while(++p
&& *p
!= '>');
2156 error ("non-matching '<' and '>' in command");
2159 if (p
[0] == ':' || p
[0] == ' ' || p
[0] == '\t')
2161 /* start-sanitize-java */
2162 if (p
[0] == '.' && strchr (p
, ':') == NULL
) /* Java qualified method. */
2164 /* Find the *last* '.', since the others are package qualifiers. */
2165 for (p1
= p
; *p1
; p1
++)
2172 /* end-sanitize-java */
2174 while (p
[0] == ' ' || p
[0] == '\t') p
++;
2176 if ((p
[0] == ':' || p
[0] == '.') && !has_parens
)
2179 /* start-sanitize-java */
2181 /* end-sanitize-java */
2182 if (is_quoted
) *argptr
= *argptr
+1;
2183 if (p
[0] == '.' || p
[1] ==':')
2185 struct symbol
*sym_class
;
2187 /* Extract the class name. */
2189 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
2190 copy
= (char *) alloca (p
- *argptr
+ 1);
2191 memcpy (copy
, *argptr
, p
- *argptr
);
2192 copy
[p
- *argptr
] = 0;
2194 /* Discard the class name from the arg. */
2195 p
= p1
+ (p1
[0] == ':' ? 2 : 1);
2196 while (*p
== ' ' || *p
== '\t') p
++;
2199 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
2200 (struct symtab
**)NULL
);
2203 (TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_STRUCT
2204 || TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_UNION
))
2206 struct symbol
**sym_arr
;
2210 t
= check_typedef (SYMBOL_TYPE (sym_class
));
2212 /* Arg token is not digits => try it as a function name
2213 Find the next token(everything up to end or next blank). */
2215 && strchr (gdb_completer_quote_characters
, **argptr
) != NULL
)
2217 p
= skip_quoted(*argptr
);
2218 *argptr
= *argptr
+ 1;
2223 while (*p
&& *p
!=' ' && *p
!='\t' && *p
!=',' && *p
!=':') p
++;
2226 q = operator_chars (*argptr, &q1);
2230 char *tmp = alloca (q1 - q + 1);
2231 memcpy (tmp, q, q1 - q);
2233 opname = cplus_mangle_opname (tmp, DMGL_ANSI);
2237 printf_filtered ("no mangling for \"%s\"\n", tmp);
2238 cplusplus_hint (saved_arg);
2239 return_to_top_level (RETURN_ERROR);
2241 copy = (char*) alloca (3 + strlen(opname));
2242 sprintf (copy, "__%s", opname);
2248 copy
= (char *) alloca (p
- *argptr
+ 1 );
2249 memcpy (copy
, *argptr
, p
- *argptr
);
2250 copy
[p
- *argptr
] = '\0';
2252 && copy
[p
- *argptr
- 1]
2253 && strchr (gdb_completer_quote_characters
,
2254 copy
[p
- *argptr
- 1]) != NULL
)
2255 copy
[p
- *argptr
- 1] = '\0';
2258 /* no line number may be specified */
2259 while (*p
== ' ' || *p
== '\t') p
++;
2263 i1
= 0; /* counter for the symbol array */
2264 sym_arr
= (struct symbol
**) alloca(total_number_of_methods (t
)
2265 * sizeof(struct symbol
*));
2267 if (destructor_name_p (copy
, t
))
2269 /* Destructors are a special case. */
2270 int m_index
, f_index
;
2272 if (get_destructor_fn_field (t
, &m_index
, &f_index
))
2274 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, m_index
);
2277 lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f
, f_index
),
2278 NULL
, VAR_NAMESPACE
, (int *) NULL
,
2279 (struct symtab
**)NULL
);
2285 i1
= find_methods (t
, copy
, sym_arr
);
2288 /* There is exactly one field with that name. */
2291 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2293 values
.sals
= (struct symtab_and_line
*)
2294 xmalloc (sizeof (struct symtab_and_line
));
2296 values
.sals
[0] = find_function_start_sal (sym
,
2307 /* There is more than one field with that name
2308 (overloaded). Ask the user which one to use. */
2309 return decode_line_2 (sym_arr
, i1
, funfirstline
, canonical
);
2315 if (OPNAME_PREFIX_P (copy
))
2317 tmp
= (char *)alloca (strlen (copy
+3) + 9);
2318 strcpy (tmp
, "operator ");
2319 strcat (tmp
, copy
+3);
2326 ("the class `%s' does not have destructor defined\n",
2327 SYMBOL_SOURCE_NAME(sym_class
));
2330 ("the class %s does not have any method named %s\n",
2331 SYMBOL_SOURCE_NAME(sym_class
), tmp
);
2332 cplusplus_hint (saved_arg
);
2333 return_to_top_level (RETURN_ERROR
);
2339 /* The quotes are important if copy is empty. */
2341 ("can't find class, struct, or union named \"%s\"\n", copy
);
2342 cplusplus_hint (saved_arg
);
2343 return_to_top_level (RETURN_ERROR
);
2349 /* Extract the file name. */
2351 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
2352 copy
= (char *) alloca (p
- *argptr
+ 1);
2353 memcpy (copy
, *argptr
, p
- *argptr
);
2354 copy
[p
- *argptr
] = 0;
2356 /* Find that file's data. */
2357 s
= lookup_symtab (copy
);
2360 if (!have_full_symbols () && !have_partial_symbols ())
2361 error (no_symtab_msg
);
2362 error ("No source file named %s.", copy
);
2365 /* Discard the file name from the arg. */
2367 while (*p
== ' ' || *p
== '\t') p
++;
2371 /* S is specified file's symtab, or 0 if no file specified.
2372 arg no longer contains the file name. */
2374 /* Check whether arg is all digits (and sign) */
2377 if (*q
== '-' || *q
== '+') q
++;
2378 while (*q
>= '0' && *q
<= '9')
2381 if (q
!= *argptr
&& (*q
== 0 || *q
== ' ' || *q
== '\t' || *q
== ','))
2383 /* We found a token consisting of all digits -- at least one digit. */
2384 enum sign
{none
, plus
, minus
} sign
= none
;
2386 /* We might need a canonical line spec if no file was specified. */
2387 int need_canonical
= (s
== 0) ? 1 : 0;
2389 /* This is where we need to make sure that we have good defaults.
2390 We must guarantee that this section of code is never executed
2391 when we are called with just a function name, since
2392 select_source_symtab calls us with such an argument */
2394 if (s
== 0 && default_symtab
== 0)
2396 select_source_symtab (0);
2397 default_symtab
= current_source_symtab
;
2398 default_line
= current_source_line
;
2401 if (**argptr
== '+')
2402 sign
= plus
, (*argptr
)++;
2403 else if (**argptr
== '-')
2404 sign
= minus
, (*argptr
)++;
2405 val
.line
= atoi (*argptr
);
2412 val
.line
= default_line
+ val
.line
;
2418 val
.line
= default_line
- val
.line
;
2423 break; /* No need to adjust val.line. */
2426 while (*q
== ' ' || *q
== '\t') q
++;
2432 values
.sals
= (struct symtab_and_line
*)
2433 xmalloc (sizeof (struct symtab_and_line
));
2434 values
.sals
[0] = val
;
2437 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
2441 /* Arg token is not digits => try it as a variable name
2442 Find the next token (everything up to end or next whitespace). */
2444 if (**argptr
== '$') /* Convenience variable */
2445 p
= skip_quoted (*argptr
+ 1);
2448 p
= skip_quoted (*argptr
);
2450 error ("Unmatched single quote.");
2452 else if (has_parens
)
2458 p
= skip_quoted(*argptr
);
2461 copy
= (char *) alloca (p
- *argptr
+ 1);
2462 memcpy (copy
, *argptr
, p
- *argptr
);
2463 copy
[p
- *argptr
] = '\0';
2466 && copy
[0] == copy
[p
- *argptr
- 1]
2467 && strchr (gdb_completer_quote_characters
, copy
[0]) != NULL
)
2469 copy
[p
- *argptr
- 1] = '\0';
2472 while (*p
== ' ' || *p
== '\t') p
++;
2475 /* See if it's a convenience variable */
2480 int need_canonical
= (s
== 0) ? 1 : 0;
2482 valx
= value_of_internalvar (lookup_internalvar (copy
+ 1));
2483 if (TYPE_CODE (VALUE_TYPE (valx
)) != TYPE_CODE_INT
)
2484 error ("Convenience variables used in line specs must have integer values.");
2486 val
.symtab
= s
? s
: default_symtab
;
2487 val
.line
= value_as_long (valx
);
2490 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof val
);
2491 values
.sals
[0] = val
;
2495 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
2501 /* Look up that token as a variable.
2502 If file specified, use that file's per-file block to start with. */
2504 sym
= lookup_symbol (copy
,
2505 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
2506 : get_selected_block ()),
2507 VAR_NAMESPACE
, 0, &sym_symtab
);
2511 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2513 /* Arg is the name of a function */
2514 values
.sals
= (struct symtab_and_line
*)
2515 xmalloc (sizeof (struct symtab_and_line
));
2516 values
.sals
[0] = find_function_start_sal (sym
, funfirstline
);
2519 /* Don't use the SYMBOL_LINE; if used at all it points to
2520 the line containing the parameters or thereabouts, not
2521 the first line of code. */
2523 /* We might need a canonical line spec if it is a static
2527 struct blockvector
*bv
= BLOCKVECTOR (sym_symtab
);
2528 struct block
*b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2529 if (lookup_block_symbol (b
, copy
, VAR_NAMESPACE
) != NULL
)
2530 build_canonical_line_spec (values
.sals
, copy
, canonical
);
2537 error ("\"%s\" is not a function", copy
);
2538 else if (SYMBOL_LINE (sym
) != 0)
2540 /* We know its line number. */
2541 values
.sals
= (struct symtab_and_line
*)
2542 xmalloc (sizeof (struct symtab_and_line
));
2544 memset (&values
.sals
[0], 0, sizeof (values
.sals
[0]));
2545 values
.sals
[0].symtab
= sym_symtab
;
2546 values
.sals
[0].line
= SYMBOL_LINE (sym
);
2550 /* This can happen if it is compiled with a compiler which doesn't
2551 put out line numbers for variables. */
2552 /* FIXME: Shouldn't we just set .line and .symtab to zero
2553 and return? For example, "info line foo" could print
2555 error ("Line number not known for symbol \"%s\"", copy
);
2559 msymbol
= lookup_minimal_symbol (copy
, NULL
, NULL
);
2560 if (msymbol
!= NULL
)
2562 val
.pc
= SYMBOL_VALUE_ADDRESS (msymbol
);
2563 val
.section
= SYMBOL_BFD_SECTION (msymbol
);
2566 val
.pc
+= FUNCTION_START_OFFSET
;
2567 SKIP_PROLOGUE (val
.pc
);
2569 values
.sals
= (struct symtab_and_line
*)
2570 xmalloc (sizeof (struct symtab_and_line
));
2571 values
.sals
[0] = val
;
2576 if (!have_full_symbols () &&
2577 !have_partial_symbols () && !have_minimal_symbols ())
2578 error (no_symtab_msg
);
2580 error ("Function \"%s\" not defined.", copy
);
2581 return values
; /* for lint */
2584 struct symtabs_and_lines
2585 decode_line_spec (string
, funfirstline
)
2589 struct symtabs_and_lines sals
;
2591 error ("Empty line specification.");
2592 sals
= decode_line_1 (&string
, funfirstline
,
2593 current_source_symtab
, current_source_line
,
2596 error ("Junk at end of line specification: %s", string
);
2600 /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to
2601 operate on (ask user if necessary).
2602 If CANONICAL is non-NULL return a corresponding array of mangled names
2603 as canonical line specs there. */
2605 static struct symtabs_and_lines
2606 decode_line_2 (sym_arr
, nelts
, funfirstline
, canonical
)
2607 struct symbol
*sym_arr
[];
2612 struct symtabs_and_lines values
, return_values
;
2617 struct cleanup
*old_chain
;
2618 char **canonical_arr
= (char **)NULL
;
2620 values
.sals
= (struct symtab_and_line
*)
2621 alloca (nelts
* sizeof(struct symtab_and_line
));
2622 return_values
.sals
= (struct symtab_and_line
*)
2623 xmalloc (nelts
* sizeof(struct symtab_and_line
));
2624 old_chain
= make_cleanup (free
, return_values
.sals
);
2628 canonical_arr
= (char **) xmalloc (nelts
* sizeof (char *));
2629 make_cleanup (free
, canonical_arr
);
2630 memset (canonical_arr
, 0, nelts
* sizeof (char *));
2631 *canonical
= canonical_arr
;
2635 printf_unfiltered("[0] cancel\n[1] all\n");
2638 INIT_SAL (&return_values
.sals
[i
]); /* initialize to zeroes */
2639 INIT_SAL (&values
.sals
[i
]);
2640 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
2642 values
.sals
[i
] = find_function_start_sal (sym_arr
[i
], funfirstline
);
2643 printf_unfiltered ("[%d] %s at %s:%d\n",
2645 SYMBOL_SOURCE_NAME (sym_arr
[i
]),
2646 values
.sals
[i
].symtab
->filename
,
2647 values
.sals
[i
].line
);
2650 printf_unfiltered ("?HERE\n");
2654 if ((prompt
= getenv ("PS2")) == NULL
)
2658 printf_unfiltered("%s ",prompt
);
2659 gdb_flush(gdb_stdout
);
2661 args
= command_line_input ((char *) NULL
, 0, "overload-choice");
2663 if (args
== 0 || *args
== 0)
2664 error_no_arg ("one or more choice numbers");
2672 while (*arg1
>= '0' && *arg1
<= '9') arg1
++;
2673 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
2674 error ("Arguments must be choice numbers.");
2679 error ("cancelled");
2684 for (i
= 0; i
< nelts
; i
++)
2686 if (canonical_arr
[i
] == NULL
)
2688 symname
= SYMBOL_NAME (sym_arr
[i
]);
2689 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
2693 memcpy (return_values
.sals
, values
.sals
,
2694 (nelts
* sizeof(struct symtab_and_line
)));
2695 return_values
.nelts
= nelts
;
2696 discard_cleanups (old_chain
);
2697 return return_values
;
2700 if (num
>= nelts
+ 2)
2702 printf_unfiltered ("No choice number %d.\n", num
);
2707 if (values
.sals
[num
].pc
)
2711 symname
= SYMBOL_NAME (sym_arr
[num
]);
2712 make_cleanup (free
, symname
);
2713 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
2715 return_values
.sals
[i
++] = values
.sals
[num
];
2716 values
.sals
[num
].pc
= 0;
2720 printf_unfiltered ("duplicate request for %d ignored.\n", num
);
2725 while (*args
== ' ' || *args
== '\t') args
++;
2727 return_values
.nelts
= i
;
2728 discard_cleanups (old_chain
);
2729 return return_values
;
2733 /* Slave routine for sources_info. Force line breaks at ,'s.
2734 NAME is the name to print and *FIRST is nonzero if this is the first
2735 name printed. Set *FIRST to zero. */
2737 output_source_filename (name
, first
)
2741 /* Table of files printed so far. Since a single source file can
2742 result in several partial symbol tables, we need to avoid printing
2743 it more than once. Note: if some of the psymtabs are read in and
2744 some are not, it gets printed both under "Source files for which
2745 symbols have been read" and "Source files for which symbols will
2746 be read in on demand". I consider this a reasonable way to deal
2747 with the situation. I'm not sure whether this can also happen for
2748 symtabs; it doesn't hurt to check. */
2749 static char **tab
= NULL
;
2750 /* Allocated size of tab in elements.
2751 Start with one 256-byte block (when using GNU malloc.c).
2752 24 is the malloc overhead when range checking is in effect. */
2753 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
2754 /* Current size of tab in elements. */
2755 static int tab_cur_size
;
2762 tab
= (char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
2766 /* Is NAME in tab? */
2767 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
2768 if (STREQ (*p
, name
))
2769 /* Yes; don't print it again. */
2771 /* No; add it to tab. */
2772 if (tab_cur_size
== tab_alloc_size
)
2774 tab_alloc_size
*= 2;
2775 tab
= (char **) xrealloc ((char *) tab
, tab_alloc_size
* sizeof (*tab
));
2777 tab
[tab_cur_size
++] = name
;
2785 printf_filtered (", ");
2789 fputs_filtered (name
, gdb_stdout
);
2793 sources_info (ignore
, from_tty
)
2797 register struct symtab
*s
;
2798 register struct partial_symtab
*ps
;
2799 register struct objfile
*objfile
;
2802 if (!have_full_symbols () && !have_partial_symbols ())
2804 error (no_symtab_msg
);
2807 printf_filtered ("Source files for which symbols have been read in:\n\n");
2810 ALL_SYMTABS (objfile
, s
)
2812 output_source_filename (s
-> filename
, &first
);
2814 printf_filtered ("\n\n");
2816 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2819 ALL_PSYMTABS (objfile
, ps
)
2823 output_source_filename (ps
-> filename
, &first
);
2826 printf_filtered ("\n");
2830 file_matches (file
, files
, nfiles
)
2837 if (file
!= NULL
&& nfiles
!= 0)
2839 for (i
= 0; i
< nfiles
; i
++)
2841 if (strcmp (files
[i
], basename (file
)) == 0)
2845 else if (nfiles
== 0)
2850 /* Free any memory associated with a search. */
2852 free_search_symbols (symbols
)
2853 struct symbol_search
*symbols
;
2855 struct symbol_search
*p
;
2856 struct symbol_search
*next
;
2858 for (p
= symbols
; p
!= NULL
; p
= next
)
2865 /* Search the symbol table for matches to the regular expression REGEXP,
2866 returning the results in *MATCHES.
2868 Only symbols of KIND are searched:
2869 FUNCTIONS_NAMESPACE - search all functions
2870 TYPES_NAMESPACE - search all type names
2871 METHODS_NAMESPACE - search all methods NOT IMPLEMENTED
2872 VARIABLES_NAMESPACE - search all symbols, excluding functions, type names,
2873 and constants (enums)
2875 free_search_symbols should be called when *MATCHES is no longer needed.
2878 search_symbols (regexp
, kind
, nfiles
, files
, matches
)
2880 namespace_enum kind
;
2883 struct symbol_search
**matches
;
2886 register struct symtab
*s
;
2887 register struct partial_symtab
*ps
;
2888 register struct blockvector
*bv
;
2889 struct blockvector
*prev_bv
= 0;
2890 register struct block
*b
;
2892 register struct symbol
*sym
;
2893 struct partial_symbol
**psym
;
2894 struct objfile
*objfile
;
2895 struct minimal_symbol
*msymbol
;
2898 static enum minimal_symbol_type types
[]
2899 = {mst_data
, mst_text
, mst_abs
, mst_unknown
};
2900 static enum minimal_symbol_type types2
[]
2901 = {mst_bss
, mst_file_text
, mst_abs
, mst_unknown
};
2902 static enum minimal_symbol_type types3
[]
2903 = {mst_file_data
, mst_solib_trampoline
, mst_abs
, mst_unknown
};
2904 static enum minimal_symbol_type types4
[]
2905 = {mst_file_bss
, mst_text
, mst_abs
, mst_unknown
};
2906 enum minimal_symbol_type ourtype
;
2907 enum minimal_symbol_type ourtype2
;
2908 enum minimal_symbol_type ourtype3
;
2909 enum minimal_symbol_type ourtype4
;
2910 struct symbol_search
*sr
;
2911 struct symbol_search
*psr
;
2912 struct symbol_search
*tail
;
2913 struct cleanup
*old_chain
= NULL
;
2915 if (kind
< LABEL_NAMESPACE
)
2916 error ("must search on specific namespace");
2918 ourtype
= types
[(int) (kind
- LABEL_NAMESPACE
)];
2919 ourtype2
= types2
[(int) (kind
- LABEL_NAMESPACE
)];
2920 ourtype3
= types3
[(int) (kind
- LABEL_NAMESPACE
)];
2921 ourtype4
= types4
[(int) (kind
- LABEL_NAMESPACE
)];
2923 sr
= *matches
= NULL
;
2928 /* Make sure spacing is right for C++ operators.
2929 This is just a courtesy to make the matching less sensitive
2930 to how many spaces the user leaves between 'operator'
2931 and <TYPENAME> or <OPERATOR>. */
2933 char *opname
= operator_chars (regexp
, &opend
);
2936 int fix
= -1; /* -1 means ok; otherwise number of spaces needed. */
2937 if (isalpha(*opname
) || *opname
== '_' || *opname
== '$')
2939 /* There should 1 space between 'operator' and 'TYPENAME'. */
2940 if (opname
[-1] != ' ' || opname
[-2] == ' ')
2945 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2946 if (opname
[-1] == ' ')
2949 /* If wrong number of spaces, fix it. */
2952 char *tmp
= (char*) alloca(opend
-opname
+10);
2953 sprintf(tmp
, "operator%.*s%s", fix
, " ", opname
);
2958 if (0 != (val
= re_comp (regexp
)))
2959 error ("Invalid regexp (%s): %s", val
, regexp
);
2962 /* Search through the partial symtabs *first* for all symbols
2963 matching the regexp. That way we don't have to reproduce all of
2964 the machinery below. */
2966 ALL_PSYMTABS (objfile
, ps
)
2968 struct partial_symbol
**bound
, **gbound
, **sbound
;
2971 if (ps
->readin
) continue;
2973 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2974 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2977 /* Go through all of the symbols stored in a partial
2978 symtab in one loop. */
2979 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2984 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2986 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2997 /* If it would match (logic taken from loop below)
2998 load the file and go on to the next one */
2999 if (file_matches (ps
->filename
, files
, nfiles
)
3000 && ((regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (*psym
))
3001 && ((kind
== VARIABLES_NAMESPACE
&& SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
3002 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
3003 || (kind
== FUNCTIONS_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
3004 || (kind
== TYPES_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
)
3005 || (kind
== METHODS_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
))))
3007 PSYMTAB_TO_SYMTAB(ps
);
3015 /* Here, we search through the minimal symbol tables for functions
3016 and variables that match, and force their symbols to be read.
3017 This is in particular necessary for demangled variable names,
3018 which are no longer put into the partial symbol tables.
3019 The symbol will then be found during the scan of symtabs below.
3021 For functions, find_pc_symtab should succeed if we have debug info
3022 for the function, for variables we have to call lookup_symbol
3023 to determine if the variable has debug info.
3024 If the lookup fails, set found_misc so that we will rescan to print
3025 any matching symbols without debug info.
3028 if (nfiles
== 0 && (kind
== VARIABLES_NAMESPACE
|| kind
== FUNCTIONS_NAMESPACE
))
3030 ALL_MSYMBOLS (objfile
, msymbol
)
3032 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
3033 MSYMBOL_TYPE (msymbol
) == ourtype2
||
3034 MSYMBOL_TYPE (msymbol
) == ourtype3
||
3035 MSYMBOL_TYPE (msymbol
) == ourtype4
)
3037 if (regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (msymbol
))
3039 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
)))
3041 if (kind
== FUNCTIONS_NAMESPACE
3042 || lookup_symbol (SYMBOL_NAME (msymbol
),
3043 (struct block
*) NULL
,
3045 0, (struct symtab
**) NULL
) == NULL
)
3053 ALL_SYMTABS (objfile
, s
)
3055 bv
= BLOCKVECTOR (s
);
3056 /* Often many files share a blockvector.
3057 Scan each blockvector only once so that
3058 we don't get every symbol many times.
3059 It happens that the first symtab in the list
3060 for any given blockvector is the main file. */
3062 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
3064 b
= BLOCKVECTOR_BLOCK (bv
, i
);
3065 /* Skip the sort if this block is always sorted. */
3066 if (!BLOCK_SHOULD_SORT (b
))
3067 sort_block_syms (b
);
3068 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
3071 sym
= BLOCK_SYM (b
, j
);
3072 if (file_matches (s
->filename
, files
, nfiles
)
3073 && ((regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (sym
))
3074 && ((kind
== VARIABLES_NAMESPACE
&& SYMBOL_CLASS (sym
) != LOC_TYPEDEF
3075 && SYMBOL_CLASS (sym
) != LOC_BLOCK
3076 && SYMBOL_CLASS (sym
) != LOC_CONST
)
3077 || (kind
== FUNCTIONS_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3078 || (kind
== TYPES_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3079 || (kind
== METHODS_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
))))
3082 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
3086 psr
->msymbol
= NULL
;
3091 old_chain
= make_cleanup (free_search_symbols
, sr
);
3102 /* If there are no eyes, avoid all contact. I mean, if there are
3103 no debug symbols, then print directly from the msymbol_vector. */
3105 if (found_misc
|| kind
!= FUNCTIONS_NAMESPACE
)
3107 ALL_MSYMBOLS (objfile
, msymbol
)
3109 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
3110 MSYMBOL_TYPE (msymbol
) == ourtype2
||
3111 MSYMBOL_TYPE (msymbol
) == ourtype3
||
3112 MSYMBOL_TYPE (msymbol
) == ourtype4
)
3114 if (regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (msymbol
))
3116 /* Functions: Look up by address. */
3117 if (kind
!= FUNCTIONS_NAMESPACE
||
3118 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
))))
3120 /* Variables/Absolutes: Look up by name */
3121 if (lookup_symbol (SYMBOL_NAME (msymbol
),
3122 (struct block
*) NULL
, VAR_NAMESPACE
,
3123 0, (struct symtab
**) NULL
) == NULL
)
3126 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
3128 psr
->msymbol
= msymbol
;
3135 old_chain
= make_cleanup (free_search_symbols
, &sr
);
3149 discard_cleanups (old_chain
);
3152 /* Helper function for symtab_symbol_info, this function uses
3153 the data returned from search_symbols() to print information
3154 regarding the match to gdb_stdout.
3157 print_symbol_info (kind
, s
, sym
, block
, last
)
3158 namespace_enum kind
;
3164 if (last
== NULL
|| strcmp (last
, s
->filename
) != 0)
3166 fputs_filtered ("\nFile ", gdb_stdout
);
3167 fputs_filtered (s
->filename
, gdb_stdout
);
3168 fputs_filtered (":\n", gdb_stdout
);
3171 if (kind
!= TYPES_NAMESPACE
&& block
== STATIC_BLOCK
)
3172 printf_filtered ("static ");
3174 /* Typedef that is not a C++ class */
3175 if (kind
== TYPES_NAMESPACE
3176 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
3177 c_typedef_print (SYMBOL_TYPE(sym
), sym
, gdb_stdout
);
3178 /* variable, func, or typedef-that-is-c++-class */
3179 else if (kind
< TYPES_NAMESPACE
||
3180 (kind
== TYPES_NAMESPACE
&&
3181 SYMBOL_NAMESPACE(sym
) == STRUCT_NAMESPACE
))
3183 type_print (SYMBOL_TYPE (sym
),
3184 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3185 ? "" : SYMBOL_SOURCE_NAME (sym
)),
3188 printf_filtered (";\n");
3193 /* Tiemann says: "info methods was never implemented." */
3194 char *demangled_name
;
3195 c_type_print_base (TYPE_FN_FIELD_TYPE(t
, block
),
3197 c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t
, block
),
3199 if (TYPE_FN_FIELD_STUB (t
, block
))
3200 check_stub_method (TYPE_DOMAIN_TYPE (type
), j
, block
);
3202 cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t
, block
),
3203 DMGL_ANSI
| DMGL_PARAMS
);
3204 if (demangled_name
== NULL
)
3205 fprintf_filtered (stream
, "<badly mangled name %s>",
3206 TYPE_FN_FIELD_PHYSNAME (t
, block
));
3209 fputs_filtered (demangled_name
, stream
);
3210 free (demangled_name
);
3216 /* This help function for symtab_symbol_info() prints information
3217 for non-debugging symbols to gdb_stdout.
3220 print_msymbol_info (msymbol
)
3221 struct minimal_symbol
*msymbol
;
3223 printf_filtered (" %08lx %s\n",
3224 (unsigned long) SYMBOL_VALUE_ADDRESS (msymbol
),
3225 SYMBOL_SOURCE_NAME (msymbol
));
3228 /* This is the guts of the commands "info functions", "info types", and
3229 "info variables". It calls search_symbols to find all matches and then
3230 print_[m]symbol_info to print out some useful information about the
3234 symtab_symbol_info (regexp
, kind
, from_tty
)
3236 namespace_enum kind
;
3239 static char *classnames
[]
3240 = {"variable", "function", "type", "method"};
3241 struct symbol_search
*symbols
;
3242 struct symbol_search
*p
;
3243 struct cleanup
*old_chain
;
3244 char *last_filename
= NULL
;
3247 /* must make sure that if we're interrupted, symbols gets freed */
3248 search_symbols (regexp
, kind
, 0, (char **) NULL
, &symbols
);
3249 old_chain
= make_cleanup (free_search_symbols
, symbols
);
3251 printf_filtered (regexp
3252 ? "All %ss matching regular expression \"%s\":\n"
3253 : "All defined %ss:\n",
3254 classnames
[(int) (kind
- LABEL_NAMESPACE
- 1)], regexp
);
3256 for (p
= symbols
; p
!= NULL
; p
= p
->next
)
3260 if (p
->msymbol
!= NULL
)
3264 printf_filtered ("\nNon-debugging symbols:\n");
3267 print_msymbol_info (p
->msymbol
);
3271 print_symbol_info (kind
,
3276 last_filename
= p
->symtab
->filename
;
3280 do_cleanups (old_chain
);
3284 variables_info (regexp
, from_tty
)
3288 symtab_symbol_info (regexp
, VARIABLES_NAMESPACE
, from_tty
);
3292 functions_info (regexp
, from_tty
)
3296 symtab_symbol_info (regexp
, FUNCTIONS_NAMESPACE
, from_tty
);
3300 types_info (regexp
, from_tty
)
3304 symtab_symbol_info (regexp
, TYPES_NAMESPACE
, from_tty
);
3308 /* Tiemann says: "info methods was never implemented." */
3310 methods_info (regexp
)
3313 symtab_symbol_info (regexp
, METHODS_NAMESPACE
, 0, from_tty
);
3317 /* Breakpoint all functions matching regular expression. */
3319 rbreak_command (regexp
, from_tty
)
3323 struct symbol_search
*ss
;
3324 struct symbol_search
*p
;
3325 struct cleanup
*old_chain
;
3327 search_symbols (regexp
, FUNCTIONS_NAMESPACE
, 0, (char **) NULL
, &ss
);
3328 old_chain
= make_cleanup (free_search_symbols
, ss
);
3330 for (p
= ss
; p
!= NULL
; p
= p
->next
)
3332 if (p
->msymbol
== NULL
)
3334 char *string
= (char *) alloca (strlen (p
->symtab
->filename
)
3335 + strlen (SYMBOL_NAME (p
->symbol
))
3337 strcpy (string
, p
->symtab
->filename
);
3338 strcat (string
, ":'");
3339 strcat (string
, SYMBOL_NAME (p
->symbol
));
3340 strcat (string
, "'");
3341 break_command (string
, from_tty
);
3342 print_symbol_info (FUNCTIONS_NAMESPACE
,
3346 p
->symtab
->filename
);
3350 break_command (SYMBOL_NAME (p
->msymbol
), from_tty
);
3351 printf_filtered ("<function, no debug info> %s;\n",
3352 SYMBOL_SOURCE_NAME (p
->msymbol
));
3356 do_cleanups (old_chain
);
3360 /* Return Nonzero if block a is lexically nested within block b,
3361 or if a and b have the same pc range.
3362 Return zero otherwise. */
3365 struct block
*a
, *b
;
3369 return BLOCK_START (a
) >= BLOCK_START (b
)
3370 && BLOCK_END (a
) <= BLOCK_END (b
);
3374 /* Helper routine for make_symbol_completion_list. */
3376 static int return_val_size
;
3377 static int return_val_index
;
3378 static char **return_val
;
3380 #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
3382 if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \
3383 /* Put only the mangled name on the list. */ \
3384 /* Advantage: "b foo<TAB>" completes to "b foo(int, int)" */ \
3385 /* Disadvantage: "b foo__i<TAB>" doesn't complete. */ \
3386 completion_list_add_name \
3387 (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \
3389 completion_list_add_name \
3390 (SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \
3393 /* Test to see if the symbol specified by SYMNAME (which is already
3394 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3395 characters. If so, add it to the current completion list. */
3398 completion_list_add_name (symname
, sym_text
, sym_text_len
, text
, word
)
3408 /* clip symbols that cannot match */
3410 if (strncmp (symname
, sym_text
, sym_text_len
) != 0)
3415 /* Clip any symbol names that we've already considered. (This is a
3416 time optimization) */
3418 for (i
= 0; i
< return_val_index
; ++i
)
3420 if (STREQ (symname
, return_val
[i
]))
3426 /* We have a match for a completion, so add SYMNAME to the current list
3427 of matches. Note that the name is moved to freshly malloc'd space. */
3431 if (word
== sym_text
)
3433 new = xmalloc (strlen (symname
) + 5);
3434 strcpy (new, symname
);
3436 else if (word
> sym_text
)
3438 /* Return some portion of symname. */
3439 new = xmalloc (strlen (symname
) + 5);
3440 strcpy (new, symname
+ (word
- sym_text
));
3444 /* Return some of SYM_TEXT plus symname. */
3445 new = xmalloc (strlen (symname
) + (sym_text
- word
) + 5);
3446 strncpy (new, word
, sym_text
- word
);
3447 new[sym_text
- word
] = '\0';
3448 strcat (new, symname
);
3451 /* Recheck for duplicates if we intend to add a modified symbol. */
3452 if (word
!= sym_text
)
3454 for (i
= 0; i
< return_val_index
; ++i
)
3456 if (STREQ (new, return_val
[i
]))
3464 if (return_val_index
+ 3 > return_val_size
)
3466 newsize
= (return_val_size
*= 2) * sizeof (char *);
3467 return_val
= (char **) xrealloc ((char *) return_val
, newsize
);
3469 return_val
[return_val_index
++] = new;
3470 return_val
[return_val_index
] = NULL
;
3474 /* Return a NULL terminated array of all symbols (regardless of class) which
3475 begin by matching TEXT. If the answer is no symbols, then the return value
3476 is an array which contains only a NULL pointer.
3478 Problem: All of the symbols have to be copied because readline frees them.
3479 I'm not going to worry about this; hopefully there won't be that many. */
3482 make_symbol_completion_list (text
, word
)
3486 register struct symbol
*sym
;
3487 register struct symtab
*s
;
3488 register struct partial_symtab
*ps
;
3489 register struct minimal_symbol
*msymbol
;
3490 register struct objfile
*objfile
;
3491 register struct block
*b
, *surrounding_static_block
= 0;
3493 struct partial_symbol
**psym
;
3494 /* The symbol we are completing on. Points in same buffer as text. */
3496 /* Length of sym_text. */
3499 /* Now look for the symbol we are supposed to complete on.
3500 FIXME: This should be language-specific. */
3504 char *quote_pos
= NULL
;
3506 /* First see if this is a quoted string. */
3508 for (p
= text
; *p
!= '\0'; ++p
)
3510 if (quote_found
!= '\0')
3512 if (*p
== quote_found
)
3513 /* Found close quote. */
3515 else if (*p
== '\\' && p
[1] == quote_found
)
3516 /* A backslash followed by the quote character
3517 doesn't end the string. */
3520 else if (*p
== '\'' || *p
== '"')
3526 if (quote_found
== '\'')
3527 /* A string within single quotes can be a symbol, so complete on it. */
3528 sym_text
= quote_pos
+ 1;
3529 else if (quote_found
== '"')
3530 /* A double-quoted string is never a symbol, nor does it make sense
3531 to complete it any other way. */
3535 /* It is not a quoted string. Break it based on the characters
3536 which are in symbols. */
3539 if (isalnum (p
[-1]) || p
[-1] == '_' || p
[-1] == '\0')
3548 sym_text_len
= strlen (sym_text
);
3550 return_val_size
= 100;
3551 return_val_index
= 0;
3552 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
3553 return_val
[0] = NULL
;
3555 /* Look through the partial symtabs for all symbols which begin
3556 by matching SYM_TEXT. Add each one that you find to the list. */
3558 ALL_PSYMTABS (objfile
, ps
)
3560 /* If the psymtab's been read in we'll get it when we search
3561 through the blockvector. */
3562 if (ps
->readin
) continue;
3564 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
3565 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
3566 + ps
->n_global_syms
);
3569 /* If interrupted, then quit. */
3571 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3574 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
3575 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
3576 + ps
->n_static_syms
);
3580 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3584 /* At this point scan through the misc symbol vectors and add each
3585 symbol you find to the list. Eventually we want to ignore
3586 anything that isn't a text symbol (everything else will be
3587 handled by the psymtab code above). */
3589 ALL_MSYMBOLS (objfile
, msymbol
)
3592 COMPLETION_LIST_ADD_SYMBOL (msymbol
, sym_text
, sym_text_len
, text
, word
);
3595 /* Search upwards from currently selected frame (so that we can
3596 complete on local vars. */
3598 for (b
= get_selected_block (); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
3600 if (!BLOCK_SUPERBLOCK (b
))
3602 surrounding_static_block
= b
; /* For elmin of dups */
3605 /* Also catch fields of types defined in this places which match our
3606 text string. Only complete on types visible from current context. */
3608 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3610 sym
= BLOCK_SYM (b
, i
);
3611 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3612 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3614 struct type
*t
= SYMBOL_TYPE (sym
);
3615 enum type_code c
= TYPE_CODE (t
);
3617 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
3619 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
3621 if (TYPE_FIELD_NAME (t
, j
))
3623 completion_list_add_name (TYPE_FIELD_NAME (t
, j
),
3624 sym_text
, sym_text_len
, text
, word
);
3632 /* Go through the symtabs and check the externs and statics for
3633 symbols which match. */
3635 ALL_SYMTABS (objfile
, s
)
3638 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3639 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3641 sym
= BLOCK_SYM (b
, i
);
3642 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3646 ALL_SYMTABS (objfile
, s
)
3649 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3650 /* Don't do this block twice. */
3651 if (b
== surrounding_static_block
) continue;
3652 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3654 sym
= BLOCK_SYM (b
, i
);
3655 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3659 return (return_val
);
3662 /* Determine if PC is in the prologue of a function. The prologue is the area
3663 between the first instruction of a function, and the first executable line.
3664 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
3666 If non-zero, func_start is where we think the prologue starts, possibly
3667 by previous examination of symbol table information.
3671 in_prologue (pc
, func_start
)
3673 CORE_ADDR func_start
;
3675 struct symtab_and_line sal
;
3676 CORE_ADDR func_addr
, func_end
;
3678 if (!find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
3679 goto nosyms
; /* Might be in prologue */
3681 sal
= find_pc_line (func_addr
, 0);
3686 if (sal
.end
> func_addr
3687 && sal
.end
<= func_end
) /* Is prologue in function? */
3688 return pc
< sal
.end
; /* Yes, is pc in prologue? */
3690 /* The line after the prologue seems to be outside the function. In this
3691 case, tell the caller to find the prologue the hard way. */
3695 /* Come here when symtabs don't contain line # info. In this case, it is
3696 likely that the user has stepped into a library function w/o symbols, or
3697 is doing a stepi/nexti through code without symbols. */
3701 /* If func_start is zero (meaning unknown) then we don't know whether pc is
3702 in the prologue or not. I.E. it might be. */
3704 if (!func_start
) return 1;
3706 /* We need to call the target-specific prologue skipping functions with the
3707 function's start address because PC may be pointing at an instruction that
3708 could be mistakenly considered part of the prologue. */
3710 SKIP_PROLOGUE (func_start
);
3712 return pc
< func_start
;
3717 _initialize_symtab ()
3719 add_info ("variables", variables_info
,
3720 "All global and static variable names, or those matching REGEXP.");
3721 add_info ("functions", functions_info
,
3722 "All function names, or those matching REGEXP.");
3724 /* FIXME: This command has at least the following problems:
3725 1. It prints builtin types (in a very strange and confusing fashion).
3726 2. It doesn't print right, e.g. with
3727 typedef struct foo *FOO
3728 type_print prints "FOO" when we want to make it (in this situation)
3729 print "struct foo *".
3730 I also think "ptype" or "whatis" is more likely to be useful (but if
3731 there is much disagreement "info types" can be fixed). */
3732 add_info ("types", types_info
,
3733 "All type names, or those matching REGEXP.");
3736 add_info ("methods", methods_info
,
3737 "All method names, or those matching REGEXP::REGEXP.\n\
3738 If the class qualifier is omitted, it is assumed to be the current scope.\n\
3739 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
3742 add_info ("sources", sources_info
,
3743 "Source files in the program.");
3745 add_com ("rbreak", class_breakpoint
, rbreak_command
,
3746 "Set a breakpoint for all functions matching REGEXP.");
3748 /* Initialize the one built-in type that isn't language dependent... */
3749 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
3750 "<unknown type>", (struct objfile
*) NULL
);