* defs.h: Delete extraneous whitespace at end of file.
[platform/upstream/binutils.git] / gdb / maint.c
1 /* Support for GDB maintenance commands.
2    Copyright 1992, 1993, 1994 Free Software Foundation, Inc.
3    Written by Fred Fish at Cygnus Support.
4
5 This file is part of GDB.
6
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.
11
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.
16
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, Boston, MA 02111-1307, USA.  */
20
21
22 #include "defs.h"
23
24 #if MAINTENANCE_CMDS    /* Entire rest of file goes away if not including maint cmds */
25
26 #include <signal.h>
27 #include "command.h"
28 #include "gdbcmd.h"
29 #include "symtab.h"
30 #include "gdbtypes.h"
31 #include "demangle.h"
32 #include "gdbcore.h"
33 #include "expression.h" /* For language.h */
34 #include "language.h"
35
36 #ifdef HAVE_UNISTD_H
37 #include <unistd.h>
38 #endif
39
40 static void maintenance_command PARAMS ((char *, int));
41
42 static void maintenance_dump_me PARAMS ((char *, int));
43
44 static void maintenance_demangle PARAMS ((char *, int));
45
46 static void maintenance_time_display PARAMS ((char *, int));
47
48 static void maintenance_space_display PARAMS ((char *, int));
49
50 /* Set this to the maximum number of seconds to wait instead of waiting forever
51    in target_wait().  If this timer times out, then it generates an error and
52    the command is aborted.  This replaces most of the need for timeouts in the
53    GDB test suite, and makes it possible to distinguish between a hung target
54    and one with slow communications.  */
55
56 int watchdog = 0;
57
58 /*
59
60 LOCAL FUNCTION
61
62         maintenance_command -- access the maintenance subcommands
63
64 SYNOPSIS
65
66         void maintenance_command (char *args, int from_tty)
67
68 DESCRIPTION
69
70 */
71
72 static void
73 maintenance_command (args, from_tty)
74      char *args;
75      int from_tty;
76 {
77   printf_unfiltered ("\"maintenance\" must be followed by the name of a maintenance command.\n");
78   help_list (maintenancelist, "maintenance ", -1, gdb_stdout);
79 }
80
81
82 /* ARGSUSED */
83 static void
84 maintenance_dump_me (args, from_tty)
85      char *args;
86      int from_tty;
87 {
88   if (query ("Should GDB dump core? "))
89     {
90       signal (SIGQUIT, SIG_DFL);
91       kill (getpid (), SIGQUIT);
92     }
93 }
94
95 /*  Someday we should allow demangling for things other than just
96     explicit strings.  For example, we might want to be able to
97     specify the address of a string in either GDB's process space
98     or the debuggee's process space, and have gdb fetch and demangle
99     that string.  If we have a char* pointer "ptr" that points to
100     a string, we might want to be able to given just the name and
101     have GDB demangle and print what it points to, etc.  (FIXME) */
102
103 static void
104 maintenance_demangle (args, from_tty)
105      char *args;
106      int from_tty;
107 {
108   char *demangled;
109
110   if (args == NULL || *args == '\0')
111     {
112       printf_unfiltered ("\"maintenance demangle\" takes an argument to demangle.\n");
113     }
114   else
115     {
116       demangled = cplus_demangle (args, DMGL_ANSI | DMGL_PARAMS);
117       if (demangled != NULL)
118         {
119           printf_unfiltered ("%s\n", demangled);
120           free (demangled);
121         }
122       else
123         {
124           printf_unfiltered ("Can't demangle \"%s\"\n", args);
125         }
126     }
127 }
128
129 static void
130 maintenance_time_display (args, from_tty)
131      char *args;
132      int from_tty;
133 {
134   extern int display_time;
135
136   if (args == NULL || *args == '\0')
137     printf_unfiltered ("\"maintenance time\" takes a numeric argument.\n");
138   else
139     display_time = strtol (args, NULL, 10);
140 }
141
142 static void
143 maintenance_space_display (args, from_tty)
144      char *args;
145      int from_tty;
146 {
147   extern int display_space;
148
149   if (args == NULL || *args == '\0')
150     printf_unfiltered ("\"maintenance space\" takes a numeric argument.\n");
151   else
152     display_space = strtol (args, NULL, 10);
153 }
154
155 /* The "maintenance info" command is defined as a prefix, with allow_unknown 0.
156    Therefore, its own definition is called only for "maintenance info" with
157    no args.  */
158
159 /* ARGSUSED */
160 static void
161 maintenance_info_command (arg, from_tty)
162      char *arg;
163      int from_tty;
164 {
165   printf_unfiltered ("\"maintenance info\" must be followed by the name of an info command.\n");
166   help_list (maintenanceinfolist, "maintenance info ", -1, gdb_stdout);
167 }
168
169 static void
170 print_section_table (abfd, asect, ignore)
171      bfd *abfd;
172      asection *asect;
173      PTR ignore;
174 {
175   flagword flags;
176
177   flags = bfd_get_section_flags (abfd, asect);
178
179   /* FIXME-32x64: Need print_address_numeric with field width.  */
180   printf_filtered ("    %s",
181                    local_hex_string_custom
182                      ((unsigned long) bfd_section_vma (abfd, asect), "08l"));
183   printf_filtered ("->%s",
184                    local_hex_string_custom
185                      ((unsigned long) (bfd_section_vma (abfd, asect)
186                                        + bfd_section_size (abfd, asect)),
187                       "08l"));
188   printf_filtered (" at %s",
189                    local_hex_string_custom
190                      ((unsigned long) asect->filepos, "08l"));
191   printf_filtered (": %s", bfd_section_name (abfd, asect));
192
193   if (flags & SEC_ALLOC)
194     printf_filtered (" ALLOC");
195   if (flags & SEC_LOAD)
196     printf_filtered (" LOAD");
197   if (flags & SEC_RELOC)
198     printf_filtered (" RELOC");
199   if (flags & SEC_READONLY)
200     printf_filtered (" READONLY");
201   if (flags & SEC_CODE)
202     printf_filtered (" CODE");
203   if (flags & SEC_DATA)
204     printf_filtered (" DATA");
205   if (flags & SEC_ROM)
206     printf_filtered (" ROM");
207   if (flags & SEC_CONSTRUCTOR)
208     printf_filtered (" CONSTRUCTOR");
209   if (flags & SEC_HAS_CONTENTS)
210     printf_filtered (" HAS_CONTENTS");
211   if (flags & SEC_NEVER_LOAD)
212     printf_filtered (" NEVER_LOAD");
213   if (flags & SEC_COFF_SHARED_LIBRARY)
214     printf_filtered (" COFF_SHARED_LIBRARY");
215   if (flags & SEC_IS_COMMON)
216     printf_filtered (" IS_COMMON");
217
218   printf_filtered ("\n");
219 }
220
221 /* ARGSUSED */
222 static void
223 maintenance_info_sections (arg, from_tty)
224      char *arg;
225      int from_tty;
226 {
227   if (exec_bfd)
228     {
229       printf_filtered ("Exec file:\n");
230       printf_filtered ("    `%s', ", bfd_get_filename(exec_bfd));
231       wrap_here ("        ");
232       printf_filtered ("file type %s.\n", bfd_get_target(exec_bfd));
233       bfd_map_over_sections(exec_bfd, print_section_table, 0);
234     }
235
236   if (core_bfd)
237     {
238       printf_filtered ("Core file:\n");
239       printf_filtered ("    `%s', ", bfd_get_filename(core_bfd));
240       wrap_here ("        ");
241       printf_filtered ("file type %s.\n", bfd_get_target(core_bfd));
242       bfd_map_over_sections(core_bfd, print_section_table, 0);
243     }
244 }
245
246 /* ARGSUSED */
247 void
248 maintenance_print_statistics (args, from_tty)
249      char *args;
250      int from_tty;
251 {
252   print_objfile_statistics ();
253 }
254
255 /* The "maintenance print" command is defined as a prefix, with allow_unknown
256    0.  Therefore, its own definition is called only for "maintenance print"
257    with no args.  */
258
259 /* ARGSUSED */
260 static void
261 maintenance_print_command (arg, from_tty)
262      char *arg;
263      int from_tty;
264 {
265   printf_unfiltered ("\"maintenance print\" must be followed by the name of a print command.\n");
266   help_list (maintenanceprintlist, "maintenance print ", -1, gdb_stdout);
267 }
268
269 #endif  /* MAINTENANCE_CMDS */
270
271 void
272 _initialize_maint_cmds ()
273 {
274 #if MAINTENANCE_CMDS    /* Entire file goes away if not including maint cmds */
275   add_prefix_cmd ("maintenance", class_maintenance, maintenance_command,
276                   "Commands for use by GDB maintainers.\n\
277 Includes commands to dump specific internal GDB structures in\n\
278 a human readable form, to cause GDB to deliberately dump core,\n\
279 to test internal functions such as the C++ demangler, etc.",
280                   &maintenancelist, "maintenance ", 0,
281                   &cmdlist);
282
283   add_com_alias ("mt", "maintenance", class_maintenance, 1);
284
285   add_prefix_cmd ("info", class_maintenance, maintenance_info_command,
286                   "Commands for showing internal info about the program being debugged.",
287                   &maintenanceinfolist, "maintenance info ", 0,
288                   &maintenancelist);
289
290   add_cmd ("sections", class_maintenance, maintenance_info_sections,
291            "List the BFD sections of the exec and core files.",
292            &maintenanceinfolist);
293
294   add_prefix_cmd ("print", class_maintenance, maintenance_print_command,
295                   "Maintenance command for printing GDB internal state.",
296                   &maintenanceprintlist, "maintenance print ", 0,
297                   &maintenancelist);
298
299   add_cmd ("dump-me", class_maintenance, maintenance_dump_me,
300            "Get fatal error; make debugger dump its core.\n\
301 GDB sets it's handling of SIGQUIT back to SIG_DFL and then sends\n\
302 itself a SIGQUIT signal.",
303            &maintenancelist);
304
305   add_cmd ("demangle", class_maintenance, maintenance_demangle,
306            "Demangle a C++ mangled name.\n\
307 Call internal GDB demangler routine to demangle a C++ link name\n\
308 and prints the result.",
309            &maintenancelist);
310
311   add_cmd ("time", class_maintenance, maintenance_time_display,
312            "Set the display of time usage.\n\
313 If nonzero, will cause the execution time for each command to be\n\
314 displayed, following the command's output.",
315            &maintenancelist);
316
317   add_cmd ("space", class_maintenance, maintenance_space_display,
318            "Set the display of space usage.\n\
319 If nonzero, will cause the execution space for each command to be\n\
320 displayed, following the command's output.",
321            &maintenancelist);
322
323   add_cmd ("type", class_maintenance, maintenance_print_type,
324            "Print a type chain for a given symbol.\n\
325 For each node in a type chain, print the raw data for each member of\n\
326 the type structure, and the interpretation of the data.",
327            &maintenanceprintlist);
328
329   add_cmd ("symbols", class_maintenance, maintenance_print_symbols,
330            "Print dump of current symbol definitions.\n\
331 Entries in the full symbol table are dumped to file OUTFILE.\n\
332 If a SOURCE file is specified, dump only that file's symbols.",
333            &maintenanceprintlist);
334
335   add_cmd ("msymbols", class_maintenance, maintenance_print_msymbols,
336            "Print dump of current minimal symbol definitions.\n\
337 Entries in the minimal symbol table are dumped to file OUTFILE.\n\
338 If a SOURCE file is specified, dump only that file's minimal symbols.",
339            &maintenanceprintlist);
340
341   add_cmd ("psymbols", class_maintenance, maintenance_print_psymbols,
342            "Print dump of current partial symbol definitions.\n\
343 Entries in the partial symbol table are dumped to file OUTFILE.\n\
344 If a SOURCE file is specified, dump only that file's partial symbols.",
345            &maintenanceprintlist);
346
347   add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles,
348            "Print dump of current object file definitions.",
349            &maintenanceprintlist);
350
351   add_cmd ("statistics", class_maintenance, maintenance_print_statistics,
352            "Print statistics about internal gdb state.",
353            &maintenanceprintlist);
354
355   add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
356            "Check consistency of psymtabs and symtabs.",
357            &maintenancelist);
358
359   add_show_from_set (
360     add_set_cmd ("watchdog", class_maintenance, var_zinteger, (char *)&watchdog,
361                  "Set watchdog timer.\n\
362 When non-zero, this timeout is used instead of waiting forever for a target to\n\
363 finish a low-level step or continue operation.  If the specified amount of time\n\
364 passes without a response from the target, an error occurs.", &setlist),
365                      &showlist);
366 #endif  /* MAINTENANCE_CMDS */
367 }