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