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