1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
31 #include "call-cmds.h"
33 #include "expression.h"
40 #include <sys/types.h>
46 /* Prototypes for local functions */
49 expensive_mangler
PARAMS ((const char *));
52 find_methods
PARAMS ((struct type
*, char *, char **, struct symbol
**));
55 completion_list_add_symbol
PARAMS ((char *, char *, int));
57 static struct symtabs_and_lines
58 decode_line_2
PARAMS ((struct symbol
*[], int, int));
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));
79 output_source_filename
PARAMS ((char *, int *));
82 operator_chars
PARAMS ((char *, char **));
85 find_line_common
PARAMS ((struct linetable
*, int, int *));
87 static struct partial_symbol
*
88 lookup_partial_symbol
PARAMS ((struct partial_symtab
*, const char *,
89 int, enum namespace));
91 static struct partial_symbol
*
92 lookup_demangled_partial_symbol
PARAMS ((const struct partial_symtab
*,
95 static struct symbol
*
96 lookup_demangled_block_symbol
PARAMS ((const struct block
*, const char *));
98 static struct symtab
*
99 lookup_symtab_1
PARAMS ((char *));
103 /* The single non-language-specific builtin type */
104 struct type
*builtin_type_error
;
106 /* Block in which the most recently searched-for symbol was found.
107 Might be better to make this a parameter to lookup_symbol and
110 const struct block
*block_found
;
112 char no_symtab_msg
[] = "No symbol table is loaded. Use the \"file\" command.";
114 /* While the C++ support is still in flux, issue a possibly helpful hint on
115 using the new command completion feature on single quoted demangled C++
116 symbols. Remove when loose ends are cleaned up. FIXME -fnf */
119 cplusplus_hint (name
)
122 printf ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name
, name
);
123 printf ("(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 (strcmp (name
, s
->filename
) == 0)
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
, '/');
160 if (strcmp (p
, name
) == 0)
164 /* Same search rules as above apply here, but now we look thru the
167 ALL_PSYMTABS (objfile
, ps
)
168 if (strcmp (name
, ps
-> filename
) == 0)
172 ALL_PSYMTABS (objfile
, ps
)
174 char *p
= ps
-> filename
;
175 char *tail
= strrchr (p
, '/');
180 if (strcmp (p
, name
) == 0)
189 error ("Internal: readin %s pst for `%s' found when no symtab found.",
190 ps
-> filename
, name
);
192 s
= PSYMTAB_TO_SYMTAB (ps
);
197 /* At this point, we have located the psymtab for this file, but
198 the conversion to a symtab has failed. This usually happens
199 when we are looking up an include file. In this case,
200 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
201 been created. So, we need to run through the symtabs again in
202 order to find the file.
203 XXX - This is a crock, and should be fixed inside of the the
204 symbol parsing routines. */
208 /* Lookup the symbol table of a source file named NAME. Try a couple
209 of variations if the first lookup doesn't work. */
215 register struct symtab
*s
;
218 s
= lookup_symtab_1 (name
);
221 /* If name not found as specified, see if adding ".c" helps. */
223 copy
= (char *) alloca (strlen (name
) + 3);
226 s
= lookup_symtab_1 (copy
);
229 /* We didn't find anything; die. */
233 /* Lookup the partial symbol table of a source file named NAME. This
234 only returns true on an exact match (ie. this semantics are
235 different from lookup_symtab. */
237 struct partial_symtab
*
238 lookup_partial_symtab (name
)
241 register struct partial_symtab
*pst
;
242 register struct objfile
*objfile
;
244 ALL_PSYMTABS (objfile
, pst
)
246 if (strcmp (name
, pst
-> filename
) == 0)
254 /* Demangle a GDB method stub type. */
256 gdb_mangle_name (type
, i
, j
)
260 int mangled_name_len
;
262 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
263 struct fn_field
*method
= &f
[j
];
264 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
265 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, j
);
266 char *newname
= type_name_no_tag (type
);
267 int is_constructor
= strcmp(field_name
, newname
) == 0;
268 int is_destructor
= is_constructor
&& physname
[0] == '_'
269 && physname
[1] == CPLUS_MARKER
&& physname
[2] == '_';
270 /* Need a new type prefix. */
271 char *const_prefix
= method
->is_const
? "C" : "";
272 char *volatile_prefix
= method
->is_volatile
? "V" : "";
274 #ifndef GCC_MANGLE_BUG
275 int len
= strlen (newname
);
279 mangled_name
= (char*) xmalloc(strlen(physname
)+1);
280 strcpy(mangled_name
, physname
);
284 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
285 mangled_name_len
= ((is_constructor
? 0 : strlen (field_name
))
290 /* Only needed for GNU-mangled names. ANSI-mangled names
291 work with the normal mechanisms. */
292 if (OPNAME_PREFIX_P (field_name
))
294 char *opname
= cplus_mangle_opname (field_name
+ 3, 0);
296 error ("No mangling for \"%s\"", field_name
);
297 mangled_name_len
+= strlen (opname
);
298 mangled_name
= (char *)xmalloc (mangled_name_len
);
300 strncpy (mangled_name
, field_name
, 3);
301 mangled_name
[3] = '\0';
302 strcat (mangled_name
, opname
);
306 mangled_name
= (char *)xmalloc (mangled_name_len
);
308 mangled_name
[0] = '\0';
310 strcpy (mangled_name
, field_name
);
312 strcat (mangled_name
, buf
);
313 strcat (mangled_name
, newname
);
323 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
326 mangled_name_len
= ((is_constructor
? 0 : strlen (field_name
))
327 + strlen (buf
) + strlen (physname
) + 1);
329 /* Only needed for GNU-mangled names. ANSI-mangled names
330 work with the normal mechanisms. */
331 if (OPNAME_PREFIX_P (field_name
))
333 opname
= cplus_mangle_opname (field_name
+ 3, 0);
336 error ("No mangling for \"%s\"", field_name
);
338 mangled_name_len
+= strlen (opname
);
339 mangled_name
= (char *) xmalloc (mangled_name_len
);
341 strncpy (mangled_name
, field_name
, 3);
342 strcpy (mangled_name
+ 3, opname
);
346 mangled_name
= (char *) xmalloc (mangled_name_len
);
349 mangled_name
[0] = '\0';
353 strcpy (mangled_name
, field_name
);
356 strcat (mangled_name
, buf
);
359 strcat (mangled_name
, physname
);
360 return (mangled_name
);
364 /* Find which partial symtab on contains PC. Return 0 if none. */
366 struct partial_symtab
*
368 register CORE_ADDR pc
;
370 register struct partial_symtab
*pst
;
371 register struct objfile
*objfile
;
373 ALL_PSYMTABS (objfile
, pst
)
375 if (pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
381 /* Find which partial symbol within a psymtab contains PC. Return 0
382 if none. Check all psymtabs if PSYMTAB is 0. */
383 struct partial_symbol
*
384 find_pc_psymbol (psymtab
, pc
)
385 struct partial_symtab
*psymtab
;
388 struct partial_symbol
*best
, *p
;
392 psymtab
= find_pc_psymtab (pc
);
396 best_pc
= psymtab
->textlow
- 1;
398 for (p
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
399 (p
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
400 < psymtab
->n_static_syms
);
402 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
403 && SYMBOL_CLASS (p
) == LOC_BLOCK
404 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
405 && SYMBOL_VALUE_ADDRESS (p
) > best_pc
)
407 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
410 if (best_pc
== psymtab
->textlow
- 1)
416 /* Find the definition for a specified symbol name NAME
417 in namespace NAMESPACE, visible from lexical block BLOCK.
418 Returns the struct symbol pointer, or zero if no symbol is found.
419 If SYMTAB is non-NULL, store the symbol table in which the
420 symbol was found there, or NULL if not found.
421 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
422 NAME is a field of the current implied argument `this'. If so set
423 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
424 BLOCK_FOUND is set to the block in which NAME is found (in the case of
425 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
428 lookup_symbol (name
, block
, namespace, is_a_field_of_this
, symtab
)
430 register const struct block
*block
;
431 const enum namespace namespace;
432 int *is_a_field_of_this
;
433 struct symtab
**symtab
;
435 register struct symbol
*sym
;
436 register struct symtab
*s
;
437 register struct partial_symtab
*ps
;
438 struct blockvector
*bv
;
439 register struct objfile
*objfile
;
440 register struct block
*b
;
441 register struct minimal_symbol
*msymbol
;
443 extern char *gdb_completer_word_break_characters
;
445 /* If NAME contains any characters from gdb_completer_word_break_characters
446 then it is probably from a quoted name string. So check to see if it
447 has a C++ mangled equivalent, and if so, use the mangled equivalent. */
449 if (strpbrk (name
, gdb_completer_word_break_characters
) != NULL
)
451 if ((temp
= expensive_mangler (name
)) != NULL
)
457 /* Search specified block and its superiors. */
461 sym
= lookup_block_symbol (block
, name
, namespace);
467 /* Search the list of symtabs for one which contains the
468 address of the start of this block. */
469 ALL_SYMTABS (objfile
, s
)
471 bv
= BLOCKVECTOR (s
);
472 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
473 if (BLOCK_START (b
) <= BLOCK_START (block
)
474 && BLOCK_END (b
) > BLOCK_START (block
))
483 block
= BLOCK_SUPERBLOCK (block
);
486 /* But that doesn't do any demangling for the STATIC_BLOCK.
487 I'm not sure whether demangling is needed in the case of
488 nested function in inner blocks; if so this needs to be changed.
490 Don't need to mess with the psymtabs; if we have a block,
491 that file is read in. If we don't, then we deal later with
492 all the psymtab stuff that needs checking. */
493 if (namespace == VAR_NAMESPACE
&& block
!= NULL
)
496 /* Find the right symtab. */
497 ALL_SYMTABS (objfile
, s
)
499 bv
= BLOCKVECTOR (s
);
500 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
501 if (BLOCK_START (b
) <= BLOCK_START (block
)
502 && BLOCK_END (b
) > BLOCK_START (block
))
504 sym
= lookup_demangled_block_symbol (b
, name
);
517 /* C++: If requested to do so by the caller,
518 check to see if NAME is a field of `this'. */
519 if (is_a_field_of_this
)
521 struct value
*v
= value_of_this (0);
523 *is_a_field_of_this
= 0;
524 if (v
&& check_field (v
, name
))
526 *is_a_field_of_this
= 1;
533 /* Now search all global blocks. Do the symtab's first, then
534 check the psymtab's */
536 ALL_SYMTABS (objfile
, s
)
538 bv
= BLOCKVECTOR (s
);
539 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
540 sym
= lookup_block_symbol (block
, name
, namespace);
550 /* Check for the possibility of the symbol being a global function
551 that is stored in one of the minimal symbol tables. Eventually, all
552 global symbols might be resolved in this way. */
554 if (namespace == VAR_NAMESPACE
)
556 msymbol
= lookup_minimal_symbol (name
, (struct objfile
*) NULL
);
560 /* Test each minimal symbol to see if the minimal symbol's name
561 is a C++ mangled name that matches a user visible name. */
565 ALL_MSYMBOLS (objfile
, msymbol
)
567 demangled
= demangle_and_match (msymbol
-> name
, name
,
568 DMGL_PARAMS
| DMGL_ANSI
);
569 if (demangled
!= NULL
)
575 msymbol
= NULL
; /* Not found */
581 s
= find_pc_symtab (msymbol
-> address
);
582 /* If S is NULL, there are no debug symbols for this file.
583 Skip this stuff and check for matching static symbols below. */
586 bv
= BLOCKVECTOR (s
);
587 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
588 sym
= lookup_block_symbol (block
, msymbol
-> name
, namespace);
589 /* We kept static functions in minimal symbol table as well as
590 in static scope. We want to find them in the symbol table. */
592 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
593 sym
= lookup_block_symbol (block
, msymbol
-> name
,
597 /* sym == 0 if symbol was found in the minimal symbol table
598 but not in the symtab.
599 Return 0 to use the msymbol definition of "foo_".
601 This happens for Fortran "foo_" symbols,
602 which are "foo" in the symtab.
604 This can also happen if "asm" is used to make a
605 regular symbol but not a debugging symbol, e.g.
617 ALL_PSYMTABS (objfile
, ps
)
619 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
621 s
= PSYMTAB_TO_SYMTAB(ps
);
622 bv
= BLOCKVECTOR (s
);
623 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
624 sym
= lookup_block_symbol (block
, name
, namespace);
626 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab", name
, ps
->filename
);
633 /* Now search all per-file blocks.
634 Not strictly correct, but more useful than an error.
635 Do the symtabs first, then check the psymtabs */
637 ALL_SYMTABS (objfile
, s
)
639 bv
= BLOCKVECTOR (s
);
640 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
641 sym
= lookup_block_symbol (block
, name
, namespace);
651 ALL_PSYMTABS (objfile
, ps
)
653 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
655 s
= PSYMTAB_TO_SYMTAB(ps
);
656 bv
= BLOCKVECTOR (s
);
657 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
658 sym
= lookup_block_symbol (block
, name
, namespace);
660 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab", name
, ps
->filename
);
667 /* Now search all per-file blocks for static mangled symbols.
668 Do the symtabs first, then check the psymtabs. */
670 if (namespace == VAR_NAMESPACE
)
672 ALL_SYMTABS (objfile
, s
)
674 bv
= BLOCKVECTOR (s
);
675 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
676 sym
= lookup_demangled_block_symbol (block
, name
);
686 ALL_PSYMTABS (objfile
, ps
)
688 if (!ps
->readin
&& lookup_demangled_partial_symbol (ps
, name
))
690 s
= PSYMTAB_TO_SYMTAB(ps
);
691 bv
= BLOCKVECTOR (s
);
692 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
693 sym
= lookup_demangled_block_symbol (block
, name
);
695 error ("Internal: mangled static symbol `%s' found in %s psymtab but not in symtab", name
, ps
->filename
);
708 /* Look for a static demangled symbol in block BLOCK. */
710 static struct symbol
*
711 lookup_demangled_block_symbol (block
, name
)
712 register const struct block
*block
;
715 register int bot
, top
;
716 register struct symbol
*sym
;
720 top
= BLOCK_NSYMS (block
);
724 sym
= BLOCK_SYM (block
, bot
);
725 if (SYMBOL_NAMESPACE (sym
) == VAR_NAMESPACE
)
727 demangled
= demangle_and_match (SYMBOL_NAME (sym
), name
,
728 DMGL_PARAMS
| DMGL_ANSI
);
729 if (demangled
!= NULL
)
741 /* Look, in partial_symtab PST, for static mangled symbol NAME. */
743 static struct partial_symbol
*
744 lookup_demangled_partial_symbol (pst
, name
)
745 const struct partial_symtab
*pst
;
748 struct partial_symbol
*start
, *psym
;
749 int length
= pst
->n_static_syms
;
753 return (struct partial_symbol
*) 0;
755 start
= pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
;
756 for (psym
= start
; psym
< start
+ length
; psym
++)
758 if (SYMBOL_NAMESPACE (psym
) == VAR_NAMESPACE
)
760 demangled
= demangle_and_match (SYMBOL_NAME (psym
), name
,
761 DMGL_PARAMS
| DMGL_ANSI
);
762 if (demangled
!= NULL
)
773 /* Look, in partial_symtab PST, for symbol NAME. Check the global
774 symbols if GLOBAL, the static symbols if not */
776 static struct partial_symbol
*
777 lookup_partial_symbol (pst
, name
, global
, namespace)
778 struct partial_symtab
*pst
;
781 enum namespace namespace;
783 struct partial_symbol
*start
, *psym
;
784 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
787 return (struct partial_symbol
*) 0;
790 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
791 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
793 if (global
) /* This means we can use a binary */
796 struct partial_symbol
*top
, *bottom
, *center
;
798 /* Binary search. This search is guaranteed to end with center
799 pointing at the earliest partial symbol with the correct
800 name. At that point *all* partial symbols with that name
801 will be checked against the correct namespace. */
803 top
= start
+ length
- 1;
806 center
= bottom
+ (top
- bottom
) / 2;
808 assert (center
< top
);
810 if (strcmp (SYMBOL_NAME (center
), name
) >= 0)
815 assert (top
== bottom
);
817 while (!strcmp (SYMBOL_NAME (top
), name
))
819 if (SYMBOL_NAMESPACE (top
) == namespace)
826 /* Can't use a binary search */
827 for (psym
= start
; psym
< start
+ length
; psym
++)
828 if (namespace == SYMBOL_NAMESPACE (psym
)
829 && !strcmp (name
, SYMBOL_NAME (psym
)))
833 return (struct partial_symbol
*) 0;
836 /* Find the psymtab containing main(). */
837 /* FIXME: What about languages without main() or specially linked
838 executables that have no main() ? */
840 struct partial_symtab
*
843 register struct partial_symtab
*pst
;
844 register struct objfile
*objfile
;
846 ALL_PSYMTABS (objfile
, pst
)
848 if (lookup_partial_symbol (pst
, "main", 1, VAR_NAMESPACE
))
856 /* Look for a symbol in block BLOCK. */
859 lookup_block_symbol (block
, name
, namespace)
860 register const struct block
*block
;
862 const enum namespace namespace;
864 register int bot
, top
, inc
;
865 register struct symbol
*sym
, *parameter_sym
;
867 top
= BLOCK_NSYMS (block
);
870 /* If the blocks's symbols were sorted, start with a binary search. */
872 if (BLOCK_SHOULD_SORT (block
))
874 /* First, advance BOT to not far before
875 the first symbol whose name is NAME. */
879 inc
= (top
- bot
+ 1);
880 /* No need to keep binary searching for the last few bits worth. */
883 inc
= (inc
>> 1) + bot
;
884 sym
= BLOCK_SYM (block
, inc
);
885 if (SYMBOL_NAME (sym
)[0] < name
[0])
887 else if (SYMBOL_NAME (sym
)[0] > name
[0])
889 else if (strcmp (SYMBOL_NAME (sym
), name
) < 0)
895 /* Now scan forward until we run out of symbols,
896 find one whose name is greater than NAME,
898 If there is more than one symbol with the right name and namespace,
899 we return the first one. dbxread.c is careful to make sure
900 that if one is a register then it comes first. */
902 top
= BLOCK_NSYMS (block
);
905 sym
= BLOCK_SYM (block
, bot
);
906 inc
= SYMBOL_NAME (sym
)[0] - name
[0];
908 inc
= strcmp (SYMBOL_NAME (sym
), name
);
909 if (inc
== 0 && SYMBOL_NAMESPACE (sym
) == namespace)
918 /* Here if block isn't sorted.
919 This loop is equivalent to the loop above,
920 but hacked greatly for speed.
922 Note that parameter symbols do not always show up last in the
923 list; this loop makes sure to take anything else other than
924 parameter symbols first; it only uses parameter symbols as a
925 last resort. Note that this only takes up extra computation
928 parameter_sym
= (struct symbol
*) 0;
929 top
= BLOCK_NSYMS (block
);
933 sym
= BLOCK_SYM (block
, bot
);
934 if (SYMBOL_NAME (sym
)[0] == inc
935 && !strcmp (SYMBOL_NAME (sym
), name
)
936 && SYMBOL_NAMESPACE (sym
) == namespace)
938 if (SYMBOL_CLASS (sym
) == LOC_ARG
939 || SYMBOL_CLASS (sym
) == LOC_LOCAL_ARG
940 || SYMBOL_CLASS (sym
) == LOC_REF_ARG
941 || SYMBOL_CLASS (sym
) == LOC_REGPARM
)
948 return parameter_sym
; /* Will be 0 if not found. */
951 /* Return the symbol for the function which contains a specified
952 lexical block, described by a struct block BL. */
958 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
959 bl
= BLOCK_SUPERBLOCK (bl
);
961 return BLOCK_FUNCTION (bl
);
964 /* Find the symtab associated with PC. Look through the psymtabs and read in
965 another symtab if necessary. */
969 register CORE_ADDR pc
;
971 register struct block
*b
;
972 struct blockvector
*bv
;
973 register struct symtab
*s
= NULL
;
974 register struct partial_symtab
*ps
;
975 register struct objfile
*objfile
;
977 /* Search all symtabs for one whose file contains our pc */
979 ALL_SYMTABS (objfile
, s
)
981 bv
= BLOCKVECTOR (s
);
982 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
983 if (BLOCK_START (b
) <= pc
984 && BLOCK_END (b
) > pc
)
989 ps
= find_pc_psymtab (pc
);
993 printf_filtered ("(Internal error: pc 0x%x in read in psymtab, but not in symtab.)\n", pc
);
994 s
= PSYMTAB_TO_SYMTAB (ps
);
999 /* Find the source file and line number for a given PC value.
1000 Return a structure containing a symtab pointer, a line number,
1001 and a pc range for the entire source line.
1002 The value's .pc field is NOT the specified pc.
1003 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1004 use the line that ends there. Otherwise, in that case, the line
1005 that begins there is used. */
1007 /* The big complication here is that a line may start in one file, and end just
1008 before the start of another file. This usually occurs when you #include
1009 code in the middle of a subroutine. To properly find the end of a line's PC
1010 range, we must search all symtabs associated with this compilation unit, and
1011 find the one whose first PC is closer than that of the next line in this
1015 struct symtab_and_line
1016 find_pc_line (pc
, notcurrent
)
1021 register struct linetable
*l
;
1024 register struct linetable_entry
*item
;
1025 struct symtab_and_line val
;
1026 struct blockvector
*bv
;
1028 /* Info on best line seen so far, and where it starts, and its file. */
1030 struct linetable_entry
*best
= NULL
;
1031 CORE_ADDR best_end
= 0;
1032 struct symtab
*best_symtab
= 0;
1034 /* Store here the first line number
1035 of a file which contains the line at the smallest pc after PC.
1036 If we don't find a line whose range contains PC,
1037 we will use a line one less than this,
1038 with a range from the start of that file to the first line's pc. */
1039 struct linetable_entry
*alt
= NULL
;
1040 struct symtab
*alt_symtab
= 0;
1042 /* Info on best line seen in this file. */
1044 struct linetable_entry
*prev
;
1046 /* If this pc is not from the current frame,
1047 it is the address of the end of a call instruction.
1048 Quite likely that is the start of the following statement.
1049 But what we want is the statement containing the instruction.
1050 Fudge the pc to make sure we get that. */
1052 if (notcurrent
) pc
-= 1;
1054 s
= find_pc_symtab (pc
);
1064 bv
= BLOCKVECTOR (s
);
1066 /* Look at all the symtabs that share this blockvector.
1067 They all have the same apriori range, that we found was right;
1068 but they have different line tables. */
1070 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1072 /* Find the best line in this symtab. */
1079 fprintf (stderr
, "Inconsistent line number info for %s\n",
1085 item
= l
->item
; /* Get first line info */
1087 /* Is this file's first line closer than the first lines of other files?
1088 If so, record this file, and its first line, as best alternate. */
1089 if (item
->pc
> pc
&& (!alt
|| item
->pc
< alt
->pc
))
1095 for (i
= 0; i
< len
; i
++, item
++)
1097 /* Return the last line that did not start after PC. */
1104 /* At this point, prev points at the line whose start addr is <= pc, and
1105 item points at the next line. If we ran off the end of the linetable
1106 (pc >= start of the last line), then prev == item. If pc < start of
1107 the first line, prev will not be set. */
1109 /* Is this file's best line closer than the best in the other files?
1110 If so, record this file, and its best line, as best so far. */
1112 if (prev
&& (!best
|| prev
->pc
> best
->pc
))
1116 /* If another line is in the linetable, and its PC is closer
1117 than the best_end we currently have, take it as best_end. */
1118 if (i
< len
&& (best_end
== 0 || best_end
> item
->pc
))
1119 best_end
= item
->pc
;
1126 { /* If we didn't find any line # info, just
1135 val
.symtab
= alt_symtab
;
1136 val
.line
= alt
->line
- 1;
1137 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1143 val
.symtab
= best_symtab
;
1144 val
.line
= best
->line
;
1146 if (best_end
&& (!alt
|| best_end
< alt
->pc
))
1151 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1156 /* Find the PC value for a given source file and line number.
1157 Returns zero for invalid line number.
1158 The source file is specified with a struct symtab. */
1161 find_line_pc (symtab
, line
)
1162 struct symtab
*symtab
;
1165 register struct linetable
*l
;
1171 l
= LINETABLE (symtab
);
1172 ind
= find_line_common(l
, line
, &dummy
);
1173 return (ind
>= 0) ? l
->item
[ind
].pc
: 0;
1176 /* Find the range of pc values in a line.
1177 Store the starting pc of the line into *STARTPTR
1178 and the ending pc (start of next line) into *ENDPTR.
1179 Returns 1 to indicate success.
1180 Returns 0 if could not find the specified line. */
1183 find_line_pc_range (symtab
, thisline
, startptr
, endptr
)
1184 struct symtab
*symtab
;
1186 CORE_ADDR
*startptr
, *endptr
;
1188 register struct linetable
*l
;
1190 int exact_match
; /* did we get an exact linenumber match */
1195 l
= LINETABLE (symtab
);
1196 ind
= find_line_common (l
, thisline
, &exact_match
);
1199 *startptr
= l
->item
[ind
].pc
;
1200 /* If we have not seen an entry for the specified line,
1201 assume that means the specified line has zero bytes. */
1202 if (!exact_match
|| ind
== l
->nitems
-1)
1203 *endptr
= *startptr
;
1205 /* Perhaps the following entry is for the following line.
1206 It's worth a try. */
1207 if (ind
+1 < l
->nitems
1208 && l
->item
[ind
+1].line
== thisline
+ 1)
1209 *endptr
= l
->item
[ind
+1].pc
;
1211 *endptr
= find_line_pc (symtab
, thisline
+1);
1218 /* Given a line table and a line number, return the index into the line
1219 table for the pc of the nearest line whose number is >= the specified one.
1220 Return -1 if none is found. The value is >= 0 if it is an index.
1222 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1225 find_line_common (l
, lineno
, exact_match
)
1226 register struct linetable
*l
;
1227 register int lineno
;
1233 /* BEST is the smallest linenumber > LINENO so far seen,
1234 or 0 if none has been seen so far.
1235 BEST_INDEX identifies the item for it. */
1237 int best_index
= -1;
1246 for (i
= 0; i
< len
; i
++)
1248 register struct linetable_entry
*item
= &(l
->item
[i
]);
1250 if (item
->line
== lineno
)
1256 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
1263 /* If we got here, we didn't get an exact match. */
1270 find_pc_line_pc_range (pc
, startptr
, endptr
)
1272 CORE_ADDR
*startptr
, *endptr
;
1274 struct symtab_and_line sal
;
1275 sal
= find_pc_line (pc
, 0);
1278 return sal
.symtab
!= 0;
1281 /* If P is of the form "operator[ \t]+..." where `...' is
1282 some legitimate operator text, return a pointer to the
1283 beginning of the substring of the operator text.
1284 Otherwise, return "". */
1286 operator_chars (p
, end
)
1291 if (strncmp (p
, "operator", 8))
1295 /* Don't get faked out by `operator' being part of a longer
1297 if (isalpha(*p
) || *p
== '_' || *p
== '$' || *p
== '\0')
1300 /* Allow some whitespace between `operator' and the operator symbol. */
1301 while (*p
== ' ' || *p
== '\t')
1304 /* Recognize 'operator TYPENAME'. */
1306 if (isalpha(*p
) || *p
== '_' || *p
== '$')
1308 register char *q
= p
+1;
1309 while (isalnum(*q
) || *q
== '_' || *q
== '$')
1334 if (p
[1] == '=' || p
[1] == p
[0])
1345 error ("`operator ()' must be specified without whitespace in `()'");
1350 error ("`operator ?:' must be specified without whitespace in `?:'");
1355 error ("`operator []' must be specified without whitespace in `[]'");
1359 error ("`operator %s' not supported", p
);
1366 /* Recursive helper function for decode_line_1.
1367 * Look for methods named NAME in type T.
1368 * Return number of matches.
1369 * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1370 * These allocations seem to define "big enough":
1371 * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1372 * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1376 find_methods (t
, name
, physnames
, sym_arr
)
1380 struct symbol
**sym_arr
;
1384 struct symbol
*sym_class
;
1385 char *class_name
= type_name_no_tag (t
);
1386 /* Ignore this class if it doesn't have a name.
1387 This prevents core dumps, but is just a workaround
1388 because we might not find the function in
1389 certain cases, such as
1390 struct D {virtual int f();}
1391 struct C : D {virtual int g();}
1392 (in this case g++ 1.35.1- does not put out a name
1393 for D as such, it defines type 19 (for example) in
1394 the same stab as C, and then does a
1395 .stabs "D:T19" and a .stabs "D:t19".
1397 "break C::f" should not be looking for field f in
1399 but just for the field f in the baseclasses of C
1400 (no matter what their names).
1402 However, I don't know how to replace the code below
1403 that depends on knowing the name of D. */
1405 && (sym_class
= lookup_symbol (class_name
,
1406 (struct block
*)NULL
,
1409 (struct symtab
**)NULL
)))
1412 t
= SYMBOL_TYPE (sym_class
);
1413 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
1414 method_counter
>= 0;
1418 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
1420 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
1421 if (!strcmp (name
, method_name
))
1422 /* Find all the fields with that name. */
1423 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
1428 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
1429 check_stub_method (t
, method_counter
, field_counter
);
1430 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
1431 physnames
[i1
] = (char*) alloca (strlen (phys_name
) + 1);
1432 strcpy (physnames
[i1
], phys_name
);
1433 sym_arr
[i1
] = lookup_symbol (phys_name
,
1434 SYMBOL_BLOCK_VALUE (sym_class
),
1437 (struct symtab
**) NULL
);
1438 if (sym_arr
[i1
]) i1
++;
1441 fputs_filtered("(Cannot find method ", stdout
);
1442 fputs_demangled(phys_name
, stdout
, DMGL_PARAMS
);
1443 fputs_filtered(" - possibly inlined.)\n", stdout
);
1448 /* Only search baseclasses if there is no match yet,
1449 * since names in derived classes override those in baseclasses.
1453 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
1454 i1
+= find_methods(TYPE_BASECLASS(t
, ibase
), name
,
1455 physnames
+ i1
, sym_arr
+ i1
);
1459 /* Parse a string that specifies a line number.
1460 Pass the address of a char * variable; that variable will be
1461 advanced over the characters actually parsed.
1465 LINENUM -- that line number in current file. PC returned is 0.
1466 FILE:LINENUM -- that line in that file. PC returned is 0.
1467 FUNCTION -- line number of openbrace of that function.
1468 PC returned is the start of the function.
1469 VARIABLE -- line number of definition of that variable.
1471 FILE:FUNCTION -- likewise, but prefer functions in that file.
1472 *EXPR -- line in which address EXPR appears.
1474 FUNCTION may be an undebuggable function found in minimal symbol table.
1476 If the argument FUNFIRSTLINE is nonzero, we want the first line
1477 of real code inside a function when a function is specified.
1479 DEFAULT_SYMTAB specifies the file to use if none is specified.
1480 It defaults to current_source_symtab.
1481 DEFAULT_LINE specifies the line number to use for relative
1482 line numbers (that start with signs). Defaults to current_source_line.
1484 Note that it is possible to return zero for the symtab
1485 if no file is validly specified. Callers must check that.
1486 Also, the line number returned may be invalid. */
1488 struct symtabs_and_lines
1489 decode_line_1 (argptr
, funfirstline
, default_symtab
, default_line
)
1492 struct symtab
*default_symtab
;
1495 struct symtabs_and_lines values
;
1496 #ifdef HPPA_COMPILER_BUG
1497 /* FIXME: The native HP 9000/700 compiler has a bug which appears
1498 when optimizing this file with target i960-vxworks. I haven't
1499 been able to construct a simple test case. The problem is that
1500 in the second call to SKIP_PROLOGUE below, the compiler somehow
1501 does not realize that the statement val = find_pc_line (...) will
1502 change the values of the fields of val. It extracts the elements
1503 into registers at the top of the block, and does not update the
1504 registers after the call to find_pc_line. You can check this by
1505 inserting a printf at the end of find_pc_line to show what values
1506 it is returning for val.pc and val.end and another printf after
1507 the call to see what values the function actually got (remember,
1508 this is compiling with cc -O, with this patch removed). You can
1509 also examine the assembly listing: search for the second call to
1510 skip_prologue; the LDO statement before the next call to
1511 find_pc_line loads the address of the structure which
1512 find_pc_line will return; if there is a LDW just before the LDO,
1513 which fetches an element of the structure, then the compiler
1516 Setting val to volatile avoids the problem. We must undef
1517 volatile, because the HPPA native compiler does not define
1518 __STDC__, although it does understand volatile, and so volatile
1519 will have been defined away in defs.h. */
1521 volatile struct symtab_and_line val
;
1522 #define volatile /*nothing*/
1524 struct symtab_and_line val
;
1526 register char *p
, *p1
;
1528 register struct symtab
*s
;
1530 register struct symbol
*sym
;
1531 /* The symtab that SYM was found in. */
1532 struct symtab
*sym_symtab
;
1534 register CORE_ADDR pc
;
1535 register struct minimal_symbol
*msymbol
;
1537 struct symbol
*sym_class
;
1540 struct symbol
**sym_arr
;
1543 char *saved_arg
= *argptr
;
1544 extern char *gdb_completer_quote_characters
;
1546 /* Defaults have defaults. */
1548 if (default_symtab
== 0)
1550 default_symtab
= current_source_symtab
;
1551 default_line
= current_source_line
;
1554 /* See if arg is *PC */
1556 if (**argptr
== '*')
1558 if (**argptr
== '*')
1562 pc
= parse_and_eval_address_1 (argptr
);
1563 values
.sals
= (struct symtab_and_line
*)
1564 xmalloc (sizeof (struct symtab_and_line
));
1566 values
.sals
[0] = find_pc_line (pc
, 0);
1567 values
.sals
[0].pc
= pc
;
1571 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1574 is_quoted
= (strchr (gdb_completer_quote_characters
, **argptr
) != NULL
);
1576 for (p
= *argptr
; *p
; p
++)
1578 if (p
[0] == ':' || p
[0] == ' ' || p
[0] == '\t')
1581 while (p
[0] == ' ' || p
[0] == '\t') p
++;
1583 if ((p
[0] == ':') && !is_quoted
)
1589 /* Extract the class name. */
1591 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1592 copy
= (char *) alloca (p
- *argptr
+ 1);
1593 memcpy (copy
, *argptr
, p
- *argptr
);
1594 copy
[p
- *argptr
] = 0;
1596 /* Discard the class name from the arg. */
1598 while (*p
== ' ' || *p
== '\t') p
++;
1601 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
1602 (struct symtab
**)NULL
);
1605 ( TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_STRUCT
1606 || TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_UNION
))
1608 /* Arg token is not digits => try it as a function name
1609 Find the next token (everything up to end or next whitespace). */
1611 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',' && *p
!=':') p
++;
1612 q
= operator_chars (*argptr
, &q1
);
1617 char *tmp
= alloca (q1
- q
+ 1);
1618 memcpy (tmp
, q
, q1
- q
);
1620 opname
= cplus_mangle_opname (tmp
, DMGL_ANSI
);
1623 warning ("no mangling for \"%s\"", tmp
);
1624 cplusplus_hint (saved_arg
);
1625 return_to_top_level ();
1627 copy
= (char*) alloca (3 + strlen(opname
));
1628 sprintf (copy
, "__%s", opname
);
1633 copy
= (char *) alloca (p
- *argptr
+ 1 + (q1
- q
));
1634 memcpy (copy
, *argptr
, p
- *argptr
);
1635 copy
[p
- *argptr
] = '\0';
1638 /* no line number may be specified */
1639 while (*p
== ' ' || *p
== '\t') p
++;
1643 i1
= 0; /* counter for the symbol array */
1644 t
= SYMBOL_TYPE (sym_class
);
1645 sym_arr
= (struct symbol
**) alloca(TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(struct symbol
*));
1646 physnames
= (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(char*));
1648 if (destructor_name_p (copy
, t
))
1650 /* destructors are a special case. */
1651 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, 0);
1652 int len
= TYPE_FN_FIELDLIST_LENGTH (t
, 0) - 1;
1653 char *phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, len
);
1654 physnames
[i1
] = (char *)alloca (strlen (phys_name
) + 1);
1655 strcpy (physnames
[i1
], phys_name
);
1657 lookup_symbol (phys_name
, SYMBOL_BLOCK_VALUE (sym_class
),
1658 VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
1659 if (sym_arr
[i1
]) i1
++;
1662 i1
= find_methods (t
, copy
, physnames
, sym_arr
);
1665 /* There is exactly one field with that name. */
1668 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1670 /* Arg is the name of a function */
1671 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1674 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1676 values
.sals
[0] = find_pc_line (pc
, 0);
1677 values
.sals
[0].pc
= (values
.sals
[0].end
&& values
.sals
[0].pc
!= pc
) ? values
.sals
[0].end
: pc
;
1687 /* There is more than one field with that name
1688 (overloaded). Ask the user which one to use. */
1689 return decode_line_2 (sym_arr
, i1
, funfirstline
);
1695 if (OPNAME_PREFIX_P (copy
))
1697 tmp
= (char *)alloca (strlen (copy
+3) + 9);
1698 strcpy (tmp
, "operator ");
1699 strcat (tmp
, copy
+3);
1704 warning ("the class `%s' does not have destructor defined",
1707 warning ("the class %s does not have any method named %s",
1708 sym_class
->name
, tmp
);
1709 cplusplus_hint (saved_arg
);
1710 return_to_top_level ();
1715 /* The quotes are important if copy is empty. */
1716 warning ("can't find class, struct, or union named \"%s\"",
1718 cplusplus_hint (saved_arg
);
1719 return_to_top_level ();
1725 /* Extract the file name. */
1727 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1728 copy
= (char *) alloca (p
- *argptr
+ 1);
1729 memcpy (copy
, *argptr
, p
- *argptr
);
1730 copy
[p
- *argptr
] = 0;
1732 /* Find that file's data. */
1733 s
= lookup_symtab (copy
);
1736 if (!have_full_symbols () && !have_partial_symbols ())
1737 error (no_symtab_msg
);
1738 error ("No source file named %s.", copy
);
1741 /* Discard the file name from the arg. */
1743 while (*p
== ' ' || *p
== '\t') p
++;
1747 /* S is specified file's symtab, or 0 if no file specified.
1748 arg no longer contains the file name. */
1750 /* Check whether arg is all digits (and sign) */
1753 if (*p
== '-' || *p
== '+') p
++;
1754 while (*p
>= '0' && *p
<= '9')
1757 if (p
!= *argptr
&& (*p
== 0 || *p
== ' ' || *p
== '\t' || *p
== ','))
1759 /* We found a token consisting of all digits -- at least one digit. */
1760 enum sign
{none
, plus
, minus
} sign
= none
;
1762 /* This is where we need to make sure that we have good defaults.
1763 We must guarantee that this section of code is never executed
1764 when we are called with just a function name, since
1765 select_source_symtab calls us with such an argument */
1767 if (s
== 0 && default_symtab
== 0)
1769 select_source_symtab (0);
1770 default_symtab
= current_source_symtab
;
1771 default_line
= current_source_line
;
1774 if (**argptr
== '+')
1775 sign
= plus
, (*argptr
)++;
1776 else if (**argptr
== '-')
1777 sign
= minus
, (*argptr
)++;
1778 val
.line
= atoi (*argptr
);
1785 val
.line
= default_line
+ val
.line
;
1791 val
.line
= default_line
- val
.line
;
1796 break; /* No need to adjust val.line. */
1799 while (*p
== ' ' || *p
== '\t') p
++;
1805 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1806 values
.sals
[0] = val
;
1811 /* Arg token is not digits => try it as a variable name
1812 Find the next token (everything up to end or next whitespace). */
1814 p
= skip_quoted (*argptr
);
1815 copy
= (char *) alloca (p
- *argptr
+ 1);
1816 memcpy (copy
, *argptr
, p
- *argptr
);
1817 copy
[p
- *argptr
] = '\0';
1818 if ((copy
[0] == copy
[p
- *argptr
- 1])
1819 && strchr (gdb_completer_quote_characters
, copy
[0]) != NULL
)
1822 copy
[p
- *argptr
- 1] = '\0';
1824 if ((temp
= expensive_mangler (copy
)) != NULL
)
1829 while (*p
== ' ' || *p
== '\t') p
++;
1832 /* Look up that token as a variable.
1833 If file specified, use that file's per-file block to start with. */
1835 sym
= lookup_symbol (copy
,
1836 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
1837 : get_selected_block ()),
1838 VAR_NAMESPACE
, 0, &sym_symtab
);
1842 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1844 /* Arg is the name of a function */
1845 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1848 val
= find_pc_line (pc
, 0);
1849 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1850 /* Convex: no need to suppress code on first line, if any */
1853 /* If SKIP_PROLOGUE left us in mid-line, and the next line is still
1854 part of the same function:
1855 advance to next line,
1856 recalculate its line number (might not be N+1). */
1857 if (val
.pc
!= pc
&& val
.end
&&
1858 lookup_minimal_symbol_by_pc (pc
) == lookup_minimal_symbol_by_pc (val
.end
)) {
1859 pc
= val
.end
; /* First pc of next line */
1860 val
= find_pc_line (pc
, 0);
1864 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1865 values
.sals
[0] = val
;
1868 /* I think this is always the same as the line that
1869 we calculate above, but the general principle is
1870 "trust the symbols more than stuff like
1872 if (SYMBOL_LINE (sym
) != 0)
1873 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1877 else if (SYMBOL_LINE (sym
) != 0)
1879 /* We know its line number. */
1880 values
.sals
= (struct symtab_and_line
*)
1881 xmalloc (sizeof (struct symtab_and_line
));
1883 memset (&values
.sals
[0], 0, sizeof (values
.sals
[0]));
1884 values
.sals
[0].symtab
= sym_symtab
;
1885 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1889 /* This can happen if it is compiled with a compiler which doesn't
1890 put out line numbers for variables. */
1891 error ("Line number not known for symbol \"%s\"", copy
);
1894 msymbol
= lookup_minimal_symbol (copy
, (struct objfile
*) NULL
);
1895 if (msymbol
!= NULL
)
1899 val
.pc
= msymbol
-> address
+ FUNCTION_START_OFFSET
;
1901 SKIP_PROLOGUE (val
.pc
);
1902 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1903 values
.sals
[0] = val
;
1908 if (!have_full_symbols () &&
1909 !have_partial_symbols () && !have_minimal_symbols ())
1910 error (no_symtab_msg
);
1912 error ("Function \"%s\" not defined.", copy
);
1913 return values
; /* for lint */
1916 struct symtabs_and_lines
1917 decode_line_spec (string
, funfirstline
)
1921 struct symtabs_and_lines sals
;
1923 error ("Empty line specification.");
1924 sals
= decode_line_1 (&string
, funfirstline
,
1925 current_source_symtab
, current_source_line
);
1927 error ("Junk at end of line specification: %s", string
);
1931 /* Given a list of NELTS symbols in sym_arr (with corresponding
1932 mangled names in physnames), return a list of lines to operate on
1933 (ask user if necessary). */
1934 static struct symtabs_and_lines
1935 decode_line_2 (sym_arr
, nelts
, funfirstline
)
1936 struct symbol
*sym_arr
[];
1940 struct symtabs_and_lines values
, return_values
;
1941 register CORE_ADDR pc
;
1947 values
.sals
= (struct symtab_and_line
*) alloca (nelts
* sizeof(struct symtab_and_line
));
1948 return_values
.sals
= (struct symtab_and_line
*) xmalloc (nelts
* sizeof(struct symtab_and_line
));
1951 printf("[0] cancel\n[1] all\n");
1954 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
1956 /* Arg is the name of a function */
1957 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr
[i
]))
1958 + FUNCTION_START_OFFSET
;
1961 values
.sals
[i
] = find_pc_line (pc
, 0);
1962 values
.sals
[i
].pc
= (values
.sals
[i
].end
&& values
.sals
[i
].pc
!= pc
) ?
1963 values
.sals
[i
].end
: pc
;
1964 demangled
= cplus_demangle (SYMBOL_NAME (sym_arr
[i
]),
1965 DMGL_PARAMS
| DMGL_ANSI
);
1966 printf("[%d] %s at %s:%d\n", (i
+2),
1967 demangled
? demangled
: SYMBOL_NAME (sym_arr
[i
]),
1968 values
.sals
[i
].symtab
->filename
, values
.sals
[i
].line
);
1969 if (demangled
!= NULL
)
1974 else printf ("?HERE\n");
1978 if ((prompt
= getenv ("PS2")) == NULL
)
1982 printf("%s ",prompt
);
1985 args
= command_line_input ((char *) NULL
, 0);
1988 error_no_arg ("one or more choice numbers");
1996 while (*arg1
>= '0' && *arg1
<= '9') arg1
++;
1997 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
1998 error ("Arguments must be choice numbers.");
2003 error ("cancelled");
2006 memcpy (return_values
.sals
, values
.sals
,
2007 (nelts
* sizeof(struct symtab_and_line
)));
2008 return_values
.nelts
= nelts
;
2009 return return_values
;
2012 if (num
> nelts
+ 2)
2014 printf ("No choice number %d.\n", num
);
2019 if (values
.sals
[num
].pc
)
2021 return_values
.sals
[i
++] = values
.sals
[num
];
2022 values
.sals
[num
].pc
= 0;
2026 printf ("duplicate request for %d ignored.\n", num
);
2031 while (*args
== ' ' || *args
== '\t') args
++;
2033 return_values
.nelts
= i
;
2034 return return_values
;
2038 /* Slave routine for sources_info. Force line breaks at ,'s.
2039 NAME is the name to print and *FIRST is nonzero if this is the first
2040 name printed. Set *FIRST to zero. */
2042 output_source_filename (name
, first
)
2046 /* Table of files printed so far. Since a single source file can
2047 result in several partial symbol tables, we need to avoid printing
2048 it more than once. Note: if some of the psymtabs are read in and
2049 some are not, it gets printed both under "Source files for which
2050 symbols have been read" and "Source files for which symbols will
2051 be read in on demand". I consider this a reasonable way to deal
2052 with the situation. I'm not sure whether this can also happen for
2053 symtabs; it doesn't hurt to check. */
2054 static char **tab
= NULL
;
2055 /* Allocated size of tab in elements.
2056 Start with one 256-byte block (when using GNU malloc.c).
2057 24 is the malloc overhead when range checking is in effect. */
2058 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
2059 /* Current size of tab in elements. */
2060 static int tab_cur_size
;
2067 tab
= (char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
2071 /* Is NAME in tab? */
2072 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
2073 if (strcmp (*p
, name
) == 0)
2074 /* Yes; don't print it again. */
2076 /* No; add it to tab. */
2077 if (tab_cur_size
== tab_alloc_size
)
2079 tab_alloc_size
*= 2;
2080 tab
= (char **) xrealloc ((char *) tab
, tab_alloc_size
* sizeof (*tab
));
2082 tab
[tab_cur_size
++] = name
;
2090 printf_filtered (", ");
2094 fputs_filtered (name
, stdout
);
2098 sources_info (ignore
, from_tty
)
2102 register struct symtab
*s
;
2103 register struct partial_symtab
*ps
;
2104 register struct objfile
*objfile
;
2107 if (!have_full_symbols () && !have_partial_symbols ())
2109 error (no_symtab_msg
);
2112 printf_filtered ("Source files for which symbols have been read in:\n\n");
2115 ALL_SYMTABS (objfile
, s
)
2117 output_source_filename (s
-> filename
, &first
);
2119 printf_filtered ("\n\n");
2121 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2124 ALL_PSYMTABS (objfile
, ps
)
2128 output_source_filename (ps
-> filename
, &first
);
2131 printf_filtered ("\n");
2138 char *demangled
= cplus_demangle (name
, DMGL_ANSI
);
2139 if (demangled
!= NULL
)
2141 int cond
= re_exec (demangled
);
2145 return (re_exec (name
));
2147 #define NAME_MATCH(NAME) name_match(NAME)
2149 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2150 If CLASS is zero, list all symbols except functions, type names, and
2152 If CLASS is 1, list only functions.
2153 If CLASS is 2, list only type names.
2154 If CLASS is 3, list only method names.
2156 BPT is non-zero if we should set a breakpoint at the functions
2160 list_symbols (regexp
, class, bpt
)
2165 register struct symtab
*s
;
2166 register struct partial_symtab
*ps
;
2167 register struct blockvector
*bv
;
2168 struct blockvector
*prev_bv
= 0;
2169 register struct block
*b
;
2171 register struct symbol
*sym
;
2172 struct partial_symbol
*psym
;
2173 struct objfile
*objfile
;
2174 struct minimal_symbol
*msymbol
;
2176 static char *classnames
[]
2177 = {"variable", "function", "type", "method"};
2178 int found_in_file
= 0;
2180 static enum minimal_symbol_type types
[]
2181 = {mst_data
, mst_text
, mst_abs
, mst_unknown
};
2182 static enum minimal_symbol_type types2
[]
2183 = {mst_bss
, mst_text
, mst_abs
, mst_unknown
};
2184 enum minimal_symbol_type ourtype
= types
[class];
2185 enum minimal_symbol_type ourtype2
= types2
[class];
2189 /* Make sure spacing is right for C++ operators.
2190 This is just a courtesy to make the matching less sensitive
2191 to how many spaces the user leaves between 'operator'
2192 and <TYPENAME> or <OPERATOR>. */
2194 char *opname
= operator_chars (regexp
, &opend
);
2197 int fix
= -1; /* -1 means ok; otherwise number of spaces needed. */
2198 if (isalpha(*opname
) || *opname
== '_' || *opname
== '$')
2200 /* There should 1 space between 'operator' and 'TYPENAME'. */
2201 if (opname
[-1] != ' ' || opname
[-2] == ' ')
2206 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2207 if (opname
[-1] == ' ')
2210 /* If wrong number of spaces, fix it. */
2213 char *tmp
= (char*) alloca(opend
-opname
+10);
2214 sprintf(tmp
, "operator%.*s%s", fix
, " ", opname
);
2219 if (0 != (val
= re_comp (regexp
)))
2220 error ("Invalid regexp (%s): %s", val
, regexp
);
2223 /* Search through the partial symtabs *first* for all symbols
2224 matching the regexp. That way we don't have to reproduce all of
2225 the machinery below. */
2227 ALL_PSYMTABS (objfile
, ps
)
2229 struct partial_symbol
*bound
, *gbound
, *sbound
;
2232 if (ps
->readin
) continue;
2234 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2235 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2238 /* Go through all of the symbols stored in a partial
2239 symtab in one loop. */
2240 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2245 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2247 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2258 /* If it would match (logic taken from loop below)
2259 load the file and go on to the next one */
2260 if ((regexp
== 0 || NAME_MATCH (SYMBOL_NAME (psym
)))
2261 && ((class == 0 && SYMBOL_CLASS (psym
) != LOC_TYPEDEF
2262 && SYMBOL_CLASS (psym
) != LOC_BLOCK
)
2263 || (class == 1 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)
2264 || (class == 2 && SYMBOL_CLASS (psym
) == LOC_TYPEDEF
)
2265 || (class == 3 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)))
2267 PSYMTAB_TO_SYMTAB(ps
);
2275 /* Here, we search through the minimal symbol tables for functions that
2276 match, and call find_pc_symtab on them to force their symbols to
2277 be read. The symbol will then be found during the scan of symtabs
2278 below. If find_pc_symtab fails, set found_misc so that we will
2279 rescan to print any matching symbols without debug info. */
2283 ALL_MSYMBOLS (objfile
, msymbol
)
2285 if (msymbol
-> type
== ourtype
|| msymbol
-> type
== ourtype2
)
2287 if (regexp
== 0 || NAME_MATCH (msymbol
-> name
))
2289 if (0 == find_pc_symtab (msymbol
-> address
))
2298 /* Printout here so as to get after the "Reading in symbols"
2299 messages which will be generated above. */
2301 printf_filtered (regexp
2302 ? "All %ss matching regular expression \"%s\":\n"
2303 : "All defined %ss:\n",
2307 ALL_SYMTABS (objfile
, s
)
2310 bv
= BLOCKVECTOR (s
);
2311 /* Often many files share a blockvector.
2312 Scan each blockvector only once so that
2313 we don't get every symbol many times.
2314 It happens that the first symtab in the list
2315 for any given blockvector is the main file. */
2317 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
2319 b
= BLOCKVECTOR_BLOCK (bv
, i
);
2320 /* Skip the sort if this block is always sorted. */
2321 if (!BLOCK_SHOULD_SORT (b
))
2322 sort_block_syms (b
);
2323 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
2326 sym
= BLOCK_SYM (b
, j
);
2327 if ((regexp
== 0 || NAME_MATCH (SYMBOL_NAME (sym
)))
2328 && ((class == 0 && SYMBOL_CLASS (sym
) != LOC_TYPEDEF
2329 && SYMBOL_CLASS (sym
) != LOC_BLOCK
2330 && SYMBOL_CLASS (sym
) != LOC_CONST
)
2331 || (class == 1 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2332 || (class == 2 && SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2333 || (class == 3 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)))
2337 /* Set a breakpoint here, if it's a function */
2339 break_command (SYMBOL_NAME(sym
), 0);
2341 else if (!found_in_file
)
2343 fputs_filtered ("\nFile ", stdout
);
2344 fputs_filtered (s
->filename
, stdout
);
2345 fputs_filtered (":\n", stdout
);
2349 if (class != 2 && i
== STATIC_BLOCK
)
2350 printf_filtered ("static ");
2352 /* Typedef that is not a C++ class */
2354 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
2355 c_typedef_print (SYMBOL_TYPE(sym
), sym
, stdout
);
2356 /* variable, func, or typedef-that-is-c++-class */
2357 else if (class < 2 ||
2359 SYMBOL_NAMESPACE(sym
) == STRUCT_NAMESPACE
))
2361 type_print (SYMBOL_TYPE (sym
),
2362 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2363 ? "" : SYMBOL_NAME (sym
)),
2366 printf_filtered (";\n");
2370 # if 0 /* FIXME, why is this zapped out? */
2372 c_type_print_base (TYPE_FN_FIELD_TYPE(t
, i
),
2374 c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t
, i
),
2376 sprintf (buf
, " %s::", type_name_no_tag (t
));
2377 cp_type_print_method_args (TYPE_FN_FIELD_ARGS (t
, i
),
2387 /* If there are no eyes, avoid all contact. I mean, if there are
2388 no debug symbols, then print directly from the msymbol_vector. */
2390 if (found_misc
|| class != 1)
2393 ALL_MSYMBOLS (objfile
, msymbol
)
2395 if (msymbol
-> type
== ourtype
|| msymbol
-> type
== ourtype2
)
2397 if (regexp
== 0 || NAME_MATCH (msymbol
-> name
))
2399 /* Functions: Look up by address. */
2401 (0 == find_pc_symtab (msymbol
-> address
)))
2403 /* Variables/Absolutes: Look up by name */
2404 if (lookup_symbol (msymbol
-> name
,
2405 (struct block
*) 0, VAR_NAMESPACE
, 0,
2406 (struct symtab
**) 0) == NULL
)
2410 printf_filtered ("\nNon-debugging symbols:\n");
2413 printf_filtered (" %08x %s\n",
2425 variables_info (regexp
, from_tty
)
2429 list_symbols (regexp
, 0, 0);
2433 functions_info (regexp
, from_tty
)
2437 list_symbols (regexp
, 1, 0);
2441 types_info (regexp
, from_tty
)
2445 list_symbols (regexp
, 2, 0);
2449 /* Tiemann says: "info methods was never implemented." */
2451 methods_info (regexp
)
2454 list_symbols (regexp
, 3, 0);
2458 /* Breakpoint all functions matching regular expression. */
2460 rbreak_command (regexp
, from_tty
)
2464 list_symbols (regexp
, 1, 1);
2468 /* Return Nonzero if block a is lexically nested within block b,
2469 or if a and b have the same pc range.
2470 Return zero otherwise. */
2473 struct block
*a
, *b
;
2477 return BLOCK_START (a
) >= BLOCK_START (b
)
2478 && BLOCK_END (a
) <= BLOCK_END (b
);
2482 /* Helper routine for make_symbol_completion_list. */
2484 static int return_val_size
;
2485 static int return_val_index
;
2486 static char **return_val
;
2488 /* Test to see if the symbol specified by SYMNAME (or it's demangled
2489 equivalent) matches TEXT in the first TEXT_LEN characters. If so,
2490 add it to the current completion list. */
2493 completion_list_add_symbol (symname
, text
, text_len
)
2502 /* clip symbols that cannot match */
2504 if (!cplus_match (symname
, text
, text_len
)) {
2508 /* matches mangled, may match unmangled. now clip any symbol names
2509 that we've already considered. (This is a time optimization) */
2511 for (i
= 0; i
< return_val_index
; ++i
) {
2512 if (strcmp (symname
, return_val
[i
]) == 0) {
2517 /* See if SYMNAME is a C++ mangled name, and if so, use the
2518 demangled name instead, including any parameters. */
2520 if ((demangled
= cplus_demangle (symname
, DMGL_PARAMS
| DMGL_ANSI
)) != NULL
)
2522 if (strncmp (demangled
, text
, text_len
) != 0) {
2524 } /* demangled, but didn't match so clip it */
2526 symname
= demangled
;
2528 symname
= savestring (symname
, strlen (symname
));
2531 /* If we have a match for a completion, then add SYMNAME to the current
2532 list of matches. Note that the name is in freshly malloc'd space;
2533 either from cplus_demangle or from savestring above. */
2535 if (return_val_index
+ 3 > return_val_size
)
2537 newsize
= (return_val_size
*= 2) * sizeof (char *);
2538 return_val
= (char **) xrealloc ((char *) return_val
, newsize
);
2540 return_val
[return_val_index
++] = symname
;
2541 return_val
[return_val_index
] = NULL
;
2546 /* Return a NULL terminated array of all symbols (regardless of class) which
2547 begin by matching TEXT. If the answer is no symbols, then the return value
2548 is an array which contains only a NULL pointer.
2550 Problem: All of the symbols have to be copied because readline frees them.
2551 I'm not going to worry about this; hopefully there won't be that many. */
2554 make_symbol_completion_list (text
)
2557 register struct symbol
*sym
;
2558 register struct symtab
*s
;
2559 register struct partial_symtab
*ps
;
2560 register struct minimal_symbol
*msymbol
;
2561 register struct objfile
*objfile
;
2562 register struct block
*b
, *surrounding_static_block
= 0;
2565 struct partial_symbol
*psym
;
2567 text_len
= strlen (text
);
2568 return_val_size
= 100;
2569 return_val_index
= 0;
2570 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
2571 return_val
[0] = NULL
;
2573 /* Look through the partial symtabs for all symbols which begin
2574 by matching TEXT. Add each one that you find to the list. */
2576 ALL_PSYMTABS (objfile
, ps
)
2578 /* If the psymtab's been read in we'll get it when we search
2579 through the blockvector. */
2580 if (ps
->readin
) continue;
2582 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2583 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
2584 + ps
->n_global_syms
);
2587 /* If interrupted, then quit. */
2589 completion_list_add_symbol (SYMBOL_NAME (psym
), text
, text_len
);
2592 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2593 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
2594 + ps
->n_static_syms
);
2598 completion_list_add_symbol (SYMBOL_NAME (psym
), text
, text_len
);
2602 /* At this point scan through the misc symbol vectors and add each
2603 symbol you find to the list. Eventually we want to ignore
2604 anything that isn't a text symbol (everything else will be
2605 handled by the psymtab code above). */
2607 ALL_MSYMBOLS (objfile
, msymbol
)
2610 completion_list_add_symbol (msymbol
-> name
, text
, text_len
);
2613 /* Search upwards from currently selected frame (so that we can
2614 complete on local vars. */
2616 for (b
= get_selected_block (); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
2618 if (!BLOCK_SUPERBLOCK (b
))
2620 surrounding_static_block
= b
; /* For elmin of dups */
2623 /* Also catch fields of types defined in this places which match our
2624 text string. Only complete on types visible from current context. */
2626 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2628 sym
= BLOCK_SYM (b
, i
);
2629 completion_list_add_symbol (SYMBOL_NAME (sym
), text
, text_len
);
2630 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2632 struct type
*t
= SYMBOL_TYPE (sym
);
2633 enum type_code c
= TYPE_CODE (t
);
2635 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
2637 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
2639 if (TYPE_FIELD_NAME (t
, j
))
2641 completion_list_add_symbol (TYPE_FIELD_NAME (t
, j
),
2650 /* Go through the symtabs and check the externs and statics for
2651 symbols which match. */
2653 ALL_SYMTABS (objfile
, s
)
2656 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
2657 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2659 sym
= BLOCK_SYM (b
, i
);
2660 completion_list_add_symbol (SYMBOL_NAME (sym
), text
, text_len
);
2664 ALL_SYMTABS (objfile
, s
)
2667 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
2668 /* Don't do this block twice. */
2669 if (b
== surrounding_static_block
) continue;
2670 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2672 sym
= BLOCK_SYM (b
, i
);
2673 completion_list_add_symbol (SYMBOL_NAME (sym
), text
, text_len
);
2677 return (return_val
);
2681 /* Find a mangled symbol that corresponds to LOOKFOR using brute force.
2682 Basically we go munging through available symbols, demangling each one,
2683 looking for a match on the demangled result. */
2686 expensive_mangler (lookfor
)
2687 const char *lookfor
;
2689 register struct symbol
*sym
;
2690 register struct symtab
*s
;
2691 register struct partial_symtab
*ps
;
2692 register struct minimal_symbol
*msymbol
;
2693 register struct objfile
*objfile
;
2694 register struct block
*b
, *surrounding_static_block
= 0;
2696 struct partial_symbol
*psym
;
2699 /* Look through the partial symtabs for a symbol that matches */
2701 ALL_PSYMTABS (objfile
, ps
)
2703 /* If the psymtab's been read in we'll get it when we search
2704 through the blockvector. */
2705 if (ps
->readin
) continue;
2707 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2708 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
2709 + ps
->n_global_syms
);
2712 QUIT
; /* If interrupted, then quit. */
2713 demangled
= demangle_and_match (SYMBOL_NAME (psym
), lookfor
,
2714 DMGL_PARAMS
| DMGL_ANSI
);
2715 if (demangled
!= NULL
)
2718 return (SYMBOL_NAME (psym
));
2722 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2723 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
2724 + ps
->n_static_syms
);
2728 demangled
= demangle_and_match (SYMBOL_NAME (psym
), lookfor
,
2729 DMGL_PARAMS
| DMGL_ANSI
);
2730 if (demangled
!= NULL
)
2733 return (SYMBOL_NAME (psym
));
2738 /* Scan through the misc symbol vectors looking for a match. */
2740 ALL_MSYMBOLS (objfile
, msymbol
)
2743 demangled
= demangle_and_match (msymbol
-> name
, lookfor
,
2744 DMGL_PARAMS
| DMGL_ANSI
);
2745 if (demangled
!= NULL
)
2748 return (msymbol
-> name
);
2752 /* Search upwards from currently selected frame looking for a match */
2754 for (b
= get_selected_block (); b
; b
= BLOCK_SUPERBLOCK (b
))
2756 if (!BLOCK_SUPERBLOCK (b
))
2757 surrounding_static_block
= b
; /* For elmin of dups */
2759 /* Also catch fields of types defined in this places which
2760 match our text string. Only complete on types visible
2761 from current context. */
2762 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2764 sym
= BLOCK_SYM (b
, i
);
2765 demangled
= demangle_and_match (SYMBOL_NAME (sym
), lookfor
,
2766 DMGL_PARAMS
| DMGL_ANSI
);
2767 if (demangled
!= NULL
)
2770 return (SYMBOL_NAME (sym
));
2772 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2774 struct type
*t
= SYMBOL_TYPE (sym
);
2775 enum type_code c
= TYPE_CODE (t
);
2777 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
2779 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
2781 if (TYPE_FIELD_NAME (t
, j
))
2784 demangle_and_match (TYPE_FIELD_NAME (t
, j
),
2786 DMGL_PARAMS
| DMGL_ANSI
);
2787 if (demangled
!= NULL
)
2790 return (TYPE_FIELD_NAME (t
, j
));
2799 /* Go through the symtabs and check the externs and statics for
2800 symbols which match. */
2802 ALL_SYMTABS (objfile
, s
)
2805 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
2806 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2808 sym
= BLOCK_SYM (b
, i
);
2809 demangled
= demangle_and_match (SYMBOL_NAME (sym
), lookfor
,
2810 DMGL_PARAMS
| DMGL_ANSI
);
2811 if (demangled
!= NULL
)
2814 return (SYMBOL_NAME (sym
));
2819 ALL_SYMTABS (objfile
, s
)
2822 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
2823 /* Don't do this block twice. */
2824 if (b
== surrounding_static_block
) continue;
2825 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2827 sym
= BLOCK_SYM (b
, i
);
2828 demangled
= demangle_and_match (SYMBOL_NAME (sym
), lookfor
,
2829 DMGL_PARAMS
| DMGL_ANSI
);
2830 if (demangled
!= NULL
)
2833 return (SYMBOL_NAME (sym
));
2843 /* Add the type of the symbol sym to the type of the current
2844 function whose block we are in (assumed). The type of
2845 this current function is contained in *TYPE.
2847 This basically works as follows: When we find a function
2848 symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record
2849 a pointer to its type in the global in_function_type. Every
2850 time we come across a parameter symbol ('p' in its name), then
2851 this procedure adds the name and type of that parameter
2852 to the function type pointed to by *TYPE. (Which should correspond
2853 to in_function_type if it was called correctly).
2855 Note that since we are modifying a type, the result of
2856 lookup_function_type() should be memcpy()ed before calling
2857 this. When not in strict typing mode, the expression
2858 evaluator can choose to ignore this.
2860 Assumption: All of a function's parameter symbols will
2861 appear before another function symbol is found. The parameters
2862 appear in the same order in the argument list as they do in the
2866 add_param_to_type (type
,sym
)
2870 int num
= ++(TYPE_NFIELDS(*type
));
2872 if(TYPE_NFIELDS(*type
)-1)
2873 TYPE_FIELDS(*type
) = (struct field
*)
2874 (*current_objfile
->xrealloc
) ((char *)(TYPE_FIELDS(*type
)),
2875 num
*sizeof(struct field
));
2877 TYPE_FIELDS(*type
) = (struct field
*)
2878 (*current_objfile
->xmalloc
) (num
*sizeof(struct field
));
2880 TYPE_FIELD_BITPOS(*type
,num
-1) = num
-1;
2881 TYPE_FIELD_BITSIZE(*type
,num
-1) = 0;
2882 TYPE_FIELD_TYPE(*type
,num
-1) = SYMBOL_TYPE(sym
);
2883 TYPE_FIELD_NAME(*type
,num
-1) = SYMBOL_NAME(sym
);
2888 _initialize_symtab ()
2890 add_info ("variables", variables_info
,
2891 "All global and static variable names, or those matching REGEXP.");
2892 add_info ("functions", functions_info
,
2893 "All function names, or those matching REGEXP.");
2895 /* FIXME: This command has at least the following problems:
2896 1. It prints builtin types (in a very strange and confusing fashion).
2897 2. It doesn't print right, e.g. with
2898 typedef struct foo *FOO
2899 type_print prints "FOO" when we want to make it (in this situation)
2900 print "struct foo *".
2901 I also think "ptype" or "whatis" is more likely to be useful (but if
2902 there is much disagreement "info types" can be fixed). */
2903 add_info ("types", types_info
,
2904 "All type names, or those matching REGEXP.");
2907 add_info ("methods", methods_info
,
2908 "All method names, or those matching REGEXP::REGEXP.\n\
2909 If the class qualifier is omitted, it is assumed to be the current scope.\n\
2910 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
2913 add_info ("sources", sources_info
,
2914 "Source files in the program.");
2916 add_com ("rbreak", no_class
, rbreak_command
,
2917 "Set a breakpoint for all functions matching REGEXP.");
2919 /* Initialize the one built-in type that isn't language dependent... */
2920 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
2921 "<unknown type>", (struct objfile
*) NULL
);