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