1 /* Partial symbol tables.
3 Copyright (C) 2009-2013 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"
41 #define DEV_TTY "/dev/tty"
46 struct bcache
*bcache
;
49 static struct partial_symbol
*match_partial_symbol (struct objfile
*,
50 struct partial_symtab
*,
52 const char *, domain_enum
,
53 symbol_compare_ftype
*,
54 symbol_compare_ftype
*);
56 static struct partial_symbol
*lookup_partial_symbol (struct objfile
*,
57 struct partial_symtab
*,
61 static const char *psymtab_to_fullname (struct partial_symtab
*ps
);
63 static struct partial_symbol
*find_pc_sect_psymbol (struct objfile
*,
64 struct partial_symtab
*,
66 struct obj_section
*);
68 static void fixup_psymbol_section (struct partial_symbol
*psym
,
69 struct objfile
*objfile
);
71 static struct symtab
*psymtab_to_symtab (struct objfile
*objfile
,
72 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 /* Helper function for partial_map_symtabs_matching_filename that
129 expands the symtabs and calls the iterator. */
132 partial_map_expand_apply (struct objfile
*objfile
,
134 const char *real_path
,
135 struct partial_symtab
*pst
,
136 int (*callback
) (struct symtab
*, void *),
139 struct symtab
*last_made
= objfile
->symtabs
;
141 /* Shared psymtabs should never be seen here. Instead they should
142 be handled properly by the caller. */
143 gdb_assert (pst
->user
== NULL
);
145 /* Don't visit already-expanded psymtabs. */
149 /* This may expand more than one symtab, and we want to iterate over
151 psymtab_to_symtab (objfile
, pst
);
153 return iterate_over_some_symtabs (name
, real_path
, callback
, data
,
154 objfile
->symtabs
, last_made
);
157 /* Implementation of the map_symtabs_matching_filename method. */
160 partial_map_symtabs_matching_filename (struct objfile
*objfile
,
162 const char *real_path
,
163 int (*callback
) (struct symtab
*,
167 struct partial_symtab
*pst
;
168 const char *name_basename
= lbasename (name
);
170 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
172 /* We can skip shared psymtabs here, because any file name will be
173 attached to the unshared psymtab. */
174 if (pst
->user
!= NULL
)
177 /* Anonymous psymtabs don't have a file name. */
181 if (compare_filenames_for_search (pst
->filename
, name
))
183 if (partial_map_expand_apply (objfile
, name
, real_path
,
184 pst
, callback
, data
))
188 /* Before we invoke realpath, which can get expensive when many
189 files are involved, do a quick comparison of the basenames. */
190 if (! basenames_may_differ
191 && FILENAME_CMP (name_basename
, lbasename (pst
->filename
)) != 0)
194 /* If the user gave us an absolute path, try to find the file in
195 this symtab and use its absolute path. */
196 if (real_path
!= NULL
)
198 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
199 gdb_assert (IS_ABSOLUTE_PATH (name
));
200 psymtab_to_fullname (pst
);
201 if (pst
->fullname
!= NULL
202 && FILENAME_CMP (real_path
, pst
->fullname
) == 0)
204 if (partial_map_expand_apply (objfile
, name
, real_path
,
205 pst
, callback
, data
))
214 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
215 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
217 static struct partial_symtab
*
218 find_pc_sect_psymtab_closer (struct objfile
*objfile
,
219 CORE_ADDR pc
, struct obj_section
*section
,
220 struct partial_symtab
*pst
,
221 struct minimal_symbol
*msymbol
)
223 struct partial_symtab
*tpst
;
224 struct partial_symtab
*best_pst
= pst
;
225 CORE_ADDR best_addr
= pst
->textlow
;
227 gdb_assert (!pst
->psymtabs_addrmap_supported
);
229 /* An objfile that has its functions reordered might have
230 many partial symbol tables containing the PC, but
231 we want the partial symbol table that contains the
232 function containing the PC. */
233 if (!(objfile
->flags
& OBJF_REORDERED
) &&
234 section
== 0) /* Can't validate section this way. */
240 /* The code range of partial symtabs sometimes overlap, so, in
241 the loop below, we need to check all partial symtabs and
242 find the one that fits better for the given PC address. We
243 select the partial symtab that contains a symbol whose
244 address is closest to the PC address. By closest we mean
245 that find_pc_sect_symbol returns the symbol with address
246 that is closest and still less than the given PC. */
247 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
249 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
251 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 (objfile
, tpst
, pc
, section
);
260 && SYMBOL_VALUE_ADDRESS (p
)
261 == SYMBOL_VALUE_ADDRESS (msymbol
))
264 /* Also accept the textlow value of a psymtab as a
265 "symbol", to provide some support for partial
266 symbol tables with line information but no debug
267 symbols (e.g. those produced by an assembler). */
269 this_addr
= SYMBOL_VALUE_ADDRESS (p
);
271 this_addr
= tpst
->textlow
;
273 /* Check whether it is closer than our current
274 BEST_ADDR. Since this symbol address is
275 necessarily lower or equal to PC, the symbol closer
276 to PC is the symbol which address is the highest.
277 This way we return the psymtab which contains such
278 best match symbol. This can help in cases where the
279 symbol information/debuginfo is not complete, like
280 for instance on IRIX6 with gcc, where no debug info
281 is emitted for statics. (See also the nodebug.exp
283 if (this_addr
> best_addr
)
285 best_addr
= this_addr
;
293 /* Find which partial symtab contains PC and SECTION. Return 0 if
294 none. We return the psymtab that contains a symbol whose address
295 exactly matches PC, or, if we cannot find an exact match, the
296 psymtab that contains a symbol whose address is closest to PC. */
297 static struct partial_symtab
*
298 find_pc_sect_psymtab (struct objfile
*objfile
, CORE_ADDR pc
,
299 struct obj_section
*section
,
300 struct minimal_symbol
*msymbol
)
302 struct partial_symtab
*pst
;
304 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
305 than the later used TEXTLOW/TEXTHIGH one. */
307 if (objfile
->psymtabs_addrmap
!= NULL
)
309 pst
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
312 /* FIXME: addrmaps currently do not handle overlayed sections,
313 so fall back to the non-addrmap case if we're debugging
314 overlays and the addrmap returned the wrong section. */
315 if (overlay_debugging
&& msymbol
&& section
)
317 struct partial_symbol
*p
;
319 /* NOTE: This assumes that every psymbol has a
320 corresponding msymbol, which is not necessarily
321 true; the debug info might be much richer than the
322 object's symbol table. */
323 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
325 || SYMBOL_VALUE_ADDRESS (p
)
326 != SYMBOL_VALUE_ADDRESS (msymbol
))
330 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
331 PSYMTABS_ADDRMAP we used has already the best 1-byte
332 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
333 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
342 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
343 which still have no corresponding full SYMTABs read. But it is not
344 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
347 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
348 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
349 debug info type in single OBJFILE. */
351 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
352 if (!pst
->psymtabs_addrmap_supported
353 && pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
355 struct partial_symtab
*best_pst
;
357 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
359 if (best_pst
!= NULL
)
366 static struct symtab
*
367 find_pc_sect_symtab_from_partial (struct objfile
*objfile
,
368 struct minimal_symbol
*msymbol
,
369 CORE_ADDR pc
, struct obj_section
*section
,
372 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
376 if (warn_if_readin
&& ps
->readin
)
377 /* Might want to error() here (in case symtab is corrupt and
378 will cause a core dump), but maybe we can successfully
379 continue, so let's not. */
381 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
382 paddress (get_objfile_arch (objfile
), pc
));
383 psymtab_to_symtab (objfile
, ps
);
389 /* Find which partial symbol within a psymtab matches PC and SECTION.
392 static struct partial_symbol
*
393 find_pc_sect_psymbol (struct objfile
*objfile
,
394 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
395 struct obj_section
*section
)
397 struct partial_symbol
*best
= NULL
, *p
, **pp
;
400 gdb_assert (psymtab
!= NULL
);
402 /* Cope with programs that start at address 0. */
403 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
405 /* Search the global symbols as well as the static symbols, so that
406 find_pc_partial_function doesn't use a minimal symbol and thus
407 cache a bad endaddr. */
408 for (pp
= objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
409 (pp
- (objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
410 < psymtab
->n_global_syms
);
414 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
415 && SYMBOL_CLASS (p
) == LOC_BLOCK
416 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
417 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
418 || (psymtab
->textlow
== 0
419 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
421 if (section
) /* Match on a specific section. */
423 fixup_psymbol_section (p
, objfile
);
424 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p
), section
))
427 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
432 for (pp
= objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
433 (pp
- (objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
434 < psymtab
->n_static_syms
);
438 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
439 && SYMBOL_CLASS (p
) == LOC_BLOCK
440 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
441 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
442 || (psymtab
->textlow
== 0
443 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
445 if (section
) /* Match on a specific section. */
447 fixup_psymbol_section (p
, objfile
);
448 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p
), section
))
451 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
460 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
464 if (psym
== NULL
|| SYMBOL_OBJ_SECTION (psym
) != NULL
)
467 gdb_assert (objfile
);
469 switch (SYMBOL_CLASS (psym
))
474 addr
= SYMBOL_VALUE_ADDRESS (psym
);
477 /* Nothing else will be listed in the minsyms -- no use looking
482 fixup_section (&psym
->ginfo
, addr
, objfile
);
485 static struct symtab
*
486 lookup_symbol_aux_psymtabs (struct objfile
*objfile
,
487 int block_index
, const char *name
,
488 const domain_enum domain
)
490 struct partial_symtab
*ps
;
491 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
492 struct symtab
*stab_best
= NULL
;
494 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
496 if (!ps
->readin
&& lookup_partial_symbol (objfile
, ps
, name
,
497 psymtab_index
, domain
))
499 struct symbol
*sym
= NULL
;
500 struct symtab
*stab
= psymtab_to_symtab (objfile
, ps
);
502 /* Some caution must be observed with overloaded functions
503 and methods, since the psymtab will not contain any overload
504 information (but NAME might contain it). */
507 struct blockvector
*bv
= BLOCKVECTOR (stab
);
508 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
510 sym
= lookup_block_symbol (block
, name
, domain
);
513 if (sym
&& strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
515 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
521 /* Keep looking through other psymtabs. */
528 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
529 the global block of PST if GLOBAL, and otherwise the static block.
530 MATCH is the comparison operation that returns true iff MATCH (s,
531 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
532 non-null, the symbols in the block are assumed to be ordered
533 according to it (allowing binary search). It must be compatible
534 with MATCH. Returns the symbol, if found, and otherwise NULL. */
536 static struct partial_symbol
*
537 match_partial_symbol (struct objfile
*objfile
,
538 struct partial_symtab
*pst
, int global
,
539 const char *name
, domain_enum domain
,
540 symbol_compare_ftype
*match
,
541 symbol_compare_ftype
*ordered_compare
)
543 struct partial_symbol
**start
, **psym
;
544 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
545 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
546 int do_linear_search
= 1;
551 objfile
->global_psymbols
.list
+ pst
->globals_offset
:
552 objfile
->static_psymbols
.list
+ pst
->statics_offset
);
554 if (global
&& ordered_compare
) /* Can use a binary search. */
556 do_linear_search
= 0;
558 /* Binary search. This search is guaranteed to end with center
559 pointing at the earliest partial symbol whose name might be
560 correct. At that point *all* partial symbols with an
561 appropriate name will be checked against the correct
565 top
= start
+ length
- 1;
569 center
= bottom
+ (top
- bottom
) / 2;
570 gdb_assert (center
< top
);
571 if (!do_linear_search
572 && (SYMBOL_LANGUAGE (*center
) == language_java
))
573 do_linear_search
= 1;
574 if (ordered_compare (SYMBOL_SEARCH_NAME (*center
), name
) >= 0)
579 gdb_assert (top
== bottom
);
581 while (top
<= real_top
582 && match (SYMBOL_SEARCH_NAME (*top
), name
) == 0)
584 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
585 SYMBOL_DOMAIN (*top
), domain
))
591 /* Can't use a binary search or else we found during the binary search that
592 we should also do a linear search. */
594 if (do_linear_search
)
596 for (psym
= start
; psym
< start
+ length
; psym
++)
598 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
599 SYMBOL_DOMAIN (*psym
), domain
)
600 && match (SYMBOL_SEARCH_NAME (*psym
), name
) == 0)
608 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
609 not contain any method/function instance information (since this would
610 force reading type information while reading psymtabs). Therefore,
611 if NAME contains overload information, it must be stripped before searching
614 The caller is responsible for freeing the return result. */
617 psymtab_search_name (const char *name
)
619 switch (current_language
->la_language
)
624 if (strchr (name
, '('))
626 char *ret
= cp_remove_params (name
);
638 return xstrdup (name
);
641 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
642 Check the global symbols if GLOBAL, the static symbols if not. */
644 static struct partial_symbol
*
645 lookup_partial_symbol (struct objfile
*objfile
,
646 struct partial_symtab
*pst
, const char *name
,
647 int global
, domain_enum domain
)
649 struct partial_symbol
**start
, **psym
;
650 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
651 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
652 int do_linear_search
= 1;
654 struct cleanup
*cleanup
;
661 search_name
= psymtab_search_name (name
);
662 cleanup
= make_cleanup (xfree
, search_name
);
664 objfile
->global_psymbols
.list
+ pst
->globals_offset
:
665 objfile
->static_psymbols
.list
+ pst
->statics_offset
);
667 if (global
) /* This means we can use a binary search. */
669 do_linear_search
= 0;
671 /* Binary search. This search is guaranteed to end with center
672 pointing at the earliest partial symbol whose name might be
673 correct. At that point *all* partial symbols with an
674 appropriate name will be checked against the correct
678 top
= start
+ length
- 1;
682 center
= bottom
+ (top
- bottom
) / 2;
684 internal_error (__FILE__
, __LINE__
,
685 _("failed internal consistency check"));
686 if (!do_linear_search
687 && SYMBOL_LANGUAGE (*center
) == language_java
)
689 do_linear_search
= 1;
691 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center
),
701 if (!(top
== bottom
))
702 internal_error (__FILE__
, __LINE__
,
703 _("failed internal consistency check"));
705 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
706 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
707 while (top
>= start
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, search_name
))
710 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
713 while (top
<= real_top
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, search_name
))
715 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
716 SYMBOL_DOMAIN (*top
), domain
))
718 do_cleanups (cleanup
);
725 /* Can't use a binary search or else we found during the binary search that
726 we should also do a linear search. */
728 if (do_linear_search
)
730 for (psym
= start
; psym
< start
+ length
; psym
++)
732 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
733 SYMBOL_DOMAIN (*psym
), domain
)
734 && SYMBOL_MATCHES_SEARCH_NAME (*psym
, search_name
))
736 do_cleanups (cleanup
);
742 do_cleanups (cleanup
);
746 /* Get the symbol table that corresponds to a partial_symtab.
747 This is fast after the first time you do it. */
749 static struct symtab
*
750 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
752 /* If it is a shared psymtab, find an unshared psymtab that includes
753 it. Any such psymtab will do. */
754 while (pst
->user
!= NULL
)
757 /* If it's been looked up before, return it. */
761 /* If it has not yet been read in, read it. */
764 struct cleanup
*back_to
= increment_reading_symtab ();
766 (*pst
->read_symtab
) (pst
, objfile
);
767 do_cleanups (back_to
);
774 relocate_psymtabs (struct objfile
*objfile
,
775 struct section_offsets
*new_offsets
,
776 struct section_offsets
*delta
)
778 struct partial_symbol
**psym
;
779 struct partial_symtab
*p
;
781 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
783 p
->textlow
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
784 p
->texthigh
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
787 for (psym
= objfile
->global_psymbols
.list
;
788 psym
< objfile
->global_psymbols
.next
;
791 fixup_psymbol_section (*psym
, objfile
);
792 if (SYMBOL_SECTION (*psym
) >= 0)
793 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
794 SYMBOL_SECTION (*psym
));
796 for (psym
= objfile
->static_psymbols
.list
;
797 psym
< objfile
->static_psymbols
.next
;
800 fixup_psymbol_section (*psym
, objfile
);
801 if (SYMBOL_SECTION (*psym
) >= 0)
802 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
803 SYMBOL_SECTION (*psym
));
807 static struct symtab
*
808 find_last_source_symtab_from_partial (struct objfile
*ofp
)
810 struct partial_symtab
*ps
;
811 struct partial_symtab
*cs_pst
= 0;
813 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp
, ps
)
815 const char *name
= ps
->filename
;
816 int len
= strlen (name
);
818 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
819 || strcmp (name
, "<<C++-namespaces>>") == 0)))
827 internal_error (__FILE__
, __LINE__
,
828 _("select_source_symtab: "
829 "readin pst found and no symtabs."));
832 return psymtab_to_symtab (ofp
, cs_pst
);
838 forget_cached_source_info_partial (struct objfile
*objfile
)
840 struct partial_symtab
*pst
;
842 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
844 if (pst
->fullname
!= NULL
)
846 xfree (pst
->fullname
);
847 pst
->fullname
= NULL
;
853 print_partial_symbols (struct gdbarch
*gdbarch
,
854 struct partial_symbol
**p
, int count
, char *what
,
855 struct ui_file
*outfile
)
857 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
861 fprintf_filtered (outfile
, " `%s'", SYMBOL_LINKAGE_NAME (*p
));
862 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
864 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
866 fputs_filtered (", ", outfile
);
867 switch (SYMBOL_DOMAIN (*p
))
870 fputs_filtered ("undefined domain, ", outfile
);
873 /* This is the usual thing -- don't print it. */
876 fputs_filtered ("struct domain, ", outfile
);
879 fputs_filtered ("label domain, ", outfile
);
882 fputs_filtered ("<invalid domain>, ", outfile
);
885 switch (SYMBOL_CLASS (*p
))
888 fputs_filtered ("undefined", outfile
);
891 fputs_filtered ("constant int", outfile
);
894 fputs_filtered ("static", outfile
);
897 fputs_filtered ("register", outfile
);
900 fputs_filtered ("pass by value", outfile
);
903 fputs_filtered ("pass by reference", outfile
);
905 case LOC_REGPARM_ADDR
:
906 fputs_filtered ("register address parameter", outfile
);
909 fputs_filtered ("stack parameter", outfile
);
912 fputs_filtered ("type", outfile
);
915 fputs_filtered ("label", outfile
);
918 fputs_filtered ("function", outfile
);
920 case LOC_CONST_BYTES
:
921 fputs_filtered ("constant bytes", outfile
);
924 fputs_filtered ("unresolved", outfile
);
926 case LOC_OPTIMIZED_OUT
:
927 fputs_filtered ("optimized out", outfile
);
930 fputs_filtered ("computed at runtime", outfile
);
933 fputs_filtered ("<invalid location>", outfile
);
936 fputs_filtered (", ", outfile
);
937 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (*p
)), outfile
);
938 fprintf_filtered (outfile
, "\n");
944 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
945 struct ui_file
*outfile
)
947 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
950 if (psymtab
->anonymous
)
952 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
957 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
960 fprintf_filtered (outfile
, "(object ");
961 gdb_print_host_address (psymtab
, outfile
);
962 fprintf_filtered (outfile
, ")\n\n");
963 fprintf_unfiltered (outfile
, " Read from object file %s (",
965 gdb_print_host_address (objfile
, outfile
);
966 fprintf_unfiltered (outfile
, ")\n");
970 fprintf_filtered (outfile
,
971 " Full symtab was read (at ");
972 gdb_print_host_address (psymtab
->symtab
, outfile
);
973 fprintf_filtered (outfile
, " by function at ");
974 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
975 fprintf_filtered (outfile
, ")\n");
978 fprintf_filtered (outfile
, " Relocate symbols by ");
979 for (i
= 0; i
< objfile
->num_sections
; ++i
)
982 fprintf_filtered (outfile
, ", ");
984 fputs_filtered (paddress (gdbarch
,
985 ANOFFSET (psymtab
->section_offsets
, i
)),
988 fprintf_filtered (outfile
, "\n");
990 fprintf_filtered (outfile
, " Symbols cover text addresses ");
991 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
), outfile
);
992 fprintf_filtered (outfile
, "-");
993 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
), outfile
);
994 fprintf_filtered (outfile
, "\n");
995 fprintf_filtered (outfile
, " Address map supported - %s.\n",
996 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
997 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
998 psymtab
->number_of_dependencies
);
999 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1001 fprintf_filtered (outfile
, " %d ", i
);
1002 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
1003 fprintf_filtered (outfile
, " %s\n",
1004 psymtab
->dependencies
[i
]->filename
);
1006 if (psymtab
->user
!= NULL
)
1008 fprintf_filtered (outfile
, " Shared partial symtab with user ");
1009 gdb_print_host_address (psymtab
->user
, outfile
);
1010 fprintf_filtered (outfile
, "\n");
1012 if (psymtab
->n_global_syms
> 0)
1014 print_partial_symbols (gdbarch
,
1015 objfile
->global_psymbols
.list
1016 + psymtab
->globals_offset
,
1017 psymtab
->n_global_syms
, "Global", outfile
);
1019 if (psymtab
->n_static_syms
> 0)
1021 print_partial_symbols (gdbarch
,
1022 objfile
->static_psymbols
.list
1023 + psymtab
->statics_offset
,
1024 psymtab
->n_static_syms
, "Static", outfile
);
1026 fprintf_filtered (outfile
, "\n");
1030 print_psymtab_stats_for_objfile (struct objfile
*objfile
)
1033 struct partial_symtab
*ps
;
1036 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1038 if (ps
->readin
== 0)
1041 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
1045 dump_psymtabs_for_objfile (struct objfile
*objfile
)
1047 struct partial_symtab
*psymtab
;
1049 if (objfile
->psymtabs
)
1051 printf_filtered ("Psymtabs:\n");
1052 for (psymtab
= objfile
->psymtabs
;
1054 psymtab
= psymtab
->next
)
1056 printf_filtered ("%s at ",
1058 gdb_print_host_address (psymtab
, gdb_stdout
);
1059 printf_filtered (", ");
1062 printf_filtered ("\n\n");
1066 /* Look through the partial symtabs for all symbols which begin
1067 by matching FUNC_NAME. Make sure we read that symbol table in. */
1070 read_symtabs_for_function (struct objfile
*objfile
, const char *func_name
)
1072 struct partial_symtab
*ps
;
1074 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1079 if ((lookup_partial_symbol (objfile
, ps
, func_name
, 1, VAR_DOMAIN
)
1081 || (lookup_partial_symbol (objfile
, ps
, func_name
, 0, VAR_DOMAIN
)
1083 psymtab_to_symtab (objfile
, ps
);
1088 expand_partial_symbol_tables (struct objfile
*objfile
)
1090 struct partial_symtab
*psymtab
;
1092 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1094 psymtab_to_symtab (objfile
, psymtab
);
1099 read_psymtabs_with_fullname (struct objfile
*objfile
, const char *fullname
)
1101 struct partial_symtab
*p
;
1103 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
1105 /* Anonymous psymtabs don't have a name of a source file. */
1109 if (filename_cmp (fullname
, p
->filename
) == 0)
1110 psymtab_to_symtab (objfile
, p
);
1115 map_symbol_filenames_psymtab (struct objfile
*objfile
,
1116 symbol_filename_ftype
*fun
, void *data
,
1119 struct partial_symtab
*ps
;
1121 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1123 const char *fullname
;
1128 /* We can skip shared psymtabs here, because any file name will be
1129 attached to the unshared psymtab. */
1130 if (ps
->user
!= NULL
)
1133 /* Anonymous psymtabs don't have a file name. */
1139 fullname
= psymtab_to_fullname (ps
);
1142 (*fun
) (ps
->filename
, fullname
, data
);
1146 /* Finds the fullname that a partial_symtab represents.
1148 If this functions finds the fullname, it will save it in ps->fullname
1149 and it will also return the value.
1151 If this function fails to find the file that this partial_symtab represents,
1152 NULL will be returned and ps->fullname will be set to NULL. */
1155 psymtab_to_fullname (struct partial_symtab
*ps
)
1164 /* Use cached copy if we have it.
1165 We rely on forget_cached_source_info being called appropriately
1166 to handle cases like the file being moved. */
1168 return ps
->fullname
;
1170 r
= find_and_open_source (ps
->filename
, ps
->dirname
, &ps
->fullname
);
1175 return ps
->fullname
;
1182 find_symbol_file_from_partial (struct objfile
*objfile
, const char *name
)
1184 struct partial_symtab
*pst
;
1186 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
1188 if (lookup_partial_symbol (objfile
, pst
, name
, 1, VAR_DOMAIN
))
1189 return pst
->filename
;
1194 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1195 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1196 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1197 ever returns non-zero, and otherwise returns 0. */
1200 map_block (const char *name
, domain_enum
namespace, struct objfile
*objfile
,
1201 struct block
*block
,
1202 int (*callback
) (struct block
*, struct symbol
*, void *),
1203 void *data
, symbol_compare_ftype
*match
)
1205 struct block_iterator iter
;
1208 for (sym
= block_iter_match_first (block
, name
, match
, &iter
);
1209 sym
!= NULL
; sym
= block_iter_match_next (name
, match
, &iter
))
1211 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym
),
1212 SYMBOL_DOMAIN (sym
), namespace))
1214 if (callback (block
, sym
, data
))
1222 /* Psymtab version of map_matching_symbols. See its definition in
1223 the definition of quick_symbol_functions in symfile.h. */
1226 map_matching_symbols_psymtab (const char *name
, domain_enum
namespace,
1227 struct objfile
*objfile
, int global
,
1228 int (*callback
) (struct block
*,
1229 struct symbol
*, void *),
1231 symbol_compare_ftype
*match
,
1232 symbol_compare_ftype
*ordered_compare
)
1234 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1235 struct partial_symtab
*ps
;
1237 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1241 || match_partial_symbol (objfile
, ps
, global
, name
, namespace, match
,
1244 struct symtab
*s
= psymtab_to_symtab (objfile
, ps
);
1245 struct block
*block
;
1247 if (s
== NULL
|| !s
->primary
)
1249 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), block_kind
);
1250 if (map_block (name
, namespace, objfile
, block
,
1251 callback
, data
, match
))
1253 if (callback (block
, NULL
, data
))
1259 /* A helper for expand_symtabs_matching_via_partial that handles
1260 searching included psymtabs. This returns 1 if a symbol is found,
1261 and zero otherwise. It also updates the 'searched_flag' on the
1262 various psymtabs that it searches. */
1265 recursively_search_psymtabs (struct partial_symtab
*ps
,
1266 struct objfile
*objfile
,
1267 enum search_domain kind
,
1268 int (*name_matcher
) (const char *, void *),
1271 struct partial_symbol
**psym
;
1272 struct partial_symbol
**bound
, **gbound
, **sbound
;
1274 int result
= PST_SEARCHED_AND_NOT_FOUND
;
1277 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1278 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1280 /* Recurse into shared psymtabs first, because they may have already
1281 been searched, and this could save some time. */
1282 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1286 /* Skip non-shared dependencies, these are handled elsewhere. */
1287 if (ps
->dependencies
[i
]->user
== NULL
)
1290 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1291 objfile
, kind
, name_matcher
, data
);
1294 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1299 gbound
= (objfile
->global_psymbols
.list
1300 + ps
->globals_offset
+ ps
->n_global_syms
);
1301 sbound
= (objfile
->static_psymbols
.list
1302 + ps
->statics_offset
+ ps
->n_static_syms
);
1305 /* Go through all of the symbols stored in a partial
1306 symtab in one loop. */
1307 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1312 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
1314 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1325 if ((kind
== ALL_DOMAIN
1326 || (kind
== VARIABLES_DOMAIN
1327 && SYMBOL_CLASS (*psym
) != LOC_TYPEDEF
1328 && SYMBOL_CLASS (*psym
) != LOC_BLOCK
)
1329 || (kind
== FUNCTIONS_DOMAIN
1330 && SYMBOL_CLASS (*psym
) == LOC_BLOCK
)
1331 || (kind
== TYPES_DOMAIN
1332 && SYMBOL_CLASS (*psym
) == LOC_TYPEDEF
))
1333 && (*name_matcher
) (SYMBOL_SEARCH_NAME (*psym
), data
))
1335 /* Found a match, so notify our caller. */
1336 result
= PST_SEARCHED_AND_FOUND
;
1343 ps
->searched_flag
= result
;
1344 return result
== PST_SEARCHED_AND_FOUND
;
1348 expand_symtabs_matching_via_partial
1349 (struct objfile
*objfile
,
1350 int (*file_matcher
) (const char *, void *),
1351 int (*name_matcher
) (const char *, void *),
1352 enum search_domain kind
,
1355 struct partial_symtab
*ps
;
1357 /* Clear the search flags. */
1358 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1360 ps
->searched_flag
= PST_NOT_SEARCHED
;
1363 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1368 /* We skip shared psymtabs because file-matching doesn't apply
1369 to them; but we search them later in the loop. */
1370 if (ps
->user
!= NULL
)
1377 if (! (*file_matcher
) (ps
->filename
, data
))
1381 if (recursively_search_psymtabs (ps
, objfile
, kind
, name_matcher
, data
))
1382 psymtab_to_symtab (objfile
, ps
);
1387 objfile_has_psyms (struct objfile
*objfile
)
1389 return objfile
->psymtabs
!= NULL
;
1392 const struct quick_symbol_functions psym_functions
=
1395 find_last_source_symtab_from_partial
,
1396 forget_cached_source_info_partial
,
1397 partial_map_symtabs_matching_filename
,
1398 lookup_symbol_aux_psymtabs
,
1399 print_psymtab_stats_for_objfile
,
1400 dump_psymtabs_for_objfile
,
1402 read_symtabs_for_function
,
1403 expand_partial_symbol_tables
,
1404 read_psymtabs_with_fullname
,
1405 find_symbol_file_from_partial
,
1406 map_matching_symbols_psymtab
,
1407 expand_symtabs_matching_via_partial
,
1408 find_pc_sect_symtab_from_partial
,
1409 map_symbol_filenames_psymtab
1414 /* This compares two partial symbols by names, using strcmp_iw_ordered
1415 for the comparison. */
1418 compare_psymbols (const void *s1p
, const void *s2p
)
1420 struct partial_symbol
*const *s1
= s1p
;
1421 struct partial_symbol
*const *s2
= s2p
;
1423 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1
),
1424 SYMBOL_SEARCH_NAME (*s2
));
1428 sort_pst_symbols (struct objfile
*objfile
, struct partial_symtab
*pst
)
1430 /* Sort the global list; don't sort the static list. */
1432 qsort (objfile
->global_psymbols
.list
+ pst
->globals_offset
,
1433 pst
->n_global_syms
, sizeof (struct partial_symbol
*),
1437 /* Allocate and partially fill a partial symtab. It will be
1438 completely filled at the end of the symbol list.
1440 FILENAME is the name of the symbol-file we are reading from. */
1442 struct partial_symtab
*
1443 start_psymtab_common (struct objfile
*objfile
,
1444 struct section_offsets
*section_offsets
,
1445 const char *filename
,
1446 CORE_ADDR textlow
, struct partial_symbol
**global_syms
,
1447 struct partial_symbol
**static_syms
)
1449 struct partial_symtab
*psymtab
;
1451 psymtab
= allocate_psymtab (filename
, objfile
);
1452 psymtab
->section_offsets
= section_offsets
;
1453 psymtab
->textlow
= textlow
;
1454 psymtab
->texthigh
= psymtab
->textlow
; /* default */
1455 psymtab
->globals_offset
= global_syms
- objfile
->global_psymbols
.list
;
1456 psymtab
->statics_offset
= static_syms
- objfile
->static_psymbols
.list
;
1460 /* Calculate a hash code for the given partial symbol. The hash is
1461 calculated using the symbol's value, language, domain, class
1462 and name. These are the values which are set by
1463 add_psymbol_to_bcache. */
1465 static unsigned long
1466 psymbol_hash (const void *addr
, int length
)
1468 unsigned long h
= 0;
1469 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1470 unsigned int lang
= psymbol
->ginfo
.language
;
1471 unsigned int domain
= PSYMBOL_DOMAIN (psymbol
);
1472 unsigned int class = PSYMBOL_CLASS (psymbol
);
1474 h
= hash_continue (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1475 h
= hash_continue (&lang
, sizeof (unsigned int), h
);
1476 h
= hash_continue (&domain
, sizeof (unsigned int), h
);
1477 h
= hash_continue (&class, sizeof (unsigned int), h
);
1478 h
= hash_continue (psymbol
->ginfo
.name
, strlen (psymbol
->ginfo
.name
), h
);
1483 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1484 For the comparison this function uses a symbols value,
1485 language, domain, class and name. */
1488 psymbol_compare (const void *addr1
, const void *addr2
, int length
)
1490 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1491 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1493 return (memcmp (&sym1
->ginfo
.value
, &sym1
->ginfo
.value
,
1494 sizeof (sym1
->ginfo
.value
)) == 0
1495 && sym1
->ginfo
.language
== sym2
->ginfo
.language
1496 && PSYMBOL_DOMAIN (sym1
) == PSYMBOL_DOMAIN (sym2
)
1497 && PSYMBOL_CLASS (sym1
) == PSYMBOL_CLASS (sym2
)
1498 && sym1
->ginfo
.name
== sym2
->ginfo
.name
);
1501 /* Initialize a partial symbol bcache. */
1503 struct psymbol_bcache
*
1504 psymbol_bcache_init (void)
1506 struct psymbol_bcache
*bcache
= XCALLOC (1, struct psymbol_bcache
);
1507 bcache
->bcache
= bcache_xmalloc (psymbol_hash
, psymbol_compare
);
1511 /* Free a partial symbol bcache. */
1513 psymbol_bcache_free (struct psymbol_bcache
*bcache
)
1518 bcache_xfree (bcache
->bcache
);
1522 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1525 psymbol_bcache_get_bcache (struct psymbol_bcache
*bcache
)
1527 return bcache
->bcache
;
1530 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1531 symbol before, add a copy to BCACHE. In either case, return a pointer
1532 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1533 1 in case of new entry or 0 if returning an old entry. */
1535 static const struct partial_symbol
*
1536 psymbol_bcache_full (struct partial_symbol
*sym
,
1537 struct psymbol_bcache
*bcache
,
1540 return bcache_full (sym
,
1541 sizeof (struct partial_symbol
),
1546 /* Helper function, initialises partial symbol structure and stashes
1547 it into objfile's bcache. Note that our caching mechanism will
1548 use all fields of struct partial_symbol to determine hash value of the
1549 structure. In other words, having two symbols with the same name but
1550 different domain (or address) is possible and correct. */
1552 static const struct partial_symbol
*
1553 add_psymbol_to_bcache (const char *name
, int namelength
, int copy_name
,
1555 enum address_class
class,
1556 long val
, /* Value as a long */
1557 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1558 enum language language
, struct objfile
*objfile
,
1561 struct partial_symbol psymbol
;
1563 /* We must ensure that the entire 'value' field has been zeroed
1564 before assigning to it, because an assignment may not write the
1566 memset (&psymbol
.ginfo
.value
, 0, sizeof (psymbol
.ginfo
.value
));
1568 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1571 SYMBOL_VALUE (&psymbol
) = val
;
1575 SYMBOL_VALUE_ADDRESS (&psymbol
) = coreaddr
;
1577 SYMBOL_SECTION (&psymbol
) = 0;
1578 SYMBOL_OBJ_SECTION (&psymbol
) = NULL
;
1579 SYMBOL_SET_LANGUAGE (&psymbol
, language
);
1580 PSYMBOL_DOMAIN (&psymbol
) = domain
;
1581 PSYMBOL_CLASS (&psymbol
) = class;
1583 SYMBOL_SET_NAMES (&psymbol
, name
, namelength
, copy_name
, objfile
);
1585 /* Stash the partial symbol away in the cache. */
1586 return psymbol_bcache_full (&psymbol
,
1587 objfile
->psymbol_cache
,
1591 /* Increase the space allocated for LISTP, which is probably
1592 global_psymbols or static_psymbols. This space will eventually
1593 be freed in free_objfile(). */
1596 extend_psymbol_list (struct psymbol_allocation_list
*listp
,
1597 struct objfile
*objfile
)
1601 if (listp
->size
== 0)
1604 listp
->list
= (struct partial_symbol
**)
1605 xmalloc (new_size
* sizeof (struct partial_symbol
*));
1609 new_size
= listp
->size
* 2;
1610 listp
->list
= (struct partial_symbol
**)
1611 xrealloc ((char *) listp
->list
,
1612 new_size
* sizeof (struct partial_symbol
*));
1614 /* Next assumes we only went one over. Should be good if
1615 program works correctly. */
1616 listp
->next
= listp
->list
+ listp
->size
;
1617 listp
->size
= new_size
;
1620 /* Helper function, adds partial symbol to the given partial symbol
1624 append_psymbol_to_list (struct psymbol_allocation_list
*list
,
1625 const struct partial_symbol
*psym
,
1626 struct objfile
*objfile
)
1628 if (list
->next
>= list
->list
+ list
->size
)
1629 extend_psymbol_list (list
, objfile
);
1630 *list
->next
++ = (struct partial_symbol
*) psym
;
1631 OBJSTAT (objfile
, n_psyms
++);
1634 /* Add a symbol with a long value to a psymtab.
1635 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1636 Return the partial symbol that has been added. */
1639 add_psymbol_to_list (const char *name
, int namelength
, int copy_name
,
1641 enum address_class
class,
1642 struct psymbol_allocation_list
*list
,
1643 long val
, /* Value as a long */
1644 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1645 enum language language
, struct objfile
*objfile
)
1647 const struct partial_symbol
*psym
;
1651 /* Stash the partial symbol away in the cache. */
1652 psym
= add_psymbol_to_bcache (name
, namelength
, copy_name
, domain
, class,
1653 val
, coreaddr
, language
, objfile
, &added
);
1655 /* Do not duplicate global partial symbols. */
1656 if (list
== &objfile
->global_psymbols
1660 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1661 append_psymbol_to_list (list
, psym
, objfile
);
1664 /* Initialize storage for partial symbols. */
1667 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1669 /* Free any previously allocated psymbol lists. */
1671 if (objfile
->global_psymbols
.list
)
1673 xfree (objfile
->global_psymbols
.list
);
1675 if (objfile
->static_psymbols
.list
)
1677 xfree (objfile
->static_psymbols
.list
);
1680 /* Current best guess is that approximately a twentieth
1681 of the total symbols (in a debugging file) are global or static
1682 oriented symbols, then multiply that by slop factor of two. */
1684 objfile
->global_psymbols
.size
= total_symbols
/ 10;
1685 objfile
->static_psymbols
.size
= total_symbols
/ 10;
1687 if (objfile
->global_psymbols
.size
> 0)
1689 objfile
->global_psymbols
.next
=
1690 objfile
->global_psymbols
.list
= (struct partial_symbol
**)
1691 xmalloc ((objfile
->global_psymbols
.size
1692 * sizeof (struct partial_symbol
*)));
1694 if (objfile
->static_psymbols
.size
> 0)
1696 objfile
->static_psymbols
.next
=
1697 objfile
->static_psymbols
.list
= (struct partial_symbol
**)
1698 xmalloc ((objfile
->static_psymbols
.size
1699 * sizeof (struct partial_symbol
*)));
1703 struct partial_symtab
*
1704 allocate_psymtab (const char *filename
, struct objfile
*objfile
)
1706 struct partial_symtab
*psymtab
;
1708 if (objfile
->free_psymtabs
)
1710 psymtab
= objfile
->free_psymtabs
;
1711 objfile
->free_psymtabs
= psymtab
->next
;
1714 psymtab
= (struct partial_symtab
*)
1715 obstack_alloc (&objfile
->objfile_obstack
,
1716 sizeof (struct partial_symtab
));
1718 memset (psymtab
, 0, sizeof (struct partial_symtab
));
1719 psymtab
->filename
= obstack_copy0 (&objfile
->objfile_obstack
,
1720 filename
, strlen (filename
));
1721 psymtab
->symtab
= NULL
;
1723 /* Prepend it to the psymtab list for the objfile it belongs to.
1724 Psymtabs are searched in most recent inserted -> least recent
1727 psymtab
->next
= objfile
->psymtabs
;
1728 objfile
->psymtabs
= psymtab
;
1730 if (symtab_create_debug
)
1732 /* Be a bit clever with debugging messages, and don't print objfile
1733 every time, only when it changes. */
1734 static char *last_objfile_name
= NULL
;
1736 if (last_objfile_name
== NULL
1737 || strcmp (last_objfile_name
, objfile
->name
) != 0)
1739 xfree (last_objfile_name
);
1740 last_objfile_name
= xstrdup (objfile
->name
);
1741 fprintf_unfiltered (gdb_stdlog
,
1742 "Creating one or more psymtabs for objfile %s ...\n",
1745 fprintf_unfiltered (gdb_stdlog
,
1746 "Created psymtab %s for module %s.\n",
1747 host_address_to_string (psymtab
), filename
);
1754 discard_psymtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
1756 struct partial_symtab
**prev_pst
;
1759 Empty psymtabs happen as a result of header files which don't
1760 have any symbols in them. There can be a lot of them. But this
1761 check is wrong, in that a psymtab with N_SLINE entries but
1762 nothing else is not empty, but we don't realize that. Fixing
1763 that without slowing things down might be tricky. */
1765 /* First, snip it out of the psymtab chain. */
1767 prev_pst
= &(objfile
->psymtabs
);
1768 while ((*prev_pst
) != pst
)
1769 prev_pst
= &((*prev_pst
)->next
);
1770 (*prev_pst
) = pst
->next
;
1772 /* Next, put it on a free list for recycling. */
1774 pst
->next
= objfile
->free_psymtabs
;
1775 objfile
->free_psymtabs
= pst
;
1778 /* An object of this type is passed to discard_psymtabs_upto. */
1780 struct psymtab_state
1782 /* The objfile where psymtabs are discarded. */
1784 struct objfile
*objfile
;
1786 /* The first psymtab to save. */
1788 struct partial_symtab
*save
;
1791 /* A cleanup function used by make_cleanup_discard_psymtabs. */
1794 discard_psymtabs_upto (void *arg
)
1796 struct psymtab_state
*state
= arg
;
1798 while (state
->objfile
->psymtabs
!= state
->save
)
1799 discard_psymtab (state
->objfile
, state
->objfile
->psymtabs
);
1802 /* Return a new cleanup that discards all psymtabs created in OBJFILE
1803 after this function is called. */
1806 make_cleanup_discard_psymtabs (struct objfile
*objfile
)
1808 struct psymtab_state
*state
= XNEW (struct psymtab_state
);
1810 state
->objfile
= objfile
;
1811 state
->save
= objfile
->psymtabs
;
1813 return make_cleanup_dtor (discard_psymtabs_upto
, state
, xfree
);
1819 maintenance_print_psymbols (char *args
, int from_tty
)
1822 struct ui_file
*outfile
;
1823 struct cleanup
*cleanups
;
1824 char *symname
= NULL
;
1825 char *filename
= DEV_TTY
;
1826 struct objfile
*objfile
;
1827 struct partial_symtab
*ps
;
1834 print-psymbols takes an output file name and optional symbol file name"));
1836 argv
= gdb_buildargv (args
);
1837 cleanups
= make_cleanup_freeargv (argv
);
1839 if (argv
[0] != NULL
)
1842 /* If a second arg is supplied, it is a source file name to match on. */
1843 if (argv
[1] != NULL
)
1849 filename
= tilde_expand (filename
);
1850 make_cleanup (xfree
, filename
);
1852 outfile
= gdb_fopen (filename
, FOPEN_WT
);
1854 perror_with_name (filename
);
1855 make_cleanup_ui_file_delete (outfile
);
1857 ALL_PSYMTABS (objfile
, ps
)
1860 if (symname
== NULL
|| filename_cmp (symname
, ps
->filename
) == 0)
1861 dump_psymtab (objfile
, ps
, outfile
);
1863 do_cleanups (cleanups
);
1866 /* List all the partial symbol tables whose names match REGEXP (optional). */
1868 maintenance_info_psymtabs (char *regexp
, int from_tty
)
1870 struct program_space
*pspace
;
1871 struct objfile
*objfile
;
1876 ALL_PSPACES (pspace
)
1877 ALL_PSPACE_OBJFILES (pspace
, objfile
)
1879 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1880 struct partial_symtab
*psymtab
;
1882 /* We don't want to print anything for this objfile until we
1883 actually find a symtab whose name matches. */
1884 int printed_objfile_start
= 0;
1886 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1891 || re_exec (psymtab
->filename
))
1893 if (! printed_objfile_start
)
1895 printf_filtered ("{ objfile %s ", objfile
->name
);
1897 printf_filtered ("((struct objfile *) %s)\n",
1898 host_address_to_string (objfile
));
1899 printed_objfile_start
= 1;
1902 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1904 printf_filtered ("((struct partial_symtab *) %s)\n",
1905 host_address_to_string (psymtab
));
1907 printf_filtered (" readin %s\n",
1908 psymtab
->readin
? "yes" : "no");
1909 printf_filtered (" fullname %s\n",
1911 ? psymtab
->fullname
: "(null)");
1912 printf_filtered (" text addresses ");
1913 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
),
1915 printf_filtered (" -- ");
1916 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
),
1918 printf_filtered ("\n");
1919 printf_filtered (" psymtabs_addrmap_supported %s\n",
1920 (psymtab
->psymtabs_addrmap_supported
1922 printf_filtered (" globals ");
1923 if (psymtab
->n_global_syms
)
1925 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1926 host_address_to_string (objfile
->global_psymbols
.list
1927 + psymtab
->globals_offset
),
1928 psymtab
->n_global_syms
);
1931 printf_filtered ("(none)\n");
1932 printf_filtered (" statics ");
1933 if (psymtab
->n_static_syms
)
1935 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1936 host_address_to_string (objfile
->static_psymbols
.list
1937 + psymtab
->statics_offset
),
1938 psymtab
->n_static_syms
);
1941 printf_filtered ("(none)\n");
1942 printf_filtered (" dependencies ");
1943 if (psymtab
->number_of_dependencies
)
1947 printf_filtered ("{\n");
1948 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1950 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1952 /* Note the string concatenation there --- no comma. */
1953 printf_filtered (" psymtab %s "
1954 "((struct partial_symtab *) %s)\n",
1956 host_address_to_string (dep
));
1958 printf_filtered (" }\n");
1961 printf_filtered ("(none)\n");
1962 printf_filtered (" }\n");
1966 if (printed_objfile_start
)
1967 printf_filtered ("}\n");
1971 /* Check consistency of psymtabs and symtabs. */
1974 maintenance_check_symtabs (char *ignore
, int from_tty
)
1977 struct partial_symbol
**psym
;
1978 struct symtab
*s
= NULL
;
1979 struct partial_symtab
*ps
;
1980 struct blockvector
*bv
;
1981 struct objfile
*objfile
;
1985 ALL_PSYMTABS (objfile
, ps
)
1987 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1989 s
= psymtab_to_symtab (objfile
, ps
);
1992 bv
= BLOCKVECTOR (s
);
1993 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1994 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1995 length
= ps
->n_static_syms
;
1998 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
1999 SYMBOL_DOMAIN (*psym
));
2002 printf_filtered ("Static symbol `");
2003 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
2004 printf_filtered ("' only found in ");
2005 puts_filtered (ps
->filename
);
2006 printf_filtered (" psymtab\n");
2010 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2011 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2012 length
= ps
->n_global_syms
;
2015 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
2016 SYMBOL_DOMAIN (*psym
));
2019 printf_filtered ("Global symbol `");
2020 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
2021 printf_filtered ("' only found in ");
2022 puts_filtered (ps
->filename
);
2023 printf_filtered (" psymtab\n");
2027 if (ps
->texthigh
< ps
->textlow
)
2029 printf_filtered ("Psymtab ");
2030 puts_filtered (ps
->filename
);
2031 printf_filtered (" covers bad range ");
2032 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
2033 printf_filtered (" - ");
2034 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
2035 printf_filtered ("\n");
2038 if (ps
->texthigh
== 0)
2040 if (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
))
2042 printf_filtered ("Psymtab ");
2043 puts_filtered (ps
->filename
);
2044 printf_filtered (" covers ");
2045 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
2046 printf_filtered (" - ");
2047 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
2048 printf_filtered (" but symtab covers only ");
2049 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2050 printf_filtered (" - ");
2051 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2052 printf_filtered ("\n");
2060 expand_partial_symbol_names (int (*fun
) (const char *, void *),
2063 struct objfile
*objfile
;
2065 ALL_OBJFILES (objfile
)
2068 objfile
->sf
->qf
->expand_symtabs_matching (objfile
, NULL
, fun
,
2074 map_partial_symbol_filenames (symbol_filename_ftype
*fun
, void *data
,
2077 struct objfile
*objfile
;
2079 ALL_OBJFILES (objfile
)
2082 objfile
->sf
->qf
->map_symbol_filenames (objfile
, fun
, data
,
2087 extern initialize_file_ftype _initialize_psymtab
;
2090 _initialize_psymtab (void)
2092 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2093 Print dump of current partial symbol definitions.\n\
2094 Entries in the partial symbol table are dumped to file OUTFILE.\n\
2095 If a SOURCE file is specified, dump only that file's partial symbols."),
2096 &maintenanceprintlist
);
2098 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2099 List the partial symbol tables for all object files.\n\
2100 This does not include information about individual partial symbols,\n\
2101 just the symbol table structures themselves."),
2102 &maintenanceinfolist
);
2104 add_cmd ("check-symtabs", class_maintenance
, maintenance_check_symtabs
,
2105 _("Check consistency of psymtabs and symtabs."),