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