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 /* sym == 0 if symbol was found in the minimal symbol table
521 but not in the symtab.
522 Return 0 to use the msymbol definition of "foo_".
524 This happens for Fortran "foo_" symbols,
525 which are "foo" in the symtab.
527 This can also happen if "asm" is used to make a
528 regular symbol but not a debugging symbol, e.g.
540 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
542 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
->next
)
544 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
546 s
= PSYMTAB_TO_SYMTAB(ps
);
547 bv
= BLOCKVECTOR (s
);
548 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
549 sym
= lookup_block_symbol (block
, name
, namespace);
551 error ("Internal: global symbol `%s' found in psymtab but not in symtab", name
);
559 /* Now search all per-file blocks.
560 Not strictly correct, but more useful than an error.
561 Do the symtabs first, then check the psymtabs */
563 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
565 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
567 bv
= BLOCKVECTOR (s
);
568 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
569 sym
= lookup_block_symbol (block
, name
, namespace);
580 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
582 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
584 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
586 s
= PSYMTAB_TO_SYMTAB(ps
);
587 bv
= BLOCKVECTOR (s
);
588 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
589 sym
= lookup_block_symbol (block
, name
, namespace);
591 error ("Internal: static symbol `%s' found in psymtab but not in symtab", name
);
599 /* Now search all per-file blocks for static mangled symbols.
600 Do the symtabs first, then check the psymtabs. */
602 if (namespace == VAR_NAMESPACE
)
604 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
606 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
608 bv
= BLOCKVECTOR (s
);
609 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
610 sym
= lookup_demangled_block_symbol (block
, name
);
621 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
623 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
625 if (!ps
->readin
&& lookup_demangled_partial_symbol (ps
, name
))
627 s
= PSYMTAB_TO_SYMTAB(ps
);
628 bv
= BLOCKVECTOR (s
);
629 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
630 sym
= lookup_demangled_block_symbol (block
, name
);
632 error ("Internal: mangled static symbol `%s' found in psymtab but not in symtab", name
);
646 /* Look for a static demangled symbol in block BLOCK. */
648 static struct symbol
*
649 lookup_demangled_block_symbol (block
, name
)
650 register const struct block
*block
;
653 register int bot
, top
, inc
;
654 register struct symbol
*sym
;
657 top
= BLOCK_NSYMS (block
);
662 sym
= BLOCK_SYM (block
, bot
);
663 if (SYMBOL_NAME (sym
)[0] == inc
664 && SYMBOL_NAMESPACE (sym
) == VAR_NAMESPACE
)
666 char *demangled
= cplus_demangle(SYMBOL_NAME (sym
), -1);
667 if (demangled
!= NULL
)
669 int cond
= strcmp (demangled
, name
);
681 /* Look, in partial_symtab PST, for static mangled symbol NAME. */
683 static struct partial_symbol
*
684 lookup_demangled_partial_symbol (pst
, name
)
685 const struct partial_symtab
*pst
;
688 struct partial_symbol
*start
, *psym
;
689 int length
= pst
->n_static_syms
;
690 register int inc
= name
[0];
693 return (struct partial_symbol
*) 0;
695 start
= pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
;
696 for (psym
= start
; psym
< start
+ length
; psym
++)
698 if (SYMBOL_NAME (psym
)[0] == inc
699 && SYMBOL_NAMESPACE (psym
) == VAR_NAMESPACE
)
701 char *demangled
= cplus_demangle(SYMBOL_NAME (psym
), -1);
702 if (demangled
!= NULL
)
704 int cond
= strcmp (demangled
, name
);
712 return (struct partial_symbol
*) 0;
715 /* Look, in partial_symtab PST, for symbol NAME. Check the global
716 symbols if GLOBAL, the static symbols if not */
718 static struct partial_symbol
*
719 lookup_partial_symbol (pst
, name
, global
, namespace)
720 struct partial_symtab
*pst
;
723 enum namespace namespace;
725 struct partial_symbol
*start
, *psym
;
726 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
729 return (struct partial_symbol
*) 0;
732 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
733 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
735 if (global
) /* This means we can use a binary */
738 struct partial_symbol
*top
, *bottom
, *center
;
740 /* Binary search. This search is guaranteed to end with center
741 pointing at the earliest partial symbol with the correct
742 name. At that point *all* partial symbols with that name
743 will be checked against the correct namespace. */
745 top
= start
+ length
- 1;
748 center
= bottom
+ (top
- bottom
) / 2;
750 assert (center
< top
);
752 if (strcmp (SYMBOL_NAME (center
), name
) >= 0)
757 assert (top
== bottom
);
759 while (!strcmp (SYMBOL_NAME (top
), name
))
761 if (SYMBOL_NAMESPACE (top
) == namespace)
768 /* Can't use a binary search */
769 for (psym
= start
; psym
< start
+ length
; psym
++)
770 if (namespace == SYMBOL_NAMESPACE (psym
)
771 && !strcmp (name
, SYMBOL_NAME (psym
)))
775 return (struct partial_symbol
*) 0;
778 /* Find the psymtab containing main(). */
780 struct partial_symtab
*
783 register struct partial_symtab
*pst
;
784 register struct objfile
*objfile
;
786 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
788 for (pst
= objfile
-> psymtabs
; pst
; pst
= pst
->next
)
790 if (lookup_partial_symbol (pst
, "main", 1, VAR_NAMESPACE
))
799 /* Look for a symbol in block BLOCK. */
802 lookup_block_symbol (block
, name
, namespace)
803 register const struct block
*block
;
805 const enum namespace namespace;
807 register int bot
, top
, inc
;
808 register struct symbol
*sym
, *parameter_sym
;
810 top
= BLOCK_NSYMS (block
);
813 /* If the blocks's symbols were sorted, start with a binary search. */
815 if (BLOCK_SHOULD_SORT (block
))
817 /* First, advance BOT to not far before
818 the first symbol whose name is NAME. */
822 inc
= (top
- bot
+ 1);
823 /* No need to keep binary searching for the last few bits worth. */
826 inc
= (inc
>> 1) + bot
;
827 sym
= BLOCK_SYM (block
, inc
);
828 if (SYMBOL_NAME (sym
)[0] < name
[0])
830 else if (SYMBOL_NAME (sym
)[0] > name
[0])
832 else if (strcmp (SYMBOL_NAME (sym
), name
) < 0)
838 /* Now scan forward until we run out of symbols,
839 find one whose name is greater than NAME,
841 If there is more than one symbol with the right name and namespace,
842 we return the first one. dbxread.c is careful to make sure
843 that if one is a register then it comes first. */
845 top
= BLOCK_NSYMS (block
);
848 sym
= BLOCK_SYM (block
, bot
);
849 inc
= SYMBOL_NAME (sym
)[0] - name
[0];
851 inc
= strcmp (SYMBOL_NAME (sym
), name
);
852 if (inc
== 0 && SYMBOL_NAMESPACE (sym
) == namespace)
861 /* Here if block isn't sorted.
862 This loop is equivalent to the loop above,
863 but hacked greatly for speed.
865 Note that parameter symbols do not always show up last in the
866 list; this loop makes sure to take anything else other than
867 parameter symbols first; it only uses parameter symbols as a
868 last resort. Note that this only takes up extra computation
871 parameter_sym
= (struct symbol
*) 0;
872 top
= BLOCK_NSYMS (block
);
876 sym
= BLOCK_SYM (block
, bot
);
877 if (SYMBOL_NAME (sym
)[0] == inc
878 && !strcmp (SYMBOL_NAME (sym
), name
)
879 && SYMBOL_NAMESPACE (sym
) == namespace)
881 if (SYMBOL_CLASS (sym
) == LOC_ARG
882 || SYMBOL_CLASS (sym
) == LOC_LOCAL_ARG
883 || SYMBOL_CLASS (sym
) == LOC_REF_ARG
884 || SYMBOL_CLASS (sym
) == LOC_REGPARM
)
891 return parameter_sym
; /* Will be 0 if not found. */
894 /* Return the symbol for the function which contains a specified
895 lexical block, described by a struct block BL. */
901 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
902 bl
= BLOCK_SUPERBLOCK (bl
);
904 return BLOCK_FUNCTION (bl
);
907 /* Subroutine of find_pc_line */
911 register CORE_ADDR pc
;
913 register struct block
*b
;
914 struct blockvector
*bv
;
915 register struct symtab
*s
= 0;
916 register struct partial_symtab
*ps
;
917 register struct objfile
*objfile
;
920 /* Search all symtabs for one whose file contains our pc */
922 for (found
= 0, objfile
= object_files
;
923 !found
&& objfile
!= NULL
;
924 objfile
= objfile
-> next
)
926 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
928 bv
= BLOCKVECTOR (s
);
929 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
930 if (BLOCK_START (b
) <= pc
931 && BLOCK_END (b
) > pc
)
941 ps
= find_pc_psymtab (pc
);
942 if (ps
&& ps
->readin
)
944 printf_filtered ("(Internal error: pc 0x%x in read in psymtab, but not in symtab.)\n", pc
);
948 s
= PSYMTAB_TO_SYMTAB (ps
);
955 /* Find the source file and line number for a given PC value.
956 Return a structure containing a symtab pointer, a line number,
957 and a pc range for the entire source line.
958 The value's .pc field is NOT the specified pc.
959 NOTCURRENT nonzero means, if specified pc is on a line boundary,
960 use the line that ends there. Otherwise, in that case, the line
961 that begins there is used. */
963 struct symtab_and_line
964 find_pc_line (pc
, notcurrent
)
969 register struct linetable
*l
;
972 register struct linetable_entry
*item
;
973 struct symtab_and_line val
;
974 struct blockvector
*bv
;
976 /* Info on best line seen so far, and where it starts, and its file. */
979 CORE_ADDR best_pc
= 0;
980 CORE_ADDR best_end
= 0;
981 struct symtab
*best_symtab
= 0;
983 /* Store here the first line number
984 of a file which contains the line at the smallest pc after PC.
985 If we don't find a line whose range contains PC,
986 we will use a line one less than this,
987 with a range from the start of that file to the first line's pc. */
989 CORE_ADDR alt_pc
= 0;
990 struct symtab
*alt_symtab
= 0;
992 /* Info on best line seen in this file. */
997 /* Info on first line of this file. */
1002 /* If this pc is not from the current frame,
1003 it is the address of the end of a call instruction.
1004 Quite likely that is the start of the following statement.
1005 But what we want is the statement containing the instruction.
1006 Fudge the pc to make sure we get that. */
1008 if (notcurrent
) pc
-= 1;
1010 s
= find_pc_symtab (pc
);
1020 bv
= BLOCKVECTOR (s
);
1022 /* Look at all the symtabs that share this blockvector.
1023 They all have the same apriori range, that we found was right;
1024 but they have different line tables. */
1026 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1028 /* Find the best line in this symtab. */
1035 for (i
= 0; i
< len
; i
++)
1037 item
= &(l
->item
[i
]);
1041 first_line
= item
->line
;
1042 first_pc
= item
->pc
;
1044 /* Return the last line that did not start after PC. */
1047 prev_line
= item
->line
;
1054 /* Is this file's best line closer than the best in the other files?
1055 If so, record this file, and its best line, as best so far. */
1056 if (prev_line
>= 0 && prev_pc
> best_pc
)
1059 best_line
= prev_line
;
1061 /* If another line is in the linetable, and its PC is closer
1062 than the best_end we currently have, take it as best_end. */
1063 if (i
< len
&& (best_end
== 0 || best_end
> item
->pc
))
1064 best_end
= item
->pc
;
1066 /* Is this file's first line closer than the first lines of other files?
1067 If so, record this file, and its first line, as best alternate. */
1068 if (first_line
>= 0 && first_pc
> pc
1069 && (alt_pc
== 0 || first_pc
< alt_pc
))
1072 alt_line
= first_line
;
1076 if (best_symtab
== 0)
1078 val
.symtab
= alt_symtab
;
1079 val
.line
= alt_line
- 1;
1080 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1085 val
.symtab
= best_symtab
;
1086 val
.line
= best_line
;
1088 if (best_end
&& (alt_pc
== 0 || best_end
< alt_pc
))
1093 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1098 /* Find the PC value for a given source file and line number.
1099 Returns zero for invalid line number.
1100 The source file is specified with a struct symtab. */
1103 find_line_pc (symtab
, line
)
1104 struct symtab
*symtab
;
1107 register struct linetable
*l
;
1113 l
= LINETABLE (symtab
);
1114 ind
= find_line_common(l
, line
, &dummy
);
1115 return (ind
>= 0) ? l
->item
[ind
].pc
: 0;
1118 /* Find the range of pc values in a line.
1119 Store the starting pc of the line into *STARTPTR
1120 and the ending pc (start of next line) into *ENDPTR.
1121 Returns 1 to indicate success.
1122 Returns 0 if could not find the specified line. */
1125 find_line_pc_range (symtab
, thisline
, startptr
, endptr
)
1126 struct symtab
*symtab
;
1128 CORE_ADDR
*startptr
, *endptr
;
1130 register struct linetable
*l
;
1132 int exact_match
; /* did we get an exact linenumber match */
1137 l
= LINETABLE (symtab
);
1138 ind
= find_line_common (l
, thisline
, &exact_match
);
1141 *startptr
= l
->item
[ind
].pc
;
1142 /* If we have not seen an entry for the specified line,
1143 assume that means the specified line has zero bytes. */
1144 if (!exact_match
|| ind
== l
->nitems
-1)
1145 *endptr
= *startptr
;
1147 /* Perhaps the following entry is for the following line.
1148 It's worth a try. */
1149 if (ind
+1 < l
->nitems
1150 && l
->item
[ind
+1].line
== thisline
+ 1)
1151 *endptr
= l
->item
[ind
+1].pc
;
1153 *endptr
= find_line_pc (symtab
, thisline
+1);
1160 /* Given a line table and a line number, return the index into the line
1161 table for the pc of the nearest line whose number is >= the specified one.
1162 Return -1 if none is found. The value is >= 0 if it is an index.
1164 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1167 find_line_common (l
, lineno
, exact_match
)
1168 register struct linetable
*l
;
1169 register int lineno
;
1175 /* BEST is the smallest linenumber > LINENO so far seen,
1176 or 0 if none has been seen so far.
1177 BEST_INDEX identifies the item for it. */
1179 int best_index
= -1;
1188 for (i
= 0; i
< len
; i
++)
1190 register struct linetable_entry
*item
= &(l
->item
[i
]);
1192 if (item
->line
== lineno
)
1198 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
1205 /* If we got here, we didn't get an exact match. */
1212 find_pc_line_pc_range (pc
, startptr
, endptr
)
1214 CORE_ADDR
*startptr
, *endptr
;
1216 struct symtab_and_line sal
;
1217 sal
= find_pc_line (pc
, 0);
1220 return sal
.symtab
!= 0;
1223 /* If P is of the form "operator[ \t]+..." where `...' is
1224 some legitimate operator text, return a pointer to the
1225 beginning of the substring of the operator text.
1226 Otherwise, return "". */
1228 operator_chars (p
, end
)
1233 if (strncmp (p
, "operator", 8))
1237 /* Don't get faked out by `operator' being part of a longer
1239 if ((*p
>= 'A' && *p
<= 'Z') || (*p
>= 'a' && *p
<= 'z')
1240 || *p
== '_' || *p
== '$' || *p
== '\0')
1243 /* Allow some whitespace between `operator' and the operator symbol. */
1244 while (*p
== ' ' || *p
== '\t')
1266 if (p
[1] == '=' || p
[1] == p
[0])
1277 error ("`operator ()' must be specified without whitespace in `()'");
1282 error ("`operator ?:' must be specified without whitespace in `?:'");
1287 error ("`operator []' must be specified without whitespace in `[]'");
1291 error ("`operator %s' not supported", p
);
1298 /* Recursive helper function for decode_line_1.
1299 * Look for methods named NAME in type T.
1300 * Return number of matches.
1301 * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1302 * These allocations seem to define "big enough":
1303 * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1304 * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1308 find_methods (t
, name
, physnames
, sym_arr
)
1312 struct symbol
**sym_arr
;
1316 struct symbol
*sym_class
;
1317 char *class_name
= type_name_no_tag (t
);
1318 /* Ignore this class if it doesn't have a name.
1319 This prevents core dumps, but is just a workaround
1320 because we might not find the function in
1321 certain cases, such as
1322 struct D {virtual int f();}
1323 struct C : D {virtual int g();}
1324 (in this case g++ 1.35.1- does not put out a name
1325 for D as such, it defines type 19 (for example) in
1326 the same stab as C, and then does a
1327 .stabs "D:T19" and a .stabs "D:t19".
1329 "break C::f" should not be looking for field f in
1331 but just for the field f in the baseclasses of C
1332 (no matter what their names).
1334 However, I don't know how to replace the code below
1335 that depends on knowing the name of D. */
1337 && (sym_class
= lookup_symbol (class_name
,
1338 (struct block
*)NULL
,
1341 (struct symtab
**)NULL
)))
1344 t
= SYMBOL_TYPE (sym_class
);
1345 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
1346 method_counter
>= 0;
1350 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
1352 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
1353 if (!strcmp (name
, method_name
))
1354 /* Find all the fields with that name. */
1355 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
1360 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
1361 check_stub_method (t
, method_counter
, field_counter
);
1362 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
1363 physnames
[i1
] = (char*) alloca (strlen (phys_name
) + 1);
1364 strcpy (physnames
[i1
], phys_name
);
1365 sym_arr
[i1
] = lookup_symbol (phys_name
,
1366 SYMBOL_BLOCK_VALUE (sym_class
),
1369 (struct symtab
**) NULL
);
1370 if (sym_arr
[i1
]) i1
++;
1374 /* Only search baseclasses if there is no match yet,
1375 * since names in derived classes override those in baseclasses.
1379 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
1380 i1
+= find_methods(TYPE_BASECLASS(t
, ibase
), name
,
1381 physnames
+ i1
, sym_arr
+ i1
);
1385 /* Parse a string that specifies a line number.
1386 Pass the address of a char * variable; that variable will be
1387 advanced over the characters actually parsed.
1391 LINENUM -- that line number in current file. PC returned is 0.
1392 FILE:LINENUM -- that line in that file. PC returned is 0.
1393 FUNCTION -- line number of openbrace of that function.
1394 PC returned is the start of the function.
1395 VARIABLE -- line number of definition of that variable.
1397 FILE:FUNCTION -- likewise, but prefer functions in that file.
1398 *EXPR -- line in which address EXPR appears.
1400 FUNCTION may be an undebuggable function found in minimal symbol table.
1402 If the argument FUNFIRSTLINE is nonzero, we want the first line
1403 of real code inside a function when a function is specified.
1405 DEFAULT_SYMTAB specifies the file to use if none is specified.
1406 It defaults to current_source_symtab.
1407 DEFAULT_LINE specifies the line number to use for relative
1408 line numbers (that start with signs). Defaults to current_source_line.
1410 Note that it is possible to return zero for the symtab
1411 if no file is validly specified. Callers must check that.
1412 Also, the line number returned may be invalid. */
1414 struct symtabs_and_lines
1415 decode_line_1 (argptr
, funfirstline
, default_symtab
, default_line
)
1418 struct symtab
*default_symtab
;
1421 struct symtabs_and_lines values
;
1422 struct symtab_and_line val
;
1423 register char *p
, *p1
;
1425 register struct symtab
*s
;
1427 register struct symbol
*sym
;
1428 /* The symtab that SYM was found in. */
1429 struct symtab
*sym_symtab
;
1431 register CORE_ADDR pc
;
1432 register struct minimal_symbol
*msymbol
;
1434 struct symbol
*sym_class
;
1436 struct symbol
**sym_arr
;
1440 /* Defaults have defaults. */
1442 if (default_symtab
== 0)
1444 default_symtab
= current_source_symtab
;
1445 default_line
= current_source_line
;
1448 /* See if arg is *PC */
1450 if (**argptr
== '*')
1453 pc
= parse_and_eval_address_1 (argptr
);
1454 values
.sals
= (struct symtab_and_line
*)
1455 xmalloc (sizeof (struct symtab_and_line
));
1457 values
.sals
[0] = find_pc_line (pc
, 0);
1458 values
.sals
[0].pc
= pc
;
1462 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1466 for (p
= *argptr
; *p
; p
++)
1468 if (p
[0] == ':' || p
[0] == ' ' || p
[0] == '\t')
1471 while (p
[0] == ' ' || p
[0] == '\t') p
++;
1479 /* Extract the class name. */
1481 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1482 copy
= (char *) alloca (p
- *argptr
+ 1);
1483 bcopy (*argptr
, copy
, p
- *argptr
);
1484 copy
[p
- *argptr
] = 0;
1486 /* Discard the class name from the arg. */
1488 while (*p
== ' ' || *p
== '\t') p
++;
1491 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
1492 (struct symtab
**)NULL
);
1495 ( TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_STRUCT
1496 || TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_UNION
))
1498 /* Arg token is not digits => try it as a function name
1499 Find the next token (everything up to end or next whitespace). */
1501 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',' && *p
!=':') p
++;
1502 q
= operator_chars (*argptr
, &q1
);
1504 copy
= (char *) alloca (p
- *argptr
+ 1 + (q1
- q
));
1509 copy
[2] = CPLUS_MARKER
;
1510 bcopy (q
, copy
+ 3, q1
- q
);
1511 copy
[3 + (q1
- q
)] = '\0';
1516 bcopy (*argptr
, copy
, p
- *argptr
);
1517 copy
[p
- *argptr
] = '\0';
1520 /* no line number may be specified */
1521 while (*p
== ' ' || *p
== '\t') p
++;
1525 i1
= 0; /* counter for the symbol array */
1526 t
= SYMBOL_TYPE (sym_class
);
1527 sym_arr
= (struct symbol
**) alloca(TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(struct symbol
*));
1528 physnames
= (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(char*));
1530 if (destructor_name_p (copy
, t
))
1532 /* destructors are a special case. */
1533 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, 0);
1534 int len
= TYPE_FN_FIELDLIST_LENGTH (t
, 0) - 1;
1535 char *phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, len
);
1536 physnames
[i1
] = (char *)alloca (strlen (phys_name
) + 1);
1537 strcpy (physnames
[i1
], phys_name
);
1539 lookup_symbol (phys_name
, SYMBOL_BLOCK_VALUE (sym_class
),
1540 VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
1541 if (sym_arr
[i1
]) i1
++;
1544 i1
= find_methods (t
, copy
, physnames
, sym_arr
);
1547 /* There is exactly one field with that name. */
1550 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1552 /* Arg is the name of a function */
1553 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1556 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1558 values
.sals
[0] = find_pc_line (pc
, 0);
1559 values
.sals
[0].pc
= (values
.sals
[0].end
&& values
.sals
[0].pc
!= pc
) ? values
.sals
[0].end
: pc
;
1569 /* There is more than one field with that name
1570 (overloaded). Ask the user which one to use. */
1571 return decode_line_2 (sym_arr
, i1
, funfirstline
);
1577 if (OPNAME_PREFIX_P (copy
))
1579 tmp
= (char *)alloca (strlen (copy
+3) + 9);
1580 strcpy (tmp
, "operator ");
1581 strcat (tmp
, copy
+3);
1586 error ("The class `%s' does not have destructor defined",
1589 error ("The class %s does not have any method named %s",
1590 sym_class
->name
, tmp
);
1594 /* The quotes are important if copy is empty. */
1595 error("No class, struct, or union named \"%s\"", copy
);
1600 /* Extract the file name. */
1602 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1603 copy
= (char *) alloca (p
- *argptr
+ 1);
1604 bcopy (*argptr
, copy
, p
- *argptr
);
1605 copy
[p
- *argptr
] = 0;
1607 /* Find that file's data. */
1608 s
= lookup_symtab (copy
);
1611 if (!have_full_symbols () && !have_partial_symbols ())
1612 error (no_symtab_msg
);
1613 error ("No source file named %s.", copy
);
1616 /* Discard the file name from the arg. */
1618 while (*p
== ' ' || *p
== '\t') p
++;
1622 /* S is specified file's symtab, or 0 if no file specified.
1623 arg no longer contains the file name. */
1625 /* Check whether arg is all digits (and sign) */
1628 if (*p
== '-' || *p
== '+') p
++;
1629 while (*p
>= '0' && *p
<= '9')
1632 if (p
!= *argptr
&& (*p
== 0 || *p
== ' ' || *p
== '\t' || *p
== ','))
1634 /* We found a token consisting of all digits -- at least one digit. */
1635 enum sign
{none
, plus
, minus
} sign
= none
;
1637 /* This is where we need to make sure that we have good defaults.
1638 We must guarantee that this section of code is never executed
1639 when we are called with just a function name, since
1640 select_source_symtab calls us with such an argument */
1642 if (s
== 0 && default_symtab
== 0)
1644 select_source_symtab (0);
1645 default_symtab
= current_source_symtab
;
1646 default_line
= current_source_line
;
1649 if (**argptr
== '+')
1650 sign
= plus
, (*argptr
)++;
1651 else if (**argptr
== '-')
1652 sign
= minus
, (*argptr
)++;
1653 val
.line
= atoi (*argptr
);
1660 val
.line
= default_line
+ val
.line
;
1666 val
.line
= default_line
- val
.line
;
1671 break; /* No need to adjust val.line. */
1674 while (*p
== ' ' || *p
== '\t') p
++;
1680 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1681 values
.sals
[0] = val
;
1686 /* Arg token is not digits => try it as a variable name
1687 Find the next token (everything up to end or next whitespace). */
1689 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',') p
++;
1690 copy
= (char *) alloca (p
- *argptr
+ 1);
1691 bcopy (*argptr
, copy
, p
- *argptr
);
1692 copy
[p
- *argptr
] = 0;
1693 while (*p
== ' ' || *p
== '\t') p
++;
1696 /* Look up that token as a variable.
1697 If file specified, use that file's per-file block to start with. */
1699 sym
= lookup_symbol (copy
,
1700 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
1701 : get_selected_block ()),
1702 VAR_NAMESPACE
, 0, &sym_symtab
);
1706 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1708 /* Arg is the name of a function */
1709 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1712 val
= find_pc_line (pc
, 0);
1713 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1714 /* Convex: no need to suppress code on first line, if any */
1717 /* If SKIP_PROLOGUE left us in mid-line, and the next line is still
1718 part of the same function:
1719 advance to next line,
1720 recalculate its line number (might not be N+1). */
1721 if (val
.pc
!= pc
&& val
.end
&&
1722 lookup_minimal_symbol_by_pc (pc
) == lookup_minimal_symbol_by_pc (val
.end
)) {
1723 pc
= val
.end
; /* First pc of next line */
1724 val
= find_pc_line (pc
, 0);
1728 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1729 values
.sals
[0] = val
;
1732 /* I think this is always the same as the line that
1733 we calculate above, but the general principle is
1734 "trust the symbols more than stuff like
1736 if (SYMBOL_LINE (sym
) != 0)
1737 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1741 else if (SYMBOL_LINE (sym
) != 0)
1743 /* We know its line number. */
1744 values
.sals
= (struct symtab_and_line
*)
1745 xmalloc (sizeof (struct symtab_and_line
));
1747 bzero (&values
.sals
[0], sizeof (values
.sals
[0]));
1748 values
.sals
[0].symtab
= sym_symtab
;
1749 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1753 /* This can happen if it is compiled with a compiler which doesn't
1754 put out line numbers for variables. */
1755 error ("Line number not known for symbol \"%s\"", copy
);
1758 msymbol
= lookup_minimal_symbol (copy
, (struct objfile
*) NULL
);
1759 if (msymbol
!= NULL
)
1763 val
.pc
= msymbol
-> address
+ FUNCTION_START_OFFSET
;
1765 SKIP_PROLOGUE (val
.pc
);
1766 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1767 values
.sals
[0] = val
;
1772 if (!have_full_symbols () &&
1773 !have_partial_symbols () && !have_minimal_symbols ())
1774 error (no_symtab_msg
);
1776 error ("Function %s not defined.", copy
);
1777 return values
; /* for lint */
1780 struct symtabs_and_lines
1781 decode_line_spec (string
, funfirstline
)
1785 struct symtabs_and_lines sals
;
1787 error ("Empty line specification.");
1788 sals
= decode_line_1 (&string
, funfirstline
,
1789 current_source_symtab
, current_source_line
);
1791 error ("Junk at end of line specification: %s", string
);
1795 /* Given a list of NELTS symbols in sym_arr (with corresponding
1796 mangled names in physnames), return a list of lines to operate on
1797 (ask user if necessary). */
1798 static struct symtabs_and_lines
1799 decode_line_2 (sym_arr
, nelts
, funfirstline
)
1800 struct symbol
*sym_arr
[];
1804 struct symtabs_and_lines values
, return_values
;
1805 register CORE_ADDR pc
;
1810 values
.sals
= (struct symtab_and_line
*) alloca (nelts
* sizeof(struct symtab_and_line
));
1811 return_values
.sals
= (struct symtab_and_line
*) xmalloc (nelts
* sizeof(struct symtab_and_line
));
1814 printf("[0] cancel\n[1] all\n");
1817 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
1819 /* Arg is the name of a function */
1820 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr
[i
]))
1821 + FUNCTION_START_OFFSET
;
1824 values
.sals
[i
] = find_pc_line (pc
, 0);
1825 values
.sals
[i
].pc
= (values
.sals
[i
].end
&& values
.sals
[i
].pc
!= pc
) ?
1826 values
.sals
[i
].end
: pc
;
1827 printf("[%d] file:%s; line number:%d\n",
1828 (i
+2), values
.sals
[i
].symtab
->filename
, values
.sals
[i
].line
);
1830 else printf ("?HERE\n");
1834 if ((prompt
= getenv ("PS2")) == NULL
)
1838 printf("%s ",prompt
);
1841 args
= command_line_input ((char *) NULL
, 0);
1844 error_no_arg ("one or more choice numbers");
1852 while (*arg1
>= '0' && *arg1
<= '9') arg1
++;
1853 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
1854 error ("Arguments must be choice numbers.");
1859 error ("cancelled");
1862 bcopy (values
.sals
, return_values
.sals
, (nelts
* sizeof(struct symtab_and_line
)));
1863 return_values
.nelts
= nelts
;
1864 return return_values
;
1867 if (num
> nelts
+ 2)
1869 printf ("No choice number %d.\n", num
);
1874 if (values
.sals
[num
].pc
)
1876 return_values
.sals
[i
++] = values
.sals
[num
];
1877 values
.sals
[num
].pc
= 0;
1881 printf ("duplicate request for %d ignored.\n", num
);
1886 while (*args
== ' ' || *args
== '\t') args
++;
1888 return_values
.nelts
= i
;
1889 return return_values
;
1893 /* Slave routine for sources_info. Force line breaks at ,'s.
1894 NAME is the name to print and *FIRST is nonzero if this is the first
1895 name printed. Set *FIRST to zero. */
1897 output_source_filename (name
, first
)
1901 static unsigned int column
;
1902 /* Table of files printed so far. Since a single source file can
1903 result in several partial symbol tables, we need to avoid printing
1904 it more than once. Note: if some of the psymtabs are read in and
1905 some are not, it gets printed both under "Source files for which
1906 symbols have been read" and "Source files for which symbols will
1907 be read in on demand". I consider this a reasonable way to deal
1908 with the situation. I'm not sure whether this can also happen for
1909 symtabs; it doesn't hurt to check. */
1910 static char **tab
= NULL
;
1911 /* Allocated size of tab in elements.
1912 Start with one 256-byte block (when using GNU malloc.c).
1913 24 is the malloc overhead when range checking is in effect. */
1914 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
1915 /* Current size of tab in elements. */
1916 static int tab_cur_size
;
1923 tab
= (char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
1927 /* Is NAME in tab? */
1928 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
1929 if (strcmp (*p
, name
) == 0)
1930 /* Yes; don't print it again. */
1932 /* No; add it to tab. */
1933 if (tab_cur_size
== tab_alloc_size
)
1935 tab_alloc_size
*= 2;
1936 tab
= (char **) xrealloc ((char *) tab
, tab_alloc_size
* sizeof (*tab
));
1938 tab
[tab_cur_size
++] = name
;
1947 printf_filtered (",");
1951 if (column
!= 0 && column
+ strlen (name
) >= 70)
1953 printf_filtered ("\n");
1956 else if (column
!= 0)
1958 printf_filtered (" ");
1961 fputs_filtered (name
, stdout
);
1962 column
+= strlen (name
);
1968 register struct symtab
*s
;
1969 register struct partial_symtab
*ps
;
1970 register struct objfile
*objfile
;
1973 if (!have_full_symbols () && !have_partial_symbols ())
1975 error (no_symtab_msg
);
1978 printf_filtered ("Source files for which symbols have been read in:\n\n");
1981 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
1983 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
1985 output_source_filename (s
-> filename
, &first
);
1988 printf_filtered ("\n\n");
1990 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
1993 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
1995 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
1999 output_source_filename (ps
-> filename
, &first
);
2003 printf_filtered ("\n");
2006 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2007 If CLASS is zero, list all symbols except functions and type names.
2008 If CLASS is 1, list only functions.
2009 If CLASS is 2, list only type names.
2010 If CLASS is 3, list only method names.
2012 BPT is non-zero if we should set a breakpoint at the functions
2016 list_symbols (regexp
, class, bpt
)
2021 register struct symtab
*s
;
2022 register struct partial_symtab
*ps
;
2023 register struct blockvector
*bv
;
2024 struct blockvector
*prev_bv
= 0;
2025 register struct block
*b
;
2027 register struct symbol
*sym
;
2028 struct partial_symbol
*psym
;
2029 struct objfile
*objfile
;
2030 struct minimal_symbol
*msymbol
;
2032 static char *classnames
[]
2033 = {"variable", "function", "type", "method"};
2034 int found_in_file
= 0;
2036 static enum minimal_symbol_type types
[]
2037 = {mst_data
, mst_text
, mst_abs
, mst_unknown
};
2038 static enum minimal_symbol_type types2
[]
2039 = {mst_bss
, mst_text
, mst_abs
, mst_unknown
};
2040 enum minimal_symbol_type ourtype
= types
[class];
2041 enum minimal_symbol_type ourtype2
= types2
[class];
2044 if (0 != (val
= re_comp (regexp
)))
2045 error ("Invalid regexp (%s): %s", val
, regexp
);
2047 /* Search through the partial symtabs *first* for all symbols
2048 matching the regexp. That way we don't have to reproduce all of
2049 the machinery below. */
2051 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2053 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
2055 struct partial_symbol
*bound
, *gbound
, *sbound
;
2058 if (ps
->readin
) continue;
2060 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2061 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2064 /* Go through all of the symbols stored in a partial
2065 symtab in one loop. */
2066 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2071 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2073 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2084 /* If it would match (logic taken from loop below)
2085 load the file and go on to the next one */
2086 if ((regexp
== 0 || re_exec (SYMBOL_NAME (psym
)))
2087 && ((class == 0 && SYMBOL_CLASS (psym
) != LOC_TYPEDEF
2088 && SYMBOL_CLASS (psym
) != LOC_BLOCK
)
2089 || (class == 1 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)
2090 || (class == 2 && SYMBOL_CLASS (psym
) == LOC_TYPEDEF
)
2091 || (class == 3 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)))
2093 (void) PSYMTAB_TO_SYMTAB(ps
);
2102 /* Here, we search through the minimal symbol tables for functions that
2103 match, and call find_pc_symtab on them to force their symbols to
2104 be read. The symbol will then be found during the scan of symtabs
2105 below. If find_pc_symtab fails, set found_misc so that we will
2106 rescan to print any matching symbols without debug info. */
2110 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2112 for (msymbol
= objfile
-> msymbols
;
2113 msymbol
-> name
!= NULL
; msymbol
++)
2115 if (msymbol
-> type
== ourtype
|| msymbol
-> type
== ourtype2
)
2117 if (regexp
== 0 || re_exec (msymbol
-> name
))
2119 if (0 == find_pc_symtab (msymbol
-> address
))
2129 /* Printout here so as to get after the "Reading in symbols"
2130 messages which will be generated above. */
2132 printf_filtered (regexp
2133 ? "All %ss matching regular expression \"%s\":\n"
2134 : "All defined %ss:\n",
2138 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2140 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
2143 bv
= BLOCKVECTOR (s
);
2144 /* Often many files share a blockvector.
2145 Scan each blockvector only once so that
2146 we don't get every symbol many times.
2147 It happens that the first symtab in the list
2148 for any given blockvector is the main file. */
2150 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
2152 b
= BLOCKVECTOR_BLOCK (bv
, i
);
2153 /* Skip the sort if this block is always sorted. */
2154 if (!BLOCK_SHOULD_SORT (b
))
2155 sort_block_syms (b
);
2156 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
2159 sym
= BLOCK_SYM (b
, j
);
2160 if ((regexp
== 0 || re_exec (SYMBOL_NAME (sym
)))
2161 && ((class == 0 && SYMBOL_CLASS (sym
) != LOC_TYPEDEF
2162 && SYMBOL_CLASS (sym
) != LOC_BLOCK
)
2163 || (class == 1 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2164 || (class == 2 && SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2165 || (class == 3 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)))
2169 /* Set a breakpoint here, if it's a function */
2171 break_command (SYMBOL_NAME(sym
), 0);
2173 else if (!found_in_file
)
2175 fputs_filtered ("\nFile ", stdout
);
2176 fputs_filtered (s
->filename
, stdout
);
2177 fputs_filtered (":\n", stdout
);
2181 if (class != 2 && i
== STATIC_BLOCK
)
2182 printf_filtered ("static ");
2184 /* Typedef that is not a C++ class */
2186 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
2187 typedef_print (SYMBOL_TYPE(sym
), sym
, stdout
);
2188 /* variable, func, or typedef-that-is-c++-class */
2189 else if (class < 2 ||
2191 SYMBOL_NAMESPACE(sym
) == STRUCT_NAMESPACE
))
2193 type_print (SYMBOL_TYPE (sym
),
2194 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2195 ? "" : SYMBOL_NAME (sym
)),
2198 printf_filtered (";\n");
2204 type_print_base (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0, 0);
2205 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0);
2206 sprintf (buf
, " %s::", type_name_no_tag (t
));
2207 type_print_method_args (TYPE_FN_FIELD_ARGS (t
, i
), buf
, name
, stdout
);
2217 /* If there are no eyes, avoid all contact. I mean, if there are
2218 no debug symbols, then print directly from the msymbol_vector. */
2220 if (found_misc
|| class != 1)
2223 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2225 for (msymbol
= objfile
-> msymbols
;
2226 msymbol
-> name
!= NULL
; msymbol
++)
2228 if (msymbol
-> type
== ourtype
|| msymbol
-> type
== ourtype2
)
2230 if (regexp
== 0 || re_exec (msymbol
-> name
))
2232 /* Functions: Look up by address. */
2234 (find_pc_symtab (msymbol
-> address
) != NULL
))
2236 /* Variables/Absolutes: Look up by name */
2237 if (lookup_symbol (msymbol
-> name
,
2238 (struct block
*) 0, VAR_NAMESPACE
, 0,
2239 (struct symtab
**) 0) == NULL
)
2243 printf_filtered ("\nNon-debugging symbols:\n");
2246 printf_filtered (" %08x %s\n",
2259 variables_info (regexp
)
2262 list_symbols (regexp
, 0, 0);
2266 functions_info (regexp
)
2269 list_symbols (regexp
, 1, 0);
2276 list_symbols (regexp
, 2, 0);
2280 /* Tiemann says: "info methods was never implemented." */
2282 methods_info (regexp
)
2285 list_symbols (regexp
, 3, 0);
2289 /* Breakpoint all functions matching regular expression. */
2291 rbreak_command (regexp
)
2294 list_symbols (regexp
, 1, 1);
2298 /* Return Nonzero if block a is lexically nested within block b,
2299 or if a and b have the same pc range.
2300 Return zero otherwise. */
2303 struct block
*a
, *b
;
2307 return BLOCK_START (a
) >= BLOCK_START (b
)
2308 && BLOCK_END (a
) <= BLOCK_END (b
);
2312 /* Helper routine for make_symbol_completion_list. */
2314 int return_val_size
, return_val_index
;
2318 completion_list_add_symbol (symname
)
2321 if (return_val_index
+ 3 > return_val_size
)
2322 return_val
= (char **) xrealloc ((char *) return_val
,
2323 (return_val_size
*= 2) * sizeof (char *));
2325 return_val
[return_val_index
] =
2326 (char *)xmalloc (1 + strlen (symname
));
2328 strcpy (return_val
[return_val_index
], symname
);
2330 return_val
[++return_val_index
] = (char *)NULL
;
2333 /* Return a NULL terminated array of all symbols (regardless of class) which
2334 begin by matching TEXT. If the answer is no symbols, then the return value
2335 is an array which contains only a NULL pointer.
2337 Problem: All of the symbols have to be copied because readline
2338 frees them. I'm not going to worry about this; hopefully there
2339 won't be that many. */
2342 make_symbol_completion_list (text
)
2345 register struct symtab
*s
;
2346 register struct partial_symtab
*ps
;
2347 register struct minimal_symbol
*msymbol
;
2348 register struct objfile
*objfile
;
2349 register struct block
*b
, *surrounding_static_block
= 0;
2351 struct partial_symbol
*psym
;
2353 int text_len
= strlen (text
);
2354 return_val_size
= 100;
2355 return_val_index
= 0;
2357 (char **)xmalloc ((1 + return_val_size
) *sizeof (char *));
2358 return_val
[0] = (char *)NULL
;
2360 /* Look through the partial symtabs for all symbols which begin
2361 by matching TEXT. Add each one that you find to the list. */
2363 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2365 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
2367 /* If the psymtab's been read in we'll get it when we search
2368 through the blockvector. */
2369 if (ps
->readin
) continue;
2371 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2372 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
2373 + ps
->n_global_syms
);
2376 QUIT
; /* If interrupted, then quit. */
2377 if ((strncmp (SYMBOL_NAME (psym
), text
, text_len
) == 0))
2378 completion_list_add_symbol (SYMBOL_NAME (psym
));
2381 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2382 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
2383 + ps
->n_static_syms
);
2387 if ((strncmp (SYMBOL_NAME (psym
), text
, text_len
) == 0))
2388 completion_list_add_symbol (SYMBOL_NAME (psym
));
2393 /* At this point scan through the misc symbol vectors and add each
2394 symbol you find to the list. Eventually we want to ignore
2395 anything that isn't a text symbol (everything else will be
2396 handled by the psymtab code above). */
2398 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2400 for (msymbol
= objfile
-> msymbols
;
2401 msymbol
->name
!= NULL
; msymbol
++)
2403 if (strncmp (text
, msymbol
-> name
, text_len
) == 0)
2405 completion_list_add_symbol (msymbol
-> name
);
2410 /* Search upwards from currently selected frame (so that we can
2411 complete on local vars. */
2412 for (b
= get_selected_block (); b
; b
= BLOCK_SUPERBLOCK (b
))
2414 if (!BLOCK_SUPERBLOCK (b
))
2415 surrounding_static_block
= b
; /* For elmin of dups */
2417 /* Also catch fields of types defined in this places which
2418 match our text string. Only complete on types visible
2419 from current context. */
2420 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2422 register struct symbol
*sym
= BLOCK_SYM (b
, i
);
2424 if (!strncmp (SYMBOL_NAME (sym
), text
, text_len
))
2425 completion_list_add_symbol (SYMBOL_NAME (sym
));
2427 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2429 struct type
*t
= SYMBOL_TYPE (sym
);
2430 enum type_code c
= TYPE_CODE (t
);
2432 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
2433 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
2434 if (TYPE_FIELD_NAME (t
, j
) &&
2435 !strncmp (TYPE_FIELD_NAME (t
, j
), text
, text_len
))
2436 completion_list_add_symbol (TYPE_FIELD_NAME (t
, j
));
2441 /* Go through the symtabs and check the externs and statics for
2442 symbols which match. */
2444 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2446 for (s
= objfile
->symtabs
; s
!= NULL
; s
= s
-> next
)
2448 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
2450 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2451 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b
, i
)), text
, text_len
))
2452 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
2456 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2458 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
2460 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
2462 /* Don't do this block twice. */
2463 if (b
== surrounding_static_block
) continue;
2465 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2466 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b
, i
)), text
, text_len
))
2467 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
2471 return (return_val
);
2475 /* Add the type of the symbol sym to the type of the current
2476 function whose block we are in (assumed). The type of
2477 this current function is contained in *TYPE.
2479 This basically works as follows: When we find a function
2480 symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record
2481 a pointer to its type in the global in_function_type. Every
2482 time we come across a parameter symbol ('p' in its name), then
2483 this procedure adds the name and type of that parameter
2484 to the function type pointed to by *TYPE. (Which should correspond
2485 to in_function_type if it was called correctly).
2487 Note that since we are modifying a type, the result of
2488 lookup_function_type() should be bcopy()ed before calling
2489 this. When not in strict typing mode, the expression
2490 evaluator can choose to ignore this.
2492 Assumption: All of a function's parameter symbols will
2493 appear before another function symbol is found. The parameters
2494 appear in the same order in the argument list as they do in the
2498 add_param_to_type (type
,sym
)
2502 int num
= ++(TYPE_NFIELDS(*type
));
2504 if(TYPE_NFIELDS(*type
)-1)
2505 TYPE_FIELDS(*type
) = (struct field
*)
2506 (*current_objfile
->xrealloc
) ((char *)(TYPE_FIELDS(*type
)),
2507 num
*sizeof(struct field
));
2509 TYPE_FIELDS(*type
) = (struct field
*)
2510 (*current_objfile
->xmalloc
) (num
*sizeof(struct field
));
2512 TYPE_FIELD_BITPOS(*type
,num
-1) = num
-1;
2513 TYPE_FIELD_BITSIZE(*type
,num
-1) = 0;
2514 TYPE_FIELD_TYPE(*type
,num
-1) = SYMBOL_TYPE(sym
);
2515 TYPE_FIELD_NAME(*type
,num
-1) = SYMBOL_NAME(sym
);
2520 _initialize_symtab ()
2522 add_info ("variables", variables_info
,
2523 "All global and static variable names, or those matching REGEXP.");
2524 add_info ("functions", functions_info
,
2525 "All function names, or those matching REGEXP.");
2527 /* FIXME: This command has at least the following problems:
2528 1. It prints builtin types (in a very strange and confusing fashion).
2529 2. It doesn't print right, e.g. with
2530 typedef struct foo *FOO
2531 type_print prints "FOO" when we want to make it (in this situation)
2532 print "struct foo *".
2533 I also think "ptype" or "whatis" is more likely to be useful (but if
2534 there is much disagreement "info types" can be fixed). */
2535 add_info ("types", types_info
,
2536 "All type names, or those matching REGEXP.");
2539 add_info ("methods", methods_info
,
2540 "All method names, or those matching REGEXP::REGEXP.\n\
2541 If the class qualifier is ommited, it is assumed to be the current scope.\n\
2542 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
2545 add_info ("sources", sources_info
,
2546 "Source files in the program.");
2548 add_com ("rbreak", no_class
, rbreak_command
,
2549 "Set a breakpoint for all functions matching REGEXP.");
2551 /* Initialize the one built-in type that isn't language dependent... */
2552 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
2553 "<unknown type>", (struct objfile
*) NULL
);