1 /* Top level `main' program for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
3 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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. */
23 #include "call-cmds.h"
28 #include "breakpoint.h"
30 #include "expression.h"
35 /* readline include files */
39 /* readline defines this. */
43 #include <sys/types.h>
52 #include <sys/param.h>
56 #ifdef SET_STACK_LIMIT_HUGE
58 #include <sys/resource.h>
60 int original_stack_limit
;
63 /* Prototypes for local functions */
66 symbol_completion_function
PARAMS ((char *, int));
69 command_loop
PARAMS ((void));
72 command_loop_marker
PARAMS ((int));
75 print_gdb_version
PARAMS ((FILE *));
78 quit_command
PARAMS ((char *, int));
81 init_main
PARAMS ((void));
84 init_history
PARAMS ((void));
87 init_cmd_lists
PARAMS ((void));
90 float_handler
PARAMS ((int));
93 source_command
PARAMS ((char *, int));
96 cd_command
PARAMS ((char *, int));
99 print_gnu_advertisement
PARAMS ((void));
102 init_signals
PARAMS ((void));
105 read_command_file
PARAMS ((FILE *));
108 set_verbose
PARAMS ((char *, int, struct cmd_list_element
*));
111 show_history
PARAMS ((char *, int));
114 set_history
PARAMS ((char *, int));
117 set_history_size_command
PARAMS ((char *, int, struct cmd_list_element
*));
120 show_commands
PARAMS ((char *, int));
123 echo_command
PARAMS ((char *, int));
126 pwd_command
PARAMS ((char *, int));
129 show_version
PARAMS ((char *, int));
132 document_command
PARAMS ((char *, int));
135 define_command
PARAMS ((char *, int));
138 validate_comname
PARAMS ((char *));
141 help_command
PARAMS ((char *, int));
144 show_command
PARAMS ((char *, int));
147 info_command
PARAMS ((char *, int));
150 do_nothing
PARAMS ((int));
153 quit_cover
PARAMS ((char *));
156 disconnect
PARAMS ((int));
159 source_cleanup
PARAMS ((FILE *));
161 /* If this definition isn't overridden by the header files, assume
162 that isatty and fileno exist on this system. */
164 #define ISATTY(FP) (isatty (fileno (FP)))
167 /* Initialization file name for gdb. This is overridden in some configs. */
169 #ifndef GDBINIT_FILENAME
170 #define GDBINIT_FILENAME ".gdbinit"
172 static char gdbinit
[] = GDBINIT_FILENAME
;
173 static int inhibit_gdbinit
= 0;
175 #define ALL_CLEANUPS ((struct cleanup *)0)
177 /* Version number of GDB, as a string. */
179 extern char *version
;
181 /* Canonical host name as a string. */
183 extern char *host_canonical
;
185 /* Canonical target name as a string. */
187 extern char *target_canonical
;
189 /* Message to be printed before the error message, when an error occurs. */
191 extern char *error_pre_print
;
193 /* Message to be printed before the warning message, when a warning occurs. */
195 extern char *warning_pre_print
;
197 extern char lang_frame_mismatch_warn
[]; /* language.c */
199 /* Whether GDB's stdin is on a terminal. */
201 extern int gdb_has_a_terminal
; /* inflow.c */
203 /* Flag for whether we want all the "from_tty" gubbish printed. */
205 int caution
= 1; /* Default is yes, sigh. */
208 * Define all cmd_list_element's
211 /* Chain containing all defined commands. */
213 struct cmd_list_element
*cmdlist
;
215 /* Chain containing all defined info subcommands. */
217 struct cmd_list_element
*infolist
;
219 /* Chain containing all defined enable subcommands. */
221 struct cmd_list_element
*enablelist
;
223 /* Chain containing all defined disable subcommands. */
225 struct cmd_list_element
*disablelist
;
227 /* Chain containing all defined delete subcommands. */
229 struct cmd_list_element
*deletelist
;
231 /* Chain containing all defined "enable breakpoint" subcommands. */
233 struct cmd_list_element
*enablebreaklist
;
235 /* Chain containing all defined set subcommands */
237 struct cmd_list_element
*setlist
;
239 /* Chain containing all defined unset subcommands */
241 struct cmd_list_element
*unsetlist
;
243 /* Chain containing all defined show subcommands. */
245 struct cmd_list_element
*showlist
;
247 /* Chain containing all defined \"set history\". */
249 struct cmd_list_element
*sethistlist
;
251 /* Chain containing all defined \"show history\". */
253 struct cmd_list_element
*showhistlist
;
255 /* Chain containing all defined \"unset history\". */
257 struct cmd_list_element
*unsethistlist
;
259 /* Chain containing all defined maintenance subcommands. */
262 struct cmd_list_element
*maintenancelist
;
265 /* Chain containing all defined "maintenance info" subcommands. */
268 struct cmd_list_element
*maintenanceinfolist
;
271 /* Chain containing all defined "maintenance print" subcommands. */
274 struct cmd_list_element
*maintenanceprintlist
;
277 struct cmd_list_element
*setprintlist
;
279 struct cmd_list_element
*showprintlist
;
281 struct cmd_list_element
*setchecklist
;
283 struct cmd_list_element
*showchecklist
;
285 /* stdio stream that command input is being read from. */
289 /* Current working directory. */
291 char *current_directory
;
293 /* The directory name is actually stored here (usually). */
294 static char dirbuf
[1024];
296 /* Function to call before reading a command, if nonzero.
297 The function receives two args: an input stream,
298 and a prompt string. */
300 void (*window_hook
) PARAMS ((FILE *, char *));
302 extern int mapped_symbol_files
;
303 extern int readnow_symbol_files
;
308 /* gdb prints this when reading a command interactively */
311 /* Buffer used for reading command lines, and the size
312 allocated for it so far. */
317 /* Baud rate specified for talking to serial target systems. Default
318 is left as a zero pointer, so targets can choose their own defaults. */
322 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
326 #define STOP_SIGNAL SIGTSTP
327 static void stop_sig
PARAMS ((int));
331 /* Some System V have job control but not sigsetmask(). */
332 #if !defined (HAVE_SIGSETMASK)
333 #define HAVE_SIGSETMASK !defined (USG)
336 #if 0 == (HAVE_SIGSETMASK)
337 #define sigsetmask(n)
340 /* Where to go for return_to_top_level (RETURN_ERROR). */
341 static jmp_buf error_return
;
342 /* Where to go for return_to_top_level (RETURN_QUIT). */
343 static jmp_buf quit_return
;
345 /* Temporary variable for SET_TOP_LEVEL. */
346 static int top_level_val
;
348 /* Do a setjmp on error_return and quit_return. catch_errors is
349 generally a cleaner way to do this, but main() would look pretty
350 ugly if it had to use catch_errors each time. */
352 #define SET_TOP_LEVEL() \
353 (((top_level_val = setjmp (error_return)) \
354 ? (PTR) 0 : (PTR) memcpy (quit_return, error_return, sizeof (jmp_buf))) \
357 /* Return for reason REASON. This generally gets back to the command
358 loop, but can be caught via catch_errors. */
361 return_to_top_level (reason
)
362 enum return_reason reason
;
366 bpstat_clear_actions(stop_bpstat
); /* Clear queued breakpoint commands */
367 disable_current_display ();
368 do_cleanups (ALL_CLEANUPS
);
369 (NORETURN
void) longjmp
370 (reason
== RETURN_ERROR
? error_return
: quit_return
, 1);
373 /* Call FUNC with arg ARGS, catching any errors. If there is no
374 error, return the value returned by FUNC. If there is an error,
375 print ERRSTRING, print the specific error message, then return
378 MASK specifies what to catch; it is normally set to
379 RETURN_MASK_ALL, if for no other reason than that the code which
380 calls catch_errors might not be set up to deal with a quit which
381 isn't caught. But if the code can deal with it, it generally
382 should be RETURN_MASK_ERROR, unless for some reason it is more
383 useful to abort only the portion of the operation inside the
384 catch_errors. Note that quit should return to the command line
385 fairly quickly, even if some further processing is being done. */
388 catch_errors (func
, args
, errstring
, mask
)
389 int (*func
) PARAMS ((char *));
398 struct cleanup
*saved_cleanup_chain
;
399 char *saved_error_pre_print
;
401 saved_cleanup_chain
= save_cleanups ();
402 saved_error_pre_print
= error_pre_print
;
404 if (mask
& RETURN_MASK_ERROR
)
405 memcpy ((char *)saved_error
, (char *)error_return
, sizeof (jmp_buf));
406 if (mask
& RETURN_MASK_QUIT
)
407 memcpy (saved_quit
, quit_return
, sizeof (jmp_buf));
408 error_pre_print
= errstring
;
410 if (setjmp (tmp_jmp
) == 0)
412 if (mask
& RETURN_MASK_ERROR
)
413 memcpy (error_return
, tmp_jmp
, sizeof (jmp_buf));
414 if (mask
& RETURN_MASK_QUIT
)
415 memcpy (quit_return
, tmp_jmp
, sizeof (jmp_buf));
416 val
= (*func
) (args
);
421 restore_cleanups (saved_cleanup_chain
);
423 error_pre_print
= saved_error_pre_print
;
424 if (mask
& RETURN_MASK_ERROR
)
425 memcpy (error_return
, saved_error
, sizeof (jmp_buf));
426 if (mask
& RETURN_MASK_QUIT
)
427 memcpy (quit_return
, saved_quit
, sizeof (jmp_buf));
431 /* Handler for SIGHUP. */
437 catch_errors (quit_cover
, NULL
,
438 "Could not kill the program being debugged", RETURN_MASK_ALL
);
439 signal (SIGHUP
, SIG_DFL
);
440 kill (getpid (), SIGHUP
);
443 /* Just a little helper function for disconnect(). */
449 caution
= 0; /* Throw caution to the wind -- we're exiting.
450 This prevents asking the user dumb questions. */
451 quit_command((char *)0, 0);
455 /* Clean up on error during a "source" command (or execution of a
456 user-defined command). */
459 source_cleanup (stream
)
462 /* Restore the previous input stream. */
466 /* Read commands from STREAM. */
468 read_command_file (stream
)
471 struct cleanup
*cleanups
;
473 cleanups
= make_cleanup (source_cleanup
, instream
);
476 do_cleanups (cleanups
);
485 static int quiet
= 0;
486 static int batch
= 0;
488 /* Pointers to various arguments from command line. */
490 char *execarg
= NULL
;
491 char *corearg
= NULL
;
495 /* Pointers to all arguments of +command option. */
497 /* Allocated size of cmdarg. */
499 /* Number of elements of cmdarg used. */
502 /* Indices of all arguments of +directory option. */
504 /* Allocated size. */
506 /* Number of elements used. */
509 struct stat homebuf
, cwdbuf
;
510 char *homedir
, *homeinit
;
514 /* This needs to happen before the first use of malloc. */
515 init_malloc ((PTR
) NULL
);
517 #if defined (ALIGN_STACK_ON_STARTUP)
518 i
= (int) &count
& 0x3;
523 /* If error() is called from initialization code, just exit */
524 if (SET_TOP_LEVEL ()) {
529 cmdarg
= (char **) xmalloc (cmdsize
* sizeof (*cmdarg
));
532 dirarg
= (char **) xmalloc (dirsize
* sizeof (*dirarg
));
536 line
= (char *) xmalloc (linesize
);
537 line
[0] = '\0'; /* Terminate saved (now empty) cmd line */
540 getcwd (dirbuf
, sizeof (dirbuf
));
541 current_directory
= dirbuf
;
543 #ifdef SET_STACK_LIMIT_HUGE
547 /* Set the stack limit huge so that alloca (particularly stringtab
548 * in dbxread.c) does not fail. */
549 getrlimit (RLIMIT_STACK
, &rlim
);
550 original_stack_limit
= rlim
.rlim_cur
;
551 rlim
.rlim_cur
= rlim
.rlim_max
;
552 setrlimit (RLIMIT_STACK
, &rlim
);
554 #endif /* SET_STACK_LIMIT_HUGE */
556 /* Parse arguments and options. */
559 static int print_help
;
560 /* When var field is 0, use flag field to record the equivalent
561 short option (or arbitrary numbers starting at 10 for those
562 with no equivalent). */
563 static struct option long_options
[] =
565 {"readnow", no_argument
, &readnow_symbol_files
, 1},
566 {"r", no_argument
, &readnow_symbol_files
, 1},
567 {"mapped", no_argument
, &mapped_symbol_files
, 1},
568 {"m", no_argument
, &mapped_symbol_files
, 1},
569 {"quiet", no_argument
, &quiet
, 1},
570 {"q", no_argument
, &quiet
, 1},
571 {"silent", no_argument
, &quiet
, 1},
572 {"nx", no_argument
, &inhibit_gdbinit
, 1},
573 {"n", no_argument
, &inhibit_gdbinit
, 1},
574 {"batch", no_argument
, &batch
, 1},
575 {"epoch", no_argument
, &epoch_interface
, 1},
576 {"fullname", no_argument
, &frame_file_full_name
, 1},
577 {"f", no_argument
, &frame_file_full_name
, 1},
578 {"help", no_argument
, &print_help
, 1},
579 {"se", required_argument
, 0, 10},
580 {"symbols", required_argument
, 0, 's'},
581 {"s", required_argument
, 0, 's'},
582 {"exec", required_argument
, 0, 'e'},
583 {"e", required_argument
, 0, 'e'},
584 {"core", required_argument
, 0, 'c'},
585 {"c", required_argument
, 0, 'c'},
586 {"command", required_argument
, 0, 'x'},
587 {"x", required_argument
, 0, 'x'},
588 {"directory", required_argument
, 0, 'd'},
589 {"cd", required_argument
, 0, 11},
590 {"tty", required_argument
, 0, 't'},
591 {"baud", required_argument
, 0, 'b'},
592 {"b", required_argument
, 0, 'b'},
593 /* Allow machine descriptions to add more options... */
594 #ifdef ADDITIONAL_OPTIONS
597 {0, no_argument
, 0, 0},
604 c
= getopt_long_only (argc
, argv
, "",
605 long_options
, &option_index
);
609 /* Long option that takes an argument. */
610 if (c
== 0 && long_options
[option_index
].flag
== 0)
611 c
= long_options
[option_index
].val
;
616 /* Long option that just sets a flag. */
635 cmdarg
[ncmd
++] = optarg
;
639 cmdarg
= (char **) xrealloc ((char *)cmdarg
,
640 cmdsize
* sizeof (*cmdarg
));
644 dirarg
[ndir
++] = optarg
;
648 dirarg
= (char **) xrealloc ((char *)dirarg
,
649 dirsize
* sizeof (*dirarg
));
661 #ifdef ADDITIONAL_OPTION_CASES
662 ADDITIONAL_OPTION_CASES
666 "Use `%s --help' for a complete list of options.\n",
674 print_gdb_version(stderr
);
676 This is the GNU debugger. Usage:\n\
677 gdb [options] [executable-file [core-file or process-id]]\n\
679 -help Print this message.\n\
680 -quiet Do not print version number on startup.\n\
681 -fullname Output information used by emacs-GDB interface.\n\
682 -epoch Output information used by epoch emacs-GDB interface.\n\
683 -batch Exit after processing options.\n\
684 -nx Do not read .gdbinit file.\n\
685 -tty=TTY Use TTY for input/output by the program being debugged.\n\
686 -cd=DIR Change current directory to DIR.\n\
687 -directory=DIR Search for source files in DIR.\n\
688 -command=FILE Execute GDB commands from FILE.\n\
689 -symbols=SYMFILE Read symbols from SYMFILE.\n\
690 -exec=EXECFILE Use EXECFILE as the executable.\n\
691 -se=FILE Use FILE as symbol file and executable file.\n\
692 -core=COREFILE Analyze the core dump COREFILE.\n\
693 -b BAUDRATE Set serial port baud rate used for remote debugging.\n\
694 -mapped Use mapped symbol files if supported on this system.\n\
695 -readnow Fully read symbol files on first access.\n\
697 #ifdef ADDITIONAL_OPTION_HELP
698 fputs (ADDITIONAL_OPTION_HELP
, stderr
);
701 For more information, type \"help\" from within GDB, or consult the\n\
702 GDB manual (available as on-line info or a printed manual).\n", stderr
);
703 /* Exiting after printing this message seems like
704 the most useful thing to do. */
708 /* OK, that's all the options. The other arguments are filenames. */
710 for (; optind
< argc
; optind
++)
714 symarg
= argv
[optind
];
715 execarg
= argv
[optind
];
718 corearg
= argv
[optind
];
722 "Excess command line arguments ignored. (%s%s)\n",
723 argv
[optind
], (optind
== argc
- 1) ? "" : " ...");
730 /* Run the init function of each source file */
732 init_cmd_lists (); /* This needs to be done first */
733 initialize_all_files ();
734 init_main (); /* But that omits this file! Do it now */
739 /* Print all the junk at the top, with trailing "..." if we are about
740 to read a symbol file (possibly slowly). */
741 print_gnu_advertisement ();
742 print_gdb_version (stdout
);
744 printf_filtered ("..");
746 fflush (stdout
); /* Force to screen during slow operations */
749 error_pre_print
= "\n\n";
750 /* We may get more than one warning, don't double space all of them... */
751 warning_pre_print
= "\nwarning: ";
753 /* We need a default language for parsing expressions, so simple things like
754 "set width 0" won't fail if no language is explicitly set in a config file
755 or implicitly set by reading an executable during startup. */
756 set_language (language_c
);
757 expected_language
= current_language
; /* don't warn about the change. */
759 /* Read and execute $HOME/.gdbinit file, if it exists. This is done
760 *before* all the command line arguments are processed; it sets
761 global parameters, which are independent of what file you are
762 debugging or what directory you are in. */
763 homedir
= getenv ("HOME");
766 homeinit
= (char *) alloca (strlen (getenv ("HOME")) +
767 strlen (gdbinit
) + 10);
768 strcpy (homeinit
, getenv ("HOME"));
769 strcat (homeinit
, "/");
770 strcat (homeinit
, gdbinit
);
771 if (!inhibit_gdbinit
&& access (homeinit
, R_OK
) == 0)
773 if (!SET_TOP_LEVEL ())
774 source_command (homeinit
, 0);
776 do_cleanups (ALL_CLEANUPS
);
778 /* Do stats; no need to do them elsewhere since we'll only
779 need them if homedir is set. Make sure that they are
780 zero in case one of them fails (this guarantees that they
781 won't match if either exists). */
783 memset (&homebuf
, 0, sizeof (struct stat
));
784 memset (&cwdbuf
, 0, sizeof (struct stat
));
786 stat (homeinit
, &homebuf
);
787 stat (gdbinit
, &cwdbuf
); /* We'll only need this if
791 /* Now perform all the actions indicated by the arguments. */
794 if (!SET_TOP_LEVEL ())
796 cd_command (cdarg
, 0);
800 do_cleanups (ALL_CLEANUPS
);
802 for (i
= 0; i
< ndir
; i
++)
803 if (!SET_TOP_LEVEL ())
804 directory_command (dirarg
[i
], 0);
806 do_cleanups (ALL_CLEANUPS
);
810 && STREQ (execarg
, symarg
))
812 /* The exec file and the symbol-file are the same. If we can't open
813 it, better only print one error message. */
814 if (!SET_TOP_LEVEL ())
816 exec_file_command (execarg
, !batch
);
817 symbol_file_command (symarg
, 0);
823 if (!SET_TOP_LEVEL ())
824 exec_file_command (execarg
, !batch
);
826 if (!SET_TOP_LEVEL ())
827 symbol_file_command (symarg
, 0);
829 do_cleanups (ALL_CLEANUPS
);
831 /* After the symbol file has been read, print a newline to get us
832 beyond the copyright line... But errors should still set off
833 the error message with a (single) blank line. */
835 printf_filtered ("\n");
836 error_pre_print
= "\n";
837 warning_pre_print
= "\nwarning: ";
840 if (!SET_TOP_LEVEL ())
841 core_file_command (corearg
, !batch
);
842 else if (isdigit (corearg
[0]) && !SET_TOP_LEVEL ())
843 attach_command (corearg
, !batch
);
844 do_cleanups (ALL_CLEANUPS
);
847 if (!SET_TOP_LEVEL ())
848 tty_command (ttyarg
, !batch
);
849 do_cleanups (ALL_CLEANUPS
);
851 #ifdef ADDITIONAL_OPTION_HANDLER
852 ADDITIONAL_OPTION_HANDLER
;
855 /* Error messages should no longer be distinguished with extra output. */
857 warning_pre_print
= "warning: ";
859 /* Read the .gdbinit file in the current directory, *if* it isn't
860 the same as the $HOME/.gdbinit file (it should exist, also). */
863 || memcmp ((char *) &homebuf
, (char *) &cwdbuf
, sizeof (struct stat
)))
864 if (!inhibit_gdbinit
&& access (gdbinit
, R_OK
) == 0)
866 if (!SET_TOP_LEVEL ())
867 source_command (gdbinit
, 0);
869 do_cleanups (ALL_CLEANUPS
);
871 for (i
= 0; i
< ncmd
; i
++)
873 if (!SET_TOP_LEVEL ())
875 if (cmdarg
[i
][0] == '-' && cmdarg
[i
][1] == '\0')
876 read_command_file (stdin
);
878 source_command (cmdarg
[i
], !batch
);
879 do_cleanups (ALL_CLEANUPS
);
884 /* Read in the old history after all the command files have been read. */
889 /* We have hit the end of the batch file. */
893 /* Do any host- or target-specific hacks. This is used for i960 targets
894 to force the user to set a nindy target and spec its parameters. */
896 #ifdef BEFORE_MAIN_LOOP_HOOK
897 BEFORE_MAIN_LOOP_HOOK
;
900 /* The command loop. */
904 if (!SET_TOP_LEVEL ())
906 do_cleanups (ALL_CLEANUPS
); /* Do complete cleanup */
908 quit_command ((char *)0, instream
== stdin
);
911 /* No exit -- exit is through quit_command. */
915 execute_user_command (c
, args
)
916 struct cmd_list_element
*c
;
919 register struct command_line
*cmdlines
;
920 struct cleanup
*old_chain
;
923 error ("User-defined commands cannot take arguments.");
925 cmdlines
= c
->user_commands
;
930 /* Set the instream to 0, indicating execution of a
931 user-defined function. */
932 old_chain
= make_cleanup (source_cleanup
, instream
);
933 instream
= (FILE *) 0;
936 execute_command (cmdlines
->line
, 0);
937 cmdlines
= cmdlines
->next
;
939 do_cleanups (old_chain
);
942 /* Execute the line P as a command.
943 Pass FROM_TTY as second argument to the defining function. */
946 execute_command (p
, from_tty
)
950 register struct cmd_list_element
*c
;
951 register enum language flang
;
952 static int warned
= 0;
956 /* This can happen when command_line_input hits end of file. */
960 while (*p
== ' ' || *p
== '\t') p
++;
965 c
= lookup_cmd (&p
, cmdlist
, "", 0, 1);
966 /* Pass null arg rather than an empty one. */
969 /* If this command has been hooked, run the hook first. */
971 execute_user_command (c
->hook
, (char *)0);
973 if (c
->class == class_user
)
974 execute_user_command (c
, arg
);
975 else if (c
->type
== set_cmd
|| c
->type
== show_cmd
)
976 do_setshow_command (arg
, from_tty
& caution
, c
);
977 else if (c
->function
.cfunc
== NO_FUNCTION
)
978 error ("That is not a command, just a help topic.");
980 (*c
->function
.cfunc
) (arg
, from_tty
& caution
);
983 /* Tell the user if the language has changed (except first time). */
984 if (current_language
!= expected_language
)
986 if (language_mode
== language_mode_auto
) {
987 language_info (1); /* Print what changed. */
992 /* Warn the user if the working language does not match the
993 language of the current frame. Only warn the user if we are
994 actually running the program, i.e. there is a stack. */
995 /* FIXME: This should be cacheing the frame and only running when
996 the frame changes. */
997 if (target_has_stack
)
999 flang
= get_frame_language ();
1001 && flang
!= language_unknown
1002 && flang
!= current_language
->la_language
)
1004 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
1012 command_loop_marker (foo
)
1017 /* Read commands from `instream' and execute them
1018 until end of file or error reading instream. */
1022 struct cleanup
*old_chain
;
1024 int stdin_is_tty
= ISATTY (stdin
);
1026 while (!feof (instream
))
1028 if (window_hook
&& instream
== stdin
)
1029 (*window_hook
) (instream
, prompt
);
1032 if (instream
== stdin
&& stdin_is_tty
)
1033 reinitialize_more_filter ();
1034 old_chain
= make_cleanup (command_loop_marker
, 0);
1035 command
= command_line_input (instream
== stdin
? prompt
: (char *) NULL
,
1039 execute_command (command
, instream
== stdin
);
1040 /* Do any commands attached to breakpoint we stopped at. */
1041 bpstat_do_actions (&stop_bpstat
);
1042 do_cleanups (old_chain
);
1046 /* Commands call this if they do not want to be repeated by null lines. */
1051 /* If we aren't reading from standard input, we are saving the last
1052 thing read from stdin in line and don't want to delete it. Null lines
1053 won't repeat here in any case. */
1054 if (instream
== stdin
)
1058 /* Read a line from the stream "instream" without command line editing.
1060 It prints PRROMPT once at the start.
1061 Action is compatible with "readline", e.g. space for the result is
1062 malloc'd and should be freed by the caller.
1064 A NULL return means end of file. */
1066 gdb_readline (prrompt
)
1071 int input_index
= 0;
1072 int result_size
= 80;
1076 /* Don't use a _filtered function here. It causes the assumed
1077 character position to be off, since the newline we read from
1078 the user is not accounted for. */
1079 fputs (prrompt
, stdout
);
1083 result
= (char *) xmalloc (result_size
);
1087 /* Read from stdin if we are executing a user defined command.
1088 This is the right thing for prompt_for_continue, at least. */
1089 c
= fgetc (instream
? instream
: stdin
);
1100 result
[input_index
++] = c
;
1101 while (input_index
>= result_size
)
1104 result
= (char *) xrealloc (result
, result_size
);
1108 result
[input_index
++] = '\0';
1112 /* Variables which control command line editing and history
1113 substitution. These variables are given default values at the end
1115 static int command_editing_p
;
1116 static int history_expansion_p
;
1117 static int write_history_p
;
1118 static int history_size
;
1119 static char *history_filename
;
1121 /* Variables which are necessary for fancy command line editing. */
1122 char *gdb_completer_word_break_characters
=
1123 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1125 /* When completing on command names, we remove '-' from the list of
1126 word break characters, since we use it in command names. If the
1127 readline library sees one in any of the current completion strings,
1128 it thinks that the string needs to be quoted and automatically supplies
1130 char *gdb_completer_command_word_break_characters
=
1131 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1133 /* Characters that can be used to quote completion strings. Note that we
1134 can't include '"' because the gdb C parser treats such quoted sequences
1136 char *gdb_completer_quote_characters
=
1139 /* Functions that are used as part of the fancy command line editing. */
1141 /* This can be used for functions which don't want to complete on symbols
1142 but don't want to complete on anything else either. */
1145 noop_completer (text
)
1151 /* Complete on filenames. */
1152 /* FIXME: This would be a lot more useful if the word breaks got set
1153 to not include '/'. Probably best to make it up to each completer
1154 to do its own word breaking. */
1156 filename_completer (text
)
1159 /* From readline. */
1160 extern char *filename_completion_function ();
1161 int subsequent_name
;
1163 int return_val_used
;
1164 int return_val_alloced
;
1166 return_val_used
= 0;
1167 /* Small for testing. */
1168 return_val_alloced
= 1;
1169 return_val
= (char **) xmalloc (return_val_alloced
* sizeof (char *));
1171 subsequent_name
= 0;
1175 p
= filename_completion_function (text
, subsequent_name
);
1176 if (return_val_used
>= return_val_alloced
)
1178 return_val_alloced
*= 2;
1180 (char **) xrealloc (return_val
,
1181 return_val_alloced
* sizeof (char *));
1183 /* The string itself has already been stored in newly malloc'd space
1184 for us by filename_completion_function. */
1185 return_val
[return_val_used
++] = p
;
1188 subsequent_name
= 1;
1193 /* Generate symbol names one by one for the completer. Each time we are
1194 called return another potential completion to the caller.
1196 TEXT is what we expect the symbol to start with.
1198 MATCHES is the number of matches that have currently been collected from
1199 calling this completion function. When zero, then we need to initialize,
1200 otherwise the initialization has already taken place and we can just
1201 return the next potential completion string.
1203 Returns NULL if there are no more completions, else a pointer to a string
1204 which is a possible completion.
1206 RL_LINE_BUFFER is available to be looked at; it contains the entire text
1207 of the line. RL_POINT is the offset in that line of the cursor. You
1208 should pretend that the line ends at RL_POINT. */
1211 symbol_completion_function (text
, matches
)
1215 static char **list
= (char **)NULL
; /* Cache of completions */
1216 static int index
; /* Next cached completion */
1217 char *output
= NULL
;
1218 char *tmp_command
, *p
;
1219 struct cmd_list_element
*c
, *result_list
;
1220 extern char *rl_line_buffer
;
1221 extern int rl_point
;
1225 /* The caller is beginning to accumulate a new set of completions, so
1226 we need to find all of them now, and cache them for returning one at
1227 a time on future calls. */
1231 /* Free the storage used by LIST, but not by the strings inside.
1232 This is because rl_complete_internal () frees the strings. */
1238 /* Choose the default set of word break characters to break completions.
1239 If we later find out that we are doing completions on command strings
1240 (as opposed to strings supplied by the individual command completer
1241 functions, which can be any string) then we will switch to the
1242 special word break set for command strings, which leaves out the
1243 '-' character used in some commands. */
1245 /* FIXME: Using rl_completer_word_break_characters is the wrong
1246 approach, because "show foo-bar<TAB>" won't know to use the
1247 new set until too late. Better approach is to do the word breaking
1250 rl_completer_word_break_characters
=
1251 gdb_completer_word_break_characters
;
1253 /* Decide whether to complete on a list of gdb commands or on symbols. */
1254 tmp_command
= (char *) alloca (rl_point
+ 1);
1257 strncpy (tmp_command
, rl_line_buffer
, rl_point
);
1258 tmp_command
[rl_point
] = '\0';
1262 /* An empty line we want to consider ambiguous; that is, it
1263 could be any command. */
1264 c
= (struct cmd_list_element
*) -1;
1269 c
= lookup_cmd_1 (&p
, cmdlist
, &result_list
, 1);
1272 /* Move p up to the next interesting thing. */
1273 while (*p
== ' ' || *p
== '\t')
1280 /* He's typed something unrecognizable. Sigh. */
1283 else if (c
== (struct cmd_list_element
*) -1)
1285 /* If we didn't recognize everything up to the thing that
1286 needs completing, and we don't know what command it is
1287 yet, we are in trouble. */
1289 if (p
+ strlen(text
) != tmp_command
+ rl_point
)
1291 /* This really should not produce an error. Better would
1292 be to pretend to hit RETURN here; this would produce a
1293 response like "Ambiguous command: foo, foobar, etc",
1294 and leave the line available for re-entry with ^P.
1295 Instead, this error blows away the user's typed input
1296 without any way to get it back. */
1297 error (" Unrecognized command.");
1300 /* He's typed something ambiguous. This is easier. */
1303 list
= complete_on_cmdlist (*result_list
->prefixlist
, text
);
1307 list
= complete_on_cmdlist (cmdlist
, text
);
1309 rl_completer_word_break_characters
=
1310 gdb_completer_command_word_break_characters
;
1314 /* If we've gotten this far, gdb has recognized a full
1315 command. There are several possibilities:
1317 1) We need to complete on the command.
1318 2) We need to complete on the possibilities coming after
1320 2) We need to complete the text of what comes after the
1325 /* Always (might be longer versions of thie command). */
1326 list
= complete_on_cmdlist (result_list
, text
);
1327 rl_completer_word_break_characters
=
1328 gdb_completer_command_word_break_characters
;
1330 else if (!*p
&& !*text
)
1334 list
= complete_on_cmdlist (*c
->prefixlist
, "");
1335 rl_completer_word_break_characters
=
1336 gdb_completer_command_word_break_characters
;
1340 list
= (*c
->completer
) ("");
1345 if (c
->prefixlist
&& !c
->allow_unknown
)
1347 /* Something like "info adsfkdj". But error() is not the
1348 proper response; just return no completions instead. */
1353 list
= (*c
->completer
) (text
);
1359 /* If we found a list of potential completions during initialization then
1360 dole them out one at a time. The vector of completions is NULL
1361 terminated, so after returning the last one, return NULL (and continue
1362 to do so) each time we are called after that, until a new list is
1367 output
= list
[index
];
1377 /* Skip over a possibly quoted word (as defined by the quote characters
1378 and word break characters the completer uses). Returns pointer to the
1379 location after the "word". */
1385 char quote_char
= '\0';
1388 for (scan
= str
; *scan
!= '\0'; scan
++)
1390 if (quote_char
!= '\0')
1392 /* Ignore everything until the matching close quote char */
1393 if (*scan
== quote_char
)
1395 /* Found matching close quote. */
1400 else if (strchr (gdb_completer_quote_characters
, *scan
))
1402 /* Found start of a quoted string. */
1405 else if (strchr (gdb_completer_word_break_characters
, *scan
))
1419 #if STOP_SIGNAL == SIGTSTP
1420 signal (SIGTSTP
, SIG_DFL
);
1422 kill (getpid (), SIGTSTP
);
1423 signal (SIGTSTP
, stop_sig
);
1425 signal (STOP_SIGNAL
, stop_sig
);
1427 printf ("%s", prompt
);
1430 /* Forget about any previous command -- null line now will do nothing. */
1433 #endif /* STOP_SIGNAL */
1435 /* Initialize signal handlers. */
1445 signal (SIGINT
, request_quit
);
1447 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
1448 passed to the inferior, which we don't want. It would be
1449 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
1450 on BSD4.3 systems using vfork, that can affect the
1451 GDB process as well as the inferior (the signal handling tables
1452 might be in memory, shared between the two). Since we establish
1453 a handler for SIGQUIT, when we call exec it will set the signal
1454 to SIG_DFL for us. */
1455 signal (SIGQUIT
, do_nothing
);
1456 if (signal (SIGHUP
, do_nothing
) != SIG_IGN
)
1457 signal (SIGHUP
, disconnect
);
1458 signal (SIGFPE
, float_handler
);
1460 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1461 signal (SIGWINCH
, SIGWINCH_HANDLER
);
1465 /* Read one line from the command input stream `instream'
1466 into the local static buffer `linebuffer' (whose current length
1468 The buffer is made bigger as necessary.
1469 Returns the address of the start of the line.
1471 NULL is returned for end of file.
1473 *If* the instream == stdin & stdin is a terminal, the line read
1474 is copied into the file line saver (global var char *line,
1475 length linesize) so that it can be duplicated.
1477 This routine either uses fancy command line editing or
1478 simple input as the user has requested. */
1481 command_line_input (prrompt
, repeat
)
1485 static char *linebuffer
= 0;
1486 static unsigned linelength
= 0;
1490 char *local_prompt
= prrompt
;
1495 if (linebuffer
== 0)
1498 linebuffer
= (char *) xmalloc (linelength
);
1503 /* Control-C quits instantly if typed while in this loop
1504 since it should not wait until the user types a newline. */
1507 signal (STOP_SIGNAL
, stop_sig
);
1512 /* Reports are that some Sys V's don't flush stdout/err on reads
1513 from stdin, when stdin/out are sockets rather than ttys. So we
1514 have to do it ourselves, to make emacs-gdb and xxgdb work.
1515 On other machines, doing this once per input should be a cheap nop. */
1519 /* Don't use fancy stuff if not talking to stdin. */
1520 if (command_editing_p
&& instream
== stdin
1521 && ISATTY (instream
))
1522 rl
= readline (local_prompt
);
1524 rl
= gdb_readline (local_prompt
);
1526 if (!rl
|| rl
== (char *) EOF
)
1531 if (strlen(rl
) + 1 + (p
- linebuffer
) > linelength
)
1533 linelength
= strlen(rl
) + 1 + (p
- linebuffer
);
1534 nline
= (char *) xrealloc (linebuffer
, linelength
);
1535 p
+= nline
- linebuffer
;
1539 /* Copy line. Don't copy null at end. (Leaves line alone
1540 if this was just a newline) */
1544 free (rl
); /* Allocated in readline. */
1546 if (p
== linebuffer
|| *(p
- 1) != '\\')
1549 p
--; /* Put on top of '\'. */
1550 local_prompt
= (char *) 0;
1554 signal (STOP_SIGNAL
, SIG_DFL
);
1561 /* Do history expansion if that is wished. */
1562 if (history_expansion_p
&& instream
== stdin
1563 && ISATTY (instream
))
1565 char *history_value
;
1568 *p
= '\0'; /* Insert null now. */
1569 expanded
= history_expand (linebuffer
, &history_value
);
1572 /* Print the changes. */
1573 printf ("%s\n", history_value
);
1575 /* If there was an error, call this function again. */
1578 free (history_value
);
1579 return command_line_input (prrompt
, repeat
);
1581 if (strlen (history_value
) > linelength
)
1583 linelength
= strlen (history_value
) + 1;
1584 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
1586 strcpy (linebuffer
, history_value
);
1587 p
= linebuffer
+ strlen(linebuffer
);
1588 free (history_value
);
1592 /* If we just got an empty line, and that is supposed
1593 to repeat the previous command, return the value in the
1597 if (p
== linebuffer
)
1600 while (*p1
== ' ' || *p1
== '\t')
1608 /* Add line to history if appropriate. */
1609 if (instream
== stdin
1610 && ISATTY (stdin
) && *linebuffer
)
1611 add_history (linebuffer
);
1613 /* Note: lines consisting soley of comments are added to the command
1614 history. This is useful when you type a command, and then
1615 realize you don't want to execute it quite yet. You can comment
1616 out the command and then later fetch it from the value history
1617 and remove the '#'. The kill ring is probably better, but some
1618 people are in the habit of commenting things out. */
1620 while ((c
= *p1
++) != '\0')
1623 while ((c
= *p1
++) != '"')
1625 /* Make sure an escaped '"' doesn't make us think the string
1633 while ((c
= *p1
++) != '\'')
1635 /* Make sure an escaped '\'' doesn't make us think the string
1644 /* Found a comment. */
1650 /* Save into global buffer if appropriate. */
1653 if (linelength
> linesize
)
1655 line
= xrealloc (line
, linelength
);
1656 linesize
= linelength
;
1658 strcpy (line
, linebuffer
);
1665 /* Read lines from the input stream
1666 and accumulate them in a chain of struct command_line's
1667 which is then returned. */
1669 struct command_line
*
1670 read_command_lines ()
1672 struct command_line
*first
= 0;
1673 register struct command_line
*next
, *tail
= 0;
1674 register char *p
, *p1
;
1675 struct cleanup
*old_chain
= 0;
1680 p
= command_line_input ((char *) NULL
, instream
== stdin
);
1682 /* Treat end of file like "end". */
1685 /* Remove leading and trailing blanks. */
1686 while (*p
== ' ' || *p
== '\t') p
++;
1687 p1
= p
+ strlen (p
);
1688 while (p1
!= p
&& (p1
[-1] == ' ' || p1
[-1] == '\t')) p1
--;
1690 /* Is this "end"? */
1691 if (p1
- p
== 3 && !strncmp (p
, "end", 3))
1694 /* No => add this line to the chain of command lines. */
1695 next
= (struct command_line
*) xmalloc (sizeof (struct command_line
));
1696 next
->line
= savestring (p
, p1
- p
);
1704 /* We just read the first line.
1705 From now on, arrange to throw away the lines we have
1706 if we quit or get an error while inside this function. */
1708 old_chain
= make_cleanup (free_command_lines
, &first
);
1715 /* Now we are about to return the chain to our caller,
1716 so freeing it becomes his responsibility. */
1718 discard_cleanups (old_chain
);
1722 /* Free a chain of struct command_line's. */
1725 free_command_lines (lptr
)
1726 struct command_line
**lptr
;
1728 register struct command_line
*l
= *lptr
;
1729 register struct command_line
*next
;
1740 /* Add an element to the list of info subcommands. */
1743 add_info (name
, fun
, doc
)
1745 void (*fun
) PARAMS ((char *, int));
1748 add_cmd (name
, no_class
, fun
, doc
, &infolist
);
1751 /* Add an alias to the list of info subcommands. */
1754 add_info_alias (name
, oldname
, abbrev_flag
)
1759 add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
1762 /* The "info" command is defined as a prefix, with allow_unknown = 0.
1763 Therefore, its own definition is called only for "info" with no args. */
1767 info_command (arg
, from_tty
)
1771 printf ("\"info\" must be followed by the name of an info command.\n");
1772 help_list (infolist
, "info ", -1, stdout
);
1775 /* The "show" command with no arguments shows all the settings. */
1779 show_command (arg
, from_tty
)
1783 cmd_show_list (showlist
, from_tty
, "");
1786 /* Add an element to the list of commands. */
1789 add_com (name
, class, fun
, doc
)
1791 enum command_class
class;
1792 void (*fun
) PARAMS ((char *, int));
1795 add_cmd (name
, class, fun
, doc
, &cmdlist
);
1798 /* Add an alias or abbreviation command to the list of commands. */
1801 add_com_alias (name
, oldname
, class, abbrev_flag
)
1804 enum command_class
class;
1807 add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
1814 error ("Argument required (%s).", why
);
1819 help_command (command
, from_tty
)
1821 int from_tty
; /* Ignored */
1823 help_cmd (command
, stdout
);
1827 validate_comname (comname
)
1833 error_no_arg ("name of command to define");
1838 if (!isalnum(*p
) && *p
!= '-')
1839 error ("Junk in argument list: \"%s\"", p
);
1844 /* This is just a placeholder in the command data structures. */
1846 user_defined_command (ignore
, from_tty
)
1853 define_command (comname
, from_tty
)
1857 register struct command_line
*cmds
;
1858 register struct cmd_list_element
*c
, *newc
, *hookc
= 0;
1859 char *tem
= comname
;
1860 #define HOOK_STRING "hook-"
1863 validate_comname (comname
);
1865 /* Look it up, and verify that we got an exact match. */
1866 c
= lookup_cmd (&tem
, cmdlist
, "", -1, 1);
1867 if (c
&& !STREQ (comname
, c
->name
))
1872 if (c
->class == class_user
|| c
->class == class_alias
)
1873 tem
= "Redefine command \"%s\"? ";
1875 tem
= "Really redefine built-in command \"%s\"? ";
1876 if (!query (tem
, c
->name
))
1877 error ("Command \"%s\" not redefined.", c
->name
);
1880 /* If this new command is a hook, then mark the command which it
1881 is hooking. Note that we allow hooking `help' commands, so that
1882 we can hook the `stop' pseudo-command. */
1884 if (!strncmp (comname
, HOOK_STRING
, HOOK_LEN
))
1886 /* Look up cmd it hooks, and verify that we got an exact match. */
1887 tem
= comname
+HOOK_LEN
;
1888 hookc
= lookup_cmd (&tem
, cmdlist
, "", -1, 0);
1889 if (hookc
&& !STREQ (comname
+HOOK_LEN
, hookc
->name
))
1893 warning ("Your new `%s' command does not hook any existing command.",
1895 if (!query ("Proceed? ", (char *)0))
1896 error ("Not confirmed.");
1900 comname
= savestring (comname
, strlen (comname
));
1902 /* If the rest of the commands will be case insensitive, this one
1903 should behave in the same manner. */
1904 for (tem
= comname
; *tem
; tem
++)
1905 if (isupper(*tem
)) *tem
= tolower(*tem
);
1909 printf ("Type commands for definition of \"%s\".\n\
1910 End with a line saying just \"end\".\n", comname
);
1914 cmds
= read_command_lines ();
1916 if (c
&& c
->class == class_user
)
1917 free_command_lines (&c
->user_commands
);
1919 newc
= add_cmd (comname
, class_user
, user_defined_command
,
1920 (c
&& c
->class == class_user
)
1921 ? c
->doc
: savestring ("User-defined.", 13), &cmdlist
);
1922 newc
->user_commands
= cmds
;
1924 /* If this new command is a hook, then mark both commands as being
1928 hookc
->hook
= newc
; /* Target gets hooked. */
1929 newc
->hookee
= hookc
; /* We are marked as hooking target cmd. */
1934 document_command (comname
, from_tty
)
1938 struct command_line
*doclines
;
1939 register struct cmd_list_element
*c
;
1940 char *tem
= comname
;
1942 validate_comname (comname
);
1944 c
= lookup_cmd (&tem
, cmdlist
, "", 0, 1);
1946 if (c
->class != class_user
)
1947 error ("Command \"%s\" is built-in.", comname
);
1950 printf ("Type documentation for \"%s\".\n\
1951 End with a line saying just \"end\".\n", comname
);
1953 doclines
= read_command_lines ();
1955 if (c
->doc
) free (c
->doc
);
1958 register struct command_line
*cl1
;
1959 register int len
= 0;
1961 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
1962 len
+= strlen (cl1
->line
) + 1;
1964 c
->doc
= (char *) xmalloc (len
+ 1);
1967 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
1969 strcat (c
->doc
, cl1
->line
);
1971 strcat (c
->doc
, "\n");
1975 free_command_lines (&doclines
);
1979 print_gnu_advertisement()
1982 GDB is free software and you are welcome to distribute copies of it\n\
1983 under certain conditions; type \"show copying\" to see the conditions.\n\
1984 There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
1989 print_gdb_version (stream
)
1992 fprintf_filtered (stream
, "\
1993 GDB %s (%s", version
, host_canonical
);
1995 if (strcmp(host_canonical
, target_canonical
))
1996 fprintf_filtered (stream
, " --target %s", target_canonical
);
1998 fprintf_filtered (stream
, "), ");
2000 fprintf_filtered (stream
, "Copyright 1993 Free Software Foundation, Inc.");
2005 show_version (args
, from_tty
)
2010 print_gnu_advertisement ();
2011 print_gdb_version (stdout
);
2012 printf_filtered ("\n");
2016 /* xgdb calls this to reprint the usual GDB prompt. */
2021 printf ("%s", prompt
);
2026 quit_command (args
, from_tty
)
2030 if (inferior_pid
!= 0 && target_has_execution
)
2034 if (query ("The program is running. Quit anyway (and detach it)? "))
2035 target_detach (args
, from_tty
);
2037 error ("Not confirmed.");
2041 if (query ("The program is running. Quit anyway (and kill it)? "))
2044 error ("Not confirmed.");
2047 /* Save the history information if it is appropriate to do so. */
2048 if (write_history_p
&& history_filename
)
2049 write_history (history_filename
);
2053 /* Returns whether GDB is running on a terminal and whether the user
2054 desires that questions be asked of them on that terminal. */
2057 input_from_terminal_p ()
2059 return gdb_has_a_terminal
&& (instream
== stdin
) & caution
;
2064 pwd_command (args
, from_tty
)
2068 if (args
) error ("The \"pwd\" command does not take an argument: %s", args
);
2069 getcwd (dirbuf
, sizeof (dirbuf
));
2071 if (!STREQ (dirbuf
, current_directory
))
2072 printf ("Working directory %s\n (canonically %s).\n",
2073 current_directory
, dirbuf
);
2075 printf ("Working directory %s.\n", current_directory
);
2079 cd_command (dir
, from_tty
)
2086 /* If the new directory is absolute, repeat is a no-op; if relative,
2087 repeat might be useful but is more likely to be a mistake. */
2091 error_no_arg ("new working directory");
2093 dir
= tilde_expand (dir
);
2094 make_cleanup (free
, dir
);
2096 if (chdir (dir
) < 0)
2097 perror_with_name (dir
);
2100 dir
= savestring (dir
, len
- (len
> 1 && dir
[len
-1] == '/'));
2102 current_directory
= dir
;
2105 current_directory
= concat (current_directory
, "/", dir
, NULL
);
2109 /* Now simplify any occurrences of `.' and `..' in the pathname. */
2117 for (p
= current_directory
; *p
;)
2119 if (!strncmp (p
, "/./", 2)
2120 && (p
[2] == 0 || p
[2] == '/'))
2122 else if (!strncmp (p
, "/..", 3)
2123 && (p
[3] == 0 || p
[3] == '/')
2124 && p
!= current_directory
)
2127 while (q
!= current_directory
&& q
[-1] != '/') q
--;
2128 if (q
!= current_directory
)
2138 forget_cached_source_info ();
2141 pwd_command ((char *) 0, 1);
2146 source_command (args
, from_tty
)
2151 struct cleanup
*cleanups
;
2156 error ("source command requires pathname of file to source.");
2159 file
= tilde_expand (file
);
2160 make_cleanup (free
, file
);
2162 stream
= fopen (file
, FOPEN_RT
);
2164 perror_with_name (file
);
2166 cleanups
= make_cleanup (fclose
, stream
);
2168 read_command_file (stream
);
2170 do_cleanups (cleanups
);
2175 echo_command (text
, from_tty
)
2183 while ((c
= *p
++) != '\0')
2187 /* \ at end of argument is used after spaces
2188 so they won't be lost. */
2192 c
= parse_escape (&p
);
2194 printf_filtered ("%c", c
);
2197 printf_filtered ("%c", c
);
2200 /* Force this output to appear now. */
2206 /* Functions to manipulate command line editing control variables. */
2208 /* Number of commands to print in each call to show_commands. */
2209 #define Hist_print 10
2211 show_commands (args
, from_tty
)
2215 /* Index for history commands. Relative to history_base. */
2218 /* Number of the history entry which we are planning to display next.
2219 Relative to history_base. */
2222 /* The first command in the history which doesn't exist (i.e. one more
2223 than the number of the last command). Relative to history_base. */
2226 extern struct _hist_entry
*history_get
PARAMS ((int));
2227 extern int history_base
;
2229 /* Print out some of the commands from the command history. */
2230 /* First determine the length of the history list. */
2231 hist_len
= history_size
;
2232 for (offset
= 0; offset
< history_size
; offset
++)
2234 if (!history_get (history_base
+ offset
))
2243 if (args
[0] == '+' && args
[1] == '\0')
2244 /* "info editing +" should print from the stored position. */
2247 /* "info editing <exp>" should print around command number <exp>. */
2248 num
= (parse_and_eval_address (args
) - history_base
) - Hist_print
/ 2;
2250 /* "show commands" means print the last Hist_print commands. */
2253 num
= hist_len
- Hist_print
;
2259 /* If there are at least Hist_print commands, we want to display the last
2260 Hist_print rather than, say, the last 6. */
2261 if (hist_len
- num
< Hist_print
)
2263 num
= hist_len
- Hist_print
;
2268 for (offset
= num
; offset
< num
+ Hist_print
&& offset
< hist_len
; offset
++)
2270 printf_filtered ("%5d %s\n", history_base
+ offset
,
2271 (history_get (history_base
+ offset
))->line
);
2274 /* The next command we want to display is the next one that we haven't
2278 /* If the user repeats this command with return, it should do what
2279 "show commands +" does. This is unnecessary if arg is null,
2280 because "show commands +" is not useful after "show commands". */
2281 if (from_tty
&& args
)
2288 /* Called by do_setshow_command. */
2291 set_history_size_command (args
, from_tty
, c
)
2294 struct cmd_list_element
*c
;
2296 if (history_size
== INT_MAX
)
2297 unstifle_history ();
2298 else if (history_size
>= 0)
2299 stifle_history (history_size
);
2302 history_size
= INT_MAX
;
2303 error ("History size must be non-negative");
2309 set_history (args
, from_tty
)
2313 printf ("\"set history\" must be followed by the name of a history subcommand.\n");
2314 help_list (sethistlist
, "set history ", -1, stdout
);
2319 show_history (args
, from_tty
)
2323 cmd_show_list (showhistlist
, from_tty
, "");
2326 int info_verbose
= 0; /* Default verbose msgs off */
2328 /* Called by do_setshow_command. An elaborate joke. */
2331 set_verbose (args
, from_tty
, c
)
2334 struct cmd_list_element
*c
;
2336 char *cmdname
= "verbose";
2337 struct cmd_list_element
*showcmd
;
2339 showcmd
= lookup_cmd_1 (&cmdname
, showlist
, NULL
, 1);
2343 c
->doc
= "Set verbose printing of informational messages.";
2344 showcmd
->doc
= "Show verbose printing of informational messages.";
2348 c
->doc
= "Set verbosity.";
2349 showcmd
->doc
= "Show verbosity.";
2354 float_handler (signo
)
2357 /* This message is based on ANSI C, section 4.7. Note that integer
2358 divide by zero causes this, so "float" is a misnomer. */
2359 signal (SIGFPE
, float_handler
);
2360 error ("Erroneous arithmetic operation.");
2363 /* Return whether we are running a batch file or from terminal. */
2367 return !(instream
== stdin
&& ISATTY (stdin
));
2379 enablebreaklist
= NULL
;
2384 showhistlist
= NULL
;
2385 unsethistlist
= NULL
;
2386 #if MAINTENANCE_CMDS
2387 maintenancelist
= NULL
;
2388 maintenanceinfolist
= NULL
;
2389 maintenanceprintlist
= NULL
;
2391 setprintlist
= NULL
;
2392 showprintlist
= NULL
;
2393 setchecklist
= NULL
;
2394 showchecklist
= NULL
;
2397 /* Init the history buffer. Note that we are called after the init file(s)
2398 * have been read so that the user can change the history file via his
2399 * .gdbinit file (for instance). The GDBHISTFILE environment variable
2400 * overrides all of this.
2408 tmpenv
= getenv ("HISTSIZE");
2410 history_size
= atoi (tmpenv
);
2411 else if (!history_size
)
2414 stifle_history (history_size
);
2416 tmpenv
= getenv ("GDBHISTFILE");
2418 history_filename
= savestring (tmpenv
, strlen(tmpenv
));
2419 else if (!history_filename
) {
2420 /* We include the current directory so that if the user changes
2421 directories the file written will be the same as the one
2423 history_filename
= concat (current_directory
, "/.gdb_history", NULL
);
2425 read_history (history_filename
);
2431 struct cmd_list_element
*c
;
2433 #ifdef DEFAULT_PROMPT
2434 prompt
= savestring (DEFAULT_PROMPT
, strlen(DEFAULT_PROMPT
));
2436 prompt
= savestring ("(gdb) ", 6);
2439 /* Set the important stuff up for command editing. */
2440 command_editing_p
= 1;
2441 history_expansion_p
= 0;
2442 write_history_p
= 0;
2444 /* Setup important stuff for command line editing. */
2445 rl_completion_entry_function
= (int (*)()) symbol_completion_function
;
2446 rl_completer_word_break_characters
= gdb_completer_word_break_characters
;
2447 rl_completer_quote_characters
= gdb_completer_quote_characters
;
2448 rl_readline_name
= "gdb";
2450 /* Define the classes of commands.
2451 They will appear in the help list in the reverse of this order. */
2453 add_cmd ("internals", class_maintenance
, NO_FUNCTION
,
2454 "Maintenance commands.\n\
2455 Some gdb commands are provided just for use by gdb maintainers.\n\
2456 These commands are subject to frequent change, and may not be as\n\
2457 well documented as user commands.",
2459 add_cmd ("obscure", class_obscure
, NO_FUNCTION
, "Obscure features.", &cmdlist
);
2460 add_cmd ("aliases", class_alias
, NO_FUNCTION
, "Aliases of other commands.", &cmdlist
);
2461 add_cmd ("user-defined", class_user
, NO_FUNCTION
, "User-defined commands.\n\
2462 The commands in this class are those defined by the user.\n\
2463 Use the \"define\" command to define a command.", &cmdlist
);
2464 add_cmd ("support", class_support
, NO_FUNCTION
, "Support facilities.", &cmdlist
);
2465 add_cmd ("status", class_info
, NO_FUNCTION
, "Status inquiries.", &cmdlist
);
2466 add_cmd ("files", class_files
, NO_FUNCTION
, "Specifying and examining files.", &cmdlist
);
2467 add_cmd ("breakpoints", class_breakpoint
, NO_FUNCTION
, "Making program stop at certain points.", &cmdlist
);
2468 add_cmd ("data", class_vars
, NO_FUNCTION
, "Examining data.", &cmdlist
);
2469 add_cmd ("stack", class_stack
, NO_FUNCTION
, "Examining the stack.\n\
2470 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
2471 counting from zero for the innermost (currently executing) frame.\n\n\
2472 At any time gdb identifies one frame as the \"selected\" frame.\n\
2473 Variable lookups are done with respect to the selected frame.\n\
2474 When the program being debugged stops, gdb selects the innermost frame.\n\
2475 The commands below can be used to select other frames by number or address.",
2477 add_cmd ("running", class_run
, NO_FUNCTION
, "Running the program.", &cmdlist
);
2479 add_com ("pwd", class_files
, pwd_command
,
2480 "Print working directory. This is used for your program as well.");
2481 c
= add_cmd ("cd", class_files
, cd_command
,
2482 "Set working directory to DIR for debugger and program being debugged.\n\
2483 The change does not take effect for the program being debugged\n\
2484 until the next time it is started.", &cmdlist
);
2485 c
->completer
= filename_completer
;
2488 (add_set_cmd ("prompt", class_support
, var_string
, (char *)&prompt
,
2493 add_com ("echo", class_support
, echo_command
,
2494 "Print a constant string. Give string as argument.\n\
2495 C escape sequences may be used in the argument.\n\
2496 No newline is added at the end of the argument;\n\
2497 use \"\\n\" if you want a newline to be printed.\n\
2498 Since leading and trailing whitespace are ignored in command arguments,\n\
2499 if you want to print some you must use \"\\\" before leading whitespace\n\
2500 to be printed or after trailing whitespace.");
2501 add_com ("document", class_support
, document_command
,
2502 "Document a user-defined command.\n\
2503 Give command name as argument. Give documentation on following lines.\n\
2504 End with a line of just \"end\".");
2505 add_com ("define", class_support
, define_command
,
2506 "Define a new command name. Command name is argument.\n\
2507 Definition appears on following lines, one command per line.\n\
2508 End with a line of just \"end\".\n\
2509 Use the \"document\" command to give documentation for the new command.\n\
2510 Commands defined in this way do not take arguments.");
2513 c
= add_cmd ("source", class_support
, source_command
,
2514 "Read commands from a file named FILE.\n\
2515 Note that the file \"" GDBINIT_FILENAME
"\" is read automatically in this way\n\
2516 when gdb is started.", &cmdlist
);
2518 /* Punt file name, we can't help it easily. */
2519 c
= add_cmd ("source", class_support
, source_command
,
2520 "Read commands from a file named FILE.\n\
2521 Note that the file \".gdbinit\" is read automatically in this way\n\
2522 when gdb is started.", &cmdlist
);
2524 c
->completer
= filename_completer
;
2526 add_com ("quit", class_support
, quit_command
, "Exit gdb.");
2527 add_com ("help", class_support
, help_command
, "Print list of commands.");
2528 add_com_alias ("q", "quit", class_support
, 1);
2529 add_com_alias ("h", "help", class_support
, 1);
2532 c
= add_set_cmd ("verbose", class_support
, var_boolean
, (char *)&info_verbose
,
2535 add_show_from_set (c
, &showlist
);
2536 c
->function
.sfunc
= set_verbose
;
2537 set_verbose (NULL
, 0, c
);
2540 (add_set_cmd ("editing", class_support
, var_boolean
, (char *)&command_editing_p
,
2541 "Set editing of command lines as they are typed.\n\
2542 Use \"on\" to enable to enable the editing, and \"off\" to disable it.\n\
2543 Without an argument, command line editing is enabled. To edit, use\n\
2544 EMACS-like or VI-like commands like control-P or ESC.", &setlist
),
2547 add_prefix_cmd ("history", class_support
, set_history
,
2548 "Generic command for setting command history parameters.",
2549 &sethistlist
, "set history ", 0, &setlist
);
2550 add_prefix_cmd ("history", class_support
, show_history
,
2551 "Generic command for showing command history parameters.",
2552 &showhistlist
, "show history ", 0, &showlist
);
2555 (add_set_cmd ("expansion", no_class
, var_boolean
, (char *)&history_expansion_p
,
2556 "Set history expansion on command input.\n\
2557 Without an argument, history expansion is enabled.", &sethistlist
),
2561 (add_set_cmd ("save", no_class
, var_boolean
, (char *)&write_history_p
,
2562 "Set saving of the history record on exit.\n\
2563 Use \"on\" to enable to enable the saving, and \"off\" to disable it.\n\
2564 Without an argument, saving is enabled.", &sethistlist
),
2567 c
= add_set_cmd ("size", no_class
, var_integer
, (char *)&history_size
,
2568 "Set the size of the command history, \n\
2569 ie. the number of previous commands to keep a record of.", &sethistlist
);
2570 add_show_from_set (c
, &showhistlist
);
2571 c
->function
.sfunc
= set_history_size_command
;
2574 (add_set_cmd ("filename", no_class
, var_filename
, (char *)&history_filename
,
2575 "Set the filename in which to record the command history\n\
2576 (the list of previous commands of which a record is kept).", &sethistlist
),
2580 (add_set_cmd ("confirm", class_support
, var_boolean
,
2582 "Set whether to confirm potentially dangerous operations.",
2586 add_prefix_cmd ("info", class_info
, info_command
,
2587 "Generic command for showing things about the program being debugged.",
2588 &infolist
, "info ", 0, &cmdlist
);
2589 add_com_alias ("i", "info", class_info
, 1);
2591 add_prefix_cmd ("show", class_info
, show_command
,
2592 "Generic command for showing things about the debugger.",
2593 &showlist
, "show ", 0, &cmdlist
);
2594 /* Another way to get at the same thing. */
2595 add_info ("set", show_command
, "Show all GDB settings.");
2597 add_cmd ("commands", no_class
, show_commands
,
2598 "Show the the history of commands you typed.\n\
2599 You can supply a command number to start with, or a `+' to start after\n\
2600 the previous command number shown.",
2603 add_cmd ("version", no_class
, show_version
,
2604 "Show what version of GDB this is.", &showlist
);