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