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