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"
37 #include "cp-support.h"
40 #define DEV_TTY "/dev/tty"
45 struct bcache
*bcache
;
48 /* A fast way to get from a psymtab to its symtab (after the first time). */
49 #define PSYMTAB_TO_SYMTAB(pst) \
50 ((pst) -> symtab != NULL ? (pst) -> symtab : psymtab_to_symtab (pst))
52 static struct partial_symbol
*match_partial_symbol (struct partial_symtab
*,
54 const char *, domain_enum
,
55 symbol_compare_ftype
*,
56 symbol_compare_ftype
*);
58 static struct partial_symbol
*lookup_partial_symbol (struct partial_symtab
*,
62 static char *psymtab_to_fullname (struct partial_symtab
*ps
);
64 static struct partial_symbol
*find_pc_sect_psymbol (struct partial_symtab
*,
66 struct obj_section
*);
68 static struct partial_symbol
*fixup_psymbol_section (struct partial_symbol
70 struct objfile
*objfile
);
72 static struct symtab
*psymtab_to_symtab (struct partial_symtab
*pst
);
74 /* Ensure that the partial symbols for OBJFILE have been loaded. This
75 function always returns its argument, as a convenience. */
78 require_partial_symbols (struct objfile
*objfile
, int verbose
)
80 if ((objfile
->flags
& OBJF_PSYMTABS_READ
) == 0)
82 objfile
->flags
|= OBJF_PSYMTABS_READ
;
84 if (objfile
->sf
->sym_read_psymbols
)
88 printf_unfiltered (_("Reading symbols from %s..."),
90 gdb_flush (gdb_stdout
);
92 (*objfile
->sf
->sym_read_psymbols
) (objfile
);
95 if (!objfile_has_symbols (objfile
))
98 printf_unfiltered (_("(no debugging symbols found)..."));
102 printf_unfiltered (_("done.\n"));
110 /* Traverse all psymtabs in one objfile, requiring that the psymtabs
113 #define ALL_OBJFILE_PSYMTABS_REQUIRED(objfile, p) \
114 for ((p) = require_partial_symbols (objfile, 1)->psymtabs; \
118 /* We want to make sure this file always requires psymtabs. */
120 #undef ALL_OBJFILE_PSYMTABS
122 /* Traverse all psymtabs in all objfiles. */
124 #define ALL_PSYMTABS(objfile, p) \
125 ALL_OBJFILES (objfile) \
126 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
128 /* Lookup the partial symbol table of a source file named NAME.
129 *If* there is no '/' in the name, a match after a '/'
130 in the psymtab filename will also work. */
132 static struct partial_symtab
*
133 lookup_partial_symtab (struct objfile
*objfile
, const char *name
,
134 const char *full_path
, const char *real_path
)
136 struct partial_symtab
*pst
;
137 const char *name_basename
= lbasename (name
);
139 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
141 if (FILENAME_CMP (name
, pst
->filename
) == 0)
146 /* Before we invoke realpath, which can get expensive when many
147 files are involved, do a quick comparison of the basenames. */
148 if (! basenames_may_differ
149 && FILENAME_CMP (name_basename
, lbasename (pst
->filename
)) != 0)
152 /* If the user gave us an absolute path, try to find the file in
153 this symtab and use its absolute path. */
154 if (full_path
!= NULL
)
156 psymtab_to_fullname (pst
);
157 if (pst
->fullname
!= NULL
158 && FILENAME_CMP (full_path
, pst
->fullname
) == 0)
164 if (real_path
!= NULL
)
167 psymtab_to_fullname (pst
);
168 if (pst
->fullname
!= NULL
)
170 rp
= gdb_realpath (pst
->fullname
);
171 make_cleanup (xfree
, rp
);
173 if (rp
!= NULL
&& FILENAME_CMP (real_path
, rp
) == 0)
180 /* Now, search for a matching tail (only if name doesn't have any dirs). */
182 if (name_basename
== name
)
183 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
185 if (FILENAME_CMP (lbasename (pst
->filename
), name
) == 0)
193 lookup_symtab_via_partial_symtab (struct objfile
*objfile
, const char *name
,
194 const char *full_path
, const char *real_path
,
195 struct symtab
**result
)
197 struct partial_symtab
*ps
;
199 ps
= lookup_partial_symtab (objfile
, name
, full_path
, real_path
);
204 error (_("Internal: readin %s pst for `%s' found when no symtab found."),
207 *result
= PSYMTAB_TO_SYMTAB (ps
);
211 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
212 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
214 static struct partial_symtab
*
215 find_pc_sect_psymtab_closer (CORE_ADDR pc
, struct obj_section
*section
,
216 struct partial_symtab
*pst
,
217 struct minimal_symbol
*msymbol
)
219 struct objfile
*objfile
= pst
->objfile
;
220 struct partial_symtab
*tpst
;
221 struct partial_symtab
*best_pst
= pst
;
222 CORE_ADDR best_addr
= pst
->textlow
;
224 /* An objfile that has its functions reordered might have
225 many partial symbol tables containing the PC, but
226 we want the partial symbol table that contains the
227 function containing the PC. */
228 if (!(objfile
->flags
& OBJF_REORDERED
) &&
229 section
== 0) /* Can't validate section this way. */
235 /* The code range of partial symtabs sometimes overlap, so, in
236 the loop below, we need to check all partial symtabs and
237 find the one that fits better for the given PC address. We
238 select the partial symtab that contains a symbol whose
239 address is closest to the PC address. By closest we mean
240 that find_pc_sect_symbol returns the symbol with address
241 that is closest and still less than the given PC. */
242 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
244 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
246 struct partial_symbol
*p
;
249 /* NOTE: This assumes that every psymbol has a
250 corresponding msymbol, which is not necessarily
251 true; the debug info might be much richer than the
252 object's symbol table. */
253 p
= find_pc_sect_psymbol (tpst
, pc
, section
);
255 && SYMBOL_VALUE_ADDRESS (p
)
256 == SYMBOL_VALUE_ADDRESS (msymbol
))
259 /* Also accept the textlow value of a psymtab as a
260 "symbol", to provide some support for partial
261 symbol tables with line information but no debug
262 symbols (e.g. those produced by an assembler). */
264 this_addr
= SYMBOL_VALUE_ADDRESS (p
);
266 this_addr
= tpst
->textlow
;
268 /* Check whether it is closer than our current
269 BEST_ADDR. Since this symbol address is
270 necessarily lower or equal to PC, the symbol closer
271 to PC is the symbol which address is the highest.
272 This way we return the psymtab which contains such
273 best match symbol. This can help in cases where the
274 symbol information/debuginfo is not complete, like
275 for instance on IRIX6 with gcc, where no debug info
276 is emitted for statics. (See also the nodebug.exp
278 if (this_addr
> best_addr
)
280 best_addr
= this_addr
;
288 /* Find which partial symtab contains PC and SECTION. Return 0 if
289 none. We return the psymtab that contains a symbol whose address
290 exactly matches PC, or, if we cannot find an exact match, the
291 psymtab that contains a symbol whose address is closest to PC. */
292 static struct partial_symtab
*
293 find_pc_sect_psymtab (struct objfile
*objfile
, CORE_ADDR pc
,
294 struct obj_section
*section
,
295 struct minimal_symbol
*msymbol
)
297 struct partial_symtab
*pst
;
299 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
300 than the later used TEXTLOW/TEXTHIGH one. */
302 if (objfile
->psymtabs_addrmap
!= NULL
)
304 pst
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
307 /* FIXME: addrmaps currently do not handle overlayed sections,
308 so fall back to the non-addrmap case if we're debugging
309 overlays and the addrmap returned the wrong section. */
310 if (overlay_debugging
&& msymbol
&& section
)
312 struct partial_symbol
*p
;
314 /* NOTE: This assumes that every psymbol has a
315 corresponding msymbol, which is not necessarily
316 true; the debug info might be much richer than the
317 object's symbol table. */
318 p
= find_pc_sect_psymbol (pst
, pc
, section
);
320 || SYMBOL_VALUE_ADDRESS (p
)
321 != SYMBOL_VALUE_ADDRESS (msymbol
))
325 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
326 PSYMTABS_ADDRMAP we used has already the best 1-byte
327 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
328 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
337 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
338 which still have no corresponding full SYMTABs read. But it is not
339 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
342 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
343 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
344 debug info type in single OBJFILE. */
346 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
347 if (pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
349 struct partial_symtab
*best_pst
;
351 best_pst
= find_pc_sect_psymtab_closer (pc
, section
, pst
, msymbol
);
352 if (best_pst
!= NULL
)
359 static struct symtab
*
360 find_pc_sect_symtab_from_partial (struct objfile
*objfile
,
361 struct minimal_symbol
*msymbol
,
362 CORE_ADDR pc
, struct obj_section
*section
,
365 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
369 if (warn_if_readin
&& ps
->readin
)
370 /* Might want to error() here (in case symtab is corrupt and
371 will cause a core dump), but maybe we can successfully
372 continue, so let's not. */
374 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
375 paddress (get_objfile_arch (ps
->objfile
), pc
));
376 return PSYMTAB_TO_SYMTAB (ps
);
381 /* Find which partial symbol within a psymtab matches PC and SECTION.
384 static struct partial_symbol
*
385 find_pc_sect_psymbol (struct partial_symtab
*psymtab
, CORE_ADDR pc
,
386 struct obj_section
*section
)
388 struct partial_symbol
*best
= NULL
, *p
, **pp
;
391 gdb_assert (psymtab
!= NULL
);
393 /* Cope with programs that start at address 0. */
394 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
396 /* Search the global symbols as well as the static symbols, so that
397 find_pc_partial_function doesn't use a minimal symbol and thus
398 cache a bad endaddr. */
399 for (pp
= psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
400 (pp
- (psymtab
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
401 < psymtab
->n_global_syms
);
405 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
406 && SYMBOL_CLASS (p
) == LOC_BLOCK
407 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
408 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
409 || (psymtab
->textlow
== 0
410 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
412 if (section
) /* Match on a specific section. */
414 fixup_psymbol_section (p
, psymtab
->objfile
);
415 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p
), section
))
418 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
423 for (pp
= psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
424 (pp
- (psymtab
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
425 < psymtab
->n_static_syms
);
429 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
430 && SYMBOL_CLASS (p
) == LOC_BLOCK
431 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
432 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
433 || (psymtab
->textlow
== 0
434 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
436 if (section
) /* Match on a specific section. */
438 fixup_psymbol_section (p
, psymtab
->objfile
);
439 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p
), section
))
442 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
450 static struct partial_symbol
*
451 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
458 if (SYMBOL_OBJ_SECTION (psym
))
461 gdb_assert (objfile
);
463 switch (SYMBOL_CLASS (psym
))
468 addr
= SYMBOL_VALUE_ADDRESS (psym
);
471 /* Nothing else will be listed in the minsyms -- no use looking
476 fixup_section (&psym
->ginfo
, addr
, objfile
);
481 static struct symtab
*
482 lookup_symbol_aux_psymtabs (struct objfile
*objfile
,
483 int block_index
, const char *name
,
484 const domain_enum domain
)
486 struct partial_symtab
*ps
;
487 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
489 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
491 if (!ps
->readin
&& lookup_partial_symbol (ps
, name
, psymtab_index
, domain
))
493 struct symbol
*sym
= NULL
;
494 struct symtab
*stab
= PSYMTAB_TO_SYMTAB (ps
);
496 /* Some caution must be observed with overloaded functions
497 and methods, since the psymtab will not contain any overload
498 information (but NAME might contain it). */
501 struct blockvector
*bv
= BLOCKVECTOR (stab
);
502 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
504 sym
= lookup_block_symbol (block
, name
, domain
);
507 if (sym
&& strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
510 /* Keep looking through other psymtabs. */
517 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
518 the global block of PST if GLOBAL, and otherwise the static block.
519 MATCH is the comparison operation that returns true iff MATCH (s,
520 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
521 non-null, the symbols in the block are assumed to be ordered
522 according to it (allowing binary search). It must be compatible
523 with MATCH. Returns the symbol, if found, and otherwise NULL. */
525 static struct partial_symbol
*
526 match_partial_symbol (struct partial_symtab
*pst
, int global
,
527 const char *name
, domain_enum domain
,
528 symbol_compare_ftype
*match
,
529 symbol_compare_ftype
*ordered_compare
)
531 struct partial_symbol
**start
, **psym
;
532 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
533 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
534 int do_linear_search
= 1;
539 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
540 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
542 if (global
&& ordered_compare
) /* Can use a binary search. */
544 do_linear_search
= 0;
546 /* Binary search. This search is guaranteed to end with center
547 pointing at the earliest partial symbol whose name might be
548 correct. At that point *all* partial symbols with an
549 appropriate name will be checked against the correct
553 top
= start
+ length
- 1;
557 center
= bottom
+ (top
- bottom
) / 2;
558 gdb_assert (center
< top
);
559 if (!do_linear_search
560 && (SYMBOL_LANGUAGE (*center
) == language_java
))
561 do_linear_search
= 1;
562 if (ordered_compare (SYMBOL_SEARCH_NAME (*center
), name
) >= 0)
567 gdb_assert (top
== bottom
);
569 while (top
<= real_top
570 && match (SYMBOL_SEARCH_NAME (*top
), name
) == 0)
572 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
573 SYMBOL_DOMAIN (*top
), domain
))
579 /* Can't use a binary search or else we found during the binary search that
580 we should also do a linear search. */
582 if (do_linear_search
)
584 for (psym
= start
; psym
< start
+ length
; psym
++)
586 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
587 SYMBOL_DOMAIN (*psym
), domain
)
588 && match (SYMBOL_SEARCH_NAME (*psym
), name
) == 0)
597 pre_expand_symtabs_matching_psymtabs (struct objfile
*objfile
,
598 enum block_enum block_kind
,
605 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
606 not contain any method/function instance information (since this would
607 force reading type information while reading psymtabs). Therefore,
608 if NAME contains overload information, it must be stripped before searching
611 The caller is responsible for freeing the return result. */
614 psymtab_search_name (const char *name
)
616 switch (current_language
->la_language
)
621 if (strchr (name
, '('))
623 char *ret
= cp_remove_params (name
);
635 return xstrdup (name
);
638 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
639 Check the global symbols if GLOBAL, the static symbols if not. */
641 static struct partial_symbol
*
642 lookup_partial_symbol (struct partial_symtab
*pst
, const char *name
,
643 int global
, domain_enum domain
)
645 struct partial_symbol
**start
, **psym
;
646 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
647 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
648 int do_linear_search
= 1;
650 struct cleanup
*cleanup
;
657 search_name
= psymtab_search_name (name
);
658 cleanup
= make_cleanup (xfree
, search_name
);
660 pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
:
661 pst
->objfile
->static_psymbols
.list
+ pst
->statics_offset
);
663 if (global
) /* This means we can use a binary search. */
665 do_linear_search
= 0;
667 /* Binary search. This search is guaranteed to end with center
668 pointing at the earliest partial symbol whose name might be
669 correct. At that point *all* partial symbols with an
670 appropriate name will be checked against the correct
674 top
= start
+ length
- 1;
678 center
= bottom
+ (top
- bottom
) / 2;
680 internal_error (__FILE__
, __LINE__
,
681 _("failed internal consistency check"));
682 if (!do_linear_search
683 && SYMBOL_LANGUAGE (*center
) == language_java
)
685 do_linear_search
= 1;
687 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center
),
697 if (!(top
== bottom
))
698 internal_error (__FILE__
, __LINE__
,
699 _("failed internal consistency check"));
701 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
702 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
703 while (top
>= start
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, search_name
))
706 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
709 while (top
<= real_top
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, search_name
))
711 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
712 SYMBOL_DOMAIN (*top
), domain
))
714 do_cleanups (cleanup
);
721 /* Can't use a binary search or else we found during the binary search that
722 we should also do a linear search. */
724 if (do_linear_search
)
726 for (psym
= start
; psym
< start
+ length
; psym
++)
728 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
729 SYMBOL_DOMAIN (*psym
), domain
)
730 && SYMBOL_MATCHES_SEARCH_NAME (*psym
, search_name
))
732 do_cleanups (cleanup
);
738 do_cleanups (cleanup
);
742 /* Get the symbol table that corresponds to a partial_symtab.
743 This is fast after the first time you do it. In fact, there
744 is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
747 static struct symtab
*
748 psymtab_to_symtab (struct partial_symtab
*pst
)
750 /* If it's been looked up before, return it. */
754 /* If it has not yet been read in, read it. */
757 struct cleanup
*back_to
= increment_reading_symtab ();
759 (*pst
->read_symtab
) (pst
);
760 do_cleanups (back_to
);
767 relocate_psymtabs (struct objfile
*objfile
,
768 struct section_offsets
*new_offsets
,
769 struct section_offsets
*delta
)
771 struct partial_symbol
**psym
;
772 struct partial_symtab
*p
;
774 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
776 p
->textlow
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
777 p
->texthigh
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
780 for (psym
= objfile
->global_psymbols
.list
;
781 psym
< objfile
->global_psymbols
.next
;
784 fixup_psymbol_section (*psym
, objfile
);
785 if (SYMBOL_SECTION (*psym
) >= 0)
786 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
787 SYMBOL_SECTION (*psym
));
789 for (psym
= objfile
->static_psymbols
.list
;
790 psym
< objfile
->static_psymbols
.next
;
793 fixup_psymbol_section (*psym
, objfile
);
794 if (SYMBOL_SECTION (*psym
) >= 0)
795 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
796 SYMBOL_SECTION (*psym
));
800 static struct symtab
*
801 find_last_source_symtab_from_partial (struct objfile
*ofp
)
803 struct partial_symtab
*ps
;
804 struct partial_symtab
*cs_pst
= 0;
806 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp
, ps
)
808 const char *name
= ps
->filename
;
809 int len
= strlen (name
);
811 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
812 || strcmp (name
, "<<C++-namespaces>>") == 0)))
820 internal_error (__FILE__
, __LINE__
,
821 _("select_source_symtab: "
822 "readin pst found and no symtabs."));
825 return PSYMTAB_TO_SYMTAB (cs_pst
);
831 forget_cached_source_info_partial (struct objfile
*objfile
)
833 struct partial_symtab
*pst
;
835 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
837 if (pst
->fullname
!= NULL
)
839 xfree (pst
->fullname
);
840 pst
->fullname
= NULL
;
846 print_partial_symbols (struct gdbarch
*gdbarch
,
847 struct partial_symbol
**p
, int count
, char *what
,
848 struct ui_file
*outfile
)
850 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
853 fprintf_filtered (outfile
, " `%s'", SYMBOL_LINKAGE_NAME (*p
));
854 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
856 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
858 fputs_filtered (", ", outfile
);
859 switch (SYMBOL_DOMAIN (*p
))
862 fputs_filtered ("undefined domain, ", outfile
);
865 /* This is the usual thing -- don't print it. */
868 fputs_filtered ("struct domain, ", outfile
);
871 fputs_filtered ("label domain, ", outfile
);
874 fputs_filtered ("<invalid domain>, ", outfile
);
877 switch (SYMBOL_CLASS (*p
))
880 fputs_filtered ("undefined", outfile
);
883 fputs_filtered ("constant int", outfile
);
886 fputs_filtered ("static", outfile
);
889 fputs_filtered ("register", outfile
);
892 fputs_filtered ("pass by value", outfile
);
895 fputs_filtered ("pass by reference", outfile
);
897 case LOC_REGPARM_ADDR
:
898 fputs_filtered ("register address parameter", outfile
);
901 fputs_filtered ("stack parameter", outfile
);
904 fputs_filtered ("type", outfile
);
907 fputs_filtered ("label", outfile
);
910 fputs_filtered ("function", outfile
);
912 case LOC_CONST_BYTES
:
913 fputs_filtered ("constant bytes", outfile
);
916 fputs_filtered ("unresolved", outfile
);
918 case LOC_OPTIMIZED_OUT
:
919 fputs_filtered ("optimized out", outfile
);
922 fputs_filtered ("computed at runtime", outfile
);
925 fputs_filtered ("<invalid location>", outfile
);
928 fputs_filtered (", ", outfile
);
929 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (*p
)), outfile
);
930 fprintf_filtered (outfile
, "\n");
936 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
937 struct ui_file
*outfile
)
939 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
942 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
944 fprintf_filtered (outfile
, "(object ");
945 gdb_print_host_address (psymtab
, outfile
);
946 fprintf_filtered (outfile
, ")\n\n");
947 fprintf_unfiltered (outfile
, " Read from object file %s (",
949 gdb_print_host_address (objfile
, outfile
);
950 fprintf_unfiltered (outfile
, ")\n");
954 fprintf_filtered (outfile
,
955 " Full symtab was read (at ");
956 gdb_print_host_address (psymtab
->symtab
, outfile
);
957 fprintf_filtered (outfile
, " by function at ");
958 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
959 fprintf_filtered (outfile
, ")\n");
962 fprintf_filtered (outfile
, " Relocate symbols by ");
963 for (i
= 0; i
< psymtab
->objfile
->num_sections
; ++i
)
966 fprintf_filtered (outfile
, ", ");
968 fputs_filtered (paddress (gdbarch
,
969 ANOFFSET (psymtab
->section_offsets
, i
)),
972 fprintf_filtered (outfile
, "\n");
974 fprintf_filtered (outfile
, " Symbols cover text addresses ");
975 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
), outfile
);
976 fprintf_filtered (outfile
, "-");
977 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
), outfile
);
978 fprintf_filtered (outfile
, "\n");
979 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
980 psymtab
->number_of_dependencies
);
981 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
983 fprintf_filtered (outfile
, " %d ", i
);
984 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
985 fprintf_filtered (outfile
, " %s\n",
986 psymtab
->dependencies
[i
]->filename
);
988 if (psymtab
->n_global_syms
> 0)
990 print_partial_symbols (gdbarch
,
991 objfile
->global_psymbols
.list
992 + psymtab
->globals_offset
,
993 psymtab
->n_global_syms
, "Global", outfile
);
995 if (psymtab
->n_static_syms
> 0)
997 print_partial_symbols (gdbarch
,
998 objfile
->static_psymbols
.list
999 + psymtab
->statics_offset
,
1000 psymtab
->n_static_syms
, "Static", outfile
);
1002 fprintf_filtered (outfile
, "\n");
1006 print_psymtab_stats_for_objfile (struct objfile
*objfile
)
1009 struct partial_symtab
*ps
;
1012 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1014 if (ps
->readin
== 0)
1017 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
1021 dump_psymtabs_for_objfile (struct objfile
*objfile
)
1023 struct partial_symtab
*psymtab
;
1025 if (objfile
->psymtabs
)
1027 printf_filtered ("Psymtabs:\n");
1028 for (psymtab
= objfile
->psymtabs
;
1030 psymtab
= psymtab
->next
)
1032 printf_filtered ("%s at ",
1034 gdb_print_host_address (psymtab
, gdb_stdout
);
1035 printf_filtered (", ");
1036 if (psymtab
->objfile
!= objfile
)
1038 printf_filtered ("NOT ON CHAIN! ");
1042 printf_filtered ("\n\n");
1046 /* Look through the partial symtabs for all symbols which begin
1047 by matching FUNC_NAME. Make sure we read that symbol table in. */
1050 read_symtabs_for_function (struct objfile
*objfile
, const char *func_name
)
1052 struct partial_symtab
*ps
;
1054 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1059 if ((lookup_partial_symbol (ps
, func_name
, 1, VAR_DOMAIN
)
1061 || (lookup_partial_symbol (ps
, func_name
, 0, VAR_DOMAIN
)
1063 psymtab_to_symtab (ps
);
1068 expand_partial_symbol_tables (struct objfile
*objfile
)
1070 struct partial_symtab
*psymtab
;
1072 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1074 psymtab_to_symtab (psymtab
);
1079 read_psymtabs_with_filename (struct objfile
*objfile
, const char *filename
)
1081 struct partial_symtab
*p
;
1083 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
1085 if (filename_cmp (filename
, p
->filename
) == 0)
1086 PSYMTAB_TO_SYMTAB (p
);
1091 map_symbol_filenames_psymtab (struct objfile
*objfile
,
1092 symbol_filename_ftype
*fun
, void *data
,
1095 struct partial_symtab
*ps
;
1097 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1099 const char *fullname
;
1106 fullname
= psymtab_to_fullname (ps
);
1109 (*fun
) (ps
->filename
, fullname
, data
);
1113 int find_and_open_source (const char *filename
,
1114 const char *dirname
,
1117 /* Finds the fullname that a partial_symtab represents.
1119 If this functions finds the fullname, it will save it in ps->fullname
1120 and it will also return the value.
1122 If this function fails to find the file that this partial_symtab represents,
1123 NULL will be returned and ps->fullname will be set to NULL. */
1126 psymtab_to_fullname (struct partial_symtab
*ps
)
1133 /* Use cached copy if we have it.
1134 We rely on forget_cached_source_info being called appropriately
1135 to handle cases like the file being moved. */
1137 return ps
->fullname
;
1139 r
= find_and_open_source (ps
->filename
, ps
->dirname
, &ps
->fullname
);
1144 return ps
->fullname
;
1151 find_symbol_file_from_partial (struct objfile
*objfile
, const char *name
)
1153 struct partial_symtab
*pst
;
1155 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
1157 if (lookup_partial_symbol (pst
, name
, 1, VAR_DOMAIN
))
1158 return pst
->filename
;
1163 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1164 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1165 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1166 ever returns non-zero, and otherwise returns 0. */
1169 map_block (const char *name
, domain_enum
namespace, struct objfile
*objfile
,
1170 struct block
*block
,
1171 int (*callback
) (struct block
*, struct symbol
*, void *),
1172 void *data
, symbol_compare_ftype
*match
)
1174 struct dict_iterator iter
;
1177 for (sym
= dict_iter_match_first (BLOCK_DICT (block
), name
, match
, &iter
);
1178 sym
!= NULL
; sym
= dict_iter_match_next (name
, match
, &iter
))
1180 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym
),
1181 SYMBOL_DOMAIN (sym
), namespace))
1183 if (callback (block
, sym
, data
))
1191 /* Psymtab version of map_matching_symbols. See its definition in
1192 the definition of quick_symbol_functions in symfile.h. */
1195 map_matching_symbols_psymtab (const char *name
, domain_enum
namespace,
1196 struct objfile
*objfile
, int global
,
1197 int (*callback
) (struct block
*,
1198 struct symbol
*, void *),
1200 symbol_compare_ftype
*match
,
1201 symbol_compare_ftype
*ordered_compare
)
1203 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1204 struct partial_symtab
*ps
;
1206 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1210 || match_partial_symbol (ps
, global
, name
, namespace, match
,
1213 struct symtab
*s
= PSYMTAB_TO_SYMTAB (ps
);
1214 struct block
*block
;
1216 if (s
== NULL
|| !s
->primary
)
1218 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), block_kind
);
1219 if (map_block (name
, namespace, objfile
, block
,
1220 callback
, data
, match
))
1222 if (callback (block
, NULL
, data
))
1229 expand_symtabs_matching_via_partial (struct objfile
*objfile
,
1230 int (*file_matcher
) (const char *,
1232 int (*name_matcher
) (const char *,
1234 enum search_domain kind
,
1237 struct partial_symtab
*ps
;
1239 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1241 struct partial_symbol
**psym
;
1242 struct partial_symbol
**bound
, **gbound
, **sbound
;
1248 if (file_matcher
&& ! (*file_matcher
) (ps
->filename
, data
))
1251 gbound
= objfile
->global_psymbols
.list
1252 + ps
->globals_offset
+ ps
->n_global_syms
;
1253 sbound
= objfile
->static_psymbols
.list
1254 + ps
->statics_offset
+ ps
->n_static_syms
;
1257 /* Go through all of the symbols stored in a partial
1258 symtab in one loop. */
1259 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1264 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
1266 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1277 if ((kind
== ALL_DOMAIN
1278 || (kind
== VARIABLES_DOMAIN
1279 && SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
1280 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
1281 || (kind
== FUNCTIONS_DOMAIN
1282 && SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
1283 || (kind
== TYPES_DOMAIN
1284 && SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
))
1285 && (*name_matcher
) (SYMBOL_NATURAL_NAME (*psym
), data
))
1287 PSYMTAB_TO_SYMTAB (ps
);
1297 objfile_has_psyms (struct objfile
*objfile
)
1299 return objfile
->psymtabs
!= NULL
;
1302 const struct quick_symbol_functions psym_functions
=
1305 find_last_source_symtab_from_partial
,
1306 forget_cached_source_info_partial
,
1307 lookup_symtab_via_partial_symtab
,
1308 lookup_symbol_aux_psymtabs
,
1309 pre_expand_symtabs_matching_psymtabs
,
1310 print_psymtab_stats_for_objfile
,
1311 dump_psymtabs_for_objfile
,
1313 read_symtabs_for_function
,
1314 expand_partial_symbol_tables
,
1315 read_psymtabs_with_filename
,
1316 find_symbol_file_from_partial
,
1317 map_matching_symbols_psymtab
,
1318 expand_symtabs_matching_via_partial
,
1319 find_pc_sect_symtab_from_partial
,
1320 map_symbol_filenames_psymtab
1325 /* This compares two partial symbols by names, using strcmp_iw_ordered
1326 for the comparison. */
1329 compare_psymbols (const void *s1p
, const void *s2p
)
1331 struct partial_symbol
*const *s1
= s1p
;
1332 struct partial_symbol
*const *s2
= s2p
;
1334 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1
),
1335 SYMBOL_SEARCH_NAME (*s2
));
1339 sort_pst_symbols (struct partial_symtab
*pst
)
1341 /* Sort the global list; don't sort the static list. */
1343 qsort (pst
->objfile
->global_psymbols
.list
+ pst
->globals_offset
,
1344 pst
->n_global_syms
, sizeof (struct partial_symbol
*),
1348 /* Allocate and partially fill a partial symtab. It will be
1349 completely filled at the end of the symbol list.
1351 FILENAME is the name of the symbol-file we are reading from. */
1353 struct partial_symtab
*
1354 start_psymtab_common (struct objfile
*objfile
,
1355 struct section_offsets
*section_offsets
,
1356 const char *filename
,
1357 CORE_ADDR textlow
, struct partial_symbol
**global_syms
,
1358 struct partial_symbol
**static_syms
)
1360 struct partial_symtab
*psymtab
;
1362 psymtab
= allocate_psymtab (filename
, objfile
);
1363 psymtab
->section_offsets
= section_offsets
;
1364 psymtab
->textlow
= textlow
;
1365 psymtab
->texthigh
= psymtab
->textlow
; /* default */
1366 psymtab
->globals_offset
= global_syms
- objfile
->global_psymbols
.list
;
1367 psymtab
->statics_offset
= static_syms
- objfile
->static_psymbols
.list
;
1371 /* Calculate a hash code for the given partial symbol. The hash is
1372 calculated using the symbol's value, language, domain, class
1373 and name. These are the values which are set by
1374 add_psymbol_to_bcache. */
1376 static unsigned long
1377 psymbol_hash (const void *addr
, int length
)
1379 unsigned long h
= 0;
1380 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1381 unsigned int lang
= psymbol
->ginfo
.language
;
1382 unsigned int domain
= PSYMBOL_DOMAIN (psymbol
);
1383 unsigned int class = PSYMBOL_CLASS (psymbol
);
1385 h
= hash_continue (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1386 h
= hash_continue (&lang
, sizeof (unsigned int), h
);
1387 h
= hash_continue (&domain
, sizeof (unsigned int), h
);
1388 h
= hash_continue (&class, sizeof (unsigned int), h
);
1389 h
= hash_continue (psymbol
->ginfo
.name
, strlen (psymbol
->ginfo
.name
), h
);
1394 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1395 For the comparison this function uses a symbols value,
1396 language, domain, class and name. */
1399 psymbol_compare (const void *addr1
, const void *addr2
, int length
)
1401 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1402 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1404 return (memcmp (&sym1
->ginfo
.value
, &sym1
->ginfo
.value
,
1405 sizeof (sym1
->ginfo
.value
)) == 0
1406 && sym1
->ginfo
.language
== sym2
->ginfo
.language
1407 && PSYMBOL_DOMAIN (sym1
) == PSYMBOL_DOMAIN (sym2
)
1408 && PSYMBOL_CLASS (sym1
) == PSYMBOL_CLASS (sym2
)
1409 && sym1
->ginfo
.name
== sym2
->ginfo
.name
);
1412 /* Initialize a partial symbol bcache. */
1414 struct psymbol_bcache
*
1415 psymbol_bcache_init (void)
1417 struct psymbol_bcache
*bcache
= XCALLOC (1, struct psymbol_bcache
);
1418 bcache
->bcache
= bcache_xmalloc (psymbol_hash
, psymbol_compare
);
1422 /* Free a partial symbol bcache. */
1424 psymbol_bcache_free (struct psymbol_bcache
*bcache
)
1429 bcache_xfree (bcache
->bcache
);
1433 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1436 psymbol_bcache_get_bcache (struct psymbol_bcache
*bcache
)
1438 return bcache
->bcache
;
1441 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1442 symbol before, add a copy to BCACHE. In either case, return a pointer
1443 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1444 1 in case of new entry or 0 if returning an old entry. */
1446 static const struct partial_symbol
*
1447 psymbol_bcache_full (struct partial_symbol
*sym
,
1448 struct psymbol_bcache
*bcache
,
1451 return bcache_full (sym
,
1452 sizeof (struct partial_symbol
),
1457 /* Helper function, initialises partial symbol structure and stashes
1458 it into objfile's bcache. Note that our caching mechanism will
1459 use all fields of struct partial_symbol to determine hash value of the
1460 structure. In other words, having two symbols with the same name but
1461 different domain (or address) is possible and correct. */
1463 static const struct partial_symbol
*
1464 add_psymbol_to_bcache (const char *name
, int namelength
, int copy_name
,
1466 enum address_class
class,
1467 long val
, /* Value as a long */
1468 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1469 enum language language
, struct objfile
*objfile
,
1472 struct partial_symbol psymbol
;
1474 /* We must ensure that the entire 'value' field has been zeroed
1475 before assigning to it, because an assignment may not write the
1477 memset (&psymbol
.ginfo
.value
, 0, sizeof (psymbol
.ginfo
.value
));
1479 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1482 SYMBOL_VALUE (&psymbol
) = val
;
1486 SYMBOL_VALUE_ADDRESS (&psymbol
) = coreaddr
;
1488 SYMBOL_SECTION (&psymbol
) = 0;
1489 SYMBOL_OBJ_SECTION (&psymbol
) = NULL
;
1490 SYMBOL_SET_LANGUAGE (&psymbol
, language
);
1491 PSYMBOL_DOMAIN (&psymbol
) = domain
;
1492 PSYMBOL_CLASS (&psymbol
) = class;
1494 SYMBOL_SET_NAMES (&psymbol
, name
, namelength
, copy_name
, objfile
);
1496 /* Stash the partial symbol away in the cache. */
1497 return psymbol_bcache_full (&psymbol
,
1498 objfile
->psymbol_cache
,
1502 /* Increase the space allocated for LISTP, which is probably
1503 global_psymbols or static_psymbols. This space will eventually
1504 be freed in free_objfile(). */
1507 extend_psymbol_list (struct psymbol_allocation_list
*listp
,
1508 struct objfile
*objfile
)
1512 if (listp
->size
== 0)
1515 listp
->list
= (struct partial_symbol
**)
1516 xmalloc (new_size
* sizeof (struct partial_symbol
*));
1520 new_size
= listp
->size
* 2;
1521 listp
->list
= (struct partial_symbol
**)
1522 xrealloc ((char *) listp
->list
,
1523 new_size
* sizeof (struct partial_symbol
*));
1525 /* Next assumes we only went one over. Should be good if
1526 program works correctly. */
1527 listp
->next
= listp
->list
+ listp
->size
;
1528 listp
->size
= new_size
;
1531 /* Helper function, adds partial symbol to the given partial symbol
1535 append_psymbol_to_list (struct psymbol_allocation_list
*list
,
1536 const struct partial_symbol
*psym
,
1537 struct objfile
*objfile
)
1539 if (list
->next
>= list
->list
+ list
->size
)
1540 extend_psymbol_list (list
, objfile
);
1541 *list
->next
++ = (struct partial_symbol
*) psym
;
1542 OBJSTAT (objfile
, n_psyms
++);
1545 /* Add a symbol with a long value to a psymtab.
1546 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1547 Return the partial symbol that has been added. */
1549 /* NOTE: carlton/2003-09-11: The reason why we return the partial
1550 symbol is so that callers can get access to the symbol's demangled
1551 name, which they don't have any cheap way to determine otherwise.
1552 (Currenly, dwarf2read.c is the only file who uses that information,
1553 though it's possible that other readers might in the future.)
1554 Elena wasn't thrilled about that, and I don't blame her, but we
1555 couldn't come up with a better way to get that information. If
1556 it's needed in other situations, we could consider breaking up
1557 SYMBOL_SET_NAMES to provide access to the demangled name lookup
1560 const struct partial_symbol
*
1561 add_psymbol_to_list (const char *name
, int namelength
, int copy_name
,
1563 enum address_class
class,
1564 struct psymbol_allocation_list
*list
,
1565 long val
, /* Value as a long */
1566 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1567 enum language language
, struct objfile
*objfile
)
1569 const struct partial_symbol
*psym
;
1573 /* Stash the partial symbol away in the cache. */
1574 psym
= add_psymbol_to_bcache (name
, namelength
, copy_name
, domain
, class,
1575 val
, coreaddr
, language
, objfile
, &added
);
1577 /* Do not duplicate global partial symbols. */
1578 if (list
== &objfile
->global_psymbols
1582 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1583 append_psymbol_to_list (list
, psym
, objfile
);
1587 /* Initialize storage for partial symbols. */
1590 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1592 /* Free any previously allocated psymbol lists. */
1594 if (objfile
->global_psymbols
.list
)
1596 xfree (objfile
->global_psymbols
.list
);
1598 if (objfile
->static_psymbols
.list
)
1600 xfree (objfile
->static_psymbols
.list
);
1603 /* Current best guess is that approximately a twentieth
1604 of the total symbols (in a debugging file) are global or static
1605 oriented symbols. */
1607 objfile
->global_psymbols
.size
= total_symbols
/ 10;
1608 objfile
->static_psymbols
.size
= total_symbols
/ 10;
1610 if (objfile
->global_psymbols
.size
> 0)
1612 objfile
->global_psymbols
.next
=
1613 objfile
->global_psymbols
.list
= (struct partial_symbol
**)
1614 xmalloc ((objfile
->global_psymbols
.size
1615 * sizeof (struct partial_symbol
*)));
1617 if (objfile
->static_psymbols
.size
> 0)
1619 objfile
->static_psymbols
.next
=
1620 objfile
->static_psymbols
.list
= (struct partial_symbol
**)
1621 xmalloc ((objfile
->static_psymbols
.size
1622 * sizeof (struct partial_symbol
*)));
1626 struct partial_symtab
*
1627 allocate_psymtab (const char *filename
, struct objfile
*objfile
)
1629 struct partial_symtab
*psymtab
;
1631 if (objfile
->free_psymtabs
)
1633 psymtab
= objfile
->free_psymtabs
;
1634 objfile
->free_psymtabs
= psymtab
->next
;
1637 psymtab
= (struct partial_symtab
*)
1638 obstack_alloc (&objfile
->objfile_obstack
,
1639 sizeof (struct partial_symtab
));
1641 memset (psymtab
, 0, sizeof (struct partial_symtab
));
1642 psymtab
->filename
= obsavestring (filename
, strlen (filename
),
1643 &objfile
->objfile_obstack
);
1644 psymtab
->symtab
= NULL
;
1646 /* Prepend it to the psymtab list for the objfile it belongs to.
1647 Psymtabs are searched in most recent inserted -> least recent
1650 psymtab
->objfile
= objfile
;
1651 psymtab
->next
= objfile
->psymtabs
;
1652 objfile
->psymtabs
= psymtab
;
1658 discard_psymtab (struct partial_symtab
*pst
)
1660 struct partial_symtab
**prev_pst
;
1663 Empty psymtabs happen as a result of header files which don't
1664 have any symbols in them. There can be a lot of them. But this
1665 check is wrong, in that a psymtab with N_SLINE entries but
1666 nothing else is not empty, but we don't realize that. Fixing
1667 that without slowing things down might be tricky. */
1669 /* First, snip it out of the psymtab chain. */
1671 prev_pst
= &(pst
->objfile
->psymtabs
);
1672 while ((*prev_pst
) != pst
)
1673 prev_pst
= &((*prev_pst
)->next
);
1674 (*prev_pst
) = pst
->next
;
1676 /* Next, put it on a free list for recycling. */
1678 pst
->next
= pst
->objfile
->free_psymtabs
;
1679 pst
->objfile
->free_psymtabs
= pst
;
1685 maintenance_print_psymbols (char *args
, int from_tty
)
1688 struct ui_file
*outfile
;
1689 struct cleanup
*cleanups
;
1690 char *symname
= NULL
;
1691 char *filename
= DEV_TTY
;
1692 struct objfile
*objfile
;
1693 struct partial_symtab
*ps
;
1700 print-psymbols takes an output file name and optional symbol file name"));
1702 argv
= gdb_buildargv (args
);
1703 cleanups
= make_cleanup_freeargv (argv
);
1705 if (argv
[0] != NULL
)
1708 /* If a second arg is supplied, it is a source file name to match on. */
1709 if (argv
[1] != NULL
)
1715 filename
= tilde_expand (filename
);
1716 make_cleanup (xfree
, filename
);
1718 outfile
= gdb_fopen (filename
, FOPEN_WT
);
1720 perror_with_name (filename
);
1721 make_cleanup_ui_file_delete (outfile
);
1724 ALL_PSYMTABS (objfile
, ps
)
1725 if (symname
== NULL
|| filename_cmp (symname
, ps
->filename
) == 0)
1726 dump_psymtab (objfile
, ps
, outfile
);
1728 do_cleanups (cleanups
);
1731 /* List all the partial symbol tables whose names match REGEXP (optional). */
1733 maintenance_info_psymtabs (char *regexp
, int from_tty
)
1735 struct program_space
*pspace
;
1736 struct objfile
*objfile
;
1741 ALL_PSPACES (pspace
)
1742 ALL_PSPACE_OBJFILES (pspace
, objfile
)
1744 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1745 struct partial_symtab
*psymtab
;
1747 /* We don't want to print anything for this objfile until we
1748 actually find a symtab whose name matches. */
1749 int printed_objfile_start
= 0;
1751 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1756 || re_exec (psymtab
->filename
))
1758 if (! printed_objfile_start
)
1760 printf_filtered ("{ objfile %s ", objfile
->name
);
1762 printf_filtered ("((struct objfile *) %s)\n",
1763 host_address_to_string (objfile
));
1764 printed_objfile_start
= 1;
1767 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1769 printf_filtered ("((struct partial_symtab *) %s)\n",
1770 host_address_to_string (psymtab
));
1772 printf_filtered (" readin %s\n",
1773 psymtab
->readin
? "yes" : "no");
1774 printf_filtered (" fullname %s\n",
1776 ? psymtab
->fullname
: "(null)");
1777 printf_filtered (" text addresses ");
1778 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
),
1780 printf_filtered (" -- ");
1781 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
),
1783 printf_filtered ("\n");
1784 printf_filtered (" globals ");
1785 if (psymtab
->n_global_syms
)
1787 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1788 host_address_to_string (psymtab
->objfile
->global_psymbols
.list
1789 + psymtab
->globals_offset
),
1790 psymtab
->n_global_syms
);
1793 printf_filtered ("(none)\n");
1794 printf_filtered (" statics ");
1795 if (psymtab
->n_static_syms
)
1797 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1798 host_address_to_string (psymtab
->objfile
->static_psymbols
.list
1799 + psymtab
->statics_offset
),
1800 psymtab
->n_static_syms
);
1803 printf_filtered ("(none)\n");
1804 printf_filtered (" dependencies ");
1805 if (psymtab
->number_of_dependencies
)
1809 printf_filtered ("{\n");
1810 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1812 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1814 /* Note the string concatenation there --- no comma. */
1815 printf_filtered (" psymtab %s "
1816 "((struct partial_symtab *) %s)\n",
1818 host_address_to_string (dep
));
1820 printf_filtered (" }\n");
1823 printf_filtered ("(none)\n");
1824 printf_filtered (" }\n");
1828 if (printed_objfile_start
)
1829 printf_filtered ("}\n");
1833 /* Check consistency of psymtabs and symtabs. */
1836 maintenance_check_symtabs (char *ignore
, int from_tty
)
1839 struct partial_symbol
**psym
;
1840 struct symtab
*s
= NULL
;
1841 struct partial_symtab
*ps
;
1842 struct blockvector
*bv
;
1843 struct objfile
*objfile
;
1847 ALL_PSYMTABS (objfile
, ps
)
1849 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1851 s
= PSYMTAB_TO_SYMTAB (ps
);
1854 bv
= BLOCKVECTOR (s
);
1855 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1856 psym
= ps
->objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1857 length
= ps
->n_static_syms
;
1860 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
1861 SYMBOL_DOMAIN (*psym
));
1864 printf_filtered ("Static symbol `");
1865 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
1866 printf_filtered ("' only found in ");
1867 puts_filtered (ps
->filename
);
1868 printf_filtered (" psymtab\n");
1872 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
1873 psym
= ps
->objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1874 length
= ps
->n_global_syms
;
1877 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
1878 SYMBOL_DOMAIN (*psym
));
1881 printf_filtered ("Global symbol `");
1882 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
1883 printf_filtered ("' only found in ");
1884 puts_filtered (ps
->filename
);
1885 printf_filtered (" psymtab\n");
1889 if (ps
->texthigh
< ps
->textlow
)
1891 printf_filtered ("Psymtab ");
1892 puts_filtered (ps
->filename
);
1893 printf_filtered (" covers bad range ");
1894 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
1895 printf_filtered (" - ");
1896 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
1897 printf_filtered ("\n");
1900 if (ps
->texthigh
== 0)
1902 if (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
))
1904 printf_filtered ("Psymtab ");
1905 puts_filtered (ps
->filename
);
1906 printf_filtered (" covers ");
1907 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
1908 printf_filtered (" - ");
1909 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
1910 printf_filtered (" but symtab covers only ");
1911 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
1912 printf_filtered (" - ");
1913 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
1914 printf_filtered ("\n");
1922 expand_partial_symbol_names (int (*fun
) (const char *, void *), void *data
)
1924 struct objfile
*objfile
;
1926 ALL_OBJFILES (objfile
)
1929 objfile
->sf
->qf
->expand_symtabs_matching (objfile
, NULL
, fun
,
1935 map_partial_symbol_filenames (symbol_filename_ftype
*fun
, void *data
,
1938 struct objfile
*objfile
;
1940 ALL_OBJFILES (objfile
)
1943 objfile
->sf
->qf
->map_symbol_filenames (objfile
, fun
, data
,