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" |
dbda9972 | 39 | #include "readline/readline.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 | ||
a14ed312 | 55 | static int block_depth (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) |
99d89cde TT |
67 | for (objfile *objfile : all_objfiles (pspace)) |
68 | { | |
69 | QUIT; | |
70 | printf_filtered (_("Byte cache statistics for '%s':\n"), | |
71 | objfile_name (objfile)); | |
d320c2b5 TT |
72 | print_bcache_statistics |
73 | (psymbol_bcache_get_bcache (objfile->partial_symtabs->psymbol_cache), | |
74 | "partial symbol cache"); | |
99d89cde TT |
75 | print_bcache_statistics (objfile->per_bfd->macro_cache, |
76 | "preprocessor macro cache"); | |
77 | print_bcache_statistics (objfile->per_bfd->filename_cache, | |
78 | "file name cache"); | |
79 | } | |
c906108c SS |
80 | } |
81 | ||
82 | void | |
fba45db2 | 83 | print_objfile_statistics (void) |
c906108c | 84 | { |
6c95b8df | 85 | struct program_space *pspace; |
c4f90d87 | 86 | int i, linetables, blockvectors; |
c906108c | 87 | |
6c95b8df | 88 | ALL_PSPACES (pspace) |
99d89cde TT |
89 | for (objfile *objfile : all_objfiles (pspace)) |
90 | { | |
91 | QUIT; | |
92 | printf_filtered (_("Statistics for '%s':\n"), objfile_name (objfile)); | |
93 | if (OBJSTAT (objfile, n_stabs) > 0) | |
94 | printf_filtered (_(" Number of \"stab\" symbols read: %d\n"), | |
95 | OBJSTAT (objfile, n_stabs)); | |
96 | if (objfile->per_bfd->n_minsyms > 0) | |
97 | printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"), | |
98 | objfile->per_bfd->n_minsyms); | |
99 | if (OBJSTAT (objfile, n_psyms) > 0) | |
100 | printf_filtered (_(" Number of \"partial\" symbols read: %d\n"), | |
101 | OBJSTAT (objfile, n_psyms)); | |
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); | |
592553c4 | 110 | i = linetables = 0; |
d5da8b3c | 111 | for (compunit_symtab *cu : objfile_compunits (objfile)) |
99d89cde | 112 | { |
d5da8b3c TT |
113 | for (symtab *s : compunit_filetabs (cu)) |
114 | { | |
115 | i++; | |
116 | if (SYMTAB_LINETABLE (s) != NULL) | |
117 | linetables++; | |
118 | } | |
99d89cde | 119 | } |
592553c4 TT |
120 | blockvectors = std::distance (objfile_compunits (objfile).begin (), |
121 | objfile_compunits (objfile).end ()); | |
99d89cde TT |
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))); | |
d320c2b5 TT |
137 | printf_filtered |
138 | (_(" Total memory used for psymbol cache: %d\n"), | |
139 | bcache_memory_used (psymbol_bcache_get_bcache | |
140 | (objfile->partial_symtabs->psymbol_cache))); | |
99d89cde TT |
141 | printf_filtered (_(" Total memory used for macro cache: %d\n"), |
142 | bcache_memory_used (objfile->per_bfd->macro_cache)); | |
143 | printf_filtered (_(" Total memory used for file name cache: %d\n"), | |
144 | bcache_memory_used (objfile->per_bfd->filename_cache)); | |
145 | } | |
c906108c SS |
146 | } |
147 | ||
c5aa993b | 148 | static void |
fba45db2 | 149 | dump_objfile (struct objfile *objfile) |
c906108c | 150 | { |
4262abfb | 151 | printf_filtered ("\nObject file %s: ", objfile_name (objfile)); |
c906108c | 152 | printf_filtered ("Objfile at "); |
d4f3574e | 153 | gdb_print_host_address (objfile, gdb_stdout); |
c906108c | 154 | printf_filtered (", bfd at "); |
d4f3574e | 155 | gdb_print_host_address (objfile->obfd, gdb_stdout); |
c906108c | 156 | printf_filtered (", %d minsyms\n\n", |
34643a32 | 157 | objfile->per_bfd->minimal_symbol_count); |
c906108c | 158 | |
ccefe4c4 TT |
159 | if (objfile->sf) |
160 | objfile->sf->qf->dump (objfile); | |
c906108c | 161 | |
43f3e411 | 162 | if (objfile->compunit_symtabs != NULL) |
c906108c SS |
163 | { |
164 | printf_filtered ("Symtabs:\n"); | |
d5da8b3c | 165 | for (compunit_symtab *cu : objfile_compunits (objfile)) |
c906108c | 166 | { |
d5da8b3c | 167 | for (symtab *symtab : compunit_filetabs (cu)) |
c906108c | 168 | { |
d5da8b3c TT |
169 | printf_filtered ("%s at ", |
170 | symtab_to_filename_for_display (symtab)); | |
171 | gdb_print_host_address (symtab, gdb_stdout); | |
172 | printf_filtered (", "); | |
173 | if (SYMTAB_OBJFILE (symtab) != objfile) | |
174 | { | |
175 | printf_filtered ("NOT ON CHAIN! "); | |
176 | } | |
177 | wrap_here (" "); | |
c906108c | 178 | } |
c906108c SS |
179 | } |
180 | printf_filtered ("\n\n"); | |
181 | } | |
182 | } | |
183 | ||
184 | /* Print minimal symbols from this objfile. */ | |
c5aa993b JM |
185 | |
186 | static void | |
fba45db2 | 187 | dump_msymbols (struct objfile *objfile, struct ui_file *outfile) |
c906108c | 188 | { |
5af949e3 | 189 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
190 | int index; |
191 | char ms_type; | |
c5aa993b | 192 | |
4262abfb | 193 | fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile_name (objfile)); |
34643a32 | 194 | if (objfile->per_bfd->minimal_symbol_count == 0) |
c906108c SS |
195 | { |
196 | fprintf_filtered (outfile, "No minimal symbols found.\n"); | |
197 | return; | |
198 | } | |
3567439c | 199 | index = 0; |
5325b9bf | 200 | for (minimal_symbol *msymbol : objfile_msymbols (objfile)) |
c906108c | 201 | { |
efd66ac6 | 202 | struct obj_section *section = MSYMBOL_OBJ_SECTION (objfile, msymbol); |
714835d5 | 203 | |
712f90be | 204 | switch (MSYMBOL_TYPE (msymbol)) |
c906108c | 205 | { |
c5aa993b JM |
206 | case mst_unknown: |
207 | ms_type = 'u'; | |
208 | break; | |
209 | case mst_text: | |
210 | ms_type = 'T'; | |
211 | break; | |
0875794a | 212 | case mst_text_gnu_ifunc: |
f50776aa | 213 | case mst_data_gnu_ifunc: |
0875794a JK |
214 | ms_type = 'i'; |
215 | break; | |
c5aa993b JM |
216 | case mst_solib_trampoline: |
217 | ms_type = 'S'; | |
218 | break; | |
219 | case mst_data: | |
220 | ms_type = 'D'; | |
221 | break; | |
222 | case mst_bss: | |
223 | ms_type = 'B'; | |
224 | break; | |
225 | case mst_abs: | |
226 | ms_type = 'A'; | |
227 | break; | |
228 | case mst_file_text: | |
229 | ms_type = 't'; | |
230 | break; | |
231 | case mst_file_data: | |
232 | ms_type = 'd'; | |
233 | break; | |
234 | case mst_file_bss: | |
235 | ms_type = 'b'; | |
236 | break; | |
237 | default: | |
238 | ms_type = '?'; | |
239 | break; | |
c906108c SS |
240 | } |
241 | fprintf_filtered (outfile, "[%2d] %c ", index, ms_type); | |
77e371c0 TT |
242 | fputs_filtered (paddress (gdbarch, MSYMBOL_VALUE_ADDRESS (objfile, |
243 | msymbol)), | |
5af949e3 | 244 | outfile); |
efd66ac6 | 245 | fprintf_filtered (outfile, " %s", MSYMBOL_LINKAGE_NAME (msymbol)); |
714835d5 | 246 | if (section) |
8625fc1b TT |
247 | { |
248 | if (section->the_bfd_section != NULL) | |
249 | fprintf_filtered (outfile, " section %s", | |
250 | bfd_section_name (objfile->obfd, | |
251 | section->the_bfd_section)); | |
252 | else | |
253 | fprintf_filtered (outfile, " spurious section %ld", | |
4c8429ef | 254 | (long) (section - objfile->sections)); |
8625fc1b | 255 | } |
efd66ac6 | 256 | if (MSYMBOL_DEMANGLED_NAME (msymbol) != NULL) |
c906108c | 257 | { |
efd66ac6 | 258 | fprintf_filtered (outfile, " %s", MSYMBOL_DEMANGLED_NAME (msymbol)); |
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; |
de4f826b | 284 | 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 DJ |
341 | fprintf_filtered (outfile, ", function %s", |
342 | SYMBOL_LINKAGE_NAME (BLOCK_FUNCTION (b))); | |
c906108c SS |
343 | if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL) |
344 | { | |
345 | fprintf_filtered (outfile, ", %s", | |
c5aa993b | 346 | SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b))); |
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 | { |
bf469271 PA |
355 | TRY |
356 | { | |
357 | print_symbol (gdbarch, sym, depth + 1, outfile); | |
358 | } | |
359 | CATCH (ex, RETURN_MASK_ERROR) | |
360 | { | |
361 | exception_fprintf (gdb_stderr, ex, | |
362 | "Error printing symbol:\n"); | |
363 | } | |
364 | END_CATCH | |
c906108c SS |
365 | } |
366 | } | |
367 | fprintf_filtered (outfile, "\n"); | |
368 | } | |
369 | else | |
370 | { | |
6c739336 DE |
371 | const char *compunit_filename |
372 | = symtab_to_filename_for_display (COMPUNIT_FILETABS (SYMTAB_COMPUNIT (symtab))); | |
373 | ||
374 | fprintf_filtered (outfile, | |
375 | "\nBlockvector same as owning compunit: %s\n\n", | |
376 | compunit_filename); | |
c906108c SS |
377 | } |
378 | } | |
379 | ||
44b164c5 | 380 | static void |
d04c1a59 | 381 | dump_symtab (struct symtab *symtab, struct ui_file *outfile) |
44b164c5 | 382 | { |
44b164c5 JB |
383 | /* Set the current language to the language of the symtab we're dumping |
384 | because certain routines used during dump_symtab() use the current | |
969107c5 EZ |
385 | language to print an image of the symbol. We'll restore it later. |
386 | But use only real languages, not placeholders. */ | |
387 | if (symtab->language != language_unknown | |
388 | && symtab->language != language_auto) | |
389 | { | |
390 | enum language saved_lang; | |
391 | ||
392 | saved_lang = set_language (symtab->language); | |
44b164c5 | 393 | |
d04c1a59 | 394 | dump_symtab_1 (symtab, outfile); |
44b164c5 | 395 | |
969107c5 EZ |
396 | set_language (saved_lang); |
397 | } | |
398 | else | |
d04c1a59 | 399 | dump_symtab_1 (symtab, outfile); |
44b164c5 JB |
400 | } |
401 | ||
80480540 | 402 | static void |
e99c83e7 | 403 | maintenance_print_symbols (const char *args, int from_tty) |
c906108c | 404 | { |
34c41c68 | 405 | struct ui_file *outfile = gdb_stdout; |
34c41c68 DE |
406 | char *address_arg = NULL, *source_arg = NULL, *objfile_arg = NULL; |
407 | int i, outfile_idx; | |
c906108c SS |
408 | |
409 | dont_repeat (); | |
410 | ||
773a1edc | 411 | gdb_argv argv (args); |
c906108c | 412 | |
99e8a4f9 | 413 | for (i = 0; argv != NULL && argv[i] != NULL; ++i) |
c906108c | 414 | { |
34c41c68 DE |
415 | if (strcmp (argv[i], "-pc") == 0) |
416 | { | |
417 | if (argv[i + 1] == NULL) | |
418 | error (_("Missing pc value")); | |
419 | address_arg = argv[++i]; | |
420 | } | |
421 | else if (strcmp (argv[i], "-source") == 0) | |
422 | { | |
423 | if (argv[i + 1] == NULL) | |
424 | error (_("Missing source file")); | |
425 | source_arg = argv[++i]; | |
426 | } | |
427 | else if (strcmp (argv[i], "-objfile") == 0) | |
428 | { | |
429 | if (argv[i + 1] == NULL) | |
430 | error (_("Missing objfile name")); | |
431 | objfile_arg = argv[++i]; | |
432 | } | |
433 | else if (strcmp (argv[i], "--") == 0) | |
434 | { | |
435 | /* End of options. */ | |
436 | ++i; | |
437 | break; | |
438 | } | |
439 | else if (argv[i][0] == '-') | |
c906108c | 440 | { |
34c41c68 DE |
441 | /* Future proofing: Don't allow OUTFILE to begin with "-". */ |
442 | error (_("Unknown option: %s"), argv[i]); | |
c906108c | 443 | } |
34c41c68 DE |
444 | else |
445 | break; | |
c906108c | 446 | } |
34c41c68 | 447 | outfile_idx = i; |
c906108c | 448 | |
34c41c68 DE |
449 | if (address_arg != NULL && source_arg != NULL) |
450 | error (_("Must specify at most one of -pc and -source")); | |
c5aa993b | 451 | |
d7e74731 PA |
452 | stdio_file arg_outfile; |
453 | ||
99e8a4f9 | 454 | if (argv != NULL && argv[outfile_idx] != NULL) |
34c41c68 | 455 | { |
34c41c68 DE |
456 | if (argv[outfile_idx + 1] != NULL) |
457 | error (_("Junk at end of command")); | |
ee0c3293 TT |
458 | gdb::unique_xmalloc_ptr<char> outfile_name |
459 | (tilde_expand (argv[outfile_idx])); | |
460 | if (!arg_outfile.open (outfile_name.get (), FOPEN_WT)) | |
461 | perror_with_name (outfile_name.get ()); | |
d7e74731 | 462 | outfile = &arg_outfile; |
34c41c68 | 463 | } |
c906108c | 464 | |
34c41c68 | 465 | if (address_arg != NULL) |
27618ce4 | 466 | { |
34c41c68 DE |
467 | CORE_ADDR pc = parse_and_eval_address (address_arg); |
468 | struct symtab *s = find_pc_line_symtab (pc); | |
469 | ||
470 | if (s == NULL) | |
471 | error (_("No symtab for address: %s"), address_arg); | |
472 | dump_symtab (s, outfile); | |
27618ce4 | 473 | } |
34c41c68 DE |
474 | else |
475 | { | |
34c41c68 DE |
476 | int found = 0; |
477 | ||
aed57c53 | 478 | for (objfile *objfile : all_objfiles (current_program_space)) |
34c41c68 DE |
479 | { |
480 | int print_for_objfile = 1; | |
481 | ||
482 | if (objfile_arg != NULL) | |
483 | print_for_objfile | |
484 | = compare_filenames_for_search (objfile_name (objfile), | |
485 | objfile_arg); | |
486 | if (!print_for_objfile) | |
487 | continue; | |
488 | ||
d5da8b3c | 489 | for (compunit_symtab *cu : objfile_compunits (objfile)) |
34c41c68 | 490 | { |
d5da8b3c | 491 | for (symtab *s : compunit_filetabs (cu)) |
34c41c68 | 492 | { |
d5da8b3c TT |
493 | int print_for_source = 0; |
494 | ||
495 | QUIT; | |
496 | if (source_arg != NULL) | |
497 | { | |
498 | print_for_source | |
499 | = compare_filenames_for_search | |
500 | (symtab_to_filename_for_display (s), source_arg); | |
501 | found = 1; | |
502 | } | |
503 | if (source_arg == NULL | |
504 | || print_for_source) | |
505 | dump_symtab (s, outfile); | |
34c41c68 | 506 | } |
34c41c68 DE |
507 | } |
508 | } | |
509 | ||
510 | if (source_arg != NULL && !found) | |
511 | error (_("No symtab for source file: %s"), source_arg); | |
512 | } | |
c906108c SS |
513 | } |
514 | ||
bf469271 | 515 | /* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */ |
c906108c | 516 | |
bf469271 PA |
517 | static void |
518 | print_symbol (struct gdbarch *gdbarch, struct symbol *symbol, | |
519 | int depth, ui_file *outfile) | |
c906108c | 520 | { |
1994afbf DE |
521 | struct obj_section *section; |
522 | ||
523 | if (SYMBOL_OBJFILE_OWNED (symbol)) | |
524 | section = SYMBOL_OBJ_SECTION (symbol_objfile (symbol), symbol); | |
525 | else | |
526 | section = NULL; | |
c906108c SS |
527 | |
528 | print_spaces (depth, outfile); | |
176620f1 | 529 | if (SYMBOL_DOMAIN (symbol) == LABEL_DOMAIN) |
c906108c | 530 | { |
de5ad195 | 531 | fprintf_filtered (outfile, "label %s at ", SYMBOL_PRINT_NAME (symbol)); |
5af949e3 UW |
532 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)), |
533 | outfile); | |
714835d5 | 534 | if (section) |
c906108c | 535 | fprintf_filtered (outfile, " section %s\n", |
714835d5 UW |
536 | bfd_section_name (section->the_bfd_section->owner, |
537 | section->the_bfd_section)); | |
c906108c SS |
538 | else |
539 | fprintf_filtered (outfile, "\n"); | |
bf469271 | 540 | return; |
c906108c | 541 | } |
bf469271 | 542 | |
176620f1 | 543 | if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN) |
c906108c | 544 | { |
e86ca25f | 545 | if (TYPE_NAME (SYMBOL_TYPE (symbol))) |
c906108c | 546 | { |
79d43c61 TT |
547 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth, |
548 | &type_print_raw_options); | |
c906108c SS |
549 | } |
550 | else | |
551 | { | |
552 | fprintf_filtered (outfile, "%s %s = ", | |
c5aa993b JM |
553 | (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM |
554 | ? "enum" | |
555 | : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT | |
556 | ? "struct" : "union")), | |
3567439c | 557 | SYMBOL_LINKAGE_NAME (symbol)); |
79d43c61 TT |
558 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth, |
559 | &type_print_raw_options); | |
c906108c SS |
560 | } |
561 | fprintf_filtered (outfile, ";\n"); | |
562 | } | |
563 | else | |
564 | { | |
565 | if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF) | |
566 | fprintf_filtered (outfile, "typedef "); | |
567 | if (SYMBOL_TYPE (symbol)) | |
568 | { | |
569 | /* Print details of types, except for enums where it's clutter. */ | |
de5ad195 | 570 | LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_PRINT_NAME (symbol), |
c906108c SS |
571 | outfile, |
572 | TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM, | |
79d43c61 TT |
573 | depth, |
574 | &type_print_raw_options); | |
c906108c SS |
575 | fprintf_filtered (outfile, "; "); |
576 | } | |
577 | else | |
de5ad195 | 578 | fprintf_filtered (outfile, "%s ", SYMBOL_PRINT_NAME (symbol)); |
c906108c SS |
579 | |
580 | switch (SYMBOL_CLASS (symbol)) | |
581 | { | |
582 | case LOC_CONST: | |
12df843f JK |
583 | fprintf_filtered (outfile, "const %s (%s)", |
584 | plongest (SYMBOL_VALUE (symbol)), | |
585 | hex_string (SYMBOL_VALUE (symbol))); | |
c906108c SS |
586 | break; |
587 | ||
588 | case LOC_CONST_BYTES: | |
589 | { | |
590 | unsigned i; | |
591 | struct type *type = check_typedef (SYMBOL_TYPE (symbol)); | |
433759f7 | 592 | |
c906108c SS |
593 | fprintf_filtered (outfile, "const %u hex bytes:", |
594 | TYPE_LENGTH (type)); | |
595 | for (i = 0; i < TYPE_LENGTH (type); i++) | |
596 | fprintf_filtered (outfile, " %02x", | |
c5aa993b | 597 | (unsigned) SYMBOL_VALUE_BYTES (symbol)[i]); |
c906108c SS |
598 | } |
599 | break; | |
600 | ||
601 | case LOC_STATIC: | |
602 | fprintf_filtered (outfile, "static at "); | |
5af949e3 UW |
603 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)), |
604 | outfile); | |
714835d5 | 605 | if (section) |
c906108c | 606 | fprintf_filtered (outfile, " section %s", |
714835d5 UW |
607 | bfd_section_name (section->the_bfd_section->owner, |
608 | section->the_bfd_section)); | |
c906108c SS |
609 | break; |
610 | ||
c906108c | 611 | case LOC_REGISTER: |
2a2d4dc3 | 612 | if (SYMBOL_IS_ARGUMENT (symbol)) |
12df843f JK |
613 | fprintf_filtered (outfile, "parameter register %s", |
614 | plongest (SYMBOL_VALUE (symbol))); | |
2a2d4dc3 | 615 | else |
12df843f JK |
616 | fprintf_filtered (outfile, "register %s", |
617 | plongest (SYMBOL_VALUE (symbol))); | |
c906108c SS |
618 | break; |
619 | ||
620 | case LOC_ARG: | |
12df843f JK |
621 | fprintf_filtered (outfile, "arg at offset %s", |
622 | hex_string (SYMBOL_VALUE (symbol))); | |
c906108c SS |
623 | break; |
624 | ||
c906108c | 625 | case LOC_REF_ARG: |
12df843f JK |
626 | fprintf_filtered (outfile, "reference arg at %s", |
627 | hex_string (SYMBOL_VALUE (symbol))); | |
c906108c SS |
628 | break; |
629 | ||
c906108c | 630 | case LOC_REGPARM_ADDR: |
12df843f JK |
631 | fprintf_filtered (outfile, "address parameter register %s", |
632 | plongest (SYMBOL_VALUE (symbol))); | |
c906108c SS |
633 | break; |
634 | ||
635 | case LOC_LOCAL: | |
12df843f JK |
636 | fprintf_filtered (outfile, "local at offset %s", |
637 | hex_string (SYMBOL_VALUE (symbol))); | |
c906108c SS |
638 | break; |
639 | ||
c906108c SS |
640 | case LOC_TYPEDEF: |
641 | break; | |
642 | ||
643 | case LOC_LABEL: | |
644 | fprintf_filtered (outfile, "label at "); | |
5af949e3 UW |
645 | fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (symbol)), |
646 | outfile); | |
714835d5 | 647 | if (section) |
c906108c | 648 | fprintf_filtered (outfile, " section %s", |
714835d5 UW |
649 | bfd_section_name (section->the_bfd_section->owner, |
650 | section->the_bfd_section)); | |
c906108c SS |
651 | break; |
652 | ||
653 | case LOC_BLOCK: | |
654 | fprintf_filtered (outfile, "block object "); | |
d4f3574e | 655 | gdb_print_host_address (SYMBOL_BLOCK_VALUE (symbol), outfile); |
c906108c | 656 | fprintf_filtered (outfile, ", "); |
5af949e3 UW |
657 | fputs_filtered (paddress (gdbarch, |
658 | BLOCK_START (SYMBOL_BLOCK_VALUE (symbol))), | |
ed49a04f | 659 | outfile); |
c906108c | 660 | fprintf_filtered (outfile, ".."); |
5af949e3 UW |
661 | fputs_filtered (paddress (gdbarch, |
662 | BLOCK_END (SYMBOL_BLOCK_VALUE (symbol))), | |
ed49a04f | 663 | outfile); |
714835d5 | 664 | if (section) |
c906108c | 665 | fprintf_filtered (outfile, " section %s", |
714835d5 UW |
666 | bfd_section_name (section->the_bfd_section->owner, |
667 | section->the_bfd_section)); | |
c906108c SS |
668 | break; |
669 | ||
4c2df51b | 670 | case LOC_COMPUTED: |
4c2df51b DJ |
671 | fprintf_filtered (outfile, "computed at runtime"); |
672 | break; | |
673 | ||
c906108c SS |
674 | case LOC_UNRESOLVED: |
675 | fprintf_filtered (outfile, "unresolved"); | |
676 | break; | |
677 | ||
678 | case LOC_OPTIMIZED_OUT: | |
679 | fprintf_filtered (outfile, "optimized out"); | |
680 | break; | |
681 | ||
c5aa993b | 682 | default: |
c906108c SS |
683 | fprintf_filtered (outfile, "botched symbol class %x", |
684 | SYMBOL_CLASS (symbol)); | |
685 | break; | |
686 | } | |
687 | } | |
688 | fprintf_filtered (outfile, "\n"); | |
c906108c SS |
689 | } |
690 | ||
80480540 | 691 | static void |
e99c83e7 | 692 | maintenance_print_msymbols (const char *args, int from_tty) |
c906108c | 693 | { |
34c41c68 | 694 | struct ui_file *outfile = gdb_stdout; |
34c41c68 | 695 | char *objfile_arg = NULL; |
34c41c68 | 696 | int i, outfile_idx; |
07318b29 | 697 | |
c906108c SS |
698 | dont_repeat (); |
699 | ||
773a1edc | 700 | gdb_argv argv (args); |
c906108c | 701 | |
99e8a4f9 | 702 | for (i = 0; argv != NULL && argv[i] != NULL; ++i) |
c906108c | 703 | { |
34c41c68 | 704 | if (strcmp (argv[i], "-objfile") == 0) |
c906108c | 705 | { |
34c41c68 DE |
706 | if (argv[i + 1] == NULL) |
707 | error (_("Missing objfile name")); | |
708 | objfile_arg = argv[++i]; | |
709 | } | |
710 | else if (strcmp (argv[i], "--") == 0) | |
711 | { | |
712 | /* End of options. */ | |
713 | ++i; | |
714 | break; | |
c906108c | 715 | } |
34c41c68 DE |
716 | else if (argv[i][0] == '-') |
717 | { | |
718 | /* Future proofing: Don't allow OUTFILE to begin with "-". */ | |
719 | error (_("Unknown option: %s"), argv[i]); | |
720 | } | |
721 | else | |
722 | break; | |
c906108c | 723 | } |
34c41c68 | 724 | outfile_idx = i; |
c906108c | 725 | |
d7e74731 PA |
726 | stdio_file arg_outfile; |
727 | ||
99e8a4f9 | 728 | if (argv != NULL && argv[outfile_idx] != NULL) |
34c41c68 | 729 | { |
34c41c68 DE |
730 | if (argv[outfile_idx + 1] != NULL) |
731 | error (_("Junk at end of command")); | |
ee0c3293 TT |
732 | gdb::unique_xmalloc_ptr<char> outfile_name |
733 | (tilde_expand (argv[outfile_idx])); | |
734 | if (!arg_outfile.open (outfile_name.get (), FOPEN_WT)) | |
735 | perror_with_name (outfile_name.get ()); | |
d7e74731 | 736 | outfile = &arg_outfile; |
34c41c68 | 737 | } |
c5aa993b | 738 | |
aed57c53 TT |
739 | for (objfile *objfile : all_objfiles (current_program_space)) |
740 | { | |
741 | QUIT; | |
742 | if (objfile_arg == NULL | |
743 | || compare_filenames_for_search (objfile_name (objfile), objfile_arg)) | |
744 | dump_msymbols (objfile, outfile); | |
745 | } | |
c906108c SS |
746 | } |
747 | ||
80480540 | 748 | static void |
e99c83e7 | 749 | maintenance_print_objfiles (const char *regexp, int from_tty) |
c906108c | 750 | { |
6c95b8df | 751 | struct program_space *pspace; |
c906108c SS |
752 | |
753 | dont_repeat (); | |
754 | ||
52e260a3 DE |
755 | if (regexp) |
756 | re_comp (regexp); | |
757 | ||
6c95b8df | 758 | ALL_PSPACES (pspace) |
99d89cde | 759 | for (objfile *objfile : all_objfiles (pspace)) |
27618ce4 TT |
760 | { |
761 | QUIT; | |
52e260a3 | 762 | if (! regexp |
4262abfb | 763 | || re_exec (objfile_name (objfile))) |
52e260a3 | 764 | dump_objfile (objfile); |
27618ce4 | 765 | } |
c906108c SS |
766 | } |
767 | ||
5e7b2f39 | 768 | /* List all the symbol tables whose names match REGEXP (optional). */ |
b5ebcee6 | 769 | |
80480540 | 770 | static void |
e99c83e7 | 771 | maintenance_info_symtabs (const char *regexp, int from_tty) |
44ea7b70 | 772 | { |
6c95b8df | 773 | struct program_space *pspace; |
44ea7b70 | 774 | |
db68bbae DE |
775 | dont_repeat (); |
776 | ||
44ea7b70 JB |
777 | if (regexp) |
778 | re_comp (regexp); | |
779 | ||
6c95b8df | 780 | ALL_PSPACES (pspace) |
99d89cde TT |
781 | for (objfile *objfile : all_objfiles (pspace)) |
782 | { | |
99d89cde TT |
783 | /* We don't want to print anything for this objfile until we |
784 | actually find a symtab whose name matches. */ | |
785 | int printed_objfile_start = 0; | |
43f3e411 | 786 | |
592553c4 | 787 | for (compunit_symtab *cust : objfile_compunits (objfile)) |
99d89cde TT |
788 | { |
789 | int printed_compunit_symtab_start = 0; | |
790 | ||
5accd1a0 | 791 | for (symtab *symtab : compunit_filetabs (cust)) |
99d89cde TT |
792 | { |
793 | QUIT; | |
794 | ||
795 | if (! regexp | |
796 | || re_exec (symtab_to_filename_for_display (symtab))) | |
797 | { | |
798 | if (! printed_objfile_start) | |
799 | { | |
800 | printf_filtered ("{ objfile %s ", objfile_name (objfile)); | |
801 | wrap_here (" "); | |
802 | printf_filtered ("((struct objfile *) %s)\n", | |
803 | host_address_to_string (objfile)); | |
804 | printed_objfile_start = 1; | |
805 | } | |
806 | if (! printed_compunit_symtab_start) | |
807 | { | |
808 | printf_filtered (" { ((struct compunit_symtab *) %s)\n", | |
809 | host_address_to_string (cust)); | |
810 | printf_filtered (" debugformat %s\n", | |
811 | COMPUNIT_DEBUGFORMAT (cust)); | |
812 | printf_filtered (" producer %s\n", | |
813 | COMPUNIT_PRODUCER (cust) != NULL | |
814 | ? COMPUNIT_PRODUCER (cust) | |
815 | : "(null)"); | |
816 | printf_filtered (" dirname %s\n", | |
817 | COMPUNIT_DIRNAME (cust) != NULL | |
818 | ? COMPUNIT_DIRNAME (cust) | |
819 | : "(null)"); | |
820 | printf_filtered (" blockvector" | |
821 | " ((struct blockvector *) %s)\n", | |
822 | host_address_to_string | |
43f3e411 | 823 | (COMPUNIT_BLOCKVECTOR (cust))); |
99d89cde TT |
824 | printed_compunit_symtab_start = 1; |
825 | } | |
826 | ||
827 | printf_filtered ("\t{ symtab %s ", | |
828 | symtab_to_filename_for_display (symtab)); | |
829 | wrap_here (" "); | |
830 | printf_filtered ("((struct symtab *) %s)\n", | |
831 | host_address_to_string (symtab)); | |
832 | printf_filtered ("\t fullname %s\n", | |
833 | symtab->fullname != NULL | |
834 | ? symtab->fullname | |
835 | : "(null)"); | |
836 | printf_filtered ("\t " | |
837 | "linetable ((struct linetable *) %s)\n", | |
838 | host_address_to_string (symtab->linetable)); | |
839 | printf_filtered ("\t}\n"); | |
840 | } | |
841 | } | |
842 | ||
843 | if (printed_compunit_symtab_start) | |
844 | printf_filtered (" }\n"); | |
845 | } | |
44ea7b70 | 846 | |
99d89cde TT |
847 | if (printed_objfile_start) |
848 | printf_filtered ("}\n"); | |
849 | } | |
44ea7b70 | 850 | } |
7d0c9981 DE |
851 | |
852 | /* Check consistency of symtabs. | |
853 | An example of what this checks for is NULL blockvectors. | |
854 | They can happen if there's a bug during debug info reading. | |
855 | GDB assumes they are always non-NULL. | |
856 | ||
857 | Note: This does not check for psymtab vs symtab consistency. | |
858 | Use "maint check-psymtabs" for that. */ | |
859 | ||
860 | static void | |
e99c83e7 | 861 | maintenance_check_symtabs (const char *ignore, int from_tty) |
7d0c9981 DE |
862 | { |
863 | struct program_space *pspace; | |
7d0c9981 DE |
864 | |
865 | ALL_PSPACES (pspace) | |
99d89cde TT |
866 | for (objfile *objfile : all_objfiles (pspace)) |
867 | { | |
99d89cde TT |
868 | /* We don't want to print anything for this objfile until we |
869 | actually find something worth printing. */ | |
870 | int printed_objfile_start = 0; | |
7d0c9981 | 871 | |
592553c4 | 872 | for (compunit_symtab *cust : objfile_compunits (objfile)) |
99d89cde TT |
873 | { |
874 | int found_something = 0; | |
875 | struct symtab *symtab = compunit_primary_filetab (cust); | |
876 | ||
877 | QUIT; | |
878 | ||
879 | if (COMPUNIT_BLOCKVECTOR (cust) == NULL) | |
880 | found_something = 1; | |
881 | /* Add more checks here. */ | |
882 | ||
883 | if (found_something) | |
884 | { | |
885 | if (! printed_objfile_start) | |
886 | { | |
887 | printf_filtered ("{ objfile %s ", objfile_name (objfile)); | |
888 | wrap_here (" "); | |
889 | printf_filtered ("((struct objfile *) %s)\n", | |
890 | host_address_to_string (objfile)); | |
891 | printed_objfile_start = 1; | |
892 | } | |
893 | printf_filtered (" { symtab %s\n", | |
894 | symtab_to_filename_for_display (symtab)); | |
895 | if (COMPUNIT_BLOCKVECTOR (cust) == NULL) | |
896 | printf_filtered (" NULL blockvector\n"); | |
897 | printf_filtered (" }\n"); | |
898 | } | |
899 | } | |
7d0c9981 | 900 | |
99d89cde TT |
901 | if (printed_objfile_start) |
902 | printf_filtered ("}\n"); | |
903 | } | |
7d0c9981 DE |
904 | } |
905 | ||
7d0c9981 DE |
906 | /* Expand all symbol tables whose name matches an optional regexp. */ |
907 | ||
908 | static void | |
e99c83e7 | 909 | maintenance_expand_symtabs (const char *args, int from_tty) |
7d0c9981 DE |
910 | { |
911 | struct program_space *pspace; | |
7d0c9981 DE |
912 | char *regexp = NULL; |
913 | ||
914 | /* We use buildargv here so that we handle spaces in the regexp | |
915 | in a way that allows adding more arguments later. */ | |
773a1edc | 916 | gdb_argv argv (args); |
7d0c9981 DE |
917 | |
918 | if (argv != NULL) | |
919 | { | |
920 | if (argv[0] != NULL) | |
921 | { | |
922 | regexp = argv[0]; | |
923 | if (argv[1] != NULL) | |
924 | error (_("Extra arguments after regexp.")); | |
925 | } | |
926 | } | |
927 | ||
928 | if (regexp) | |
929 | re_comp (regexp); | |
930 | ||
931 | ALL_PSPACES (pspace) | |
99d89cde TT |
932 | for (objfile *objfile : all_objfiles (pspace)) |
933 | { | |
934 | if (objfile->sf) | |
935 | { | |
936 | objfile->sf->qf->expand_symtabs_matching | |
937 | (objfile, | |
938 | [&] (const char *filename, bool basenames) | |
939 | { | |
940 | /* KISS: Only apply the regexp to the complete file name. */ | |
941 | return (!basenames | |
942 | && (regexp == NULL || re_exec (filename))); | |
943 | }, | |
944 | lookup_name_info::match_any (), | |
945 | [] (const char *symname) | |
946 | { | |
947 | /* Since we're not searching on symbols, just return true. */ | |
948 | return true; | |
949 | }, | |
950 | NULL, | |
951 | ALL_DOMAIN); | |
952 | } | |
953 | } | |
7d0c9981 | 954 | } |
c906108c | 955 | \f |
c5aa993b | 956 | |
c906108c SS |
957 | /* Return the nexting depth of a block within other blocks in its symtab. */ |
958 | ||
959 | static int | |
fba45db2 | 960 | block_depth (struct block *block) |
c906108c | 961 | { |
52f0bd74 | 962 | int i = 0; |
433759f7 | 963 | |
c5aa993b | 964 | while ((block = BLOCK_SUPERBLOCK (block)) != NULL) |
c906108c SS |
965 | { |
966 | i++; | |
967 | } | |
968 | return i; | |
969 | } | |
c906108c | 970 | \f |
c5aa993b | 971 | |
f2403c39 AB |
972 | /* Used by MAINTENANCE_INFO_LINE_TABLES to print the information about a |
973 | single line table. */ | |
974 | ||
975 | static int | |
976 | maintenance_print_one_line_table (struct symtab *symtab, void *data) | |
977 | { | |
978 | struct linetable *linetable; | |
979 | struct objfile *objfile; | |
980 | ||
981 | objfile = symtab->compunit_symtab->objfile; | |
982 | printf_filtered (_("objfile: %s ((struct objfile *) %s)\n"), | |
983 | objfile_name (objfile), | |
984 | host_address_to_string (objfile)); | |
985 | printf_filtered (_("compunit_symtab: ((struct compunit_symtab *) %s)\n"), | |
986 | host_address_to_string (symtab->compunit_symtab)); | |
987 | printf_filtered (_("symtab: %s ((struct symtab *) %s)\n"), | |
988 | symtab_to_fullname (symtab), | |
989 | host_address_to_string (symtab)); | |
990 | linetable = SYMTAB_LINETABLE (symtab); | |
991 | printf_filtered (_("linetable: ((struct linetable *) %s):\n"), | |
992 | host_address_to_string (linetable)); | |
993 | ||
994 | if (linetable == NULL) | |
995 | printf_filtered (_("No line table.\n")); | |
996 | else if (linetable->nitems <= 0) | |
997 | printf_filtered (_("Line table has no lines.\n")); | |
998 | else | |
999 | { | |
1000 | int i; | |
1001 | ||
1002 | /* Leave space for 6 digits of index and line number. After that the | |
1003 | tables will just not format as well. */ | |
1004 | printf_filtered (_("%-6s %6s %s\n"), | |
1005 | _("INDEX"), _("LINE"), _("ADDRESS")); | |
1006 | ||
1007 | for (i = 0; i < linetable->nitems; ++i) | |
1008 | { | |
1009 | struct linetable_entry *item; | |
f2403c39 AB |
1010 | |
1011 | item = &linetable->item [i]; | |
1012 | printf_filtered (_("%-6d %6d %s\n"), i, item->line, | |
1013 | core_addr_to_string (item->pc)); | |
1014 | } | |
1015 | } | |
1016 | ||
1017 | return 0; | |
1018 | } | |
1019 | ||
1020 | /* Implement the 'maint info line-table' command. */ | |
1021 | ||
1022 | static void | |
e99c83e7 | 1023 | maintenance_info_line_tables (const char *regexp, int from_tty) |
f2403c39 AB |
1024 | { |
1025 | struct program_space *pspace; | |
f2403c39 AB |
1026 | |
1027 | dont_repeat (); | |
1028 | ||
1029 | if (regexp != NULL) | |
1030 | re_comp (regexp); | |
1031 | ||
1032 | ALL_PSPACES (pspace) | |
99d89cde TT |
1033 | for (objfile *objfile : all_objfiles (pspace)) |
1034 | { | |
592553c4 | 1035 | for (compunit_symtab *cust : objfile_compunits (objfile)) |
99d89cde | 1036 | { |
5accd1a0 | 1037 | for (symtab *symtab : compunit_filetabs (cust)) |
99d89cde TT |
1038 | { |
1039 | QUIT; | |
1040 | ||
1041 | if (regexp == NULL | |
1042 | || re_exec (symtab_to_filename_for_display (symtab))) | |
1043 | maintenance_print_one_line_table (symtab, NULL); | |
1044 | } | |
1045 | } | |
1046 | } | |
f2403c39 AB |
1047 | } |
1048 | ||
1049 | \f | |
1050 | ||
c378eb4e | 1051 | /* Do early runtime initializations. */ |
b5ebcee6 | 1052 | |
c906108c | 1053 | void |
fba45db2 | 1054 | _initialize_symmisc (void) |
c906108c | 1055 | { |
c5aa993b | 1056 | std_in = stdin; |
c906108c SS |
1057 | std_out = stdout; |
1058 | std_err = stderr; | |
80480540 YQ |
1059 | |
1060 | add_cmd ("symbols", class_maintenance, maintenance_print_symbols, _("\ | |
1061 | Print dump of current symbol definitions.\n\ | |
48c5e7e2 TT |
1062 | Usage: mt print symbols [-pc ADDRESS] [--] [OUTFILE]\n\ |
1063 | mt print symbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\ | |
34c41c68 DE |
1064 | Entries in the full symbol table are dumped to file OUTFILE,\n\ |
1065 | or the terminal if OUTFILE is unspecified.\n\ | |
1066 | If ADDRESS is provided, dump only the file for that address.\n\ | |
1067 | If SOURCE is provided, dump only that file's symbols.\n\ | |
1068 | If OBJFILE is provided, dump only that file's minimal symbols."), | |
80480540 YQ |
1069 | &maintenanceprintlist); |
1070 | ||
1071 | add_cmd ("msymbols", class_maintenance, maintenance_print_msymbols, _("\ | |
1072 | Print dump of current minimal symbol definitions.\n\ | |
48c5e7e2 | 1073 | Usage: mt print msymbols [-objfile OBJFILE] [--] [OUTFILE]\n\ |
34c41c68 DE |
1074 | Entries in the minimal symbol table are dumped to file OUTFILE,\n\ |
1075 | or the terminal if OUTFILE is unspecified.\n\ | |
1076 | If OBJFILE is provided, dump only that file's minimal symbols."), | |
80480540 YQ |
1077 | &maintenanceprintlist); |
1078 | ||
1079 | add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles, | |
52e260a3 DE |
1080 | _("Print dump of current object file definitions.\n\ |
1081 | With an argument REGEXP, list the object files with matching names."), | |
80480540 YQ |
1082 | &maintenanceprintlist); |
1083 | ||
1084 | add_cmd ("symtabs", class_maintenance, maintenance_info_symtabs, _("\ | |
1085 | List the full symbol tables for all object files.\n\ | |
1086 | This does not include information about individual symbols, blocks, or\n\ | |
1087 | linetables --- just the symbol table structures themselves.\n\ | |
db68bbae | 1088 | With an argument REGEXP, list the symbol tables with matching names."), |
80480540 | 1089 | &maintenanceinfolist); |
7d0c9981 | 1090 | |
f2403c39 AB |
1091 | add_cmd ("line-table", class_maintenance, maintenance_info_line_tables, _("\ |
1092 | List the contents of all line tables, from all symbol tables.\n\ | |
1093 | With an argument REGEXP, list just the line tables for the symbol\n\ | |
1094 | tables with matching names."), | |
1095 | &maintenanceinfolist); | |
1096 | ||
7d0c9981 DE |
1097 | add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs, |
1098 | _("\ | |
1099 | Check consistency of currently expanded symtabs."), | |
1100 | &maintenancelist); | |
1101 | ||
1102 | add_cmd ("expand-symtabs", class_maintenance, maintenance_expand_symtabs, | |
1103 | _("Expand symbol tables.\n\ | |
1104 | With an argument REGEXP, only expand the symbol tables with matching names."), | |
1105 | &maintenancelist); | |
c906108c | 1106 | } |