1 /* Symbol table lookup for the GNU debugger, GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
5 Free Software Foundation, Inc.
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., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
34 #include "call-cmds.h"
35 #include "gdb_regex.h"
36 #include "expression.h"
42 #include "filenames.h" /* for FILENAME_CMP */
43 #include "objc-lang.h"
48 #include "gdb_obstack.h"
50 #include "dictionary.h"
52 #include <sys/types.h>
54 #include "gdb_string.h"
60 /* Prototypes for local functions */
62 static void completion_list_add_name (char *, char *, int, char *, char *);
64 static void rbreak_command (char *, int);
66 static void types_info (char *, int);
68 static void functions_info (char *, int);
70 static void variables_info (char *, int);
72 static void sources_info (char *, int);
74 static void output_source_filename (const char *, int *);
76 static int find_line_common (struct linetable
*, int, int *);
78 /* This one is used by linespec.c */
80 char *operator_chars (char *p
, char **end
);
82 static struct symbol
*lookup_symbol_aux (const char *name
,
83 const char *linkage_name
,
84 const struct block
*block
,
85 const domain_enum domain
,
86 int *is_a_field_of_this
,
87 struct symtab
**symtab
);
90 struct symbol
*lookup_symbol_aux_local (const char *name
,
91 const char *linkage_name
,
92 const struct block
*block
,
93 const domain_enum domain
,
94 struct symtab
**symtab
);
97 struct symbol
*lookup_symbol_aux_symtabs (int block_index
,
99 const char *linkage_name
,
100 const domain_enum domain
,
101 struct symtab
**symtab
);
104 struct symbol
*lookup_symbol_aux_psymtabs (int block_index
,
106 const char *linkage_name
,
107 const domain_enum domain
,
108 struct symtab
**symtab
);
112 struct symbol
*lookup_symbol_aux_minsyms (const char *name
,
113 const char *linkage_name
,
114 const domain_enum domain
,
115 int *is_a_field_of_this
,
116 struct symtab
**symtab
);
119 /* This flag is used in hppa-tdep.c, and set in hp-symtab-read.c.
120 Signals the presence of objects compiled by HP compilers. */
121 int deprecated_hp_som_som_object_present
= 0;
123 static void fixup_section (struct general_symbol_info
*, struct objfile
*);
125 static int file_matches (char *, char **, int);
127 static void print_symbol_info (domain_enum
,
128 struct symtab
*, struct symbol
*, int, char *);
130 static void print_msymbol_info (struct minimal_symbol
*);
132 static void symtab_symbol_info (char *, domain_enum
, int);
134 void _initialize_symtab (void);
138 /* The single non-language-specific builtin type */
139 struct type
*builtin_type_error
;
141 /* Block in which the most recently searched-for symbol was found.
142 Might be better to make this a parameter to lookup_symbol and
145 const struct block
*block_found
;
147 /* Check for a symtab of a specific name; first in symtabs, then in
148 psymtabs. *If* there is no '/' in the name, a match after a '/'
149 in the symtab filename will also work. */
152 lookup_symtab (const char *name
)
155 struct partial_symtab
*ps
;
156 struct objfile
*objfile
;
157 char *real_path
= NULL
;
158 char *full_path
= NULL
;
160 /* Here we are interested in canonicalizing an absolute path, not
161 absolutizing a relative path. */
162 if (IS_ABSOLUTE_PATH (name
))
164 full_path
= xfullpath (name
);
165 make_cleanup (xfree
, full_path
);
166 real_path
= gdb_realpath (name
);
167 make_cleanup (xfree
, real_path
);
172 /* First, search for an exact match */
174 ALL_SYMTABS (objfile
, s
)
176 if (FILENAME_CMP (name
, s
->filename
) == 0)
181 /* If the user gave us an absolute path, try to find the file in
182 this symtab and use its absolute path. */
184 if (full_path
!= NULL
)
186 const char *fp
= symtab_to_fullname (s
);
187 if (fp
!= NULL
&& FILENAME_CMP (full_path
, fp
) == 0)
193 if (real_path
!= NULL
)
195 char *fullname
= symtab_to_fullname (s
);
196 if (fullname
!= NULL
)
198 char *rp
= gdb_realpath (fullname
);
199 make_cleanup (xfree
, rp
);
200 if (FILENAME_CMP (real_path
, rp
) == 0)
208 /* Now, search for a matching tail (only if name doesn't have any dirs) */
210 if (lbasename (name
) == name
)
211 ALL_SYMTABS (objfile
, s
)
213 if (FILENAME_CMP (lbasename (s
->filename
), name
) == 0)
217 /* Same search rules as above apply here, but now we look thru the
220 ps
= lookup_partial_symtab (name
);
225 error (_("Internal: readin %s pst for `%s' found when no symtab found."),
228 s
= PSYMTAB_TO_SYMTAB (ps
);
233 /* At this point, we have located the psymtab for this file, but
234 the conversion to a symtab has failed. This usually happens
235 when we are looking up an include file. In this case,
236 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
237 been created. So, we need to run through the symtabs again in
238 order to find the file.
239 XXX - This is a crock, and should be fixed inside of the the
240 symbol parsing routines. */
244 /* Lookup the partial symbol table of a source file named NAME.
245 *If* there is no '/' in the name, a match after a '/'
246 in the psymtab filename will also work. */
248 struct partial_symtab
*
249 lookup_partial_symtab (const char *name
)
251 struct partial_symtab
*pst
;
252 struct objfile
*objfile
;
253 char *full_path
= NULL
;
254 char *real_path
= NULL
;
256 /* Here we are interested in canonicalizing an absolute path, not
257 absolutizing a relative path. */
258 if (IS_ABSOLUTE_PATH (name
))
260 full_path
= xfullpath (name
);
261 make_cleanup (xfree
, full_path
);
262 real_path
= gdb_realpath (name
);
263 make_cleanup (xfree
, real_path
);
266 ALL_PSYMTABS (objfile
, pst
)
268 if (FILENAME_CMP (name
, pst
->filename
) == 0)
273 /* If the user gave us an absolute path, try to find the file in
274 this symtab and use its absolute path. */
275 if (full_path
!= NULL
)
277 psymtab_to_fullname (pst
);
278 if (pst
->fullname
!= NULL
279 && FILENAME_CMP (full_path
, pst
->fullname
) == 0)
285 if (real_path
!= NULL
)
288 psymtab_to_fullname (pst
);
289 if (pst
->fullname
!= NULL
)
291 rp
= gdb_realpath (pst
->fullname
);
292 make_cleanup (xfree
, rp
);
294 if (rp
!= NULL
&& FILENAME_CMP (real_path
, rp
) == 0)
301 /* Now, search for a matching tail (only if name doesn't have any dirs) */
303 if (lbasename (name
) == name
)
304 ALL_PSYMTABS (objfile
, pst
)
306 if (FILENAME_CMP (lbasename (pst
->filename
), name
) == 0)
313 /* Mangle a GDB method stub type. This actually reassembles the pieces of the
314 full method name, which consist of the class name (from T), the unadorned
315 method name from METHOD_ID, and the signature for the specific overload,
316 specified by SIGNATURE_ID. Note that this function is g++ specific. */
319 gdb_mangle_name (struct type
*type
, int method_id
, int signature_id
)
321 int mangled_name_len
;
323 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
324 struct fn_field
*method
= &f
[signature_id
];
325 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, method_id
);
326 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, signature_id
);
327 char *newname
= type_name_no_tag (type
);
329 /* Does the form of physname indicate that it is the full mangled name
330 of a constructor (not just the args)? */
331 int is_full_physname_constructor
;
334 int is_destructor
= is_destructor_name (physname
);
335 /* Need a new type prefix. */
336 char *const_prefix
= method
->is_const
? "C" : "";
337 char *volatile_prefix
= method
->is_volatile
? "V" : "";
339 int len
= (newname
== NULL
? 0 : strlen (newname
));
341 /* Nothing to do if physname already contains a fully mangled v3 abi name
342 or an operator name. */
343 if ((physname
[0] == '_' && physname
[1] == 'Z')
344 || is_operator_name (field_name
))
345 return xstrdup (physname
);
347 is_full_physname_constructor
= is_constructor_name (physname
);
350 is_full_physname_constructor
|| (newname
&& strcmp (field_name
, newname
) == 0);
353 is_destructor
= (strncmp (physname
, "__dt", 4) == 0);
355 if (is_destructor
|| is_full_physname_constructor
)
357 mangled_name
= (char *) xmalloc (strlen (physname
) + 1);
358 strcpy (mangled_name
, physname
);
364 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
366 else if (physname
[0] == 't' || physname
[0] == 'Q')
368 /* The physname for template and qualified methods already includes
370 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
376 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
378 mangled_name_len
= ((is_constructor
? 0 : strlen (field_name
))
379 + strlen (buf
) + len
+ strlen (physname
) + 1);
382 mangled_name
= (char *) xmalloc (mangled_name_len
);
384 mangled_name
[0] = '\0';
386 strcpy (mangled_name
, field_name
);
388 strcat (mangled_name
, buf
);
389 /* If the class doesn't have a name, i.e. newname NULL, then we just
390 mangle it using 0 for the length of the class. Thus it gets mangled
391 as something starting with `::' rather than `classname::'. */
393 strcat (mangled_name
, newname
);
395 strcat (mangled_name
, physname
);
396 return (mangled_name
);
400 /* Initialize the language dependent portion of a symbol
401 depending upon the language for the symbol. */
403 symbol_init_language_specific (struct general_symbol_info
*gsymbol
,
404 enum language language
)
406 gsymbol
->language
= language
;
407 if (gsymbol
->language
== language_cplus
408 || gsymbol
->language
== language_java
409 || gsymbol
->language
== language_objc
)
411 gsymbol
->language_specific
.cplus_specific
.demangled_name
= NULL
;
415 memset (&gsymbol
->language_specific
, 0,
416 sizeof (gsymbol
->language_specific
));
420 /* Functions to initialize a symbol's mangled name. */
422 /* Create the hash table used for demangled names. Each hash entry is
423 a pair of strings; one for the mangled name and one for the demangled
424 name. The entry is hashed via just the mangled name. */
427 create_demangled_names_hash (struct objfile
*objfile
)
429 /* Choose 256 as the starting size of the hash table, somewhat arbitrarily.
430 The hash table code will round this up to the next prime number.
431 Choosing a much larger table size wastes memory, and saves only about
432 1% in symbol reading. */
434 objfile
->demangled_names_hash
= htab_create_alloc
435 (256, htab_hash_string
, (int (*) (const void *, const void *)) streq
,
436 NULL
, xcalloc
, xfree
);
439 /* Try to determine the demangled name for a symbol, based on the
440 language of that symbol. If the language is set to language_auto,
441 it will attempt to find any demangling algorithm that works and
442 then set the language appropriately. The returned name is allocated
443 by the demangler and should be xfree'd. */
446 symbol_find_demangled_name (struct general_symbol_info
*gsymbol
,
449 char *demangled
= NULL
;
451 if (gsymbol
->language
== language_unknown
)
452 gsymbol
->language
= language_auto
;
454 if (gsymbol
->language
== language_objc
455 || gsymbol
->language
== language_auto
)
458 objc_demangle (mangled
, 0);
459 if (demangled
!= NULL
)
461 gsymbol
->language
= language_objc
;
465 if (gsymbol
->language
== language_cplus
466 || gsymbol
->language
== language_auto
)
469 cplus_demangle (mangled
, DMGL_PARAMS
| DMGL_ANSI
);
470 if (demangled
!= NULL
)
472 gsymbol
->language
= language_cplus
;
476 if (gsymbol
->language
== language_java
)
479 cplus_demangle (mangled
,
480 DMGL_PARAMS
| DMGL_ANSI
| DMGL_JAVA
);
481 if (demangled
!= NULL
)
483 gsymbol
->language
= language_java
;
490 /* Set both the mangled and demangled (if any) names for GSYMBOL based
491 on LINKAGE_NAME and LEN. The hash table corresponding to OBJFILE
492 is used, and the memory comes from that objfile's objfile_obstack.
493 LINKAGE_NAME is copied, so the pointer can be discarded after
494 calling this function. */
496 /* We have to be careful when dealing with Java names: when we run
497 into a Java minimal symbol, we don't know it's a Java symbol, so it
498 gets demangled as a C++ name. This is unfortunate, but there's not
499 much we can do about it: but when demangling partial symbols and
500 regular symbols, we'd better not reuse the wrong demangled name.
501 (See PR gdb/1039.) We solve this by putting a distinctive prefix
502 on Java names when storing them in the hash table. */
504 /* FIXME: carlton/2003-03-13: This is an unfortunate situation. I
505 don't mind the Java prefix so much: different languages have
506 different demangling requirements, so it's only natural that we
507 need to keep language data around in our demangling cache. But
508 it's not good that the minimal symbol has the wrong demangled name.
509 Unfortunately, I can't think of any easy solution to that
512 #define JAVA_PREFIX "##JAVA$$"
513 #define JAVA_PREFIX_LEN 8
516 symbol_set_names (struct general_symbol_info
*gsymbol
,
517 const char *linkage_name
, int len
, struct objfile
*objfile
)
520 /* A 0-terminated copy of the linkage name. */
521 const char *linkage_name_copy
;
522 /* A copy of the linkage name that might have a special Java prefix
523 added to it, for use when looking names up in the hash table. */
524 const char *lookup_name
;
525 /* The length of lookup_name. */
528 if (objfile
->demangled_names_hash
== NULL
)
529 create_demangled_names_hash (objfile
);
531 /* The stabs reader generally provides names that are not
532 NUL-terminated; most of the other readers don't do this, so we
533 can just use the given copy, unless we're in the Java case. */
534 if (gsymbol
->language
== language_java
)
537 lookup_len
= len
+ JAVA_PREFIX_LEN
;
539 alloc_name
= alloca (lookup_len
+ 1);
540 memcpy (alloc_name
, JAVA_PREFIX
, JAVA_PREFIX_LEN
);
541 memcpy (alloc_name
+ JAVA_PREFIX_LEN
, linkage_name
, len
);
542 alloc_name
[lookup_len
] = '\0';
544 lookup_name
= alloc_name
;
545 linkage_name_copy
= alloc_name
+ JAVA_PREFIX_LEN
;
547 else if (linkage_name
[len
] != '\0')
552 alloc_name
= alloca (lookup_len
+ 1);
553 memcpy (alloc_name
, linkage_name
, len
);
554 alloc_name
[lookup_len
] = '\0';
556 lookup_name
= alloc_name
;
557 linkage_name_copy
= alloc_name
;
562 lookup_name
= linkage_name
;
563 linkage_name_copy
= linkage_name
;
566 slot
= (char **) htab_find_slot (objfile
->demangled_names_hash
,
567 lookup_name
, INSERT
);
569 /* If this name is not in the hash table, add it. */
572 char *demangled_name
= symbol_find_demangled_name (gsymbol
,
574 int demangled_len
= demangled_name
? strlen (demangled_name
) : 0;
576 /* If there is a demangled name, place it right after the mangled name.
577 Otherwise, just place a second zero byte after the end of the mangled
579 *slot
= obstack_alloc (&objfile
->objfile_obstack
,
580 lookup_len
+ demangled_len
+ 2);
581 memcpy (*slot
, lookup_name
, lookup_len
+ 1);
582 if (demangled_name
!= NULL
)
584 memcpy (*slot
+ lookup_len
+ 1, demangled_name
, demangled_len
+ 1);
585 xfree (demangled_name
);
588 (*slot
)[lookup_len
+ 1] = '\0';
591 gsymbol
->name
= *slot
+ lookup_len
- len
;
592 if ((*slot
)[lookup_len
+ 1] != '\0')
593 gsymbol
->language_specific
.cplus_specific
.demangled_name
594 = &(*slot
)[lookup_len
+ 1];
596 gsymbol
->language_specific
.cplus_specific
.demangled_name
= NULL
;
599 /* Initialize the demangled name of GSYMBOL if possible. Any required space
600 to store the name is obtained from the specified obstack. The function
601 symbol_set_names, above, should be used instead where possible for more
602 efficient memory usage. */
605 symbol_init_demangled_name (struct general_symbol_info
*gsymbol
,
606 struct obstack
*obstack
)
608 char *mangled
= gsymbol
->name
;
609 char *demangled
= NULL
;
611 demangled
= symbol_find_demangled_name (gsymbol
, mangled
);
612 if (gsymbol
->language
== language_cplus
613 || gsymbol
->language
== language_java
614 || gsymbol
->language
== language_objc
)
618 gsymbol
->language_specific
.cplus_specific
.demangled_name
619 = obsavestring (demangled
, strlen (demangled
), obstack
);
623 gsymbol
->language_specific
.cplus_specific
.demangled_name
= NULL
;
627 /* Unknown language; just clean up quietly. */
633 /* Return the source code name of a symbol. In languages where
634 demangling is necessary, this is the demangled name. */
637 symbol_natural_name (const struct general_symbol_info
*gsymbol
)
639 switch (gsymbol
->language
)
644 if (gsymbol
->language_specific
.cplus_specific
.demangled_name
!= NULL
)
645 return gsymbol
->language_specific
.cplus_specific
.demangled_name
;
648 if (gsymbol
->language_specific
.cplus_specific
.demangled_name
!= NULL
)
649 return gsymbol
->language_specific
.cplus_specific
.demangled_name
;
651 return ada_decode_symbol (gsymbol
);
656 return gsymbol
->name
;
659 /* Return the demangled name for a symbol based on the language for
660 that symbol. If no demangled name exists, return NULL. */
662 symbol_demangled_name (struct general_symbol_info
*gsymbol
)
664 switch (gsymbol
->language
)
669 if (gsymbol
->language_specific
.cplus_specific
.demangled_name
!= NULL
)
670 return gsymbol
->language_specific
.cplus_specific
.demangled_name
;
673 if (gsymbol
->language_specific
.cplus_specific
.demangled_name
!= NULL
)
674 return gsymbol
->language_specific
.cplus_specific
.demangled_name
;
676 return ada_decode_symbol (gsymbol
);
684 /* Return the search name of a symbol---generally the demangled or
685 linkage name of the symbol, depending on how it will be searched for.
686 If there is no distinct demangled name, then returns the same value
687 (same pointer) as SYMBOL_LINKAGE_NAME. */
689 symbol_search_name (const struct general_symbol_info
*gsymbol
)
691 if (gsymbol
->language
== language_ada
)
692 return gsymbol
->name
;
694 return symbol_natural_name (gsymbol
);
697 /* Initialize the structure fields to zero values. */
699 init_sal (struct symtab_and_line
*sal
)
710 /* Find which partial symtab contains PC and SECTION. Return 0 if
711 none. We return the psymtab that contains a symbol whose address
712 exactly matches PC, or, if we cannot find an exact match, the
713 psymtab that contains a symbol whose address is closest to PC. */
714 struct partial_symtab
*
715 find_pc_sect_psymtab (CORE_ADDR pc
, asection
*section
)
717 struct partial_symtab
*pst
;
718 struct objfile
*objfile
;
719 struct minimal_symbol
*msymbol
;
721 /* If we know that this is not a text address, return failure. This is
722 necessary because we loop based on texthigh and textlow, which do
723 not include the data ranges. */
724 msymbol
= lookup_minimal_symbol_by_pc_section (pc
, section
);
726 && (msymbol
->type
== mst_data
727 || msymbol
->type
== mst_bss
728 || msymbol
->type
== mst_abs
729 || msymbol
->type
== mst_file_data
730 || msymbol
->type
== mst_file_bss
))
733 ALL_PSYMTABS (objfile
, pst
)
735 if (pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
737 struct partial_symtab
*tpst
;
738 struct partial_symtab
*best_pst
= pst
;
739 struct partial_symbol
*best_psym
= NULL
;
741 /* An objfile that has its functions reordered might have
742 many partial symbol tables containing the PC, but
743 we want the partial symbol table that contains the
744 function containing the PC. */
745 if (!(objfile
->flags
& OBJF_REORDERED
) &&
746 section
== 0) /* can't validate section this way */
752 /* The code range of partial symtabs sometimes overlap, so, in
753 the loop below, we need to check all partial symtabs and
754 find the one that fits better for the given PC address. We
755 select the partial symtab that contains a symbol whose
756 address is closest to the PC address. By closest we mean
757 that find_pc_sect_symbol returns the symbol with address
758 that is closest and still less than the given PC. */
759 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
761 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
763 struct partial_symbol
*p
;
765 p
= find_pc_sect_psymbol (tpst
, pc
, section
);
767 && SYMBOL_VALUE_ADDRESS (p
)
768 == SYMBOL_VALUE_ADDRESS (msymbol
))
772 /* We found a symbol in this partial symtab which
773 matches (or is closest to) PC, check whether it
774 is closer than our current BEST_PSYM. Since
775 this symbol address is necessarily lower or
776 equal to PC, the symbol closer to PC is the
777 symbol which address is the highest. */
778 /* This way we return the psymtab which contains
779 such best match symbol. This can help in cases
780 where the symbol information/debuginfo is not
781 complete, like for instance on IRIX6 with gcc,
782 where no debug info is emitted for
783 statics. (See also the nodebug.exp
785 if (best_psym
== NULL
786 || SYMBOL_VALUE_ADDRESS (p
)
787 > SYMBOL_VALUE_ADDRESS (best_psym
))
802 /* Find which partial symtab contains PC. Return 0 if none.
803 Backward compatibility, no section */
805 struct partial_symtab
*
806 find_pc_psymtab (CORE_ADDR pc
)
808 return find_pc_sect_psymtab (pc
, find_pc_mapped_section (pc
));
811 /* Find which partial symbol within a psymtab matches PC and SECTION.
812 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
814 struct partial_symbol
*
815 find_pc_sect_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
,
818 struct partial_symbol
*best
= NULL
, *p
, **pp
;
822 psymtab
= find_pc_sect_psymtab (pc
, section
);
826 /* Cope with programs that start at address 0 */
827 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
829 /* Search the global symbols as well as the static symbols, so that
830 find_pc_partial_function doesn't use a minimal symbol and thus
831 cache a bad endaddr. */
832 for (pp
= psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
833 (pp
- (psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
834 < psymtab
->n_global_syms
);
838 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
839 && SYMBOL_CLASS (p
) == LOC_BLOCK
840 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
841 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
842 || (psymtab
->textlow
== 0
843 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
845 if (section
) /* match on a specific section */
847 fixup_psymbol_section (p
, psymtab
->objfile
);
848 if (SYMBOL_BFD_SECTION (p
) != section
)
851 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
856 for (pp
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
857 (pp
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
858 < psymtab
->n_static_syms
);
862 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
863 && SYMBOL_CLASS (p
) == LOC_BLOCK
864 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
865 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
866 || (psymtab
->textlow
== 0
867 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
869 if (section
) /* match on a specific section */
871 fixup_psymbol_section (p
, psymtab
->objfile
);
872 if (SYMBOL_BFD_SECTION (p
) != section
)
875 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
883 /* Find which partial symbol within a psymtab matches PC. Return 0 if none.
884 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
886 struct partial_symbol
*
887 find_pc_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
)
889 return find_pc_sect_psymbol (psymtab
, pc
, find_pc_mapped_section (pc
));
892 /* Debug symbols usually don't have section information. We need to dig that
893 out of the minimal symbols and stash that in the debug symbol. */
896 fixup_section (struct general_symbol_info
*ginfo
, struct objfile
*objfile
)
898 struct minimal_symbol
*msym
;
899 msym
= lookup_minimal_symbol (ginfo
->name
, NULL
, objfile
);
903 ginfo
->bfd_section
= SYMBOL_BFD_SECTION (msym
);
904 ginfo
->section
= SYMBOL_SECTION (msym
);
908 /* Static, function-local variables do appear in the linker
909 (minimal) symbols, but are frequently given names that won't
910 be found via lookup_minimal_symbol(). E.g., it has been
911 observed in frv-uclinux (ELF) executables that a static,
912 function-local variable named "foo" might appear in the
913 linker symbols as "foo.6" or "foo.3". Thus, there is no
914 point in attempting to extend the lookup-by-name mechanism to
915 handle this case due to the fact that there can be multiple
918 So, instead, search the section table when lookup by name has
919 failed. The ``addr'' and ``endaddr'' fields may have already
920 been relocated. If so, the relocation offset (i.e. the
921 ANOFFSET value) needs to be subtracted from these values when
922 performing the comparison. We unconditionally subtract it,
923 because, when no relocation has been performed, the ANOFFSET
924 value will simply be zero.
926 The address of the symbol whose section we're fixing up HAS
927 NOT BEEN adjusted (relocated) yet. It can't have been since
928 the section isn't yet known and knowing the section is
929 necessary in order to add the correct relocation value. In
930 other words, we wouldn't even be in this function (attempting
931 to compute the section) if it were already known.
933 Note that it is possible to search the minimal symbols
934 (subtracting the relocation value if necessary) to find the
935 matching minimal symbol, but this is overkill and much less
936 efficient. It is not necessary to find the matching minimal
937 symbol, only its section.
939 Note that this technique (of doing a section table search)
940 can fail when unrelocated section addresses overlap. For
941 this reason, we still attempt a lookup by name prior to doing
942 a search of the section table. */
945 struct obj_section
*s
;
947 addr
= ginfo
->value
.address
;
949 ALL_OBJFILE_OSECTIONS (objfile
, s
)
951 int idx
= s
->the_bfd_section
->index
;
952 CORE_ADDR offset
= ANOFFSET (objfile
->section_offsets
, idx
);
954 if (s
->addr
- offset
<= addr
&& addr
< s
->endaddr
- offset
)
956 ginfo
->bfd_section
= s
->the_bfd_section
;
957 ginfo
->section
= idx
;
965 fixup_symbol_section (struct symbol
*sym
, struct objfile
*objfile
)
970 if (SYMBOL_BFD_SECTION (sym
))
973 fixup_section (&sym
->ginfo
, objfile
);
978 struct partial_symbol
*
979 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
984 if (SYMBOL_BFD_SECTION (psym
))
987 fixup_section (&psym
->ginfo
, objfile
);
992 /* Find the definition for a specified symbol name NAME
993 in domain DOMAIN, visible from lexical block BLOCK.
994 Returns the struct symbol pointer, or zero if no symbol is found.
995 If SYMTAB is non-NULL, store the symbol table in which the
996 symbol was found there, or NULL if not found.
997 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
998 NAME is a field of the current implied argument `this'. If so set
999 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
1000 BLOCK_FOUND is set to the block in which NAME is found (in the case of
1001 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
1003 /* This function has a bunch of loops in it and it would seem to be
1004 attractive to put in some QUIT's (though I'm not really sure
1005 whether it can run long enough to be really important). But there
1006 are a few calls for which it would appear to be bad news to quit
1007 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c. (Note
1008 that there is C++ code below which can error(), but that probably
1009 doesn't affect these calls since they are looking for a known
1010 variable and thus can probably assume it will never hit the C++
1014 lookup_symbol (const char *name
, const struct block
*block
,
1015 const domain_enum domain
, int *is_a_field_of_this
,
1016 struct symtab
**symtab
)
1018 char *demangled_name
= NULL
;
1019 const char *modified_name
= NULL
;
1020 const char *mangled_name
= NULL
;
1021 int needtofreename
= 0;
1022 struct symbol
*returnval
;
1024 modified_name
= name
;
1026 /* If we are using C++ or Java, demangle the name before doing a lookup, so
1027 we can always binary search. */
1028 if (current_language
->la_language
== language_cplus
)
1030 demangled_name
= cplus_demangle (name
, DMGL_ANSI
| DMGL_PARAMS
);
1033 mangled_name
= name
;
1034 modified_name
= demangled_name
;
1038 else if (current_language
->la_language
== language_java
)
1040 demangled_name
= cplus_demangle (name
,
1041 DMGL_ANSI
| DMGL_PARAMS
| DMGL_JAVA
);
1044 mangled_name
= name
;
1045 modified_name
= demangled_name
;
1050 if (case_sensitivity
== case_sensitive_off
)
1055 len
= strlen (name
);
1056 copy
= (char *) alloca (len
+ 1);
1057 for (i
= 0; i
< len
; i
++)
1058 copy
[i
] = tolower (name
[i
]);
1060 modified_name
= copy
;
1063 returnval
= lookup_symbol_aux (modified_name
, mangled_name
, block
,
1064 domain
, is_a_field_of_this
, symtab
);
1066 xfree (demangled_name
);
1071 /* Behave like lookup_symbol_aux except that NAME is the natural name
1072 of the symbol that we're looking for and, if LINKAGE_NAME is
1073 non-NULL, ensure that the symbol's linkage name matches as
1076 static struct symbol
*
1077 lookup_symbol_aux (const char *name
, const char *linkage_name
,
1078 const struct block
*block
, const domain_enum domain
,
1079 int *is_a_field_of_this
, struct symtab
**symtab
)
1083 /* Make sure we do something sensible with is_a_field_of_this, since
1084 the callers that set this parameter to some non-null value will
1085 certainly use it later and expect it to be either 0 or 1.
1086 If we don't set it, the contents of is_a_field_of_this are
1088 if (is_a_field_of_this
!= NULL
)
1089 *is_a_field_of_this
= 0;
1091 /* Search specified block and its superiors. Don't search
1092 STATIC_BLOCK or GLOBAL_BLOCK. */
1094 sym
= lookup_symbol_aux_local (name
, linkage_name
, block
, domain
,
1099 /* If requested to do so by the caller and if appropriate for the
1100 current language, check to see if NAME is a field of `this'. */
1102 if (current_language
->la_value_of_this
!= NULL
1103 && is_a_field_of_this
!= NULL
)
1105 struct value
*v
= current_language
->la_value_of_this (0);
1107 if (v
&& check_field (v
, name
))
1109 *is_a_field_of_this
= 1;
1116 /* Now do whatever is appropriate for the current language to look
1117 up static and global variables. */
1119 sym
= current_language
->la_lookup_symbol_nonlocal (name
, linkage_name
,
1125 /* Now search all static file-level symbols. Not strictly correct,
1126 but more useful than an error. Do the symtabs first, then check
1127 the psymtabs. If a psymtab indicates the existence of the
1128 desired name as a file-level static, then do psymtab-to-symtab
1129 conversion on the fly and return the found symbol. */
1131 sym
= lookup_symbol_aux_symtabs (STATIC_BLOCK
, name
, linkage_name
,
1136 sym
= lookup_symbol_aux_psymtabs (STATIC_BLOCK
, name
, linkage_name
,
1146 /* Check to see if the symbol is defined in BLOCK or its superiors.
1147 Don't search STATIC_BLOCK or GLOBAL_BLOCK. */
1149 static struct symbol
*
1150 lookup_symbol_aux_local (const char *name
, const char *linkage_name
,
1151 const struct block
*block
,
1152 const domain_enum domain
,
1153 struct symtab
**symtab
)
1156 const struct block
*static_block
= block_static_block (block
);
1158 /* Check if either no block is specified or it's a global block. */
1160 if (static_block
== NULL
)
1163 while (block
!= static_block
)
1165 sym
= lookup_symbol_aux_block (name
, linkage_name
, block
, domain
,
1169 block
= BLOCK_SUPERBLOCK (block
);
1172 /* We've reached the static block without finding a result. */
1177 /* Look up a symbol in a block; if found, locate its symtab, fixup the
1178 symbol, and set block_found appropriately. */
1181 lookup_symbol_aux_block (const char *name
, const char *linkage_name
,
1182 const struct block
*block
,
1183 const domain_enum domain
,
1184 struct symtab
**symtab
)
1187 struct objfile
*objfile
= NULL
;
1188 struct blockvector
*bv
;
1190 struct symtab
*s
= NULL
;
1192 sym
= lookup_block_symbol (block
, name
, linkage_name
, domain
);
1195 block_found
= block
;
1198 /* Search the list of symtabs for one which contains the
1199 address of the start of this block. */
1200 ALL_SYMTABS (objfile
, s
)
1202 bv
= BLOCKVECTOR (s
);
1203 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1204 if (BLOCK_START (b
) <= BLOCK_START (block
)
1205 && BLOCK_END (b
) > BLOCK_START (block
))
1212 return fixup_symbol_section (sym
, objfile
);
1218 /* Check to see if the symbol is defined in one of the symtabs.
1219 BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
1220 depending on whether or not we want to search global symbols or
1223 static struct symbol
*
1224 lookup_symbol_aux_symtabs (int block_index
,
1225 const char *name
, const char *linkage_name
,
1226 const domain_enum domain
,
1227 struct symtab
**symtab
)
1230 struct objfile
*objfile
;
1231 struct blockvector
*bv
;
1232 const struct block
*block
;
1235 ALL_SYMTABS (objfile
, s
)
1237 bv
= BLOCKVECTOR (s
);
1238 block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
1239 sym
= lookup_block_symbol (block
, name
, linkage_name
, domain
);
1242 block_found
= block
;
1245 return fixup_symbol_section (sym
, objfile
);
1252 /* Check to see if the symbol is defined in one of the partial
1253 symtabs. BLOCK_INDEX should be either GLOBAL_BLOCK or
1254 STATIC_BLOCK, depending on whether or not we want to search global
1255 symbols or static symbols. */
1257 static struct symbol
*
1258 lookup_symbol_aux_psymtabs (int block_index
, const char *name
,
1259 const char *linkage_name
,
1260 const domain_enum domain
,
1261 struct symtab
**symtab
)
1264 struct objfile
*objfile
;
1265 struct blockvector
*bv
;
1266 const struct block
*block
;
1267 struct partial_symtab
*ps
;
1269 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
1271 ALL_PSYMTABS (objfile
, ps
)
1274 && lookup_partial_symbol (ps
, name
, linkage_name
,
1275 psymtab_index
, domain
))
1277 s
= PSYMTAB_TO_SYMTAB (ps
);
1278 bv
= BLOCKVECTOR (s
);
1279 block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
1280 sym
= lookup_block_symbol (block
, name
, linkage_name
, domain
);
1283 /* This shouldn't be necessary, but as a last resort try
1284 looking in the statics even though the psymtab claimed
1285 the symbol was global, or vice-versa. It's possible
1286 that the psymtab gets it wrong in some cases. */
1288 /* FIXME: carlton/2002-09-30: Should we really do that?
1289 If that happens, isn't it likely to be a GDB error, in
1290 which case we should fix the GDB error rather than
1291 silently dealing with it here? So I'd vote for
1292 removing the check for the symbol in the other
1294 block
= BLOCKVECTOR_BLOCK (bv
,
1295 block_index
== GLOBAL_BLOCK
?
1296 STATIC_BLOCK
: GLOBAL_BLOCK
);
1297 sym
= lookup_block_symbol (block
, name
, linkage_name
, domain
);
1299 error (_("Internal: %s symbol `%s' found in %s psymtab but not in symtab.\n%s may be an inlined function, or may be a template function\n(if a template, try specifying an instantiation: %s<type>)."),
1300 block_index
== GLOBAL_BLOCK
? "global" : "static",
1301 name
, ps
->filename
, name
, name
);
1305 return fixup_symbol_section (sym
, objfile
);
1313 /* Check for the possibility of the symbol being a function or a
1314 mangled variable that is stored in one of the minimal symbol
1315 tables. Eventually, all global symbols might be resolved in this
1318 /* NOTE: carlton/2002-12-05: At one point, this function was part of
1319 lookup_symbol_aux, and what are now 'return' statements within
1320 lookup_symbol_aux_minsyms returned from lookup_symbol_aux, even if
1321 sym was NULL. As far as I can tell, this was basically accidental;
1322 it didn't happen every time that msymbol was non-NULL, but only if
1323 some additional conditions held as well, and it caused problems
1324 with HP-generated symbol tables. */
1326 /* NOTE: carlton/2003-05-14: This function was once used as part of
1327 lookup_symbol. It is currently unnecessary for correctness
1328 reasons, however, and using it doesn't seem to be any faster than
1329 using lookup_symbol_aux_psymtabs, so I'm commenting it out. */
1331 static struct symbol
*
1332 lookup_symbol_aux_minsyms (const char *name
,
1333 const char *linkage_name
,
1334 const domain_enum domain
,
1335 int *is_a_field_of_this
,
1336 struct symtab
**symtab
)
1339 struct blockvector
*bv
;
1340 const struct block
*block
;
1341 struct minimal_symbol
*msymbol
;
1344 if (domain
== VAR_DOMAIN
)
1346 msymbol
= lookup_minimal_symbol (name
, NULL
, NULL
);
1348 if (msymbol
!= NULL
)
1350 /* OK, we found a minimal symbol in spite of not finding any
1351 symbol. There are various possible explanations for
1352 this. One possibility is the symbol exists in code not
1353 compiled -g. Another possibility is that the 'psymtab'
1354 isn't doing its job. A third possibility, related to #2,
1355 is that we were confused by name-mangling. For instance,
1356 maybe the psymtab isn't doing its job because it only
1357 know about demangled names, but we were given a mangled
1360 /* We first use the address in the msymbol to try to locate
1361 the appropriate symtab. Note that find_pc_sect_symtab()
1362 has a side-effect of doing psymtab-to-symtab expansion,
1363 for the found symtab. */
1364 s
= find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol
),
1365 SYMBOL_BFD_SECTION (msymbol
));
1368 /* This is a function which has a symtab for its address. */
1369 bv
= BLOCKVECTOR (s
);
1370 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1372 /* This call used to pass `SYMBOL_LINKAGE_NAME (msymbol)' as the
1373 `name' argument to lookup_block_symbol. But the name
1374 of a minimal symbol is always mangled, so that seems
1375 to be clearly the wrong thing to pass as the
1378 lookup_block_symbol (block
, name
, linkage_name
, domain
);
1379 /* We kept static functions in minimal symbol table as well as
1380 in static scope. We want to find them in the symbol table. */
1383 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1384 sym
= lookup_block_symbol (block
, name
,
1385 linkage_name
, domain
);
1388 /* NOTE: carlton/2002-12-04: The following comment was
1389 taken from a time when two versions of this function
1390 were part of the body of lookup_symbol_aux: this
1391 comment was taken from the version of the function
1392 that was #ifdef HPUXHPPA, and the comment was right
1393 before the 'return NULL' part of lookup_symbol_aux.
1394 (Hence the "Fall through and return 0" comment.)
1395 Elena did some digging into the situation for
1396 Fortran, and she reports:
1398 "I asked around (thanks to Jeff Knaggs), and I think
1399 the story for Fortran goes like this:
1401 "Apparently, in older Fortrans, '_' was not part of
1402 the user namespace. g77 attached a final '_' to
1403 procedure names as the exported symbols for linkage
1404 (foo_) , but the symbols went in the debug info just
1405 like 'foo'. The rationale behind this is not
1406 completely clear, and maybe it was done to other
1407 symbols as well, not just procedures." */
1409 /* If we get here with sym == 0, the symbol was
1410 found in the minimal symbol table
1411 but not in the symtab.
1412 Fall through and return 0 to use the msymbol
1413 definition of "foo_".
1414 (Note that outer code generally follows up a call
1415 to this routine with a call to lookup_minimal_symbol(),
1416 so a 0 return means we'll just flow into that other routine).
1418 This happens for Fortran "foo_" symbols,
1419 which are "foo" in the symtab.
1421 This can also happen if "asm" is used to make a
1422 regular symbol but not a debugging symbol, e.g.
1423 asm(".globl _main");
1427 if (symtab
!= NULL
&& sym
!= NULL
)
1429 return fixup_symbol_section (sym
, s
->objfile
);
1438 /* A default version of lookup_symbol_nonlocal for use by languages
1439 that can't think of anything better to do. This implements the C
1443 basic_lookup_symbol_nonlocal (const char *name
,
1444 const char *linkage_name
,
1445 const struct block
*block
,
1446 const domain_enum domain
,
1447 struct symtab
**symtab
)
1451 /* NOTE: carlton/2003-05-19: The comments below were written when
1452 this (or what turned into this) was part of lookup_symbol_aux;
1453 I'm much less worried about these questions now, since these
1454 decisions have turned out well, but I leave these comments here
1457 /* NOTE: carlton/2002-12-05: There is a question as to whether or
1458 not it would be appropriate to search the current global block
1459 here as well. (That's what this code used to do before the
1460 is_a_field_of_this check was moved up.) On the one hand, it's
1461 redundant with the lookup_symbol_aux_symtabs search that happens
1462 next. On the other hand, if decode_line_1 is passed an argument
1463 like filename:var, then the user presumably wants 'var' to be
1464 searched for in filename. On the third hand, there shouldn't be
1465 multiple global variables all of which are named 'var', and it's
1466 not like decode_line_1 has ever restricted its search to only
1467 global variables in a single filename. All in all, only
1468 searching the static block here seems best: it's correct and it's
1471 /* NOTE: carlton/2002-12-05: There's also a possible performance
1472 issue here: if you usually search for global symbols in the
1473 current file, then it would be slightly better to search the
1474 current global block before searching all the symtabs. But there
1475 are other factors that have a much greater effect on performance
1476 than that one, so I don't think we should worry about that for
1479 sym
= lookup_symbol_static (name
, linkage_name
, block
, domain
, symtab
);
1483 return lookup_symbol_global (name
, linkage_name
, domain
, symtab
);
1486 /* Lookup a symbol in the static block associated to BLOCK, if there
1487 is one; do nothing if BLOCK is NULL or a global block. */
1490 lookup_symbol_static (const char *name
,
1491 const char *linkage_name
,
1492 const struct block
*block
,
1493 const domain_enum domain
,
1494 struct symtab
**symtab
)
1496 const struct block
*static_block
= block_static_block (block
);
1498 if (static_block
!= NULL
)
1499 return lookup_symbol_aux_block (name
, linkage_name
, static_block
,
1505 /* Lookup a symbol in all files' global blocks (searching psymtabs if
1509 lookup_symbol_global (const char *name
,
1510 const char *linkage_name
,
1511 const domain_enum domain
,
1512 struct symtab
**symtab
)
1516 sym
= lookup_symbol_aux_symtabs (GLOBAL_BLOCK
, name
, linkage_name
,
1521 return lookup_symbol_aux_psymtabs (GLOBAL_BLOCK
, name
, linkage_name
,
1525 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
1526 If LINKAGE_NAME is non-NULL, check in addition that the symbol's
1527 linkage name matches it. Check the global symbols if GLOBAL, the
1528 static symbols if not */
1530 struct partial_symbol
*
1531 lookup_partial_symbol (struct partial_symtab
*pst
, const char *name
,
1532 const char *linkage_name
, int global
,
1535 struct partial_symbol
*temp
;
1536 struct partial_symbol
**start
, **psym
;
1537 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
1538 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
1539 int do_linear_search
= 1;
1546 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
1547 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1549 if (global
) /* This means we can use a binary search. */
1551 do_linear_search
= 0;
1553 /* Binary search. This search is guaranteed to end with center
1554 pointing at the earliest partial symbol whose name might be
1555 correct. At that point *all* partial symbols with an
1556 appropriate name will be checked against the correct
1560 top
= start
+ length
- 1;
1562 while (top
> bottom
)
1564 center
= bottom
+ (top
- bottom
) / 2;
1565 if (!(center
< top
))
1566 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
1567 if (!do_linear_search
1568 && (SYMBOL_LANGUAGE (*center
) == language_java
))
1570 do_linear_search
= 1;
1572 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center
), name
) >= 0)
1578 bottom
= center
+ 1;
1581 if (!(top
== bottom
))
1582 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
1584 while (top
<= real_top
1585 && (linkage_name
!= NULL
1586 ? strcmp (SYMBOL_LINKAGE_NAME (*top
), linkage_name
) == 0
1587 : SYMBOL_MATCHES_SEARCH_NAME (*top
,name
)))
1589 if (SYMBOL_DOMAIN (*top
) == domain
)
1597 /* Can't use a binary search or else we found during the binary search that
1598 we should also do a linear search. */
1600 if (do_linear_search
)
1602 for (psym
= start
; psym
< start
+ length
; psym
++)
1604 if (domain
== SYMBOL_DOMAIN (*psym
))
1606 if (linkage_name
!= NULL
1607 ? strcmp (SYMBOL_LINKAGE_NAME (*psym
), linkage_name
) == 0
1608 : SYMBOL_MATCHES_SEARCH_NAME (*psym
, name
))
1619 /* Look up a type named NAME in the struct_domain. The type returned
1620 must not be opaque -- i.e., must have at least one field
1624 lookup_transparent_type (const char *name
)
1626 return current_language
->la_lookup_transparent_type (name
);
1629 /* The standard implementation of lookup_transparent_type. This code
1630 was modeled on lookup_symbol -- the parts not relevant to looking
1631 up types were just left out. In particular it's assumed here that
1632 types are available in struct_domain and only at file-static or
1636 basic_lookup_transparent_type (const char *name
)
1639 struct symtab
*s
= NULL
;
1640 struct partial_symtab
*ps
;
1641 struct blockvector
*bv
;
1642 struct objfile
*objfile
;
1643 struct block
*block
;
1645 /* Now search all the global symbols. Do the symtab's first, then
1646 check the psymtab's. If a psymtab indicates the existence
1647 of the desired name as a global, then do psymtab-to-symtab
1648 conversion on the fly and return the found symbol. */
1650 ALL_SYMTABS (objfile
, s
)
1652 bv
= BLOCKVECTOR (s
);
1653 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1654 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1655 if (sym
&& !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1657 return SYMBOL_TYPE (sym
);
1661 ALL_PSYMTABS (objfile
, ps
)
1663 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, NULL
,
1666 s
= PSYMTAB_TO_SYMTAB (ps
);
1667 bv
= BLOCKVECTOR (s
);
1668 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1669 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1672 /* This shouldn't be necessary, but as a last resort
1673 * try looking in the statics even though the psymtab
1674 * claimed the symbol was global. It's possible that
1675 * the psymtab gets it wrong in some cases.
1677 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1678 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1680 error (_("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
1681 %s may be an inlined function, or may be a template function\n\
1682 (if a template, try specifying an instantiation: %s<type>)."),
1683 name
, ps
->filename
, name
, name
);
1685 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1686 return SYMBOL_TYPE (sym
);
1690 /* Now search the static file-level symbols.
1691 Not strictly correct, but more useful than an error.
1692 Do the symtab's first, then
1693 check the psymtab's. If a psymtab indicates the existence
1694 of the desired name as a file-level static, then do psymtab-to-symtab
1695 conversion on the fly and return the found symbol.
1698 ALL_SYMTABS (objfile
, s
)
1700 bv
= BLOCKVECTOR (s
);
1701 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1702 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1703 if (sym
&& !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1705 return SYMBOL_TYPE (sym
);
1709 ALL_PSYMTABS (objfile
, ps
)
1711 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, NULL
, 0, STRUCT_DOMAIN
))
1713 s
= PSYMTAB_TO_SYMTAB (ps
);
1714 bv
= BLOCKVECTOR (s
);
1715 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1716 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1719 /* This shouldn't be necessary, but as a last resort
1720 * try looking in the globals even though the psymtab
1721 * claimed the symbol was static. It's possible that
1722 * the psymtab gets it wrong in some cases.
1724 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1725 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1727 error (_("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
1728 %s may be an inlined function, or may be a template function\n\
1729 (if a template, try specifying an instantiation: %s<type>)."),
1730 name
, ps
->filename
, name
, name
);
1732 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1733 return SYMBOL_TYPE (sym
);
1736 return (struct type
*) 0;
1740 /* Find the psymtab containing main(). */
1741 /* FIXME: What about languages without main() or specially linked
1742 executables that have no main() ? */
1744 struct partial_symtab
*
1745 find_main_psymtab (void)
1747 struct partial_symtab
*pst
;
1748 struct objfile
*objfile
;
1750 ALL_PSYMTABS (objfile
, pst
)
1752 if (lookup_partial_symbol (pst
, main_name (), NULL
, 1, VAR_DOMAIN
))
1760 /* Search BLOCK for symbol NAME in DOMAIN.
1762 Note that if NAME is the demangled form of a C++ symbol, we will fail
1763 to find a match during the binary search of the non-encoded names, but
1764 for now we don't worry about the slight inefficiency of looking for
1765 a match we'll never find, since it will go pretty quick. Once the
1766 binary search terminates, we drop through and do a straight linear
1767 search on the symbols. Each symbol which is marked as being a ObjC/C++
1768 symbol (language_cplus or language_objc set) has both the encoded and
1769 non-encoded names tested for a match.
1771 If LINKAGE_NAME is non-NULL, verify that any symbol we find has this
1772 particular mangled name.
1776 lookup_block_symbol (const struct block
*block
, const char *name
,
1777 const char *linkage_name
,
1778 const domain_enum domain
)
1780 struct dict_iterator iter
;
1783 if (!BLOCK_FUNCTION (block
))
1785 for (sym
= dict_iter_name_first (BLOCK_DICT (block
), name
, &iter
);
1787 sym
= dict_iter_name_next (name
, &iter
))
1789 if (SYMBOL_DOMAIN (sym
) == domain
1790 && (linkage_name
!= NULL
1791 ? strcmp (SYMBOL_LINKAGE_NAME (sym
), linkage_name
) == 0 : 1))
1798 /* Note that parameter symbols do not always show up last in the
1799 list; this loop makes sure to take anything else other than
1800 parameter symbols first; it only uses parameter symbols as a
1801 last resort. Note that this only takes up extra computation
1804 struct symbol
*sym_found
= NULL
;
1806 for (sym
= dict_iter_name_first (BLOCK_DICT (block
), name
, &iter
);
1808 sym
= dict_iter_name_next (name
, &iter
))
1810 if (SYMBOL_DOMAIN (sym
) == domain
1811 && (linkage_name
!= NULL
1812 ? strcmp (SYMBOL_LINKAGE_NAME (sym
), linkage_name
) == 0 : 1))
1815 if (SYMBOL_CLASS (sym
) != LOC_ARG
&&
1816 SYMBOL_CLASS (sym
) != LOC_LOCAL_ARG
&&
1817 SYMBOL_CLASS (sym
) != LOC_REF_ARG
&&
1818 SYMBOL_CLASS (sym
) != LOC_REGPARM
&&
1819 SYMBOL_CLASS (sym
) != LOC_REGPARM_ADDR
&&
1820 SYMBOL_CLASS (sym
) != LOC_BASEREG_ARG
&&
1821 SYMBOL_CLASS (sym
) != LOC_COMPUTED_ARG
)
1827 return (sym_found
); /* Will be NULL if not found. */
1831 /* Find the symtab associated with PC and SECTION. Look through the
1832 psymtabs and read in another symtab if necessary. */
1835 find_pc_sect_symtab (CORE_ADDR pc
, asection
*section
)
1838 struct blockvector
*bv
;
1839 struct symtab
*s
= NULL
;
1840 struct symtab
*best_s
= NULL
;
1841 struct partial_symtab
*ps
;
1842 struct objfile
*objfile
;
1843 CORE_ADDR distance
= 0;
1844 struct minimal_symbol
*msymbol
;
1846 /* If we know that this is not a text address, return failure. This is
1847 necessary because we loop based on the block's high and low code
1848 addresses, which do not include the data ranges, and because
1849 we call find_pc_sect_psymtab which has a similar restriction based
1850 on the partial_symtab's texthigh and textlow. */
1851 msymbol
= lookup_minimal_symbol_by_pc_section (pc
, section
);
1853 && (msymbol
->type
== mst_data
1854 || msymbol
->type
== mst_bss
1855 || msymbol
->type
== mst_abs
1856 || msymbol
->type
== mst_file_data
1857 || msymbol
->type
== mst_file_bss
))
1860 /* Search all symtabs for the one whose file contains our address, and which
1861 is the smallest of all the ones containing the address. This is designed
1862 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1863 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1864 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1866 This happens for native ecoff format, where code from included files
1867 gets its own symtab. The symtab for the included file should have
1868 been read in already via the dependency mechanism.
1869 It might be swifter to create several symtabs with the same name
1870 like xcoff does (I'm not sure).
1872 It also happens for objfiles that have their functions reordered.
1873 For these, the symtab we are looking for is not necessarily read in. */
1875 ALL_SYMTABS (objfile
, s
)
1877 bv
= BLOCKVECTOR (s
);
1878 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1880 if (BLOCK_START (b
) <= pc
1881 && BLOCK_END (b
) > pc
1883 || BLOCK_END (b
) - BLOCK_START (b
) < distance
))
1885 /* For an objfile that has its functions reordered,
1886 find_pc_psymtab will find the proper partial symbol table
1887 and we simply return its corresponding symtab. */
1888 /* In order to better support objfiles that contain both
1889 stabs and coff debugging info, we continue on if a psymtab
1891 if ((objfile
->flags
& OBJF_REORDERED
) && objfile
->psymtabs
)
1893 ps
= find_pc_sect_psymtab (pc
, section
);
1895 return PSYMTAB_TO_SYMTAB (ps
);
1899 struct dict_iterator iter
;
1900 struct symbol
*sym
= NULL
;
1902 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1904 fixup_symbol_section (sym
, objfile
);
1905 if (section
== SYMBOL_BFD_SECTION (sym
))
1909 continue; /* no symbol in this symtab matches section */
1911 distance
= BLOCK_END (b
) - BLOCK_START (b
);
1920 ps
= find_pc_sect_psymtab (pc
, section
);
1924 /* Might want to error() here (in case symtab is corrupt and
1925 will cause a core dump), but maybe we can successfully
1926 continue, so let's not. */
1928 (Internal error: pc 0x%s in read in psymtab, but not in symtab.)\n"),
1930 s
= PSYMTAB_TO_SYMTAB (ps
);
1935 /* Find the symtab associated with PC. Look through the psymtabs and
1936 read in another symtab if necessary. Backward compatibility, no section */
1939 find_pc_symtab (CORE_ADDR pc
)
1941 return find_pc_sect_symtab (pc
, find_pc_mapped_section (pc
));
1945 /* Find the source file and line number for a given PC value and SECTION.
1946 Return a structure containing a symtab pointer, a line number,
1947 and a pc range for the entire source line.
1948 The value's .pc field is NOT the specified pc.
1949 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1950 use the line that ends there. Otherwise, in that case, the line
1951 that begins there is used. */
1953 /* The big complication here is that a line may start in one file, and end just
1954 before the start of another file. This usually occurs when you #include
1955 code in the middle of a subroutine. To properly find the end of a line's PC
1956 range, we must search all symtabs associated with this compilation unit, and
1957 find the one whose first PC is closer than that of the next line in this
1960 /* If it's worth the effort, we could be using a binary search. */
1962 struct symtab_and_line
1963 find_pc_sect_line (CORE_ADDR pc
, struct bfd_section
*section
, int notcurrent
)
1966 struct linetable
*l
;
1969 struct linetable_entry
*item
;
1970 struct symtab_and_line val
;
1971 struct blockvector
*bv
;
1972 struct minimal_symbol
*msymbol
;
1973 struct minimal_symbol
*mfunsym
;
1975 /* Info on best line seen so far, and where it starts, and its file. */
1977 struct linetable_entry
*best
= NULL
;
1978 CORE_ADDR best_end
= 0;
1979 struct symtab
*best_symtab
= 0;
1981 /* Store here the first line number
1982 of a file which contains the line at the smallest pc after PC.
1983 If we don't find a line whose range contains PC,
1984 we will use a line one less than this,
1985 with a range from the start of that file to the first line's pc. */
1986 struct linetable_entry
*alt
= NULL
;
1987 struct symtab
*alt_symtab
= 0;
1989 /* Info on best line seen in this file. */
1991 struct linetable_entry
*prev
;
1993 /* If this pc is not from the current frame,
1994 it is the address of the end of a call instruction.
1995 Quite likely that is the start of the following statement.
1996 But what we want is the statement containing the instruction.
1997 Fudge the pc to make sure we get that. */
1999 init_sal (&val
); /* initialize to zeroes */
2001 /* It's tempting to assume that, if we can't find debugging info for
2002 any function enclosing PC, that we shouldn't search for line
2003 number info, either. However, GAS can emit line number info for
2004 assembly files --- very helpful when debugging hand-written
2005 assembly code. In such a case, we'd have no debug info for the
2006 function, but we would have line info. */
2011 /* elz: added this because this function returned the wrong
2012 information if the pc belongs to a stub (import/export)
2013 to call a shlib function. This stub would be anywhere between
2014 two functions in the target, and the line info was erroneously
2015 taken to be the one of the line before the pc.
2017 /* RT: Further explanation:
2019 * We have stubs (trampolines) inserted between procedures.
2021 * Example: "shr1" exists in a shared library, and a "shr1" stub also
2022 * exists in the main image.
2024 * In the minimal symbol table, we have a bunch of symbols
2025 * sorted by start address. The stubs are marked as "trampoline",
2026 * the others appear as text. E.g.:
2028 * Minimal symbol table for main image
2029 * main: code for main (text symbol)
2030 * shr1: stub (trampoline symbol)
2031 * foo: code for foo (text symbol)
2033 * Minimal symbol table for "shr1" image:
2035 * shr1: code for shr1 (text symbol)
2038 * So the code below is trying to detect if we are in the stub
2039 * ("shr1" stub), and if so, find the real code ("shr1" trampoline),
2040 * and if found, do the symbolization from the real-code address
2041 * rather than the stub address.
2043 * Assumptions being made about the minimal symbol table:
2044 * 1. lookup_minimal_symbol_by_pc() will return a trampoline only
2045 * if we're really in the trampoline. If we're beyond it (say
2046 * we're in "foo" in the above example), it'll have a closer
2047 * symbol (the "foo" text symbol for example) and will not
2048 * return the trampoline.
2049 * 2. lookup_minimal_symbol_text() will find a real text symbol
2050 * corresponding to the trampoline, and whose address will
2051 * be different than the trampoline address. I put in a sanity
2052 * check for the address being the same, to avoid an
2053 * infinite recursion.
2055 msymbol
= lookup_minimal_symbol_by_pc (pc
);
2056 if (msymbol
!= NULL
)
2057 if (MSYMBOL_TYPE (msymbol
) == mst_solib_trampoline
)
2059 mfunsym
= lookup_minimal_symbol_text (SYMBOL_LINKAGE_NAME (msymbol
),
2061 if (mfunsym
== NULL
)
2062 /* I eliminated this warning since it is coming out
2063 * in the following situation:
2064 * gdb shmain // test program with shared libraries
2065 * (gdb) break shr1 // function in shared lib
2066 * Warning: In stub for ...
2067 * In the above situation, the shared lib is not loaded yet,
2068 * so of course we can't find the real func/line info,
2069 * but the "break" still works, and the warning is annoying.
2070 * So I commented out the warning. RT */
2071 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_LINKAGE_NAME (msymbol)) */ ;
2073 else if (SYMBOL_VALUE (mfunsym
) == SYMBOL_VALUE (msymbol
))
2074 /* Avoid infinite recursion */
2075 /* See above comment about why warning is commented out */
2076 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_LINKAGE_NAME (msymbol)) */ ;
2079 return find_pc_line (SYMBOL_VALUE (mfunsym
), 0);
2083 s
= find_pc_sect_symtab (pc
, section
);
2086 /* if no symbol information, return previous pc */
2093 bv
= BLOCKVECTOR (s
);
2095 /* Look at all the symtabs that share this blockvector.
2096 They all have the same apriori range, that we found was right;
2097 but they have different line tables. */
2099 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
2101 /* Find the best line in this symtab. */
2108 /* I think len can be zero if the symtab lacks line numbers
2109 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
2110 I'm not sure which, and maybe it depends on the symbol
2116 item
= l
->item
; /* Get first line info */
2118 /* Is this file's first line closer than the first lines of other files?
2119 If so, record this file, and its first line, as best alternate. */
2120 if (item
->pc
> pc
&& (!alt
|| item
->pc
< alt
->pc
))
2126 for (i
= 0; i
< len
; i
++, item
++)
2128 /* Leave prev pointing to the linetable entry for the last line
2129 that started at or before PC. */
2136 /* At this point, prev points at the line whose start addr is <= pc, and
2137 item points at the next line. If we ran off the end of the linetable
2138 (pc >= start of the last line), then prev == item. If pc < start of
2139 the first line, prev will not be set. */
2141 /* Is this file's best line closer than the best in the other files?
2142 If so, record this file, and its best line, as best so far. Don't
2143 save prev if it represents the end of a function (i.e. line number
2144 0) instead of a real line. */
2146 if (prev
&& prev
->line
&& (!best
|| prev
->pc
> best
->pc
))
2151 /* Discard BEST_END if it's before the PC of the current BEST. */
2152 if (best_end
<= best
->pc
)
2156 /* If another line (denoted by ITEM) is in the linetable and its
2157 PC is after BEST's PC, but before the current BEST_END, then
2158 use ITEM's PC as the new best_end. */
2159 if (best
&& i
< len
&& item
->pc
> best
->pc
2160 && (best_end
== 0 || best_end
> item
->pc
))
2161 best_end
= item
->pc
;
2167 { /* If we didn't find any line # info, just
2173 val
.symtab
= alt_symtab
;
2174 val
.line
= alt
->line
- 1;
2176 /* Don't return line 0, that means that we didn't find the line. */
2180 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
2184 else if (best
->line
== 0)
2186 /* If our best fit is in a range of PC's for which no line
2187 number info is available (line number is zero) then we didn't
2188 find any valid line information. */
2193 val
.symtab
= best_symtab
;
2194 val
.line
= best
->line
;
2196 if (best_end
&& (!alt
|| best_end
< alt
->pc
))
2201 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
2203 val
.section
= section
;
2207 /* Backward compatibility (no section) */
2209 struct symtab_and_line
2210 find_pc_line (CORE_ADDR pc
, int notcurrent
)
2214 section
= find_pc_overlay (pc
);
2215 if (pc_in_unmapped_range (pc
, section
))
2216 pc
= overlay_mapped_address (pc
, section
);
2217 return find_pc_sect_line (pc
, section
, notcurrent
);
2220 /* Find line number LINE in any symtab whose name is the same as
2223 If found, return the symtab that contains the linetable in which it was
2224 found, set *INDEX to the index in the linetable of the best entry
2225 found, and set *EXACT_MATCH nonzero if the value returned is an
2228 If not found, return NULL. */
2231 find_line_symtab (struct symtab
*symtab
, int line
, int *index
, int *exact_match
)
2235 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
2239 struct linetable
*best_linetable
;
2240 struct symtab
*best_symtab
;
2242 /* First try looking it up in the given symtab. */
2243 best_linetable
= LINETABLE (symtab
);
2244 best_symtab
= symtab
;
2245 best_index
= find_line_common (best_linetable
, line
, &exact
);
2246 if (best_index
< 0 || !exact
)
2248 /* Didn't find an exact match. So we better keep looking for
2249 another symtab with the same name. In the case of xcoff,
2250 multiple csects for one source file (produced by IBM's FORTRAN
2251 compiler) produce multiple symtabs (this is unavoidable
2252 assuming csects can be at arbitrary places in memory and that
2253 the GLOBAL_BLOCK of a symtab has a begin and end address). */
2255 /* BEST is the smallest linenumber > LINE so far seen,
2256 or 0 if none has been seen so far.
2257 BEST_INDEX and BEST_LINETABLE identify the item for it. */
2260 struct objfile
*objfile
;
2263 if (best_index
>= 0)
2264 best
= best_linetable
->item
[best_index
].line
;
2268 ALL_SYMTABS (objfile
, s
)
2270 struct linetable
*l
;
2273 if (strcmp (symtab
->filename
, s
->filename
) != 0)
2276 ind
= find_line_common (l
, line
, &exact
);
2286 if (best
== 0 || l
->item
[ind
].line
< best
)
2288 best
= l
->item
[ind
].line
;
2301 *index
= best_index
;
2303 *exact_match
= exact
;
2308 /* Set the PC value for a given source file and line number and return true.
2309 Returns zero for invalid line number (and sets the PC to 0).
2310 The source file is specified with a struct symtab. */
2313 find_line_pc (struct symtab
*symtab
, int line
, CORE_ADDR
*pc
)
2315 struct linetable
*l
;
2322 symtab
= find_line_symtab (symtab
, line
, &ind
, NULL
);
2325 l
= LINETABLE (symtab
);
2326 *pc
= l
->item
[ind
].pc
;
2333 /* Find the range of pc values in a line.
2334 Store the starting pc of the line into *STARTPTR
2335 and the ending pc (start of next line) into *ENDPTR.
2336 Returns 1 to indicate success.
2337 Returns 0 if could not find the specified line. */
2340 find_line_pc_range (struct symtab_and_line sal
, CORE_ADDR
*startptr
,
2343 CORE_ADDR startaddr
;
2344 struct symtab_and_line found_sal
;
2347 if (startaddr
== 0 && !find_line_pc (sal
.symtab
, sal
.line
, &startaddr
))
2350 /* This whole function is based on address. For example, if line 10 has
2351 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
2352 "info line *0x123" should say the line goes from 0x100 to 0x200
2353 and "info line *0x355" should say the line goes from 0x300 to 0x400.
2354 This also insures that we never give a range like "starts at 0x134
2355 and ends at 0x12c". */
2357 found_sal
= find_pc_sect_line (startaddr
, sal
.section
, 0);
2358 if (found_sal
.line
!= sal
.line
)
2360 /* The specified line (sal) has zero bytes. */
2361 *startptr
= found_sal
.pc
;
2362 *endptr
= found_sal
.pc
;
2366 *startptr
= found_sal
.pc
;
2367 *endptr
= found_sal
.end
;
2372 /* Given a line table and a line number, return the index into the line
2373 table for the pc of the nearest line whose number is >= the specified one.
2374 Return -1 if none is found. The value is >= 0 if it is an index.
2376 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
2379 find_line_common (struct linetable
*l
, int lineno
,
2385 /* BEST is the smallest linenumber > LINENO so far seen,
2386 or 0 if none has been seen so far.
2387 BEST_INDEX identifies the item for it. */
2389 int best_index
= -1;
2398 for (i
= 0; i
< len
; i
++)
2400 struct linetable_entry
*item
= &(l
->item
[i
]);
2402 if (item
->line
== lineno
)
2404 /* Return the first (lowest address) entry which matches. */
2409 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
2416 /* If we got here, we didn't get an exact match. */
2423 find_pc_line_pc_range (CORE_ADDR pc
, CORE_ADDR
*startptr
, CORE_ADDR
*endptr
)
2425 struct symtab_and_line sal
;
2426 sal
= find_pc_line (pc
, 0);
2429 return sal
.symtab
!= 0;
2432 /* Given a function symbol SYM, find the symtab and line for the start
2434 If the argument FUNFIRSTLINE is nonzero, we want the first line
2435 of real code inside the function. */
2437 struct symtab_and_line
2438 find_function_start_sal (struct symbol
*sym
, int funfirstline
)
2441 struct symtab_and_line sal
;
2443 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
2444 fixup_symbol_section (sym
, NULL
);
2446 { /* skip "first line" of function (which is actually its prologue) */
2447 asection
*section
= SYMBOL_BFD_SECTION (sym
);
2448 /* If function is in an unmapped overlay, use its unmapped LMA
2449 address, so that SKIP_PROLOGUE has something unique to work on */
2450 if (section_is_overlay (section
) &&
2451 !section_is_mapped (section
))
2452 pc
= overlay_unmapped_address (pc
, section
);
2454 pc
+= DEPRECATED_FUNCTION_START_OFFSET
;
2455 pc
= SKIP_PROLOGUE (pc
);
2457 /* For overlays, map pc back into its mapped VMA range */
2458 pc
= overlay_mapped_address (pc
, section
);
2460 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
2462 /* Check if SKIP_PROLOGUE left us in mid-line, and the next
2463 line is still part of the same function. */
2465 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) <= sal
.end
2466 && sal
.end
< BLOCK_END (SYMBOL_BLOCK_VALUE (sym
)))
2468 /* First pc of next line */
2470 /* Recalculate the line number (might not be N+1). */
2471 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
2478 /* If P is of the form "operator[ \t]+..." where `...' is
2479 some legitimate operator text, return a pointer to the
2480 beginning of the substring of the operator text.
2481 Otherwise, return "". */
2483 operator_chars (char *p
, char **end
)
2486 if (strncmp (p
, "operator", 8))
2490 /* Don't get faked out by `operator' being part of a longer
2492 if (isalpha (*p
) || *p
== '_' || *p
== '$' || *p
== '\0')
2495 /* Allow some whitespace between `operator' and the operator symbol. */
2496 while (*p
== ' ' || *p
== '\t')
2499 /* Recognize 'operator TYPENAME'. */
2501 if (isalpha (*p
) || *p
== '_' || *p
== '$')
2504 while (isalnum (*q
) || *q
== '_' || *q
== '$')
2513 case '\\': /* regexp quoting */
2516 if (p
[2] == '=') /* 'operator\*=' */
2518 else /* 'operator\*' */
2522 else if (p
[1] == '[')
2525 error (_("mismatched quoting on brackets, try 'operator\\[\\]'"));
2526 else if (p
[2] == '\\' && p
[3] == ']')
2528 *end
= p
+ 4; /* 'operator\[\]' */
2532 error (_("nothing is allowed between '[' and ']'"));
2536 /* Gratuitous qoute: skip it and move on. */
2558 if (p
[0] == '-' && p
[1] == '>')
2560 /* Struct pointer member operator 'operator->'. */
2563 *end
= p
+ 3; /* 'operator->*' */
2566 else if (p
[2] == '\\')
2568 *end
= p
+ 4; /* Hopefully 'operator->\*' */
2573 *end
= p
+ 2; /* 'operator->' */
2577 if (p
[1] == '=' || p
[1] == p
[0])
2588 error (_("`operator ()' must be specified without whitespace in `()'"));
2593 error (_("`operator ?:' must be specified without whitespace in `?:'"));
2598 error (_("`operator []' must be specified without whitespace in `[]'"));
2602 error (_("`operator %s' not supported"), p
);
2611 /* If FILE is not already in the table of files, return zero;
2612 otherwise return non-zero. Optionally add FILE to the table if ADD
2613 is non-zero. If *FIRST is non-zero, forget the old table
2616 filename_seen (const char *file
, int add
, int *first
)
2618 /* Table of files seen so far. */
2619 static const char **tab
= NULL
;
2620 /* Allocated size of tab in elements.
2621 Start with one 256-byte block (when using GNU malloc.c).
2622 24 is the malloc overhead when range checking is in effect. */
2623 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
2624 /* Current size of tab in elements. */
2625 static int tab_cur_size
;
2631 tab
= (const char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
2635 /* Is FILE in tab? */
2636 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
2637 if (strcmp (*p
, file
) == 0)
2640 /* No; maybe add it to tab. */
2643 if (tab_cur_size
== tab_alloc_size
)
2645 tab_alloc_size
*= 2;
2646 tab
= (const char **) xrealloc ((char *) tab
,
2647 tab_alloc_size
* sizeof (*tab
));
2649 tab
[tab_cur_size
++] = file
;
2655 /* Slave routine for sources_info. Force line breaks at ,'s.
2656 NAME is the name to print and *FIRST is nonzero if this is the first
2657 name printed. Set *FIRST to zero. */
2659 output_source_filename (const char *name
, int *first
)
2661 /* Since a single source file can result in several partial symbol
2662 tables, we need to avoid printing it more than once. Note: if
2663 some of the psymtabs are read in and some are not, it gets
2664 printed both under "Source files for which symbols have been
2665 read" and "Source files for which symbols will be read in on
2666 demand". I consider this a reasonable way to deal with the
2667 situation. I'm not sure whether this can also happen for
2668 symtabs; it doesn't hurt to check. */
2670 /* Was NAME already seen? */
2671 if (filename_seen (name
, 1, first
))
2673 /* Yes; don't print it again. */
2676 /* No; print it and reset *FIRST. */
2683 printf_filtered (", ");
2687 fputs_filtered (name
, gdb_stdout
);
2691 sources_info (char *ignore
, int from_tty
)
2694 struct partial_symtab
*ps
;
2695 struct objfile
*objfile
;
2698 if (!have_full_symbols () && !have_partial_symbols ())
2700 error (_("No symbol table is loaded. Use the \"file\" command."));
2703 printf_filtered ("Source files for which symbols have been read in:\n\n");
2706 ALL_SYMTABS (objfile
, s
)
2708 const char *fullname
= symtab_to_fullname (s
);
2709 output_source_filename (fullname
? fullname
: s
->filename
, &first
);
2711 printf_filtered ("\n\n");
2713 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2716 ALL_PSYMTABS (objfile
, ps
)
2720 const char *fullname
= psymtab_to_fullname (ps
);
2721 output_source_filename (fullname
? fullname
: ps
->filename
, &first
);
2724 printf_filtered ("\n");
2728 file_matches (char *file
, char *files
[], int nfiles
)
2732 if (file
!= NULL
&& nfiles
!= 0)
2734 for (i
= 0; i
< nfiles
; i
++)
2736 if (strcmp (files
[i
], lbasename (file
)) == 0)
2740 else if (nfiles
== 0)
2745 /* Free any memory associated with a search. */
2747 free_search_symbols (struct symbol_search
*symbols
)
2749 struct symbol_search
*p
;
2750 struct symbol_search
*next
;
2752 for (p
= symbols
; p
!= NULL
; p
= next
)
2760 do_free_search_symbols_cleanup (void *symbols
)
2762 free_search_symbols (symbols
);
2766 make_cleanup_free_search_symbols (struct symbol_search
*symbols
)
2768 return make_cleanup (do_free_search_symbols_cleanup
, symbols
);
2771 /* Helper function for sort_search_symbols and qsort. Can only
2772 sort symbols, not minimal symbols. */
2774 compare_search_syms (const void *sa
, const void *sb
)
2776 struct symbol_search
**sym_a
= (struct symbol_search
**) sa
;
2777 struct symbol_search
**sym_b
= (struct symbol_search
**) sb
;
2779 return strcmp (SYMBOL_PRINT_NAME ((*sym_a
)->symbol
),
2780 SYMBOL_PRINT_NAME ((*sym_b
)->symbol
));
2783 /* Sort the ``nfound'' symbols in the list after prevtail. Leave
2784 prevtail where it is, but update its next pointer to point to
2785 the first of the sorted symbols. */
2786 static struct symbol_search
*
2787 sort_search_symbols (struct symbol_search
*prevtail
, int nfound
)
2789 struct symbol_search
**symbols
, *symp
, *old_next
;
2792 symbols
= (struct symbol_search
**) xmalloc (sizeof (struct symbol_search
*)
2794 symp
= prevtail
->next
;
2795 for (i
= 0; i
< nfound
; i
++)
2800 /* Generally NULL. */
2803 qsort (symbols
, nfound
, sizeof (struct symbol_search
*),
2804 compare_search_syms
);
2807 for (i
= 0; i
< nfound
; i
++)
2809 symp
->next
= symbols
[i
];
2812 symp
->next
= old_next
;
2818 /* Search the symbol table for matches to the regular expression REGEXP,
2819 returning the results in *MATCHES.
2821 Only symbols of KIND are searched:
2822 FUNCTIONS_DOMAIN - search all functions
2823 TYPES_DOMAIN - search all type names
2824 METHODS_DOMAIN - search all methods NOT IMPLEMENTED
2825 VARIABLES_DOMAIN - search all symbols, excluding functions, type names,
2826 and constants (enums)
2828 free_search_symbols should be called when *MATCHES is no longer needed.
2830 The results are sorted locally; each symtab's global and static blocks are
2831 separately alphabetized.
2834 search_symbols (char *regexp
, domain_enum kind
, int nfiles
, char *files
[],
2835 struct symbol_search
**matches
)
2838 struct partial_symtab
*ps
;
2839 struct blockvector
*bv
;
2840 struct blockvector
*prev_bv
= 0;
2843 struct dict_iterator iter
;
2845 struct partial_symbol
**psym
;
2846 struct objfile
*objfile
;
2847 struct minimal_symbol
*msymbol
;
2850 static enum minimal_symbol_type types
[]
2852 {mst_data
, mst_text
, mst_abs
, mst_unknown
};
2853 static enum minimal_symbol_type types2
[]
2855 {mst_bss
, mst_file_text
, mst_abs
, mst_unknown
};
2856 static enum minimal_symbol_type types3
[]
2858 {mst_file_data
, mst_solib_trampoline
, mst_abs
, mst_unknown
};
2859 static enum minimal_symbol_type types4
[]
2861 {mst_file_bss
, mst_text
, mst_abs
, mst_unknown
};
2862 enum minimal_symbol_type ourtype
;
2863 enum minimal_symbol_type ourtype2
;
2864 enum minimal_symbol_type ourtype3
;
2865 enum minimal_symbol_type ourtype4
;
2866 struct symbol_search
*sr
;
2867 struct symbol_search
*psr
;
2868 struct symbol_search
*tail
;
2869 struct cleanup
*old_chain
= NULL
;
2871 if (kind
< VARIABLES_DOMAIN
)
2872 error (_("must search on specific domain"));
2874 ourtype
= types
[(int) (kind
- VARIABLES_DOMAIN
)];
2875 ourtype2
= types2
[(int) (kind
- VARIABLES_DOMAIN
)];
2876 ourtype3
= types3
[(int) (kind
- VARIABLES_DOMAIN
)];
2877 ourtype4
= types4
[(int) (kind
- VARIABLES_DOMAIN
)];
2879 sr
= *matches
= NULL
;
2884 /* Make sure spacing is right for C++ operators.
2885 This is just a courtesy to make the matching less sensitive
2886 to how many spaces the user leaves between 'operator'
2887 and <TYPENAME> or <OPERATOR>. */
2889 char *opname
= operator_chars (regexp
, &opend
);
2892 int fix
= -1; /* -1 means ok; otherwise number of spaces needed. */
2893 if (isalpha (*opname
) || *opname
== '_' || *opname
== '$')
2895 /* There should 1 space between 'operator' and 'TYPENAME'. */
2896 if (opname
[-1] != ' ' || opname
[-2] == ' ')
2901 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2902 if (opname
[-1] == ' ')
2905 /* If wrong number of spaces, fix it. */
2908 char *tmp
= (char *) alloca (8 + fix
+ strlen (opname
) + 1);
2909 sprintf (tmp
, "operator%.*s%s", fix
, " ", opname
);
2914 if (0 != (val
= re_comp (regexp
)))
2915 error (_("Invalid regexp (%s): %s"), val
, regexp
);
2918 /* Search through the partial symtabs *first* for all symbols
2919 matching the regexp. That way we don't have to reproduce all of
2920 the machinery below. */
2922 ALL_PSYMTABS (objfile
, ps
)
2924 struct partial_symbol
**bound
, **gbound
, **sbound
;
2930 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2931 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2934 /* Go through all of the symbols stored in a partial
2935 symtab in one loop. */
2936 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2941 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2943 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2954 /* If it would match (logic taken from loop below)
2955 load the file and go on to the next one */
2956 if (file_matches (ps
->filename
, files
, nfiles
)
2958 || re_exec (SYMBOL_NATURAL_NAME (*psym
)) != 0)
2959 && ((kind
== VARIABLES_DOMAIN
&& SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
2960 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
2961 || (kind
== FUNCTIONS_DOMAIN
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
2962 || (kind
== TYPES_DOMAIN
&& SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
)
2963 || (kind
== METHODS_DOMAIN
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
))))
2965 PSYMTAB_TO_SYMTAB (ps
);
2973 /* Here, we search through the minimal symbol tables for functions
2974 and variables that match, and force their symbols to be read.
2975 This is in particular necessary for demangled variable names,
2976 which are no longer put into the partial symbol tables.
2977 The symbol will then be found during the scan of symtabs below.
2979 For functions, find_pc_symtab should succeed if we have debug info
2980 for the function, for variables we have to call lookup_symbol
2981 to determine if the variable has debug info.
2982 If the lookup fails, set found_misc so that we will rescan to print
2983 any matching symbols without debug info.
2986 if (nfiles
== 0 && (kind
== VARIABLES_DOMAIN
|| kind
== FUNCTIONS_DOMAIN
))
2988 ALL_MSYMBOLS (objfile
, msymbol
)
2990 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
2991 MSYMBOL_TYPE (msymbol
) == ourtype2
||
2992 MSYMBOL_TYPE (msymbol
) == ourtype3
||
2993 MSYMBOL_TYPE (msymbol
) == ourtype4
)
2996 || re_exec (SYMBOL_NATURAL_NAME (msymbol
)) != 0)
2998 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
)))
3000 /* FIXME: carlton/2003-02-04: Given that the
3001 semantics of lookup_symbol keeps on changing
3002 slightly, it would be a nice idea if we had a
3003 function lookup_symbol_minsym that found the
3004 symbol associated to a given minimal symbol (if
3006 if (kind
== FUNCTIONS_DOMAIN
3007 || lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol
),
3008 (struct block
*) NULL
,
3010 0, (struct symtab
**) NULL
) == NULL
)
3018 ALL_SYMTABS (objfile
, s
)
3020 bv
= BLOCKVECTOR (s
);
3021 /* Often many files share a blockvector.
3022 Scan each blockvector only once so that
3023 we don't get every symbol many times.
3024 It happens that the first symtab in the list
3025 for any given blockvector is the main file. */
3027 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
3029 struct symbol_search
*prevtail
= tail
;
3031 b
= BLOCKVECTOR_BLOCK (bv
, i
);
3032 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
3035 if (file_matches (s
->filename
, files
, nfiles
)
3037 || re_exec (SYMBOL_NATURAL_NAME (sym
)) != 0)
3038 && ((kind
== VARIABLES_DOMAIN
&& SYMBOL_CLASS (sym
) != LOC_TYPEDEF
3039 && SYMBOL_CLASS (sym
) != LOC_BLOCK
3040 && SYMBOL_CLASS (sym
) != LOC_CONST
)
3041 || (kind
== FUNCTIONS_DOMAIN
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3042 || (kind
== TYPES_DOMAIN
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3043 || (kind
== METHODS_DOMAIN
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
))))
3046 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
3050 psr
->msymbol
= NULL
;
3062 if (prevtail
== NULL
)
3064 struct symbol_search dummy
;
3067 tail
= sort_search_symbols (&dummy
, nfound
);
3070 old_chain
= make_cleanup_free_search_symbols (sr
);
3073 tail
= sort_search_symbols (prevtail
, nfound
);
3079 /* If there are no eyes, avoid all contact. I mean, if there are
3080 no debug symbols, then print directly from the msymbol_vector. */
3082 if (found_misc
|| kind
!= FUNCTIONS_DOMAIN
)
3084 ALL_MSYMBOLS (objfile
, msymbol
)
3086 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
3087 MSYMBOL_TYPE (msymbol
) == ourtype2
||
3088 MSYMBOL_TYPE (msymbol
) == ourtype3
||
3089 MSYMBOL_TYPE (msymbol
) == ourtype4
)
3092 || re_exec (SYMBOL_NATURAL_NAME (msymbol
)) != 0)
3094 /* Functions: Look up by address. */
3095 if (kind
!= FUNCTIONS_DOMAIN
||
3096 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
))))
3098 /* Variables/Absolutes: Look up by name */
3099 if (lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol
),
3100 (struct block
*) NULL
, VAR_DOMAIN
,
3101 0, (struct symtab
**) NULL
) == NULL
)
3104 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
3106 psr
->msymbol
= msymbol
;
3113 old_chain
= make_cleanup_free_search_symbols (sr
);
3127 discard_cleanups (old_chain
);
3130 /* Helper function for symtab_symbol_info, this function uses
3131 the data returned from search_symbols() to print information
3132 regarding the match to gdb_stdout.
3135 print_symbol_info (domain_enum kind
, struct symtab
*s
, struct symbol
*sym
,
3136 int block
, char *last
)
3138 if (last
== NULL
|| strcmp (last
, s
->filename
) != 0)
3140 fputs_filtered ("\nFile ", gdb_stdout
);
3141 fputs_filtered (s
->filename
, gdb_stdout
);
3142 fputs_filtered (":\n", gdb_stdout
);
3145 if (kind
!= TYPES_DOMAIN
&& block
== STATIC_BLOCK
)
3146 printf_filtered ("static ");
3148 /* Typedef that is not a C++ class */
3149 if (kind
== TYPES_DOMAIN
3150 && SYMBOL_DOMAIN (sym
) != STRUCT_DOMAIN
)
3151 typedef_print (SYMBOL_TYPE (sym
), sym
, gdb_stdout
);
3152 /* variable, func, or typedef-that-is-c++-class */
3153 else if (kind
< TYPES_DOMAIN
||
3154 (kind
== TYPES_DOMAIN
&&
3155 SYMBOL_DOMAIN (sym
) == STRUCT_DOMAIN
))
3157 type_print (SYMBOL_TYPE (sym
),
3158 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3159 ? "" : SYMBOL_PRINT_NAME (sym
)),
3162 printf_filtered (";\n");
3166 /* This help function for symtab_symbol_info() prints information
3167 for non-debugging symbols to gdb_stdout.
3170 print_msymbol_info (struct minimal_symbol
*msymbol
)
3174 if (TARGET_ADDR_BIT
<= 32)
3175 tmp
= hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol
)
3176 & (CORE_ADDR
) 0xffffffff,
3179 tmp
= hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol
),
3181 printf_filtered ("%s %s\n",
3182 tmp
, SYMBOL_PRINT_NAME (msymbol
));
3185 /* This is the guts of the commands "info functions", "info types", and
3186 "info variables". It calls search_symbols to find all matches and then
3187 print_[m]symbol_info to print out some useful information about the
3191 symtab_symbol_info (char *regexp
, domain_enum kind
, int from_tty
)
3193 static char *classnames
[]
3195 {"variable", "function", "type", "method"};
3196 struct symbol_search
*symbols
;
3197 struct symbol_search
*p
;
3198 struct cleanup
*old_chain
;
3199 char *last_filename
= NULL
;
3202 /* must make sure that if we're interrupted, symbols gets freed */
3203 search_symbols (regexp
, kind
, 0, (char **) NULL
, &symbols
);
3204 old_chain
= make_cleanup_free_search_symbols (symbols
);
3206 printf_filtered (regexp
3207 ? "All %ss matching regular expression \"%s\":\n"
3208 : "All defined %ss:\n",
3209 classnames
[(int) (kind
- VARIABLES_DOMAIN
)], regexp
);
3211 for (p
= symbols
; p
!= NULL
; p
= p
->next
)
3215 if (p
->msymbol
!= NULL
)
3219 printf_filtered ("\nNon-debugging symbols:\n");
3222 print_msymbol_info (p
->msymbol
);
3226 print_symbol_info (kind
,
3231 last_filename
= p
->symtab
->filename
;
3235 do_cleanups (old_chain
);
3239 variables_info (char *regexp
, int from_tty
)
3241 symtab_symbol_info (regexp
, VARIABLES_DOMAIN
, from_tty
);
3245 functions_info (char *regexp
, int from_tty
)
3247 symtab_symbol_info (regexp
, FUNCTIONS_DOMAIN
, from_tty
);
3252 types_info (char *regexp
, int from_tty
)
3254 symtab_symbol_info (regexp
, TYPES_DOMAIN
, from_tty
);
3257 /* Breakpoint all functions matching regular expression. */
3260 rbreak_command_wrapper (char *regexp
, int from_tty
)
3262 rbreak_command (regexp
, from_tty
);
3266 rbreak_command (char *regexp
, int from_tty
)
3268 struct symbol_search
*ss
;
3269 struct symbol_search
*p
;
3270 struct cleanup
*old_chain
;
3272 search_symbols (regexp
, FUNCTIONS_DOMAIN
, 0, (char **) NULL
, &ss
);
3273 old_chain
= make_cleanup_free_search_symbols (ss
);
3275 for (p
= ss
; p
!= NULL
; p
= p
->next
)
3277 if (p
->msymbol
== NULL
)
3279 char *string
= alloca (strlen (p
->symtab
->filename
)
3280 + strlen (SYMBOL_LINKAGE_NAME (p
->symbol
))
3282 strcpy (string
, p
->symtab
->filename
);
3283 strcat (string
, ":'");
3284 strcat (string
, SYMBOL_LINKAGE_NAME (p
->symbol
));
3285 strcat (string
, "'");
3286 break_command (string
, from_tty
);
3287 print_symbol_info (FUNCTIONS_DOMAIN
,
3291 p
->symtab
->filename
);
3295 break_command (SYMBOL_LINKAGE_NAME (p
->msymbol
), from_tty
);
3296 printf_filtered ("<function, no debug info> %s;\n",
3297 SYMBOL_PRINT_NAME (p
->msymbol
));
3301 do_cleanups (old_chain
);
3305 /* Helper routine for make_symbol_completion_list. */
3307 static int return_val_size
;
3308 static int return_val_index
;
3309 static char **return_val
;
3311 #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
3312 completion_list_add_name \
3313 (SYMBOL_NATURAL_NAME (symbol), (sym_text), (len), (text), (word))
3315 /* Test to see if the symbol specified by SYMNAME (which is already
3316 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3317 characters. If so, add it to the current completion list. */
3320 completion_list_add_name (char *symname
, char *sym_text
, int sym_text_len
,
3321 char *text
, char *word
)
3326 /* clip symbols that cannot match */
3328 if (strncmp (symname
, sym_text
, sym_text_len
) != 0)
3333 /* We have a match for a completion, so add SYMNAME to the current list
3334 of matches. Note that the name is moved to freshly malloc'd space. */
3338 if (word
== sym_text
)
3340 new = xmalloc (strlen (symname
) + 5);
3341 strcpy (new, symname
);
3343 else if (word
> sym_text
)
3345 /* Return some portion of symname. */
3346 new = xmalloc (strlen (symname
) + 5);
3347 strcpy (new, symname
+ (word
- sym_text
));
3351 /* Return some of SYM_TEXT plus symname. */
3352 new = xmalloc (strlen (symname
) + (sym_text
- word
) + 5);
3353 strncpy (new, word
, sym_text
- word
);
3354 new[sym_text
- word
] = '\0';
3355 strcat (new, symname
);
3358 if (return_val_index
+ 3 > return_val_size
)
3360 newsize
= (return_val_size
*= 2) * sizeof (char *);
3361 return_val
= (char **) xrealloc ((char *) return_val
, newsize
);
3363 return_val
[return_val_index
++] = new;
3364 return_val
[return_val_index
] = NULL
;
3368 /* ObjC: In case we are completing on a selector, look as the msymbol
3369 again and feed all the selectors into the mill. */
3372 completion_list_objc_symbol (struct minimal_symbol
*msymbol
, char *sym_text
,
3373 int sym_text_len
, char *text
, char *word
)
3375 static char *tmp
= NULL
;
3376 static unsigned int tmplen
= 0;
3378 char *method
, *category
, *selector
;
3381 method
= SYMBOL_NATURAL_NAME (msymbol
);
3383 /* Is it a method? */
3384 if ((method
[0] != '-') && (method
[0] != '+'))
3387 if (sym_text
[0] == '[')
3388 /* Complete on shortened method method. */
3389 completion_list_add_name (method
+ 1, sym_text
, sym_text_len
, text
, word
);
3391 while ((strlen (method
) + 1) >= tmplen
)
3397 tmp
= xrealloc (tmp
, tmplen
);
3399 selector
= strchr (method
, ' ');
3400 if (selector
!= NULL
)
3403 category
= strchr (method
, '(');
3405 if ((category
!= NULL
) && (selector
!= NULL
))
3407 memcpy (tmp
, method
, (category
- method
));
3408 tmp
[category
- method
] = ' ';
3409 memcpy (tmp
+ (category
- method
) + 1, selector
, strlen (selector
) + 1);
3410 completion_list_add_name (tmp
, sym_text
, sym_text_len
, text
, word
);
3411 if (sym_text
[0] == '[')
3412 completion_list_add_name (tmp
+ 1, sym_text
, sym_text_len
, text
, word
);
3415 if (selector
!= NULL
)
3417 /* Complete on selector only. */
3418 strcpy (tmp
, selector
);
3419 tmp2
= strchr (tmp
, ']');
3423 completion_list_add_name (tmp
, sym_text
, sym_text_len
, text
, word
);
3427 /* Break the non-quoted text based on the characters which are in
3428 symbols. FIXME: This should probably be language-specific. */
3431 language_search_unquoted_string (char *text
, char *p
)
3433 for (; p
> text
; --p
)
3435 if (isalnum (p
[-1]) || p
[-1] == '_' || p
[-1] == '\0')
3439 if ((current_language
->la_language
== language_objc
))
3441 if (p
[-1] == ':') /* might be part of a method name */
3443 else if (p
[-1] == '[' && (p
[-2] == '-' || p
[-2] == '+'))
3444 p
-= 2; /* beginning of a method name */
3445 else if (p
[-1] == ' ' || p
[-1] == '(' || p
[-1] == ')')
3446 { /* might be part of a method name */
3449 /* Seeing a ' ' or a '(' is not conclusive evidence
3450 that we are in the middle of a method name. However,
3451 finding "-[" or "+[" should be pretty un-ambiguous.
3452 Unfortunately we have to find it now to decide. */
3455 if (isalnum (t
[-1]) || t
[-1] == '_' ||
3456 t
[-1] == ' ' || t
[-1] == ':' ||
3457 t
[-1] == '(' || t
[-1] == ')')
3462 if (t
[-1] == '[' && (t
[-2] == '-' || t
[-2] == '+'))
3463 p
= t
- 2; /* method name detected */
3464 /* else we leave with p unchanged */
3474 /* Return a NULL terminated array of all symbols (regardless of class)
3475 which begin by matching TEXT. If the answer is no symbols, then
3476 the return value is an array which contains only a NULL pointer.
3478 Problem: All of the symbols have to be copied because readline frees them.
3479 I'm not going to worry about this; hopefully there won't be that many. */
3482 make_symbol_completion_list (char *text
, char *word
)
3486 struct partial_symtab
*ps
;
3487 struct minimal_symbol
*msymbol
;
3488 struct objfile
*objfile
;
3489 struct block
*b
, *surrounding_static_block
= 0;
3490 struct dict_iterator iter
;
3492 struct partial_symbol
**psym
;
3493 /* The symbol we are completing on. Points in same buffer as text. */
3495 /* Length of sym_text. */
3498 /* Now look for the symbol we are supposed to complete on.
3499 FIXME: This should be language-specific. */
3503 char *quote_pos
= NULL
;
3505 /* First see if this is a quoted string. */
3507 for (p
= text
; *p
!= '\0'; ++p
)
3509 if (quote_found
!= '\0')
3511 if (*p
== quote_found
)
3512 /* Found close quote. */
3514 else if (*p
== '\\' && p
[1] == quote_found
)
3515 /* A backslash followed by the quote character
3516 doesn't end the string. */
3519 else if (*p
== '\'' || *p
== '"')
3525 if (quote_found
== '\'')
3526 /* A string within single quotes can be a symbol, so complete on it. */
3527 sym_text
= quote_pos
+ 1;
3528 else if (quote_found
== '"')
3529 /* A double-quoted string is never a symbol, nor does it make sense
3530 to complete it any other way. */
3532 return_val
= (char **) xmalloc (sizeof (char *));
3533 return_val
[0] = NULL
;
3538 /* It is not a quoted string. Break it based on the characters
3539 which are in symbols. */
3542 if (isalnum (p
[-1]) || p
[-1] == '_' || p
[-1] == '\0')
3551 sym_text_len
= strlen (sym_text
);
3553 return_val_size
= 100;
3554 return_val_index
= 0;
3555 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
3556 return_val
[0] = NULL
;
3558 /* Look through the partial symtabs for all symbols which begin
3559 by matching SYM_TEXT. Add each one that you find to the list. */
3561 ALL_PSYMTABS (objfile
, ps
)
3563 /* If the psymtab's been read in we'll get it when we search
3564 through the blockvector. */
3568 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
3569 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
3570 + ps
->n_global_syms
);
3573 /* If interrupted, then quit. */
3575 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3578 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
3579 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
3580 + ps
->n_static_syms
);
3584 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3588 /* At this point scan through the misc symbol vectors and add each
3589 symbol you find to the list. Eventually we want to ignore
3590 anything that isn't a text symbol (everything else will be
3591 handled by the psymtab code above). */
3593 ALL_MSYMBOLS (objfile
, msymbol
)
3596 COMPLETION_LIST_ADD_SYMBOL (msymbol
, sym_text
, sym_text_len
, text
, word
);
3598 completion_list_objc_symbol (msymbol
, sym_text
, sym_text_len
, text
, word
);
3601 /* Search upwards from currently selected frame (so that we can
3602 complete on local vars. */
3604 for (b
= get_selected_block (0); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
3606 if (!BLOCK_SUPERBLOCK (b
))
3608 surrounding_static_block
= b
; /* For elmin of dups */
3611 /* Also catch fields of types defined in this places which match our
3612 text string. Only complete on types visible from current context. */
3614 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
3617 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3618 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3620 struct type
*t
= SYMBOL_TYPE (sym
);
3621 enum type_code c
= TYPE_CODE (t
);
3623 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
3625 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
3627 if (TYPE_FIELD_NAME (t
, j
))
3629 completion_list_add_name (TYPE_FIELD_NAME (t
, j
),
3630 sym_text
, sym_text_len
, text
, word
);
3638 /* Go through the symtabs and check the externs and statics for
3639 symbols which match. */
3641 ALL_SYMTABS (objfile
, s
)
3644 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3645 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
3647 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3651 ALL_SYMTABS (objfile
, s
)
3654 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3655 /* Don't do this block twice. */
3656 if (b
== surrounding_static_block
)
3658 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
3660 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3664 return (return_val
);
3667 /* Like make_symbol_completion_list, but returns a list of symbols
3668 defined in a source file FILE. */
3671 make_file_symbol_completion_list (char *text
, char *word
, char *srcfile
)
3676 struct dict_iterator iter
;
3677 /* The symbol we are completing on. Points in same buffer as text. */
3679 /* Length of sym_text. */
3682 /* Now look for the symbol we are supposed to complete on.
3683 FIXME: This should be language-specific. */
3687 char *quote_pos
= NULL
;
3689 /* First see if this is a quoted string. */
3691 for (p
= text
; *p
!= '\0'; ++p
)
3693 if (quote_found
!= '\0')
3695 if (*p
== quote_found
)
3696 /* Found close quote. */
3698 else if (*p
== '\\' && p
[1] == quote_found
)
3699 /* A backslash followed by the quote character
3700 doesn't end the string. */
3703 else if (*p
== '\'' || *p
== '"')
3709 if (quote_found
== '\'')
3710 /* A string within single quotes can be a symbol, so complete on it. */
3711 sym_text
= quote_pos
+ 1;
3712 else if (quote_found
== '"')
3713 /* A double-quoted string is never a symbol, nor does it make sense
3714 to complete it any other way. */
3716 return_val
= (char **) xmalloc (sizeof (char *));
3717 return_val
[0] = NULL
;
3722 /* Not a quoted string. */
3723 sym_text
= language_search_unquoted_string (text
, p
);
3727 sym_text_len
= strlen (sym_text
);
3729 return_val_size
= 10;
3730 return_val_index
= 0;
3731 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
3732 return_val
[0] = NULL
;
3734 /* Find the symtab for SRCFILE (this loads it if it was not yet read
3736 s
= lookup_symtab (srcfile
);
3739 /* Maybe they typed the file with leading directories, while the
3740 symbol tables record only its basename. */
3741 const char *tail
= lbasename (srcfile
);
3744 s
= lookup_symtab (tail
);
3747 /* If we have no symtab for that file, return an empty list. */
3749 return (return_val
);
3751 /* Go through this symtab and check the externs and statics for
3752 symbols which match. */
3754 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3755 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
3757 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3760 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3761 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
3763 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3766 return (return_val
);
3769 /* A helper function for make_source_files_completion_list. It adds
3770 another file name to a list of possible completions, growing the
3771 list as necessary. */
3774 add_filename_to_list (const char *fname
, char *text
, char *word
,
3775 char ***list
, int *list_used
, int *list_alloced
)
3778 size_t fnlen
= strlen (fname
);
3780 if (*list_used
+ 1 >= *list_alloced
)
3783 *list
= (char **) xrealloc ((char *) *list
,
3784 *list_alloced
* sizeof (char *));
3789 /* Return exactly fname. */
3790 new = xmalloc (fnlen
+ 5);
3791 strcpy (new, fname
);
3793 else if (word
> text
)
3795 /* Return some portion of fname. */
3796 new = xmalloc (fnlen
+ 5);
3797 strcpy (new, fname
+ (word
- text
));
3801 /* Return some of TEXT plus fname. */
3802 new = xmalloc (fnlen
+ (text
- word
) + 5);
3803 strncpy (new, word
, text
- word
);
3804 new[text
- word
] = '\0';
3805 strcat (new, fname
);
3807 (*list
)[*list_used
] = new;
3808 (*list
)[++*list_used
] = NULL
;
3812 not_interesting_fname (const char *fname
)
3814 static const char *illegal_aliens
[] = {
3815 "_globals_", /* inserted by coff_symtab_read */
3820 for (i
= 0; illegal_aliens
[i
]; i
++)
3822 if (strcmp (fname
, illegal_aliens
[i
]) == 0)
3828 /* Return a NULL terminated array of all source files whose names
3829 begin with matching TEXT. The file names are looked up in the
3830 symbol tables of this program. If the answer is no matchess, then
3831 the return value is an array which contains only a NULL pointer. */
3834 make_source_files_completion_list (char *text
, char *word
)
3837 struct partial_symtab
*ps
;
3838 struct objfile
*objfile
;
3840 int list_alloced
= 1;
3842 size_t text_len
= strlen (text
);
3843 char **list
= (char **) xmalloc (list_alloced
* sizeof (char *));
3844 const char *base_name
;
3848 if (!have_full_symbols () && !have_partial_symbols ())
3851 ALL_SYMTABS (objfile
, s
)
3853 if (not_interesting_fname (s
->filename
))
3855 if (!filename_seen (s
->filename
, 1, &first
)
3856 #if HAVE_DOS_BASED_FILE_SYSTEM
3857 && strncasecmp (s
->filename
, text
, text_len
) == 0
3859 && strncmp (s
->filename
, text
, text_len
) == 0
3863 /* This file matches for a completion; add it to the current
3865 add_filename_to_list (s
->filename
, text
, word
,
3866 &list
, &list_used
, &list_alloced
);
3870 /* NOTE: We allow the user to type a base name when the
3871 debug info records leading directories, but not the other
3872 way around. This is what subroutines of breakpoint
3873 command do when they parse file names. */
3874 base_name
= lbasename (s
->filename
);
3875 if (base_name
!= s
->filename
3876 && !filename_seen (base_name
, 1, &first
)
3877 #if HAVE_DOS_BASED_FILE_SYSTEM
3878 && strncasecmp (base_name
, text
, text_len
) == 0
3880 && strncmp (base_name
, text
, text_len
) == 0
3883 add_filename_to_list (base_name
, text
, word
,
3884 &list
, &list_used
, &list_alloced
);
3888 ALL_PSYMTABS (objfile
, ps
)
3890 if (not_interesting_fname (ps
->filename
))
3894 if (!filename_seen (ps
->filename
, 1, &first
)
3895 #if HAVE_DOS_BASED_FILE_SYSTEM
3896 && strncasecmp (ps
->filename
, text
, text_len
) == 0
3898 && strncmp (ps
->filename
, text
, text_len
) == 0
3902 /* This file matches for a completion; add it to the
3903 current list of matches. */
3904 add_filename_to_list (ps
->filename
, text
, word
,
3905 &list
, &list_used
, &list_alloced
);
3910 base_name
= lbasename (ps
->filename
);
3911 if (base_name
!= ps
->filename
3912 && !filename_seen (base_name
, 1, &first
)
3913 #if HAVE_DOS_BASED_FILE_SYSTEM
3914 && strncasecmp (base_name
, text
, text_len
) == 0
3916 && strncmp (base_name
, text
, text_len
) == 0
3919 add_filename_to_list (base_name
, text
, word
,
3920 &list
, &list_used
, &list_alloced
);
3928 /* Determine if PC is in the prologue of a function. The prologue is the area
3929 between the first instruction of a function, and the first executable line.
3930 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
3932 If non-zero, func_start is where we think the prologue starts, possibly
3933 by previous examination of symbol table information.
3937 in_prologue (CORE_ADDR pc
, CORE_ADDR func_start
)
3939 struct symtab_and_line sal
;
3940 CORE_ADDR func_addr
, func_end
;
3942 /* We have several sources of information we can consult to figure
3944 - Compilers usually emit line number info that marks the prologue
3945 as its own "source line". So the ending address of that "line"
3946 is the end of the prologue. If available, this is the most
3948 - The minimal symbols and partial symbols, which can usually tell
3949 us the starting and ending addresses of a function.
3950 - If we know the function's start address, we can call the
3951 architecture-defined SKIP_PROLOGUE function to analyze the
3952 instruction stream and guess where the prologue ends.
3953 - Our `func_start' argument; if non-zero, this is the caller's
3954 best guess as to the function's entry point. At the time of
3955 this writing, handle_inferior_event doesn't get this right, so
3956 it should be our last resort. */
3958 /* Consult the partial symbol table, to find which function
3960 if (! find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
3962 CORE_ADDR prologue_end
;
3964 /* We don't even have minsym information, so fall back to using
3965 func_start, if given. */
3967 return 1; /* We *might* be in a prologue. */
3969 prologue_end
= SKIP_PROLOGUE (func_start
);
3971 return func_start
<= pc
&& pc
< prologue_end
;
3974 /* If we have line number information for the function, that's
3975 usually pretty reliable. */
3976 sal
= find_pc_line (func_addr
, 0);
3978 /* Now sal describes the source line at the function's entry point,
3979 which (by convention) is the prologue. The end of that "line",
3980 sal.end, is the end of the prologue.
3982 Note that, for functions whose source code is all on a single
3983 line, the line number information doesn't always end up this way.
3984 So we must verify that our purported end-of-prologue address is
3985 *within* the function, not at its start or end. */
3987 || sal
.end
<= func_addr
3988 || func_end
<= sal
.end
)
3990 /* We don't have any good line number info, so use the minsym
3991 information, together with the architecture-specific prologue
3993 CORE_ADDR prologue_end
= SKIP_PROLOGUE (func_addr
);
3995 return func_addr
<= pc
&& pc
< prologue_end
;
3998 /* We have line number info, and it looks good. */
3999 return func_addr
<= pc
&& pc
< sal
.end
;
4002 /* Given PC at the function's start address, attempt to find the
4003 prologue end using SAL information. Return zero if the skip fails.
4005 A non-optimized prologue traditionally has one SAL for the function
4006 and a second for the function body. A single line function has
4007 them both pointing at the same line.
4009 An optimized prologue is similar but the prologue may contain
4010 instructions (SALs) from the instruction body. Need to skip those
4011 while not getting into the function body.
4013 The functions end point and an increasing SAL line are used as
4014 indicators of the prologue's endpoint.
4016 This code is based on the function refine_prologue_limit (versions
4017 found in both ia64 and ppc). */
4020 skip_prologue_using_sal (CORE_ADDR func_addr
)
4022 struct symtab_and_line prologue_sal
;
4026 /* Get an initial range for the function. */
4027 find_pc_partial_function (func_addr
, NULL
, &start_pc
, &end_pc
);
4028 start_pc
+= DEPRECATED_FUNCTION_START_OFFSET
;
4030 prologue_sal
= find_pc_line (start_pc
, 0);
4031 if (prologue_sal
.line
!= 0)
4033 /* If there is only one sal that covers the entire function,
4034 then it is probably a single line function, like
4036 if (prologue_sal
.end
== end_pc
)
4038 while (prologue_sal
.end
< end_pc
)
4040 struct symtab_and_line sal
;
4042 sal
= find_pc_line (prologue_sal
.end
, 0);
4045 /* Assume that a consecutive SAL for the same (or larger)
4046 line mark the prologue -> body transition. */
4047 if (sal
.line
>= prologue_sal
.line
)
4049 /* The case in which compiler's optimizer/scheduler has
4050 moved instructions into the prologue. We look ahead in
4051 the function looking for address ranges whose
4052 corresponding line number is less the first one that we
4053 found for the function. This is more conservative then
4054 refine_prologue_limit which scans a large number of SALs
4055 looking for any in the prologue */
4059 return prologue_sal
.end
;
4062 struct symtabs_and_lines
4063 decode_line_spec (char *string
, int funfirstline
)
4065 struct symtabs_and_lines sals
;
4066 struct symtab_and_line cursal
;
4069 error (_("Empty line specification."));
4071 /* We use whatever is set as the current source line. We do not try
4072 and get a default or it will recursively call us! */
4073 cursal
= get_current_source_symtab_and_line ();
4075 sals
= decode_line_1 (&string
, funfirstline
,
4076 cursal
.symtab
, cursal
.line
,
4077 (char ***) NULL
, NULL
);
4080 error (_("Junk at end of line specification: %s"), string
);
4085 static char *name_of_main
;
4088 set_main_name (const char *name
)
4090 if (name_of_main
!= NULL
)
4092 xfree (name_of_main
);
4093 name_of_main
= NULL
;
4097 name_of_main
= xstrdup (name
);
4101 /* Deduce the name of the main procedure, and set NAME_OF_MAIN
4105 find_main_name (void)
4107 char *new_main_name
;
4109 /* Try to see if the main procedure is in Ada. */
4110 /* FIXME: brobecker/2005-03-07: Another way of doing this would
4111 be to add a new method in the language vector, and call this
4112 method for each language until one of them returns a non-empty
4113 name. This would allow us to remove this hard-coded call to
4114 an Ada function. It is not clear that this is a better approach
4115 at this point, because all methods need to be written in a way
4116 such that false positives never be returned. For instance, it is
4117 important that a method does not return a wrong name for the main
4118 procedure if the main procedure is actually written in a different
4119 language. It is easy to guaranty this with Ada, since we use a
4120 special symbol generated only when the main in Ada to find the name
4121 of the main procedure. It is difficult however to see how this can
4122 be guarantied for languages such as C, for instance. This suggests
4123 that order of call for these methods becomes important, which means
4124 a more complicated approach. */
4125 new_main_name
= ada_main_name ();
4126 if (new_main_name
!= NULL
)
4128 set_main_name (new_main_name
);
4132 /* The languages above didn't identify the name of the main procedure.
4133 Fallback to "main". */
4134 set_main_name ("main");
4140 if (name_of_main
== NULL
)
4143 return name_of_main
;
4146 /* Handle ``executable_changed'' events for the symtab module. */
4149 symtab_observer_executable_changed (void *unused
)
4151 /* NAME_OF_MAIN may no longer be the same, so reset it for now. */
4152 set_main_name (NULL
);
4156 _initialize_symtab (void)
4158 add_info ("variables", variables_info
, _("\
4159 All global and static variable names, or those matching REGEXP."));
4161 add_com ("whereis", class_info
, variables_info
, _("\
4162 All global and static variable names, or those matching REGEXP."));
4164 add_info ("functions", functions_info
,
4165 _("All function names, or those matching REGEXP."));
4168 /* FIXME: This command has at least the following problems:
4169 1. It prints builtin types (in a very strange and confusing fashion).
4170 2. It doesn't print right, e.g. with
4171 typedef struct foo *FOO
4172 type_print prints "FOO" when we want to make it (in this situation)
4173 print "struct foo *".
4174 I also think "ptype" or "whatis" is more likely to be useful (but if
4175 there is much disagreement "info types" can be fixed). */
4176 add_info ("types", types_info
,
4177 _("All type names, or those matching REGEXP."));
4179 add_info ("sources", sources_info
,
4180 _("Source files in the program."));
4182 add_com ("rbreak", class_breakpoint
, rbreak_command
,
4183 _("Set a breakpoint for all functions matching REGEXP."));
4187 add_com ("lf", class_info
, sources_info
,
4188 _("Source files in the program"));
4189 add_com ("lg", class_info
, variables_info
, _("\
4190 All global and static variable names, or those matching REGEXP."));
4193 /* Initialize the one built-in type that isn't language dependent... */
4194 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
4195 "<unknown type>", (struct objfile
*) NULL
);
4197 observer_attach_executable_changed (symtab_observer_executable_changed
);