* rs6000-tdep.c (BL_MASK, BL_INSTRUCTION, BL_DISPLACEMENT_MASK):
[deliverable/binutils-gdb.git] / gdb / maint.c
CommitLineData
c906108c 1/* Support for GDB maintenance commands.
c6f0559b 2
6aba47ca 3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002,
9b254dd1 4 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
c6f0559b 5
c906108c
SS
6 Written by Fred Fish at Cygnus Support.
7
c5aa993b 8 This file is part of GDB.
c906108c 9
c5aa993b
JM
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
a9762ec7 12 the Free Software Foundation; either version 3 of the License, or
c5aa993b 13 (at your option) any later version.
c906108c 14
c5aa993b
JM
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
c906108c 19
c5aa993b 20 You should have received a copy of the GNU General Public License
a9762ec7 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
22
23
24#include "defs.h"
c906108c
SS
25#include <ctype.h>
26#include <signal.h>
27#include "command.h"
28#include "gdbcmd.h"
29#include "symtab.h"
30#include "gdbtypes.h"
31#include "demangle.h"
32#include "gdbcore.h"
c5aa993b 33#include "expression.h" /* For language.h */
c906108c
SS
34#include "language.h"
35#include "symfile.h"
36#include "objfiles.h"
37#include "value.h"
38
18a642a1
AC
39#include "cli/cli-decode.h"
40
a14ed312 41extern void _initialize_maint_cmds (void);
392a587b 42
a14ed312 43static void maintenance_command (char *, int);
c906108c 44
a14ed312 45static void maintenance_internal_error (char *args, int from_tty);
7be570e7 46
a14ed312 47static void maintenance_demangle (char *, int);
c906108c 48
a14ed312 49static void maintenance_time_display (char *, int);
c906108c 50
a14ed312 51static void maintenance_space_display (char *, int);
c906108c 52
a14ed312 53static void maintenance_info_command (char *, int);
c906108c 54
a14ed312 55static void maintenance_info_sections (char *, int);
c906108c 56
a14ed312 57static void maintenance_print_command (char *, int);
c906108c 58
1c689132
DB
59static void maintenance_do_deprecate (char *, int);
60
c906108c
SS
61/* Set this to the maximum number of seconds to wait instead of waiting forever
62 in target_wait(). If this timer times out, then it generates an error and
63 the command is aborted. This replaces most of the need for timeouts in the
64 GDB test suite, and makes it possible to distinguish between a hung target
65 and one with slow communications. */
66
67int watchdog = 0;
920d2a44
AC
68static void
69show_watchdog (struct ui_file *file, int from_tty,
70 struct cmd_list_element *c, const char *value)
71{
72 fprintf_filtered (file, _("Watchdog timer is %s.\n"), value);
73}
c906108c
SS
74
75/*
76
c5aa993b 77 LOCAL FUNCTION
c906108c 78
c5aa993b 79 maintenance_command -- access the maintenance subcommands
c906108c 80
c5aa993b 81 SYNOPSIS
c906108c 82
c5aa993b 83 void maintenance_command (char *args, int from_tty)
c906108c 84
c5aa993b 85 DESCRIPTION
c906108c 86
c5aa993b 87 */
c906108c
SS
88
89static void
fba45db2 90maintenance_command (char *args, int from_tty)
c906108c 91{
a3f17187 92 printf_unfiltered (_("\"maintenance\" must be followed by the name of a maintenance command.\n"));
c906108c
SS
93 help_list (maintenancelist, "maintenance ", -1, gdb_stdout);
94}
95
96#ifndef _WIN32
c906108c 97static void
fba45db2 98maintenance_dump_me (char *args, int from_tty)
c906108c
SS
99{
100 if (query ("Should GDB dump core? "))
101 {
7be570e7
JM
102#ifdef __DJGPP__
103 /* SIGQUIT by default is ignored, so use SIGABRT instead. */
104 signal (SIGABRT, SIG_DFL);
105 kill (getpid (), SIGABRT);
106#else
c906108c
SS
107 signal (SIGQUIT, SIG_DFL);
108 kill (getpid (), SIGQUIT);
7be570e7 109#endif
c906108c
SS
110 }
111}
112#endif
113
7be570e7
JM
114/* Stimulate the internal error mechanism that GDB uses when an
115 internal problem is detected. Allows testing of the mechanism.
116 Also useful when the user wants to drop a core file but not exit
117 GDB. */
118
119static void
120maintenance_internal_error (char *args, int from_tty)
121{
dec43320
AC
122 internal_error (__FILE__, __LINE__, "%s", (args == NULL ? "" : args));
123}
124
125/* Stimulate the internal error mechanism that GDB uses when an
126 internal problem is detected. Allows testing of the mechanism.
127 Also useful when the user wants to drop a core file but not exit
128 GDB. */
129
130static void
131maintenance_internal_warning (char *args, int from_tty)
132{
133 internal_warning (__FILE__, __LINE__, "%s", (args == NULL ? "" : args));
7be570e7
JM
134}
135
33f91161
AC
136/* Someday we should allow demangling for things other than just
137 explicit strings. For example, we might want to be able to specify
138 the address of a string in either GDB's process space or the
139 debuggee's process space, and have gdb fetch and demangle that
140 string. If we have a char* pointer "ptr" that points to a string,
141 we might want to be able to given just the name and have GDB
142 demangle and print what it points to, etc. (FIXME) */
c906108c
SS
143
144static void
fba45db2 145maintenance_demangle (char *args, int from_tty)
c906108c
SS
146{
147 char *demangled;
148
149 if (args == NULL || *args == '\0')
150 {
a3f17187 151 printf_unfiltered (_("\"maintenance demangle\" takes an argument to demangle.\n"));
c906108c
SS
152 }
153 else
154 {
9a3d7dfd
AF
155 demangled = language_demangle (current_language, args,
156 DMGL_ANSI | DMGL_PARAMS);
c906108c
SS
157 if (demangled != NULL)
158 {
159 printf_unfiltered ("%s\n", demangled);
b8c9b27d 160 xfree (demangled);
c906108c
SS
161 }
162 else
163 {
a3f17187 164 printf_unfiltered (_("Can't demangle \"%s\"\n"), args);
c906108c
SS
165 }
166 }
167}
168
169static void
fba45db2 170maintenance_time_display (char *args, int from_tty)
c906108c
SS
171{
172 extern int display_time;
173
174 if (args == NULL || *args == '\0')
a3f17187 175 printf_unfiltered (_("\"maintenance time\" takes a numeric argument.\n"));
c906108c
SS
176 else
177 display_time = strtol (args, NULL, 10);
178}
179
180static void
fba45db2 181maintenance_space_display (char *args, int from_tty)
c906108c
SS
182{
183 extern int display_space;
184
185 if (args == NULL || *args == '\0')
186 printf_unfiltered ("\"maintenance space\" takes a numeric argument.\n");
187 else
188 display_space = strtol (args, NULL, 10);
189}
190
33f91161
AC
191/* The "maintenance info" command is defined as a prefix, with
192 allow_unknown 0. Therefore, its own definition is called only for
193 "maintenance info" with no args. */
c906108c 194
c906108c 195static void
fba45db2 196maintenance_info_command (char *arg, int from_tty)
c906108c 197{
a3f17187 198 printf_unfiltered (_("\"maintenance info\" must be followed by the name of an info command.\n"));
c906108c
SS
199 help_list (maintenanceinfolist, "maintenance info ", -1, gdb_stdout);
200}
201
a532ca62
MS
202/* Mini tokenizing lexer for 'maint info sections' command. */
203
204static int
473e38f3 205match_substring (const char *string, const char *substr)
a532ca62
MS
206{
207 int substr_len = strlen(substr);
473e38f3 208 const char *tok;
a532ca62
MS
209
210 while ((tok = strstr (string, substr)) != NULL)
211 {
212 /* Got a partial match. Is it a whole word? */
b01d807c
MS
213 if (tok == string
214 || tok[-1] == ' '
215 || tok[-1] == '\t')
a532ca62
MS
216 {
217 /* Token is delimited at the front... */
b01d807c
MS
218 if (tok[substr_len] == ' '
219 || tok[substr_len] == '\t'
220 || tok[substr_len] == '\0')
a532ca62
MS
221 {
222 /* Token is delimited at the rear. Got a whole-word match. */
223 return 1;
224 }
225 }
226 /* Token didn't match as a whole word. Advance and try again. */
227 string = tok + 1;
228 }
229 return 0;
230}
231
43155bc1
MS
232static int
233match_bfd_flags (char *string, flagword flags)
c906108c 234{
43155bc1 235 if (flags & SEC_ALLOC)
a532ca62 236 if (match_substring (string, "ALLOC"))
43155bc1
MS
237 return 1;
238 if (flags & SEC_LOAD)
a532ca62 239 if (match_substring (string, "LOAD"))
43155bc1
MS
240 return 1;
241 if (flags & SEC_RELOC)
a532ca62 242 if (match_substring (string, "RELOC"))
43155bc1
MS
243 return 1;
244 if (flags & SEC_READONLY)
a532ca62 245 if (match_substring (string, "READONLY"))
43155bc1
MS
246 return 1;
247 if (flags & SEC_CODE)
a532ca62 248 if (match_substring (string, "CODE"))
43155bc1
MS
249 return 1;
250 if (flags & SEC_DATA)
a532ca62 251 if (match_substring (string, "DATA"))
43155bc1
MS
252 return 1;
253 if (flags & SEC_ROM)
a532ca62 254 if (match_substring (string, "ROM"))
43155bc1
MS
255 return 1;
256 if (flags & SEC_CONSTRUCTOR)
a532ca62 257 if (match_substring (string, "CONSTRUCTOR"))
43155bc1
MS
258 return 1;
259 if (flags & SEC_HAS_CONTENTS)
a532ca62 260 if (match_substring (string, "HAS_CONTENTS"))
43155bc1
MS
261 return 1;
262 if (flags & SEC_NEVER_LOAD)
a532ca62 263 if (match_substring (string, "NEVER_LOAD"))
43155bc1
MS
264 return 1;
265 if (flags & SEC_COFF_SHARED_LIBRARY)
a532ca62 266 if (match_substring (string, "COFF_SHARED_LIBRARY"))
43155bc1
MS
267 return 1;
268 if (flags & SEC_IS_COMMON)
a532ca62 269 if (match_substring (string, "IS_COMMON"))
43155bc1 270 return 1;
c906108c 271
43155bc1
MS
272 return 0;
273}
c906108c 274
43155bc1
MS
275static void
276print_bfd_flags (flagword flags)
277{
c906108c
SS
278 if (flags & SEC_ALLOC)
279 printf_filtered (" ALLOC");
280 if (flags & SEC_LOAD)
281 printf_filtered (" LOAD");
282 if (flags & SEC_RELOC)
283 printf_filtered (" RELOC");
284 if (flags & SEC_READONLY)
285 printf_filtered (" READONLY");
286 if (flags & SEC_CODE)
287 printf_filtered (" CODE");
288 if (flags & SEC_DATA)
289 printf_filtered (" DATA");
290 if (flags & SEC_ROM)
291 printf_filtered (" ROM");
292 if (flags & SEC_CONSTRUCTOR)
293 printf_filtered (" CONSTRUCTOR");
294 if (flags & SEC_HAS_CONTENTS)
295 printf_filtered (" HAS_CONTENTS");
296 if (flags & SEC_NEVER_LOAD)
297 printf_filtered (" NEVER_LOAD");
298 if (flags & SEC_COFF_SHARED_LIBRARY)
299 printf_filtered (" COFF_SHARED_LIBRARY");
300 if (flags & SEC_IS_COMMON)
301 printf_filtered (" IS_COMMON");
43155bc1
MS
302}
303
304static void
67a2b77e
AC
305maint_print_section_info (const char *name, flagword flags,
306 CORE_ADDR addr, CORE_ADDR endaddr,
307 unsigned long filepos)
43155bc1 308{
50ee7535 309 /* FIXME-32x64: Need paddress with field width. */
e3d3bfda
MS
310 printf_filtered (" 0x%s", paddr (addr));
311 printf_filtered ("->0x%s", paddr (endaddr));
3ab13650 312 printf_filtered (" at %s",
bb599908 313 hex_string_custom ((unsigned long) filepos, 8));
e3d3bfda
MS
314 printf_filtered (": %s", name);
315 print_bfd_flags (flags);
316 printf_filtered ("\n");
317}
c906108c 318
e3d3bfda
MS
319static void
320print_bfd_section_info (bfd *abfd,
321 asection *asect,
322 void *arg)
323{
324 flagword flags = bfd_get_section_flags (abfd, asect);
325 const char *name = bfd_section_name (abfd, asect);
326
b01d807c
MS
327 if (arg == NULL || *((char *) arg) == '\0'
328 || match_substring ((char *) arg, name)
329 || match_bfd_flags ((char *) arg, flags))
e3d3bfda
MS
330 {
331 CORE_ADDR addr, endaddr;
332
333 addr = bfd_section_vma (abfd, asect);
334 endaddr = addr + bfd_section_size (abfd, asect);
67a2b77e 335 maint_print_section_info (name, flags, addr, endaddr, asect->filepos);
e3d3bfda
MS
336 }
337}
338
339static void
340print_objfile_section_info (bfd *abfd,
341 struct obj_section *asect,
342 char *string)
343{
344 flagword flags = bfd_get_section_flags (abfd, asect->the_bfd_section);
345 const char *name = bfd_section_name (abfd, asect->the_bfd_section);
43155bc1 346
b01d807c
MS
347 if (string == NULL || *string == '\0'
348 || match_substring (string, name)
349 || match_bfd_flags (string, flags))
43155bc1 350 {
67a2b77e 351 maint_print_section_info (name, flags, asect->addr, asect->endaddr,
e3d3bfda 352 asect->the_bfd_section->filepos);
43155bc1 353 }
c906108c
SS
354}
355
c906108c 356static void
fba45db2 357maintenance_info_sections (char *arg, int from_tty)
c906108c
SS
358{
359 if (exec_bfd)
360 {
a3f17187 361 printf_filtered (_("Exec file:\n"));
c5aa993b 362 printf_filtered (" `%s', ", bfd_get_filename (exec_bfd));
c906108c 363 wrap_here (" ");
a3f17187 364 printf_filtered (_("file type %s.\n"), bfd_get_target (exec_bfd));
a532ca62 365 if (arg && *arg && match_substring (arg, "ALLOBJ"))
e3d3bfda
MS
366 {
367 struct objfile *ofile;
368 struct obj_section *osect;
369
370 /* Only this function cares about the 'ALLOBJ' argument;
371 if 'ALLOBJ' is the only argument, discard it rather than
372 passing it down to print_objfile_section_info (which
373 wouldn't know how to handle it). */
374 if (strcmp (arg, "ALLOBJ") == 0)
375 arg = NULL;
376
377 ALL_OBJFILES (ofile)
378 {
a3f17187 379 printf_filtered (_(" Object file: %s\n"),
e3d3bfda
MS
380 bfd_get_filename (ofile->obfd));
381 ALL_OBJFILE_OSECTIONS (ofile, osect)
382 {
383 print_objfile_section_info (ofile->obfd, osect, arg);
384 }
385 }
386 }
387 else
388 bfd_map_over_sections (exec_bfd, print_bfd_section_info, arg);
c906108c
SS
389 }
390
391 if (core_bfd)
392 {
a3f17187 393 printf_filtered (_("Core file:\n"));
c5aa993b 394 printf_filtered (" `%s', ", bfd_get_filename (core_bfd));
c906108c 395 wrap_here (" ");
a3f17187 396 printf_filtered (_("file type %s.\n"), bfd_get_target (core_bfd));
e3d3bfda 397 bfd_map_over_sections (core_bfd, print_bfd_section_info, arg);
c906108c
SS
398 }
399}
400
c906108c 401void
fba45db2 402maintenance_print_statistics (char *args, int from_tty)
c906108c
SS
403{
404 print_objfile_statistics ();
405 print_symbol_bcache_statistics ();
406}
407
b9362cc7 408static void
4b9b3959
AC
409maintenance_print_architecture (char *args, int from_tty)
410{
411 if (args == NULL)
412 gdbarch_dump (current_gdbarch, gdb_stdout);
413 else
414 {
415 struct ui_file *file = gdb_fopen (args, "w");
416 if (file == NULL)
e2e0b3e5 417 perror_with_name (_("maintenance print architecture"));
4b9b3959
AC
418 gdbarch_dump (current_gdbarch, file);
419 ui_file_delete (file);
420 }
421}
422
33f91161
AC
423/* The "maintenance print" command is defined as a prefix, with
424 allow_unknown 0. Therefore, its own definition is called only for
425 "maintenance print" with no args. */
c906108c 426
c906108c 427static void
fba45db2 428maintenance_print_command (char *arg, int from_tty)
c906108c 429{
a3f17187 430 printf_unfiltered (_("\"maintenance print\" must be followed by the name of a print command.\n"));
c906108c
SS
431 help_list (maintenanceprintlist, "maintenance print ", -1, gdb_stdout);
432}
433
434/* The "maintenance translate-address" command converts a section and address
435 to a symbol. This can be called in two ways:
c5aa993b
JM
436 maintenance translate-address <secname> <addr>
437 or maintenance translate-address <addr>
438 */
c906108c
SS
439
440static void
fba45db2 441maintenance_translate_address (char *arg, int from_tty)
c906108c
SS
442{
443 CORE_ADDR address;
444 asection *sect;
445 char *p;
446 struct minimal_symbol *sym;
447 struct objfile *objfile;
448
449 if (arg == NULL || *arg == 0)
8a3fe4f8 450 error (_("requires argument (address or section + address)"));
c906108c
SS
451
452 sect = NULL;
453 p = arg;
454
455 if (!isdigit (*p))
456 { /* See if we have a valid section name */
c5aa993b 457 while (*p && !isspace (*p)) /* Find end of section name */
c906108c
SS
458 p++;
459 if (*p == '\000') /* End of command? */
8a3fe4f8 460 error (_("Need to specify <section-name> and <address>"));
c906108c 461 *p++ = '\000';
c5aa993b
JM
462 while (isspace (*p))
463 p++; /* Skip whitespace */
c906108c
SS
464
465 ALL_OBJFILES (objfile)
c5aa993b
JM
466 {
467 sect = bfd_get_section_by_name (objfile->obfd, arg);
468 if (sect != NULL)
469 break;
470 }
c906108c
SS
471
472 if (!sect)
8a3fe4f8 473 error (_("Unknown section %s."), arg);
c906108c
SS
474 }
475
476 address = parse_and_eval_address (p);
477
478 if (sect)
479 sym = lookup_minimal_symbol_by_pc_section (address, sect);
480 else
481 sym = lookup_minimal_symbol_by_pc (address);
482
483 if (sym)
d4f3574e 484 printf_filtered ("%s+%s\n",
de5ad195 485 SYMBOL_PRINT_NAME (sym),
d4f3574e 486 paddr_u (address - SYMBOL_VALUE_ADDRESS (sym)));
c906108c 487 else if (sect)
a3f17187 488 printf_filtered (_("no symbol at %s:0x%s\n"), sect->name, paddr (address));
c906108c 489 else
a3f17187 490 printf_filtered (_("no symbol at 0x%s\n"), paddr (address));
c906108c
SS
491
492 return;
493}
494
56382845 495
c114dcd5 496/* When a command is deprecated the user will be warned the first time
33f91161
AC
497 the command is used. If possible, a replacement will be
498 offered. */
56382845
FN
499
500static void
501maintenance_deprecate (char *args, int from_tty)
502{
503 if (args == NULL || *args == '\0')
504 {
a3f17187 505 printf_unfiltered (_("\"maintenance deprecate\" takes an argument, \n\
56382845 506the command you want to deprecate, and optionally the replacement command \n\
a3f17187 507enclosed in quotes.\n"));
56382845 508 }
33f91161 509
56382845
FN
510 maintenance_do_deprecate (args, 1);
511
512}
513
514
515static void
516maintenance_undeprecate (char *args, int from_tty)
517{
518 if (args == NULL || *args == '\0')
519 {
a3f17187
AC
520 printf_unfiltered (_("\"maintenance undeprecate\" takes an argument, \n\
521the command you want to undeprecate.\n"));
56382845 522 }
33f91161 523
56382845 524 maintenance_do_deprecate (args, 0);
33f91161 525
56382845
FN
526}
527
33f91161
AC
528/* You really shouldn't be using this. It is just for the testsuite.
529 Rather, you should use deprecate_cmd() when the command is created
530 in _initialize_blah().
531
532 This function deprecates a command and optionally assigns it a
533 replacement. */
534
8399535b 535static void
33f91161
AC
536maintenance_do_deprecate (char *text, int deprecate)
537{
538
539 struct cmd_list_element *alias = NULL;
540 struct cmd_list_element *prefix_cmd = NULL;
541 struct cmd_list_element *cmd = NULL;
542
543 char *start_ptr = NULL;
544 char *end_ptr = NULL;
56382845 545 int len;
33f91161
AC
546 char *replacement = NULL;
547
1c689132
DB
548 if (text == NULL)
549 return;
56382845 550
33f91161
AC
551 if (!lookup_cmd_composition (text, &alias, &prefix_cmd, &cmd))
552 {
a3f17187 553 printf_filtered (_("Can't find command '%s' to deprecate.\n"), text);
33f91161
AC
554 return;
555 }
56382845 556
56382845
FN
557 if (deprecate)
558 {
559 /* look for a replacement command */
80ce1ecb
AC
560 start_ptr = strchr (text, '\"');
561 if (start_ptr != NULL)
33f91161
AC
562 {
563 start_ptr++;
80ce1ecb
AC
564 end_ptr = strrchr (start_ptr, '\"');
565 if (end_ptr != NULL)
33f91161
AC
566 {
567 len = end_ptr - start_ptr;
568 start_ptr[len] = '\0';
569 replacement = xstrdup (start_ptr);
570 }
571 }
56382845 572 }
33f91161 573
56382845
FN
574 if (!start_ptr || !end_ptr)
575 replacement = NULL;
33f91161
AC
576
577
56382845 578 /* If they used an alias, we only want to deprecate the alias.
33f91161 579
56382845
FN
580 Note the MALLOCED_REPLACEMENT test. If the command's replacement
581 string was allocated at compile time we don't want to free the
33f91161 582 memory. */
56382845
FN
583 if (alias)
584 {
33f91161 585
56382845 586 if (alias->flags & MALLOCED_REPLACEMENT)
b8c9b27d 587 xfree (alias->replacement);
33f91161 588
56382845 589 if (deprecate)
33f91161 590 alias->flags |= (DEPRECATED_WARN_USER | CMD_DEPRECATED);
56382845 591 else
33f91161
AC
592 alias->flags &= ~(DEPRECATED_WARN_USER | CMD_DEPRECATED);
593 alias->replacement = replacement;
56382845
FN
594 alias->flags |= MALLOCED_REPLACEMENT;
595 return;
596 }
597 else if (cmd)
598 {
599 if (cmd->flags & MALLOCED_REPLACEMENT)
b8c9b27d 600 xfree (cmd->replacement);
56382845
FN
601
602 if (deprecate)
33f91161 603 cmd->flags |= (DEPRECATED_WARN_USER | CMD_DEPRECATED);
56382845 604 else
33f91161
AC
605 cmd->flags &= ~(DEPRECATED_WARN_USER | CMD_DEPRECATED);
606 cmd->replacement = replacement;
56382845
FN
607 cmd->flags |= MALLOCED_REPLACEMENT;
608 return;
609 }
610}
611
4f337972
AC
612/* Maintenance set/show framework. */
613
ae038cb0
DJ
614struct cmd_list_element *maintenance_set_cmdlist;
615struct cmd_list_element *maintenance_show_cmdlist;
4f337972
AC
616
617static void
618maintenance_set_cmd (char *args, int from_tty)
619{
a3f17187 620 printf_unfiltered (_("\"maintenance set\" must be followed by the name of a set command.\n"));
4f337972
AC
621 help_list (maintenance_set_cmdlist, "maintenance set ", -1, gdb_stdout);
622}
623
624static void
625maintenance_show_cmd (char *args, int from_tty)
626{
627 cmd_show_list (maintenance_show_cmdlist, from_tty, "");
628}
629
4f337972
AC
630/* Profiling support. */
631
632static int maintenance_profile_p;
920d2a44
AC
633static void
634show_maintenance_profile_p (struct ui_file *file, int from_tty,
635 struct cmd_list_element *c, const char *value)
636{
637 fprintf_filtered (file, _("Internal profiling is %s.\n"), value);
638}
d9feb4e7 639
b0b1c2c0
MK
640#ifdef HAVE__ETEXT
641extern char _etext;
642#define TEXTEND &_etext
01fe12f6 643#elif defined (HAVE_ETEXT)
b0b1c2c0
MK
644extern char etext;
645#define TEXTEND &etext
646#endif
647
01fe12f6
JB
648#if defined (HAVE_MONSTARTUP) && defined (HAVE__MCLEANUP) && defined (TEXTEND)
649
d28f9cdf
DJ
650static int profiling_state;
651
652static void
653mcleanup_wrapper (void)
654{
655 extern void _mcleanup (void);
656
657 if (profiling_state)
658 _mcleanup ();
659}
4f337972
AC
660
661static void
662maintenance_set_profile_cmd (char *args, int from_tty, struct cmd_list_element *c)
663{
d28f9cdf
DJ
664 if (maintenance_profile_p == profiling_state)
665 return;
666
667 profiling_state = maintenance_profile_p;
668
669 if (maintenance_profile_p)
670 {
671 static int profiling_initialized;
672
673 extern void monstartup (unsigned long, unsigned long);
d28f9cdf
DJ
674 extern int main();
675
676 if (!profiling_initialized)
677 {
678 atexit (mcleanup_wrapper);
679 profiling_initialized = 1;
680 }
681
682 /* "main" is now always the first function in the text segment, so use
683 its address for monstartup. */
b0b1c2c0 684 monstartup ((unsigned long) &main, (unsigned long) TEXTEND);
d28f9cdf
DJ
685 }
686 else
687 {
688 extern void _mcleanup (void);
689 _mcleanup ();
690 }
4f337972 691}
d9feb4e7
DJ
692#else
693static void
694maintenance_set_profile_cmd (char *args, int from_tty, struct cmd_list_element *c)
695{
8a3fe4f8 696 error (_("Profiling support is not available on this system."));
d9feb4e7
DJ
697}
698#endif
56382845 699
c906108c 700void
fba45db2 701_initialize_maint_cmds (void)
c906108c 702{
4f337972
AC
703 struct cmd_list_element *tmpcmd;
704
1bedd215
AC
705 add_prefix_cmd ("maintenance", class_maintenance, maintenance_command, _("\
706Commands for use by GDB maintainers.\n\
c906108c
SS
707Includes commands to dump specific internal GDB structures in\n\
708a human readable form, to cause GDB to deliberately dump core,\n\
1bedd215 709to test internal functions such as the C++/ObjC demangler, etc."),
c906108c
SS
710 &maintenancelist, "maintenance ", 0,
711 &cmdlist);
712
713 add_com_alias ("mt", "maintenance", class_maintenance, 1);
714
1bedd215
AC
715 add_prefix_cmd ("info", class_maintenance, maintenance_info_command, _("\
716Commands for showing internal info about the program being debugged."),
c906108c
SS
717 &maintenanceinfolist, "maintenance info ", 0,
718 &maintenancelist);
90515c23 719 add_alias_cmd ("i", "info", class_maintenance, 1, &maintenancelist);
c906108c 720
1a966eab
AC
721 add_cmd ("sections", class_maintenance, maintenance_info_sections, _("\
722List the BFD sections of the exec and core files. \n\
e3d3bfda
MS
723Arguments may be any combination of:\n\
724 [one or more section names]\n\
725 ALLOC LOAD RELOC READONLY CODE DATA ROM CONSTRUCTOR\n\
726 HAS_CONTENTS NEVER_LOAD COFF_SHARED_LIBRARY IS_COMMON\n\
727Sections matching any argument will be listed (no argument\n\
728implies all sections). In addition, the special argument\n\
729 ALLOBJ\n\
1a966eab 730lists all sections from all object files, including shared libraries."),
c906108c
SS
731 &maintenanceinfolist);
732
733 add_prefix_cmd ("print", class_maintenance, maintenance_print_command,
1bedd215 734 _("Maintenance command for printing GDB internal state."),
c906108c
SS
735 &maintenanceprintlist, "maintenance print ", 0,
736 &maintenancelist);
737
1bedd215 738 add_prefix_cmd ("set", class_maintenance, maintenance_set_cmd, _("\
4f337972 739Set GDB internal variables used by the GDB maintainer.\n\
1bedd215 740Configure variables internal to GDB that aid in GDB's maintenance"),
4f337972
AC
741 &maintenance_set_cmdlist, "maintenance set ",
742 0/*allow-unknown*/,
743 &maintenancelist);
744
1bedd215 745 add_prefix_cmd ("show", class_maintenance, maintenance_show_cmd, _("\
4f337972 746Show GDB internal variables used by the GDB maintainer.\n\
1bedd215 747Configure variables internal to GDB that aid in GDB's maintenance"),
4f337972
AC
748 &maintenance_show_cmdlist, "maintenance show ",
749 0/*allow-unknown*/,
750 &maintenancelist);
751
c906108c 752#ifndef _WIN32
1a966eab
AC
753 add_cmd ("dump-me", class_maintenance, maintenance_dump_me, _("\
754Get fatal error; make debugger dump its core.\n\
8308e54c 755GDB sets its handling of SIGQUIT back to SIG_DFL and then sends\n\
1a966eab 756itself a SIGQUIT signal."),
c906108c
SS
757 &maintenancelist);
758#endif
759
1a966eab
AC
760 add_cmd ("internal-error", class_maintenance,
761 maintenance_internal_error, _("\
762Give GDB an internal error.\n\
763Cause GDB to behave as if an internal error was detected."),
7be570e7
JM
764 &maintenancelist);
765
1a966eab
AC
766 add_cmd ("internal-warning", class_maintenance,
767 maintenance_internal_warning, _("\
768Give GDB an internal warning.\n\
769Cause GDB to behave as if an internal warning was reported."),
dec43320
AC
770 &maintenancelist);
771
1a966eab
AC
772 add_cmd ("demangle", class_maintenance, maintenance_demangle, _("\
773Demangle a C++/ObjC mangled name.\n\
c906108c 774Call internal GDB demangler routine to demangle a C++ link name\n\
1a966eab 775and prints the result."),
c906108c
SS
776 &maintenancelist);
777
1a966eab
AC
778 add_cmd ("time", class_maintenance, maintenance_time_display, _("\
779Set the display of time usage.\n\
c906108c 780If nonzero, will cause the execution time for each command to be\n\
1a966eab 781displayed, following the command's output."),
c906108c
SS
782 &maintenancelist);
783
1a966eab
AC
784 add_cmd ("space", class_maintenance, maintenance_space_display, _("\
785Set the display of space usage.\n\
c906108c 786If nonzero, will cause the execution space for each command to be\n\
1a966eab 787displayed, following the command's output."),
c906108c
SS
788 &maintenancelist);
789
1a966eab
AC
790 add_cmd ("type", class_maintenance, maintenance_print_type, _("\
791Print a type chain for a given symbol.\n\
c906108c 792For each node in a type chain, print the raw data for each member of\n\
1a966eab 793the type structure, and the interpretation of the data."),
c906108c
SS
794 &maintenanceprintlist);
795
1a966eab
AC
796 add_cmd ("symbols", class_maintenance, maintenance_print_symbols, _("\
797Print dump of current symbol definitions.\n\
c906108c 798Entries in the full symbol table are dumped to file OUTFILE.\n\
1a966eab 799If a SOURCE file is specified, dump only that file's symbols."),
c906108c
SS
800 &maintenanceprintlist);
801
1a966eab
AC
802 add_cmd ("msymbols", class_maintenance, maintenance_print_msymbols, _("\
803Print dump of current minimal symbol definitions.\n\
c906108c 804Entries in the minimal symbol table are dumped to file OUTFILE.\n\
1a966eab 805If a SOURCE file is specified, dump only that file's minimal symbols."),
c906108c
SS
806 &maintenanceprintlist);
807
1a966eab
AC
808 add_cmd ("psymbols", class_maintenance, maintenance_print_psymbols, _("\
809Print dump of current partial symbol definitions.\n\
c906108c 810Entries in the partial symbol table are dumped to file OUTFILE.\n\
1a966eab 811If a SOURCE file is specified, dump only that file's partial symbols."),
c906108c
SS
812 &maintenanceprintlist);
813
814 add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles,
1a966eab 815 _("Print dump of current object file definitions."),
c906108c
SS
816 &maintenanceprintlist);
817
1a966eab
AC
818 add_cmd ("symtabs", class_maintenance, maintenance_info_symtabs, _("\
819List the full symbol tables for all object files.\n\
44ea7b70
JB
820This does not include information about individual symbols, blocks, or\n\
821linetables --- just the symbol table structures themselves.\n\
1a966eab 822With an argument REGEXP, list the symbol tables whose names that match that."),
5e7b2f39 823 &maintenanceinfolist);
44ea7b70 824
1a966eab
AC
825 add_cmd ("psymtabs", class_maintenance, maintenance_info_psymtabs, _("\
826List the partial symbol tables for all object files.\n\
44ea7b70 827This does not include information about individual partial symbols,\n\
1a966eab 828just the symbol table structures themselves."),
5e7b2f39 829 &maintenanceinfolist);
44ea7b70 830
c906108c 831 add_cmd ("statistics", class_maintenance, maintenance_print_statistics,
1a966eab 832 _("Print statistics about internal gdb state."),
c906108c
SS
833 &maintenanceprintlist);
834
1a966eab
AC
835 add_cmd ("architecture", class_maintenance,
836 maintenance_print_architecture, _("\
837Print the internal architecture configuration.\n\
838Takes an optional file parameter."),
4b9b3959
AC
839 &maintenanceprintlist);
840
c906108c 841 add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
1a966eab 842 _("Check consistency of psymtabs and symtabs."),
c906108c
SS
843 &maintenancelist);
844
845 add_cmd ("translate-address", class_maintenance, maintenance_translate_address,
1a966eab 846 _("Translate a section name and address to a symbol."),
c906108c
SS
847 &maintenancelist);
848
1a966eab
AC
849 add_cmd ("deprecate", class_maintenance, maintenance_deprecate, _("\
850Deprecate a command. Note that this is just in here so the \n\
56382845
FN
851testsuite can check the comamnd deprecator. You probably shouldn't use this,\n\
852rather you should use the C function deprecate_cmd(). If you decide you \n\
6f122dc9 853want to use it: maintenance deprecate 'commandname' \"replacement\". The \n\
1a966eab 854replacement is optional."), &maintenancelist);
56382845 855
1a966eab
AC
856 add_cmd ("undeprecate", class_maintenance, maintenance_undeprecate, _("\
857Undeprecate a command. Note that this is just in here so the \n\
56382845 858testsuite can check the comamnd deprecator. You probably shouldn't use this,\n\
1a966eab 859If you decide you want to use it: maintenance undeprecate 'commandname'"),
33f91161 860 &maintenancelist);
56382845 861
85c07804
AC
862 add_setshow_zinteger_cmd ("watchdog", class_maintenance, &watchdog, _("\
863Set watchdog timer."), _("\
864Show watchdog timer."), _("\
cb1a6d5f
AC
865When non-zero, this timeout is used instead of waiting forever for a target\n\
866to finish a low-level step or continue operation. If the specified amount\n\
85c07804
AC
867of time passes without a response from the target, an error occurs."),
868 NULL,
920d2a44 869 show_watchdog,
85c07804 870 &setlist, &showlist);
4f337972 871
d28f9cdf 872 add_setshow_boolean_cmd ("profile", class_maintenance,
7915a72c
AC
873 &maintenance_profile_p, _("\
874Set internal profiling."), _("\
875Show internal profiling."), _("\
876When enabled GDB is profiled."),
2c5b56ce 877 maintenance_set_profile_cmd,
920d2a44 878 show_maintenance_profile_p,
d28f9cdf
DJ
879 &maintenance_set_cmdlist,
880 &maintenance_show_cmdlist);
c906108c 881}
This page took 0.782538 seconds and 4 git commands to generate.