Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support for GDB maintenance commands. |
c6f0559b | 2 | |
3666a048 | 3 | Copyright (C) 1992-2021 Free Software Foundation, Inc. |
c6f0559b | 4 | |
c906108c SS |
5 | Written by Fred Fish at Cygnus Support. |
6 | ||
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 12 | (at your option) any later version. |
c906108c | 13 | |
c5aa993b JM |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
c906108c | 18 | |
c5aa993b | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | ||
23 | #include "defs.h" | |
e17c207e | 24 | #include "arch-utils.h" |
c906108c | 25 | #include <ctype.h> |
aa17805f | 26 | #include <cmath> |
c906108c SS |
27 | #include <signal.h> |
28 | #include "command.h" | |
29 | #include "gdbcmd.h" | |
30 | #include "symtab.h" | |
bd712aed | 31 | #include "block.h" |
c906108c SS |
32 | #include "gdbtypes.h" |
33 | #include "demangle.h" | |
34 | #include "gdbcore.h" | |
c5aa993b | 35 | #include "expression.h" /* For language.h */ |
c906108c SS |
36 | #include "language.h" |
37 | #include "symfile.h" | |
38 | #include "objfiles.h" | |
39 | #include "value.h" | |
bd712aed | 40 | #include "top.h" |
bd712aed | 41 | #include "maint.h" |
268a13a5 | 42 | #include "gdbsupport/selftest.h" |
328d42d8 | 43 | #include "inferior.h" |
c906108c | 44 | |
18a642a1 | 45 | #include "cli/cli-decode.h" |
529480d0 | 46 | #include "cli/cli-utils.h" |
bd712aed | 47 | #include "cli/cli-setshow.h" |
fdbc9870 | 48 | #include "cli/cli-cmds.h" |
18a642a1 | 49 | |
22138db6 TT |
50 | #if CXX_STD_THREAD |
51 | #include "gdbsupport/thread-pool.h" | |
52 | #endif | |
53 | ||
58971144 | 54 | static void maintenance_do_deprecate (const char *, int); |
1c689132 | 55 | |
c906108c | 56 | #ifndef _WIN32 |
c906108c | 57 | static void |
58971144 | 58 | maintenance_dump_me (const char *args, int from_tty) |
c906108c | 59 | { |
9e2f0ad4 | 60 | if (query (_("Should GDB dump core? "))) |
c906108c | 61 | { |
7be570e7 JM |
62 | #ifdef __DJGPP__ |
63 | /* SIGQUIT by default is ignored, so use SIGABRT instead. */ | |
64 | signal (SIGABRT, SIG_DFL); | |
65 | kill (getpid (), SIGABRT); | |
66 | #else | |
c906108c SS |
67 | signal (SIGQUIT, SIG_DFL); |
68 | kill (getpid (), SIGQUIT); | |
7be570e7 | 69 | #endif |
c906108c SS |
70 | } |
71 | } | |
72 | #endif | |
73 | ||
7be570e7 JM |
74 | /* Stimulate the internal error mechanism that GDB uses when an |
75 | internal problem is detected. Allows testing of the mechanism. | |
76 | Also useful when the user wants to drop a core file but not exit | |
025bb325 | 77 | GDB. */ |
7be570e7 JM |
78 | |
79 | static void | |
5fed81ff | 80 | maintenance_internal_error (const char *args, int from_tty) |
7be570e7 | 81 | { |
dec43320 AC |
82 | internal_error (__FILE__, __LINE__, "%s", (args == NULL ? "" : args)); |
83 | } | |
84 | ||
85 | /* Stimulate the internal error mechanism that GDB uses when an | |
86 | internal problem is detected. Allows testing of the mechanism. | |
87 | Also useful when the user wants to drop a core file but not exit | |
025bb325 | 88 | GDB. */ |
dec43320 AC |
89 | |
90 | static void | |
5fed81ff | 91 | maintenance_internal_warning (const char *args, int from_tty) |
dec43320 AC |
92 | { |
93 | internal_warning (__FILE__, __LINE__, "%s", (args == NULL ? "" : args)); | |
7be570e7 JM |
94 | } |
95 | ||
57fcfb1b GB |
96 | /* Stimulate the internal error mechanism that GDB uses when an |
97 | demangler problem is detected. Allows testing of the mechanism. */ | |
98 | ||
99 | static void | |
5fed81ff | 100 | maintenance_demangler_warning (const char *args, int from_tty) |
57fcfb1b GB |
101 | { |
102 | demangler_warning (__FILE__, __LINE__, "%s", (args == NULL ? "" : args)); | |
103 | } | |
104 | ||
439250fb DE |
105 | /* Old command to demangle a string. The command has been moved to "demangle". |
106 | It is kept for now because otherwise "mt demangle" gets interpreted as | |
107 | "mt demangler-warning" which artificially creates an internal gdb error. */ | |
c906108c SS |
108 | |
109 | static void | |
58971144 | 110 | maintenance_demangle (const char *args, int from_tty) |
c906108c | 111 | { |
439250fb | 112 | printf_filtered (_("This command has been moved to \"demangle\".\n")); |
c906108c SS |
113 | } |
114 | ||
115 | static void | |
58971144 | 116 | maintenance_time_display (const char *args, int from_tty) |
c906108c | 117 | { |
c906108c | 118 | if (args == NULL || *args == '\0') |
a3f17187 | 119 | printf_unfiltered (_("\"maintenance time\" takes a numeric argument.\n")); |
c906108c | 120 | else |
bd712aed | 121 | set_per_command_time (strtol (args, NULL, 10)); |
c906108c SS |
122 | } |
123 | ||
124 | static void | |
5fed81ff | 125 | maintenance_space_display (const char *args, int from_tty) |
c906108c | 126 | { |
c906108c SS |
127 | if (args == NULL || *args == '\0') |
128 | printf_unfiltered ("\"maintenance space\" takes a numeric argument.\n"); | |
129 | else | |
bd712aed | 130 | set_per_command_space (strtol (args, NULL, 10)); |
c906108c SS |
131 | } |
132 | ||
a532ca62 MS |
133 | /* Mini tokenizing lexer for 'maint info sections' command. */ |
134 | ||
bf3386f0 | 135 | static bool |
473e38f3 | 136 | match_substring (const char *string, const char *substr) |
a532ca62 | 137 | { |
bf3386f0 | 138 | int substr_len = strlen (substr); |
473e38f3 | 139 | const char *tok; |
a532ca62 MS |
140 | |
141 | while ((tok = strstr (string, substr)) != NULL) | |
142 | { | |
025bb325 | 143 | /* Got a partial match. Is it a whole word? */ |
b01d807c MS |
144 | if (tok == string |
145 | || tok[-1] == ' ' | |
146 | || tok[-1] == '\t') | |
a532ca62 | 147 | { |
025bb325 | 148 | /* Token is delimited at the front... */ |
b01d807c MS |
149 | if (tok[substr_len] == ' ' |
150 | || tok[substr_len] == '\t' | |
151 | || tok[substr_len] == '\0') | |
a532ca62 MS |
152 | { |
153 | /* Token is delimited at the rear. Got a whole-word match. */ | |
bf3386f0 | 154 | return true; |
a532ca62 MS |
155 | } |
156 | } | |
157 | /* Token didn't match as a whole word. Advance and try again. */ | |
158 | string = tok + 1; | |
159 | } | |
bf3386f0 | 160 | return false; |
a532ca62 MS |
161 | } |
162 | ||
bf3386f0 AB |
163 | /* Structure holding information about a single bfd section flag. This is |
164 | used by the "maintenance info sections" command to print the sections, | |
165 | and for filtering which sections are printed. */ | |
166 | ||
167 | struct single_bfd_flag_info | |
168 | { | |
169 | /* The name of the section. This is what is printed for the flag, and | |
170 | what the user enter in order to filter by flag. */ | |
171 | const char *name; | |
172 | ||
173 | /* The bfd defined SEC_* flagword value for this flag. */ | |
174 | flagword value; | |
175 | }; | |
176 | ||
177 | /* Vector of all the known bfd flags. */ | |
178 | ||
179 | static const single_bfd_flag_info bfd_flag_info[] = | |
180 | { | |
181 | { "ALLOC", SEC_ALLOC }, | |
182 | { "LOAD", SEC_LOAD }, | |
183 | { "RELOC", SEC_RELOC }, | |
184 | { "READONLY", SEC_READONLY }, | |
185 | { "CODE", SEC_CODE }, | |
186 | { "DATA", SEC_DATA }, | |
187 | { "ROM", SEC_ROM }, | |
188 | { "CONSTRUCTOR", SEC_CONSTRUCTOR }, | |
189 | { "HAS_CONTENTS", SEC_HAS_CONTENTS }, | |
190 | { "NEVER_LOAD", SEC_NEVER_LOAD }, | |
191 | { "COFF_SHARED_LIBRARY", SEC_COFF_SHARED_LIBRARY }, | |
192 | { "IS_COMMON", SEC_IS_COMMON } | |
193 | }; | |
194 | ||
195 | /* For each flag in the global BFD_FLAG_INFO list, if FLAGS has a flag's | |
196 | flagword value set, and STRING contains the flag's name then return | |
197 | true, otherwise return false. STRING is never nullptr. */ | |
198 | ||
199 | static bool | |
fc4baa5e | 200 | match_bfd_flags (const char *string, flagword flags) |
c906108c | 201 | { |
bf3386f0 AB |
202 | gdb_assert (string != nullptr); |
203 | ||
204 | for (const auto &f : bfd_flag_info) | |
205 | { | |
206 | if (flags & f.value | |
207 | && match_substring (string, f.name)) | |
208 | return true; | |
209 | } | |
210 | ||
211 | return false; | |
43155bc1 | 212 | } |
c906108c | 213 | |
bf3386f0 AB |
214 | /* Print the names of all flags set in FLAGS. The names are taken from the |
215 | BFD_FLAG_INFO global. */ | |
216 | ||
43155bc1 MS |
217 | static void |
218 | print_bfd_flags (flagword flags) | |
219 | { | |
bf3386f0 AB |
220 | for (const auto &f : bfd_flag_info) |
221 | { | |
222 | if (flags & f.value) | |
223 | printf_filtered (" %s", f.name); | |
224 | } | |
43155bc1 MS |
225 | } |
226 | ||
227 | static void | |
bf3386f0 AB |
228 | maint_print_section_info (const char *name, flagword flags, |
229 | CORE_ADDR addr, CORE_ADDR endaddr, | |
5af949e3 | 230 | unsigned long filepos, int addr_size) |
43155bc1 | 231 | { |
5af949e3 UW |
232 | printf_filtered (" %s", hex_string_custom (addr, addr_size)); |
233 | printf_filtered ("->%s", hex_string_custom (endaddr, addr_size)); | |
3ab13650 | 234 | printf_filtered (" at %s", |
bb599908 | 235 | hex_string_custom ((unsigned long) filepos, 8)); |
e3d3bfda MS |
236 | printf_filtered (": %s", name); |
237 | print_bfd_flags (flags); | |
238 | printf_filtered ("\n"); | |
239 | } | |
c906108c | 240 | |
c5065df0 SM |
241 | /* Return the number of digits required to display COUNT in decimal. |
242 | ||
243 | Used when pretty printing index numbers to ensure all of the indexes line | |
244 | up.*/ | |
245 | ||
246 | static int | |
247 | index_digits (int count) | |
aa17805f | 248 | { |
c5065df0 SM |
249 | return ((int) log10 ((float) count)) + 1; |
250 | } | |
aa17805f AB |
251 | |
252 | /* Helper function to pretty-print the section index of ASECT from ABFD. | |
253 | The INDEX_DIGITS is the number of digits in the largest index that will | |
254 | be printed, and is used to pretty-print the resulting string. */ | |
255 | ||
256 | static void | |
257 | print_section_index (bfd *abfd, | |
258 | asection *asect, | |
259 | int index_digits) | |
260 | { | |
261 | std::string result | |
262 | = string_printf (" [%d] ", gdb_bfd_section_index (abfd, asect)); | |
263 | /* The '+ 4' for the leading and trailing characters. */ | |
264 | printf_filtered ("%-*s", (index_digits + 4), result.c_str ()); | |
265 | } | |
266 | ||
b886559f SM |
267 | /* Print information about ASECT from ABFD. The section will be printed using |
268 | the VMA's from the bfd, which will not be the relocated addresses for bfds | |
269 | that should be relocated. The information must be printed with the same | |
c5065df0 SM |
270 | layout as PRINT_OBJFILE_SECTION_INFO below. |
271 | ||
272 | ARG is the argument string passed by the user to the top level maintenance | |
273 | info sections command. Used for filtering which sections are printed. */ | |
aa17805f | 274 | |
e3d3bfda | 275 | static void |
c5065df0 SM |
276 | print_bfd_section_info (bfd *abfd, asection *asect, const char *arg, |
277 | int index_digits) | |
e3d3bfda | 278 | { |
fd361982 AM |
279 | flagword flags = bfd_section_flags (asect); |
280 | const char *name = bfd_section_name (asect); | |
e3d3bfda | 281 | |
fc4baa5e TT |
282 | if (arg == NULL || *arg == '\0' |
283 | || match_substring (arg, name) | |
284 | || match_bfd_flags (arg, flags)) | |
e3d3bfda | 285 | { |
5af949e3 UW |
286 | struct gdbarch *gdbarch = gdbarch_from_bfd (abfd); |
287 | int addr_size = gdbarch_addr_bit (gdbarch) / 8; | |
e3d3bfda MS |
288 | CORE_ADDR addr, endaddr; |
289 | ||
fd361982 AM |
290 | addr = bfd_section_vma (asect); |
291 | endaddr = addr + bfd_section_size (asect); | |
c5065df0 | 292 | print_section_index (abfd, asect, index_digits); |
5af949e3 UW |
293 | maint_print_section_info (name, flags, addr, endaddr, |
294 | asect->filepos, addr_size); | |
e3d3bfda MS |
295 | } |
296 | } | |
297 | ||
aa17805f AB |
298 | /* Print information about ASECT which is GDB's wrapper around a section |
299 | from ABFD. The information must be printed with the same layout as | |
300 | PRINT_BFD_SECTION_INFO above. PRINT_DATA holds information used to | |
c5065df0 SM |
301 | filter which sections are printed, and for formatting the output. |
302 | ||
303 | ARG is the argument string passed by the user to the top level maintenance | |
304 | info sections command. Used for filtering which sections are printed. */ | |
aa17805f | 305 | |
e3d3bfda | 306 | static void |
c5065df0 SM |
307 | print_objfile_section_info (bfd *abfd, struct obj_section *asect, |
308 | const char *arg, int index_digits) | |
e3d3bfda | 309 | { |
fd361982 AM |
310 | flagword flags = bfd_section_flags (asect->the_bfd_section); |
311 | const char *name = bfd_section_name (asect->the_bfd_section); | |
43155bc1 | 312 | |
c5065df0 SM |
313 | if (arg == NULL || *arg == '\0' |
314 | || match_substring (arg, name) | |
315 | || match_bfd_flags (arg, flags)) | |
43155bc1 | 316 | { |
5af949e3 UW |
317 | struct gdbarch *gdbarch = gdbarch_from_bfd (abfd); |
318 | int addr_size = gdbarch_addr_bit (gdbarch) / 8; | |
b8d56208 | 319 | |
c5065df0 | 320 | print_section_index (abfd, asect->the_bfd_section, index_digits); |
f1f6aadf PA |
321 | maint_print_section_info (name, flags, |
322 | obj_section_addr (asect), | |
323 | obj_section_endaddr (asect), | |
5af949e3 UW |
324 | asect->the_bfd_section->filepos, |
325 | addr_size); | |
43155bc1 | 326 | } |
c906108c SS |
327 | } |
328 | ||
aa17805f AB |
329 | /* Find an obj_section, GDB's wrapper around a bfd section for ASECTION |
330 | from ABFD. It might be that no such wrapper exists (for example debug | |
331 | sections don't have such wrappers) in which case nullptr is returned. */ | |
332 | ||
333 | static obj_section * | |
334 | maint_obj_section_from_bfd_section (bfd *abfd, | |
335 | asection *asection, | |
336 | objfile *ofile) | |
337 | { | |
338 | if (ofile->sections == nullptr) | |
339 | return nullptr; | |
340 | ||
341 | obj_section *osect | |
342 | = &ofile->sections[gdb_bfd_section_index (abfd, asection)]; | |
343 | ||
344 | if (osect >= ofile->sections_end) | |
345 | return nullptr; | |
346 | ||
347 | return osect; | |
348 | } | |
349 | ||
4790db14 AB |
350 | /* Print information about all sections from ABFD, which is the bfd |
351 | corresponding to OBJFILE. It is fine for OBJFILE to be nullptr, but | |
352 | ABFD must never be nullptr. If OBJFILE is provided then the sections of | |
353 | ABFD will (potentially) be displayed relocated (i.e. the object file was | |
354 | loaded with add-symbol-file and custom offsets were provided). | |
c5065df0 | 355 | |
4790db14 AB |
356 | HEADER is a string that describes this file, e.g. 'Exec file: ', or |
357 | 'Core file: '. | |
358 | ||
359 | ARG is a string used for filtering which sections are printed, this can | |
360 | be nullptr for no filtering. See the top level 'maint info sections' | |
361 | for a fuller description of the possible filtering strings. */ | |
aa17805f AB |
362 | |
363 | static void | |
4790db14 AB |
364 | maint_print_all_sections (const char *header, bfd *abfd, objfile *objfile, |
365 | const char *arg) | |
aa17805f | 366 | { |
4790db14 AB |
367 | puts_filtered (header); |
368 | wrap_here (" "); | |
369 | printf_filtered ("`%s', ", bfd_get_filename (abfd)); | |
370 | wrap_here (" "); | |
371 | printf_filtered (_("file type %s.\n"), bfd_get_target (abfd)); | |
aa17805f | 372 | |
4790db14 AB |
373 | int section_count = gdb_bfd_count_sections (abfd); |
374 | int digits = index_digits (section_count); | |
375 | ||
376 | for (asection *sect : gdb_bfd_sections (abfd)) | |
377 | { | |
378 | obj_section *osect = nullptr; | |
379 | ||
380 | if (objfile != nullptr) | |
381 | { | |
382 | gdb_assert (objfile->sections != nullptr); | |
383 | osect | |
384 | = maint_obj_section_from_bfd_section (abfd, sect, objfile); | |
385 | if (osect->the_bfd_section == nullptr) | |
386 | osect = nullptr; | |
387 | } | |
388 | ||
389 | if (osect == nullptr) | |
390 | print_bfd_section_info (abfd, sect, arg, digits); | |
391 | else | |
392 | print_objfile_section_info (abfd, osect, arg, digits); | |
393 | } | |
aa17805f AB |
394 | } |
395 | ||
bf3386f0 AB |
396 | /* The options for the "maintenance info sections" command. */ |
397 | ||
398 | struct maint_info_sections_opts | |
399 | { | |
400 | /* For "-all-objects". */ | |
401 | bool all_objects = false; | |
402 | }; | |
403 | ||
404 | static const gdb::option::option_def maint_info_sections_option_defs[] = { | |
405 | ||
406 | gdb::option::flag_option_def<maint_info_sections_opts> { | |
407 | "all-objects", | |
408 | [] (maint_info_sections_opts *opts) { return &opts->all_objects; }, | |
409 | N_("Display information from all loaded object files."), | |
410 | }, | |
411 | }; | |
412 | ||
413 | /* Create an option_def_group for the "maintenance info sections" options, | |
414 | with CC_OPTS as context. */ | |
415 | ||
416 | static inline gdb::option::option_def_group | |
417 | make_maint_info_sections_options_def_group (maint_info_sections_opts *cc_opts) | |
418 | { | |
419 | return {{maint_info_sections_option_defs}, cc_opts}; | |
420 | } | |
421 | ||
422 | /* Completion for the "maintenance info sections" command. */ | |
423 | ||
424 | static void | |
425 | maint_info_sections_completer (struct cmd_list_element *cmd, | |
426 | completion_tracker &tracker, | |
427 | const char *text, const char * /* word */) | |
428 | { | |
429 | /* Complete command options. */ | |
430 | const auto group = make_maint_info_sections_options_def_group (nullptr); | |
431 | if (gdb::option::complete_options | |
432 | (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group)) | |
433 | return; | |
434 | const char *word = advance_to_expression_complete_word_point (tracker, text); | |
435 | ||
436 | /* Offer completion for section flags, but not section names. This is | |
437 | only a maintenance command after all, no point going over the top. */ | |
438 | std::vector<const char *> flags; | |
439 | for (const auto &f : bfd_flag_info) | |
440 | flags.push_back (f.name); | |
441 | flags.push_back (nullptr); | |
442 | complete_on_enum (tracker, flags.data (), text, word); | |
443 | } | |
444 | ||
aa17805f AB |
445 | /* Implement the "maintenance info sections" command. */ |
446 | ||
c906108c | 447 | static void |
58971144 | 448 | maintenance_info_sections (const char *arg, int from_tty) |
c906108c | 449 | { |
bf3386f0 AB |
450 | /* Check if the "-all-objects" flag was passed. */ |
451 | maint_info_sections_opts opts; | |
452 | const auto group = make_maint_info_sections_options_def_group (&opts); | |
453 | gdb::option::process_options | |
454 | (&arg, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group); | |
c906108c | 455 | |
4790db14 | 456 | for (objfile *ofile : current_program_space->objfiles ()) |
c906108c | 457 | { |
4790db14 AB |
458 | if (ofile->obfd == current_program_space->exec_bfd ()) |
459 | maint_print_all_sections (_("Exec file: "), ofile->obfd, ofile, arg); | |
bf3386f0 | 460 | else if (opts.all_objects) |
4790db14 | 461 | maint_print_all_sections (_("Object file: "), ofile->obfd, ofile, arg); |
c906108c | 462 | } |
4790db14 AB |
463 | |
464 | if (core_bfd) | |
465 | maint_print_all_sections (_("Core file: "), core_bfd, nullptr, arg); | |
c906108c SS |
466 | } |
467 | ||
02a79309 AB |
468 | /* Implement the "maintenance info target-sections" command. */ |
469 | ||
470 | static void | |
471 | maintenance_info_target_sections (const char *arg, int from_tty) | |
472 | { | |
473 | bfd *abfd = nullptr; | |
474 | int digits = 0; | |
475 | const target_section_table *table | |
328d42d8 | 476 | = target_get_section_table (current_inferior ()->top_target ()); |
02a79309 AB |
477 | if (table == nullptr) |
478 | return; | |
479 | ||
480 | for (const target_section &sec : *table) | |
481 | { | |
482 | if (abfd == nullptr || sec.the_bfd_section->owner != abfd) | |
483 | { | |
484 | abfd = sec.the_bfd_section->owner; | |
485 | digits = std::max (index_digits (gdb_bfd_count_sections (abfd)), | |
486 | digits); | |
487 | } | |
488 | } | |
489 | ||
490 | struct gdbarch *gdbarch = nullptr; | |
491 | int addr_size = 0; | |
492 | abfd = nullptr; | |
493 | for (const target_section &sec : *table) | |
494 | { | |
495 | if (sec.the_bfd_section->owner != abfd) | |
496 | { | |
497 | abfd = sec.the_bfd_section->owner; | |
498 | gdbarch = gdbarch_from_bfd (abfd); | |
499 | addr_size = gdbarch_addr_bit (gdbarch) / 8; | |
500 | ||
501 | printf_filtered (_("From '%s', file type %s:\n"), | |
502 | bfd_get_filename (abfd), bfd_get_target (abfd)); | |
503 | } | |
504 | print_bfd_section_info (abfd, | |
505 | sec.the_bfd_section, | |
506 | nullptr, | |
507 | digits); | |
508 | /* The magic '8 + digits' here ensures that the 'Start' is aligned | |
509 | with the output of print_bfd_section_info. */ | |
510 | printf_filtered ("%*sStart: %s, End: %s, Owner token: %p\n", | |
511 | (8 + digits), "", | |
512 | hex_string_custom (sec.addr, addr_size), | |
513 | hex_string_custom (sec.endaddr, addr_size), | |
514 | sec.owner); | |
515 | } | |
516 | } | |
517 | ||
025cfdb2 | 518 | static void |
58971144 | 519 | maintenance_print_statistics (const char *args, int from_tty) |
c906108c SS |
520 | { |
521 | print_objfile_statistics (); | |
c906108c SS |
522 | } |
523 | ||
b9362cc7 | 524 | static void |
5fed81ff | 525 | maintenance_print_architecture (const char *args, int from_tty) |
4b9b3959 | 526 | { |
e17c207e UW |
527 | struct gdbarch *gdbarch = get_current_arch (); |
528 | ||
4b9b3959 | 529 | if (args == NULL) |
e17c207e | 530 | gdbarch_dump (gdbarch, gdb_stdout); |
4b9b3959 AC |
531 | else |
532 | { | |
d7e74731 | 533 | stdio_file file; |
b8d56208 | 534 | |
d7e74731 | 535 | if (!file.open (args, "w")) |
e2e0b3e5 | 536 | perror_with_name (_("maintenance print architecture")); |
d7e74731 | 537 | gdbarch_dump (gdbarch, &file); |
4b9b3959 AC |
538 | } |
539 | } | |
540 | ||
c906108c SS |
541 | /* The "maintenance translate-address" command converts a section and address |
542 | to a symbol. This can be called in two ways: | |
c5aa993b | 543 | maintenance translate-address <secname> <addr> |
025bb325 | 544 | or maintenance translate-address <addr>. */ |
c906108c SS |
545 | |
546 | static void | |
5fed81ff | 547 | maintenance_translate_address (const char *arg, int from_tty) |
c906108c SS |
548 | { |
549 | CORE_ADDR address; | |
714835d5 | 550 | struct obj_section *sect; |
5fed81ff | 551 | const char *p; |
7cbd4a93 | 552 | struct bound_minimal_symbol sym; |
c906108c SS |
553 | |
554 | if (arg == NULL || *arg == 0) | |
8a3fe4f8 | 555 | error (_("requires argument (address or section + address)")); |
c906108c SS |
556 | |
557 | sect = NULL; | |
558 | p = arg; | |
559 | ||
560 | if (!isdigit (*p)) | |
025bb325 MS |
561 | { /* See if we have a valid section name. */ |
562 | while (*p && !isspace (*p)) /* Find end of section name. */ | |
c906108c | 563 | p++; |
025bb325 | 564 | if (*p == '\000') /* End of command? */ |
65e65158 | 565 | error (_("Need to specify section name and address")); |
5fed81ff TT |
566 | |
567 | int arg_len = p - arg; | |
568 | p = skip_spaces (p + 1); | |
c906108c | 569 | |
2030c079 | 570 | for (objfile *objfile : current_program_space->objfiles ()) |
3b9d3ac2 TT |
571 | ALL_OBJFILE_OSECTIONS (objfile, sect) |
572 | { | |
573 | if (strncmp (sect->the_bfd_section->name, arg, arg_len) == 0) | |
574 | goto found; | |
575 | } | |
c906108c | 576 | |
3b9d3ac2 TT |
577 | error (_("Unknown section %s."), arg); |
578 | found: ; | |
c906108c SS |
579 | } |
580 | ||
581 | address = parse_and_eval_address (p); | |
582 | ||
583 | if (sect) | |
584 | sym = lookup_minimal_symbol_by_pc_section (address, sect); | |
585 | else | |
586 | sym = lookup_minimal_symbol_by_pc (address); | |
587 | ||
7cbd4a93 | 588 | if (sym.minsym) |
c14c28ba | 589 | { |
c9d95fa3 | 590 | const char *symbol_name = sym.minsym->print_name (); |
3e43a32a | 591 | const char *symbol_offset |
77e371c0 | 592 | = pulongest (address - BMSYMBOL_VALUE_ADDRESS (sym)); |
c14c28ba | 593 | |
1db66e34 | 594 | sect = sym.obj_section (); |
c14c28ba PP |
595 | if (sect != NULL) |
596 | { | |
597 | const char *section_name; | |
598 | const char *obj_name; | |
599 | ||
600 | gdb_assert (sect->the_bfd_section && sect->the_bfd_section->name); | |
601 | section_name = sect->the_bfd_section->name; | |
602 | ||
4262abfb JK |
603 | gdb_assert (sect->objfile && objfile_name (sect->objfile)); |
604 | obj_name = objfile_name (sect->objfile); | |
c14c28ba | 605 | |
deeafabb | 606 | if (current_program_space->multi_objfile_p ()) |
c14c28ba | 607 | printf_filtered (_("%s + %s in section %s of %s\n"), |
3e43a32a MS |
608 | symbol_name, symbol_offset, |
609 | section_name, obj_name); | |
c14c28ba PP |
610 | else |
611 | printf_filtered (_("%s + %s in section %s\n"), | |
612 | symbol_name, symbol_offset, section_name); | |
613 | } | |
614 | else | |
615 | printf_filtered (_("%s + %s\n"), symbol_name, symbol_offset); | |
616 | } | |
c906108c | 617 | else if (sect) |
5af949e3 UW |
618 | printf_filtered (_("no symbol at %s:%s\n"), |
619 | sect->the_bfd_section->name, hex_string (address)); | |
c906108c | 620 | else |
5af949e3 | 621 | printf_filtered (_("no symbol at %s\n"), hex_string (address)); |
c906108c SS |
622 | |
623 | return; | |
624 | } | |
625 | ||
56382845 | 626 | |
c114dcd5 | 627 | /* When a command is deprecated the user will be warned the first time |
33f91161 | 628 | the command is used. If possible, a replacement will be |
025bb325 | 629 | offered. */ |
56382845 FN |
630 | |
631 | static void | |
58971144 | 632 | maintenance_deprecate (const char *args, int from_tty) |
56382845 FN |
633 | { |
634 | if (args == NULL || *args == '\0') | |
635 | { | |
cce7e648 PA |
636 | printf_unfiltered (_("\"maintenance deprecate\" takes an argument,\n\ |
637 | the command you want to deprecate, and optionally the replacement command\n\ | |
a3f17187 | 638 | enclosed in quotes.\n")); |
56382845 | 639 | } |
33f91161 | 640 | |
56382845 | 641 | maintenance_do_deprecate (args, 1); |
56382845 FN |
642 | } |
643 | ||
644 | ||
645 | static void | |
58971144 | 646 | maintenance_undeprecate (const char *args, int from_tty) |
56382845 FN |
647 | { |
648 | if (args == NULL || *args == '\0') | |
649 | { | |
a3f17187 AC |
650 | printf_unfiltered (_("\"maintenance undeprecate\" takes an argument, \n\ |
651 | the command you want to undeprecate.\n")); | |
56382845 | 652 | } |
33f91161 | 653 | |
56382845 | 654 | maintenance_do_deprecate (args, 0); |
56382845 FN |
655 | } |
656 | ||
025bb325 | 657 | /* You really shouldn't be using this. It is just for the testsuite. |
33f91161 AC |
658 | Rather, you should use deprecate_cmd() when the command is created |
659 | in _initialize_blah(). | |
660 | ||
661 | This function deprecates a command and optionally assigns it a | |
662 | replacement. */ | |
663 | ||
8399535b | 664 | static void |
58971144 | 665 | maintenance_do_deprecate (const char *text, int deprecate) |
33f91161 | 666 | { |
33f91161 AC |
667 | struct cmd_list_element *alias = NULL; |
668 | struct cmd_list_element *prefix_cmd = NULL; | |
669 | struct cmd_list_element *cmd = NULL; | |
670 | ||
58971144 TT |
671 | const char *start_ptr = NULL; |
672 | const char *end_ptr = NULL; | |
56382845 | 673 | int len; |
33f91161 AC |
674 | char *replacement = NULL; |
675 | ||
1c689132 DB |
676 | if (text == NULL) |
677 | return; | |
56382845 | 678 | |
33f91161 AC |
679 | if (!lookup_cmd_composition (text, &alias, &prefix_cmd, &cmd)) |
680 | { | |
a3f17187 | 681 | printf_filtered (_("Can't find command '%s' to deprecate.\n"), text); |
33f91161 AC |
682 | return; |
683 | } | |
56382845 | 684 | |
56382845 FN |
685 | if (deprecate) |
686 | { | |
025bb325 | 687 | /* Look for a replacement command. */ |
80ce1ecb AC |
688 | start_ptr = strchr (text, '\"'); |
689 | if (start_ptr != NULL) | |
33f91161 AC |
690 | { |
691 | start_ptr++; | |
80ce1ecb AC |
692 | end_ptr = strrchr (start_ptr, '\"'); |
693 | if (end_ptr != NULL) | |
33f91161 AC |
694 | { |
695 | len = end_ptr - start_ptr; | |
58971144 | 696 | replacement = savestring (start_ptr, len); |
33f91161 AC |
697 | } |
698 | } | |
56382845 | 699 | } |
33f91161 | 700 | |
56382845 FN |
701 | if (!start_ptr || !end_ptr) |
702 | replacement = NULL; | |
33f91161 AC |
703 | |
704 | ||
56382845 | 705 | /* If they used an alias, we only want to deprecate the alias. |
33f91161 | 706 | |
56382845 FN |
707 | Note the MALLOCED_REPLACEMENT test. If the command's replacement |
708 | string was allocated at compile time we don't want to free the | |
025bb325 | 709 | memory. */ |
56382845 FN |
710 | if (alias) |
711 | { | |
1f2bdf09 | 712 | if (alias->malloced_replacement) |
429e55ea | 713 | xfree ((char *) alias->replacement); |
33f91161 | 714 | |
56382845 | 715 | if (deprecate) |
1f2bdf09 TT |
716 | { |
717 | alias->deprecated_warn_user = 1; | |
718 | alias->cmd_deprecated = 1; | |
719 | } | |
56382845 | 720 | else |
1f2bdf09 TT |
721 | { |
722 | alias->deprecated_warn_user = 0; | |
723 | alias->cmd_deprecated = 0; | |
724 | } | |
33f91161 | 725 | alias->replacement = replacement; |
1f2bdf09 | 726 | alias->malloced_replacement = 1; |
56382845 FN |
727 | return; |
728 | } | |
729 | else if (cmd) | |
730 | { | |
1f2bdf09 | 731 | if (cmd->malloced_replacement) |
429e55ea | 732 | xfree ((char *) cmd->replacement); |
56382845 FN |
733 | |
734 | if (deprecate) | |
1f2bdf09 TT |
735 | { |
736 | cmd->deprecated_warn_user = 1; | |
737 | cmd->cmd_deprecated = 1; | |
738 | } | |
56382845 | 739 | else |
1f2bdf09 TT |
740 | { |
741 | cmd->deprecated_warn_user = 0; | |
742 | cmd->cmd_deprecated = 0; | |
743 | } | |
33f91161 | 744 | cmd->replacement = replacement; |
1f2bdf09 | 745 | cmd->malloced_replacement = 1; |
56382845 FN |
746 | return; |
747 | } | |
240f9570 | 748 | xfree (replacement); |
56382845 FN |
749 | } |
750 | ||
4f337972 AC |
751 | /* Maintenance set/show framework. */ |
752 | ||
ae038cb0 DJ |
753 | struct cmd_list_element *maintenance_set_cmdlist; |
754 | struct cmd_list_element *maintenance_show_cmdlist; | |
4f337972 | 755 | |
fdbc9870 PA |
756 | /* "maintenance with" command. */ |
757 | ||
758 | static void | |
759 | maintenance_with_cmd (const char *args, int from_tty) | |
760 | { | |
761 | with_command_1 ("maintenance set ", maintenance_set_cmdlist, args, from_tty); | |
762 | } | |
763 | ||
764 | /* "maintenance with" command completer. */ | |
765 | ||
766 | static void | |
767 | maintenance_with_cmd_completer (struct cmd_list_element *ignore, | |
768 | completion_tracker &tracker, | |
769 | const char *text, const char * /*word*/) | |
770 | { | |
771 | with_command_completer_1 ("maintenance set ", tracker, text); | |
772 | } | |
773 | ||
4f337972 AC |
774 | /* Profiling support. */ |
775 | ||
491144b5 | 776 | static bool maintenance_profile_p; |
920d2a44 AC |
777 | static void |
778 | show_maintenance_profile_p (struct ui_file *file, int from_tty, | |
779 | struct cmd_list_element *c, const char *value) | |
780 | { | |
781 | fprintf_filtered (file, _("Internal profiling is %s.\n"), value); | |
782 | } | |
d9feb4e7 | 783 | |
b0b1c2c0 MK |
784 | #ifdef HAVE__ETEXT |
785 | extern char _etext; | |
786 | #define TEXTEND &_etext | |
01fe12f6 | 787 | #elif defined (HAVE_ETEXT) |
b0b1c2c0 MK |
788 | extern char etext; |
789 | #define TEXTEND &etext | |
790 | #endif | |
791 | ||
01fe12f6 JB |
792 | #if defined (HAVE_MONSTARTUP) && defined (HAVE__MCLEANUP) && defined (TEXTEND) |
793 | ||
d28f9cdf DJ |
794 | static int profiling_state; |
795 | ||
56000a98 PA |
796 | EXTERN_C void _mcleanup (void); |
797 | ||
d28f9cdf DJ |
798 | static void |
799 | mcleanup_wrapper (void) | |
800 | { | |
d28f9cdf DJ |
801 | if (profiling_state) |
802 | _mcleanup (); | |
803 | } | |
4f337972 | 804 | |
56000a98 PA |
805 | EXTERN_C void monstartup (unsigned long, unsigned long); |
806 | extern int main (); | |
807 | ||
4f337972 | 808 | static void |
eb4c3f4a | 809 | maintenance_set_profile_cmd (const char *args, int from_tty, |
3e43a32a | 810 | struct cmd_list_element *c) |
4f337972 | 811 | { |
d28f9cdf DJ |
812 | if (maintenance_profile_p == profiling_state) |
813 | return; | |
814 | ||
815 | profiling_state = maintenance_profile_p; | |
816 | ||
817 | if (maintenance_profile_p) | |
818 | { | |
819 | static int profiling_initialized; | |
820 | ||
d28f9cdf DJ |
821 | if (!profiling_initialized) |
822 | { | |
823 | atexit (mcleanup_wrapper); | |
824 | profiling_initialized = 1; | |
825 | } | |
826 | ||
827 | /* "main" is now always the first function in the text segment, so use | |
828 | its address for monstartup. */ | |
b0b1c2c0 | 829 | monstartup ((unsigned long) &main, (unsigned long) TEXTEND); |
d28f9cdf DJ |
830 | } |
831 | else | |
832 | { | |
833 | extern void _mcleanup (void); | |
b8d56208 | 834 | |
d28f9cdf DJ |
835 | _mcleanup (); |
836 | } | |
4f337972 | 837 | } |
d9feb4e7 DJ |
838 | #else |
839 | static void | |
eb4c3f4a | 840 | maintenance_set_profile_cmd (const char *args, int from_tty, |
3e43a32a | 841 | struct cmd_list_element *c) |
d9feb4e7 | 842 | { |
8a3fe4f8 | 843 | error (_("Profiling support is not available on this system.")); |
d9feb4e7 DJ |
844 | } |
845 | #endif | |
22138db6 | 846 | |
f1d293cc | 847 | static int n_worker_threads = -1; |
22138db6 TT |
848 | |
849 | /* Update the thread pool for the desired number of threads. */ | |
850 | static void | |
851 | update_thread_pool_size () | |
852 | { | |
853 | #if CXX_STD_THREAD | |
854 | int n_threads = n_worker_threads; | |
855 | ||
856 | if (n_threads < 0) | |
857 | n_threads = std::thread::hardware_concurrency (); | |
858 | ||
859 | gdb::thread_pool::g_thread_pool->set_thread_count (n_threads); | |
860 | #endif | |
861 | } | |
862 | ||
863 | static void | |
864 | maintenance_set_worker_threads (const char *args, int from_tty, | |
865 | struct cmd_list_element *c) | |
866 | { | |
867 | update_thread_pool_size (); | |
868 | } | |
869 | ||
bd712aed | 870 | \f |
491144b5 | 871 | /* If true, display time usage both at startup and for each command. */ |
56382845 | 872 | |
491144b5 | 873 | static bool per_command_time; |
bd712aed | 874 | |
491144b5 | 875 | /* If true, display space usage both at startup and for each command. */ |
bd712aed | 876 | |
491144b5 | 877 | static bool per_command_space; |
bd712aed | 878 | |
491144b5 | 879 | /* If true, display basic symtab stats for each command. */ |
bd712aed | 880 | |
491144b5 | 881 | static bool per_command_symtab; |
bd712aed DE |
882 | |
883 | /* mt per-command commands. */ | |
884 | ||
885 | static struct cmd_list_element *per_command_setlist; | |
886 | static struct cmd_list_element *per_command_showlist; | |
887 | ||
bd712aed DE |
888 | /* Set whether to display time statistics to NEW_VALUE |
889 | (non-zero means true). */ | |
890 | ||
891 | void | |
892 | set_per_command_time (int new_value) | |
893 | { | |
894 | per_command_time = new_value; | |
895 | } | |
896 | ||
897 | /* Set whether to display space statistics to NEW_VALUE | |
898 | (non-zero means true). */ | |
899 | ||
900 | void | |
901 | set_per_command_space (int new_value) | |
902 | { | |
903 | per_command_space = new_value; | |
904 | } | |
905 | ||
906 | /* Count the number of symtabs and blocks. */ | |
907 | ||
908 | static void | |
43f3e411 | 909 | count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr, |
bd712aed DE |
910 | int *nr_blocks_ptr) |
911 | { | |
bd712aed | 912 | int nr_symtabs = 0; |
43f3e411 | 913 | int nr_compunit_symtabs = 0; |
bd712aed DE |
914 | int nr_blocks = 0; |
915 | ||
b8b8facf DE |
916 | /* When collecting statistics during startup, this is called before |
917 | pretty much anything in gdb has been initialized, and thus | |
918 | current_program_space may be NULL. */ | |
919 | if (current_program_space != NULL) | |
bd712aed | 920 | { |
2030c079 | 921 | for (objfile *o : current_program_space->objfiles ()) |
bd712aed | 922 | { |
b669c953 | 923 | for (compunit_symtab *cu : o->compunits ()) |
d8aeb77f TT |
924 | { |
925 | ++nr_compunit_symtabs; | |
926 | nr_blocks += BLOCKVECTOR_NBLOCKS (COMPUNIT_BLOCKVECTOR (cu)); | |
5accd1a0 TT |
927 | nr_symtabs += std::distance (compunit_filetabs (cu).begin (), |
928 | compunit_filetabs (cu).end ()); | |
d8aeb77f | 929 | } |
bd712aed DE |
930 | } |
931 | } | |
932 | ||
933 | *nr_symtabs_ptr = nr_symtabs; | |
43f3e411 | 934 | *nr_compunit_symtabs_ptr = nr_compunit_symtabs; |
bd712aed DE |
935 | *nr_blocks_ptr = nr_blocks; |
936 | } | |
937 | ||
1e3b796d TT |
938 | /* As indicated by display_time and display_space, report GDB's |
939 | elapsed time and space usage from the base time and space recorded | |
940 | in this object. */ | |
bd712aed | 941 | |
1e3b796d | 942 | scoped_command_stats::~scoped_command_stats () |
bd712aed | 943 | { |
1e3b796d TT |
944 | /* Early exit if we're not reporting any stats. It can be expensive to |
945 | compute the pre-command values so don't collect them at all if we're | |
946 | not reporting stats. Alas this doesn't work in the startup case because | |
947 | we don't know yet whether we will be reporting the stats. For the | |
948 | startup case collect the data anyway (it should be cheap at this point), | |
949 | and leave it to the reporter to decide whether to print them. */ | |
950 | if (m_msg_type | |
951 | && !per_command_time | |
952 | && !per_command_space | |
953 | && !per_command_symtab) | |
954 | return; | |
bd712aed | 955 | |
1e3b796d | 956 | if (m_time_enabled && per_command_time) |
bd712aed | 957 | { |
3847a7bf TT |
958 | print_time (_("command finished")); |
959 | ||
dcb07cfa | 960 | using namespace std::chrono; |
bd712aed | 961 | |
dcb07cfa PA |
962 | run_time_clock::duration cmd_time |
963 | = run_time_clock::now () - m_start_cpu_time; | |
bd712aed | 964 | |
dcb07cfa PA |
965 | steady_clock::duration wall_time |
966 | = steady_clock::now () - m_start_wall_time; | |
bd712aed | 967 | /* Subtract time spend in prompt_for_continue from walltime. */ |
dcb07cfa | 968 | wall_time -= get_prompt_for_continue_wait_time (); |
bd712aed | 969 | |
1e3b796d | 970 | printf_unfiltered (!m_msg_type |
dcb07cfa PA |
971 | ? _("Startup time: %.6f (cpu), %.6f (wall)\n") |
972 | : _("Command execution time: %.6f (cpu), %.6f (wall)\n"), | |
973 | duration<double> (cmd_time).count (), | |
974 | duration<double> (wall_time).count ()); | |
bd712aed DE |
975 | } |
976 | ||
1e3b796d | 977 | if (m_space_enabled && per_command_space) |
bd712aed | 978 | { |
6242c6a6 | 979 | #ifdef HAVE_USEFUL_SBRK |
bd712aed DE |
980 | char *lim = (char *) sbrk (0); |
981 | ||
982 | long space_now = lim - lim_at_start; | |
1e3b796d | 983 | long space_diff = space_now - m_start_space; |
bd712aed | 984 | |
1e3b796d | 985 | printf_unfiltered (!m_msg_type |
bd712aed DE |
986 | ? _("Space used: %ld (%s%ld during startup)\n") |
987 | : _("Space used: %ld (%s%ld for this command)\n"), | |
988 | space_now, | |
989 | (space_diff >= 0 ? "+" : ""), | |
990 | space_diff); | |
991 | #endif | |
992 | } | |
993 | ||
1e3b796d | 994 | if (m_symtab_enabled && per_command_symtab) |
bd712aed | 995 | { |
43f3e411 | 996 | int nr_symtabs, nr_compunit_symtabs, nr_blocks; |
bd712aed | 997 | |
43f3e411 | 998 | count_symtabs_and_blocks (&nr_symtabs, &nr_compunit_symtabs, &nr_blocks); |
bd712aed | 999 | printf_unfiltered (_("#symtabs: %d (+%d)," |
43f3e411 | 1000 | " #compunits: %d (+%d)," |
bd712aed DE |
1001 | " #blocks: %d (+%d)\n"), |
1002 | nr_symtabs, | |
1e3b796d | 1003 | nr_symtabs - m_start_nr_symtabs, |
43f3e411 DE |
1004 | nr_compunit_symtabs, |
1005 | (nr_compunit_symtabs | |
1e3b796d | 1006 | - m_start_nr_compunit_symtabs), |
bd712aed | 1007 | nr_blocks, |
1e3b796d | 1008 | nr_blocks - m_start_nr_blocks); |
bd712aed DE |
1009 | } |
1010 | } | |
1011 | ||
1e3b796d TT |
1012 | scoped_command_stats::scoped_command_stats (bool msg_type) |
1013 | : m_msg_type (msg_type) | |
bd712aed | 1014 | { |
1e3b796d | 1015 | if (!m_msg_type || per_command_space) |
bd712aed | 1016 | { |
6242c6a6 | 1017 | #ifdef HAVE_USEFUL_SBRK |
bd712aed | 1018 | char *lim = (char *) sbrk (0); |
1e3b796d TT |
1019 | m_start_space = lim - lim_at_start; |
1020 | m_space_enabled = 1; | |
bd712aed DE |
1021 | #endif |
1022 | } | |
44d83468 PA |
1023 | else |
1024 | m_space_enabled = 0; | |
bd712aed | 1025 | |
b8b8facf | 1026 | if (msg_type == 0 || per_command_time) |
bd712aed | 1027 | { |
dcb07cfa PA |
1028 | using namespace std::chrono; |
1029 | ||
1030 | m_start_cpu_time = run_time_clock::now (); | |
1031 | m_start_wall_time = steady_clock::now (); | |
1e3b796d | 1032 | m_time_enabled = 1; |
3847a7bf TT |
1033 | |
1034 | if (per_command_time) | |
1035 | print_time (_("command started")); | |
bd712aed | 1036 | } |
44d83468 PA |
1037 | else |
1038 | m_time_enabled = 0; | |
bd712aed | 1039 | |
b8b8facf | 1040 | if (msg_type == 0 || per_command_symtab) |
bd712aed | 1041 | { |
43f3e411 | 1042 | int nr_symtabs, nr_compunit_symtabs, nr_blocks; |
bd712aed | 1043 | |
43f3e411 | 1044 | count_symtabs_and_blocks (&nr_symtabs, &nr_compunit_symtabs, &nr_blocks); |
1e3b796d TT |
1045 | m_start_nr_symtabs = nr_symtabs; |
1046 | m_start_nr_compunit_symtabs = nr_compunit_symtabs; | |
1047 | m_start_nr_blocks = nr_blocks; | |
1048 | m_symtab_enabled = 1; | |
bd712aed | 1049 | } |
44d83468 PA |
1050 | else |
1051 | m_symtab_enabled = 0; | |
bd712aed | 1052 | |
26c4b26f | 1053 | /* Initialize timer to keep track of how long we waited for the user. */ |
bd712aed | 1054 | reset_prompt_for_continue_wait_time (); |
bd712aed DE |
1055 | } |
1056 | ||
3847a7bf TT |
1057 | /* See maint.h. */ |
1058 | ||
1059 | void | |
1060 | scoped_command_stats::print_time (const char *msg) | |
1061 | { | |
1062 | using namespace std::chrono; | |
1063 | ||
1064 | auto now = system_clock::now (); | |
1065 | auto ticks = now.time_since_epoch ().count () / (1000 * 1000); | |
1066 | auto millis = ticks % 1000; | |
1067 | ||
1068 | std::time_t as_time = system_clock::to_time_t (now); | |
53fea9c7 CB |
1069 | struct tm tm; |
1070 | localtime_r (&as_time, &tm); | |
3847a7bf TT |
1071 | |
1072 | char out[100]; | |
53fea9c7 | 1073 | strftime (out, sizeof (out), "%F %H:%M:%S", &tm); |
3847a7bf TT |
1074 | |
1075 | printf_unfiltered ("%s.%03d - %s\n", out, (int) millis, msg); | |
1076 | } | |
1077 | ||
bd712aed DE |
1078 | /* Handle unknown "mt set per-command" arguments. |
1079 | In this case have "mt set per-command on|off" affect every setting. */ | |
1080 | ||
1081 | static void | |
981a3fb3 | 1082 | set_per_command_cmd (const char *args, int from_tty) |
bd712aed DE |
1083 | { |
1084 | struct cmd_list_element *list; | |
bd712aed DE |
1085 | int val; |
1086 | ||
1087 | val = parse_cli_boolean_value (args); | |
1088 | if (val < 0) | |
1089 | error (_("Bad value for 'mt set per-command no'.")); | |
1090 | ||
1091 | for (list = per_command_setlist; list != NULL; list = list->next) | |
1092 | if (list->var_type == var_boolean) | |
1093 | { | |
1094 | gdb_assert (list->type == set_cmd); | |
1095 | do_set_command (args, from_tty, list); | |
1096 | } | |
1097 | } | |
1098 | ||
dcd1f979 TT |
1099 | \f |
1100 | ||
1101 | /* The "maintenance selftest" command. */ | |
1102 | ||
1103 | static void | |
58971144 | 1104 | maintenance_selftest (const char *args, int from_tty) |
dcd1f979 | 1105 | { |
1e5ded6c | 1106 | #if GDB_SELF_TEST |
ece5bc8a | 1107 | gdb_argv argv (args); |
d369b608 | 1108 | selftests::run_tests (argv.as_array_view ()); |
1e5ded6c YQ |
1109 | #else |
1110 | printf_filtered (_("\ | |
8ecfd7bd | 1111 | Selftests have been disabled for this build.\n")); |
1e5ded6c | 1112 | #endif |
1526853e SM |
1113 | } |
1114 | ||
1115 | static void | |
5fed81ff | 1116 | maintenance_info_selftests (const char *arg, int from_tty) |
1526853e | 1117 | { |
1e5ded6c | 1118 | #if GDB_SELF_TEST |
1526853e SM |
1119 | printf_filtered ("Registered selftests:\n"); |
1120 | selftests::for_each_selftest ([] (const std::string &name) { | |
1121 | printf_filtered (" - %s\n", name.c_str ()); | |
1122 | }); | |
1e5ded6c YQ |
1123 | #else |
1124 | printf_filtered (_("\ | |
8ecfd7bd | 1125 | Selftests have been disabled for this build.\n")); |
1e5ded6c | 1126 | #endif |
dcd1f979 TT |
1127 | } |
1128 | ||
bd712aed | 1129 | \f |
6c265988 | 1130 | void _initialize_maint_cmds (); |
c906108c | 1131 | void |
6c265988 | 1132 | _initialize_maint_cmds () |
c906108c | 1133 | { |
439250fb DE |
1134 | struct cmd_list_element *cmd; |
1135 | ||
3947f654 SM |
1136 | cmd_list_element *maintenance_cmd |
1137 | = add_basic_prefix_cmd ("maintenance", class_maintenance, _("\ | |
1bedd215 | 1138 | Commands for use by GDB maintainers.\n\ |
c906108c | 1139 | Includes commands to dump specific internal GDB structures in\n\ |
439250fb | 1140 | a human readable form, to cause GDB to deliberately dump core, etc."), |
3947f654 SM |
1141 | &maintenancelist, 0, |
1142 | &cmdlist); | |
c906108c | 1143 | |
3947f654 | 1144 | add_com_alias ("mt", maintenance_cmd, class_maintenance, 1); |
c906108c | 1145 | |
5e84b7ee SM |
1146 | cmd_list_element *maintenance_info_cmd |
1147 | = add_basic_prefix_cmd ("info", class_maintenance, _("\ | |
1bedd215 | 1148 | Commands for showing internal info about the program being debugged."), |
5e84b7ee SM |
1149 | &maintenanceinfolist, 0, |
1150 | &maintenancelist); | |
1151 | add_alias_cmd ("i", maintenance_info_cmd, class_maintenance, 1, | |
1152 | &maintenancelist); | |
c906108c | 1153 | |
bf3386f0 AB |
1154 | const auto opts = make_maint_info_sections_options_def_group (nullptr); |
1155 | static std::string maint_info_sections_command_help | |
1156 | = gdb::option::build_help (_("\ | |
590042fc | 1157 | List the BFD sections of the exec and core files.\n\ |
bf3386f0 AB |
1158 | \n\ |
1159 | Usage: maintenance info sections [-all-objects] [FILTERS]\n\ | |
1160 | \n\ | |
1161 | FILTERS is a list of words, each word is either:\n\ | |
1162 | + A section name - any section with this name will be printed, or\n\ | |
1163 | + A section flag - any section with this flag will be printed. The\n\ | |
1164 | known flags are:\n\ | |
1165 | ALLOC LOAD RELOC READONLY CODE DATA ROM CONSTRUCTOR\n\ | |
1166 | HAS_CONTENTS NEVER_LOAD COFF_SHARED_LIBRARY IS_COMMON\n\ | |
1167 | \n\ | |
1168 | Sections matching any of the FILTERS will be listed (no FILTERS implies\n\ | |
1169 | all sections should be printed).\n\ | |
1170 | \n\ | |
1171 | Options:\n\ | |
1172 | %OPTIONS%"), opts); | |
1173 | cmd = add_cmd ("sections", class_maintenance, maintenance_info_sections, | |
1174 | maint_info_sections_command_help.c_str (), | |
1175 | &maintenanceinfolist); | |
1176 | set_cmd_completer_handle_brkchars (cmd, maint_info_sections_completer); | |
c906108c | 1177 | |
02a79309 AB |
1178 | add_cmd ("target-sections", class_maintenance, |
1179 | maintenance_info_target_sections, _("\ | |
1180 | List GDB's internal section table.\n\ | |
1181 | \n\ | |
1182 | Print the current targets section list. This is a sub-set of all\n\ | |
1183 | sections, from all objects currently loaded. Usually the ALLOC\n\ | |
1184 | sectoins."), | |
1185 | &maintenanceinfolist); | |
1186 | ||
0743fc83 TT |
1187 | add_basic_prefix_cmd ("print", class_maintenance, |
1188 | _("Maintenance command for printing GDB internal state."), | |
2f822da5 | 1189 | &maintenanceprintlist, 0, |
0743fc83 | 1190 | &maintenancelist); |
c906108c | 1191 | |
50a5f187 AB |
1192 | add_basic_prefix_cmd ("flush", class_maintenance, |
1193 | _("Maintenance command for flushing GDB internal caches."), | |
2f822da5 | 1194 | &maintenanceflushlist, 0, |
50a5f187 AB |
1195 | &maintenancelist); |
1196 | ||
0743fc83 | 1197 | add_basic_prefix_cmd ("set", class_maintenance, _("\ |
4f337972 | 1198 | Set GDB internal variables used by the GDB maintainer.\n\ |
1bedd215 | 1199 | Configure variables internal to GDB that aid in GDB's maintenance"), |
2f822da5 | 1200 | &maintenance_set_cmdlist, |
0743fc83 TT |
1201 | 0/*allow-unknown*/, |
1202 | &maintenancelist); | |
4f337972 | 1203 | |
0743fc83 | 1204 | add_show_prefix_cmd ("show", class_maintenance, _("\ |
4f337972 | 1205 | Show GDB internal variables used by the GDB maintainer.\n\ |
1bedd215 | 1206 | Configure variables internal to GDB that aid in GDB's maintenance"), |
2f822da5 | 1207 | &maintenance_show_cmdlist, |
0743fc83 TT |
1208 | 0/*allow-unknown*/, |
1209 | &maintenancelist); | |
4f337972 | 1210 | |
fdbc9870 PA |
1211 | cmd = add_cmd ("with", class_maintenance, maintenance_with_cmd, _("\ |
1212 | Like \"with\", but works with \"maintenance set\" variables.\n\ | |
1213 | Usage: maintenance with SETTING [VALUE] [-- COMMAND]\n\ | |
1214 | With no COMMAND, repeats the last executed command.\n\ | |
1215 | SETTING is any setting you can change with the \"maintenance set\"\n\ | |
1216 | subcommands."), | |
1217 | &maintenancelist); | |
1218 | set_cmd_completer_handle_brkchars (cmd, maintenance_with_cmd_completer); | |
1219 | ||
c906108c | 1220 | #ifndef _WIN32 |
1a966eab AC |
1221 | add_cmd ("dump-me", class_maintenance, maintenance_dump_me, _("\ |
1222 | Get fatal error; make debugger dump its core.\n\ | |
8308e54c | 1223 | GDB sets its handling of SIGQUIT back to SIG_DFL and then sends\n\ |
1a966eab | 1224 | itself a SIGQUIT signal."), |
c906108c SS |
1225 | &maintenancelist); |
1226 | #endif | |
1227 | ||
1a966eab AC |
1228 | add_cmd ("internal-error", class_maintenance, |
1229 | maintenance_internal_error, _("\ | |
1230 | Give GDB an internal error.\n\ | |
1231 | Cause GDB to behave as if an internal error was detected."), | |
7be570e7 JM |
1232 | &maintenancelist); |
1233 | ||
1a966eab AC |
1234 | add_cmd ("internal-warning", class_maintenance, |
1235 | maintenance_internal_warning, _("\ | |
1236 | Give GDB an internal warning.\n\ | |
1237 | Cause GDB to behave as if an internal warning was reported."), | |
dec43320 AC |
1238 | &maintenancelist); |
1239 | ||
57fcfb1b GB |
1240 | add_cmd ("demangler-warning", class_maintenance, |
1241 | maintenance_demangler_warning, _("\ | |
1242 | Give GDB a demangler warning.\n\ | |
1243 | Cause GDB to behave as if a demangler warning was reported."), | |
1244 | &maintenancelist); | |
1245 | ||
439250fb DE |
1246 | cmd = add_cmd ("demangle", class_maintenance, maintenance_demangle, _("\ |
1247 | This command has been moved to \"demangle\"."), | |
1248 | &maintenancelist); | |
1249 | deprecate_cmd (cmd, "demangle"); | |
c906108c | 1250 | |
bd712aed DE |
1251 | add_prefix_cmd ("per-command", class_maintenance, set_per_command_cmd, _("\ |
1252 | Per-command statistics settings."), | |
2f822da5 | 1253 | &per_command_setlist, |
bd712aed DE |
1254 | 1/*allow-unknown*/, &maintenance_set_cmdlist); |
1255 | ||
0743fc83 | 1256 | add_show_prefix_cmd ("per-command", class_maintenance, _("\ |
bd712aed | 1257 | Show per-command statistics settings."), |
2f822da5 | 1258 | &per_command_showlist, |
0743fc83 | 1259 | 0/*allow-unknown*/, &maintenance_show_cmdlist); |
bd712aed DE |
1260 | |
1261 | add_setshow_boolean_cmd ("time", class_maintenance, | |
1262 | &per_command_time, _("\ | |
1263 | Set whether to display per-command execution time."), _("\ | |
1264 | Show whether to display per-command execution time."), | |
1265 | _("\ | |
1266 | If enabled, the execution time for each command will be\n\ | |
1267 | displayed following the command's output."), | |
1268 | NULL, NULL, | |
1269 | &per_command_setlist, &per_command_showlist); | |
1270 | ||
1271 | add_setshow_boolean_cmd ("space", class_maintenance, | |
1272 | &per_command_space, _("\ | |
1273 | Set whether to display per-command space usage."), _("\ | |
1274 | Show whether to display per-command space usage."), | |
1275 | _("\ | |
1276 | If enabled, the space usage for each command will be\n\ | |
1277 | displayed following the command's output."), | |
1278 | NULL, NULL, | |
1279 | &per_command_setlist, &per_command_showlist); | |
1280 | ||
1281 | add_setshow_boolean_cmd ("symtab", class_maintenance, | |
1282 | &per_command_symtab, _("\ | |
1283 | Set whether to display per-command symtab statistics."), _("\ | |
1284 | Show whether to display per-command symtab statistics."), | |
1285 | _("\ | |
1286 | If enabled, the basic symtab statistics for each command will be\n\ | |
1287 | displayed following the command's output."), | |
1288 | NULL, NULL, | |
1289 | &per_command_setlist, &per_command_showlist); | |
1290 | ||
1291 | /* This is equivalent to "mt set per-command time on". | |
1292 | Kept because some people are used to typing "mt time 1". */ | |
1a966eab AC |
1293 | add_cmd ("time", class_maintenance, maintenance_time_display, _("\ |
1294 | Set the display of time usage.\n\ | |
c906108c | 1295 | If nonzero, will cause the execution time for each command to be\n\ |
1a966eab | 1296 | displayed, following the command's output."), |
c906108c SS |
1297 | &maintenancelist); |
1298 | ||
bd712aed DE |
1299 | /* This is equivalent to "mt set per-command space on". |
1300 | Kept because some people are used to typing "mt space 1". */ | |
1a966eab AC |
1301 | add_cmd ("space", class_maintenance, maintenance_space_display, _("\ |
1302 | Set the display of space usage.\n\ | |
c906108c | 1303 | If nonzero, will cause the execution space for each command to be\n\ |
1a966eab | 1304 | displayed, following the command's output."), |
c906108c SS |
1305 | &maintenancelist); |
1306 | ||
a4915e8d | 1307 | cmd = add_cmd ("type", class_maintenance, maintenance_print_type, _("\ |
1a966eab | 1308 | Print a type chain for a given symbol.\n\ |
c906108c | 1309 | For each node in a type chain, print the raw data for each member of\n\ |
1a966eab | 1310 | the type structure, and the interpretation of the data."), |
c906108c | 1311 | &maintenanceprintlist); |
a4915e8d | 1312 | set_cmd_completer (cmd, expression_completer); |
c906108c | 1313 | |
c906108c | 1314 | add_cmd ("statistics", class_maintenance, maintenance_print_statistics, |
1a966eab | 1315 | _("Print statistics about internal gdb state."), |
c906108c SS |
1316 | &maintenanceprintlist); |
1317 | ||
1a966eab AC |
1318 | add_cmd ("architecture", class_maintenance, |
1319 | maintenance_print_architecture, _("\ | |
1320 | Print the internal architecture configuration.\n\ | |
1321 | Takes an optional file parameter."), | |
4b9b3959 AC |
1322 | &maintenanceprintlist); |
1323 | ||
0743fc83 | 1324 | add_basic_prefix_cmd ("check", class_maintenance, _("\ |
27d41eac | 1325 | Commands for checking internal gdb state."), |
2f822da5 | 1326 | &maintenancechecklist, 0, |
0743fc83 | 1327 | &maintenancelist); |
27d41eac | 1328 | |
3e43a32a MS |
1329 | add_cmd ("translate-address", class_maintenance, |
1330 | maintenance_translate_address, | |
1a966eab | 1331 | _("Translate a section name and address to a symbol."), |
c906108c SS |
1332 | &maintenancelist); |
1333 | ||
1a966eab | 1334 | add_cmd ("deprecate", class_maintenance, maintenance_deprecate, _("\ |
590042fc PW |
1335 | Deprecate a command (for testing purposes).\n\ |
1336 | Usage: maintenance deprecate COMMANDNAME [\"REPLACEMENT\"]\n\ | |
1337 | This is used by the testsuite to check the command deprecator.\n\ | |
1338 | You probably shouldn't use this,\n\ | |
1339 | rather you should use the C function deprecate_cmd()."), &maintenancelist); | |
56382845 | 1340 | |
1a966eab | 1341 | add_cmd ("undeprecate", class_maintenance, maintenance_undeprecate, _("\ |
590042fc PW |
1342 | Undeprecate a command (for testing purposes).\n\ |
1343 | Usage: maintenance undeprecate COMMANDNAME\n\ | |
1344 | This is used by the testsuite to check the command deprecator.\n\ | |
1345 | You probably shouldn't use this."), | |
33f91161 | 1346 | &maintenancelist); |
56382845 | 1347 | |
dcd1f979 TT |
1348 | add_cmd ("selftest", class_maintenance, maintenance_selftest, _("\ |
1349 | Run gdb's unit tests.\n\ | |
590042fc | 1350 | Usage: maintenance selftest [FILTER]\n\ |
dcd1f979 | 1351 | This will run any unit tests that were built in to gdb.\n\ |
1526853e | 1352 | If a filter is given, only the tests with that value in their name will ran."), |
dcd1f979 TT |
1353 | &maintenancelist); |
1354 | ||
1526853e SM |
1355 | add_cmd ("selftests", class_maintenance, maintenance_info_selftests, |
1356 | _("List the registered selftests."), &maintenanceinfolist); | |
1357 | ||
d28f9cdf | 1358 | add_setshow_boolean_cmd ("profile", class_maintenance, |
7915a72c AC |
1359 | &maintenance_profile_p, _("\ |
1360 | Set internal profiling."), _("\ | |
1361 | Show internal profiling."), _("\ | |
1362 | When enabled GDB is profiled."), | |
2c5b56ce | 1363 | maintenance_set_profile_cmd, |
920d2a44 | 1364 | show_maintenance_profile_p, |
d28f9cdf DJ |
1365 | &maintenance_set_cmdlist, |
1366 | &maintenance_show_cmdlist); | |
22138db6 TT |
1367 | |
1368 | add_setshow_zuinteger_unlimited_cmd ("worker-threads", | |
1369 | class_maintenance, | |
1370 | &n_worker_threads, _("\ | |
1371 | Set the number of worker threads GDB can use."), _("\ | |
1372 | Show the number of worker threads GDB can use."), _("\ | |
1373 | GDB may use multiple threads to speed up certain CPU-intensive operations,\n\ | |
1374 | such as demangling symbol names."), | |
1375 | maintenance_set_worker_threads, NULL, | |
1376 | &maintenance_set_cmdlist, | |
1377 | &maintenance_show_cmdlist); | |
1378 | ||
1379 | update_thread_pool_size (); | |
c906108c | 1380 | } |