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