1 /* Symbol table lookup for the GNU debugger, GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
34 #include "call-cmds.h"
35 #include "gdb_regex.h"
36 #include "expression.h"
41 #include "filenames.h" /* for FILENAME_CMP */
43 #include "gdb_obstack.h"
45 #include <sys/types.h>
47 #include "gdb_string.h"
52 /* Prototype for one function in parser-defs.h,
53 instead of including that entire file. */
55 extern char *find_template_name_end (char *);
57 /* Prototypes for local functions */
59 static void completion_list_add_name (char *, char *, int, char *, char *);
61 static void rbreak_command (char *, int);
63 static void types_info (char *, int);
65 static void functions_info (char *, int);
67 static void variables_info (char *, int);
69 static void sources_info (char *, int);
71 static void output_source_filename (char *, int *);
73 static int find_line_common (struct linetable
*, int, int *);
75 /* This one is used by linespec.c */
77 char *operator_chars (char *p
, char **end
);
79 static struct partial_symbol
*lookup_partial_symbol (struct partial_symtab
*,
83 static struct symbol
*lookup_symbol_aux (const char *name
,
84 const char *mangled_name
,
85 const struct block
*block
,
86 const namespace_enum
namespace,
87 int *is_a_field_of_this
,
88 struct symtab
**symtab
);
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. */
141 lookup_symtab (const char *name
)
143 register struct symtab
*s
;
144 register struct partial_symtab
*ps
;
145 register struct objfile
*objfile
;
146 char *real_path
= NULL
;
147 char *full_path
= NULL
;
149 /* Here we are interested in canonicalizing an absolute path, not
150 absolutizing a relative path. */
151 if (IS_ABSOLUTE_PATH (name
))
153 full_path
= xfullpath (name
);
154 make_cleanup (xfree
, full_path
);
155 real_path
= gdb_realpath (name
);
156 make_cleanup (xfree
, real_path
);
161 /* First, search for an exact match */
163 ALL_SYMTABS (objfile
, s
)
165 if (FILENAME_CMP (name
, s
->filename
) == 0)
170 /* If the user gave us an absolute path, try to find the file in
171 this symtab and use its absolute path. */
173 if (full_path
!= NULL
)
175 const char *fp
= symtab_to_filename (s
);
176 if (FILENAME_CMP (full_path
, fp
) == 0)
182 if (real_path
!= NULL
)
184 char *rp
= gdb_realpath (symtab_to_filename (s
));
185 make_cleanup (xfree
, rp
);
186 if (FILENAME_CMP (real_path
, rp
) == 0)
193 /* Now, search for a matching tail (only if name doesn't have any dirs) */
195 if (lbasename (name
) == name
)
196 ALL_SYMTABS (objfile
, s
)
198 if (FILENAME_CMP (lbasename (s
->filename
), name
) == 0)
202 /* Same search rules as above apply here, but now we look thru the
205 ps
= lookup_partial_symtab (name
);
210 error ("Internal: readin %s pst for `%s' found when no symtab found.",
213 s
= PSYMTAB_TO_SYMTAB (ps
);
218 /* At this point, we have located the psymtab for this file, but
219 the conversion to a symtab has failed. This usually happens
220 when we are looking up an include file. In this case,
221 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
222 been created. So, we need to run through the symtabs again in
223 order to find the file.
224 XXX - This is a crock, and should be fixed inside of the the
225 symbol parsing routines. */
229 /* Lookup the partial symbol table of a source file named NAME.
230 *If* there is no '/' in the name, a match after a '/'
231 in the psymtab filename will also work. */
233 struct partial_symtab
*
234 lookup_partial_symtab (const char *name
)
236 register struct partial_symtab
*pst
;
237 register struct objfile
*objfile
;
238 char *full_path
= NULL
;
239 char *real_path
= NULL
;
241 /* Here we are interested in canonicalizing an absolute path, not
242 absolutizing a relative path. */
243 if (IS_ABSOLUTE_PATH (name
))
245 full_path
= xfullpath (name
);
246 make_cleanup (xfree
, full_path
);
247 real_path
= gdb_realpath (name
);
248 make_cleanup (xfree
, real_path
);
251 ALL_PSYMTABS (objfile
, pst
)
253 if (FILENAME_CMP (name
, pst
->filename
) == 0)
258 /* If the user gave us an absolute path, try to find the file in
259 this symtab and use its absolute path. */
260 if (full_path
!= NULL
)
262 if (pst
->fullname
== NULL
)
263 source_full_path_of (pst
->filename
, &pst
->fullname
);
264 if (pst
->fullname
!= NULL
265 && FILENAME_CMP (full_path
, pst
->fullname
) == 0)
271 if (real_path
!= NULL
)
274 if (pst
->fullname
== NULL
)
275 source_full_path_of (pst
->filename
, &pst
->fullname
);
276 if (pst
->fullname
!= NULL
)
278 rp
= gdb_realpath (pst
->fullname
);
279 make_cleanup (xfree
, rp
);
281 if (rp
!= NULL
&& FILENAME_CMP (real_path
, rp
) == 0)
288 /* Now, search for a matching tail (only if name doesn't have any dirs) */
290 if (lbasename (name
) == name
)
291 ALL_PSYMTABS (objfile
, pst
)
293 if (FILENAME_CMP (lbasename (pst
->filename
), name
) == 0)
300 /* Mangle a GDB method stub type. This actually reassembles the pieces of the
301 full method name, which consist of the class name (from T), the unadorned
302 method name from METHOD_ID, and the signature for the specific overload,
303 specified by SIGNATURE_ID. Note that this function is g++ specific. */
306 gdb_mangle_name (struct type
*type
, int method_id
, int signature_id
)
308 int mangled_name_len
;
310 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
311 struct fn_field
*method
= &f
[signature_id
];
312 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, method_id
);
313 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, signature_id
);
314 char *newname
= type_name_no_tag (type
);
316 /* Does the form of physname indicate that it is the full mangled name
317 of a constructor (not just the args)? */
318 int is_full_physname_constructor
;
321 int is_destructor
= is_destructor_name (physname
);
322 /* Need a new type prefix. */
323 char *const_prefix
= method
->is_const
? "C" : "";
324 char *volatile_prefix
= method
->is_volatile
? "V" : "";
326 int len
= (newname
== NULL
? 0 : strlen (newname
));
328 /* Nothing to do if physname already contains a fully mangled v3 abi name
329 or an operator name. */
330 if ((physname
[0] == '_' && physname
[1] == 'Z')
331 || is_operator_name (field_name
))
332 return xstrdup (physname
);
334 is_full_physname_constructor
= is_constructor_name (physname
);
337 is_full_physname_constructor
|| (newname
&& STREQ (field_name
, newname
));
340 is_destructor
= (strncmp (physname
, "__dt", 4) == 0);
342 if (is_destructor
|| is_full_physname_constructor
)
344 mangled_name
= (char *) xmalloc (strlen (physname
) + 1);
345 strcpy (mangled_name
, physname
);
351 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
353 else if (physname
[0] == 't' || physname
[0] == 'Q')
355 /* The physname for template and qualified methods already includes
357 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
363 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
365 mangled_name_len
= ((is_constructor
? 0 : strlen (field_name
))
366 + strlen (buf
) + len
+ strlen (physname
) + 1);
369 mangled_name
= (char *) xmalloc (mangled_name_len
);
371 mangled_name
[0] = '\0';
373 strcpy (mangled_name
, field_name
);
375 strcat (mangled_name
, buf
);
376 /* If the class doesn't have a name, i.e. newname NULL, then we just
377 mangle it using 0 for the length of the class. Thus it gets mangled
378 as something starting with `::' rather than `classname::'. */
380 strcat (mangled_name
, newname
);
382 strcat (mangled_name
, physname
);
383 return (mangled_name
);
387 /* Initialize a symbol's mangled name. */
389 /* Try to initialize the demangled name for a symbol, based on the
390 language of that symbol. If the language is set to language_auto,
391 it will attempt to find any demangling algorithm that works and
392 then set the language appropriately. If no demangling of any kind
393 is found, the language is set back to language_unknown, so we can
394 avoid doing this work again the next time we encounter the symbol.
395 Any required space to store the name is obtained from the specified
399 symbol_init_demangled_name (struct general_symbol_info
*gsymbol
,
400 struct obstack
*obstack
)
402 char *mangled
= gsymbol
->name
;
403 char *demangled
= NULL
;
405 if (gsymbol
->language
== language_unknown
)
406 gsymbol
->language
= language_auto
;
407 if (gsymbol
->language
== language_cplus
408 || gsymbol
->language
== language_auto
)
411 cplus_demangle (gsymbol
->name
, DMGL_PARAMS
| DMGL_ANSI
);
412 if (demangled
!= NULL
)
414 gsymbol
->language
= language_cplus
;
415 gsymbol
->language_specific
.cplus_specific
.demangled_name
=
416 obsavestring (demangled
, strlen (demangled
), obstack
);
421 gsymbol
->language_specific
.cplus_specific
.demangled_name
= NULL
;
424 if (gsymbol
->language
== language_java
)
427 cplus_demangle (gsymbol
->name
,
428 DMGL_PARAMS
| DMGL_ANSI
| DMGL_JAVA
);
429 if (demangled
!= NULL
)
431 gsymbol
->language
= language_java
;
432 gsymbol
->language_specific
.cplus_specific
.demangled_name
=
433 obsavestring (demangled
, strlen (demangled
), obstack
);
438 gsymbol
->language_specific
.cplus_specific
.demangled_name
= NULL
;
442 /* OBSOLETE if (demangled == NULL */
443 /* OBSOLETE && (gsymbol->language == language_chill */
444 /* OBSOLETE || gsymbol->language == language_auto)) */
446 /* OBSOLETE demangled = */
447 /* OBSOLETE chill_demangle (gsymbol->name); */
448 /* OBSOLETE if (demangled != NULL) */
450 /* OBSOLETE gsymbol->language = language_chill; */
451 /* OBSOLETE gsymbol->language_specific.chill_specific.demangled_name = */
452 /* OBSOLETE obsavestring (demangled, strlen (demangled), obstack); */
453 /* OBSOLETE xfree (demangled); */
457 /* OBSOLETE gsymbol->language_specific.chill_specific.demangled_name = NULL; */
467 /* Find which partial symtab on contains PC and SECTION. Return 0 if none. */
469 struct partial_symtab
*
470 find_pc_sect_psymtab (CORE_ADDR pc
, asection
*section
)
472 register struct partial_symtab
*pst
;
473 register struct objfile
*objfile
;
474 struct minimal_symbol
*msymbol
;
476 /* If we know that this is not a text address, return failure. This is
477 necessary because we loop based on texthigh and textlow, which do
478 not include the data ranges. */
479 msymbol
= lookup_minimal_symbol_by_pc_section (pc
, section
);
481 && (msymbol
->type
== mst_data
482 || msymbol
->type
== mst_bss
483 || msymbol
->type
== mst_abs
484 || msymbol
->type
== mst_file_data
485 || msymbol
->type
== mst_file_bss
))
488 ALL_PSYMTABS (objfile
, pst
)
490 if (pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
492 struct partial_symtab
*tpst
;
494 /* An objfile that has its functions reordered might have
495 many partial symbol tables containing the PC, but
496 we want the partial symbol table that contains the
497 function containing the PC. */
498 if (!(objfile
->flags
& OBJF_REORDERED
) &&
499 section
== 0) /* can't validate section this way */
505 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
507 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
509 struct partial_symbol
*p
;
511 p
= find_pc_sect_psymbol (tpst
, pc
, section
);
513 && SYMBOL_VALUE_ADDRESS (p
)
514 == SYMBOL_VALUE_ADDRESS (msymbol
))
524 /* Find which partial symtab contains PC. Return 0 if none.
525 Backward compatibility, no section */
527 struct partial_symtab
*
528 find_pc_psymtab (CORE_ADDR pc
)
530 return find_pc_sect_psymtab (pc
, find_pc_mapped_section (pc
));
533 /* Find which partial symbol within a psymtab matches PC and SECTION.
534 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
536 struct partial_symbol
*
537 find_pc_sect_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
,
540 struct partial_symbol
*best
= NULL
, *p
, **pp
;
544 psymtab
= find_pc_sect_psymtab (pc
, section
);
548 /* Cope with programs that start at address 0 */
549 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
551 /* Search the global symbols as well as the static symbols, so that
552 find_pc_partial_function doesn't use a minimal symbol and thus
553 cache a bad endaddr. */
554 for (pp
= psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
555 (pp
- (psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
556 < psymtab
->n_global_syms
);
560 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
561 && SYMBOL_CLASS (p
) == LOC_BLOCK
562 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
563 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
564 || (psymtab
->textlow
== 0
565 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
567 if (section
) /* match on a specific section */
569 fixup_psymbol_section (p
, psymtab
->objfile
);
570 if (SYMBOL_BFD_SECTION (p
) != section
)
573 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
578 for (pp
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
579 (pp
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
580 < psymtab
->n_static_syms
);
584 if (SYMBOL_NAMESPACE (p
) == VAR_NAMESPACE
585 && SYMBOL_CLASS (p
) == LOC_BLOCK
586 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
587 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
588 || (psymtab
->textlow
== 0
589 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
591 if (section
) /* match on a specific section */
593 fixup_psymbol_section (p
, psymtab
->objfile
);
594 if (SYMBOL_BFD_SECTION (p
) != section
)
597 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
605 /* Find which partial symbol within a psymtab matches PC. Return 0 if none.
606 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
608 struct partial_symbol
*
609 find_pc_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
)
611 return find_pc_sect_psymbol (psymtab
, pc
, find_pc_mapped_section (pc
));
614 /* Debug symbols usually don't have section information. We need to dig that
615 out of the minimal symbols and stash that in the debug symbol. */
618 fixup_section (struct general_symbol_info
*ginfo
, struct objfile
*objfile
)
620 struct minimal_symbol
*msym
;
621 msym
= lookup_minimal_symbol (ginfo
->name
, NULL
, objfile
);
625 ginfo
->bfd_section
= SYMBOL_BFD_SECTION (msym
);
626 ginfo
->section
= SYMBOL_SECTION (msym
);
631 fixup_symbol_section (struct symbol
*sym
, struct objfile
*objfile
)
636 if (SYMBOL_BFD_SECTION (sym
))
639 fixup_section (&sym
->ginfo
, objfile
);
644 struct partial_symbol
*
645 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
650 if (SYMBOL_BFD_SECTION (psym
))
653 fixup_section (&psym
->ginfo
, objfile
);
658 /* Find the definition for a specified symbol name NAME
659 in namespace NAMESPACE, visible from lexical block BLOCK.
660 Returns the struct symbol pointer, or zero if no symbol is found.
661 If SYMTAB is non-NULL, store the symbol table in which the
662 symbol was found there, or NULL if not found.
663 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
664 NAME is a field of the current implied argument `this'. If so set
665 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
666 BLOCK_FOUND is set to the block in which NAME is found (in the case of
667 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
669 /* This function has a bunch of loops in it and it would seem to be
670 attractive to put in some QUIT's (though I'm not really sure
671 whether it can run long enough to be really important). But there
672 are a few calls for which it would appear to be bad news to quit
673 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c, and
674 nindy_frame_chain_valid in nindy-tdep.c. (Note that there is C++
675 code below which can error(), but that probably doesn't affect
676 these calls since they are looking for a known variable and thus
677 can probably assume it will never hit the C++ code). */
680 lookup_symbol (const char *name
, const struct block
*block
,
681 const namespace_enum
namespace, int *is_a_field_of_this
,
682 struct symtab
**symtab
)
684 char *demangled_name
= NULL
;
685 const char *modified_name
= NULL
;
686 const char *mangled_name
= NULL
;
687 int needtofreename
= 0;
688 struct symbol
*returnval
;
690 modified_name
= name
;
692 /* If we are using C++ language, demangle the name before doing a lookup, so
693 we can always binary search. */
694 if (current_language
->la_language
== language_cplus
)
696 demangled_name
= cplus_demangle (name
, DMGL_ANSI
| DMGL_PARAMS
);
700 modified_name
= demangled_name
;
705 if (case_sensitivity
== case_sensitive_off
)
711 copy
= (char *) alloca (len
+ 1);
712 for (i
= 0; i
< len
; i
++)
713 copy
[i
] = tolower (name
[i
]);
715 modified_name
= copy
;
718 returnval
= lookup_symbol_aux (modified_name
, mangled_name
, block
,
719 namespace, is_a_field_of_this
, symtab
);
721 xfree (demangled_name
);
726 static struct symbol
*
727 lookup_symbol_aux (const char *name
, const char *mangled_name
,
728 const struct block
*block
, const namespace_enum
namespace,
729 int *is_a_field_of_this
, struct symtab
**symtab
)
731 register struct symbol
*sym
;
732 register struct symtab
*s
= NULL
;
733 register struct partial_symtab
*ps
;
734 register struct blockvector
*bv
;
735 register struct objfile
*objfile
= NULL
;
736 register struct block
*b
;
737 register struct minimal_symbol
*msymbol
;
740 /* Search specified block and its superiors. */
744 sym
= lookup_block_symbol (block
, name
, mangled_name
, namespace);
750 /* Search the list of symtabs for one which contains the
751 address of the start of this block. */
752 ALL_SYMTABS (objfile
, s
)
754 bv
= BLOCKVECTOR (s
);
755 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
756 if (BLOCK_START (b
) <= BLOCK_START (block
)
757 && BLOCK_END (b
) > BLOCK_START (block
))
764 return fixup_symbol_section (sym
, objfile
);
766 block
= BLOCK_SUPERBLOCK (block
);
769 /* FIXME: this code is never executed--block is always NULL at this
770 point. What is it trying to do, anyway? We already should have
771 checked the STATIC_BLOCK above (it is the superblock of top-level
772 blocks). Why is VAR_NAMESPACE special-cased? */
773 /* Don't need to mess with the psymtabs; if we have a block,
774 that file is read in. If we don't, then we deal later with
775 all the psymtab stuff that needs checking. */
776 /* Note (RT): The following never-executed code looks unnecessary to me also.
777 * If we change the code to use the original (passed-in)
778 * value of 'block', we could cause it to execute, but then what
779 * would it do? The STATIC_BLOCK of the symtab containing the passed-in
780 * 'block' was already searched by the above code. And the STATIC_BLOCK's
781 * of *other* symtabs (those files not containing 'block' lexically)
782 * should not contain 'block' address-wise. So we wouldn't expect this
783 * code to find any 'sym''s that were not found above. I vote for
784 * deleting the following paragraph of code.
786 if (namespace == VAR_NAMESPACE
&& block
!= NULL
)
789 /* Find the right symtab. */
790 ALL_SYMTABS (objfile
, s
)
792 bv
= BLOCKVECTOR (s
);
793 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
794 if (BLOCK_START (b
) <= BLOCK_START (block
)
795 && BLOCK_END (b
) > BLOCK_START (block
))
797 sym
= lookup_block_symbol (b
, name
, mangled_name
, VAR_NAMESPACE
);
803 return fixup_symbol_section (sym
, objfile
);
810 /* C++: If requested to do so by the caller,
811 check to see if NAME is a field of `this'. */
812 if (is_a_field_of_this
)
814 struct value
*v
= value_of_this (0);
816 *is_a_field_of_this
= 0;
817 if (v
&& check_field (v
, name
))
819 *is_a_field_of_this
= 1;
826 /* Now search all global blocks. Do the symtab's first, then
827 check the psymtab's. If a psymtab indicates the existence
828 of the desired name as a global, then do psymtab-to-symtab
829 conversion on the fly and return the found symbol. */
831 ALL_SYMTABS (objfile
, s
)
833 bv
= BLOCKVECTOR (s
);
834 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
835 sym
= lookup_block_symbol (block
, name
, mangled_name
, namespace);
841 return fixup_symbol_section (sym
, objfile
);
847 /* Check for the possibility of the symbol being a function or
848 a mangled variable that is stored in one of the minimal symbol tables.
849 Eventually, all global symbols might be resolved in this way. */
851 if (namespace == VAR_NAMESPACE
)
853 msymbol
= lookup_minimal_symbol (name
, NULL
, NULL
);
856 s
= find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol
),
857 SYMBOL_BFD_SECTION (msymbol
));
860 /* This is a function which has a symtab for its address. */
861 bv
= BLOCKVECTOR (s
);
862 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
863 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
864 mangled_name
, namespace);
865 /* We kept static functions in minimal symbol table as well as
866 in static scope. We want to find them in the symbol table. */
869 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
870 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
871 mangled_name
, namespace);
874 /* sym == 0 if symbol was found in the minimal symbol table
875 but not in the symtab.
876 Return 0 to use the msymbol definition of "foo_".
878 This happens for Fortran "foo_" symbols,
879 which are "foo" in the symtab.
881 This can also happen if "asm" is used to make a
882 regular symbol but not a debugging symbol, e.g.
889 return fixup_symbol_section (sym
, objfile
);
891 else if (MSYMBOL_TYPE (msymbol
) != mst_text
892 && MSYMBOL_TYPE (msymbol
) != mst_file_text
893 && !STREQ (name
, SYMBOL_NAME (msymbol
)))
895 /* This is a mangled variable, look it up by its
897 return lookup_symbol_aux (SYMBOL_NAME (msymbol
), mangled_name
, block
,
898 namespace, is_a_field_of_this
, symtab
);
900 /* There are no debug symbols for this file, or we are looking
901 for an unmangled variable.
902 Try to find a matching static symbol below. */
908 ALL_PSYMTABS (objfile
, ps
)
910 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, namespace))
912 s
= PSYMTAB_TO_SYMTAB (ps
);
913 bv
= BLOCKVECTOR (s
);
914 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
915 sym
= lookup_block_symbol (block
, name
, mangled_name
, namespace);
918 /* This shouldn't be necessary, but as a last resort
919 * try looking in the statics even though the psymtab
920 * claimed the symbol was global. It's possible that
921 * the psymtab gets it wrong in some cases.
923 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
924 sym
= lookup_block_symbol (block
, name
, mangled_name
, namespace);
926 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
927 %s may be an inlined function, or may be a template function\n\
928 (if a template, try specifying an instantiation: %s<type>).",
929 name
, ps
->filename
, name
, name
);
933 return fixup_symbol_section (sym
, objfile
);
937 /* Now search all static file-level symbols.
938 Not strictly correct, but more useful than an error.
939 Do the symtabs first, then check the psymtabs.
940 If a psymtab indicates the existence
941 of the desired name as a file-level static, then do psymtab-to-symtab
942 conversion on the fly and return the found symbol. */
944 ALL_SYMTABS (objfile
, s
)
946 bv
= BLOCKVECTOR (s
);
947 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
948 sym
= lookup_block_symbol (block
, name
, mangled_name
, namespace);
954 return fixup_symbol_section (sym
, objfile
);
958 ALL_PSYMTABS (objfile
, ps
)
960 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, namespace))
962 s
= PSYMTAB_TO_SYMTAB (ps
);
963 bv
= BLOCKVECTOR (s
);
964 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
965 sym
= lookup_block_symbol (block
, name
, mangled_name
, namespace);
968 /* This shouldn't be necessary, but as a last resort
969 * try looking in the globals even though the psymtab
970 * claimed the symbol was static. It's possible that
971 * the psymtab gets it wrong in some cases.
973 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
974 sym
= lookup_block_symbol (block
, name
, mangled_name
, namespace);
976 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
977 %s may be an inlined function, or may be a template function\n\
978 (if a template, try specifying an instantiation: %s<type>).",
979 name
, ps
->filename
, name
, name
);
983 return fixup_symbol_section (sym
, objfile
);
989 /* Check for the possibility of the symbol being a function or
990 a global variable that is stored in one of the minimal symbol tables.
991 The "minimal symbol table" is built from linker-supplied info.
993 RT: I moved this check to last, after the complete search of
994 the global (p)symtab's and static (p)symtab's. For HP-generated
995 symbol tables, this check was causing a premature exit from
996 lookup_symbol with NULL return, and thus messing up symbol lookups
997 of things like "c::f". It seems to me a check of the minimal
998 symbol table ought to be a last resort in any case. I'm vaguely
999 worried about the comment below which talks about FORTRAN routines "foo_"
1000 though... is it saying we need to do the "minsym" check before
1001 the static check in this case?
1004 if (namespace == VAR_NAMESPACE
)
1006 msymbol
= lookup_minimal_symbol (name
, NULL
, NULL
);
1007 if (msymbol
!= NULL
)
1009 /* OK, we found a minimal symbol in spite of not
1010 * finding any symbol. There are various possible
1011 * explanations for this. One possibility is the symbol
1012 * exists in code not compiled -g. Another possibility
1013 * is that the 'psymtab' isn't doing its job.
1014 * A third possibility, related to #2, is that we were confused
1015 * by name-mangling. For instance, maybe the psymtab isn't
1016 * doing its job because it only know about demangled
1017 * names, but we were given a mangled name...
1020 /* We first use the address in the msymbol to try to
1021 * locate the appropriate symtab. Note that find_pc_symtab()
1022 * has a side-effect of doing psymtab-to-symtab expansion,
1023 * for the found symtab.
1025 s
= find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
));
1028 bv
= BLOCKVECTOR (s
);
1029 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1030 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
1031 mangled_name
, namespace);
1032 /* We kept static functions in minimal symbol table as well as
1033 in static scope. We want to find them in the symbol table. */
1036 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1037 sym
= lookup_block_symbol (block
, SYMBOL_NAME (msymbol
),
1038 mangled_name
, namespace);
1040 /* If we found one, return it */
1048 /* If we get here with sym == 0, the symbol was
1049 found in the minimal symbol table
1050 but not in the symtab.
1051 Fall through and return 0 to use the msymbol
1052 definition of "foo_".
1053 (Note that outer code generally follows up a call
1054 to this routine with a call to lookup_minimal_symbol(),
1055 so a 0 return means we'll just flow into that other routine).
1057 This happens for Fortran "foo_" symbols,
1058 which are "foo" in the symtab.
1060 This can also happen if "asm" is used to make a
1061 regular symbol but not a debugging symbol, e.g.
1062 asm(".globl _main");
1067 /* If the lookup-by-address fails, try repeating the
1068 * entire lookup process with the symbol name from
1069 * the msymbol (if different from the original symbol name).
1071 else if (MSYMBOL_TYPE (msymbol
) != mst_text
1072 && MSYMBOL_TYPE (msymbol
) != mst_file_text
1073 && !STREQ (name
, SYMBOL_NAME (msymbol
)))
1075 return lookup_symbol_aux (SYMBOL_NAME (msymbol
), mangled_name
,
1076 block
, namespace, is_a_field_of_this
,
1089 /* Look, in partial_symtab PST, for symbol NAME. Check the global
1090 symbols if GLOBAL, the static symbols if not */
1092 static struct partial_symbol
*
1093 lookup_partial_symbol (struct partial_symtab
*pst
, const char *name
, int global
,
1094 namespace_enum
namespace)
1096 struct partial_symbol
*temp
;
1097 struct partial_symbol
**start
, **psym
;
1098 struct partial_symbol
**top
, **bottom
, **center
;
1099 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
1100 int do_linear_search
= 1;
1107 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
1108 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1110 if (global
) /* This means we can use a binary search. */
1112 do_linear_search
= 0;
1114 /* Binary search. This search is guaranteed to end with center
1115 pointing at the earliest partial symbol with the correct
1116 name. At that point *all* partial symbols with that name
1117 will be checked against the correct namespace. */
1120 top
= start
+ length
- 1;
1121 while (top
> bottom
)
1123 center
= bottom
+ (top
- bottom
) / 2;
1124 if (!(center
< top
))
1125 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
1126 if (!do_linear_search
1127 && (SYMBOL_LANGUAGE (*center
) == language_java
))
1129 do_linear_search
= 1;
1131 if (strcmp (SYMBOL_SOURCE_NAME (*center
), name
) >= 0)
1137 bottom
= center
+ 1;
1140 if (!(top
== bottom
))
1141 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
1143 /* djb - 2000-06-03 - Use SYMBOL_MATCHES_NAME, not a strcmp, so
1144 we don't have to force a linear search on C++. Probably holds true
1145 for JAVA as well, no way to check.*/
1146 while (SYMBOL_MATCHES_NAME (*top
,name
))
1148 if (SYMBOL_NAMESPACE (*top
) == namespace)
1156 /* Can't use a binary search or else we found during the binary search that
1157 we should also do a linear search. */
1159 if (do_linear_search
)
1161 for (psym
= start
; psym
< start
+ length
; psym
++)
1163 if (namespace == SYMBOL_NAMESPACE (*psym
))
1165 if (SYMBOL_MATCHES_NAME (*psym
, name
))
1176 /* Look up a type named NAME in the struct_namespace. The type returned
1177 must not be opaque -- i.e., must have at least one field defined
1179 This code was modelled on lookup_symbol -- the parts not relevant to looking
1180 up types were just left out. In particular it's assumed here that types
1181 are available in struct_namespace and only at file-static or global blocks. */
1185 lookup_transparent_type (const char *name
)
1187 register struct symbol
*sym
;
1188 register struct symtab
*s
= NULL
;
1189 register struct partial_symtab
*ps
;
1190 struct blockvector
*bv
;
1191 register struct objfile
*objfile
;
1192 register struct block
*block
;
1194 /* Now search all the global symbols. Do the symtab's first, then
1195 check the psymtab's. If a psymtab indicates the existence
1196 of the desired name as a global, then do psymtab-to-symtab
1197 conversion on the fly and return the found symbol. */
1199 ALL_SYMTABS (objfile
, s
)
1201 bv
= BLOCKVECTOR (s
);
1202 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1203 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_NAMESPACE
);
1204 if (sym
&& !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1206 return SYMBOL_TYPE (sym
);
1210 ALL_PSYMTABS (objfile
, ps
)
1212 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 1, STRUCT_NAMESPACE
))
1214 s
= PSYMTAB_TO_SYMTAB (ps
);
1215 bv
= BLOCKVECTOR (s
);
1216 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1217 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_NAMESPACE
);
1220 /* This shouldn't be necessary, but as a last resort
1221 * try looking in the statics even though the psymtab
1222 * claimed the symbol was global. It's possible that
1223 * the psymtab gets it wrong in some cases.
1225 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1226 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_NAMESPACE
);
1228 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
1229 %s may be an inlined function, or may be a template function\n\
1230 (if a template, try specifying an instantiation: %s<type>).",
1231 name
, ps
->filename
, name
, name
);
1233 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1234 return SYMBOL_TYPE (sym
);
1238 /* Now search the static file-level symbols.
1239 Not strictly correct, but more useful than an error.
1240 Do the symtab's first, then
1241 check the psymtab's. If a psymtab indicates the existence
1242 of the desired name as a file-level static, then do psymtab-to-symtab
1243 conversion on the fly and return the found symbol.
1246 ALL_SYMTABS (objfile
, s
)
1248 bv
= BLOCKVECTOR (s
);
1249 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1250 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_NAMESPACE
);
1251 if (sym
&& !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1253 return SYMBOL_TYPE (sym
);
1257 ALL_PSYMTABS (objfile
, ps
)
1259 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, 0, STRUCT_NAMESPACE
))
1261 s
= PSYMTAB_TO_SYMTAB (ps
);
1262 bv
= BLOCKVECTOR (s
);
1263 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1264 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_NAMESPACE
);
1267 /* This shouldn't be necessary, but as a last resort
1268 * try looking in the globals even though the psymtab
1269 * claimed the symbol was static. It's possible that
1270 * the psymtab gets it wrong in some cases.
1272 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1273 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_NAMESPACE
);
1275 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
1276 %s may be an inlined function, or may be a template function\n\
1277 (if a template, try specifying an instantiation: %s<type>).",
1278 name
, ps
->filename
, name
, name
);
1280 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1281 return SYMBOL_TYPE (sym
);
1284 return (struct type
*) 0;
1288 /* Find the psymtab containing main(). */
1289 /* FIXME: What about languages without main() or specially linked
1290 executables that have no main() ? */
1292 struct partial_symtab
*
1293 find_main_psymtab (void)
1295 register struct partial_symtab
*pst
;
1296 register struct objfile
*objfile
;
1298 ALL_PSYMTABS (objfile
, pst
)
1300 if (lookup_partial_symbol (pst
, main_name (), 1, VAR_NAMESPACE
))
1308 /* Search BLOCK for symbol NAME in NAMESPACE.
1310 Note that if NAME is the demangled form of a C++ symbol, we will fail
1311 to find a match during the binary search of the non-encoded names, but
1312 for now we don't worry about the slight inefficiency of looking for
1313 a match we'll never find, since it will go pretty quick. Once the
1314 binary search terminates, we drop through and do a straight linear
1315 search on the symbols. Each symbol which is marked as being a C++
1316 symbol (language_cplus set) has both the encoded and non-encoded names
1319 If MANGLED_NAME is non-NULL, verify that any symbol we find has this
1320 particular mangled name.
1324 lookup_block_symbol (register const struct block
*block
, const char *name
,
1325 const char *mangled_name
,
1326 const namespace_enum
namespace)
1328 register int bot
, top
, inc
;
1329 register struct symbol
*sym
;
1330 register struct symbol
*sym_found
= NULL
;
1331 register int do_linear_search
= 1;
1333 if (BLOCK_HASHTABLE (block
))
1335 unsigned int hash_index
;
1336 hash_index
= msymbol_hash_iw (name
);
1337 hash_index
= hash_index
% BLOCK_BUCKETS (block
);
1338 for (sym
= BLOCK_BUCKET (block
, hash_index
); sym
; sym
= sym
->hash_next
)
1340 if (SYMBOL_NAMESPACE (sym
) == namespace
1342 ? strcmp (SYMBOL_NAME (sym
), mangled_name
) == 0
1343 : SYMBOL_MATCHES_NAME (sym
, name
)))
1349 /* If the blocks's symbols were sorted, start with a binary search. */
1351 if (BLOCK_SHOULD_SORT (block
))
1353 /* Reset the linear search flag so if the binary search fails, we
1354 won't do the linear search once unless we find some reason to
1357 do_linear_search
= 0;
1358 top
= BLOCK_NSYMS (block
);
1361 /* Advance BOT to not far before the first symbol whose name is NAME. */
1365 inc
= (top
- bot
+ 1);
1366 /* No need to keep binary searching for the last few bits worth. */
1371 inc
= (inc
>> 1) + bot
;
1372 sym
= BLOCK_SYM (block
, inc
);
1373 if (!do_linear_search
&& (SYMBOL_LANGUAGE (sym
) == language_java
))
1375 do_linear_search
= 1;
1377 if (SYMBOL_SOURCE_NAME (sym
)[0] < name
[0])
1381 else if (SYMBOL_SOURCE_NAME (sym
)[0] > name
[0])
1385 else if (strcmp (SYMBOL_SOURCE_NAME (sym
), name
) < 0)
1395 /* Now scan forward until we run out of symbols, find one whose
1396 name is greater than NAME, or find one we want. If there is
1397 more than one symbol with the right name and namespace, we
1398 return the first one; I believe it is now impossible for us
1399 to encounter two symbols with the same name and namespace
1400 here, because blocks containing argument symbols are no
1401 longer sorted. The exception is for C++, where multiple functions
1402 (cloned constructors / destructors, in particular) can have
1403 the same demangled name. So if we have a particular
1404 mangled name to match, try to do so. */
1406 top
= BLOCK_NSYMS (block
);
1409 sym
= BLOCK_SYM (block
, bot
);
1410 if (SYMBOL_NAMESPACE (sym
) == namespace
1412 ? strcmp (SYMBOL_NAME (sym
), mangled_name
) == 0
1413 : SYMBOL_MATCHES_NAME (sym
, name
)))
1417 if (SYMBOL_SOURCE_NAME (sym
)[0] > name
[0])
1425 /* Here if block isn't sorted, or we fail to find a match during the
1426 binary search above. If during the binary search above, we find a
1427 symbol which is a Java symbol, then we have re-enabled the linear
1428 search flag which was reset when starting the binary search.
1430 This loop is equivalent to the loop above, but hacked greatly for speed.
1432 Note that parameter symbols do not always show up last in the
1433 list; this loop makes sure to take anything else other than
1434 parameter symbols first; it only uses parameter symbols as a
1435 last resort. Note that this only takes up extra computation
1438 if (do_linear_search
)
1440 top
= BLOCK_NSYMS (block
);
1444 sym
= BLOCK_SYM (block
, bot
);
1445 if (SYMBOL_NAMESPACE (sym
) == namespace
1447 ? strcmp (SYMBOL_NAME (sym
), mangled_name
) == 0
1448 : SYMBOL_MATCHES_NAME (sym
, name
)))
1450 /* If SYM has aliases, then use any alias that is active
1451 at the current PC. If no alias is active at the current
1452 PC, then use the main symbol.
1454 ?!? Is checking the current pc correct? Is this routine
1455 ever called to look up a symbol from another context?
1457 FIXME: No, it's not correct. If someone sets a
1458 conditional breakpoint at an address, then the
1459 breakpoint's `struct expression' should refer to the
1460 `struct symbol' appropriate for the breakpoint's
1461 address, which may not be the PC.
1463 Even if it were never called from another context,
1464 it's totally bizarre for lookup_symbol's behavior to
1465 depend on the value of the inferior's current PC. We
1466 should pass in the appropriate PC as well as the
1467 block. The interface to lookup_symbol should change
1468 to require the caller to provide a PC. */
1470 if (SYMBOL_ALIASES (sym
))
1471 sym
= find_active_alias (sym
, read_pc ());
1474 if (SYMBOL_CLASS (sym
) != LOC_ARG
&&
1475 SYMBOL_CLASS (sym
) != LOC_LOCAL_ARG
&&
1476 SYMBOL_CLASS (sym
) != LOC_REF_ARG
&&
1477 SYMBOL_CLASS (sym
) != LOC_REGPARM
&&
1478 SYMBOL_CLASS (sym
) != LOC_REGPARM_ADDR
&&
1479 SYMBOL_CLASS (sym
) != LOC_BASEREG_ARG
)
1487 return (sym_found
); /* Will be NULL if not found. */
1490 /* Given a main symbol SYM and ADDR, search through the alias
1491 list to determine if an alias is active at ADDR and return
1494 If no alias is active, then return SYM. */
1496 static struct symbol
*
1497 find_active_alias (struct symbol
*sym
, CORE_ADDR addr
)
1499 struct range_list
*r
;
1500 struct alias_list
*aliases
;
1502 /* If we have aliases, check them first. */
1503 aliases
= SYMBOL_ALIASES (sym
);
1507 if (!SYMBOL_RANGES (aliases
->sym
))
1508 return aliases
->sym
;
1509 for (r
= SYMBOL_RANGES (aliases
->sym
); r
; r
= r
->next
)
1511 if (r
->start
<= addr
&& r
->end
> addr
)
1512 return aliases
->sym
;
1514 aliases
= aliases
->next
;
1517 /* Nothing found, return the main symbol. */
1522 /* Return the symbol for the function which contains a specified
1523 lexical block, described by a struct block BL. */
1526 block_function (struct block
*bl
)
1528 while (BLOCK_FUNCTION (bl
) == 0 && BLOCK_SUPERBLOCK (bl
) != 0)
1529 bl
= BLOCK_SUPERBLOCK (bl
);
1531 return BLOCK_FUNCTION (bl
);
1534 /* Find the symtab associated with PC and SECTION. Look through the
1535 psymtabs and read in another symtab if necessary. */
1538 find_pc_sect_symtab (CORE_ADDR pc
, asection
*section
)
1540 register struct block
*b
;
1541 struct blockvector
*bv
;
1542 register struct symtab
*s
= NULL
;
1543 register struct symtab
*best_s
= NULL
;
1544 register struct partial_symtab
*ps
;
1545 register struct objfile
*objfile
;
1546 CORE_ADDR distance
= 0;
1547 struct minimal_symbol
*msymbol
;
1549 /* If we know that this is not a text address, return failure. This is
1550 necessary because we loop based on the block's high and low code
1551 addresses, which do not include the data ranges, and because
1552 we call find_pc_sect_psymtab which has a similar restriction based
1553 on the partial_symtab's texthigh and textlow. */
1554 msymbol
= lookup_minimal_symbol_by_pc_section (pc
, section
);
1556 && (msymbol
->type
== mst_data
1557 || msymbol
->type
== mst_bss
1558 || msymbol
->type
== mst_abs
1559 || msymbol
->type
== mst_file_data
1560 || msymbol
->type
== mst_file_bss
))
1563 /* Search all symtabs for the one whose file contains our address, and which
1564 is the smallest of all the ones containing the address. This is designed
1565 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1566 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1567 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1569 This happens for native ecoff format, where code from included files
1570 gets its own symtab. The symtab for the included file should have
1571 been read in already via the dependency mechanism.
1572 It might be swifter to create several symtabs with the same name
1573 like xcoff does (I'm not sure).
1575 It also happens for objfiles that have their functions reordered.
1576 For these, the symtab we are looking for is not necessarily read in. */
1578 ALL_SYMTABS (objfile
, s
)
1580 bv
= BLOCKVECTOR (s
);
1581 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1583 if (BLOCK_START (b
) <= pc
1584 && BLOCK_END (b
) > pc
1586 || BLOCK_END (b
) - BLOCK_START (b
) < distance
))
1588 /* For an objfile that has its functions reordered,
1589 find_pc_psymtab will find the proper partial symbol table
1590 and we simply return its corresponding symtab. */
1591 /* In order to better support objfiles that contain both
1592 stabs and coff debugging info, we continue on if a psymtab
1594 if ((objfile
->flags
& OBJF_REORDERED
) && objfile
->psymtabs
)
1596 ps
= find_pc_sect_psymtab (pc
, section
);
1598 return PSYMTAB_TO_SYMTAB (ps
);
1603 struct symbol
*sym
= NULL
;
1605 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
1607 fixup_symbol_section (sym
, objfile
);
1608 if (section
== SYMBOL_BFD_SECTION (sym
))
1611 if ((i
>= BLOCK_BUCKETS (b
)) && (sym
== NULL
))
1612 continue; /* no symbol in this symtab matches section */
1614 distance
= BLOCK_END (b
) - BLOCK_START (b
);
1623 ps
= find_pc_sect_psymtab (pc
, section
);
1627 /* Might want to error() here (in case symtab is corrupt and
1628 will cause a core dump), but maybe we can successfully
1629 continue, so let's not. */
1631 (Internal error: pc 0x%s in read in psymtab, but not in symtab.)\n",
1633 s
= PSYMTAB_TO_SYMTAB (ps
);
1638 /* Find the symtab associated with PC. Look through the psymtabs and
1639 read in another symtab if necessary. Backward compatibility, no section */
1642 find_pc_symtab (CORE_ADDR pc
)
1644 return find_pc_sect_symtab (pc
, find_pc_mapped_section (pc
));
1650 /* Find the closest symbol value (of any sort -- function or variable)
1651 for a given address value. Slow but complete. (currently unused,
1652 mainly because it is too slow. We could fix it if each symtab and
1653 psymtab had contained in it the addresses ranges of each of its
1654 sections, which also would be required to make things like "info
1655 line *0x2345" cause psymtabs to be converted to symtabs). */
1658 find_addr_symbol (CORE_ADDR addr
, struct symtab
**symtabp
, CORE_ADDR
*symaddrp
)
1660 struct symtab
*symtab
, *best_symtab
;
1661 struct objfile
*objfile
;
1662 register int bot
, top
;
1663 register struct symbol
*sym
;
1664 register CORE_ADDR sym_addr
;
1665 struct block
*block
;
1668 /* Info on best symbol seen so far */
1670 register CORE_ADDR best_sym_addr
= 0;
1671 struct symbol
*best_sym
= 0;
1673 /* FIXME -- we should pull in all the psymtabs, too! */
1674 ALL_SYMTABS (objfile
, symtab
)
1676 /* Search the global and static blocks in this symtab for
1677 the closest symbol-address to the desired address. */
1679 for (blocknum
= GLOBAL_BLOCK
; blocknum
<= STATIC_BLOCK
; blocknum
++)
1682 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab
), blocknum
);
1683 ALL_BLOCK_SYMBOLS (block
, bot
, sym
)
1685 switch (SYMBOL_CLASS (sym
))
1689 sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1693 sym_addr
= SYMBOL_VALUE_ADDRESS (sym
);
1694 /* An indirect symbol really lives at *sym_addr,
1695 * so an indirection needs to be done.
1696 * However, I am leaving this commented out because it's
1697 * expensive, and it's possible that symbolization
1698 * could be done without an active process (in
1699 * case this read_memory will fail). RT
1700 sym_addr = read_memory_unsigned_integer
1701 (sym_addr, TARGET_PTR_BIT / TARGET_CHAR_BIT);
1706 sym_addr
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
1713 if (sym_addr
<= addr
)
1714 if (sym_addr
> best_sym_addr
)
1716 /* Quit if we found an exact match. */
1718 best_sym_addr
= sym_addr
;
1719 best_symtab
= symtab
;
1720 if (sym_addr
== addr
)
1729 *symtabp
= best_symtab
;
1731 *symaddrp
= best_sym_addr
;
1736 /* Find the source file and line number for a given PC value and SECTION.
1737 Return a structure containing a symtab pointer, a line number,
1738 and a pc range for the entire source line.
1739 The value's .pc field is NOT the specified pc.
1740 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1741 use the line that ends there. Otherwise, in that case, the line
1742 that begins there is used. */
1744 /* The big complication here is that a line may start in one file, and end just
1745 before the start of another file. This usually occurs when you #include
1746 code in the middle of a subroutine. To properly find the end of a line's PC
1747 range, we must search all symtabs associated with this compilation unit, and
1748 find the one whose first PC is closer than that of the next line in this
1751 /* If it's worth the effort, we could be using a binary search. */
1753 struct symtab_and_line
1754 find_pc_sect_line (CORE_ADDR pc
, struct sec
*section
, int notcurrent
)
1757 register struct linetable
*l
;
1760 register struct linetable_entry
*item
;
1761 struct symtab_and_line val
;
1762 struct blockvector
*bv
;
1763 struct minimal_symbol
*msymbol
;
1764 struct minimal_symbol
*mfunsym
;
1766 /* Info on best line seen so far, and where it starts, and its file. */
1768 struct linetable_entry
*best
= NULL
;
1769 CORE_ADDR best_end
= 0;
1770 struct symtab
*best_symtab
= 0;
1772 /* Store here the first line number
1773 of a file which contains the line at the smallest pc after PC.
1774 If we don't find a line whose range contains PC,
1775 we will use a line one less than this,
1776 with a range from the start of that file to the first line's pc. */
1777 struct linetable_entry
*alt
= NULL
;
1778 struct symtab
*alt_symtab
= 0;
1780 /* Info on best line seen in this file. */
1782 struct linetable_entry
*prev
;
1784 /* If this pc is not from the current frame,
1785 it is the address of the end of a call instruction.
1786 Quite likely that is the start of the following statement.
1787 But what we want is the statement containing the instruction.
1788 Fudge the pc to make sure we get that. */
1790 INIT_SAL (&val
); /* initialize to zeroes */
1792 /* It's tempting to assume that, if we can't find debugging info for
1793 any function enclosing PC, that we shouldn't search for line
1794 number info, either. However, GAS can emit line number info for
1795 assembly files --- very helpful when debugging hand-written
1796 assembly code. In such a case, we'd have no debug info for the
1797 function, but we would have line info. */
1802 /* elz: added this because this function returned the wrong
1803 information if the pc belongs to a stub (import/export)
1804 to call a shlib function. This stub would be anywhere between
1805 two functions in the target, and the line info was erroneously
1806 taken to be the one of the line before the pc.
1808 /* RT: Further explanation:
1810 * We have stubs (trampolines) inserted between procedures.
1812 * Example: "shr1" exists in a shared library, and a "shr1" stub also
1813 * exists in the main image.
1815 * In the minimal symbol table, we have a bunch of symbols
1816 * sorted by start address. The stubs are marked as "trampoline",
1817 * the others appear as text. E.g.:
1819 * Minimal symbol table for main image
1820 * main: code for main (text symbol)
1821 * shr1: stub (trampoline symbol)
1822 * foo: code for foo (text symbol)
1824 * Minimal symbol table for "shr1" image:
1826 * shr1: code for shr1 (text symbol)
1829 * So the code below is trying to detect if we are in the stub
1830 * ("shr1" stub), and if so, find the real code ("shr1" trampoline),
1831 * and if found, do the symbolization from the real-code address
1832 * rather than the stub address.
1834 * Assumptions being made about the minimal symbol table:
1835 * 1. lookup_minimal_symbol_by_pc() will return a trampoline only
1836 * if we're really in the trampoline. If we're beyond it (say
1837 * we're in "foo" in the above example), it'll have a closer
1838 * symbol (the "foo" text symbol for example) and will not
1839 * return the trampoline.
1840 * 2. lookup_minimal_symbol_text() will find a real text symbol
1841 * corresponding to the trampoline, and whose address will
1842 * be different than the trampoline address. I put in a sanity
1843 * check for the address being the same, to avoid an
1844 * infinite recursion.
1846 msymbol
= lookup_minimal_symbol_by_pc (pc
);
1847 if (msymbol
!= NULL
)
1848 if (MSYMBOL_TYPE (msymbol
) == mst_solib_trampoline
)
1850 mfunsym
= lookup_minimal_symbol_text (SYMBOL_NAME (msymbol
), NULL
, NULL
);
1851 if (mfunsym
== NULL
)
1852 /* I eliminated this warning since it is coming out
1853 * in the following situation:
1854 * gdb shmain // test program with shared libraries
1855 * (gdb) break shr1 // function in shared lib
1856 * Warning: In stub for ...
1857 * In the above situation, the shared lib is not loaded yet,
1858 * so of course we can't find the real func/line info,
1859 * but the "break" still works, and the warning is annoying.
1860 * So I commented out the warning. RT */
1861 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_NAME(msymbol)) */ ;
1863 else if (SYMBOL_VALUE (mfunsym
) == SYMBOL_VALUE (msymbol
))
1864 /* Avoid infinite recursion */
1865 /* See above comment about why warning is commented out */
1866 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_NAME(msymbol)) */ ;
1869 return find_pc_line (SYMBOL_VALUE (mfunsym
), 0);
1873 s
= find_pc_sect_symtab (pc
, section
);
1876 /* if no symbol information, return previous pc */
1883 bv
= BLOCKVECTOR (s
);
1885 /* Look at all the symtabs that share this blockvector.
1886 They all have the same apriori range, that we found was right;
1887 but they have different line tables. */
1889 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
1891 /* Find the best line in this symtab. */
1898 /* I think len can be zero if the symtab lacks line numbers
1899 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
1900 I'm not sure which, and maybe it depends on the symbol
1906 item
= l
->item
; /* Get first line info */
1908 /* Is this file's first line closer than the first lines of other files?
1909 If so, record this file, and its first line, as best alternate. */
1910 if (item
->pc
> pc
&& (!alt
|| item
->pc
< alt
->pc
))
1916 for (i
= 0; i
< len
; i
++, item
++)
1918 /* Leave prev pointing to the linetable entry for the last line
1919 that started at or before PC. */
1926 /* At this point, prev points at the line whose start addr is <= pc, and
1927 item points at the next line. If we ran off the end of the linetable
1928 (pc >= start of the last line), then prev == item. If pc < start of
1929 the first line, prev will not be set. */
1931 /* Is this file's best line closer than the best in the other files?
1932 If so, record this file, and its best line, as best so far. */
1934 if (prev
&& (!best
|| prev
->pc
> best
->pc
))
1939 /* Discard BEST_END if it's before the PC of the current BEST. */
1940 if (best_end
<= best
->pc
)
1944 /* If another line (denoted by ITEM) is in the linetable and its
1945 PC is after BEST's PC, but before the current BEST_END, then
1946 use ITEM's PC as the new best_end. */
1947 if (best
&& i
< len
&& item
->pc
> best
->pc
1948 && (best_end
== 0 || best_end
> item
->pc
))
1949 best_end
= item
->pc
;
1955 { /* If we didn't find any line # info, just
1961 val
.symtab
= alt_symtab
;
1962 val
.line
= alt
->line
- 1;
1964 /* Don't return line 0, that means that we didn't find the line. */
1968 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1972 else if (best
->line
== 0)
1974 /* If our best fit is in a range of PC's for which no line
1975 number info is available (line number is zero) then we didn't
1976 find any valid line information. */
1981 val
.symtab
= best_symtab
;
1982 val
.line
= best
->line
;
1984 if (best_end
&& (!alt
|| best_end
< alt
->pc
))
1989 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
1991 val
.section
= section
;
1995 /* Backward compatibility (no section) */
1997 struct symtab_and_line
1998 find_pc_line (CORE_ADDR pc
, int notcurrent
)
2002 section
= find_pc_overlay (pc
);
2003 if (pc_in_unmapped_range (pc
, section
))
2004 pc
= overlay_mapped_address (pc
, section
);
2005 return find_pc_sect_line (pc
, section
, notcurrent
);
2008 /* Find line number LINE in any symtab whose name is the same as
2011 If found, return the symtab that contains the linetable in which it was
2012 found, set *INDEX to the index in the linetable of the best entry
2013 found, and set *EXACT_MATCH nonzero if the value returned is an
2016 If not found, return NULL. */
2019 find_line_symtab (struct symtab
*symtab
, int line
, int *index
, int *exact_match
)
2023 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
2027 struct linetable
*best_linetable
;
2028 struct symtab
*best_symtab
;
2030 /* First try looking it up in the given symtab. */
2031 best_linetable
= LINETABLE (symtab
);
2032 best_symtab
= symtab
;
2033 best_index
= find_line_common (best_linetable
, line
, &exact
);
2034 if (best_index
< 0 || !exact
)
2036 /* Didn't find an exact match. So we better keep looking for
2037 another symtab with the same name. In the case of xcoff,
2038 multiple csects for one source file (produced by IBM's FORTRAN
2039 compiler) produce multiple symtabs (this is unavoidable
2040 assuming csects can be at arbitrary places in memory and that
2041 the GLOBAL_BLOCK of a symtab has a begin and end address). */
2043 /* BEST is the smallest linenumber > LINE so far seen,
2044 or 0 if none has been seen so far.
2045 BEST_INDEX and BEST_LINETABLE identify the item for it. */
2048 struct objfile
*objfile
;
2051 if (best_index
>= 0)
2052 best
= best_linetable
->item
[best_index
].line
;
2056 ALL_SYMTABS (objfile
, s
)
2058 struct linetable
*l
;
2061 if (!STREQ (symtab
->filename
, s
->filename
))
2064 ind
= find_line_common (l
, line
, &exact
);
2074 if (best
== 0 || l
->item
[ind
].line
< best
)
2076 best
= l
->item
[ind
].line
;
2089 *index
= best_index
;
2091 *exact_match
= exact
;
2096 /* Set the PC value for a given source file and line number and return true.
2097 Returns zero for invalid line number (and sets the PC to 0).
2098 The source file is specified with a struct symtab. */
2101 find_line_pc (struct symtab
*symtab
, int line
, CORE_ADDR
*pc
)
2103 struct linetable
*l
;
2110 symtab
= find_line_symtab (symtab
, line
, &ind
, NULL
);
2113 l
= LINETABLE (symtab
);
2114 *pc
= l
->item
[ind
].pc
;
2121 /* Find the range of pc values in a line.
2122 Store the starting pc of the line into *STARTPTR
2123 and the ending pc (start of next line) into *ENDPTR.
2124 Returns 1 to indicate success.
2125 Returns 0 if could not find the specified line. */
2128 find_line_pc_range (struct symtab_and_line sal
, CORE_ADDR
*startptr
,
2131 CORE_ADDR startaddr
;
2132 struct symtab_and_line found_sal
;
2135 if (startaddr
== 0 && !find_line_pc (sal
.symtab
, sal
.line
, &startaddr
))
2138 /* This whole function is based on address. For example, if line 10 has
2139 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
2140 "info line *0x123" should say the line goes from 0x100 to 0x200
2141 and "info line *0x355" should say the line goes from 0x300 to 0x400.
2142 This also insures that we never give a range like "starts at 0x134
2143 and ends at 0x12c". */
2145 found_sal
= find_pc_sect_line (startaddr
, sal
.section
, 0);
2146 if (found_sal
.line
!= sal
.line
)
2148 /* The specified line (sal) has zero bytes. */
2149 *startptr
= found_sal
.pc
;
2150 *endptr
= found_sal
.pc
;
2154 *startptr
= found_sal
.pc
;
2155 *endptr
= found_sal
.end
;
2160 /* Given a line table and a line number, return the index into the line
2161 table for the pc of the nearest line whose number is >= the specified one.
2162 Return -1 if none is found. The value is >= 0 if it is an index.
2164 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
2167 find_line_common (register struct linetable
*l
, register int lineno
,
2173 /* BEST is the smallest linenumber > LINENO so far seen,
2174 or 0 if none has been seen so far.
2175 BEST_INDEX identifies the item for it. */
2177 int best_index
= -1;
2186 for (i
= 0; i
< len
; i
++)
2188 register struct linetable_entry
*item
= &(l
->item
[i
]);
2190 if (item
->line
== lineno
)
2192 /* Return the first (lowest address) entry which matches. */
2197 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
2204 /* If we got here, we didn't get an exact match. */
2211 find_pc_line_pc_range (CORE_ADDR pc
, CORE_ADDR
*startptr
, CORE_ADDR
*endptr
)
2213 struct symtab_and_line sal
;
2214 sal
= find_pc_line (pc
, 0);
2217 return sal
.symtab
!= 0;
2220 /* Given a function symbol SYM, find the symtab and line for the start
2222 If the argument FUNFIRSTLINE is nonzero, we want the first line
2223 of real code inside the function. */
2225 struct symtab_and_line
2226 find_function_start_sal (struct symbol
*sym
, int funfirstline
)
2229 struct symtab_and_line sal
;
2231 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
2232 fixup_symbol_section (sym
, NULL
);
2234 { /* skip "first line" of function (which is actually its prologue) */
2235 asection
*section
= SYMBOL_BFD_SECTION (sym
);
2236 /* If function is in an unmapped overlay, use its unmapped LMA
2237 address, so that SKIP_PROLOGUE has something unique to work on */
2238 if (section_is_overlay (section
) &&
2239 !section_is_mapped (section
))
2240 pc
= overlay_unmapped_address (pc
, section
);
2242 pc
+= FUNCTION_START_OFFSET
;
2243 pc
= SKIP_PROLOGUE (pc
);
2245 /* For overlays, map pc back into its mapped VMA range */
2246 pc
= overlay_mapped_address (pc
, section
);
2248 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
2250 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2251 /* Convex: no need to suppress code on first line, if any */
2254 /* Check if SKIP_PROLOGUE left us in mid-line, and the next
2255 line is still part of the same function. */
2257 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) <= sal
.end
2258 && sal
.end
< BLOCK_END (SYMBOL_BLOCK_VALUE (sym
)))
2260 /* First pc of next line */
2262 /* Recalculate the line number (might not be N+1). */
2263 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
2271 /* If P is of the form "operator[ \t]+..." where `...' is
2272 some legitimate operator text, return a pointer to the
2273 beginning of the substring of the operator text.
2274 Otherwise, return "". */
2276 operator_chars (char *p
, char **end
)
2279 if (strncmp (p
, "operator", 8))
2283 /* Don't get faked out by `operator' being part of a longer
2285 if (isalpha (*p
) || *p
== '_' || *p
== '$' || *p
== '\0')
2288 /* Allow some whitespace between `operator' and the operator symbol. */
2289 while (*p
== ' ' || *p
== '\t')
2292 /* Recognize 'operator TYPENAME'. */
2294 if (isalpha (*p
) || *p
== '_' || *p
== '$')
2296 register char *q
= p
+ 1;
2297 while (isalnum (*q
) || *q
== '_' || *q
== '$')
2306 case '\\': /* regexp quoting */
2309 if (p
[2] == '=') /* 'operator\*=' */
2311 else /* 'operator\*' */
2315 else if (p
[1] == '[')
2318 error ("mismatched quoting on brackets, try 'operator\\[\\]'");
2319 else if (p
[2] == '\\' && p
[3] == ']')
2321 *end
= p
+ 4; /* 'operator\[\]' */
2325 error ("nothing is allowed between '[' and ']'");
2329 /* Gratuitous qoute: skip it and move on. */
2351 if (p
[0] == '-' && p
[1] == '>')
2353 /* Struct pointer member operator 'operator->'. */
2356 *end
= p
+ 3; /* 'operator->*' */
2359 else if (p
[2] == '\\')
2361 *end
= p
+ 4; /* Hopefully 'operator->\*' */
2366 *end
= p
+ 2; /* 'operator->' */
2370 if (p
[1] == '=' || p
[1] == p
[0])
2381 error ("`operator ()' must be specified without whitespace in `()'");
2386 error ("`operator ?:' must be specified without whitespace in `?:'");
2391 error ("`operator []' must be specified without whitespace in `[]'");
2395 error ("`operator %s' not supported", p
);
2404 /* If FILE is not already in the table of files, return zero;
2405 otherwise return non-zero. Optionally add FILE to the table if ADD
2406 is non-zero. If *FIRST is non-zero, forget the old table
2409 filename_seen (const char *file
, int add
, int *first
)
2411 /* Table of files seen so far. */
2412 static const char **tab
= NULL
;
2413 /* Allocated size of tab in elements.
2414 Start with one 256-byte block (when using GNU malloc.c).
2415 24 is the malloc overhead when range checking is in effect. */
2416 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
2417 /* Current size of tab in elements. */
2418 static int tab_cur_size
;
2424 tab
= (const char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
2428 /* Is FILE in tab? */
2429 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
2430 if (strcmp (*p
, file
) == 0)
2433 /* No; maybe add it to tab. */
2436 if (tab_cur_size
== tab_alloc_size
)
2438 tab_alloc_size
*= 2;
2439 tab
= (const char **) xrealloc ((char *) tab
,
2440 tab_alloc_size
* sizeof (*tab
));
2442 tab
[tab_cur_size
++] = file
;
2448 /* Slave routine for sources_info. Force line breaks at ,'s.
2449 NAME is the name to print and *FIRST is nonzero if this is the first
2450 name printed. Set *FIRST to zero. */
2452 output_source_filename (char *name
, int *first
)
2454 /* Since a single source file can result in several partial symbol
2455 tables, we need to avoid printing it more than once. Note: if
2456 some of the psymtabs are read in and some are not, it gets
2457 printed both under "Source files for which symbols have been
2458 read" and "Source files for which symbols will be read in on
2459 demand". I consider this a reasonable way to deal with the
2460 situation. I'm not sure whether this can also happen for
2461 symtabs; it doesn't hurt to check. */
2463 /* Was NAME already seen? */
2464 if (filename_seen (name
, 1, first
))
2466 /* Yes; don't print it again. */
2469 /* No; print it and reset *FIRST. */
2476 printf_filtered (", ");
2480 fputs_filtered (name
, gdb_stdout
);
2484 sources_info (char *ignore
, int from_tty
)
2486 register struct symtab
*s
;
2487 register struct partial_symtab
*ps
;
2488 register struct objfile
*objfile
;
2491 if (!have_full_symbols () && !have_partial_symbols ())
2493 error ("No symbol table is loaded. Use the \"file\" command.");
2496 printf_filtered ("Source files for which symbols have been read in:\n\n");
2499 ALL_SYMTABS (objfile
, s
)
2501 output_source_filename (s
->filename
, &first
);
2503 printf_filtered ("\n\n");
2505 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2508 ALL_PSYMTABS (objfile
, ps
)
2512 output_source_filename (ps
->filename
, &first
);
2515 printf_filtered ("\n");
2519 file_matches (char *file
, char *files
[], int nfiles
)
2523 if (file
!= NULL
&& nfiles
!= 0)
2525 for (i
= 0; i
< nfiles
; i
++)
2527 if (strcmp (files
[i
], lbasename (file
)) == 0)
2531 else if (nfiles
== 0)
2536 /* Free any memory associated with a search. */
2538 free_search_symbols (struct symbol_search
*symbols
)
2540 struct symbol_search
*p
;
2541 struct symbol_search
*next
;
2543 for (p
= symbols
; p
!= NULL
; p
= next
)
2551 do_free_search_symbols_cleanup (void *symbols
)
2553 free_search_symbols (symbols
);
2557 make_cleanup_free_search_symbols (struct symbol_search
*symbols
)
2559 return make_cleanup (do_free_search_symbols_cleanup
, symbols
);
2562 /* Helper function for sort_search_symbols and qsort. Can only
2563 sort symbols, not minimal symbols. */
2565 compare_search_syms (const void *sa
, const void *sb
)
2567 struct symbol_search
**sym_a
= (struct symbol_search
**) sa
;
2568 struct symbol_search
**sym_b
= (struct symbol_search
**) sb
;
2570 return strcmp (SYMBOL_SOURCE_NAME ((*sym_a
)->symbol
),
2571 SYMBOL_SOURCE_NAME ((*sym_b
)->symbol
));
2574 /* Sort the ``nfound'' symbols in the list after prevtail. Leave
2575 prevtail where it is, but update its next pointer to point to
2576 the first of the sorted symbols. */
2577 static struct symbol_search
*
2578 sort_search_symbols (struct symbol_search
*prevtail
, int nfound
)
2580 struct symbol_search
**symbols
, *symp
, *old_next
;
2583 symbols
= (struct symbol_search
**) xmalloc (sizeof (struct symbol_search
*)
2585 symp
= prevtail
->next
;
2586 for (i
= 0; i
< nfound
; i
++)
2591 /* Generally NULL. */
2594 qsort (symbols
, nfound
, sizeof (struct symbol_search
*),
2595 compare_search_syms
);
2598 for (i
= 0; i
< nfound
; i
++)
2600 symp
->next
= symbols
[i
];
2603 symp
->next
= old_next
;
2609 /* Search the symbol table for matches to the regular expression REGEXP,
2610 returning the results in *MATCHES.
2612 Only symbols of KIND are searched:
2613 FUNCTIONS_NAMESPACE - search all functions
2614 TYPES_NAMESPACE - search all type names
2615 METHODS_NAMESPACE - search all methods NOT IMPLEMENTED
2616 VARIABLES_NAMESPACE - search all symbols, excluding functions, type names,
2617 and constants (enums)
2619 free_search_symbols should be called when *MATCHES is no longer needed.
2621 The results are sorted locally; each symtab's global and static blocks are
2622 separately alphabetized.
2625 search_symbols (char *regexp
, namespace_enum kind
, int nfiles
, char *files
[],
2626 struct symbol_search
**matches
)
2628 register struct symtab
*s
;
2629 register struct partial_symtab
*ps
;
2630 register struct blockvector
*bv
;
2631 struct blockvector
*prev_bv
= 0;
2632 register struct block
*b
;
2635 register struct symbol
*sym
;
2636 struct partial_symbol
**psym
;
2637 struct objfile
*objfile
;
2638 struct minimal_symbol
*msymbol
;
2641 static enum minimal_symbol_type types
[]
2643 {mst_data
, mst_text
, mst_abs
, mst_unknown
};
2644 static enum minimal_symbol_type types2
[]
2646 {mst_bss
, mst_file_text
, mst_abs
, mst_unknown
};
2647 static enum minimal_symbol_type types3
[]
2649 {mst_file_data
, mst_solib_trampoline
, mst_abs
, mst_unknown
};
2650 static enum minimal_symbol_type types4
[]
2652 {mst_file_bss
, mst_text
, mst_abs
, mst_unknown
};
2653 enum minimal_symbol_type ourtype
;
2654 enum minimal_symbol_type ourtype2
;
2655 enum minimal_symbol_type ourtype3
;
2656 enum minimal_symbol_type ourtype4
;
2657 struct symbol_search
*sr
;
2658 struct symbol_search
*psr
;
2659 struct symbol_search
*tail
;
2660 struct cleanup
*old_chain
= NULL
;
2662 if (kind
< VARIABLES_NAMESPACE
)
2663 error ("must search on specific namespace");
2665 ourtype
= types
[(int) (kind
- VARIABLES_NAMESPACE
)];
2666 ourtype2
= types2
[(int) (kind
- VARIABLES_NAMESPACE
)];
2667 ourtype3
= types3
[(int) (kind
- VARIABLES_NAMESPACE
)];
2668 ourtype4
= types4
[(int) (kind
- VARIABLES_NAMESPACE
)];
2670 sr
= *matches
= NULL
;
2675 /* Make sure spacing is right for C++ operators.
2676 This is just a courtesy to make the matching less sensitive
2677 to how many spaces the user leaves between 'operator'
2678 and <TYPENAME> or <OPERATOR>. */
2680 char *opname
= operator_chars (regexp
, &opend
);
2683 int fix
= -1; /* -1 means ok; otherwise number of spaces needed. */
2684 if (isalpha (*opname
) || *opname
== '_' || *opname
== '$')
2686 /* There should 1 space between 'operator' and 'TYPENAME'. */
2687 if (opname
[-1] != ' ' || opname
[-2] == ' ')
2692 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2693 if (opname
[-1] == ' ')
2696 /* If wrong number of spaces, fix it. */
2699 char *tmp
= (char *) alloca (8 + fix
+ strlen (opname
) + 1);
2700 sprintf (tmp
, "operator%.*s%s", fix
, " ", opname
);
2705 if (0 != (val
= re_comp (regexp
)))
2706 error ("Invalid regexp (%s): %s", val
, regexp
);
2709 /* Search through the partial symtabs *first* for all symbols
2710 matching the regexp. That way we don't have to reproduce all of
2711 the machinery below. */
2713 ALL_PSYMTABS (objfile
, ps
)
2715 struct partial_symbol
**bound
, **gbound
, **sbound
;
2721 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2722 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2725 /* Go through all of the symbols stored in a partial
2726 symtab in one loop. */
2727 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2732 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2734 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2745 /* If it would match (logic taken from loop below)
2746 load the file and go on to the next one */
2747 if (file_matches (ps
->filename
, files
, nfiles
)
2748 && ((regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (*psym
))
2749 && ((kind
== VARIABLES_NAMESPACE
&& SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
2750 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
2751 || (kind
== FUNCTIONS_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
2752 || (kind
== TYPES_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
)
2753 || (kind
== METHODS_NAMESPACE
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
))))
2755 PSYMTAB_TO_SYMTAB (ps
);
2763 /* Here, we search through the minimal symbol tables for functions
2764 and variables that match, and force their symbols to be read.
2765 This is in particular necessary for demangled variable names,
2766 which are no longer put into the partial symbol tables.
2767 The symbol will then be found during the scan of symtabs below.
2769 For functions, find_pc_symtab should succeed if we have debug info
2770 for the function, for variables we have to call lookup_symbol
2771 to determine if the variable has debug info.
2772 If the lookup fails, set found_misc so that we will rescan to print
2773 any matching symbols without debug info.
2776 if (nfiles
== 0 && (kind
== VARIABLES_NAMESPACE
|| kind
== FUNCTIONS_NAMESPACE
))
2778 ALL_MSYMBOLS (objfile
, msymbol
)
2780 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
2781 MSYMBOL_TYPE (msymbol
) == ourtype2
||
2782 MSYMBOL_TYPE (msymbol
) == ourtype3
||
2783 MSYMBOL_TYPE (msymbol
) == ourtype4
)
2785 if (regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (msymbol
))
2787 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
)))
2789 if (kind
== FUNCTIONS_NAMESPACE
2790 || lookup_symbol (SYMBOL_NAME (msymbol
),
2791 (struct block
*) NULL
,
2793 0, (struct symtab
**) NULL
) == NULL
)
2801 ALL_SYMTABS (objfile
, s
)
2803 bv
= BLOCKVECTOR (s
);
2804 /* Often many files share a blockvector.
2805 Scan each blockvector only once so that
2806 we don't get every symbol many times.
2807 It happens that the first symtab in the list
2808 for any given blockvector is the main file. */
2810 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
2812 struct symbol_search
*prevtail
= tail
;
2814 b
= BLOCKVECTOR_BLOCK (bv
, i
);
2815 ALL_BLOCK_SYMBOLS (b
, j
, sym
)
2818 if (file_matches (s
->filename
, files
, nfiles
)
2819 && ((regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (sym
))
2820 && ((kind
== VARIABLES_NAMESPACE
&& SYMBOL_CLASS (sym
) != LOC_TYPEDEF
2821 && SYMBOL_CLASS (sym
) != LOC_BLOCK
2822 && SYMBOL_CLASS (sym
) != LOC_CONST
)
2823 || (kind
== FUNCTIONS_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2824 || (kind
== TYPES_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
2825 || (kind
== METHODS_NAMESPACE
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
))))
2828 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
2832 psr
->msymbol
= NULL
;
2844 if (prevtail
== NULL
)
2846 struct symbol_search dummy
;
2849 tail
= sort_search_symbols (&dummy
, nfound
);
2852 old_chain
= make_cleanup_free_search_symbols (sr
);
2855 tail
= sort_search_symbols (prevtail
, nfound
);
2861 /* If there are no eyes, avoid all contact. I mean, if there are
2862 no debug symbols, then print directly from the msymbol_vector. */
2864 if (found_misc
|| kind
!= FUNCTIONS_NAMESPACE
)
2866 ALL_MSYMBOLS (objfile
, msymbol
)
2868 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
2869 MSYMBOL_TYPE (msymbol
) == ourtype2
||
2870 MSYMBOL_TYPE (msymbol
) == ourtype3
||
2871 MSYMBOL_TYPE (msymbol
) == ourtype4
)
2873 if (regexp
== NULL
|| SYMBOL_MATCHES_REGEXP (msymbol
))
2875 /* Functions: Look up by address. */
2876 if (kind
!= FUNCTIONS_NAMESPACE
||
2877 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
))))
2879 /* Variables/Absolutes: Look up by name */
2880 if (lookup_symbol (SYMBOL_NAME (msymbol
),
2881 (struct block
*) NULL
, VAR_NAMESPACE
,
2882 0, (struct symtab
**) NULL
) == NULL
)
2885 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
2887 psr
->msymbol
= msymbol
;
2894 old_chain
= make_cleanup_free_search_symbols (sr
);
2908 discard_cleanups (old_chain
);
2911 /* Helper function for symtab_symbol_info, this function uses
2912 the data returned from search_symbols() to print information
2913 regarding the match to gdb_stdout.
2916 print_symbol_info (namespace_enum kind
, struct symtab
*s
, struct symbol
*sym
,
2917 int block
, char *last
)
2919 if (last
== NULL
|| strcmp (last
, s
->filename
) != 0)
2921 fputs_filtered ("\nFile ", gdb_stdout
);
2922 fputs_filtered (s
->filename
, gdb_stdout
);
2923 fputs_filtered (":\n", gdb_stdout
);
2926 if (kind
!= TYPES_NAMESPACE
&& block
== STATIC_BLOCK
)
2927 printf_filtered ("static ");
2929 /* Typedef that is not a C++ class */
2930 if (kind
== TYPES_NAMESPACE
2931 && SYMBOL_NAMESPACE (sym
) != STRUCT_NAMESPACE
)
2932 typedef_print (SYMBOL_TYPE (sym
), sym
, gdb_stdout
);
2933 /* variable, func, or typedef-that-is-c++-class */
2934 else if (kind
< TYPES_NAMESPACE
||
2935 (kind
== TYPES_NAMESPACE
&&
2936 SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
))
2938 type_print (SYMBOL_TYPE (sym
),
2939 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2940 ? "" : SYMBOL_SOURCE_NAME (sym
)),
2943 printf_filtered (";\n");
2948 /* Tiemann says: "info methods was never implemented." */
2949 char *demangled_name
;
2950 c_type_print_base (TYPE_FN_FIELD_TYPE (t
, block
),
2952 c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (t
, block
),
2954 if (TYPE_FN_FIELD_STUB (t
, block
))
2955 check_stub_method (TYPE_DOMAIN_TYPE (type
), j
, block
);
2957 cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t
, block
),
2958 DMGL_ANSI
| DMGL_PARAMS
);
2959 if (demangled_name
== NULL
)
2960 fprintf_filtered (stream
, "<badly mangled name %s>",
2961 TYPE_FN_FIELD_PHYSNAME (t
, block
));
2964 fputs_filtered (demangled_name
, stream
);
2965 xfree (demangled_name
);
2971 /* This help function for symtab_symbol_info() prints information
2972 for non-debugging symbols to gdb_stdout.
2975 print_msymbol_info (struct minimal_symbol
*msymbol
)
2979 if (TARGET_ADDR_BIT
<= 32)
2980 tmp
= local_hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol
)
2981 & (CORE_ADDR
) 0xffffffff,
2984 tmp
= local_hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol
),
2986 printf_filtered ("%s %s\n",
2987 tmp
, SYMBOL_SOURCE_NAME (msymbol
));
2990 /* This is the guts of the commands "info functions", "info types", and
2991 "info variables". It calls search_symbols to find all matches and then
2992 print_[m]symbol_info to print out some useful information about the
2996 symtab_symbol_info (char *regexp
, namespace_enum kind
, int from_tty
)
2998 static char *classnames
[]
3000 {"variable", "function", "type", "method"};
3001 struct symbol_search
*symbols
;
3002 struct symbol_search
*p
;
3003 struct cleanup
*old_chain
;
3004 char *last_filename
= NULL
;
3007 /* must make sure that if we're interrupted, symbols gets freed */
3008 search_symbols (regexp
, kind
, 0, (char **) NULL
, &symbols
);
3009 old_chain
= make_cleanup_free_search_symbols (symbols
);
3011 printf_filtered (regexp
3012 ? "All %ss matching regular expression \"%s\":\n"
3013 : "All defined %ss:\n",
3014 classnames
[(int) (kind
- VARIABLES_NAMESPACE
)], regexp
);
3016 for (p
= symbols
; p
!= NULL
; p
= p
->next
)
3020 if (p
->msymbol
!= NULL
)
3024 printf_filtered ("\nNon-debugging symbols:\n");
3027 print_msymbol_info (p
->msymbol
);
3031 print_symbol_info (kind
,
3036 last_filename
= p
->symtab
->filename
;
3040 do_cleanups (old_chain
);
3044 variables_info (char *regexp
, int from_tty
)
3046 symtab_symbol_info (regexp
, VARIABLES_NAMESPACE
, from_tty
);
3050 functions_info (char *regexp
, int from_tty
)
3052 symtab_symbol_info (regexp
, FUNCTIONS_NAMESPACE
, from_tty
);
3057 types_info (char *regexp
, int from_tty
)
3059 symtab_symbol_info (regexp
, TYPES_NAMESPACE
, from_tty
);
3063 /* Tiemann says: "info methods was never implemented." */
3065 methods_info (char *regexp
)
3067 symtab_symbol_info (regexp
, METHODS_NAMESPACE
, 0, from_tty
);
3071 /* Breakpoint all functions matching regular expression. */
3074 rbreak_command_wrapper (char *regexp
, int from_tty
)
3076 rbreak_command (regexp
, from_tty
);
3080 rbreak_command (char *regexp
, int from_tty
)
3082 struct symbol_search
*ss
;
3083 struct symbol_search
*p
;
3084 struct cleanup
*old_chain
;
3086 search_symbols (regexp
, FUNCTIONS_NAMESPACE
, 0, (char **) NULL
, &ss
);
3087 old_chain
= make_cleanup_free_search_symbols (ss
);
3089 for (p
= ss
; p
!= NULL
; p
= p
->next
)
3091 if (p
->msymbol
== NULL
)
3093 char *string
= (char *) alloca (strlen (p
->symtab
->filename
)
3094 + strlen (SYMBOL_NAME (p
->symbol
))
3096 strcpy (string
, p
->symtab
->filename
);
3097 strcat (string
, ":'");
3098 strcat (string
, SYMBOL_NAME (p
->symbol
));
3099 strcat (string
, "'");
3100 break_command (string
, from_tty
);
3101 print_symbol_info (FUNCTIONS_NAMESPACE
,
3105 p
->symtab
->filename
);
3109 break_command (SYMBOL_NAME (p
->msymbol
), from_tty
);
3110 printf_filtered ("<function, no debug info> %s;\n",
3111 SYMBOL_SOURCE_NAME (p
->msymbol
));
3115 do_cleanups (old_chain
);
3119 /* Return Nonzero if block a is lexically nested within block b,
3120 or if a and b have the same pc range.
3121 Return zero otherwise. */
3123 contained_in (struct block
*a
, struct block
*b
)
3127 return BLOCK_START (a
) >= BLOCK_START (b
)
3128 && BLOCK_END (a
) <= BLOCK_END (b
);
3132 /* Helper routine for make_symbol_completion_list. */
3134 static int return_val_size
;
3135 static int return_val_index
;
3136 static char **return_val
;
3138 #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
3140 if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \
3141 /* Put only the mangled name on the list. */ \
3142 /* Advantage: "b foo<TAB>" completes to "b foo(int, int)" */ \
3143 /* Disadvantage: "b foo__i<TAB>" doesn't complete. */ \
3144 completion_list_add_name \
3145 (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \
3147 completion_list_add_name \
3148 (SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \
3151 /* Test to see if the symbol specified by SYMNAME (which is already
3152 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3153 characters. If so, add it to the current completion list. */
3156 completion_list_add_name (char *symname
, char *sym_text
, int sym_text_len
,
3157 char *text
, char *word
)
3162 /* clip symbols that cannot match */
3164 if (strncmp (symname
, sym_text
, sym_text_len
) != 0)
3169 /* We have a match for a completion, so add SYMNAME to the current list
3170 of matches. Note that the name is moved to freshly malloc'd space. */
3174 if (word
== sym_text
)
3176 new = xmalloc (strlen (symname
) + 5);
3177 strcpy (new, symname
);
3179 else if (word
> sym_text
)
3181 /* Return some portion of symname. */
3182 new = xmalloc (strlen (symname
) + 5);
3183 strcpy (new, symname
+ (word
- sym_text
));
3187 /* Return some of SYM_TEXT plus symname. */
3188 new = xmalloc (strlen (symname
) + (sym_text
- word
) + 5);
3189 strncpy (new, word
, sym_text
- word
);
3190 new[sym_text
- word
] = '\0';
3191 strcat (new, symname
);
3194 if (return_val_index
+ 3 > return_val_size
)
3196 newsize
= (return_val_size
*= 2) * sizeof (char *);
3197 return_val
= (char **) xrealloc ((char *) return_val
, newsize
);
3199 return_val
[return_val_index
++] = new;
3200 return_val
[return_val_index
] = NULL
;
3204 /* Return a NULL terminated array of all symbols (regardless of class)
3205 which begin by matching TEXT. If the answer is no symbols, then
3206 the return value is an array which contains only a NULL pointer.
3208 Problem: All of the symbols have to be copied because readline frees them.
3209 I'm not going to worry about this; hopefully there won't be that many. */
3212 make_symbol_completion_list (char *text
, char *word
)
3214 register struct symbol
*sym
;
3215 register struct symtab
*s
;
3216 register struct partial_symtab
*ps
;
3217 register struct minimal_symbol
*msymbol
;
3218 register struct objfile
*objfile
;
3219 register struct block
*b
, *surrounding_static_block
= 0;
3221 struct partial_symbol
**psym
;
3222 /* The symbol we are completing on. Points in same buffer as text. */
3224 /* Length of sym_text. */
3227 /* Now look for the symbol we are supposed to complete on.
3228 FIXME: This should be language-specific. */
3232 char *quote_pos
= NULL
;
3234 /* First see if this is a quoted string. */
3236 for (p
= text
; *p
!= '\0'; ++p
)
3238 if (quote_found
!= '\0')
3240 if (*p
== quote_found
)
3241 /* Found close quote. */
3243 else if (*p
== '\\' && p
[1] == quote_found
)
3244 /* A backslash followed by the quote character
3245 doesn't end the string. */
3248 else if (*p
== '\'' || *p
== '"')
3254 if (quote_found
== '\'')
3255 /* A string within single quotes can be a symbol, so complete on it. */
3256 sym_text
= quote_pos
+ 1;
3257 else if (quote_found
== '"')
3258 /* A double-quoted string is never a symbol, nor does it make sense
3259 to complete it any other way. */
3261 return_val
= (char **) xmalloc (sizeof (char *));
3262 return_val
[0] = NULL
;
3267 /* It is not a quoted string. Break it based on the characters
3268 which are in symbols. */
3271 if (isalnum (p
[-1]) || p
[-1] == '_' || p
[-1] == '\0')
3280 sym_text_len
= strlen (sym_text
);
3282 return_val_size
= 100;
3283 return_val_index
= 0;
3284 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
3285 return_val
[0] = NULL
;
3287 /* Look through the partial symtabs for all symbols which begin
3288 by matching SYM_TEXT. Add each one that you find to the list. */
3290 ALL_PSYMTABS (objfile
, ps
)
3292 /* If the psymtab's been read in we'll get it when we search
3293 through the blockvector. */
3297 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
3298 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
3299 + ps
->n_global_syms
);
3302 /* If interrupted, then quit. */
3304 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3307 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
3308 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
3309 + ps
->n_static_syms
);
3313 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3317 /* At this point scan through the misc symbol vectors and add each
3318 symbol you find to the list. Eventually we want to ignore
3319 anything that isn't a text symbol (everything else will be
3320 handled by the psymtab code above). */
3322 ALL_MSYMBOLS (objfile
, msymbol
)
3325 COMPLETION_LIST_ADD_SYMBOL (msymbol
, sym_text
, sym_text_len
, text
, word
);
3328 /* Search upwards from currently selected frame (so that we can
3329 complete on local vars. */
3331 for (b
= get_selected_block (0); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
3333 if (!BLOCK_SUPERBLOCK (b
))
3335 surrounding_static_block
= b
; /* For elmin of dups */
3338 /* Also catch fields of types defined in this places which match our
3339 text string. Only complete on types visible from current context. */
3341 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
3343 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3344 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3346 struct type
*t
= SYMBOL_TYPE (sym
);
3347 enum type_code c
= TYPE_CODE (t
);
3349 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
3351 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
3353 if (TYPE_FIELD_NAME (t
, j
))
3355 completion_list_add_name (TYPE_FIELD_NAME (t
, j
),
3356 sym_text
, sym_text_len
, text
, word
);
3364 /* Go through the symtabs and check the externs and statics for
3365 symbols which match. */
3367 ALL_SYMTABS (objfile
, s
)
3370 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3371 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
3373 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3377 ALL_SYMTABS (objfile
, s
)
3380 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3381 /* Don't do this block twice. */
3382 if (b
== surrounding_static_block
)
3384 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
3386 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3390 return (return_val
);
3393 /* Like make_symbol_completion_list, but returns a list of symbols
3394 defined in a source file FILE. */
3397 make_file_symbol_completion_list (char *text
, char *word
, char *srcfile
)
3399 register struct symbol
*sym
;
3400 register struct symtab
*s
;
3401 register struct block
*b
;
3403 /* The symbol we are completing on. Points in same buffer as text. */
3405 /* Length of sym_text. */
3408 /* Now look for the symbol we are supposed to complete on.
3409 FIXME: This should be language-specific. */
3413 char *quote_pos
= NULL
;
3415 /* First see if this is a quoted string. */
3417 for (p
= text
; *p
!= '\0'; ++p
)
3419 if (quote_found
!= '\0')
3421 if (*p
== quote_found
)
3422 /* Found close quote. */
3424 else if (*p
== '\\' && p
[1] == quote_found
)
3425 /* A backslash followed by the quote character
3426 doesn't end the string. */
3429 else if (*p
== '\'' || *p
== '"')
3435 if (quote_found
== '\'')
3436 /* A string within single quotes can be a symbol, so complete on it. */
3437 sym_text
= quote_pos
+ 1;
3438 else if (quote_found
== '"')
3439 /* A double-quoted string is never a symbol, nor does it make sense
3440 to complete it any other way. */
3442 return_val
= (char **) xmalloc (sizeof (char *));
3443 return_val
[0] = NULL
;
3448 /* It is not a quoted string. Break it based on the characters
3449 which are in symbols. */
3452 if (isalnum (p
[-1]) || p
[-1] == '_' || p
[-1] == '\0')
3461 sym_text_len
= strlen (sym_text
);
3463 return_val_size
= 10;
3464 return_val_index
= 0;
3465 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
3466 return_val
[0] = NULL
;
3468 /* Find the symtab for SRCFILE (this loads it if it was not yet read
3470 s
= lookup_symtab (srcfile
);
3473 /* Maybe they typed the file with leading directories, while the
3474 symbol tables record only its basename. */
3475 const char *tail
= lbasename (srcfile
);
3478 s
= lookup_symtab (tail
);
3481 /* If we have no symtab for that file, return an empty list. */
3483 return (return_val
);
3485 /* Go through this symtab and check the externs and statics for
3486 symbols which match. */
3488 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3489 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
3491 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3494 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3495 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
3497 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3500 return (return_val
);
3503 /* A helper function for make_source_files_completion_list. It adds
3504 another file name to a list of possible completions, growing the
3505 list as necessary. */
3508 add_filename_to_list (const char *fname
, char *text
, char *word
,
3509 char ***list
, int *list_used
, int *list_alloced
)
3512 size_t fnlen
= strlen (fname
);
3514 if (*list_used
+ 1 >= *list_alloced
)
3517 *list
= (char **) xrealloc ((char *) *list
,
3518 *list_alloced
* sizeof (char *));
3523 /* Return exactly fname. */
3524 new = xmalloc (fnlen
+ 5);
3525 strcpy (new, fname
);
3527 else if (word
> text
)
3529 /* Return some portion of fname. */
3530 new = xmalloc (fnlen
+ 5);
3531 strcpy (new, fname
+ (word
- text
));
3535 /* Return some of TEXT plus fname. */
3536 new = xmalloc (fnlen
+ (text
- word
) + 5);
3537 strncpy (new, word
, text
- word
);
3538 new[text
- word
] = '\0';
3539 strcat (new, fname
);
3541 (*list
)[*list_used
] = new;
3542 (*list
)[++*list_used
] = NULL
;
3546 not_interesting_fname (const char *fname
)
3548 static const char *illegal_aliens
[] = {
3549 "_globals_", /* inserted by coff_symtab_read */
3554 for (i
= 0; illegal_aliens
[i
]; i
++)
3556 if (strcmp (fname
, illegal_aliens
[i
]) == 0)
3562 /* Return a NULL terminated array of all source files whose names
3563 begin with matching TEXT. The file names are looked up in the
3564 symbol tables of this program. If the answer is no matchess, then
3565 the return value is an array which contains only a NULL pointer. */
3568 make_source_files_completion_list (char *text
, char *word
)
3570 register struct symtab
*s
;
3571 register struct partial_symtab
*ps
;
3572 register struct objfile
*objfile
;
3574 int list_alloced
= 1;
3576 size_t text_len
= strlen (text
);
3577 char **list
= (char **) xmalloc (list_alloced
* sizeof (char *));
3578 const char *base_name
;
3582 if (!have_full_symbols () && !have_partial_symbols ())
3585 ALL_SYMTABS (objfile
, s
)
3587 if (not_interesting_fname (s
->filename
))
3589 if (!filename_seen (s
->filename
, 1, &first
)
3590 #if HAVE_DOS_BASED_FILE_SYSTEM
3591 && strncasecmp (s
->filename
, text
, text_len
) == 0
3593 && strncmp (s
->filename
, text
, text_len
) == 0
3597 /* This file matches for a completion; add it to the current
3599 add_filename_to_list (s
->filename
, text
, word
,
3600 &list
, &list_used
, &list_alloced
);
3604 /* NOTE: We allow the user to type a base name when the
3605 debug info records leading directories, but not the other
3606 way around. This is what subroutines of breakpoint
3607 command do when they parse file names. */
3608 base_name
= lbasename (s
->filename
);
3609 if (base_name
!= s
->filename
3610 && !filename_seen (base_name
, 1, &first
)
3611 #if HAVE_DOS_BASED_FILE_SYSTEM
3612 && strncasecmp (base_name
, text
, text_len
) == 0
3614 && strncmp (base_name
, text
, text_len
) == 0
3617 add_filename_to_list (base_name
, text
, word
,
3618 &list
, &list_used
, &list_alloced
);
3622 ALL_PSYMTABS (objfile
, ps
)
3624 if (not_interesting_fname (ps
->filename
))
3628 if (!filename_seen (ps
->filename
, 1, &first
)
3629 #if HAVE_DOS_BASED_FILE_SYSTEM
3630 && strncasecmp (ps
->filename
, text
, text_len
) == 0
3632 && strncmp (ps
->filename
, text
, text_len
) == 0
3636 /* This file matches for a completion; add it to the
3637 current list of matches. */
3638 add_filename_to_list (ps
->filename
, text
, word
,
3639 &list
, &list_used
, &list_alloced
);
3644 base_name
= lbasename (ps
->filename
);
3645 if (base_name
!= ps
->filename
3646 && !filename_seen (base_name
, 1, &first
)
3647 #if HAVE_DOS_BASED_FILE_SYSTEM
3648 && strncasecmp (base_name
, text
, text_len
) == 0
3650 && strncmp (base_name
, text
, text_len
) == 0
3653 add_filename_to_list (base_name
, text
, word
,
3654 &list
, &list_used
, &list_alloced
);
3662 /* Determine if PC is in the prologue of a function. The prologue is the area
3663 between the first instruction of a function, and the first executable line.
3664 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
3666 If non-zero, func_start is where we think the prologue starts, possibly
3667 by previous examination of symbol table information.
3671 in_prologue (CORE_ADDR pc
, CORE_ADDR func_start
)
3673 struct symtab_and_line sal
;
3674 CORE_ADDR func_addr
, func_end
;
3676 /* We have several sources of information we can consult to figure
3678 - Compilers usually emit line number info that marks the prologue
3679 as its own "source line". So the ending address of that "line"
3680 is the end of the prologue. If available, this is the most
3682 - The minimal symbols and partial symbols, which can usually tell
3683 us the starting and ending addresses of a function.
3684 - If we know the function's start address, we can call the
3685 architecture-defined SKIP_PROLOGUE function to analyze the
3686 instruction stream and guess where the prologue ends.
3687 - Our `func_start' argument; if non-zero, this is the caller's
3688 best guess as to the function's entry point. At the time of
3689 this writing, handle_inferior_event doesn't get this right, so
3690 it should be our last resort. */
3692 /* Consult the partial symbol table, to find which function
3694 if (! find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
3696 CORE_ADDR prologue_end
;
3698 /* We don't even have minsym information, so fall back to using
3699 func_start, if given. */
3701 return 1; /* We *might* be in a prologue. */
3703 prologue_end
= SKIP_PROLOGUE (func_start
);
3705 return func_start
<= pc
&& pc
< prologue_end
;
3708 /* If we have line number information for the function, that's
3709 usually pretty reliable. */
3710 sal
= find_pc_line (func_addr
, 0);
3712 /* Now sal describes the source line at the function's entry point,
3713 which (by convention) is the prologue. The end of that "line",
3714 sal.end, is the end of the prologue.
3716 Note that, for functions whose source code is all on a single
3717 line, the line number information doesn't always end up this way.
3718 So we must verify that our purported end-of-prologue address is
3719 *within* the function, not at its start or end. */
3721 || sal
.end
<= func_addr
3722 || func_end
<= sal
.end
)
3724 /* We don't have any good line number info, so use the minsym
3725 information, together with the architecture-specific prologue
3727 CORE_ADDR prologue_end
= SKIP_PROLOGUE (func_addr
);
3729 return func_addr
<= pc
&& pc
< prologue_end
;
3732 /* We have line number info, and it looks good. */
3733 return func_addr
<= pc
&& pc
< sal
.end
;
3737 /* Begin overload resolution functions */
3740 remove_params (const char *demangled_name
)
3746 if (demangled_name
== NULL
)
3749 /* First find the end of the arg list. */
3750 argp
= strrchr (demangled_name
, ')');
3754 /* Back up to the beginning. */
3757 while (argp
-- > demangled_name
)
3761 else if (*argp
== '(')
3770 internal_error (__FILE__
, __LINE__
,
3771 "bad demangled name %s\n", demangled_name
);
3772 while (argp
[-1] == ' ' && argp
> demangled_name
)
3775 new_name
= xmalloc (argp
- demangled_name
+ 1);
3776 memcpy (new_name
, demangled_name
, argp
- demangled_name
);
3777 new_name
[argp
- demangled_name
] = '\0';
3781 /* Helper routine for make_symbol_completion_list. */
3783 static int sym_return_val_size
;
3784 static int sym_return_val_index
;
3785 static struct symbol
**sym_return_val
;
3787 /* Test to see if the symbol specified by SYMNAME (which is already
3788 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3789 characters. If so, add it to the current completion list. */
3792 overload_list_add_symbol (struct symbol
*sym
, char *oload_name
)
3798 /* If there is no type information, we can't do anything, so skip */
3799 if (SYMBOL_TYPE (sym
) == NULL
)
3802 /* skip any symbols that we've already considered. */
3803 for (i
= 0; i
< sym_return_val_index
; ++i
)
3804 if (!strcmp (SYMBOL_NAME (sym
), SYMBOL_NAME (sym_return_val
[i
])))
3807 /* Get the demangled name without parameters */
3808 sym_name
= remove_params (SYMBOL_DEMANGLED_NAME (sym
));
3812 /* skip symbols that cannot match */
3813 if (strcmp (sym_name
, oload_name
) != 0)
3821 /* We have a match for an overload instance, so add SYM to the current list
3822 * of overload instances */
3823 if (sym_return_val_index
+ 3 > sym_return_val_size
)
3825 newsize
= (sym_return_val_size
*= 2) * sizeof (struct symbol
*);
3826 sym_return_val
= (struct symbol
**) xrealloc ((char *) sym_return_val
, newsize
);
3828 sym_return_val
[sym_return_val_index
++] = sym
;
3829 sym_return_val
[sym_return_val_index
] = NULL
;
3832 /* Return a null-terminated list of pointers to function symbols that
3833 * match name of the supplied symbol FSYM.
3834 * This is used in finding all overloaded instances of a function name.
3835 * This has been modified from make_symbol_completion_list. */
3839 make_symbol_overload_list (struct symbol
*fsym
)
3841 register struct symbol
*sym
;
3842 register struct symtab
*s
;
3843 register struct partial_symtab
*ps
;
3844 register struct objfile
*objfile
;
3845 register struct block
*b
, *surrounding_static_block
= 0;
3847 /* The name we are completing on. */
3848 char *oload_name
= NULL
;
3849 /* Length of name. */
3850 int oload_name_len
= 0;
3852 /* Look for the symbol we are supposed to complete on. */
3854 oload_name
= remove_params (SYMBOL_DEMANGLED_NAME (fsym
));
3857 sym_return_val_size
= 1;
3858 sym_return_val
= (struct symbol
**) xmalloc (2 * sizeof (struct symbol
*));
3859 sym_return_val
[0] = fsym
;
3860 sym_return_val
[1] = NULL
;
3862 return sym_return_val
;
3864 oload_name_len
= strlen (oload_name
);
3866 sym_return_val_size
= 100;
3867 sym_return_val_index
= 0;
3868 sym_return_val
= (struct symbol
**) xmalloc ((sym_return_val_size
+ 1) * sizeof (struct symbol
*));
3869 sym_return_val
[0] = NULL
;
3871 /* Look through the partial symtabs for all symbols which begin
3872 by matching OLOAD_NAME. Make sure we read that symbol table in. */
3874 ALL_PSYMTABS (objfile
, ps
)
3876 struct partial_symbol
**psym
;
3878 /* If the psymtab's been read in we'll get it when we search
3879 through the blockvector. */
3883 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
3884 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
3885 + ps
->n_global_syms
);
3888 /* If interrupted, then quit. */
3890 /* This will cause the symbol table to be read if it has not yet been */
3891 s
= PSYMTAB_TO_SYMTAB (ps
);
3894 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
3895 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
3896 + ps
->n_static_syms
);
3900 /* This will cause the symbol table to be read if it has not yet been */
3901 s
= PSYMTAB_TO_SYMTAB (ps
);
3905 /* Search upwards from currently selected frame (so that we can
3906 complete on local vars. */
3908 for (b
= get_selected_block (0); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
3910 if (!BLOCK_SUPERBLOCK (b
))
3912 surrounding_static_block
= b
; /* For elimination of dups */
3915 /* Also catch fields of types defined in this places which match our
3916 text string. Only complete on types visible from current context. */
3918 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
3920 overload_list_add_symbol (sym
, oload_name
);
3924 /* Go through the symtabs and check the externs and statics for
3925 symbols which match. */
3927 ALL_SYMTABS (objfile
, s
)
3930 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3931 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
3933 overload_list_add_symbol (sym
, oload_name
);
3937 ALL_SYMTABS (objfile
, s
)
3940 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3941 /* Don't do this block twice. */
3942 if (b
== surrounding_static_block
)
3944 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
3946 overload_list_add_symbol (sym
, oload_name
);
3952 return (sym_return_val
);
3955 /* End of overload resolution functions */
3957 struct symtabs_and_lines
3958 decode_line_spec (char *string
, int funfirstline
)
3960 struct symtabs_and_lines sals
;
3962 error ("Empty line specification.");
3963 sals
= decode_line_1 (&string
, funfirstline
,
3964 current_source_symtab
, current_source_line
,
3967 error ("Junk at end of line specification: %s", string
);
3972 static char *name_of_main
;
3975 set_main_name (const char *name
)
3977 if (name_of_main
!= NULL
)
3979 xfree (name_of_main
);
3980 name_of_main
= NULL
;
3984 name_of_main
= xstrdup (name
);
3991 if (name_of_main
!= NULL
)
3992 return name_of_main
;
3999 _initialize_symtab (void)
4001 add_info ("variables", variables_info
,
4002 "All global and static variable names, or those matching REGEXP.");
4004 add_com ("whereis", class_info
, variables_info
,
4005 "All global and static variable names, or those matching REGEXP.");
4007 add_info ("functions", functions_info
,
4008 "All function names, or those matching REGEXP.");
4011 /* FIXME: This command has at least the following problems:
4012 1. It prints builtin types (in a very strange and confusing fashion).
4013 2. It doesn't print right, e.g. with
4014 typedef struct foo *FOO
4015 type_print prints "FOO" when we want to make it (in this situation)
4016 print "struct foo *".
4017 I also think "ptype" or "whatis" is more likely to be useful (but if
4018 there is much disagreement "info types" can be fixed). */
4019 add_info ("types", types_info
,
4020 "All type names, or those matching REGEXP.");
4023 add_info ("methods", methods_info
,
4024 "All method names, or those matching REGEXP::REGEXP.\n\
4025 If the class qualifier is omitted, it is assumed to be the current scope.\n\
4026 If the first REGEXP is omitted, then all methods matching the second REGEXP\n\
4029 add_info ("sources", sources_info
,
4030 "Source files in the program.");
4032 add_com ("rbreak", class_breakpoint
, rbreak_command
,
4033 "Set a breakpoint for all functions matching REGEXP.");
4037 add_com ("lf", class_info
, sources_info
, "Source files in the program");
4038 add_com ("lg", class_info
, variables_info
,
4039 "All global and static variable names, or those matching REGEXP.");
4042 /* Initialize the one built-in type that isn't language dependent... */
4043 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
4044 "<unknown type>", (struct objfile
*) NULL
);