* bcache.c, bcache.h: New files to implement a byte cache.
[deliverable/binutils-gdb.git] / gdb / maint.c
CommitLineData
0239d9b3 1/* Support for GDB maintenance commands.
43ab4ba5 2 Copyright 1992, 1993, 1994 Free Software Foundation, Inc.
0239d9b3
FF
3 Written by Fred Fish at Cygnus Support.
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
6c9638b4 19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
0239d9b3
FF
20
21
22#include "defs.h"
23
2dd30c72 24#if MAINTENANCE_CMDS /* Entire rest of file goes away if not including maint cmds */
0239d9b3
FF
25
26#include <signal.h>
27#include "command.h"
28#include "gdbcmd.h"
29#include "symtab.h"
30#include "gdbtypes.h"
311592ff 31#include "demangle.h"
b1eaba9a 32#include "gdbcore.h"
100f92e2
JK
33#include "expression.h" /* For language.h */
34#include "language.h"
0239d9b3 35
1a494973
C
36#ifdef HAVE_UNISTD_H
37#include <unistd.h>
38#endif
39
43ab4ba5 40static void maintenance_command PARAMS ((char *, int));
0239d9b3 41
43ab4ba5 42static void maintenance_dump_me PARAMS ((char *, int));
0239d9b3 43
43ab4ba5
SS
44static void maintenance_demangle PARAMS ((char *, int));
45
46static void maintenance_time_display PARAMS ((char *, int));
47
48static void maintenance_space_display PARAMS ((char *, int));
311592ff 49
4887063b
SG
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
56int watchdog = 0;
57
0239d9b3
FF
58/*
59
60LOCAL FUNCTION
61
62 maintenance_command -- access the maintenance subcommands
63
64SYNOPSIS
65
66 void maintenance_command (char *args, int from_tty)
67
68DESCRIPTION
69
70*/
71
72static void
73maintenance_command (args, from_tty)
74 char *args;
75 int from_tty;
76{
199b2450
TL
77 printf_unfiltered ("\"maintenance\" must be followed by the name of a maintenance command.\n");
78 help_list (maintenancelist, "maintenance ", -1, gdb_stdout);
0239d9b3
FF
79}
80
81
82/* ARGSUSED */
83static void
84maintenance_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
311592ff
FF
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
103static void
104maintenance_demangle (args, from_tty)
105 char *args;
106 int from_tty;
107{
108 char *demangled;
109
110 if (args == NULL || *args == '\0')
111 {
199b2450 112 printf_unfiltered ("\"maintenance demangle\" takes an argument to demangle.\n");
311592ff
FF
113 }
114 else
115 {
116 demangled = cplus_demangle (args, DMGL_ANSI | DMGL_PARAMS);
117 if (demangled != NULL)
118 {
199b2450 119 printf_unfiltered ("%s\n", demangled);
311592ff
FF
120 free (demangled);
121 }
122 else
123 {
199b2450 124 printf_unfiltered ("Can't demangle \"%s\"\n", args);
311592ff
FF
125 }
126 }
127}
128
43ab4ba5
SS
129static void
130maintenance_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
142static void
143maintenance_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
0239d9b3
FF
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 */
160static void
161maintenance_info_command (arg, from_tty)
162 char *arg;
163 int from_tty;
164{
199b2450
TL
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);
0239d9b3
FF
167}
168
b1eaba9a
SG
169static void
170print_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
833e0d94 179 /* FIXME-32x64: Need print_address_numeric with field width. */
b1eaba9a 180 printf_filtered (" %s",
5573d7d4
JK
181 local_hex_string_custom
182 ((unsigned long) bfd_section_vma (abfd, asect), "08l"));
b1eaba9a 183 printf_filtered ("->%s",
5573d7d4
JK
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"));
b1eaba9a
SG
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");
0286d386
ILT
213 if (flags & SEC_COFF_SHARED_LIBRARY)
214 printf_filtered (" COFF_SHARED_LIBRARY");
b1eaba9a
SG
215 if (flags & SEC_IS_COMMON)
216 printf_filtered (" IS_COMMON");
217
218 printf_filtered ("\n");
219}
220
221/* ARGSUSED */
222static void
223maintenance_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
2dd30c72
FF
246/* ARGSUSED */
247void
248maintenance_print_statistics (args, from_tty)
249 char *args;
250 int from_tty;
251{
2ad5709f
FF
252 int temp;
253
2dd30c72 254 print_objfile_statistics ();
2ad5709f 255 print_symbol_bcache_statistics ();
2dd30c72
FF
256}
257
311592ff
FF
258/* The "maintenance print" command is defined as a prefix, with allow_unknown
259 0. Therefore, its own definition is called only for "maintenance print"
260 with no args. */
261
262/* ARGSUSED */
263static void
264maintenance_print_command (arg, from_tty)
265 char *arg;
266 int from_tty;
267{
199b2450
TL
268 printf_unfiltered ("\"maintenance print\" must be followed by the name of a print command.\n");
269 help_list (maintenanceprintlist, "maintenance print ", -1, gdb_stdout);
311592ff
FF
270}
271
976bb0be 272#endif /* MAINTENANCE_CMDS */
0239d9b3
FF
273
274void
275_initialize_maint_cmds ()
276{
976bb0be 277#if MAINTENANCE_CMDS /* Entire file goes away if not including maint cmds */
0239d9b3
FF
278 add_prefix_cmd ("maintenance", class_maintenance, maintenance_command,
279 "Commands for use by GDB maintainers.\n\
280Includes commands to dump specific internal GDB structures in\n\
311592ff
FF
281a human readable form, to cause GDB to deliberately dump core,\n\
282to test internal functions such as the C++ demangler, etc.",
2e9309df 283 &maintenancelist, "maintenance ", 0,
0239d9b3
FF
284 &cmdlist);
285
327f7197 286 add_com_alias ("mt", "maintenance", class_maintenance, 1);
311592ff 287
327f7197
JG
288 add_prefix_cmd ("info", class_maintenance, maintenance_info_command,
289 "Commands for showing internal info about the program being debugged.",
2e9309df 290 &maintenanceinfolist, "maintenance info ", 0,
0239d9b3
FF
291 &maintenancelist);
292
b1eaba9a
SG
293 add_cmd ("sections", class_maintenance, maintenance_info_sections,
294 "List the BFD sections of the exec and core files.",
295 &maintenanceinfolist);
296
311592ff
FF
297 add_prefix_cmd ("print", class_maintenance, maintenance_print_command,
298 "Maintenance command for printing GDB internal state.",
299 &maintenanceprintlist, "maintenance print ", 0,
300 &maintenancelist);
301
0239d9b3
FF
302 add_cmd ("dump-me", class_maintenance, maintenance_dump_me,
303 "Get fatal error; make debugger dump its core.\n\
304GDB sets it's handling of SIGQUIT back to SIG_DFL and then sends\n\
305itself a SIGQUIT signal.",
306 &maintenancelist);
307
311592ff
FF
308 add_cmd ("demangle", class_maintenance, maintenance_demangle,
309 "Demangle a C++ mangled name.\n\
310Call internal GDB demangler routine to demangle a C++ link name\n\
311and prints the result.",
312 &maintenancelist);
313
43ab4ba5
SS
314 add_cmd ("time", class_maintenance, maintenance_time_display,
315 "Set the display of time usage.\n\
316If nonzero, will cause the execution time for each command to be\n\
317displayed, following the command's output.",
318 &maintenancelist);
319
320 add_cmd ("space", class_maintenance, maintenance_space_display,
321 "Set the display of space usage.\n\
322If nonzero, will cause the execution space for each command to be\n\
323displayed, following the command's output.",
324 &maintenancelist);
325
311592ff 326 add_cmd ("type", class_maintenance, maintenance_print_type,
0239d9b3
FF
327 "Print a type chain for a given symbol.\n\
328For each node in a type chain, print the raw data for each member of\n\
329the type structure, and the interpretation of the data.",
311592ff 330 &maintenanceprintlist);
0239d9b3 331
311592ff 332 add_cmd ("symbols", class_maintenance, maintenance_print_symbols,
0239d9b3
FF
333 "Print dump of current symbol definitions.\n\
334Entries in the full symbol table are dumped to file OUTFILE.\n\
335If a SOURCE file is specified, dump only that file's symbols.",
311592ff 336 &maintenanceprintlist);
0239d9b3 337
311592ff 338 add_cmd ("msymbols", class_maintenance, maintenance_print_msymbols,
0239d9b3
FF
339 "Print dump of current minimal symbol definitions.\n\
340Entries in the minimal symbol table are dumped to file OUTFILE.\n\
341If a SOURCE file is specified, dump only that file's minimal symbols.",
311592ff 342 &maintenanceprintlist);
0239d9b3 343
311592ff 344 add_cmd ("psymbols", class_maintenance, maintenance_print_psymbols,
0239d9b3
FF
345 "Print dump of current partial symbol definitions.\n\
346Entries in the partial symbol table are dumped to file OUTFILE.\n\
347If a SOURCE file is specified, dump only that file's partial symbols.",
311592ff 348 &maintenanceprintlist);
0239d9b3 349
311592ff 350 add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles,
0239d9b3 351 "Print dump of current object file definitions.",
311592ff 352 &maintenanceprintlist);
71c33ef7 353
2dd30c72
FF
354 add_cmd ("statistics", class_maintenance, maintenance_print_statistics,
355 "Print statistics about internal gdb state.",
356 &maintenanceprintlist);
357
71c33ef7
PS
358 add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
359 "Check consistency of psymtabs and symtabs.",
360 &maintenancelist);
4887063b
SG
361
362 add_show_from_set (
363 add_set_cmd ("watchdog", class_maintenance, var_zinteger, (char *)&watchdog,
364 "Set watchdog timer.\n\
365When non-zero, this timeout is used instead of waiting forever for a target to\n\
366finish a low-level step or continue operation. If the specified amount of time\n\
367passes without a response from the target, an error occurs.", &setlist),
368 &showlist);
0239d9b3 369#endif /* MAINTENANCE_CMDS */
976bb0be 370}
This page took 0.415038 seconds and 4 git commands to generate.