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