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