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