1 /* Support for GDB maintenance commands.
2 Copyright 1992, 1993, 1994 Free Software Foundation, Inc.
3 Written by Fred Fish at Cygnus Support.
5 This file is part of GDB.
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.
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.
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. */
32 #include "expression.h" /* For language.h */
42 extern void _initialize_maint_cmds
PARAMS ((void));
44 static void maintenance_command
PARAMS ((char *, int));
46 static void maintenance_dump_me
PARAMS ((char *, int));
48 static void maintenance_internal_error
PARAMS ((char *args
, int from_tty
));
50 static void maintenance_demangle
PARAMS ((char *, int));
52 static void maintenance_time_display
PARAMS ((char *, int));
54 static void maintenance_space_display
PARAMS ((char *, int));
56 static void maintenance_info_command
PARAMS ((char *, int));
58 static void print_section_table
PARAMS ((bfd
*, asection
*, PTR
));
60 static void maintenance_info_sections
PARAMS ((char *, int));
62 static void maintenance_print_command
PARAMS ((char *, int));
64 /* Set this to the maximum number of seconds to wait instead of waiting forever
65 in target_wait(). If this timer times out, then it generates an error and
66 the command is aborted. This replaces most of the need for timeouts in the
67 GDB test suite, and makes it possible to distinguish between a hung target
68 and one with slow communications. */
76 maintenance_command -- access the maintenance subcommands
80 void maintenance_command (char *args, int from_tty)
87 maintenance_command (args
, from_tty
)
91 printf_unfiltered ("\"maintenance\" must be followed by the name of a maintenance command.\n");
92 help_list (maintenancelist
, "maintenance ", -1, gdb_stdout
);
98 maintenance_dump_me (args
, from_tty
)
102 if (query ("Should GDB dump core? "))
105 /* SIGQUIT by default is ignored, so use SIGABRT instead. */
106 signal (SIGABRT
, SIG_DFL
);
107 kill (getpid (), SIGABRT
);
109 signal (SIGQUIT
, SIG_DFL
);
110 kill (getpid (), SIGQUIT
);
116 /* Stimulate the internal error mechanism that GDB uses when an
117 internal problem is detected. Allows testing of the mechanism.
118 Also useful when the user wants to drop a core file but not exit
122 maintenance_internal_error (char *args
, int from_tty
)
124 internal_error ("internal maintenance");
127 /* Someday we should allow demangling for things other than just
128 explicit strings. For example, we might want to be able to
129 specify the address of a string in either GDB's process space
130 or the debuggee's process space, and have gdb fetch and demangle
131 that string. If we have a char* pointer "ptr" that points to
132 a string, we might want to be able to given just the name and
133 have GDB demangle and print what it points to, etc. (FIXME) */
136 maintenance_demangle (args
, from_tty
)
142 if (args
== NULL
|| *args
== '\0')
144 printf_unfiltered ("\"maintenance demangle\" takes an argument to demangle.\n");
148 demangled
= cplus_demangle (args
, DMGL_ANSI
| DMGL_PARAMS
);
149 if (demangled
!= NULL
)
151 printf_unfiltered ("%s\n", demangled
);
156 printf_unfiltered ("Can't demangle \"%s\"\n", args
);
162 maintenance_time_display (args
, from_tty
)
166 extern int display_time
;
168 if (args
== NULL
|| *args
== '\0')
169 printf_unfiltered ("\"maintenance time\" takes a numeric argument.\n");
171 display_time
= strtol (args
, NULL
, 10);
175 maintenance_space_display (args
, from_tty
)
179 extern int display_space
;
181 if (args
== NULL
|| *args
== '\0')
182 printf_unfiltered ("\"maintenance space\" takes a numeric argument.\n");
184 display_space
= strtol (args
, NULL
, 10);
187 /* The "maintenance info" command is defined as a prefix, with allow_unknown 0.
188 Therefore, its own definition is called only for "maintenance info" with
193 maintenance_info_command (arg
, from_tty
)
197 printf_unfiltered ("\"maintenance info\" must be followed by the name of an info command.\n");
198 help_list (maintenanceinfolist
, "maintenance info ", -1, gdb_stdout
);
202 print_section_table (abfd
, asect
, ignore
)
209 flags
= bfd_get_section_flags (abfd
, asect
);
211 /* FIXME-32x64: Need print_address_numeric with field width. */
212 printf_filtered (" %s",
213 local_hex_string_custom
214 ((unsigned long) bfd_section_vma (abfd
, asect
), "08l"));
215 printf_filtered ("->%s",
216 local_hex_string_custom
217 ((unsigned long) (bfd_section_vma (abfd
, asect
)
218 + bfd_section_size (abfd
, asect
)),
220 printf_filtered (" at %s",
221 local_hex_string_custom
222 ((unsigned long) asect
->filepos
, "08l"));
223 printf_filtered (": %s", bfd_section_name (abfd
, asect
));
225 if (flags
& SEC_ALLOC
)
226 printf_filtered (" ALLOC");
227 if (flags
& SEC_LOAD
)
228 printf_filtered (" LOAD");
229 if (flags
& SEC_RELOC
)
230 printf_filtered (" RELOC");
231 if (flags
& SEC_READONLY
)
232 printf_filtered (" READONLY");
233 if (flags
& SEC_CODE
)
234 printf_filtered (" CODE");
235 if (flags
& SEC_DATA
)
236 printf_filtered (" DATA");
238 printf_filtered (" ROM");
239 if (flags
& SEC_CONSTRUCTOR
)
240 printf_filtered (" CONSTRUCTOR");
241 if (flags
& SEC_HAS_CONTENTS
)
242 printf_filtered (" HAS_CONTENTS");
243 if (flags
& SEC_NEVER_LOAD
)
244 printf_filtered (" NEVER_LOAD");
245 if (flags
& SEC_COFF_SHARED_LIBRARY
)
246 printf_filtered (" COFF_SHARED_LIBRARY");
247 if (flags
& SEC_IS_COMMON
)
248 printf_filtered (" IS_COMMON");
250 printf_filtered ("\n");
255 maintenance_info_sections (arg
, from_tty
)
261 printf_filtered ("Exec file:\n");
262 printf_filtered (" `%s', ", bfd_get_filename (exec_bfd
));
264 printf_filtered ("file type %s.\n", bfd_get_target (exec_bfd
));
265 bfd_map_over_sections (exec_bfd
, print_section_table
, 0);
270 printf_filtered ("Core file:\n");
271 printf_filtered (" `%s', ", bfd_get_filename (core_bfd
));
273 printf_filtered ("file type %s.\n", bfd_get_target (core_bfd
));
274 bfd_map_over_sections (core_bfd
, print_section_table
, 0);
280 maintenance_print_statistics (args
, from_tty
)
284 print_objfile_statistics ();
285 print_symbol_bcache_statistics ();
288 /* The "maintenance print" command is defined as a prefix, with allow_unknown
289 0. Therefore, its own definition is called only for "maintenance print"
294 maintenance_print_command (arg
, from_tty
)
298 printf_unfiltered ("\"maintenance print\" must be followed by the name of a print command.\n");
299 help_list (maintenanceprintlist
, "maintenance print ", -1, gdb_stdout
);
302 /* The "maintenance translate-address" command converts a section and address
303 to a symbol. This can be called in two ways:
304 maintenance translate-address <secname> <addr>
305 or maintenance translate-address <addr>
309 maintenance_translate_address (arg
, from_tty
)
316 struct minimal_symbol
*sym
;
317 struct objfile
*objfile
;
319 if (arg
== NULL
|| *arg
== 0)
320 error ("requires argument (address or section + address)");
326 { /* See if we have a valid section name */
327 while (*p
&& !isspace (*p
)) /* Find end of section name */
329 if (*p
== '\000') /* End of command? */
330 error ("Need to specify <section-name> and <address>");
333 p
++; /* Skip whitespace */
335 ALL_OBJFILES (objfile
)
337 sect
= bfd_get_section_by_name (objfile
->obfd
, arg
);
343 error ("Unknown section %s.", arg
);
346 address
= parse_and_eval_address (p
);
349 sym
= lookup_minimal_symbol_by_pc_section (address
, sect
);
351 sym
= lookup_minimal_symbol_by_pc (address
);
354 printf_filtered ("%s+%u\n",
355 SYMBOL_SOURCE_NAME (sym
),
356 address
- SYMBOL_VALUE_ADDRESS (sym
));
358 printf_filtered ("no symbol at %s:0x%08x\n", sect
->name
, address
);
360 printf_filtered ("no symbol at 0x%08x\n", address
);
366 _initialize_maint_cmds ()
368 add_prefix_cmd ("maintenance", class_maintenance
, maintenance_command
,
369 "Commands for use by GDB maintainers.\n\
370 Includes commands to dump specific internal GDB structures in\n\
371 a human readable form, to cause GDB to deliberately dump core,\n\
372 to test internal functions such as the C++ demangler, etc.",
373 &maintenancelist
, "maintenance ", 0,
376 add_com_alias ("mt", "maintenance", class_maintenance
, 1);
378 add_prefix_cmd ("info", class_maintenance
, maintenance_info_command
,
379 "Commands for showing internal info about the program being debugged.",
380 &maintenanceinfolist
, "maintenance info ", 0,
383 add_cmd ("sections", class_maintenance
, maintenance_info_sections
,
384 "List the BFD sections of the exec and core files.",
385 &maintenanceinfolist
);
387 add_prefix_cmd ("print", class_maintenance
, maintenance_print_command
,
388 "Maintenance command for printing GDB internal state.",
389 &maintenanceprintlist
, "maintenance print ", 0,
393 add_cmd ("dump-me", class_maintenance
, maintenance_dump_me
,
394 "Get fatal error; make debugger dump its core.\n\
395 GDB sets it's handling of SIGQUIT back to SIG_DFL and then sends\n\
396 itself a SIGQUIT signal.",
400 add_cmd ("internal-error", class_maintenance
, maintenance_internal_error
,
401 "Give GDB an internal error.\n\
402 Cause GDB to behave as if an internal error was detected.",
405 add_cmd ("demangle", class_maintenance
, maintenance_demangle
,
406 "Demangle a C++ mangled name.\n\
407 Call internal GDB demangler routine to demangle a C++ link name\n\
408 and prints the result.",
411 add_cmd ("time", class_maintenance
, maintenance_time_display
,
412 "Set the display of time usage.\n\
413 If nonzero, will cause the execution time for each command to be\n\
414 displayed, following the command's output.",
417 add_cmd ("space", class_maintenance
, maintenance_space_display
,
418 "Set the display of space usage.\n\
419 If nonzero, will cause the execution space for each command to be\n\
420 displayed, following the command's output.",
423 add_cmd ("type", class_maintenance
, maintenance_print_type
,
424 "Print a type chain for a given symbol.\n\
425 For each node in a type chain, print the raw data for each member of\n\
426 the type structure, and the interpretation of the data.",
427 &maintenanceprintlist
);
429 add_cmd ("symbols", class_maintenance
, maintenance_print_symbols
,
430 "Print dump of current symbol definitions.\n\
431 Entries in the full symbol table are dumped to file OUTFILE.\n\
432 If a SOURCE file is specified, dump only that file's symbols.",
433 &maintenanceprintlist
);
435 add_cmd ("msymbols", class_maintenance
, maintenance_print_msymbols
,
436 "Print dump of current minimal symbol definitions.\n\
437 Entries in the minimal symbol table are dumped to file OUTFILE.\n\
438 If a SOURCE file is specified, dump only that file's minimal symbols.",
439 &maintenanceprintlist
);
441 add_cmd ("psymbols", class_maintenance
, maintenance_print_psymbols
,
442 "Print dump of current partial symbol definitions.\n\
443 Entries in the partial symbol table are dumped to file OUTFILE.\n\
444 If a SOURCE file is specified, dump only that file's partial symbols.",
445 &maintenanceprintlist
);
447 add_cmd ("objfiles", class_maintenance
, maintenance_print_objfiles
,
448 "Print dump of current object file definitions.",
449 &maintenanceprintlist
);
451 add_cmd ("statistics", class_maintenance
, maintenance_print_statistics
,
452 "Print statistics about internal gdb state.",
453 &maintenanceprintlist
);
455 add_cmd ("check-symtabs", class_maintenance
, maintenance_check_symtabs
,
456 "Check consistency of psymtabs and symtabs.",
459 add_cmd ("translate-address", class_maintenance
, maintenance_translate_address
,
460 "Translate a section name and address to a symbol.",
464 add_set_cmd ("watchdog", class_maintenance
, var_zinteger
, (char *) &watchdog
,
465 "Set watchdog timer.\n\
466 When non-zero, this timeout is used instead of waiting forever for a target to\n\
467 finish a low-level step or continue operation. If the specified amount of time\n\
468 passes without a response from the target, an error occurs.", &setlist
),