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