* Makefile.in configure configure.in: Remove ENABLE_CLIBS,
[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"
b52cac6b
FF
35#include "symfile.h"
36#include "objfiles.h"
0239d9b3 37
1a494973
C
38#ifdef HAVE_UNISTD_H
39#include <unistd.h>
40#endif
41
43ab4ba5 42static void maintenance_command PARAMS ((char *, int));
0239d9b3 43
43ab4ba5 44static void maintenance_dump_me PARAMS ((char *, int));
0239d9b3 45
43ab4ba5
SS
46static void maintenance_demangle PARAMS ((char *, int));
47
48static void maintenance_time_display PARAMS ((char *, int));
49
50static void maintenance_space_display PARAMS ((char *, int));
311592ff 51
b607efe7
FF
52static void maintenance_info_command PARAMS ((char *, int));
53
54static void print_section_table PARAMS ((bfd *, asection *, PTR));
55
56static void maintenance_info_sections PARAMS ((char *, int));
57
58static void maintenance_print_command PARAMS ((char *, int));
59
4887063b
SG
60/* Set this to the maximum number of seconds to wait instead of waiting forever
61 in target_wait(). If this timer times out, then it generates an error and
62 the command is aborted. This replaces most of the need for timeouts in the
63 GDB test suite, and makes it possible to distinguish between a hung target
64 and one with slow communications. */
65
66int watchdog = 0;
67
0239d9b3
FF
68/*
69
70LOCAL FUNCTION
71
72 maintenance_command -- access the maintenance subcommands
73
74SYNOPSIS
75
76 void maintenance_command (char *args, int from_tty)
77
78DESCRIPTION
79
80*/
81
82static void
83maintenance_command (args, from_tty)
84 char *args;
85 int from_tty;
86{
199b2450
TL
87 printf_unfiltered ("\"maintenance\" must be followed by the name of a maintenance command.\n");
88 help_list (maintenancelist, "maintenance ", -1, gdb_stdout);
0239d9b3
FF
89}
90
9e77e83d 91#ifndef _WIN32
0239d9b3
FF
92/* ARGSUSED */
93static void
94maintenance_dump_me (args, from_tty)
95 char *args;
96 int from_tty;
97{
98 if (query ("Should GDB dump core? "))
99 {
100 signal (SIGQUIT, SIG_DFL);
101 kill (getpid (), SIGQUIT);
102 }
103}
9e77e83d 104#endif
0239d9b3 105
311592ff
FF
106/* Someday we should allow demangling for things other than just
107 explicit strings. For example, we might want to be able to
108 specify the address of a string in either GDB's process space
109 or the debuggee's process space, and have gdb fetch and demangle
110 that string. If we have a char* pointer "ptr" that points to
111 a string, we might want to be able to given just the name and
112 have GDB demangle and print what it points to, etc. (FIXME) */
113
114static void
115maintenance_demangle (args, from_tty)
116 char *args;
117 int from_tty;
118{
119 char *demangled;
120
121 if (args == NULL || *args == '\0')
122 {
199b2450 123 printf_unfiltered ("\"maintenance demangle\" takes an argument to demangle.\n");
311592ff
FF
124 }
125 else
126 {
127 demangled = cplus_demangle (args, DMGL_ANSI | DMGL_PARAMS);
128 if (demangled != NULL)
129 {
199b2450 130 printf_unfiltered ("%s\n", demangled);
311592ff
FF
131 free (demangled);
132 }
133 else
134 {
199b2450 135 printf_unfiltered ("Can't demangle \"%s\"\n", args);
311592ff
FF
136 }
137 }
138}
139
43ab4ba5
SS
140static void
141maintenance_time_display (args, from_tty)
142 char *args;
143 int from_tty;
144{
145 extern int display_time;
146
147 if (args == NULL || *args == '\0')
148 printf_unfiltered ("\"maintenance time\" takes a numeric argument.\n");
149 else
150 display_time = strtol (args, NULL, 10);
151}
152
153static void
154maintenance_space_display (args, from_tty)
155 char *args;
156 int from_tty;
157{
158 extern int display_space;
159
160 if (args == NULL || *args == '\0')
161 printf_unfiltered ("\"maintenance space\" takes a numeric argument.\n");
162 else
163 display_space = strtol (args, NULL, 10);
164}
165
0239d9b3
FF
166/* The "maintenance info" command is defined as a prefix, with allow_unknown 0.
167 Therefore, its own definition is called only for "maintenance info" with
168 no args. */
169
170/* ARGSUSED */
171static void
172maintenance_info_command (arg, from_tty)
173 char *arg;
174 int from_tty;
175{
199b2450
TL
176 printf_unfiltered ("\"maintenance info\" must be followed by the name of an info command.\n");
177 help_list (maintenanceinfolist, "maintenance info ", -1, gdb_stdout);
0239d9b3
FF
178}
179
b1eaba9a
SG
180static void
181print_section_table (abfd, asect, ignore)
182 bfd *abfd;
183 asection *asect;
184 PTR ignore;
185{
186 flagword flags;
187
188 flags = bfd_get_section_flags (abfd, asect);
189
833e0d94 190 /* FIXME-32x64: Need print_address_numeric with field width. */
b1eaba9a 191 printf_filtered (" %s",
5573d7d4
JK
192 local_hex_string_custom
193 ((unsigned long) bfd_section_vma (abfd, asect), "08l"));
b1eaba9a 194 printf_filtered ("->%s",
5573d7d4
JK
195 local_hex_string_custom
196 ((unsigned long) (bfd_section_vma (abfd, asect)
197 + bfd_section_size (abfd, asect)),
198 "08l"));
199 printf_filtered (" at %s",
200 local_hex_string_custom
201 ((unsigned long) asect->filepos, "08l"));
b1eaba9a
SG
202 printf_filtered (": %s", bfd_section_name (abfd, asect));
203
204 if (flags & SEC_ALLOC)
205 printf_filtered (" ALLOC");
206 if (flags & SEC_LOAD)
207 printf_filtered (" LOAD");
208 if (flags & SEC_RELOC)
209 printf_filtered (" RELOC");
210 if (flags & SEC_READONLY)
211 printf_filtered (" READONLY");
212 if (flags & SEC_CODE)
213 printf_filtered (" CODE");
214 if (flags & SEC_DATA)
215 printf_filtered (" DATA");
216 if (flags & SEC_ROM)
217 printf_filtered (" ROM");
218 if (flags & SEC_CONSTRUCTOR)
219 printf_filtered (" CONSTRUCTOR");
220 if (flags & SEC_HAS_CONTENTS)
221 printf_filtered (" HAS_CONTENTS");
222 if (flags & SEC_NEVER_LOAD)
223 printf_filtered (" NEVER_LOAD");
0286d386
ILT
224 if (flags & SEC_COFF_SHARED_LIBRARY)
225 printf_filtered (" COFF_SHARED_LIBRARY");
b1eaba9a
SG
226 if (flags & SEC_IS_COMMON)
227 printf_filtered (" IS_COMMON");
228
229 printf_filtered ("\n");
230}
231
232/* ARGSUSED */
233static void
234maintenance_info_sections (arg, from_tty)
235 char *arg;
236 int from_tty;
237{
238 if (exec_bfd)
239 {
240 printf_filtered ("Exec file:\n");
241 printf_filtered (" `%s', ", bfd_get_filename(exec_bfd));
242 wrap_here (" ");
243 printf_filtered ("file type %s.\n", bfd_get_target(exec_bfd));
244 bfd_map_over_sections(exec_bfd, print_section_table, 0);
245 }
246
247 if (core_bfd)
248 {
249 printf_filtered ("Core file:\n");
250 printf_filtered (" `%s', ", bfd_get_filename(core_bfd));
251 wrap_here (" ");
252 printf_filtered ("file type %s.\n", bfd_get_target(core_bfd));
253 bfd_map_over_sections(core_bfd, print_section_table, 0);
254 }
255}
256
2dd30c72
FF
257/* ARGSUSED */
258void
259maintenance_print_statistics (args, from_tty)
260 char *args;
261 int from_tty;
262{
263 print_objfile_statistics ();
2ad5709f 264 print_symbol_bcache_statistics ();
2dd30c72
FF
265}
266
311592ff
FF
267/* The "maintenance print" command is defined as a prefix, with allow_unknown
268 0. Therefore, its own definition is called only for "maintenance print"
269 with no args. */
270
271/* ARGSUSED */
272static void
273maintenance_print_command (arg, from_tty)
274 char *arg;
275 int from_tty;
276{
199b2450
TL
277 printf_unfiltered ("\"maintenance print\" must be followed by the name of a print command.\n");
278 help_list (maintenanceprintlist, "maintenance print ", -1, gdb_stdout);
311592ff
FF
279}
280
4c681116
SG
281/* The "maintenance translate-address" command converts a section and address
282 to a symbol. This can be called in two ways:
283 maintenance translate-address <secname> <addr>
284 or maintenance translate-address <addr>
285*/
286
287static void
288maintenance_translate_address (arg, from_tty)
289 char *arg;
290 int from_tty;
291{
292 CORE_ADDR address;
293 asection *sect;
294 char *p;
295 struct symbol *sym;
296
297 sect = NULL;
298 p = arg;
299
300 if (!isdigit (p))
301 { /* See if we have a valid section name */
302 while (*p && !isspace (*p)) /* Find end of section name */
303 p++;
304 if (*p == '\000') /* End of command? */
305 error ("Need to specify <section-name> and <address>");
306 *p++ = '\000';
307 while (isspace (*p)) p++; /* Skip whitespace */
308
309 sect = bfd_get_section_by_name (exec_bfd, arg);
310 if (!sect)
311 error ("Unknown section %s.", arg);
312 }
313
314 address = parse_and_eval_address (p);
315
316 return;
317/* sym = find_pc_function_section (address, sect);*/
318
319 printf_unfiltered ("%s+%u\n", SYMBOL_SOURCE_NAME (sym), address - SYMBOL_VALUE_ADDRESS (sym));
320}
321
976bb0be 322#endif /* MAINTENANCE_CMDS */
0239d9b3
FF
323
324void
325_initialize_maint_cmds ()
326{
976bb0be 327#if MAINTENANCE_CMDS /* Entire file goes away if not including maint cmds */
0239d9b3
FF
328 add_prefix_cmd ("maintenance", class_maintenance, maintenance_command,
329 "Commands for use by GDB maintainers.\n\
330Includes commands to dump specific internal GDB structures in\n\
311592ff
FF
331a human readable form, to cause GDB to deliberately dump core,\n\
332to test internal functions such as the C++ demangler, etc.",
2e9309df 333 &maintenancelist, "maintenance ", 0,
0239d9b3
FF
334 &cmdlist);
335
327f7197 336 add_com_alias ("mt", "maintenance", class_maintenance, 1);
311592ff 337
327f7197
JG
338 add_prefix_cmd ("info", class_maintenance, maintenance_info_command,
339 "Commands for showing internal info about the program being debugged.",
2e9309df 340 &maintenanceinfolist, "maintenance info ", 0,
0239d9b3
FF
341 &maintenancelist);
342
b1eaba9a
SG
343 add_cmd ("sections", class_maintenance, maintenance_info_sections,
344 "List the BFD sections of the exec and core files.",
345 &maintenanceinfolist);
346
311592ff
FF
347 add_prefix_cmd ("print", class_maintenance, maintenance_print_command,
348 "Maintenance command for printing GDB internal state.",
349 &maintenanceprintlist, "maintenance print ", 0,
350 &maintenancelist);
351
9e77e83d 352#ifndef _WIN32
0239d9b3
FF
353 add_cmd ("dump-me", class_maintenance, maintenance_dump_me,
354 "Get fatal error; make debugger dump its core.\n\
355GDB sets it's handling of SIGQUIT back to SIG_DFL and then sends\n\
356itself a SIGQUIT signal.",
357 &maintenancelist);
9e77e83d 358#endif
0239d9b3 359
311592ff
FF
360 add_cmd ("demangle", class_maintenance, maintenance_demangle,
361 "Demangle a C++ mangled name.\n\
362Call internal GDB demangler routine to demangle a C++ link name\n\
363and prints the result.",
364 &maintenancelist);
365
43ab4ba5
SS
366 add_cmd ("time", class_maintenance, maintenance_time_display,
367 "Set the display of time usage.\n\
368If nonzero, will cause the execution time for each command to be\n\
369displayed, following the command's output.",
370 &maintenancelist);
371
372 add_cmd ("space", class_maintenance, maintenance_space_display,
373 "Set the display of space usage.\n\
374If nonzero, will cause the execution space for each command to be\n\
375displayed, following the command's output.",
376 &maintenancelist);
377
311592ff 378 add_cmd ("type", class_maintenance, maintenance_print_type,
0239d9b3
FF
379 "Print a type chain for a given symbol.\n\
380For each node in a type chain, print the raw data for each member of\n\
381the type structure, and the interpretation of the data.",
311592ff 382 &maintenanceprintlist);
0239d9b3 383
311592ff 384 add_cmd ("symbols", class_maintenance, maintenance_print_symbols,
0239d9b3
FF
385 "Print dump of current symbol definitions.\n\
386Entries in the full symbol table are dumped to file OUTFILE.\n\
387If a SOURCE file is specified, dump only that file's symbols.",
311592ff 388 &maintenanceprintlist);
0239d9b3 389
311592ff 390 add_cmd ("msymbols", class_maintenance, maintenance_print_msymbols,
0239d9b3
FF
391 "Print dump of current minimal symbol definitions.\n\
392Entries in the minimal symbol table are dumped to file OUTFILE.\n\
393If a SOURCE file is specified, dump only that file's minimal symbols.",
311592ff 394 &maintenanceprintlist);
0239d9b3 395
311592ff 396 add_cmd ("psymbols", class_maintenance, maintenance_print_psymbols,
0239d9b3
FF
397 "Print dump of current partial symbol definitions.\n\
398Entries in the partial symbol table are dumped to file OUTFILE.\n\
399If a SOURCE file is specified, dump only that file's partial symbols.",
311592ff 400 &maintenanceprintlist);
0239d9b3 401
311592ff 402 add_cmd ("objfiles", class_maintenance, maintenance_print_objfiles,
0239d9b3 403 "Print dump of current object file definitions.",
311592ff 404 &maintenanceprintlist);
71c33ef7 405
2dd30c72
FF
406 add_cmd ("statistics", class_maintenance, maintenance_print_statistics,
407 "Print statistics about internal gdb state.",
408 &maintenanceprintlist);
409
71c33ef7
PS
410 add_cmd ("check-symtabs", class_maintenance, maintenance_check_symtabs,
411 "Check consistency of psymtabs and symtabs.",
412 &maintenancelist);
4887063b 413
4c681116
SG
414 add_cmd ("translate-address", class_maintenance, maintenance_translate_address,
415 "Translate a section name and address to a symbol.",
416 &maintenancelist);
417
4887063b
SG
418 add_show_from_set (
419 add_set_cmd ("watchdog", class_maintenance, var_zinteger, (char *)&watchdog,
420 "Set watchdog timer.\n\
421When non-zero, this timeout is used instead of waiting forever for a target to\n\
422finish a low-level step or continue operation. If the specified amount of time\n\
423passes without a response from the target, an error occurs.", &setlist),
424 &showlist);
0239d9b3 425#endif /* MAINTENANCE_CMDS */
976bb0be 426}
This page took 0.421834 seconds and 4 git commands to generate.