Commit | Line | Data |
---|---|---|
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 | ||
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 | |
6c9638b4 | 19 | Foundation, 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 | 42 | static void maintenance_command PARAMS ((char *, int)); |
0239d9b3 | 43 | |
43ab4ba5 | 44 | static void maintenance_dump_me PARAMS ((char *, int)); |
0239d9b3 | 45 | |
43ab4ba5 SS |
46 | static void maintenance_demangle PARAMS ((char *, int)); |
47 | ||
48 | static void maintenance_time_display PARAMS ((char *, int)); | |
49 | ||
50 | static void maintenance_space_display PARAMS ((char *, int)); | |
311592ff | 51 | |
4887063b SG |
52 | /* Set this to the maximum number of seconds to wait instead of waiting forever |
53 | in target_wait(). If this timer times out, then it generates an error and | |
54 | the command is aborted. This replaces most of the need for timeouts in the | |
55 | GDB test suite, and makes it possible to distinguish between a hung target | |
56 | and one with slow communications. */ | |
57 | ||
58 | int watchdog = 0; | |
59 | ||
0239d9b3 FF |
60 | /* |
61 | ||
62 | LOCAL FUNCTION | |
63 | ||
64 | maintenance_command -- access the maintenance subcommands | |
65 | ||
66 | SYNOPSIS | |
67 | ||
68 | void maintenance_command (char *args, int from_tty) | |
69 | ||
70 | DESCRIPTION | |
71 | ||
72 | */ | |
73 | ||
74 | static void | |
75 | maintenance_command (args, from_tty) | |
76 | char *args; | |
77 | int from_tty; | |
78 | { | |
199b2450 TL |
79 | printf_unfiltered ("\"maintenance\" must be followed by the name of a maintenance command.\n"); |
80 | help_list (maintenancelist, "maintenance ", -1, gdb_stdout); | |
0239d9b3 FF |
81 | } |
82 | ||
83 | ||
84 | /* ARGSUSED */ | |
85 | static void | |
86 | maintenance_dump_me (args, from_tty) | |
87 | char *args; | |
88 | int from_tty; | |
89 | { | |
90 | if (query ("Should GDB dump core? ")) | |
91 | { | |
92 | signal (SIGQUIT, SIG_DFL); | |
93 | kill (getpid (), SIGQUIT); | |
94 | } | |
95 | } | |
96 | ||
311592ff FF |
97 | /* Someday we should allow demangling for things other than just |
98 | explicit strings. For example, we might want to be able to | |
99 | specify the address of a string in either GDB's process space | |
100 | or the debuggee's process space, and have gdb fetch and demangle | |
101 | that string. If we have a char* pointer "ptr" that points to | |
102 | a string, we might want to be able to given just the name and | |
103 | have GDB demangle and print what it points to, etc. (FIXME) */ | |
104 | ||
105 | static void | |
106 | maintenance_demangle (args, from_tty) | |
107 | char *args; | |
108 | int from_tty; | |
109 | { | |
110 | char *demangled; | |
111 | ||
112 | if (args == NULL || *args == '\0') | |
113 | { | |
199b2450 | 114 | printf_unfiltered ("\"maintenance demangle\" takes an argument to demangle.\n"); |
311592ff FF |
115 | } |
116 | else | |
117 | { | |
118 | demangled = cplus_demangle (args, DMGL_ANSI | DMGL_PARAMS); | |
119 | if (demangled != NULL) | |
120 | { | |
199b2450 | 121 | printf_unfiltered ("%s\n", demangled); |
311592ff FF |
122 | free (demangled); |
123 | } | |
124 | else | |
125 | { | |
199b2450 | 126 | printf_unfiltered ("Can't demangle \"%s\"\n", args); |
311592ff FF |
127 | } |
128 | } | |
129 | } | |
130 | ||
43ab4ba5 SS |
131 | static void |
132 | maintenance_time_display (args, from_tty) | |
133 | char *args; | |
134 | int from_tty; | |
135 | { | |
136 | extern int display_time; | |
137 | ||
138 | if (args == NULL || *args == '\0') | |
139 | printf_unfiltered ("\"maintenance time\" takes a numeric argument.\n"); | |
140 | else | |
141 | display_time = strtol (args, NULL, 10); | |
142 | } | |
143 | ||
144 | static void | |
145 | maintenance_space_display (args, from_tty) | |
146 | char *args; | |
147 | int from_tty; | |
148 | { | |
149 | extern int display_space; | |
150 | ||
151 | if (args == NULL || *args == '\0') | |
152 | printf_unfiltered ("\"maintenance space\" takes a numeric argument.\n"); | |
153 | else | |
154 | display_space = strtol (args, NULL, 10); | |
155 | } | |
156 | ||
0239d9b3 FF |
157 | /* The "maintenance info" command is defined as a prefix, with allow_unknown 0. |
158 | Therefore, its own definition is called only for "maintenance info" with | |
159 | no args. */ | |
160 | ||
161 | /* ARGSUSED */ | |
162 | static void | |
163 | maintenance_info_command (arg, from_tty) | |
164 | char *arg; | |
165 | int from_tty; | |
166 | { | |
199b2450 TL |
167 | printf_unfiltered ("\"maintenance info\" must be followed by the name of an info command.\n"); |
168 | help_list (maintenanceinfolist, "maintenance info ", -1, gdb_stdout); | |
0239d9b3 FF |
169 | } |
170 | ||
b1eaba9a SG |
171 | static void |
172 | print_section_table (abfd, asect, ignore) | |
173 | bfd *abfd; | |
174 | asection *asect; | |
175 | PTR ignore; | |
176 | { | |
177 | flagword flags; | |
178 | ||
179 | flags = bfd_get_section_flags (abfd, asect); | |
180 | ||
833e0d94 | 181 | /* FIXME-32x64: Need print_address_numeric with field width. */ |
b1eaba9a | 182 | printf_filtered (" %s", |
5573d7d4 JK |
183 | local_hex_string_custom |
184 | ((unsigned long) bfd_section_vma (abfd, asect), "08l")); | |
b1eaba9a | 185 | printf_filtered ("->%s", |
5573d7d4 JK |
186 | local_hex_string_custom |
187 | ((unsigned long) (bfd_section_vma (abfd, asect) | |
188 | + bfd_section_size (abfd, asect)), | |
189 | "08l")); | |
190 | printf_filtered (" at %s", | |
191 | local_hex_string_custom | |
192 | ((unsigned long) asect->filepos, "08l")); | |
b1eaba9a SG |
193 | printf_filtered (": %s", bfd_section_name (abfd, asect)); |
194 | ||
195 | if (flags & SEC_ALLOC) | |
196 | printf_filtered (" ALLOC"); | |
197 | if (flags & SEC_LOAD) | |
198 | printf_filtered (" LOAD"); | |
199 | if (flags & SEC_RELOC) | |
200 | printf_filtered (" RELOC"); | |
201 | if (flags & SEC_READONLY) | |
202 | printf_filtered (" READONLY"); | |
203 | if (flags & SEC_CODE) | |
204 | printf_filtered (" CODE"); | |
205 | if (flags & SEC_DATA) | |
206 | printf_filtered (" DATA"); | |
207 | if (flags & SEC_ROM) | |
208 | printf_filtered (" ROM"); | |
209 | if (flags & SEC_CONSTRUCTOR) | |
210 | printf_filtered (" CONSTRUCTOR"); | |
211 | if (flags & SEC_HAS_CONTENTS) | |
212 | printf_filtered (" HAS_CONTENTS"); | |
213 | if (flags & SEC_NEVER_LOAD) | |
214 | printf_filtered (" NEVER_LOAD"); | |
0286d386 ILT |
215 | if (flags & SEC_COFF_SHARED_LIBRARY) |
216 | printf_filtered (" COFF_SHARED_LIBRARY"); | |
b1eaba9a SG |
217 | if (flags & SEC_IS_COMMON) |
218 | printf_filtered (" IS_COMMON"); | |
219 | ||
220 | printf_filtered ("\n"); | |
221 | } | |
222 | ||
223 | /* ARGSUSED */ | |
224 | static void | |
225 | maintenance_info_sections (arg, from_tty) | |
226 | char *arg; | |
227 | int from_tty; | |
228 | { | |
229 | if (exec_bfd) | |
230 | { | |
231 | printf_filtered ("Exec file:\n"); | |
232 | printf_filtered (" `%s', ", bfd_get_filename(exec_bfd)); | |
233 | wrap_here (" "); | |
234 | printf_filtered ("file type %s.\n", bfd_get_target(exec_bfd)); | |
235 | bfd_map_over_sections(exec_bfd, print_section_table, 0); | |
236 | } | |
237 | ||
238 | if (core_bfd) | |
239 | { | |
240 | printf_filtered ("Core file:\n"); | |
241 | printf_filtered (" `%s', ", bfd_get_filename(core_bfd)); | |
242 | wrap_here (" "); | |
243 | printf_filtered ("file type %s.\n", bfd_get_target(core_bfd)); | |
244 | bfd_map_over_sections(core_bfd, print_section_table, 0); | |
245 | } | |
246 | } | |
247 | ||
2dd30c72 FF |
248 | /* ARGSUSED */ |
249 | void | |
250 | maintenance_print_statistics (args, from_tty) | |
251 | char *args; | |
252 | int from_tty; | |
253 | { | |
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 */ | |
263 | static void | |
264 | maintenance_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 | |
274 | void | |
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\ | |
280 | Includes commands to dump specific internal GDB structures in\n\ | |
311592ff FF |
281 | a human readable form, to cause GDB to deliberately dump core,\n\ |
282 | to 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\ | |
304 | GDB sets it's handling of SIGQUIT back to SIG_DFL and then sends\n\ | |
305 | itself a SIGQUIT signal.", | |
306 | &maintenancelist); | |
307 | ||
311592ff FF |
308 | add_cmd ("demangle", class_maintenance, maintenance_demangle, |
309 | "Demangle a C++ mangled name.\n\ | |
310 | Call internal GDB demangler routine to demangle a C++ link name\n\ | |
311 | and 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\ | |
316 | If nonzero, will cause the execution time for each command to be\n\ | |
317 | displayed, 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\ | |
322 | If nonzero, will cause the execution space for each command to be\n\ | |
323 | displayed, 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\ |
328 | For each node in a type chain, print the raw data for each member of\n\ | |
329 | the 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\ |
334 | Entries in the full symbol table are dumped to file OUTFILE.\n\ | |
335 | If 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\ |
340 | Entries in the minimal symbol table are dumped to file OUTFILE.\n\ | |
341 | If 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\ |
346 | Entries in the partial symbol table are dumped to file OUTFILE.\n\ | |
347 | If 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\ | |
365 | When non-zero, this timeout is used instead of waiting forever for a target to\n\ | |
366 | finish a low-level step or continue operation. If the specified amount of time\n\ | |
367 | passes without a response from the target, an error occurs.", &setlist), | |
368 | &showlist); | |
0239d9b3 | 369 | #endif /* MAINTENANCE_CMDS */ |
976bb0be | 370 | } |