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