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
)
383 /* Find which partial symbol within a psymtab contains PC. Return 0
384 if none. Check all psymtabs if PSYMTAB is 0. */
385 struct partial_symbol
*
386 find_pc_psymbol (psymtab
, pc
)
387 struct partial_symtab
*psymtab
;
390 struct partial_symbol
*best
, *p
;
394 psymtab
= find_pc_psymtab (pc
);
398 best_pc
= psymtab
->textlow
- 1;
400 for (p
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
401 (p
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
402 < psymtab
->n_static_syms
);
404 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
405 && SYMBOL_CLASS (p
) == LOC_BLOCK
406 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
407 && SYMBOL_VALUE_ADDRESS (p
) > best_pc
)
409 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
412 if (best_pc
== psymtab
->textlow
- 1)
418 /* Find the definition for a specified symbol name NAME
419 in namespace NAMESPACE, visible from lexical block BLOCK.
420 Returns the struct symbol pointer, or zero if no symbol is found.
421 If SYMTAB is non-NULL, store the symbol table in which the
422 symbol was found there, or NULL if not found.
423 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
424 NAME is a field of the current implied argument `this'. If so set
425 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
426 BLOCK_FOUND is set to the block in which NAME is found (in the case of
427 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
430 lookup_symbol (name
, block
, namespace, is_a_field_of_this
, symtab
)
432 register const struct block
*block
;
433 const enum namespace namespace;
434 int *is_a_field_of_this
;
435 struct symtab
**symtab
;
437 register struct symbol
*sym
;
438 register struct symtab
*s
;
439 register struct partial_symtab
*ps
;
440 struct blockvector
*bv
;
441 register struct objfile
*objfile
;
442 register struct block
*b
;
443 register struct minimal_symbol
*msymbol
;
445 extern char *gdb_completer_word_break_characters
;
447 /* If NAME contains any characters from gdb_completer_word_break_characters
448 then it is probably from a quoted name string. So check to see if it
449 has a C++ mangled equivalent, and if so, use the mangled equivalent. */
451 if (strpbrk (name
, gdb_completer_word_break_characters
) != NULL
)
453 if ((temp
= expensive_mangler (name
)) != NULL
)
459 /* Search specified block and its superiors. */
463 sym
= lookup_block_symbol (block
, name
, namespace);
469 /* Search the list of symtabs for one which contains the
470 address of the start of this block. */
471 ALL_SYMTABS (objfile
, s
)
473 bv
= BLOCKVECTOR (s
);
474 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
475 if (BLOCK_START (b
) <= BLOCK_START (block
)
476 && BLOCK_END (b
) > BLOCK_START (block
))
485 block
= BLOCK_SUPERBLOCK (block
);
488 /* But that doesn't do any demangling for the STATIC_BLOCK.
489 I'm not sure whether demangling is needed in the case of
490 nested function in inner blocks; if so this needs to be changed.
492 Don't need to mess with the psymtabs; if we have a block,
493 that file is read in. If we don't, then we deal later with
494 all the psymtab stuff that needs checking. */
495 if (namespace == VAR_NAMESPACE
&& block
!= NULL
)
498 /* Find the right symtab. */
499 ALL_SYMTABS (objfile
, s
)
501 bv
= BLOCKVECTOR (s
);
502 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
503 if (BLOCK_START (b
) <= BLOCK_START (block
)
504 && BLOCK_END (b
) > BLOCK_START (block
))
506 sym
= lookup_demangled_block_symbol (b
, name
);
519 /* C++: If requested to do so by the caller,
520 check to see if NAME is a field of `this'. */
521 if (is_a_field_of_this
)
523 struct value
*v
= value_of_this (0);
525 *is_a_field_of_this
= 0;
526 if (v
&& check_field (v
, name
))
528 *is_a_field_of_this
= 1;
535 /* Now search all global blocks. Do the symtab's first, then
536 check the psymtab's */
538 ALL_SYMTABS (objfile
, s
)
540 bv
= BLOCKVECTOR (s
);
541 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
542 sym
= lookup_block_symbol (block
, name
, namespace);
552 /* Check for the possibility of the symbol being a global function
553 that is stored in one of the minimal symbol tables. Eventually, all
554 global symbols might be resolved in this way. */
556 if (namespace == VAR_NAMESPACE
)
558 msymbol
= lookup_minimal_symbol (name
, (struct objfile
*) NULL
);
562 /* Test each minimal symbol to see if the minimal symbol's name
563 is a C++ mangled name that matches a user visible name. */
567 ALL_MSYMBOLS (objfile
, msymbol
)
569 demangled
= demangle_and_match (msymbol
-> name
, name
,
570 DMGL_PARAMS
| DMGL_ANSI
);
571 if (demangled
!= NULL
)
577 msymbol
= NULL
; /* Not found */
583 s
= find_pc_symtab (msymbol
-> address
);
584 /* If S is NULL, there are no debug symbols for this file.
585 Skip this stuff and check for matching static symbols below. */
588 bv
= BLOCKVECTOR (s
);
589 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
590 sym
= lookup_block_symbol (block
, msymbol
-> name
, namespace);
591 /* We kept static functions in minimal symbol table as well as
592 in static scope. We want to find them in the symbol table. */
594 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
595 sym
= lookup_block_symbol (block
, msymbol
-> name
,
599 /* sym == 0 if symbol was found in the minimal symbol table
600 but not in the symtab.
601 Return 0 to use the msymbol definition of "foo_".
603 This happens for Fortran "foo_" symbols,
604 which are "foo" in the symtab.
606 This can also happen if "asm" is used to make a
607 regular symbol but not a debugging symbol, e.g.
619 ALL_PSYMTABS (objfile
, ps
)
621 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
623 s
= PSYMTAB_TO_SYMTAB(ps
);
624 bv
= BLOCKVECTOR (s
);
625 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
626 sym
= lookup_block_symbol (block
, name
, namespace);
628 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab", name
, ps
->filename
);
635 /* Now search all per-file blocks.
636 Not strictly correct, but more useful than an error.
637 Do the symtabs first, then check the psymtabs */
639 ALL_SYMTABS (objfile
, s
)
641 bv
= BLOCKVECTOR (s
);
642 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
643 sym
= lookup_block_symbol (block
, name
, namespace);
653 ALL_PSYMTABS (objfile
, ps
)
655 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
657 s
= PSYMTAB_TO_SYMTAB(ps
);
658 bv
= BLOCKVECTOR (s
);
659 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
660 sym
= lookup_block_symbol (block
, name
, namespace);
662 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab", name
, ps
->filename
);
669 /* Now search all per-file blocks for static mangled symbols.
670 Do the symtabs first, then check the psymtabs. */
672 if (namespace == VAR_NAMESPACE
)
674 ALL_SYMTABS (objfile
, s
)
676 bv
= BLOCKVECTOR (s
);
677 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
678 sym
= lookup_demangled_block_symbol (block
, name
);
688 ALL_PSYMTABS (objfile
, ps
)
690 if (!ps
->readin
&& lookup_demangled_partial_symbol (ps
, name
))
692 s
= PSYMTAB_TO_SYMTAB(ps
);
693 bv
= BLOCKVECTOR (s
);
694 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
695 sym
= lookup_demangled_block_symbol (block
, name
);
697 error ("Internal: mangled static symbol `%s' found in %s psymtab but not in symtab", name
, ps
->filename
);
710 /* Look for a static demangled symbol in block BLOCK. */
712 static struct symbol
*
713 lookup_demangled_block_symbol (block
, name
)
714 register const struct block
*block
;
717 register int bot
, top
;
718 register struct symbol
*sym
;
722 top
= BLOCK_NSYMS (block
);
726 sym
= BLOCK_SYM (block
, bot
);
727 if (SYMBOL_NAMESPACE (sym
) == VAR_NAMESPACE
)
729 demangled
= demangle_and_match (SYMBOL_NAME (sym
), name
,
730 DMGL_PARAMS
| DMGL_ANSI
);
731 if (demangled
!= NULL
)
743 /* Look, in partial_symtab PST, for static mangled symbol NAME. */
745 static struct partial_symbol
*
746 lookup_demangled_partial_symbol (pst
, name
)
747 const struct partial_symtab
*pst
;
750 struct partial_symbol
*start
, *psym
;
751 int length
= pst
->n_static_syms
;
755 return (struct partial_symbol
*) 0;
757 start
= pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
;
758 for (psym
= start
; psym
< start
+ length
; psym
++)
760 if (SYMBOL_NAMESPACE (psym
) == VAR_NAMESPACE
)
762 demangled
= demangle_and_match (SYMBOL_NAME (psym
), name
,
763 DMGL_PARAMS
| DMGL_ANSI
);
764 if (demangled
!= NULL
)
775 /* Look, in partial_symtab PST, for symbol NAME. Check the global
776 symbols if GLOBAL, the static symbols if not */
778 static struct partial_symbol
*
779 lookup_partial_symbol (pst
, name
, global
, namespace)
780 struct partial_symtab
*pst
;
783 enum namespace namespace;
785 struct partial_symbol
*start
, *psym
;
786 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
789 return (struct partial_symbol
*) 0;
792 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
793 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
795 if (global
) /* This means we can use a binary */
798 struct partial_symbol
*top
, *bottom
, *center
;
800 /* Binary search. This search is guaranteed to end with center
801 pointing at the earliest partial symbol with the correct
802 name. At that point *all* partial symbols with that name
803 will be checked against the correct namespace. */
805 top
= start
+ length
- 1;
808 center
= bottom
+ (top
- bottom
) / 2;
810 assert (center
< top
);
812 if (strcmp (SYMBOL_NAME (center
), name
) >= 0)
817 assert (top
== bottom
);
819 while (!strcmp (SYMBOL_NAME (top
), name
))
821 if (SYMBOL_NAMESPACE (top
) == namespace)
828 /* Can't use a binary search */
829 for (psym
= start
; psym
< start
+ length
; psym
++)
830 if (namespace == SYMBOL_NAMESPACE (psym
)
831 && !strcmp (name
, SYMBOL_NAME (psym
)))
835 return (struct partial_symbol
*) 0;
838 /* Find the psymtab containing 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 /* Subroutine of find_pc_line */
968 register CORE_ADDR pc
;
970 register struct block
*b
;
971 struct blockvector
*bv
;
972 register struct symtab
*s
= 0;
973 register struct partial_symtab
*ps
;
974 register struct objfile
*objfile
;
976 /* Search all symtabs for one whose file contains our pc */
978 ALL_SYMTABS (objfile
, s
)
980 bv
= BLOCKVECTOR (s
);
981 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
982 if (BLOCK_START (b
) <= pc
983 && BLOCK_END (b
) > pc
)
989 ps
= find_pc_psymtab (pc
);
990 if (ps
&& ps
->readin
)
992 printf_filtered ("(Internal error: pc 0x%x in read in psymtab, but not in symtab.)\n", pc
);
996 s
= PSYMTAB_TO_SYMTAB (ps
);
1004 /* Find the source file and line number for a given PC value.
1005 Return a structure containing a symtab pointer, a line number,
1006 and a pc range for the entire source line.
1007 The value's .pc field is NOT the specified pc.
1008 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1009 use the line that ends there. Otherwise, in that case, the line
1010 that begins there is used. */
1012 struct symtab_and_line
1013 find_pc_line (pc
, notcurrent
)
1018 register struct linetable
*l
;
1021 register struct linetable_entry
*item
;
1022 struct symtab_and_line val
;
1023 struct blockvector
*bv
;
1025 /* Info on best line seen so far, and where it starts, and its file. */
1028 CORE_ADDR best_pc
= 0;
1029 CORE_ADDR best_end
= 0;
1030 struct symtab
*best_symtab
= 0;
1032 /* Store here the first line number
1033 of a file which contains the line at the smallest pc after PC.
1034 If we don't find a line whose range contains PC,
1035 we will use a line one less than this,
1036 with a range from the start of that file to the first line's pc. */
1038 CORE_ADDR alt_pc
= 0;
1039 struct symtab
*alt_symtab
= 0;
1041 /* Info on best line seen in this file. */
1046 /* Info on first line of this file. */
1051 /* If this pc is not from the current frame,
1052 it is the address of the end of a call instruction.
1053 Quite likely that is the start of the following statement.
1054 But what we want is the statement containing the instruction.
1055 Fudge the pc to make sure we get that. */
1057 if (notcurrent
) pc
-= 1;
1059 s
= find_pc_symtab (pc
);
1069 bv
= BLOCKVECTOR (s
);
1071 /* Look at all the symtabs that share this blockvector.
1072 They all have the same apriori range, that we found was right;
1073 but they have different line tables. */
1075 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1077 /* Find the best line in this symtab. */
1084 for (i
= 0; i
< len
; i
++)
1086 item
= &(l
->item
[i
]);
1090 first_line
= item
->line
;
1091 first_pc
= item
->pc
;
1093 /* Return the last line that did not start after PC. */
1096 prev_line
= item
->line
;
1103 /* Is this file's best line closer than the best in the other files?
1104 If so, record this file, and its best line, as best so far. */
1105 if (prev_line
>= 0 && prev_pc
> best_pc
)
1108 best_line
= prev_line
;
1110 /* If another line is in the linetable, and its PC is closer
1111 than the best_end we currently have, take it as best_end. */
1112 if (i
< len
&& (best_end
== 0 || best_end
> item
->pc
))
1113 best_end
= item
->pc
;
1115 /* Is this file's first line closer than the first lines of other files?
1116 If so, record this file, and its first line, as best alternate. */
1117 if (first_line
>= 0 && first_pc
> pc
1118 && (alt_pc
== 0 || first_pc
< alt_pc
))
1121 alt_line
= first_line
;
1125 if (best_symtab
== 0)
1127 val
.symtab
= alt_symtab
;
1128 val
.line
= alt_line
- 1;
1129 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1134 val
.symtab
= best_symtab
;
1135 val
.line
= best_line
;
1137 if (best_end
&& (alt_pc
== 0 || best_end
< alt_pc
))
1142 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1147 /* Find the PC value for a given source file and line number.
1148 Returns zero for invalid line number.
1149 The source file is specified with a struct symtab. */
1152 find_line_pc (symtab
, line
)
1153 struct symtab
*symtab
;
1156 register struct linetable
*l
;
1162 l
= LINETABLE (symtab
);
1163 ind
= find_line_common(l
, line
, &dummy
);
1164 return (ind
>= 0) ? l
->item
[ind
].pc
: 0;
1167 /* Find the range of pc values in a line.
1168 Store the starting pc of the line into *STARTPTR
1169 and the ending pc (start of next line) into *ENDPTR.
1170 Returns 1 to indicate success.
1171 Returns 0 if could not find the specified line. */
1174 find_line_pc_range (symtab
, thisline
, startptr
, endptr
)
1175 struct symtab
*symtab
;
1177 CORE_ADDR
*startptr
, *endptr
;
1179 register struct linetable
*l
;
1181 int exact_match
; /* did we get an exact linenumber match */
1186 l
= LINETABLE (symtab
);
1187 ind
= find_line_common (l
, thisline
, &exact_match
);
1190 *startptr
= l
->item
[ind
].pc
;
1191 /* If we have not seen an entry for the specified line,
1192 assume that means the specified line has zero bytes. */
1193 if (!exact_match
|| ind
== l
->nitems
-1)
1194 *endptr
= *startptr
;
1196 /* Perhaps the following entry is for the following line.
1197 It's worth a try. */
1198 if (ind
+1 < l
->nitems
1199 && l
->item
[ind
+1].line
== thisline
+ 1)
1200 *endptr
= l
->item
[ind
+1].pc
;
1202 *endptr
= find_line_pc (symtab
, thisline
+1);
1209 /* Given a line table and a line number, return the index into the line
1210 table for the pc of the nearest line whose number is >= the specified one.
1211 Return -1 if none is found. The value is >= 0 if it is an index.
1213 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1216 find_line_common (l
, lineno
, exact_match
)
1217 register struct linetable
*l
;
1218 register int lineno
;
1224 /* BEST is the smallest linenumber > LINENO so far seen,
1225 or 0 if none has been seen so far.
1226 BEST_INDEX identifies the item for it. */
1228 int best_index
= -1;
1237 for (i
= 0; i
< len
; i
++)
1239 register struct linetable_entry
*item
= &(l
->item
[i
]);
1241 if (item
->line
== lineno
)
1247 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
1254 /* If we got here, we didn't get an exact match. */
1261 find_pc_line_pc_range (pc
, startptr
, endptr
)
1263 CORE_ADDR
*startptr
, *endptr
;
1265 struct symtab_and_line sal
;
1266 sal
= find_pc_line (pc
, 0);
1269 return sal
.symtab
!= 0;
1272 /* If P is of the form "operator[ \t]+..." where `...' is
1273 some legitimate operator text, return a pointer to the
1274 beginning of the substring of the operator text.
1275 Otherwise, return "". */
1277 operator_chars (p
, end
)
1282 if (strncmp (p
, "operator", 8))
1286 /* Don't get faked out by `operator' being part of a longer
1288 if (isalpha(*p
) || *p
== '_' || *p
== '$' || *p
== '\0')
1291 /* Allow some whitespace between `operator' and the operator symbol. */
1292 while (*p
== ' ' || *p
== '\t')
1295 /* Recognize 'operator TYPENAME'. */
1297 if (isalpha(*p
) || *p
== '_' || *p
== '$')
1299 register char *q
= p
+1;
1300 while (isalnum(*q
) || *q
== '_' || *q
== '$')
1325 if (p
[1] == '=' || p
[1] == p
[0])
1336 error ("`operator ()' must be specified without whitespace in `()'");
1341 error ("`operator ?:' must be specified without whitespace in `?:'");
1346 error ("`operator []' must be specified without whitespace in `[]'");
1350 error ("`operator %s' not supported", p
);
1357 /* Recursive helper function for decode_line_1.
1358 * Look for methods named NAME in type T.
1359 * Return number of matches.
1360 * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1361 * These allocations seem to define "big enough":
1362 * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1363 * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1367 find_methods (t
, name
, physnames
, sym_arr
)
1371 struct symbol
**sym_arr
;
1375 struct symbol
*sym_class
;
1376 char *class_name
= type_name_no_tag (t
);
1377 /* Ignore this class if it doesn't have a name.
1378 This prevents core dumps, but is just a workaround
1379 because we might not find the function in
1380 certain cases, such as
1381 struct D {virtual int f();}
1382 struct C : D {virtual int g();}
1383 (in this case g++ 1.35.1- does not put out a name
1384 for D as such, it defines type 19 (for example) in
1385 the same stab as C, and then does a
1386 .stabs "D:T19" and a .stabs "D:t19".
1388 "break C::f" should not be looking for field f in
1390 but just for the field f in the baseclasses of C
1391 (no matter what their names).
1393 However, I don't know how to replace the code below
1394 that depends on knowing the name of D. */
1396 && (sym_class
= lookup_symbol (class_name
,
1397 (struct block
*)NULL
,
1400 (struct symtab
**)NULL
)))
1403 t
= SYMBOL_TYPE (sym_class
);
1404 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
1405 method_counter
>= 0;
1409 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
1411 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
1412 if (!strcmp (name
, method_name
))
1413 /* Find all the fields with that name. */
1414 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
1419 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
1420 check_stub_method (t
, method_counter
, field_counter
);
1421 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
1422 physnames
[i1
] = (char*) alloca (strlen (phys_name
) + 1);
1423 strcpy (physnames
[i1
], phys_name
);
1424 sym_arr
[i1
] = lookup_symbol (phys_name
,
1425 SYMBOL_BLOCK_VALUE (sym_class
),
1428 (struct symtab
**) NULL
);
1429 if (sym_arr
[i1
]) i1
++;
1432 fputs_filtered("(Cannot find method ", stdout
);
1433 fputs_demangled(phys_name
, stdout
, DMGL_PARAMS
);
1434 fputs_filtered(" - possibly inlined.)\n", stdout
);
1439 /* Only search baseclasses if there is no match yet,
1440 * since names in derived classes override those in baseclasses.
1444 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
1445 i1
+= find_methods(TYPE_BASECLASS(t
, ibase
), name
,
1446 physnames
+ i1
, sym_arr
+ i1
);
1450 /* Parse a string that specifies a line number.
1451 Pass the address of a char * variable; that variable will be
1452 advanced over the characters actually parsed.
1456 LINENUM -- that line number in current file. PC returned is 0.
1457 FILE:LINENUM -- that line in that file. PC returned is 0.
1458 FUNCTION -- line number of openbrace of that function.
1459 PC returned is the start of the function.
1460 VARIABLE -- line number of definition of that variable.
1462 FILE:FUNCTION -- likewise, but prefer functions in that file.
1463 *EXPR -- line in which address EXPR appears.
1465 FUNCTION may be an undebuggable function found in minimal symbol table.
1467 If the argument FUNFIRSTLINE is nonzero, we want the first line
1468 of real code inside a function when a function is specified.
1470 DEFAULT_SYMTAB specifies the file to use if none is specified.
1471 It defaults to current_source_symtab.
1472 DEFAULT_LINE specifies the line number to use for relative
1473 line numbers (that start with signs). Defaults to current_source_line.
1475 Note that it is possible to return zero for the symtab
1476 if no file is validly specified. Callers must check that.
1477 Also, the line number returned may be invalid. */
1479 struct symtabs_and_lines
1480 decode_line_1 (argptr
, funfirstline
, default_symtab
, default_line
)
1483 struct symtab
*default_symtab
;
1486 struct symtabs_and_lines values
;
1487 struct symtab_and_line val
;
1488 register char *p
, *p1
;
1490 register struct symtab
*s
;
1492 register struct symbol
*sym
;
1493 /* The symtab that SYM was found in. */
1494 struct symtab
*sym_symtab
;
1496 register CORE_ADDR pc
;
1497 register struct minimal_symbol
*msymbol
;
1499 struct symbol
*sym_class
;
1502 struct symbol
**sym_arr
;
1505 char *saved_arg
= *argptr
;
1506 extern char *gdb_completer_quote_characters
;
1508 /* Defaults have defaults. */
1510 if (default_symtab
== 0)
1512 default_symtab
= current_source_symtab
;
1513 default_line
= current_source_line
;
1516 /* See if arg is *PC */
1518 if (**argptr
== '*')
1520 if (**argptr
== '*')
1524 pc
= parse_and_eval_address_1 (argptr
);
1525 values
.sals
= (struct symtab_and_line
*)
1526 xmalloc (sizeof (struct symtab_and_line
));
1528 values
.sals
[0] = find_pc_line (pc
, 0);
1529 values
.sals
[0].pc
= pc
;
1533 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1536 is_quoted
= (strchr (gdb_completer_quote_characters
, **argptr
) != NULL
);
1538 for (p
= *argptr
; *p
; p
++)
1540 if (p
[0] == ':' || p
[0] == ' ' || p
[0] == '\t')
1543 while (p
[0] == ' ' || p
[0] == '\t') p
++;
1545 if ((p
[0] == ':') && !is_quoted
)
1551 /* Extract the class name. */
1553 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1554 copy
= (char *) alloca (p
- *argptr
+ 1);
1555 memcpy (copy
, *argptr
, p
- *argptr
);
1556 copy
[p
- *argptr
] = 0;
1558 /* Discard the class name from the arg. */
1560 while (*p
== ' ' || *p
== '\t') p
++;
1563 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
1564 (struct symtab
**)NULL
);
1567 ( TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_STRUCT
1568 || TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_UNION
))
1570 /* Arg token is not digits => try it as a function name
1571 Find the next token (everything up to end or next whitespace). */
1573 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',' && *p
!=':') p
++;
1574 q
= operator_chars (*argptr
, &q1
);
1579 char *tmp
= alloca (q1
- q
+ 1);
1580 memcpy (tmp
, q
, q1
- q
);
1582 opname
= cplus_mangle_opname (tmp
, DMGL_ANSI
);
1585 warning ("no mangling for \"%s\"", tmp
);
1586 cplusplus_hint (saved_arg
);
1587 return_to_top_level ();
1589 copy
= (char*) alloca (3 + strlen(opname
));
1590 sprintf (copy
, "__%s", opname
);
1595 copy
= (char *) alloca (p
- *argptr
+ 1 + (q1
- q
));
1596 memcpy (copy
, *argptr
, p
- *argptr
);
1597 copy
[p
- *argptr
] = '\0';
1600 /* no line number may be specified */
1601 while (*p
== ' ' || *p
== '\t') p
++;
1605 i1
= 0; /* counter for the symbol array */
1606 t
= SYMBOL_TYPE (sym_class
);
1607 sym_arr
= (struct symbol
**) alloca(TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(struct symbol
*));
1608 physnames
= (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(char*));
1610 if (destructor_name_p (copy
, t
))
1612 /* destructors are a special case. */
1613 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, 0);
1614 int len
= TYPE_FN_FIELDLIST_LENGTH (t
, 0) - 1;
1615 char *phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, len
);
1616 physnames
[i1
] = (char *)alloca (strlen (phys_name
) + 1);
1617 strcpy (physnames
[i1
], phys_name
);
1619 lookup_symbol (phys_name
, SYMBOL_BLOCK_VALUE (sym_class
),
1620 VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
1621 if (sym_arr
[i1
]) i1
++;
1624 i1
= find_methods (t
, copy
, physnames
, sym_arr
);
1627 /* There is exactly one field with that name. */
1630 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1632 /* Arg is the name of a function */
1633 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1636 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1638 values
.sals
[0] = find_pc_line (pc
, 0);
1639 values
.sals
[0].pc
= (values
.sals
[0].end
&& values
.sals
[0].pc
!= pc
) ? values
.sals
[0].end
: pc
;
1649 /* There is more than one field with that name
1650 (overloaded). Ask the user which one to use. */
1651 return decode_line_2 (sym_arr
, i1
, funfirstline
);
1657 if (OPNAME_PREFIX_P (copy
))
1659 tmp
= (char *)alloca (strlen (copy
+3) + 9);
1660 strcpy (tmp
, "operator ");
1661 strcat (tmp
, copy
+3);
1666 warning ("the class `%s' does not have destructor defined",
1669 warning ("the class %s does not have any method named %s",
1670 sym_class
->name
, tmp
);
1671 cplusplus_hint (saved_arg
);
1672 return_to_top_level ();
1677 /* The quotes are important if copy is empty. */
1678 warning ("can't find class, struct, or union named \"%s\"",
1680 cplusplus_hint (saved_arg
);
1681 return_to_top_level ();
1687 /* Extract the file name. */
1689 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1690 copy
= (char *) alloca (p
- *argptr
+ 1);
1691 memcpy (copy
, *argptr
, p
- *argptr
);
1692 copy
[p
- *argptr
] = 0;
1694 /* Find that file's data. */
1695 s
= lookup_symtab (copy
);
1698 if (!have_full_symbols () && !have_partial_symbols ())
1699 error (no_symtab_msg
);
1700 error ("No source file named %s.", copy
);
1703 /* Discard the file name from the arg. */
1705 while (*p
== ' ' || *p
== '\t') p
++;
1709 /* S is specified file's symtab, or 0 if no file specified.
1710 arg no longer contains the file name. */
1712 /* Check whether arg is all digits (and sign) */
1715 if (*p
== '-' || *p
== '+') p
++;
1716 while (*p
>= '0' && *p
<= '9')
1719 if (p
!= *argptr
&& (*p
== 0 || *p
== ' ' || *p
== '\t' || *p
== ','))
1721 /* We found a token consisting of all digits -- at least one digit. */
1722 enum sign
{none
, plus
, minus
} sign
= none
;
1724 /* This is where we need to make sure that we have good defaults.
1725 We must guarantee that this section of code is never executed
1726 when we are called with just a function name, since
1727 select_source_symtab calls us with such an argument */
1729 if (s
== 0 && default_symtab
== 0)
1731 select_source_symtab (0);
1732 default_symtab
= current_source_symtab
;
1733 default_line
= current_source_line
;
1736 if (**argptr
== '+')
1737 sign
= plus
, (*argptr
)++;
1738 else if (**argptr
== '-')
1739 sign
= minus
, (*argptr
)++;
1740 val
.line
= atoi (*argptr
);
1747 val
.line
= default_line
+ val
.line
;
1753 val
.line
= default_line
- val
.line
;
1758 break; /* No need to adjust val.line. */
1761 while (*p
== ' ' || *p
== '\t') p
++;
1767 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1768 values
.sals
[0] = val
;
1773 /* Arg token is not digits => try it as a variable name
1774 Find the next token (everything up to end or next whitespace). */
1776 p
= skip_quoted (*argptr
);
1777 copy
= (char *) alloca (p
- *argptr
+ 1);
1778 memcpy (copy
, *argptr
, p
- *argptr
);
1779 copy
[p
- *argptr
] = '\0';
1780 if ((copy
[0] == copy
[p
- *argptr
- 1])
1781 && strchr (gdb_completer_quote_characters
, copy
[0]) != NULL
)
1784 copy
[p
- *argptr
- 1] = '\0';
1786 if ((temp
= expensive_mangler (copy
)) != NULL
)
1791 while (*p
== ' ' || *p
== '\t') p
++;
1794 /* Look up that token as a variable.
1795 If file specified, use that file's per-file block to start with. */
1797 sym
= lookup_symbol (copy
,
1798 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
1799 : get_selected_block ()),
1800 VAR_NAMESPACE
, 0, &sym_symtab
);
1804 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1806 /* Arg is the name of a function */
1807 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1810 val
= find_pc_line (pc
, 0);
1811 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1812 /* Convex: no need to suppress code on first line, if any */
1815 /* If SKIP_PROLOGUE left us in mid-line, and the next line is still
1816 part of the same function:
1817 advance to next line,
1818 recalculate its line number (might not be N+1). */
1819 if (val
.pc
!= pc
&& val
.end
&&
1820 lookup_minimal_symbol_by_pc (pc
) == lookup_minimal_symbol_by_pc (val
.end
)) {
1821 pc
= val
.end
; /* First pc of next line */
1822 val
= find_pc_line (pc
, 0);
1826 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1827 values
.sals
[0] = val
;
1830 /* I think this is always the same as the line that
1831 we calculate above, but the general principle is
1832 "trust the symbols more than stuff like
1834 if (SYMBOL_LINE (sym
) != 0)
1835 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1839 else if (SYMBOL_LINE (sym
) != 0)
1841 /* We know its line number. */
1842 values
.sals
= (struct symtab_and_line
*)
1843 xmalloc (sizeof (struct symtab_and_line
));
1845 memset (&values
.sals
[0], 0, sizeof (values
.sals
[0]));
1846 values
.sals
[0].symtab
= sym_symtab
;
1847 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1851 /* This can happen if it is compiled with a compiler which doesn't
1852 put out line numbers for variables. */
1853 error ("Line number not known for symbol \"%s\"", copy
);
1856 msymbol
= lookup_minimal_symbol (copy
, (struct objfile
*) NULL
);
1857 if (msymbol
!= NULL
)
1861 val
.pc
= msymbol
-> address
+ FUNCTION_START_OFFSET
;
1863 SKIP_PROLOGUE (val
.pc
);
1864 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1865 values
.sals
[0] = val
;
1870 if (!have_full_symbols () &&
1871 !have_partial_symbols () && !have_minimal_symbols ())
1872 error (no_symtab_msg
);
1874 error ("Function \"%s\" not defined.", copy
);
1875 return values
; /* for lint */
1878 struct symtabs_and_lines
1879 decode_line_spec (string
, funfirstline
)
1883 struct symtabs_and_lines sals
;
1885 error ("Empty line specification.");
1886 sals
= decode_line_1 (&string
, funfirstline
,
1887 current_source_symtab
, current_source_line
);
1889 error ("Junk at end of line specification: %s", string
);
1893 /* Given a list of NELTS symbols in sym_arr (with corresponding
1894 mangled names in physnames), return a list of lines to operate on
1895 (ask user if necessary). */
1896 static struct symtabs_and_lines
1897 decode_line_2 (sym_arr
, nelts
, funfirstline
)
1898 struct symbol
*sym_arr
[];
1902 struct symtabs_and_lines values
, return_values
;
1903 register CORE_ADDR pc
;
1909 values
.sals
= (struct symtab_and_line
*) alloca (nelts
* sizeof(struct symtab_and_line
));
1910 return_values
.sals
= (struct symtab_and_line
*) xmalloc (nelts
* sizeof(struct symtab_and_line
));
1913 printf("[0] cancel\n[1] all\n");
1916 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
1918 /* Arg is the name of a function */
1919 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr
[i
]))
1920 + FUNCTION_START_OFFSET
;
1923 values
.sals
[i
] = find_pc_line (pc
, 0);
1924 values
.sals
[i
].pc
= (values
.sals
[i
].end
&& values
.sals
[i
].pc
!= pc
) ?
1925 values
.sals
[i
].end
: pc
;
1926 demangled
= cplus_demangle (SYMBOL_NAME (sym_arr
[i
]),
1927 DMGL_PARAMS
| DMGL_ANSI
);
1928 printf("[%d] %s at %s:%d\n", (i
+2),
1929 demangled
? demangled
: SYMBOL_NAME (sym_arr
[i
]),
1930 values
.sals
[i
].symtab
->filename
, values
.sals
[i
].line
);
1931 if (demangled
!= NULL
)
1936 else printf ("?HERE\n");
1940 if ((prompt
= getenv ("PS2")) == NULL
)
1944 printf("%s ",prompt
);
1947 args
= command_line_input ((char *) NULL
, 0);
1950 error_no_arg ("one or more choice numbers");
1958 while (*arg1
>= '0' && *arg1
<= '9') arg1
++;
1959 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
1960 error ("Arguments must be choice numbers.");
1965 error ("cancelled");
1968 memcpy (return_values
.sals
, values
.sals
,
1969 (nelts
* sizeof(struct symtab_and_line
)));
1970 return_values
.nelts
= nelts
;
1971 return return_values
;
1974 if (num
> nelts
+ 2)
1976 printf ("No choice number %d.\n", num
);
1981 if (values
.sals
[num
].pc
)
1983 return_values
.sals
[i
++] = values
.sals
[num
];
1984 values
.sals
[num
].pc
= 0;
1988 printf ("duplicate request for %d ignored.\n", num
);
1993 while (*args
== ' ' || *args
== '\t') args
++;
1995 return_values
.nelts
= i
;
1996 return return_values
;
2000 /* Slave routine for sources_info. Force line breaks at ,'s.
2001 NAME is the name to print and *FIRST is nonzero if this is the first
2002 name printed. Set *FIRST to zero. */
2004 output_source_filename (name
, first
)
2008 /* Table of files printed so far. Since a single source file can
2009 result in several partial symbol tables, we need to avoid printing
2010 it more than once. Note: if some of the psymtabs are read in and
2011 some are not, it gets printed both under "Source files for which
2012 symbols have been read" and "Source files for which symbols will
2013 be read in on demand". I consider this a reasonable way to deal
2014 with the situation. I'm not sure whether this can also happen for
2015 symtabs; it doesn't hurt to check. */
2016 static char **tab
= NULL
;
2017 /* Allocated size of tab in elements.
2018 Start with one 256-byte block (when using GNU malloc.c).
2019 24 is the malloc overhead when range checking is in effect. */
2020 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
2021 /* Current size of tab in elements. */
2022 static int tab_cur_size
;
2029 tab
= (char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
2033 /* Is NAME in tab? */
2034 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
2035 if (strcmp (*p
, name
) == 0)
2036 /* Yes; don't print it again. */
2038 /* No; add it to tab. */
2039 if (tab_cur_size
== tab_alloc_size
)
2041 tab_alloc_size
*= 2;
2042 tab
= (char **) xrealloc ((char *) tab
, tab_alloc_size
* sizeof (*tab
));
2044 tab
[tab_cur_size
++] = name
;
2052 printf_filtered (", ");
2056 fputs_filtered (name
, stdout
);
2060 sources_info (ignore
, from_tty
)
2064 register struct symtab
*s
;
2065 register struct partial_symtab
*ps
;
2066 register struct objfile
*objfile
;
2069 if (!have_full_symbols () && !have_partial_symbols ())
2071 error (no_symtab_msg
);
2074 printf_filtered ("Source files for which symbols have been read in:\n\n");
2077 ALL_SYMTABS (objfile
, s
)
2079 output_source_filename (s
-> filename
, &first
);
2081 printf_filtered ("\n\n");
2083 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2086 ALL_PSYMTABS (objfile
, ps
)
2090 output_source_filename (ps
-> filename
, &first
);
2093 printf_filtered ("\n");
2100 char *demangled
= cplus_demangle (name
, DMGL_ANSI
);
2101 if (demangled
!= NULL
)
2103 int cond
= re_exec (demangled
);
2107 return (re_exec (name
));
2109 #define NAME_MATCH(NAME) name_match(NAME)
2111 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2112 If CLASS is zero, list all symbols except functions, type names, and
2114 If CLASS is 1, list only functions.
2115 If CLASS is 2, list only type names.
2116 If CLASS is 3, list only method names.
2118 BPT is non-zero if we should set a breakpoint at the functions
2122 list_symbols (regexp
, class, bpt
)
2127 register struct symtab
*s
;
2128 register struct partial_symtab
*ps
;
2129 register struct blockvector
*bv
;
2130 struct blockvector
*prev_bv
= 0;
2131 register struct block
*b
;
2133 register struct symbol
*sym
;
2134 struct partial_symbol
*psym
;
2135 struct objfile
*objfile
;
2136 struct minimal_symbol
*msymbol
;
2138 static char *classnames
[]
2139 = {"variable", "function", "type", "method"};
2140 int found_in_file
= 0;
2142 static enum minimal_symbol_type types
[]
2143 = {mst_data
, mst_text
, mst_abs
, mst_unknown
};
2144 static enum minimal_symbol_type types2
[]
2145 = {mst_bss
, mst_text
, mst_abs
, mst_unknown
};
2146 enum minimal_symbol_type ourtype
= types
[class];
2147 enum minimal_symbol_type ourtype2
= types2
[class];
2151 /* Make sure spacing is right for C++ operators.
2152 This is just a courtesy to make the matching less sensitive
2153 to how many spaces the user leaves between 'operator'
2154 and <TYPENAME> or <OPERATOR>. */
2156 char *opname
= operator_chars (regexp
, &opend
);
2159 int fix
= -1; /* -1 means ok; otherwise number of spaces needed. */
2160 if (isalpha(*opname
) || *opname
== '_' || *opname
== '$')
2162 /* There should 1 space between 'operator' and 'TYPENAME'. */
2163 if (opname
[-1] != ' ' || opname
[-2] == ' ')
2168 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2169 if (opname
[-1] == ' ')
2172 /* If wrong number of spaces, fix it. */
2175 char *tmp
= (char*) alloca(opend
-opname
+10);
2176 sprintf(tmp
, "operator%.*s%s", fix
, " ", opname
);
2181 if (0 != (val
= re_comp (regexp
)))
2182 error ("Invalid regexp (%s): %s", val
, regexp
);
2185 /* Search through the partial symtabs *first* for all symbols
2186 matching the regexp. That way we don't have to reproduce all of
2187 the machinery below. */
2189 ALL_PSYMTABS (objfile
, ps
)
2191 struct partial_symbol
*bound
, *gbound
, *sbound
;
2194 if (ps
->readin
) continue;
2196 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2197 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2200 /* Go through all of the symbols stored in a partial
2201 symtab in one loop. */
2202 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2207 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2209 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2220 /* If it would match (logic taken from loop below)
2221 load the file and go on to the next one */
2222 if ((regexp
== 0 || NAME_MATCH (SYMBOL_NAME (psym
)))
2223 && ((class == 0 && SYMBOL_CLASS (psym
) != LOC_TYPEDEF
2224 && SYMBOL_CLASS (psym
) != LOC_BLOCK
)
2225 || (class == 1 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)
2226 || (class == 2 && SYMBOL_CLASS (psym
) == LOC_TYPEDEF
)
2227 || (class == 3 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)))
2229 PSYMTAB_TO_SYMTAB(ps
);
2237 /* Here, we search through the minimal symbol tables for functions that
2238 match, and call find_pc_symtab on them to force their symbols to
2239 be read. The symbol will then be found during the scan of symtabs
2240 below. If find_pc_symtab fails, set found_misc so that we will
2241 rescan to print any matching symbols without debug info. */
2245 ALL_MSYMBOLS (objfile
, msymbol
)
2247 if (msymbol
-> type
== ourtype
|| msymbol
-> type
== ourtype2
)
2249 if (regexp
== 0 || NAME_MATCH (msymbol
-> name
))
2251 if (0 == find_pc_symtab (msymbol
-> address
))
2260 /* Printout here so as to get after the "Reading in symbols"
2261 messages which will be generated above. */
2263 printf_filtered (regexp
2264 ? "All %ss matching regular expression \"%s\":\n"
2265 : "All defined %ss:\n",
2269 ALL_SYMTABS (objfile
, s
)
2272 bv
= BLOCKVECTOR (s
);
2273 /* Often many files share a blockvector.
2274 Scan each blockvector only once so that
2275 we don't get every symbol many times.
2276 It happens that the first symtab in the list
2277 for any given blockvector is the main file. */
2279 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
2281 b
= BLOCKVECTOR_BLOCK (bv
, i
);
2282 /* Skip the sort if this block is always sorted. */
2283 if (!BLOCK_SHOULD_SORT (b
))
2284 sort_block_syms (b
);
2285 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
2288 sym
= BLOCK_SYM (b
, j
);
2289 if ((regexp
== 0 || NAME_MATCH (SYMBOL_NAME (sym
)))
2290 && ((class == 0 && SYMBOL_CLASS (sym
) != LOC_TYPEDEF
2291 && SYMBOL_CLASS (sym
) != LOC_BLOCK
2292 && SYMBOL_CLASS (sym
) != LOC_CONST
)
2293 || (class == 1 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2294 || (class == 2 && SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2295 || (class == 3 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)))
2299 /* Set a breakpoint here, if it's a function */
2301 break_command (SYMBOL_NAME(sym
), 0);
2303 else if (!found_in_file
)
2305 fputs_filtered ("\nFile ", stdout
);
2306 fputs_filtered (s
->filename
, stdout
);
2307 fputs_filtered (":\n", stdout
);
2311 if (class != 2 && i
== STATIC_BLOCK
)
2312 printf_filtered ("static ");
2314 /* Typedef that is not a C++ class */
2316 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
2317 typedef_print (SYMBOL_TYPE(sym
), sym
, stdout
);
2318 /* variable, func, or typedef-that-is-c++-class */
2319 else if (class < 2 ||
2321 SYMBOL_NAMESPACE(sym
) == STRUCT_NAMESPACE
))
2323 type_print (SYMBOL_TYPE (sym
),
2324 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2325 ? "" : SYMBOL_NAME (sym
)),
2328 printf_filtered (";\n");
2333 /* FIXME, why is this zapped out? */
2335 type_print_base (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0, 0);
2336 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0);
2337 sprintf (buf
, " %s::", type_name_no_tag (t
));
2338 type_print_method_args (TYPE_FN_FIELD_ARGS (t
, i
), buf
, name
, stdout
);
2347 /* If there are no eyes, avoid all contact. I mean, if there are
2348 no debug symbols, then print directly from the msymbol_vector. */
2350 if (found_misc
|| class != 1)
2353 ALL_MSYMBOLS (objfile
, msymbol
)
2355 if (msymbol
-> type
== ourtype
|| msymbol
-> type
== ourtype2
)
2357 if (regexp
== 0 || NAME_MATCH (msymbol
-> name
))
2359 /* Functions: Look up by address. */
2361 (0 == find_pc_symtab (msymbol
-> address
)))
2363 /* Variables/Absolutes: Look up by name */
2364 if (lookup_symbol (msymbol
-> name
,
2365 (struct block
*) 0, VAR_NAMESPACE
, 0,
2366 (struct symtab
**) 0) == NULL
)
2370 printf_filtered ("\nNon-debugging symbols:\n");
2373 printf_filtered (" %08x %s\n",
2385 variables_info (regexp
, from_tty
)
2389 list_symbols (regexp
, 0, 0);
2393 functions_info (regexp
, from_tty
)
2397 list_symbols (regexp
, 1, 0);
2401 types_info (regexp
, from_tty
)
2405 list_symbols (regexp
, 2, 0);
2409 /* Tiemann says: "info methods was never implemented." */
2411 methods_info (regexp
)
2414 list_symbols (regexp
, 3, 0);
2418 /* Breakpoint all functions matching regular expression. */
2420 rbreak_command (regexp
, from_tty
)
2424 list_symbols (regexp
, 1, 1);
2428 /* Return Nonzero if block a is lexically nested within block b,
2429 or if a and b have the same pc range.
2430 Return zero otherwise. */
2433 struct block
*a
, *b
;
2437 return BLOCK_START (a
) >= BLOCK_START (b
)
2438 && BLOCK_END (a
) <= BLOCK_END (b
);
2442 /* Helper routine for make_symbol_completion_list. */
2444 static int return_val_size
;
2445 static int return_val_index
;
2446 static char **return_val
;
2448 /* Test to see if the symbol specified by SYMNAME (or it's demangled
2449 equivalent) matches TEXT in the first TEXT_LEN characters. If so,
2450 add it to the current completion list. */
2453 completion_list_add_symbol (symname
, text
, text_len
)
2462 /* clip symbols that cannot match */
2464 if (!cplus_match (symname
, text
, text_len
)) {
2468 /* matches mangled, may match unmangled. now clip any symbol names
2469 that we've already considered. (This is a time optimization) */
2471 for (i
= 0; i
< return_val_index
; ++i
) {
2472 if (strcmp (symname
, return_val
[i
]) == 0) {
2477 /* See if SYMNAME is a C++ mangled name, and if so, use the
2478 demangled name instead, including any parameters. */
2480 if ((demangled
= cplus_demangle (symname
, DMGL_PARAMS
| DMGL_ANSI
)) != NULL
)
2482 if (strncmp (demangled
, text
, text_len
) != 0) {
2484 } /* demangled, but didn't match so clip it */
2486 symname
= demangled
;
2488 symname
= savestring (symname
, strlen (symname
));
2491 /* If we have a match for a completion, then add SYMNAME to the current
2492 list of matches. Note that the name is in freshly malloc'd space;
2493 either from cplus_demangle or from savestring above. */
2495 if (return_val_index
+ 3 > return_val_size
)
2497 newsize
= (return_val_size
*= 2) * sizeof (char *);
2498 return_val
= (char **) xrealloc ((char *) return_val
, newsize
);
2500 return_val
[return_val_index
++] = symname
;
2501 return_val
[return_val_index
] = NULL
;
2506 /* Return a NULL terminated array of all symbols (regardless of class) which
2507 begin by matching TEXT. If the answer is no symbols, then the return value
2508 is an array which contains only a NULL pointer.
2510 Problem: All of the symbols have to be copied because readline frees them.
2511 I'm not going to worry about this; hopefully there won't be that many. */
2514 make_symbol_completion_list (text
)
2517 register struct symbol
*sym
;
2518 register struct symtab
*s
;
2519 register struct partial_symtab
*ps
;
2520 register struct minimal_symbol
*msymbol
;
2521 register struct objfile
*objfile
;
2522 register struct block
*b
, *surrounding_static_block
= 0;
2525 struct partial_symbol
*psym
;
2527 text_len
= strlen (text
);
2528 return_val_size
= 100;
2529 return_val_index
= 0;
2530 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
2531 return_val
[0] = NULL
;
2533 /* Look through the partial symtabs for all symbols which begin
2534 by matching TEXT. Add each one that you find to the list. */
2536 ALL_PSYMTABS (objfile
, ps
)
2538 /* If the psymtab's been read in we'll get it when we search
2539 through the blockvector. */
2540 if (ps
->readin
) continue;
2542 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2543 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
2544 + ps
->n_global_syms
);
2547 /* If interrupted, then quit. */
2549 completion_list_add_symbol (SYMBOL_NAME (psym
), text
, text_len
);
2552 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2553 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
2554 + ps
->n_static_syms
);
2558 completion_list_add_symbol (SYMBOL_NAME (psym
), text
, text_len
);
2562 /* At this point scan through the misc symbol vectors and add each
2563 symbol you find to the list. Eventually we want to ignore
2564 anything that isn't a text symbol (everything else will be
2565 handled by the psymtab code above). */
2567 ALL_MSYMBOLS (objfile
, msymbol
)
2570 completion_list_add_symbol (msymbol
-> name
, text
, text_len
);
2573 /* Search upwards from currently selected frame (so that we can
2574 complete on local vars. */
2576 for (b
= get_selected_block (); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
2578 if (!BLOCK_SUPERBLOCK (b
))
2580 surrounding_static_block
= b
; /* For elmin of dups */
2583 /* Also catch fields of types defined in this places which match our
2584 text string. Only complete on types visible from current context. */
2586 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2588 sym
= BLOCK_SYM (b
, i
);
2589 completion_list_add_symbol (SYMBOL_NAME (sym
), text
, text_len
);
2590 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2592 struct type
*t
= SYMBOL_TYPE (sym
);
2593 enum type_code c
= TYPE_CODE (t
);
2595 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
2597 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
2599 if (TYPE_FIELD_NAME (t
, j
))
2601 completion_list_add_symbol (TYPE_FIELD_NAME (t
, j
),
2610 /* Go through the symtabs and check the externs and statics for
2611 symbols which match. */
2613 ALL_SYMTABS (objfile
, s
)
2616 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
2617 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2619 sym
= BLOCK_SYM (b
, i
);
2620 completion_list_add_symbol (SYMBOL_NAME (sym
), text
, text_len
);
2624 ALL_SYMTABS (objfile
, s
)
2627 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
2628 /* Don't do this block twice. */
2629 if (b
== surrounding_static_block
) continue;
2630 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2632 sym
= BLOCK_SYM (b
, i
);
2633 completion_list_add_symbol (SYMBOL_NAME (sym
), text
, text_len
);
2637 return (return_val
);
2641 /* Find a mangled symbol that corresponds to LOOKFOR using brute force.
2642 Basically we go munging through available symbols, demangling each one,
2643 looking for a match on the demangled result. */
2646 expensive_mangler (lookfor
)
2647 const char *lookfor
;
2649 register struct symbol
*sym
;
2650 register struct symtab
*s
;
2651 register struct partial_symtab
*ps
;
2652 register struct minimal_symbol
*msymbol
;
2653 register struct objfile
*objfile
;
2654 register struct block
*b
, *surrounding_static_block
= 0;
2656 struct partial_symbol
*psym
;
2659 /* Look through the partial symtabs for a symbol that matches */
2661 ALL_PSYMTABS (objfile
, ps
)
2663 /* If the psymtab's been read in we'll get it when we search
2664 through the blockvector. */
2665 if (ps
->readin
) continue;
2667 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2668 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
2669 + ps
->n_global_syms
);
2672 QUIT
; /* If interrupted, then quit. */
2673 demangled
= demangle_and_match (SYMBOL_NAME (psym
), lookfor
,
2674 DMGL_PARAMS
| DMGL_ANSI
);
2675 if (demangled
!= NULL
)
2678 return (SYMBOL_NAME (psym
));
2682 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2683 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
2684 + ps
->n_static_syms
);
2688 demangled
= demangle_and_match (SYMBOL_NAME (psym
), lookfor
,
2689 DMGL_PARAMS
| DMGL_ANSI
);
2690 if (demangled
!= NULL
)
2693 return (SYMBOL_NAME (psym
));
2698 /* Scan through the misc symbol vectors looking for a match. */
2700 ALL_MSYMBOLS (objfile
, msymbol
)
2703 demangled
= demangle_and_match (msymbol
-> name
, lookfor
,
2704 DMGL_PARAMS
| DMGL_ANSI
);
2705 if (demangled
!= NULL
)
2708 return (msymbol
-> name
);
2712 /* Search upwards from currently selected frame looking for a match */
2714 for (b
= get_selected_block (); b
; b
= BLOCK_SUPERBLOCK (b
))
2716 if (!BLOCK_SUPERBLOCK (b
))
2717 surrounding_static_block
= b
; /* For elmin of dups */
2719 /* Also catch fields of types defined in this places which
2720 match our text string. Only complete on types visible
2721 from current context. */
2722 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2724 sym
= BLOCK_SYM (b
, i
);
2725 demangled
= demangle_and_match (SYMBOL_NAME (sym
), lookfor
,
2726 DMGL_PARAMS
| DMGL_ANSI
);
2727 if (demangled
!= NULL
)
2730 return (SYMBOL_NAME (sym
));
2732 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2734 struct type
*t
= SYMBOL_TYPE (sym
);
2735 enum type_code c
= TYPE_CODE (t
);
2737 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
2739 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
2741 if (TYPE_FIELD_NAME (t
, j
))
2744 demangle_and_match (TYPE_FIELD_NAME (t
, j
),
2746 DMGL_PARAMS
| DMGL_ANSI
);
2747 if (demangled
!= NULL
)
2750 return (TYPE_FIELD_NAME (t
, j
));
2759 /* Go through the symtabs and check the externs and statics for
2760 symbols which match. */
2762 ALL_SYMTABS (objfile
, s
)
2765 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
2766 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2768 sym
= BLOCK_SYM (b
, i
);
2769 demangled
= demangle_and_match (SYMBOL_NAME (sym
), lookfor
,
2770 DMGL_PARAMS
| DMGL_ANSI
);
2771 if (demangled
!= NULL
)
2774 return (SYMBOL_NAME (sym
));
2779 ALL_SYMTABS (objfile
, s
)
2782 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
2783 /* Don't do this block twice. */
2784 if (b
== surrounding_static_block
) continue;
2785 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2787 sym
= BLOCK_SYM (b
, i
);
2788 demangled
= demangle_and_match (SYMBOL_NAME (sym
), lookfor
,
2789 DMGL_PARAMS
| DMGL_ANSI
);
2790 if (demangled
!= NULL
)
2793 return (SYMBOL_NAME (sym
));
2803 /* Add the type of the symbol sym to the type of the current
2804 function whose block we are in (assumed). The type of
2805 this current function is contained in *TYPE.
2807 This basically works as follows: When we find a function
2808 symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record
2809 a pointer to its type in the global in_function_type. Every
2810 time we come across a parameter symbol ('p' in its name), then
2811 this procedure adds the name and type of that parameter
2812 to the function type pointed to by *TYPE. (Which should correspond
2813 to in_function_type if it was called correctly).
2815 Note that since we are modifying a type, the result of
2816 lookup_function_type() should be memcpy()ed before calling
2817 this. When not in strict typing mode, the expression
2818 evaluator can choose to ignore this.
2820 Assumption: All of a function's parameter symbols will
2821 appear before another function symbol is found. The parameters
2822 appear in the same order in the argument list as they do in the
2826 add_param_to_type (type
,sym
)
2830 int num
= ++(TYPE_NFIELDS(*type
));
2832 if(TYPE_NFIELDS(*type
)-1)
2833 TYPE_FIELDS(*type
) = (struct field
*)
2834 (*current_objfile
->xrealloc
) ((char *)(TYPE_FIELDS(*type
)),
2835 num
*sizeof(struct field
));
2837 TYPE_FIELDS(*type
) = (struct field
*)
2838 (*current_objfile
->xmalloc
) (num
*sizeof(struct field
));
2840 TYPE_FIELD_BITPOS(*type
,num
-1) = num
-1;
2841 TYPE_FIELD_BITSIZE(*type
,num
-1) = 0;
2842 TYPE_FIELD_TYPE(*type
,num
-1) = SYMBOL_TYPE(sym
);
2843 TYPE_FIELD_NAME(*type
,num
-1) = SYMBOL_NAME(sym
);
2848 _initialize_symtab ()
2850 add_info ("variables", variables_info
,
2851 "All global and static variable names, or those matching REGEXP.");
2852 add_info ("functions", functions_info
,
2853 "All function names, or those matching REGEXP.");
2855 /* FIXME: This command has at least the following problems:
2856 1. It prints builtin types (in a very strange and confusing fashion).
2857 2. It doesn't print right, e.g. with
2858 typedef struct foo *FOO
2859 type_print prints "FOO" when we want to make it (in this situation)
2860 print "struct foo *".
2861 I also think "ptype" or "whatis" is more likely to be useful (but if
2862 there is much disagreement "info types" can be fixed). */
2863 add_info ("types", types_info
,
2864 "All type names, or those matching REGEXP.");
2867 add_info ("methods", methods_info
,
2868 "All method names, or those matching REGEXP::REGEXP.\n\
2869 If the class qualifier is omitted, it is assumed to be the current scope.\n\
2870 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
2873 add_info ("sources", sources_info
,
2874 "Source files in the program.");
2876 add_com ("rbreak", no_class
, rbreak_command
,
2877 "Set a breakpoint for all functions matching REGEXP.");
2879 /* Initialize the one built-in type that isn't language dependent... */
2880 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
2881 "<unknown type>", (struct objfile
*) NULL
);