Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Do various things to symbol tables (other than lookup), for GDB. |
af5f3db6 | 2 | |
b811d2c2 | 3 | Copyright (C) 1986-2020 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 TT |
41 | #include "psymtab.h" |
42 | ||
c906108c SS |
43 | /* Unfortunately for debugging, stderr is usually a macro. This is painful |
44 | when calling functions that take FILE *'s from the debugger. | |
45 | So we make a variable which has the same value and which is accessible when | |
46 | debugging GDB with itself. Because stdin et al need not be constants, | |
47 | we initialize them in the _initialize_symmisc function at the bottom | |
48 | of the file. */ | |
49 | FILE *std_in; | |
50 | FILE *std_out; | |
51 | FILE *std_err; | |
52 | ||
53 | /* Prototypes for local functions */ | |
54 | ||
582942f4 | 55 | static int block_depth (const struct block *); |
c906108c | 56 | |
bf469271 PA |
57 | static void print_symbol (struct gdbarch *gdbarch, struct symbol *symbol, |
58 | int depth, ui_file *outfile); | |
c906108c | 59 | \f |
c906108c | 60 | |
c906108c | 61 | void |
fba45db2 | 62 | print_symbol_bcache_statistics (void) |
c906108c | 63 | { |
6c95b8df | 64 | struct program_space *pspace; |
c906108c | 65 | |
6c95b8df | 66 | ALL_PSPACES (pspace) |
2030c079 | 67 | for (objfile *objfile : pspace->objfiles ()) |
99d89cde TT |
68 | { |
69 | QUIT; | |
70 | printf_filtered (_("Byte cache statistics for '%s':\n"), | |
71 | objfile_name (objfile)); | |
25629dfd TT |
72 | objfile->partial_symtabs->psymbol_cache.print_statistics |
73 | ("partial symbol cache"); | |
74 | objfile->per_bfd->macro_cache.print_statistics | |
75 | ("preprocessor macro cache"); | |
76 | objfile->per_bfd->filename_cache.print_statistics ("file name cache"); | |
99d89cde | 77 | } |
c906108c SS |
78 | } |
79 | ||
80 | void | |
fba45db2 | 81 | print_objfile_statistics (void) |
c906108c | 82 | { |
6c95b8df | 83 | struct program_space *pspace; |
c4f90d87 | 84 | int i, linetables, blockvectors; |
c906108c | 85 | |
6c95b8df | 86 | ALL_PSPACES (pspace) |
2030c079 | 87 | for (objfile *objfile : pspace->objfiles ()) |
99d89cde TT |
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); | |
97 | if (OBJSTAT (objfile, n_psyms) > 0) | |
98 | printf_filtered (_(" Number of \"partial\" symbols read: %d\n"), | |
99 | OBJSTAT (objfile, n_psyms)); | |
100 | if (OBJSTAT (objfile, n_syms) > 0) | |
101 | printf_filtered (_(" Number of \"full\" symbols read: %d\n"), | |
102 | OBJSTAT (objfile, n_syms)); | |
103 | if (OBJSTAT (objfile, n_types) > 0) | |
104 | printf_filtered (_(" Number of \"types\" defined: %d\n"), | |
105 | OBJSTAT (objfile, n_types)); | |
106 | if (objfile->sf) | |
107 | objfile->sf->qf->print_stats (objfile); | |
592553c4 | 108 | i = linetables = 0; |
b669c953 | 109 | for (compunit_symtab *cu : objfile->compunits ()) |
99d89cde | 110 | { |
d5da8b3c TT |
111 | for (symtab *s : compunit_filetabs (cu)) |
112 | { | |
113 | i++; | |
114 | if (SYMTAB_LINETABLE (s) != NULL) | |
115 | linetables++; | |
116 | } | |
99d89cde | 117 | } |
b669c953 TT |
118 | blockvectors = std::distance (objfile->compunits ().begin (), |
119 | objfile->compunits ().end ()); | |
99d89cde TT |
120 | printf_filtered (_(" Number of symbol tables: %d\n"), i); |
121 | printf_filtered (_(" Number of symbol tables with line tables: %d\n"), | |
122 | linetables); | |
123 | printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"), | |
124 | blockvectors); | |
125 | ||
126 | if (OBJSTAT (objfile, sz_strtab) > 0) | |
127 | printf_filtered (_(" Space used by string tables: %d\n"), | |
128 | OBJSTAT (objfile, sz_strtab)); | |
129 | printf_filtered (_(" Total memory used for objfile obstack: %s\n"), | |
130 | pulongest (obstack_memory_used (&objfile | |
131 | ->objfile_obstack))); | |
132 | printf_filtered (_(" Total memory used for BFD obstack: %s\n"), | |
133 | pulongest (obstack_memory_used (&objfile->per_bfd | |
134 | ->storage_obstack))); | |
d320c2b5 TT |
135 | printf_filtered |
136 | (_(" Total memory used for psymbol cache: %d\n"), | |
25629dfd | 137 | objfile->partial_symtabs->psymbol_cache.memory_used ()); |
99d89cde | 138 | printf_filtered (_(" Total memory used for macro cache: %d\n"), |
25629dfd | 139 | objfile->per_bfd->macro_cache.memory_used ()); |
99d89cde | 140 | printf_filtered (_(" Total memory used for file name cache: %d\n"), |
25629dfd | 141 | objfile->per_bfd->filename_cache.memory_used ()); |
99d89cde | 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 | { |
5af949e3 | 186 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
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 | { |
efd66ac6 | 199 | struct obj_section *section = MSYMBOL_OBJ_SECTION (objfile, msymbol); |
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); |
5af949e3 | 276 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
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 | ||
05cba821 JK |
286 | fprintf_filtered (outfile, "\nSymtab for file %s\n", |
287 | symtab_to_filename_for_display (symtab)); | |
ee6f8984 | 288 | if (SYMTAB_DIRNAME (symtab) != NULL) |
c906108c | 289 | fprintf_filtered (outfile, "Compilation directory is %s\n", |
ee6f8984 | 290 | SYMTAB_DIRNAME (symtab)); |
4262abfb JK |
291 | fprintf_filtered (outfile, "Read from object file %s (", |
292 | objfile_name (objfile)); | |
d4f3574e | 293 | gdb_print_host_address (objfile, outfile); |
c906108c | 294 | fprintf_filtered (outfile, ")\n"); |
3e43a32a MS |
295 | fprintf_filtered (outfile, "Language: %s\n", |
296 | language_str (symtab->language)); | |
c906108c SS |
297 | |
298 | /* First print the line table. */ | |
8435453b | 299 | l = SYMTAB_LINETABLE (symtab); |
c906108c SS |
300 | if (l) |
301 | { | |
302 | fprintf_filtered (outfile, "\nLine table:\n\n"); | |
303 | len = l->nitems; | |
304 | for (i = 0; i < len; i++) | |
305 | { | |
306 | fprintf_filtered (outfile, " line %d at ", l->item[i].line); | |
5af949e3 | 307 | fputs_filtered (paddress (gdbarch, l->item[i].pc), outfile); |
c906108c SS |
308 | fprintf_filtered (outfile, "\n"); |
309 | } | |
310 | } | |
43f3e411 | 311 | /* Now print the block info, but only for compunit symtabs since we will |
c378eb4e | 312 | print lots of duplicate info otherwise. */ |
43f3e411 | 313 | if (symtab == COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab))) |
c906108c SS |
314 | { |
315 | fprintf_filtered (outfile, "\nBlockvector:\n\n"); | |
439247b6 | 316 | bv = SYMTAB_BLOCKVECTOR (symtab); |
c906108c SS |
317 | len = BLOCKVECTOR_NBLOCKS (bv); |
318 | for (i = 0; i < len; i++) | |
319 | { | |
320 | b = BLOCKVECTOR_BLOCK (bv, i); | |
321 | depth = block_depth (b) * 2; | |
322 | print_spaces (depth, outfile); | |
323 | fprintf_filtered (outfile, "block #%03d, object at ", i); | |
d4f3574e | 324 | gdb_print_host_address (b, outfile); |
c906108c SS |
325 | if (BLOCK_SUPERBLOCK (b)) |
326 | { | |
327 | fprintf_filtered (outfile, " under "); | |
d4f3574e | 328 | gdb_print_host_address (BLOCK_SUPERBLOCK (b), outfile); |
c906108c | 329 | } |
261397f8 DJ |
330 | /* drow/2002-07-10: We could save the total symbols count |
331 | even if we're using a hashtable, but nothing else but this message | |
332 | wants it. */ | |
de4f826b | 333 | fprintf_filtered (outfile, ", %d syms/buckets in ", |
b026f593 | 334 | mdict_size (BLOCK_MULTIDICT (b))); |
5af949e3 | 335 | fputs_filtered (paddress (gdbarch, BLOCK_START (b)), outfile); |
c906108c | 336 | fprintf_filtered (outfile, ".."); |
5af949e3 | 337 | fputs_filtered (paddress (gdbarch, BLOCK_END (b)), outfile); |
c906108c SS |
338 | if (BLOCK_FUNCTION (b)) |
339 | { | |
3567439c | 340 | fprintf_filtered (outfile, ", function %s", |
987012b8 CB |
341 | BLOCK_FUNCTION (b)->linkage_name ()); |
342 | if (BLOCK_FUNCTION (b)->demangled_name () != NULL) | |
c906108c SS |
343 | { |
344 | fprintf_filtered (outfile, ", %s", | |
987012b8 | 345 | BLOCK_FUNCTION (b)->demangled_name ()); |
c906108c SS |
346 | } |
347 | } | |
c906108c | 348 | fprintf_filtered (outfile, "\n"); |
261397f8 | 349 | /* Now print each symbol in this block (in no particular order, if |
8157b174 TT |
350 | we're using a hashtable). Note that we only want this |
351 | block, not any blocks from included symtabs. */ | |
b026f593 | 352 | ALL_DICT_SYMBOLS (BLOCK_MULTIDICT (b), miter, sym) |
c906108c | 353 | { |
a70b8144 | 354 | try |
bf469271 PA |
355 | { |
356 | print_symbol (gdbarch, sym, depth + 1, outfile); | |
357 | } | |
230d2906 | 358 | catch (const gdb_exception_error &ex) |
bf469271 PA |
359 | { |
360 | exception_fprintf (gdb_stderr, ex, | |
361 | "Error printing symbol:\n"); | |
362 | } | |
c906108c SS |
363 | } |
364 | } | |
365 | fprintf_filtered (outfile, "\n"); | |
366 | } | |
367 | else | |
368 | { | |
6c739336 DE |
369 | const char *compunit_filename |
370 | = symtab_to_filename_for_display (COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab))); | |
371 | ||
372 | fprintf_filtered (outfile, | |
373 | "\nBlockvector same as owning compunit: %s\n\n", | |
374 | compunit_filename); | |
c906108c SS |
375 | } |
376 | } | |
377 | ||
44b164c5 | 378 | static void |
d04c1a59 | 379 | dump_symtab (struct symtab *symtab, struct ui_file *outfile) |
44b164c5 | 380 | { |
44b164c5 JB |
381 | /* Set the current language to the language of the symtab we're dumping |
382 | because certain routines used during dump_symtab() use the current | |
969107c5 EZ |
383 | language to print an image of the symbol. We'll restore it later. |
384 | But use only real languages, not placeholders. */ | |
385 | if (symtab->language != language_unknown | |
386 | && symtab->language != language_auto) | |
387 | { | |
9bb9b2f9 TT |
388 | scoped_restore_current_language save_lang; |
389 | set_language (symtab->language); | |
d04c1a59 | 390 | dump_symtab_1 (symtab, outfile); |
969107c5 EZ |
391 | } |
392 | else | |
d04c1a59 | 393 | dump_symtab_1 (symtab, outfile); |
44b164c5 JB |
394 | } |
395 | ||
80480540 | 396 | static void |
e99c83e7 | 397 | maintenance_print_symbols (const char *args, int from_tty) |
c906108c | 398 | { |
34c41c68 | 399 | struct ui_file *outfile = gdb_stdout; |
34c41c68 DE |
400 | char *address_arg = NULL, *source_arg = NULL, *objfile_arg = NULL; |
401 | int i, outfile_idx; | |
c906108c SS |
402 | |
403 | dont_repeat (); | |
404 | ||
773a1edc | 405 | gdb_argv argv (args); |
c906108c | 406 | |
99e8a4f9 | 407 | for (i = 0; argv != NULL && argv[i] != NULL; ++i) |
c906108c | 408 | { |
34c41c68 DE |
409 | if (strcmp (argv[i], "-pc") == 0) |
410 | { | |
411 | if (argv[i + 1] == NULL) | |
412 | error (_("Missing pc value")); | |
413 | address_arg = argv[++i]; | |
414 | } | |
415 | else if (strcmp (argv[i], "-source") == 0) | |
416 | { | |
417 | if (argv[i + 1] == NULL) | |
418 | error (_("Missing source file")); | |
419 | source_arg = argv[++i]; | |
420 | } | |
421 | else if (strcmp (argv[i], "-objfile") == 0) | |
422 | { | |
423 | if (argv[i + 1] == NULL) | |
424 | error (_("Missing objfile name")); | |
425 | objfile_arg = argv[++i]; | |
426 | } | |
427 | else if (strcmp (argv[i], "--") == 0) | |
428 | { | |
429 | /* End of options. */ | |
430 | ++i; | |
431 | break; | |
432 | } | |
433 | else if (argv[i][0] == '-') | |
c906108c | 434 | { |
34c41c68 DE |
435 | /* Future proofing: Don't allow OUTFILE to begin with "-". */ |
436 | error (_("Unknown option: %s"), argv[i]); | |
c906108c | 437 | } |
34c41c68 DE |
438 | else |
439 | break; | |
c906108c | 440 | } |
34c41c68 | 441 | outfile_idx = i; |
c906108c | 442 | |
34c41c68 DE |
443 | if (address_arg != NULL && source_arg != NULL) |
444 | error (_("Must specify at most one of -pc and -source")); | |
c5aa993b | 445 | |
d7e74731 PA |
446 | stdio_file arg_outfile; |
447 | ||
99e8a4f9 | 448 | if (argv != NULL && argv[outfile_idx] != NULL) |
34c41c68 | 449 | { |
34c41c68 DE |
450 | if (argv[outfile_idx + 1] != NULL) |
451 | error (_("Junk at end of command")); | |
ee0c3293 TT |
452 | gdb::unique_xmalloc_ptr<char> outfile_name |
453 | (tilde_expand (argv[outfile_idx])); | |
454 | if (!arg_outfile.open (outfile_name.get (), FOPEN_WT)) | |
455 | perror_with_name (outfile_name.get ()); | |
d7e74731 | 456 | outfile = &arg_outfile; |
34c41c68 | 457 | } |
c906108c | 458 | |
34c41c68 | 459 | if (address_arg != NULL) |
27618ce4 | 460 | { |
34c41c68 DE |
461 | CORE_ADDR pc = parse_and_eval_address (address_arg); |
462 | struct symtab *s = find_pc_line_symtab (pc); | |
463 | ||
464 | if (s == NULL) | |
465 | error (_("No symtab for address: %s"), address_arg); | |
466 | dump_symtab (s, outfile); | |
27618ce4 | 467 | } |
34c41c68 DE |
468 | else |
469 | { | |
34c41c68 DE |
470 | int found = 0; |
471 | ||
2030c079 | 472 | for (objfile *objfile : current_program_space->objfiles ()) |
34c41c68 DE |
473 | { |
474 | int print_for_objfile = 1; | |
475 | ||
476 | if (objfile_arg != NULL) | |
477 | print_for_objfile | |
478 | = compare_filenames_for_search (objfile_name (objfile), | |
479 | objfile_arg); | |
480 | if (!print_for_objfile) | |
481 | continue; | |
482 | ||
b669c953 | 483 | for (compunit_symtab *cu : objfile->compunits ()) |
34c41c68 | 484 | { |
d5da8b3c | 485 | for (symtab *s : compunit_filetabs (cu)) |
34c41c68 | 486 | { |
d5da8b3c TT |
487 | int print_for_source = 0; |
488 | ||
489 | QUIT; | |
490 | if (source_arg != NULL) | |
491 | { | |
492 | print_for_source | |
493 | = compare_filenames_for_search | |
494 | (symtab_to_filename_for_display (s), source_arg); | |
495 | found = 1; | |
496 | } | |
497 | if (source_arg == NULL | |
498 | || print_for_source) | |
499 | dump_symtab (s, outfile); | |
34c41c68 | 500 | } |
34c41c68 DE |
501 | } |
502 | } | |
503 | ||
504 | if (source_arg != NULL && !found) | |
505 | error (_("No symtab for source file: %s"), source_arg); | |
506 | } | |
c906108c SS |
507 | } |
508 | ||
bf469271 | 509 | /* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */ |
c906108c | 510 | |
bf469271 PA |
511 | static void |
512 | print_symbol (struct gdbarch *gdbarch, struct symbol *symbol, | |
513 | int depth, ui_file *outfile) | |
c906108c | 514 | { |
1994afbf DE |
515 | struct obj_section *section; |
516 | ||
517 | if (SYMBOL_OBJFILE_OWNED (symbol)) | |
518 | section = SYMBOL_OBJ_SECTION (symbol_objfile (symbol), symbol); | |
519 | else | |
520 | section = NULL; | |
c906108c SS |
521 | |
522 | print_spaces (depth, outfile); | |
176620f1 | 523 | if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN) |
c906108c | 524 | { |
987012b8 | 525 | fprintf_filtered (outfile, "label %s at ", symbol->print_name ()); |
5af949e3 UW |
526 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)), |
527 | outfile); | |
714835d5 | 528 | if (section) |
c906108c | 529 | fprintf_filtered (outfile, " section %s\n", |
fd361982 | 530 | bfd_section_name (section->the_bfd_section)); |
c906108c SS |
531 | else |
532 | fprintf_filtered (outfile, "\n"); | |
bf469271 | 533 | return; |
c906108c | 534 | } |
bf469271 | 535 | |
176620f1 | 536 | if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN) |
c906108c | 537 | { |
e86ca25f | 538 | if (TYPE_NAME (SYMBOL_TYPE (symbol))) |
c906108c | 539 | { |
79d43c61 TT |
540 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth, |
541 | &type_print_raw_options); | |
c906108c SS |
542 | } |
543 | else | |
544 | { | |
545 | fprintf_filtered (outfile, "%s %s = ", | |
c5aa993b JM |
546 | (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM |
547 | ? "enum" | |
548 | : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT | |
549 | ? "struct" : "union")), | |
987012b8 | 550 | symbol->linkage_name ()); |
79d43c61 TT |
551 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth, |
552 | &type_print_raw_options); | |
c906108c SS |
553 | } |
554 | fprintf_filtered (outfile, ";\n"); | |
555 | } | |
556 | else | |
557 | { | |
558 | if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF) | |
559 | fprintf_filtered (outfile, "typedef "); | |
560 | if (SYMBOL_TYPE (symbol)) | |
561 | { | |
562 | /* Print details of types, except for enums where it's clutter. */ | |
987012b8 | 563 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), symbol->print_name (), |
c906108c SS |
564 | outfile, |
565 | TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM, | |
79d43c61 TT |
566 | depth, |
567 | &type_print_raw_options); | |
c906108c SS |
568 | fprintf_filtered (outfile, "; "); |
569 | } | |
570 | else | |
987012b8 | 571 | fprintf_filtered (outfile, "%s ", symbol->print_name ()); |
c906108c SS |
572 | |
573 | switch (SYMBOL_CLASS (symbol)) | |
574 | { | |
575 | case LOC_CONST: | |
12df843f JK |
576 | fprintf_filtered (outfile, "const %s (%s)", |
577 | plongest (SYMBOL_VALUE (symbol)), | |
578 | hex_string (SYMBOL_VALUE (symbol))); | |
c906108c SS |
579 | break; |
580 | ||
581 | case LOC_CONST_BYTES: | |
582 | { | |
583 | unsigned i; | |
584 | struct type *type = check_typedef (SYMBOL_TYPE (symbol)); | |
433759f7 | 585 | |
cc1defb1 KS |
586 | fprintf_filtered (outfile, "const %s hex bytes:", |
587 | pulongest (TYPE_LENGTH (type))); | |
c906108c SS |
588 | for (i = 0; i < TYPE_LENGTH (type); i++) |
589 | fprintf_filtered (outfile, " %02x", | |
c5aa993b | 590 | (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]); |
c906108c SS |
591 | } |
592 | break; | |
593 | ||
594 | case LOC_STATIC: | |
595 | fprintf_filtered (outfile, "static at "); | |
5af949e3 UW |
596 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)), |
597 | outfile); | |
714835d5 | 598 | if (section) |
c906108c | 599 | fprintf_filtered (outfile, " section %s", |
fd361982 | 600 | bfd_section_name (section->the_bfd_section)); |
c906108c SS |
601 | break; |
602 | ||
c906108c | 603 | case LOC_REGISTER: |
2a2d4dc3 | 604 | if (SYMBOL_IS_ARGUMENT (symbol)) |
12df843f JK |
605 | fprintf_filtered (outfile, "parameter register %s", |
606 | plongest (SYMBOL_VALUE (symbol))); | |
2a2d4dc3 | 607 | else |
12df843f JK |
608 | fprintf_filtered (outfile, "register %s", |
609 | plongest (SYMBOL_VALUE (symbol))); | |
c906108c SS |
610 | break; |
611 | ||
612 | case LOC_ARG: | |
12df843f JK |
613 | fprintf_filtered (outfile, "arg at offset %s", |
614 | hex_string (SYMBOL_VALUE (symbol))); | |
c906108c SS |
615 | break; |
616 | ||
c906108c | 617 | case LOC_REF_ARG: |
12df843f JK |
618 | fprintf_filtered (outfile, "reference arg at %s", |
619 | hex_string (SYMBOL_VALUE (symbol))); | |
c906108c SS |
620 | break; |
621 | ||
c906108c | 622 | case LOC_REGPARM_ADDR: |
12df843f JK |
623 | fprintf_filtered (outfile, "address parameter register %s", |
624 | plongest (SYMBOL_VALUE (symbol))); | |
c906108c SS |
625 | break; |
626 | ||
627 | case LOC_LOCAL: | |
12df843f JK |
628 | fprintf_filtered (outfile, "local at offset %s", |
629 | hex_string (SYMBOL_VALUE (symbol))); | |
c906108c SS |
630 | break; |
631 | ||
c906108c SS |
632 | case LOC_TYPEDEF: |
633 | break; | |
634 | ||
635 | case LOC_LABEL: | |
636 | fprintf_filtered (outfile, "label at "); | |
5af949e3 UW |
637 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)), |
638 | outfile); | |
714835d5 | 639 | if (section) |
c906108c | 640 | fprintf_filtered (outfile, " section %s", |
fd361982 | 641 | bfd_section_name (section->the_bfd_section)); |
c906108c SS |
642 | break; |
643 | ||
644 | case LOC_BLOCK: | |
645 | fprintf_filtered (outfile, "block object "); | |
d4f3574e | 646 | gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile); |
c906108c | 647 | fprintf_filtered (outfile, ", "); |
5af949e3 UW |
648 | fputs_filtered (paddress (gdbarch, |
649 | BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))), | |
ed49a04f | 650 | outfile); |
c906108c | 651 | fprintf_filtered (outfile, ".."); |
5af949e3 UW |
652 | fputs_filtered (paddress (gdbarch, |
653 | BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))), | |
ed49a04f | 654 | outfile); |
714835d5 | 655 | if (section) |
c906108c | 656 | fprintf_filtered (outfile, " section %s", |
fd361982 | 657 | bfd_section_name (section->the_bfd_section)); |
c906108c SS |
658 | break; |
659 | ||
4c2df51b | 660 | case LOC_COMPUTED: |
4c2df51b DJ |
661 | fprintf_filtered (outfile, "computed at runtime"); |
662 | break; | |
663 | ||
c906108c SS |
664 | case LOC_UNRESOLVED: |
665 | fprintf_filtered (outfile, "unresolved"); | |
666 | break; | |
667 | ||
668 | case LOC_OPTIMIZED_OUT: | |
669 | fprintf_filtered (outfile, "optimized out"); | |
670 | break; | |
671 | ||
c5aa993b | 672 | default: |
c906108c SS |
673 | fprintf_filtered (outfile, "botched symbol class %x", |
674 | SYMBOL_CLASS (symbol)); | |
675 | break; | |
676 | } | |
677 | } | |
678 | fprintf_filtered (outfile, "\n"); | |
c906108c SS |
679 | } |
680 | ||
80480540 | 681 | static void |
e99c83e7 | 682 | maintenance_print_msymbols (const char *args, int from_tty) |
c906108c | 683 | { |
34c41c68 | 684 | struct ui_file *outfile = gdb_stdout; |
34c41c68 | 685 | char *objfile_arg = NULL; |
34c41c68 | 686 | int i, outfile_idx; |
07318b29 | 687 | |
c906108c SS |
688 | dont_repeat (); |
689 | ||
773a1edc | 690 | gdb_argv argv (args); |
c906108c | 691 | |
99e8a4f9 | 692 | for (i = 0; argv != NULL && argv[i] != NULL; ++i) |
c906108c | 693 | { |
34c41c68 | 694 | if (strcmp (argv[i], "-objfile") == 0) |
c906108c | 695 | { |
34c41c68 DE |
696 | if (argv[i + 1] == NULL) |
697 | error (_("Missing objfile name")); | |
698 | objfile_arg = argv[++i]; | |
699 | } | |
700 | else if (strcmp (argv[i], "--") == 0) | |
701 | { | |
702 | /* End of options. */ | |
703 | ++i; | |
704 | break; | |
c906108c | 705 | } |
34c41c68 DE |
706 | else if (argv[i][0] == '-') |
707 | { | |
708 | /* Future proofing: Don't allow OUTFILE to begin with "-". */ | |
709 | error (_("Unknown option: %s"), argv[i]); | |
710 | } | |
711 | else | |
712 | break; | |
c906108c | 713 | } |
34c41c68 | 714 | outfile_idx = i; |
c906108c | 715 | |
d7e74731 PA |
716 | stdio_file arg_outfile; |
717 | ||
99e8a4f9 | 718 | if (argv != NULL && argv[outfile_idx] != NULL) |
34c41c68 | 719 | { |
34c41c68 DE |
720 | if (argv[outfile_idx + 1] != NULL) |
721 | error (_("Junk at end of command")); | |
ee0c3293 TT |
722 | gdb::unique_xmalloc_ptr<char> outfile_name |
723 | (tilde_expand (argv[outfile_idx])); | |
724 | if (!arg_outfile.open (outfile_name.get (), FOPEN_WT)) | |
725 | perror_with_name (outfile_name.get ()); | |
d7e74731 | 726 | outfile = &arg_outfile; |
34c41c68 | 727 | } |
c5aa993b | 728 | |
2030c079 | 729 | for (objfile *objfile : current_program_space->objfiles ()) |
aed57c53 TT |
730 | { |
731 | QUIT; | |
732 | if (objfile_arg == NULL | |
733 | || compare_filenames_for_search (objfile_name (objfile), objfile_arg)) | |
734 | dump_msymbols (objfile, outfile); | |
735 | } | |
c906108c SS |
736 | } |
737 | ||
80480540 | 738 | static void |
e99c83e7 | 739 | maintenance_print_objfiles (const char *regexp, int from_tty) |
c906108c | 740 | { |
6c95b8df | 741 | struct program_space *pspace; |
c906108c SS |
742 | |
743 | dont_repeat (); | |
744 | ||
52e260a3 DE |
745 | if (regexp) |
746 | re_comp (regexp); | |
747 | ||
6c95b8df | 748 | ALL_PSPACES (pspace) |
2030c079 | 749 | for (objfile *objfile : pspace->objfiles ()) |
27618ce4 TT |
750 | { |
751 | QUIT; | |
52e260a3 | 752 | if (! regexp |
4262abfb | 753 | || re_exec (objfile_name (objfile))) |
52e260a3 | 754 | dump_objfile (objfile); |
27618ce4 | 755 | } |
c906108c SS |
756 | } |
757 | ||
5e7b2f39 | 758 | /* List all the symbol tables whose names match REGEXP (optional). */ |
b5ebcee6 | 759 | |
80480540 | 760 | static void |
e99c83e7 | 761 | maintenance_info_symtabs (const char *regexp, int from_tty) |
44ea7b70 | 762 | { |
6c95b8df | 763 | struct program_space *pspace; |
44ea7b70 | 764 | |
db68bbae DE |
765 | dont_repeat (); |
766 | ||
44ea7b70 JB |
767 | if (regexp) |
768 | re_comp (regexp); | |
769 | ||
6c95b8df | 770 | ALL_PSPACES (pspace) |
2030c079 | 771 | for (objfile *objfile : pspace->objfiles ()) |
99d89cde | 772 | { |
99d89cde TT |
773 | /* We don't want to print anything for this objfile until we |
774 | actually find a symtab whose name matches. */ | |
775 | int printed_objfile_start = 0; | |
43f3e411 | 776 | |
b669c953 | 777 | for (compunit_symtab *cust : objfile->compunits ()) |
99d89cde TT |
778 | { |
779 | int printed_compunit_symtab_start = 0; | |
780 | ||
5accd1a0 | 781 | for (symtab *symtab : compunit_filetabs (cust)) |
99d89cde TT |
782 | { |
783 | QUIT; | |
784 | ||
785 | if (! regexp | |
786 | || re_exec (symtab_to_filename_for_display (symtab))) | |
787 | { | |
788 | if (! printed_objfile_start) | |
789 | { | |
790 | printf_filtered ("{ objfile %s ", objfile_name (objfile)); | |
791 | wrap_here (" "); | |
792 | printf_filtered ("((struct objfile *) %s)\n", | |
793 | host_address_to_string (objfile)); | |
794 | printed_objfile_start = 1; | |
795 | } | |
796 | if (! printed_compunit_symtab_start) | |
797 | { | |
798 | printf_filtered (" { ((struct compunit_symtab *) %s)\n", | |
799 | host_address_to_string (cust)); | |
800 | printf_filtered (" debugformat %s\n", | |
801 | COMPUNIT_DEBUGFORMAT (cust)); | |
802 | printf_filtered (" producer %s\n", | |
803 | COMPUNIT_PRODUCER (cust) != NULL | |
804 | ? COMPUNIT_PRODUCER (cust) | |
805 | : "(null)"); | |
806 | printf_filtered (" dirname %s\n", | |
807 | COMPUNIT_DIRNAME (cust) != NULL | |
808 | ? COMPUNIT_DIRNAME (cust) | |
809 | : "(null)"); | |
810 | printf_filtered (" blockvector" | |
811 | " ((struct blockvector *) %s)\n", | |
812 | host_address_to_string | |
43f3e411 | 813 | (COMPUNIT_BLOCKVECTOR (cust))); |
99d89cde TT |
814 | printed_compunit_symtab_start = 1; |
815 | } | |
816 | ||
817 | printf_filtered ("\t{ symtab %s ", | |
818 | symtab_to_filename_for_display (symtab)); | |
819 | wrap_here (" "); | |
820 | printf_filtered ("((struct symtab *) %s)\n", | |
821 | host_address_to_string (symtab)); | |
822 | printf_filtered ("\t fullname %s\n", | |
823 | symtab->fullname != NULL | |
824 | ? symtab->fullname | |
825 | : "(null)"); | |
826 | printf_filtered ("\t " | |
827 | "linetable ((struct linetable *) %s)\n", | |
828 | host_address_to_string (symtab->linetable)); | |
829 | printf_filtered ("\t}\n"); | |
830 | } | |
831 | } | |
832 | ||
833 | if (printed_compunit_symtab_start) | |
834 | printf_filtered (" }\n"); | |
835 | } | |
44ea7b70 | 836 | |
99d89cde TT |
837 | if (printed_objfile_start) |
838 | printf_filtered ("}\n"); | |
839 | } | |
44ea7b70 | 840 | } |
7d0c9981 DE |
841 | |
842 | /* Check consistency of symtabs. | |
843 | An example of what this checks for is NULL blockvectors. | |
844 | They can happen if there's a bug during debug info reading. | |
845 | GDB assumes they are always non-NULL. | |
846 | ||
847 | Note: This does not check for psymtab vs symtab consistency. | |
848 | Use "maint check-psymtabs" for that. */ | |
849 | ||
850 | static void | |
e99c83e7 | 851 | maintenance_check_symtabs (const char *ignore, int from_tty) |
7d0c9981 DE |
852 | { |
853 | struct program_space *pspace; | |
7d0c9981 DE |
854 | |
855 | ALL_PSPACES (pspace) | |
2030c079 | 856 | for (objfile *objfile : pspace->objfiles ()) |
99d89cde | 857 | { |
99d89cde TT |
858 | /* We don't want to print anything for this objfile until we |
859 | actually find something worth printing. */ | |
860 | int printed_objfile_start = 0; | |
7d0c9981 | 861 | |
b669c953 | 862 | for (compunit_symtab *cust : objfile->compunits ()) |
99d89cde TT |
863 | { |
864 | int found_something = 0; | |
865 | struct symtab *symtab = compunit_primary_filetab (cust); | |
866 | ||
867 | QUIT; | |
868 | ||
869 | if (COMPUNIT_BLOCKVECTOR (cust) == NULL) | |
870 | found_something = 1; | |
871 | /* Add more checks here. */ | |
872 | ||
873 | if (found_something) | |
874 | { | |
875 | if (! printed_objfile_start) | |
876 | { | |
877 | printf_filtered ("{ objfile %s ", objfile_name (objfile)); | |
878 | wrap_here (" "); | |
879 | printf_filtered ("((struct objfile *) %s)\n", | |
880 | host_address_to_string (objfile)); | |
881 | printed_objfile_start = 1; | |
882 | } | |
883 | printf_filtered (" { symtab %s\n", | |
884 | symtab_to_filename_for_display (symtab)); | |
885 | if (COMPUNIT_BLOCKVECTOR (cust) == NULL) | |
886 | printf_filtered (" NULL blockvector\n"); | |
887 | printf_filtered (" }\n"); | |
888 | } | |
889 | } | |
7d0c9981 | 890 | |
99d89cde TT |
891 | if (printed_objfile_start) |
892 | printf_filtered ("}\n"); | |
893 | } | |
7d0c9981 DE |
894 | } |
895 | ||
7d0c9981 DE |
896 | /* Expand all symbol tables whose name matches an optional regexp. */ |
897 | ||
898 | static void | |
e99c83e7 | 899 | maintenance_expand_symtabs (const char *args, int from_tty) |
7d0c9981 DE |
900 | { |
901 | struct program_space *pspace; | |
7d0c9981 DE |
902 | char *regexp = NULL; |
903 | ||
904 | /* We use buildargv here so that we handle spaces in the regexp | |
905 | in a way that allows adding more arguments later. */ | |
773a1edc | 906 | gdb_argv argv (args); |
7d0c9981 DE |
907 | |
908 | if (argv != NULL) | |
909 | { | |
910 | if (argv[0] != NULL) | |
911 | { | |
912 | regexp = argv[0]; | |
913 | if (argv[1] != NULL) | |
914 | error (_("Extra arguments after regexp.")); | |
915 | } | |
916 | } | |
917 | ||
918 | if (regexp) | |
919 | re_comp (regexp); | |
920 | ||
921 | ALL_PSPACES (pspace) | |
2030c079 | 922 | for (objfile *objfile : pspace->objfiles ()) |
99d89cde TT |
923 | { |
924 | if (objfile->sf) | |
925 | { | |
926 | objfile->sf->qf->expand_symtabs_matching | |
927 | (objfile, | |
928 | [&] (const char *filename, bool basenames) | |
929 | { | |
930 | /* KISS: Only apply the regexp to the complete file name. */ | |
931 | return (!basenames | |
932 | && (regexp == NULL || re_exec (filename))); | |
933 | }, | |
934 | lookup_name_info::match_any (), | |
935 | [] (const char *symname) | |
936 | { | |
937 | /* Since we're not searching on symbols, just return true. */ | |
938 | return true; | |
939 | }, | |
940 | NULL, | |
941 | ALL_DOMAIN); | |
942 | } | |
943 | } | |
7d0c9981 | 944 | } |
c906108c | 945 | \f |
c5aa993b | 946 | |
c906108c SS |
947 | /* Return the nexting depth of a block within other blocks in its symtab. */ |
948 | ||
949 | static int | |
582942f4 | 950 | block_depth (const struct block *block) |
c906108c | 951 | { |
52f0bd74 | 952 | int i = 0; |
433759f7 | 953 | |
c5aa993b | 954 | while ((block = BLOCK_SUPERBLOCK (block)) != NULL) |
c906108c SS |
955 | { |
956 | i++; | |
957 | } | |
958 | return i; | |
959 | } | |
c906108c | 960 | \f |
c5aa993b | 961 | |
f2403c39 AB |
962 | /* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a |
963 | single line table. */ | |
964 | ||
965 | static int | |
966 | maintenance_print_one_line_table (struct symtab *symtab, void *data) | |
967 | { | |
968 | struct linetable *linetable; | |
969 | struct objfile *objfile; | |
970 | ||
971 | objfile = symtab->compunit_symtab->objfile; | |
972 | printf_filtered (_("objfile: %s ((struct objfile *) %s)\n"), | |
973 | objfile_name (objfile), | |
974 | host_address_to_string (objfile)); | |
975 | printf_filtered (_("compunit_symtab: ((struct compunit_symtab *) %s)\n"), | |
976 | host_address_to_string (symtab->compunit_symtab)); | |
977 | printf_filtered (_("symtab: %s ((struct symtab *) %s)\n"), | |
978 | symtab_to_fullname (symtab), | |
979 | host_address_to_string (symtab)); | |
980 | linetable = SYMTAB_LINETABLE (symtab); | |
981 | printf_filtered (_("linetable: ((struct linetable *) %s):\n"), | |
982 | host_address_to_string (linetable)); | |
983 | ||
984 | if (linetable == NULL) | |
985 | printf_filtered (_("No line table.\n")); | |
986 | else if (linetable->nitems <= 0) | |
987 | printf_filtered (_("Line table has no lines.\n")); | |
988 | else | |
989 | { | |
990 | int i; | |
991 | ||
992 | /* Leave space for 6 digits of index and line number. After that the | |
993 | tables will just not format as well. */ | |
994 | printf_filtered (_("%-6s %6s %s\n"), | |
995 | _("INDEX"), _("LINE"), _("ADDRESS")); | |
996 | ||
997 | for (i = 0; i < linetable->nitems; ++i) | |
998 | { | |
999 | struct linetable_entry *item; | |
f2403c39 AB |
1000 | |
1001 | item = &linetable->item [i]; | |
1002 | printf_filtered (_("%-6d %6d %s\n"), i, item->line, | |
1003 | core_addr_to_string (item->pc)); | |
1004 | } | |
1005 | } | |
1006 | ||
1007 | return 0; | |
1008 | } | |
1009 | ||
1010 | /* Implement the 'maint info line-table' command. */ | |
1011 | ||
1012 | static void | |
e99c83e7 | 1013 | maintenance_info_line_tables (const char *regexp, int from_tty) |
f2403c39 AB |
1014 | { |
1015 | struct program_space *pspace; | |
f2403c39 AB |
1016 | |
1017 | dont_repeat (); | |
1018 | ||
1019 | if (regexp != NULL) | |
1020 | re_comp (regexp); | |
1021 | ||
1022 | ALL_PSPACES (pspace) | |
2030c079 | 1023 | for (objfile *objfile : pspace->objfiles ()) |
99d89cde | 1024 | { |
b669c953 | 1025 | for (compunit_symtab *cust : objfile->compunits ()) |
99d89cde | 1026 | { |
5accd1a0 | 1027 | for (symtab *symtab : compunit_filetabs (cust)) |
99d89cde TT |
1028 | { |
1029 | QUIT; | |
1030 | ||
1031 | if (regexp == NULL | |
1032 | || re_exec (symtab_to_filename_for_display (symtab))) | |
1033 | maintenance_print_one_line_table (symtab, NULL); | |
1034 | } | |
1035 | } | |
1036 | } | |
f2403c39 AB |
1037 | } |
1038 | ||
1039 | \f | |
1040 | ||
c378eb4e | 1041 | /* Do early runtime initializations. */ |
b5ebcee6 | 1042 | |
6c265988 | 1043 | void _initialize_symmisc (); |
c906108c | 1044 | void |
6c265988 | 1045 | _initialize_symmisc () |
c906108c | 1046 | { |
c5aa993b | 1047 | std_in = stdin; |
c906108c SS |
1048 | std_out = stdout; |
1049 | std_err = stderr; | |
80480540 YQ |
1050 | |
1051 | add_cmd ("symbols", class_maintenance, maintenance_print_symbols, _("\ | |
1052 | Print dump of current symbol definitions.\n\ | |
48c5e7e2 TT |
1053 | Usage: mt print symbols [-pc ADDRESS] [--] [OUTFILE]\n\ |
1054 | mt print symbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\ | |
34c41c68 DE |
1055 | Entries in the full symbol table are dumped to file OUTFILE,\n\ |
1056 | or the terminal if OUTFILE is unspecified.\n\ | |
1057 | If ADDRESS is provided, dump only the file for that address.\n\ | |
1058 | If SOURCE is provided, dump only that file's symbols.\n\ | |
1059 | If OBJFILE is provided, dump only that file's minimal symbols."), | |
80480540 YQ |
1060 | &maintenanceprintlist); |
1061 | ||
1062 | add_cmd ("msymbols", class_maintenance, maintenance_print_msymbols, _("\ | |
1063 | Print dump of current minimal symbol definitions.\n\ | |
48c5e7e2 | 1064 | Usage: mt print msymbols [-objfile OBJFILE] [--] [OUTFILE]\n\ |
34c41c68 DE |
1065 | Entries in the minimal symbol table are dumped to file OUTFILE,\n\ |
1066 | or the terminal if OUTFILE is unspecified.\n\ | |
1067 | If OBJFILE is provided, dump only that file's minimal symbols."), | |
80480540 YQ |
1068 | &maintenanceprintlist); |
1069 | ||
1070 | add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles, | |
52e260a3 DE |
1071 | _("Print dump of current object file definitions.\n\ |
1072 | With an argument REGEXP, list the object files with matching names."), | |
80480540 YQ |
1073 | &maintenanceprintlist); |
1074 | ||
1075 | add_cmd ("symtabs", class_maintenance, maintenance_info_symtabs, _("\ | |
1076 | List the full symbol tables for all object files.\n\ | |
1077 | This does not include information about individual symbols, blocks, or\n\ | |
1078 | linetables --- just the symbol table structures themselves.\n\ | |
db68bbae | 1079 | With an argument REGEXP, list the symbol tables with matching names."), |
80480540 | 1080 | &maintenanceinfolist); |
7d0c9981 | 1081 | |
f2403c39 AB |
1082 | add_cmd ("line-table", class_maintenance, maintenance_info_line_tables, _("\ |
1083 | List the contents of all line tables, from all symbol tables.\n\ | |
1084 | With an argument REGEXP, list just the line tables for the symbol\n\ | |
1085 | tables with matching names."), | |
1086 | &maintenanceinfolist); | |
1087 | ||
7d0c9981 DE |
1088 | add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs, |
1089 | _("\ | |
1090 | Check consistency of currently expanded symtabs."), | |
1091 | &maintenancelist); | |
1092 | ||
1093 | add_cmd ("expand-symtabs", class_maintenance, maintenance_expand_symtabs, | |
1094 | _("Expand symbol tables.\n\ | |
1095 | With an argument REGEXP, only expand the symbol tables with matching names."), | |
1096 | &maintenancelist); | |
c906108c | 1097 | } |