1 /* Partial symbol tables.
3 Copyright (C) 2009-2015 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/>. */
25 #include "filenames.h"
32 #include "readline/readline.h"
33 #include "gdb_regex.h"
34 #include "dictionary.h"
36 #include "cp-support.h"
40 #define DEV_TTY "/dev/tty"
45 struct bcache
*bcache
;
48 static struct partial_symbol
*match_partial_symbol (struct objfile
*,
49 struct partial_symtab
*,
51 const char *, domain_enum
,
52 symbol_compare_ftype
*,
53 symbol_compare_ftype
*);
55 static struct partial_symbol
*lookup_partial_symbol (struct objfile
*,
56 struct partial_symtab
*,
60 static const char *psymtab_to_fullname (struct partial_symtab
*ps
);
62 static struct partial_symbol
*find_pc_sect_psymbol (struct objfile
*,
63 struct partial_symtab
*,
65 struct obj_section
*);
67 static void fixup_psymbol_section (struct partial_symbol
*psym
,
68 struct objfile
*objfile
);
70 static struct compunit_symtab
*psymtab_to_symtab (struct objfile
*objfile
,
71 struct partial_symtab
*pst
);
73 /* Ensure that the partial symbols for OBJFILE have been loaded. This
74 function always returns its argument, as a convenience. */
77 require_partial_symbols (struct objfile
*objfile
, int verbose
)
79 if ((objfile
->flags
& OBJF_PSYMTABS_READ
) == 0)
81 objfile
->flags
|= OBJF_PSYMTABS_READ
;
83 if (objfile
->sf
->sym_read_psymbols
)
87 printf_unfiltered (_("Reading symbols from %s..."),
88 objfile_name (objfile
));
89 gdb_flush (gdb_stdout
);
91 (*objfile
->sf
->sym_read_psymbols
) (objfile
);
94 if (!objfile_has_symbols (objfile
))
97 printf_unfiltered (_("(no debugging symbols found)..."));
101 printf_unfiltered (_("done.\n"));
109 /* Traverse all psymtabs in one objfile, requiring that the psymtabs
112 #define ALL_OBJFILE_PSYMTABS_REQUIRED(objfile, p) \
113 for ((p) = require_partial_symbols (objfile, 1)->psymtabs; \
117 /* We want to make sure this file always requires psymtabs. */
119 #undef ALL_OBJFILE_PSYMTABS
121 /* Traverse all psymtabs in all objfiles. */
123 #define ALL_PSYMTABS(objfile, p) \
124 ALL_OBJFILES (objfile) \
125 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
127 /* Helper function for psym_map_symtabs_matching_filename that
128 expands the symtabs and calls the iterator. */
131 partial_map_expand_apply (struct objfile
*objfile
,
133 const char *real_path
,
134 struct partial_symtab
*pst
,
135 int (*callback
) (struct symtab
*, void *),
138 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
140 /* Shared psymtabs should never be seen here. Instead they should
141 be handled properly by the caller. */
142 gdb_assert (pst
->user
== NULL
);
144 /* Don't visit already-expanded psymtabs. */
148 /* This may expand more than one symtab, and we want to iterate over
150 psymtab_to_symtab (objfile
, pst
);
152 return iterate_over_some_symtabs (name
, real_path
, callback
, data
,
153 objfile
->compunit_symtabs
, last_made
);
156 /* Psymtab version of map_symtabs_matching_filename. See its definition in
157 the definition of quick_symbol_functions in symfile.h. */
160 psym_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 bound_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. */
245 if (msymbol
.minsym
== NULL
)
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 == BMSYMBOL_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 bound_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
.minsym
&& 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 != BMSYMBOL_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 /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in
375 the definition of quick_symbol_functions in symfile.h. */
377 static struct compunit_symtab
*
378 psym_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
379 struct bound_minimal_symbol msymbol
,
381 struct obj_section
*section
,
384 struct partial_symtab
*ps
= find_pc_sect_psymtab (objfile
, pc
, section
,
388 if (warn_if_readin
&& ps
->readin
)
389 /* Might want to error() here (in case symtab is corrupt and
390 will cause a core dump), but maybe we can successfully
391 continue, so let's not. */
393 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
394 paddress (get_objfile_arch (objfile
), pc
));
395 psymtab_to_symtab (objfile
, ps
);
396 return ps
->compunit_symtab
;
401 /* Find which partial symbol within a psymtab matches PC and SECTION.
404 static struct partial_symbol
*
405 find_pc_sect_psymbol (struct objfile
*objfile
,
406 struct partial_symtab
*psymtab
, CORE_ADDR pc
,
407 struct obj_section
*section
)
409 struct partial_symbol
*best
= NULL
, *p
, **pp
;
412 gdb_assert (psymtab
!= NULL
);
414 /* Cope with programs that start at address 0. */
415 best_pc
= (psymtab
->textlow
!= 0) ? psymtab
->textlow
- 1 : 0;
417 /* Search the global symbols as well as the static symbols, so that
418 find_pc_partial_function doesn't use a minimal symbol and thus
419 cache a bad endaddr. */
420 for (pp
= objfile
->global_psymbols
.list
+ psymtab
->globals_offset
;
421 (pp
- (objfile
->global_psymbols
.list
+ psymtab
->globals_offset
)
422 < psymtab
->n_global_syms
);
426 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
427 && PSYMBOL_CLASS (p
) == LOC_BLOCK
428 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
429 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
430 || (psymtab
->textlow
== 0
431 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
433 if (section
) /* Match on a specific section. */
435 fixup_psymbol_section (p
, objfile
);
436 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (objfile
, p
),
440 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
445 for (pp
= objfile
->static_psymbols
.list
+ psymtab
->statics_offset
;
446 (pp
- (objfile
->static_psymbols
.list
+ psymtab
->statics_offset
)
447 < psymtab
->n_static_syms
);
451 if (SYMBOL_DOMAIN (p
) == VAR_DOMAIN
452 && PSYMBOL_CLASS (p
) == LOC_BLOCK
453 && pc
>= SYMBOL_VALUE_ADDRESS (p
)
454 && (SYMBOL_VALUE_ADDRESS (p
) > best_pc
455 || (psymtab
->textlow
== 0
456 && best_pc
== 0 && SYMBOL_VALUE_ADDRESS (p
) == 0)))
458 if (section
) /* Match on a specific section. */
460 fixup_psymbol_section (p
, objfile
);
461 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (objfile
, p
),
465 best_pc
= SYMBOL_VALUE_ADDRESS (p
);
474 fixup_psymbol_section (struct partial_symbol
*psym
, struct objfile
*objfile
)
481 if (SYMBOL_SECTION (psym
) >= 0)
484 gdb_assert (objfile
);
486 switch (PSYMBOL_CLASS (psym
))
491 addr
= SYMBOL_VALUE_ADDRESS (psym
);
494 /* Nothing else will be listed in the minsyms -- no use looking
499 fixup_section (&psym
->ginfo
, addr
, objfile
);
502 /* Psymtab version of lookup_symbol. See its definition in
503 the definition of quick_symbol_functions in symfile.h. */
505 static struct compunit_symtab
*
506 psym_lookup_symbol (struct objfile
*objfile
,
507 int block_index
, const char *name
,
508 const domain_enum domain
)
510 struct partial_symtab
*ps
;
511 const int psymtab_index
= (block_index
== GLOBAL_BLOCK
? 1 : 0);
512 struct compunit_symtab
*stab_best
= NULL
;
514 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
516 if (!ps
->readin
&& lookup_partial_symbol (objfile
, ps
, name
,
517 psymtab_index
, domain
))
519 struct symbol
*sym
= NULL
;
520 struct compunit_symtab
*stab
= psymtab_to_symtab (objfile
, ps
);
521 /* Note: While psymtab_to_symtab can return NULL if the partial symtab
522 is empty, we can assume it won't here because lookup_partial_symbol
524 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
525 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
527 /* Some caution must be observed with overloaded functions
528 and methods, since the psymtab will not contain any overload
529 information (but NAME might contain it). */
530 sym
= block_lookup_symbol (block
, name
, domain
);
532 if (sym
&& strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
534 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym
)))
540 /* Keep looking through other psymtabs. */
547 /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
548 the global block of PST if GLOBAL, and otherwise the static block.
549 MATCH is the comparison operation that returns true iff MATCH (s,
550 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
551 non-null, the symbols in the block are assumed to be ordered
552 according to it (allowing binary search). It must be compatible
553 with MATCH. Returns the symbol, if found, and otherwise NULL. */
555 static struct partial_symbol
*
556 match_partial_symbol (struct objfile
*objfile
,
557 struct partial_symtab
*pst
, int global
,
558 const char *name
, domain_enum domain
,
559 symbol_compare_ftype
*match
,
560 symbol_compare_ftype
*ordered_compare
)
562 struct partial_symbol
**start
, **psym
;
563 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
564 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
565 int do_linear_search
= 1;
570 objfile
->global_psymbols
.list
+ pst
->globals_offset
:
571 objfile
->static_psymbols
.list
+ pst
->statics_offset
);
573 if (global
&& ordered_compare
) /* Can use a binary search. */
575 do_linear_search
= 0;
577 /* Binary search. This search is guaranteed to end with center
578 pointing at the earliest partial symbol whose name might be
579 correct. At that point *all* partial symbols with an
580 appropriate name will be checked against the correct
584 top
= start
+ length
- 1;
588 center
= bottom
+ (top
- bottom
) / 2;
589 gdb_assert (center
< top
);
590 if (!do_linear_search
591 && (SYMBOL_LANGUAGE (*center
) == language_java
))
592 do_linear_search
= 1;
593 if (ordered_compare (SYMBOL_SEARCH_NAME (*center
), name
) >= 0)
598 gdb_assert (top
== bottom
);
600 while (top
<= real_top
601 && match (SYMBOL_SEARCH_NAME (*top
), name
) == 0)
603 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
604 SYMBOL_DOMAIN (*top
), domain
))
610 /* Can't use a binary search or else we found during the binary search that
611 we should also do a linear search. */
613 if (do_linear_search
)
615 for (psym
= start
; psym
< start
+ length
; psym
++)
617 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
618 SYMBOL_DOMAIN (*psym
), domain
)
619 && match (SYMBOL_SEARCH_NAME (*psym
), name
) == 0)
627 /* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
628 not contain any method/function instance information (since this would
629 force reading type information while reading psymtabs). Therefore,
630 if NAME contains overload information, it must be stripped before searching
633 The caller is responsible for freeing the return result. */
636 psymtab_search_name (const char *name
)
638 switch (current_language
->la_language
)
643 if (strchr (name
, '('))
645 char *ret
= cp_remove_params (name
);
657 return xstrdup (name
);
660 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
661 Check the global symbols if GLOBAL, the static symbols if not. */
663 static struct partial_symbol
*
664 lookup_partial_symbol (struct objfile
*objfile
,
665 struct partial_symtab
*pst
, const char *name
,
666 int global
, domain_enum domain
)
668 struct partial_symbol
**start
, **psym
;
669 struct partial_symbol
**top
, **real_top
, **bottom
, **center
;
670 int length
= (global
? pst
->n_global_syms
: pst
->n_static_syms
);
671 int do_linear_search
= 1;
673 struct cleanup
*cleanup
;
680 search_name
= psymtab_search_name (name
);
681 cleanup
= make_cleanup (xfree
, search_name
);
683 objfile
->global_psymbols
.list
+ pst
->globals_offset
:
684 objfile
->static_psymbols
.list
+ pst
->statics_offset
);
686 if (global
) /* This means we can use a binary search. */
688 do_linear_search
= 0;
690 /* Binary search. This search is guaranteed to end with center
691 pointing at the earliest partial symbol whose name might be
692 correct. At that point *all* partial symbols with an
693 appropriate name will be checked against the correct
697 top
= start
+ length
- 1;
701 center
= bottom
+ (top
- bottom
) / 2;
703 internal_error (__FILE__
, __LINE__
,
704 _("failed internal consistency check"));
705 if (!do_linear_search
706 && SYMBOL_LANGUAGE (*center
) == language_java
)
708 do_linear_search
= 1;
710 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center
),
720 if (!(top
== bottom
))
721 internal_error (__FILE__
, __LINE__
,
722 _("failed internal consistency check"));
724 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
725 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
726 while (top
>= start
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, search_name
))
729 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
732 while (top
<= real_top
&& SYMBOL_MATCHES_SEARCH_NAME (*top
, search_name
))
734 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top
),
735 SYMBOL_DOMAIN (*top
), domain
))
737 do_cleanups (cleanup
);
744 /* Can't use a binary search or else we found during the binary search that
745 we should also do a linear search. */
747 if (do_linear_search
)
749 for (psym
= start
; psym
< start
+ length
; psym
++)
751 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym
),
752 SYMBOL_DOMAIN (*psym
), domain
)
753 && SYMBOL_MATCHES_SEARCH_NAME (*psym
, search_name
))
755 do_cleanups (cleanup
);
761 do_cleanups (cleanup
);
765 /* Get the symbol table that corresponds to a partial_symtab.
766 This is fast after the first time you do it.
767 The result will be NULL if the primary symtab has no symbols,
768 which can happen. Otherwise the result is the primary symtab
769 that contains PST. */
771 static struct compunit_symtab
*
772 psymtab_to_symtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
774 /* If it is a shared psymtab, find an unshared psymtab that includes
775 it. Any such psymtab will do. */
776 while (pst
->user
!= NULL
)
779 /* If it's been looked up before, return it. */
780 if (pst
->compunit_symtab
)
781 return pst
->compunit_symtab
;
783 /* If it has not yet been read in, read it. */
786 struct cleanup
*back_to
= increment_reading_symtab ();
788 (*pst
->read_symtab
) (pst
, objfile
);
789 do_cleanups (back_to
);
792 return pst
->compunit_symtab
;
795 /* Psymtab version of relocate. See its definition in
796 the definition of quick_symbol_functions in symfile.h. */
799 psym_relocate (struct objfile
*objfile
,
800 const struct section_offsets
*new_offsets
,
801 const struct section_offsets
*delta
)
803 struct partial_symbol
**psym
;
804 struct partial_symtab
*p
;
806 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
808 p
->textlow
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
809 p
->texthigh
+= ANOFFSET (delta
, SECT_OFF_TEXT (objfile
));
812 for (psym
= objfile
->global_psymbols
.list
;
813 psym
< objfile
->global_psymbols
.next
;
816 fixup_psymbol_section (*psym
, objfile
);
817 if (SYMBOL_SECTION (*psym
) >= 0)
818 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
819 SYMBOL_SECTION (*psym
));
821 for (psym
= objfile
->static_psymbols
.list
;
822 psym
< objfile
->static_psymbols
.next
;
825 fixup_psymbol_section (*psym
, objfile
);
826 if (SYMBOL_SECTION (*psym
) >= 0)
827 SYMBOL_VALUE_ADDRESS (*psym
) += ANOFFSET (delta
,
828 SYMBOL_SECTION (*psym
));
832 /* Psymtab version of find_last_source_symtab. See its definition in
833 the definition of quick_symbol_functions in symfile.h. */
835 static struct symtab
*
836 psym_find_last_source_symtab (struct objfile
*ofp
)
838 struct partial_symtab
*ps
;
839 struct partial_symtab
*cs_pst
= 0;
841 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp
, ps
)
843 const char *name
= ps
->filename
;
844 int len
= strlen (name
);
846 if (!(len
> 2 && (strcmp (&name
[len
- 2], ".h") == 0
847 || strcmp (name
, "<<C++-namespaces>>") == 0)))
855 internal_error (__FILE__
, __LINE__
,
856 _("select_source_symtab: "
857 "readin pst found and no symtabs."));
861 struct compunit_symtab
*cust
= psymtab_to_symtab (ofp
, cs_pst
);
865 return compunit_primary_filetab (cust
);
871 /* Psymtab version of forget_cached_source_info. See its definition in
872 the definition of quick_symbol_functions in symfile.h. */
875 psym_forget_cached_source_info (struct objfile
*objfile
)
877 struct partial_symtab
*pst
;
879 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, pst
)
881 if (pst
->fullname
!= NULL
)
883 xfree (pst
->fullname
);
884 pst
->fullname
= NULL
;
890 print_partial_symbols (struct gdbarch
*gdbarch
,
891 struct partial_symbol
**p
, int count
, char *what
,
892 struct ui_file
*outfile
)
894 fprintf_filtered (outfile
, " %s partial symbols:\n", what
);
898 fprintf_filtered (outfile
, " `%s'", SYMBOL_LINKAGE_NAME (*p
));
899 if (SYMBOL_DEMANGLED_NAME (*p
) != NULL
)
901 fprintf_filtered (outfile
, " `%s'", SYMBOL_DEMANGLED_NAME (*p
));
903 fputs_filtered (", ", outfile
);
904 switch (SYMBOL_DOMAIN (*p
))
907 fputs_filtered ("undefined domain, ", outfile
);
910 /* This is the usual thing -- don't print it. */
913 fputs_filtered ("struct domain, ", outfile
);
916 fputs_filtered ("label domain, ", outfile
);
919 fputs_filtered ("<invalid domain>, ", outfile
);
922 switch (PSYMBOL_CLASS (*p
))
925 fputs_filtered ("undefined", outfile
);
928 fputs_filtered ("constant int", outfile
);
931 fputs_filtered ("static", outfile
);
934 fputs_filtered ("register", outfile
);
937 fputs_filtered ("pass by value", outfile
);
940 fputs_filtered ("pass by reference", outfile
);
942 case LOC_REGPARM_ADDR
:
943 fputs_filtered ("register address parameter", outfile
);
946 fputs_filtered ("stack parameter", outfile
);
949 fputs_filtered ("type", outfile
);
952 fputs_filtered ("label", outfile
);
955 fputs_filtered ("function", outfile
);
957 case LOC_CONST_BYTES
:
958 fputs_filtered ("constant bytes", outfile
);
961 fputs_filtered ("unresolved", outfile
);
963 case LOC_OPTIMIZED_OUT
:
964 fputs_filtered ("optimized out", outfile
);
967 fputs_filtered ("computed at runtime", outfile
);
970 fputs_filtered ("<invalid location>", outfile
);
973 fputs_filtered (", ", outfile
);
974 fputs_filtered (paddress (gdbarch
, SYMBOL_VALUE_ADDRESS (*p
)), outfile
);
975 fprintf_filtered (outfile
, "\n");
981 dump_psymtab (struct objfile
*objfile
, struct partial_symtab
*psymtab
,
982 struct ui_file
*outfile
)
984 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
987 if (psymtab
->anonymous
)
989 fprintf_filtered (outfile
, "\nAnonymous partial symtab (%s) ",
994 fprintf_filtered (outfile
, "\nPartial symtab for source file %s ",
997 fprintf_filtered (outfile
, "(object ");
998 gdb_print_host_address (psymtab
, outfile
);
999 fprintf_filtered (outfile
, ")\n\n");
1000 fprintf_unfiltered (outfile
, " Read from object file %s (",
1001 objfile_name (objfile
));
1002 gdb_print_host_address (objfile
, outfile
);
1003 fprintf_unfiltered (outfile
, ")\n");
1005 if (psymtab
->readin
)
1007 fprintf_filtered (outfile
,
1008 " Full symtab was read (at ");
1009 gdb_print_host_address (psymtab
->compunit_symtab
, outfile
);
1010 fprintf_filtered (outfile
, " by function at ");
1011 gdb_print_host_address (psymtab
->read_symtab
, outfile
);
1012 fprintf_filtered (outfile
, ")\n");
1015 fprintf_filtered (outfile
, " Relocate symbols by ");
1016 for (i
= 0; i
< objfile
->num_sections
; ++i
)
1019 fprintf_filtered (outfile
, ", ");
1021 fputs_filtered (paddress (gdbarch
,
1022 ANOFFSET (psymtab
->section_offsets
, i
)),
1025 fprintf_filtered (outfile
, "\n");
1027 fprintf_filtered (outfile
, " Symbols cover text addresses ");
1028 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
), outfile
);
1029 fprintf_filtered (outfile
, "-");
1030 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
), outfile
);
1031 fprintf_filtered (outfile
, "\n");
1032 fprintf_filtered (outfile
, " Address map supported - %s.\n",
1033 psymtab
->psymtabs_addrmap_supported
? "yes" : "no");
1034 fprintf_filtered (outfile
, " Depends on %d other partial symtabs.\n",
1035 psymtab
->number_of_dependencies
);
1036 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
1038 fprintf_filtered (outfile
, " %d ", i
);
1039 gdb_print_host_address (psymtab
->dependencies
[i
], outfile
);
1040 fprintf_filtered (outfile
, " %s\n",
1041 psymtab
->dependencies
[i
]->filename
);
1043 if (psymtab
->user
!= NULL
)
1045 fprintf_filtered (outfile
, " Shared partial symtab with user ");
1046 gdb_print_host_address (psymtab
->user
, outfile
);
1047 fprintf_filtered (outfile
, "\n");
1049 if (psymtab
->n_global_syms
> 0)
1051 print_partial_symbols (gdbarch
,
1052 objfile
->global_psymbols
.list
1053 + psymtab
->globals_offset
,
1054 psymtab
->n_global_syms
, "Global", outfile
);
1056 if (psymtab
->n_static_syms
> 0)
1058 print_partial_symbols (gdbarch
,
1059 objfile
->static_psymbols
.list
1060 + psymtab
->statics_offset
,
1061 psymtab
->n_static_syms
, "Static", outfile
);
1063 fprintf_filtered (outfile
, "\n");
1066 /* Psymtab version of print_stats. See its definition in
1067 the definition of quick_symbol_functions in symfile.h. */
1070 psym_print_stats (struct objfile
*objfile
)
1073 struct partial_symtab
*ps
;
1076 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1078 if (ps
->readin
== 0)
1081 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i
);
1084 /* Psymtab version of dump. See its definition in
1085 the definition of quick_symbol_functions in symfile.h. */
1088 psym_dump (struct objfile
*objfile
)
1090 struct partial_symtab
*psymtab
;
1092 if (objfile
->psymtabs
)
1094 printf_filtered ("Psymtabs:\n");
1095 for (psymtab
= objfile
->psymtabs
;
1097 psymtab
= psymtab
->next
)
1099 printf_filtered ("%s at ",
1101 gdb_print_host_address (psymtab
, gdb_stdout
);
1102 printf_filtered (", ");
1105 printf_filtered ("\n\n");
1109 /* Psymtab version of expand_symtabs_for_function. See its definition in
1110 the definition of quick_symbol_functions in symfile.h. */
1113 psym_expand_symtabs_for_function (struct objfile
*objfile
,
1114 const char *func_name
)
1116 struct partial_symtab
*ps
;
1118 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1123 if ((lookup_partial_symbol (objfile
, ps
, func_name
, 1, VAR_DOMAIN
)
1125 || (lookup_partial_symbol (objfile
, ps
, func_name
, 0, VAR_DOMAIN
)
1127 psymtab_to_symtab (objfile
, ps
);
1131 /* Psymtab version of expand_all_symtabs. See its definition in
1132 the definition of quick_symbol_functions in symfile.h. */
1135 psym_expand_all_symtabs (struct objfile
*objfile
)
1137 struct partial_symtab
*psymtab
;
1139 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1141 psymtab_to_symtab (objfile
, psymtab
);
1145 /* Psymtab version of expand_symtabs_with_fullname. See its definition in
1146 the definition of quick_symbol_functions in symfile.h. */
1149 psym_expand_symtabs_with_fullname (struct objfile
*objfile
,
1150 const char *fullname
)
1152 struct partial_symtab
*p
;
1154 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, p
)
1156 /* Anonymous psymtabs don't have a name of a source file. */
1160 /* psymtab_to_fullname tries to open the file which is slow.
1161 Don't call it if we know the basenames don't match. */
1162 if ((basenames_may_differ
1163 || filename_cmp (lbasename (fullname
), lbasename (p
->filename
)) == 0)
1164 && filename_cmp (fullname
, psymtab_to_fullname (p
)) == 0)
1165 psymtab_to_symtab (objfile
, p
);
1169 /* Psymtab version of map_symbol_filenames. See its definition in
1170 the definition of quick_symbol_functions in symfile.h. */
1173 psym_map_symbol_filenames (struct objfile
*objfile
,
1174 symbol_filename_ftype
*fun
, void *data
,
1177 struct partial_symtab
*ps
;
1179 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1181 const char *fullname
;
1186 /* We can skip shared psymtabs here, because any file name will be
1187 attached to the unshared psymtab. */
1188 if (ps
->user
!= NULL
)
1191 /* Anonymous psymtabs don't have a file name. */
1197 fullname
= psymtab_to_fullname (ps
);
1200 (*fun
) (ps
->filename
, fullname
, data
);
1204 /* Finds the fullname that a partial_symtab represents.
1206 If this functions finds the fullname, it will save it in ps->fullname
1207 and it will also return the value.
1209 If this function fails to find the file that this partial_symtab represents,
1210 NULL will be returned and ps->fullname will be set to NULL. */
1213 psymtab_to_fullname (struct partial_symtab
*ps
)
1215 gdb_assert (!ps
->anonymous
);
1217 /* Use cached copy if we have it.
1218 We rely on forget_cached_source_info being called appropriately
1219 to handle cases like the file being moved. */
1220 if (ps
->fullname
== NULL
)
1222 int fd
= find_and_open_source (ps
->filename
, ps
->dirname
, &ps
->fullname
);
1229 struct cleanup
*back_to
;
1231 /* rewrite_source_path would be applied by find_and_open_source, we
1232 should report the pathname where GDB tried to find the file. */
1234 if (ps
->dirname
== NULL
|| IS_ABSOLUTE_PATH (ps
->filename
))
1235 fullname
= xstrdup (ps
->filename
);
1237 fullname
= concat (ps
->dirname
, SLASH_STRING
, ps
->filename
, NULL
);
1239 back_to
= make_cleanup (xfree
, fullname
);
1240 ps
->fullname
= rewrite_source_path (fullname
);
1241 if (ps
->fullname
== NULL
)
1242 ps
->fullname
= xstrdup (fullname
);
1243 do_cleanups (back_to
);
1247 return ps
->fullname
;
1250 /* For all symbols, s, in BLOCK that are in DOMAIN and match NAME
1251 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1252 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1253 ever returns non-zero, and otherwise returns 0. */
1256 map_block (const char *name
, domain_enum domain
, struct objfile
*objfile
,
1257 struct block
*block
,
1258 int (*callback
) (struct block
*, struct symbol
*, void *),
1259 void *data
, symbol_compare_ftype
*match
)
1261 struct block_iterator iter
;
1264 for (sym
= block_iter_match_first (block
, name
, match
, &iter
);
1265 sym
!= NULL
; sym
= block_iter_match_next (name
, match
, &iter
))
1267 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym
),
1268 SYMBOL_DOMAIN (sym
), domain
))
1270 if (callback (block
, sym
, data
))
1278 /* Psymtab version of map_matching_symbols. See its definition in
1279 the definition of quick_symbol_functions in symfile.h. */
1282 psym_map_matching_symbols (struct objfile
*objfile
,
1283 const char *name
, domain_enum domain
,
1285 int (*callback
) (struct block
*,
1286 struct symbol
*, void *),
1288 symbol_compare_ftype
*match
,
1289 symbol_compare_ftype
*ordered_compare
)
1291 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
1292 struct partial_symtab
*ps
;
1294 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1298 || match_partial_symbol (objfile
, ps
, global
, name
, domain
, match
,
1301 struct compunit_symtab
*cust
= psymtab_to_symtab (objfile
, ps
);
1302 struct block
*block
;
1306 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
1307 if (map_block (name
, domain
, objfile
, block
,
1308 callback
, data
, match
))
1310 if (callback (block
, NULL
, data
))
1316 /* A helper for psym_expand_symtabs_matching that handles
1317 searching included psymtabs. This returns 1 if a symbol is found,
1318 and zero otherwise. It also updates the 'searched_flag' on the
1319 various psymtabs that it searches. */
1322 recursively_search_psymtabs (struct partial_symtab
*ps
,
1323 struct objfile
*objfile
,
1324 enum search_domain kind
,
1325 expand_symtabs_symbol_matcher_ftype
*sym_matcher
,
1328 struct partial_symbol
**psym
;
1329 struct partial_symbol
**bound
, **gbound
, **sbound
;
1331 int result
= PST_SEARCHED_AND_NOT_FOUND
;
1334 if (ps
->searched_flag
!= PST_NOT_SEARCHED
)
1335 return ps
->searched_flag
== PST_SEARCHED_AND_FOUND
;
1337 /* Recurse into shared psymtabs first, because they may have already
1338 been searched, and this could save some time. */
1339 for (i
= 0; i
< ps
->number_of_dependencies
; ++i
)
1343 /* Skip non-shared dependencies, these are handled elsewhere. */
1344 if (ps
->dependencies
[i
]->user
== NULL
)
1347 r
= recursively_search_psymtabs (ps
->dependencies
[i
],
1348 objfile
, kind
, sym_matcher
, data
);
1351 ps
->searched_flag
= PST_SEARCHED_AND_FOUND
;
1356 gbound
= (objfile
->global_psymbols
.list
1357 + ps
->globals_offset
+ ps
->n_global_syms
);
1358 sbound
= (objfile
->static_psymbols
.list
1359 + ps
->statics_offset
+ ps
->n_static_syms
);
1362 /* Go through all of the symbols stored in a partial
1363 symtab in one loop. */
1364 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
1369 if (bound
== gbound
&& ps
->n_static_syms
!= 0)
1371 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
1382 if ((kind
== ALL_DOMAIN
1383 || (kind
== VARIABLES_DOMAIN
1384 && PSYMBOL_CLASS (*psym
) != LOC_TYPEDEF
1385 && PSYMBOL_CLASS (*psym
) != LOC_BLOCK
)
1386 || (kind
== FUNCTIONS_DOMAIN
1387 && PSYMBOL_CLASS (*psym
) == LOC_BLOCK
)
1388 || (kind
== TYPES_DOMAIN
1389 && PSYMBOL_CLASS (*psym
) == LOC_TYPEDEF
))
1390 && (*sym_matcher
) (SYMBOL_SEARCH_NAME (*psym
), data
))
1392 /* Found a match, so notify our caller. */
1393 result
= PST_SEARCHED_AND_FOUND
;
1400 ps
->searched_flag
= result
;
1401 return result
== PST_SEARCHED_AND_FOUND
;
1404 /* Psymtab version of expand_symtabs_matching. See its definition in
1405 the definition of quick_symbol_functions in symfile.h. */
1408 psym_expand_symtabs_matching
1409 (struct objfile
*objfile
,
1410 expand_symtabs_file_matcher_ftype
*file_matcher
,
1411 expand_symtabs_symbol_matcher_ftype
*symbol_matcher
,
1412 expand_symtabs_exp_notify_ftype
*expansion_notify
,
1413 enum search_domain kind
,
1416 struct partial_symtab
*ps
;
1418 /* Clear the search flags. */
1419 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1421 ps
->searched_flag
= PST_NOT_SEARCHED
;
1424 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, ps
)
1431 /* We skip shared psymtabs because file-matching doesn't apply
1432 to them; but we search them later in the loop. */
1433 if (ps
->user
!= NULL
)
1443 match
= (*file_matcher
) (ps
->filename
, data
, 0);
1446 /* Before we invoke realpath, which can get expensive when many
1447 files are involved, do a quick comparison of the basenames. */
1448 if (basenames_may_differ
1449 || (*file_matcher
) (lbasename (ps
->filename
), data
, 1))
1450 match
= (*file_matcher
) (psymtab_to_fullname (ps
), data
, 0);
1456 if (recursively_search_psymtabs (ps
, objfile
, kind
, symbol_matcher
, data
))
1458 struct compunit_symtab
*symtab
=
1459 psymtab_to_symtab (objfile
, ps
);
1461 if (expansion_notify
!= NULL
)
1462 expansion_notify (symtab
, data
);
1467 /* Psymtab version of has_symbols. See its definition in
1468 the definition of quick_symbol_functions in symfile.h. */
1471 psym_has_symbols (struct objfile
*objfile
)
1473 return objfile
->psymtabs
!= NULL
;
1476 const struct quick_symbol_functions psym_functions
=
1479 psym_find_last_source_symtab
,
1480 psym_forget_cached_source_info
,
1481 psym_map_symtabs_matching_filename
,
1486 psym_expand_symtabs_for_function
,
1487 psym_expand_all_symtabs
,
1488 psym_expand_symtabs_with_fullname
,
1489 psym_map_matching_symbols
,
1490 psym_expand_symtabs_matching
,
1491 psym_find_pc_sect_compunit_symtab
,
1492 psym_map_symbol_filenames
1497 /* This compares two partial symbols by names, using strcmp_iw_ordered
1498 for the comparison. */
1501 compare_psymbols (const void *s1p
, const void *s2p
)
1503 struct partial_symbol
*const *s1
= s1p
;
1504 struct partial_symbol
*const *s2
= s2p
;
1506 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1
),
1507 SYMBOL_SEARCH_NAME (*s2
));
1511 sort_pst_symbols (struct objfile
*objfile
, struct partial_symtab
*pst
)
1513 /* Sort the global list; don't sort the static list. */
1515 qsort (objfile
->global_psymbols
.list
+ pst
->globals_offset
,
1516 pst
->n_global_syms
, sizeof (struct partial_symbol
*),
1520 /* Allocate and partially fill a partial symtab. It will be
1521 completely filled at the end of the symbol list.
1523 FILENAME is the name of the symbol-file we are reading from. */
1525 struct partial_symtab
*
1526 start_psymtab_common (struct objfile
*objfile
,
1527 struct section_offsets
*section_offsets
,
1528 const char *filename
,
1529 CORE_ADDR textlow
, struct partial_symbol
**global_syms
,
1530 struct partial_symbol
**static_syms
)
1532 struct partial_symtab
*psymtab
;
1534 psymtab
= allocate_psymtab (filename
, objfile
);
1535 psymtab
->section_offsets
= section_offsets
;
1536 psymtab
->textlow
= textlow
;
1537 psymtab
->texthigh
= psymtab
->textlow
; /* default */
1538 psymtab
->globals_offset
= global_syms
- objfile
->global_psymbols
.list
;
1539 psymtab
->statics_offset
= static_syms
- objfile
->static_psymbols
.list
;
1543 /* Calculate a hash code for the given partial symbol. The hash is
1544 calculated using the symbol's value, language, domain, class
1545 and name. These are the values which are set by
1546 add_psymbol_to_bcache. */
1548 static unsigned long
1549 psymbol_hash (const void *addr
, int length
)
1551 unsigned long h
= 0;
1552 struct partial_symbol
*psymbol
= (struct partial_symbol
*) addr
;
1553 unsigned int lang
= psymbol
->ginfo
.language
;
1554 unsigned int domain
= PSYMBOL_DOMAIN (psymbol
);
1555 unsigned int theclass
= PSYMBOL_CLASS (psymbol
);
1557 h
= hash_continue (&psymbol
->ginfo
.value
, sizeof (psymbol
->ginfo
.value
), h
);
1558 h
= hash_continue (&lang
, sizeof (unsigned int), h
);
1559 h
= hash_continue (&domain
, sizeof (unsigned int), h
);
1560 h
= hash_continue (&theclass
, sizeof (unsigned int), h
);
1561 h
= hash_continue (psymbol
->ginfo
.name
, strlen (psymbol
->ginfo
.name
), h
);
1566 /* Returns true if the symbol at addr1 equals the symbol at addr2.
1567 For the comparison this function uses a symbols value,
1568 language, domain, class and name. */
1571 psymbol_compare (const void *addr1
, const void *addr2
, int length
)
1573 struct partial_symbol
*sym1
= (struct partial_symbol
*) addr1
;
1574 struct partial_symbol
*sym2
= (struct partial_symbol
*) addr2
;
1576 return (memcmp (&sym1
->ginfo
.value
, &sym1
->ginfo
.value
,
1577 sizeof (sym1
->ginfo
.value
)) == 0
1578 && sym1
->ginfo
.language
== sym2
->ginfo
.language
1579 && PSYMBOL_DOMAIN (sym1
) == PSYMBOL_DOMAIN (sym2
)
1580 && PSYMBOL_CLASS (sym1
) == PSYMBOL_CLASS (sym2
)
1581 && sym1
->ginfo
.name
== sym2
->ginfo
.name
);
1584 /* Initialize a partial symbol bcache. */
1586 struct psymbol_bcache
*
1587 psymbol_bcache_init (void)
1589 struct psymbol_bcache
*bcache
= XCNEW (struct psymbol_bcache
);
1590 bcache
->bcache
= bcache_xmalloc (psymbol_hash
, psymbol_compare
);
1594 /* Free a partial symbol bcache. */
1596 psymbol_bcache_free (struct psymbol_bcache
*bcache
)
1601 bcache_xfree (bcache
->bcache
);
1605 /* Return the internal bcache of the psymbol_bcache BCACHE. */
1608 psymbol_bcache_get_bcache (struct psymbol_bcache
*bcache
)
1610 return bcache
->bcache
;
1613 /* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1614 symbol before, add a copy to BCACHE. In either case, return a pointer
1615 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1616 1 in case of new entry or 0 if returning an old entry. */
1618 static const struct partial_symbol
*
1619 psymbol_bcache_full (struct partial_symbol
*sym
,
1620 struct psymbol_bcache
*bcache
,
1623 return bcache_full (sym
,
1624 sizeof (struct partial_symbol
),
1629 /* Helper function, initialises partial symbol structure and stashes
1630 it into objfile's bcache. Note that our caching mechanism will
1631 use all fields of struct partial_symbol to determine hash value of the
1632 structure. In other words, having two symbols with the same name but
1633 different domain (or address) is possible and correct. */
1635 static const struct partial_symbol
*
1636 add_psymbol_to_bcache (const char *name
, int namelength
, int copy_name
,
1638 enum address_class theclass
,
1639 long val
, /* Value as a long */
1640 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1641 enum language language
, struct objfile
*objfile
,
1644 struct partial_symbol psymbol
;
1646 /* We must ensure that the entire struct has been zeroed before
1647 assigning to it, because an assignment may not touch some of the
1649 memset (&psymbol
, 0, sizeof (psymbol
));
1651 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
1654 SYMBOL_VALUE (&psymbol
) = val
;
1658 SYMBOL_VALUE_ADDRESS (&psymbol
) = coreaddr
;
1660 SYMBOL_SECTION (&psymbol
) = -1;
1661 SYMBOL_SET_LANGUAGE (&psymbol
, language
, &objfile
->objfile_obstack
);
1662 PSYMBOL_DOMAIN (&psymbol
) = domain
;
1663 PSYMBOL_CLASS (&psymbol
) = theclass
;
1665 SYMBOL_SET_NAMES (&psymbol
, name
, namelength
, copy_name
, objfile
);
1667 /* Stash the partial symbol away in the cache. */
1668 return psymbol_bcache_full (&psymbol
,
1669 objfile
->psymbol_cache
,
1673 /* Increase the space allocated for LISTP, which is probably
1674 global_psymbols or static_psymbols. This space will eventually
1675 be freed in free_objfile(). */
1678 extend_psymbol_list (struct psymbol_allocation_list
*listp
,
1679 struct objfile
*objfile
)
1683 if (listp
->size
== 0)
1686 listp
->list
= (struct partial_symbol
**)
1687 xmalloc (new_size
* sizeof (struct partial_symbol
*));
1691 new_size
= listp
->size
* 2;
1692 listp
->list
= (struct partial_symbol
**)
1693 xrealloc ((char *) listp
->list
,
1694 new_size
* sizeof (struct partial_symbol
*));
1696 /* Next assumes we only went one over. Should be good if
1697 program works correctly. */
1698 listp
->next
= listp
->list
+ listp
->size
;
1699 listp
->size
= new_size
;
1702 /* Helper function, adds partial symbol to the given partial symbol
1706 append_psymbol_to_list (struct psymbol_allocation_list
*list
,
1707 const struct partial_symbol
*psym
,
1708 struct objfile
*objfile
)
1710 if (list
->next
>= list
->list
+ list
->size
)
1711 extend_psymbol_list (list
, objfile
);
1712 *list
->next
++ = (struct partial_symbol
*) psym
;
1713 OBJSTAT (objfile
, n_psyms
++);
1716 /* Add a symbol with a long value to a psymtab.
1717 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1718 Return the partial symbol that has been added. */
1721 add_psymbol_to_list (const char *name
, int namelength
, int copy_name
,
1723 enum address_class theclass
,
1724 struct psymbol_allocation_list
*list
,
1725 long val
, /* Value as a long */
1726 CORE_ADDR coreaddr
, /* Value as a CORE_ADDR */
1727 enum language language
, struct objfile
*objfile
)
1729 const struct partial_symbol
*psym
;
1733 /* Stash the partial symbol away in the cache. */
1734 psym
= add_psymbol_to_bcache (name
, namelength
, copy_name
, domain
, theclass
,
1735 val
, coreaddr
, language
, objfile
, &added
);
1737 /* Do not duplicate global partial symbols. */
1738 if (list
== &objfile
->global_psymbols
1742 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1743 append_psymbol_to_list (list
, psym
, objfile
);
1746 /* Initialize storage for partial symbols. */
1749 init_psymbol_list (struct objfile
*objfile
, int total_symbols
)
1751 /* Free any previously allocated psymbol lists. */
1753 if (objfile
->global_psymbols
.list
)
1755 xfree (objfile
->global_psymbols
.list
);
1757 if (objfile
->static_psymbols
.list
)
1759 xfree (objfile
->static_psymbols
.list
);
1762 /* Current best guess is that approximately a twentieth
1763 of the total symbols (in a debugging file) are global or static
1764 oriented symbols, then multiply that by slop factor of two. */
1766 objfile
->global_psymbols
.size
= total_symbols
/ 10;
1767 objfile
->static_psymbols
.size
= total_symbols
/ 10;
1769 if (objfile
->global_psymbols
.size
> 0)
1771 objfile
->global_psymbols
.next
=
1772 objfile
->global_psymbols
.list
= (struct partial_symbol
**)
1773 xmalloc ((objfile
->global_psymbols
.size
1774 * sizeof (struct partial_symbol
*)));
1776 if (objfile
->static_psymbols
.size
> 0)
1778 objfile
->static_psymbols
.next
=
1779 objfile
->static_psymbols
.list
= (struct partial_symbol
**)
1780 xmalloc ((objfile
->static_psymbols
.size
1781 * sizeof (struct partial_symbol
*)));
1785 struct partial_symtab
*
1786 allocate_psymtab (const char *filename
, struct objfile
*objfile
)
1788 struct partial_symtab
*psymtab
;
1790 if (objfile
->free_psymtabs
)
1792 psymtab
= objfile
->free_psymtabs
;
1793 objfile
->free_psymtabs
= psymtab
->next
;
1796 psymtab
= (struct partial_symtab
*)
1797 obstack_alloc (&objfile
->objfile_obstack
,
1798 sizeof (struct partial_symtab
));
1800 memset (psymtab
, 0, sizeof (struct partial_symtab
));
1801 psymtab
->filename
= bcache (filename
, strlen (filename
) + 1,
1802 objfile
->per_bfd
->filename_cache
);
1803 psymtab
->compunit_symtab
= NULL
;
1805 /* Prepend it to the psymtab list for the objfile it belongs to.
1806 Psymtabs are searched in most recent inserted -> least recent
1809 psymtab
->next
= objfile
->psymtabs
;
1810 objfile
->psymtabs
= psymtab
;
1812 if (symtab_create_debug
)
1814 /* Be a bit clever with debugging messages, and don't print objfile
1815 every time, only when it changes. */
1816 static char *last_objfile_name
= NULL
;
1818 if (last_objfile_name
== NULL
1819 || strcmp (last_objfile_name
, objfile_name (objfile
)) != 0)
1821 xfree (last_objfile_name
);
1822 last_objfile_name
= xstrdup (objfile_name (objfile
));
1823 fprintf_unfiltered (gdb_stdlog
,
1824 "Creating one or more psymtabs for objfile %s ...\n",
1827 fprintf_unfiltered (gdb_stdlog
,
1828 "Created psymtab %s for module %s.\n",
1829 host_address_to_string (psymtab
), filename
);
1836 discard_psymtab (struct objfile
*objfile
, struct partial_symtab
*pst
)
1838 struct partial_symtab
**prev_pst
;
1841 Empty psymtabs happen as a result of header files which don't
1842 have any symbols in them. There can be a lot of them. But this
1843 check is wrong, in that a psymtab with N_SLINE entries but
1844 nothing else is not empty, but we don't realize that. Fixing
1845 that without slowing things down might be tricky. */
1847 /* First, snip it out of the psymtab chain. */
1849 prev_pst
= &(objfile
->psymtabs
);
1850 while ((*prev_pst
) != pst
)
1851 prev_pst
= &((*prev_pst
)->next
);
1852 (*prev_pst
) = pst
->next
;
1854 /* Next, put it on a free list for recycling. */
1856 pst
->next
= objfile
->free_psymtabs
;
1857 objfile
->free_psymtabs
= pst
;
1860 /* An object of this type is passed to discard_psymtabs_upto. */
1862 struct psymtab_state
1864 /* The objfile where psymtabs are discarded. */
1866 struct objfile
*objfile
;
1868 /* The first psymtab to save. */
1870 struct partial_symtab
*save
;
1873 /* A cleanup function used by make_cleanup_discard_psymtabs. */
1876 discard_psymtabs_upto (void *arg
)
1878 struct psymtab_state
*state
= arg
;
1880 while (state
->objfile
->psymtabs
!= state
->save
)
1881 discard_psymtab (state
->objfile
, state
->objfile
->psymtabs
);
1884 /* Return a new cleanup that discards all psymtabs created in OBJFILE
1885 after this function is called. */
1888 make_cleanup_discard_psymtabs (struct objfile
*objfile
)
1890 struct psymtab_state
*state
= XNEW (struct psymtab_state
);
1892 state
->objfile
= objfile
;
1893 state
->save
= objfile
->psymtabs
;
1895 return make_cleanup_dtor (discard_psymtabs_upto
, state
, xfree
);
1901 maintenance_print_psymbols (char *args
, int from_tty
)
1904 struct ui_file
*outfile
;
1905 struct cleanup
*cleanups
;
1906 char *symname
= NULL
;
1907 char *filename
= DEV_TTY
;
1908 struct objfile
*objfile
;
1909 struct partial_symtab
*ps
;
1916 print-psymbols takes an output file name and optional symbol file name"));
1918 argv
= gdb_buildargv (args
);
1919 cleanups
= make_cleanup_freeargv (argv
);
1921 if (argv
[0] != NULL
)
1924 /* If a second arg is supplied, it is a source file name to match on. */
1925 if (argv
[1] != NULL
)
1931 filename
= tilde_expand (filename
);
1932 make_cleanup (xfree
, filename
);
1934 outfile
= gdb_fopen (filename
, FOPEN_WT
);
1936 perror_with_name (filename
);
1937 make_cleanup_ui_file_delete (outfile
);
1939 ALL_PSYMTABS (objfile
, ps
)
1942 if (symname
== NULL
|| filename_cmp (symname
, ps
->filename
) == 0)
1943 dump_psymtab (objfile
, ps
, outfile
);
1945 do_cleanups (cleanups
);
1948 /* List all the partial symbol tables whose names match REGEXP (optional). */
1950 maintenance_info_psymtabs (char *regexp
, int from_tty
)
1952 struct program_space
*pspace
;
1953 struct objfile
*objfile
;
1958 ALL_PSPACES (pspace
)
1959 ALL_PSPACE_OBJFILES (pspace
, objfile
)
1961 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
1962 struct partial_symtab
*psymtab
;
1964 /* We don't want to print anything for this objfile until we
1965 actually find a symtab whose name matches. */
1966 int printed_objfile_start
= 0;
1968 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile
, psymtab
)
1973 || re_exec (psymtab
->filename
))
1975 if (! printed_objfile_start
)
1977 printf_filtered ("{ objfile %s ", objfile_name (objfile
));
1979 printf_filtered ("((struct objfile *) %s)\n",
1980 host_address_to_string (objfile
));
1981 printed_objfile_start
= 1;
1984 printf_filtered (" { psymtab %s ", psymtab
->filename
);
1986 printf_filtered ("((struct partial_symtab *) %s)\n",
1987 host_address_to_string (psymtab
));
1989 printf_filtered (" readin %s\n",
1990 psymtab
->readin
? "yes" : "no");
1991 printf_filtered (" fullname %s\n",
1993 ? psymtab
->fullname
: "(null)");
1994 printf_filtered (" text addresses ");
1995 fputs_filtered (paddress (gdbarch
, psymtab
->textlow
),
1997 printf_filtered (" -- ");
1998 fputs_filtered (paddress (gdbarch
, psymtab
->texthigh
),
2000 printf_filtered ("\n");
2001 printf_filtered (" psymtabs_addrmap_supported %s\n",
2002 (psymtab
->psymtabs_addrmap_supported
2004 printf_filtered (" globals ");
2005 if (psymtab
->n_global_syms
)
2007 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
2008 host_address_to_string (objfile
->global_psymbols
.list
2009 + psymtab
->globals_offset
),
2010 psymtab
->n_global_syms
);
2013 printf_filtered ("(none)\n");
2014 printf_filtered (" statics ");
2015 if (psymtab
->n_static_syms
)
2017 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
2018 host_address_to_string (objfile
->static_psymbols
.list
2019 + psymtab
->statics_offset
),
2020 psymtab
->n_static_syms
);
2023 printf_filtered ("(none)\n");
2024 printf_filtered (" dependencies ");
2025 if (psymtab
->number_of_dependencies
)
2029 printf_filtered ("{\n");
2030 for (i
= 0; i
< psymtab
->number_of_dependencies
; i
++)
2032 struct partial_symtab
*dep
= psymtab
->dependencies
[i
];
2034 /* Note the string concatenation there --- no comma. */
2035 printf_filtered (" psymtab %s "
2036 "((struct partial_symtab *) %s)\n",
2038 host_address_to_string (dep
));
2040 printf_filtered (" }\n");
2043 printf_filtered ("(none)\n");
2044 printf_filtered (" }\n");
2048 if (printed_objfile_start
)
2049 printf_filtered ("}\n");
2053 /* Check consistency of currently expanded psymtabs vs symtabs. */
2056 maintenance_check_psymtabs (char *ignore
, int from_tty
)
2059 struct partial_symbol
**psym
;
2060 struct compunit_symtab
*cust
= NULL
;
2061 struct partial_symtab
*ps
;
2062 const struct blockvector
*bv
;
2063 struct objfile
*objfile
;
2067 ALL_PSYMTABS (objfile
, ps
)
2069 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2071 /* We don't call psymtab_to_symtab here because that may cause symtab
2072 expansion. When debugging a problem it helps if checkers leave
2073 things unchanged. */
2074 cust
= ps
->compunit_symtab
;
2076 /* First do some checks that don't require the associated symtab. */
2077 if (ps
->texthigh
< ps
->textlow
)
2079 printf_filtered ("Psymtab ");
2080 puts_filtered (ps
->filename
);
2081 printf_filtered (" covers bad range ");
2082 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
2083 printf_filtered (" - ");
2084 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
2085 printf_filtered ("\n");
2089 /* Now do checks requiring the associated symtab. */
2092 bv
= COMPUNIT_BLOCKVECTOR (cust
);
2093 b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
2094 psym
= objfile
->static_psymbols
.list
+ ps
->statics_offset
;
2095 length
= ps
->n_static_syms
;
2098 sym
= block_lookup_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
2099 SYMBOL_DOMAIN (*psym
));
2102 printf_filtered ("Static symbol `");
2103 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
2104 printf_filtered ("' only found in ");
2105 puts_filtered (ps
->filename
);
2106 printf_filtered (" psymtab\n");
2110 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
2111 psym
= objfile
->global_psymbols
.list
+ ps
->globals_offset
;
2112 length
= ps
->n_global_syms
;
2115 sym
= block_lookup_symbol (b
, SYMBOL_LINKAGE_NAME (*psym
),
2116 SYMBOL_DOMAIN (*psym
));
2119 printf_filtered ("Global symbol `");
2120 puts_filtered (SYMBOL_LINKAGE_NAME (*psym
));
2121 printf_filtered ("' only found in ");
2122 puts_filtered (ps
->filename
);
2123 printf_filtered (" psymtab\n");
2127 if (ps
->texthigh
!= 0
2128 && (ps
->textlow
< BLOCK_START (b
) || ps
->texthigh
> BLOCK_END (b
)))
2130 printf_filtered ("Psymtab ");
2131 puts_filtered (ps
->filename
);
2132 printf_filtered (" covers ");
2133 fputs_filtered (paddress (gdbarch
, ps
->textlow
), gdb_stdout
);
2134 printf_filtered (" - ");
2135 fputs_filtered (paddress (gdbarch
, ps
->texthigh
), gdb_stdout
);
2136 printf_filtered (" but symtab covers only ");
2137 fputs_filtered (paddress (gdbarch
, BLOCK_START (b
)), gdb_stdout
);
2138 printf_filtered (" - ");
2139 fputs_filtered (paddress (gdbarch
, BLOCK_END (b
)), gdb_stdout
);
2140 printf_filtered ("\n");
2147 extern initialize_file_ftype _initialize_psymtab
;
2150 _initialize_psymtab (void)
2152 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
, _("\
2153 Print dump of current partial symbol definitions.\n\
2154 Entries in the partial symbol table are dumped to file OUTFILE.\n\
2155 If a SOURCE file is specified, dump only that file's partial symbols."),
2156 &maintenanceprintlist
);
2158 add_cmd ("psymtabs", class_maintenance
, maintenance_info_psymtabs
, _("\
2159 List the partial symbol tables for all object files.\n\
2160 This does not include information about individual partial symbols,\n\
2161 just the symbol table structures themselves."),
2162 &maintenanceinfolist
);
2164 add_cmd ("check-psymtabs", class_maintenance
, maintenance_check_psymtabs
,
2166 Check consistency of currently expanded psymtabs versus symtabs."),