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