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