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