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