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