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