1 /* Support for GDB maintenance commands.
3 Copyright (C) 1992-2020 Free Software Foundation, Inc.
5 Written by Fred Fish at Cygnus Support.
7 This file is part of GDB.
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
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "arch-utils.h"
35 #include "expression.h" /* For language.h */
42 #include "gdbsupport/selftest.h"
44 #include "cli/cli-decode.h"
45 #include "cli/cli-utils.h"
46 #include "cli/cli-setshow.h"
47 #include "cli/cli-cmds.h"
50 #include "gdbsupport/thread-pool.h"
53 static void maintenance_do_deprecate (const char *, int);
57 maintenance_dump_me (const char *args
, int from_tty
)
59 if (query (_("Should GDB dump core? ")))
62 /* SIGQUIT by default is ignored, so use SIGABRT instead. */
63 signal (SIGABRT
, SIG_DFL
);
64 kill (getpid (), SIGABRT
);
66 signal (SIGQUIT
, SIG_DFL
);
67 kill (getpid (), SIGQUIT
);
73 /* Stimulate the internal error mechanism that GDB uses when an
74 internal problem is detected. Allows testing of the mechanism.
75 Also useful when the user wants to drop a core file but not exit
79 maintenance_internal_error (const char *args
, int from_tty
)
81 internal_error (__FILE__
, __LINE__
, "%s", (args
== NULL
? "" : args
));
84 /* Stimulate the internal error mechanism that GDB uses when an
85 internal problem is detected. Allows testing of the mechanism.
86 Also useful when the user wants to drop a core file but not exit
90 maintenance_internal_warning (const char *args
, int from_tty
)
92 internal_warning (__FILE__
, __LINE__
, "%s", (args
== NULL
? "" : args
));
95 /* Stimulate the internal error mechanism that GDB uses when an
96 demangler problem is detected. Allows testing of the mechanism. */
99 maintenance_demangler_warning (const char *args
, int from_tty
)
101 demangler_warning (__FILE__
, __LINE__
, "%s", (args
== NULL
? "" : args
));
104 /* Old command to demangle a string. The command has been moved to "demangle".
105 It is kept for now because otherwise "mt demangle" gets interpreted as
106 "mt demangler-warning" which artificially creates an internal gdb error. */
109 maintenance_demangle (const char *args
, int from_tty
)
111 printf_filtered (_("This command has been moved to \"demangle\".\n"));
115 maintenance_time_display (const char *args
, int from_tty
)
117 if (args
== NULL
|| *args
== '\0')
118 printf_unfiltered (_("\"maintenance time\" takes a numeric argument.\n"));
120 set_per_command_time (strtol (args
, NULL
, 10));
124 maintenance_space_display (const char *args
, int from_tty
)
126 if (args
== NULL
|| *args
== '\0')
127 printf_unfiltered ("\"maintenance space\" takes a numeric argument.\n");
129 set_per_command_space (strtol (args
, NULL
, 10));
132 /* Mini tokenizing lexer for 'maint info sections' command. */
135 match_substring (const char *string
, const char *substr
)
137 int substr_len
= strlen(substr
);
140 while ((tok
= strstr (string
, substr
)) != NULL
)
142 /* Got a partial match. Is it a whole word? */
147 /* Token is delimited at the front... */
148 if (tok
[substr_len
] == ' '
149 || tok
[substr_len
] == '\t'
150 || tok
[substr_len
] == '\0')
152 /* Token is delimited at the rear. Got a whole-word match. */
156 /* Token didn't match as a whole word. Advance and try again. */
163 match_bfd_flags (const char *string
, flagword flags
)
165 if (flags
& SEC_ALLOC
)
166 if (match_substring (string
, "ALLOC"))
168 if (flags
& SEC_LOAD
)
169 if (match_substring (string
, "LOAD"))
171 if (flags
& SEC_RELOC
)
172 if (match_substring (string
, "RELOC"))
174 if (flags
& SEC_READONLY
)
175 if (match_substring (string
, "READONLY"))
177 if (flags
& SEC_CODE
)
178 if (match_substring (string
, "CODE"))
180 if (flags
& SEC_DATA
)
181 if (match_substring (string
, "DATA"))
184 if (match_substring (string
, "ROM"))
186 if (flags
& SEC_CONSTRUCTOR
)
187 if (match_substring (string
, "CONSTRUCTOR"))
189 if (flags
& SEC_HAS_CONTENTS
)
190 if (match_substring (string
, "HAS_CONTENTS"))
192 if (flags
& SEC_NEVER_LOAD
)
193 if (match_substring (string
, "NEVER_LOAD"))
195 if (flags
& SEC_COFF_SHARED_LIBRARY
)
196 if (match_substring (string
, "COFF_SHARED_LIBRARY"))
198 if (flags
& SEC_IS_COMMON
)
199 if (match_substring (string
, "IS_COMMON"))
206 print_bfd_flags (flagword flags
)
208 if (flags
& SEC_ALLOC
)
209 printf_filtered (" ALLOC");
210 if (flags
& SEC_LOAD
)
211 printf_filtered (" LOAD");
212 if (flags
& SEC_RELOC
)
213 printf_filtered (" RELOC");
214 if (flags
& SEC_READONLY
)
215 printf_filtered (" READONLY");
216 if (flags
& SEC_CODE
)
217 printf_filtered (" CODE");
218 if (flags
& SEC_DATA
)
219 printf_filtered (" DATA");
221 printf_filtered (" ROM");
222 if (flags
& SEC_CONSTRUCTOR
)
223 printf_filtered (" CONSTRUCTOR");
224 if (flags
& SEC_HAS_CONTENTS
)
225 printf_filtered (" HAS_CONTENTS");
226 if (flags
& SEC_NEVER_LOAD
)
227 printf_filtered (" NEVER_LOAD");
228 if (flags
& SEC_COFF_SHARED_LIBRARY
)
229 printf_filtered (" COFF_SHARED_LIBRARY");
230 if (flags
& SEC_IS_COMMON
)
231 printf_filtered (" IS_COMMON");
235 maint_print_section_info (const char *name
, flagword flags
,
236 CORE_ADDR addr
, CORE_ADDR endaddr
,
237 unsigned long filepos
, int addr_size
)
239 printf_filtered (" %s", hex_string_custom (addr
, addr_size
));
240 printf_filtered ("->%s", hex_string_custom (endaddr
, addr_size
));
241 printf_filtered (" at %s",
242 hex_string_custom ((unsigned long) filepos
, 8));
243 printf_filtered (": %s", name
);
244 print_bfd_flags (flags
);
245 printf_filtered ("\n");
248 /* Return the number of digits required to display COUNT in decimal.
250 Used when pretty printing index numbers to ensure all of the indexes line
254 index_digits (int count
)
256 return ((int) log10 ((float) count
)) + 1;
259 /* Helper function to pretty-print the section index of ASECT from ABFD.
260 The INDEX_DIGITS is the number of digits in the largest index that will
261 be printed, and is used to pretty-print the resulting string. */
264 print_section_index (bfd
*abfd
,
269 = string_printf (" [%d] ", gdb_bfd_section_index (abfd
, asect
));
270 /* The '+ 4' for the leading and trailing characters. */
271 printf_filtered ("%-*s", (index_digits
+ 4), result
.c_str ());
274 /* Print information about ASECT from ABFD. The section will be printed using
275 the VMA's from the bfd, which will not be the relocated addresses for bfds
276 that should be relocated. The information must be printed with the same
277 layout as PRINT_OBJFILE_SECTION_INFO below.
279 ARG is the argument string passed by the user to the top level maintenance
280 info sections command. Used for filtering which sections are printed. */
283 print_bfd_section_info (bfd
*abfd
, asection
*asect
, const char *arg
,
286 flagword flags
= bfd_section_flags (asect
);
287 const char *name
= bfd_section_name (asect
);
289 if (arg
== NULL
|| *arg
== '\0'
290 || match_substring (arg
, name
)
291 || match_bfd_flags (arg
, flags
))
293 struct gdbarch
*gdbarch
= gdbarch_from_bfd (abfd
);
294 int addr_size
= gdbarch_addr_bit (gdbarch
) / 8;
295 CORE_ADDR addr
, endaddr
;
297 addr
= bfd_section_vma (asect
);
298 endaddr
= addr
+ bfd_section_size (asect
);
299 print_section_index (abfd
, asect
, index_digits
);
300 maint_print_section_info (name
, flags
, addr
, endaddr
,
301 asect
->filepos
, addr_size
);
305 /* Print information about ASECT which is GDB's wrapper around a section
306 from ABFD. The information must be printed with the same layout as
307 PRINT_BFD_SECTION_INFO above. PRINT_DATA holds information used to
308 filter which sections are printed, and for formatting the output.
310 ARG is the argument string passed by the user to the top level maintenance
311 info sections command. Used for filtering which sections are printed. */
314 print_objfile_section_info (bfd
*abfd
, struct obj_section
*asect
,
315 const char *arg
, int index_digits
)
317 flagword flags
= bfd_section_flags (asect
->the_bfd_section
);
318 const char *name
= bfd_section_name (asect
->the_bfd_section
);
320 if (arg
== NULL
|| *arg
== '\0'
321 || match_substring (arg
, name
)
322 || match_bfd_flags (arg
, flags
))
324 struct gdbarch
*gdbarch
= gdbarch_from_bfd (abfd
);
325 int addr_size
= gdbarch_addr_bit (gdbarch
) / 8;
327 print_section_index (abfd
, asect
->the_bfd_section
, index_digits
);
328 maint_print_section_info (name
, flags
,
329 obj_section_addr (asect
),
330 obj_section_endaddr (asect
),
331 asect
->the_bfd_section
->filepos
,
336 /* Find an obj_section, GDB's wrapper around a bfd section for ASECTION
337 from ABFD. It might be that no such wrapper exists (for example debug
338 sections don't have such wrappers) in which case nullptr is returned. */
341 maint_obj_section_from_bfd_section (bfd
*abfd
,
345 if (ofile
->sections
== nullptr)
349 = &ofile
->sections
[gdb_bfd_section_index (abfd
, asection
)];
351 if (osect
>= ofile
->sections_end
)
357 /* Print information about ASECT from ABFD. Where possible the information for
358 ASECT will print the relocated addresses of the section.
360 ARG is the argument string passed by the user to the top level maintenance
361 info sections command. Used for filtering which sections are printed. */
364 print_bfd_section_info_maybe_relocated (bfd
*abfd
, asection
*asect
,
365 objfile
*objfile
, const char *arg
,
368 gdb_assert (objfile
->sections
!= NULL
);
370 = maint_obj_section_from_bfd_section (abfd
, asect
, objfile
);
372 if (osect
->the_bfd_section
== NULL
)
373 print_bfd_section_info (abfd
, asect
, arg
, index_digits
);
375 print_objfile_section_info (abfd
, osect
, arg
, index_digits
);
378 /* Implement the "maintenance info sections" command. */
381 maintenance_info_sections (const char *arg
, int from_tty
)
383 if (current_program_space
->exec_bfd ())
387 printf_filtered (_("Exec file:\n"));
388 printf_filtered (" `%s', ",
389 bfd_get_filename (current_program_space
->exec_bfd ()));
391 printf_filtered (_("file type %s.\n"),
392 bfd_get_target (current_program_space
->exec_bfd ()));
394 /* Only this function cares about the 'ALLOBJ' argument;
395 if 'ALLOBJ' is the only argument, discard it rather than
396 passing it down to print_objfile_section_info (which
397 wouldn't know how to handle it). */
398 if (arg
&& strcmp (arg
, "ALLOBJ") == 0)
404 for (objfile
*ofile
: current_program_space
->objfiles ())
407 printf_filtered (_(" Object file: %s\n"),
408 bfd_get_filename (ofile
->obfd
));
409 else if (ofile
->obfd
!= current_program_space
->exec_bfd ())
412 int section_count
= gdb_bfd_count_sections (ofile
->obfd
);
414 for (asection
*sect
: gdb_bfd_sections (ofile
->obfd
))
415 print_bfd_section_info_maybe_relocated
416 (ofile
->obfd
, sect
, ofile
, arg
, index_digits (section_count
));
422 printf_filtered (_("Core file:\n"));
423 printf_filtered (" `%s', ", bfd_get_filename (core_bfd
));
425 printf_filtered (_("file type %s.\n"), bfd_get_target (core_bfd
));
427 int section_count
= gdb_bfd_count_sections (core_bfd
);
429 for (asection
*sect
: gdb_bfd_sections (core_bfd
))
430 print_bfd_section_info (core_bfd
, sect
, arg
,
431 index_digits (section_count
));
436 maintenance_print_statistics (const char *args
, int from_tty
)
438 print_objfile_statistics ();
439 print_symbol_bcache_statistics ();
443 maintenance_print_architecture (const char *args
, int from_tty
)
445 struct gdbarch
*gdbarch
= get_current_arch ();
448 gdbarch_dump (gdbarch
, gdb_stdout
);
453 if (!file
.open (args
, "w"))
454 perror_with_name (_("maintenance print architecture"));
455 gdbarch_dump (gdbarch
, &file
);
459 /* The "maintenance translate-address" command converts a section and address
460 to a symbol. This can be called in two ways:
461 maintenance translate-address <secname> <addr>
462 or maintenance translate-address <addr>. */
465 maintenance_translate_address (const char *arg
, int from_tty
)
468 struct obj_section
*sect
;
470 struct bound_minimal_symbol sym
;
472 if (arg
== NULL
|| *arg
== 0)
473 error (_("requires argument (address or section + address)"));
479 { /* See if we have a valid section name. */
480 while (*p
&& !isspace (*p
)) /* Find end of section name. */
482 if (*p
== '\000') /* End of command? */
483 error (_("Need to specify section name and address"));
485 int arg_len
= p
- arg
;
486 p
= skip_spaces (p
+ 1);
488 for (objfile
*objfile
: current_program_space
->objfiles ())
489 ALL_OBJFILE_OSECTIONS (objfile
, sect
)
491 if (strncmp (sect
->the_bfd_section
->name
, arg
, arg_len
) == 0)
495 error (_("Unknown section %s."), arg
);
499 address
= parse_and_eval_address (p
);
502 sym
= lookup_minimal_symbol_by_pc_section (address
, sect
);
504 sym
= lookup_minimal_symbol_by_pc (address
);
508 const char *symbol_name
= sym
.minsym
->print_name ();
509 const char *symbol_offset
510 = pulongest (address
- BMSYMBOL_VALUE_ADDRESS (sym
));
512 sect
= MSYMBOL_OBJ_SECTION(sym
.objfile
, sym
.minsym
);
515 const char *section_name
;
516 const char *obj_name
;
518 gdb_assert (sect
->the_bfd_section
&& sect
->the_bfd_section
->name
);
519 section_name
= sect
->the_bfd_section
->name
;
521 gdb_assert (sect
->objfile
&& objfile_name (sect
->objfile
));
522 obj_name
= objfile_name (sect
->objfile
);
524 if (current_program_space
->multi_objfile_p ())
525 printf_filtered (_("%s + %s in section %s of %s\n"),
526 symbol_name
, symbol_offset
,
527 section_name
, obj_name
);
529 printf_filtered (_("%s + %s in section %s\n"),
530 symbol_name
, symbol_offset
, section_name
);
533 printf_filtered (_("%s + %s\n"), symbol_name
, symbol_offset
);
536 printf_filtered (_("no symbol at %s:%s\n"),
537 sect
->the_bfd_section
->name
, hex_string (address
));
539 printf_filtered (_("no symbol at %s\n"), hex_string (address
));
545 /* When a command is deprecated the user will be warned the first time
546 the command is used. If possible, a replacement will be
550 maintenance_deprecate (const char *args
, int from_tty
)
552 if (args
== NULL
|| *args
== '\0')
554 printf_unfiltered (_("\"maintenance deprecate\" takes an argument,\n\
555 the command you want to deprecate, and optionally the replacement command\n\
556 enclosed in quotes.\n"));
559 maintenance_do_deprecate (args
, 1);
564 maintenance_undeprecate (const char *args
, int from_tty
)
566 if (args
== NULL
|| *args
== '\0')
568 printf_unfiltered (_("\"maintenance undeprecate\" takes an argument, \n\
569 the command you want to undeprecate.\n"));
572 maintenance_do_deprecate (args
, 0);
575 /* You really shouldn't be using this. It is just for the testsuite.
576 Rather, you should use deprecate_cmd() when the command is created
577 in _initialize_blah().
579 This function deprecates a command and optionally assigns it a
583 maintenance_do_deprecate (const char *text
, int deprecate
)
585 struct cmd_list_element
*alias
= NULL
;
586 struct cmd_list_element
*prefix_cmd
= NULL
;
587 struct cmd_list_element
*cmd
= NULL
;
589 const char *start_ptr
= NULL
;
590 const char *end_ptr
= NULL
;
592 char *replacement
= NULL
;
597 if (!lookup_cmd_composition (text
, &alias
, &prefix_cmd
, &cmd
))
599 printf_filtered (_("Can't find command '%s' to deprecate.\n"), text
);
605 /* Look for a replacement command. */
606 start_ptr
= strchr (text
, '\"');
607 if (start_ptr
!= NULL
)
610 end_ptr
= strrchr (start_ptr
, '\"');
613 len
= end_ptr
- start_ptr
;
614 replacement
= savestring (start_ptr
, len
);
619 if (!start_ptr
|| !end_ptr
)
623 /* If they used an alias, we only want to deprecate the alias.
625 Note the MALLOCED_REPLACEMENT test. If the command's replacement
626 string was allocated at compile time we don't want to free the
630 if (alias
->malloced_replacement
)
631 xfree ((char *) alias
->replacement
);
635 alias
->deprecated_warn_user
= 1;
636 alias
->cmd_deprecated
= 1;
640 alias
->deprecated_warn_user
= 0;
641 alias
->cmd_deprecated
= 0;
643 alias
->replacement
= replacement
;
644 alias
->malloced_replacement
= 1;
649 if (cmd
->malloced_replacement
)
650 xfree ((char *) cmd
->replacement
);
654 cmd
->deprecated_warn_user
= 1;
655 cmd
->cmd_deprecated
= 1;
659 cmd
->deprecated_warn_user
= 0;
660 cmd
->cmd_deprecated
= 0;
662 cmd
->replacement
= replacement
;
663 cmd
->malloced_replacement
= 1;
669 /* Maintenance set/show framework. */
671 struct cmd_list_element
*maintenance_set_cmdlist
;
672 struct cmd_list_element
*maintenance_show_cmdlist
;
674 /* "maintenance with" command. */
677 maintenance_with_cmd (const char *args
, int from_tty
)
679 with_command_1 ("maintenance set ", maintenance_set_cmdlist
, args
, from_tty
);
682 /* "maintenance with" command completer. */
685 maintenance_with_cmd_completer (struct cmd_list_element
*ignore
,
686 completion_tracker
&tracker
,
687 const char *text
, const char * /*word*/)
689 with_command_completer_1 ("maintenance set ", tracker
, text
);
692 /* Profiling support. */
694 static bool maintenance_profile_p
;
696 show_maintenance_profile_p (struct ui_file
*file
, int from_tty
,
697 struct cmd_list_element
*c
, const char *value
)
699 fprintf_filtered (file
, _("Internal profiling is %s.\n"), value
);
704 #define TEXTEND &_etext
705 #elif defined (HAVE_ETEXT)
707 #define TEXTEND &etext
710 #if defined (HAVE_MONSTARTUP) && defined (HAVE__MCLEANUP) && defined (TEXTEND)
712 static int profiling_state
;
714 EXTERN_C
void _mcleanup (void);
717 mcleanup_wrapper (void)
723 EXTERN_C
void monstartup (unsigned long, unsigned long);
727 maintenance_set_profile_cmd (const char *args
, int from_tty
,
728 struct cmd_list_element
*c
)
730 if (maintenance_profile_p
== profiling_state
)
733 profiling_state
= maintenance_profile_p
;
735 if (maintenance_profile_p
)
737 static int profiling_initialized
;
739 if (!profiling_initialized
)
741 atexit (mcleanup_wrapper
);
742 profiling_initialized
= 1;
745 /* "main" is now always the first function in the text segment, so use
746 its address for monstartup. */
747 monstartup ((unsigned long) &main
, (unsigned long) TEXTEND
);
751 extern void _mcleanup (void);
758 maintenance_set_profile_cmd (const char *args
, int from_tty
,
759 struct cmd_list_element
*c
)
761 error (_("Profiling support is not available on this system."));
765 static int n_worker_threads
= -1;
767 /* Update the thread pool for the desired number of threads. */
769 update_thread_pool_size ()
772 int n_threads
= n_worker_threads
;
775 n_threads
= std::thread::hardware_concurrency ();
777 gdb::thread_pool::g_thread_pool
->set_thread_count (n_threads
);
782 maintenance_set_worker_threads (const char *args
, int from_tty
,
783 struct cmd_list_element
*c
)
785 update_thread_pool_size ();
789 /* If true, display time usage both at startup and for each command. */
791 static bool per_command_time
;
793 /* If true, display space usage both at startup and for each command. */
795 static bool per_command_space
;
797 /* If true, display basic symtab stats for each command. */
799 static bool per_command_symtab
;
801 /* mt per-command commands. */
803 static struct cmd_list_element
*per_command_setlist
;
804 static struct cmd_list_element
*per_command_showlist
;
806 /* Set whether to display time statistics to NEW_VALUE
807 (non-zero means true). */
810 set_per_command_time (int new_value
)
812 per_command_time
= new_value
;
815 /* Set whether to display space statistics to NEW_VALUE
816 (non-zero means true). */
819 set_per_command_space (int new_value
)
821 per_command_space
= new_value
;
824 /* Count the number of symtabs and blocks. */
827 count_symtabs_and_blocks (int *nr_symtabs_ptr
, int *nr_compunit_symtabs_ptr
,
831 int nr_compunit_symtabs
= 0;
834 /* When collecting statistics during startup, this is called before
835 pretty much anything in gdb has been initialized, and thus
836 current_program_space may be NULL. */
837 if (current_program_space
!= NULL
)
839 for (objfile
*o
: current_program_space
->objfiles ())
841 for (compunit_symtab
*cu
: o
->compunits ())
843 ++nr_compunit_symtabs
;
844 nr_blocks
+= BLOCKVECTOR_NBLOCKS (COMPUNIT_BLOCKVECTOR (cu
));
845 nr_symtabs
+= std::distance (compunit_filetabs (cu
).begin (),
846 compunit_filetabs (cu
).end ());
851 *nr_symtabs_ptr
= nr_symtabs
;
852 *nr_compunit_symtabs_ptr
= nr_compunit_symtabs
;
853 *nr_blocks_ptr
= nr_blocks
;
856 /* As indicated by display_time and display_space, report GDB's
857 elapsed time and space usage from the base time and space recorded
860 scoped_command_stats::~scoped_command_stats ()
862 /* Early exit if we're not reporting any stats. It can be expensive to
863 compute the pre-command values so don't collect them at all if we're
864 not reporting stats. Alas this doesn't work in the startup case because
865 we don't know yet whether we will be reporting the stats. For the
866 startup case collect the data anyway (it should be cheap at this point),
867 and leave it to the reporter to decide whether to print them. */
870 && !per_command_space
871 && !per_command_symtab
)
874 if (m_time_enabled
&& per_command_time
)
876 print_time (_("command finished"));
878 using namespace std::chrono
;
880 run_time_clock::duration cmd_time
881 = run_time_clock::now () - m_start_cpu_time
;
883 steady_clock::duration wall_time
884 = steady_clock::now () - m_start_wall_time
;
885 /* Subtract time spend in prompt_for_continue from walltime. */
886 wall_time
-= get_prompt_for_continue_wait_time ();
888 printf_unfiltered (!m_msg_type
889 ? _("Startup time: %.6f (cpu), %.6f (wall)\n")
890 : _("Command execution time: %.6f (cpu), %.6f (wall)\n"),
891 duration
<double> (cmd_time
).count (),
892 duration
<double> (wall_time
).count ());
895 if (m_space_enabled
&& per_command_space
)
897 #ifdef HAVE_USEFUL_SBRK
898 char *lim
= (char *) sbrk (0);
900 long space_now
= lim
- lim_at_start
;
901 long space_diff
= space_now
- m_start_space
;
903 printf_unfiltered (!m_msg_type
904 ? _("Space used: %ld (%s%ld during startup)\n")
905 : _("Space used: %ld (%s%ld for this command)\n"),
907 (space_diff
>= 0 ? "+" : ""),
912 if (m_symtab_enabled
&& per_command_symtab
)
914 int nr_symtabs
, nr_compunit_symtabs
, nr_blocks
;
916 count_symtabs_and_blocks (&nr_symtabs
, &nr_compunit_symtabs
, &nr_blocks
);
917 printf_unfiltered (_("#symtabs: %d (+%d),"
918 " #compunits: %d (+%d),"
919 " #blocks: %d (+%d)\n"),
921 nr_symtabs
- m_start_nr_symtabs
,
924 - m_start_nr_compunit_symtabs
),
926 nr_blocks
- m_start_nr_blocks
);
930 scoped_command_stats::scoped_command_stats (bool msg_type
)
931 : m_msg_type (msg_type
)
933 if (!m_msg_type
|| per_command_space
)
935 #ifdef HAVE_USEFUL_SBRK
936 char *lim
= (char *) sbrk (0);
937 m_start_space
= lim
- lim_at_start
;
944 if (msg_type
== 0 || per_command_time
)
946 using namespace std::chrono
;
948 m_start_cpu_time
= run_time_clock::now ();
949 m_start_wall_time
= steady_clock::now ();
952 if (per_command_time
)
953 print_time (_("command started"));
958 if (msg_type
== 0 || per_command_symtab
)
960 int nr_symtabs
, nr_compunit_symtabs
, nr_blocks
;
962 count_symtabs_and_blocks (&nr_symtabs
, &nr_compunit_symtabs
, &nr_blocks
);
963 m_start_nr_symtabs
= nr_symtabs
;
964 m_start_nr_compunit_symtabs
= nr_compunit_symtabs
;
965 m_start_nr_blocks
= nr_blocks
;
966 m_symtab_enabled
= 1;
969 m_symtab_enabled
= 0;
971 /* Initialize timer to keep track of how long we waited for the user. */
972 reset_prompt_for_continue_wait_time ();
978 scoped_command_stats::print_time (const char *msg
)
980 using namespace std::chrono
;
982 auto now
= system_clock::now ();
983 auto ticks
= now
.time_since_epoch ().count () / (1000 * 1000);
984 auto millis
= ticks
% 1000;
986 std::time_t as_time
= system_clock::to_time_t (now
);
988 localtime_r (&as_time
, &tm
);
991 strftime (out
, sizeof (out
), "%F %H:%M:%S", &tm
);
993 printf_unfiltered ("%s.%03d - %s\n", out
, (int) millis
, msg
);
996 /* Handle unknown "mt set per-command" arguments.
997 In this case have "mt set per-command on|off" affect every setting. */
1000 set_per_command_cmd (const char *args
, int from_tty
)
1002 struct cmd_list_element
*list
;
1005 val
= parse_cli_boolean_value (args
);
1007 error (_("Bad value for 'mt set per-command no'."));
1009 for (list
= per_command_setlist
; list
!= NULL
; list
= list
->next
)
1010 if (list
->var_type
== var_boolean
)
1012 gdb_assert (list
->type
== set_cmd
);
1013 do_set_command (args
, from_tty
, list
);
1019 /* The "maintenance selftest" command. */
1022 maintenance_selftest (const char *args
, int from_tty
)
1025 gdb_argv
argv (args
);
1026 selftests::run_tests (argv
.as_array_view ());
1028 printf_filtered (_("\
1029 Selftests have been disabled for this build.\n"));
1034 maintenance_info_selftests (const char *arg
, int from_tty
)
1037 printf_filtered ("Registered selftests:\n");
1038 selftests::for_each_selftest ([] (const std::string
&name
) {
1039 printf_filtered (" - %s\n", name
.c_str ());
1042 printf_filtered (_("\
1043 Selftests have been disabled for this build.\n"));
1048 void _initialize_maint_cmds ();
1050 _initialize_maint_cmds ()
1052 struct cmd_list_element
*cmd
;
1054 add_basic_prefix_cmd ("maintenance", class_maintenance
, _("\
1055 Commands for use by GDB maintainers.\n\
1056 Includes commands to dump specific internal GDB structures in\n\
1057 a human readable form, to cause GDB to deliberately dump core, etc."),
1058 &maintenancelist
, "maintenance ", 0,
1061 add_com_alias ("mt", "maintenance", class_maintenance
, 1);
1063 add_basic_prefix_cmd ("info", class_maintenance
, _("\
1064 Commands for showing internal info about the program being debugged."),
1065 &maintenanceinfolist
, "maintenance info ", 0,
1067 add_alias_cmd ("i", "info", class_maintenance
, 1, &maintenancelist
);
1069 add_cmd ("sections", class_maintenance
, maintenance_info_sections
, _("\
1070 List the BFD sections of the exec and core files.\n\
1071 Arguments may be any combination of:\n\
1072 [one or more section names]\n\
1073 ALLOC LOAD RELOC READONLY CODE DATA ROM CONSTRUCTOR\n\
1074 HAS_CONTENTS NEVER_LOAD COFF_SHARED_LIBRARY IS_COMMON\n\
1075 Sections matching any argument will be listed (no argument\n\
1076 implies all sections). In addition, the special argument\n\
1078 lists all sections from all object files, including shared libraries."),
1079 &maintenanceinfolist
);
1081 add_basic_prefix_cmd ("print", class_maintenance
,
1082 _("Maintenance command for printing GDB internal state."),
1083 &maintenanceprintlist
, "maintenance print ", 0,
1086 add_basic_prefix_cmd ("set", class_maintenance
, _("\
1087 Set GDB internal variables used by the GDB maintainer.\n\
1088 Configure variables internal to GDB that aid in GDB's maintenance"),
1089 &maintenance_set_cmdlist
, "maintenance set ",
1093 add_show_prefix_cmd ("show", class_maintenance
, _("\
1094 Show GDB internal variables used by the GDB maintainer.\n\
1095 Configure variables internal to GDB that aid in GDB's maintenance"),
1096 &maintenance_show_cmdlist
, "maintenance show ",
1100 cmd
= add_cmd ("with", class_maintenance
, maintenance_with_cmd
, _("\
1101 Like \"with\", but works with \"maintenance set\" variables.\n\
1102 Usage: maintenance with SETTING [VALUE] [-- COMMAND]\n\
1103 With no COMMAND, repeats the last executed command.\n\
1104 SETTING is any setting you can change with the \"maintenance set\"\n\
1107 set_cmd_completer_handle_brkchars (cmd
, maintenance_with_cmd_completer
);
1110 add_cmd ("dump-me", class_maintenance
, maintenance_dump_me
, _("\
1111 Get fatal error; make debugger dump its core.\n\
1112 GDB sets its handling of SIGQUIT back to SIG_DFL and then sends\n\
1113 itself a SIGQUIT signal."),
1117 add_cmd ("internal-error", class_maintenance
,
1118 maintenance_internal_error
, _("\
1119 Give GDB an internal error.\n\
1120 Cause GDB to behave as if an internal error was detected."),
1123 add_cmd ("internal-warning", class_maintenance
,
1124 maintenance_internal_warning
, _("\
1125 Give GDB an internal warning.\n\
1126 Cause GDB to behave as if an internal warning was reported."),
1129 add_cmd ("demangler-warning", class_maintenance
,
1130 maintenance_demangler_warning
, _("\
1131 Give GDB a demangler warning.\n\
1132 Cause GDB to behave as if a demangler warning was reported."),
1135 cmd
= add_cmd ("demangle", class_maintenance
, maintenance_demangle
, _("\
1136 This command has been moved to \"demangle\"."),
1138 deprecate_cmd (cmd
, "demangle");
1140 add_prefix_cmd ("per-command", class_maintenance
, set_per_command_cmd
, _("\
1141 Per-command statistics settings."),
1142 &per_command_setlist
, "maintenance set per-command ",
1143 1/*allow-unknown*/, &maintenance_set_cmdlist
);
1145 add_show_prefix_cmd ("per-command", class_maintenance
, _("\
1146 Show per-command statistics settings."),
1147 &per_command_showlist
, "maintenance show per-command ",
1148 0/*allow-unknown*/, &maintenance_show_cmdlist
);
1150 add_setshow_boolean_cmd ("time", class_maintenance
,
1151 &per_command_time
, _("\
1152 Set whether to display per-command execution time."), _("\
1153 Show whether to display per-command execution time."),
1155 If enabled, the execution time for each command will be\n\
1156 displayed following the command's output."),
1158 &per_command_setlist
, &per_command_showlist
);
1160 add_setshow_boolean_cmd ("space", class_maintenance
,
1161 &per_command_space
, _("\
1162 Set whether to display per-command space usage."), _("\
1163 Show whether to display per-command space usage."),
1165 If enabled, the space usage for each command will be\n\
1166 displayed following the command's output."),
1168 &per_command_setlist
, &per_command_showlist
);
1170 add_setshow_boolean_cmd ("symtab", class_maintenance
,
1171 &per_command_symtab
, _("\
1172 Set whether to display per-command symtab statistics."), _("\
1173 Show whether to display per-command symtab statistics."),
1175 If enabled, the basic symtab statistics for each command will be\n\
1176 displayed following the command's output."),
1178 &per_command_setlist
, &per_command_showlist
);
1180 /* This is equivalent to "mt set per-command time on".
1181 Kept because some people are used to typing "mt time 1". */
1182 add_cmd ("time", class_maintenance
, maintenance_time_display
, _("\
1183 Set the display of time usage.\n\
1184 If nonzero, will cause the execution time for each command to be\n\
1185 displayed, following the command's output."),
1188 /* This is equivalent to "mt set per-command space on".
1189 Kept because some people are used to typing "mt space 1". */
1190 add_cmd ("space", class_maintenance
, maintenance_space_display
, _("\
1191 Set the display of space usage.\n\
1192 If nonzero, will cause the execution space for each command to be\n\
1193 displayed, following the command's output."),
1196 add_cmd ("type", class_maintenance
, maintenance_print_type
, _("\
1197 Print a type chain for a given symbol.\n\
1198 For each node in a type chain, print the raw data for each member of\n\
1199 the type structure, and the interpretation of the data."),
1200 &maintenanceprintlist
);
1202 add_cmd ("statistics", class_maintenance
, maintenance_print_statistics
,
1203 _("Print statistics about internal gdb state."),
1204 &maintenanceprintlist
);
1206 add_cmd ("architecture", class_maintenance
,
1207 maintenance_print_architecture
, _("\
1208 Print the internal architecture configuration.\n\
1209 Takes an optional file parameter."),
1210 &maintenanceprintlist
);
1212 add_basic_prefix_cmd ("check", class_maintenance
, _("\
1213 Commands for checking internal gdb state."),
1214 &maintenancechecklist
, "maintenance check ", 0,
1217 add_cmd ("translate-address", class_maintenance
,
1218 maintenance_translate_address
,
1219 _("Translate a section name and address to a symbol."),
1222 add_cmd ("deprecate", class_maintenance
, maintenance_deprecate
, _("\
1223 Deprecate a command (for testing purposes).\n\
1224 Usage: maintenance deprecate COMMANDNAME [\"REPLACEMENT\"]\n\
1225 This is used by the testsuite to check the command deprecator.\n\
1226 You probably shouldn't use this,\n\
1227 rather you should use the C function deprecate_cmd()."), &maintenancelist
);
1229 add_cmd ("undeprecate", class_maintenance
, maintenance_undeprecate
, _("\
1230 Undeprecate a command (for testing purposes).\n\
1231 Usage: maintenance undeprecate COMMANDNAME\n\
1232 This is used by the testsuite to check the command deprecator.\n\
1233 You probably shouldn't use this."),
1236 add_cmd ("selftest", class_maintenance
, maintenance_selftest
, _("\
1237 Run gdb's unit tests.\n\
1238 Usage: maintenance selftest [FILTER]\n\
1239 This will run any unit tests that were built in to gdb.\n\
1240 If a filter is given, only the tests with that value in their name will ran."),
1243 add_cmd ("selftests", class_maintenance
, maintenance_info_selftests
,
1244 _("List the registered selftests."), &maintenanceinfolist
);
1246 add_setshow_boolean_cmd ("profile", class_maintenance
,
1247 &maintenance_profile_p
, _("\
1248 Set internal profiling."), _("\
1249 Show internal profiling."), _("\
1250 When enabled GDB is profiled."),
1251 maintenance_set_profile_cmd
,
1252 show_maintenance_profile_p
,
1253 &maintenance_set_cmdlist
,
1254 &maintenance_show_cmdlist
);
1256 add_setshow_zuinteger_unlimited_cmd ("worker-threads",
1258 &n_worker_threads
, _("\
1259 Set the number of worker threads GDB can use."), _("\
1260 Show the number of worker threads GDB can use."), _("\
1261 GDB may use multiple threads to speed up certain CPU-intensive operations,\n\
1262 such as demangling symbol names."),
1263 maintenance_set_worker_threads
, NULL
,
1264 &maintenance_set_cmdlist
,
1265 &maintenance_show_cmdlist
);
1267 update_thread_pool_size ();