import gdb-1999-08-16 snapshot
[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
38#ifdef HAVE_UNISTD_H
39#include <unistd.h>
40#endif
41
392a587b
JM
42extern void _initialize_maint_cmds PARAMS ((void));
43
c906108c
SS
44static void maintenance_command PARAMS ((char *, int));
45
46static void maintenance_dump_me PARAMS ((char *, int));
47
7be570e7
JM
48static void maintenance_internal_error PARAMS ((char *args, int from_tty));
49
c906108c
SS
50static void maintenance_demangle PARAMS ((char *, int));
51
52static void maintenance_time_display PARAMS ((char *, int));
53
54static void maintenance_space_display PARAMS ((char *, int));
55
56static void maintenance_info_command PARAMS ((char *, int));
57
58static void print_section_table PARAMS ((bfd *, asection *, PTR));
59
60static void maintenance_info_sections PARAMS ((char *, int));
61
62static void maintenance_print_command PARAMS ((char *, int));
63
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. */
69
70int watchdog = 0;
71
72/*
73
c5aa993b 74 LOCAL FUNCTION
c906108c 75
c5aa993b 76 maintenance_command -- access the maintenance subcommands
c906108c 77
c5aa993b 78 SYNOPSIS
c906108c 79
c5aa993b 80 void maintenance_command (char *args, int from_tty)
c906108c 81
c5aa993b 82 DESCRIPTION
c906108c 83
c5aa993b 84 */
c906108c
SS
85
86static void
87maintenance_command (args, from_tty)
88 char *args;
89 int from_tty;
90{
91 printf_unfiltered ("\"maintenance\" must be followed by the name of a maintenance command.\n");
92 help_list (maintenancelist, "maintenance ", -1, gdb_stdout);
93}
94
95#ifndef _WIN32
96/* ARGSUSED */
97static void
98maintenance_dump_me (args, from_tty)
99 char *args;
100 int from_tty;
101{
102 if (query ("Should GDB dump core? "))
103 {
7be570e7
JM
104#ifdef __DJGPP__
105 /* SIGQUIT by default is ignored, so use SIGABRT instead. */
106 signal (SIGABRT, SIG_DFL);
107 kill (getpid (), SIGABRT);
108#else
c906108c
SS
109 signal (SIGQUIT, SIG_DFL);
110 kill (getpid (), SIGQUIT);
7be570e7 111#endif
c906108c
SS
112 }
113}
114#endif
115
7be570e7
JM
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
119 GDB. */
120
121static void
122maintenance_internal_error (char *args, int from_tty)
123{
124 internal_error ("internal maintenance");
125}
126
c906108c 127/* Someday we should allow demangling for things other than just
c5aa993b
JM
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) */
c906108c
SS
134
135static void
136maintenance_demangle (args, from_tty)
137 char *args;
138 int from_tty;
139{
140 char *demangled;
141
142 if (args == NULL || *args == '\0')
143 {
144 printf_unfiltered ("\"maintenance demangle\" takes an argument to demangle.\n");
145 }
146 else
147 {
148 demangled = cplus_demangle (args, DMGL_ANSI | DMGL_PARAMS);
149 if (demangled != NULL)
150 {
151 printf_unfiltered ("%s\n", demangled);
152 free (demangled);
153 }
154 else
155 {
156 printf_unfiltered ("Can't demangle \"%s\"\n", args);
157 }
158 }
159}
160
161static void
162maintenance_time_display (args, from_tty)
163 char *args;
164 int from_tty;
165{
166 extern int display_time;
167
168 if (args == NULL || *args == '\0')
169 printf_unfiltered ("\"maintenance time\" takes a numeric argument.\n");
170 else
171 display_time = strtol (args, NULL, 10);
172}
173
174static void
175maintenance_space_display (args, from_tty)
176 char *args;
177 int from_tty;
178{
179 extern int display_space;
180
181 if (args == NULL || *args == '\0')
182 printf_unfiltered ("\"maintenance space\" takes a numeric argument.\n");
183 else
184 display_space = strtol (args, NULL, 10);
185}
186
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
189 no args. */
190
191/* ARGSUSED */
192static void
193maintenance_info_command (arg, from_tty)
194 char *arg;
195 int from_tty;
196{
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);
199}
200
201static void
202print_section_table (abfd, asect, ignore)
203 bfd *abfd;
204 asection *asect;
205 PTR ignore;
206{
207 flagword flags;
208
209 flags = bfd_get_section_flags (abfd, asect);
210
211 /* FIXME-32x64: Need print_address_numeric with field width. */
212 printf_filtered (" %s",
213 local_hex_string_custom
c5aa993b 214 ((unsigned long) bfd_section_vma (abfd, asect), "08l"));
c906108c
SS
215 printf_filtered ("->%s",
216 local_hex_string_custom
c5aa993b
JM
217 ((unsigned long) (bfd_section_vma (abfd, asect)
218 + bfd_section_size (abfd, asect)),
219 "08l"));
c906108c
SS
220 printf_filtered (" at %s",
221 local_hex_string_custom
c5aa993b 222 ((unsigned long) asect->filepos, "08l"));
c906108c
SS
223 printf_filtered (": %s", bfd_section_name (abfd, asect));
224
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");
237 if (flags & SEC_ROM)
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");
249
250 printf_filtered ("\n");
251}
252
253/* ARGSUSED */
254static void
255maintenance_info_sections (arg, from_tty)
256 char *arg;
257 int from_tty;
258{
259 if (exec_bfd)
260 {
261 printf_filtered ("Exec file:\n");
c5aa993b 262 printf_filtered (" `%s', ", bfd_get_filename (exec_bfd));
c906108c 263 wrap_here (" ");
c5aa993b
JM
264 printf_filtered ("file type %s.\n", bfd_get_target (exec_bfd));
265 bfd_map_over_sections (exec_bfd, print_section_table, 0);
c906108c
SS
266 }
267
268 if (core_bfd)
269 {
270 printf_filtered ("Core file:\n");
c5aa993b 271 printf_filtered (" `%s', ", bfd_get_filename (core_bfd));
c906108c 272 wrap_here (" ");
c5aa993b
JM
273 printf_filtered ("file type %s.\n", bfd_get_target (core_bfd));
274 bfd_map_over_sections (core_bfd, print_section_table, 0);
c906108c
SS
275 }
276}
277
278/* ARGSUSED */
279void
280maintenance_print_statistics (args, from_tty)
281 char *args;
282 int from_tty;
283{
284 print_objfile_statistics ();
285 print_symbol_bcache_statistics ();
286}
287
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"
290 with no args. */
291
292/* ARGSUSED */
293static void
294maintenance_print_command (arg, from_tty)
295 char *arg;
296 int from_tty;
297{
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);
300}
301
302/* The "maintenance translate-address" command converts a section and address
303 to a symbol. This can be called in two ways:
c5aa993b
JM
304 maintenance translate-address <secname> <addr>
305 or maintenance translate-address <addr>
306 */
c906108c
SS
307
308static void
309maintenance_translate_address (arg, from_tty)
310 char *arg;
311 int from_tty;
312{
313 CORE_ADDR address;
314 asection *sect;
315 char *p;
316 struct minimal_symbol *sym;
317 struct objfile *objfile;
318
319 if (arg == NULL || *arg == 0)
320 error ("requires argument (address or section + address)");
321
322 sect = NULL;
323 p = arg;
324
325 if (!isdigit (*p))
326 { /* See if we have a valid section name */
c5aa993b 327 while (*p && !isspace (*p)) /* Find end of section name */
c906108c
SS
328 p++;
329 if (*p == '\000') /* End of command? */
330 error ("Need to specify <section-name> and <address>");
331 *p++ = '\000';
c5aa993b
JM
332 while (isspace (*p))
333 p++; /* Skip whitespace */
c906108c
SS
334
335 ALL_OBJFILES (objfile)
c5aa993b
JM
336 {
337 sect = bfd_get_section_by_name (objfile->obfd, arg);
338 if (sect != NULL)
339 break;
340 }
c906108c
SS
341
342 if (!sect)
343 error ("Unknown section %s.", arg);
344 }
345
346 address = parse_and_eval_address (p);
347
348 if (sect)
349 sym = lookup_minimal_symbol_by_pc_section (address, sect);
350 else
351 sym = lookup_minimal_symbol_by_pc (address);
352
353 if (sym)
c5aa993b
JM
354 printf_filtered ("%s+%u\n",
355 SYMBOL_SOURCE_NAME (sym),
c906108c
SS
356 address - SYMBOL_VALUE_ADDRESS (sym));
357 else if (sect)
358 printf_filtered ("no symbol at %s:0x%08x\n", sect->name, address);
359 else
360 printf_filtered ("no symbol at 0x%08x\n", address);
361
362 return;
363}
364
c906108c
SS
365void
366_initialize_maint_cmds ()
367{
c906108c
SS
368 add_prefix_cmd ("maintenance", class_maintenance, maintenance_command,
369 "Commands for use by GDB maintainers.\n\
370Includes commands to dump specific internal GDB structures in\n\
371a human readable form, to cause GDB to deliberately dump core,\n\
372to test internal functions such as the C++ demangler, etc.",
373 &maintenancelist, "maintenance ", 0,
374 &cmdlist);
375
376 add_com_alias ("mt", "maintenance", class_maintenance, 1);
377
378 add_prefix_cmd ("info", class_maintenance, maintenance_info_command,
c5aa993b 379 "Commands for showing internal info about the program being debugged.",
c906108c
SS
380 &maintenanceinfolist, "maintenance info ", 0,
381 &maintenancelist);
382
383 add_cmd ("sections", class_maintenance, maintenance_info_sections,
384 "List the BFD sections of the exec and core files.",
385 &maintenanceinfolist);
386
387 add_prefix_cmd ("print", class_maintenance, maintenance_print_command,
388 "Maintenance command for printing GDB internal state.",
389 &maintenanceprintlist, "maintenance print ", 0,
390 &maintenancelist);
391
392#ifndef _WIN32
393 add_cmd ("dump-me", class_maintenance, maintenance_dump_me,
394 "Get fatal error; make debugger dump its core.\n\
395GDB sets it's handling of SIGQUIT back to SIG_DFL and then sends\n\
396itself a SIGQUIT signal.",
397 &maintenancelist);
398#endif
399
7be570e7
JM
400 add_cmd ("internal-error", class_maintenance, maintenance_internal_error,
401 "Give GDB an internal error.\n\
402Cause GDB to behave as if an internal error was detected.",
403 &maintenancelist);
404
c906108c
SS
405 add_cmd ("demangle", class_maintenance, maintenance_demangle,
406 "Demangle a C++ mangled name.\n\
407Call internal GDB demangler routine to demangle a C++ link name\n\
408and prints the result.",
409 &maintenancelist);
410
411 add_cmd ("time", class_maintenance, maintenance_time_display,
412 "Set the display of time usage.\n\
413If nonzero, will cause the execution time for each command to be\n\
414displayed, following the command's output.",
415 &maintenancelist);
416
417 add_cmd ("space", class_maintenance, maintenance_space_display,
418 "Set the display of space usage.\n\
419If nonzero, will cause the execution space for each command to be\n\
420displayed, following the command's output.",
421 &maintenancelist);
422
423 add_cmd ("type", class_maintenance, maintenance_print_type,
424 "Print a type chain for a given symbol.\n\
425For each node in a type chain, print the raw data for each member of\n\
426the type structure, and the interpretation of the data.",
427 &maintenanceprintlist);
428
429 add_cmd ("symbols", class_maintenance, maintenance_print_symbols,
430 "Print dump of current symbol definitions.\n\
431Entries in the full symbol table are dumped to file OUTFILE.\n\
432If a SOURCE file is specified, dump only that file's symbols.",
433 &maintenanceprintlist);
434
435 add_cmd ("msymbols", class_maintenance, maintenance_print_msymbols,
436 "Print dump of current minimal symbol definitions.\n\
437Entries in the minimal symbol table are dumped to file OUTFILE.\n\
438If a SOURCE file is specified, dump only that file's minimal symbols.",
439 &maintenanceprintlist);
440
441 add_cmd ("psymbols", class_maintenance, maintenance_print_psymbols,
442 "Print dump of current partial symbol definitions.\n\
443Entries in the partial symbol table are dumped to file OUTFILE.\n\
444If a SOURCE file is specified, dump only that file's partial symbols.",
445 &maintenanceprintlist);
446
447 add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles,
448 "Print dump of current object file definitions.",
449 &maintenanceprintlist);
450
451 add_cmd ("statistics", class_maintenance, maintenance_print_statistics,
452 "Print statistics about internal gdb state.",
453 &maintenanceprintlist);
454
455 add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
456 "Check consistency of psymtabs and symtabs.",
457 &maintenancelist);
458
459 add_cmd ("translate-address", class_maintenance, maintenance_translate_address,
460 "Translate a section name and address to a symbol.",
461 &maintenancelist);
462
463 add_show_from_set (
c5aa993b
JM
464 add_set_cmd ("watchdog", class_maintenance, var_zinteger, (char *) &watchdog,
465 "Set watchdog timer.\n\
c906108c
SS
466When non-zero, this timeout is used instead of waiting forever for a target to\n\
467finish a low-level step or continue operation. If the specified amount of time\n\
468passes without a response from the target, an error occurs.", &setlist),
c5aa993b 469 &showlist);
c906108c 470}
This page took 0.054878 seconds and 4 git commands to generate.