1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 1998
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 */
48 static int find_methods
PARAMS ((struct type
*, char *, struct symbol
**));
50 static void completion_list_add_name
PARAMS ((char *, char *, int, char *,
53 static void build_canonical_line_spec
PARAMS ((struct symtab_and_line
*,
56 static struct symtabs_and_lines decode_line_2
PARAMS ((struct symbol
*[],
59 static void rbreak_command
PARAMS ((char *, int));
61 static void types_info
PARAMS ((char *, int));
63 static void functions_info
PARAMS ((char *, int));
65 static void variables_info
PARAMS ((char *, int));
67 static void sources_info
PARAMS ((char *, int));
69 static void output_source_filename
PARAMS ((char *, int *));
71 char *operator_chars
PARAMS ((char *, char **));
73 static int find_line_common
PARAMS ((struct linetable
*, int, int *));
75 static struct partial_symbol
*lookup_partial_symbol PARAMS
76 ((struct partial_symtab
*, const char *,
77 int, namespace_enum
));
79 static struct partial_symbol
*fixup_psymbol_section
PARAMS ((struct
80 partial_symbol
*, struct objfile
*));
82 static struct symtab
*lookup_symtab_1
PARAMS ((char *));
84 static void cplusplus_hint
PARAMS ((char *));
86 static struct symbol
*find_active_alias
PARAMS ((struct symbol
*sym
,
89 /* This flag is used in hppa-tdep.c, and set in hp-symtab-read.c */
90 /* Signals the presence of objects compiled by HP compilers */
91 int hp_som_som_object_present
= 0;
93 static void fixup_section
PARAMS ((struct general_symbol_info
*,
96 static int file_matches
PARAMS ((char *, char **, int));
98 static void print_symbol_info
PARAMS ((namespace_enum
,
99 struct symtab
*, struct symbol
*,
102 static void print_msymbol_info
PARAMS ((struct minimal_symbol
*));
104 static void symtab_symbol_info
PARAMS ((char *, namespace_enum
, int));
106 void _initialize_symtab
PARAMS ((void));
110 /* The single non-language-specific builtin type */
111 struct type
*builtin_type_error
;
113 /* Block in which the most recently searched-for symbol was found.
114 Might be better to make this a parameter to lookup_symbol and
117 const struct block
*block_found
;
119 char no_symtab_msg
[] = "No symbol table is loaded. Use the \"file\" command.";
121 /* While the C++ support is still in flux, issue a possibly helpful hint on
122 using the new command completion feature on single quoted demangled C++
123 symbols. Remove when loose ends are cleaned up. FIXME -fnf */
126 cplusplus_hint (name
)
129 while (*name
== '\'')
131 printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name
, name
);
132 printf_filtered ("(Note leading single quote.)\n");
135 /* Check for a symtab of a specific name; first in symtabs, then in
136 psymtabs. *If* there is no '/' in the name, a match after a '/'
137 in the symtab filename will also work. */
139 static struct symtab
*
140 lookup_symtab_1 (name
)
143 register struct symtab
*s
;
144 register struct partial_symtab
*ps
;
145 register char *slash
;
146 register struct objfile
*objfile
;
150 /* First, search for an exact match */
152 ALL_SYMTABS (objfile
, s
)
153 if (STREQ (name
, s
->filename
))
156 slash
= strchr (name
, '/');
158 /* Now, search for a matching tail (only if name doesn't have any dirs) */
161 ALL_SYMTABS (objfile
, s
)
163 char *p
= s
-> filename
;
164 char *tail
= strrchr (p
, '/');
173 /* Same search rules as above apply here, but now we look thru the
176 ps
= lookup_partial_symtab (name
);
181 error ("Internal: readin %s pst for `%s' found when no symtab found.",
182 ps
-> filename
, name
);
184 s
= PSYMTAB_TO_SYMTAB (ps
);
189 /* At this point, we have located the psymtab for this file, but
190 the conversion to a symtab has failed. This usually happens
191 when we are looking up an include file. In this case,
192 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
193 been created. So, we need to run through the symtabs again in
194 order to find the file.
195 XXX - This is a crock, and should be fixed inside of the the
196 symbol parsing routines. */
200 /* Lookup the symbol table of a source file named NAME. Try a couple
201 of variations if the first lookup doesn't work. */
207 register struct symtab
*s
;
212 s
= lookup_symtab_1 (name
);
216 /* This screws c-exp.y:yylex if there is both a type "tree" and a symtab
219 /* If name not found as specified, see if adding ".c" helps. */
220 /* Why is this? Is it just a user convenience? (If so, it's pretty
221 questionable in the presence of C++, FORTRAN, etc.). It's not in
224 copy
= (char *) alloca (strlen (name
) + 3);
227 s
= lookup_symtab_1 (copy
);
231 /* We didn't find anything; die. */
235 /* Lookup the partial symbol table of a source file named NAME.
236 *If* there is no '/' in the name, a match after a '/'
237 in the psymtab filename will also work. */
239 struct partial_symtab
*
240 lookup_partial_symtab (name
)
243 register struct partial_symtab
*pst
;
244 register struct objfile
*objfile
;
246 ALL_PSYMTABS (objfile
, pst
)
248 if (STREQ (name
, pst
-> filename
))
254 /* Now, search for a matching tail (only if name doesn't have any dirs) */
256 if (!strchr (name
, '/'))
257 ALL_PSYMTABS (objfile
, pst
)
259 char *p
= pst
-> filename
;
260 char *tail
= strrchr (p
, '/');
272 /* Mangle a GDB method stub type. This actually reassembles the pieces of the
273 full method name, which consist of the class name (from T), the unadorned
274 method name from METHOD_ID, and the signature for the specific overload,
275 specified by SIGNATURE_ID. Note that this function is g++ specific. */
278 gdb_mangle_name (type
, method_id
, signature_id
)
280 int method_id
, signature_id
;
282 int mangled_name_len
;
284 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
285 struct fn_field
*method
= &f
[signature_id
];
286 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, method_id
);
287 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, signature_id
);
288 char *newname
= type_name_no_tag (type
);
290 /* Does the form of physname indicate that it is the full mangled name
291 of a constructor (not just the args)? */
292 int is_full_physname_constructor
;
295 int is_destructor
= DESTRUCTOR_PREFIX_P (physname
);
296 /* Need a new type prefix. */
297 char *const_prefix
= method
->is_const
? "C" : "";
298 char *volatile_prefix
= method
->is_volatile
? "V" : "";
300 int len
= (newname
== NULL
? 0 : strlen (newname
));
302 is_full_physname_constructor
=
303 ((physname
[0]=='_' && physname
[1]=='_' &&
304 (isdigit(physname
[2]) || physname
[2]=='Q' || physname
[2]=='t'))
305 || (strncmp(physname
, "__ct", 4) == 0));
308 is_full_physname_constructor
|| (newname
&& STREQ(field_name
, newname
));
311 is_destructor
= (strncmp(physname
, "__dt", 4) == 0);
313 if (is_destructor
|| is_full_physname_constructor
)
315 mangled_name
= (char*) xmalloc(strlen(physname
)+1);
316 strcpy(mangled_name
, physname
);
322 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
324 else if (physname
[0] == 't' || physname
[0] == 'Q')
326 /* The physname for template and qualified methods already includes
328 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
334 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
336 mangled_name_len
= ((is_constructor
? 0 : strlen (field_name
))
341 /* Only needed for GNU-mangled names. ANSI-mangled names
342 work with the normal mechanisms. */
343 if (OPNAME_PREFIX_P (field_name
))
345 const char *opname
= cplus_mangle_opname (field_name
+ 3, 0);
347 error ("No mangling for \"%s\"", field_name
);
348 mangled_name_len
+= strlen (opname
);
349 mangled_name
= (char *)xmalloc (mangled_name_len
);
351 strncpy (mangled_name
, field_name
, 3);
352 mangled_name
[3] = '\0';
353 strcat (mangled_name
, opname
);
357 mangled_name
= (char *)xmalloc (mangled_name_len
);
359 mangled_name
[0] = '\0';
361 strcpy (mangled_name
, field_name
);
363 strcat (mangled_name
, buf
);
364 /* If the class doesn't have a name, i.e. newname NULL, then we just
365 mangle it using 0 for the length of the class. Thus it gets mangled
366 as something starting with `::' rather than `classname::'. */
368 strcat (mangled_name
, newname
);
370 strcat (mangled_name
, physname
);
371 return (mangled_name
);
376 /* Find which partial symtab on contains PC and SECTION. Return 0 if none. */
378 struct partial_symtab
*
379 find_pc_sect_psymtab (pc
, section
)
383 register struct partial_symtab
*pst
;
384 register struct objfile
*objfile
;
386 ALL_PSYMTABS (objfile
, pst
)
388 if (pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
390 struct minimal_symbol
*msymbol
;
391 struct partial_symtab
*tpst
;
393 /* An objfile that has its functions reordered might have
394 many partial symbol tables containing the PC, but
395 we want the partial symbol table that contains the
396 function containing the PC. */
397 if (!(objfile
->flags
& OBJF_REORDERED
) &&
398 section
== 0) /* can't validate section this way */
401 msymbol
= lookup_minimal_symbol_by_pc_section (pc
, section
);
405 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
407 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
409 struct partial_symbol
*p
;
411 p
= find_pc_sect_psymbol (tpst
, pc
, section
);
413 && SYMBOL_VALUE_ADDRESS(p
)
414 == SYMBOL_VALUE_ADDRESS (msymbol
))
424 /* Find which partial symtab contains PC. Return 0 if none.
425 Backward compatibility, no section */
427 struct partial_symtab
*
431 return find_pc_sect_psymtab (pc
, find_pc_mapped_section (pc
));
434 /* Find which partial symbol within a psymtab matches PC and SECTION.
435 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
437 struct partial_symbol
*
438 find_pc_sect_psymbol (psymtab
, pc
, section
)
439 struct partial_symtab
*psymtab
;
443 struct partial_symbol
*best
= NULL
, *p
, **pp
;
447 psymtab
= find_pc_sect_psymtab (pc
, section
);
451 /* Cope with programs that start at address 0 */
452 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
454 /* Search the global symbols as well as the static symbols, so that
455 find_pc_partial_function doesn't use a minimal symbol and thus
456 cache a bad endaddr. */
457 for (pp
= psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
458 (pp
- (psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
459 < psymtab
->n_global_syms
);
463 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
464 && SYMBOL_CLASS (p
) == LOC_BLOCK
465 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
466 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
467 || (psymtab
->textlow
== 0
468 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
470 if (section
) /* match on a specific section */
472 fixup_psymbol_section (p
, psymtab
->objfile
);
473 if (SYMBOL_BFD_SECTION (p
) != section
)
476 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
481 for (pp
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
482 (pp
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
483 < psymtab
->n_static_syms
);
487 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
488 && SYMBOL_CLASS (p
) == LOC_BLOCK
489 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
490 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
491 || (psymtab
->textlow
== 0
492 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
494 if (section
) /* match on a specific section */
496 fixup_psymbol_section (p
, psymtab
->objfile
);
497 if (SYMBOL_BFD_SECTION (p
) != section
)
500 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
508 /* Find which partial symbol within a psymtab matches PC. Return 0 if none.
509 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
511 struct partial_symbol
*
512 find_pc_psymbol (psymtab
, pc
)
513 struct partial_symtab
*psymtab
;
516 return find_pc_sect_psymbol (psymtab
, pc
, find_pc_mapped_section (pc
));
519 /* Debug symbols usually don't have section information. We need to dig that
520 out of the minimal symbols and stash that in the debug symbol. */
523 fixup_section (ginfo
, objfile
)
524 struct general_symbol_info
*ginfo
;
525 struct objfile
*objfile
;
527 struct minimal_symbol
*msym
;
528 msym
= lookup_minimal_symbol (ginfo
->name
, NULL
, objfile
);
531 ginfo
->bfd_section
= SYMBOL_BFD_SECTION (msym
);
535 fixup_symbol_section (sym
, objfile
)
537 struct objfile
*objfile
;
542 if (SYMBOL_BFD_SECTION (sym
))
545 fixup_section (&sym
->ginfo
, objfile
);
550 static struct partial_symbol
*
551 fixup_psymbol_section (psym
, objfile
)
552 struct partial_symbol
*psym
;
553 struct objfile
*objfile
;
558 if (SYMBOL_BFD_SECTION (psym
))
561 fixup_section (&psym
->ginfo
, objfile
);
566 /* Find the definition for a specified symbol name NAME
567 in namespace NAMESPACE, visible from lexical block BLOCK.
568 Returns the struct symbol pointer, or zero if no symbol is found.
569 If SYMTAB is non-NULL, store the symbol table in which the
570 symbol was found there, or NULL if not found.
571 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
572 NAME is a field of the current implied argument `this'. If so set
573 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
574 BLOCK_FOUND is set to the block in which NAME is found (in the case of
575 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
577 /* This function has a bunch of loops in it and it would seem to be
578 attractive to put in some QUIT's (though I'm not really sure
579 whether it can run long enough to be really important). But there
580 are a few calls for which it would appear to be bad news to quit
581 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and
582 nindy_frame_chain_valid in nindy-tdep.c. (Note that there is C++
583 code below which can error(), but that probably doesn't affect
584 these calls since they are looking for a known variable and thus
585 can probably assume it will never hit the C++ code). */
588 lookup_symbol (name
, block
, namespace, is_a_field_of_this
, symtab
)
590 register const struct block
*block
;
591 const namespace_enum
namespace;
592 int *is_a_field_of_this
;
593 struct symtab
**symtab
;
595 register struct symbol
*sym
;
596 register struct symtab
*s
= NULL
;
597 register struct partial_symtab
*ps
;
598 struct blockvector
*bv
;
599 register struct objfile
*objfile
= NULL
;
600 register struct block
*b
;
601 register struct minimal_symbol
*msymbol
;
603 /* Search specified block and its superiors. */
607 sym
= lookup_block_symbol (block
, name
, namespace);
613 /* Search the list of symtabs for one which contains the
614 address of the start of this block. */
615 ALL_SYMTABS (objfile
, s
)
617 bv
= BLOCKVECTOR (s
);
618 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
619 if (BLOCK_START (b
) <= BLOCK_START (block
)
620 && BLOCK_END (b
) > BLOCK_START (block
))
627 return fixup_symbol_section (sym
, objfile
);
629 block
= BLOCK_SUPERBLOCK (block
);
632 /* FIXME: this code is never executed--block is always NULL at this
633 point. What is it trying to do, anyway? We already should have
634 checked the STATIC_BLOCK above (it is the superblock of top-level
635 blocks). Why is VAR_NAMESPACE special-cased? */
636 /* Don't need to mess with the psymtabs; if we have a block,
637 that file is read in. If we don't, then we deal later with
638 all the psymtab stuff that needs checking. */
639 if (namespace == VAR_NAMESPACE
&& block
!= NULL
)
642 /* Find the right symtab. */
643 ALL_SYMTABS (objfile
, s
)
645 bv
= BLOCKVECTOR (s
);
646 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
647 if (BLOCK_START (b
) <= BLOCK_START (block
)
648 && BLOCK_END (b
) > BLOCK_START (block
))
650 sym
= lookup_block_symbol (b
, name
, VAR_NAMESPACE
);
656 return fixup_symbol_section (sym
, objfile
);
663 /* C++: If requested to do so by the caller,
664 check to see if NAME is a field of `this'. */
665 if (is_a_field_of_this
)
667 struct value
*v
= value_of_this (0);
669 *is_a_field_of_this
= 0;
670 if (v
&& check_field (v
, name
))
672 *is_a_field_of_this
= 1;
679 /* Now search all global blocks. Do the symtab's first, then
680 check the psymtab's */
682 ALL_SYMTABS (objfile
, s
)
684 bv
= BLOCKVECTOR (s
);
685 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
686 sym
= lookup_block_symbol (block
, name
, namespace);
692 return fixup_symbol_section (sym
, objfile
);
696 /* Check for the possibility of the symbol being a function or
697 a mangled variable that is stored in one of the minimal symbol tables.
698 Eventually, all global symbols might be resolved in this way. */
700 if (namespace == VAR_NAMESPACE
)
702 msymbol
= lookup_minimal_symbol (name
, NULL
, NULL
);
705 s
= find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol
),
706 SYMBOL_BFD_SECTION (msymbol
));
709 /* This is a function which has a symtab for its address. */
710 bv
= BLOCKVECTOR (s
);
711 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
712 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
714 /* We kept static functions in minimal symbol table as well as
715 in static scope. We want to find them in the symbol table. */
717 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
718 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
722 /* sym == 0 if symbol was found in the minimal symbol table
723 but not in the symtab.
724 Return 0 to use the msymbol definition of "foo_".
726 This happens for Fortran "foo_" symbols,
727 which are "foo" in the symtab.
729 This can also happen if "asm" is used to make a
730 regular symbol but not a debugging symbol, e.g.
737 return fixup_symbol_section (sym
, objfile
);
739 else if (MSYMBOL_TYPE (msymbol
) != mst_text
740 && MSYMBOL_TYPE (msymbol
) != mst_file_text
741 && !STREQ (name
, SYMBOL_NAME (msymbol
)))
743 /* This is a mangled variable, look it up by its
745 return lookup_symbol (SYMBOL_NAME (msymbol
), block
,
746 namespace, is_a_field_of_this
, symtab
);
748 /* There are no debug symbols for this file, or we are looking
749 for an unmangled variable.
750 Try to find a matching static symbol below. */
754 ALL_PSYMTABS (objfile
, ps
)
756 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
758 s
= PSYMTAB_TO_SYMTAB(ps
);
759 bv
= BLOCKVECTOR (s
);
760 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
761 sym
= lookup_block_symbol (block
, name
, namespace);
763 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab", name
, ps
->filename
);
766 return fixup_symbol_section (sym
, objfile
);
770 /* Now search all per-file blocks.
771 Not strictly correct, but more useful than an error.
772 Do the symtabs first, then check the psymtabs */
774 ALL_SYMTABS (objfile
, s
)
776 bv
= BLOCKVECTOR (s
);
777 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
778 sym
= lookup_block_symbol (block
, name
, namespace);
784 return fixup_symbol_section (sym
, objfile
);
788 ALL_PSYMTABS (objfile
, ps
)
790 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
792 s
= PSYMTAB_TO_SYMTAB(ps
);
793 bv
= BLOCKVECTOR (s
);
794 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
795 sym
= lookup_block_symbol (block
, name
, namespace);
797 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab", name
, ps
->filename
);
800 return fixup_symbol_section (sym
, objfile
);
809 /* Look, in partial_symtab PST, for symbol NAME. Check the global
810 symbols if GLOBAL, the static symbols if not */
812 static struct partial_symbol
*
813 lookup_partial_symbol (pst
, name
, global
, namespace)
814 struct partial_symtab
*pst
;
817 namespace_enum
namespace;
819 struct partial_symbol
**start
, **psym
;
820 struct partial_symbol
**top
, **bottom
, **center
;
821 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
822 int do_linear_search
= 1;
830 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
831 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
833 if (global
) /* This means we can use a binary search. */
835 do_linear_search
= 0;
837 /* Binary search. This search is guaranteed to end with center
838 pointing at the earliest partial symbol with the correct
839 name. At that point *all* partial symbols with that name
840 will be checked against the correct namespace. */
843 top
= start
+ length
- 1;
846 center
= bottom
+ (top
- bottom
) / 2;
849 if (!do_linear_search
850 && (SYMBOL_LANGUAGE (*center
) == language_cplus
851 /* start-sanitize-java */
852 || SYMBOL_LANGUAGE (*center
) == language_java
853 /* end-sanitize-java */
856 do_linear_search
= 1;
858 if (STRCMP (SYMBOL_NAME (*center
), name
) >= 0)
867 if (!(top
== bottom
))
869 while (STREQ (SYMBOL_NAME (*top
), name
))
871 if (SYMBOL_NAMESPACE (*top
) == namespace)
879 /* Can't use a binary search or else we found during the binary search that
880 we should also do a linear search. */
882 if (do_linear_search
)
884 for (psym
= start
; psym
< start
+ length
; psym
++)
886 if (namespace == SYMBOL_NAMESPACE (*psym
))
888 if (SYMBOL_MATCHES_NAME (*psym
, name
))
899 /* Look up a type named NAME in the struct_namespace. The type returned
900 must not be opaque -- i.e., must have at least one field defined
902 This code was modelled on lookup_symbol -- the parts not relevant to looking
903 up types were just left out. In particular it's assumed here that types
904 are available in struct_namespace and only at file-static or global blocks. */
908 lookup_transparent_type (name
)
911 register struct symbol
*sym
;
912 register struct symtab
*s
= NULL
;
913 register struct partial_symtab
*ps
;
914 struct blockvector
*bv
;
915 register struct objfile
*objfile
;
916 register struct block
*block
;
917 register struct minimal_symbol
*msymbol
;
919 /* Now search all the global symbols. Do the symtab's first, then
920 check the psymtab's. If a psymtab indicates the existence
921 of the desired name as a global, then do psymtab-to-symtab
922 conversion on the fly and return the found symbol. */
924 ALL_SYMTABS (objfile
, s
)
926 bv
= BLOCKVECTOR (s
);
927 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
928 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
929 if (sym
&& !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
931 return SYMBOL_TYPE (sym
);
935 ALL_PSYMTABS (objfile
, ps
)
937 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, STRUCT_NAMESPACE
))
939 s
= PSYMTAB_TO_SYMTAB(ps
);
940 bv
= BLOCKVECTOR (s
);
941 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
942 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
945 /* This shouldn't be necessary, but as a last resort
946 * try looking in the statics even though the psymtab
947 * claimed the symbol was global. It's possible that
948 * the psymtab gets it wrong in some cases.
950 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
951 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
953 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
954 %s may be an inlined function, or may be a template function\n\
955 (if a template, try specifying an instantiation: %s<type>).",
956 name
, ps
->filename
, name
, name
);
958 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
959 return SYMBOL_TYPE (sym
);
963 /* Now search the static file-level symbols.
964 Not strictly correct, but more useful than an error.
965 Do the symtab's first, then
966 check the psymtab's. If a psymtab indicates the existence
967 of the desired name as a file-level static, then do psymtab-to-symtab
968 conversion on the fly and return the found symbol.
971 ALL_SYMTABS (objfile
, s
)
973 bv
= BLOCKVECTOR (s
);
974 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
975 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
976 if (sym
&& !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
978 return SYMBOL_TYPE (sym
);
982 ALL_PSYMTABS (objfile
, ps
)
984 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, STRUCT_NAMESPACE
))
986 s
= PSYMTAB_TO_SYMTAB(ps
);
987 bv
= BLOCKVECTOR (s
);
988 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
989 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
992 /* This shouldn't be necessary, but as a last resort
993 * try looking in the globals even though the psymtab
994 * claimed the symbol was static. It's possible that
995 * the psymtab gets it wrong in some cases.
997 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
998 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1000 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
1001 %s may be an inlined function, or may be a template function\n\
1002 (if a template, try specifying an instantiation: %s<type>).",
1003 name
, ps
->filename
, name
, name
);
1005 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1006 return SYMBOL_TYPE (sym
);
1009 return (struct type
*) 0;
1013 /* Find the psymtab containing main(). */
1014 /* FIXME: What about languages without main() or specially linked
1015 executables that have no main() ? */
1017 struct partial_symtab
*
1018 find_main_psymtab ()
1020 register struct partial_symtab
*pst
;
1021 register struct objfile
*objfile
;
1023 ALL_PSYMTABS (objfile
, pst
)
1025 if (lookup_partial_symbol (pst
, "main", 1, VAR_NAMESPACE
))
1033 /* Search BLOCK for symbol NAME in NAMESPACE.
1035 Note that if NAME is the demangled form of a C++ symbol, we will fail
1036 to find a match during the binary search of the non-encoded names, but
1037 for now we don't worry about the slight inefficiency of looking for
1038 a match we'll never find, since it will go pretty quick. Once the
1039 binary search terminates, we drop through and do a straight linear
1040 search on the symbols. Each symbol which is marked as being a C++
1041 symbol (language_cplus set) has both the encoded and non-encoded names
1042 tested for a match. */
1045 lookup_block_symbol (block
, name
, namespace)
1046 register const struct block
*block
;
1048 const namespace_enum
namespace;
1050 register int bot
, top
, inc
;
1051 register struct symbol
*sym
;
1052 register struct symbol
*sym_found
= NULL
;
1053 register int do_linear_search
= 1;
1055 /* If the blocks's symbols were sorted, start with a binary search. */
1057 if (BLOCK_SHOULD_SORT (block
))
1059 /* Reset the linear search flag so if the binary search fails, we
1060 won't do the linear search once unless we find some reason to
1061 do so, such as finding a C++ symbol during the binary search.
1062 Note that for C++ modules, ALL the symbols in a block should
1063 end up marked as C++ symbols. */
1065 do_linear_search
= 0;
1066 top
= BLOCK_NSYMS (block
);
1069 /* Advance BOT to not far before the first symbol whose name is NAME. */
1073 inc
= (top
- bot
+ 1);
1074 /* No need to keep binary searching for the last few bits worth. */
1079 inc
= (inc
>> 1) + bot
;
1080 sym
= BLOCK_SYM (block
, inc
);
1081 if (!do_linear_search
1082 && (SYMBOL_LANGUAGE (sym
) == language_cplus
1083 /* start-sanitize-java */
1084 || SYMBOL_LANGUAGE (sym
) == language_java
1085 /* end-sanitize-java */
1088 do_linear_search
= 1;
1090 if (SYMBOL_NAME (sym
)[0] < name
[0])
1094 else if (SYMBOL_NAME (sym
)[0] > name
[0])
1098 else if (STRCMP (SYMBOL_NAME (sym
), name
) < 0)
1108 /* Now scan forward until we run out of symbols, find one whose
1109 name is greater than NAME, or find one we want. If there is
1110 more than one symbol with the right name and namespace, we
1111 return the first one; I believe it is now impossible for us
1112 to encounter two symbols with the same name and namespace
1113 here, because blocks containing argument symbols are no
1116 top
= BLOCK_NSYMS (block
);
1119 sym
= BLOCK_SYM (block
, bot
);
1120 inc
= SYMBOL_NAME (sym
)[0] - name
[0];
1123 inc
= STRCMP (SYMBOL_NAME (sym
), name
);
1125 if (inc
== 0 && SYMBOL_NAMESPACE (sym
) == namespace)
1137 /* Here if block isn't sorted, or we fail to find a match during the
1138 binary search above. If during the binary search above, we find a
1139 symbol which is a C++ symbol, then we have re-enabled the linear
1140 search flag which was reset when starting the binary search.
1142 This loop is equivalent to the loop above, but hacked greatly for speed.
1144 Note that parameter symbols do not always show up last in the
1145 list; this loop makes sure to take anything else other than
1146 parameter symbols first; it only uses parameter symbols as a
1147 last resort. Note that this only takes up extra computation
1150 if (do_linear_search
)
1152 top
= BLOCK_NSYMS (block
);
1156 sym
= BLOCK_SYM (block
, bot
);
1157 if (SYMBOL_NAMESPACE (sym
) == namespace &&
1158 SYMBOL_MATCHES_NAME (sym
, name
))
1160 /* If SYM has aliases, then use any alias that is active
1161 at the current PC. If no alias is active at the current
1162 PC, then use the main symbol.
1164 ?!? Is checking the current pc correct? Is this routine
1165 ever called to look up a symbol from another context? */
1166 if (SYMBOL_ALIASES (sym
))
1167 sym
= find_active_alias (sym
, read_pc ());
1170 if (SYMBOL_CLASS (sym
) != LOC_ARG
&&
1171 SYMBOL_CLASS (sym
) != LOC_LOCAL_ARG
&&
1172 SYMBOL_CLASS (sym
) != LOC_REF_ARG
&&
1173 SYMBOL_CLASS (sym
) != LOC_REGPARM
&&
1174 SYMBOL_CLASS (sym
) != LOC_REGPARM_ADDR
&&
1175 SYMBOL_CLASS (sym
) != LOC_BASEREG_ARG
)
1183 return (sym_found
); /* Will be NULL if not found. */
1186 /* Given a main symbol SYM and ADDR, search through the alias
1187 list to determine if an alias is active at ADDR and return
1190 If no alias is active, then return SYM. */
1192 static struct symbol
*
1193 find_active_alias (sym
, addr
)
1197 struct range_list
*r
;
1198 struct alias_list
*aliases
;
1200 /* If we have aliases, check them first. */
1201 aliases
= SYMBOL_ALIASES (sym
);
1205 if (!SYMBOL_RANGES (aliases
->sym
))
1206 return aliases
->sym
;
1207 for (r
= SYMBOL_RANGES (aliases
->sym
); r
; r
= r
->next
)
1209 if (r
->start
<= addr
&& r
->end
> addr
)
1210 return aliases
->sym
;
1212 aliases
= aliases
->next
;
1215 /* Nothing found, return the main symbol. */
1220 /* Return the symbol for the function which contains a specified
1221 lexical block, described by a struct block BL. */
1227 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
1228 bl
= BLOCK_SUPERBLOCK (bl
);
1230 return BLOCK_FUNCTION (bl
);
1233 /* Find the symtab associated with PC and SECTION. Look through the
1234 psymtabs and read in another symtab if necessary. */
1237 find_pc_sect_symtab (pc
, section
)
1241 register struct block
*b
;
1242 struct blockvector
*bv
;
1243 register struct symtab
*s
= NULL
;
1244 register struct symtab
*best_s
= NULL
;
1245 register struct partial_symtab
*ps
;
1246 register struct objfile
*objfile
;
1247 CORE_ADDR distance
= 0;
1249 /* Search all symtabs for the one whose file contains our address, and which
1250 is the smallest of all the ones containing the address. This is designed
1251 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1252 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1253 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1255 This happens for native ecoff format, where code from included files
1256 gets its own symtab. The symtab for the included file should have
1257 been read in already via the dependency mechanism.
1258 It might be swifter to create several symtabs with the same name
1259 like xcoff does (I'm not sure).
1261 It also happens for objfiles that have their functions reordered.
1262 For these, the symtab we are looking for is not necessarily read in. */
1264 ALL_SYMTABS (objfile
, s
)
1266 bv
= BLOCKVECTOR (s
);
1267 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1268 if (BLOCK_START (b
) <= pc
1269 && BLOCK_END (b
) > pc
1271 || BLOCK_END (b
) - BLOCK_START (b
) < distance
))
1273 /* For an objfile that has its functions reordered,
1274 find_pc_psymtab will find the proper partial symbol table
1275 and we simply return its corresponding symtab. */
1276 /* In order to better support objfiles that contain both
1277 stabs and coff debugging info, we continue on if a psymtab
1279 if ((objfile
->flags
& OBJF_REORDERED
) && objfile
->psymtabs
)
1281 ps
= find_pc_sect_psymtab (pc
, section
);
1283 return PSYMTAB_TO_SYMTAB (ps
);
1289 for (i
= 0; i
< b
->nsyms
; i
++)
1291 fixup_symbol_section (b
->sym
[i
], objfile
);
1292 if (section
== SYMBOL_BFD_SECTION (b
->sym
[i
]))
1296 continue; /* no symbol in this symtab matches section */
1298 distance
= BLOCK_END (b
) - BLOCK_START (b
);
1307 ps
= find_pc_sect_psymtab (pc
, section
);
1311 /* Might want to error() here (in case symtab is corrupt and
1312 will cause a core dump), but maybe we can successfully
1313 continue, so let's not. */
1314 /* FIXME-32x64: assumes pc fits in a long */
1316 (Internal error: pc 0x%lx in read in psymtab, but not in symtab.)\n",
1317 (unsigned long) pc
);
1318 s
= PSYMTAB_TO_SYMTAB (ps
);
1323 /* Find the symtab associated with PC. Look through the psymtabs and
1324 read in another symtab if necessary. Backward compatibility, no section */
1330 return find_pc_sect_symtab (pc
, find_pc_mapped_section (pc
));
1336 /* Find the closest symbol value (of any sort -- function or variable)
1337 for a given address value. Slow but complete. (currently unused,
1338 mainly because it is too slow. We could fix it if each symtab and
1339 psymtab had contained in it the addresses ranges of each of its
1340 sections, which also would be required to make things like "info
1341 line *0x2345" cause psymtabs to be converted to symtabs). */
1344 find_addr_symbol (addr
, symtabp
, symaddrp
)
1346 struct symtab
**symtabp
;
1347 CORE_ADDR
*symaddrp
;
1349 struct symtab
*symtab
, *best_symtab
;
1350 struct objfile
*objfile
;
1351 register int bot
, top
;
1352 register struct symbol
*sym
;
1353 register CORE_ADDR sym_addr
;
1354 struct block
*block
;
1357 /* Info on best symbol seen so far */
1359 register CORE_ADDR best_sym_addr
= 0;
1360 struct symbol
*best_sym
= 0;
1362 /* FIXME -- we should pull in all the psymtabs, too! */
1363 ALL_SYMTABS (objfile
, symtab
)
1365 /* Search the global and static blocks in this symtab for
1366 the closest symbol-address to the desired address. */
1368 for (blocknum
= GLOBAL_BLOCK
; blocknum
<= STATIC_BLOCK
; blocknum
++)
1371 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab
), blocknum
);
1372 top
= BLOCK_NSYMS (block
);
1373 for (bot
= 0; bot
< top
; bot
++)
1375 sym
= BLOCK_SYM (block
, bot
);
1376 switch (SYMBOL_CLASS (sym
))
1380 sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1384 sym_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1391 if (sym_addr
<= addr
)
1392 if (sym_addr
> best_sym_addr
)
1394 /* Quit if we found an exact match. */
1396 best_sym_addr
= sym_addr
;
1397 best_symtab
= symtab
;
1398 if (sym_addr
== addr
)
1407 *symtabp
= best_symtab
;
1409 *symaddrp
= best_sym_addr
;
1414 /* Find the source file and line number for a given PC value and section.
1415 Return a structure containing a symtab pointer, a line number,
1416 and a pc range for the entire source line.
1417 The value's .pc field is NOT the specified pc.
1418 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1419 use the line that ends there. Otherwise, in that case, the line
1420 that begins there is used. */
1422 /* The big complication here is that a line may start in one file, and end just
1423 before the start of another file. This usually occurs when you #include
1424 code in the middle of a subroutine. To properly find the end of a line's PC
1425 range, we must search all symtabs associated with this compilation unit, and
1426 find the one whose first PC is closer than that of the next line in this
1429 /* If it's worth the effort, we could be using a binary search. */
1431 struct symtab_and_line
1432 find_pc_sect_line (pc
, section
, notcurrent
)
1434 struct sec
*section
;
1438 register struct linetable
*l
;
1441 register struct linetable_entry
*item
;
1442 struct symtab_and_line val
;
1443 struct blockvector
*bv
;
1445 /* Info on best line seen so far, and where it starts, and its file. */
1447 struct linetable_entry
*best
= NULL
;
1448 CORE_ADDR best_end
= 0;
1449 struct symtab
*best_symtab
= 0;
1451 /* Store here the first line number
1452 of a file which contains the line at the smallest pc after PC.
1453 If we don't find a line whose range contains PC,
1454 we will use a line one less than this,
1455 with a range from the start of that file to the first line's pc. */
1456 struct linetable_entry
*alt
= NULL
;
1457 struct symtab
*alt_symtab
= 0;
1459 /* Info on best line seen in this file. */
1461 struct linetable_entry
*prev
;
1463 /* If this pc is not from the current frame,
1464 it is the address of the end of a call instruction.
1465 Quite likely that is the start of the following statement.
1466 But what we want is the statement containing the instruction.
1467 Fudge the pc to make sure we get that. */
1469 INIT_SAL (&val
); /* initialize to zeroes */
1474 s
= find_pc_sect_symtab (pc
, section
);
1477 /* if no symbol information, return previous pc */
1484 bv
= BLOCKVECTOR (s
);
1486 /* Look at all the symtabs that share this blockvector.
1487 They all have the same apriori range, that we found was right;
1488 but they have different line tables. */
1490 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1492 /* Find the best line in this symtab. */
1499 /* I think len can be zero if the symtab lacks line numbers
1500 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
1501 I'm not sure which, and maybe it depends on the symbol
1507 item
= l
->item
; /* Get first line info */
1509 /* Is this file's first line closer than the first lines of other files?
1510 If so, record this file, and its first line, as best alternate. */
1511 if (item
->pc
> pc
&& (!alt
|| item
->pc
< alt
->pc
))
1517 for (i
= 0; i
< len
; i
++, item
++)
1519 /* Leave prev pointing to the linetable entry for the last line
1520 that started at or before PC. */
1527 /* At this point, prev points at the line whose start addr is <= pc, and
1528 item points at the next line. If we ran off the end of the linetable
1529 (pc >= start of the last line), then prev == item. If pc < start of
1530 the first line, prev will not be set. */
1532 /* Is this file's best line closer than the best in the other files?
1533 If so, record this file, and its best line, as best so far. */
1535 if (prev
&& (!best
|| prev
->pc
> best
->pc
))
1539 /* If another line is in the linetable, and its PC is closer
1540 than the best_end we currently have, take it as best_end. */
1541 if (i
< len
&& (best_end
== 0 || best_end
> item
->pc
))
1542 best_end
= item
->pc
;
1549 { /* If we didn't find any line # info, just
1555 val
.symtab
= alt_symtab
;
1556 val
.line
= alt
->line
- 1;
1558 /* Don't return line 0, that means that we didn't find the line. */
1559 if (val
.line
== 0) ++val
.line
;
1561 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1567 val
.symtab
= best_symtab
;
1568 val
.line
= best
->line
;
1570 if (best_end
&& (!alt
|| best_end
< alt
->pc
))
1575 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1577 val
.section
= section
;
1581 /* Backward compatibility (no section) */
1583 struct symtab_and_line
1584 find_pc_line (pc
, notcurrent
)
1590 section
= find_pc_overlay (pc
);
1591 if (pc_in_unmapped_range (pc
, section
))
1592 pc
= overlay_mapped_address (pc
, section
);
1593 return find_pc_sect_line (pc
, section
, notcurrent
);
1597 static struct symtab
* find_line_symtab
PARAMS ((struct symtab
*, int,
1600 /* Find line number LINE in any symtab whose name is the same as
1603 If found, return the symtab that contains the linetable in which it was
1604 found, set *INDEX to the index in the linetable of the best entry
1605 found, and set *EXACT_MATCH nonzero if the value returned is an
1608 If not found, return NULL. */
1610 static struct symtab
*
1611 find_line_symtab (symtab
, line
, index
, exact_match
)
1612 struct symtab
*symtab
;
1619 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
1623 struct linetable
*best_linetable
;
1624 struct symtab
*best_symtab
;
1626 /* First try looking it up in the given symtab. */
1627 best_linetable
= LINETABLE (symtab
);
1628 best_symtab
= symtab
;
1629 best_index
= find_line_common (best_linetable
, line
, &exact
);
1630 if (best_index
< 0 || !exact
)
1632 /* Didn't find an exact match. So we better keep looking for
1633 another symtab with the same name. In the case of xcoff,
1634 multiple csects for one source file (produced by IBM's FORTRAN
1635 compiler) produce multiple symtabs (this is unavoidable
1636 assuming csects can be at arbitrary places in memory and that
1637 the GLOBAL_BLOCK of a symtab has a begin and end address). */
1639 /* BEST is the smallest linenumber > LINE so far seen,
1640 or 0 if none has been seen so far.
1641 BEST_INDEX and BEST_LINETABLE identify the item for it. */
1644 struct objfile
*objfile
;
1647 if (best_index
>= 0)
1648 best
= best_linetable
->item
[best_index
].line
;
1652 ALL_SYMTABS (objfile
, s
)
1654 struct linetable
*l
;
1657 if (!STREQ (symtab
->filename
, s
->filename
))
1660 ind
= find_line_common (l
, line
, &exact
);
1670 if (best
== 0 || l
->item
[ind
].line
< best
)
1672 best
= l
->item
[ind
].line
;
1685 *index
= best_index
;
1687 *exact_match
= exact
;
1692 /* Set the PC value for a given source file and line number and return true.
1693 Returns zero for invalid line number (and sets the PC to 0).
1694 The source file is specified with a struct symtab. */
1697 find_line_pc (symtab
, line
, pc
)
1698 struct symtab
*symtab
;
1702 struct linetable
*l
;
1709 symtab
= find_line_symtab (symtab
, line
, &ind
, NULL
);
1712 l
= LINETABLE (symtab
);
1713 *pc
= l
->item
[ind
].pc
;
1720 /* Find the range of pc values in a line.
1721 Store the starting pc of the line into *STARTPTR
1722 and the ending pc (start of next line) into *ENDPTR.
1723 Returns 1 to indicate success.
1724 Returns 0 if could not find the specified line. */
1727 find_line_pc_range (sal
, startptr
, endptr
)
1728 struct symtab_and_line sal
;
1729 CORE_ADDR
*startptr
, *endptr
;
1731 CORE_ADDR startaddr
;
1732 struct symtab_and_line found_sal
;
1735 if (startaddr
==0 && !find_line_pc (sal
.symtab
, sal
.line
, &startaddr
))
1738 /* This whole function is based on address. For example, if line 10 has
1739 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
1740 "info line *0x123" should say the line goes from 0x100 to 0x200
1741 and "info line *0x355" should say the line goes from 0x300 to 0x400.
1742 This also insures that we never give a range like "starts at 0x134
1743 and ends at 0x12c". */
1745 found_sal
= find_pc_sect_line (startaddr
, sal
.section
, 0);
1746 if (found_sal
.line
!= sal
.line
)
1748 /* The specified line (sal) has zero bytes. */
1749 *startptr
= found_sal
.pc
;
1750 *endptr
= found_sal
.pc
;
1754 *startptr
= found_sal
.pc
;
1755 *endptr
= found_sal
.end
;
1760 /* Given a line table and a line number, return the index into the line
1761 table for the pc of the nearest line whose number is >= the specified one.
1762 Return -1 if none is found. The value is >= 0 if it is an index.
1764 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1767 find_line_common (l
, lineno
, exact_match
)
1768 register struct linetable
*l
;
1769 register int lineno
;
1775 /* BEST is the smallest linenumber > LINENO so far seen,
1776 or 0 if none has been seen so far.
1777 BEST_INDEX identifies the item for it. */
1779 int best_index
= -1;
1788 for (i
= 0; i
< len
; i
++)
1790 register struct linetable_entry
*item
= &(l
->item
[i
]);
1792 if (item
->line
== lineno
)
1794 /* Return the first (lowest address) entry which matches. */
1799 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
1806 /* If we got here, we didn't get an exact match. */
1813 find_pc_line_pc_range (pc
, startptr
, endptr
)
1815 CORE_ADDR
*startptr
, *endptr
;
1817 struct symtab_and_line sal
;
1818 sal
= find_pc_line (pc
, 0);
1821 return sal
.symtab
!= 0;
1824 /* Given a function symbol SYM, find the symtab and line for the start
1826 If the argument FUNFIRSTLINE is nonzero, we want the first line
1827 of real code inside the function. */
1829 static struct symtab_and_line
1830 find_function_start_sal
PARAMS ((struct symbol
*sym
, int));
1832 static struct symtab_and_line
1833 find_function_start_sal (sym
, funfirstline
)
1838 struct symtab_and_line sal
;
1840 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1841 fixup_symbol_section (sym
, NULL
);
1843 { /* skip "first line" of function (which is actually its prologue) */
1844 asection
*section
= SYMBOL_BFD_SECTION (sym
);
1845 /* If function is in an unmapped overlay, use its unmapped LMA
1846 address, so that SKIP_PROLOGUE has something unique to work on */
1847 if (section_is_overlay (section
) &&
1848 !section_is_mapped (section
))
1849 pc
= overlay_unmapped_address (pc
, section
);
1851 pc
+= FUNCTION_START_OFFSET
;
1854 /* For overlays, map pc back into its mapped VMA range */
1855 pc
= overlay_mapped_address (pc
, section
);
1857 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
1859 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1860 /* Convex: no need to suppress code on first line, if any */
1863 /* Check if SKIP_PROLOGUE left us in mid-line, and the next
1864 line is still part of the same function. */
1866 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) <= sal
.end
1867 && sal
.end
< BLOCK_END (SYMBOL_BLOCK_VALUE (sym
)))
1869 /* First pc of next line */
1871 /* Recalculate the line number (might not be N+1). */
1872 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
1880 /* If P is of the form "operator[ \t]+..." where `...' is
1881 some legitimate operator text, return a pointer to the
1882 beginning of the substring of the operator text.
1883 Otherwise, return "". */
1885 operator_chars (p
, end
)
1890 if (strncmp (p
, "operator", 8))
1894 /* Don't get faked out by `operator' being part of a longer
1896 if (isalpha(*p
) || *p
== '_' || *p
== '$' || *p
== '\0')
1899 /* Allow some whitespace between `operator' and the operator symbol. */
1900 while (*p
== ' ' || *p
== '\t')
1903 /* Recognize 'operator TYPENAME'. */
1905 if (isalpha(*p
) || *p
== '_' || *p
== '$')
1907 register char *q
= p
+1;
1908 while (isalnum(*q
) || *q
== '_' || *q
== '$')
1933 if (p
[1] == '=' || p
[1] == p
[0])
1944 error ("`operator ()' must be specified without whitespace in `()'");
1949 error ("`operator ?:' must be specified without whitespace in `?:'");
1954 error ("`operator []' must be specified without whitespace in `[]'");
1958 error ("`operator %s' not supported", p
);
1965 /* Return the number of methods described for TYPE, including the
1966 methods from types it derives from. This can't be done in the symbol
1967 reader because the type of the baseclass might still be stubbed
1968 when the definition of the derived class is parsed. */
1970 static int total_number_of_methods
PARAMS ((struct type
*type
));
1973 total_number_of_methods (type
)
1979 CHECK_TYPEDEF (type
);
1980 if (TYPE_CPLUS_SPECIFIC (type
) == NULL
)
1982 count
= TYPE_NFN_FIELDS_TOTAL (type
);
1984 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
1985 count
+= total_number_of_methods (TYPE_BASECLASS (type
, n
));
1990 /* Recursive helper function for decode_line_1.
1991 Look for methods named NAME in type T.
1992 Return number of matches.
1993 Put matches in SYM_ARR, which should have been allocated with
1994 a size of total_number_of_methods (T) * sizeof (struct symbol *).
1995 Note that this function is g++ specific. */
1998 find_methods (t
, name
, sym_arr
)
2001 struct symbol
**sym_arr
;
2005 struct symbol
*sym_class
;
2006 char *class_name
= type_name_no_tag (t
);
2008 /* Ignore this class if it doesn't have a name. This is ugly, but
2009 unless we figure out how to get the physname without the name of
2010 the class, then the loop can't do any good. */
2012 && (sym_class
= lookup_symbol (class_name
,
2013 (struct block
*)NULL
,
2016 (struct symtab
**)NULL
)))
2020 /* FIXME: Shouldn't this just be CHECK_TYPEDEF (t)? */
2021 t
= SYMBOL_TYPE (sym_class
);
2023 /* Loop over each method name. At this level, all overloads of a name
2024 are counted as a single name. There is an inner loop which loops over
2027 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
2028 method_counter
>= 0;
2032 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
2033 char dem_opname
[64];
2035 if (strncmp (method_name
, "__", 2) == 0 ||
2036 strncmp (method_name
, "op", 2) == 0 ||
2037 strncmp (method_name
, "type", 4) == 0)
2039 if (cplus_demangle_opname (method_name
, dem_opname
, DMGL_ANSI
))
2040 method_name
= dem_opname
;
2041 else if (cplus_demangle_opname (method_name
, dem_opname
, 0))
2042 method_name
= dem_opname
;
2045 if (STREQ (name
, method_name
))
2046 /* Find all the overloaded methods with that name. */
2047 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
2054 f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
2056 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
2060 tmp_name
= gdb_mangle_name (t
,
2063 phys_name
= alloca (strlen (tmp_name
) + 1);
2064 strcpy (phys_name
, tmp_name
);
2068 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
2070 /* Destructor is handled by caller, dont add it to the list */
2071 if (DESTRUCTOR_PREFIX_P (phys_name
))
2074 sym_arr
[i1
] = lookup_symbol (phys_name
,
2075 NULL
, VAR_NAMESPACE
,
2077 (struct symtab
**) NULL
);
2082 /* This error message gets printed, but the method
2083 still seems to be found
2084 fputs_filtered("(Cannot find method ", gdb_stdout);
2085 fprintf_symbol_filtered (gdb_stdout, phys_name,
2087 DMGL_PARAMS | DMGL_ANSI);
2088 fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
2095 /* Only search baseclasses if there is no match yet, since names in
2096 derived classes override those in baseclasses.
2098 FIXME: The above is not true; it is only true of member functions
2099 if they have the same number of arguments (??? - section 13.1 of the
2100 ARM says the function members are not in the same scope but doesn't
2101 really spell out the rules in a way I understand. In any case, if
2102 the number of arguments differ this is a case in which we can overload
2103 rather than hiding without any problem, and gcc 2.4.5 does overload
2104 rather than hiding in this case). */
2107 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
2108 i1
+= find_methods (TYPE_BASECLASS (t
, ibase
), name
, sym_arr
+ i1
);
2113 /* Helper function for decode_line_1.
2114 Build a canonical line spec in CANONICAL if it is non-NULL and if
2115 the SAL has a symtab.
2116 If SYMNAME is non-NULL the canonical line spec is `filename:symname'.
2117 If SYMNAME is NULL the line number from SAL is used and the canonical
2118 line spec is `filename:linenum'. */
2121 build_canonical_line_spec (sal
, symname
, canonical
)
2122 struct symtab_and_line
*sal
;
2126 char **canonical_arr
;
2127 char *canonical_name
;
2129 struct symtab
*s
= sal
->symtab
;
2131 if (s
== (struct symtab
*)NULL
2132 || s
->filename
== (char *)NULL
2133 || canonical
== (char ***)NULL
)
2136 canonical_arr
= (char **) xmalloc (sizeof (char *));
2137 *canonical
= canonical_arr
;
2139 filename
= s
->filename
;
2140 if (symname
!= NULL
)
2142 canonical_name
= xmalloc (strlen (filename
) + strlen (symname
) + 2);
2143 sprintf (canonical_name
, "%s:%s", filename
, symname
);
2147 canonical_name
= xmalloc (strlen (filename
) + 30);
2148 sprintf (canonical_name
, "%s:%d", filename
, sal
->line
);
2150 canonical_arr
[0] = canonical_name
;
2153 /* Parse a string that specifies a line number.
2154 Pass the address of a char * variable; that variable will be
2155 advanced over the characters actually parsed.
2159 LINENUM -- that line number in current file. PC returned is 0.
2160 FILE:LINENUM -- that line in that file. PC returned is 0.
2161 FUNCTION -- line number of openbrace of that function.
2162 PC returned is the start of the function.
2163 VARIABLE -- line number of definition of that variable.
2165 FILE:FUNCTION -- likewise, but prefer functions in that file.
2166 *EXPR -- line in which address EXPR appears.
2168 FUNCTION may be an undebuggable function found in minimal symbol table.
2170 If the argument FUNFIRSTLINE is nonzero, we want the first line
2171 of real code inside a function when a function is specified, and it is
2172 not OK to specify a variable or type to get its line number.
2174 DEFAULT_SYMTAB specifies the file to use if none is specified.
2175 It defaults to current_source_symtab.
2176 DEFAULT_LINE specifies the line number to use for relative
2177 line numbers (that start with signs). Defaults to current_source_line.
2178 If CANONICAL is non-NULL, store an array of strings containing the canonical
2179 line specs there if necessary. Currently overloaded member functions and
2180 line numbers or static functions without a filename yield a canonical
2181 line spec. The array and the line spec strings are allocated on the heap,
2182 it is the callers responsibility to free them.
2184 Note that it is possible to return zero for the symtab
2185 if no file is validly specified. Callers must check that.
2186 Also, the line number returned may be invalid. */
2188 /* We allow single quotes in various places. This is a hideous
2189 kludge, which exists because the completer can't yet deal with the
2190 lack of single quotes. FIXME: write a linespec_completer which we
2191 can use as appropriate instead of make_symbol_completion_list. */
2193 struct symtabs_and_lines
2194 decode_line_1 (argptr
, funfirstline
, default_symtab
, default_line
, canonical
)
2197 struct symtab
*default_symtab
;
2201 struct symtabs_and_lines values
;
2202 #ifdef HPPA_COMPILER_BUG
2203 /* FIXME: The native HP 9000/700 compiler has a bug which appears
2204 when optimizing this file with target i960-vxworks. I haven't
2205 been able to construct a simple test case. The problem is that
2206 in the second call to SKIP_PROLOGUE below, the compiler somehow
2207 does not realize that the statement val = find_pc_line (...) will
2208 change the values of the fields of val. It extracts the elements
2209 into registers at the top of the block, and does not update the
2210 registers after the call to find_pc_line. You can check this by
2211 inserting a printf at the end of find_pc_line to show what values
2212 it is returning for val.pc and val.end and another printf after
2213 the call to see what values the function actually got (remember,
2214 this is compiling with cc -O, with this patch removed). You can
2215 also examine the assembly listing: search for the second call to
2216 skip_prologue; the LDO statement before the next call to
2217 find_pc_line loads the address of the structure which
2218 find_pc_line will return; if there is a LDW just before the LDO,
2219 which fetches an element of the structure, then the compiler
2222 Setting val to volatile avoids the problem. We must undef
2223 volatile, because the HPPA native compiler does not define
2224 __STDC__, although it does understand volatile, and so volatile
2225 will have been defined away in defs.h. */
2227 volatile struct symtab_and_line val
;
2228 #define volatile /*nothing*/
2230 struct symtab_and_line val
;
2232 register char *p
, *p1
;
2234 register struct symtab
*s
;
2236 register struct symbol
*sym
;
2237 /* The symtab that SYM was found in. */
2238 struct symtab
*sym_symtab
;
2240 register CORE_ADDR pc
;
2241 register struct minimal_symbol
*msymbol
;
2243 int is_quoted
, has_parens
;
2244 char *saved_arg
= *argptr
;
2245 extern char *gdb_completer_quote_characters
;
2247 INIT_SAL (&val
); /* initialize to zeroes */
2249 /* Defaults have defaults. */
2251 if (default_symtab
== 0)
2253 default_symtab
= current_source_symtab
;
2254 default_line
= current_source_line
;
2257 /* See if arg is *PC */
2259 if (**argptr
== '*')
2262 pc
= parse_and_eval_address_1 (argptr
);
2264 values
.sals
= (struct symtab_and_line
*)
2265 xmalloc (sizeof (struct symtab_and_line
));
2268 values
.sals
[0] = find_pc_line (pc
, 0);
2269 values
.sals
[0].pc
= pc
;
2270 values
.sals
[0].section
= find_pc_overlay (pc
);
2275 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
2278 is_quoted
= (**argptr
2279 && strchr (gdb_completer_quote_characters
, **argptr
) != NULL
);
2280 has_parens
= ((pp
= strchr (*argptr
, '(')) != NULL
2281 && (pp
= strchr (pp
, ')')) != NULL
);
2283 for (p
= *argptr
; *p
; p
++)
2287 while(++p
&& *p
!= '>');
2290 error ("non-matching '<' and '>' in command");
2293 if (p
[0] == ':' || p
[0] == ' ' || p
[0] == '\t')
2295 /* start-sanitize-java */
2296 if (p
[0] == '.' && strchr (p
, ':') == NULL
) /* Java qualified method. */
2298 /* Find the *last* '.', since the others are package qualifiers. */
2299 for (p1
= p
; *p1
; p1
++)
2306 /* end-sanitize-java */
2308 while (p
[0] == ' ' || p
[0] == '\t') p
++;
2310 if ((p
[0] == ':' || p
[0] == '.') && !has_parens
)
2313 /* start-sanitize-java */
2315 /* end-sanitize-java */
2316 if (is_quoted
) *argptr
= *argptr
+1;
2317 if (p
[0] == '.' || p
[1] ==':')
2319 struct symbol
*sym_class
;
2321 /* Extract the class name. */
2323 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
2324 copy
= (char *) alloca (p
- *argptr
+ 1);
2325 memcpy (copy
, *argptr
, p
- *argptr
);
2326 copy
[p
- *argptr
] = 0;
2328 /* Discard the class name from the arg. */
2329 p
= p1
+ (p1
[0] == ':' ? 2 : 1);
2330 while (*p
== ' ' || *p
== '\t') p
++;
2333 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
2334 (struct symtab
**)NULL
);
2337 (TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_STRUCT
2338 || TYPE_CODE (SYMBOL_TYPE (sym_class
)) == TYPE_CODE_UNION
))
2340 struct symbol
**sym_arr
;
2344 t
= check_typedef (SYMBOL_TYPE (sym_class
));
2346 /* Arg token is not digits => try it as a function name
2347 Find the next token(everything up to end or next blank). */
2349 && strchr (gdb_completer_quote_characters
, **argptr
) != NULL
)
2351 p
= skip_quoted(*argptr
);
2352 *argptr
= *argptr
+ 1;
2357 while (*p
&& *p
!=' ' && *p
!='\t' && *p
!=',' && *p
!=':') p
++;
2360 q = operator_chars (*argptr, &q1);
2364 char *tmp = alloca (q1 - q + 1);
2365 memcpy (tmp, q, q1 - q);
2367 opname = cplus_mangle_opname (tmp, DMGL_ANSI);
2371 printf_filtered ("no mangling for \"%s\"\n", tmp);
2372 cplusplus_hint (saved_arg);
2373 return_to_top_level (RETURN_ERROR);
2375 copy = (char*) alloca (3 + strlen(opname));
2376 sprintf (copy, "__%s", opname);
2382 copy
= (char *) alloca (p
- *argptr
+ 1 );
2383 memcpy (copy
, *argptr
, p
- *argptr
);
2384 copy
[p
- *argptr
] = '\0';
2386 && copy
[p
- *argptr
- 1]
2387 && strchr (gdb_completer_quote_characters
,
2388 copy
[p
- *argptr
- 1]) != NULL
)
2389 copy
[p
- *argptr
- 1] = '\0';
2392 /* no line number may be specified */
2393 while (*p
== ' ' || *p
== '\t') p
++;
2397 i1
= 0; /* counter for the symbol array */
2398 sym_arr
= (struct symbol
**) alloca(total_number_of_methods (t
)
2399 * sizeof(struct symbol
*));
2401 if (destructor_name_p (copy
, t
))
2403 /* Destructors are a special case. */
2404 int m_index
, f_index
;
2406 if (get_destructor_fn_field (t
, &m_index
, &f_index
))
2408 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, m_index
);
2411 lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f
, f_index
),
2412 NULL
, VAR_NAMESPACE
, (int *) NULL
,
2413 (struct symtab
**)NULL
);
2419 i1
= find_methods (t
, copy
, sym_arr
);
2422 /* There is exactly one field with that name. */
2425 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2427 values
.sals
= (struct symtab_and_line
*)
2428 xmalloc (sizeof (struct symtab_and_line
));
2430 values
.sals
[0] = find_function_start_sal (sym
,
2441 /* There is more than one field with that name
2442 (overloaded). Ask the user which one to use. */
2443 return decode_line_2 (sym_arr
, i1
, funfirstline
, canonical
);
2449 if (OPNAME_PREFIX_P (copy
))
2451 tmp
= (char *)alloca (strlen (copy
+3) + 9);
2452 strcpy (tmp
, "operator ");
2453 strcat (tmp
, copy
+3);
2460 ("the class `%s' does not have destructor defined\n",
2461 SYMBOL_SOURCE_NAME(sym_class
));
2464 ("the class %s does not have any method named %s\n",
2465 SYMBOL_SOURCE_NAME(sym_class
), tmp
);
2466 cplusplus_hint (saved_arg
);
2467 return_to_top_level (RETURN_ERROR
);
2473 /* The quotes are important if copy is empty. */
2475 ("can't find class, struct, or union named \"%s\"\n", copy
);
2476 cplusplus_hint (saved_arg
);
2477 return_to_top_level (RETURN_ERROR
);
2483 /* Extract the file name. */
2485 while (p
!= *argptr
&& p
[-1] == ' ') --p
;
2486 copy
= (char *) alloca (p
- *argptr
+ 1);
2487 memcpy (copy
, *argptr
, p
- *argptr
);
2488 copy
[p
- *argptr
] = 0;
2490 /* Find that file's data. */
2491 s
= lookup_symtab (copy
);
2494 if (!have_full_symbols () && !have_partial_symbols ())
2495 error (no_symtab_msg
);
2496 error ("No source file named %s.", copy
);
2499 /* Discard the file name from the arg. */
2501 while (*p
== ' ' || *p
== '\t') p
++;
2505 /* S is specified file's symtab, or 0 if no file specified.
2506 arg no longer contains the file name. */
2508 /* Check whether arg is all digits (and sign) */
2511 if (*q
== '-' || *q
== '+') q
++;
2512 while (*q
>= '0' && *q
<= '9')
2515 if (q
!= *argptr
&& (*q
== 0 || *q
== ' ' || *q
== '\t' || *q
== ','))
2517 /* We found a token consisting of all digits -- at least one digit. */
2518 enum sign
{none
, plus
, minus
} sign
= none
;
2520 /* We might need a canonical line spec if no file was specified. */
2521 int need_canonical
= (s
== 0) ? 1 : 0;
2523 /* This is where we need to make sure that we have good defaults.
2524 We must guarantee that this section of code is never executed
2525 when we are called with just a function name, since
2526 select_source_symtab calls us with such an argument */
2528 if (s
== 0 && default_symtab
== 0)
2530 select_source_symtab (0);
2531 default_symtab
= current_source_symtab
;
2532 default_line
= current_source_line
;
2535 if (**argptr
== '+')
2536 sign
= plus
, (*argptr
)++;
2537 else if (**argptr
== '-')
2538 sign
= minus
, (*argptr
)++;
2539 val
.line
= atoi (*argptr
);
2546 val
.line
= default_line
+ val
.line
;
2552 val
.line
= default_line
- val
.line
;
2557 break; /* No need to adjust val.line. */
2560 while (*q
== ' ' || *q
== '\t') q
++;
2565 /* It is possible that this source file has more than one symtab,
2566 and that the new line number specification has moved us from the
2567 default (in s) to a new one. */
2568 val
.symtab
= find_line_symtab (s
, val
.line
, NULL
, NULL
);
2569 if (val
.symtab
== 0)
2573 values
.sals
= (struct symtab_and_line
*)
2574 xmalloc (sizeof (struct symtab_and_line
));
2575 values
.sals
[0] = val
;
2578 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
2582 /* Arg token is not digits => try it as a variable name
2583 Find the next token (everything up to end or next whitespace). */
2585 if (**argptr
== '$') /* Convenience variable */
2586 p
= skip_quoted (*argptr
+ 1);
2589 p
= skip_quoted (*argptr
);
2591 error ("Unmatched single quote.");
2593 else if (has_parens
)
2599 p
= skip_quoted(*argptr
);
2602 copy
= (char *) alloca (p
- *argptr
+ 1);
2603 memcpy (copy
, *argptr
, p
- *argptr
);
2604 copy
[p
- *argptr
] = '\0';
2607 && copy
[0] == copy
[p
- *argptr
- 1]
2608 && strchr (gdb_completer_quote_characters
, copy
[0]) != NULL
)
2610 copy
[p
- *argptr
- 1] = '\0';
2613 while (*p
== ' ' || *p
== '\t') p
++;
2616 /* See if it's a convenience variable */
2621 int need_canonical
= (s
== 0) ? 1 : 0;
2623 valx
= value_of_internalvar (lookup_internalvar (copy
+ 1));
2624 if (TYPE_CODE (VALUE_TYPE (valx
)) != TYPE_CODE_INT
)
2625 error ("Convenience variables used in line specs must have integer values.");
2627 val
.symtab
= s
? s
: default_symtab
;
2628 val
.line
= value_as_long (valx
);
2631 values
.sals
= (struct symtab_and_line
*)xmalloc (sizeof val
);
2632 values
.sals
[0] = val
;
2636 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
2642 /* Look up that token as a variable.
2643 If file specified, use that file's per-file block to start with. */
2645 sym
= lookup_symbol (copy
,
2646 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
2647 : get_selected_block ()),
2648 VAR_NAMESPACE
, 0, &sym_symtab
);
2652 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2654 /* Arg is the name of a function */
2655 values
.sals
= (struct symtab_and_line
*)
2656 xmalloc (sizeof (struct symtab_and_line
));
2657 values
.sals
[0] = find_function_start_sal (sym
, funfirstline
);
2660 /* Don't use the SYMBOL_LINE; if used at all it points to
2661 the line containing the parameters or thereabouts, not
2662 the first line of code. */
2664 /* We might need a canonical line spec if it is a static
2668 struct blockvector
*bv
= BLOCKVECTOR (sym_symtab
);
2669 struct block
*b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2670 if (lookup_block_symbol (b
, copy
, VAR_NAMESPACE
) != NULL
)
2671 build_canonical_line_spec (values
.sals
, copy
, canonical
);
2678 error ("\"%s\" is not a function", copy
);
2679 else if (SYMBOL_LINE (sym
) != 0)
2681 /* We know its line number. */
2682 values
.sals
= (struct symtab_and_line
*)
2683 xmalloc (sizeof (struct symtab_and_line
));
2685 memset (&values
.sals
[0], 0, sizeof (values
.sals
[0]));
2686 values
.sals
[0].symtab
= sym_symtab
;
2687 values
.sals
[0].line
= SYMBOL_LINE (sym
);
2691 /* This can happen if it is compiled with a compiler which doesn't
2692 put out line numbers for variables. */
2693 /* FIXME: Shouldn't we just set .line and .symtab to zero
2694 and return? For example, "info line foo" could print
2696 error ("Line number not known for symbol \"%s\"", copy
);
2700 msymbol
= lookup_minimal_symbol (copy
, NULL
, NULL
);
2701 if (msymbol
!= NULL
)
2703 values
.sals
= (struct symtab_and_line
*)
2704 xmalloc (sizeof (struct symtab_and_line
));
2705 values
.sals
[0] = find_pc_sect_line ( SYMBOL_VALUE_ADDRESS (msymbol
),
2706 (struct sec
*)0,0 );
2707 values
.sals
[0].section
= SYMBOL_BFD_SECTION (msymbol
);
2710 values
.sals
[0].pc
+= FUNCTION_START_OFFSET
;
2711 SKIP_PROLOGUE (values
.sals
[0].pc
);
2717 if (!have_full_symbols () &&
2718 !have_partial_symbols () && !have_minimal_symbols ())
2719 error (no_symtab_msg
);
2721 error ("Function \"%s\" not defined.", copy
);
2722 return values
; /* for lint */
2725 struct symtabs_and_lines
2726 decode_line_spec (string
, funfirstline
)
2730 struct symtabs_and_lines sals
;
2732 error ("Empty line specification.");
2733 sals
= decode_line_1 (&string
, funfirstline
,
2734 current_source_symtab
, current_source_line
,
2737 error ("Junk at end of line specification: %s", string
);
2741 /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to
2742 operate on (ask user if necessary).
2743 If CANONICAL is non-NULL return a corresponding array of mangled names
2744 as canonical line specs there. */
2746 static struct symtabs_and_lines
2747 decode_line_2 (sym_arr
, nelts
, funfirstline
, canonical
)
2748 struct symbol
*sym_arr
[];
2753 struct symtabs_and_lines values
, return_values
;
2758 struct cleanup
*old_chain
;
2759 char **canonical_arr
= (char **)NULL
;
2761 values
.sals
= (struct symtab_and_line
*)
2762 alloca (nelts
* sizeof(struct symtab_and_line
));
2763 return_values
.sals
= (struct symtab_and_line
*)
2764 xmalloc (nelts
* sizeof(struct symtab_and_line
));
2765 old_chain
= make_cleanup (free
, return_values
.sals
);
2769 canonical_arr
= (char **) xmalloc (nelts
* sizeof (char *));
2770 make_cleanup (free
, canonical_arr
);
2771 memset (canonical_arr
, 0, nelts
* sizeof (char *));
2772 *canonical
= canonical_arr
;
2776 printf_unfiltered("[0] cancel\n[1] all\n");
2779 INIT_SAL (&return_values
.sals
[i
]); /* initialize to zeroes */
2780 INIT_SAL (&values
.sals
[i
]);
2781 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
2783 values
.sals
[i
] = find_function_start_sal (sym_arr
[i
], funfirstline
);
2784 printf_unfiltered ("[%d] %s at %s:%d\n",
2786 SYMBOL_SOURCE_NAME (sym_arr
[i
]),
2787 values
.sals
[i
].symtab
->filename
,
2788 values
.sals
[i
].line
);
2791 printf_unfiltered ("?HERE\n");
2795 if ((prompt
= getenv ("PS2")) == NULL
)
2799 args
= command_line_input (prompt
, 0, "overload-choice");
2801 if (args
== 0 || *args
== 0)
2802 error_no_arg ("one or more choice numbers");
2810 while (*arg1
>= '0' && *arg1
<= '9') arg1
++;
2811 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
2812 error ("Arguments must be choice numbers.");
2817 error ("cancelled");
2822 for (i
= 0; i
< nelts
; i
++)
2824 if (canonical_arr
[i
] == NULL
)
2826 symname
= SYMBOL_NAME (sym_arr
[i
]);
2827 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
2831 memcpy (return_values
.sals
, values
.sals
,
2832 (nelts
* sizeof(struct symtab_and_line
)));
2833 return_values
.nelts
= nelts
;
2834 discard_cleanups (old_chain
);
2835 return return_values
;
2838 if (num
>= nelts
+ 2)
2840 printf_unfiltered ("No choice number %d.\n", num
);
2845 if (values
.sals
[num
].pc
)
2849 symname
= SYMBOL_NAME (sym_arr
[num
]);
2850 make_cleanup (free
, symname
);
2851 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
2853 return_values
.sals
[i
++] = values
.sals
[num
];
2854 values
.sals
[num
].pc
= 0;
2858 printf_unfiltered ("duplicate request for %d ignored.\n", num
);
2863 while (*args
== ' ' || *args
== '\t') args
++;
2865 return_values
.nelts
= i
;
2866 discard_cleanups (old_chain
);
2867 return return_values
;
2871 /* Slave routine for sources_info. Force line breaks at ,'s.
2872 NAME is the name to print and *FIRST is nonzero if this is the first
2873 name printed. Set *FIRST to zero. */
2875 output_source_filename (name
, first
)
2879 /* Table of files printed so far. Since a single source file can
2880 result in several partial symbol tables, we need to avoid printing
2881 it more than once. Note: if some of the psymtabs are read in and
2882 some are not, it gets printed both under "Source files for which
2883 symbols have been read" and "Source files for which symbols will
2884 be read in on demand". I consider this a reasonable way to deal
2885 with the situation. I'm not sure whether this can also happen for
2886 symtabs; it doesn't hurt to check. */
2887 static char **tab
= NULL
;
2888 /* Allocated size of tab in elements.
2889 Start with one 256-byte block (when using GNU malloc.c).
2890 24 is the malloc overhead when range checking is in effect. */
2891 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
2892 /* Current size of tab in elements. */
2893 static int tab_cur_size
;
2900 tab
= (char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
2904 /* Is NAME in tab? */
2905 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
2906 if (STREQ (*p
, name
))
2907 /* Yes; don't print it again. */
2909 /* No; add it to tab. */
2910 if (tab_cur_size
== tab_alloc_size
)
2912 tab_alloc_size
*= 2;
2913 tab
= (char **) xrealloc ((char *) tab
, tab_alloc_size
* sizeof (*tab
));
2915 tab
[tab_cur_size
++] = name
;
2923 printf_filtered (", ");
2927 fputs_filtered (name
, gdb_stdout
);
2931 sources_info (ignore
, from_tty
)
2935 register struct symtab
*s
;
2936 register struct partial_symtab
*ps
;
2937 register struct objfile
*objfile
;
2940 if (!have_full_symbols () && !have_partial_symbols ())
2942 error (no_symtab_msg
);
2945 printf_filtered ("Source files for which symbols have been read in:\n\n");
2948 ALL_SYMTABS (objfile
, s
)
2950 output_source_filename (s
-> filename
, &first
);
2952 printf_filtered ("\n\n");
2954 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2957 ALL_PSYMTABS (objfile
, ps
)
2961 output_source_filename (ps
-> filename
, &first
);
2964 printf_filtered ("\n");
2968 file_matches (file
, files
, nfiles
)
2975 if (file
!= NULL
&& nfiles
!= 0)
2977 for (i
= 0; i
< nfiles
; i
++)
2979 if (strcmp (files
[i
], basename (file
)) == 0)
2983 else if (nfiles
== 0)
2988 /* Free any memory associated with a search. */
2990 free_search_symbols (symbols
)
2991 struct symbol_search
*symbols
;
2993 struct symbol_search
*p
;
2994 struct symbol_search
*next
;
2996 for (p
= symbols
; p
!= NULL
; p
= next
)
3003 /* Search the symbol table for matches to the regular expression REGEXP,
3004 returning the results in *MATCHES.
3006 Only symbols of KIND are searched:
3007 FUNCTIONS_NAMESPACE - search all functions
3008 TYPES_NAMESPACE - search all type names
3009 METHODS_NAMESPACE - search all methods NOT IMPLEMENTED
3010 VARIABLES_NAMESPACE - search all symbols, excluding functions, type names,
3011 and constants (enums)
3013 free_search_symbols should be called when *MATCHES is no longer needed.
3016 search_symbols (regexp
, kind
, nfiles
, files
, matches
)
3018 namespace_enum kind
;
3021 struct symbol_search
**matches
;
3024 register struct symtab
*s
;
3025 register struct partial_symtab
*ps
;
3026 register struct blockvector
*bv
;
3027 struct blockvector
*prev_bv
= 0;
3028 register struct block
*b
;
3031 register struct symbol
*sym
;
3032 struct partial_symbol
**psym
;
3033 struct objfile
*objfile
;
3034 struct minimal_symbol
*msymbol
;
3037 static enum minimal_symbol_type types
[]
3038 = {mst_data
, mst_text
, mst_abs
, mst_unknown
};
3039 static enum minimal_symbol_type types2
[]
3040 = {mst_bss
, mst_file_text
, mst_abs
, mst_unknown
};
3041 static enum minimal_symbol_type types3
[]
3042 = {mst_file_data
, mst_solib_trampoline
, mst_abs
, mst_unknown
};
3043 static enum minimal_symbol_type types4
[]
3044 = {mst_file_bss
, mst_text
, mst_abs
, mst_unknown
};
3045 enum minimal_symbol_type ourtype
;
3046 enum minimal_symbol_type ourtype2
;
3047 enum minimal_symbol_type ourtype3
;
3048 enum minimal_symbol_type ourtype4
;
3049 struct symbol_search
*sr
;
3050 struct symbol_search
*psr
;
3051 struct symbol_search
*tail
;
3052 struct cleanup
*old_chain
= NULL
;
3054 if (kind
< LABEL_NAMESPACE
)
3055 error ("must search on specific namespace");
3057 ourtype
= types
[(int) (kind
- LABEL_NAMESPACE
)];
3058 ourtype2
= types2
[(int) (kind
- LABEL_NAMESPACE
)];
3059 ourtype3
= types3
[(int) (kind
- LABEL_NAMESPACE
)];
3060 ourtype4
= types4
[(int) (kind
- LABEL_NAMESPACE
)];
3062 sr
= *matches
= NULL
;
3067 /* Make sure spacing is right for C++ operators.
3068 This is just a courtesy to make the matching less sensitive
3069 to how many spaces the user leaves between 'operator'
3070 and <TYPENAME> or <OPERATOR>. */
3072 char *opname
= operator_chars (regexp
, &opend
);
3075 int fix
= -1; /* -1 means ok; otherwise number of spaces needed. */
3076 if (isalpha(*opname
) || *opname
== '_' || *opname
== '$')
3078 /* There should 1 space between 'operator' and 'TYPENAME'. */
3079 if (opname
[-1] != ' ' || opname
[-2] == ' ')
3084 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
3085 if (opname
[-1] == ' ')
3088 /* If wrong number of spaces, fix it. */
3091 char *tmp
= (char*) alloca(opend
-opname
+10);
3092 sprintf(tmp
, "operator%.*s%s", fix
, " ", opname
);
3097 if (0 != (val
= re_comp (regexp
)))
3098 error ("Invalid regexp (%s): %s", val
, regexp
);
3101 /* Search through the partial symtabs *first* for all symbols
3102 matching the regexp. That way we don't have to reproduce all of
3103 the machinery below. */
3105 ALL_PSYMTABS (objfile
, ps
)
3107 struct partial_symbol
**bound
, **gbound
, **sbound
;
3110 if (ps
->readin
) continue;
3112 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
3113 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
3116 /* Go through all of the symbols stored in a partial
3117 symtab in one loop. */
3118 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
3123 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
3125 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
3136 /* If it would match (logic taken from loop below)
3137 load the file and go on to the next one */
3138 if (file_matches (ps
->filename
, files
, nfiles
)
3139 && ((regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (*psym
))
3140 && ((kind
== VARIABLES_NAMESPACE
&& SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
3141 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
3142 || (kind
== FUNCTIONS_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
3143 || (kind
== TYPES_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
)
3144 || (kind
== METHODS_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
))))
3146 PSYMTAB_TO_SYMTAB(ps
);
3154 /* Here, we search through the minimal symbol tables for functions
3155 and variables that match, and force their symbols to be read.
3156 This is in particular necessary for demangled variable names,
3157 which are no longer put into the partial symbol tables.
3158 The symbol will then be found during the scan of symtabs below.
3160 For functions, find_pc_symtab should succeed if we have debug info
3161 for the function, for variables we have to call lookup_symbol
3162 to determine if the variable has debug info.
3163 If the lookup fails, set found_misc so that we will rescan to print
3164 any matching symbols without debug info.
3167 if (nfiles
== 0 && (kind
== VARIABLES_NAMESPACE
|| kind
== FUNCTIONS_NAMESPACE
))
3169 ALL_MSYMBOLS (objfile
, msymbol
)
3171 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
3172 MSYMBOL_TYPE (msymbol
) == ourtype2
||
3173 MSYMBOL_TYPE (msymbol
) == ourtype3
||
3174 MSYMBOL_TYPE (msymbol
) == ourtype4
)
3176 if (regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (msymbol
))
3178 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
)))
3180 if (kind
== FUNCTIONS_NAMESPACE
3181 || lookup_symbol (SYMBOL_NAME (msymbol
),
3182 (struct block
*) NULL
,
3184 0, (struct symtab
**) NULL
) == NULL
)
3192 ALL_SYMTABS (objfile
, s
)
3194 bv
= BLOCKVECTOR (s
);
3195 /* Often many files share a blockvector.
3196 Scan each blockvector only once so that
3197 we don't get every symbol many times.
3198 It happens that the first symtab in the list
3199 for any given blockvector is the main file. */
3201 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
3203 b
= BLOCKVECTOR_BLOCK (bv
, i
);
3204 /* Skip the sort if this block is always sorted. */
3205 if (!BLOCK_SHOULD_SORT (b
))
3206 sort_block_syms (b
);
3207 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
3210 sym
= BLOCK_SYM (b
, j
);
3211 if (file_matches (s
->filename
, files
, nfiles
)
3212 && ((regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (sym
))
3213 && ((kind
== VARIABLES_NAMESPACE
&& SYMBOL_CLASS (sym
) != LOC_TYPEDEF
3214 && SYMBOL_CLASS (sym
) != LOC_BLOCK
3215 && SYMBOL_CLASS (sym
) != LOC_CONST
)
3216 || (kind
== FUNCTIONS_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3217 || (kind
== TYPES_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3218 || (kind
== METHODS_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
))))
3221 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
3225 psr
->msymbol
= NULL
;
3230 old_chain
= make_cleanup ((make_cleanup_func
)
3231 free_search_symbols
, sr
);
3242 /* If there are no eyes, avoid all contact. I mean, if there are
3243 no debug symbols, then print directly from the msymbol_vector. */
3245 if (found_misc
|| kind
!= FUNCTIONS_NAMESPACE
)
3247 ALL_MSYMBOLS (objfile
, msymbol
)
3249 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
3250 MSYMBOL_TYPE (msymbol
) == ourtype2
||
3251 MSYMBOL_TYPE (msymbol
) == ourtype3
||
3252 MSYMBOL_TYPE (msymbol
) == ourtype4
)
3254 if (regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (msymbol
))
3256 /* Functions: Look up by address. */
3257 if (kind
!= FUNCTIONS_NAMESPACE
||
3258 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
))))
3260 /* Variables/Absolutes: Look up by name */
3261 if (lookup_symbol (SYMBOL_NAME (msymbol
),
3262 (struct block
*) NULL
, VAR_NAMESPACE
,
3263 0, (struct symtab
**) NULL
) == NULL
)
3266 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
3268 psr
->msymbol
= msymbol
;
3275 old_chain
= make_cleanup ((make_cleanup_func
)
3276 free_search_symbols
, &sr
);
3290 discard_cleanups (old_chain
);
3293 /* Helper function for symtab_symbol_info, this function uses
3294 the data returned from search_symbols() to print information
3295 regarding the match to gdb_stdout.
3298 print_symbol_info (kind
, s
, sym
, block
, last
)
3299 namespace_enum kind
;
3305 if (last
== NULL
|| strcmp (last
, s
->filename
) != 0)
3307 fputs_filtered ("\nFile ", gdb_stdout
);
3308 fputs_filtered (s
->filename
, gdb_stdout
);
3309 fputs_filtered (":\n", gdb_stdout
);
3312 if (kind
!= TYPES_NAMESPACE
&& block
== STATIC_BLOCK
)
3313 printf_filtered ("static ");
3315 /* Typedef that is not a C++ class */
3316 if (kind
== TYPES_NAMESPACE
3317 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
3318 c_typedef_print (SYMBOL_TYPE(sym
), sym
, gdb_stdout
);
3319 /* variable, func, or typedef-that-is-c++-class */
3320 else if (kind
< TYPES_NAMESPACE
||
3321 (kind
== TYPES_NAMESPACE
&&
3322 SYMBOL_NAMESPACE(sym
) == STRUCT_NAMESPACE
))
3324 type_print (SYMBOL_TYPE (sym
),
3325 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3326 ? "" : SYMBOL_SOURCE_NAME (sym
)),
3329 printf_filtered (";\n");
3334 /* Tiemann says: "info methods was never implemented." */
3335 char *demangled_name
;
3336 c_type_print_base (TYPE_FN_FIELD_TYPE(t
, block
),
3338 c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t
, block
),
3340 if (TYPE_FN_FIELD_STUB (t
, block
))
3341 check_stub_method (TYPE_DOMAIN_TYPE (type
), j
, block
);
3343 cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t
, block
),
3344 DMGL_ANSI
| DMGL_PARAMS
);
3345 if (demangled_name
== NULL
)
3346 fprintf_filtered (stream
, "<badly mangled name %s>",
3347 TYPE_FN_FIELD_PHYSNAME (t
, block
));
3350 fputs_filtered (demangled_name
, stream
);
3351 free (demangled_name
);
3357 /* This help function for symtab_symbol_info() prints information
3358 for non-debugging symbols to gdb_stdout.
3361 print_msymbol_info (msymbol
)
3362 struct minimal_symbol
*msymbol
;
3364 printf_filtered (" %08lx %s\n",
3365 (unsigned long) SYMBOL_VALUE_ADDRESS (msymbol
),
3366 SYMBOL_SOURCE_NAME (msymbol
));
3369 /* This is the guts of the commands "info functions", "info types", and
3370 "info variables". It calls search_symbols to find all matches and then
3371 print_[m]symbol_info to print out some useful information about the
3375 symtab_symbol_info (regexp
, kind
, from_tty
)
3377 namespace_enum kind
;
3380 static char *classnames
[]
3381 = {"variable", "function", "type", "method"};
3382 struct symbol_search
*symbols
;
3383 struct symbol_search
*p
;
3384 struct cleanup
*old_chain
;
3385 char *last_filename
= NULL
;
3388 /* must make sure that if we're interrupted, symbols gets freed */
3389 search_symbols (regexp
, kind
, 0, (char **) NULL
, &symbols
);
3390 old_chain
= make_cleanup ((make_cleanup_func
) free_search_symbols
, symbols
);
3392 printf_filtered (regexp
3393 ? "All %ss matching regular expression \"%s\":\n"
3394 : "All defined %ss:\n",
3395 classnames
[(int) (kind
- LABEL_NAMESPACE
- 1)], regexp
);
3397 for (p
= symbols
; p
!= NULL
; p
= p
->next
)
3401 if (p
->msymbol
!= NULL
)
3405 printf_filtered ("\nNon-debugging symbols:\n");
3408 print_msymbol_info (p
->msymbol
);
3412 print_symbol_info (kind
,
3417 last_filename
= p
->symtab
->filename
;
3421 do_cleanups (old_chain
);
3425 variables_info (regexp
, from_tty
)
3429 symtab_symbol_info (regexp
, VARIABLES_NAMESPACE
, from_tty
);
3433 functions_info (regexp
, from_tty
)
3437 symtab_symbol_info (regexp
, FUNCTIONS_NAMESPACE
, from_tty
);
3441 types_info (regexp
, from_tty
)
3445 symtab_symbol_info (regexp
, TYPES_NAMESPACE
, from_tty
);
3449 /* Tiemann says: "info methods was never implemented." */
3451 methods_info (regexp
)
3454 symtab_symbol_info (regexp
, METHODS_NAMESPACE
, 0, from_tty
);
3458 /* Breakpoint all functions matching regular expression. */
3460 rbreak_command (regexp
, from_tty
)
3464 struct symbol_search
*ss
;
3465 struct symbol_search
*p
;
3466 struct cleanup
*old_chain
;
3468 search_symbols (regexp
, FUNCTIONS_NAMESPACE
, 0, (char **) NULL
, &ss
);
3469 old_chain
= make_cleanup ((make_cleanup_func
) free_search_symbols
, ss
);
3471 for (p
= ss
; p
!= NULL
; p
= p
->next
)
3473 if (p
->msymbol
== NULL
)
3475 char *string
= (char *) alloca (strlen (p
->symtab
->filename
)
3476 + strlen (SYMBOL_NAME (p
->symbol
))
3478 strcpy (string
, p
->symtab
->filename
);
3479 strcat (string
, ":'");
3480 strcat (string
, SYMBOL_NAME (p
->symbol
));
3481 strcat (string
, "'");
3482 break_command (string
, from_tty
);
3483 print_symbol_info (FUNCTIONS_NAMESPACE
,
3487 p
->symtab
->filename
);
3491 break_command (SYMBOL_NAME (p
->msymbol
), from_tty
);
3492 printf_filtered ("<function, no debug info> %s;\n",
3493 SYMBOL_SOURCE_NAME (p
->msymbol
));
3497 do_cleanups (old_chain
);
3501 /* Return Nonzero if block a is lexically nested within block b,
3502 or if a and b have the same pc range.
3503 Return zero otherwise. */
3506 struct block
*a
, *b
;
3510 return BLOCK_START (a
) >= BLOCK_START (b
)
3511 && BLOCK_END (a
) <= BLOCK_END (b
);
3515 /* Helper routine for make_symbol_completion_list. */
3517 static int return_val_size
;
3518 static int return_val_index
;
3519 static char **return_val
;
3521 #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
3523 if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \
3524 /* Put only the mangled name on the list. */ \
3525 /* Advantage: "b foo<TAB>" completes to "b foo(int, int)" */ \
3526 /* Disadvantage: "b foo__i<TAB>" doesn't complete. */ \
3527 completion_list_add_name \
3528 (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \
3530 completion_list_add_name \
3531 (SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \
3534 /* Test to see if the symbol specified by SYMNAME (which is already
3535 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3536 characters. If so, add it to the current completion list. */
3539 completion_list_add_name (symname
, sym_text
, sym_text_len
, text
, word
)
3549 /* clip symbols that cannot match */
3551 if (strncmp (symname
, sym_text
, sym_text_len
) != 0)
3556 /* Clip any symbol names that we've already considered. (This is a
3557 time optimization) */
3559 for (i
= 0; i
< return_val_index
; ++i
)
3561 if (STREQ (symname
, return_val
[i
]))
3567 /* We have a match for a completion, so add SYMNAME to the current list
3568 of matches. Note that the name is moved to freshly malloc'd space. */
3572 if (word
== sym_text
)
3574 new = xmalloc (strlen (symname
) + 5);
3575 strcpy (new, symname
);
3577 else if (word
> sym_text
)
3579 /* Return some portion of symname. */
3580 new = xmalloc (strlen (symname
) + 5);
3581 strcpy (new, symname
+ (word
- sym_text
));
3585 /* Return some of SYM_TEXT plus symname. */
3586 new = xmalloc (strlen (symname
) + (sym_text
- word
) + 5);
3587 strncpy (new, word
, sym_text
- word
);
3588 new[sym_text
- word
] = '\0';
3589 strcat (new, symname
);
3592 /* Recheck for duplicates if we intend to add a modified symbol. */
3593 if (word
!= sym_text
)
3595 for (i
= 0; i
< return_val_index
; ++i
)
3597 if (STREQ (new, return_val
[i
]))
3605 if (return_val_index
+ 3 > return_val_size
)
3607 newsize
= (return_val_size
*= 2) * sizeof (char *);
3608 return_val
= (char **) xrealloc ((char *) return_val
, newsize
);
3610 return_val
[return_val_index
++] = new;
3611 return_val
[return_val_index
] = NULL
;
3615 /* Return a NULL terminated array of all symbols (regardless of class) which
3616 begin by matching TEXT. If the answer is no symbols, then the return value
3617 is an array which contains only a NULL pointer.
3619 Problem: All of the symbols have to be copied because readline frees them.
3620 I'm not going to worry about this; hopefully there won't be that many. */
3623 make_symbol_completion_list (text
, word
)
3627 register struct symbol
*sym
;
3628 register struct symtab
*s
;
3629 register struct partial_symtab
*ps
;
3630 register struct minimal_symbol
*msymbol
;
3631 register struct objfile
*objfile
;
3632 register struct block
*b
, *surrounding_static_block
= 0;
3634 struct partial_symbol
**psym
;
3635 /* The symbol we are completing on. Points in same buffer as text. */
3637 /* Length of sym_text. */
3640 /* Now look for the symbol we are supposed to complete on.
3641 FIXME: This should be language-specific. */
3645 char *quote_pos
= NULL
;
3647 /* First see if this is a quoted string. */
3649 for (p
= text
; *p
!= '\0'; ++p
)
3651 if (quote_found
!= '\0')
3653 if (*p
== quote_found
)
3654 /* Found close quote. */
3656 else if (*p
== '\\' && p
[1] == quote_found
)
3657 /* A backslash followed by the quote character
3658 doesn't end the string. */
3661 else if (*p
== '\'' || *p
== '"')
3667 if (quote_found
== '\'')
3668 /* A string within single quotes can be a symbol, so complete on it. */
3669 sym_text
= quote_pos
+ 1;
3670 else if (quote_found
== '"')
3671 /* A double-quoted string is never a symbol, nor does it make sense
3672 to complete it any other way. */
3676 /* It is not a quoted string. Break it based on the characters
3677 which are in symbols. */
3680 if (isalnum (p
[-1]) || p
[-1] == '_' || p
[-1] == '\0')
3689 sym_text_len
= strlen (sym_text
);
3691 return_val_size
= 100;
3692 return_val_index
= 0;
3693 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
3694 return_val
[0] = NULL
;
3696 /* Look through the partial symtabs for all symbols which begin
3697 by matching SYM_TEXT. Add each one that you find to the list. */
3699 ALL_PSYMTABS (objfile
, ps
)
3701 /* If the psymtab's been read in we'll get it when we search
3702 through the blockvector. */
3703 if (ps
->readin
) continue;
3705 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
3706 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
3707 + ps
->n_global_syms
);
3710 /* If interrupted, then quit. */
3712 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3715 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
3716 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
3717 + ps
->n_static_syms
);
3721 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3725 /* At this point scan through the misc symbol vectors and add each
3726 symbol you find to the list. Eventually we want to ignore
3727 anything that isn't a text symbol (everything else will be
3728 handled by the psymtab code above). */
3730 ALL_MSYMBOLS (objfile
, msymbol
)
3733 COMPLETION_LIST_ADD_SYMBOL (msymbol
, sym_text
, sym_text_len
, text
, word
);
3736 /* Search upwards from currently selected frame (so that we can
3737 complete on local vars. */
3739 for (b
= get_selected_block (); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
3741 if (!BLOCK_SUPERBLOCK (b
))
3743 surrounding_static_block
= b
; /* For elmin of dups */
3746 /* Also catch fields of types defined in this places which match our
3747 text string. Only complete on types visible from current context. */
3749 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3751 sym
= BLOCK_SYM (b
, i
);
3752 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3753 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3755 struct type
*t
= SYMBOL_TYPE (sym
);
3756 enum type_code c
= TYPE_CODE (t
);
3758 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
3760 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
3762 if (TYPE_FIELD_NAME (t
, j
))
3764 completion_list_add_name (TYPE_FIELD_NAME (t
, j
),
3765 sym_text
, sym_text_len
, text
, word
);
3773 /* Go through the symtabs and check the externs and statics for
3774 symbols which match. */
3776 ALL_SYMTABS (objfile
, s
)
3779 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3780 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3782 sym
= BLOCK_SYM (b
, i
);
3783 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3787 ALL_SYMTABS (objfile
, s
)
3790 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3791 /* Don't do this block twice. */
3792 if (b
== surrounding_static_block
) continue;
3793 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3795 sym
= BLOCK_SYM (b
, i
);
3796 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3800 return (return_val
);
3803 /* Determine if PC is in the prologue of a function. The prologue is the area
3804 between the first instruction of a function, and the first executable line.
3805 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
3807 If non-zero, func_start is where we think the prologue starts, possibly
3808 by previous examination of symbol table information.
3812 in_prologue (pc
, func_start
)
3814 CORE_ADDR func_start
;
3816 struct symtab_and_line sal
;
3817 CORE_ADDR func_addr
, func_end
;
3819 if (!find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
3820 goto nosyms
; /* Might be in prologue */
3822 sal
= find_pc_line (func_addr
, 0);
3827 if (sal
.end
> func_addr
3828 && sal
.end
<= func_end
) /* Is prologue in function? */
3829 return pc
< sal
.end
; /* Yes, is pc in prologue? */
3831 /* The line after the prologue seems to be outside the function. In this
3832 case, tell the caller to find the prologue the hard way. */
3836 /* Come here when symtabs don't contain line # info. In this case, it is
3837 likely that the user has stepped into a library function w/o symbols, or
3838 is doing a stepi/nexti through code without symbols. */
3842 /* If func_start is zero (meaning unknown) then we don't know whether pc is
3843 in the prologue or not. I.E. it might be. */
3845 if (!func_start
) return 1;
3847 /* We need to call the target-specific prologue skipping functions with the
3848 function's start address because PC may be pointing at an instruction that
3849 could be mistakenly considered part of the prologue. */
3851 SKIP_PROLOGUE (func_start
);
3853 return pc
< func_start
;
3858 _initialize_symtab ()
3860 add_info ("variables", variables_info
,
3861 "All global and static variable names, or those matching REGEXP.");
3862 add_info ("functions", functions_info
,
3863 "All function names, or those matching REGEXP.");
3865 /* FIXME: This command has at least the following problems:
3866 1. It prints builtin types (in a very strange and confusing fashion).
3867 2. It doesn't print right, e.g. with
3868 typedef struct foo *FOO
3869 type_print prints "FOO" when we want to make it (in this situation)
3870 print "struct foo *".
3871 I also think "ptype" or "whatis" is more likely to be useful (but if
3872 there is much disagreement "info types" can be fixed). */
3873 add_info ("types", types_info
,
3874 "All type names, or those matching REGEXP.");
3877 add_info ("methods", methods_info
,
3878 "All method names, or those matching REGEXP::REGEXP.\n\
3879 If the class qualifier is omitted, it is assumed to be the current scope.\n\
3880 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
3883 add_info ("sources", sources_info
,
3884 "Source files in the program.");
3886 add_com ("rbreak", class_breakpoint
, rbreak_command
,
3887 "Set a breakpoint for all functions matching REGEXP.");
3889 /* Initialize the one built-in type that isn't language dependent... */
3890 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
3891 "<unknown type>", (struct objfile
*) NULL
);