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