gdb
[deliverable/binutils-gdb.git] / gdb / psymtab.c
CommitLineData
ccefe4c4
TT
1/* Partial symbol tables.
2
3 Copyright (C) 2009, 2010 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20#include "defs.h"
21#include "symtab.h"
22#include "psympriv.h"
23#include "objfiles.h"
24#include "gdb_assert.h"
25#include "block.h"
26#include "filenames.h"
27#include "source.h"
28#include "addrmap.h"
29#include "gdbtypes.h"
30#include "bcache.h"
31#include "ui-out.h"
32#include "command.h"
33#include "readline/readline.h"
34#include "gdb_regex.h"
35
36#ifndef DEV_TTY
37#define DEV_TTY "/dev/tty"
38#endif
39
40/* A fast way to get from a psymtab to its symtab (after the first time). */
41#define PSYMTAB_TO_SYMTAB(pst) \
42 ((pst) -> symtab != NULL ? (pst) -> symtab : psymtab_to_symtab (pst))
43
44/* Lookup a partial symbol. */
45static struct partial_symbol *lookup_partial_symbol (struct partial_symtab *,
46 const char *, int,
47 domain_enum);
48
49static char *psymtab_to_fullname (struct partial_symtab *ps);
50
51static struct partial_symbol *find_pc_sect_psymbol (struct partial_symtab *,
52 CORE_ADDR,
53 struct obj_section *);
54
55static struct partial_symbol *fixup_psymbol_section (struct partial_symbol
56 *psym,
57 struct objfile *objfile);
58
59static struct symtab *psymtab_to_symtab (struct partial_symtab *pst);
60
61/* Lookup the partial symbol table of a source file named NAME.
62 *If* there is no '/' in the name, a match after a '/'
63 in the psymtab filename will also work. */
64
65static struct partial_symtab *
66lookup_partial_symtab (struct objfile *objfile, const char *name,
67 const char *full_path, const char *real_path)
68{
69 struct partial_symtab *pst;
70
71 ALL_OBJFILE_PSYMTABS (objfile, pst)
72 {
73 if (FILENAME_CMP (name, pst->filename) == 0)
74 {
75 return (pst);
76 }
77
78 /* If the user gave us an absolute path, try to find the file in
79 this symtab and use its absolute path. */
80 if (full_path != NULL)
81 {
82 psymtab_to_fullname (pst);
83 if (pst->fullname != NULL
84 && FILENAME_CMP (full_path, pst->fullname) == 0)
85 {
86 return pst;
87 }
88 }
89
90 if (real_path != NULL)
91 {
92 char *rp = NULL;
93 psymtab_to_fullname (pst);
94 if (pst->fullname != NULL)
95 {
96 rp = gdb_realpath (pst->fullname);
97 make_cleanup (xfree, rp);
98 }
99 if (rp != NULL && FILENAME_CMP (real_path, rp) == 0)
100 {
101 return pst;
102 }
103 }
104 }
105
106 /* Now, search for a matching tail (only if name doesn't have any dirs) */
107
108 if (lbasename (name) == name)
109 ALL_OBJFILE_PSYMTABS (objfile, pst)
110 {
111 if (FILENAME_CMP (lbasename (pst->filename), name) == 0)
112 return (pst);
113 }
114
115 return (NULL);
116}
117
118static int
119lookup_symtab_via_partial_symtab (struct objfile *objfile, const char *name,
120 const char *full_path, const char *real_path,
121 struct symtab **result)
122{
123 struct partial_symtab *ps;
124
125 ps = lookup_partial_symtab (objfile, name, full_path, real_path);
126 if (!ps)
127 return 0;
128
129 if (ps->readin)
130 error (_("Internal: readin %s pst for `%s' found when no symtab found."),
131 ps->filename, name);
132
133 *result = PSYMTAB_TO_SYMTAB (ps);
134 return 1;
135}
136
137/* Find which partial symtab contains PC and SECTION starting at psymtab PST.
138 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
139
140static struct partial_symtab *
141find_pc_sect_psymtab_closer (CORE_ADDR pc, struct obj_section *section,
142 struct partial_symtab *pst,
143 struct minimal_symbol *msymbol)
144{
145 struct objfile *objfile = pst->objfile;
146 struct partial_symtab *tpst;
147 struct partial_symtab *best_pst = pst;
148 CORE_ADDR best_addr = pst->textlow;
149
150 /* An objfile that has its functions reordered might have
151 many partial symbol tables containing the PC, but
152 we want the partial symbol table that contains the
153 function containing the PC. */
154 if (!(objfile->flags & OBJF_REORDERED) &&
155 section == 0) /* can't validate section this way */
156 return pst;
157
158 if (msymbol == NULL)
159 return (pst);
160
161 /* The code range of partial symtabs sometimes overlap, so, in
162 the loop below, we need to check all partial symtabs and
163 find the one that fits better for the given PC address. We
164 select the partial symtab that contains a symbol whose
165 address is closest to the PC address. By closest we mean
166 that find_pc_sect_symbol returns the symbol with address
167 that is closest and still less than the given PC. */
168 for (tpst = pst; tpst != NULL; tpst = tpst->next)
169 {
170 if (pc >= tpst->textlow && pc < tpst->texthigh)
171 {
172 struct partial_symbol *p;
173 CORE_ADDR this_addr;
174
175 /* NOTE: This assumes that every psymbol has a
176 corresponding msymbol, which is not necessarily
177 true; the debug info might be much richer than the
178 object's symbol table. */
179 p = find_pc_sect_psymbol (tpst, pc, section);
180 if (p != NULL
181 && SYMBOL_VALUE_ADDRESS (p)
182 == SYMBOL_VALUE_ADDRESS (msymbol))
183 return tpst;
184
185 /* Also accept the textlow value of a psymtab as a
186 "symbol", to provide some support for partial
187 symbol tables with line information but no debug
188 symbols (e.g. those produced by an assembler). */
189 if (p != NULL)
190 this_addr = SYMBOL_VALUE_ADDRESS (p);
191 else
192 this_addr = tpst->textlow;
193
194 /* Check whether it is closer than our current
195 BEST_ADDR. Since this symbol address is
196 necessarily lower or equal to PC, the symbol closer
197 to PC is the symbol which address is the highest.
198 This way we return the psymtab which contains such
199 best match symbol. This can help in cases where the
200 symbol information/debuginfo is not complete, like
201 for instance on IRIX6 with gcc, where no debug info
202 is emitted for statics. (See also the nodebug.exp
203 testcase.) */
204 if (this_addr > best_addr)
205 {
206 best_addr = this_addr;
207 best_pst = tpst;
208 }
209 }
210 }
211 return best_pst;
212}
213
214/* Find which partial symtab contains PC and SECTION. Return 0 if
215 none. We return the psymtab that contains a symbol whose address
216 exactly matches PC, or, if we cannot find an exact match, the
217 psymtab that contains a symbol whose address is closest to PC. */
218static struct partial_symtab *
219find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
220 struct obj_section *section,
221 struct minimal_symbol *msymbol)
222{
223 struct partial_symtab *pst;
224
225 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
226 than the later used TEXTLOW/TEXTHIGH one. */
227
228 if (objfile->psymtabs_addrmap != NULL)
229 {
230 pst = addrmap_find (objfile->psymtabs_addrmap, pc);
231 if (pst != NULL)
232 {
233 /* FIXME: addrmaps currently do not handle overlayed sections,
234 so fall back to the non-addrmap case if we're debugging
235 overlays and the addrmap returned the wrong section. */
236 if (overlay_debugging && msymbol && section)
237 {
238 struct partial_symbol *p;
239 /* NOTE: This assumes that every psymbol has a
240 corresponding msymbol, which is not necessarily
241 true; the debug info might be much richer than the
242 object's symbol table. */
243 p = find_pc_sect_psymbol (pst, pc, section);
244 if (!p
245 || SYMBOL_VALUE_ADDRESS (p)
246 != SYMBOL_VALUE_ADDRESS (msymbol))
247 goto next;
248 }
249
250 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
251 PSYMTABS_ADDRMAP we used has already the best 1-byte
252 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
253 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
254 overlap. */
255
256 return pst;
257 }
258 }
259
260 next:
261
262 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
263 which still have no corresponding full SYMTABs read. But it is not
264 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
265 so far. */
266
267 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
268 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
269 debug info type in single OBJFILE. */
270
271 ALL_OBJFILE_PSYMTABS (objfile, pst)
272 if (pc >= pst->textlow && pc < pst->texthigh)
273 {
274 struct partial_symtab *best_pst;
275
276 best_pst = find_pc_sect_psymtab_closer (pc, section, pst, msymbol);
277 if (best_pst != NULL)
278 return best_pst;
279 }
280
281 return NULL;
282}
283
284static struct symtab *
285find_pc_sect_symtab_from_partial (struct objfile *objfile,
286 struct minimal_symbol *msymbol,
287 CORE_ADDR pc, struct obj_section *section,
288 int warn_if_readin)
289{
290 struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
291 msymbol);
292 if (ps)
293 {
294 if (warn_if_readin && ps->readin)
295 /* Might want to error() here (in case symtab is corrupt and
296 will cause a core dump), but maybe we can successfully
297 continue, so let's not. */
298 warning (_("\
299(Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
300 paddress (get_objfile_arch (ps->objfile), pc));
301 return PSYMTAB_TO_SYMTAB (ps);
302 }
303 return NULL;
304}
305
306/* Find which partial symbol within a psymtab matches PC and SECTION.
307 Return 0 if none. */
308
309static struct partial_symbol *
310find_pc_sect_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc,
311 struct obj_section *section)
312{
313 struct partial_symbol *best = NULL, *p, **pp;
314 CORE_ADDR best_pc;
315
316 gdb_assert (psymtab != NULL);
317
318 /* Cope with programs that start at address 0 */
319 best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
320
321 /* Search the global symbols as well as the static symbols, so that
322 find_pc_partial_function doesn't use a minimal symbol and thus
323 cache a bad endaddr. */
324 for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
325 (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
326 < psymtab->n_global_syms);
327 pp++)
328 {
329 p = *pp;
330 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
331 && SYMBOL_CLASS (p) == LOC_BLOCK
332 && pc >= SYMBOL_VALUE_ADDRESS (p)
333 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
334 || (psymtab->textlow == 0
335 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
336 {
337 if (section) /* match on a specific section */
338 {
339 fixup_psymbol_section (p, psymtab->objfile);
340 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
341 continue;
342 }
343 best_pc = SYMBOL_VALUE_ADDRESS (p);
344 best = p;
345 }
346 }
347
348 for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
349 (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
350 < psymtab->n_static_syms);
351 pp++)
352 {
353 p = *pp;
354 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
355 && SYMBOL_CLASS (p) == LOC_BLOCK
356 && pc >= SYMBOL_VALUE_ADDRESS (p)
357 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
358 || (psymtab->textlow == 0
359 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
360 {
361 if (section) /* match on a specific section */
362 {
363 fixup_psymbol_section (p, psymtab->objfile);
364 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
365 continue;
366 }
367 best_pc = SYMBOL_VALUE_ADDRESS (p);
368 best = p;
369 }
370 }
371
372 return best;
373}
374
375static struct partial_symbol *
376fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
377{
378 CORE_ADDR addr;
379
380 if (!psym)
381 return NULL;
382
383 if (SYMBOL_OBJ_SECTION (psym))
384 return psym;
385
386 gdb_assert (objfile);
387
388 switch (SYMBOL_CLASS (psym))
389 {
390 case LOC_STATIC:
391 case LOC_LABEL:
392 case LOC_BLOCK:
393 addr = SYMBOL_VALUE_ADDRESS (psym);
394 break;
395 default:
396 /* Nothing else will be listed in the minsyms -- no use looking
397 it up. */
398 return psym;
399 }
400
401 fixup_section (&psym->ginfo, addr, objfile);
402
403 return psym;
404}
405
406static struct symtab *
407lookup_symbol_aux_psymtabs (struct objfile *objfile,
408 int block_index, const char *name,
409 const domain_enum domain)
410{
411 struct partial_symtab *ps;
412 const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
413
414 ALL_OBJFILE_PSYMTABS (objfile, ps)
415 {
416 if (!ps->readin && lookup_partial_symbol (ps, name, psymtab_index, domain))
417 return PSYMTAB_TO_SYMTAB (ps);
418 }
419
420 return NULL;
421}
422
423/* Look, in partial_symtab PST, for symbol whose natural name is NAME.
424 Check the global symbols if GLOBAL, the static symbols if not. */
425
426struct partial_symbol *
427lookup_partial_symbol (struct partial_symtab *pst, const char *name,
428 int global, domain_enum domain)
429{
430 struct partial_symbol *temp;
431 struct partial_symbol **start, **psym;
432 struct partial_symbol **top, **real_top, **bottom, **center;
433 int length = (global ? pst->n_global_syms : pst->n_static_syms);
434 int do_linear_search = 1;
435
436 if (length == 0)
437 {
438 return (NULL);
439 }
440 start = (global ?
441 pst->objfile->global_psymbols.list + pst->globals_offset :
442 pst->objfile->static_psymbols.list + pst->statics_offset);
443
444 if (global) /* This means we can use a binary search. */
445 {
446 do_linear_search = 0;
447
448 /* Binary search. This search is guaranteed to end with center
449 pointing at the earliest partial symbol whose name might be
450 correct. At that point *all* partial symbols with an
451 appropriate name will be checked against the correct
452 domain. */
453
454 bottom = start;
455 top = start + length - 1;
456 real_top = top;
457 while (top > bottom)
458 {
459 center = bottom + (top - bottom) / 2;
460 if (!(center < top))
461 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
462 if (!do_linear_search
463 && (SYMBOL_LANGUAGE (*center) == language_java))
464 {
465 do_linear_search = 1;
466 }
467 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center), name) >= 0)
468 {
469 top = center;
470 }
471 else
472 {
473 bottom = center + 1;
474 }
475 }
476 if (!(top == bottom))
477 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
478
479 while (top <= real_top
480 && SYMBOL_MATCHES_SEARCH_NAME (*top, name))
481 {
482 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
483 SYMBOL_DOMAIN (*top), domain))
484 return (*top);
485 top++;
486 }
487 }
488
489 /* Can't use a binary search or else we found during the binary search that
490 we should also do a linear search. */
491
492 if (do_linear_search)
493 {
494 for (psym = start; psym < start + length; psym++)
495 {
496 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
497 SYMBOL_DOMAIN (*psym), domain)
498 && SYMBOL_MATCHES_SEARCH_NAME (*psym, name))
499 return (*psym);
500 }
501 }
502
503 return (NULL);
504}
505
506/* Get the symbol table that corresponds to a partial_symtab.
507 This is fast after the first time you do it. In fact, there
508 is an even faster macro PSYMTAB_TO_SYMTAB that does the fast
509 case inline. */
510
511static struct symtab *
512psymtab_to_symtab (struct partial_symtab *pst)
513{
514 /* If it's been looked up before, return it. */
515 if (pst->symtab)
516 return pst->symtab;
517
518 /* If it has not yet been read in, read it. */
519 if (!pst->readin)
520 {
521 struct cleanup *back_to = increment_reading_symtab ();
522 (*pst->read_symtab) (pst);
523 do_cleanups (back_to);
524 }
525
526 return pst->symtab;
527}
528
529static void
530relocate_psymtabs (struct objfile *objfile,
531 struct section_offsets *new_offsets,
532 struct section_offsets *delta)
533{
534 struct partial_symbol **psym;
535 struct partial_symtab *p;
536
537 ALL_OBJFILE_PSYMTABS (objfile, p)
538 {
539 p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
540 p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
541 }
542
543 for (psym = objfile->global_psymbols.list;
544 psym < objfile->global_psymbols.next;
545 psym++)
546 {
547 fixup_psymbol_section (*psym, objfile);
548 if (SYMBOL_SECTION (*psym) >= 0)
549 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
550 SYMBOL_SECTION (*psym));
551 }
552 for (psym = objfile->static_psymbols.list;
553 psym < objfile->static_psymbols.next;
554 psym++)
555 {
556 fixup_psymbol_section (*psym, objfile);
557 if (SYMBOL_SECTION (*psym) >= 0)
558 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
559 SYMBOL_SECTION (*psym));
560 }
561}
562
563static struct symtab *
564find_last_source_symtab_from_partial (struct objfile *ofp)
565{
566 struct symtab *result;
567 struct partial_symtab *ps;
568 struct partial_symtab *cs_pst = 0;
569
570 ALL_OBJFILE_PSYMTABS (ofp, ps)
571 {
572 const char *name = ps->filename;
573 int len = strlen (name);
574 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
575 || strcmp (name, "<<C++-namespaces>>") == 0)))
576 cs_pst = ps;
577 }
578
579 if (cs_pst)
580 {
581 if (cs_pst->readin)
582 {
583 internal_error (__FILE__, __LINE__,
584 _("select_source_symtab: "
585 "readin pst found and no symtabs."));
586 }
587 else
588 return PSYMTAB_TO_SYMTAB (cs_pst);
589 }
590 return NULL;
591}
592
593static void
594forget_cached_source_info_partial (struct objfile *objfile)
595{
596 struct partial_symtab *pst;
597
598 ALL_OBJFILE_PSYMTABS (objfile, pst)
599 {
600 if (pst->fullname != NULL)
601 {
602 xfree (pst->fullname);
603 pst->fullname = NULL;
604 }
605 }
606}
607
608static void
609print_partial_symbols (struct gdbarch *gdbarch,
610 struct partial_symbol **p, int count, char *what,
611 struct ui_file *outfile)
612{
613 fprintf_filtered (outfile, " %s partial symbols:\n", what);
614 while (count-- > 0)
615 {
616 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
617 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
618 {
619 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
620 }
621 fputs_filtered (", ", outfile);
622 switch (SYMBOL_DOMAIN (*p))
623 {
624 case UNDEF_DOMAIN:
625 fputs_filtered ("undefined domain, ", outfile);
626 break;
627 case VAR_DOMAIN:
628 /* This is the usual thing -- don't print it */
629 break;
630 case STRUCT_DOMAIN:
631 fputs_filtered ("struct domain, ", outfile);
632 break;
633 case LABEL_DOMAIN:
634 fputs_filtered ("label domain, ", outfile);
635 break;
636 default:
637 fputs_filtered ("<invalid domain>, ", outfile);
638 break;
639 }
640 switch (SYMBOL_CLASS (*p))
641 {
642 case LOC_UNDEF:
643 fputs_filtered ("undefined", outfile);
644 break;
645 case LOC_CONST:
646 fputs_filtered ("constant int", outfile);
647 break;
648 case LOC_STATIC:
649 fputs_filtered ("static", outfile);
650 break;
651 case LOC_REGISTER:
652 fputs_filtered ("register", outfile);
653 break;
654 case LOC_ARG:
655 fputs_filtered ("pass by value", outfile);
656 break;
657 case LOC_REF_ARG:
658 fputs_filtered ("pass by reference", outfile);
659 break;
660 case LOC_REGPARM_ADDR:
661 fputs_filtered ("register address parameter", outfile);
662 break;
663 case LOC_LOCAL:
664 fputs_filtered ("stack parameter", outfile);
665 break;
666 case LOC_TYPEDEF:
667 fputs_filtered ("type", outfile);
668 break;
669 case LOC_LABEL:
670 fputs_filtered ("label", outfile);
671 break;
672 case LOC_BLOCK:
673 fputs_filtered ("function", outfile);
674 break;
675 case LOC_CONST_BYTES:
676 fputs_filtered ("constant bytes", outfile);
677 break;
678 case LOC_UNRESOLVED:
679 fputs_filtered ("unresolved", outfile);
680 break;
681 case LOC_OPTIMIZED_OUT:
682 fputs_filtered ("optimized out", outfile);
683 break;
684 case LOC_COMPUTED:
685 fputs_filtered ("computed at runtime", outfile);
686 break;
687 default:
688 fputs_filtered ("<invalid location>", outfile);
689 break;
690 }
691 fputs_filtered (", ", outfile);
692 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
693 fprintf_filtered (outfile, "\n");
694 p++;
695 }
696}
697
698static void
699dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
700 struct ui_file *outfile)
701{
702 struct gdbarch *gdbarch = get_objfile_arch (objfile);
703 int i;
704
705 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
706 psymtab->filename);
707 fprintf_filtered (outfile, "(object ");
708 gdb_print_host_address (psymtab, outfile);
709 fprintf_filtered (outfile, ")\n\n");
710 fprintf_unfiltered (outfile, " Read from object file %s (",
711 objfile->name);
712 gdb_print_host_address (objfile, outfile);
713 fprintf_unfiltered (outfile, ")\n");
714
715 if (psymtab->readin)
716 {
717 fprintf_filtered (outfile,
718 " Full symtab was read (at ");
719 gdb_print_host_address (psymtab->symtab, outfile);
720 fprintf_filtered (outfile, " by function at ");
721 gdb_print_host_address (psymtab->read_symtab, outfile);
722 fprintf_filtered (outfile, ")\n");
723 }
724
725 fprintf_filtered (outfile, " Relocate symbols by ");
726 for (i = 0; i < psymtab->objfile->num_sections; ++i)
727 {
728 if (i != 0)
729 fprintf_filtered (outfile, ", ");
730 wrap_here (" ");
731 fputs_filtered (paddress (gdbarch,
732 ANOFFSET (psymtab->section_offsets, i)),
733 outfile);
734 }
735 fprintf_filtered (outfile, "\n");
736
737 fprintf_filtered (outfile, " Symbols cover text addresses ");
738 fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
739 fprintf_filtered (outfile, "-");
740 fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
741 fprintf_filtered (outfile, "\n");
742 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
743 psymtab->number_of_dependencies);
744 for (i = 0; i < psymtab->number_of_dependencies; i++)
745 {
746 fprintf_filtered (outfile, " %d ", i);
747 gdb_print_host_address (psymtab->dependencies[i], outfile);
748 fprintf_filtered (outfile, " %s\n",
749 psymtab->dependencies[i]->filename);
750 }
751 if (psymtab->n_global_syms > 0)
752 {
753 print_partial_symbols (gdbarch,
754 objfile->global_psymbols.list
755 + psymtab->globals_offset,
756 psymtab->n_global_syms, "Global", outfile);
757 }
758 if (psymtab->n_static_syms > 0)
759 {
760 print_partial_symbols (gdbarch,
761 objfile->static_psymbols.list
762 + psymtab->statics_offset,
763 psymtab->n_static_syms, "Static", outfile);
764 }
765 fprintf_filtered (outfile, "\n");
766}
767
768static void
769print_psymtab_stats_for_objfile (struct objfile *objfile)
770{
771 int i;
772 struct partial_symtab *ps;
773 i = 0;
774 ALL_OBJFILE_PSYMTABS (objfile, ps)
775 {
776 if (ps->readin == 0)
777 i++;
778 }
779 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
780}
781
782static void
783dump_psymtabs_for_objfile (struct objfile *objfile)
784{
785 struct partial_symtab *psymtab;
786
787 if (objfile->psymtabs)
788 {
789 printf_filtered ("Psymtabs:\n");
790 for (psymtab = objfile->psymtabs;
791 psymtab != NULL;
792 psymtab = psymtab->next)
793 {
794 printf_filtered ("%s at ",
795 psymtab->filename);
796 gdb_print_host_address (psymtab, gdb_stdout);
797 printf_filtered (", ");
798 if (psymtab->objfile != objfile)
799 {
800 printf_filtered ("NOT ON CHAIN! ");
801 }
802 wrap_here (" ");
803 }
804 printf_filtered ("\n\n");
805 }
806}
807
808/* Look through the partial symtabs for all symbols which begin
809 by matching FUNC_NAME. Make sure we read that symbol table in. */
810
811static void
812read_symtabs_for_function (struct objfile *objfile, const char *func_name)
813{
814 struct partial_symtab *ps;
815
816 ALL_OBJFILE_PSYMTABS (objfile, ps)
817 {
818 if (ps->readin)
819 continue;
820
821 if ((lookup_partial_symbol (ps, func_name, 1, VAR_DOMAIN)
822 != NULL)
823 || (lookup_partial_symbol (ps, func_name, 0, VAR_DOMAIN)
824 != NULL))
825 psymtab_to_symtab (ps);
826 }
827}
828
829static void
830expand_partial_symbol_tables (struct objfile *objfile)
831{
832 struct partial_symtab *psymtab;
833
834 for (psymtab = objfile->psymtabs;
835 psymtab != NULL;
836 psymtab = psymtab->next)
837 {
838 psymtab_to_symtab (psymtab);
839 }
840}
841
842static void
843read_psymtabs_with_filename (struct objfile *objfile, const char *filename)
844{
845 struct partial_symtab *p;
846
847 ALL_OBJFILE_PSYMTABS (objfile, p)
848 {
849 if (strcmp (filename, p->filename) == 0)
850 PSYMTAB_TO_SYMTAB (p);
851 }
852}
853
854static void
855map_symbol_names_psymtab (struct objfile *objfile,
856 void (*fun) (const char *, void *), void *data)
857{
858 struct partial_symtab *ps;
859 ALL_OBJFILE_PSYMTABS (objfile, ps)
860 {
861 struct partial_symbol **psym;
862
863 /* If the psymtab's been read in we'll get it when we search
864 through the blockvector. */
865 if (ps->readin)
866 continue;
867
868 for (psym = objfile->global_psymbols.list + ps->globals_offset;
869 psym < (objfile->global_psymbols.list + ps->globals_offset
870 + ps->n_global_syms);
871 psym++)
872 {
873 /* If interrupted, then quit. */
874 QUIT;
875 (*fun) (SYMBOL_NATURAL_NAME (*psym), data);
876 }
877
878 for (psym = objfile->static_psymbols.list + ps->statics_offset;
879 psym < (objfile->static_psymbols.list + ps->statics_offset
880 + ps->n_static_syms);
881 psym++)
882 {
883 QUIT;
884 (*fun) (SYMBOL_NATURAL_NAME (*psym), data);
885 }
886 }
887}
888
889static void
890map_symbol_filenames_psymtab (struct objfile *objfile,
891 void (*fun) (const char *, const char *,
892 void *),
893 void *data)
894{
895 struct partial_symtab *ps;
896
897 ALL_OBJFILE_PSYMTABS (objfile, ps)
898 {
899 const char *fullname;
900
901 if (ps->readin)
902 continue;
903
904 fullname = psymtab_to_fullname (ps);
905 (*fun) (fullname, ps->filename, data);
906 }
907}
908
909int find_and_open_source (const char *filename,
910 const char *dirname,
911 char **fullname);
912
913/* Finds the fullname that a partial_symtab represents.
914
915 If this functions finds the fullname, it will save it in ps->fullname
916 and it will also return the value.
917
918 If this function fails to find the file that this partial_symtab represents,
919 NULL will be returned and ps->fullname will be set to NULL. */
920static char *
921psymtab_to_fullname (struct partial_symtab *ps)
922{
923 int r;
924
925 if (!ps)
926 return NULL;
927
928 /* Don't check ps->fullname here, the file could have been
929 deleted/moved/..., look for it again */
930 r = find_and_open_source (ps->filename, ps->dirname, &ps->fullname);
931
932 if (r >= 0)
933 {
934 close (r);
935 return ps->fullname;
936 }
937
938 return NULL;
939}
940
941static char *
942find_symbol_file_from_partial (struct objfile *objfile, const char *name)
943{
944 struct partial_symtab *pst;
945
946 ALL_OBJFILE_PSYMTABS (objfile, pst)
947 {
948 if (lookup_partial_symbol (pst, name, 1, VAR_DOMAIN))
949 return pst->filename;
950 }
951 return NULL;
952}
953
954/* Look, in partial_symtab PST, for symbol NAME in given namespace.
955 Check the global symbols if GLOBAL, the static symbols if not.
956 Do wild-card match if WILD. */
957
958static struct partial_symbol *
959ada_lookup_partial_symbol (struct partial_symtab *pst, const char *name,
960 int global, domain_enum namespace, int wild,
961 int (*wild_match) (const char *, int, const char *),
962 int (*is_name_suffix) (const char *))
963{
964 struct partial_symbol **start;
965 int name_len = strlen (name);
966 int length = (global ? pst->n_global_syms : pst->n_static_syms);
967 int i;
968
969 if (length == 0)
970 {
971 return (NULL);
972 }
973
974 start = (global ?
975 pst->objfile->global_psymbols.list + pst->globals_offset :
976 pst->objfile->static_psymbols.list + pst->statics_offset);
977
978 if (wild)
979 {
980 for (i = 0; i < length; i += 1)
981 {
982 struct partial_symbol *psym = start[i];
983
984 if (symbol_matches_domain (SYMBOL_LANGUAGE (psym),
985 SYMBOL_DOMAIN (psym), namespace)
986 && (*wild_match) (name, name_len, SYMBOL_LINKAGE_NAME (psym)))
987 return psym;
988 }
989 return NULL;
990 }
991 else
992 {
993 if (global)
994 {
995 int U;
996 i = 0;
997 U = length - 1;
998 while (U - i > 4)
999 {
1000 int M = (U + i) >> 1;
1001 struct partial_symbol *psym = start[M];
1002 if (SYMBOL_LINKAGE_NAME (psym)[0] < name[0])
1003 i = M + 1;
1004 else if (SYMBOL_LINKAGE_NAME (psym)[0] > name[0])
1005 U = M - 1;
1006 else if (strcmp (SYMBOL_LINKAGE_NAME (psym), name) < 0)
1007 i = M + 1;
1008 else
1009 U = M;
1010 }
1011 }
1012 else
1013 i = 0;
1014
1015 while (i < length)
1016 {
1017 struct partial_symbol *psym = start[i];
1018
1019 if (symbol_matches_domain (SYMBOL_LANGUAGE (psym),
1020 SYMBOL_DOMAIN (psym), namespace))
1021 {
1022 int cmp = strncmp (name, SYMBOL_LINKAGE_NAME (psym), name_len);
1023
1024 if (cmp < 0)
1025 {
1026 if (global)
1027 break;
1028 }
1029 else if (cmp == 0
1030 && (*is_name_suffix) (SYMBOL_LINKAGE_NAME (psym)
1031 + name_len))
1032 return psym;
1033 }
1034 i += 1;
1035 }
1036
1037 if (global)
1038 {
1039 int U;
1040 i = 0;
1041 U = length - 1;
1042 while (U - i > 4)
1043 {
1044 int M = (U + i) >> 1;
1045 struct partial_symbol *psym = start[M];
1046 if (SYMBOL_LINKAGE_NAME (psym)[0] < '_')
1047 i = M + 1;
1048 else if (SYMBOL_LINKAGE_NAME (psym)[0] > '_')
1049 U = M - 1;
1050 else if (strcmp (SYMBOL_LINKAGE_NAME (psym), "_ada_") < 0)
1051 i = M + 1;
1052 else
1053 U = M;
1054 }
1055 }
1056 else
1057 i = 0;
1058
1059 while (i < length)
1060 {
1061 struct partial_symbol *psym = start[i];
1062
1063 if (symbol_matches_domain (SYMBOL_LANGUAGE (psym),
1064 SYMBOL_DOMAIN (psym), namespace))
1065 {
1066 int cmp;
1067
1068 cmp = (int) '_' - (int) SYMBOL_LINKAGE_NAME (psym)[0];
1069 if (cmp == 0)
1070 {
1071 cmp = strncmp ("_ada_", SYMBOL_LINKAGE_NAME (psym), 5);
1072 if (cmp == 0)
1073 cmp = strncmp (name, SYMBOL_LINKAGE_NAME (psym) + 5,
1074 name_len);
1075 }
1076
1077 if (cmp < 0)
1078 {
1079 if (global)
1080 break;
1081 }
1082 else if (cmp == 0
1083 && (*is_name_suffix) (SYMBOL_LINKAGE_NAME (psym)
1084 + name_len + 5))
1085 return psym;
1086 }
1087 i += 1;
1088 }
1089 }
1090 return NULL;
1091}
1092
1093static void
1094map_ada_symtabs (struct objfile *objfile,
1095 int (*wild_match) (const char *, int, const char *),
1096 int (*is_name_suffix) (const char *),
1097 void (*callback) (struct objfile *, struct symtab *, void *),
1098 const char *name, int global, domain_enum namespace, int wild,
1099 void *data)
1100{
1101 struct partial_symtab *ps;
1102
1103 ALL_OBJFILE_PSYMTABS (objfile, ps)
1104 {
1105 QUIT;
1106 if (ps->readin
1107 || ada_lookup_partial_symbol (ps, name, global, namespace, wild,
1108 wild_match, is_name_suffix))
1109 {
1110 struct symtab *s = PSYMTAB_TO_SYMTAB (ps);
1111 if (s == NULL || !s->primary)
1112 continue;
1113 (*callback) (objfile, s, data);
1114 }
1115 }
1116}
1117
1118static void
1119expand_symtabs_matching_via_partial (struct objfile *objfile,
1120 int (*file_matcher) (const char *, void *),
1121 int (*name_matcher) (const char *, void *),
1122 domain_enum kind,
1123 void *data)
1124{
1125 struct partial_symtab *ps;
1126
1127 ALL_OBJFILE_PSYMTABS (objfile, ps)
1128 {
1129 struct partial_symbol **psym;
1130 struct partial_symbol **bound, **gbound, **sbound;
1131 int keep_going = 1;
1132
1133 if (ps->readin)
1134 continue;
1135
1136 if (! (*file_matcher) (ps->filename, data))
1137 continue;
1138
1139 gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms;
1140 sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms;
1141 bound = gbound;
1142
1143 /* Go through all of the symbols stored in a partial
1144 symtab in one loop. */
1145 psym = objfile->global_psymbols.list + ps->globals_offset;
1146 while (keep_going)
1147 {
1148 if (psym >= bound)
1149 {
1150 if (bound == gbound && ps->n_static_syms != 0)
1151 {
1152 psym = objfile->static_psymbols.list + ps->statics_offset;
1153 bound = sbound;
1154 }
1155 else
1156 keep_going = 0;
1157 continue;
1158 }
1159 else
1160 {
1161 QUIT;
1162
1163 if ((*name_matcher) (SYMBOL_NATURAL_NAME (*psym), data)
1164 && ((kind == VARIABLES_DOMAIN
1165 && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
1166 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
1167 || (kind == FUNCTIONS_DOMAIN
1168 && SYMBOL_CLASS (*psym) == LOC_BLOCK)
1169 || (kind == TYPES_DOMAIN
1170 && SYMBOL_CLASS (*psym) == LOC_TYPEDEF)))
1171 {
1172 PSYMTAB_TO_SYMTAB (ps);
1173 keep_going = 0;
1174 }
1175 }
1176 psym++;
1177 }
1178 }
1179}
1180
1181static int
1182objfile_has_psyms (struct objfile *objfile)
1183{
1184 return objfile->psymtabs != NULL;
1185}
1186
1187const struct quick_symbol_functions psym_functions =
1188{
1189 objfile_has_psyms,
1190 find_last_source_symtab_from_partial,
1191 forget_cached_source_info_partial,
1192 lookup_symtab_via_partial_symtab,
1193 lookup_symbol_aux_psymtabs,
1194 print_psymtab_stats_for_objfile,
1195 dump_psymtabs_for_objfile,
1196 relocate_psymtabs,
1197 read_symtabs_for_function,
1198 expand_partial_symbol_tables,
1199 read_psymtabs_with_filename,
1200 find_symbol_file_from_partial,
1201 map_ada_symtabs,
1202 expand_symtabs_matching_via_partial,
1203 find_pc_sect_symtab_from_partial,
1204 map_symbol_names_psymtab,
1205 map_symbol_filenames_psymtab
1206};
1207
1208\f
1209
1210/* This compares two partial symbols by names, using strcmp_iw_ordered
1211 for the comparison. */
1212
1213static int
1214compare_psymbols (const void *s1p, const void *s2p)
1215{
1216 struct partial_symbol *const *s1 = s1p;
1217 struct partial_symbol *const *s2 = s2p;
1218
1219 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1),
1220 SYMBOL_SEARCH_NAME (*s2));
1221}
1222
1223void
1224sort_pst_symbols (struct partial_symtab *pst)
1225{
1226 /* Sort the global list; don't sort the static list */
1227
1228 qsort (pst->objfile->global_psymbols.list + pst->globals_offset,
1229 pst->n_global_syms, sizeof (struct partial_symbol *),
1230 compare_psymbols);
1231}
1232
1233/* Allocate and partially fill a partial symtab. It will be
1234 completely filled at the end of the symbol list.
1235
1236 FILENAME is the name of the symbol-file we are reading from. */
1237
1238struct partial_symtab *
1239start_psymtab_common (struct objfile *objfile,
1240 struct section_offsets *section_offsets,
1241 const char *filename,
1242 CORE_ADDR textlow, struct partial_symbol **global_syms,
1243 struct partial_symbol **static_syms)
1244{
1245 struct partial_symtab *psymtab;
1246
1247 psymtab = allocate_psymtab (filename, objfile);
1248 psymtab->section_offsets = section_offsets;
1249 psymtab->textlow = textlow;
1250 psymtab->texthigh = psymtab->textlow; /* default */
1251 psymtab->globals_offset = global_syms - objfile->global_psymbols.list;
1252 psymtab->statics_offset = static_syms - objfile->static_psymbols.list;
1253 return (psymtab);
1254}
1255
1256/* Helper function, initialises partial symbol structure and stashes
1257 it into objfile's bcache. Note that our caching mechanism will
1258 use all fields of struct partial_symbol to determine hash value of the
1259 structure. In other words, having two symbols with the same name but
1260 different domain (or address) is possible and correct. */
1261
1262static const struct partial_symbol *
1263add_psymbol_to_bcache (char *name, int namelength, int copy_name,
1264 domain_enum domain,
1265 enum address_class class,
1266 long val, /* Value as a long */
1267 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1268 enum language language, struct objfile *objfile,
1269 int *added)
1270{
1271 /* psymbol is static so that there will be no uninitialized gaps in the
1272 structure which might contain random data, causing cache misses in
1273 bcache. */
1274 static struct partial_symbol psymbol;
1275
1276 /* However, we must ensure that the entire 'value' field has been
1277 zeroed before assigning to it, because an assignment may not
1278 write the entire field. */
1279 memset (&psymbol.ginfo.value, 0, sizeof (psymbol.ginfo.value));
1280 /* val and coreaddr are mutually exclusive, one of them *will* be zero */
1281 if (val != 0)
1282 {
1283 SYMBOL_VALUE (&psymbol) = val;
1284 }
1285 else
1286 {
1287 SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
1288 }
1289 SYMBOL_SECTION (&psymbol) = 0;
1290 SYMBOL_LANGUAGE (&psymbol) = language;
1291 PSYMBOL_DOMAIN (&psymbol) = domain;
1292 PSYMBOL_CLASS (&psymbol) = class;
1293
1294 SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
1295
1296 /* Stash the partial symbol away in the cache */
1297 return bcache_full (&psymbol, sizeof (struct partial_symbol),
1298 objfile->psymbol_cache, added);
1299}
1300
1301/* Helper function, adds partial symbol to the given partial symbol
1302 list. */
1303
1304static void
1305append_psymbol_to_list (struct psymbol_allocation_list *list,
1306 const struct partial_symbol *psym,
1307 struct objfile *objfile)
1308{
1309 if (list->next >= list->list + list->size)
1310 extend_psymbol_list (list, objfile);
1311 *list->next++ = (struct partial_symbol *) psym;
1312 OBJSTAT (objfile, n_psyms++);
1313}
1314
1315/* Add a symbol with a long value to a psymtab.
1316 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1317 Return the partial symbol that has been added. */
1318
1319/* NOTE: carlton/2003-09-11: The reason why we return the partial
1320 symbol is so that callers can get access to the symbol's demangled
1321 name, which they don't have any cheap way to determine otherwise.
1322 (Currenly, dwarf2read.c is the only file who uses that information,
1323 though it's possible that other readers might in the future.)
1324 Elena wasn't thrilled about that, and I don't blame her, but we
1325 couldn't come up with a better way to get that information. If
1326 it's needed in other situations, we could consider breaking up
1327 SYMBOL_SET_NAMES to provide access to the demangled name lookup
1328 cache. */
1329
1330const struct partial_symbol *
1331add_psymbol_to_list (char *name, int namelength, int copy_name,
1332 domain_enum domain,
1333 enum address_class class,
1334 struct psymbol_allocation_list *list,
1335 long val, /* Value as a long */
1336 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1337 enum language language, struct objfile *objfile)
1338{
1339 const struct partial_symbol *psym;
1340
1341 int added;
1342
1343 /* Stash the partial symbol away in the cache */
1344 psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, class,
1345 val, coreaddr, language, objfile, &added);
1346
1347 /* Do not duplicate global partial symbols. */
1348 if (list == &objfile->global_psymbols
1349 && !added)
1350 return psym;
1351
1352 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
1353 append_psymbol_to_list (list, psym, objfile);
1354 return psym;
1355}
1356
1357/* Initialize storage for partial symbols. */
1358
1359void
1360init_psymbol_list (struct objfile *objfile, int total_symbols)
1361{
1362 /* Free any previously allocated psymbol lists. */
1363
1364 if (objfile->global_psymbols.list)
1365 {
1366 xfree (objfile->global_psymbols.list);
1367 }
1368 if (objfile->static_psymbols.list)
1369 {
1370 xfree (objfile->static_psymbols.list);
1371 }
1372
1373 /* Current best guess is that approximately a twentieth
1374 of the total symbols (in a debugging file) are global or static
1375 oriented symbols */
1376
1377 objfile->global_psymbols.size = total_symbols / 10;
1378 objfile->static_psymbols.size = total_symbols / 10;
1379
1380 if (objfile->global_psymbols.size > 0)
1381 {
1382 objfile->global_psymbols.next =
1383 objfile->global_psymbols.list = (struct partial_symbol **)
1384 xmalloc ((objfile->global_psymbols.size
1385 * sizeof (struct partial_symbol *)));
1386 }
1387 if (objfile->static_psymbols.size > 0)
1388 {
1389 objfile->static_psymbols.next =
1390 objfile->static_psymbols.list = (struct partial_symbol **)
1391 xmalloc ((objfile->static_psymbols.size
1392 * sizeof (struct partial_symbol *)));
1393 }
1394}
1395
1396struct partial_symtab *
1397allocate_psymtab (const char *filename, struct objfile *objfile)
1398{
1399 struct partial_symtab *psymtab;
1400
1401 if (objfile->free_psymtabs)
1402 {
1403 psymtab = objfile->free_psymtabs;
1404 objfile->free_psymtabs = psymtab->next;
1405 }
1406 else
1407 psymtab = (struct partial_symtab *)
1408 obstack_alloc (&objfile->objfile_obstack,
1409 sizeof (struct partial_symtab));
1410
1411 memset (psymtab, 0, sizeof (struct partial_symtab));
1412 psymtab->filename = obsavestring (filename, strlen (filename),
1413 &objfile->objfile_obstack);
1414 psymtab->symtab = NULL;
1415
1416 /* Prepend it to the psymtab list for the objfile it belongs to.
1417 Psymtabs are searched in most recent inserted -> least recent
1418 inserted order. */
1419
1420 psymtab->objfile = objfile;
1421 psymtab->next = objfile->psymtabs;
1422 objfile->psymtabs = psymtab;
1423#if 0
1424 {
1425 struct partial_symtab **prev_pst;
1426 psymtab->objfile = objfile;
1427 psymtab->next = NULL;
1428 prev_pst = &(objfile->psymtabs);
1429 while ((*prev_pst) != NULL)
1430 prev_pst = &((*prev_pst)->next);
1431 (*prev_pst) = psymtab;
1432 }
1433#endif
1434
1435 return (psymtab);
1436}
1437
1438void
1439discard_psymtab (struct partial_symtab *pst)
1440{
1441 struct partial_symtab **prev_pst;
1442
1443 /* From dbxread.c:
1444 Empty psymtabs happen as a result of header files which don't
1445 have any symbols in them. There can be a lot of them. But this
1446 check is wrong, in that a psymtab with N_SLINE entries but
1447 nothing else is not empty, but we don't realize that. Fixing
1448 that without slowing things down might be tricky. */
1449
1450 /* First, snip it out of the psymtab chain */
1451
1452 prev_pst = &(pst->objfile->psymtabs);
1453 while ((*prev_pst) != pst)
1454 prev_pst = &((*prev_pst)->next);
1455 (*prev_pst) = pst->next;
1456
1457 /* Next, put it on a free list for recycling */
1458
1459 pst->next = pst->objfile->free_psymtabs;
1460 pst->objfile->free_psymtabs = pst;
1461}
1462
1463/* Increase the space allocated for LISTP, which is probably
1464 global_psymbols or static_psymbols. This space will eventually
1465 be freed in free_objfile(). */
1466
1467void
1468extend_psymbol_list (struct psymbol_allocation_list *listp,
1469 struct objfile *objfile)
1470{
1471 int new_size;
1472 if (listp->size == 0)
1473 {
1474 new_size = 255;
1475 listp->list = (struct partial_symbol **)
1476 xmalloc (new_size * sizeof (struct partial_symbol *));
1477 }
1478 else
1479 {
1480 new_size = listp->size * 2;
1481 listp->list = (struct partial_symbol **)
1482 xrealloc ((char *) listp->list,
1483 new_size * sizeof (struct partial_symbol *));
1484 }
1485 /* Next assumes we only went one over. Should be good if
1486 program works correctly */
1487 listp->next = listp->list + listp->size;
1488 listp->size = new_size;
1489}
1490
1491\f
1492
1493void
1494maintenance_print_psymbols (char *args, int from_tty)
1495{
1496 char **argv;
1497 struct ui_file *outfile;
1498 struct cleanup *cleanups;
1499 char *symname = NULL;
1500 char *filename = DEV_TTY;
1501 struct objfile *objfile;
1502 struct partial_symtab *ps;
1503
1504 dont_repeat ();
1505
1506 if (args == NULL)
1507 {
1508 error (_("print-psymbols takes an output file name and optional symbol file name"));
1509 }
1510 argv = gdb_buildargv (args);
1511 cleanups = make_cleanup_freeargv (argv);
1512
1513 if (argv[0] != NULL)
1514 {
1515 filename = argv[0];
1516 /* If a second arg is supplied, it is a source file name to match on */
1517 if (argv[1] != NULL)
1518 {
1519 symname = argv[1];
1520 }
1521 }
1522
1523 filename = tilde_expand (filename);
1524 make_cleanup (xfree, filename);
1525
1526 outfile = gdb_fopen (filename, FOPEN_WT);
1527 if (outfile == 0)
1528 perror_with_name (filename);
1529 make_cleanup_ui_file_delete (outfile);
1530
1531 immediate_quit++;
1532 ALL_PSYMTABS (objfile, ps)
1533 if (symname == NULL || strcmp (symname, ps->filename) == 0)
1534 dump_psymtab (objfile, ps, outfile);
1535 immediate_quit--;
1536 do_cleanups (cleanups);
1537}
1538
1539/* List all the partial symbol tables whose names match REGEXP (optional). */
1540void
1541maintenance_info_psymtabs (char *regexp, int from_tty)
1542{
1543 struct program_space *pspace;
1544 struct objfile *objfile;
1545
1546 if (regexp)
1547 re_comp (regexp);
1548
1549 ALL_PSPACES (pspace)
1550 ALL_PSPACE_OBJFILES (pspace, objfile)
1551 {
1552 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1553 struct partial_symtab *psymtab;
1554
1555 /* We don't want to print anything for this objfile until we
1556 actually find a symtab whose name matches. */
1557 int printed_objfile_start = 0;
1558
1559 ALL_OBJFILE_PSYMTABS (objfile, psymtab)
1560 {
1561 QUIT;
1562
1563 if (! regexp
1564 || re_exec (psymtab->filename))
1565 {
1566 if (! printed_objfile_start)
1567 {
1568 printf_filtered ("{ objfile %s ", objfile->name);
1569 wrap_here (" ");
1570 printf_filtered ("((struct objfile *) %s)\n",
1571 host_address_to_string (objfile));
1572 printed_objfile_start = 1;
1573 }
1574
1575 printf_filtered (" { psymtab %s ", psymtab->filename);
1576 wrap_here (" ");
1577 printf_filtered ("((struct partial_symtab *) %s)\n",
1578 host_address_to_string (psymtab));
1579
1580 printf_filtered (" readin %s\n",
1581 psymtab->readin ? "yes" : "no");
1582 printf_filtered (" fullname %s\n",
1583 psymtab->fullname ? psymtab->fullname : "(null)");
1584 printf_filtered (" text addresses ");
1585 fputs_filtered (paddress (gdbarch, psymtab->textlow),
1586 gdb_stdout);
1587 printf_filtered (" -- ");
1588 fputs_filtered (paddress (gdbarch, psymtab->texthigh),
1589 gdb_stdout);
1590 printf_filtered ("\n");
1591 printf_filtered (" globals ");
1592 if (psymtab->n_global_syms)
1593 {
1594 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1595 host_address_to_string (psymtab->objfile->global_psymbols.list
1596 + psymtab->globals_offset),
1597 psymtab->n_global_syms);
1598 }
1599 else
1600 printf_filtered ("(none)\n");
1601 printf_filtered (" statics ");
1602 if (psymtab->n_static_syms)
1603 {
1604 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1605 host_address_to_string (psymtab->objfile->static_psymbols.list
1606 + psymtab->statics_offset),
1607 psymtab->n_static_syms);
1608 }
1609 else
1610 printf_filtered ("(none)\n");
1611 printf_filtered (" dependencies ");
1612 if (psymtab->number_of_dependencies)
1613 {
1614 int i;
1615
1616 printf_filtered ("{\n");
1617 for (i = 0; i < psymtab->number_of_dependencies; i++)
1618 {
1619 struct partial_symtab *dep = psymtab->dependencies[i];
1620
1621 /* Note the string concatenation there --- no comma. */
1622 printf_filtered (" psymtab %s "
1623 "((struct partial_symtab *) %s)\n",
1624 dep->filename,
1625 host_address_to_string (dep));
1626 }
1627 printf_filtered (" }\n");
1628 }
1629 else
1630 printf_filtered ("(none)\n");
1631 printf_filtered (" }\n");
1632 }
1633 }
1634
1635 if (printed_objfile_start)
1636 printf_filtered ("}\n");
1637 }
1638}
1639
1640/* Check consistency of psymtabs and symtabs. */
1641
1642void
1643maintenance_check_symtabs (char *ignore, int from_tty)
1644{
1645 struct symbol *sym;
1646 struct partial_symbol **psym;
1647 struct symtab *s = NULL;
1648 struct partial_symtab *ps;
1649 struct blockvector *bv;
1650 struct objfile *objfile;
1651 struct block *b;
1652 int length;
1653
1654 ALL_PSYMTABS (objfile, ps)
1655 {
1656 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1657 s = PSYMTAB_TO_SYMTAB (ps);
1658 if (s == NULL)
1659 continue;
1660 bv = BLOCKVECTOR (s);
1661 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1662 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1663 length = ps->n_static_syms;
1664 while (length--)
1665 {
1666 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1667 SYMBOL_DOMAIN (*psym));
1668 if (!sym)
1669 {
1670 printf_filtered ("Static symbol `");
1671 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1672 printf_filtered ("' only found in ");
1673 puts_filtered (ps->filename);
1674 printf_filtered (" psymtab\n");
1675 }
1676 psym++;
1677 }
1678 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1679 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
1680 length = ps->n_global_syms;
1681 while (length--)
1682 {
1683 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1684 SYMBOL_DOMAIN (*psym));
1685 if (!sym)
1686 {
1687 printf_filtered ("Global symbol `");
1688 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
1689 printf_filtered ("' only found in ");
1690 puts_filtered (ps->filename);
1691 printf_filtered (" psymtab\n");
1692 }
1693 psym++;
1694 }
1695 if (ps->texthigh < ps->textlow)
1696 {
1697 printf_filtered ("Psymtab ");
1698 puts_filtered (ps->filename);
1699 printf_filtered (" covers bad range ");
1700 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1701 printf_filtered (" - ");
1702 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1703 printf_filtered ("\n");
1704 continue;
1705 }
1706 if (ps->texthigh == 0)
1707 continue;
1708 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
1709 {
1710 printf_filtered ("Psymtab ");
1711 puts_filtered (ps->filename);
1712 printf_filtered (" covers ");
1713 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
1714 printf_filtered (" - ");
1715 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
1716 printf_filtered (" but symtab covers only ");
1717 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
1718 printf_filtered (" - ");
1719 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
1720 printf_filtered ("\n");
1721 }
1722 }
1723}
1724
1725\f
1726
1727void
1728map_partial_symbol_names (void (*fun) (const char *, void *), void *data)
1729{
1730 struct objfile *objfile;
1731
1732 ALL_OBJFILES (objfile)
1733 {
1734 if (objfile->sf)
1735 objfile->sf->qf->map_symbol_names (objfile, fun, data);
1736 }
1737}
1738
1739void
1740map_partial_symbol_filenames (void (*fun) (const char *, const char *,
1741 void *),
1742 void *data)
1743{
1744 struct objfile *objfile;
1745
1746 ALL_OBJFILES (objfile)
1747 {
1748 if (objfile->sf)
1749 objfile->sf->qf->map_symbol_filenames (objfile, fun, data);
1750 }
1751}
This page took 0.085944 seconds and 4 git commands to generate.