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