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