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