1 /* Symbol table lookup for the GNU debugger, GDB.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
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., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
34 #include "call-cmds.h"
35 #include "gdb_regex.h"
36 #include "expression.h"
42 #include "filenames.h" /* for FILENAME_CMP */
43 #include "objc-lang.h"
47 #include "gdb_obstack.h"
50 #include <sys/types.h>
52 #include "gdb_string.h"
57 /* Prototypes for local functions */
59 static void completion_list_add_name (char *, char *, int, char *, char *);
61 static void rbreak_command (char *, int);
63 static void types_info (char *, int);
65 static void functions_info (char *, int);
67 static void variables_info (char *, int);
69 static void sources_info (char *, int);
71 static void output_source_filename (char *, int *);
73 static int find_line_common (struct linetable
*, int, int *);
75 /* This one is used by linespec.c */
77 char *operator_chars (char *p
, char **end
);
79 static struct partial_symbol
*lookup_partial_symbol (struct partial_symtab
*,
84 static struct symbol
*lookup_symbol_aux (const char *name
,
85 const char *linkage_name
,
86 const struct block
*block
,
87 const domain_enum domain
,
88 int *is_a_field_of_this
,
89 struct symtab
**symtab
);
92 struct symbol
*lookup_symbol_aux_local (const char *name
,
93 const char *linkage_name
,
94 const struct block
*block
,
95 const domain_enum domain
,
96 struct symtab
**symtab
);
99 struct symbol
*lookup_symbol_aux_block (const char *name
,
100 const char *linkage_name
,
101 const struct block
*block
,
102 const domain_enum domain
,
103 struct symtab
**symtab
);
106 struct symbol
*lookup_symbol_aux_symtabs (int block_index
,
108 const char *linkage_name
,
109 const domain_enum domain
,
110 struct symtab
**symtab
);
113 struct symbol
*lookup_symbol_aux_psymtabs (int block_index
,
115 const char *linkage_name
,
116 const domain_enum domain
,
117 struct symtab
**symtab
);
121 struct symbol
*lookup_symbol_aux_minsyms (const char *name
,
122 const char *linkage_name
,
123 const domain_enum domain
,
124 int *is_a_field_of_this
,
125 struct symtab
**symtab
);
128 static struct symbol
*find_active_alias (struct symbol
*sym
, CORE_ADDR addr
);
130 /* This flag is used in hppa-tdep.c, and set in hp-symtab-read.c */
131 /* Signals the presence of objects compiled by HP compilers */
132 int hp_som_som_object_present
= 0;
134 static void fixup_section (struct general_symbol_info
*, struct objfile
*);
136 static int file_matches (char *, char **, int);
138 static void print_symbol_info (domain_enum
,
139 struct symtab
*, struct symbol
*, int, char *);
141 static void print_msymbol_info (struct minimal_symbol
*);
143 static void symtab_symbol_info (char *, domain_enum
, int);
145 static void overload_list_add_symbol (struct symbol
*sym
, char *oload_name
);
147 void _initialize_symtab (void);
151 /* The single non-language-specific builtin type */
152 struct type
*builtin_type_error
;
154 /* Block in which the most recently searched-for symbol was found.
155 Might be better to make this a parameter to lookup_symbol and
158 const struct block
*block_found
;
160 /* Check for a symtab of a specific name; first in symtabs, then in
161 psymtabs. *If* there is no '/' in the name, a match after a '/'
162 in the symtab filename will also work. */
165 lookup_symtab (const char *name
)
167 register struct symtab
*s
;
168 register struct partial_symtab
*ps
;
169 register struct objfile
*objfile
;
170 char *real_path
= NULL
;
171 char *full_path
= NULL
;
173 /* Here we are interested in canonicalizing an absolute path, not
174 absolutizing a relative path. */
175 if (IS_ABSOLUTE_PATH (name
))
177 full_path
= xfullpath (name
);
178 make_cleanup (xfree
, full_path
);
179 real_path
= gdb_realpath (name
);
180 make_cleanup (xfree
, real_path
);
185 /* First, search for an exact match */
187 ALL_SYMTABS (objfile
, s
)
189 if (FILENAME_CMP (name
, s
->filename
) == 0)
194 /* If the user gave us an absolute path, try to find the file in
195 this symtab and use its absolute path. */
197 if (full_path
!= NULL
)
199 const char *fp
= symtab_to_filename (s
);
200 if (FILENAME_CMP (full_path
, fp
) == 0)
206 if (real_path
!= NULL
)
208 char *rp
= gdb_realpath (symtab_to_filename (s
));
209 make_cleanup (xfree
, rp
);
210 if (FILENAME_CMP (real_path
, rp
) == 0)
217 /* Now, search for a matching tail (only if name doesn't have any dirs) */
219 if (lbasename (name
) == name
)
220 ALL_SYMTABS (objfile
, s
)
222 if (FILENAME_CMP (lbasename (s
->filename
), name
) == 0)
226 /* Same search rules as above apply here, but now we look thru the
229 ps
= lookup_partial_symtab (name
);
234 error ("Internal: readin %s pst for `%s' found when no symtab found.",
237 s
= PSYMTAB_TO_SYMTAB (ps
);
242 /* At this point, we have located the psymtab for this file, but
243 the conversion to a symtab has failed. This usually happens
244 when we are looking up an include file. In this case,
245 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
246 been created. So, we need to run through the symtabs again in
247 order to find the file.
248 XXX - This is a crock, and should be fixed inside of the the
249 symbol parsing routines. */
253 /* Lookup the partial symbol table of a source file named NAME.
254 *If* there is no '/' in the name, a match after a '/'
255 in the psymtab filename will also work. */
257 struct partial_symtab
*
258 lookup_partial_symtab (const char *name
)
260 register struct partial_symtab
*pst
;
261 register struct objfile
*objfile
;
262 char *full_path
= NULL
;
263 char *real_path
= NULL
;
265 /* Here we are interested in canonicalizing an absolute path, not
266 absolutizing a relative path. */
267 if (IS_ABSOLUTE_PATH (name
))
269 full_path
= xfullpath (name
);
270 make_cleanup (xfree
, full_path
);
271 real_path
= gdb_realpath (name
);
272 make_cleanup (xfree
, real_path
);
275 ALL_PSYMTABS (objfile
, pst
)
277 if (FILENAME_CMP (name
, pst
->filename
) == 0)
282 /* If the user gave us an absolute path, try to find the file in
283 this symtab and use its absolute path. */
284 if (full_path
!= NULL
)
286 if (pst
->fullname
== NULL
)
287 source_full_path_of (pst
->filename
, &pst
->fullname
);
288 if (pst
->fullname
!= NULL
289 && FILENAME_CMP (full_path
, pst
->fullname
) == 0)
295 if (real_path
!= NULL
)
298 if (pst
->fullname
== NULL
)
299 source_full_path_of (pst
->filename
, &pst
->fullname
);
300 if (pst
->fullname
!= NULL
)
302 rp
= gdb_realpath (pst
->fullname
);
303 make_cleanup (xfree
, rp
);
305 if (rp
!= NULL
&& FILENAME_CMP (real_path
, rp
) == 0)
312 /* Now, search for a matching tail (only if name doesn't have any dirs) */
314 if (lbasename (name
) == name
)
315 ALL_PSYMTABS (objfile
, pst
)
317 if (FILENAME_CMP (lbasename (pst
->filename
), name
) == 0)
324 /* Mangle a GDB method stub type. This actually reassembles the pieces of the
325 full method name, which consist of the class name (from T), the unadorned
326 method name from METHOD_ID, and the signature for the specific overload,
327 specified by SIGNATURE_ID. Note that this function is g++ specific. */
330 gdb_mangle_name (struct type
*type
, int method_id
, int signature_id
)
332 int mangled_name_len
;
334 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
335 struct fn_field
*method
= &f
[signature_id
];
336 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, method_id
);
337 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, signature_id
);
338 char *newname
= type_name_no_tag (type
);
340 /* Does the form of physname indicate that it is the full mangled name
341 of a constructor (not just the args)? */
342 int is_full_physname_constructor
;
345 int is_destructor
= is_destructor_name (physname
);
346 /* Need a new type prefix. */
347 char *const_prefix
= method
->is_const
? "C" : "";
348 char *volatile_prefix
= method
->is_volatile
? "V" : "";
350 int len
= (newname
== NULL
? 0 : strlen (newname
));
352 /* Nothing to do if physname already contains a fully mangled v3 abi name
353 or an operator name. */
354 if ((physname
[0] == '_' && physname
[1] == 'Z')
355 || is_operator_name (field_name
))
356 return xstrdup (physname
);
358 is_full_physname_constructor
= is_constructor_name (physname
);
361 is_full_physname_constructor
|| (newname
&& STREQ (field_name
, newname
));
364 is_destructor
= (strncmp (physname
, "__dt", 4) == 0);
366 if (is_destructor
|| is_full_physname_constructor
)
368 mangled_name
= (char *) xmalloc (strlen (physname
) + 1);
369 strcpy (mangled_name
, physname
);
375 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
377 else if (physname
[0] == 't' || physname
[0] == 'Q')
379 /* The physname for template and qualified methods already includes
381 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
387 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
389 mangled_name_len
= ((is_constructor
? 0 : strlen (field_name
))
390 + strlen (buf
) + len
+ strlen (physname
) + 1);
393 mangled_name
= (char *) xmalloc (mangled_name_len
);
395 mangled_name
[0] = '\0';
397 strcpy (mangled_name
, field_name
);
399 strcat (mangled_name
, buf
);
400 /* If the class doesn't have a name, i.e. newname NULL, then we just
401 mangle it using 0 for the length of the class. Thus it gets mangled
402 as something starting with `::' rather than `classname::'. */
404 strcat (mangled_name
, newname
);
406 strcat (mangled_name
, physname
);
407 return (mangled_name
);
411 /* Initialize the language dependent portion of a symbol
412 depending upon the language for the symbol. */
414 symbol_init_language_specific (struct general_symbol_info
*gsymbol
,
415 enum language language
)
417 gsymbol
->language
= language
;
418 if (gsymbol
->language
== language_cplus
419 || gsymbol
->language
== language_java
420 || gsymbol
->language
== language_objc
)
422 gsymbol
->language_specific
.cplus_specific
.demangled_name
= NULL
;
426 memset (&gsymbol
->language_specific
, 0,
427 sizeof (gsymbol
->language_specific
));
431 /* Functions to initialize a symbol's mangled name. */
433 /* Create the hash table used for demangled names. Each hash entry is
434 a pair of strings; one for the mangled name and one for the demangled
435 name. The entry is hashed via just the mangled name. */
438 create_demangled_names_hash (struct objfile
*objfile
)
440 /* Choose 256 as the starting size of the hash table, somewhat arbitrarily.
441 The hash table code will round this up to the next prime number.
442 Choosing a much larger table size wastes memory, and saves only about
443 1% in symbol reading. */
445 objfile
->demangled_names_hash
= htab_create_alloc_ex
446 (256, htab_hash_string
, (int (*) (const void *, const void *)) streq
,
447 NULL
, objfile
->md
, xmcalloc
, xmfree
);
450 /* Try to determine the demangled name for a symbol, based on the
451 language of that symbol. If the language is set to language_auto,
452 it will attempt to find any demangling algorithm that works and
453 then set the language appropriately. The returned name is allocated
454 by the demangler and should be xfree'd. */
457 symbol_find_demangled_name (struct general_symbol_info
*gsymbol
,
460 char *demangled
= NULL
;
462 if (gsymbol
->language
== language_unknown
)
463 gsymbol
->language
= language_auto
;
465 if (gsymbol
->language
== language_objc
466 || gsymbol
->language
== language_auto
)
469 objc_demangle (mangled
, 0);
470 if (demangled
!= NULL
)
472 gsymbol
->language
= language_objc
;
476 if (gsymbol
->language
== language_cplus
477 || gsymbol
->language
== language_auto
)
480 cplus_demangle (mangled
, DMGL_PARAMS
| DMGL_ANSI
);
481 if (demangled
!= NULL
)
483 gsymbol
->language
= language_cplus
;
487 if (gsymbol
->language
== language_java
)
490 cplus_demangle (mangled
,
491 DMGL_PARAMS
| DMGL_ANSI
| DMGL_JAVA
);
492 if (demangled
!= NULL
)
494 gsymbol
->language
= language_java
;
501 /* Set both the mangled and demangled (if any) names for GSYMBOL based
502 on LINKAGE_NAME and LEN. The hash table corresponding to OBJFILE
503 is used, and the memory comes from that objfile's symbol_obstack.
504 LINKAGE_NAME is copied, so the pointer can be discarded after
505 calling this function. */
507 /* We have to be careful when dealing with Java names: when we run
508 into a Java minimal symbol, we don't know it's a Java symbol, so it
509 gets demangled as a C++ name. This is unfortunate, but there's not
510 much we can do about it: but when demangling partial symbols and
511 regular symbols, we'd better not reuse the wrong demangled name.
512 (See PR gdb/1039.) We solve this by putting a distinctive prefix
513 on Java names when storing them in the hash table. */
515 /* FIXME: carlton/2003-03-13: This is an unfortunate situation. I
516 don't mind the Java prefix so much: different languages have
517 different demangling requirements, so it's only natural that we
518 need to keep language data around in our demangling cache. But
519 it's not good that the minimal symbol has the wrong demangled name.
520 Unfortunately, I can't think of any easy solution to that
523 #define JAVA_PREFIX "##JAVA$$"
524 #define JAVA_PREFIX_LEN 8
527 symbol_set_names (struct general_symbol_info
*gsymbol
,
528 const char *linkage_name
, int len
, struct objfile
*objfile
)
531 /* A 0-terminated copy of the linkage name. */
532 const char *linkage_name_copy
;
533 /* A copy of the linkage name that might have a special Java prefix
534 added to it, for use when looking names up in the hash table. */
535 const char *lookup_name
;
536 /* The length of lookup_name. */
539 if (objfile
->demangled_names_hash
== NULL
)
540 create_demangled_names_hash (objfile
);
542 /* The stabs reader generally provides names that are not
543 NUL-terminated; most of the other readers don't do this, so we
544 can just use the given copy, unless we're in the Java case. */
545 if (gsymbol
->language
== language_java
)
548 lookup_len
= len
+ JAVA_PREFIX_LEN
;
550 alloc_name
= alloca (lookup_len
+ 1);
551 memcpy (alloc_name
, JAVA_PREFIX
, JAVA_PREFIX_LEN
);
552 memcpy (alloc_name
+ JAVA_PREFIX_LEN
, linkage_name
, len
);
553 alloc_name
[lookup_len
] = '\0';
555 lookup_name
= alloc_name
;
556 linkage_name_copy
= alloc_name
+ JAVA_PREFIX_LEN
;
558 else if (linkage_name
[len
] != '\0')
563 alloc_name
= alloca (lookup_len
+ 1);
564 memcpy (alloc_name
, linkage_name
, len
);
565 alloc_name
[lookup_len
] = '\0';
567 lookup_name
= alloc_name
;
568 linkage_name_copy
= alloc_name
;
573 lookup_name
= linkage_name
;
574 linkage_name_copy
= linkage_name
;
577 slot
= (char **) htab_find_slot (objfile
->demangled_names_hash
,
578 lookup_name
, INSERT
);
580 /* If this name is not in the hash table, add it. */
583 char *demangled_name
= symbol_find_demangled_name (gsymbol
,
585 int demangled_len
= demangled_name
? strlen (demangled_name
) : 0;
587 /* If there is a demangled name, place it right after the mangled name.
588 Otherwise, just place a second zero byte after the end of the mangled
590 *slot
= obstack_alloc (&objfile
->symbol_obstack
,
591 lookup_len
+ demangled_len
+ 2);
592 memcpy (*slot
, lookup_name
, lookup_len
+ 1);
593 if (demangled_name
!= NULL
)
595 memcpy (*slot
+ lookup_len
+ 1, demangled_name
, demangled_len
+ 1);
596 xfree (demangled_name
);
599 (*slot
)[lookup_len
+ 1] = '\0';
602 gsymbol
->name
= *slot
+ lookup_len
- len
;
603 if ((*slot
)[lookup_len
+ 1] != '\0')
604 gsymbol
->language_specific
.cplus_specific
.demangled_name
605 = &(*slot
)[lookup_len
+ 1];
607 gsymbol
->language_specific
.cplus_specific
.demangled_name
= NULL
;
610 /* Initialize the demangled name of GSYMBOL if possible. Any required space
611 to store the name is obtained from the specified obstack. The function
612 symbol_set_names, above, should be used instead where possible for more
613 efficient memory usage. */
616 symbol_init_demangled_name (struct general_symbol_info
*gsymbol
,
617 struct obstack
*obstack
)
619 char *mangled
= gsymbol
->name
;
620 char *demangled
= NULL
;
622 demangled
= symbol_find_demangled_name (gsymbol
, mangled
);
623 if (gsymbol
->language
== language_cplus
624 || gsymbol
->language
== language_java
625 || gsymbol
->language
== language_objc
)
629 gsymbol
->language_specific
.cplus_specific
.demangled_name
630 = obsavestring (demangled
, strlen (demangled
), obstack
);
634 gsymbol
->language_specific
.cplus_specific
.demangled_name
= NULL
;
638 /* Unknown language; just clean up quietly. */
644 /* Return the source code name of a symbol. In languages where
645 demangling is necessary, this is the demangled name. */
648 symbol_natural_name (const struct general_symbol_info
*gsymbol
)
650 if ((gsymbol
->language
== language_cplus
651 || gsymbol
->language
== language_java
652 || gsymbol
->language
== language_objc
)
653 && (gsymbol
->language_specific
.cplus_specific
.demangled_name
!= NULL
))
655 return gsymbol
->language_specific
.cplus_specific
.demangled_name
;
659 return gsymbol
->name
;
663 /* Return the demangled name for a symbol based on the language for
664 that symbol. If no demangled name exists, return NULL. */
666 symbol_demangled_name (struct general_symbol_info
*gsymbol
)
668 if (gsymbol
->language
== language_cplus
669 || gsymbol
->language
== language_java
670 || gsymbol
->language
== language_objc
)
671 return gsymbol
->language_specific
.cplus_specific
.demangled_name
;
677 /* Initialize the structure fields to zero values. */
679 init_sal (struct symtab_and_line
*sal
)
690 /* Find which partial symtab on contains PC and SECTION. Return 0 if none. */
692 struct partial_symtab
*
693 find_pc_sect_psymtab (CORE_ADDR pc
, asection
*section
)
695 register struct partial_symtab
*pst
;
696 register struct objfile
*objfile
;
697 struct minimal_symbol
*msymbol
;
699 /* If we know that this is not a text address, return failure. This is
700 necessary because we loop based on texthigh and textlow, which do
701 not include the data ranges. */
702 msymbol
= lookup_minimal_symbol_by_pc_section (pc
, section
);
704 && (msymbol
->type
== mst_data
705 || msymbol
->type
== mst_bss
706 || msymbol
->type
== mst_abs
707 || msymbol
->type
== mst_file_data
708 || msymbol
->type
== mst_file_bss
))
711 ALL_PSYMTABS (objfile
, pst
)
713 if (pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
715 struct partial_symtab
*tpst
;
717 /* An objfile that has its functions reordered might have
718 many partial symbol tables containing the PC, but
719 we want the partial symbol table that contains the
720 function containing the PC. */
721 if (!(objfile
->flags
& OBJF_REORDERED
) &&
722 section
== 0) /* can't validate section this way */
728 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
730 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
732 struct partial_symbol
*p
;
734 p
= find_pc_sect_psymbol (tpst
, pc
, section
);
736 && SYMBOL_VALUE_ADDRESS (p
)
737 == SYMBOL_VALUE_ADDRESS (msymbol
))
747 /* Find which partial symtab contains PC. Return 0 if none.
748 Backward compatibility, no section */
750 struct partial_symtab
*
751 find_pc_psymtab (CORE_ADDR pc
)
753 return find_pc_sect_psymtab (pc
, find_pc_mapped_section (pc
));
756 /* Find which partial symbol within a psymtab matches PC and SECTION.
757 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
759 struct partial_symbol
*
760 find_pc_sect_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
,
763 struct partial_symbol
*best
= NULL
, *p
, **pp
;
767 psymtab
= find_pc_sect_psymtab (pc
, section
);
771 /* Cope with programs that start at address 0 */
772 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
774 /* Search the global symbols as well as the static symbols, so that
775 find_pc_partial_function doesn't use a minimal symbol and thus
776 cache a bad endaddr. */
777 for (pp
= psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
778 (pp
- (psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
779 < psymtab
->n_global_syms
);
783 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
784 && SYMBOL_CLASS (p
) == LOC_BLOCK
785 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
786 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
787 || (psymtab
->textlow
== 0
788 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
790 if (section
) /* match on a specific section */
792 fixup_psymbol_section (p
, psymtab
->objfile
);
793 if (SYMBOL_BFD_SECTION (p
) != section
)
796 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
801 for (pp
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
802 (pp
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
803 < psymtab
->n_static_syms
);
807 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
808 && SYMBOL_CLASS (p
) == LOC_BLOCK
809 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
810 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
811 || (psymtab
->textlow
== 0
812 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
814 if (section
) /* match on a specific section */
816 fixup_psymbol_section (p
, psymtab
->objfile
);
817 if (SYMBOL_BFD_SECTION (p
) != section
)
820 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
828 /* Find which partial symbol within a psymtab matches PC. Return 0 if none.
829 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
831 struct partial_symbol
*
832 find_pc_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
)
834 return find_pc_sect_psymbol (psymtab
, pc
, find_pc_mapped_section (pc
));
837 /* Debug symbols usually don't have section information. We need to dig that
838 out of the minimal symbols and stash that in the debug symbol. */
841 fixup_section (struct general_symbol_info
*ginfo
, struct objfile
*objfile
)
843 struct minimal_symbol
*msym
;
844 msym
= lookup_minimal_symbol (ginfo
->name
, NULL
, objfile
);
848 ginfo
->bfd_section
= SYMBOL_BFD_SECTION (msym
);
849 ginfo
->section
= SYMBOL_SECTION (msym
);
854 fixup_symbol_section (struct symbol
*sym
, struct objfile
*objfile
)
859 if (SYMBOL_BFD_SECTION (sym
))
862 fixup_section (&sym
->ginfo
, objfile
);
867 struct partial_symbol
*
868 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
873 if (SYMBOL_BFD_SECTION (psym
))
876 fixup_section (&psym
->ginfo
, objfile
);
881 /* Find the definition for a specified symbol name NAME
882 in domain DOMAIN, visible from lexical block BLOCK.
883 Returns the struct symbol pointer, or zero if no symbol is found.
884 If SYMTAB is non-NULL, store the symbol table in which the
885 symbol was found there, or NULL if not found.
886 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
887 NAME is a field of the current implied argument `this'. If so set
888 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
889 BLOCK_FOUND is set to the block in which NAME is found (in the case of
890 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
892 /* This function has a bunch of loops in it and it would seem to be
893 attractive to put in some QUIT's (though I'm not really sure
894 whether it can run long enough to be really important). But there
895 are a few calls for which it would appear to be bad news to quit
896 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c. (Note
897 that there is C++ code below which can error(), but that probably
898 doesn't affect these calls since they are looking for a known
899 variable and thus can probably assume it will never hit the C++
903 lookup_symbol (const char *name
, const struct block
*block
,
904 const domain_enum domain
, int *is_a_field_of_this
,
905 struct symtab
**symtab
)
907 char *demangled_name
= NULL
;
908 const char *modified_name
= NULL
;
909 const char *mangled_name
= NULL
;
910 int needtofreename
= 0;
911 struct symbol
*returnval
;
913 modified_name
= name
;
915 /* If we are using C++ language, demangle the name before doing a lookup, so
916 we can always binary search. */
917 if (current_language
->la_language
== language_cplus
)
919 demangled_name
= cplus_demangle (name
, DMGL_ANSI
| DMGL_PARAMS
);
923 modified_name
= demangled_name
;
928 if (case_sensitivity
== case_sensitive_off
)
934 copy
= (char *) alloca (len
+ 1);
935 for (i
= 0; i
< len
; i
++)
936 copy
[i
] = tolower (name
[i
]);
938 modified_name
= copy
;
941 returnval
= lookup_symbol_aux (modified_name
, mangled_name
, block
,
942 domain
, is_a_field_of_this
, symtab
);
944 xfree (demangled_name
);
949 /* Behave like lookup_symbol_aux except that NAME is the natural name
950 of the symbol that we're looking for and, if LINKAGE_NAME is
951 non-NULL, ensure that the symbol's linkage name matches as
954 static struct symbol
*
955 lookup_symbol_aux (const char *name
, const char *linkage_name
,
956 const struct block
*block
, const domain_enum domain
,
957 int *is_a_field_of_this
, struct symtab
**symtab
)
960 const struct block
*static_block
;
962 /* Search specified block and its superiors. Don't search
963 STATIC_BLOCK or GLOBAL_BLOCK. */
965 sym
= lookup_symbol_aux_local (name
, linkage_name
, block
, domain
,
970 /* C++/Java/Objective-C: If requested to do so by the caller,
971 check to see if NAME is a field of `this'. */
972 if (is_a_field_of_this
)
974 struct value
*v
= value_of_this (0);
976 *is_a_field_of_this
= 0;
977 if (v
&& check_field (v
, name
))
979 *is_a_field_of_this
= 1;
986 /* If there's a static block to search, search it next. */
988 /* NOTE: carlton/2002-12-05: There is a question as to whether or
989 not it would be appropriate to search the current global block
990 here as well. (That's what this code used to do before the
991 is_a_field_of_this check was moved up.) On the one hand, it's
992 redundant with the lookup_symbol_aux_symtabs search that happens
993 next. On the other hand, if decode_line_1 is passed an argument
994 like filename:var, then the user presumably wants 'var' to be
995 searched for in filename. On the third hand, there shouldn't be
996 multiple global variables all of which are named 'var', and it's
997 not like decode_line_1 has ever restricted its search to only
998 global variables in a single filename. All in all, only
999 searching the static block here seems best: it's correct and it's
1002 /* NOTE: carlton/2002-12-05: There's also a possible performance
1003 issue here: if you usually search for global symbols in the
1004 current file, then it would be slightly better to search the
1005 current global block before searching all the symtabs. But there
1006 are other factors that have a much greater effect on performance
1007 than that one, so I don't think we should worry about that for
1010 static_block
= block_static_block (block
);
1011 if (static_block
!= NULL
)
1013 sym
= lookup_symbol_aux_block (name
, linkage_name
, static_block
,
1019 /* Now search all global blocks. Do the symtab's first, then
1020 check the psymtab's. If a psymtab indicates the existence
1021 of the desired name as a global, then do psymtab-to-symtab
1022 conversion on the fly and return the found symbol. */
1024 sym
= lookup_symbol_aux_symtabs (GLOBAL_BLOCK
, name
, linkage_name
,
1029 sym
= lookup_symbol_aux_psymtabs (GLOBAL_BLOCK
, name
, linkage_name
,
1034 /* Now search all static file-level symbols. Not strictly correct,
1035 but more useful than an error. Do the symtabs first, then check
1036 the psymtabs. If a psymtab indicates the existence of the
1037 desired name as a file-level static, then do psymtab-to-symtab
1038 conversion on the fly and return the found symbol. */
1040 sym
= lookup_symbol_aux_symtabs (STATIC_BLOCK
, name
, linkage_name
,
1045 sym
= lookup_symbol_aux_psymtabs (STATIC_BLOCK
, name
, linkage_name
,
1055 /* Check to see if the symbol is defined in BLOCK or its superiors.
1056 Don't search STATIC_BLOCK or GLOBAL_BLOCK. */
1058 static struct symbol
*
1059 lookup_symbol_aux_local (const char *name
, const char *linkage_name
,
1060 const struct block
*block
,
1061 const domain_enum domain
,
1062 struct symtab
**symtab
)
1065 const struct block
*static_block
= block_static_block (block
);
1067 /* Check if either no block is specified or it's a global block. */
1069 if (static_block
== NULL
)
1072 while (block
!= static_block
)
1074 sym
= lookup_symbol_aux_block (name
, linkage_name
, block
, domain
,
1078 block
= BLOCK_SUPERBLOCK (block
);
1081 /* We've reached the static block without finding a result. */
1086 /* Look up a symbol in a block; if found, locate its symtab, fixup the
1087 symbol, and set block_found appropriately. */
1089 static struct symbol
*
1090 lookup_symbol_aux_block (const char *name
, const char *linkage_name
,
1091 const struct block
*block
,
1092 const domain_enum domain
,
1093 struct symtab
**symtab
)
1096 struct objfile
*objfile
= NULL
;
1097 struct blockvector
*bv
;
1099 struct symtab
*s
= NULL
;
1101 sym
= lookup_block_symbol (block
, name
, linkage_name
, domain
);
1104 block_found
= block
;
1107 /* Search the list of symtabs for one which contains the
1108 address of the start of this block. */
1109 ALL_SYMTABS (objfile
, s
)
1111 bv
= BLOCKVECTOR (s
);
1112 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1113 if (BLOCK_START (b
) <= BLOCK_START (block
)
1114 && BLOCK_END (b
) > BLOCK_START (block
))
1121 return fixup_symbol_section (sym
, objfile
);
1127 /* Check to see if the symbol is defined in one of the symtabs.
1128 BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
1129 depending on whether or not we want to search global symbols or
1132 static struct symbol
*
1133 lookup_symbol_aux_symtabs (int block_index
,
1134 const char *name
, const char *linkage_name
,
1135 const domain_enum domain
,
1136 struct symtab
**symtab
)
1139 struct objfile
*objfile
;
1140 struct blockvector
*bv
;
1141 const struct block
*block
;
1144 ALL_SYMTABS (objfile
, s
)
1146 bv
= BLOCKVECTOR (s
);
1147 block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
1148 sym
= lookup_block_symbol (block
, name
, linkage_name
, domain
);
1151 block_found
= block
;
1154 return fixup_symbol_section (sym
, objfile
);
1161 /* Check to see if the symbol is defined in one of the partial
1162 symtabs. BLOCK_INDEX should be either GLOBAL_BLOCK or
1163 STATIC_BLOCK, depending on whether or not we want to search global
1164 symbols or static symbols. */
1166 static struct symbol
*
1167 lookup_symbol_aux_psymtabs (int block_index
, const char *name
,
1168 const char *linkage_name
,
1169 const domain_enum domain
,
1170 struct symtab
**symtab
)
1173 struct objfile
*objfile
;
1174 struct blockvector
*bv
;
1175 const struct block
*block
;
1176 struct partial_symtab
*ps
;
1178 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
1180 ALL_PSYMTABS (objfile
, ps
)
1183 && lookup_partial_symbol (ps
, name
, linkage_name
,
1184 psymtab_index
, domain
))
1186 s
= PSYMTAB_TO_SYMTAB (ps
);
1187 bv
= BLOCKVECTOR (s
);
1188 block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
1189 sym
= lookup_block_symbol (block
, name
, linkage_name
, domain
);
1192 /* This shouldn't be necessary, but as a last resort try
1193 looking in the statics even though the psymtab claimed
1194 the symbol was global, or vice-versa. It's possible
1195 that the psymtab gets it wrong in some cases. */
1197 /* FIXME: carlton/2002-09-30: Should we really do that?
1198 If that happens, isn't it likely to be a GDB error, in
1199 which case we should fix the GDB error rather than
1200 silently dealing with it here? So I'd vote for
1201 removing the check for the symbol in the other
1203 block
= BLOCKVECTOR_BLOCK (bv
,
1204 block_index
== GLOBAL_BLOCK
?
1205 STATIC_BLOCK
: GLOBAL_BLOCK
);
1206 sym
= lookup_block_symbol (block
, name
, linkage_name
, domain
);
1208 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>).",
1209 block_index
== GLOBAL_BLOCK
? "global" : "static",
1210 name
, ps
->filename
, name
, name
);
1214 return fixup_symbol_section (sym
, objfile
);
1222 /* Check for the possibility of the symbol being a function or a
1223 mangled variable that is stored in one of the minimal symbol
1224 tables. Eventually, all global symbols might be resolved in this
1227 /* NOTE: carlton/2002-12-05: At one point, this function was part of
1228 lookup_symbol_aux, and what are now 'return' statements within
1229 lookup_symbol_aux_minsyms returned from lookup_symbol_aux, even if
1230 sym was NULL. As far as I can tell, this was basically accidental;
1231 it didn't happen every time that msymbol was non-NULL, but only if
1232 some additional conditions held as well, and it caused problems
1233 with HP-generated symbol tables. */
1235 /* NOTE: carlton/2003-05-14: This function was once used as part of
1236 lookup_symbol. It is currently unnecessary for correctness
1237 reasons, however, and using it doesn't seem to be any faster than
1238 using lookup_symbol_aux_psymtabs, so I'm commenting it out. */
1240 static struct symbol
*
1241 lookup_symbol_aux_minsyms (const char *name
,
1242 const char *linkage_name
,
1243 const domain_enum domain
,
1244 int *is_a_field_of_this
,
1245 struct symtab
**symtab
)
1248 struct blockvector
*bv
;
1249 const struct block
*block
;
1250 struct minimal_symbol
*msymbol
;
1253 if (domain
== VAR_DOMAIN
)
1255 msymbol
= lookup_minimal_symbol (name
, NULL
, NULL
);
1257 if (msymbol
!= NULL
)
1259 /* OK, we found a minimal symbol in spite of not finding any
1260 symbol. There are various possible explanations for
1261 this. One possibility is the symbol exists in code not
1262 compiled -g. Another possibility is that the 'psymtab'
1263 isn't doing its job. A third possibility, related to #2,
1264 is that we were confused by name-mangling. For instance,
1265 maybe the psymtab isn't doing its job because it only
1266 know about demangled names, but we were given a mangled
1269 /* We first use the address in the msymbol to try to locate
1270 the appropriate symtab. Note that find_pc_sect_symtab()
1271 has a side-effect of doing psymtab-to-symtab expansion,
1272 for the found symtab. */
1273 s
= find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol
),
1274 SYMBOL_BFD_SECTION (msymbol
));
1277 /* This is a function which has a symtab for its address. */
1278 bv
= BLOCKVECTOR (s
);
1279 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1281 /* This call used to pass `DEPRECATED_SYMBOL_NAME (msymbol)' as the
1282 `name' argument to lookup_block_symbol. But the name
1283 of a minimal symbol is always mangled, so that seems
1284 to be clearly the wrong thing to pass as the
1287 lookup_block_symbol (block
, name
, linkage_name
, domain
);
1288 /* We kept static functions in minimal symbol table as well as
1289 in static scope. We want to find them in the symbol table. */
1292 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1293 sym
= lookup_block_symbol (block
, name
,
1294 linkage_name
, domain
);
1297 /* NOTE: carlton/2002-12-04: The following comment was
1298 taken from a time when two versions of this function
1299 were part of the body of lookup_symbol_aux: this
1300 comment was taken from the version of the function
1301 that was #ifdef HPUXHPPA, and the comment was right
1302 before the 'return NULL' part of lookup_symbol_aux.
1303 (Hence the "Fall through and return 0" comment.)
1304 Elena did some digging into the situation for
1305 Fortran, and she reports:
1307 "I asked around (thanks to Jeff Knaggs), and I think
1308 the story for Fortran goes like this:
1310 "Apparently, in older Fortrans, '_' was not part of
1311 the user namespace. g77 attached a final '_' to
1312 procedure names as the exported symbols for linkage
1313 (foo_) , but the symbols went in the debug info just
1314 like 'foo'. The rationale behind this is not
1315 completely clear, and maybe it was done to other
1316 symbols as well, not just procedures." */
1318 /* If we get here with sym == 0, the symbol was
1319 found in the minimal symbol table
1320 but not in the symtab.
1321 Fall through and return 0 to use the msymbol
1322 definition of "foo_".
1323 (Note that outer code generally follows up a call
1324 to this routine with a call to lookup_minimal_symbol(),
1325 so a 0 return means we'll just flow into that other routine).
1327 This happens for Fortran "foo_" symbols,
1328 which are "foo" in the symtab.
1330 This can also happen if "asm" is used to make a
1331 regular symbol but not a debugging symbol, e.g.
1332 asm(".globl _main");
1336 if (symtab
!= NULL
&& sym
!= NULL
)
1338 return fixup_symbol_section (sym
, s
->objfile
);
1347 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
1348 If LINKAGE_NAME is non-NULL, check in addition that the symbol's
1349 linkage name matches it. Check the global symbols if GLOBAL, the
1350 static symbols if not */
1352 static struct partial_symbol
*
1353 lookup_partial_symbol (struct partial_symtab
*pst
, const char *name
,
1354 const char *linkage_name
, int global
,
1357 struct partial_symbol
*temp
;
1358 struct partial_symbol
**start
, **psym
;
1359 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
1360 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
1361 int do_linear_search
= 1;
1368 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
1369 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1371 if (global
) /* This means we can use a binary search. */
1373 do_linear_search
= 0;
1375 /* Binary search. This search is guaranteed to end with center
1376 pointing at the earliest partial symbol whose name might be
1377 correct. At that point *all* partial symbols with an
1378 appropriate name will be checked against the correct
1382 top
= start
+ length
- 1;
1384 while (top
> bottom
)
1386 center
= bottom
+ (top
- bottom
) / 2;
1387 if (!(center
< top
))
1388 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
1389 if (!do_linear_search
1390 && (SYMBOL_LANGUAGE (*center
) == language_java
))
1392 do_linear_search
= 1;
1394 if (strcmp_iw_ordered (SYMBOL_NATURAL_NAME (*center
), name
) >= 0)
1400 bottom
= center
+ 1;
1403 if (!(top
== bottom
))
1404 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
1406 while (top
<= real_top
1407 && (linkage_name
!= NULL
1408 ? strcmp (SYMBOL_LINKAGE_NAME (*top
), linkage_name
) == 0
1409 : SYMBOL_MATCHES_NATURAL_NAME (*top
,name
)))
1411 if (SYMBOL_DOMAIN (*top
) == domain
)
1419 /* Can't use a binary search or else we found during the binary search that
1420 we should also do a linear search. */
1422 if (do_linear_search
)
1424 for (psym
= start
; psym
< start
+ length
; psym
++)
1426 if (domain
== SYMBOL_DOMAIN (*psym
))
1428 if (linkage_name
!= NULL
1429 ? strcmp (SYMBOL_LINKAGE_NAME (*psym
), linkage_name
) == 0
1430 : SYMBOL_MATCHES_NATURAL_NAME (*psym
, name
))
1441 /* Look up a type named NAME in the struct_domain. The type returned
1442 must not be opaque -- i.e., must have at least one field defined
1444 This code was modelled on lookup_symbol -- the parts not relevant to looking
1445 up types were just left out. In particular it's assumed here that types
1446 are available in struct_domain and only at file-static or global blocks. */
1450 lookup_transparent_type (const char *name
)
1452 register struct symbol
*sym
;
1453 register struct symtab
*s
= NULL
;
1454 register struct partial_symtab
*ps
;
1455 struct blockvector
*bv
;
1456 register struct objfile
*objfile
;
1457 register struct block
*block
;
1459 /* Now search all the global symbols. Do the symtab's first, then
1460 check the psymtab's. If a psymtab indicates the existence
1461 of the desired name as a global, then do psymtab-to-symtab
1462 conversion on the fly and return the found symbol. */
1464 ALL_SYMTABS (objfile
, s
)
1466 bv
= BLOCKVECTOR (s
);
1467 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1468 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1469 if (sym
&& !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1471 return SYMBOL_TYPE (sym
);
1475 ALL_PSYMTABS (objfile
, ps
)
1477 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, NULL
,
1480 s
= PSYMTAB_TO_SYMTAB (ps
);
1481 bv
= BLOCKVECTOR (s
);
1482 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1483 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1486 /* This shouldn't be necessary, but as a last resort
1487 * try looking in the statics even though the psymtab
1488 * claimed the symbol was global. It's possible that
1489 * the psymtab gets it wrong in some cases.
1491 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1492 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1494 error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
1495 %s may be an inlined function, or may be a template function\n\
1496 (if a template, try specifying an instantiation: %s<type>).",
1497 name
, ps
->filename
, name
, name
);
1499 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1500 return SYMBOL_TYPE (sym
);
1504 /* Now search the static file-level symbols.
1505 Not strictly correct, but more useful than an error.
1506 Do the symtab's first, then
1507 check the psymtab's. If a psymtab indicates the existence
1508 of the desired name as a file-level static, then do psymtab-to-symtab
1509 conversion on the fly and return the found symbol.
1512 ALL_SYMTABS (objfile
, s
)
1514 bv
= BLOCKVECTOR (s
);
1515 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1516 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1517 if (sym
&& !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1519 return SYMBOL_TYPE (sym
);
1523 ALL_PSYMTABS (objfile
, ps
)
1525 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, NULL
, 0, STRUCT_DOMAIN
))
1527 s
= PSYMTAB_TO_SYMTAB (ps
);
1528 bv
= BLOCKVECTOR (s
);
1529 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1530 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1533 /* This shouldn't be necessary, but as a last resort
1534 * try looking in the globals even though the psymtab
1535 * claimed the symbol was static. It's possible that
1536 * the psymtab gets it wrong in some cases.
1538 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1539 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1541 error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
1542 %s may be an inlined function, or may be a template function\n\
1543 (if a template, try specifying an instantiation: %s<type>).",
1544 name
, ps
->filename
, name
, name
);
1546 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1547 return SYMBOL_TYPE (sym
);
1550 return (struct type
*) 0;
1554 /* Find the psymtab containing main(). */
1555 /* FIXME: What about languages without main() or specially linked
1556 executables that have no main() ? */
1558 struct partial_symtab
*
1559 find_main_psymtab (void)
1561 register struct partial_symtab
*pst
;
1562 register struct objfile
*objfile
;
1564 ALL_PSYMTABS (objfile
, pst
)
1566 if (lookup_partial_symbol (pst
, main_name (), NULL
, 1, VAR_DOMAIN
))
1574 /* Search BLOCK for symbol NAME in DOMAIN.
1576 Note that if NAME is the demangled form of a C++ symbol, we will fail
1577 to find a match during the binary search of the non-encoded names, but
1578 for now we don't worry about the slight inefficiency of looking for
1579 a match we'll never find, since it will go pretty quick. Once the
1580 binary search terminates, we drop through and do a straight linear
1581 search on the symbols. Each symbol which is marked as being a ObjC/C++
1582 symbol (language_cplus or language_objc set) has both the encoded and
1583 non-encoded names tested for a match.
1585 If LINKAGE_NAME is non-NULL, verify that any symbol we find has this
1586 particular mangled name.
1590 lookup_block_symbol (register const struct block
*block
, const char *name
,
1591 const char *linkage_name
,
1592 const domain_enum domain
)
1594 register int bot
, top
, inc
;
1595 register struct symbol
*sym
;
1596 register struct symbol
*sym_found
= NULL
;
1597 register int do_linear_search
= 1;
1599 if (BLOCK_HASHTABLE (block
))
1601 unsigned int hash_index
;
1602 hash_index
= msymbol_hash_iw (name
);
1603 hash_index
= hash_index
% BLOCK_BUCKETS (block
);
1604 for (sym
= BLOCK_BUCKET (block
, hash_index
); sym
; sym
= sym
->hash_next
)
1606 if (SYMBOL_DOMAIN (sym
) == domain
1608 ? strcmp (DEPRECATED_SYMBOL_NAME (sym
), linkage_name
) == 0
1609 : SYMBOL_MATCHES_NATURAL_NAME (sym
, name
)))
1615 /* If the blocks's symbols were sorted, start with a binary search. */
1617 if (BLOCK_SHOULD_SORT (block
))
1619 /* Reset the linear search flag so if the binary search fails, we
1620 won't do the linear search once unless we find some reason to
1623 do_linear_search
= 0;
1624 top
= BLOCK_NSYMS (block
);
1627 /* Advance BOT to not far before the first symbol whose name is NAME. */
1631 inc
= (top
- bot
+ 1);
1632 /* No need to keep binary searching for the last few bits worth. */
1637 inc
= (inc
>> 1) + bot
;
1638 sym
= BLOCK_SYM (block
, inc
);
1639 if (!do_linear_search
&& (SYMBOL_LANGUAGE (sym
) == language_java
))
1641 do_linear_search
= 1;
1643 if (SYMBOL_NATURAL_NAME (sym
)[0] < name
[0])
1647 else if (SYMBOL_NATURAL_NAME (sym
)[0] > name
[0])
1651 else if (strcmp (SYMBOL_NATURAL_NAME (sym
), name
) < 0)
1661 /* Now scan forward until we run out of symbols, find one whose
1662 name is greater than NAME, or find one we want. If there is
1663 more than one symbol with the right name and domain, we
1664 return the first one; I believe it is now impossible for us
1665 to encounter two symbols with the same name and domain
1666 here, because blocks containing argument symbols are no
1667 longer sorted. The exception is for C++, where multiple functions
1668 (cloned constructors / destructors, in particular) can have
1669 the same demangled name. So if we have a particular
1670 mangled name to match, try to do so. */
1672 top
= BLOCK_NSYMS (block
);
1675 sym
= BLOCK_SYM (block
, bot
);
1676 if (SYMBOL_DOMAIN (sym
) == domain
1678 ? strcmp (DEPRECATED_SYMBOL_NAME (sym
), linkage_name
) == 0
1679 : SYMBOL_MATCHES_NATURAL_NAME (sym
, name
)))
1683 if (SYMBOL_PRINT_NAME (sym
)[0] > name
[0])
1691 /* Here if block isn't sorted, or we fail to find a match during the
1692 binary search above. If during the binary search above, we find a
1693 symbol which is a Java symbol, then we have re-enabled the linear
1694 search flag which was reset when starting the binary search.
1696 This loop is equivalent to the loop above, but hacked greatly for speed.
1698 Note that parameter symbols do not always show up last in the
1699 list; this loop makes sure to take anything else other than
1700 parameter symbols first; it only uses parameter symbols as a
1701 last resort. Note that this only takes up extra computation
1704 if (do_linear_search
)
1706 top
= BLOCK_NSYMS (block
);
1710 sym
= BLOCK_SYM (block
, bot
);
1711 if (SYMBOL_DOMAIN (sym
) == domain
1713 ? strcmp (DEPRECATED_SYMBOL_NAME (sym
), linkage_name
) == 0
1714 : SYMBOL_MATCHES_NATURAL_NAME (sym
, name
)))
1716 /* If SYM has aliases, then use any alias that is active
1717 at the current PC. If no alias is active at the current
1718 PC, then use the main symbol.
1720 ?!? Is checking the current pc correct? Is this routine
1721 ever called to look up a symbol from another context?
1723 FIXME: No, it's not correct. If someone sets a
1724 conditional breakpoint at an address, then the
1725 breakpoint's `struct expression' should refer to the
1726 `struct symbol' appropriate for the breakpoint's
1727 address, which may not be the PC.
1729 Even if it were never called from another context,
1730 it's totally bizarre for lookup_symbol's behavior to
1731 depend on the value of the inferior's current PC. We
1732 should pass in the appropriate PC as well as the
1733 block. The interface to lookup_symbol should change
1734 to require the caller to provide a PC. */
1736 if (SYMBOL_ALIASES (sym
))
1737 sym
= find_active_alias (sym
, read_pc ());
1740 if (SYMBOL_CLASS (sym
) != LOC_ARG
&&
1741 SYMBOL_CLASS (sym
) != LOC_LOCAL_ARG
&&
1742 SYMBOL_CLASS (sym
) != LOC_REF_ARG
&&
1743 SYMBOL_CLASS (sym
) != LOC_REGPARM
&&
1744 SYMBOL_CLASS (sym
) != LOC_REGPARM_ADDR
&&
1745 SYMBOL_CLASS (sym
) != LOC_BASEREG_ARG
&&
1746 SYMBOL_CLASS (sym
) != LOC_COMPUTED_ARG
)
1754 return (sym_found
); /* Will be NULL if not found. */
1757 /* Given a main symbol SYM and ADDR, search through the alias
1758 list to determine if an alias is active at ADDR and return
1761 If no alias is active, then return SYM. */
1763 static struct symbol
*
1764 find_active_alias (struct symbol
*sym
, CORE_ADDR addr
)
1766 struct range_list
*r
;
1767 struct alias_list
*aliases
;
1769 /* If we have aliases, check them first. */
1770 aliases
= SYMBOL_ALIASES (sym
);
1774 if (!SYMBOL_RANGES (aliases
->sym
))
1775 return aliases
->sym
;
1776 for (r
= SYMBOL_RANGES (aliases
->sym
); r
; r
= r
->next
)
1778 if (r
->start
<= addr
&& r
->end
> addr
)
1779 return aliases
->sym
;
1781 aliases
= aliases
->next
;
1784 /* Nothing found, return the main symbol. */
1789 /* Find the symtab associated with PC and SECTION. Look through the
1790 psymtabs and read in another symtab if necessary. */
1793 find_pc_sect_symtab (CORE_ADDR pc
, asection
*section
)
1795 register struct block
*b
;
1796 struct blockvector
*bv
;
1797 register struct symtab
*s
= NULL
;
1798 register struct symtab
*best_s
= NULL
;
1799 register struct partial_symtab
*ps
;
1800 register struct objfile
*objfile
;
1801 CORE_ADDR distance
= 0;
1802 struct minimal_symbol
*msymbol
;
1804 /* If we know that this is not a text address, return failure. This is
1805 necessary because we loop based on the block's high and low code
1806 addresses, which do not include the data ranges, and because
1807 we call find_pc_sect_psymtab which has a similar restriction based
1808 on the partial_symtab's texthigh and textlow. */
1809 msymbol
= lookup_minimal_symbol_by_pc_section (pc
, section
);
1811 && (msymbol
->type
== mst_data
1812 || msymbol
->type
== mst_bss
1813 || msymbol
->type
== mst_abs
1814 || msymbol
->type
== mst_file_data
1815 || msymbol
->type
== mst_file_bss
))
1818 /* Search all symtabs for the one whose file contains our address, and which
1819 is the smallest of all the ones containing the address. This is designed
1820 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1821 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1822 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1824 This happens for native ecoff format, where code from included files
1825 gets its own symtab. The symtab for the included file should have
1826 been read in already via the dependency mechanism.
1827 It might be swifter to create several symtabs with the same name
1828 like xcoff does (I'm not sure).
1830 It also happens for objfiles that have their functions reordered.
1831 For these, the symtab we are looking for is not necessarily read in. */
1833 ALL_SYMTABS (objfile
, s
)
1835 bv
= BLOCKVECTOR (s
);
1836 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1838 if (BLOCK_START (b
) <= pc
1839 && BLOCK_END (b
) > pc
1841 || BLOCK_END (b
) - BLOCK_START (b
) < distance
))
1843 /* For an objfile that has its functions reordered,
1844 find_pc_psymtab will find the proper partial symbol table
1845 and we simply return its corresponding symtab. */
1846 /* In order to better support objfiles that contain both
1847 stabs and coff debugging info, we continue on if a psymtab
1849 if ((objfile
->flags
& OBJF_REORDERED
) && objfile
->psymtabs
)
1851 ps
= find_pc_sect_psymtab (pc
, section
);
1853 return PSYMTAB_TO_SYMTAB (ps
);
1858 struct symbol
*sym
= NULL
;
1860 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
1862 fixup_symbol_section (sym
, objfile
);
1863 if (section
== SYMBOL_BFD_SECTION (sym
))
1866 if ((i
>= BLOCK_BUCKETS (b
)) && (sym
== NULL
))
1867 continue; /* no symbol in this symtab matches section */
1869 distance
= BLOCK_END (b
) - BLOCK_START (b
);
1878 ps
= find_pc_sect_psymtab (pc
, section
);
1882 /* Might want to error() here (in case symtab is corrupt and
1883 will cause a core dump), but maybe we can successfully
1884 continue, so let's not. */
1886 (Internal error: pc 0x%s in read in psymtab, but not in symtab.)\n",
1888 s
= PSYMTAB_TO_SYMTAB (ps
);
1893 /* Find the symtab associated with PC. Look through the psymtabs and
1894 read in another symtab if necessary. Backward compatibility, no section */
1897 find_pc_symtab (CORE_ADDR pc
)
1899 return find_pc_sect_symtab (pc
, find_pc_mapped_section (pc
));
1903 /* Find the source file and line number for a given PC value and SECTION.
1904 Return a structure containing a symtab pointer, a line number,
1905 and a pc range for the entire source line.
1906 The value's .pc field is NOT the specified pc.
1907 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1908 use the line that ends there. Otherwise, in that case, the line
1909 that begins there is used. */
1911 /* The big complication here is that a line may start in one file, and end just
1912 before the start of another file. This usually occurs when you #include
1913 code in the middle of a subroutine. To properly find the end of a line's PC
1914 range, we must search all symtabs associated with this compilation unit, and
1915 find the one whose first PC is closer than that of the next line in this
1918 /* If it's worth the effort, we could be using a binary search. */
1920 struct symtab_and_line
1921 find_pc_sect_line (CORE_ADDR pc
, struct sec
*section
, int notcurrent
)
1924 register struct linetable
*l
;
1927 register struct linetable_entry
*item
;
1928 struct symtab_and_line val
;
1929 struct blockvector
*bv
;
1930 struct minimal_symbol
*msymbol
;
1931 struct minimal_symbol
*mfunsym
;
1933 /* Info on best line seen so far, and where it starts, and its file. */
1935 struct linetable_entry
*best
= NULL
;
1936 CORE_ADDR best_end
= 0;
1937 struct symtab
*best_symtab
= 0;
1939 /* Store here the first line number
1940 of a file which contains the line at the smallest pc after PC.
1941 If we don't find a line whose range contains PC,
1942 we will use a line one less than this,
1943 with a range from the start of that file to the first line's pc. */
1944 struct linetable_entry
*alt
= NULL
;
1945 struct symtab
*alt_symtab
= 0;
1947 /* Info on best line seen in this file. */
1949 struct linetable_entry
*prev
;
1951 /* If this pc is not from the current frame,
1952 it is the address of the end of a call instruction.
1953 Quite likely that is the start of the following statement.
1954 But what we want is the statement containing the instruction.
1955 Fudge the pc to make sure we get that. */
1957 init_sal (&val
); /* initialize to zeroes */
1959 /* It's tempting to assume that, if we can't find debugging info for
1960 any function enclosing PC, that we shouldn't search for line
1961 number info, either. However, GAS can emit line number info for
1962 assembly files --- very helpful when debugging hand-written
1963 assembly code. In such a case, we'd have no debug info for the
1964 function, but we would have line info. */
1969 /* elz: added this because this function returned the wrong
1970 information if the pc belongs to a stub (import/export)
1971 to call a shlib function. This stub would be anywhere between
1972 two functions in the target, and the line info was erroneously
1973 taken to be the one of the line before the pc.
1975 /* RT: Further explanation:
1977 * We have stubs (trampolines) inserted between procedures.
1979 * Example: "shr1" exists in a shared library, and a "shr1" stub also
1980 * exists in the main image.
1982 * In the minimal symbol table, we have a bunch of symbols
1983 * sorted by start address. The stubs are marked as "trampoline",
1984 * the others appear as text. E.g.:
1986 * Minimal symbol table for main image
1987 * main: code for main (text symbol)
1988 * shr1: stub (trampoline symbol)
1989 * foo: code for foo (text symbol)
1991 * Minimal symbol table for "shr1" image:
1993 * shr1: code for shr1 (text symbol)
1996 * So the code below is trying to detect if we are in the stub
1997 * ("shr1" stub), and if so, find the real code ("shr1" trampoline),
1998 * and if found, do the symbolization from the real-code address
1999 * rather than the stub address.
2001 * Assumptions being made about the minimal symbol table:
2002 * 1. lookup_minimal_symbol_by_pc() will return a trampoline only
2003 * if we're really in the trampoline. If we're beyond it (say
2004 * we're in "foo" in the above example), it'll have a closer
2005 * symbol (the "foo" text symbol for example) and will not
2006 * return the trampoline.
2007 * 2. lookup_minimal_symbol_text() will find a real text symbol
2008 * corresponding to the trampoline, and whose address will
2009 * be different than the trampoline address. I put in a sanity
2010 * check for the address being the same, to avoid an
2011 * infinite recursion.
2013 msymbol
= lookup_minimal_symbol_by_pc (pc
);
2014 if (msymbol
!= NULL
)
2015 if (MSYMBOL_TYPE (msymbol
) == mst_solib_trampoline
)
2017 mfunsym
= lookup_minimal_symbol_text (DEPRECATED_SYMBOL_NAME (msymbol
), NULL
, NULL
);
2018 if (mfunsym
== NULL
)
2019 /* I eliminated this warning since it is coming out
2020 * in the following situation:
2021 * gdb shmain // test program with shared libraries
2022 * (gdb) break shr1 // function in shared lib
2023 * Warning: In stub for ...
2024 * In the above situation, the shared lib is not loaded yet,
2025 * so of course we can't find the real func/line info,
2026 * but the "break" still works, and the warning is annoying.
2027 * So I commented out the warning. RT */
2028 /* warning ("In stub for %s; unable to find real function/line info", DEPRECATED_SYMBOL_NAME (msymbol)) */ ;
2030 else if (SYMBOL_VALUE (mfunsym
) == SYMBOL_VALUE (msymbol
))
2031 /* Avoid infinite recursion */
2032 /* See above comment about why warning is commented out */
2033 /* warning ("In stub for %s; unable to find real function/line info", DEPRECATED_SYMBOL_NAME (msymbol)) */ ;
2036 return find_pc_line (SYMBOL_VALUE (mfunsym
), 0);
2040 s
= find_pc_sect_symtab (pc
, section
);
2043 /* if no symbol information, return previous pc */
2050 bv
= BLOCKVECTOR (s
);
2052 /* Look at all the symtabs that share this blockvector.
2053 They all have the same apriori range, that we found was right;
2054 but they have different line tables. */
2056 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
2058 /* Find the best line in this symtab. */
2065 /* I think len can be zero if the symtab lacks line numbers
2066 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
2067 I'm not sure which, and maybe it depends on the symbol
2073 item
= l
->item
; /* Get first line info */
2075 /* Is this file's first line closer than the first lines of other files?
2076 If so, record this file, and its first line, as best alternate. */
2077 if (item
->pc
> pc
&& (!alt
|| item
->pc
< alt
->pc
))
2083 for (i
= 0; i
< len
; i
++, item
++)
2085 /* Leave prev pointing to the linetable entry for the last line
2086 that started at or before PC. */
2093 /* At this point, prev points at the line whose start addr is <= pc, and
2094 item points at the next line. If we ran off the end of the linetable
2095 (pc >= start of the last line), then prev == item. If pc < start of
2096 the first line, prev will not be set. */
2098 /* Is this file's best line closer than the best in the other files?
2099 If so, record this file, and its best line, as best so far. Don't
2100 save prev if it represents the end of a function (i.e. line number
2101 0) instead of a real line. */
2103 if (prev
&& prev
->line
&& (!best
|| prev
->pc
> best
->pc
))
2108 /* Discard BEST_END if it's before the PC of the current BEST. */
2109 if (best_end
<= best
->pc
)
2113 /* If another line (denoted by ITEM) is in the linetable and its
2114 PC is after BEST's PC, but before the current BEST_END, then
2115 use ITEM's PC as the new best_end. */
2116 if (best
&& i
< len
&& item
->pc
> best
->pc
2117 && (best_end
== 0 || best_end
> item
->pc
))
2118 best_end
= item
->pc
;
2124 { /* If we didn't find any line # info, just
2130 val
.symtab
= alt_symtab
;
2131 val
.line
= alt
->line
- 1;
2133 /* Don't return line 0, that means that we didn't find the line. */
2137 val
.pc
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
2141 else if (best
->line
== 0)
2143 /* If our best fit is in a range of PC's for which no line
2144 number info is available (line number is zero) then we didn't
2145 find any valid line information. */
2150 val
.symtab
= best_symtab
;
2151 val
.line
= best
->line
;
2153 if (best_end
&& (!alt
|| best_end
< alt
->pc
))
2158 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
2160 val
.section
= section
;
2164 /* Backward compatibility (no section) */
2166 struct symtab_and_line
2167 find_pc_line (CORE_ADDR pc
, int notcurrent
)
2171 section
= find_pc_overlay (pc
);
2172 if (pc_in_unmapped_range (pc
, section
))
2173 pc
= overlay_mapped_address (pc
, section
);
2174 return find_pc_sect_line (pc
, section
, notcurrent
);
2177 /* Find line number LINE in any symtab whose name is the same as
2180 If found, return the symtab that contains the linetable in which it was
2181 found, set *INDEX to the index in the linetable of the best entry
2182 found, and set *EXACT_MATCH nonzero if the value returned is an
2185 If not found, return NULL. */
2188 find_line_symtab (struct symtab
*symtab
, int line
, int *index
, int *exact_match
)
2192 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
2196 struct linetable
*best_linetable
;
2197 struct symtab
*best_symtab
;
2199 /* First try looking it up in the given symtab. */
2200 best_linetable
= LINETABLE (symtab
);
2201 best_symtab
= symtab
;
2202 best_index
= find_line_common (best_linetable
, line
, &exact
);
2203 if (best_index
< 0 || !exact
)
2205 /* Didn't find an exact match. So we better keep looking for
2206 another symtab with the same name. In the case of xcoff,
2207 multiple csects for one source file (produced by IBM's FORTRAN
2208 compiler) produce multiple symtabs (this is unavoidable
2209 assuming csects can be at arbitrary places in memory and that
2210 the GLOBAL_BLOCK of a symtab has a begin and end address). */
2212 /* BEST is the smallest linenumber > LINE so far seen,
2213 or 0 if none has been seen so far.
2214 BEST_INDEX and BEST_LINETABLE identify the item for it. */
2217 struct objfile
*objfile
;
2220 if (best_index
>= 0)
2221 best
= best_linetable
->item
[best_index
].line
;
2225 ALL_SYMTABS (objfile
, s
)
2227 struct linetable
*l
;
2230 if (!STREQ (symtab
->filename
, s
->filename
))
2233 ind
= find_line_common (l
, line
, &exact
);
2243 if (best
== 0 || l
->item
[ind
].line
< best
)
2245 best
= l
->item
[ind
].line
;
2258 *index
= best_index
;
2260 *exact_match
= exact
;
2265 /* Set the PC value for a given source file and line number and return true.
2266 Returns zero for invalid line number (and sets the PC to 0).
2267 The source file is specified with a struct symtab. */
2270 find_line_pc (struct symtab
*symtab
, int line
, CORE_ADDR
*pc
)
2272 struct linetable
*l
;
2279 symtab
= find_line_symtab (symtab
, line
, &ind
, NULL
);
2282 l
= LINETABLE (symtab
);
2283 *pc
= l
->item
[ind
].pc
;
2290 /* Find the range of pc values in a line.
2291 Store the starting pc of the line into *STARTPTR
2292 and the ending pc (start of next line) into *ENDPTR.
2293 Returns 1 to indicate success.
2294 Returns 0 if could not find the specified line. */
2297 find_line_pc_range (struct symtab_and_line sal
, CORE_ADDR
*startptr
,
2300 CORE_ADDR startaddr
;
2301 struct symtab_and_line found_sal
;
2304 if (startaddr
== 0 && !find_line_pc (sal
.symtab
, sal
.line
, &startaddr
))
2307 /* This whole function is based on address. For example, if line 10 has
2308 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
2309 "info line *0x123" should say the line goes from 0x100 to 0x200
2310 and "info line *0x355" should say the line goes from 0x300 to 0x400.
2311 This also insures that we never give a range like "starts at 0x134
2312 and ends at 0x12c". */
2314 found_sal
= find_pc_sect_line (startaddr
, sal
.section
, 0);
2315 if (found_sal
.line
!= sal
.line
)
2317 /* The specified line (sal) has zero bytes. */
2318 *startptr
= found_sal
.pc
;
2319 *endptr
= found_sal
.pc
;
2323 *startptr
= found_sal
.pc
;
2324 *endptr
= found_sal
.end
;
2329 /* Given a line table and a line number, return the index into the line
2330 table for the pc of the nearest line whose number is >= the specified one.
2331 Return -1 if none is found. The value is >= 0 if it is an index.
2333 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
2336 find_line_common (register struct linetable
*l
, register int lineno
,
2342 /* BEST is the smallest linenumber > LINENO so far seen,
2343 or 0 if none has been seen so far.
2344 BEST_INDEX identifies the item for it. */
2346 int best_index
= -1;
2355 for (i
= 0; i
< len
; i
++)
2357 register struct linetable_entry
*item
= &(l
->item
[i
]);
2359 if (item
->line
== lineno
)
2361 /* Return the first (lowest address) entry which matches. */
2366 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
2373 /* If we got here, we didn't get an exact match. */
2380 find_pc_line_pc_range (CORE_ADDR pc
, CORE_ADDR
*startptr
, CORE_ADDR
*endptr
)
2382 struct symtab_and_line sal
;
2383 sal
= find_pc_line (pc
, 0);
2386 return sal
.symtab
!= 0;
2389 /* Given a function symbol SYM, find the symtab and line for the start
2391 If the argument FUNFIRSTLINE is nonzero, we want the first line
2392 of real code inside the function. */
2394 struct symtab_and_line
2395 find_function_start_sal (struct symbol
*sym
, int funfirstline
)
2398 struct symtab_and_line sal
;
2400 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
2401 fixup_symbol_section (sym
, NULL
);
2403 { /* skip "first line" of function (which is actually its prologue) */
2404 asection
*section
= SYMBOL_BFD_SECTION (sym
);
2405 /* If function is in an unmapped overlay, use its unmapped LMA
2406 address, so that SKIP_PROLOGUE has something unique to work on */
2407 if (section_is_overlay (section
) &&
2408 !section_is_mapped (section
))
2409 pc
= overlay_unmapped_address (pc
, section
);
2411 pc
+= FUNCTION_START_OFFSET
;
2412 pc
= SKIP_PROLOGUE (pc
);
2414 /* For overlays, map pc back into its mapped VMA range */
2415 pc
= overlay_mapped_address (pc
, section
);
2417 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
2419 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
2420 /* Convex: no need to suppress code on first line, if any */
2423 /* Check if SKIP_PROLOGUE left us in mid-line, and the next
2424 line is still part of the same function. */
2426 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) <= sal
.end
2427 && sal
.end
< BLOCK_END (SYMBOL_BLOCK_VALUE (sym
)))
2429 /* First pc of next line */
2431 /* Recalculate the line number (might not be N+1). */
2432 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
2440 /* If P is of the form "operator[ \t]+..." where `...' is
2441 some legitimate operator text, return a pointer to the
2442 beginning of the substring of the operator text.
2443 Otherwise, return "". */
2445 operator_chars (char *p
, char **end
)
2448 if (strncmp (p
, "operator", 8))
2452 /* Don't get faked out by `operator' being part of a longer
2454 if (isalpha (*p
) || *p
== '_' || *p
== '$' || *p
== '\0')
2457 /* Allow some whitespace between `operator' and the operator symbol. */
2458 while (*p
== ' ' || *p
== '\t')
2461 /* Recognize 'operator TYPENAME'. */
2463 if (isalpha (*p
) || *p
== '_' || *p
== '$')
2465 register char *q
= p
+ 1;
2466 while (isalnum (*q
) || *q
== '_' || *q
== '$')
2475 case '\\': /* regexp quoting */
2478 if (p
[2] == '=') /* 'operator\*=' */
2480 else /* 'operator\*' */
2484 else if (p
[1] == '[')
2487 error ("mismatched quoting on brackets, try 'operator\\[\\]'");
2488 else if (p
[2] == '\\' && p
[3] == ']')
2490 *end
= p
+ 4; /* 'operator\[\]' */
2494 error ("nothing is allowed between '[' and ']'");
2498 /* Gratuitous qoute: skip it and move on. */
2520 if (p
[0] == '-' && p
[1] == '>')
2522 /* Struct pointer member operator 'operator->'. */
2525 *end
= p
+ 3; /* 'operator->*' */
2528 else if (p
[2] == '\\')
2530 *end
= p
+ 4; /* Hopefully 'operator->\*' */
2535 *end
= p
+ 2; /* 'operator->' */
2539 if (p
[1] == '=' || p
[1] == p
[0])
2550 error ("`operator ()' must be specified without whitespace in `()'");
2555 error ("`operator ?:' must be specified without whitespace in `?:'");
2560 error ("`operator []' must be specified without whitespace in `[]'");
2564 error ("`operator %s' not supported", p
);
2573 /* If FILE is not already in the table of files, return zero;
2574 otherwise return non-zero. Optionally add FILE to the table if ADD
2575 is non-zero. If *FIRST is non-zero, forget the old table
2578 filename_seen (const char *file
, int add
, int *first
)
2580 /* Table of files seen so far. */
2581 static const char **tab
= NULL
;
2582 /* Allocated size of tab in elements.
2583 Start with one 256-byte block (when using GNU malloc.c).
2584 24 is the malloc overhead when range checking is in effect. */
2585 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
2586 /* Current size of tab in elements. */
2587 static int tab_cur_size
;
2593 tab
= (const char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
2597 /* Is FILE in tab? */
2598 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
2599 if (strcmp (*p
, file
) == 0)
2602 /* No; maybe add it to tab. */
2605 if (tab_cur_size
== tab_alloc_size
)
2607 tab_alloc_size
*= 2;
2608 tab
= (const char **) xrealloc ((char *) tab
,
2609 tab_alloc_size
* sizeof (*tab
));
2611 tab
[tab_cur_size
++] = file
;
2617 /* Slave routine for sources_info. Force line breaks at ,'s.
2618 NAME is the name to print and *FIRST is nonzero if this is the first
2619 name printed. Set *FIRST to zero. */
2621 output_source_filename (char *name
, int *first
)
2623 /* Since a single source file can result in several partial symbol
2624 tables, we need to avoid printing it more than once. Note: if
2625 some of the psymtabs are read in and some are not, it gets
2626 printed both under "Source files for which symbols have been
2627 read" and "Source files for which symbols will be read in on
2628 demand". I consider this a reasonable way to deal with the
2629 situation. I'm not sure whether this can also happen for
2630 symtabs; it doesn't hurt to check. */
2632 /* Was NAME already seen? */
2633 if (filename_seen (name
, 1, first
))
2635 /* Yes; don't print it again. */
2638 /* No; print it and reset *FIRST. */
2645 printf_filtered (", ");
2649 fputs_filtered (name
, gdb_stdout
);
2653 sources_info (char *ignore
, int from_tty
)
2655 register struct symtab
*s
;
2656 register struct partial_symtab
*ps
;
2657 register struct objfile
*objfile
;
2660 if (!have_full_symbols () && !have_partial_symbols ())
2662 error ("No symbol table is loaded. Use the \"file\" command.");
2665 printf_filtered ("Source files for which symbols have been read in:\n\n");
2668 ALL_SYMTABS (objfile
, s
)
2670 output_source_filename (s
->filename
, &first
);
2672 printf_filtered ("\n\n");
2674 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2677 ALL_PSYMTABS (objfile
, ps
)
2681 output_source_filename (ps
->filename
, &first
);
2684 printf_filtered ("\n");
2688 file_matches (char *file
, char *files
[], int nfiles
)
2692 if (file
!= NULL
&& nfiles
!= 0)
2694 for (i
= 0; i
< nfiles
; i
++)
2696 if (strcmp (files
[i
], lbasename (file
)) == 0)
2700 else if (nfiles
== 0)
2705 /* Free any memory associated with a search. */
2707 free_search_symbols (struct symbol_search
*symbols
)
2709 struct symbol_search
*p
;
2710 struct symbol_search
*next
;
2712 for (p
= symbols
; p
!= NULL
; p
= next
)
2720 do_free_search_symbols_cleanup (void *symbols
)
2722 free_search_symbols (symbols
);
2726 make_cleanup_free_search_symbols (struct symbol_search
*symbols
)
2728 return make_cleanup (do_free_search_symbols_cleanup
, symbols
);
2731 /* Helper function for sort_search_symbols and qsort. Can only
2732 sort symbols, not minimal symbols. */
2734 compare_search_syms (const void *sa
, const void *sb
)
2736 struct symbol_search
**sym_a
= (struct symbol_search
**) sa
;
2737 struct symbol_search
**sym_b
= (struct symbol_search
**) sb
;
2739 return strcmp (SYMBOL_PRINT_NAME ((*sym_a
)->symbol
),
2740 SYMBOL_PRINT_NAME ((*sym_b
)->symbol
));
2743 /* Sort the ``nfound'' symbols in the list after prevtail. Leave
2744 prevtail where it is, but update its next pointer to point to
2745 the first of the sorted symbols. */
2746 static struct symbol_search
*
2747 sort_search_symbols (struct symbol_search
*prevtail
, int nfound
)
2749 struct symbol_search
**symbols
, *symp
, *old_next
;
2752 symbols
= (struct symbol_search
**) xmalloc (sizeof (struct symbol_search
*)
2754 symp
= prevtail
->next
;
2755 for (i
= 0; i
< nfound
; i
++)
2760 /* Generally NULL. */
2763 qsort (symbols
, nfound
, sizeof (struct symbol_search
*),
2764 compare_search_syms
);
2767 for (i
= 0; i
< nfound
; i
++)
2769 symp
->next
= symbols
[i
];
2772 symp
->next
= old_next
;
2778 /* Search the symbol table for matches to the regular expression REGEXP,
2779 returning the results in *MATCHES.
2781 Only symbols of KIND are searched:
2782 FUNCTIONS_DOMAIN - search all functions
2783 TYPES_DOMAIN - search all type names
2784 METHODS_DOMAIN - search all methods NOT IMPLEMENTED
2785 VARIABLES_DOMAIN - search all symbols, excluding functions, type names,
2786 and constants (enums)
2788 free_search_symbols should be called when *MATCHES is no longer needed.
2790 The results are sorted locally; each symtab's global and static blocks are
2791 separately alphabetized.
2794 search_symbols (char *regexp
, domain_enum kind
, int nfiles
, char *files
[],
2795 struct symbol_search
**matches
)
2797 register struct symtab
*s
;
2798 register struct partial_symtab
*ps
;
2799 register struct blockvector
*bv
;
2800 struct blockvector
*prev_bv
= 0;
2801 register struct block
*b
;
2804 register struct symbol
*sym
;
2805 struct partial_symbol
**psym
;
2806 struct objfile
*objfile
;
2807 struct minimal_symbol
*msymbol
;
2810 static enum minimal_symbol_type types
[]
2812 {mst_data
, mst_text
, mst_abs
, mst_unknown
};
2813 static enum minimal_symbol_type types2
[]
2815 {mst_bss
, mst_file_text
, mst_abs
, mst_unknown
};
2816 static enum minimal_symbol_type types3
[]
2818 {mst_file_data
, mst_solib_trampoline
, mst_abs
, mst_unknown
};
2819 static enum minimal_symbol_type types4
[]
2821 {mst_file_bss
, mst_text
, mst_abs
, mst_unknown
};
2822 enum minimal_symbol_type ourtype
;
2823 enum minimal_symbol_type ourtype2
;
2824 enum minimal_symbol_type ourtype3
;
2825 enum minimal_symbol_type ourtype4
;
2826 struct symbol_search
*sr
;
2827 struct symbol_search
*psr
;
2828 struct symbol_search
*tail
;
2829 struct cleanup
*old_chain
= NULL
;
2831 if (kind
< VARIABLES_DOMAIN
)
2832 error ("must search on specific domain");
2834 ourtype
= types
[(int) (kind
- VARIABLES_DOMAIN
)];
2835 ourtype2
= types2
[(int) (kind
- VARIABLES_DOMAIN
)];
2836 ourtype3
= types3
[(int) (kind
- VARIABLES_DOMAIN
)];
2837 ourtype4
= types4
[(int) (kind
- VARIABLES_DOMAIN
)];
2839 sr
= *matches
= NULL
;
2844 /* Make sure spacing is right for C++ operators.
2845 This is just a courtesy to make the matching less sensitive
2846 to how many spaces the user leaves between 'operator'
2847 and <TYPENAME> or <OPERATOR>. */
2849 char *opname
= operator_chars (regexp
, &opend
);
2852 int fix
= -1; /* -1 means ok; otherwise number of spaces needed. */
2853 if (isalpha (*opname
) || *opname
== '_' || *opname
== '$')
2855 /* There should 1 space between 'operator' and 'TYPENAME'. */
2856 if (opname
[-1] != ' ' || opname
[-2] == ' ')
2861 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2862 if (opname
[-1] == ' ')
2865 /* If wrong number of spaces, fix it. */
2868 char *tmp
= (char *) alloca (8 + fix
+ strlen (opname
) + 1);
2869 sprintf (tmp
, "operator%.*s%s", fix
, " ", opname
);
2874 if (0 != (val
= re_comp (regexp
)))
2875 error ("Invalid regexp (%s): %s", val
, regexp
);
2878 /* Search through the partial symtabs *first* for all symbols
2879 matching the regexp. That way we don't have to reproduce all of
2880 the machinery below. */
2882 ALL_PSYMTABS (objfile
, ps
)
2884 struct partial_symbol
**bound
, **gbound
, **sbound
;
2890 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2891 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2894 /* Go through all of the symbols stored in a partial
2895 symtab in one loop. */
2896 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2901 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2903 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2914 /* If it would match (logic taken from loop below)
2915 load the file and go on to the next one */
2916 if (file_matches (ps
->filename
, files
, nfiles
)
2918 || re_exec (SYMBOL_NATURAL_NAME (*psym
)) != 0)
2919 && ((kind
== VARIABLES_DOMAIN
&& SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
2920 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
2921 || (kind
== FUNCTIONS_DOMAIN
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
2922 || (kind
== TYPES_DOMAIN
&& SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
)
2923 || (kind
== METHODS_DOMAIN
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
))))
2925 PSYMTAB_TO_SYMTAB (ps
);
2933 /* Here, we search through the minimal symbol tables for functions
2934 and variables that match, and force their symbols to be read.
2935 This is in particular necessary for demangled variable names,
2936 which are no longer put into the partial symbol tables.
2937 The symbol will then be found during the scan of symtabs below.
2939 For functions, find_pc_symtab should succeed if we have debug info
2940 for the function, for variables we have to call lookup_symbol
2941 to determine if the variable has debug info.
2942 If the lookup fails, set found_misc so that we will rescan to print
2943 any matching symbols without debug info.
2946 if (nfiles
== 0 && (kind
== VARIABLES_DOMAIN
|| kind
== FUNCTIONS_DOMAIN
))
2948 ALL_MSYMBOLS (objfile
, msymbol
)
2950 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
2951 MSYMBOL_TYPE (msymbol
) == ourtype2
||
2952 MSYMBOL_TYPE (msymbol
) == ourtype3
||
2953 MSYMBOL_TYPE (msymbol
) == ourtype4
)
2956 || re_exec (SYMBOL_NATURAL_NAME (msymbol
)) != 0)
2958 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
)))
2960 /* FIXME: carlton/2003-02-04: Given that the
2961 semantics of lookup_symbol keeps on changing
2962 slightly, it would be a nice idea if we had a
2963 function lookup_symbol_minsym that found the
2964 symbol associated to a given minimal symbol (if
2966 if (kind
== FUNCTIONS_DOMAIN
2967 || lookup_symbol (DEPRECATED_SYMBOL_NAME (msymbol
),
2968 (struct block
*) NULL
,
2970 0, (struct symtab
**) NULL
) == NULL
)
2978 ALL_SYMTABS (objfile
, s
)
2980 bv
= BLOCKVECTOR (s
);
2981 /* Often many files share a blockvector.
2982 Scan each blockvector only once so that
2983 we don't get every symbol many times.
2984 It happens that the first symtab in the list
2985 for any given blockvector is the main file. */
2987 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
2989 struct symbol_search
*prevtail
= tail
;
2991 b
= BLOCKVECTOR_BLOCK (bv
, i
);
2992 ALL_BLOCK_SYMBOLS (b
, j
, sym
)
2995 if (file_matches (s
->filename
, files
, nfiles
)
2997 || re_exec (SYMBOL_NATURAL_NAME (sym
)) != 0)
2998 && ((kind
== VARIABLES_DOMAIN
&& SYMBOL_CLASS (sym
) != LOC_TYPEDEF
2999 && SYMBOL_CLASS (sym
) != LOC_BLOCK
3000 && SYMBOL_CLASS (sym
) != LOC_CONST
)
3001 || (kind
== FUNCTIONS_DOMAIN
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3002 || (kind
== TYPES_DOMAIN
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3003 || (kind
== METHODS_DOMAIN
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
))))
3006 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
3010 psr
->msymbol
= NULL
;
3022 if (prevtail
== NULL
)
3024 struct symbol_search dummy
;
3027 tail
= sort_search_symbols (&dummy
, nfound
);
3030 old_chain
= make_cleanup_free_search_symbols (sr
);
3033 tail
= sort_search_symbols (prevtail
, nfound
);
3039 /* If there are no eyes, avoid all contact. I mean, if there are
3040 no debug symbols, then print directly from the msymbol_vector. */
3042 if (found_misc
|| kind
!= FUNCTIONS_DOMAIN
)
3044 ALL_MSYMBOLS (objfile
, msymbol
)
3046 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
3047 MSYMBOL_TYPE (msymbol
) == ourtype2
||
3048 MSYMBOL_TYPE (msymbol
) == ourtype3
||
3049 MSYMBOL_TYPE (msymbol
) == ourtype4
)
3052 || re_exec (SYMBOL_NATURAL_NAME (msymbol
)) != 0)
3054 /* Functions: Look up by address. */
3055 if (kind
!= FUNCTIONS_DOMAIN
||
3056 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
))))
3058 /* Variables/Absolutes: Look up by name */
3059 if (lookup_symbol (DEPRECATED_SYMBOL_NAME (msymbol
),
3060 (struct block
*) NULL
, VAR_DOMAIN
,
3061 0, (struct symtab
**) NULL
) == NULL
)
3064 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
3066 psr
->msymbol
= msymbol
;
3073 old_chain
= make_cleanup_free_search_symbols (sr
);
3087 discard_cleanups (old_chain
);
3090 /* Helper function for symtab_symbol_info, this function uses
3091 the data returned from search_symbols() to print information
3092 regarding the match to gdb_stdout.
3095 print_symbol_info (domain_enum kind
, struct symtab
*s
, struct symbol
*sym
,
3096 int block
, char *last
)
3098 if (last
== NULL
|| strcmp (last
, s
->filename
) != 0)
3100 fputs_filtered ("\nFile ", gdb_stdout
);
3101 fputs_filtered (s
->filename
, gdb_stdout
);
3102 fputs_filtered (":\n", gdb_stdout
);
3105 if (kind
!= TYPES_DOMAIN
&& block
== STATIC_BLOCK
)
3106 printf_filtered ("static ");
3108 /* Typedef that is not a C++ class */
3109 if (kind
== TYPES_DOMAIN
3110 && SYMBOL_DOMAIN (sym
) != STRUCT_DOMAIN
)
3111 typedef_print (SYMBOL_TYPE (sym
), sym
, gdb_stdout
);
3112 /* variable, func, or typedef-that-is-c++-class */
3113 else if (kind
< TYPES_DOMAIN
||
3114 (kind
== TYPES_DOMAIN
&&
3115 SYMBOL_DOMAIN (sym
) == STRUCT_DOMAIN
))
3117 type_print (SYMBOL_TYPE (sym
),
3118 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3119 ? "" : SYMBOL_PRINT_NAME (sym
)),
3122 printf_filtered (";\n");
3126 /* This help function for symtab_symbol_info() prints information
3127 for non-debugging symbols to gdb_stdout.
3130 print_msymbol_info (struct minimal_symbol
*msymbol
)
3134 if (TARGET_ADDR_BIT
<= 32)
3135 tmp
= local_hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol
)
3136 & (CORE_ADDR
) 0xffffffff,
3139 tmp
= local_hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol
),
3141 printf_filtered ("%s %s\n",
3142 tmp
, SYMBOL_PRINT_NAME (msymbol
));
3145 /* This is the guts of the commands "info functions", "info types", and
3146 "info variables". It calls search_symbols to find all matches and then
3147 print_[m]symbol_info to print out some useful information about the
3151 symtab_symbol_info (char *regexp
, domain_enum kind
, int from_tty
)
3153 static char *classnames
[]
3155 {"variable", "function", "type", "method"};
3156 struct symbol_search
*symbols
;
3157 struct symbol_search
*p
;
3158 struct cleanup
*old_chain
;
3159 char *last_filename
= NULL
;
3162 /* must make sure that if we're interrupted, symbols gets freed */
3163 search_symbols (regexp
, kind
, 0, (char **) NULL
, &symbols
);
3164 old_chain
= make_cleanup_free_search_symbols (symbols
);
3166 printf_filtered (regexp
3167 ? "All %ss matching regular expression \"%s\":\n"
3168 : "All defined %ss:\n",
3169 classnames
[(int) (kind
- VARIABLES_DOMAIN
)], regexp
);
3171 for (p
= symbols
; p
!= NULL
; p
= p
->next
)
3175 if (p
->msymbol
!= NULL
)
3179 printf_filtered ("\nNon-debugging symbols:\n");
3182 print_msymbol_info (p
->msymbol
);
3186 print_symbol_info (kind
,
3191 last_filename
= p
->symtab
->filename
;
3195 do_cleanups (old_chain
);
3199 variables_info (char *regexp
, int from_tty
)
3201 symtab_symbol_info (regexp
, VARIABLES_DOMAIN
, from_tty
);
3205 functions_info (char *regexp
, int from_tty
)
3207 symtab_symbol_info (regexp
, FUNCTIONS_DOMAIN
, from_tty
);
3212 types_info (char *regexp
, int from_tty
)
3214 symtab_symbol_info (regexp
, TYPES_DOMAIN
, from_tty
);
3217 /* Breakpoint all functions matching regular expression. */
3220 rbreak_command_wrapper (char *regexp
, int from_tty
)
3222 rbreak_command (regexp
, from_tty
);
3226 rbreak_command (char *regexp
, int from_tty
)
3228 struct symbol_search
*ss
;
3229 struct symbol_search
*p
;
3230 struct cleanup
*old_chain
;
3232 search_symbols (regexp
, FUNCTIONS_DOMAIN
, 0, (char **) NULL
, &ss
);
3233 old_chain
= make_cleanup_free_search_symbols (ss
);
3235 for (p
= ss
; p
!= NULL
; p
= p
->next
)
3237 if (p
->msymbol
== NULL
)
3239 char *string
= (char *) alloca (strlen (p
->symtab
->filename
)
3240 + strlen (DEPRECATED_SYMBOL_NAME (p
->symbol
))
3242 strcpy (string
, p
->symtab
->filename
);
3243 strcat (string
, ":'");
3244 strcat (string
, DEPRECATED_SYMBOL_NAME (p
->symbol
));
3245 strcat (string
, "'");
3246 break_command (string
, from_tty
);
3247 print_symbol_info (FUNCTIONS_DOMAIN
,
3251 p
->symtab
->filename
);
3255 break_command (DEPRECATED_SYMBOL_NAME (p
->msymbol
), from_tty
);
3256 printf_filtered ("<function, no debug info> %s;\n",
3257 SYMBOL_PRINT_NAME (p
->msymbol
));
3261 do_cleanups (old_chain
);
3265 /* Helper routine for make_symbol_completion_list. */
3267 static int return_val_size
;
3268 static int return_val_index
;
3269 static char **return_val
;
3271 #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
3273 if (SYMBOL_DEMANGLED_NAME (symbol) != NULL) \
3274 /* Put only the mangled name on the list. */ \
3275 /* Advantage: "b foo<TAB>" completes to "b foo(int, int)" */ \
3276 /* Disadvantage: "b foo__i<TAB>" doesn't complete. */ \
3277 completion_list_add_name \
3278 (SYMBOL_DEMANGLED_NAME (symbol), (sym_text), (len), (text), (word)); \
3280 completion_list_add_name \
3281 (DEPRECATED_SYMBOL_NAME (symbol), (sym_text), (len), (text), (word)); \
3284 /* Test to see if the symbol specified by SYMNAME (which is already
3285 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3286 characters. If so, add it to the current completion list. */
3289 completion_list_add_name (char *symname
, char *sym_text
, int sym_text_len
,
3290 char *text
, char *word
)
3295 /* clip symbols that cannot match */
3297 if (strncmp (symname
, sym_text
, sym_text_len
) != 0)
3302 /* We have a match for a completion, so add SYMNAME to the current list
3303 of matches. Note that the name is moved to freshly malloc'd space. */
3307 if (word
== sym_text
)
3309 new = xmalloc (strlen (symname
) + 5);
3310 strcpy (new, symname
);
3312 else if (word
> sym_text
)
3314 /* Return some portion of symname. */
3315 new = xmalloc (strlen (symname
) + 5);
3316 strcpy (new, symname
+ (word
- sym_text
));
3320 /* Return some of SYM_TEXT plus symname. */
3321 new = xmalloc (strlen (symname
) + (sym_text
- word
) + 5);
3322 strncpy (new, word
, sym_text
- word
);
3323 new[sym_text
- word
] = '\0';
3324 strcat (new, symname
);
3327 if (return_val_index
+ 3 > return_val_size
)
3329 newsize
= (return_val_size
*= 2) * sizeof (char *);
3330 return_val
= (char **) xrealloc ((char *) return_val
, newsize
);
3332 return_val
[return_val_index
++] = new;
3333 return_val
[return_val_index
] = NULL
;
3337 /* ObjC: In case we are completing on a selector, look as the msymbol
3338 again and feed all the selectors into the mill. */
3341 completion_list_objc_symbol (struct minimal_symbol
*msymbol
, char *sym_text
,
3342 int sym_text_len
, char *text
, char *word
)
3344 static char *tmp
= NULL
;
3345 static unsigned int tmplen
= 0;
3347 char *method
, *category
, *selector
;
3350 method
= SYMBOL_NATURAL_NAME (msymbol
);
3352 /* Is it a method? */
3353 if ((method
[0] != '-') && (method
[0] != '+'))
3356 if (sym_text
[0] == '[')
3357 /* Complete on shortened method method. */
3358 completion_list_add_name (method
+ 1, sym_text
, sym_text_len
, text
, word
);
3360 while ((strlen (method
) + 1) >= tmplen
)
3366 tmp
= xrealloc (tmp
, tmplen
);
3368 selector
= strchr (method
, ' ');
3369 if (selector
!= NULL
)
3372 category
= strchr (method
, '(');
3374 if ((category
!= NULL
) && (selector
!= NULL
))
3376 memcpy (tmp
, method
, (category
- method
));
3377 tmp
[category
- method
] = ' ';
3378 memcpy (tmp
+ (category
- method
) + 1, selector
, strlen (selector
) + 1);
3379 completion_list_add_name (tmp
, sym_text
, sym_text_len
, text
, word
);
3380 if (sym_text
[0] == '[')
3381 completion_list_add_name (tmp
+ 1, sym_text
, sym_text_len
, text
, word
);
3384 if (selector
!= NULL
)
3386 /* Complete on selector only. */
3387 strcpy (tmp
, selector
);
3388 tmp2
= strchr (tmp
, ']');
3392 completion_list_add_name (tmp
, sym_text
, sym_text_len
, text
, word
);
3396 /* Break the non-quoted text based on the characters which are in
3397 symbols. FIXME: This should probably be language-specific. */
3400 language_search_unquoted_string (char *text
, char *p
)
3402 for (; p
> text
; --p
)
3404 if (isalnum (p
[-1]) || p
[-1] == '_' || p
[-1] == '\0')
3408 if ((current_language
->la_language
== language_objc
))
3410 if (p
[-1] == ':') /* might be part of a method name */
3412 else if (p
[-1] == '[' && (p
[-2] == '-' || p
[-2] == '+'))
3413 p
-= 2; /* beginning of a method name */
3414 else if (p
[-1] == ' ' || p
[-1] == '(' || p
[-1] == ')')
3415 { /* might be part of a method name */
3418 /* Seeing a ' ' or a '(' is not conclusive evidence
3419 that we are in the middle of a method name. However,
3420 finding "-[" or "+[" should be pretty un-ambiguous.
3421 Unfortunately we have to find it now to decide. */
3424 if (isalnum (t
[-1]) || t
[-1] == '_' ||
3425 t
[-1] == ' ' || t
[-1] == ':' ||
3426 t
[-1] == '(' || t
[-1] == ')')
3431 if (t
[-1] == '[' && (t
[-2] == '-' || t
[-2] == '+'))
3432 p
= t
- 2; /* method name detected */
3433 /* else we leave with p unchanged */
3443 /* Return a NULL terminated array of all symbols (regardless of class)
3444 which begin by matching TEXT. If the answer is no symbols, then
3445 the return value is an array which contains only a NULL pointer.
3447 Problem: All of the symbols have to be copied because readline frees them.
3448 I'm not going to worry about this; hopefully there won't be that many. */
3451 make_symbol_completion_list (char *text
, char *word
)
3453 register struct symbol
*sym
;
3454 register struct symtab
*s
;
3455 register struct partial_symtab
*ps
;
3456 register struct minimal_symbol
*msymbol
;
3457 register struct objfile
*objfile
;
3458 register struct block
*b
, *surrounding_static_block
= 0;
3460 struct partial_symbol
**psym
;
3461 /* The symbol we are completing on. Points in same buffer as text. */
3463 /* Length of sym_text. */
3466 /* Now look for the symbol we are supposed to complete on.
3467 FIXME: This should be language-specific. */
3471 char *quote_pos
= NULL
;
3473 /* First see if this is a quoted string. */
3475 for (p
= text
; *p
!= '\0'; ++p
)
3477 if (quote_found
!= '\0')
3479 if (*p
== quote_found
)
3480 /* Found close quote. */
3482 else if (*p
== '\\' && p
[1] == quote_found
)
3483 /* A backslash followed by the quote character
3484 doesn't end the string. */
3487 else if (*p
== '\'' || *p
== '"')
3493 if (quote_found
== '\'')
3494 /* A string within single quotes can be a symbol, so complete on it. */
3495 sym_text
= quote_pos
+ 1;
3496 else if (quote_found
== '"')
3497 /* A double-quoted string is never a symbol, nor does it make sense
3498 to complete it any other way. */
3500 return_val
= (char **) xmalloc (sizeof (char *));
3501 return_val
[0] = NULL
;
3506 /* It is not a quoted string. Break it based on the characters
3507 which are in symbols. */
3510 if (isalnum (p
[-1]) || p
[-1] == '_' || p
[-1] == '\0')
3519 sym_text_len
= strlen (sym_text
);
3521 return_val_size
= 100;
3522 return_val_index
= 0;
3523 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
3524 return_val
[0] = NULL
;
3526 /* Look through the partial symtabs for all symbols which begin
3527 by matching SYM_TEXT. Add each one that you find to the list. */
3529 ALL_PSYMTABS (objfile
, ps
)
3531 /* If the psymtab's been read in we'll get it when we search
3532 through the blockvector. */
3536 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
3537 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
3538 + ps
->n_global_syms
);
3541 /* If interrupted, then quit. */
3543 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3546 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
3547 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
3548 + ps
->n_static_syms
);
3552 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3556 /* At this point scan through the misc symbol vectors and add each
3557 symbol you find to the list. Eventually we want to ignore
3558 anything that isn't a text symbol (everything else will be
3559 handled by the psymtab code above). */
3561 ALL_MSYMBOLS (objfile
, msymbol
)
3564 COMPLETION_LIST_ADD_SYMBOL (msymbol
, sym_text
, sym_text_len
, text
, word
);
3566 completion_list_objc_symbol (msymbol
, sym_text
, sym_text_len
, text
, word
);
3569 /* Search upwards from currently selected frame (so that we can
3570 complete on local vars. */
3572 for (b
= get_selected_block (0); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
3574 if (!BLOCK_SUPERBLOCK (b
))
3576 surrounding_static_block
= b
; /* For elmin of dups */
3579 /* Also catch fields of types defined in this places which match our
3580 text string. Only complete on types visible from current context. */
3582 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
3585 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3586 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3588 struct type
*t
= SYMBOL_TYPE (sym
);
3589 enum type_code c
= TYPE_CODE (t
);
3591 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
3593 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
3595 if (TYPE_FIELD_NAME (t
, j
))
3597 completion_list_add_name (TYPE_FIELD_NAME (t
, j
),
3598 sym_text
, sym_text_len
, text
, word
);
3606 /* Go through the symtabs and check the externs and statics for
3607 symbols which match. */
3609 ALL_SYMTABS (objfile
, s
)
3612 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3613 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
3615 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3619 ALL_SYMTABS (objfile
, s
)
3622 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3623 /* Don't do this block twice. */
3624 if (b
== surrounding_static_block
)
3626 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
3628 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3632 return (return_val
);
3635 /* Like make_symbol_completion_list, but returns a list of symbols
3636 defined in a source file FILE. */
3639 make_file_symbol_completion_list (char *text
, char *word
, char *srcfile
)
3641 register struct symbol
*sym
;
3642 register struct symtab
*s
;
3643 register struct block
*b
;
3645 /* The symbol we are completing on. Points in same buffer as text. */
3647 /* Length of sym_text. */
3650 /* Now look for the symbol we are supposed to complete on.
3651 FIXME: This should be language-specific. */
3655 char *quote_pos
= NULL
;
3657 /* First see if this is a quoted string. */
3659 for (p
= text
; *p
!= '\0'; ++p
)
3661 if (quote_found
!= '\0')
3663 if (*p
== quote_found
)
3664 /* Found close quote. */
3666 else if (*p
== '\\' && p
[1] == quote_found
)
3667 /* A backslash followed by the quote character
3668 doesn't end the string. */
3671 else if (*p
== '\'' || *p
== '"')
3677 if (quote_found
== '\'')
3678 /* A string within single quotes can be a symbol, so complete on it. */
3679 sym_text
= quote_pos
+ 1;
3680 else if (quote_found
== '"')
3681 /* A double-quoted string is never a symbol, nor does it make sense
3682 to complete it any other way. */
3684 return_val
= (char **) xmalloc (sizeof (char *));
3685 return_val
[0] = NULL
;
3690 /* Not a quoted string. */
3691 sym_text
= language_search_unquoted_string (text
, p
);
3695 sym_text_len
= strlen (sym_text
);
3697 return_val_size
= 10;
3698 return_val_index
= 0;
3699 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
3700 return_val
[0] = NULL
;
3702 /* Find the symtab for SRCFILE (this loads it if it was not yet read
3704 s
= lookup_symtab (srcfile
);
3707 /* Maybe they typed the file with leading directories, while the
3708 symbol tables record only its basename. */
3709 const char *tail
= lbasename (srcfile
);
3712 s
= lookup_symtab (tail
);
3715 /* If we have no symtab for that file, return an empty list. */
3717 return (return_val
);
3719 /* Go through this symtab and check the externs and statics for
3720 symbols which match. */
3722 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3723 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
3725 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3728 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3729 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
3731 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3734 return (return_val
);
3737 /* A helper function for make_source_files_completion_list. It adds
3738 another file name to a list of possible completions, growing the
3739 list as necessary. */
3742 add_filename_to_list (const char *fname
, char *text
, char *word
,
3743 char ***list
, int *list_used
, int *list_alloced
)
3746 size_t fnlen
= strlen (fname
);
3748 if (*list_used
+ 1 >= *list_alloced
)
3751 *list
= (char **) xrealloc ((char *) *list
,
3752 *list_alloced
* sizeof (char *));
3757 /* Return exactly fname. */
3758 new = xmalloc (fnlen
+ 5);
3759 strcpy (new, fname
);
3761 else if (word
> text
)
3763 /* Return some portion of fname. */
3764 new = xmalloc (fnlen
+ 5);
3765 strcpy (new, fname
+ (word
- text
));
3769 /* Return some of TEXT plus fname. */
3770 new = xmalloc (fnlen
+ (text
- word
) + 5);
3771 strncpy (new, word
, text
- word
);
3772 new[text
- word
] = '\0';
3773 strcat (new, fname
);
3775 (*list
)[*list_used
] = new;
3776 (*list
)[++*list_used
] = NULL
;
3780 not_interesting_fname (const char *fname
)
3782 static const char *illegal_aliens
[] = {
3783 "_globals_", /* inserted by coff_symtab_read */
3788 for (i
= 0; illegal_aliens
[i
]; i
++)
3790 if (strcmp (fname
, illegal_aliens
[i
]) == 0)
3796 /* Return a NULL terminated array of all source files whose names
3797 begin with matching TEXT. The file names are looked up in the
3798 symbol tables of this program. If the answer is no matchess, then
3799 the return value is an array which contains only a NULL pointer. */
3802 make_source_files_completion_list (char *text
, char *word
)
3804 register struct symtab
*s
;
3805 register struct partial_symtab
*ps
;
3806 register struct objfile
*objfile
;
3808 int list_alloced
= 1;
3810 size_t text_len
= strlen (text
);
3811 char **list
= (char **) xmalloc (list_alloced
* sizeof (char *));
3812 const char *base_name
;
3816 if (!have_full_symbols () && !have_partial_symbols ())
3819 ALL_SYMTABS (objfile
, s
)
3821 if (not_interesting_fname (s
->filename
))
3823 if (!filename_seen (s
->filename
, 1, &first
)
3824 #if HAVE_DOS_BASED_FILE_SYSTEM
3825 && strncasecmp (s
->filename
, text
, text_len
) == 0
3827 && strncmp (s
->filename
, text
, text_len
) == 0
3831 /* This file matches for a completion; add it to the current
3833 add_filename_to_list (s
->filename
, text
, word
,
3834 &list
, &list_used
, &list_alloced
);
3838 /* NOTE: We allow the user to type a base name when the
3839 debug info records leading directories, but not the other
3840 way around. This is what subroutines of breakpoint
3841 command do when they parse file names. */
3842 base_name
= lbasename (s
->filename
);
3843 if (base_name
!= s
->filename
3844 && !filename_seen (base_name
, 1, &first
)
3845 #if HAVE_DOS_BASED_FILE_SYSTEM
3846 && strncasecmp (base_name
, text
, text_len
) == 0
3848 && strncmp (base_name
, text
, text_len
) == 0
3851 add_filename_to_list (base_name
, text
, word
,
3852 &list
, &list_used
, &list_alloced
);
3856 ALL_PSYMTABS (objfile
, ps
)
3858 if (not_interesting_fname (ps
->filename
))
3862 if (!filename_seen (ps
->filename
, 1, &first
)
3863 #if HAVE_DOS_BASED_FILE_SYSTEM
3864 && strncasecmp (ps
->filename
, text
, text_len
) == 0
3866 && strncmp (ps
->filename
, text
, text_len
) == 0
3870 /* This file matches for a completion; add it to the
3871 current list of matches. */
3872 add_filename_to_list (ps
->filename
, text
, word
,
3873 &list
, &list_used
, &list_alloced
);
3878 base_name
= lbasename (ps
->filename
);
3879 if (base_name
!= ps
->filename
3880 && !filename_seen (base_name
, 1, &first
)
3881 #if HAVE_DOS_BASED_FILE_SYSTEM
3882 && strncasecmp (base_name
, text
, text_len
) == 0
3884 && strncmp (base_name
, text
, text_len
) == 0
3887 add_filename_to_list (base_name
, text
, word
,
3888 &list
, &list_used
, &list_alloced
);
3896 /* Determine if PC is in the prologue of a function. The prologue is the area
3897 between the first instruction of a function, and the first executable line.
3898 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
3900 If non-zero, func_start is where we think the prologue starts, possibly
3901 by previous examination of symbol table information.
3905 in_prologue (CORE_ADDR pc
, CORE_ADDR func_start
)
3907 struct symtab_and_line sal
;
3908 CORE_ADDR func_addr
, func_end
;
3910 /* We have several sources of information we can consult to figure
3912 - Compilers usually emit line number info that marks the prologue
3913 as its own "source line". So the ending address of that "line"
3914 is the end of the prologue. If available, this is the most
3916 - The minimal symbols and partial symbols, which can usually tell
3917 us the starting and ending addresses of a function.
3918 - If we know the function's start address, we can call the
3919 architecture-defined SKIP_PROLOGUE function to analyze the
3920 instruction stream and guess where the prologue ends.
3921 - Our `func_start' argument; if non-zero, this is the caller's
3922 best guess as to the function's entry point. At the time of
3923 this writing, handle_inferior_event doesn't get this right, so
3924 it should be our last resort. */
3926 /* Consult the partial symbol table, to find which function
3928 if (! find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
3930 CORE_ADDR prologue_end
;
3932 /* We don't even have minsym information, so fall back to using
3933 func_start, if given. */
3935 return 1; /* We *might* be in a prologue. */
3937 prologue_end
= SKIP_PROLOGUE (func_start
);
3939 return func_start
<= pc
&& pc
< prologue_end
;
3942 /* If we have line number information for the function, that's
3943 usually pretty reliable. */
3944 sal
= find_pc_line (func_addr
, 0);
3946 /* Now sal describes the source line at the function's entry point,
3947 which (by convention) is the prologue. The end of that "line",
3948 sal.end, is the end of the prologue.
3950 Note that, for functions whose source code is all on a single
3951 line, the line number information doesn't always end up this way.
3952 So we must verify that our purported end-of-prologue address is
3953 *within* the function, not at its start or end. */
3955 || sal
.end
<= func_addr
3956 || func_end
<= sal
.end
)
3958 /* We don't have any good line number info, so use the minsym
3959 information, together with the architecture-specific prologue
3961 CORE_ADDR prologue_end
= SKIP_PROLOGUE (func_addr
);
3963 return func_addr
<= pc
&& pc
< prologue_end
;
3966 /* We have line number info, and it looks good. */
3967 return func_addr
<= pc
&& pc
< sal
.end
;
3971 /* Begin overload resolution functions */
3974 remove_params (const char *demangled_name
)
3980 if (demangled_name
== NULL
)
3983 /* First find the end of the arg list. */
3984 argp
= strrchr (demangled_name
, ')');
3988 /* Back up to the beginning. */
3991 while (argp
-- > demangled_name
)
3995 else if (*argp
== '(')
4004 internal_error (__FILE__
, __LINE__
,
4005 "bad demangled name %s\n", demangled_name
);
4006 while (argp
[-1] == ' ' && argp
> demangled_name
)
4009 new_name
= xmalloc (argp
- demangled_name
+ 1);
4010 memcpy (new_name
, demangled_name
, argp
- demangled_name
);
4011 new_name
[argp
- demangled_name
] = '\0';
4015 /* Helper routine for make_symbol_completion_list. */
4017 static int sym_return_val_size
;
4018 static int sym_return_val_index
;
4019 static struct symbol
**sym_return_val
;
4021 /* Test to see if the symbol specified by SYMNAME (which is already
4022 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
4023 characters. If so, add it to the current completion list. */
4026 overload_list_add_symbol (struct symbol
*sym
, char *oload_name
)
4032 /* If there is no type information, we can't do anything, so skip */
4033 if (SYMBOL_TYPE (sym
) == NULL
)
4036 /* skip any symbols that we've already considered. */
4037 for (i
= 0; i
< sym_return_val_index
; ++i
)
4038 if (!strcmp (DEPRECATED_SYMBOL_NAME (sym
), DEPRECATED_SYMBOL_NAME (sym_return_val
[i
])))
4041 /* Get the demangled name without parameters */
4042 sym_name
= remove_params (SYMBOL_DEMANGLED_NAME (sym
));
4046 /* skip symbols that cannot match */
4047 if (strcmp (sym_name
, oload_name
) != 0)
4055 /* We have a match for an overload instance, so add SYM to the current list
4056 * of overload instances */
4057 if (sym_return_val_index
+ 3 > sym_return_val_size
)
4059 newsize
= (sym_return_val_size
*= 2) * sizeof (struct symbol
*);
4060 sym_return_val
= (struct symbol
**) xrealloc ((char *) sym_return_val
, newsize
);
4062 sym_return_val
[sym_return_val_index
++] = sym
;
4063 sym_return_val
[sym_return_val_index
] = NULL
;
4066 /* Return a null-terminated list of pointers to function symbols that
4067 * match name of the supplied symbol FSYM.
4068 * This is used in finding all overloaded instances of a function name.
4069 * This has been modified from make_symbol_completion_list. */
4073 make_symbol_overload_list (struct symbol
*fsym
)
4075 register struct symbol
*sym
;
4076 register struct symtab
*s
;
4077 register struct partial_symtab
*ps
;
4078 register struct objfile
*objfile
;
4079 register struct block
*b
, *surrounding_static_block
= 0;
4081 /* The name we are completing on. */
4082 char *oload_name
= NULL
;
4083 /* Length of name. */
4084 int oload_name_len
= 0;
4086 /* Look for the symbol we are supposed to complete on. */
4088 oload_name
= remove_params (SYMBOL_DEMANGLED_NAME (fsym
));
4091 sym_return_val_size
= 1;
4092 sym_return_val
= (struct symbol
**) xmalloc (2 * sizeof (struct symbol
*));
4093 sym_return_val
[0] = fsym
;
4094 sym_return_val
[1] = NULL
;
4096 return sym_return_val
;
4098 oload_name_len
= strlen (oload_name
);
4100 sym_return_val_size
= 100;
4101 sym_return_val_index
= 0;
4102 sym_return_val
= (struct symbol
**) xmalloc ((sym_return_val_size
+ 1) * sizeof (struct symbol
*));
4103 sym_return_val
[0] = NULL
;
4105 /* Read in all partial symtabs containing a partial symbol named
4108 ALL_PSYMTABS (objfile
, ps
)
4110 struct partial_symbol
**psym
;
4112 /* If the psymtab's been read in we'll get it when we search
4113 through the blockvector. */
4117 if ((lookup_partial_symbol (ps
, oload_name
, NULL
, 1, VAR_DOMAIN
)
4119 || (lookup_partial_symbol (ps
, oload_name
, NULL
, 0, VAR_DOMAIN
)
4121 PSYMTAB_TO_SYMTAB (ps
);
4124 /* Search upwards from currently selected frame (so that we can
4125 complete on local vars. */
4127 for (b
= get_selected_block (0); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
4129 if (!BLOCK_SUPERBLOCK (b
))
4131 surrounding_static_block
= b
; /* For elimination of dups */
4134 /* Also catch fields of types defined in this places which match our
4135 text string. Only complete on types visible from current context. */
4137 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
4139 overload_list_add_symbol (sym
, oload_name
);
4143 /* Go through the symtabs and check the externs and statics for
4144 symbols which match. */
4146 ALL_SYMTABS (objfile
, s
)
4149 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
4150 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
4152 overload_list_add_symbol (sym
, oload_name
);
4156 ALL_SYMTABS (objfile
, s
)
4159 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
4160 /* Don't do this block twice. */
4161 if (b
== surrounding_static_block
)
4163 ALL_BLOCK_SYMBOLS (b
, i
, sym
)
4165 overload_list_add_symbol (sym
, oload_name
);
4171 return (sym_return_val
);
4174 /* End of overload resolution functions */
4176 struct symtabs_and_lines
4177 decode_line_spec (char *string
, int funfirstline
)
4179 struct symtabs_and_lines sals
;
4180 struct symtab_and_line cursal
;
4183 error ("Empty line specification.");
4185 /* We use whatever is set as the current source line. We do not try
4186 and get a default or it will recursively call us! */
4187 cursal
= get_current_source_symtab_and_line ();
4189 sals
= decode_line_1 (&string
, funfirstline
,
4190 cursal
.symtab
, cursal
.line
,
4194 error ("Junk at end of line specification: %s", string
);
4199 static char *name_of_main
;
4202 set_main_name (const char *name
)
4204 if (name_of_main
!= NULL
)
4206 xfree (name_of_main
);
4207 name_of_main
= NULL
;
4211 name_of_main
= xstrdup (name
);
4218 if (name_of_main
!= NULL
)
4219 return name_of_main
;
4226 _initialize_symtab (void)
4228 add_info ("variables", variables_info
,
4229 "All global and static variable names, or those matching REGEXP.");
4231 add_com ("whereis", class_info
, variables_info
,
4232 "All global and static variable names, or those matching REGEXP.");
4234 add_info ("functions", functions_info
,
4235 "All function names, or those matching REGEXP.");
4238 /* FIXME: This command has at least the following problems:
4239 1. It prints builtin types (in a very strange and confusing fashion).
4240 2. It doesn't print right, e.g. with
4241 typedef struct foo *FOO
4242 type_print prints "FOO" when we want to make it (in this situation)
4243 print "struct foo *".
4244 I also think "ptype" or "whatis" is more likely to be useful (but if
4245 there is much disagreement "info types" can be fixed). */
4246 add_info ("types", types_info
,
4247 "All type names, or those matching REGEXP.");
4249 add_info ("sources", sources_info
,
4250 "Source files in the program.");
4252 add_com ("rbreak", class_breakpoint
, rbreak_command
,
4253 "Set a breakpoint for all functions matching REGEXP.");
4257 add_com ("lf", class_info
, sources_info
, "Source files in the program");
4258 add_com ("lg", class_info
, variables_info
,
4259 "All global and static variable names, or those matching REGEXP.");
4262 /* Initialize the one built-in type that isn't language dependent... */
4263 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
4264 "<unknown type>", (struct objfile
*) NULL
);