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