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