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