1 /* Partial symbol tables.
3 Copyright (C) 2009, 2010 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 int (*) (const char *,
55 int (*) (const char *,
59 static struct partial_symbol
*lookup_partial_symbol (struct partial_symtab
*,
63 static char *psymtab_to_fullname (struct partial_symtab
*ps
);
65 static struct partial_symbol
*find_pc_sect_psymbol (struct partial_symtab
*,
67 struct obj_section
*);
69 static struct partial_symbol
*fixup_psymbol_section (struct partial_symbol
71 struct objfile
*objfile
);
73 static struct symtab
*psymtab_to_symtab (struct partial_symtab
*pst
);
75 /* Lookup the partial symbol table of a source file named NAME.
76 *If* there is no '/' in the name, a match after a '/'
77 in the psymtab filename will also work. */
79 static struct partial_symtab
*
80 lookup_partial_symtab (struct objfile
*objfile
, const char *name
,
81 const char *full_path
, const char *real_path
)
83 struct partial_symtab
*pst
;
85 ALL_OBJFILE_PSYMTABS (objfile
, pst
)
87 if (FILENAME_CMP (name
, pst
->filename
) == 0)
92 /* If the user gave us an absolute path, try to find the file in
93 this symtab and use its absolute path. */
94 if (full_path
!= NULL
)
96 psymtab_to_fullname (pst
);
97 if (pst
->fullname
!= NULL
98 && FILENAME_CMP (full_path
, pst
->fullname
) == 0)
104 if (real_path
!= NULL
)
107 psymtab_to_fullname (pst
);
108 if (pst
->fullname
!= NULL
)
110 rp
= gdb_realpath (pst
->fullname
);
111 make_cleanup (xfree
, rp
);
113 if (rp
!= NULL
&& FILENAME_CMP (real_path
, rp
) == 0)
120 /* Now, search for a matching tail (only if name doesn't have any dirs) */
122 if (lbasename (name
) == name
)
123 ALL_OBJFILE_PSYMTABS (objfile
, pst
)
125 if (FILENAME_CMP (lbasename (pst
->filename
), name
) == 0)
133 lookup_symtab_via_partial_symtab (struct objfile
*objfile
, const char *name
,
134 const char *full_path
, const char *real_path
,
135 struct symtab
**result
)
137 struct partial_symtab
*ps
;
139 ps
= lookup_partial_symtab (objfile
, name
, full_path
, real_path
);
144 error (_("Internal: readin %s pst for `%s' found when no symtab found."),
147 *result
= PSYMTAB_TO_SYMTAB (ps
);
151 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
152 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
154 static struct partial_symtab
*
155 find_pc_sect_psymtab_closer (CORE_ADDR pc
, struct obj_section
*section
,
156 struct partial_symtab
*pst
,
157 struct minimal_symbol
*msymbol
)
159 struct objfile
*objfile
= pst
->objfile
;
160 struct partial_symtab
*tpst
;
161 struct partial_symtab
*best_pst
= pst
;
162 CORE_ADDR best_addr
= pst
->textlow
;
164 /* An objfile that has its functions reordered might have
165 many partial symbol tables containing the PC, but
166 we want the partial symbol table that contains the
167 function containing the PC. */
168 if (!(objfile
->flags
& OBJF_REORDERED
) &&
169 section
== 0) /* can't validate section this way */
175 /* The code range of partial symtabs sometimes overlap, so, in
176 the loop below, we need to check all partial symtabs and
177 find the one that fits better for the given PC address. We
178 select the partial symtab that contains a symbol whose
179 address is closest to the PC address. By closest we mean
180 that find_pc_sect_symbol returns the symbol with address
181 that is closest and still less than the given PC. */
182 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
184 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
186 struct partial_symbol
*p
;
189 /* NOTE: This assumes that every psymbol has a
190 corresponding msymbol, which is not necessarily
191 true; the debug info might be much richer than the
192 object's symbol table. */
193 p
= find_pc_sect_psymbol (tpst
, pc
, section
);
195 && SYMBOL_VALUE_ADDRESS (p
)
196 == SYMBOL_VALUE_ADDRESS (msymbol
))
199 /* Also accept the textlow value of a psymtab as a
200 "symbol", to provide some support for partial
201 symbol tables with line information but no debug
202 symbols (e.g. those produced by an assembler). */
204 this_addr
= SYMBOL_VALUE_ADDRESS (p
);
206 this_addr
= tpst
->textlow
;
208 /* Check whether it is closer than our current
209 BEST_ADDR. Since this symbol address is
210 necessarily lower or equal to PC, the symbol closer
211 to PC is the symbol which address is the highest.
212 This way we return the psymtab which contains such
213 best match symbol. This can help in cases where the
214 symbol information/debuginfo is not complete, like
215 for instance on IRIX6 with gcc, where no debug info
216 is emitted for statics. (See also the nodebug.exp
218 if (this_addr
> best_addr
)
220 best_addr
= this_addr
;
228 /* Find which partial symtab contains PC and SECTION. Return 0 if
229 none. We return the psymtab that contains a symbol whose address
230 exactly matches PC, or, if we cannot find an exact match, the
231 psymtab that contains a symbol whose address is closest to PC. */
232 static struct partial_symtab
*
233 find_pc_sect_psymtab (struct objfile
*objfile
, CORE_ADDR pc
,
234 struct obj_section
*section
,
235 struct minimal_symbol
*msymbol
)
237 struct partial_symtab
*pst
;
239 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
240 than the later used TEXTLOW/TEXTHIGH one. */
242 if (objfile
->psymtabs_addrmap
!= NULL
)
244 pst
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
247 /* FIXME: addrmaps currently do not handle overlayed sections,
248 so fall back to the non-addrmap case if we're debugging
249 overlays and the addrmap returned the wrong section. */
250 if (overlay_debugging
&& msymbol
&& section
)
252 struct partial_symbol
*p
;
254 /* NOTE: This assumes that every psymbol has a
255 corresponding msymbol, which is not necessarily
256 true; the debug info might be much richer than the
257 object's symbol table. */
258 p
= find_pc_sect_psymbol (pst
, pc
, section
);
260 || SYMBOL_VALUE_ADDRESS (p
)
261 != SYMBOL_VALUE_ADDRESS (msymbol
))
265 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
266 PSYMTABS_ADDRMAP we used has already the best 1-byte
267 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
268 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
277 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
278 which still have no corresponding full SYMTABs read. But it is not
279 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
282 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
283 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
284 debug info type in single OBJFILE. */
286 ALL_OBJFILE_PSYMTABS (objfile
, pst
)
287 if (pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
289 struct partial_symtab
*best_pst
;
291 best_pst
= find_pc_sect_psymtab_closer (pc
, section
, pst
, msymbol
);
292 if (best_pst
!= NULL
)
299 static struct symtab
*
300 find_pc_sect_symtab_from_partial (struct objfile
*objfile
,
301 struct minimal_symbol
*msymbol
,
302 CORE_ADDR pc
, struct obj_section
*section
,
305 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
309 if (warn_if_readin
&& ps
->readin
)
310 /* Might want to error() here (in case symtab is corrupt and
311 will cause a core dump), but maybe we can successfully
312 continue, so let's not. */
314 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
315 paddress (get_objfile_arch (ps
->objfile
), pc
));
316 return PSYMTAB_TO_SYMTAB (ps
);
321 /* Find which partial symbol within a psymtab matches PC and SECTION.
324 static struct partial_symbol
*
325 find_pc_sect_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
,
326 struct obj_section
*section
)
328 struct partial_symbol
*best
= NULL
, *p
, **pp
;
331 gdb_assert (psymtab
!= NULL
);
333 /* Cope with programs that start at address 0 */
334 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
336 /* Search the global symbols as well as the static symbols, so that
337 find_pc_partial_function doesn't use a minimal symbol and thus
338 cache a bad endaddr. */
339 for (pp
= psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
340 (pp
- (psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
341 < psymtab
->n_global_syms
);
345 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
346 && SYMBOL_CLASS (p
) == LOC_BLOCK
347 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
348 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
349 || (psymtab
->textlow
== 0
350 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
352 if (section
) /* match on a specific section */
354 fixup_psymbol_section (p
, psymtab
->objfile
);
355 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p
), section
))
358 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
363 for (pp
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
364 (pp
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
365 < psymtab
->n_static_syms
);
369 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
370 && SYMBOL_CLASS (p
) == LOC_BLOCK
371 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
372 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
373 || (psymtab
->textlow
== 0
374 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
376 if (section
) /* match on a specific section */
378 fixup_psymbol_section (p
, psymtab
->objfile
);
379 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p
), section
))
382 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
390 static struct partial_symbol
*
391 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
398 if (SYMBOL_OBJ_SECTION (psym
))
401 gdb_assert (objfile
);
403 switch (SYMBOL_CLASS (psym
))
408 addr
= SYMBOL_VALUE_ADDRESS (psym
);
411 /* Nothing else will be listed in the minsyms -- no use looking
416 fixup_section (&psym
->ginfo
, addr
, objfile
);
421 static struct symtab
*
422 lookup_symbol_aux_psymtabs (struct objfile
*objfile
,
423 int block_index
, const char *name
,
424 const domain_enum domain
)
426 struct partial_symtab
*ps
;
427 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
429 ALL_OBJFILE_PSYMTABS (objfile
, ps
)
431 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, psymtab_index
, domain
))
432 return PSYMTAB_TO_SYMTAB (ps
);
438 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
439 the global block of PST if GLOBAL, and otherwise the static block.
440 MATCH is the comparison operation that returns true iff MATCH (s,
441 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
442 non-null, the symbols in the block are assumed to be ordered
443 according to it (allowing binary search). It must be compatible
444 with MATCH. Returns the symbol, if found, and otherwise NULL. */
446 static struct partial_symbol
*
447 match_partial_symbol (struct partial_symtab
*pst
, int global
,
448 const char *name
, domain_enum domain
,
449 int (*match
) (const char *, const char *),
450 int (*ordered_compare
) (const char *, const char *))
452 struct partial_symbol
**start
, **psym
;
453 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
454 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
455 int do_linear_search
= 1;
460 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
461 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
463 if (global
&& ordered_compare
) /* Can use a binary search. */
465 do_linear_search
= 0;
467 /* Binary search. This search is guaranteed to end with center
468 pointing at the earliest partial symbol whose name might be
469 correct. At that point *all* partial symbols with an
470 appropriate name will be checked against the correct
474 top
= start
+ length
- 1;
478 center
= bottom
+ (top
- bottom
) / 2;
479 gdb_assert (center
< top
);
480 if (!do_linear_search
481 && (SYMBOL_LANGUAGE (*center
) == language_java
))
482 do_linear_search
= 1;
483 if (ordered_compare (SYMBOL_SEARCH_NAME (*center
), name
) >= 0)
488 gdb_assert (top
== bottom
);
490 while (top
<= real_top
491 && match (SYMBOL_SEARCH_NAME (*top
), name
) == 0)
493 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
494 SYMBOL_DOMAIN (*top
), domain
))
500 /* Can't use a binary search or else we found during the binary search that
501 we should also do a linear search. */
503 if (do_linear_search
)
505 for (psym
= start
; psym
< start
+ length
; psym
++)
507 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
508 SYMBOL_DOMAIN (*psym
), domain
)
509 && match (SYMBOL_SEARCH_NAME (*psym
), name
) == 0)
518 pre_expand_symtabs_matching_psymtabs (struct objfile
*objfile
,
519 int kind
, const char *name
,
525 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
526 Check the global symbols if GLOBAL, the static symbols if not. */
528 static struct partial_symbol
*
529 lookup_partial_symbol (struct partial_symtab
*pst
, const char *name
,
530 int global
, domain_enum domain
)
532 struct partial_symbol
**start
, **psym
;
533 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
534 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
535 int do_linear_search
= 1;
542 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
543 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
545 if (global
) /* This means we can use a binary search. */
547 do_linear_search
= 0;
549 /* Binary search. This search is guaranteed to end with center
550 pointing at the earliest partial symbol whose name might be
551 correct. At that point *all* partial symbols with an
552 appropriate name will be checked against the correct
556 top
= start
+ length
- 1;
560 center
= bottom
+ (top
- bottom
) / 2;
562 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
563 if (!do_linear_search
564 && SYMBOL_LANGUAGE (*center
) == language_java
)
566 do_linear_search
= 1;
568 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center
), name
) >= 0)
577 if (!(top
== bottom
))
578 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
580 while (top
<= real_top
581 && SYMBOL_MATCHES_SEARCH_NAME (*top
, name
))
583 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
584 SYMBOL_DOMAIN (*top
), domain
))
590 /* Can't use a binary search or else we found during the binary search that
591 we should also do a linear search. */
593 if (do_linear_search
)
595 for (psym
= start
; psym
< start
+ length
; psym
++)
597 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
598 SYMBOL_DOMAIN (*psym
), domain
)
599 && SYMBOL_MATCHES_SEARCH_NAME (*psym
, name
))
607 /* Get the symbol table that corresponds to a partial_symtab.
608 This is fast after the first time you do it. In fact, there
609 is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
612 static struct symtab
*
613 psymtab_to_symtab (struct partial_symtab
*pst
)
615 /* If it's been looked up before, return it. */
619 /* If it has not yet been read in, read it. */
622 struct cleanup
*back_to
= increment_reading_symtab ();
624 (*pst
->read_symtab
) (pst
);
625 do_cleanups (back_to
);
632 relocate_psymtabs (struct objfile
*objfile
,
633 struct section_offsets
*new_offsets
,
634 struct section_offsets
*delta
)
636 struct partial_symbol
**psym
;
637 struct partial_symtab
*p
;
639 ALL_OBJFILE_PSYMTABS (objfile
, p
)
641 p
->textlow
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
642 p
->texthigh
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
645 for (psym
= objfile
->global_psymbols
.list
;
646 psym
< objfile
->global_psymbols
.next
;
649 fixup_psymbol_section (*psym
, objfile
);
650 if (SYMBOL_SECTION (*psym
) >= 0)
651 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
652 SYMBOL_SECTION (*psym
));
654 for (psym
= objfile
->static_psymbols
.list
;
655 psym
< objfile
->static_psymbols
.next
;
658 fixup_psymbol_section (*psym
, objfile
);
659 if (SYMBOL_SECTION (*psym
) >= 0)
660 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
661 SYMBOL_SECTION (*psym
));
665 static struct symtab
*
666 find_last_source_symtab_from_partial (struct objfile
*ofp
)
668 struct partial_symtab
*ps
;
669 struct partial_symtab
*cs_pst
= 0;
671 ALL_OBJFILE_PSYMTABS (ofp
, ps
)
673 const char *name
= ps
->filename
;
674 int len
= strlen (name
);
676 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
677 || strcmp (name
, "<<C++-namespaces>>") == 0)))
685 internal_error (__FILE__
, __LINE__
,
686 _("select_source_symtab: "
687 "readin pst found and no symtabs."));
690 return PSYMTAB_TO_SYMTAB (cs_pst
);
696 forget_cached_source_info_partial (struct objfile
*objfile
)
698 struct partial_symtab
*pst
;
700 ALL_OBJFILE_PSYMTABS (objfile
, pst
)
702 if (pst
->fullname
!= NULL
)
704 xfree (pst
->fullname
);
705 pst
->fullname
= NULL
;
711 print_partial_symbols (struct gdbarch
*gdbarch
,
712 struct partial_symbol
**p
, int count
, char *what
,
713 struct ui_file
*outfile
)
715 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
718 fprintf_filtered (outfile
, " `%s'", SYMBOL_LINKAGE_NAME (*p
));
719 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
721 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
723 fputs_filtered (", ", outfile
);
724 switch (SYMBOL_DOMAIN (*p
))
727 fputs_filtered ("undefined domain, ", outfile
);
730 /* This is the usual thing -- don't print it */
733 fputs_filtered ("struct domain, ", outfile
);
736 fputs_filtered ("label domain, ", outfile
);
739 fputs_filtered ("<invalid domain>, ", outfile
);
742 switch (SYMBOL_CLASS (*p
))
745 fputs_filtered ("undefined", outfile
);
748 fputs_filtered ("constant int", outfile
);
751 fputs_filtered ("static", outfile
);
754 fputs_filtered ("register", outfile
);
757 fputs_filtered ("pass by value", outfile
);
760 fputs_filtered ("pass by reference", outfile
);
762 case LOC_REGPARM_ADDR
:
763 fputs_filtered ("register address parameter", outfile
);
766 fputs_filtered ("stack parameter", outfile
);
769 fputs_filtered ("type", outfile
);
772 fputs_filtered ("label", outfile
);
775 fputs_filtered ("function", outfile
);
777 case LOC_CONST_BYTES
:
778 fputs_filtered ("constant bytes", outfile
);
781 fputs_filtered ("unresolved", outfile
);
783 case LOC_OPTIMIZED_OUT
:
784 fputs_filtered ("optimized out", outfile
);
787 fputs_filtered ("computed at runtime", outfile
);
790 fputs_filtered ("<invalid location>", outfile
);
793 fputs_filtered (", ", outfile
);
794 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (*p
)), outfile
);
795 fprintf_filtered (outfile
, "\n");
801 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
802 struct ui_file
*outfile
)
804 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
807 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
809 fprintf_filtered (outfile
, "(object ");
810 gdb_print_host_address (psymtab
, outfile
);
811 fprintf_filtered (outfile
, ")\n\n");
812 fprintf_unfiltered (outfile
, " Read from object file %s (",
814 gdb_print_host_address (objfile
, outfile
);
815 fprintf_unfiltered (outfile
, ")\n");
819 fprintf_filtered (outfile
,
820 " Full symtab was read (at ");
821 gdb_print_host_address (psymtab
->symtab
, outfile
);
822 fprintf_filtered (outfile
, " by function at ");
823 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
824 fprintf_filtered (outfile
, ")\n");
827 fprintf_filtered (outfile
, " Relocate symbols by ");
828 for (i
= 0; i
< psymtab
->objfile
->num_sections
; ++i
)
831 fprintf_filtered (outfile
, ", ");
833 fputs_filtered (paddress (gdbarch
,
834 ANOFFSET (psymtab
->section_offsets
, i
)),
837 fprintf_filtered (outfile
, "\n");
839 fprintf_filtered (outfile
, " Symbols cover text addresses ");
840 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
), outfile
);
841 fprintf_filtered (outfile
, "-");
842 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
), outfile
);
843 fprintf_filtered (outfile
, "\n");
844 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
845 psymtab
->number_of_dependencies
);
846 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
848 fprintf_filtered (outfile
, " %d ", i
);
849 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
850 fprintf_filtered (outfile
, " %s\n",
851 psymtab
->dependencies
[i
]->filename
);
853 if (psymtab
->n_global_syms
> 0)
855 print_partial_symbols (gdbarch
,
856 objfile
->global_psymbols
.list
857 + psymtab
->globals_offset
,
858 psymtab
->n_global_syms
, "Global", outfile
);
860 if (psymtab
->n_static_syms
> 0)
862 print_partial_symbols (gdbarch
,
863 objfile
->static_psymbols
.list
864 + psymtab
->statics_offset
,
865 psymtab
->n_static_syms
, "Static", outfile
);
867 fprintf_filtered (outfile
, "\n");
871 print_psymtab_stats_for_objfile (struct objfile
*objfile
)
874 struct partial_symtab
*ps
;
877 ALL_OBJFILE_PSYMTABS (objfile
, ps
)
882 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
886 dump_psymtabs_for_objfile (struct objfile
*objfile
)
888 struct partial_symtab
*psymtab
;
890 if (objfile
->psymtabs
)
892 printf_filtered ("Psymtabs:\n");
893 for (psymtab
= objfile
->psymtabs
;
895 psymtab
= psymtab
->next
)
897 printf_filtered ("%s at ",
899 gdb_print_host_address (psymtab
, gdb_stdout
);
900 printf_filtered (", ");
901 if (psymtab
->objfile
!= objfile
)
903 printf_filtered ("NOT ON CHAIN! ");
907 printf_filtered ("\n\n");
911 /* Look through the partial symtabs for all symbols which begin
912 by matching FUNC_NAME. Make sure we read that symbol table in. */
915 read_symtabs_for_function (struct objfile
*objfile
, const char *func_name
)
917 struct partial_symtab
*ps
;
919 ALL_OBJFILE_PSYMTABS (objfile
, ps
)
924 if ((lookup_partial_symbol (ps
, func_name
, 1, VAR_DOMAIN
)
926 || (lookup_partial_symbol (ps
, func_name
, 0, VAR_DOMAIN
)
928 psymtab_to_symtab (ps
);
933 expand_partial_symbol_tables (struct objfile
*objfile
)
935 struct partial_symtab
*psymtab
;
937 for (psymtab
= objfile
->psymtabs
;
939 psymtab
= psymtab
->next
)
941 psymtab_to_symtab (psymtab
);
946 read_psymtabs_with_filename (struct objfile
*objfile
, const char *filename
)
948 struct partial_symtab
*p
;
950 ALL_OBJFILE_PSYMTABS (objfile
, p
)
952 if (strcmp (filename
, p
->filename
) == 0)
953 PSYMTAB_TO_SYMTAB (p
);
958 map_symbol_names_psymtab (struct objfile
*objfile
,
959 void (*fun
) (const char *, void *), void *data
)
961 struct partial_symtab
*ps
;
963 ALL_OBJFILE_PSYMTABS (objfile
, ps
)
965 struct partial_symbol
**psym
;
967 /* If the psymtab's been read in we'll get it when we search
968 through the blockvector. */
972 for (psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
973 psym
< (objfile
->global_psymbols
.list
+ ps
->globals_offset
974 + ps
->n_global_syms
);
977 /* If interrupted, then quit. */
979 (*fun
) (SYMBOL_NATURAL_NAME (*psym
), data
);
982 for (psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
983 psym
< (objfile
->static_psymbols
.list
+ ps
->statics_offset
984 + ps
->n_static_syms
);
988 (*fun
) (SYMBOL_NATURAL_NAME (*psym
), data
);
994 map_symbol_filenames_psymtab (struct objfile
*objfile
,
995 void (*fun
) (const char *, const char *,
999 struct partial_symtab
*ps
;
1001 ALL_OBJFILE_PSYMTABS (objfile
, ps
)
1003 const char *fullname
;
1008 fullname
= psymtab_to_fullname (ps
);
1009 (*fun
) (ps
->filename
, fullname
, data
);
1013 int find_and_open_source (const char *filename
,
1014 const char *dirname
,
1017 /* Finds the fullname that a partial_symtab represents.
1019 If this functions finds the fullname, it will save it in ps->fullname
1020 and it will also return the value.
1022 If this function fails to find the file that this partial_symtab represents,
1023 NULL will be returned and ps->fullname will be set to NULL. */
1025 psymtab_to_fullname (struct partial_symtab
*ps
)
1032 /* Don't check ps->fullname here, the file could have been
1033 deleted/moved/..., look for it again */
1034 r
= find_and_open_source (ps
->filename
, ps
->dirname
, &ps
->fullname
);
1039 return ps
->fullname
;
1046 find_symbol_file_from_partial (struct objfile
*objfile
, const char *name
)
1048 struct partial_symtab
*pst
;
1050 ALL_OBJFILE_PSYMTABS (objfile
, pst
)
1052 if (lookup_partial_symbol (pst
, name
, 1, VAR_DOMAIN
))
1053 return pst
->filename
;
1058 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1059 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1060 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1061 ever returns non-zero, and otherwise returns 0. */
1064 map_block (const char *name
, domain_enum
namespace, struct objfile
*objfile
,
1065 struct block
*block
,
1066 int (*callback
) (struct block
*, struct symbol
*, void *),
1068 int (*match
) (const char *, const char *))
1070 struct dict_iterator iter
;
1073 for (sym
= dict_iter_match_first (BLOCK_DICT (block
), name
, match
, &iter
);
1074 sym
!= NULL
; sym
= dict_iter_match_next (name
, match
, &iter
))
1076 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym
),
1077 SYMBOL_DOMAIN (sym
), namespace))
1079 if (callback (block
, sym
, data
))
1087 /* Psymtab version of map_matching_symbols. See its definition in
1088 the definition of quick_symbol_functions in symfile.h. */
1091 map_matching_symbols_psymtab (const char *name
, domain_enum
namespace,
1092 struct objfile
*objfile
, int global
,
1093 int (*callback
) (struct block
*,
1094 struct symbol
*, void *),
1096 int (*match
) (const char *, const char *),
1097 int (*ordered_compare
) (const char *,
1100 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1101 struct partial_symtab
*ps
;
1103 ALL_OBJFILE_PSYMTABS (objfile
, ps
)
1107 || match_partial_symbol (ps
, global
, name
, namespace, match
,
1110 struct symtab
*s
= PSYMTAB_TO_SYMTAB (ps
);
1111 struct block
*block
;
1113 if (s
== NULL
|| !s
->primary
)
1115 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), block_kind
);
1116 if (map_block (name
, namespace, objfile
, block
,
1117 callback
, data
, match
))
1119 if (callback (block
, NULL
, data
))
1126 expand_symtabs_matching_via_partial (struct objfile
*objfile
,
1127 int (*file_matcher
) (const char *, void *),
1128 int (*name_matcher
) (const char *, void *),
1132 struct partial_symtab
*ps
;
1134 ALL_OBJFILE_PSYMTABS (objfile
, ps
)
1136 struct partial_symbol
**psym
;
1137 struct partial_symbol
**bound
, **gbound
, **sbound
;
1143 if (! (*file_matcher
) (ps
->filename
, data
))
1146 gbound
= objfile
->global_psymbols
.list
+ ps
->globals_offset
+ ps
->n_global_syms
;
1147 sbound
= objfile
->static_psymbols
.list
+ ps
->statics_offset
+ ps
->n_static_syms
;
1150 /* Go through all of the symbols stored in a partial
1151 symtab in one loop. */
1152 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1157 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
1159 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1170 if ((*name_matcher
) (SYMBOL_NATURAL_NAME (*psym
), data
)
1171 && ((kind
== VARIABLES_DOMAIN
1172 && SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
1173 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
1174 || (kind
== FUNCTIONS_DOMAIN
1175 && SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
1176 || (kind
== TYPES_DOMAIN
1177 && SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
)))
1179 PSYMTAB_TO_SYMTAB (ps
);
1189 objfile_has_psyms (struct objfile
*objfile
)
1191 return objfile
->psymtabs
!= NULL
;
1194 const struct quick_symbol_functions psym_functions
=
1197 find_last_source_symtab_from_partial
,
1198 forget_cached_source_info_partial
,
1199 lookup_symtab_via_partial_symtab
,
1200 lookup_symbol_aux_psymtabs
,
1201 pre_expand_symtabs_matching_psymtabs
,
1202 print_psymtab_stats_for_objfile
,
1203 dump_psymtabs_for_objfile
,
1205 read_symtabs_for_function
,
1206 expand_partial_symbol_tables
,
1207 read_psymtabs_with_filename
,
1208 find_symbol_file_from_partial
,
1209 map_matching_symbols_psymtab
,
1210 expand_symtabs_matching_via_partial
,
1211 find_pc_sect_symtab_from_partial
,
1212 map_symbol_names_psymtab
,
1213 map_symbol_filenames_psymtab
1218 /* This compares two partial symbols by names, using strcmp_iw_ordered
1219 for the comparison. */
1222 compare_psymbols (const void *s1p
, const void *s2p
)
1224 struct partial_symbol
*const *s1
= s1p
;
1225 struct partial_symbol
*const *s2
= s2p
;
1227 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1
),
1228 SYMBOL_SEARCH_NAME (*s2
));
1232 sort_pst_symbols (struct partial_symtab
*pst
)
1234 /* Sort the global list; don't sort the static list */
1236 qsort (pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
,
1237 pst
->n_global_syms
, sizeof (struct partial_symbol
*),
1241 /* Allocate and partially fill a partial symtab. It will be
1242 completely filled at the end of the symbol list.
1244 FILENAME is the name of the symbol-file we are reading from. */
1246 struct partial_symtab
*
1247 start_psymtab_common (struct objfile
*objfile
,
1248 struct section_offsets
*section_offsets
,
1249 const char *filename
,
1250 CORE_ADDR textlow
, struct partial_symbol
**global_syms
,
1251 struct partial_symbol
**static_syms
)
1253 struct partial_symtab
*psymtab
;
1255 psymtab
= allocate_psymtab (filename
, objfile
);
1256 psymtab
->section_offsets
= section_offsets
;
1257 psymtab
->textlow
= textlow
;
1258 psymtab
->texthigh
= psymtab
->textlow
; /* default */
1259 psymtab
->globals_offset
= global_syms
- objfile
->global_psymbols
.list
;
1260 psymtab
->statics_offset
= static_syms
- objfile
->static_psymbols
.list
;
1264 /* Calculate a hash code for the given partial symbol. The hash is
1265 calculated using the symbol's value, language, domain, class
1266 and name. These are the values which are set by
1267 add_psymbol_to_bcache. */
1269 static unsigned long
1270 psymbol_hash (const void *addr
, int length
)
1272 unsigned long h
= 0;
1273 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1274 unsigned int lang
= psymbol
->ginfo
.language
;
1275 unsigned int domain
= PSYMBOL_DOMAIN (psymbol
);
1276 unsigned int class = PSYMBOL_CLASS (psymbol
);
1278 h
= hash_continue (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1279 h
= hash_continue (&lang
, sizeof (unsigned int), h
);
1280 h
= hash_continue (&domain
, sizeof (unsigned int), h
);
1281 h
= hash_continue (&class, sizeof (unsigned int), h
);
1282 h
= hash_continue (psymbol
->ginfo
.name
, strlen (psymbol
->ginfo
.name
), h
);
1287 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1288 For the comparison this function uses a symbols value,
1289 language, domain, class and name. */
1292 psymbol_compare (const void *addr1
, const void *addr2
, int length
)
1294 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1295 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1297 return (memcmp (&sym1
->ginfo
.value
, &sym1
->ginfo
.value
,
1298 sizeof (sym1
->ginfo
.value
)) == 0
1299 && sym1
->ginfo
.language
== sym2
->ginfo
.language
1300 && PSYMBOL_DOMAIN (sym1
) == PSYMBOL_DOMAIN (sym2
)
1301 && PSYMBOL_CLASS (sym1
) == PSYMBOL_CLASS (sym2
)
1302 && sym1
->ginfo
.name
== sym2
->ginfo
.name
);
1305 /* Initialize a partial symbol bcache. */
1307 struct psymbol_bcache
*
1308 psymbol_bcache_init (void)
1310 struct psymbol_bcache
*bcache
= XCALLOC (1, struct psymbol_bcache
);
1311 bcache
->bcache
= bcache_xmalloc (psymbol_hash
, psymbol_compare
);
1315 /* Free a partial symbol bcache. */
1317 psymbol_bcache_free (struct psymbol_bcache
*bcache
)
1322 bcache_xfree (bcache
->bcache
);
1326 /* Return the internal bcache of the psymbol_bcache BCACHE*/
1329 psymbol_bcache_get_bcache (struct psymbol_bcache
*bcache
)
1331 return bcache
->bcache
;
1334 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1335 symbol before, add a copy to BCACHE. In either case, return a pointer
1336 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1337 1 in case of new entry or 0 if returning an old entry. */
1339 static const struct partial_symbol
*
1340 psymbol_bcache_full (struct partial_symbol
*sym
,
1341 struct psymbol_bcache
*bcache
,
1344 return bcache_full (sym
,
1345 sizeof (struct partial_symbol
),
1350 /* Helper function, initialises partial symbol structure and stashes
1351 it into objfile's bcache. Note that our caching mechanism will
1352 use all fields of struct partial_symbol to determine hash value of the
1353 structure. In other words, having two symbols with the same name but
1354 different domain (or address) is possible and correct. */
1356 static const struct partial_symbol
*
1357 add_psymbol_to_bcache (const char *name
, int namelength
, int copy_name
,
1359 enum address_class
class,
1360 long val
, /* Value as a long */
1361 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1362 enum language language
, struct objfile
*objfile
,
1365 struct partial_symbol psymbol
;
1367 /* We must ensure that the entire 'value' field has been zeroed
1368 before assigning to it, because an assignment may not write the
1370 memset (&psymbol
.ginfo
.value
, 0, sizeof (psymbol
.ginfo
.value
));
1372 /* val and coreaddr are mutually exclusive, one of them *will* be zero */
1375 SYMBOL_VALUE (&psymbol
) = val
;
1379 SYMBOL_VALUE_ADDRESS (&psymbol
) = coreaddr
;
1381 SYMBOL_SECTION (&psymbol
) = 0;
1382 SYMBOL_OBJ_SECTION (&psymbol
) = NULL
;
1383 SYMBOL_SET_LANGUAGE (&psymbol
, language
);
1384 PSYMBOL_DOMAIN (&psymbol
) = domain
;
1385 PSYMBOL_CLASS (&psymbol
) = class;
1387 SYMBOL_SET_NAMES (&psymbol
, name
, namelength
, copy_name
, objfile
);
1389 /* Stash the partial symbol away in the cache */
1390 return psymbol_bcache_full (&psymbol
,
1391 objfile
->psymbol_cache
,
1395 /* Increase the space allocated for LISTP, which is probably
1396 global_psymbols or static_psymbols. This space will eventually
1397 be freed in free_objfile(). */
1400 extend_psymbol_list (struct psymbol_allocation_list
*listp
,
1401 struct objfile
*objfile
)
1405 if (listp
->size
== 0)
1408 listp
->list
= (struct partial_symbol
**)
1409 xmalloc (new_size
* sizeof (struct partial_symbol
*));
1413 new_size
= listp
->size
* 2;
1414 listp
->list
= (struct partial_symbol
**)
1415 xrealloc ((char *) listp
->list
,
1416 new_size
* sizeof (struct partial_symbol
*));
1418 /* Next assumes we only went one over. Should be good if
1419 program works correctly */
1420 listp
->next
= listp
->list
+ listp
->size
;
1421 listp
->size
= new_size
;
1424 /* Helper function, adds partial symbol to the given partial symbol
1428 append_psymbol_to_list (struct psymbol_allocation_list
*list
,
1429 const struct partial_symbol
*psym
,
1430 struct objfile
*objfile
)
1432 if (list
->next
>= list
->list
+ list
->size
)
1433 extend_psymbol_list (list
, objfile
);
1434 *list
->next
++ = (struct partial_symbol
*) psym
;
1435 OBJSTAT (objfile
, n_psyms
++);
1438 /* Add a symbol with a long value to a psymtab.
1439 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1440 Return the partial symbol that has been added. */
1442 /* NOTE: carlton/2003-09-11: The reason why we return the partial
1443 symbol is so that callers can get access to the symbol's demangled
1444 name, which they don't have any cheap way to determine otherwise.
1445 (Currenly, dwarf2read.c is the only file who uses that information,
1446 though it's possible that other readers might in the future.)
1447 Elena wasn't thrilled about that, and I don't blame her, but we
1448 couldn't come up with a better way to get that information. If
1449 it's needed in other situations, we could consider breaking up
1450 SYMBOL_SET_NAMES to provide access to the demangled name lookup
1453 const struct partial_symbol
*
1454 add_psymbol_to_list (const char *name
, int namelength
, int copy_name
,
1456 enum address_class
class,
1457 struct psymbol_allocation_list
*list
,
1458 long val
, /* Value as a long */
1459 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1460 enum language language
, struct objfile
*objfile
)
1462 const struct partial_symbol
*psym
;
1466 /* Stash the partial symbol away in the cache */
1467 psym
= add_psymbol_to_bcache (name
, namelength
, copy_name
, domain
, class,
1468 val
, coreaddr
, language
, objfile
, &added
);
1470 /* Do not duplicate global partial symbols. */
1471 if (list
== &objfile
->global_psymbols
1475 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1476 append_psymbol_to_list (list
, psym
, objfile
);
1480 /* Initialize storage for partial symbols. */
1483 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1485 /* Free any previously allocated psymbol lists. */
1487 if (objfile
->global_psymbols
.list
)
1489 xfree (objfile
->global_psymbols
.list
);
1491 if (objfile
->static_psymbols
.list
)
1493 xfree (objfile
->static_psymbols
.list
);
1496 /* Current best guess is that approximately a twentieth
1497 of the total symbols (in a debugging file) are global or static
1500 objfile
->global_psymbols
.size
= total_symbols
/ 10;
1501 objfile
->static_psymbols
.size
= total_symbols
/ 10;
1503 if (objfile
->global_psymbols
.size
> 0)
1505 objfile
->global_psymbols
.next
=
1506 objfile
->global_psymbols
.list
= (struct partial_symbol
**)
1507 xmalloc ((objfile
->global_psymbols
.size
1508 * sizeof (struct partial_symbol
*)));
1510 if (objfile
->static_psymbols
.size
> 0)
1512 objfile
->static_psymbols
.next
=
1513 objfile
->static_psymbols
.list
= (struct partial_symbol
**)
1514 xmalloc ((objfile
->static_psymbols
.size
1515 * sizeof (struct partial_symbol
*)));
1519 struct partial_symtab
*
1520 allocate_psymtab (const char *filename
, struct objfile
*objfile
)
1522 struct partial_symtab
*psymtab
;
1524 if (objfile
->free_psymtabs
)
1526 psymtab
= objfile
->free_psymtabs
;
1527 objfile
->free_psymtabs
= psymtab
->next
;
1530 psymtab
= (struct partial_symtab
*)
1531 obstack_alloc (&objfile
->objfile_obstack
,
1532 sizeof (struct partial_symtab
));
1534 memset (psymtab
, 0, sizeof (struct partial_symtab
));
1535 psymtab
->filename
= obsavestring (filename
, strlen (filename
),
1536 &objfile
->objfile_obstack
);
1537 psymtab
->symtab
= NULL
;
1539 /* Prepend it to the psymtab list for the objfile it belongs to.
1540 Psymtabs are searched in most recent inserted -> least recent
1543 psymtab
->objfile
= objfile
;
1544 psymtab
->next
= objfile
->psymtabs
;
1545 objfile
->psymtabs
= psymtab
;
1551 discard_psymtab (struct partial_symtab
*pst
)
1553 struct partial_symtab
**prev_pst
;
1556 Empty psymtabs happen as a result of header files which don't
1557 have any symbols in them. There can be a lot of them. But this
1558 check is wrong, in that a psymtab with N_SLINE entries but
1559 nothing else is not empty, but we don't realize that. Fixing
1560 that without slowing things down might be tricky. */
1562 /* First, snip it out of the psymtab chain */
1564 prev_pst
= &(pst
->objfile
->psymtabs
);
1565 while ((*prev_pst
) != pst
)
1566 prev_pst
= &((*prev_pst
)->next
);
1567 (*prev_pst
) = pst
->next
;
1569 /* Next, put it on a free list for recycling */
1571 pst
->next
= pst
->objfile
->free_psymtabs
;
1572 pst
->objfile
->free_psymtabs
= pst
;
1578 maintenance_print_psymbols (char *args
, int from_tty
)
1581 struct ui_file
*outfile
;
1582 struct cleanup
*cleanups
;
1583 char *symname
= NULL
;
1584 char *filename
= DEV_TTY
;
1585 struct objfile
*objfile
;
1586 struct partial_symtab
*ps
;
1592 error (_("print-psymbols takes an output file name and optional symbol file name"));
1594 argv
= gdb_buildargv (args
);
1595 cleanups
= make_cleanup_freeargv (argv
);
1597 if (argv
[0] != NULL
)
1600 /* If a second arg is supplied, it is a source file name to match on */
1601 if (argv
[1] != NULL
)
1607 filename
= tilde_expand (filename
);
1608 make_cleanup (xfree
, filename
);
1610 outfile
= gdb_fopen (filename
, FOPEN_WT
);
1612 perror_with_name (filename
);
1613 make_cleanup_ui_file_delete (outfile
);
1616 ALL_PSYMTABS (objfile
, ps
)
1617 if (symname
== NULL
|| strcmp (symname
, ps
->filename
) == 0)
1618 dump_psymtab (objfile
, ps
, outfile
);
1620 do_cleanups (cleanups
);
1623 /* List all the partial symbol tables whose names match REGEXP (optional). */
1625 maintenance_info_psymtabs (char *regexp
, int from_tty
)
1627 struct program_space
*pspace
;
1628 struct objfile
*objfile
;
1633 ALL_PSPACES (pspace
)
1634 ALL_PSPACE_OBJFILES (pspace
, objfile
)
1636 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1637 struct partial_symtab
*psymtab
;
1639 /* We don't want to print anything for this objfile until we
1640 actually find a symtab whose name matches. */
1641 int printed_objfile_start
= 0;
1643 ALL_OBJFILE_PSYMTABS (objfile
, psymtab
)
1648 || re_exec (psymtab
->filename
))
1650 if (! printed_objfile_start
)
1652 printf_filtered ("{ objfile %s ", objfile
->name
);
1654 printf_filtered ("((struct objfile *) %s)\n",
1655 host_address_to_string (objfile
));
1656 printed_objfile_start
= 1;
1659 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1661 printf_filtered ("((struct partial_symtab *) %s)\n",
1662 host_address_to_string (psymtab
));
1664 printf_filtered (" readin %s\n",
1665 psymtab
->readin
? "yes" : "no");
1666 printf_filtered (" fullname %s\n",
1667 psymtab
->fullname
? psymtab
->fullname
: "(null)");
1668 printf_filtered (" text addresses ");
1669 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
),
1671 printf_filtered (" -- ");
1672 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
),
1674 printf_filtered ("\n");
1675 printf_filtered (" globals ");
1676 if (psymtab
->n_global_syms
)
1678 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1679 host_address_to_string (psymtab
->objfile
->global_psymbols
.list
1680 + psymtab
->globals_offset
),
1681 psymtab
->n_global_syms
);
1684 printf_filtered ("(none)\n");
1685 printf_filtered (" statics ");
1686 if (psymtab
->n_static_syms
)
1688 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1689 host_address_to_string (psymtab
->objfile
->static_psymbols
.list
1690 + psymtab
->statics_offset
),
1691 psymtab
->n_static_syms
);
1694 printf_filtered ("(none)\n");
1695 printf_filtered (" dependencies ");
1696 if (psymtab
->number_of_dependencies
)
1700 printf_filtered ("{\n");
1701 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1703 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1705 /* Note the string concatenation there --- no comma. */
1706 printf_filtered (" psymtab %s "
1707 "((struct partial_symtab *) %s)\n",
1709 host_address_to_string (dep
));
1711 printf_filtered (" }\n");
1714 printf_filtered ("(none)\n");
1715 printf_filtered (" }\n");
1719 if (printed_objfile_start
)
1720 printf_filtered ("}\n");
1724 /* Check consistency of psymtabs and symtabs. */
1727 maintenance_check_symtabs (char *ignore
, int from_tty
)
1730 struct partial_symbol
**psym
;
1731 struct symtab
*s
= NULL
;
1732 struct partial_symtab
*ps
;
1733 struct blockvector
*bv
;
1734 struct objfile
*objfile
;
1738 ALL_PSYMTABS (objfile
, ps
)
1740 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1742 s
= PSYMTAB_TO_SYMTAB (ps
);
1745 bv
= BLOCKVECTOR (s
);
1746 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1747 psym
= ps
->objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1748 length
= ps
->n_static_syms
;
1751 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
1752 SYMBOL_DOMAIN (*psym
));
1755 printf_filtered ("Static symbol `");
1756 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
1757 printf_filtered ("' only found in ");
1758 puts_filtered (ps
->filename
);
1759 printf_filtered (" psymtab\n");
1763 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1764 psym
= ps
->objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1765 length
= ps
->n_global_syms
;
1768 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
1769 SYMBOL_DOMAIN (*psym
));
1772 printf_filtered ("Global symbol `");
1773 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
1774 printf_filtered ("' only found in ");
1775 puts_filtered (ps
->filename
);
1776 printf_filtered (" psymtab\n");
1780 if (ps
->texthigh
< ps
->textlow
)
1782 printf_filtered ("Psymtab ");
1783 puts_filtered (ps
->filename
);
1784 printf_filtered (" covers bad range ");
1785 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
1786 printf_filtered (" - ");
1787 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
1788 printf_filtered ("\n");
1791 if (ps
->texthigh
== 0)
1793 if (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
))
1795 printf_filtered ("Psymtab ");
1796 puts_filtered (ps
->filename
);
1797 printf_filtered (" covers ");
1798 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
1799 printf_filtered (" - ");
1800 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
1801 printf_filtered (" but symtab covers only ");
1802 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
1803 printf_filtered (" - ");
1804 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
1805 printf_filtered ("\n");
1813 map_partial_symbol_names (void (*fun
) (const char *, void *), void *data
)
1815 struct objfile
*objfile
;
1817 ALL_OBJFILES (objfile
)
1820 objfile
->sf
->qf
->map_symbol_names (objfile
, fun
, data
);
1825 map_partial_symbol_filenames (void (*fun
) (const char *, const char *,
1829 struct objfile
*objfile
;
1831 ALL_OBJFILES (objfile
)
1834 objfile
->sf
->qf
->map_symbol_filenames (objfile
, fun
, data
);