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,
20 Boston, MA 02111-1307, USA. */
32 #include "call-cmds.h"
33 #include "gnu-regex.h"
34 #include "expression.h"
41 #include <sys/types.h>
43 #include "gdb_string.h"
47 /* Prototype for one function in parser-defs.h,
48 instead of including that entire file. */
50 extern char *find_template_name_end
PARAMS ((char *));
52 /* Prototypes for local functions */
54 static int find_methods
PARAMS ((struct type
*, char *, struct symbol
**));
56 static void completion_list_add_name
PARAMS ((char *, char *, int, char *,
59 static void build_canonical_line_spec
PARAMS ((struct symtab_and_line
*,
62 static struct symtabs_and_lines decode_line_2
PARAMS ((struct symbol
*[],
65 static void rbreak_command
PARAMS ((char *, int));
67 static void types_info
PARAMS ((char *, int));
69 static void functions_info
PARAMS ((char *, int));
71 static void variables_info
PARAMS ((char *, int));
73 static void sources_info
PARAMS ((char *, int));
75 static void output_source_filename
PARAMS ((char *, int *));
77 char *operator_chars
PARAMS ((char *, char **));
79 static int find_line_common
PARAMS ((struct linetable
*, int, int *));
81 static struct partial_symbol
*lookup_partial_symbol PARAMS
82 ((struct partial_symtab
*, const char *,
83 int, namespace_enum
));
85 static struct partial_symbol
*fixup_psymbol_section
PARAMS ((struct
86 partial_symbol
*, struct objfile
*));
88 static struct symtab
*lookup_symtab_1
PARAMS ((char *));
90 static void cplusplus_hint
PARAMS ((char *));
92 static struct symbol
*find_active_alias
PARAMS ((struct symbol
* sym
,
95 /* This flag is used in hppa-tdep.c, and set in hp-symtab-read.c */
96 /* Signals the presence of objects compiled by HP compilers */
97 int hp_som_som_object_present
= 0;
99 static void fixup_section
PARAMS ((struct general_symbol_info
*,
102 static int file_matches
PARAMS ((char *, char **, int));
104 static void print_symbol_info
PARAMS ((namespace_enum
,
105 struct symtab
*, struct symbol
*,
108 static void print_msymbol_info
PARAMS ((struct minimal_symbol
*));
110 static void symtab_symbol_info
PARAMS ((char *, namespace_enum
, int));
112 static void overload_list_add_symbol
PARAMS ((struct symbol
* sym
,
115 void _initialize_symtab
PARAMS ((void));
119 /* The single non-language-specific builtin type */
120 struct type
*builtin_type_error
;
122 /* Block in which the most recently searched-for symbol was found.
123 Might be better to make this a parameter to lookup_symbol and
126 const struct block
*block_found
;
128 char no_symtab_msg
[] = "No symbol table is loaded. Use the \"file\" command.";
130 /* While the C++ support is still in flux, issue a possibly helpful hint on
131 using the new command completion feature on single quoted demangled C++
132 symbols. Remove when loose ends are cleaned up. FIXME -fnf */
135 cplusplus_hint (name
)
138 while (*name
== '\'')
140 printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name
, name
);
141 printf_filtered ("(Note leading single quote.)\n");
144 /* Check for a symtab of a specific name; first in symtabs, then in
145 psymtabs. *If* there is no '/' in the name, a match after a '/'
146 in the symtab filename will also work. */
148 static struct symtab
*
149 lookup_symtab_1 (name
)
152 register struct symtab
*s
;
153 register struct partial_symtab
*ps
;
154 register char *slash
;
155 register struct objfile
*objfile
;
159 /* First, search for an exact match */
161 ALL_SYMTABS (objfile
, s
)
162 if (STREQ (name
, s
->filename
))
165 slash
= strchr (name
, '/');
167 /* Now, search for a matching tail (only if name doesn't have any dirs) */
170 ALL_SYMTABS (objfile
, s
)
172 char *p
= s
->filename
;
173 char *tail
= strrchr (p
, '/');
182 /* Same search rules as above apply here, but now we look thru the
185 ps
= lookup_partial_symtab (name
);
190 error ("Internal: readin %s pst for `%s' found when no symtab found.",
193 s
= PSYMTAB_TO_SYMTAB (ps
);
198 /* At this point, we have located the psymtab for this file, but
199 the conversion to a symtab has failed. This usually happens
200 when we are looking up an include file. In this case,
201 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
202 been created. So, we need to run through the symtabs again in
203 order to find the file.
204 XXX - This is a crock, and should be fixed inside of the the
205 symbol parsing routines. */
209 /* Lookup the symbol table of a source file named NAME. Try a couple
210 of variations if the first lookup doesn't work. */
216 register struct symtab
*s
;
221 s
= lookup_symtab_1 (name
);
226 /* This screws c-exp.y:yylex if there is both a type "tree" and a symtab
229 /* If name not found as specified, see if adding ".c" helps. */
230 /* Why is this? Is it just a user convenience? (If so, it's pretty
231 questionable in the presence of C++, FORTRAN, etc.). It's not in
234 copy
= (char *) alloca (strlen (name
) + 3);
237 s
= lookup_symtab_1 (copy
);
242 /* We didn't find anything; die. */
246 /* Lookup the partial symbol table of a source file named NAME.
247 *If* there is no '/' in the name, a match after a '/'
248 in the psymtab filename will also work. */
250 struct partial_symtab
*
251 lookup_partial_symtab (name
)
254 register struct partial_symtab
*pst
;
255 register struct objfile
*objfile
;
257 ALL_PSYMTABS (objfile
, pst
)
259 if (STREQ (name
, pst
->filename
))
265 /* Now, search for a matching tail (only if name doesn't have any dirs) */
267 if (!strchr (name
, '/'))
268 ALL_PSYMTABS (objfile
, pst
)
270 char *p
= pst
->filename
;
271 char *tail
= strrchr (p
, '/');
283 /* Mangle a GDB method stub type. This actually reassembles the pieces of the
284 full method name, which consist of the class name (from T), the unadorned
285 method name from METHOD_ID, and the signature for the specific overload,
286 specified by SIGNATURE_ID. Note that this function is g++ specific. */
289 gdb_mangle_name (type
, method_id
, signature_id
)
291 int method_id
, signature_id
;
293 int mangled_name_len
;
295 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
296 struct fn_field
*method
= &f
[signature_id
];
297 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, method_id
);
298 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, signature_id
);
299 char *newname
= type_name_no_tag (type
);
301 /* Does the form of physname indicate that it is the full mangled name
302 of a constructor (not just the args)? */
303 int is_full_physname_constructor
;
306 int is_destructor
= DESTRUCTOR_PREFIX_P (physname
);
307 /* Need a new type prefix. */
308 char *const_prefix
= method
->is_const
? "C" : "";
309 char *volatile_prefix
= method
->is_volatile
? "V" : "";
311 int len
= (newname
== NULL
? 0 : strlen (newname
));
313 is_full_physname_constructor
=
314 ((physname
[0] == '_' && physname
[1] == '_' &&
315 (isdigit (physname
[2]) || physname
[2] == 'Q' || physname
[2] == 't'))
316 || (strncmp (physname
, "__ct", 4) == 0));
319 is_full_physname_constructor
|| (newname
&& STREQ (field_name
, newname
));
322 is_destructor
= (strncmp (physname
, "__dt", 4) == 0);
324 if (is_destructor
|| is_full_physname_constructor
)
326 mangled_name
= (char *) xmalloc (strlen (physname
) + 1);
327 strcpy (mangled_name
, physname
);
333 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
335 else if (physname
[0] == 't' || physname
[0] == 'Q')
337 /* The physname for template and qualified methods already includes
339 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
345 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
347 mangled_name_len
= ((is_constructor
? 0 : strlen (field_name
))
352 /* Only needed for GNU-mangled names. ANSI-mangled names
353 work with the normal mechanisms. */
354 if (OPNAME_PREFIX_P (field_name
))
356 const char *opname
= cplus_mangle_opname (field_name
+ 3, 0);
358 error ("No mangling for \"%s\"", field_name
);
359 mangled_name_len
+= strlen (opname
);
360 mangled_name
= (char *) xmalloc (mangled_name_len
);
362 strncpy (mangled_name
, field_name
, 3);
363 mangled_name
[3] = '\0';
364 strcat (mangled_name
, opname
);
368 mangled_name
= (char *) xmalloc (mangled_name_len
);
370 mangled_name
[0] = '\0';
372 strcpy (mangled_name
, field_name
);
374 strcat (mangled_name
, buf
);
375 /* If the class doesn't have a name, i.e. newname NULL, then we just
376 mangle it using 0 for the length of the class. Thus it gets mangled
377 as something starting with `::' rather than `classname::'. */
379 strcat (mangled_name
, newname
);
381 strcat (mangled_name
, physname
);
382 return (mangled_name
);
387 /* Find which partial symtab on contains PC and SECTION. Return 0 if none. */
389 struct partial_symtab
*
390 find_pc_sect_psymtab (pc
, section
)
394 register struct partial_symtab
*pst
;
395 register struct objfile
*objfile
;
397 ALL_PSYMTABS (objfile
, pst
)
399 #if defined(HPUXHPPA)
400 if (pc
>= pst
->textlow
&& pc
<= pst
->texthigh
)
402 if (pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
405 struct minimal_symbol
*msymbol
;
406 struct partial_symtab
*tpst
;
408 /* An objfile that has its functions reordered might have
409 many partial symbol tables containing the PC, but
410 we want the partial symbol table that contains the
411 function containing the PC. */
412 if (!(objfile
->flags
& OBJF_REORDERED
) &&
413 section
== 0) /* can't validate section this way */
416 msymbol
= lookup_minimal_symbol_by_pc_section (pc
, section
);
420 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
422 #if defined(HPUXHPPA)
423 if (pc
>= tpst
->textlow
&& pc
<= tpst
->texthigh
)
425 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
428 struct partial_symbol
*p
;
430 p
= find_pc_sect_psymbol (tpst
, pc
, section
);
432 && SYMBOL_VALUE_ADDRESS (p
)
433 == SYMBOL_VALUE_ADDRESS (msymbol
))
443 /* Find which partial symtab contains PC. Return 0 if none.
444 Backward compatibility, no section */
446 struct partial_symtab
*
450 return find_pc_sect_psymtab (pc
, find_pc_mapped_section (pc
));
453 /* Find which partial symbol within a psymtab matches PC and SECTION.
454 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
456 struct partial_symbol
*
457 find_pc_sect_psymbol (psymtab
, pc
, section
)
458 struct partial_symtab
*psymtab
;
462 struct partial_symbol
*best
= NULL
, *p
, **pp
;
466 psymtab
= find_pc_sect_psymtab (pc
, section
);
470 /* Cope with programs that start at address 0 */
471 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
473 /* Search the global symbols as well as the static symbols, so that
474 find_pc_partial_function doesn't use a minimal symbol and thus
475 cache a bad endaddr. */
476 for (pp
= psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
477 (pp
- (psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
478 < psymtab
->n_global_syms
);
482 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
483 && SYMBOL_CLASS (p
) == LOC_BLOCK
484 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
485 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
486 || (psymtab
->textlow
== 0
487 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
489 if (section
) /* match on a specific section */
491 fixup_psymbol_section (p
, psymtab
->objfile
);
492 if (SYMBOL_BFD_SECTION (p
) != section
)
495 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
500 for (pp
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
501 (pp
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
502 < psymtab
->n_static_syms
);
506 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
507 && SYMBOL_CLASS (p
) == LOC_BLOCK
508 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
509 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
510 || (psymtab
->textlow
== 0
511 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
513 if (section
) /* match on a specific section */
515 fixup_psymbol_section (p
, psymtab
->objfile
);
516 if (SYMBOL_BFD_SECTION (p
) != section
)
519 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
527 /* Find which partial symbol within a psymtab matches PC. Return 0 if none.
528 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
530 struct partial_symbol
*
531 find_pc_psymbol (psymtab
, pc
)
532 struct partial_symtab
*psymtab
;
535 return find_pc_sect_psymbol (psymtab
, pc
, find_pc_mapped_section (pc
));
538 /* Debug symbols usually don't have section information. We need to dig that
539 out of the minimal symbols and stash that in the debug symbol. */
542 fixup_section (ginfo
, objfile
)
543 struct general_symbol_info
*ginfo
;
544 struct objfile
*objfile
;
546 struct minimal_symbol
*msym
;
547 msym
= lookup_minimal_symbol (ginfo
->name
, NULL
, objfile
);
550 ginfo
->bfd_section
= SYMBOL_BFD_SECTION (msym
);
554 fixup_symbol_section (sym
, objfile
)
556 struct objfile
*objfile
;
561 if (SYMBOL_BFD_SECTION (sym
))
564 fixup_section (&sym
->ginfo
, objfile
);
569 static struct partial_symbol
*
570 fixup_psymbol_section (psym
, objfile
)
571 struct partial_symbol
*psym
;
572 struct objfile
*objfile
;
577 if (SYMBOL_BFD_SECTION (psym
))
580 fixup_section (&psym
->ginfo
, objfile
);
585 /* Find the definition for a specified symbol name NAME
586 in namespace NAMESPACE, visible from lexical block BLOCK.
587 Returns the struct symbol pointer, or zero if no symbol is found.
588 If SYMTAB is non-NULL, store the symbol table in which the
589 symbol was found there, or NULL if not found.
590 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
591 NAME is a field of the current implied argument `this'. If so set
592 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
593 BLOCK_FOUND is set to the block in which NAME is found (in the case of
594 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
596 /* This function has a bunch of loops in it and it would seem to be
597 attractive to put in some QUIT's (though I'm not really sure
598 whether it can run long enough to be really important). But there
599 are a few calls for which it would appear to be bad news to quit
600 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and
601 nindy_frame_chain_valid in nindy-tdep.c. (Note that there is C++
602 code below which can error(), but that probably doesn't affect
603 these calls since they are looking for a known variable and thus
604 can probably assume it will never hit the C++ code). */
607 lookup_symbol (name
, block
, namespace, is_a_field_of_this
, symtab
)
609 register const struct block
*block
;
610 const namespace_enum
namespace;
611 int *is_a_field_of_this
;
612 struct symtab
**symtab
;
614 register struct symbol
*sym
;
615 register struct symtab
*s
= NULL
;
616 register struct partial_symtab
*ps
;
617 struct blockvector
*bv
;
618 register struct objfile
*objfile
= NULL
;
619 register struct block
*b
;
620 register struct minimal_symbol
*msymbol
;
622 /* Search specified block and its superiors. */
626 sym
= lookup_block_symbol (block
, name
, namespace);
632 /* Search the list of symtabs for one which contains the
633 address of the start of this block. */
634 ALL_SYMTABS (objfile
, s
)
636 bv
= BLOCKVECTOR (s
);
637 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
638 if (BLOCK_START (b
) <= BLOCK_START (block
)
639 && BLOCK_END (b
) > BLOCK_START (block
))
646 return fixup_symbol_section (sym
, objfile
);
648 block
= BLOCK_SUPERBLOCK (block
);
651 /* FIXME: this code is never executed--block is always NULL at this
652 point. What is it trying to do, anyway? We already should have
653 checked the STATIC_BLOCK above (it is the superblock of top-level
654 blocks). Why is VAR_NAMESPACE special-cased? */
655 /* Don't need to mess with the psymtabs; if we have a block,
656 that file is read in. If we don't, then we deal later with
657 all the psymtab stuff that needs checking. */
658 /* Note (RT): The following never-executed code looks unnecessary to me also.
659 * If we change the code to use the original (passed-in)
660 * value of 'block', we could cause it to execute, but then what
661 * would it do? The STATIC_BLOCK of the symtab containing the passed-in
662 * 'block' was already searched by the above code. And the STATIC_BLOCK's
663 * of *other* symtabs (those files not containing 'block' lexically)
664 * should not contain 'block' address-wise. So we wouldn't expect this
665 * code to find any 'sym''s that were not found above. I vote for
666 * deleting the following paragraph of code.
668 if (namespace == VAR_NAMESPACE
&& block
!= NULL
)
671 /* Find the right symtab. */
672 ALL_SYMTABS (objfile
, s
)
674 bv
= BLOCKVECTOR (s
);
675 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
676 if (BLOCK_START (b
) <= BLOCK_START (block
)
677 && BLOCK_END (b
) > BLOCK_START (block
))
679 sym
= lookup_block_symbol (b
, name
, VAR_NAMESPACE
);
685 return fixup_symbol_section (sym
, objfile
);
692 /* C++: If requested to do so by the caller,
693 check to see if NAME is a field of `this'. */
694 if (is_a_field_of_this
)
696 struct value
*v
= value_of_this (0);
698 *is_a_field_of_this
= 0;
699 if (v
&& check_field (v
, name
))
701 *is_a_field_of_this
= 1;
708 /* Now search all global blocks. Do the symtab's first, then
709 check the psymtab's. If a psymtab indicates the existence
710 of the desired name as a global, then do psymtab-to-symtab
711 conversion on the fly and return the found symbol. */
713 ALL_SYMTABS (objfile
, s
)
715 bv
= BLOCKVECTOR (s
);
716 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
717 sym
= lookup_block_symbol (block
, name
, namespace);
723 return fixup_symbol_section (sym
, objfile
);
729 /* Check for the possibility of the symbol being a function or
730 a mangled variable that is stored in one of the minimal symbol tables.
731 Eventually, all global symbols might be resolved in this way. */
733 if (namespace == VAR_NAMESPACE
)
735 msymbol
= lookup_minimal_symbol (name
, NULL
, NULL
);
738 s
= find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol
),
739 SYMBOL_BFD_SECTION (msymbol
));
742 /* This is a function which has a symtab for its address. */
743 bv
= BLOCKVECTOR (s
);
744 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
745 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
747 /* We kept static functions in minimal symbol table as well as
748 in static scope. We want to find them in the symbol table. */
751 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
752 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
756 /* sym == 0 if symbol was found in the minimal symbol table
757 but not in the symtab.
758 Return 0 to use the msymbol definition of "foo_".
760 This happens for Fortran "foo_" symbols,
761 which are "foo" in the symtab.
763 This can also happen if "asm" is used to make a
764 regular symbol but not a debugging symbol, e.g.
771 return fixup_symbol_section (sym
, objfile
);
773 else if (MSYMBOL_TYPE (msymbol
) != mst_text
774 && MSYMBOL_TYPE (msymbol
) != mst_file_text
775 && !STREQ (name
, SYMBOL_NAME (msymbol
)))
777 /* This is a mangled variable, look it up by its
779 return lookup_symbol (SYMBOL_NAME (msymbol
), block
,
780 namespace, is_a_field_of_this
, symtab
);
782 /* There are no debug symbols for this file, or we are looking
783 for an unmangled variable.
784 Try to find a matching static symbol below. */
790 ALL_PSYMTABS (objfile
, ps
)
792 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
794 s
= PSYMTAB_TO_SYMTAB (ps
);
795 bv
= BLOCKVECTOR (s
);
796 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
797 sym
= lookup_block_symbol (block
, name
, namespace);
800 /* This shouldn't be necessary, but as a last resort
801 * try looking in the statics even though the psymtab
802 * claimed the symbol was global. It's possible that
803 * the psymtab gets it wrong in some cases.
805 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
806 sym
= lookup_block_symbol (block
, name
, namespace);
808 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
809 %s may be an inlined function, or may be a template function\n\
810 (if a template, try specifying an instantiation: %s<type>).",
811 name
, ps
->filename
, name
, name
);
815 return fixup_symbol_section (sym
, objfile
);
819 /* Now search all static file-level symbols.
820 Not strictly correct, but more useful than an error.
821 Do the symtabs first, then check the psymtabs.
822 If a psymtab indicates the existence
823 of the desired name as a file-level static, then do psymtab-to-symtab
824 conversion on the fly and return the found symbol. */
826 ALL_SYMTABS (objfile
, s
)
828 bv
= BLOCKVECTOR (s
);
829 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
830 sym
= lookup_block_symbol (block
, name
, namespace);
836 return fixup_symbol_section (sym
, objfile
);
840 ALL_PSYMTABS (objfile
, ps
)
842 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
844 s
= PSYMTAB_TO_SYMTAB (ps
);
845 bv
= BLOCKVECTOR (s
);
846 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
847 sym
= lookup_block_symbol (block
, name
, namespace);
850 /* This shouldn't be necessary, but as a last resort
851 * try looking in the globals even though the psymtab
852 * claimed the symbol was static. It's possible that
853 * the psymtab gets it wrong in some cases.
855 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
856 sym
= lookup_block_symbol (block
, name
, namespace);
858 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
859 %s may be an inlined function, or may be a template function\n\
860 (if a template, try specifying an instantiation: %s<type>).",
861 name
, ps
->filename
, name
, name
);
865 return fixup_symbol_section (sym
, objfile
);
871 /* Check for the possibility of the symbol being a function or
872 a global variable that is stored in one of the minimal symbol tables.
873 The "minimal symbol table" is built from linker-supplied info.
875 RT: I moved this check to last, after the complete search of
876 the global (p)symtab's and static (p)symtab's. For HP-generated
877 symbol tables, this check was causing a premature exit from
878 lookup_symbol with NULL return, and thus messing up symbol lookups
879 of things like "c::f". It seems to me a check of the minimal
880 symbol table ought to be a last resort in any case. I'm vaguely
881 worried about the comment below which talks about FORTRAN routines "foo_"
882 though... is it saying we need to do the "minsym" check before
883 the static check in this case?
886 if (namespace == VAR_NAMESPACE
)
888 msymbol
= lookup_minimal_symbol (name
, NULL
, NULL
);
891 /* OK, we found a minimal symbol in spite of not
892 * finding any symbol. There are various possible
893 * explanations for this. One possibility is the symbol
894 * exists in code not compiled -g. Another possibility
895 * is that the 'psymtab' isn't doing its job.
896 * A third possibility, related to #2, is that we were confused
897 * by name-mangling. For instance, maybe the psymtab isn't
898 * doing its job because it only know about demangled
899 * names, but we were given a mangled name...
902 /* We first use the address in the msymbol to try to
903 * locate the appropriate symtab. Note that find_pc_symtab()
904 * has a side-effect of doing psymtab-to-symtab expansion,
905 * for the found symtab.
907 s
= find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
));
910 bv
= BLOCKVECTOR (s
);
911 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
912 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
914 /* We kept static functions in minimal symbol table as well as
915 in static scope. We want to find them in the symbol table. */
918 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
919 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
922 /* If we found one, return it */
930 /* If we get here with sym == 0, the symbol was
931 found in the minimal symbol table
932 but not in the symtab.
933 Fall through and return 0 to use the msymbol
934 definition of "foo_".
935 (Note that outer code generally follows up a call
936 to this routine with a call to lookup_minimal_symbol(),
937 so a 0 return means we'll just flow into that other routine).
939 This happens for Fortran "foo_" symbols,
940 which are "foo" in the symtab.
942 This can also happen if "asm" is used to make a
943 regular symbol but not a debugging symbol, e.g.
949 /* If the lookup-by-address fails, try repeating the
950 * entire lookup process with the symbol name from
951 * the msymbol (if different from the original symbol name).
953 else if (MSYMBOL_TYPE (msymbol
) != mst_text
954 && MSYMBOL_TYPE (msymbol
) != mst_file_text
955 && !STREQ (name
, SYMBOL_NAME (msymbol
)))
957 return lookup_symbol (SYMBOL_NAME (msymbol
), block
,
958 namespace, is_a_field_of_this
, symtab
);
970 /* Look, in partial_symtab PST, for symbol NAME. Check the global
971 symbols if GLOBAL, the static symbols if not */
973 static struct partial_symbol
*
974 lookup_partial_symbol (pst
, name
, global
, namespace)
975 struct partial_symtab
*pst
;
978 namespace_enum
namespace;
980 struct partial_symbol
**start
, **psym
;
981 struct partial_symbol
**top
, **bottom
, **center
;
982 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
983 int do_linear_search
= 1;
991 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
992 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
994 if (global
) /* This means we can use a binary search. */
996 do_linear_search
= 0;
998 /* Binary search. This search is guaranteed to end with center
999 pointing at the earliest partial symbol with the correct
1000 name. At that point *all* partial symbols with that name
1001 will be checked against the correct namespace. */
1004 top
= start
+ length
- 1;
1005 while (top
> bottom
)
1007 center
= bottom
+ (top
- bottom
) / 2;
1008 if (!(center
< top
))
1010 if (!do_linear_search
1011 && (SYMBOL_LANGUAGE (*center
) == language_cplus
1012 || SYMBOL_LANGUAGE (*center
) == language_java
1015 do_linear_search
= 1;
1017 if (STRCMP (SYMBOL_NAME (*center
), name
) >= 0)
1023 bottom
= center
+ 1;
1026 if (!(top
== bottom
))
1028 while (STREQ (SYMBOL_NAME (*top
), name
))
1030 if (SYMBOL_NAMESPACE (*top
) == namespace)
1038 /* Can't use a binary search or else we found during the binary search that
1039 we should also do a linear search. */
1041 if (do_linear_search
)
1043 for (psym
= start
; psym
< start
+ length
; psym
++)
1045 if (namespace == SYMBOL_NAMESPACE (*psym
))
1047 if (SYMBOL_MATCHES_NAME (*psym
, name
))
1058 /* Look up a type named NAME in the struct_namespace. The type returned
1059 must not be opaque -- i.e., must have at least one field defined
1061 This code was modelled on lookup_symbol -- the parts not relevant to looking
1062 up types were just left out. In particular it's assumed here that types
1063 are available in struct_namespace and only at file-static or global blocks. */
1067 lookup_transparent_type (name
)
1070 register struct symbol
*sym
;
1071 register struct symtab
*s
= NULL
;
1072 register struct partial_symtab
*ps
;
1073 struct blockvector
*bv
;
1074 register struct objfile
*objfile
;
1075 register struct block
*block
;
1076 register struct minimal_symbol
*msymbol
;
1078 /* Now search all the global symbols. Do the symtab's first, then
1079 check the psymtab's. If a psymtab indicates the existence
1080 of the desired name as a global, then do psymtab-to-symtab
1081 conversion on the fly and return the found symbol. */
1083 ALL_SYMTABS (objfile
, s
)
1085 bv
= BLOCKVECTOR (s
);
1086 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1087 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1088 if (sym
&& !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1090 return SYMBOL_TYPE (sym
);
1094 ALL_PSYMTABS (objfile
, ps
)
1096 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, STRUCT_NAMESPACE
))
1098 s
= PSYMTAB_TO_SYMTAB (ps
);
1099 bv
= BLOCKVECTOR (s
);
1100 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1101 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1104 /* This shouldn't be necessary, but as a last resort
1105 * try looking in the statics even though the psymtab
1106 * claimed the symbol was global. It's possible that
1107 * the psymtab gets it wrong in some cases.
1109 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1110 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1112 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
1113 %s may be an inlined function, or may be a template function\n\
1114 (if a template, try specifying an instantiation: %s<type>).",
1115 name
, ps
->filename
, name
, name
);
1117 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1118 return SYMBOL_TYPE (sym
);
1122 /* Now search the static file-level symbols.
1123 Not strictly correct, but more useful than an error.
1124 Do the symtab's first, then
1125 check the psymtab's. If a psymtab indicates the existence
1126 of the desired name as a file-level static, then do psymtab-to-symtab
1127 conversion on the fly and return the found symbol.
1130 ALL_SYMTABS (objfile
, s
)
1132 bv
= BLOCKVECTOR (s
);
1133 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1134 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1135 if (sym
&& !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1137 return SYMBOL_TYPE (sym
);
1141 ALL_PSYMTABS (objfile
, ps
)
1143 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, STRUCT_NAMESPACE
))
1145 s
= PSYMTAB_TO_SYMTAB (ps
);
1146 bv
= BLOCKVECTOR (s
);
1147 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1148 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1151 /* This shouldn't be necessary, but as a last resort
1152 * try looking in the globals even though the psymtab
1153 * claimed the symbol was static. It's possible that
1154 * the psymtab gets it wrong in some cases.
1156 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1157 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1159 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
1160 %s may be an inlined function, or may be a template function\n\
1161 (if a template, try specifying an instantiation: %s<type>).",
1162 name
, ps
->filename
, name
, name
);
1164 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1165 return SYMBOL_TYPE (sym
);
1168 return (struct type
*) 0;
1172 /* Find the psymtab containing main(). */
1173 /* FIXME: What about languages without main() or specially linked
1174 executables that have no main() ? */
1176 struct partial_symtab
*
1177 find_main_psymtab ()
1179 register struct partial_symtab
*pst
;
1180 register struct objfile
*objfile
;
1182 ALL_PSYMTABS (objfile
, pst
)
1184 if (lookup_partial_symbol (pst
, "main", 1, VAR_NAMESPACE
))
1192 /* Search BLOCK for symbol NAME in NAMESPACE.
1194 Note that if NAME is the demangled form of a C++ symbol, we will fail
1195 to find a match during the binary search of the non-encoded names, but
1196 for now we don't worry about the slight inefficiency of looking for
1197 a match we'll never find, since it will go pretty quick. Once the
1198 binary search terminates, we drop through and do a straight linear
1199 search on the symbols. Each symbol which is marked as being a C++
1200 symbol (language_cplus set) has both the encoded and non-encoded names
1201 tested for a match. */
1204 lookup_block_symbol (block
, name
, namespace)
1205 register const struct block
*block
;
1207 const namespace_enum
namespace;
1209 register int bot
, top
, inc
;
1210 register struct symbol
*sym
;
1211 register struct symbol
*sym_found
= NULL
;
1212 register int do_linear_search
= 1;
1214 /* If the blocks's symbols were sorted, start with a binary search. */
1216 if (BLOCK_SHOULD_SORT (block
))
1218 /* Reset the linear search flag so if the binary search fails, we
1219 won't do the linear search once unless we find some reason to
1220 do so, such as finding a C++ symbol during the binary search.
1221 Note that for C++ modules, ALL the symbols in a block should
1222 end up marked as C++ symbols. */
1224 do_linear_search
= 0;
1225 top
= BLOCK_NSYMS (block
);
1228 /* Advance BOT to not far before the first symbol whose name is NAME. */
1232 inc
= (top
- bot
+ 1);
1233 /* No need to keep binary searching for the last few bits worth. */
1238 inc
= (inc
>> 1) + bot
;
1239 sym
= BLOCK_SYM (block
, inc
);
1240 if (!do_linear_search
1241 && (SYMBOL_LANGUAGE (sym
) == language_cplus
1242 || SYMBOL_LANGUAGE (sym
) == language_java
1245 do_linear_search
= 1;
1247 if (SYMBOL_NAME (sym
)[0] < name
[0])
1251 else if (SYMBOL_NAME (sym
)[0] > name
[0])
1255 else if (STRCMP (SYMBOL_NAME (sym
), name
) < 0)
1265 /* Now scan forward until we run out of symbols, find one whose
1266 name is greater than NAME, or find one we want. If there is
1267 more than one symbol with the right name and namespace, we
1268 return the first one; I believe it is now impossible for us
1269 to encounter two symbols with the same name and namespace
1270 here, because blocks containing argument symbols are no
1273 top
= BLOCK_NSYMS (block
);
1276 sym
= BLOCK_SYM (block
, bot
);
1277 inc
= SYMBOL_NAME (sym
)[0] - name
[0];
1280 inc
= STRCMP (SYMBOL_NAME (sym
), name
);
1282 if (inc
== 0 && SYMBOL_NAMESPACE (sym
) == namespace)
1294 /* Here if block isn't sorted, or we fail to find a match during the
1295 binary search above. If during the binary search above, we find a
1296 symbol which is a C++ symbol, then we have re-enabled the linear
1297 search flag which was reset when starting the binary search.
1299 This loop is equivalent to the loop above, but hacked greatly for speed.
1301 Note that parameter symbols do not always show up last in the
1302 list; this loop makes sure to take anything else other than
1303 parameter symbols first; it only uses parameter symbols as a
1304 last resort. Note that this only takes up extra computation
1307 if (do_linear_search
)
1309 top
= BLOCK_NSYMS (block
);
1313 sym
= BLOCK_SYM (block
, bot
);
1314 if (SYMBOL_NAMESPACE (sym
) == namespace &&
1315 SYMBOL_MATCHES_NAME (sym
, name
))
1317 /* If SYM has aliases, then use any alias that is active
1318 at the current PC. If no alias is active at the current
1319 PC, then use the main symbol.
1321 ?!? Is checking the current pc correct? Is this routine
1322 ever called to look up a symbol from another context?
1324 FIXME: No, it's not correct. If someone sets a
1325 conditional breakpoint at an address, then the
1326 breakpoint's `struct expression' should refer to the
1327 `struct symbol' appropriate for the breakpoint's
1328 address, which may not be the PC.
1330 Even if it were never called from another context,
1331 it's totally bizarre for lookup_symbol's behavior to
1332 depend on the value of the inferior's current PC. We
1333 should pass in the appropriate PC as well as the
1334 block. The interface to lookup_symbol should change
1335 to require the caller to provide a PC. */
1337 if (SYMBOL_ALIASES (sym
))
1338 sym
= find_active_alias (sym
, read_pc ());
1341 if (SYMBOL_CLASS (sym
) != LOC_ARG
&&
1342 SYMBOL_CLASS (sym
) != LOC_LOCAL_ARG
&&
1343 SYMBOL_CLASS (sym
) != LOC_REF_ARG
&&
1344 SYMBOL_CLASS (sym
) != LOC_REGPARM
&&
1345 SYMBOL_CLASS (sym
) != LOC_REGPARM_ADDR
&&
1346 SYMBOL_CLASS (sym
) != LOC_BASEREG_ARG
)
1354 return (sym_found
); /* Will be NULL if not found. */
1357 /* Given a main symbol SYM and ADDR, search through the alias
1358 list to determine if an alias is active at ADDR and return
1361 If no alias is active, then return SYM. */
1363 static struct symbol
*
1364 find_active_alias (sym
, addr
)
1368 struct range_list
*r
;
1369 struct alias_list
*aliases
;
1371 /* If we have aliases, check them first. */
1372 aliases
= SYMBOL_ALIASES (sym
);
1376 if (!SYMBOL_RANGES (aliases
->sym
))
1377 return aliases
->sym
;
1378 for (r
= SYMBOL_RANGES (aliases
->sym
); r
; r
= r
->next
)
1380 if (r
->start
<= addr
&& r
->end
> addr
)
1381 return aliases
->sym
;
1383 aliases
= aliases
->next
;
1386 /* Nothing found, return the main symbol. */
1391 /* Return the symbol for the function which contains a specified
1392 lexical block, described by a struct block BL. */
1398 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
1399 bl
= BLOCK_SUPERBLOCK (bl
);
1401 return BLOCK_FUNCTION (bl
);
1404 /* Find the symtab associated with PC and SECTION. Look through the
1405 psymtabs and read in another symtab if necessary. */
1408 find_pc_sect_symtab (pc
, section
)
1412 register struct block
*b
;
1413 struct blockvector
*bv
;
1414 register struct symtab
*s
= NULL
;
1415 register struct symtab
*best_s
= NULL
;
1416 register struct partial_symtab
*ps
;
1417 register struct objfile
*objfile
;
1418 CORE_ADDR distance
= 0;
1420 /* Search all symtabs for the one whose file contains our address, and which
1421 is the smallest of all the ones containing the address. This is designed
1422 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1423 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1424 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1426 This happens for native ecoff format, where code from included files
1427 gets its own symtab. The symtab for the included file should have
1428 been read in already via the dependency mechanism.
1429 It might be swifter to create several symtabs with the same name
1430 like xcoff does (I'm not sure).
1432 It also happens for objfiles that have their functions reordered.
1433 For these, the symtab we are looking for is not necessarily read in. */
1435 ALL_SYMTABS (objfile
, s
)
1437 bv
= BLOCKVECTOR (s
);
1438 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1440 if (BLOCK_START (b
) <= pc
1441 #if defined(HPUXHPPA)
1442 && BLOCK_END (b
) >= pc
1444 && BLOCK_END (b
) > pc
1447 || BLOCK_END (b
) - BLOCK_START (b
) < distance
))
1449 /* For an objfile that has its functions reordered,
1450 find_pc_psymtab will find the proper partial symbol table
1451 and we simply return its corresponding symtab. */
1452 /* In order to better support objfiles that contain both
1453 stabs and coff debugging info, we continue on if a psymtab
1455 if ((objfile
->flags
& OBJF_REORDERED
) && objfile
->psymtabs
)
1457 ps
= find_pc_sect_psymtab (pc
, section
);
1459 return PSYMTAB_TO_SYMTAB (ps
);
1465 for (i
= 0; i
< b
->nsyms
; i
++)
1467 fixup_symbol_section (b
->sym
[i
], objfile
);
1468 if (section
== SYMBOL_BFD_SECTION (b
->sym
[i
]))
1472 continue; /* no symbol in this symtab matches section */
1474 distance
= BLOCK_END (b
) - BLOCK_START (b
);
1483 ps
= find_pc_sect_psymtab (pc
, section
);
1487 /* Might want to error() here (in case symtab is corrupt and
1488 will cause a core dump), but maybe we can successfully
1489 continue, so let's not. */
1490 /* FIXME-32x64: assumes pc fits in a long */
1492 (Internal error: pc 0x%lx in read in psymtab, but not in symtab.)\n",
1493 (unsigned long) pc
);
1494 s
= PSYMTAB_TO_SYMTAB (ps
);
1499 /* Find the symtab associated with PC. Look through the psymtabs and
1500 read in another symtab if necessary. Backward compatibility, no section */
1506 return find_pc_sect_symtab (pc
, find_pc_mapped_section (pc
));
1512 /* Find the closest symbol value (of any sort -- function or variable)
1513 for a given address value. Slow but complete. (currently unused,
1514 mainly because it is too slow. We could fix it if each symtab and
1515 psymtab had contained in it the addresses ranges of each of its
1516 sections, which also would be required to make things like "info
1517 line *0x2345" cause psymtabs to be converted to symtabs). */
1520 find_addr_symbol (addr
, symtabp
, symaddrp
)
1522 struct symtab
**symtabp
;
1523 CORE_ADDR
*symaddrp
;
1525 struct symtab
*symtab
, *best_symtab
;
1526 struct objfile
*objfile
;
1527 register int bot
, top
;
1528 register struct symbol
*sym
;
1529 register CORE_ADDR sym_addr
;
1530 struct block
*block
;
1533 /* Info on best symbol seen so far */
1535 register CORE_ADDR best_sym_addr
= 0;
1536 struct symbol
*best_sym
= 0;
1538 /* FIXME -- we should pull in all the psymtabs, too! */
1539 ALL_SYMTABS (objfile
, symtab
)
1541 /* Search the global and static blocks in this symtab for
1542 the closest symbol-address to the desired address. */
1544 for (blocknum
= GLOBAL_BLOCK
; blocknum
<= STATIC_BLOCK
; blocknum
++)
1547 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab
), blocknum
);
1548 top
= BLOCK_NSYMS (block
);
1549 for (bot
= 0; bot
< top
; bot
++)
1551 sym
= BLOCK_SYM (block
, bot
);
1552 switch (SYMBOL_CLASS (sym
))
1556 sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1560 sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1561 /* An indirect symbol really lives at *sym_addr,
1562 * so an indirection needs to be done.
1563 * However, I am leaving this commented out because it's
1564 * expensive, and it's possible that symbolization
1565 * could be done without an active process (in
1566 * case this read_memory will fail). RT
1567 sym_addr = read_memory_unsigned_integer
1568 (sym_addr, TARGET_PTR_BIT / TARGET_CHAR_BIT);
1573 sym_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1580 if (sym_addr
<= addr
)
1581 if (sym_addr
> best_sym_addr
)
1583 /* Quit if we found an exact match. */
1585 best_sym_addr
= sym_addr
;
1586 best_symtab
= symtab
;
1587 if (sym_addr
== addr
)
1596 *symtabp
= best_symtab
;
1598 *symaddrp
= best_sym_addr
;
1603 /* Find the source file and line number for a given PC value and section.
1604 Return a structure containing a symtab pointer, a line number,
1605 and a pc range for the entire source line.
1606 The value's .pc field is NOT the specified pc.
1607 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1608 use the line that ends there. Otherwise, in that case, the line
1609 that begins there is used. */
1611 /* The big complication here is that a line may start in one file, and end just
1612 before the start of another file. This usually occurs when you #include
1613 code in the middle of a subroutine. To properly find the end of a line's PC
1614 range, we must search all symtabs associated with this compilation unit, and
1615 find the one whose first PC is closer than that of the next line in this
1618 /* If it's worth the effort, we could be using a binary search. */
1620 struct symtab_and_line
1621 find_pc_sect_line (pc
, section
, notcurrent
)
1623 struct sec
*section
;
1627 register struct linetable
*l
;
1630 register struct linetable_entry
*item
;
1631 struct symtab_and_line val
;
1632 struct blockvector
*bv
;
1633 struct minimal_symbol
*msymbol
;
1634 struct minimal_symbol
*mfunsym
;
1636 /* Info on best line seen so far, and where it starts, and its file. */
1638 struct linetable_entry
*best
= NULL
;
1639 CORE_ADDR best_end
= 0;
1640 struct symtab
*best_symtab
= 0;
1642 /* Store here the first line number
1643 of a file which contains the line at the smallest pc after PC.
1644 If we don't find a line whose range contains PC,
1645 we will use a line one less than this,
1646 with a range from the start of that file to the first line's pc. */
1647 struct linetable_entry
*alt
= NULL
;
1648 struct symtab
*alt_symtab
= 0;
1650 /* Info on best line seen in this file. */
1652 struct linetable_entry
*prev
;
1654 /* If this pc is not from the current frame,
1655 it is the address of the end of a call instruction.
1656 Quite likely that is the start of the following statement.
1657 But what we want is the statement containing the instruction.
1658 Fudge the pc to make sure we get that. */
1660 INIT_SAL (&val
); /* initialize to zeroes */
1665 /* elz: added this because this function returned the wrong
1666 information if the pc belongs to a stub (import/export)
1667 to call a shlib function. This stub would be anywhere between
1668 two functions in the target, and the line info was erroneously
1669 taken to be the one of the line before the pc.
1671 /* RT: Further explanation:
1673 * We have stubs (trampolines) inserted between procedures.
1675 * Example: "shr1" exists in a shared library, and a "shr1" stub also
1676 * exists in the main image.
1678 * In the minimal symbol table, we have a bunch of symbols
1679 * sorted by start address. The stubs are marked as "trampoline",
1680 * the others appear as text. E.g.:
1682 * Minimal symbol table for main image
1683 * main: code for main (text symbol)
1684 * shr1: stub (trampoline symbol)
1685 * foo: code for foo (text symbol)
1687 * Minimal symbol table for "shr1" image:
1689 * shr1: code for shr1 (text symbol)
1692 * So the code below is trying to detect if we are in the stub
1693 * ("shr1" stub), and if so, find the real code ("shr1" trampoline),
1694 * and if found, do the symbolization from the real-code address
1695 * rather than the stub address.
1697 * Assumptions being made about the minimal symbol table:
1698 * 1. lookup_minimal_symbol_by_pc() will return a trampoline only
1699 * if we're really in the trampoline. If we're beyond it (say
1700 * we're in "foo" in the above example), it'll have a closer
1701 * symbol (the "foo" text symbol for example) and will not
1702 * return the trampoline.
1703 * 2. lookup_minimal_symbol_text() will find a real text symbol
1704 * corresponding to the trampoline, and whose address will
1705 * be different than the trampoline address. I put in a sanity
1706 * check for the address being the same, to avoid an
1707 * infinite recursion.
1709 msymbol
= lookup_minimal_symbol_by_pc (pc
);
1710 if (msymbol
!= NULL
)
1711 if (MSYMBOL_TYPE (msymbol
) == mst_solib_trampoline
)
1713 mfunsym
= lookup_minimal_symbol_text (SYMBOL_NAME (msymbol
), NULL
, NULL
);
1714 if (mfunsym
== NULL
)
1715 /* I eliminated this warning since it is coming out
1716 * in the following situation:
1717 * gdb shmain // test program with shared libraries
1718 * (gdb) break shr1 // function in shared lib
1719 * Warning: In stub for ...
1720 * In the above situation, the shared lib is not loaded yet,
1721 * so of course we can't find the real func/line info,
1722 * but the "break" still works, and the warning is annoying.
1723 * So I commented out the warning. RT */
1724 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_NAME(msymbol)) */ ;
1726 else if (SYMBOL_VALUE (mfunsym
) == SYMBOL_VALUE (msymbol
))
1727 /* Avoid infinite recursion */
1728 /* See above comment about why warning is commented out */
1729 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_NAME(msymbol)) */ ;
1732 return find_pc_line (SYMBOL_VALUE (mfunsym
), 0);
1736 s
= find_pc_sect_symtab (pc
, section
);
1739 /* if no symbol information, return previous pc */
1746 bv
= BLOCKVECTOR (s
);
1748 /* Look at all the symtabs that share this blockvector.
1749 They all have the same apriori range, that we found was right;
1750 but they have different line tables. */
1752 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1754 /* Find the best line in this symtab. */
1761 /* I think len can be zero if the symtab lacks line numbers
1762 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
1763 I'm not sure which, and maybe it depends on the symbol
1769 item
= l
->item
; /* Get first line info */
1771 /* Is this file's first line closer than the first lines of other files?
1772 If so, record this file, and its first line, as best alternate. */
1773 if (item
->pc
> pc
&& (!alt
|| item
->pc
< alt
->pc
))
1779 for (i
= 0; i
< len
; i
++, item
++)
1781 /* Leave prev pointing to the linetable entry for the last line
1782 that started at or before PC. */
1789 /* At this point, prev points at the line whose start addr is <= pc, and
1790 item points at the next line. If we ran off the end of the linetable
1791 (pc >= start of the last line), then prev == item. If pc < start of
1792 the first line, prev will not be set. */
1794 /* Is this file's best line closer than the best in the other files?
1795 If so, record this file, and its best line, as best so far. */
1797 if (prev
&& (!best
|| prev
->pc
> best
->pc
))
1801 /* If another line is in the linetable, and its PC is closer
1802 than the best_end we currently have, take it as best_end. */
1803 if (i
< len
&& (best_end
== 0 || best_end
> item
->pc
))
1804 best_end
= item
->pc
;
1811 { /* If we didn't find any line # info, just
1817 val
.symtab
= alt_symtab
;
1818 val
.line
= alt
->line
- 1;
1820 /* Don't return line 0, that means that we didn't find the line. */
1824 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1830 val
.symtab
= best_symtab
;
1831 val
.line
= best
->line
;
1833 if (best_end
&& (!alt
|| best_end
< alt
->pc
))
1838 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1840 val
.section
= section
;
1844 /* Backward compatibility (no section) */
1846 struct symtab_and_line
1847 find_pc_line (pc
, notcurrent
)
1853 section
= find_pc_overlay (pc
);
1854 if (pc_in_unmapped_range (pc
, section
))
1855 pc
= overlay_mapped_address (pc
, section
);
1856 return find_pc_sect_line (pc
, section
, notcurrent
);
1860 static struct symtab
*find_line_symtab
PARAMS ((struct symtab
*, int,
1863 /* Find line number LINE in any symtab whose name is the same as
1866 If found, return the symtab that contains the linetable in which it was
1867 found, set *INDEX to the index in the linetable of the best entry
1868 found, and set *EXACT_MATCH nonzero if the value returned is an
1871 If not found, return NULL. */
1873 static struct symtab
*
1874 find_line_symtab (symtab
, line
, index
, exact_match
)
1875 struct symtab
*symtab
;
1882 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
1886 struct linetable
*best_linetable
;
1887 struct symtab
*best_symtab
;
1889 /* First try looking it up in the given symtab. */
1890 best_linetable
= LINETABLE (symtab
);
1891 best_symtab
= symtab
;
1892 best_index
= find_line_common (best_linetable
, line
, &exact
);
1893 if (best_index
< 0 || !exact
)
1895 /* Didn't find an exact match. So we better keep looking for
1896 another symtab with the same name. In the case of xcoff,
1897 multiple csects for one source file (produced by IBM's FORTRAN
1898 compiler) produce multiple symtabs (this is unavoidable
1899 assuming csects can be at arbitrary places in memory and that
1900 the GLOBAL_BLOCK of a symtab has a begin and end address). */
1902 /* BEST is the smallest linenumber > LINE so far seen,
1903 or 0 if none has been seen so far.
1904 BEST_INDEX and BEST_LINETABLE identify the item for it. */
1907 struct objfile
*objfile
;
1910 if (best_index
>= 0)
1911 best
= best_linetable
->item
[best_index
].line
;
1915 ALL_SYMTABS (objfile
, s
)
1917 struct linetable
*l
;
1920 if (!STREQ (symtab
->filename
, s
->filename
))
1923 ind
= find_line_common (l
, line
, &exact
);
1933 if (best
== 0 || l
->item
[ind
].line
< best
)
1935 best
= l
->item
[ind
].line
;
1948 *index
= best_index
;
1950 *exact_match
= exact
;
1955 /* Set the PC value for a given source file and line number and return true.
1956 Returns zero for invalid line number (and sets the PC to 0).
1957 The source file is specified with a struct symtab. */
1960 find_line_pc (symtab
, line
, pc
)
1961 struct symtab
*symtab
;
1965 struct linetable
*l
;
1972 symtab
= find_line_symtab (symtab
, line
, &ind
, NULL
);
1975 l
= LINETABLE (symtab
);
1976 *pc
= l
->item
[ind
].pc
;
1983 /* Find the range of pc values in a line.
1984 Store the starting pc of the line into *STARTPTR
1985 and the ending pc (start of next line) into *ENDPTR.
1986 Returns 1 to indicate success.
1987 Returns 0 if could not find the specified line. */
1990 find_line_pc_range (sal
, startptr
, endptr
)
1991 struct symtab_and_line sal
;
1992 CORE_ADDR
*startptr
, *endptr
;
1994 CORE_ADDR startaddr
;
1995 struct symtab_and_line found_sal
;
1998 if (startaddr
== 0 && !find_line_pc (sal
.symtab
, sal
.line
, &startaddr
))
2001 /* This whole function is based on address. For example, if line 10 has
2002 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
2003 "info line *0x123" should say the line goes from 0x100 to 0x200
2004 and "info line *0x355" should say the line goes from 0x300 to 0x400.
2005 This also insures that we never give a range like "starts at 0x134
2006 and ends at 0x12c". */
2008 found_sal
= find_pc_sect_line (startaddr
, sal
.section
, 0);
2009 if (found_sal
.line
!= sal
.line
)
2011 /* The specified line (sal) has zero bytes. */
2012 *startptr
= found_sal
.pc
;
2013 *endptr
= found_sal
.pc
;
2017 *startptr
= found_sal
.pc
;
2018 *endptr
= found_sal
.end
;
2023 /* Given a line table and a line number, return the index into the line
2024 table for the pc of the nearest line whose number is >= the specified one.
2025 Return -1 if none is found. The value is >= 0 if it is an index.
2027 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
2030 find_line_common (l
, lineno
, exact_match
)
2031 register struct linetable
*l
;
2032 register int lineno
;
2038 /* BEST is the smallest linenumber > LINENO so far seen,
2039 or 0 if none has been seen so far.
2040 BEST_INDEX identifies the item for it. */
2042 int best_index
= -1;
2051 for (i
= 0; i
< len
; i
++)
2053 register struct linetable_entry
*item
= &(l
->item
[i
]);
2055 if (item
->line
== lineno
)
2057 /* Return the first (lowest address) entry which matches. */
2062 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
2069 /* If we got here, we didn't get an exact match. */
2076 find_pc_line_pc_range (pc
, startptr
, endptr
)
2078 CORE_ADDR
*startptr
, *endptr
;
2080 struct symtab_and_line sal
;
2081 sal
= find_pc_line (pc
, 0);
2084 return sal
.symtab
!= 0;
2087 /* Given a function symbol SYM, find the symtab and line for the start
2089 If the argument FUNFIRSTLINE is nonzero, we want the first line
2090 of real code inside the function. */
2092 static struct symtab_and_line
2093 find_function_start_sal
PARAMS ((struct symbol
* sym
, int));
2095 static struct symtab_and_line
2096 find_function_start_sal (sym
, funfirstline
)
2101 struct symtab_and_line sal
;
2103 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
2104 fixup_symbol_section (sym
, NULL
);
2106 { /* skip "first line" of function (which is actually its prologue) */
2107 asection
*section
= SYMBOL_BFD_SECTION (sym
);
2108 /* If function is in an unmapped overlay, use its unmapped LMA
2109 address, so that SKIP_PROLOGUE has something unique to work on */
2110 if (section_is_overlay (section
) &&
2111 !section_is_mapped (section
))
2112 pc
= overlay_unmapped_address (pc
, section
);
2114 pc
+= FUNCTION_START_OFFSET
;
2115 pc
= SKIP_PROLOGUE (pc
);
2117 /* For overlays, map pc back into its mapped VMA range */
2118 pc
= overlay_mapped_address (pc
, section
);
2120 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
2122 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2123 /* Convex: no need to suppress code on first line, if any */
2126 /* Check if SKIP_PROLOGUE left us in mid-line, and the next
2127 line is still part of the same function. */
2129 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) <= sal
.end
2130 && sal
.end
< BLOCK_END (SYMBOL_BLOCK_VALUE (sym
)))
2132 /* First pc of next line */
2134 /* Recalculate the line number (might not be N+1). */
2135 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
2143 /* If P is of the form "operator[ \t]+..." where `...' is
2144 some legitimate operator text, return a pointer to the
2145 beginning of the substring of the operator text.
2146 Otherwise, return "". */
2148 operator_chars (p
, end
)
2153 if (strncmp (p
, "operator", 8))
2157 /* Don't get faked out by `operator' being part of a longer
2159 if (isalpha (*p
) || *p
== '_' || *p
== '$' || *p
== '\0')
2162 /* Allow some whitespace between `operator' and the operator symbol. */
2163 while (*p
== ' ' || *p
== '\t')
2166 /* Recognize 'operator TYPENAME'. */
2168 if (isalpha (*p
) || *p
== '_' || *p
== '$')
2170 register char *q
= p
+ 1;
2171 while (isalnum (*q
) || *q
== '_' || *q
== '$')
2196 if (p
[1] == '=' || p
[1] == p
[0])
2207 error ("`operator ()' must be specified without whitespace in `()'");
2212 error ("`operator ?:' must be specified without whitespace in `?:'");
2217 error ("`operator []' must be specified without whitespace in `[]'");
2221 error ("`operator %s' not supported", p
);
2228 /* Return the number of methods described for TYPE, including the
2229 methods from types it derives from. This can't be done in the symbol
2230 reader because the type of the baseclass might still be stubbed
2231 when the definition of the derived class is parsed. */
2233 static int total_number_of_methods
PARAMS ((struct type
* type
));
2236 total_number_of_methods (type
)
2242 CHECK_TYPEDEF (type
);
2243 if (TYPE_CPLUS_SPECIFIC (type
) == NULL
)
2245 count
= TYPE_NFN_FIELDS_TOTAL (type
);
2247 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2248 count
+= total_number_of_methods (TYPE_BASECLASS (type
, n
));
2253 /* Recursive helper function for decode_line_1.
2254 Look for methods named NAME in type T.
2255 Return number of matches.
2256 Put matches in SYM_ARR, which should have been allocated with
2257 a size of total_number_of_methods (T) * sizeof (struct symbol *).
2258 Note that this function is g++ specific. */
2261 find_methods (t
, name
, sym_arr
)
2264 struct symbol
**sym_arr
;
2268 struct symbol
*sym_class
;
2269 char *class_name
= type_name_no_tag (t
);
2271 /* Ignore this class if it doesn't have a name. This is ugly, but
2272 unless we figure out how to get the physname without the name of
2273 the class, then the loop can't do any good. */
2275 && (sym_class
= lookup_symbol (class_name
,
2276 (struct block
*) NULL
,
2279 (struct symtab
**) NULL
)))
2283 /* FIXME: Shouldn't this just be CHECK_TYPEDEF (t)? */
2284 t
= SYMBOL_TYPE (sym_class
);
2286 /* Loop over each method name. At this level, all overloads of a name
2287 are counted as a single name. There is an inner loop which loops over
2290 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
2291 method_counter
>= 0;
2295 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
2296 char dem_opname
[64];
2298 if (strncmp (method_name
, "__", 2) == 0 ||
2299 strncmp (method_name
, "op", 2) == 0 ||
2300 strncmp (method_name
, "type", 4) == 0)
2302 if (cplus_demangle_opname (method_name
, dem_opname
, DMGL_ANSI
))
2303 method_name
= dem_opname
;
2304 else if (cplus_demangle_opname (method_name
, dem_opname
, 0))
2305 method_name
= dem_opname
;
2308 if (STREQ (name
, method_name
))
2309 /* Find all the overloaded methods with that name. */
2310 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
2317 f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
2319 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
2323 tmp_name
= gdb_mangle_name (t
,
2326 phys_name
= alloca (strlen (tmp_name
) + 1);
2327 strcpy (phys_name
, tmp_name
);
2331 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
2333 /* Destructor is handled by caller, dont add it to the list */
2334 if (DESTRUCTOR_PREFIX_P (phys_name
))
2337 sym_arr
[i1
] = lookup_symbol (phys_name
,
2338 NULL
, VAR_NAMESPACE
,
2340 (struct symtab
**) NULL
);
2345 /* This error message gets printed, but the method
2346 still seems to be found
2347 fputs_filtered("(Cannot find method ", gdb_stdout);
2348 fprintf_symbol_filtered (gdb_stdout, phys_name,
2350 DMGL_PARAMS | DMGL_ANSI);
2351 fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
2358 /* Only search baseclasses if there is no match yet, since names in
2359 derived classes override those in baseclasses.
2361 FIXME: The above is not true; it is only true of member functions
2362 if they have the same number of arguments (??? - section 13.1 of the
2363 ARM says the function members are not in the same scope but doesn't
2364 really spell out the rules in a way I understand. In any case, if
2365 the number of arguments differ this is a case in which we can overload
2366 rather than hiding without any problem, and gcc 2.4.5 does overload
2367 rather than hiding in this case). */
2370 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
2371 i1
+= find_methods (TYPE_BASECLASS (t
, ibase
), name
, sym_arr
+ i1
);
2376 /* Helper function for decode_line_1.
2377 Build a canonical line spec in CANONICAL if it is non-NULL and if
2378 the SAL has a symtab.
2379 If SYMNAME is non-NULL the canonical line spec is `filename:symname'.
2380 If SYMNAME is NULL the line number from SAL is used and the canonical
2381 line spec is `filename:linenum'. */
2384 build_canonical_line_spec (sal
, symname
, canonical
)
2385 struct symtab_and_line
*sal
;
2389 char **canonical_arr
;
2390 char *canonical_name
;
2392 struct symtab
*s
= sal
->symtab
;
2394 if (s
== (struct symtab
*) NULL
2395 || s
->filename
== (char *) NULL
2396 || canonical
== (char ***) NULL
)
2399 canonical_arr
= (char **) xmalloc (sizeof (char *));
2400 *canonical
= canonical_arr
;
2402 filename
= s
->filename
;
2403 if (symname
!= NULL
)
2405 canonical_name
= xmalloc (strlen (filename
) + strlen (symname
) + 2);
2406 sprintf (canonical_name
, "%s:%s", filename
, symname
);
2410 canonical_name
= xmalloc (strlen (filename
) + 30);
2411 sprintf (canonical_name
, "%s:%d", filename
, sal
->line
);
2413 canonical_arr
[0] = canonical_name
;
2416 /* Parse a string that specifies a line number.
2417 Pass the address of a char * variable; that variable will be
2418 advanced over the characters actually parsed.
2422 LINENUM -- that line number in current file. PC returned is 0.
2423 FILE:LINENUM -- that line in that file. PC returned is 0.
2424 FUNCTION -- line number of openbrace of that function.
2425 PC returned is the start of the function.
2426 VARIABLE -- line number of definition of that variable.
2428 FILE:FUNCTION -- likewise, but prefer functions in that file.
2429 *EXPR -- line in which address EXPR appears.
2431 This may all be followed by an "if EXPR", which we ignore.
2433 FUNCTION may be an undebuggable function found in minimal symbol table.
2435 If the argument FUNFIRSTLINE is nonzero, we want the first line
2436 of real code inside a function when a function is specified, and it is
2437 not OK to specify a variable or type to get its line number.
2439 DEFAULT_SYMTAB specifies the file to use if none is specified.
2440 It defaults to current_source_symtab.
2441 DEFAULT_LINE specifies the line number to use for relative
2442 line numbers (that start with signs). Defaults to current_source_line.
2443 If CANONICAL is non-NULL, store an array of strings containing the canonical
2444 line specs there if necessary. Currently overloaded member functions and
2445 line numbers or static functions without a filename yield a canonical
2446 line spec. The array and the line spec strings are allocated on the heap,
2447 it is the callers responsibility to free them.
2449 Note that it is possible to return zero for the symtab
2450 if no file is validly specified. Callers must check that.
2451 Also, the line number returned may be invalid. */
2453 /* We allow single quotes in various places. This is a hideous
2454 kludge, which exists because the completer can't yet deal with the
2455 lack of single quotes. FIXME: write a linespec_completer which we
2456 can use as appropriate instead of make_symbol_completion_list. */
2458 struct symtabs_and_lines
2459 decode_line_1 (argptr
, funfirstline
, default_symtab
, default_line
, canonical
)
2462 struct symtab
*default_symtab
;
2466 struct symtabs_and_lines values
;
2467 #ifdef HPPA_COMPILER_BUG
2468 /* FIXME: The native HP 9000/700 compiler has a bug which appears
2469 when optimizing this file with target i960-vxworks. I haven't
2470 been able to construct a simple test case. The problem is that
2471 in the second call to SKIP_PROLOGUE below, the compiler somehow
2472 does not realize that the statement val = find_pc_line (...) will
2473 change the values of the fields of val. It extracts the elements
2474 into registers at the top of the block, and does not update the
2475 registers after the call to find_pc_line. You can check this by
2476 inserting a printf at the end of find_pc_line to show what values
2477 it is returning for val.pc and val.end and another printf after
2478 the call to see what values the function actually got (remember,
2479 this is compiling with cc -O, with this patch removed). You can
2480 also examine the assembly listing: search for the second call to
2481 skip_prologue; the LDO statement before the next call to
2482 find_pc_line loads the address of the structure which
2483 find_pc_line will return; if there is a LDW just before the LDO,
2484 which fetches an element of the structure, then the compiler
2487 Setting val to volatile avoids the problem. We must undef
2488 volatile, because the HPPA native compiler does not define
2489 __STDC__, although it does understand volatile, and so volatile
2490 will have been defined away in defs.h. */
2492 volatile struct symtab_and_line val
;
2493 #define volatile /*nothing */
2495 struct symtab_and_line val
;
2497 register char *p
, *p1
;
2498 char *q
, *pp
, *ii
, *p2
;
2502 register struct symtab
*s
;
2504 register struct symbol
*sym
;
2505 /* The symtab that SYM was found in. */
2506 struct symtab
*sym_symtab
;
2508 register CORE_ADDR pc
;
2509 register struct minimal_symbol
*msymbol
;
2511 struct symbol
*sym_class
;
2514 int is_quote_enclosed
;
2518 struct symbol
**sym_arr
;
2520 char *saved_arg
= *argptr
;
2521 extern char *gdb_completer_quote_characters
;
2523 INIT_SAL (&val
); /* initialize to zeroes */
2525 /* Defaults have defaults. */
2527 if (default_symtab
== 0)
2529 default_symtab
= current_source_symtab
;
2530 default_line
= current_source_line
;
2533 /* See if arg is *PC */
2535 if (**argptr
== '*')
2538 pc
= parse_and_eval_address_1 (argptr
);
2540 values
.sals
= (struct symtab_and_line
*)
2541 xmalloc (sizeof (struct symtab_and_line
));
2544 values
.sals
[0] = find_pc_line (pc
, 0);
2545 values
.sals
[0].pc
= pc
;
2546 values
.sals
[0].section
= find_pc_overlay (pc
);
2551 /* 'has_if' is for the syntax:
2552 * (gdb) break foo if (a==b)
2554 if ((ii
= strstr (*argptr
, " if ")) != NULL
||
2555 (ii
= strstr (*argptr
, "\tif ")) != NULL
||
2556 (ii
= strstr (*argptr
, " if\t")) != NULL
||
2557 (ii
= strstr (*argptr
, "\tif\t")) != NULL
||
2558 (ii
= strstr (*argptr
, " if(")) != NULL
||
2559 (ii
= strstr (*argptr
, "\tif( ")) != NULL
)
2561 /* Temporarily zap out "if (condition)" to not
2562 * confuse the parenthesis-checking code below.
2563 * This is undone below. Do not change ii!!
2570 /* Set various flags.
2571 * 'has_parens' is important for overload checking, where
2572 * we allow things like:
2573 * (gdb) break c::f(int)
2576 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
2578 is_quoted
= (**argptr
2579 && strchr (gdb_completer_quote_characters
, **argptr
) != NULL
);
2581 has_parens
= ((pp
= strchr (*argptr
, '(')) != NULL
2582 && (pp
= strchr (pp
, ')')) != NULL
);
2584 /* Now that we're safely past the has_parens check,
2585 * put back " if (condition)" so outer layers can see it
2590 /* Maybe we were called with a line range FILENAME:LINENUM,FILENAME:LINENUM
2591 and we must isolate the first half. Outer layers will call again later
2592 for the second half */
2593 if ((ii
= strchr (*argptr
, ',')) != NULL
)
2595 /* Temporarily zap out second half to not
2596 * confuse the code below.
2597 * This is undone below. Do not change ii!!
2604 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
2605 /* May also be CLASS::MEMBER, or NAMESPACE::NAME */
2606 /* Look for ':', but ignore inside of <> */
2612 is_quote_enclosed
= 1;
2616 is_quote_enclosed
= 0;
2621 char *temp_end
= find_template_name_end (p
);
2623 error ("malformed template specification in command");
2626 /* Check for the end of the first half of the linespec. End of line,
2627 a tab, a double colon or the last single colon, or a space. But
2628 if enclosed in double quotes we do not break on enclosed spaces */
2632 && ((p
[1] == ':') || (strchr (p
+ 1, ':') == NULL
)))
2633 || ((p
[0] == ' ') && !is_quote_enclosed
))
2635 if (p
[0] == '.' && strchr (p
, ':') == NULL
) /* Java qualified method. */
2637 /* Find the *last* '.', since the others are package qualifiers. */
2638 for (p1
= p
; *p1
; p1
++)
2646 while (p
[0] == ' ' || p
[0] == '\t')
2648 /* if the closing double quote was left at the end, remove it */
2649 if (is_quote_enclosed
&& ((pp
= strchr (p
, '"')) != NULL
))
2653 /* Now that we've safely parsed the first half,
2654 * put back ',' so outer layers can see it
2659 if ((p
[0] == ':' || p
[0] == '.') && !has_parens
)
2664 *argptr
= *argptr
+ 1;
2665 if (p
[0] == '.' || p
[1] == ':')
2668 char *saved_arg2
= *argptr
;
2670 /* First check for "global" namespace specification,
2671 of the form "::foo". If found, skip over the colons
2672 and jump to normal symbol processing */
2673 if ((*argptr
== p
) || (p
[-1] == ' ') || (p
[-1] == '\t'))
2676 /* We have what looks like a class or namespace
2677 scope specification (A::B), possibly with many
2678 levels of namespaces or classes (A::B::C::D).
2680 Some versions of the HP ANSI C++ compiler (as also possibly
2681 other compilers) generate class/function/member names with
2682 embedded double-colons if they are inside namespaces. To
2683 handle this, we loop a few times, considering larger and
2684 larger prefixes of the string as though they were single
2685 symbols. So, if the initially supplied string is
2686 A::B::C::D::foo, we have to look up "A", then "A::B",
2687 then "A::B::C", then "A::B::C::D", and finally
2688 "A::B::C::D::foo" as single, monolithic symbols, because
2689 A, B, C or D may be namespaces.
2691 Note that namespaces can nest only inside other
2692 namespaces, and not inside classes. So we need only
2693 consider *prefixes* of the string; there is no need to look up
2694 "B::C" separately as a symbol in the previous example. */
2696 p2
= p
; /* save for restart */
2699 /* Extract the class name. */
2701 while (p
!= *argptr
&& p
[-1] == ' ')
2703 copy
= (char *) alloca (p
- *argptr
+ 1);
2704 memcpy (copy
, *argptr
, p
- *argptr
);
2705 copy
[p
- *argptr
] = 0;
2707 /* Discard the class name from the arg. */
2708 p
= p1
+ (p1
[0] == ':' ? 2 : 1);
2709 while (*p
== ' ' || *p
== '\t')
2713 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
2714 (struct symtab
**) NULL
);
2717 (t
= check_typedef (SYMBOL_TYPE (sym_class
)),
2718 (TYPE_CODE (t
) == TYPE_CODE_STRUCT
2719 || TYPE_CODE (t
) == TYPE_CODE_UNION
)))
2721 /* Arg token is not digits => try it as a function name
2722 Find the next token(everything up to end or next blank). */
2724 && strchr (gdb_completer_quote_characters
, **argptr
) != NULL
)
2726 p
= skip_quoted (*argptr
);
2727 *argptr
= *argptr
+ 1;
2732 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',' && *p
!= ':')
2736 q = operator_chars (*argptr, &q1);
2740 char *tmp = alloca (q1 - q + 1);
2741 memcpy (tmp, q, q1 - q);
2743 opname = cplus_mangle_opname (tmp, DMGL_ANSI);
2747 printf_filtered ("no mangling for \"%s\"\n", tmp);
2748 cplusplus_hint (saved_arg);
2749 return_to_top_level (RETURN_ERROR);
2751 copy = (char*) alloca (3 + strlen(opname));
2752 sprintf (copy, "__%s", opname);
2758 copy
= (char *) alloca (p
- *argptr
+ 1);
2759 memcpy (copy
, *argptr
, p
- *argptr
);
2760 copy
[p
- *argptr
] = '\0';
2762 && copy
[p
- *argptr
- 1]
2763 && strchr (gdb_completer_quote_characters
,
2764 copy
[p
- *argptr
- 1]) != NULL
)
2765 copy
[p
- *argptr
- 1] = '\0';
2768 /* no line number may be specified */
2769 while (*p
== ' ' || *p
== '\t')
2774 i1
= 0; /* counter for the symbol array */
2775 sym_arr
= (struct symbol
**) alloca (total_number_of_methods (t
)
2776 * sizeof (struct symbol
*));
2778 if (destructor_name_p (copy
, t
))
2780 /* Destructors are a special case. */
2781 int m_index
, f_index
;
2783 if (get_destructor_fn_field (t
, &m_index
, &f_index
))
2785 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, m_index
);
2788 lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f
, f_index
),
2789 NULL
, VAR_NAMESPACE
, (int *) NULL
,
2790 (struct symtab
**) NULL
);
2796 i1
= find_methods (t
, copy
, sym_arr
);
2799 /* There is exactly one field with that name. */
2802 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2804 values
.sals
= (struct symtab_and_line
*)
2805 xmalloc (sizeof (struct symtab_and_line
));
2807 values
.sals
[0] = find_function_start_sal (sym
,
2818 /* There is more than one field with that name
2819 (overloaded). Ask the user which one to use. */
2820 return decode_line_2 (sym_arr
, i1
, funfirstline
, canonical
);
2826 if (OPNAME_PREFIX_P (copy
))
2828 tmp
= (char *) alloca (strlen (copy
+ 3) + 9);
2829 strcpy (tmp
, "operator ");
2830 strcat (tmp
, copy
+ 3);
2837 ("the class `%s' does not have destructor defined\n",
2838 SYMBOL_SOURCE_NAME (sym_class
));
2841 ("the class %s does not have any method named %s\n",
2842 SYMBOL_SOURCE_NAME (sym_class
), tmp
);
2843 cplusplus_hint (saved_arg
);
2844 return_to_top_level (RETURN_ERROR
);
2848 /* Move pointer up to next possible class/namespace token */
2849 p
= p2
+ 1; /* restart with old value +1 */
2850 /* Move pointer ahead to next double-colon */
2851 while (*p
&& (p
[0] != ' ') && (p
[0] != '\t') && (p
[0] != '\''))
2855 temp_end
= find_template_name_end (p
);
2857 error ("malformed template specification in command");
2860 else if ((p
[0] == ':') && (p
[1] == ':'))
2861 break; /* found double-colon */
2867 break; /* out of the while (1) */
2869 p2
= p
; /* save restart for next time around */
2870 *argptr
= saved_arg2
; /* restore argptr */
2873 /* Last chance attempt -- check entire name as a symbol */
2874 /* Use "copy" in preparation for jumping out of this block,
2875 to be consistent with usage following the jump target */
2876 copy
= (char *) alloca (p
- saved_arg2
+ 1);
2877 memcpy (copy
, saved_arg2
, p
- saved_arg2
);
2878 /* Note: if is_quoted should be true, we snuff out quote here anyway */
2879 copy
[p
- saved_arg2
] = '\000';
2880 /* Set argptr to skip over the name */
2881 *argptr
= (*p
== '\'') ? p
+ 1 : p
;
2882 /* Look up entire name */
2883 sym
= lookup_symbol (copy
, 0, VAR_NAMESPACE
, 0, &sym_symtab
);
2884 s
= (struct symtab
*) 0;
2885 /* Prepare to jump: restore the " if (condition)" so outer layers see it */
2886 /* Symbol was found --> jump to normal symbol processing.
2887 Code following "symbol_found" expects "copy" to have the
2888 symbol name, "sym" to have the symbol pointer, "s" to be
2889 a specified file's symtab, and sym_symtab to be the symbol's
2891 /* By jumping there we avoid falling through the FILE:LINE and
2892 FILE:FUNC processing stuff below */
2896 /* Couldn't find any interpretation as classes/namespaces, so give up */
2898 /* The quotes are important if copy is empty. */
2900 ("Can't find member of namespace, class, struct, or union named \"%s\"\n", copy
);
2901 cplusplus_hint (saved_arg
);
2902 return_to_top_level (RETURN_ERROR
);
2907 /* Extract the file name. */
2909 while (p
!= *argptr
&& p
[-1] == ' ')
2911 if ((*p
== '"') && is_quote_enclosed
)
2913 copy
= (char *) alloca (p
- *argptr
+ 1);
2914 if ((**argptr
== '"') && is_quote_enclosed
)
2916 memcpy (copy
, *argptr
+ 1, p
- *argptr
- 1);
2917 /* It may have the ending quote right after the file name */
2918 if (copy
[p
- *argptr
- 2] == '"')
2919 copy
[p
- *argptr
- 2] = 0;
2921 copy
[p
- *argptr
- 1] = 0;
2925 memcpy (copy
, *argptr
, p
- *argptr
);
2926 copy
[p
- *argptr
] = 0;
2929 /* Find that file's data. */
2930 s
= lookup_symtab (copy
);
2933 if (!have_full_symbols () && !have_partial_symbols ())
2934 error (no_symtab_msg
);
2935 error ("No source file named %s.", copy
);
2938 /* Discard the file name from the arg. */
2940 while (*p
== ' ' || *p
== '\t')
2945 /* No one really seems to know why this was added. It certainly
2946 breaks the command line, though, whenever the passed
2947 name is of the form ClassName::Method. This bit of code
2948 singles out the class name, and if funfirstline is set (for
2949 example, you are setting a breakpoint at this function),
2950 you get an error. This did not occur with earlier
2951 verions, so I am ifdef'ing this out. 3/29/99 */
2954 /* Check if what we have till now is a symbol name */
2956 /* We may be looking at a template instantiation such
2957 as "foo<int>". Check here whether we know about it,
2958 instead of falling through to the code below which
2959 handles ordinary function names, because that code
2960 doesn't like seeing '<' and '>' in a name -- the
2961 skip_quoted call doesn't go past them. So see if we
2962 can figure it out right now. */
2964 copy
= (char *) alloca (p
- *argptr
+ 1);
2965 memcpy (copy
, *argptr
, p
- *argptr
);
2966 copy
[p
- *argptr
] = '\000';
2967 sym
= lookup_symbol (copy
, 0, VAR_NAMESPACE
, 0, &sym_symtab
);
2970 /* Yes, we have a symbol; jump to symbol processing */
2971 /* Code after symbol_found expects S, SYM_SYMTAB, SYM,
2972 and COPY to be set correctly */
2973 *argptr
= (*p
== '\'') ? p
+ 1 : p
;
2974 s
= (struct symtab
*) 0;
2977 /* Otherwise fall out from here and go to file/line spec
2982 /* S is specified file's symtab, or 0 if no file specified.
2983 arg no longer contains the file name. */
2985 /* Check whether arg is all digits (and sign) */
2988 if (*q
== '-' || *q
== '+')
2990 while (*q
>= '0' && *q
<= '9')
2993 if (q
!= *argptr
&& (*q
== 0 || *q
== ' ' || *q
== '\t' || *q
== ','))
2995 /* We found a token consisting of all digits -- at least one digit. */
3002 /* We might need a canonical line spec if no file was specified. */
3003 int need_canonical
= (s
== 0) ? 1 : 0;
3005 /* This is where we need to make sure that we have good defaults.
3006 We must guarantee that this section of code is never executed
3007 when we are called with just a function name, since
3008 select_source_symtab calls us with such an argument */
3010 if (s
== 0 && default_symtab
== 0)
3012 select_source_symtab (0);
3013 default_symtab
= current_source_symtab
;
3014 default_line
= current_source_line
;
3017 if (**argptr
== '+')
3018 sign
= plus
, (*argptr
)++;
3019 else if (**argptr
== '-')
3020 sign
= minus
, (*argptr
)++;
3021 val
.line
= atoi (*argptr
);
3028 val
.line
= default_line
+ val
.line
;
3034 val
.line
= default_line
- val
.line
;
3039 break; /* No need to adjust val.line. */
3042 while (*q
== ' ' || *q
== '\t')
3048 /* It is possible that this source file has more than one symtab,
3049 and that the new line number specification has moved us from the
3050 default (in s) to a new one. */
3051 val
.symtab
= find_line_symtab (s
, val
.line
, NULL
, NULL
);
3052 if (val
.symtab
== 0)
3056 values
.sals
= (struct symtab_and_line
*)
3057 xmalloc (sizeof (struct symtab_and_line
));
3058 values
.sals
[0] = val
;
3061 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
3065 /* Arg token is not digits => try it as a variable name
3066 Find the next token (everything up to end or next whitespace). */
3068 if (**argptr
== '$') /* May be a convenience variable */
3069 p
= skip_quoted (*argptr
+ (((*argptr
)[1] == '$') ? 2 : 1)); /* One or two $ chars possible */
3072 p
= skip_quoted (*argptr
);
3074 error ("Unmatched single quote.");
3076 else if (has_parens
)
3082 p
= skip_quoted (*argptr
);
3085 copy
= (char *) alloca (p
- *argptr
+ 1);
3086 memcpy (copy
, *argptr
, p
- *argptr
);
3087 copy
[p
- *argptr
] = '\0';
3090 && copy
[0] == copy
[p
- *argptr
- 1]
3091 && strchr (gdb_completer_quote_characters
, copy
[0]) != NULL
)
3093 copy
[p
- *argptr
- 1] = '\0';
3096 while (*p
== ' ' || *p
== '\t')
3100 /* If it starts with $: may be a legitimate variable or routine name
3101 (e.g. HP-UX millicode routines such as $$dyncall), or it may
3102 be history value, or it may be a convenience variable */
3108 int need_canonical
= 0;
3110 p
= (copy
[1] == '$') ? copy
+ 2 : copy
+ 1;
3111 while (*p
>= '0' && *p
<= '9')
3113 if (!*p
) /* reached end of token without hitting non-digit */
3115 /* We have a value history reference */
3116 sscanf ((copy
[1] == '$') ? copy
+ 2 : copy
+ 1, "%d", &index
);
3117 valx
= access_value_history ((copy
[1] == '$') ? -index
: index
);
3118 if (TYPE_CODE (VALUE_TYPE (valx
)) != TYPE_CODE_INT
)
3119 error ("History values used in line specs must have integer values.");
3123 /* Not all digits -- may be user variable/function or a
3124 convenience variable */
3126 /* Look up entire name as a symbol first */
3127 sym
= lookup_symbol (copy
, 0, VAR_NAMESPACE
, 0, &sym_symtab
);
3128 s
= (struct symtab
*) 0;
3130 /* Symbol was found --> jump to normal symbol processing.
3131 Code following "symbol_found" expects "copy" to have the
3132 symbol name, "sym" to have the symbol pointer, "s" to be
3133 a specified file's symtab, and sym_symtab to be the symbol's
3138 /* If symbol was not found, look in minimal symbol tables */
3139 msymbol
= lookup_minimal_symbol (copy
, 0, 0);
3140 /* Min symbol was found --> jump to minsym processing. */
3142 goto minimal_symbol_found
;
3144 /* Not a user variable or function -- must be convenience variable */
3145 need_canonical
= (s
== 0) ? 1 : 0;
3146 valx
= value_of_internalvar (lookup_internalvar (copy
+ 1));
3147 if (TYPE_CODE (VALUE_TYPE (valx
)) != TYPE_CODE_INT
)
3148 error ("Convenience variables used in line specs must have integer values.");
3151 /* Either history value or convenience value from above, in valx */
3152 val
.symtab
= s
? s
: default_symtab
;
3153 val
.line
= value_as_long (valx
);
3156 values
.sals
= (struct symtab_and_line
*) xmalloc (sizeof val
);
3157 values
.sals
[0] = val
;
3161 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
3167 /* Look up that token as a variable.
3168 If file specified, use that file's per-file block to start with. */
3170 sym
= lookup_symbol (copy
,
3171 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
3172 : get_selected_block ()),
3173 VAR_NAMESPACE
, 0, &sym_symtab
);
3175 symbol_found
: /* We also jump here from inside the C++ class/namespace
3176 code on finding a symbol of the form "A::B::C" */
3180 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3182 /* Arg is the name of a function */
3183 values
.sals
= (struct symtab_and_line
*)
3184 xmalloc (sizeof (struct symtab_and_line
));
3185 values
.sals
[0] = find_function_start_sal (sym
, funfirstline
);
3188 /* Don't use the SYMBOL_LINE; if used at all it points to
3189 the line containing the parameters or thereabouts, not
3190 the first line of code. */
3192 /* We might need a canonical line spec if it is a static
3196 struct blockvector
*bv
= BLOCKVECTOR (sym_symtab
);
3197 struct block
*b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
3198 if (lookup_block_symbol (b
, copy
, VAR_NAMESPACE
) != NULL
)
3199 build_canonical_line_spec (values
.sals
, copy
, canonical
);
3206 error ("\"%s\" is not a function", copy
);
3207 else if (SYMBOL_LINE (sym
) != 0)
3209 /* We know its line number. */
3210 values
.sals
= (struct symtab_and_line
*)
3211 xmalloc (sizeof (struct symtab_and_line
));
3213 memset (&values
.sals
[0], 0, sizeof (values
.sals
[0]));
3214 values
.sals
[0].symtab
= sym_symtab
;
3215 values
.sals
[0].line
= SYMBOL_LINE (sym
);
3219 /* This can happen if it is compiled with a compiler which doesn't
3220 put out line numbers for variables. */
3221 /* FIXME: Shouldn't we just set .line and .symtab to zero
3222 and return? For example, "info line foo" could print
3224 error ("Line number not known for symbol \"%s\"", copy
);
3228 msymbol
= lookup_minimal_symbol (copy
, NULL
, NULL
);
3230 minimal_symbol_found
: /* We also jump here from the case for variables
3231 that begin with '$' */
3233 if (msymbol
!= NULL
)
3235 values
.sals
= (struct symtab_and_line
*)
3236 xmalloc (sizeof (struct symtab_and_line
));
3237 values
.sals
[0] = find_pc_sect_line (SYMBOL_VALUE_ADDRESS (msymbol
),
3238 (struct sec
*) 0, 0);
3239 values
.sals
[0].section
= SYMBOL_BFD_SECTION (msymbol
);
3242 values
.sals
[0].pc
+= FUNCTION_START_OFFSET
;
3243 values
.sals
[0].pc
= SKIP_PROLOGUE (values
.sals
[0].pc
);
3249 if (!have_full_symbols () &&
3250 !have_partial_symbols () && !have_minimal_symbols ())
3251 error (no_symtab_msg
);
3253 error ("Function \"%s\" not defined.", copy
);
3254 return values
; /* for lint */
3257 struct symtabs_and_lines
3258 decode_line_spec (string
, funfirstline
)
3262 struct symtabs_and_lines sals
;
3264 error ("Empty line specification.");
3265 sals
= decode_line_1 (&string
, funfirstline
,
3266 current_source_symtab
, current_source_line
,
3269 error ("Junk at end of line specification: %s", string
);
3273 /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to
3274 operate on (ask user if necessary).
3275 If CANONICAL is non-NULL return a corresponding array of mangled names
3276 as canonical line specs there. */
3278 static struct symtabs_and_lines
3279 decode_line_2 (sym_arr
, nelts
, funfirstline
, canonical
)
3280 struct symbol
*sym_arr
[];
3285 struct symtabs_and_lines values
, return_values
;
3290 struct cleanup
*old_chain
;
3291 char **canonical_arr
= (char **) NULL
;
3293 values
.sals
= (struct symtab_and_line
*)
3294 alloca (nelts
* sizeof (struct symtab_and_line
));
3295 return_values
.sals
= (struct symtab_and_line
*)
3296 xmalloc (nelts
* sizeof (struct symtab_and_line
));
3297 old_chain
= make_cleanup (free
, return_values
.sals
);
3301 canonical_arr
= (char **) xmalloc (nelts
* sizeof (char *));
3302 make_cleanup (free
, canonical_arr
);
3303 memset (canonical_arr
, 0, nelts
* sizeof (char *));
3304 *canonical
= canonical_arr
;
3308 printf_unfiltered ("[0] cancel\n[1] all\n");
3311 INIT_SAL (&return_values
.sals
[i
]); /* initialize to zeroes */
3312 INIT_SAL (&values
.sals
[i
]);
3313 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
3315 values
.sals
[i
] = find_function_start_sal (sym_arr
[i
], funfirstline
);
3316 printf_unfiltered ("[%d] %s at %s:%d\n",
3318 SYMBOL_SOURCE_NAME (sym_arr
[i
]),
3319 values
.sals
[i
].symtab
->filename
,
3320 values
.sals
[i
].line
);
3323 printf_unfiltered ("?HERE\n");
3327 if ((prompt
= getenv ("PS2")) == NULL
)
3331 args
= command_line_input (prompt
, 0, "overload-choice");
3333 if (args
== 0 || *args
== 0)
3334 error_no_arg ("one or more choice numbers");
3342 while (*arg1
>= '0' && *arg1
<= '9')
3344 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
3345 error ("Arguments must be choice numbers.");
3350 error ("cancelled");
3355 for (i
= 0; i
< nelts
; i
++)
3357 if (canonical_arr
[i
] == NULL
)
3359 symname
= SYMBOL_NAME (sym_arr
[i
]);
3360 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
3364 memcpy (return_values
.sals
, values
.sals
,
3365 (nelts
* sizeof (struct symtab_and_line
)));
3366 return_values
.nelts
= nelts
;
3367 discard_cleanups (old_chain
);
3368 return return_values
;
3371 if (num
>= nelts
+ 2)
3373 printf_unfiltered ("No choice number %d.\n", num
);
3378 if (values
.sals
[num
].pc
)
3382 symname
= SYMBOL_NAME (sym_arr
[num
]);
3383 make_cleanup (free
, symname
);
3384 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
3386 return_values
.sals
[i
++] = values
.sals
[num
];
3387 values
.sals
[num
].pc
= 0;
3391 printf_unfiltered ("duplicate request for %d ignored.\n", num
);
3396 while (*args
== ' ' || *args
== '\t')
3399 return_values
.nelts
= i
;
3400 discard_cleanups (old_chain
);
3401 return return_values
;
3405 /* Slave routine for sources_info. Force line breaks at ,'s.
3406 NAME is the name to print and *FIRST is nonzero if this is the first
3407 name printed. Set *FIRST to zero. */
3409 output_source_filename (name
, first
)
3413 /* Table of files printed so far. Since a single source file can
3414 result in several partial symbol tables, we need to avoid printing
3415 it more than once. Note: if some of the psymtabs are read in and
3416 some are not, it gets printed both under "Source files for which
3417 symbols have been read" and "Source files for which symbols will
3418 be read in on demand". I consider this a reasonable way to deal
3419 with the situation. I'm not sure whether this can also happen for
3420 symtabs; it doesn't hurt to check. */
3421 static char **tab
= NULL
;
3422 /* Allocated size of tab in elements.
3423 Start with one 256-byte block (when using GNU malloc.c).
3424 24 is the malloc overhead when range checking is in effect. */
3425 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
3426 /* Current size of tab in elements. */
3427 static int tab_cur_size
;
3434 tab
= (char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
3438 /* Is NAME in tab? */
3439 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
3440 if (STREQ (*p
, name
))
3441 /* Yes; don't print it again. */
3443 /* No; add it to tab. */
3444 if (tab_cur_size
== tab_alloc_size
)
3446 tab_alloc_size
*= 2;
3447 tab
= (char **) xrealloc ((char *) tab
, tab_alloc_size
* sizeof (*tab
));
3449 tab
[tab_cur_size
++] = name
;
3457 printf_filtered (", ");
3461 fputs_filtered (name
, gdb_stdout
);
3465 sources_info (ignore
, from_tty
)
3469 register struct symtab
*s
;
3470 register struct partial_symtab
*ps
;
3471 register struct objfile
*objfile
;
3474 if (!have_full_symbols () && !have_partial_symbols ())
3476 error (no_symtab_msg
);
3479 printf_filtered ("Source files for which symbols have been read in:\n\n");
3482 ALL_SYMTABS (objfile
, s
)
3484 output_source_filename (s
->filename
, &first
);
3486 printf_filtered ("\n\n");
3488 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
3491 ALL_PSYMTABS (objfile
, ps
)
3495 output_source_filename (ps
->filename
, &first
);
3498 printf_filtered ("\n");
3502 file_matches (file
, files
, nfiles
)
3509 if (file
!= NULL
&& nfiles
!= 0)
3511 for (i
= 0; i
< nfiles
; i
++)
3513 if (strcmp (files
[i
], basename (file
)) == 0)
3517 else if (nfiles
== 0)
3522 /* Free any memory associated with a search. */
3524 free_search_symbols (symbols
)
3525 struct symbol_search
*symbols
;
3527 struct symbol_search
*p
;
3528 struct symbol_search
*next
;
3530 for (p
= symbols
; p
!= NULL
; p
= next
)
3537 /* Search the symbol table for matches to the regular expression REGEXP,
3538 returning the results in *MATCHES.
3540 Only symbols of KIND are searched:
3541 FUNCTIONS_NAMESPACE - search all functions
3542 TYPES_NAMESPACE - search all type names
3543 METHODS_NAMESPACE - search all methods NOT IMPLEMENTED
3544 VARIABLES_NAMESPACE - search all symbols, excluding functions, type names,
3545 and constants (enums)
3547 free_search_symbols should be called when *MATCHES is no longer needed.
3550 search_symbols (regexp
, kind
, nfiles
, files
, matches
)
3552 namespace_enum kind
;
3555 struct symbol_search
**matches
;
3558 register struct symtab
*s
;
3559 register struct partial_symtab
*ps
;
3560 register struct blockvector
*bv
;
3561 struct blockvector
*prev_bv
= 0;
3562 register struct block
*b
;
3565 register struct symbol
*sym
;
3566 struct partial_symbol
**psym
;
3567 struct objfile
*objfile
;
3568 struct minimal_symbol
*msymbol
;
3571 static enum minimal_symbol_type types
[]
3573 {mst_data
, mst_text
, mst_abs
, mst_unknown
};
3574 static enum minimal_symbol_type types2
[]
3576 {mst_bss
, mst_file_text
, mst_abs
, mst_unknown
};
3577 static enum minimal_symbol_type types3
[]
3579 {mst_file_data
, mst_solib_trampoline
, mst_abs
, mst_unknown
};
3580 static enum minimal_symbol_type types4
[]
3582 {mst_file_bss
, mst_text
, mst_abs
, mst_unknown
};
3583 enum minimal_symbol_type ourtype
;
3584 enum minimal_symbol_type ourtype2
;
3585 enum minimal_symbol_type ourtype3
;
3586 enum minimal_symbol_type ourtype4
;
3587 struct symbol_search
*sr
;
3588 struct symbol_search
*psr
;
3589 struct symbol_search
*tail
;
3590 struct cleanup
*old_chain
= NULL
;
3592 if (kind
< LABEL_NAMESPACE
)
3593 error ("must search on specific namespace");
3595 ourtype
= types
[(int) (kind
- LABEL_NAMESPACE
)];
3596 ourtype2
= types2
[(int) (kind
- LABEL_NAMESPACE
)];
3597 ourtype3
= types3
[(int) (kind
- LABEL_NAMESPACE
)];
3598 ourtype4
= types4
[(int) (kind
- LABEL_NAMESPACE
)];
3600 sr
= *matches
= NULL
;
3605 /* Make sure spacing is right for C++ operators.
3606 This is just a courtesy to make the matching less sensitive
3607 to how many spaces the user leaves between 'operator'
3608 and <TYPENAME> or <OPERATOR>. */
3610 char *opname
= operator_chars (regexp
, &opend
);
3613 int fix
= -1; /* -1 means ok; otherwise number of spaces needed. */
3614 if (isalpha (*opname
) || *opname
== '_' || *opname
== '$')
3616 /* There should 1 space between 'operator' and 'TYPENAME'. */
3617 if (opname
[-1] != ' ' || opname
[-2] == ' ')
3622 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
3623 if (opname
[-1] == ' ')
3626 /* If wrong number of spaces, fix it. */
3629 char *tmp
= (char *) alloca (opend
- opname
+ 10);
3630 sprintf (tmp
, "operator%.*s%s", fix
, " ", opname
);
3635 if (0 != (val
= re_comp (regexp
)))
3636 error ("Invalid regexp (%s): %s", val
, regexp
);
3639 /* Search through the partial symtabs *first* for all symbols
3640 matching the regexp. That way we don't have to reproduce all of
3641 the machinery below. */
3643 ALL_PSYMTABS (objfile
, ps
)
3645 struct partial_symbol
**bound
, **gbound
, **sbound
;
3651 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
3652 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
3655 /* Go through all of the symbols stored in a partial
3656 symtab in one loop. */
3657 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
3662 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
3664 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
3675 /* If it would match (logic taken from loop below)
3676 load the file and go on to the next one */
3677 if (file_matches (ps
->filename
, files
, nfiles
)
3678 && ((regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (*psym
))
3679 && ((kind
== VARIABLES_NAMESPACE
&& SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
3680 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
3681 || (kind
== FUNCTIONS_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
3682 || (kind
== TYPES_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
)
3683 || (kind
== METHODS_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
))))
3685 PSYMTAB_TO_SYMTAB (ps
);
3693 /* Here, we search through the minimal symbol tables for functions
3694 and variables that match, and force their symbols to be read.
3695 This is in particular necessary for demangled variable names,
3696 which are no longer put into the partial symbol tables.
3697 The symbol will then be found during the scan of symtabs below.
3699 For functions, find_pc_symtab should succeed if we have debug info
3700 for the function, for variables we have to call lookup_symbol
3701 to determine if the variable has debug info.
3702 If the lookup fails, set found_misc so that we will rescan to print
3703 any matching symbols without debug info.
3706 if (nfiles
== 0 && (kind
== VARIABLES_NAMESPACE
|| kind
== FUNCTIONS_NAMESPACE
))
3708 ALL_MSYMBOLS (objfile
, msymbol
)
3710 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
3711 MSYMBOL_TYPE (msymbol
) == ourtype2
||
3712 MSYMBOL_TYPE (msymbol
) == ourtype3
||
3713 MSYMBOL_TYPE (msymbol
) == ourtype4
)
3715 if (regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (msymbol
))
3717 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
)))
3719 if (kind
== FUNCTIONS_NAMESPACE
3720 || lookup_symbol (SYMBOL_NAME (msymbol
),
3721 (struct block
*) NULL
,
3723 0, (struct symtab
**) NULL
) == NULL
)
3731 ALL_SYMTABS (objfile
, s
)
3733 bv
= BLOCKVECTOR (s
);
3734 /* Often many files share a blockvector.
3735 Scan each blockvector only once so that
3736 we don't get every symbol many times.
3737 It happens that the first symtab in the list
3738 for any given blockvector is the main file. */
3740 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
3742 b
= BLOCKVECTOR_BLOCK (bv
, i
);
3743 /* Skip the sort if this block is always sorted. */
3744 if (!BLOCK_SHOULD_SORT (b
))
3745 sort_block_syms (b
);
3746 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
3749 sym
= BLOCK_SYM (b
, j
);
3750 if (file_matches (s
->filename
, files
, nfiles
)
3751 && ((regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (sym
))
3752 && ((kind
== VARIABLES_NAMESPACE
&& SYMBOL_CLASS (sym
) != LOC_TYPEDEF
3753 && SYMBOL_CLASS (sym
) != LOC_BLOCK
3754 && SYMBOL_CLASS (sym
) != LOC_CONST
)
3755 || (kind
== FUNCTIONS_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3756 || (kind
== TYPES_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3757 || (kind
== METHODS_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
))))
3760 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
3764 psr
->msymbol
= NULL
;
3769 old_chain
= make_cleanup ((make_cleanup_func
)
3770 free_search_symbols
, sr
);
3781 /* If there are no eyes, avoid all contact. I mean, if there are
3782 no debug symbols, then print directly from the msymbol_vector. */
3784 if (found_misc
|| kind
!= FUNCTIONS_NAMESPACE
)
3786 ALL_MSYMBOLS (objfile
, msymbol
)
3788 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
3789 MSYMBOL_TYPE (msymbol
) == ourtype2
||
3790 MSYMBOL_TYPE (msymbol
) == ourtype3
||
3791 MSYMBOL_TYPE (msymbol
) == ourtype4
)
3793 if (regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (msymbol
))
3795 /* Functions: Look up by address. */
3796 if (kind
!= FUNCTIONS_NAMESPACE
||
3797 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
))))
3799 /* Variables/Absolutes: Look up by name */
3800 if (lookup_symbol (SYMBOL_NAME (msymbol
),
3801 (struct block
*) NULL
, VAR_NAMESPACE
,
3802 0, (struct symtab
**) NULL
) == NULL
)
3805 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
3807 psr
->msymbol
= msymbol
;
3814 old_chain
= make_cleanup ((make_cleanup_func
)
3815 free_search_symbols
, &sr
);
3829 discard_cleanups (old_chain
);
3832 /* Helper function for symtab_symbol_info, this function uses
3833 the data returned from search_symbols() to print information
3834 regarding the match to gdb_stdout.
3837 print_symbol_info (kind
, s
, sym
, block
, last
)
3838 namespace_enum kind
;
3844 if (last
== NULL
|| strcmp (last
, s
->filename
) != 0)
3846 fputs_filtered ("\nFile ", gdb_stdout
);
3847 fputs_filtered (s
->filename
, gdb_stdout
);
3848 fputs_filtered (":\n", gdb_stdout
);
3851 if (kind
!= TYPES_NAMESPACE
&& block
== STATIC_BLOCK
)
3852 printf_filtered ("static ");
3854 /* Typedef that is not a C++ class */
3855 if (kind
== TYPES_NAMESPACE
3856 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
3857 c_typedef_print (SYMBOL_TYPE (sym
), sym
, gdb_stdout
);
3858 /* variable, func, or typedef-that-is-c++-class */
3859 else if (kind
< TYPES_NAMESPACE
||
3860 (kind
== TYPES_NAMESPACE
&&
3861 SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
))
3863 type_print (SYMBOL_TYPE (sym
),
3864 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3865 ? "" : SYMBOL_SOURCE_NAME (sym
)),
3868 printf_filtered (";\n");
3873 /* Tiemann says: "info methods was never implemented." */
3874 char *demangled_name
;
3875 c_type_print_base (TYPE_FN_FIELD_TYPE (t
, block
),
3877 c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (t
, block
),
3879 if (TYPE_FN_FIELD_STUB (t
, block
))
3880 check_stub_method (TYPE_DOMAIN_TYPE (type
), j
, block
);
3882 cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t
, block
),
3883 DMGL_ANSI
| DMGL_PARAMS
);
3884 if (demangled_name
== NULL
)
3885 fprintf_filtered (stream
, "<badly mangled name %s>",
3886 TYPE_FN_FIELD_PHYSNAME (t
, block
));
3889 fputs_filtered (demangled_name
, stream
);
3890 free (demangled_name
);
3896 /* This help function for symtab_symbol_info() prints information
3897 for non-debugging symbols to gdb_stdout.
3900 print_msymbol_info (msymbol
)
3901 struct minimal_symbol
*msymbol
;
3903 printf_filtered (" %08lx %s\n",
3904 (unsigned long) SYMBOL_VALUE_ADDRESS (msymbol
),
3905 SYMBOL_SOURCE_NAME (msymbol
));
3908 /* This is the guts of the commands "info functions", "info types", and
3909 "info variables". It calls search_symbols to find all matches and then
3910 print_[m]symbol_info to print out some useful information about the
3914 symtab_symbol_info (regexp
, kind
, from_tty
)
3916 namespace_enum kind
;
3919 static char *classnames
[]
3921 {"variable", "function", "type", "method"};
3922 struct symbol_search
*symbols
;
3923 struct symbol_search
*p
;
3924 struct cleanup
*old_chain
;
3925 char *last_filename
= NULL
;
3928 /* must make sure that if we're interrupted, symbols gets freed */
3929 search_symbols (regexp
, kind
, 0, (char **) NULL
, &symbols
);
3930 old_chain
= make_cleanup ((make_cleanup_func
) free_search_symbols
, symbols
);
3932 printf_filtered (regexp
3933 ? "All %ss matching regular expression \"%s\":\n"
3934 : "All defined %ss:\n",
3935 classnames
[(int) (kind
- LABEL_NAMESPACE
- 1)], regexp
);
3937 for (p
= symbols
; p
!= NULL
; p
= p
->next
)
3941 if (p
->msymbol
!= NULL
)
3945 printf_filtered ("\nNon-debugging symbols:\n");
3948 print_msymbol_info (p
->msymbol
);
3952 print_symbol_info (kind
,
3957 last_filename
= p
->symtab
->filename
;
3961 do_cleanups (old_chain
);
3965 variables_info (regexp
, from_tty
)
3969 symtab_symbol_info (regexp
, VARIABLES_NAMESPACE
, from_tty
);
3973 functions_info (regexp
, from_tty
)
3977 symtab_symbol_info (regexp
, FUNCTIONS_NAMESPACE
, from_tty
);
3981 types_info (regexp
, from_tty
)
3985 symtab_symbol_info (regexp
, TYPES_NAMESPACE
, from_tty
);
3989 /* Tiemann says: "info methods was never implemented." */
3991 methods_info (regexp
)
3994 symtab_symbol_info (regexp
, METHODS_NAMESPACE
, 0, from_tty
);
3998 /* Breakpoint all functions matching regular expression. */
4000 rbreak_command (regexp
, from_tty
)
4004 struct symbol_search
*ss
;
4005 struct symbol_search
*p
;
4006 struct cleanup
*old_chain
;
4008 search_symbols (regexp
, FUNCTIONS_NAMESPACE
, 0, (char **) NULL
, &ss
);
4009 old_chain
= make_cleanup ((make_cleanup_func
) free_search_symbols
, ss
);
4011 for (p
= ss
; p
!= NULL
; p
= p
->next
)
4013 if (p
->msymbol
== NULL
)
4015 char *string
= (char *) alloca (strlen (p
->symtab
->filename
)
4016 + strlen (SYMBOL_NAME (p
->symbol
))
4018 strcpy (string
, p
->symtab
->filename
);
4019 strcat (string
, ":'");
4020 strcat (string
, SYMBOL_NAME (p
->symbol
));
4021 strcat (string
, "'");
4022 break_command (string
, from_tty
);
4023 print_symbol_info (FUNCTIONS_NAMESPACE
,
4027 p
->symtab
->filename
);
4031 break_command (SYMBOL_NAME (p
->msymbol
), from_tty
);
4032 printf_filtered ("<function, no debug info> %s;\n",
4033 SYMBOL_SOURCE_NAME (p
->msymbol
));
4037 do_cleanups (old_chain
);
4041 /* Return Nonzero if block a is lexically nested within block b,
4042 or if a and b have the same pc range.
4043 Return zero otherwise. */
4046 struct block
*a
, *b
;
4050 return BLOCK_START (a
) >= BLOCK_START (b
)
4051 && BLOCK_END (a
) <= BLOCK_END (b
);
4055 /* Helper routine for make_symbol_completion_list. */
4057 static int return_val_size
;
4058 static int return_val_index
;
4059 static char **return_val
;
4061 #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
4063 if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \
4064 /* Put only the mangled name on the list. */ \
4065 /* Advantage: "b foo<TAB>" completes to "b foo(int, int)" */ \
4066 /* Disadvantage: "b foo__i<TAB>" doesn't complete. */ \
4067 completion_list_add_name \
4068 (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \
4070 completion_list_add_name \
4071 (SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \
4074 /* Test to see if the symbol specified by SYMNAME (which is already
4075 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
4076 characters. If so, add it to the current completion list. */
4079 completion_list_add_name (symname
, sym_text
, sym_text_len
, text
, word
)
4089 /* clip symbols that cannot match */
4091 if (strncmp (symname
, sym_text
, sym_text_len
) != 0)
4096 /* Clip any symbol names that we've already considered. (This is a
4097 time optimization) */
4099 for (i
= 0; i
< return_val_index
; ++i
)
4101 if (STREQ (symname
, return_val
[i
]))
4107 /* We have a match for a completion, so add SYMNAME to the current list
4108 of matches. Note that the name is moved to freshly malloc'd space. */
4112 if (word
== sym_text
)
4114 new = xmalloc (strlen (symname
) + 5);
4115 strcpy (new, symname
);
4117 else if (word
> sym_text
)
4119 /* Return some portion of symname. */
4120 new = xmalloc (strlen (symname
) + 5);
4121 strcpy (new, symname
+ (word
- sym_text
));
4125 /* Return some of SYM_TEXT plus symname. */
4126 new = xmalloc (strlen (symname
) + (sym_text
- word
) + 5);
4127 strncpy (new, word
, sym_text
- word
);
4128 new[sym_text
- word
] = '\0';
4129 strcat (new, symname
);
4132 /* Recheck for duplicates if we intend to add a modified symbol. */
4133 if (word
!= sym_text
)
4135 for (i
= 0; i
< return_val_index
; ++i
)
4137 if (STREQ (new, return_val
[i
]))
4145 if (return_val_index
+ 3 > return_val_size
)
4147 newsize
= (return_val_size
*= 2) * sizeof (char *);
4148 return_val
= (char **) xrealloc ((char *) return_val
, newsize
);
4150 return_val
[return_val_index
++] = new;
4151 return_val
[return_val_index
] = NULL
;
4155 /* Return a NULL terminated array of all symbols (regardless of class) which
4156 begin by matching TEXT. If the answer is no symbols, then the return value
4157 is an array which contains only a NULL pointer.
4159 Problem: All of the symbols have to be copied because readline frees them.
4160 I'm not going to worry about this; hopefully there won't be that many. */
4163 make_symbol_completion_list (text
, word
)
4167 register struct symbol
*sym
;
4168 register struct symtab
*s
;
4169 register struct partial_symtab
*ps
;
4170 register struct minimal_symbol
*msymbol
;
4171 register struct objfile
*objfile
;
4172 register struct block
*b
, *surrounding_static_block
= 0;
4174 struct partial_symbol
**psym
;
4175 /* The symbol we are completing on. Points in same buffer as text. */
4177 /* Length of sym_text. */
4180 /* Now look for the symbol we are supposed to complete on.
4181 FIXME: This should be language-specific. */
4185 char *quote_pos
= NULL
;
4187 /* First see if this is a quoted string. */
4189 for (p
= text
; *p
!= '\0'; ++p
)
4191 if (quote_found
!= '\0')
4193 if (*p
== quote_found
)
4194 /* Found close quote. */
4196 else if (*p
== '\\' && p
[1] == quote_found
)
4197 /* A backslash followed by the quote character
4198 doesn't end the string. */
4201 else if (*p
== '\'' || *p
== '"')
4207 if (quote_found
== '\'')
4208 /* A string within single quotes can be a symbol, so complete on it. */
4209 sym_text
= quote_pos
+ 1;
4210 else if (quote_found
== '"')
4211 /* A double-quoted string is never a symbol, nor does it make sense
4212 to complete it any other way. */
4216 /* It is not a quoted string. Break it based on the characters
4217 which are in symbols. */
4220 if (isalnum (p
[-1]) || p
[-1] == '_' || p
[-1] == '\0')
4229 sym_text_len
= strlen (sym_text
);
4231 return_val_size
= 100;
4232 return_val_index
= 0;
4233 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
4234 return_val
[0] = NULL
;
4236 /* Look through the partial symtabs for all symbols which begin
4237 by matching SYM_TEXT. Add each one that you find to the list. */
4239 ALL_PSYMTABS (objfile
, ps
)
4241 /* If the psymtab's been read in we'll get it when we search
4242 through the blockvector. */
4246 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
4247 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
4248 + ps
->n_global_syms
);
4251 /* If interrupted, then quit. */
4253 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
4256 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
4257 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
4258 + ps
->n_static_syms
);
4262 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
4266 /* At this point scan through the misc symbol vectors and add each
4267 symbol you find to the list. Eventually we want to ignore
4268 anything that isn't a text symbol (everything else will be
4269 handled by the psymtab code above). */
4271 ALL_MSYMBOLS (objfile
, msymbol
)
4274 COMPLETION_LIST_ADD_SYMBOL (msymbol
, sym_text
, sym_text_len
, text
, word
);
4277 /* Search upwards from currently selected frame (so that we can
4278 complete on local vars. */
4280 for (b
= get_selected_block (); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
4282 if (!BLOCK_SUPERBLOCK (b
))
4284 surrounding_static_block
= b
; /* For elmin of dups */
4287 /* Also catch fields of types defined in this places which match our
4288 text string. Only complete on types visible from current context. */
4290 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
4292 sym
= BLOCK_SYM (b
, i
);
4293 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
4294 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
4296 struct type
*t
= SYMBOL_TYPE (sym
);
4297 enum type_code c
= TYPE_CODE (t
);
4299 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
4301 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
4303 if (TYPE_FIELD_NAME (t
, j
))
4305 completion_list_add_name (TYPE_FIELD_NAME (t
, j
),
4306 sym_text
, sym_text_len
, text
, word
);
4314 /* Go through the symtabs and check the externs and statics for
4315 symbols which match. */
4317 ALL_SYMTABS (objfile
, s
)
4320 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
4321 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
4323 sym
= BLOCK_SYM (b
, i
);
4324 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
4328 ALL_SYMTABS (objfile
, s
)
4331 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
4332 /* Don't do this block twice. */
4333 if (b
== surrounding_static_block
)
4335 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
4337 sym
= BLOCK_SYM (b
, i
);
4338 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
4342 return (return_val
);
4345 /* Determine if PC is in the prologue of a function. The prologue is the area
4346 between the first instruction of a function, and the first executable line.
4347 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
4349 If non-zero, func_start is where we think the prologue starts, possibly
4350 by previous examination of symbol table information.
4354 in_prologue (pc
, func_start
)
4356 CORE_ADDR func_start
;
4358 struct symtab_and_line sal
;
4359 CORE_ADDR func_addr
, func_end
;
4361 if (!find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
4362 goto nosyms
; /* Might be in prologue */
4364 sal
= find_pc_line (func_addr
, 0);
4369 /* sal.end is the address of the first instruction past sal.line. */
4370 if (sal
.end
> func_addr
4371 && sal
.end
<= func_end
) /* Is prologue in function? */
4372 return pc
< sal
.end
; /* Yes, is pc in prologue? */
4374 /* The line after the prologue seems to be outside the function. In this
4375 case, tell the caller to find the prologue the hard way. */
4379 /* Come here when symtabs don't contain line # info. In this case, it is
4380 likely that the user has stepped into a library function w/o symbols, or
4381 is doing a stepi/nexti through code without symbols. */
4385 /* If func_start is zero (meaning unknown) then we don't know whether pc is
4386 in the prologue or not. I.E. it might be. */
4391 /* We need to call the target-specific prologue skipping functions with the
4392 function's start address because PC may be pointing at an instruction that
4393 could be mistakenly considered part of the prologue. */
4395 func_start
= SKIP_PROLOGUE (func_start
);
4397 return pc
< func_start
;
4401 /* Begin overload resolution functions */
4402 /* Helper routine for make_symbol_completion_list. */
4404 static int sym_return_val_size
;
4405 static int sym_return_val_index
;
4406 static struct symbol
**sym_return_val
;
4408 /* Test to see if the symbol specified by SYMNAME (which is already
4409 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
4410 characters. If so, add it to the current completion list. */
4413 overload_list_add_symbol (sym
, oload_name
)
4420 /* Get the demangled name without parameters */
4421 char *sym_name
= cplus_demangle (SYMBOL_NAME (sym
), DMGL_ARM
| DMGL_ANSI
);
4424 sym_name
= (char *) xmalloc (strlen (SYMBOL_NAME (sym
)) + 1);
4425 strcpy (sym_name
, SYMBOL_NAME (sym
));
4428 /* skip symbols that cannot match */
4429 if (strcmp (sym_name
, oload_name
) != 0)
4432 /* If there is no type information, we can't do anything, so skip */
4433 if (SYMBOL_TYPE (sym
) == NULL
)
4436 /* skip any symbols that we've already considered. */
4437 for (i
= 0; i
< sym_return_val_index
; ++i
)
4438 if (!strcmp (SYMBOL_NAME (sym
), SYMBOL_NAME (sym_return_val
[i
])))
4441 /* We have a match for an overload instance, so add SYM to the current list
4442 * of overload instances */
4443 if (sym_return_val_index
+ 3 > sym_return_val_size
)
4445 newsize
= (sym_return_val_size
*= 2) * sizeof (struct symbol
*);
4446 sym_return_val
= (struct symbol
**) xrealloc ((char *) sym_return_val
, newsize
);
4448 sym_return_val
[sym_return_val_index
++] = sym
;
4449 sym_return_val
[sym_return_val_index
] = NULL
;
4454 /* Return a null-terminated list of pointers to function symbols that
4455 * match name of the supplied symbol FSYM.
4456 * This is used in finding all overloaded instances of a function name.
4457 * This has been modified from make_symbol_completion_list. */
4461 make_symbol_overload_list (fsym
)
4462 struct symbol
*fsym
;
4464 register struct symbol
*sym
;
4465 register struct symtab
*s
;
4466 register struct partial_symtab
*ps
;
4467 register struct minimal_symbol
*msymbol
;
4468 register struct objfile
*objfile
;
4469 register struct block
*b
, *surrounding_static_block
= 0;
4471 struct partial_symbol
**psym
;
4472 /* The name we are completing on. */
4473 char *oload_name
= NULL
;
4474 /* Length of name. */
4475 int oload_name_len
= 0;
4477 /* Look for the symbol we are supposed to complete on.
4478 * FIXME: This should be language-specific. */
4480 oload_name
= cplus_demangle (SYMBOL_NAME (fsym
), DMGL_ARM
| DMGL_ANSI
);
4483 oload_name
= (char *) xmalloc (strlen (SYMBOL_NAME (fsym
)) + 1);
4484 strcpy (oload_name
, SYMBOL_NAME (fsym
));
4486 oload_name_len
= strlen (oload_name
);
4488 sym_return_val_size
= 100;
4489 sym_return_val_index
= 0;
4490 sym_return_val
= (struct symbol
**) xmalloc ((sym_return_val_size
+ 1) * sizeof (struct symbol
*));
4491 sym_return_val
[0] = NULL
;
4493 /* Comment and #if 0 from Rajiv Mirani <mirani@cup.hp.com>.
4494 However, leaving #if 0's around is uncool. We need to figure out
4495 what this is really trying to do, decide whether we want that,
4496 and either fix it or delete it. --- Jim Blandy, Mar 1999 */
4498 /* ??? RM: What in hell is this? overload_list_add_symbol expects a symbol,
4499 * not a partial_symbol or a minimal_symbol. And it looks at the type field
4500 * of the symbol, and we don't know the type of minimal and partial symbols
4503 /* Look through the partial symtabs for all symbols which begin
4504 by matching OLOAD_NAME. Add each one that you find to the list. */
4506 ALL_PSYMTABS (objfile
, ps
)
4508 /* If the psymtab's been read in we'll get it when we search
4509 through the blockvector. */
4513 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
4514 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
4515 + ps
->n_global_syms
);
4518 /* If interrupted, then quit. */
4520 overload_list_add_symbol (*psym
, oload_name
);
4523 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
4524 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
4525 + ps
->n_static_syms
);
4529 overload_list_add_symbol (*psym
, oload_name
);
4533 /* At this point scan through the misc symbol vectors and add each
4534 symbol you find to the list. Eventually we want to ignore
4535 anything that isn't a text symbol (everything else will be
4536 handled by the psymtab code above). */
4538 ALL_MSYMBOLS (objfile
, msymbol
)
4541 overload_list_add_symbol (msymbol
, oload_name
);
4545 /* Search upwards from currently selected frame (so that we can
4546 complete on local vars. */
4548 for (b
= get_selected_block (); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
4550 if (!BLOCK_SUPERBLOCK (b
))
4552 surrounding_static_block
= b
; /* For elimination of dups */
4555 /* Also catch fields of types defined in this places which match our
4556 text string. Only complete on types visible from current context. */
4558 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
4560 sym
= BLOCK_SYM (b
, i
);
4561 overload_list_add_symbol (sym
, oload_name
);
4565 /* Go through the symtabs and check the externs and statics for
4566 symbols which match. */
4568 ALL_SYMTABS (objfile
, s
)
4571 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
4572 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
4574 sym
= BLOCK_SYM (b
, i
);
4575 overload_list_add_symbol (sym
, oload_name
);
4579 ALL_SYMTABS (objfile
, s
)
4582 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
4583 /* Don't do this block twice. */
4584 if (b
== surrounding_static_block
)
4586 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
4588 sym
= BLOCK_SYM (b
, i
);
4589 overload_list_add_symbol (sym
, oload_name
);
4595 return (sym_return_val
);
4598 /* End of overload resolution functions */
4602 _initialize_symtab ()
4604 add_info ("variables", variables_info
,
4605 "All global and static variable names, or those matching REGEXP.");
4607 add_com ("whereis", class_info
, variables_info
,
4608 "All global and static variable names, or those matching REGEXP.");
4610 add_info ("functions", functions_info
,
4611 "All function names, or those matching REGEXP.");
4613 /* FIXME: This command has at least the following problems:
4614 1. It prints builtin types (in a very strange and confusing fashion).
4615 2. It doesn't print right, e.g. with
4616 typedef struct foo *FOO
4617 type_print prints "FOO" when we want to make it (in this situation)
4618 print "struct foo *".
4619 I also think "ptype" or "whatis" is more likely to be useful (but if
4620 there is much disagreement "info types" can be fixed). */
4621 add_info ("types", types_info
,
4622 "All type names, or those matching REGEXP.");
4625 add_info ("methods", methods_info
,
4626 "All method names, or those matching REGEXP::REGEXP.\n\
4627 If the class qualifier is omitted, it is assumed to be the current scope.\n\
4628 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
4631 add_info ("sources", sources_info
,
4632 "Source files in the program.");
4634 add_com ("rbreak", class_breakpoint
, rbreak_command
,
4635 "Set a breakpoint for all functions matching REGEXP.");
4639 add_com ("lf", class_info
, sources_info
, "Source files in the program");
4640 add_com ("lg", class_info
, variables_info
,
4641 "All global and static variable names, or those matching REGEXP.");
4644 /* Initialize the one built-in type that isn't language dependent... */
4645 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
4646 "<unknown type>", (struct objfile
*) NULL
);