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. */
30 #include "expression.h"
36 #include <sys/types.h>
41 /* Prototypes for local functions */
44 find_methods
PARAMS ((struct type
*, char *, char **, struct symbol
**));
47 completion_list_add_symbol
PARAMS ((char *));
49 static struct symtabs_and_lines
50 decode_line_2
PARAMS ((struct symbol
*[], int, int));
53 rbreak_command
PARAMS ((char *));
56 types_info
PARAMS ((char *));
59 functions_info
PARAMS ((char *));
62 variables_info
PARAMS ((char *));
65 list_symbols
PARAMS ((char *, int, int));
68 sources_info
PARAMS ((void));
71 output_source_filename
PARAMS ((char *, int *));
74 operator_chars
PARAMS ((char *, char **));
77 find_line_common
PARAMS ((struct linetable
*, int, int *));
79 static struct partial_symbol
*
80 lookup_partial_symbol
PARAMS ((struct partial_symtab
*, const char *,
81 int, enum namespace));
83 static struct partial_symbol
*
84 lookup_demangled_partial_symbol
PARAMS ((const struct partial_symtab
*,
87 static struct symbol
*
88 lookup_demangled_block_symbol
PARAMS ((const struct block
*, const char *));
90 static struct symtab
*
91 lookup_symtab_1
PARAMS ((char *));
95 /* The single non-language-specific builtin type */
96 struct type
*builtin_type_error
;
98 /* Block in which the most recently searched-for symbol was found.
99 Might be better to make this a parameter to lookup_symbol and
102 const struct block
*block_found
;
104 char no_symtab_msg
[] = "No symbol table is loaded. Use the \"file\" command.";
106 /* Check for a symtab of a specific name; first in symtabs, then in
107 psymtabs. *If* there is no '/' in the name, a match after a '/'
108 in the symtab filename will also work. */
110 static struct symtab
*
111 lookup_symtab_1 (name
)
114 register struct symtab
*s
;
115 register struct partial_symtab
*ps
;
116 register char *slash
= strchr (name
, '/');
117 register int len
= strlen (name
);
118 register struct objfile
*objfile
;
121 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
123 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
125 if (strcmp (name
, s
->filename
) == 0)
131 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
133 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
->next
)
135 if (strcmp (name
, ps
-> filename
) == 0)
139 error ("Internal: readin pst for `%s' found when no symtab found.", name
);
141 return (PSYMTAB_TO_SYMTAB (ps
));
147 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
149 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
151 int l
= strlen (s
->filename
);
153 if (s
->filename
[l
- len
-1] == '/'
154 && (strcmp (s
->filename
+ l
- len
, name
) == 0))
161 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
163 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
165 int l
= strlen (ps
-> filename
);
167 if (ps
-> filename
[l
- len
- 1] == '/'
168 && (strcmp (ps
->filename
+ l
- len
, name
) == 0))
172 error ("Internal: readin pst for `%s' found when no symtab found.", name
);
174 return (PSYMTAB_TO_SYMTAB (ps
));
182 /* Lookup the symbol table of a source file named NAME. Try a couple
183 of variations if the first lookup doesn't work. */
189 register struct symtab
*s
;
192 s
= lookup_symtab_1 (name
);
195 /* If name not found as specified, see if adding ".c" helps. */
197 copy
= (char *) alloca (strlen (name
) + 3);
200 s
= lookup_symtab_1 (copy
);
203 /* We didn't find anything; die. */
207 /* Lookup the partial symbol table of a source file named NAME. This
208 only returns true on an exact match (ie. this semantics are
209 different from lookup_symtab. */
211 struct partial_symtab
*
212 lookup_partial_symtab (name
)
215 register struct partial_symtab
*pst
;
216 register struct objfile
*objfile
;
218 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
220 for (pst
= objfile
-> psymtabs
; pst
!= NULL
; pst
= pst
-> next
)
222 if (strcmp (name
, pst
-> filename
) == 0)
231 /* Demangle a GDB method stub type. */
233 gdb_mangle_name (type
, i
, j
)
237 int mangled_name_len
;
239 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
240 struct fn_field
*method
= &f
[j
];
241 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
242 int is_constructor
= strcmp(field_name
, TYPE_NAME (type
)) == 0;
244 /* Need a new type prefix. */
245 char *const_prefix
= method
->is_const
? "C" : "";
246 char *volatile_prefix
= method
->is_volatile
? "V" : "";
247 char *newname
= type_name_no_tag (type
);
249 int len
= strlen (newname
);
251 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
252 mangled_name_len
= ((is_constructor
? 0 : strlen (field_name
))
254 + strlen (TYPE_FN_FIELD_PHYSNAME (f
, j
))
257 /* Only needed for GNU-mangled names. ANSI-mangled names
258 work with the normal mechanisms. */
259 if (OPNAME_PREFIX_P (field_name
))
261 char *opname
= cplus_mangle_opname (field_name
+ 3, 0);
263 error ("No mangling for \"%s\"", field_name
);
264 mangled_name_len
+= strlen (opname
);
265 mangled_name
= (char *)xmalloc (mangled_name_len
);
267 strncpy (mangled_name
, field_name
, 3);
268 mangled_name
[3] = '\0';
269 strcat (mangled_name
, opname
);
273 mangled_name
= (char *)xmalloc (mangled_name_len
);
275 mangled_name
[0] = '\0';
277 strcpy (mangled_name
, field_name
);
279 strcat (mangled_name
, buf
);
280 strcat (mangled_name
, newname
);
281 strcat (mangled_name
, TYPE_FN_FIELD_PHYSNAME (f
, j
));
287 /* Find which partial symtab on contains PC. Return 0 if none. */
289 struct partial_symtab
*
291 register CORE_ADDR pc
;
293 register struct partial_symtab
*pst
;
294 register struct objfile
*objfile
;
296 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
298 for (pst
= objfile
-> psymtabs
; pst
!= NULL
; pst
= pst
-> next
)
300 if (pc
>= pst
-> textlow
&& pc
< pst
-> texthigh
)
309 /* Find which partial symbol within a psymtab contains PC. Return 0
310 if none. Check all psymtabs if PSYMTAB is 0. */
311 struct partial_symbol
*
312 find_pc_psymbol (psymtab
, pc
)
313 struct partial_symtab
*psymtab
;
316 struct partial_symbol
*best
, *p
;
320 psymtab
= find_pc_psymtab (pc
);
324 best_pc
= psymtab
->textlow
- 1;
326 for (p
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
327 (p
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
328 < psymtab
->n_static_syms
);
330 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
331 && SYMBOL_CLASS (p
) == LOC_BLOCK
332 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
333 && SYMBOL_VALUE_ADDRESS (p
) > best_pc
)
335 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
338 if (best_pc
== psymtab
->textlow
- 1)
344 /* Function called via iterate_over_msymbols() that tests a minimal symbol
345 to see if the minimal symbol's name is a C++ mangled name that matches
346 a user visible name. The user visible name (pname) is passed as arg1
347 and the number of leading characters that must match in both the mangled
348 name and the user name (matchcount) is passed as arg2. Returns a pointer
349 to the minimal symbol if it matches, NULL otherwise. */
352 cplus_mangled_symbol (objfile
, msymbol
, arg1
, arg2
, arg3
)
353 struct objfile
*objfile
;
354 struct minimal_symbol
*msymbol
;
359 char *pname
= (char *) arg1
;
360 int matchcount
= (int) arg2
;
362 struct minimal_symbol
*foundit
= NULL
;
364 if (strncmp (msymbol
-> name
, pname
, matchcount
) == 0)
366 if ((demangled
= cplus_demangle (msymbol
-> name
, -1)) != NULL
)
368 if (strcmp (demangled
, pname
) == 0)
375 return ((PTR
) foundit
);
378 /* Find the definition for a specified symbol name NAME
379 in namespace NAMESPACE, visible from lexical block BLOCK.
380 Returns the struct symbol pointer, or zero if no symbol is found.
381 If SYMTAB is non-NULL, store the symbol table in which the
382 symbol was found there, or NULL if not found.
383 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
384 NAME is a field of the current implied argument `this'. If so set
385 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
386 BLOCK_FOUND is set to the block in which NAME is found (in the case of
387 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
390 lookup_symbol (name
, block
, namespace, is_a_field_of_this
, symtab
)
392 register const struct block
*block
;
393 const enum namespace namespace;
394 int *is_a_field_of_this
;
395 struct symtab
**symtab
;
397 register struct symbol
*sym
;
398 register struct symtab
*s
;
399 register struct partial_symtab
*ps
;
400 struct blockvector
*bv
;
401 register struct objfile
*objfile
;
402 register struct block
*b
;
404 register struct minimal_symbol
*msymbol
;
406 /* Search specified block and its superiors. */
410 sym
= lookup_block_symbol (block
, name
, namespace);
416 /* Search the list of symtabs for one which contains the
417 address of the start of this block. */
418 for (found
= 0, objfile
= object_files
;
419 !found
&& objfile
!= NULL
;
420 objfile
= objfile
-> next
)
422 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
424 bv
= BLOCKVECTOR (s
);
425 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
426 if (BLOCK_START (b
) <= BLOCK_START (block
)
427 && BLOCK_END (b
) > BLOCK_START (block
))
439 block
= BLOCK_SUPERBLOCK (block
);
442 /* But that doesn't do any demangling for the STATIC_BLOCK.
443 I'm not sure whether demangling is needed in the case of
444 nested function in inner blocks; if so this needs to be changed.
446 Don't need to mess with the psymtabs; if we have a block,
447 that file is read in. If we don't, then we deal later with
448 all the psymtab stuff that needs checking. */
449 if (namespace == VAR_NAMESPACE
&& block
!= NULL
)
452 /* Find the right symtab. */
453 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
455 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
457 bv
= BLOCKVECTOR (s
);
458 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
459 if (BLOCK_START (b
) <= BLOCK_START (block
)
460 && BLOCK_END (b
) > BLOCK_START (block
))
462 sym
= lookup_demangled_block_symbol (b
, name
);
476 /* C++: If requested to do so by the caller,
477 check to see if NAME is a field of `this'. */
478 if (is_a_field_of_this
)
480 struct value
*v
= value_of_this (0);
482 *is_a_field_of_this
= 0;
483 if (v
&& check_field (v
, name
))
485 *is_a_field_of_this
= 1;
492 /* Now search all global blocks. Do the symtab's first, then
493 check the psymtab's */
495 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
497 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
499 bv
= BLOCKVECTOR (s
);
500 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
501 sym
= lookup_block_symbol (block
, name
, namespace);
512 /* Check for the possibility of the symbol being a global function
513 that is stored in one of the minimal symbol tables. Eventually, all
514 global symbols might be resolved in this way. */
516 if (namespace == VAR_NAMESPACE
)
518 msymbol
= lookup_minimal_symbol (name
, (struct objfile
*) NULL
);
521 /* Look for a mangled C++ name for NAME. */
522 msymbol
= (struct minimal_symbol
*)
523 iterate_over_msymbols (cplus_mangled_symbol
, (PTR
) name
,
524 (PTR
) strlen (name
), (PTR
) NULL
);
528 s
= find_pc_symtab (msymbol
-> address
);
529 /* If S is NULL, there are no debug symbols for this file.
530 Skip this stuff and check for matching static symbols below. */
533 bv
= BLOCKVECTOR (s
);
534 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
535 sym
= lookup_block_symbol (block
, msymbol
-> name
, namespace);
536 /* We kept static functions in minimal symbol table as well as
537 in static scope. We want to find them in the symbol table. */
539 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
540 sym
= lookup_block_symbol (block
, msymbol
-> name
,
544 /* sym == 0 if symbol was found in the minimal symbol table
545 but not in the symtab.
546 Return 0 to use the msymbol definition of "foo_".
548 This happens for Fortran "foo_" symbols,
549 which are "foo" in the symtab.
551 This can also happen if "asm" is used to make a
552 regular symbol but not a debugging symbol, e.g.
564 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
566 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
->next
)
568 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
570 s
= PSYMTAB_TO_SYMTAB(ps
);
571 bv
= BLOCKVECTOR (s
);
572 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
573 sym
= lookup_block_symbol (block
, name
, namespace);
575 error ("Internal: global symbol `%s' found in psymtab but not in symtab", name
);
583 /* Now search all per-file blocks.
584 Not strictly correct, but more useful than an error.
585 Do the symtabs first, then check the psymtabs */
587 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
589 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
591 bv
= BLOCKVECTOR (s
);
592 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
593 sym
= lookup_block_symbol (block
, name
, namespace);
604 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
606 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
608 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
610 s
= PSYMTAB_TO_SYMTAB(ps
);
611 bv
= BLOCKVECTOR (s
);
612 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
613 sym
= lookup_block_symbol (block
, name
, namespace);
615 error ("Internal: static symbol `%s' found in psymtab but not in symtab", name
);
623 /* Now search all per-file blocks for static mangled symbols.
624 Do the symtabs first, then check the psymtabs. */
626 if (namespace == VAR_NAMESPACE
)
628 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
630 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
632 bv
= BLOCKVECTOR (s
);
633 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
634 sym
= lookup_demangled_block_symbol (block
, name
);
645 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
647 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
649 if (!ps
->readin
&& lookup_demangled_partial_symbol (ps
, name
))
651 s
= PSYMTAB_TO_SYMTAB(ps
);
652 bv
= BLOCKVECTOR (s
);
653 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
654 sym
= lookup_demangled_block_symbol (block
, name
);
656 error ("Internal: mangled static symbol `%s' found in psymtab but not in symtab", name
);
670 /* Look for a static demangled symbol in block BLOCK. */
672 static struct symbol
*
673 lookup_demangled_block_symbol (block
, name
)
674 register const struct block
*block
;
677 register int bot
, top
, inc
;
678 register struct symbol
*sym
;
681 top
= BLOCK_NSYMS (block
);
686 sym
= BLOCK_SYM (block
, bot
);
687 if (SYMBOL_NAME (sym
)[0] == inc
688 && SYMBOL_NAMESPACE (sym
) == VAR_NAMESPACE
)
690 char *demangled
= cplus_demangle(SYMBOL_NAME (sym
), -1);
691 if (demangled
!= NULL
)
693 int cond
= strcmp (demangled
, name
);
705 /* Look, in partial_symtab PST, for static mangled symbol NAME. */
707 static struct partial_symbol
*
708 lookup_demangled_partial_symbol (pst
, name
)
709 const struct partial_symtab
*pst
;
712 struct partial_symbol
*start
, *psym
;
713 int length
= pst
->n_static_syms
;
714 register int inc
= name
[0];
717 return (struct partial_symbol
*) 0;
719 start
= pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
;
720 for (psym
= start
; psym
< start
+ length
; psym
++)
722 if (SYMBOL_NAME (psym
)[0] == inc
723 && SYMBOL_NAMESPACE (psym
) == VAR_NAMESPACE
)
725 char *demangled
= cplus_demangle(SYMBOL_NAME (psym
), -1);
726 if (demangled
!= NULL
)
728 int cond
= strcmp (demangled
, name
);
736 return (struct partial_symbol
*) 0;
739 /* Look, in partial_symtab PST, for symbol NAME. Check the global
740 symbols if GLOBAL, the static symbols if not */
742 static struct partial_symbol
*
743 lookup_partial_symbol (pst
, name
, global
, namespace)
744 struct partial_symtab
*pst
;
747 enum namespace namespace;
749 struct partial_symbol
*start
, *psym
;
750 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
753 return (struct partial_symbol
*) 0;
756 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
757 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
759 if (global
) /* This means we can use a binary */
762 struct partial_symbol
*top
, *bottom
, *center
;
764 /* Binary search. This search is guaranteed to end with center
765 pointing at the earliest partial symbol with the correct
766 name. At that point *all* partial symbols with that name
767 will be checked against the correct namespace. */
769 top
= start
+ length
- 1;
772 center
= bottom
+ (top
- bottom
) / 2;
774 assert (center
< top
);
776 if (strcmp (SYMBOL_NAME (center
), name
) >= 0)
781 assert (top
== bottom
);
783 while (!strcmp (SYMBOL_NAME (top
), name
))
785 if (SYMBOL_NAMESPACE (top
) == namespace)
792 /* Can't use a binary search */
793 for (psym
= start
; psym
< start
+ length
; psym
++)
794 if (namespace == SYMBOL_NAMESPACE (psym
)
795 && !strcmp (name
, SYMBOL_NAME (psym
)))
799 return (struct partial_symbol
*) 0;
802 /* Find the psymtab containing main(). */
804 struct partial_symtab
*
807 register struct partial_symtab
*pst
;
808 register struct objfile
*objfile
;
810 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
812 for (pst
= objfile
-> psymtabs
; pst
; pst
= pst
->next
)
814 if (lookup_partial_symbol (pst
, "main", 1, VAR_NAMESPACE
))
823 /* Look for a symbol in block BLOCK. */
826 lookup_block_symbol (block
, name
, namespace)
827 register const struct block
*block
;
829 const enum namespace namespace;
831 register int bot
, top
, inc
;
832 register struct symbol
*sym
, *parameter_sym
;
834 top
= BLOCK_NSYMS (block
);
837 /* If the blocks's symbols were sorted, start with a binary search. */
839 if (BLOCK_SHOULD_SORT (block
))
841 /* First, advance BOT to not far before
842 the first symbol whose name is NAME. */
846 inc
= (top
- bot
+ 1);
847 /* No need to keep binary searching for the last few bits worth. */
850 inc
= (inc
>> 1) + bot
;
851 sym
= BLOCK_SYM (block
, inc
);
852 if (SYMBOL_NAME (sym
)[0] < name
[0])
854 else if (SYMBOL_NAME (sym
)[0] > name
[0])
856 else if (strcmp (SYMBOL_NAME (sym
), name
) < 0)
862 /* Now scan forward until we run out of symbols,
863 find one whose name is greater than NAME,
865 If there is more than one symbol with the right name and namespace,
866 we return the first one. dbxread.c is careful to make sure
867 that if one is a register then it comes first. */
869 top
= BLOCK_NSYMS (block
);
872 sym
= BLOCK_SYM (block
, bot
);
873 inc
= SYMBOL_NAME (sym
)[0] - name
[0];
875 inc
= strcmp (SYMBOL_NAME (sym
), name
);
876 if (inc
== 0 && SYMBOL_NAMESPACE (sym
) == namespace)
885 /* Here if block isn't sorted.
886 This loop is equivalent to the loop above,
887 but hacked greatly for speed.
889 Note that parameter symbols do not always show up last in the
890 list; this loop makes sure to take anything else other than
891 parameter symbols first; it only uses parameter symbols as a
892 last resort. Note that this only takes up extra computation
895 parameter_sym
= (struct symbol
*) 0;
896 top
= BLOCK_NSYMS (block
);
900 sym
= BLOCK_SYM (block
, bot
);
901 if (SYMBOL_NAME (sym
)[0] == inc
902 && !strcmp (SYMBOL_NAME (sym
), name
)
903 && SYMBOL_NAMESPACE (sym
) == namespace)
905 if (SYMBOL_CLASS (sym
) == LOC_ARG
906 || SYMBOL_CLASS (sym
) == LOC_LOCAL_ARG
907 || SYMBOL_CLASS (sym
) == LOC_REF_ARG
908 || SYMBOL_CLASS (sym
) == LOC_REGPARM
)
915 return parameter_sym
; /* Will be 0 if not found. */
918 /* Return the symbol for the function which contains a specified
919 lexical block, described by a struct block BL. */
925 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
926 bl
= BLOCK_SUPERBLOCK (bl
);
928 return BLOCK_FUNCTION (bl
);
931 /* Subroutine of find_pc_line */
935 register CORE_ADDR pc
;
937 register struct block
*b
;
938 struct blockvector
*bv
;
939 register struct symtab
*s
= 0;
940 register struct partial_symtab
*ps
;
941 register struct objfile
*objfile
;
944 /* Search all symtabs for one whose file contains our pc */
946 for (found
= 0, objfile
= object_files
;
947 !found
&& objfile
!= NULL
;
948 objfile
= objfile
-> next
)
950 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
952 bv
= BLOCKVECTOR (s
);
953 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
954 if (BLOCK_START (b
) <= pc
955 && BLOCK_END (b
) > pc
)
965 ps
= find_pc_psymtab (pc
);
966 if (ps
&& ps
->readin
)
968 printf_filtered ("(Internal error: pc 0x%x in read in psymtab, but not in symtab.)\n", pc
);
972 s
= PSYMTAB_TO_SYMTAB (ps
);
979 /* Find the source file and line number for a given PC value.
980 Return a structure containing a symtab pointer, a line number,
981 and a pc range for the entire source line.
982 The value's .pc field is NOT the specified pc.
983 NOTCURRENT nonzero means, if specified pc is on a line boundary,
984 use the line that ends there. Otherwise, in that case, the line
985 that begins there is used. */
987 struct symtab_and_line
988 find_pc_line (pc
, notcurrent
)
993 register struct linetable
*l
;
996 register struct linetable_entry
*item
;
997 struct symtab_and_line val
;
998 struct blockvector
*bv
;
1000 /* Info on best line seen so far, and where it starts, and its file. */
1003 CORE_ADDR best_pc
= 0;
1004 CORE_ADDR best_end
= 0;
1005 struct symtab
*best_symtab
= 0;
1007 /* Store here the first line number
1008 of a file which contains the line at the smallest pc after PC.
1009 If we don't find a line whose range contains PC,
1010 we will use a line one less than this,
1011 with a range from the start of that file to the first line's pc. */
1013 CORE_ADDR alt_pc
= 0;
1014 struct symtab
*alt_symtab
= 0;
1016 /* Info on best line seen in this file. */
1021 /* Info on first line of this file. */
1026 /* If this pc is not from the current frame,
1027 it is the address of the end of a call instruction.
1028 Quite likely that is the start of the following statement.
1029 But what we want is the statement containing the instruction.
1030 Fudge the pc to make sure we get that. */
1032 if (notcurrent
) pc
-= 1;
1034 s
= find_pc_symtab (pc
);
1044 bv
= BLOCKVECTOR (s
);
1046 /* Look at all the symtabs that share this blockvector.
1047 They all have the same apriori range, that we found was right;
1048 but they have different line tables. */
1050 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1052 /* Find the best line in this symtab. */
1059 for (i
= 0; i
< len
; i
++)
1061 item
= &(l
->item
[i
]);
1065 first_line
= item
->line
;
1066 first_pc
= item
->pc
;
1068 /* Return the last line that did not start after PC. */
1071 prev_line
= item
->line
;
1078 /* Is this file's best line closer than the best in the other files?
1079 If so, record this file, and its best line, as best so far. */
1080 if (prev_line
>= 0 && prev_pc
> best_pc
)
1083 best_line
= prev_line
;
1085 /* If another line is in the linetable, and its PC is closer
1086 than the best_end we currently have, take it as best_end. */
1087 if (i
< len
&& (best_end
== 0 || best_end
> item
->pc
))
1088 best_end
= item
->pc
;
1090 /* Is this file's first line closer than the first lines of other files?
1091 If so, record this file, and its first line, as best alternate. */
1092 if (first_line
>= 0 && first_pc
> pc
1093 && (alt_pc
== 0 || first_pc
< alt_pc
))
1096 alt_line
= first_line
;
1100 if (best_symtab
== 0)
1102 val
.symtab
= alt_symtab
;
1103 val
.line
= alt_line
- 1;
1104 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1109 val
.symtab
= best_symtab
;
1110 val
.line
= best_line
;
1112 if (best_end
&& (alt_pc
== 0 || best_end
< alt_pc
))
1117 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1122 /* Find the PC value for a given source file and line number.
1123 Returns zero for invalid line number.
1124 The source file is specified with a struct symtab. */
1127 find_line_pc (symtab
, line
)
1128 struct symtab
*symtab
;
1131 register struct linetable
*l
;
1137 l
= LINETABLE (symtab
);
1138 ind
= find_line_common(l
, line
, &dummy
);
1139 return (ind
>= 0) ? l
->item
[ind
].pc
: 0;
1142 /* Find the range of pc values in a line.
1143 Store the starting pc of the line into *STARTPTR
1144 and the ending pc (start of next line) into *ENDPTR.
1145 Returns 1 to indicate success.
1146 Returns 0 if could not find the specified line. */
1149 find_line_pc_range (symtab
, thisline
, startptr
, endptr
)
1150 struct symtab
*symtab
;
1152 CORE_ADDR
*startptr
, *endptr
;
1154 register struct linetable
*l
;
1156 int exact_match
; /* did we get an exact linenumber match */
1161 l
= LINETABLE (symtab
);
1162 ind
= find_line_common (l
, thisline
, &exact_match
);
1165 *startptr
= l
->item
[ind
].pc
;
1166 /* If we have not seen an entry for the specified line,
1167 assume that means the specified line has zero bytes. */
1168 if (!exact_match
|| ind
== l
->nitems
-1)
1169 *endptr
= *startptr
;
1171 /* Perhaps the following entry is for the following line.
1172 It's worth a try. */
1173 if (ind
+1 < l
->nitems
1174 && l
->item
[ind
+1].line
== thisline
+ 1)
1175 *endptr
= l
->item
[ind
+1].pc
;
1177 *endptr
= find_line_pc (symtab
, thisline
+1);
1184 /* Given a line table and a line number, return the index into the line
1185 table for the pc of the nearest line whose number is >= the specified one.
1186 Return -1 if none is found. The value is >= 0 if it is an index.
1188 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1191 find_line_common (l
, lineno
, exact_match
)
1192 register struct linetable
*l
;
1193 register int lineno
;
1199 /* BEST is the smallest linenumber > LINENO so far seen,
1200 or 0 if none has been seen so far.
1201 BEST_INDEX identifies the item for it. */
1203 int best_index
= -1;
1212 for (i
= 0; i
< len
; i
++)
1214 register struct linetable_entry
*item
= &(l
->item
[i
]);
1216 if (item
->line
== lineno
)
1222 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
1229 /* If we got here, we didn't get an exact match. */
1236 find_pc_line_pc_range (pc
, startptr
, endptr
)
1238 CORE_ADDR
*startptr
, *endptr
;
1240 struct symtab_and_line sal
;
1241 sal
= find_pc_line (pc
, 0);
1244 return sal
.symtab
!= 0;
1247 /* If P is of the form "operator[ \t]+..." where `...' is
1248 some legitimate operator text, return a pointer to the
1249 beginning of the substring of the operator text.
1250 Otherwise, return "". */
1252 operator_chars (p
, end
)
1257 if (strncmp (p
, "operator", 8))
1261 /* Don't get faked out by `operator' being part of a longer
1263 if ((*p
>= 'A' && *p
<= 'Z') || (*p
>= 'a' && *p
<= 'z')
1264 || *p
== '_' || *p
== '$' || *p
== '\0')
1267 /* Allow some whitespace between `operator' and the operator symbol. */
1268 while (*p
== ' ' || *p
== '\t')
1290 if (p
[1] == '=' || p
[1] == p
[0])
1301 error ("`operator ()' must be specified without whitespace in `()'");
1306 error ("`operator ?:' must be specified without whitespace in `?:'");
1311 error ("`operator []' must be specified without whitespace in `[]'");
1315 error ("`operator %s' not supported", p
);
1322 /* Recursive helper function for decode_line_1.
1323 * Look for methods named NAME in type T.
1324 * Return number of matches.
1325 * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1326 * These allocations seem to define "big enough":
1327 * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1328 * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1332 find_methods (t
, name
, physnames
, sym_arr
)
1336 struct symbol
**sym_arr
;
1340 struct symbol
*sym_class
;
1341 char *class_name
= type_name_no_tag (t
);
1342 /* Ignore this class if it doesn't have a name.
1343 This prevents core dumps, but is just a workaround
1344 because we might not find the function in
1345 certain cases, such as
1346 struct D {virtual int f();}
1347 struct C : D {virtual int g();}
1348 (in this case g++ 1.35.1- does not put out a name
1349 for D as such, it defines type 19 (for example) in
1350 the same stab as C, and then does a
1351 .stabs "D:T19" and a .stabs "D:t19".
1353 "break C::f" should not be looking for field f in
1355 but just for the field f in the baseclasses of C
1356 (no matter what their names).
1358 However, I don't know how to replace the code below
1359 that depends on knowing the name of D. */
1361 && (sym_class
= lookup_symbol (class_name
,
1362 (struct block
*)NULL
,
1365 (struct symtab
**)NULL
)))
1368 t
= SYMBOL_TYPE (sym_class
);
1369 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
1370 method_counter
>= 0;
1374 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
1376 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
1377 if (!strcmp (name
, method_name
))
1378 /* Find all the fields with that name. */
1379 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
1384 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
1385 check_stub_method (t
, method_counter
, field_counter
);
1386 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
1387 physnames
[i1
] = (char*) alloca (strlen (phys_name
) + 1);
1388 strcpy (physnames
[i1
], phys_name
);
1389 sym_arr
[i1
] = lookup_symbol (phys_name
,
1390 SYMBOL_BLOCK_VALUE (sym_class
),
1393 (struct symtab
**) NULL
);
1394 if (sym_arr
[i1
]) i1
++;
1398 /* Only search baseclasses if there is no match yet,
1399 * since names in derived classes override those in baseclasses.
1403 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
1404 i1
+= find_methods(TYPE_BASECLASS(t
, ibase
), name
,
1405 physnames
+ i1
, sym_arr
+ i1
);
1409 /* Parse a string that specifies a line number.
1410 Pass the address of a char * variable; that variable will be
1411 advanced over the characters actually parsed.
1415 LINENUM -- that line number in current file. PC returned is 0.
1416 FILE:LINENUM -- that line in that file. PC returned is 0.
1417 FUNCTION -- line number of openbrace of that function.
1418 PC returned is the start of the function.
1419 VARIABLE -- line number of definition of that variable.
1421 FILE:FUNCTION -- likewise, but prefer functions in that file.
1422 *EXPR -- line in which address EXPR appears.
1424 FUNCTION may be an undebuggable function found in minimal symbol table.
1426 If the argument FUNFIRSTLINE is nonzero, we want the first line
1427 of real code inside a function when a function is specified.
1429 DEFAULT_SYMTAB specifies the file to use if none is specified.
1430 It defaults to current_source_symtab.
1431 DEFAULT_LINE specifies the line number to use for relative
1432 line numbers (that start with signs). Defaults to current_source_line.
1434 Note that it is possible to return zero for the symtab
1435 if no file is validly specified. Callers must check that.
1436 Also, the line number returned may be invalid. */
1438 struct symtabs_and_lines
1439 decode_line_1 (argptr
, funfirstline
, default_symtab
, default_line
)
1442 struct symtab
*default_symtab
;
1445 struct symtabs_and_lines values
;
1446 struct symtab_and_line val
;
1447 register char *p
, *p1
;
1449 register struct symtab
*s
;
1451 register struct symbol
*sym
;
1452 /* The symtab that SYM was found in. */
1453 struct symtab
*sym_symtab
;
1455 register CORE_ADDR pc
;
1456 register struct minimal_symbol
*msymbol
;
1458 struct symbol
*sym_class
;
1460 struct symbol
**sym_arr
;
1464 /* Defaults have defaults. */
1466 if (default_symtab
== 0)
1468 default_symtab
= current_source_symtab
;
1469 default_line
= current_source_line
;
1472 /* See if arg is *PC */
1474 if (**argptr
== '*')
1477 pc
= parse_and_eval_address_1 (argptr
);
1478 values
.sals
= (struct symtab_and_line
*)
1479 xmalloc (sizeof (struct symtab_and_line
));
1481 values
.sals
[0] = find_pc_line (pc
, 0);
1482 values
.sals
[0].pc
= pc
;
1486 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1490 for (p
= *argptr
; *p
; p
++)
1492 if (p
[0] == ':' || p
[0] == ' ' || p
[0] == '\t')
1495 while (p
[0] == ' ' || p
[0] == '\t') p
++;
1503 /* Extract the class name. */
1505 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1506 copy
= (char *) alloca (p
- *argptr
+ 1);
1507 bcopy (*argptr
, copy
, p
- *argptr
);
1508 copy
[p
- *argptr
] = 0;
1510 /* Discard the class name from the arg. */
1512 while (*p
== ' ' || *p
== '\t') p
++;
1515 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
1516 (struct symtab
**)NULL
);
1519 ( TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_STRUCT
1520 || TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_UNION
))
1522 /* Arg token is not digits => try it as a function name
1523 Find the next token (everything up to end or next whitespace). */
1525 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',' && *p
!=':') p
++;
1526 q
= operator_chars (*argptr
, &q1
);
1528 copy
= (char *) alloca (p
- *argptr
+ 1 + (q1
- q
));
1533 copy
[2] = CPLUS_MARKER
;
1534 bcopy (q
, copy
+ 3, q1
- q
);
1535 copy
[3 + (q1
- q
)] = '\0';
1540 bcopy (*argptr
, copy
, p
- *argptr
);
1541 copy
[p
- *argptr
] = '\0';
1544 /* no line number may be specified */
1545 while (*p
== ' ' || *p
== '\t') p
++;
1549 i1
= 0; /* counter for the symbol array */
1550 t
= SYMBOL_TYPE (sym_class
);
1551 sym_arr
= (struct symbol
**) alloca(TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(struct symbol
*));
1552 physnames
= (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(char*));
1554 if (destructor_name_p (copy
, t
))
1556 /* destructors are a special case. */
1557 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, 0);
1558 int len
= TYPE_FN_FIELDLIST_LENGTH (t
, 0) - 1;
1559 char *phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, len
);
1560 physnames
[i1
] = (char *)alloca (strlen (phys_name
) + 1);
1561 strcpy (physnames
[i1
], phys_name
);
1563 lookup_symbol (phys_name
, SYMBOL_BLOCK_VALUE (sym_class
),
1564 VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
1565 if (sym_arr
[i1
]) i1
++;
1568 i1
= find_methods (t
, copy
, physnames
, sym_arr
);
1571 /* There is exactly one field with that name. */
1574 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1576 /* Arg is the name of a function */
1577 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1580 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1582 values
.sals
[0] = find_pc_line (pc
, 0);
1583 values
.sals
[0].pc
= (values
.sals
[0].end
&& values
.sals
[0].pc
!= pc
) ? values
.sals
[0].end
: pc
;
1593 /* There is more than one field with that name
1594 (overloaded). Ask the user which one to use. */
1595 return decode_line_2 (sym_arr
, i1
, funfirstline
);
1601 if (OPNAME_PREFIX_P (copy
))
1603 tmp
= (char *)alloca (strlen (copy
+3) + 9);
1604 strcpy (tmp
, "operator ");
1605 strcat (tmp
, copy
+3);
1610 error ("The class `%s' does not have destructor defined",
1613 error ("The class %s does not have any method named %s",
1614 sym_class
->name
, tmp
);
1618 /* The quotes are important if copy is empty. */
1619 error("No class, struct, or union named \"%s\"", copy
);
1624 /* Extract the file name. */
1626 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1627 copy
= (char *) alloca (p
- *argptr
+ 1);
1628 bcopy (*argptr
, copy
, p
- *argptr
);
1629 copy
[p
- *argptr
] = 0;
1631 /* Find that file's data. */
1632 s
= lookup_symtab (copy
);
1635 if (!have_full_symbols () && !have_partial_symbols ())
1636 error (no_symtab_msg
);
1637 error ("No source file named %s.", copy
);
1640 /* Discard the file name from the arg. */
1642 while (*p
== ' ' || *p
== '\t') p
++;
1646 /* S is specified file's symtab, or 0 if no file specified.
1647 arg no longer contains the file name. */
1649 /* Check whether arg is all digits (and sign) */
1652 if (*p
== '-' || *p
== '+') p
++;
1653 while (*p
>= '0' && *p
<= '9')
1656 if (p
!= *argptr
&& (*p
== 0 || *p
== ' ' || *p
== '\t' || *p
== ','))
1658 /* We found a token consisting of all digits -- at least one digit. */
1659 enum sign
{none
, plus
, minus
} sign
= none
;
1661 /* This is where we need to make sure that we have good defaults.
1662 We must guarantee that this section of code is never executed
1663 when we are called with just a function name, since
1664 select_source_symtab calls us with such an argument */
1666 if (s
== 0 && default_symtab
== 0)
1668 select_source_symtab (0);
1669 default_symtab
= current_source_symtab
;
1670 default_line
= current_source_line
;
1673 if (**argptr
== '+')
1674 sign
= plus
, (*argptr
)++;
1675 else if (**argptr
== '-')
1676 sign
= minus
, (*argptr
)++;
1677 val
.line
= atoi (*argptr
);
1684 val
.line
= default_line
+ val
.line
;
1690 val
.line
= default_line
- val
.line
;
1695 break; /* No need to adjust val.line. */
1698 while (*p
== ' ' || *p
== '\t') p
++;
1704 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1705 values
.sals
[0] = val
;
1710 /* Arg token is not digits => try it as a variable name
1711 Find the next token (everything up to end or next whitespace). */
1713 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',') p
++;
1714 copy
= (char *) alloca (p
- *argptr
+ 1);
1715 bcopy (*argptr
, copy
, p
- *argptr
);
1716 copy
[p
- *argptr
] = 0;
1717 while (*p
== ' ' || *p
== '\t') p
++;
1720 /* Look up that token as a variable.
1721 If file specified, use that file's per-file block to start with. */
1723 sym
= lookup_symbol (copy
,
1724 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
1725 : get_selected_block ()),
1726 VAR_NAMESPACE
, 0, &sym_symtab
);
1730 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1732 /* Arg is the name of a function */
1733 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1736 val
= find_pc_line (pc
, 0);
1737 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1738 /* Convex: no need to suppress code on first line, if any */
1741 /* If SKIP_PROLOGUE left us in mid-line, and the next line is still
1742 part of the same function:
1743 advance to next line,
1744 recalculate its line number (might not be N+1). */
1745 if (val
.pc
!= pc
&& val
.end
&&
1746 lookup_minimal_symbol_by_pc (pc
) == lookup_minimal_symbol_by_pc (val
.end
)) {
1747 pc
= val
.end
; /* First pc of next line */
1748 val
= find_pc_line (pc
, 0);
1752 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1753 values
.sals
[0] = val
;
1756 /* I think this is always the same as the line that
1757 we calculate above, but the general principle is
1758 "trust the symbols more than stuff like
1760 if (SYMBOL_LINE (sym
) != 0)
1761 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1765 else if (SYMBOL_LINE (sym
) != 0)
1767 /* We know its line number. */
1768 values
.sals
= (struct symtab_and_line
*)
1769 xmalloc (sizeof (struct symtab_and_line
));
1771 bzero (&values
.sals
[0], sizeof (values
.sals
[0]));
1772 values
.sals
[0].symtab
= sym_symtab
;
1773 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1777 /* This can happen if it is compiled with a compiler which doesn't
1778 put out line numbers for variables. */
1779 error ("Line number not known for symbol \"%s\"", copy
);
1782 msymbol
= lookup_minimal_symbol (copy
, (struct objfile
*) NULL
);
1783 if (msymbol
!= NULL
)
1787 val
.pc
= msymbol
-> address
+ FUNCTION_START_OFFSET
;
1789 SKIP_PROLOGUE (val
.pc
);
1790 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1791 values
.sals
[0] = val
;
1796 if (!have_full_symbols () &&
1797 !have_partial_symbols () && !have_minimal_symbols ())
1798 error (no_symtab_msg
);
1800 error ("Function %s not defined.", copy
);
1801 return values
; /* for lint */
1804 struct symtabs_and_lines
1805 decode_line_spec (string
, funfirstline
)
1809 struct symtabs_and_lines sals
;
1811 error ("Empty line specification.");
1812 sals
= decode_line_1 (&string
, funfirstline
,
1813 current_source_symtab
, current_source_line
);
1815 error ("Junk at end of line specification: %s", string
);
1819 /* Given a list of NELTS symbols in sym_arr (with corresponding
1820 mangled names in physnames), return a list of lines to operate on
1821 (ask user if necessary). */
1822 static struct symtabs_and_lines
1823 decode_line_2 (sym_arr
, nelts
, funfirstline
)
1824 struct symbol
*sym_arr
[];
1828 struct symtabs_and_lines values
, return_values
;
1829 register CORE_ADDR pc
;
1834 values
.sals
= (struct symtab_and_line
*) alloca (nelts
* sizeof(struct symtab_and_line
));
1835 return_values
.sals
= (struct symtab_and_line
*) xmalloc (nelts
* sizeof(struct symtab_and_line
));
1838 printf("[0] cancel\n[1] all\n");
1841 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
1843 /* Arg is the name of a function */
1844 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr
[i
]))
1845 + FUNCTION_START_OFFSET
;
1848 values
.sals
[i
] = find_pc_line (pc
, 0);
1849 values
.sals
[i
].pc
= (values
.sals
[i
].end
&& values
.sals
[i
].pc
!= pc
) ?
1850 values
.sals
[i
].end
: pc
;
1851 printf("[%d] file:%s; line number:%d\n",
1852 (i
+2), values
.sals
[i
].symtab
->filename
, values
.sals
[i
].line
);
1854 else printf ("?HERE\n");
1858 if ((prompt
= getenv ("PS2")) == NULL
)
1862 printf("%s ",prompt
);
1865 args
= command_line_input ((char *) NULL
, 0);
1868 error_no_arg ("one or more choice numbers");
1876 while (*arg1
>= '0' && *arg1
<= '9') arg1
++;
1877 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
1878 error ("Arguments must be choice numbers.");
1883 error ("cancelled");
1886 bcopy (values
.sals
, return_values
.sals
, (nelts
* sizeof(struct symtab_and_line
)));
1887 return_values
.nelts
= nelts
;
1888 return return_values
;
1891 if (num
> nelts
+ 2)
1893 printf ("No choice number %d.\n", num
);
1898 if (values
.sals
[num
].pc
)
1900 return_values
.sals
[i
++] = values
.sals
[num
];
1901 values
.sals
[num
].pc
= 0;
1905 printf ("duplicate request for %d ignored.\n", num
);
1910 while (*args
== ' ' || *args
== '\t') args
++;
1912 return_values
.nelts
= i
;
1913 return return_values
;
1917 /* Slave routine for sources_info. Force line breaks at ,'s.
1918 NAME is the name to print and *FIRST is nonzero if this is the first
1919 name printed. Set *FIRST to zero. */
1921 output_source_filename (name
, first
)
1925 static unsigned int column
;
1926 /* Table of files printed so far. Since a single source file can
1927 result in several partial symbol tables, we need to avoid printing
1928 it more than once. Note: if some of the psymtabs are read in and
1929 some are not, it gets printed both under "Source files for which
1930 symbols have been read" and "Source files for which symbols will
1931 be read in on demand". I consider this a reasonable way to deal
1932 with the situation. I'm not sure whether this can also happen for
1933 symtabs; it doesn't hurt to check. */
1934 static char **tab
= NULL
;
1935 /* Allocated size of tab in elements.
1936 Start with one 256-byte block (when using GNU malloc.c).
1937 24 is the malloc overhead when range checking is in effect. */
1938 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
1939 /* Current size of tab in elements. */
1940 static int tab_cur_size
;
1947 tab
= (char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
1951 /* Is NAME in tab? */
1952 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
1953 if (strcmp (*p
, name
) == 0)
1954 /* Yes; don't print it again. */
1956 /* No; add it to tab. */
1957 if (tab_cur_size
== tab_alloc_size
)
1959 tab_alloc_size
*= 2;
1960 tab
= (char **) xrealloc ((char *) tab
, tab_alloc_size
* sizeof (*tab
));
1962 tab
[tab_cur_size
++] = name
;
1971 printf_filtered (",");
1975 if (column
!= 0 && column
+ strlen (name
) >= 70)
1977 printf_filtered ("\n");
1980 else if (column
!= 0)
1982 printf_filtered (" ");
1985 fputs_filtered (name
, stdout
);
1986 column
+= strlen (name
);
1992 register struct symtab
*s
;
1993 register struct partial_symtab
*ps
;
1994 register struct objfile
*objfile
;
1997 if (!have_full_symbols () && !have_partial_symbols ())
1999 error (no_symtab_msg
);
2002 printf_filtered ("Source files for which symbols have been read in:\n\n");
2005 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2007 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
2009 output_source_filename (s
-> filename
, &first
);
2012 printf_filtered ("\n\n");
2014 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2017 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2019 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
2023 output_source_filename (ps
-> filename
, &first
);
2027 printf_filtered ("\n");
2030 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2031 If CLASS is zero, list all symbols except functions and type names.
2032 If CLASS is 1, list only functions.
2033 If CLASS is 2, list only type names.
2034 If CLASS is 3, list only method names.
2036 BPT is non-zero if we should set a breakpoint at the functions
2040 list_symbols (regexp
, class, bpt
)
2045 register struct symtab
*s
;
2046 register struct partial_symtab
*ps
;
2047 register struct blockvector
*bv
;
2048 struct blockvector
*prev_bv
= 0;
2049 register struct block
*b
;
2051 register struct symbol
*sym
;
2052 struct partial_symbol
*psym
;
2053 struct objfile
*objfile
;
2054 struct minimal_symbol
*msymbol
;
2056 static char *classnames
[]
2057 = {"variable", "function", "type", "method"};
2058 int found_in_file
= 0;
2060 static enum minimal_symbol_type types
[]
2061 = {mst_data
, mst_text
, mst_abs
, mst_unknown
};
2062 static enum minimal_symbol_type types2
[]
2063 = {mst_bss
, mst_text
, mst_abs
, mst_unknown
};
2064 enum minimal_symbol_type ourtype
= types
[class];
2065 enum minimal_symbol_type ourtype2
= types2
[class];
2068 if (0 != (val
= re_comp (regexp
)))
2069 error ("Invalid regexp (%s): %s", val
, regexp
);
2071 /* Search through the partial symtabs *first* for all symbols
2072 matching the regexp. That way we don't have to reproduce all of
2073 the machinery below. */
2075 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2077 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
2079 struct partial_symbol
*bound
, *gbound
, *sbound
;
2082 if (ps
->readin
) continue;
2084 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2085 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2088 /* Go through all of the symbols stored in a partial
2089 symtab in one loop. */
2090 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2095 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2097 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2108 /* If it would match (logic taken from loop below)
2109 load the file and go on to the next one */
2110 if ((regexp
== 0 || re_exec (SYMBOL_NAME (psym
)))
2111 && ((class == 0 && SYMBOL_CLASS (psym
) != LOC_TYPEDEF
2112 && SYMBOL_CLASS (psym
) != LOC_BLOCK
)
2113 || (class == 1 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)
2114 || (class == 2 && SYMBOL_CLASS (psym
) == LOC_TYPEDEF
)
2115 || (class == 3 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)))
2117 (void) PSYMTAB_TO_SYMTAB(ps
);
2126 /* Here, we search through the minimal symbol tables for functions that
2127 match, and call find_pc_symtab on them to force their symbols to
2128 be read. The symbol will then be found during the scan of symtabs
2129 below. If find_pc_symtab fails, set found_misc so that we will
2130 rescan to print any matching symbols without debug info. */
2134 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2136 for (msymbol
= objfile
-> msymbols
;
2137 msymbol
-> name
!= NULL
; msymbol
++)
2139 if (msymbol
-> type
== ourtype
|| msymbol
-> type
== ourtype2
)
2141 if (regexp
== 0 || re_exec (msymbol
-> name
))
2143 if (0 == find_pc_symtab (msymbol
-> address
))
2153 /* Printout here so as to get after the "Reading in symbols"
2154 messages which will be generated above. */
2156 printf_filtered (regexp
2157 ? "All %ss matching regular expression \"%s\":\n"
2158 : "All defined %ss:\n",
2162 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2164 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
2167 bv
= BLOCKVECTOR (s
);
2168 /* Often many files share a blockvector.
2169 Scan each blockvector only once so that
2170 we don't get every symbol many times.
2171 It happens that the first symtab in the list
2172 for any given blockvector is the main file. */
2174 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
2176 b
= BLOCKVECTOR_BLOCK (bv
, i
);
2177 /* Skip the sort if this block is always sorted. */
2178 if (!BLOCK_SHOULD_SORT (b
))
2179 sort_block_syms (b
);
2180 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
2183 sym
= BLOCK_SYM (b
, j
);
2184 if ((regexp
== 0 || re_exec (SYMBOL_NAME (sym
)))
2185 && ((class == 0 && SYMBOL_CLASS (sym
) != LOC_TYPEDEF
2186 && SYMBOL_CLASS (sym
) != LOC_BLOCK
)
2187 || (class == 1 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2188 || (class == 2 && SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2189 || (class == 3 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)))
2193 /* Set a breakpoint here, if it's a function */
2195 break_command (SYMBOL_NAME(sym
), 0);
2197 else if (!found_in_file
)
2199 fputs_filtered ("\nFile ", stdout
);
2200 fputs_filtered (s
->filename
, stdout
);
2201 fputs_filtered (":\n", stdout
);
2205 if (class != 2 && i
== STATIC_BLOCK
)
2206 printf_filtered ("static ");
2208 /* Typedef that is not a C++ class */
2210 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
2211 typedef_print (SYMBOL_TYPE(sym
), sym
, stdout
);
2212 /* variable, func, or typedef-that-is-c++-class */
2213 else if (class < 2 ||
2215 SYMBOL_NAMESPACE(sym
) == STRUCT_NAMESPACE
))
2217 type_print (SYMBOL_TYPE (sym
),
2218 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2219 ? "" : SYMBOL_NAME (sym
)),
2222 printf_filtered (";\n");
2228 type_print_base (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0, 0);
2229 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0);
2230 sprintf (buf
, " %s::", type_name_no_tag (t
));
2231 type_print_method_args (TYPE_FN_FIELD_ARGS (t
, i
), buf
, name
, stdout
);
2241 /* If there are no eyes, avoid all contact. I mean, if there are
2242 no debug symbols, then print directly from the msymbol_vector. */
2244 if (found_misc
|| class != 1)
2247 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2249 for (msymbol
= objfile
-> msymbols
;
2250 msymbol
-> name
!= NULL
; msymbol
++)
2252 if (msymbol
-> type
== ourtype
|| msymbol
-> type
== ourtype2
)
2254 if (regexp
== 0 || re_exec (msymbol
-> name
))
2256 /* Functions: Look up by address. */
2258 (find_pc_symtab (msymbol
-> address
) != NULL
))
2260 /* Variables/Absolutes: Look up by name */
2261 if (lookup_symbol (msymbol
-> name
,
2262 (struct block
*) 0, VAR_NAMESPACE
, 0,
2263 (struct symtab
**) 0) == NULL
)
2267 printf_filtered ("\nNon-debugging symbols:\n");
2270 printf_filtered (" %08x %s\n",
2283 variables_info (regexp
)
2286 list_symbols (regexp
, 0, 0);
2290 functions_info (regexp
)
2293 list_symbols (regexp
, 1, 0);
2300 list_symbols (regexp
, 2, 0);
2304 /* Tiemann says: "info methods was never implemented." */
2306 methods_info (regexp
)
2309 list_symbols (regexp
, 3, 0);
2313 /* Breakpoint all functions matching regular expression. */
2315 rbreak_command (regexp
)
2318 list_symbols (regexp
, 1, 1);
2322 /* Return Nonzero if block a is lexically nested within block b,
2323 or if a and b have the same pc range.
2324 Return zero otherwise. */
2327 struct block
*a
, *b
;
2331 return BLOCK_START (a
) >= BLOCK_START (b
)
2332 && BLOCK_END (a
) <= BLOCK_END (b
);
2336 /* Helper routine for make_symbol_completion_list. */
2338 int return_val_size
, return_val_index
;
2342 completion_list_add_symbol (symname
)
2345 if (return_val_index
+ 3 > return_val_size
)
2346 return_val
= (char **) xrealloc ((char *) return_val
,
2347 (return_val_size
*= 2) * sizeof (char *));
2349 return_val
[return_val_index
] =
2350 (char *)xmalloc (1 + strlen (symname
));
2352 strcpy (return_val
[return_val_index
], symname
);
2354 return_val
[++return_val_index
] = (char *)NULL
;
2357 /* Return a NULL terminated array of all symbols (regardless of class) which
2358 begin by matching TEXT. If the answer is no symbols, then the return value
2359 is an array which contains only a NULL pointer.
2361 Problem: All of the symbols have to be copied because readline
2362 frees them. I'm not going to worry about this; hopefully there
2363 won't be that many. */
2366 make_symbol_completion_list (text
)
2369 register struct symtab
*s
;
2370 register struct partial_symtab
*ps
;
2371 register struct minimal_symbol
*msymbol
;
2372 register struct objfile
*objfile
;
2373 register struct block
*b
, *surrounding_static_block
= 0;
2375 struct partial_symbol
*psym
;
2377 int text_len
= strlen (text
);
2378 return_val_size
= 100;
2379 return_val_index
= 0;
2381 (char **)xmalloc ((1 + return_val_size
) *sizeof (char *));
2382 return_val
[0] = (char *)NULL
;
2384 /* Look through the partial symtabs for all symbols which begin
2385 by matching TEXT. Add each one that you find to the list. */
2387 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2389 for (ps
= objfile
-> psymtabs
; ps
!= NULL
; ps
= ps
-> next
)
2391 /* If the psymtab's been read in we'll get it when we search
2392 through the blockvector. */
2393 if (ps
->readin
) continue;
2395 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2396 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
2397 + ps
->n_global_syms
);
2400 QUIT
; /* If interrupted, then quit. */
2401 if ((strncmp (SYMBOL_NAME (psym
), text
, text_len
) == 0))
2402 completion_list_add_symbol (SYMBOL_NAME (psym
));
2405 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2406 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
2407 + ps
->n_static_syms
);
2411 if ((strncmp (SYMBOL_NAME (psym
), text
, text_len
) == 0))
2412 completion_list_add_symbol (SYMBOL_NAME (psym
));
2417 /* At this point scan through the misc symbol vectors and add each
2418 symbol you find to the list. Eventually we want to ignore
2419 anything that isn't a text symbol (everything else will be
2420 handled by the psymtab code above). */
2422 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2424 for (msymbol
= objfile
-> msymbols
;
2425 msymbol
->name
!= NULL
; msymbol
++)
2427 if (strncmp (text
, msymbol
-> name
, text_len
) == 0)
2429 completion_list_add_symbol (msymbol
-> name
);
2434 /* Search upwards from currently selected frame (so that we can
2435 complete on local vars. */
2436 for (b
= get_selected_block (); b
; b
= BLOCK_SUPERBLOCK (b
))
2438 if (!BLOCK_SUPERBLOCK (b
))
2439 surrounding_static_block
= b
; /* For elmin of dups */
2441 /* Also catch fields of types defined in this places which
2442 match our text string. Only complete on types visible
2443 from current context. */
2444 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2446 register struct symbol
*sym
= BLOCK_SYM (b
, i
);
2448 if (!strncmp (SYMBOL_NAME (sym
), text
, text_len
))
2449 completion_list_add_symbol (SYMBOL_NAME (sym
));
2451 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2453 struct type
*t
= SYMBOL_TYPE (sym
);
2454 enum type_code c
= TYPE_CODE (t
);
2456 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
2457 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
2458 if (TYPE_FIELD_NAME (t
, j
) &&
2459 !strncmp (TYPE_FIELD_NAME (t
, j
), text
, text_len
))
2460 completion_list_add_symbol (TYPE_FIELD_NAME (t
, j
));
2465 /* Go through the symtabs and check the externs and statics for
2466 symbols which match. */
2468 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2470 for (s
= objfile
->symtabs
; s
!= NULL
; s
= s
-> next
)
2472 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
2474 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2475 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b
, i
)), text
, text_len
))
2476 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
2480 for (objfile
= object_files
; objfile
!= NULL
; objfile
= objfile
-> next
)
2482 for (s
= objfile
-> symtabs
; s
!= NULL
; s
= s
-> next
)
2484 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
2486 /* Don't do this block twice. */
2487 if (b
== surrounding_static_block
) continue;
2489 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2490 if (!strncmp (SYMBOL_NAME (BLOCK_SYM (b
, i
)), text
, text_len
))
2491 completion_list_add_symbol (SYMBOL_NAME (BLOCK_SYM (b
, i
)));
2495 return (return_val
);
2499 /* Add the type of the symbol sym to the type of the current
2500 function whose block we are in (assumed). The type of
2501 this current function is contained in *TYPE.
2503 This basically works as follows: When we find a function
2504 symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record
2505 a pointer to its type in the global in_function_type. Every
2506 time we come across a parameter symbol ('p' in its name), then
2507 this procedure adds the name and type of that parameter
2508 to the function type pointed to by *TYPE. (Which should correspond
2509 to in_function_type if it was called correctly).
2511 Note that since we are modifying a type, the result of
2512 lookup_function_type() should be bcopy()ed before calling
2513 this. When not in strict typing mode, the expression
2514 evaluator can choose to ignore this.
2516 Assumption: All of a function's parameter symbols will
2517 appear before another function symbol is found. The parameters
2518 appear in the same order in the argument list as they do in the
2522 add_param_to_type (type
,sym
)
2526 int num
= ++(TYPE_NFIELDS(*type
));
2528 if(TYPE_NFIELDS(*type
)-1)
2529 TYPE_FIELDS(*type
) = (struct field
*)
2530 (*current_objfile
->xrealloc
) ((char *)(TYPE_FIELDS(*type
)),
2531 num
*sizeof(struct field
));
2533 TYPE_FIELDS(*type
) = (struct field
*)
2534 (*current_objfile
->xmalloc
) (num
*sizeof(struct field
));
2536 TYPE_FIELD_BITPOS(*type
,num
-1) = num
-1;
2537 TYPE_FIELD_BITSIZE(*type
,num
-1) = 0;
2538 TYPE_FIELD_TYPE(*type
,num
-1) = SYMBOL_TYPE(sym
);
2539 TYPE_FIELD_NAME(*type
,num
-1) = SYMBOL_NAME(sym
);
2544 _initialize_symtab ()
2546 add_info ("variables", variables_info
,
2547 "All global and static variable names, or those matching REGEXP.");
2548 add_info ("functions", functions_info
,
2549 "All function names, or those matching REGEXP.");
2551 /* FIXME: This command has at least the following problems:
2552 1. It prints builtin types (in a very strange and confusing fashion).
2553 2. It doesn't print right, e.g. with
2554 typedef struct foo *FOO
2555 type_print prints "FOO" when we want to make it (in this situation)
2556 print "struct foo *".
2557 I also think "ptype" or "whatis" is more likely to be useful (but if
2558 there is much disagreement "info types" can be fixed). */
2559 add_info ("types", types_info
,
2560 "All type names, or those matching REGEXP.");
2563 add_info ("methods", methods_info
,
2564 "All method names, or those matching REGEXP::REGEXP.\n\
2565 If the class qualifier is ommited, it is assumed to be the current scope.\n\
2566 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
2569 add_info ("sources", sources_info
,
2570 "Source files in the program.");
2572 add_com ("rbreak", no_class
, rbreak_command
,
2573 "Set a breakpoint for all functions matching REGEXP.");
2575 /* Initialize the one built-in type that isn't language dependent... */
2576 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
2577 "<unknown type>", (struct objfile
*) NULL
);