Commit | Line | Data |
---|---|---|
7d9884b9 | 1 | /* Top level `main' program for GDB, the GNU debugger. |
51b57ded FF |
2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992 |
3 | Free Software Foundation, Inc. | |
bd5635a1 RP |
4 | |
5 | This file is part of GDB. | |
6 | ||
e522fb52 | 7 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 8 | it under the terms of the GNU General Public License as published by |
e522fb52 JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
bd5635a1 | 11 | |
e522fb52 | 12 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
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 | |
e522fb52 JG |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
bd5635a1 | 20 | |
bd5635a1 RP |
21 | #include "defs.h" |
22 | #include "gdbcmd.h" | |
51b57ded | 23 | #include "call-cmds.h" |
bd5635a1 RP |
24 | #include "symtab.h" |
25 | #include "inferior.h" | |
26 | #include "signals.h" | |
27 | #include "target.h" | |
28 | #include "breakpoint.h" | |
30875e1c SG |
29 | #include "gdbtypes.h" |
30 | #include "expression.h" | |
bd099407 | 31 | #include "language.h" |
bd5635a1 | 32 | |
e522fb52 JG |
33 | #include "getopt.h" |
34 | ||
35 | /* readline include files */ | |
36 | #include "readline.h" | |
37 | #include "history.h" | |
bd5635a1 RP |
38 | |
39 | /* readline defines this. */ | |
40 | #undef savestring | |
41 | ||
42 | #ifdef USG | |
43 | #include <sys/types.h> | |
44 | #include <unistd.h> | |
45 | #endif | |
46 | ||
47 | #include <string.h> | |
ee0613d1 | 48 | #ifndef NO_SYS_FILE |
bd5635a1 | 49 | #include <sys/file.h> |
ee0613d1 | 50 | #endif |
bd5635a1 RP |
51 | #include <setjmp.h> |
52 | #include <sys/param.h> | |
53 | #include <sys/stat.h> | |
e522fb52 | 54 | #include <ctype.h> |
bd5635a1 RP |
55 | |
56 | #ifdef SET_STACK_LIMIT_HUGE | |
57 | #include <sys/time.h> | |
58 | #include <sys/resource.h> | |
bd5635a1 RP |
59 | |
60 | int original_stack_limit; | |
61 | #endif | |
62 | ||
30875e1c SG |
63 | /* Prototypes for local functions */ |
64 | ||
65 | static char * | |
66 | symbol_completion_function PARAMS ((char *, int)); | |
67 | ||
68 | static void | |
69 | command_loop PARAMS ((void)); | |
70 | ||
71 | static void | |
72 | command_loop_marker PARAMS ((int)); | |
73 | ||
74 | static void | |
75 | print_gdb_version PARAMS ((void)); | |
76 | ||
77 | static void | |
78 | quit_command PARAMS ((char *, int)); | |
79 | ||
80 | static void | |
81 | initialize_main PARAMS ((void)); | |
82 | ||
83 | static void | |
84 | initialize_history PARAMS ((void)); | |
85 | ||
86 | static void | |
87 | initialize_cmd_lists PARAMS ((void)); | |
88 | ||
89 | static void | |
90 | float_handler PARAMS ((int)); | |
91 | ||
92 | static void | |
93 | source_command PARAMS ((char *, int)); | |
94 | ||
95 | static void | |
96 | cd_command PARAMS ((char *, int)); | |
97 | ||
98 | static void | |
99 | print_gnu_advertisement PARAMS ((void)); | |
100 | ||
101 | static void | |
102 | init_signals PARAMS ((void)); | |
103 | ||
104 | static void | |
105 | read_command_file PARAMS ((FILE *)); | |
106 | ||
107 | static void | |
108 | set_verbose PARAMS ((char *, int, struct cmd_list_element *)); | |
109 | ||
110 | static void | |
111 | show_history PARAMS ((char *, int)); | |
112 | ||
113 | static void | |
114 | set_history PARAMS ((char *, int)); | |
115 | ||
116 | static void | |
117 | set_history_size_command PARAMS ((char *, int, struct cmd_list_element *)); | |
118 | ||
119 | static void | |
120 | show_commands PARAMS ((char *, int)); | |
121 | ||
30875e1c SG |
122 | static void |
123 | echo_command PARAMS ((char *, int)); | |
124 | ||
125 | static void | |
126 | pwd_command PARAMS ((char *, int)); | |
127 | ||
128 | static void | |
129 | show_version PARAMS ((char *, int)); | |
130 | ||
131 | static void | |
132 | document_command PARAMS ((char *, int)); | |
133 | ||
134 | static void | |
135 | define_command PARAMS ((char *, int)); | |
136 | ||
137 | static void | |
138 | validate_comname PARAMS ((char *)); | |
139 | ||
140 | static void | |
141 | help_command PARAMS ((char *, int)); | |
142 | ||
143 | static void | |
144 | show_command PARAMS ((char *, int)); | |
145 | ||
146 | static void | |
147 | info_command PARAMS ((char *, int)); | |
148 | ||
149 | static void | |
150 | do_nothing PARAMS ((int)); | |
151 | ||
152 | static void | |
153 | disconnect PARAMS ((int)); | |
154 | ||
155 | static void | |
156 | source_cleanup PARAMS ((FILE *)); | |
bd5635a1 RP |
157 | |
158 | /* If this definition isn't overridden by the header files, assume | |
159 | that isatty and fileno exist on this system. */ | |
160 | #ifndef ISATTY | |
161 | #define ISATTY(FP) (isatty (fileno (FP))) | |
162 | #endif | |
163 | ||
164 | /* Initialization file name for gdb. This is overridden in some configs. */ | |
165 | ||
166 | #ifndef GDBINIT_FILENAME | |
167 | #define GDBINIT_FILENAME ".gdbinit" | |
168 | #endif | |
169 | char gdbinit[] = GDBINIT_FILENAME; | |
170 | ||
f266e564 JK |
171 | #define ALL_CLEANUPS ((struct cleanup *)0) |
172 | ||
bd5635a1 RP |
173 | /* Version number of GDB, as a string. */ |
174 | ||
175 | extern char *version; | |
176 | ||
81066208 JG |
177 | /* Message to be printed before the error message, when an error occurs. */ |
178 | ||
179 | extern char *error_pre_print; | |
180 | ||
318bf84f FF |
181 | /* Message to be printed before the warning message, when a warning occurs. */ |
182 | ||
183 | extern char *warning_pre_print; | |
184 | ||
bd099407 JG |
185 | extern char lang_frame_mismatch_warn[]; /* language.c */ |
186 | ||
ee0613d1 JG |
187 | /* Whether GDB's stdin is on a terminal. */ |
188 | ||
189 | extern int gdb_has_a_terminal; /* inflow.c */ | |
190 | ||
bd5635a1 RP |
191 | /* Flag for whether we want all the "from_tty" gubbish printed. */ |
192 | ||
193 | int caution = 1; /* Default is yes, sigh. */ | |
194 | ||
195 | /* | |
196 | * Define all cmd_list_element's | |
197 | */ | |
198 | ||
199 | /* Chain containing all defined commands. */ | |
200 | ||
201 | struct cmd_list_element *cmdlist; | |
202 | ||
203 | /* Chain containing all defined info subcommands. */ | |
204 | ||
205 | struct cmd_list_element *infolist; | |
206 | ||
207 | /* Chain containing all defined enable subcommands. */ | |
208 | ||
209 | struct cmd_list_element *enablelist; | |
210 | ||
211 | /* Chain containing all defined disable subcommands. */ | |
212 | ||
213 | struct cmd_list_element *disablelist; | |
214 | ||
215 | /* Chain containing all defined delete subcommands. */ | |
216 | ||
217 | struct cmd_list_element *deletelist; | |
218 | ||
219 | /* Chain containing all defined "enable breakpoint" subcommands. */ | |
220 | ||
221 | struct cmd_list_element *enablebreaklist; | |
222 | ||
223 | /* Chain containing all defined set subcommands */ | |
224 | ||
225 | struct cmd_list_element *setlist; | |
226 | ||
0239d9b3 FF |
227 | /* Chain containing all defined unset subcommands */ |
228 | ||
229 | struct cmd_list_element *unsetlist; | |
230 | ||
bd5635a1 | 231 | /* Chain containing all defined show subcommands. */ |
0239d9b3 | 232 | |
bd5635a1 RP |
233 | struct cmd_list_element *showlist; |
234 | ||
235 | /* Chain containing all defined \"set history\". */ | |
236 | ||
237 | struct cmd_list_element *sethistlist; | |
238 | ||
239 | /* Chain containing all defined \"show history\". */ | |
0239d9b3 | 240 | |
bd5635a1 RP |
241 | struct cmd_list_element *showhistlist; |
242 | ||
243 | /* Chain containing all defined \"unset history\". */ | |
244 | ||
245 | struct cmd_list_element *unsethistlist; | |
246 | ||
0239d9b3 FF |
247 | /* Chain containing all defined maintenance subcommands. */ |
248 | ||
249 | #if MAINTENANCE_CMDS | |
250 | struct cmd_list_element *maintenancelist; | |
251 | #endif | |
252 | ||
253 | /* Chain containing all defined "maintenance info" subcommands. */ | |
254 | ||
255 | #if MAINTENANCE_CMDS | |
256 | struct cmd_list_element *maintenanceinfolist; | |
257 | #endif | |
258 | ||
a8e033f2 SG |
259 | /* Chain containing all defined "maintenance print" subcommands. */ |
260 | ||
261 | #if MAINTENANCE_CMDS | |
262 | struct cmd_list_element *maintenanceprintlist; | |
263 | #endif | |
264 | ||
0239d9b3 FF |
265 | struct cmd_list_element *setprintlist; |
266 | ||
267 | struct cmd_list_element *showprintlist; | |
268 | ||
269 | struct cmd_list_element *setchecklist; | |
270 | ||
271 | struct cmd_list_element *showchecklist; | |
272 | ||
bd5635a1 RP |
273 | /* stdio stream that command input is being read from. */ |
274 | ||
275 | FILE *instream; | |
276 | ||
277 | /* Current working directory. */ | |
278 | ||
279 | char *current_directory; | |
280 | ||
281 | /* The directory name is actually stored here (usually). */ | |
f7402c04 | 282 | static char dirbuf[1024]; |
bd5635a1 RP |
283 | |
284 | /* Function to call before reading a command, if nonzero. | |
285 | The function receives two args: an input stream, | |
286 | and a prompt string. */ | |
bd099407 | 287 | |
30875e1c | 288 | void (*window_hook) PARAMS ((FILE *, char *)); |
bd5635a1 RP |
289 | |
290 | extern int frame_file_full_name; | |
318bf84f FF |
291 | extern int mapped_symbol_files; |
292 | extern int readnow_symbol_files; | |
293 | ||
bd5635a1 RP |
294 | int epoch_interface; |
295 | int xgdb_verbose; | |
296 | ||
bd5635a1 RP |
297 | /* gdb prints this when reading a command interactively */ |
298 | static char *prompt; | |
299 | ||
300 | /* Buffer used for reading command lines, and the size | |
301 | allocated for it so far. */ | |
302 | ||
303 | char *line; | |
304 | int linesize = 100; | |
305 | ||
306 | /* Baud rate specified for talking to serial target systems. Default | |
307 | is left as a zero pointer, so targets can choose their own defaults. */ | |
308 | ||
309 | char *baud_rate; | |
310 | ||
311 | /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */ | |
312 | ||
313 | #ifndef STOP_SIGNAL | |
314 | #ifdef SIGTSTP | |
315 | #define STOP_SIGNAL SIGTSTP | |
30875e1c | 316 | static void stop_sig PARAMS ((int)); |
bd5635a1 RP |
317 | #endif |
318 | #endif | |
d566d62a JK |
319 | |
320 | /* Some System V have job control but not sigsetmask(). */ | |
321 | #if !defined (HAVE_SIGSETMASK) | |
322 | #define HAVE_SIGSETMASK !defined (USG) | |
323 | #endif | |
324 | ||
8b3c897a | 325 | #if 0 == (HAVE_SIGSETMASK) |
d566d62a JK |
326 | #define sigsetmask(n) |
327 | #endif | |
bd5635a1 RP |
328 | \f |
329 | /* This is how `error' returns to command level. */ | |
330 | ||
331 | jmp_buf to_top_level; | |
332 | ||
30875e1c | 333 | NORETURN void |
bd5635a1 RP |
334 | return_to_top_level () |
335 | { | |
336 | quit_flag = 0; | |
337 | immediate_quit = 0; | |
338 | bpstat_clear_actions(stop_bpstat); /* Clear queued breakpoint commands */ | |
bd5635a1 | 339 | disable_current_display (); |
f266e564 | 340 | do_cleanups (ALL_CLEANUPS); |
30875e1c | 341 | (NORETURN void) longjmp (to_top_level, 1); |
bd5635a1 RP |
342 | } |
343 | ||
344 | /* Call FUNC with arg ARGS, catching any errors. | |
345 | If there is no error, return the value returned by FUNC. | |
81066208 JG |
346 | If there is an error, print ERRSTRING, print the specific error message, |
347 | then return zero. */ | |
bd5635a1 RP |
348 | |
349 | int | |
350 | catch_errors (func, args, errstring) | |
30875e1c | 351 | int (*func) PARAMS ((char *)); |
bdbd5f50 | 352 | char *args; |
bd5635a1 RP |
353 | char *errstring; |
354 | { | |
355 | jmp_buf saved; | |
356 | int val; | |
357 | struct cleanup *saved_cleanup_chain; | |
81066208 | 358 | char *saved_error_pre_print; |
bd5635a1 RP |
359 | |
360 | saved_cleanup_chain = save_cleanups (); | |
81066208 | 361 | saved_error_pre_print = error_pre_print; |
bd5635a1 | 362 | |
318bf84f | 363 | memcpy ((char *)saved, (char *)to_top_level, sizeof (jmp_buf)); |
81066208 | 364 | error_pre_print = errstring; |
bd5635a1 RP |
365 | |
366 | if (setjmp (to_top_level) == 0) | |
367 | val = (*func) (args); | |
368 | else | |
81066208 | 369 | val = 0; |
bd5635a1 RP |
370 | |
371 | restore_cleanups (saved_cleanup_chain); | |
372 | ||
81066208 | 373 | error_pre_print = saved_error_pre_print; |
318bf84f | 374 | memcpy ((char *)to_top_level, (char *)saved, sizeof (jmp_buf)); |
bd5635a1 RP |
375 | return val; |
376 | } | |
377 | ||
378 | /* Handler for SIGHUP. */ | |
379 | ||
380 | static void | |
30875e1c SG |
381 | disconnect (signo) |
382 | int signo; | |
bd5635a1 RP |
383 | { |
384 | kill_inferior_fast (); | |
318bf84f | 385 | signal (signo, SIG_DFL); |
bd5635a1 RP |
386 | kill (getpid (), SIGHUP); |
387 | } | |
388 | \f | |
389 | /* Clean up on error during a "source" command (or execution of a | |
390 | user-defined command). */ | |
391 | ||
392 | static void | |
393 | source_cleanup (stream) | |
394 | FILE *stream; | |
395 | { | |
396 | /* Restore the previous input stream. */ | |
397 | instream = stream; | |
398 | } | |
399 | ||
400 | /* Read commands from STREAM. */ | |
401 | static void | |
402 | read_command_file (stream) | |
403 | FILE *stream; | |
404 | { | |
405 | struct cleanup *cleanups; | |
406 | ||
407 | cleanups = make_cleanup (source_cleanup, instream); | |
408 | instream = stream; | |
409 | command_loop (); | |
410 | do_cleanups (cleanups); | |
411 | } | |
412 | \f | |
413 | int | |
414 | main (argc, argv) | |
415 | int argc; | |
416 | char **argv; | |
417 | { | |
418 | int count; | |
419 | static int inhibit_gdbinit = 0; | |
420 | static int quiet = 0; | |
421 | static int batch = 0; | |
422 | ||
423 | /* Pointers to various arguments from command line. */ | |
424 | char *symarg = NULL; | |
425 | char *execarg = NULL; | |
426 | char *corearg = NULL; | |
427 | char *cdarg = NULL; | |
428 | char *ttyarg = NULL; | |
429 | ||
430 | /* Pointers to all arguments of +command option. */ | |
431 | char **cmdarg; | |
432 | /* Allocated size of cmdarg. */ | |
433 | int cmdsize; | |
434 | /* Number of elements of cmdarg used. */ | |
435 | int ncmd; | |
436 | ||
437 | /* Indices of all arguments of +directory option. */ | |
438 | char **dirarg; | |
439 | /* Allocated size. */ | |
440 | int dirsize; | |
441 | /* Number of elements used. */ | |
442 | int ndir; | |
443 | ||
3a16d640 JG |
444 | struct stat homebuf, cwdbuf; |
445 | char *homedir, *homeinit; | |
446 | ||
bd5635a1 RP |
447 | register int i; |
448 | ||
449 | /* This needs to happen before the first use of malloc. */ | |
318bf84f | 450 | init_malloc ((PTR) NULL); |
bd5635a1 RP |
451 | |
452 | #if defined (ALIGN_STACK_ON_STARTUP) | |
453 | i = (int) &count & 0x3; | |
454 | if (i != 0) | |
455 | alloca (4 - i); | |
456 | #endif | |
457 | ||
bd099407 JG |
458 | /* If error() is called from initialization code, just exit */ |
459 | if (setjmp (to_top_level)) { | |
460 | exit(1); | |
461 | } | |
462 | ||
bd5635a1 RP |
463 | cmdsize = 1; |
464 | cmdarg = (char **) xmalloc (cmdsize * sizeof (*cmdarg)); | |
465 | ncmd = 0; | |
466 | dirsize = 1; | |
467 | dirarg = (char **) xmalloc (dirsize * sizeof (*dirarg)); | |
468 | ndir = 0; | |
469 | ||
470 | quit_flag = 0; | |
471 | line = (char *) xmalloc (linesize); | |
472 | line[0] = '\0'; /* Terminate saved (now empty) cmd line */ | |
473 | instream = stdin; | |
474 | ||
f7402c04 | 475 | getcwd (dirbuf, sizeof (dirbuf)); |
bd5635a1 RP |
476 | current_directory = dirbuf; |
477 | ||
478 | #ifdef SET_STACK_LIMIT_HUGE | |
479 | { | |
480 | struct rlimit rlim; | |
481 | ||
482 | /* Set the stack limit huge so that alloca (particularly stringtab | |
483 | * in dbxread.c) does not fail. */ | |
484 | getrlimit (RLIMIT_STACK, &rlim); | |
485 | original_stack_limit = rlim.rlim_cur; | |
486 | rlim.rlim_cur = rlim.rlim_max; | |
487 | setrlimit (RLIMIT_STACK, &rlim); | |
488 | } | |
489 | #endif /* SET_STACK_LIMIT_HUGE */ | |
490 | ||
491 | /* Parse arguments and options. */ | |
492 | { | |
493 | int c; | |
494 | static int print_help; | |
495 | /* When var field is 0, use flag field to record the equivalent | |
496 | short option (or arbitrary numbers starting at 10 for those | |
497 | with no equivalent). */ | |
498 | static struct option long_options[] = | |
499 | { | |
318bf84f FF |
500 | {"readnow", no_argument, &readnow_symbol_files, 1}, |
501 | {"r", no_argument, &readnow_symbol_files, 1}, | |
502 | {"mapped", no_argument, &mapped_symbol_files, 1}, | |
503 | {"m", no_argument, &mapped_symbol_files, 1}, | |
ee0613d1 JG |
504 | {"quiet", no_argument, &quiet, 1}, |
505 | {"q", no_argument, &quiet, 1}, | |
506 | {"nx", no_argument, &inhibit_gdbinit, 1}, | |
507 | {"n", no_argument, &inhibit_gdbinit, 1}, | |
508 | {"batch", no_argument, &batch, 1}, | |
509 | {"epoch", no_argument, &epoch_interface, 1}, | |
510 | {"fullname", no_argument, &frame_file_full_name, 1}, | |
511 | {"f", no_argument, &frame_file_full_name, 1}, | |
512 | {"help", no_argument, &print_help, 1}, | |
513 | {"se", required_argument, 0, 10}, | |
514 | {"symbols", required_argument, 0, 's'}, | |
515 | {"s", required_argument, 0, 's'}, | |
516 | {"exec", required_argument, 0, 'e'}, | |
517 | {"e", required_argument, 0, 'e'}, | |
518 | {"core", required_argument, 0, 'c'}, | |
519 | {"c", required_argument, 0, 'c'}, | |
520 | {"command", required_argument, 0, 'x'}, | |
521 | {"x", required_argument, 0, 'x'}, | |
522 | {"directory", required_argument, 0, 'd'}, | |
523 | {"cd", required_argument, 0, 11}, | |
524 | {"tty", required_argument, 0, 't'}, | |
525 | {"baud", required_argument, 0, 'b'}, | |
526 | {"b", required_argument, 0, 'b'}, | |
bd5635a1 RP |
527 | /* Allow machine descriptions to add more options... */ |
528 | #ifdef ADDITIONAL_OPTIONS | |
529 | ADDITIONAL_OPTIONS | |
530 | #endif | |
ee0613d1 | 531 | {0, no_argument, 0, 0}, |
bd5635a1 RP |
532 | }; |
533 | ||
534 | while (1) | |
535 | { | |
ee0613d1 JG |
536 | int option_index; |
537 | ||
bd5635a1 RP |
538 | c = getopt_long_only (argc, argv, "", |
539 | long_options, &option_index); | |
540 | if (c == EOF) | |
541 | break; | |
542 | ||
543 | /* Long option that takes an argument. */ | |
544 | if (c == 0 && long_options[option_index].flag == 0) | |
545 | c = long_options[option_index].val; | |
546 | ||
547 | switch (c) | |
548 | { | |
549 | case 0: | |
550 | /* Long option that just sets a flag. */ | |
551 | break; | |
552 | case 10: | |
553 | symarg = optarg; | |
554 | execarg = optarg; | |
555 | break; | |
556 | case 11: | |
557 | cdarg = optarg; | |
558 | break; | |
559 | case 's': | |
560 | symarg = optarg; | |
561 | break; | |
562 | case 'e': | |
563 | execarg = optarg; | |
564 | break; | |
565 | case 'c': | |
566 | corearg = optarg; | |
567 | break; | |
568 | case 'x': | |
569 | cmdarg[ncmd++] = optarg; | |
570 | if (ncmd >= cmdsize) | |
571 | { | |
572 | cmdsize *= 2; | |
573 | cmdarg = (char **) xrealloc ((char *)cmdarg, | |
574 | cmdsize * sizeof (*cmdarg)); | |
575 | } | |
576 | break; | |
577 | case 'd': | |
578 | dirarg[ndir++] = optarg; | |
579 | if (ndir >= dirsize) | |
580 | { | |
581 | dirsize *= 2; | |
582 | dirarg = (char **) xrealloc ((char *)dirarg, | |
583 | dirsize * sizeof (*dirarg)); | |
584 | } | |
585 | break; | |
586 | case 't': | |
587 | ttyarg = optarg; | |
588 | break; | |
589 | case 'q': | |
590 | quiet = 1; | |
591 | break; | |
592 | case 'b': | |
593 | baud_rate = optarg; | |
594 | break; | |
595 | #ifdef ADDITIONAL_OPTION_CASES | |
596 | ADDITIONAL_OPTION_CASES | |
597 | #endif | |
598 | case '?': | |
a8e033f2 | 599 | fprintf_filtered (stderr, |
bd5635a1 RP |
600 | "Use `%s +help' for a complete list of options.\n", |
601 | argv[0]); | |
602 | exit (1); | |
603 | } | |
604 | ||
605 | } | |
606 | if (print_help) | |
607 | { | |
608 | fputs ("\ | |
609 | This is GDB, the GNU debugger. Use the command\n\ | |
610 | gdb [options] [executable [core-file]]\n\ | |
611 | to enter the debugger.\n\ | |
612 | \n\ | |
613 | Options available are:\n\ | |
614 | -help Print this message.\n\ | |
615 | -quiet Do not print version number on startup.\n\ | |
616 | -fullname Output information used by emacs-GDB interface.\n\ | |
617 | -epoch Output information used by epoch emacs-GDB interface.\n\ | |
618 | -batch Exit after processing options.\n\ | |
619 | -nx Do not read .gdbinit file.\n\ | |
620 | -tty=TTY Use TTY for input/output by the program being debugged.\n\ | |
621 | -cd=DIR Change current directory to DIR.\n\ | |
622 | -directory=DIR Search for source files in DIR.\n\ | |
623 | -command=FILE Execute GDB commands from FILE.\n\ | |
624 | -symbols=SYMFILE Read symbols from SYMFILE.\n\ | |
625 | -exec=EXECFILE Use EXECFILE as the executable.\n\ | |
626 | -se=FILE Use FILE as symbol file and executable file.\n\ | |
627 | -core=COREFILE Analyze the core dump COREFILE.\n\ | |
b0246b3b FF |
628 | -b BAUDRATE Set serial port baud rate used for remote debugging.\n\ |
629 | -mapped Use mapped symbol files if supported on this system.\n\ | |
630 | -readnow Fully read symbol files on first access.\n\ | |
bd5635a1 RP |
631 | ", stderr); |
632 | #ifdef ADDITIONAL_OPTION_HELP | |
633 | fputs (ADDITIONAL_OPTION_HELP, stderr); | |
634 | #endif | |
635 | fputs ("\n\ | |
636 | For more information, type \"help\" from within GDB, or consult the\n\ | |
637 | GDB manual (available as on-line info or a printed manual).\n", stderr); | |
638 | /* Exiting after printing this message seems like | |
639 | the most useful thing to do. */ | |
640 | exit (0); | |
641 | } | |
642 | ||
643 | /* OK, that's all the options. The other arguments are filenames. */ | |
644 | count = 0; | |
645 | for (; optind < argc; optind++) | |
646 | switch (++count) | |
647 | { | |
648 | case 1: | |
649 | symarg = argv[optind]; | |
650 | execarg = argv[optind]; | |
651 | break; | |
652 | case 2: | |
653 | corearg = argv[optind]; | |
654 | break; | |
655 | case 3: | |
a8e033f2 | 656 | fprintf_filtered (stderr, |
bd5635a1 RP |
657 | "Excess command line arguments ignored. (%s%s)\n", |
658 | argv[optind], (optind == argc - 1) ? "" : " ..."); | |
659 | break; | |
660 | } | |
661 | if (batch) | |
662 | quiet = 1; | |
663 | } | |
664 | ||
665 | /* Run the init function of each source file */ | |
666 | ||
667 | initialize_cmd_lists (); /* This needs to be done first */ | |
668 | initialize_all_files (); | |
669 | initialize_main (); /* But that omits this file! Do it now */ | |
670 | init_signals (); | |
671 | ||
672 | if (!quiet) | |
673 | { | |
81066208 JG |
674 | /* Print all the junk at the top, with trailing "..." if we are about |
675 | to read a symbol file (possibly slowly). */ | |
676 | print_gnu_advertisement (); | |
677 | print_gdb_version (); | |
678 | if (symarg) | |
679 | printf_filtered (".."); | |
bd099407 | 680 | wrap_here(""); |
81066208 | 681 | fflush (stdout); /* Force to screen during slow operations */ |
bd5635a1 RP |
682 | } |
683 | ||
81066208 | 684 | error_pre_print = "\n\n"; |
51b57ded FF |
685 | /* We may get more than one warning, don't double space all of them... */ |
686 | warning_pre_print = "\nwarning: "; | |
81066208 | 687 | |
538280d8 FF |
688 | /* We need a default language for parsing expressions, so simple things like |
689 | "set width 0" won't fail if no language is explicitly set in a config file | |
690 | or implicitly set by reading an executable during startup. */ | |
691 | set_language (language_c); | |
692 | ||
3a16d640 JG |
693 | /* Read and execute $HOME/.gdbinit file, if it exists. This is done |
694 | *before* all the command line arguments are processed; it sets | |
695 | global parameters, which are independent of what file you are | |
696 | debugging or what directory you are in. */ | |
697 | homedir = getenv ("HOME"); | |
698 | if (homedir) | |
699 | { | |
700 | homeinit = (char *) alloca (strlen (getenv ("HOME")) + | |
701 | strlen (gdbinit) + 10); | |
702 | strcpy (homeinit, getenv ("HOME")); | |
703 | strcat (homeinit, "/"); | |
704 | strcat (homeinit, gdbinit); | |
705 | if (!inhibit_gdbinit && access (homeinit, R_OK) == 0) | |
706 | { | |
3a16d640 JG |
707 | if (!setjmp (to_top_level)) |
708 | source_command (homeinit, 0); | |
709 | } | |
710 | do_cleanups (ALL_CLEANUPS); | |
711 | ||
712 | /* Do stats; no need to do them elsewhere since we'll only | |
713 | need them if homedir is set. Make sure that they are | |
714 | zero in case one of them fails (this guarantees that they | |
715 | won't match if either exists). */ | |
716 | ||
717 | memset (&homebuf, 0, sizeof (struct stat)); | |
718 | memset (&cwdbuf, 0, sizeof (struct stat)); | |
719 | ||
720 | stat (homeinit, &homebuf); | |
721 | stat (gdbinit, &cwdbuf); /* We'll only need this if | |
722 | homedir was set. */ | |
723 | } | |
724 | ||
bd5635a1 RP |
725 | /* Now perform all the actions indicated by the arguments. */ |
726 | if (cdarg != NULL) | |
727 | { | |
728 | if (!setjmp (to_top_level)) | |
729 | { | |
730 | cd_command (cdarg, 0); | |
731 | init_source_path (); | |
732 | } | |
733 | } | |
f266e564 JK |
734 | do_cleanups (ALL_CLEANUPS); |
735 | ||
bd5635a1 RP |
736 | for (i = 0; i < ndir; i++) |
737 | if (!setjmp (to_top_level)) | |
738 | directory_command (dirarg[i], 0); | |
51b57ded | 739 | free ((PTR)dirarg); |
f266e564 JK |
740 | do_cleanups (ALL_CLEANUPS); |
741 | ||
bd5635a1 RP |
742 | if (execarg != NULL |
743 | && symarg != NULL | |
744 | && strcmp (execarg, symarg) == 0) | |
745 | { | |
746 | /* The exec file and the symbol-file are the same. If we can't open | |
747 | it, better only print one error message. */ | |
748 | if (!setjmp (to_top_level)) | |
749 | { | |
750 | exec_file_command (execarg, !batch); | |
81066208 | 751 | symbol_file_command (symarg, 0); |
bd5635a1 RP |
752 | } |
753 | } | |
754 | else | |
755 | { | |
756 | if (execarg != NULL) | |
757 | if (!setjmp (to_top_level)) | |
758 | exec_file_command (execarg, !batch); | |
759 | if (symarg != NULL) | |
760 | if (!setjmp (to_top_level)) | |
81066208 | 761 | symbol_file_command (symarg, 0); |
bd5635a1 | 762 | } |
f266e564 JK |
763 | do_cleanups (ALL_CLEANUPS); |
764 | ||
81066208 JG |
765 | /* After the symbol file has been read, print a newline to get us |
766 | beyond the copyright line... But errors should still set off | |
767 | the error message with a (single) blank line. */ | |
afe4ca15 JG |
768 | if (!quiet) |
769 | printf_filtered ("\n"); | |
81066208 | 770 | error_pre_print = "\n"; |
318bf84f | 771 | warning_pre_print = "\nwarning: "; |
81066208 | 772 | |
bd5635a1 RP |
773 | if (corearg != NULL) |
774 | if (!setjmp (to_top_level)) | |
775 | core_file_command (corearg, !batch); | |
e522fb52 | 776 | else if (isdigit (corearg[0]) && !setjmp (to_top_level)) |
bd5635a1 | 777 | attach_command (corearg, !batch); |
f266e564 | 778 | do_cleanups (ALL_CLEANUPS); |
bd5635a1 RP |
779 | |
780 | if (ttyarg != NULL) | |
781 | if (!setjmp (to_top_level)) | |
782 | tty_command (ttyarg, !batch); | |
f266e564 | 783 | do_cleanups (ALL_CLEANUPS); |
bd5635a1 RP |
784 | |
785 | #ifdef ADDITIONAL_OPTION_HANDLER | |
786 | ADDITIONAL_OPTION_HANDLER; | |
787 | #endif | |
788 | ||
81066208 JG |
789 | /* Error messages should no longer be distinguished with extra output. */ |
790 | error_pre_print = 0; | |
318bf84f | 791 | warning_pre_print = "warning: "; |
81066208 | 792 | |
3a16d640 JG |
793 | /* Read the .gdbinit file in the current directory, *if* it isn't |
794 | the same as the $HOME/.gdbinit file (it should exist, also). */ | |
795 | ||
796 | if (!homedir | |
797 | || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat))) | |
798 | if (!inhibit_gdbinit && access (gdbinit, R_OK) == 0) | |
bd5635a1 | 799 | { |
d75710b0 FF |
800 | if (!setjmp (to_top_level)) |
801 | source_command (gdbinit, 0); | |
bd5635a1 | 802 | } |
d75710b0 FF |
803 | do_cleanups (ALL_CLEANUPS); |
804 | ||
805 | for (i = 0; i < ncmd; i++) | |
806 | { | |
d75710b0 FF |
807 | if (!setjmp (to_top_level)) |
808 | { | |
809 | if (cmdarg[i][0] == '-' && cmdarg[i][1] == '\0') | |
810 | read_command_file (stdin); | |
811 | else | |
812 | source_command (cmdarg[i], !batch); | |
813 | do_cleanups (ALL_CLEANUPS); | |
814 | } | |
815 | } | |
51b57ded | 816 | free ((PTR)cmdarg); |
bd5635a1 | 817 | |
8b3c897a SG |
818 | /* Read in the old history after all the command files have been read. */ |
819 | initialize_history(); | |
820 | ||
bd5635a1 RP |
821 | if (batch) |
822 | { | |
823 | /* We have hit the end of the batch file. */ | |
824 | exit (0); | |
825 | } | |
826 | ||
827 | /* Do any host- or target-specific hacks. This is used for i960 targets | |
828 | to force the user to set a nindy target and spec its parameters. */ | |
829 | ||
830 | #ifdef BEFORE_MAIN_LOOP_HOOK | |
831 | BEFORE_MAIN_LOOP_HOOK; | |
832 | #endif | |
833 | ||
834 | /* The command loop. */ | |
835 | ||
836 | while (1) | |
837 | { | |
838 | if (!setjmp (to_top_level)) | |
839 | { | |
f266e564 | 840 | do_cleanups (ALL_CLEANUPS); /* Do complete cleanup */ |
bd5635a1 RP |
841 | command_loop (); |
842 | quit_command ((char *)0, instream == stdin); | |
843 | } | |
844 | } | |
845 | /* No exit -- exit is through quit_command. */ | |
846 | } | |
847 | ||
848 | /* Execute the line P as a command. | |
849 | Pass FROM_TTY as second argument to the defining function. */ | |
850 | ||
851 | void | |
852 | execute_command (p, from_tty) | |
853 | char *p; | |
854 | int from_tty; | |
855 | { | |
856 | register struct cmd_list_element *c; | |
857 | register struct command_line *cmdlines; | |
bd099407 | 858 | register enum language flang; |
ee0613d1 | 859 | static const struct language_defn *saved_language = 0; |
bd099407 | 860 | static int warned = 0; |
bd5635a1 RP |
861 | |
862 | free_all_values (); | |
863 | ||
864 | /* This can happen when command_line_input hits end of file. */ | |
865 | if (p == NULL) | |
866 | return; | |
867 | ||
868 | while (*p == ' ' || *p == '\t') p++; | |
869 | if (*p) | |
870 | { | |
871 | char *arg; | |
872 | ||
873 | c = lookup_cmd (&p, cmdlist, "", 0, 1); | |
874 | /* Pass null arg rather than an empty one. */ | |
875 | arg = *p ? p : 0; | |
876 | if (c->class == class_user) | |
877 | { | |
878 | struct cleanup *old_chain; | |
879 | ||
880 | if (*p) | |
881 | error ("User-defined commands cannot take arguments."); | |
882 | cmdlines = c->user_commands; | |
883 | if (cmdlines == 0) | |
884 | /* Null command */ | |
885 | return; | |
886 | ||
887 | /* Set the instream to 0, indicating execution of a | |
888 | user-defined function. */ | |
889 | old_chain = make_cleanup (source_cleanup, instream); | |
890 | instream = (FILE *) 0; | |
891 | while (cmdlines) | |
892 | { | |
893 | execute_command (cmdlines->line, 0); | |
894 | cmdlines = cmdlines->next; | |
895 | } | |
896 | do_cleanups (old_chain); | |
897 | } | |
898 | else if (c->type == set_cmd || c->type == show_cmd) | |
899 | do_setshow_command (arg, from_tty & caution, c); | |
30875e1c | 900 | else if (c->function.cfunc == NO_FUNCTION) |
bd5635a1 RP |
901 | error ("That is not a command, just a help topic."); |
902 | else | |
30875e1c | 903 | (*c->function.cfunc) (arg, from_tty & caution); |
bd099407 JG |
904 | } |
905 | ||
afe4ca15 JG |
906 | /* Tell the user if the language has changed (except first time). */ |
907 | if (current_language != saved_language) | |
bd099407 JG |
908 | { |
909 | if (language_mode == language_mode_auto) { | |
afe4ca15 | 910 | if (saved_language) |
ee0613d1 | 911 | language_info (1); /* Print what changed. */ |
bd5635a1 | 912 | } |
afe4ca15 | 913 | saved_language = current_language; |
bd099407 JG |
914 | warned = 0; |
915 | } | |
916 | ||
917 | /* Warn the user if the working language does not match the | |
918 | language of the current frame. Only warn the user if we are | |
919 | actually running the program, i.e. there is a stack. */ | |
afe4ca15 JG |
920 | /* FIXME: This should be cacheing the frame and only running when |
921 | the frame changes. */ | |
bd099407 JG |
922 | if (target_has_stack) |
923 | { | |
afe4ca15 JG |
924 | flang = get_frame_language (); |
925 | if (!warned | |
926 | && flang != language_unknown | |
927 | && flang != current_language->la_language) | |
bd099407 JG |
928 | { |
929 | printf_filtered ("%s\n", lang_frame_mismatch_warn); | |
930 | warned = 1; | |
931 | } | |
932 | } | |
bd5635a1 RP |
933 | } |
934 | ||
935 | /* ARGSUSED */ | |
30875e1c | 936 | static void |
f266e564 | 937 | command_loop_marker (foo) |
bd5635a1 RP |
938 | int foo; |
939 | { | |
940 | } | |
941 | ||
942 | /* Read commands from `instream' and execute them | |
943 | until end of file or error reading instream. */ | |
30875e1c | 944 | static void |
bd5635a1 RP |
945 | command_loop () |
946 | { | |
947 | struct cleanup *old_chain; | |
948 | char *command; | |
949 | int stdin_is_tty = ISATTY (stdin); | |
950 | ||
951 | while (!feof (instream)) | |
952 | { | |
953 | if (window_hook && instream == stdin) | |
954 | (*window_hook) (instream, prompt); | |
955 | ||
956 | quit_flag = 0; | |
957 | if (instream == stdin && stdin_is_tty) | |
958 | reinitialize_more_filter (); | |
f266e564 | 959 | old_chain = make_cleanup (command_loop_marker, 0); |
30875e1c | 960 | command = command_line_input (instream == stdin ? prompt : (char *) NULL, |
bd5635a1 RP |
961 | instream == stdin); |
962 | if (command == 0) | |
963 | return; | |
964 | execute_command (command, instream == stdin); | |
965 | /* Do any commands attached to breakpoint we stopped at. */ | |
966 | bpstat_do_actions (&stop_bpstat); | |
967 | do_cleanups (old_chain); | |
968 | } | |
969 | } | |
970 | \f | |
971 | /* Commands call this if they do not want to be repeated by null lines. */ | |
972 | ||
973 | void | |
974 | dont_repeat () | |
975 | { | |
976 | /* If we aren't reading from standard input, we are saving the last | |
977 | thing read from stdin in line and don't want to delete it. Null lines | |
978 | won't repeat here in any case. */ | |
979 | if (instream == stdin) | |
980 | *line = 0; | |
981 | } | |
982 | \f | |
983 | /* Read a line from the stream "instream" without command line editing. | |
984 | ||
985 | It prints PRROMPT once at the start. | |
bdbd5f50 JG |
986 | Action is compatible with "readline", e.g. space for the result is |
987 | malloc'd and should be freed by the caller. | |
bd5635a1 | 988 | |
bdbd5f50 | 989 | A NULL return means end of file. */ |
bd5635a1 | 990 | char * |
bdbd5f50 | 991 | gdb_readline (prrompt) |
bd5635a1 | 992 | char *prrompt; |
bd5635a1 RP |
993 | { |
994 | int c; | |
995 | char *result; | |
996 | int input_index = 0; | |
997 | int result_size = 80; | |
998 | ||
999 | if (prrompt) | |
1000 | { | |
c35475f9 JG |
1001 | /* Don't use a _filtered function here. It causes the assumed |
1002 | character position to be off, since the newline we read from | |
1003 | the user is not accounted for. */ | |
1004 | fputs (prrompt, stdout); | |
bd5635a1 RP |
1005 | fflush (stdout); |
1006 | } | |
1007 | ||
bdbd5f50 | 1008 | result = (char *) xmalloc (result_size); |
bd5635a1 RP |
1009 | |
1010 | while (1) | |
1011 | { | |
1012 | /* Read from stdin if we are executing a user defined command. | |
1013 | This is the right thing for prompt_for_continue, at least. */ | |
1014 | c = fgetc (instream ? instream : stdin); | |
bdbd5f50 JG |
1015 | |
1016 | if (c == EOF) | |
bd5635a1 | 1017 | { |
bdbd5f50 JG |
1018 | free (result); |
1019 | return NULL; | |
bd5635a1 | 1020 | } |
bd5635a1 | 1021 | |
bdbd5f50 JG |
1022 | if (c == '\n') |
1023 | break; | |
bd5635a1 | 1024 | |
bdbd5f50 JG |
1025 | result[input_index++] = c; |
1026 | while (input_index >= result_size) | |
1027 | { | |
1028 | result_size *= 2; | |
1029 | result = (char *) xrealloc (result, result_size); | |
1030 | } | |
bd5635a1 | 1031 | } |
bdbd5f50 JG |
1032 | |
1033 | result[input_index++] = '\0'; | |
1034 | return result; | |
bd5635a1 RP |
1035 | } |
1036 | ||
bd5635a1 RP |
1037 | /* Variables which control command line editing and history |
1038 | substitution. These variables are given default values at the end | |
1039 | of this file. */ | |
1040 | static int command_editing_p; | |
1041 | static int history_expansion_p; | |
1042 | static int write_history_p; | |
1043 | static int history_size; | |
1044 | static char *history_filename; | |
1045 | ||
1046 | /* Variables which are necessary for fancy command line editing. */ | |
1047 | char *gdb_completer_word_break_characters = | |
a8e033f2 SG |
1048 | " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-"; |
1049 | ||
1050 | /* When completing on command names, we remove '-' from the list of | |
1051 | word break characters, since we use it in command names. If the | |
1052 | readline library sees one in any of the current completion strings, | |
1053 | it thinks that the string needs to be quoted and automatically supplies | |
1054 | a leading quote. */ | |
1055 | char *gdb_completer_command_word_break_characters = | |
1056 | " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,"; | |
1057 | ||
51b57ded FF |
1058 | /* Characters that can be used to quote completion strings. Note that we |
1059 | can't include '"' because the gdb C parser treats such quoted sequences | |
1060 | as strings. */ | |
1061 | char *gdb_completer_quote_characters = | |
1062 | "'"; | |
bd5635a1 RP |
1063 | |
1064 | /* Functions that are used as part of the fancy command line editing. */ | |
1065 | ||
1066 | /* This can be used for functions which don't want to complete on symbols | |
1067 | but don't want to complete on anything else either. */ | |
1068 | /* ARGSUSED */ | |
1069 | char ** | |
1070 | noop_completer (text) | |
1071 | char *text; | |
1072 | { | |
1073 | return NULL; | |
1074 | } | |
1075 | ||
51b57ded FF |
1076 | /* Generate symbol names one by one for the completer. Each time we are |
1077 | called return another potential completion to the caller. | |
1078 | ||
1079 | TEXT is what we expect the symbol to start with. | |
1080 | ||
1081 | MATCHES is the number of matches that have currently been collected from | |
1082 | calling this completion function. When zero, then we need to initialize, | |
1083 | otherwise the initialization has already taken place and we can just | |
1084 | return the next potential completion string. | |
30875e1c | 1085 | |
51b57ded FF |
1086 | Returns NULL if there are no more completions, else a pointer to a string |
1087 | which is a possible completion. | |
1088 | ||
1089 | RL_LINE_BUFFER is available to be looked at; it contains the entire text | |
1090 | of the line. RL_POINT is the offset in that line of the cursor. You | |
1091 | should pretend that the line ends at RL_POINT. */ | |
1092 | ||
30875e1c | 1093 | static char * |
51b57ded | 1094 | symbol_completion_function (text, matches) |
bd5635a1 | 1095 | char *text; |
51b57ded | 1096 | int matches; |
bd5635a1 | 1097 | { |
51b57ded FF |
1098 | static char **list = (char **)NULL; /* Cache of completions */ |
1099 | static int index; /* Next cached completion */ | |
1100 | char *output = NULL; | |
bd5635a1 RP |
1101 | char *tmp_command, *p; |
1102 | struct cmd_list_element *c, *result_list; | |
51b57ded FF |
1103 | extern char *rl_line_buffer; |
1104 | extern int rl_point; | |
bd5635a1 | 1105 | |
51b57ded | 1106 | if (matches == 0) |
bd5635a1 | 1107 | { |
51b57ded FF |
1108 | /* The caller is beginning to accumulate a new set of completions, so |
1109 | we need to find all of them now, and cache them for returning one at | |
1110 | a time on future calls. */ | |
1111 | ||
bd5635a1 | 1112 | if (list) |
51b57ded FF |
1113 | { |
1114 | /* Free the storage used by LIST, but not by the strings inside. | |
1115 | This is because rl_complete_internal () frees the strings. */ | |
1116 | free ((PTR)list); | |
1117 | } | |
bd5635a1 RP |
1118 | list = 0; |
1119 | index = 0; | |
1120 | ||
a8e033f2 SG |
1121 | /* Choose the default set of word break characters to break completions. |
1122 | If we later find out that we are doing completions on command strings | |
1123 | (as opposed to strings supplied by the individual command completer | |
1124 | functions, which can be any string) then we will switch to the | |
1125 | special word break set for command strings, which leaves out the | |
1126 | '-' character used in some commands. */ | |
1127 | ||
1128 | rl_completer_word_break_characters = | |
1129 | gdb_completer_word_break_characters; | |
1130 | ||
51b57ded | 1131 | /* Decide whether to complete on a list of gdb commands or on symbols. */ |
bd5635a1 RP |
1132 | tmp_command = (char *) alloca (rl_point + 1); |
1133 | p = tmp_command; | |
1134 | ||
1135 | strncpy (tmp_command, rl_line_buffer, rl_point); | |
1136 | tmp_command[rl_point] = '\0'; | |
1137 | ||
1138 | if (rl_point == 0) | |
1139 | { | |
51b57ded FF |
1140 | /* An empty line we want to consider ambiguous; that is, it |
1141 | could be any command. */ | |
bd5635a1 RP |
1142 | c = (struct cmd_list_element *) -1; |
1143 | result_list = 0; | |
1144 | } | |
1145 | else | |
51b57ded FF |
1146 | { |
1147 | c = lookup_cmd_1 (&p, cmdlist, &result_list, 1); | |
1148 | } | |
bd5635a1 RP |
1149 | |
1150 | /* Move p up to the next interesting thing. */ | |
1151 | while (*p == ' ' || *p == '\t') | |
51b57ded FF |
1152 | { |
1153 | p++; | |
1154 | } | |
bd5635a1 RP |
1155 | |
1156 | if (!c) | |
51b57ded FF |
1157 | { |
1158 | /* He's typed something unrecognizable. Sigh. */ | |
1159 | list = NULL; | |
1160 | } | |
bd5635a1 RP |
1161 | else if (c == (struct cmd_list_element *) -1) |
1162 | { | |
1163 | /* If we didn't recognize everything up to the thing that | |
1164 | needs completing, and we don't know what command it is | |
a8e033f2 | 1165 | yet, we are in trouble. */ |
51b57ded FF |
1166 | |
1167 | if (p + strlen(text) != tmp_command + rl_point) | |
1168 | { | |
a8e033f2 SG |
1169 | /* This really should not produce an error. Better would |
1170 | be to pretend to hit RETURN here; this would produce a | |
1171 | response like "Ambiguous command: foo, foobar, etc", | |
1172 | and leave the line available for re-entry with ^P. | |
1173 | Instead, this error blows away the user's typed input | |
1174 | without any way to get it back. */ | |
1175 | error (" Unrecognized command."); | |
bd5635a1 | 1176 | } |
bd5635a1 RP |
1177 | |
1178 | /* He's typed something ambiguous. This is easier. */ | |
1179 | if (result_list) | |
51b57ded FF |
1180 | { |
1181 | list = complete_on_cmdlist (*result_list->prefixlist, text); | |
1182 | } | |
bd5635a1 | 1183 | else |
51b57ded FF |
1184 | { |
1185 | list = complete_on_cmdlist (cmdlist, text); | |
1186 | } | |
a8e033f2 SG |
1187 | rl_completer_word_break_characters = |
1188 | gdb_completer_command_word_break_characters; | |
bd5635a1 RP |
1189 | } |
1190 | else | |
1191 | { | |
1192 | /* If we've gotten this far, gdb has recognized a full | |
1193 | command. There are several possibilities: | |
1194 | ||
1195 | 1) We need to complete on the command. | |
1196 | 2) We need to complete on the possibilities coming after | |
1197 | the command. | |
1198 | 2) We need to complete the text of what comes after the | |
1199 | command. */ | |
1200 | ||
1201 | if (!*p && *text) | |
51b57ded FF |
1202 | { |
1203 | /* Always (might be longer versions of thie command). */ | |
1204 | list = complete_on_cmdlist (result_list, text); | |
a8e033f2 SG |
1205 | rl_completer_word_break_characters = |
1206 | gdb_completer_command_word_break_characters; | |
51b57ded | 1207 | } |
bd5635a1 RP |
1208 | else if (!*p && !*text) |
1209 | { | |
1210 | if (c->prefixlist) | |
51b57ded FF |
1211 | { |
1212 | list = complete_on_cmdlist (*c->prefixlist, ""); | |
a8e033f2 SG |
1213 | rl_completer_word_break_characters = |
1214 | gdb_completer_command_word_break_characters; | |
51b57ded | 1215 | } |
bd5635a1 | 1216 | else |
51b57ded FF |
1217 | { |
1218 | list = (*c->completer) (""); | |
1219 | } | |
bd5635a1 RP |
1220 | } |
1221 | else | |
1222 | { | |
1223 | if (c->prefixlist && !c->allow_unknown) | |
1224 | { | |
51b57ded FF |
1225 | /* Something like "info adsfkdj". But error() is not the |
1226 | proper response; just return no completions instead. */ | |
bd5635a1 | 1227 | list = NULL; |
bd5635a1 RP |
1228 | } |
1229 | else | |
51b57ded FF |
1230 | { |
1231 | list = (*c->completer) (text); | |
1232 | } | |
bd5635a1 RP |
1233 | } |
1234 | } | |
1235 | } | |
1236 | ||
51b57ded FF |
1237 | /* If we found a list of potential completions during initialization then |
1238 | dole them out one at a time. The vector of completions is NULL | |
1239 | terminated, so after returning the last one, return NULL (and continue | |
1240 | to do so) each time we are called after that, until a new list is | |
1241 | available. */ | |
bd5635a1 | 1242 | |
51b57ded FF |
1243 | if (list) |
1244 | { | |
1245 | output = list[index]; | |
1246 | if (output) | |
1247 | { | |
1248 | index++; | |
1249 | } | |
1250 | } | |
bd5635a1 RP |
1251 | |
1252 | return (output); | |
1253 | } | |
51b57ded FF |
1254 | |
1255 | /* Skip over a possibly quoted word (as defined by the quote characters | |
1256 | and word break characters the completer uses). Returns pointer to the | |
1257 | location after the "word". */ | |
1258 | ||
1259 | char * | |
1260 | skip_quoted (str) | |
1261 | char *str; | |
1262 | { | |
1263 | char quote_char = '\0'; | |
1264 | char *scan; | |
1265 | ||
1266 | for (scan = str; *scan != '\0'; scan++) | |
1267 | { | |
1268 | if (quote_char != '\0') | |
1269 | { | |
1270 | /* Ignore everything until the matching close quote char */ | |
1271 | if (*scan == quote_char) | |
1272 | { | |
1273 | /* Found matching close quote. */ | |
1274 | scan++; | |
1275 | break; | |
1276 | } | |
1277 | } | |
1278 | else if (strchr (gdb_completer_quote_characters, *scan)) | |
1279 | { | |
1280 | /* Found start of a quoted string. */ | |
1281 | quote_char = *scan; | |
1282 | } | |
1283 | else if (strchr (gdb_completer_word_break_characters, *scan)) | |
1284 | { | |
1285 | break; | |
1286 | } | |
1287 | } | |
1288 | return (scan); | |
1289 | } | |
1290 | ||
bd5635a1 RP |
1291 | \f |
1292 | #ifdef STOP_SIGNAL | |
1293 | static void | |
30875e1c SG |
1294 | stop_sig (signo) |
1295 | int signo; | |
bd5635a1 RP |
1296 | { |
1297 | #if STOP_SIGNAL == SIGTSTP | |
1298 | signal (SIGTSTP, SIG_DFL); | |
1299 | sigsetmask (0); | |
1300 | kill (getpid (), SIGTSTP); | |
1301 | signal (SIGTSTP, stop_sig); | |
1302 | #else | |
1303 | signal (STOP_SIGNAL, stop_sig); | |
1304 | #endif | |
a8e033f2 | 1305 | printf_filtered ("%s", prompt); |
bd5635a1 RP |
1306 | fflush (stdout); |
1307 | ||
1308 | /* Forget about any previous command -- null line now will do nothing. */ | |
1309 | dont_repeat (); | |
1310 | } | |
1311 | #endif /* STOP_SIGNAL */ | |
1312 | ||
bd5635a1 | 1313 | /* Initialize signal handlers. */ |
f266e564 | 1314 | static void |
30875e1c SG |
1315 | do_nothing (signo) |
1316 | int signo; | |
f266e564 JK |
1317 | { |
1318 | } | |
1319 | ||
bd5635a1 RP |
1320 | static void |
1321 | init_signals () | |
1322 | { | |
bd5635a1 RP |
1323 | signal (SIGINT, request_quit); |
1324 | ||
1325 | /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get | |
1326 | passed to the inferior, which we don't want. It would be | |
1327 | possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but | |
bdbd5f50 | 1328 | on BSD4.3 systems using vfork, that can affect the |
bd5635a1 | 1329 | GDB process as well as the inferior (the signal handling tables |
bdbd5f50 | 1330 | might be in memory, shared between the two). Since we establish |
bd5635a1 RP |
1331 | a handler for SIGQUIT, when we call exec it will set the signal |
1332 | to SIG_DFL for us. */ | |
1333 | signal (SIGQUIT, do_nothing); | |
1334 | if (signal (SIGHUP, do_nothing) != SIG_IGN) | |
1335 | signal (SIGHUP, disconnect); | |
1336 | signal (SIGFPE, float_handler); | |
1eeba686 PB |
1337 | |
1338 | #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER) | |
1339 | signal (SIGWINCH, SIGWINCH_HANDLER); | |
1340 | #endif | |
bd5635a1 RP |
1341 | } |
1342 | \f | |
1343 | /* Read one line from the command input stream `instream' | |
1344 | into the local static buffer `linebuffer' (whose current length | |
1345 | is `linelength'). | |
1346 | The buffer is made bigger as necessary. | |
1347 | Returns the address of the start of the line. | |
1348 | ||
1349 | NULL is returned for end of file. | |
1350 | ||
1351 | *If* the instream == stdin & stdin is a terminal, the line read | |
1352 | is copied into the file line saver (global var char *line, | |
1353 | length linesize) so that it can be duplicated. | |
1354 | ||
1355 | This routine either uses fancy command line editing or | |
1356 | simple input as the user has requested. */ | |
1357 | ||
1358 | char * | |
1359 | command_line_input (prrompt, repeat) | |
1360 | char *prrompt; | |
1361 | int repeat; | |
1362 | { | |
1363 | static char *linebuffer = 0; | |
30875e1c | 1364 | static unsigned linelength = 0; |
bd5635a1 RP |
1365 | register char *p; |
1366 | char *p1; | |
1367 | char *rl; | |
1368 | char *local_prompt = prrompt; | |
1369 | register int c; | |
1370 | char *nline; | |
1371 | char got_eof = 0; | |
1372 | ||
1373 | if (linebuffer == 0) | |
1374 | { | |
1375 | linelength = 80; | |
1376 | linebuffer = (char *) xmalloc (linelength); | |
1377 | } | |
1378 | ||
1379 | p = linebuffer; | |
1380 | ||
1381 | /* Control-C quits instantly if typed while in this loop | |
1382 | since it should not wait until the user types a newline. */ | |
1383 | immediate_quit++; | |
1384 | #ifdef STOP_SIGNAL | |
1385 | signal (STOP_SIGNAL, stop_sig); | |
1386 | #endif | |
1387 | ||
1388 | while (1) | |
1389 | { | |
e522fb52 JG |
1390 | /* Reports are that some Sys V's don't flush stdout/err on reads |
1391 | from stdin, when stdin/out are sockets rather than ttys. So we | |
1392 | have to do it ourselves, to make emacs-gdb and xxgdb work. | |
1393 | On other machines, doing this once per input should be a cheap nop. */ | |
1394 | fflush (stdout); | |
1395 | fflush (stderr); | |
1396 | ||
bd5635a1 RP |
1397 | /* Don't use fancy stuff if not talking to stdin. */ |
1398 | if (command_editing_p && instream == stdin | |
1399 | && ISATTY (instream)) | |
1400 | rl = readline (local_prompt); | |
1401 | else | |
bdbd5f50 | 1402 | rl = gdb_readline (local_prompt); |
bd5635a1 RP |
1403 | |
1404 | if (!rl || rl == (char *) EOF) | |
1405 | { | |
1406 | got_eof = 1; | |
1407 | break; | |
1408 | } | |
1409 | if (strlen(rl) + 1 + (p - linebuffer) > linelength) | |
1410 | { | |
1411 | linelength = strlen(rl) + 1 + (p - linebuffer); | |
1412 | nline = (char *) xrealloc (linebuffer, linelength); | |
1413 | p += nline - linebuffer; | |
1414 | linebuffer = nline; | |
1415 | } | |
1416 | p1 = rl; | |
1417 | /* Copy line. Don't copy null at end. (Leaves line alone | |
1418 | if this was just a newline) */ | |
1419 | while (*p1) | |
1420 | *p++ = *p1++; | |
1421 | ||
1422 | free (rl); /* Allocated in readline. */ | |
1423 | ||
1424 | if (p == linebuffer || *(p - 1) != '\\') | |
1425 | break; | |
1426 | ||
1427 | p--; /* Put on top of '\'. */ | |
1428 | local_prompt = (char *) 0; | |
1429 | } | |
1430 | ||
1431 | #ifdef STOP_SIGNAL | |
1432 | signal (SIGTSTP, SIG_DFL); | |
1433 | #endif | |
1434 | immediate_quit--; | |
1435 | ||
1436 | if (got_eof) | |
1437 | return NULL; | |
1438 | ||
1439 | /* Do history expansion if that is wished. */ | |
1440 | if (history_expansion_p && instream == stdin | |
1441 | && ISATTY (instream)) | |
1442 | { | |
1443 | char *history_value; | |
1444 | int expanded; | |
1445 | ||
1446 | *p = '\0'; /* Insert null now. */ | |
1447 | expanded = history_expand (linebuffer, &history_value); | |
1448 | if (expanded) | |
1449 | { | |
1450 | /* Print the changes. */ | |
a8e033f2 | 1451 | printf_filtered ("%s\n", history_value); |
bd5635a1 RP |
1452 | |
1453 | /* If there was an error, call this function again. */ | |
1454 | if (expanded < 0) | |
1455 | { | |
1456 | free (history_value); | |
1457 | return command_line_input (prrompt, repeat); | |
1458 | } | |
1459 | if (strlen (history_value) > linelength) | |
1460 | { | |
1461 | linelength = strlen (history_value) + 1; | |
1462 | linebuffer = (char *) xrealloc (linebuffer, linelength); | |
1463 | } | |
1464 | strcpy (linebuffer, history_value); | |
1465 | p = linebuffer + strlen(linebuffer); | |
1466 | free (history_value); | |
1467 | } | |
1468 | } | |
1469 | ||
1470 | /* If we just got an empty line, and that is supposed | |
1471 | to repeat the previous command, return the value in the | |
1472 | global buffer. */ | |
1473 | if (repeat) | |
1474 | { | |
1475 | if (p == linebuffer) | |
1476 | return line; | |
1477 | p1 = linebuffer; | |
1478 | while (*p1 == ' ' || *p1 == '\t') | |
1479 | p1++; | |
1480 | if (!*p1) | |
1481 | return line; | |
1482 | } | |
1483 | ||
1484 | *p = 0; | |
1485 | ||
1486 | /* Add line to history if appropriate. */ | |
1487 | if (instream == stdin | |
1488 | && ISATTY (stdin) && *linebuffer) | |
1489 | add_history (linebuffer); | |
1490 | ||
1491 | /* Note: lines consisting soley of comments are added to the command | |
1492 | history. This is useful when you type a command, and then | |
1493 | realize you don't want to execute it quite yet. You can comment | |
1494 | out the command and then later fetch it from the value history | |
1495 | and remove the '#'. The kill ring is probably better, but some | |
1496 | people are in the habit of commenting things out. */ | |
1497 | p1 = linebuffer; | |
1498 | while ((c = *p1++) != '\0') | |
1499 | { | |
1500 | if (c == '"') | |
1501 | while ((c = *p1++) != '"') | |
1502 | { | |
1503 | /* Make sure an escaped '"' doesn't make us think the string | |
1504 | is ended. */ | |
1505 | if (c == '\\') | |
1506 | parse_escape (&p1); | |
1507 | if (c == '\0') | |
1508 | break; | |
1509 | } | |
1510 | else if (c == '\'') | |
1511 | while ((c = *p1++) != '\'') | |
1512 | { | |
1513 | /* Make sure an escaped '\'' doesn't make us think the string | |
1514 | is ended. */ | |
1515 | if (c == '\\') | |
1516 | parse_escape (&p1); | |
1517 | if (c == '\0') | |
1518 | break; | |
1519 | } | |
1520 | else if (c == '#') | |
1521 | { | |
1522 | /* Found a comment. */ | |
1523 | p1[-1] = '\0'; | |
1524 | break; | |
1525 | } | |
1526 | } | |
1527 | ||
1528 | /* Save into global buffer if appropriate. */ | |
1529 | if (repeat) | |
1530 | { | |
1531 | if (linelength > linesize) | |
1532 | { | |
1533 | line = xrealloc (line, linelength); | |
1534 | linesize = linelength; | |
1535 | } | |
1536 | strcpy (line, linebuffer); | |
1537 | return line; | |
1538 | } | |
1539 | ||
1540 | return linebuffer; | |
1541 | } | |
1542 | \f | |
1543 | /* Read lines from the input stream | |
1544 | and accumulate them in a chain of struct command_line's | |
1545 | which is then returned. */ | |
1546 | ||
1547 | struct command_line * | |
1548 | read_command_lines () | |
1549 | { | |
1550 | struct command_line *first = 0; | |
1551 | register struct command_line *next, *tail = 0; | |
1552 | register char *p, *p1; | |
1553 | struct cleanup *old_chain = 0; | |
1554 | ||
1555 | while (1) | |
1556 | { | |
1557 | dont_repeat (); | |
30875e1c | 1558 | p = command_line_input ((char *) NULL, instream == stdin); |
bd5635a1 RP |
1559 | if (p == NULL) |
1560 | /* Treat end of file like "end". */ | |
1561 | break; | |
1562 | ||
1563 | /* Remove leading and trailing blanks. */ | |
1564 | while (*p == ' ' || *p == '\t') p++; | |
1565 | p1 = p + strlen (p); | |
1566 | while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t')) p1--; | |
1567 | ||
1568 | /* Is this "end"? */ | |
1569 | if (p1 - p == 3 && !strncmp (p, "end", 3)) | |
1570 | break; | |
1571 | ||
1572 | /* No => add this line to the chain of command lines. */ | |
1573 | next = (struct command_line *) xmalloc (sizeof (struct command_line)); | |
1574 | next->line = savestring (p, p1 - p); | |
1575 | next->next = 0; | |
1576 | if (tail) | |
1577 | { | |
1578 | tail->next = next; | |
1579 | } | |
1580 | else | |
1581 | { | |
1582 | /* We just read the first line. | |
1583 | From now on, arrange to throw away the lines we have | |
1584 | if we quit or get an error while inside this function. */ | |
1585 | first = next; | |
1586 | old_chain = make_cleanup (free_command_lines, &first); | |
1587 | } | |
1588 | tail = next; | |
1589 | } | |
1590 | ||
1591 | dont_repeat (); | |
1592 | ||
1593 | /* Now we are about to return the chain to our caller, | |
1594 | so freeing it becomes his responsibility. */ | |
1595 | if (first) | |
1596 | discard_cleanups (old_chain); | |
1597 | return first; | |
1598 | } | |
1599 | ||
1600 | /* Free a chain of struct command_line's. */ | |
1601 | ||
1602 | void | |
1603 | free_command_lines (lptr) | |
1604 | struct command_line **lptr; | |
1605 | { | |
1606 | register struct command_line *l = *lptr; | |
1607 | register struct command_line *next; | |
1608 | ||
1609 | while (l) | |
1610 | { | |
1611 | next = l->next; | |
1612 | free (l->line); | |
51b57ded | 1613 | free ((PTR)l); |
bd5635a1 RP |
1614 | l = next; |
1615 | } | |
1616 | } | |
1617 | \f | |
1618 | /* Add an element to the list of info subcommands. */ | |
1619 | ||
1620 | void | |
1621 | add_info (name, fun, doc) | |
1622 | char *name; | |
30875e1c | 1623 | void (*fun) PARAMS ((char *, int)); |
bd5635a1 RP |
1624 | char *doc; |
1625 | { | |
1626 | add_cmd (name, no_class, fun, doc, &infolist); | |
1627 | } | |
1628 | ||
1629 | /* Add an alias to the list of info subcommands. */ | |
1630 | ||
1631 | void | |
1632 | add_info_alias (name, oldname, abbrev_flag) | |
1633 | char *name; | |
1634 | char *oldname; | |
1635 | int abbrev_flag; | |
1636 | { | |
1637 | add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist); | |
1638 | } | |
1639 | ||
1640 | /* The "info" command is defined as a prefix, with allow_unknown = 0. | |
1641 | Therefore, its own definition is called only for "info" with no args. */ | |
1642 | ||
1643 | /* ARGSUSED */ | |
1644 | static void | |
1645 | info_command (arg, from_tty) | |
1646 | char *arg; | |
1647 | int from_tty; | |
1648 | { | |
a8e033f2 | 1649 | printf_filtered ("\"info\" must be followed by the name of an info command.\n"); |
bd5635a1 RP |
1650 | help_list (infolist, "info ", -1, stdout); |
1651 | } | |
1652 | ||
1653 | /* The "show" command with no arguments shows all the settings. */ | |
1654 | ||
1655 | /* ARGSUSED */ | |
1656 | static void | |
1657 | show_command (arg, from_tty) | |
1658 | char *arg; | |
1659 | int from_tty; | |
1660 | { | |
1661 | cmd_show_list (showlist, from_tty, ""); | |
1662 | } | |
1663 | \f | |
1664 | /* Add an element to the list of commands. */ | |
1665 | ||
1666 | void | |
1667 | add_com (name, class, fun, doc) | |
1668 | char *name; | |
1669 | enum command_class class; | |
30875e1c | 1670 | void (*fun) PARAMS ((char *, int)); |
bd5635a1 RP |
1671 | char *doc; |
1672 | { | |
1673 | add_cmd (name, class, fun, doc, &cmdlist); | |
1674 | } | |
1675 | ||
1676 | /* Add an alias or abbreviation command to the list of commands. */ | |
1677 | ||
1678 | void | |
1679 | add_com_alias (name, oldname, class, abbrev_flag) | |
1680 | char *name; | |
1681 | char *oldname; | |
1682 | enum command_class class; | |
1683 | int abbrev_flag; | |
1684 | { | |
1685 | add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist); | |
1686 | } | |
1687 | ||
1688 | void | |
1689 | error_no_arg (why) | |
1690 | char *why; | |
1691 | { | |
1692 | error ("Argument required (%s).", why); | |
1693 | } | |
1694 | ||
e1ce8aa5 | 1695 | /* ARGSUSED */ |
bd5635a1 RP |
1696 | static void |
1697 | help_command (command, from_tty) | |
1698 | char *command; | |
1699 | int from_tty; /* Ignored */ | |
1700 | { | |
1701 | help_cmd (command, stdout); | |
1702 | } | |
1703 | \f | |
1704 | static void | |
1705 | validate_comname (comname) | |
1706 | char *comname; | |
1707 | { | |
1708 | register char *p; | |
1709 | ||
1710 | if (comname == 0) | |
1711 | error_no_arg ("name of command to define"); | |
1712 | ||
1713 | p = comname; | |
1714 | while (*p) | |
1715 | { | |
c2e4669f | 1716 | if (!isalnum(*p) && *p != '-') |
bd5635a1 RP |
1717 | error ("Junk in argument list: \"%s\"", p); |
1718 | p++; | |
1719 | } | |
1720 | } | |
1721 | ||
51b57ded FF |
1722 | /* This is just a placeholder in the command data structures. */ |
1723 | static void | |
1724 | user_defined_command (ignore, from_tty) | |
1725 | char *ignore; | |
1726 | int from_tty; | |
1727 | { | |
1728 | } | |
1729 | ||
bd5635a1 RP |
1730 | static void |
1731 | define_command (comname, from_tty) | |
1732 | char *comname; | |
1733 | int from_tty; | |
1734 | { | |
1735 | register struct command_line *cmds; | |
1736 | register struct cmd_list_element *c, *newc; | |
1737 | char *tem = comname; | |
bd5635a1 RP |
1738 | |
1739 | validate_comname (comname); | |
1740 | ||
afe4ca15 | 1741 | /* Look it up, and verify that we got an exact match. */ |
bd5635a1 | 1742 | c = lookup_cmd (&tem, cmdlist, "", -1, 1); |
afe4ca15 JG |
1743 | if (c && 0 != strcmp (comname, c->name)) |
1744 | c = 0; | |
1745 | ||
bd5635a1 RP |
1746 | if (c) |
1747 | { | |
1748 | if (c->class == class_user || c->class == class_alias) | |
1749 | tem = "Redefine command \"%s\"? "; | |
1750 | else | |
1751 | tem = "Really redefine built-in command \"%s\"? "; | |
c2e4669f JG |
1752 | if (!query (tem, c->name)) |
1753 | error ("Command \"%s\" not redefined.", c->name); | |
bd5635a1 RP |
1754 | } |
1755 | ||
c2e4669f JG |
1756 | comname = savestring (comname, strlen (comname)); |
1757 | ||
1758 | /* If the rest of the commands will be case insensetive, this one | |
1759 | should behave in the same manner. */ | |
1760 | for (tem = comname; *tem; tem++) | |
1761 | if (isupper(*tem)) *tem = tolower(*tem); | |
1762 | ||
bd5635a1 RP |
1763 | if (from_tty) |
1764 | { | |
a8e033f2 | 1765 | printf_filtered ("Type commands for definition of \"%s\".\n\ |
bd5635a1 RP |
1766 | End with a line saying just \"end\".\n", comname); |
1767 | fflush (stdout); | |
1768 | } | |
bd5635a1 RP |
1769 | |
1770 | cmds = read_command_lines (); | |
1771 | ||
1772 | if (c && c->class == class_user) | |
1773 | free_command_lines (&c->user_commands); | |
1774 | ||
51b57ded | 1775 | newc = add_cmd (comname, class_user, user_defined_command, |
bd5635a1 RP |
1776 | (c && c->class == class_user) |
1777 | ? c->doc : savestring ("User-defined.", 13), &cmdlist); | |
1778 | newc->user_commands = cmds; | |
1779 | } | |
1780 | ||
1781 | static void | |
1782 | document_command (comname, from_tty) | |
1783 | char *comname; | |
1784 | int from_tty; | |
1785 | { | |
1786 | struct command_line *doclines; | |
1787 | register struct cmd_list_element *c; | |
1788 | char *tem = comname; | |
1789 | ||
1790 | validate_comname (comname); | |
1791 | ||
1792 | c = lookup_cmd (&tem, cmdlist, "", 0, 1); | |
1793 | ||
1794 | if (c->class != class_user) | |
1795 | error ("Command \"%s\" is built-in.", comname); | |
1796 | ||
1797 | if (from_tty) | |
a8e033f2 | 1798 | printf_filtered ("Type documentation for \"%s\".\n\ |
bd5635a1 RP |
1799 | End with a line saying just \"end\".\n", comname); |
1800 | ||
1801 | doclines = read_command_lines (); | |
1802 | ||
1803 | if (c->doc) free (c->doc); | |
1804 | ||
1805 | { | |
1806 | register struct command_line *cl1; | |
1807 | register int len = 0; | |
1808 | ||
1809 | for (cl1 = doclines; cl1; cl1 = cl1->next) | |
1810 | len += strlen (cl1->line) + 1; | |
1811 | ||
1812 | c->doc = (char *) xmalloc (len + 1); | |
1813 | *c->doc = 0; | |
1814 | ||
1815 | for (cl1 = doclines; cl1; cl1 = cl1->next) | |
1816 | { | |
1817 | strcat (c->doc, cl1->line); | |
1818 | if (cl1->next) | |
1819 | strcat (c->doc, "\n"); | |
1820 | } | |
1821 | } | |
1822 | ||
1823 | free_command_lines (&doclines); | |
1824 | } | |
1825 | \f | |
1826 | static void | |
81066208 | 1827 | print_gnu_advertisement() |
bd5635a1 | 1828 | { |
a8e033f2 | 1829 | printf_filtered ("\ |
bd5635a1 | 1830 | GDB is free software and you are welcome to distribute copies of it\n\ |
afe4ca15 JG |
1831 | under certain conditions; type \"show copying\" to see the conditions.\n\ |
1832 | There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\ | |
81066208 JG |
1833 | "); |
1834 | } | |
1835 | ||
1836 | static void | |
1837 | print_gdb_version () | |
1838 | { | |
1839 | printf_filtered ("\ | |
ee0613d1 | 1840 | GDB %s, Copyright 1992 Free Software Foundation, Inc.", |
81066208 | 1841 | version); |
bd5635a1 RP |
1842 | } |
1843 | ||
e1ce8aa5 | 1844 | /* ARGSUSED */ |
bd5635a1 | 1845 | static void |
f266e564 | 1846 | show_version (args, from_tty) |
bd5635a1 RP |
1847 | char *args; |
1848 | int from_tty; | |
1849 | { | |
1850 | immediate_quit++; | |
81066208 JG |
1851 | print_gnu_advertisement (); |
1852 | print_gdb_version (); | |
1853 | printf_filtered ("\n"); | |
bd5635a1 RP |
1854 | immediate_quit--; |
1855 | } | |
1856 | \f | |
1857 | /* xgdb calls this to reprint the usual GDB prompt. */ | |
1858 | ||
1859 | void | |
1860 | print_prompt () | |
1861 | { | |
a8e033f2 | 1862 | printf_filtered ("%s", prompt); |
bd5635a1 RP |
1863 | fflush (stdout); |
1864 | } | |
1865 | \f | |
1866 | static void | |
1867 | quit_command (args, from_tty) | |
1868 | char *args; | |
1869 | int from_tty; | |
1870 | { | |
f266e564 | 1871 | if (inferior_pid != 0 && target_has_execution) |
bd5635a1 RP |
1872 | { |
1873 | if (query ("The program is running. Quit anyway? ")) | |
1874 | { | |
ee0613d1 | 1875 | target_kill (); |
bd5635a1 RP |
1876 | } |
1877 | else | |
1878 | error ("Not confirmed."); | |
1879 | } | |
1880 | /* Save the history information if it is appropriate to do so. */ | |
1881 | if (write_history_p && history_filename) | |
1882 | write_history (history_filename); | |
1883 | exit (0); | |
1884 | } | |
1885 | ||
ee0613d1 JG |
1886 | /* Returns whether GDB is running on a terminal and whether the user |
1887 | desires that questions be asked of them on that terminal. */ | |
1888 | ||
bd5635a1 RP |
1889 | int |
1890 | input_from_terminal_p () | |
1891 | { | |
ee0613d1 | 1892 | return gdb_has_a_terminal && (instream == stdin) & caution; |
bd5635a1 RP |
1893 | } |
1894 | \f | |
e1ce8aa5 | 1895 | /* ARGSUSED */ |
bd5635a1 RP |
1896 | static void |
1897 | pwd_command (args, from_tty) | |
1898 | char *args; | |
1899 | int from_tty; | |
1900 | { | |
1901 | if (args) error ("The \"pwd\" command does not take an argument: %s", args); | |
f7402c04 | 1902 | getcwd (dirbuf, sizeof (dirbuf)); |
bd5635a1 RP |
1903 | |
1904 | if (strcmp (dirbuf, current_directory)) | |
a8e033f2 | 1905 | printf_filtered ("Working directory %s\n (canonically %s).\n", |
bd5635a1 RP |
1906 | current_directory, dirbuf); |
1907 | else | |
a8e033f2 | 1908 | printf_filtered ("Working directory %s.\n", current_directory); |
bd5635a1 RP |
1909 | } |
1910 | ||
1911 | static void | |
1912 | cd_command (dir, from_tty) | |
1913 | char *dir; | |
1914 | int from_tty; | |
1915 | { | |
1916 | int len; | |
1917 | int change; | |
1918 | ||
9107291d JK |
1919 | /* If the new directory is absolute, repeat is a no-op; if relative, |
1920 | repeat might be useful but is more likely to be a mistake. */ | |
1921 | dont_repeat (); | |
1922 | ||
bd5635a1 RP |
1923 | if (dir == 0) |
1924 | error_no_arg ("new working directory"); | |
1925 | ||
1926 | dir = tilde_expand (dir); | |
1927 | make_cleanup (free, dir); | |
1928 | ||
ee0613d1 JG |
1929 | if (chdir (dir) < 0) |
1930 | perror_with_name (dir); | |
1931 | ||
bd5635a1 RP |
1932 | len = strlen (dir); |
1933 | dir = savestring (dir, len - (len > 1 && dir[len-1] == '/')); | |
1934 | if (dir[0] == '/') | |
1935 | current_directory = dir; | |
1936 | else | |
1937 | { | |
7d9884b9 | 1938 | current_directory = concat (current_directory, "/", dir, NULL); |
bd5635a1 RP |
1939 | free (dir); |
1940 | } | |
1941 | ||
1942 | /* Now simplify any occurrences of `.' and `..' in the pathname. */ | |
1943 | ||
1944 | change = 1; | |
1945 | while (change) | |
1946 | { | |
1947 | char *p; | |
1948 | change = 0; | |
1949 | ||
1950 | for (p = current_directory; *p;) | |
1951 | { | |
1952 | if (!strncmp (p, "/./", 2) | |
1953 | && (p[2] == 0 || p[2] == '/')) | |
1954 | strcpy (p, p + 2); | |
1955 | else if (!strncmp (p, "/..", 3) | |
1956 | && (p[3] == 0 || p[3] == '/') | |
1957 | && p != current_directory) | |
1958 | { | |
1959 | char *q = p; | |
1960 | while (q != current_directory && q[-1] != '/') q--; | |
1961 | if (q != current_directory) | |
1962 | { | |
1963 | strcpy (q-1, p+3); | |
1964 | p = q-1; | |
1965 | } | |
1966 | } | |
1967 | else p++; | |
1968 | } | |
1969 | } | |
1970 | ||
bd5635a1 RP |
1971 | forget_cached_source_info (); |
1972 | ||
1973 | if (from_tty) | |
1974 | pwd_command ((char *) 0, 1); | |
1975 | } | |
1976 | \f | |
e1ce8aa5 | 1977 | /* ARGSUSED */ |
bd5635a1 RP |
1978 | static void |
1979 | source_command (args, from_tty) | |
1980 | char *args; | |
1981 | int from_tty; | |
1982 | { | |
1983 | FILE *stream; | |
1984 | struct cleanup *cleanups; | |
1985 | char *file = args; | |
1986 | ||
1987 | if (file == 0) | |
1988 | /* Let source without arguments read .gdbinit. */ | |
1989 | file = gdbinit; | |
1990 | ||
1991 | file = tilde_expand (file); | |
1992 | make_cleanup (free, file); | |
1993 | ||
1994 | stream = fopen (file, "r"); | |
1995 | if (stream == 0) | |
1996 | perror_with_name (file); | |
1997 | ||
1998 | cleanups = make_cleanup (fclose, stream); | |
1999 | ||
2000 | read_command_file (stream); | |
2001 | ||
2002 | do_cleanups (cleanups); | |
2003 | } | |
2004 | ||
2005 | /* ARGSUSED */ | |
2006 | static void | |
2007 | echo_command (text, from_tty) | |
2008 | char *text; | |
2009 | int from_tty; | |
2010 | { | |
2011 | char *p = text; | |
2012 | register int c; | |
2013 | ||
2014 | if (text) | |
2015 | while (c = *p++) | |
2016 | { | |
2017 | if (c == '\\') | |
2018 | { | |
2019 | /* \ at end of argument is used after spaces | |
2020 | so they won't be lost. */ | |
2021 | if (*p == 0) | |
2022 | return; | |
2023 | ||
2024 | c = parse_escape (&p); | |
2025 | if (c >= 0) | |
afe4ca15 | 2026 | printf_filtered ("%c", c); |
bd5635a1 RP |
2027 | } |
2028 | else | |
afe4ca15 | 2029 | printf_filtered ("%c", c); |
bd5635a1 | 2030 | } |
afe4ca15 JG |
2031 | |
2032 | /* Force this output to appear now. */ | |
2033 | wrap_here (""); | |
f266e564 | 2034 | fflush (stdout); |
bd5635a1 RP |
2035 | } |
2036 | ||
bd5635a1 RP |
2037 | \f |
2038 | /* Functions to manipulate command line editing control variables. */ | |
2039 | ||
f266e564 | 2040 | /* Number of commands to print in each call to show_commands. */ |
bd5635a1 RP |
2041 | #define Hist_print 10 |
2042 | static void | |
f266e564 | 2043 | show_commands (args, from_tty) |
bd5635a1 RP |
2044 | char *args; |
2045 | int from_tty; | |
2046 | { | |
2047 | /* Index for history commands. Relative to history_base. */ | |
2048 | int offset; | |
2049 | ||
2050 | /* Number of the history entry which we are planning to display next. | |
2051 | Relative to history_base. */ | |
2052 | static int num = 0; | |
2053 | ||
2054 | /* The first command in the history which doesn't exist (i.e. one more | |
2055 | than the number of the last command). Relative to history_base. */ | |
2056 | int hist_len; | |
2057 | ||
30875e1c | 2058 | extern struct _hist_entry *history_get PARAMS ((int)); |
bd5635a1 RP |
2059 | extern int history_base; |
2060 | ||
bd5635a1 RP |
2061 | /* Print out some of the commands from the command history. */ |
2062 | /* First determine the length of the history list. */ | |
2063 | hist_len = history_size; | |
2064 | for (offset = 0; offset < history_size; offset++) | |
2065 | { | |
2066 | if (!history_get (history_base + offset)) | |
2067 | { | |
2068 | hist_len = offset; | |
2069 | break; | |
2070 | } | |
2071 | } | |
2072 | ||
2073 | if (args) | |
2074 | { | |
2075 | if (args[0] == '+' && args[1] == '\0') | |
2076 | /* "info editing +" should print from the stored position. */ | |
2077 | ; | |
2078 | else | |
2079 | /* "info editing <exp>" should print around command number <exp>. */ | |
2080 | num = (parse_and_eval_address (args) - history_base) - Hist_print / 2; | |
2081 | } | |
ee0613d1 | 2082 | /* "show commands" means print the last Hist_print commands. */ |
bd5635a1 RP |
2083 | else |
2084 | { | |
2085 | num = hist_len - Hist_print; | |
2086 | } | |
2087 | ||
2088 | if (num < 0) | |
2089 | num = 0; | |
2090 | ||
2091 | /* If there are at least Hist_print commands, we want to display the last | |
2092 | Hist_print rather than, say, the last 6. */ | |
2093 | if (hist_len - num < Hist_print) | |
2094 | { | |
2095 | num = hist_len - Hist_print; | |
2096 | if (num < 0) | |
2097 | num = 0; | |
2098 | } | |
2099 | ||
bd5635a1 RP |
2100 | for (offset = num; offset < num + Hist_print && offset < hist_len; offset++) |
2101 | { | |
2102 | printf_filtered ("%5d %s\n", history_base + offset, | |
2103 | (history_get (history_base + offset))->line); | |
2104 | } | |
2105 | ||
2106 | /* The next command we want to display is the next one that we haven't | |
2107 | displayed yet. */ | |
2108 | num += Hist_print; | |
2109 | ||
2110 | /* If the user repeats this command with return, it should do what | |
ee0613d1 JG |
2111 | "show commands +" does. This is unnecessary if arg is null, |
2112 | because "show commands +" is not useful after "show commands". */ | |
bd5635a1 RP |
2113 | if (from_tty && args) |
2114 | { | |
2115 | args[0] = '+'; | |
2116 | args[1] = '\0'; | |
2117 | } | |
2118 | } | |
2119 | ||
2120 | /* Called by do_setshow_command. */ | |
e1ce8aa5 | 2121 | /* ARGSUSED */ |
bd5635a1 RP |
2122 | static void |
2123 | set_history_size_command (args, from_tty, c) | |
2124 | char *args; | |
2125 | int from_tty; | |
2126 | struct cmd_list_element *c; | |
2127 | { | |
2128 | if (history_size == UINT_MAX) | |
2129 | unstifle_history (); | |
c2e4669f | 2130 | else if (history_size >= 0) |
bd5635a1 | 2131 | stifle_history (history_size); |
c2e4669f JG |
2132 | else |
2133 | { | |
2134 | history_size = UINT_MAX; | |
2135 | error ("History size must be non-negative"); | |
2136 | } | |
bd5635a1 RP |
2137 | } |
2138 | ||
e1ce8aa5 | 2139 | /* ARGSUSED */ |
bd5635a1 RP |
2140 | static void |
2141 | set_history (args, from_tty) | |
2142 | char *args; | |
2143 | int from_tty; | |
2144 | { | |
a8e033f2 | 2145 | printf_filtered ("\"set history\" must be followed by the name of a history subcommand.\n"); |
bd5635a1 RP |
2146 | help_list (sethistlist, "set history ", -1, stdout); |
2147 | } | |
2148 | ||
e1ce8aa5 | 2149 | /* ARGSUSED */ |
bd5635a1 RP |
2150 | static void |
2151 | show_history (args, from_tty) | |
2152 | char *args; | |
2153 | int from_tty; | |
2154 | { | |
f266e564 | 2155 | cmd_show_list (showhistlist, from_tty, ""); |
bd5635a1 RP |
2156 | } |
2157 | ||
2158 | int info_verbose = 0; /* Default verbose msgs off */ | |
2159 | ||
2160 | /* Called by do_setshow_command. An elaborate joke. */ | |
e1ce8aa5 | 2161 | /* ARGSUSED */ |
bd5635a1 RP |
2162 | static void |
2163 | set_verbose (args, from_tty, c) | |
2164 | char *args; | |
2165 | int from_tty; | |
2166 | struct cmd_list_element *c; | |
2167 | { | |
2168 | char *cmdname = "verbose"; | |
2169 | struct cmd_list_element *showcmd; | |
2170 | ||
2171 | showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1); | |
2172 | ||
2173 | if (info_verbose) | |
2174 | { | |
2175 | c->doc = "Set verbose printing of informational messages."; | |
2176 | showcmd->doc = "Show verbose printing of informational messages."; | |
2177 | } | |
2178 | else | |
2179 | { | |
2180 | c->doc = "Set verbosity."; | |
2181 | showcmd->doc = "Show verbosity."; | |
2182 | } | |
2183 | } | |
2184 | ||
2185 | static void | |
30875e1c SG |
2186 | float_handler (signo) |
2187 | int signo; | |
bd5635a1 RP |
2188 | { |
2189 | /* This message is based on ANSI C, section 4.7. Note that integer | |
2190 | divide by zero causes this, so "float" is a misnomer. */ | |
2191 | error ("Erroneous arithmetic operation."); | |
2192 | } | |
2193 | ||
2194 | /* Return whether we are running a batch file or from terminal. */ | |
2195 | int | |
2196 | batch_mode () | |
2197 | { | |
2198 | return !(instream == stdin && ISATTY (stdin)); | |
2199 | } | |
2200 | ||
2201 | \f | |
2202 | static void | |
2203 | initialize_cmd_lists () | |
2204 | { | |
0239d9b3 FF |
2205 | cmdlist = NULL; |
2206 | infolist = NULL; | |
2207 | enablelist = NULL; | |
2208 | disablelist = NULL; | |
2209 | deletelist = NULL; | |
2210 | enablebreaklist = NULL; | |
2211 | setlist = NULL; | |
2212 | unsetlist = NULL; | |
bd5635a1 | 2213 | showlist = NULL; |
0239d9b3 | 2214 | sethistlist = NULL; |
bd5635a1 | 2215 | showhistlist = NULL; |
0239d9b3 FF |
2216 | unsethistlist = NULL; |
2217 | #if MAINTENANCE_CMDS | |
2218 | maintenancelist = NULL; | |
2219 | maintenanceinfolist = NULL; | |
a8e033f2 | 2220 | maintenanceprintlist = NULL; |
0239d9b3 FF |
2221 | #endif |
2222 | setprintlist = NULL; | |
2223 | showprintlist = NULL; | |
2224 | setchecklist = NULL; | |
2225 | showchecklist = NULL; | |
bd5635a1 RP |
2226 | } |
2227 | ||
8b3c897a SG |
2228 | /* Init the history buffer. Note that we are called after the init file(s) |
2229 | * have been read so that the user can change the history file via his | |
2230 | * .gdbinit file (for instance). The GDBHISTFILE environment variable | |
2231 | * overrides all of this. | |
2232 | */ | |
2233 | ||
bd5635a1 | 2234 | static void |
8b3c897a | 2235 | initialize_history() |
bd5635a1 | 2236 | { |
bd5635a1 | 2237 | char *tmpenv; |
bd5635a1 | 2238 | |
318bf84f FF |
2239 | tmpenv = getenv ("HISTSIZE"); |
2240 | if (tmpenv) | |
bd5635a1 | 2241 | history_size = atoi (tmpenv); |
8b3c897a | 2242 | else if (!history_size) |
bd5635a1 RP |
2243 | history_size = 256; |
2244 | ||
2245 | stifle_history (history_size); | |
2246 | ||
318bf84f FF |
2247 | tmpenv = getenv ("GDBHISTFILE"); |
2248 | if (tmpenv) | |
bd5635a1 | 2249 | history_filename = savestring (tmpenv, strlen(tmpenv)); |
8b3c897a | 2250 | else if (!history_filename) { |
bd5635a1 RP |
2251 | /* We include the current directory so that if the user changes |
2252 | directories the file written will be the same as the one | |
2253 | that was read. */ | |
7d9884b9 | 2254 | history_filename = concat (current_directory, "/.gdb_history", NULL); |
8b3c897a | 2255 | } |
bd5635a1 | 2256 | read_history (history_filename); |
8b3c897a | 2257 | } |
bd5635a1 | 2258 | |
8b3c897a SG |
2259 | static void |
2260 | initialize_main () | |
2261 | { | |
2262 | struct cmd_list_element *c; | |
2263 | ||
2264 | #ifdef DEFAULT_PROMPT | |
2265 | prompt = savestring (DEFAULT_PROMPT, strlen(DEFAULT_PROMPT)); | |
2266 | #else | |
2267 | prompt = savestring ("(gdb) ", 6); | |
2268 | #endif | |
2269 | ||
2270 | /* Set the important stuff up for command editing. */ | |
2271 | command_editing_p = 1; | |
2272 | history_expansion_p = 0; | |
2273 | write_history_p = 0; | |
2274 | ||
bd5635a1 RP |
2275 | /* Setup important stuff for command line editing. */ |
2276 | rl_completion_entry_function = (int (*)()) symbol_completion_function; | |
2277 | rl_completer_word_break_characters = gdb_completer_word_break_characters; | |
51b57ded | 2278 | rl_completer_quote_characters = gdb_completer_quote_characters; |
bd5635a1 RP |
2279 | rl_readline_name = "gdb"; |
2280 | ||
2281 | /* Define the classes of commands. | |
2282 | They will appear in the help list in the reverse of this order. */ | |
2283 | ||
0239d9b3 FF |
2284 | add_cmd ("internals", class_maintenance, NO_FUNCTION, |
2285 | "Maintenance commands.\n\ | |
2286 | Some gdb commands are provided just for use by gdb maintainers.\n\ | |
2287 | These commands are subject to frequent change, and may not be as\n\ | |
2288 | well documented as user commands.", | |
2289 | &cmdlist); | |
bd5635a1 RP |
2290 | add_cmd ("obscure", class_obscure, NO_FUNCTION, "Obscure features.", &cmdlist); |
2291 | add_cmd ("aliases", class_alias, NO_FUNCTION, "Aliases of other commands.", &cmdlist); | |
2292 | add_cmd ("user-defined", class_user, NO_FUNCTION, "User-defined commands.\n\ | |
2293 | The commands in this class are those defined by the user.\n\ | |
2294 | Use the \"define\" command to define a command.", &cmdlist); | |
2295 | add_cmd ("support", class_support, NO_FUNCTION, "Support facilities.", &cmdlist); | |
2296 | add_cmd ("status", class_info, NO_FUNCTION, "Status inquiries.", &cmdlist); | |
2297 | add_cmd ("files", class_files, NO_FUNCTION, "Specifying and examining files.", &cmdlist); | |
2298 | add_cmd ("breakpoints", class_breakpoint, NO_FUNCTION, "Making program stop at certain points.", &cmdlist); | |
2299 | add_cmd ("data", class_vars, NO_FUNCTION, "Examining data.", &cmdlist); | |
2300 | add_cmd ("stack", class_stack, NO_FUNCTION, "Examining the stack.\n\ | |
2301 | The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\ | |
2302 | counting from zero for the innermost (currently executing) frame.\n\n\ | |
2303 | At any time gdb identifies one frame as the \"selected\" frame.\n\ | |
2304 | Variable lookups are done with respect to the selected frame.\n\ | |
2305 | When the program being debugged stops, gdb selects the innermost frame.\n\ | |
2306 | The commands below can be used to select other frames by number or address.", | |
2307 | &cmdlist); | |
2308 | add_cmd ("running", class_run, NO_FUNCTION, "Running the program.", &cmdlist); | |
2309 | ||
2310 | add_com ("pwd", class_files, pwd_command, | |
2311 | "Print working directory. This is used for your program as well."); | |
2312 | add_com ("cd", class_files, cd_command, | |
2313 | "Set working directory to DIR for debugger and program being debugged.\n\ | |
2314 | The change does not take effect for the program being debugged\n\ | |
2315 | until the next time it is started."); | |
2316 | ||
2317 | add_show_from_set | |
2318 | (add_set_cmd ("prompt", class_support, var_string, (char *)&prompt, | |
2319 | "Set gdb's prompt", | |
2320 | &setlist), | |
2321 | &showlist); | |
2322 | ||
2323 | add_com ("echo", class_support, echo_command, | |
2324 | "Print a constant string. Give string as argument.\n\ | |
2325 | C escape sequences may be used in the argument.\n\ | |
2326 | No newline is added at the end of the argument;\n\ | |
2327 | use \"\\n\" if you want a newline to be printed.\n\ | |
2328 | Since leading and trailing whitespace are ignored in command arguments,\n\ | |
2329 | if you want to print some you must use \"\\\" before leading whitespace\n\ | |
2330 | to be printed or after trailing whitespace."); | |
2331 | add_com ("document", class_support, document_command, | |
2332 | "Document a user-defined command.\n\ | |
2333 | Give command name as argument. Give documentation on following lines.\n\ | |
2334 | End with a line of just \"end\"."); | |
2335 | add_com ("define", class_support, define_command, | |
2336 | "Define a new command name. Command name is argument.\n\ | |
2337 | Definition appears on following lines, one command per line.\n\ | |
2338 | End with a line of just \"end\".\n\ | |
2339 | Use the \"document\" command to give documentation for the new command.\n\ | |
2340 | Commands defined in this way do not take arguments."); | |
2341 | ||
2342 | #ifdef __STDC__ | |
2343 | add_com ("source", class_support, source_command, | |
2344 | "Read commands from a file named FILE.\n\ | |
2345 | Note that the file \"" GDBINIT_FILENAME "\" is read automatically in this way\n\ | |
2346 | when gdb is started."); | |
2347 | #else | |
2348 | /* Punt file name, we can't help it easily. */ | |
2349 | add_com ("source", class_support, source_command, | |
2350 | "Read commands from a file named FILE.\n\ | |
2351 | Note that the file \".gdbinit\" is read automatically in this way\n\ | |
2352 | when gdb is started."); | |
2353 | #endif | |
2354 | ||
2355 | add_com ("quit", class_support, quit_command, "Exit gdb."); | |
2356 | add_com ("help", class_support, help_command, "Print list of commands."); | |
2357 | add_com_alias ("q", "quit", class_support, 1); | |
2358 | add_com_alias ("h", "help", class_support, 1); | |
2359 | ||
2360 | ||
2361 | c = add_set_cmd ("verbose", class_support, var_boolean, (char *)&info_verbose, | |
2362 | "Set ", | |
2363 | &setlist), | |
2364 | add_show_from_set (c, &showlist); | |
30875e1c | 2365 | c->function.sfunc = set_verbose; |
bd5635a1 RP |
2366 | set_verbose (NULL, 0, c); |
2367 | ||
bd5635a1 RP |
2368 | add_show_from_set |
2369 | (add_set_cmd ("editing", class_support, var_boolean, (char *)&command_editing_p, | |
ee0613d1 | 2370 | "Set editing of command lines as they are typed.\n\ |
bd5635a1 | 2371 | Use \"on\" to enable to enable the editing, and \"off\" to disable it.\n\ |
ee0613d1 JG |
2372 | Without an argument, command line editing is enabled. To edit, use\n\ |
2373 | EMACS-like or VI-like commands like control-P or ESC.", &setlist), | |
bd5635a1 RP |
2374 | &showlist); |
2375 | ||
2376 | add_prefix_cmd ("history", class_support, set_history, | |
2377 | "Generic command for setting command history parameters.", | |
2378 | &sethistlist, "set history ", 0, &setlist); | |
2379 | add_prefix_cmd ("history", class_support, show_history, | |
2380 | "Generic command for showing command history parameters.", | |
2381 | &showhistlist, "show history ", 0, &showlist); | |
2382 | ||
2383 | add_show_from_set | |
2384 | (add_set_cmd ("expansion", no_class, var_boolean, (char *)&history_expansion_p, | |
2385 | "Set history expansion on command input.\n\ | |
2386 | Without an argument, history expansion is enabled.", &sethistlist), | |
2387 | &showhistlist); | |
2388 | ||
2389 | add_show_from_set | |
f266e564 | 2390 | (add_set_cmd ("save", no_class, var_boolean, (char *)&write_history_p, |
bd5635a1 RP |
2391 | "Set saving of the history record on exit.\n\ |
2392 | Use \"on\" to enable to enable the saving, and \"off\" to disable it.\n\ | |
2393 | Without an argument, saving is enabled.", &sethistlist), | |
2394 | &showhistlist); | |
2395 | ||
2396 | c = add_set_cmd ("size", no_class, var_uinteger, (char *)&history_size, | |
2397 | "Set the size of the command history, \n\ | |
2398 | ie. the number of previous commands to keep a record of.", &sethistlist); | |
2399 | add_show_from_set (c, &showhistlist); | |
30875e1c | 2400 | c->function.sfunc = set_history_size_command; |
bd5635a1 RP |
2401 | |
2402 | add_show_from_set | |
2403 | (add_set_cmd ("filename", no_class, var_filename, (char *)&history_filename, | |
2404 | "Set the filename in which to record the command history\n\ | |
2405 | (the list of previous commands of which a record is kept).", &sethistlist), | |
2406 | &showhistlist); | |
2407 | ||
2408 | add_show_from_set | |
f266e564 | 2409 | (add_set_cmd ("confirm", class_support, var_boolean, |
bd5635a1 | 2410 | (char *)&caution, |
f266e564 JK |
2411 | "Set whether to confirm potentially dangerous operations.", |
2412 | &setlist), | |
bd5635a1 RP |
2413 | &showlist); |
2414 | ||
2415 | add_prefix_cmd ("info", class_info, info_command, | |
ee0613d1 | 2416 | "Generic command for showing things about the program being debugged.", |
bd5635a1 RP |
2417 | &infolist, "info ", 0, &cmdlist); |
2418 | add_com_alias ("i", "info", class_info, 1); | |
2419 | ||
2420 | add_prefix_cmd ("show", class_info, show_command, | |
ee0613d1 | 2421 | "Generic command for showing things about the debugger.", |
bd5635a1 RP |
2422 | &showlist, "show ", 0, &cmdlist); |
2423 | /* Another way to get at the same thing. */ | |
2424 | add_info ("set", show_command, "Show all GDB settings."); | |
2425 | ||
ee0613d1 JG |
2426 | add_cmd ("commands", no_class, show_commands, |
2427 | "Show the the history of commands you typed.\n\ | |
2428 | You can supply a command number to start with, or a `+' to start after\n\ | |
2429 | the previous command number shown.", | |
f266e564 | 2430 | &showlist); |
bd5635a1 | 2431 | |
f266e564 | 2432 | add_cmd ("version", no_class, show_version, |
ee0613d1 | 2433 | "Show what version of GDB this is.", &showlist); |
bd5635a1 | 2434 | } |