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