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