1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
31 #include "call-cmds.h"
33 #include "expression.h"
40 #include <sys/types.h>
46 /* Prototypes for local functions */
49 expensive_mangler
PARAMS ((const char *));
52 find_methods
PARAMS ((struct type
*, char *, char **, struct symbol
**));
55 completion_list_add_symbol
PARAMS ((char *, char *, int));
57 static struct symtabs_and_lines
58 decode_line_2
PARAMS ((struct symbol
*[], int, int));
61 rbreak_command
PARAMS ((char *, int));
64 types_info
PARAMS ((char *, int));
67 functions_info
PARAMS ((char *, int));
70 variables_info
PARAMS ((char *, int));
73 sources_info
PARAMS ((char *, int));
76 list_symbols
PARAMS ((char *, int, int));
79 output_source_filename
PARAMS ((char *, int *));
82 operator_chars
PARAMS ((char *, char **));
85 find_line_common
PARAMS ((struct linetable
*, int, int *));
87 static struct partial_symbol
*
88 lookup_partial_symbol
PARAMS ((struct partial_symtab
*, const char *,
89 int, enum namespace));
91 static struct partial_symbol
*
92 lookup_demangled_partial_symbol
PARAMS ((const struct partial_symtab
*,
95 static struct symbol
*
96 lookup_demangled_block_symbol
PARAMS ((const struct block
*, const char *));
98 static struct symtab
*
99 lookup_symtab_1
PARAMS ((char *));
103 /* The single non-language-specific builtin type */
104 struct type
*builtin_type_error
;
106 /* Block in which the most recently searched-for symbol was found.
107 Might be better to make this a parameter to lookup_symbol and
110 const struct block
*block_found
;
112 char no_symtab_msg
[] = "No symbol table is loaded. Use the \"file\" command.";
114 /* While the C++ support is still in flux, issue a possibly helpful hint on
115 using the new command completion feature on single quoted demangled C++
116 symbols. Remove when loose ends are cleaned up. FIXME -fnf */
119 cplusplus_hint (name
)
122 printf ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name
, name
);
123 printf ("(Note leading single quote.)\n");
126 /* Check for a symtab of a specific name; first in symtabs, then in
127 psymtabs. *If* there is no '/' in the name, a match after a '/'
128 in the symtab filename will also work. */
130 static struct symtab
*
131 lookup_symtab_1 (name
)
134 register struct symtab
*s
;
135 register struct partial_symtab
*ps
;
136 register char *slash
;
138 register struct objfile
*objfile
;
140 ALL_SYMTABS (objfile
, s
)
142 if (strcmp (name
, s
->filename
) == 0)
148 ALL_PSYMTABS (objfile
, ps
)
150 if (strcmp (name
, ps
-> filename
) == 0)
154 error ("Internal: readin pst for `%s' found when no symtab found.", name
);
156 return (PSYMTAB_TO_SYMTAB (ps
));
160 slash
= strchr (name
, '/');
165 ALL_SYMTABS (objfile
, s
)
167 int l
= strlen (s
->filename
);
170 && s
->filename
[l
- len
-1] == '/'
171 && (strcmp (s
->filename
+ l
- len
, name
) == 0))
177 ALL_PSYMTABS (objfile
, ps
)
179 int l
= strlen (ps
-> filename
);
182 && ps
-> filename
[l
- len
- 1] == '/'
183 && (strcmp (ps
->filename
+ l
- len
, name
) == 0))
187 error ("Internal: readin pst for `%s' found when no symtab found.", name
);
189 return (PSYMTAB_TO_SYMTAB (ps
));
196 /* Lookup the symbol table of a source file named NAME. Try a couple
197 of variations if the first lookup doesn't work. */
203 register struct symtab
*s
;
206 s
= lookup_symtab_1 (name
);
209 /* If name not found as specified, see if adding ".c" helps. */
211 copy
= (char *) alloca (strlen (name
) + 3);
214 s
= lookup_symtab_1 (copy
);
217 /* We didn't find anything; die. */
221 /* Lookup the partial symbol table of a source file named NAME. This
222 only returns true on an exact match (ie. this semantics are
223 different from lookup_symtab. */
225 struct partial_symtab
*
226 lookup_partial_symtab (name
)
229 register struct partial_symtab
*pst
;
230 register struct objfile
*objfile
;
232 ALL_PSYMTABS (objfile
, pst
)
234 if (strcmp (name
, pst
-> filename
) == 0)
242 /* Demangle a GDB method stub type. */
244 gdb_mangle_name (type
, i
, j
)
248 int mangled_name_len
;
250 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
251 struct fn_field
*method
= &f
[j
];
252 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
253 int is_constructor
= strcmp(field_name
, TYPE_NAME (type
)) == 0;
255 /* Need a new type prefix. */
256 char *const_prefix
= method
->is_const
? "C" : "";
257 char *volatile_prefix
= method
->is_volatile
? "V" : "";
258 char *newname
= type_name_no_tag (type
);
260 int len
= strlen (newname
);
262 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
263 mangled_name_len
= ((is_constructor
? 0 : strlen (field_name
))
265 + strlen (TYPE_FN_FIELD_PHYSNAME (f
, j
))
268 /* Only needed for GNU-mangled names. ANSI-mangled names
269 work with the normal mechanisms. */
270 if (OPNAME_PREFIX_P (field_name
))
272 char *opname
= cplus_mangle_opname (field_name
+ 3, 0);
274 error ("No mangling for \"%s\"", field_name
);
275 mangled_name_len
+= strlen (opname
);
276 mangled_name
= (char *)xmalloc (mangled_name_len
);
278 strncpy (mangled_name
, field_name
, 3);
279 mangled_name
[3] = '\0';
280 strcat (mangled_name
, opname
);
284 mangled_name
= (char *)xmalloc (mangled_name_len
);
286 mangled_name
[0] = '\0';
288 strcpy (mangled_name
, field_name
);
290 strcat (mangled_name
, buf
);
291 strcat (mangled_name
, newname
);
292 strcat (mangled_name
, TYPE_FN_FIELD_PHYSNAME (f
, j
));
298 /* Find which partial symtab on contains PC. Return 0 if none. */
300 struct partial_symtab
*
302 register CORE_ADDR pc
;
304 register struct partial_symtab
*pst
;
305 register struct objfile
*objfile
;
307 ALL_PSYMTABS (objfile
, pst
)
309 if (pc
>= pst
-> textlow
&& pc
< pst
-> texthigh
)
317 /* Find which partial symbol within a psymtab contains PC. Return 0
318 if none. Check all psymtabs if PSYMTAB is 0. */
319 struct partial_symbol
*
320 find_pc_psymbol (psymtab
, pc
)
321 struct partial_symtab
*psymtab
;
324 struct partial_symbol
*best
, *p
;
328 psymtab
= find_pc_psymtab (pc
);
332 best_pc
= psymtab
->textlow
- 1;
334 for (p
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
335 (p
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
336 < psymtab
->n_static_syms
);
338 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
339 && SYMBOL_CLASS (p
) == LOC_BLOCK
340 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
341 && SYMBOL_VALUE_ADDRESS (p
) > best_pc
)
343 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
346 if (best_pc
== psymtab
->textlow
- 1)
352 /* Find the definition for a specified symbol name NAME
353 in namespace NAMESPACE, visible from lexical block BLOCK.
354 Returns the struct symbol pointer, or zero if no symbol is found.
355 If SYMTAB is non-NULL, store the symbol table in which the
356 symbol was found there, or NULL if not found.
357 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
358 NAME is a field of the current implied argument `this'. If so set
359 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
360 BLOCK_FOUND is set to the block in which NAME is found (in the case of
361 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
364 lookup_symbol (name
, block
, namespace, is_a_field_of_this
, symtab
)
366 register const struct block
*block
;
367 const enum namespace namespace;
368 int *is_a_field_of_this
;
369 struct symtab
**symtab
;
371 register struct symbol
*sym
;
372 register struct symtab
*s
;
373 register struct partial_symtab
*ps
;
374 struct blockvector
*bv
;
375 register struct objfile
*objfile
;
376 register struct block
*b
;
377 register struct minimal_symbol
*msymbol
;
379 extern char *gdb_completer_word_break_characters
;
381 /* If NAME contains any characters from gdb_completer_word_break_characters
382 then it is probably from a quoted name string. So check to see if it
383 has a C++ mangled equivalent, and if so, use the mangled equivalent. */
385 if (strpbrk (name
, gdb_completer_word_break_characters
) != NULL
)
387 if ((temp
= expensive_mangler (name
)) != NULL
)
393 /* Search specified block and its superiors. */
397 sym
= lookup_block_symbol (block
, name
, namespace);
403 /* Search the list of symtabs for one which contains the
404 address of the start of this block. */
405 ALL_SYMTABS (objfile
, s
)
407 bv
= BLOCKVECTOR (s
);
408 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
409 if (BLOCK_START (b
) <= BLOCK_START (block
)
410 && BLOCK_END (b
) > BLOCK_START (block
))
419 block
= BLOCK_SUPERBLOCK (block
);
422 /* But that doesn't do any demangling for the STATIC_BLOCK.
423 I'm not sure whether demangling is needed in the case of
424 nested function in inner blocks; if so this needs to be changed.
426 Don't need to mess with the psymtabs; if we have a block,
427 that file is read in. If we don't, then we deal later with
428 all the psymtab stuff that needs checking. */
429 if (namespace == VAR_NAMESPACE
&& block
!= NULL
)
432 /* Find the right symtab. */
433 ALL_SYMTABS (objfile
, s
)
435 bv
= BLOCKVECTOR (s
);
436 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
437 if (BLOCK_START (b
) <= BLOCK_START (block
)
438 && BLOCK_END (b
) > BLOCK_START (block
))
440 sym
= lookup_demangled_block_symbol (b
, name
);
453 /* C++: If requested to do so by the caller,
454 check to see if NAME is a field of `this'. */
455 if (is_a_field_of_this
)
457 struct value
*v
= value_of_this (0);
459 *is_a_field_of_this
= 0;
460 if (v
&& check_field (v
, name
))
462 *is_a_field_of_this
= 1;
469 /* Now search all global blocks. Do the symtab's first, then
470 check the psymtab's */
472 ALL_SYMTABS (objfile
, s
)
474 bv
= BLOCKVECTOR (s
);
475 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
476 sym
= lookup_block_symbol (block
, name
, namespace);
486 /* Check for the possibility of the symbol being a global function
487 that is stored in one of the minimal symbol tables. Eventually, all
488 global symbols might be resolved in this way. */
490 if (namespace == VAR_NAMESPACE
)
492 msymbol
= lookup_minimal_symbol (name
, (struct objfile
*) NULL
);
496 /* Test each minimal symbol to see if the minimal symbol's name
497 is a C++ mangled name that matches a user visible name. */
501 ALL_MSYMBOLS (objfile
, msymbol
)
503 demangled
= demangle_and_match (msymbol
-> name
, name
, 0);
504 if (demangled
!= NULL
)
510 msymbol
= NULL
; /* Not found */
516 s
= find_pc_symtab (msymbol
-> address
);
517 /* If S is NULL, there are no debug symbols for this file.
518 Skip this stuff and check for matching static symbols below. */
521 bv
= BLOCKVECTOR (s
);
522 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
523 sym
= lookup_block_symbol (block
, msymbol
-> name
, namespace);
524 /* We kept static functions in minimal symbol table as well as
525 in static scope. We want to find them in the symbol table. */
527 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
528 sym
= lookup_block_symbol (block
, msymbol
-> name
,
532 /* sym == 0 if symbol was found in the minimal symbol table
533 but not in the symtab.
534 Return 0 to use the msymbol definition of "foo_".
536 This happens for Fortran "foo_" symbols,
537 which are "foo" in the symtab.
539 This can also happen if "asm" is used to make a
540 regular symbol but not a debugging symbol, e.g.
552 ALL_PSYMTABS (objfile
, ps
)
554 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
556 s
= PSYMTAB_TO_SYMTAB(ps
);
557 bv
= BLOCKVECTOR (s
);
558 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
559 sym
= lookup_block_symbol (block
, name
, namespace);
561 error ("Internal: global symbol `%s' found in psymtab but not in symtab", name
);
568 /* Now search all per-file blocks.
569 Not strictly correct, but more useful than an error.
570 Do the symtabs first, then check the psymtabs */
572 ALL_SYMTABS (objfile
, s
)
574 bv
= BLOCKVECTOR (s
);
575 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
576 sym
= lookup_block_symbol (block
, name
, namespace);
586 ALL_PSYMTABS (objfile
, ps
)
588 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
590 s
= PSYMTAB_TO_SYMTAB(ps
);
591 bv
= BLOCKVECTOR (s
);
592 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
593 sym
= lookup_block_symbol (block
, name
, namespace);
595 error ("Internal: static symbol `%s' found in psymtab but not in symtab", name
);
602 /* Now search all per-file blocks for static mangled symbols.
603 Do the symtabs first, then check the psymtabs. */
605 if (namespace == VAR_NAMESPACE
)
607 ALL_SYMTABS (objfile
, s
)
609 bv
= BLOCKVECTOR (s
);
610 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
611 sym
= lookup_demangled_block_symbol (block
, name
);
621 ALL_PSYMTABS (objfile
, ps
)
623 if (!ps
->readin
&& lookup_demangled_partial_symbol (ps
, name
))
625 s
= PSYMTAB_TO_SYMTAB(ps
);
626 bv
= BLOCKVECTOR (s
);
627 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
628 sym
= lookup_demangled_block_symbol (block
, name
);
630 error ("Internal: mangled static symbol `%s' found in psymtab but not in symtab", name
);
643 /* Look for a static demangled symbol in block BLOCK. */
645 static struct symbol
*
646 lookup_demangled_block_symbol (block
, name
)
647 register const struct block
*block
;
650 register int bot
, top
;
651 register struct symbol
*sym
;
655 top
= BLOCK_NSYMS (block
);
659 sym
= BLOCK_SYM (block
, bot
);
660 if (SYMBOL_NAMESPACE (sym
) == VAR_NAMESPACE
)
662 demangled
= demangle_and_match (SYMBOL_NAME (sym
), name
, 0);
663 if (demangled
!= NULL
)
675 /* Look, in partial_symtab PST, for static mangled symbol NAME. */
677 static struct partial_symbol
*
678 lookup_demangled_partial_symbol (pst
, name
)
679 const struct partial_symtab
*pst
;
682 struct partial_symbol
*start
, *psym
;
683 int length
= pst
->n_static_syms
;
687 return (struct partial_symbol
*) 0;
689 start
= pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
;
690 for (psym
= start
; psym
< start
+ length
; psym
++)
692 if (SYMBOL_NAMESPACE (psym
) == VAR_NAMESPACE
)
694 demangled
= demangle_and_match (SYMBOL_NAME (psym
), name
, 0);
695 if (demangled
!= NULL
)
706 /* Look, in partial_symtab PST, for symbol NAME. Check the global
707 symbols if GLOBAL, the static symbols if not */
709 static struct partial_symbol
*
710 lookup_partial_symbol (pst
, name
, global
, namespace)
711 struct partial_symtab
*pst
;
714 enum namespace namespace;
716 struct partial_symbol
*start
, *psym
;
717 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
720 return (struct partial_symbol
*) 0;
723 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
724 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
726 if (global
) /* This means we can use a binary */
729 struct partial_symbol
*top
, *bottom
, *center
;
731 /* Binary search. This search is guaranteed to end with center
732 pointing at the earliest partial symbol with the correct
733 name. At that point *all* partial symbols with that name
734 will be checked against the correct namespace. */
736 top
= start
+ length
- 1;
739 center
= bottom
+ (top
- bottom
) / 2;
741 assert (center
< top
);
743 if (strcmp (SYMBOL_NAME (center
), name
) >= 0)
748 assert (top
== bottom
);
750 while (!strcmp (SYMBOL_NAME (top
), name
))
752 if (SYMBOL_NAMESPACE (top
) == namespace)
759 /* Can't use a binary search */
760 for (psym
= start
; psym
< start
+ length
; psym
++)
761 if (namespace == SYMBOL_NAMESPACE (psym
)
762 && !strcmp (name
, SYMBOL_NAME (psym
)))
766 return (struct partial_symbol
*) 0;
769 /* Find the psymtab containing main(). */
771 struct partial_symtab
*
774 register struct partial_symtab
*pst
;
775 register struct objfile
*objfile
;
777 ALL_PSYMTABS (objfile
, pst
)
779 if (lookup_partial_symbol (pst
, "main", 1, VAR_NAMESPACE
))
787 /* Look for a symbol in block BLOCK. */
790 lookup_block_symbol (block
, name
, namespace)
791 register const struct block
*block
;
793 const enum namespace namespace;
795 register int bot
, top
, inc
;
796 register struct symbol
*sym
, *parameter_sym
;
798 top
= BLOCK_NSYMS (block
);
801 /* If the blocks's symbols were sorted, start with a binary search. */
803 if (BLOCK_SHOULD_SORT (block
))
805 /* First, advance BOT to not far before
806 the first symbol whose name is NAME. */
810 inc
= (top
- bot
+ 1);
811 /* No need to keep binary searching for the last few bits worth. */
814 inc
= (inc
>> 1) + bot
;
815 sym
= BLOCK_SYM (block
, inc
);
816 if (SYMBOL_NAME (sym
)[0] < name
[0])
818 else if (SYMBOL_NAME (sym
)[0] > name
[0])
820 else if (strcmp (SYMBOL_NAME (sym
), name
) < 0)
826 /* Now scan forward until we run out of symbols,
827 find one whose name is greater than NAME,
829 If there is more than one symbol with the right name and namespace,
830 we return the first one. dbxread.c is careful to make sure
831 that if one is a register then it comes first. */
833 top
= BLOCK_NSYMS (block
);
836 sym
= BLOCK_SYM (block
, bot
);
837 inc
= SYMBOL_NAME (sym
)[0] - name
[0];
839 inc
= strcmp (SYMBOL_NAME (sym
), name
);
840 if (inc
== 0 && SYMBOL_NAMESPACE (sym
) == namespace)
849 /* Here if block isn't sorted.
850 This loop is equivalent to the loop above,
851 but hacked greatly for speed.
853 Note that parameter symbols do not always show up last in the
854 list; this loop makes sure to take anything else other than
855 parameter symbols first; it only uses parameter symbols as a
856 last resort. Note that this only takes up extra computation
859 parameter_sym
= (struct symbol
*) 0;
860 top
= BLOCK_NSYMS (block
);
864 sym
= BLOCK_SYM (block
, bot
);
865 if (SYMBOL_NAME (sym
)[0] == inc
866 && !strcmp (SYMBOL_NAME (sym
), name
)
867 && SYMBOL_NAMESPACE (sym
) == namespace)
869 if (SYMBOL_CLASS (sym
) == LOC_ARG
870 || SYMBOL_CLASS (sym
) == LOC_LOCAL_ARG
871 || SYMBOL_CLASS (sym
) == LOC_REF_ARG
872 || SYMBOL_CLASS (sym
) == LOC_REGPARM
)
879 return parameter_sym
; /* Will be 0 if not found. */
882 /* Return the symbol for the function which contains a specified
883 lexical block, described by a struct block BL. */
889 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
890 bl
= BLOCK_SUPERBLOCK (bl
);
892 return BLOCK_FUNCTION (bl
);
895 /* Subroutine of find_pc_line */
899 register CORE_ADDR pc
;
901 register struct block
*b
;
902 struct blockvector
*bv
;
903 register struct symtab
*s
= 0;
904 register struct partial_symtab
*ps
;
905 register struct objfile
*objfile
;
907 /* Search all symtabs for one whose file contains our pc */
909 ALL_SYMTABS (objfile
, s
)
911 bv
= BLOCKVECTOR (s
);
912 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
913 if (BLOCK_START (b
) <= pc
914 && BLOCK_END (b
) > pc
)
920 ps
= find_pc_psymtab (pc
);
921 if (ps
&& ps
->readin
)
923 printf_filtered ("(Internal error: pc 0x%x in read in psymtab, but not in symtab.)\n", pc
);
927 s
= PSYMTAB_TO_SYMTAB (ps
);
935 /* Find the source file and line number for a given PC value.
936 Return a structure containing a symtab pointer, a line number,
937 and a pc range for the entire source line.
938 The value's .pc field is NOT the specified pc.
939 NOTCURRENT nonzero means, if specified pc is on a line boundary,
940 use the line that ends there. Otherwise, in that case, the line
941 that begins there is used. */
943 struct symtab_and_line
944 find_pc_line (pc
, notcurrent
)
949 register struct linetable
*l
;
952 register struct linetable_entry
*item
;
953 struct symtab_and_line val
;
954 struct blockvector
*bv
;
956 /* Info on best line seen so far, and where it starts, and its file. */
959 CORE_ADDR best_pc
= 0;
960 CORE_ADDR best_end
= 0;
961 struct symtab
*best_symtab
= 0;
963 /* Store here the first line number
964 of a file which contains the line at the smallest pc after PC.
965 If we don't find a line whose range contains PC,
966 we will use a line one less than this,
967 with a range from the start of that file to the first line's pc. */
969 CORE_ADDR alt_pc
= 0;
970 struct symtab
*alt_symtab
= 0;
972 /* Info on best line seen in this file. */
977 /* Info on first line of this file. */
982 /* If this pc is not from the current frame,
983 it is the address of the end of a call instruction.
984 Quite likely that is the start of the following statement.
985 But what we want is the statement containing the instruction.
986 Fudge the pc to make sure we get that. */
988 if (notcurrent
) pc
-= 1;
990 s
= find_pc_symtab (pc
);
1000 bv
= BLOCKVECTOR (s
);
1002 /* Look at all the symtabs that share this blockvector.
1003 They all have the same apriori range, that we found was right;
1004 but they have different line tables. */
1006 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1008 /* Find the best line in this symtab. */
1015 for (i
= 0; i
< len
; i
++)
1017 item
= &(l
->item
[i
]);
1021 first_line
= item
->line
;
1022 first_pc
= item
->pc
;
1024 /* Return the last line that did not start after PC. */
1027 prev_line
= item
->line
;
1034 /* Is this file's best line closer than the best in the other files?
1035 If so, record this file, and its best line, as best so far. */
1036 if (prev_line
>= 0 && prev_pc
> best_pc
)
1039 best_line
= prev_line
;
1041 /* If another line is in the linetable, and its PC is closer
1042 than the best_end we currently have, take it as best_end. */
1043 if (i
< len
&& (best_end
== 0 || best_end
> item
->pc
))
1044 best_end
= item
->pc
;
1046 /* Is this file's first line closer than the first lines of other files?
1047 If so, record this file, and its first line, as best alternate. */
1048 if (first_line
>= 0 && first_pc
> pc
1049 && (alt_pc
== 0 || first_pc
< alt_pc
))
1052 alt_line
= first_line
;
1056 if (best_symtab
== 0)
1058 val
.symtab
= alt_symtab
;
1059 val
.line
= alt_line
- 1;
1060 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1065 val
.symtab
= best_symtab
;
1066 val
.line
= best_line
;
1068 if (best_end
&& (alt_pc
== 0 || best_end
< alt_pc
))
1073 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1078 /* Find the PC value for a given source file and line number.
1079 Returns zero for invalid line number.
1080 The source file is specified with a struct symtab. */
1083 find_line_pc (symtab
, line
)
1084 struct symtab
*symtab
;
1087 register struct linetable
*l
;
1093 l
= LINETABLE (symtab
);
1094 ind
= find_line_common(l
, line
, &dummy
);
1095 return (ind
>= 0) ? l
->item
[ind
].pc
: 0;
1098 /* Find the range of pc values in a line.
1099 Store the starting pc of the line into *STARTPTR
1100 and the ending pc (start of next line) into *ENDPTR.
1101 Returns 1 to indicate success.
1102 Returns 0 if could not find the specified line. */
1105 find_line_pc_range (symtab
, thisline
, startptr
, endptr
)
1106 struct symtab
*symtab
;
1108 CORE_ADDR
*startptr
, *endptr
;
1110 register struct linetable
*l
;
1112 int exact_match
; /* did we get an exact linenumber match */
1117 l
= LINETABLE (symtab
);
1118 ind
= find_line_common (l
, thisline
, &exact_match
);
1121 *startptr
= l
->item
[ind
].pc
;
1122 /* If we have not seen an entry for the specified line,
1123 assume that means the specified line has zero bytes. */
1124 if (!exact_match
|| ind
== l
->nitems
-1)
1125 *endptr
= *startptr
;
1127 /* Perhaps the following entry is for the following line.
1128 It's worth a try. */
1129 if (ind
+1 < l
->nitems
1130 && l
->item
[ind
+1].line
== thisline
+ 1)
1131 *endptr
= l
->item
[ind
+1].pc
;
1133 *endptr
= find_line_pc (symtab
, thisline
+1);
1140 /* Given a line table and a line number, return the index into the line
1141 table for the pc of the nearest line whose number is >= the specified one.
1142 Return -1 if none is found. The value is >= 0 if it is an index.
1144 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1147 find_line_common (l
, lineno
, exact_match
)
1148 register struct linetable
*l
;
1149 register int lineno
;
1155 /* BEST is the smallest linenumber > LINENO so far seen,
1156 or 0 if none has been seen so far.
1157 BEST_INDEX identifies the item for it. */
1159 int best_index
= -1;
1168 for (i
= 0; i
< len
; i
++)
1170 register struct linetable_entry
*item
= &(l
->item
[i
]);
1172 if (item
->line
== lineno
)
1178 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
1185 /* If we got here, we didn't get an exact match. */
1192 find_pc_line_pc_range (pc
, startptr
, endptr
)
1194 CORE_ADDR
*startptr
, *endptr
;
1196 struct symtab_and_line sal
;
1197 sal
= find_pc_line (pc
, 0);
1200 return sal
.symtab
!= 0;
1203 /* If P is of the form "operator[ \t]+..." where `...' is
1204 some legitimate operator text, return a pointer to the
1205 beginning of the substring of the operator text.
1206 Otherwise, return "". */
1208 operator_chars (p
, end
)
1213 if (strncmp (p
, "operator", 8))
1217 /* Don't get faked out by `operator' being part of a longer
1219 if (isalpha(*p
) || *p
== '_' || *p
== '$' || *p
== '\0')
1222 /* Allow some whitespace between `operator' and the operator symbol. */
1223 while (*p
== ' ' || *p
== '\t')
1226 /* Recognize 'operator TYPENAME'. */
1228 if (isalpha(*p
) || *p
== '_' || *p
== '$')
1230 register char *q
= p
+1;
1231 while (isalnum(*q
) || *q
== '_' || *q
== '$')
1256 if (p
[1] == '=' || p
[1] == p
[0])
1267 error ("`operator ()' must be specified without whitespace in `()'");
1272 error ("`operator ?:' must be specified without whitespace in `?:'");
1277 error ("`operator []' must be specified without whitespace in `[]'");
1281 error ("`operator %s' not supported", p
);
1288 /* Recursive helper function for decode_line_1.
1289 * Look for methods named NAME in type T.
1290 * Return number of matches.
1291 * Put matches in PHYSNAMES and SYM_ARR (which better be big enough!).
1292 * These allocations seem to define "big enough":
1293 * sym_arr = (struct symbol **) alloca(TYPE_NFN_FIELDS_TOTAL (t) * sizeof(struct symbol*));
1294 * physnames = (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t) * sizeof(char*));
1298 find_methods (t
, name
, physnames
, sym_arr
)
1302 struct symbol
**sym_arr
;
1306 struct symbol
*sym_class
;
1307 char *class_name
= type_name_no_tag (t
);
1308 /* Ignore this class if it doesn't have a name.
1309 This prevents core dumps, but is just a workaround
1310 because we might not find the function in
1311 certain cases, such as
1312 struct D {virtual int f();}
1313 struct C : D {virtual int g();}
1314 (in this case g++ 1.35.1- does not put out a name
1315 for D as such, it defines type 19 (for example) in
1316 the same stab as C, and then does a
1317 .stabs "D:T19" and a .stabs "D:t19".
1319 "break C::f" should not be looking for field f in
1321 but just for the field f in the baseclasses of C
1322 (no matter what their names).
1324 However, I don't know how to replace the code below
1325 that depends on knowing the name of D. */
1327 && (sym_class
= lookup_symbol (class_name
,
1328 (struct block
*)NULL
,
1331 (struct symtab
**)NULL
)))
1334 t
= SYMBOL_TYPE (sym_class
);
1335 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
1336 method_counter
>= 0;
1340 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
1342 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
1343 if (!strcmp (name
, method_name
))
1344 /* Find all the fields with that name. */
1345 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
1350 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
1351 check_stub_method (t
, method_counter
, field_counter
);
1352 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
1353 physnames
[i1
] = (char*) alloca (strlen (phys_name
) + 1);
1354 strcpy (physnames
[i1
], phys_name
);
1355 sym_arr
[i1
] = lookup_symbol (phys_name
,
1356 SYMBOL_BLOCK_VALUE (sym_class
),
1359 (struct symtab
**) NULL
);
1360 if (sym_arr
[i1
]) i1
++;
1363 fputs_filtered("(Cannot find method ", stdout
);
1364 fputs_demangled(phys_name
, stdout
, DMGL_PARAMS
);
1365 fputs_filtered(" - possibly inlined.)\n", stdout
);
1370 /* Only search baseclasses if there is no match yet,
1371 * since names in derived classes override those in baseclasses.
1375 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
1376 i1
+= find_methods(TYPE_BASECLASS(t
, ibase
), name
,
1377 physnames
+ i1
, sym_arr
+ i1
);
1381 /* Parse a string that specifies a line number.
1382 Pass the address of a char * variable; that variable will be
1383 advanced over the characters actually parsed.
1387 LINENUM -- that line number in current file. PC returned is 0.
1388 FILE:LINENUM -- that line in that file. PC returned is 0.
1389 FUNCTION -- line number of openbrace of that function.
1390 PC returned is the start of the function.
1391 VARIABLE -- line number of definition of that variable.
1393 FILE:FUNCTION -- likewise, but prefer functions in that file.
1394 *EXPR -- line in which address EXPR appears.
1396 FUNCTION may be an undebuggable function found in minimal symbol table.
1398 If the argument FUNFIRSTLINE is nonzero, we want the first line
1399 of real code inside a function when a function is specified.
1401 DEFAULT_SYMTAB specifies the file to use if none is specified.
1402 It defaults to current_source_symtab.
1403 DEFAULT_LINE specifies the line number to use for relative
1404 line numbers (that start with signs). Defaults to current_source_line.
1406 Note that it is possible to return zero for the symtab
1407 if no file is validly specified. Callers must check that.
1408 Also, the line number returned may be invalid. */
1410 struct symtabs_and_lines
1411 decode_line_1 (argptr
, funfirstline
, default_symtab
, default_line
)
1414 struct symtab
*default_symtab
;
1417 struct symtabs_and_lines values
;
1418 struct symtab_and_line val
;
1419 register char *p
, *p1
;
1421 register struct symtab
*s
;
1423 register struct symbol
*sym
;
1424 /* The symtab that SYM was found in. */
1425 struct symtab
*sym_symtab
;
1427 register CORE_ADDR pc
;
1428 register struct minimal_symbol
*msymbol
;
1430 struct symbol
*sym_class
;
1432 struct symbol
**sym_arr
;
1435 char *saved_arg
= *argptr
;
1436 extern char *gdb_completer_quote_characters
;
1438 /* Defaults have defaults. */
1440 if (default_symtab
== 0)
1442 default_symtab
= current_source_symtab
;
1443 default_line
= current_source_line
;
1447 /* Check to see if *ARGPTR points to a string that has been quoted with
1448 gdb_completer_quote_characters. If so, P will be left pointing at
1449 someplace other than *ARGPTR */
1451 if (((p
= skip_quoted (*argptr
)) != *argptr
) &&
1452 ((*(p
- 1) != **argptr
) ||
1453 (strchr (gdb_completer_quote_characters
, **argptr
) == NULL
)))
1455 /* Not quoted symbol string specification, reset P */
1459 /* See if arg is *PC or '<some symbol specifier string>' */
1461 if ((**argptr
== '*') || (p
!= *argptr
))
1463 if (**argptr
== '*')
1467 pc
= parse_and_eval_address_1 (argptr
);
1468 values
.sals
= (struct symtab_and_line
*)
1469 xmalloc (sizeof (struct symtab_and_line
));
1471 values
.sals
[0] = find_pc_line (pc
, 0);
1472 values
.sals
[0].pc
= pc
;
1476 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
1480 for (p
= *argptr
; *p
; p
++)
1482 if (p
[0] == ':' || p
[0] == ' ' || p
[0] == '\t')
1485 while (p
[0] == ' ' || p
[0] == '\t') p
++;
1493 /* Extract the class name. */
1495 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1496 copy
= (char *) alloca (p
- *argptr
+ 1);
1497 memcpy (copy
, *argptr
, p
- *argptr
);
1498 copy
[p
- *argptr
] = 0;
1500 /* Discard the class name from the arg. */
1502 while (*p
== ' ' || *p
== '\t') p
++;
1505 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
1506 (struct symtab
**)NULL
);
1509 ( TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_STRUCT
1510 || TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_UNION
))
1512 /* Arg token is not digits => try it as a function name
1513 Find the next token (everything up to end or next whitespace). */
1515 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',' && *p
!=':') p
++;
1516 q
= operator_chars (*argptr
, &q1
);
1521 char *tmp
= alloca (q1
- q
+ 1);
1522 memcpy (tmp
, q
, q1
- q
);
1524 opname
= cplus_mangle_opname (tmp
, 1);
1527 warning ("no mangling for \"%s\"", tmp
);
1528 cplusplus_hint (saved_arg
);
1529 return_to_top_level ();
1531 copy
= (char*) alloca (3 + strlen(opname
));
1532 sprintf (copy
, "__%s", opname
);
1537 copy
= (char *) alloca (p
- *argptr
+ 1 + (q1
- q
));
1538 memcpy (copy
, *argptr
, p
- *argptr
);
1539 copy
[p
- *argptr
] = '\0';
1542 /* no line number may be specified */
1543 while (*p
== ' ' || *p
== '\t') p
++;
1547 i1
= 0; /* counter for the symbol array */
1548 t
= SYMBOL_TYPE (sym_class
);
1549 sym_arr
= (struct symbol
**) alloca(TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(struct symbol
*));
1550 physnames
= (char **) alloca (TYPE_NFN_FIELDS_TOTAL (t
) * sizeof(char*));
1552 if (destructor_name_p (copy
, t
))
1554 /* destructors are a special case. */
1555 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, 0);
1556 int len
= TYPE_FN_FIELDLIST_LENGTH (t
, 0) - 1;
1557 char *phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, len
);
1558 physnames
[i1
] = (char *)alloca (strlen (phys_name
) + 1);
1559 strcpy (physnames
[i1
], phys_name
);
1561 lookup_symbol (phys_name
, SYMBOL_BLOCK_VALUE (sym_class
),
1562 VAR_NAMESPACE
, 0, (struct symtab
**)NULL
);
1563 if (sym_arr
[i1
]) i1
++;
1566 i1
= find_methods (t
, copy
, physnames
, sym_arr
);
1569 /* There is exactly one field with that name. */
1572 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1574 /* Arg is the name of a function */
1575 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1578 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1580 values
.sals
[0] = find_pc_line (pc
, 0);
1581 values
.sals
[0].pc
= (values
.sals
[0].end
&& values
.sals
[0].pc
!= pc
) ? values
.sals
[0].end
: pc
;
1591 /* There is more than one field with that name
1592 (overloaded). Ask the user which one to use. */
1593 return decode_line_2 (sym_arr
, i1
, funfirstline
);
1599 if (OPNAME_PREFIX_P (copy
))
1601 tmp
= (char *)alloca (strlen (copy
+3) + 9);
1602 strcpy (tmp
, "operator ");
1603 strcat (tmp
, copy
+3);
1608 warning ("the class `%s' does not have destructor defined",
1611 warning ("the class %s does not have any method named %s",
1612 sym_class
->name
, tmp
);
1613 cplusplus_hint (saved_arg
);
1614 return_to_top_level ();
1619 /* The quotes are important if copy is empty. */
1620 warning ("can't find class, struct, or union named \"%s\"",
1622 cplusplus_hint (saved_arg
);
1623 return_to_top_level ();
1629 /* Extract the file name. */
1631 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
1632 copy
= (char *) alloca (p
- *argptr
+ 1);
1633 memcpy (copy
, *argptr
, p
- *argptr
);
1634 copy
[p
- *argptr
] = 0;
1636 /* Find that file's data. */
1637 s
= lookup_symtab (copy
);
1640 if (!have_full_symbols () && !have_partial_symbols ())
1641 error (no_symtab_msg
);
1642 error ("No source file named %s.", copy
);
1645 /* Discard the file name from the arg. */
1647 while (*p
== ' ' || *p
== '\t') p
++;
1651 /* S is specified file's symtab, or 0 if no file specified.
1652 arg no longer contains the file name. */
1654 /* Check whether arg is all digits (and sign) */
1657 if (*p
== '-' || *p
== '+') p
++;
1658 while (*p
>= '0' && *p
<= '9')
1661 if (p
!= *argptr
&& (*p
== 0 || *p
== ' ' || *p
== '\t' || *p
== ','))
1663 /* We found a token consisting of all digits -- at least one digit. */
1664 enum sign
{none
, plus
, minus
} sign
= none
;
1666 /* This is where we need to make sure that we have good defaults.
1667 We must guarantee that this section of code is never executed
1668 when we are called with just a function name, since
1669 select_source_symtab calls us with such an argument */
1671 if (s
== 0 && default_symtab
== 0)
1673 select_source_symtab (0);
1674 default_symtab
= current_source_symtab
;
1675 default_line
= current_source_line
;
1678 if (**argptr
== '+')
1679 sign
= plus
, (*argptr
)++;
1680 else if (**argptr
== '-')
1681 sign
= minus
, (*argptr
)++;
1682 val
.line
= atoi (*argptr
);
1689 val
.line
= default_line
+ val
.line
;
1695 val
.line
= default_line
- val
.line
;
1700 break; /* No need to adjust val.line. */
1703 while (*p
== ' ' || *p
== '\t') p
++;
1709 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1710 values
.sals
[0] = val
;
1715 /* Arg token is not digits => try it as a variable name
1716 Find the next token (everything up to end or next whitespace). */
1718 p
= skip_quoted (*argptr
);
1719 copy
= (char *) alloca (p
- *argptr
+ 1);
1720 memcpy (copy
, *argptr
, p
- *argptr
);
1721 copy
[p
- *argptr
] = '\0';
1722 if ((copy
[0] == copy
[p
- *argptr
- 1])
1723 && strchr (gdb_completer_quote_characters
, copy
[0]) != NULL
)
1726 copy
[p
- *argptr
- 1] = '\0';
1728 if ((temp
= expensive_mangler (copy
)) != NULL
)
1733 while (*p
== ' ' || *p
== '\t') p
++;
1736 /* Look up that token as a variable.
1737 If file specified, use that file's per-file block to start with. */
1739 sym
= lookup_symbol (copy
,
1740 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
1741 : get_selected_block ()),
1742 VAR_NAMESPACE
, 0, &sym_symtab
);
1746 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1748 /* Arg is the name of a function */
1749 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) + FUNCTION_START_OFFSET
;
1752 val
= find_pc_line (pc
, 0);
1753 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1754 /* Convex: no need to suppress code on first line, if any */
1757 /* If SKIP_PROLOGUE left us in mid-line, and the next line is still
1758 part of the same function:
1759 advance to next line,
1760 recalculate its line number (might not be N+1). */
1761 if (val
.pc
!= pc
&& val
.end
&&
1762 lookup_minimal_symbol_by_pc (pc
) == lookup_minimal_symbol_by_pc (val
.end
)) {
1763 pc
= val
.end
; /* First pc of next line */
1764 val
= find_pc_line (pc
, 0);
1768 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1769 values
.sals
[0] = val
;
1772 /* I think this is always the same as the line that
1773 we calculate above, but the general principle is
1774 "trust the symbols more than stuff like
1776 if (SYMBOL_LINE (sym
) != 0)
1777 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1781 else if (SYMBOL_LINE (sym
) != 0)
1783 /* We know its line number. */
1784 values
.sals
= (struct symtab_and_line
*)
1785 xmalloc (sizeof (struct symtab_and_line
));
1787 memset (&values
.sals
[0], 0, sizeof (values
.sals
[0]));
1788 values
.sals
[0].symtab
= sym_symtab
;
1789 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1793 /* This can happen if it is compiled with a compiler which doesn't
1794 put out line numbers for variables. */
1795 error ("Line number not known for symbol \"%s\"", copy
);
1798 msymbol
= lookup_minimal_symbol (copy
, (struct objfile
*) NULL
);
1799 if (msymbol
!= NULL
)
1803 val
.pc
= msymbol
-> address
+ FUNCTION_START_OFFSET
;
1805 SKIP_PROLOGUE (val
.pc
);
1806 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof (struct symtab_and_line
));
1807 values
.sals
[0] = val
;
1812 if (!have_full_symbols () &&
1813 !have_partial_symbols () && !have_minimal_symbols ())
1814 error (no_symtab_msg
);
1816 error ("Function \"%s\" not defined.", copy
);
1817 return values
; /* for lint */
1820 struct symtabs_and_lines
1821 decode_line_spec (string
, funfirstline
)
1825 struct symtabs_and_lines sals
;
1827 error ("Empty line specification.");
1828 sals
= decode_line_1 (&string
, funfirstline
,
1829 current_source_symtab
, current_source_line
);
1831 error ("Junk at end of line specification: %s", string
);
1835 /* Given a list of NELTS symbols in sym_arr (with corresponding
1836 mangled names in physnames), return a list of lines to operate on
1837 (ask user if necessary). */
1838 static struct symtabs_and_lines
1839 decode_line_2 (sym_arr
, nelts
, funfirstline
)
1840 struct symbol
*sym_arr
[];
1844 struct symtabs_and_lines values
, return_values
;
1845 register CORE_ADDR pc
;
1850 values
.sals
= (struct symtab_and_line
*) alloca (nelts
* sizeof(struct symtab_and_line
));
1851 return_values
.sals
= (struct symtab_and_line
*) xmalloc (nelts
* sizeof(struct symtab_and_line
));
1854 printf("[0] cancel\n[1] all\n");
1857 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
1859 /* Arg is the name of a function */
1860 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym_arr
[i
]))
1861 + FUNCTION_START_OFFSET
;
1864 values
.sals
[i
] = find_pc_line (pc
, 0);
1865 values
.sals
[i
].pc
= (values
.sals
[i
].end
&& values
.sals
[i
].pc
!= pc
) ?
1866 values
.sals
[i
].end
: pc
;
1867 printf("[%d] file:%s; line number:%d\n",
1868 (i
+2), values
.sals
[i
].symtab
->filename
, values
.sals
[i
].line
);
1870 else printf ("?HERE\n");
1874 if ((prompt
= getenv ("PS2")) == NULL
)
1878 printf("%s ",prompt
);
1881 args
= command_line_input ((char *) NULL
, 0);
1884 error_no_arg ("one or more choice numbers");
1892 while (*arg1
>= '0' && *arg1
<= '9') arg1
++;
1893 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
1894 error ("Arguments must be choice numbers.");
1899 error ("cancelled");
1902 memcpy (return_values
.sals
, values
.sals
,
1903 (nelts
* sizeof(struct symtab_and_line
)));
1904 return_values
.nelts
= nelts
;
1905 return return_values
;
1908 if (num
> nelts
+ 2)
1910 printf ("No choice number %d.\n", num
);
1915 if (values
.sals
[num
].pc
)
1917 return_values
.sals
[i
++] = values
.sals
[num
];
1918 values
.sals
[num
].pc
= 0;
1922 printf ("duplicate request for %d ignored.\n", num
);
1927 while (*args
== ' ' || *args
== '\t') args
++;
1929 return_values
.nelts
= i
;
1930 return return_values
;
1934 /* Slave routine for sources_info. Force line breaks at ,'s.
1935 NAME is the name to print and *FIRST is nonzero if this is the first
1936 name printed. Set *FIRST to zero. */
1938 output_source_filename (name
, first
)
1942 /* Table of files printed so far. Since a single source file can
1943 result in several partial symbol tables, we need to avoid printing
1944 it more than once. Note: if some of the psymtabs are read in and
1945 some are not, it gets printed both under "Source files for which
1946 symbols have been read" and "Source files for which symbols will
1947 be read in on demand". I consider this a reasonable way to deal
1948 with the situation. I'm not sure whether this can also happen for
1949 symtabs; it doesn't hurt to check. */
1950 static char **tab
= NULL
;
1951 /* Allocated size of tab in elements.
1952 Start with one 256-byte block (when using GNU malloc.c).
1953 24 is the malloc overhead when range checking is in effect. */
1954 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
1955 /* Current size of tab in elements. */
1956 static int tab_cur_size
;
1963 tab
= (char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
1967 /* Is NAME in tab? */
1968 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
1969 if (strcmp (*p
, name
) == 0)
1970 /* Yes; don't print it again. */
1972 /* No; add it to tab. */
1973 if (tab_cur_size
== tab_alloc_size
)
1975 tab_alloc_size
*= 2;
1976 tab
= (char **) xrealloc ((char *) tab
, tab_alloc_size
* sizeof (*tab
));
1978 tab
[tab_cur_size
++] = name
;
1986 printf_filtered (", ");
1990 fputs_filtered (name
, stdout
);
1994 sources_info (ignore
, from_tty
)
1998 register struct symtab
*s
;
1999 register struct partial_symtab
*ps
;
2000 register struct objfile
*objfile
;
2003 if (!have_full_symbols () && !have_partial_symbols ())
2005 error (no_symtab_msg
);
2008 printf_filtered ("Source files for which symbols have been read in:\n\n");
2011 ALL_SYMTABS (objfile
, s
)
2013 output_source_filename (s
-> filename
, &first
);
2015 printf_filtered ("\n\n");
2017 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2020 ALL_PSYMTABS (objfile
, ps
)
2024 output_source_filename (ps
-> filename
, &first
);
2027 printf_filtered ("\n");
2034 char *demangled
= cplus_demangle (name
, 0);
2035 if (demangled
!= NULL
)
2037 int cond
= re_exec (demangled
);
2041 return (re_exec (name
));
2043 #define NAME_MATCH(NAME) name_match(NAME)
2045 /* List all symbols (if REGEXP is 0) or all symbols matching REGEXP.
2046 If CLASS is zero, list all symbols except functions and type names.
2047 If CLASS is 1, list only functions.
2048 If CLASS is 2, list only type names.
2049 If CLASS is 3, list only method names.
2051 BPT is non-zero if we should set a breakpoint at the functions
2055 list_symbols (regexp
, class, bpt
)
2060 register struct symtab
*s
;
2061 register struct partial_symtab
*ps
;
2062 register struct blockvector
*bv
;
2063 struct blockvector
*prev_bv
= 0;
2064 register struct block
*b
;
2066 register struct symbol
*sym
;
2067 struct partial_symbol
*psym
;
2068 struct objfile
*objfile
;
2069 struct minimal_symbol
*msymbol
;
2071 static char *classnames
[]
2072 = {"variable", "function", "type", "method"};
2073 int found_in_file
= 0;
2075 static enum minimal_symbol_type types
[]
2076 = {mst_data
, mst_text
, mst_abs
, mst_unknown
};
2077 static enum minimal_symbol_type types2
[]
2078 = {mst_bss
, mst_text
, mst_abs
, mst_unknown
};
2079 enum minimal_symbol_type ourtype
= types
[class];
2080 enum minimal_symbol_type ourtype2
= types2
[class];
2084 /* Make sure spacing is right for C++ operators.
2085 This is just a courtesy to make the matching less sensitive
2086 to how many spaces the user leaves between 'operator'
2087 and <TYPENAME> or <OPERATOR>. */
2089 char *opname
= operator_chars (regexp
, &opend
);
2092 int fix
= -1; /* -1 means ok; otherwise number of spaces needed. */
2093 if (isalpha(*opname
) || *opname
== '_' || *opname
== '$')
2095 /* There should 1 space between 'operator' and 'TYPENAME'. */
2096 if (opname
[-1] != ' ' || opname
[-2] == ' ')
2101 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2102 if (opname
[-1] == ' ')
2105 /* If wrong number of spaces, fix it. */
2108 char *tmp
= (char*) alloca(opend
-opname
+10);
2109 sprintf(tmp
, "operator%.*s%s", fix
, " ", opname
);
2114 if (0 != (val
= re_comp (regexp
)))
2115 error ("Invalid regexp (%s): %s", val
, regexp
);
2118 /* Search through the partial symtabs *first* for all symbols
2119 matching the regexp. That way we don't have to reproduce all of
2120 the machinery below. */
2122 ALL_PSYMTABS (objfile
, ps
)
2124 struct partial_symbol
*bound
, *gbound
, *sbound
;
2127 if (ps
->readin
) continue;
2129 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2130 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2133 /* Go through all of the symbols stored in a partial
2134 symtab in one loop. */
2135 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2140 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2142 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2153 /* If it would match (logic taken from loop below)
2154 load the file and go on to the next one */
2155 if ((regexp
== 0 || NAME_MATCH (SYMBOL_NAME (psym
)))
2156 && ((class == 0 && SYMBOL_CLASS (psym
) != LOC_TYPEDEF
2157 && SYMBOL_CLASS (psym
) != LOC_BLOCK
)
2158 || (class == 1 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)
2159 || (class == 2 && SYMBOL_CLASS (psym
) == LOC_TYPEDEF
)
2160 || (class == 3 && SYMBOL_CLASS (psym
) == LOC_BLOCK
)))
2162 PSYMTAB_TO_SYMTAB(ps
);
2170 /* Here, we search through the minimal symbol tables for functions that
2171 match, and call find_pc_symtab on them to force their symbols to
2172 be read. The symbol will then be found during the scan of symtabs
2173 below. If find_pc_symtab fails, set found_misc so that we will
2174 rescan to print any matching symbols without debug info. */
2178 ALL_MSYMBOLS (objfile
, msymbol
)
2180 if (msymbol
-> type
== ourtype
|| msymbol
-> type
== ourtype2
)
2182 if (regexp
== 0 || NAME_MATCH (msymbol
-> name
))
2184 if (0 == find_pc_symtab (msymbol
-> address
))
2193 /* Printout here so as to get after the "Reading in symbols"
2194 messages which will be generated above. */
2196 printf_filtered (regexp
2197 ? "All %ss matching regular expression \"%s\":\n"
2198 : "All defined %ss:\n",
2202 ALL_SYMTABS (objfile
, s
)
2205 bv
= BLOCKVECTOR (s
);
2206 /* Often many files share a blockvector.
2207 Scan each blockvector only once so that
2208 we don't get every symbol many times.
2209 It happens that the first symtab in the list
2210 for any given blockvector is the main file. */
2212 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
2214 b
= BLOCKVECTOR_BLOCK (bv
, i
);
2215 /* Skip the sort if this block is always sorted. */
2216 if (!BLOCK_SHOULD_SORT (b
))
2217 sort_block_syms (b
);
2218 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
2221 sym
= BLOCK_SYM (b
, j
);
2222 if ((regexp
== 0 || NAME_MATCH (SYMBOL_NAME (sym
)))
2223 && ((class == 0 && SYMBOL_CLASS (sym
) != LOC_TYPEDEF
2224 && SYMBOL_CLASS (sym
) != LOC_BLOCK
)
2225 || (class == 1 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2226 || (class == 2 && SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2227 || (class == 3 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)))
2231 /* Set a breakpoint here, if it's a function */
2233 break_command (SYMBOL_NAME(sym
), 0);
2235 else if (!found_in_file
)
2237 fputs_filtered ("\nFile ", stdout
);
2238 fputs_filtered (s
->filename
, stdout
);
2239 fputs_filtered (":\n", stdout
);
2243 if (class != 2 && i
== STATIC_BLOCK
)
2244 printf_filtered ("static ");
2246 /* Typedef that is not a C++ class */
2248 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
2249 typedef_print (SYMBOL_TYPE(sym
), sym
, stdout
);
2250 /* variable, func, or typedef-that-is-c++-class */
2251 else if (class < 2 ||
2253 SYMBOL_NAMESPACE(sym
) == STRUCT_NAMESPACE
))
2255 type_print (SYMBOL_TYPE (sym
),
2256 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2257 ? "" : SYMBOL_NAME (sym
)),
2260 printf_filtered (";\n");
2265 /* FIXME, why is this zapped out? */
2267 type_print_base (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0, 0);
2268 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t
, i
), stdout
, 0);
2269 sprintf (buf
, " %s::", type_name_no_tag (t
));
2270 type_print_method_args (TYPE_FN_FIELD_ARGS (t
, i
), buf
, name
, stdout
);
2279 /* If there are no eyes, avoid all contact. I mean, if there are
2280 no debug symbols, then print directly from the msymbol_vector. */
2282 if (found_misc
|| class != 1)
2285 ALL_MSYMBOLS (objfile
, msymbol
)
2287 if (msymbol
-> type
== ourtype
|| msymbol
-> type
== ourtype2
)
2289 if (regexp
== 0 || NAME_MATCH (msymbol
-> name
))
2291 /* Functions: Look up by address. */
2293 (0 == find_pc_symtab (msymbol
-> address
)))
2295 /* Variables/Absolutes: Look up by name */
2296 if (lookup_symbol (msymbol
-> name
,
2297 (struct block
*) 0, VAR_NAMESPACE
, 0,
2298 (struct symtab
**) 0) == NULL
)
2302 printf_filtered ("\nNon-debugging symbols:\n");
2305 printf_filtered (" %08x %s\n",
2317 variables_info (regexp
, from_tty
)
2321 list_symbols (regexp
, 0, 0);
2325 functions_info (regexp
, from_tty
)
2329 list_symbols (regexp
, 1, 0);
2333 types_info (regexp
, from_tty
)
2337 list_symbols (regexp
, 2, 0);
2341 /* Tiemann says: "info methods was never implemented." */
2343 methods_info (regexp
)
2346 list_symbols (regexp
, 3, 0);
2350 /* Breakpoint all functions matching regular expression. */
2352 rbreak_command (regexp
, from_tty
)
2356 list_symbols (regexp
, 1, 1);
2360 /* Return Nonzero if block a is lexically nested within block b,
2361 or if a and b have the same pc range.
2362 Return zero otherwise. */
2365 struct block
*a
, *b
;
2369 return BLOCK_START (a
) >= BLOCK_START (b
)
2370 && BLOCK_END (a
) <= BLOCK_END (b
);
2374 /* Helper routine for make_symbol_completion_list. */
2376 static int return_val_size
;
2377 static int return_val_index
;
2378 static char **return_val
;
2380 /* Test to see if the symbol specified by SYMNAME (or it's demangled
2381 equivalent) matches TEXT in the first TEXT_LEN characters. If so,
2382 add it to the current completion list. */
2385 completion_list_add_symbol (symname
, text
, text_len
)
2393 /* First see if SYMNAME is a C++ mangled name, and if so, use the
2394 demangled name instead, including any parameters. */
2396 if ((demangled
= cplus_demangle (symname
, DMGL_PARAMS
| DMGL_ANSI
)) != NULL
)
2398 symname
= demangled
;
2401 /* If we have a match for a completion, then add SYMNAME to the current
2402 list of matches. Note that we always make a copy of the string, even
2403 if it is one that was returned from cplus_demangle and is already
2404 in malloc'd memory. */
2406 if (strncmp (symname
, text
, text_len
) == 0)
2408 if (return_val_index
+ 3 > return_val_size
)
2410 newsize
= (return_val_size
*= 2) * sizeof (char *);
2411 return_val
= (char **) xrealloc ((char *) return_val
, newsize
);
2413 return_val
[return_val_index
++] = savestring (symname
, strlen (symname
));
2414 return_val
[return_val_index
] = NULL
;
2417 if (demangled
!= NULL
)
2423 /* Return a NULL terminated array of all symbols (regardless of class) which
2424 begin by matching TEXT. If the answer is no symbols, then the return value
2425 is an array which contains only a NULL pointer.
2427 Problem: All of the symbols have to be copied because readline frees them.
2428 I'm not going to worry about this; hopefully there won't be that many. */
2431 make_symbol_completion_list (text
)
2434 register struct symbol
*sym
;
2435 register struct symtab
*s
;
2436 register struct partial_symtab
*ps
;
2437 register struct minimal_symbol
*msymbol
;
2438 register struct objfile
*objfile
;
2439 register struct block
*b
, *surrounding_static_block
= 0;
2442 struct partial_symbol
*psym
;
2444 text_len
= strlen (text
);
2445 return_val_size
= 100;
2446 return_val_index
= 0;
2447 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
2448 return_val
[0] = NULL
;
2450 /* Look through the partial symtabs for all symbols which begin
2451 by matching TEXT. Add each one that you find to the list. */
2453 ALL_PSYMTABS (objfile
, ps
)
2455 /* If the psymtab's been read in we'll get it when we search
2456 through the blockvector. */
2457 if (ps
->readin
) continue;
2459 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2460 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
2461 + ps
->n_global_syms
);
2464 /* If interrupted, then quit. */
2466 completion_list_add_symbol (SYMBOL_NAME (psym
), text
, text_len
);
2469 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2470 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
2471 + ps
->n_static_syms
);
2475 completion_list_add_symbol (SYMBOL_NAME (psym
), text
, text_len
);
2479 /* At this point scan through the misc symbol vectors and add each
2480 symbol you find to the list. Eventually we want to ignore
2481 anything that isn't a text symbol (everything else will be
2482 handled by the psymtab code above). */
2484 ALL_MSYMBOLS (objfile
, msymbol
)
2487 completion_list_add_symbol (msymbol
-> name
, text
, text_len
);
2490 /* Search upwards from currently selected frame (so that we can
2491 complete on local vars. */
2493 for (b
= get_selected_block (); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
2495 if (!BLOCK_SUPERBLOCK (b
))
2497 surrounding_static_block
= b
; /* For elmin of dups */
2500 /* Also catch fields of types defined in this places which match our
2501 text string. Only complete on types visible from current context. */
2503 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2505 sym
= BLOCK_SYM (b
, i
);
2506 completion_list_add_symbol (SYMBOL_NAME (sym
), text
, text_len
);
2507 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2509 struct type
*t
= SYMBOL_TYPE (sym
);
2510 enum type_code c
= TYPE_CODE (t
);
2512 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
2514 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
2516 if (TYPE_FIELD_NAME (t
, j
))
2518 completion_list_add_symbol (TYPE_FIELD_NAME (t
, j
),
2527 /* Go through the symtabs and check the externs and statics for
2528 symbols which match. */
2530 ALL_SYMTABS (objfile
, s
)
2533 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
2534 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2536 sym
= BLOCK_SYM (b
, i
);
2537 completion_list_add_symbol (SYMBOL_NAME (sym
), text
, text_len
);
2541 ALL_SYMTABS (objfile
, s
)
2544 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
2545 /* Don't do this block twice. */
2546 if (b
== surrounding_static_block
) continue;
2547 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2549 sym
= BLOCK_SYM (b
, i
);
2550 completion_list_add_symbol (SYMBOL_NAME (sym
), text
, text_len
);
2554 return (return_val
);
2558 /* Find a mangled symbol that corresponds to LOOKFOR using brute force.
2559 Basically we go munging through available symbols, demangling each one,
2560 looking for a match on the demangled result. */
2563 expensive_mangler (lookfor
)
2564 const char *lookfor
;
2566 register struct symbol
*sym
;
2567 register struct symtab
*s
;
2568 register struct partial_symtab
*ps
;
2569 register struct minimal_symbol
*msymbol
;
2570 register struct objfile
*objfile
;
2571 register struct block
*b
, *surrounding_static_block
= 0;
2573 struct partial_symbol
*psym
;
2576 /* Look through the partial symtabs for a symbol that matches */
2578 ALL_PSYMTABS (objfile
, ps
)
2580 /* If the psymtab's been read in we'll get it when we search
2581 through the blockvector. */
2582 if (ps
->readin
) continue;
2584 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2585 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
2586 + ps
->n_global_syms
);
2589 QUIT
; /* If interrupted, then quit. */
2590 demangled
= demangle_and_match (SYMBOL_NAME (psym
), lookfor
,
2591 DMGL_PARAMS
| DMGL_ANSI
);
2592 if (demangled
!= NULL
)
2595 return (SYMBOL_NAME (psym
));
2599 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2600 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
2601 + ps
->n_static_syms
);
2605 demangled
= demangle_and_match (SYMBOL_NAME (psym
), lookfor
,
2606 DMGL_PARAMS
| DMGL_ANSI
);
2607 if (demangled
!= NULL
)
2610 return (SYMBOL_NAME (psym
));
2615 /* Scan through the misc symbol vectors looking for a match. */
2617 ALL_MSYMBOLS (objfile
, msymbol
)
2620 demangled
= demangle_and_match (msymbol
-> name
, lookfor
,
2621 DMGL_PARAMS
| DMGL_ANSI
);
2622 if (demangled
!= NULL
)
2625 return (msymbol
-> name
);
2629 /* Search upwards from currently selected frame looking for a match */
2631 for (b
= get_selected_block (); b
; b
= BLOCK_SUPERBLOCK (b
))
2633 if (!BLOCK_SUPERBLOCK (b
))
2634 surrounding_static_block
= b
; /* For elmin of dups */
2636 /* Also catch fields of types defined in this places which
2637 match our text string. Only complete on types visible
2638 from current context. */
2639 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2641 sym
= BLOCK_SYM (b
, i
);
2642 demangled
= demangle_and_match (SYMBOL_NAME (sym
), lookfor
,
2643 DMGL_PARAMS
| DMGL_ANSI
);
2644 if (demangled
!= NULL
)
2647 return (SYMBOL_NAME (sym
));
2649 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2651 struct type
*t
= SYMBOL_TYPE (sym
);
2652 enum type_code c
= TYPE_CODE (t
);
2654 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
2656 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
2658 if (TYPE_FIELD_NAME (t
, j
))
2661 demangle_and_match (TYPE_FIELD_NAME (t
, j
),
2663 DMGL_PARAMS
| DMGL_ANSI
);
2664 if (demangled
!= NULL
)
2667 return (TYPE_FIELD_NAME (t
, j
));
2676 /* Go through the symtabs and check the externs and statics for
2677 symbols which match. */
2679 ALL_SYMTABS (objfile
, s
)
2682 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
2683 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2685 sym
= BLOCK_SYM (b
, i
);
2686 demangled
= demangle_and_match (SYMBOL_NAME (sym
), lookfor
,
2687 DMGL_PARAMS
| DMGL_ANSI
);
2688 if (demangled
!= NULL
)
2691 return (SYMBOL_NAME (sym
));
2696 ALL_SYMTABS (objfile
, s
)
2699 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
2700 /* Don't do this block twice. */
2701 if (b
== surrounding_static_block
) continue;
2702 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
2704 sym
= BLOCK_SYM (b
, i
);
2705 demangled
= demangle_and_match (SYMBOL_NAME (sym
), lookfor
,
2706 DMGL_PARAMS
| DMGL_ANSI
);
2707 if (demangled
!= NULL
)
2710 return (SYMBOL_NAME (sym
));
2720 /* Add the type of the symbol sym to the type of the current
2721 function whose block we are in (assumed). The type of
2722 this current function is contained in *TYPE.
2724 This basically works as follows: When we find a function
2725 symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record
2726 a pointer to its type in the global in_function_type. Every
2727 time we come across a parameter symbol ('p' in its name), then
2728 this procedure adds the name and type of that parameter
2729 to the function type pointed to by *TYPE. (Which should correspond
2730 to in_function_type if it was called correctly).
2732 Note that since we are modifying a type, the result of
2733 lookup_function_type() should be memcpy()ed before calling
2734 this. When not in strict typing mode, the expression
2735 evaluator can choose to ignore this.
2737 Assumption: All of a function's parameter symbols will
2738 appear before another function symbol is found. The parameters
2739 appear in the same order in the argument list as they do in the
2743 add_param_to_type (type
,sym
)
2747 int num
= ++(TYPE_NFIELDS(*type
));
2749 if(TYPE_NFIELDS(*type
)-1)
2750 TYPE_FIELDS(*type
) = (struct field
*)
2751 (*current_objfile
->xrealloc
) ((char *)(TYPE_FIELDS(*type
)),
2752 num
*sizeof(struct field
));
2754 TYPE_FIELDS(*type
) = (struct field
*)
2755 (*current_objfile
->xmalloc
) (num
*sizeof(struct field
));
2757 TYPE_FIELD_BITPOS(*type
,num
-1) = num
-1;
2758 TYPE_FIELD_BITSIZE(*type
,num
-1) = 0;
2759 TYPE_FIELD_TYPE(*type
,num
-1) = SYMBOL_TYPE(sym
);
2760 TYPE_FIELD_NAME(*type
,num
-1) = SYMBOL_NAME(sym
);
2765 _initialize_symtab ()
2767 add_info ("variables", variables_info
,
2768 "All global and static variable names, or those matching REGEXP.");
2769 add_info ("functions", functions_info
,
2770 "All function names, or those matching REGEXP.");
2772 /* FIXME: This command has at least the following problems:
2773 1. It prints builtin types (in a very strange and confusing fashion).
2774 2. It doesn't print right, e.g. with
2775 typedef struct foo *FOO
2776 type_print prints "FOO" when we want to make it (in this situation)
2777 print "struct foo *".
2778 I also think "ptype" or "whatis" is more likely to be useful (but if
2779 there is much disagreement "info types" can be fixed). */
2780 add_info ("types", types_info
,
2781 "All type names, or those matching REGEXP.");
2784 add_info ("methods", methods_info
,
2785 "All method names, or those matching REGEXP::REGEXP.\n\
2786 If the class qualifier is omitted, it is assumed to be the current scope.\n\
2787 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
2790 add_info ("sources", sources_info
,
2791 "Source files in the program.");
2793 add_com ("rbreak", no_class
, rbreak_command
,
2794 "Set a breakpoint for all functions matching REGEXP.");
2796 /* Initialize the one built-in type that isn't language dependent... */
2797 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
2798 "<unknown type>", (struct objfile
*) NULL
);