1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 1997
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 #include "call-cmds.h"
32 #include "gnu-regex.h"
33 #include "expression.h"
40 #include <sys/types.h>
42 #include "gdb_string.h"
46 /* Prototypes for local functions */
49 find_methods
PARAMS ((struct type
*, char *, struct symbol
**));
52 completion_list_add_name
PARAMS ((char *, char *, int, char *, char *));
55 build_canonical_line_spec
PARAMS ((struct symtab_and_line
*, char *, char ***));
57 static struct symtabs_and_lines
58 decode_line_2
PARAMS ((struct symbol
*[], int, int, char ***));
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 output_source_filename
PARAMS ((char *, int *));
79 operator_chars
PARAMS ((char *, char **));
81 static int find_line_common
PARAMS ((struct linetable
*, int, int *));
83 static struct partial_symbol
*
84 lookup_partial_symbol
PARAMS ((struct partial_symtab
*, const char *,
85 int, namespace_enum
));
87 static struct partial_symbol
*
88 fixup_psymbol_section
PARAMS ((struct partial_symbol
*, struct objfile
*));
90 static struct symtab
*
91 lookup_symtab_1
PARAMS ((char *));
94 cplusplus_hint
PARAMS ((char *));
96 static struct symbol
*
97 find_active_alias
PARAMS ((struct symbol
*sym
, CORE_ADDR addr
));
101 /* The single non-language-specific builtin type */
102 struct type
*builtin_type_error
;
104 /* Block in which the most recently searched-for symbol was found.
105 Might be better to make this a parameter to lookup_symbol and
108 const struct block
*block_found
;
110 char no_symtab_msg
[] = "No symbol table is loaded. Use the \"file\" command.";
112 /* While the C++ support is still in flux, issue a possibly helpful hint on
113 using the new command completion feature on single quoted demangled C++
114 symbols. Remove when loose ends are cleaned up. FIXME -fnf */
117 cplusplus_hint (name
)
120 while (*name
== '\'')
122 printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name
, name
);
123 printf_filtered ("(Note leading single quote.)\n");
126 /* Check for a symtab of a specific name; first in symtabs, then in
127 psymtabs. *If* there is no '/' in the name, a match after a '/'
128 in the symtab filename will also work. */
130 static struct symtab
*
131 lookup_symtab_1 (name
)
134 register struct symtab
*s
;
135 register struct partial_symtab
*ps
;
136 register char *slash
;
137 register struct objfile
*objfile
;
141 /* First, search for an exact match */
143 ALL_SYMTABS (objfile
, s
)
144 if (STREQ (name
, s
->filename
))
147 slash
= strchr (name
, '/');
149 /* Now, search for a matching tail (only if name doesn't have any dirs) */
152 ALL_SYMTABS (objfile
, s
)
154 char *p
= s
-> filename
;
155 char *tail
= strrchr (p
, '/');
164 /* Same search rules as above apply here, but now we look thru the
167 ps
= lookup_partial_symtab (name
);
172 error ("Internal: readin %s pst for `%s' found when no symtab found.",
173 ps
-> filename
, name
);
175 s
= PSYMTAB_TO_SYMTAB (ps
);
180 /* At this point, we have located the psymtab for this file, but
181 the conversion to a symtab has failed. This usually happens
182 when we are looking up an include file. In this case,
183 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
184 been created. So, we need to run through the symtabs again in
185 order to find the file.
186 XXX - This is a crock, and should be fixed inside of the the
187 symbol parsing routines. */
191 /* Lookup the symbol table of a source file named NAME. Try a couple
192 of variations if the first lookup doesn't work. */
198 register struct symtab
*s
;
203 s
= lookup_symtab_1 (name
);
207 /* This screws c-exp.y:yylex if there is both a type "tree" and a symtab
210 /* If name not found as specified, see if adding ".c" helps. */
211 /* Why is this? Is it just a user convenience? (If so, it's pretty
212 questionable in the presence of C++, FORTRAN, etc.). It's not in
215 copy
= (char *) alloca (strlen (name
) + 3);
218 s
= lookup_symtab_1 (copy
);
222 /* We didn't find anything; die. */
226 /* Lookup the partial symbol table of a source file named NAME.
227 *If* there is no '/' in the name, a match after a '/'
228 in the psymtab filename will also work. */
230 struct partial_symtab
*
231 lookup_partial_symtab (name
)
234 register struct partial_symtab
*pst
;
235 register struct objfile
*objfile
;
237 ALL_PSYMTABS (objfile
, pst
)
239 if (STREQ (name
, pst
-> filename
))
245 /* Now, search for a matching tail (only if name doesn't have any dirs) */
247 if (!strchr (name
, '/'))
248 ALL_PSYMTABS (objfile
, pst
)
250 char *p
= pst
-> filename
;
251 char *tail
= strrchr (p
, '/');
263 /* Mangle a GDB method stub type. This actually reassembles the pieces of the
264 full method name, which consist of the class name (from T), the unadorned
265 method name from METHOD_ID, and the signature for the specific overload,
266 specified by SIGNATURE_ID. Note that this function is g++ specific. */
269 gdb_mangle_name (type
, method_id
, signature_id
)
271 int method_id
, signature_id
;
273 int mangled_name_len
;
275 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
276 struct fn_field
*method
= &f
[signature_id
];
277 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, method_id
);
278 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, signature_id
);
279 char *newname
= type_name_no_tag (type
);
281 /* Does the form of physname indicate that it is the full mangled name
282 of a constructor (not just the args)? */
283 int is_full_physname_constructor
;
286 int is_destructor
= DESTRUCTOR_PREFIX_P (physname
);
287 /* Need a new type prefix. */
288 char *const_prefix
= method
->is_const
? "C" : "";
289 char *volatile_prefix
= method
->is_volatile
? "V" : "";
291 int len
= (newname
== NULL
? 0 : strlen (newname
));
293 is_full_physname_constructor
=
294 ((physname
[0]=='_' && physname
[1]=='_' &&
295 (isdigit(physname
[2]) || physname
[2]=='Q' || physname
[2]=='t'))
296 || (strncmp(physname
, "__ct", 4) == 0));
299 is_full_physname_constructor
|| (newname
&& STREQ(field_name
, newname
));
302 is_destructor
= (strncmp(physname
, "__dt", 4) == 0);
304 if (is_destructor
|| is_full_physname_constructor
)
306 mangled_name
= (char*) xmalloc(strlen(physname
)+1);
307 strcpy(mangled_name
, physname
);
313 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
315 else if (physname
[0] == 't' || physname
[0] == 'Q')
317 /* The physname for template and qualified methods already includes
319 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
325 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
327 mangled_name_len
= ((is_constructor
? 0 : strlen (field_name
))
332 /* Only needed for GNU-mangled names. ANSI-mangled names
333 work with the normal mechanisms. */
334 if (OPNAME_PREFIX_P (field_name
))
336 const char *opname
= cplus_mangle_opname (field_name
+ 3, 0);
338 error ("No mangling for \"%s\"", field_name
);
339 mangled_name_len
+= strlen (opname
);
340 mangled_name
= (char *)xmalloc (mangled_name_len
);
342 strncpy (mangled_name
, field_name
, 3);
343 mangled_name
[3] = '\0';
344 strcat (mangled_name
, opname
);
348 mangled_name
= (char *)xmalloc (mangled_name_len
);
350 mangled_name
[0] = '\0';
352 strcpy (mangled_name
, field_name
);
354 strcat (mangled_name
, buf
);
355 /* If the class doesn't have a name, i.e. newname NULL, then we just
356 mangle it using 0 for the length of the class. Thus it gets mangled
357 as something starting with `::' rather than `classname::'. */
359 strcat (mangled_name
, newname
);
361 strcat (mangled_name
, physname
);
362 return (mangled_name
);
367 /* Find which partial symtab on contains PC and SECTION. Return 0 if none. */
369 struct partial_symtab
*
370 find_pc_sect_psymtab (pc
, section
)
374 register struct partial_symtab
*pst
;
375 register struct objfile
*objfile
;
377 ALL_PSYMTABS (objfile
, pst
)
379 if (pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
381 struct minimal_symbol
*msymbol
;
382 struct partial_symtab
*tpst
;
384 /* An objfile that has its functions reordered might have
385 many partial symbol tables containing the PC, but
386 we want the partial symbol table that contains the
387 function containing the PC. */
388 if (!(objfile
->flags
& OBJF_REORDERED
) &&
389 section
== 0) /* can't validate section this way */
392 msymbol
= lookup_minimal_symbol_by_pc_section (pc
, section
);
396 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
398 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
400 struct partial_symbol
*p
;
402 p
= find_pc_sect_psymbol (tpst
, pc
, section
);
404 && SYMBOL_VALUE_ADDRESS(p
)
405 == SYMBOL_VALUE_ADDRESS (msymbol
))
415 /* Find which partial symtab contains PC. Return 0 if none.
416 Backward compatibility, no section */
418 struct partial_symtab
*
422 return find_pc_sect_psymtab (pc
, find_pc_mapped_section (pc
));
425 /* Find which partial symbol within a psymtab matches PC and SECTION.
426 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
428 struct partial_symbol
*
429 find_pc_sect_psymbol (psymtab
, pc
, section
)
430 struct partial_symtab
*psymtab
;
434 struct partial_symbol
*best
= NULL
, *p
, **pp
;
438 psymtab
= find_pc_sect_psymtab (pc
, section
);
442 /* Cope with programs that start at address 0 */
443 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
445 /* Search the global symbols as well as the static symbols, so that
446 find_pc_partial_function doesn't use a minimal symbol and thus
447 cache a bad endaddr. */
448 for (pp
= psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
449 (pp
- (psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
450 < psymtab
->n_global_syms
);
454 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
455 && SYMBOL_CLASS (p
) == LOC_BLOCK
456 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
457 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
458 || (psymtab
->textlow
== 0
459 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
461 if (section
) /* match on a specific section */
463 fixup_psymbol_section (p
, psymtab
->objfile
);
464 if (SYMBOL_BFD_SECTION (p
) != section
)
467 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
472 for (pp
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
473 (pp
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
474 < psymtab
->n_static_syms
);
478 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
479 && SYMBOL_CLASS (p
) == LOC_BLOCK
480 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
481 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
482 || (psymtab
->textlow
== 0
483 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
485 if (section
) /* match on a specific section */
487 fixup_psymbol_section (p
, psymtab
->objfile
);
488 if (SYMBOL_BFD_SECTION (p
) != section
)
491 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
499 /* Find which partial symbol within a psymtab matches PC. Return 0 if none.
500 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
502 struct partial_symbol
*
503 find_pc_psymbol (psymtab
, pc
)
504 struct partial_symtab
*psymtab
;
507 return find_pc_sect_psymbol (psymtab
, pc
, find_pc_mapped_section (pc
));
510 /* Debug symbols usually don't have section information. We need to dig that
511 out of the minimal symbols and stash that in the debug symbol. */
514 fixup_section (ginfo
, objfile
)
515 struct general_symbol_info
*ginfo
;
516 struct objfile
*objfile
;
518 struct minimal_symbol
*msym
;
519 msym
= lookup_minimal_symbol (ginfo
->name
, NULL
, objfile
);
522 ginfo
->bfd_section
= SYMBOL_BFD_SECTION (msym
);
526 fixup_symbol_section (sym
, objfile
)
528 struct objfile
*objfile
;
533 if (SYMBOL_BFD_SECTION (sym
))
536 fixup_section (&sym
->ginfo
, objfile
);
541 static struct partial_symbol
*
542 fixup_psymbol_section (psym
, objfile
)
543 struct partial_symbol
*psym
;
544 struct objfile
*objfile
;
549 if (SYMBOL_BFD_SECTION (psym
))
552 fixup_section (&psym
->ginfo
, objfile
);
557 /* Find the definition for a specified symbol name NAME
558 in namespace NAMESPACE, visible from lexical block BLOCK.
559 Returns the struct symbol pointer, or zero if no symbol is found.
560 If SYMTAB is non-NULL, store the symbol table in which the
561 symbol was found there, or NULL if not found.
562 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
563 NAME is a field of the current implied argument `this'. If so set
564 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
565 BLOCK_FOUND is set to the block in which NAME is found (in the case of
566 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
568 /* This function has a bunch of loops in it and it would seem to be
569 attractive to put in some QUIT's (though I'm not really sure
570 whether it can run long enough to be really important). But there
571 are a few calls for which it would appear to be bad news to quit
572 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and
573 nindy_frame_chain_valid in nindy-tdep.c. (Note that there is C++
574 code below which can error(), but that probably doesn't affect
575 these calls since they are looking for a known variable and thus
576 can probably assume it will never hit the C++ code). */
579 lookup_symbol (name
, block
, namespace, is_a_field_of_this
, symtab
)
581 register const struct block
*block
;
582 const namespace_enum
namespace;
583 int *is_a_field_of_this
;
584 struct symtab
**symtab
;
586 register struct symbol
*sym
;
587 register struct symtab
*s
= NULL
;
588 register struct partial_symtab
*ps
;
589 struct blockvector
*bv
;
590 register struct objfile
*objfile
= NULL
;
591 register struct block
*b
;
592 register struct minimal_symbol
*msymbol
;
594 /* Search specified block and its superiors. */
598 sym
= lookup_block_symbol (block
, name
, namespace);
604 /* Search the list of symtabs for one which contains the
605 address of the start of this block. */
606 ALL_SYMTABS (objfile
, s
)
608 bv
= BLOCKVECTOR (s
);
609 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
610 if (BLOCK_START (b
) <= BLOCK_START (block
)
611 && BLOCK_END (b
) > BLOCK_START (block
))
618 return fixup_symbol_section (sym
, objfile
);
620 block
= BLOCK_SUPERBLOCK (block
);
623 /* FIXME: this code is never executed--block is always NULL at this
624 point. What is it trying to do, anyway? We already should have
625 checked the STATIC_BLOCK above (it is the superblock of top-level
626 blocks). Why is VAR_NAMESPACE special-cased? */
627 /* Don't need to mess with the psymtabs; if we have a block,
628 that file is read in. If we don't, then we deal later with
629 all the psymtab stuff that needs checking. */
630 if (namespace == VAR_NAMESPACE
&& block
!= NULL
)
633 /* Find the right symtab. */
634 ALL_SYMTABS (objfile
, s
)
636 bv
= BLOCKVECTOR (s
);
637 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
638 if (BLOCK_START (b
) <= BLOCK_START (block
)
639 && BLOCK_END (b
) > BLOCK_START (block
))
641 sym
= lookup_block_symbol (b
, name
, VAR_NAMESPACE
);
647 return fixup_symbol_section (sym
, objfile
);
654 /* C++: If requested to do so by the caller,
655 check to see if NAME is a field of `this'. */
656 if (is_a_field_of_this
)
658 struct value
*v
= value_of_this (0);
660 *is_a_field_of_this
= 0;
661 if (v
&& check_field (v
, name
))
663 *is_a_field_of_this
= 1;
670 /* Now search all global blocks. Do the symtab's first, then
671 check the psymtab's */
673 ALL_SYMTABS (objfile
, s
)
675 bv
= BLOCKVECTOR (s
);
676 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
677 sym
= lookup_block_symbol (block
, name
, namespace);
683 return fixup_symbol_section (sym
, objfile
);
687 /* Check for the possibility of the symbol being a function or
688 a mangled variable that is stored in one of the minimal symbol tables.
689 Eventually, all global symbols might be resolved in this way. */
691 if (namespace == VAR_NAMESPACE
)
693 msymbol
= lookup_minimal_symbol (name
, NULL
, NULL
);
696 s
= find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol
),
697 SYMBOL_BFD_SECTION (msymbol
));
700 /* This is a function which has a symtab for its address. */
701 bv
= BLOCKVECTOR (s
);
702 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
703 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
705 /* We kept static functions in minimal symbol table as well as
706 in static scope. We want to find them in the symbol table. */
708 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
709 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
713 /* sym == 0 if symbol was found in the minimal symbol table
714 but not in the symtab.
715 Return 0 to use the msymbol definition of "foo_".
717 This happens for Fortran "foo_" symbols,
718 which are "foo" in the symtab.
720 This can also happen if "asm" is used to make a
721 regular symbol but not a debugging symbol, e.g.
728 return fixup_symbol_section (sym
, objfile
);
730 else if (MSYMBOL_TYPE (msymbol
) != mst_text
731 && MSYMBOL_TYPE (msymbol
) != mst_file_text
732 && !STREQ (name
, SYMBOL_NAME (msymbol
)))
734 /* This is a mangled variable, look it up by its
736 return lookup_symbol (SYMBOL_NAME (msymbol
), block
,
737 namespace, is_a_field_of_this
, symtab
);
739 /* There are no debug symbols for this file, or we are looking
740 for an unmangled variable.
741 Try to find a matching static symbol below. */
745 ALL_PSYMTABS (objfile
, ps
)
747 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
749 s
= PSYMTAB_TO_SYMTAB(ps
);
750 bv
= BLOCKVECTOR (s
);
751 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
752 sym
= lookup_block_symbol (block
, name
, namespace);
754 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab", name
, ps
->filename
);
757 return fixup_symbol_section (sym
, objfile
);
761 /* Now search all per-file blocks.
762 Not strictly correct, but more useful than an error.
763 Do the symtabs first, then check the psymtabs */
765 ALL_SYMTABS (objfile
, s
)
767 bv
= BLOCKVECTOR (s
);
768 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
769 sym
= lookup_block_symbol (block
, name
, namespace);
775 return fixup_symbol_section (sym
, objfile
);
779 ALL_PSYMTABS (objfile
, ps
)
781 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
783 s
= PSYMTAB_TO_SYMTAB(ps
);
784 bv
= BLOCKVECTOR (s
);
785 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
786 sym
= lookup_block_symbol (block
, name
, namespace);
788 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab", name
, ps
->filename
);
791 return fixup_symbol_section (sym
, objfile
);
800 /* Look, in partial_symtab PST, for symbol NAME. Check the global
801 symbols if GLOBAL, the static symbols if not */
803 static struct partial_symbol
*
804 lookup_partial_symbol (pst
, name
, global
, namespace)
805 struct partial_symtab
*pst
;
808 namespace_enum
namespace;
810 struct partial_symbol
**start
, **psym
;
811 struct partial_symbol
**top
, **bottom
, **center
;
812 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
813 int do_linear_search
= 1;
821 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
822 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
824 if (global
) /* This means we can use a binary search. */
826 do_linear_search
= 0;
828 /* Binary search. This search is guaranteed to end with center
829 pointing at the earliest partial symbol with the correct
830 name. At that point *all* partial symbols with that name
831 will be checked against the correct namespace. */
834 top
= start
+ length
- 1;
837 center
= bottom
+ (top
- bottom
) / 2;
840 if (!do_linear_search
841 && (SYMBOL_LANGUAGE (*center
) == language_cplus
842 /* start-sanitize-java */
843 || SYMBOL_LANGUAGE (*center
) == language_java
844 /* end-sanitize-java */
847 do_linear_search
= 1;
849 if (STRCMP (SYMBOL_NAME (*center
), name
) >= 0)
858 if (!(top
== bottom
))
860 while (STREQ (SYMBOL_NAME (*top
), name
))
862 if (SYMBOL_NAMESPACE (*top
) == namespace)
870 /* Can't use a binary search or else we found during the binary search that
871 we should also do a linear search. */
873 if (do_linear_search
)
875 for (psym
= start
; psym
< start
+ length
; psym
++)
877 if (namespace == SYMBOL_NAMESPACE (*psym
))
879 if (SYMBOL_MATCHES_NAME (*psym
, name
))
890 /* Find the psymtab containing main(). */
891 /* FIXME: What about languages without main() or specially linked
892 executables that have no main() ? */
894 struct partial_symtab
*
897 register struct partial_symtab
*pst
;
898 register struct objfile
*objfile
;
900 ALL_PSYMTABS (objfile
, pst
)
902 if (lookup_partial_symbol (pst
, "main", 1, VAR_NAMESPACE
))
910 /* Search BLOCK for symbol NAME in NAMESPACE.
912 Note that if NAME is the demangled form of a C++ symbol, we will fail
913 to find a match during the binary search of the non-encoded names, but
914 for now we don't worry about the slight inefficiency of looking for
915 a match we'll never find, since it will go pretty quick. Once the
916 binary search terminates, we drop through and do a straight linear
917 search on the symbols. Each symbol which is marked as being a C++
918 symbol (language_cplus set) has both the encoded and non-encoded names
919 tested for a match. */
922 lookup_block_symbol (block
, name
, namespace)
923 register const struct block
*block
;
925 const namespace_enum
namespace;
927 register int bot
, top
, inc
;
928 register struct symbol
*sym
;
929 register struct symbol
*sym_found
= NULL
;
930 register int do_linear_search
= 1;
932 /* If the blocks's symbols were sorted, start with a binary search. */
934 if (BLOCK_SHOULD_SORT (block
))
936 /* Reset the linear search flag so if the binary search fails, we
937 won't do the linear search once unless we find some reason to
938 do so, such as finding a C++ symbol during the binary search.
939 Note that for C++ modules, ALL the symbols in a block should
940 end up marked as C++ symbols. */
942 do_linear_search
= 0;
943 top
= BLOCK_NSYMS (block
);
946 /* Advance BOT to not far before the first symbol whose name is NAME. */
950 inc
= (top
- bot
+ 1);
951 /* No need to keep binary searching for the last few bits worth. */
956 inc
= (inc
>> 1) + bot
;
957 sym
= BLOCK_SYM (block
, inc
);
958 if (!do_linear_search
959 && (SYMBOL_LANGUAGE (sym
) == language_cplus
960 /* start-sanitize-java */
961 || SYMBOL_LANGUAGE (sym
) == language_java
962 /* end-sanitize-java */
965 do_linear_search
= 1;
967 if (SYMBOL_NAME (sym
)[0] < name
[0])
971 else if (SYMBOL_NAME (sym
)[0] > name
[0])
975 else if (STRCMP (SYMBOL_NAME (sym
), name
) < 0)
985 /* Now scan forward until we run out of symbols, find one whose
986 name is greater than NAME, or find one we want. If there is
987 more than one symbol with the right name and namespace, we
988 return the first one; I believe it is now impossible for us
989 to encounter two symbols with the same name and namespace
990 here, because blocks containing argument symbols are no
993 top
= BLOCK_NSYMS (block
);
996 sym
= BLOCK_SYM (block
, bot
);
997 inc
= SYMBOL_NAME (sym
)[0] - name
[0];
1000 inc
= STRCMP (SYMBOL_NAME (sym
), name
);
1002 if (inc
== 0 && SYMBOL_NAMESPACE (sym
) == namespace)
1014 /* Here if block isn't sorted, or we fail to find a match during the
1015 binary search above. If during the binary search above, we find a
1016 symbol which is a C++ symbol, then we have re-enabled the linear
1017 search flag which was reset when starting the binary search.
1019 This loop is equivalent to the loop above, but hacked greatly for speed.
1021 Note that parameter symbols do not always show up last in the
1022 list; this loop makes sure to take anything else other than
1023 parameter symbols first; it only uses parameter symbols as a
1024 last resort. Note that this only takes up extra computation
1027 if (do_linear_search
)
1029 top
= BLOCK_NSYMS (block
);
1033 sym
= BLOCK_SYM (block
, bot
);
1034 if (SYMBOL_NAMESPACE (sym
) == namespace &&
1035 SYMBOL_MATCHES_NAME (sym
, name
))
1037 /* If SYM has aliases, then use any alias that is active
1038 at the current PC. If no alias is active at the current
1039 PC, then use the main symbol.
1041 ?!? Is checking the current pc correct? Is this routine
1042 ever called to look up a symbol from another context? */
1043 if (SYMBOL_ALIASES (sym
))
1044 sym
= find_active_alias (sym
, read_pc ());
1047 if (SYMBOL_CLASS (sym
) != LOC_ARG
&&
1048 SYMBOL_CLASS (sym
) != LOC_LOCAL_ARG
&&
1049 SYMBOL_CLASS (sym
) != LOC_REF_ARG
&&
1050 SYMBOL_CLASS (sym
) != LOC_REGPARM
&&
1051 SYMBOL_CLASS (sym
) != LOC_REGPARM_ADDR
&&
1052 SYMBOL_CLASS (sym
) != LOC_BASEREG_ARG
)
1060 return (sym_found
); /* Will be NULL if not found. */
1063 /* Given a main symbol SYM and ADDR, search through the alias
1064 list to determine if an alias is active at ADDR and return
1067 If no alias is active, then return SYM. */
1069 static struct symbol
*
1070 find_active_alias (sym
, addr
)
1074 struct range_list
*r
;
1075 struct alias_list
*aliases
;
1077 /* If we have aliases, check them first. */
1078 aliases
= SYMBOL_ALIASES (sym
);
1082 if (!SYMBOL_RANGES (aliases
->sym
))
1083 return aliases
->sym
;
1084 for (r
= SYMBOL_RANGES (aliases
->sym
); r
; r
= r
->next
)
1086 if (r
->start
<= addr
&& r
->end
> addr
)
1087 return aliases
->sym
;
1089 aliases
= aliases
->next
;
1092 /* Nothing found, return the main symbol. */
1097 /* Return the symbol for the function which contains a specified
1098 lexical block, described by a struct block BL. */
1104 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
1105 bl
= BLOCK_SUPERBLOCK (bl
);
1107 return BLOCK_FUNCTION (bl
);
1110 /* Find the symtab associated with PC and SECTION. Look through the
1111 psymtabs and read in another symtab if necessary. */
1114 find_pc_sect_symtab (pc
, section
)
1118 register struct block
*b
;
1119 struct blockvector
*bv
;
1120 register struct symtab
*s
= NULL
;
1121 register struct symtab
*best_s
= NULL
;
1122 register struct partial_symtab
*ps
;
1123 register struct objfile
*objfile
;
1124 CORE_ADDR distance
= 0;
1126 /* Search all symtabs for the one whose file contains our address, and which
1127 is the smallest of all the ones containing the address. This is designed
1128 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1129 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1130 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1132 This happens for native ecoff format, where code from included files
1133 gets its own symtab. The symtab for the included file should have
1134 been read in already via the dependency mechanism.
1135 It might be swifter to create several symtabs with the same name
1136 like xcoff does (I'm not sure).
1138 It also happens for objfiles that have their functions reordered.
1139 For these, the symtab we are looking for is not necessarily read in. */
1141 ALL_SYMTABS (objfile
, s
)
1143 bv
= BLOCKVECTOR (s
);
1144 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1145 if (BLOCK_START (b
) <= pc
1146 && BLOCK_END (b
) > pc
1148 || BLOCK_END (b
) - BLOCK_START (b
) < distance
))
1150 /* For an objfile that has its functions reordered,
1151 find_pc_psymtab will find the proper partial symbol table
1152 and we simply return its corresponding symtab. */
1153 /* In order to better support objfiles that contain both
1154 stabs and coff debugging info, we continue on if a psymtab
1156 if ((objfile
->flags
& OBJF_REORDERED
) && objfile
->psymtabs
)
1158 ps
= find_pc_sect_psymtab (pc
, section
);
1160 return PSYMTAB_TO_SYMTAB (ps
);
1166 for (i
= 0; i
< b
->nsyms
; i
++)
1168 fixup_symbol_section (b
->sym
[i
], objfile
);
1169 if (section
== SYMBOL_BFD_SECTION (b
->sym
[i
]))
1173 continue; /* no symbol in this symtab matches section */
1175 distance
= BLOCK_END (b
) - BLOCK_START (b
);
1184 ps
= find_pc_sect_psymtab (pc
, section
);
1188 /* Might want to error() here (in case symtab is corrupt and
1189 will cause a core dump), but maybe we can successfully
1190 continue, so let's not. */
1191 /* FIXME-32x64: assumes pc fits in a long */
1193 (Internal error: pc 0x%lx in read in psymtab, but not in symtab.)\n",
1194 (unsigned long) pc
);
1195 s
= PSYMTAB_TO_SYMTAB (ps
);
1200 /* Find the symtab associated with PC. Look through the psymtabs and
1201 read in another symtab if necessary. Backward compatibility, no section */
1207 return find_pc_sect_symtab (pc
, find_pc_mapped_section (pc
));
1213 /* Find the closest symbol value (of any sort -- function or variable)
1214 for a given address value. Slow but complete. (currently unused,
1215 mainly because it is too slow. We could fix it if each symtab and
1216 psymtab had contained in it the addresses ranges of each of its
1217 sections, which also would be required to make things like "info
1218 line *0x2345" cause psymtabs to be converted to symtabs). */
1221 find_addr_symbol (addr
, symtabp
, symaddrp
)
1223 struct symtab
**symtabp
;
1224 CORE_ADDR
*symaddrp
;
1226 struct symtab
*symtab
, *best_symtab
;
1227 struct objfile
*objfile
;
1228 register int bot
, top
;
1229 register struct symbol
*sym
;
1230 register CORE_ADDR sym_addr
;
1231 struct block
*block
;
1234 /* Info on best symbol seen so far */
1236 register CORE_ADDR best_sym_addr
= 0;
1237 struct symbol
*best_sym
= 0;
1239 /* FIXME -- we should pull in all the psymtabs, too! */
1240 ALL_SYMTABS (objfile
, symtab
)
1242 /* Search the global and static blocks in this symtab for
1243 the closest symbol-address to the desired address. */
1245 for (blocknum
= GLOBAL_BLOCK
; blocknum
<= STATIC_BLOCK
; blocknum
++)
1248 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab
), blocknum
);
1249 top
= BLOCK_NSYMS (block
);
1250 for (bot
= 0; bot
< top
; bot
++)
1252 sym
= BLOCK_SYM (block
, bot
);
1253 switch (SYMBOL_CLASS (sym
))
1257 sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1261 sym_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1268 if (sym_addr
<= addr
)
1269 if (sym_addr
> best_sym_addr
)
1271 /* Quit if we found an exact match. */
1273 best_sym_addr
= sym_addr
;
1274 best_symtab
= symtab
;
1275 if (sym_addr
== addr
)
1284 *symtabp
= best_symtab
;
1286 *symaddrp
= best_sym_addr
;
1291 /* Find the source file and line number for a given PC value and section.
1292 Return a structure containing a symtab pointer, a line number,
1293 and a pc range for the entire source line.
1294 The value's .pc field is NOT the specified pc.
1295 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1296 use the line that ends there. Otherwise, in that case, the line
1297 that begins there is used. */
1299 /* The big complication here is that a line may start in one file, and end just
1300 before the start of another file. This usually occurs when you #include
1301 code in the middle of a subroutine. To properly find the end of a line's PC
1302 range, we must search all symtabs associated with this compilation unit, and
1303 find the one whose first PC is closer than that of the next line in this
1306 /* If it's worth the effort, we could be using a binary search. */
1308 struct symtab_and_line
1309 find_pc_sect_line (pc
, section
, notcurrent
)
1311 struct sec
*section
;
1315 register struct linetable
*l
;
1318 register struct linetable_entry
*item
;
1319 struct symtab_and_line val
;
1320 struct blockvector
*bv
;
1322 /* Info on best line seen so far, and where it starts, and its file. */
1324 struct linetable_entry
*best
= NULL
;
1325 CORE_ADDR best_end
= 0;
1326 struct symtab
*best_symtab
= 0;
1328 /* Store here the first line number
1329 of a file which contains the line at the smallest pc after PC.
1330 If we don't find a line whose range contains PC,
1331 we will use a line one less than this,
1332 with a range from the start of that file to the first line's pc. */
1333 struct linetable_entry
*alt
= NULL
;
1334 struct symtab
*alt_symtab
= 0;
1336 /* Info on best line seen in this file. */
1338 struct linetable_entry
*prev
;
1340 /* If this pc is not from the current frame,
1341 it is the address of the end of a call instruction.
1342 Quite likely that is the start of the following statement.
1343 But what we want is the statement containing the instruction.
1344 Fudge the pc to make sure we get that. */
1346 INIT_SAL (&val
); /* initialize to zeroes */
1351 s
= find_pc_sect_symtab (pc
, section
);
1354 /* if no symbol information, return previous pc */
1361 bv
= BLOCKVECTOR (s
);
1363 /* Look at all the symtabs that share this blockvector.
1364 They all have the same apriori range, that we found was right;
1365 but they have different line tables. */
1367 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1369 /* Find the best line in this symtab. */
1376 /* I think len can be zero if the symtab lacks line numbers
1377 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
1378 I'm not sure which, and maybe it depends on the symbol
1384 item
= l
->item
; /* Get first line info */
1386 /* Is this file's first line closer than the first lines of other files?
1387 If so, record this file, and its first line, as best alternate. */
1388 if (item
->pc
> pc
&& (!alt
|| item
->pc
< alt
->pc
))
1394 for (i
= 0; i
< len
; i
++, item
++)
1396 /* Leave prev pointing to the linetable entry for the last line
1397 that started at or before PC. */
1404 /* At this point, prev points at the line whose start addr is <= pc, and
1405 item points at the next line. If we ran off the end of the linetable
1406 (pc >= start of the last line), then prev == item. If pc < start of
1407 the first line, prev will not be set. */
1409 /* Is this file's best line closer than the best in the other files?
1410 If so, record this file, and its best line, as best so far. */
1412 if (prev
&& (!best
|| prev
->pc
> best
->pc
))
1416 /* If another line is in the linetable, and its PC is closer
1417 than the best_end we currently have, take it as best_end. */
1418 if (i
< len
&& (best_end
== 0 || best_end
> item
->pc
))
1419 best_end
= item
->pc
;
1426 { /* If we didn't find any line # info, just
1432 val
.symtab
= alt_symtab
;
1433 val
.line
= alt
->line
- 1;
1435 /* Don't return line 0, that means that we didn't find the line. */
1436 if (val
.line
== 0) ++val
.line
;
1438 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1444 val
.symtab
= best_symtab
;
1445 val
.line
= best
->line
;
1447 if (best_end
&& (!alt
|| best_end
< alt
->pc
))
1452 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1454 val
.section
= section
;
1458 /* Backward compatibility (no section) */
1460 struct symtab_and_line
1461 find_pc_line (pc
, notcurrent
)
1467 section
= find_pc_overlay (pc
);
1468 if (pc_in_unmapped_range (pc
, section
))
1469 pc
= overlay_mapped_address (pc
, section
);
1470 return find_pc_sect_line (pc
, section
, notcurrent
);
1474 static struct symtab
* find_line_symtab
PARAMS ((struct symtab
*, int,
1477 /* Find line number LINE in any symtab whose name is the same as
1480 If found, return the symtab that contains the linetable in which it was
1481 found, set *INDEX to the index in the linetable of the best entry
1482 found, and set *EXACT_MATCH nonzero if the value returned is an
1485 If not found, return NULL. */
1487 static struct symtab
*
1488 find_line_symtab (symtab
, line
, index
, exact_match
)
1489 struct symtab
*symtab
;
1496 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
1500 struct linetable
*best_linetable
;
1501 struct symtab
*best_symtab
;
1503 /* First try looking it up in the given symtab. */
1504 best_linetable
= LINETABLE (symtab
);
1505 best_symtab
= symtab
;
1506 best_index
= find_line_common (best_linetable
, line
, &exact
);
1507 if (best_index
< 0 || !exact
)
1509 /* Didn't find an exact match. So we better keep looking for
1510 another symtab with the same name. In the case of xcoff,
1511 multiple csects for one source file (produced by IBM's FORTRAN
1512 compiler) produce multiple symtabs (this is unavoidable
1513 assuming csects can be at arbitrary places in memory and that
1514 the GLOBAL_BLOCK of a symtab has a begin and end address). */
1516 /* BEST is the smallest linenumber > LINE so far seen,
1517 or 0 if none has been seen so far.
1518 BEST_INDEX and BEST_LINETABLE identify the item for it. */
1521 struct objfile
*objfile
;
1524 if (best_index
>= 0)
1525 best
= best_linetable
->item
[best_index
].line
;
1529 ALL_SYMTABS (objfile
, s
)
1531 struct linetable
*l
;
1534 if (!STREQ (symtab
->filename
, s
->filename
))
1537 ind
= find_line_common (l
, line
, &exact
);
1547 if (best
== 0 || l
->item
[ind
].line
< best
)
1549 best
= l
->item
[ind
].line
;
1562 *index
= best_index
;
1564 *exact_match
= exact
;
1569 /* Set the PC value for a given source file and line number and return true.
1570 Returns zero for invalid line number (and sets the PC to 0).
1571 The source file is specified with a struct symtab. */
1574 find_line_pc (symtab
, line
, pc
)
1575 struct symtab
*symtab
;
1579 struct linetable
*l
;
1586 symtab
= find_line_symtab (symtab
, line
, &ind
, NULL
);
1589 l
= LINETABLE (symtab
);
1590 *pc
= l
->item
[ind
].pc
;
1597 /* Find the range of pc values in a line.
1598 Store the starting pc of the line into *STARTPTR
1599 and the ending pc (start of next line) into *ENDPTR.
1600 Returns 1 to indicate success.
1601 Returns 0 if could not find the specified line. */
1604 find_line_pc_range (sal
, startptr
, endptr
)
1605 struct symtab_and_line sal
;
1606 CORE_ADDR
*startptr
, *endptr
;
1608 CORE_ADDR startaddr
;
1609 struct symtab_and_line found_sal
;
1612 if (startaddr
==0 && !find_line_pc (sal
.symtab
, sal
.line
, &startaddr
))
1615 /* This whole function is based on address. For example, if line 10 has
1616 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
1617 "info line *0x123" should say the line goes from 0x100 to 0x200
1618 and "info line *0x355" should say the line goes from 0x300 to 0x400.
1619 This also insures that we never give a range like "starts at 0x134
1620 and ends at 0x12c". */
1622 found_sal
= find_pc_sect_line (startaddr
, sal
.section
, 0);
1623 if (found_sal
.line
!= sal
.line
)
1625 /* The specified line (sal) has zero bytes. */
1626 *startptr
= found_sal
.pc
;
1627 *endptr
= found_sal
.pc
;
1631 *startptr
= found_sal
.pc
;
1632 *endptr
= found_sal
.end
;
1637 /* Given a line table and a line number, return the index into the line
1638 table for the pc of the nearest line whose number is >= the specified one.
1639 Return -1 if none is found. The value is >= 0 if it is an index.
1641 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1644 find_line_common (l
, lineno
, exact_match
)
1645 register struct linetable
*l
;
1646 register int lineno
;
1652 /* BEST is the smallest linenumber > LINENO so far seen,
1653 or 0 if none has been seen so far.
1654 BEST_INDEX identifies the item for it. */
1656 int best_index
= -1;
1665 for (i
= 0; i
< len
; i
++)
1667 register struct linetable_entry
*item
= &(l
->item
[i
]);
1669 if (item
->line
== lineno
)
1671 /* Return the first (lowest address) entry which matches. */
1676 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
1683 /* If we got here, we didn't get an exact match. */
1690 find_pc_line_pc_range (pc
, startptr
, endptr
)
1692 CORE_ADDR
*startptr
, *endptr
;
1694 struct symtab_and_line sal
;
1695 sal
= find_pc_line (pc
, 0);
1698 return sal
.symtab
!= 0;
1701 /* Given a function symbol SYM, find the symtab and line for the start
1703 If the argument FUNFIRSTLINE is nonzero, we want the first line
1704 of real code inside the function. */
1706 static struct symtab_and_line
1707 find_function_start_sal
PARAMS ((struct symbol
*sym
, int));
1709 static struct symtab_and_line
1710 find_function_start_sal (sym
, funfirstline
)
1715 struct symtab_and_line sal
;
1717 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1718 fixup_symbol_section (sym
, NULL
);
1720 { /* skip "first line" of function (which is actually its prologue) */
1721 asection
*section
= SYMBOL_BFD_SECTION (sym
);
1722 /* If function is in an unmapped overlay, use its unmapped LMA
1723 address, so that SKIP_PROLOGUE has something unique to work on */
1724 if (section_is_overlay (section
) &&
1725 !section_is_mapped (section
))
1726 pc
= overlay_unmapped_address (pc
, section
);
1728 pc
+= FUNCTION_START_OFFSET
;
1731 /* For overlays, map pc back into its mapped VMA range */
1732 pc
= overlay_mapped_address (pc
, section
);
1734 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
1736 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1737 /* Convex: no need to suppress code on first line, if any */
1740 /* Check if SKIP_PROLOGUE left us in mid-line, and the next
1741 line is still part of the same function. */
1743 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) <= sal
.end
1744 && sal
.end
< BLOCK_END (SYMBOL_BLOCK_VALUE (sym
)))
1746 /* First pc of next line */
1748 /* Recalculate the line number (might not be N+1). */
1749 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
1757 /* If P is of the form "operator[ \t]+..." where `...' is
1758 some legitimate operator text, return a pointer to the
1759 beginning of the substring of the operator text.
1760 Otherwise, return "". */
1762 operator_chars (p
, end
)
1767 if (strncmp (p
, "operator", 8))
1771 /* Don't get faked out by `operator' being part of a longer
1773 if (isalpha(*p
) || *p
== '_' || *p
== '$' || *p
== '\0')
1776 /* Allow some whitespace between `operator' and the operator symbol. */
1777 while (*p
== ' ' || *p
== '\t')
1780 /* Recognize 'operator TYPENAME'. */
1782 if (isalpha(*p
) || *p
== '_' || *p
== '$')
1784 register char *q
= p
+1;
1785 while (isalnum(*q
) || *q
== '_' || *q
== '$')
1810 if (p
[1] == '=' || p
[1] == p
[0])
1821 error ("`operator ()' must be specified without whitespace in `()'");
1826 error ("`operator ?:' must be specified without whitespace in `?:'");
1831 error ("`operator []' must be specified without whitespace in `[]'");
1835 error ("`operator %s' not supported", p
);
1842 /* Return the number of methods described for TYPE, including the
1843 methods from types it derives from. This can't be done in the symbol
1844 reader because the type of the baseclass might still be stubbed
1845 when the definition of the derived class is parsed. */
1847 static int total_number_of_methods
PARAMS ((struct type
*type
));
1850 total_number_of_methods (type
)
1856 CHECK_TYPEDEF (type
);
1857 if (TYPE_CPLUS_SPECIFIC (type
) == NULL
)
1859 count
= TYPE_NFN_FIELDS_TOTAL (type
);
1861 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
1862 count
+= total_number_of_methods (TYPE_BASECLASS (type
, n
));
1867 /* Recursive helper function for decode_line_1.
1868 Look for methods named NAME in type T.
1869 Return number of matches.
1870 Put matches in SYM_ARR, which should have been allocated with
1871 a size of total_number_of_methods (T) * sizeof (struct symbol *).
1872 Note that this function is g++ specific. */
1875 find_methods (t
, name
, sym_arr
)
1878 struct symbol
**sym_arr
;
1882 struct symbol
*sym_class
;
1883 char *class_name
= type_name_no_tag (t
);
1885 /* Ignore this class if it doesn't have a name. This is ugly, but
1886 unless we figure out how to get the physname without the name of
1887 the class, then the loop can't do any good. */
1889 && (sym_class
= lookup_symbol (class_name
,
1890 (struct block
*)NULL
,
1893 (struct symtab
**)NULL
)))
1897 /* FIXME: Shouldn't this just be CHECK_TYPEDEF (t)? */
1898 t
= SYMBOL_TYPE (sym_class
);
1900 /* Loop over each method name. At this level, all overloads of a name
1901 are counted as a single name. There is an inner loop which loops over
1904 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
1905 method_counter
>= 0;
1909 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
1910 char dem_opname
[64];
1912 if (strncmp (method_name
, "__", 2) == 0 ||
1913 strncmp (method_name
, "op", 2) == 0 ||
1914 strncmp (method_name
, "type", 4) == 0)
1915 if (cplus_demangle_opname (method_name
, dem_opname
, DMGL_ANSI
))
1916 method_name
= dem_opname
;
1917 else if (cplus_demangle_opname (method_name
, dem_opname
, 0))
1918 method_name
= dem_opname
;
1920 if (STREQ (name
, method_name
))
1921 /* Find all the overloaded methods with that name. */
1922 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
1929 f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
1931 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
1935 tmp_name
= gdb_mangle_name (t
,
1938 phys_name
= alloca (strlen (tmp_name
) + 1);
1939 strcpy (phys_name
, tmp_name
);
1943 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
1945 /* Destructor is handled by caller, dont add it to the list */
1946 if (DESTRUCTOR_PREFIX_P (phys_name
))
1949 sym_arr
[i1
] = lookup_symbol (phys_name
,
1950 NULL
, VAR_NAMESPACE
,
1952 (struct symtab
**) NULL
);
1957 /* This error message gets printed, but the method
1958 still seems to be found
1959 fputs_filtered("(Cannot find method ", gdb_stdout);
1960 fprintf_symbol_filtered (gdb_stdout, phys_name,
1962 DMGL_PARAMS | DMGL_ANSI);
1963 fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
1970 /* Only search baseclasses if there is no match yet, since names in
1971 derived classes override those in baseclasses.
1973 FIXME: The above is not true; it is only true of member functions
1974 if they have the same number of arguments (??? - section 13.1 of the
1975 ARM says the function members are not in the same scope but doesn't
1976 really spell out the rules in a way I understand. In any case, if
1977 the number of arguments differ this is a case in which we can overload
1978 rather than hiding without any problem, and gcc 2.4.5 does overload
1979 rather than hiding in this case). */
1982 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
1983 i1
+= find_methods (TYPE_BASECLASS (t
, ibase
), name
, sym_arr
+ i1
);
1988 /* Helper function for decode_line_1.
1989 Build a canonical line spec in CANONICAL if it is non-NULL and if
1990 the SAL has a symtab.
1991 If SYMNAME is non-NULL the canonical line spec is `filename:symname'.
1992 If SYMNAME is NULL the line number from SAL is used and the canonical
1993 line spec is `filename:linenum'. */
1996 build_canonical_line_spec (sal
, symname
, canonical
)
1997 struct symtab_and_line
*sal
;
2001 char **canonical_arr
;
2002 char *canonical_name
;
2004 struct symtab
*s
= sal
->symtab
;
2006 if (s
== (struct symtab
*)NULL
2007 || s
->filename
== (char *)NULL
2008 || canonical
== (char ***)NULL
)
2011 canonical_arr
= (char **) xmalloc (sizeof (char *));
2012 *canonical
= canonical_arr
;
2014 filename
= s
->filename
;
2015 if (symname
!= NULL
)
2017 canonical_name
= xmalloc (strlen (filename
) + strlen (symname
) + 2);
2018 sprintf (canonical_name
, "%s:%s", filename
, symname
);
2022 canonical_name
= xmalloc (strlen (filename
) + 30);
2023 sprintf (canonical_name
, "%s:%d", filename
, sal
->line
);
2025 canonical_arr
[0] = canonical_name
;
2028 /* Parse a string that specifies a line number.
2029 Pass the address of a char * variable; that variable will be
2030 advanced over the characters actually parsed.
2034 LINENUM -- that line number in current file. PC returned is 0.
2035 FILE:LINENUM -- that line in that file. PC returned is 0.
2036 FUNCTION -- line number of openbrace of that function.
2037 PC returned is the start of the function.
2038 VARIABLE -- line number of definition of that variable.
2040 FILE:FUNCTION -- likewise, but prefer functions in that file.
2041 *EXPR -- line in which address EXPR appears.
2043 FUNCTION may be an undebuggable function found in minimal symbol table.
2045 If the argument FUNFIRSTLINE is nonzero, we want the first line
2046 of real code inside a function when a function is specified, and it is
2047 not OK to specify a variable or type to get its line number.
2049 DEFAULT_SYMTAB specifies the file to use if none is specified.
2050 It defaults to current_source_symtab.
2051 DEFAULT_LINE specifies the line number to use for relative
2052 line numbers (that start with signs). Defaults to current_source_line.
2053 If CANONICAL is non-NULL, store an array of strings containing the canonical
2054 line specs there if necessary. Currently overloaded member functions and
2055 line numbers or static functions without a filename yield a canonical
2056 line spec. The array and the line spec strings are allocated on the heap,
2057 it is the callers responsibility to free them.
2059 Note that it is possible to return zero for the symtab
2060 if no file is validly specified. Callers must check that.
2061 Also, the line number returned may be invalid. */
2063 /* We allow single quotes in various places. This is a hideous
2064 kludge, which exists because the completer can't yet deal with the
2065 lack of single quotes. FIXME: write a linespec_completer which we
2066 can use as appropriate instead of make_symbol_completion_list. */
2068 struct symtabs_and_lines
2069 decode_line_1 (argptr
, funfirstline
, default_symtab
, default_line
, canonical
)
2072 struct symtab
*default_symtab
;
2076 struct symtabs_and_lines values
;
2077 #ifdef HPPA_COMPILER_BUG
2078 /* FIXME: The native HP 9000/700 compiler has a bug which appears
2079 when optimizing this file with target i960-vxworks. I haven't
2080 been able to construct a simple test case. The problem is that
2081 in the second call to SKIP_PROLOGUE below, the compiler somehow
2082 does not realize that the statement val = find_pc_line (...) will
2083 change the values of the fields of val. It extracts the elements
2084 into registers at the top of the block, and does not update the
2085 registers after the call to find_pc_line. You can check this by
2086 inserting a printf at the end of find_pc_line to show what values
2087 it is returning for val.pc and val.end and another printf after
2088 the call to see what values the function actually got (remember,
2089 this is compiling with cc -O, with this patch removed). You can
2090 also examine the assembly listing: search for the second call to
2091 skip_prologue; the LDO statement before the next call to
2092 find_pc_line loads the address of the structure which
2093 find_pc_line will return; if there is a LDW just before the LDO,
2094 which fetches an element of the structure, then the compiler
2097 Setting val to volatile avoids the problem. We must undef
2098 volatile, because the HPPA native compiler does not define
2099 __STDC__, although it does understand volatile, and so volatile
2100 will have been defined away in defs.h. */
2102 volatile struct symtab_and_line val
;
2103 #define volatile /*nothing*/
2105 struct symtab_and_line val
;
2107 register char *p
, *p1
;
2109 register struct symtab
*s
;
2111 register struct symbol
*sym
;
2112 /* The symtab that SYM was found in. */
2113 struct symtab
*sym_symtab
;
2115 register CORE_ADDR pc
;
2116 register struct minimal_symbol
*msymbol
;
2118 int is_quoted
, has_parens
;
2119 char *saved_arg
= *argptr
;
2120 extern char *gdb_completer_quote_characters
;
2122 INIT_SAL (&val
); /* initialize to zeroes */
2124 /* Defaults have defaults. */
2126 if (default_symtab
== 0)
2128 default_symtab
= current_source_symtab
;
2129 default_line
= current_source_line
;
2132 /* See if arg is *PC */
2134 if (**argptr
== '*')
2137 pc
= parse_and_eval_address_1 (argptr
);
2139 values
.sals
= (struct symtab_and_line
*)
2140 xmalloc (sizeof (struct symtab_and_line
));
2143 values
.sals
[0] = find_pc_line (pc
, 0);
2144 values
.sals
[0].pc
= pc
;
2145 values
.sals
[0].section
= find_pc_overlay (pc
);
2150 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
2153 is_quoted
= (**argptr
2154 && strchr (gdb_completer_quote_characters
, **argptr
) != NULL
);
2155 has_parens
= ((pp
= strchr (*argptr
, '(')) != NULL
2156 && (pp
= strchr (pp
, ')')) != NULL
);
2158 for (p
= *argptr
; *p
; p
++)
2162 while(++p
&& *p
!= '>');
2165 error ("non-matching '<' and '>' in command");
2168 if (p
[0] == ':' || p
[0] == ' ' || p
[0] == '\t')
2170 /* start-sanitize-java */
2171 if (p
[0] == '.' && strchr (p
, ':') == NULL
) /* Java qualified method. */
2173 /* Find the *last* '.', since the others are package qualifiers. */
2174 for (p1
= p
; *p1
; p1
++)
2181 /* end-sanitize-java */
2183 while (p
[0] == ' ' || p
[0] == '\t') p
++;
2185 if ((p
[0] == ':' || p
[0] == '.') && !has_parens
)
2188 /* start-sanitize-java */
2190 /* end-sanitize-java */
2191 if (is_quoted
) *argptr
= *argptr
+1;
2192 if (p
[0] == '.' || p
[1] ==':')
2194 struct symbol
*sym_class
;
2196 /* Extract the class name. */
2198 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
2199 copy
= (char *) alloca (p
- *argptr
+ 1);
2200 memcpy (copy
, *argptr
, p
- *argptr
);
2201 copy
[p
- *argptr
] = 0;
2203 /* Discard the class name from the arg. */
2204 p
= p1
+ (p1
[0] == ':' ? 2 : 1);
2205 while (*p
== ' ' || *p
== '\t') p
++;
2208 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
2209 (struct symtab
**)NULL
);
2212 (TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_STRUCT
2213 || TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_UNION
))
2215 struct symbol
**sym_arr
;
2219 t
= check_typedef (SYMBOL_TYPE (sym_class
));
2221 /* Arg token is not digits => try it as a function name
2222 Find the next token(everything up to end or next blank). */
2224 && strchr (gdb_completer_quote_characters
, **argptr
) != NULL
)
2226 p
= skip_quoted(*argptr
);
2227 *argptr
= *argptr
+ 1;
2232 while (*p
&& *p
!=' ' && *p
!='\t' && *p
!=',' && *p
!=':') p
++;
2235 q = operator_chars (*argptr, &q1);
2239 char *tmp = alloca (q1 - q + 1);
2240 memcpy (tmp, q, q1 - q);
2242 opname = cplus_mangle_opname (tmp, DMGL_ANSI);
2246 printf_filtered ("no mangling for \"%s\"\n", tmp);
2247 cplusplus_hint (saved_arg);
2248 return_to_top_level (RETURN_ERROR);
2250 copy = (char*) alloca (3 + strlen(opname));
2251 sprintf (copy, "__%s", opname);
2257 copy
= (char *) alloca (p
- *argptr
+ 1 );
2258 memcpy (copy
, *argptr
, p
- *argptr
);
2259 copy
[p
- *argptr
] = '\0';
2261 && copy
[p
- *argptr
- 1]
2262 && strchr (gdb_completer_quote_characters
,
2263 copy
[p
- *argptr
- 1]) != NULL
)
2264 copy
[p
- *argptr
- 1] = '\0';
2267 /* no line number may be specified */
2268 while (*p
== ' ' || *p
== '\t') p
++;
2272 i1
= 0; /* counter for the symbol array */
2273 sym_arr
= (struct symbol
**) alloca(total_number_of_methods (t
)
2274 * sizeof(struct symbol
*));
2276 if (destructor_name_p (copy
, t
))
2278 /* Destructors are a special case. */
2279 int m_index
, f_index
;
2281 if (get_destructor_fn_field (t
, &m_index
, &f_index
))
2283 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, m_index
);
2286 lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f
, f_index
),
2287 NULL
, VAR_NAMESPACE
, (int *) NULL
,
2288 (struct symtab
**)NULL
);
2294 i1
= find_methods (t
, copy
, sym_arr
);
2297 /* There is exactly one field with that name. */
2300 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2302 values
.sals
= (struct symtab_and_line
*)
2303 xmalloc (sizeof (struct symtab_and_line
));
2305 values
.sals
[0] = find_function_start_sal (sym
,
2316 /* There is more than one field with that name
2317 (overloaded). Ask the user which one to use. */
2318 return decode_line_2 (sym_arr
, i1
, funfirstline
, canonical
);
2324 if (OPNAME_PREFIX_P (copy
))
2326 tmp
= (char *)alloca (strlen (copy
+3) + 9);
2327 strcpy (tmp
, "operator ");
2328 strcat (tmp
, copy
+3);
2335 ("the class `%s' does not have destructor defined\n",
2336 SYMBOL_SOURCE_NAME(sym_class
));
2339 ("the class %s does not have any method named %s\n",
2340 SYMBOL_SOURCE_NAME(sym_class
), tmp
);
2341 cplusplus_hint (saved_arg
);
2342 return_to_top_level (RETURN_ERROR
);
2348 /* The quotes are important if copy is empty. */
2350 ("can't find class, struct, or union named \"%s\"\n", copy
);
2351 cplusplus_hint (saved_arg
);
2352 return_to_top_level (RETURN_ERROR
);
2358 /* Extract the file name. */
2360 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
2361 copy
= (char *) alloca (p
- *argptr
+ 1);
2362 memcpy (copy
, *argptr
, p
- *argptr
);
2363 copy
[p
- *argptr
] = 0;
2365 /* Find that file's data. */
2366 s
= lookup_symtab (copy
);
2369 if (!have_full_symbols () && !have_partial_symbols ())
2370 error (no_symtab_msg
);
2371 error ("No source file named %s.", copy
);
2374 /* Discard the file name from the arg. */
2376 while (*p
== ' ' || *p
== '\t') p
++;
2380 /* S is specified file's symtab, or 0 if no file specified.
2381 arg no longer contains the file name. */
2383 /* Check whether arg is all digits (and sign) */
2386 if (*q
== '-' || *q
== '+') q
++;
2387 while (*q
>= '0' && *q
<= '9')
2390 if (q
!= *argptr
&& (*q
== 0 || *q
== ' ' || *q
== '\t' || *q
== ','))
2392 /* We found a token consisting of all digits -- at least one digit. */
2393 enum sign
{none
, plus
, minus
} sign
= none
;
2395 /* We might need a canonical line spec if no file was specified. */
2396 int need_canonical
= (s
== 0) ? 1 : 0;
2398 /* This is where we need to make sure that we have good defaults.
2399 We must guarantee that this section of code is never executed
2400 when we are called with just a function name, since
2401 select_source_symtab calls us with such an argument */
2403 if (s
== 0 && default_symtab
== 0)
2405 select_source_symtab (0);
2406 default_symtab
= current_source_symtab
;
2407 default_line
= current_source_line
;
2410 if (**argptr
== '+')
2411 sign
= plus
, (*argptr
)++;
2412 else if (**argptr
== '-')
2413 sign
= minus
, (*argptr
)++;
2414 val
.line
= atoi (*argptr
);
2421 val
.line
= default_line
+ val
.line
;
2427 val
.line
= default_line
- val
.line
;
2432 break; /* No need to adjust val.line. */
2435 while (*q
== ' ' || *q
== '\t') q
++;
2440 /* It is possible that this source file has more than one symtab,
2441 and that the new line number specification has moved us from the
2442 default (in s) to a new one. */
2443 val
.symtab
= find_line_symtab (s
, val
.line
, NULL
, NULL
);
2444 if (val
.symtab
== 0)
2448 values
.sals
= (struct symtab_and_line
*)
2449 xmalloc (sizeof (struct symtab_and_line
));
2450 values
.sals
[0] = val
;
2453 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
2457 /* Arg token is not digits => try it as a variable name
2458 Find the next token (everything up to end or next whitespace). */
2460 if (**argptr
== '$') /* Convenience variable */
2461 p
= skip_quoted (*argptr
+ 1);
2464 p
= skip_quoted (*argptr
);
2466 error ("Unmatched single quote.");
2468 else if (has_parens
)
2474 p
= skip_quoted(*argptr
);
2477 copy
= (char *) alloca (p
- *argptr
+ 1);
2478 memcpy (copy
, *argptr
, p
- *argptr
);
2479 copy
[p
- *argptr
] = '\0';
2482 && copy
[0] == copy
[p
- *argptr
- 1]
2483 && strchr (gdb_completer_quote_characters
, copy
[0]) != NULL
)
2485 copy
[p
- *argptr
- 1] = '\0';
2488 while (*p
== ' ' || *p
== '\t') p
++;
2491 /* See if it's a convenience variable */
2496 int need_canonical
= (s
== 0) ? 1 : 0;
2498 valx
= value_of_internalvar (lookup_internalvar (copy
+ 1));
2499 if (TYPE_CODE (VALUE_TYPE (valx
)) != TYPE_CODE_INT
)
2500 error ("Convenience variables used in line specs must have integer values.");
2502 val
.symtab
= s
? s
: default_symtab
;
2503 val
.line
= value_as_long (valx
);
2506 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof val
);
2507 values
.sals
[0] = val
;
2511 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
2517 /* Look up that token as a variable.
2518 If file specified, use that file's per-file block to start with. */
2520 sym
= lookup_symbol (copy
,
2521 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
2522 : get_selected_block ()),
2523 VAR_NAMESPACE
, 0, &sym_symtab
);
2527 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2529 /* Arg is the name of a function */
2530 values
.sals
= (struct symtab_and_line
*)
2531 xmalloc (sizeof (struct symtab_and_line
));
2532 values
.sals
[0] = find_function_start_sal (sym
, funfirstline
);
2535 /* Don't use the SYMBOL_LINE; if used at all it points to
2536 the line containing the parameters or thereabouts, not
2537 the first line of code. */
2539 /* We might need a canonical line spec if it is a static
2543 struct blockvector
*bv
= BLOCKVECTOR (sym_symtab
);
2544 struct block
*b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2545 if (lookup_block_symbol (b
, copy
, VAR_NAMESPACE
) != NULL
)
2546 build_canonical_line_spec (values
.sals
, copy
, canonical
);
2553 error ("\"%s\" is not a function", copy
);
2554 else if (SYMBOL_LINE (sym
) != 0)
2556 /* We know its line number. */
2557 values
.sals
= (struct symtab_and_line
*)
2558 xmalloc (sizeof (struct symtab_and_line
));
2560 memset (&values
.sals
[0], 0, sizeof (values
.sals
[0]));
2561 values
.sals
[0].symtab
= sym_symtab
;
2562 values
.sals
[0].line
= SYMBOL_LINE (sym
);
2566 /* This can happen if it is compiled with a compiler which doesn't
2567 put out line numbers for variables. */
2568 /* FIXME: Shouldn't we just set .line and .symtab to zero
2569 and return? For example, "info line foo" could print
2571 error ("Line number not known for symbol \"%s\"", copy
);
2575 msymbol
= lookup_minimal_symbol (copy
, NULL
, NULL
);
2576 if (msymbol
!= NULL
)
2578 val
.pc
= SYMBOL_VALUE_ADDRESS (msymbol
);
2579 val
.section
= SYMBOL_BFD_SECTION (msymbol
);
2582 val
.pc
+= FUNCTION_START_OFFSET
;
2583 SKIP_PROLOGUE (val
.pc
);
2585 values
.sals
= (struct symtab_and_line
*)
2586 xmalloc (sizeof (struct symtab_and_line
));
2587 values
.sals
[0] = val
;
2592 if (!have_full_symbols () &&
2593 !have_partial_symbols () && !have_minimal_symbols ())
2594 error (no_symtab_msg
);
2596 error ("Function \"%s\" not defined.", copy
);
2597 return values
; /* for lint */
2600 struct symtabs_and_lines
2601 decode_line_spec (string
, funfirstline
)
2605 struct symtabs_and_lines sals
;
2607 error ("Empty line specification.");
2608 sals
= decode_line_1 (&string
, funfirstline
,
2609 current_source_symtab
, current_source_line
,
2612 error ("Junk at end of line specification: %s", string
);
2616 /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to
2617 operate on (ask user if necessary).
2618 If CANONICAL is non-NULL return a corresponding array of mangled names
2619 as canonical line specs there. */
2621 static struct symtabs_and_lines
2622 decode_line_2 (sym_arr
, nelts
, funfirstline
, canonical
)
2623 struct symbol
*sym_arr
[];
2628 struct symtabs_and_lines values
, return_values
;
2633 struct cleanup
*old_chain
;
2634 char **canonical_arr
= (char **)NULL
;
2636 values
.sals
= (struct symtab_and_line
*)
2637 alloca (nelts
* sizeof(struct symtab_and_line
));
2638 return_values
.sals
= (struct symtab_and_line
*)
2639 xmalloc (nelts
* sizeof(struct symtab_and_line
));
2640 old_chain
= make_cleanup (free
, return_values
.sals
);
2644 canonical_arr
= (char **) xmalloc (nelts
* sizeof (char *));
2645 make_cleanup (free
, canonical_arr
);
2646 memset (canonical_arr
, 0, nelts
* sizeof (char *));
2647 *canonical
= canonical_arr
;
2651 printf_unfiltered("[0] cancel\n[1] all\n");
2654 INIT_SAL (&return_values
.sals
[i
]); /* initialize to zeroes */
2655 INIT_SAL (&values
.sals
[i
]);
2656 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
2658 values
.sals
[i
] = find_function_start_sal (sym_arr
[i
], funfirstline
);
2659 printf_unfiltered ("[%d] %s at %s:%d\n",
2661 SYMBOL_SOURCE_NAME (sym_arr
[i
]),
2662 values
.sals
[i
].symtab
->filename
,
2663 values
.sals
[i
].line
);
2666 printf_unfiltered ("?HERE\n");
2670 if ((prompt
= getenv ("PS2")) == NULL
)
2674 printf_unfiltered("%s ",prompt
);
2675 gdb_flush(gdb_stdout
);
2677 args
= command_line_input ((char *) NULL
, 0, "overload-choice");
2679 if (args
== 0 || *args
== 0)
2680 error_no_arg ("one or more choice numbers");
2688 while (*arg1
>= '0' && *arg1
<= '9') arg1
++;
2689 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
2690 error ("Arguments must be choice numbers.");
2695 error ("cancelled");
2700 for (i
= 0; i
< nelts
; i
++)
2702 if (canonical_arr
[i
] == NULL
)
2704 symname
= SYMBOL_NAME (sym_arr
[i
]);
2705 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
2709 memcpy (return_values
.sals
, values
.sals
,
2710 (nelts
* sizeof(struct symtab_and_line
)));
2711 return_values
.nelts
= nelts
;
2712 discard_cleanups (old_chain
);
2713 return return_values
;
2716 if (num
>= nelts
+ 2)
2718 printf_unfiltered ("No choice number %d.\n", num
);
2723 if (values
.sals
[num
].pc
)
2727 symname
= SYMBOL_NAME (sym_arr
[num
]);
2728 make_cleanup (free
, symname
);
2729 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
2731 return_values
.sals
[i
++] = values
.sals
[num
];
2732 values
.sals
[num
].pc
= 0;
2736 printf_unfiltered ("duplicate request for %d ignored.\n", num
);
2741 while (*args
== ' ' || *args
== '\t') args
++;
2743 return_values
.nelts
= i
;
2744 discard_cleanups (old_chain
);
2745 return return_values
;
2749 /* Slave routine for sources_info. Force line breaks at ,'s.
2750 NAME is the name to print and *FIRST is nonzero if this is the first
2751 name printed. Set *FIRST to zero. */
2753 output_source_filename (name
, first
)
2757 /* Table of files printed so far. Since a single source file can
2758 result in several partial symbol tables, we need to avoid printing
2759 it more than once. Note: if some of the psymtabs are read in and
2760 some are not, it gets printed both under "Source files for which
2761 symbols have been read" and "Source files for which symbols will
2762 be read in on demand". I consider this a reasonable way to deal
2763 with the situation. I'm not sure whether this can also happen for
2764 symtabs; it doesn't hurt to check. */
2765 static char **tab
= NULL
;
2766 /* Allocated size of tab in elements.
2767 Start with one 256-byte block (when using GNU malloc.c).
2768 24 is the malloc overhead when range checking is in effect. */
2769 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
2770 /* Current size of tab in elements. */
2771 static int tab_cur_size
;
2778 tab
= (char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
2782 /* Is NAME in tab? */
2783 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
2784 if (STREQ (*p
, name
))
2785 /* Yes; don't print it again. */
2787 /* No; add it to tab. */
2788 if (tab_cur_size
== tab_alloc_size
)
2790 tab_alloc_size
*= 2;
2791 tab
= (char **) xrealloc ((char *) tab
, tab_alloc_size
* sizeof (*tab
));
2793 tab
[tab_cur_size
++] = name
;
2801 printf_filtered (", ");
2805 fputs_filtered (name
, gdb_stdout
);
2809 sources_info (ignore
, from_tty
)
2813 register struct symtab
*s
;
2814 register struct partial_symtab
*ps
;
2815 register struct objfile
*objfile
;
2818 if (!have_full_symbols () && !have_partial_symbols ())
2820 error (no_symtab_msg
);
2823 printf_filtered ("Source files for which symbols have been read in:\n\n");
2826 ALL_SYMTABS (objfile
, s
)
2828 output_source_filename (s
-> filename
, &first
);
2830 printf_filtered ("\n\n");
2832 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2835 ALL_PSYMTABS (objfile
, ps
)
2839 output_source_filename (ps
-> filename
, &first
);
2842 printf_filtered ("\n");
2846 file_matches (file
, files
, nfiles
)
2853 if (file
!= NULL
&& nfiles
!= 0)
2855 for (i
= 0; i
< nfiles
; i
++)
2857 if (strcmp (files
[i
], basename (file
)) == 0)
2861 else if (nfiles
== 0)
2866 /* Free any memory associated with a search. */
2868 free_search_symbols (symbols
)
2869 struct symbol_search
*symbols
;
2871 struct symbol_search
*p
;
2872 struct symbol_search
*next
;
2874 for (p
= symbols
; p
!= NULL
; p
= next
)
2881 /* Search the symbol table for matches to the regular expression REGEXP,
2882 returning the results in *MATCHES.
2884 Only symbols of KIND are searched:
2885 FUNCTIONS_NAMESPACE - search all functions
2886 TYPES_NAMESPACE - search all type names
2887 METHODS_NAMESPACE - search all methods NOT IMPLEMENTED
2888 VARIABLES_NAMESPACE - search all symbols, excluding functions, type names,
2889 and constants (enums)
2891 free_search_symbols should be called when *MATCHES is no longer needed.
2894 search_symbols (regexp
, kind
, nfiles
, files
, matches
)
2896 namespace_enum kind
;
2899 struct symbol_search
**matches
;
2902 register struct symtab
*s
;
2903 register struct partial_symtab
*ps
;
2904 register struct blockvector
*bv
;
2905 struct blockvector
*prev_bv
= 0;
2906 register struct block
*b
;
2908 register struct symbol
*sym
;
2909 struct partial_symbol
**psym
;
2910 struct objfile
*objfile
;
2911 struct minimal_symbol
*msymbol
;
2914 static enum minimal_symbol_type types
[]
2915 = {mst_data
, mst_text
, mst_abs
, mst_unknown
};
2916 static enum minimal_symbol_type types2
[]
2917 = {mst_bss
, mst_file_text
, mst_abs
, mst_unknown
};
2918 static enum minimal_symbol_type types3
[]
2919 = {mst_file_data
, mst_solib_trampoline
, mst_abs
, mst_unknown
};
2920 static enum minimal_symbol_type types4
[]
2921 = {mst_file_bss
, mst_text
, mst_abs
, mst_unknown
};
2922 enum minimal_symbol_type ourtype
;
2923 enum minimal_symbol_type ourtype2
;
2924 enum minimal_symbol_type ourtype3
;
2925 enum minimal_symbol_type ourtype4
;
2926 struct symbol_search
*sr
;
2927 struct symbol_search
*psr
;
2928 struct symbol_search
*tail
;
2929 struct cleanup
*old_chain
= NULL
;
2931 if (kind
< LABEL_NAMESPACE
)
2932 error ("must search on specific namespace");
2934 ourtype
= types
[(int) (kind
- LABEL_NAMESPACE
)];
2935 ourtype2
= types2
[(int) (kind
- LABEL_NAMESPACE
)];
2936 ourtype3
= types3
[(int) (kind
- LABEL_NAMESPACE
)];
2937 ourtype4
= types4
[(int) (kind
- LABEL_NAMESPACE
)];
2939 sr
= *matches
= NULL
;
2944 /* Make sure spacing is right for C++ operators.
2945 This is just a courtesy to make the matching less sensitive
2946 to how many spaces the user leaves between 'operator'
2947 and <TYPENAME> or <OPERATOR>. */
2949 char *opname
= operator_chars (regexp
, &opend
);
2952 int fix
= -1; /* -1 means ok; otherwise number of spaces needed. */
2953 if (isalpha(*opname
) || *opname
== '_' || *opname
== '$')
2955 /* There should 1 space between 'operator' and 'TYPENAME'. */
2956 if (opname
[-1] != ' ' || opname
[-2] == ' ')
2961 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2962 if (opname
[-1] == ' ')
2965 /* If wrong number of spaces, fix it. */
2968 char *tmp
= (char*) alloca(opend
-opname
+10);
2969 sprintf(tmp
, "operator%.*s%s", fix
, " ", opname
);
2974 if (0 != (val
= re_comp (regexp
)))
2975 error ("Invalid regexp (%s): %s", val
, regexp
);
2978 /* Search through the partial symtabs *first* for all symbols
2979 matching the regexp. That way we don't have to reproduce all of
2980 the machinery below. */
2982 ALL_PSYMTABS (objfile
, ps
)
2984 struct partial_symbol
**bound
, **gbound
, **sbound
;
2987 if (ps
->readin
) continue;
2989 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2990 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2993 /* Go through all of the symbols stored in a partial
2994 symtab in one loop. */
2995 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
3000 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
3002 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
3013 /* If it would match (logic taken from loop below)
3014 load the file and go on to the next one */
3015 if (file_matches (ps
->filename
, files
, nfiles
)
3016 && ((regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (*psym
))
3017 && ((kind
== VARIABLES_NAMESPACE
&& SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
3018 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
3019 || (kind
== FUNCTIONS_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
3020 || (kind
== TYPES_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
)
3021 || (kind
== METHODS_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
))))
3023 PSYMTAB_TO_SYMTAB(ps
);
3031 /* Here, we search through the minimal symbol tables for functions
3032 and variables that match, and force their symbols to be read.
3033 This is in particular necessary for demangled variable names,
3034 which are no longer put into the partial symbol tables.
3035 The symbol will then be found during the scan of symtabs below.
3037 For functions, find_pc_symtab should succeed if we have debug info
3038 for the function, for variables we have to call lookup_symbol
3039 to determine if the variable has debug info.
3040 If the lookup fails, set found_misc so that we will rescan to print
3041 any matching symbols without debug info.
3044 if (nfiles
== 0 && (kind
== VARIABLES_NAMESPACE
|| kind
== FUNCTIONS_NAMESPACE
))
3046 ALL_MSYMBOLS (objfile
, msymbol
)
3048 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
3049 MSYMBOL_TYPE (msymbol
) == ourtype2
||
3050 MSYMBOL_TYPE (msymbol
) == ourtype3
||
3051 MSYMBOL_TYPE (msymbol
) == ourtype4
)
3053 if (regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (msymbol
))
3055 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
)))
3057 if (kind
== FUNCTIONS_NAMESPACE
3058 || lookup_symbol (SYMBOL_NAME (msymbol
),
3059 (struct block
*) NULL
,
3061 0, (struct symtab
**) NULL
) == NULL
)
3069 ALL_SYMTABS (objfile
, s
)
3071 bv
= BLOCKVECTOR (s
);
3072 /* Often many files share a blockvector.
3073 Scan each blockvector only once so that
3074 we don't get every symbol many times.
3075 It happens that the first symtab in the list
3076 for any given blockvector is the main file. */
3078 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
3080 b
= BLOCKVECTOR_BLOCK (bv
, i
);
3081 /* Skip the sort if this block is always sorted. */
3082 if (!BLOCK_SHOULD_SORT (b
))
3083 sort_block_syms (b
);
3084 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
3087 sym
= BLOCK_SYM (b
, j
);
3088 if (file_matches (s
->filename
, files
, nfiles
)
3089 && ((regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (sym
))
3090 && ((kind
== VARIABLES_NAMESPACE
&& SYMBOL_CLASS (sym
) != LOC_TYPEDEF
3091 && SYMBOL_CLASS (sym
) != LOC_BLOCK
3092 && SYMBOL_CLASS (sym
) != LOC_CONST
)
3093 || (kind
== FUNCTIONS_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3094 || (kind
== TYPES_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3095 || (kind
== METHODS_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
))))
3098 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
3102 psr
->msymbol
= NULL
;
3107 old_chain
= make_cleanup (free_search_symbols
, sr
);
3118 /* If there are no eyes, avoid all contact. I mean, if there are
3119 no debug symbols, then print directly from the msymbol_vector. */
3121 if (found_misc
|| kind
!= FUNCTIONS_NAMESPACE
)
3123 ALL_MSYMBOLS (objfile
, msymbol
)
3125 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
3126 MSYMBOL_TYPE (msymbol
) == ourtype2
||
3127 MSYMBOL_TYPE (msymbol
) == ourtype3
||
3128 MSYMBOL_TYPE (msymbol
) == ourtype4
)
3130 if (regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (msymbol
))
3132 /* Functions: Look up by address. */
3133 if (kind
!= FUNCTIONS_NAMESPACE
||
3134 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
))))
3136 /* Variables/Absolutes: Look up by name */
3137 if (lookup_symbol (SYMBOL_NAME (msymbol
),
3138 (struct block
*) NULL
, VAR_NAMESPACE
,
3139 0, (struct symtab
**) NULL
) == NULL
)
3142 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
3144 psr
->msymbol
= msymbol
;
3151 old_chain
= make_cleanup (free_search_symbols
, &sr
);
3165 discard_cleanups (old_chain
);
3168 /* Helper function for symtab_symbol_info, this function uses
3169 the data returned from search_symbols() to print information
3170 regarding the match to gdb_stdout.
3173 print_symbol_info (kind
, s
, sym
, block
, last
)
3174 namespace_enum kind
;
3180 if (last
== NULL
|| strcmp (last
, s
->filename
) != 0)
3182 fputs_filtered ("\nFile ", gdb_stdout
);
3183 fputs_filtered (s
->filename
, gdb_stdout
);
3184 fputs_filtered (":\n", gdb_stdout
);
3187 if (kind
!= TYPES_NAMESPACE
&& block
== STATIC_BLOCK
)
3188 printf_filtered ("static ");
3190 /* Typedef that is not a C++ class */
3191 if (kind
== TYPES_NAMESPACE
3192 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
3193 c_typedef_print (SYMBOL_TYPE(sym
), sym
, gdb_stdout
);
3194 /* variable, func, or typedef-that-is-c++-class */
3195 else if (kind
< TYPES_NAMESPACE
||
3196 (kind
== TYPES_NAMESPACE
&&
3197 SYMBOL_NAMESPACE(sym
) == STRUCT_NAMESPACE
))
3199 type_print (SYMBOL_TYPE (sym
),
3200 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3201 ? "" : SYMBOL_SOURCE_NAME (sym
)),
3204 printf_filtered (";\n");
3209 /* Tiemann says: "info methods was never implemented." */
3210 char *demangled_name
;
3211 c_type_print_base (TYPE_FN_FIELD_TYPE(t
, block
),
3213 c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t
, block
),
3215 if (TYPE_FN_FIELD_STUB (t
, block
))
3216 check_stub_method (TYPE_DOMAIN_TYPE (type
), j
, block
);
3218 cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t
, block
),
3219 DMGL_ANSI
| DMGL_PARAMS
);
3220 if (demangled_name
== NULL
)
3221 fprintf_filtered (stream
, "<badly mangled name %s>",
3222 TYPE_FN_FIELD_PHYSNAME (t
, block
));
3225 fputs_filtered (demangled_name
, stream
);
3226 free (demangled_name
);
3232 /* This help function for symtab_symbol_info() prints information
3233 for non-debugging symbols to gdb_stdout.
3236 print_msymbol_info (msymbol
)
3237 struct minimal_symbol
*msymbol
;
3239 printf_filtered (" %08lx %s\n",
3240 (unsigned long) SYMBOL_VALUE_ADDRESS (msymbol
),
3241 SYMBOL_SOURCE_NAME (msymbol
));
3244 /* This is the guts of the commands "info functions", "info types", and
3245 "info variables". It calls search_symbols to find all matches and then
3246 print_[m]symbol_info to print out some useful information about the
3250 symtab_symbol_info (regexp
, kind
, from_tty
)
3252 namespace_enum kind
;
3255 static char *classnames
[]
3256 = {"variable", "function", "type", "method"};
3257 struct symbol_search
*symbols
;
3258 struct symbol_search
*p
;
3259 struct cleanup
*old_chain
;
3260 char *last_filename
= NULL
;
3263 /* must make sure that if we're interrupted, symbols gets freed */
3264 search_symbols (regexp
, kind
, 0, (char **) NULL
, &symbols
);
3265 old_chain
= make_cleanup (free_search_symbols
, symbols
);
3267 printf_filtered (regexp
3268 ? "All %ss matching regular expression \"%s\":\n"
3269 : "All defined %ss:\n",
3270 classnames
[(int) (kind
- LABEL_NAMESPACE
- 1)], regexp
);
3272 for (p
= symbols
; p
!= NULL
; p
= p
->next
)
3276 if (p
->msymbol
!= NULL
)
3280 printf_filtered ("\nNon-debugging symbols:\n");
3283 print_msymbol_info (p
->msymbol
);
3287 print_symbol_info (kind
,
3292 last_filename
= p
->symtab
->filename
;
3296 do_cleanups (old_chain
);
3300 variables_info (regexp
, from_tty
)
3304 symtab_symbol_info (regexp
, VARIABLES_NAMESPACE
, from_tty
);
3308 functions_info (regexp
, from_tty
)
3312 symtab_symbol_info (regexp
, FUNCTIONS_NAMESPACE
, from_tty
);
3316 types_info (regexp
, from_tty
)
3320 symtab_symbol_info (regexp
, TYPES_NAMESPACE
, from_tty
);
3324 /* Tiemann says: "info methods was never implemented." */
3326 methods_info (regexp
)
3329 symtab_symbol_info (regexp
, METHODS_NAMESPACE
, 0, from_tty
);
3333 /* Breakpoint all functions matching regular expression. */
3335 rbreak_command (regexp
, from_tty
)
3339 struct symbol_search
*ss
;
3340 struct symbol_search
*p
;
3341 struct cleanup
*old_chain
;
3343 search_symbols (regexp
, FUNCTIONS_NAMESPACE
, 0, (char **) NULL
, &ss
);
3344 old_chain
= make_cleanup (free_search_symbols
, ss
);
3346 for (p
= ss
; p
!= NULL
; p
= p
->next
)
3348 if (p
->msymbol
== NULL
)
3350 char *string
= (char *) alloca (strlen (p
->symtab
->filename
)
3351 + strlen (SYMBOL_NAME (p
->symbol
))
3353 strcpy (string
, p
->symtab
->filename
);
3354 strcat (string
, ":'");
3355 strcat (string
, SYMBOL_NAME (p
->symbol
));
3356 strcat (string
, "'");
3357 break_command (string
, from_tty
);
3358 print_symbol_info (FUNCTIONS_NAMESPACE
,
3362 p
->symtab
->filename
);
3366 break_command (SYMBOL_NAME (p
->msymbol
), from_tty
);
3367 printf_filtered ("<function, no debug info> %s;\n",
3368 SYMBOL_SOURCE_NAME (p
->msymbol
));
3372 do_cleanups (old_chain
);
3376 /* Return Nonzero if block a is lexically nested within block b,
3377 or if a and b have the same pc range.
3378 Return zero otherwise. */
3381 struct block
*a
, *b
;
3385 return BLOCK_START (a
) >= BLOCK_START (b
)
3386 && BLOCK_END (a
) <= BLOCK_END (b
);
3390 /* Helper routine for make_symbol_completion_list. */
3392 static int return_val_size
;
3393 static int return_val_index
;
3394 static char **return_val
;
3396 #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
3398 if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \
3399 /* Put only the mangled name on the list. */ \
3400 /* Advantage: "b foo<TAB>" completes to "b foo(int, int)" */ \
3401 /* Disadvantage: "b foo__i<TAB>" doesn't complete. */ \
3402 completion_list_add_name \
3403 (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \
3405 completion_list_add_name \
3406 (SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \
3409 /* Test to see if the symbol specified by SYMNAME (which is already
3410 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3411 characters. If so, add it to the current completion list. */
3414 completion_list_add_name (symname
, sym_text
, sym_text_len
, text
, word
)
3424 /* clip symbols that cannot match */
3426 if (strncmp (symname
, sym_text
, sym_text_len
) != 0)
3431 /* Clip any symbol names that we've already considered. (This is a
3432 time optimization) */
3434 for (i
= 0; i
< return_val_index
; ++i
)
3436 if (STREQ (symname
, return_val
[i
]))
3442 /* We have a match for a completion, so add SYMNAME to the current list
3443 of matches. Note that the name is moved to freshly malloc'd space. */
3447 if (word
== sym_text
)
3449 new = xmalloc (strlen (symname
) + 5);
3450 strcpy (new, symname
);
3452 else if (word
> sym_text
)
3454 /* Return some portion of symname. */
3455 new = xmalloc (strlen (symname
) + 5);
3456 strcpy (new, symname
+ (word
- sym_text
));
3460 /* Return some of SYM_TEXT plus symname. */
3461 new = xmalloc (strlen (symname
) + (sym_text
- word
) + 5);
3462 strncpy (new, word
, sym_text
- word
);
3463 new[sym_text
- word
] = '\0';
3464 strcat (new, symname
);
3467 /* Recheck for duplicates if we intend to add a modified symbol. */
3468 if (word
!= sym_text
)
3470 for (i
= 0; i
< return_val_index
; ++i
)
3472 if (STREQ (new, return_val
[i
]))
3480 if (return_val_index
+ 3 > return_val_size
)
3482 newsize
= (return_val_size
*= 2) * sizeof (char *);
3483 return_val
= (char **) xrealloc ((char *) return_val
, newsize
);
3485 return_val
[return_val_index
++] = new;
3486 return_val
[return_val_index
] = NULL
;
3490 /* Return a NULL terminated array of all symbols (regardless of class) which
3491 begin by matching TEXT. If the answer is no symbols, then the return value
3492 is an array which contains only a NULL pointer.
3494 Problem: All of the symbols have to be copied because readline frees them.
3495 I'm not going to worry about this; hopefully there won't be that many. */
3498 make_symbol_completion_list (text
, word
)
3502 register struct symbol
*sym
;
3503 register struct symtab
*s
;
3504 register struct partial_symtab
*ps
;
3505 register struct minimal_symbol
*msymbol
;
3506 register struct objfile
*objfile
;
3507 register struct block
*b
, *surrounding_static_block
= 0;
3509 struct partial_symbol
**psym
;
3510 /* The symbol we are completing on. Points in same buffer as text. */
3512 /* Length of sym_text. */
3515 /* Now look for the symbol we are supposed to complete on.
3516 FIXME: This should be language-specific. */
3520 char *quote_pos
= NULL
;
3522 /* First see if this is a quoted string. */
3524 for (p
= text
; *p
!= '\0'; ++p
)
3526 if (quote_found
!= '\0')
3528 if (*p
== quote_found
)
3529 /* Found close quote. */
3531 else if (*p
== '\\' && p
[1] == quote_found
)
3532 /* A backslash followed by the quote character
3533 doesn't end the string. */
3536 else if (*p
== '\'' || *p
== '"')
3542 if (quote_found
== '\'')
3543 /* A string within single quotes can be a symbol, so complete on it. */
3544 sym_text
= quote_pos
+ 1;
3545 else if (quote_found
== '"')
3546 /* A double-quoted string is never a symbol, nor does it make sense
3547 to complete it any other way. */
3551 /* It is not a quoted string. Break it based on the characters
3552 which are in symbols. */
3555 if (isalnum (p
[-1]) || p
[-1] == '_' || p
[-1] == '\0')
3564 sym_text_len
= strlen (sym_text
);
3566 return_val_size
= 100;
3567 return_val_index
= 0;
3568 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
3569 return_val
[0] = NULL
;
3571 /* Look through the partial symtabs for all symbols which begin
3572 by matching SYM_TEXT. Add each one that you find to the list. */
3574 ALL_PSYMTABS (objfile
, ps
)
3576 /* If the psymtab's been read in we'll get it when we search
3577 through the blockvector. */
3578 if (ps
->readin
) continue;
3580 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
3581 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
3582 + ps
->n_global_syms
);
3585 /* If interrupted, then quit. */
3587 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3590 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
3591 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
3592 + ps
->n_static_syms
);
3596 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3600 /* At this point scan through the misc symbol vectors and add each
3601 symbol you find to the list. Eventually we want to ignore
3602 anything that isn't a text symbol (everything else will be
3603 handled by the psymtab code above). */
3605 ALL_MSYMBOLS (objfile
, msymbol
)
3608 COMPLETION_LIST_ADD_SYMBOL (msymbol
, sym_text
, sym_text_len
, text
, word
);
3611 /* Search upwards from currently selected frame (so that we can
3612 complete on local vars. */
3614 for (b
= get_selected_block (); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
3616 if (!BLOCK_SUPERBLOCK (b
))
3618 surrounding_static_block
= b
; /* For elmin of dups */
3621 /* Also catch fields of types defined in this places which match our
3622 text string. Only complete on types visible from current context. */
3624 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3626 sym
= BLOCK_SYM (b
, i
);
3627 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3628 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3630 struct type
*t
= SYMBOL_TYPE (sym
);
3631 enum type_code c
= TYPE_CODE (t
);
3633 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
3635 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
3637 if (TYPE_FIELD_NAME (t
, j
))
3639 completion_list_add_name (TYPE_FIELD_NAME (t
, j
),
3640 sym_text
, sym_text_len
, text
, word
);
3648 /* Go through the symtabs and check the externs and statics for
3649 symbols which match. */
3651 ALL_SYMTABS (objfile
, s
)
3654 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3655 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3657 sym
= BLOCK_SYM (b
, i
);
3658 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3662 ALL_SYMTABS (objfile
, s
)
3665 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3666 /* Don't do this block twice. */
3667 if (b
== surrounding_static_block
) continue;
3668 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3670 sym
= BLOCK_SYM (b
, i
);
3671 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3675 return (return_val
);
3678 /* Determine if PC is in the prologue of a function. The prologue is the area
3679 between the first instruction of a function, and the first executable line.
3680 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
3682 If non-zero, func_start is where we think the prologue starts, possibly
3683 by previous examination of symbol table information.
3687 in_prologue (pc
, func_start
)
3689 CORE_ADDR func_start
;
3691 struct symtab_and_line sal
;
3692 CORE_ADDR func_addr
, func_end
;
3694 if (!find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
3695 goto nosyms
; /* Might be in prologue */
3697 sal
= find_pc_line (func_addr
, 0);
3702 if (sal
.end
> func_addr
3703 && sal
.end
<= func_end
) /* Is prologue in function? */
3704 return pc
< sal
.end
; /* Yes, is pc in prologue? */
3706 /* The line after the prologue seems to be outside the function. In this
3707 case, tell the caller to find the prologue the hard way. */
3711 /* Come here when symtabs don't contain line # info. In this case, it is
3712 likely that the user has stepped into a library function w/o symbols, or
3713 is doing a stepi/nexti through code without symbols. */
3717 /* If func_start is zero (meaning unknown) then we don't know whether pc is
3718 in the prologue or not. I.E. it might be. */
3720 if (!func_start
) return 1;
3722 /* We need to call the target-specific prologue skipping functions with the
3723 function's start address because PC may be pointing at an instruction that
3724 could be mistakenly considered part of the prologue. */
3726 SKIP_PROLOGUE (func_start
);
3728 return pc
< func_start
;
3733 _initialize_symtab ()
3735 add_info ("variables", variables_info
,
3736 "All global and static variable names, or those matching REGEXP.");
3737 add_info ("functions", functions_info
,
3738 "All function names, or those matching REGEXP.");
3740 /* FIXME: This command has at least the following problems:
3741 1. It prints builtin types (in a very strange and confusing fashion).
3742 2. It doesn't print right, e.g. with
3743 typedef struct foo *FOO
3744 type_print prints "FOO" when we want to make it (in this situation)
3745 print "struct foo *".
3746 I also think "ptype" or "whatis" is more likely to be useful (but if
3747 there is much disagreement "info types" can be fixed). */
3748 add_info ("types", types_info
,
3749 "All type names, or those matching REGEXP.");
3752 add_info ("methods", methods_info
,
3753 "All method names, or those matching REGEXP::REGEXP.\n\
3754 If the class qualifier is omitted, it is assumed to be the current scope.\n\
3755 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
3758 add_info ("sources", sources_info
,
3759 "Source files in the program.");
3761 add_com ("rbreak", class_breakpoint
, rbreak_command
,
3762 "Set a breakpoint for all functions matching REGEXP.");
3764 /* Initialize the one built-in type that isn't language dependent... */
3765 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
3766 "<unknown type>", (struct objfile
*) NULL
);