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