Re-indent.
[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
392a587b
JM
38extern void _initialize_maint_cmds PARAMS ((void));
39
c906108c
SS
40static void maintenance_command PARAMS ((char *, int));
41
42static void maintenance_dump_me PARAMS ((char *, int));
43
7be570e7
JM
44static void maintenance_internal_error PARAMS ((char *args, int from_tty));
45
c906108c
SS
46static void maintenance_demangle PARAMS ((char *, int));
47
48static void maintenance_time_display PARAMS ((char *, int));
49
50static void maintenance_space_display PARAMS ((char *, int));
51
52static void maintenance_info_command PARAMS ((char *, int));
53
54static void print_section_table PARAMS ((bfd *, asection *, PTR));
55
56static void maintenance_info_sections PARAMS ((char *, int));
57
58static void maintenance_print_command PARAMS ((char *, int));
59
60/* Set this to the maximum number of seconds to wait instead of waiting forever
61 in target_wait(). If this timer times out, then it generates an error and
62 the command is aborted. This replaces most of the need for timeouts in the
63 GDB test suite, and makes it possible to distinguish between a hung target
64 and one with slow communications. */
65
66int watchdog = 0;
67
68/*
69
c5aa993b 70 LOCAL FUNCTION
c906108c 71
c5aa993b 72 maintenance_command -- access the maintenance subcommands
c906108c 73
c5aa993b 74 SYNOPSIS
c906108c 75
c5aa993b 76 void maintenance_command (char *args, int from_tty)
c906108c 77
c5aa993b 78 DESCRIPTION
c906108c 79
c5aa993b 80 */
c906108c
SS
81
82static void
83maintenance_command (args, from_tty)
84 char *args;
85 int from_tty;
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
94maintenance_dump_me (args, from_tty)
95 char *args;
96 int from_tty;
97{
98 if (query ("Should GDB dump core? "))
99 {
7be570e7
JM
100#ifdef __DJGPP__
101 /* SIGQUIT by default is ignored, so use SIGABRT instead. */
102 signal (SIGABRT, SIG_DFL);
103 kill (getpid (), SIGABRT);
104#else
c906108c
SS
105 signal (SIGQUIT, SIG_DFL);
106 kill (getpid (), SIGQUIT);
7be570e7 107#endif
c906108c
SS
108 }
109}
110#endif
111
7be570e7
JM
112/* Stimulate the internal error mechanism that GDB uses when an
113 internal problem is detected. Allows testing of the mechanism.
114 Also useful when the user wants to drop a core file but not exit
115 GDB. */
116
117static void
118maintenance_internal_error (char *args, int from_tty)
119{
120 internal_error ("internal maintenance");
121}
122
33f91161
AC
123/* Someday we should allow demangling for things other than just
124 explicit strings. For example, we might want to be able to specify
125 the address of a string in either GDB's process space or the
126 debuggee's process space, and have gdb fetch and demangle that
127 string. If we have a char* pointer "ptr" that points to a string,
128 we might want to be able to given just the name and have GDB
129 demangle and print what it points to, etc. (FIXME) */
c906108c
SS
130
131static void
132maintenance_demangle (args, from_tty)
133 char *args;
134 int from_tty;
135{
136 char *demangled;
137
138 if (args == NULL || *args == '\0')
139 {
140 printf_unfiltered ("\"maintenance demangle\" takes an argument to demangle.\n");
141 }
142 else
143 {
144 demangled = cplus_demangle (args, DMGL_ANSI | DMGL_PARAMS);
145 if (demangled != NULL)
146 {
147 printf_unfiltered ("%s\n", demangled);
148 free (demangled);
149 }
150 else
151 {
152 printf_unfiltered ("Can't demangle \"%s\"\n", args);
153 }
154 }
155}
156
157static void
158maintenance_time_display (args, from_tty)
159 char *args;
160 int from_tty;
161{
162 extern int display_time;
163
164 if (args == NULL || *args == '\0')
165 printf_unfiltered ("\"maintenance time\" takes a numeric argument.\n");
166 else
167 display_time = strtol (args, NULL, 10);
168}
169
170static void
171maintenance_space_display (args, from_tty)
172 char *args;
173 int from_tty;
174{
175 extern int display_space;
176
177 if (args == NULL || *args == '\0')
178 printf_unfiltered ("\"maintenance space\" takes a numeric argument.\n");
179 else
180 display_space = strtol (args, NULL, 10);
181}
182
33f91161
AC
183/* The "maintenance info" command is defined as a prefix, with
184 allow_unknown 0. Therefore, its own definition is called only for
185 "maintenance info" with no args. */
c906108c
SS
186
187/* ARGSUSED */
188static void
189maintenance_info_command (arg, from_tty)
190 char *arg;
191 int from_tty;
192{
193 printf_unfiltered ("\"maintenance info\" must be followed by the name of an info command.\n");
194 help_list (maintenanceinfolist, "maintenance info ", -1, gdb_stdout);
195}
196
197static void
198print_section_table (abfd, asect, ignore)
199 bfd *abfd;
200 asection *asect;
201 PTR ignore;
202{
203 flagword flags;
204
205 flags = bfd_get_section_flags (abfd, asect);
206
207 /* FIXME-32x64: Need print_address_numeric with field width. */
208 printf_filtered (" %s",
209 local_hex_string_custom
c5aa993b 210 ((unsigned long) bfd_section_vma (abfd, asect), "08l"));
c906108c
SS
211 printf_filtered ("->%s",
212 local_hex_string_custom
c5aa993b
JM
213 ((unsigned long) (bfd_section_vma (abfd, asect)
214 + bfd_section_size (abfd, asect)),
215 "08l"));
c906108c
SS
216 printf_filtered (" at %s",
217 local_hex_string_custom
c5aa993b 218 ((unsigned long) asect->filepos, "08l"));
c906108c
SS
219 printf_filtered (": %s", bfd_section_name (abfd, asect));
220
221 if (flags & SEC_ALLOC)
222 printf_filtered (" ALLOC");
223 if (flags & SEC_LOAD)
224 printf_filtered (" LOAD");
225 if (flags & SEC_RELOC)
226 printf_filtered (" RELOC");
227 if (flags & SEC_READONLY)
228 printf_filtered (" READONLY");
229 if (flags & SEC_CODE)
230 printf_filtered (" CODE");
231 if (flags & SEC_DATA)
232 printf_filtered (" DATA");
233 if (flags & SEC_ROM)
234 printf_filtered (" ROM");
235 if (flags & SEC_CONSTRUCTOR)
236 printf_filtered (" CONSTRUCTOR");
237 if (flags & SEC_HAS_CONTENTS)
238 printf_filtered (" HAS_CONTENTS");
239 if (flags & SEC_NEVER_LOAD)
240 printf_filtered (" NEVER_LOAD");
241 if (flags & SEC_COFF_SHARED_LIBRARY)
242 printf_filtered (" COFF_SHARED_LIBRARY");
243 if (flags & SEC_IS_COMMON)
244 printf_filtered (" IS_COMMON");
245
246 printf_filtered ("\n");
247}
248
249/* ARGSUSED */
250static void
251maintenance_info_sections (arg, from_tty)
252 char *arg;
253 int from_tty;
254{
255 if (exec_bfd)
256 {
257 printf_filtered ("Exec file:\n");
c5aa993b 258 printf_filtered (" `%s', ", bfd_get_filename (exec_bfd));
c906108c 259 wrap_here (" ");
c5aa993b
JM
260 printf_filtered ("file type %s.\n", bfd_get_target (exec_bfd));
261 bfd_map_over_sections (exec_bfd, print_section_table, 0);
c906108c
SS
262 }
263
264 if (core_bfd)
265 {
266 printf_filtered ("Core file:\n");
c5aa993b 267 printf_filtered (" `%s', ", bfd_get_filename (core_bfd));
c906108c 268 wrap_here (" ");
c5aa993b
JM
269 printf_filtered ("file type %s.\n", bfd_get_target (core_bfd));
270 bfd_map_over_sections (core_bfd, print_section_table, 0);
c906108c
SS
271 }
272}
273
274/* ARGSUSED */
275void
276maintenance_print_statistics (args, from_tty)
277 char *args;
278 int from_tty;
279{
280 print_objfile_statistics ();
281 print_symbol_bcache_statistics ();
282}
283
33f91161
AC
284/* The "maintenance print" command is defined as a prefix, with
285 allow_unknown 0. Therefore, its own definition is called only for
286 "maintenance print" with no args. */
c906108c
SS
287
288/* ARGSUSED */
289static void
290maintenance_print_command (arg, from_tty)
291 char *arg;
292 int from_tty;
293{
294 printf_unfiltered ("\"maintenance print\" must be followed by the name of a print command.\n");
295 help_list (maintenanceprintlist, "maintenance print ", -1, gdb_stdout);
296}
297
298/* The "maintenance translate-address" command converts a section and address
299 to a symbol. This can be called in two ways:
c5aa993b
JM
300 maintenance translate-address <secname> <addr>
301 or maintenance translate-address <addr>
302 */
c906108c
SS
303
304static void
305maintenance_translate_address (arg, from_tty)
306 char *arg;
307 int from_tty;
308{
309 CORE_ADDR address;
310 asection *sect;
311 char *p;
312 struct minimal_symbol *sym;
313 struct objfile *objfile;
314
315 if (arg == NULL || *arg == 0)
316 error ("requires argument (address or section + address)");
317
318 sect = NULL;
319 p = arg;
320
321 if (!isdigit (*p))
322 { /* See if we have a valid section name */
c5aa993b 323 while (*p && !isspace (*p)) /* Find end of section name */
c906108c
SS
324 p++;
325 if (*p == '\000') /* End of command? */
326 error ("Need to specify <section-name> and <address>");
327 *p++ = '\000';
c5aa993b
JM
328 while (isspace (*p))
329 p++; /* Skip whitespace */
c906108c
SS
330
331 ALL_OBJFILES (objfile)
c5aa993b
JM
332 {
333 sect = bfd_get_section_by_name (objfile->obfd, arg);
334 if (sect != NULL)
335 break;
336 }
c906108c
SS
337
338 if (!sect)
339 error ("Unknown section %s.", arg);
340 }
341
342 address = parse_and_eval_address (p);
343
344 if (sect)
345 sym = lookup_minimal_symbol_by_pc_section (address, sect);
346 else
347 sym = lookup_minimal_symbol_by_pc (address);
348
349 if (sym)
d4f3574e 350 printf_filtered ("%s+%s\n",
c5aa993b 351 SYMBOL_SOURCE_NAME (sym),
d4f3574e 352 paddr_u (address - SYMBOL_VALUE_ADDRESS (sym)));
c906108c 353 else if (sect)
d4f3574e 354 printf_filtered ("no symbol at %s:0x%s\n", sect->name, paddr (address));
c906108c 355 else
d4f3574e 356 printf_filtered ("no symbol at 0x%s\n", paddr (address));
c906108c
SS
357
358 return;
359}
360
56382845
FN
361
362/* When a comamnd is deprecated the user will be warned the first time
33f91161
AC
363 the command is used. If possible, a replacement will be
364 offered. */
56382845
FN
365
366static void
367maintenance_deprecate (char *args, int from_tty)
368{
369 if (args == NULL || *args == '\0')
370 {
371 printf_unfiltered ("\"maintenance deprecate\" takes an argument, \n\
372the command you want to deprecate, and optionally the replacement command \n\
373enclosed in quotes.\n");
374 }
33f91161 375
56382845
FN
376 maintenance_do_deprecate (args, 1);
377
378}
379
380
381static void
382maintenance_undeprecate (char *args, int from_tty)
383{
384 if (args == NULL || *args == '\0')
385 {
386 printf_unfiltered ("\"maintenance undeprecate\" takes an argument, \n\
387the command you want to undeprecate.\n");
388 }
33f91161 389
56382845 390 maintenance_do_deprecate (args, 0);
33f91161 391
56382845
FN
392}
393
33f91161
AC
394/* You really shouldn't be using this. It is just for the testsuite.
395 Rather, you should use deprecate_cmd() when the command is created
396 in _initialize_blah().
397
398 This function deprecates a command and optionally assigns it a
399 replacement. */
400
401static void
402maintenance_do_deprecate (char *text, int deprecate)
403{
404
405 struct cmd_list_element *alias = NULL;
406 struct cmd_list_element *prefix_cmd = NULL;
407 struct cmd_list_element *cmd = NULL;
408
409 char *start_ptr = NULL;
410 char *end_ptr = NULL;
56382845 411 int len;
33f91161
AC
412 char *replacement = NULL;
413
56382845 414
33f91161
AC
415 if (!lookup_cmd_composition (text, &alias, &prefix_cmd, &cmd))
416 {
417 printf_filtered ("Can't find command '%s' to deprecate.\n", text);
418 return;
419 }
56382845 420
56382845
FN
421 if (deprecate)
422 {
423 /* look for a replacement command */
424 if (start_ptr = strchr (text, '\"'))
33f91161
AC
425 {
426 start_ptr++;
427 if (end_ptr = strrchr (start_ptr, '\"'))
428 {
429 len = end_ptr - start_ptr;
430 start_ptr[len] = '\0';
431 replacement = xstrdup (start_ptr);
432 }
433 }
56382845 434 }
33f91161 435
56382845
FN
436 if (!start_ptr || !end_ptr)
437 replacement = NULL;
33f91161
AC
438
439
56382845 440 /* If they used an alias, we only want to deprecate the alias.
33f91161 441
56382845
FN
442 Note the MALLOCED_REPLACEMENT test. If the command's replacement
443 string was allocated at compile time we don't want to free the
33f91161 444 memory. */
56382845
FN
445 if (alias)
446 {
33f91161 447
56382845 448 if (alias->flags & MALLOCED_REPLACEMENT)
33f91161
AC
449 free (alias->replacement);
450
56382845 451 if (deprecate)
33f91161 452 alias->flags |= (DEPRECATED_WARN_USER | CMD_DEPRECATED);
56382845 453 else
33f91161
AC
454 alias->flags &= ~(DEPRECATED_WARN_USER | CMD_DEPRECATED);
455 alias->replacement = replacement;
56382845
FN
456 alias->flags |= MALLOCED_REPLACEMENT;
457 return;
458 }
459 else if (cmd)
460 {
461 if (cmd->flags & MALLOCED_REPLACEMENT)
33f91161 462 free (cmd->replacement);
56382845
FN
463
464 if (deprecate)
33f91161 465 cmd->flags |= (DEPRECATED_WARN_USER | CMD_DEPRECATED);
56382845 466 else
33f91161
AC
467 cmd->flags &= ~(DEPRECATED_WARN_USER | CMD_DEPRECATED);
468 cmd->replacement = replacement;
56382845
FN
469 cmd->flags |= MALLOCED_REPLACEMENT;
470 return;
471 }
472}
473
474
c906108c
SS
475void
476_initialize_maint_cmds ()
477{
c906108c
SS
478 add_prefix_cmd ("maintenance", class_maintenance, maintenance_command,
479 "Commands for use by GDB maintainers.\n\
480Includes commands to dump specific internal GDB structures in\n\
481a human readable form, to cause GDB to deliberately dump core,\n\
482to test internal functions such as the C++ demangler, etc.",
483 &maintenancelist, "maintenance ", 0,
484 &cmdlist);
485
486 add_com_alias ("mt", "maintenance", class_maintenance, 1);
487
488 add_prefix_cmd ("info", class_maintenance, maintenance_info_command,
c5aa993b 489 "Commands for showing internal info about the program being debugged.",
c906108c
SS
490 &maintenanceinfolist, "maintenance info ", 0,
491 &maintenancelist);
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
565 add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
566 "Check consistency of psymtabs and symtabs.",
567 &maintenancelist);
568
569 add_cmd ("translate-address", class_maintenance, maintenance_translate_address,
570 "Translate a section name and address to a symbol.",
571 &maintenancelist);
572
56382845 573 add_cmd ("deprecate", class_maintenance, maintenance_deprecate,
33f91161 574 "Deprecate a command. Note that this is just in here so the \n\
56382845
FN
575testsuite can check the comamnd deprecator. You probably shouldn't use this,\n\
576rather you should use the C function deprecate_cmd(). If you decide you \n\
6f122dc9 577want to use it: maintenance deprecate 'commandname' \"replacement\". The \n\
56382845
FN
578replacement is optional.", &maintenancelist);
579
580 add_cmd ("undeprecate", class_maintenance, maintenance_undeprecate,
33f91161 581 "Undeprecate a command. Note that this is just in here so the \n\
56382845 582testsuite can check the comamnd deprecator. You probably shouldn't use this,\n\
33f91161
AC
583If you decide you want to use it: maintenance undeprecate 'commandname'",
584 &maintenancelist);
56382845 585
c906108c 586 add_show_from_set (
c5aa993b
JM
587 add_set_cmd ("watchdog", class_maintenance, var_zinteger, (char *) &watchdog,
588 "Set watchdog timer.\n\
c906108c
SS
589When non-zero, this timeout is used instead of waiting forever for a target to\n\
590finish a low-level step or continue operation. If the specified amount of time\n\
591passes without a response from the target, an error occurs.", &setlist),
c5aa993b 592 &showlist);
c906108c 593}
This page took 0.099667 seconds and 4 git commands to generate.