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 /* Don't visit already-expanded psymtabs. */
142 /* This may expand more than one symtab, and we want to iterate over
144 psymtab_to_symtab (pst
);
146 return iterate_over_some_symtabs (name
, full_path
, real_path
, callback
, data
,
147 objfile
->symtabs
, last_made
);
150 /* Implementation of the map_symtabs_matching_filename method. */
153 partial_map_symtabs_matching_filename (struct objfile
*objfile
,
155 const char *full_path
,
156 const char *real_path
,
157 int (*callback
) (struct symtab
*,
161 struct partial_symtab
*pst
;
162 const char *name_basename
= lbasename (name
);
163 int name_len
= strlen (name
);
164 int is_abs
= IS_ABSOLUTE_PATH (name
);
166 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
168 if (FILENAME_CMP (name
, pst
->filename
) == 0
169 || (!is_abs
&& compare_filenames_for_search (pst
->filename
,
172 if (partial_map_expand_apply (objfile
, name
, full_path
, real_path
,
173 pst
, callback
, data
))
177 /* Before we invoke realpath, which can get expensive when many
178 files are involved, do a quick comparison of the basenames. */
179 if (! basenames_may_differ
180 && FILENAME_CMP (name_basename
, lbasename (pst
->filename
)) != 0)
183 /* If the user gave us an absolute path, try to find the file in
184 this symtab and use its absolute path. */
185 if (full_path
!= NULL
)
187 psymtab_to_fullname (pst
);
188 if (pst
->fullname
!= NULL
189 && (FILENAME_CMP (full_path
, pst
->fullname
) == 0
190 || (!is_abs
&& compare_filenames_for_search (pst
->fullname
,
193 if (partial_map_expand_apply (objfile
, name
, full_path
, real_path
,
194 pst
, callback
, data
))
199 if (real_path
!= NULL
)
202 psymtab_to_fullname (pst
);
203 if (pst
->fullname
!= NULL
)
205 rp
= gdb_realpath (pst
->fullname
);
206 make_cleanup (xfree
, rp
);
209 && (FILENAME_CMP (real_path
, rp
) == 0
210 || (!is_abs
&& compare_filenames_for_search (real_path
,
213 if (partial_map_expand_apply (objfile
, name
, full_path
, real_path
,
214 pst
, callback
, data
))
223 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
224 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
226 static struct partial_symtab
*
227 find_pc_sect_psymtab_closer (CORE_ADDR pc
, struct obj_section
*section
,
228 struct partial_symtab
*pst
,
229 struct minimal_symbol
*msymbol
)
231 struct objfile
*objfile
= pst
->objfile
;
232 struct partial_symtab
*tpst
;
233 struct partial_symtab
*best_pst
= pst
;
234 CORE_ADDR best_addr
= pst
->textlow
;
236 gdb_assert (!pst
->psymtabs_addrmap_supported
);
238 /* An objfile that has its functions reordered might have
239 many partial symbol tables containing the PC, but
240 we want the partial symbol table that contains the
241 function containing the PC. */
242 if (!(objfile
->flags
& OBJF_REORDERED
) &&
243 section
== 0) /* Can't validate section this way. */
249 /* The code range of partial symtabs sometimes overlap, so, in
250 the loop below, we need to check all partial symtabs and
251 find the one that fits better for the given PC address. We
252 select the partial symtab that contains a symbol whose
253 address is closest to the PC address. By closest we mean
254 that find_pc_sect_symbol returns the symbol with address
255 that is closest and still less than the given PC. */
256 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
258 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
260 struct partial_symbol
*p
;
263 /* NOTE: This assumes that every psymbol has a
264 corresponding msymbol, which is not necessarily
265 true; the debug info might be much richer than the
266 object's symbol table. */
267 p
= find_pc_sect_psymbol (tpst
, pc
, section
);
269 && SYMBOL_VALUE_ADDRESS (p
)
270 == SYMBOL_VALUE_ADDRESS (msymbol
))
273 /* Also accept the textlow value of a psymtab as a
274 "symbol", to provide some support for partial
275 symbol tables with line information but no debug
276 symbols (e.g. those produced by an assembler). */
278 this_addr
= SYMBOL_VALUE_ADDRESS (p
);
280 this_addr
= tpst
->textlow
;
282 /* Check whether it is closer than our current
283 BEST_ADDR. Since this symbol address is
284 necessarily lower or equal to PC, the symbol closer
285 to PC is the symbol which address is the highest.
286 This way we return the psymtab which contains such
287 best match symbol. This can help in cases where the
288 symbol information/debuginfo is not complete, like
289 for instance on IRIX6 with gcc, where no debug info
290 is emitted for statics. (See also the nodebug.exp
292 if (this_addr
> best_addr
)
294 best_addr
= this_addr
;
302 /* Find which partial symtab contains PC and SECTION. Return 0 if
303 none. We return the psymtab that contains a symbol whose address
304 exactly matches PC, or, if we cannot find an exact match, the
305 psymtab that contains a symbol whose address is closest to PC. */
306 static struct partial_symtab
*
307 find_pc_sect_psymtab (struct objfile
*objfile
, CORE_ADDR pc
,
308 struct obj_section
*section
,
309 struct minimal_symbol
*msymbol
)
311 struct partial_symtab
*pst
;
313 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
314 than the later used TEXTLOW/TEXTHIGH one. */
316 if (objfile
->psymtabs_addrmap
!= NULL
)
318 pst
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
321 /* FIXME: addrmaps currently do not handle overlayed sections,
322 so fall back to the non-addrmap case if we're debugging
323 overlays and the addrmap returned the wrong section. */
324 if (overlay_debugging
&& msymbol
&& section
)
326 struct partial_symbol
*p
;
328 /* NOTE: This assumes that every psymbol has a
329 corresponding msymbol, which is not necessarily
330 true; the debug info might be much richer than the
331 object's symbol table. */
332 p
= find_pc_sect_psymbol (pst
, pc
, section
);
334 || SYMBOL_VALUE_ADDRESS (p
)
335 != SYMBOL_VALUE_ADDRESS (msymbol
))
339 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
340 PSYMTABS_ADDRMAP we used has already the best 1-byte
341 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
342 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
351 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
352 which still have no corresponding full SYMTABs read. But it is not
353 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
356 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
357 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
358 debug info type in single OBJFILE. */
360 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
361 if (!pst
->psymtabs_addrmap_supported
362 && pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
364 struct partial_symtab
*best_pst
;
366 best_pst
= find_pc_sect_psymtab_closer (pc
, section
, pst
, msymbol
);
367 if (best_pst
!= NULL
)
374 static struct symtab
*
375 find_pc_sect_symtab_from_partial (struct objfile
*objfile
,
376 struct minimal_symbol
*msymbol
,
377 CORE_ADDR pc
, struct obj_section
*section
,
380 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
384 if (warn_if_readin
&& ps
->readin
)
385 /* Might want to error() here (in case symtab is corrupt and
386 will cause a core dump), but maybe we can successfully
387 continue, so let's not. */
389 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
390 paddress (get_objfile_arch (ps
->objfile
), pc
));
391 return psymtab_to_symtab (ps
);
396 /* Find which partial symbol within a psymtab matches PC and SECTION.
399 static struct partial_symbol
*
400 find_pc_sect_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
,
401 struct obj_section
*section
)
403 struct partial_symbol
*best
= NULL
, *p
, **pp
;
406 gdb_assert (psymtab
!= NULL
);
408 /* Cope with programs that start at address 0. */
409 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
411 /* Search the global symbols as well as the static symbols, so that
412 find_pc_partial_function doesn't use a minimal symbol and thus
413 cache a bad endaddr. */
414 for (pp
= psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
415 (pp
- (psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
416 < psymtab
->n_global_syms
);
420 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
421 && SYMBOL_CLASS (p
) == LOC_BLOCK
422 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
423 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
424 || (psymtab
->textlow
== 0
425 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
427 if (section
) /* Match on a specific section. */
429 fixup_psymbol_section (p
, psymtab
->objfile
);
430 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p
), section
))
433 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
438 for (pp
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
439 (pp
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
440 < psymtab
->n_static_syms
);
444 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
445 && SYMBOL_CLASS (p
) == LOC_BLOCK
446 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
447 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
448 || (psymtab
->textlow
== 0
449 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
451 if (section
) /* Match on a specific section. */
453 fixup_psymbol_section (p
, psymtab
->objfile
);
454 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p
), section
))
457 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
465 static struct partial_symbol
*
466 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
473 if (SYMBOL_OBJ_SECTION (psym
))
476 gdb_assert (objfile
);
478 switch (SYMBOL_CLASS (psym
))
483 addr
= SYMBOL_VALUE_ADDRESS (psym
);
486 /* Nothing else will be listed in the minsyms -- no use looking
491 fixup_section (&psym
->ginfo
, addr
, objfile
);
496 static struct symtab
*
497 lookup_symbol_aux_psymtabs (struct objfile
*objfile
,
498 int block_index
, const char *name
,
499 const domain_enum domain
)
501 struct partial_symtab
*ps
;
502 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
504 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
506 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, psymtab_index
, domain
))
508 struct symbol
*sym
= NULL
;
509 struct symtab
*stab
= psymtab_to_symtab (ps
);
511 /* Some caution must be observed with overloaded functions
512 and methods, since the psymtab will not contain any overload
513 information (but NAME might contain it). */
516 struct blockvector
*bv
= BLOCKVECTOR (stab
);
517 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
519 sym
= lookup_block_symbol (block
, name
, domain
);
522 if (sym
&& strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
525 /* Keep looking through other psymtabs. */
532 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
533 the global block of PST if GLOBAL, and otherwise the static block.
534 MATCH is the comparison operation that returns true iff MATCH (s,
535 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
536 non-null, the symbols in the block are assumed to be ordered
537 according to it (allowing binary search). It must be compatible
538 with MATCH. Returns the symbol, if found, and otherwise NULL. */
540 static struct partial_symbol
*
541 match_partial_symbol (struct partial_symtab
*pst
, int global
,
542 const char *name
, domain_enum domain
,
543 symbol_compare_ftype
*match
,
544 symbol_compare_ftype
*ordered_compare
)
546 struct partial_symbol
**start
, **psym
;
547 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
548 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
549 int do_linear_search
= 1;
554 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
555 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
557 if (global
&& ordered_compare
) /* Can use a binary search. */
559 do_linear_search
= 0;
561 /* Binary search. This search is guaranteed to end with center
562 pointing at the earliest partial symbol whose name might be
563 correct. At that point *all* partial symbols with an
564 appropriate name will be checked against the correct
568 top
= start
+ length
- 1;
572 center
= bottom
+ (top
- bottom
) / 2;
573 gdb_assert (center
< top
);
574 if (!do_linear_search
575 && (SYMBOL_LANGUAGE (*center
) == language_java
))
576 do_linear_search
= 1;
577 if (ordered_compare (SYMBOL_SEARCH_NAME (*center
), name
) >= 0)
582 gdb_assert (top
== bottom
);
584 while (top
<= real_top
585 && match (SYMBOL_SEARCH_NAME (*top
), name
) == 0)
587 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
588 SYMBOL_DOMAIN (*top
), domain
))
594 /* Can't use a binary search or else we found during the binary search that
595 we should also do a linear search. */
597 if (do_linear_search
)
599 for (psym
= start
; psym
< start
+ length
; psym
++)
601 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
602 SYMBOL_DOMAIN (*psym
), domain
)
603 && match (SYMBOL_SEARCH_NAME (*psym
), name
) == 0)
612 pre_expand_symtabs_matching_psymtabs (struct objfile
*objfile
,
613 enum block_enum block_kind
,
620 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
621 not contain any method/function instance information (since this would
622 force reading type information while reading psymtabs). Therefore,
623 if NAME contains overload information, it must be stripped before searching
626 The caller is responsible for freeing the return result. */
629 psymtab_search_name (const char *name
)
631 switch (current_language
->la_language
)
636 if (strchr (name
, '('))
638 char *ret
= cp_remove_params (name
);
650 return xstrdup (name
);
653 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
654 Check the global symbols if GLOBAL, the static symbols if not. */
656 static struct partial_symbol
*
657 lookup_partial_symbol (struct partial_symtab
*pst
, const char *name
,
658 int global
, domain_enum domain
)
660 struct partial_symbol
**start
, **psym
;
661 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
662 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
663 int do_linear_search
= 1;
665 struct cleanup
*cleanup
;
672 search_name
= psymtab_search_name (name
);
673 cleanup
= make_cleanup (xfree
, search_name
);
675 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
676 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
678 if (global
) /* This means we can use a binary search. */
680 do_linear_search
= 0;
682 /* Binary search. This search is guaranteed to end with center
683 pointing at the earliest partial symbol whose name might be
684 correct. At that point *all* partial symbols with an
685 appropriate name will be checked against the correct
689 top
= start
+ length
- 1;
693 center
= bottom
+ (top
- bottom
) / 2;
695 internal_error (__FILE__
, __LINE__
,
696 _("failed internal consistency check"));
697 if (!do_linear_search
698 && SYMBOL_LANGUAGE (*center
) == language_java
)
700 do_linear_search
= 1;
702 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center
),
712 if (!(top
== bottom
))
713 internal_error (__FILE__
, __LINE__
,
714 _("failed internal consistency check"));
716 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
717 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
718 while (top
>= start
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, search_name
))
721 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
724 while (top
<= real_top
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, search_name
))
726 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
727 SYMBOL_DOMAIN (*top
), domain
))
729 do_cleanups (cleanup
);
736 /* Can't use a binary search or else we found during the binary search that
737 we should also do a linear search. */
739 if (do_linear_search
)
741 for (psym
= start
; psym
< start
+ length
; psym
++)
743 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
744 SYMBOL_DOMAIN (*psym
), domain
)
745 && SYMBOL_MATCHES_SEARCH_NAME (*psym
, search_name
))
747 do_cleanups (cleanup
);
753 do_cleanups (cleanup
);
757 /* Get the symbol table that corresponds to a partial_symtab.
758 This is fast after the first time you do it. */
760 static struct symtab
*
761 psymtab_to_symtab (struct partial_symtab
*pst
)
763 /* If it's been looked up before, return it. */
767 /* If it has not yet been read in, read it. */
770 struct cleanup
*back_to
= increment_reading_symtab ();
772 (*pst
->read_symtab
) (pst
);
773 do_cleanups (back_to
);
780 relocate_psymtabs (struct objfile
*objfile
,
781 struct section_offsets
*new_offsets
,
782 struct section_offsets
*delta
)
784 struct partial_symbol
**psym
;
785 struct partial_symtab
*p
;
787 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
789 p
->textlow
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
790 p
->texthigh
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
793 for (psym
= objfile
->global_psymbols
.list
;
794 psym
< objfile
->global_psymbols
.next
;
797 fixup_psymbol_section (*psym
, objfile
);
798 if (SYMBOL_SECTION (*psym
) >= 0)
799 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
800 SYMBOL_SECTION (*psym
));
802 for (psym
= objfile
->static_psymbols
.list
;
803 psym
< objfile
->static_psymbols
.next
;
806 fixup_psymbol_section (*psym
, objfile
);
807 if (SYMBOL_SECTION (*psym
) >= 0)
808 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
809 SYMBOL_SECTION (*psym
));
813 static struct symtab
*
814 find_last_source_symtab_from_partial (struct objfile
*ofp
)
816 struct partial_symtab
*ps
;
817 struct partial_symtab
*cs_pst
= 0;
819 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp
, ps
)
821 const char *name
= ps
->filename
;
822 int len
= strlen (name
);
824 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
825 || strcmp (name
, "<<C++-namespaces>>") == 0)))
833 internal_error (__FILE__
, __LINE__
,
834 _("select_source_symtab: "
835 "readin pst found and no symtabs."));
838 return psymtab_to_symtab (cs_pst
);
844 forget_cached_source_info_partial (struct objfile
*objfile
)
846 struct partial_symtab
*pst
;
848 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
850 if (pst
->fullname
!= NULL
)
852 xfree (pst
->fullname
);
853 pst
->fullname
= NULL
;
859 print_partial_symbols (struct gdbarch
*gdbarch
,
860 struct partial_symbol
**p
, int count
, char *what
,
861 struct ui_file
*outfile
)
863 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
866 fprintf_filtered (outfile
, " `%s'", SYMBOL_LINKAGE_NAME (*p
));
867 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
869 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
871 fputs_filtered (", ", outfile
);
872 switch (SYMBOL_DOMAIN (*p
))
875 fputs_filtered ("undefined domain, ", outfile
);
878 /* This is the usual thing -- don't print it. */
881 fputs_filtered ("struct domain, ", outfile
);
884 fputs_filtered ("label domain, ", outfile
);
887 fputs_filtered ("<invalid domain>, ", outfile
);
890 switch (SYMBOL_CLASS (*p
))
893 fputs_filtered ("undefined", outfile
);
896 fputs_filtered ("constant int", outfile
);
899 fputs_filtered ("static", outfile
);
902 fputs_filtered ("register", outfile
);
905 fputs_filtered ("pass by value", outfile
);
908 fputs_filtered ("pass by reference", outfile
);
910 case LOC_REGPARM_ADDR
:
911 fputs_filtered ("register address parameter", outfile
);
914 fputs_filtered ("stack parameter", outfile
);
917 fputs_filtered ("type", outfile
);
920 fputs_filtered ("label", outfile
);
923 fputs_filtered ("function", outfile
);
925 case LOC_CONST_BYTES
:
926 fputs_filtered ("constant bytes", outfile
);
929 fputs_filtered ("unresolved", outfile
);
931 case LOC_OPTIMIZED_OUT
:
932 fputs_filtered ("optimized out", outfile
);
935 fputs_filtered ("computed at runtime", outfile
);
938 fputs_filtered ("<invalid location>", outfile
);
941 fputs_filtered (", ", outfile
);
942 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (*p
)), outfile
);
943 fprintf_filtered (outfile
, "\n");
949 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
950 struct ui_file
*outfile
)
952 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
955 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
957 fprintf_filtered (outfile
, "(object ");
958 gdb_print_host_address (psymtab
, outfile
);
959 fprintf_filtered (outfile
, ")\n\n");
960 fprintf_unfiltered (outfile
, " Read from object file %s (",
962 gdb_print_host_address (objfile
, outfile
);
963 fprintf_unfiltered (outfile
, ")\n");
967 fprintf_filtered (outfile
,
968 " Full symtab was read (at ");
969 gdb_print_host_address (psymtab
->symtab
, outfile
);
970 fprintf_filtered (outfile
, " by function at ");
971 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
972 fprintf_filtered (outfile
, ")\n");
975 fprintf_filtered (outfile
, " Relocate symbols by ");
976 for (i
= 0; i
< psymtab
->objfile
->num_sections
; ++i
)
979 fprintf_filtered (outfile
, ", ");
981 fputs_filtered (paddress (gdbarch
,
982 ANOFFSET (psymtab
->section_offsets
, i
)),
985 fprintf_filtered (outfile
, "\n");
987 fprintf_filtered (outfile
, " Symbols cover text addresses ");
988 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
), outfile
);
989 fprintf_filtered (outfile
, "-");
990 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
), outfile
);
991 fprintf_filtered (outfile
, "\n");
992 fprintf_filtered (outfile
, " Address map supported - %s.\n",
993 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
994 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
995 psymtab
->number_of_dependencies
);
996 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
998 fprintf_filtered (outfile
, " %d ", i
);
999 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
1000 fprintf_filtered (outfile
, " %s\n",
1001 psymtab
->dependencies
[i
]->filename
);
1003 if (psymtab
->n_global_syms
> 0)
1005 print_partial_symbols (gdbarch
,
1006 objfile
->global_psymbols
.list
1007 + psymtab
->globals_offset
,
1008 psymtab
->n_global_syms
, "Global", outfile
);
1010 if (psymtab
->n_static_syms
> 0)
1012 print_partial_symbols (gdbarch
,
1013 objfile
->static_psymbols
.list
1014 + psymtab
->statics_offset
,
1015 psymtab
->n_static_syms
, "Static", outfile
);
1017 fprintf_filtered (outfile
, "\n");
1021 print_psymtab_stats_for_objfile (struct objfile
*objfile
)
1024 struct partial_symtab
*ps
;
1027 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1029 if (ps
->readin
== 0)
1032 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
1036 dump_psymtabs_for_objfile (struct objfile
*objfile
)
1038 struct partial_symtab
*psymtab
;
1040 if (objfile
->psymtabs
)
1042 printf_filtered ("Psymtabs:\n");
1043 for (psymtab
= objfile
->psymtabs
;
1045 psymtab
= psymtab
->next
)
1047 printf_filtered ("%s at ",
1049 gdb_print_host_address (psymtab
, gdb_stdout
);
1050 printf_filtered (", ");
1051 if (psymtab
->objfile
!= objfile
)
1053 printf_filtered ("NOT ON CHAIN! ");
1057 printf_filtered ("\n\n");
1061 /* Look through the partial symtabs for all symbols which begin
1062 by matching FUNC_NAME. Make sure we read that symbol table in. */
1065 read_symtabs_for_function (struct objfile
*objfile
, const char *func_name
)
1067 struct partial_symtab
*ps
;
1069 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1074 if ((lookup_partial_symbol (ps
, func_name
, 1, VAR_DOMAIN
)
1076 || (lookup_partial_symbol (ps
, func_name
, 0, VAR_DOMAIN
)
1078 psymtab_to_symtab (ps
);
1083 expand_partial_symbol_tables (struct objfile
*objfile
)
1085 struct partial_symtab
*psymtab
;
1087 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1089 psymtab_to_symtab (psymtab
);
1094 read_psymtabs_with_filename (struct objfile
*objfile
, const char *filename
)
1096 struct partial_symtab
*p
;
1098 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
1100 if (filename_cmp (filename
, p
->filename
) == 0)
1101 psymtab_to_symtab (p
);
1106 map_symbol_filenames_psymtab (struct objfile
*objfile
,
1107 symbol_filename_ftype
*fun
, void *data
,
1110 struct partial_symtab
*ps
;
1112 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1114 const char *fullname
;
1121 fullname
= psymtab_to_fullname (ps
);
1124 (*fun
) (ps
->filename
, fullname
, data
);
1128 /* Finds the fullname that a partial_symtab represents.
1130 If this functions finds the fullname, it will save it in ps->fullname
1131 and it will also return the value.
1133 If this function fails to find the file that this partial_symtab represents,
1134 NULL will be returned and ps->fullname will be set to NULL. */
1137 psymtab_to_fullname (struct partial_symtab
*ps
)
1144 /* Use cached copy if we have it.
1145 We rely on forget_cached_source_info being called appropriately
1146 to handle cases like the file being moved. */
1148 return ps
->fullname
;
1150 r
= find_and_open_source (ps
->filename
, ps
->dirname
, &ps
->fullname
);
1155 return ps
->fullname
;
1162 find_symbol_file_from_partial (struct objfile
*objfile
, const char *name
)
1164 struct partial_symtab
*pst
;
1166 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
1168 if (lookup_partial_symbol (pst
, name
, 1, VAR_DOMAIN
))
1169 return pst
->filename
;
1174 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1175 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1176 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1177 ever returns non-zero, and otherwise returns 0. */
1180 map_block (const char *name
, domain_enum
namespace, struct objfile
*objfile
,
1181 struct block
*block
,
1182 int (*callback
) (struct block
*, struct symbol
*, void *),
1183 void *data
, symbol_compare_ftype
*match
)
1185 struct dict_iterator iter
;
1188 for (sym
= dict_iter_match_first (BLOCK_DICT (block
), name
, match
, &iter
);
1189 sym
!= NULL
; sym
= dict_iter_match_next (name
, match
, &iter
))
1191 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym
),
1192 SYMBOL_DOMAIN (sym
), namespace))
1194 if (callback (block
, sym
, data
))
1202 /* Psymtab version of map_matching_symbols. See its definition in
1203 the definition of quick_symbol_functions in symfile.h. */
1206 map_matching_symbols_psymtab (const char *name
, domain_enum
namespace,
1207 struct objfile
*objfile
, int global
,
1208 int (*callback
) (struct block
*,
1209 struct symbol
*, void *),
1211 symbol_compare_ftype
*match
,
1212 symbol_compare_ftype
*ordered_compare
)
1214 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1215 struct partial_symtab
*ps
;
1217 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1221 || match_partial_symbol (ps
, global
, name
, namespace, match
,
1224 struct symtab
*s
= psymtab_to_symtab (ps
);
1225 struct block
*block
;
1227 if (s
== NULL
|| !s
->primary
)
1229 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), block_kind
);
1230 if (map_block (name
, namespace, objfile
, block
,
1231 callback
, data
, match
))
1233 if (callback (block
, NULL
, data
))
1240 expand_symtabs_matching_via_partial
1241 (struct objfile
*objfile
,
1242 int (*file_matcher
) (const char *, void *),
1243 int (*name_matcher
) (const char *, void *),
1244 enum search_domain kind
,
1247 struct partial_symtab
*ps
;
1249 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1251 struct partial_symbol
**psym
;
1252 struct partial_symbol
**bound
, **gbound
, **sbound
;
1258 if (file_matcher
&& ! (*file_matcher
) (ps
->filename
, data
))
1261 gbound
= objfile
->global_psymbols
.list
1262 + ps
->globals_offset
+ ps
->n_global_syms
;
1263 sbound
= objfile
->static_psymbols
.list
1264 + ps
->statics_offset
+ ps
->n_static_syms
;
1267 /* Go through all of the symbols stored in a partial
1268 symtab in one loop. */
1269 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1274 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
1276 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1287 if ((kind
== ALL_DOMAIN
1288 || (kind
== VARIABLES_DOMAIN
1289 && SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
1290 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
1291 || (kind
== FUNCTIONS_DOMAIN
1292 && SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
1293 || (kind
== TYPES_DOMAIN
1294 && SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
))
1295 && (*name_matcher
) (SYMBOL_SEARCH_NAME (*psym
), data
))
1297 psymtab_to_symtab (ps
);
1307 objfile_has_psyms (struct objfile
*objfile
)
1309 return objfile
->psymtabs
!= NULL
;
1312 const struct quick_symbol_functions psym_functions
=
1315 find_last_source_symtab_from_partial
,
1316 forget_cached_source_info_partial
,
1317 partial_map_symtabs_matching_filename
,
1318 lookup_symbol_aux_psymtabs
,
1319 pre_expand_symtabs_matching_psymtabs
,
1320 print_psymtab_stats_for_objfile
,
1321 dump_psymtabs_for_objfile
,
1323 read_symtabs_for_function
,
1324 expand_partial_symbol_tables
,
1325 read_psymtabs_with_filename
,
1326 find_symbol_file_from_partial
,
1327 map_matching_symbols_psymtab
,
1328 expand_symtabs_matching_via_partial
,
1329 find_pc_sect_symtab_from_partial
,
1330 map_symbol_filenames_psymtab
1335 /* This compares two partial symbols by names, using strcmp_iw_ordered
1336 for the comparison. */
1339 compare_psymbols (const void *s1p
, const void *s2p
)
1341 struct partial_symbol
*const *s1
= s1p
;
1342 struct partial_symbol
*const *s2
= s2p
;
1344 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1
),
1345 SYMBOL_SEARCH_NAME (*s2
));
1349 sort_pst_symbols (struct partial_symtab
*pst
)
1351 /* Sort the global list; don't sort the static list. */
1353 qsort (pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
,
1354 pst
->n_global_syms
, sizeof (struct partial_symbol
*),
1358 /* Allocate and partially fill a partial symtab. It will be
1359 completely filled at the end of the symbol list.
1361 FILENAME is the name of the symbol-file we are reading from. */
1363 struct partial_symtab
*
1364 start_psymtab_common (struct objfile
*objfile
,
1365 struct section_offsets
*section_offsets
,
1366 const char *filename
,
1367 CORE_ADDR textlow
, struct partial_symbol
**global_syms
,
1368 struct partial_symbol
**static_syms
)
1370 struct partial_symtab
*psymtab
;
1372 psymtab
= allocate_psymtab (filename
, objfile
);
1373 psymtab
->section_offsets
= section_offsets
;
1374 psymtab
->textlow
= textlow
;
1375 psymtab
->texthigh
= psymtab
->textlow
; /* default */
1376 psymtab
->globals_offset
= global_syms
- objfile
->global_psymbols
.list
;
1377 psymtab
->statics_offset
= static_syms
- objfile
->static_psymbols
.list
;
1381 /* Calculate a hash code for the given partial symbol. The hash is
1382 calculated using the symbol's value, language, domain, class
1383 and name. These are the values which are set by
1384 add_psymbol_to_bcache. */
1386 static unsigned long
1387 psymbol_hash (const void *addr
, int length
)
1389 unsigned long h
= 0;
1390 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1391 unsigned int lang
= psymbol
->ginfo
.language
;
1392 unsigned int domain
= PSYMBOL_DOMAIN (psymbol
);
1393 unsigned int class = PSYMBOL_CLASS (psymbol
);
1395 h
= hash_continue (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1396 h
= hash_continue (&lang
, sizeof (unsigned int), h
);
1397 h
= hash_continue (&domain
, sizeof (unsigned int), h
);
1398 h
= hash_continue (&class, sizeof (unsigned int), h
);
1399 h
= hash_continue (psymbol
->ginfo
.name
, strlen (psymbol
->ginfo
.name
), h
);
1404 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1405 For the comparison this function uses a symbols value,
1406 language, domain, class and name. */
1409 psymbol_compare (const void *addr1
, const void *addr2
, int length
)
1411 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1412 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1414 return (memcmp (&sym1
->ginfo
.value
, &sym1
->ginfo
.value
,
1415 sizeof (sym1
->ginfo
.value
)) == 0
1416 && sym1
->ginfo
.language
== sym2
->ginfo
.language
1417 && PSYMBOL_DOMAIN (sym1
) == PSYMBOL_DOMAIN (sym2
)
1418 && PSYMBOL_CLASS (sym1
) == PSYMBOL_CLASS (sym2
)
1419 && sym1
->ginfo
.name
== sym2
->ginfo
.name
);
1422 /* Initialize a partial symbol bcache. */
1424 struct psymbol_bcache
*
1425 psymbol_bcache_init (void)
1427 struct psymbol_bcache
*bcache
= XCALLOC (1, struct psymbol_bcache
);
1428 bcache
->bcache
= bcache_xmalloc (psymbol_hash
, psymbol_compare
);
1432 /* Free a partial symbol bcache. */
1434 psymbol_bcache_free (struct psymbol_bcache
*bcache
)
1439 bcache_xfree (bcache
->bcache
);
1443 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1446 psymbol_bcache_get_bcache (struct psymbol_bcache
*bcache
)
1448 return bcache
->bcache
;
1451 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1452 symbol before, add a copy to BCACHE. In either case, return a pointer
1453 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1454 1 in case of new entry or 0 if returning an old entry. */
1456 static const struct partial_symbol
*
1457 psymbol_bcache_full (struct partial_symbol
*sym
,
1458 struct psymbol_bcache
*bcache
,
1461 return bcache_full (sym
,
1462 sizeof (struct partial_symbol
),
1467 /* Helper function, initialises partial symbol structure and stashes
1468 it into objfile's bcache. Note that our caching mechanism will
1469 use all fields of struct partial_symbol to determine hash value of the
1470 structure. In other words, having two symbols with the same name but
1471 different domain (or address) is possible and correct. */
1473 static const struct partial_symbol
*
1474 add_psymbol_to_bcache (const char *name
, int namelength
, int copy_name
,
1476 enum address_class
class,
1477 long val
, /* Value as a long */
1478 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1479 enum language language
, struct objfile
*objfile
,
1482 struct partial_symbol psymbol
;
1484 /* We must ensure that the entire 'value' field has been zeroed
1485 before assigning to it, because an assignment may not write the
1487 memset (&psymbol
.ginfo
.value
, 0, sizeof (psymbol
.ginfo
.value
));
1489 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1492 SYMBOL_VALUE (&psymbol
) = val
;
1496 SYMBOL_VALUE_ADDRESS (&psymbol
) = coreaddr
;
1498 SYMBOL_SECTION (&psymbol
) = 0;
1499 SYMBOL_OBJ_SECTION (&psymbol
) = NULL
;
1500 SYMBOL_SET_LANGUAGE (&psymbol
, language
);
1501 PSYMBOL_DOMAIN (&psymbol
) = domain
;
1502 PSYMBOL_CLASS (&psymbol
) = class;
1504 SYMBOL_SET_NAMES (&psymbol
, name
, namelength
, copy_name
, objfile
);
1506 /* Stash the partial symbol away in the cache. */
1507 return psymbol_bcache_full (&psymbol
,
1508 objfile
->psymbol_cache
,
1512 /* Increase the space allocated for LISTP, which is probably
1513 global_psymbols or static_psymbols. This space will eventually
1514 be freed in free_objfile(). */
1517 extend_psymbol_list (struct psymbol_allocation_list
*listp
,
1518 struct objfile
*objfile
)
1522 if (listp
->size
== 0)
1525 listp
->list
= (struct partial_symbol
**)
1526 xmalloc (new_size
* sizeof (struct partial_symbol
*));
1530 new_size
= listp
->size
* 2;
1531 listp
->list
= (struct partial_symbol
**)
1532 xrealloc ((char *) listp
->list
,
1533 new_size
* sizeof (struct partial_symbol
*));
1535 /* Next assumes we only went one over. Should be good if
1536 program works correctly. */
1537 listp
->next
= listp
->list
+ listp
->size
;
1538 listp
->size
= new_size
;
1541 /* Helper function, adds partial symbol to the given partial symbol
1545 append_psymbol_to_list (struct psymbol_allocation_list
*list
,
1546 const struct partial_symbol
*psym
,
1547 struct objfile
*objfile
)
1549 if (list
->next
>= list
->list
+ list
->size
)
1550 extend_psymbol_list (list
, objfile
);
1551 *list
->next
++ = (struct partial_symbol
*) psym
;
1552 OBJSTAT (objfile
, n_psyms
++);
1555 /* Add a symbol with a long value to a psymtab.
1556 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1557 Return the partial symbol that has been added. */
1560 add_psymbol_to_list (const char *name
, int namelength
, int copy_name
,
1562 enum address_class
class,
1563 struct psymbol_allocation_list
*list
,
1564 long val
, /* Value as a long */
1565 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1566 enum language language
, struct objfile
*objfile
)
1568 const struct partial_symbol
*psym
;
1572 /* Stash the partial symbol away in the cache. */
1573 psym
= add_psymbol_to_bcache (name
, namelength
, copy_name
, domain
, class,
1574 val
, coreaddr
, language
, objfile
, &added
);
1576 /* Do not duplicate global partial symbols. */
1577 if (list
== &objfile
->global_psymbols
1581 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1582 append_psymbol_to_list (list
, psym
, objfile
);
1585 /* Initialize storage for partial symbols. */
1588 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1590 /* Free any previously allocated psymbol lists. */
1592 if (objfile
->global_psymbols
.list
)
1594 xfree (objfile
->global_psymbols
.list
);
1596 if (objfile
->static_psymbols
.list
)
1598 xfree (objfile
->static_psymbols
.list
);
1601 /* Current best guess is that approximately a twentieth
1602 of the total symbols (in a debugging file) are global or static
1603 oriented symbols. */
1605 objfile
->global_psymbols
.size
= total_symbols
/ 10;
1606 objfile
->static_psymbols
.size
= total_symbols
/ 10;
1608 if (objfile
->global_psymbols
.size
> 0)
1610 objfile
->global_psymbols
.next
=
1611 objfile
->global_psymbols
.list
= (struct partial_symbol
**)
1612 xmalloc ((objfile
->global_psymbols
.size
1613 * sizeof (struct partial_symbol
*)));
1615 if (objfile
->static_psymbols
.size
> 0)
1617 objfile
->static_psymbols
.next
=
1618 objfile
->static_psymbols
.list
= (struct partial_symbol
**)
1619 xmalloc ((objfile
->static_psymbols
.size
1620 * sizeof (struct partial_symbol
*)));
1624 struct partial_symtab
*
1625 allocate_psymtab (const char *filename
, struct objfile
*objfile
)
1627 struct partial_symtab
*psymtab
;
1629 if (objfile
->free_psymtabs
)
1631 psymtab
= objfile
->free_psymtabs
;
1632 objfile
->free_psymtabs
= psymtab
->next
;
1635 psymtab
= (struct partial_symtab
*)
1636 obstack_alloc (&objfile
->objfile_obstack
,
1637 sizeof (struct partial_symtab
));
1639 memset (psymtab
, 0, sizeof (struct partial_symtab
));
1640 psymtab
->filename
= obsavestring (filename
, strlen (filename
),
1641 &objfile
->objfile_obstack
);
1642 psymtab
->symtab
= NULL
;
1644 /* Prepend it to the psymtab list for the objfile it belongs to.
1645 Psymtabs are searched in most recent inserted -> least recent
1648 psymtab
->objfile
= objfile
;
1649 psymtab
->next
= objfile
->psymtabs
;
1650 objfile
->psymtabs
= psymtab
;
1656 discard_psymtab (struct partial_symtab
*pst
)
1658 struct partial_symtab
**prev_pst
;
1661 Empty psymtabs happen as a result of header files which don't
1662 have any symbols in them. There can be a lot of them. But this
1663 check is wrong, in that a psymtab with N_SLINE entries but
1664 nothing else is not empty, but we don't realize that. Fixing
1665 that without slowing things down might be tricky. */
1667 /* First, snip it out of the psymtab chain. */
1669 prev_pst
= &(pst
->objfile
->psymtabs
);
1670 while ((*prev_pst
) != pst
)
1671 prev_pst
= &((*prev_pst
)->next
);
1672 (*prev_pst
) = pst
->next
;
1674 /* Next, put it on a free list for recycling. */
1676 pst
->next
= pst
->objfile
->free_psymtabs
;
1677 pst
->objfile
->free_psymtabs
= pst
;
1683 maintenance_print_psymbols (char *args
, int from_tty
)
1686 struct ui_file
*outfile
;
1687 struct cleanup
*cleanups
;
1688 char *symname
= NULL
;
1689 char *filename
= DEV_TTY
;
1690 struct objfile
*objfile
;
1691 struct partial_symtab
*ps
;
1698 print-psymbols takes an output file name and optional symbol file name"));
1700 argv
= gdb_buildargv (args
);
1701 cleanups
= make_cleanup_freeargv (argv
);
1703 if (argv
[0] != NULL
)
1706 /* If a second arg is supplied, it is a source file name to match on. */
1707 if (argv
[1] != NULL
)
1713 filename
= tilde_expand (filename
);
1714 make_cleanup (xfree
, filename
);
1716 outfile
= gdb_fopen (filename
, FOPEN_WT
);
1718 perror_with_name (filename
);
1719 make_cleanup_ui_file_delete (outfile
);
1722 ALL_PSYMTABS (objfile
, ps
)
1723 if (symname
== NULL
|| filename_cmp (symname
, ps
->filename
) == 0)
1724 dump_psymtab (objfile
, ps
, outfile
);
1726 do_cleanups (cleanups
);
1729 /* List all the partial symbol tables whose names match REGEXP (optional). */
1731 maintenance_info_psymtabs (char *regexp
, int from_tty
)
1733 struct program_space
*pspace
;
1734 struct objfile
*objfile
;
1739 ALL_PSPACES (pspace
)
1740 ALL_PSPACE_OBJFILES (pspace
, objfile
)
1742 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1743 struct partial_symtab
*psymtab
;
1745 /* We don't want to print anything for this objfile until we
1746 actually find a symtab whose name matches. */
1747 int printed_objfile_start
= 0;
1749 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1754 || re_exec (psymtab
->filename
))
1756 if (! printed_objfile_start
)
1758 printf_filtered ("{ objfile %s ", objfile
->name
);
1760 printf_filtered ("((struct objfile *) %s)\n",
1761 host_address_to_string (objfile
));
1762 printed_objfile_start
= 1;
1765 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1767 printf_filtered ("((struct partial_symtab *) %s)\n",
1768 host_address_to_string (psymtab
));
1770 printf_filtered (" readin %s\n",
1771 psymtab
->readin
? "yes" : "no");
1772 printf_filtered (" fullname %s\n",
1774 ? psymtab
->fullname
: "(null)");
1775 printf_filtered (" text addresses ");
1776 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
),
1778 printf_filtered (" -- ");
1779 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
),
1781 printf_filtered ("\n");
1782 printf_filtered (" psymtabs_addrmap_supported %s\n",
1783 (psymtab
->psymtabs_addrmap_supported
1785 printf_filtered (" globals ");
1786 if (psymtab
->n_global_syms
)
1788 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1789 host_address_to_string (psymtab
->objfile
->global_psymbols
.list
1790 + psymtab
->globals_offset
),
1791 psymtab
->n_global_syms
);
1794 printf_filtered ("(none)\n");
1795 printf_filtered (" statics ");
1796 if (psymtab
->n_static_syms
)
1798 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1799 host_address_to_string (psymtab
->objfile
->static_psymbols
.list
1800 + psymtab
->statics_offset
),
1801 psymtab
->n_static_syms
);
1804 printf_filtered ("(none)\n");
1805 printf_filtered (" dependencies ");
1806 if (psymtab
->number_of_dependencies
)
1810 printf_filtered ("{\n");
1811 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1813 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1815 /* Note the string concatenation there --- no comma. */
1816 printf_filtered (" psymtab %s "
1817 "((struct partial_symtab *) %s)\n",
1819 host_address_to_string (dep
));
1821 printf_filtered (" }\n");
1824 printf_filtered ("(none)\n");
1825 printf_filtered (" }\n");
1829 if (printed_objfile_start
)
1830 printf_filtered ("}\n");
1834 /* Check consistency of psymtabs and symtabs. */
1837 maintenance_check_symtabs (char *ignore
, int from_tty
)
1840 struct partial_symbol
**psym
;
1841 struct symtab
*s
= NULL
;
1842 struct partial_symtab
*ps
;
1843 struct blockvector
*bv
;
1844 struct objfile
*objfile
;
1848 ALL_PSYMTABS (objfile
, ps
)
1850 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1852 s
= psymtab_to_symtab (ps
);
1855 bv
= BLOCKVECTOR (s
);
1856 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1857 psym
= ps
->objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1858 length
= ps
->n_static_syms
;
1861 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
1862 SYMBOL_DOMAIN (*psym
));
1865 printf_filtered ("Static symbol `");
1866 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
1867 printf_filtered ("' only found in ");
1868 puts_filtered (ps
->filename
);
1869 printf_filtered (" psymtab\n");
1873 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1874 psym
= ps
->objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1875 length
= ps
->n_global_syms
;
1878 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
1879 SYMBOL_DOMAIN (*psym
));
1882 printf_filtered ("Global symbol `");
1883 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
1884 printf_filtered ("' only found in ");
1885 puts_filtered (ps
->filename
);
1886 printf_filtered (" psymtab\n");
1890 if (ps
->texthigh
< ps
->textlow
)
1892 printf_filtered ("Psymtab ");
1893 puts_filtered (ps
->filename
);
1894 printf_filtered (" covers bad range ");
1895 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
1896 printf_filtered (" - ");
1897 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
1898 printf_filtered ("\n");
1901 if (ps
->texthigh
== 0)
1903 if (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
))
1905 printf_filtered ("Psymtab ");
1906 puts_filtered (ps
->filename
);
1907 printf_filtered (" covers ");
1908 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
1909 printf_filtered (" - ");
1910 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
1911 printf_filtered (" but symtab covers only ");
1912 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
1913 printf_filtered (" - ");
1914 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
1915 printf_filtered ("\n");
1923 expand_partial_symbol_names (int (*fun
) (const char *, void *),
1926 struct objfile
*objfile
;
1928 ALL_OBJFILES (objfile
)
1931 objfile
->sf
->qf
->expand_symtabs_matching (objfile
, NULL
, fun
,
1937 map_partial_symbol_filenames (symbol_filename_ftype
*fun
, void *data
,
1940 struct objfile
*objfile
;
1942 ALL_OBJFILES (objfile
)
1945 objfile
->sf
->qf
->map_symbol_filenames (objfile
, fun
, data
,