* symfile.c (separate_debug_file_exists): Update.
[deliverable/binutils-gdb.git] / gdb / psymtab.c
CommitLineData
ccefe4c4
TT
1/* Partial symbol tables.
2
0b302171 3 Copyright (C) 2009-2012 Free Software Foundation, Inc.
ccefe4c4
TT
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"
40658b94 35#include "dictionary.h"
c00f8484
KS
36#include "language.h"
37#include "cp-support.h"
ccefe4c4
TT
38
39#ifndef DEV_TTY
40#define DEV_TTY "/dev/tty"
41#endif
42
710e1a31
SW
43struct psymbol_bcache
44{
45 struct bcache *bcache;
46};
47
40658b94
PH
48static struct partial_symbol *match_partial_symbol (struct partial_symtab *,
49 int,
50 const char *, domain_enum,
2edb89d3
JK
51 symbol_compare_ftype *,
52 symbol_compare_ftype *);
40658b94 53
ccefe4c4
TT
54static struct partial_symbol *lookup_partial_symbol (struct partial_symtab *,
55 const char *, int,
56 domain_enum);
57
58static char *psymtab_to_fullname (struct partial_symtab *ps);
59
60static struct partial_symbol *find_pc_sect_psymbol (struct partial_symtab *,
61 CORE_ADDR,
62 struct obj_section *);
63
64static struct partial_symbol *fixup_psymbol_section (struct partial_symbol
65 *psym,
66 struct objfile *objfile);
67
68static struct symtab *psymtab_to_symtab (struct partial_symtab *pst);
69
b11896a5
TT
70/* Ensure that the partial symbols for OBJFILE have been loaded. This
71 function always returns its argument, as a convenience. */
72
73struct objfile *
74require_partial_symbols (struct objfile *objfile, int verbose)
75{
76 if ((objfile->flags & OBJF_PSYMTABS_READ) == 0)
77 {
78 objfile->flags |= OBJF_PSYMTABS_READ;
79
80 if (objfile->sf->sym_read_psymbols)
81 {
82 if (verbose)
83 {
84 printf_unfiltered (_("Reading symbols from %s..."),
85 objfile->name);
86 gdb_flush (gdb_stdout);
87 }
88 (*objfile->sf->sym_read_psymbols) (objfile);
89 if (verbose)
90 {
91 if (!objfile_has_symbols (objfile))
92 {
93 wrap_here ("");
94 printf_unfiltered (_("(no debugging symbols found)..."));
95 wrap_here ("");
96 }
97
98 printf_unfiltered (_("done.\n"));
99 }
100 }
101 }
102
103 return objfile;
104}
105
106/* Traverse all psymtabs in one objfile, requiring that the psymtabs
107 be read in. */
108
109#define ALL_OBJFILE_PSYMTABS_REQUIRED(objfile, p) \
110 for ((p) = require_partial_symbols (objfile, 1)->psymtabs; \
111 (p) != NULL; \
112 (p) = (p)->next)
113
114/* We want to make sure this file always requires psymtabs. */
115
116#undef ALL_OBJFILE_PSYMTABS
117
118/* Traverse all psymtabs in all objfiles. */
119
120#define ALL_PSYMTABS(objfile, p) \
121 ALL_OBJFILES (objfile) \
122 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
123
f8eba3c6
TT
124/* Helper function for partial_map_symtabs_matching_filename that
125 expands the symtabs and calls the iterator. */
ccefe4c4 126
f8eba3c6
TT
127static int
128partial_map_expand_apply (struct objfile *objfile,
129 const char *name,
130 const char *full_path,
131 const char *real_path,
132 struct partial_symtab *pst,
133 int (*callback) (struct symtab *, void *),
134 void *data)
135{
136 struct symtab *last_made = objfile->symtabs;
137
9439a077
TT
138 /* Shared psymtabs should never be seen here. Instead they should
139 be handled properly by the caller. */
140 gdb_assert (pst->user == NULL);
141
f8eba3c6
TT
142 /* Don't visit already-expanded psymtabs. */
143 if (pst->readin)
144 return 0;
145
146 /* This may expand more than one symtab, and we want to iterate over
147 all of them. */
148 psymtab_to_symtab (pst);
149
150 return iterate_over_some_symtabs (name, full_path, real_path, callback, data,
151 objfile->symtabs, last_made);
152}
153
154/* Implementation of the map_symtabs_matching_filename method. */
155
156static int
157partial_map_symtabs_matching_filename (struct objfile *objfile,
158 const char *name,
159 const char *full_path,
160 const char *real_path,
161 int (*callback) (struct symtab *,
162 void *),
163 void *data)
ccefe4c4
TT
164{
165 struct partial_symtab *pst;
c011a4f4 166 const char *name_basename = lbasename (name);
4aac40c8
TT
167 int name_len = strlen (name);
168 int is_abs = IS_ABSOLUTE_PATH (name);
ccefe4c4 169
b11896a5 170 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
ccefe4c4 171 {
9439a077
TT
172 /* We can skip shared psymtabs here, because any file name will be
173 attached to the unshared psymtab. */
174 if (pst->user != NULL)
175 continue;
176
b4c41fc7
DE
177 /* Anonymous psymtabs don't have a file name. */
178 if (pst->anonymous)
179 continue;
180
4aac40c8
TT
181 if (FILENAME_CMP (name, pst->filename) == 0
182 || (!is_abs && compare_filenames_for_search (pst->filename,
183 name, name_len)))
ccefe4c4 184 {
f8eba3c6
TT
185 if (partial_map_expand_apply (objfile, name, full_path, real_path,
186 pst, callback, data))
187 return 1;
ccefe4c4
TT
188 }
189
c011a4f4
DE
190 /* Before we invoke realpath, which can get expensive when many
191 files are involved, do a quick comparison of the basenames. */
192 if (! basenames_may_differ
193 && FILENAME_CMP (name_basename, lbasename (pst->filename)) != 0)
194 continue;
195
ccefe4c4
TT
196 /* If the user gave us an absolute path, try to find the file in
197 this symtab and use its absolute path. */
198 if (full_path != NULL)
199 {
200 psymtab_to_fullname (pst);
201 if (pst->fullname != NULL
4aac40c8
TT
202 && (FILENAME_CMP (full_path, pst->fullname) == 0
203 || (!is_abs && compare_filenames_for_search (pst->fullname,
204 name, name_len))))
ccefe4c4 205 {
f8eba3c6
TT
206 if (partial_map_expand_apply (objfile, name, full_path, real_path,
207 pst, callback, data))
208 return 1;
ccefe4c4
TT
209 }
210 }
211
212 if (real_path != NULL)
213 {
214 char *rp = NULL;
215 psymtab_to_fullname (pst);
216 if (pst->fullname != NULL)
217 {
218 rp = gdb_realpath (pst->fullname);
219 make_cleanup (xfree, rp);
220 }
4aac40c8
TT
221 if (rp != NULL
222 && (FILENAME_CMP (real_path, rp) == 0
223 || (!is_abs && compare_filenames_for_search (real_path,
224 name, name_len))))
ccefe4c4 225 {
f8eba3c6
TT
226 if (partial_map_expand_apply (objfile, name, full_path, real_path,
227 pst, callback, data))
228 return 1;
ccefe4c4
TT
229 }
230 }
231 }
232
f8eba3c6 233 return 0;
ccefe4c4
TT
234}
235
236/* Find which partial symtab contains PC and SECTION starting at psymtab PST.
237 We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */
238
239static struct partial_symtab *
240find_pc_sect_psymtab_closer (CORE_ADDR pc, struct obj_section *section,
241 struct partial_symtab *pst,
242 struct minimal_symbol *msymbol)
243{
244 struct objfile *objfile = pst->objfile;
245 struct partial_symtab *tpst;
246 struct partial_symtab *best_pst = pst;
247 CORE_ADDR best_addr = pst->textlow;
248
9750bca9
JK
249 gdb_assert (!pst->psymtabs_addrmap_supported);
250
ccefe4c4
TT
251 /* An objfile that has its functions reordered might have
252 many partial symbol tables containing the PC, but
253 we want the partial symbol table that contains the
254 function containing the PC. */
255 if (!(objfile->flags & OBJF_REORDERED) &&
0df8b418 256 section == 0) /* Can't validate section this way. */
ccefe4c4
TT
257 return pst;
258
259 if (msymbol == NULL)
260 return (pst);
261
262 /* The code range of partial symtabs sometimes overlap, so, in
263 the loop below, we need to check all partial symtabs and
0df8b418 264 find the one that fits better for the given PC address. We
ccefe4c4
TT
265 select the partial symtab that contains a symbol whose
266 address is closest to the PC address. By closest we mean
267 that find_pc_sect_symbol returns the symbol with address
268 that is closest and still less than the given PC. */
269 for (tpst = pst; tpst != NULL; tpst = tpst->next)
270 {
271 if (pc >= tpst->textlow && pc < tpst->texthigh)
272 {
273 struct partial_symbol *p;
274 CORE_ADDR this_addr;
275
276 /* NOTE: This assumes that every psymbol has a
277 corresponding msymbol, which is not necessarily
278 true; the debug info might be much richer than the
279 object's symbol table. */
280 p = find_pc_sect_psymbol (tpst, pc, section);
281 if (p != NULL
282 && SYMBOL_VALUE_ADDRESS (p)
283 == SYMBOL_VALUE_ADDRESS (msymbol))
284 return tpst;
285
286 /* Also accept the textlow value of a psymtab as a
287 "symbol", to provide some support for partial
288 symbol tables with line information but no debug
289 symbols (e.g. those produced by an assembler). */
290 if (p != NULL)
291 this_addr = SYMBOL_VALUE_ADDRESS (p);
292 else
293 this_addr = tpst->textlow;
294
295 /* Check whether it is closer than our current
296 BEST_ADDR. Since this symbol address is
297 necessarily lower or equal to PC, the symbol closer
298 to PC is the symbol which address is the highest.
299 This way we return the psymtab which contains such
0df8b418 300 best match symbol. This can help in cases where the
ccefe4c4
TT
301 symbol information/debuginfo is not complete, like
302 for instance on IRIX6 with gcc, where no debug info
0df8b418
MS
303 is emitted for statics. (See also the nodebug.exp
304 testcase.) */
ccefe4c4
TT
305 if (this_addr > best_addr)
306 {
307 best_addr = this_addr;
308 best_pst = tpst;
309 }
310 }
311 }
312 return best_pst;
313}
314
315/* Find which partial symtab contains PC and SECTION. Return 0 if
316 none. We return the psymtab that contains a symbol whose address
317 exactly matches PC, or, if we cannot find an exact match, the
318 psymtab that contains a symbol whose address is closest to PC. */
319static struct partial_symtab *
320find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
321 struct obj_section *section,
322 struct minimal_symbol *msymbol)
323{
324 struct partial_symtab *pst;
325
326 /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
327 than the later used TEXTLOW/TEXTHIGH one. */
328
329 if (objfile->psymtabs_addrmap != NULL)
330 {
331 pst = addrmap_find (objfile->psymtabs_addrmap, pc);
332 if (pst != NULL)
333 {
334 /* FIXME: addrmaps currently do not handle overlayed sections,
335 so fall back to the non-addrmap case if we're debugging
336 overlays and the addrmap returned the wrong section. */
337 if (overlay_debugging && msymbol && section)
338 {
339 struct partial_symbol *p;
ad3bbd48 340
ccefe4c4
TT
341 /* NOTE: This assumes that every psymbol has a
342 corresponding msymbol, which is not necessarily
343 true; the debug info might be much richer than the
344 object's symbol table. */
345 p = find_pc_sect_psymbol (pst, pc, section);
346 if (!p
347 || SYMBOL_VALUE_ADDRESS (p)
348 != SYMBOL_VALUE_ADDRESS (msymbol))
349 goto next;
350 }
351
352 /* We do not try to call FIND_PC_SECT_PSYMTAB_CLOSER as
353 PSYMTABS_ADDRMAP we used has already the best 1-byte
354 granularity and FIND_PC_SECT_PSYMTAB_CLOSER may mislead us into
355 a worse chosen section due to the TEXTLOW/TEXTHIGH ranges
356 overlap. */
357
358 return pst;
359 }
360 }
361
362 next:
363
364 /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs
365 which still have no corresponding full SYMTABs read. But it is not
366 present for non-DWARF2 debug infos not supporting PSYMTABS_ADDRMAP in GDB
367 so far. */
368
369 /* Check even OBJFILE with non-zero PSYMTABS_ADDRMAP as only several of
370 its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
371 debug info type in single OBJFILE. */
372
b11896a5 373 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
9750bca9
JK
374 if (!pst->psymtabs_addrmap_supported
375 && pc >= pst->textlow && pc < pst->texthigh)
ccefe4c4
TT
376 {
377 struct partial_symtab *best_pst;
378
379 best_pst = find_pc_sect_psymtab_closer (pc, section, pst, msymbol);
380 if (best_pst != NULL)
381 return best_pst;
382 }
383
384 return NULL;
385}
386
387static struct symtab *
388find_pc_sect_symtab_from_partial (struct objfile *objfile,
389 struct minimal_symbol *msymbol,
390 CORE_ADDR pc, struct obj_section *section,
391 int warn_if_readin)
392{
393 struct partial_symtab *ps = find_pc_sect_psymtab (objfile, pc, section,
394 msymbol);
395 if (ps)
396 {
397 if (warn_if_readin && ps->readin)
398 /* Might want to error() here (in case symtab is corrupt and
399 will cause a core dump), but maybe we can successfully
400 continue, so let's not. */
401 warning (_("\
402(Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
403 paddress (get_objfile_arch (ps->objfile), pc));
9703b513
TT
404 psymtab_to_symtab (ps);
405 return ps->symtab;
ccefe4c4
TT
406 }
407 return NULL;
408}
409
410/* Find which partial symbol within a psymtab matches PC and SECTION.
411 Return 0 if none. */
412
413static struct partial_symbol *
414find_pc_sect_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc,
415 struct obj_section *section)
416{
417 struct partial_symbol *best = NULL, *p, **pp;
418 CORE_ADDR best_pc;
419
420 gdb_assert (psymtab != NULL);
421
0df8b418 422 /* Cope with programs that start at address 0. */
ccefe4c4
TT
423 best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
424
425 /* Search the global symbols as well as the static symbols, so that
426 find_pc_partial_function doesn't use a minimal symbol and thus
427 cache a bad endaddr. */
428 for (pp = psymtab->objfile->global_psymbols.list + psymtab->globals_offset;
429 (pp - (psymtab->objfile->global_psymbols.list + psymtab->globals_offset)
430 < psymtab->n_global_syms);
431 pp++)
432 {
433 p = *pp;
434 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
435 && SYMBOL_CLASS (p) == LOC_BLOCK
436 && pc >= SYMBOL_VALUE_ADDRESS (p)
437 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
438 || (psymtab->textlow == 0
439 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
440 {
0df8b418 441 if (section) /* Match on a specific section. */
ccefe4c4
TT
442 {
443 fixup_psymbol_section (p, psymtab->objfile);
444 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
445 continue;
446 }
447 best_pc = SYMBOL_VALUE_ADDRESS (p);
448 best = p;
449 }
450 }
451
452 for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
453 (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
454 < psymtab->n_static_syms);
455 pp++)
456 {
457 p = *pp;
458 if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
459 && SYMBOL_CLASS (p) == LOC_BLOCK
460 && pc >= SYMBOL_VALUE_ADDRESS (p)
461 && (SYMBOL_VALUE_ADDRESS (p) > best_pc
462 || (psymtab->textlow == 0
463 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
464 {
0df8b418 465 if (section) /* Match on a specific section. */
ccefe4c4
TT
466 {
467 fixup_psymbol_section (p, psymtab->objfile);
468 if (!matching_obj_sections (SYMBOL_OBJ_SECTION (p), section))
469 continue;
470 }
471 best_pc = SYMBOL_VALUE_ADDRESS (p);
472 best = p;
473 }
474 }
475
476 return best;
477}
478
479static struct partial_symbol *
480fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
481{
482 CORE_ADDR addr;
483
484 if (!psym)
485 return NULL;
486
487 if (SYMBOL_OBJ_SECTION (psym))
488 return psym;
489
490 gdb_assert (objfile);
491
492 switch (SYMBOL_CLASS (psym))
493 {
494 case LOC_STATIC:
495 case LOC_LABEL:
496 case LOC_BLOCK:
497 addr = SYMBOL_VALUE_ADDRESS (psym);
498 break;
499 default:
500 /* Nothing else will be listed in the minsyms -- no use looking
501 it up. */
502 return psym;
503 }
504
505 fixup_section (&psym->ginfo, addr, objfile);
506
507 return psym;
508}
509
510static struct symtab *
511lookup_symbol_aux_psymtabs (struct objfile *objfile,
512 int block_index, const char *name,
513 const domain_enum domain)
514{
515 struct partial_symtab *ps;
516 const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
bfb05775 517 struct symtab *stab_best = NULL;
ccefe4c4 518
b11896a5 519 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
ccefe4c4
TT
520 {
521 if (!ps->readin && lookup_partial_symbol (ps, name, psymtab_index, domain))
c00f8484
KS
522 {
523 struct symbol *sym = NULL;
a2ca7a52 524 struct symtab *stab = psymtab_to_symtab (ps);
c00f8484
KS
525
526 /* Some caution must be observed with overloaded functions
527 and methods, since the psymtab will not contain any overload
528 information (but NAME might contain it). */
529 if (stab->primary)
530 {
531 struct blockvector *bv = BLOCKVECTOR (stab);
532 struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
533
534 sym = lookup_block_symbol (block, name, domain);
535 }
536
537 if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
bfb05775
JK
538 {
539 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
540 return stab;
541
542 stab_best = stab;
543 }
c00f8484
KS
544
545 /* Keep looking through other psymtabs. */
546 }
ccefe4c4
TT
547 }
548
bfb05775 549 return stab_best;
ccefe4c4
TT
550}
551
40658b94
PH
552/* Look in PST for a symbol in DOMAIN whose name matches NAME. Search
553 the global block of PST if GLOBAL, and otherwise the static block.
554 MATCH is the comparison operation that returns true iff MATCH (s,
555 NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is
556 non-null, the symbols in the block are assumed to be ordered
557 according to it (allowing binary search). It must be compatible
558 with MATCH. Returns the symbol, if found, and otherwise NULL. */
559
560static struct partial_symbol *
561match_partial_symbol (struct partial_symtab *pst, int global,
562 const char *name, domain_enum domain,
2edb89d3
JK
563 symbol_compare_ftype *match,
564 symbol_compare_ftype *ordered_compare)
40658b94
PH
565{
566 struct partial_symbol **start, **psym;
567 struct partial_symbol **top, **real_top, **bottom, **center;
568 int length = (global ? pst->n_global_syms : pst->n_static_syms);
569 int do_linear_search = 1;
570
571 if (length == 0)
572 return NULL;
573 start = (global ?
574 pst->objfile->global_psymbols.list + pst->globals_offset :
575 pst->objfile->static_psymbols.list + pst->statics_offset);
576
577 if (global && ordered_compare) /* Can use a binary search. */
578 {
579 do_linear_search = 0;
580
581 /* Binary search. This search is guaranteed to end with center
582 pointing at the earliest partial symbol whose name might be
583 correct. At that point *all* partial symbols with an
584 appropriate name will be checked against the correct
585 domain. */
586
587 bottom = start;
588 top = start + length - 1;
589 real_top = top;
590 while (top > bottom)
591 {
592 center = bottom + (top - bottom) / 2;
593 gdb_assert (center < top);
594 if (!do_linear_search
595 && (SYMBOL_LANGUAGE (*center) == language_java))
596 do_linear_search = 1;
597 if (ordered_compare (SYMBOL_SEARCH_NAME (*center), name) >= 0)
598 top = center;
599 else
600 bottom = center + 1;
601 }
602 gdb_assert (top == bottom);
603
604 while (top <= real_top
605 && match (SYMBOL_SEARCH_NAME (*top), name) == 0)
606 {
607 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
608 SYMBOL_DOMAIN (*top), domain))
609 return *top;
610 top++;
611 }
612 }
613
614 /* Can't use a binary search or else we found during the binary search that
615 we should also do a linear search. */
616
617 if (do_linear_search)
618 {
619 for (psym = start; psym < start + length; psym++)
620 {
621 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
622 SYMBOL_DOMAIN (*psym), domain)
623 && match (SYMBOL_SEARCH_NAME (*psym), name) == 0)
624 return *psym;
625 }
626 }
627
628 return NULL;
629}
630
774b6a14
TT
631static void
632pre_expand_symtabs_matching_psymtabs (struct objfile *objfile,
8903c50d
TT
633 enum block_enum block_kind,
634 const char *name,
774b6a14 635 domain_enum domain)
58b6ab13 636{
774b6a14 637 /* Nothing. */
58b6ab13
TT
638}
639
c00f8484
KS
640/* Returns the name used to search psymtabs. Unlike symtabs, psymtabs do
641 not contain any method/function instance information (since this would
642 force reading type information while reading psymtabs). Therefore,
643 if NAME contains overload information, it must be stripped before searching
644 psymtabs.
645
646 The caller is responsible for freeing the return result. */
647
648static char *
649psymtab_search_name (const char *name)
650{
651 switch (current_language->la_language)
652 {
653 case language_cplus:
654 case language_java:
655 {
656 if (strchr (name, '('))
657 {
658 char *ret = cp_remove_params (name);
659
660 if (ret)
661 return ret;
662 }
663 }
664 break;
665
666 default:
667 break;
668 }
669
670 return xstrdup (name);
671}
672
ccefe4c4 673/* Look, in partial_symtab PST, for symbol whose natural name is NAME.
40658b94 674 Check the global symbols if GLOBAL, the static symbols if not. */
ccefe4c4 675
18430289 676static struct partial_symbol *
ccefe4c4
TT
677lookup_partial_symbol (struct partial_symtab *pst, const char *name,
678 int global, domain_enum domain)
679{
ccefe4c4
TT
680 struct partial_symbol **start, **psym;
681 struct partial_symbol **top, **real_top, **bottom, **center;
682 int length = (global ? pst->n_global_syms : pst->n_static_syms);
683 int do_linear_search = 1;
c00f8484
KS
684 char *search_name;
685 struct cleanup *cleanup;
ccefe4c4
TT
686
687 if (length == 0)
688 {
689 return (NULL);
690 }
c00f8484
KS
691
692 search_name = psymtab_search_name (name);
693 cleanup = make_cleanup (xfree, search_name);
ccefe4c4
TT
694 start = (global ?
695 pst->objfile->global_psymbols.list + pst->globals_offset :
696 pst->objfile->static_psymbols.list + pst->statics_offset);
697
0df8b418 698 if (global) /* This means we can use a binary search. */
ccefe4c4
TT
699 {
700 do_linear_search = 0;
701
702 /* Binary search. This search is guaranteed to end with center
703 pointing at the earliest partial symbol whose name might be
704 correct. At that point *all* partial symbols with an
705 appropriate name will be checked against the correct
706 domain. */
707
708 bottom = start;
709 top = start + length - 1;
710 real_top = top;
711 while (top > bottom)
712 {
713 center = bottom + (top - bottom) / 2;
714 if (!(center < top))
3e43a32a
MS
715 internal_error (__FILE__, __LINE__,
716 _("failed internal consistency check"));
ccefe4c4 717 if (!do_linear_search
40658b94 718 && SYMBOL_LANGUAGE (*center) == language_java)
ccefe4c4
TT
719 {
720 do_linear_search = 1;
721 }
c00f8484
KS
722 if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
723 search_name) >= 0)
ccefe4c4
TT
724 {
725 top = center;
726 }
727 else
728 {
729 bottom = center + 1;
730 }
731 }
732 if (!(top == bottom))
3e43a32a
MS
733 internal_error (__FILE__, __LINE__,
734 _("failed internal consistency check"));
ccefe4c4 735
559a7a62
JK
736 /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
737 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */
738 while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
739 top--;
740
741 /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */
742 top++;
743
744 while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
ccefe4c4
TT
745 {
746 if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
747 SYMBOL_DOMAIN (*top), domain))
c00f8484
KS
748 {
749 do_cleanups (cleanup);
750 return (*top);
751 }
ccefe4c4
TT
752 top++;
753 }
754 }
755
756 /* Can't use a binary search or else we found during the binary search that
40658b94 757 we should also do a linear search. */
ccefe4c4
TT
758
759 if (do_linear_search)
760 {
761 for (psym = start; psym < start + length; psym++)
762 {
763 if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
764 SYMBOL_DOMAIN (*psym), domain)
c00f8484
KS
765 && SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name))
766 {
767 do_cleanups (cleanup);
768 return (*psym);
769 }
ccefe4c4
TT
770 }
771 }
772
c00f8484 773 do_cleanups (cleanup);
ccefe4c4
TT
774 return (NULL);
775}
776
777/* Get the symbol table that corresponds to a partial_symtab.
a2ca7a52 778 This is fast after the first time you do it. */
ccefe4c4
TT
779
780static struct symtab *
781psymtab_to_symtab (struct partial_symtab *pst)
782{
9439a077
TT
783 /* If it is a shared psymtab, find an unshared psymtab that includes
784 it. Any such psymtab will do. */
785 while (pst->user != NULL)
786 pst = pst->user;
787
0df8b418 788 /* If it's been looked up before, return it. */
ccefe4c4
TT
789 if (pst->symtab)
790 return pst->symtab;
791
792 /* If it has not yet been read in, read it. */
793 if (!pst->readin)
794 {
795 struct cleanup *back_to = increment_reading_symtab ();
ad3bbd48 796
ccefe4c4
TT
797 (*pst->read_symtab) (pst);
798 do_cleanups (back_to);
799 }
800
801 return pst->symtab;
802}
803
804static void
805relocate_psymtabs (struct objfile *objfile,
806 struct section_offsets *new_offsets,
807 struct section_offsets *delta)
808{
809 struct partial_symbol **psym;
810 struct partial_symtab *p;
811
b11896a5 812 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
ccefe4c4
TT
813 {
814 p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
815 p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
816 }
817
818 for (psym = objfile->global_psymbols.list;
819 psym < objfile->global_psymbols.next;
820 psym++)
821 {
822 fixup_psymbol_section (*psym, objfile);
823 if (SYMBOL_SECTION (*psym) >= 0)
824 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
825 SYMBOL_SECTION (*psym));
826 }
827 for (psym = objfile->static_psymbols.list;
828 psym < objfile->static_psymbols.next;
829 psym++)
830 {
831 fixup_psymbol_section (*psym, objfile);
832 if (SYMBOL_SECTION (*psym) >= 0)
833 SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta,
834 SYMBOL_SECTION (*psym));
835 }
836}
837
838static struct symtab *
839find_last_source_symtab_from_partial (struct objfile *ofp)
840{
ccefe4c4
TT
841 struct partial_symtab *ps;
842 struct partial_symtab *cs_pst = 0;
843
b11896a5 844 ALL_OBJFILE_PSYMTABS_REQUIRED (ofp, ps)
ccefe4c4
TT
845 {
846 const char *name = ps->filename;
847 int len = strlen (name);
ad3bbd48 848
ccefe4c4
TT
849 if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0
850 || strcmp (name, "<<C++-namespaces>>") == 0)))
851 cs_pst = ps;
852 }
853
854 if (cs_pst)
855 {
856 if (cs_pst->readin)
857 {
858 internal_error (__FILE__, __LINE__,
859 _("select_source_symtab: "
860 "readin pst found and no symtabs."));
861 }
862 else
a2ca7a52 863 return psymtab_to_symtab (cs_pst);
ccefe4c4
TT
864 }
865 return NULL;
866}
867
868static void
869forget_cached_source_info_partial (struct objfile *objfile)
870{
871 struct partial_symtab *pst;
872
b11896a5 873 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
ccefe4c4
TT
874 {
875 if (pst->fullname != NULL)
876 {
877 xfree (pst->fullname);
878 pst->fullname = NULL;
879 }
880 }
881}
882
883static void
884print_partial_symbols (struct gdbarch *gdbarch,
885 struct partial_symbol **p, int count, char *what,
886 struct ui_file *outfile)
887{
888 fprintf_filtered (outfile, " %s partial symbols:\n", what);
889 while (count-- > 0)
890 {
891 fprintf_filtered (outfile, " `%s'", SYMBOL_LINKAGE_NAME (*p));
892 if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
893 {
894 fprintf_filtered (outfile, " `%s'", SYMBOL_DEMANGLED_NAME (*p));
895 }
896 fputs_filtered (", ", outfile);
897 switch (SYMBOL_DOMAIN (*p))
898 {
899 case UNDEF_DOMAIN:
900 fputs_filtered ("undefined domain, ", outfile);
901 break;
902 case VAR_DOMAIN:
0df8b418 903 /* This is the usual thing -- don't print it. */
ccefe4c4
TT
904 break;
905 case STRUCT_DOMAIN:
906 fputs_filtered ("struct domain, ", outfile);
907 break;
908 case LABEL_DOMAIN:
909 fputs_filtered ("label domain, ", outfile);
910 break;
911 default:
912 fputs_filtered ("<invalid domain>, ", outfile);
913 break;
914 }
915 switch (SYMBOL_CLASS (*p))
916 {
917 case LOC_UNDEF:
918 fputs_filtered ("undefined", outfile);
919 break;
920 case LOC_CONST:
921 fputs_filtered ("constant int", outfile);
922 break;
923 case LOC_STATIC:
924 fputs_filtered ("static", outfile);
925 break;
926 case LOC_REGISTER:
927 fputs_filtered ("register", outfile);
928 break;
929 case LOC_ARG:
930 fputs_filtered ("pass by value", outfile);
931 break;
932 case LOC_REF_ARG:
933 fputs_filtered ("pass by reference", outfile);
934 break;
935 case LOC_REGPARM_ADDR:
936 fputs_filtered ("register address parameter", outfile);
937 break;
938 case LOC_LOCAL:
939 fputs_filtered ("stack parameter", outfile);
940 break;
941 case LOC_TYPEDEF:
942 fputs_filtered ("type", outfile);
943 break;
944 case LOC_LABEL:
945 fputs_filtered ("label", outfile);
946 break;
947 case LOC_BLOCK:
948 fputs_filtered ("function", outfile);
949 break;
950 case LOC_CONST_BYTES:
951 fputs_filtered ("constant bytes", outfile);
952 break;
953 case LOC_UNRESOLVED:
954 fputs_filtered ("unresolved", outfile);
955 break;
956 case LOC_OPTIMIZED_OUT:
957 fputs_filtered ("optimized out", outfile);
958 break;
959 case LOC_COMPUTED:
960 fputs_filtered ("computed at runtime", outfile);
961 break;
962 default:
963 fputs_filtered ("<invalid location>", outfile);
964 break;
965 }
966 fputs_filtered (", ", outfile);
967 fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
968 fprintf_filtered (outfile, "\n");
969 p++;
970 }
971}
972
973static void
974dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
975 struct ui_file *outfile)
976{
977 struct gdbarch *gdbarch = get_objfile_arch (objfile);
978 int i;
979
b4c41fc7
DE
980 if (psymtab->anonymous)
981 {
982 fprintf_filtered (outfile, "\nAnonymous partial symtab (%s) ",
983 psymtab->filename);
984 }
985 else
986 {
987 fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
988 psymtab->filename);
989 }
ccefe4c4
TT
990 fprintf_filtered (outfile, "(object ");
991 gdb_print_host_address (psymtab, outfile);
992 fprintf_filtered (outfile, ")\n\n");
993 fprintf_unfiltered (outfile, " Read from object file %s (",
994 objfile->name);
995 gdb_print_host_address (objfile, outfile);
996 fprintf_unfiltered (outfile, ")\n");
997
998 if (psymtab->readin)
999 {
1000 fprintf_filtered (outfile,
1001 " Full symtab was read (at ");
1002 gdb_print_host_address (psymtab->symtab, outfile);
1003 fprintf_filtered (outfile, " by function at ");
1004 gdb_print_host_address (psymtab->read_symtab, outfile);
1005 fprintf_filtered (outfile, ")\n");
1006 }
1007
1008 fprintf_filtered (outfile, " Relocate symbols by ");
1009 for (i = 0; i < psymtab->objfile->num_sections; ++i)
1010 {
1011 if (i != 0)
1012 fprintf_filtered (outfile, ", ");
1013 wrap_here (" ");
1014 fputs_filtered (paddress (gdbarch,
1015 ANOFFSET (psymtab->section_offsets, i)),
1016 outfile);
1017 }
1018 fprintf_filtered (outfile, "\n");
1019
1020 fprintf_filtered (outfile, " Symbols cover text addresses ");
1021 fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
1022 fprintf_filtered (outfile, "-");
1023 fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
1024 fprintf_filtered (outfile, "\n");
9750bca9
JK
1025 fprintf_filtered (outfile, " Address map supported - %s.\n",
1026 psymtab->psymtabs_addrmap_supported ? "yes" : "no");
ccefe4c4
TT
1027 fprintf_filtered (outfile, " Depends on %d other partial symtabs.\n",
1028 psymtab->number_of_dependencies);
1029 for (i = 0; i < psymtab->number_of_dependencies; i++)
1030 {
1031 fprintf_filtered (outfile, " %d ", i);
1032 gdb_print_host_address (psymtab->dependencies[i], outfile);
1033 fprintf_filtered (outfile, " %s\n",
1034 psymtab->dependencies[i]->filename);
1035 }
9439a077
TT
1036 if (psymtab->user != NULL)
1037 {
1038 fprintf_filtered (outfile, " Shared partial symtab with user ");
1039 gdb_print_host_address (psymtab->user, outfile);
1040 fprintf_filtered (outfile, "\n");
1041 }
ccefe4c4
TT
1042 if (psymtab->n_global_syms > 0)
1043 {
1044 print_partial_symbols (gdbarch,
1045 objfile->global_psymbols.list
1046 + psymtab->globals_offset,
1047 psymtab->n_global_syms, "Global", outfile);
1048 }
1049 if (psymtab->n_static_syms > 0)
1050 {
1051 print_partial_symbols (gdbarch,
1052 objfile->static_psymbols.list
1053 + psymtab->statics_offset,
1054 psymtab->n_static_syms, "Static", outfile);
1055 }
1056 fprintf_filtered (outfile, "\n");
1057}
1058
1059static void
1060print_psymtab_stats_for_objfile (struct objfile *objfile)
1061{
1062 int i;
1063 struct partial_symtab *ps;
ad3bbd48 1064
ccefe4c4 1065 i = 0;
b11896a5 1066 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
ccefe4c4
TT
1067 {
1068 if (ps->readin == 0)
1069 i++;
1070 }
1071 printf_filtered (_(" Number of psym tables (not yet expanded): %d\n"), i);
1072}
1073
1074static void
1075dump_psymtabs_for_objfile (struct objfile *objfile)
1076{
1077 struct partial_symtab *psymtab;
1078
1079 if (objfile->psymtabs)
1080 {
1081 printf_filtered ("Psymtabs:\n");
1082 for (psymtab = objfile->psymtabs;
1083 psymtab != NULL;
1084 psymtab = psymtab->next)
1085 {
1086 printf_filtered ("%s at ",
1087 psymtab->filename);
1088 gdb_print_host_address (psymtab, gdb_stdout);
1089 printf_filtered (", ");
1090 if (psymtab->objfile != objfile)
1091 {
1092 printf_filtered ("NOT ON CHAIN! ");
1093 }
1094 wrap_here (" ");
1095 }
1096 printf_filtered ("\n\n");
1097 }
1098}
1099
1100/* Look through the partial symtabs for all symbols which begin
0df8b418 1101 by matching FUNC_NAME. Make sure we read that symbol table in. */
ccefe4c4
TT
1102
1103static void
1104read_symtabs_for_function (struct objfile *objfile, const char *func_name)
1105{
1106 struct partial_symtab *ps;
1107
b11896a5 1108 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
ccefe4c4
TT
1109 {
1110 if (ps->readin)
1111 continue;
1112
1113 if ((lookup_partial_symbol (ps, func_name, 1, VAR_DOMAIN)
1114 != NULL)
1115 || (lookup_partial_symbol (ps, func_name, 0, VAR_DOMAIN)
1116 != NULL))
1117 psymtab_to_symtab (ps);
1118 }
1119}
1120
1121static void
1122expand_partial_symbol_tables (struct objfile *objfile)
1123{
1124 struct partial_symtab *psymtab;
1125
b11896a5 1126 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
ccefe4c4
TT
1127 {
1128 psymtab_to_symtab (psymtab);
1129 }
1130}
1131
1132static void
1133read_psymtabs_with_filename (struct objfile *objfile, const char *filename)
1134{
1135 struct partial_symtab *p;
1136
b11896a5 1137 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
ccefe4c4 1138 {
b4c41fc7
DE
1139 /* Anonymous psymtabs don't have a name of a source file. */
1140 if (p->anonymous)
1141 continue;
1142
0ba1096a 1143 if (filename_cmp (filename, p->filename) == 0)
a2ca7a52 1144 psymtab_to_symtab (p);
ccefe4c4
TT
1145 }
1146}
1147
ccefe4c4
TT
1148static void
1149map_symbol_filenames_psymtab (struct objfile *objfile,
74e2f255
DE
1150 symbol_filename_ftype *fun, void *data,
1151 int need_fullname)
ccefe4c4
TT
1152{
1153 struct partial_symtab *ps;
1154
b11896a5 1155 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
ccefe4c4
TT
1156 {
1157 const char *fullname;
1158
1159 if (ps->readin)
1160 continue;
1161
f80c6f3f
DE
1162 /* We can skip shared psymtabs here, because any file name will be
1163 attached to the unshared psymtab. */
1164 if (ps->user != NULL)
1165 continue;
1166
b4c41fc7
DE
1167 /* Anonymous psymtabs don't have a file name. */
1168 if (ps->anonymous)
1169 continue;
1170
821296b7 1171 QUIT;
74e2f255
DE
1172 if (need_fullname)
1173 fullname = psymtab_to_fullname (ps);
1174 else
1175 fullname = NULL;
2837d59e 1176 (*fun) (ps->filename, fullname, data);
ccefe4c4
TT
1177 }
1178}
1179
ccefe4c4
TT
1180/* Finds the fullname that a partial_symtab represents.
1181
1182 If this functions finds the fullname, it will save it in ps->fullname
1183 and it will also return the value.
1184
1185 If this function fails to find the file that this partial_symtab represents,
1186 NULL will be returned and ps->fullname will be set to NULL. */
256f06f3 1187
ccefe4c4
TT
1188static char *
1189psymtab_to_fullname (struct partial_symtab *ps)
1190{
1191 int r;
1192
1193 if (!ps)
1194 return NULL;
b4c41fc7
DE
1195 if (ps->anonymous)
1196 return NULL;
ccefe4c4 1197
256f06f3
DE
1198 /* Use cached copy if we have it.
1199 We rely on forget_cached_source_info being called appropriately
1200 to handle cases like the file being moved. */
1201 if (ps->fullname)
1202 return ps->fullname;
1203
ccefe4c4
TT
1204 r = find_and_open_source (ps->filename, ps->dirname, &ps->fullname);
1205
1206 if (r >= 0)
1207 {
1208 close (r);
1209 return ps->fullname;
1210 }
1211
1212 return NULL;
1213}
1214
dd786858 1215static const char *
ccefe4c4
TT
1216find_symbol_file_from_partial (struct objfile *objfile, const char *name)
1217{
1218 struct partial_symtab *pst;
1219
b11896a5 1220 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
ccefe4c4
TT
1221 {
1222 if (lookup_partial_symbol (pst, name, 1, VAR_DOMAIN))
1223 return pst->filename;
1224 }
1225 return NULL;
1226}
1227
40658b94
PH
1228/* For all symbols, s, in BLOCK that are in NAMESPACE and match NAME
1229 according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
1230 BLOCK is assumed to come from OBJFILE. Returns 1 iff CALLBACK
1231 ever returns non-zero, and otherwise returns 0. */
ccefe4c4 1232
40658b94
PH
1233static int
1234map_block (const char *name, domain_enum namespace, struct objfile *objfile,
1235 struct block *block,
1236 int (*callback) (struct block *, struct symbol *, void *),
2edb89d3 1237 void *data, symbol_compare_ftype *match)
ccefe4c4 1238{
8157b174 1239 struct block_iterator iter;
40658b94 1240 struct symbol *sym;
ccefe4c4 1241
8157b174
TT
1242 for (sym = block_iter_match_first (block, name, match, &iter);
1243 sym != NULL; sym = block_iter_match_next (name, match, &iter))
ccefe4c4 1244 {
40658b94
PH
1245 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
1246 SYMBOL_DOMAIN (sym), namespace))
1247 {
1248 if (callback (block, sym, data))
1249 return 1;
1250 }
ccefe4c4
TT
1251 }
1252
40658b94 1253 return 0;
ccefe4c4
TT
1254}
1255
40658b94
PH
1256/* Psymtab version of map_matching_symbols. See its definition in
1257 the definition of quick_symbol_functions in symfile.h. */
1258
ccefe4c4 1259static void
40658b94
PH
1260map_matching_symbols_psymtab (const char *name, domain_enum namespace,
1261 struct objfile *objfile, int global,
1262 int (*callback) (struct block *,
1263 struct symbol *, void *),
1264 void *data,
2edb89d3
JK
1265 symbol_compare_ftype *match,
1266 symbol_compare_ftype *ordered_compare)
ccefe4c4 1267{
40658b94 1268 const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
ccefe4c4
TT
1269 struct partial_symtab *ps;
1270
b11896a5 1271 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
ccefe4c4
TT
1272 {
1273 QUIT;
1274 if (ps->readin
40658b94
PH
1275 || match_partial_symbol (ps, global, name, namespace, match,
1276 ordered_compare))
ccefe4c4 1277 {
a2ca7a52 1278 struct symtab *s = psymtab_to_symtab (ps);
40658b94 1279 struct block *block;
ad3bbd48 1280
ccefe4c4
TT
1281 if (s == NULL || !s->primary)
1282 continue;
40658b94
PH
1283 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), block_kind);
1284 if (map_block (name, namespace, objfile, block,
1285 callback, data, match))
1286 return;
1287 if (callback (block, NULL, data))
1288 return;
ccefe4c4
TT
1289 }
1290 }
40658b94 1291}
ccefe4c4 1292
9439a077
TT
1293/* A helper for expand_symtabs_matching_via_partial that handles
1294 searching included psymtabs. This returns 1 if a symbol is found,
1295 and zero otherwise. It also updates the 'searched_flag' on the
1296 various psymtabs that it searches. */
1297
1298static int
1299recursively_search_psymtabs (struct partial_symtab *ps,
1300 struct objfile *objfile,
1301 enum search_domain kind,
1302 int (*name_matcher) (const char *, void *),
1303 void *data)
1304{
1305 struct partial_symbol **psym;
1306 struct partial_symbol **bound, **gbound, **sbound;
1307 int keep_going = 1;
1308 int result = PST_SEARCHED_AND_NOT_FOUND;
1309 int i;
1310
1311 if (ps->searched_flag != PST_NOT_SEARCHED)
1312 return ps->searched_flag == PST_SEARCHED_AND_FOUND;
1313
1314 /* Recurse into shared psymtabs first, because they may have already
1315 been searched, and this could save some time. */
1316 for (i = 0; i < ps->number_of_dependencies; ++i)
1317 {
1318 int r;
1319
1320 /* Skip non-shared dependencies, these are handled elsewhere. */
1321 if (ps->dependencies[i]->user == NULL)
1322 continue;
1323
1324 r = recursively_search_psymtabs (ps->dependencies[i],
1325 objfile, kind, name_matcher, data);
1326 if (r != 0)
1327 {
1328 ps->searched_flag = PST_SEARCHED_AND_FOUND;
1329 return 1;
1330 }
1331 }
1332
1333 gbound = (objfile->global_psymbols.list
1334 + ps->globals_offset + ps->n_global_syms);
1335 sbound = (objfile->static_psymbols.list
1336 + ps->statics_offset + ps->n_static_syms);
1337 bound = gbound;
1338
1339 /* Go through all of the symbols stored in a partial
1340 symtab in one loop. */
1341 psym = objfile->global_psymbols.list + ps->globals_offset;
1342 while (keep_going)
1343 {
1344 if (psym >= bound)
1345 {
1346 if (bound == gbound && ps->n_static_syms != 0)
1347 {
1348 psym = objfile->static_psymbols.list + ps->statics_offset;
1349 bound = sbound;
1350 }
1351 else
1352 keep_going = 0;
1353 continue;
1354 }
1355 else
1356 {
1357 QUIT;
1358
1359 if ((kind == ALL_DOMAIN
1360 || (kind == VARIABLES_DOMAIN
1361 && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
1362 && SYMBOL_CLASS (*psym) != LOC_BLOCK)
1363 || (kind == FUNCTIONS_DOMAIN
1364 && SYMBOL_CLASS (*psym) == LOC_BLOCK)
1365 || (kind == TYPES_DOMAIN
1366 && SYMBOL_CLASS (*psym) == LOC_TYPEDEF))
1367 && (*name_matcher) (SYMBOL_SEARCH_NAME (*psym), data))
1368 {
1369 /* Found a match, so notify our caller. */
1370 result = PST_SEARCHED_AND_FOUND;
1371 keep_going = 0;
1372 }
1373 }
1374 psym++;
1375 }
1376
1377 ps->searched_flag = result;
1378 return result == PST_SEARCHED_AND_FOUND;
1379}
1380
ccefe4c4 1381static void
f8eba3c6
TT
1382expand_symtabs_matching_via_partial
1383 (struct objfile *objfile,
1384 int (*file_matcher) (const char *, void *),
e078317b 1385 int (*name_matcher) (const char *, void *),
f8eba3c6
TT
1386 enum search_domain kind,
1387 void *data)
ccefe4c4
TT
1388{
1389 struct partial_symtab *ps;
1390
9439a077 1391 /* Clear the search flags. */
b11896a5 1392 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
ccefe4c4 1393 {
9439a077
TT
1394 ps->searched_flag = PST_NOT_SEARCHED;
1395 }
ccefe4c4 1396
9439a077
TT
1397 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
1398 {
ccefe4c4
TT
1399 if (ps->readin)
1400 continue;
1401
9439a077
TT
1402 /* We skip shared psymtabs because file-matching doesn't apply
1403 to them; but we search them later in the loop. */
1404 if (ps->user != NULL)
ccefe4c4
TT
1405 continue;
1406
b4c41fc7
DE
1407 if (file_matcher)
1408 {
1409 if (ps->anonymous)
1410 continue;
1411 if (! (*file_matcher) (ps->filename, data))
1412 continue;
1413 }
ccefe4c4 1414
9439a077
TT
1415 if (recursively_search_psymtabs (ps, objfile, kind, name_matcher, data))
1416 psymtab_to_symtab (ps);
ccefe4c4
TT
1417 }
1418}
1419
1420static int
1421objfile_has_psyms (struct objfile *objfile)
1422{
1423 return objfile->psymtabs != NULL;
1424}
1425
1426const struct quick_symbol_functions psym_functions =
1427{
1428 objfile_has_psyms,
1429 find_last_source_symtab_from_partial,
1430 forget_cached_source_info_partial,
f8eba3c6 1431 partial_map_symtabs_matching_filename,
ccefe4c4 1432 lookup_symbol_aux_psymtabs,
774b6a14 1433 pre_expand_symtabs_matching_psymtabs,
ccefe4c4
TT
1434 print_psymtab_stats_for_objfile,
1435 dump_psymtabs_for_objfile,
1436 relocate_psymtabs,
1437 read_symtabs_for_function,
1438 expand_partial_symbol_tables,
1439 read_psymtabs_with_filename,
1440 find_symbol_file_from_partial,
40658b94 1441 map_matching_symbols_psymtab,
ccefe4c4
TT
1442 expand_symtabs_matching_via_partial,
1443 find_pc_sect_symtab_from_partial,
ccefe4c4
TT
1444 map_symbol_filenames_psymtab
1445};
1446
1447\f
1448
1449/* This compares two partial symbols by names, using strcmp_iw_ordered
1450 for the comparison. */
1451
1452static int
1453compare_psymbols (const void *s1p, const void *s2p)
1454{
1455 struct partial_symbol *const *s1 = s1p;
1456 struct partial_symbol *const *s2 = s2p;
1457
1458 return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*s1),
1459 SYMBOL_SEARCH_NAME (*s2));
1460}
1461
1462void
1463sort_pst_symbols (struct partial_symtab *pst)
1464{
0df8b418 1465 /* Sort the global list; don't sort the static list. */
ccefe4c4
TT
1466
1467 qsort (pst->objfile->global_psymbols.list + pst->globals_offset,
1468 pst->n_global_syms, sizeof (struct partial_symbol *),
1469 compare_psymbols);
1470}
1471
1472/* Allocate and partially fill a partial symtab. It will be
1473 completely filled at the end of the symbol list.
1474
0df8b418 1475 FILENAME is the name of the symbol-file we are reading from. */
ccefe4c4
TT
1476
1477struct partial_symtab *
1478start_psymtab_common (struct objfile *objfile,
1479 struct section_offsets *section_offsets,
1480 const char *filename,
1481 CORE_ADDR textlow, struct partial_symbol **global_syms,
1482 struct partial_symbol **static_syms)
1483{
1484 struct partial_symtab *psymtab;
1485
1486 psymtab = allocate_psymtab (filename, objfile);
1487 psymtab->section_offsets = section_offsets;
1488 psymtab->textlow = textlow;
1489 psymtab->texthigh = psymtab->textlow; /* default */
1490 psymtab->globals_offset = global_syms - objfile->global_psymbols.list;
1491 psymtab->statics_offset = static_syms - objfile->static_psymbols.list;
1492 return (psymtab);
1493}
1494
cbd70537
SW
1495/* Calculate a hash code for the given partial symbol. The hash is
1496 calculated using the symbol's value, language, domain, class
0df8b418 1497 and name. These are the values which are set by
cbd70537
SW
1498 add_psymbol_to_bcache. */
1499
710e1a31 1500static unsigned long
cbd70537
SW
1501psymbol_hash (const void *addr, int length)
1502{
1503 unsigned long h = 0;
1504 struct partial_symbol *psymbol = (struct partial_symbol *) addr;
1505 unsigned int lang = psymbol->ginfo.language;
1506 unsigned int domain = PSYMBOL_DOMAIN (psymbol);
1507 unsigned int class = PSYMBOL_CLASS (psymbol);
1508
1509 h = hash_continue (&psymbol->ginfo.value, sizeof (psymbol->ginfo.value), h);
1510 h = hash_continue (&lang, sizeof (unsigned int), h);
1511 h = hash_continue (&domain, sizeof (unsigned int), h);
1512 h = hash_continue (&class, sizeof (unsigned int), h);
1513 h = hash_continue (psymbol->ginfo.name, strlen (psymbol->ginfo.name), h);
1514
1515 return h;
1516}
1517
1518/* Returns true if the symbol at addr1 equals the symbol at addr2.
1519 For the comparison this function uses a symbols value,
1520 language, domain, class and name. */
1521
710e1a31 1522static int
cbd70537
SW
1523psymbol_compare (const void *addr1, const void *addr2, int length)
1524{
1525 struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
1526 struct partial_symbol *sym2 = (struct partial_symbol *) addr2;
1527
1528 return (memcmp (&sym1->ginfo.value, &sym1->ginfo.value,
1529 sizeof (sym1->ginfo.value)) == 0
1530 && sym1->ginfo.language == sym2->ginfo.language
1531 && PSYMBOL_DOMAIN (sym1) == PSYMBOL_DOMAIN (sym2)
1532 && PSYMBOL_CLASS (sym1) == PSYMBOL_CLASS (sym2)
1533 && sym1->ginfo.name == sym2->ginfo.name);
1534}
1535
710e1a31
SW
1536/* Initialize a partial symbol bcache. */
1537
1538struct psymbol_bcache *
1539psymbol_bcache_init (void)
1540{
1541 struct psymbol_bcache *bcache = XCALLOC (1, struct psymbol_bcache);
1542 bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare);
1543 return bcache;
1544}
1545
1546/* Free a partial symbol bcache. */
1547void
1548psymbol_bcache_free (struct psymbol_bcache *bcache)
1549{
1550 if (bcache == NULL)
1551 return;
1552
1553 bcache_xfree (bcache->bcache);
1554 xfree (bcache);
1555}
1556
0df8b418 1557/* Return the internal bcache of the psymbol_bcache BCACHE. */
710e1a31
SW
1558
1559struct bcache *
1560psymbol_bcache_get_bcache (struct psymbol_bcache *bcache)
1561{
1562 return bcache->bcache;
1563}
1564
1565/* Find a copy of the SYM in BCACHE. If BCACHE has never seen this
1566 symbol before, add a copy to BCACHE. In either case, return a pointer
1567 to BCACHE's copy of the symbol. If optional ADDED is not NULL, return
1568 1 in case of new entry or 0 if returning an old entry. */
1569
1570static const struct partial_symbol *
1571psymbol_bcache_full (struct partial_symbol *sym,
1572 struct psymbol_bcache *bcache,
1573 int *added)
1574{
1575 return bcache_full (sym,
1576 sizeof (struct partial_symbol),
1577 bcache->bcache,
1578 added);
1579}
1580
ccefe4c4
TT
1581/* Helper function, initialises partial symbol structure and stashes
1582 it into objfile's bcache. Note that our caching mechanism will
1583 use all fields of struct partial_symbol to determine hash value of the
1584 structure. In other words, having two symbols with the same name but
1585 different domain (or address) is possible and correct. */
1586
1587static const struct partial_symbol *
72b9f47f 1588add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
ccefe4c4
TT
1589 domain_enum domain,
1590 enum address_class class,
1591 long val, /* Value as a long */
1592 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1593 enum language language, struct objfile *objfile,
1594 int *added)
1595{
cbd70537
SW
1596 struct partial_symbol psymbol;
1597
fc956729
SW
1598 /* We must ensure that the entire 'value' field has been zeroed
1599 before assigning to it, because an assignment may not write the
1600 entire field. */
1601 memset (&psymbol.ginfo.value, 0, sizeof (psymbol.ginfo.value));
1602
0df8b418 1603 /* val and coreaddr are mutually exclusive, one of them *will* be zero. */
ccefe4c4
TT
1604 if (val != 0)
1605 {
1606 SYMBOL_VALUE (&psymbol) = val;
1607 }
1608 else
1609 {
1610 SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
1611 }
1612 SYMBOL_SECTION (&psymbol) = 0;
fc956729 1613 SYMBOL_OBJ_SECTION (&psymbol) = NULL;
33e5013e 1614 SYMBOL_SET_LANGUAGE (&psymbol, language);
ccefe4c4
TT
1615 PSYMBOL_DOMAIN (&psymbol) = domain;
1616 PSYMBOL_CLASS (&psymbol) = class;
1617
1618 SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
1619
0df8b418 1620 /* Stash the partial symbol away in the cache. */
710e1a31
SW
1621 return psymbol_bcache_full (&psymbol,
1622 objfile->psymbol_cache,
1623 added);
ccefe4c4
TT
1624}
1625
923c6a3d 1626/* Increase the space allocated for LISTP, which is probably
0df8b418 1627 global_psymbols or static_psymbols. This space will eventually
923c6a3d
TT
1628 be freed in free_objfile(). */
1629
1630static void
1631extend_psymbol_list (struct psymbol_allocation_list *listp,
1632 struct objfile *objfile)
1633{
1634 int new_size;
1635
1636 if (listp->size == 0)
1637 {
1638 new_size = 255;
1639 listp->list = (struct partial_symbol **)
1640 xmalloc (new_size * sizeof (struct partial_symbol *));
1641 }
1642 else
1643 {
1644 new_size = listp->size * 2;
1645 listp->list = (struct partial_symbol **)
1646 xrealloc ((char *) listp->list,
1647 new_size * sizeof (struct partial_symbol *));
1648 }
1649 /* Next assumes we only went one over. Should be good if
0df8b418 1650 program works correctly. */
923c6a3d
TT
1651 listp->next = listp->list + listp->size;
1652 listp->size = new_size;
1653}
1654
ccefe4c4
TT
1655/* Helper function, adds partial symbol to the given partial symbol
1656 list. */
1657
1658static void
1659append_psymbol_to_list (struct psymbol_allocation_list *list,
1660 const struct partial_symbol *psym,
1661 struct objfile *objfile)
1662{
1663 if (list->next >= list->list + list->size)
1664 extend_psymbol_list (list, objfile);
1665 *list->next++ = (struct partial_symbol *) psym;
1666 OBJSTAT (objfile, n_psyms++);
1667}
1668
1669/* Add a symbol with a long value to a psymtab.
1670 Since one arg is a struct, we pass in a ptr and deref it (sigh).
1671 Return the partial symbol that has been added. */
1672
7dc25483 1673void
72b9f47f 1674add_psymbol_to_list (const char *name, int namelength, int copy_name,
ccefe4c4
TT
1675 domain_enum domain,
1676 enum address_class class,
1677 struct psymbol_allocation_list *list,
1678 long val, /* Value as a long */
1679 CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
1680 enum language language, struct objfile *objfile)
1681{
1682 const struct partial_symbol *psym;
1683
1684 int added;
1685
0df8b418 1686 /* Stash the partial symbol away in the cache. */
ccefe4c4
TT
1687 psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, class,
1688 val, coreaddr, language, objfile, &added);
1689
1690 /* Do not duplicate global partial symbols. */
1691 if (list == &objfile->global_psymbols
1692 && !added)
7dc25483 1693 return;
ccefe4c4 1694
0df8b418 1695 /* Save pointer to partial symbol in psymtab, growing symtab if needed. */
ccefe4c4 1696 append_psymbol_to_list (list, psym, objfile);
ccefe4c4
TT
1697}
1698
1699/* Initialize storage for partial symbols. */
1700
1701void
1702init_psymbol_list (struct objfile *objfile, int total_symbols)
1703{
1704 /* Free any previously allocated psymbol lists. */
1705
1706 if (objfile->global_psymbols.list)
1707 {
1708 xfree (objfile->global_psymbols.list);
1709 }
1710 if (objfile->static_psymbols.list)
1711 {
1712 xfree (objfile->static_psymbols.list);
1713 }
1714
1715 /* Current best guess is that approximately a twentieth
1716 of the total symbols (in a debugging file) are global or static
0df8b418 1717 oriented symbols. */
ccefe4c4
TT
1718
1719 objfile->global_psymbols.size = total_symbols / 10;
1720 objfile->static_psymbols.size = total_symbols / 10;
1721
1722 if (objfile->global_psymbols.size > 0)
1723 {
1724 objfile->global_psymbols.next =
1725 objfile->global_psymbols.list = (struct partial_symbol **)
1726 xmalloc ((objfile->global_psymbols.size
1727 * sizeof (struct partial_symbol *)));
1728 }
1729 if (objfile->static_psymbols.size > 0)
1730 {
1731 objfile->static_psymbols.next =
1732 objfile->static_psymbols.list = (struct partial_symbol **)
1733 xmalloc ((objfile->static_psymbols.size
1734 * sizeof (struct partial_symbol *)));
1735 }
1736}
1737
1738struct partial_symtab *
1739allocate_psymtab (const char *filename, struct objfile *objfile)
1740{
1741 struct partial_symtab *psymtab;
1742
1743 if (objfile->free_psymtabs)
1744 {
1745 psymtab = objfile->free_psymtabs;
1746 objfile->free_psymtabs = psymtab->next;
1747 }
1748 else
1749 psymtab = (struct partial_symtab *)
1750 obstack_alloc (&objfile->objfile_obstack,
1751 sizeof (struct partial_symtab));
1752
1753 memset (psymtab, 0, sizeof (struct partial_symtab));
1754 psymtab->filename = obsavestring (filename, strlen (filename),
1755 &objfile->objfile_obstack);
1756 psymtab->symtab = NULL;
1757
1758 /* Prepend it to the psymtab list for the objfile it belongs to.
1759 Psymtabs are searched in most recent inserted -> least recent
0df8b418 1760 inserted order. */
ccefe4c4
TT
1761
1762 psymtab->objfile = objfile;
1763 psymtab->next = objfile->psymtabs;
1764 objfile->psymtabs = psymtab;
ccefe4c4 1765
45cfd468
DE
1766 if (symtab_create_debug)
1767 {
1768 /* Be a bit clever with debugging messages, and don't print objfile
1769 every time, only when it changes. */
1770 static char *last_objfile_name = NULL;
1771
1772 if (last_objfile_name == NULL
1773 || strcmp (last_objfile_name, objfile->name) != 0)
1774 {
1775 xfree (last_objfile_name);
1776 last_objfile_name = xstrdup (objfile->name);
1777 fprintf_unfiltered (gdb_stdlog,
1778 "Creating one or more psymtabs for objfile %s ...\n",
1779 last_objfile_name);
1780 }
1781 fprintf_unfiltered (gdb_stdlog,
fd55216c
DE
1782 "Created psymtab %s for module %s.\n",
1783 host_address_to_string (psymtab), filename);
45cfd468
DE
1784 }
1785
ccefe4c4
TT
1786 return (psymtab);
1787}
1788
1789void
1790discard_psymtab (struct partial_symtab *pst)
1791{
1792 struct partial_symtab **prev_pst;
1793
1794 /* From dbxread.c:
1795 Empty psymtabs happen as a result of header files which don't
1796 have any symbols in them. There can be a lot of them. But this
1797 check is wrong, in that a psymtab with N_SLINE entries but
1798 nothing else is not empty, but we don't realize that. Fixing
1799 that without slowing things down might be tricky. */
1800
0df8b418 1801 /* First, snip it out of the psymtab chain. */
ccefe4c4
TT
1802
1803 prev_pst = &(pst->objfile->psymtabs);
1804 while ((*prev_pst) != pst)
1805 prev_pst = &((*prev_pst)->next);
1806 (*prev_pst) = pst->next;
1807
0df8b418 1808 /* Next, put it on a free list for recycling. */
ccefe4c4
TT
1809
1810 pst->next = pst->objfile->free_psymtabs;
1811 pst->objfile->free_psymtabs = pst;
1812}
1813
ccefe4c4
TT
1814\f
1815
1816void
1817maintenance_print_psymbols (char *args, int from_tty)
1818{
1819 char **argv;
1820 struct ui_file *outfile;
1821 struct cleanup *cleanups;
1822 char *symname = NULL;
1823 char *filename = DEV_TTY;
1824 struct objfile *objfile;
1825 struct partial_symtab *ps;
1826
1827 dont_repeat ();
1828
1829 if (args == NULL)
1830 {
3e43a32a
MS
1831 error (_("\
1832print-psymbols takes an output file name and optional symbol file name"));
ccefe4c4
TT
1833 }
1834 argv = gdb_buildargv (args);
1835 cleanups = make_cleanup_freeargv (argv);
1836
1837 if (argv[0] != NULL)
1838 {
1839 filename = argv[0];
0df8b418 1840 /* If a second arg is supplied, it is a source file name to match on. */
ccefe4c4
TT
1841 if (argv[1] != NULL)
1842 {
1843 symname = argv[1];
1844 }
1845 }
1846
1847 filename = tilde_expand (filename);
1848 make_cleanup (xfree, filename);
1849
1850 outfile = gdb_fopen (filename, FOPEN_WT);
1851 if (outfile == 0)
1852 perror_with_name (filename);
1853 make_cleanup_ui_file_delete (outfile);
1854
1855 immediate_quit++;
1856 ALL_PSYMTABS (objfile, ps)
0ba1096a 1857 if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
ccefe4c4
TT
1858 dump_psymtab (objfile, ps, outfile);
1859 immediate_quit--;
1860 do_cleanups (cleanups);
1861}
1862
1863/* List all the partial symbol tables whose names match REGEXP (optional). */
1864void
1865maintenance_info_psymtabs (char *regexp, int from_tty)
1866{
1867 struct program_space *pspace;
1868 struct objfile *objfile;
1869
1870 if (regexp)
1871 re_comp (regexp);
1872
1873 ALL_PSPACES (pspace)
1874 ALL_PSPACE_OBJFILES (pspace, objfile)
1875 {
1876 struct gdbarch *gdbarch = get_objfile_arch (objfile);
1877 struct partial_symtab *psymtab;
1878
1879 /* We don't want to print anything for this objfile until we
1880 actually find a symtab whose name matches. */
1881 int printed_objfile_start = 0;
1882
b11896a5 1883 ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
ccefe4c4
TT
1884 {
1885 QUIT;
1886
1887 if (! regexp
1888 || re_exec (psymtab->filename))
1889 {
1890 if (! printed_objfile_start)
1891 {
1892 printf_filtered ("{ objfile %s ", objfile->name);
1893 wrap_here (" ");
1894 printf_filtered ("((struct objfile *) %s)\n",
1895 host_address_to_string (objfile));
1896 printed_objfile_start = 1;
1897 }
1898
1899 printf_filtered (" { psymtab %s ", psymtab->filename);
1900 wrap_here (" ");
1901 printf_filtered ("((struct partial_symtab *) %s)\n",
1902 host_address_to_string (psymtab));
1903
1904 printf_filtered (" readin %s\n",
1905 psymtab->readin ? "yes" : "no");
1906 printf_filtered (" fullname %s\n",
3e43a32a
MS
1907 psymtab->fullname
1908 ? psymtab->fullname : "(null)");
ccefe4c4
TT
1909 printf_filtered (" text addresses ");
1910 fputs_filtered (paddress (gdbarch, psymtab->textlow),
1911 gdb_stdout);
1912 printf_filtered (" -- ");
1913 fputs_filtered (paddress (gdbarch, psymtab->texthigh),
1914 gdb_stdout);
1915 printf_filtered ("\n");
9750bca9
JK
1916 printf_filtered (" psymtabs_addrmap_supported %s\n",
1917 (psymtab->psymtabs_addrmap_supported
1918 ? "yes" : "no"));
ccefe4c4
TT
1919 printf_filtered (" globals ");
1920 if (psymtab->n_global_syms)
1921 {
1922 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1923 host_address_to_string (psymtab->objfile->global_psymbols.list
1924 + psymtab->globals_offset),
1925 psymtab->n_global_syms);
1926 }
1927 else
1928 printf_filtered ("(none)\n");
1929 printf_filtered (" statics ");
1930 if (psymtab->n_static_syms)
1931 {
1932 printf_filtered ("(* (struct partial_symbol **) %s @ %d)\n",
1933 host_address_to_string (psymtab->objfile->static_psymbols.list
1934 + psymtab->statics_offset),
1935 psymtab->n_static_syms);
1936 }
1937 else
1938 printf_filtered ("(none)\n");
1939 printf_filtered (" dependencies ");
1940 if (psymtab->number_of_dependencies)
1941 {
1942 int i;
1943
1944 printf_filtered ("{\n");
1945 for (i = 0; i < psymtab->number_of_dependencies; i++)
1946 {
1947 struct partial_symtab *dep = psymtab->dependencies[i];
1948
1949 /* Note the string concatenation there --- no comma. */
1950 printf_filtered (" psymtab %s "
1951 "((struct partial_symtab *) %s)\n",
1952 dep->filename,
1953 host_address_to_string (dep));
1954 }
1955 printf_filtered (" }\n");
1956 }
1957 else
1958 printf_filtered ("(none)\n");
1959 printf_filtered (" }\n");
1960 }
1961 }
1962
1963 if (printed_objfile_start)
1964 printf_filtered ("}\n");
1965 }
1966}
1967
1968/* Check consistency of psymtabs and symtabs. */
1969
1970void
1971maintenance_check_symtabs (char *ignore, int from_tty)
1972{
1973 struct symbol *sym;
1974 struct partial_symbol **psym;
1975 struct symtab *s = NULL;
1976 struct partial_symtab *ps;
1977 struct blockvector *bv;
1978 struct objfile *objfile;
1979 struct block *b;
1980 int length;
1981
1982 ALL_PSYMTABS (objfile, ps)
1983 {
1984 struct gdbarch *gdbarch = get_objfile_arch (objfile);
ad3bbd48 1985
a2ca7a52 1986 s = psymtab_to_symtab (ps);
ccefe4c4
TT
1987 if (s == NULL)
1988 continue;
1989 bv = BLOCKVECTOR (s);
1990 b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
1991 psym = ps->objfile->static_psymbols.list + ps->statics_offset;
1992 length = ps->n_static_syms;
1993 while (length--)
1994 {
1995 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
1996 SYMBOL_DOMAIN (*psym));
1997 if (!sym)
1998 {
1999 printf_filtered ("Static symbol `");
2000 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
2001 printf_filtered ("' only found in ");
2002 puts_filtered (ps->filename);
2003 printf_filtered (" psymtab\n");
2004 }
2005 psym++;
2006 }
2007 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
2008 psym = ps->objfile->global_psymbols.list + ps->globals_offset;
2009 length = ps->n_global_syms;
2010 while (length--)
2011 {
2012 sym = lookup_block_symbol (b, SYMBOL_LINKAGE_NAME (*psym),
2013 SYMBOL_DOMAIN (*psym));
2014 if (!sym)
2015 {
2016 printf_filtered ("Global symbol `");
2017 puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
2018 printf_filtered ("' only found in ");
2019 puts_filtered (ps->filename);
2020 printf_filtered (" psymtab\n");
2021 }
2022 psym++;
2023 }
2024 if (ps->texthigh < ps->textlow)
2025 {
2026 printf_filtered ("Psymtab ");
2027 puts_filtered (ps->filename);
2028 printf_filtered (" covers bad range ");
2029 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
2030 printf_filtered (" - ");
2031 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
2032 printf_filtered ("\n");
2033 continue;
2034 }
2035 if (ps->texthigh == 0)
2036 continue;
2037 if (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b))
2038 {
2039 printf_filtered ("Psymtab ");
2040 puts_filtered (ps->filename);
2041 printf_filtered (" covers ");
2042 fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
2043 printf_filtered (" - ");
2044 fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
2045 printf_filtered (" but symtab covers only ");
2046 fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
2047 printf_filtered (" - ");
2048 fputs_filtered (paddress (gdbarch, BLOCK_END (b)), gdb_stdout);
2049 printf_filtered ("\n");
2050 }
2051 }
2052}
2053
2054\f
2055
2056void
e078317b 2057expand_partial_symbol_names (int (*fun) (const char *, void *),
f8eba3c6 2058 void *data)
ccefe4c4
TT
2059{
2060 struct objfile *objfile;
2061
2062 ALL_OBJFILES (objfile)
2063 {
2064 if (objfile->sf)
7b08b9eb
JK
2065 objfile->sf->qf->expand_symtabs_matching (objfile, NULL, fun,
2066 ALL_DOMAIN, data);
ccefe4c4
TT
2067 }
2068}
2069
2070void
74e2f255
DE
2071map_partial_symbol_filenames (symbol_filename_ftype *fun, void *data,
2072 int need_fullname)
ccefe4c4
TT
2073{
2074 struct objfile *objfile;
2075
2076 ALL_OBJFILES (objfile)
2077 {
2078 if (objfile->sf)
74e2f255
DE
2079 objfile->sf->qf->map_symbol_filenames (objfile, fun, data,
2080 need_fullname);
ccefe4c4
TT
2081 }
2082}
This page took 0.360328 seconds and 4 git commands to generate.