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