1 /* Partial symbol tables.
3 Copyright (C) 2009, 2010, 2011 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"
38 #define DEV_TTY "/dev/tty"
43 struct bcache
*bcache
;
46 /* A fast way to get from a psymtab to its symtab (after the first time). */
47 #define PSYMTAB_TO_SYMTAB(pst) \
48 ((pst) -> symtab != NULL ? (pst) -> symtab : psymtab_to_symtab (pst))
50 static struct partial_symbol
*match_partial_symbol (struct partial_symtab
*,
52 const char *, domain_enum
,
53 symbol_compare_ftype
*,
54 symbol_compare_ftype
*);
56 static struct partial_symbol
*lookup_partial_symbol (struct partial_symtab
*,
60 static char *psymtab_to_fullname (struct partial_symtab
*ps
);
62 static struct partial_symbol
*find_pc_sect_psymbol (struct partial_symtab
*,
64 struct obj_section
*);
66 static struct partial_symbol
*fixup_psymbol_section (struct partial_symbol
68 struct objfile
*objfile
);
70 static struct symtab
*psymtab_to_symtab (struct partial_symtab
*pst
);
72 /* Ensure that the partial symbols for OBJFILE have been loaded. This
73 function always returns its argument, as a convenience. */
76 require_partial_symbols (struct objfile
*objfile
, int verbose
)
78 if ((objfile
->flags
& OBJF_PSYMTABS_READ
) == 0)
80 objfile
->flags
|= OBJF_PSYMTABS_READ
;
82 if (objfile
->sf
->sym_read_psymbols
)
86 printf_unfiltered (_("Reading symbols from %s..."),
88 gdb_flush (gdb_stdout
);
90 (*objfile
->sf
->sym_read_psymbols
) (objfile
);
93 if (!objfile_has_symbols (objfile
))
96 printf_unfiltered (_("(no debugging symbols found)..."));
100 printf_unfiltered (_("done.\n"));
108 /* Traverse all psymtabs in one objfile, requiring that the psymtabs
111 #define ALL_OBJFILE_PSYMTABS_REQUIRED(objfile, p) \
112 for ((p) = require_partial_symbols (objfile, 1)->psymtabs; \
116 /* We want to make sure this file always requires psymtabs. */
118 #undef ALL_OBJFILE_PSYMTABS
120 /* Traverse all psymtabs in all objfiles. */
122 #define ALL_PSYMTABS(objfile, p) \
123 ALL_OBJFILES (objfile) \
124 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
126 /* Lookup the partial symbol table of a source file named NAME.
127 *If* there is no '/' in the name, a match after a '/'
128 in the psymtab filename will also work. */
130 static struct partial_symtab
*
131 lookup_partial_symtab (struct objfile
*objfile
, const char *name
,
132 const char *full_path
, const char *real_path
)
134 struct partial_symtab
*pst
;
136 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
138 if (FILENAME_CMP (name
, pst
->filename
) == 0)
143 /* If the user gave us an absolute path, try to find the file in
144 this symtab and use its absolute path. */
145 if (full_path
!= NULL
)
147 psymtab_to_fullname (pst
);
148 if (pst
->fullname
!= NULL
149 && FILENAME_CMP (full_path
, pst
->fullname
) == 0)
155 if (real_path
!= NULL
)
158 psymtab_to_fullname (pst
);
159 if (pst
->fullname
!= NULL
)
161 rp
= gdb_realpath (pst
->fullname
);
162 make_cleanup (xfree
, rp
);
164 if (rp
!= NULL
&& FILENAME_CMP (real_path
, rp
) == 0)
171 /* Now, search for a matching tail (only if name doesn't have any dirs). */
173 if (lbasename (name
) == name
)
174 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
176 if (FILENAME_CMP (lbasename (pst
->filename
), name
) == 0)
184 lookup_symtab_via_partial_symtab (struct objfile
*objfile
, const char *name
,
185 const char *full_path
, const char *real_path
,
186 struct symtab
**result
)
188 struct partial_symtab
*ps
;
190 ps
= lookup_partial_symtab (objfile
, name
, full_path
, real_path
);
195 error (_("Internal: readin %s pst for `%s' found when no symtab found."),
198 *result
= PSYMTAB_TO_SYMTAB (ps
);
202 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
203 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
205 static struct partial_symtab
*
206 find_pc_sect_psymtab_closer (CORE_ADDR pc
, struct obj_section
*section
,
207 struct partial_symtab
*pst
,
208 struct minimal_symbol
*msymbol
)
210 struct objfile
*objfile
= pst
->objfile
;
211 struct partial_symtab
*tpst
;
212 struct partial_symtab
*best_pst
= pst
;
213 CORE_ADDR best_addr
= pst
->textlow
;
215 /* An objfile that has its functions reordered might have
216 many partial symbol tables containing the PC, but
217 we want the partial symbol table that contains the
218 function containing the PC. */
219 if (!(objfile
->flags
& OBJF_REORDERED
) &&
220 section
== 0) /* Can't validate section this way. */
226 /* The code range of partial symtabs sometimes overlap, so, in
227 the loop below, we need to check all partial symtabs and
228 find the one that fits better for the given PC address. We
229 select the partial symtab that contains a symbol whose
230 address is closest to the PC address. By closest we mean
231 that find_pc_sect_symbol returns the symbol with address
232 that is closest and still less than the given PC. */
233 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
235 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
237 struct partial_symbol
*p
;
240 /* NOTE: This assumes that every psymbol has a
241 corresponding msymbol, which is not necessarily
242 true; the debug info might be much richer than the
243 object's symbol table. */
244 p
= find_pc_sect_psymbol (tpst
, pc
, section
);
246 && SYMBOL_VALUE_ADDRESS (p
)
247 == SYMBOL_VALUE_ADDRESS (msymbol
))
250 /* Also accept the textlow value of a psymtab as a
251 "symbol", to provide some support for partial
252 symbol tables with line information but no debug
253 symbols (e.g. those produced by an assembler). */
255 this_addr
= SYMBOL_VALUE_ADDRESS (p
);
257 this_addr
= tpst
->textlow
;
259 /* Check whether it is closer than our current
260 BEST_ADDR. Since this symbol address is
261 necessarily lower or equal to PC, the symbol closer
262 to PC is the symbol which address is the highest.
263 This way we return the psymtab which contains such
264 best match symbol. This can help in cases where the
265 symbol information/debuginfo is not complete, like
266 for instance on IRIX6 with gcc, where no debug info
267 is emitted for statics. (See also the nodebug.exp
269 if (this_addr
> best_addr
)
271 best_addr
= this_addr
;
279 /* Find which partial symtab contains PC and SECTION. Return 0 if
280 none. We return the psymtab that contains a symbol whose address
281 exactly matches PC, or, if we cannot find an exact match, the
282 psymtab that contains a symbol whose address is closest to PC. */
283 static struct partial_symtab
*
284 find_pc_sect_psymtab (struct objfile
*objfile
, CORE_ADDR pc
,
285 struct obj_section
*section
,
286 struct minimal_symbol
*msymbol
)
288 struct partial_symtab
*pst
;
290 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
291 than the later used TEXTLOW/TEXTHIGH one. */
293 if (objfile
->psymtabs_addrmap
!= NULL
)
295 pst
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
298 /* FIXME: addrmaps currently do not handle overlayed sections,
299 so fall back to the non-addrmap case if we're debugging
300 overlays and the addrmap returned the wrong section. */
301 if (overlay_debugging
&& msymbol
&& section
)
303 struct partial_symbol
*p
;
305 /* NOTE: This assumes that every psymbol has a
306 corresponding msymbol, which is not necessarily
307 true; the debug info might be much richer than the
308 object's symbol table. */
309 p
= find_pc_sect_psymbol (pst
, pc
, section
);
311 || SYMBOL_VALUE_ADDRESS (p
)
312 != SYMBOL_VALUE_ADDRESS (msymbol
))
316 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
317 PSYMTABS_ADDRMAP we used has already the best 1-byte
318 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
319 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
328 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
329 which still have no corresponding full SYMTABs read. But it is not
330 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
333 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
334 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
335 debug info type in single OBJFILE. */
337 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
338 if (pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
340 struct partial_symtab
*best_pst
;
342 best_pst
= find_pc_sect_psymtab_closer (pc
, section
, pst
, msymbol
);
343 if (best_pst
!= NULL
)
350 static struct symtab
*
351 find_pc_sect_symtab_from_partial (struct objfile
*objfile
,
352 struct minimal_symbol
*msymbol
,
353 CORE_ADDR pc
, struct obj_section
*section
,
356 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
360 if (warn_if_readin
&& ps
->readin
)
361 /* Might want to error() here (in case symtab is corrupt and
362 will cause a core dump), but maybe we can successfully
363 continue, so let's not. */
365 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
366 paddress (get_objfile_arch (ps
->objfile
), pc
));
367 return PSYMTAB_TO_SYMTAB (ps
);
372 /* Find which partial symbol within a psymtab matches PC and SECTION.
375 static struct partial_symbol
*
376 find_pc_sect_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
,
377 struct obj_section
*section
)
379 struct partial_symbol
*best
= NULL
, *p
, **pp
;
382 gdb_assert (psymtab
!= NULL
);
384 /* Cope with programs that start at address 0. */
385 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
387 /* Search the global symbols as well as the static symbols, so that
388 find_pc_partial_function doesn't use a minimal symbol and thus
389 cache a bad endaddr. */
390 for (pp
= psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
391 (pp
- (psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
392 < psymtab
->n_global_syms
);
396 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
397 && SYMBOL_CLASS (p
) == LOC_BLOCK
398 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
399 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
400 || (psymtab
->textlow
== 0
401 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
403 if (section
) /* Match on a specific section. */
405 fixup_psymbol_section (p
, psymtab
->objfile
);
406 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p
), section
))
409 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
414 for (pp
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
415 (pp
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
416 < psymtab
->n_static_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
);
441 static struct partial_symbol
*
442 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
449 if (SYMBOL_OBJ_SECTION (psym
))
452 gdb_assert (objfile
);
454 switch (SYMBOL_CLASS (psym
))
459 addr
= SYMBOL_VALUE_ADDRESS (psym
);
462 /* Nothing else will be listed in the minsyms -- no use looking
467 fixup_section (&psym
->ginfo
, addr
, objfile
);
472 static struct symtab
*
473 lookup_symbol_aux_psymtabs (struct objfile
*objfile
,
474 int block_index
, const char *name
,
475 const domain_enum domain
)
477 struct partial_symtab
*ps
;
478 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
480 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
482 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, psymtab_index
, domain
))
483 return PSYMTAB_TO_SYMTAB (ps
);
489 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
490 the global block of PST if GLOBAL, and otherwise the static block.
491 MATCH is the comparison operation that returns true iff MATCH (s,
492 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
493 non-null, the symbols in the block are assumed to be ordered
494 according to it (allowing binary search). It must be compatible
495 with MATCH. Returns the symbol, if found, and otherwise NULL. */
497 static struct partial_symbol
*
498 match_partial_symbol (struct partial_symtab
*pst
, int global
,
499 const char *name
, domain_enum domain
,
500 symbol_compare_ftype
*match
,
501 symbol_compare_ftype
*ordered_compare
)
503 struct partial_symbol
**start
, **psym
;
504 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
505 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
506 int do_linear_search
= 1;
511 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
512 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
514 if (global
&& ordered_compare
) /* Can use a binary search. */
516 do_linear_search
= 0;
518 /* Binary search. This search is guaranteed to end with center
519 pointing at the earliest partial symbol whose name might be
520 correct. At that point *all* partial symbols with an
521 appropriate name will be checked against the correct
525 top
= start
+ length
- 1;
529 center
= bottom
+ (top
- bottom
) / 2;
530 gdb_assert (center
< top
);
531 if (!do_linear_search
532 && (SYMBOL_LANGUAGE (*center
) == language_java
))
533 do_linear_search
= 1;
534 if (ordered_compare (SYMBOL_SEARCH_NAME (*center
), name
) >= 0)
539 gdb_assert (top
== bottom
);
541 while (top
<= real_top
542 && match (SYMBOL_SEARCH_NAME (*top
), name
) == 0)
544 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
545 SYMBOL_DOMAIN (*top
), domain
))
551 /* Can't use a binary search or else we found during the binary search that
552 we should also do a linear search. */
554 if (do_linear_search
)
556 for (psym
= start
; psym
< start
+ length
; psym
++)
558 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
559 SYMBOL_DOMAIN (*psym
), domain
)
560 && match (SYMBOL_SEARCH_NAME (*psym
), name
) == 0)
569 pre_expand_symtabs_matching_psymtabs (struct objfile
*objfile
,
570 int kind
, const char *name
,
576 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
577 Check the global symbols if GLOBAL, the static symbols if not. */
579 static struct partial_symbol
*
580 lookup_partial_symbol (struct partial_symtab
*pst
, const char *name
,
581 int global
, domain_enum domain
)
583 struct partial_symbol
**start
, **psym
;
584 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
585 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
586 int do_linear_search
= 1;
593 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
594 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
596 if (global
) /* This means we can use a binary search. */
598 do_linear_search
= 0;
600 /* Binary search. This search is guaranteed to end with center
601 pointing at the earliest partial symbol whose name might be
602 correct. At that point *all* partial symbols with an
603 appropriate name will be checked against the correct
607 top
= start
+ length
- 1;
611 center
= bottom
+ (top
- bottom
) / 2;
613 internal_error (__FILE__
, __LINE__
,
614 _("failed internal consistency check"));
615 if (!do_linear_search
616 && SYMBOL_LANGUAGE (*center
) == language_java
)
618 do_linear_search
= 1;
620 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center
), name
) >= 0)
629 if (!(top
== bottom
))
630 internal_error (__FILE__
, __LINE__
,
631 _("failed internal consistency check"));
633 while (top
<= real_top
634 && SYMBOL_MATCHES_SEARCH_NAME (*top
, name
))
636 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
637 SYMBOL_DOMAIN (*top
), domain
))
643 /* Can't use a binary search or else we found during the binary search that
644 we should also do a linear search. */
646 if (do_linear_search
)
648 for (psym
= start
; psym
< start
+ length
; psym
++)
650 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
651 SYMBOL_DOMAIN (*psym
), domain
)
652 && SYMBOL_MATCHES_SEARCH_NAME (*psym
, name
))
660 /* Get the symbol table that corresponds to a partial_symtab.
661 This is fast after the first time you do it. In fact, there
662 is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
665 static struct symtab
*
666 psymtab_to_symtab (struct partial_symtab
*pst
)
668 /* If it's been looked up before, return it. */
672 /* If it has not yet been read in, read it. */
675 struct cleanup
*back_to
= increment_reading_symtab ();
677 (*pst
->read_symtab
) (pst
);
678 do_cleanups (back_to
);
685 relocate_psymtabs (struct objfile
*objfile
,
686 struct section_offsets
*new_offsets
,
687 struct section_offsets
*delta
)
689 struct partial_symbol
**psym
;
690 struct partial_symtab
*p
;
692 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
694 p
->textlow
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
695 p
->texthigh
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
698 for (psym
= objfile
->global_psymbols
.list
;
699 psym
< objfile
->global_psymbols
.next
;
702 fixup_psymbol_section (*psym
, objfile
);
703 if (SYMBOL_SECTION (*psym
) >= 0)
704 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
705 SYMBOL_SECTION (*psym
));
707 for (psym
= objfile
->static_psymbols
.list
;
708 psym
< objfile
->static_psymbols
.next
;
711 fixup_psymbol_section (*psym
, objfile
);
712 if (SYMBOL_SECTION (*psym
) >= 0)
713 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
714 SYMBOL_SECTION (*psym
));
718 static struct symtab
*
719 find_last_source_symtab_from_partial (struct objfile
*ofp
)
721 struct partial_symtab
*ps
;
722 struct partial_symtab
*cs_pst
= 0;
724 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp
, ps
)
726 const char *name
= ps
->filename
;
727 int len
= strlen (name
);
729 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
730 || strcmp (name
, "<<C++-namespaces>>") == 0)))
738 internal_error (__FILE__
, __LINE__
,
739 _("select_source_symtab: "
740 "readin pst found and no symtabs."));
743 return PSYMTAB_TO_SYMTAB (cs_pst
);
749 forget_cached_source_info_partial (struct objfile
*objfile
)
751 struct partial_symtab
*pst
;
753 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
755 if (pst
->fullname
!= NULL
)
757 xfree (pst
->fullname
);
758 pst
->fullname
= NULL
;
764 print_partial_symbols (struct gdbarch
*gdbarch
,
765 struct partial_symbol
**p
, int count
, char *what
,
766 struct ui_file
*outfile
)
768 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
771 fprintf_filtered (outfile
, " `%s'", SYMBOL_LINKAGE_NAME (*p
));
772 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
774 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
776 fputs_filtered (", ", outfile
);
777 switch (SYMBOL_DOMAIN (*p
))
780 fputs_filtered ("undefined domain, ", outfile
);
783 /* This is the usual thing -- don't print it. */
786 fputs_filtered ("struct domain, ", outfile
);
789 fputs_filtered ("label domain, ", outfile
);
792 fputs_filtered ("<invalid domain>, ", outfile
);
795 switch (SYMBOL_CLASS (*p
))
798 fputs_filtered ("undefined", outfile
);
801 fputs_filtered ("constant int", outfile
);
804 fputs_filtered ("static", outfile
);
807 fputs_filtered ("register", outfile
);
810 fputs_filtered ("pass by value", outfile
);
813 fputs_filtered ("pass by reference", outfile
);
815 case LOC_REGPARM_ADDR
:
816 fputs_filtered ("register address parameter", outfile
);
819 fputs_filtered ("stack parameter", outfile
);
822 fputs_filtered ("type", outfile
);
825 fputs_filtered ("label", outfile
);
828 fputs_filtered ("function", outfile
);
830 case LOC_CONST_BYTES
:
831 fputs_filtered ("constant bytes", outfile
);
834 fputs_filtered ("unresolved", outfile
);
836 case LOC_OPTIMIZED_OUT
:
837 fputs_filtered ("optimized out", outfile
);
840 fputs_filtered ("computed at runtime", outfile
);
843 fputs_filtered ("<invalid location>", outfile
);
846 fputs_filtered (", ", outfile
);
847 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (*p
)), outfile
);
848 fprintf_filtered (outfile
, "\n");
854 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
855 struct ui_file
*outfile
)
857 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
860 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
862 fprintf_filtered (outfile
, "(object ");
863 gdb_print_host_address (psymtab
, outfile
);
864 fprintf_filtered (outfile
, ")\n\n");
865 fprintf_unfiltered (outfile
, " Read from object file %s (",
867 gdb_print_host_address (objfile
, outfile
);
868 fprintf_unfiltered (outfile
, ")\n");
872 fprintf_filtered (outfile
,
873 " Full symtab was read (at ");
874 gdb_print_host_address (psymtab
->symtab
, outfile
);
875 fprintf_filtered (outfile
, " by function at ");
876 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
877 fprintf_filtered (outfile
, ")\n");
880 fprintf_filtered (outfile
, " Relocate symbols by ");
881 for (i
= 0; i
< psymtab
->objfile
->num_sections
; ++i
)
884 fprintf_filtered (outfile
, ", ");
886 fputs_filtered (paddress (gdbarch
,
887 ANOFFSET (psymtab
->section_offsets
, i
)),
890 fprintf_filtered (outfile
, "\n");
892 fprintf_filtered (outfile
, " Symbols cover text addresses ");
893 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
), outfile
);
894 fprintf_filtered (outfile
, "-");
895 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
), outfile
);
896 fprintf_filtered (outfile
, "\n");
897 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
898 psymtab
->number_of_dependencies
);
899 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
901 fprintf_filtered (outfile
, " %d ", i
);
902 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
903 fprintf_filtered (outfile
, " %s\n",
904 psymtab
->dependencies
[i
]->filename
);
906 if (psymtab
->n_global_syms
> 0)
908 print_partial_symbols (gdbarch
,
909 objfile
->global_psymbols
.list
910 + psymtab
->globals_offset
,
911 psymtab
->n_global_syms
, "Global", outfile
);
913 if (psymtab
->n_static_syms
> 0)
915 print_partial_symbols (gdbarch
,
916 objfile
->static_psymbols
.list
917 + psymtab
->statics_offset
,
918 psymtab
->n_static_syms
, "Static", outfile
);
920 fprintf_filtered (outfile
, "\n");
924 print_psymtab_stats_for_objfile (struct objfile
*objfile
)
927 struct partial_symtab
*ps
;
930 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
935 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
939 dump_psymtabs_for_objfile (struct objfile
*objfile
)
941 struct partial_symtab
*psymtab
;
943 if (objfile
->psymtabs
)
945 printf_filtered ("Psymtabs:\n");
946 for (psymtab
= objfile
->psymtabs
;
948 psymtab
= psymtab
->next
)
950 printf_filtered ("%s at ",
952 gdb_print_host_address (psymtab
, gdb_stdout
);
953 printf_filtered (", ");
954 if (psymtab
->objfile
!= objfile
)
956 printf_filtered ("NOT ON CHAIN! ");
960 printf_filtered ("\n\n");
964 /* Look through the partial symtabs for all symbols which begin
965 by matching FUNC_NAME. Make sure we read that symbol table in. */
968 read_symtabs_for_function (struct objfile
*objfile
, const char *func_name
)
970 struct partial_symtab
*ps
;
972 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
977 if ((lookup_partial_symbol (ps
, func_name
, 1, VAR_DOMAIN
)
979 || (lookup_partial_symbol (ps
, func_name
, 0, VAR_DOMAIN
)
981 psymtab_to_symtab (ps
);
986 expand_partial_symbol_tables (struct objfile
*objfile
)
988 struct partial_symtab
*psymtab
;
990 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
992 psymtab_to_symtab (psymtab
);
997 read_psymtabs_with_filename (struct objfile
*objfile
, const char *filename
)
999 struct partial_symtab
*p
;
1001 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
1003 if (strcmp (filename
, p
->filename
) == 0)
1004 PSYMTAB_TO_SYMTAB (p
);
1009 map_symbol_names_psymtab (struct objfile
*objfile
,
1010 void (*fun
) (const char *, void *), void *data
)
1012 struct partial_symtab
*ps
;
1014 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1016 struct partial_symbol
**psym
;
1018 /* If the psymtab's been read in we'll get it when we search
1019 through the blockvector. */
1023 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1024 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
1025 + ps
->n_global_syms
);
1028 /* If interrupted, then quit. */
1030 (*fun
) (SYMBOL_NATURAL_NAME (*psym
), data
);
1033 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1034 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
1035 + ps
->n_static_syms
);
1039 (*fun
) (SYMBOL_NATURAL_NAME (*psym
), data
);
1045 map_symbol_filenames_psymtab (struct objfile
*objfile
,
1046 void (*fun
) (const char *, const char *,
1050 struct partial_symtab
*ps
;
1052 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1054 const char *fullname
;
1059 fullname
= psymtab_to_fullname (ps
);
1060 (*fun
) (ps
->filename
, fullname
, data
);
1064 int find_and_open_source (const char *filename
,
1065 const char *dirname
,
1068 /* Finds the fullname that a partial_symtab represents.
1070 If this functions finds the fullname, it will save it in ps->fullname
1071 and it will also return the value.
1073 If this function fails to find the file that this partial_symtab represents,
1074 NULL will be returned and ps->fullname will be set to NULL. */
1076 psymtab_to_fullname (struct partial_symtab
*ps
)
1083 /* Don't check ps->fullname here, the file could have been
1084 deleted/moved/..., look for it again. */
1085 r
= find_and_open_source (ps
->filename
, ps
->dirname
, &ps
->fullname
);
1090 return ps
->fullname
;
1097 find_symbol_file_from_partial (struct objfile
*objfile
, const char *name
)
1099 struct partial_symtab
*pst
;
1101 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
1103 if (lookup_partial_symbol (pst
, name
, 1, VAR_DOMAIN
))
1104 return pst
->filename
;
1109 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1110 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1111 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1112 ever returns non-zero, and otherwise returns 0. */
1115 map_block (const char *name
, domain_enum
namespace, struct objfile
*objfile
,
1116 struct block
*block
,
1117 int (*callback
) (struct block
*, struct symbol
*, void *),
1118 void *data
, symbol_compare_ftype
*match
)
1120 struct dict_iterator iter
;
1123 for (sym
= dict_iter_match_first (BLOCK_DICT (block
), name
, match
, &iter
);
1124 sym
!= NULL
; sym
= dict_iter_match_next (name
, match
, &iter
))
1126 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym
),
1127 SYMBOL_DOMAIN (sym
), namespace))
1129 if (callback (block
, sym
, data
))
1137 /* Psymtab version of map_matching_symbols. See its definition in
1138 the definition of quick_symbol_functions in symfile.h. */
1141 map_matching_symbols_psymtab (const char *name
, domain_enum
namespace,
1142 struct objfile
*objfile
, int global
,
1143 int (*callback
) (struct block
*,
1144 struct symbol
*, void *),
1146 symbol_compare_ftype
*match
,
1147 symbol_compare_ftype
*ordered_compare
)
1149 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1150 struct partial_symtab
*ps
;
1152 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1156 || match_partial_symbol (ps
, global
, name
, namespace, match
,
1159 struct symtab
*s
= PSYMTAB_TO_SYMTAB (ps
);
1160 struct block
*block
;
1162 if (s
== NULL
|| !s
->primary
)
1164 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), block_kind
);
1165 if (map_block (name
, namespace, objfile
, block
,
1166 callback
, data
, match
))
1168 if (callback (block
, NULL
, data
))
1175 expand_symtabs_matching_via_partial (struct objfile
*objfile
,
1176 int (*file_matcher
) (const char *,
1178 int (*name_matcher
) (const char *,
1183 struct partial_symtab
*ps
;
1185 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1187 struct partial_symbol
**psym
;
1188 struct partial_symbol
**bound
, **gbound
, **sbound
;
1194 if (! (*file_matcher
) (ps
->filename
, data
))
1197 gbound
= objfile
->global_psymbols
.list
1198 + ps
->globals_offset
+ ps
->n_global_syms
;
1199 sbound
= objfile
->static_psymbols
.list
1200 + ps
->statics_offset
+ ps
->n_static_syms
;
1203 /* Go through all of the symbols stored in a partial
1204 symtab in one loop. */
1205 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1210 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
1212 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1223 if ((*name_matcher
) (SYMBOL_NATURAL_NAME (*psym
), data
)
1224 && ((kind
== VARIABLES_DOMAIN
1225 && SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
1226 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
1227 || (kind
== FUNCTIONS_DOMAIN
1228 && SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
1229 || (kind
== TYPES_DOMAIN
1230 && SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
)))
1232 PSYMTAB_TO_SYMTAB (ps
);
1242 objfile_has_psyms (struct objfile
*objfile
)
1244 return objfile
->psymtabs
!= NULL
;
1247 const struct quick_symbol_functions psym_functions
=
1250 find_last_source_symtab_from_partial
,
1251 forget_cached_source_info_partial
,
1252 lookup_symtab_via_partial_symtab
,
1253 lookup_symbol_aux_psymtabs
,
1254 pre_expand_symtabs_matching_psymtabs
,
1255 print_psymtab_stats_for_objfile
,
1256 dump_psymtabs_for_objfile
,
1258 read_symtabs_for_function
,
1259 expand_partial_symbol_tables
,
1260 read_psymtabs_with_filename
,
1261 find_symbol_file_from_partial
,
1262 map_matching_symbols_psymtab
,
1263 expand_symtabs_matching_via_partial
,
1264 find_pc_sect_symtab_from_partial
,
1265 map_symbol_names_psymtab
,
1266 map_symbol_filenames_psymtab
1271 /* This compares two partial symbols by names, using strcmp_iw_ordered
1272 for the comparison. */
1275 compare_psymbols (const void *s1p
, const void *s2p
)
1277 struct partial_symbol
*const *s1
= s1p
;
1278 struct partial_symbol
*const *s2
= s2p
;
1280 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1
),
1281 SYMBOL_SEARCH_NAME (*s2
));
1285 sort_pst_symbols (struct partial_symtab
*pst
)
1287 /* Sort the global list; don't sort the static list. */
1289 qsort (pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
,
1290 pst
->n_global_syms
, sizeof (struct partial_symbol
*),
1294 /* Allocate and partially fill a partial symtab. It will be
1295 completely filled at the end of the symbol list.
1297 FILENAME is the name of the symbol-file we are reading from. */
1299 struct partial_symtab
*
1300 start_psymtab_common (struct objfile
*objfile
,
1301 struct section_offsets
*section_offsets
,
1302 const char *filename
,
1303 CORE_ADDR textlow
, struct partial_symbol
**global_syms
,
1304 struct partial_symbol
**static_syms
)
1306 struct partial_symtab
*psymtab
;
1308 psymtab
= allocate_psymtab (filename
, objfile
);
1309 psymtab
->section_offsets
= section_offsets
;
1310 psymtab
->textlow
= textlow
;
1311 psymtab
->texthigh
= psymtab
->textlow
; /* default */
1312 psymtab
->globals_offset
= global_syms
- objfile
->global_psymbols
.list
;
1313 psymtab
->statics_offset
= static_syms
- objfile
->static_psymbols
.list
;
1317 /* Calculate a hash code for the given partial symbol. The hash is
1318 calculated using the symbol's value, language, domain, class
1319 and name. These are the values which are set by
1320 add_psymbol_to_bcache. */
1322 static unsigned long
1323 psymbol_hash (const void *addr
, int length
)
1325 unsigned long h
= 0;
1326 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1327 unsigned int lang
= psymbol
->ginfo
.language
;
1328 unsigned int domain
= PSYMBOL_DOMAIN (psymbol
);
1329 unsigned int class = PSYMBOL_CLASS (psymbol
);
1331 h
= hash_continue (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1332 h
= hash_continue (&lang
, sizeof (unsigned int), h
);
1333 h
= hash_continue (&domain
, sizeof (unsigned int), h
);
1334 h
= hash_continue (&class, sizeof (unsigned int), h
);
1335 h
= hash_continue (psymbol
->ginfo
.name
, strlen (psymbol
->ginfo
.name
), h
);
1340 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1341 For the comparison this function uses a symbols value,
1342 language, domain, class and name. */
1345 psymbol_compare (const void *addr1
, const void *addr2
, int length
)
1347 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1348 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1350 return (memcmp (&sym1
->ginfo
.value
, &sym1
->ginfo
.value
,
1351 sizeof (sym1
->ginfo
.value
)) == 0
1352 && sym1
->ginfo
.language
== sym2
->ginfo
.language
1353 && PSYMBOL_DOMAIN (sym1
) == PSYMBOL_DOMAIN (sym2
)
1354 && PSYMBOL_CLASS (sym1
) == PSYMBOL_CLASS (sym2
)
1355 && sym1
->ginfo
.name
== sym2
->ginfo
.name
);
1358 /* Initialize a partial symbol bcache. */
1360 struct psymbol_bcache
*
1361 psymbol_bcache_init (void)
1363 struct psymbol_bcache
*bcache
= XCALLOC (1, struct psymbol_bcache
);
1364 bcache
->bcache
= bcache_xmalloc (psymbol_hash
, psymbol_compare
);
1368 /* Free a partial symbol bcache. */
1370 psymbol_bcache_free (struct psymbol_bcache
*bcache
)
1375 bcache_xfree (bcache
->bcache
);
1379 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1382 psymbol_bcache_get_bcache (struct psymbol_bcache
*bcache
)
1384 return bcache
->bcache
;
1387 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1388 symbol before, add a copy to BCACHE. In either case, return a pointer
1389 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1390 1 in case of new entry or 0 if returning an old entry. */
1392 static const struct partial_symbol
*
1393 psymbol_bcache_full (struct partial_symbol
*sym
,
1394 struct psymbol_bcache
*bcache
,
1397 return bcache_full (sym
,
1398 sizeof (struct partial_symbol
),
1403 /* Helper function, initialises partial symbol structure and stashes
1404 it into objfile's bcache. Note that our caching mechanism will
1405 use all fields of struct partial_symbol to determine hash value of the
1406 structure. In other words, having two symbols with the same name but
1407 different domain (or address) is possible and correct. */
1409 static const struct partial_symbol
*
1410 add_psymbol_to_bcache (const char *name
, int namelength
, int copy_name
,
1412 enum address_class
class,
1413 long val
, /* Value as a long */
1414 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1415 enum language language
, struct objfile
*objfile
,
1418 struct partial_symbol psymbol
;
1420 /* We must ensure that the entire 'value' field has been zeroed
1421 before assigning to it, because an assignment may not write the
1423 memset (&psymbol
.ginfo
.value
, 0, sizeof (psymbol
.ginfo
.value
));
1425 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1428 SYMBOL_VALUE (&psymbol
) = val
;
1432 SYMBOL_VALUE_ADDRESS (&psymbol
) = coreaddr
;
1434 SYMBOL_SECTION (&psymbol
) = 0;
1435 SYMBOL_OBJ_SECTION (&psymbol
) = NULL
;
1436 SYMBOL_SET_LANGUAGE (&psymbol
, language
);
1437 PSYMBOL_DOMAIN (&psymbol
) = domain
;
1438 PSYMBOL_CLASS (&psymbol
) = class;
1440 SYMBOL_SET_NAMES (&psymbol
, name
, namelength
, copy_name
, objfile
);
1442 /* Stash the partial symbol away in the cache. */
1443 return psymbol_bcache_full (&psymbol
,
1444 objfile
->psymbol_cache
,
1448 /* Increase the space allocated for LISTP, which is probably
1449 global_psymbols or static_psymbols. This space will eventually
1450 be freed in free_objfile(). */
1453 extend_psymbol_list (struct psymbol_allocation_list
*listp
,
1454 struct objfile
*objfile
)
1458 if (listp
->size
== 0)
1461 listp
->list
= (struct partial_symbol
**)
1462 xmalloc (new_size
* sizeof (struct partial_symbol
*));
1466 new_size
= listp
->size
* 2;
1467 listp
->list
= (struct partial_symbol
**)
1468 xrealloc ((char *) listp
->list
,
1469 new_size
* sizeof (struct partial_symbol
*));
1471 /* Next assumes we only went one over. Should be good if
1472 program works correctly. */
1473 listp
->next
= listp
->list
+ listp
->size
;
1474 listp
->size
= new_size
;
1477 /* Helper function, adds partial symbol to the given partial symbol
1481 append_psymbol_to_list (struct psymbol_allocation_list
*list
,
1482 const struct partial_symbol
*psym
,
1483 struct objfile
*objfile
)
1485 if (list
->next
>= list
->list
+ list
->size
)
1486 extend_psymbol_list (list
, objfile
);
1487 *list
->next
++ = (struct partial_symbol
*) psym
;
1488 OBJSTAT (objfile
, n_psyms
++);
1491 /* Add a symbol with a long value to a psymtab.
1492 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1493 Return the partial symbol that has been added. */
1495 /* NOTE: carlton/2003-09-11: The reason why we return the partial
1496 symbol is so that callers can get access to the symbol's demangled
1497 name, which they don't have any cheap way to determine otherwise.
1498 (Currenly, dwarf2read.c is the only file who uses that information,
1499 though it's possible that other readers might in the future.)
1500 Elena wasn't thrilled about that, and I don't blame her, but we
1501 couldn't come up with a better way to get that information. If
1502 it's needed in other situations, we could consider breaking up
1503 SYMBOL_SET_NAMES to provide access to the demangled name lookup
1506 const struct partial_symbol
*
1507 add_psymbol_to_list (const char *name
, int namelength
, int copy_name
,
1509 enum address_class
class,
1510 struct psymbol_allocation_list
*list
,
1511 long val
, /* Value as a long */
1512 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1513 enum language language
, struct objfile
*objfile
)
1515 const struct partial_symbol
*psym
;
1519 /* Stash the partial symbol away in the cache. */
1520 psym
= add_psymbol_to_bcache (name
, namelength
, copy_name
, domain
, class,
1521 val
, coreaddr
, language
, objfile
, &added
);
1523 /* Do not duplicate global partial symbols. */
1524 if (list
== &objfile
->global_psymbols
1528 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1529 append_psymbol_to_list (list
, psym
, objfile
);
1533 /* Initialize storage for partial symbols. */
1536 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1538 /* Free any previously allocated psymbol lists. */
1540 if (objfile
->global_psymbols
.list
)
1542 xfree (objfile
->global_psymbols
.list
);
1544 if (objfile
->static_psymbols
.list
)
1546 xfree (objfile
->static_psymbols
.list
);
1549 /* Current best guess is that approximately a twentieth
1550 of the total symbols (in a debugging file) are global or static
1551 oriented symbols. */
1553 objfile
->global_psymbols
.size
= total_symbols
/ 10;
1554 objfile
->static_psymbols
.size
= total_symbols
/ 10;
1556 if (objfile
->global_psymbols
.size
> 0)
1558 objfile
->global_psymbols
.next
=
1559 objfile
->global_psymbols
.list
= (struct partial_symbol
**)
1560 xmalloc ((objfile
->global_psymbols
.size
1561 * sizeof (struct partial_symbol
*)));
1563 if (objfile
->static_psymbols
.size
> 0)
1565 objfile
->static_psymbols
.next
=
1566 objfile
->static_psymbols
.list
= (struct partial_symbol
**)
1567 xmalloc ((objfile
->static_psymbols
.size
1568 * sizeof (struct partial_symbol
*)));
1572 struct partial_symtab
*
1573 allocate_psymtab (const char *filename
, struct objfile
*objfile
)
1575 struct partial_symtab
*psymtab
;
1577 if (objfile
->free_psymtabs
)
1579 psymtab
= objfile
->free_psymtabs
;
1580 objfile
->free_psymtabs
= psymtab
->next
;
1583 psymtab
= (struct partial_symtab
*)
1584 obstack_alloc (&objfile
->objfile_obstack
,
1585 sizeof (struct partial_symtab
));
1587 memset (psymtab
, 0, sizeof (struct partial_symtab
));
1588 psymtab
->filename
= obsavestring (filename
, strlen (filename
),
1589 &objfile
->objfile_obstack
);
1590 psymtab
->symtab
= NULL
;
1592 /* Prepend it to the psymtab list for the objfile it belongs to.
1593 Psymtabs are searched in most recent inserted -> least recent
1596 psymtab
->objfile
= objfile
;
1597 psymtab
->next
= objfile
->psymtabs
;
1598 objfile
->psymtabs
= psymtab
;
1604 discard_psymtab (struct partial_symtab
*pst
)
1606 struct partial_symtab
**prev_pst
;
1609 Empty psymtabs happen as a result of header files which don't
1610 have any symbols in them. There can be a lot of them. But this
1611 check is wrong, in that a psymtab with N_SLINE entries but
1612 nothing else is not empty, but we don't realize that. Fixing
1613 that without slowing things down might be tricky. */
1615 /* First, snip it out of the psymtab chain. */
1617 prev_pst
= &(pst
->objfile
->psymtabs
);
1618 while ((*prev_pst
) != pst
)
1619 prev_pst
= &((*prev_pst
)->next
);
1620 (*prev_pst
) = pst
->next
;
1622 /* Next, put it on a free list for recycling. */
1624 pst
->next
= pst
->objfile
->free_psymtabs
;
1625 pst
->objfile
->free_psymtabs
= pst
;
1631 maintenance_print_psymbols (char *args
, int from_tty
)
1634 struct ui_file
*outfile
;
1635 struct cleanup
*cleanups
;
1636 char *symname
= NULL
;
1637 char *filename
= DEV_TTY
;
1638 struct objfile
*objfile
;
1639 struct partial_symtab
*ps
;
1646 print-psymbols takes an output file name and optional symbol file name"));
1648 argv
= gdb_buildargv (args
);
1649 cleanups
= make_cleanup_freeargv (argv
);
1651 if (argv
[0] != NULL
)
1654 /* If a second arg is supplied, it is a source file name to match on. */
1655 if (argv
[1] != NULL
)
1661 filename
= tilde_expand (filename
);
1662 make_cleanup (xfree
, filename
);
1664 outfile
= gdb_fopen (filename
, FOPEN_WT
);
1666 perror_with_name (filename
);
1667 make_cleanup_ui_file_delete (outfile
);
1670 ALL_PSYMTABS (objfile
, ps
)
1671 if (symname
== NULL
|| strcmp (symname
, ps
->filename
) == 0)
1672 dump_psymtab (objfile
, ps
, outfile
);
1674 do_cleanups (cleanups
);
1677 /* List all the partial symbol tables whose names match REGEXP (optional). */
1679 maintenance_info_psymtabs (char *regexp
, int from_tty
)
1681 struct program_space
*pspace
;
1682 struct objfile
*objfile
;
1687 ALL_PSPACES (pspace
)
1688 ALL_PSPACE_OBJFILES (pspace
, objfile
)
1690 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1691 struct partial_symtab
*psymtab
;
1693 /* We don't want to print anything for this objfile until we
1694 actually find a symtab whose name matches. */
1695 int printed_objfile_start
= 0;
1697 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1702 || re_exec (psymtab
->filename
))
1704 if (! printed_objfile_start
)
1706 printf_filtered ("{ objfile %s ", objfile
->name
);
1708 printf_filtered ("((struct objfile *) %s)\n",
1709 host_address_to_string (objfile
));
1710 printed_objfile_start
= 1;
1713 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1715 printf_filtered ("((struct partial_symtab *) %s)\n",
1716 host_address_to_string (psymtab
));
1718 printf_filtered (" readin %s\n",
1719 psymtab
->readin
? "yes" : "no");
1720 printf_filtered (" fullname %s\n",
1722 ? psymtab
->fullname
: "(null)");
1723 printf_filtered (" text addresses ");
1724 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
),
1726 printf_filtered (" -- ");
1727 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
),
1729 printf_filtered ("\n");
1730 printf_filtered (" globals ");
1731 if (psymtab
->n_global_syms
)
1733 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1734 host_address_to_string (psymtab
->objfile
->global_psymbols
.list
1735 + psymtab
->globals_offset
),
1736 psymtab
->n_global_syms
);
1739 printf_filtered ("(none)\n");
1740 printf_filtered (" statics ");
1741 if (psymtab
->n_static_syms
)
1743 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1744 host_address_to_string (psymtab
->objfile
->static_psymbols
.list
1745 + psymtab
->statics_offset
),
1746 psymtab
->n_static_syms
);
1749 printf_filtered ("(none)\n");
1750 printf_filtered (" dependencies ");
1751 if (psymtab
->number_of_dependencies
)
1755 printf_filtered ("{\n");
1756 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1758 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1760 /* Note the string concatenation there --- no comma. */
1761 printf_filtered (" psymtab %s "
1762 "((struct partial_symtab *) %s)\n",
1764 host_address_to_string (dep
));
1766 printf_filtered (" }\n");
1769 printf_filtered ("(none)\n");
1770 printf_filtered (" }\n");
1774 if (printed_objfile_start
)
1775 printf_filtered ("}\n");
1779 /* Check consistency of psymtabs and symtabs. */
1782 maintenance_check_symtabs (char *ignore
, int from_tty
)
1785 struct partial_symbol
**psym
;
1786 struct symtab
*s
= NULL
;
1787 struct partial_symtab
*ps
;
1788 struct blockvector
*bv
;
1789 struct objfile
*objfile
;
1793 ALL_PSYMTABS (objfile
, ps
)
1795 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1797 s
= PSYMTAB_TO_SYMTAB (ps
);
1800 bv
= BLOCKVECTOR (s
);
1801 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1802 psym
= ps
->objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1803 length
= ps
->n_static_syms
;
1806 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
1807 SYMBOL_DOMAIN (*psym
));
1810 printf_filtered ("Static symbol `");
1811 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
1812 printf_filtered ("' only found in ");
1813 puts_filtered (ps
->filename
);
1814 printf_filtered (" psymtab\n");
1818 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1819 psym
= ps
->objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1820 length
= ps
->n_global_syms
;
1823 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
1824 SYMBOL_DOMAIN (*psym
));
1827 printf_filtered ("Global symbol `");
1828 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
1829 printf_filtered ("' only found in ");
1830 puts_filtered (ps
->filename
);
1831 printf_filtered (" psymtab\n");
1835 if (ps
->texthigh
< ps
->textlow
)
1837 printf_filtered ("Psymtab ");
1838 puts_filtered (ps
->filename
);
1839 printf_filtered (" covers bad range ");
1840 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
1841 printf_filtered (" - ");
1842 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
1843 printf_filtered ("\n");
1846 if (ps
->texthigh
== 0)
1848 if (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
))
1850 printf_filtered ("Psymtab ");
1851 puts_filtered (ps
->filename
);
1852 printf_filtered (" covers ");
1853 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
1854 printf_filtered (" - ");
1855 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
1856 printf_filtered (" but symtab covers only ");
1857 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
1858 printf_filtered (" - ");
1859 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
1860 printf_filtered ("\n");
1868 map_partial_symbol_names (void (*fun
) (const char *, void *), void *data
)
1870 struct objfile
*objfile
;
1872 ALL_OBJFILES (objfile
)
1875 objfile
->sf
->qf
->map_symbol_names (objfile
, fun
, data
);
1880 map_partial_symbol_filenames (void (*fun
) (const char *, const char *,
1884 struct objfile
*objfile
;
1886 ALL_OBJFILES (objfile
)
1889 objfile
->sf
->qf
->map_symbol_filenames (objfile
, fun
, data
);