1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
31 #include "expression.h"
37 #include <sys/types.h>
42 /* Prototypes for local functions */
45 find_methods
PARAMS ((struct type
*, char *, char **, struct symbol
**));
48 completion_list_add_symbol
PARAMS ((char *));
50 static struct symtabs_and_lines
51 decode_line_2
PARAMS ((struct symbol
*[], int, int));
54 rbreak_command
PARAMS ((char *));
57 types_info
PARAMS ((char *));
60 functions_info
PARAMS ((char *));
63 variables_info
PARAMS ((char *));
66 list_symbols
PARAMS ((char *, int, int));
69 sources_info
PARAMS ((void));
72 output_source_filename
PARAMS ((char *, int *));
75 operator_chars
PARAMS ((char *, char **));
78 find_line_common
PARAMS ((struct linetable
*, int, int *));
80 static struct partial_symbol
*
81 lookup_partial_symbol
PARAMS ((struct partial_symtab
*, const char *,
82 int, enum namespace));
84 static struct partial_symbol
*
85 lookup_demangled_partial_symbol
PARAMS ((const struct partial_symtab
*,
88 static struct symbol
*
89 lookup_demangled_block_symbol
PARAMS ((const struct block
*, const char *));
91 static struct symtab
*
92 lookup_symtab_1
PARAMS ((char *));
96 /* The single non-language-specific builtin type */
97 struct type
*builtin_type_error
;
99 /* Block in which the most recently searched-for symbol was found.
100 Might be better to make this a parameter to lookup_symbol and
103 const struct block
*block_found
;
105 char no_symtab_msg
[] = "No symbol table is loaded. Use the \"file\" command.";
107 /* Check for a symtab of a specific name; first in symtabs, then in
108 psymtabs. *If* there is no '/' in the name, a match after a '/'
109 in the symtab filename will also work. */
111 static struct symtab
*
112 lookup_symtab_1 (name
)
115 register struct symtab
*s
;
116 register struct partial_symtab
*ps
;
117 register char *slash
= strchr (name
, '/');
118 register int len
= strlen (name
);
119 register struct objfile
*objfile
;
122 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
124 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
126 if (strcmp (name
, s
->filename
) == 0)
132 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
134 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
->next
)
136 if (strcmp (name
, ps
-> filename
) == 0)
140 error ("Internal: readin pst for `%s' found when no symtab found.", name
);
142 return (PSYMTAB_TO_SYMTAB (ps
));
148 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
150 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
152 int l
= strlen (s
->filename
);
154 if (s
->filename
[l
- len
-1] == '/'
155 && (strcmp (s
->filename
+ l
- len
, name
) == 0))
162 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
164 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
166 int l
= strlen (ps
-> filename
);
168 if (ps
-> filename
[l
- len
- 1] == '/'
169 && (strcmp (ps
->filename
+ l
- len
, name
) == 0))
173 error ("Internal: readin pst for `%s' found when no symtab found.", name
);
175 return (PSYMTAB_TO_SYMTAB (ps
));
183 /* Lookup the symbol table of a source file named NAME. Try a couple
184 of variations if the first lookup doesn't work. */
190 register struct symtab
*s
;
193 s
= lookup_symtab_1 (name
);
196 /* If name not found as specified, see if adding ".c" helps. */
198 copy
= (char *) alloca (strlen (name
) + 3);
201 s
= lookup_symtab_1 (copy
);
204 /* We didn't find anything; die. */
208 /* Lookup the partial symbol table of a source file named NAME. This
209 only returns true on an exact match (ie. this semantics are
210 different from lookup_symtab. */
212 struct partial_symtab
*
213 lookup_partial_symtab (name
)
216 register struct partial_symtab
*pst
;
217 register struct objfile
*objfile
;
219 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
221 for (pst
= objfile
-> psymtabs
; pst
!= NULL
; pst
= pst
-> next
)
223 if (strcmp (name
, pst
-> filename
) == 0)
232 /* Demangle a GDB method stub type. */
234 gdb_mangle_name (type
, i
, j
)
238 int mangled_name_len
;
240 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
241 struct fn_field
*method
= &f
[j
];
242 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
243 int is_constructor
= strcmp(field_name
, TYPE_NAME (type
)) == 0;
245 /* Need a new type prefix. */
246 char *const_prefix
= method
->is_const
? "C" : "";
247 char *volatile_prefix
= method
->is_volatile
? "V" : "";
248 char *newname
= type_name_no_tag (type
);
250 int len
= strlen (newname
);
252 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
253 mangled_name_len
= ((is_constructor
? 0 : strlen (field_name
))
255 + strlen (TYPE_FN_FIELD_PHYSNAME (f
, j
))
258 /* Only needed for GNU-mangled names. ANSI-mangled names
259 work with the normal mechanisms. */
260 if (OPNAME_PREFIX_P (field_name
))
262 char *opname
= cplus_mangle_opname (field_name
+ 3, 0);
264 error ("No mangling for \"%s\"", field_name
);
265 mangled_name_len
+= strlen (opname
);
266 mangled_name
= (char *)xmalloc (mangled_name_len
);
268 strncpy (mangled_name
, field_name
, 3);
269 mangled_name
[3] = '\0';
270 strcat (mangled_name
, opname
);
274 mangled_name
= (char *)xmalloc (mangled_name_len
);
276 mangled_name
[0] = '\0';
278 strcpy (mangled_name
, field_name
);
280 strcat (mangled_name
, buf
);
281 strcat (mangled_name
, newname
);
282 strcat (mangled_name
, TYPE_FN_FIELD_PHYSNAME (f
, j
));
288 /* Find which partial symtab on contains PC. Return 0 if none. */
290 struct partial_symtab
*
292 register CORE_ADDR pc
;
294 register struct partial_symtab
*pst
;
295 register struct objfile
*objfile
;
297 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
299 for (pst
= objfile
-> psymtabs
; pst
!= NULL
; pst
= pst
-> next
)
301 if (pc
>= pst
-> textlow
&& pc
< pst
-> texthigh
)
310 /* Find which partial symbol within a psymtab contains PC. Return 0
311 if none. Check all psymtabs if PSYMTAB is 0. */
312 struct partial_symbol
*
313 find_pc_psymbol (psymtab
, pc
)
314 struct partial_symtab
*psymtab
;
317 struct partial_symbol
*best
, *p
;
321 psymtab
= find_pc_psymtab (pc
);
325 best_pc
= psymtab
->textlow
- 1;
327 for (p
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
328 (p
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
329 < psymtab
->n_static_syms
);
331 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
332 && SYMBOL_CLASS (p
) == LOC_BLOCK
333 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
334 && SYMBOL_VALUE_ADDRESS (p
) > best_pc
)
336 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
339 if (best_pc
== psymtab
->textlow
- 1)
345 /* Find the definition for a specified symbol name NAME
346 in namespace NAMESPACE, visible from lexical block BLOCK.
347 Returns the struct symbol pointer, or zero if no symbol is found.
348 If SYMTAB is non-NULL, store the symbol table in which the
349 symbol was found there, or NULL if not found.
350 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
351 NAME is a field of the current implied argument `this'. If so set
352 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
353 BLOCK_FOUND is set to the block in which NAME is found (in the case of
354 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
357 lookup_symbol (name
, block
, namespace, is_a_field_of_this
, symtab
)
359 register const struct block
*block
;
360 const enum namespace namespace;
361 int *is_a_field_of_this
;
362 struct symtab
**symtab
;
364 register struct symbol
*sym
;
365 register struct symtab
*s
;
366 register struct partial_symtab
*ps
;
367 struct blockvector
*bv
;
368 register struct objfile
*objfile
;
369 register struct block
*b
;
371 register struct minimal_symbol
*msymbol
;
373 /* Search specified block and its superiors. */
377 sym
= lookup_block_symbol (block
, name
, namespace);
383 /* Search the list of symtabs for one which contains the
384 address of the start of this block. */
385 for (found
= 0, objfile
= object_files
;
386 !found
&& objfile
!= NULL
;
387 objfile
= objfile
-> next
)
389 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
391 bv
= BLOCKVECTOR (s
);
392 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
393 if (BLOCK_START (b
) <= BLOCK_START (block
)
394 && BLOCK_END (b
) > BLOCK_START (block
))
406 block
= BLOCK_SUPERBLOCK (block
);
409 /* But that doesn't do any demangling for the STATIC_BLOCK.
410 I'm not sure whether demangling is needed in the case of
411 nested function in inner blocks; if so this needs to be changed.
413 Don't need to mess with the psymtabs; if we have a block,
414 that file is read in. If we don't, then we deal later with
415 all the psymtab stuff that needs checking. */
416 if (namespace == VAR_NAMESPACE
&& block
!= NULL
)
419 /* Find the right symtab. */
420 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
422 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
424 bv
= BLOCKVECTOR (s
);
425 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
426 if (BLOCK_START (b
) <= BLOCK_START (block
)
427 && BLOCK_END (b
) > BLOCK_START (block
))
429 sym
= lookup_demangled_block_symbol (b
, name
);
443 /* C++: If requested to do so by the caller,
444 check to see if NAME is a field of `this'. */
445 if (is_a_field_of_this
)
447 struct value
*v
= value_of_this (0);
449 *is_a_field_of_this
= 0;
450 if (v
&& check_field (v
, name
))
452 *is_a_field_of_this
= 1;
459 /* Now search all global blocks. Do the symtab's first, then
460 check the psymtab's */
462 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
464 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
466 bv
= BLOCKVECTOR (s
);
467 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
468 sym
= lookup_block_symbol (block
, name
, namespace);
479 /* Check for the possibility of the symbol being a global function
480 that is stored in one of the minimal symbol tables. Eventually, all
481 global symbols might be resolved in this way. */
483 if (namespace == VAR_NAMESPACE
)
485 msymbol
= lookup_minimal_symbol (name
, (struct objfile
*) NULL
);
486 /* Look for a mangled C++ name for NAME. */
489 int name_len
= strlen (name
);
491 #if 0 /* FIXME: Needs to be fixed to use new minimal symbol tables */
492 for (ind
= misc_function_count
; --ind
>= 0; )
493 /* Assume orginal name is prefix of mangled name. */
494 if (!strncmp (misc_function_vector
[ind
].name
, name
, name_len
))
497 cplus_demangle(misc_function_vector
[ind
].name
, -1);
498 if (demangled
!= NULL
)
500 int cond
= strcmp (demangled
, name
);
506 /* Loop terminates on no match with ind == -1. */
512 s
= find_pc_symtab (msymbol
-> address
);
513 /* If S is zero, there are no debug symbols for this file.
514 Skip this stuff and check for matching static symbols below. */
517 bv
= BLOCKVECTOR (s
);
518 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
519 sym
= lookup_block_symbol (block
, msymbol
-> name
, namespace);
520 #if 0 /* defined(IBM6000) */
521 /* we kept static functions in misc_function_vector as well as
522 in static scope. We want to find them in the symbol table. */
525 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
526 sym
= lookup_block_symbol (block
, misc_function_vector
[ind
].name
,
531 /* sym == 0 if symbol was found in the minimal symbol table
532 but not in the symtab.
533 Return 0 to use the msymbol definition of "foo_".
535 This happens for Fortran "foo_" symbols,
536 which are "foo" in the symtab.
538 This can also happen if "asm" is used to make a
539 regular symbol but not a debugging symbol, e.g.
551 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
553 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
->next
)
555 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
557 s
= PSYMTAB_TO_SYMTAB(ps
);
558 bv
= BLOCKVECTOR (s
);
559 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
560 sym
= lookup_block_symbol (block
, name
, namespace);
562 error ("Internal: global symbol `%s' found in psymtab but not in symtab", name
);
570 /* Now search all per-file blocks.
571 Not strictly correct, but more useful than an error.
572 Do the symtabs first, then check the psymtabs */
574 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
576 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
578 bv
= BLOCKVECTOR (s
);
579 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
580 sym
= lookup_block_symbol (block
, name
, namespace);
591 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
593 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
595 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
597 s
= PSYMTAB_TO_SYMTAB(ps
);
598 bv
= BLOCKVECTOR (s
);
599 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
600 sym
= lookup_block_symbol (block
, name
, namespace);
602 error ("Internal: static symbol `%s' found in psymtab but not in symtab", name
);
610 /* Now search all per-file blocks for static mangled symbols.
611 Do the symtabs first, then check the psymtabs. */
613 if (namespace == VAR_NAMESPACE
)
615 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
617 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
619 bv
= BLOCKVECTOR (s
);
620 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
621 sym
= lookup_demangled_block_symbol (block
, name
);
632 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
634 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
636 if (!ps
->readin
&& lookup_demangled_partial_symbol (ps
, name
))
638 s
= PSYMTAB_TO_SYMTAB(ps
);
639 bv
= BLOCKVECTOR (s
);
640 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
641 sym
= lookup_demangled_block_symbol (block
, name
);
643 error ("Internal: mangled static symbol `%s' found in psymtab but not in symtab", name
);
657 /* Look for a static demangled symbol in block BLOCK. */
659 static struct symbol
*
660 lookup_demangled_block_symbol (block
, name
)
661 register const struct block
*block
;
664 register int bot
, top
, inc
;
665 register struct symbol
*sym
;
668 top
= BLOCK_NSYMS (block
);
673 sym
= BLOCK_SYM (block
, bot
);
674 if (SYMBOL_NAME (sym
)[0] == inc
675 && SYMBOL_NAMESPACE (sym
) == VAR_NAMESPACE
)
677 char *demangled
= cplus_demangle(SYMBOL_NAME (sym
), -1);
678 if (demangled
!= NULL
)
680 int cond
= strcmp (demangled
, name
);
692 /* Look, in partial_symtab PST, for static mangled symbol NAME. */
694 static struct partial_symbol
*
695 lookup_demangled_partial_symbol (pst
, name
)
696 const struct partial_symtab
*pst
;
699 struct partial_symbol
*start
, *psym
;
700 int length
= pst
->n_static_syms
;
701 register int inc
= name
[0];
704 return (struct partial_symbol
*) 0;
706 start
= pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
;
707 for (psym
= start
; psym
< start
+ length
; psym
++)
709 if (SYMBOL_NAME (psym
)[0] == inc
710 && SYMBOL_NAMESPACE (psym
) == VAR_NAMESPACE
)
712 char *demangled
= cplus_demangle(SYMBOL_NAME (psym
), -1);
713 if (demangled
!= NULL
)
715 int cond
= strcmp (demangled
, name
);
723 return (struct partial_symbol
*) 0;
726 /* Look, in partial_symtab PST, for symbol NAME. Check the global
727 symbols if GLOBAL, the static symbols if not */
729 static struct partial_symbol
*
730 lookup_partial_symbol (pst
, name
, global
, namespace)
731 struct partial_symtab
*pst
;
734 enum namespace namespace;
736 struct partial_symbol
*start
, *psym
;
737 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
740 return (struct partial_symbol
*) 0;
743 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
744 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
746 if (global
) /* This means we can use a binary */
749 struct partial_symbol
*top
, *bottom
, *center
;
751 /* Binary search. This search is guaranteed to end with center
752 pointing at the earliest partial symbol with the correct
753 name. At that point *all* partial symbols with that name
754 will be checked against the correct namespace. */
756 top
= start
+ length
- 1;
759 center
= bottom
+ (top
- bottom
) / 2;
761 assert (center
< top
);
763 if (strcmp (SYMBOL_NAME (center
), name
) >= 0)
768 assert (top
== bottom
);
770 while (!strcmp (SYMBOL_NAME (top
), name
))
772 if (SYMBOL_NAMESPACE (top
) == namespace)
779 /* Can't use a binary search */
780 for (psym
= start
; psym
< start
+ length
; psym
++)
781 if (namespace == SYMBOL_NAMESPACE (psym
)
782 && !strcmp (name
, SYMBOL_NAME (psym
)))
786 return (struct partial_symbol
*) 0;
789 /* Find the psymtab containing main(). */
791 struct partial_symtab
*
794 register struct partial_symtab
*pst
;
795 register struct objfile
*objfile
;
797 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
799 for (pst
= objfile
-> psymtabs
; pst
; pst
= pst
->next
)
801 if (lookup_partial_symbol (pst
, "main", 1, VAR_NAMESPACE
))
810 /* Look for a symbol in block BLOCK. */
813 lookup_block_symbol (block
, name
, namespace)
814 register const struct block
*block
;
816 const enum namespace namespace;
818 register int bot
, top
, inc
;
819 register struct symbol
*sym
, *parameter_sym
;
821 top
= BLOCK_NSYMS (block
);
824 /* If the blocks's symbols were sorted, start with a binary search. */
826 if (BLOCK_SHOULD_SORT (block
))
828 /* First, advance BOT to not far before
829 the first symbol whose name is NAME. */
833 inc
= (top
- bot
+ 1);
834 /* No need to keep binary searching for the last few bits worth. */
837 inc
= (inc
>> 1) + bot
;
838 sym
= BLOCK_SYM (block
, inc
);
839 if (SYMBOL_NAME (sym
)[0] < name
[0])
841 else if (SYMBOL_NAME (sym
)[0] > name
[0])
843 else if (strcmp (SYMBOL_NAME (sym
), name
) < 0)
849 /* Now scan forward until we run out of symbols,
850 find one whose name is greater than NAME,
852 If there is more than one symbol with the right name and namespace,
853 we return the first one. dbxread.c is careful to make sure
854 that if one is a register then it comes first. */
856 top
= BLOCK_NSYMS (block
);
859 sym
= BLOCK_SYM (block
, bot
);
860 inc
= SYMBOL_NAME (sym
)[0] - name
[0];
862 inc
= strcmp (SYMBOL_NAME (sym
), name
);
863 if (inc
== 0 && SYMBOL_NAMESPACE (sym
) == namespace)
872 /* Here if block isn't sorted.
873 This loop is equivalent to the loop above,
874 but hacked greatly for speed.
876 Note that parameter symbols do not always show up last in the
877 list; this loop makes sure to take anything else other than
878 parameter symbols first; it only uses parameter symbols as a
879 last resort. Note that this only takes up extra computation
882 parameter_sym
= (struct symbol
*) 0;
883 top
= BLOCK_NSYMS (block
);
887 sym
= BLOCK_SYM (block
, bot
);
888 if (SYMBOL_NAME (sym
)[0] == inc
889 && !strcmp (SYMBOL_NAME (sym
), name
)
890 && SYMBOL_NAMESPACE (sym
) == namespace)
892 if (SYMBOL_CLASS (sym
) == LOC_ARG
893 || SYMBOL_CLASS (sym
) == LOC_LOCAL_ARG
894 || SYMBOL_CLASS (sym
) == LOC_REF_ARG
895 || SYMBOL_CLASS (sym
) == LOC_REGPARM
)
902 return parameter_sym
; /* Will be 0 if not found. */
905 /* Return the symbol for the function which contains a specified
906 lexical block, described by a struct block BL. */
912 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
913 bl
= BLOCK_SUPERBLOCK (bl
);
915 return BLOCK_FUNCTION (bl
);
918 /* Subroutine of find_pc_line */
922 register CORE_ADDR pc
;
924 register struct block
*b
;
925 struct blockvector
*bv
;
926 register struct symtab
*s
= 0;
927 register struct partial_symtab
*ps
;
928 register struct objfile
*objfile
;
931 /* Search all symtabs for one whose file contains our pc */
933 for (found
= 0, objfile
= object_files
;
934 !found
&& objfile
!= NULL
;
935 objfile
= objfile
-> next
)
937 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
939 bv
= BLOCKVECTOR (s
);
940 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
941 if (BLOCK_START (b
) <= pc
942 && BLOCK_END (b
) > pc
)
952 ps
= find_pc_psymtab (pc
);
953 if (ps
&& ps
->readin
)
955 printf_filtered ("(Internal error: pc 0x%x in read in psymtab, but not in symtab.)\n", pc
);
959 s
= PSYMTAB_TO_SYMTAB (ps
);
966 /* Find the source file and line number for a given PC value.
967 Return a structure containing a symtab pointer, a line number,
968 and a pc range for the entire source line.
969 The value's .pc field is NOT the specified pc.
970 NOTCURRENT nonzero means, if specified pc is on a line boundary,
971 use the line that ends there. Otherwise, in that case, the line
972 that begins there is used. */
974 struct symtab_and_line
975 find_pc_line (pc
, notcurrent
)
980 register struct linetable
*l
;
983 register struct linetable_entry
*item
;
984 struct symtab_and_line val
;
985 struct blockvector
*bv
;
987 /* Info on best line seen so far, and where it starts, and its file. */
990 CORE_ADDR best_pc
= 0;
991 CORE_ADDR best_end
= 0;
992 struct symtab
*best_symtab
= 0;
994 /* Store here the first line number
995 of a file which contains the line at the smallest pc after PC.
996 If we don't find a line whose range contains PC,
997 we will use a line one less than this,
998 with a range from the start of that file to the first line's pc. */
1000 CORE_ADDR alt_pc
= 0;
1001 struct symtab
*alt_symtab
= 0;
1003 /* Info on best line seen in this file. */
1008 /* Info on first line of this file. */
1013 /* If this pc is not from the current frame,
1014 it is the address of the end of a call instruction.
1015 Quite likely that is the start of the following statement.
1016 But what we want is the statement containing the instruction.
1017 Fudge the pc to make sure we get that. */
1019 if (notcurrent
) pc
-= 1;
1021 s
= find_pc_symtab (pc
);
1031 bv
= BLOCKVECTOR (s
);
1033 /* Look at all the symtabs that share this blockvector.
1034 They all have the same apriori range, that we found was right;
1035 but they have different line tables. */
1037 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1039 /* Find the best line in this symtab. */
1046 for (i
= 0; i
< len
; i
++)
1048 item
= &(l
->item
[i
]);
1052 first_line
= item
->line
;
1053 first_pc
= item
->pc
;
1055 /* Return the last line that did not start after PC. */
1058 prev_line
= item
->line
;
1065 /* Is this file's best line closer than the best in the other files?
1066 If so, record this file, and its best line, as best so far. */
1067 if (prev_line
>= 0 && prev_pc
> best_pc
)
1070 best_line
= prev_line
;
1072 /* If another line is in the linetable, and its PC is closer
1073 than the best_end we currently have, take it as best_end. */
1074 if (i
< len
&& (best_end
== 0 || best_end
> item
->pc
))
1075 best_end
= item
->pc
;
1077 /* Is this file's first line closer than the first lines of other files?
1078 If so, record this file, and its first line, as best alternate. */
1079 if (first_line
>= 0 && first_pc
> pc
1080 && (alt_pc
== 0 || first_pc
< alt_pc
))
1083 alt_line
= first_line
;
1087 if (best_symtab
== 0)
1089 val
.symtab
= alt_symtab
;
1090 val
.line
= alt_line
- 1;
1091 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1096 val
.symtab
= best_symtab
;
1097 val
.line
= best_line
;
1099 if (best_end
&& (alt_pc
== 0 || best_end
< alt_pc
))
1104 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1109 /* Find the PC value for a given source file and line number.
1110 Returns zero for invalid line number.
1111 The source file is specified with a struct symtab. */
1114 find_line_pc (symtab
, line
)
1115 struct symtab
*symtab
;
1118 register struct linetable
*l
;
1124 l
= LINETABLE (symtab
);
1125 ind
= find_line_common(l
, line
, &dummy
);
1126 return (ind
>= 0) ? l
->item
[ind
].pc
: 0;
1129 /* Find the range of pc values in a line.
1130 Store the starting pc of the line into *STARTPTR
1131 and the ending pc (start of next line) into *ENDPTR.
1132 Returns 1 to indicate success.
1133 Returns 0 if could not find the specified line. */
1136 find_line_pc_range (symtab
, thisline
, startptr
, endptr
)
1137 struct symtab
*symtab
;
1139 CORE_ADDR
*startptr
, *endptr
;
1141 register struct linetable
*l
;
1143 int exact_match
; /* did we get an exact linenumber match */
1148 l
= LINETABLE (symtab
);
1149 ind
= find_line_common (l
, thisline
, &exact_match
);
1152 *startptr
= l
->item
[ind
].pc
;
1153 /* If we have not seen an entry for the specified line,
1154 assume that means the specified line has zero bytes. */
1155 if (!exact_match
|| ind
== l
->nitems
-1)
1156 *endptr
= *startptr
;
1158 /* Perhaps the following entry is for the following line.
1159 It's worth a try. */
1160 if (ind
+1 < l
->nitems
1161 && l
->item
[ind
+1].line
== thisline
+ 1)
1162 *endptr
= l
->item
[ind
+1].pc
;
1164 *endptr
= find_line_pc (symtab
, thisline
+1);
1171 /* Given a line table and a line number, return the index into the line
1172 table for the pc of the nearest line whose number is >= the specified one.
1173 Return -1 if none is found. The value is >= 0 if it is an index.
1175 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1178 find_line_common (l
, lineno
, exact_match
)
1179 register struct linetable
*l
;
1180 register int lineno
;
1186 /* BEST is the smallest linenumber > LINENO so far seen,
1187 or 0 if none has been seen so far.
1188 BEST_INDEX identifies the item for it. */
1190 int best_index
= -1;
1199 for (i
= 0; i
< len
; i
++)
1201 register struct linetable_entry
*item
= &(l
->item
[i
]);
1203 if (item
->line
== lineno
)
1209 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
1216 /* If we got here, we didn't get an exact match. */
1223 find_pc_line_pc_range (pc
, startptr
, endptr
)
1225 CORE_ADDR
*startptr
, *endptr
;
1227 struct symtab_and_line sal
;
1228 sal
= find_pc_line (pc
, 0);
1231 return sal
.symtab
!= 0;
1234 /* If P is of the form "operator[ \t]+..." where `...' is
1235 some legitimate operator text, return a pointer to the
1236 beginning of the substring of the operator text.
1237 Otherwise, return "". */
1239 operator_chars (p
, end
)
1244 if (strncmp (p
, "operator", 8))
1248 /* Don't get faked out by `operator' being part of a longer
1250 if ((*p
>= 'A' && *p
<= 'Z') || (*p
>= 'a' && *p
<= 'z')
1251 || *p
== '_' || *p
== '$' || *p
== '\0')
1254 /* Allow some whitespace between `operator' and the operator symbol. */
1255 while (*p
== ' ' || *p
== '\t')
1277 if (p
[1] == '=' || p
[1] == p
[0])
1288 error ("`operator ()' must be specified without whitespace in `()'");
1293 error ("`operator ?:' must be specified without whitespace in `?:'");
1298 error ("`operator []' must be specified without whitespace in `[]'");
1302 error ("`operator %s' not supported", p
);
1309 /* Recursive helper function for decode_line_1.
1310 * Look for methods named NAME in type T.
1311 * Return number of matches.
1312 * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1313 * These allocations seem to define "big enough":
1314 * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1315 * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1319 find_methods (t
, name
, physnames
, sym_arr
)
1323 struct symbol
**sym_arr
;
1327 struct symbol
*sym_class
;
1328 char *class_name
= type_name_no_tag (t
);
1329 /* Ignore this class if it doesn't have a name.
1330 This prevents core dumps, but is just a workaround
1331 because we might not find the function in
1332 certain cases, such as
1333 struct D {virtual int f();}
1334 struct C : D {virtual int g();}
1335 (in this case g++ 1.35.1- does not put out a name
1336 for D as such, it defines type 19 (for example) in
1337 the same stab as C, and then does a
1338 .stabs "D:T19" and a .stabs "D:t19".
1340 "break C::f" should not be looking for field f in
1342 but just for the field f in the baseclasses of C
1343 (no matter what their names).
1345 However, I don't know how to replace the code below
1346 that depends on knowing the name of D. */
1348 && (sym_class
= lookup_symbol (class_name
,
1349 (struct block
*)NULL
,
1352 (struct symtab
**)NULL
)))
1355 t
= SYMBOL_TYPE (sym_class
);
1356 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
1357 method_counter
>= 0;
1361 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
1363 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
1364 if (!strcmp (name
, method_name
))
1365 /* Find all the fields with that name. */
1366 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
1371 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
1372 check_stub_method (t
, method_counter
, field_counter
);
1373 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
1374 physnames
[i1
] = (char*) alloca (strlen (phys_name
) + 1);
1375 strcpy (physnames
[i1
], phys_name
);
1376 sym_arr
[i1
] = lookup_symbol (phys_name
,
1377 SYMBOL_BLOCK_VALUE (sym_class
),
1380 (struct symtab
**) NULL
);
1381 if (sym_arr
[i1
]) i1
++;
1385 /* Only search baseclasses if there is no match yet,
1386 * since names in derived classes override those in baseclasses.
1390 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
1391 i1
+= find_methods(TYPE_BASECLASS(t
, ibase
), name
,
1392 physnames
+ i1
, sym_arr
+ i1
);
1396 /* Parse a string that specifies a line number.
1397 Pass the address of a char * variable; that variable will be
1398 advanced over the characters actually parsed.
1402 LINENUM -- that line number in current file. PC returned is 0.
1403 FILE:LINENUM -- that line in that file. PC returned is 0.
1404 FUNCTION -- line number of openbrace of that function.
1405 PC returned is the start of the function.
1406 VARIABLE -- line number of definition of that variable.
1408 FILE:FUNCTION -- likewise, but prefer functions in that file.
1409 *EXPR -- line in which address EXPR appears.
1411 FUNCTION may be an undebuggable function found in minimal symbol table.
1413 If the argument FUNFIRSTLINE is nonzero, we want the first line
1414 of real code inside a function when a function is specified.
1416 DEFAULT_SYMTAB specifies the file to use if none is specified.
1417 It defaults to current_source_symtab.
1418 DEFAULT_LINE specifies the line number to use for relative
1419 line numbers (that start with signs). Defaults to current_source_line.
1421 Note that it is possible to return zero for the symtab
1422 if no file is validly specified. Callers must check that.
1423 Also, the line number returned may be invalid. */
1425 struct symtabs_and_lines
1426 decode_line_1 (argptr
, funfirstline
, default_symtab
, default_line
)
1429 struct symtab
*default_symtab
;
1432 struct symtabs_and_lines values
;
1433 struct symtab_and_line val
;
1434 register char *p
, *p1
;
1436 register struct symtab
*s
;
1438 register struct symbol
*sym
;
1439 /* The symtab that SYM was found in. */
1440 struct symtab
*sym_symtab
;
1442 register CORE_ADDR pc
;
1443 register struct minimal_symbol
*msymbol
;
1445 struct symbol
*sym_class
;
1447 struct symbol
**sym_arr
;
1451 /* Defaults have defaults. */
1453 if (default_symtab
== 0)
1455 default_symtab
= current_source_symtab
;
1456 default_line
= current_source_line
;
1459 /* See if arg is *PC */
1461 if (**argptr
== '*')
1464 pc
= parse_and_eval_address_1 (argptr
);
1465 values
.sals
= (struct symtab_and_line
*)
1466 xmalloc (sizeof (struct symtab_and_line
));
1468 values
.sals
[0] = find_pc_line (pc
, 0);
1469 values
.sals
[0].pc
= pc
;
1473 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1477 for (p
= *argptr
; *p
; p
++)
1479 if (p
[0] == ':' || p
[0] == ' ' || p
[0] == '\t')
1482 while (p
[0] == ' ' || p
[0] == '\t') p
++;
1490 /* Extract the class name. */
1492 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1493 copy
= (char *) alloca (p
- *argptr
+ 1);
1494 bcopy (*argptr
, copy
, p
- *argptr
);
1495 copy
[p
- *argptr
] = 0;
1497 /* Discard the class name from the arg. */
1499 while (*p
== ' ' || *p
== '\t') p
++;
1502 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
1503 (struct symtab
**)NULL
);
1506 ( TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_STRUCT
1507 || TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_UNION
))
1509 /* Arg token is not digits => try it as a function name
1510 Find the next token (everything up to end or next whitespace). */
1512 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',' && *p
!=':') p
++;
1513 q
= operator_chars (*argptr
, &q1
);
1515 copy
= (char *) alloca (p
- *argptr
+ 1 + (q1
- q
));
1520 copy
[2] = CPLUS_MARKER
;
1521 bcopy (q
, copy
+ 3, q1
- q
);
1522 copy
[3 + (q1
- q
)] = '\0';
1527 bcopy (*argptr
, copy
, p
- *argptr
);
1528 copy
[p
- *argptr
] = '\0';
1531 /* no line number may be specified */
1532 while (*p
== ' ' || *p
== '\t') p
++;
1536 i1
= 0; /* counter for the symbol array */
1537 t
= SYMBOL_TYPE (sym_class
);
1538 sym_arr
= (struct symbol
**) alloca(TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(struct symbol
*));
1539 physnames
= (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(char*));
1541 if (destructor_name_p (copy
, t
))
1543 /* destructors are a special case. */
1544 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, 0);
1545 int len
= TYPE_FN_FIELDLIST_LENGTH (t
, 0) - 1;
1546 char *phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, len
);
1547 physnames
[i1
] = (char *)alloca (strlen (phys_name
) + 1);
1548 strcpy (physnames
[i1
], phys_name
);
1550 lookup_symbol (phys_name
, SYMBOL_BLOCK_VALUE (sym_class
),
1551 VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
1552 if (sym_arr
[i1
]) i1
++;
1555 i1
= find_methods (t
, copy
, physnames
, sym_arr
);
1558 /* There is exactly one field with that name. */
1561 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1563 /* Arg is the name of a function */
1564 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1567 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1569 values
.sals
[0] = find_pc_line (pc
, 0);
1570 values
.sals
[0].pc
= (values
.sals
[0].end
&& values
.sals
[0].pc
!= pc
) ? values
.sals
[0].end
: pc
;
1580 /* There is more than one field with that name
1581 (overloaded). Ask the user which one to use. */
1582 return decode_line_2 (sym_arr
, i1
, funfirstline
);
1588 if (OPNAME_PREFIX_P (copy
))
1590 tmp
= (char *)alloca (strlen (copy
+3) + 9);
1591 strcpy (tmp
, "operator ");
1592 strcat (tmp
, copy
+3);
1597 error ("The class `%s' does not have destructor defined",
1600 error ("The class %s does not have any method named %s",
1601 sym_class
->name
, tmp
);
1605 /* The quotes are important if copy is empty. */
1606 error("No class, struct, or union named \"%s\"", copy
);
1611 /* Extract the file name. */
1613 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1614 copy
= (char *) alloca (p
- *argptr
+ 1);
1615 bcopy (*argptr
, copy
, p
- *argptr
);
1616 copy
[p
- *argptr
] = 0;
1618 /* Find that file's data. */
1619 s
= lookup_symtab (copy
);
1622 if (!have_full_symbols () && !have_partial_symbols ())
1623 error (no_symtab_msg
);
1624 error ("No source file named %s.", copy
);
1627 /* Discard the file name from the arg. */
1629 while (*p
== ' ' || *p
== '\t') p
++;
1633 /* S is specified file's symtab, or 0 if no file specified.
1634 arg no longer contains the file name. */
1636 /* Check whether arg is all digits (and sign) */
1639 if (*p
== '-' || *p
== '+') p
++;
1640 while (*p
>= '0' && *p
<= '9')
1643 if (p
!= *argptr
&& (*p
== 0 || *p
== ' ' || *p
== '\t' || *p
== ','))
1645 /* We found a token consisting of all digits -- at least one digit. */
1646 enum sign
{none
, plus
, minus
} sign
= none
;
1648 /* This is where we need to make sure that we have good defaults.
1649 We must guarantee that this section of code is never executed
1650 when we are called with just a function name, since
1651 select_source_symtab calls us with such an argument */
1653 if (s
== 0 && default_symtab
== 0)
1655 select_source_symtab (0);
1656 default_symtab
= current_source_symtab
;
1657 default_line
= current_source_line
;
1660 if (**argptr
== '+')
1661 sign
= plus
, (*argptr
)++;
1662 else if (**argptr
== '-')
1663 sign
= minus
, (*argptr
)++;
1664 val
.line
= atoi (*argptr
);
1671 val
.line
= default_line
+ val
.line
;
1677 val
.line
= default_line
- val
.line
;
1682 break; /* No need to adjust val.line. */
1685 while (*p
== ' ' || *p
== '\t') p
++;
1691 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1692 values
.sals
[0] = val
;
1697 /* Arg token is not digits => try it as a variable name
1698 Find the next token (everything up to end or next whitespace). */
1700 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',') p
++;
1701 copy
= (char *) alloca (p
- *argptr
+ 1);
1702 bcopy (*argptr
, copy
, p
- *argptr
);
1703 copy
[p
- *argptr
] = 0;
1704 while (*p
== ' ' || *p
== '\t') p
++;
1707 /* Look up that token as a variable.
1708 If file specified, use that file's per-file block to start with. */
1710 sym
= lookup_symbol (copy
,
1711 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
1712 : get_selected_block ()),
1713 VAR_NAMESPACE
, 0, &sym_symtab
);
1717 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1719 /* Arg is the name of a function */
1720 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1723 val
= find_pc_line (pc
, 0);
1724 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1725 /* Convex: no need to suppress code on first line, if any */
1728 /* If SKIP_PROLOGUE left us in mid-line, and the next line is still
1729 part of the same function:
1730 advance to next line,
1731 recalculate its line number (might not be N+1). */
1732 if (val
.pc
!= pc
&& val
.end
&&
1733 lookup_minimal_symbol_by_pc (pc
) == lookup_minimal_symbol_by_pc (val
.end
)) {
1734 pc
= val
.end
; /* First pc of next line */
1735 val
= find_pc_line (pc
, 0);
1739 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1740 values
.sals
[0] = val
;
1743 /* I think this is always the same as the line that
1744 we calculate above, but the general principle is
1745 "trust the symbols more than stuff like
1747 if (SYMBOL_LINE (sym
) != 0)
1748 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1752 else if (SYMBOL_LINE (sym
) != 0)
1754 /* We know its line number. */
1755 values
.sals
= (struct symtab_and_line
*)
1756 xmalloc (sizeof (struct symtab_and_line
));
1758 bzero (&values
.sals
[0], sizeof (values
.sals
[0]));
1759 values
.sals
[0].symtab
= sym_symtab
;
1760 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1764 /* This can happen if it is compiled with a compiler which doesn't
1765 put out line numbers for variables. */
1766 error ("Line number not known for symbol \"%s\"", copy
);
1769 msymbol
= lookup_minimal_symbol (copy
, (struct objfile
*) NULL
);
1770 if (msymbol
!= NULL
)
1774 val
.pc
= msymbol
-> address
+ FUNCTION_START_OFFSET
;
1776 SKIP_PROLOGUE (val
.pc
);
1777 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1778 values
.sals
[0] = val
;
1783 if (!have_full_symbols () &&
1784 !have_partial_symbols () && !have_minimal_symbols ())
1785 error (no_symtab_msg
);
1787 error ("Function %s not defined.", copy
);
1788 return values
; /* for lint */
1791 struct symtabs_and_lines
1792 decode_line_spec (string
, funfirstline
)
1796 struct symtabs_and_lines sals
;
1798 error ("Empty line specification.");
1799 sals
= decode_line_1 (&string
, funfirstline
,
1800 current_source_symtab
, current_source_line
);
1802 error ("Junk at end of line specification: %s", string
);
1806 /* Given a list of NELTS symbols in sym_arr (with corresponding
1807 mangled names in physnames), return a list of lines to operate on
1808 (ask user if necessary). */
1809 static struct symtabs_and_lines
1810 decode_line_2 (sym_arr
, nelts
, funfirstline
)
1811 struct symbol
*sym_arr
[];
1815 struct symtabs_and_lines values
, return_values
;
1816 register CORE_ADDR pc
;
1821 values
.sals
= (struct symtab_and_line
*) alloca (nelts
* sizeof(struct symtab_and_line
));
1822 return_values
.sals
= (struct symtab_and_line
*) xmalloc (nelts
* sizeof(struct symtab_and_line
));
1825 printf("[0] cancel\n[1] all\n");
1828 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
1830 /* Arg is the name of a function */
1831 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr
[i
]))
1832 + FUNCTION_START_OFFSET
;
1835 values
.sals
[i
] = find_pc_line (pc
, 0);
1836 values
.sals
[i
].pc
= (values
.sals
[i
].end
&& values
.sals
[i
].pc
!= pc
) ?
1837 values
.sals
[i
].end
: pc
;
1838 printf("[%d] file:%s; line number:%d\n",
1839 (i
+2), values
.sals
[i
].symtab
->filename
, values
.sals
[i
].line
);
1841 else printf ("?HERE\n");
1845 if ((prompt
= getenv ("PS2")) == NULL
)
1849 printf("%s ",prompt
);
1852 args
= command_line_input ((char *) NULL
, 0);
1855 error_no_arg ("one or more choice numbers");
1863 while (*arg1
>= '0' && *arg1
<= '9') arg1
++;
1864 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
1865 error ("Arguments must be choice numbers.");
1870 error ("cancelled");
1873 bcopy (values
.sals
, return_values
.sals
, (nelts
* sizeof(struct symtab_and_line
)));
1874 return_values
.nelts
= nelts
;
1875 return return_values
;
1878 if (num
> nelts
+ 2)
1880 printf ("No choice number %d.\n", num
);
1885 if (values
.sals
[num
].pc
)
1887 return_values
.sals
[i
++] = values
.sals
[num
];
1888 values
.sals
[num
].pc
= 0;
1892 printf ("duplicate request for %d ignored.\n", num
);
1897 while (*args
== ' ' || *args
== '\t') args
++;
1899 return_values
.nelts
= i
;
1900 return return_values
;
1904 /* Slave routine for sources_info. Force line breaks at ,'s.
1905 NAME is the name to print and *FIRST is nonzero if this is the first
1906 name printed. Set *FIRST to zero. */
1908 output_source_filename (name
, first
)
1912 static unsigned int column
;
1913 /* Table of files printed so far. Since a single source file can
1914 result in several partial symbol tables, we need to avoid printing
1915 it more than once. Note: if some of the psymtabs are read in and
1916 some are not, it gets printed both under "Source files for which
1917 symbols have been read" and "Source files for which symbols will
1918 be read in on demand". I consider this a reasonable way to deal
1919 with the situation. I'm not sure whether this can also happen for
1920 symtabs; it doesn't hurt to check. */
1921 static char **tab
= NULL
;
1922 /* Allocated size of tab in elements.
1923 Start with one 256-byte block (when using GNU malloc.c).
1924 24 is the malloc overhead when range checking is in effect. */
1925 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
1926 /* Current size of tab in elements. */
1927 static int tab_cur_size
;
1934 tab
= (char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
1938 /* Is NAME in tab? */
1939 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
1940 if (strcmp (*p
, name
) == 0)
1941 /* Yes; don't print it again. */
1943 /* No; add it to tab. */
1944 if (tab_cur_size
== tab_alloc_size
)
1946 tab_alloc_size
*= 2;
1947 tab
= (char **) xrealloc ((char *) tab
, tab_alloc_size
* sizeof (*tab
));
1949 tab
[tab_cur_size
++] = name
;
1958 printf_filtered (",");
1962 if (column
!= 0 && column
+ strlen (name
) >= 70)
1964 printf_filtered ("\n");
1967 else if (column
!= 0)
1969 printf_filtered (" ");
1972 fputs_filtered (name
, stdout
);
1973 column
+= strlen (name
);
1979 register struct symtab
*s
;
1980 register struct partial_symtab
*ps
;
1981 register struct objfile
*objfile
;
1984 if (!have_full_symbols () && !have_partial_symbols ())
1986 error (no_symtab_msg
);
1989 printf_filtered ("Source files for which symbols have been read in:\n\n");
1992 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
1994 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
1996 output_source_filename (s
-> filename
, &first
);
1999 printf_filtered ("\n\n");
2001 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2004 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2006 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
2010 output_source_filename (ps
-> filename
, &first
);
2014 printf_filtered ("\n");
2017 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2018 If CLASS is zero, list all symbols except functions and type names.
2019 If CLASS is 1, list only functions.
2020 If CLASS is 2, list only type names.
2021 If CLASS is 3, list only method names.
2023 BPT is non-zero if we should set a breakpoint at the functions
2027 list_symbols (regexp
, class, bpt
)
2032 register struct symtab
*s
;
2033 register struct partial_symtab
*ps
;
2034 register struct blockvector
*bv
;
2035 struct blockvector
*prev_bv
= 0;
2036 register struct block
*b
;
2038 register struct symbol
*sym
;
2039 struct partial_symbol
*psym
;
2040 struct objfile
*objfile
;
2041 struct minimal_symbol
*msymbol
;
2043 static char *classnames
[]
2044 = {"variable", "function", "type", "method"};
2045 int found_in_file
= 0;
2047 static enum minimal_symbol_type types
[]
2048 = {mst_data
, mst_text
, mst_abs
, mst_unknown
};
2049 static enum minimal_symbol_type types2
[]
2050 = {mst_bss
, mst_text
, mst_abs
, mst_unknown
};
2051 enum minimal_symbol_type ourtype
= types
[class];
2052 enum minimal_symbol_type ourtype2
= types2
[class];
2055 if (0 != (val
= re_comp (regexp
)))
2056 error ("Invalid regexp (%s): %s", val
, regexp
);
2058 /* Search through the partial symtabs *first* for all symbols
2059 matching the regexp. That way we don't have to reproduce all of
2060 the machinery below. */
2062 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2064 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
2066 struct partial_symbol
*bound
, *gbound
, *sbound
;
2069 if (ps
->readin
) continue;
2071 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2072 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2075 /* Go through all of the symbols stored in a partial
2076 symtab in one loop. */
2077 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2082 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2084 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2095 /* If it would match (logic taken from loop below)
2096 load the file and go on to the next one */
2097 if ((regexp
== 0 || re_exec (SYMBOL_NAME (psym
)))
2098 && ((class == 0 && SYMBOL_CLASS (psym
) != LOC_TYPEDEF
2099 && SYMBOL_CLASS (psym
) != LOC_BLOCK
)
2100 || (class == 1 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)
2101 || (class == 2 && SYMBOL_CLASS (psym
) == LOC_TYPEDEF
)
2102 || (class == 3 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)))
2104 (void) PSYMTAB_TO_SYMTAB(ps
);
2113 /* Here, we search through the minimal symbol tables for functions that
2114 match, and call find_pc_symtab on them to force their symbols to
2115 be read. The symbol will then be found during the scan of symtabs
2116 below. If find_pc_symtab fails, set found_misc so that we will
2117 rescan to print any matching symbols without debug info. */
2121 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2123 for (msymbol
= objfile
-> msymbols
;
2124 msymbol
-> name
!= NULL
; msymbol
++)
2126 if (msymbol
-> type
== ourtype
|| msymbol
-> type
== ourtype2
)
2128 if (regexp
== 0 || re_exec (msymbol
-> name
))
2130 if (0 == find_pc_symtab (msymbol
-> address
))
2140 /* Printout here so as to get after the "Reading in symbols"
2141 messages which will be generated above. */
2143 printf_filtered (regexp
2144 ? "All %ss matching regular expression \"%s\":\n"
2145 : "All defined %ss:\n",
2149 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2151 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
2154 bv
= BLOCKVECTOR (s
);
2155 /* Often many files share a blockvector.
2156 Scan each blockvector only once so that
2157 we don't get every symbol many times.
2158 It happens that the first symtab in the list
2159 for any given blockvector is the main file. */
2161 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
2163 b
= BLOCKVECTOR_BLOCK (bv
, i
);
2164 /* Skip the sort if this block is always sorted. */
2165 if (!BLOCK_SHOULD_SORT (b
))
2166 sort_block_syms (b
);
2167 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
2170 sym
= BLOCK_SYM (b
, j
);
2171 if ((regexp
== 0 || re_exec (SYMBOL_NAME (sym
)))
2172 && ((class == 0 && SYMBOL_CLASS (sym
) != LOC_TYPEDEF
2173 && SYMBOL_CLASS (sym
) != LOC_BLOCK
)
2174 || (class == 1 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2175 || (class == 2 && SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2176 || (class == 3 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)))
2180 /* Set a breakpoint here, if it's a function */
2182 break_command (SYMBOL_NAME(sym
), 0);
2184 else if (!found_in_file
)
2186 fputs_filtered ("\nFile ", stdout
);
2187 fputs_filtered (s
->filename
, stdout
);
2188 fputs_filtered (":\n", stdout
);
2192 if (class != 2 && i
== STATIC_BLOCK
)
2193 printf_filtered ("static ");
2195 /* Typedef that is not a C++ class */
2197 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
2198 typedef_print (SYMBOL_TYPE(sym
), sym
, stdout
);
2199 /* variable, func, or typedef-that-is-c++-class */
2200 else if (class < 2 ||
2202 SYMBOL_NAMESPACE(sym
) == STRUCT_NAMESPACE
))
2204 type_print (SYMBOL_TYPE (sym
),
2205 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2206 ? "" : SYMBOL_NAME (sym
)),
2209 printf_filtered (";\n");
2215 type_print_base (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0, 0);
2216 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0);
2217 sprintf (buf
, " %s::", type_name_no_tag (t
));
2218 type_print_method_args (TYPE_FN_FIELD_ARGS (t
, i
), buf
, name
, stdout
);
2228 /* If there are no eyes, avoid all contact. I mean, if there are
2229 no debug symbols, then print directly from the msymbol_vector. */
2231 if (found_misc
|| class != 1)
2234 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2236 for (msymbol
= objfile
-> msymbols
;
2237 msymbol
-> name
!= NULL
; msymbol
++)
2239 if (msymbol
-> type
== ourtype
|| msymbol
-> type
== ourtype2
)
2241 if (regexp
== 0 || re_exec (msymbol
-> name
))
2243 /* Functions: Look up by address. */
2245 (find_pc_symtab (msymbol
-> address
) != NULL
))
2247 /* Variables/Absolutes: Look up by name */
2248 if (lookup_symbol (msymbol
-> name
,
2249 (struct block
*) 0, VAR_NAMESPACE
, 0,
2250 (struct symtab
**) 0) == NULL
)
2254 printf_filtered ("\nNon-debugging symbols:\n");
2257 printf_filtered (" %08x %s\n",
2270 variables_info (regexp
)
2273 list_symbols (regexp
, 0, 0);
2277 functions_info (regexp
)
2280 list_symbols (regexp
, 1, 0);
2287 list_symbols (regexp
, 2, 0);
2291 /* Tiemann says: "info methods was never implemented." */
2293 methods_info (regexp
)
2296 list_symbols (regexp
, 3, 0);
2300 /* Breakpoint all functions matching regular expression. */
2302 rbreak_command (regexp
)
2305 list_symbols (regexp
, 1, 1);
2309 /* Return Nonzero if block a is lexically nested within block b,
2310 or if a and b have the same pc range.
2311 Return zero otherwise. */
2314 struct block
*a
, *b
;
2318 return BLOCK_START (a
) >= BLOCK_START (b
)
2319 && BLOCK_END (a
) <= BLOCK_END (b
);
2323 /* Helper routine for make_symbol_completion_list. */
2325 int return_val_size
, return_val_index
;
2329 completion_list_add_symbol (symname
)
2332 if (return_val_index
+ 3 > return_val_size
)
2333 return_val
= (char **) xrealloc ((char *) return_val
,
2334 (return_val_size
*= 2) * sizeof (char *));
2336 return_val
[return_val_index
] =
2337 (char *)xmalloc (1 + strlen (symname
));
2339 strcpy (return_val
[return_val_index
], symname
);
2341 return_val
[++return_val_index
] = (char *)NULL
;
2344 /* Return a NULL terminated array of all symbols (regardless of class) which
2345 begin by matching TEXT. If the answer is no symbols, then the return value
2346 is an array which contains only a NULL pointer.
2348 Problem: All of the symbols have to be copied because readline
2349 frees them. I'm not going to worry about this; hopefully there
2350 won't be that many. */
2353 make_symbol_completion_list (text
)
2356 register struct symtab
*s
;
2357 register struct partial_symtab
*ps
;
2358 register struct minimal_symbol
*msymbol
;
2359 register struct objfile
*objfile
;
2360 register struct block
*b
, *surrounding_static_block
= 0;
2362 struct partial_symbol
*psym
;
2364 int text_len
= strlen (text
);
2365 return_val_size
= 100;
2366 return_val_index
= 0;
2368 (char **)xmalloc ((1 + return_val_size
) *sizeof (char *));
2369 return_val
[0] = (char *)NULL
;
2371 /* Look through the partial symtabs for all symbols which begin
2372 by matching TEXT. Add each one that you find to the list. */
2374 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2376 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
2378 /* If the psymtab's been read in we'll get it when we search
2379 through the blockvector. */
2380 if (ps
->readin
) continue;
2382 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2383 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
2384 + ps
->n_global_syms
);
2387 QUIT
; /* If interrupted, then quit. */
2388 if ((strncmp (SYMBOL_NAME (psym
), text
, text_len
) == 0))
2389 completion_list_add_symbol (SYMBOL_NAME (psym
));
2392 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2393 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
2394 + ps
->n_static_syms
);
2398 if ((strncmp (SYMBOL_NAME (psym
), text
, text_len
) == 0))
2399 completion_list_add_symbol (SYMBOL_NAME (psym
));
2404 /* At this point scan through the misc symbol vectors and add each
2405 symbol you find to the list. Eventually we want to ignore
2406 anything that isn't a text symbol (everything else will be
2407 handled by the psymtab code above). */
2409 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2411 for (msymbol
= objfile
-> msymbols
;
2412 msymbol
->name
!= NULL
; msymbol
++)
2414 if (strncmp (text
, msymbol
-> name
, text_len
) == 0)
2416 completion_list_add_symbol (msymbol
-> name
);
2421 /* Search upwards from currently selected frame (so that we can
2422 complete on local vars. */
2423 for (b
= get_selected_block (); b
; b
= BLOCK_SUPERBLOCK (b
))
2425 if (!BLOCK_SUPERBLOCK (b
))
2426 surrounding_static_block
= b
; /* For elmin of dups */
2428 /* Also catch fields of types defined in this places which
2429 match our text string. Only complete on types visible
2430 from current context. */
2431 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2433 register struct symbol
*sym
= BLOCK_SYM (b
, i
);
2435 if (!strncmp (SYMBOL_NAME (sym
), text
, text_len
))
2436 completion_list_add_symbol (SYMBOL_NAME (sym
));
2438 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2440 struct type
*t
= SYMBOL_TYPE (sym
);
2441 enum type_code c
= TYPE_CODE (t
);
2443 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
2444 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
2445 if (TYPE_FIELD_NAME (t
, j
) &&
2446 !strncmp (TYPE_FIELD_NAME (t
, j
), text
, text_len
))
2447 completion_list_add_symbol (TYPE_FIELD_NAME (t
, j
));
2452 /* Go through the symtabs and check the externs and statics for
2453 symbols which match. */
2455 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2457 for (s
= objfile
->symtabs
; s
!= NULL
; s
= s
-> next
)
2459 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
2461 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2462 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b
, i
)), text
, text_len
))
2463 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
2467 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2469 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
2471 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
2473 /* Don't do this block twice. */
2474 if (b
== surrounding_static_block
) continue;
2476 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2477 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b
, i
)), text
, text_len
))
2478 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
2482 return (return_val
);
2486 /* Add the type of the symbol sym to the type of the current
2487 function whose block we are in (assumed). The type of
2488 this current function is contained in *TYPE.
2490 This basically works as follows: When we find a function
2491 symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record
2492 a pointer to its type in the global in_function_type. Every
2493 time we come across a parameter symbol ('p' in its name), then
2494 this procedure adds the name and type of that parameter
2495 to the function type pointed to by *TYPE. (Which should correspond
2496 to in_function_type if it was called correctly).
2498 Note that since we are modifying a type, the result of
2499 lookup_function_type() should be bcopy()ed before calling
2500 this. When not in strict typing mode, the expression
2501 evaluator can choose to ignore this.
2503 Assumption: All of a function's parameter symbols will
2504 appear before another function symbol is found. The parameters
2505 appear in the same order in the argument list as they do in the
2509 add_param_to_type (type
,sym
)
2513 int num
= ++(TYPE_NFIELDS(*type
));
2515 if(TYPE_NFIELDS(*type
)-1)
2516 TYPE_FIELDS(*type
) = (struct field
*)
2517 (*current_objfile
->xrealloc
) ((char *)(TYPE_FIELDS(*type
)),
2518 num
*sizeof(struct field
));
2520 TYPE_FIELDS(*type
) = (struct field
*)
2521 (*current_objfile
->xmalloc
) (num
*sizeof(struct field
));
2523 TYPE_FIELD_BITPOS(*type
,num
-1) = num
-1;
2524 TYPE_FIELD_BITSIZE(*type
,num
-1) = 0;
2525 TYPE_FIELD_TYPE(*type
,num
-1) = SYMBOL_TYPE(sym
);
2526 TYPE_FIELD_NAME(*type
,num
-1) = SYMBOL_NAME(sym
);
2531 _initialize_symtab ()
2533 add_info ("variables", variables_info
,
2534 "All global and static variable names, or those matching REGEXP.");
2535 add_info ("functions", functions_info
,
2536 "All function names, or those matching REGEXP.");
2538 /* FIXME: This command has at least the following problems:
2539 1. It prints builtin types (in a very strange and confusing fashion).
2540 2. It doesn't print right, e.g. with
2541 typedef struct foo *FOO
2542 type_print prints "FOO" when we want to make it (in this situation)
2543 print "struct foo *".
2544 I also think "ptype" or "whatis" is more likely to be useful (but if
2545 there is much disagreement "info types" can be fixed). */
2546 add_info ("types", types_info
,
2547 "All type names, or those matching REGEXP.");
2550 add_info ("methods", methods_info
,
2551 "All method names, or those matching REGEXP::REGEXP.\n\
2552 If the class qualifier is ommited, it is assumed to be the current scope.\n\
2553 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
2556 add_info ("sources", sources_info
,
2557 "Source files in the program.");
2559 add_com ("rbreak", no_class
, rbreak_command
,
2560 "Set a breakpoint for all functions matching REGEXP.");
2562 /* Initialize the one built-in type that isn't language dependent... */
2563 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
2564 "<unknown type>", (struct objfile
*) NULL
);