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