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
))
189 /* Before we invoke realpath, which can get expensive when many
190 files are involved, do a quick comparison of the basenames. */
191 if (! basenames_may_differ
192 && FILENAME_CMP (name_basename
, lbasename (pst
->filename
)) != 0)
195 if (compare_filenames_for_search (psymtab_to_fullname (pst
), name
))
197 if (partial_map_expand_apply (objfile
, name
, real_path
,
198 pst
, callback
, data
))
203 /* If the user gave us an absolute path, try to find the file in
204 this symtab and use its absolute path. */
205 if (real_path
!= NULL
)
207 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
208 gdb_assert (IS_ABSOLUTE_PATH (name
));
209 if (filename_cmp (psymtab_to_fullname (pst
), real_path
) == 0)
211 if (partial_map_expand_apply (objfile
, name
, real_path
,
212 pst
, callback
, data
))
222 /* Find which partial symtab contains PC and SECTION starting at psymtab PST.
223 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
225 static struct partial_symtab
*
226 find_pc_sect_psymtab_closer (struct objfile
*objfile
,
227 CORE_ADDR pc
, struct obj_section
*section
,
228 struct partial_symtab
*pst
,
229 struct minimal_symbol
*msymbol
)
231 struct partial_symtab
*tpst
;
232 struct partial_symtab
*best_pst
= pst
;
233 CORE_ADDR best_addr
= pst
->textlow
;
235 gdb_assert (!pst
->psymtabs_addrmap_supported
);
237 /* An objfile that has its functions reordered might have
238 many partial symbol tables containing the PC, but
239 we want the partial symbol table that contains the
240 function containing the PC. */
241 if (!(objfile
->flags
& OBJF_REORDERED
) &&
242 section
== 0) /* Can't validate section this way. */
248 /* The code range of partial symtabs sometimes overlap, so, in
249 the loop below, we need to check all partial symtabs and
250 find the one that fits better for the given PC address. We
251 select the partial symtab that contains a symbol whose
252 address is closest to the PC address. By closest we mean
253 that find_pc_sect_symbol returns the symbol with address
254 that is closest and still less than the given PC. */
255 for (tpst
= pst
; tpst
!= NULL
; tpst
= tpst
->next
)
257 if (pc
>= tpst
->textlow
&& pc
< tpst
->texthigh
)
259 struct partial_symbol
*p
;
262 /* NOTE: This assumes that every psymbol has a
263 corresponding msymbol, which is not necessarily
264 true; the debug info might be much richer than the
265 object's symbol table. */
266 p
= find_pc_sect_psymbol (objfile
, tpst
, pc
, section
);
268 && SYMBOL_VALUE_ADDRESS (p
)
269 == SYMBOL_VALUE_ADDRESS (msymbol
))
272 /* Also accept the textlow value of a psymtab as a
273 "symbol", to provide some support for partial
274 symbol tables with line information but no debug
275 symbols (e.g. those produced by an assembler). */
277 this_addr
= SYMBOL_VALUE_ADDRESS (p
);
279 this_addr
= tpst
->textlow
;
281 /* Check whether it is closer than our current
282 BEST_ADDR. Since this symbol address is
283 necessarily lower or equal to PC, the symbol closer
284 to PC is the symbol which address is the highest.
285 This way we return the psymtab which contains such
286 best match symbol. This can help in cases where the
287 symbol information/debuginfo is not complete, like
288 for instance on IRIX6 with gcc, where no debug info
289 is emitted for statics. (See also the nodebug.exp
291 if (this_addr
> best_addr
)
293 best_addr
= this_addr
;
301 /* Find which partial symtab contains PC and SECTION. Return 0 if
302 none. We return the psymtab that contains a symbol whose address
303 exactly matches PC, or, if we cannot find an exact match, the
304 psymtab that contains a symbol whose address is closest to PC. */
305 static struct partial_symtab
*
306 find_pc_sect_psymtab (struct objfile
*objfile
, CORE_ADDR pc
,
307 struct obj_section
*section
,
308 struct minimal_symbol
*msymbol
)
310 struct partial_symtab
*pst
;
312 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
313 than the later used TEXTLOW/TEXTHIGH one. */
315 if (objfile
->psymtabs_addrmap
!= NULL
)
317 pst
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
320 /* FIXME: addrmaps currently do not handle overlayed sections,
321 so fall back to the non-addrmap case if we're debugging
322 overlays and the addrmap returned the wrong section. */
323 if (overlay_debugging
&& msymbol
&& section
)
325 struct partial_symbol
*p
;
327 /* NOTE: This assumes that every psymbol has a
328 corresponding msymbol, which is not necessarily
329 true; the debug info might be much richer than the
330 object's symbol table. */
331 p
= find_pc_sect_psymbol (objfile
, pst
, pc
, section
);
333 || SYMBOL_VALUE_ADDRESS (p
)
334 != SYMBOL_VALUE_ADDRESS (msymbol
))
338 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
339 PSYMTABS_ADDRMAP we used has already the best 1-byte
340 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
341 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
350 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
351 which still have no corresponding full SYMTABs read. But it is not
352 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
355 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
356 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
357 debug info type in single OBJFILE. */
359 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
360 if (!pst
->psymtabs_addrmap_supported
361 && pc
>= pst
->textlow
&& pc
< pst
->texthigh
)
363 struct partial_symtab
*best_pst
;
365 best_pst
= find_pc_sect_psymtab_closer (objfile
, pc
, section
, pst
,
367 if (best_pst
!= NULL
)
374 static struct symtab
*
375 find_pc_sect_symtab_from_partial (struct objfile
*objfile
,
376 struct minimal_symbol
*msymbol
,
377 CORE_ADDR pc
, struct obj_section
*section
,
380 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
384 if (warn_if_readin
&& ps
->readin
)
385 /* Might want to error() here (in case symtab is corrupt and
386 will cause a core dump), but maybe we can successfully
387 continue, so let's not. */
389 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
390 paddress (get_objfile_arch (objfile
), pc
));
391 psymtab_to_symtab (objfile
, ps
);
397 /* Find which partial symbol within a psymtab matches PC and SECTION.
400 static struct partial_symbol
*
401 find_pc_sect_psymbol (struct objfile
*objfile
,
402 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
403 struct obj_section
*section
)
405 struct partial_symbol
*best
= NULL
, *p
, **pp
;
408 gdb_assert (psymtab
!= NULL
);
410 /* Cope with programs that start at address 0. */
411 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
413 /* Search the global symbols as well as the static symbols, so that
414 find_pc_partial_function doesn't use a minimal symbol and thus
415 cache a bad endaddr. */
416 for (pp
= objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
417 (pp
- (objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
418 < psymtab
->n_global_syms
);
422 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
423 && PSYMBOL_CLASS (p
) == LOC_BLOCK
424 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
425 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
426 || (psymtab
->textlow
== 0
427 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
429 if (section
) /* Match on a specific section. */
431 fixup_psymbol_section (p
, objfile
);
432 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p
), section
))
435 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
440 for (pp
= objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
441 (pp
- (objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
442 < psymtab
->n_static_syms
);
446 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
447 && PSYMBOL_CLASS (p
) == LOC_BLOCK
448 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
449 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
450 || (psymtab
->textlow
== 0
451 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
453 if (section
) /* Match on a specific section. */
455 fixup_psymbol_section (p
, objfile
);
456 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p
), section
))
459 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
468 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
472 if (psym
== NULL
|| SYMBOL_OBJ_SECTION (psym
) != NULL
)
475 gdb_assert (objfile
);
477 switch (PSYMBOL_CLASS (psym
))
482 addr
= SYMBOL_VALUE_ADDRESS (psym
);
485 /* Nothing else will be listed in the minsyms -- no use looking
490 fixup_section (&psym
->ginfo
, addr
, objfile
);
493 static struct symtab
*
494 lookup_symbol_aux_psymtabs (struct objfile
*objfile
,
495 int block_index
, const char *name
,
496 const domain_enum domain
)
498 struct partial_symtab
*ps
;
499 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
500 struct symtab
*stab_best
= NULL
;
502 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
504 if (!ps
->readin
&& lookup_partial_symbol (objfile
, ps
, name
,
505 psymtab_index
, domain
))
507 struct symbol
*sym
= NULL
;
508 struct symtab
*stab
= psymtab_to_symtab (objfile
, ps
);
510 /* Some caution must be observed with overloaded functions
511 and methods, since the psymtab will not contain any overload
512 information (but NAME might contain it). */
515 struct blockvector
*bv
= BLOCKVECTOR (stab
);
516 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
518 sym
= lookup_block_symbol (block
, name
, domain
);
521 if (sym
&& strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
523 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
529 /* Keep looking through other psymtabs. */
536 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
537 the global block of PST if GLOBAL, and otherwise the static block.
538 MATCH is the comparison operation that returns true iff MATCH (s,
539 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
540 non-null, the symbols in the block are assumed to be ordered
541 according to it (allowing binary search). It must be compatible
542 with MATCH. Returns the symbol, if found, and otherwise NULL. */
544 static struct partial_symbol
*
545 match_partial_symbol (struct objfile
*objfile
,
546 struct partial_symtab
*pst
, int global
,
547 const char *name
, domain_enum domain
,
548 symbol_compare_ftype
*match
,
549 symbol_compare_ftype
*ordered_compare
)
551 struct partial_symbol
**start
, **psym
;
552 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
553 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
554 int do_linear_search
= 1;
559 objfile
->global_psymbols
.list
+ pst
->globals_offset
:
560 objfile
->static_psymbols
.list
+ pst
->statics_offset
);
562 if (global
&& ordered_compare
) /* Can use a binary search. */
564 do_linear_search
= 0;
566 /* Binary search. This search is guaranteed to end with center
567 pointing at the earliest partial symbol whose name might be
568 correct. At that point *all* partial symbols with an
569 appropriate name will be checked against the correct
573 top
= start
+ length
- 1;
577 center
= bottom
+ (top
- bottom
) / 2;
578 gdb_assert (center
< top
);
579 if (!do_linear_search
580 && (SYMBOL_LANGUAGE (*center
) == language_java
))
581 do_linear_search
= 1;
582 if (ordered_compare (SYMBOL_SEARCH_NAME (*center
), name
) >= 0)
587 gdb_assert (top
== bottom
);
589 while (top
<= real_top
590 && match (SYMBOL_SEARCH_NAME (*top
), name
) == 0)
592 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
593 SYMBOL_DOMAIN (*top
), domain
))
599 /* Can't use a binary search or else we found during the binary search that
600 we should also do a linear search. */
602 if (do_linear_search
)
604 for (psym
= start
; psym
< start
+ length
; psym
++)
606 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
607 SYMBOL_DOMAIN (*psym
), domain
)
608 && match (SYMBOL_SEARCH_NAME (*psym
), name
) == 0)
616 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
617 not contain any method/function instance information (since this would
618 force reading type information while reading psymtabs). Therefore,
619 if NAME contains overload information, it must be stripped before searching
622 The caller is responsible for freeing the return result. */
625 psymtab_search_name (const char *name
)
627 switch (current_language
->la_language
)
632 if (strchr (name
, '('))
634 char *ret
= cp_remove_params (name
);
646 return xstrdup (name
);
649 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
650 Check the global symbols if GLOBAL, the static symbols if not. */
652 static struct partial_symbol
*
653 lookup_partial_symbol (struct objfile
*objfile
,
654 struct partial_symtab
*pst
, const char *name
,
655 int global
, domain_enum domain
)
657 struct partial_symbol
**start
, **psym
;
658 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
659 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
660 int do_linear_search
= 1;
662 struct cleanup
*cleanup
;
669 search_name
= psymtab_search_name (name
);
670 cleanup
= make_cleanup (xfree
, search_name
);
672 objfile
->global_psymbols
.list
+ pst
->globals_offset
:
673 objfile
->static_psymbols
.list
+ pst
->statics_offset
);
675 if (global
) /* This means we can use a binary search. */
677 do_linear_search
= 0;
679 /* Binary search. This search is guaranteed to end with center
680 pointing at the earliest partial symbol whose name might be
681 correct. At that point *all* partial symbols with an
682 appropriate name will be checked against the correct
686 top
= start
+ length
- 1;
690 center
= bottom
+ (top
- bottom
) / 2;
692 internal_error (__FILE__
, __LINE__
,
693 _("failed internal consistency check"));
694 if (!do_linear_search
695 && SYMBOL_LANGUAGE (*center
) == language_java
)
697 do_linear_search
= 1;
699 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center
),
709 if (!(top
== bottom
))
710 internal_error (__FILE__
, __LINE__
,
711 _("failed internal consistency check"));
713 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
714 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
715 while (top
>= start
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, search_name
))
718 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
721 while (top
<= real_top
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, search_name
))
723 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
724 SYMBOL_DOMAIN (*top
), domain
))
726 do_cleanups (cleanup
);
733 /* Can't use a binary search or else we found during the binary search that
734 we should also do a linear search. */
736 if (do_linear_search
)
738 for (psym
= start
; psym
< start
+ length
; psym
++)
740 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
741 SYMBOL_DOMAIN (*psym
), domain
)
742 && SYMBOL_MATCHES_SEARCH_NAME (*psym
, search_name
))
744 do_cleanups (cleanup
);
750 do_cleanups (cleanup
);
754 /* Get the symbol table that corresponds to a partial_symtab.
755 This is fast after the first time you do it. */
757 static struct symtab
*
758 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
760 /* If it is a shared psymtab, find an unshared psymtab that includes
761 it. Any such psymtab will do. */
762 while (pst
->user
!= NULL
)
765 /* If it's been looked up before, return it. */
769 /* If it has not yet been read in, read it. */
772 struct cleanup
*back_to
= increment_reading_symtab ();
774 (*pst
->read_symtab
) (pst
, objfile
);
775 do_cleanups (back_to
);
782 relocate_psymtabs (struct objfile
*objfile
,
783 struct section_offsets
*new_offsets
,
784 struct section_offsets
*delta
)
786 struct partial_symbol
**psym
;
787 struct partial_symtab
*p
;
789 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
791 p
->textlow
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
792 p
->texthigh
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
795 for (psym
= objfile
->global_psymbols
.list
;
796 psym
< objfile
->global_psymbols
.next
;
799 fixup_psymbol_section (*psym
, objfile
);
800 if (SYMBOL_SECTION (*psym
) >= 0)
801 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
802 SYMBOL_SECTION (*psym
));
804 for (psym
= objfile
->static_psymbols
.list
;
805 psym
< objfile
->static_psymbols
.next
;
808 fixup_psymbol_section (*psym
, objfile
);
809 if (SYMBOL_SECTION (*psym
) >= 0)
810 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
811 SYMBOL_SECTION (*psym
));
815 static struct symtab
*
816 find_last_source_symtab_from_partial (struct objfile
*ofp
)
818 struct partial_symtab
*ps
;
819 struct partial_symtab
*cs_pst
= 0;
821 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp
, ps
)
823 const char *name
= ps
->filename
;
824 int len
= strlen (name
);
826 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
827 || strcmp (name
, "<<C++-namespaces>>") == 0)))
835 internal_error (__FILE__
, __LINE__
,
836 _("select_source_symtab: "
837 "readin pst found and no symtabs."));
840 return psymtab_to_symtab (ofp
, cs_pst
);
846 forget_cached_source_info_partial (struct objfile
*objfile
)
848 struct partial_symtab
*pst
;
850 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
852 if (pst
->fullname
!= NULL
)
854 xfree (pst
->fullname
);
855 pst
->fullname
= NULL
;
861 print_partial_symbols (struct gdbarch
*gdbarch
,
862 struct partial_symbol
**p
, int count
, char *what
,
863 struct ui_file
*outfile
)
865 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
869 fprintf_filtered (outfile
, " `%s'", SYMBOL_LINKAGE_NAME (*p
));
870 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
872 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
874 fputs_filtered (", ", outfile
);
875 switch (SYMBOL_DOMAIN (*p
))
878 fputs_filtered ("undefined domain, ", outfile
);
881 /* This is the usual thing -- don't print it. */
884 fputs_filtered ("struct domain, ", outfile
);
887 fputs_filtered ("label domain, ", outfile
);
890 fputs_filtered ("<invalid domain>, ", outfile
);
893 switch (PSYMBOL_CLASS (*p
))
896 fputs_filtered ("undefined", outfile
);
899 fputs_filtered ("constant int", outfile
);
902 fputs_filtered ("static", outfile
);
905 fputs_filtered ("register", outfile
);
908 fputs_filtered ("pass by value", outfile
);
911 fputs_filtered ("pass by reference", outfile
);
913 case LOC_REGPARM_ADDR
:
914 fputs_filtered ("register address parameter", outfile
);
917 fputs_filtered ("stack parameter", outfile
);
920 fputs_filtered ("type", outfile
);
923 fputs_filtered ("label", outfile
);
926 fputs_filtered ("function", outfile
);
928 case LOC_CONST_BYTES
:
929 fputs_filtered ("constant bytes", outfile
);
932 fputs_filtered ("unresolved", outfile
);
934 case LOC_OPTIMIZED_OUT
:
935 fputs_filtered ("optimized out", outfile
);
938 fputs_filtered ("computed at runtime", outfile
);
941 fputs_filtered ("<invalid location>", outfile
);
944 fputs_filtered (", ", outfile
);
945 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (*p
)), outfile
);
946 fprintf_filtered (outfile
, "\n");
952 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
953 struct ui_file
*outfile
)
955 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
958 if (psymtab
->anonymous
)
960 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
965 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
968 fprintf_filtered (outfile
, "(object ");
969 gdb_print_host_address (psymtab
, outfile
);
970 fprintf_filtered (outfile
, ")\n\n");
971 fprintf_unfiltered (outfile
, " Read from object file %s (",
973 gdb_print_host_address (objfile
, outfile
);
974 fprintf_unfiltered (outfile
, ")\n");
978 fprintf_filtered (outfile
,
979 " Full symtab was read (at ");
980 gdb_print_host_address (psymtab
->symtab
, outfile
);
981 fprintf_filtered (outfile
, " by function at ");
982 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
983 fprintf_filtered (outfile
, ")\n");
986 fprintf_filtered (outfile
, " Relocate symbols by ");
987 for (i
= 0; i
< objfile
->num_sections
; ++i
)
990 fprintf_filtered (outfile
, ", ");
992 fputs_filtered (paddress (gdbarch
,
993 ANOFFSET (psymtab
->section_offsets
, i
)),
996 fprintf_filtered (outfile
, "\n");
998 fprintf_filtered (outfile
, " Symbols cover text addresses ");
999 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
), outfile
);
1000 fprintf_filtered (outfile
, "-");
1001 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
), outfile
);
1002 fprintf_filtered (outfile
, "\n");
1003 fprintf_filtered (outfile
, " Address map supported - %s.\n",
1004 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
1005 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
1006 psymtab
->number_of_dependencies
);
1007 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1009 fprintf_filtered (outfile
, " %d ", i
);
1010 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
1011 fprintf_filtered (outfile
, " %s\n",
1012 psymtab
->dependencies
[i
]->filename
);
1014 if (psymtab
->user
!= NULL
)
1016 fprintf_filtered (outfile
, " Shared partial symtab with user ");
1017 gdb_print_host_address (psymtab
->user
, outfile
);
1018 fprintf_filtered (outfile
, "\n");
1020 if (psymtab
->n_global_syms
> 0)
1022 print_partial_symbols (gdbarch
,
1023 objfile
->global_psymbols
.list
1024 + psymtab
->globals_offset
,
1025 psymtab
->n_global_syms
, "Global", outfile
);
1027 if (psymtab
->n_static_syms
> 0)
1029 print_partial_symbols (gdbarch
,
1030 objfile
->static_psymbols
.list
1031 + psymtab
->statics_offset
,
1032 psymtab
->n_static_syms
, "Static", outfile
);
1034 fprintf_filtered (outfile
, "\n");
1038 print_psymtab_stats_for_objfile (struct objfile
*objfile
)
1041 struct partial_symtab
*ps
;
1044 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1046 if (ps
->readin
== 0)
1049 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
1053 dump_psymtabs_for_objfile (struct objfile
*objfile
)
1055 struct partial_symtab
*psymtab
;
1057 if (objfile
->psymtabs
)
1059 printf_filtered ("Psymtabs:\n");
1060 for (psymtab
= objfile
->psymtabs
;
1062 psymtab
= psymtab
->next
)
1064 printf_filtered ("%s at ",
1066 gdb_print_host_address (psymtab
, gdb_stdout
);
1067 printf_filtered (", ");
1070 printf_filtered ("\n\n");
1074 /* Look through the partial symtabs for all symbols which begin
1075 by matching FUNC_NAME. Make sure we read that symbol table in. */
1078 read_symtabs_for_function (struct objfile
*objfile
, const char *func_name
)
1080 struct partial_symtab
*ps
;
1082 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1087 if ((lookup_partial_symbol (objfile
, ps
, func_name
, 1, VAR_DOMAIN
)
1089 || (lookup_partial_symbol (objfile
, ps
, func_name
, 0, VAR_DOMAIN
)
1091 psymtab_to_symtab (objfile
, ps
);
1096 expand_partial_symbol_tables (struct objfile
*objfile
)
1098 struct partial_symtab
*psymtab
;
1100 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1102 psymtab_to_symtab (objfile
, psymtab
);
1107 read_psymtabs_with_fullname (struct objfile
*objfile
, const char *fullname
)
1109 struct partial_symtab
*p
;
1111 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
1113 /* Anonymous psymtabs don't have a name of a source file. */
1117 /* psymtab_to_fullname tries to open the file which is slow.
1118 Don't call it if we know the basenames don't match. */
1119 if ((basenames_may_differ
1120 || filename_cmp (lbasename (fullname
), lbasename (p
->filename
)) == 0)
1121 && filename_cmp (fullname
, psymtab_to_fullname (p
)) == 0)
1122 psymtab_to_symtab (objfile
, p
);
1127 map_symbol_filenames_psymtab (struct objfile
*objfile
,
1128 symbol_filename_ftype
*fun
, void *data
,
1131 struct partial_symtab
*ps
;
1133 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1135 const char *fullname
;
1140 /* We can skip shared psymtabs here, because any file name will be
1141 attached to the unshared psymtab. */
1142 if (ps
->user
!= NULL
)
1145 /* Anonymous psymtabs don't have a file name. */
1151 fullname
= psymtab_to_fullname (ps
);
1154 (*fun
) (ps
->filename
, fullname
, data
);
1158 /* Finds the fullname that a partial_symtab represents.
1160 If this functions finds the fullname, it will save it in ps->fullname
1161 and it will also return the value.
1163 If this function fails to find the file that this partial_symtab represents,
1164 NULL will be returned and ps->fullname will be set to NULL. */
1167 psymtab_to_fullname (struct partial_symtab
*ps
)
1169 gdb_assert (!ps
->anonymous
);
1171 /* Use cached copy if we have it.
1172 We rely on forget_cached_source_info being called appropriately
1173 to handle cases like the file being moved. */
1174 if (ps
->fullname
== NULL
)
1176 int fd
= find_and_open_source (ps
->filename
, ps
->dirname
, &ps
->fullname
);
1183 struct cleanup
*back_to
;
1185 /* rewrite_source_path would be applied by find_and_open_source, we
1186 should report the pathname where GDB tried to find the file. */
1188 if (ps
->dirname
== NULL
|| IS_ABSOLUTE_PATH (ps
->filename
))
1189 fullname
= xstrdup (ps
->filename
);
1191 fullname
= concat (ps
->dirname
, SLASH_STRING
, ps
->filename
, NULL
);
1193 back_to
= make_cleanup (xfree
, fullname
);
1194 ps
->fullname
= rewrite_source_path (fullname
);
1195 if (ps
->fullname
== NULL
)
1196 ps
->fullname
= xstrdup (fullname
);
1197 do_cleanups (back_to
);
1201 return ps
->fullname
;
1205 find_symbol_file_from_partial (struct objfile
*objfile
, const char *name
)
1207 struct partial_symtab
*pst
;
1209 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
1211 if (lookup_partial_symbol (objfile
, pst
, name
, 1, VAR_DOMAIN
))
1212 return pst
->filename
;
1217 /* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1218 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1219 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1220 ever returns non-zero, and otherwise returns 0. */
1223 map_block (const char *name
, domain_enum
namespace, struct objfile
*objfile
,
1224 struct block
*block
,
1225 int (*callback
) (struct block
*, struct symbol
*, void *),
1226 void *data
, symbol_compare_ftype
*match
)
1228 struct block_iterator iter
;
1231 for (sym
= block_iter_match_first (block
, name
, match
, &iter
);
1232 sym
!= NULL
; sym
= block_iter_match_next (name
, match
, &iter
))
1234 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym
),
1235 SYMBOL_DOMAIN (sym
), namespace))
1237 if (callback (block
, sym
, data
))
1245 /* Psymtab version of map_matching_symbols. See its definition in
1246 the definition of quick_symbol_functions in symfile.h. */
1249 map_matching_symbols_psymtab (const char *name
, domain_enum
namespace,
1250 struct objfile
*objfile
, int global
,
1251 int (*callback
) (struct block
*,
1252 struct symbol
*, void *),
1254 symbol_compare_ftype
*match
,
1255 symbol_compare_ftype
*ordered_compare
)
1257 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1258 struct partial_symtab
*ps
;
1260 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1264 || match_partial_symbol (objfile
, ps
, global
, name
, namespace, match
,
1267 struct symtab
*s
= psymtab_to_symtab (objfile
, ps
);
1268 struct block
*block
;
1270 if (s
== NULL
|| !s
->primary
)
1272 block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), block_kind
);
1273 if (map_block (name
, namespace, objfile
, block
,
1274 callback
, data
, match
))
1276 if (callback (block
, NULL
, data
))
1282 /* A helper for expand_symtabs_matching_via_partial that handles
1283 searching included psymtabs. This returns 1 if a symbol is found,
1284 and zero otherwise. It also updates the 'searched_flag' on the
1285 various psymtabs that it searches. */
1288 recursively_search_psymtabs (struct partial_symtab
*ps
,
1289 struct objfile
*objfile
,
1290 enum search_domain kind
,
1291 int (*name_matcher
) (const char *, void *),
1294 struct partial_symbol
**psym
;
1295 struct partial_symbol
**bound
, **gbound
, **sbound
;
1297 int result
= PST_SEARCHED_AND_NOT_FOUND
;
1300 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1301 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1303 /* Recurse into shared psymtabs first, because they may have already
1304 been searched, and this could save some time. */
1305 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1309 /* Skip non-shared dependencies, these are handled elsewhere. */
1310 if (ps
->dependencies
[i
]->user
== NULL
)
1313 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1314 objfile
, kind
, name_matcher
, data
);
1317 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1322 gbound
= (objfile
->global_psymbols
.list
1323 + ps
->globals_offset
+ ps
->n_global_syms
);
1324 sbound
= (objfile
->static_psymbols
.list
1325 + ps
->statics_offset
+ ps
->n_static_syms
);
1328 /* Go through all of the symbols stored in a partial
1329 symtab in one loop. */
1330 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1335 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
1337 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1348 if ((kind
== ALL_DOMAIN
1349 || (kind
== VARIABLES_DOMAIN
1350 && PSYMBOL_CLASS (*psym
) != LOC_TYPEDEF
1351 && PSYMBOL_CLASS (*psym
) != LOC_BLOCK
)
1352 || (kind
== FUNCTIONS_DOMAIN
1353 && PSYMBOL_CLASS (*psym
) == LOC_BLOCK
)
1354 || (kind
== TYPES_DOMAIN
1355 && PSYMBOL_CLASS (*psym
) == LOC_TYPEDEF
))
1356 && (*name_matcher
) (SYMBOL_SEARCH_NAME (*psym
), data
))
1358 /* Found a match, so notify our caller. */
1359 result
= PST_SEARCHED_AND_FOUND
;
1366 ps
->searched_flag
= result
;
1367 return result
== PST_SEARCHED_AND_FOUND
;
1371 expand_symtabs_matching_via_partial
1372 (struct objfile
*objfile
,
1373 int (*file_matcher
) (const char *, void *, int basenames
),
1374 int (*name_matcher
) (const char *, void *),
1375 enum search_domain kind
,
1378 struct partial_symtab
*ps
;
1380 /* Clear the search flags. */
1381 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1383 ps
->searched_flag
= PST_NOT_SEARCHED
;
1386 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1391 /* We skip shared psymtabs because file-matching doesn't apply
1392 to them; but we search them later in the loop. */
1393 if (ps
->user
!= NULL
)
1401 /* Before we invoke realpath, which can get expensive when many
1402 files are involved, do a quick comparison of the basenames. */
1403 if (!(*file_matcher
) (ps
->filename
, data
, 0)
1404 && (basenames_may_differ
1405 || (*file_matcher
) (lbasename (ps
->filename
), data
, 1))
1406 && !(*file_matcher
) (psymtab_to_fullname (ps
), data
, 0))
1410 if (recursively_search_psymtabs (ps
, objfile
, kind
, name_matcher
, data
))
1411 psymtab_to_symtab (objfile
, ps
);
1416 objfile_has_psyms (struct objfile
*objfile
)
1418 return objfile
->psymtabs
!= NULL
;
1421 const struct quick_symbol_functions psym_functions
=
1424 find_last_source_symtab_from_partial
,
1425 forget_cached_source_info_partial
,
1426 partial_map_symtabs_matching_filename
,
1427 lookup_symbol_aux_psymtabs
,
1428 print_psymtab_stats_for_objfile
,
1429 dump_psymtabs_for_objfile
,
1431 read_symtabs_for_function
,
1432 expand_partial_symbol_tables
,
1433 read_psymtabs_with_fullname
,
1434 find_symbol_file_from_partial
,
1435 map_matching_symbols_psymtab
,
1436 expand_symtabs_matching_via_partial
,
1437 find_pc_sect_symtab_from_partial
,
1438 map_symbol_filenames_psymtab
1443 /* This compares two partial symbols by names, using strcmp_iw_ordered
1444 for the comparison. */
1447 compare_psymbols (const void *s1p
, const void *s2p
)
1449 struct partial_symbol
*const *s1
= s1p
;
1450 struct partial_symbol
*const *s2
= s2p
;
1452 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1
),
1453 SYMBOL_SEARCH_NAME (*s2
));
1457 sort_pst_symbols (struct objfile
*objfile
, struct partial_symtab
*pst
)
1459 /* Sort the global list; don't sort the static list. */
1461 qsort (objfile
->global_psymbols
.list
+ pst
->globals_offset
,
1462 pst
->n_global_syms
, sizeof (struct partial_symbol
*),
1466 /* Allocate and partially fill a partial symtab. It will be
1467 completely filled at the end of the symbol list.
1469 FILENAME is the name of the symbol-file we are reading from. */
1471 struct partial_symtab
*
1472 start_psymtab_common (struct objfile
*objfile
,
1473 struct section_offsets
*section_offsets
,
1474 const char *filename
,
1475 CORE_ADDR textlow
, struct partial_symbol
**global_syms
,
1476 struct partial_symbol
**static_syms
)
1478 struct partial_symtab
*psymtab
;
1480 psymtab
= allocate_psymtab (filename
, objfile
);
1481 psymtab
->section_offsets
= section_offsets
;
1482 psymtab
->textlow
= textlow
;
1483 psymtab
->texthigh
= psymtab
->textlow
; /* default */
1484 psymtab
->globals_offset
= global_syms
- objfile
->global_psymbols
.list
;
1485 psymtab
->statics_offset
= static_syms
- objfile
->static_psymbols
.list
;
1489 /* Calculate a hash code for the given partial symbol. The hash is
1490 calculated using the symbol's value, language, domain, class
1491 and name. These are the values which are set by
1492 add_psymbol_to_bcache. */
1494 static unsigned long
1495 psymbol_hash (const void *addr
, int length
)
1497 unsigned long h
= 0;
1498 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1499 unsigned int lang
= psymbol
->ginfo
.language
;
1500 unsigned int domain
= PSYMBOL_DOMAIN (psymbol
);
1501 unsigned int class = PSYMBOL_CLASS (psymbol
);
1503 h
= hash_continue (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1504 h
= hash_continue (&lang
, sizeof (unsigned int), h
);
1505 h
= hash_continue (&domain
, sizeof (unsigned int), h
);
1506 h
= hash_continue (&class, sizeof (unsigned int), h
);
1507 h
= hash_continue (psymbol
->ginfo
.name
, strlen (psymbol
->ginfo
.name
), h
);
1512 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1513 For the comparison this function uses a symbols value,
1514 language, domain, class and name. */
1517 psymbol_compare (const void *addr1
, const void *addr2
, int length
)
1519 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1520 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1522 return (memcmp (&sym1
->ginfo
.value
, &sym1
->ginfo
.value
,
1523 sizeof (sym1
->ginfo
.value
)) == 0
1524 && sym1
->ginfo
.language
== sym2
->ginfo
.language
1525 && PSYMBOL_DOMAIN (sym1
) == PSYMBOL_DOMAIN (sym2
)
1526 && PSYMBOL_CLASS (sym1
) == PSYMBOL_CLASS (sym2
)
1527 && sym1
->ginfo
.name
== sym2
->ginfo
.name
);
1530 /* Initialize a partial symbol bcache. */
1532 struct psymbol_bcache
*
1533 psymbol_bcache_init (void)
1535 struct psymbol_bcache
*bcache
= XCALLOC (1, struct psymbol_bcache
);
1536 bcache
->bcache
= bcache_xmalloc (psymbol_hash
, psymbol_compare
);
1540 /* Free a partial symbol bcache. */
1542 psymbol_bcache_free (struct psymbol_bcache
*bcache
)
1547 bcache_xfree (bcache
->bcache
);
1551 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1554 psymbol_bcache_get_bcache (struct psymbol_bcache
*bcache
)
1556 return bcache
->bcache
;
1559 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1560 symbol before, add a copy to BCACHE. In either case, return a pointer
1561 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1562 1 in case of new entry or 0 if returning an old entry. */
1564 static const struct partial_symbol
*
1565 psymbol_bcache_full (struct partial_symbol
*sym
,
1566 struct psymbol_bcache
*bcache
,
1569 return bcache_full (sym
,
1570 sizeof (struct partial_symbol
),
1575 /* Helper function, initialises partial symbol structure and stashes
1576 it into objfile's bcache. Note that our caching mechanism will
1577 use all fields of struct partial_symbol to determine hash value of the
1578 structure. In other words, having two symbols with the same name but
1579 different domain (or address) is possible and correct. */
1581 static const struct partial_symbol
*
1582 add_psymbol_to_bcache (const char *name
, int namelength
, int copy_name
,
1584 enum address_class
class,
1585 long val
, /* Value as a long */
1586 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1587 enum language language
, struct objfile
*objfile
,
1590 struct partial_symbol psymbol
;
1592 /* We must ensure that the entire struct has been zeroed before
1593 assigning to it, because an assignment may not touch some of the
1595 memset (&psymbol
, 0, sizeof (psymbol
));
1597 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1600 SYMBOL_VALUE (&psymbol
) = val
;
1604 SYMBOL_VALUE_ADDRESS (&psymbol
) = coreaddr
;
1606 SYMBOL_SECTION (&psymbol
) = 0;
1607 SYMBOL_OBJ_SECTION (&psymbol
) = NULL
;
1608 SYMBOL_SET_LANGUAGE (&psymbol
, language
, &objfile
->objfile_obstack
);
1609 PSYMBOL_DOMAIN (&psymbol
) = domain
;
1610 PSYMBOL_CLASS (&psymbol
) = class;
1612 SYMBOL_SET_NAMES (&psymbol
, name
, namelength
, copy_name
, objfile
);
1614 /* Stash the partial symbol away in the cache. */
1615 return psymbol_bcache_full (&psymbol
,
1616 objfile
->psymbol_cache
,
1620 /* Increase the space allocated for LISTP, which is probably
1621 global_psymbols or static_psymbols. This space will eventually
1622 be freed in free_objfile(). */
1625 extend_psymbol_list (struct psymbol_allocation_list
*listp
,
1626 struct objfile
*objfile
)
1630 if (listp
->size
== 0)
1633 listp
->list
= (struct partial_symbol
**)
1634 xmalloc (new_size
* sizeof (struct partial_symbol
*));
1638 new_size
= listp
->size
* 2;
1639 listp
->list
= (struct partial_symbol
**)
1640 xrealloc ((char *) listp
->list
,
1641 new_size
* sizeof (struct partial_symbol
*));
1643 /* Next assumes we only went one over. Should be good if
1644 program works correctly. */
1645 listp
->next
= listp
->list
+ listp
->size
;
1646 listp
->size
= new_size
;
1649 /* Helper function, adds partial symbol to the given partial symbol
1653 append_psymbol_to_list (struct psymbol_allocation_list
*list
,
1654 const struct partial_symbol
*psym
,
1655 struct objfile
*objfile
)
1657 if (list
->next
>= list
->list
+ list
->size
)
1658 extend_psymbol_list (list
, objfile
);
1659 *list
->next
++ = (struct partial_symbol
*) psym
;
1660 OBJSTAT (objfile
, n_psyms
++);
1663 /* Add a symbol with a long value to a psymtab.
1664 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1665 Return the partial symbol that has been added. */
1668 add_psymbol_to_list (const char *name
, int namelength
, int copy_name
,
1670 enum address_class
class,
1671 struct psymbol_allocation_list
*list
,
1672 long val
, /* Value as a long */
1673 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1674 enum language language
, struct objfile
*objfile
)
1676 const struct partial_symbol
*psym
;
1680 /* Stash the partial symbol away in the cache. */
1681 psym
= add_psymbol_to_bcache (name
, namelength
, copy_name
, domain
, class,
1682 val
, coreaddr
, language
, objfile
, &added
);
1684 /* Do not duplicate global partial symbols. */
1685 if (list
== &objfile
->global_psymbols
1689 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1690 append_psymbol_to_list (list
, psym
, objfile
);
1693 /* Initialize storage for partial symbols. */
1696 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1698 /* Free any previously allocated psymbol lists. */
1700 if (objfile
->global_psymbols
.list
)
1702 xfree (objfile
->global_psymbols
.list
);
1704 if (objfile
->static_psymbols
.list
)
1706 xfree (objfile
->static_psymbols
.list
);
1709 /* Current best guess is that approximately a twentieth
1710 of the total symbols (in a debugging file) are global or static
1711 oriented symbols, then multiply that by slop factor of two. */
1713 objfile
->global_psymbols
.size
= total_symbols
/ 10;
1714 objfile
->static_psymbols
.size
= total_symbols
/ 10;
1716 if (objfile
->global_psymbols
.size
> 0)
1718 objfile
->global_psymbols
.next
=
1719 objfile
->global_psymbols
.list
= (struct partial_symbol
**)
1720 xmalloc ((objfile
->global_psymbols
.size
1721 * sizeof (struct partial_symbol
*)));
1723 if (objfile
->static_psymbols
.size
> 0)
1725 objfile
->static_psymbols
.next
=
1726 objfile
->static_psymbols
.list
= (struct partial_symbol
**)
1727 xmalloc ((objfile
->static_psymbols
.size
1728 * sizeof (struct partial_symbol
*)));
1732 struct partial_symtab
*
1733 allocate_psymtab (const char *filename
, struct objfile
*objfile
)
1735 struct partial_symtab
*psymtab
;
1737 if (objfile
->free_psymtabs
)
1739 psymtab
= objfile
->free_psymtabs
;
1740 objfile
->free_psymtabs
= psymtab
->next
;
1743 psymtab
= (struct partial_symtab
*)
1744 obstack_alloc (&objfile
->objfile_obstack
,
1745 sizeof (struct partial_symtab
));
1747 memset (psymtab
, 0, sizeof (struct partial_symtab
));
1748 psymtab
->filename
= obstack_copy0 (&objfile
->objfile_obstack
,
1749 filename
, strlen (filename
));
1750 psymtab
->symtab
= NULL
;
1752 /* Prepend it to the psymtab list for the objfile it belongs to.
1753 Psymtabs are searched in most recent inserted -> least recent
1756 psymtab
->next
= objfile
->psymtabs
;
1757 objfile
->psymtabs
= psymtab
;
1759 if (symtab_create_debug
)
1761 /* Be a bit clever with debugging messages, and don't print objfile
1762 every time, only when it changes. */
1763 static char *last_objfile_name
= NULL
;
1765 if (last_objfile_name
== NULL
1766 || strcmp (last_objfile_name
, objfile
->name
) != 0)
1768 xfree (last_objfile_name
);
1769 last_objfile_name
= xstrdup (objfile
->name
);
1770 fprintf_unfiltered (gdb_stdlog
,
1771 "Creating one or more psymtabs for objfile %s ...\n",
1774 fprintf_unfiltered (gdb_stdlog
,
1775 "Created psymtab %s for module %s.\n",
1776 host_address_to_string (psymtab
), filename
);
1783 discard_psymtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
1785 struct partial_symtab
**prev_pst
;
1788 Empty psymtabs happen as a result of header files which don't
1789 have any symbols in them. There can be a lot of them. But this
1790 check is wrong, in that a psymtab with N_SLINE entries but
1791 nothing else is not empty, but we don't realize that. Fixing
1792 that without slowing things down might be tricky. */
1794 /* First, snip it out of the psymtab chain. */
1796 prev_pst
= &(objfile
->psymtabs
);
1797 while ((*prev_pst
) != pst
)
1798 prev_pst
= &((*prev_pst
)->next
);
1799 (*prev_pst
) = pst
->next
;
1801 /* Next, put it on a free list for recycling. */
1803 pst
->next
= objfile
->free_psymtabs
;
1804 objfile
->free_psymtabs
= pst
;
1807 /* An object of this type is passed to discard_psymtabs_upto. */
1809 struct psymtab_state
1811 /* The objfile where psymtabs are discarded. */
1813 struct objfile
*objfile
;
1815 /* The first psymtab to save. */
1817 struct partial_symtab
*save
;
1820 /* A cleanup function used by make_cleanup_discard_psymtabs. */
1823 discard_psymtabs_upto (void *arg
)
1825 struct psymtab_state
*state
= arg
;
1827 while (state
->objfile
->psymtabs
!= state
->save
)
1828 discard_psymtab (state
->objfile
, state
->objfile
->psymtabs
);
1831 /* Return a new cleanup that discards all psymtabs created in OBJFILE
1832 after this function is called. */
1835 make_cleanup_discard_psymtabs (struct objfile
*objfile
)
1837 struct psymtab_state
*state
= XNEW (struct psymtab_state
);
1839 state
->objfile
= objfile
;
1840 state
->save
= objfile
->psymtabs
;
1842 return make_cleanup_dtor (discard_psymtabs_upto
, state
, xfree
);
1848 maintenance_print_psymbols (char *args
, int from_tty
)
1851 struct ui_file
*outfile
;
1852 struct cleanup
*cleanups
;
1853 char *symname
= NULL
;
1854 char *filename
= DEV_TTY
;
1855 struct objfile
*objfile
;
1856 struct partial_symtab
*ps
;
1863 print-psymbols takes an output file name and optional symbol file name"));
1865 argv
= gdb_buildargv (args
);
1866 cleanups
= make_cleanup_freeargv (argv
);
1868 if (argv
[0] != NULL
)
1871 /* If a second arg is supplied, it is a source file name to match on. */
1872 if (argv
[1] != NULL
)
1878 filename
= tilde_expand (filename
);
1879 make_cleanup (xfree
, filename
);
1881 outfile
= gdb_fopen (filename
, FOPEN_WT
);
1883 perror_with_name (filename
);
1884 make_cleanup_ui_file_delete (outfile
);
1886 ALL_PSYMTABS (objfile
, ps
)
1889 if (symname
== NULL
|| filename_cmp (symname
, ps
->filename
) == 0)
1890 dump_psymtab (objfile
, ps
, outfile
);
1892 do_cleanups (cleanups
);
1895 /* List all the partial symbol tables whose names match REGEXP (optional). */
1897 maintenance_info_psymtabs (char *regexp
, int from_tty
)
1899 struct program_space
*pspace
;
1900 struct objfile
*objfile
;
1905 ALL_PSPACES (pspace
)
1906 ALL_PSPACE_OBJFILES (pspace
, objfile
)
1908 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1909 struct partial_symtab
*psymtab
;
1911 /* We don't want to print anything for this objfile until we
1912 actually find a symtab whose name matches. */
1913 int printed_objfile_start
= 0;
1915 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1920 || re_exec (psymtab
->filename
))
1922 if (! printed_objfile_start
)
1924 printf_filtered ("{ objfile %s ", objfile
->name
);
1926 printf_filtered ("((struct objfile *) %s)\n",
1927 host_address_to_string (objfile
));
1928 printed_objfile_start
= 1;
1931 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1933 printf_filtered ("((struct partial_symtab *) %s)\n",
1934 host_address_to_string (psymtab
));
1936 printf_filtered (" readin %s\n",
1937 psymtab
->readin
? "yes" : "no");
1938 printf_filtered (" fullname %s\n",
1940 ? psymtab
->fullname
: "(null)");
1941 printf_filtered (" text addresses ");
1942 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
),
1944 printf_filtered (" -- ");
1945 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
),
1947 printf_filtered ("\n");
1948 printf_filtered (" psymtabs_addrmap_supported %s\n",
1949 (psymtab
->psymtabs_addrmap_supported
1951 printf_filtered (" globals ");
1952 if (psymtab
->n_global_syms
)
1954 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1955 host_address_to_string (objfile
->global_psymbols
.list
1956 + psymtab
->globals_offset
),
1957 psymtab
->n_global_syms
);
1960 printf_filtered ("(none)\n");
1961 printf_filtered (" statics ");
1962 if (psymtab
->n_static_syms
)
1964 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1965 host_address_to_string (objfile
->static_psymbols
.list
1966 + psymtab
->statics_offset
),
1967 psymtab
->n_static_syms
);
1970 printf_filtered ("(none)\n");
1971 printf_filtered (" dependencies ");
1972 if (psymtab
->number_of_dependencies
)
1976 printf_filtered ("{\n");
1977 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1979 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
1981 /* Note the string concatenation there --- no comma. */
1982 printf_filtered (" psymtab %s "
1983 "((struct partial_symtab *) %s)\n",
1985 host_address_to_string (dep
));
1987 printf_filtered (" }\n");
1990 printf_filtered ("(none)\n");
1991 printf_filtered (" }\n");
1995 if (printed_objfile_start
)
1996 printf_filtered ("}\n");
2000 /* Check consistency of psymtabs and symtabs. */
2003 maintenance_check_symtabs (char *ignore
, int from_tty
)
2006 struct partial_symbol
**psym
;
2007 struct symtab
*s
= NULL
;
2008 struct partial_symtab
*ps
;
2009 struct blockvector
*bv
;
2010 struct objfile
*objfile
;
2014 ALL_PSYMTABS (objfile
, ps
)
2016 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2018 s
= psymtab_to_symtab (objfile
, ps
);
2021 bv
= BLOCKVECTOR (s
);
2022 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2023 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2024 length
= ps
->n_static_syms
;
2027 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
2028 SYMBOL_DOMAIN (*psym
));
2031 printf_filtered ("Static symbol `");
2032 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
2033 printf_filtered ("' only found in ");
2034 puts_filtered (ps
->filename
);
2035 printf_filtered (" psymtab\n");
2039 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2040 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2041 length
= ps
->n_global_syms
;
2044 sym
= lookup_block_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
2045 SYMBOL_DOMAIN (*psym
));
2048 printf_filtered ("Global symbol `");
2049 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
2050 printf_filtered ("' only found in ");
2051 puts_filtered (ps
->filename
);
2052 printf_filtered (" psymtab\n");
2056 if (ps
->texthigh
< ps
->textlow
)
2058 printf_filtered ("Psymtab ");
2059 puts_filtered (ps
->filename
);
2060 printf_filtered (" covers bad range ");
2061 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
2062 printf_filtered (" - ");
2063 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
2064 printf_filtered ("\n");
2067 if (ps
->texthigh
== 0)
2069 if (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
))
2071 printf_filtered ("Psymtab ");
2072 puts_filtered (ps
->filename
);
2073 printf_filtered (" covers ");
2074 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
2075 printf_filtered (" - ");
2076 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
2077 printf_filtered (" but symtab covers only ");
2078 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2079 printf_filtered (" - ");
2080 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2081 printf_filtered ("\n");
2089 expand_partial_symbol_names (int (*fun
) (const char *, void *),
2092 struct objfile
*objfile
;
2094 ALL_OBJFILES (objfile
)
2097 objfile
->sf
->qf
->expand_symtabs_matching (objfile
, NULL
, fun
,
2103 map_partial_symbol_filenames (symbol_filename_ftype
*fun
, void *data
,
2106 struct objfile
*objfile
;
2108 ALL_OBJFILES (objfile
)
2111 objfile
->sf
->qf
->map_symbol_filenames (objfile
, fun
, data
,
2116 extern initialize_file_ftype _initialize_psymtab
;
2119 _initialize_psymtab (void)
2121 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2122 Print dump of current partial symbol definitions.\n\
2123 Entries in the partial symbol table are dumped to file OUTFILE.\n\
2124 If a SOURCE file is specified, dump only that file's partial symbols."),
2125 &maintenanceprintlist
);
2127 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2128 List the partial symbol tables for all object files.\n\
2129 This does not include information about individual partial symbols,\n\
2130 just the symbol table structures themselves."),
2131 &maintenanceinfolist
);
2133 add_cmd ("check-symtabs", class_maintenance
, maintenance_check_symtabs
,
2134 _("Check consistency of psymtabs and symtabs."),