1 /* Symbol table lookup for the GNU debugger, GDB.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007
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 3 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, see <http://www.gnu.org/licenses/>. */
32 #include "call-cmds.h"
33 #include "gdb_regex.h"
34 #include "expression.h"
40 #include "filenames.h" /* for FILENAME_CMP */
41 #include "objc-lang.h"
46 #include "gdb_obstack.h"
48 #include "dictionary.h"
50 #include <sys/types.h>
52 #include "gdb_string.h"
57 #include "gdb_assert.h"
60 /* Prototypes for local functions */
62 static void completion_list_add_name (char *, char *, int, char *, char *);
64 static void rbreak_command (char *, int);
66 static void types_info (char *, int);
68 static void functions_info (char *, int);
70 static void variables_info (char *, int);
72 static void sources_info (char *, int);
74 static void output_source_filename (const char *, int *);
76 static int find_line_common (struct linetable
*, int, int *);
78 /* This one is used by linespec.c */
80 char *operator_chars (char *p
, char **end
);
82 static struct symbol
*lookup_symbol_aux (const char *name
,
83 const char *linkage_name
,
84 const struct block
*block
,
85 const domain_enum domain
,
86 enum language language
,
87 int *is_a_field_of_this
,
88 struct symtab
**symtab
);
91 struct symbol
*lookup_symbol_aux_local (const char *name
,
92 const char *linkage_name
,
93 const struct block
*block
,
94 const domain_enum domain
,
95 struct symtab
**symtab
);
98 struct symbol
*lookup_symbol_aux_symtabs (int block_index
,
100 const char *linkage_name
,
101 const domain_enum domain
,
102 struct symtab
**symtab
);
105 struct symbol
*lookup_symbol_aux_psymtabs (int block_index
,
107 const char *linkage_name
,
108 const domain_enum domain
,
109 struct symtab
**symtab
);
111 static void fixup_section (struct general_symbol_info
*, struct objfile
*);
113 static int file_matches (char *, char **, int);
115 static void print_symbol_info (domain_enum
,
116 struct symtab
*, struct symbol
*, int, char *);
118 static void print_msymbol_info (struct minimal_symbol
*);
120 static void symtab_symbol_info (char *, domain_enum
, int);
122 void _initialize_symtab (void);
126 /* The single non-language-specific builtin type */
127 struct type
*builtin_type_error
;
129 /* Block in which the most recently searched-for symbol was found.
130 Might be better to make this a parameter to lookup_symbol and
133 const struct block
*block_found
;
135 /* Check for a symtab of a specific name; first in symtabs, then in
136 psymtabs. *If* there is no '/' in the name, a match after a '/'
137 in the symtab filename will also work. */
140 lookup_symtab (const char *name
)
143 struct partial_symtab
*ps
;
144 struct objfile
*objfile
;
145 char *real_path
= NULL
;
146 char *full_path
= NULL
;
148 /* Here we are interested in canonicalizing an absolute path, not
149 absolutizing a relative path. */
150 if (IS_ABSOLUTE_PATH (name
))
152 full_path
= xfullpath (name
);
153 make_cleanup (xfree
, full_path
);
154 real_path
= gdb_realpath (name
);
155 make_cleanup (xfree
, real_path
);
160 /* First, search for an exact match */
162 ALL_SYMTABS (objfile
, s
)
164 if (FILENAME_CMP (name
, s
->filename
) == 0)
169 /* If the user gave us an absolute path, try to find the file in
170 this symtab and use its absolute path. */
172 if (full_path
!= NULL
)
174 const char *fp
= symtab_to_fullname (s
);
175 if (fp
!= NULL
&& FILENAME_CMP (full_path
, fp
) == 0)
181 if (real_path
!= NULL
)
183 char *fullname
= symtab_to_fullname (s
);
184 if (fullname
!= NULL
)
186 char *rp
= gdb_realpath (fullname
);
187 make_cleanup (xfree
, rp
);
188 if (FILENAME_CMP (real_path
, rp
) == 0)
196 /* Now, search for a matching tail (only if name doesn't have any dirs) */
198 if (lbasename (name
) == name
)
199 ALL_SYMTABS (objfile
, s
)
201 if (FILENAME_CMP (lbasename (s
->filename
), name
) == 0)
205 /* Same search rules as above apply here, but now we look thru the
208 ps
= lookup_partial_symtab (name
);
213 error (_("Internal: readin %s pst for `%s' found when no symtab found."),
216 s
= PSYMTAB_TO_SYMTAB (ps
);
221 /* At this point, we have located the psymtab for this file, but
222 the conversion to a symtab has failed. This usually happens
223 when we are looking up an include file. In this case,
224 PSYMTAB_TO_SYMTAB doesn't return a symtab, even though one has
225 been created. So, we need to run through the symtabs again in
226 order to find the file.
227 XXX - This is a crock, and should be fixed inside of the the
228 symbol parsing routines. */
232 /* Lookup the partial symbol table of a source file named NAME.
233 *If* there is no '/' in the name, a match after a '/'
234 in the psymtab filename will also work. */
236 struct partial_symtab
*
237 lookup_partial_symtab (const char *name
)
239 struct partial_symtab
*pst
;
240 struct objfile
*objfile
;
241 char *full_path
= NULL
;
242 char *real_path
= NULL
;
244 /* Here we are interested in canonicalizing an absolute path, not
245 absolutizing a relative path. */
246 if (IS_ABSOLUTE_PATH (name
))
248 full_path
= xfullpath (name
);
249 make_cleanup (xfree
, full_path
);
250 real_path
= gdb_realpath (name
);
251 make_cleanup (xfree
, real_path
);
254 ALL_PSYMTABS (objfile
, pst
)
256 if (FILENAME_CMP (name
, pst
->filename
) == 0)
261 /* If the user gave us an absolute path, try to find the file in
262 this symtab and use its absolute path. */
263 if (full_path
!= NULL
)
265 psymtab_to_fullname (pst
);
266 if (pst
->fullname
!= NULL
267 && FILENAME_CMP (full_path
, pst
->fullname
) == 0)
273 if (real_path
!= NULL
)
276 psymtab_to_fullname (pst
);
277 if (pst
->fullname
!= NULL
)
279 rp
= gdb_realpath (pst
->fullname
);
280 make_cleanup (xfree
, rp
);
282 if (rp
!= NULL
&& FILENAME_CMP (real_path
, rp
) == 0)
289 /* Now, search for a matching tail (only if name doesn't have any dirs) */
291 if (lbasename (name
) == name
)
292 ALL_PSYMTABS (objfile
, pst
)
294 if (FILENAME_CMP (lbasename (pst
->filename
), name
) == 0)
301 /* Mangle a GDB method stub type. This actually reassembles the pieces of the
302 full method name, which consist of the class name (from T), the unadorned
303 method name from METHOD_ID, and the signature for the specific overload,
304 specified by SIGNATURE_ID. Note that this function is g++ specific. */
307 gdb_mangle_name (struct type
*type
, int method_id
, int signature_id
)
309 int mangled_name_len
;
311 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, method_id
);
312 struct fn_field
*method
= &f
[signature_id
];
313 char *field_name
= TYPE_FN_FIELDLIST_NAME (type
, method_id
);
314 char *physname
= TYPE_FN_FIELD_PHYSNAME (f
, signature_id
);
315 char *newname
= type_name_no_tag (type
);
317 /* Does the form of physname indicate that it is the full mangled name
318 of a constructor (not just the args)? */
319 int is_full_physname_constructor
;
322 int is_destructor
= is_destructor_name (physname
);
323 /* Need a new type prefix. */
324 char *const_prefix
= method
->is_const
? "C" : "";
325 char *volatile_prefix
= method
->is_volatile
? "V" : "";
327 int len
= (newname
== NULL
? 0 : strlen (newname
));
329 /* Nothing to do if physname already contains a fully mangled v3 abi name
330 or an operator name. */
331 if ((physname
[0] == '_' && physname
[1] == 'Z')
332 || is_operator_name (field_name
))
333 return xstrdup (physname
);
335 is_full_physname_constructor
= is_constructor_name (physname
);
338 is_full_physname_constructor
|| (newname
&& strcmp (field_name
, newname
) == 0);
341 is_destructor
= (strncmp (physname
, "__dt", 4) == 0);
343 if (is_destructor
|| is_full_physname_constructor
)
345 mangled_name
= (char *) xmalloc (strlen (physname
) + 1);
346 strcpy (mangled_name
, physname
);
352 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
354 else if (physname
[0] == 't' || physname
[0] == 'Q')
356 /* The physname for template and qualified methods already includes
358 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
364 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
366 mangled_name_len
= ((is_constructor
? 0 : strlen (field_name
))
367 + strlen (buf
) + len
+ strlen (physname
) + 1);
370 mangled_name
= (char *) xmalloc (mangled_name_len
);
372 mangled_name
[0] = '\0';
374 strcpy (mangled_name
, field_name
);
376 strcat (mangled_name
, buf
);
377 /* If the class doesn't have a name, i.e. newname NULL, then we just
378 mangle it using 0 for the length of the class. Thus it gets mangled
379 as something starting with `::' rather than `classname::'. */
381 strcat (mangled_name
, newname
);
383 strcat (mangled_name
, physname
);
384 return (mangled_name
);
388 /* Initialize the language dependent portion of a symbol
389 depending upon the language for the symbol. */
391 symbol_init_language_specific (struct general_symbol_info
*gsymbol
,
392 enum language language
)
394 gsymbol
->language
= language
;
395 if (gsymbol
->language
== language_cplus
396 || gsymbol
->language
== language_java
397 || gsymbol
->language
== language_objc
)
399 gsymbol
->language_specific
.cplus_specific
.demangled_name
= NULL
;
403 memset (&gsymbol
->language_specific
, 0,
404 sizeof (gsymbol
->language_specific
));
408 /* Functions to initialize a symbol's mangled name. */
410 /* Create the hash table used for demangled names. Each hash entry is
411 a pair of strings; one for the mangled name and one for the demangled
412 name. The entry is hashed via just the mangled name. */
415 create_demangled_names_hash (struct objfile
*objfile
)
417 /* Choose 256 as the starting size of the hash table, somewhat arbitrarily.
418 The hash table code will round this up to the next prime number.
419 Choosing a much larger table size wastes memory, and saves only about
420 1% in symbol reading. */
422 objfile
->demangled_names_hash
= htab_create_alloc
423 (256, htab_hash_string
, (int (*) (const void *, const void *)) streq
,
424 NULL
, xcalloc
, xfree
);
427 /* Try to determine the demangled name for a symbol, based on the
428 language of that symbol. If the language is set to language_auto,
429 it will attempt to find any demangling algorithm that works and
430 then set the language appropriately. The returned name is allocated
431 by the demangler and should be xfree'd. */
434 symbol_find_demangled_name (struct general_symbol_info
*gsymbol
,
437 char *demangled
= NULL
;
439 if (gsymbol
->language
== language_unknown
)
440 gsymbol
->language
= language_auto
;
442 if (gsymbol
->language
== language_objc
443 || gsymbol
->language
== language_auto
)
446 objc_demangle (mangled
, 0);
447 if (demangled
!= NULL
)
449 gsymbol
->language
= language_objc
;
453 if (gsymbol
->language
== language_cplus
454 || gsymbol
->language
== language_auto
)
457 cplus_demangle (mangled
, DMGL_PARAMS
| DMGL_ANSI
);
458 if (demangled
!= NULL
)
460 gsymbol
->language
= language_cplus
;
464 if (gsymbol
->language
== language_java
)
467 cplus_demangle (mangled
,
468 DMGL_PARAMS
| DMGL_ANSI
| DMGL_JAVA
);
469 if (demangled
!= NULL
)
471 gsymbol
->language
= language_java
;
478 /* Set both the mangled and demangled (if any) names for GSYMBOL based
479 on LINKAGE_NAME and LEN. The hash table corresponding to OBJFILE
480 is used, and the memory comes from that objfile's objfile_obstack.
481 LINKAGE_NAME is copied, so the pointer can be discarded after
482 calling this function. */
484 /* We have to be careful when dealing with Java names: when we run
485 into a Java minimal symbol, we don't know it's a Java symbol, so it
486 gets demangled as a C++ name. This is unfortunate, but there's not
487 much we can do about it: but when demangling partial symbols and
488 regular symbols, we'd better not reuse the wrong demangled name.
489 (See PR gdb/1039.) We solve this by putting a distinctive prefix
490 on Java names when storing them in the hash table. */
492 /* FIXME: carlton/2003-03-13: This is an unfortunate situation. I
493 don't mind the Java prefix so much: different languages have
494 different demangling requirements, so it's only natural that we
495 need to keep language data around in our demangling cache. But
496 it's not good that the minimal symbol has the wrong demangled name.
497 Unfortunately, I can't think of any easy solution to that
500 #define JAVA_PREFIX "##JAVA$$"
501 #define JAVA_PREFIX_LEN 8
504 symbol_set_names (struct general_symbol_info
*gsymbol
,
505 const char *linkage_name
, int len
, struct objfile
*objfile
)
508 /* A 0-terminated copy of the linkage name. */
509 const char *linkage_name_copy
;
510 /* A copy of the linkage name that might have a special Java prefix
511 added to it, for use when looking names up in the hash table. */
512 const char *lookup_name
;
513 /* The length of lookup_name. */
516 if (objfile
->demangled_names_hash
== NULL
)
517 create_demangled_names_hash (objfile
);
519 /* The stabs reader generally provides names that are not
520 NUL-terminated; most of the other readers don't do this, so we
521 can just use the given copy, unless we're in the Java case. */
522 if (gsymbol
->language
== language_java
)
525 lookup_len
= len
+ JAVA_PREFIX_LEN
;
527 alloc_name
= alloca (lookup_len
+ 1);
528 memcpy (alloc_name
, JAVA_PREFIX
, JAVA_PREFIX_LEN
);
529 memcpy (alloc_name
+ JAVA_PREFIX_LEN
, linkage_name
, len
);
530 alloc_name
[lookup_len
] = '\0';
532 lookup_name
= alloc_name
;
533 linkage_name_copy
= alloc_name
+ JAVA_PREFIX_LEN
;
535 else if (linkage_name
[len
] != '\0')
540 alloc_name
= alloca (lookup_len
+ 1);
541 memcpy (alloc_name
, linkage_name
, len
);
542 alloc_name
[lookup_len
] = '\0';
544 lookup_name
= alloc_name
;
545 linkage_name_copy
= alloc_name
;
550 lookup_name
= linkage_name
;
551 linkage_name_copy
= linkage_name
;
554 slot
= (char **) htab_find_slot (objfile
->demangled_names_hash
,
555 lookup_name
, INSERT
);
557 /* If this name is not in the hash table, add it. */
560 char *demangled_name
= symbol_find_demangled_name (gsymbol
,
562 int demangled_len
= demangled_name
? strlen (demangled_name
) : 0;
564 /* If there is a demangled name, place it right after the mangled name.
565 Otherwise, just place a second zero byte after the end of the mangled
567 *slot
= obstack_alloc (&objfile
->objfile_obstack
,
568 lookup_len
+ demangled_len
+ 2);
569 memcpy (*slot
, lookup_name
, lookup_len
+ 1);
570 if (demangled_name
!= NULL
)
572 memcpy (*slot
+ lookup_len
+ 1, demangled_name
, demangled_len
+ 1);
573 xfree (demangled_name
);
576 (*slot
)[lookup_len
+ 1] = '\0';
579 gsymbol
->name
= *slot
+ lookup_len
- len
;
580 if ((*slot
)[lookup_len
+ 1] != '\0')
581 gsymbol
->language_specific
.cplus_specific
.demangled_name
582 = &(*slot
)[lookup_len
+ 1];
584 gsymbol
->language_specific
.cplus_specific
.demangled_name
= NULL
;
587 /* Initialize the demangled name of GSYMBOL if possible. Any required space
588 to store the name is obtained from the specified obstack. The function
589 symbol_set_names, above, should be used instead where possible for more
590 efficient memory usage. */
593 symbol_init_demangled_name (struct general_symbol_info
*gsymbol
,
594 struct obstack
*obstack
)
596 char *mangled
= gsymbol
->name
;
597 char *demangled
= NULL
;
599 demangled
= symbol_find_demangled_name (gsymbol
, mangled
);
600 if (gsymbol
->language
== language_cplus
601 || gsymbol
->language
== language_java
602 || gsymbol
->language
== language_objc
)
606 gsymbol
->language_specific
.cplus_specific
.demangled_name
607 = obsavestring (demangled
, strlen (demangled
), obstack
);
611 gsymbol
->language_specific
.cplus_specific
.demangled_name
= NULL
;
615 /* Unknown language; just clean up quietly. */
621 /* Return the source code name of a symbol. In languages where
622 demangling is necessary, this is the demangled name. */
625 symbol_natural_name (const struct general_symbol_info
*gsymbol
)
627 switch (gsymbol
->language
)
632 if (gsymbol
->language_specific
.cplus_specific
.demangled_name
!= NULL
)
633 return gsymbol
->language_specific
.cplus_specific
.demangled_name
;
636 if (gsymbol
->language_specific
.cplus_specific
.demangled_name
!= NULL
)
637 return gsymbol
->language_specific
.cplus_specific
.demangled_name
;
639 return ada_decode_symbol (gsymbol
);
644 return gsymbol
->name
;
647 /* Return the demangled name for a symbol based on the language for
648 that symbol. If no demangled name exists, return NULL. */
650 symbol_demangled_name (struct general_symbol_info
*gsymbol
)
652 switch (gsymbol
->language
)
657 if (gsymbol
->language_specific
.cplus_specific
.demangled_name
!= NULL
)
658 return gsymbol
->language_specific
.cplus_specific
.demangled_name
;
661 if (gsymbol
->language_specific
.cplus_specific
.demangled_name
!= NULL
)
662 return gsymbol
->language_specific
.cplus_specific
.demangled_name
;
664 return ada_decode_symbol (gsymbol
);
672 /* Return the search name of a symbol---generally the demangled or
673 linkage name of the symbol, depending on how it will be searched for.
674 If there is no distinct demangled name, then returns the same value
675 (same pointer) as SYMBOL_LINKAGE_NAME. */
677 symbol_search_name (const struct general_symbol_info
*gsymbol
)
679 if (gsymbol
->language
== language_ada
)
680 return gsymbol
->name
;
682 return symbol_natural_name (gsymbol
);
685 /* Initialize the structure fields to zero values. */
687 init_sal (struct symtab_and_line
*sal
)
694 sal
->explicit_pc
= 0;
695 sal
->explicit_line
= 0;
699 /* Return 1 if the two sections are the same, or if they could
700 plausibly be copies of each other, one in an original object
701 file and another in a separated debug file. */
704 matching_bfd_sections (asection
*first
, asection
*second
)
708 /* If they're the same section, then they match. */
712 /* If either is NULL, give up. */
713 if (first
== NULL
|| second
== NULL
)
716 /* This doesn't apply to absolute symbols. */
717 if (first
->owner
== NULL
|| second
->owner
== NULL
)
720 /* If they're in the same object file, they must be different sections. */
721 if (first
->owner
== second
->owner
)
724 /* Check whether the two sections are potentially corresponding. They must
725 have the same size, address, and name. We can't compare section indexes,
726 which would be more reliable, because some sections may have been
728 if (bfd_get_section_size (first
) != bfd_get_section_size (second
))
731 /* In-memory addresses may start at a different offset, relativize them. */
732 if (bfd_get_section_vma (first
->owner
, first
)
733 - bfd_get_start_address (first
->owner
)
734 != bfd_get_section_vma (second
->owner
, second
)
735 - bfd_get_start_address (second
->owner
))
738 if (bfd_get_section_name (first
->owner
, first
) == NULL
739 || bfd_get_section_name (second
->owner
, second
) == NULL
740 || strcmp (bfd_get_section_name (first
->owner
, first
),
741 bfd_get_section_name (second
->owner
, second
)) != 0)
744 /* Otherwise check that they are in corresponding objfiles. */
747 if (obj
->obfd
== first
->owner
)
749 gdb_assert (obj
!= NULL
);
751 if (obj
->separate_debug_objfile
!= NULL
752 && obj
->separate_debug_objfile
->obfd
== second
->owner
)
754 if (obj
->separate_debug_objfile_backlink
!= NULL
755 && obj
->separate_debug_objfile_backlink
->obfd
== second
->owner
)
761 /* Find which partial symtab contains PC and SECTION. Return 0 if
762 none. We return the psymtab that contains a symbol whose address
763 exactly matches PC, or, if we cannot find an exact match, the
764 psymtab that contains a symbol whose address is closest to PC. */
765 struct partial_symtab
*
766 find_pc_sect_psymtab (CORE_ADDR pc
, asection
*section
)
768 struct partial_symtab
*pst
;
769 struct objfile
*objfile
;
770 struct minimal_symbol
*msymbol
;
772 /* If we know that this is not a text address, return failure. This is
773 necessary because we loop based on texthigh and textlow, which do
774 not include the data ranges. */
775 msymbol
= lookup_minimal_symbol_by_pc_section (pc
, section
);
777 && (msymbol
->type
== mst_data
778 || msymbol
->type
== mst_bss
779 || msymbol
->type
== mst_abs
780 || msymbol
->type
== mst_file_data
781 || msymbol
->type
== mst_file_bss
))
784 ALL_PSYMTABS (objfile
, pst
)
786 if (pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
788 struct partial_symtab
*tpst
;
789 struct partial_symtab
*best_pst
= pst
;
790 CORE_ADDR best_addr
= pst
->textlow
;
792 /* An objfile that has its functions reordered might have
793 many partial symbol tables containing the PC, but
794 we want the partial symbol table that contains the
795 function containing the PC. */
796 if (!(objfile
->flags
& OBJF_REORDERED
) &&
797 section
== 0) /* can't validate section this way */
803 /* The code range of partial symtabs sometimes overlap, so, in
804 the loop below, we need to check all partial symtabs and
805 find the one that fits better for the given PC address. We
806 select the partial symtab that contains a symbol whose
807 address is closest to the PC address. By closest we mean
808 that find_pc_sect_symbol returns the symbol with address
809 that is closest and still less than the given PC. */
810 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
812 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
814 struct partial_symbol
*p
;
817 /* NOTE: This assumes that every psymbol has a
818 corresponding msymbol, which is not necessarily
819 true; the debug info might be much richer than the
820 object's symbol table. */
821 p
= find_pc_sect_psymbol (tpst
, pc
, section
);
823 && SYMBOL_VALUE_ADDRESS (p
)
824 == SYMBOL_VALUE_ADDRESS (msymbol
))
827 /* Also accept the textlow value of a psymtab as a
828 "symbol", to provide some support for partial
829 symbol tables with line information but no debug
830 symbols (e.g. those produced by an assembler). */
832 this_addr
= SYMBOL_VALUE_ADDRESS (p
);
834 this_addr
= tpst
->textlow
;
836 /* Check whether it is closer than our current
837 BEST_ADDR. Since this symbol address is
838 necessarily lower or equal to PC, the symbol closer
839 to PC is the symbol which address is the highest.
840 This way we return the psymtab which contains such
841 best match symbol. This can help in cases where the
842 symbol information/debuginfo is not complete, like
843 for instance on IRIX6 with gcc, where no debug info
844 is emitted for statics. (See also the nodebug.exp
846 if (this_addr
> best_addr
)
848 best_addr
= this_addr
;
859 /* Find which partial symtab contains PC. Return 0 if none.
860 Backward compatibility, no section */
862 struct partial_symtab
*
863 find_pc_psymtab (CORE_ADDR pc
)
865 return find_pc_sect_psymtab (pc
, find_pc_mapped_section (pc
));
868 /* Find which partial symbol within a psymtab matches PC and SECTION.
869 Return 0 if none. Check all psymtabs if PSYMTAB is 0. */
871 struct partial_symbol
*
872 find_pc_sect_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
,
875 struct partial_symbol
*best
= NULL
, *p
, **pp
;
879 psymtab
= find_pc_sect_psymtab (pc
, section
);
883 /* Cope with programs that start at address 0 */
884 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
886 /* Search the global symbols as well as the static symbols, so that
887 find_pc_partial_function doesn't use a minimal symbol and thus
888 cache a bad endaddr. */
889 for (pp
= psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
890 (pp
- (psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
891 < psymtab
->n_global_syms
);
895 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
896 && SYMBOL_CLASS (p
) == LOC_BLOCK
897 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
898 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
899 || (psymtab
->textlow
== 0
900 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
902 if (section
) /* match on a specific section */
904 fixup_psymbol_section (p
, psymtab
->objfile
);
905 if (!matching_bfd_sections (SYMBOL_BFD_SECTION (p
), section
))
908 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
913 for (pp
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
914 (pp
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
915 < psymtab
->n_static_syms
);
919 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
920 && SYMBOL_CLASS (p
) == LOC_BLOCK
921 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
922 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
923 || (psymtab
->textlow
== 0
924 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
926 if (section
) /* match on a specific section */
928 fixup_psymbol_section (p
, psymtab
->objfile
);
929 if (!matching_bfd_sections (SYMBOL_BFD_SECTION (p
), section
))
932 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
940 /* Find which partial symbol within a psymtab matches PC. Return 0 if none.
941 Check all psymtabs if PSYMTAB is 0. Backwards compatibility, no section. */
943 struct partial_symbol
*
944 find_pc_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
)
946 return find_pc_sect_psymbol (psymtab
, pc
, find_pc_mapped_section (pc
));
949 /* Debug symbols usually don't have section information. We need to dig that
950 out of the minimal symbols and stash that in the debug symbol. */
953 fixup_section (struct general_symbol_info
*ginfo
, struct objfile
*objfile
)
955 struct minimal_symbol
*msym
;
956 msym
= lookup_minimal_symbol (ginfo
->name
, NULL
, objfile
);
960 ginfo
->bfd_section
= SYMBOL_BFD_SECTION (msym
);
961 ginfo
->section
= SYMBOL_SECTION (msym
);
965 /* Static, function-local variables do appear in the linker
966 (minimal) symbols, but are frequently given names that won't
967 be found via lookup_minimal_symbol(). E.g., it has been
968 observed in frv-uclinux (ELF) executables that a static,
969 function-local variable named "foo" might appear in the
970 linker symbols as "foo.6" or "foo.3". Thus, there is no
971 point in attempting to extend the lookup-by-name mechanism to
972 handle this case due to the fact that there can be multiple
975 So, instead, search the section table when lookup by name has
976 failed. The ``addr'' and ``endaddr'' fields may have already
977 been relocated. If so, the relocation offset (i.e. the
978 ANOFFSET value) needs to be subtracted from these values when
979 performing the comparison. We unconditionally subtract it,
980 because, when no relocation has been performed, the ANOFFSET
981 value will simply be zero.
983 The address of the symbol whose section we're fixing up HAS
984 NOT BEEN adjusted (relocated) yet. It can't have been since
985 the section isn't yet known and knowing the section is
986 necessary in order to add the correct relocation value. In
987 other words, we wouldn't even be in this function (attempting
988 to compute the section) if it were already known.
990 Note that it is possible to search the minimal symbols
991 (subtracting the relocation value if necessary) to find the
992 matching minimal symbol, but this is overkill and much less
993 efficient. It is not necessary to find the matching minimal
994 symbol, only its section.
996 Note that this technique (of doing a section table search)
997 can fail when unrelocated section addresses overlap. For
998 this reason, we still attempt a lookup by name prior to doing
999 a search of the section table. */
1002 struct obj_section
*s
;
1004 addr
= ginfo
->value
.address
;
1006 ALL_OBJFILE_OSECTIONS (objfile
, s
)
1008 int idx
= s
->the_bfd_section
->index
;
1009 CORE_ADDR offset
= ANOFFSET (objfile
->section_offsets
, idx
);
1011 if (s
->addr
- offset
<= addr
&& addr
< s
->endaddr
- offset
)
1013 ginfo
->bfd_section
= s
->the_bfd_section
;
1014 ginfo
->section
= idx
;
1022 fixup_symbol_section (struct symbol
*sym
, struct objfile
*objfile
)
1027 if (SYMBOL_BFD_SECTION (sym
))
1030 fixup_section (&sym
->ginfo
, objfile
);
1035 struct partial_symbol
*
1036 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
1041 if (SYMBOL_BFD_SECTION (psym
))
1044 fixup_section (&psym
->ginfo
, objfile
);
1049 /* Find the definition for a specified symbol name NAME
1050 in domain DOMAIN, visible from lexical block BLOCK.
1051 Returns the struct symbol pointer, or zero if no symbol is found.
1052 If SYMTAB is non-NULL, store the symbol table in which the
1053 symbol was found there, or NULL if not found.
1054 C++: if IS_A_FIELD_OF_THIS is nonzero on entry, check to see if
1055 NAME is a field of the current implied argument `this'. If so set
1056 *IS_A_FIELD_OF_THIS to 1, otherwise set it to zero.
1057 BLOCK_FOUND is set to the block in which NAME is found (in the case of
1058 a field of `this', value_of_this sets BLOCK_FOUND to the proper value.) */
1060 /* This function has a bunch of loops in it and it would seem to be
1061 attractive to put in some QUIT's (though I'm not really sure
1062 whether it can run long enough to be really important). But there
1063 are a few calls for which it would appear to be bad news to quit
1064 out of here: find_proc_desc in alpha-tdep.c and mips-tdep.c. (Note
1065 that there is C++ code below which can error(), but that probably
1066 doesn't affect these calls since they are looking for a known
1067 variable and thus can probably assume it will never hit the C++
1071 lookup_symbol_in_language (const char *name
, const struct block
*block
,
1072 const domain_enum domain
, enum language lang
,
1073 int *is_a_field_of_this
,
1074 struct symtab
**symtab
)
1076 char *demangled_name
= NULL
;
1077 const char *modified_name
= NULL
;
1078 const char *mangled_name
= NULL
;
1079 int needtofreename
= 0;
1080 struct symbol
*returnval
;
1082 modified_name
= name
;
1084 /* If we are using C++ or Java, demangle the name before doing a lookup, so
1085 we can always binary search. */
1086 if (lang
== language_cplus
)
1088 demangled_name
= cplus_demangle (name
, DMGL_ANSI
| DMGL_PARAMS
);
1091 mangled_name
= name
;
1092 modified_name
= demangled_name
;
1096 else if (lang
== language_java
)
1098 demangled_name
= cplus_demangle (name
,
1099 DMGL_ANSI
| DMGL_PARAMS
| DMGL_JAVA
);
1102 mangled_name
= name
;
1103 modified_name
= demangled_name
;
1108 if (case_sensitivity
== case_sensitive_off
)
1113 len
= strlen (name
);
1114 copy
= (char *) alloca (len
+ 1);
1115 for (i
= 0; i
< len
; i
++)
1116 copy
[i
] = tolower (name
[i
]);
1118 modified_name
= copy
;
1121 returnval
= lookup_symbol_aux (modified_name
, mangled_name
, block
,
1123 is_a_field_of_this
, symtab
);
1125 xfree (demangled_name
);
1127 /* Override the returned symtab with the symbol's specific one. */
1128 if (returnval
!= NULL
&& symtab
!= NULL
)
1129 *symtab
= SYMBOL_SYMTAB (returnval
);
1134 /* Behave like lookup_symbol_in_language, but performed with the
1135 current language. */
1138 lookup_symbol (const char *name
, const struct block
*block
,
1139 domain_enum domain
, int *is_a_field_of_this
,
1140 struct symtab
**symtab
)
1142 return lookup_symbol_in_language (name
, block
, domain
,
1143 current_language
->la_language
,
1144 is_a_field_of_this
, symtab
);
1147 /* Behave like lookup_symbol except that NAME is the natural name
1148 of the symbol that we're looking for and, if LINKAGE_NAME is
1149 non-NULL, ensure that the symbol's linkage name matches as
1152 static struct symbol
*
1153 lookup_symbol_aux (const char *name
, const char *linkage_name
,
1154 const struct block
*block
, const domain_enum domain
,
1155 enum language language
,
1156 int *is_a_field_of_this
, struct symtab
**symtab
)
1159 const struct language_defn
*langdef
;
1161 /* Make sure we do something sensible with is_a_field_of_this, since
1162 the callers that set this parameter to some non-null value will
1163 certainly use it later and expect it to be either 0 or 1.
1164 If we don't set it, the contents of is_a_field_of_this are
1166 if (is_a_field_of_this
!= NULL
)
1167 *is_a_field_of_this
= 0;
1169 /* Search specified block and its superiors. Don't search
1170 STATIC_BLOCK or GLOBAL_BLOCK. */
1172 sym
= lookup_symbol_aux_local (name
, linkage_name
, block
, domain
,
1177 /* If requested to do so by the caller and if appropriate for LANGUAGE,
1178 check to see if NAME is a field of `this'. */
1180 langdef
= language_def (language
);
1182 if (langdef
->la_value_of_this
!= NULL
1183 && is_a_field_of_this
!= NULL
)
1185 struct value
*v
= langdef
->la_value_of_this (0);
1187 if (v
&& check_field (v
, name
))
1189 *is_a_field_of_this
= 1;
1196 /* Now do whatever is appropriate for LANGUAGE to look
1197 up static and global variables. */
1199 sym
= langdef
->la_lookup_symbol_nonlocal (name
, linkage_name
,
1200 block
, domain
, symtab
);
1204 /* Now search all static file-level symbols. Not strictly correct,
1205 but more useful than an error. Do the symtabs first, then check
1206 the psymtabs. If a psymtab indicates the existence of the
1207 desired name as a file-level static, then do psymtab-to-symtab
1208 conversion on the fly and return the found symbol. */
1210 sym
= lookup_symbol_aux_symtabs (STATIC_BLOCK
, name
, linkage_name
,
1215 sym
= lookup_symbol_aux_psymtabs (STATIC_BLOCK
, name
, linkage_name
,
1225 /* Check to see if the symbol is defined in BLOCK or its superiors.
1226 Don't search STATIC_BLOCK or GLOBAL_BLOCK. */
1228 static struct symbol
*
1229 lookup_symbol_aux_local (const char *name
, const char *linkage_name
,
1230 const struct block
*block
,
1231 const domain_enum domain
,
1232 struct symtab
**symtab
)
1235 const struct block
*static_block
= block_static_block (block
);
1237 /* Check if either no block is specified or it's a global block. */
1239 if (static_block
== NULL
)
1242 while (block
!= static_block
)
1244 sym
= lookup_symbol_aux_block (name
, linkage_name
, block
, domain
,
1248 block
= BLOCK_SUPERBLOCK (block
);
1251 /* We've reached the static block without finding a result. */
1256 /* Look up OBJFILE to BLOCK. */
1258 static struct objfile
*
1259 lookup_objfile_from_block (const struct block
*block
)
1261 struct objfile
*obj
;
1267 block
= block_global_block (block
);
1268 /* Go through SYMTABS. */
1269 ALL_SYMTABS (obj
, s
)
1270 if (block
== BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
))
1276 /* Look up a symbol in a block; if found, locate its symtab, fixup the
1277 symbol, and set block_found appropriately. */
1280 lookup_symbol_aux_block (const char *name
, const char *linkage_name
,
1281 const struct block
*block
,
1282 const domain_enum domain
,
1283 struct symtab
**symtab
)
1286 struct objfile
*objfile
= NULL
;
1287 struct blockvector
*bv
;
1289 struct symtab
*s
= NULL
;
1291 sym
= lookup_block_symbol (block
, name
, linkage_name
, domain
);
1294 block_found
= block
;
1297 /* Search the list of symtabs for one which contains the
1298 address of the start of this block. */
1299 ALL_PRIMARY_SYMTABS (objfile
, s
)
1301 bv
= BLOCKVECTOR (s
);
1302 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1303 if (BLOCK_START (b
) <= BLOCK_START (block
)
1304 && BLOCK_END (b
) > BLOCK_START (block
))
1311 return fixup_symbol_section (sym
, objfile
);
1317 /* Check all global symbols in OBJFILE in symtabs and
1321 lookup_global_symbol_from_objfile (const struct objfile
*objfile
,
1323 const char *linkage_name
,
1324 const domain_enum domain
,
1325 struct symtab
**symtab
)
1328 struct blockvector
*bv
;
1329 const struct block
*block
;
1331 struct partial_symtab
*ps
;
1333 /* Go through symtabs. */
1334 ALL_OBJFILE_SYMTABS (objfile
, s
)
1336 bv
= BLOCKVECTOR (s
);
1337 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1338 sym
= lookup_block_symbol (block
, name
, linkage_name
, domain
);
1341 block_found
= block
;
1344 return fixup_symbol_section (sym
, (struct objfile
*)objfile
);
1348 /* Now go through psymtabs. */
1349 ALL_OBJFILE_PSYMTABS (objfile
, ps
)
1352 && lookup_partial_symbol (ps
, name
, linkage_name
,
1355 s
= PSYMTAB_TO_SYMTAB (ps
);
1356 bv
= BLOCKVECTOR (s
);
1357 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1358 sym
= lookup_block_symbol (block
, name
, linkage_name
, domain
);
1361 return fixup_symbol_section (sym
, (struct objfile
*)objfile
);
1368 /* Check to see if the symbol is defined in one of the symtabs.
1369 BLOCK_INDEX should be either GLOBAL_BLOCK or STATIC_BLOCK,
1370 depending on whether or not we want to search global symbols or
1373 static struct symbol
*
1374 lookup_symbol_aux_symtabs (int block_index
,
1375 const char *name
, const char *linkage_name
,
1376 const domain_enum domain
,
1377 struct symtab
**symtab
)
1380 struct objfile
*objfile
;
1381 struct blockvector
*bv
;
1382 const struct block
*block
;
1385 ALL_PRIMARY_SYMTABS (objfile
, s
)
1387 bv
= BLOCKVECTOR (s
);
1388 block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
1389 sym
= lookup_block_symbol (block
, name
, linkage_name
, domain
);
1392 block_found
= block
;
1395 return fixup_symbol_section (sym
, objfile
);
1402 /* Check to see if the symbol is defined in one of the partial
1403 symtabs. BLOCK_INDEX should be either GLOBAL_BLOCK or
1404 STATIC_BLOCK, depending on whether or not we want to search global
1405 symbols or static symbols. */
1407 static struct symbol
*
1408 lookup_symbol_aux_psymtabs (int block_index
, const char *name
,
1409 const char *linkage_name
,
1410 const domain_enum domain
,
1411 struct symtab
**symtab
)
1414 struct objfile
*objfile
;
1415 struct blockvector
*bv
;
1416 const struct block
*block
;
1417 struct partial_symtab
*ps
;
1419 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
1421 ALL_PSYMTABS (objfile
, ps
)
1424 && lookup_partial_symbol (ps
, name
, linkage_name
,
1425 psymtab_index
, domain
))
1427 s
= PSYMTAB_TO_SYMTAB (ps
);
1428 bv
= BLOCKVECTOR (s
);
1429 block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
1430 sym
= lookup_block_symbol (block
, name
, linkage_name
, domain
);
1433 /* This shouldn't be necessary, but as a last resort try
1434 looking in the statics even though the psymtab claimed
1435 the symbol was global, or vice-versa. It's possible
1436 that the psymtab gets it wrong in some cases. */
1438 /* FIXME: carlton/2002-09-30: Should we really do that?
1439 If that happens, isn't it likely to be a GDB error, in
1440 which case we should fix the GDB error rather than
1441 silently dealing with it here? So I'd vote for
1442 removing the check for the symbol in the other
1444 block
= BLOCKVECTOR_BLOCK (bv
,
1445 block_index
== GLOBAL_BLOCK
?
1446 STATIC_BLOCK
: GLOBAL_BLOCK
);
1447 sym
= lookup_block_symbol (block
, name
, linkage_name
, domain
);
1449 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>)."),
1450 block_index
== GLOBAL_BLOCK
? "global" : "static",
1451 name
, ps
->filename
, name
, name
);
1455 return fixup_symbol_section (sym
, objfile
);
1462 /* A default version of lookup_symbol_nonlocal for use by languages
1463 that can't think of anything better to do. This implements the C
1467 basic_lookup_symbol_nonlocal (const char *name
,
1468 const char *linkage_name
,
1469 const struct block
*block
,
1470 const domain_enum domain
,
1471 struct symtab
**symtab
)
1475 /* NOTE: carlton/2003-05-19: The comments below were written when
1476 this (or what turned into this) was part of lookup_symbol_aux;
1477 I'm much less worried about these questions now, since these
1478 decisions have turned out well, but I leave these comments here
1481 /* NOTE: carlton/2002-12-05: There is a question as to whether or
1482 not it would be appropriate to search the current global block
1483 here as well. (That's what this code used to do before the
1484 is_a_field_of_this check was moved up.) On the one hand, it's
1485 redundant with the lookup_symbol_aux_symtabs search that happens
1486 next. On the other hand, if decode_line_1 is passed an argument
1487 like filename:var, then the user presumably wants 'var' to be
1488 searched for in filename. On the third hand, there shouldn't be
1489 multiple global variables all of which are named 'var', and it's
1490 not like decode_line_1 has ever restricted its search to only
1491 global variables in a single filename. All in all, only
1492 searching the static block here seems best: it's correct and it's
1495 /* NOTE: carlton/2002-12-05: There's also a possible performance
1496 issue here: if you usually search for global symbols in the
1497 current file, then it would be slightly better to search the
1498 current global block before searching all the symtabs. But there
1499 are other factors that have a much greater effect on performance
1500 than that one, so I don't think we should worry about that for
1503 sym
= lookup_symbol_static (name
, linkage_name
, block
, domain
, symtab
);
1507 return lookup_symbol_global (name
, linkage_name
, block
, domain
, symtab
);
1510 /* Lookup a symbol in the static block associated to BLOCK, if there
1511 is one; do nothing if BLOCK is NULL or a global block. */
1514 lookup_symbol_static (const char *name
,
1515 const char *linkage_name
,
1516 const struct block
*block
,
1517 const domain_enum domain
,
1518 struct symtab
**symtab
)
1520 const struct block
*static_block
= block_static_block (block
);
1522 if (static_block
!= NULL
)
1523 return lookup_symbol_aux_block (name
, linkage_name
, static_block
,
1529 /* Lookup a symbol in all files' global blocks (searching psymtabs if
1533 lookup_symbol_global (const char *name
,
1534 const char *linkage_name
,
1535 const struct block
*block
,
1536 const domain_enum domain
,
1537 struct symtab
**symtab
)
1539 struct symbol
*sym
= NULL
;
1540 struct objfile
*objfile
= NULL
;
1542 /* Call library-specific lookup procedure. */
1543 objfile
= lookup_objfile_from_block (block
);
1544 if (objfile
!= NULL
)
1545 sym
= solib_global_lookup (objfile
, name
, linkage_name
, domain
, symtab
);
1549 sym
= lookup_symbol_aux_symtabs (GLOBAL_BLOCK
, name
, linkage_name
,
1554 return lookup_symbol_aux_psymtabs (GLOBAL_BLOCK
, name
, linkage_name
,
1558 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
1559 If LINKAGE_NAME is non-NULL, check in addition that the symbol's
1560 linkage name matches it. Check the global symbols if GLOBAL, the
1561 static symbols if not */
1563 struct partial_symbol
*
1564 lookup_partial_symbol (struct partial_symtab
*pst
, const char *name
,
1565 const char *linkage_name
, int global
,
1568 struct partial_symbol
*temp
;
1569 struct partial_symbol
**start
, **psym
;
1570 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
1571 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
1572 int do_linear_search
= 1;
1579 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
1580 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1582 if (global
) /* This means we can use a binary search. */
1584 do_linear_search
= 0;
1586 /* Binary search. This search is guaranteed to end with center
1587 pointing at the earliest partial symbol whose name might be
1588 correct. At that point *all* partial symbols with an
1589 appropriate name will be checked against the correct
1593 top
= start
+ length
- 1;
1595 while (top
> bottom
)
1597 center
= bottom
+ (top
- bottom
) / 2;
1598 if (!(center
< top
))
1599 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
1600 if (!do_linear_search
1601 && (SYMBOL_LANGUAGE (*center
) == language_java
))
1603 do_linear_search
= 1;
1605 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center
), name
) >= 0)
1611 bottom
= center
+ 1;
1614 if (!(top
== bottom
))
1615 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
1617 while (top
<= real_top
1618 && (linkage_name
!= NULL
1619 ? strcmp (SYMBOL_LINKAGE_NAME (*top
), linkage_name
) == 0
1620 : SYMBOL_MATCHES_SEARCH_NAME (*top
,name
)))
1622 if (SYMBOL_DOMAIN (*top
) == domain
)
1630 /* Can't use a binary search or else we found during the binary search that
1631 we should also do a linear search. */
1633 if (do_linear_search
)
1635 for (psym
= start
; psym
< start
+ length
; psym
++)
1637 if (domain
== SYMBOL_DOMAIN (*psym
))
1639 if (linkage_name
!= NULL
1640 ? strcmp (SYMBOL_LINKAGE_NAME (*psym
), linkage_name
) == 0
1641 : SYMBOL_MATCHES_SEARCH_NAME (*psym
, name
))
1652 /* Look up a type named NAME in the struct_domain. The type returned
1653 must not be opaque -- i.e., must have at least one field
1657 lookup_transparent_type (const char *name
)
1659 return current_language
->la_lookup_transparent_type (name
);
1662 /* The standard implementation of lookup_transparent_type. This code
1663 was modeled on lookup_symbol -- the parts not relevant to looking
1664 up types were just left out. In particular it's assumed here that
1665 types are available in struct_domain and only at file-static or
1669 basic_lookup_transparent_type (const char *name
)
1672 struct symtab
*s
= NULL
;
1673 struct partial_symtab
*ps
;
1674 struct blockvector
*bv
;
1675 struct objfile
*objfile
;
1676 struct block
*block
;
1678 /* Now search all the global symbols. Do the symtab's first, then
1679 check the psymtab's. If a psymtab indicates the existence
1680 of the desired name as a global, then do psymtab-to-symtab
1681 conversion on the fly and return the found symbol. */
1683 ALL_PRIMARY_SYMTABS (objfile
, s
)
1685 bv
= BLOCKVECTOR (s
);
1686 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1687 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1688 if (sym
&& !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1690 return SYMBOL_TYPE (sym
);
1694 ALL_PSYMTABS (objfile
, ps
)
1696 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, NULL
,
1699 s
= PSYMTAB_TO_SYMTAB (ps
);
1700 bv
= BLOCKVECTOR (s
);
1701 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1702 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1705 /* This shouldn't be necessary, but as a last resort
1706 * try looking in the statics even though the psymtab
1707 * claimed the symbol was global. It's possible that
1708 * the psymtab gets it wrong in some cases.
1710 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1711 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1713 error (_("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
1714 %s may be an inlined function, or may be a template function\n\
1715 (if a template, try specifying an instantiation: %s<type>)."),
1716 name
, ps
->filename
, name
, name
);
1718 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1719 return SYMBOL_TYPE (sym
);
1723 /* Now search the static file-level symbols.
1724 Not strictly correct, but more useful than an error.
1725 Do the symtab's first, then
1726 check the psymtab's. If a psymtab indicates the existence
1727 of the desired name as a file-level static, then do psymtab-to-symtab
1728 conversion on the fly and return the found symbol.
1731 ALL_PRIMARY_SYMTABS (objfile
, s
)
1733 bv
= BLOCKVECTOR (s
);
1734 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1735 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1736 if (sym
&& !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1738 return SYMBOL_TYPE (sym
);
1742 ALL_PSYMTABS (objfile
, ps
)
1744 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, NULL
, 0, STRUCT_DOMAIN
))
1746 s
= PSYMTAB_TO_SYMTAB (ps
);
1747 bv
= BLOCKVECTOR (s
);
1748 block
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1749 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1752 /* This shouldn't be necessary, but as a last resort
1753 * try looking in the globals even though the psymtab
1754 * claimed the symbol was static. It's possible that
1755 * the psymtab gets it wrong in some cases.
1757 block
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1758 sym
= lookup_block_symbol (block
, name
, NULL
, STRUCT_DOMAIN
);
1760 error (_("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
1761 %s may be an inlined function, or may be a template function\n\
1762 (if a template, try specifying an instantiation: %s<type>)."),
1763 name
, ps
->filename
, name
, name
);
1765 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
1766 return SYMBOL_TYPE (sym
);
1769 return (struct type
*) 0;
1773 /* Find the psymtab containing main(). */
1774 /* FIXME: What about languages without main() or specially linked
1775 executables that have no main() ? */
1777 struct partial_symtab
*
1778 find_main_psymtab (void)
1780 struct partial_symtab
*pst
;
1781 struct objfile
*objfile
;
1783 ALL_PSYMTABS (objfile
, pst
)
1785 if (lookup_partial_symbol (pst
, main_name (), NULL
, 1, VAR_DOMAIN
))
1793 /* Search BLOCK for symbol NAME in DOMAIN.
1795 Note that if NAME is the demangled form of a C++ symbol, we will fail
1796 to find a match during the binary search of the non-encoded names, but
1797 for now we don't worry about the slight inefficiency of looking for
1798 a match we'll never find, since it will go pretty quick. Once the
1799 binary search terminates, we drop through and do a straight linear
1800 search on the symbols. Each symbol which is marked as being a ObjC/C++
1801 symbol (language_cplus or language_objc set) has both the encoded and
1802 non-encoded names tested for a match.
1804 If LINKAGE_NAME is non-NULL, verify that any symbol we find has this
1805 particular mangled name.
1809 lookup_block_symbol (const struct block
*block
, const char *name
,
1810 const char *linkage_name
,
1811 const domain_enum domain
)
1813 struct dict_iterator iter
;
1816 if (!BLOCK_FUNCTION (block
))
1818 for (sym
= dict_iter_name_first (BLOCK_DICT (block
), name
, &iter
);
1820 sym
= dict_iter_name_next (name
, &iter
))
1822 if (SYMBOL_DOMAIN (sym
) == domain
1823 && (linkage_name
!= NULL
1824 ? strcmp (SYMBOL_LINKAGE_NAME (sym
), linkage_name
) == 0 : 1))
1831 /* Note that parameter symbols do not always show up last in the
1832 list; this loop makes sure to take anything else other than
1833 parameter symbols first; it only uses parameter symbols as a
1834 last resort. Note that this only takes up extra computation
1837 struct symbol
*sym_found
= NULL
;
1839 for (sym
= dict_iter_name_first (BLOCK_DICT (block
), name
, &iter
);
1841 sym
= dict_iter_name_next (name
, &iter
))
1843 if (SYMBOL_DOMAIN (sym
) == domain
1844 && (linkage_name
!= NULL
1845 ? strcmp (SYMBOL_LINKAGE_NAME (sym
), linkage_name
) == 0 : 1))
1848 if (SYMBOL_CLASS (sym
) != LOC_ARG
&&
1849 SYMBOL_CLASS (sym
) != LOC_LOCAL_ARG
&&
1850 SYMBOL_CLASS (sym
) != LOC_REF_ARG
&&
1851 SYMBOL_CLASS (sym
) != LOC_REGPARM
&&
1852 SYMBOL_CLASS (sym
) != LOC_REGPARM_ADDR
&&
1853 SYMBOL_CLASS (sym
) != LOC_BASEREG_ARG
&&
1854 SYMBOL_CLASS (sym
) != LOC_COMPUTED_ARG
)
1860 return (sym_found
); /* Will be NULL if not found. */
1864 /* Find the symtab associated with PC and SECTION. Look through the
1865 psymtabs and read in another symtab if necessary. */
1868 find_pc_sect_symtab (CORE_ADDR pc
, asection
*section
)
1871 struct blockvector
*bv
;
1872 struct symtab
*s
= NULL
;
1873 struct symtab
*best_s
= NULL
;
1874 struct partial_symtab
*ps
;
1875 struct objfile
*objfile
;
1876 CORE_ADDR distance
= 0;
1877 struct minimal_symbol
*msymbol
;
1879 /* If we know that this is not a text address, return failure. This is
1880 necessary because we loop based on the block's high and low code
1881 addresses, which do not include the data ranges, and because
1882 we call find_pc_sect_psymtab which has a similar restriction based
1883 on the partial_symtab's texthigh and textlow. */
1884 msymbol
= lookup_minimal_symbol_by_pc_section (pc
, section
);
1886 && (msymbol
->type
== mst_data
1887 || msymbol
->type
== mst_bss
1888 || msymbol
->type
== mst_abs
1889 || msymbol
->type
== mst_file_data
1890 || msymbol
->type
== mst_file_bss
))
1893 /* Search all symtabs for the one whose file contains our address, and which
1894 is the smallest of all the ones containing the address. This is designed
1895 to deal with a case like symtab a is at 0x1000-0x2000 and 0x3000-0x4000
1896 and symtab b is at 0x2000-0x3000. So the GLOBAL_BLOCK for a is from
1897 0x1000-0x4000, but for address 0x2345 we want to return symtab b.
1899 This happens for native ecoff format, where code from included files
1900 gets its own symtab. The symtab for the included file should have
1901 been read in already via the dependency mechanism.
1902 It might be swifter to create several symtabs with the same name
1903 like xcoff does (I'm not sure).
1905 It also happens for objfiles that have their functions reordered.
1906 For these, the symtab we are looking for is not necessarily read in. */
1908 ALL_PRIMARY_SYMTABS (objfile
, s
)
1910 bv
= BLOCKVECTOR (s
);
1911 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1913 if (BLOCK_START (b
) <= pc
1914 && BLOCK_END (b
) > pc
1916 || BLOCK_END (b
) - BLOCK_START (b
) < distance
))
1918 /* For an objfile that has its functions reordered,
1919 find_pc_psymtab will find the proper partial symbol table
1920 and we simply return its corresponding symtab. */
1921 /* In order to better support objfiles that contain both
1922 stabs and coff debugging info, we continue on if a psymtab
1924 if ((objfile
->flags
& OBJF_REORDERED
) && objfile
->psymtabs
)
1926 ps
= find_pc_sect_psymtab (pc
, section
);
1928 return PSYMTAB_TO_SYMTAB (ps
);
1932 struct dict_iterator iter
;
1933 struct symbol
*sym
= NULL
;
1935 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1937 fixup_symbol_section (sym
, objfile
);
1938 if (matching_bfd_sections (SYMBOL_BFD_SECTION (sym
), section
))
1942 continue; /* no symbol in this symtab matches section */
1944 distance
= BLOCK_END (b
) - BLOCK_START (b
);
1953 ps
= find_pc_sect_psymtab (pc
, section
);
1957 /* Might want to error() here (in case symtab is corrupt and
1958 will cause a core dump), but maybe we can successfully
1959 continue, so let's not. */
1961 (Internal error: pc 0x%s in read in psymtab, but not in symtab.)\n"),
1963 s
= PSYMTAB_TO_SYMTAB (ps
);
1968 /* Find the symtab associated with PC. Look through the psymtabs and
1969 read in another symtab if necessary. Backward compatibility, no section */
1972 find_pc_symtab (CORE_ADDR pc
)
1974 return find_pc_sect_symtab (pc
, find_pc_mapped_section (pc
));
1978 /* Find the source file and line number for a given PC value and SECTION.
1979 Return a structure containing a symtab pointer, a line number,
1980 and a pc range for the entire source line.
1981 The value's .pc field is NOT the specified pc.
1982 NOTCURRENT nonzero means, if specified pc is on a line boundary,
1983 use the line that ends there. Otherwise, in that case, the line
1984 that begins there is used. */
1986 /* The big complication here is that a line may start in one file, and end just
1987 before the start of another file. This usually occurs when you #include
1988 code in the middle of a subroutine. To properly find the end of a line's PC
1989 range, we must search all symtabs associated with this compilation unit, and
1990 find the one whose first PC is closer than that of the next line in this
1993 /* If it's worth the effort, we could be using a binary search. */
1995 struct symtab_and_line
1996 find_pc_sect_line (CORE_ADDR pc
, struct bfd_section
*section
, int notcurrent
)
1999 struct linetable
*l
;
2002 struct linetable_entry
*item
;
2003 struct symtab_and_line val
;
2004 struct blockvector
*bv
;
2005 struct minimal_symbol
*msymbol
;
2006 struct minimal_symbol
*mfunsym
;
2008 /* Info on best line seen so far, and where it starts, and its file. */
2010 struct linetable_entry
*best
= NULL
;
2011 CORE_ADDR best_end
= 0;
2012 struct symtab
*best_symtab
= 0;
2014 /* Store here the first line number
2015 of a file which contains the line at the smallest pc after PC.
2016 If we don't find a line whose range contains PC,
2017 we will use a line one less than this,
2018 with a range from the start of that file to the first line's pc. */
2019 struct linetable_entry
*alt
= NULL
;
2020 struct symtab
*alt_symtab
= 0;
2022 /* Info on best line seen in this file. */
2024 struct linetable_entry
*prev
;
2026 /* If this pc is not from the current frame,
2027 it is the address of the end of a call instruction.
2028 Quite likely that is the start of the following statement.
2029 But what we want is the statement containing the instruction.
2030 Fudge the pc to make sure we get that. */
2032 init_sal (&val
); /* initialize to zeroes */
2034 /* It's tempting to assume that, if we can't find debugging info for
2035 any function enclosing PC, that we shouldn't search for line
2036 number info, either. However, GAS can emit line number info for
2037 assembly files --- very helpful when debugging hand-written
2038 assembly code. In such a case, we'd have no debug info for the
2039 function, but we would have line info. */
2044 /* elz: added this because this function returned the wrong
2045 information if the pc belongs to a stub (import/export)
2046 to call a shlib function. This stub would be anywhere between
2047 two functions in the target, and the line info was erroneously
2048 taken to be the one of the line before the pc.
2050 /* RT: Further explanation:
2052 * We have stubs (trampolines) inserted between procedures.
2054 * Example: "shr1" exists in a shared library, and a "shr1" stub also
2055 * exists in the main image.
2057 * In the minimal symbol table, we have a bunch of symbols
2058 * sorted by start address. The stubs are marked as "trampoline",
2059 * the others appear as text. E.g.:
2061 * Minimal symbol table for main image
2062 * main: code for main (text symbol)
2063 * shr1: stub (trampoline symbol)
2064 * foo: code for foo (text symbol)
2066 * Minimal symbol table for "shr1" image:
2068 * shr1: code for shr1 (text symbol)
2071 * So the code below is trying to detect if we are in the stub
2072 * ("shr1" stub), and if so, find the real code ("shr1" trampoline),
2073 * and if found, do the symbolization from the real-code address
2074 * rather than the stub address.
2076 * Assumptions being made about the minimal symbol table:
2077 * 1. lookup_minimal_symbol_by_pc() will return a trampoline only
2078 * if we're really in the trampoline. If we're beyond it (say
2079 * we're in "foo" in the above example), it'll have a closer
2080 * symbol (the "foo" text symbol for example) and will not
2081 * return the trampoline.
2082 * 2. lookup_minimal_symbol_text() will find a real text symbol
2083 * corresponding to the trampoline, and whose address will
2084 * be different than the trampoline address. I put in a sanity
2085 * check for the address being the same, to avoid an
2086 * infinite recursion.
2088 msymbol
= lookup_minimal_symbol_by_pc (pc
);
2089 if (msymbol
!= NULL
)
2090 if (MSYMBOL_TYPE (msymbol
) == mst_solib_trampoline
)
2092 mfunsym
= lookup_minimal_symbol_text (SYMBOL_LINKAGE_NAME (msymbol
),
2094 if (mfunsym
== NULL
)
2095 /* I eliminated this warning since it is coming out
2096 * in the following situation:
2097 * gdb shmain // test program with shared libraries
2098 * (gdb) break shr1 // function in shared lib
2099 * Warning: In stub for ...
2100 * In the above situation, the shared lib is not loaded yet,
2101 * so of course we can't find the real func/line info,
2102 * but the "break" still works, and the warning is annoying.
2103 * So I commented out the warning. RT */
2104 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_LINKAGE_NAME (msymbol)) */ ;
2106 else if (SYMBOL_VALUE (mfunsym
) == SYMBOL_VALUE (msymbol
))
2107 /* Avoid infinite recursion */
2108 /* See above comment about why warning is commented out */
2109 /* warning ("In stub for %s; unable to find real function/line info", SYMBOL_LINKAGE_NAME (msymbol)) */ ;
2112 return find_pc_line (SYMBOL_VALUE (mfunsym
), 0);
2116 s
= find_pc_sect_symtab (pc
, section
);
2119 /* if no symbol information, return previous pc */
2126 bv
= BLOCKVECTOR (s
);
2128 /* Look at all the symtabs that share this blockvector.
2129 They all have the same apriori range, that we found was right;
2130 but they have different line tables. */
2132 for (; s
&& BLOCKVECTOR (s
) == bv
; s
= s
->next
)
2134 /* Find the best line in this symtab. */
2141 /* I think len can be zero if the symtab lacks line numbers
2142 (e.g. gcc -g1). (Either that or the LINETABLE is NULL;
2143 I'm not sure which, and maybe it depends on the symbol
2149 item
= l
->item
; /* Get first line info */
2151 /* Is this file's first line closer than the first lines of other files?
2152 If so, record this file, and its first line, as best alternate. */
2153 if (item
->pc
> pc
&& (!alt
|| item
->pc
< alt
->pc
))
2159 for (i
= 0; i
< len
; i
++, item
++)
2161 /* Leave prev pointing to the linetable entry for the last line
2162 that started at or before PC. */
2169 /* At this point, prev points at the line whose start addr is <= pc, and
2170 item points at the next line. If we ran off the end of the linetable
2171 (pc >= start of the last line), then prev == item. If pc < start of
2172 the first line, prev will not be set. */
2174 /* Is this file's best line closer than the best in the other files?
2175 If so, record this file, and its best line, as best so far. Don't
2176 save prev if it represents the end of a function (i.e. line number
2177 0) instead of a real line. */
2179 if (prev
&& prev
->line
&& (!best
|| prev
->pc
> best
->pc
))
2184 /* Discard BEST_END if it's before the PC of the current BEST. */
2185 if (best_end
<= best
->pc
)
2189 /* If another line (denoted by ITEM) is in the linetable and its
2190 PC is after BEST's PC, but before the current BEST_END, then
2191 use ITEM's PC as the new best_end. */
2192 if (best
&& i
< len
&& item
->pc
> best
->pc
2193 && (best_end
== 0 || best_end
> item
->pc
))
2194 best_end
= item
->pc
;
2199 /* If we didn't find any line number info, just return zeros.
2200 We used to return alt->line - 1 here, but that could be
2201 anywhere; if we don't have line number info for this PC,
2202 don't make some up. */
2205 else if (best
->line
== 0)
2207 /* If our best fit is in a range of PC's for which no line
2208 number info is available (line number is zero) then we didn't
2209 find any valid line information. */
2214 val
.symtab
= best_symtab
;
2215 val
.line
= best
->line
;
2217 if (best_end
&& (!alt
|| best_end
< alt
->pc
))
2222 val
.end
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
2224 val
.section
= section
;
2228 /* Backward compatibility (no section) */
2230 struct symtab_and_line
2231 find_pc_line (CORE_ADDR pc
, int notcurrent
)
2235 section
= find_pc_overlay (pc
);
2236 if (pc_in_unmapped_range (pc
, section
))
2237 pc
= overlay_mapped_address (pc
, section
);
2238 return find_pc_sect_line (pc
, section
, notcurrent
);
2241 /* Find line number LINE in any symtab whose name is the same as
2244 If found, return the symtab that contains the linetable in which it was
2245 found, set *INDEX to the index in the linetable of the best entry
2246 found, and set *EXACT_MATCH nonzero if the value returned is an
2249 If not found, return NULL. */
2252 find_line_symtab (struct symtab
*symtab
, int line
, int *index
, int *exact_match
)
2256 /* BEST_INDEX and BEST_LINETABLE identify the smallest linenumber > LINE
2260 struct linetable
*best_linetable
;
2261 struct symtab
*best_symtab
;
2263 /* First try looking it up in the given symtab. */
2264 best_linetable
= LINETABLE (symtab
);
2265 best_symtab
= symtab
;
2266 best_index
= find_line_common (best_linetable
, line
, &exact
);
2267 if (best_index
< 0 || !exact
)
2269 /* Didn't find an exact match. So we better keep looking for
2270 another symtab with the same name. In the case of xcoff,
2271 multiple csects for one source file (produced by IBM's FORTRAN
2272 compiler) produce multiple symtabs (this is unavoidable
2273 assuming csects can be at arbitrary places in memory and that
2274 the GLOBAL_BLOCK of a symtab has a begin and end address). */
2276 /* BEST is the smallest linenumber > LINE so far seen,
2277 or 0 if none has been seen so far.
2278 BEST_INDEX and BEST_LINETABLE identify the item for it. */
2281 struct objfile
*objfile
;
2284 if (best_index
>= 0)
2285 best
= best_linetable
->item
[best_index
].line
;
2289 ALL_SYMTABS (objfile
, s
)
2291 struct linetable
*l
;
2294 if (strcmp (symtab
->filename
, s
->filename
) != 0)
2297 ind
= find_line_common (l
, line
, &exact
);
2307 if (best
== 0 || l
->item
[ind
].line
< best
)
2309 best
= l
->item
[ind
].line
;
2322 *index
= best_index
;
2324 *exact_match
= exact
;
2329 /* Set the PC value for a given source file and line number and return true.
2330 Returns zero for invalid line number (and sets the PC to 0).
2331 The source file is specified with a struct symtab. */
2334 find_line_pc (struct symtab
*symtab
, int line
, CORE_ADDR
*pc
)
2336 struct linetable
*l
;
2343 symtab
= find_line_symtab (symtab
, line
, &ind
, NULL
);
2346 l
= LINETABLE (symtab
);
2347 *pc
= l
->item
[ind
].pc
;
2354 /* Find the range of pc values in a line.
2355 Store the starting pc of the line into *STARTPTR
2356 and the ending pc (start of next line) into *ENDPTR.
2357 Returns 1 to indicate success.
2358 Returns 0 if could not find the specified line. */
2361 find_line_pc_range (struct symtab_and_line sal
, CORE_ADDR
*startptr
,
2364 CORE_ADDR startaddr
;
2365 struct symtab_and_line found_sal
;
2368 if (startaddr
== 0 && !find_line_pc (sal
.symtab
, sal
.line
, &startaddr
))
2371 /* This whole function is based on address. For example, if line 10 has
2372 two parts, one from 0x100 to 0x200 and one from 0x300 to 0x400, then
2373 "info line *0x123" should say the line goes from 0x100 to 0x200
2374 and "info line *0x355" should say the line goes from 0x300 to 0x400.
2375 This also insures that we never give a range like "starts at 0x134
2376 and ends at 0x12c". */
2378 found_sal
= find_pc_sect_line (startaddr
, sal
.section
, 0);
2379 if (found_sal
.line
!= sal
.line
)
2381 /* The specified line (sal) has zero bytes. */
2382 *startptr
= found_sal
.pc
;
2383 *endptr
= found_sal
.pc
;
2387 *startptr
= found_sal
.pc
;
2388 *endptr
= found_sal
.end
;
2393 /* Given a line table and a line number, return the index into the line
2394 table for the pc of the nearest line whose number is >= the specified one.
2395 Return -1 if none is found. The value is >= 0 if it is an index.
2397 Set *EXACT_MATCH nonzero if the value returned is an exact match. */
2400 find_line_common (struct linetable
*l
, int lineno
,
2406 /* BEST is the smallest linenumber > LINENO so far seen,
2407 or 0 if none has been seen so far.
2408 BEST_INDEX identifies the item for it. */
2410 int best_index
= -1;
2419 for (i
= 0; i
< len
; i
++)
2421 struct linetable_entry
*item
= &(l
->item
[i
]);
2423 if (item
->line
== lineno
)
2425 /* Return the first (lowest address) entry which matches. */
2430 if (item
->line
> lineno
&& (best
== 0 || item
->line
< best
))
2437 /* If we got here, we didn't get an exact match. */
2444 find_pc_line_pc_range (CORE_ADDR pc
, CORE_ADDR
*startptr
, CORE_ADDR
*endptr
)
2446 struct symtab_and_line sal
;
2447 sal
= find_pc_line (pc
, 0);
2450 return sal
.symtab
!= 0;
2453 /* Given a function symbol SYM, find the symtab and line for the start
2455 If the argument FUNFIRSTLINE is nonzero, we want the first line
2456 of real code inside the function. */
2458 struct symtab_and_line
2459 find_function_start_sal (struct symbol
*sym
, int funfirstline
)
2462 struct symtab_and_line sal
;
2464 pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (sym
));
2465 fixup_symbol_section (sym
, NULL
);
2467 { /* skip "first line" of function (which is actually its prologue) */
2468 asection
*section
= SYMBOL_BFD_SECTION (sym
);
2469 /* If function is in an unmapped overlay, use its unmapped LMA
2470 address, so that gdbarch_skip_prologue has something unique to work
2472 if (section_is_overlay (section
) &&
2473 !section_is_mapped (section
))
2474 pc
= overlay_unmapped_address (pc
, section
);
2476 pc
+= gdbarch_deprecated_function_start_offset (current_gdbarch
);
2477 pc
= gdbarch_skip_prologue (current_gdbarch
, pc
);
2479 /* For overlays, map pc back into its mapped VMA range */
2480 pc
= overlay_mapped_address (pc
, section
);
2482 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
2484 /* Check if gdbarch_skip_prologue left us in mid-line, and the next
2485 line is still part of the same function. */
2487 && BLOCK_START (SYMBOL_BLOCK_VALUE (sym
)) <= sal
.end
2488 && sal
.end
< BLOCK_END (SYMBOL_BLOCK_VALUE (sym
)))
2490 /* First pc of next line */
2492 /* Recalculate the line number (might not be N+1). */
2493 sal
= find_pc_sect_line (pc
, SYMBOL_BFD_SECTION (sym
), 0);
2500 /* If P is of the form "operator[ \t]+..." where `...' is
2501 some legitimate operator text, return a pointer to the
2502 beginning of the substring of the operator text.
2503 Otherwise, return "". */
2505 operator_chars (char *p
, char **end
)
2508 if (strncmp (p
, "operator", 8))
2512 /* Don't get faked out by `operator' being part of a longer
2514 if (isalpha (*p
) || *p
== '_' || *p
== '$' || *p
== '\0')
2517 /* Allow some whitespace between `operator' and the operator symbol. */
2518 while (*p
== ' ' || *p
== '\t')
2521 /* Recognize 'operator TYPENAME'. */
2523 if (isalpha (*p
) || *p
== '_' || *p
== '$')
2526 while (isalnum (*q
) || *q
== '_' || *q
== '$')
2535 case '\\': /* regexp quoting */
2538 if (p
[2] == '=') /* 'operator\*=' */
2540 else /* 'operator\*' */
2544 else if (p
[1] == '[')
2547 error (_("mismatched quoting on brackets, try 'operator\\[\\]'"));
2548 else if (p
[2] == '\\' && p
[3] == ']')
2550 *end
= p
+ 4; /* 'operator\[\]' */
2554 error (_("nothing is allowed between '[' and ']'"));
2558 /* Gratuitous qoute: skip it and move on. */
2580 if (p
[0] == '-' && p
[1] == '>')
2582 /* Struct pointer member operator 'operator->'. */
2585 *end
= p
+ 3; /* 'operator->*' */
2588 else if (p
[2] == '\\')
2590 *end
= p
+ 4; /* Hopefully 'operator->\*' */
2595 *end
= p
+ 2; /* 'operator->' */
2599 if (p
[1] == '=' || p
[1] == p
[0])
2610 error (_("`operator ()' must be specified without whitespace in `()'"));
2615 error (_("`operator ?:' must be specified without whitespace in `?:'"));
2620 error (_("`operator []' must be specified without whitespace in `[]'"));
2624 error (_("`operator %s' not supported"), p
);
2633 /* If FILE is not already in the table of files, return zero;
2634 otherwise return non-zero. Optionally add FILE to the table if ADD
2635 is non-zero. If *FIRST is non-zero, forget the old table
2638 filename_seen (const char *file
, int add
, int *first
)
2640 /* Table of files seen so far. */
2641 static const char **tab
= NULL
;
2642 /* Allocated size of tab in elements.
2643 Start with one 256-byte block (when using GNU malloc.c).
2644 24 is the malloc overhead when range checking is in effect. */
2645 static int tab_alloc_size
= (256 - 24) / sizeof (char *);
2646 /* Current size of tab in elements. */
2647 static int tab_cur_size
;
2653 tab
= (const char **) xmalloc (tab_alloc_size
* sizeof (*tab
));
2657 /* Is FILE in tab? */
2658 for (p
= tab
; p
< tab
+ tab_cur_size
; p
++)
2659 if (strcmp (*p
, file
) == 0)
2662 /* No; maybe add it to tab. */
2665 if (tab_cur_size
== tab_alloc_size
)
2667 tab_alloc_size
*= 2;
2668 tab
= (const char **) xrealloc ((char *) tab
,
2669 tab_alloc_size
* sizeof (*tab
));
2671 tab
[tab_cur_size
++] = file
;
2677 /* Slave routine for sources_info. Force line breaks at ,'s.
2678 NAME is the name to print and *FIRST is nonzero if this is the first
2679 name printed. Set *FIRST to zero. */
2681 output_source_filename (const char *name
, int *first
)
2683 /* Since a single source file can result in several partial symbol
2684 tables, we need to avoid printing it more than once. Note: if
2685 some of the psymtabs are read in and some are not, it gets
2686 printed both under "Source files for which symbols have been
2687 read" and "Source files for which symbols will be read in on
2688 demand". I consider this a reasonable way to deal with the
2689 situation. I'm not sure whether this can also happen for
2690 symtabs; it doesn't hurt to check. */
2692 /* Was NAME already seen? */
2693 if (filename_seen (name
, 1, first
))
2695 /* Yes; don't print it again. */
2698 /* No; print it and reset *FIRST. */
2705 printf_filtered (", ");
2709 fputs_filtered (name
, gdb_stdout
);
2713 sources_info (char *ignore
, int from_tty
)
2716 struct partial_symtab
*ps
;
2717 struct objfile
*objfile
;
2720 if (!have_full_symbols () && !have_partial_symbols ())
2722 error (_("No symbol table is loaded. Use the \"file\" command."));
2725 printf_filtered ("Source files for which symbols have been read in:\n\n");
2728 ALL_SYMTABS (objfile
, s
)
2730 const char *fullname
= symtab_to_fullname (s
);
2731 output_source_filename (fullname
? fullname
: s
->filename
, &first
);
2733 printf_filtered ("\n\n");
2735 printf_filtered ("Source files for which symbols will be read in on demand:\n\n");
2738 ALL_PSYMTABS (objfile
, ps
)
2742 const char *fullname
= psymtab_to_fullname (ps
);
2743 output_source_filename (fullname
? fullname
: ps
->filename
, &first
);
2746 printf_filtered ("\n");
2750 file_matches (char *file
, char *files
[], int nfiles
)
2754 if (file
!= NULL
&& nfiles
!= 0)
2756 for (i
= 0; i
< nfiles
; i
++)
2758 if (strcmp (files
[i
], lbasename (file
)) == 0)
2762 else if (nfiles
== 0)
2767 /* Free any memory associated with a search. */
2769 free_search_symbols (struct symbol_search
*symbols
)
2771 struct symbol_search
*p
;
2772 struct symbol_search
*next
;
2774 for (p
= symbols
; p
!= NULL
; p
= next
)
2782 do_free_search_symbols_cleanup (void *symbols
)
2784 free_search_symbols (symbols
);
2788 make_cleanup_free_search_symbols (struct symbol_search
*symbols
)
2790 return make_cleanup (do_free_search_symbols_cleanup
, symbols
);
2793 /* Helper function for sort_search_symbols and qsort. Can only
2794 sort symbols, not minimal symbols. */
2796 compare_search_syms (const void *sa
, const void *sb
)
2798 struct symbol_search
**sym_a
= (struct symbol_search
**) sa
;
2799 struct symbol_search
**sym_b
= (struct symbol_search
**) sb
;
2801 return strcmp (SYMBOL_PRINT_NAME ((*sym_a
)->symbol
),
2802 SYMBOL_PRINT_NAME ((*sym_b
)->symbol
));
2805 /* Sort the ``nfound'' symbols in the list after prevtail. Leave
2806 prevtail where it is, but update its next pointer to point to
2807 the first of the sorted symbols. */
2808 static struct symbol_search
*
2809 sort_search_symbols (struct symbol_search
*prevtail
, int nfound
)
2811 struct symbol_search
**symbols
, *symp
, *old_next
;
2814 symbols
= (struct symbol_search
**) xmalloc (sizeof (struct symbol_search
*)
2816 symp
= prevtail
->next
;
2817 for (i
= 0; i
< nfound
; i
++)
2822 /* Generally NULL. */
2825 qsort (symbols
, nfound
, sizeof (struct symbol_search
*),
2826 compare_search_syms
);
2829 for (i
= 0; i
< nfound
; i
++)
2831 symp
->next
= symbols
[i
];
2834 symp
->next
= old_next
;
2840 /* Search the symbol table for matches to the regular expression REGEXP,
2841 returning the results in *MATCHES.
2843 Only symbols of KIND are searched:
2844 FUNCTIONS_DOMAIN - search all functions
2845 TYPES_DOMAIN - search all type names
2846 METHODS_DOMAIN - search all methods NOT IMPLEMENTED
2847 VARIABLES_DOMAIN - search all symbols, excluding functions, type names,
2848 and constants (enums)
2850 free_search_symbols should be called when *MATCHES is no longer needed.
2852 The results are sorted locally; each symtab's global and static blocks are
2853 separately alphabetized.
2856 search_symbols (char *regexp
, domain_enum kind
, int nfiles
, char *files
[],
2857 struct symbol_search
**matches
)
2860 struct partial_symtab
*ps
;
2861 struct blockvector
*bv
;
2864 struct dict_iterator iter
;
2866 struct partial_symbol
**psym
;
2867 struct objfile
*objfile
;
2868 struct minimal_symbol
*msymbol
;
2871 static enum minimal_symbol_type types
[]
2873 {mst_data
, mst_text
, mst_abs
, mst_unknown
};
2874 static enum minimal_symbol_type types2
[]
2876 {mst_bss
, mst_file_text
, mst_abs
, mst_unknown
};
2877 static enum minimal_symbol_type types3
[]
2879 {mst_file_data
, mst_solib_trampoline
, mst_abs
, mst_unknown
};
2880 static enum minimal_symbol_type types4
[]
2882 {mst_file_bss
, mst_text
, mst_abs
, mst_unknown
};
2883 enum minimal_symbol_type ourtype
;
2884 enum minimal_symbol_type ourtype2
;
2885 enum minimal_symbol_type ourtype3
;
2886 enum minimal_symbol_type ourtype4
;
2887 struct symbol_search
*sr
;
2888 struct symbol_search
*psr
;
2889 struct symbol_search
*tail
;
2890 struct cleanup
*old_chain
= NULL
;
2892 if (kind
< VARIABLES_DOMAIN
)
2893 error (_("must search on specific domain"));
2895 ourtype
= types
[(int) (kind
- VARIABLES_DOMAIN
)];
2896 ourtype2
= types2
[(int) (kind
- VARIABLES_DOMAIN
)];
2897 ourtype3
= types3
[(int) (kind
- VARIABLES_DOMAIN
)];
2898 ourtype4
= types4
[(int) (kind
- VARIABLES_DOMAIN
)];
2900 sr
= *matches
= NULL
;
2905 /* Make sure spacing is right for C++ operators.
2906 This is just a courtesy to make the matching less sensitive
2907 to how many spaces the user leaves between 'operator'
2908 and <TYPENAME> or <OPERATOR>. */
2910 char *opname
= operator_chars (regexp
, &opend
);
2913 int fix
= -1; /* -1 means ok; otherwise number of spaces needed. */
2914 if (isalpha (*opname
) || *opname
== '_' || *opname
== '$')
2916 /* There should 1 space between 'operator' and 'TYPENAME'. */
2917 if (opname
[-1] != ' ' || opname
[-2] == ' ')
2922 /* There should 0 spaces between 'operator' and 'OPERATOR'. */
2923 if (opname
[-1] == ' ')
2926 /* If wrong number of spaces, fix it. */
2929 char *tmp
= (char *) alloca (8 + fix
+ strlen (opname
) + 1);
2930 sprintf (tmp
, "operator%.*s%s", fix
, " ", opname
);
2935 if (0 != (val
= re_comp (regexp
)))
2936 error (_("Invalid regexp (%s): %s"), val
, regexp
);
2939 /* Search through the partial symtabs *first* for all symbols
2940 matching the regexp. That way we don't have to reproduce all of
2941 the machinery below. */
2943 ALL_PSYMTABS (objfile
, ps
)
2945 struct partial_symbol
**bound
, **gbound
, **sbound
;
2951 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
2952 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
2955 /* Go through all of the symbols stored in a partial
2956 symtab in one loop. */
2957 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2962 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
2964 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2975 /* If it would match (logic taken from loop below)
2976 load the file and go on to the next one. We check the
2977 filename here, but that's a bit bogus: we don't know
2978 what file it really comes from until we have full
2979 symtabs. The symbol might be in a header file included by
2980 this psymtab. This only affects Insight. */
2981 if (file_matches (ps
->filename
, files
, nfiles
)
2983 || re_exec (SYMBOL_NATURAL_NAME (*psym
)) != 0)
2984 && ((kind
== VARIABLES_DOMAIN
&& SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
2985 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
2986 || (kind
== FUNCTIONS_DOMAIN
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
2987 || (kind
== TYPES_DOMAIN
&& SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
)
2988 || (kind
== METHODS_DOMAIN
&& SYMBOL_CLASS (*psym
) == LOC_BLOCK
))))
2990 PSYMTAB_TO_SYMTAB (ps
);
2998 /* Here, we search through the minimal symbol tables for functions
2999 and variables that match, and force their symbols to be read.
3000 This is in particular necessary for demangled variable names,
3001 which are no longer put into the partial symbol tables.
3002 The symbol will then be found during the scan of symtabs below.
3004 For functions, find_pc_symtab should succeed if we have debug info
3005 for the function, for variables we have to call lookup_symbol
3006 to determine if the variable has debug info.
3007 If the lookup fails, set found_misc so that we will rescan to print
3008 any matching symbols without debug info.
3011 if (nfiles
== 0 && (kind
== VARIABLES_DOMAIN
|| kind
== FUNCTIONS_DOMAIN
))
3013 ALL_MSYMBOLS (objfile
, msymbol
)
3015 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
3016 MSYMBOL_TYPE (msymbol
) == ourtype2
||
3017 MSYMBOL_TYPE (msymbol
) == ourtype3
||
3018 MSYMBOL_TYPE (msymbol
) == ourtype4
)
3021 || re_exec (SYMBOL_NATURAL_NAME (msymbol
)) != 0)
3023 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
)))
3025 /* FIXME: carlton/2003-02-04: Given that the
3026 semantics of lookup_symbol keeps on changing
3027 slightly, it would be a nice idea if we had a
3028 function lookup_symbol_minsym that found the
3029 symbol associated to a given minimal symbol (if
3031 if (kind
== FUNCTIONS_DOMAIN
3032 || lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol
),
3033 (struct block
*) NULL
,
3035 0, (struct symtab
**) NULL
)
3044 ALL_PRIMARY_SYMTABS (objfile
, s
)
3046 bv
= BLOCKVECTOR (s
);
3047 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
3049 struct symbol_search
*prevtail
= tail
;
3051 b
= BLOCKVECTOR_BLOCK (bv
, i
);
3052 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
3054 struct symtab
*real_symtab
= SYMBOL_SYMTAB (sym
);
3057 if (file_matches (real_symtab
->filename
, files
, nfiles
)
3059 || re_exec (SYMBOL_NATURAL_NAME (sym
)) != 0)
3060 && ((kind
== VARIABLES_DOMAIN
&& SYMBOL_CLASS (sym
) != LOC_TYPEDEF
3061 && SYMBOL_CLASS (sym
) != LOC_BLOCK
3062 && SYMBOL_CLASS (sym
) != LOC_CONST
)
3063 || (kind
== FUNCTIONS_DOMAIN
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3064 || (kind
== TYPES_DOMAIN
&& SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3065 || (kind
== METHODS_DOMAIN
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
))))
3068 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
3070 psr
->symtab
= real_symtab
;
3072 psr
->msymbol
= NULL
;
3084 if (prevtail
== NULL
)
3086 struct symbol_search dummy
;
3089 tail
= sort_search_symbols (&dummy
, nfound
);
3092 old_chain
= make_cleanup_free_search_symbols (sr
);
3095 tail
= sort_search_symbols (prevtail
, nfound
);
3100 /* If there are no eyes, avoid all contact. I mean, if there are
3101 no debug symbols, then print directly from the msymbol_vector. */
3103 if (found_misc
|| kind
!= FUNCTIONS_DOMAIN
)
3105 ALL_MSYMBOLS (objfile
, msymbol
)
3107 if (MSYMBOL_TYPE (msymbol
) == ourtype
||
3108 MSYMBOL_TYPE (msymbol
) == ourtype2
||
3109 MSYMBOL_TYPE (msymbol
) == ourtype3
||
3110 MSYMBOL_TYPE (msymbol
) == ourtype4
)
3113 || re_exec (SYMBOL_NATURAL_NAME (msymbol
)) != 0)
3115 /* Functions: Look up by address. */
3116 if (kind
!= FUNCTIONS_DOMAIN
||
3117 (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol
))))
3119 /* Variables/Absolutes: Look up by name */
3120 if (lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol
),
3121 (struct block
*) NULL
, VAR_DOMAIN
,
3122 0, (struct symtab
**) NULL
) == NULL
)
3125 psr
= (struct symbol_search
*) xmalloc (sizeof (struct symbol_search
));
3127 psr
->msymbol
= msymbol
;
3134 old_chain
= make_cleanup_free_search_symbols (sr
);
3148 discard_cleanups (old_chain
);
3151 /* Helper function for symtab_symbol_info, this function uses
3152 the data returned from search_symbols() to print information
3153 regarding the match to gdb_stdout.
3156 print_symbol_info (domain_enum kind
, struct symtab
*s
, struct symbol
*sym
,
3157 int block
, char *last
)
3159 if (last
== NULL
|| strcmp (last
, s
->filename
) != 0)
3161 fputs_filtered ("\nFile ", gdb_stdout
);
3162 fputs_filtered (s
->filename
, gdb_stdout
);
3163 fputs_filtered (":\n", gdb_stdout
);
3166 if (kind
!= TYPES_DOMAIN
&& block
== STATIC_BLOCK
)
3167 printf_filtered ("static ");
3169 /* Typedef that is not a C++ class */
3170 if (kind
== TYPES_DOMAIN
3171 && SYMBOL_DOMAIN (sym
) != STRUCT_DOMAIN
)
3172 typedef_print (SYMBOL_TYPE (sym
), sym
, gdb_stdout
);
3173 /* variable, func, or typedef-that-is-c++-class */
3174 else if (kind
< TYPES_DOMAIN
||
3175 (kind
== TYPES_DOMAIN
&&
3176 SYMBOL_DOMAIN (sym
) == STRUCT_DOMAIN
))
3178 type_print (SYMBOL_TYPE (sym
),
3179 (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3180 ? "" : SYMBOL_PRINT_NAME (sym
)),
3183 printf_filtered (";\n");
3187 /* This help function for symtab_symbol_info() prints information
3188 for non-debugging symbols to gdb_stdout.
3191 print_msymbol_info (struct minimal_symbol
*msymbol
)
3195 if (gdbarch_addr_bit (current_gdbarch
) <= 32)
3196 tmp
= hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol
)
3197 & (CORE_ADDR
) 0xffffffff,
3200 tmp
= hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol
),
3202 printf_filtered ("%s %s\n",
3203 tmp
, SYMBOL_PRINT_NAME (msymbol
));
3206 /* This is the guts of the commands "info functions", "info types", and
3207 "info variables". It calls search_symbols to find all matches and then
3208 print_[m]symbol_info to print out some useful information about the
3212 symtab_symbol_info (char *regexp
, domain_enum kind
, int from_tty
)
3214 static char *classnames
[]
3216 {"variable", "function", "type", "method"};
3217 struct symbol_search
*symbols
;
3218 struct symbol_search
*p
;
3219 struct cleanup
*old_chain
;
3220 char *last_filename
= NULL
;
3223 /* must make sure that if we're interrupted, symbols gets freed */
3224 search_symbols (regexp
, kind
, 0, (char **) NULL
, &symbols
);
3225 old_chain
= make_cleanup_free_search_symbols (symbols
);
3227 printf_filtered (regexp
3228 ? "All %ss matching regular expression \"%s\":\n"
3229 : "All defined %ss:\n",
3230 classnames
[(int) (kind
- VARIABLES_DOMAIN
)], regexp
);
3232 for (p
= symbols
; p
!= NULL
; p
= p
->next
)
3236 if (p
->msymbol
!= NULL
)
3240 printf_filtered ("\nNon-debugging symbols:\n");
3243 print_msymbol_info (p
->msymbol
);
3247 print_symbol_info (kind
,
3252 last_filename
= p
->symtab
->filename
;
3256 do_cleanups (old_chain
);
3260 variables_info (char *regexp
, int from_tty
)
3262 symtab_symbol_info (regexp
, VARIABLES_DOMAIN
, from_tty
);
3266 functions_info (char *regexp
, int from_tty
)
3268 symtab_symbol_info (regexp
, FUNCTIONS_DOMAIN
, from_tty
);
3273 types_info (char *regexp
, int from_tty
)
3275 symtab_symbol_info (regexp
, TYPES_DOMAIN
, from_tty
);
3278 /* Breakpoint all functions matching regular expression. */
3281 rbreak_command_wrapper (char *regexp
, int from_tty
)
3283 rbreak_command (regexp
, from_tty
);
3287 rbreak_command (char *regexp
, int from_tty
)
3289 struct symbol_search
*ss
;
3290 struct symbol_search
*p
;
3291 struct cleanup
*old_chain
;
3293 search_symbols (regexp
, FUNCTIONS_DOMAIN
, 0, (char **) NULL
, &ss
);
3294 old_chain
= make_cleanup_free_search_symbols (ss
);
3296 for (p
= ss
; p
!= NULL
; p
= p
->next
)
3298 if (p
->msymbol
== NULL
)
3300 char *string
= alloca (strlen (p
->symtab
->filename
)
3301 + strlen (SYMBOL_LINKAGE_NAME (p
->symbol
))
3303 strcpy (string
, p
->symtab
->filename
);
3304 strcat (string
, ":'");
3305 strcat (string
, SYMBOL_LINKAGE_NAME (p
->symbol
));
3306 strcat (string
, "'");
3307 break_command (string
, from_tty
);
3308 print_symbol_info (FUNCTIONS_DOMAIN
,
3312 p
->symtab
->filename
);
3316 break_command (SYMBOL_LINKAGE_NAME (p
->msymbol
), from_tty
);
3317 printf_filtered ("<function, no debug info> %s;\n",
3318 SYMBOL_PRINT_NAME (p
->msymbol
));
3322 do_cleanups (old_chain
);
3326 /* Helper routine for make_symbol_completion_list. */
3328 static int return_val_size
;
3329 static int return_val_index
;
3330 static char **return_val
;
3332 #define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \
3333 completion_list_add_name \
3334 (SYMBOL_NATURAL_NAME (symbol), (sym_text), (len), (text), (word))
3336 /* Test to see if the symbol specified by SYMNAME (which is already
3337 demangled for C++ symbols) matches SYM_TEXT in the first SYM_TEXT_LEN
3338 characters. If so, add it to the current completion list. */
3341 completion_list_add_name (char *symname
, char *sym_text
, int sym_text_len
,
3342 char *text
, char *word
)
3347 /* clip symbols that cannot match */
3349 if (strncmp (symname
, sym_text
, sym_text_len
) != 0)
3354 /* We have a match for a completion, so add SYMNAME to the current list
3355 of matches. Note that the name is moved to freshly malloc'd space. */
3359 if (word
== sym_text
)
3361 new = xmalloc (strlen (symname
) + 5);
3362 strcpy (new, symname
);
3364 else if (word
> sym_text
)
3366 /* Return some portion of symname. */
3367 new = xmalloc (strlen (symname
) + 5);
3368 strcpy (new, symname
+ (word
- sym_text
));
3372 /* Return some of SYM_TEXT plus symname. */
3373 new = xmalloc (strlen (symname
) + (sym_text
- word
) + 5);
3374 strncpy (new, word
, sym_text
- word
);
3375 new[sym_text
- word
] = '\0';
3376 strcat (new, symname
);
3379 if (return_val_index
+ 3 > return_val_size
)
3381 newsize
= (return_val_size
*= 2) * sizeof (char *);
3382 return_val
= (char **) xrealloc ((char *) return_val
, newsize
);
3384 return_val
[return_val_index
++] = new;
3385 return_val
[return_val_index
] = NULL
;
3389 /* ObjC: In case we are completing on a selector, look as the msymbol
3390 again and feed all the selectors into the mill. */
3393 completion_list_objc_symbol (struct minimal_symbol
*msymbol
, char *sym_text
,
3394 int sym_text_len
, char *text
, char *word
)
3396 static char *tmp
= NULL
;
3397 static unsigned int tmplen
= 0;
3399 char *method
, *category
, *selector
;
3402 method
= SYMBOL_NATURAL_NAME (msymbol
);
3404 /* Is it a method? */
3405 if ((method
[0] != '-') && (method
[0] != '+'))
3408 if (sym_text
[0] == '[')
3409 /* Complete on shortened method method. */
3410 completion_list_add_name (method
+ 1, sym_text
, sym_text_len
, text
, word
);
3412 while ((strlen (method
) + 1) >= tmplen
)
3418 tmp
= xrealloc (tmp
, tmplen
);
3420 selector
= strchr (method
, ' ');
3421 if (selector
!= NULL
)
3424 category
= strchr (method
, '(');
3426 if ((category
!= NULL
) && (selector
!= NULL
))
3428 memcpy (tmp
, method
, (category
- method
));
3429 tmp
[category
- method
] = ' ';
3430 memcpy (tmp
+ (category
- method
) + 1, selector
, strlen (selector
) + 1);
3431 completion_list_add_name (tmp
, sym_text
, sym_text_len
, text
, word
);
3432 if (sym_text
[0] == '[')
3433 completion_list_add_name (tmp
+ 1, sym_text
, sym_text_len
, text
, word
);
3436 if (selector
!= NULL
)
3438 /* Complete on selector only. */
3439 strcpy (tmp
, selector
);
3440 tmp2
= strchr (tmp
, ']');
3444 completion_list_add_name (tmp
, sym_text
, sym_text_len
, text
, word
);
3448 /* Break the non-quoted text based on the characters which are in
3449 symbols. FIXME: This should probably be language-specific. */
3452 language_search_unquoted_string (char *text
, char *p
)
3454 for (; p
> text
; --p
)
3456 if (isalnum (p
[-1]) || p
[-1] == '_' || p
[-1] == '\0')
3460 if ((current_language
->la_language
== language_objc
))
3462 if (p
[-1] == ':') /* might be part of a method name */
3464 else if (p
[-1] == '[' && (p
[-2] == '-' || p
[-2] == '+'))
3465 p
-= 2; /* beginning of a method name */
3466 else if (p
[-1] == ' ' || p
[-1] == '(' || p
[-1] == ')')
3467 { /* might be part of a method name */
3470 /* Seeing a ' ' or a '(' is not conclusive evidence
3471 that we are in the middle of a method name. However,
3472 finding "-[" or "+[" should be pretty un-ambiguous.
3473 Unfortunately we have to find it now to decide. */
3476 if (isalnum (t
[-1]) || t
[-1] == '_' ||
3477 t
[-1] == ' ' || t
[-1] == ':' ||
3478 t
[-1] == '(' || t
[-1] == ')')
3483 if (t
[-1] == '[' && (t
[-2] == '-' || t
[-2] == '+'))
3484 p
= t
- 2; /* method name detected */
3485 /* else we leave with p unchanged */
3495 /* Return a NULL terminated array of all symbols (regardless of class)
3496 which begin by matching TEXT. If the answer is no symbols, then
3497 the return value is an array which contains only a NULL pointer.
3499 Problem: All of the symbols have to be copied because readline frees them.
3500 I'm not going to worry about this; hopefully there won't be that many. */
3503 make_symbol_completion_list (char *text
, char *word
)
3507 struct partial_symtab
*ps
;
3508 struct minimal_symbol
*msymbol
;
3509 struct objfile
*objfile
;
3510 struct block
*b
, *surrounding_static_block
= 0;
3511 struct dict_iterator iter
;
3513 struct partial_symbol
**psym
;
3514 /* The symbol we are completing on. Points in same buffer as text. */
3516 /* Length of sym_text. */
3519 /* Now look for the symbol we are supposed to complete on.
3520 FIXME: This should be language-specific. */
3524 char *quote_pos
= NULL
;
3526 /* First see if this is a quoted string. */
3528 for (p
= text
; *p
!= '\0'; ++p
)
3530 if (quote_found
!= '\0')
3532 if (*p
== quote_found
)
3533 /* Found close quote. */
3535 else if (*p
== '\\' && p
[1] == quote_found
)
3536 /* A backslash followed by the quote character
3537 doesn't end the string. */
3540 else if (*p
== '\'' || *p
== '"')
3546 if (quote_found
== '\'')
3547 /* A string within single quotes can be a symbol, so complete on it. */
3548 sym_text
= quote_pos
+ 1;
3549 else if (quote_found
== '"')
3550 /* A double-quoted string is never a symbol, nor does it make sense
3551 to complete it any other way. */
3553 return_val
= (char **) xmalloc (sizeof (char *));
3554 return_val
[0] = NULL
;
3559 /* It is not a quoted string. Break it based on the characters
3560 which are in symbols. */
3563 if (isalnum (p
[-1]) || p
[-1] == '_' || p
[-1] == '\0')
3572 sym_text_len
= strlen (sym_text
);
3574 return_val_size
= 100;
3575 return_val_index
= 0;
3576 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
3577 return_val
[0] = NULL
;
3579 /* Look through the partial symtabs for all symbols which begin
3580 by matching SYM_TEXT. Add each one that you find to the list. */
3582 ALL_PSYMTABS (objfile
, ps
)
3584 /* If the psymtab's been read in we'll get it when we search
3585 through the blockvector. */
3589 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
3590 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
3591 + ps
->n_global_syms
);
3594 /* If interrupted, then quit. */
3596 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3599 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
3600 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
3601 + ps
->n_static_syms
);
3605 COMPLETION_LIST_ADD_SYMBOL (*psym
, sym_text
, sym_text_len
, text
, word
);
3609 /* At this point scan through the misc symbol vectors and add each
3610 symbol you find to the list. Eventually we want to ignore
3611 anything that isn't a text symbol (everything else will be
3612 handled by the psymtab code above). */
3614 ALL_MSYMBOLS (objfile
, msymbol
)
3617 COMPLETION_LIST_ADD_SYMBOL (msymbol
, sym_text
, sym_text_len
, text
, word
);
3619 completion_list_objc_symbol (msymbol
, sym_text
, sym_text_len
, text
, word
);
3622 /* Search upwards from currently selected frame (so that we can
3623 complete on local vars. */
3625 for (b
= get_selected_block (0); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
3627 if (!BLOCK_SUPERBLOCK (b
))
3629 surrounding_static_block
= b
; /* For elmin of dups */
3632 /* Also catch fields of types defined in this places which match our
3633 text string. Only complete on types visible from current context. */
3635 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
3638 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3639 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
)
3641 struct type
*t
= SYMBOL_TYPE (sym
);
3642 enum type_code c
= TYPE_CODE (t
);
3644 if (c
== TYPE_CODE_UNION
|| c
== TYPE_CODE_STRUCT
)
3646 for (j
= TYPE_N_BASECLASSES (t
); j
< TYPE_NFIELDS (t
); j
++)
3648 if (TYPE_FIELD_NAME (t
, j
))
3650 completion_list_add_name (TYPE_FIELD_NAME (t
, j
),
3651 sym_text
, sym_text_len
, text
, word
);
3659 /* Go through the symtabs and check the externs and statics for
3660 symbols which match. */
3662 ALL_PRIMARY_SYMTABS (objfile
, s
)
3665 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3666 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
3668 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3672 ALL_PRIMARY_SYMTABS (objfile
, s
)
3675 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3676 /* Don't do this block twice. */
3677 if (b
== surrounding_static_block
)
3679 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
3681 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3685 return (return_val
);
3688 /* Like make_symbol_completion_list, but returns a list of symbols
3689 defined in a source file FILE. */
3692 make_file_symbol_completion_list (char *text
, char *word
, char *srcfile
)
3697 struct dict_iterator iter
;
3698 /* The symbol we are completing on. Points in same buffer as text. */
3700 /* Length of sym_text. */
3703 /* Now look for the symbol we are supposed to complete on.
3704 FIXME: This should be language-specific. */
3708 char *quote_pos
= NULL
;
3710 /* First see if this is a quoted string. */
3712 for (p
= text
; *p
!= '\0'; ++p
)
3714 if (quote_found
!= '\0')
3716 if (*p
== quote_found
)
3717 /* Found close quote. */
3719 else if (*p
== '\\' && p
[1] == quote_found
)
3720 /* A backslash followed by the quote character
3721 doesn't end the string. */
3724 else if (*p
== '\'' || *p
== '"')
3730 if (quote_found
== '\'')
3731 /* A string within single quotes can be a symbol, so complete on it. */
3732 sym_text
= quote_pos
+ 1;
3733 else if (quote_found
== '"')
3734 /* A double-quoted string is never a symbol, nor does it make sense
3735 to complete it any other way. */
3737 return_val
= (char **) xmalloc (sizeof (char *));
3738 return_val
[0] = NULL
;
3743 /* Not a quoted string. */
3744 sym_text
= language_search_unquoted_string (text
, p
);
3748 sym_text_len
= strlen (sym_text
);
3750 return_val_size
= 10;
3751 return_val_index
= 0;
3752 return_val
= (char **) xmalloc ((return_val_size
+ 1) * sizeof (char *));
3753 return_val
[0] = NULL
;
3755 /* Find the symtab for SRCFILE (this loads it if it was not yet read
3757 s
= lookup_symtab (srcfile
);
3760 /* Maybe they typed the file with leading directories, while the
3761 symbol tables record only its basename. */
3762 const char *tail
= lbasename (srcfile
);
3765 s
= lookup_symtab (tail
);
3768 /* If we have no symtab for that file, return an empty list. */
3770 return (return_val
);
3772 /* Go through this symtab and check the externs and statics for
3773 symbols which match. */
3775 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3776 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
3778 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3781 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
3782 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
3784 COMPLETION_LIST_ADD_SYMBOL (sym
, sym_text
, sym_text_len
, text
, word
);
3787 return (return_val
);
3790 /* A helper function for make_source_files_completion_list. It adds
3791 another file name to a list of possible completions, growing the
3792 list as necessary. */
3795 add_filename_to_list (const char *fname
, char *text
, char *word
,
3796 char ***list
, int *list_used
, int *list_alloced
)
3799 size_t fnlen
= strlen (fname
);
3801 if (*list_used
+ 1 >= *list_alloced
)
3804 *list
= (char **) xrealloc ((char *) *list
,
3805 *list_alloced
* sizeof (char *));
3810 /* Return exactly fname. */
3811 new = xmalloc (fnlen
+ 5);
3812 strcpy (new, fname
);
3814 else if (word
> text
)
3816 /* Return some portion of fname. */
3817 new = xmalloc (fnlen
+ 5);
3818 strcpy (new, fname
+ (word
- text
));
3822 /* Return some of TEXT plus fname. */
3823 new = xmalloc (fnlen
+ (text
- word
) + 5);
3824 strncpy (new, word
, text
- word
);
3825 new[text
- word
] = '\0';
3826 strcat (new, fname
);
3828 (*list
)[*list_used
] = new;
3829 (*list
)[++*list_used
] = NULL
;
3833 not_interesting_fname (const char *fname
)
3835 static const char *illegal_aliens
[] = {
3836 "_globals_", /* inserted by coff_symtab_read */
3841 for (i
= 0; illegal_aliens
[i
]; i
++)
3843 if (strcmp (fname
, illegal_aliens
[i
]) == 0)
3849 /* Return a NULL terminated array of all source files whose names
3850 begin with matching TEXT. The file names are looked up in the
3851 symbol tables of this program. If the answer is no matchess, then
3852 the return value is an array which contains only a NULL pointer. */
3855 make_source_files_completion_list (char *text
, char *word
)
3858 struct partial_symtab
*ps
;
3859 struct objfile
*objfile
;
3861 int list_alloced
= 1;
3863 size_t text_len
= strlen (text
);
3864 char **list
= (char **) xmalloc (list_alloced
* sizeof (char *));
3865 const char *base_name
;
3869 if (!have_full_symbols () && !have_partial_symbols ())
3872 ALL_SYMTABS (objfile
, s
)
3874 if (not_interesting_fname (s
->filename
))
3876 if (!filename_seen (s
->filename
, 1, &first
)
3877 #if HAVE_DOS_BASED_FILE_SYSTEM
3878 && strncasecmp (s
->filename
, text
, text_len
) == 0
3880 && strncmp (s
->filename
, text
, text_len
) == 0
3884 /* This file matches for a completion; add it to the current
3886 add_filename_to_list (s
->filename
, text
, word
,
3887 &list
, &list_used
, &list_alloced
);
3891 /* NOTE: We allow the user to type a base name when the
3892 debug info records leading directories, but not the other
3893 way around. This is what subroutines of breakpoint
3894 command do when they parse file names. */
3895 base_name
= lbasename (s
->filename
);
3896 if (base_name
!= s
->filename
3897 && !filename_seen (base_name
, 1, &first
)
3898 #if HAVE_DOS_BASED_FILE_SYSTEM
3899 && strncasecmp (base_name
, text
, text_len
) == 0
3901 && strncmp (base_name
, text
, text_len
) == 0
3904 add_filename_to_list (base_name
, text
, word
,
3905 &list
, &list_used
, &list_alloced
);
3909 ALL_PSYMTABS (objfile
, ps
)
3911 if (not_interesting_fname (ps
->filename
))
3915 if (!filename_seen (ps
->filename
, 1, &first
)
3916 #if HAVE_DOS_BASED_FILE_SYSTEM
3917 && strncasecmp (ps
->filename
, text
, text_len
) == 0
3919 && strncmp (ps
->filename
, text
, text_len
) == 0
3923 /* This file matches for a completion; add it to the
3924 current list of matches. */
3925 add_filename_to_list (ps
->filename
, text
, word
,
3926 &list
, &list_used
, &list_alloced
);
3931 base_name
= lbasename (ps
->filename
);
3932 if (base_name
!= ps
->filename
3933 && !filename_seen (base_name
, 1, &first
)
3934 #if HAVE_DOS_BASED_FILE_SYSTEM
3935 && strncasecmp (base_name
, text
, text_len
) == 0
3937 && strncmp (base_name
, text
, text_len
) == 0
3940 add_filename_to_list (base_name
, text
, word
,
3941 &list
, &list_used
, &list_alloced
);
3949 /* Determine if PC is in the prologue of a function. The prologue is the area
3950 between the first instruction of a function, and the first executable line.
3951 Returns 1 if PC *might* be in prologue, 0 if definately *not* in prologue.
3953 If non-zero, func_start is where we think the prologue starts, possibly
3954 by previous examination of symbol table information.
3958 in_prologue (CORE_ADDR pc
, CORE_ADDR func_start
)
3960 struct symtab_and_line sal
;
3961 CORE_ADDR func_addr
, func_end
;
3963 /* We have several sources of information we can consult to figure
3965 - Compilers usually emit line number info that marks the prologue
3966 as its own "source line". So the ending address of that "line"
3967 is the end of the prologue. If available, this is the most
3969 - The minimal symbols and partial symbols, which can usually tell
3970 us the starting and ending addresses of a function.
3971 - If we know the function's start address, we can call the
3972 architecture-defined gdbarch_skip_prologue function to analyze the
3973 instruction stream and guess where the prologue ends.
3974 - Our `func_start' argument; if non-zero, this is the caller's
3975 best guess as to the function's entry point. At the time of
3976 this writing, handle_inferior_event doesn't get this right, so
3977 it should be our last resort. */
3979 /* Consult the partial symbol table, to find which function
3981 if (! find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
3983 CORE_ADDR prologue_end
;
3985 /* We don't even have minsym information, so fall back to using
3986 func_start, if given. */
3988 return 1; /* We *might* be in a prologue. */
3990 prologue_end
= gdbarch_skip_prologue (current_gdbarch
, func_start
);
3992 return func_start
<= pc
&& pc
< prologue_end
;
3995 /* If we have line number information for the function, that's
3996 usually pretty reliable. */
3997 sal
= find_pc_line (func_addr
, 0);
3999 /* Now sal describes the source line at the function's entry point,
4000 which (by convention) is the prologue. The end of that "line",
4001 sal.end, is the end of the prologue.
4003 Note that, for functions whose source code is all on a single
4004 line, the line number information doesn't always end up this way.
4005 So we must verify that our purported end-of-prologue address is
4006 *within* the function, not at its start or end. */
4008 || sal
.end
<= func_addr
4009 || func_end
<= sal
.end
)
4011 /* We don't have any good line number info, so use the minsym
4012 information, together with the architecture-specific prologue
4014 CORE_ADDR prologue_end
= gdbarch_skip_prologue
4015 (current_gdbarch
, func_addr
);
4017 return func_addr
<= pc
&& pc
< prologue_end
;
4020 /* We have line number info, and it looks good. */
4021 return func_addr
<= pc
&& pc
< sal
.end
;
4024 /* Given PC at the function's start address, attempt to find the
4025 prologue end using SAL information. Return zero if the skip fails.
4027 A non-optimized prologue traditionally has one SAL for the function
4028 and a second for the function body. A single line function has
4029 them both pointing at the same line.
4031 An optimized prologue is similar but the prologue may contain
4032 instructions (SALs) from the instruction body. Need to skip those
4033 while not getting into the function body.
4035 The functions end point and an increasing SAL line are used as
4036 indicators of the prologue's endpoint.
4038 This code is based on the function refine_prologue_limit (versions
4039 found in both ia64 and ppc). */
4042 skip_prologue_using_sal (CORE_ADDR func_addr
)
4044 struct symtab_and_line prologue_sal
;
4048 /* Get an initial range for the function. */
4049 find_pc_partial_function (func_addr
, NULL
, &start_pc
, &end_pc
);
4050 start_pc
+= gdbarch_deprecated_function_start_offset (current_gdbarch
);
4052 prologue_sal
= find_pc_line (start_pc
, 0);
4053 if (prologue_sal
.line
!= 0)
4055 /* If there is only one sal that covers the entire function,
4056 then it is probably a single line function, like
4058 if (prologue_sal
.end
>= end_pc
)
4060 while (prologue_sal
.end
< end_pc
)
4062 struct symtab_and_line sal
;
4064 sal
= find_pc_line (prologue_sal
.end
, 0);
4067 /* Assume that a consecutive SAL for the same (or larger)
4068 line mark the prologue -> body transition. */
4069 if (sal
.line
>= prologue_sal
.line
)
4071 /* The case in which compiler's optimizer/scheduler has
4072 moved instructions into the prologue. We look ahead in
4073 the function looking for address ranges whose
4074 corresponding line number is less the first one that we
4075 found for the function. This is more conservative then
4076 refine_prologue_limit which scans a large number of SALs
4077 looking for any in the prologue */
4081 return prologue_sal
.end
;
4084 struct symtabs_and_lines
4085 decode_line_spec (char *string
, int funfirstline
)
4087 struct symtabs_and_lines sals
;
4088 struct symtab_and_line cursal
;
4091 error (_("Empty line specification."));
4093 /* We use whatever is set as the current source line. We do not try
4094 and get a default or it will recursively call us! */
4095 cursal
= get_current_source_symtab_and_line ();
4097 sals
= decode_line_1 (&string
, funfirstline
,
4098 cursal
.symtab
, cursal
.line
,
4099 (char ***) NULL
, NULL
);
4102 error (_("Junk at end of line specification: %s"), string
);
4107 static char *name_of_main
;
4110 set_main_name (const char *name
)
4112 if (name_of_main
!= NULL
)
4114 xfree (name_of_main
);
4115 name_of_main
= NULL
;
4119 name_of_main
= xstrdup (name
);
4123 /* Deduce the name of the main procedure, and set NAME_OF_MAIN
4127 find_main_name (void)
4129 char *new_main_name
;
4131 /* Try to see if the main procedure is in Ada. */
4132 /* FIXME: brobecker/2005-03-07: Another way of doing this would
4133 be to add a new method in the language vector, and call this
4134 method for each language until one of them returns a non-empty
4135 name. This would allow us to remove this hard-coded call to
4136 an Ada function. It is not clear that this is a better approach
4137 at this point, because all methods need to be written in a way
4138 such that false positives never be returned. For instance, it is
4139 important that a method does not return a wrong name for the main
4140 procedure if the main procedure is actually written in a different
4141 language. It is easy to guaranty this with Ada, since we use a
4142 special symbol generated only when the main in Ada to find the name
4143 of the main procedure. It is difficult however to see how this can
4144 be guarantied for languages such as C, for instance. This suggests
4145 that order of call for these methods becomes important, which means
4146 a more complicated approach. */
4147 new_main_name
= ada_main_name ();
4148 if (new_main_name
!= NULL
)
4150 set_main_name (new_main_name
);
4154 /* The languages above didn't identify the name of the main procedure.
4155 Fallback to "main". */
4156 set_main_name ("main");
4162 if (name_of_main
== NULL
)
4165 return name_of_main
;
4168 /* Handle ``executable_changed'' events for the symtab module. */
4171 symtab_observer_executable_changed (void *unused
)
4173 /* NAME_OF_MAIN may no longer be the same, so reset it for now. */
4174 set_main_name (NULL
);
4177 /* Helper to expand_line_sal below. Appends new sal to SAL,
4178 initializing it from SYMTAB, LINENO and PC. */
4180 append_expanded_sal (struct symtabs_and_lines
*sal
,
4181 struct symtab
*symtab
,
4182 int lineno
, CORE_ADDR pc
)
4184 CORE_ADDR func_addr
, func_end
;
4186 sal
->sals
= xrealloc (sal
->sals
,
4187 sizeof (sal
->sals
[0])
4188 * (sal
->nelts
+ 1));
4189 init_sal (sal
->sals
+ sal
->nelts
);
4190 sal
->sals
[sal
->nelts
].symtab
= symtab
;
4191 sal
->sals
[sal
->nelts
].section
= NULL
;
4192 sal
->sals
[sal
->nelts
].end
= 0;
4193 sal
->sals
[sal
->nelts
].line
= lineno
;
4194 sal
->sals
[sal
->nelts
].pc
= pc
;
4198 /* Compute a set of all sals in
4199 the entire program that correspond to same file
4200 and line as SAL and return those. If there
4201 are several sals that belong to the same block,
4202 only one sal for the block is included in results. */
4204 struct symtabs_and_lines
4205 expand_line_sal (struct symtab_and_line sal
)
4207 struct symtabs_and_lines ret
, this_line
;
4209 struct objfile
*objfile
;
4210 struct partial_symtab
*psymtab
;
4211 struct symtab
*symtab
;
4214 struct block
**blocks
= NULL
;
4220 if (sal
.symtab
== NULL
|| sal
.line
== 0 || sal
.pc
!= 0)
4222 ret
.sals
= xmalloc (sizeof (struct symtab_and_line
));
4229 struct linetable_entry
*best_item
= 0;
4230 struct symtab
*best_symtab
= 0;
4235 /* We meed to find all symtabs for a file which name
4236 is described by sal. We cannot just directly
4237 iterate over symtabs, since a symtab might not be
4238 yet created. We also cannot iterate over psymtabs,
4239 calling PSYMTAB_TO_SYMTAB and working on that symtab,
4240 since PSYMTAB_TO_SYMTAB will return NULL for psymtab
4241 corresponding to an included file. Therefore, we do
4242 first pass over psymtabs, reading in those with
4243 the right name. Then, we iterate over symtabs, knowing
4244 that all symtabs we're interested in are loaded. */
4246 ALL_PSYMTABS (objfile
, psymtab
)
4248 if (strcmp (sal
.symtab
->filename
,
4249 psymtab
->filename
) == 0)
4250 PSYMTAB_TO_SYMTAB (psymtab
);
4254 /* For each symtab, we add all pcs to ret.sals. I'm actually
4255 not sure what to do if we have exact match in one symtab,
4256 and non-exact match on another symtab.
4258 ALL_SYMTABS (objfile
, symtab
)
4260 if (strcmp (sal
.symtab
->filename
,
4261 symtab
->filename
) == 0)
4263 struct linetable
*l
;
4265 l
= LINETABLE (symtab
);
4270 for (j
= 0; j
< len
; j
++)
4272 struct linetable_entry
*item
= &(l
->item
[j
]);
4274 if (item
->line
== lineno
)
4277 append_expanded_sal (&ret
, symtab
, lineno
, item
->pc
);
4279 else if (!exact
&& item
->line
> lineno
4280 && (best_item
== NULL
|| item
->line
< best_item
->line
))
4284 best_symtab
= symtab
;
4289 if (!exact
&& best_item
)
4290 append_expanded_sal (&ret
, best_symtab
, lineno
, best_item
->pc
);
4293 /* For optimized code, compiler can scatter one source line accross
4294 disjoint ranges of PC values, even when no duplicate functions
4295 or inline functions are involved. For example, 'for (;;)' inside
4296 non-template non-inline non-ctor-or-dtor function can result
4297 in two PC ranges. In this case, we don't want to set breakpoint
4298 on first PC of each range. To filter such cases, we use containing
4299 blocks -- for each PC found above we see if there are other PCs
4300 that are in the same block. If yes, the other PCs are filtered out. */
4302 filter
= xmalloc (ret
.nelts
* sizeof (int));
4303 blocks
= xmalloc (ret
.nelts
* sizeof (struct block
*));
4304 for (i
= 0; i
< ret
.nelts
; ++i
)
4307 blocks
[i
] = block_for_pc (ret
.sals
[i
].pc
);
4310 for (i
= 0; i
< ret
.nelts
; ++i
)
4311 if (blocks
[i
] != NULL
)
4312 for (j
= i
+1; j
< ret
.nelts
; ++j
)
4313 if (blocks
[j
] == blocks
[i
])
4321 struct symtab_and_line
*final
=
4322 xmalloc (sizeof (struct symtab_and_line
) * (ret
.nelts
-deleted
));
4324 for (i
= 0, j
= 0; i
< ret
.nelts
; ++i
)
4326 final
[j
++] = ret
.sals
[i
];
4328 ret
.nelts
-= deleted
;
4338 _initialize_symtab (void)
4340 add_info ("variables", variables_info
, _("\
4341 All global and static variable names, or those matching REGEXP."));
4343 add_com ("whereis", class_info
, variables_info
, _("\
4344 All global and static variable names, or those matching REGEXP."));
4346 add_info ("functions", functions_info
,
4347 _("All function names, or those matching REGEXP."));
4350 /* FIXME: This command has at least the following problems:
4351 1. It prints builtin types (in a very strange and confusing fashion).
4352 2. It doesn't print right, e.g. with
4353 typedef struct foo *FOO
4354 type_print prints "FOO" when we want to make it (in this situation)
4355 print "struct foo *".
4356 I also think "ptype" or "whatis" is more likely to be useful (but if
4357 there is much disagreement "info types" can be fixed). */
4358 add_info ("types", types_info
,
4359 _("All type names, or those matching REGEXP."));
4361 add_info ("sources", sources_info
,
4362 _("Source files in the program."));
4364 add_com ("rbreak", class_breakpoint
, rbreak_command
,
4365 _("Set a breakpoint for all functions matching REGEXP."));
4369 add_com ("lf", class_info
, sources_info
,
4370 _("Source files in the program"));
4371 add_com ("lg", class_info
, variables_info
, _("\
4372 All global and static variable names, or those matching REGEXP."));
4375 /* Initialize the one built-in type that isn't language dependent... */
4376 builtin_type_error
= init_type (TYPE_CODE_ERROR
, 0, 0,
4377 "<unknown type>", (struct objfile
*) NULL
);
4379 observer_attach_executable_changed (symtab_observer_executable_changed
);