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