maint.c 43 KB

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