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