1 /* Partial symbol tables.
3 Copyright (C) 2009-2012 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_assert.h"
26 #include "filenames.h"
33 #include "readline/readline.h"
34 #include "gdb_regex.h"
35 #include "dictionary.h"
37 #include "cp-support.h"
40 #define DEV_TTY "/dev/tty"
45 struct bcache
*bcache
;
48 static struct partial_symbol
*match_partial_symbol (struct partial_symtab
*,
50 const char *, domain_enum
,
51 symbol_compare_ftype
*,
52 symbol_compare_ftype
*);
54 static struct partial_symbol
*lookup_partial_symbol (struct partial_symtab
*,
58 static char *psymtab_to_fullname (struct partial_symtab
*ps
);
60 static struct partial_symbol
*find_pc_sect_psymbol (struct partial_symtab
*,
62 struct obj_section
*);
64 static struct partial_symbol
*fixup_psymbol_section (struct partial_symbol
66 struct objfile
*objfile
);
68 static struct symtab
*psymtab_to_symtab (struct partial_symtab
*pst
);
70 /* Ensure that the partial symbols for OBJFILE have been loaded. This
71 function always returns its argument, as a convenience. */
74 require_partial_symbols (struct objfile
*objfile
, int verbose
)
76 if ((objfile
->flags
& OBJF_PSYMTABS_READ
) == 0)
78 objfile
->flags
|= OBJF_PSYMTABS_READ
;
80 if (objfile
->sf
->sym_read_psymbols
)
84 printf_unfiltered (_("Reading symbols from %s..."),
86 gdb_flush (gdb_stdout
);
88 (*objfile
->sf
->sym_read_psymbols
) (objfile
);
91 if (!objfile_has_symbols (objfile
))
94 printf_unfiltered (_("(no debugging symbols found)..."));
98 printf_unfiltered (_("done.\n"));
106 /* Traverse all psymtabs in one objfile, requiring that the psymtabs
109 #define ALL_OBJFILE_PSYMTABS_REQUIRED(objfile, p) \
110 for ((p) = require_partial_symbols (objfile, 1)->psymtabs; \
114 /* We want to make sure this file always requires psymtabs. */
116 #undef ALL_OBJFILE_PSYMTABS
118 /* Traverse all psymtabs in all objfiles. */
120 #define ALL_PSYMTABS(objfile, p) \
121 ALL_OBJFILES (objfile) \
122 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
124 /* Helper function for partial_map_symtabs_matching_filename that
125 expands the symtabs and calls the iterator. */
128 partial_map_expand_apply (struct objfile
*objfile
,
130 const char *full_path
,
131 const char *real_path
,
132 struct partial_symtab
*pst
,
133 int (*callback
) (struct symtab
*, void *),
136 struct symtab
*last_made
= objfile
->symtabs
;
138 /* Shared psymtabs should never be seen here. Instead they should
139 be handled properly by the caller. */
140 gdb_assert (pst
->user
== NULL
);
142 /* Don't visit already-expanded psymtabs. */
146 /* This may expand more than one symtab, and we want to iterate over
148 psymtab_to_symtab (pst
);
150 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
151 objfile
->symtabs
, last_made
);
154 /* Implementation of the map_symtabs_matching_filename method. */
157 partial_map_symtabs_matching_filename (struct objfile
*objfile
,
159 const char *full_path
,
160 const char *real_path
,
161 int (*callback
) (struct symtab
*,
165 struct partial_symtab
*pst
;
166 const char *name_basename
= lbasename (name
);
167 int name_len
= strlen (name
);
168 int is_abs
= IS_ABSOLUTE_PATH (name
);
170 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
172 /* We can skip shared psymtabs here, because any file name will be
173 attached to the unshared psymtab. */
174 if (pst
->user
!= NULL
)
177 /* Anonymous psymtabs don't have a file name. */
181 if (FILENAME_CMP (name
, pst
->filename
) == 0
182 || (!is_abs
&& compare_filenames_for_search (pst
->filename
,
185 if (partial_map_expand_apply (objfile
, name
, full_path
, real_path
,
186 pst
, callback
, data
))
190 /* Before we invoke realpath, which can get expensive when many
191 files are involved, do a quick comparison of the basenames. */
192 if (! basenames_may_differ
193 && FILENAME_CMP (name_basename
, lbasename (pst
->filename
)) != 0)
196 /* If the user gave us an absolute path, try to find the file in
197 this symtab and use its absolute path. */
198 if (full_path
!= NULL
)
200 psymtab_to_fullname (pst
);
201 if (pst
->fullname
!= NULL
202 && (FILENAME_CMP (full_path
, pst
->fullname
) == 0
203 || (!is_abs
&& compare_filenames_for_search (pst
->fullname
,
206 if (partial_map_expand_apply (objfile
, name
, full_path
, real_path
,
207 pst
, callback
, data
))
212 if (real_path
!= NULL
)
215 psymtab_to_fullname (pst
);
216 if (pst
->fullname
!= NULL
)
218 rp
= gdb_realpath (pst
->fullname
);
219 make_cleanup (xfree
, rp
);
222 && (FILENAME_CMP (real_path
, rp
) == 0
223 || (!is_abs
&& compare_filenames_for_search (real_path
,
226 if (partial_map_expand_apply (objfile
, name
, full_path
, real_path
,
227 pst
, callback
, data
))
236 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
237 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
239 static struct partial_symtab
*
240 find_pc_sect_psymtab_closer (CORE_ADDR pc
, struct obj_section
*section
,
241 struct partial_symtab
*pst
,
242 struct minimal_symbol
*msymbol
)
244 struct objfile
*objfile
= pst
->objfile
;
245 struct partial_symtab
*tpst
;
246 struct partial_symtab
*best_pst
= pst
;
247 CORE_ADDR best_addr
= pst
->textlow
;
249 gdb_assert (!pst
->psymtabs_addrmap_supported
);
251 /* An objfile that has its functions reordered might have
252 many partial symbol tables containing the PC, but
253 we want the partial symbol table that contains the
254 function containing the PC. */
255 if (!(objfile
->flags
& OBJF_REORDERED
) &&
256 section
== 0) /* Can't validate section this way. */
262 /* The code range of partial symtabs sometimes overlap, so, in
263 the loop below, we need to check all partial symtabs and
264 find the one that fits better for the given PC address. We
265 select the partial symtab that contains a symbol whose
266 address is closest to the PC address. By closest we mean
267 that find_pc_sect_symbol returns the symbol with address
268 that is closest and still less than the given PC. */
269 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
271 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
273 struct partial_symbol
*p
;
276 /* NOTE: This assumes that every psymbol has a
277 corresponding msymbol, which is not necessarily
278 true; the debug info might be much richer than the
279 object's symbol table. */
280 p
= find_pc_sect_psymbol (tpst
, pc
, section
);
282 && SYMBOL_VALUE_ADDRESS (p
)
283 == SYMBOL_VALUE_ADDRESS (msymbol
))
286 /* Also accept the textlow value of a psymtab as a
287 "symbol", to provide some support for partial
288 symbol tables with line information but no debug
289 symbols (e.g. those produced by an assembler). */
291 this_addr
= SYMBOL_VALUE_ADDRESS (p
);
293 this_addr
= tpst
->textlow
;
295 /* Check whether it is closer than our current
296 BEST_ADDR. Since this symbol address is
297 necessarily lower or equal to PC, the symbol closer
298 to PC is the symbol which address is the highest.
299 This way we return the psymtab which contains such
300 best match symbol. This can help in cases where the
301 symbol information/debuginfo is not complete, like
302 for instance on IRIX6 with gcc, where no debug info
303 is emitted for statics. (See also the nodebug.exp
305 if (this_addr
> best_addr
)
307 best_addr
= this_addr
;
315 /* Find which partial symtab contains PC and SECTION. Return 0 if
316 none. We return the psymtab that contains a symbol whose address
317 exactly matches PC, or, if we cannot find an exact match, the
318 psymtab that contains a symbol whose address is closest to PC. */
319 static struct partial_symtab
*
320 find_pc_sect_psymtab (struct objfile
*objfile
, CORE_ADDR pc
,
321 struct obj_section
*section
,
322 struct minimal_symbol
*msymbol
)
324 struct partial_symtab
*pst
;
326 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
327 than the later used TEXTLOW/TEXTHIGH one. */
329 if (objfile
->psymtabs_addrmap
!= NULL
)
331 pst
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
334 /* FIXME: addrmaps currently do not handle overlayed sections,
335 so fall back to the non-addrmap case if we're debugging
336 overlays and the addrmap returned the wrong section. */
337 if (overlay_debugging
&& msymbol
&& section
)
339 struct partial_symbol
*p
;
341 /* NOTE: This assumes that every psymbol has a
342 corresponding msymbol, which is not necessarily
343 true; the debug info might be much richer than the
344 object's symbol table. */
345 p
= find_pc_sect_psymbol (pst
, pc
, section
);
347 || SYMBOL_VALUE_ADDRESS (p
)
348 != SYMBOL_VALUE_ADDRESS (msymbol
))
352 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
353 PSYMTABS_ADDRMAP we used has already the best 1-byte
354 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
355 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
364 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
365 which still have no corresponding full SYMTABs read. But it is not
366 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
369 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
370 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
371 debug info type in single OBJFILE. */
373 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
374 if (!pst
->psymtabs_addrmap_supported
375 && pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
377 struct partial_symtab
*best_pst
;
379 best_pst
= find_pc_sect_psymtab_closer (pc
, section
, pst
, msymbol
);
380 if (best_pst
!= NULL
)
387 static struct symtab
*
388 find_pc_sect_symtab_from_partial (struct objfile
*objfile
,
389 struct minimal_symbol
*msymbol
,
390 CORE_ADDR pc
, struct obj_section
*section
,
393 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
397 if (warn_if_readin
&& ps
->readin
)
398 /* Might want to error() here (in case symtab is corrupt and
399 will cause a core dump), but maybe we can successfully
400 continue, so let's not. */
402 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
403 paddress (get_objfile_arch (ps
->objfile
), pc
));
404 psymtab_to_symtab (ps
);
410 /* Find which partial symbol within a psymtab matches PC and SECTION.
413 static struct partial_symbol
*
414 find_pc_sect_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
,
415 struct obj_section
*section
)
417 struct partial_symbol
*best
= NULL
, *p
, **pp
;
420 gdb_assert (psymtab
!= NULL
);
422 /* Cope with programs that start at address 0. */
423 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
425 /* Search the global symbols as well as the static symbols, so that
426 find_pc_partial_function doesn't use a minimal symbol and thus
427 cache a bad endaddr. */
428 for (pp
= psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
429 (pp
- (psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
430 < psymtab
->n_global_syms
);
434 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
435 && SYMBOL_CLASS (p
) == LOC_BLOCK
436 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
437 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
438 || (psymtab
->textlow
== 0
439 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
441 if (section
) /* Match on a specific section. */
443 fixup_psymbol_section (p
, psymtab
->objfile
);
444 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p
), section
))
447 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
452 for (pp
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
453 (pp
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
454 < psymtab
->n_static_syms
);
458 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
459 && SYMBOL_CLASS (p
) == LOC_BLOCK
460 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
461 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
462 || (psymtab
->textlow
== 0
463 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
465 if (section
) /* Match on a specific section. */
467 fixup_psymbol_section (p
, psymtab
->objfile
);
468 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p
), section
))
471 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
479 static struct partial_symbol
*
480 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
487 if (SYMBOL_OBJ_SECTION (psym
))
490 gdb_assert (objfile
);
492 switch (SYMBOL_CLASS (psym
))
497 addr
= SYMBOL_VALUE_ADDRESS (psym
);
500 /* Nothing else will be listed in the minsyms -- no use looking
505 fixup_section (&psym
->ginfo
, addr
, objfile
);
510 static struct symtab
*
511 lookup_symbol_aux_psymtabs (struct objfile
*objfile
,
512 int block_index
, const char *name
,
513 const domain_enum domain
)
515 struct partial_symtab
*ps
;
516 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
517 struct symtab
*stab_best
= NULL
;
519 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
521 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, psymtab_index
, domain
))
523 struct symbol
*sym
= NULL
;
524 struct symtab
*stab
= psymtab_to_symtab (ps
);
526 /* Some caution must be observed with overloaded functions
527 and methods, since the psymtab will not contain any overload
528 information (but NAME might contain it). */
531 struct blockvector
*bv
= BLOCKVECTOR (stab
);
532 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
534 sym
= lookup_block_symbol (block
, name
, domain
);
537 if (sym
&& strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
539 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
545 /* Keep looking through other psymtabs. */
552 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
553 the global block of PST if GLOBAL, and otherwise the static block.
554 MATCH is the comparison operation that returns true iff MATCH (s,
555 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
556 non-null, the symbols in the block are assumed to be ordered
557 according to it (allowing binary search). It must be compatible
558 with MATCH. Returns the symbol, if found, and otherwise NULL. */
560 static struct partial_symbol
*
561 match_partial_symbol (struct partial_symtab
*pst
, int global
,
562 const char *name
, domain_enum domain
,
563 symbol_compare_ftype
*match
,
564 symbol_compare_ftype
*ordered_compare
)
566 struct partial_symbol
**start
, **psym
;
567 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
568 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
569 int do_linear_search
= 1;
574 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
575 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
577 if (global
&& ordered_compare
) /* Can use a binary search. */
579 do_linear_search
= 0;
581 /* Binary search. This search is guaranteed to end with center
582 pointing at the earliest partial symbol whose name might be
583 correct. At that point *all* partial symbols with an
584 appropriate name will be checked against the correct
588 top
= start
+ length
- 1;
592 center
= bottom
+ (top
- bottom
) / 2;
593 gdb_assert (center
< top
);
594 if (!do_linear_search
595 && (SYMBOL_LANGUAGE (*center
) == language_java
))
596 do_linear_search
= 1;
597 if (ordered_compare (SYMBOL_SEARCH_NAME (*center
), name
) >= 0)
602 gdb_assert (top
== bottom
);
604 while (top
<= real_top
605 && match (SYMBOL_SEARCH_NAME (*top
), name
) == 0)
607 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
608 SYMBOL_DOMAIN (*top
), domain
))
614 /* Can't use a binary search or else we found during the binary search that
615 we should also do a linear search. */
617 if (do_linear_search
)
619 for (psym
= start
; psym
< start
+ length
; psym
++)
621 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
622 SYMBOL_DOMAIN (*psym
), domain
)
623 && match (SYMBOL_SEARCH_NAME (*psym
), name
) == 0)
632 pre_expand_symtabs_matching_psymtabs (struct objfile
*objfile
,
633 enum block_enum block_kind
,
640 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
641 not contain any method/function instance information (since this would
642 force reading type information while reading psymtabs). Therefore,
643 if NAME contains overload information, it must be stripped before searching
646 The caller is responsible for freeing the return result. */
649 psymtab_search_name (const char *name
)
651 switch (current_language
->la_language
)
656 if (strchr (name
, '('))
658 char *ret
= cp_remove_params (name
);
670 return xstrdup (name
);
673 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
674 Check the global symbols if GLOBAL, the static symbols if not. */
676 static struct partial_symbol
*
677 lookup_partial_symbol (struct partial_symtab
*pst
, const char *name
,
678 int global
, domain_enum domain
)
680 struct partial_symbol
**start
, **psym
;
681 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
682 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
683 int do_linear_search
= 1;
685 struct cleanup
*cleanup
;
692 search_name
= psymtab_search_name (name
);
693 cleanup
= make_cleanup (xfree
, search_name
);
695 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
696 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
698 if (global
) /* This means we can use a binary search. */
700 do_linear_search
= 0;
702 /* Binary search. This search is guaranteed to end with center
703 pointing at the earliest partial symbol whose name might be
704 correct. At that point *all* partial symbols with an
705 appropriate name will be checked against the correct
709 top
= start
+ length
- 1;
713 center
= bottom
+ (top
- bottom
) / 2;
715 internal_error (__FILE__
, __LINE__
,
716 _("failed internal consistency check"));
717 if (!do_linear_search
718 && SYMBOL_LANGUAGE (*center
) == language_java
)
720 do_linear_search
= 1;
722 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center
),
732 if (!(top
== bottom
))
733 internal_error (__FILE__
, __LINE__
,
734 _("failed internal consistency check"));
736 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
737 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
738 while (top
>= start
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, search_name
))
741 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
744 while (top
<= real_top
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, search_name
))
746 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
747 SYMBOL_DOMAIN (*top
), domain
))
749 do_cleanups (cleanup
);
756 /* Can't use a binary search or else we found during the binary search that
757 we should also do a linear search. */
759 if (do_linear_search
)
761 for (psym
= start
; psym
< start
+ length
; psym
++)
763 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
764 SYMBOL_DOMAIN (*psym
), domain
)
765 && SYMBOL_MATCHES_SEARCH_NAME (*psym
, search_name
))
767 do_cleanups (cleanup
);
773 do_cleanups (cleanup
);
777 /* Get the symbol table that corresponds to a partial_symtab.
778 This is fast after the first time you do it. */
780 static struct symtab
*
781 psymtab_to_symtab (struct partial_symtab
*pst
)
783 /* If it is a shared psymtab, find an unshared psymtab that includes
784 it. Any such psymtab will do. */
785 while (pst
->user
!= NULL
)
788 /* If it's been looked up before, return it. */
792 /* If it has not yet been read in, read it. */
795 struct cleanup
*back_to
= increment_reading_symtab ();
797 (*pst
->read_symtab
) (pst
);
798 do_cleanups (back_to
);
805 relocate_psymtabs (struct objfile
*objfile
,
806 struct section_offsets
*new_offsets
,
807 struct section_offsets
*delta
)
809 struct partial_symbol
**psym
;
810 struct partial_symtab
*p
;
812 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
814 p
->textlow
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
815 p
->texthigh
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
818 for (psym
= objfile
->global_psymbols
.list
;
819 psym
< objfile
->global_psymbols
.next
;
822 fixup_psymbol_section (*psym
, objfile
);
823 if (SYMBOL_SECTION (*psym
) >= 0)
824 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
825 SYMBOL_SECTION (*psym
));
827 for (psym
= objfile
->static_psymbols
.list
;
828 psym
< objfile
->static_psymbols
.next
;
831 fixup_psymbol_section (*psym
, objfile
);
832 if (SYMBOL_SECTION (*psym
) >= 0)
833 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
834 SYMBOL_SECTION (*psym
));
838 static struct symtab
*
839 find_last_source_symtab_from_partial (struct objfile
*ofp
)
841 struct partial_symtab
*ps
;
842 struct partial_symtab
*cs_pst
= 0;
844 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp
, ps
)
846 const char *name
= ps
->filename
;
847 int len
= strlen (name
);
849 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
850 || strcmp (name
, "<<C++-namespaces>>") == 0)))
858 internal_error (__FILE__
, __LINE__
,
859 _("select_source_symtab: "
860 "readin pst found and no symtabs."));
863 return psymtab_to_symtab (cs_pst
);
869 forget_cached_source_info_partial (struct objfile
*objfile
)
871 struct partial_symtab
*pst
;
873 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
875 if (pst
->fullname
!= NULL
)
877 xfree (pst
->fullname
);
878 pst
->fullname
= NULL
;
884 print_partial_symbols (struct gdbarch
*gdbarch
,
885 struct partial_symbol
**p
, int count
, char *what
,
886 struct ui_file
*outfile
)
888 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
892 fprintf_filtered (outfile
, " `%s'", SYMBOL_LINKAGE_NAME (*p
));
893 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
895 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
897 fputs_filtered (", ", outfile
);
898 switch (SYMBOL_DOMAIN (*p
))
901 fputs_filtered ("undefined domain, ", outfile
);
904 /* This is the usual thing -- don't print it. */
907 fputs_filtered ("struct domain, ", outfile
);
910 fputs_filtered ("label domain, ", outfile
);
913 fputs_filtered ("<invalid domain>, ", outfile
);
916 switch (SYMBOL_CLASS (*p
))
919 fputs_filtered ("undefined", outfile
);
922 fputs_filtered ("constant int", outfile
);
925 fputs_filtered ("static", outfile
);
928 fputs_filtered ("register", outfile
);
931 fputs_filtered ("pass by value", outfile
);
934 fputs_filtered ("pass by reference", outfile
);
936 case LOC_REGPARM_ADDR
:
937 fputs_filtered ("register address parameter", outfile
);
940 fputs_filtered ("stack parameter", outfile
);
943 fputs_filtered ("type", outfile
);
946 fputs_filtered ("label", outfile
);
949 fputs_filtered ("function", outfile
);
951 case LOC_CONST_BYTES
:
952 fputs_filtered ("constant bytes", outfile
);
955 fputs_filtered ("unresolved", outfile
);
957 case LOC_OPTIMIZED_OUT
:
958 fputs_filtered ("optimized out", outfile
);
961 fputs_filtered ("computed at runtime", outfile
);
964 fputs_filtered ("<invalid location>", outfile
);
967 fputs_filtered (", ", outfile
);
968 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (*p
)), outfile
);
969 fprintf_filtered (outfile
, "\n");
975 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
976 struct ui_file
*outfile
)
978 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
981 if (psymtab
->anonymous
)
983 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
988 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
991 fprintf_filtered (outfile
, "(object ");
992 gdb_print_host_address (psymtab
, outfile
);
993 fprintf_filtered (outfile
, ")\n\n");
994 fprintf_unfiltered (outfile
, " Read from object file %s (",
996 gdb_print_host_address (objfile
, outfile
);
997 fprintf_unfiltered (outfile
, ")\n");
1001 fprintf_filtered (outfile
,
1002 " Full symtab was read (at ");
1003 gdb_print_host_address (psymtab
->symtab
, outfile
);
1004 fprintf_filtered (outfile
, " by function at ");
1005 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
1006 fprintf_filtered (outfile
, ")\n");
1009 fprintf_filtered (outfile
, " Relocate symbols by ");
1010 for (i
= 0; i
< psymtab
->objfile
->num_sections
; ++i
)
1013 fprintf_filtered (outfile
, ", ");
1015 fputs_filtered (paddress (gdbarch
,
1016 ANOFFSET (psymtab
->section_offsets
, i
)),
1019 fprintf_filtered (outfile
, "\n");
1021 fprintf_filtered (outfile
, " Symbols cover text addresses ");
1022 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
), outfile
);
1023 fprintf_filtered (outfile
, "-");
1024 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
), outfile
);
1025 fprintf_filtered (outfile
, "\n");
1026 fprintf_filtered (outfile
, " Address map supported - %s.\n",
1027 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
1028 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
1029 psymtab
->number_of_dependencies
);
1030 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1032 fprintf_filtered (outfile
, " %d ", i
);
1033 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
1034 fprintf_filtered (outfile
, " %s\n",
1035 psymtab
->dependencies
[i
]->filename
);
1037 if (psymtab
->user
!= NULL
)
1039 fprintf_filtered (outfile
, " Shared partial symtab with user ");
1040 gdb_print_host_address (psymtab
->user
, outfile
);
1041 fprintf_filtered (outfile
, "\n");
1043 if (psymtab
->n_global_syms
> 0)
1045 print_partial_symbols (gdbarch
,
1046 objfile
->global_psymbols
.list
1047 + psymtab
->globals_offset
,
1048 psymtab
->n_global_syms
, "Global", outfile
);
1050 if (psymtab
->n_static_syms
> 0)
1052 print_partial_symbols (gdbarch
,
1053 objfile
->static_psymbols
.list
1054 + psymtab
->statics_offset
,
1055 psymtab
->n_static_syms
, "Static", outfile
);
1057 fprintf_filtered (outfile
, "\n");
1061 print_psymtab_stats_for_objfile (struct objfile
*objfile
)
1064 struct partial_symtab
*ps
;
1067 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1069 if (ps
->readin
== 0)
1072 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
1076 dump_psymtabs_for_objfile (struct objfile
*objfile
)
1078 struct partial_symtab
*psymtab
;
1080 if (objfile
->psymtabs
)
1082 printf_filtered ("Psymtabs:\n");
1083 for (psymtab
= objfile
->psymtabs
;
1085 psymtab
= psymtab
->next
)
1087 printf_filtered ("%s at ",
1089 gdb_print_host_address (psymtab
, gdb_stdout
);
1090 printf_filtered (", ");
1091 if (psymtab
->objfile
!= objfile
)
1093 printf_filtered ("NOT ON CHAIN! ");
1097 printf_filtered ("\n\n");
1101 /* Look through the partial symtabs for all symbols which begin
1102 by matching FUNC_NAME. Make sure we read that symbol table in. */
1105 read_symtabs_for_function (struct objfile
*objfile
, const char *func_name
)
1107 struct partial_symtab
*ps
;
1109 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1114 if ((lookup_partial_symbol (ps
, func_name
, 1, VAR_DOMAIN
)
1116 || (lookup_partial_symbol (ps
, func_name
, 0, VAR_DOMAIN
)
1118 psymtab_to_symtab (ps
);
1123 expand_partial_symbol_tables (struct objfile
*objfile
)
1125 struct partial_symtab
*psymtab
;
1127 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1129 psymtab_to_symtab (psymtab
);
1134 read_psymtabs_with_filename (struct objfile
*objfile
, const char *filename
)
1136 struct partial_symtab
*p
;
1138 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
1140 /* Anonymous psymtabs don't have a name of a source file. */
1144 if (filename_cmp (filename
, p
->filename
) == 0)
1145 psymtab_to_symtab (p
);
1150 map_symbol_filenames_psymtab (struct objfile
*objfile
,
1151 symbol_filename_ftype
*fun
, void *data
,
1154 struct partial_symtab
*ps
;
1156 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1158 const char *fullname
;
1163 /* We can skip shared psymtabs here, because any file name will be
1164 attached to the unshared psymtab. */
1165 if (ps
->user
!= NULL
)
1168 /* Anonymous psymtabs don't have a file name. */
1174 fullname
= psymtab_to_fullname (ps
);
1177 (*fun
) (ps
->filename
, fullname
, data
);
1181 /* Finds the fullname that a partial_symtab represents.
1183 If this functions finds the fullname, it will save it in ps->fullname
1184 and it will also return the value.
1186 If this function fails to find the file that this partial_symtab represents,
1187 NULL will be returned and ps->fullname will be set to NULL. */
1190 psymtab_to_fullname (struct partial_symtab
*ps
)
1199 /* Use cached copy if we have it.
1200 We rely on forget_cached_source_info being called appropriately
1201 to handle cases like the file being moved. */
1203 return ps
->fullname
;
1205 r
= find_and_open_source (ps
->filename
, ps
->dirname
, &ps
->fullname
);
1210 return ps
->fullname
;
1217 find_symbol_file_from_partial (struct objfile
*objfile
, const char *name
)
1219 struct partial_symtab
*pst
;
1221 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
1223 if (lookup_partial_symbol (pst
, name
, 1, VAR_DOMAIN
))
1224 return pst
->filename
;
1229 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1230 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1231 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1232 ever returns non-zero, and otherwise returns 0. */
1235 map_block (const char *name
, domain_enum
namespace, struct objfile
*objfile
,
1236 struct block
*block
,
1237 int (*callback
) (struct block
*, struct symbol
*, void *),
1238 void *data
, symbol_compare_ftype
*match
)
1240 struct block_iterator iter
;
1243 for (sym
= block_iter_match_first (block
, name
, match
, &iter
);
1244 sym
!= NULL
; sym
= block_iter_match_next (name
, match
, &iter
))
1246 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym
),
1247 SYMBOL_DOMAIN (sym
), namespace))
1249 if (callback (block
, sym
, data
))
1257 /* Psymtab version of map_matching_symbols. See its definition in
1258 the definition of quick_symbol_functions in symfile.h. */
1261 map_matching_symbols_psymtab (const char *name
, domain_enum
namespace,
1262 struct objfile
*objfile
, int global
,
1263 int (*callback
) (struct block
*,
1264 struct symbol
*, void *),
1266 symbol_compare_ftype
*match
,
1267 symbol_compare_ftype
*ordered_compare
)
1269 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1270 struct partial_symtab
*ps
;
1272 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1276 || match_partial_symbol (ps
, global
, name
, namespace, match
,
1279 struct symtab
*s
= psymtab_to_symtab (ps
);
1280 struct block
*block
;
1282 if (s
== NULL
|| !s
->primary
)
1284 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), block_kind
);
1285 if (map_block (name
, namespace, objfile
, block
,
1286 callback
, data
, match
))
1288 if (callback (block
, NULL
, data
))
1294 /* A helper for expand_symtabs_matching_via_partial that handles
1295 searching included psymtabs. This returns 1 if a symbol is found,
1296 and zero otherwise. It also updates the 'searched_flag' on the
1297 various psymtabs that it searches. */
1300 recursively_search_psymtabs (struct partial_symtab
*ps
,
1301 struct objfile
*objfile
,
1302 enum search_domain kind
,
1303 int (*name_matcher
) (const char *, void *),
1306 struct partial_symbol
**psym
;
1307 struct partial_symbol
**bound
, **gbound
, **sbound
;
1309 int result
= PST_SEARCHED_AND_NOT_FOUND
;
1312 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1313 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1315 /* Recurse into shared psymtabs first, because they may have already
1316 been searched, and this could save some time. */
1317 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1321 /* Skip non-shared dependencies, these are handled elsewhere. */
1322 if (ps
->dependencies
[i
]->user
== NULL
)
1325 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1326 objfile
, kind
, name_matcher
, data
);
1329 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1334 gbound
= (objfile
->global_psymbols
.list
1335 + ps
->globals_offset
+ ps
->n_global_syms
);
1336 sbound
= (objfile
->static_psymbols
.list
1337 + ps
->statics_offset
+ ps
->n_static_syms
);
1340 /* Go through all of the symbols stored in a partial
1341 symtab in one loop. */
1342 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1347 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
1349 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1360 if ((kind
== ALL_DOMAIN
1361 || (kind
== VARIABLES_DOMAIN
1362 && SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
1363 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
1364 || (kind
== FUNCTIONS_DOMAIN
1365 && SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
1366 || (kind
== TYPES_DOMAIN
1367 && SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
))
1368 && (*name_matcher
) (SYMBOL_SEARCH_NAME (*psym
), data
))
1370 /* Found a match, so notify our caller. */
1371 result
= PST_SEARCHED_AND_FOUND
;
1378 ps
->searched_flag
= result
;
1379 return result
== PST_SEARCHED_AND_FOUND
;
1383 expand_symtabs_matching_via_partial
1384 (struct objfile
*objfile
,
1385 int (*file_matcher
) (const char *, void *),
1386 int (*name_matcher
) (const char *, void *),
1387 enum search_domain kind
,
1390 struct partial_symtab
*ps
;
1392 /* Clear the search flags. */
1393 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1395 ps
->searched_flag
= PST_NOT_SEARCHED
;
1398 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1403 /* We skip shared psymtabs because file-matching doesn't apply
1404 to them; but we search them later in the loop. */
1405 if (ps
->user
!= NULL
)
1412 if (! (*file_matcher
) (ps
->filename
, data
))
1416 if (recursively_search_psymtabs (ps
, objfile
, kind
, name_matcher
, data
))
1417 psymtab_to_symtab (ps
);
1422 objfile_has_psyms (struct objfile
*objfile
)
1424 return objfile
->psymtabs
!= NULL
;
1427 const struct quick_symbol_functions psym_functions
=
1430 find_last_source_symtab_from_partial
,
1431 forget_cached_source_info_partial
,
1432 partial_map_symtabs_matching_filename
,
1433 lookup_symbol_aux_psymtabs
,
1434 pre_expand_symtabs_matching_psymtabs
,
1435 print_psymtab_stats_for_objfile
,
1436 dump_psymtabs_for_objfile
,
1438 read_symtabs_for_function
,
1439 expand_partial_symbol_tables
,
1440 read_psymtabs_with_filename
,
1441 find_symbol_file_from_partial
,
1442 map_matching_symbols_psymtab
,
1443 expand_symtabs_matching_via_partial
,
1444 find_pc_sect_symtab_from_partial
,
1445 map_symbol_filenames_psymtab
1450 /* This compares two partial symbols by names, using strcmp_iw_ordered
1451 for the comparison. */
1454 compare_psymbols (const void *s1p
, const void *s2p
)
1456 struct partial_symbol
*const *s1
= s1p
;
1457 struct partial_symbol
*const *s2
= s2p
;
1459 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1
),
1460 SYMBOL_SEARCH_NAME (*s2
));
1464 sort_pst_symbols (struct partial_symtab
*pst
)
1466 /* Sort the global list; don't sort the static list. */
1468 qsort (pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
,
1469 pst
->n_global_syms
, sizeof (struct partial_symbol
*),
1473 /* Allocate and partially fill a partial symtab. It will be
1474 completely filled at the end of the symbol list.
1476 FILENAME is the name of the symbol-file we are reading from. */
1478 struct partial_symtab
*
1479 start_psymtab_common (struct objfile
*objfile
,
1480 struct section_offsets
*section_offsets
,
1481 const char *filename
,
1482 CORE_ADDR textlow
, struct partial_symbol
**global_syms
,
1483 struct partial_symbol
**static_syms
)
1485 struct partial_symtab
*psymtab
;
1487 psymtab
= allocate_psymtab (filename
, objfile
);
1488 psymtab
->section_offsets
= section_offsets
;
1489 psymtab
->textlow
= textlow
;
1490 psymtab
->texthigh
= psymtab
->textlow
; /* default */
1491 psymtab
->globals_offset
= global_syms
- objfile
->global_psymbols
.list
;
1492 psymtab
->statics_offset
= static_syms
- objfile
->static_psymbols
.list
;
1496 /* Calculate a hash code for the given partial symbol. The hash is
1497 calculated using the symbol's value, language, domain, class
1498 and name. These are the values which are set by
1499 add_psymbol_to_bcache. */
1501 static unsigned long
1502 psymbol_hash (const void *addr
, int length
)
1504 unsigned long h
= 0;
1505 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1506 unsigned int lang
= psymbol
->ginfo
.language
;
1507 unsigned int domain
= PSYMBOL_DOMAIN (psymbol
);
1508 unsigned int class = PSYMBOL_CLASS (psymbol
);
1510 h
= hash_continue (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1511 h
= hash_continue (&lang
, sizeof (unsigned int), h
);
1512 h
= hash_continue (&domain
, sizeof (unsigned int), h
);
1513 h
= hash_continue (&class, sizeof (unsigned int), h
);
1514 h
= hash_continue (psymbol
->ginfo
.name
, strlen (psymbol
->ginfo
.name
), h
);
1519 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1520 For the comparison this function uses a symbols value,
1521 language, domain, class and name. */
1524 psymbol_compare (const void *addr1
, const void *addr2
, int length
)
1526 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1527 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1529 return (memcmp (&sym1
->ginfo
.value
, &sym1
->ginfo
.value
,
1530 sizeof (sym1
->ginfo
.value
)) == 0
1531 && sym1
->ginfo
.language
== sym2
->ginfo
.language
1532 && PSYMBOL_DOMAIN (sym1
) == PSYMBOL_DOMAIN (sym2
)
1533 && PSYMBOL_CLASS (sym1
) == PSYMBOL_CLASS (sym2
)
1534 && sym1
->ginfo
.name
== sym2
->ginfo
.name
);
1537 /* Initialize a partial symbol bcache. */
1539 struct psymbol_bcache
*
1540 psymbol_bcache_init (void)
1542 struct psymbol_bcache
*bcache
= XCALLOC (1, struct psymbol_bcache
);
1543 bcache
->bcache
= bcache_xmalloc (psymbol_hash
, psymbol_compare
);
1547 /* Free a partial symbol bcache. */
1549 psymbol_bcache_free (struct psymbol_bcache
*bcache
)
1554 bcache_xfree (bcache
->bcache
);
1558 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1561 psymbol_bcache_get_bcache (struct psymbol_bcache
*bcache
)
1563 return bcache
->bcache
;
1566 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1567 symbol before, add a copy to BCACHE. In either case, return a pointer
1568 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1569 1 in case of new entry or 0 if returning an old entry. */
1571 static const struct partial_symbol
*
1572 psymbol_bcache_full (struct partial_symbol
*sym
,
1573 struct psymbol_bcache
*bcache
,
1576 return bcache_full (sym
,
1577 sizeof (struct partial_symbol
),
1582 /* Helper function, initialises partial symbol structure and stashes
1583 it into objfile's bcache. Note that our caching mechanism will
1584 use all fields of struct partial_symbol to determine hash value of the
1585 structure. In other words, having two symbols with the same name but
1586 different domain (or address) is possible and correct. */
1588 static const struct partial_symbol
*
1589 add_psymbol_to_bcache (const char *name
, int namelength
, int copy_name
,
1591 enum address_class
class,
1592 long val
, /* Value as a long */
1593 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1594 enum language language
, struct objfile
*objfile
,
1597 struct partial_symbol psymbol
;
1599 /* We must ensure that the entire 'value' field has been zeroed
1600 before assigning to it, because an assignment may not write the
1602 memset (&psymbol
.ginfo
.value
, 0, sizeof (psymbol
.ginfo
.value
));
1604 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1607 SYMBOL_VALUE (&psymbol
) = val
;
1611 SYMBOL_VALUE_ADDRESS (&psymbol
) = coreaddr
;
1613 SYMBOL_SECTION (&psymbol
) = 0;
1614 SYMBOL_OBJ_SECTION (&psymbol
) = NULL
;
1615 SYMBOL_SET_LANGUAGE (&psymbol
, language
);
1616 PSYMBOL_DOMAIN (&psymbol
) = domain
;
1617 PSYMBOL_CLASS (&psymbol
) = class;
1619 SYMBOL_SET_NAMES (&psymbol
, name
, namelength
, copy_name
, objfile
);
1621 /* Stash the partial symbol away in the cache. */
1622 return psymbol_bcache_full (&psymbol
,
1623 objfile
->psymbol_cache
,
1627 /* Increase the space allocated for LISTP, which is probably
1628 global_psymbols or static_psymbols. This space will eventually
1629 be freed in free_objfile(). */
1632 extend_psymbol_list (struct psymbol_allocation_list
*listp
,
1633 struct objfile
*objfile
)
1637 if (listp
->size
== 0)
1640 listp
->list
= (struct partial_symbol
**)
1641 xmalloc (new_size
* sizeof (struct partial_symbol
*));
1645 new_size
= listp
->size
* 2;
1646 listp
->list
= (struct partial_symbol
**)
1647 xrealloc ((char *) listp
->list
,
1648 new_size
* sizeof (struct partial_symbol
*));
1650 /* Next assumes we only went one over. Should be good if
1651 program works correctly. */
1652 listp
->next
= listp
->list
+ listp
->size
;
1653 listp
->size
= new_size
;
1656 /* Helper function, adds partial symbol to the given partial symbol
1660 append_psymbol_to_list (struct psymbol_allocation_list
*list
,
1661 const struct partial_symbol
*psym
,
1662 struct objfile
*objfile
)
1664 if (list
->next
>= list
->list
+ list
->size
)
1665 extend_psymbol_list (list
, objfile
);
1666 *list
->next
++ = (struct partial_symbol
*) psym
;
1667 OBJSTAT (objfile
, n_psyms
++);
1670 /* Add a symbol with a long value to a psymtab.
1671 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1672 Return the partial symbol that has been added. */
1675 add_psymbol_to_list (const char *name
, int namelength
, int copy_name
,
1677 enum address_class
class,
1678 struct psymbol_allocation_list
*list
,
1679 long val
, /* Value as a long */
1680 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1681 enum language language
, struct objfile
*objfile
)
1683 const struct partial_symbol
*psym
;
1687 /* Stash the partial symbol away in the cache. */
1688 psym
= add_psymbol_to_bcache (name
, namelength
, copy_name
, domain
, class,
1689 val
, coreaddr
, language
, objfile
, &added
);
1691 /* Do not duplicate global partial symbols. */
1692 if (list
== &objfile
->global_psymbols
1696 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1697 append_psymbol_to_list (list
, psym
, objfile
);
1700 /* Initialize storage for partial symbols. */
1703 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1705 /* Free any previously allocated psymbol lists. */
1707 if (objfile
->global_psymbols
.list
)
1709 xfree (objfile
->global_psymbols
.list
);
1711 if (objfile
->static_psymbols
.list
)
1713 xfree (objfile
->static_psymbols
.list
);
1716 /* Current best guess is that approximately a twentieth
1717 of the total symbols (in a debugging file) are global or static
1718 oriented symbols. */
1720 objfile
->global_psymbols
.size
= total_symbols
/ 10;
1721 objfile
->static_psymbols
.size
= total_symbols
/ 10;
1723 if (objfile
->global_psymbols
.size
> 0)
1725 objfile
->global_psymbols
.next
=
1726 objfile
->global_psymbols
.list
= (struct partial_symbol
**)
1727 xmalloc ((objfile
->global_psymbols
.size
1728 * sizeof (struct partial_symbol
*)));
1730 if (objfile
->static_psymbols
.size
> 0)
1732 objfile
->static_psymbols
.next
=
1733 objfile
->static_psymbols
.list
= (struct partial_symbol
**)
1734 xmalloc ((objfile
->static_psymbols
.size
1735 * sizeof (struct partial_symbol
*)));
1739 struct partial_symtab
*
1740 allocate_psymtab (const char *filename
, struct objfile
*objfile
)
1742 struct partial_symtab
*psymtab
;
1744 if (objfile
->free_psymtabs
)
1746 psymtab
= objfile
->free_psymtabs
;
1747 objfile
->free_psymtabs
= psymtab
->next
;
1750 psymtab
= (struct partial_symtab
*)
1751 obstack_alloc (&objfile
->objfile_obstack
,
1752 sizeof (struct partial_symtab
));
1754 memset (psymtab
, 0, sizeof (struct partial_symtab
));
1755 psymtab
->filename
= obsavestring (filename
, strlen (filename
),
1756 &objfile
->objfile_obstack
);
1757 psymtab
->symtab
= NULL
;
1759 /* Prepend it to the psymtab list for the objfile it belongs to.
1760 Psymtabs are searched in most recent inserted -> least recent
1763 psymtab
->objfile
= objfile
;
1764 psymtab
->next
= objfile
->psymtabs
;
1765 objfile
->psymtabs
= psymtab
;
1767 if (symtab_create_debug
)
1769 /* Be a bit clever with debugging messages, and don't print objfile
1770 every time, only when it changes. */
1771 static char *last_objfile_name
= NULL
;
1773 if (last_objfile_name
== NULL
1774 || strcmp (last_objfile_name
, objfile
->name
) != 0)
1776 xfree (last_objfile_name
);
1777 last_objfile_name
= xstrdup (objfile
->name
);
1778 fprintf_unfiltered (gdb_stdlog
,
1779 "Creating one or more psymtabs for objfile %s ...\n",
1782 fprintf_unfiltered (gdb_stdlog
,
1783 "Created psymtab %s for module %s.\n",
1784 host_address_to_string (psymtab
), filename
);
1791 discard_psymtab (struct partial_symtab
*pst
)
1793 struct partial_symtab
**prev_pst
;
1796 Empty psymtabs happen as a result of header files which don't
1797 have any symbols in them. There can be a lot of them. But this
1798 check is wrong, in that a psymtab with N_SLINE entries but
1799 nothing else is not empty, but we don't realize that. Fixing
1800 that without slowing things down might be tricky. */
1802 /* First, snip it out of the psymtab chain. */
1804 prev_pst
= &(pst
->objfile
->psymtabs
);
1805 while ((*prev_pst
) != pst
)
1806 prev_pst
= &((*prev_pst
)->next
);
1807 (*prev_pst
) = pst
->next
;
1809 /* Next, put it on a free list for recycling. */
1811 pst
->next
= pst
->objfile
->free_psymtabs
;
1812 pst
->objfile
->free_psymtabs
= pst
;
1818 maintenance_print_psymbols (char *args
, int from_tty
)
1821 struct ui_file
*outfile
;
1822 struct cleanup
*cleanups
;
1823 char *symname
= NULL
;
1824 char *filename
= DEV_TTY
;
1825 struct objfile
*objfile
;
1826 struct partial_symtab
*ps
;
1833 print-psymbols takes an output file name and optional symbol file name"));
1835 argv
= gdb_buildargv (args
);
1836 cleanups
= make_cleanup_freeargv (argv
);
1838 if (argv
[0] != NULL
)
1841 /* If a second arg is supplied, it is a source file name to match on. */
1842 if (argv
[1] != NULL
)
1848 filename
= tilde_expand (filename
);
1849 make_cleanup (xfree
, filename
);
1851 outfile
= gdb_fopen (filename
, FOPEN_WT
);
1853 perror_with_name (filename
);
1854 make_cleanup_ui_file_delete (outfile
);
1856 ALL_PSYMTABS (objfile
, ps
)
1859 if (symname
== NULL
|| filename_cmp (symname
, ps
->filename
) == 0)
1860 dump_psymtab (objfile
, ps
, outfile
);
1862 do_cleanups (cleanups
);
1865 /* List all the partial symbol tables whose names match REGEXP (optional). */
1867 maintenance_info_psymtabs (char *regexp
, int from_tty
)
1869 struct program_space
*pspace
;
1870 struct objfile
*objfile
;
1875 ALL_PSPACES (pspace
)
1876 ALL_PSPACE_OBJFILES (pspace
, objfile
)
1878 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1879 struct partial_symtab
*psymtab
;
1881 /* We don't want to print anything for this objfile until we
1882 actually find a symtab whose name matches. */
1883 int printed_objfile_start
= 0;
1885 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1890 || re_exec (psymtab
->filename
))
1892 if (! printed_objfile_start
)
1894 printf_filtered ("{ objfile %s ", objfile
->name
);
1896 printf_filtered ("((struct objfile *) %s)\n",
1897 host_address_to_string (objfile
));
1898 printed_objfile_start
= 1;
1901 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1903 printf_filtered ("((struct partial_symtab *) %s)\n",
1904 host_address_to_string (psymtab
));
1906 printf_filtered (" readin %s\n",
1907 psymtab
->readin
? "yes" : "no");
1908 printf_filtered (" fullname %s\n",
1910 ? psymtab
->fullname
: "(null)");
1911 printf_filtered (" text addresses ");
1912 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
),
1914 printf_filtered (" -- ");
1915 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
),
1917 printf_filtered ("\n");
1918 printf_filtered (" psymtabs_addrmap_supported %s\n",
1919 (psymtab
->psymtabs_addrmap_supported
1921 printf_filtered (" globals ");
1922 if (psymtab
->n_global_syms
)
1924 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1925 host_address_to_string (psymtab
->objfile
->global_psymbols
.list
1926 + psymtab
->globals_offset
),
1927 psymtab
->n_global_syms
);
1930 printf_filtered ("(none)\n");
1931 printf_filtered (" statics ");
1932 if (psymtab
->n_static_syms
)
1934 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1935 host_address_to_string (psymtab
->objfile
->static_psymbols
.list
1936 + psymtab
->statics_offset
),
1937 psymtab
->n_static_syms
);
1940 printf_filtered ("(none)\n");
1941 printf_filtered (" dependencies ");
1942 if (psymtab
->number_of_dependencies
)
1946 printf_filtered ("{\n");
1947 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1949 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1951 /* Note the string concatenation there --- no comma. */
1952 printf_filtered (" psymtab %s "
1953 "((struct partial_symtab *) %s)\n",
1955 host_address_to_string (dep
));
1957 printf_filtered (" }\n");
1960 printf_filtered ("(none)\n");
1961 printf_filtered (" }\n");
1965 if (printed_objfile_start
)
1966 printf_filtered ("}\n");
1970 /* Check consistency of psymtabs and symtabs. */
1973 maintenance_check_symtabs (char *ignore
, int from_tty
)
1976 struct partial_symbol
**psym
;
1977 struct symtab
*s
= NULL
;
1978 struct partial_symtab
*ps
;
1979 struct blockvector
*bv
;
1980 struct objfile
*objfile
;
1984 ALL_PSYMTABS (objfile
, ps
)
1986 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1988 s
= psymtab_to_symtab (ps
);
1991 bv
= BLOCKVECTOR (s
);
1992 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1993 psym
= ps
->objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1994 length
= ps
->n_static_syms
;
1997 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
1998 SYMBOL_DOMAIN (*psym
));
2001 printf_filtered ("Static symbol `");
2002 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
2003 printf_filtered ("' only found in ");
2004 puts_filtered (ps
->filename
);
2005 printf_filtered (" psymtab\n");
2009 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2010 psym
= ps
->objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2011 length
= ps
->n_global_syms
;
2014 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
2015 SYMBOL_DOMAIN (*psym
));
2018 printf_filtered ("Global symbol `");
2019 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
2020 printf_filtered ("' only found in ");
2021 puts_filtered (ps
->filename
);
2022 printf_filtered (" psymtab\n");
2026 if (ps
->texthigh
< ps
->textlow
)
2028 printf_filtered ("Psymtab ");
2029 puts_filtered (ps
->filename
);
2030 printf_filtered (" covers bad range ");
2031 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
2032 printf_filtered (" - ");
2033 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
2034 printf_filtered ("\n");
2037 if (ps
->texthigh
== 0)
2039 if (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
))
2041 printf_filtered ("Psymtab ");
2042 puts_filtered (ps
->filename
);
2043 printf_filtered (" covers ");
2044 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
2045 printf_filtered (" - ");
2046 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
2047 printf_filtered (" but symtab covers only ");
2048 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2049 printf_filtered (" - ");
2050 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2051 printf_filtered ("\n");
2059 expand_partial_symbol_names (int (*fun
) (const char *, void *),
2062 struct objfile
*objfile
;
2064 ALL_OBJFILES (objfile
)
2067 objfile
->sf
->qf
->expand_symtabs_matching (objfile
, NULL
, fun
,
2073 map_partial_symbol_filenames (symbol_filename_ftype
*fun
, void *data
,
2076 struct objfile
*objfile
;
2078 ALL_OBJFILES (objfile
)
2081 objfile
->sf
->qf
->map_symbol_filenames (objfile
, fun
, data
,