Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Do various things to symbol tables (other than lookup), for GDB. |
af5f3db6 | 2 | |
3666a048 | 3 | Copyright (C) 1986-2021 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
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 | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
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. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
21 | #include "symtab.h" | |
22 | #include "gdbtypes.h" | |
23 | #include "bfd.h" | |
0ba1096a | 24 | #include "filenames.h" |
c906108c SS |
25 | #include "symfile.h" |
26 | #include "objfiles.h" | |
27 | #include "breakpoint.h" | |
28 | #include "command.h" | |
04ea0df1 | 29 | #include "gdb_obstack.h" |
c906108c SS |
30 | #include "language.h" |
31 | #include "bcache.h" | |
fe898f56 | 32 | #include "block.h" |
44ea7b70 | 33 | #include "gdb_regex.h" |
53ce3c39 | 34 | #include <sys/stat.h> |
de4f826b | 35 | #include "dictionary.h" |
79d43c61 | 36 | #include "typeprint.h" |
80480540 | 37 | #include "gdbcmd.h" |
05cba821 | 38 | #include "source.h" |
e0eac551 | 39 | #include "readline/tilde.h" |
c906108c | 40 | |
ccefe4c4 | 41 | #include "psymtab.h" |
0684bb51 | 42 | #include "psympriv.h" |
ccefe4c4 | 43 | |
c906108c SS |
44 | /* Prototypes for local functions */ |
45 | ||
582942f4 | 46 | static int block_depth (const struct block *); |
c906108c | 47 | |
bf469271 PA |
48 | static void print_symbol (struct gdbarch *gdbarch, struct symbol *symbol, |
49 | int depth, ui_file *outfile); | |
c906108c | 50 | \f |
c906108c | 51 | |
c906108c | 52 | void |
fba45db2 | 53 | print_symbol_bcache_statistics (void) |
c906108c | 54 | { |
94c93c35 | 55 | for (struct program_space *pspace : program_spaces) |
2030c079 | 56 | for (objfile *objfile : pspace->objfiles ()) |
99d89cde TT |
57 | { |
58 | QUIT; | |
59 | printf_filtered (_("Byte cache statistics for '%s':\n"), | |
60 | objfile_name (objfile)); | |
25629dfd TT |
61 | objfile->partial_symtabs->psymbol_cache.print_statistics |
62 | ("partial symbol cache"); | |
be1e3d3e | 63 | objfile->per_bfd->string_cache.print_statistics ("string cache"); |
99d89cde | 64 | } |
c906108c SS |
65 | } |
66 | ||
0684bb51 TT |
67 | /* Count the number of partial symbols in OBJFILE. */ |
68 | ||
69 | static int | |
70 | count_psyms (struct objfile *objfile) | |
71 | { | |
72 | int count = 0; | |
73 | for (partial_symtab *pst : objfile->psymtabs ()) | |
74 | { | |
75 | count += pst->global_psymbols.size (); | |
76 | count += pst->static_psymbols.size (); | |
77 | } | |
78 | return count; | |
79 | } | |
80 | ||
c906108c | 81 | void |
fba45db2 | 82 | print_objfile_statistics (void) |
c906108c | 83 | { |
c4f90d87 | 84 | int i, linetables, blockvectors; |
c906108c | 85 | |
94c93c35 TT |
86 | for (struct program_space *pspace : program_spaces) |
87 | for (objfile *objfile : pspace->objfiles ()) | |
88 | { | |
89 | QUIT; | |
90 | printf_filtered (_("Statistics for '%s':\n"), objfile_name (objfile)); | |
91 | if (OBJSTAT (objfile, n_stabs) > 0) | |
92 | printf_filtered (_(" Number of \"stab\" symbols read: %d\n"), | |
93 | OBJSTAT (objfile, n_stabs)); | |
94 | if (objfile->per_bfd->n_minsyms > 0) | |
95 | printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"), | |
96 | objfile->per_bfd->n_minsyms); | |
0684bb51 TT |
97 | |
98 | int n_psyms = count_psyms (objfile); | |
99 | if (n_psyms > 0) | |
94c93c35 | 100 | printf_filtered (_(" Number of \"partial\" symbols read: %d\n"), |
0684bb51 | 101 | n_psyms); |
94c93c35 TT |
102 | if (OBJSTAT (objfile, n_syms) > 0) |
103 | printf_filtered (_(" Number of \"full\" symbols read: %d\n"), | |
104 | OBJSTAT (objfile, n_syms)); | |
105 | if (OBJSTAT (objfile, n_types) > 0) | |
106 | printf_filtered (_(" Number of \"types\" defined: %d\n"), | |
107 | OBJSTAT (objfile, n_types)); | |
108 | if (objfile->sf) | |
109 | objfile->sf->qf->print_stats (objfile); | |
110 | i = linetables = 0; | |
111 | for (compunit_symtab *cu : objfile->compunits ()) | |
112 | { | |
113 | for (symtab *s : compunit_filetabs (cu)) | |
114 | { | |
115 | i++; | |
116 | if (SYMTAB_LINETABLE (s) != NULL) | |
117 | linetables++; | |
118 | } | |
119 | } | |
120 | blockvectors = std::distance (objfile->compunits ().begin (), | |
121 | objfile->compunits ().end ()); | |
122 | printf_filtered (_(" Number of symbol tables: %d\n"), i); | |
123 | printf_filtered (_(" Number of symbol tables with line tables: %d\n"), | |
124 | linetables); | |
125 | printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"), | |
126 | blockvectors); | |
127 | ||
128 | if (OBJSTAT (objfile, sz_strtab) > 0) | |
129 | printf_filtered (_(" Space used by string tables: %d\n"), | |
130 | OBJSTAT (objfile, sz_strtab)); | |
131 | printf_filtered (_(" Total memory used for objfile obstack: %s\n"), | |
132 | pulongest (obstack_memory_used (&objfile | |
133 | ->objfile_obstack))); | |
134 | printf_filtered (_(" Total memory used for BFD obstack: %s\n"), | |
135 | pulongest (obstack_memory_used (&objfile->per_bfd | |
136 | ->storage_obstack))); | |
137 | printf_filtered | |
138 | (_(" Total memory used for psymbol cache: %d\n"), | |
139 | objfile->partial_symtabs->psymbol_cache.memory_used ()); | |
140 | printf_filtered (_(" Total memory used for string cache: %d\n"), | |
141 | objfile->per_bfd->string_cache.memory_used ()); | |
142 | } | |
c906108c SS |
143 | } |
144 | ||
c5aa993b | 145 | static void |
fba45db2 | 146 | dump_objfile (struct objfile *objfile) |
c906108c | 147 | { |
4262abfb | 148 | printf_filtered ("\nObject file %s: ", objfile_name (objfile)); |
c906108c | 149 | printf_filtered ("Objfile at "); |
d4f3574e | 150 | gdb_print_host_address (objfile, gdb_stdout); |
c906108c | 151 | printf_filtered (", bfd at "); |
d4f3574e | 152 | gdb_print_host_address (objfile->obfd, gdb_stdout); |
c906108c | 153 | printf_filtered (", %d minsyms\n\n", |
34643a32 | 154 | objfile->per_bfd->minimal_symbol_count); |
c906108c | 155 | |
ccefe4c4 TT |
156 | if (objfile->sf) |
157 | objfile->sf->qf->dump (objfile); | |
c906108c | 158 | |
43f3e411 | 159 | if (objfile->compunit_symtabs != NULL) |
c906108c SS |
160 | { |
161 | printf_filtered ("Symtabs:\n"); | |
b669c953 | 162 | for (compunit_symtab *cu : objfile->compunits ()) |
c906108c | 163 | { |
d5da8b3c | 164 | for (symtab *symtab : compunit_filetabs (cu)) |
c906108c | 165 | { |
d5da8b3c TT |
166 | printf_filtered ("%s at ", |
167 | symtab_to_filename_for_display (symtab)); | |
168 | gdb_print_host_address (symtab, gdb_stdout); | |
169 | printf_filtered (", "); | |
170 | if (SYMTAB_OBJFILE (symtab) != objfile) | |
171 | { | |
172 | printf_filtered ("NOT ON CHAIN! "); | |
173 | } | |
174 | wrap_here (" "); | |
c906108c | 175 | } |
c906108c SS |
176 | } |
177 | printf_filtered ("\n\n"); | |
178 | } | |
179 | } | |
180 | ||
181 | /* Print minimal symbols from this objfile. */ | |
c5aa993b JM |
182 | |
183 | static void | |
fba45db2 | 184 | dump_msymbols (struct objfile *objfile, struct ui_file *outfile) |
c906108c | 185 | { |
08feed99 | 186 | struct gdbarch *gdbarch = objfile->arch (); |
c906108c SS |
187 | int index; |
188 | char ms_type; | |
c5aa993b | 189 | |
4262abfb | 190 | fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile_name (objfile)); |
34643a32 | 191 | if (objfile->per_bfd->minimal_symbol_count == 0) |
c906108c SS |
192 | { |
193 | fprintf_filtered (outfile, "No minimal symbols found.\n"); | |
194 | return; | |
195 | } | |
3567439c | 196 | index = 0; |
7932255d | 197 | for (minimal_symbol *msymbol : objfile->msymbols ()) |
c906108c | 198 | { |
ebbc3a7d | 199 | struct obj_section *section = msymbol->obj_section (objfile); |
714835d5 | 200 | |
712f90be | 201 | switch (MSYMBOL_TYPE (msymbol)) |
c906108c | 202 | { |
c5aa993b JM |
203 | case mst_unknown: |
204 | ms_type = 'u'; | |
205 | break; | |
206 | case mst_text: | |
207 | ms_type = 'T'; | |
208 | break; | |
0875794a | 209 | case mst_text_gnu_ifunc: |
f50776aa | 210 | case mst_data_gnu_ifunc: |
0875794a JK |
211 | ms_type = 'i'; |
212 | break; | |
c5aa993b JM |
213 | case mst_solib_trampoline: |
214 | ms_type = 'S'; | |
215 | break; | |
216 | case mst_data: | |
217 | ms_type = 'D'; | |
218 | break; | |
219 | case mst_bss: | |
220 | ms_type = 'B'; | |
221 | break; | |
222 | case mst_abs: | |
223 | ms_type = 'A'; | |
224 | break; | |
225 | case mst_file_text: | |
226 | ms_type = 't'; | |
227 | break; | |
228 | case mst_file_data: | |
229 | ms_type = 'd'; | |
230 | break; | |
231 | case mst_file_bss: | |
232 | ms_type = 'b'; | |
233 | break; | |
234 | default: | |
235 | ms_type = '?'; | |
236 | break; | |
c906108c SS |
237 | } |
238 | fprintf_filtered (outfile, "[%2d] %c ", index, ms_type); | |
4b610737 TT |
239 | |
240 | /* Use the relocated address as shown in the symbol here -- do | |
241 | not try to respect copy relocations. */ | |
242 | CORE_ADDR addr = (msymbol->value.address | |
6a053cb1 | 243 | + objfile->section_offsets[msymbol->section]); |
4b610737 | 244 | fputs_filtered (paddress (gdbarch, addr), outfile); |
c9d95fa3 | 245 | fprintf_filtered (outfile, " %s", msymbol->linkage_name ()); |
714835d5 | 246 | if (section) |
8625fc1b TT |
247 | { |
248 | if (section->the_bfd_section != NULL) | |
249 | fprintf_filtered (outfile, " section %s", | |
fd361982 | 250 | bfd_section_name (section->the_bfd_section)); |
8625fc1b TT |
251 | else |
252 | fprintf_filtered (outfile, " spurious section %ld", | |
4c8429ef | 253 | (long) (section - objfile->sections)); |
8625fc1b | 254 | } |
c9d95fa3 | 255 | if (msymbol->demangled_name () != NULL) |
c906108c | 256 | { |
c9d95fa3 | 257 | fprintf_filtered (outfile, " %s", msymbol->demangled_name ()); |
c906108c | 258 | } |
c906108c SS |
259 | if (msymbol->filename) |
260 | fprintf_filtered (outfile, " %s", msymbol->filename); | |
c906108c | 261 | fputs_filtered ("\n", outfile); |
3567439c | 262 | index++; |
c906108c | 263 | } |
34643a32 | 264 | if (objfile->per_bfd->minimal_symbol_count != index) |
c906108c | 265 | { |
8a3fe4f8 | 266 | warning (_("internal error: minimal symbol count %d != %d"), |
34643a32 | 267 | objfile->per_bfd->minimal_symbol_count, index); |
c906108c SS |
268 | } |
269 | fprintf_filtered (outfile, "\n"); | |
270 | } | |
271 | ||
c5aa993b | 272 | static void |
d04c1a59 | 273 | dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile) |
c906108c | 274 | { |
d04c1a59 | 275 | struct objfile *objfile = SYMTAB_OBJFILE (symtab); |
08feed99 | 276 | struct gdbarch *gdbarch = objfile->arch (); |
de4f826b | 277 | int i; |
b026f593 | 278 | struct mdict_iterator miter; |
952a6d41 | 279 | int len; |
de4f826b | 280 | struct linetable *l; |
346d1dfe | 281 | const struct blockvector *bv; |
e88c90f2 | 282 | struct symbol *sym; |
582942f4 | 283 | const struct block *b; |
c906108c SS |
284 | int depth; |
285 | ||
7b1eff95 TV |
286 | fprintf_filtered (outfile, "\nSymtab for file %s at %s\n", |
287 | symtab_to_filename_for_display (symtab), | |
288 | host_address_to_string (symtab)); | |
289 | ||
ee6f8984 | 290 | if (SYMTAB_DIRNAME (symtab) != NULL) |
c906108c | 291 | fprintf_filtered (outfile, "Compilation directory is %s\n", |
ee6f8984 | 292 | SYMTAB_DIRNAME (symtab)); |
4262abfb JK |
293 | fprintf_filtered (outfile, "Read from object file %s (", |
294 | objfile_name (objfile)); | |
d4f3574e | 295 | gdb_print_host_address (objfile, outfile); |
c906108c | 296 | fprintf_filtered (outfile, ")\n"); |
3e43a32a MS |
297 | fprintf_filtered (outfile, "Language: %s\n", |
298 | language_str (symtab->language)); | |
c906108c SS |
299 | |
300 | /* First print the line table. */ | |
8435453b | 301 | l = SYMTAB_LINETABLE (symtab); |
c906108c SS |
302 | if (l) |
303 | { | |
304 | fprintf_filtered (outfile, "\nLine table:\n\n"); | |
305 | len = l->nitems; | |
306 | for (i = 0; i < len; i++) | |
307 | { | |
308 | fprintf_filtered (outfile, " line %d at ", l->item[i].line); | |
5af949e3 | 309 | fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile); |
8c95582d AB |
310 | if (l->item[i].is_stmt) |
311 | fprintf_filtered (outfile, "\t(stmt)"); | |
c906108c SS |
312 | fprintf_filtered (outfile, "\n"); |
313 | } | |
314 | } | |
43f3e411 | 315 | /* Now print the block info, but only for compunit symtabs since we will |
c378eb4e | 316 | print lots of duplicate info otherwise. */ |
7b1eff95 | 317 | if (is_main_symtab_of_compunit_symtab (symtab)) |
c906108c SS |
318 | { |
319 | fprintf_filtered (outfile, "\nBlockvector:\n\n"); | |
439247b6 | 320 | bv = SYMTAB_BLOCKVECTOR (symtab); |
c906108c SS |
321 | len = BLOCKVECTOR_NBLOCKS (bv); |
322 | for (i = 0; i < len; i++) | |
323 | { | |
324 | b = BLOCKVECTOR_BLOCK (bv, i); | |
325 | depth = block_depth (b) * 2; | |
326 | print_spaces (depth, outfile); | |
327 | fprintf_filtered (outfile, "block #%03d, object at ", i); | |
d4f3574e | 328 | gdb_print_host_address (b, outfile); |
c906108c SS |
329 | if (BLOCK_SUPERBLOCK (b)) |
330 | { | |
331 | fprintf_filtered (outfile, " under "); | |
d4f3574e | 332 | gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile); |
c906108c | 333 | } |
261397f8 DJ |
334 | /* drow/2002-07-10: We could save the total symbols count |
335 | even if we're using a hashtable, but nothing else but this message | |
336 | wants it. */ | |
de4f826b | 337 | fprintf_filtered (outfile, ", %d syms/buckets in ", |
b026f593 | 338 | mdict_size (BLOCK_MULTIDICT (b))); |
5af949e3 | 339 | fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile); |
c906108c | 340 | fprintf_filtered (outfile, ".."); |
5af949e3 | 341 | fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile); |
c906108c SS |
342 | if (BLOCK_FUNCTION (b)) |
343 | { | |
3567439c | 344 | fprintf_filtered (outfile, ", function %s", |
987012b8 CB |
345 | BLOCK_FUNCTION (b)->linkage_name ()); |
346 | if (BLOCK_FUNCTION (b)->demangled_name () != NULL) | |
c906108c SS |
347 | { |
348 | fprintf_filtered (outfile, ", %s", | |
987012b8 | 349 | BLOCK_FUNCTION (b)->demangled_name ()); |
c906108c SS |
350 | } |
351 | } | |
c906108c | 352 | fprintf_filtered (outfile, "\n"); |
261397f8 | 353 | /* Now print each symbol in this block (in no particular order, if |
8157b174 TT |
354 | we're using a hashtable). Note that we only want this |
355 | block, not any blocks from included symtabs. */ | |
b026f593 | 356 | ALL_DICT_SYMBOLS (BLOCK_MULTIDICT (b), miter, sym) |
c906108c | 357 | { |
a70b8144 | 358 | try |
bf469271 PA |
359 | { |
360 | print_symbol (gdbarch, sym, depth + 1, outfile); | |
361 | } | |
230d2906 | 362 | catch (const gdb_exception_error &ex) |
bf469271 PA |
363 | { |
364 | exception_fprintf (gdb_stderr, ex, | |
365 | "Error printing symbol:\n"); | |
366 | } | |
c906108c SS |
367 | } |
368 | } | |
369 | fprintf_filtered (outfile, "\n"); | |
370 | } | |
371 | else | |
372 | { | |
6c739336 DE |
373 | const char *compunit_filename |
374 | = symtab_to_filename_for_display (COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab))); | |
375 | ||
376 | fprintf_filtered (outfile, | |
377 | "\nBlockvector same as owning compunit: %s\n\n", | |
378 | compunit_filename); | |
c906108c | 379 | } |
7b1eff95 TV |
380 | |
381 | /* Print info about the user of this compunit_symtab, and the | |
382 | compunit_symtabs included by this one. */ | |
383 | if (is_main_symtab_of_compunit_symtab (symtab)) | |
384 | { | |
385 | struct compunit_symtab *cust = SYMTAB_COMPUNIT (symtab); | |
386 | ||
387 | if (cust->user != nullptr) | |
388 | { | |
389 | const char *addr | |
390 | = host_address_to_string (COMPUNIT_FILETABS (cust->user)); | |
391 | fprintf_filtered (outfile, "Compunit user: %s\n", addr); | |
392 | } | |
393 | if (cust->includes != nullptr) | |
394 | for (i = 0; ; ++i) | |
395 | { | |
396 | struct compunit_symtab *include = cust->includes[i]; | |
397 | if (include == nullptr) | |
398 | break; | |
399 | const char *addr | |
400 | = host_address_to_string (COMPUNIT_FILETABS (include)); | |
401 | fprintf_filtered (outfile, "Compunit include: %s\n", addr); | |
402 | } | |
403 | } | |
c906108c SS |
404 | } |
405 | ||
44b164c5 | 406 | static void |
d04c1a59 | 407 | dump_symtab (struct symtab *symtab, struct ui_file *outfile) |
44b164c5 | 408 | { |
44b164c5 JB |
409 | /* Set the current language to the language of the symtab we're dumping |
410 | because certain routines used during dump_symtab() use the current | |
969107c5 EZ |
411 | language to print an image of the symbol. We'll restore it later. |
412 | But use only real languages, not placeholders. */ | |
413 | if (symtab->language != language_unknown | |
414 | && symtab->language != language_auto) | |
415 | { | |
9bb9b2f9 TT |
416 | scoped_restore_current_language save_lang; |
417 | set_language (symtab->language); | |
d04c1a59 | 418 | dump_symtab_1 (symtab, outfile); |
969107c5 EZ |
419 | } |
420 | else | |
d04c1a59 | 421 | dump_symtab_1 (symtab, outfile); |
44b164c5 JB |
422 | } |
423 | ||
80480540 | 424 | static void |
e99c83e7 | 425 | maintenance_print_symbols (const char *args, int from_tty) |
c906108c | 426 | { |
34c41c68 | 427 | struct ui_file *outfile = gdb_stdout; |
34c41c68 DE |
428 | char *address_arg = NULL, *source_arg = NULL, *objfile_arg = NULL; |
429 | int i, outfile_idx; | |
c906108c SS |
430 | |
431 | dont_repeat (); | |
432 | ||
773a1edc | 433 | gdb_argv argv (args); |
c906108c | 434 | |
99e8a4f9 | 435 | for (i = 0; argv != NULL && argv[i] != NULL; ++i) |
c906108c | 436 | { |
34c41c68 DE |
437 | if (strcmp (argv[i], "-pc") == 0) |
438 | { | |
439 | if (argv[i + 1] == NULL) | |
440 | error (_("Missing pc value")); | |
441 | address_arg = argv[++i]; | |
442 | } | |
443 | else if (strcmp (argv[i], "-source") == 0) | |
444 | { | |
445 | if (argv[i + 1] == NULL) | |
446 | error (_("Missing source file")); | |
447 | source_arg = argv[++i]; | |
448 | } | |
449 | else if (strcmp (argv[i], "-objfile") == 0) | |
450 | { | |
451 | if (argv[i + 1] == NULL) | |
452 | error (_("Missing objfile name")); | |
453 | objfile_arg = argv[++i]; | |
454 | } | |
455 | else if (strcmp (argv[i], "--") == 0) | |
456 | { | |
457 | /* End of options. */ | |
458 | ++i; | |
459 | break; | |
460 | } | |
461 | else if (argv[i][0] == '-') | |
c906108c | 462 | { |
34c41c68 DE |
463 | /* Future proofing: Don't allow OUTFILE to begin with "-". */ |
464 | error (_("Unknown option: %s"), argv[i]); | |
c906108c | 465 | } |
34c41c68 DE |
466 | else |
467 | break; | |
c906108c | 468 | } |
34c41c68 | 469 | outfile_idx = i; |
c906108c | 470 | |
34c41c68 DE |
471 | if (address_arg != NULL && source_arg != NULL) |
472 | error (_("Must specify at most one of -pc and -source")); | |
c5aa993b | 473 | |
d7e74731 PA |
474 | stdio_file arg_outfile; |
475 | ||
99e8a4f9 | 476 | if (argv != NULL && argv[outfile_idx] != NULL) |
34c41c68 | 477 | { |
34c41c68 DE |
478 | if (argv[outfile_idx + 1] != NULL) |
479 | error (_("Junk at end of command")); | |
ee0c3293 TT |
480 | gdb::unique_xmalloc_ptr<char> outfile_name |
481 | (tilde_expand (argv[outfile_idx])); | |
482 | if (!arg_outfile.open (outfile_name.get (), FOPEN_WT)) | |
483 | perror_with_name (outfile_name.get ()); | |
d7e74731 | 484 | outfile = &arg_outfile; |
34c41c68 | 485 | } |
c906108c | 486 | |
34c41c68 | 487 | if (address_arg != NULL) |
27618ce4 | 488 | { |
34c41c68 DE |
489 | CORE_ADDR pc = parse_and_eval_address (address_arg); |
490 | struct symtab *s = find_pc_line_symtab (pc); | |
491 | ||
492 | if (s == NULL) | |
493 | error (_("No symtab for address: %s"), address_arg); | |
494 | dump_symtab (s, outfile); | |
27618ce4 | 495 | } |
34c41c68 DE |
496 | else |
497 | { | |
34c41c68 DE |
498 | int found = 0; |
499 | ||
2030c079 | 500 | for (objfile *objfile : current_program_space->objfiles ()) |
34c41c68 DE |
501 | { |
502 | int print_for_objfile = 1; | |
503 | ||
504 | if (objfile_arg != NULL) | |
505 | print_for_objfile | |
506 | = compare_filenames_for_search (objfile_name (objfile), | |
507 | objfile_arg); | |
508 | if (!print_for_objfile) | |
509 | continue; | |
510 | ||
b669c953 | 511 | for (compunit_symtab *cu : objfile->compunits ()) |
34c41c68 | 512 | { |
d5da8b3c | 513 | for (symtab *s : compunit_filetabs (cu)) |
34c41c68 | 514 | { |
d5da8b3c TT |
515 | int print_for_source = 0; |
516 | ||
517 | QUIT; | |
518 | if (source_arg != NULL) | |
519 | { | |
520 | print_for_source | |
521 | = compare_filenames_for_search | |
522 | (symtab_to_filename_for_display (s), source_arg); | |
523 | found = 1; | |
524 | } | |
525 | if (source_arg == NULL | |
526 | || print_for_source) | |
527 | dump_symtab (s, outfile); | |
34c41c68 | 528 | } |
34c41c68 DE |
529 | } |
530 | } | |
531 | ||
532 | if (source_arg != NULL && !found) | |
533 | error (_("No symtab for source file: %s"), source_arg); | |
534 | } | |
c906108c SS |
535 | } |
536 | ||
bf469271 | 537 | /* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */ |
c906108c | 538 | |
bf469271 PA |
539 | static void |
540 | print_symbol (struct gdbarch *gdbarch, struct symbol *symbol, | |
541 | int depth, ui_file *outfile) | |
c906108c | 542 | { |
1994afbf DE |
543 | struct obj_section *section; |
544 | ||
545 | if (SYMBOL_OBJFILE_OWNED (symbol)) | |
ebbc3a7d | 546 | section = symbol->obj_section (symbol_objfile (symbol)); |
1994afbf DE |
547 | else |
548 | section = NULL; | |
c906108c SS |
549 | |
550 | print_spaces (depth, outfile); | |
176620f1 | 551 | if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN) |
c906108c | 552 | { |
987012b8 | 553 | fprintf_filtered (outfile, "label %s at ", symbol->print_name ()); |
5af949e3 UW |
554 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)), |
555 | outfile); | |
714835d5 | 556 | if (section) |
c906108c | 557 | fprintf_filtered (outfile, " section %s\n", |
fd361982 | 558 | bfd_section_name (section->the_bfd_section)); |
c906108c SS |
559 | else |
560 | fprintf_filtered (outfile, "\n"); | |
bf469271 | 561 | return; |
c906108c | 562 | } |
bf469271 | 563 | |
176620f1 | 564 | if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN) |
c906108c | 565 | { |
7d93a1e0 | 566 | if (SYMBOL_TYPE (symbol)->name ()) |
c906108c | 567 | { |
79d43c61 TT |
568 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth, |
569 | &type_print_raw_options); | |
c906108c SS |
570 | } |
571 | else | |
572 | { | |
573 | fprintf_filtered (outfile, "%s %s = ", | |
78134374 | 574 | (SYMBOL_TYPE (symbol)->code () == TYPE_CODE_ENUM |
c5aa993b | 575 | ? "enum" |
78134374 | 576 | : (SYMBOL_TYPE (symbol)->code () == TYPE_CODE_STRUCT |
c5aa993b | 577 | ? "struct" : "union")), |
987012b8 | 578 | symbol->linkage_name ()); |
79d43c61 TT |
579 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth, |
580 | &type_print_raw_options); | |
c906108c SS |
581 | } |
582 | fprintf_filtered (outfile, ";\n"); | |
583 | } | |
584 | else | |
585 | { | |
586 | if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF) | |
587 | fprintf_filtered (outfile, "typedef "); | |
588 | if (SYMBOL_TYPE (symbol)) | |
589 | { | |
590 | /* Print details of types, except for enums where it's clutter. */ | |
987012b8 | 591 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), symbol->print_name (), |
c906108c | 592 | outfile, |
78134374 | 593 | SYMBOL_TYPE (symbol)->code () != TYPE_CODE_ENUM, |
79d43c61 TT |
594 | depth, |
595 | &type_print_raw_options); | |
c906108c SS |
596 | fprintf_filtered (outfile, "; "); |
597 | } | |
598 | else | |
987012b8 | 599 | fprintf_filtered (outfile, "%s ", symbol->print_name ()); |
c906108c SS |
600 | |
601 | switch (SYMBOL_CLASS (symbol)) | |
602 | { | |
603 | case LOC_CONST: | |
12df843f JK |
604 | fprintf_filtered (outfile, "const %s (%s)", |
605 | plongest (SYMBOL_VALUE (symbol)), | |
606 | hex_string (SYMBOL_VALUE (symbol))); | |
c906108c SS |
607 | break; |
608 | ||
609 | case LOC_CONST_BYTES: | |
610 | { | |
611 | unsigned i; | |
612 | struct type *type = check_typedef (SYMBOL_TYPE (symbol)); | |
433759f7 | 613 | |
cc1defb1 KS |
614 | fprintf_filtered (outfile, "const %s hex bytes:", |
615 | pulongest (TYPE_LENGTH (type))); | |
c906108c SS |
616 | for (i = 0; i < TYPE_LENGTH (type); i++) |
617 | fprintf_filtered (outfile, " %02x", | |
c5aa993b | 618 | (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]); |
c906108c SS |
619 | } |
620 | break; | |
621 | ||
622 | case LOC_STATIC: | |
623 | fprintf_filtered (outfile, "static at "); | |
5af949e3 UW |
624 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)), |
625 | outfile); | |
714835d5 | 626 | if (section) |
c906108c | 627 | fprintf_filtered (outfile, " section %s", |
fd361982 | 628 | bfd_section_name (section->the_bfd_section)); |
c906108c SS |
629 | break; |
630 | ||
c906108c | 631 | case LOC_REGISTER: |
2a2d4dc3 | 632 | if (SYMBOL_IS_ARGUMENT (symbol)) |
12df843f JK |
633 | fprintf_filtered (outfile, "parameter register %s", |
634 | plongest (SYMBOL_VALUE (symbol))); | |
2a2d4dc3 | 635 | else |
12df843f JK |
636 | fprintf_filtered (outfile, "register %s", |
637 | plongest (SYMBOL_VALUE (symbol))); | |
c906108c SS |
638 | break; |
639 | ||
640 | case LOC_ARG: | |
12df843f JK |
641 | fprintf_filtered (outfile, "arg at offset %s", |
642 | hex_string (SYMBOL_VALUE (symbol))); | |
c906108c SS |
643 | break; |
644 | ||
c906108c | 645 | case LOC_REF_ARG: |
12df843f JK |
646 | fprintf_filtered (outfile, "reference arg at %s", |
647 | hex_string (SYMBOL_VALUE (symbol))); | |
c906108c SS |
648 | break; |
649 | ||
c906108c | 650 | case LOC_REGPARM_ADDR: |
12df843f JK |
651 | fprintf_filtered (outfile, "address parameter register %s", |
652 | plongest (SYMBOL_VALUE (symbol))); | |
c906108c SS |
653 | break; |
654 | ||
655 | case LOC_LOCAL: | |
12df843f JK |
656 | fprintf_filtered (outfile, "local at offset %s", |
657 | hex_string (SYMBOL_VALUE (symbol))); | |
c906108c SS |
658 | break; |
659 | ||
c906108c SS |
660 | case LOC_TYPEDEF: |
661 | break; | |
662 | ||
663 | case LOC_LABEL: | |
664 | fprintf_filtered (outfile, "label at "); | |
5af949e3 UW |
665 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)), |
666 | outfile); | |
714835d5 | 667 | if (section) |
c906108c | 668 | fprintf_filtered (outfile, " section %s", |
fd361982 | 669 | bfd_section_name (section->the_bfd_section)); |
c906108c SS |
670 | break; |
671 | ||
672 | case LOC_BLOCK: | |
673 | fprintf_filtered (outfile, "block object "); | |
d4f3574e | 674 | gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile); |
c906108c | 675 | fprintf_filtered (outfile, ", "); |
5af949e3 UW |
676 | fputs_filtered (paddress (gdbarch, |
677 | BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))), | |
ed49a04f | 678 | outfile); |
c906108c | 679 | fprintf_filtered (outfile, ".."); |
5af949e3 UW |
680 | fputs_filtered (paddress (gdbarch, |
681 | BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))), | |
ed49a04f | 682 | outfile); |
714835d5 | 683 | if (section) |
c906108c | 684 | fprintf_filtered (outfile, " section %s", |
fd361982 | 685 | bfd_section_name (section->the_bfd_section)); |
c906108c SS |
686 | break; |
687 | ||
4c2df51b | 688 | case LOC_COMPUTED: |
4c2df51b DJ |
689 | fprintf_filtered (outfile, "computed at runtime"); |
690 | break; | |
691 | ||
c906108c SS |
692 | case LOC_UNRESOLVED: |
693 | fprintf_filtered (outfile, "unresolved"); | |
694 | break; | |
695 | ||
696 | case LOC_OPTIMIZED_OUT: | |
697 | fprintf_filtered (outfile, "optimized out"); | |
698 | break; | |
699 | ||
c5aa993b | 700 | default: |
c906108c SS |
701 | fprintf_filtered (outfile, "botched symbol class %x", |
702 | SYMBOL_CLASS (symbol)); | |
703 | break; | |
704 | } | |
705 | } | |
706 | fprintf_filtered (outfile, "\n"); | |
c906108c SS |
707 | } |
708 | ||
80480540 | 709 | static void |
e99c83e7 | 710 | maintenance_print_msymbols (const char *args, int from_tty) |
c906108c | 711 | { |
34c41c68 | 712 | struct ui_file *outfile = gdb_stdout; |
34c41c68 | 713 | char *objfile_arg = NULL; |
34c41c68 | 714 | int i, outfile_idx; |
07318b29 | 715 | |
c906108c SS |
716 | dont_repeat (); |
717 | ||
773a1edc | 718 | gdb_argv argv (args); |
c906108c | 719 | |
99e8a4f9 | 720 | for (i = 0; argv != NULL && argv[i] != NULL; ++i) |
c906108c | 721 | { |
34c41c68 | 722 | if (strcmp (argv[i], "-objfile") == 0) |
c906108c | 723 | { |
34c41c68 DE |
724 | if (argv[i + 1] == NULL) |
725 | error (_("Missing objfile name")); | |
726 | objfile_arg = argv[++i]; | |
727 | } | |
728 | else if (strcmp (argv[i], "--") == 0) | |
729 | { | |
730 | /* End of options. */ | |
731 | ++i; | |
732 | break; | |
c906108c | 733 | } |
34c41c68 DE |
734 | else if (argv[i][0] == '-') |
735 | { | |
736 | /* Future proofing: Don't allow OUTFILE to begin with "-". */ | |
737 | error (_("Unknown option: %s"), argv[i]); | |
738 | } | |
739 | else | |
740 | break; | |
c906108c | 741 | } |
34c41c68 | 742 | outfile_idx = i; |
c906108c | 743 | |
d7e74731 PA |
744 | stdio_file arg_outfile; |
745 | ||
99e8a4f9 | 746 | if (argv != NULL && argv[outfile_idx] != NULL) |
34c41c68 | 747 | { |
34c41c68 DE |
748 | if (argv[outfile_idx + 1] != NULL) |
749 | error (_("Junk at end of command")); | |
ee0c3293 TT |
750 | gdb::unique_xmalloc_ptr<char> outfile_name |
751 | (tilde_expand (argv[outfile_idx])); | |
752 | if (!arg_outfile.open (outfile_name.get (), FOPEN_WT)) | |
753 | perror_with_name (outfile_name.get ()); | |
d7e74731 | 754 | outfile = &arg_outfile; |
34c41c68 | 755 | } |
c5aa993b | 756 | |
2030c079 | 757 | for (objfile *objfile : current_program_space->objfiles ()) |
aed57c53 TT |
758 | { |
759 | QUIT; | |
760 | if (objfile_arg == NULL | |
761 | || compare_filenames_for_search (objfile_name (objfile), objfile_arg)) | |
762 | dump_msymbols (objfile, outfile); | |
763 | } | |
c906108c SS |
764 | } |
765 | ||
80480540 | 766 | static void |
e99c83e7 | 767 | maintenance_print_objfiles (const char *regexp, int from_tty) |
c906108c | 768 | { |
c906108c SS |
769 | dont_repeat (); |
770 | ||
52e260a3 DE |
771 | if (regexp) |
772 | re_comp (regexp); | |
773 | ||
94c93c35 | 774 | for (struct program_space *pspace : program_spaces) |
2030c079 | 775 | for (objfile *objfile : pspace->objfiles ()) |
27618ce4 TT |
776 | { |
777 | QUIT; | |
52e260a3 | 778 | if (! regexp |
4262abfb | 779 | || re_exec (objfile_name (objfile))) |
52e260a3 | 780 | dump_objfile (objfile); |
27618ce4 | 781 | } |
c906108c SS |
782 | } |
783 | ||
5e7b2f39 | 784 | /* List all the symbol tables whose names match REGEXP (optional). */ |
b5ebcee6 | 785 | |
80480540 | 786 | static void |
e99c83e7 | 787 | maintenance_info_symtabs (const char *regexp, int from_tty) |
44ea7b70 | 788 | { |
db68bbae DE |
789 | dont_repeat (); |
790 | ||
44ea7b70 JB |
791 | if (regexp) |
792 | re_comp (regexp); | |
793 | ||
94c93c35 | 794 | for (struct program_space *pspace : program_spaces) |
2030c079 | 795 | for (objfile *objfile : pspace->objfiles ()) |
99d89cde | 796 | { |
99d89cde TT |
797 | /* We don't want to print anything for this objfile until we |
798 | actually find a symtab whose name matches. */ | |
799 | int printed_objfile_start = 0; | |
43f3e411 | 800 | |
b669c953 | 801 | for (compunit_symtab *cust : objfile->compunits ()) |
99d89cde TT |
802 | { |
803 | int printed_compunit_symtab_start = 0; | |
804 | ||
5accd1a0 | 805 | for (symtab *symtab : compunit_filetabs (cust)) |
99d89cde TT |
806 | { |
807 | QUIT; | |
808 | ||
809 | if (! regexp | |
810 | || re_exec (symtab_to_filename_for_display (symtab))) | |
811 | { | |
812 | if (! printed_objfile_start) | |
813 | { | |
814 | printf_filtered ("{ objfile %s ", objfile_name (objfile)); | |
815 | wrap_here (" "); | |
816 | printf_filtered ("((struct objfile *) %s)\n", | |
817 | host_address_to_string (objfile)); | |
818 | printed_objfile_start = 1; | |
819 | } | |
820 | if (! printed_compunit_symtab_start) | |
821 | { | |
822 | printf_filtered (" { ((struct compunit_symtab *) %s)\n", | |
823 | host_address_to_string (cust)); | |
824 | printf_filtered (" debugformat %s\n", | |
825 | COMPUNIT_DEBUGFORMAT (cust)); | |
826 | printf_filtered (" producer %s\n", | |
827 | COMPUNIT_PRODUCER (cust) != NULL | |
828 | ? COMPUNIT_PRODUCER (cust) | |
829 | : "(null)"); | |
830 | printf_filtered (" dirname %s\n", | |
831 | COMPUNIT_DIRNAME (cust) != NULL | |
832 | ? COMPUNIT_DIRNAME (cust) | |
833 | : "(null)"); | |
834 | printf_filtered (" blockvector" | |
835 | " ((struct blockvector *) %s)\n", | |
836 | host_address_to_string | |
dda83cd7 | 837 | (COMPUNIT_BLOCKVECTOR (cust))); |
7b1eff95 TV |
838 | printf_filtered (" user" |
839 | " ((struct compunit_symtab *) %s)\n", | |
840 | cust->user != nullptr | |
841 | ? host_address_to_string (cust->user) | |
842 | : "(null)"); | |
843 | if (cust->includes != nullptr) | |
844 | { | |
845 | printf_filtered (" ( includes\n"); | |
846 | for (int i = 0; ; ++i) | |
847 | { | |
848 | struct compunit_symtab *include | |
849 | = cust->includes[i]; | |
850 | if (include == nullptr) | |
851 | break; | |
852 | const char *addr | |
853 | = host_address_to_string (include); | |
854 | printf_filtered (" (%s %s)\n", | |
855 | "(struct compunit_symtab *)", | |
856 | addr); | |
857 | } | |
858 | printf_filtered (" )\n"); | |
859 | } | |
99d89cde TT |
860 | printed_compunit_symtab_start = 1; |
861 | } | |
862 | ||
863 | printf_filtered ("\t{ symtab %s ", | |
864 | symtab_to_filename_for_display (symtab)); | |
865 | wrap_here (" "); | |
866 | printf_filtered ("((struct symtab *) %s)\n", | |
867 | host_address_to_string (symtab)); | |
868 | printf_filtered ("\t fullname %s\n", | |
869 | symtab->fullname != NULL | |
870 | ? symtab->fullname | |
871 | : "(null)"); | |
872 | printf_filtered ("\t " | |
873 | "linetable ((struct linetable *) %s)\n", | |
874 | host_address_to_string (symtab->linetable)); | |
875 | printf_filtered ("\t}\n"); | |
876 | } | |
877 | } | |
878 | ||
879 | if (printed_compunit_symtab_start) | |
880 | printf_filtered (" }\n"); | |
881 | } | |
44ea7b70 | 882 | |
99d89cde TT |
883 | if (printed_objfile_start) |
884 | printf_filtered ("}\n"); | |
885 | } | |
44ea7b70 | 886 | } |
7d0c9981 DE |
887 | |
888 | /* Check consistency of symtabs. | |
889 | An example of what this checks for is NULL blockvectors. | |
890 | They can happen if there's a bug during debug info reading. | |
891 | GDB assumes they are always non-NULL. | |
892 | ||
893 | Note: This does not check for psymtab vs symtab consistency. | |
894 | Use "maint check-psymtabs" for that. */ | |
895 | ||
896 | static void | |
e99c83e7 | 897 | maintenance_check_symtabs (const char *ignore, int from_tty) |
7d0c9981 | 898 | { |
94c93c35 | 899 | for (struct program_space *pspace : program_spaces) |
2030c079 | 900 | for (objfile *objfile : pspace->objfiles ()) |
99d89cde | 901 | { |
99d89cde TT |
902 | /* We don't want to print anything for this objfile until we |
903 | actually find something worth printing. */ | |
904 | int printed_objfile_start = 0; | |
7d0c9981 | 905 | |
b669c953 | 906 | for (compunit_symtab *cust : objfile->compunits ()) |
99d89cde TT |
907 | { |
908 | int found_something = 0; | |
909 | struct symtab *symtab = compunit_primary_filetab (cust); | |
910 | ||
911 | QUIT; | |
912 | ||
913 | if (COMPUNIT_BLOCKVECTOR (cust) == NULL) | |
914 | found_something = 1; | |
915 | /* Add more checks here. */ | |
916 | ||
917 | if (found_something) | |
918 | { | |
919 | if (! printed_objfile_start) | |
920 | { | |
921 | printf_filtered ("{ objfile %s ", objfile_name (objfile)); | |
922 | wrap_here (" "); | |
923 | printf_filtered ("((struct objfile *) %s)\n", | |
924 | host_address_to_string (objfile)); | |
925 | printed_objfile_start = 1; | |
926 | } | |
927 | printf_filtered (" { symtab %s\n", | |
928 | symtab_to_filename_for_display (symtab)); | |
929 | if (COMPUNIT_BLOCKVECTOR (cust) == NULL) | |
930 | printf_filtered (" NULL blockvector\n"); | |
931 | printf_filtered (" }\n"); | |
932 | } | |
933 | } | |
7d0c9981 | 934 | |
99d89cde TT |
935 | if (printed_objfile_start) |
936 | printf_filtered ("}\n"); | |
937 | } | |
7d0c9981 DE |
938 | } |
939 | ||
7d0c9981 DE |
940 | /* Expand all symbol tables whose name matches an optional regexp. */ |
941 | ||
942 | static void | |
e99c83e7 | 943 | maintenance_expand_symtabs (const char *args, int from_tty) |
7d0c9981 | 944 | { |
7d0c9981 DE |
945 | char *regexp = NULL; |
946 | ||
947 | /* We use buildargv here so that we handle spaces in the regexp | |
948 | in a way that allows adding more arguments later. */ | |
773a1edc | 949 | gdb_argv argv (args); |
7d0c9981 DE |
950 | |
951 | if (argv != NULL) | |
952 | { | |
953 | if (argv[0] != NULL) | |
954 | { | |
955 | regexp = argv[0]; | |
956 | if (argv[1] != NULL) | |
957 | error (_("Extra arguments after regexp.")); | |
958 | } | |
959 | } | |
960 | ||
961 | if (regexp) | |
962 | re_comp (regexp); | |
963 | ||
94c93c35 | 964 | for (struct program_space *pspace : program_spaces) |
2030c079 | 965 | for (objfile *objfile : pspace->objfiles ()) |
99d89cde TT |
966 | { |
967 | if (objfile->sf) | |
968 | { | |
969 | objfile->sf->qf->expand_symtabs_matching | |
970 | (objfile, | |
971 | [&] (const char *filename, bool basenames) | |
972 | { | |
973 | /* KISS: Only apply the regexp to the complete file name. */ | |
974 | return (!basenames | |
975 | && (regexp == NULL || re_exec (filename))); | |
976 | }, | |
c1a66c06 TV |
977 | NULL, |
978 | NULL, | |
99d89cde TT |
979 | NULL, |
980 | ALL_DOMAIN); | |
981 | } | |
982 | } | |
7d0c9981 | 983 | } |
c906108c | 984 | \f |
c5aa993b | 985 | |
c906108c SS |
986 | /* Return the nexting depth of a block within other blocks in its symtab. */ |
987 | ||
988 | static int | |
582942f4 | 989 | block_depth (const struct block *block) |
c906108c | 990 | { |
52f0bd74 | 991 | int i = 0; |
433759f7 | 992 | |
c5aa993b | 993 | while ((block = BLOCK_SUPERBLOCK (block)) != NULL) |
c906108c SS |
994 | { |
995 | i++; | |
996 | } | |
997 | return i; | |
998 | } | |
c906108c | 999 | \f |
c5aa993b | 1000 | |
f2403c39 AB |
1001 | /* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a |
1002 | single line table. */ | |
1003 | ||
1004 | static int | |
1005 | maintenance_print_one_line_table (struct symtab *symtab, void *data) | |
1006 | { | |
1007 | struct linetable *linetable; | |
1008 | struct objfile *objfile; | |
1009 | ||
1010 | objfile = symtab->compunit_symtab->objfile; | |
1011 | printf_filtered (_("objfile: %s ((struct objfile *) %s)\n"), | |
1012 | objfile_name (objfile), | |
1013 | host_address_to_string (objfile)); | |
1014 | printf_filtered (_("compunit_symtab: ((struct compunit_symtab *) %s)\n"), | |
1015 | host_address_to_string (symtab->compunit_symtab)); | |
1016 | printf_filtered (_("symtab: %s ((struct symtab *) %s)\n"), | |
1017 | symtab_to_fullname (symtab), | |
1018 | host_address_to_string (symtab)); | |
1019 | linetable = SYMTAB_LINETABLE (symtab); | |
1020 | printf_filtered (_("linetable: ((struct linetable *) %s):\n"), | |
1021 | host_address_to_string (linetable)); | |
1022 | ||
1023 | if (linetable == NULL) | |
1024 | printf_filtered (_("No line table.\n")); | |
1025 | else if (linetable->nitems <= 0) | |
1026 | printf_filtered (_("Line table has no lines.\n")); | |
1027 | else | |
1028 | { | |
f2403c39 AB |
1029 | /* Leave space for 6 digits of index and line number. After that the |
1030 | tables will just not format as well. */ | |
1773be9e TT |
1031 | struct ui_out *uiout = current_uiout; |
1032 | ui_out_emit_table table_emitter (uiout, 4, -1, "line-table"); | |
1033 | uiout->table_header (6, ui_left, "index", _("INDEX")); | |
1034 | uiout->table_header (6, ui_left, "line", _("LINE")); | |
1035 | uiout->table_header (18, ui_left, "address", _("ADDRESS")); | |
1036 | uiout->table_header (1, ui_left, "is-stmt", _("IS-STMT")); | |
1037 | uiout->table_body (); | |
1038 | ||
1039 | for (int i = 0; i < linetable->nitems; ++i) | |
f2403c39 AB |
1040 | { |
1041 | struct linetable_entry *item; | |
f2403c39 AB |
1042 | |
1043 | item = &linetable->item [i]; | |
1773be9e TT |
1044 | ui_out_emit_tuple tuple_emitter (uiout, nullptr); |
1045 | uiout->field_signed ("index", i); | |
94a72be7 | 1046 | if (item->line > 0) |
1773be9e | 1047 | uiout->field_signed ("line", item->line); |
94a72be7 | 1048 | else |
1773be9e | 1049 | uiout->field_string ("line", _("END")); |
08feed99 | 1050 | uiout->field_core_addr ("address", objfile->arch (), |
1773be9e TT |
1051 | item->pc); |
1052 | uiout->field_string ("is-stmt", item->is_stmt ? "Y" : ""); | |
1053 | uiout->text ("\n"); | |
f2403c39 AB |
1054 | } |
1055 | } | |
1056 | ||
1057 | return 0; | |
1058 | } | |
1059 | ||
1060 | /* Implement the 'maint info line-table' command. */ | |
1061 | ||
1062 | static void | |
e99c83e7 | 1063 | maintenance_info_line_tables (const char *regexp, int from_tty) |
f2403c39 | 1064 | { |
f2403c39 AB |
1065 | dont_repeat (); |
1066 | ||
1067 | if (regexp != NULL) | |
1068 | re_comp (regexp); | |
1069 | ||
94c93c35 | 1070 | for (struct program_space *pspace : program_spaces) |
2030c079 | 1071 | for (objfile *objfile : pspace->objfiles ()) |
99d89cde | 1072 | { |
b669c953 | 1073 | for (compunit_symtab *cust : objfile->compunits ()) |
99d89cde | 1074 | { |
5accd1a0 | 1075 | for (symtab *symtab : compunit_filetabs (cust)) |
99d89cde TT |
1076 | { |
1077 | QUIT; | |
1078 | ||
1079 | if (regexp == NULL | |
1080 | || re_exec (symtab_to_filename_for_display (symtab))) | |
1081 | maintenance_print_one_line_table (symtab, NULL); | |
1082 | } | |
1083 | } | |
1084 | } | |
f2403c39 AB |
1085 | } |
1086 | ||
1087 | \f | |
1088 | ||
c378eb4e | 1089 | /* Do early runtime initializations. */ |
b5ebcee6 | 1090 | |
6c265988 | 1091 | void _initialize_symmisc (); |
c906108c | 1092 | void |
6c265988 | 1093 | _initialize_symmisc () |
c906108c | 1094 | { |
80480540 YQ |
1095 | add_cmd ("symbols", class_maintenance, maintenance_print_symbols, _("\ |
1096 | Print dump of current symbol definitions.\n\ | |
48c5e7e2 TT |
1097 | Usage: mt print symbols [-pc ADDRESS] [--] [OUTFILE]\n\ |
1098 | mt print symbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\ | |
34c41c68 DE |
1099 | Entries in the full symbol table are dumped to file OUTFILE,\n\ |
1100 | or the terminal if OUTFILE is unspecified.\n\ | |
1101 | If ADDRESS is provided, dump only the file for that address.\n\ | |
1102 | If SOURCE is provided, dump only that file's symbols.\n\ | |
1103 | If OBJFILE is provided, dump only that file's minimal symbols."), | |
80480540 YQ |
1104 | &maintenanceprintlist); |
1105 | ||
1106 | add_cmd ("msymbols", class_maintenance, maintenance_print_msymbols, _("\ | |
1107 | Print dump of current minimal symbol definitions.\n\ | |
48c5e7e2 | 1108 | Usage: mt print msymbols [-objfile OBJFILE] [--] [OUTFILE]\n\ |
34c41c68 DE |
1109 | Entries in the minimal symbol table are dumped to file OUTFILE,\n\ |
1110 | or the terminal if OUTFILE is unspecified.\n\ | |
1111 | If OBJFILE is provided, dump only that file's minimal symbols."), | |
80480540 YQ |
1112 | &maintenanceprintlist); |
1113 | ||
1114 | add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles, | |
52e260a3 DE |
1115 | _("Print dump of current object file definitions.\n\ |
1116 | With an argument REGEXP, list the object files with matching names."), | |
80480540 YQ |
1117 | &maintenanceprintlist); |
1118 | ||
1119 | add_cmd ("symtabs", class_maintenance, maintenance_info_symtabs, _("\ | |
1120 | List the full symbol tables for all object files.\n\ | |
1121 | This does not include information about individual symbols, blocks, or\n\ | |
1122 | linetables --- just the symbol table structures themselves.\n\ | |
db68bbae | 1123 | With an argument REGEXP, list the symbol tables with matching names."), |
80480540 | 1124 | &maintenanceinfolist); |
7d0c9981 | 1125 | |
f2403c39 AB |
1126 | add_cmd ("line-table", class_maintenance, maintenance_info_line_tables, _("\ |
1127 | List the contents of all line tables, from all symbol tables.\n\ | |
1128 | With an argument REGEXP, list just the line tables for the symbol\n\ | |
1129 | tables with matching names."), | |
1130 | &maintenanceinfolist); | |
1131 | ||
7d0c9981 DE |
1132 | add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs, |
1133 | _("\ | |
1134 | Check consistency of currently expanded symtabs."), | |
1135 | &maintenancelist); | |
1136 | ||
1137 | add_cmd ("expand-symtabs", class_maintenance, maintenance_expand_symtabs, | |
1138 | _("Expand symbol tables.\n\ | |
1139 | With an argument REGEXP, only expand the symbol tables with matching names."), | |
1140 | &maintenancelist); | |
c906108c | 1141 | } |