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