]>
Commit | Line | Data |
---|---|---|
ccefe4c4 | 1 | /* Partial symbol tables. |
95cf5869 | 2 | |
213516ef | 3 | Copyright (C) 2009-2023 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" |
d322d6d6 | 32 | #include "gdbsupport/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> |
7904e961 | 39 | #include "gdbsupport/buildargv.h" |
ccefe4c4 | 40 | |
5c80ed9d TT |
41 | static struct partial_symbol *lookup_partial_symbol (struct objfile *, |
42 | struct partial_symtab *, | |
8c072cb6 TT |
43 | const lookup_name_info &, |
44 | int, | |
ccefe4c4 TT |
45 | domain_enum); |
46 | ||
da5132d3 | 47 | static const char *psymtab_to_fullname (struct partial_symtab *ps); |
ccefe4c4 | 48 | |
5c80ed9d TT |
49 | static struct partial_symbol *find_pc_sect_psymbol (struct objfile *, |
50 | struct partial_symtab *, | |
ccefe4c4 TT |
51 | CORE_ADDR, |
52 | struct obj_section *); | |
53 | ||
43f3e411 DE |
54 | static struct compunit_symtab *psymtab_to_symtab (struct objfile *objfile, |
55 | struct partial_symtab *pst); | |
ccefe4c4 | 56 | |
d320c2b5 TT |
57 | psymtab_storage::~psymtab_storage () |
58 | { | |
6f17252b TT |
59 | partial_symtab *iter = psymtabs; |
60 | while (iter != nullptr) | |
61 | { | |
62 | partial_symtab *next = iter->next; | |
63 | delete iter; | |
64 | iter = next; | |
65 | } | |
d320c2b5 TT |
66 | } |
67 | ||
b596a3c7 TT |
68 | /* See psymtab.h. */ |
69 | ||
abaa2f23 TT |
70 | void |
71 | psymtab_storage::install_psymtab (partial_symtab *pst) | |
b596a3c7 | 72 | { |
abaa2f23 TT |
73 | pst->next = psymtabs; |
74 | psymtabs = pst; | |
b596a3c7 TT |
75 | } |
76 | ||
d320c2b5 TT |
77 | \f |
78 | ||
98aa8321 | 79 | /* See psympriv.h. */ |
b11896a5 | 80 | |
3aa31ce7 | 81 | psymtab_storage::partial_symtab_range |
98aa8321 | 82 | psymbol_functions::partial_symbols (struct objfile *objfile) |
b11896a5 | 83 | { |
98aa8321 | 84 | gdb_assert ((objfile->flags & OBJF_PSYMTABS_READ) != 0); |
3aa31ce7 | 85 | return m_partial_symtabs->range (); |
b11896a5 TT |
86 | } |
87 | ||
ccefe4c4 TT |
88 | /* Find which partial symtab contains PC and SECTION starting at psymtab PST. |
89 | We may find a different psymtab than PST. See FIND_PC_SECT_PSYMTAB. */ | |
90 | ||
91 | static struct partial_symtab * | |
5c80ed9d TT |
92 | find_pc_sect_psymtab_closer (struct objfile *objfile, |
93 | CORE_ADDR pc, struct obj_section *section, | |
ccefe4c4 | 94 | struct partial_symtab *pst, |
77e371c0 | 95 | struct bound_minimal_symbol msymbol) |
ccefe4c4 | 96 | { |
ccefe4c4 TT |
97 | struct partial_symtab *tpst; |
98 | struct partial_symtab *best_pst = pst; | |
79748972 | 99 | CORE_ADDR best_addr = pst->text_low (objfile); |
ccefe4c4 TT |
100 | |
101 | /* An objfile that has its functions reordered might have | |
102 | many partial symbol tables containing the PC, but | |
103 | we want the partial symbol table that contains the | |
104 | function containing the PC. */ | |
100e3935 | 105 | if (section == nullptr) |
ccefe4c4 TT |
106 | return pst; |
107 | ||
77e371c0 | 108 | if (msymbol.minsym == NULL) |
95cf5869 | 109 | return pst; |
ccefe4c4 TT |
110 | |
111 | /* The code range of partial symtabs sometimes overlap, so, in | |
112 | the loop below, we need to check all partial symtabs and | |
0df8b418 | 113 | find the one that fits better for the given PC address. We |
ccefe4c4 TT |
114 | select the partial symtab that contains a symbol whose |
115 | address is closest to the PC address. By closest we mean | |
116 | that find_pc_sect_symbol returns the symbol with address | |
117 | that is closest and still less than the given PC. */ | |
118 | for (tpst = pst; tpst != NULL; tpst = tpst->next) | |
119 | { | |
79748972 | 120 | if (pc >= tpst->text_low (objfile) && pc < tpst->text_high (objfile)) |
ccefe4c4 TT |
121 | { |
122 | struct partial_symbol *p; | |
123 | CORE_ADDR this_addr; | |
124 | ||
125 | /* NOTE: This assumes that every psymbol has a | |
126 | corresponding msymbol, which is not necessarily | |
127 | true; the debug info might be much richer than the | |
128 | object's symbol table. */ | |
5c80ed9d | 129 | p = find_pc_sect_psymbol (objfile, tpst, pc, section); |
ccefe4c4 | 130 | if (p != NULL |
4aeddc50 | 131 | && (p->address (objfile) == msymbol.value_address ())) |
ccefe4c4 TT |
132 | return tpst; |
133 | ||
134 | /* Also accept the textlow value of a psymtab as a | |
135 | "symbol", to provide some support for partial | |
136 | symbol tables with line information but no debug | |
137 | symbols (e.g. those produced by an assembler). */ | |
138 | if (p != NULL) | |
02e9e7f7 | 139 | this_addr = p->address (objfile); |
ccefe4c4 | 140 | else |
79748972 | 141 | this_addr = tpst->text_low (objfile); |
ccefe4c4 TT |
142 | |
143 | /* Check whether it is closer than our current | |
144 | BEST_ADDR. Since this symbol address is | |
145 | necessarily lower or equal to PC, the symbol closer | |
146 | to PC is the symbol which address is the highest. | |
147 | This way we return the psymtab which contains such | |
0df8b418 | 148 | best match symbol. This can help in cases where the |
ccefe4c4 TT |
149 | symbol information/debuginfo is not complete, like |
150 | for instance on IRIX6 with gcc, where no debug info | |
0df8b418 MS |
151 | is emitted for statics. (See also the nodebug.exp |
152 | testcase.) */ | |
ccefe4c4 TT |
153 | if (this_addr > best_addr) |
154 | { | |
155 | best_addr = this_addr; | |
156 | best_pst = tpst; | |
157 | } | |
158 | } | |
159 | } | |
160 | return best_pst; | |
161 | } | |
162 | ||
3aa31ce7 | 163 | /* See psympriv.h. */ |
95cf5869 | 164 | |
3aa31ce7 TT |
165 | struct partial_symtab * |
166 | psymbol_functions::find_pc_sect_psymtab (struct objfile *objfile, | |
167 | CORE_ADDR pc, | |
168 | struct obj_section *section, | |
169 | struct bound_minimal_symbol msymbol) | |
ccefe4c4 | 170 | { |
98aa8321 | 171 | for (partial_symtab *pst : partial_symbols (objfile)) |
32681b48 | 172 | if (pc >= pst->text_low (objfile) && pc < pst->text_high (objfile)) |
ccefe4c4 TT |
173 | { |
174 | struct partial_symtab *best_pst; | |
175 | ||
5c80ed9d TT |
176 | best_pst = find_pc_sect_psymtab_closer (objfile, pc, section, pst, |
177 | msymbol); | |
ccefe4c4 TT |
178 | if (best_pst != NULL) |
179 | return best_pst; | |
180 | } | |
181 | ||
182 | return NULL; | |
183 | } | |
184 | ||
95cf5869 DE |
185 | /* Psymtab version of find_pc_sect_compunit_symtab. See its definition in |
186 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 187 | |
39298a5d TT |
188 | struct compunit_symtab * |
189 | psymbol_functions::find_pc_sect_compunit_symtab | |
190 | (struct objfile *objfile, | |
191 | struct bound_minimal_symbol msymbol, | |
192 | CORE_ADDR pc, | |
193 | struct obj_section *section, | |
194 | int warn_if_readin) | |
ccefe4c4 | 195 | { |
17d66340 | 196 | struct partial_symtab *ps = find_pc_sect_psymtab (objfile, |
17d66340 | 197 | pc, section, |
ccefe4c4 | 198 | msymbol); |
95cf5869 | 199 | if (ps != NULL) |
ccefe4c4 | 200 | { |
5717c425 | 201 | if (warn_if_readin && ps->readin_p (objfile)) |
ccefe4c4 TT |
202 | /* Might want to error() here (in case symtab is corrupt and |
203 | will cause a core dump), but maybe we can successfully | |
204 | continue, so let's not. */ | |
205 | warning (_("\ | |
206 | (Internal error: pc %s in read in psymtab, but not in symtab.)\n"), | |
08feed99 | 207 | paddress (objfile->arch (), pc)); |
5c80ed9d | 208 | psymtab_to_symtab (objfile, ps); |
5717c425 | 209 | return ps->get_compunit_symtab (objfile); |
ccefe4c4 TT |
210 | } |
211 | return NULL; | |
212 | } | |
213 | ||
214 | /* Find which partial symbol within a psymtab matches PC and SECTION. | |
95cf5869 | 215 | Return NULL if none. */ |
ccefe4c4 TT |
216 | |
217 | static struct partial_symbol * | |
5c80ed9d TT |
218 | find_pc_sect_psymbol (struct objfile *objfile, |
219 | struct partial_symtab *psymtab, CORE_ADDR pc, | |
ccefe4c4 TT |
220 | struct obj_section *section) |
221 | { | |
af5bf4ad | 222 | struct partial_symbol *best = NULL; |
ccefe4c4 | 223 | CORE_ADDR best_pc; |
79748972 | 224 | const CORE_ADDR textlow = psymtab->text_low (objfile); |
ccefe4c4 TT |
225 | |
226 | gdb_assert (psymtab != NULL); | |
227 | ||
0df8b418 | 228 | /* Cope with programs that start at address 0. */ |
79748972 | 229 | best_pc = (textlow != 0) ? textlow - 1 : 0; |
ccefe4c4 TT |
230 | |
231 | /* Search the global symbols as well as the static symbols, so that | |
232 | find_pc_partial_function doesn't use a minimal symbol and thus | |
233 | cache a bad endaddr. */ | |
932539d7 | 234 | for (partial_symbol *p : psymtab->global_psymbols) |
ccefe4c4 | 235 | { |
8a6d4234 TT |
236 | if (p->domain == VAR_DOMAIN |
237 | && p->aclass == LOC_BLOCK | |
02e9e7f7 TT |
238 | && pc >= p->address (objfile) |
239 | && (p->address (objfile) > best_pc | |
79748972 | 240 | || (psymtab->text_low (objfile) == 0 |
02e9e7f7 | 241 | && best_pc == 0 && p->address (objfile) == 0))) |
ccefe4c4 | 242 | { |
95cf5869 | 243 | if (section != NULL) /* Match on a specific section. */ |
ccefe4c4 | 244 | { |
8a6d4234 | 245 | if (!matching_obj_sections (p->obj_section (objfile), |
e27d198c | 246 | section)) |
ccefe4c4 TT |
247 | continue; |
248 | } | |
02e9e7f7 | 249 | best_pc = p->address (objfile); |
ccefe4c4 TT |
250 | best = p; |
251 | } | |
252 | } | |
253 | ||
932539d7 | 254 | for (partial_symbol *p : psymtab->static_psymbols) |
ccefe4c4 | 255 | { |
8a6d4234 TT |
256 | if (p->domain == VAR_DOMAIN |
257 | && p->aclass == LOC_BLOCK | |
02e9e7f7 TT |
258 | && pc >= p->address (objfile) |
259 | && (p->address (objfile) > best_pc | |
79748972 | 260 | || (psymtab->text_low (objfile) == 0 |
02e9e7f7 | 261 | && best_pc == 0 && p->address (objfile) == 0))) |
ccefe4c4 | 262 | { |
95cf5869 | 263 | if (section != NULL) /* Match on a specific section. */ |
ccefe4c4 | 264 | { |
8a6d4234 | 265 | if (!matching_obj_sections (p->obj_section (objfile), |
e27d198c | 266 | section)) |
ccefe4c4 TT |
267 | continue; |
268 | } | |
02e9e7f7 | 269 | best_pc = p->address (objfile); |
ccefe4c4 TT |
270 | best = p; |
271 | } | |
272 | } | |
273 | ||
274 | return best; | |
275 | } | |
276 | ||
d3214198 TV |
277 | /* Psymtab version of lookup_global_symbol_language. See its definition in |
278 | the definition of quick_symbol_functions in symfile.h. */ | |
279 | ||
39298a5d TT |
280 | enum language |
281 | psymbol_functions::lookup_global_symbol_language (struct objfile *objfile, | |
282 | const char *name, | |
283 | domain_enum domain, | |
284 | bool *symbol_found_p) | |
d3214198 TV |
285 | { |
286 | *symbol_found_p = false; | |
287 | if (objfile->sf == NULL) | |
288 | return language_unknown; | |
289 | ||
290 | lookup_name_info lookup_name (name, symbol_name_match_type::FULL); | |
291 | ||
98aa8321 | 292 | for (partial_symtab *ps : partial_symbols (objfile)) |
d3214198 TV |
293 | { |
294 | struct partial_symbol *psym; | |
5717c425 | 295 | if (ps->readin_p (objfile)) |
d3214198 TV |
296 | continue; |
297 | ||
298 | psym = lookup_partial_symbol (objfile, ps, lookup_name, 1, domain); | |
299 | if (psym) | |
300 | { | |
301 | *symbol_found_p = true; | |
302 | return psym->ginfo.language (); | |
303 | } | |
304 | } | |
305 | ||
306 | return language_unknown; | |
307 | } | |
308 | ||
b5ec771e PA |
309 | /* Returns true if PSYM matches LOOKUP_NAME. */ |
310 | ||
311 | static bool | |
312 | psymbol_name_matches (partial_symbol *psym, | |
313 | const lookup_name_info &lookup_name) | |
314 | { | |
c1b5c1eb | 315 | const language_defn *lang = language_def (psym->ginfo.language ()); |
b5ec771e | 316 | symbol_name_matcher_ftype *name_match |
c9debfb9 | 317 | = lang->get_symbol_name_matcher (lookup_name); |
c9d95fa3 | 318 | return name_match (psym->ginfo.search_name (), lookup_name, NULL); |
b5ec771e PA |
319 | } |
320 | ||
40658b94 PH |
321 | /* Look in PST for a symbol in DOMAIN whose name matches NAME. Search |
322 | the global block of PST if GLOBAL, and otherwise the static block. | |
323 | MATCH is the comparison operation that returns true iff MATCH (s, | |
324 | NAME), where s is a SYMBOL_SEARCH_NAME. If ORDERED_COMPARE is | |
325 | non-null, the symbols in the block are assumed to be ordered | |
326 | according to it (allowing binary search). It must be compatible | |
327 | with MATCH. Returns the symbol, if found, and otherwise NULL. */ | |
328 | ||
329 | static struct partial_symbol * | |
5c80ed9d TT |
330 | match_partial_symbol (struct objfile *objfile, |
331 | struct partial_symtab *pst, int global, | |
b054970d | 332 | const lookup_name_info &name, domain_enum domain, |
2edb89d3 | 333 | symbol_compare_ftype *ordered_compare) |
40658b94 PH |
334 | { |
335 | struct partial_symbol **start, **psym; | |
336 | struct partial_symbol **top, **real_top, **bottom, **center; | |
932539d7 TT |
337 | int length = (global |
338 | ? pst->global_psymbols.size () | |
339 | : pst->static_psymbols.size ()); | |
40658b94 PH |
340 | int do_linear_search = 1; |
341 | ||
342 | if (length == 0) | |
b5ec771e PA |
343 | return NULL; |
344 | ||
40658b94 | 345 | start = (global ? |
932539d7 TT |
346 | &pst->global_psymbols[0] : |
347 | &pst->static_psymbols[0]); | |
40658b94 PH |
348 | |
349 | if (global && ordered_compare) /* Can use a binary search. */ | |
350 | { | |
351 | do_linear_search = 0; | |
352 | ||
353 | /* Binary search. This search is guaranteed to end with center | |
dda83cd7 SM |
354 | pointing at the earliest partial symbol whose name might be |
355 | correct. At that point *all* partial symbols with an | |
356 | appropriate name will be checked against the correct | |
357 | domain. */ | |
40658b94 PH |
358 | |
359 | bottom = start; | |
360 | top = start + length - 1; | |
361 | real_top = top; | |
362 | while (top > bottom) | |
363 | { | |
364 | center = bottom + (top - bottom) / 2; | |
365 | gdb_assert (center < top); | |
b5ec771e | 366 | |
c1b5c1eb | 367 | enum language lang = (*center)->ginfo.language (); |
e0802d59 | 368 | const char *lang_ln = name.language_lookup_name (lang); |
b5ec771e | 369 | |
c9d95fa3 | 370 | if (ordered_compare ((*center)->ginfo.search_name (), |
af97b416 | 371 | lang_ln) >= 0) |
40658b94 PH |
372 | top = center; |
373 | else | |
374 | bottom = center + 1; | |
375 | } | |
376 | gdb_assert (top == bottom); | |
377 | ||
378 | while (top <= real_top | |
b054970d | 379 | && psymbol_name_matches (*top, name)) |
40658b94 | 380 | { |
c1b5c1eb | 381 | if (symbol_matches_domain ((*top)->ginfo.language (), |
8a6d4234 | 382 | (*top)->domain, domain)) |
40658b94 PH |
383 | return *top; |
384 | top++; | |
385 | } | |
386 | } | |
387 | ||
388 | /* Can't use a binary search or else we found during the binary search that | |
389 | we should also do a linear search. */ | |
390 | ||
391 | if (do_linear_search) | |
392 | { | |
393 | for (psym = start; psym < start + length; psym++) | |
394 | { | |
c1b5c1eb | 395 | if (symbol_matches_domain ((*psym)->ginfo.language (), |
8a6d4234 | 396 | (*psym)->domain, domain) |
b054970d | 397 | && psymbol_name_matches (*psym, name)) |
40658b94 PH |
398 | return *psym; |
399 | } | |
400 | } | |
401 | ||
402 | return NULL; | |
403 | } | |
404 | ||
8c072cb6 TT |
405 | /* Look, in partial_symtab PST, for symbol whose natural name is |
406 | LOOKUP_NAME. Check the global symbols if GLOBAL, the static | |
407 | symbols if not. */ | |
ccefe4c4 | 408 | |
18430289 | 409 | static struct partial_symbol * |
5c80ed9d | 410 | lookup_partial_symbol (struct objfile *objfile, |
8c072cb6 TT |
411 | struct partial_symtab *pst, |
412 | const lookup_name_info &lookup_name, | |
ccefe4c4 TT |
413 | int global, domain_enum domain) |
414 | { | |
ccefe4c4 TT |
415 | struct partial_symbol **start, **psym; |
416 | struct partial_symbol **top, **real_top, **bottom, **center; | |
932539d7 TT |
417 | int length = (global |
418 | ? pst->global_psymbols.size () | |
419 | : pst->static_psymbols.size ()); | |
ccefe4c4 TT |
420 | int do_linear_search = 1; |
421 | ||
422 | if (length == 0) | |
95cf5869 | 423 | return NULL; |
c00f8484 | 424 | |
ccefe4c4 | 425 | start = (global ? |
932539d7 TT |
426 | &pst->global_psymbols[0] : |
427 | &pst->static_psymbols[0]); | |
ccefe4c4 | 428 | |
0df8b418 | 429 | if (global) /* This means we can use a binary search. */ |
ccefe4c4 TT |
430 | { |
431 | do_linear_search = 0; | |
432 | ||
433 | /* Binary search. This search is guaranteed to end with center | |
dda83cd7 SM |
434 | pointing at the earliest partial symbol whose name might be |
435 | correct. At that point *all* partial symbols with an | |
436 | appropriate name will be checked against the correct | |
437 | domain. */ | |
ccefe4c4 TT |
438 | |
439 | bottom = start; | |
440 | top = start + length - 1; | |
441 | real_top = top; | |
442 | while (top > bottom) | |
443 | { | |
444 | center = bottom + (top - bottom) / 2; | |
e2ff18a0 SM |
445 | |
446 | gdb_assert (center < top); | |
447 | ||
c9d95fa3 | 448 | if (strcmp_iw_ordered ((*center)->ginfo.search_name (), |
e0802d59 | 449 | lookup_name.c_str ()) >= 0) |
ccefe4c4 TT |
450 | { |
451 | top = center; | |
452 | } | |
453 | else | |
454 | { | |
455 | bottom = center + 1; | |
456 | } | |
457 | } | |
e2ff18a0 SM |
458 | |
459 | gdb_assert (top == bottom); | |
ccefe4c4 | 460 | |
559a7a62 JK |
461 | /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will |
462 | search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME. */ | |
af97b416 TT |
463 | while (top >= start && symbol_matches_search_name (&(*top)->ginfo, |
464 | lookup_name)) | |
559a7a62 JK |
465 | top--; |
466 | ||
467 | /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME. */ | |
468 | top++; | |
469 | ||
af97b416 TT |
470 | while (top <= real_top && symbol_matches_search_name (&(*top)->ginfo, |
471 | lookup_name)) | |
ccefe4c4 | 472 | { |
c1b5c1eb | 473 | if (symbol_matches_domain ((*top)->ginfo.language (), |
8a6d4234 | 474 | (*top)->domain, domain)) |
56f37645 | 475 | return *top; |
ccefe4c4 TT |
476 | top++; |
477 | } | |
478 | } | |
479 | ||
480 | /* Can't use a binary search or else we found during the binary search that | |
40658b94 | 481 | we should also do a linear search. */ |
ccefe4c4 TT |
482 | |
483 | if (do_linear_search) | |
484 | { | |
485 | for (psym = start; psym < start + length; psym++) | |
486 | { | |
c1b5c1eb | 487 | if (symbol_matches_domain ((*psym)->ginfo.language (), |
8a6d4234 | 488 | (*psym)->domain, domain) |
af97b416 | 489 | && symbol_matches_search_name (&(*psym)->ginfo, lookup_name)) |
56f37645 | 490 | return *psym; |
ccefe4c4 TT |
491 | } |
492 | } | |
493 | ||
95cf5869 | 494 | return NULL; |
ccefe4c4 TT |
495 | } |
496 | ||
497 | /* Get the symbol table that corresponds to a partial_symtab. | |
f194fefb DE |
498 | This is fast after the first time you do it. |
499 | The result will be NULL if the primary symtab has no symbols, | |
500 | which can happen. Otherwise the result is the primary symtab | |
501 | that contains PST. */ | |
ccefe4c4 | 502 | |
43f3e411 | 503 | static struct compunit_symtab * |
5c80ed9d | 504 | psymtab_to_symtab (struct objfile *objfile, struct partial_symtab *pst) |
ccefe4c4 | 505 | { |
9439a077 TT |
506 | /* If it is a shared psymtab, find an unshared psymtab that includes |
507 | it. Any such psymtab will do. */ | |
508 | while (pst->user != NULL) | |
509 | pst = pst->user; | |
510 | ||
0df8b418 | 511 | /* If it's been looked up before, return it. */ |
5717c425 TT |
512 | if (pst->get_compunit_symtab (objfile)) |
513 | return pst->get_compunit_symtab (objfile); | |
ccefe4c4 TT |
514 | |
515 | /* If it has not yet been read in, read it. */ | |
5717c425 | 516 | if (!pst->readin_p (objfile)) |
ccefe4c4 | 517 | { |
c83dd867 | 518 | scoped_restore decrementer = increment_reading_symtab (); |
ad3bbd48 | 519 | |
077cbab2 TT |
520 | if (info_verbose) |
521 | { | |
6cb06a8c TT |
522 | gdb_printf (_("Reading in symbols for %s...\n"), |
523 | pst->filename); | |
077cbab2 TT |
524 | gdb_flush (gdb_stdout); |
525 | } | |
526 | ||
891813be | 527 | pst->read_symtab (objfile); |
ccefe4c4 TT |
528 | } |
529 | ||
5717c425 | 530 | return pst->get_compunit_symtab (objfile); |
ccefe4c4 TT |
531 | } |
532 | ||
95cf5869 DE |
533 | /* Psymtab version of find_last_source_symtab. See its definition in |
534 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 535 | |
39298a5d TT |
536 | struct symtab * |
537 | psymbol_functions::find_last_source_symtab (struct objfile *ofp) | |
ccefe4c4 | 538 | { |
95cf5869 | 539 | struct partial_symtab *cs_pst = NULL; |
ccefe4c4 | 540 | |
98aa8321 | 541 | for (partial_symtab *ps : partial_symbols (ofp)) |
ccefe4c4 TT |
542 | { |
543 | const char *name = ps->filename; | |
544 | int len = strlen (name); | |
ad3bbd48 | 545 | |
ccefe4c4 TT |
546 | if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0 |
547 | || strcmp (name, "<<C++-namespaces>>") == 0))) | |
548 | cs_pst = ps; | |
549 | } | |
550 | ||
551 | if (cs_pst) | |
552 | { | |
5717c425 | 553 | if (cs_pst->readin_p (ofp)) |
ccefe4c4 | 554 | { |
f34652de | 555 | internal_error (_("select_source_symtab: " |
ccefe4c4 TT |
556 | "readin pst found and no symtabs.")); |
557 | } | |
558 | else | |
43f3e411 DE |
559 | { |
560 | struct compunit_symtab *cust = psymtab_to_symtab (ofp, cs_pst); | |
561 | ||
562 | if (cust == NULL) | |
563 | return NULL; | |
0b17a4f7 | 564 | return cust->primary_filetab (); |
43f3e411 | 565 | } |
ccefe4c4 TT |
566 | } |
567 | return NULL; | |
568 | } | |
569 | ||
95cf5869 DE |
570 | /* Psymtab version of forget_cached_source_info. See its definition in |
571 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 572 | |
39298a5d TT |
573 | void |
574 | psymbol_functions::forget_cached_source_info (struct objfile *objfile) | |
ccefe4c4 | 575 | { |
98aa8321 | 576 | for (partial_symtab *pst : partial_symbols (objfile)) |
ccefe4c4 TT |
577 | { |
578 | if (pst->fullname != NULL) | |
579 | { | |
580 | xfree (pst->fullname); | |
581 | pst->fullname = NULL; | |
582 | } | |
583 | } | |
584 | } | |
585 | ||
586 | static void | |
02e9e7f7 | 587 | print_partial_symbols (struct gdbarch *gdbarch, struct objfile *objfile, |
932539d7 TT |
588 | const std::vector<partial_symbol *> &symbols, |
589 | const char *what, struct ui_file *outfile) | |
ccefe4c4 | 590 | { |
6cb06a8c | 591 | gdb_printf (outfile, " %s partial symbols:\n", what); |
932539d7 | 592 | for (partial_symbol *p : symbols) |
ccefe4c4 | 593 | { |
27618ce4 | 594 | QUIT; |
6cb06a8c | 595 | gdb_printf (outfile, " `%s'", p->ginfo.linkage_name ()); |
932539d7 | 596 | if (p->ginfo.demangled_name () != NULL) |
ccefe4c4 | 597 | { |
6cb06a8c TT |
598 | gdb_printf (outfile, " `%s'", |
599 | p->ginfo.demangled_name ()); | |
ccefe4c4 | 600 | } |
0426ad51 | 601 | gdb_puts (", ", outfile); |
932539d7 | 602 | switch (p->domain) |
ccefe4c4 TT |
603 | { |
604 | case UNDEF_DOMAIN: | |
0426ad51 | 605 | gdb_puts ("undefined domain, ", outfile); |
ccefe4c4 TT |
606 | break; |
607 | case VAR_DOMAIN: | |
0df8b418 | 608 | /* This is the usual thing -- don't print it. */ |
ccefe4c4 TT |
609 | break; |
610 | case STRUCT_DOMAIN: | |
0426ad51 | 611 | gdb_puts ("struct domain, ", outfile); |
ccefe4c4 | 612 | break; |
06ff036e | 613 | case MODULE_DOMAIN: |
0426ad51 | 614 | gdb_puts ("module domain, ", outfile); |
06ff036e | 615 | break; |
ccefe4c4 | 616 | case LABEL_DOMAIN: |
0426ad51 | 617 | gdb_puts ("label domain, ", outfile); |
ccefe4c4 | 618 | break; |
06ff036e | 619 | case COMMON_BLOCK_DOMAIN: |
0426ad51 | 620 | gdb_puts ("common block domain, ", outfile); |
06ff036e | 621 | break; |
ccefe4c4 | 622 | default: |
0426ad51 | 623 | gdb_puts ("<invalid domain>, ", outfile); |
ccefe4c4 TT |
624 | break; |
625 | } | |
932539d7 | 626 | switch (p->aclass) |
ccefe4c4 TT |
627 | { |
628 | case LOC_UNDEF: | |
0426ad51 | 629 | gdb_puts ("undefined", outfile); |
ccefe4c4 TT |
630 | break; |
631 | case LOC_CONST: | |
0426ad51 | 632 | gdb_puts ("constant int", outfile); |
ccefe4c4 TT |
633 | break; |
634 | case LOC_STATIC: | |
0426ad51 | 635 | gdb_puts ("static", outfile); |
ccefe4c4 TT |
636 | break; |
637 | case LOC_REGISTER: | |
0426ad51 | 638 | gdb_puts ("register", outfile); |
ccefe4c4 TT |
639 | break; |
640 | case LOC_ARG: | |
0426ad51 | 641 | gdb_puts ("pass by value", outfile); |
ccefe4c4 TT |
642 | break; |
643 | case LOC_REF_ARG: | |
0426ad51 | 644 | gdb_puts ("pass by reference", outfile); |
ccefe4c4 TT |
645 | break; |
646 | case LOC_REGPARM_ADDR: | |
0426ad51 | 647 | gdb_puts ("register address parameter", outfile); |
ccefe4c4 TT |
648 | break; |
649 | case LOC_LOCAL: | |
0426ad51 | 650 | gdb_puts ("stack parameter", outfile); |
ccefe4c4 TT |
651 | break; |
652 | case LOC_TYPEDEF: | |
0426ad51 | 653 | gdb_puts ("type", outfile); |
ccefe4c4 TT |
654 | break; |
655 | case LOC_LABEL: | |
0426ad51 | 656 | gdb_puts ("label", outfile); |
ccefe4c4 TT |
657 | break; |
658 | case LOC_BLOCK: | |
0426ad51 | 659 | gdb_puts ("function", outfile); |
ccefe4c4 TT |
660 | break; |
661 | case LOC_CONST_BYTES: | |
0426ad51 | 662 | gdb_puts ("constant bytes", outfile); |
ccefe4c4 TT |
663 | break; |
664 | case LOC_UNRESOLVED: | |
0426ad51 | 665 | gdb_puts ("unresolved", outfile); |
ccefe4c4 TT |
666 | break; |
667 | case LOC_OPTIMIZED_OUT: | |
0426ad51 | 668 | gdb_puts ("optimized out", outfile); |
ccefe4c4 TT |
669 | break; |
670 | case LOC_COMPUTED: | |
0426ad51 | 671 | gdb_puts ("computed at runtime", outfile); |
ccefe4c4 TT |
672 | break; |
673 | default: | |
0426ad51 | 674 | gdb_puts ("<invalid location>", outfile); |
ccefe4c4 TT |
675 | break; |
676 | } | |
0426ad51 | 677 | gdb_puts (", ", outfile); |
1ee8702d TT |
678 | gdb_puts (paddress (gdbarch, CORE_ADDR (p->unrelocated_address ())), |
679 | outfile); | |
6cb06a8c | 680 | gdb_printf (outfile, "\n"); |
ccefe4c4 TT |
681 | } |
682 | } | |
683 | ||
684 | static void | |
685 | dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab, | |
686 | struct ui_file *outfile) | |
687 | { | |
08feed99 | 688 | struct gdbarch *gdbarch = objfile->arch (); |
ccefe4c4 TT |
689 | int i; |
690 | ||
b4c41fc7 DE |
691 | if (psymtab->anonymous) |
692 | { | |
6cb06a8c TT |
693 | gdb_printf (outfile, "\nAnonymous partial symtab (%s) ", |
694 | psymtab->filename); | |
b4c41fc7 DE |
695 | } |
696 | else | |
697 | { | |
6cb06a8c TT |
698 | gdb_printf (outfile, "\nPartial symtab for source file %s ", |
699 | psymtab->filename); | |
b4c41fc7 | 700 | } |
6cb06a8c TT |
701 | gdb_printf (outfile, "(object %s)\n\n", |
702 | host_address_to_string (psymtab)); | |
703 | gdb_printf (outfile, " Read from object file %s (%s)\n", | |
704 | objfile_name (objfile), | |
705 | host_address_to_string (objfile)); | |
ccefe4c4 | 706 | |
5717c425 | 707 | if (psymtab->readin_p (objfile)) |
6cb06a8c | 708 | gdb_printf |
64b7cc50 TT |
709 | (outfile, |
710 | " Full symtab was read (at %s)\n", | |
711 | host_address_to_string (psymtab->get_compunit_symtab (objfile))); | |
ccefe4c4 | 712 | |
6cb06a8c | 713 | gdb_printf (outfile, " Symbols cover text addresses "); |
0426ad51 | 714 | gdb_puts (paddress (gdbarch, psymtab->text_low (objfile)), outfile); |
6cb06a8c | 715 | gdb_printf (outfile, "-"); |
0426ad51 | 716 | gdb_puts (paddress (gdbarch, psymtab->text_high (objfile)), outfile); |
6cb06a8c | 717 | gdb_printf (outfile, "\n"); |
6cb06a8c TT |
718 | gdb_printf (outfile, " Depends on %d other partial symtabs.\n", |
719 | psymtab->number_of_dependencies); | |
ccefe4c4 | 720 | for (i = 0; i < psymtab->number_of_dependencies; i++) |
6cb06a8c TT |
721 | gdb_printf (outfile, " %d %s\n", i, |
722 | host_address_to_string (psymtab->dependencies[i])); | |
9439a077 | 723 | if (psymtab->user != NULL) |
6cb06a8c TT |
724 | gdb_printf (outfile, " Shared partial symtab with user %s\n", |
725 | host_address_to_string (psymtab->user)); | |
932539d7 | 726 | if (!psymtab->global_psymbols.empty ()) |
ccefe4c4 | 727 | { |
d320c2b5 | 728 | print_partial_symbols |
932539d7 TT |
729 | (gdbarch, objfile, psymtab->global_psymbols, |
730 | "Global", outfile); | |
ccefe4c4 | 731 | } |
932539d7 | 732 | if (!psymtab->static_psymbols.empty ()) |
ccefe4c4 | 733 | { |
d320c2b5 | 734 | print_partial_symbols |
932539d7 TT |
735 | (gdbarch, objfile, psymtab->static_psymbols, |
736 | "Static", outfile); | |
ccefe4c4 | 737 | } |
6cb06a8c | 738 | gdb_printf (outfile, "\n"); |
ccefe4c4 TT |
739 | } |
740 | ||
4829711b TT |
741 | /* Count the number of partial symbols in OBJFILE. */ |
742 | ||
caf8c1e5 TT |
743 | int |
744 | psymbol_functions::count_psyms () | |
4829711b TT |
745 | { |
746 | int count = 0; | |
caf8c1e5 | 747 | for (partial_symtab *pst : m_partial_symtabs->range ()) |
4829711b TT |
748 | { |
749 | count += pst->global_psymbols.size (); | |
750 | count += pst->static_psymbols.size (); | |
751 | } | |
752 | return count; | |
753 | } | |
754 | ||
95cf5869 DE |
755 | /* Psymtab version of print_stats. See its definition in |
756 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 757 | |
39298a5d | 758 | void |
4829711b | 759 | psymbol_functions::print_stats (struct objfile *objfile, bool print_bcache) |
ccefe4c4 TT |
760 | { |
761 | int i; | |
ad3bbd48 | 762 | |
4829711b TT |
763 | if (!print_bcache) |
764 | { | |
caf8c1e5 | 765 | int n_psyms = count_psyms (); |
4829711b | 766 | if (n_psyms > 0) |
6cb06a8c TT |
767 | gdb_printf (_(" Number of \"partial\" symbols read: %d\n"), |
768 | n_psyms); | |
4829711b TT |
769 | |
770 | i = 0; | |
98aa8321 | 771 | for (partial_symtab *ps : partial_symbols (objfile)) |
4829711b TT |
772 | { |
773 | if (!ps->readin_p (objfile)) | |
774 | i++; | |
775 | } | |
6cb06a8c TT |
776 | gdb_printf (_(" Number of psym tables (not yet expanded): %d\n"), |
777 | i); | |
778 | gdb_printf (_(" Total memory used for psymbol cache: %d\n"), | |
779 | m_partial_symtabs->psymbol_cache.memory_used ()); | |
4829711b TT |
780 | } |
781 | else | |
ccefe4c4 | 782 | { |
6cb06a8c | 783 | gdb_printf (_("Psymbol byte cache statistics:\n")); |
17d66340 | 784 | m_partial_symtabs->psymbol_cache.print_statistics |
4829711b | 785 | ("partial symbol cache"); |
ccefe4c4 | 786 | } |
ccefe4c4 TT |
787 | } |
788 | ||
95cf5869 DE |
789 | /* Psymtab version of dump. See its definition in |
790 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 791 | |
39298a5d TT |
792 | void |
793 | psymbol_functions::dump (struct objfile *objfile) | |
ccefe4c4 TT |
794 | { |
795 | struct partial_symtab *psymtab; | |
796 | ||
17d66340 | 797 | if (m_partial_symtabs->psymtabs) |
ccefe4c4 | 798 | { |
6cb06a8c | 799 | gdb_printf ("Psymtabs:\n"); |
17d66340 | 800 | for (psymtab = m_partial_symtabs->psymtabs; |
ccefe4c4 TT |
801 | psymtab != NULL; |
802 | psymtab = psymtab->next) | |
6cb06a8c TT |
803 | gdb_printf ("%s at %s\n", |
804 | psymtab->filename, | |
805 | host_address_to_string (psymtab)); | |
806 | gdb_printf ("\n\n"); | |
ccefe4c4 TT |
807 | } |
808 | } | |
809 | ||
95cf5869 DE |
810 | /* Psymtab version of expand_all_symtabs. See its definition in |
811 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 812 | |
39298a5d TT |
813 | void |
814 | psymbol_functions::expand_all_symtabs (struct objfile *objfile) | |
ccefe4c4 | 815 | { |
98aa8321 | 816 | for (partial_symtab *psymtab : partial_symbols (objfile)) |
b22a7c6a | 817 | psymtab_to_symtab (objfile, psymtab); |
ccefe4c4 TT |
818 | } |
819 | ||
95cf5869 DE |
820 | /* Psymtab version of map_symbol_filenames. See its definition in |
821 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 822 | |
39298a5d | 823 | void |
f4655dee TT |
824 | psymbol_functions::map_symbol_filenames |
825 | (struct objfile *objfile, | |
826 | gdb::function_view<symbol_filename_ftype> fun, | |
827 | bool need_fullname) | |
ccefe4c4 | 828 | { |
98aa8321 | 829 | for (partial_symtab *ps : partial_symbols (objfile)) |
ccefe4c4 TT |
830 | { |
831 | const char *fullname; | |
832 | ||
5717c425 | 833 | if (ps->readin_p (objfile)) |
ccefe4c4 TT |
834 | continue; |
835 | ||
f80c6f3f DE |
836 | /* We can skip shared psymtabs here, because any file name will be |
837 | attached to the unshared psymtab. */ | |
838 | if (ps->user != NULL) | |
839 | continue; | |
840 | ||
b4c41fc7 DE |
841 | /* Anonymous psymtabs don't have a file name. */ |
842 | if (ps->anonymous) | |
843 | continue; | |
844 | ||
821296b7 | 845 | QUIT; |
74e2f255 DE |
846 | if (need_fullname) |
847 | fullname = psymtab_to_fullname (ps); | |
848 | else | |
849 | fullname = NULL; | |
f4655dee | 850 | fun (ps->filename, fullname); |
ccefe4c4 TT |
851 | } |
852 | } | |
853 | ||
ccefe4c4 TT |
854 | /* Finds the fullname that a partial_symtab represents. |
855 | ||
856 | If this functions finds the fullname, it will save it in ps->fullname | |
857 | and it will also return the value. | |
858 | ||
859 | If this function fails to find the file that this partial_symtab represents, | |
860 | NULL will be returned and ps->fullname will be set to NULL. */ | |
256f06f3 | 861 | |
da5132d3 | 862 | static const char * |
ccefe4c4 TT |
863 | psymtab_to_fullname (struct partial_symtab *ps) |
864 | { | |
fbd9ab74 | 865 | gdb_assert (!ps->anonymous); |
ccefe4c4 | 866 | |
256f06f3 DE |
867 | /* Use cached copy if we have it. |
868 | We rely on forget_cached_source_info being called appropriately | |
869 | to handle cases like the file being moved. */ | |
fbd9ab74 JK |
870 | if (ps->fullname == NULL) |
871 | { | |
4584f33d TT |
872 | gdb::unique_xmalloc_ptr<char> fullname |
873 | = find_source_or_rewrite (ps->filename, ps->dirname); | |
e0cc99a6 | 874 | ps->fullname = fullname.release (); |
95cf5869 | 875 | } |
fbd9ab74 JK |
876 | |
877 | return ps->fullname; | |
ccefe4c4 TT |
878 | } |
879 | ||
0b7b2c2a | 880 | /* Psymtab version of expand_matching_symbols. See its definition in |
95cf5869 | 881 | the definition of quick_symbol_functions in symfile.h. */ |
40658b94 | 882 | |
39298a5d | 883 | void |
0b7b2c2a | 884 | psymbol_functions::expand_matching_symbols |
199b4314 | 885 | (struct objfile *objfile, |
b054970d | 886 | const lookup_name_info &name, domain_enum domain, |
199b4314 | 887 | int global, |
199b4314 | 888 | symbol_compare_ftype *ordered_compare) |
ccefe4c4 | 889 | { |
98aa8321 | 890 | for (partial_symtab *ps : partial_symbols (objfile)) |
ccefe4c4 TT |
891 | { |
892 | QUIT; | |
0b7b2c2a TT |
893 | if (!ps->readin_p (objfile) |
894 | && match_partial_symbol (objfile, ps, global, name, domain, | |
40658b94 | 895 | ordered_compare)) |
0b7b2c2a | 896 | psymtab_to_symtab (objfile, ps); |
ccefe4c4 | 897 | } |
95cf5869 | 898 | } |
ccefe4c4 | 899 | |
14bc53a8 PA |
900 | /* A helper for psym_expand_symtabs_matching that handles searching |
901 | included psymtabs. This returns true if a symbol is found, and | |
902 | false otherwise. It also updates the 'searched_flag' on the | |
9439a077 TT |
903 | various psymtabs that it searches. */ |
904 | ||
14bc53a8 PA |
905 | static bool |
906 | recursively_search_psymtabs | |
d2f7dcb2 JB |
907 | (struct partial_symtab *ps, |
908 | struct objfile *objfile, | |
03a8ea51 | 909 | block_search_flags search_flags, |
3bfa51a7 TT |
910 | domain_enum domain, |
911 | enum search_domain search, | |
b5ec771e | 912 | const lookup_name_info &lookup_name, |
14bc53a8 | 913 | gdb::function_view<expand_symtabs_symbol_matcher_ftype> sym_matcher) |
9439a077 | 914 | { |
9439a077 | 915 | int keep_going = 1; |
f486487f | 916 | enum psymtab_search_status result = PST_SEARCHED_AND_NOT_FOUND; |
9439a077 TT |
917 | int i; |
918 | ||
919 | if (ps->searched_flag != PST_NOT_SEARCHED) | |
920 | return ps->searched_flag == PST_SEARCHED_AND_FOUND; | |
921 | ||
922 | /* Recurse into shared psymtabs first, because they may have already | |
923 | been searched, and this could save some time. */ | |
924 | for (i = 0; i < ps->number_of_dependencies; ++i) | |
925 | { | |
926 | int r; | |
927 | ||
928 | /* Skip non-shared dependencies, these are handled elsewhere. */ | |
929 | if (ps->dependencies[i]->user == NULL) | |
930 | continue; | |
931 | ||
932 | r = recursively_search_psymtabs (ps->dependencies[i], | |
3bfa51a7 | 933 | objfile, search_flags, domain, search, |
03a8ea51 | 934 | lookup_name, sym_matcher); |
9439a077 TT |
935 | if (r != 0) |
936 | { | |
937 | ps->searched_flag = PST_SEARCHED_AND_FOUND; | |
14bc53a8 | 938 | return true; |
9439a077 TT |
939 | } |
940 | } | |
941 | ||
932539d7 TT |
942 | partial_symbol **gbound = (ps->global_psymbols.data () |
943 | + ps->global_psymbols.size ()); | |
944 | partial_symbol **sbound = (ps->static_psymbols.data () | |
945 | + ps->static_psymbols.size ()); | |
af5bf4ad | 946 | partial_symbol **bound = gbound; |
9439a077 TT |
947 | |
948 | /* Go through all of the symbols stored in a partial | |
949 | symtab in one loop. */ | |
932539d7 | 950 | partial_symbol **psym = ps->global_psymbols.data (); |
03a8ea51 TT |
951 | |
952 | if ((search_flags & SEARCH_GLOBAL_BLOCK) == 0) | |
953 | { | |
954 | if (ps->static_psymbols.empty ()) | |
955 | keep_going = 0; | |
956 | else | |
957 | { | |
958 | psym = ps->static_psymbols.data (); | |
959 | bound = sbound; | |
960 | } | |
961 | } | |
962 | ||
9439a077 TT |
963 | while (keep_going) |
964 | { | |
965 | if (psym >= bound) | |
966 | { | |
03a8ea51 TT |
967 | if (bound == gbound && !ps->static_psymbols.empty () |
968 | && (search_flags & SEARCH_STATIC_BLOCK) != 0) | |
9439a077 | 969 | { |
932539d7 | 970 | psym = ps->static_psymbols.data (); |
9439a077 TT |
971 | bound = sbound; |
972 | } | |
973 | else | |
974 | keep_going = 0; | |
975 | continue; | |
976 | } | |
977 | else | |
978 | { | |
979 | QUIT; | |
980 | ||
3bfa51a7 TT |
981 | if ((domain == UNDEF_DOMAIN |
982 | || symbol_matches_domain ((*psym)->ginfo.language (), | |
983 | (*psym)->domain, domain)) | |
984 | && (search == ALL_DOMAIN | |
985 | || (search == MODULES_DOMAIN | |
986 | && (*psym)->domain == MODULE_DOMAIN) | |
987 | || (search == VARIABLES_DOMAIN | |
988 | && (*psym)->aclass != LOC_TYPEDEF | |
989 | && (*psym)->aclass != LOC_BLOCK) | |
990 | || (search == FUNCTIONS_DOMAIN | |
991 | && (*psym)->aclass == LOC_BLOCK) | |
992 | || (search == TYPES_DOMAIN | |
993 | && (*psym)->aclass == LOC_TYPEDEF)) | |
b5ec771e | 994 | && psymbol_name_matches (*psym, lookup_name) |
af97b416 | 995 | && (sym_matcher == NULL |
c9d95fa3 | 996 | || sym_matcher ((*psym)->ginfo.search_name ()))) |
9439a077 TT |
997 | { |
998 | /* Found a match, so notify our caller. */ | |
999 | result = PST_SEARCHED_AND_FOUND; | |
1000 | keep_going = 0; | |
1001 | } | |
1002 | } | |
1003 | psym++; | |
1004 | } | |
1005 | ||
1006 | ps->searched_flag = result; | |
1007 | return result == PST_SEARCHED_AND_FOUND; | |
1008 | } | |
1009 | ||
95cf5869 DE |
1010 | /* Psymtab version of expand_symtabs_matching. See its definition in |
1011 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 1012 | |
df35e626 | 1013 | bool |
39298a5d | 1014 | psymbol_functions::expand_symtabs_matching |
f8eba3c6 | 1015 | (struct objfile *objfile, |
14bc53a8 | 1016 | gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher, |
c1a66c06 | 1017 | const lookup_name_info *lookup_name, |
14bc53a8 PA |
1018 | gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher, |
1019 | gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify, | |
03a8ea51 | 1020 | block_search_flags search_flags, |
3bfa51a7 TT |
1021 | domain_enum domain, |
1022 | enum search_domain search) | |
ccefe4c4 | 1023 | { |
9439a077 | 1024 | /* Clear the search flags. */ |
98aa8321 | 1025 | for (partial_symtab *ps : partial_symbols (objfile)) |
b22a7c6a | 1026 | ps->searched_flag = PST_NOT_SEARCHED; |
ccefe4c4 | 1027 | |
e2cd5ca4 TT |
1028 | gdb::optional<lookup_name_info> psym_lookup_name; |
1029 | if (lookup_name != nullptr) | |
1030 | psym_lookup_name = lookup_name->make_ignore_params (); | |
1031 | ||
4f348ca8 TT |
1032 | /* This invariant is documented in quick-functions.h. */ |
1033 | gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr); | |
1034 | ||
17d66340 | 1035 | for (partial_symtab *ps : m_partial_symtabs->range ()) |
9439a077 | 1036 | { |
30b3dd9d DE |
1037 | QUIT; |
1038 | ||
5717c425 | 1039 | if (ps->readin_p (objfile)) |
ccefe4c4 TT |
1040 | continue; |
1041 | ||
b4c41fc7 DE |
1042 | if (file_matcher) |
1043 | { | |
14bc53a8 | 1044 | bool match; |
680d1742 | 1045 | |
b4c41fc7 DE |
1046 | if (ps->anonymous) |
1047 | continue; | |
fbd9ab74 | 1048 | |
14bc53a8 | 1049 | match = file_matcher (ps->filename, false); |
680d1742 DE |
1050 | if (!match) |
1051 | { | |
1052 | /* Before we invoke realpath, which can get expensive when many | |
1053 | files are involved, do a quick comparison of the basenames. */ | |
1054 | if (basenames_may_differ | |
14bc53a8 PA |
1055 | || file_matcher (lbasename (ps->filename), true)) |
1056 | match = file_matcher (psymtab_to_fullname (ps), false); | |
680d1742 DE |
1057 | } |
1058 | if (!match) | |
b4c41fc7 DE |
1059 | continue; |
1060 | } | |
ccefe4c4 | 1061 | |
4f348ca8 | 1062 | if (lookup_name == nullptr |
3bfa51a7 TT |
1063 | || recursively_search_psymtabs (ps, objfile, search_flags, |
1064 | domain, search, | |
e2cd5ca4 | 1065 | *psym_lookup_name, |
c1a66c06 | 1066 | symbol_matcher)) |
276d885b | 1067 | { |
cb25fdbb | 1068 | compunit_symtab *cust = psymtab_to_symtab (objfile, ps); |
276d885b | 1069 | |
cb25fdbb SM |
1070 | if (cust != nullptr && expansion_notify != nullptr) |
1071 | if (!expansion_notify (cust)) | |
df35e626 | 1072 | return false; |
276d885b | 1073 | } |
ccefe4c4 | 1074 | } |
df35e626 TT |
1075 | |
1076 | return true; | |
ccefe4c4 TT |
1077 | } |
1078 | ||
95cf5869 DE |
1079 | /* Psymtab version of has_symbols. See its definition in |
1080 | the definition of quick_symbol_functions in symfile.h. */ | |
83827540 | 1081 | |
39298a5d TT |
1082 | bool |
1083 | psymbol_functions::has_symbols (struct objfile *objfile) | |
ccefe4c4 | 1084 | { |
17d66340 | 1085 | return m_partial_symtabs->psymtabs != NULL; |
ccefe4c4 TT |
1086 | } |
1087 | ||
fc4d5ebf AB |
1088 | /* See quick_symbol_functions::has_unexpanded_symtabs in quick-symbol.h. */ |
1089 | ||
1090 | bool | |
1091 | psymbol_functions::has_unexpanded_symtabs (struct objfile *objfile) | |
1092 | { | |
98aa8321 | 1093 | for (partial_symtab *psymtab : partial_symbols (objfile)) |
fc4d5ebf AB |
1094 | { |
1095 | /* Is this already expanded? */ | |
1096 | if (psymtab->readin_p (objfile)) | |
1097 | continue; | |
1098 | ||
1099 | /* It has not yet been expanded. */ | |
1100 | return true; | |
1101 | } | |
1102 | ||
1103 | return false; | |
1104 | } | |
1105 | ||
ccefe4c4 TT |
1106 | \f |
1107 | ||
c3693a1d TT |
1108 | /* Partially fill a partial symtab. It will be completely filled at |
1109 | the end of the symbol list. */ | |
ccefe4c4 | 1110 | |
c3693a1d | 1111 | partial_symtab::partial_symtab (const char *filename, |
7b249e47 | 1112 | psymtab_storage *partial_symtabs, |
0072c873 | 1113 | objfile_per_bfd_storage *objfile_per_bfd, |
584d0cda | 1114 | unrelocated_addr textlow) |
0072c873 | 1115 | : partial_symtab (filename, partial_symtabs, objfile_per_bfd) |
ccefe4c4 | 1116 | { |
c3693a1d TT |
1117 | set_text_low (textlow); |
1118 | set_text_high (raw_text_low ()); /* default */ | |
ccefe4c4 TT |
1119 | } |
1120 | ||
8763cede DE |
1121 | /* Perform "finishing up" operations of a partial symtab. */ |
1122 | ||
1123 | void | |
ae7754b2 | 1124 | partial_symtab::end () |
8763cede | 1125 | { |
ae7754b2 TT |
1126 | global_psymbols.shrink_to_fit (); |
1127 | static_psymbols.shrink_to_fit (); | |
8763cede | 1128 | |
ae7754b2 TT |
1129 | /* Sort the global list; don't sort the static list. */ |
1130 | std::sort (global_psymbols.begin (), | |
1131 | global_psymbols.end (), | |
1132 | [] (partial_symbol *s1, partial_symbol *s2) | |
1133 | { | |
1134 | return strcmp_iw_ordered (s1->ginfo.search_name (), | |
1135 | s2->ginfo.search_name ()) < 0; | |
1136 | }); | |
8763cede DE |
1137 | } |
1138 | ||
89806626 | 1139 | /* See psymtab.h. */ |
cbd70537 | 1140 | |
89806626 SM |
1141 | unsigned long |
1142 | psymbol_bcache::hash (const void *addr, int length) | |
cbd70537 SW |
1143 | { |
1144 | unsigned long h = 0; | |
1145 | struct partial_symbol *psymbol = (struct partial_symbol *) addr; | |
c1b5c1eb | 1146 | unsigned int lang = psymbol->ginfo.language (); |
8a6d4234 TT |
1147 | unsigned int domain = psymbol->domain; |
1148 | unsigned int theclass = psymbol->aclass; | |
cbd70537 | 1149 | |
4aeddc50 | 1150 | h = fast_hash (&psymbol->ginfo.m_value, sizeof (psymbol->ginfo.m_value), h); |
4cbd39b2 CB |
1151 | h = fast_hash (&lang, sizeof (unsigned int), h); |
1152 | h = fast_hash (&domain, sizeof (unsigned int), h); | |
1153 | h = fast_hash (&theclass, sizeof (unsigned int), h); | |
4d4eaa30 | 1154 | /* Note that psymbol names are interned via compute_and_set_names, so |
e793c052 | 1155 | there's no need to hash the contents of the name here. */ |
4d4eaa30 | 1156 | h = fast_hash (&psymbol->ginfo.m_name, sizeof (psymbol->ginfo.m_name), h); |
cbd70537 SW |
1157 | |
1158 | return h; | |
1159 | } | |
1160 | ||
89806626 | 1161 | /* See psymtab.h. */ |
cbd70537 | 1162 | |
89806626 SM |
1163 | int |
1164 | psymbol_bcache::compare (const void *addr1, const void *addr2, int length) | |
cbd70537 SW |
1165 | { |
1166 | struct partial_symbol *sym1 = (struct partial_symbol *) addr1; | |
1167 | struct partial_symbol *sym2 = (struct partial_symbol *) addr2; | |
1168 | ||
4aeddc50 SM |
1169 | return (memcmp (&sym1->ginfo.m_value, &sym2->ginfo.m_value, |
1170 | sizeof (sym1->ginfo.m_value)) == 0 | |
c1b5c1eb | 1171 | && sym1->ginfo.language () == sym2->ginfo.language () |
dda83cd7 SM |
1172 | && sym1->domain == sym2->domain |
1173 | && sym1->aclass == sym2->aclass | |
e793c052 | 1174 | /* Note that psymbol names are interned via |
4d4eaa30 | 1175 | compute_and_set_names, so there's no need to compare the |
e793c052 | 1176 | contents of the name here. */ |
dda83cd7 | 1177 | && sym1->ginfo.linkage_name () == sym2->ginfo.linkage_name ()); |
cbd70537 SW |
1178 | } |
1179 | ||
703a86c2 | 1180 | /* See psympriv.h. */ |
ccefe4c4 | 1181 | |
7dc25483 | 1182 | void |
932539d7 TT |
1183 | partial_symtab::add_psymbol (const partial_symbol &psymbol, |
1184 | psymbol_placement where, | |
7b249e47 | 1185 | psymtab_storage *partial_symtabs, |
932539d7 | 1186 | struct objfile *objfile) |
ccefe4c4 | 1187 | { |
ef5e5b0b | 1188 | bool added; |
ccefe4c4 | 1189 | |
0df8b418 | 1190 | /* Stash the partial symbol away in the cache. */ |
7b249e47 TT |
1191 | partial_symbol *psym |
1192 | = ((struct partial_symbol *) | |
1193 | partial_symtabs->psymbol_cache.insert | |
1194 | (&psymbol, sizeof (struct partial_symbol), &added)); | |
ccefe4c4 TT |
1195 | |
1196 | /* Do not duplicate global partial symbols. */ | |
75aedd27 | 1197 | if (where == psymbol_placement::GLOBAL && !added) |
7dc25483 | 1198 | return; |
ccefe4c4 | 1199 | |
0df8b418 | 1200 | /* Save pointer to partial symbol in psymtab, growing symtab if needed. */ |
932539d7 | 1201 | std::vector<partial_symbol *> &list |
75aedd27 | 1202 | = (where == psymbol_placement::STATIC |
932539d7 TT |
1203 | ? static_psymbols |
1204 | : global_psymbols); | |
0684bb51 | 1205 | list.push_back (psym); |
ccefe4c4 TT |
1206 | } |
1207 | ||
6eee24ce | 1208 | /* See psympriv.h. */ |
ccefe4c4 | 1209 | |
2467f4f6 | 1210 | void |
932539d7 TT |
1211 | partial_symtab::add_psymbol (gdb::string_view name, bool copy_name, |
1212 | domain_enum domain, | |
1213 | enum address_class theclass, | |
1214 | short section, | |
1215 | psymbol_placement where, | |
1ee8702d | 1216 | unrelocated_addr coreaddr, |
7b249e47 TT |
1217 | enum language language, |
1218 | psymtab_storage *partial_symtabs, | |
1219 | struct objfile *objfile) | |
2467f4f6 TT |
1220 | { |
1221 | struct partial_symbol psymbol; | |
1222 | memset (&psymbol, 0, sizeof (psymbol)); | |
1223 | ||
1224 | psymbol.set_unrelocated_address (coreaddr); | |
a52d653e | 1225 | psymbol.ginfo.set_section_index (section); |
2467f4f6 TT |
1226 | psymbol.domain = domain; |
1227 | psymbol.aclass = theclass; | |
7b249e47 | 1228 | psymbol.ginfo.set_language (language, partial_symtabs->obstack ()); |
2467f4f6 TT |
1229 | psymbol.ginfo.compute_and_set_names (name, copy_name, objfile->per_bfd); |
1230 | ||
7b249e47 | 1231 | add_psymbol (psymbol, where, partial_symtabs, objfile); |
2467f4f6 TT |
1232 | } |
1233 | ||
1234 | /* See psympriv.h. */ | |
1235 | ||
7b249e47 TT |
1236 | partial_symtab::partial_symtab (const char *filename_, |
1237 | psymtab_storage *partial_symtabs, | |
0072c873 | 1238 | objfile_per_bfd_storage *objfile_per_bfd) |
32caafd0 TT |
1239 | : searched_flag (PST_NOT_SEARCHED), |
1240 | text_low_valid (0), | |
1241 | text_high_valid (0) | |
ccefe4c4 | 1242 | { |
7b249e47 | 1243 | partial_symtabs->install_psymtab (this); |
ccefe4c4 | 1244 | |
0072c873 | 1245 | filename = objfile_per_bfd->intern (filename_); |
ccefe4c4 | 1246 | |
2ab317fb | 1247 | if (symtab_create_debug >= 1) |
45cfd468 DE |
1248 | { |
1249 | /* Be a bit clever with debugging messages, and don't print objfile | |
1250 | every time, only when it changes. */ | |
0072c873 SM |
1251 | static std::string last_bfd_name; |
1252 | const char *this_bfd_name | |
1253 | = bfd_get_filename (objfile_per_bfd->get_bfd ()); | |
45cfd468 | 1254 | |
0072c873 | 1255 | if (last_bfd_name.empty () || last_bfd_name != this_bfd_name) |
45cfd468 | 1256 | { |
0072c873 | 1257 | last_bfd_name = this_bfd_name; |
2ab317fb SM |
1258 | |
1259 | symtab_create_debug_printf ("creating one or more psymtabs for %s", | |
1260 | this_bfd_name); | |
45cfd468 | 1261 | } |
2ab317fb SM |
1262 | |
1263 | symtab_create_debug_printf ("created psymtab %s for module %s", | |
1264 | host_address_to_string (this), filename); | |
45cfd468 | 1265 | } |
ccefe4c4 TT |
1266 | } |
1267 | ||
0494dbec TT |
1268 | /* See psympriv.h. */ |
1269 | ||
1270 | void | |
48993951 | 1271 | partial_symtab::expand_dependencies (struct objfile *objfile) |
0494dbec TT |
1272 | { |
1273 | for (int i = 0; i < number_of_dependencies; ++i) | |
1274 | { | |
5717c425 | 1275 | if (!dependencies[i]->readin_p (objfile) |
1eb73179 | 1276 | && dependencies[i]->user == NULL) |
0494dbec TT |
1277 | { |
1278 | /* Inform about additional files to be read in. */ | |
1279 | if (info_verbose) | |
1280 | { | |
0426ad51 | 1281 | gdb_puts (" "); |
1285ce86 | 1282 | gdb_stdout->wrap_here (0); |
0426ad51 | 1283 | gdb_puts ("and "); |
1285ce86 | 1284 | gdb_stdout->wrap_here (0); |
6cb06a8c | 1285 | gdb_printf ("%s...", dependencies[i]->filename); |
0494dbec TT |
1286 | gdb_flush (gdb_stdout); |
1287 | } | |
1288 | dependencies[i]->expand_psymtab (objfile); | |
1289 | } | |
1290 | } | |
1291 | } | |
1292 | ||
1293 | ||
ccefe4c4 | 1294 | void |
d320c2b5 | 1295 | psymtab_storage::discard_psymtab (struct partial_symtab *pst) |
ccefe4c4 TT |
1296 | { |
1297 | struct partial_symtab **prev_pst; | |
1298 | ||
1299 | /* From dbxread.c: | |
1300 | Empty psymtabs happen as a result of header files which don't | |
1301 | have any symbols in them. There can be a lot of them. But this | |
1302 | check is wrong, in that a psymtab with N_SLINE entries but | |
1303 | nothing else is not empty, but we don't realize that. Fixing | |
1304 | that without slowing things down might be tricky. */ | |
1305 | ||
0df8b418 | 1306 | /* First, snip it out of the psymtab chain. */ |
ccefe4c4 | 1307 | |
d320c2b5 | 1308 | prev_pst = &psymtabs; |
ccefe4c4 TT |
1309 | while ((*prev_pst) != pst) |
1310 | prev_pst = &((*prev_pst)->next); | |
1311 | (*prev_pst) = pst->next; | |
6f17252b | 1312 | delete pst; |
ccefe4c4 TT |
1313 | } |
1314 | ||
ccefe4c4 TT |
1315 | \f |
1316 | ||
dfc7bb5b | 1317 | static void |
990b9f9f | 1318 | maintenance_print_psymbols (const char *args, int from_tty) |
ccefe4c4 | 1319 | { |
34c41c68 | 1320 | struct ui_file *outfile = gdb_stdout; |
34c41c68 | 1321 | char *address_arg = NULL, *source_arg = NULL, *objfile_arg = NULL; |
34c41c68 DE |
1322 | int i, outfile_idx, found; |
1323 | CORE_ADDR pc = 0; | |
1324 | struct obj_section *section = NULL; | |
ccefe4c4 TT |
1325 | |
1326 | dont_repeat (); | |
1327 | ||
773a1edc | 1328 | gdb_argv argv (args); |
ccefe4c4 | 1329 | |
99e8a4f9 | 1330 | for (i = 0; argv != NULL && argv[i] != NULL; ++i) |
ccefe4c4 | 1331 | { |
34c41c68 DE |
1332 | if (strcmp (argv[i], "-pc") == 0) |
1333 | { | |
1334 | if (argv[i + 1] == NULL) | |
1335 | error (_("Missing pc value")); | |
1336 | address_arg = argv[++i]; | |
1337 | } | |
1338 | else if (strcmp (argv[i], "-source") == 0) | |
1339 | { | |
1340 | if (argv[i + 1] == NULL) | |
1341 | error (_("Missing source file")); | |
1342 | source_arg = argv[++i]; | |
1343 | } | |
1344 | else if (strcmp (argv[i], "-objfile") == 0) | |
1345 | { | |
1346 | if (argv[i + 1] == NULL) | |
1347 | error (_("Missing objfile name")); | |
1348 | objfile_arg = argv[++i]; | |
1349 | } | |
1350 | else if (strcmp (argv[i], "--") == 0) | |
1351 | { | |
1352 | /* End of options. */ | |
1353 | ++i; | |
1354 | break; | |
1355 | } | |
1356 | else if (argv[i][0] == '-') | |
ccefe4c4 | 1357 | { |
34c41c68 DE |
1358 | /* Future proofing: Don't allow OUTFILE to begin with "-". */ |
1359 | error (_("Unknown option: %s"), argv[i]); | |
ccefe4c4 | 1360 | } |
34c41c68 DE |
1361 | else |
1362 | break; | |
ccefe4c4 | 1363 | } |
34c41c68 | 1364 | outfile_idx = i; |
ccefe4c4 | 1365 | |
34c41c68 DE |
1366 | if (address_arg != NULL && source_arg != NULL) |
1367 | error (_("Must specify at most one of -pc and -source")); | |
ccefe4c4 | 1368 | |
d7e74731 PA |
1369 | stdio_file arg_outfile; |
1370 | ||
99e8a4f9 | 1371 | if (argv != NULL && argv[outfile_idx] != NULL) |
34c41c68 | 1372 | { |
34c41c68 DE |
1373 | if (argv[outfile_idx + 1] != NULL) |
1374 | error (_("Junk at end of command")); | |
ee0c3293 TT |
1375 | gdb::unique_xmalloc_ptr<char> outfile_name |
1376 | (tilde_expand (argv[outfile_idx])); | |
1377 | if (!arg_outfile.open (outfile_name.get (), FOPEN_WT)) | |
1378 | perror_with_name (outfile_name.get ()); | |
d7e74731 | 1379 | outfile = &arg_outfile; |
34c41c68 | 1380 | } |
ccefe4c4 | 1381 | |
34c41c68 DE |
1382 | if (address_arg != NULL) |
1383 | { | |
1384 | pc = parse_and_eval_address (address_arg); | |
1385 | /* If we fail to find a section, that's ok, try the lookup anyway. */ | |
1386 | section = find_pc_section (pc); | |
1387 | } | |
372405a5 | 1388 | |
34c41c68 | 1389 | found = 0; |
2030c079 | 1390 | for (objfile *objfile : current_program_space->objfiles ()) |
27618ce4 | 1391 | { |
34c41c68 DE |
1392 | int printed_objfile_header = 0; |
1393 | int print_for_objfile = 1; | |
1394 | ||
27618ce4 | 1395 | QUIT; |
34c41c68 DE |
1396 | if (objfile_arg != NULL) |
1397 | print_for_objfile | |
1398 | = compare_filenames_for_search (objfile_name (objfile), | |
1399 | objfile_arg); | |
1400 | if (!print_for_objfile) | |
1401 | continue; | |
1402 | ||
e1114590 | 1403 | for (const auto &iter : objfile->qf) |
34c41c68 | 1404 | { |
e1114590 TT |
1405 | psymbol_functions *psf |
1406 | = dynamic_cast<psymbol_functions *> (iter.get ()); | |
1407 | if (psf == nullptr) | |
1408 | continue; | |
34c41c68 | 1409 | |
e1114590 | 1410 | if (address_arg != NULL) |
34c41c68 | 1411 | { |
f6b3ad54 | 1412 | struct bound_minimal_symbol msymbol; |
34c41c68 | 1413 | |
e1114590 TT |
1414 | /* We don't assume each pc has a unique objfile (this is for |
1415 | debugging). */ | |
1416 | struct partial_symtab *ps | |
1417 | = psf->find_pc_sect_psymtab (objfile, pc, section, msymbol); | |
1418 | if (ps != NULL) | |
34c41c68 DE |
1419 | { |
1420 | if (!printed_objfile_header) | |
1421 | { | |
d7e74731 PA |
1422 | outfile->printf ("\nPartial symtabs for objfile %s\n", |
1423 | objfile_name (objfile)); | |
34c41c68 DE |
1424 | printed_objfile_header = 1; |
1425 | } | |
1426 | dump_psymtab (objfile, ps, outfile); | |
e1114590 TT |
1427 | found = 1; |
1428 | } | |
1429 | } | |
1430 | else | |
1431 | { | |
98aa8321 | 1432 | for (partial_symtab *ps : psf->partial_symbols (objfile)) |
e1114590 TT |
1433 | { |
1434 | int print_for_source = 0; | |
1435 | ||
1436 | QUIT; | |
1437 | if (source_arg != NULL) | |
1438 | { | |
1439 | print_for_source | |
1440 | = compare_filenames_for_search (ps->filename, source_arg); | |
1441 | found = 1; | |
1442 | } | |
1443 | if (source_arg == NULL | |
1444 | || print_for_source) | |
1445 | { | |
1446 | if (!printed_objfile_header) | |
1447 | { | |
1448 | outfile->printf ("\nPartial symtabs for objfile %s\n", | |
1449 | objfile_name (objfile)); | |
1450 | printed_objfile_header = 1; | |
1451 | } | |
1452 | dump_psymtab (objfile, ps, outfile); | |
e1114590 | 1453 | } |
34c41c68 DE |
1454 | } |
1455 | } | |
372405a5 | 1456 | } |
27618ce4 | 1457 | } |
372405a5 | 1458 | |
34c41c68 DE |
1459 | if (!found) |
1460 | { | |
1461 | if (address_arg != NULL) | |
1462 | error (_("No partial symtab for address: %s"), address_arg); | |
1463 | if (source_arg != NULL) | |
1464 | error (_("No partial symtab for source file: %s"), source_arg); | |
1465 | } | |
ccefe4c4 TT |
1466 | } |
1467 | ||
1468 | /* List all the partial symbol tables whose names match REGEXP (optional). */ | |
95cf5869 | 1469 | |
dfc7bb5b | 1470 | static void |
990b9f9f | 1471 | maintenance_info_psymtabs (const char *regexp, int from_tty) |
ccefe4c4 | 1472 | { |
ccefe4c4 TT |
1473 | if (regexp) |
1474 | re_comp (regexp); | |
1475 | ||
94c93c35 | 1476 | for (struct program_space *pspace : program_spaces) |
2030c079 | 1477 | for (objfile *objfile : pspace->objfiles ()) |
99d89cde | 1478 | { |
08feed99 | 1479 | struct gdbarch *gdbarch = objfile->arch (); |
ccefe4c4 | 1480 | |
99d89cde TT |
1481 | /* We don't want to print anything for this objfile until we |
1482 | actually find a symtab whose name matches. */ | |
1483 | int printed_objfile_start = 0; | |
ccefe4c4 | 1484 | |
e1114590 | 1485 | for (const auto &iter : objfile->qf) |
99d89cde | 1486 | { |
e1114590 TT |
1487 | psymbol_functions *psf |
1488 | = dynamic_cast<psymbol_functions *> (iter.get ()); | |
1489 | if (psf == nullptr) | |
1490 | continue; | |
98aa8321 | 1491 | for (partial_symtab *psymtab : psf->partial_symbols (objfile)) |
99d89cde | 1492 | { |
e1114590 | 1493 | QUIT; |
99d89cde | 1494 | |
e1114590 TT |
1495 | if (! regexp |
1496 | || re_exec (psymtab->filename)) | |
99d89cde | 1497 | { |
e1114590 TT |
1498 | if (! printed_objfile_start) |
1499 | { | |
6cb06a8c | 1500 | gdb_printf ("{ objfile %s ", objfile_name (objfile)); |
1285ce86 | 1501 | gdb_stdout->wrap_here (2); |
6cb06a8c TT |
1502 | gdb_printf ("((struct objfile *) %s)\n", |
1503 | host_address_to_string (objfile)); | |
e1114590 TT |
1504 | printed_objfile_start = 1; |
1505 | } | |
99d89cde | 1506 | |
6cb06a8c | 1507 | gdb_printf (" { psymtab %s ", psymtab->filename); |
1285ce86 | 1508 | gdb_stdout->wrap_here (4); |
6cb06a8c TT |
1509 | gdb_printf ("((struct partial_symtab *) %s)\n", |
1510 | host_address_to_string (psymtab)); | |
1511 | ||
1512 | gdb_printf (" readin %s\n", | |
1513 | psymtab->readin_p (objfile) ? "yes" : "no"); | |
1514 | gdb_printf (" fullname %s\n", | |
1515 | psymtab->fullname | |
1516 | ? psymtab->fullname : "(null)"); | |
1517 | gdb_printf (" text addresses "); | |
0426ad51 TT |
1518 | gdb_puts (paddress (gdbarch, |
1519 | psymtab->text_low (objfile))); | |
6cb06a8c | 1520 | gdb_printf (" -- "); |
0426ad51 TT |
1521 | gdb_puts (paddress (gdbarch, |
1522 | psymtab->text_high (objfile))); | |
6cb06a8c | 1523 | gdb_printf ("\n"); |
6cb06a8c | 1524 | gdb_printf (" globals "); |
e1114590 | 1525 | if (!psymtab->global_psymbols.empty ()) |
6cb06a8c | 1526 | gdb_printf |
e1114590 TT |
1527 | ("(* (struct partial_symbol **) %s @ %d)\n", |
1528 | host_address_to_string (psymtab->global_psymbols.data ()), | |
1529 | (int) psymtab->global_psymbols.size ()); | |
1530 | else | |
6cb06a8c TT |
1531 | gdb_printf ("(none)\n"); |
1532 | gdb_printf (" statics "); | |
e1114590 | 1533 | if (!psymtab->static_psymbols.empty ()) |
6cb06a8c | 1534 | gdb_printf |
e1114590 TT |
1535 | ("(* (struct partial_symbol **) %s @ %d)\n", |
1536 | host_address_to_string (psymtab->static_psymbols.data ()), | |
1537 | (int) psymtab->static_psymbols.size ()); | |
1538 | else | |
6cb06a8c | 1539 | gdb_printf ("(none)\n"); |
e1114590 | 1540 | if (psymtab->user) |
6cb06a8c TT |
1541 | gdb_printf (" user %s " |
1542 | "((struct partial_symtab *) %s)\n", | |
1543 | psymtab->user->filename, | |
1544 | host_address_to_string (psymtab->user)); | |
1545 | gdb_printf (" dependencies "); | |
e1114590 | 1546 | if (psymtab->number_of_dependencies) |
99d89cde | 1547 | { |
e1114590 TT |
1548 | int i; |
1549 | ||
6cb06a8c | 1550 | gdb_printf ("{\n"); |
e1114590 TT |
1551 | for (i = 0; i < psymtab->number_of_dependencies; i++) |
1552 | { | |
1553 | struct partial_symtab *dep = psymtab->dependencies[i]; | |
1554 | ||
1555 | /* Note the string concatenation there --- no | |
1556 | comma. */ | |
6cb06a8c TT |
1557 | gdb_printf (" psymtab %s " |
1558 | "((struct partial_symtab *) %s)\n", | |
1559 | dep->filename, | |
1560 | host_address_to_string (dep)); | |
e1114590 | 1561 | } |
6cb06a8c | 1562 | gdb_printf (" }\n"); |
99d89cde | 1563 | } |
e1114590 | 1564 | else |
6cb06a8c TT |
1565 | gdb_printf ("(none)\n"); |
1566 | gdb_printf (" }\n"); | |
99d89cde | 1567 | } |
99d89cde TT |
1568 | } |
1569 | } | |
ccefe4c4 | 1570 | |
99d89cde | 1571 | if (printed_objfile_start) |
6cb06a8c | 1572 | gdb_printf ("}\n"); |
99d89cde | 1573 | } |
ccefe4c4 TT |
1574 | } |
1575 | ||
7d0c9981 | 1576 | /* Check consistency of currently expanded psymtabs vs symtabs. */ |
ccefe4c4 | 1577 | |
dfc7bb5b | 1578 | static void |
990b9f9f | 1579 | maintenance_check_psymtabs (const char *ignore, int from_tty) |
ccefe4c4 TT |
1580 | { |
1581 | struct symbol *sym; | |
43f3e411 | 1582 | struct compunit_symtab *cust = NULL; |
346d1dfe | 1583 | const struct blockvector *bv; |
582942f4 | 1584 | const struct block *b; |
ccefe4c4 | 1585 | |
2030c079 | 1586 | for (objfile *objfile : current_program_space->objfiles ()) |
3aa31ce7 | 1587 | { |
e1114590 | 1588 | for (const auto &iter : objfile->qf) |
3aa31ce7 | 1589 | { |
e1114590 TT |
1590 | psymbol_functions *psf |
1591 | = dynamic_cast<psymbol_functions *> (iter.get ()); | |
1592 | if (psf == nullptr) | |
1593 | continue; | |
aed57c53 | 1594 | |
98aa8321 | 1595 | for (partial_symtab *ps : psf->partial_symbols (objfile)) |
3aa31ce7 | 1596 | { |
e1114590 | 1597 | struct gdbarch *gdbarch = objfile->arch (); |
5707e24b | 1598 | |
e1114590 TT |
1599 | /* We don't call psymtab_to_symtab here because that may cause symtab |
1600 | expansion. When debugging a problem it helps if checkers leave | |
1601 | things unchanged. */ | |
1602 | cust = ps->get_compunit_symtab (objfile); | |
3aa31ce7 | 1603 | |
e1114590 TT |
1604 | /* First do some checks that don't require the associated symtab. */ |
1605 | if (ps->text_high (objfile) < ps->text_low (objfile)) | |
3aa31ce7 | 1606 | { |
6cb06a8c | 1607 | gdb_printf ("Psymtab "); |
0426ad51 | 1608 | gdb_puts (ps->filename); |
6cb06a8c | 1609 | gdb_printf (" covers bad range "); |
0426ad51 | 1610 | gdb_puts (paddress (gdbarch, ps->text_low (objfile))); |
6cb06a8c | 1611 | gdb_printf (" - "); |
0426ad51 | 1612 | gdb_puts (paddress (gdbarch, ps->text_high (objfile))); |
6cb06a8c | 1613 | gdb_printf ("\n"); |
e1114590 | 1614 | continue; |
3aa31ce7 | 1615 | } |
e1114590 TT |
1616 | |
1617 | /* Now do checks requiring the associated symtab. */ | |
1618 | if (cust == NULL) | |
1619 | continue; | |
af39c5c8 | 1620 | bv = cust->blockvector (); |
63d609de | 1621 | b = bv->static_block (); |
e1114590 TT |
1622 | for (partial_symbol *psym : ps->static_psymbols) |
1623 | { | |
1624 | /* Skip symbols for inlined functions without address. These may | |
1625 | or may not have a match in the full symtab. */ | |
1626 | if (psym->aclass == LOC_BLOCK | |
4aeddc50 | 1627 | && psym->ginfo.value_address () == 0) |
e1114590 TT |
1628 | continue; |
1629 | ||
1630 | sym = block_lookup_symbol (b, psym->ginfo.search_name (), | |
1631 | symbol_name_match_type::SEARCH_NAME, | |
1632 | psym->domain); | |
1633 | if (!sym) | |
1634 | { | |
6cb06a8c | 1635 | gdb_printf ("Static symbol `"); |
0426ad51 | 1636 | gdb_puts (psym->ginfo.linkage_name ()); |
6cb06a8c | 1637 | gdb_printf ("' only found in "); |
0426ad51 | 1638 | gdb_puts (ps->filename); |
6cb06a8c | 1639 | gdb_printf (" psymtab\n"); |
e1114590 TT |
1640 | } |
1641 | } | |
63d609de | 1642 | b = bv->global_block (); |
e1114590 TT |
1643 | for (partial_symbol *psym : ps->global_psymbols) |
1644 | { | |
1645 | sym = block_lookup_symbol (b, psym->ginfo.search_name (), | |
1646 | symbol_name_match_type::SEARCH_NAME, | |
1647 | psym->domain); | |
1648 | if (!sym) | |
1649 | { | |
6cb06a8c | 1650 | gdb_printf ("Global symbol `"); |
0426ad51 | 1651 | gdb_puts (psym->ginfo.linkage_name ()); |
6cb06a8c | 1652 | gdb_printf ("' only found in "); |
0426ad51 | 1653 | gdb_puts (ps->filename); |
6cb06a8c | 1654 | gdb_printf (" psymtab\n"); |
e1114590 TT |
1655 | } |
1656 | } | |
584d0cda | 1657 | if (ps->raw_text_high () != unrelocated_addr (0) |
4b8791e1 SM |
1658 | && (ps->text_low (objfile) < b->start () |
1659 | || ps->text_high (objfile) > b->end ())) | |
3aa31ce7 | 1660 | { |
6cb06a8c | 1661 | gdb_printf ("Psymtab "); |
0426ad51 | 1662 | gdb_puts (ps->filename); |
6cb06a8c | 1663 | gdb_printf (" covers "); |
0426ad51 | 1664 | gdb_puts (paddress (gdbarch, ps->text_low (objfile))); |
6cb06a8c | 1665 | gdb_printf (" - "); |
0426ad51 | 1666 | gdb_puts (paddress (gdbarch, ps->text_high (objfile))); |
6cb06a8c | 1667 | gdb_printf (" but symtab covers only "); |
4b8791e1 | 1668 | gdb_puts (paddress (gdbarch, b->start ())); |
6cb06a8c | 1669 | gdb_printf (" - "); |
4b8791e1 | 1670 | gdb_puts (paddress (gdbarch, b->end ())); |
6cb06a8c | 1671 | gdb_printf ("\n"); |
3aa31ce7 TT |
1672 | } |
1673 | } | |
3aa31ce7 TT |
1674 | } |
1675 | } | |
ccefe4c4 TT |
1676 | } |
1677 | ||
6c265988 | 1678 | void _initialize_psymtab (); |
dfc7bb5b | 1679 | void |
6c265988 | 1680 | _initialize_psymtab () |
dfc7bb5b YQ |
1681 | { |
1682 | add_cmd ("psymbols", class_maintenance, maintenance_print_psymbols, _("\ | |
1683 | Print dump of current partial symbol definitions.\n\ | |
48c5e7e2 TT |
1684 | Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\ |
1685 | mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\ | |
34c41c68 DE |
1686 | Entries in the partial symbol table are dumped to file OUTFILE,\n\ |
1687 | or the terminal if OUTFILE is unspecified.\n\ | |
1688 | If ADDRESS is provided, dump only the file for that address.\n\ | |
1689 | If SOURCE is provided, dump only that file's symbols.\n\ | |
1690 | If OBJFILE is provided, dump only that file's minimal symbols."), | |
dfc7bb5b YQ |
1691 | &maintenanceprintlist); |
1692 | ||
1693 | add_cmd ("psymtabs", class_maintenance, maintenance_info_psymtabs, _("\ | |
1694 | List the partial symbol tables for all object files.\n\ | |
1695 | This does not include information about individual partial symbols,\n\ | |
1696 | just the symbol table structures themselves."), | |
1697 | &maintenanceinfolist); | |
1698 | ||
7d0c9981 DE |
1699 | add_cmd ("check-psymtabs", class_maintenance, maintenance_check_psymtabs, |
1700 | _("\ | |
1701 | Check consistency of currently expanded psymtabs versus symtabs."), | |
dfc7bb5b YQ |
1702 | &maintenancelist); |
1703 | } |