1 /* Top level stuff for GDB, the GNU debugger.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 1997
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "call-cmds.h"
28 #include "breakpoint.h"
30 #include "expression.h"
33 #include "terminal.h" /* For job_control. */
38 /* readline include files */
42 /* readline defines this. */
45 #include <sys/types.h>
50 #include "gdb_string.h"
54 extern void initialize_utils PARAMS ((void));
56 /* Prototypes for local functions */
58 static void dont_repeat_command PARAMS ((char *, int));
60 static void source_cleanup_lines PARAMS ((PTR));
62 static void user_defined_command PARAMS ((char *, int));
64 static void init_signals PARAMS ((void));
67 static void stop_sig PARAMS ((int));
70 static void disconnect PARAMS ((int));
72 static char * line_completion_function PARAMS ((char *, int, char *, int));
74 static char * readline_line_completion_function PARAMS ((char *, int));
76 static void command_loop_marker PARAMS ((int));
78 static void while_command PARAMS ((char *, int));
80 static void if_command PARAMS ((char *, int));
82 static struct command_line *
83 build_command_line PARAMS ((enum command_control_type, char *));
85 static struct command_line *
86 get_command_line PARAMS ((enum command_control_type, char *));
88 static void realloc_body_list PARAMS ((struct command_line *, int));
90 static enum misc_command_type read_next_line PARAMS ((struct command_line **));
92 static enum command_control_type
93 recurse_read_control_structure PARAMS ((struct command_line *));
95 static struct cleanup * setup_user_args PARAMS ((char *));
97 static char * locate_arg PARAMS ((char *));
99 static char * insert_args PARAMS ((char *));
101 static void arg_cleanup PARAMS ((void));
103 static void init_main PARAMS ((void));
105 static void init_cmd_lists PARAMS ((void));
107 static void float_handler PARAMS ((int));
109 static void init_signals PARAMS ((void));
111 static void set_verbose PARAMS ((char *, int, struct cmd_list_element *));
113 #ifdef TARGET_BYTE_ORDER_SELECTABLE
115 static void set_endian PARAMS ((char *, int));
117 static void set_endian_big PARAMS ((char *, int));
119 static void set_endian_little PARAMS ((char *, int));
121 static void set_endian_auto PARAMS ((char *, int));
123 static void show_endian PARAMS ((char *, int));
127 static void show_history PARAMS ((char *, int));
129 static void set_history PARAMS ((char *, int));
131 static void set_history_size_command PARAMS ((char *, int,
132 struct cmd_list_element *));
134 static void show_commands PARAMS ((char *, int));
136 static void echo_command PARAMS ((char *, int));
138 static void pwd_command PARAMS ((char *, int));
140 static void show_version PARAMS ((char *, int));
142 static void document_command PARAMS ((char *, int));
144 static void define_command PARAMS ((char *, int));
146 static void validate_comname PARAMS ((char *));
148 static void help_command PARAMS ((char *, int));
150 static void show_command PARAMS ((char *, int));
152 static void info_command PARAMS ((char *, int));
154 static void complete_command PARAMS ((char *, int));
156 static void do_nothing PARAMS ((int));
158 static int quit_cover PARAMS ((char *));
160 static void disconnect PARAMS ((int));
162 static void source_cleanup PARAMS ((FILE *));
164 /* If this definition isn't overridden by the header files, assume
165 that isatty and fileno exist on this system. */
167 #define ISATTY(FP) (isatty (fileno (FP)))
170 /* Initialization file name for gdb. This is overridden in some configs. */
172 #ifndef GDBINIT_FILENAME
173 #define GDBINIT_FILENAME ".gdbinit"
175 char gdbinit[] = GDBINIT_FILENAME;
177 int inhibit_gdbinit = 0;
179 /* If nonzero, and GDB has been configured to be able to use windows,
180 attempt to open them upon startup. */
184 /* Version number of GDB, as a string. */
186 extern char *version;
188 /* Canonical host name as a string. */
190 extern char *host_name;
192 /* Canonical target name as a string. */
194 extern char *target_name;
196 extern char lang_frame_mismatch_warn[]; /* language.c */
198 /* Flag for whether we want all the "from_tty" gubbish printed. */
200 int caution = 1; /* Default is yes, sigh. */
202 /* Define all cmd_list_elements. */
204 /* Chain containing all defined commands. */
206 struct cmd_list_element *cmdlist;
208 /* Chain containing all defined info subcommands. */
210 struct cmd_list_element *infolist;
212 /* Chain containing all defined enable subcommands. */
214 struct cmd_list_element *enablelist;
216 /* Chain containing all defined disable subcommands. */
218 struct cmd_list_element *disablelist;
220 /* Chain containing all defined delete subcommands. */
222 struct cmd_list_element *deletelist;
224 /* Chain containing all defined "enable breakpoint" subcommands. */
226 struct cmd_list_element *enablebreaklist;
228 /* Chain containing all defined set subcommands */
230 struct cmd_list_element *setlist;
232 /* Chain containing all defined unset subcommands */
234 struct cmd_list_element *unsetlist;
236 /* Chain containing all defined show subcommands. */
238 struct cmd_list_element *showlist;
240 #ifdef TARGET_BYTE_ORDER_SELECTABLE
241 /* Chain containing the \"set endian\" commands. */
243 struct cmd_list_element *endianlist;
246 /* Chain containing all defined \"set history\". */
248 struct cmd_list_element *sethistlist;
250 /* Chain containing all defined \"show history\". */
252 struct cmd_list_element *showhistlist;
254 /* Chain containing all defined \"unset history\". */
256 struct cmd_list_element *unsethistlist;
258 /* Chain containing all defined maintenance subcommands. */
261 struct cmd_list_element *maintenancelist;
264 /* Chain containing all defined "maintenance info" subcommands. */
267 struct cmd_list_element *maintenanceinfolist;
270 /* Chain containing all defined "maintenance print" subcommands. */
273 struct cmd_list_element *maintenanceprintlist;
276 struct cmd_list_element *setprintlist;
278 struct cmd_list_element *showprintlist;
280 struct cmd_list_element *setchecklist;
282 struct cmd_list_element *showchecklist;
284 /* stdio stream that command input is being read from. Set to stdin normally.
285 Set by source_command to the file we are sourcing. Set to NULL if we are
286 executing a user-defined command or interacting via a GUI. */
290 /* Current working directory. */
292 char *current_directory;
294 /* The directory name is actually stored here (usually). */
295 char gdb_dirbuf[1024];
297 /* Function to call before reading a command, if nonzero.
298 The function receives two args: an input stream,
299 and a prompt string. */
301 void (*window_hook) PARAMS ((FILE *, char *));
306 /* gdb prints this when reading a command interactively */
309 /* Buffer used for reading command lines, and the size
310 allocated for it so far. */
315 /* Nonzero if the current command is modified by "server ". This
316 affects things like recording into the command history, comamnds
317 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
318 whatever) can issue its own commands and also send along commands
319 from the user, and have the user not notice that the user interface
320 is issuing commands too. */
323 /* Baud rate specified for talking to serial target systems. Default
324 is left as -1, so targets can choose their own defaults. */
325 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
326 or (unsigned int)-1. This is a Bad User Interface. */
330 /* Timeout limit for response from target. */
332 int remote_timeout = 20; /* Set default to 20 */
334 /* Non-zero tells remote* modules to output debugging info. */
336 int remote_debug = 0;
338 /* Level of control structure. */
339 static int control_level;
341 /* Structure for arguments to user defined functions. */
342 #define MAXUSERARGS 10
345 struct user_args *next;
354 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
358 #define STOP_SIGNAL SIGTSTP
359 static void stop_sig PARAMS ((int));
363 /* Some System V have job control but not sigsetmask(). */
364 #if !defined (HAVE_SIGSETMASK)
366 #define HAVE_SIGSETMASK 1
368 #define HAVE_SIGSETMASK 0
372 #if 0 == (HAVE_SIGSETMASK)
373 #define sigsetmask(n)
376 /* Hooks for alternate command interfaces. */
378 /* Called after most modules have been initialized, but before taking users
381 void (*init_ui_hook) PARAMS ((void));
383 /* Called instead of command_loop at top level. Can be invoked via
384 return_to_top_level. */
386 void (*command_loop_hook) PARAMS ((void));
389 /* Called instead of fputs for all output. */
391 void (*fputs_unfiltered_hook) PARAMS ((const char *linebuffer, FILE *stream));
393 /* Called when the target says something to the host, which may
394 want to appear in a different window. */
396 void (*target_output_hook) PARAMS ((char *));
398 /* Called from print_frame_info to list the line we stopped in. */
400 void (*print_frame_info_listing_hook) PARAMS ((struct symtab *s, int line,
401 int stopline, int noerror));
402 /* Replaces most of query. */
404 int (*query_hook) PARAMS ((const char *, va_list));
406 /* Called from gdb_flush to flush output. */
408 void (*flush_hook) PARAMS ((FILE *stream));
410 /* These three functions support getting lines of text from the user. They
411 are used in sequence. First readline_begin_hook is called with a text
412 string that might be (for example) a message for the user to type in a
413 sequence of commands to be executed at a breakpoint. If this function
414 calls back to a GUI, it might take this opportunity to pop up a text
415 interaction window with this message. Next, readline_hook is called
416 with a prompt that is emitted prior to collecting the user input.
417 It can be called multiple times. Finally, readline_end_hook is called
418 to notify the GUI that we are done with the interaction window and it
421 void (*readline_begin_hook) PARAMS ((char *, ...));
422 char * (*readline_hook) PARAMS ((char *));
423 void (*readline_end_hook) PARAMS ((void));
425 /* Called as appropriate to notify the interface of the specified breakpoint
428 void (*create_breakpoint_hook) PARAMS ((struct breakpoint *bpt));
429 void (*delete_breakpoint_hook) PARAMS ((struct breakpoint *bpt));
430 void (*modify_breakpoint_hook) PARAMS ((struct breakpoint *bpt));
432 /* Called during long calculations to allow GUI to repair window damage, and to
433 check for stop buttons, etc... */
435 void (*interactive_hook) PARAMS ((void));
437 /* Called when the registers have changed, as a hint to a GUI
438 to minimize window update. */
440 void (*registers_changed_hook) PARAMS ((void));
442 /* Called when going to wait for the target. Usually allows the GUI to run
443 while waiting for target events. */
445 int (*target_wait_hook) PARAMS ((int pid, struct target_waitstatus *status));
447 /* Used by UI as a wrapper around command execution. May do various things
448 like enabling/disabling buttons, etc... */
450 void (*call_command_hook) PARAMS ((struct cmd_list_element *c, char *cmd,
454 /* Takes control from error (). Typically used to prevent longjmps out of the
455 middle of the GUI. Usually used in conjunction with a catch routine. */
457 NORETURN void (*error_hook) PARAMS ((void)) ATTR_NORETURN;
460 /* Where to go for return_to_top_level (RETURN_ERROR). */
461 jmp_buf error_return;
462 /* Where to go for return_to_top_level (RETURN_QUIT). */
465 /* Return for reason REASON. This generally gets back to the command
466 loop, but can be caught via catch_errors. */
469 return_to_top_level (reason)
470 enum return_reason reason;
475 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
476 I can think of a reason why that is vital, though). */
477 bpstat_clear_actions(stop_bpstat); /* Clear queued breakpoint commands */
479 disable_current_display ();
480 do_cleanups (ALL_CLEANUPS);
482 if (annotation_level > 1)
493 (NORETURN void) longjmp
494 (reason == RETURN_ERROR ? error_return : quit_return, 1);
497 /* Call FUNC with arg ARGS, catching any errors. If there is no
498 error, return the value returned by FUNC. If there is an error,
499 print ERRSTRING, print the specific error message, then return
502 Must not be called with immediate_quit in effect (bad things might
503 happen, say we got a signal in the middle of a memcpy to quit_return).
504 This is an OK restriction; with very few exceptions immediate_quit can
505 be replaced by judicious use of QUIT.
507 MASK specifies what to catch; it is normally set to
508 RETURN_MASK_ALL, if for no other reason than that the code which
509 calls catch_errors might not be set up to deal with a quit which
510 isn't caught. But if the code can deal with it, it generally
511 should be RETURN_MASK_ERROR, unless for some reason it is more
512 useful to abort only the portion of the operation inside the
513 catch_errors. Note that quit should return to the command line
514 fairly quickly, even if some further processing is being done. */
517 catch_errors (func, args, errstring, mask)
518 int (*func) PARAMS ((char *));
527 struct cleanup *saved_cleanup_chain;
528 char *saved_error_pre_print;
529 char *saved_quit_pre_print;
531 saved_cleanup_chain = save_cleanups ();
532 saved_error_pre_print = error_pre_print;
533 saved_quit_pre_print = quit_pre_print;
535 if (mask & RETURN_MASK_ERROR)
537 memcpy ((char *)saved_error, (char *)error_return, sizeof (jmp_buf));
538 error_pre_print = errstring;
540 if (mask & RETURN_MASK_QUIT)
542 memcpy (saved_quit, quit_return, sizeof (jmp_buf));
543 quit_pre_print = errstring;
546 if (setjmp (tmp_jmp) == 0)
548 if (mask & RETURN_MASK_ERROR)
549 memcpy (error_return, tmp_jmp, sizeof (jmp_buf));
550 if (mask & RETURN_MASK_QUIT)
551 memcpy (quit_return, tmp_jmp, sizeof (jmp_buf));
552 val = (*func) (args);
557 restore_cleanups (saved_cleanup_chain);
559 if (mask & RETURN_MASK_ERROR)
561 memcpy (error_return, saved_error, sizeof (jmp_buf));
562 error_pre_print = saved_error_pre_print;
564 if (mask & RETURN_MASK_QUIT)
566 memcpy (quit_return, saved_quit, sizeof (jmp_buf));
567 quit_pre_print = saved_quit_pre_print;
572 /* Handler for SIGHUP. */
578 catch_errors (quit_cover, NULL,
579 "Could not kill the program being debugged", RETURN_MASK_ALL);
580 signal (SIGHUP, SIG_DFL);
581 kill (getpid (), SIGHUP);
584 /* Just a little helper function for disconnect(). */
590 caution = 0; /* Throw caution to the wind -- we're exiting.
591 This prevents asking the user dumb questions. */
592 quit_command((char *)0, 0);
596 /* Line number we are currently in in a file which is being sourced. */
597 static int source_line_number;
599 /* Name of the file we are sourcing. */
600 static char *source_file_name;
602 /* Buffer containing the error_pre_print used by the source stuff.
604 static char *source_error;
605 static int source_error_allocated;
607 /* Something to glom on to the start of error_pre_print if source_file_name
609 static char *source_pre_error;
611 /* Clean up on error during a "source" command (or execution of a
612 user-defined command). */
615 source_cleanup (stream)
618 /* Restore the previous input stream. */
622 /* Read commands from STREAM. */
624 read_command_file (stream)
627 struct cleanup *cleanups;
629 cleanups = make_cleanup (source_cleanup, instream);
632 do_cleanups (cleanups);
635 extern void init_proc PARAMS ((void));
637 void (*pre_init_ui_hook) PARAMS ((void));
642 if (pre_init_ui_hook)
645 /* Run the init function of each source file */
647 getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
648 current_directory = gdb_dirbuf;
650 init_cmd_lists (); /* This needs to be done first */
651 initialize_targets (); /* Setup target_terminal macros for utils.c */
652 initialize_utils (); /* Make errors and warnings possible */
653 initialize_all_files ();
654 init_main (); /* But that omits this file! Do it now */
659 /* We need a default language for parsing expressions, so simple things like
660 "set width 0" won't fail if no language is explicitly set in a config file
661 or implicitly set by reading an executable during startup. */
662 set_language (language_c);
663 expected_language = current_language; /* don't warn about the change. */
669 /* Allocate, initialize a new command line structure for one of the
670 control commands (if/while). */
672 static struct command_line *
673 build_command_line (type, args)
674 enum command_control_type type;
677 struct command_line *cmd;
680 error ("if/while commands require arguments.\n");
682 cmd = (struct command_line *)xmalloc (sizeof (struct command_line));
684 cmd->control_type = type;
688 = (struct command_line **)xmalloc (sizeof (struct command_line *)
690 memset (cmd->body_list, 0, sizeof (struct command_line *) * cmd->body_count);
691 cmd->line = savestring (args, strlen (args));
695 /* Build and return a new command structure for the control commands
696 such as "if" and "while". */
698 static struct command_line *
699 get_command_line (type, arg)
700 enum command_control_type type;
703 struct command_line *cmd;
704 struct cleanup *old_chain = NULL;
706 /* Allocate and build a new command line structure. */
707 cmd = build_command_line (type, arg);
709 old_chain = make_cleanup (free_command_lines, &cmd);
711 /* Read in the body of this command. */
712 if (recurse_read_control_structure (cmd) == invalid_control)
714 warning ("error reading in control structure\n");
715 do_cleanups (old_chain);
719 discard_cleanups (old_chain);
723 /* Recursively print a command (including full control structures). */
725 print_command_line (cmd, depth)
726 struct command_line *cmd;
733 for (i = 0; i < depth; i++)
734 fputs_filtered (" ", gdb_stdout);
737 /* A simple command, print it and return. */
738 if (cmd->control_type == simple_control)
740 fputs_filtered (cmd->line, gdb_stdout);
741 fputs_filtered ("\n", gdb_stdout);
745 /* loop_continue to jump to the start of a while loop, print it
747 if (cmd->control_type == continue_control)
749 fputs_filtered ("loop_continue\n", gdb_stdout);
753 /* loop_break to break out of a while loop, print it and return. */
754 if (cmd->control_type == break_control)
756 fputs_filtered ("loop_break\n", gdb_stdout);
760 /* A while command. Recursively print its subcommands before returning. */
761 if (cmd->control_type == while_control)
763 struct command_line *list;
764 fputs_filtered ("while ", gdb_stdout);
765 fputs_filtered (cmd->line, gdb_stdout);
766 fputs_filtered ("\n", gdb_stdout);
767 list = *cmd->body_list;
770 print_command_line (list, depth + 1);
775 /* An if command. Recursively print both arms before returning. */
776 if (cmd->control_type == if_control)
778 fputs_filtered ("if ", gdb_stdout);
779 fputs_filtered (cmd->line, gdb_stdout);
780 fputs_filtered ("\n", gdb_stdout);
782 print_command_line (cmd->body_list[0], depth + 1);
784 /* Show the false arm if it exists. */
785 if (cmd->body_count == 2)
789 for (i = 0; i < depth; i++)
790 fputs_filtered (" ", gdb_stdout);
792 fputs_filtered ("else\n", gdb_stdout);
793 print_command_line (cmd->body_list[1], depth + 1);
797 for (i = 0; i < depth; i++)
798 fputs_filtered (" ", gdb_stdout);
800 fputs_filtered ("end\n", gdb_stdout);
804 /* Execute the command in CMD. */
806 enum command_control_type
807 execute_control_command (cmd)
808 struct command_line *cmd;
810 struct expression *expr;
811 struct command_line *current;
812 struct cleanup *old_chain = 0;
816 enum command_control_type ret;
819 switch (cmd->control_type)
822 /* A simple command, execute it and return. */
823 new_line = insert_args (cmd->line);
825 return invalid_control;
826 old_chain = make_cleanup (free_current_contents, &new_line);
827 execute_command (new_line, 0);
828 ret = cmd->control_type;
831 case continue_control:
833 /* Return for "continue", and "break" so we can either
834 continue the loop at the top, or break out. */
835 ret = cmd->control_type;
840 /* Parse the loop control expression for the while statement. */
841 new_line = insert_args (cmd->line);
843 return invalid_control;
844 old_chain = make_cleanup (free_current_contents, &new_line);
845 expr = parse_expression (new_line);
846 make_cleanup (free_current_contents, &expr);
848 ret = simple_control;
851 /* Keep iterating so long as the expression is true. */
858 /* Evaluate the expression. */
859 val_mark = value_mark ();
860 val = evaluate_expression (expr);
861 cond_result = value_true (val);
862 value_free_to_mark (val_mark);
864 /* If the value is false, then break out of the loop. */
868 /* Execute the body of the while statement. */
869 current = *cmd->body_list;
872 ret = execute_control_command (current);
874 /* If we got an error, or a "break" command, then stop
876 if (ret == invalid_control || ret == break_control)
882 /* If we got a "continue" command, then restart the loop
884 if (ret == continue_control)
887 /* Get the next statement. */
888 current = current->next;
892 /* Reset RET so that we don't recurse the break all the way down. */
893 if (ret == break_control)
894 ret = simple_control;
901 new_line = insert_args (cmd->line);
903 return invalid_control;
904 old_chain = make_cleanup (free_current_contents, &new_line);
905 /* Parse the conditional for the if statement. */
906 expr = parse_expression (new_line);
907 make_cleanup (free_current_contents, &expr);
910 ret = simple_control;
912 /* Evaluate the conditional. */
913 val_mark = value_mark ();
914 val = evaluate_expression (expr);
916 /* Choose which arm to take commands from based on the value of the
917 conditional expression. */
918 if (value_true (val))
919 current = *cmd->body_list;
920 else if (cmd->body_count == 2)
921 current = *(cmd->body_list + 1);
922 value_free_to_mark (val_mark);
924 /* Execute commands in the given arm. */
927 ret = execute_control_command (current);
929 /* If we got an error, get out. */
930 if (ret != simple_control)
933 /* Get the next statement in the body. */
934 current = current->next;
941 warning ("Invalid control type in command structure.");
942 return invalid_control;
946 do_cleanups (old_chain);
951 /* "while" command support. Executes a body of statements while the
952 loop condition is nonzero. */
955 while_command (arg, from_tty)
959 struct command_line *command = NULL;
962 command = get_command_line (while_control, arg);
967 execute_control_command (command);
968 free_command_lines (&command);
971 /* "if" command support. Execute either the true or false arm depending
972 on the value of the if conditional. */
975 if_command (arg, from_tty)
979 struct command_line *command = NULL;
982 command = get_command_line (if_control, arg);
987 execute_control_command (command);
988 free_command_lines (&command);
995 struct user_args *oargs = user_args;
997 fatal ("Internal error, arg_cleanup called with no user args.\n");
999 user_args = user_args->next;
1003 /* Bind the incomming arguments for a user defined command to
1004 $arg0, $arg1 ... $argMAXUSERARGS. */
1006 static struct cleanup *
1010 struct user_args *args;
1011 struct cleanup *old_chain;
1012 unsigned int arg_count = 0;
1014 args = (struct user_args *)xmalloc (sizeof (struct user_args));
1015 memset (args, 0, sizeof (struct user_args));
1017 args->next = user_args;
1020 old_chain = make_cleanup (arg_cleanup, 0);
1032 if (arg_count >= MAXUSERARGS)
1034 error ("user defined function may only have %d arguments.\n",
1039 /* Strip whitespace. */
1040 while (*p == ' ' || *p == '\t')
1043 /* P now points to an argument. */
1045 user_args->a[arg_count].arg = p;
1047 /* Get to the end of this argument. */
1050 if (((*p == ' ' || *p == '\t')) && !squote && !dquote && !bsquote)
1056 else if (*p == '\\')
1079 user_args->a[arg_count].len = p - start_arg;
1086 /* Given character string P, return a point to the first argument ($arg),
1087 or NULL if P contains no arguments. */
1093 while ((p = strchr (p, '$')))
1095 if (strncmp (p, "$arg", 4) == 0 && isdigit (p[4]))
1102 /* Insert the user defined arguments stored in user_arg into the $arg
1103 arguments found in line, with the updated copy being placed into nline. */
1109 char *p, *save_line, *new_line;
1112 /* First we need to know how much memory to allocate for the new line. */
1115 while ((p = locate_arg (line)))
1120 if (i >= user_args->count)
1122 error ("Missing argument %d in user function.\n", i);
1125 len += user_args->a[i].len;
1129 /* Don't forget the tail. */
1130 len += strlen (line);
1132 /* Allocate space for the new line and fill it in. */
1133 new_line = (char *)xmalloc (len + 1);
1134 if (new_line == NULL)
1137 /* Restore pointer to beginning of old line. */
1140 /* Save pointer to beginning of new line. */
1141 save_line = new_line;
1143 while ((p = locate_arg (line)))
1147 memcpy (new_line, line, p - line);
1148 new_line += p - line;
1151 len = user_args->a[i].len;
1154 memcpy (new_line, user_args->a[i].arg, len);
1159 /* Don't forget the tail. */
1160 strcpy (new_line, line);
1162 /* Return a pointer to the beginning of the new line. */
1167 execute_user_command (c, args)
1168 struct cmd_list_element *c;
1171 register struct command_line *cmdlines;
1172 struct cleanup *old_chain;
1173 enum command_control_type ret;
1175 old_chain = setup_user_args (args);
1177 cmdlines = c->user_commands;
1182 /* Set the instream to 0, indicating execution of a
1183 user-defined function. */
1184 old_chain = make_cleanup (source_cleanup, instream);
1185 instream = (FILE *) 0;
1188 ret = execute_control_command (cmdlines);
1189 if (ret != simple_control && ret != break_control)
1191 warning ("Error in control structure.\n");
1194 cmdlines = cmdlines->next;
1196 do_cleanups (old_chain);
1199 /* Execute the line P as a command.
1200 Pass FROM_TTY as second argument to the defining function. */
1203 execute_command (p, from_tty)
1207 register struct cmd_list_element *c;
1208 register enum language flang;
1209 static int warned = 0;
1210 /* FIXME: These should really be in an appropriate header file */
1211 extern void serial_log_command PARAMS ((const char *));
1215 /* This can happen when command_line_input hits end of file. */
1219 serial_log_command (p);
1221 while (*p == ' ' || *p == '\t') p++;
1226 c = lookup_cmd (&p, cmdlist, "", 0, 1);
1227 /* Pass null arg rather than an empty one. */
1230 /* Clear off trailing whitespace, except for set and complete command. */
1231 if (arg && c->type != set_cmd && c->function.cfunc != complete_command)
1233 p = arg + strlen (arg) - 1;
1234 while (p >= arg && (*p == ' ' || *p == '\t'))
1239 /* If this command has been hooked, run the hook first. */
1241 execute_user_command (c->hook, (char *)0);
1243 if (c->class == class_user)
1244 execute_user_command (c, arg);
1245 else if (c->type == set_cmd || c->type == show_cmd)
1246 do_setshow_command (arg, from_tty & caution, c);
1247 else if (c->function.cfunc == NO_FUNCTION)
1248 error ("That is not a command, just a help topic.");
1249 else if (call_command_hook)
1250 call_command_hook (c, arg, from_tty & caution);
1252 (*c->function.cfunc) (arg, from_tty & caution);
1255 /* Tell the user if the language has changed (except first time). */
1256 if (current_language != expected_language)
1258 if (language_mode == language_mode_auto) {
1259 language_info (1); /* Print what changed. */
1264 /* Warn the user if the working language does not match the
1265 language of the current frame. Only warn the user if we are
1266 actually running the program, i.e. there is a stack. */
1267 /* FIXME: This should be cacheing the frame and only running when
1268 the frame changes. */
1270 if (target_has_stack)
1272 flang = get_frame_language ();
1274 && flang != language_unknown
1275 && flang != current_language->la_language)
1277 printf_filtered ("%s\n", lang_frame_mismatch_warn);
1285 command_loop_marker (foo)
1290 /* Read commands from `instream' and execute them
1291 until end of file or error reading instream. */
1296 struct cleanup *old_chain;
1298 int stdin_is_tty = ISATTY (stdin);
1299 long time_at_cmd_start;
1301 long space_at_cmd_start;
1303 extern int display_time;
1304 extern int display_space;
1306 while (instream && !feof (instream))
1308 if (window_hook && instream == stdin)
1309 (*window_hook) (instream, prompt);
1312 if (instream == stdin && stdin_is_tty)
1313 reinitialize_more_filter ();
1314 old_chain = make_cleanup (command_loop_marker, 0);
1315 command = command_line_input (instream == stdin ? prompt : (char *) NULL,
1316 instream == stdin, "prompt");
1320 time_at_cmd_start = get_run_time ();
1325 extern char **environ;
1326 char *lim = (char *) sbrk (0);
1328 space_at_cmd_start = (long) (lim - (char *) &environ);
1332 execute_command (command, instream == stdin);
1333 /* Do any commands attached to breakpoint we stopped at. */
1334 bpstat_do_actions (&stop_bpstat);
1335 do_cleanups (old_chain);
1339 long cmd_time = get_run_time () - time_at_cmd_start;
1341 printf_unfiltered ("Command execution time: %ld.%06ld\n",
1342 cmd_time / 1000000, cmd_time % 1000000);
1348 extern char **environ;
1349 char *lim = (char *) sbrk (0);
1350 long space_now = lim - (char *) &environ;
1351 long space_diff = space_now - space_at_cmd_start;
1353 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
1355 (space_diff >= 0 ? '+' : '-'),
1362 /* Commands call this if they do not want to be repeated by null lines. */
1370 /* If we aren't reading from standard input, we are saving the last
1371 thing read from stdin in line and don't want to delete it. Null lines
1372 won't repeat here in any case. */
1373 if (instream == stdin)
1377 /* Read a line from the stream "instream" without command line editing.
1379 It prints PRROMPT once at the start.
1380 Action is compatible with "readline", e.g. space for the result is
1381 malloc'd and should be freed by the caller.
1383 A NULL return means end of file. */
1385 gdb_readline (prrompt)
1390 int input_index = 0;
1391 int result_size = 80;
1395 /* Don't use a _filtered function here. It causes the assumed
1396 character position to be off, since the newline we read from
1397 the user is not accounted for. */
1398 fputs_unfiltered (prrompt, gdb_stdout);
1400 /* Move to a new line so the entered line doesn't have a prompt
1401 on the front of it. */
1402 fputs_unfiltered ("\n", gdb_stdout);
1404 gdb_flush (gdb_stdout);
1407 result = (char *) xmalloc (result_size);
1411 /* Read from stdin if we are executing a user defined command.
1412 This is the right thing for prompt_for_continue, at least. */
1413 c = fgetc (instream ? instream : stdin);
1417 if (input_index > 0)
1418 /* The last line does not end with a newline. Return it, and
1419 if we are called again fgetc will still return EOF and
1420 we'll return NULL then. */
1429 result[input_index++] = c;
1430 while (input_index >= result_size)
1433 result = (char *) xrealloc (result, result_size);
1437 result[input_index++] = '\0';
1441 /* Variables which control command line editing and history
1442 substitution. These variables are given default values at the end
1444 static int command_editing_p;
1445 static int history_expansion_p;
1446 static int write_history_p;
1447 static int history_size;
1448 static char *history_filename;
1450 /* readline uses the word breaks for two things:
1451 (1) In figuring out where to point the TEXT parameter to the
1452 rl_completion_entry_function. Since we don't use TEXT for much,
1453 it doesn't matter a lot what the word breaks are for this purpose, but
1454 it does affect how much stuff M-? lists.
1455 (2) If one of the matches contains a word break character, readline
1456 will quote it. That's why we switch between
1457 gdb_completer_word_break_characters and
1458 gdb_completer_command_word_break_characters. I'm not sure when
1459 we need this behavior (perhaps for funky characters in C++ symbols?). */
1461 /* Variables which are necessary for fancy command line editing. */
1462 char *gdb_completer_word_break_characters =
1463 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1465 /* When completing on command names, we remove '-' from the list of
1466 word break characters, since we use it in command names. If the
1467 readline library sees one in any of the current completion strings,
1468 it thinks that the string needs to be quoted and automatically supplies
1470 char *gdb_completer_command_word_break_characters =
1471 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1473 /* Characters that can be used to quote completion strings. Note that we
1474 can't include '"' because the gdb C parser treats such quoted sequences
1476 char *gdb_completer_quote_characters =
1479 /* Functions that are used as part of the fancy command line editing. */
1481 /* This can be used for functions which don't want to complete on symbols
1482 but don't want to complete on anything else either. */
1485 noop_completer (text, prefix)
1492 /* Complete on filenames. */
1494 filename_completer (text, word)
1498 /* From readline. */
1499 extern char *filename_completion_function PARAMS ((char *, int));
1500 int subsequent_name;
1502 int return_val_used;
1503 int return_val_alloced;
1505 return_val_used = 0;
1506 /* Small for testing. */
1507 return_val_alloced = 1;
1508 return_val = (char **) xmalloc (return_val_alloced * sizeof (char *));
1510 subsequent_name = 0;
1514 p = filename_completion_function (text, subsequent_name);
1515 if (return_val_used >= return_val_alloced)
1517 return_val_alloced *= 2;
1519 (char **) xrealloc (return_val,
1520 return_val_alloced * sizeof (char *));
1524 return_val[return_val_used++] = p;
1527 /* Like emacs, don't complete on old versions. Especially useful
1528 in the "source" command. */
1529 if (p[strlen (p) - 1] == '~')
1535 /* Return exactly p. */
1536 return_val[return_val_used++] = p;
1537 else if (word > text)
1539 /* Return some portion of p. */
1540 q = xmalloc (strlen (p) + 5);
1541 strcpy (q, p + (word - text));
1542 return_val[return_val_used++] = q;
1547 /* Return some of TEXT plus p. */
1548 q = xmalloc (strlen (p) + (text - word) + 5);
1549 strncpy (q, word, text - word);
1550 q[text - word] = '\0';
1552 return_val[return_val_used++] = q;
1556 subsequent_name = 1;
1559 /* There is no way to do this just long enough to affect quote inserting
1560 without also affecting the next completion. This should be fixed in
1562 /* Insure that readline does the right thing
1563 with respect to inserting quotes. */
1564 rl_completer_word_break_characters = "";
1569 /* Here are some useful test cases for completion. FIXME: These should
1570 be put in the test suite. They should be tested with both M-? and TAB.
1572 "show output-" "radix"
1573 "show output" "-radix"
1574 "p" ambiguous (commands starting with p--path, print, printf, etc.)
1575 "p " ambiguous (all symbols)
1576 "info t foo" no completions
1577 "info t " no completions
1578 "info t" ambiguous ("info target", "info terminal", etc.)
1579 "info ajksdlfk" no completions
1580 "info ajksdlfk " no completions
1582 "info " ambiguous (all info commands)
1583 "p \"a" no completions (string constant)
1584 "p 'a" ambiguous (all symbols starting with a)
1585 "p b-a" ambiguous (all symbols starting with a)
1586 "p b-" ambiguous (all symbols)
1587 "file Make" "file" (word break hard to screw up here)
1588 "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
1591 /* Generate completions one by one for the completer. Each time we are
1592 called return another potential completion to the caller.
1593 line_completion just completes on commands or passes the buck to the
1594 command's completer function, the stuff specific to symbol completion
1595 is in make_symbol_completion_list.
1597 TEXT is the caller's idea of the "word" we are looking at.
1599 MATCHES is the number of matches that have currently been collected from
1600 calling this completion function. When zero, then we need to initialize,
1601 otherwise the initialization has already taken place and we can just
1602 return the next potential completion string.
1604 LINE_BUFFER is available to be looked at; it contains the entire text
1605 of the line. POINT is the offset in that line of the cursor. You
1606 should pretend that the line ends at POINT.
1608 Returns NULL if there are no more completions, else a pointer to a string
1609 which is a possible completion, it is the caller's responsibility to
1613 line_completion_function (text, matches, line_buffer, point)
1619 static char **list = (char **)NULL; /* Cache of completions */
1620 static int index; /* Next cached completion */
1621 char *output = NULL;
1622 char *tmp_command, *p;
1623 /* Pointer within tmp_command which corresponds to text. */
1625 struct cmd_list_element *c, *result_list;
1629 /* The caller is beginning to accumulate a new set of completions, so
1630 we need to find all of them now, and cache them for returning one at
1631 a time on future calls. */
1635 /* Free the storage used by LIST, but not by the strings inside.
1636 This is because rl_complete_internal () frees the strings. */
1642 /* Choose the default set of word break characters to break completions.
1643 If we later find out that we are doing completions on command strings
1644 (as opposed to strings supplied by the individual command completer
1645 functions, which can be any string) then we will switch to the
1646 special word break set for command strings, which leaves out the
1647 '-' character used in some commands. */
1649 rl_completer_word_break_characters =
1650 gdb_completer_word_break_characters;
1652 /* Decide whether to complete on a list of gdb commands or on symbols. */
1653 tmp_command = (char *) alloca (point + 1);
1656 strncpy (tmp_command, line_buffer, point);
1657 tmp_command[point] = '\0';
1658 /* Since text always contains some number of characters leading up
1659 to point, we can find the equivalent position in tmp_command
1660 by subtracting that many characters from the end of tmp_command. */
1661 word = tmp_command + point - strlen (text);
1665 /* An empty line we want to consider ambiguous; that is, it
1666 could be any command. */
1667 c = (struct cmd_list_element *) -1;
1672 c = lookup_cmd_1 (&p, cmdlist, &result_list, 1);
1675 /* Move p up to the next interesting thing. */
1676 while (*p == ' ' || *p == '\t')
1683 /* It is an unrecognized command. So there are no
1684 possible completions. */
1687 else if (c == (struct cmd_list_element *) -1)
1691 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
1692 doesn't advance over that thing itself. Do so now. */
1694 while (*q && (isalnum (*q) || *q == '-' || *q == '_'))
1696 if (q != tmp_command + point)
1698 /* There is something beyond the ambiguous
1699 command, so there are no possible completions. For
1700 example, "info t " or "info t foo" does not complete
1701 to anything, because "info t" can be "info target" or
1707 /* We're trying to complete on the command which was ambiguous.
1708 This we can deal with. */
1711 list = complete_on_cmdlist (*result_list->prefixlist, p,
1716 list = complete_on_cmdlist (cmdlist, p, word);
1718 /* Insure that readline does the right thing with respect to
1719 inserting quotes. */
1720 rl_completer_word_break_characters =
1721 gdb_completer_command_word_break_characters;
1726 /* We've recognized a full command. */
1728 if (p == tmp_command + point)
1730 /* There is no non-whitespace in the line beyond the command. */
1732 if (p[-1] == ' ' || p[-1] == '\t')
1734 /* The command is followed by whitespace; we need to complete
1735 on whatever comes after command. */
1738 /* It is a prefix command; what comes after it is
1739 a subcommand (e.g. "info "). */
1740 list = complete_on_cmdlist (*c->prefixlist, p, word);
1742 /* Insure that readline does the right thing
1743 with respect to inserting quotes. */
1744 rl_completer_word_break_characters =
1745 gdb_completer_command_word_break_characters;
1749 list = complete_on_enum (c->enums, p, word);
1750 rl_completer_word_break_characters =
1751 gdb_completer_command_word_break_characters;
1755 /* It is a normal command; what comes after it is
1756 completed by the command's completer function. */
1757 list = (*c->completer) (p, word);
1762 /* The command is not followed by whitespace; we need to
1763 complete on the command itself. e.g. "p" which is a
1764 command itself but also can complete to "print", "ptype"
1768 /* Find the command we are completing on. */
1770 while (q > tmp_command)
1772 if (isalnum (q[-1]) || q[-1] == '-' || q[-1] == '_')
1778 list = complete_on_cmdlist (result_list, q, word);
1780 /* Insure that readline does the right thing
1781 with respect to inserting quotes. */
1782 rl_completer_word_break_characters =
1783 gdb_completer_command_word_break_characters;
1788 /* There is non-whitespace beyond the command. */
1790 if (c->prefixlist && !c->allow_unknown)
1792 /* It is an unrecognized subcommand of a prefix command,
1793 e.g. "info adsfkdj". */
1798 list = complete_on_enum (c->enums, p, word);
1802 /* It is a normal command. */
1803 list = (*c->completer) (p, word);
1809 /* If we found a list of potential completions during initialization then
1810 dole them out one at a time. The vector of completions is NULL
1811 terminated, so after returning the last one, return NULL (and continue
1812 to do so) each time we are called after that, until a new list is
1817 output = list[index];
1825 /* Can't do this because readline hasn't yet checked the word breaks
1826 for figuring out whether to insert a quote. */
1828 /* Make sure the word break characters are set back to normal for the
1829 next time that readline tries to complete something. */
1830 rl_completer_word_break_characters =
1831 gdb_completer_word_break_characters;
1837 /* Line completion interface function for readline. */
1840 readline_line_completion_function (text, matches)
1844 return line_completion_function (text, matches, rl_line_buffer, rl_point);
1847 /* Skip over a possibly quoted word (as defined by the quote characters
1848 and word break characters the completer uses). Returns pointer to the
1849 location after the "word". */
1855 char quote_char = '\0';
1858 for (scan = str; *scan != '\0'; scan++)
1860 if (quote_char != '\0')
1862 /* Ignore everything until the matching close quote char */
1863 if (*scan == quote_char)
1865 /* Found matching close quote. */
1870 else if (strchr (gdb_completer_quote_characters, *scan))
1872 /* Found start of a quoted string. */
1875 else if (strchr (gdb_completer_word_break_characters, *scan))
1889 #if STOP_SIGNAL == SIGTSTP
1890 signal (SIGTSTP, SIG_DFL);
1892 kill (getpid (), SIGTSTP);
1893 signal (SIGTSTP, stop_sig);
1895 signal (STOP_SIGNAL, stop_sig);
1897 printf_unfiltered ("%s", prompt);
1898 gdb_flush (gdb_stdout);
1900 /* Forget about any previous command -- null line now will do nothing. */
1903 #endif /* STOP_SIGNAL */
1905 /* Initialize signal handlers. */
1915 signal (SIGINT, request_quit);
1917 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
1918 to the inferior and breakpoints will be ignored. */
1920 signal (SIGTRAP, SIG_DFL);
1923 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
1924 passed to the inferior, which we don't want. It would be
1925 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
1926 on BSD4.3 systems using vfork, that can affect the
1927 GDB process as well as the inferior (the signal handling tables
1928 might be in memory, shared between the two). Since we establish
1929 a handler for SIGQUIT, when we call exec it will set the signal
1930 to SIG_DFL for us. */
1931 signal (SIGQUIT, do_nothing);
1932 if (signal (SIGHUP, do_nothing) != SIG_IGN)
1933 signal (SIGHUP, disconnect);
1934 signal (SIGFPE, float_handler);
1936 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1937 signal (SIGWINCH, SIGWINCH_HANDLER);
1941 /* Read one line from the command input stream `instream'
1942 into the local static buffer `linebuffer' (whose current length
1944 The buffer is made bigger as necessary.
1945 Returns the address of the start of the line.
1947 NULL is returned for end of file.
1949 *If* the instream == stdin & stdin is a terminal, the line read
1950 is copied into the file line saver (global var char *line,
1951 length linesize) so that it can be duplicated.
1953 This routine either uses fancy command line editing or
1954 simple input as the user has requested. */
1957 command_line_input (prrompt, repeat, annotation_suffix)
1960 char *annotation_suffix;
1962 static char *linebuffer = 0;
1963 static unsigned linelength = 0;
1967 char *local_prompt = prrompt;
1971 /* The annotation suffix must be non-NULL. */
1972 if (annotation_suffix == NULL)
1973 annotation_suffix = "";
1975 if (annotation_level > 1 && instream == stdin)
1977 local_prompt = alloca ((prrompt == NULL ? 0 : strlen (prrompt))
1978 + strlen (annotation_suffix) + 40);
1979 if (prrompt == NULL)
1980 local_prompt[0] = '\0';
1982 strcpy (local_prompt, prrompt);
1983 strcat (local_prompt, "\n\032\032");
1984 strcat (local_prompt, annotation_suffix);
1985 strcat (local_prompt, "\n");
1988 if (linebuffer == 0)
1991 linebuffer = (char *) xmalloc (linelength);
1996 /* Control-C quits instantly if typed while in this loop
1997 since it should not wait until the user types a newline. */
2001 signal (STOP_SIGNAL, stop_sig);
2006 /* Make sure that all output has been output. Some machines may let
2007 you get away with leaving out some of the gdb_flush, but not all. */
2009 gdb_flush (gdb_stdout);
2010 gdb_flush (gdb_stderr);
2012 if (source_file_name != NULL)
2014 ++source_line_number;
2015 sprintf (source_error,
2016 "%s%s:%d: Error in sourced command file:\n",
2019 source_line_number);
2020 error_pre_print = source_error;
2023 if (annotation_level > 1 && instream == stdin)
2025 printf_unfiltered ("\n\032\032pre-");
2026 printf_unfiltered (annotation_suffix);
2027 printf_unfiltered ("\n");
2030 /* Don't use fancy stuff if not talking to stdin. */
2031 if (readline_hook && instream == NULL)
2033 rl = (*readline_hook) (local_prompt);
2035 else if (command_editing_p && instream == stdin && ISATTY (instream))
2037 rl = readline (local_prompt);
2041 rl = gdb_readline (local_prompt);
2044 if (annotation_level > 1 && instream == stdin)
2046 printf_unfiltered ("\n\032\032post-");
2047 printf_unfiltered (annotation_suffix);
2048 printf_unfiltered ("\n");
2051 if (!rl || rl == (char *) EOF)
2056 if (strlen(rl) + 1 + (p - linebuffer) > linelength)
2058 linelength = strlen(rl) + 1 + (p - linebuffer);
2059 nline = (char *) xrealloc (linebuffer, linelength);
2060 p += nline - linebuffer;
2064 /* Copy line. Don't copy null at end. (Leaves line alone
2065 if this was just a newline) */
2069 free (rl); /* Allocated in readline. */
2071 if (p == linebuffer || *(p - 1) != '\\')
2074 p--; /* Put on top of '\'. */
2075 local_prompt = (char *) 0;
2080 signal (STOP_SIGNAL, SIG_DFL);
2087 #define SERVER_COMMAND_LENGTH 7
2089 (p - linebuffer > SERVER_COMMAND_LENGTH)
2090 && STREQN (linebuffer, "server ", SERVER_COMMAND_LENGTH);
2093 /* Note that we don't set `line'. Between this and the check in
2094 dont_repeat, this insures that repeating will still do the
2097 return linebuffer + SERVER_COMMAND_LENGTH;
2100 /* Do history expansion if that is wished. */
2101 if (history_expansion_p && instream == stdin
2102 && ISATTY (instream))
2104 char *history_value;
2107 *p = '\0'; /* Insert null now. */
2108 expanded = history_expand (linebuffer, &history_value);
2111 /* Print the changes. */
2112 printf_unfiltered ("%s\n", history_value);
2114 /* If there was an error, call this function again. */
2117 free (history_value);
2118 return command_line_input (prrompt, repeat, annotation_suffix);
2120 if (strlen (history_value) > linelength)
2122 linelength = strlen (history_value) + 1;
2123 linebuffer = (char *) xrealloc (linebuffer, linelength);
2125 strcpy (linebuffer, history_value);
2126 p = linebuffer + strlen(linebuffer);
2127 free (history_value);
2131 /* If we just got an empty line, and that is supposed
2132 to repeat the previous command, return the value in the
2134 if (repeat && p == linebuffer)
2136 for (p1 = linebuffer; *p1 == ' ' || *p1 == '\t'; p1++) ;
2142 /* Add line to history if appropriate. */
2143 if (instream == stdin
2144 && ISATTY (stdin) && *linebuffer)
2145 add_history (linebuffer);
2147 /* Note: lines consisting solely of comments are added to the command
2148 history. This is useful when you type a command, and then
2149 realize you don't want to execute it quite yet. You can comment
2150 out the command and then later fetch it from the value history
2151 and remove the '#'. The kill ring is probably better, but some
2152 people are in the habit of commenting things out. */
2154 *p1 = '\0'; /* Found a comment. */
2156 /* Save into global buffer if appropriate. */
2159 if (linelength > linesize)
2161 line = xrealloc (line, linelength);
2162 linesize = linelength;
2164 strcpy (line, linebuffer);
2172 /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
2173 code bodies. This is typically used when we encounter an "else"
2174 clause for an "if" command. */
2177 realloc_body_list (command, new_length)
2178 struct command_line *command;
2182 struct command_line **body_list;
2184 n = command->body_count;
2186 /* Nothing to do? */
2187 if (new_length <= n)
2190 body_list = (struct command_line **)
2191 xmalloc (sizeof (struct command_line *) * new_length);
2193 memcpy (body_list, command->body_list, sizeof (struct command_line *) * n);
2195 free (command->body_list);
2196 command->body_list = body_list;
2197 command->body_count = new_length;
2200 /* Read one line from the input stream. If the command is an "else" or
2201 "end", return such an indication to the caller. */
2203 static enum misc_command_type
2204 read_next_line (command)
2205 struct command_line **command;
2207 char *p, *p1, *prompt_ptr, control_prompt[256];
2210 if (control_level >= 254)
2211 error ("Control nesting too deep!\n");
2213 /* Set a prompt based on the nesting of the control commands. */
2214 if (instream == stdin || (instream == 0 && readline_hook != NULL))
2216 for (i = 0; i < control_level; i++)
2217 control_prompt[i] = ' ';
2218 control_prompt[i] = '>';
2219 control_prompt[i+1] = '\0';
2220 prompt_ptr = (char *)&control_prompt[0];
2225 p = command_line_input (prompt_ptr, instream == stdin, "commands");
2227 /* Not sure what to do here. */
2231 /* Strip leading and trailing whitespace. */
2232 while (*p == ' ' || *p == '\t')
2235 p1 = p + strlen (p);
2236 while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t'))
2239 /* Blanks and comments don't really do anything, but we need to
2240 distinguish them from else, end and other commands which can be
2242 if (p1 == p || p[0] == '#')
2245 /* Is this the end of a simple, while, or if control structure? */
2246 if (p1 - p == 3 && !strncmp (p, "end", 3))
2249 /* Is the else clause of an if control structure? */
2250 if (p1 - p == 4 && !strncmp (p, "else", 4))
2251 return else_command;
2253 /* Check for while, if, break, continue, etc and build a new command
2254 line structure for them. */
2255 if (p1 - p > 5 && !strncmp (p, "while", 5))
2256 *command = build_command_line (while_control, p + 6);
2257 else if (p1 - p > 2 && !strncmp (p, "if", 2))
2258 *command = build_command_line (if_control, p + 3);
2259 else if (p1 - p == 10 && !strncmp (p, "loop_break", 10))
2261 *command = (struct command_line *)
2262 xmalloc (sizeof (struct command_line));
2263 (*command)->next = NULL;
2264 (*command)->line = NULL;
2265 (*command)->control_type = break_control;
2266 (*command)->body_count = 0;
2267 (*command)->body_list = NULL;
2269 else if (p1 - p == 13 && !strncmp (p, "loop_continue", 13))
2271 *command = (struct command_line *)
2272 xmalloc (sizeof (struct command_line));
2273 (*command)->next = NULL;
2274 (*command)->line = NULL;
2275 (*command)->control_type = continue_control;
2276 (*command)->body_count = 0;
2277 (*command)->body_list = NULL;
2281 /* A normal command. */
2282 *command = (struct command_line *)
2283 xmalloc (sizeof (struct command_line));
2284 (*command)->next = NULL;
2285 (*command)->line = savestring (p, p1 - p);
2286 (*command)->control_type = simple_control;
2287 (*command)->body_count = 0;
2288 (*command)->body_list = NULL;
2291 /* Nothing special. */
2295 /* Recursively read in the control structures and create a command_line
2296 structure from them.
2298 The parent_control parameter is the control structure in which the
2299 following commands are nested. */
2301 static enum command_control_type
2302 recurse_read_control_structure (current_cmd)
2303 struct command_line *current_cmd;
2305 int current_body, i;
2306 enum misc_command_type val;
2307 enum command_control_type ret;
2308 struct command_line **body_ptr, *child_tail, *next;
2313 /* Sanity checks. */
2314 if (current_cmd->control_type == simple_control)
2316 error ("Recursed on a simple control type\n");
2317 return invalid_control;
2320 if (current_body > current_cmd->body_count)
2322 error ("Allocated body is smaller than this command type needs\n");
2323 return invalid_control;
2326 /* Read lines from the input stream and build control structures. */
2332 val = read_next_line (&next);
2334 /* Just skip blanks and comments. */
2335 if (val == nop_command)
2338 if (val == end_command)
2340 if (current_cmd->control_type == while_control
2341 || current_cmd->control_type == if_control)
2343 /* Success reading an entire control structure. */
2344 ret = simple_control;
2349 ret = invalid_control;
2354 /* Not the end of a control structure. */
2355 if (val == else_command)
2357 if (current_cmd->control_type == if_control
2358 && current_body == 1)
2360 realloc_body_list (current_cmd, 2);
2367 ret = invalid_control;
2374 child_tail->next = next;
2378 body_ptr = current_cmd->body_list;
2379 for (i = 1; i < current_body; i++)
2388 /* If the latest line is another control structure, then recurse
2390 if (next->control_type == while_control
2391 || next->control_type == if_control)
2394 ret = recurse_read_control_structure (next);
2397 if (ret != simple_control)
2407 /* Read lines from the input stream and accumulate them in a chain of
2408 struct command_line's, which is then returned. For input from a
2409 terminal, the special command "end" is used to mark the end of the
2410 input, and is not included in the returned chain of commands. */
2412 #define END_MESSAGE "End with a line saying just \"end\"."
2414 struct command_line *
2415 read_command_lines (prompt, from_tty)
2419 struct command_line *head, *tail, *next;
2420 struct cleanup *old_chain;
2421 enum command_control_type ret;
2422 enum misc_command_type val;
2424 if (readline_begin_hook)
2426 /* Note - intentional to merge messages with no newline */
2427 (*readline_begin_hook) ("%s %s\n", prompt, END_MESSAGE);
2429 else if (from_tty && input_from_terminal_p ())
2431 printf_unfiltered ("%s\n%s\n", prompt, END_MESSAGE);
2432 gdb_flush (gdb_stdout);
2440 val = read_next_line (&next);
2442 /* Ignore blank lines or comments. */
2443 if (val == nop_command)
2446 if (val == end_command)
2448 ret = simple_control;
2452 if (val != ok_command)
2454 ret = invalid_control;
2458 if (next->control_type == while_control
2459 || next->control_type == if_control)
2462 ret = recurse_read_control_structure (next);
2465 if (ret == invalid_control)
2476 old_chain = make_cleanup (free_command_lines, &head);
2485 if (ret != invalid_control)
2487 discard_cleanups (old_chain);
2490 do_cleanups (old_chain);
2493 if (readline_end_hook)
2495 (*readline_end_hook) ();
2500 /* Free a chain of struct command_line's. */
2503 free_command_lines (lptr)
2504 struct command_line **lptr;
2506 register struct command_line *l = *lptr;
2507 register struct command_line *next;
2508 struct command_line **blist;
2513 if (l->body_count > 0)
2515 blist = l->body_list;
2516 for (i = 0; i < l->body_count; i++, blist++)
2517 free_command_lines (blist);
2526 /* Add an element to the list of info subcommands. */
2529 add_info (name, fun, doc)
2531 void (*fun) PARAMS ((char *, int));
2534 add_cmd (name, no_class, fun, doc, &infolist);
2537 /* Add an alias to the list of info subcommands. */
2540 add_info_alias (name, oldname, abbrev_flag)
2545 add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist);
2548 /* The "info" command is defined as a prefix, with allow_unknown = 0.
2549 Therefore, its own definition is called only for "info" with no args. */
2553 info_command (arg, from_tty)
2557 printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
2558 help_list (infolist, "info ", -1, gdb_stdout);
2561 /* The "complete" command is used by Emacs to implement completion. */
2565 complete_command (arg, from_tty)
2577 argpoint = strlen (arg);
2579 for (completion = line_completion_function (arg, i = 0, arg, argpoint);
2581 completion = line_completion_function (arg, ++i, arg, argpoint))
2583 printf_unfiltered ("%s\n", completion);
2588 /* The "show" command with no arguments shows all the settings. */
2592 show_command (arg, from_tty)
2596 cmd_show_list (showlist, from_tty, "");
2599 /* Add an element to the list of commands. */
2602 add_com (name, class, fun, doc)
2604 enum command_class class;
2605 void (*fun) PARAMS ((char *, int));
2608 add_cmd (name, class, fun, doc, &cmdlist);
2611 /* Add an alias or abbreviation command to the list of commands. */
2614 add_com_alias (name, oldname, class, abbrev_flag)
2617 enum command_class class;
2620 add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist);
2627 error ("Argument required (%s).", why);
2632 help_command (command, from_tty)
2634 int from_tty; /* Ignored */
2636 help_cmd (command, gdb_stdout);
2640 validate_comname (comname)
2646 error_no_arg ("name of command to define");
2651 if (!isalnum(*p) && *p != '-' && *p != '_')
2652 error ("Junk in argument list: \"%s\"", p);
2657 /* This is just a placeholder in the command data structures. */
2659 user_defined_command (ignore, from_tty)
2666 define_command (comname, from_tty)
2670 register struct command_line *cmds;
2671 register struct cmd_list_element *c, *newc, *hookc = 0;
2672 char *tem = comname;
2674 #define HOOK_STRING "hook-"
2677 validate_comname (comname);
2679 /* Look it up, and verify that we got an exact match. */
2680 c = lookup_cmd (&tem, cmdlist, "", -1, 1);
2681 if (c && !STREQ (comname, c->name))
2686 if (c->class == class_user || c->class == class_alias)
2687 tem = "Redefine command \"%s\"? ";
2689 tem = "Really redefine built-in command \"%s\"? ";
2690 if (!query (tem, c->name))
2691 error ("Command \"%s\" not redefined.", c->name);
2694 /* If this new command is a hook, then mark the command which it
2695 is hooking. Note that we allow hooking `help' commands, so that
2696 we can hook the `stop' pseudo-command. */
2698 if (!strncmp (comname, HOOK_STRING, HOOK_LEN))
2700 /* Look up cmd it hooks, and verify that we got an exact match. */
2701 tem = comname+HOOK_LEN;
2702 hookc = lookup_cmd (&tem, cmdlist, "", -1, 0);
2703 if (hookc && !STREQ (comname+HOOK_LEN, hookc->name))
2707 warning ("Your new `%s' command does not hook any existing command.",
2709 if (!query ("Proceed? "))
2710 error ("Not confirmed.");
2714 comname = savestring (comname, strlen (comname));
2716 /* If the rest of the commands will be case insensitive, this one
2717 should behave in the same manner. */
2718 for (tem = comname; *tem; tem++)
2719 if (isupper(*tem)) *tem = tolower(*tem);
2722 sprintf (tmpbuf, "Type commands for definition of \"%s\".", comname);
2723 cmds = read_command_lines (tmpbuf, from_tty);
2725 if (c && c->class == class_user)
2726 free_command_lines (&c->user_commands);
2728 newc = add_cmd (comname, class_user, user_defined_command,
2729 (c && c->class == class_user)
2730 ? c->doc : savestring ("User-defined.", 13), &cmdlist);
2731 newc->user_commands = cmds;
2733 /* If this new command is a hook, then mark both commands as being
2737 hookc->hook = newc; /* Target gets hooked. */
2738 newc->hookee = hookc; /* We are marked as hooking target cmd. */
2743 document_command (comname, from_tty)
2747 struct command_line *doclines;
2748 register struct cmd_list_element *c;
2749 char *tem = comname;
2752 validate_comname (comname);
2754 c = lookup_cmd (&tem, cmdlist, "", 0, 1);
2756 if (c->class != class_user)
2757 error ("Command \"%s\" is built-in.", comname);
2759 sprintf (tmpbuf, "Type documentation for \"%s\".", comname);
2760 doclines = read_command_lines (tmpbuf, from_tty);
2762 if (c->doc) free (c->doc);
2765 register struct command_line *cl1;
2766 register int len = 0;
2768 for (cl1 = doclines; cl1; cl1 = cl1->next)
2769 len += strlen (cl1->line) + 1;
2771 c->doc = (char *) xmalloc (len + 1);
2774 for (cl1 = doclines; cl1; cl1 = cl1->next)
2776 strcat (c->doc, cl1->line);
2778 strcat (c->doc, "\n");
2782 free_command_lines (&doclines);
2786 print_gdb_version (stream)
2789 /* From GNU coding standards, first line is meant to be easy for a
2790 program to parse, and is just canonical program name and version
2791 number, which starts after last space. */
2793 fprintf_filtered (stream, "GNU gdb %s\n", version);
2795 /* Second line is a copyright notice. */
2797 fprintf_filtered (stream, "Copyright 1997 Free Software Foundation, Inc.\n");
2799 /* Following the copyright is a brief statement that the program is
2800 free software, that users are free to copy and change it on
2801 certain conditions, that it is covered by the GNU GPL, and that
2802 there is no warranty. */
2804 fprintf_filtered (stream, "\
2805 GDB is free software, covered by the GNU General Public License, and you are\n\
2806 welcome to change it and/or distribute copies of it under certain conditions.\n\
2807 Type \"show copying\" to see the conditions.\n\
2808 There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n");
2810 /* After the required info we print the configuration information. */
2812 fprintf_filtered (stream, "This GDB was configured as \"");
2813 if (!STREQ (host_name, target_name))
2815 fprintf_filtered (stream, "--host=%s --target=%s", host_name, target_name);
2819 fprintf_filtered (stream, "%s", host_name);
2821 fprintf_filtered (stream, "\".");
2826 show_version (args, from_tty)
2831 print_gdb_version (gdb_stdout);
2832 printf_filtered ("\n");
2836 /* xgdb calls this to reprint the usual GDB prompt. Obsolete now that xgdb
2842 printf_unfiltered ("%s", prompt);
2843 gdb_flush (gdb_stdout);
2847 quit_command (args, from_tty)
2853 /* An optional expression may be used to cause gdb to terminate with the
2854 value of that expression. */
2857 value_ptr val = parse_and_eval (args);
2859 exit_code = (int) value_as_long (val);
2862 if (inferior_pid != 0 && target_has_execution)
2866 if (query ("The program is running. Quit anyway (and detach it)? "))
2867 target_detach (args, from_tty);
2869 error ("Not confirmed.");
2873 if (query ("The program is running. Quit anyway (and kill it)? "))
2876 error ("Not confirmed.");
2879 /* UDI wants this, to kill the TIP. */
2882 /* Save the history information if it is appropriate to do so. */
2883 if (write_history_p && history_filename)
2884 write_history (history_filename);
2886 do_final_cleanups(ALL_CLEANUPS); /* Do any final cleanups before exiting */
2891 /* Returns whether GDB is running on a terminal and whether the user
2892 desires that questions be asked of them on that terminal. */
2895 input_from_terminal_p ()
2897 return gdb_has_a_terminal () && (instream == stdin) & caution;
2902 pwd_command (args, from_tty)
2906 if (args) error ("The \"pwd\" command does not take an argument: %s", args);
2907 getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
2909 if (!STREQ (gdb_dirbuf, current_directory))
2910 printf_unfiltered ("Working directory %s\n (canonically %s).\n",
2911 current_directory, gdb_dirbuf);
2913 printf_unfiltered ("Working directory %s.\n", current_directory);
2917 cd_command (dir, from_tty)
2922 /* Found something other than leading repetitions of "/..". */
2923 int found_real_path;
2926 /* If the new directory is absolute, repeat is a no-op; if relative,
2927 repeat might be useful but is more likely to be a mistake. */
2931 error_no_arg ("new working directory");
2933 dir = tilde_expand (dir);
2934 make_cleanup (free, dir);
2936 if (chdir (dir) < 0)
2937 perror_with_name (dir);
2940 dir = savestring (dir, len - (len > 1 && SLASH_P(dir[len-1])));
2942 current_directory = dir;
2945 if (SLASH_P (current_directory[0]) && current_directory[1] == '\0')
2946 current_directory = concat (current_directory, dir, NULL);
2948 current_directory = concat (current_directory, SLASH_STRING, dir, NULL);
2952 /* Now simplify any occurrences of `.' and `..' in the pathname. */
2954 found_real_path = 0;
2955 for (p = current_directory; *p;)
2957 if (SLASH_P (p[0]) && p[1] == '.' && (p[2] == 0 || SLASH_P (p[2])))
2959 else if (SLASH_P (p[0]) && p[1] == '.' && p[2] == '.'
2960 && (p[3] == 0 || SLASH_P (p[3])))
2962 if (found_real_path)
2964 /* Search backwards for the directory just before the "/.."
2965 and obliterate it and the "/..". */
2967 while (q != current_directory && ! SLASH_P (q[-1]))
2970 if (q == current_directory)
2971 /* current_directory is
2972 a relative pathname ("can't happen"--leave it alone). */
2976 strcpy (q - 1, p + 3);
2981 /* We are dealing with leading repetitions of "/..", for example
2982 "/../..", which is the Mach super-root. */
2987 found_real_path = 1;
2992 forget_cached_source_info ();
2995 pwd_command ((char *) 0, 1);
2998 struct source_cleanup_lines_args {
3001 char *old_pre_error;
3002 char *old_error_pre_print;
3006 source_cleanup_lines (args)
3009 struct source_cleanup_lines_args *p =
3010 (struct source_cleanup_lines_args *)args;
3011 source_line_number = p->old_line;
3012 source_file_name = p->old_file;
3013 source_pre_error = p->old_pre_error;
3014 error_pre_print = p->old_error_pre_print;
3019 source_command (args, from_tty)
3024 struct cleanup *old_cleanups;
3026 struct source_cleanup_lines_args old_lines;
3031 error ("source command requires pathname of file to source.");
3034 file = tilde_expand (file);
3035 old_cleanups = make_cleanup (free, file);
3037 stream = fopen (file, FOPEN_RT);
3040 perror_with_name (file);
3044 make_cleanup (fclose, stream);
3046 old_lines.old_line = source_line_number;
3047 old_lines.old_file = source_file_name;
3048 old_lines.old_pre_error = source_pre_error;
3049 old_lines.old_error_pre_print = error_pre_print;
3050 make_cleanup (source_cleanup_lines, &old_lines);
3051 source_line_number = 0;
3052 source_file_name = file;
3053 source_pre_error = error_pre_print == NULL ? "" : error_pre_print;
3054 source_pre_error = savestring (source_pre_error, strlen (source_pre_error));
3055 make_cleanup (free, source_pre_error);
3056 /* This will get set every time we read a line. So it won't stay "" for
3058 error_pre_print = "";
3060 needed_length = strlen (source_file_name) + strlen (source_pre_error) + 80;
3061 if (source_error_allocated < needed_length)
3063 source_error_allocated *= 2;
3064 if (source_error_allocated < needed_length)
3065 source_error_allocated = needed_length;
3066 if (source_error == NULL)
3067 source_error = xmalloc (source_error_allocated);
3069 source_error = xrealloc (source_error, source_error_allocated);
3072 read_command_file (stream);
3074 do_cleanups (old_cleanups);
3079 echo_command (text, from_tty)
3087 while ((c = *p++) != '\0')
3091 /* \ at end of argument is used after spaces
3092 so they won't be lost. */
3096 c = parse_escape (&p);
3098 printf_filtered ("%c", c);
3101 printf_filtered ("%c", c);
3104 /* Force this output to appear now. */
3106 gdb_flush (gdb_stdout);
3111 dont_repeat_command (ignored, from_tty)
3115 *line = 0; /* Can't call dont_repeat here because we're not
3116 necessarily reading from stdin. */
3119 #ifdef TARGET_BYTE_ORDER_SELECTABLE
3121 /* Functions to manipulate the endianness of the target. */
3123 #ifndef TARGET_BYTE_ORDER_DEFAULT
3124 #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
3127 int target_byte_order = TARGET_BYTE_ORDER_DEFAULT;
3129 static int target_byte_order_auto = 1;
3131 /* Called if the user enters ``set endian'' without an argument. */
3133 set_endian (args, from_tty)
3137 printf_unfiltered ("\"set endian\" must be followed by \"auto\", \"big\" or \"little\".\n");
3138 show_endian (args, from_tty);
3141 /* Called by ``set endian big''. */
3143 set_endian_big (args, from_tty)
3147 target_byte_order = BIG_ENDIAN;
3148 target_byte_order_auto = 0;
3151 /* Called by ``set endian little''. */
3153 set_endian_little (args, from_tty)
3157 target_byte_order = LITTLE_ENDIAN;
3158 target_byte_order_auto = 0;
3161 /* Called by ``set endian auto''. */
3163 set_endian_auto (args, from_tty)
3167 target_byte_order_auto = 1;
3170 /* Called by ``show endian''. */
3172 show_endian (args, from_tty)
3177 (target_byte_order_auto
3178 ? "The target endianness is set automatically (currently %s endian)\n"
3179 : "The target is assumed to be %s endian\n");
3180 printf_unfiltered ((char *) msg, TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
3183 #endif /* defined (TARGET_BYTE_ORDER_SELECTABLE) */
3185 /* Set the endianness from a BFD. */
3187 set_endian_from_file (abfd)
3190 #ifdef TARGET_BYTE_ORDER_SELECTABLE
3193 if (bfd_big_endian (abfd))
3196 want = LITTLE_ENDIAN;
3197 if (target_byte_order_auto)
3198 target_byte_order = want;
3199 else if (target_byte_order != want)
3200 warning ("%s endian file does not match %s endian target.",
3201 want == BIG_ENDIAN ? "big" : "little",
3202 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
3204 #else /* ! defined (TARGET_BYTE_ORDER_SELECTABLE) */
3206 if (bfd_big_endian (abfd)
3207 ? TARGET_BYTE_ORDER != BIG_ENDIAN
3208 : TARGET_BYTE_ORDER == BIG_ENDIAN)
3209 warning ("%s endian file does not match %s endian target.",
3210 bfd_big_endian (abfd) ? "big" : "little",
3211 TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
3213 #endif /* ! defined (TARGET_BYTE_ORDER_SELECTABLE) */
3216 /* Functions to manipulate command line editing control variables. */
3218 /* Number of commands to print in each call to show_commands. */
3219 #define Hist_print 10
3221 show_commands (args, from_tty)
3225 /* Index for history commands. Relative to history_base. */
3228 /* Number of the history entry which we are planning to display next.
3229 Relative to history_base. */
3232 /* The first command in the history which doesn't exist (i.e. one more
3233 than the number of the last command). Relative to history_base. */
3236 extern HIST_ENTRY *history_get PARAMS ((int));
3238 /* Print out some of the commands from the command history. */
3239 /* First determine the length of the history list. */
3240 hist_len = history_size;
3241 for (offset = 0; offset < history_size; offset++)
3243 if (!history_get (history_base + offset))
3252 if (args[0] == '+' && args[1] == '\0')
3253 /* "info editing +" should print from the stored position. */
3256 /* "info editing <exp>" should print around command number <exp>. */
3257 num = (parse_and_eval_address (args) - history_base) - Hist_print / 2;
3259 /* "show commands" means print the last Hist_print commands. */
3262 num = hist_len - Hist_print;
3268 /* If there are at least Hist_print commands, we want to display the last
3269 Hist_print rather than, say, the last 6. */
3270 if (hist_len - num < Hist_print)
3272 num = hist_len - Hist_print;
3277 for (offset = num; offset < num + Hist_print && offset < hist_len; offset++)
3279 printf_filtered ("%5d %s\n", history_base + offset,
3280 (history_get (history_base + offset))->line);
3283 /* The next command we want to display is the next one that we haven't
3287 /* If the user repeats this command with return, it should do what
3288 "show commands +" does. This is unnecessary if arg is null,
3289 because "show commands +" is not useful after "show commands". */
3290 if (from_tty && args)
3297 /* Called by do_setshow_command. */
3300 set_history_size_command (args, from_tty, c)
3303 struct cmd_list_element *c;
3305 if (history_size == INT_MAX)
3306 unstifle_history ();
3307 else if (history_size >= 0)
3308 stifle_history (history_size);
3311 history_size = INT_MAX;
3312 error ("History size must be non-negative");
3318 set_history (args, from_tty)
3322 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
3323 help_list (sethistlist, "set history ", -1, gdb_stdout);
3328 show_history (args, from_tty)
3332 cmd_show_list (showhistlist, from_tty, "");
3335 int info_verbose = 0; /* Default verbose msgs off */
3337 /* Called by do_setshow_command. An elaborate joke. */
3340 set_verbose (args, from_tty, c)
3343 struct cmd_list_element *c;
3345 char *cmdname = "verbose";
3346 struct cmd_list_element *showcmd;
3348 showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
3352 c->doc = "Set verbose printing of informational messages.";
3353 showcmd->doc = "Show verbose printing of informational messages.";
3357 c->doc = "Set verbosity.";
3358 showcmd->doc = "Show verbosity.";
3363 float_handler (signo)
3366 /* This message is based on ANSI C, section 4.7. Note that integer
3367 divide by zero causes this, so "float" is a misnomer. */
3368 signal (SIGFPE, float_handler);
3369 error ("Erroneous arithmetic operation.");
3381 enablebreaklist = NULL;
3385 #ifdef TARGET_BYTE_ORDER_SELECTABLE
3389 showhistlist = NULL;
3390 unsethistlist = NULL;
3391 #if MAINTENANCE_CMDS
3392 maintenancelist = NULL;
3393 maintenanceinfolist = NULL;
3394 maintenanceprintlist = NULL;
3396 setprintlist = NULL;
3397 showprintlist = NULL;
3398 setchecklist = NULL;
3399 showchecklist = NULL;
3402 /* Init the history buffer. Note that we are called after the init file(s)
3403 * have been read so that the user can change the history file via his
3404 * .gdbinit file (for instance). The GDBHISTFILE environment variable
3405 * overrides all of this.
3413 tmpenv = getenv ("HISTSIZE");
3415 history_size = atoi (tmpenv);
3416 else if (!history_size)
3419 stifle_history (history_size);
3421 tmpenv = getenv ("GDBHISTFILE");
3423 history_filename = savestring (tmpenv, strlen(tmpenv));
3424 else if (!history_filename) {
3425 /* We include the current directory so that if the user changes
3426 directories the file written will be the same as the one
3428 history_filename = concat (current_directory, "/.gdb_history", NULL);
3430 read_history (history_filename);
3436 struct cmd_list_element *c;
3438 #ifdef TARGET_BYTE_ORDER_SELECTABLE
3440 add_prefix_cmd ("endian", class_support, set_endian,
3441 "Set endianness of target.",
3442 &endianlist, "set endian ", 0, &setlist);
3443 add_cmd ("big", class_support, set_endian_big,
3444 "Set target as being big endian.", &endianlist);
3445 add_cmd ("little", class_support, set_endian_little,
3446 "Set target as being little endian.", &endianlist);
3447 add_cmd ("auto", class_support, set_endian_auto,
3448 "Select target endianness automatically.", &endianlist);
3449 add_cmd ("endian", class_support, show_endian,
3450 "Show endianness of target.", &showlist);
3452 #endif /* defined (TARGET_BYTE_ORDER_SELECTABLE) */
3454 #ifdef DEFAULT_PROMPT
3455 prompt = savestring (DEFAULT_PROMPT, strlen(DEFAULT_PROMPT));
3457 prompt = savestring ("(gdb) ", 6);
3460 /* Set the important stuff up for command editing. */
3461 command_editing_p = 1;
3462 history_expansion_p = 0;
3463 write_history_p = 0;
3465 /* Setup important stuff for command line editing. */
3466 rl_completion_entry_function = (int (*)()) readline_line_completion_function;
3467 rl_completer_word_break_characters = gdb_completer_word_break_characters;
3468 rl_completer_quote_characters = gdb_completer_quote_characters;
3469 rl_readline_name = "gdb";
3471 /* Define the classes of commands.
3472 They will appear in the help list in the reverse of this order. */
3474 add_cmd ("internals", class_maintenance, NO_FUNCTION,
3475 "Maintenance commands.\n\
3476 Some gdb commands are provided just for use by gdb maintainers.\n\
3477 These commands are subject to frequent change, and may not be as\n\
3478 well documented as user commands.",
3480 add_cmd ("obscure", class_obscure, NO_FUNCTION, "Obscure features.", &cmdlist);
3481 add_cmd ("aliases", class_alias, NO_FUNCTION, "Aliases of other commands.", &cmdlist);
3482 add_cmd ("user-defined", class_user, NO_FUNCTION, "User-defined commands.\n\
3483 The commands in this class are those defined by the user.\n\
3484 Use the \"define\" command to define a command.", &cmdlist);
3485 add_cmd ("support", class_support, NO_FUNCTION, "Support facilities.", &cmdlist);
3486 add_cmd ("status", class_info, NO_FUNCTION, "Status inquiries.", &cmdlist);
3487 add_cmd ("files", class_files, NO_FUNCTION, "Specifying and examining files.", &cmdlist);
3488 add_cmd ("breakpoints", class_breakpoint, NO_FUNCTION, "Making program stop at certain points.", &cmdlist);
3489 add_cmd ("data", class_vars, NO_FUNCTION, "Examining data.", &cmdlist);
3490 add_cmd ("stack", class_stack, NO_FUNCTION, "Examining the stack.\n\
3491 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
3492 counting from zero for the innermost (currently executing) frame.\n\n\
3493 At any time gdb identifies one frame as the \"selected\" frame.\n\
3494 Variable lookups are done with respect to the selected frame.\n\
3495 When the program being debugged stops, gdb selects the innermost frame.\n\
3496 The commands below can be used to select other frames by number or address.",
3498 add_cmd ("running", class_run, NO_FUNCTION, "Running the program.", &cmdlist);
3500 add_com ("pwd", class_files, pwd_command,
3501 "Print working directory. This is used for your program as well.");
3502 c = add_cmd ("cd", class_files, cd_command,
3503 "Set working directory to DIR for debugger and program being debugged.\n\
3504 The change does not take effect for the program being debugged\n\
3505 until the next time it is started.", &cmdlist);
3506 c->completer = filename_completer;
3509 (add_set_cmd ("prompt", class_support, var_string, (char *)&prompt,
3514 add_com ("echo", class_support, echo_command,
3515 "Print a constant string. Give string as argument.\n\
3516 C escape sequences may be used in the argument.\n\
3517 No newline is added at the end of the argument;\n\
3518 use \"\\n\" if you want a newline to be printed.\n\
3519 Since leading and trailing whitespace are ignored in command arguments,\n\
3520 if you want to print some you must use \"\\\" before leading whitespace\n\
3521 to be printed or after trailing whitespace.");
3522 add_com ("document", class_support, document_command,
3523 "Document a user-defined command.\n\
3524 Give command name as argument. Give documentation on following lines.\n\
3525 End with a line of just \"end\".");
3526 add_com ("define", class_support, define_command,
3527 "Define a new command name. Command name is argument.\n\
3528 Definition appears on following lines, one command per line.\n\
3529 End with a line of just \"end\".\n\
3530 Use the \"document\" command to give documentation for the new command.\n\
3531 Commands defined in this way may have up to ten arguments.");
3534 c = add_cmd ("source", class_support, source_command,
3535 "Read commands from a file named FILE.\n\
3536 Note that the file \"" GDBINIT_FILENAME "\" is read automatically in this way\n\
3537 when gdb is started.", &cmdlist);
3539 /* Punt file name, we can't help it easily. */
3540 c = add_cmd ("source", class_support, source_command,
3541 "Read commands from a file named FILE.\n\
3542 Note that the file \".gdbinit\" is read automatically in this way\n\
3543 when gdb is started.", &cmdlist);
3545 c->completer = filename_completer;
3547 add_com ("quit", class_support, quit_command, "Exit gdb.");
3548 add_com ("help", class_support, help_command, "Print list of commands.");
3549 add_com_alias ("q", "quit", class_support, 1);
3550 add_com_alias ("h", "help", class_support, 1);
3552 add_com ("dont-repeat", class_support, dont_repeat_command, "Don't repeat this command.\n\
3553 Primarily used inside of user-defined commands that should not be repeated when\n\
3556 c = add_set_cmd ("verbose", class_support, var_boolean, (char *)&info_verbose,
3559 add_show_from_set (c, &showlist);
3560 c->function.sfunc = set_verbose;
3561 set_verbose (NULL, 0, c);
3564 (add_set_cmd ("editing", class_support, var_boolean, (char *)&command_editing_p,
3565 "Set editing of command lines as they are typed.\n\
3566 Use \"on\" to enable to enable the editing, and \"off\" to disable it.\n\
3567 Without an argument, command line editing is enabled. To edit, use\n\
3568 EMACS-like or VI-like commands like control-P or ESC.", &setlist),
3571 add_prefix_cmd ("history", class_support, set_history,
3572 "Generic command for setting command history parameters.",
3573 &sethistlist, "set history ", 0, &setlist);
3574 add_prefix_cmd ("history", class_support, show_history,
3575 "Generic command for showing command history parameters.",
3576 &showhistlist, "show history ", 0, &showlist);
3579 (add_set_cmd ("expansion", no_class, var_boolean, (char *)&history_expansion_p,
3580 "Set history expansion on command input.\n\
3581 Without an argument, history expansion is enabled.", &sethistlist),
3585 (add_set_cmd ("save", no_class, var_boolean, (char *)&write_history_p,
3586 "Set saving of the history record on exit.\n\
3587 Use \"on\" to enable to enable the saving, and \"off\" to disable it.\n\
3588 Without an argument, saving is enabled.", &sethistlist),
3591 c = add_set_cmd ("size", no_class, var_integer, (char *)&history_size,
3592 "Set the size of the command history, \n\
3593 ie. the number of previous commands to keep a record of.", &sethistlist);
3594 add_show_from_set (c, &showhistlist);
3595 c->function.sfunc = set_history_size_command;
3598 (add_set_cmd ("filename", no_class, var_filename, (char *)&history_filename,
3599 "Set the filename in which to record the command history\n\
3600 (the list of previous commands of which a record is kept).", &sethistlist),
3604 (add_set_cmd ("confirm", class_support, var_boolean,
3606 "Set whether to confirm potentially dangerous operations.",
3610 add_prefix_cmd ("info", class_info, info_command,
3611 "Generic command for showing things about the program being debugged.",
3612 &infolist, "info ", 0, &cmdlist);
3613 add_com_alias ("i", "info", class_info, 1);
3615 add_com ("complete", class_obscure, complete_command,
3616 "List the completions for the rest of the line as a command.");
3618 add_prefix_cmd ("show", class_info, show_command,
3619 "Generic command for showing things about the debugger.",
3620 &showlist, "show ", 0, &cmdlist);
3621 /* Another way to get at the same thing. */
3622 add_info ("set", show_command, "Show all GDB settings.");
3624 add_cmd ("commands", no_class, show_commands,
3625 "Show the history of commands you typed.\n\
3626 You can supply a command number to start with, or a `+' to start after\n\
3627 the previous command number shown.",
3630 add_cmd ("version", no_class, show_version,
3631 "Show what version of GDB this is.", &showlist);
3633 add_com ("while", class_support, while_command,
3634 "Execute nested commands WHILE the conditional expression is non zero.\n\
3635 The conditional expression must follow the word `while' and must in turn be\n\
3636 followed by a new line. The nested commands must be entered one per line,\n\
3637 and should be terminated by the word `end'.");
3639 add_com ("if", class_support, if_command,
3640 "Execute nested commands once IF the conditional expression is non zero.\n\
3641 The conditional expression must follow the word `if' and must in turn be\n\
3642 followed by a new line. The nested commands must be entered one per line,\n\
3643 and should be terminated by the word 'else' or `end'. If an else clause\n\
3644 is used, the same rules apply to its nested commands as to the first ones.");
3646 /* If target is open when baud changes, it doesn't take effect until the
3647 next open (I think, not sure). */
3648 add_show_from_set (add_set_cmd ("remotebaud", no_class,
3649 var_zinteger, (char *)&baud_rate,
3650 "Set baud rate for remote serial I/O.\n\
3651 This value is used to set the speed of the serial port when debugging\n\
3652 using remote targets.", &setlist),
3656 add_set_cmd ("remotedebug", no_class, var_zinteger, (char *)&remote_debug,
3657 "Set debugging of remote protocol.\n\
3658 When enabled, each packet sent or received with the remote target\n\
3659 is displayed.", &setlist),
3663 add_set_cmd ("remotetimeout", no_class, var_integer, (char *)&remote_timeout,
3664 "Set timeout limit to wait for target to respond.\n\
3665 This value is used to set the time limit for gdb to wait for a response\n\
3666 from he target.", &setlist),
3669 c = add_set_cmd ("annotate", class_obscure, var_zinteger,
3670 (char *)&annotation_level, "Set annotation_level.\n\
3671 0 == normal; 1 == fullname (for use when running under emacs)\n\
3672 2 == output annotated suitably for use by programs that control GDB.",
3674 c = add_show_from_set (c, &showlist);