1 /* Symbol table lookup for the GNU debugger, GDB.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
33 #include "call-cmds.h"
34 #include "gdb_regex.h"
35 #include "expression.h"
40 #include "filenames.h" /* for FILENAME_CMP */
44 #include <sys/types.h>
46 #include "gdb_string.h"
51 /* Prototype for one function in parser-defs.h,
52 instead of including that entire file. */
54 extern char *find_template_name_end (char *);
56 /* Prototypes for local functions */
58 static void completion_list_add_name (char *, char *, int, char *, char *);
60 static void rbreak_command (char *, int);
62 static void types_info (char *, int);
64 static void functions_info (char *, int);
66 static void variables_info (char *, int);
68 static void sources_info (char *, int);
70 static void output_source_filename (char *, int *);
72 static int find_line_common (struct linetable
*, int, int *);
74 /* This one is used by linespec.c */
76 char *operator_chars (char *p
, char **end
);
78 static struct partial_symbol
*lookup_partial_symbol (struct partial_symtab
*,
82 static struct symtab
*lookup_symtab_1 (const char *);
84 static struct symbol
*lookup_symbol_aux (const char *name
, const
85 struct block
*block
, const
86 namespace_enum
namespace, int
87 *is_a_field_of_this
, struct
91 static struct symbol
*find_active_alias (struct symbol
*sym
, CORE_ADDR addr
);
93 /* This flag is used in hppa-tdep.c, and set in hp-symtab-read.c */
94 /* Signals the presence of objects compiled by HP compilers */
95 int hp_som_som_object_present
= 0;
97 static void fixup_section (struct general_symbol_info
*, struct objfile
*);
99 static int file_matches (char *, char **, int);
101 static void print_symbol_info (namespace_enum
,
102 struct symtab
*, struct symbol
*, int, char *);
104 static void print_msymbol_info (struct minimal_symbol
*);
106 static void symtab_symbol_info (char *, namespace_enum
, int);
108 static void overload_list_add_symbol (struct symbol
*sym
, char *oload_name
);
110 void _initialize_symtab (void);
114 /* The single non-language-specific builtin type */
115 struct type
*builtin_type_error
;
117 /* Block in which the most recently searched-for symbol was found.
118 Might be better to make this a parameter to lookup_symbol and
121 const struct block
*block_found
;
123 /* While the C++ support is still in flux, issue a possibly helpful hint on
124 using the new command completion feature on single quoted demangled C++
125 symbols. Remove when loose ends are cleaned up. FIXME -fnf */
128 cplusplus_hint (char *name
)
130 while (*name
== '\'')
132 printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name
, name
);
133 printf_filtered ("(Note leading single quote.)\n");
136 /* Check for a symtab of a specific name; first in symtabs, then in
137 psymtabs. *If* there is no '/' in the name, a match after a '/'
138 in the symtab filename will also work. */
140 static struct symtab
*
141 lookup_symtab_1 (const char *name
)
143 register struct symtab
*s
;
144 register struct partial_symtab
*ps
;
145 register struct objfile
*objfile
;
149 /* First, search for an exact match */
151 ALL_SYMTABS (objfile
, s
)
152 if (FILENAME_CMP (name
, s
->filename
) == 0)
155 /* Now, search for a matching tail (only if name doesn't have any dirs) */
157 if (lbasename (name
) == name
)
158 ALL_SYMTABS (objfile
, s
)
160 if (FILENAME_CMP (lbasename (s
->filename
), name
) == 0)
164 /* Same search rules as above apply here, but now we look thru the
167 ps
= lookup_partial_symtab (name
);
172 error ("Internal: readin %s pst for `%s' found when no symtab found.",
175 s
= PSYMTAB_TO_SYMTAB (ps
);
180 /* At this point, we have located the psymtab for this file, but
181 the conversion to a symtab has failed. This usually happens
182 when we are looking up an include file. In this case,
183 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
184 been created. So, we need to run through the symtabs again in
185 order to find the file.
186 XXX - This is a crock, and should be fixed inside of the the
187 symbol parsing routines. */
191 /* Lookup the symbol table of a source file named NAME. Try a couple
192 of variations if the first lookup doesn't work. */
195 lookup_symtab (const char *name
)
197 register struct symtab
*s
;
202 s
= lookup_symtab_1 (name
);
207 /* This screws c-exp.y:yylex if there is both a type "tree" and a symtab
210 /* If name not found as specified, see if adding ".c" helps. */
211 /* Why is this? Is it just a user convenience? (If so, it's pretty
212 questionable in the presence of C++, FORTRAN, etc.). It's not in
215 copy
= (char *) alloca (strlen (name
) + 3);
218 s
= lookup_symtab_1 (copy
);
223 /* We didn't find anything; die. */
227 /* Lookup the partial symbol table of a source file named NAME.
228 *If* there is no '/' in the name, a match after a '/'
229 in the psymtab filename will also work. */
231 struct partial_symtab
*
232 lookup_partial_symtab (const char *name
)
234 register struct partial_symtab
*pst
;
235 register struct objfile
*objfile
;
237 ALL_PSYMTABS (objfile
, pst
)
239 if (FILENAME_CMP (name
, pst
->filename
) == 0)
245 /* Now, search for a matching tail (only if name doesn't have any dirs) */
247 if (lbasename (name
) == name
)
248 ALL_PSYMTABS (objfile
, pst
)
250 if (FILENAME_CMP (lbasename (pst
->filename
), name
) == 0)
257 /* Mangle a GDB method stub type. This actually reassembles the pieces of the
258 full method name, which consist of the class name (from T), the unadorned
259 method name from METHOD_ID, and the signature for the specific overload,
260 specified by SIGNATURE_ID. Note that this function is g++ specific. */
263 gdb_mangle_name (struct type
*type
, int method_id
, int signature_id
)
265 int mangled_name_len
;
267 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
268 struct fn_field
*method
= &f
[signature_id
];
269 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, method_id
);
270 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, signature_id
);
271 char *newname
= type_name_no_tag (type
);
273 /* Does the form of physname indicate that it is the full mangled name
274 of a constructor (not just the args)? */
275 int is_full_physname_constructor
;
278 int is_destructor
= is_destructor_name (physname
);
279 /* Need a new type prefix. */
280 char *const_prefix
= method
->is_const
? "C" : "";
281 char *volatile_prefix
= method
->is_volatile
? "V" : "";
283 int len
= (newname
== NULL
? 0 : strlen (newname
));
285 if (is_operator_name (field_name
))
286 return xstrdup (physname
);
288 is_full_physname_constructor
= is_constructor_name (physname
);
291 is_full_physname_constructor
|| (newname
&& STREQ (field_name
, newname
));
294 is_destructor
= (strncmp (physname
, "__dt", 4) == 0);
296 if (is_destructor
|| is_full_physname_constructor
)
298 mangled_name
= (char *) xmalloc (strlen (physname
) + 1);
299 strcpy (mangled_name
, physname
);
305 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
307 else if (physname
[0] == 't' || physname
[0] == 'Q')
309 /* The physname for template and qualified methods already includes
311 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
317 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
319 mangled_name_len
= ((is_constructor
? 0 : strlen (field_name
))
320 + strlen (buf
) + len
+ strlen (physname
) + 1);
323 mangled_name
= (char *) xmalloc (mangled_name_len
);
325 mangled_name
[0] = '\0';
327 strcpy (mangled_name
, field_name
);
329 strcat (mangled_name
, buf
);
330 /* If the class doesn't have a name, i.e. newname NULL, then we just
331 mangle it using 0 for the length of the class. Thus it gets mangled
332 as something starting with `::' rather than `classname::'. */
334 strcat (mangled_name
, newname
);
336 strcat (mangled_name
, physname
);
337 return (mangled_name
);
342 /* Find which partial symtab on contains PC and SECTION. Return 0 if none. */
344 struct partial_symtab
*
345 find_pc_sect_psymtab (CORE_ADDR pc
, asection
*section
)
347 register struct partial_symtab
*pst
;
348 register struct objfile
*objfile
;
350 ALL_PSYMTABS (objfile
, pst
)
352 if (pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
354 struct minimal_symbol
*msymbol
;
355 struct partial_symtab
*tpst
;
357 /* An objfile that has its functions reordered might have
358 many partial symbol tables containing the PC, but
359 we want the partial symbol table that contains the
360 function containing the PC. */
361 if (!(objfile
->flags
& OBJF_REORDERED
) &&
362 section
== 0) /* can't validate section this way */
365 msymbol
= lookup_minimal_symbol_by_pc_section (pc
, section
);
369 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
371 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
373 struct partial_symbol
*p
;
375 p
= find_pc_sect_psymbol (tpst
, pc
, section
);
377 && SYMBOL_VALUE_ADDRESS (p
)
378 == SYMBOL_VALUE_ADDRESS (msymbol
))
388 /* Find which partial symtab contains PC. Return 0 if none.
389 Backward compatibility, no section */
391 struct partial_symtab
*
392 find_pc_psymtab (CORE_ADDR pc
)
394 return find_pc_sect_psymtab (pc
, find_pc_mapped_section (pc
));
397 /* Find which partial symbol within a psymtab matches PC and SECTION.
398 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
400 struct partial_symbol
*
401 find_pc_sect_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
,
404 struct partial_symbol
*best
= NULL
, *p
, **pp
;
408 psymtab
= find_pc_sect_psymtab (pc
, section
);
412 /* Cope with programs that start at address 0 */
413 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
415 /* Search the global symbols as well as the static symbols, so that
416 find_pc_partial_function doesn't use a minimal symbol and thus
417 cache a bad endaddr. */
418 for (pp
= psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
419 (pp
- (psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
420 < psymtab
->n_global_syms
);
424 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
425 && SYMBOL_CLASS (p
) == LOC_BLOCK
426 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
427 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
428 || (psymtab
->textlow
== 0
429 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
431 if (section
) /* match on a specific section */
433 fixup_psymbol_section (p
, psymtab
->objfile
);
434 if (SYMBOL_BFD_SECTION (p
) != section
)
437 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
442 for (pp
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
443 (pp
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
444 < psymtab
->n_static_syms
);
448 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
449 && SYMBOL_CLASS (p
) == LOC_BLOCK
450 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
451 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
452 || (psymtab
->textlow
== 0
453 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
455 if (section
) /* match on a specific section */
457 fixup_psymbol_section (p
, psymtab
->objfile
);
458 if (SYMBOL_BFD_SECTION (p
) != section
)
461 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
469 /* Find which partial symbol within a psymtab matches PC. Return 0 if none.
470 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
472 struct partial_symbol
*
473 find_pc_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
)
475 return find_pc_sect_psymbol (psymtab
, pc
, find_pc_mapped_section (pc
));
478 /* Debug symbols usually don't have section information. We need to dig that
479 out of the minimal symbols and stash that in the debug symbol. */
482 fixup_section (struct general_symbol_info
*ginfo
, struct objfile
*objfile
)
484 struct minimal_symbol
*msym
;
485 msym
= lookup_minimal_symbol (ginfo
->name
, NULL
, objfile
);
489 ginfo
->bfd_section
= SYMBOL_BFD_SECTION (msym
);
490 ginfo
->section
= SYMBOL_SECTION (msym
);
495 fixup_symbol_section (struct symbol
*sym
, struct objfile
*objfile
)
500 if (SYMBOL_BFD_SECTION (sym
))
503 fixup_section (&sym
->ginfo
, objfile
);
508 struct partial_symbol
*
509 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
514 if (SYMBOL_BFD_SECTION (psym
))
517 fixup_section (&psym
->ginfo
, objfile
);
522 /* Find the definition for a specified symbol name NAME
523 in namespace NAMESPACE, visible from lexical block BLOCK.
524 Returns the struct symbol pointer, or zero if no symbol is found.
525 If SYMTAB is non-NULL, store the symbol table in which the
526 symbol was found there, or NULL if not found.
527 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
528 NAME is a field of the current implied argument `this'. If so set
529 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
530 BLOCK_FOUND is set to the block in which NAME is found (in the case of
531 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
533 /* This function has a bunch of loops in it and it would seem to be
534 attractive to put in some QUIT's (though I'm not really sure
535 whether it can run long enough to be really important). But there
536 are a few calls for which it would appear to be bad news to quit
537 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and
538 nindy_frame_chain_valid in nindy-tdep.c. (Note that there is C++
539 code below which can error(), but that probably doesn't affect
540 these calls since they are looking for a known variable and thus
541 can probably assume it will never hit the C++ code). */
544 lookup_symbol (const char *name
, const struct block
*block
,
545 const namespace_enum
namespace, int *is_a_field_of_this
,
546 struct symtab
**symtab
)
548 char *modified_name
= NULL
;
549 char *modified_name2
= NULL
;
550 int needtofreename
= 0;
551 struct symbol
*returnval
;
553 if (case_sensitivity
== case_sensitive_off
)
559 copy
= (char *) alloca (len
+ 1);
560 for (i
= 0; i
< len
; i
++)
561 copy
[i
] = tolower (name
[i
]);
563 modified_name
= copy
;
566 modified_name
= (char *) name
;
568 /* If we are using C++ language, demangle the name before doing a lookup, so
569 we can always binary search. */
570 if (current_language
->la_language
== language_cplus
)
572 modified_name2
= cplus_demangle (modified_name
, DMGL_ANSI
| DMGL_PARAMS
);
575 modified_name
= modified_name2
;
580 returnval
= lookup_symbol_aux (modified_name
, block
, namespace,
581 is_a_field_of_this
, symtab
);
583 xfree (modified_name2
);
588 static struct symbol
*
589 lookup_symbol_aux (const char *name
, const struct block
*block
,
590 const namespace_enum
namespace, int *is_a_field_of_this
,
591 struct symtab
**symtab
)
593 register struct symbol
*sym
;
594 register struct symtab
*s
= NULL
;
595 register struct partial_symtab
*ps
;
596 register struct blockvector
*bv
;
597 register struct objfile
*objfile
= NULL
;
598 register struct block
*b
;
599 register struct minimal_symbol
*msymbol
;
602 /* Search specified block and its superiors. */
606 sym
= lookup_block_symbol (block
, name
, namespace);
612 /* Search the list of symtabs for one which contains the
613 address of the start of this block. */
614 ALL_SYMTABS (objfile
, s
)
616 bv
= BLOCKVECTOR (s
);
617 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
618 if (BLOCK_START (b
) <= BLOCK_START (block
)
619 && BLOCK_END (b
) > BLOCK_START (block
))
626 return fixup_symbol_section (sym
, objfile
);
628 block
= BLOCK_SUPERBLOCK (block
);
631 /* FIXME: this code is never executed--block is always NULL at this
632 point. What is it trying to do, anyway? We already should have
633 checked the STATIC_BLOCK above (it is the superblock of top-level
634 blocks). Why is VAR_NAMESPACE special-cased? */
635 /* Don't need to mess with the psymtabs; if we have a block,
636 that file is read in. If we don't, then we deal later with
637 all the psymtab stuff that needs checking. */
638 /* Note (RT): The following never-executed code looks unnecessary to me also.
639 * If we change the code to use the original (passed-in)
640 * value of 'block', we could cause it to execute, but then what
641 * would it do? The STATIC_BLOCK of the symtab containing the passed-in
642 * 'block' was already searched by the above code. And the STATIC_BLOCK's
643 * of *other* symtabs (those files not containing 'block' lexically)
644 * should not contain 'block' address-wise. So we wouldn't expect this
645 * code to find any 'sym''s that were not found above. I vote for
646 * deleting the following paragraph of code.
648 if (namespace == VAR_NAMESPACE
&& block
!= NULL
)
651 /* Find the right symtab. */
652 ALL_SYMTABS (objfile
, s
)
654 bv
= BLOCKVECTOR (s
);
655 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
656 if (BLOCK_START (b
) <= BLOCK_START (block
)
657 && BLOCK_END (b
) > BLOCK_START (block
))
659 sym
= lookup_block_symbol (b
, name
, VAR_NAMESPACE
);
665 return fixup_symbol_section (sym
, objfile
);
672 /* C++: If requested to do so by the caller,
673 check to see if NAME is a field of `this'. */
674 if (is_a_field_of_this
)
676 struct value
*v
= value_of_this (0);
678 *is_a_field_of_this
= 0;
679 if (v
&& check_field (v
, name
))
681 *is_a_field_of_this
= 1;
688 /* Now search all global blocks. Do the symtab's first, then
689 check the psymtab's. If a psymtab indicates the existence
690 of the desired name as a global, then do psymtab-to-symtab
691 conversion on the fly and return the found symbol. */
693 ALL_SYMTABS (objfile
, s
)
695 bv
= BLOCKVECTOR (s
);
696 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
697 sym
= lookup_block_symbol (block
, name
, namespace);
703 return fixup_symbol_section (sym
, objfile
);
709 /* Check for the possibility of the symbol being a function or
710 a mangled variable that is stored in one of the minimal symbol tables.
711 Eventually, all global symbols might be resolved in this way. */
713 if (namespace == VAR_NAMESPACE
)
715 msymbol
= lookup_minimal_symbol (name
, NULL
, NULL
);
718 s
= find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol
),
719 SYMBOL_BFD_SECTION (msymbol
));
722 /* This is a function which has a symtab for its address. */
723 bv
= BLOCKVECTOR (s
);
724 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
725 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
727 /* We kept static functions in minimal symbol table as well as
728 in static scope. We want to find them in the symbol table. */
731 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
732 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
736 /* sym == 0 if symbol was found in the minimal symbol table
737 but not in the symtab.
738 Return 0 to use the msymbol definition of "foo_".
740 This happens for Fortran "foo_" symbols,
741 which are "foo" in the symtab.
743 This can also happen if "asm" is used to make a
744 regular symbol but not a debugging symbol, e.g.
751 return fixup_symbol_section (sym
, objfile
);
753 else if (MSYMBOL_TYPE (msymbol
) != mst_text
754 && MSYMBOL_TYPE (msymbol
) != mst_file_text
755 && !STREQ (name
, SYMBOL_NAME (msymbol
)))
757 /* This is a mangled variable, look it up by its
759 return lookup_symbol_aux (SYMBOL_NAME (msymbol
), block
,
760 namespace, is_a_field_of_this
, symtab
);
762 /* There are no debug symbols for this file, or we are looking
763 for an unmangled variable.
764 Try to find a matching static symbol below. */
770 ALL_PSYMTABS (objfile
, ps
)
772 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
774 s
= PSYMTAB_TO_SYMTAB (ps
);
775 bv
= BLOCKVECTOR (s
);
776 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
777 sym
= lookup_block_symbol (block
, name
, namespace);
780 /* This shouldn't be necessary, but as a last resort
781 * try looking in the statics even though the psymtab
782 * claimed the symbol was global. It's possible that
783 * the psymtab gets it wrong in some cases.
785 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
786 sym
= lookup_block_symbol (block
, name
, namespace);
788 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
789 %s may be an inlined function, or may be a template function\n\
790 (if a template, try specifying an instantiation: %s<type>).",
791 name
, ps
->filename
, name
, name
);
795 return fixup_symbol_section (sym
, objfile
);
799 /* Now search all static file-level symbols.
800 Not strictly correct, but more useful than an error.
801 Do the symtabs first, then check the psymtabs.
802 If a psymtab indicates the existence
803 of the desired name as a file-level static, then do psymtab-to-symtab
804 conversion on the fly and return the found symbol. */
806 ALL_SYMTABS (objfile
, s
)
808 bv
= BLOCKVECTOR (s
);
809 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
810 sym
= lookup_block_symbol (block
, name
, namespace);
816 return fixup_symbol_section (sym
, objfile
);
820 ALL_PSYMTABS (objfile
, ps
)
822 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
824 s
= PSYMTAB_TO_SYMTAB (ps
);
825 bv
= BLOCKVECTOR (s
);
826 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
827 sym
= lookup_block_symbol (block
, name
, namespace);
830 /* This shouldn't be necessary, but as a last resort
831 * try looking in the globals even though the psymtab
832 * claimed the symbol was static. It's possible that
833 * the psymtab gets it wrong in some cases.
835 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
836 sym
= lookup_block_symbol (block
, name
, namespace);
838 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
839 %s may be an inlined function, or may be a template function\n\
840 (if a template, try specifying an instantiation: %s<type>).",
841 name
, ps
->filename
, name
, name
);
845 return fixup_symbol_section (sym
, objfile
);
851 /* Check for the possibility of the symbol being a function or
852 a global variable that is stored in one of the minimal symbol tables.
853 The "minimal symbol table" is built from linker-supplied info.
855 RT: I moved this check to last, after the complete search of
856 the global (p)symtab's and static (p)symtab's. For HP-generated
857 symbol tables, this check was causing a premature exit from
858 lookup_symbol with NULL return, and thus messing up symbol lookups
859 of things like "c::f". It seems to me a check of the minimal
860 symbol table ought to be a last resort in any case. I'm vaguely
861 worried about the comment below which talks about FORTRAN routines "foo_"
862 though... is it saying we need to do the "minsym" check before
863 the static check in this case?
866 if (namespace == VAR_NAMESPACE
)
868 msymbol
= lookup_minimal_symbol (name
, NULL
, NULL
);
871 /* OK, we found a minimal symbol in spite of not
872 * finding any symbol. There are various possible
873 * explanations for this. One possibility is the symbol
874 * exists in code not compiled -g. Another possibility
875 * is that the 'psymtab' isn't doing its job.
876 * A third possibility, related to #2, is that we were confused
877 * by name-mangling. For instance, maybe the psymtab isn't
878 * doing its job because it only know about demangled
879 * names, but we were given a mangled name...
882 /* We first use the address in the msymbol to try to
883 * locate the appropriate symtab. Note that find_pc_symtab()
884 * has a side-effect of doing psymtab-to-symtab expansion,
885 * for the found symtab.
887 s
= find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
));
890 bv
= BLOCKVECTOR (s
);
891 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
892 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
894 /* We kept static functions in minimal symbol table as well as
895 in static scope. We want to find them in the symbol table. */
898 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
899 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
902 /* If we found one, return it */
910 /* If we get here with sym == 0, the symbol was
911 found in the minimal symbol table
912 but not in the symtab.
913 Fall through and return 0 to use the msymbol
914 definition of "foo_".
915 (Note that outer code generally follows up a call
916 to this routine with a call to lookup_minimal_symbol(),
917 so a 0 return means we'll just flow into that other routine).
919 This happens for Fortran "foo_" symbols,
920 which are "foo" in the symtab.
922 This can also happen if "asm" is used to make a
923 regular symbol but not a debugging symbol, e.g.
929 /* If the lookup-by-address fails, try repeating the
930 * entire lookup process with the symbol name from
931 * the msymbol (if different from the original symbol name).
933 else if (MSYMBOL_TYPE (msymbol
) != mst_text
934 && MSYMBOL_TYPE (msymbol
) != mst_file_text
935 && !STREQ (name
, SYMBOL_NAME (msymbol
)))
937 return lookup_symbol_aux (SYMBOL_NAME (msymbol
), block
,
938 namespace, is_a_field_of_this
, symtab
);
950 /* Look, in partial_symtab PST, for symbol NAME. Check the global
951 symbols if GLOBAL, the static symbols if not */
953 static struct partial_symbol
*
954 lookup_partial_symbol (struct partial_symtab
*pst
, const char *name
, int global
,
955 namespace_enum
namespace)
957 struct partial_symbol
*temp
;
958 struct partial_symbol
**start
, **psym
;
959 struct partial_symbol
**top
, **bottom
, **center
;
960 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
961 int do_linear_search
= 1;
968 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
969 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
971 if (global
) /* This means we can use a binary search. */
973 do_linear_search
= 0;
975 /* Binary search. This search is guaranteed to end with center
976 pointing at the earliest partial symbol with the correct
977 name. At that point *all* partial symbols with that name
978 will be checked against the correct namespace. */
981 top
= start
+ length
- 1;
984 center
= bottom
+ (top
- bottom
) / 2;
986 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
987 if (!do_linear_search
988 && (SYMBOL_LANGUAGE (*center
) == language_java
))
990 do_linear_search
= 1;
992 if (strcmp (SYMBOL_SOURCE_NAME (*center
), name
) >= 0)
1001 if (!(top
== bottom
))
1002 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
1004 /* djb - 2000-06-03 - Use SYMBOL_MATCHES_NAME, not a strcmp, so
1005 we don't have to force a linear search on C++. Probably holds true
1006 for JAVA as well, no way to check.*/
1007 while (SYMBOL_MATCHES_NAME (*top
,name
))
1009 if (SYMBOL_NAMESPACE (*top
) == namespace)
1017 /* Can't use a binary search or else we found during the binary search that
1018 we should also do a linear search. */
1020 if (do_linear_search
)
1022 for (psym
= start
; psym
< start
+ length
; psym
++)
1024 if (namespace == SYMBOL_NAMESPACE (*psym
))
1026 if (SYMBOL_MATCHES_NAME (*psym
, name
))
1037 /* Look up a type named NAME in the struct_namespace. The type returned
1038 must not be opaque -- i.e., must have at least one field defined
1040 This code was modelled on lookup_symbol -- the parts not relevant to looking
1041 up types were just left out. In particular it's assumed here that types
1042 are available in struct_namespace and only at file-static or global blocks. */
1046 lookup_transparent_type (const char *name
)
1048 register struct symbol
*sym
;
1049 register struct symtab
*s
= NULL
;
1050 register struct partial_symtab
*ps
;
1051 struct blockvector
*bv
;
1052 register struct objfile
*objfile
;
1053 register struct block
*block
;
1055 /* Now search all the global symbols. Do the symtab's first, then
1056 check the psymtab's. If a psymtab indicates the existence
1057 of the desired name as a global, then do psymtab-to-symtab
1058 conversion on the fly and return the found symbol. */
1060 ALL_SYMTABS (objfile
, s
)
1062 bv
= BLOCKVECTOR (s
);
1063 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1064 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1065 if (sym
&& !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1067 return SYMBOL_TYPE (sym
);
1071 ALL_PSYMTABS (objfile
, ps
)
1073 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, STRUCT_NAMESPACE
))
1075 s
= PSYMTAB_TO_SYMTAB (ps
);
1076 bv
= BLOCKVECTOR (s
);
1077 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1078 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1081 /* This shouldn't be necessary, but as a last resort
1082 * try looking in the statics even though the psymtab
1083 * claimed the symbol was global. It's possible that
1084 * the psymtab gets it wrong in some cases.
1086 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1087 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1089 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
1090 %s may be an inlined function, or may be a template function\n\
1091 (if a template, try specifying an instantiation: %s<type>).",
1092 name
, ps
->filename
, name
, name
);
1094 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1095 return SYMBOL_TYPE (sym
);
1099 /* Now search the static file-level symbols.
1100 Not strictly correct, but more useful than an error.
1101 Do the symtab's first, then
1102 check the psymtab's. If a psymtab indicates the existence
1103 of the desired name as a file-level static, then do psymtab-to-symtab
1104 conversion on the fly and return the found symbol.
1107 ALL_SYMTABS (objfile
, s
)
1109 bv
= BLOCKVECTOR (s
);
1110 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1111 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1112 if (sym
&& !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1114 return SYMBOL_TYPE (sym
);
1118 ALL_PSYMTABS (objfile
, ps
)
1120 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, STRUCT_NAMESPACE
))
1122 s
= PSYMTAB_TO_SYMTAB (ps
);
1123 bv
= BLOCKVECTOR (s
);
1124 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1125 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1128 /* This shouldn't be necessary, but as a last resort
1129 * try looking in the globals even though the psymtab
1130 * claimed the symbol was static. It's possible that
1131 * the psymtab gets it wrong in some cases.
1133 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1134 sym
= lookup_block_symbol (block
, name
, STRUCT_NAMESPACE
);
1136 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
1137 %s may be an inlined function, or may be a template function\n\
1138 (if a template, try specifying an instantiation: %s<type>).",
1139 name
, ps
->filename
, name
, name
);
1141 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1142 return SYMBOL_TYPE (sym
);
1145 return (struct type
*) 0;
1149 /* Find the psymtab containing main(). */
1150 /* FIXME: What about languages without main() or specially linked
1151 executables that have no main() ? */
1153 struct partial_symtab
*
1154 find_main_psymtab (void)
1156 register struct partial_symtab
*pst
;
1157 register struct objfile
*objfile
;
1159 ALL_PSYMTABS (objfile
, pst
)
1161 if (lookup_partial_symbol (pst
, "main", 1, VAR_NAMESPACE
))
1169 /* Search BLOCK for symbol NAME in NAMESPACE.
1171 Note that if NAME is the demangled form of a C++ symbol, we will fail
1172 to find a match during the binary search of the non-encoded names, but
1173 for now we don't worry about the slight inefficiency of looking for
1174 a match we'll never find, since it will go pretty quick. Once the
1175 binary search terminates, we drop through and do a straight linear
1176 search on the symbols. Each symbol which is marked as being a C++
1177 symbol (language_cplus set) has both the encoded and non-encoded names
1178 tested for a match. */
1181 lookup_block_symbol (register const struct block
*block
, const char *name
,
1182 const namespace_enum
namespace)
1184 register int bot
, top
, inc
;
1185 register struct symbol
*sym
;
1186 register struct symbol
*sym_found
= NULL
;
1187 register int do_linear_search
= 1;
1189 /* If the blocks's symbols were sorted, start with a binary search. */
1191 if (BLOCK_SHOULD_SORT (block
))
1193 /* Reset the linear search flag so if the binary search fails, we
1194 won't do the linear search once unless we find some reason to
1197 do_linear_search
= 0;
1198 top
= BLOCK_NSYMS (block
);
1201 /* Advance BOT to not far before the first symbol whose name is NAME. */
1205 inc
= (top
- bot
+ 1);
1206 /* No need to keep binary searching for the last few bits worth. */
1211 inc
= (inc
>> 1) + bot
;
1212 sym
= BLOCK_SYM (block
, inc
);
1213 if (!do_linear_search
&& (SYMBOL_LANGUAGE (sym
) == language_java
))
1215 do_linear_search
= 1;
1217 if (SYMBOL_SOURCE_NAME (sym
)[0] < name
[0])
1221 else if (SYMBOL_SOURCE_NAME (sym
)[0] > name
[0])
1225 else if (strcmp (SYMBOL_SOURCE_NAME (sym
), name
) < 0)
1235 /* Now scan forward until we run out of symbols, find one whose
1236 name is greater than NAME, or find one we want. If there is
1237 more than one symbol with the right name and namespace, we
1238 return the first one; I believe it is now impossible for us
1239 to encounter two symbols with the same name and namespace
1240 here, because blocks containing argument symbols are no
1243 top
= BLOCK_NSYMS (block
);
1246 sym
= BLOCK_SYM (block
, bot
);
1247 if (SYMBOL_NAMESPACE (sym
) == namespace &&
1248 SYMBOL_MATCHES_NAME (sym
, name
))
1256 /* Here if block isn't sorted, or we fail to find a match during the
1257 binary search above. If during the binary search above, we find a
1258 symbol which is a C++ symbol, then we have re-enabled the linear
1259 search flag which was reset when starting the binary search.
1261 This loop is equivalent to the loop above, but hacked greatly for speed.
1263 Note that parameter symbols do not always show up last in the
1264 list; this loop makes sure to take anything else other than
1265 parameter symbols first; it only uses parameter symbols as a
1266 last resort. Note that this only takes up extra computation
1269 if (do_linear_search
)
1271 top
= BLOCK_NSYMS (block
);
1275 sym
= BLOCK_SYM (block
, bot
);
1276 if (SYMBOL_NAMESPACE (sym
) == namespace &&
1277 SYMBOL_MATCHES_NAME (sym
, name
))
1279 /* If SYM has aliases, then use any alias that is active
1280 at the current PC. If no alias is active at the current
1281 PC, then use the main symbol.
1283 ?!? Is checking the current pc correct? Is this routine
1284 ever called to look up a symbol from another context?
1286 FIXME: No, it's not correct. If someone sets a
1287 conditional breakpoint at an address, then the
1288 breakpoint's `struct expression' should refer to the
1289 `struct symbol' appropriate for the breakpoint's
1290 address, which may not be the PC.
1292 Even if it were never called from another context,
1293 it's totally bizarre for lookup_symbol's behavior to
1294 depend on the value of the inferior's current PC. We
1295 should pass in the appropriate PC as well as the
1296 block. The interface to lookup_symbol should change
1297 to require the caller to provide a PC. */
1299 if (SYMBOL_ALIASES (sym
))
1300 sym
= find_active_alias (sym
, read_pc ());
1303 if (SYMBOL_CLASS (sym
) != LOC_ARG
&&
1304 SYMBOL_CLASS (sym
) != LOC_LOCAL_ARG
&&
1305 SYMBOL_CLASS (sym
) != LOC_REF_ARG
&&
1306 SYMBOL_CLASS (sym
) != LOC_REGPARM
&&
1307 SYMBOL_CLASS (sym
) != LOC_REGPARM_ADDR
&&
1308 SYMBOL_CLASS (sym
) != LOC_BASEREG_ARG
)
1316 return (sym_found
); /* Will be NULL if not found. */
1319 /* Given a main symbol SYM and ADDR, search through the alias
1320 list to determine if an alias is active at ADDR and return
1323 If no alias is active, then return SYM. */
1325 static struct symbol
*
1326 find_active_alias (struct symbol
*sym
, CORE_ADDR addr
)
1328 struct range_list
*r
;
1329 struct alias_list
*aliases
;
1331 /* If we have aliases, check them first. */
1332 aliases
= SYMBOL_ALIASES (sym
);
1336 if (!SYMBOL_RANGES (aliases
->sym
))
1337 return aliases
->sym
;
1338 for (r
= SYMBOL_RANGES (aliases
->sym
); r
; r
= r
->next
)
1340 if (r
->start
<= addr
&& r
->end
> addr
)
1341 return aliases
->sym
;
1343 aliases
= aliases
->next
;
1346 /* Nothing found, return the main symbol. */
1351 /* Return the symbol for the function which contains a specified
1352 lexical block, described by a struct block BL. */
1355 block_function (struct block
*bl
)
1357 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
1358 bl
= BLOCK_SUPERBLOCK (bl
);
1360 return BLOCK_FUNCTION (bl
);
1363 /* Find the symtab associated with PC and SECTION. Look through the
1364 psymtabs and read in another symtab if necessary. */
1367 find_pc_sect_symtab (CORE_ADDR pc
, asection
*section
)
1369 register struct block
*b
;
1370 struct blockvector
*bv
;
1371 register struct symtab
*s
= NULL
;
1372 register struct symtab
*best_s
= NULL
;
1373 register struct partial_symtab
*ps
;
1374 register struct objfile
*objfile
;
1375 CORE_ADDR distance
= 0;
1377 /* Search all symtabs for the one whose file contains our address, and which
1378 is the smallest of all the ones containing the address. This is designed
1379 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1380 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1381 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1383 This happens for native ecoff format, where code from included files
1384 gets its own symtab. The symtab for the included file should have
1385 been read in already via the dependency mechanism.
1386 It might be swifter to create several symtabs with the same name
1387 like xcoff does (I'm not sure).
1389 It also happens for objfiles that have their functions reordered.
1390 For these, the symtab we are looking for is not necessarily read in. */
1392 ALL_SYMTABS (objfile
, s
)
1394 bv
= BLOCKVECTOR (s
);
1395 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1397 if (BLOCK_START (b
) <= pc
1398 && BLOCK_END (b
) > pc
1400 || BLOCK_END (b
) - BLOCK_START (b
) < distance
))
1402 /* For an objfile that has its functions reordered,
1403 find_pc_psymtab will find the proper partial symbol table
1404 and we simply return its corresponding symtab. */
1405 /* In order to better support objfiles that contain both
1406 stabs and coff debugging info, we continue on if a psymtab
1408 if ((objfile
->flags
& OBJF_REORDERED
) && objfile
->psymtabs
)
1410 ps
= find_pc_sect_psymtab (pc
, section
);
1412 return PSYMTAB_TO_SYMTAB (ps
);
1418 for (i
= 0; i
< b
->nsyms
; i
++)
1420 fixup_symbol_section (b
->sym
[i
], objfile
);
1421 if (section
== SYMBOL_BFD_SECTION (b
->sym
[i
]))
1425 continue; /* no symbol in this symtab matches section */
1427 distance
= BLOCK_END (b
) - BLOCK_START (b
);
1436 ps
= find_pc_sect_psymtab (pc
, section
);
1440 /* Might want to error() here (in case symtab is corrupt and
1441 will cause a core dump), but maybe we can successfully
1442 continue, so let's not. */
1444 (Internal error: pc 0x%s in read in psymtab, but not in symtab.)\n",
1446 s
= PSYMTAB_TO_SYMTAB (ps
);
1451 /* Find the symtab associated with PC. Look through the psymtabs and
1452 read in another symtab if necessary. Backward compatibility, no section */
1455 find_pc_symtab (CORE_ADDR pc
)
1457 return find_pc_sect_symtab (pc
, find_pc_mapped_section (pc
));
1463 /* Find the closest symbol value (of any sort -- function or variable)
1464 for a given address value. Slow but complete. (currently unused,
1465 mainly because it is too slow. We could fix it if each symtab and
1466 psymtab had contained in it the addresses ranges of each of its
1467 sections, which also would be required to make things like "info
1468 line *0x2345" cause psymtabs to be converted to symtabs). */
1471 find_addr_symbol (CORE_ADDR addr
, struct symtab
**symtabp
, CORE_ADDR
*symaddrp
)
1473 struct symtab
*symtab
, *best_symtab
;
1474 struct objfile
*objfile
;
1475 register int bot
, top
;
1476 register struct symbol
*sym
;
1477 register CORE_ADDR sym_addr
;
1478 struct block
*block
;
1481 /* Info on best symbol seen so far */
1483 register CORE_ADDR best_sym_addr
= 0;
1484 struct symbol
*best_sym
= 0;
1486 /* FIXME -- we should pull in all the psymtabs, too! */
1487 ALL_SYMTABS (objfile
, symtab
)
1489 /* Search the global and static blocks in this symtab for
1490 the closest symbol-address to the desired address. */
1492 for (blocknum
= GLOBAL_BLOCK
; blocknum
<= STATIC_BLOCK
; blocknum
++)
1495 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab
), blocknum
);
1496 top
= BLOCK_NSYMS (block
);
1497 for (bot
= 0; bot
< top
; bot
++)
1499 sym
= BLOCK_SYM (block
, bot
);
1500 switch (SYMBOL_CLASS (sym
))
1504 sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1508 sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1509 /* An indirect symbol really lives at *sym_addr,
1510 * so an indirection needs to be done.
1511 * However, I am leaving this commented out because it's
1512 * expensive, and it's possible that symbolization
1513 * could be done without an active process (in
1514 * case this read_memory will fail). RT
1515 sym_addr = read_memory_unsigned_integer
1516 (sym_addr, TARGET_PTR_BIT / TARGET_CHAR_BIT);
1521 sym_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1528 if (sym_addr
<= addr
)
1529 if (sym_addr
> best_sym_addr
)
1531 /* Quit if we found an exact match. */
1533 best_sym_addr
= sym_addr
;
1534 best_symtab
= symtab
;
1535 if (sym_addr
== addr
)
1544 *symtabp
= best_symtab
;
1546 *symaddrp
= best_sym_addr
;
1551 /* Find the source file and line number for a given PC value and SECTION.
1552 Return a structure containing a symtab pointer, a line number,
1553 and a pc range for the entire source line.
1554 The value's .pc field is NOT the specified pc.
1555 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1556 use the line that ends there. Otherwise, in that case, the line
1557 that begins there is used. */
1559 /* The big complication here is that a line may start in one file, and end just
1560 before the start of another file. This usually occurs when you #include
1561 code in the middle of a subroutine. To properly find the end of a line's PC
1562 range, we must search all symtabs associated with this compilation unit, and
1563 find the one whose first PC is closer than that of the next line in this
1566 /* If it's worth the effort, we could be using a binary search. */
1568 struct symtab_and_line
1569 find_pc_sect_line (CORE_ADDR pc
, struct sec
*section
, int notcurrent
)
1572 register struct linetable
*l
;
1575 register struct linetable_entry
*item
;
1576 struct symtab_and_line val
;
1577 struct blockvector
*bv
;
1578 struct minimal_symbol
*msymbol
;
1579 struct minimal_symbol
*mfunsym
;
1581 /* Info on best line seen so far, and where it starts, and its file. */
1583 struct linetable_entry
*best
= NULL
;
1584 CORE_ADDR best_end
= 0;
1585 struct symtab
*best_symtab
= 0;
1587 /* Store here the first line number
1588 of a file which contains the line at the smallest pc after PC.
1589 If we don't find a line whose range contains PC,
1590 we will use a line one less than this,
1591 with a range from the start of that file to the first line's pc. */
1592 struct linetable_entry
*alt
= NULL
;
1593 struct symtab
*alt_symtab
= 0;
1595 /* Info on best line seen in this file. */
1597 struct linetable_entry
*prev
;
1599 /* If this pc is not from the current frame,
1600 it is the address of the end of a call instruction.
1601 Quite likely that is the start of the following statement.
1602 But what we want is the statement containing the instruction.
1603 Fudge the pc to make sure we get that. */
1605 INIT_SAL (&val
); /* initialize to zeroes */
1610 /* elz: added this because this function returned the wrong
1611 information if the pc belongs to a stub (import/export)
1612 to call a shlib function. This stub would be anywhere between
1613 two functions in the target, and the line info was erroneously
1614 taken to be the one of the line before the pc.
1616 /* RT: Further explanation:
1618 * We have stubs (trampolines) inserted between procedures.
1620 * Example: "shr1" exists in a shared library, and a "shr1" stub also
1621 * exists in the main image.
1623 * In the minimal symbol table, we have a bunch of symbols
1624 * sorted by start address. The stubs are marked as "trampoline",
1625 * the others appear as text. E.g.:
1627 * Minimal symbol table for main image
1628 * main: code for main (text symbol)
1629 * shr1: stub (trampoline symbol)
1630 * foo: code for foo (text symbol)
1632 * Minimal symbol table for "shr1" image:
1634 * shr1: code for shr1 (text symbol)
1637 * So the code below is trying to detect if we are in the stub
1638 * ("shr1" stub), and if so, find the real code ("shr1" trampoline),
1639 * and if found, do the symbolization from the real-code address
1640 * rather than the stub address.
1642 * Assumptions being made about the minimal symbol table:
1643 * 1. lookup_minimal_symbol_by_pc() will return a trampoline only
1644 * if we're really in the trampoline. If we're beyond it (say
1645 * we're in "foo" in the above example), it'll have a closer
1646 * symbol (the "foo" text symbol for example) and will not
1647 * return the trampoline.
1648 * 2. lookup_minimal_symbol_text() will find a real text symbol
1649 * corresponding to the trampoline, and whose address will
1650 * be different than the trampoline address. I put in a sanity
1651 * check for the address being the same, to avoid an
1652 * infinite recursion.
1654 msymbol
= lookup_minimal_symbol_by_pc (pc
);
1655 if (msymbol
!= NULL
)
1656 if (MSYMBOL_TYPE (msymbol
) == mst_solib_trampoline
)
1658 mfunsym
= lookup_minimal_symbol_text (SYMBOL_NAME (msymbol
), NULL
, NULL
);
1659 if (mfunsym
== NULL
)
1660 /* I eliminated this warning since it is coming out
1661 * in the following situation:
1662 * gdb shmain // test program with shared libraries
1663 * (gdb) break shr1 // function in shared lib
1664 * Warning: In stub for ...
1665 * In the above situation, the shared lib is not loaded yet,
1666 * so of course we can't find the real func/line info,
1667 * but the "break" still works, and the warning is annoying.
1668 * So I commented out the warning. RT */
1669 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_NAME(msymbol)) */ ;
1671 else if (SYMBOL_VALUE (mfunsym
) == SYMBOL_VALUE (msymbol
))
1672 /* Avoid infinite recursion */
1673 /* See above comment about why warning is commented out */
1674 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_NAME(msymbol)) */ ;
1677 return find_pc_line (SYMBOL_VALUE (mfunsym
), 0);
1681 s
= find_pc_sect_symtab (pc
, section
);
1684 /* if no symbol information, return previous pc */
1691 bv
= BLOCKVECTOR (s
);
1693 /* Look at all the symtabs that share this blockvector.
1694 They all have the same apriori range, that we found was right;
1695 but they have different line tables. */
1697 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1699 /* Find the best line in this symtab. */
1706 /* I think len can be zero if the symtab lacks line numbers
1707 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
1708 I'm not sure which, and maybe it depends on the symbol
1714 item
= l
->item
; /* Get first line info */
1716 /* Is this file's first line closer than the first lines of other files?
1717 If so, record this file, and its first line, as best alternate. */
1718 if (item
->pc
> pc
&& (!alt
|| item
->pc
< alt
->pc
))
1724 for (i
= 0; i
< len
; i
++, item
++)
1726 /* Leave prev pointing to the linetable entry for the last line
1727 that started at or before PC. */
1734 /* At this point, prev points at the line whose start addr is <= pc, and
1735 item points at the next line. If we ran off the end of the linetable
1736 (pc >= start of the last line), then prev == item. If pc < start of
1737 the first line, prev will not be set. */
1739 /* Is this file's best line closer than the best in the other files?
1740 If so, record this file, and its best line, as best so far. */
1742 if (prev
&& (!best
|| prev
->pc
> best
->pc
))
1747 /* Discard BEST_END if it's before the PC of the current BEST. */
1748 if (best_end
<= best
->pc
)
1752 /* If another line (denoted by ITEM) is in the linetable and its
1753 PC is after BEST's PC, but before the current BEST_END, then
1754 use ITEM's PC as the new best_end. */
1755 if (best
&& i
< len
&& item
->pc
> best
->pc
1756 && (best_end
== 0 || best_end
> item
->pc
))
1757 best_end
= item
->pc
;
1763 { /* If we didn't find any line # info, just
1769 val
.symtab
= alt_symtab
;
1770 val
.line
= alt
->line
- 1;
1772 /* Don't return line 0, that means that we didn't find the line. */
1776 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1782 val
.symtab
= best_symtab
;
1783 val
.line
= best
->line
;
1785 if (best_end
&& (!alt
|| best_end
< alt
->pc
))
1790 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1792 val
.section
= section
;
1796 /* Backward compatibility (no section) */
1798 struct symtab_and_line
1799 find_pc_line (CORE_ADDR pc
, int notcurrent
)
1803 section
= find_pc_overlay (pc
);
1804 if (pc_in_unmapped_range (pc
, section
))
1805 pc
= overlay_mapped_address (pc
, section
);
1806 return find_pc_sect_line (pc
, section
, notcurrent
);
1809 /* Find line number LINE in any symtab whose name is the same as
1812 If found, return the symtab that contains the linetable in which it was
1813 found, set *INDEX to the index in the linetable of the best entry
1814 found, and set *EXACT_MATCH nonzero if the value returned is an
1817 If not found, return NULL. */
1820 find_line_symtab (struct symtab
*symtab
, int line
, int *index
, int *exact_match
)
1824 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
1828 struct linetable
*best_linetable
;
1829 struct symtab
*best_symtab
;
1831 /* First try looking it up in the given symtab. */
1832 best_linetable
= LINETABLE (symtab
);
1833 best_symtab
= symtab
;
1834 best_index
= find_line_common (best_linetable
, line
, &exact
);
1835 if (best_index
< 0 || !exact
)
1837 /* Didn't find an exact match. So we better keep looking for
1838 another symtab with the same name. In the case of xcoff,
1839 multiple csects for one source file (produced by IBM's FORTRAN
1840 compiler) produce multiple symtabs (this is unavoidable
1841 assuming csects can be at arbitrary places in memory and that
1842 the GLOBAL_BLOCK of a symtab has a begin and end address). */
1844 /* BEST is the smallest linenumber > LINE so far seen,
1845 or 0 if none has been seen so far.
1846 BEST_INDEX and BEST_LINETABLE identify the item for it. */
1849 struct objfile
*objfile
;
1852 if (best_index
>= 0)
1853 best
= best_linetable
->item
[best_index
].line
;
1857 ALL_SYMTABS (objfile
, s
)
1859 struct linetable
*l
;
1862 if (!STREQ (symtab
->filename
, s
->filename
))
1865 ind
= find_line_common (l
, line
, &exact
);
1875 if (best
== 0 || l
->item
[ind
].line
< best
)
1877 best
= l
->item
[ind
].line
;
1890 *index
= best_index
;
1892 *exact_match
= exact
;
1897 /* Set the PC value for a given source file and line number and return true.
1898 Returns zero for invalid line number (and sets the PC to 0).
1899 The source file is specified with a struct symtab. */
1902 find_line_pc (struct symtab
*symtab
, int line
, CORE_ADDR
*pc
)
1904 struct linetable
*l
;
1911 symtab
= find_line_symtab (symtab
, line
, &ind
, NULL
);
1914 l
= LINETABLE (symtab
);
1915 *pc
= l
->item
[ind
].pc
;
1922 /* Find the range of pc values in a line.
1923 Store the starting pc of the line into *STARTPTR
1924 and the ending pc (start of next line) into *ENDPTR.
1925 Returns 1 to indicate success.
1926 Returns 0 if could not find the specified line. */
1929 find_line_pc_range (struct symtab_and_line sal
, CORE_ADDR
*startptr
,
1932 CORE_ADDR startaddr
;
1933 struct symtab_and_line found_sal
;
1936 if (startaddr
== 0 && !find_line_pc (sal
.symtab
, sal
.line
, &startaddr
))
1939 /* This whole function is based on address. For example, if line 10 has
1940 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
1941 "info line *0x123" should say the line goes from 0x100 to 0x200
1942 and "info line *0x355" should say the line goes from 0x300 to 0x400.
1943 This also insures that we never give a range like "starts at 0x134
1944 and ends at 0x12c". */
1946 found_sal
= find_pc_sect_line (startaddr
, sal
.section
, 0);
1947 if (found_sal
.line
!= sal
.line
)
1949 /* The specified line (sal) has zero bytes. */
1950 *startptr
= found_sal
.pc
;
1951 *endptr
= found_sal
.pc
;
1955 *startptr
= found_sal
.pc
;
1956 *endptr
= found_sal
.end
;
1961 /* Given a line table and a line number, return the index into the line
1962 table for the pc of the nearest line whose number is >= the specified one.
1963 Return -1 if none is found. The value is >= 0 if it is an index.
1965 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
1968 find_line_common (register struct linetable
*l
, register int lineno
,
1974 /* BEST is the smallest linenumber > LINENO so far seen,
1975 or 0 if none has been seen so far.
1976 BEST_INDEX identifies the item for it. */
1978 int best_index
= -1;
1987 for (i
= 0; i
< len
; i
++)
1989 register struct linetable_entry
*item
= &(l
->item
[i
]);
1991 if (item
->line
== lineno
)
1993 /* Return the first (lowest address) entry which matches. */
1998 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
2005 /* If we got here, we didn't get an exact match. */
2012 find_pc_line_pc_range (CORE_ADDR pc
, CORE_ADDR
*startptr
, CORE_ADDR
*endptr
)
2014 struct symtab_and_line sal
;
2015 sal
= find_pc_line (pc
, 0);
2018 return sal
.symtab
!= 0;
2021 /* Given a function symbol SYM, find the symtab and line for the start
2023 If the argument FUNFIRSTLINE is nonzero, we want the first line
2024 of real code inside the function. */
2026 struct symtab_and_line
2027 find_function_start_sal (struct symbol
*sym
, int funfirstline
)
2030 struct symtab_and_line sal
;
2032 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
2033 fixup_symbol_section (sym
, NULL
);
2035 { /* skip "first line" of function (which is actually its prologue) */
2036 asection
*section
= SYMBOL_BFD_SECTION (sym
);
2037 /* If function is in an unmapped overlay, use its unmapped LMA
2038 address, so that SKIP_PROLOGUE has something unique to work on */
2039 if (section_is_overlay (section
) &&
2040 !section_is_mapped (section
))
2041 pc
= overlay_unmapped_address (pc
, section
);
2043 pc
+= FUNCTION_START_OFFSET
;
2044 pc
= SKIP_PROLOGUE (pc
);
2046 /* For overlays, map pc back into its mapped VMA range */
2047 pc
= overlay_mapped_address (pc
, section
);
2049 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
2051 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2052 /* Convex: no need to suppress code on first line, if any */
2055 /* Check if SKIP_PROLOGUE left us in mid-line, and the next
2056 line is still part of the same function. */
2058 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) <= sal
.end
2059 && sal
.end
< BLOCK_END (SYMBOL_BLOCK_VALUE (sym
)))
2061 /* First pc of next line */
2063 /* Recalculate the line number (might not be N+1). */
2064 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
2072 /* If P is of the form "operator[ \t]+..." where `...' is
2073 some legitimate operator text, return a pointer to the
2074 beginning of the substring of the operator text.
2075 Otherwise, return "". */
2077 operator_chars (char *p
, char **end
)
2080 if (strncmp (p
, "operator", 8))
2084 /* Don't get faked out by `operator' being part of a longer
2086 if (isalpha (*p
) || *p
== '_' || *p
== '$' || *p
== '\0')
2089 /* Allow some whitespace between `operator' and the operator symbol. */
2090 while (*p
== ' ' || *p
== '\t')
2093 /* Recognize 'operator TYPENAME'. */
2095 if (isalpha (*p
) || *p
== '_' || *p
== '$')
2097 register char *q
= p
+ 1;
2098 while (isalnum (*q
) || *q
== '_' || *q
== '$')
2123 if (p
[1] == '=' || p
[1] == p
[0])
2134 error ("`operator ()' must be specified without whitespace in `()'");
2139 error ("`operator ?:' must be specified without whitespace in `?:'");
2144 error ("`operator []' must be specified without whitespace in `[]'");
2148 error ("`operator %s' not supported", p
);
2156 /* If FILE is not already in the table of files, return zero;
2157 otherwise return non-zero. Optionally add FILE to the table if ADD
2158 is non-zero. If *FIRST is non-zero, forget the old table
2161 filename_seen (const char *file
, int add
, int *first
)
2163 /* Table of files seen so far. */
2164 static const char **tab
= NULL
;
2165 /* Allocated size of tab in elements.
2166 Start with one 256-byte block (when using GNU malloc.c).
2167 24 is the malloc overhead when range checking is in effect. */
2168 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
2169 /* Current size of tab in elements. */
2170 static int tab_cur_size
;
2176 tab
= (const char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
2180 /* Is FILE in tab? */
2181 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
2182 if (strcmp (*p
, file
) == 0)
2185 /* No; maybe add it to tab. */
2188 if (tab_cur_size
== tab_alloc_size
)
2190 tab_alloc_size
*= 2;
2191 tab
= (const char **) xrealloc ((char *) tab
,
2192 tab_alloc_size
* sizeof (*tab
));
2194 tab
[tab_cur_size
++] = file
;
2200 /* Slave routine for sources_info. Force line breaks at ,'s.
2201 NAME is the name to print and *FIRST is nonzero if this is the first
2202 name printed. Set *FIRST to zero. */
2204 output_source_filename (char *name
, int *first
)
2206 /* Since a single source file can result in several partial symbol
2207 tables, we need to avoid printing it more than once. Note: if
2208 some of the psymtabs are read in and some are not, it gets
2209 printed both under "Source files for which symbols have been
2210 read" and "Source files for which symbols will be read in on
2211 demand". I consider this a reasonable way to deal with the
2212 situation. I'm not sure whether this can also happen for
2213 symtabs; it doesn't hurt to check. */
2215 /* Was NAME already seen? */
2216 if (filename_seen (name
, 1, first
))
2218 /* Yes; don't print it again. */
2221 /* No; print it and reset *FIRST. */
2228 printf_filtered (", ");
2232 fputs_filtered (name
, gdb_stdout
);
2236 sources_info (char *ignore
, int from_tty
)
2238 register struct symtab
*s
;
2239 register struct partial_symtab
*ps
;
2240 register struct objfile
*objfile
;
2243 if (!have_full_symbols () && !have_partial_symbols ())
2245 error ("No symbol table is loaded. Use the \"file\" command.");
2248 printf_filtered ("Source files for which symbols have been read in:\n\n");
2251 ALL_SYMTABS (objfile
, s
)
2253 output_source_filename (s
->filename
, &first
);
2255 printf_filtered ("\n\n");
2257 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2260 ALL_PSYMTABS (objfile
, ps
)
2264 output_source_filename (ps
->filename
, &first
);
2267 printf_filtered ("\n");
2271 file_matches (char *file
, char *files
[], int nfiles
)
2275 if (file
!= NULL
&& nfiles
!= 0)
2277 for (i
= 0; i
< nfiles
; i
++)
2279 if (strcmp (files
[i
], lbasename (file
)) == 0)
2283 else if (nfiles
== 0)
2288 /* Free any memory associated with a search. */
2290 free_search_symbols (struct symbol_search
*symbols
)
2292 struct symbol_search
*p
;
2293 struct symbol_search
*next
;
2295 for (p
= symbols
; p
!= NULL
; p
= next
)
2303 do_free_search_symbols_cleanup (void *symbols
)
2305 free_search_symbols (symbols
);
2309 make_cleanup_free_search_symbols (struct symbol_search
*symbols
)
2311 return make_cleanup (do_free_search_symbols_cleanup
, symbols
);
2315 /* Search the symbol table for matches to the regular expression REGEXP,
2316 returning the results in *MATCHES.
2318 Only symbols of KIND are searched:
2319 FUNCTIONS_NAMESPACE - search all functions
2320 TYPES_NAMESPACE - search all type names
2321 METHODS_NAMESPACE - search all methods NOT IMPLEMENTED
2322 VARIABLES_NAMESPACE - search all symbols, excluding functions, type names,
2323 and constants (enums)
2325 free_search_symbols should be called when *MATCHES is no longer needed.
2328 search_symbols (char *regexp
, namespace_enum kind
, int nfiles
, char *files
[],
2329 struct symbol_search
**matches
)
2331 register struct symtab
*s
;
2332 register struct partial_symtab
*ps
;
2333 register struct blockvector
*bv
;
2334 struct blockvector
*prev_bv
= 0;
2335 register struct block
*b
;
2338 register struct symbol
*sym
;
2339 struct partial_symbol
**psym
;
2340 struct objfile
*objfile
;
2341 struct minimal_symbol
*msymbol
;
2344 static enum minimal_symbol_type types
[]
2346 {mst_data
, mst_text
, mst_abs
, mst_unknown
};
2347 static enum minimal_symbol_type types2
[]
2349 {mst_bss
, mst_file_text
, mst_abs
, mst_unknown
};
2350 static enum minimal_symbol_type types3
[]
2352 {mst_file_data
, mst_solib_trampoline
, mst_abs
, mst_unknown
};
2353 static enum minimal_symbol_type types4
[]
2355 {mst_file_bss
, mst_text
, mst_abs
, mst_unknown
};
2356 enum minimal_symbol_type ourtype
;
2357 enum minimal_symbol_type ourtype2
;
2358 enum minimal_symbol_type ourtype3
;
2359 enum minimal_symbol_type ourtype4
;
2360 struct symbol_search
*sr
;
2361 struct symbol_search
*psr
;
2362 struct symbol_search
*tail
;
2363 struct cleanup
*old_chain
= NULL
;
2365 if (kind
< VARIABLES_NAMESPACE
)
2366 error ("must search on specific namespace");
2368 ourtype
= types
[(int) (kind
- VARIABLES_NAMESPACE
)];
2369 ourtype2
= types2
[(int) (kind
- VARIABLES_NAMESPACE
)];
2370 ourtype3
= types3
[(int) (kind
- VARIABLES_NAMESPACE
)];
2371 ourtype4
= types4
[(int) (kind
- VARIABLES_NAMESPACE
)];
2373 sr
= *matches
= NULL
;
2378 /* Make sure spacing is right for C++ operators.
2379 This is just a courtesy to make the matching less sensitive
2380 to how many spaces the user leaves between 'operator'
2381 and <TYPENAME> or <OPERATOR>. */
2383 char *opname
= operator_chars (regexp
, &opend
);
2386 int fix
= -1; /* -1 means ok; otherwise number of spaces needed. */
2387 if (isalpha (*opname
) || *opname
== '_' || *opname
== '$')
2389 /* There should 1 space between 'operator' and 'TYPENAME'. */
2390 if (opname
[-1] != ' ' || opname
[-2] == ' ')
2395 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2396 if (opname
[-1] == ' ')
2399 /* If wrong number of spaces, fix it. */
2402 char *tmp
= (char *) alloca (opend
- opname
+ 10);
2403 sprintf (tmp
, "operator%.*s%s", fix
, " ", opname
);
2408 if (0 != (val
= re_comp (regexp
)))
2409 error ("Invalid regexp (%s): %s", val
, regexp
);
2412 /* Search through the partial symtabs *first* for all symbols
2413 matching the regexp. That way we don't have to reproduce all of
2414 the machinery below. */
2416 ALL_PSYMTABS (objfile
, ps
)
2418 struct partial_symbol
**bound
, **gbound
, **sbound
;
2424 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2425 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2428 /* Go through all of the symbols stored in a partial
2429 symtab in one loop. */
2430 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2435 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2437 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2448 /* If it would match (logic taken from loop below)
2449 load the file and go on to the next one */
2450 if (file_matches (ps
->filename
, files
, nfiles
)
2451 && ((regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (*psym
))
2452 && ((kind
== VARIABLES_NAMESPACE
&& SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
2453 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
2454 || (kind
== FUNCTIONS_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
2455 || (kind
== TYPES_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
)
2456 || (kind
== METHODS_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
))))
2458 PSYMTAB_TO_SYMTAB (ps
);
2466 /* Here, we search through the minimal symbol tables for functions
2467 and variables that match, and force their symbols to be read.
2468 This is in particular necessary for demangled variable names,
2469 which are no longer put into the partial symbol tables.
2470 The symbol will then be found during the scan of symtabs below.
2472 For functions, find_pc_symtab should succeed if we have debug info
2473 for the function, for variables we have to call lookup_symbol
2474 to determine if the variable has debug info.
2475 If the lookup fails, set found_misc so that we will rescan to print
2476 any matching symbols without debug info.
2479 if (nfiles
== 0 && (kind
== VARIABLES_NAMESPACE
|| kind
== FUNCTIONS_NAMESPACE
))
2481 ALL_MSYMBOLS (objfile
, msymbol
)
2483 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
2484 MSYMBOL_TYPE (msymbol
) == ourtype2
||
2485 MSYMBOL_TYPE (msymbol
) == ourtype3
||
2486 MSYMBOL_TYPE (msymbol
) == ourtype4
)
2488 if (regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (msymbol
))
2490 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
)))
2492 if (kind
== FUNCTIONS_NAMESPACE
2493 || lookup_symbol (SYMBOL_NAME (msymbol
),
2494 (struct block
*) NULL
,
2496 0, (struct symtab
**) NULL
) == NULL
)
2504 ALL_SYMTABS (objfile
, s
)
2506 bv
= BLOCKVECTOR (s
);
2507 /* Often many files share a blockvector.
2508 Scan each blockvector only once so that
2509 we don't get every symbol many times.
2510 It happens that the first symtab in the list
2511 for any given blockvector is the main file. */
2513 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
2515 b
= BLOCKVECTOR_BLOCK (bv
, i
);
2516 /* Skip the sort if this block is always sorted. */
2517 if (!BLOCK_SHOULD_SORT (b
))
2518 sort_block_syms (b
);
2519 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
2522 sym
= BLOCK_SYM (b
, j
);
2523 if (file_matches (s
->filename
, files
, nfiles
)
2524 && ((regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (sym
))
2525 && ((kind
== VARIABLES_NAMESPACE
&& SYMBOL_CLASS (sym
) != LOC_TYPEDEF
2526 && SYMBOL_CLASS (sym
) != LOC_BLOCK
2527 && SYMBOL_CLASS (sym
) != LOC_CONST
)
2528 || (kind
== FUNCTIONS_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2529 || (kind
== TYPES_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2530 || (kind
== METHODS_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
))))
2533 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
2537 psr
->msymbol
= NULL
;
2542 old_chain
= make_cleanup_free_search_symbols (sr
);
2553 /* If there are no eyes, avoid all contact. I mean, if there are
2554 no debug symbols, then print directly from the msymbol_vector. */
2556 if (found_misc
|| kind
!= FUNCTIONS_NAMESPACE
)
2558 ALL_MSYMBOLS (objfile
, msymbol
)
2560 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
2561 MSYMBOL_TYPE (msymbol
) == ourtype2
||
2562 MSYMBOL_TYPE (msymbol
) == ourtype3
||
2563 MSYMBOL_TYPE (msymbol
) == ourtype4
)
2565 if (regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (msymbol
))
2567 /* Functions: Look up by address. */
2568 if (kind
!= FUNCTIONS_NAMESPACE
||
2569 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
))))
2571 /* Variables/Absolutes: Look up by name */
2572 if (lookup_symbol (SYMBOL_NAME (msymbol
),
2573 (struct block
*) NULL
, VAR_NAMESPACE
,
2574 0, (struct symtab
**) NULL
) == NULL
)
2577 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
2579 psr
->msymbol
= msymbol
;
2586 old_chain
= make_cleanup_free_search_symbols (sr
);
2600 discard_cleanups (old_chain
);
2603 /* Helper function for symtab_symbol_info, this function uses
2604 the data returned from search_symbols() to print information
2605 regarding the match to gdb_stdout.
2608 print_symbol_info (namespace_enum kind
, struct symtab
*s
, struct symbol
*sym
,
2609 int block
, char *last
)
2611 if (last
== NULL
|| strcmp (last
, s
->filename
) != 0)
2613 fputs_filtered ("\nFile ", gdb_stdout
);
2614 fputs_filtered (s
->filename
, gdb_stdout
);
2615 fputs_filtered (":\n", gdb_stdout
);
2618 if (kind
!= TYPES_NAMESPACE
&& block
== STATIC_BLOCK
)
2619 printf_filtered ("static ");
2621 /* Typedef that is not a C++ class */
2622 if (kind
== TYPES_NAMESPACE
2623 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
2624 typedef_print (SYMBOL_TYPE (sym
), sym
, gdb_stdout
);
2625 /* variable, func, or typedef-that-is-c++-class */
2626 else if (kind
< TYPES_NAMESPACE
||
2627 (kind
== TYPES_NAMESPACE
&&
2628 SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
))
2630 type_print (SYMBOL_TYPE (sym
),
2631 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2632 ? "" : SYMBOL_SOURCE_NAME (sym
)),
2635 printf_filtered (";\n");
2640 /* Tiemann says: "info methods was never implemented." */
2641 char *demangled_name
;
2642 c_type_print_base (TYPE_FN_FIELD_TYPE (t
, block
),
2644 c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (t
, block
),
2646 if (TYPE_FN_FIELD_STUB (t
, block
))
2647 check_stub_method (TYPE_DOMAIN_TYPE (type
), j
, block
);
2649 cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t
, block
),
2650 DMGL_ANSI
| DMGL_PARAMS
);
2651 if (demangled_name
== NULL
)
2652 fprintf_filtered (stream
, "<badly mangled name %s>",
2653 TYPE_FN_FIELD_PHYSNAME (t
, block
));
2656 fputs_filtered (demangled_name
, stream
);
2657 xfree (demangled_name
);
2663 /* This help function for symtab_symbol_info() prints information
2664 for non-debugging symbols to gdb_stdout.
2667 print_msymbol_info (struct minimal_symbol
*msymbol
)
2671 if (TARGET_ADDR_BIT
<= 32)
2672 tmp
= longest_local_hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol
)
2673 & (CORE_ADDR
) 0xffffffff,
2676 tmp
= longest_local_hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol
),
2678 printf_filtered ("%s %s\n",
2679 tmp
, SYMBOL_SOURCE_NAME (msymbol
));
2682 /* This is the guts of the commands "info functions", "info types", and
2683 "info variables". It calls search_symbols to find all matches and then
2684 print_[m]symbol_info to print out some useful information about the
2688 symtab_symbol_info (char *regexp
, namespace_enum kind
, int from_tty
)
2690 static char *classnames
[]
2692 {"variable", "function", "type", "method"};
2693 struct symbol_search
*symbols
;
2694 struct symbol_search
*p
;
2695 struct cleanup
*old_chain
;
2696 char *last_filename
= NULL
;
2699 /* must make sure that if we're interrupted, symbols gets freed */
2700 search_symbols (regexp
, kind
, 0, (char **) NULL
, &symbols
);
2701 old_chain
= make_cleanup_free_search_symbols (symbols
);
2703 printf_filtered (regexp
2704 ? "All %ss matching regular expression \"%s\":\n"
2705 : "All defined %ss:\n",
2706 classnames
[(int) (kind
- VARIABLES_NAMESPACE
)], regexp
);
2708 for (p
= symbols
; p
!= NULL
; p
= p
->next
)
2712 if (p
->msymbol
!= NULL
)
2716 printf_filtered ("\nNon-debugging symbols:\n");
2719 print_msymbol_info (p
->msymbol
);
2723 print_symbol_info (kind
,
2728 last_filename
= p
->symtab
->filename
;
2732 do_cleanups (old_chain
);
2736 variables_info (char *regexp
, int from_tty
)
2738 symtab_symbol_info (regexp
, VARIABLES_NAMESPACE
, from_tty
);
2742 functions_info (char *regexp
, int from_tty
)
2744 symtab_symbol_info (regexp
, FUNCTIONS_NAMESPACE
, from_tty
);
2749 types_info (char *regexp
, int from_tty
)
2751 symtab_symbol_info (regexp
, TYPES_NAMESPACE
, from_tty
);
2755 /* Tiemann says: "info methods was never implemented." */
2757 methods_info (char *regexp
)
2759 symtab_symbol_info (regexp
, METHODS_NAMESPACE
, 0, from_tty
);
2763 /* Breakpoint all functions matching regular expression. */
2766 rbreak_command_wrapper (char *regexp
, int from_tty
)
2768 rbreak_command (regexp
, from_tty
);
2772 rbreak_command (char *regexp
, int from_tty
)
2774 struct symbol_search
*ss
;
2775 struct symbol_search
*p
;
2776 struct cleanup
*old_chain
;
2778 search_symbols (regexp
, FUNCTIONS_NAMESPACE
, 0, (char **) NULL
, &ss
);
2779 old_chain
= make_cleanup_free_search_symbols (ss
);
2781 for (p
= ss
; p
!= NULL
; p
= p
->next
)
2783 if (p
->msymbol
== NULL
)
2785 char *string
= (char *) alloca (strlen (p
->symtab
->filename
)
2786 + strlen (SYMBOL_NAME (p
->symbol
))
2788 strcpy (string
, p
->symtab
->filename
);
2789 strcat (string
, ":'");
2790 strcat (string
, SYMBOL_NAME (p
->symbol
));
2791 strcat (string
, "'");
2792 break_command (string
, from_tty
);
2793 print_symbol_info (FUNCTIONS_NAMESPACE
,
2797 p
->symtab
->filename
);
2801 break_command (SYMBOL_NAME (p
->msymbol
), from_tty
);
2802 printf_filtered ("<function, no debug info> %s;\n",
2803 SYMBOL_SOURCE_NAME (p
->msymbol
));
2807 do_cleanups (old_chain
);
2811 /* Return Nonzero if block a is lexically nested within block b,
2812 or if a and b have the same pc range.
2813 Return zero otherwise. */
2815 contained_in (struct block
*a
, struct block
*b
)
2819 return BLOCK_START (a
) >= BLOCK_START (b
)
2820 && BLOCK_END (a
) <= BLOCK_END (b
);
2824 /* Helper routine for make_symbol_completion_list. */
2826 static int return_val_size
;
2827 static int return_val_index
;
2828 static char **return_val
;
2830 #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
2832 if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \
2833 /* Put only the mangled name on the list. */ \
2834 /* Advantage: "b foo<TAB>" completes to "b foo(int, int)" */ \
2835 /* Disadvantage: "b foo__i<TAB>" doesn't complete. */ \
2836 completion_list_add_name \
2837 (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \
2839 completion_list_add_name \
2840 (SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \
2843 /* Test to see if the symbol specified by SYMNAME (which is already
2844 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
2845 characters. If so, add it to the current completion list. */
2848 completion_list_add_name (char *symname
, char *sym_text
, int sym_text_len
,
2849 char *text
, char *word
)
2854 /* clip symbols that cannot match */
2856 if (strncmp (symname
, sym_text
, sym_text_len
) != 0)
2861 /* We have a match for a completion, so add SYMNAME to the current list
2862 of matches. Note that the name is moved to freshly malloc'd space. */
2866 if (word
== sym_text
)
2868 new = xmalloc (strlen (symname
) + 5);
2869 strcpy (new, symname
);
2871 else if (word
> sym_text
)
2873 /* Return some portion of symname. */
2874 new = xmalloc (strlen (symname
) + 5);
2875 strcpy (new, symname
+ (word
- sym_text
));
2879 /* Return some of SYM_TEXT plus symname. */
2880 new = xmalloc (strlen (symname
) + (sym_text
- word
) + 5);
2881 strncpy (new, word
, sym_text
- word
);
2882 new[sym_text
- word
] = '\0';
2883 strcat (new, symname
);
2886 if (return_val_index
+ 3 > return_val_size
)
2888 newsize
= (return_val_size
*= 2) * sizeof (char *);
2889 return_val
= (char **) xrealloc ((char *) return_val
, newsize
);
2891 return_val
[return_val_index
++] = new;
2892 return_val
[return_val_index
] = NULL
;
2896 /* Return a NULL terminated array of all symbols (regardless of class)
2897 which begin by matching TEXT. If the answer is no symbols, then
2898 the return value is an array which contains only a NULL pointer.
2900 Problem: All of the symbols have to be copied because readline frees them.
2901 I'm not going to worry about this; hopefully there won't be that many. */
2904 make_symbol_completion_list (char *text
, char *word
)
2906 register struct symbol
*sym
;
2907 register struct symtab
*s
;
2908 register struct partial_symtab
*ps
;
2909 register struct minimal_symbol
*msymbol
;
2910 register struct objfile
*objfile
;
2911 register struct block
*b
, *surrounding_static_block
= 0;
2913 struct partial_symbol
**psym
;
2914 /* The symbol we are completing on. Points in same buffer as text. */
2916 /* Length of sym_text. */
2919 /* Now look for the symbol we are supposed to complete on.
2920 FIXME: This should be language-specific. */
2924 char *quote_pos
= NULL
;
2926 /* First see if this is a quoted string. */
2928 for (p
= text
; *p
!= '\0'; ++p
)
2930 if (quote_found
!= '\0')
2932 if (*p
== quote_found
)
2933 /* Found close quote. */
2935 else if (*p
== '\\' && p
[1] == quote_found
)
2936 /* A backslash followed by the quote character
2937 doesn't end the string. */
2940 else if (*p
== '\'' || *p
== '"')
2946 if (quote_found
== '\'')
2947 /* A string within single quotes can be a symbol, so complete on it. */
2948 sym_text
= quote_pos
+ 1;
2949 else if (quote_found
== '"')
2950 /* A double-quoted string is never a symbol, nor does it make sense
2951 to complete it any other way. */
2953 return_val
= (char **) xmalloc (sizeof (char *));
2954 return_val
[0] = NULL
;
2959 /* It is not a quoted string. Break it based on the characters
2960 which are in symbols. */
2963 if (isalnum (p
[-1]) || p
[-1] == '_' || p
[-1] == '\0')
2972 sym_text_len
= strlen (sym_text
);
2974 return_val_size
= 100;
2975 return_val_index
= 0;
2976 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
2977 return_val
[0] = NULL
;
2979 /* Look through the partial symtabs for all symbols which begin
2980 by matching SYM_TEXT. Add each one that you find to the list. */
2982 ALL_PSYMTABS (objfile
, ps
)
2984 /* If the psymtab's been read in we'll get it when we search
2985 through the blockvector. */
2989 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2990 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
2991 + ps
->n_global_syms
);
2994 /* If interrupted, then quit. */
2996 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
2999 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
3000 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
3001 + ps
->n_static_syms
);
3005 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3009 /* At this point scan through the misc symbol vectors and add each
3010 symbol you find to the list. Eventually we want to ignore
3011 anything that isn't a text symbol (everything else will be
3012 handled by the psymtab code above). */
3014 ALL_MSYMBOLS (objfile
, msymbol
)
3017 COMPLETION_LIST_ADD_SYMBOL (msymbol
, sym_text
, sym_text_len
, text
, word
);
3020 /* Search upwards from currently selected frame (so that we can
3021 complete on local vars. */
3023 for (b
= get_selected_block (); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
3025 if (!BLOCK_SUPERBLOCK (b
))
3027 surrounding_static_block
= b
; /* For elmin of dups */
3030 /* Also catch fields of types defined in this places which match our
3031 text string. Only complete on types visible from current context. */
3033 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3035 sym
= BLOCK_SYM (b
, i
);
3036 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3037 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3039 struct type
*t
= SYMBOL_TYPE (sym
);
3040 enum type_code c
= TYPE_CODE (t
);
3042 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
3044 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
3046 if (TYPE_FIELD_NAME (t
, j
))
3048 completion_list_add_name (TYPE_FIELD_NAME (t
, j
),
3049 sym_text
, sym_text_len
, text
, word
);
3057 /* Go through the symtabs and check the externs and statics for
3058 symbols which match. */
3060 ALL_SYMTABS (objfile
, s
)
3063 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3064 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3066 sym
= BLOCK_SYM (b
, i
);
3067 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3071 ALL_SYMTABS (objfile
, s
)
3074 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3075 /* Don't do this block twice. */
3076 if (b
== surrounding_static_block
)
3078 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3080 sym
= BLOCK_SYM (b
, i
);
3081 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3085 return (return_val
);
3088 /* Like make_symbol_completion_list, but returns a list of symbols
3089 defined in a source file FILE. */
3092 make_file_symbol_completion_list (char *text
, char *word
, char *srcfile
)
3094 register struct symbol
*sym
;
3095 register struct symtab
*s
;
3096 register struct block
*b
;
3098 /* The symbol we are completing on. Points in same buffer as text. */
3100 /* Length of sym_text. */
3103 /* Now look for the symbol we are supposed to complete on.
3104 FIXME: This should be language-specific. */
3108 char *quote_pos
= NULL
;
3110 /* First see if this is a quoted string. */
3112 for (p
= text
; *p
!= '\0'; ++p
)
3114 if (quote_found
!= '\0')
3116 if (*p
== quote_found
)
3117 /* Found close quote. */
3119 else if (*p
== '\\' && p
[1] == quote_found
)
3120 /* A backslash followed by the quote character
3121 doesn't end the string. */
3124 else if (*p
== '\'' || *p
== '"')
3130 if (quote_found
== '\'')
3131 /* A string within single quotes can be a symbol, so complete on it. */
3132 sym_text
= quote_pos
+ 1;
3133 else if (quote_found
== '"')
3134 /* A double-quoted string is never a symbol, nor does it make sense
3135 to complete it any other way. */
3137 return_val
= (char **) xmalloc (sizeof (char *));
3138 return_val
[0] = NULL
;
3143 /* It is not a quoted string. Break it based on the characters
3144 which are in symbols. */
3147 if (isalnum (p
[-1]) || p
[-1] == '_' || p
[-1] == '\0')
3156 sym_text_len
= strlen (sym_text
);
3158 return_val_size
= 10;
3159 return_val_index
= 0;
3160 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
3161 return_val
[0] = NULL
;
3163 /* Find the symtab for SRCFILE (this loads it if it was not yet read
3165 s
= lookup_symtab (srcfile
);
3168 /* Maybe they typed the file with leading directories, while the
3169 symbol tables record only its basename. */
3170 const char *tail
= lbasename (srcfile
);
3173 s
= lookup_symtab (tail
);
3176 /* If we have no symtab for that file, return an empty list. */
3178 return (return_val
);
3180 /* Go through this symtab and check the externs and statics for
3181 symbols which match. */
3183 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3184 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3186 sym
= BLOCK_SYM (b
, i
);
3187 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3190 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3191 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3193 sym
= BLOCK_SYM (b
, i
);
3194 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3197 return (return_val
);
3200 /* A helper function for make_source_files_completion_list. It adds
3201 another file name to a list of possible completions, growing the
3202 list as necessary. */
3205 add_filename_to_list (const char *fname
, char *text
, char *word
,
3206 char ***list
, int *list_used
, int *list_alloced
)
3209 size_t fnlen
= strlen (fname
);
3211 if (*list_used
+ 1 >= *list_alloced
)
3214 *list
= (char **) xrealloc ((char *) *list
,
3215 *list_alloced
* sizeof (char *));
3220 /* Return exactly fname. */
3221 new = xmalloc (fnlen
+ 5);
3222 strcpy (new, fname
);
3224 else if (word
> text
)
3226 /* Return some portion of fname. */
3227 new = xmalloc (fnlen
+ 5);
3228 strcpy (new, fname
+ (word
- text
));
3232 /* Return some of TEXT plus fname. */
3233 new = xmalloc (fnlen
+ (text
- word
) + 5);
3234 strncpy (new, word
, text
- word
);
3235 new[text
- word
] = '\0';
3236 strcat (new, fname
);
3238 (*list
)[*list_used
] = new;
3239 (*list
)[++*list_used
] = NULL
;
3243 not_interesting_fname (const char *fname
)
3245 static const char *illegal_aliens
[] = {
3246 "_globals_", /* inserted by coff_symtab_read */
3251 for (i
= 0; illegal_aliens
[i
]; i
++)
3253 if (strcmp (fname
, illegal_aliens
[i
]) == 0)
3259 /* Return a NULL terminated array of all source files whose names
3260 begin with matching TEXT. The file names are looked up in the
3261 symbol tables of this program. If the answer is no matchess, then
3262 the return value is an array which contains only a NULL pointer. */
3265 make_source_files_completion_list (char *text
, char *word
)
3267 register struct symtab
*s
;
3268 register struct partial_symtab
*ps
;
3269 register struct objfile
*objfile
;
3271 int list_alloced
= 1;
3273 size_t text_len
= strlen (text
);
3274 char **list
= (char **) xmalloc (list_alloced
* sizeof (char *));
3275 const char *base_name
;
3279 if (!have_full_symbols () && !have_partial_symbols ())
3282 ALL_SYMTABS (objfile
, s
)
3284 if (not_interesting_fname (s
->filename
))
3286 if (!filename_seen (s
->filename
, 1, &first
)
3287 #if HAVE_DOS_BASED_FILE_SYSTEM
3288 && strncasecmp (s
->filename
, text
, text_len
) == 0
3290 && strncmp (s
->filename
, text
, text_len
) == 0
3294 /* This file matches for a completion; add it to the current
3296 add_filename_to_list (s
->filename
, text
, word
,
3297 &list
, &list_used
, &list_alloced
);
3301 /* NOTE: We allow the user to type a base name when the
3302 debug info records leading directories, but not the other
3303 way around. This is what subroutines of breakpoint
3304 command do when they parse file names. */
3305 base_name
= lbasename (s
->filename
);
3306 if (base_name
!= s
->filename
3307 && !filename_seen (base_name
, 1, &first
)
3308 #if HAVE_DOS_BASED_FILE_SYSTEM
3309 && strncasecmp (base_name
, text
, text_len
) == 0
3311 && strncmp (base_name
, text
, text_len
) == 0
3314 add_filename_to_list (base_name
, text
, word
,
3315 &list
, &list_used
, &list_alloced
);
3319 ALL_PSYMTABS (objfile
, ps
)
3321 if (not_interesting_fname (ps
->filename
))
3325 if (!filename_seen (ps
->filename
, 1, &first
)
3326 #if HAVE_DOS_BASED_FILE_SYSTEM
3327 && strncasecmp (ps
->filename
, text
, text_len
) == 0
3329 && strncmp (ps
->filename
, text
, text_len
) == 0
3333 /* This file matches for a completion; add it to the
3334 current list of matches. */
3335 add_filename_to_list (ps
->filename
, text
, word
,
3336 &list
, &list_used
, &list_alloced
);
3341 base_name
= lbasename (ps
->filename
);
3342 if (base_name
!= ps
->filename
3343 && !filename_seen (base_name
, 1, &first
)
3344 #if HAVE_DOS_BASED_FILE_SYSTEM
3345 && strncasecmp (base_name
, text
, text_len
) == 0
3347 && strncmp (base_name
, text
, text_len
) == 0
3350 add_filename_to_list (base_name
, text
, word
,
3351 &list
, &list_used
, &list_alloced
);
3359 /* Determine if PC is in the prologue of a function. The prologue is the area
3360 between the first instruction of a function, and the first executable line.
3361 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
3363 If non-zero, func_start is where we think the prologue starts, possibly
3364 by previous examination of symbol table information.
3368 in_prologue (CORE_ADDR pc
, CORE_ADDR func_start
)
3370 struct symtab_and_line sal
;
3371 CORE_ADDR func_addr
, func_end
;
3373 /* We have several sources of information we can consult to figure
3375 - Compilers usually emit line number info that marks the prologue
3376 as its own "source line". So the ending address of that "line"
3377 is the end of the prologue. If available, this is the most
3379 - The minimal symbols and partial symbols, which can usually tell
3380 us the starting and ending addresses of a function.
3381 - If we know the function's start address, we can call the
3382 architecture-defined SKIP_PROLOGUE function to analyze the
3383 instruction stream and guess where the prologue ends.
3384 - Our `func_start' argument; if non-zero, this is the caller's
3385 best guess as to the function's entry point. At the time of
3386 this writing, handle_inferior_event doesn't get this right, so
3387 it should be our last resort. */
3389 /* Consult the partial symbol table, to find which function
3391 if (! find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
3393 CORE_ADDR prologue_end
;
3395 /* We don't even have minsym information, so fall back to using
3396 func_start, if given. */
3398 return 1; /* We *might* be in a prologue. */
3400 prologue_end
= SKIP_PROLOGUE (func_start
);
3402 return func_start
<= pc
&& pc
< prologue_end
;
3405 /* If we have line number information for the function, that's
3406 usually pretty reliable. */
3407 sal
= find_pc_line (func_addr
, 0);
3409 /* Now sal describes the source line at the function's entry point,
3410 which (by convention) is the prologue. The end of that "line",
3411 sal.end, is the end of the prologue.
3413 Note that, for functions whose source code is all on a single
3414 line, the line number information doesn't always end up this way.
3415 So we must verify that our purported end-of-prologue address is
3416 *within* the function, not at its start or end. */
3418 || sal
.end
<= func_addr
3419 || func_end
<= sal
.end
)
3421 /* We don't have any good line number info, so use the minsym
3422 information, together with the architecture-specific prologue
3424 CORE_ADDR prologue_end
= SKIP_PROLOGUE (func_addr
);
3426 return func_addr
<= pc
&& pc
< prologue_end
;
3429 /* We have line number info, and it looks good. */
3430 return func_addr
<= pc
&& pc
< sal
.end
;
3434 /* Begin overload resolution functions */
3435 /* Helper routine for make_symbol_completion_list. */
3437 static int sym_return_val_size
;
3438 static int sym_return_val_index
;
3439 static struct symbol
**sym_return_val
;
3441 /* Test to see if the symbol specified by SYMNAME (which is already
3442 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3443 characters. If so, add it to the current completion list. */
3446 overload_list_add_symbol (struct symbol
*sym
, char *oload_name
)
3451 /* Get the demangled name without parameters */
3452 char *sym_name
= cplus_demangle (SYMBOL_NAME (sym
), DMGL_ARM
| DMGL_ANSI
);
3455 sym_name
= (char *) xmalloc (strlen (SYMBOL_NAME (sym
)) + 1);
3456 strcpy (sym_name
, SYMBOL_NAME (sym
));
3459 /* skip symbols that cannot match */
3460 if (strcmp (sym_name
, oload_name
) != 0)
3466 /* If there is no type information, we can't do anything, so skip */
3467 if (SYMBOL_TYPE (sym
) == NULL
)
3470 /* skip any symbols that we've already considered. */
3471 for (i
= 0; i
< sym_return_val_index
; ++i
)
3472 if (!strcmp (SYMBOL_NAME (sym
), SYMBOL_NAME (sym_return_val
[i
])))
3475 /* We have a match for an overload instance, so add SYM to the current list
3476 * of overload instances */
3477 if (sym_return_val_index
+ 3 > sym_return_val_size
)
3479 newsize
= (sym_return_val_size
*= 2) * sizeof (struct symbol
*);
3480 sym_return_val
= (struct symbol
**) xrealloc ((char *) sym_return_val
, newsize
);
3482 sym_return_val
[sym_return_val_index
++] = sym
;
3483 sym_return_val
[sym_return_val_index
] = NULL
;
3488 /* Return a null-terminated list of pointers to function symbols that
3489 * match name of the supplied symbol FSYM.
3490 * This is used in finding all overloaded instances of a function name.
3491 * This has been modified from make_symbol_completion_list. */
3495 make_symbol_overload_list (struct symbol
*fsym
)
3497 register struct symbol
*sym
;
3498 register struct symtab
*s
;
3499 register struct partial_symtab
*ps
;
3500 register struct objfile
*objfile
;
3501 register struct block
*b
, *surrounding_static_block
= 0;
3503 /* The name we are completing on. */
3504 char *oload_name
= NULL
;
3505 /* Length of name. */
3506 int oload_name_len
= 0;
3508 /* Look for the symbol we are supposed to complete on.
3509 * FIXME: This should be language-specific. */
3511 oload_name
= cplus_demangle (SYMBOL_NAME (fsym
), DMGL_ARM
| DMGL_ANSI
);
3514 oload_name
= (char *) xmalloc (strlen (SYMBOL_NAME (fsym
)) + 1);
3515 strcpy (oload_name
, SYMBOL_NAME (fsym
));
3517 oload_name_len
= strlen (oload_name
);
3519 sym_return_val_size
= 100;
3520 sym_return_val_index
= 0;
3521 sym_return_val
= (struct symbol
**) xmalloc ((sym_return_val_size
+ 1) * sizeof (struct symbol
*));
3522 sym_return_val
[0] = NULL
;
3524 /* Look through the partial symtabs for all symbols which begin
3525 by matching OLOAD_NAME. Make sure we read that symbol table in. */
3527 ALL_PSYMTABS (objfile
, ps
)
3529 struct partial_symbol
**psym
;
3531 /* If the psymtab's been read in we'll get it when we search
3532 through the blockvector. */
3536 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
3537 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
3538 + ps
->n_global_syms
);
3541 /* If interrupted, then quit. */
3543 /* This will cause the symbol table to be read if it has not yet been */
3544 s
= PSYMTAB_TO_SYMTAB (ps
);
3547 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
3548 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
3549 + ps
->n_static_syms
);
3553 /* This will cause the symbol table to be read if it has not yet been */
3554 s
= PSYMTAB_TO_SYMTAB (ps
);
3558 /* Search upwards from currently selected frame (so that we can
3559 complete on local vars. */
3561 for (b
= get_selected_block (); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
3563 if (!BLOCK_SUPERBLOCK (b
))
3565 surrounding_static_block
= b
; /* For elimination of dups */
3568 /* Also catch fields of types defined in this places which match our
3569 text string. Only complete on types visible from current context. */
3571 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3573 sym
= BLOCK_SYM (b
, i
);
3574 overload_list_add_symbol (sym
, oload_name
);
3578 /* Go through the symtabs and check the externs and statics for
3579 symbols which match. */
3581 ALL_SYMTABS (objfile
, s
)
3584 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3585 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3587 sym
= BLOCK_SYM (b
, i
);
3588 overload_list_add_symbol (sym
, oload_name
);
3592 ALL_SYMTABS (objfile
, s
)
3595 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3596 /* Don't do this block twice. */
3597 if (b
== surrounding_static_block
)
3599 for (i
= 0; i
< BLOCK_NSYMS (b
); i
++)
3601 sym
= BLOCK_SYM (b
, i
);
3602 overload_list_add_symbol (sym
, oload_name
);
3608 return (sym_return_val
);
3611 /* End of overload resolution functions */
3613 struct symtabs_and_lines
3614 decode_line_spec (char *string
, int funfirstline
)
3616 struct symtabs_and_lines sals
;
3618 error ("Empty line specification.");
3619 sals
= decode_line_1 (&string
, funfirstline
,
3620 current_source_symtab
, current_source_line
,
3623 error ("Junk at end of line specification: %s", string
);
3628 _initialize_symtab (void)
3630 add_info ("variables", variables_info
,
3631 "All global and static variable names, or those matching REGEXP.");
3633 add_com ("whereis", class_info
, variables_info
,
3634 "All global and static variable names, or those matching REGEXP.");
3636 add_info ("functions", functions_info
,
3637 "All function names, or those matching REGEXP.");
3640 /* FIXME: This command has at least the following problems:
3641 1. It prints builtin types (in a very strange and confusing fashion).
3642 2. It doesn't print right, e.g. with
3643 typedef struct foo *FOO
3644 type_print prints "FOO" when we want to make it (in this situation)
3645 print "struct foo *".
3646 I also think "ptype" or "whatis" is more likely to be useful (but if
3647 there is much disagreement "info types" can be fixed). */
3648 add_info ("types", types_info
,
3649 "All type names, or those matching REGEXP.");
3652 add_info ("methods", methods_info
,
3653 "All method names, or those matching REGEXP::REGEXP.\n\
3654 If the class qualifier is omitted, it is assumed to be the current scope.\n\
3655 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
3658 add_info ("sources", sources_info
,
3659 "Source files in the program.");
3661 add_com ("rbreak", class_breakpoint
, rbreak_command
,
3662 "Set a breakpoint for all functions matching REGEXP.");
3666 add_com ("lf", class_info
, sources_info
, "Source files in the program");
3667 add_com ("lg", class_info
, variables_info
,
3668 "All global and static variable names, or those matching REGEXP.");
3671 /* Initialize the one built-in type that isn't language dependent... */
3672 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
3673 "<unknown type>", (struct objfile
*) NULL
);