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