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