]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/maint.c
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / maint.c
CommitLineData
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"
c906108c 43
18a642a1 44#include "cli/cli-decode.h"
529480d0 45#include "cli/cli-utils.h"
bd712aed 46#include "cli/cli-setshow.h"
fdbc9870 47#include "cli/cli-cmds.h"
18a642a1 48
22138db6
TT
49#if CXX_STD_THREAD
50#include "gdbsupport/thread-pool.h"
51#endif
52
58971144 53static void maintenance_do_deprecate (const char *, int);
1c689132 54
c906108c 55#ifndef _WIN32
c906108c 56static void
58971144 57maintenance_dump_me (const char *args, int from_tty)
c906108c 58{
9e2f0ad4 59 if (query (_("Should GDB dump core? ")))
c906108c 60 {
7be570e7
JM
61#ifdef __DJGPP__
62 /* SIGQUIT by default is ignored, so use SIGABRT instead. */
63 signal (SIGABRT, SIG_DFL);
64 kill (getpid (), SIGABRT);
65#else
c906108c
SS
66 signal (SIGQUIT, SIG_DFL);
67 kill (getpid (), SIGQUIT);
7be570e7 68#endif
c906108c
SS
69 }
70}
71#endif
72
7be570e7
JM
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
025bb325 76 GDB. */
7be570e7
JM
77
78static void
5fed81ff 79maintenance_internal_error (const char *args, int from_tty)
7be570e7 80{
dec43320
AC
81 internal_error (__FILE__, __LINE__, "%s", (args == NULL ? "" : args));
82}
83
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
025bb325 87 GDB. */
dec43320
AC
88
89static void
5fed81ff 90maintenance_internal_warning (const char *args, int from_tty)
dec43320
AC
91{
92 internal_warning (__FILE__, __LINE__, "%s", (args == NULL ? "" : args));
7be570e7
JM
93}
94
57fcfb1b
GB
95/* Stimulate the internal error mechanism that GDB uses when an
96 demangler problem is detected. Allows testing of the mechanism. */
97
98static void
5fed81ff 99maintenance_demangler_warning (const char *args, int from_tty)
57fcfb1b
GB
100{
101 demangler_warning (__FILE__, __LINE__, "%s", (args == NULL ? "" : args));
102}
103
439250fb
DE
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. */
c906108c
SS
107
108static void
58971144 109maintenance_demangle (const char *args, int from_tty)
c906108c 110{
439250fb 111 printf_filtered (_("This command has been moved to \"demangle\".\n"));
c906108c
SS
112}
113
114static void
58971144 115maintenance_time_display (const char *args, int from_tty)
c906108c 116{
c906108c 117 if (args == NULL || *args == '\0')
a3f17187 118 printf_unfiltered (_("\"maintenance time\" takes a numeric argument.\n"));
c906108c 119 else
bd712aed 120 set_per_command_time (strtol (args, NULL, 10));
c906108c
SS
121}
122
123static void
5fed81ff 124maintenance_space_display (const char *args, int from_tty)
c906108c 125{
c906108c
SS
126 if (args == NULL || *args == '\0')
127 printf_unfiltered ("\"maintenance space\" takes a numeric argument.\n");
128 else
bd712aed 129 set_per_command_space (strtol (args, NULL, 10));
c906108c
SS
130}
131
a532ca62
MS
132/* Mini tokenizing lexer for 'maint info sections' command. */
133
134static int
473e38f3 135match_substring (const char *string, const char *substr)
a532ca62
MS
136{
137 int substr_len = strlen(substr);
473e38f3 138 const char *tok;
a532ca62
MS
139
140 while ((tok = strstr (string, substr)) != NULL)
141 {
025bb325 142 /* Got a partial match. Is it a whole word? */
b01d807c
MS
143 if (tok == string
144 || tok[-1] == ' '
145 || tok[-1] == '\t')
a532ca62 146 {
025bb325 147 /* Token is delimited at the front... */
b01d807c
MS
148 if (tok[substr_len] == ' '
149 || tok[substr_len] == '\t'
150 || tok[substr_len] == '\0')
a532ca62
MS
151 {
152 /* Token is delimited at the rear. Got a whole-word match. */
153 return 1;
154 }
155 }
156 /* Token didn't match as a whole word. Advance and try again. */
157 string = tok + 1;
158 }
159 return 0;
160}
161
43155bc1 162static int
fc4baa5e 163match_bfd_flags (const char *string, flagword flags)
c906108c 164{
43155bc1 165 if (flags & SEC_ALLOC)
a532ca62 166 if (match_substring (string, "ALLOC"))
43155bc1
MS
167 return 1;
168 if (flags & SEC_LOAD)
a532ca62 169 if (match_substring (string, "LOAD"))
43155bc1
MS
170 return 1;
171 if (flags & SEC_RELOC)
a532ca62 172 if (match_substring (string, "RELOC"))
43155bc1
MS
173 return 1;
174 if (flags & SEC_READONLY)
a532ca62 175 if (match_substring (string, "READONLY"))
43155bc1
MS
176 return 1;
177 if (flags & SEC_CODE)
a532ca62 178 if (match_substring (string, "CODE"))
43155bc1
MS
179 return 1;
180 if (flags & SEC_DATA)
a532ca62 181 if (match_substring (string, "DATA"))
43155bc1
MS
182 return 1;
183 if (flags & SEC_ROM)
a532ca62 184 if (match_substring (string, "ROM"))
43155bc1
MS
185 return 1;
186 if (flags & SEC_CONSTRUCTOR)
a532ca62 187 if (match_substring (string, "CONSTRUCTOR"))
43155bc1
MS
188 return 1;
189 if (flags & SEC_HAS_CONTENTS)
a532ca62 190 if (match_substring (string, "HAS_CONTENTS"))
43155bc1
MS
191 return 1;
192 if (flags & SEC_NEVER_LOAD)
a532ca62 193 if (match_substring (string, "NEVER_LOAD"))
43155bc1
MS
194 return 1;
195 if (flags & SEC_COFF_SHARED_LIBRARY)
a532ca62 196 if (match_substring (string, "COFF_SHARED_LIBRARY"))
43155bc1
MS
197 return 1;
198 if (flags & SEC_IS_COMMON)
a532ca62 199 if (match_substring (string, "IS_COMMON"))
43155bc1 200 return 1;
c906108c 201
43155bc1
MS
202 return 0;
203}
c906108c 204
43155bc1
MS
205static void
206print_bfd_flags (flagword flags)
207{
c906108c
SS
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");
220 if (flags & SEC_ROM)
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");
43155bc1
MS
232}
233
234static void
67a2b77e
AC
235maint_print_section_info (const char *name, flagword flags,
236 CORE_ADDR addr, CORE_ADDR endaddr,
5af949e3 237 unsigned long filepos, int addr_size)
43155bc1 238{
5af949e3
UW
239 printf_filtered (" %s", hex_string_custom (addr, addr_size));
240 printf_filtered ("->%s", hex_string_custom (endaddr, addr_size));
3ab13650 241 printf_filtered (" at %s",
bb599908 242 hex_string_custom ((unsigned long) filepos, 8));
e3d3bfda
MS
243 printf_filtered (": %s", name);
244 print_bfd_flags (flags);
245 printf_filtered ("\n");
246}
c906108c 247
c5065df0
SM
248/* Return the number of digits required to display COUNT in decimal.
249
250 Used when pretty printing index numbers to ensure all of the indexes line
251 up.*/
252
253static int
254index_digits (int count)
aa17805f 255{
c5065df0
SM
256 return ((int) log10 ((float) count)) + 1;
257}
aa17805f
AB
258
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. */
262
263static void
264print_section_index (bfd *abfd,
265 asection *asect,
266 int index_digits)
267{
268 std::string result
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 ());
272}
273
b886559f
SM
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
c5065df0
SM
277 layout as PRINT_OBJFILE_SECTION_INFO below.
278
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. */
aa17805f 281
e3d3bfda 282static void
c5065df0
SM
283print_bfd_section_info (bfd *abfd, asection *asect, const char *arg,
284 int index_digits)
e3d3bfda 285{
fd361982
AM
286 flagword flags = bfd_section_flags (asect);
287 const char *name = bfd_section_name (asect);
e3d3bfda 288
fc4baa5e
TT
289 if (arg == NULL || *arg == '\0'
290 || match_substring (arg, name)
291 || match_bfd_flags (arg, flags))
e3d3bfda 292 {
5af949e3
UW
293 struct gdbarch *gdbarch = gdbarch_from_bfd (abfd);
294 int addr_size = gdbarch_addr_bit (gdbarch) / 8;
e3d3bfda
MS
295 CORE_ADDR addr, endaddr;
296
fd361982
AM
297 addr = bfd_section_vma (asect);
298 endaddr = addr + bfd_section_size (asect);
c5065df0 299 print_section_index (abfd, asect, index_digits);
5af949e3
UW
300 maint_print_section_info (name, flags, addr, endaddr,
301 asect->filepos, addr_size);
e3d3bfda
MS
302 }
303}
304
aa17805f
AB
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
c5065df0
SM
308 filter which sections are printed, and for formatting the output.
309
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. */
aa17805f 312
e3d3bfda 313static void
c5065df0
SM
314print_objfile_section_info (bfd *abfd, struct obj_section *asect,
315 const char *arg, int index_digits)
e3d3bfda 316{
fd361982
AM
317 flagword flags = bfd_section_flags (asect->the_bfd_section);
318 const char *name = bfd_section_name (asect->the_bfd_section);
43155bc1 319
c5065df0
SM
320 if (arg == NULL || *arg == '\0'
321 || match_substring (arg, name)
322 || match_bfd_flags (arg, flags))
43155bc1 323 {
5af949e3
UW
324 struct gdbarch *gdbarch = gdbarch_from_bfd (abfd);
325 int addr_size = gdbarch_addr_bit (gdbarch) / 8;
b8d56208 326
c5065df0 327 print_section_index (abfd, asect->the_bfd_section, index_digits);
f1f6aadf
PA
328 maint_print_section_info (name, flags,
329 obj_section_addr (asect),
330 obj_section_endaddr (asect),
5af949e3
UW
331 asect->the_bfd_section->filepos,
332 addr_size);
43155bc1 333 }
c906108c
SS
334}
335
aa17805f
AB
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. */
339
340static obj_section *
341maint_obj_section_from_bfd_section (bfd *abfd,
342 asection *asection,
343 objfile *ofile)
344{
345 if (ofile->sections == nullptr)
346 return nullptr;
347
348 obj_section *osect
349 = &ofile->sections[gdb_bfd_section_index (abfd, asection)];
350
351 if (osect >= ofile->sections_end)
352 return nullptr;
353
354 return osect;
355}
356
b886559f 357/* Print information about ASECT from ABFD. Where possible the information for
c5065df0
SM
358 ASECT will print the relocated addresses of the section.
359
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. */
aa17805f
AB
362
363static void
c5065df0
SM
364print_bfd_section_info_maybe_relocated (bfd *abfd, asection *asect,
365 objfile *objfile, const char *arg,
366 int index_digits)
aa17805f 367{
aa17805f
AB
368 gdb_assert (objfile->sections != NULL);
369 obj_section *osect
370 = maint_obj_section_from_bfd_section (abfd, asect, objfile);
371
372 if (osect->the_bfd_section == NULL)
c5065df0 373 print_bfd_section_info (abfd, asect, arg, index_digits);
aa17805f 374 else
c5065df0 375 print_objfile_section_info (abfd, osect, arg, index_digits);
aa17805f
AB
376}
377
378/* Implement the "maintenance info sections" command. */
379
c906108c 380static void
58971144 381maintenance_info_sections (const char *arg, int from_tty)
c906108c 382{
7e10abd1 383 if (current_program_space->exec_bfd ())
c906108c 384 {
6eac171f
TV
385 bool allobj = false;
386
a3f17187 387 printf_filtered (_("Exec file:\n"));
7e10abd1
TT
388 printf_filtered (" `%s', ",
389 bfd_get_filename (current_program_space->exec_bfd ()));
c906108c 390 wrap_here (" ");
7e10abd1
TT
391 printf_filtered (_("file type %s.\n"),
392 bfd_get_target (current_program_space->exec_bfd ()));
e3d3bfda 393
6eac171f
TV
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)
399 {
400 arg = NULL;
401 allobj = true;
402 }
e3d3bfda 403
6eac171f
TV
404 for (objfile *ofile : current_program_space->objfiles ())
405 {
406 if (allobj)
407 printf_filtered (_(" Object file: %s\n"),
408 bfd_get_filename (ofile->obfd));
7e10abd1 409 else if (ofile->obfd != current_program_space->exec_bfd ())
aa17805f
AB
410 continue;
411
c5065df0 412 int section_count = gdb_bfd_count_sections (ofile->obfd);
aa17805f 413
b886559f 414 for (asection *sect : gdb_bfd_sections (ofile->obfd))
c5065df0
SM
415 print_bfd_section_info_maybe_relocated
416 (ofile->obfd, sect, ofile, arg, index_digits (section_count));
e3d3bfda 417 }
c906108c
SS
418 }
419
420 if (core_bfd)
421 {
a3f17187 422 printf_filtered (_("Core file:\n"));
c5aa993b 423 printf_filtered (" `%s', ", bfd_get_filename (core_bfd));
c906108c 424 wrap_here (" ");
a3f17187 425 printf_filtered (_("file type %s.\n"), bfd_get_target (core_bfd));
b886559f 426
c5065df0
SM
427 int section_count = gdb_bfd_count_sections (core_bfd);
428
b886559f 429 for (asection *sect : gdb_bfd_sections (core_bfd))
c5065df0
SM
430 print_bfd_section_info (core_bfd, sect, arg,
431 index_digits (section_count));
c906108c
SS
432 }
433}
434
025cfdb2 435static void
58971144 436maintenance_print_statistics (const char *args, int from_tty)
c906108c
SS
437{
438 print_objfile_statistics ();
439 print_symbol_bcache_statistics ();
440}
441
b9362cc7 442static void
5fed81ff 443maintenance_print_architecture (const char *args, int from_tty)
4b9b3959 444{
e17c207e
UW
445 struct gdbarch *gdbarch = get_current_arch ();
446
4b9b3959 447 if (args == NULL)
e17c207e 448 gdbarch_dump (gdbarch, gdb_stdout);
4b9b3959
AC
449 else
450 {
d7e74731 451 stdio_file file;
b8d56208 452
d7e74731 453 if (!file.open (args, "w"))
e2e0b3e5 454 perror_with_name (_("maintenance print architecture"));
d7e74731 455 gdbarch_dump (gdbarch, &file);
4b9b3959
AC
456 }
457}
458
c906108c
SS
459/* The "maintenance translate-address" command converts a section and address
460 to a symbol. This can be called in two ways:
c5aa993b 461 maintenance translate-address <secname> <addr>
025bb325 462 or maintenance translate-address <addr>. */
c906108c
SS
463
464static void
5fed81ff 465maintenance_translate_address (const char *arg, int from_tty)
c906108c
SS
466{
467 CORE_ADDR address;
714835d5 468 struct obj_section *sect;
5fed81ff 469 const char *p;
7cbd4a93 470 struct bound_minimal_symbol sym;
c906108c
SS
471
472 if (arg == NULL || *arg == 0)
8a3fe4f8 473 error (_("requires argument (address or section + address)"));
c906108c
SS
474
475 sect = NULL;
476 p = arg;
477
478 if (!isdigit (*p))
025bb325
MS
479 { /* See if we have a valid section name. */
480 while (*p && !isspace (*p)) /* Find end of section name. */
c906108c 481 p++;
025bb325 482 if (*p == '\000') /* End of command? */
65e65158 483 error (_("Need to specify section name and address"));
5fed81ff
TT
484
485 int arg_len = p - arg;
486 p = skip_spaces (p + 1);
c906108c 487
2030c079 488 for (objfile *objfile : current_program_space->objfiles ())
3b9d3ac2
TT
489 ALL_OBJFILE_OSECTIONS (objfile, sect)
490 {
491 if (strncmp (sect->the_bfd_section->name, arg, arg_len) == 0)
492 goto found;
493 }
c906108c 494
3b9d3ac2
TT
495 error (_("Unknown section %s."), arg);
496 found: ;
c906108c
SS
497 }
498
499 address = parse_and_eval_address (p);
500
501 if (sect)
502 sym = lookup_minimal_symbol_by_pc_section (address, sect);
503 else
504 sym = lookup_minimal_symbol_by_pc (address);
505
7cbd4a93 506 if (sym.minsym)
c14c28ba 507 {
c9d95fa3 508 const char *symbol_name = sym.minsym->print_name ();
3e43a32a 509 const char *symbol_offset
77e371c0 510 = pulongest (address - BMSYMBOL_VALUE_ADDRESS (sym));
c14c28ba 511
efd66ac6 512 sect = MSYMBOL_OBJ_SECTION(sym.objfile, sym.minsym);
c14c28ba
PP
513 if (sect != NULL)
514 {
515 const char *section_name;
516 const char *obj_name;
517
518 gdb_assert (sect->the_bfd_section && sect->the_bfd_section->name);
519 section_name = sect->the_bfd_section->name;
520
4262abfb
JK
521 gdb_assert (sect->objfile && objfile_name (sect->objfile));
522 obj_name = objfile_name (sect->objfile);
c14c28ba 523
deeafabb 524 if (current_program_space->multi_objfile_p ())
c14c28ba 525 printf_filtered (_("%s + %s in section %s of %s\n"),
3e43a32a
MS
526 symbol_name, symbol_offset,
527 section_name, obj_name);
c14c28ba
PP
528 else
529 printf_filtered (_("%s + %s in section %s\n"),
530 symbol_name, symbol_offset, section_name);
531 }
532 else
533 printf_filtered (_("%s + %s\n"), symbol_name, symbol_offset);
534 }
c906108c 535 else if (sect)
5af949e3
UW
536 printf_filtered (_("no symbol at %s:%s\n"),
537 sect->the_bfd_section->name, hex_string (address));
c906108c 538 else
5af949e3 539 printf_filtered (_("no symbol at %s\n"), hex_string (address));
c906108c
SS
540
541 return;
542}
543
56382845 544
c114dcd5 545/* When a command is deprecated the user will be warned the first time
33f91161 546 the command is used. If possible, a replacement will be
025bb325 547 offered. */
56382845
FN
548
549static void
58971144 550maintenance_deprecate (const char *args, int from_tty)
56382845
FN
551{
552 if (args == NULL || *args == '\0')
553 {
cce7e648
PA
554 printf_unfiltered (_("\"maintenance deprecate\" takes an argument,\n\
555the command you want to deprecate, and optionally the replacement command\n\
a3f17187 556enclosed in quotes.\n"));
56382845 557 }
33f91161 558
56382845 559 maintenance_do_deprecate (args, 1);
56382845
FN
560}
561
562
563static void
58971144 564maintenance_undeprecate (const char *args, int from_tty)
56382845
FN
565{
566 if (args == NULL || *args == '\0')
567 {
a3f17187
AC
568 printf_unfiltered (_("\"maintenance undeprecate\" takes an argument, \n\
569the command you want to undeprecate.\n"));
56382845 570 }
33f91161 571
56382845 572 maintenance_do_deprecate (args, 0);
56382845
FN
573}
574
025bb325 575/* You really shouldn't be using this. It is just for the testsuite.
33f91161
AC
576 Rather, you should use deprecate_cmd() when the command is created
577 in _initialize_blah().
578
579 This function deprecates a command and optionally assigns it a
580 replacement. */
581
8399535b 582static void
58971144 583maintenance_do_deprecate (const char *text, int deprecate)
33f91161 584{
33f91161
AC
585 struct cmd_list_element *alias = NULL;
586 struct cmd_list_element *prefix_cmd = NULL;
587 struct cmd_list_element *cmd = NULL;
588
58971144
TT
589 const char *start_ptr = NULL;
590 const char *end_ptr = NULL;
56382845 591 int len;
33f91161
AC
592 char *replacement = NULL;
593
1c689132
DB
594 if (text == NULL)
595 return;
56382845 596
33f91161
AC
597 if (!lookup_cmd_composition (text, &alias, &prefix_cmd, &cmd))
598 {
a3f17187 599 printf_filtered (_("Can't find command '%s' to deprecate.\n"), text);
33f91161
AC
600 return;
601 }
56382845 602
56382845
FN
603 if (deprecate)
604 {
025bb325 605 /* Look for a replacement command. */
80ce1ecb
AC
606 start_ptr = strchr (text, '\"');
607 if (start_ptr != NULL)
33f91161
AC
608 {
609 start_ptr++;
80ce1ecb
AC
610 end_ptr = strrchr (start_ptr, '\"');
611 if (end_ptr != NULL)
33f91161
AC
612 {
613 len = end_ptr - start_ptr;
58971144 614 replacement = savestring (start_ptr, len);
33f91161
AC
615 }
616 }
56382845 617 }
33f91161 618
56382845
FN
619 if (!start_ptr || !end_ptr)
620 replacement = NULL;
33f91161
AC
621
622
56382845 623 /* If they used an alias, we only want to deprecate the alias.
33f91161 624
56382845
FN
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
025bb325 627 memory. */
56382845
FN
628 if (alias)
629 {
1f2bdf09 630 if (alias->malloced_replacement)
429e55ea 631 xfree ((char *) alias->replacement);
33f91161 632
56382845 633 if (deprecate)
1f2bdf09
TT
634 {
635 alias->deprecated_warn_user = 1;
636 alias->cmd_deprecated = 1;
637 }
56382845 638 else
1f2bdf09
TT
639 {
640 alias->deprecated_warn_user = 0;
641 alias->cmd_deprecated = 0;
642 }
33f91161 643 alias->replacement = replacement;
1f2bdf09 644 alias->malloced_replacement = 1;
56382845
FN
645 return;
646 }
647 else if (cmd)
648 {
1f2bdf09 649 if (cmd->malloced_replacement)
429e55ea 650 xfree ((char *) cmd->replacement);
56382845
FN
651
652 if (deprecate)
1f2bdf09
TT
653 {
654 cmd->deprecated_warn_user = 1;
655 cmd->cmd_deprecated = 1;
656 }
56382845 657 else
1f2bdf09
TT
658 {
659 cmd->deprecated_warn_user = 0;
660 cmd->cmd_deprecated = 0;
661 }
33f91161 662 cmd->replacement = replacement;
1f2bdf09 663 cmd->malloced_replacement = 1;
56382845
FN
664 return;
665 }
240f9570 666 xfree (replacement);
56382845
FN
667}
668
4f337972
AC
669/* Maintenance set/show framework. */
670
ae038cb0
DJ
671struct cmd_list_element *maintenance_set_cmdlist;
672struct cmd_list_element *maintenance_show_cmdlist;
4f337972 673
fdbc9870
PA
674/* "maintenance with" command. */
675
676static void
677maintenance_with_cmd (const char *args, int from_tty)
678{
679 with_command_1 ("maintenance set ", maintenance_set_cmdlist, args, from_tty);
680}
681
682/* "maintenance with" command completer. */
683
684static void
685maintenance_with_cmd_completer (struct cmd_list_element *ignore,
686 completion_tracker &tracker,
687 const char *text, const char * /*word*/)
688{
689 with_command_completer_1 ("maintenance set ", tracker, text);
690}
691
4f337972
AC
692/* Profiling support. */
693
491144b5 694static bool maintenance_profile_p;
920d2a44
AC
695static void
696show_maintenance_profile_p (struct ui_file *file, int from_tty,
697 struct cmd_list_element *c, const char *value)
698{
699 fprintf_filtered (file, _("Internal profiling is %s.\n"), value);
700}
d9feb4e7 701
b0b1c2c0
MK
702#ifdef HAVE__ETEXT
703extern char _etext;
704#define TEXTEND &_etext
01fe12f6 705#elif defined (HAVE_ETEXT)
b0b1c2c0
MK
706extern char etext;
707#define TEXTEND &etext
708#endif
709
01fe12f6
JB
710#if defined (HAVE_MONSTARTUP) && defined (HAVE__MCLEANUP) && defined (TEXTEND)
711
d28f9cdf
DJ
712static int profiling_state;
713
56000a98
PA
714EXTERN_C void _mcleanup (void);
715
d28f9cdf
DJ
716static void
717mcleanup_wrapper (void)
718{
d28f9cdf
DJ
719 if (profiling_state)
720 _mcleanup ();
721}
4f337972 722
56000a98
PA
723EXTERN_C void monstartup (unsigned long, unsigned long);
724extern int main ();
725
4f337972 726static void
eb4c3f4a 727maintenance_set_profile_cmd (const char *args, int from_tty,
3e43a32a 728 struct cmd_list_element *c)
4f337972 729{
d28f9cdf
DJ
730 if (maintenance_profile_p == profiling_state)
731 return;
732
733 profiling_state = maintenance_profile_p;
734
735 if (maintenance_profile_p)
736 {
737 static int profiling_initialized;
738
d28f9cdf
DJ
739 if (!profiling_initialized)
740 {
741 atexit (mcleanup_wrapper);
742 profiling_initialized = 1;
743 }
744
745 /* "main" is now always the first function in the text segment, so use
746 its address for monstartup. */
b0b1c2c0 747 monstartup ((unsigned long) &main, (unsigned long) TEXTEND);
d28f9cdf
DJ
748 }
749 else
750 {
751 extern void _mcleanup (void);
b8d56208 752
d28f9cdf
DJ
753 _mcleanup ();
754 }
4f337972 755}
d9feb4e7
DJ
756#else
757static void
eb4c3f4a 758maintenance_set_profile_cmd (const char *args, int from_tty,
3e43a32a 759 struct cmd_list_element *c)
d9feb4e7 760{
8a3fe4f8 761 error (_("Profiling support is not available on this system."));
d9feb4e7
DJ
762}
763#endif
22138db6 764
f1d293cc 765static int n_worker_threads = -1;
22138db6
TT
766
767/* Update the thread pool for the desired number of threads. */
768static void
769update_thread_pool_size ()
770{
771#if CXX_STD_THREAD
772 int n_threads = n_worker_threads;
773
774 if (n_threads < 0)
775 n_threads = std::thread::hardware_concurrency ();
776
777 gdb::thread_pool::g_thread_pool->set_thread_count (n_threads);
778#endif
779}
780
781static void
782maintenance_set_worker_threads (const char *args, int from_tty,
783 struct cmd_list_element *c)
784{
785 update_thread_pool_size ();
786}
787
bd712aed 788\f
491144b5 789/* If true, display time usage both at startup and for each command. */
56382845 790
491144b5 791static bool per_command_time;
bd712aed 792
491144b5 793/* If true, display space usage both at startup and for each command. */
bd712aed 794
491144b5 795static bool per_command_space;
bd712aed 796
491144b5 797/* If true, display basic symtab stats for each command. */
bd712aed 798
491144b5 799static bool per_command_symtab;
bd712aed
DE
800
801/* mt per-command commands. */
802
803static struct cmd_list_element *per_command_setlist;
804static struct cmd_list_element *per_command_showlist;
805
bd712aed
DE
806/* Set whether to display time statistics to NEW_VALUE
807 (non-zero means true). */
808
809void
810set_per_command_time (int new_value)
811{
812 per_command_time = new_value;
813}
814
815/* Set whether to display space statistics to NEW_VALUE
816 (non-zero means true). */
817
818void
819set_per_command_space (int new_value)
820{
821 per_command_space = new_value;
822}
823
824/* Count the number of symtabs and blocks. */
825
826static void
43f3e411 827count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr,
bd712aed
DE
828 int *nr_blocks_ptr)
829{
bd712aed 830 int nr_symtabs = 0;
43f3e411 831 int nr_compunit_symtabs = 0;
bd712aed
DE
832 int nr_blocks = 0;
833
b8b8facf
DE
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)
bd712aed 838 {
2030c079 839 for (objfile *o : current_program_space->objfiles ())
bd712aed 840 {
b669c953 841 for (compunit_symtab *cu : o->compunits ())
d8aeb77f
TT
842 {
843 ++nr_compunit_symtabs;
844 nr_blocks += BLOCKVECTOR_NBLOCKS (COMPUNIT_BLOCKVECTOR (cu));
5accd1a0
TT
845 nr_symtabs += std::distance (compunit_filetabs (cu).begin (),
846 compunit_filetabs (cu).end ());
d8aeb77f 847 }
bd712aed
DE
848 }
849 }
850
851 *nr_symtabs_ptr = nr_symtabs;
43f3e411 852 *nr_compunit_symtabs_ptr = nr_compunit_symtabs;
bd712aed
DE
853 *nr_blocks_ptr = nr_blocks;
854}
855
1e3b796d
TT
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
858 in this object. */
bd712aed 859
1e3b796d 860scoped_command_stats::~scoped_command_stats ()
bd712aed 861{
1e3b796d
TT
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. */
868 if (m_msg_type
869 && !per_command_time
870 && !per_command_space
871 && !per_command_symtab)
872 return;
bd712aed 873
1e3b796d 874 if (m_time_enabled && per_command_time)
bd712aed 875 {
3847a7bf
TT
876 print_time (_("command finished"));
877
dcb07cfa 878 using namespace std::chrono;
bd712aed 879
dcb07cfa
PA
880 run_time_clock::duration cmd_time
881 = run_time_clock::now () - m_start_cpu_time;
bd712aed 882
dcb07cfa
PA
883 steady_clock::duration wall_time
884 = steady_clock::now () - m_start_wall_time;
bd712aed 885 /* Subtract time spend in prompt_for_continue from walltime. */
dcb07cfa 886 wall_time -= get_prompt_for_continue_wait_time ();
bd712aed 887
1e3b796d 888 printf_unfiltered (!m_msg_type
dcb07cfa
PA
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 ());
bd712aed
DE
893 }
894
1e3b796d 895 if (m_space_enabled && per_command_space)
bd712aed 896 {
6242c6a6 897#ifdef HAVE_USEFUL_SBRK
bd712aed
DE
898 char *lim = (char *) sbrk (0);
899
900 long space_now = lim - lim_at_start;
1e3b796d 901 long space_diff = space_now - m_start_space;
bd712aed 902
1e3b796d 903 printf_unfiltered (!m_msg_type
bd712aed
DE
904 ? _("Space used: %ld (%s%ld during startup)\n")
905 : _("Space used: %ld (%s%ld for this command)\n"),
906 space_now,
907 (space_diff >= 0 ? "+" : ""),
908 space_diff);
909#endif
910 }
911
1e3b796d 912 if (m_symtab_enabled && per_command_symtab)
bd712aed 913 {
43f3e411 914 int nr_symtabs, nr_compunit_symtabs, nr_blocks;
bd712aed 915
43f3e411 916 count_symtabs_and_blocks (&nr_symtabs, &nr_compunit_symtabs, &nr_blocks);
bd712aed 917 printf_unfiltered (_("#symtabs: %d (+%d),"
43f3e411 918 " #compunits: %d (+%d),"
bd712aed
DE
919 " #blocks: %d (+%d)\n"),
920 nr_symtabs,
1e3b796d 921 nr_symtabs - m_start_nr_symtabs,
43f3e411
DE
922 nr_compunit_symtabs,
923 (nr_compunit_symtabs
1e3b796d 924 - m_start_nr_compunit_symtabs),
bd712aed 925 nr_blocks,
1e3b796d 926 nr_blocks - m_start_nr_blocks);
bd712aed
DE
927 }
928}
929
1e3b796d
TT
930scoped_command_stats::scoped_command_stats (bool msg_type)
931: m_msg_type (msg_type)
bd712aed 932{
1e3b796d 933 if (!m_msg_type || per_command_space)
bd712aed 934 {
6242c6a6 935#ifdef HAVE_USEFUL_SBRK
bd712aed 936 char *lim = (char *) sbrk (0);
1e3b796d
TT
937 m_start_space = lim - lim_at_start;
938 m_space_enabled = 1;
bd712aed
DE
939#endif
940 }
44d83468
PA
941 else
942 m_space_enabled = 0;
bd712aed 943
b8b8facf 944 if (msg_type == 0 || per_command_time)
bd712aed 945 {
dcb07cfa
PA
946 using namespace std::chrono;
947
948 m_start_cpu_time = run_time_clock::now ();
949 m_start_wall_time = steady_clock::now ();
1e3b796d 950 m_time_enabled = 1;
3847a7bf
TT
951
952 if (per_command_time)
953 print_time (_("command started"));
bd712aed 954 }
44d83468
PA
955 else
956 m_time_enabled = 0;
bd712aed 957
b8b8facf 958 if (msg_type == 0 || per_command_symtab)
bd712aed 959 {
43f3e411 960 int nr_symtabs, nr_compunit_symtabs, nr_blocks;
bd712aed 961
43f3e411 962 count_symtabs_and_blocks (&nr_symtabs, &nr_compunit_symtabs, &nr_blocks);
1e3b796d
TT
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;
bd712aed 967 }
44d83468
PA
968 else
969 m_symtab_enabled = 0;
bd712aed 970
26c4b26f 971 /* Initialize timer to keep track of how long we waited for the user. */
bd712aed 972 reset_prompt_for_continue_wait_time ();
bd712aed
DE
973}
974
3847a7bf
TT
975/* See maint.h. */
976
977void
978scoped_command_stats::print_time (const char *msg)
979{
980 using namespace std::chrono;
981
982 auto now = system_clock::now ();
983 auto ticks = now.time_since_epoch ().count () / (1000 * 1000);
984 auto millis = ticks % 1000;
985
986 std::time_t as_time = system_clock::to_time_t (now);
53fea9c7
CB
987 struct tm tm;
988 localtime_r (&as_time, &tm);
3847a7bf
TT
989
990 char out[100];
53fea9c7 991 strftime (out, sizeof (out), "%F %H:%M:%S", &tm);
3847a7bf
TT
992
993 printf_unfiltered ("%s.%03d - %s\n", out, (int) millis, msg);
994}
995
bd712aed
DE
996/* Handle unknown "mt set per-command" arguments.
997 In this case have "mt set per-command on|off" affect every setting. */
998
999static void
981a3fb3 1000set_per_command_cmd (const char *args, int from_tty)
bd712aed
DE
1001{
1002 struct cmd_list_element *list;
bd712aed
DE
1003 int val;
1004
1005 val = parse_cli_boolean_value (args);
1006 if (val < 0)
1007 error (_("Bad value for 'mt set per-command no'."));
1008
1009 for (list = per_command_setlist; list != NULL; list = list->next)
1010 if (list->var_type == var_boolean)
1011 {
1012 gdb_assert (list->type == set_cmd);
1013 do_set_command (args, from_tty, list);
1014 }
1015}
1016
dcd1f979
TT
1017\f
1018
1019/* The "maintenance selftest" command. */
1020
1021static void
58971144 1022maintenance_selftest (const char *args, int from_tty)
dcd1f979 1023{
1e5ded6c 1024#if GDB_SELF_TEST
ece5bc8a 1025 gdb_argv argv (args);
d369b608 1026 selftests::run_tests (argv.as_array_view ());
1e5ded6c
YQ
1027#else
1028 printf_filtered (_("\
8ecfd7bd 1029Selftests have been disabled for this build.\n"));
1e5ded6c 1030#endif
1526853e
SM
1031}
1032
1033static void
5fed81ff 1034maintenance_info_selftests (const char *arg, int from_tty)
1526853e 1035{
1e5ded6c 1036#if GDB_SELF_TEST
1526853e
SM
1037 printf_filtered ("Registered selftests:\n");
1038 selftests::for_each_selftest ([] (const std::string &name) {
1039 printf_filtered (" - %s\n", name.c_str ());
1040 });
1e5ded6c
YQ
1041#else
1042 printf_filtered (_("\
8ecfd7bd 1043Selftests have been disabled for this build.\n"));
1e5ded6c 1044#endif
dcd1f979
TT
1045}
1046
bd712aed 1047\f
6c265988 1048void _initialize_maint_cmds ();
c906108c 1049void
6c265988 1050_initialize_maint_cmds ()
c906108c 1051{
439250fb
DE
1052 struct cmd_list_element *cmd;
1053
0743fc83 1054 add_basic_prefix_cmd ("maintenance", class_maintenance, _("\
1bedd215 1055Commands for use by GDB maintainers.\n\
c906108c 1056Includes commands to dump specific internal GDB structures in\n\
439250fb 1057a human readable form, to cause GDB to deliberately dump core, etc."),
0743fc83
TT
1058 &maintenancelist, "maintenance ", 0,
1059 &cmdlist);
c906108c
SS
1060
1061 add_com_alias ("mt", "maintenance", class_maintenance, 1);
1062
0743fc83 1063 add_basic_prefix_cmd ("info", class_maintenance, _("\
1bedd215 1064Commands for showing internal info about the program being debugged."),
0743fc83
TT
1065 &maintenanceinfolist, "maintenance info ", 0,
1066 &maintenancelist);
90515c23 1067 add_alias_cmd ("i", "info", class_maintenance, 1, &maintenancelist);
c906108c 1068
1a966eab 1069 add_cmd ("sections", class_maintenance, maintenance_info_sections, _("\
590042fc 1070List the BFD sections of the exec and core files.\n\
e3d3bfda
MS
1071Arguments 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\
1075Sections matching any argument will be listed (no argument\n\
1076implies all sections). In addition, the special argument\n\
1077 ALLOBJ\n\
1a966eab 1078lists all sections from all object files, including shared libraries."),
c906108c
SS
1079 &maintenanceinfolist);
1080
0743fc83
TT
1081 add_basic_prefix_cmd ("print", class_maintenance,
1082 _("Maintenance command for printing GDB internal state."),
1083 &maintenanceprintlist, "maintenance print ", 0,
1084 &maintenancelist);
c906108c 1085
50a5f187
AB
1086 add_basic_prefix_cmd ("flush", class_maintenance,
1087 _("Maintenance command for flushing GDB internal caches."),
1088 &maintenanceflushlist, "maintenance flush ", 0,
1089 &maintenancelist);
1090
0743fc83 1091 add_basic_prefix_cmd ("set", class_maintenance, _("\
4f337972 1092Set GDB internal variables used by the GDB maintainer.\n\
1bedd215 1093Configure variables internal to GDB that aid in GDB's maintenance"),
0743fc83
TT
1094 &maintenance_set_cmdlist, "maintenance set ",
1095 0/*allow-unknown*/,
1096 &maintenancelist);
4f337972 1097
0743fc83 1098 add_show_prefix_cmd ("show", class_maintenance, _("\
4f337972 1099Show GDB internal variables used by the GDB maintainer.\n\
1bedd215 1100Configure variables internal to GDB that aid in GDB's maintenance"),
0743fc83
TT
1101 &maintenance_show_cmdlist, "maintenance show ",
1102 0/*allow-unknown*/,
1103 &maintenancelist);
4f337972 1104
fdbc9870
PA
1105 cmd = add_cmd ("with", class_maintenance, maintenance_with_cmd, _("\
1106Like \"with\", but works with \"maintenance set\" variables.\n\
1107Usage: maintenance with SETTING [VALUE] [-- COMMAND]\n\
1108With no COMMAND, repeats the last executed command.\n\
1109SETTING is any setting you can change with the \"maintenance set\"\n\
1110subcommands."),
1111 &maintenancelist);
1112 set_cmd_completer_handle_brkchars (cmd, maintenance_with_cmd_completer);
1113
c906108c 1114#ifndef _WIN32
1a966eab
AC
1115 add_cmd ("dump-me", class_maintenance, maintenance_dump_me, _("\
1116Get fatal error; make debugger dump its core.\n\
8308e54c 1117GDB sets its handling of SIGQUIT back to SIG_DFL and then sends\n\
1a966eab 1118itself a SIGQUIT signal."),
c906108c
SS
1119 &maintenancelist);
1120#endif
1121
1a966eab
AC
1122 add_cmd ("internal-error", class_maintenance,
1123 maintenance_internal_error, _("\
1124Give GDB an internal error.\n\
1125Cause GDB to behave as if an internal error was detected."),
7be570e7
JM
1126 &maintenancelist);
1127
1a966eab
AC
1128 add_cmd ("internal-warning", class_maintenance,
1129 maintenance_internal_warning, _("\
1130Give GDB an internal warning.\n\
1131Cause GDB to behave as if an internal warning was reported."),
dec43320
AC
1132 &maintenancelist);
1133
57fcfb1b
GB
1134 add_cmd ("demangler-warning", class_maintenance,
1135 maintenance_demangler_warning, _("\
1136Give GDB a demangler warning.\n\
1137Cause GDB to behave as if a demangler warning was reported."),
1138 &maintenancelist);
1139
439250fb
DE
1140 cmd = add_cmd ("demangle", class_maintenance, maintenance_demangle, _("\
1141This command has been moved to \"demangle\"."),
1142 &maintenancelist);
1143 deprecate_cmd (cmd, "demangle");
c906108c 1144
bd712aed
DE
1145 add_prefix_cmd ("per-command", class_maintenance, set_per_command_cmd, _("\
1146Per-command statistics settings."),
387cd15b 1147 &per_command_setlist, "maintenance set per-command ",
bd712aed
DE
1148 1/*allow-unknown*/, &maintenance_set_cmdlist);
1149
0743fc83 1150 add_show_prefix_cmd ("per-command", class_maintenance, _("\
bd712aed 1151Show per-command statistics settings."),
0743fc83
TT
1152 &per_command_showlist, "maintenance show per-command ",
1153 0/*allow-unknown*/, &maintenance_show_cmdlist);
bd712aed
DE
1154
1155 add_setshow_boolean_cmd ("time", class_maintenance,
1156 &per_command_time, _("\
1157Set whether to display per-command execution time."), _("\
1158Show whether to display per-command execution time."),
1159 _("\
1160If enabled, the execution time for each command will be\n\
1161displayed following the command's output."),
1162 NULL, NULL,
1163 &per_command_setlist, &per_command_showlist);
1164
1165 add_setshow_boolean_cmd ("space", class_maintenance,
1166 &per_command_space, _("\
1167Set whether to display per-command space usage."), _("\
1168Show whether to display per-command space usage."),
1169 _("\
1170If enabled, the space usage for each command will be\n\
1171displayed following the command's output."),
1172 NULL, NULL,
1173 &per_command_setlist, &per_command_showlist);
1174
1175 add_setshow_boolean_cmd ("symtab", class_maintenance,
1176 &per_command_symtab, _("\
1177Set whether to display per-command symtab statistics."), _("\
1178Show whether to display per-command symtab statistics."),
1179 _("\
1180If enabled, the basic symtab statistics for each command will be\n\
1181displayed following the command's output."),
1182 NULL, NULL,
1183 &per_command_setlist, &per_command_showlist);
1184
1185 /* This is equivalent to "mt set per-command time on".
1186 Kept because some people are used to typing "mt time 1". */
1a966eab
AC
1187 add_cmd ("time", class_maintenance, maintenance_time_display, _("\
1188Set the display of time usage.\n\
c906108c 1189If nonzero, will cause the execution time for each command to be\n\
1a966eab 1190displayed, following the command's output."),
c906108c
SS
1191 &maintenancelist);
1192
bd712aed
DE
1193 /* This is equivalent to "mt set per-command space on".
1194 Kept because some people are used to typing "mt space 1". */
1a966eab
AC
1195 add_cmd ("space", class_maintenance, maintenance_space_display, _("\
1196Set the display of space usage.\n\
c906108c 1197If nonzero, will cause the execution space for each command to be\n\
1a966eab 1198displayed, following the command's output."),
c906108c
SS
1199 &maintenancelist);
1200
a4915e8d 1201 cmd = add_cmd ("type", class_maintenance, maintenance_print_type, _("\
1a966eab 1202Print a type chain for a given symbol.\n\
c906108c 1203For each node in a type chain, print the raw data for each member of\n\
1a966eab 1204the type structure, and the interpretation of the data."),
c906108c 1205 &maintenanceprintlist);
a4915e8d 1206 set_cmd_completer (cmd, expression_completer);
c906108c 1207
c906108c 1208 add_cmd ("statistics", class_maintenance, maintenance_print_statistics,
1a966eab 1209 _("Print statistics about internal gdb state."),
c906108c
SS
1210 &maintenanceprintlist);
1211
1a966eab
AC
1212 add_cmd ("architecture", class_maintenance,
1213 maintenance_print_architecture, _("\
1214Print the internal architecture configuration.\n\
1215Takes an optional file parameter."),
4b9b3959
AC
1216 &maintenanceprintlist);
1217
0743fc83 1218 add_basic_prefix_cmd ("check", class_maintenance, _("\
27d41eac 1219Commands for checking internal gdb state."),
0743fc83
TT
1220 &maintenancechecklist, "maintenance check ", 0,
1221 &maintenancelist);
27d41eac 1222
3e43a32a
MS
1223 add_cmd ("translate-address", class_maintenance,
1224 maintenance_translate_address,
1a966eab 1225 _("Translate a section name and address to a symbol."),
c906108c
SS
1226 &maintenancelist);
1227
1a966eab 1228 add_cmd ("deprecate", class_maintenance, maintenance_deprecate, _("\
590042fc
PW
1229Deprecate a command (for testing purposes).\n\
1230Usage: maintenance deprecate COMMANDNAME [\"REPLACEMENT\"]\n\
1231This is used by the testsuite to check the command deprecator.\n\
1232You probably shouldn't use this,\n\
1233rather you should use the C function deprecate_cmd()."), &maintenancelist);
56382845 1234
1a966eab 1235 add_cmd ("undeprecate", class_maintenance, maintenance_undeprecate, _("\
590042fc
PW
1236Undeprecate a command (for testing purposes).\n\
1237Usage: maintenance undeprecate COMMANDNAME\n\
1238This is used by the testsuite to check the command deprecator.\n\
1239You probably shouldn't use this."),
33f91161 1240 &maintenancelist);
56382845 1241
dcd1f979
TT
1242 add_cmd ("selftest", class_maintenance, maintenance_selftest, _("\
1243Run gdb's unit tests.\n\
590042fc 1244Usage: maintenance selftest [FILTER]\n\
dcd1f979 1245This will run any unit tests that were built in to gdb.\n\
1526853e 1246If a filter is given, only the tests with that value in their name will ran."),
dcd1f979
TT
1247 &maintenancelist);
1248
1526853e
SM
1249 add_cmd ("selftests", class_maintenance, maintenance_info_selftests,
1250 _("List the registered selftests."), &maintenanceinfolist);
1251
d28f9cdf 1252 add_setshow_boolean_cmd ("profile", class_maintenance,
7915a72c
AC
1253 &maintenance_profile_p, _("\
1254Set internal profiling."), _("\
1255Show internal profiling."), _("\
1256When enabled GDB is profiled."),
2c5b56ce 1257 maintenance_set_profile_cmd,
920d2a44 1258 show_maintenance_profile_p,
d28f9cdf
DJ
1259 &maintenance_set_cmdlist,
1260 &maintenance_show_cmdlist);
22138db6
TT
1261
1262 add_setshow_zuinteger_unlimited_cmd ("worker-threads",
1263 class_maintenance,
1264 &n_worker_threads, _("\
1265Set the number of worker threads GDB can use."), _("\
1266Show the number of worker threads GDB can use."), _("\
1267GDB may use multiple threads to speed up certain CPU-intensive operations,\n\
1268such as demangling symbol names."),
1269 maintenance_set_worker_threads, NULL,
1270 &maintenance_set_cmdlist,
1271 &maintenance_show_cmdlist);
1272
1273 update_thread_pool_size ();
c906108c 1274}