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