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 list_symbols
PARAMS ((char *, int, int, int));
79 output_source_filename
PARAMS ((char *, int *));
82 operator_chars
PARAMS ((char *, char **));
84 static int find_line_common
PARAMS ((struct linetable
*, int, int *));
86 static struct partial_symbol
*
87 lookup_partial_symbol
PARAMS ((struct partial_symtab
*, const char *,
88 int, namespace_enum
));
90 static struct symtab
*
91 lookup_symtab_1
PARAMS ((char *));
94 cplusplus_hint
PARAMS ((char *));
98 /* The single non-language-specific builtin type */
99 struct type
*builtin_type_error
;
101 /* Block in which the most recently searched-for symbol was found.
102 Might be better to make this a parameter to lookup_symbol and
105 const struct block
*block_found
;
107 char no_symtab_msg
[] = "No symbol table is loaded. Use the \"file\" command.";
109 /* While the C++ support is still in flux, issue a possibly helpful hint on
110 using the new command completion feature on single quoted demangled C++
111 symbols. Remove when loose ends are cleaned up. FIXME -fnf */
114 cplusplus_hint (name
)
117 while (*name
== '\'')
119 printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name
, name
);
120 printf_filtered ("(Note leading single quote.)\n");
123 /* Check for a symtab of a specific name; first in symtabs, then in
124 psymtabs. *If* there is no '/' in the name, a match after a '/'
125 in the symtab filename will also work. */
127 static struct symtab
*
128 lookup_symtab_1 (name
)
131 register struct symtab
*s
;
132 register struct partial_symtab
*ps
;
133 register char *slash
;
134 register struct objfile
*objfile
;
138 /* First, search for an exact match */
140 ALL_SYMTABS (objfile
, s
)
141 if (STREQ (name
, s
->filename
))
144 slash
= strchr (name
, '/');
146 /* Now, search for a matching tail (only if name doesn't have any dirs) */
149 ALL_SYMTABS (objfile
, s
)
151 char *p
= s
-> filename
;
152 char *tail
= strrchr (p
, '/');
161 /* Same search rules as above apply here, but now we look thru the
164 ps
= lookup_partial_symtab (name
);
169 error ("Internal: readin %s pst for `%s' found when no symtab found.",
170 ps
-> filename
, name
);
172 s
= PSYMTAB_TO_SYMTAB (ps
);
177 /* At this point, we have located the psymtab for this file, but
178 the conversion to a symtab has failed. This usually happens
179 when we are looking up an include file. In this case,
180 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
181 been created. So, we need to run through the symtabs again in
182 order to find the file.
183 XXX - This is a crock, and should be fixed inside of the the
184 symbol parsing routines. */
188 /* Lookup the symbol table of a source file named NAME. Try a couple
189 of variations if the first lookup doesn't work. */
195 register struct symtab
*s
;
200 s
= lookup_symtab_1 (name
);
204 /* This screws c-exp.y:yylex if there is both a type "tree" and a symtab
207 /* If name not found as specified, see if adding ".c" helps. */
208 /* Why is this? Is it just a user convenience? (If so, it's pretty
209 questionable in the presence of C++, FORTRAN, etc.). It's not in
212 copy
= (char *) alloca (strlen (name
) + 3);
215 s
= lookup_symtab_1 (copy
);
219 /* We didn't find anything; die. */
223 /* Lookup the partial symbol table of a source file named NAME.
224 *If* there is no '/' in the name, a match after a '/'
225 in the psymtab filename will also work. */
227 struct partial_symtab
*
228 lookup_partial_symtab (name
)
231 register struct partial_symtab
*pst
;
232 register struct objfile
*objfile
;
234 ALL_PSYMTABS (objfile
, pst
)
236 if (STREQ (name
, pst
-> filename
))
242 /* Now, search for a matching tail (only if name doesn't have any dirs) */
244 if (!strchr (name
, '/'))
245 ALL_PSYMTABS (objfile
, pst
)
247 char *p
= pst
-> filename
;
248 char *tail
= strrchr (p
, '/');
260 /* Demangle a GDB method stub type.
261 Note that this function is g++ specific. */
264 gdb_mangle_name (type
, i
, j
)
268 int mangled_name_len
;
270 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
271 struct fn_field
*method
= &f
[j
];
272 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
273 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
274 char *newname
= type_name_no_tag (type
);
276 /* Does the form of physname indicate that it is the full mangled name
277 of a constructor (not just the args)? */
278 int is_full_physname_constructor
;
281 int is_destructor
= DESTRUCTOR_PREFIX_P (physname
);
282 /* Need a new type prefix. */
283 char *const_prefix
= method
->is_const
? "C" : "";
284 char *volatile_prefix
= method
->is_volatile
? "V" : "";
286 int len
= (newname
== NULL
? 0 : strlen (newname
));
288 is_full_physname_constructor
=
289 ((physname
[0]=='_' && physname
[1]=='_' &&
290 (isdigit(physname
[2]) || physname
[2]=='Q' || physname
[2]=='t'))
291 || (strncmp(physname
, "__ct", 4) == 0));
294 is_full_physname_constructor
|| (newname
&& STREQ(field_name
, newname
));
297 is_destructor
= (strncmp(physname
, "__dt", 4) == 0);
299 if (is_destructor
|| is_full_physname_constructor
)
301 mangled_name
= (char*) xmalloc(strlen(physname
)+1);
302 strcpy(mangled_name
, physname
);
308 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
310 else if (physname
[0] == 't' || physname
[0] == 'Q')
312 /* The physname for template and qualified methods already includes
314 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
320 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
322 mangled_name_len
= ((is_constructor
? 0 : strlen (field_name
))
327 /* Only needed for GNU-mangled names. ANSI-mangled names
328 work with the normal mechanisms. */
329 if (OPNAME_PREFIX_P (field_name
))
331 const char *opname
= cplus_mangle_opname (field_name
+ 3, 0);
333 error ("No mangling for \"%s\"", field_name
);
334 mangled_name_len
+= strlen (opname
);
335 mangled_name
= (char *)xmalloc (mangled_name_len
);
337 strncpy (mangled_name
, field_name
, 3);
338 mangled_name
[3] = '\0';
339 strcat (mangled_name
, opname
);
343 mangled_name
= (char *)xmalloc (mangled_name_len
);
345 mangled_name
[0] = '\0';
347 strcpy (mangled_name
, field_name
);
349 strcat (mangled_name
, buf
);
350 /* If the class doesn't have a name, i.e. newname NULL, then we just
351 mangle it using 0 for the length of the class. Thus it gets mangled
352 as something starting with `::' rather than `classname::'. */
354 strcat (mangled_name
, newname
);
356 strcat (mangled_name
, physname
);
357 return (mangled_name
);
362 struct partial_symbol
* fixup_psymbol_section
PARAMS ((struct partial_symbol
*,
366 /* Find which partial symtab on contains PC and SECTION. Return 0 if none. */
368 struct partial_symtab
*
369 find_pc_sect_psymtab (pc
, section
)
373 register struct partial_symtab
*pst
;
374 register struct objfile
*objfile
;
376 ALL_PSYMTABS (objfile
, pst
)
378 if (pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
380 struct minimal_symbol
*msymbol
;
381 struct partial_symtab
*tpst
;
383 /* An objfile that has its functions reordered might have
384 many partial symbol tables containing the PC, but
385 we want the partial symbol table that contains the
386 function containing the PC. */
387 if (!(objfile
->flags
& OBJF_REORDERED
) &&
388 section
== 0) /* can't validate section this way */
391 msymbol
= lookup_minimal_symbol_by_pc_section (pc
, section
);
395 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
397 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
399 struct partial_symbol
*p
;
401 p
= find_pc_sect_psymbol (tpst
, pc
, section
);
403 && SYMBOL_VALUE_ADDRESS(p
)
404 == SYMBOL_VALUE_ADDRESS (msymbol
))
414 /* Find which partial symtab contains PC. Return 0 if none.
415 Backward compatibility, no section */
417 struct partial_symtab
*
421 return find_pc_sect_psymtab (pc
, find_pc_mapped_section (pc
));
424 /* Find which partial symbol within a psymtab matches PC and SECTION.
425 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
427 struct partial_symbol
*
428 find_pc_sect_psymbol (psymtab
, pc
, section
)
429 struct partial_symtab
*psymtab
;
433 struct partial_symbol
*best
= NULL
, *p
, **pp
;
437 psymtab
= find_pc_sect_psymtab (pc
, section
);
441 best_pc
= psymtab
->textlow
- 1;
443 /* Search the global symbols as well as the static symbols, so that
444 find_pc_partial_function doesn't use a minimal symbol and thus
445 cache a bad endaddr. */
446 for (pp
= psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
447 (pp
- (psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
448 < psymtab
->n_global_syms
);
452 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
453 && SYMBOL_CLASS (p
) == LOC_BLOCK
454 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
455 && SYMBOL_VALUE_ADDRESS (p
) > best_pc
)
457 if (section
) /* match on a specific section */
459 fixup_psymbol_section (p
, psymtab
->objfile
);
460 if (SYMBOL_BFD_SECTION (p
) != section
)
463 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
467 for (pp
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
468 (pp
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
469 < psymtab
->n_static_syms
);
473 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
474 && SYMBOL_CLASS (p
) == LOC_BLOCK
475 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
476 && SYMBOL_VALUE_ADDRESS (p
) > best_pc
)
478 if (section
) /* match on a specific section */
480 fixup_psymbol_section (p
, psymtab
->objfile
);
481 if (SYMBOL_BFD_SECTION (p
) != section
)
484 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
488 if (best_pc
== psymtab
->textlow
- 1)
493 /* Find which partial symbol within a psymtab matches PC. Return 0 if none.
494 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
496 struct partial_symbol
*
497 find_pc_psymbol (psymtab
, pc
)
498 struct partial_symtab
*psymtab
;
501 return find_pc_sect_psymbol (psymtab
, pc
, find_pc_mapped_section (pc
));
504 /* Debug symbols usually don't have section information. We need to dig that
505 out of the minimal symbols and stash that in the debug symbol. */
508 fixup_section (ginfo
, objfile
)
509 struct general_symbol_info
*ginfo
;
510 struct objfile
*objfile
;
512 struct minimal_symbol
*msym
;
513 msym
= lookup_minimal_symbol (ginfo
->name
, NULL
, objfile
);
516 ginfo
->bfd_section
= SYMBOL_BFD_SECTION (msym
);
520 fixup_symbol_section (sym
, objfile
)
522 struct objfile
*objfile
;
527 if (SYMBOL_BFD_SECTION (sym
))
530 fixup_section (&sym
->ginfo
, objfile
);
535 struct partial_symbol
*
536 fixup_psymbol_section (psym
, objfile
)
537 struct partial_symbol
*psym
;
538 struct objfile
*objfile
;
543 if (SYMBOL_BFD_SECTION (psym
))
546 fixup_section (&psym
->ginfo
, objfile
);
551 /* Find the definition for a specified symbol name NAME
552 in namespace NAMESPACE, visible from lexical block BLOCK.
553 Returns the struct symbol pointer, or zero if no symbol is found.
554 If SYMTAB is non-NULL, store the symbol table in which the
555 symbol was found there, or NULL if not found.
556 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
557 NAME is a field of the current implied argument `this'. If so set
558 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
559 BLOCK_FOUND is set to the block in which NAME is found (in the case of
560 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
562 /* This function has a bunch of loops in it and it would seem to be
563 attractive to put in some QUIT's (though I'm not really sure
564 whether it can run long enough to be really important). But there
565 are a few calls for which it would appear to be bad news to quit
566 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and
567 nindy_frame_chain_valid in nindy-tdep.c. (Note that there is C++
568 code below which can error(), but that probably doesn't affect
569 these calls since they are looking for a known variable and thus
570 can probably assume it will never hit the C++ code). */
573 lookup_symbol (name
, block
, namespace, is_a_field_of_this
, symtab
)
575 register const struct block
*block
;
576 const namespace_enum
namespace;
577 int *is_a_field_of_this
;
578 struct symtab
**symtab
;
580 register struct symbol
*sym
;
581 register struct symtab
*s
= NULL
;
582 register struct partial_symtab
*ps
;
583 struct blockvector
*bv
;
584 register struct objfile
*objfile
= NULL
;
585 register struct block
*b
;
586 register struct minimal_symbol
*msymbol
;
588 /* Search specified block and its superiors. */
592 sym
= lookup_block_symbol (block
, name
, namespace);
598 /* Search the list of symtabs for one which contains the
599 address of the start of this block. */
600 ALL_SYMTABS (objfile
, s
)
602 bv
= BLOCKVECTOR (s
);
603 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
604 if (BLOCK_START (b
) <= BLOCK_START (block
)
605 && BLOCK_END (b
) > BLOCK_START (block
))
612 return fixup_symbol_section (sym
, objfile
);
614 block
= BLOCK_SUPERBLOCK (block
);
617 /* FIXME: this code is never executed--block is always NULL at this
618 point. What is it trying to do, anyway? We already should have
619 checked the STATIC_BLOCK above (it is the superblock of top-level
620 blocks). Why is VAR_NAMESPACE special-cased? */
621 /* Don't need to mess with the psymtabs; if we have a block,
622 that file is read in. If we don't, then we deal later with
623 all the psymtab stuff that needs checking. */
624 if (namespace == VAR_NAMESPACE
&& block
!= NULL
)
627 /* Find the right symtab. */
628 ALL_SYMTABS (objfile
, s
)
630 bv
= BLOCKVECTOR (s
);
631 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
632 if (BLOCK_START (b
) <= BLOCK_START (block
)
633 && BLOCK_END (b
) > BLOCK_START (block
))
635 sym
= lookup_block_symbol (b
, name
, VAR_NAMESPACE
);
641 return fixup_symbol_section (sym
, objfile
);
648 /* C++: If requested to do so by the caller,
649 check to see if NAME is a field of `this'. */
650 if (is_a_field_of_this
)
652 struct value
*v
= value_of_this (0);
654 *is_a_field_of_this
= 0;
655 if (v
&& check_field (v
, name
))
657 *is_a_field_of_this
= 1;
664 /* Now search all global blocks. Do the symtab's first, then
665 check the psymtab's */
667 ALL_SYMTABS (objfile
, s
)
669 bv
= BLOCKVECTOR (s
);
670 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
671 sym
= lookup_block_symbol (block
, name
, namespace);
677 return fixup_symbol_section (sym
, objfile
);
681 /* Check for the possibility of the symbol being a function or
682 a mangled variable that is stored in one of the minimal symbol tables.
683 Eventually, all global symbols might be resolved in this way. */
685 if (namespace == VAR_NAMESPACE
)
687 msymbol
= lookup_minimal_symbol (name
, NULL
, NULL
);
690 s
= find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol
),
691 SYMBOL_BFD_SECTION (msymbol
));
694 /* This is a function which has a symtab for its address. */
695 bv
= BLOCKVECTOR (s
);
696 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
697 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
699 /* We kept static functions in minimal symbol table as well as
700 in static scope. We want to find them in the symbol table. */
702 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
703 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
707 /* sym == 0 if symbol was found in the minimal symbol table
708 but not in the symtab.
709 Return 0 to use the msymbol definition of "foo_".
711 This happens for Fortran "foo_" symbols,
712 which are "foo" in the symtab.
714 This can also happen if "asm" is used to make a
715 regular symbol but not a debugging symbol, e.g.
722 return fixup_symbol_section (sym
, objfile
);
724 else if (MSYMBOL_TYPE (msymbol
) != mst_text
725 && MSYMBOL_TYPE (msymbol
) != mst_file_text
726 && !STREQ (name
, SYMBOL_NAME (msymbol
)))
728 /* This is a mangled variable, look it up by its
730 return lookup_symbol (SYMBOL_NAME (msymbol
), block
,
731 namespace, is_a_field_of_this
, symtab
);
733 /* There are no debug symbols for this file, or we are looking
734 for an unmangled variable.
735 Try to find a matching static symbol below. */
739 ALL_PSYMTABS (objfile
, ps
)
741 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
743 s
= PSYMTAB_TO_SYMTAB(ps
);
744 bv
= BLOCKVECTOR (s
);
745 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
746 sym
= lookup_block_symbol (block
, name
, namespace);
748 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab", name
, ps
->filename
);
751 return fixup_symbol_section (sym
, objfile
);
755 /* Now search all per-file blocks.
756 Not strictly correct, but more useful than an error.
757 Do the symtabs first, then check the psymtabs */
759 ALL_SYMTABS (objfile
, s
)
761 bv
= BLOCKVECTOR (s
);
762 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
763 sym
= lookup_block_symbol (block
, name
, namespace);
769 return fixup_symbol_section (sym
, objfile
);
773 ALL_PSYMTABS (objfile
, ps
)
775 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
777 s
= PSYMTAB_TO_SYMTAB(ps
);
778 bv
= BLOCKVECTOR (s
);
779 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
780 sym
= lookup_block_symbol (block
, name
, namespace);
782 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab", name
, ps
->filename
);
785 return fixup_symbol_section (sym
, objfile
);
794 /* Look, in partial_symtab PST, for symbol NAME. Check the global
795 symbols if GLOBAL, the static symbols if not */
797 static struct partial_symbol
*
798 lookup_partial_symbol (pst
, name
, global
, namespace)
799 struct partial_symtab
*pst
;
802 namespace_enum
namespace;
804 struct partial_symbol
**start
, **psym
;
805 struct partial_symbol
**top
, **bottom
, **center
;
806 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
807 int do_linear_search
= 1;
815 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
816 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
818 if (global
) /* This means we can use a binary search. */
820 do_linear_search
= 0;
822 /* Binary search. This search is guaranteed to end with center
823 pointing at the earliest partial symbol with the correct
824 name. At that point *all* partial symbols with that name
825 will be checked against the correct namespace. */
828 top
= start
+ length
- 1;
831 center
= bottom
+ (top
- bottom
) / 2;
834 if (!do_linear_search
&& SYMBOL_LANGUAGE (*center
) == language_cplus
)
836 do_linear_search
= 1;
838 if (STRCMP (SYMBOL_NAME (*center
), name
) >= 0)
847 if (!(top
== bottom
))
849 while (STREQ (SYMBOL_NAME (*top
), name
))
851 if (SYMBOL_NAMESPACE (*top
) == namespace)
859 /* Can't use a binary search or else we found during the binary search that
860 we should also do a linear search. */
862 if (do_linear_search
)
864 for (psym
= start
; psym
< start
+ length
; psym
++)
866 if (namespace == SYMBOL_NAMESPACE (*psym
))
868 if (SYMBOL_MATCHES_NAME (*psym
, name
))
879 /* Find the psymtab containing main(). */
880 /* FIXME: What about languages without main() or specially linked
881 executables that have no main() ? */
883 struct partial_symtab
*
886 register struct partial_symtab
*pst
;
887 register struct objfile
*objfile
;
889 ALL_PSYMTABS (objfile
, pst
)
891 if (lookup_partial_symbol (pst
, "main", 1, VAR_NAMESPACE
))
899 /* Search BLOCK for symbol NAME in NAMESPACE.
901 Note that if NAME is the demangled form of a C++ symbol, we will fail
902 to find a match during the binary search of the non-encoded names, but
903 for now we don't worry about the slight inefficiency of looking for
904 a match we'll never find, since it will go pretty quick. Once the
905 binary search terminates, we drop through and do a straight linear
906 search on the symbols. Each symbol which is marked as being a C++
907 symbol (language_cplus set) has both the encoded and non-encoded names
908 tested for a match. */
911 lookup_block_symbol (block
, name
, namespace)
912 register const struct block
*block
;
914 const namespace_enum
namespace;
916 register int bot
, top
, inc
;
917 register struct symbol
*sym
;
918 register struct symbol
*sym_found
= NULL
;
919 register int do_linear_search
= 1;
921 /* If the blocks's symbols were sorted, start with a binary search. */
923 if (BLOCK_SHOULD_SORT (block
))
925 /* Reset the linear search flag so if the binary search fails, we
926 won't do the linear search once unless we find some reason to
927 do so, such as finding a C++ symbol during the binary search.
928 Note that for C++ modules, ALL the symbols in a block should
929 end up marked as C++ symbols. */
931 do_linear_search
= 0;
932 top
= BLOCK_NSYMS (block
);
935 /* Advance BOT to not far before the first symbol whose name is NAME. */
939 inc
= (top
- bot
+ 1);
940 /* No need to keep binary searching for the last few bits worth. */
945 inc
= (inc
>> 1) + bot
;
946 sym
= BLOCK_SYM (block
, inc
);
947 if (!do_linear_search
&& SYMBOL_LANGUAGE (sym
) == language_cplus
)
949 do_linear_search
= 1;
951 if (SYMBOL_NAME (sym
)[0] < name
[0])
955 else if (SYMBOL_NAME (sym
)[0] > name
[0])
959 else if (STRCMP (SYMBOL_NAME (sym
), name
) < 0)
969 /* Now scan forward until we run out of symbols, find one whose
970 name is greater than NAME, or find one we want. If there is
971 more than one symbol with the right name and namespace, we
972 return the first one; I believe it is now impossible for us
973 to encounter two symbols with the same name and namespace
974 here, because blocks containing argument symbols are no
977 top
= BLOCK_NSYMS (block
);
980 sym
= BLOCK_SYM (block
, bot
);
981 inc
= SYMBOL_NAME (sym
)[0] - name
[0];
984 inc
= STRCMP (SYMBOL_NAME (sym
), name
);
986 if (inc
== 0 && SYMBOL_NAMESPACE (sym
) == namespace)
998 /* Here if block isn't sorted, or we fail to find a match during the
999 binary search above. If during the binary search above, we find a
1000 symbol which is a C++ symbol, then we have re-enabled the linear
1001 search flag which was reset when starting the binary search.
1003 This loop is equivalent to the loop above, but hacked greatly for speed.
1005 Note that parameter symbols do not always show up last in the
1006 list; this loop makes sure to take anything else other than
1007 parameter symbols first; it only uses parameter symbols as a
1008 last resort. Note that this only takes up extra computation
1011 if (do_linear_search
)
1013 top
= BLOCK_NSYMS (block
);
1017 sym
= BLOCK_SYM (block
, bot
);
1018 if (SYMBOL_NAMESPACE (sym
) == namespace &&
1019 SYMBOL_MATCHES_NAME (sym
, name
))
1021 /* Given pc, search thu alias list to find the active symbol. */
1022 if (SYMBOL_ALIASES (sym
))
1023 sym
= ref_search_val (sym
, read_pc ());
1026 if (SYMBOL_CLASS (sym
) != LOC_ARG
&&
1027 SYMBOL_CLASS (sym
) != LOC_LOCAL_ARG
&&
1028 SYMBOL_CLASS (sym
) != LOC_REF_ARG
&&
1029 SYMBOL_CLASS (sym
) != LOC_REGPARM
&&
1030 SYMBOL_CLASS (sym
) != LOC_REGPARM_ADDR
&&
1031 SYMBOL_CLASS (sym
) != LOC_BASEREG_ARG
)
1039 return (sym_found
); /* Will be NULL if not found. */
1043 /* Return the symbol for the function which contains a specified
1044 lexical block, described by a struct block BL. */
1050 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
1051 bl
= BLOCK_SUPERBLOCK (bl
);
1053 return BLOCK_FUNCTION (bl
);
1056 /* Find the symtab associated with PC and SECTION. Look through the
1057 psymtabs and read in another symtab if necessary. */
1060 find_pc_sect_symtab (pc
, section
)
1064 register struct block
*b
;
1065 struct blockvector
*bv
;
1066 register struct symtab
*s
= NULL
;
1067 register struct symtab
*best_s
= NULL
;
1068 register struct partial_symtab
*ps
;
1069 register struct objfile
*objfile
;
1070 CORE_ADDR distance
= 0;
1072 /* Search all symtabs for the one whose file contains our address, and which
1073 is the smallest of all the ones containing the address. This is designed
1074 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1075 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1076 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1078 This happens for native ecoff format, where code from included files
1079 gets its own symtab. The symtab for the included file should have
1080 been read in already via the dependency mechanism.
1081 It might be swifter to create several symtabs with the same name
1082 like xcoff does (I'm not sure).
1084 It also happens for objfiles that have their functions reordered.
1085 For these, the symtab we are looking for is not necessarily read in. */
1087 ALL_SYMTABS (objfile
, s
)
1089 bv
= BLOCKVECTOR (s
);
1090 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1091 if (BLOCK_START (b
) <= pc
1092 && BLOCK_END (b
) > pc
1094 || BLOCK_END (b
) - BLOCK_START (b
) < distance
))
1096 /* For an objfile that has its functions reordered,
1097 find_pc_psymtab will find the proper partial symbol table
1098 and we simply return its corresponding symtab. */
1099 /* In order to better support objfiles that contain both
1100 stabs and coff debugging info, we continue on if a psymtab
1102 if ((objfile
->flags
& OBJF_REORDERED
) && objfile
->psymtabs
)
1104 ps
= find_pc_sect_psymtab (pc
, section
);
1106 return PSYMTAB_TO_SYMTAB (ps
);
1112 for (i
= 0; i
< b
->nsyms
; i
++)
1114 fixup_symbol_section (b
->sym
[i
], objfile
);
1115 if (section
== SYMBOL_BFD_SECTION (b
->sym
[i
]))
1119 continue; /* no symbol in this symtab matches section */
1121 distance
= BLOCK_END (b
) - BLOCK_START (b
);
1130 ps
= find_pc_sect_psymtab (pc
, section
);
1134 /* Might want to error() here (in case symtab is corrupt and
1135 will cause a core dump), but maybe we can successfully
1136 continue, so let's not. */
1137 /* FIXME-32x64: assumes pc fits in a long */
1139 (Internal error: pc 0x%lx in read in psymtab, but not in symtab.)\n",
1140 (unsigned long) pc
);
1141 s
= PSYMTAB_TO_SYMTAB (ps
);
1146 /* Find the symtab associated with PC. Look through the psymtabs and
1147 read in another symtab if necessary. Backward compatibility, no section */
1153 return find_pc_sect_symtab (pc
, find_pc_mapped_section (pc
));
1159 /* Find the closest symbol value (of any sort -- function or variable)
1160 for a given address value. Slow but complete. (currently unused,
1161 mainly because it is too slow. We could fix it if each symtab and
1162 psymtab had contained in it the addresses ranges of each of its
1163 sections, which also would be required to make things like "info
1164 line *0x2345" cause psymtabs to be converted to symtabs). */
1167 find_addr_symbol (addr
, symtabp
, symaddrp
)
1169 struct symtab
**symtabp
;
1170 CORE_ADDR
*symaddrp
;
1172 struct symtab
*symtab
, *best_symtab
;
1173 struct objfile
*objfile
;
1174 register int bot
, top
;
1175 register struct symbol
*sym
;
1176 register CORE_ADDR sym_addr
;
1177 struct block
*block
;
1180 /* Info on best symbol seen so far */
1182 register CORE_ADDR best_sym_addr
= 0;
1183 struct symbol
*best_sym
= 0;
1185 /* FIXME -- we should pull in all the psymtabs, too! */
1186 ALL_SYMTABS (objfile
, symtab
)
1188 /* Search the global and static blocks in this symtab for
1189 the closest symbol-address to the desired address. */
1191 for (blocknum
= GLOBAL_BLOCK
; blocknum
<= STATIC_BLOCK
; blocknum
++)
1194 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab
), blocknum
);
1195 top
= BLOCK_NSYMS (block
);
1196 for (bot
= 0; bot
< top
; bot
++)
1198 sym
= BLOCK_SYM (block
, bot
);
1199 switch (SYMBOL_CLASS (sym
))
1203 sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1207 sym_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1214 if (sym_addr
<= addr
)
1215 if (sym_addr
> best_sym_addr
)
1217 /* Quit if we found an exact match. */
1219 best_sym_addr
= sym_addr
;
1220 best_symtab
= symtab
;
1221 if (sym_addr
== addr
)
1230 *symtabp
= best_symtab
;
1232 *symaddrp
= best_sym_addr
;
1237 /* Find the source file and line number for a given PC value and section.
1238 Return a structure containing a symtab pointer, a line number,
1239 and a pc range for the entire source line.
1240 The value's .pc field is NOT the specified pc.
1241 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1242 use the line that ends there. Otherwise, in that case, the line
1243 that begins there is used. */
1245 /* The big complication here is that a line may start in one file, and end just
1246 before the start of another file. This usually occurs when you #include
1247 code in the middle of a subroutine. To properly find the end of a line's PC
1248 range, we must search all symtabs associated with this compilation unit, and
1249 find the one whose first PC is closer than that of the next line in this
1252 /* If it's worth the effort, we could be using a binary search. */
1254 struct symtab_and_line
1255 find_pc_sect_line (pc
, section
, notcurrent
)
1257 struct sec
*section
;
1261 register struct linetable
*l
;
1264 register struct linetable_entry
*item
;
1265 struct symtab_and_line val
;
1266 struct blockvector
*bv
;
1268 /* Info on best line seen so far, and where it starts, and its file. */
1270 struct linetable_entry
*best
= NULL
;
1271 CORE_ADDR best_end
= 0;
1272 struct symtab
*best_symtab
= 0;
1274 /* Store here the first line number
1275 of a file which contains the line at the smallest pc after PC.
1276 If we don't find a line whose range contains PC,
1277 we will use a line one less than this,
1278 with a range from the start of that file to the first line's pc. */
1279 struct linetable_entry
*alt
= NULL
;
1280 struct symtab
*alt_symtab
= 0;
1282 /* Info on best line seen in this file. */
1284 struct linetable_entry
*prev
;
1286 /* If this pc is not from the current frame,
1287 it is the address of the end of a call instruction.
1288 Quite likely that is the start of the following statement.
1289 But what we want is the statement containing the instruction.
1290 Fudge the pc to make sure we get that. */
1292 INIT_SAL (&val
); /* initialize to zeroes */
1297 s
= find_pc_sect_symtab (pc
, section
);
1304 bv
= BLOCKVECTOR (s
);
1306 /* Look at all the symtabs that share this blockvector.
1307 They all have the same apriori range, that we found was right;
1308 but they have different line tables. */
1310 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1312 /* Find the best line in this symtab. */
1319 /* I think len can be zero if the symtab lacks line numbers
1320 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
1321 I'm not sure which, and maybe it depends on the symbol
1327 item
= l
->item
; /* Get first line info */
1329 /* Is this file's first line closer than the first lines of other files?
1330 If so, record this file, and its first line, as best alternate. */
1331 if (item
->pc
> pc
&& (!alt
|| item
->pc
< alt
->pc
))
1337 for (i
= 0; i
< len
; i
++, item
++)
1339 /* Leave prev pointing to the linetable entry for the last line
1340 that started at or before PC. */
1347 /* At this point, prev points at the line whose start addr is <= pc, and
1348 item points at the next line. If we ran off the end of the linetable
1349 (pc >= start of the last line), then prev == item. If pc < start of
1350 the first line, prev will not be set. */
1352 /* Is this file's best line closer than the best in the other files?
1353 If so, record this file, and its best line, as best so far. */
1355 if (prev
&& (!best
|| prev
->pc
> best
->pc
))
1359 /* If another line is in the linetable, and its PC is closer
1360 than the best_end we currently have, take it as best_end. */
1361 if (i
< len
&& (best_end
== 0 || best_end
> item
->pc
))
1362 best_end
= item
->pc
;
1369 { /* If we didn't find any line # info, just
1375 val
.symtab
= alt_symtab
;
1376 val
.line
= alt
->line
- 1;
1378 /* Don't return line 0, that means that we didn't find the line. */
1379 if (val
.line
== 0) ++val
.line
;
1381 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1387 val
.symtab
= best_symtab
;
1388 val
.line
= best
->line
;
1390 if (best_end
&& (!alt
|| best_end
< alt
->pc
))
1395 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1397 val
.section
= section
;
1401 /* Backward compatibility (no section) */
1403 struct symtab_and_line
1404 find_pc_line (pc
, notcurrent
)
1410 section
= find_pc_overlay (pc
);
1411 if (pc_in_unmapped_range (pc
, section
))
1412 pc
= overlay_mapped_address (pc
, section
);
1413 return find_pc_sect_line (pc
, section
, notcurrent
);
1417 static int find_line_symtab
PARAMS ((struct symtab
*, int, struct linetable
**,
1420 /* Find line number LINE in any symtab whose name is the same as
1423 If found, return 1, set *LINETABLE to the linetable in which it was
1424 found, set *INDEX to the index in the linetable of the best entry
1425 found, and set *EXACT_MATCH nonzero if the value returned is an
1428 If not found, return 0. */
1431 find_line_symtab (symtab
, line
, linetable
, index
, exact_match
)
1432 struct symtab
*symtab
;
1434 struct linetable
**linetable
;
1440 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
1444 struct linetable
*best_linetable
;
1446 /* First try looking it up in the given symtab. */
1447 best_linetable
= LINETABLE (symtab
);
1448 best_index
= find_line_common (best_linetable
, line
, &exact
);
1449 if (best_index
< 0 || !exact
)
1451 /* Didn't find an exact match. So we better keep looking for
1452 another symtab with the same name. In the case of xcoff,
1453 multiple csects for one source file (produced by IBM's FORTRAN
1454 compiler) produce multiple symtabs (this is unavoidable
1455 assuming csects can be at arbitrary places in memory and that
1456 the GLOBAL_BLOCK of a symtab has a begin and end address). */
1458 /* BEST is the smallest linenumber > LINE so far seen,
1459 or 0 if none has been seen so far.
1460 BEST_INDEX and BEST_LINETABLE identify the item for it. */
1463 struct objfile
*objfile
;
1466 if (best_index
>= 0)
1467 best
= best_linetable
->item
[best_index
].line
;
1471 ALL_SYMTABS (objfile
, s
)
1473 struct linetable
*l
;
1476 if (!STREQ (symtab
->filename
, s
->filename
))
1479 ind
= find_line_common (l
, line
, &exact
);
1488 if (best
== 0 || l
->item
[ind
].line
< best
)
1490 best
= l
->item
[ind
].line
;
1502 *index
= best_index
;
1504 *linetable
= best_linetable
;
1506 *exact_match
= exact
;
1510 /* Find the PC value for a given source file and line number.
1511 Returns zero for invalid line number.
1512 The source file is specified with a struct symtab. */
1515 find_line_pc (symtab
, line
)
1516 struct symtab
*symtab
;
1519 struct linetable
*l
;
1524 if (find_line_symtab (symtab
, line
, &l
, &ind
, NULL
))
1525 return l
->item
[ind
].pc
;
1530 /* Find the range of pc values in a line.
1531 Store the starting pc of the line into *STARTPTR
1532 and the ending pc (start of next line) into *ENDPTR.
1533 Returns 1 to indicate success.
1534 Returns 0 if could not find the specified line. */
1537 find_line_pc_range (sal
, startptr
, endptr
)
1538 struct symtab_and_line sal
;
1539 CORE_ADDR
*startptr
, *endptr
;
1541 CORE_ADDR startaddr
;
1542 struct symtab_and_line found_sal
;
1547 startaddr
= find_line_pc (sal
.symtab
, sal
.line
);
1552 /* This whole function is based on address. For example, if line 10 has
1553 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
1554 "info line *0x123" should say the line goes from 0x100 to 0x200
1555 and "info line *0x355" should say the line goes from 0x300 to 0x400.
1556 This also insures that we never give a range like "starts at 0x134
1557 and ends at 0x12c". */
1559 found_sal
= find_pc_sect_line (startaddr
, sal
.section
, 0);
1560 if (found_sal
.line
!= sal
.line
)
1562 /* The specified line (sal) has zero bytes. */
1563 *startptr
= found_sal
.pc
;
1564 *endptr
= found_sal
.pc
;
1568 *startptr
= found_sal
.pc
;
1569 *endptr
= found_sal
.end
;
1574 /* Given a line table and a line number, return the index into the line
1575 table for the pc of the nearest line whose number is >= the specified one.
1576 Return -1 if none is found. The value is >= 0 if it is an index.
1578 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1581 find_line_common (l
, lineno
, exact_match
)
1582 register struct linetable
*l
;
1583 register int lineno
;
1589 /* BEST is the smallest linenumber > LINENO so far seen,
1590 or 0 if none has been seen so far.
1591 BEST_INDEX identifies the item for it. */
1593 int best_index
= -1;
1602 for (i
= 0; i
< len
; i
++)
1604 register struct linetable_entry
*item
= &(l
->item
[i
]);
1606 if (item
->line
== lineno
)
1608 /* Return the first (lowest address) entry which matches. */
1613 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
1620 /* If we got here, we didn't get an exact match. */
1627 find_pc_line_pc_range (pc
, startptr
, endptr
)
1629 CORE_ADDR
*startptr
, *endptr
;
1631 struct symtab_and_line sal
;
1632 sal
= find_pc_line (pc
, 0);
1635 return sal
.symtab
!= 0;
1638 /* Given a function symbol SYM, find the symtab and line for the start
1640 If the argument FUNFIRSTLINE is nonzero, we want the first line
1641 of real code inside the function. */
1643 static struct symtab_and_line
1644 find_function_start_sal
PARAMS ((struct symbol
*sym
, int));
1646 static struct symtab_and_line
1647 find_function_start_sal (sym
, funfirstline
)
1652 struct symtab_and_line sal
;
1654 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1655 fixup_symbol_section (sym
, NULL
);
1657 { /* skip "first line" of function (which is actually its prologue) */
1658 asection
*section
= SYMBOL_BFD_SECTION (sym
);
1659 /* If function is in an unmapped overlay, use its unmapped LMA
1660 address, so that SKIP_PROLOGUE has something unique to work on */
1661 if (section_is_overlay (section
) &&
1662 !section_is_mapped (section
))
1663 pc
= overlay_unmapped_address (pc
, section
);
1665 pc
+= FUNCTION_START_OFFSET
;
1668 /* For overlays, map pc back into its mapped VMA range */
1669 pc
= overlay_mapped_address (pc
, section
);
1671 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
1673 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1674 /* Convex: no need to suppress code on first line, if any */
1677 /* Check if SKIP_PROLOGUE left us in mid-line, and the next
1678 line is still part of the same function. */
1680 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) <= sal
.end
1681 && sal
.end
< BLOCK_END (SYMBOL_BLOCK_VALUE (sym
)))
1683 /* First pc of next line */
1685 /* Recalculate the line number (might not be N+1). */
1686 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
1694 /* If P is of the form "operator[ \t]+..." where `...' is
1695 some legitimate operator text, return a pointer to the
1696 beginning of the substring of the operator text.
1697 Otherwise, return "". */
1699 operator_chars (p
, end
)
1704 if (strncmp (p
, "operator", 8))
1708 /* Don't get faked out by `operator' being part of a longer
1710 if (isalpha(*p
) || *p
== '_' || *p
== '$' || *p
== '\0')
1713 /* Allow some whitespace between `operator' and the operator symbol. */
1714 while (*p
== ' ' || *p
== '\t')
1717 /* Recognize 'operator TYPENAME'. */
1719 if (isalpha(*p
) || *p
== '_' || *p
== '$')
1721 register char *q
= p
+1;
1722 while (isalnum(*q
) || *q
== '_' || *q
== '$')
1747 if (p
[1] == '=' || p
[1] == p
[0])
1758 error ("`operator ()' must be specified without whitespace in `()'");
1763 error ("`operator ?:' must be specified without whitespace in `?:'");
1768 error ("`operator []' must be specified without whitespace in `[]'");
1772 error ("`operator %s' not supported", p
);
1779 /* Return the number of methods described for TYPE, including the
1780 methods from types it derives from. This can't be done in the symbol
1781 reader because the type of the baseclass might still be stubbed
1782 when the definition of the derived class is parsed. */
1784 static int total_number_of_methods
PARAMS ((struct type
*type
));
1787 total_number_of_methods (type
)
1793 CHECK_TYPEDEF (type
);
1794 if (TYPE_CPLUS_SPECIFIC (type
) == NULL
)
1796 count
= TYPE_NFN_FIELDS_TOTAL (type
);
1798 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
1799 count
+= total_number_of_methods (TYPE_BASECLASS (type
, n
));
1804 /* Recursive helper function for decode_line_1.
1805 Look for methods named NAME in type T.
1806 Return number of matches.
1807 Put matches in SYM_ARR, which should have been allocated with
1808 a size of total_number_of_methods (T) * sizeof (struct symbol *).
1809 Note that this function is g++ specific. */
1812 find_methods (t
, name
, sym_arr
)
1815 struct symbol
**sym_arr
;
1819 struct symbol
*sym_class
;
1820 char *class_name
= type_name_no_tag (t
);
1821 /* Ignore this class if it doesn't have a name. This is ugly, but
1822 unless we figure out how to get the physname without the name of
1823 the class, then the loop can't do any good. */
1825 && (sym_class
= lookup_symbol (class_name
,
1826 (struct block
*)NULL
,
1829 (struct symtab
**)NULL
)))
1832 /* FIXME: Shouldn't this just be CHECK_TYPEDEF (t)? */
1833 t
= SYMBOL_TYPE (sym_class
);
1834 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
1835 method_counter
>= 0;
1839 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
1840 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
1841 char dem_opname
[64];
1843 if (strncmp(method_name
, "__", 2)==0 ||
1844 strncmp(method_name
, "op", 2)==0 ||
1845 strncmp(method_name
, "type", 4)==0 )
1847 if (cplus_demangle_opname(method_name
, dem_opname
, DMGL_ANSI
))
1848 method_name
= dem_opname
;
1849 else if (cplus_demangle_opname(method_name
, dem_opname
, 0))
1850 method_name
= dem_opname
;
1852 if (STREQ (name
, method_name
))
1853 /* Find all the fields with that name. */
1854 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
1859 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
1860 check_stub_method (t
, method_counter
, field_counter
);
1861 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
1862 /* Destructor is handled by caller, dont add it to the list */
1863 if (DESTRUCTOR_PREFIX_P (phys_name
))
1866 sym_arr
[i1
] = lookup_symbol (phys_name
,
1867 NULL
, VAR_NAMESPACE
,
1869 (struct symtab
**) NULL
);
1874 fputs_filtered("(Cannot find method ", gdb_stdout
);
1875 fprintf_symbol_filtered (gdb_stdout
, phys_name
,
1877 DMGL_PARAMS
| DMGL_ANSI
);
1878 fputs_filtered(" - possibly inlined.)\n", gdb_stdout
);
1884 /* Only search baseclasses if there is no match yet, since names in
1885 derived classes override those in baseclasses.
1887 FIXME: The above is not true; it is only true of member functions
1888 if they have the same number of arguments (??? - section 13.1 of the
1889 ARM says the function members are not in the same scope but doesn't
1890 really spell out the rules in a way I understand. In any case, if
1891 the number of arguments differ this is a case in which we can overload
1892 rather than hiding without any problem, and gcc 2.4.5 does overload
1893 rather than hiding in this case). */
1897 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
1898 i1
+= find_methods(TYPE_BASECLASS(t
, ibase
), name
,
1903 /* Helper function for decode_line_1.
1904 Build a canonical line spec in CANONICAL if it is non-NULL and if
1905 the SAL has a symtab.
1906 If SYMNAME is non-NULL the canonical line spec is `filename:symname'.
1907 If SYMNAME is NULL the line number from SAL is used and the canonical
1908 line spec is `filename:linenum'. */
1911 build_canonical_line_spec (sal
, symname
, canonical
)
1912 struct symtab_and_line
*sal
;
1916 char **canonical_arr
;
1917 char *canonical_name
;
1919 struct symtab
*s
= sal
->symtab
;
1921 if (s
== (struct symtab
*)NULL
1922 || s
->filename
== (char *)NULL
1923 || canonical
== (char ***)NULL
)
1926 canonical_arr
= (char **) xmalloc (sizeof (char *));
1927 *canonical
= canonical_arr
;
1929 filename
= s
->filename
;
1930 if (symname
!= NULL
)
1932 canonical_name
= xmalloc (strlen (filename
) + strlen (symname
) + 2);
1933 sprintf (canonical_name
, "%s:%s", filename
, symname
);
1937 canonical_name
= xmalloc (strlen (filename
) + 30);
1938 sprintf (canonical_name
, "%s:%d", filename
, sal
->line
);
1940 canonical_arr
[0] = canonical_name
;
1943 /* Parse a string that specifies a line number.
1944 Pass the address of a char * variable; that variable will be
1945 advanced over the characters actually parsed.
1949 LINENUM -- that line number in current file. PC returned is 0.
1950 FILE:LINENUM -- that line in that file. PC returned is 0.
1951 FUNCTION -- line number of openbrace of that function.
1952 PC returned is the start of the function.
1953 VARIABLE -- line number of definition of that variable.
1955 FILE:FUNCTION -- likewise, but prefer functions in that file.
1956 *EXPR -- line in which address EXPR appears.
1958 FUNCTION may be an undebuggable function found in minimal symbol table.
1960 If the argument FUNFIRSTLINE is nonzero, we want the first line
1961 of real code inside a function when a function is specified, and it is
1962 not OK to specify a variable or type to get its line number.
1964 DEFAULT_SYMTAB specifies the file to use if none is specified.
1965 It defaults to current_source_symtab.
1966 DEFAULT_LINE specifies the line number to use for relative
1967 line numbers (that start with signs). Defaults to current_source_line.
1968 If CANONICAL is non-NULL, store an array of strings containing the canonical
1969 line specs there if necessary. Currently overloaded member functions and
1970 line numbers or static functions without a filename yield a canonical
1971 line spec. The array and the line spec strings are allocated on the heap,
1972 it is the callers responsibility to free them.
1974 Note that it is possible to return zero for the symtab
1975 if no file is validly specified. Callers must check that.
1976 Also, the line number returned may be invalid. */
1978 /* We allow single quotes in various places. This is a hideous
1979 kludge, which exists because the completer can't yet deal with the
1980 lack of single quotes. FIXME: write a linespec_completer which we
1981 can use as appropriate instead of make_symbol_completion_list. */
1983 struct symtabs_and_lines
1984 decode_line_1 (argptr
, funfirstline
, default_symtab
, default_line
, canonical
)
1987 struct symtab
*default_symtab
;
1991 struct symtabs_and_lines values
;
1992 #ifdef HPPA_COMPILER_BUG
1993 /* FIXME: The native HP 9000/700 compiler has a bug which appears
1994 when optimizing this file with target i960-vxworks. I haven't
1995 been able to construct a simple test case. The problem is that
1996 in the second call to SKIP_PROLOGUE below, the compiler somehow
1997 does not realize that the statement val = find_pc_line (...) will
1998 change the values of the fields of val. It extracts the elements
1999 into registers at the top of the block, and does not update the
2000 registers after the call to find_pc_line. You can check this by
2001 inserting a printf at the end of find_pc_line to show what values
2002 it is returning for val.pc and val.end and another printf after
2003 the call to see what values the function actually got (remember,
2004 this is compiling with cc -O, with this patch removed). You can
2005 also examine the assembly listing: search for the second call to
2006 skip_prologue; the LDO statement before the next call to
2007 find_pc_line loads the address of the structure which
2008 find_pc_line will return; if there is a LDW just before the LDO,
2009 which fetches an element of the structure, then the compiler
2012 Setting val to volatile avoids the problem. We must undef
2013 volatile, because the HPPA native compiler does not define
2014 __STDC__, although it does understand volatile, and so volatile
2015 will have been defined away in defs.h. */
2017 volatile struct symtab_and_line val
;
2018 #define volatile /*nothing*/
2020 struct symtab_and_line val
;
2022 register char *p
, *p1
;
2027 register struct symtab
*s
;
2029 register struct symbol
*sym
;
2030 /* The symtab that SYM was found in. */
2031 struct symtab
*sym_symtab
;
2033 register CORE_ADDR pc
;
2034 register struct minimal_symbol
*msymbol
;
2036 struct symbol
*sym_class
;
2038 int is_quoted
, has_parens
;
2039 struct symbol
**sym_arr
;
2041 char *saved_arg
= *argptr
;
2042 extern char *gdb_completer_quote_characters
;
2044 INIT_SAL (&val
); /* initialize to zeroes */
2046 /* Defaults have defaults. */
2048 if (default_symtab
== 0)
2050 default_symtab
= current_source_symtab
;
2051 default_line
= current_source_line
;
2054 /* See if arg is *PC */
2056 if (**argptr
== '*')
2059 pc
= parse_and_eval_address_1 (argptr
);
2060 values
.sals
= (struct symtab_and_line
*)
2061 xmalloc (sizeof (struct symtab_and_line
));
2063 values
.sals
[0] = find_pc_line (pc
, 0);
2064 values
.sals
[0].pc
= pc
;
2068 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
2071 is_quoted
= (**argptr
2072 && strchr (gdb_completer_quote_characters
, **argptr
) != NULL
);
2073 has_parens
= ((pp
= strchr (*argptr
, '(')) != NULL
2074 && (pp
= strchr (pp
, ')')) != NULL
);
2076 for (p
= *argptr
; *p
; p
++)
2080 while(++p
&& *p
!= '>');
2083 error ("non-matching '<' and '>' in command");
2086 if (p
[0] == ':' || p
[0] == ' ' || p
[0] == '\t')
2088 if (p
[0] == '.' && strchr (p
, ':') == NULL
) /* Java qualified method. */
2090 /* Find the *last* '.', since the others are package qualifiers. */
2091 for (p1
= p
; *p1
; p1
++)
2099 while (p
[0] == ' ' || p
[0] == '\t') p
++;
2101 if ((p
[0] == ':' || p
[0] == '.') && !has_parens
)
2105 if (is_quoted
) *argptr
= *argptr
+1;
2106 if (p
[0] == '.' || p
[1] ==':')
2108 /* Extract the class name. */
2110 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
2111 copy
= (char *) alloca (p
- *argptr
+ 1);
2112 memcpy (copy
, *argptr
, p
- *argptr
);
2113 copy
[p
- *argptr
] = 0;
2115 /* Discard the class name from the arg. */
2116 p
= p1
+ (p1
[0] == ':' ? 2 : 1);
2117 while (*p
== ' ' || *p
== '\t') p
++;
2120 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
2121 (struct symtab
**)NULL
);
2124 (t
= check_typedef (SYMBOL_TYPE (sym_class
)),
2125 (TYPE_CODE (t
) == TYPE_CODE_STRUCT
2126 || TYPE_CODE (t
) == TYPE_CODE_UNION
)))
2128 /* Arg token is not digits => try it as a function name
2129 Find the next token(everything up to end or next blank). */
2131 && strchr (gdb_completer_quote_characters
, **argptr
) != NULL
)
2133 p
= skip_quoted(*argptr
);
2134 *argptr
= *argptr
+ 1;
2139 while (*p
&& *p
!=' ' && *p
!='\t' && *p
!=',' && *p
!=':') p
++;
2142 q = operator_chars (*argptr, &q1);
2146 char *tmp = alloca (q1 - q + 1);
2147 memcpy (tmp, q, q1 - q);
2149 opname = cplus_mangle_opname (tmp, DMGL_ANSI);
2153 printf_filtered ("no mangling for \"%s\"\n", tmp);
2154 cplusplus_hint (saved_arg);
2155 return_to_top_level (RETURN_ERROR);
2157 copy = (char*) alloca (3 + strlen(opname));
2158 sprintf (copy, "__%s", opname);
2164 copy
= (char *) alloca (p
- *argptr
+ 1 );
2165 memcpy (copy
, *argptr
, p
- *argptr
);
2166 copy
[p
- *argptr
] = '\0';
2168 && copy
[p
- *argptr
- 1]
2169 && strchr (gdb_completer_quote_characters
,
2170 copy
[p
- *argptr
- 1]) != NULL
)
2171 copy
[p
- *argptr
- 1] = '\0';
2174 /* no line number may be specified */
2175 while (*p
== ' ' || *p
== '\t') p
++;
2179 i1
= 0; /* counter for the symbol array */
2180 sym_arr
= (struct symbol
**) alloca(total_number_of_methods (t
)
2181 * sizeof(struct symbol
*));
2183 if (destructor_name_p (copy
, t
))
2185 /* Destructors are a special case. */
2186 int m_index
, f_index
;
2188 if (get_destructor_fn_field (t
, &m_index
, &f_index
))
2190 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, m_index
);
2193 lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f
, f_index
),
2194 NULL
, VAR_NAMESPACE
, (int *) NULL
,
2195 (struct symtab
**)NULL
);
2201 i1
= find_methods (t
, copy
, sym_arr
);
2204 /* There is exactly one field with that name. */
2207 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2209 values
.sals
= (struct symtab_and_line
*)
2210 xmalloc (sizeof (struct symtab_and_line
));
2212 values
.sals
[0] = find_function_start_sal (sym
,
2223 /* There is more than one field with that name
2224 (overloaded). Ask the user which one to use. */
2225 return decode_line_2 (sym_arr
, i1
, funfirstline
, canonical
);
2231 if (OPNAME_PREFIX_P (copy
))
2233 tmp
= (char *)alloca (strlen (copy
+3) + 9);
2234 strcpy (tmp
, "operator ");
2235 strcat (tmp
, copy
+3);
2242 ("the class `%s' does not have destructor defined\n",
2243 SYMBOL_SOURCE_NAME(sym_class
));
2246 ("the class %s does not have any method named %s\n",
2247 SYMBOL_SOURCE_NAME(sym_class
), tmp
);
2248 cplusplus_hint (saved_arg
);
2249 return_to_top_level (RETURN_ERROR
);
2255 /* The quotes are important if copy is empty. */
2257 ("can't find class, struct, or union named \"%s\"\n", copy
);
2258 cplusplus_hint (saved_arg
);
2259 return_to_top_level (RETURN_ERROR
);
2265 /* Extract the file name. */
2267 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
2268 copy
= (char *) alloca (p
- *argptr
+ 1);
2269 memcpy (copy
, *argptr
, p
- *argptr
);
2270 copy
[p
- *argptr
] = 0;
2272 /* Find that file's data. */
2273 s
= lookup_symtab (copy
);
2276 if (!have_full_symbols () && !have_partial_symbols ())
2277 error (no_symtab_msg
);
2278 error ("No source file named %s.", copy
);
2281 /* Discard the file name from the arg. */
2283 while (*p
== ' ' || *p
== '\t') p
++;
2287 /* S is specified file's symtab, or 0 if no file specified.
2288 arg no longer contains the file name. */
2290 /* Check whether arg is all digits (and sign) */
2293 if (*q
== '-' || *q
== '+') q
++;
2294 while (*q
>= '0' && *q
<= '9')
2297 if (q
!= *argptr
&& (*q
== 0 || *q
== ' ' || *q
== '\t' || *q
== ','))
2299 /* We found a token consisting of all digits -- at least one digit. */
2300 enum sign
{none
, plus
, minus
} sign
= none
;
2302 /* We might need a canonical line spec if no file was specified. */
2303 int need_canonical
= (s
== 0) ? 1 : 0;
2305 /* This is where we need to make sure that we have good defaults.
2306 We must guarantee that this section of code is never executed
2307 when we are called with just a function name, since
2308 select_source_symtab calls us with such an argument */
2310 if (s
== 0 && default_symtab
== 0)
2312 select_source_symtab (0);
2313 default_symtab
= current_source_symtab
;
2314 default_line
= current_source_line
;
2317 if (**argptr
== '+')
2318 sign
= plus
, (*argptr
)++;
2319 else if (**argptr
== '-')
2320 sign
= minus
, (*argptr
)++;
2321 val
.line
= atoi (*argptr
);
2328 val
.line
= default_line
+ val
.line
;
2334 val
.line
= default_line
- val
.line
;
2339 break; /* No need to adjust val.line. */
2342 while (*q
== ' ' || *q
== '\t') q
++;
2348 values
.sals
= (struct symtab_and_line
*)
2349 xmalloc (sizeof (struct symtab_and_line
));
2350 values
.sals
[0] = val
;
2353 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
2357 /* Arg token is not digits => try it as a variable name
2358 Find the next token (everything up to end or next whitespace). */
2360 if (**argptr
== '$') /* Convenience variable */
2361 p
= skip_quoted (*argptr
+ 1);
2364 p
= skip_quoted (*argptr
);
2366 error ("Unmatched single quote.");
2368 else if (has_parens
)
2374 p
= skip_quoted(*argptr
);
2377 copy
= (char *) alloca (p
- *argptr
+ 1);
2378 memcpy (copy
, *argptr
, p
- *argptr
);
2379 copy
[p
- *argptr
] = '\0';
2382 && copy
[0] == copy
[p
- *argptr
- 1]
2383 && strchr (gdb_completer_quote_characters
, copy
[0]) != NULL
)
2385 copy
[p
- *argptr
- 1] = '\0';
2388 while (*p
== ' ' || *p
== '\t') p
++;
2391 /* See if it's a convenience variable */
2396 int need_canonical
= (s
== 0) ? 1 : 0;
2398 valx
= value_of_internalvar (lookup_internalvar (copy
+ 1));
2399 if (TYPE_CODE (VALUE_TYPE (valx
)) != TYPE_CODE_INT
)
2400 error ("Convenience variables used in line specs must have integer values.");
2402 val
.symtab
= s
? s
: default_symtab
;
2403 val
.line
= value_as_long (valx
);
2406 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof val
);
2407 values
.sals
[0] = val
;
2411 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
2417 /* Look up that token as a variable.
2418 If file specified, use that file's per-file block to start with. */
2420 sym
= lookup_symbol (copy
,
2421 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
2422 : get_selected_block ()),
2423 VAR_NAMESPACE
, 0, &sym_symtab
);
2427 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2429 /* Arg is the name of a function */
2430 values
.sals
= (struct symtab_and_line
*)
2431 xmalloc (sizeof (struct symtab_and_line
));
2432 values
.sals
[0] = find_function_start_sal (sym
, funfirstline
);
2435 /* Don't use the SYMBOL_LINE; if used at all it points to
2436 the line containing the parameters or thereabouts, not
2437 the first line of code. */
2439 /* We might need a canonical line spec if it is a static
2443 struct blockvector
*bv
= BLOCKVECTOR (sym_symtab
);
2444 struct block
*b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2445 if (lookup_block_symbol (b
, copy
, VAR_NAMESPACE
) != NULL
)
2446 build_canonical_line_spec (values
.sals
, copy
, canonical
);
2453 error ("\"%s\" is not a function", copy
);
2454 else if (SYMBOL_LINE (sym
) != 0)
2456 /* We know its line number. */
2457 values
.sals
= (struct symtab_and_line
*)
2458 xmalloc (sizeof (struct symtab_and_line
));
2460 memset (&values
.sals
[0], 0, sizeof (values
.sals
[0]));
2461 values
.sals
[0].symtab
= sym_symtab
;
2462 values
.sals
[0].line
= SYMBOL_LINE (sym
);
2466 /* This can happen if it is compiled with a compiler which doesn't
2467 put out line numbers for variables. */
2468 /* FIXME: Shouldn't we just set .line and .symtab to zero
2469 and return? For example, "info line foo" could print
2471 error ("Line number not known for symbol \"%s\"", copy
);
2475 msymbol
= lookup_minimal_symbol (copy
, NULL
, NULL
);
2476 if (msymbol
!= NULL
)
2478 val
.pc
= SYMBOL_VALUE_ADDRESS (msymbol
);
2479 val
.section
= SYMBOL_BFD_SECTION (msymbol
);
2482 val
.pc
+= FUNCTION_START_OFFSET
;
2483 SKIP_PROLOGUE (val
.pc
);
2485 values
.sals
= (struct symtab_and_line
*)
2486 xmalloc (sizeof (struct symtab_and_line
));
2487 values
.sals
[0] = val
;
2492 if (!have_full_symbols () &&
2493 !have_partial_symbols () && !have_minimal_symbols ())
2494 error (no_symtab_msg
);
2496 error ("Function \"%s\" not defined.", copy
);
2497 return values
; /* for lint */
2500 struct symtabs_and_lines
2501 decode_line_spec (string
, funfirstline
)
2505 struct symtabs_and_lines sals
;
2507 error ("Empty line specification.");
2508 sals
= decode_line_1 (&string
, funfirstline
,
2509 current_source_symtab
, current_source_line
,
2512 error ("Junk at end of line specification: %s", string
);
2516 /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to
2517 operate on (ask user if necessary).
2518 If CANONICAL is non-NULL return a corresponding array of mangled names
2519 as canonical line specs there. */
2521 static struct symtabs_and_lines
2522 decode_line_2 (sym_arr
, nelts
, funfirstline
, canonical
)
2523 struct symbol
*sym_arr
[];
2528 struct symtabs_and_lines values
, return_values
;
2533 struct cleanup
*old_chain
;
2534 char **canonical_arr
= (char **)NULL
;
2536 values
.sals
= (struct symtab_and_line
*)
2537 alloca (nelts
* sizeof(struct symtab_and_line
));
2538 return_values
.sals
= (struct symtab_and_line
*)
2539 xmalloc (nelts
* sizeof(struct symtab_and_line
));
2540 old_chain
= make_cleanup (free
, return_values
.sals
);
2544 canonical_arr
= (char **) xmalloc (nelts
* sizeof (char *));
2545 make_cleanup (free
, canonical_arr
);
2546 memset (canonical_arr
, 0, nelts
* sizeof (char *));
2547 *canonical
= canonical_arr
;
2551 printf_unfiltered("[0] cancel\n[1] all\n");
2554 INIT_SAL (&return_values
.sals
[i
]); /* initialize to zeroes */
2555 INIT_SAL (&values
.sals
[i
]);
2556 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
2558 values
.sals
[i
] = find_function_start_sal (sym_arr
[i
], funfirstline
);
2559 printf_unfiltered ("[%d] %s at %s:%d\n",
2561 SYMBOL_SOURCE_NAME (sym_arr
[i
]),
2562 values
.sals
[i
].symtab
->filename
,
2563 values
.sals
[i
].line
);
2566 printf_unfiltered ("?HERE\n");
2570 if ((prompt
= getenv ("PS2")) == NULL
)
2574 printf_unfiltered("%s ",prompt
);
2575 gdb_flush(gdb_stdout
);
2577 args
= command_line_input ((char *) NULL
, 0, "overload-choice");
2579 if (args
== 0 || *args
== 0)
2580 error_no_arg ("one or more choice numbers");
2588 while (*arg1
>= '0' && *arg1
<= '9') arg1
++;
2589 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
2590 error ("Arguments must be choice numbers.");
2595 error ("cancelled");
2600 for (i
= 0; i
< nelts
; i
++)
2602 if (canonical_arr
[i
] == NULL
)
2604 symname
= SYMBOL_NAME (sym_arr
[i
]);
2605 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
2609 memcpy (return_values
.sals
, values
.sals
,
2610 (nelts
* sizeof(struct symtab_and_line
)));
2611 return_values
.nelts
= nelts
;
2612 discard_cleanups (old_chain
);
2613 return return_values
;
2616 if (num
>= nelts
+ 2)
2618 printf_unfiltered ("No choice number %d.\n", num
);
2623 if (values
.sals
[num
].pc
)
2627 symname
= SYMBOL_NAME (sym_arr
[num
]);
2628 make_cleanup (free
, symname
);
2629 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
2631 return_values
.sals
[i
++] = values
.sals
[num
];
2632 values
.sals
[num
].pc
= 0;
2636 printf_unfiltered ("duplicate request for %d ignored.\n", num
);
2641 while (*args
== ' ' || *args
== '\t') args
++;
2643 return_values
.nelts
= i
;
2644 discard_cleanups (old_chain
);
2645 return return_values
;
2649 /* Slave routine for sources_info. Force line breaks at ,'s.
2650 NAME is the name to print and *FIRST is nonzero if this is the first
2651 name printed. Set *FIRST to zero. */
2653 output_source_filename (name
, first
)
2657 /* Table of files printed so far. Since a single source file can
2658 result in several partial symbol tables, we need to avoid printing
2659 it more than once. Note: if some of the psymtabs are read in and
2660 some are not, it gets printed both under "Source files for which
2661 symbols have been read" and "Source files for which symbols will
2662 be read in on demand". I consider this a reasonable way to deal
2663 with the situation. I'm not sure whether this can also happen for
2664 symtabs; it doesn't hurt to check. */
2665 static char **tab
= NULL
;
2666 /* Allocated size of tab in elements.
2667 Start with one 256-byte block (when using GNU malloc.c).
2668 24 is the malloc overhead when range checking is in effect. */
2669 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
2670 /* Current size of tab in elements. */
2671 static int tab_cur_size
;
2678 tab
= (char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
2682 /* Is NAME in tab? */
2683 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
2684 if (STREQ (*p
, name
))
2685 /* Yes; don't print it again. */
2687 /* No; add it to tab. */
2688 if (tab_cur_size
== tab_alloc_size
)
2690 tab_alloc_size
*= 2;
2691 tab
= (char **) xrealloc ((char *) tab
, tab_alloc_size
* sizeof (*tab
));
2693 tab
[tab_cur_size
++] = name
;
2701 printf_filtered (", ");
2705 fputs_filtered (name
, gdb_stdout
);
2709 sources_info (ignore
, from_tty
)
2713 register struct symtab
*s
;
2714 register struct partial_symtab
*ps
;
2715 register struct objfile
*objfile
;
2718 if (!have_full_symbols () && !have_partial_symbols ())
2720 error (no_symtab_msg
);
2723 printf_filtered ("Source files for which symbols have been read in:\n\n");
2726 ALL_SYMTABS (objfile
, s
)
2728 output_source_filename (s
-> filename
, &first
);
2730 printf_filtered ("\n\n");
2732 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2735 ALL_PSYMTABS (objfile
, ps
)
2739 output_source_filename (ps
-> filename
, &first
);
2742 printf_filtered ("\n");
2745 /* List all symbols (if REGEXP is NULL) or all symbols matching REGEXP.
2746 If CLASS is zero, list all symbols except functions, type names, and
2748 If CLASS is 1, list only functions.
2749 If CLASS is 2, list only type names.
2750 If CLASS is 3, list only method names.
2752 BPT is non-zero if we should set a breakpoint at the functions
2756 list_symbols (regexp
, class, bpt
, from_tty
)
2762 register struct symtab
*s
;
2763 register struct partial_symtab
*ps
;
2764 register struct blockvector
*bv
;
2765 struct blockvector
*prev_bv
= 0;
2766 register struct block
*b
;
2768 register struct symbol
*sym
;
2769 struct partial_symbol
**psym
;
2770 struct objfile
*objfile
;
2771 struct minimal_symbol
*msymbol
;
2773 static char *classnames
[]
2774 = {"variable", "function", "type", "method"};
2775 int found_in_file
= 0;
2777 static enum minimal_symbol_type types
[]
2778 = {mst_data
, mst_text
, mst_abs
, mst_unknown
};
2779 static enum minimal_symbol_type types2
[]
2780 = {mst_bss
, mst_file_text
, mst_abs
, mst_unknown
};
2781 static enum minimal_symbol_type types3
[]
2782 = {mst_file_data
, mst_solib_trampoline
, mst_abs
, mst_unknown
};
2783 static enum minimal_symbol_type types4
[]
2784 = {mst_file_bss
, mst_text
, mst_abs
, mst_unknown
};
2785 enum minimal_symbol_type ourtype
= types
[class];
2786 enum minimal_symbol_type ourtype2
= types2
[class];
2787 enum minimal_symbol_type ourtype3
= types3
[class];
2788 enum minimal_symbol_type ourtype4
= types4
[class];
2792 /* Make sure spacing is right for C++ operators.
2793 This is just a courtesy to make the matching less sensitive
2794 to how many spaces the user leaves between 'operator'
2795 and <TYPENAME> or <OPERATOR>. */
2797 char *opname
= operator_chars (regexp
, &opend
);
2800 int fix
= -1; /* -1 means ok; otherwise number of spaces needed. */
2801 if (isalpha(*opname
) || *opname
== '_' || *opname
== '$')
2803 /* There should 1 space between 'operator' and 'TYPENAME'. */
2804 if (opname
[-1] != ' ' || opname
[-2] == ' ')
2809 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2810 if (opname
[-1] == ' ')
2813 /* If wrong number of spaces, fix it. */
2816 char *tmp
= (char*) alloca(opend
-opname
+10);
2817 sprintf(tmp
, "operator%.*s%s", fix
, " ", opname
);
2822 if (0 != (val
= re_comp (regexp
)))
2823 error ("Invalid regexp (%s): %s", val
, regexp
);
2826 /* Search through the partial symtabs *first* for all symbols
2827 matching the regexp. That way we don't have to reproduce all of
2828 the machinery below. */
2830 ALL_PSYMTABS (objfile
, ps
)
2832 struct partial_symbol
**bound
, **gbound
, **sbound
;
2835 if (ps
->readin
) continue;
2837 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2838 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2841 /* Go through all of the symbols stored in a partial
2842 symtab in one loop. */
2843 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2848 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2850 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2861 /* If it would match (logic taken from loop below)
2862 load the file and go on to the next one */
2863 if ((regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (*psym
))
2864 && ((class == 0 && SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
2865 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
2866 || (class == 1 && SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
2867 || (class == 2 && SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
)
2868 || (class == 3 && SYMBOL_CLASS (*psym
) == LOC_BLOCK
)))
2870 PSYMTAB_TO_SYMTAB(ps
);
2878 /* Here, we search through the minimal symbol tables for functions
2879 and variables that match, and force their symbols to be read.
2880 This is in particular necessary for demangled variable names,
2881 which are no longer put into the partial symbol tables.
2882 The symbol will then be found during the scan of symtabs below.
2884 For functions, find_pc_symtab should succeed if we have debug info
2885 for the function, for variables we have to call lookup_symbol
2886 to determine if the variable has debug info.
2887 If the lookup fails, set found_misc so that we will rescan to print
2888 any matching symbols without debug info.
2891 if (class == 0 || class == 1)
2893 ALL_MSYMBOLS (objfile
, msymbol
)
2895 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
2896 MSYMBOL_TYPE (msymbol
) == ourtype2
||
2897 MSYMBOL_TYPE (msymbol
) == ourtype3
||
2898 MSYMBOL_TYPE (msymbol
) == ourtype4
)
2900 if (regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (msymbol
))
2902 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
)))
2905 || lookup_symbol (SYMBOL_NAME (msymbol
),
2906 (struct block
*) NULL
,
2908 0, (struct symtab
**) NULL
) == NULL
)
2916 /* Printout here so as to get after the "Reading in symbols"
2917 messages which will be generated above. */
2919 printf_filtered (regexp
2920 ? "All %ss matching regular expression \"%s\":\n"
2921 : "All defined %ss:\n",
2925 ALL_SYMTABS (objfile
, s
)
2928 bv
= BLOCKVECTOR (s
);
2929 /* Often many files share a blockvector.
2930 Scan each blockvector only once so that
2931 we don't get every symbol many times.
2932 It happens that the first symtab in the list
2933 for any given blockvector is the main file. */
2935 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
2937 b
= BLOCKVECTOR_BLOCK (bv
, i
);
2938 /* Skip the sort if this block is always sorted. */
2939 if (!BLOCK_SHOULD_SORT (b
))
2940 sort_block_syms (b
);
2941 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
2944 sym
= BLOCK_SYM (b
, j
);
2945 if ((regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (sym
))
2946 && ((class == 0 && SYMBOL_CLASS (sym
) != LOC_TYPEDEF
2947 && SYMBOL_CLASS (sym
) != LOC_BLOCK
2948 && SYMBOL_CLASS (sym
) != LOC_CONST
)
2949 || (class == 1 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2950 || (class == 2 && SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2951 || (class == 3 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)))
2955 /* Set a breakpoint here, if it's a function */
2958 /* There may be more than one function with the
2959 same name but in different files. In order to
2960 set breakpoints on all of them, we must give
2961 both the file name and the function name to
2963 Quoting the symbol name gets rid of problems
2964 with mangled symbol names that contain
2965 CPLUS_MARKER characters. */
2967 (char *) alloca (strlen (s
->filename
)
2968 + strlen (SYMBOL_NAME(sym
))
2970 strcpy (string
, s
->filename
);
2971 strcat (string
, ":'");
2972 strcat (string
, SYMBOL_NAME(sym
));
2973 strcat (string
, "'");
2974 break_command (string
, from_tty
);
2977 else if (!found_in_file
)
2979 fputs_filtered ("\nFile ", gdb_stdout
);
2980 fputs_filtered (s
->filename
, gdb_stdout
);
2981 fputs_filtered (":\n", gdb_stdout
);
2985 if (class != 2 && i
== STATIC_BLOCK
)
2986 printf_filtered ("static ");
2988 /* Typedef that is not a C++ class */
2990 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
2991 c_typedef_print (SYMBOL_TYPE(sym
), sym
, gdb_stdout
);
2992 /* variable, func, or typedef-that-is-c++-class */
2993 else if (class < 2 ||
2995 SYMBOL_NAMESPACE(sym
) == STRUCT_NAMESPACE
))
2997 type_print (SYMBOL_TYPE (sym
),
2998 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2999 ? "" : SYMBOL_SOURCE_NAME (sym
)),
3002 printf_filtered (";\n");
3007 /* Tiemann says: "info methods was never implemented." */
3008 char *demangled_name
;
3009 c_type_print_base (TYPE_FN_FIELD_TYPE(t
, i
),
3011 c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t
, i
),
3013 if (TYPE_FN_FIELD_STUB (t
, i
))
3014 check_stub_method (TYPE_DOMAIN_TYPE (type
), j
, i
);
3016 cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t
, i
),
3017 DMGL_ANSI
| DMGL_PARAMS
);
3018 if (demangled_name
== NULL
)
3019 fprintf_filtered (stream
, "<badly mangled name %s>",
3020 TYPE_FN_FIELD_PHYSNAME (t
, i
));
3023 fputs_filtered (demangled_name
, stream
);
3024 free (demangled_name
);
3034 /* If there are no eyes, avoid all contact. I mean, if there are
3035 no debug symbols, then print directly from the msymbol_vector. */
3037 if (found_misc
|| class != 1)
3040 ALL_MSYMBOLS (objfile
, msymbol
)
3042 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
3043 MSYMBOL_TYPE (msymbol
) == ourtype2
||
3044 MSYMBOL_TYPE (msymbol
) == ourtype3
||
3045 MSYMBOL_TYPE (msymbol
) == ourtype4
)
3047 if (regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (msymbol
))
3049 /* Functions: Look up by address. */
3051 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
))))
3053 /* Variables/Absolutes: Look up by name */
3054 if (lookup_symbol (SYMBOL_NAME (msymbol
),
3055 (struct block
*) NULL
, VAR_NAMESPACE
,
3056 0, (struct symtab
**) NULL
) == NULL
)
3060 break_command (SYMBOL_NAME (msymbol
), from_tty
);
3061 printf_filtered ("<function, no debug info> %s;\n",
3062 SYMBOL_SOURCE_NAME (msymbol
));
3067 printf_filtered ("\nNon-debugging symbols:\n");
3070 printf_filtered (" %08lx %s\n",
3071 (unsigned long) SYMBOL_VALUE_ADDRESS (msymbol
),
3072 SYMBOL_SOURCE_NAME (msymbol
));
3082 variables_info (regexp
, from_tty
)
3086 list_symbols (regexp
, 0, 0, from_tty
);
3090 functions_info (regexp
, from_tty
)
3094 list_symbols (regexp
, 1, 0, from_tty
);
3098 types_info (regexp
, from_tty
)
3102 list_symbols (regexp
, 2, 0, from_tty
);
3106 /* Tiemann says: "info methods was never implemented." */
3108 methods_info (regexp
)
3111 list_symbols (regexp
, 3, 0, from_tty
);
3115 /* Breakpoint all functions matching regular expression. */
3117 rbreak_command (regexp
, from_tty
)
3121 list_symbols (regexp
, 1, 1, from_tty
);
3125 /* Return Nonzero if block a is lexically nested within block b,
3126 or if a and b have the same pc range.
3127 Return zero otherwise. */
3130 struct block
*a
, *b
;
3134 return BLOCK_START (a
) >= BLOCK_START (b
)
3135 && BLOCK_END (a
) <= BLOCK_END (b
);
3139 /* Helper routine for make_symbol_completion_list. */
3141 static int return_val_size
;
3142 static int return_val_index
;
3143 static char **return_val
;
3145 #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
3147 if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \
3148 /* Put only the mangled name on the list. */ \
3149 /* Advantage: "b foo<TAB>" completes to "b foo(int, int)" */ \
3150 /* Disadvantage: "b foo__i<TAB>" doesn't complete. */ \
3151 completion_list_add_name \
3152 (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \
3154 completion_list_add_name \
3155 (SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \
3158 /* Test to see if the symbol specified by SYMNAME (which is already
3159 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3160 characters. If so, add it to the current completion list. */
3163 completion_list_add_name (symname
, sym_text
, sym_text_len
, text
, word
)
3173 /* clip symbols that cannot match */
3175 if (strncmp (symname
, sym_text
, sym_text_len
) != 0)
3180 /* Clip any symbol names that we've already considered. (This is a
3181 time optimization) */
3183 for (i
= 0; i
< return_val_index
; ++i
)
3185 if (STREQ (symname
, return_val
[i
]))
3191 /* We have a match for a completion, so add SYMNAME to the current list
3192 of matches. Note that the name is moved to freshly malloc'd space. */
3196 if (word
== sym_text
)
3198 new = xmalloc (strlen (symname
) + 5);
3199 strcpy (new, symname
);
3201 else if (word
> sym_text
)
3203 /* Return some portion of symname. */
3204 new = xmalloc (strlen (symname
) + 5);
3205 strcpy (new, symname
+ (word
- sym_text
));
3209 /* Return some of SYM_TEXT plus symname. */
3210 new = xmalloc (strlen (symname
) + (sym_text
- word
) + 5);
3211 strncpy (new, word
, sym_text
- word
);
3212 new[sym_text
- word
] = '\0';
3213 strcat (new, symname
);
3216 /* Recheck for duplicates if we intend to add a modified symbol. */
3217 if (word
!= sym_text
)
3219 for (i
= 0; i
< return_val_index
; ++i
)
3221 if (STREQ (new, return_val
[i
]))
3229 if (return_val_index
+ 3 > return_val_size
)
3231 newsize
= (return_val_size
*= 2) * sizeof (char *);
3232 return_val
= (char **) xrealloc ((char *) return_val
, newsize
);
3234 return_val
[return_val_index
++] = new;
3235 return_val
[return_val_index
] = NULL
;
3239 /* Return a NULL terminated array of all symbols (regardless of class) which
3240 begin by matching TEXT. If the answer is no symbols, then the return value
3241 is an array which contains only a NULL pointer.
3243 Problem: All of the symbols have to be copied because readline frees them.
3244 I'm not going to worry about this; hopefully there won't be that many. */
3247 make_symbol_completion_list (text
, word
)
3251 register struct symbol
*sym
;
3252 register struct symtab
*s
;
3253 register struct partial_symtab
*ps
;
3254 register struct minimal_symbol
*msymbol
;
3255 register struct objfile
*objfile
;
3256 register struct block
*b
, *surrounding_static_block
= 0;
3258 struct partial_symbol
**psym
;
3259 /* The symbol we are completing on. Points in same buffer as text. */
3261 /* Length of sym_text. */
3264 /* Now look for the symbol we are supposed to complete on.
3265 FIXME: This should be language-specific. */
3269 char *quote_pos
= NULL
;
3271 /* First see if this is a quoted string. */
3273 for (p
= text
; *p
!= '\0'; ++p
)
3275 if (quote_found
!= '\0')
3277 if (*p
== quote_found
)
3278 /* Found close quote. */
3280 else if (*p
== '\\' && p
[1] == quote_found
)
3281 /* A backslash followed by the quote character
3282 doesn't end the string. */
3285 else if (*p
== '\'' || *p
== '"')
3291 if (quote_found
== '\'')
3292 /* A string within single quotes can be a symbol, so complete on it. */
3293 sym_text
= quote_pos
+ 1;
3294 else if (quote_found
== '"')
3295 /* A double-quoted string is never a symbol, nor does it make sense
3296 to complete it any other way. */
3300 /* It is not a quoted string. Break it based on the characters
3301 which are in symbols. */
3304 if (isalnum (p
[-1]) || p
[-1] == '_' || p
[-1] == '\0')
3313 sym_text_len
= strlen (sym_text
);
3315 return_val_size
= 100;
3316 return_val_index
= 0;
3317 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
3318 return_val
[0] = NULL
;
3320 /* Look through the partial symtabs for all symbols which begin
3321 by matching SYM_TEXT. Add each one that you find to the list. */
3323 ALL_PSYMTABS (objfile
, ps
)
3325 /* If the psymtab's been read in we'll get it when we search
3326 through the blockvector. */
3327 if (ps
->readin
) continue;
3329 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
3330 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
3331 + ps
->n_global_syms
);
3334 /* If interrupted, then quit. */
3336 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3339 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
3340 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
3341 + ps
->n_static_syms
);
3345 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3349 /* At this point scan through the misc symbol vectors and add each
3350 symbol you find to the list. Eventually we want to ignore
3351 anything that isn't a text symbol (everything else will be
3352 handled by the psymtab code above). */
3354 ALL_MSYMBOLS (objfile
, msymbol
)
3357 COMPLETION_LIST_ADD_SYMBOL (msymbol
, sym_text
, sym_text_len
, text
, word
);
3360 /* Search upwards from currently selected frame (so that we can
3361 complete on local vars. */
3363 for (b
= get_selected_block (); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
3365 if (!BLOCK_SUPERBLOCK (b
))
3367 surrounding_static_block
= b
; /* For elmin of dups */
3370 /* Also catch fields of types defined in this places which match our
3371 text string. Only complete on types visible from current context. */
3373 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3375 sym
= BLOCK_SYM (b
, i
);
3376 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3377 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3379 struct type
*t
= SYMBOL_TYPE (sym
);
3380 enum type_code c
= TYPE_CODE (t
);
3382 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
3384 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
3386 if (TYPE_FIELD_NAME (t
, j
))
3388 completion_list_add_name (TYPE_FIELD_NAME (t
, j
),
3389 sym_text
, sym_text_len
, text
, word
);
3397 /* Go through the symtabs and check the externs and statics for
3398 symbols which match. */
3400 ALL_SYMTABS (objfile
, s
)
3403 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3404 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3406 sym
= BLOCK_SYM (b
, i
);
3407 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3411 ALL_SYMTABS (objfile
, s
)
3414 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3415 /* Don't do this block twice. */
3416 if (b
== surrounding_static_block
) continue;
3417 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3419 sym
= BLOCK_SYM (b
, i
);
3420 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3424 return (return_val
);
3427 /* Determine if PC is in the prologue of a function. The prologue is the area
3428 between the first instruction of a function, and the first executable line.
3429 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
3431 If non-zero, func_start is where we think the prologue starts, possibly
3432 by previous examination of symbol table information.
3436 in_prologue (pc
, func_start
)
3438 CORE_ADDR func_start
;
3440 struct symtab_and_line sal
;
3441 CORE_ADDR func_addr
, func_end
;
3443 if (!find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
3444 goto nosyms
; /* Might be in prologue */
3446 sal
= find_pc_line (func_addr
, 0);
3451 if (sal
.end
> func_addr
3452 && sal
.end
<= func_end
) /* Is prologue in function? */
3453 return pc
< sal
.end
; /* Yes, is pc in prologue? */
3455 /* The line after the prologue seems to be outside the function. In this
3456 case, tell the caller to find the prologue the hard way. */
3460 /* Come here when symtabs don't contain line # info. In this case, it is
3461 likely that the user has stepped into a library function w/o symbols, or
3462 is doing a stepi/nexti through code without symbols. */
3466 /* If func_start is zero (meaning unknown) then we don't know whether pc is
3467 in the prologue or not. I.E. it might be. */
3469 if (!func_start
) return 1;
3471 /* We need to call the target-specific prologue skipping functions with the
3472 function's start address because PC may be pointing at an instruction that
3473 could be mistakenly considered part of the prologue. */
3475 SKIP_PROLOGUE (func_start
);
3477 return pc
< func_start
;
3482 _initialize_symtab ()
3484 add_info ("variables", variables_info
,
3485 "All global and static variable names, or those matching REGEXP.");
3486 add_info ("functions", functions_info
,
3487 "All function names, or those matching REGEXP.");
3489 /* FIXME: This command has at least the following problems:
3490 1. It prints builtin types (in a very strange and confusing fashion).
3491 2. It doesn't print right, e.g. with
3492 typedef struct foo *FOO
3493 type_print prints "FOO" when we want to make it (in this situation)
3494 print "struct foo *".
3495 I also think "ptype" or "whatis" is more likely to be useful (but if
3496 there is much disagreement "info types" can be fixed). */
3497 add_info ("types", types_info
,
3498 "All type names, or those matching REGEXP.");
3501 add_info ("methods", methods_info
,
3502 "All method names, or those matching REGEXP::REGEXP.\n\
3503 If the class qualifier is omitted, it is assumed to be the current scope.\n\
3504 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
3507 add_info ("sources", sources_info
,
3508 "Source files in the program.");
3510 add_com ("rbreak", no_class
, rbreak_command
,
3511 "Set a breakpoint for all functions matching REGEXP.");
3513 /* Initialize the one built-in type that isn't language dependent... */
3514 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
3515 "<unknown type>", (struct objfile
*) NULL
);