Fix whitespace problem in my most recent entry.
[deliverable/binutils-gdb.git] / gdb / maint.c
CommitLineData
c906108c 1/* Support for GDB maintenance commands.
8e65ff28 2 Copyright 1992, 1993, 1994, 2001 Free Software Foundation, Inc.
c906108c
SS
3 Written by Fred Fish at Cygnus Support.
4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
c906108c 11
c5aa993b
JM
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
c906108c 16
c5aa993b
JM
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
c906108c
SS
21
22
23#include "defs.h"
c906108c
SS
24#include <ctype.h>
25#include <signal.h>
26#include "command.h"
27#include "gdbcmd.h"
28#include "symtab.h"
29#include "gdbtypes.h"
30#include "demangle.h"
31#include "gdbcore.h"
c5aa993b 32#include "expression.h" /* For language.h */
c906108c
SS
33#include "language.h"
34#include "symfile.h"
35#include "objfiles.h"
36#include "value.h"
37
a14ed312 38extern void _initialize_maint_cmds (void);
392a587b 39
a14ed312 40static void maintenance_command (char *, int);
c906108c 41
a14ed312 42static void maintenance_dump_me (char *, int);
c906108c 43
a14ed312 44static void maintenance_internal_error (char *args, int from_tty);
7be570e7 45
a14ed312 46static void maintenance_demangle (char *, int);
c906108c 47
a14ed312 48static void maintenance_time_display (char *, int);
c906108c 49
a14ed312 50static void maintenance_space_display (char *, int);
c906108c 51
a14ed312 52static void maintenance_info_command (char *, int);
c906108c 53
a14ed312 54static void print_section_table (bfd *, asection *, PTR);
c906108c 55
a14ed312 56static void maintenance_info_sections (char *, int);
c906108c 57
a14ed312 58static void maintenance_print_command (char *, int);
c906108c 59
1c689132
DB
60static void maintenance_do_deprecate (char *, int);
61
c906108c
SS
62/* Set this to the maximum number of seconds to wait instead of waiting forever
63 in target_wait(). If this timer times out, then it generates an error and
64 the command is aborted. This replaces most of the need for timeouts in the
65 GDB test suite, and makes it possible to distinguish between a hung target
66 and one with slow communications. */
67
68int watchdog = 0;
69
70/*
71
c5aa993b 72 LOCAL FUNCTION
c906108c 73
c5aa993b 74 maintenance_command -- access the maintenance subcommands
c906108c 75
c5aa993b 76 SYNOPSIS
c906108c 77
c5aa993b 78 void maintenance_command (char *args, int from_tty)
c906108c 79
c5aa993b 80 DESCRIPTION
c906108c 81
c5aa993b 82 */
c906108c
SS
83
84static void
fba45db2 85maintenance_command (char *args, int from_tty)
c906108c
SS
86{
87 printf_unfiltered ("\"maintenance\" must be followed by the name of a maintenance command.\n");
88 help_list (maintenancelist, "maintenance ", -1, gdb_stdout);
89}
90
91#ifndef _WIN32
92/* ARGSUSED */
93static void
fba45db2 94maintenance_dump_me (char *args, int from_tty)
c906108c
SS
95{
96 if (query ("Should GDB dump core? "))
97 {
7be570e7
JM
98#ifdef __DJGPP__
99 /* SIGQUIT by default is ignored, so use SIGABRT instead. */
100 signal (SIGABRT, SIG_DFL);
101 kill (getpid (), SIGABRT);
102#else
c906108c
SS
103 signal (SIGQUIT, SIG_DFL);
104 kill (getpid (), SIGQUIT);
7be570e7 105#endif
c906108c
SS
106 }
107}
108#endif
109
7be570e7
JM
110/* Stimulate the internal error mechanism that GDB uses when an
111 internal problem is detected. Allows testing of the mechanism.
112 Also useful when the user wants to drop a core file but not exit
113 GDB. */
114
115static void
116maintenance_internal_error (char *args, int from_tty)
117{
8e65ff28
AC
118 internal_error (__FILE__, __LINE__,
119 "internal maintenance");
7be570e7
JM
120}
121
33f91161
AC
122/* Someday we should allow demangling for things other than just
123 explicit strings. For example, we might want to be able to specify
124 the address of a string in either GDB's process space or the
125 debuggee's process space, and have gdb fetch and demangle that
126 string. If we have a char* pointer "ptr" that points to a string,
127 we might want to be able to given just the name and have GDB
128 demangle and print what it points to, etc. (FIXME) */
c906108c
SS
129
130static void
fba45db2 131maintenance_demangle (char *args, int from_tty)
c906108c
SS
132{
133 char *demangled;
134
135 if (args == NULL || *args == '\0')
136 {
137 printf_unfiltered ("\"maintenance demangle\" takes an argument to demangle.\n");
138 }
139 else
140 {
141 demangled = cplus_demangle (args, DMGL_ANSI | DMGL_PARAMS);
142 if (demangled != NULL)
143 {
144 printf_unfiltered ("%s\n", demangled);
b8c9b27d 145 xfree (demangled);
c906108c
SS
146 }
147 else
148 {
149 printf_unfiltered ("Can't demangle \"%s\"\n", args);
150 }
151 }
152}
153
154static void
fba45db2 155maintenance_time_display (char *args, int from_tty)
c906108c
SS
156{
157 extern int display_time;
158
159 if (args == NULL || *args == '\0')
160 printf_unfiltered ("\"maintenance time\" takes a numeric argument.\n");
161 else
162 display_time = strtol (args, NULL, 10);
163}
164
165static void
fba45db2 166maintenance_space_display (char *args, int from_tty)
c906108c
SS
167{
168 extern int display_space;
169
170 if (args == NULL || *args == '\0')
171 printf_unfiltered ("\"maintenance space\" takes a numeric argument.\n");
172 else
173 display_space = strtol (args, NULL, 10);
174}
175
33f91161
AC
176/* The "maintenance info" command is defined as a prefix, with
177 allow_unknown 0. Therefore, its own definition is called only for
178 "maintenance info" with no args. */
c906108c
SS
179
180/* ARGSUSED */
181static void
fba45db2 182maintenance_info_command (char *arg, int from_tty)
c906108c
SS
183{
184 printf_unfiltered ("\"maintenance info\" must be followed by the name of an info command.\n");
185 help_list (maintenanceinfolist, "maintenance info ", -1, gdb_stdout);
186}
187
188static void
fba45db2 189print_section_table (bfd *abfd, asection *asect, PTR ignore)
c906108c
SS
190{
191 flagword flags;
192
193 flags = bfd_get_section_flags (abfd, asect);
194
195 /* FIXME-32x64: Need print_address_numeric with field width. */
196 printf_filtered (" %s",
197 local_hex_string_custom
c5aa993b 198 ((unsigned long) bfd_section_vma (abfd, asect), "08l"));
c906108c
SS
199 printf_filtered ("->%s",
200 local_hex_string_custom
c5aa993b
JM
201 ((unsigned long) (bfd_section_vma (abfd, asect)
202 + bfd_section_size (abfd, asect)),
203 "08l"));
c906108c
SS
204 printf_filtered (" at %s",
205 local_hex_string_custom
c5aa993b 206 ((unsigned long) asect->filepos, "08l"));
c906108c
SS
207 printf_filtered (": %s", bfd_section_name (abfd, asect));
208
209 if (flags & SEC_ALLOC)
210 printf_filtered (" ALLOC");
211 if (flags & SEC_LOAD)
212 printf_filtered (" LOAD");
213 if (flags & SEC_RELOC)
214 printf_filtered (" RELOC");
215 if (flags & SEC_READONLY)
216 printf_filtered (" READONLY");
217 if (flags & SEC_CODE)
218 printf_filtered (" CODE");
219 if (flags & SEC_DATA)
220 printf_filtered (" DATA");
221 if (flags & SEC_ROM)
222 printf_filtered (" ROM");
223 if (flags & SEC_CONSTRUCTOR)
224 printf_filtered (" CONSTRUCTOR");
225 if (flags & SEC_HAS_CONTENTS)
226 printf_filtered (" HAS_CONTENTS");
227 if (flags & SEC_NEVER_LOAD)
228 printf_filtered (" NEVER_LOAD");
229 if (flags & SEC_COFF_SHARED_LIBRARY)
230 printf_filtered (" COFF_SHARED_LIBRARY");
231 if (flags & SEC_IS_COMMON)
232 printf_filtered (" IS_COMMON");
233
234 printf_filtered ("\n");
235}
236
237/* ARGSUSED */
238static void
fba45db2 239maintenance_info_sections (char *arg, int from_tty)
c906108c
SS
240{
241 if (exec_bfd)
242 {
243 printf_filtered ("Exec file:\n");
c5aa993b 244 printf_filtered (" `%s', ", bfd_get_filename (exec_bfd));
c906108c 245 wrap_here (" ");
c5aa993b
JM
246 printf_filtered ("file type %s.\n", bfd_get_target (exec_bfd));
247 bfd_map_over_sections (exec_bfd, print_section_table, 0);
c906108c
SS
248 }
249
250 if (core_bfd)
251 {
252 printf_filtered ("Core file:\n");
c5aa993b 253 printf_filtered (" `%s', ", bfd_get_filename (core_bfd));
c906108c 254 wrap_here (" ");
c5aa993b
JM
255 printf_filtered ("file type %s.\n", bfd_get_target (core_bfd));
256 bfd_map_over_sections (core_bfd, print_section_table, 0);
c906108c
SS
257 }
258}
259
260/* ARGSUSED */
261void
fba45db2 262maintenance_print_statistics (char *args, int from_tty)
c906108c
SS
263{
264 print_objfile_statistics ();
265 print_symbol_bcache_statistics ();
266}
267
4b9b3959
AC
268void
269maintenance_print_architecture (char *args, int from_tty)
270{
271 if (args == NULL)
272 gdbarch_dump (current_gdbarch, gdb_stdout);
273 else
274 {
275 struct ui_file *file = gdb_fopen (args, "w");
276 if (file == NULL)
277 perror_with_name ("maintenance print architecture");
278 gdbarch_dump (current_gdbarch, file);
279 ui_file_delete (file);
280 }
281}
282
33f91161
AC
283/* The "maintenance print" command is defined as a prefix, with
284 allow_unknown 0. Therefore, its own definition is called only for
285 "maintenance print" with no args. */
c906108c
SS
286
287/* ARGSUSED */
288static void
fba45db2 289maintenance_print_command (char *arg, int from_tty)
c906108c
SS
290{
291 printf_unfiltered ("\"maintenance print\" must be followed by the name of a print command.\n");
292 help_list (maintenanceprintlist, "maintenance print ", -1, gdb_stdout);
293}
294
295/* The "maintenance translate-address" command converts a section and address
296 to a symbol. This can be called in two ways:
c5aa993b
JM
297 maintenance translate-address <secname> <addr>
298 or maintenance translate-address <addr>
299 */
c906108c
SS
300
301static void
fba45db2 302maintenance_translate_address (char *arg, int from_tty)
c906108c
SS
303{
304 CORE_ADDR address;
305 asection *sect;
306 char *p;
307 struct minimal_symbol *sym;
308 struct objfile *objfile;
309
310 if (arg == NULL || *arg == 0)
311 error ("requires argument (address or section + address)");
312
313 sect = NULL;
314 p = arg;
315
316 if (!isdigit (*p))
317 { /* See if we have a valid section name */
c5aa993b 318 while (*p && !isspace (*p)) /* Find end of section name */
c906108c
SS
319 p++;
320 if (*p == '\000') /* End of command? */
321 error ("Need to specify <section-name> and <address>");
322 *p++ = '\000';
c5aa993b
JM
323 while (isspace (*p))
324 p++; /* Skip whitespace */
c906108c
SS
325
326 ALL_OBJFILES (objfile)
c5aa993b
JM
327 {
328 sect = bfd_get_section_by_name (objfile->obfd, arg);
329 if (sect != NULL)
330 break;
331 }
c906108c
SS
332
333 if (!sect)
334 error ("Unknown section %s.", arg);
335 }
336
337 address = parse_and_eval_address (p);
338
339 if (sect)
340 sym = lookup_minimal_symbol_by_pc_section (address, sect);
341 else
342 sym = lookup_minimal_symbol_by_pc (address);
343
344 if (sym)
d4f3574e 345 printf_filtered ("%s+%s\n",
c5aa993b 346 SYMBOL_SOURCE_NAME (sym),
d4f3574e 347 paddr_u (address - SYMBOL_VALUE_ADDRESS (sym)));
c906108c 348 else if (sect)
d4f3574e 349 printf_filtered ("no symbol at %s:0x%s\n", sect->name, paddr (address));
c906108c 350 else
d4f3574e 351 printf_filtered ("no symbol at 0x%s\n", paddr (address));
c906108c
SS
352
353 return;
354}
355
56382845
FN
356
357/* When a comamnd is deprecated the user will be warned the first time
33f91161
AC
358 the command is used. If possible, a replacement will be
359 offered. */
56382845
FN
360
361static void
362maintenance_deprecate (char *args, int from_tty)
363{
364 if (args == NULL || *args == '\0')
365 {
366 printf_unfiltered ("\"maintenance deprecate\" takes an argument, \n\
367the command you want to deprecate, and optionally the replacement command \n\
368enclosed in quotes.\n");
369 }
33f91161 370
56382845
FN
371 maintenance_do_deprecate (args, 1);
372
373}
374
375
376static void
377maintenance_undeprecate (char *args, int from_tty)
378{
379 if (args == NULL || *args == '\0')
380 {
381 printf_unfiltered ("\"maintenance undeprecate\" takes an argument, \n\
382the command you want to undeprecate.\n");
383 }
33f91161 384
56382845 385 maintenance_do_deprecate (args, 0);
33f91161 386
56382845
FN
387}
388
33f91161
AC
389/* You really shouldn't be using this. It is just for the testsuite.
390 Rather, you should use deprecate_cmd() when the command is created
391 in _initialize_blah().
392
393 This function deprecates a command and optionally assigns it a
394 replacement. */
395
8399535b 396static void
33f91161
AC
397maintenance_do_deprecate (char *text, int deprecate)
398{
399
400 struct cmd_list_element *alias = NULL;
401 struct cmd_list_element *prefix_cmd = NULL;
402 struct cmd_list_element *cmd = NULL;
403
404 char *start_ptr = NULL;
405 char *end_ptr = NULL;
56382845 406 int len;
33f91161
AC
407 char *replacement = NULL;
408
1c689132
DB
409 if (text == NULL)
410 return;
56382845 411
33f91161
AC
412 if (!lookup_cmd_composition (text, &alias, &prefix_cmd, &cmd))
413 {
414 printf_filtered ("Can't find command '%s' to deprecate.\n", text);
415 return;
416 }
56382845 417
56382845
FN
418 if (deprecate)
419 {
420 /* look for a replacement command */
80ce1ecb
AC
421 start_ptr = strchr (text, '\"');
422 if (start_ptr != NULL)
33f91161
AC
423 {
424 start_ptr++;
80ce1ecb
AC
425 end_ptr = strrchr (start_ptr, '\"');
426 if (end_ptr != NULL)
33f91161
AC
427 {
428 len = end_ptr - start_ptr;
429 start_ptr[len] = '\0';
430 replacement = xstrdup (start_ptr);
431 }
432 }
56382845 433 }
33f91161 434
56382845
FN
435 if (!start_ptr || !end_ptr)
436 replacement = NULL;
33f91161
AC
437
438
56382845 439 /* If they used an alias, we only want to deprecate the alias.
33f91161 440
56382845
FN
441 Note the MALLOCED_REPLACEMENT test. If the command's replacement
442 string was allocated at compile time we don't want to free the
33f91161 443 memory. */
56382845
FN
444 if (alias)
445 {
33f91161 446
56382845 447 if (alias->flags & MALLOCED_REPLACEMENT)
b8c9b27d 448 xfree (alias->replacement);
33f91161 449
56382845 450 if (deprecate)
33f91161 451 alias->flags |= (DEPRECATED_WARN_USER | CMD_DEPRECATED);
56382845 452 else
33f91161
AC
453 alias->flags &= ~(DEPRECATED_WARN_USER | CMD_DEPRECATED);
454 alias->replacement = replacement;
56382845
FN
455 alias->flags |= MALLOCED_REPLACEMENT;
456 return;
457 }
458 else if (cmd)
459 {
460 if (cmd->flags & MALLOCED_REPLACEMENT)
b8c9b27d 461 xfree (cmd->replacement);
56382845
FN
462
463 if (deprecate)
33f91161 464 cmd->flags |= (DEPRECATED_WARN_USER | CMD_DEPRECATED);
56382845 465 else
33f91161
AC
466 cmd->flags &= ~(DEPRECATED_WARN_USER | CMD_DEPRECATED);
467 cmd->replacement = replacement;
56382845
FN
468 cmd->flags |= MALLOCED_REPLACEMENT;
469 return;
470 }
471}
472
473
c906108c 474void
fba45db2 475_initialize_maint_cmds (void)
c906108c 476{
c906108c
SS
477 add_prefix_cmd ("maintenance", class_maintenance, maintenance_command,
478 "Commands for use by GDB maintainers.\n\
479Includes commands to dump specific internal GDB structures in\n\
480a human readable form, to cause GDB to deliberately dump core,\n\
481to test internal functions such as the C++ demangler, etc.",
482 &maintenancelist, "maintenance ", 0,
483 &cmdlist);
484
485 add_com_alias ("mt", "maintenance", class_maintenance, 1);
486
487 add_prefix_cmd ("info", class_maintenance, maintenance_info_command,
c5aa993b 488 "Commands for showing internal info about the program being debugged.",
c906108c
SS
489 &maintenanceinfolist, "maintenance info ", 0,
490 &maintenancelist);
90515c23 491 add_alias_cmd ("i", "info", class_maintenance, 1, &maintenancelist);
c906108c
SS
492
493 add_cmd ("sections", class_maintenance, maintenance_info_sections,
494 "List the BFD sections of the exec and core files.",
495 &maintenanceinfolist);
496
497 add_prefix_cmd ("print", class_maintenance, maintenance_print_command,
498 "Maintenance command for printing GDB internal state.",
499 &maintenanceprintlist, "maintenance print ", 0,
500 &maintenancelist);
501
502#ifndef _WIN32
503 add_cmd ("dump-me", class_maintenance, maintenance_dump_me,
504 "Get fatal error; make debugger dump its core.\n\
505GDB sets it's handling of SIGQUIT back to SIG_DFL and then sends\n\
506itself a SIGQUIT signal.",
507 &maintenancelist);
508#endif
509
7be570e7
JM
510 add_cmd ("internal-error", class_maintenance, maintenance_internal_error,
511 "Give GDB an internal error.\n\
512Cause GDB to behave as if an internal error was detected.",
513 &maintenancelist);
514
c906108c
SS
515 add_cmd ("demangle", class_maintenance, maintenance_demangle,
516 "Demangle a C++ mangled name.\n\
517Call internal GDB demangler routine to demangle a C++ link name\n\
518and prints the result.",
519 &maintenancelist);
520
521 add_cmd ("time", class_maintenance, maintenance_time_display,
522 "Set the display of time usage.\n\
523If nonzero, will cause the execution time for each command to be\n\
524displayed, following the command's output.",
525 &maintenancelist);
526
527 add_cmd ("space", class_maintenance, maintenance_space_display,
528 "Set the display of space usage.\n\
529If nonzero, will cause the execution space for each command to be\n\
530displayed, following the command's output.",
531 &maintenancelist);
532
533 add_cmd ("type", class_maintenance, maintenance_print_type,
534 "Print a type chain for a given symbol.\n\
535For each node in a type chain, print the raw data for each member of\n\
536the type structure, and the interpretation of the data.",
537 &maintenanceprintlist);
538
539 add_cmd ("symbols", class_maintenance, maintenance_print_symbols,
540 "Print dump of current symbol definitions.\n\
541Entries in the full symbol table are dumped to file OUTFILE.\n\
542If a SOURCE file is specified, dump only that file's symbols.",
543 &maintenanceprintlist);
544
545 add_cmd ("msymbols", class_maintenance, maintenance_print_msymbols,
546 "Print dump of current minimal symbol definitions.\n\
547Entries in the minimal symbol table are dumped to file OUTFILE.\n\
548If a SOURCE file is specified, dump only that file's minimal symbols.",
549 &maintenanceprintlist);
550
551 add_cmd ("psymbols", class_maintenance, maintenance_print_psymbols,
552 "Print dump of current partial symbol definitions.\n\
553Entries in the partial symbol table are dumped to file OUTFILE.\n\
554If a SOURCE file is specified, dump only that file's partial symbols.",
555 &maintenanceprintlist);
556
557 add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles,
558 "Print dump of current object file definitions.",
559 &maintenanceprintlist);
560
561 add_cmd ("statistics", class_maintenance, maintenance_print_statistics,
562 "Print statistics about internal gdb state.",
563 &maintenanceprintlist);
564
4b9b3959
AC
565 add_cmd ("architecture", class_maintenance, maintenance_print_architecture,
566 "Print the internal architecture configuration.\
567Takes an optional file parameter.",
568 &maintenanceprintlist);
569
c906108c
SS
570 add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
571 "Check consistency of psymtabs and symtabs.",
572 &maintenancelist);
573
574 add_cmd ("translate-address", class_maintenance, maintenance_translate_address,
575 "Translate a section name and address to a symbol.",
576 &maintenancelist);
577
56382845 578 add_cmd ("deprecate", class_maintenance, maintenance_deprecate,
33f91161 579 "Deprecate a command. Note that this is just in here so the \n\
56382845
FN
580testsuite can check the comamnd deprecator. You probably shouldn't use this,\n\
581rather you should use the C function deprecate_cmd(). If you decide you \n\
6f122dc9 582want to use it: maintenance deprecate 'commandname' \"replacement\". The \n\
56382845
FN
583replacement is optional.", &maintenancelist);
584
585 add_cmd ("undeprecate", class_maintenance, maintenance_undeprecate,
33f91161 586 "Undeprecate a command. Note that this is just in here so the \n\
56382845 587testsuite can check the comamnd deprecator. You probably shouldn't use this,\n\
33f91161
AC
588If you decide you want to use it: maintenance undeprecate 'commandname'",
589 &maintenancelist);
56382845 590
c906108c 591 add_show_from_set (
c5aa993b
JM
592 add_set_cmd ("watchdog", class_maintenance, var_zinteger, (char *) &watchdog,
593 "Set watchdog timer.\n\
c906108c
SS
594When non-zero, this timeout is used instead of waiting forever for a target to\n\
595finish a low-level step or continue operation. If the specified amount of time\n\
596passes without a response from the target, an error occurs.", &setlist),
c5aa993b 597 &showlist);
c906108c 598}
This page took 0.142696 seconds and 4 git commands to generate.